Skip to content

Commit

Permalink
resolve conflict with dev
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoshisupra committed Jan 1, 2025
2 parents eb6464f + 2e35dbe commit fdb5c4f
Show file tree
Hide file tree
Showing 7 changed files with 2,978 additions and 595 deletions.
13 changes: 7 additions & 6 deletions aptos-move/aptos-gas-schedule-updator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ fn generate_script(gas_schedule: &GasScheduleV2) -> Result<String> {
emitln!(writer, "script {");
writer.indent();

emitln!(writer, "use aptos_framework::supra_governance;");
emitln!(writer, "use aptos_framework::gas_schedule;");
emitln!(writer, "use supra_framework::supra_governance;");
emitln!(writer, "use supra_framework::gas_schedule;");
emitln!(writer);

emitln!(writer, "fun main(proposal_id: u64) {");
writer.indent();

emitln!(
writer,
"let framework_signer = supra_governance::resolve(proposal_id, @{});\n",
"let framework_signer = supra_governance::supra_resolve(proposal_id, @{});\n",
AccountAddress::ONE,
);

Expand All @@ -83,8 +83,9 @@ fn generate_script(gas_schedule: &GasScheduleV2) -> Result<String> {

emitln!(
writer,
"gas_schedule::set_gas_schedule(&framework_signer, gas_schedule_blob);"
"gas_schedule::set_for_next_epoch(&framework_signer, gas_schedule_blob);"
);
emitln!(writer, "supra_governance::reconfigure(&framework_signer);");

writer.unindent();
emitln!(writer, "}");
Expand All @@ -98,7 +99,7 @@ fn generate_script(gas_schedule: &GasScheduleV2) -> Result<String> {
fn aptos_framework_path() -> PathBuf {
Path::join(
Path::new(env!("CARGO_MANIFEST_DIR")),
"../framework/aptos-framework",
"../framework/supra-framework",
)
}

Expand Down Expand Up @@ -133,7 +134,7 @@ pub fn generate_update_proposal(args: &GenArgs) -> Result<()> {
&generate_script(&current_gas_schedule(feature_version))?,
);
// TODO: use relative path here
pack.add_local_dep("AptosFramework", &aptos_framework_path().to_string_lossy());
pack.add_local_dep("SupraFramework", &aptos_framework_path().to_string_lossy());

pack.write_to_disk(args.output.as_deref().unwrap_or("./proposal"))?;

Expand Down
11 changes: 11 additions & 0 deletions aptos-move/framework/aptos-stdlib/sources/fixed_point64.move
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ module aptos_std::fixed_point64 {
(val * multiplier.value) >> 64
}

public fun multiply_u128_return_fixpoint64(val: u128, multiplier: FixedPoint64): FixedPoint64 {
// The product of two 128 bit values has 256 bits, so perform the
// multiplication with u256 types and keep the full 256 bit product
// to avoid losing accuracy.
let unscaled_product = (val as u256) * (multiplier.value as u256);
// Check whether the value is too large.
assert!(unscaled_product <= MAX_U128, EMULTIPLICATION);
create_from_raw_value((unscaled_product as u128))
}


/// Divide a u128 integer by a fixed-point number, truncating any
/// fractional part of the quotient. This will abort if the divisor
/// is zero or if the quotient overflows.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,21 @@ pub enum EntryFunctionCall {
stakes: Vec<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
/// specified when the delegation pool corresponding to `pool_address` was created.
///
/// Note that this function is only temporarily intended to work as specified above and exists to enable The
/// Supra Foundation to ensure that the allocations of all investors are subject to the terms specified in the
/// corresponding legal contracts. It will be deactivated before the validator set it opened up to external
/// validator-owners to prevent it from being abused.
PboDelegationPoolLockDelegatorsStakes {
pool_address: AccountAddress,
delegators: Vec<AccountAddress>,
new_principle_stakes: Vec<u64>,
},

/// Move `amount` of coins from pending_inactive to active.
PboDelegationPoolReactivateStake {
pool_address: AccountAddress,
Expand All @@ -560,6 +575,11 @@ pub enum EntryFunctionCall {
/// rightful owner of `old_delegator` but has lost access and the delegator is also the rightful
/// owner of `new_delegator` , Only for those stakeholders which were added at the time of creation
/// This does not apply to anyone who added stake later or operator
///
/// Note that this function is only temporarily intended to work as specified above and exists to enable The
/// Supra Foundation to ensure that the allocations of all investors are subject to the terms specified in the
/// corresponding legal contracts. It will be deactivated before the validator set it opened up to external
/// validator-owners to prevent it from being abused.
PboDelegationPoolReplaceDelegator {
pool_address: AccountAddress,
old_delegator: AccountAddress,
Expand Down Expand Up @@ -1510,6 +1530,15 @@ impl EntryFunctionCall {
delegators,
stakes,
} => pbo_delegation_pool_fund_delegators_with_stake(pool_address, delegators, stakes),
PboDelegationPoolLockDelegatorsStakes {
pool_address,
delegators,
new_principle_stakes,
} => pbo_delegation_pool_lock_delegators_stakes(
pool_address,
delegators,
new_principle_stakes,
),
PboDelegationPoolReactivateStake {
pool_address,
amount,
Expand Down Expand Up @@ -3307,6 +3336,38 @@ pub fn pbo_delegation_pool_fund_delegators_with_stake(
))
}

/// 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
/// specified when the delegation pool corresponding to `pool_address` was created.
///
/// Note that this function is only temporarily intended to work as specified above and exists to enable The
/// Supra Foundation to ensure that the allocations of all investors are subject to the terms specified in the
/// corresponding legal contracts. It will be deactivated before the validator set it opened up to external
/// validator-owners to prevent it from being abused.
pub fn pbo_delegation_pool_lock_delegators_stakes(
pool_address: AccountAddress,
delegators: Vec<AccountAddress>,
new_principle_stakes: Vec<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!("lock_delegators_stakes").to_owned(),
vec![],
vec![
bcs::to_bytes(&pool_address).unwrap(),
bcs::to_bytes(&delegators).unwrap(),
bcs::to_bytes(&new_principle_stakes).unwrap(),
],
))
}

/// Move `amount` of coins from pending_inactive to active.
pub fn pbo_delegation_pool_reactivate_stake(
pool_address: AccountAddress,
Expand All @@ -3333,6 +3394,11 @@ pub fn pbo_delegation_pool_reactivate_stake(
/// rightful owner of `old_delegator` but has lost access and the delegator is also the rightful
/// owner of `new_delegator` , Only for those stakeholders which were added at the time of creation
/// This does not apply to anyone who added stake later or operator
///
/// Note that this function is only temporarily intended to work as specified above and exists to enable The
/// Supra Foundation to ensure that the allocations of all investors are subject to the terms specified in the
/// corresponding legal contracts. It will be deactivated before the validator set it opened up to external
/// validator-owners to prevent it from being abused.
pub fn pbo_delegation_pool_replace_delegator(
pool_address: AccountAddress,
old_delegator: AccountAddress,
Expand Down Expand Up @@ -5974,6 +6040,20 @@ mod decoder {
}
}

pub fn pbo_delegation_pool_lock_delegators_stakes(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::PboDelegationPoolLockDelegatorsStakes {
pool_address: bcs::from_bytes(script.args().get(0)?).ok()?,
delegators: bcs::from_bytes(script.args().get(1)?).ok()?,
new_principle_stakes: bcs::from_bytes(script.args().get(2)?).ok()?,
})
} else {
None
}
}

pub fn pbo_delegation_pool_reactivate_stake(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
Expand Down Expand Up @@ -7330,6 +7410,10 @@ 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_lock_delegators_stakes".to_string(),
Box::new(decoder::pbo_delegation_pool_lock_delegators_stakes),
);
map.insert(
"pbo_delegation_pool_reactivate_stake".to_string(),
Box::new(decoder::pbo_delegation_pool_reactivate_stake),
Expand Down
10 changes: 10 additions & 0 deletions aptos-move/framework/move-stdlib/sources/fixed_point32.move
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ module std::fixed_point32 {
(val * multiplier.value) >> 32
}

public fun multiply_u64_return_fixpoint32(val: u64, multiplier: FixedPoint32): FixedPoint32 {
// The product of two 64 bit values has 128 bits, so perform the
// multiplication with u128 types and keep the full 128 bit product
// to avoid losing accuracy.
let unscaled_product = (val as u128) * (multiplier.value as u128);
// Check whether the value is too large.
assert!(unscaled_product <= MAX_U64, EMULTIPLICATION);
create_from_raw_value((unscaled_product as u64))
}

/// Divide a u64 integer by a fixed-point number, truncating any
/// fractional part of the quotient. This will abort if the divisor
/// is zero or if the quotient overflows.
Expand Down
Loading

0 comments on commit fdb5c4f

Please sign in to comment.