Farm
A contract to distribute reward tokens to stakers.
All times are in seconds.
Structs
Account
farm_id - The `sui::object::ID` of the farm to which this account belongs to.
amount - The amount of StakeCoin the user has in the Farm.
reward_debt - Amount of rewards the Farm has already paid the user.
Farm
rewards_per_second - Amount of RewardCoin to give to stakers per second.
start_timestamp - The timestamp in seconds that this farm will start distributing rewards.
last_reward_timestamp - Last timestamp that the farm was updated.
accrued_rewards_per_share - Total amount of rewards per share distributed by this farm.
balance_stake_coin - StakeCoin deposited in this farm.
balance_reward_coin - RewardCoin deposited in this farm.
stake_coin_decimal_factor - The decimal scalar of the StakeCoin.
owned_by - The `sui::object::ID` of the OwnerCap that "owns" this farm.
Interface
new_cap
It creates an OwnerCap. It is used to provide admin capabilities to the holder.
@return OwnerCap.
new_farm
It creates an Farm<StakeCoin, RewardCoin>. The start_timestamp
is in seconds.
@param cap: An OwnerCap that will be assigned the admin rights of the newly created Farm.
@param stake_coin_metadata: The
sui::coin::CoinMetadata
of theStakeCoin
.@param c: The
sui::clock::Clock
shared object.@param rewards_per_second: The amount of
RewardCoin
the farm can distribute to stakers.@param start_timestamp: The timestamp in seconds that the farm is allowed to start distributing rewards.
@return Farm<StakeCoin, RewardCoin>.
new_account
It creates an Account<StakeCoin, RewardCoin>. It is used to keep track of the holder's deposit and rewards.
@param cap: self The Farm<StakeCoin, RewardCoin>.
@return Account<StakeCoin, RewardCoin>.
rewards_per_second
Returns the self
rewards per second.
@param cap: self The Farm<StakeCoin, RewardCoin>.
@return u64.
start_timestamp
Returns the self
start timestamp.
@param cap: self The Farm<StakeCoin, RewardCoin>.
@return u64.
last_reward_timestamp
Returns the self
last reward timestamp.
@param cap: self The Farm<StakeCoin, RewardCoin>.
@return u64.
accrued_rewards_per_share
Returns the self
accrued rewards per share.
@param cap: self The Farm<StakeCoin, RewardCoin>.
@return u256.
balance_stake_coin
Returns the self
stake coin balance.
@param cap: self The Farm<StakeCoin, RewardCoin>.
@return u64.
balance_reward_coin
Returns the self
reward coin balance.
@param cap: self The Farm<StakeCoin, RewardCoin>.
@return u64.
stake_coin_decimal_factor
Returns the self
reward coin decimal scalar.
@param cap: self The Farm<StakeCoin, RewardCoin>.
@return u64.
owned_by
Returns the self
reward coin decimal scalar.
@param cap: self The Farm<StakeCoin, RewardCoin>.
@return ID.
amount
Returns the account
staked amount.
@param cap: self The Farm<StakeCoin, RewardCoin>.
@return u64.
reward_debt
Returns the account
reward debt.
@param cap: self The Farm<StakeCoin, RewardCoin>.
@return u256.
pending_rewards
Returns the account
's pending rewards. It does not update the state.
@param farm: The Farm<StakeCoin, RewardCoin>.
@param account: The Account associated with the
farm
.@param c: The
sui::clock::Clock
shared object.@return u64.
add_rewards
It allows anyone to add rewards to the farm
.
@param self: The Farm<StakeCoin, RewardCoin>.
@param c: The
sui::clock::Clock
shared object.@param reward: The RewardCoin to be added to the
self
.
stake
Allows a user to stake stake_coin
in the farm
. On the first deposits the returned Coin will have a value of zero. So make sure to destroy it.
@param farm: The Farm<StakeCoin, RewardCoin>.
@param account: The Account associated with the
farm
.@param stake_coin: The StakeCoin to stake in the
farm
.@param c: The
sui::clock::Clock
shared object.@return Coin. It gives any pending rewards to the user.
Aborts
If the
account
does not belong to thefarm
.
unstake
Allows a user to unstake his stake_coin
in the farm
.
@param farm: The Farm<StakeCoin, RewardCoin>.
@param account: The Account associated with the
farm
.@param amount: The amount of StakeCoin to remove from the
farm
.@param c: The
sui::clock::Clock
shared object.@return Coin. The staked Coin.
@return Coin. It gives any pending rewards to the user.
Aborts
amount
is larger than theaccount.amount
. If the user tries to unstake more than he has staked.
destroy_zero_account
Destroys the account
.
@param account: The Account associated with the
farm
.
Aborts
account
has an amount greater than zero.
update_rewards_per_second
Updates the rewards per second of the farm
.
@param farm: The Farm<StakeCoin, RewardCoin>.
@param cap: The OwnerCap that "owns" the
farm
.@param new_rewards_per_second: The new amount of RewardCoin the
farm
will give.@param c: The
sui::clock::Clock
shared object.
Aborts
cap
does not own thefarm
.
destroy_zero_farm
Destroys the farm
.
@param farm: The Farm<StakeCoin, RewardCoin>.
@param cap: The OwnerCap that "owns" the
farm
.
Aborts
cap
does not own thefarm
.farm
still has staked coins.farm
still has reward coins.
borrow_mut_uid
Returns a mutable reference of the farm
's sui::object::UI to allow the cap
owner to extend its functionalities.
@param farm: The Farm<StakeCoin, RewardCoin>.
@param cap: The OwnerCap that "owns" the
farm
.@return &mut UID.
Aborts
cap
does not own thefarm
.
Last updated