0x1::YieldFarmingFarmingFarmingAssetParameterModifyCapabilityStakeExpexpmul_u128div_u128truncateinitializeinitialize_assetmodify_parameterstakeunstakeharvestquery_gov_token_amountquery_total_stakequery_stakecalculate_harvest_index_with_assetcalculate_harvest_index_weight_zerocalculate_harvest_indexcalculate_withdraw_amountexists_atexists_asset_atexists_stake_at_addressuse 0x1::Errors;
use 0x1::Token;
FarmingThe object of yield farming RewardTokenT meaning token of yield farming
struct Farming<PoolType, RewardTokenT> has store, key
treasury_token: Token::Token<RewardTokenT>
FarmingAssetstruct FarmingAsset<PoolType, AssetT> has store, key
asset_total_weight: u128
harvest_index: u128
last_update_timestamp: u64
release_per_second: u128
start_time: u64
ParameterModifyCapabilityCapability to modify parameter such as period and release amount
struct ParameterModifyCapability<PoolType, AssetT> has store, key
dummy_field: bool
StakeTo store user’s asset token
struct Stake<PoolType, AssetT> has store, key
asset: AssetT
asset_weight: u128
last_harvest_index: u128
gain: u128
Expstruct Exp has copy, drop, store
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;
expfun exp(num: u128, denom: u128): YieldFarming::Exp
fun exp(num: u128, denom: u128): Exp {
// if overflow move will abort
let scaledNumerator = mul_u128(num, EXP_SCALE);
let rational = div_u128(scaledNumerator, denom);
Exp {
mantissa: rational
}
}
mul_u128fun mul_u128(a: u128, b: u128): u128
fun mul_u128(a: u128, b: u128): u128 {
if (a == 0 || b == 0) {
return 0
};
a * b
}
div_u128fun div_u128(a: u128, b: u128): u128
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
}
truncatefun truncate(exp: YieldFarming::Exp): u128
initializeCalled by token issuer this will declare a yield farming pool
public fun initialize<PoolType: store, RewardTokenT: store>(_account: &signer, _treasury_token: Token::Token<RewardTokenT>)
public fun initialize<
PoolType: store,
RewardTokenT: store>(_account: &signer,
_treasury_token: Token::Token<RewardTokenT>) {
abort Errors::deprecated(EDEPRECATED_FUNCTION)
}
initialize_assetpublic fun initialize_asset<PoolType: store, AssetT: store>(_account: &signer, _release_per_second: u128, _delay: u64): YieldFarming::ParameterModifyCapability<PoolType, AssetT>
public fun initialize_asset<PoolType: store, AssetT: store>(
_account: &signer,
_release_per_second: u128,
_delay: u64): ParameterModifyCapability<PoolType, AssetT> {
abort Errors::deprecated(EDEPRECATED_FUNCTION)
}
modify_parameterpublic fun modify_parameter<PoolType: store, RewardTokenT: store, AssetT: store>(_cap: &YieldFarming::ParameterModifyCapability<PoolType, AssetT>, _broker: address, _release_per_second: u128)
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)
}
stakeCall 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)
public fun stake<PoolType: store, RewardTokenT: store, AssetT: store>(
_account: &signer,
_broker: address,
_asset: AssetT,
_asset_weight: u128) {
abort Errors::deprecated(EDEPRECATED_FUNCTION)
}
unstakeUnstake asset from farming pool
public fun unstake<PoolType: store, RewardTokenT: store, AssetT: store>(_account: &signer, _broker: address): (AssetT, Token::Token<RewardTokenT>)
public fun unstake<PoolType: store, RewardTokenT: store, AssetT: store>(_account: &signer, _broker: address)
: (AssetT, Token::Token<RewardTokenT>) {
abort Errors::deprecated(EDEPRECATED_FUNCTION)
}
harvestHarvest yield farming token from stake
public fun harvest<PoolType: store, RewardTokenT: store, AssetT: store>(_account: &signer, _broker: address, _amount: u128): Token::Token<RewardTokenT>
public fun harvest<PoolType: store,
RewardTokenT: store,
AssetT: store>(
_account: &signer,
_broker: address,
_amount: u128): Token::Token<RewardTokenT> {
abort Errors::deprecated(EDEPRECATED_FUNCTION)
}
query_gov_token_amountThe 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
public fun query_gov_token_amount<PoolType: store,
RewardTokenT: store,
AssetT: store>(_account: &signer, _broker: address): u128 {
0
}
query_total_stakeQuery total stake count from yield farming resource
public fun query_total_stake<PoolType: store, AssetT: store>(_broker: address): u128
public fun query_total_stake<PoolType: store,
AssetT: store>(_broker: address): u128 {
0
}
query_stakeQuery stake weight from user staking objects.
public fun query_stake<PoolType: store, AssetT: store>(_account: &signer): u128
public fun query_stake<PoolType: store,
AssetT: store>(_account: &signer): u128 {
0
}
calculate_harvest_index_with_assetUpdate farming asset
fun calculate_harvest_index_with_asset<PoolType, AssetT>(_farming_asset: &YieldFarming::FarmingAsset<PoolType, AssetT>, _now_seconds: u64): u128
fun calculate_harvest_index_with_asset<PoolType, AssetT>(_farming_asset: &FarmingAsset<PoolType, AssetT>, _now_seconds: u64): u128 {
0
}
calculate_harvest_index_weight_zeroThere 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
public fun calculate_harvest_index_weight_zero(_harvest_index: u128,
_last_update_timestamp: u64,
_now_seconds: u64,
_release_per_second: u128): u128 {
0
}
calculate_harvest_indexThere 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
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
}
calculate_withdraw_amountThis function will return a gain index
public fun calculate_withdraw_amount(_harvest_index: u128, _last_harvest_index: u128, _asset_weight: u128): u128
public fun calculate_withdraw_amount(_harvest_index: u128,
_last_harvest_index: u128,
_asset_weight: u128): u128 {
0
}
exists_atCheck the Farming of TokenT is exists.
public fun exists_at<PoolType: store, RewardTokenT: store>(broker: address): bool
public fun exists_at<PoolType: store, RewardTokenT: store>(broker: address): bool {
exists<Farming<PoolType, RewardTokenT>>(broker)
}
exists_asset_atCheck the Farming of AsssetT is exists.
public fun exists_asset_at<PoolType: store, AssetT: store>(broker: address): bool
public fun exists_asset_at<PoolType: store, AssetT: store>(broker: address): bool {
exists<FarmingAsset<PoolType, AssetT>>(broker)
}
exists_stake_at_addressCheck stake at address exists.
public fun exists_stake_at_address<PoolType: store, AssetT: store>(account: address): bool
public fun exists_stake_at_address<PoolType: store, AssetT: store>(account: address): bool {
exists<Stake<PoolType, AssetT>>(account)
}
pragma verify = false;