0x0::account
Account module manages the account data for each user.
Account
open_orders
taker_volume
maker_volume
total_volume
active_stake
inactive_stake
created_proposal
voted_proposal
settled_balances
empty
update
process_maker_fill
add_taker_volume
set_voted_proposal
set_created_proposal
add_settled_balances
add_owed_balances
settle
add_rebates
claim_rebates
add_order
remove_order
add_stake
remove_stake
use 0x0::balances;
use 0x0::fill;
use 0x1::option;
use 0x2::object;
use 0x2::tx_context;
use 0x2::vec_set;
Account
Account data that is updated every epoch. One Account struct per BalanceManager object.
struct Account has copy, drop, store
epoch: u64
open_orders: vec_set::VecSet<u128>
taker_volume: u128
maker_volume: u128
active_stake: u64
inactive_stake: u64
created_proposal: bool
voted_proposal: option::Option<object::ID>
unclaimed_rebates: balances::Balances
settled_balances: balances::Balances
owed_balances: balances::Balances
open_orders
public fun open_orders(self: &account::Account): vec_set::VecSet<u128>
public fun open_orders(self: &Account): VecSet<u128> {
self.open_orders
}
taker_volume
public fun taker_volume(self: &account::Account): u128
public fun taker_volume(self: &Account): u128 {
self.taker_volume
}
maker_volume
public fun maker_volume(self: &account::Account): u128
public fun maker_volume(self: &Account): u128 {
self.maker_volume
}
total_volume
public fun total_volume(self: &account::Account): u128
public fun total_volume(self: &Account): u128 {
self.taker_volume + self.maker_volume
}
active_stake
public fun active_stake(self: &account::Account): u64
public fun active_stake(self: &Account): u64 {
self.active_stake
}
inactive_stake
public fun inactive_stake(self: &account::Account): u64
public fun inactive_stake(self: &Account): u64 {
self.inactive_stake
}
created_proposal
public fun created_proposal(self: &account::Account): bool
public fun created_proposal(self: &Account): bool {
self.created_proposal
}
voted_proposal
public fun voted_proposal(self: &account::Account): option::Option<object::ID>
public fun voted_proposal(self: &Account): Option<ID> {
self.voted_proposal
}
settled_balances
public fun settled_balances(self: &account::Account): balances::Balances
public fun settled_balances(self: &Account): Balances {
self.settled_balances
}
empty
public(friend) fun empty(ctx: &tx_context::TxContext): account::Account
public(package) fun empty(ctx: &TxContext): Account {
Account {
epoch: ctx.epoch(),
open_orders: vec_set::empty(),
taker_volume: 0,
maker_volume: 0,
active_stake: 0,
inactive_stake: 0,
created_proposal: false,
voted_proposal: option::none(),
unclaimed_rebates: balances::empty(),
settled_balances: balances::empty(),
owed_balances: balances::empty(),
}
}
update
Update the account data for the new epoch. Returns the previous epoch, maker volume, and active stake.
public(friend) fun update(self: &mut account::Account, ctx: &tx_context::TxContext): (u64, u128, u64)
public(package) fun update(
self: &mut Account,
ctx: &TxContext,
): (u64, u128, u64) {
if (self.epoch == ctx.epoch()) return (0, 0, 0);
let prev_epoch = self.epoch;
let prev_maker_volume = self.maker_volume;
let prev_active_stake = self.active_stake;
self.epoch = ctx.epoch();
self.maker_volume = 0;
self.taker_volume = 0;
self.active_stake = self.active_stake + self.inactive_stake;
self.inactive_stake = 0;
self.created_proposal = false;
self.voted_proposal = option::none();
(prev_epoch, prev_maker_volume, prev_active_stake)
}
process_maker_fill
Given a fill, update the account balances and volumes as the maker.
public(friend) fun process_maker_fill(self: &mut account::Account, fill: &fill::Fill)
public(package) fun process_maker_fill(self: &mut Account, fill: &Fill) {
let settled_balances = fill.get_settled_maker_quantities();
self.settled_balances.add_balances(settled_balances);
if (!fill.expired()) {
self.maker_volume = self.maker_volume + (fill.base_quantity() as u128);
};
if (fill.expired() || fill.completed()) {
self.open_orders.remove(&fill.maker_order_id());
}
}
add_taker_volume
public(friend) fun add_taker_volume(self: &mut account::Account, volume: u64)
public(package) fun add_taker_volume(self: &mut Account, volume: u64) {
self.taker_volume = self.taker_volume + (volume as u128);
}
set_voted_proposal
Set the voted proposal for the account and return the previous proposal.
public(friend) fun set_voted_proposal(self: &mut account::Account, proposal: option::Option<object::ID>): option::Option<object::ID>
public(package) fun set_voted_proposal(
self: &mut Account,
proposal: Option<ID>,
): Option<ID> {
let prev_proposal = self.voted_proposal;
self.voted_proposal = proposal;
prev_proposal
}
set_created_proposal
public(friend) fun set_created_proposal(self: &mut account::Account, created: bool)
public(package) fun set_created_proposal(self: &mut Account, created: bool) {
self.created_proposal = created;
}
add_settled_balances
public(friend) fun add_settled_balances(self: &mut account::Account, balances: balances::Balances)
public(package) fun add_settled_balances(
self: &mut Account,
balances: Balances,
) {
self.settled_balances.add_balances(balances);
}
add_owed_balances
public(friend) fun add_owed_balances(self: &mut account::Account, balances: balances::Balances)
public(package) fun add_owed_balances(self: &mut Account, balances: Balances) {
self.owed_balances.add_balances(balances);
}
settle
Settle the account balances. Returns the settled and owed balances by this account. Vault uses these values to perform any necessary transfers.
public(friend) fun settle(self: &mut account::Account): (balances::Balances, balances::Balances)
public(package) fun settle(self: &mut Account): (Balances, Balances) {
let settled = self.settled_balances.reset();
let owed = self.owed_balances.reset();
(settled, owed)
}
add_rebates
public(friend) fun add_rebates(self: &mut account::Account, rebates: balances::Balances)
public(package) fun add_rebates(self: &mut Account, rebates: Balances) {
self.unclaimed_rebates.add_balances(rebates);
}
claim_rebates
public(friend) fun claim_rebates(self: &mut account::Account): u64
public(package) fun claim_rebates(self: &mut Account): u64 {
let rebate_amount = self.unclaimed_rebates.deep();
self.settled_balances.add_balances(self.unclaimed_rebates);
self.unclaimed_rebates.reset();
rebate_amount
}
add_order
public(friend) fun add_order(self: &mut account::Account, order_id: u128)
public(package) fun add_order(self: &mut Account, order_id: u128) {
self.open_orders.insert(order_id);
}
remove_order
public(friend) fun remove_order(self: &mut account::Account, order_id: u128)
public(package) fun remove_order(self: &mut Account, order_id: u128) {
self.open_orders.remove(&order_id)
}
add_stake
public(friend) fun add_stake(self: &mut account::Account, stake: u64): (u64, u64)
public(package) fun add_stake(self: &mut Account, stake: u64): (u64, u64) {
let stake_before = self.active_stake + self.inactive_stake;
self.inactive_stake = self.inactive_stake + stake;
self.owed_balances.add_deep(stake);
(stake_before, self.active_stake + self.inactive_stake)
}
remove_stake
public(friend) fun remove_stake(self: &mut account::Account)
public(package) fun remove_stake(self: &mut Account) {
let stake_before = self.active_stake + self.inactive_stake;
self.active_stake = 0;
self.inactive_stake = 0;
self.voted_proposal = option::none();
self.settled_balances.add_deep(stake_before);
}