diff --git a/api/types/src/convert.rs b/api/types/src/convert.rs index 3d428e388593a..719c46abab2e1 100644 --- a/api/types/src/convert.rs +++ b/api/types/src/convert.rs @@ -1,8 +1,7 @@ +// Copyright (c) 2024 Supra. // Copyright © Aptos Foundation // Parts of the project are originally copyright © Meta Platforms, Inc. // SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2024 Supra. use crate::{ transaction::{ diff --git a/api/types/src/transaction.rs b/api/types/src/transaction.rs index f3f0b525558be..2c063727f0443 100755 --- a/api/types/src/transaction.rs +++ b/api/types/src/transaction.rs @@ -1,8 +1,7 @@ +// Copyright (c) 2024 Supra. // Copyright © Aptos Foundation // Parts of the project are originally copyright © Meta Platforms, Inc. // SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2024 Supra. use crate::{ Address, AptosError, EntryFunctionId, EventGuid, HashValue, HexEncodedBytes, diff --git a/aptos-move/aptos-gas-schedule/src/gas_schedule/aptos_framework.rs b/aptos-move/aptos-gas-schedule/src/gas_schedule/aptos_framework.rs index b5deaba210745..7d3c92bea7c49 100644 --- a/aptos-move/aptos-gas-schedule/src/gas_schedule/aptos_framework.rs +++ b/aptos-move/aptos-gas-schedule/src/gas_schedule/aptos_framework.rs @@ -1,7 +1,6 @@ +// Copyright (c) 2024 Supra. // Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2024 Supra. //! This module defines the gas parameters for Aptos Framework & Stdlib. diff --git a/aptos-move/aptos-vm/src/aptos_vm.rs b/aptos-move/aptos-vm/src/aptos_vm.rs index c6aecd8125340..b6502745dc343 100644 --- a/aptos-move/aptos-vm/src/aptos_vm.rs +++ b/aptos-move/aptos-vm/src/aptos_vm.rs @@ -1,8 +1,7 @@ +// Copyright (c) 2024 Supra. // Copyright © Aptos Foundation // Parts of the project are originally copyright © Meta Platforms, Inc. // SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2024 Supra. use crate::{ block_executor::{AptosTransactionOutput, BlockAptosVM}, diff --git a/aptos-move/aptos-vm/src/transaction_metadata.rs b/aptos-move/aptos-vm/src/transaction_metadata.rs index 4d5eadcd9424f..a536e4648eaa8 100644 --- a/aptos-move/aptos-vm/src/transaction_metadata.rs +++ b/aptos-move/aptos-vm/src/transaction_metadata.rs @@ -1,8 +1,7 @@ +// Copyright (c) 2024 Supra. // Copyright © Aptos Foundation // Parts of the project are originally copyright © Meta Platforms, Inc. // SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2024 Supra. use aptos_crypto::HashValue; use aptos_gas_algebra::{FeePerGasUnit, Gas, NumBytes}; diff --git a/aptos-move/framework/aptos-stdlib/sources/cryptography/bls12381.move b/aptos-move/framework/aptos-stdlib/sources/cryptography/bls12381.move index de7d05ad8b18b..a42621a1d7ba3 100644 --- a/aptos-move/framework/aptos-stdlib/sources/cryptography/bls12381.move +++ b/aptos-move/framework/aptos-stdlib/sources/cryptography/bls12381.move @@ -480,7 +480,7 @@ module aptos_std::bls12381 { // /// Random signature generated by running `cargo test -- bls12381_sample_signature --nocapture --include-ignored` in `crates/aptos-crypto`. - /// The message signed is "Hello Aptos!" and the associated SK is 07416693b6b32c84abe45578728e2379f525729e5b94762435a31e65ecc728da. + /// The message signed is "Hello Supra!" and the associated SK is 07416693b6b32c84abe45578728e2379f525729e5b94762435a31e65ecc728da. const RANDOM_SIGNATURE: vector = x"a01a65854f987d3434149b7f08f70730e30b241984e8712bc2aca885d632aafced4c3f661209debb6b1c8601326623cc16ca2f6c9edc53b7b88b7435fb6b05ddece418d2c34dc6aca2f5a11a79e67774582c14084a01dcb7820e4cb4bad0ea8d"; /// Random signature generated by running `cargo test -- bls12381_sample_signature --nocapture --include-ignored` in `crates/aptos-crypto`. diff --git a/aptos-move/framework/aptos-stdlib/sources/cryptography/ed25519.move b/aptos-move/framework/aptos-stdlib/sources/cryptography/ed25519.move index 0f8d9c8122970..6e5dfec654bc5 100644 --- a/aptos-move/framework/aptos-stdlib/sources/cryptography/ed25519.move +++ b/aptos-move/framework/aptos-stdlib/sources/cryptography/ed25519.move @@ -21,7 +21,7 @@ module aptos_std::ed25519 { // Constants // - /// The identifier of the Ed25519 signature scheme, which is used when deriving Aptos authentication keys by hashing + /// The identifier of the Ed25519 signature scheme, which is used when deriving Supra authentication keys by hashing /// it together with an Ed25519 public key. const SIGNATURE_SCHEME_ID: u8 = 0; @@ -156,17 +156,17 @@ module aptos_std::ed25519 { } } - /// Derives the Aptos-specific authentication key of the given Ed25519 public key. + /// Derives the Supra-specific authentication key of the given Ed25519 public key. public fun unvalidated_public_key_to_authentication_key(pk: &UnvalidatedPublicKey): vector { public_key_bytes_to_authentication_key(pk.bytes) } - /// Derives the Aptos-specific authentication key of the given Ed25519 public key. + /// Derives the Supra-specific authentication key of the given Ed25519 public key. public fun validated_public_key_to_authentication_key(pk: &ValidatedPublicKey): vector { public_key_bytes_to_authentication_key(pk.bytes) } - /// Derives the Aptos-specific authentication key of the given Ed25519 public key. + /// Derives the Supra-specific authentication key of the given Ed25519 public key. fun public_key_bytes_to_authentication_key(pk_bytes: vector): vector { std::vector::push_back(&mut pk_bytes, SIGNATURE_SCHEME_ID); std::hash::sha3_256(pk_bytes) diff --git a/aptos-move/framework/aptos-stdlib/sources/cryptography/multi_ed25519.move b/aptos-move/framework/aptos-stdlib/sources/cryptography/multi_ed25519.move index f1f97bc635720..969c0dec52a98 100644 --- a/aptos-move/framework/aptos-stdlib/sources/cryptography/multi_ed25519.move +++ b/aptos-move/framework/aptos-stdlib/sources/cryptography/multi_ed25519.move @@ -29,7 +29,7 @@ module aptos_std::multi_ed25519 { // Constants // - /// The identifier of the MultiEd25519 signature scheme, which is used when deriving Aptos authentication keys by hashing + /// The identifier of the MultiEd25519 signature scheme, which is used when deriving Supra authentication keys by hashing /// it together with an MultiEd25519 public key. const SIGNATURE_SCHEME_ID: u8 = 1; @@ -232,7 +232,7 @@ module aptos_std::multi_ed25519 { signature_verify_strict_internal(multisignature.bytes, public_key.bytes, bcs::to_bytes(&encoded)) } - /// Derives the Aptos-specific authentication key of the given Ed25519 public key. + /// Derives the Supra-specific authentication key of the given Ed25519 public key. public fun unvalidated_public_key_to_authentication_key(pk: &UnvalidatedPublicKey): vector { public_key_bytes_to_authentication_key(pk.bytes) } @@ -255,7 +255,7 @@ module aptos_std::multi_ed25519 { check_and_get_threshold(pk.bytes) } - /// Derives the Aptos-specific authentication key of the given Ed25519 public key. + /// Derives the Supra-specific authentication key of the given Ed25519 public key. public fun validated_public_key_to_authentication_key(pk: &ValidatedPublicKey): vector { public_key_bytes_to_authentication_key(pk.bytes) } @@ -298,7 +298,7 @@ module aptos_std::multi_ed25519 { } } - /// Derives the Aptos-specific authentication key of the given Ed25519 public key. + /// Derives the Supra-specific authentication key of the given Ed25519 public key. fun public_key_bytes_to_authentication_key(pk_bytes: vector): vector { vector::push_back(&mut pk_bytes, SIGNATURE_SCHEME_ID); std::hash::sha3_256(pk_bytes) diff --git a/aptos-move/framework/aptos-token-objects/sources/collection.move b/aptos-move/framework/aptos-token-objects/sources/collection.move index 7fd1eac1b559a..7bc46214228d0 100644 --- a/aptos-move/framework/aptos-token-objects/sources/collection.move +++ b/aptos-move/framework/aptos-token-objects/sources/collection.move @@ -180,7 +180,7 @@ module aptos_token_objects::collection { /// Creates a fixed-sized collection, or a collection that supports a fixed amount of tokens. /// This is useful to create a guaranteed, limited supply on-chain digital asset. For example, /// a collection 1111 vicious vipers. Note, creating restrictions such as upward limits results - /// in data structures that prevent Aptos from parallelizing mints of this collection type. + /// in data structures that prevent Supra from parallelizing mints of this collection type. /// Beyond that, it adds supply tracking with events. public fun create_fixed_collection( creator: &signer, @@ -239,7 +239,7 @@ module aptos_token_objects::collection { } /// Creates an untracked collection, or a collection that supports an arbitrary amount of - /// tokens. This is useful for mass airdrops that fully leverage Aptos parallelization. + /// tokens. This is useful for mass airdrops that fully leverage Supra parallelization. /// TODO: Hide this until we bring back meaningful way to enforce burns fun create_untracked_collection( creator: &signer, diff --git a/aptos-move/framework/aptos-token-objects/sources/token.move b/aptos-move/framework/aptos-token-objects/sources/token.move index 06bd1d44066e4..d14e82ac1fd14 100644 --- a/aptos-move/framework/aptos-token-objects/sources/token.move +++ b/aptos-move/framework/aptos-token-objects/sources/token.move @@ -1,4 +1,4 @@ -/// This defines an object-based Token. The key differentiating features from the Aptos standard +/// This defines an object-based Token. The key differentiating features from the Supra standard /// token are: /// * Decoupled token ownership from token data. /// * Explicit data model for token metadata via adjacent resources @@ -56,7 +56,7 @@ module aptos_token_objects::token { /// Was populated until concurrent_token_v2_enabled feature flag was enabled. /// /// The name of the token, which should be unique within the collection; the length of name - /// should be smaller than 128, characters, eg: "Aptos Animal #1234" + /// should be smaller than 128, characters, eg: "Supra Animal #1234" name: String, // DEPRECATED /// The Uniform Resource Identifier (uri) pointing to the JSON file stored in off-chain @@ -73,7 +73,7 @@ module aptos_token_objects::token { /// Unique identifier within the collection, optional, 0 means unassigned index: AggregatorSnapshot, /// The name of the token, which should be unique within the collection; the length of name - /// should be smaller than 128, characters, eg: "Aptos Animal #1234" + /// should be smaller than 128, characters, eg: "Supra Animal #1234" name: DerivedStringSnapshot, } diff --git a/aptos-move/framework/aptos-token/sources/token.move b/aptos-move/framework/aptos-token/sources/token.move index c7b329fb58bd7..059882e969431 100644 --- a/aptos-move/framework/aptos-token/sources/token.move +++ b/aptos-move/framework/aptos-token/sources/token.move @@ -177,7 +177,7 @@ module aptos_token::token { struct TokenDataId has copy, drop, store { /// The address of the creator, eg: 0xcafe creator: address, - /// The name of collection; this is unique under the same account, eg: "Aptos Animal Collection" + /// The name of collection; this is unique under the same account, eg: "Supra Animal Collection" collection: String, /// The name of the token; this is the same as the name field of TokenData name: String, @@ -195,7 +195,7 @@ module aptos_token::token { uri: String, /// The denominator and numerator for calculating the royalty fee; it also contains payee account address for depositing the Royalty royalty: Royalty, - /// The name of the token, which should be unique within the collection; the length of name should be smaller than 128, characters, eg: "Aptos Animal #1234" + /// The name of the token, which should be unique within the collection; the length of name should be smaller than 128, characters, eg: "Supra Animal #1234" name: String, /// Describes this Token description: String, @@ -260,7 +260,7 @@ module aptos_token::token { /// Represent the collection metadata struct CollectionData has store { - /// A description for the token collection Eg: "Aptos Toad Overload" + /// A description for the token collection Eg: "Supra Toad Overload" description: String, /// The collection name, which should be unique among all collections by the creator; the name should also be smaller than 128 characters, eg: "Animal Collection" name: String, @@ -269,7 +269,7 @@ module aptos_token::token { /// The number of different TokenData entries in this collection supply: u64, /// If maximal is a non-zero value, the number of created TokenData entries should be smaller or equal to this maximum - /// If maximal is 0, Aptos doesn't track the supply of this collection, and there is no limit + /// If maximal is 0, Supra doesn't track the supply of this collection, and there is no limit maximum: u64, /// control which collectionData field is mutable mutability_config: CollectionMutabilityConfig, diff --git a/aptos-move/framework/move-stdlib/sources/configs/features.move b/aptos-move/framework/move-stdlib/sources/configs/features.move index 8fbe0984859ae..d3800e3dabf88 100644 --- a/aptos-move/framework/move-stdlib/sources/configs/features.move +++ b/aptos-move/framework/move-stdlib/sources/configs/features.move @@ -1,5 +1,5 @@ -/// Defines feature flags for Aptos. Those are used in Aptos specific implementations of features in -/// the Move stdlib, the Aptos stdlib, and the Aptos framework. +/// Defines feature flags for Supra. Those are used in Supra specific implementations of features in +/// the Move stdlib, the Supra stdlib, and the Supra framework. /// /// ============================================================================================ /// Feature Flag Definitions diff --git a/aptos-move/framework/src/natives/transaction_context.rs b/aptos-move/framework/src/natives/transaction_context.rs index 6965a2d7d3453..54638ad4ed421 100644 --- a/aptos-move/framework/src/natives/transaction_context.rs +++ b/aptos-move/framework/src/natives/transaction_context.rs @@ -1,7 +1,6 @@ +// Copyright (c) 2024 Supra. // Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 -// -// Copyright (c) 2024 Supra. use aptos_gas_schedule::gas_params::natives::aptos_framework::*; use aptos_native_interface::{ diff --git a/aptos-move/framework/supra-framework/doc/aggregator_factory.md b/aptos-move/framework/supra-framework/doc/aggregator_factory.md index a731f537bc88c..b2a20d5d13908 100644 --- a/aptos-move/framework/supra-framework/doc/aggregator_factory.md +++ b/aptos-move/framework/supra-framework/doc/aggregator_factory.md @@ -217,7 +217,7 @@ Returns a new aggregator. 2 To create a new aggregator instance, the aggregator factory must already be initialized and exist under the Supra account. High -The create_aggregator_internal function asserts that AggregatorFactory exists for the Supra account. +The create_aggregator_internal function asserts that AggregatorFactory exists for the Aptos account. Formally verified via CreateAggregatorInternalAbortsIf. diff --git a/aptos-move/framework/supra-framework/doc/block.md b/aptos-move/framework/supra-framework/doc/block.md index cd6b2ab647d8b..51c418a64bd73 100644 --- a/aptos-move/framework/supra-framework/doc/block.md +++ b/aptos-move/framework/supra-framework/doc/block.md @@ -924,7 +924,7 @@ new block event for WriteSetPayload. 1 -During the module's initialization, it guarantees that the BlockResource resource moves under the Supra framework account with initial values. +During the module's initialization, it guarantees that the BlockResource resource moves under the Aptos framework account with initial values. High The initialize function is responsible for setting up the initial state of the module, ensuring that the following conditions are met (1) the BlockResource resource is created, indicating its existence within the module's context, and moved under the Supra framework account, (2) the block height is set to zero during initialization, and (3) the epoch interval is greater than zero. Formally Verified via Initialize. diff --git a/aptos-move/framework/supra-framework/doc/chain_id.md b/aptos-move/framework/supra-framework/doc/chain_id.md index 9584e32a83824..bf1ee60187528 100644 --- a/aptos-move/framework/supra-framework/doc/chain_id.md +++ b/aptos-move/framework/supra-framework/doc/chain_id.md @@ -129,7 +129,7 @@ Return the chain ID of this instance. 2 -The chain id can only be fetched if the chain id resource exists under the Supra framework account. +The chain id can only be fetched if the chain id resource exists under the Aptos framework account. Low The chain_id::get function fetches the chain id by borrowing the ChainId resource from the supra_framework account. Formally verified via get. diff --git a/aptos-move/framework/supra-framework/doc/genesis.md b/aptos-move/framework/supra-framework/doc/genesis.md index 8823b5d9a6d32..000797d28384f 100644 --- a/aptos-move/framework/supra-framework/doc/genesis.md +++ b/aptos-move/framework/supra-framework/doc/genesis.md @@ -797,17 +797,23 @@ If it exists, it just returns the signer. Implementation -
fun create_multiple_multisig_accounts_with_schema(supra_framework: &signer,
-owner: address, additional_owners: vector<address>,num_signatures_required:u64,metadata_keys:vector<String>,metadata_values:vector<vector<u8>>,
-timeout_duration:u64, balance:u64, num_of_accounts: u32): vector<address> {
-
+
fun create_multiple_multisig_accounts_with_schema(
+    supra_framework: &signer,
+    owner: address,
+    additional_owners: vector<address>,
+    num_signatures_required:u64,
+    metadata_keys:vector<String>,
+    metadata_values:vector<vector<u8>>,
+    timeout_duration:u64,
+    balance:u64,
+    num_of_accounts: u32
+): vector<address> {
     let counter = 0;
     let result = vector::empty();
     while (counter < num_of_accounts) {
         let account_addr = create_multisig_account_with_balance(supra_framework, owner, additional_owners,
                             num_signatures_required,metadata_keys,metadata_values,timeout_duration,balance);
         vector::push_back(&mut result,account_addr);
-        account::increment_sequence_number(owner);
         counter = counter + 1;
     };
     result
@@ -833,20 +839,25 @@ timeout_duration:u64, balance:u64, num_of_accounts: u32): create_multisig_account_with_balance(supra_framework: &signer, owner: address, additional_owners: vector<address>,
-                            num_signatures_required:u64, metadata_keys: vector<String>,
-                            metadata_values: vector<vector<u8>>, timeout_duration: u64, balance:u64 ) : address {
-
-
+
fun create_multisig_account_with_balance(
+    supra_framework: &signer,
+    owner: address,
+    additional_owners: vector<address>,
+    num_signatures_required:u64,
+    metadata_keys: vector<String>,
+    metadata_values: vector<vector<u8>>,
+    timeout_duration: u64,
+    balance:u64,
+): address {
     assert!(account::exists_at(owner),error::invalid_argument(EACCOUNT_DOES_NOT_EXIST));
     assert!(vector::all(&additional_owners,|ao_addr|{account::exists_at(*ao_addr)}),error::invalid_argument(EACCOUNT_DOES_NOT_EXIST));
     let addr = multisig_account::get_next_multisig_account_address(owner);
     let owner_signer = create_signer(owner);
     multisig_account::create_with_owners(&owner_signer,additional_owners,num_signatures_required,metadata_keys,metadata_values,timeout_duration);
     supra_coin::mint(supra_framework,addr,balance);
+    account::increment_sequence_number(owner);
     addr
-
-    }
+}
 
diff --git a/aptos-move/framework/supra-framework/doc/pbo_delegation_pool.md b/aptos-move/framework/supra-framework/doc/pbo_delegation_pool.md index f46534674a0f6..5ca21e1694513 100644 --- a/aptos-move/framework/supra-framework/doc/pbo_delegation_pool.md +++ b/aptos-move/framework/supra-framework/doc/pbo_delegation_pool.md @@ -158,6 +158,9 @@ transferred to A - [Function `get_expected_stake_pool_address`](#0x1_pbo_delegation_pool_get_expected_stake_pool_address) - [Function `min_remaining_secs_for_commission_change`](#0x1_pbo_delegation_pool_min_remaining_secs_for_commission_change) - [Function `initialize_delegation_pool`](#0x1_pbo_delegation_pool_initialize_delegation_pool) +- [Function `fund_delegators_with_locked_stake`](#0x1_pbo_delegation_pool_fund_delegators_with_locked_stake) +- [Function `fund_delegators_with_stake`](#0x1_pbo_delegation_pool_fund_delegators_with_stake) +- [Function `is_admin`](#0x1_pbo_delegation_pool_is_admin) - [Function `get_admin`](#0x1_pbo_delegation_pool_get_admin) - [Function `beneficiary_for_operator`](#0x1_pbo_delegation_pool_beneficiary_for_operator) - [Function `enable_partial_governance_voting`](#0x1_pbo_delegation_pool_enable_partial_governance_voting) @@ -187,9 +190,12 @@ transferred to A - [Function `set_delegated_voter`](#0x1_pbo_delegation_pool_set_delegated_voter) - [Function `delegate_voting_power`](#0x1_pbo_delegation_pool_delegate_voting_power) - [Function `add_stake_initialization`](#0x1_pbo_delegation_pool_add_stake_initialization) +- [Function `fund_delegator_stake`](#0x1_pbo_delegation_pool_fund_delegator_stake) - [Function `add_stake`](#0x1_pbo_delegation_pool_add_stake) - [Function `replace_in_smart_tables`](#0x1_pbo_delegation_pool_replace_in_smart_tables) - [Function `replace_delegator`](#0x1_pbo_delegation_pool_replace_delegator) +- [Function `is_principle_stakeholder`](#0x1_pbo_delegation_pool_is_principle_stakeholder) +- [Function `get_principle_stake`](#0x1_pbo_delegation_pool_get_principle_stake) - [Function `cached_unlockable_balance`](#0x1_pbo_delegation_pool_cached_unlockable_balance) - [Function `can_principle_unlock`](#0x1_pbo_delegation_pool_can_principle_unlock) - [Function `unlock`](#0x1_pbo_delegation_pool_unlock) @@ -1762,8 +1768,8 @@ Return whether a delegation pool has already enabled partial govnernance voting.
public fun partial_governance_voting_enabled(pool_address: address): bool {
-    exists<GovernanceRecords>(pool_address) && stake::get_delegated_voter(pool_address) ==
-         pool_address
+    exists<GovernanceRecords>(pool_address)
+        && stake::get_delegated_voter(pool_address) == pool_address
 }
 
@@ -1815,9 +1821,12 @@ Return whether the commission percentage for the next lockup cycle is effective. Implementation -
public fun is_next_commission_percentage_effective(pool_address: address): bool acquires NextCommissionPercentage {
-    exists<NextCommissionPercentage>(pool_address) && timestamp::now_seconds() >= borrow_global<
-        NextCommissionPercentage>(pool_address).effective_after_secs
+
public fun is_next_commission_percentage_effective(
+    pool_address: address
+): bool acquires NextCommissionPercentage {
+    exists<NextCommissionPercentage>(pool_address)
+        && timestamp::now_seconds()
+            >= borrow_global<NextCommissionPercentage>(pool_address).effective_after_secs
 }
 
@@ -1842,7 +1851,9 @@ Return the operator commission percentage set on the delegation pool pool_ Implementation -
public fun operator_commission_percentage(pool_address: address): u64 acquires DelegationPool, NextCommissionPercentage {
+
public fun operator_commission_percentage(
+    pool_address: address
+): u64 acquires DelegationPool, NextCommissionPercentage {
     assert_delegation_pool_exists(pool_address);
     if (is_next_commission_percentage_effective(pool_address)) {
         operator_commission_percentage_next_lockup_cycle(pool_address)
@@ -1873,7 +1884,9 @@ Return the operator commission percentage for the next lockup cycle.
 Implementation
 
 
-
public fun operator_commission_percentage_next_lockup_cycle(pool_address: address): u64 acquires DelegationPool, NextCommissionPercentage {
+
public fun operator_commission_percentage_next_lockup_cycle(
+    pool_address: address
+): u64 acquires DelegationPool, NextCommissionPercentage {
     assert_delegation_pool_exists(pool_address);
     if (exists<NextCommissionPercentage>(pool_address)) {
         borrow_global<NextCommissionPercentage>(pool_address).commission_percentage_next_lockup_cycle
@@ -1906,7 +1919,9 @@ Return the number of delegators owning active stake within pool_addresspublic fun shareholders_count_active_pool(pool_address: address): u64 acquires DelegationPool {
     assert_delegation_pool_exists(pool_address);
-    pool_u64::shareholders_count(&borrow_global<DelegationPool>(pool_address).active_shares)
+    pool_u64::shareholders_count(
+        &borrow_global<DelegationPool>(pool_address).active_shares
+    )
 }
 
@@ -1960,31 +1975,32 @@ some stake and the stake pool's lockup cycle has not ended, their coins are not Implementation -
public fun get_pending_withdrawal(pool_address: address, delegator_address: address)
-    : (bool, u64) acquires DelegationPool {
+
public fun get_pending_withdrawal(
+    pool_address: address, delegator_address: address
+): (bool, u64) acquires DelegationPool {
     assert_delegation_pool_exists(pool_address);
     let pool = borrow_global<DelegationPool>(pool_address);
-    let (lockup_cycle_ended, _, pending_inactive, _, commission_pending_inactive) = calculate_stake_pool_drift(
-        pool
-    );
+    let (lockup_cycle_ended, _, pending_inactive, _, commission_pending_inactive) =
+        calculate_stake_pool_drift(pool);
 
-    let (withdrawal_exists, withdrawal_olc) = pending_withdrawal_exists(pool,
-        delegator_address);
+    let (withdrawal_exists, withdrawal_olc) =
+        pending_withdrawal_exists(pool, delegator_address);
     if (!withdrawal_exists) {
         // if no pending withdrawal, there is neither inactive nor pending_inactive stake
-        (false, 0) } else {
+        (false, 0)
+    } else {
         // delegator has either inactive or pending_inactive stake due to automatic withdrawals
         let inactive_shares = table::borrow(&pool.inactive_shares, withdrawal_olc);
         if (withdrawal_olc.index < pool.observed_lockup_cycle.index) {
             // if withdrawal's lockup cycle ended on delegation pool then it is inactive
             (true, pool_u64::balance(inactive_shares, delegator_address))
-        }
-        else {
+        } else {
             pending_inactive = pool_u64::shares_to_amount_with_total_coins(
                 inactive_shares,
                 pool_u64::shares(inactive_shares, delegator_address),
                 // exclude operator pending_inactive rewards not converted to shares yet
-                pending_inactive - commission_pending_inactive);
+                pending_inactive - commission_pending_inactive
+            );
             // if withdrawal's lockup cycle ended ONLY on stake pool then it is also inactive
             (lockup_cycle_ended, pending_inactive)
         }
@@ -2014,39 +2030,44 @@ in each of its individual states: (active,inactive,Implementation
 
 
-
public fun get_stake(pool_address: address, delegator_address: address): (u64, u64, u64) acquires DelegationPool, BeneficiaryForOperator {
+
public fun get_stake(
+    pool_address: address, delegator_address: address
+): (u64, u64, u64) acquires DelegationPool, BeneficiaryForOperator {
     assert_delegation_pool_exists(pool_address);
     let pool = borrow_global<DelegationPool>(pool_address);
     let (lockup_cycle_ended, active, _, commission_active, commission_pending_inactive) =
-         calculate_stake_pool_drift(pool);
+
+        calculate_stake_pool_drift(pool);
 
     let total_active_shares = pool_u64::total_shares(&pool.active_shares);
-    let delegator_active_shares = pool_u64::shares(&pool.active_shares,
-        delegator_address);
+    let delegator_active_shares =
+        pool_u64::shares(&pool.active_shares, delegator_address);
 
     let (_, _, pending_active, _) = stake::get_stake(pool_address);
     if (pending_active == 0) {
         // zero `pending_active` stake indicates that either there are no `add_stake` fees or
         // previous epoch has ended and should identify shares owning these fees as released
-        total_active_shares = total_active_shares - pool_u64::shares(&pool.active_shares,
-            NULL_SHAREHOLDER);
+        total_active_shares = total_active_shares
+            - pool_u64::shares(&pool.active_shares, NULL_SHAREHOLDER);
         if (delegator_address == NULL_SHAREHOLDER) {
             delegator_active_shares = 0
         }
     };
-    active = pool_u64::shares_to_amount_with_total_stats(&pool.active_shares,
+    active = pool_u64::shares_to_amount_with_total_stats(
+        &pool.active_shares,
         delegator_active_shares,
         // exclude operator active rewards not converted to shares yet
-        active - commission_active, total_active_shares);
+        active - commission_active,
+        total_active_shares
+    );
 
     // get state and stake (0 if there is none) of the pending withdrawal
-    let (withdrawal_inactive, withdrawal_stake) = get_pending_withdrawal(pool_address,
-        delegator_address);
+    let (withdrawal_inactive, withdrawal_stake) =
+        get_pending_withdrawal(pool_address, delegator_address);
     // report non-active stakes accordingly to the state of the pending withdrawal
-    let (inactive, pending_inactive) = if (withdrawal_inactive)
-        (withdrawal_stake, 0)
-    else
-        (0, withdrawal_stake);
+    let (inactive, pending_inactive) =
+        if (withdrawal_inactive) (withdrawal_stake, 0)
+        else (0, withdrawal_stake);
 
     // should also include commission rewards in case of the operator account
     // operator rewards are actually used to buy shares which is introducing
@@ -2094,19 +2115,21 @@ extracted-fee = (amount - extracted-fee) * reward-rate% * (100% - operator-commi
 Implementation
 
 
-
public fun get_add_stake_fee(pool_address: address, amount: u64): u64 acquires DelegationPool, NextCommissionPercentage {
+
public fun get_add_stake_fee(
+    pool_address: address, amount: u64
+): u64 acquires DelegationPool, NextCommissionPercentage {
     if (stake::is_current_epoch_validator(pool_address)) {
-        let (rewards_rate, rewards_rate_denominator) = staking_config::get_reward_rate(&staking_config::get());
+        let (rewards_rate, rewards_rate_denominator) =
+            staking_config::get_reward_rate(&staking_config::get());
         if (rewards_rate_denominator > 0) {
             assert_delegation_pool_exists(pool_address);
 
-            rewards_rate = rewards_rate * (MAX_FEE - operator_commission_percentage(
-                    pool_address
-                ));
+            rewards_rate = rewards_rate
+                * (MAX_FEE - operator_commission_percentage(pool_address));
             rewards_rate_denominator = rewards_rate_denominator * MAX_FEE;
             (
-                (((amount as u128) * (rewards_rate as u128)) / ((rewards_rate as u128)
-                            + (rewards_rate_denominator as u128))) as u64
+                (((amount as u128) * (rewards_rate as u128))
+                    / ((rewards_rate as u128) + (rewards_rate_denominator as u128))) as u64
             )
         } else { 0 }
     } else { 0 }
@@ -2137,8 +2160,8 @@ the validator had gone inactive before its lockup expired.
 
 
 
public fun can_withdraw_pending_inactive(pool_address: address): bool {
-    stake::get_validator_state(pool_address) == VALIDATOR_STATUS_INACTIVE && timestamp::now_seconds()
-        >= stake::get_lockup_secs(pool_address)
+    stake::get_validator_state(pool_address) == VALIDATOR_STATUS_INACTIVE
+        && timestamp::now_seconds() >= stake::get_lockup_secs(pool_address)
 }
 
@@ -2164,16 +2187,17 @@ latest state. Implementation -
public fun calculate_and_update_voter_total_voting_power(pool_address: address, voter: address)
-    : u64 acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
+
public fun calculate_and_update_voter_total_voting_power(
+    pool_address: address, voter: address
+): u64 acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
     assert_partial_governance_voting_enabled(pool_address);
     // Delegation pool need to be synced to explain rewards(which could change the coin amount) and
     // commission(which could cause share transfer).
     synchronize_delegation_pool(pool_address);
     let pool = borrow_global<DelegationPool>(pool_address);
     let governance_records = borrow_global_mut<GovernanceRecords>(pool_address);
-    let latest_delegated_votes = update_and_borrow_mut_delegated_votes(pool,
-        governance_records, voter);
+    let latest_delegated_votes =
+        update_and_borrow_mut_delegated_votes(pool, governance_records, voter);
     calculate_total_voting_power(pool, latest_delegated_votes)
 }
 
@@ -2204,11 +2228,11 @@ latest state. pool_address: address, delegator_address: address ): address acquires DelegationPool, GovernanceRecords { assert_partial_governance_voting_enabled(pool_address); - calculate_and_update_delegator_voter_internal(borrow_global<DelegationPool>( - pool_address - ), + calculate_and_update_delegator_voter_internal( + borrow_global<DelegationPool>(pool_address), borrow_global_mut<GovernanceRecords>(pool_address), - delegator_address) + delegator_address + ) }
@@ -2302,67 +2326,98 @@ Ownership over setting the operator/voter is granted to owner who h unlock_numerators: vector<u64>, unlock_denominator: u64, unlock_start_time: u64, - unlock_duration: u64, + unlock_duration: u64 ) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage { //if there is an admin, it must be a multisig if (option::is_some<address>(&multisig_admin)) { // `ms_admin` is guaranteed to be NOT `@0x0` here let ms_admin = option::get_with_default<address>(&multisig_admin, @0x0); - assert!(ms_admin != @0x0, error::invalid_argument(EADMIN_ADDRESS_CANNOT_BE_ZERO)); - assert!(multisig_account::num_signatures_required(ms_admin) >= 2, - EADMIN_NOT_MULTISIG); + assert!( + ms_admin != @0x0, + error::invalid_argument(EADMIN_ADDRESS_CANNOT_BE_ZERO) + ); + assert!( + multisig_account::num_signatures_required(ms_admin) >= 2, + EADMIN_NOT_MULTISIG + ); }; // fail if the length of delegator_address and principle_stake is not the same - assert!(vector::length(&delegator_address) == vector::length(&principle_stake), - error::invalid_argument(EVECTOR_LENGTH_NOT_SAME)); + assert!( + vector::length(&delegator_address) == vector::length(&principle_stake), + error::invalid_argument(EVECTOR_LENGTH_NOT_SAME) + ); //Delegation pool must be enabled - assert!(features::delegation_pools_enabled(), - error::invalid_state(EDELEGATION_POOLS_DISABLED)); + assert!( + features::delegation_pools_enabled(), + error::invalid_state(EDELEGATION_POOLS_DISABLED) + ); //Unlock start time can not be in the past - assert!(unlock_start_time >= timestamp::now_seconds(), - error::invalid_argument(ESTARTUP_TIME_IN_PAST)); + assert!( + unlock_start_time >= timestamp::now_seconds(), + error::invalid_argument(ESTARTUP_TIME_IN_PAST) + ); //Unlock duration can not be zero assert!(unlock_duration > 0, error::invalid_argument(EPERIOD_DURATION_IS_ZERO)); //Fraction denominator can not be zero assert!(unlock_denominator != 0, error::invalid_argument(EDENOMINATOR_IS_ZERO)); //Fraction numerators can not be empty - assert!(vector::length(&unlock_numerators) > 0, - error::invalid_argument(EEMPTY_UNLOCK_SCHEDULE)); + assert!( + vector::length(&unlock_numerators) > 0, + error::invalid_argument(EEMPTY_UNLOCK_SCHEDULE) + ); //Fraction numerators can not be zero - assert!(!vector::any(&unlock_numerators, |e| { *e == 0 }), - error::invalid_argument(ESCHEDULE_WITH_ZERO_FRACTION)); + assert!( + !vector::any(&unlock_numerators, |e| { *e == 0 }), + error::invalid_argument(ESCHEDULE_WITH_ZERO_FRACTION) + ); let sum = vector::foldr(unlock_numerators, 0, |e, a| { e + a }); //Sum of numerators can not be greater than denominators - assert!(sum <= unlock_denominator, - error::invalid_argument(ENUMERATORS_GRATER_THAN_DENOMINATOR)); + assert!( + sum <= unlock_denominator, + error::invalid_argument(ENUMERATORS_GRATER_THAN_DENOMINATOR) + ); let owner_address = signer::address_of(owner); - assert!(!owner_cap_exists(owner_address), - error::already_exists(EOWNER_CAP_ALREADY_EXISTS)); - assert!(operator_commission_percentage <= MAX_FEE, - error::invalid_argument(EINVALID_COMMISSION_PERCENTAGE)); + assert!( + !owner_cap_exists(owner_address), + error::already_exists(EOWNER_CAP_ALREADY_EXISTS) + ); + assert!( + operator_commission_percentage <= MAX_FEE, + error::invalid_argument(EINVALID_COMMISSION_PERCENTAGE) + ); let sum = vector::fold(principle_stake, 0, |a, e| { a + e }); // fail if the value of coin and the sum of principle_stake is not the same - assert!(coin::value(&coin) == sum, - error::invalid_state(ECOIN_VALUE_NOT_SAME_AS_PRINCIPAL_STAKE)); + assert!( + coin::value(&coin) == sum, + error::invalid_state(ECOIN_VALUE_NOT_SAME_AS_PRINCIPAL_STAKE) + ); // generate a seed to be used to create the resource account hosting the delegation pool let seed = create_resource_account_seed(delegation_pool_creation_seed); - let (stake_pool_signer, stake_pool_signer_cap) = account::create_resource_account(owner, seed); + let (stake_pool_signer, stake_pool_signer_cap) = + account::create_resource_account(owner, seed); coin::register<SupraCoin>(&stake_pool_signer); // stake_pool_signer will be owner of the stake pool and have its `stake::OwnerCapability` let pool_address = signer::address_of(&stake_pool_signer); - stake::initialize_stake_owner(&stake_pool_signer, 0, owner_address, owner_address); + stake::initialize_stake_owner( + &stake_pool_signer, + 0, + owner_address, + owner_address + ); coin::deposit(pool_address, coin); let inactive_shares = table::new<ObservedLockupCycle, pool_u64::Pool>(); - table::add(&mut inactive_shares, + table::add( + &mut inactive_shares, olc_with_index(0), - pool_u64::create_with_scaling_factor(SHARES_SCALING_FACTOR)); + pool_u64::create_with_scaling_factor(SHARES_SCALING_FACTOR) + ); let delegator_address_copy = copy delegator_address; let principle_stake_copy = copy principle_stake; @@ -2377,14 +2432,19 @@ Ownership over setting the operator/voter is granted to owner who h //Create unlock schedule let schedule = vector::empty(); - vector::for_each_ref(&unlock_numerators, + vector::for_each_ref( + &unlock_numerators, |e| { - let fraction = fixed_point64::create_from_rational((*e as u128), - (unlock_denominator as u128)); + let fraction = + fixed_point64::create_from_rational( + (*e as u128), (unlock_denominator as u128) + ); vector::push_back(&mut schedule, fraction); - }); + } + ); - move_to(&stake_pool_signer, + move_to( + &stake_pool_signer, DelegationPool { multisig_admin: multisig_admin, active_shares: pool_u64::create_with_scaling_factor(SHARES_SCALING_FACTOR), @@ -2399,15 +2459,27 @@ Ownership over setting the operator/voter is granted to owner who h start_timestamp_secs: unlock_start_time, period_duration: unlock_duration, last_unlock_period: 0, - cumulative_unlocked_fraction: fixed_point64::create_from_rational(0, 1), + cumulative_unlocked_fraction: fixed_point64::create_from_rational( + 0, 1 + ) }, principle_stake: principle_stake_table, - add_stake_events: account::new_event_handle<AddStakeEvent>(&stake_pool_signer), - reactivate_stake_events: account::new_event_handle<ReactivateStakeEvent>(&stake_pool_signer), - unlock_stake_events: account::new_event_handle<UnlockStakeEvent>(&stake_pool_signer), - withdraw_stake_events: account::new_event_handle<WithdrawStakeEvent>(&stake_pool_signer), - distribute_commission_events: account::new_event_handle<DistributeCommissionEvent>(&stake_pool_signer), - }); + add_stake_events: account::new_event_handle<AddStakeEvent>( + &stake_pool_signer + ), + reactivate_stake_events: account::new_event_handle<ReactivateStakeEvent>( + &stake_pool_signer + ), + unlock_stake_events: account::new_event_handle<UnlockStakeEvent>( + &stake_pool_signer + ), + withdraw_stake_events: account::new_event_handle<WithdrawStakeEvent>( + &stake_pool_signer + ), + distribute_commission_events: account::new_event_handle< + DistributeCommissionEvent>(&stake_pool_signer) + } + ); // save delegation pool ownership and resource account address (inner stake pool address) on `owner` move_to(owner, DelegationPoolOwnership { pool_address }); @@ -2420,12 +2492,16 @@ Ownership over setting the operator/voter is granted to owner who h }; let (active_stake, _, _, _) = stake::get_stake(pool_address); // fail if coin in StakePool.active does not match with the balance in active_shares pool. - assert!(active_stake == pool_u64::total_coins(&borrow_global<DelegationPool>( - pool_address - ).active_shares), - error::invalid_state(EACTIVE_COIN_VALUE_NOT_SAME_STAKE_DELEGATION_POOL)); + assert!( + active_stake + == pool_u64::total_coins( + &borrow_global<DelegationPool>(pool_address).active_shares + ), + error::invalid_state(EACTIVE_COIN_VALUE_NOT_SAME_STAKE_DELEGATION_POOL) + ); // All delegation pool enable partial governace voting by default once the feature flag is enabled. - if (features::partial_governance_voting_enabled() && features::delegation_pool_partial_governance_voting_enabled()) { + if (features::partial_governance_voting_enabled() + && features::delegation_pool_partial_governance_voting_enabled()) { enable_partial_governance_voting(pool_address); } } @@ -2433,6 +2509,130 @@ Ownership over setting the operator/voter is granted to owner who h + + + + +## Function `fund_delegators_with_locked_stake` + + + +
public entry fun fund_delegators_with_locked_stake(funder: &signer, pool_address: address, delegators: vector<address>, stakes: vector<u64>)
+
+ + + +
+Implementation + + +
public entry fun fund_delegators_with_locked_stake(
+    funder: &signer,
+    pool_address: address,
+    delegators: vector<address>,
+    stakes: vector<u64>
+) acquires DelegationPool, BeneficiaryForOperator, GovernanceRecords, NextCommissionPercentage {
+    {
+        assert!(
+            is_admin(signer::address_of(funder), pool_address),
+            error::permission_denied(ENOT_AUTHORIZED)
+        );
+    };
+    let principle_stake_table =
+        &mut (borrow_global_mut<DelegationPool>(pool_address).principle_stake);
+
+    vector::zip_reverse(
+        delegators,
+        stakes,
+        |delegator, stake| {
+            //Ignore if stake to be added is `0`
+            if (stake > 0) {
+                //Compute the actual stake that would be added, `principle_stake` has to be
+                //populated in the table accordingly
+                if (table::contains(principle_stake_table, delegator)) {
+                    let stake_amount =
+                        table::borrow_mut(principle_stake_table, delegator);
+                    *stake_amount = *stake_amount + stake;
+                } else {
+                    table::add(principle_stake_table, delegator, stake);
+                }
+            }
+        }
+    );
+
+    fund_delegators_with_stake(funder, pool_address, delegators, stakes);
+}
+
+ + + +
+ + + +## Function `fund_delegators_with_stake` + + + +
public entry fun fund_delegators_with_stake(funder: &signer, pool_address: address, delegators: vector<address>, stakes: vector<u64>)
+
+ + + +
+Implementation + + +
public entry fun fund_delegators_with_stake(
+    funder: &signer,
+    pool_address: address,
+    delegators: vector<address>,
+    stakes: vector<u64>
+) acquires DelegationPool, BeneficiaryForOperator, GovernanceRecords, NextCommissionPercentage {
+    //length equality check is performed by `zip_reverse`
+    vector::zip_reverse(
+        delegators,
+        stakes,
+        |delegator, stake| {
+            fund_delegator_stake(funder, pool_address, delegator, stake);
+        }
+    );
+
+}
+
+ + + +
+ + + +## Function `is_admin` + + + +
#[view]
+public fun is_admin(user_addr: address, pool_address: address): bool
+
+ + + +
+Implementation + + +
public fun is_admin(user_addr: address, pool_address: address): bool acquires DelegationPool {
+    let option_multisig = get_admin(pool_address);
+    if (!option::is_some(&option_multisig)) {
+        return false
+    } else {
+        user_addr == *option::borrow(&option_multisig)
+    }
+}
+
+ + +
@@ -2480,7 +2680,9 @@ Return the beneficiary address of the operator.
public fun beneficiary_for_operator(operator: address): address acquires BeneficiaryForOperator {
     if (exists<BeneficiaryForOperator>(operator)) {
         return borrow_global<BeneficiaryForOperator>(operator).beneficiary_for_operator
-    } else { operator }
+    } else {
+        operator
+    }
 }
 
@@ -2505,11 +2707,17 @@ THe existing voter will be replaced. The function is permissionless. Implementation -
public entry fun enable_partial_governance_voting(pool_address: address,) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
-    assert!(features::partial_governance_voting_enabled(),
-        error::invalid_state(EDISABLED_FUNCTION));
-    assert!(features::delegation_pool_partial_governance_voting_enabled(),
-        error::invalid_state(EDISABLED_FUNCTION));
+
public entry fun enable_partial_governance_voting(
+    pool_address: address
+) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
+    assert!(
+        features::partial_governance_voting_enabled(),
+        error::invalid_state(EDISABLED_FUNCTION)
+    );
+    assert!(
+        features::delegation_pool_partial_governance_voting_enabled(),
+        error::invalid_state(EDISABLED_FUNCTION)
+    );
     assert_delegation_pool_exists(pool_address);
     // synchronize delegation and stake pools before any user operation.
     synchronize_delegation_pool(pool_address);
@@ -2518,19 +2726,25 @@ THe existing voter will be replaced. The function is permissionless.
     let stake_pool_signer = retrieve_stake_pool_owner(delegation_pool);
     // delegated_voter is managed by the stake pool itself, which signer capability is managed by DelegationPool.
     // So voting power of this stake pool can only be used through this module.
-    stake::set_delegated_voter(&stake_pool_signer,
-        signer::address_of(&stake_pool_signer));
+    stake::set_delegated_voter(
+        &stake_pool_signer, signer::address_of(&stake_pool_signer)
+    );
 
-    move_to(&stake_pool_signer,
+    move_to(
+        &stake_pool_signer,
         GovernanceRecords {
             votes: smart_table::new(),
             votes_per_proposal: smart_table::new(),
             vote_delegation: smart_table::new(),
             delegated_votes: smart_table::new(),
             vote_events: account::new_event_handle<VoteEvent>(&stake_pool_signer),
-            create_proposal_events: account::new_event_handle<CreateProposalEvent>(&stake_pool_signer),
-            delegate_voting_power_events: account::new_event_handle<DelegateVotingPowerEvent>(&stake_pool_signer),
-        });
+            create_proposal_events: account::new_event_handle<CreateProposalEvent>(
+                &stake_pool_signer
+            ),
+            delegate_voting_power_events: account::new_event_handle<
+                DelegateVotingPowerEvent>(&stake_pool_signer)
+        }
+    );
 }
 
@@ -2578,8 +2792,10 @@ THe existing voter will be replaced. The function is permissionless.
fun assert_delegation_pool_exists(pool_address: address) {
-    assert!(delegation_pool_exists(pool_address),
-        error::invalid_argument(EDELEGATION_POOL_DOES_NOT_EXIST));
+    assert!(
+        delegation_pool_exists(pool_address),
+        error::invalid_argument(EDELEGATION_POOL_DOES_NOT_EXIST)
+    );
 }
 
@@ -2602,10 +2818,14 @@ THe existing voter will be replaced. The function is permissionless. Implementation -
fun assert_min_active_balance(pool: &DelegationPool, delegator_address: address) {
+
fun assert_min_active_balance(
+    pool: &DelegationPool, delegator_address: address
+) {
     let balance = pool_u64::balance(&pool.active_shares, delegator_address);
-    assert!(balance >= MIN_COINS_ON_SHARES_POOL,
-        error::invalid_argument(EDELEGATOR_ACTIVE_BALANCE_TOO_LOW));
+    assert!(
+        balance >= MIN_COINS_ON_SHARES_POOL,
+        error::invalid_argument(EDELEGATOR_ACTIVE_BALANCE_TOO_LOW)
+    );
 }
 
@@ -2628,11 +2848,15 @@ THe existing voter will be replaced. The function is permissionless. Implementation -
fun assert_min_pending_inactive_balance(pool: &DelegationPool, delegator_address: address) {
-    let balance = pool_u64::balance(pending_inactive_shares_pool(pool),
-        delegator_address);
-    assert!(balance >= MIN_COINS_ON_SHARES_POOL,
-        error::invalid_argument(EDELEGATOR_PENDING_INACTIVE_BALANCE_TOO_LOW));
+
fun assert_min_pending_inactive_balance(
+    pool: &DelegationPool, delegator_address: address
+) {
+    let balance =
+        pool_u64::balance(pending_inactive_shares_pool(pool), delegator_address);
+    assert!(
+        balance >= MIN_COINS_ON_SHARES_POOL,
+        error::invalid_argument(EDELEGATOR_PENDING_INACTIVE_BALANCE_TOO_LOW)
+    );
 }
 
@@ -2657,8 +2881,10 @@ THe existing voter will be replaced. The function is permissionless.
fun assert_partial_governance_voting_enabled(pool_address: address) {
     assert_delegation_pool_exists(pool_address);
-    assert!(partial_governance_voting_enabled(pool_address),
-        error::invalid_state(EPARTIAL_GOVERNANCE_VOTING_NOT_ENABLED));
+    assert!(
+        partial_governance_voting_enabled(pool_address),
+        error::invalid_state(EPARTIAL_GOVERNANCE_VOTING_NOT_ENABLED)
+    );
 }
 
@@ -2682,11 +2908,14 @@ THe existing voter will be replaced. The function is permissionless.
fun coins_to_redeem_to_ensure_min_stake(
-    src_shares_pool: &pool_u64::Pool, shareholder: address, amount: u64,
+    src_shares_pool: &pool_u64::Pool, shareholder: address, amount: u64
 ): u64 {
     // find how many coins would be redeemed if supplying `amount`
-    let redeemed_coins = pool_u64::shares_to_amount(src_shares_pool,
-        amount_to_shares_to_redeem(src_shares_pool, shareholder, amount));
+    let redeemed_coins =
+        pool_u64::shares_to_amount(
+            src_shares_pool,
+            amount_to_shares_to_redeem(src_shares_pool, shareholder, amount)
+        );
     // if balance drops under threshold then redeem it entirely
     let src_balance = pool_u64::balance(src_shares_pool, shareholder);
     if (src_balance - redeemed_coins < MIN_COINS_ON_SHARES_POOL) {
@@ -2719,11 +2948,14 @@ THe existing voter will be replaced. The function is permissionless.
     src_shares_pool: &pool_u64::Pool,
     dst_shares_pool: &pool_u64::Pool,
     shareholder: address,
-    amount: u64,
+    amount: u64
 ): u64 {
     // find how many coins would be redeemed from source if supplying `amount`
-    let redeemed_coins = pool_u64::shares_to_amount(src_shares_pool,
-        amount_to_shares_to_redeem(src_shares_pool, shareholder, amount));
+    let redeemed_coins =
+        pool_u64::shares_to_amount(
+            src_shares_pool,
+            amount_to_shares_to_redeem(src_shares_pool, shareholder, amount)
+        );
     // if balance on destination would be less than threshold then redeem difference to threshold
     let dst_balance = pool_u64::balance(dst_shares_pool, shareholder);
     if (dst_balance + redeemed_coins < MIN_COINS_ON_SHARES_POOL) {
@@ -2806,7 +3038,9 @@ Get the active share amount of the delegator.
 Implementation
 
 
-
fun get_delegator_active_shares(pool: &DelegationPool, delegator: address): u128 {
+
fun get_delegator_active_shares(
+    pool: &DelegationPool, delegator: address
+): u128 {
     pool_u64::shares(&pool.active_shares, delegator)
 }
 
@@ -2831,7 +3065,9 @@ Get the pending inactive share amount of the delegator. Implementation -
fun get_delegator_pending_inactive_shares(pool: &DelegationPool, delegator: address): u128 {
+
fun get_delegator_pending_inactive_shares(
+    pool: &DelegationPool, delegator: address
+): u128 {
     pool_u64::shares(pending_inactive_shares_pool(pool), delegator)
 }
 
@@ -2860,7 +3096,7 @@ Get the used voting power of a voter on a proposal. governance_records: &GovernanceRecords, voter: address, proposal_id: u64 ): u64 { let votes = &governance_records.votes; - let key = VotingRecordKey { voter, proposal_id, }; + let key = VotingRecordKey { voter, proposal_id }; *smart_table::borrow_with_default(votes, key, &0) }
@@ -2885,7 +3121,9 @@ Create the seed to derive the resource account address. Implementation -
fun create_resource_account_seed(delegation_pool_creation_seed: vector<u8>,): vector<u8> {
+
fun create_resource_account_seed(
+    delegation_pool_creation_seed: vector<u8>
+): vector<u8> {
     let seed = vector::empty<u8>();
     // include module salt (before any subseeds) to avoid conflicts with other modules creating resource accounts
     vector::append(&mut seed, MODULE_SALT);
@@ -2919,7 +3157,7 @@ Borrow the mutable used voting power of a voter on a proposal.
     governance_records: &mut GovernanceRecords, voter: address, proposal_id: u64
 ): &mut u64 {
     let votes = &mut governance_records.votes;
-    let key = VotingRecordKey { proposal_id, voter, };
+    let key = VotingRecordKey { proposal_id, voter };
     smart_table::borrow_mut_with_default(votes, key, 0)
 }
 
@@ -2945,7 +3183,9 @@ Update VoteDelegation of a delegator to up-to-date then borrow_mut it.
fun update_and_borrow_mut_delegator_vote_delegation(
-    pool: &DelegationPool, governance_records: &mut GovernanceRecords, delegator: address
+    pool: &DelegationPool,
+    governance_records: &mut GovernanceRecords,
+    delegator: address
 ): &mut VoteDelegation {
     let pool_address = get_pool_address(pool);
     let locked_until_secs = stake::get_lockup_secs(pool_address);
@@ -2954,20 +3194,21 @@ Update VoteDelegation of a delegator to up-to-date then borrow_mut it.
     // By default, a delegator's delegated voter is itself.
     // TODO: recycle storage when VoteDelegation equals to default value.
     if (!smart_table::contains(vote_delegation_table, delegator)) {
-        return smart_table::borrow_mut_with_default(vote_delegation_table,
+        return smart_table::borrow_mut_with_default(
+            vote_delegation_table,
             delegator,
             VoteDelegation {
                 voter: delegator,
                 last_locked_until_secs: locked_until_secs,
-                pending_voter: delegator,
+                pending_voter: delegator
             }
         )
     };
 
     let vote_delegation = smart_table::borrow_mut(vote_delegation_table, delegator);
     // A lockup period has passed since last time `vote_delegation` was updated. Pending voter takes effect.
-    if (vote_delegation.last_locked_until_secs < locked_until_secs && vote_delegation.voter != vote_delegation
-        .pending_voter) {
+    if (vote_delegation.last_locked_until_secs < locked_until_secs
+        && vote_delegation.voter != vote_delegation.pending_voter) {
         vote_delegation.voter = vote_delegation.pending_voter;
     };
     vote_delegation
@@ -3006,13 +3247,14 @@ Update DelegatedVotes of a voter to up-to-date then borrow_mut it.
     if (!smart_table::contains(delegated_votes_per_voter, voter)) {
         let active_shares = get_delegator_active_shares(pool, voter);
         let inactive_shares = get_delegator_pending_inactive_shares(pool, voter);
-        return smart_table::borrow_mut_with_default(delegated_votes_per_voter,
+        return smart_table::borrow_mut_with_default(
+            delegated_votes_per_voter,
             voter,
             DelegatedVotes {
                 active_shares,
                 pending_inactive_shares: inactive_shares,
                 active_shares_next_lockup: active_shares,
-                last_locked_until_secs: locked_until_secs,
+                last_locked_until_secs: locked_until_secs
             }
         )
     };
@@ -3076,11 +3318,15 @@ power, which equals to the sum of the coin amounts.
 
fun calculate_total_voting_power(
     delegation_pool: &DelegationPool, latest_delegated_votes: &DelegatedVotes
 ): u64 {
-    let active_amount = pool_u64::shares_to_amount(&delegation_pool.active_shares,
-        latest_delegated_votes.active_shares);
-    let pending_inactive_amount = pool_u64::shares_to_amount(
-        pending_inactive_shares_pool(delegation_pool),
-        latest_delegated_votes.pending_inactive_shares);
+    let active_amount =
+        pool_u64::shares_to_amount(
+            &delegation_pool.active_shares, latest_delegated_votes.active_shares
+        );
+    let pending_inactive_amount =
+        pool_u64::shares_to_amount(
+            pending_inactive_shares_pool(delegation_pool),
+            latest_delegated_votes.pending_inactive_shares
+        );
     active_amount + pending_inactive_amount
 }
 
@@ -3106,10 +3352,14 @@ Update VoteDelegation of a delegator to up-to-date then return the latest voter.
fun calculate_and_update_delegator_voter_internal(
-    pool: &DelegationPool, governance_records: &mut GovernanceRecords, delegator: address
+    pool: &DelegationPool,
+    governance_records: &mut GovernanceRecords,
+    delegator: address
 ): address {
-    let vote_delegation = update_and_borrow_mut_delegator_vote_delegation(pool,
-        governance_records, delegator);
+    let vote_delegation =
+        update_and_borrow_mut_delegator_vote_delegation(
+            pool, governance_records, delegator
+        );
     vote_delegation.voter
 }
 
@@ -3137,8 +3387,8 @@ Update DelegatedVotes of a voter to up-to-date then return the total voting powe
fun calculate_and_update_delegated_votes(
     pool: &DelegationPool, governance_records: &mut GovernanceRecords, voter: address
 ): u64 {
-    let delegated_votes = update_and_borrow_mut_delegated_votes(pool, governance_records,
-        voter);
+    let delegated_votes =
+        update_and_borrow_mut_delegated_votes(pool, governance_records, voter);
     calculate_total_voting_power(pool, delegated_votes)
 }
 
@@ -3163,14 +3413,17 @@ Allows an owner to change the operator of the underlying stake pool. Implementation -
public entry fun set_operator(owner: &signer, new_operator: address) acquires DelegationPoolOwnership, DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
+
public entry fun set_operator(
+    owner: &signer, new_operator: address
+) acquires DelegationPoolOwnership, DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
     let pool_address = get_owned_pool_address(signer::address_of(owner));
     // synchronize delegation and stake pools before any user operation
     // ensure the old operator is paid its uncommitted commission rewards
     synchronize_delegation_pool(pool_address);
-    stake::set_operator(&retrieve_stake_pool_owner(borrow_global<DelegationPool>(
-                pool_address
-            )), new_operator);
+    stake::set_operator(
+        &retrieve_stake_pool_owner(borrow_global<DelegationPool>(pool_address)),
+        new_operator
+    );
 }
 
@@ -3197,27 +3450,34 @@ one for each pool. Implementation -
public entry fun set_beneficiary_for_operator(operator: &signer, new_beneficiary: address) acquires BeneficiaryForOperator {
-    assert!(features::operator_beneficiary_change_enabled(),
-        std::error::invalid_state(EOPERATOR_BENEFICIARY_CHANGE_NOT_SUPPORTED));
+
public entry fun set_beneficiary_for_operator(
+    operator: &signer, new_beneficiary: address
+) acquires BeneficiaryForOperator {
+    assert!(
+        features::operator_beneficiary_change_enabled(),
+        std::error::invalid_state(EOPERATOR_BENEFICIARY_CHANGE_NOT_SUPPORTED)
+    );
     // The beneficiay address of an operator is stored under the operator's address.
     // So, the operator does not need to be validated with respect to a staking pool.
     let operator_addr = signer::address_of(operator);
     let old_beneficiary = beneficiary_for_operator(operator_addr);
     if (exists<BeneficiaryForOperator>(operator_addr)) {
         borrow_global_mut<BeneficiaryForOperator>(operator_addr).beneficiary_for_operator =
-             new_beneficiary;
+            new_beneficiary;
     } else {
-        move_to(operator, BeneficiaryForOperator {
-                beneficiary_for_operator: new_beneficiary
-            });
+        move_to(
+            operator,
+            BeneficiaryForOperator { beneficiary_for_operator: new_beneficiary }
+        );
     };
 
-    emit(SetBeneficiaryForOperator {
+    emit(
+        SetBeneficiaryForOperator {
             operator: operator_addr,
             old_beneficiary,
-            new_beneficiary,
-        });
+            new_beneficiary
+        }
+    );
 }
 
@@ -3241,17 +3501,29 @@ Allows an owner to update the commission percentage for the operator of the unde Implementation -
public entry fun update_commission_percentage(owner: &signer, new_commission_percentage: u64) acquires DelegationPoolOwnership, DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
-    assert!(features::commission_change_delegation_pool_enabled(),
-        error::invalid_state(ECOMMISSION_RATE_CHANGE_NOT_SUPPORTED));
-    assert!(new_commission_percentage <= MAX_FEE,
-        error::invalid_argument(EINVALID_COMMISSION_PERCENTAGE));
+
public entry fun update_commission_percentage(
+    owner: &signer, new_commission_percentage: u64
+) acquires DelegationPoolOwnership, DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
+    assert!(
+        features::commission_change_delegation_pool_enabled(),
+        error::invalid_state(ECOMMISSION_RATE_CHANGE_NOT_SUPPORTED)
+    );
+    assert!(
+        new_commission_percentage <= MAX_FEE,
+        error::invalid_argument(EINVALID_COMMISSION_PERCENTAGE)
+    );
     let owner_address = signer::address_of(owner);
     let pool_address = get_owned_pool_address(owner_address);
-    assert!(operator_commission_percentage(pool_address) + MAX_COMMISSION_INCREASE >= new_commission_percentage,
-        error::invalid_argument(ETOO_LARGE_COMMISSION_INCREASE));
-    assert!(stake::get_remaining_lockup_secs(pool_address) >= min_remaining_secs_for_commission_change(),
-        error::invalid_state(ETOO_LATE_COMMISSION_CHANGE));
+    assert!(
+        operator_commission_percentage(pool_address) + MAX_COMMISSION_INCREASE
+            >= new_commission_percentage,
+        error::invalid_argument(ETOO_LARGE_COMMISSION_INCREASE)
+    );
+    assert!(
+        stake::get_remaining_lockup_secs(pool_address)
+            >= min_remaining_secs_for_commission_change(),
+        error::invalid_state(ETOO_LATE_COMMISSION_CHANGE)
+    );
 
     // synchronize delegation and stake pools before any user operation. this ensures:
     // (1) the operator is paid its uncommitted commission rewards with the old commission percentage, and
@@ -3259,28 +3531,34 @@ Allows an owner to update the commission percentage for the operator of the unde
     synchronize_delegation_pool(pool_address);
 
     if (exists<NextCommissionPercentage>(pool_address)) {
-        let commission_percentage = borrow_global_mut<NextCommissionPercentage>(
-            pool_address
-        );
+        let commission_percentage =
+            borrow_global_mut<NextCommissionPercentage>(pool_address);
         commission_percentage.commission_percentage_next_lockup_cycle = new_commission_percentage;
         commission_percentage.effective_after_secs = stake::get_lockup_secs(
             pool_address
         );
     } else {
         let delegation_pool = borrow_global<DelegationPool>(pool_address);
-        let pool_signer = account::create_signer_with_capability(&delegation_pool.stake_pool_signer_cap);
-        move_to(&pool_signer,
+        let pool_signer =
+            account::create_signer_with_capability(
+                &delegation_pool.stake_pool_signer_cap
+            );
+        move_to(
+            &pool_signer,
             NextCommissionPercentage {
                 commission_percentage_next_lockup_cycle: new_commission_percentage,
-                effective_after_secs: stake::get_lockup_secs(pool_address),
-            });
+                effective_after_secs: stake::get_lockup_secs(pool_address)
+            }
+        );
     };
 
-    event::emit(CommissionPercentageChange {
+    event::emit(
+        CommissionPercentageChange {
             pool_address,
             owner: owner_address,
-            commission_percentage_next_lockup_cycle: new_commission_percentage,
-        });
+            commission_percentage_next_lockup_cycle: new_commission_percentage
+        }
+    );
 }
 
@@ -3304,16 +3582,21 @@ Allows an owner to change the delegated voter of the underlying stake pool. Implementation -
public entry fun set_delegated_voter(owner: &signer, new_voter: address) acquires DelegationPoolOwnership, DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
+
public entry fun set_delegated_voter(
+    owner: &signer, new_voter: address
+) acquires DelegationPoolOwnership, DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
     // No one can change delegated_voter once the partial governance voting feature is enabled.
-    assert!(!features::delegation_pool_partial_governance_voting_enabled(),
-        error::invalid_state(EDEPRECATED_FUNCTION));
+    assert!(
+        !features::delegation_pool_partial_governance_voting_enabled(),
+        error::invalid_state(EDEPRECATED_FUNCTION)
+    );
     let pool_address = get_owned_pool_address(signer::address_of(owner));
     // synchronize delegation and stake pools before any user operation
     synchronize_delegation_pool(pool_address);
-    stake::set_delegated_voter(&retrieve_stake_pool_owner(borrow_global<DelegationPool>(
-                pool_address
-            )), new_voter);
+    stake::set_delegated_voter(
+        &retrieve_stake_pool_owner(borrow_global<DelegationPool>(pool_address)),
+        new_voter
+    );
 }
 
@@ -3349,35 +3632,40 @@ this change won't take effects until the next lockup period. let delegator_address = signer::address_of(delegator); let delegation_pool = borrow_global<DelegationPool>(pool_address); let governance_records = borrow_global_mut<GovernanceRecords>(pool_address); - let delegator_vote_delegation = update_and_borrow_mut_delegator_vote_delegation( - delegation_pool, governance_records, delegator_address - ); + let delegator_vote_delegation = + update_and_borrow_mut_delegator_vote_delegation( + delegation_pool, governance_records, delegator_address + ); let pending_voter: address = delegator_vote_delegation.pending_voter; // No need to update if the voter doesn't really change. if (pending_voter != new_voter) { delegator_vote_delegation.pending_voter = new_voter; - let active_shares = get_delegator_active_shares(delegation_pool, - delegator_address); + let active_shares = + get_delegator_active_shares(delegation_pool, delegator_address); // <active shares> of <pending voter of shareholder> -= <active_shares> // <active shares> of <new voter of shareholder> += <active_shares> - let pending_delegated_votes = update_and_borrow_mut_delegated_votes( - delegation_pool, governance_records, pending_voter - ); + let pending_delegated_votes = + update_and_borrow_mut_delegated_votes( + delegation_pool, governance_records, pending_voter + ); pending_delegated_votes.active_shares_next_lockup = pending_delegated_votes.active_shares_next_lockup - active_shares; - let new_delegated_votes = update_and_borrow_mut_delegated_votes(delegation_pool, - governance_records, new_voter); + let new_delegated_votes = + update_and_borrow_mut_delegated_votes( + delegation_pool, governance_records, new_voter + ); new_delegated_votes.active_shares_next_lockup = new_delegated_votes.active_shares_next_lockup + active_shares; }; - event::emit_event(&mut governance_records.delegate_voting_power_events, + event::emit_event( + &mut governance_records.delegate_voting_power_events, DelegateVotingPowerEvent { pool_address, delegator: delegator_address, - voter: new_voter, + voter: new_voter } ); } @@ -3403,7 +3691,9 @@ Add amount of coins to the delegation pool pool_addressImplementation -
fun add_stake_initialization(delegator_address: address, pool_address: address, amount: u64) acquires DelegationPool, GovernanceRecords {
+
fun add_stake_initialization(
+    delegator_address: address, pool_address: address, amount: u64
+) acquires DelegationPool, GovernanceRecords {
     // short-circuit if amount to add is 0 so no event is emitted
     if (amount == 0) { return };
 
@@ -3420,14 +3710,13 @@ Add amount of coins to the delegation pool pool_address
 
-
+
 
-## Function `add_stake`
+## Function `fund_delegator_stake`
 
-Add amount of coins to the delegation pool pool_address.
 
 
-
public entry fun add_stake(delegator: &signer, pool_address: address, amount: u64)
+
fun fund_delegator_stake(funder: &signer, pool_address: address, delegator_address: address, amount: u64)
 
@@ -3436,7 +3725,12 @@ Add amount of coins to the delegation pool pool_addressImplementation -
public entry fun add_stake(delegator: &signer, pool_address: address, amount: u64) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
+
fun fund_delegator_stake(
+    funder: &signer,
+    pool_address: address,
+    delegator_address: address,
+    amount: u64
+) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
     // short-circuit if amount to add is 0 so no event is emitted
     if (amount == 0) { return };
     // synchronize delegation and stake pools before any user operation
@@ -3445,11 +3739,10 @@ Add amount of coins to the delegation pool pool_addressto be charged for adding `amount` stake on this delegation pool at this epoch
     let add_stake_fee = get_add_stake_fee(pool_address, amount);
 
+    supra_account::transfer(funder, pool_address, amount);
     let pool = borrow_global_mut<DelegationPool>(pool_address);
-    let delegator_address = signer::address_of(delegator);
 
     // stake the entire amount to the stake pool
-    supra_account::transfer(delegator, pool_address, amount);
     stake::add_stake(&retrieve_stake_pool_owner(pool), amount);
 
     // but buy shares for delegator just for the remaining amount after fee
@@ -3462,14 +3755,48 @@ Add amount of coins to the delegation pool pool_addressto appreciate all shares on the active pool atomically
     buy_in_active_shares(pool, NULL_SHAREHOLDER, add_stake_fee);
 
-    event::emit_event(&mut pool.add_stake_events,
+    event::emit_event(
+        &mut pool.add_stake_events,
         AddStakeEvent {
             pool_address,
             delegator_address,
             amount_added: amount,
-            add_stake_fee,
-        },
+            add_stake_fee
+        }
     );
+
+}
+
+ + + + + + + +## Function `add_stake` + +Add amount of coins to the delegation pool pool_address. + + +
public entry fun add_stake(delegator: &signer, pool_address: address, amount: u64)
+
+ + + +
+Implementation + + +
public entry fun add_stake(
+    delegator: &signer, pool_address: address, amount: u64
+) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
+    fund_delegator_stake(
+        delegator,
+        pool_address,
+        signer::address_of(delegator),
+        amount
+    )
 }
 
@@ -3493,7 +3820,9 @@ Add amount of coins to the delegation pool pool_addressfun replace_in_smart_tables<Key: copy + drop, Val>( - table: &mut SmartTable<Key, Val>, old_entry: Key, new_entry: Key + table: &mut SmartTable<Key, Val>, + old_entry: Key, + new_entry: Key ) { if (smart_table::contains(table, old_entry)) { let val = smart_table::remove(table, old_entry); @@ -3526,43 +3855,61 @@ This does not apply to anyone who added stake later or operator
public entry fun replace_delegator(
-    multisig_admin: &signer, pool_address: address, old_delegator: address, new_delegator: address
+    multisig_admin: &signer,
+    pool_address: address,
+    old_delegator: address,
+    new_delegator: address
 ) acquires DelegationPool, GovernanceRecords {
 
+    //Ensure that authorized admin is calling
+    let admin_addr = signer::address_of(multisig_admin);
+    assert!(
+        is_admin(admin_addr, pool_address),
+        error::permission_denied(ENOT_AUTHORIZED)
+    );
     //Ensure replacement address is different
-    assert!(old_delegator != new_delegator,
-        error::invalid_argument(ENEW_IS_SAME_AS_OLD_DELEGATOR));
+    assert!(
+        old_delegator != new_delegator,
+        error::invalid_argument(ENEW_IS_SAME_AS_OLD_DELEGATOR)
+    );
     //Ensure it is a valid `pool_addres`
-    assert!(exists<DelegationPool>(pool_address),
-        error::invalid_argument(EDELEGATION_POOL_DOES_NOT_EXIST));
+    assert!(
+        exists<DelegationPool>(pool_address),
+        error::invalid_argument(EDELEGATION_POOL_DOES_NOT_EXIST)
+    );
 
     let pool: &mut DelegationPool = borrow_global_mut<DelegationPool>(pool_address);
-    let admin_addr = signer::address_of(multisig_admin);
-    //Ensure that authorized admin is calling
-    assert!(admin_addr != @0x0, error::invalid_argument(EADMIN_ADDRESS_CANNOT_BE_ZERO));
-    assert!(admin_addr == option::get_with_default(&pool.multisig_admin, @0x0),
-        error::permission_denied(ENOT_AUTHORIZED));
-
     //Ensure `old_delegator` is part of original principle stakers before commencing the replacement
-    assert!(table::contains(&pool.principle_stake, old_delegator),
-        error::unavailable(EDELEGATOR_DOES_NOT_EXIST));
+    assert!(
+        table::contains(&pool.principle_stake, old_delegator),
+        error::unavailable(EDELEGATOR_DOES_NOT_EXIST)
+    );
 
     //replace in `active_shares` pool
     {
         let active_pool = &mut pool.active_shares;
         let active_shares = pool_u64::shares(active_pool, old_delegator);
-        pool_u64::transfer_shares(active_pool, old_delegator, new_delegator,
-            active_shares);
+        pool_u64::transfer_shares(
+            active_pool,
+            old_delegator,
+            new_delegator,
+            active_shares
+        );
     };
 
     //replace in `inactive_shares` pool
-    let (withdrawal_exists, withdrawal_olc) = pending_withdrawal_exists(pool,
-        old_delegator);
+    let (withdrawal_exists, withdrawal_olc) =
+        pending_withdrawal_exists(pool, old_delegator);
     if (withdrawal_exists) {
-        let inactive_pool = table::borrow_mut(&mut pool.inactive_shares, withdrawal_olc);
+        let inactive_pool =
+            table::borrow_mut(&mut pool.inactive_shares, withdrawal_olc);
         let inactive_shares = pool_u64::shares(inactive_pool, old_delegator);
-        pool_u64::transfer_shares(inactive_pool, old_delegator, new_delegator,
-            inactive_shares);
+        pool_u64::transfer_shares(
+            inactive_pool,
+            old_delegator,
+            new_delegator,
+            inactive_shares
+        );
 
         //replace in `pending_withdrawals`
         {
@@ -3577,28 +3924,39 @@ This does not apply to anyone who added stake later or operator
     {
         if (features::partial_governance_voting_enabled()) {
             let grecords = borrow_global_mut<GovernanceRecords>(pool_address);
-            replace_in_smart_tables(&mut grecords.vote_delegation, old_delegator,
-                new_delegator);
-            replace_in_smart_tables(&mut grecords.delegated_votes, old_delegator,
-                new_delegator);
+            replace_in_smart_tables(
+                &mut grecords.vote_delegation, old_delegator, new_delegator
+            );
+            replace_in_smart_tables(
+                &mut grecords.delegated_votes, old_delegator, new_delegator
+            );
             let old_keys: vector<VotingRecordKey> = vector::empty();
             let new_keys: vector<VotingRecordKey> = vector::empty();
-            smart_table::for_each_ref<VotingRecordKey, u64>(&grecords.votes,
+            smart_table::for_each_ref<VotingRecordKey, u64>(
+                &grecords.votes,
                 |key, _val| {
                     let VotingRecordKey { voter, proposal_id } = *key;
                     if (voter == old_delegator) {
-                        vector::push_back(&mut new_keys, VotingRecordKey {
+                        vector::push_back(
+                            &mut new_keys,
+                            VotingRecordKey {
                                 voter: new_delegator,
                                 proposal_id: proposal_id
-                            });
+                            }
+                        );
                         vector::push_back(&mut old_keys, *key);
                     };
 
-                });
+                }
+            );
 
-            vector::zip_ref(&old_keys, &new_keys, |old, new| {
+            vector::zip_ref(
+                &old_keys,
+                &new_keys,
+                |old, new| {
                     replace_in_smart_tables(&mut grecords.votes, *old, *new);
-                });
+                }
+            );
         }
     };
     // replace in principle_stake table
@@ -3607,8 +3965,69 @@ This does not apply to anyone who added stake later or operator
         table::add(&mut pool.principle_stake, new_delegator, val);
     };
 
-    event::emit(DelegatorReplacemendEvent { pool_address, old_delegator, new_delegator },);
+    event::emit(
+        DelegatorReplacemendEvent { pool_address, old_delegator, new_delegator }
+    );
+
+}
+
+ + + +
+ + + +## Function `is_principle_stakeholder` + + + +
#[view]
+public fun is_principle_stakeholder(delegator_addr: address, pool_addr: address): bool
+
+ + + +
+Implementation + +
public fun is_principle_stakeholder(
+    delegator_addr: address, pool_addr: address
+): bool acquires DelegationPool {
+    let pool = borrow_global<DelegationPool>(pool_addr);
+    table::contains(&pool.principle_stake, delegator_addr)
+}
+
+ + + +
+ + + +## Function `get_principle_stake` + + + +
#[view]
+public fun get_principle_stake(delegator_addr: address, pool_addr: address): u64
+
+ + + +
+Implementation + + +
public fun get_principle_stake(
+    delegator_addr: address, pool_addr: address
+): u64 acquires DelegationPool {
+    let pool = borrow_global<DelegationPool>(pool_addr);
+    if (!table::contains(&pool.principle_stake, delegator_addr)) { 0 }
+    else {
+        *table::borrow(&pool.principle_stake, delegator_addr)
+    }
 }
 
@@ -3635,23 +4054,37 @@ accurate as time passes Implementation -
public fun cached_unlockable_balance(delegator_addr: address, pool_addr: address): u64 acquires DelegationPool {
-    assert!(exists<DelegationPool>(pool_addr),
-        error::invalid_argument(EDELEGATION_POOL_DOES_NOT_EXIST));
+
public fun cached_unlockable_balance(
+    delegator_addr: address, pool_addr: address
+): u64 acquires DelegationPool {
+    assert!(
+        exists<DelegationPool>(pool_addr),
+        error::invalid_argument(EDELEGATION_POOL_DOES_NOT_EXIST)
+    );
     let pool = borrow_global<DelegationPool>(pool_addr);
-    let delegator_active_balance = pool_u64::balance(&pool.active_shares, delegator_addr);
-    let unlockable_fraction = pool.principle_unlock_schedule.cumulative_unlocked_fraction;
-    let delegator_principle_stake = *table::borrow(&pool.principle_stake, delegator_addr);
+    let delegator_active_balance =
+        pool_u64::balance(&pool.active_shares, delegator_addr);
+    let unlockable_fraction =
+        pool.principle_unlock_schedule.cumulative_unlocked_fraction;
+    let delegator_principle_stake =
+        *table::borrow(&pool.principle_stake, delegator_addr);
 
     //To avoid problem even if fraction is slightly above 1
-    let unlockable_principle_stake = (math128::min(fixed_point64::multiply_u128(
-                (delegator_principle_stake as u128), unlockable_fraction
-            ),
-            (delegator_principle_stake as u128)) as u64);
+    let unlockable_principle_stake =
+        (
+            math128::min(
+                fixed_point64::multiply_u128(
+                    (delegator_principle_stake as u128), unlockable_fraction
+                ),
+                (delegator_principle_stake as u128)
+            ) as u64
+        );
     let locked_amount = delegator_principle_stake - unlockable_principle_stake;
 
-    assert!(delegator_active_balance >= locked_amount,
-        error::invalid_state(EDELEGATOR_ACTIVE_BALANCE_TOO_LOW));
+    assert!(
+        delegator_active_balance >= locked_amount,
+        error::invalid_state(EDELEGATOR_ACTIVE_BALANCE_TOO_LOW)
+    );
     delegator_active_balance - locked_amount
 
 }
@@ -3665,6 +4098,7 @@ accurate as time passes
 
 ## Function `can_principle_unlock`
 
+Note: this does not synchronize with stake pool, therefore the answer may be conservative
 
 
 
public fun can_principle_unlock(delegator_addr: address, pool_address: address, amount: u64): bool
@@ -3676,37 +4110,46 @@ accurate as time passes
 Implementation
 
 
-
public fun can_principle_unlock(delegator_addr: address, pool_address: address, amount: u64)
-    : bool acquires DelegationPool {
+
public fun can_principle_unlock(
+    delegator_addr: address, pool_address: address, amount: u64
+): bool acquires DelegationPool {
 
-    let principle_stake_table = &borrow_global<DelegationPool>(pool_address).principle_stake;
+    let principle_stake_table =
+        &borrow_global<DelegationPool>(pool_address).principle_stake;
 
     if (!table::contains(principle_stake_table, delegator_addr)) {
-        return true
+        return false
     };
 
-    let unlock_schedule = &mut borrow_global_mut<DelegationPool>(pool_address).principle_unlock_schedule;
+    let unlock_schedule =
+        &mut borrow_global_mut<DelegationPool>(pool_address).principle_unlock_schedule;
     let one = fixed_point64::create_from_rational(1, 1);
-    if (fixed_point64::greater_or_equal(unlock_schedule.cumulative_unlocked_fraction, one)) {
+    if (fixed_point64::greater_or_equal(
+        unlock_schedule.cumulative_unlocked_fraction, one
+    )) {
         return true
     };
     if (unlock_schedule.start_timestamp_secs > timestamp::now_seconds()) {
-        let unlockable_amount = cached_unlockable_balance(delegator_addr, pool_address);
+        let unlockable_amount =
+            cached_unlockable_balance(delegator_addr, pool_address);
         return amount <= unlockable_amount
     };
 
     //subtraction safety due to check above
-    let unlock_periods_passed = (timestamp::now_seconds() - unlock_schedule.start_timestamp_secs)
-        / unlock_schedule.period_duration;
+    let unlock_periods_passed =
+        (timestamp::now_seconds() - unlock_schedule.start_timestamp_secs)
+            / unlock_schedule.period_duration;
     let last_unlocked_period = unlock_schedule.last_unlock_period;
     let schedule_length = vector::length(&unlock_schedule.schedule);
     let cfraction = unlock_schedule.cumulative_unlocked_fraction;
-    while (last_unlocked_period < unlock_periods_passed && fixed_point64::less(
-            cfraction, one
-        )) {
-        let next_fraction = if (schedule_length <= last_unlocked_period) {
-            *vector::borrow(&unlock_schedule.schedule, schedule_length - 1)
-        } else { *vector::borrow(&unlock_schedule.schedule, last_unlocked_period) };
+    while (last_unlocked_period < unlock_periods_passed
+        && fixed_point64::less(cfraction, one)) {
+        let next_fraction =
+            if (schedule_length <= last_unlocked_period) {
+                *vector::borrow(&unlock_schedule.schedule, schedule_length - 1)
+            } else {
+                *vector::borrow(&unlock_schedule.schedule, last_unlocked_period)
+            };
         cfraction = fixed_point64::add(cfraction, next_fraction);
 
         last_unlocked_period = last_unlocked_period + 1;
@@ -3741,36 +4184,51 @@ at most how much active stake there is on the stake pool.
 Implementation
 
 
-
public entry fun unlock(delegator: &signer, pool_address: address, amount: u64) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
+
public entry fun unlock(
+    delegator: &signer, pool_address: address, amount: u64
+) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
     // short-circuit if amount to unlock is 0 so no event is emitted
     if (amount == 0) { return };
     // fail unlock of more stake than `active` on the stake pool
     let (active, _, _, _) = stake::get_stake(pool_address);
-    assert!(amount <= active,
-        error::invalid_argument(ENOT_ENOUGH_ACTIVE_STAKE_TO_UNLOCK));
+    assert!(
+        amount <= active,
+        error::invalid_argument(ENOT_ENOUGH_ACTIVE_STAKE_TO_UNLOCK)
+    );
 
     // synchronize delegation and stake pools before any user operation
     synchronize_delegation_pool(pool_address);
 
     let delegator_address = signer::address_of(delegator);
     // fail if the amount after withdraw is less than the principle stake and the lockup time is not expired
-    assert!(can_principle_unlock(delegator_address, pool_address, amount),
-        error::invalid_argument(EAMOUNT_REQUESTED_NOT_UNLOCKABLE));
+    if (is_principle_stakeholder(delegator_address, pool_address)) {
+        assert!(
+            can_principle_unlock(delegator_address, pool_address, amount),
+            error::invalid_argument(EAMOUNT_REQUESTED_NOT_UNLOCKABLE)
+        );
+    };
     let pool = borrow_global_mut<DelegationPool>(pool_address);
-    amount = coins_to_transfer_to_ensure_min_stake(&pool.active_shares,
-        pending_inactive_shares_pool(pool), delegator_address, amount,);
+    amount = coins_to_transfer_to_ensure_min_stake(
+        &pool.active_shares,
+        pending_inactive_shares_pool(pool),
+        delegator_address,
+        amount
+    );
     amount = redeem_active_shares(pool, delegator_address, amount);
     stake::unlock(&retrieve_stake_pool_owner(pool), amount);
 
     buy_in_pending_inactive_shares(pool, delegator_address, amount);
     assert_min_pending_inactive_balance(pool, delegator_address);
 
-    event::emit_event(&mut pool.unlock_stake_events,
-        UnlockStakeEvent { pool_address, delegator_address, amount_unlocked: amount, },
+    event::emit_event(
+        &mut pool.unlock_stake_events,
+        UnlockStakeEvent { pool_address, delegator_address, amount_unlocked: amount }
     );
     let (active_stake, _, pending_active, _) = stake::get_stake(pool_address);
-    assert!(active_stake + pending_active == pool_u64::total_coins(&pool.active_shares),
-        error::invalid_state(EACTIVE_COIN_VALUE_NOT_SAME_STAKE_DELEGATION_POOL));
+    assert!(
+        active_stake + pending_active == pool_u64::total_coins(&pool.active_shares),
+        error::invalid_state(EACTIVE_COIN_VALUE_NOT_SAME_STAKE_DELEGATION_POOL)
+    );
 }
 
@@ -3794,7 +4252,9 @@ Move amount of coins from pending_inactive to active. Implementation -
public entry fun reactivate_stake(delegator: &signer, pool_address: address, amount: u64) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
+
public entry fun reactivate_stake(
+    delegator: &signer, pool_address: address, amount: u64
+) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
     // short-circuit if amount to reactivate is 0 so no event is emitted
     if (amount == 0) { return };
     // synchronize delegation and stake pools before any user operation
@@ -3803,19 +4263,32 @@ Move amount of coins from pending_inactive to active.
     let pool = borrow_global_mut<DelegationPool>(pool_address);
     let delegator_address = signer::address_of(delegator);
 
-    amount = coins_to_transfer_to_ensure_min_stake(pending_inactive_shares_pool(pool), &pool
-        .active_shares, delegator_address, amount,);
+    amount = coins_to_transfer_to_ensure_min_stake(
+        pending_inactive_shares_pool(pool),
+        &pool.active_shares,
+        delegator_address,
+        amount
+    );
     let observed_lockup_cycle = pool.observed_lockup_cycle;
-    amount = redeem_inactive_shares(pool, delegator_address, amount,
-        observed_lockup_cycle);
+    amount = redeem_inactive_shares(
+        pool,
+        delegator_address,
+        amount,
+        observed_lockup_cycle
+    );
 
     stake::reactivate_stake(&retrieve_stake_pool_owner(pool), amount);
 
     buy_in_active_shares(pool, delegator_address, amount);
     assert_min_active_balance(pool, delegator_address);
 
-    event::emit_event(&mut pool.reactivate_stake_events,
-        ReactivateStakeEvent { pool_address, delegator_address, amount_reactivated: amount, },
+    event::emit_event(
+        &mut pool.reactivate_stake_events,
+        ReactivateStakeEvent {
+            pool_address,
+            delegator_address,
+            amount_reactivated: amount
+        }
     );
 }
 
@@ -3840,12 +4313,17 @@ Withdraw amount of owned inactive stake from the delegation pool at Implementation -
public entry fun withdraw(delegator: &signer, pool_address: address, amount: u64) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
+
public entry fun withdraw(
+    delegator: &signer, pool_address: address, amount: u64
+) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
     assert!(amount > 0, error::invalid_argument(EWITHDRAW_ZERO_STAKE));
     // synchronize delegation and stake pools before any user operation
     synchronize_delegation_pool(pool_address);
-    withdraw_internal(borrow_global_mut<DelegationPool>(pool_address),
-        signer::address_of(delegator), amount);
+    withdraw_internal(
+        borrow_global_mut<DelegationPool>(pool_address),
+        signer::address_of(delegator),
+        amount
+    );
 }
 
@@ -3868,25 +4346,38 @@ Withdraw amount of owned inactive stake from the delegation pool at Implementation -
fun withdraw_internal(pool: &mut DelegationPool, delegator_address: address, amount: u64) acquires GovernanceRecords {
+
fun withdraw_internal(
+    pool: &mut DelegationPool, delegator_address: address, amount: u64
+) acquires GovernanceRecords {
     // TODO: recycle storage when a delegator fully exits the delegation pool.
     // short-circuit if amount to withdraw is 0 so no event is emitted
     if (amount == 0) { return };
 
     let pool_address = get_pool_address(pool);
-    let (withdrawal_exists, withdrawal_olc) = pending_withdrawal_exists(pool,
-        delegator_address);
+    let (withdrawal_exists, withdrawal_olc) =
+        pending_withdrawal_exists(pool, delegator_address);
     // exit if no withdrawal or (it is pending and cannot withdraw pending_inactive stake from stake pool)
-    if (!(withdrawal_exists
-            && (withdrawal_olc.index < pool.observed_lockup_cycle.index || can_withdraw_pending_inactive(
-                    pool_address
-                )))) { return };
+    if (!(
+        withdrawal_exists
+            && (
+                withdrawal_olc.index < pool.observed_lockup_cycle.index
+                    || can_withdraw_pending_inactive(pool_address)
+            )
+    )) { return };
 
     if (withdrawal_olc.index == pool.observed_lockup_cycle.index) {
-        amount = coins_to_redeem_to_ensure_min_stake(pending_inactive_shares_pool(pool),
-            delegator_address, amount,)
+        amount = coins_to_redeem_to_ensure_min_stake(
+            pending_inactive_shares_pool(pool),
+            delegator_address,
+            amount
+        )
     };
-    amount = redeem_inactive_shares(pool, delegator_address, amount, withdrawal_olc);
+    amount = redeem_inactive_shares(
+        pool,
+        delegator_address,
+        amount,
+        withdrawal_olc
+    );
 
     let stake_pool_owner = &retrieve_stake_pool_owner(pool);
     // stake pool will inactivate entire pending_inactive stake at `stake::withdraw` to make it withdrawable
@@ -3915,8 +4406,9 @@ Withdraw amount of owned inactive stake from the delegation pool at
     let (_, inactive, _, _) = stake::get_stake(pool_address);
     pool.total_coins_inactive = inactive;
 
-    event::emit_event(&mut pool.withdraw_stake_events,
-        WithdrawStakeEvent { pool_address, delegator_address, amount_withdrawn: amount, },
+    event::emit_event(
+        &mut pool.withdraw_stake_events,
+        WithdrawStakeEvent { pool_address, delegator_address, amount_withdrawn: amount }
     );
 }
 
@@ -3943,12 +4435,14 @@ A bool is returned to signal if a pending withdrawal exists at all. Implementation -
fun pending_withdrawal_exists(pool: &DelegationPool, delegator_address: address)
-    : (bool,
-    ObservedLockupCycle) {
+
fun pending_withdrawal_exists(
+    pool: &DelegationPool, delegator_address: address
+): (bool, ObservedLockupCycle) {
     if (table::contains(&pool.pending_withdrawals, delegator_address)) {
         (true, *table::borrow(&pool.pending_withdrawals, delegator_address))
-    } else { (false, olc_with_index(0)) }
+    } else {
+        (false, olc_with_index(0))
+    }
 }
 
@@ -4026,10 +4520,13 @@ be explicitly withdrawn by delegator Implementation -
fun execute_pending_withdrawal(pool: &mut DelegationPool, delegator_address: address) acquires GovernanceRecords {
-    let (withdrawal_exists, withdrawal_olc) = pending_withdrawal_exists(pool,
-        delegator_address);
-    if (withdrawal_exists && withdrawal_olc.index < pool.observed_lockup_cycle.index) {
+
fun execute_pending_withdrawal(
+    pool: &mut DelegationPool, delegator_address: address
+) acquires GovernanceRecords {
+    let (withdrawal_exists, withdrawal_olc) =
+        pending_withdrawal_exists(pool, delegator_address);
+    if (withdrawal_exists
+        && withdrawal_olc.index < pool.observed_lockup_cycle.index) {
         withdraw_internal(pool, delegator_address, MAX_U64);
     }
 }
@@ -4056,8 +4553,9 @@ deposited coins_amount. This function doesn't make any coin transfe
 Implementation
 
 
-
fun buy_in_active_shares(pool: &mut DelegationPool, shareholder: address, coins_amount: u64,)
-    : u128 acquires GovernanceRecords {
+
fun buy_in_active_shares(
+    pool: &mut DelegationPool, shareholder: address, coins_amount: u64
+): u128 acquires GovernanceRecords {
     let new_shares = pool_u64::amount_to_shares(&pool.active_shares, coins_amount);
     // No need to buy 0 shares.
     if (new_shares == 0) {
@@ -4067,8 +4565,9 @@ deposited coins_amount. This function doesn't make any coin transfe
     // Always update governance records before any change to the shares pool.
     let pool_address = get_pool_address(pool);
     if (partial_governance_voting_enabled(pool_address)) {
-        update_governance_records_for_buy_in_active_shares(pool, pool_address,
-            new_shares, shareholder);
+        update_governance_records_for_buy_in_active_shares(
+            pool, pool_address, new_shares, shareholder
+        );
     };
 
     pool_u64::buy_in(&mut pool.active_shares, shareholder, coins_amount);
@@ -4100,10 +4599,12 @@ to ensure there is always only one withdrawal request.
 
 
 
fun buy_in_pending_inactive_shares(
-    pool: &mut DelegationPool, shareholder: address, coins_amount: u64,
+    pool: &mut DelegationPool, shareholder: address, coins_amount: u64
 ): u128 acquires GovernanceRecords {
-    let new_shares = pool_u64::amount_to_shares(pending_inactive_shares_pool(pool),
-        coins_amount);
+    let new_shares =
+        pool_u64::amount_to_shares(
+            pending_inactive_shares_pool(pool), coins_amount
+        );
     // never create a new pending withdrawal unless delegator owns some pending_inactive shares
     if (new_shares == 0) {
         return 0
@@ -4112,21 +4613,27 @@ to ensure there is always only one withdrawal request.
     // Always update governance records before any change to the shares pool.
     let pool_address = get_pool_address(pool);
     if (partial_governance_voting_enabled(pool_address)) {
-        update_governance_records_for_buy_in_pending_inactive_shares(pool, pool_address,
-            new_shares, shareholder);
+        update_governance_records_for_buy_in_pending_inactive_shares(
+            pool, pool_address, new_shares, shareholder
+        );
     };
 
     // cannot buy inactive shares, only pending_inactive at current lockup cycle
-    pool_u64::buy_in(pending_inactive_shares_pool_mut(pool), shareholder, coins_amount);
+    pool_u64::buy_in(
+        pending_inactive_shares_pool_mut(pool), shareholder, coins_amount
+    );
 
     // execute the pending withdrawal if exists and is inactive before creating a new one
     execute_pending_withdrawal(pool, shareholder);
 
     // save observed lockup cycle for the new pending withdrawal
     let observed_lockup_cycle = pool.observed_lockup_cycle;
-    assert!(*table::borrow_mut_with_default(&mut pool.pending_withdrawals, shareholder,
-            observed_lockup_cycle) == observed_lockup_cycle,
-        error::invalid_state(EPENDING_WITHDRAWAL_EXISTS));
+    assert!(
+        *table::borrow_mut_with_default(
+            &mut pool.pending_withdrawals, shareholder, observed_lockup_cycle
+        ) == observed_lockup_cycle,
+        error::invalid_state(EPENDING_WITHDRAWAL_EXISTS)
+    );
 
     new_shares
 }
@@ -4154,7 +4661,7 @@ to the exact number of shares to redeem in order to achieve this.
 
 
 
fun amount_to_shares_to_redeem(
-    shares_pool: &pool_u64::Pool, shareholder: address, coins_amount: u64,
+    shares_pool: &pool_u64::Pool, shareholder: address, coins_amount: u64
 ): u128 {
     if (coins_amount >= pool_u64::balance(shares_pool, shareholder)) {
         // cap result at total shares of shareholder to pass `EINSUFFICIENT_SHARES` on subsequent redeem
@@ -4188,18 +4695,23 @@ be available for withdrawal when current OLC ends.
 Implementation
 
 
-
fun redeem_active_shares(pool: &mut DelegationPool, shareholder: address, coins_amount: u64,)
-    : u64 acquires GovernanceRecords {
-    let shares_to_redeem = amount_to_shares_to_redeem(&pool.active_shares, shareholder,
-        coins_amount);
+
fun redeem_active_shares(
+    pool: &mut DelegationPool, shareholder: address, coins_amount: u64
+): u64 acquires GovernanceRecords {
+    let shares_to_redeem =
+        amount_to_shares_to_redeem(&pool.active_shares, shareholder, coins_amount);
     // silently exit if not a shareholder otherwise redeem would fail with `ESHAREHOLDER_NOT_FOUND`
     if (shares_to_redeem == 0) return 0;
 
     // Always update governance records before any change to the shares pool.
     let pool_address = get_pool_address(pool);
     if (partial_governance_voting_enabled(pool_address)) {
-        update_governanace_records_for_redeem_active_shares(pool, pool_address,
-            shares_to_redeem, shareholder);
+        update_governanace_records_for_redeem_active_shares(
+            pool,
+            pool_address,
+            shares_to_redeem,
+            shareholder
+        );
     };
 
     pool_u64::redeem_shares(&mut pool.active_shares, shareholder, shares_to_redeem)
@@ -4235,26 +4747,34 @@ escape inactivation when current lockup ends.
     pool: &mut DelegationPool,
     shareholder: address,
     coins_amount: u64,
-    lockup_cycle: ObservedLockupCycle,
+    lockup_cycle: ObservedLockupCycle
 ): u64 acquires GovernanceRecords {
-    let shares_to_redeem = amount_to_shares_to_redeem(table::borrow(&pool.inactive_shares,
-            lockup_cycle), shareholder, coins_amount);
+    let shares_to_redeem =
+        amount_to_shares_to_redeem(
+            table::borrow(&pool.inactive_shares, lockup_cycle),
+            shareholder,
+            coins_amount
+        );
     // silently exit if not a shareholder otherwise redeem would fail with `ESHAREHOLDER_NOT_FOUND`
     if (shares_to_redeem == 0) return 0;
 
     // Always update governance records before any change to the shares pool.
     let pool_address = get_pool_address(pool);
     // Only redeem shares from the pending_inactive pool at `lockup_cycle` == current OLC.
-    if (partial_governance_voting_enabled(pool_address) && lockup_cycle.index == pool.observed_lockup_cycle
-        .index) {
-        update_governanace_records_for_redeem_pending_inactive_shares(pool, pool_address,
-            shares_to_redeem, shareholder);
+    if (partial_governance_voting_enabled(pool_address)
+        && lockup_cycle.index == pool.observed_lockup_cycle.index) {
+        update_governanace_records_for_redeem_pending_inactive_shares(
+            pool,
+            pool_address,
+            shares_to_redeem,
+            shareholder
+        );
     };
 
     let inactive_shares = table::borrow_mut(&mut pool.inactive_shares, lockup_cycle);
     // 1. reaching here means delegator owns inactive/pending_inactive shares at OLC `lockup_cycle`
-    let redeemed_coins = pool_u64::redeem_shares(inactive_shares, shareholder,
-        shares_to_redeem);
+    let redeemed_coins =
+        pool_u64::redeem_shares(inactive_shares, shareholder, shares_to_redeem);
 
     // if entirely reactivated pending_inactive stake or withdrawn inactive one,
     // re-enable unlocking for delegator by deleting this pending withdrawal
@@ -4264,8 +4784,11 @@ escape inactivation when current lockup ends.
         table::remove(&mut pool.pending_withdrawals, shareholder);
     };
     // destroy inactive shares pool of past OLC if all its stake has been withdrawn
-    if (lockup_cycle.index < pool.observed_lockup_cycle.index && total_coins(inactive_shares) == 0) {
-        pool_u64::destroy_empty(table::remove(&mut pool.inactive_shares, lockup_cycle));
+    if (lockup_cycle.index < pool.observed_lockup_cycle.index
+        && total_coins(inactive_shares) == 0) {
+        pool_u64::destroy_empty(
+            table::remove(&mut pool.inactive_shares, lockup_cycle)
+        );
     };
 
     redeemed_coins
@@ -4295,10 +4818,12 @@ whether the lockup expired on the stake pool.
 
 
 
fun calculate_stake_pool_drift(pool: &DelegationPool): (bool, u64, u64, u64, u64) {
-    let (active, inactive, pending_active, pending_inactive) = stake::get_stake(
-        get_pool_address(pool));
-    assert!(inactive >= pool.total_coins_inactive,
-        error::invalid_state(ESLASHED_INACTIVE_STAKE_ON_PAST_OLC));
+    let (active, inactive, pending_active, pending_inactive) =
+        stake::get_stake(get_pool_address(pool));
+    assert!(
+        inactive >= pool.total_coins_inactive,
+        error::invalid_state(ESLASHED_INACTIVE_STAKE_ON_PAST_OLC)
+    );
     // determine whether a new lockup cycle has been ended on the stake pool and
     // inactivated SOME `pending_inactive` stake which should stop earning rewards now,
     // thus requiring separation of the `pending_inactive` stake on current observed lockup
@@ -4321,23 +4846,36 @@ whether the lockup expired on the stake pool.
 
     // operator `active` rewards not persisted yet to the active shares pool
     let pool_active = total_coins(&pool.active_shares);
-    let commission_active = if (active > pool_active) {
-        math64::mul_div(active - pool_active, pool.operator_commission_percentage,
-            MAX_FEE)
-    } else {
-        // handle any slashing applied to `active` stake
-        0 };
+    let commission_active =
+        if (active > pool_active) {
+            math64::mul_div(
+                active - pool_active, pool.operator_commission_percentage, MAX_FEE
+            )
+        } else {
+            // handle any slashing applied to `active` stake
+            0
+        };
     // operator `pending_inactive` rewards not persisted yet to the pending_inactive shares pool
     let pool_pending_inactive = total_coins(pending_inactive_shares_pool(pool));
-    let commission_pending_inactive = if (pending_inactive > pool_pending_inactive) {
-        math64::mul_div(pending_inactive - pool_pending_inactive, pool.operator_commission_percentage,
-            MAX_FEE)
-    } else {
-        // handle any slashing applied to `pending_inactive` stake
-        0 };
+    let commission_pending_inactive =
+        if (pending_inactive > pool_pending_inactive) {
+            math64::mul_div(
+                pending_inactive - pool_pending_inactive,
+                pool.operator_commission_percentage,
+                MAX_FEE
+            )
+        } else {
+            // handle any slashing applied to `pending_inactive` stake
+            0
+        };
 
-    (lockup_cycle_ended, active, pending_inactive, commission_active,
-        commission_pending_inactive)
+    (
+        lockup_cycle_ended,
+        active,
+        pending_inactive,
+        commission_active,
+        commission_pending_inactive
+    )
 }
 
@@ -4362,11 +4900,18 @@ shares pools, assign commission to operator and eventually prepare delegation po Implementation -
public entry fun synchronize_delegation_pool(pool_address: address) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
+
public entry fun synchronize_delegation_pool(
+    pool_address: address
+) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
     assert_delegation_pool_exists(pool_address);
     let pool = borrow_global_mut<DelegationPool>(pool_address);
-    let (lockup_cycle_ended, active, pending_inactive, commission_active,
-        commission_pending_inactive) = calculate_stake_pool_drift(pool);
+    let (
+        lockup_cycle_ended,
+        active,
+        pending_inactive,
+        commission_active,
+        commission_pending_inactive
+    ) = calculate_stake_pool_drift(pool);
 
     // zero `pending_active` stake indicates that either there are no `add_stake` fees or
     // previous epoch has ended and should release the shares owning the existing fees
@@ -4383,35 +4928,49 @@ shares pools, assign commission to operator and eventually prepare delegation po
 
     // update total coins accumulated by `active` + `pending_active` shares
     // redeemed `add_stake` fees are restored and distributed to the rest of the pool as rewards
-    pool_u64::update_total_coins(&mut pool.active_shares, active - commission_active);
+    pool_u64::update_total_coins(&mut pool.active_shares, active
+        - commission_active);
     // update total coins accumulated by `pending_inactive` shares at current observed lockup cycle
-    pool_u64::update_total_coins(pending_inactive_shares_pool_mut(pool),
-        pending_inactive - commission_pending_inactive);
+    pool_u64::update_total_coins(
+        pending_inactive_shares_pool_mut(pool),
+        pending_inactive - commission_pending_inactive
+    );
 
     // reward operator its commission out of uncommitted active rewards (`add_stake` fees already excluded)
-    buy_in_active_shares(pool,
-        beneficiary_for_operator(stake::get_operator(pool_address)), commission_active);
+    buy_in_active_shares(
+        pool,
+        beneficiary_for_operator(stake::get_operator(pool_address)),
+        commission_active
+    );
     // reward operator its commission out of uncommitted pending_inactive rewards
-    buy_in_pending_inactive_shares(pool,
+    buy_in_pending_inactive_shares(
+        pool,
         beneficiary_for_operator(stake::get_operator(pool_address)),
-        commission_pending_inactive);
+        commission_pending_inactive
+    );
 
-    event::emit_event(&mut pool.distribute_commission_events,
+    event::emit_event(
+        &mut pool.distribute_commission_events,
         DistributeCommissionEvent {
             pool_address,
             operator: stake::get_operator(pool_address),
             commission_active,
-            commission_pending_inactive,
-        },);
+            commission_pending_inactive
+        }
+    );
 
     if (features::operator_beneficiary_change_enabled()) {
-        emit(DistributeCommission {
+        emit(
+            DistributeCommission {
                 pool_address,
                 operator: stake::get_operator(pool_address),
-                beneficiary: beneficiary_for_operator(stake::get_operator(pool_address)),
+                beneficiary: beneficiary_for_operator(
+                    stake::get_operator(pool_address)
+                ),
                 commission_active,
-                commission_pending_inactive,
-            })
+                commission_pending_inactive
+            }
+        )
     };
 
     // advance lockup cycle on delegation pool if already ended on stake pool (AND stake explicitly inactivated)
@@ -4423,9 +4982,11 @@ shares pools, assign commission to operator and eventually prepare delegation po
         // advance lockup cycle on the delegation pool
         pool.observed_lockup_cycle.index = pool.observed_lockup_cycle.index + 1;
         // start new lockup cycle with a fresh shares pool for `pending_inactive` stake
-        table::add(&mut pool.inactive_shares,
+        table::add(
+            &mut pool.inactive_shares,
             pool.observed_lockup_cycle,
-            pool_u64::create_with_scaling_factor(SHARES_SCALING_FACTOR));
+            pool_u64::create_with_scaling_factor(SHARES_SCALING_FACTOR)
+        );
     };
 
     if (is_next_commission_percentage_effective(pool_address)) {
@@ -4456,25 +5017,35 @@ shares pools, assign commission to operator and eventually prepare delegation po
 
 
 
fun update_governance_records_for_buy_in_active_shares(
-    pool: &DelegationPool, pool_address: address, new_shares: u128, shareholder: address
+    pool: &DelegationPool,
+    pool_address: address,
+    new_shares: u128,
+    shareholder: address
 ) acquires GovernanceRecords {
     // <active shares> of <shareholder> += <new_shares> ---->
     // <active shares> of <current voter of shareholder> += <new_shares>
     // <active shares> of <next voter of shareholder> += <new_shares>
     let governance_records = borrow_global_mut<GovernanceRecords>(pool_address);
-    let vote_delegation = update_and_borrow_mut_delegator_vote_delegation(pool,
-        governance_records, shareholder);
+    let vote_delegation =
+        update_and_borrow_mut_delegator_vote_delegation(
+            pool, governance_records, shareholder
+        );
     let current_voter = vote_delegation.voter;
     let pending_voter = vote_delegation.pending_voter;
-    let current_delegated_votes = update_and_borrow_mut_delegated_votes(pool,
-        governance_records, current_voter);
-    current_delegated_votes.active_shares = current_delegated_votes.active_shares + new_shares;
+    let current_delegated_votes =
+        update_and_borrow_mut_delegated_votes(
+            pool, governance_records, current_voter
+        );
+    current_delegated_votes.active_shares = current_delegated_votes.active_shares
+        + new_shares;
     if (pending_voter == current_voter) {
         current_delegated_votes.active_shares_next_lockup = current_delegated_votes.active_shares_next_lockup
             + new_shares;
     } else {
-        let pending_delegated_votes = update_and_borrow_mut_delegated_votes(pool,
-            governance_records, pending_voter);
+        let pending_delegated_votes =
+            update_and_borrow_mut_delegated_votes(
+                pool, governance_records, pending_voter
+            );
         pending_delegated_votes.active_shares_next_lockup = pending_delegated_votes.active_shares_next_lockup
             + new_shares;
     };
@@ -4501,16 +5072,23 @@ shares pools, assign commission to operator and eventually prepare delegation po
 
 
 
fun update_governance_records_for_buy_in_pending_inactive_shares(
-    pool: &DelegationPool, pool_address: address, new_shares: u128, shareholder: address
+    pool: &DelegationPool,
+    pool_address: address,
+    new_shares: u128,
+    shareholder: address
 ) acquires GovernanceRecords {
     // <pending inactive shares> of <shareholder> += <new_shares>   ---->
     // <pending inactive shares> of <current voter of shareholder> += <new_shares>
     // no impact on <pending inactive shares> of <next voter of shareholder>
     let governance_records = borrow_global_mut<GovernanceRecords>(pool_address);
-    let current_voter = calculate_and_update_delegator_voter_internal(pool,
-        governance_records, shareholder);
-    let current_delegated_votes = update_and_borrow_mut_delegated_votes(pool,
-        governance_records, current_voter);
+    let current_voter =
+        calculate_and_update_delegator_voter_internal(
+            pool, governance_records, shareholder
+        );
+    let current_delegated_votes =
+        update_and_borrow_mut_delegated_votes(
+            pool, governance_records, current_voter
+        );
     current_delegated_votes.pending_inactive_shares = current_delegated_votes.pending_inactive_shares
         + new_shares;
 }
@@ -4536,25 +5114,35 @@ shares pools, assign commission to operator and eventually prepare delegation po
 
 
 
fun update_governanace_records_for_redeem_active_shares(
-    pool: &DelegationPool, pool_address: address, shares_to_redeem: u128, shareholder: address
+    pool: &DelegationPool,
+    pool_address: address,
+    shares_to_redeem: u128,
+    shareholder: address
 ) acquires GovernanceRecords {
     // <active shares> of <shareholder> -= <shares_to_redeem> ---->
     // <active shares> of <current voter of shareholder> -= <shares_to_redeem>
     // <active shares> of <next voter of shareholder> -= <shares_to_redeem>
     let governance_records = borrow_global_mut<GovernanceRecords>(pool_address);
-    let vote_delegation = update_and_borrow_mut_delegator_vote_delegation(pool,
-        governance_records, shareholder);
+    let vote_delegation =
+        update_and_borrow_mut_delegator_vote_delegation(
+            pool, governance_records, shareholder
+        );
     let current_voter = vote_delegation.voter;
     let pending_voter = vote_delegation.pending_voter;
-    let current_delegated_votes = update_and_borrow_mut_delegated_votes(pool,
-        governance_records, current_voter);
-    current_delegated_votes.active_shares = current_delegated_votes.active_shares - shares_to_redeem;
+    let current_delegated_votes =
+        update_and_borrow_mut_delegated_votes(
+            pool, governance_records, current_voter
+        );
+    current_delegated_votes.active_shares = current_delegated_votes.active_shares
+        - shares_to_redeem;
     if (current_voter == pending_voter) {
         current_delegated_votes.active_shares_next_lockup = current_delegated_votes.active_shares_next_lockup
             - shares_to_redeem;
     } else {
-        let pending_delegated_votes = update_and_borrow_mut_delegated_votes(pool,
-            governance_records, pending_voter);
+        let pending_delegated_votes =
+            update_and_borrow_mut_delegated_votes(
+                pool, governance_records, pending_voter
+            );
         pending_delegated_votes.active_shares_next_lockup = pending_delegated_votes.active_shares_next_lockup
             - shares_to_redeem;
     };
@@ -4581,16 +5169,23 @@ shares pools, assign commission to operator and eventually prepare delegation po
 
 
 
fun update_governanace_records_for_redeem_pending_inactive_shares(
-    pool: &DelegationPool, pool_address: address, shares_to_redeem: u128, shareholder: address
+    pool: &DelegationPool,
+    pool_address: address,
+    shares_to_redeem: u128,
+    shareholder: address
 ) acquires GovernanceRecords {
     // <pending inactive shares> of <shareholder> -= <shares_to_redeem>  ---->
     // <pending inactive shares> of <current voter of shareholder> -= <shares_to_redeem>
     // no impact on <pending inactive shares> of <next voter of shareholder>
     let governance_records = borrow_global_mut<GovernanceRecords>(pool_address);
-    let current_voter = calculate_and_update_delegator_voter_internal(pool,
-        governance_records, shareholder);
-    let current_delegated_votes = update_and_borrow_mut_delegated_votes(pool,
-        governance_records, current_voter);
+    let current_voter =
+        calculate_and_update_delegator_voter_internal(
+            pool, governance_records, shareholder
+        );
+    let current_delegated_votes =
+        update_and_borrow_mut_delegated_votes(
+            pool, governance_records, current_voter
+        );
     current_delegated_votes.pending_inactive_shares = current_delegated_votes.pending_inactive_shares
         - shares_to_redeem;
 }
diff --git a/aptos-move/framework/supra-framework/doc/stake.md b/aptos-move/framework/supra-framework/doc/stake.md
index 6f8c32f667cc2..20ce522964df5 100644
--- a/aptos-move/framework/supra-framework/doc/stake.md
+++ b/aptos-move/framework/supra-framework/doc/stake.md
@@ -5491,7 +5491,6 @@ Returns validator's next epoch voting power, including pending_active, active, a
 
 
 
pragma verify = false;
-pragma disable_invariants_in_body;
 include ResourceRequirement;
 include GetReconfigStartTimeRequirement;
 include staking_config::StakingRewardsConfigRequirement;
diff --git a/aptos-move/framework/supra-framework/doc/transaction_context.md b/aptos-move/framework/supra-framework/doc/transaction_context.md
index b930357c81eb3..c2e2fbd781032 100644
--- a/aptos-move/framework/supra-framework/doc/transaction_context.md
+++ b/aptos-move/framework/supra-framework/doc/transaction_context.md
@@ -30,6 +30,8 @@
 -  [Function `chain_id_internal`](#0x1_transaction_context_chain_id_internal)
 -  [Function `entry_function_payload`](#0x1_transaction_context_entry_function_payload)
 -  [Function `entry_function_payload_internal`](#0x1_transaction_context_entry_function_payload_internal)
+-  [Function `txn_app_hash`](#0x1_transaction_context_txn_app_hash)
+-  [Function `txn_app_hash_internal`](#0x1_transaction_context_txn_app_hash_internal)
 -  [Function `account_address`](#0x1_transaction_context_account_address)
 -  [Function `module_name`](#0x1_transaction_context_module_name)
 -  [Function `function_name`](#0x1_transaction_context_function_name)
@@ -732,6 +734,55 @@ This function aborts if called outside of the transaction prologue, execution, o
 
 
 
+
+ + + +## Function `txn_app_hash` + +Returns the original transaction hash calculated on the raw-bytes. +This function aborts if called outside of the transaction prologue, execution, or epilogue phases. + + +
public fun txn_app_hash(): vector<u8>
+
+ + + +
+Implementation + + +
public fun txn_app_hash(): vector<u8> {
+    assert!(features::transaction_context_extension_enabled(), error::invalid_state(ETRANSACTION_CONTEXT_EXTENSION_NOT_ENABLED));
+    txn_app_hash_internal()
+}
+
+ + + +
+ + + +## Function `txn_app_hash_internal` + + + +
fun txn_app_hash_internal(): vector<u8>
+
+ + + +
+Implementation + + +
native fun txn_app_hash_internal(): vector<u8>;
+
+ + +
diff --git a/aptos-move/framework/supra-framework/doc/vesting_without_staking.md b/aptos-move/framework/supra-framework/doc/vesting_without_staking.md index 8b6ddf1f8ef2e..f0280f356953c 100644 --- a/aptos-move/framework/supra-framework/doc/vesting_without_staking.md +++ b/aptos-move/framework/supra-framework/doc/vesting_without_staking.md @@ -735,6 +735,8 @@ Admin can only withdraw from an inactive (paused or terminated) vesting contract +Deprecated. + Vesting cannot start before or at the current block timestamp. Has to be in the future. @@ -1090,11 +1092,7 @@ Create a vesting schedule with the given schedule of distributions, a vesting st assert!(fixed_point32::get_raw_value(*vector::borrow(&schedule, schedule_len - 1)) != 0, error::invalid_argument(EEMPTY_VESTING_SCHEDULE)); - assert!(period_duration > 0, error::invalid_argument(EZERO_VESTING_SCHEDULE_PERIOD)); - assert!(start_timestamp_secs >= timestamp::now_seconds(), - error::invalid_argument(EVESTING_START_TOO_SOON),); - VestingSchedule { schedule, start_timestamp_secs, @@ -1114,7 +1112,7 @@ Create a vesting schedule with the given schedule of distributions, a vesting st -
public entry fun create_vesting_contract_with_amounts(admin: &signer, shareholders: vector<address>, amounts: vector<u64>, schedule_numerator: vector<u64>, schedule_denominator: u64, start_timestamp_secs: u64, period_duration: u64, withdrawal_address: address, contract_creation_seed: vector<u8>)
+
public entry fun create_vesting_contract_with_amounts(admin: &signer, shareholders: vector<address>, shares: vector<u64>, vesting_numerators: vector<u64>, vesting_denominator: u64, start_timestamp_secs: u64, period_duration: u64, withdrawal_address: address, contract_creation_seed: vector<u8>)
 
@@ -1126,9 +1124,9 @@ Create a vesting schedule with the given schedule of distributions, a vesting st
public entry fun create_vesting_contract_with_amounts (
     admin: &signer,
     shareholders: vector<address>,
-    amounts: vector<u64>,
-    schedule_numerator: vector<u64>,
-    schedule_denominator: u64,
+    shares: vector<u64>,
+    vesting_numerators: vector<u64>,
+    vesting_denominator: u64,
     start_timestamp_secs: u64,
     period_duration: u64,
     withdrawal_address: address,
@@ -1136,11 +1134,11 @@ Create a vesting schedule with the given schedule of distributions, a vesting st
 ) acquires AdminStore {
     assert!(!system_addresses::is_reserved_address(withdrawal_address),
         error::invalid_argument(EINVALID_WITHDRAWAL_ADDRESS),);
-    assert_account_is_registered_for_apt(withdrawal_address);
+    assert_account_is_registered_for_supra(withdrawal_address);
     assert!(vector::length(&shareholders) > 0,
         error::invalid_argument(ENO_SHAREHOLDERS));
     assert!(
-        vector::length(&shareholders) == vector::length(&amounts),
+        vector::length(&shareholders) == vector::length(&shares),
         error::invalid_argument(ESHARES_LENGTH_MISMATCH),
     );
 
@@ -1160,15 +1158,15 @@ Create a vesting schedule with the given schedule of distributions, a vesting st
     let (contract_signer, contract_signer_cap) = create_vesting_contract_account(admin,
         contract_creation_seed);
     let contract_signer_address = signer::address_of(&contract_signer);
-    let schedule = vector::map_ref(&schedule_numerator, |numerator| {
-        let event = fixed_point32::create_from_rational(*numerator, schedule_denominator);
+    let schedule = vector::map_ref(&vesting_numerators, |numerator| {
+        let event = fixed_point32::create_from_rational(*numerator, vesting_denominator);
         event
     });
 
     let vesting_schedule = create_vesting_schedule(schedule, start_timestamp_secs, period_duration);
     let shareholders_map = simple_map::create<address, VestingRecord>();
     let grant_amount = 0;
-    vector::for_each_reverse(amounts, |amount| {
+    vector::for_each_reverse(shares, |amount| {
         let shareholder = vector::pop_back(&mut shareholders);
         simple_map::add(&mut shareholders_map,
             shareholder,
diff --git a/crates/aptos-rosetta/src/types/objects.rs b/crates/aptos-rosetta/src/types/objects.rs
index 11f19bd151c65..f4a93f30103ff 100644
--- a/crates/aptos-rosetta/src/types/objects.rs
+++ b/crates/aptos-rosetta/src/types/objects.rs
@@ -1,7 +1,6 @@
+// Copyright (c) 2024 Supra.
 // Copyright © Aptos Foundation
 // SPDX-License-Identifier: Apache-2.0
-//
-// Copyright (c) 2024 Supra.
 
 //! Objects of the Rosetta spec
 //!
diff --git a/crates/aptos/src/common/types.rs b/crates/aptos/src/common/types.rs
index e08fd02974ccc..ad6c19a35e75b 100644
--- a/crates/aptos/src/common/types.rs
+++ b/crates/aptos/src/common/types.rs
@@ -1,7 +1,6 @@
+// Copyright (c) 2024 Supra.
 // Copyright © Aptos Foundation
 // SPDX-License-Identifier: Apache-2.0
-//
-// Copyright (c) 2024 Supra.
 
 use super::utils::fund_account;
 use crate::{
diff --git a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/convert.rs b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/convert.rs
index 10d4e02150990..27d12bebde055 100644
--- a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/convert.rs
+++ b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/convert.rs
@@ -1,7 +1,6 @@
+// Copyright (c) 2024 Supra.
 // Copyright © Aptos Foundation
 // SPDX-License-Identifier: Apache-2.0
-//
-// Copyright (c) 2024 Supra.
 
 use aptos_api_types::{
     transaction::ValidatorTransaction as ApiValidatorTransactionEnum, AccountSignature,
diff --git a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs
index 79b734b4361b9..a998a6364bf3f 100644
--- a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs
+++ b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs
@@ -1,7 +1,6 @@
+// Copyright (c) 2024 Supra.
 // Copyright © Aptos Foundation
 // SPDX-License-Identifier: Apache-2.0
-//
-// Copyright (c) 2024 Supra.
 
 use crate::{
     convert::convert_transaction,
diff --git a/execution/executor-types/src/parsed_transaction_output.rs b/execution/executor-types/src/parsed_transaction_output.rs
index a9c26508700c9..88e2259fa2a79 100644
--- a/execution/executor-types/src/parsed_transaction_output.rs
+++ b/execution/executor-types/src/parsed_transaction_output.rs
@@ -1,7 +1,6 @@
+// Copyright (c) 2024 Supra.
 // Copyright © Aptos Foundation
 // SPDX-License-Identifier: Apache-2.0
-//
-// Copyright (c) 2024 Supra.
 
 use aptos_types::{
     contract_event::ContractEvent,
diff --git a/execution/executor/src/components/chunk_output.rs b/execution/executor/src/components/chunk_output.rs
index 30a9011313923..136342d7dc00d 100644
--- a/execution/executor/src/components/chunk_output.rs
+++ b/execution/executor/src/components/chunk_output.rs
@@ -1,8 +1,7 @@
+// Copyright (c) 2024 Supra.
 // Copyright © Aptos Foundation
 // Parts of the project are originally copyright © Meta Platforms, Inc.
 // SPDX-License-Identifier: Apache-2.0
-//
-// Copyright (c) 2024 Supra.
 
 #![forbid(unsafe_code)]
 
diff --git a/protos/proto/aptos/transaction/v1/transaction.proto b/protos/proto/aptos/transaction/v1/transaction.proto
index bab5b63cb0f60..3429d02deb4f9 100644
--- a/protos/proto/aptos/transaction/v1/transaction.proto
+++ b/protos/proto/aptos/transaction/v1/transaction.proto
@@ -1,7 +1,6 @@
+// Copyright (c) 2024 Supra.
 // Copyright © Aptos Foundation
 // SPDX-License-Identifier: Apache-2.0
-//
-// Copyright (c) 2024 Supra.
 
 syntax = "proto3";
 
diff --git a/storage/backup/backup-cli/src/backup_types/transaction/analysis.rs b/storage/backup/backup-cli/src/backup_types/transaction/analysis.rs
index c329a50afcd54..62268e2fe172b 100644
--- a/storage/backup/backup-cli/src/backup_types/transaction/analysis.rs
+++ b/storage/backup/backup-cli/src/backup_types/transaction/analysis.rs
@@ -1,8 +1,7 @@
+// Copyright (c) 2024 Supra.
 // Copyright © Aptos Foundation
 // Parts of the project are originally copyright © Meta Platforms, Inc.
 // SPDX-License-Identifier: Apache-2.0
-//
-// Copyright (c) 2024 Supra.
 
 use anyhow::Result;
 use aptos_types::{
diff --git a/types/src/proptest_types.rs b/types/src/proptest_types.rs
index a0f57b16d1650..9d472ff9c7187 100644
--- a/types/src/proptest_types.rs
+++ b/types/src/proptest_types.rs
@@ -1,8 +1,7 @@
+// Copyright (c) 2024 Supra.
 // Copyright © Aptos Foundation
 // Parts of the project are originally copyright © Meta Platforms, Inc.
 // SPDX-License-Identifier: Apache-2.0
-//
-// Copyright (c) 2024 Supra.
 
 #![allow(clippy::arc_with_non_send_sync)]
 
diff --git a/types/src/transaction/mod.rs b/types/src/transaction/mod.rs
index b1d9ba491aaad..da2974cbb212c 100644
--- a/types/src/transaction/mod.rs
+++ b/types/src/transaction/mod.rs
@@ -1,8 +1,7 @@
+// Copyright (c) 2024 Supra.
 // Copyright © Aptos Foundation
 // Parts of the project are originally copyright © Meta Platforms, Inc.
 // SPDX-License-Identifier: Apache-2.0
-//
-// Copyright (c) 2024 Supra.
 
 #![allow(clippy::arc_with_non_send_sync)]
 
diff --git a/types/src/transaction/user_transaction_context.rs b/types/src/transaction/user_transaction_context.rs
index 7cf32598d7aae..487a8e1074dd7 100644
--- a/types/src/transaction/user_transaction_context.rs
+++ b/types/src/transaction/user_transaction_context.rs
@@ -1,7 +1,6 @@
+// Copyright (c) 2024 Supra.
 // Copyright © Aptos Foundation
 // SPDX-License-Identifier: Apache-2.0
-//
-// Copyright (c) 2024 Supra.
 
 use move_core_types::account_address::AccountAddress;