Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update markdown document by running tests #165

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions aptos-move/framework/aptos-stdlib/doc/fixed_point64.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ a 64-bit fractional part.
- [Function `sub`](#0x1_fixed_point64_sub)
- [Function `add`](#0x1_fixed_point64_add)
- [Function `multiply_u128`](#0x1_fixed_point64_multiply_u128)
- [Function `multiply_u128_return_fixpoint64`](#0x1_fixed_point64_multiply_u128_return_fixpoint64)
- [Function `divide_u128`](#0x1_fixed_point64_divide_u128)
- [Function `create_from_rational`](#0x1_fixed_point64_create_from_rational)
- [Function `create_from_raw_value`](#0x1_fixed_point64_create_from_raw_value)
Expand Down Expand Up @@ -255,6 +256,36 @@ overflows.



</details>

<a id="0x1_fixed_point64_multiply_u128_return_fixpoint64"></a>

## Function `multiply_u128_return_fixpoint64`



<pre><code><b>public</b> <b>fun</b> <a href="fixed_point64.md#0x1_fixed_point64_multiply_u128_return_fixpoint64">multiply_u128_return_fixpoint64</a>(val: u128, multiplier: <a href="fixed_point64.md#0x1_fixed_point64_FixedPoint64">fixed_point64::FixedPoint64</a>): <a href="fixed_point64.md#0x1_fixed_point64_FixedPoint64">fixed_point64::FixedPoint64</a>
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="fixed_point64.md#0x1_fixed_point64_multiply_u128_return_fixpoint64">multiply_u128_return_fixpoint64</a>(val: u128, multiplier: <a href="fixed_point64.md#0x1_fixed_point64_FixedPoint64">FixedPoint64</a>): <a href="fixed_point64.md#0x1_fixed_point64_FixedPoint64">FixedPoint64</a> {
// The product of two 128 bit values <b>has</b> 256 bits, so perform the
// multiplication <b>with</b> u256 types and keep the full 256 bit product
// <b>to</b> avoid losing accuracy.
<b>let</b> unscaled_product = (val <b>as</b> u256) * (multiplier.value <b>as</b> u256);
// Check whether the value is too large.
<b>assert</b>!(unscaled_product &lt;= <a href="fixed_point64.md#0x1_fixed_point64_MAX_U128">MAX_U128</a>, <a href="fixed_point64.md#0x1_fixed_point64_EMULTIPLICATION">EMULTIPLICATION</a>);
<a href="fixed_point64.md#0x1_fixed_point64_create_from_raw_value">create_from_raw_value</a>((unscaled_product <b>as</b> u128))
}
</code></pre>



</details>

<a id="0x1_fixed_point64_divide_u128"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,33 @@ pub enum EntryFunctionCall {
stakes: Vec<u64>,
},

/// Initialize a delegation pool without actual coin but withdraw from the owner's account.
PboDelegationPoolInitializeDelegationPoolWithAmount {
multisig_admin: AccountAddress,
amount: u64,
operator_commission_percentage: u64,
delegation_pool_creation_seed: Vec<u8>,
delegator_address: Vec<AccountAddress>,
principle_stake: Vec<u64>,
unlock_numerators: Vec<u64>,
unlock_denominator: u64,
unlock_start_time: u64,
unlock_duration: u64,
},

/// Initialize a delegation pool without actual coin but withdraw from the owner's account.
PboDelegationPoolInitializeDelegationPoolWithAmountWithoutMultisigAdmin {
amount: u64,
operator_commission_percentage: u64,
delegation_pool_creation_seed: Vec<u8>,
delegator_address: Vec<AccountAddress>,
principle_stake: Vec<u64>,
unlock_numerators: Vec<u64>,
unlock_denominator: u64,
unlock_start_time: u64,
unlock_duration: u64,
},

/// Updates the `principle_stake` of each `delegator` in `delegators` according to the amount specified
/// at the corresponding index of `new_principle_stakes`. Also ensures that the `delegator`'s `active` stake
/// is as close to the specified amount as possible. The locked amount is subject to the vesting schedule
Expand Down Expand Up @@ -622,6 +649,20 @@ pub enum EntryFunctionCall {
new_commission_percentage: u64,
},

/// Pre-condition: `cumulative_unlocked_fraction` should be zero, which would indicate that even
/// though there are principle stake holders, none of those have yet called `unlock` on the pool
/// thus it is ``safe'' to change the schedule
/// This is a temporary measure to allow Supra Foundation to change the schedule for those pools
/// there were initialized with ``dummy/default'' schedule. This method must be disabled
/// before external validators are allowed to join the validator set.
PboDelegationPoolUpdateUnlockingSchedule {
pool_address: AccountAddress,
unlock_numerators: Vec<u64>,
unlock_denominator: u64,
unlock_start_time: u64,
unlock_duration: u64,
},

/// Withdraw `amount` of owned inactive stake from the delegation pool at `pool_address`.
PboDelegationPoolWithdraw {
pool_address: AccountAddress,
Expand Down Expand Up @@ -1530,6 +1571,50 @@ impl EntryFunctionCall {
delegators,
stakes,
} => pbo_delegation_pool_fund_delegators_with_stake(pool_address, delegators, stakes),
PboDelegationPoolInitializeDelegationPoolWithAmount {
multisig_admin,
amount,
operator_commission_percentage,
delegation_pool_creation_seed,
delegator_address,
principle_stake,
unlock_numerators,
unlock_denominator,
unlock_start_time,
unlock_duration,
} => pbo_delegation_pool_initialize_delegation_pool_with_amount(
multisig_admin,
amount,
operator_commission_percentage,
delegation_pool_creation_seed,
delegator_address,
principle_stake,
unlock_numerators,
unlock_denominator,
unlock_start_time,
unlock_duration,
),
PboDelegationPoolInitializeDelegationPoolWithAmountWithoutMultisigAdmin {
amount,
operator_commission_percentage,
delegation_pool_creation_seed,
delegator_address,
principle_stake,
unlock_numerators,
unlock_denominator,
unlock_start_time,
unlock_duration,
} => pbo_delegation_pool_initialize_delegation_pool_with_amount_without_multisig_admin(
amount,
operator_commission_percentage,
delegation_pool_creation_seed,
delegator_address,
principle_stake,
unlock_numerators,
unlock_denominator,
unlock_start_time,
unlock_duration,
),
PboDelegationPoolLockDelegatorsStakes {
pool_address,
delegators,
Expand Down Expand Up @@ -1567,6 +1652,19 @@ impl EntryFunctionCall {
PboDelegationPoolUpdateCommissionPercentage {
new_commission_percentage,
} => pbo_delegation_pool_update_commission_percentage(new_commission_percentage),
PboDelegationPoolUpdateUnlockingSchedule {
pool_address,
unlock_numerators,
unlock_denominator,
unlock_start_time,
unlock_duration,
} => pbo_delegation_pool_update_unlocking_schedule(
pool_address,
unlock_numerators,
unlock_denominator,
unlock_start_time,
unlock_duration,
),
PboDelegationPoolWithdraw {
pool_address,
amount,
Expand Down Expand Up @@ -3336,6 +3434,80 @@ pub fn pbo_delegation_pool_fund_delegators_with_stake(
))
}

/// Initialize a delegation pool without actual coin but withdraw from the owner's account.
pub fn pbo_delegation_pool_initialize_delegation_pool_with_amount(
multisig_admin: AccountAddress,
amount: u64,
operator_commission_percentage: u64,
delegation_pool_creation_seed: Vec<u8>,
delegator_address: Vec<AccountAddress>,
principle_stake: Vec<u64>,
unlock_numerators: Vec<u64>,
unlock_denominator: u64,
unlock_start_time: u64,
unlock_duration: u64,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("pbo_delegation_pool").to_owned(),
),
ident_str!("initialize_delegation_pool_with_amount").to_owned(),
vec![],
vec![
bcs::to_bytes(&multisig_admin).unwrap(),
bcs::to_bytes(&amount).unwrap(),
bcs::to_bytes(&operator_commission_percentage).unwrap(),
bcs::to_bytes(&delegation_pool_creation_seed).unwrap(),
bcs::to_bytes(&delegator_address).unwrap(),
bcs::to_bytes(&principle_stake).unwrap(),
bcs::to_bytes(&unlock_numerators).unwrap(),
bcs::to_bytes(&unlock_denominator).unwrap(),
bcs::to_bytes(&unlock_start_time).unwrap(),
bcs::to_bytes(&unlock_duration).unwrap(),
],
))
}

/// Initialize a delegation pool without actual coin but withdraw from the owner's account.
pub fn pbo_delegation_pool_initialize_delegation_pool_with_amount_without_multisig_admin(
amount: u64,
operator_commission_percentage: u64,
delegation_pool_creation_seed: Vec<u8>,
delegator_address: Vec<AccountAddress>,
principle_stake: Vec<u64>,
unlock_numerators: Vec<u64>,
unlock_denominator: u64,
unlock_start_time: u64,
unlock_duration: u64,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("pbo_delegation_pool").to_owned(),
),
ident_str!("initialize_delegation_pool_with_amount_without_multisig_admin").to_owned(),
vec![],
vec![
bcs::to_bytes(&amount).unwrap(),
bcs::to_bytes(&operator_commission_percentage).unwrap(),
bcs::to_bytes(&delegation_pool_creation_seed).unwrap(),
bcs::to_bytes(&delegator_address).unwrap(),
bcs::to_bytes(&principle_stake).unwrap(),
bcs::to_bytes(&unlock_numerators).unwrap(),
bcs::to_bytes(&unlock_denominator).unwrap(),
bcs::to_bytes(&unlock_start_time).unwrap(),
bcs::to_bytes(&unlock_duration).unwrap(),
],
))
}

/// Updates the `principle_stake` of each `delegator` in `delegators` according to the amount specified
/// at the corresponding index of `new_principle_stakes`. Also ensures that the `delegator`'s `active` stake
/// is as close to the specified amount as possible. The locked amount is subject to the vesting schedule
Expand Down Expand Up @@ -3532,6 +3704,39 @@ pub fn pbo_delegation_pool_update_commission_percentage(
))
}

/// Pre-condition: `cumulative_unlocked_fraction` should be zero, which would indicate that even
/// though there are principle stake holders, none of those have yet called `unlock` on the pool
/// thus it is ``safe'' to change the schedule
/// This is a temporary measure to allow Supra Foundation to change the schedule for those pools
/// there were initialized with ``dummy/default'' schedule. This method must be disabled
/// before external validators are allowed to join the validator set.
pub fn pbo_delegation_pool_update_unlocking_schedule(
pool_address: AccountAddress,
unlock_numerators: Vec<u64>,
unlock_denominator: u64,
unlock_start_time: u64,
unlock_duration: u64,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("pbo_delegation_pool").to_owned(),
),
ident_str!("update_unlocking_schedule").to_owned(),
vec![],
vec![
bcs::to_bytes(&pool_address).unwrap(),
bcs::to_bytes(&unlock_numerators).unwrap(),
bcs::to_bytes(&unlock_denominator).unwrap(),
bcs::to_bytes(&unlock_start_time).unwrap(),
bcs::to_bytes(&unlock_duration).unwrap(),
],
))
}

/// Withdraw `amount` of owned inactive stake from the delegation pool at `pool_address`.
pub fn pbo_delegation_pool_withdraw(
pool_address: AccountAddress,
Expand Down Expand Up @@ -6040,6 +6245,49 @@ mod decoder {
}
}

pub fn pbo_delegation_pool_initialize_delegation_pool_with_amount(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(
EntryFunctionCall::PboDelegationPoolInitializeDelegationPoolWithAmount {
multisig_admin: bcs::from_bytes(script.args().get(0)?).ok()?,
amount: bcs::from_bytes(script.args().get(1)?).ok()?,
operator_commission_percentage: bcs::from_bytes(script.args().get(2)?).ok()?,
delegation_pool_creation_seed: bcs::from_bytes(script.args().get(3)?).ok()?,
delegator_address: bcs::from_bytes(script.args().get(4)?).ok()?,
principle_stake: bcs::from_bytes(script.args().get(5)?).ok()?,
unlock_numerators: bcs::from_bytes(script.args().get(6)?).ok()?,
unlock_denominator: bcs::from_bytes(script.args().get(7)?).ok()?,
unlock_start_time: bcs::from_bytes(script.args().get(8)?).ok()?,
unlock_duration: bcs::from_bytes(script.args().get(9)?).ok()?,
},
)
} else {
None
}
}

pub fn pbo_delegation_pool_initialize_delegation_pool_with_amount_without_multisig_admin(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::PboDelegationPoolInitializeDelegationPoolWithAmountWithoutMultisigAdmin {
amount : bcs::from_bytes(script.args().get(0)?).ok()?,
operator_commission_percentage : bcs::from_bytes(script.args().get(1)?).ok()?,
delegation_pool_creation_seed : bcs::from_bytes(script.args().get(2)?).ok()?,
delegator_address : bcs::from_bytes(script.args().get(3)?).ok()?,
principle_stake : bcs::from_bytes(script.args().get(4)?).ok()?,
unlock_numerators : bcs::from_bytes(script.args().get(5)?).ok()?,
unlock_denominator : bcs::from_bytes(script.args().get(6)?).ok()?,
unlock_start_time : bcs::from_bytes(script.args().get(7)?).ok()?,
unlock_duration : bcs::from_bytes(script.args().get(8)?).ok()?,
})
} else {
None
}
}

pub fn pbo_delegation_pool_lock_delegators_stakes(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
Expand Down Expand Up @@ -6158,6 +6406,24 @@ mod decoder {
}
}

pub fn pbo_delegation_pool_update_unlocking_schedule(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(
EntryFunctionCall::PboDelegationPoolUpdateUnlockingSchedule {
pool_address: bcs::from_bytes(script.args().get(0)?).ok()?,
unlock_numerators: bcs::from_bytes(script.args().get(1)?).ok()?,
unlock_denominator: bcs::from_bytes(script.args().get(2)?).ok()?,
unlock_start_time: bcs::from_bytes(script.args().get(3)?).ok()?,
unlock_duration: bcs::from_bytes(script.args().get(4)?).ok()?,
},
)
} else {
None
}
}

pub fn pbo_delegation_pool_withdraw(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::PboDelegationPoolWithdraw {
Expand Down Expand Up @@ -7410,6 +7676,11 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
"pbo_delegation_pool_fund_delegators_with_stake".to_string(),
Box::new(decoder::pbo_delegation_pool_fund_delegators_with_stake),
);
map.insert(
"pbo_delegation_pool_initialize_delegation_pool_with_amount".to_string(),
Box::new(decoder::pbo_delegation_pool_initialize_delegation_pool_with_amount),
);
map.insert("pbo_delegation_pool_initialize_delegation_pool_with_amount_without_multisig_admin".to_string(), Box::new(decoder::pbo_delegation_pool_initialize_delegation_pool_with_amount_without_multisig_admin));
map.insert(
"pbo_delegation_pool_lock_delegators_stakes".to_string(),
Box::new(decoder::pbo_delegation_pool_lock_delegators_stakes),
Expand Down Expand Up @@ -7446,6 +7717,10 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
"pbo_delegation_pool_update_commission_percentage".to_string(),
Box::new(decoder::pbo_delegation_pool_update_commission_percentage),
);
map.insert(
"pbo_delegation_pool_update_unlocking_schedule".to_string(),
Box::new(decoder::pbo_delegation_pool_update_unlocking_schedule),
);
map.insert(
"pbo_delegation_pool_withdraw".to_string(),
Box::new(decoder::pbo_delegation_pool_withdraw),
Expand Down
Loading