- Resource
Farming
- Resource
FarmingAsset
- Resource
ParameterModifyCapability
- Resource
Stake
- Struct
Exp
- Constants
- Function
exp
- Function
mul_u128
- Function
div_u128
- Function
truncate
- Function
initialize
- Function
initialize_asset
- Function
modify_parameter
- Function
stake
- Function
unstake
- Function
harvest
- Function
query_gov_token_amount
- Function
query_total_stake
- Function
query_stake
- Function
calculate_harvest_index_with_asset
- Function
calculate_harvest_index_weight_zero
- Function
calculate_harvest_index
- Function
calculate_withdraw_amount
- Function
exists_at
- Function
exists_asset_at
- Function
exists_stake_at_address
- Module Specification
use 0x1::Errors;
use 0x1::Token;
The object of yield farming RewardTokenT meaning token of yield farming
struct Farming<PoolType, RewardTokenT> has store, key
Fields
-
treasury_token: Token::Token<RewardTokenT>
struct FarmingAsset<PoolType, AssetT> has store, key
Fields
-
asset_total_weight: u128
-
harvest_index: u128
-
last_update_timestamp: u64
-
release_per_second: u128
-
start_time: u64
Capability to modify parameter such as period and release amount
struct ParameterModifyCapability<PoolType, AssetT> has store, key
Fields
-
dummy_field: bool
To store user's asset token
struct Stake<PoolType, AssetT> has store, key
Fields
-
asset: AssetT
-
asset_weight: u128
-
last_harvest_index: u128
-
gain: u128
struct Exp has copy, drop, store
Fields
-
mantissa: u128
const EDEPRECATED_FUNCTION: u64 = 19;
const ERR_EXP_DIVIDE_BY_ZERO: u64 = 107;
const ERR_FARMING_BALANCE_EXCEEDED: u64 = 108;
const ERR_FARMING_HAVERST_NO_GAIN: u64 = 105;
const ERR_FARMING_INIT_REPEATE: u64 = 101;
const ERR_FARMING_NOT_ENOUGH_ASSET: u64 = 109;
const ERR_FARMING_NOT_STILL_FREEZE: u64 = 102;
const ERR_FARMING_STAKE_EXISTS: u64 = 103;
const ERR_FARMING_STAKE_NOT_EXISTS: u64 = 104;
const ERR_FARMING_TIMESTAMP_INVALID: u64 = 110;
const ERR_FARMING_TOTAL_WEIGHT_IS_ZERO: u64 = 106;
const EXP_SCALE: u128 = 1000000000000000000;
fun exp(num: u128, denom: u128): YieldFarming::Exp
Implementation
fun mul_u128(a: u128, b: u128): u128
Implementation
fun mul_u128(a: u128, b: u128): u128 {
if (a == 0 || b == 0) {
return 0
};
a * b
}
fun div_u128(a: u128, b: u128): u128
Implementation
fun div_u128(a: u128, b: u128): u128 {
if ( b == 0) {
abort Errors::invalid_argument(ERR_EXP_DIVIDE_BY_ZERO)
};
if (a == 0) {
return 0
};
a / b
}
fun truncate(exp: YieldFarming::Exp): u128
Called by token issuer this will declare a yield farming pool
public fun initialize<PoolType: store, RewardTokenT: store>(_account: &signer, _treasury_token: Token::Token<RewardTokenT>)
Implementation
public fun initialize<
PoolType: store,
RewardTokenT: store>(_account: &signer,
_treasury_token: Token::Token<RewardTokenT>) {
abort Errors::deprecated(EDEPRECATED_FUNCTION)
}
public fun initialize_asset<PoolType: store, AssetT: store>(_account: &signer, _release_per_second: u128, _delay: u64): YieldFarming::ParameterModifyCapability<PoolType, AssetT>
Implementation
public fun initialize_asset<PoolType: store, AssetT: store>(
_account: &signer,
_release_per_second: u128,
_delay: u64): ParameterModifyCapability<PoolType, AssetT> {
abort Errors::deprecated(EDEPRECATED_FUNCTION)
}
public fun modify_parameter<PoolType: store, RewardTokenT: store, AssetT: store>(_cap: &YieldFarming::ParameterModifyCapability<PoolType, AssetT>, _broker: address, _release_per_second: u128)
Implementation
public fun modify_parameter<PoolType: store, RewardTokenT: store, AssetT: store>(
_cap: &ParameterModifyCapability<PoolType, AssetT>,
_broker: address,
_release_per_second: u128) {
abort Errors::deprecated(EDEPRECATED_FUNCTION)
}
Call by stake user, staking amount of asset in order to get yield farming token
public fun stake<PoolType: store, RewardTokenT: store, AssetT: store>(_account: &signer, _broker: address, _asset: AssetT, _asset_weight: u128)
Implementation
public fun stake<PoolType: store, RewardTokenT: store, AssetT: store>(
_account: &signer,
_broker: address,
_asset: AssetT,
_asset_weight: u128) {
abort Errors::deprecated(EDEPRECATED_FUNCTION)
}
Unstake asset from farming pool
public fun unstake<PoolType: store, RewardTokenT: store, AssetT: store>(_account: &signer, _broker: address): (AssetT, Token::Token<RewardTokenT>)
Implementation
public fun unstake<PoolType: store, RewardTokenT: store, AssetT: store>(_account: &signer, _broker: address)
: (AssetT, Token::Token<RewardTokenT>) {
abort Errors::deprecated(EDEPRECATED_FUNCTION)
}
Harvest yield farming token from stake
public fun harvest<PoolType: store, RewardTokenT: store, AssetT: store>(_account: &signer, _broker: address, _amount: u128): Token::Token<RewardTokenT>
Implementation
public fun harvest<PoolType: store,
RewardTokenT: store,
AssetT: store>(
_account: &signer,
_broker: address,
_amount: u128): Token::Token<RewardTokenT> {
abort Errors::deprecated(EDEPRECATED_FUNCTION)
}
The user can quering all yield farming amount in any time and scene
public fun query_gov_token_amount<PoolType: store, RewardTokenT: store, AssetT: store>(_account: &signer, _broker: address): u128
Implementation
public fun query_gov_token_amount<PoolType: store,
RewardTokenT: store,
AssetT: store>(_account: &signer, _broker: address): u128 {
0
}
Query total stake count from yield farming resource
public fun query_total_stake<PoolType: store, AssetT: store>(_broker: address): u128
Implementation
public fun query_total_stake<PoolType: store,
AssetT: store>(_broker: address): u128 {
0
}
Query stake weight from user staking objects.
public fun query_stake<PoolType: store, AssetT: store>(_account: &signer): u128
Implementation
public fun query_stake<PoolType: store,
AssetT: store>(_account: &signer): u128 {
0
}
Update farming asset
fun calculate_harvest_index_with_asset<PoolType, AssetT>(_farming_asset: &YieldFarming::FarmingAsset<PoolType, AssetT>, _now_seconds: u64): u128
Implementation
fun calculate_harvest_index_with_asset<PoolType, AssetT>(_farming_asset: &FarmingAsset<PoolType, AssetT>, _now_seconds: u64): u128 {
0
}
There is calculating from harvest index and global parameters without asset_total_weight
public fun calculate_harvest_index_weight_zero(_harvest_index: u128, _last_update_timestamp: u64, _now_seconds: u64, _release_per_second: u128): u128
Implementation
public fun calculate_harvest_index_weight_zero(_harvest_index: u128,
_last_update_timestamp: u64,
_now_seconds: u64,
_release_per_second: u128): u128 {
0
}
There is calculating from harvest index and global parameters
public fun calculate_harvest_index(_harvest_index: u128, _asset_total_weight: u128, _last_update_timestamp: u64, _now_seconds: u64, _release_per_second: u128): u128
Implementation
public fun calculate_harvest_index(_harvest_index: u128,
_asset_total_weight: u128,
_last_update_timestamp: u64,
_now_seconds: u64,
_release_per_second: u128): u128 {
0
}
This function will return a gain index
public fun calculate_withdraw_amount(_harvest_index: u128, _last_harvest_index: u128, _asset_weight: u128): u128
Implementation
public fun calculate_withdraw_amount(_harvest_index: u128,
_last_harvest_index: u128,
_asset_weight: u128): u128 {
0
}
Check the Farming of TokenT is exists.
public fun exists_at<PoolType: store, RewardTokenT: store>(broker: address): bool
Implementation
Check the Farming of AsssetT is exists.
public fun exists_asset_at<PoolType: store, AssetT: store>(broker: address): bool
Implementation
public fun exists_asset_at<PoolType: store, AssetT: store>(broker: address): bool {
exists<FarmingAsset<PoolType, AssetT>>(broker)
}
Check stake at address exists.
public fun exists_stake_at_address<PoolType: store, AssetT: store>(account: address): bool
Implementation
public fun exists_stake_at_address<PoolType: store, AssetT: store>(account: address): bool {
exists<Stake<PoolType, AssetT>>(account)
}
pragma verify = false;