Skip to content

Commit

Permalink
add arg
Browse files Browse the repository at this point in the history
  • Loading branch information
runtian-zhou committed Dec 16, 2024
1 parent 328074f commit 16346c7
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ module aptos_framework::aptos_governance {
struct GovernancePermission has copy, drop, store {}

/// Permissions
inline fun check_signer_permission(s: &signer) {
inline fun check_governance_permission(s: &signer) {
assert!(
permissioned_signer::check_permission_exists(s, GovernancePermission {}),
error::permission_denied(ENO_GOVERNANCE_PERMISSION),
Expand Down Expand Up @@ -394,7 +394,7 @@ module aptos_framework::aptos_governance {
metadata_hash: vector<u8>,
is_multi_step_proposal: bool,
): u64 acquires GovernanceConfig, GovernanceEvents {
check_signer_permission(proposer);
check_governance_permission(proposer);
let proposer_address = signer::address_of(proposer);
assert!(
stake::get_delegated_voter(stake_pool) == proposer_address,
Expand Down
6 changes: 3 additions & 3 deletions aptos-move/framework/aptos-framework/sources/code.move
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ module aptos_framework::code {
struct CodePublishingPermission has copy, drop, store {}

/// Permissions
public(friend) fun check_signer_permission(s: &signer) {
public(friend) fun check_code_publishing_permission(s: &signer) {
assert!(
permissioned_signer::check_permission_exists(s, CodePublishingPermission {}),
error::permission_denied(ENO_CODE_PERMISSION),
Expand Down Expand Up @@ -166,7 +166,7 @@ module aptos_framework::code {
/// Publishes a package at the given signer's address. The caller must provide package metadata describing the
/// package.
public fun publish_package(owner: &signer, pack: PackageMetadata, code: vector<vector<u8>>) acquires PackageRegistry {
check_signer_permission(owner);
check_code_publishing_permission(owner);
// Disallow incompatible upgrade mode. Governance can decide later if this should be reconsidered.
assert!(
pack.upgrade_policy.policy > upgrade_policy_arbitrary().policy,
Expand Down Expand Up @@ -228,7 +228,7 @@ module aptos_framework::code {
}

public fun freeze_code_object(publisher: &signer, code_object: Object<PackageRegistry>) acquires PackageRegistry {
check_signer_permission(publisher);
check_code_publishing_permission(publisher);
let code_object_addr = object::object_address(&code_object);
assert!(exists<PackageRegistry>(code_object_addr), error::not_found(ECODE_OBJECT_DOES_NOT_EXIST));
assert!(
Expand Down
58 changes: 36 additions & 22 deletions aptos-move/framework/aptos-framework/sources/delegation_pool.move
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ module aptos_framework::delegation_pool {
allowlist: SmartTable<address, bool>,
}

struct DelegationPermission has copy, drop, store {}
enum DelegationPermission has copy, drop, store {
DelegationPoolManagementPermission,
StakeManagementPermission,
}

#[event]
struct AddStake has drop, store {
Expand Down Expand Up @@ -839,15 +842,26 @@ module aptos_framework::delegation_pool {
}

/// Permissions
inline fun check_signer_permission(s: &signer) {
inline fun check_delegation_pool_management_permission(s: &signer) {
assert!(
permissioned_signer::check_permission_exists(s, DelegationPermission::DelegationPoolManagementPermission {}),
error::permission_denied(ENO_DELEGATION_PERMISSION),
);
}

public fun grant_delegation_pool_management_permission(master: &signer, permissioned_signer: &signer) {
permissioned_signer::authorize_unlimited(master, permissioned_signer, DelegationPermission::DelegationPoolManagementPermission {})
}

inline fun check_stake_management_permission(s: &signer) {
assert!(
permissioned_signer::check_permission_exists(s, DelegationPermission {}),
permissioned_signer::check_permission_exists(s, DelegationPermission::StakeManagementPermission {}),
error::permission_denied(ENO_DELEGATION_PERMISSION),
);
}

public fun grant_permission(master: &signer, permissioned_signer: &signer) {
permissioned_signer::authorize_unlimited(master, permissioned_signer, DelegationPermission {})
public fun grant_stake_management_permission(master: &signer, permissioned_signer: &signer) {
permissioned_signer::authorize_unlimited(master, permissioned_signer, DelegationPermission::StakeManagementPermission {})
}

/// Initialize a delegation pool of custom fixed `operator_commission_percentage`.
Expand All @@ -859,7 +873,7 @@ module aptos_framework::delegation_pool {
operator_commission_percentage: u64,
delegation_pool_creation_seed: vector<u8>,
) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
check_signer_permission(owner);
check_delegation_pool_management_permission(owner);
assert!(features::delegation_pools_enabled(), error::invalid_state(EDELEGATION_POOLS_DISABLED));
let owner_address = signer::address_of(owner);
assert!(!owner_cap_exists(owner_address), error::already_exists(EOWNER_CAP_ALREADY_EXISTS));
Expand Down Expand Up @@ -960,7 +974,7 @@ module aptos_framework::delegation_pool {
voting_power: u64,
should_pass: bool
) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
check_signer_permission(voter);
check_stake_management_permission(voter);
assert_partial_governance_voting_enabled(pool_address);
// synchronize delegation and stake pools before any user operation.
synchronize_delegation_pool(pool_address);
Expand Down Expand Up @@ -1020,7 +1034,7 @@ module aptos_framework::delegation_pool {
metadata_hash: vector<u8>,
is_multi_step_proposal: bool,
) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
check_signer_permission(voter);
check_stake_management_permission(voter);
assert_partial_governance_voting_enabled(pool_address);

// synchronize delegation and stake pools before any user operation
Expand Down Expand Up @@ -1313,7 +1327,7 @@ module aptos_framework::delegation_pool {
owner: &signer,
new_operator: address
) acquires DelegationPoolOwnership, DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
check_signer_permission(owner);
check_delegation_pool_management_permission(owner);
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
Expand All @@ -1329,7 +1343,7 @@ module aptos_framework::delegation_pool {
operator: &signer,
new_beneficiary: address
) acquires BeneficiaryForOperator {
check_signer_permission(operator);
check_stake_management_permission(operator);
assert!(features::operator_beneficiary_change_enabled(), std::error::invalid_state(
EOPERATOR_BENEFICIARY_CHANGE_NOT_SUPPORTED
));
Expand All @@ -1355,7 +1369,7 @@ module aptos_framework::delegation_pool {
owner: &signer,
new_commission_percentage: u64
) acquires DelegationPoolOwnership, DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
check_signer_permission(owner);
check_delegation_pool_management_permission(owner);
assert!(features::commission_change_delegation_pool_enabled(), error::invalid_state(
ECOMMISSION_RATE_CHANGE_NOT_SUPPORTED
));
Expand Down Expand Up @@ -1401,7 +1415,7 @@ module aptos_framework::delegation_pool {
owner: &signer,
new_voter: address
) acquires DelegationPoolOwnership, DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
check_signer_permission(owner);
check_delegation_pool_management_permission(owner);
// No one can change delegated_voter once the partial governance voting feature is enabled.
assert!(
!features::delegation_pool_partial_governance_voting_enabled(),
Expand All @@ -1420,7 +1434,7 @@ module aptos_framework::delegation_pool {
pool_address: address,
new_voter: address
) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
check_signer_permission(delegator);
check_stake_management_permission(delegator);
assert_partial_governance_voting_enabled(pool_address);

// synchronize delegation and stake pools before any user operation
Expand Down Expand Up @@ -1478,7 +1492,7 @@ module aptos_framework::delegation_pool {
public entry fun enable_delegators_allowlisting(
owner: &signer,
) acquires DelegationPoolOwnership, DelegationPool {
check_signer_permission(owner);
check_delegation_pool_management_permission(owner);
assert!(
features::delegation_pool_allowlisting_enabled(),
error::invalid_state(EDELEGATORS_ALLOWLISTING_NOT_SUPPORTED)
Expand All @@ -1497,7 +1511,7 @@ module aptos_framework::delegation_pool {
public entry fun disable_delegators_allowlisting(
owner: &signer,
) acquires DelegationPoolOwnership, DelegationPoolAllowlisting {
check_signer_permission(owner);
check_delegation_pool_management_permission(owner);
let pool_address = get_owned_pool_address(signer::address_of(owner));
assert_allowlisting_enabled(pool_address);

Expand All @@ -1513,7 +1527,7 @@ module aptos_framework::delegation_pool {
owner: &signer,
delegator_address: address,
) acquires DelegationPoolOwnership, DelegationPoolAllowlisting {
check_signer_permission(owner);
check_delegation_pool_management_permission(owner);
let pool_address = get_owned_pool_address(signer::address_of(owner));
assert_allowlisting_enabled(pool_address);

Expand All @@ -1529,7 +1543,7 @@ module aptos_framework::delegation_pool {
owner: &signer,
delegator_address: address,
) acquires DelegationPoolOwnership, DelegationPoolAllowlisting {
check_signer_permission(owner);
check_delegation_pool_management_permission(owner);
let pool_address = get_owned_pool_address(signer::address_of(owner));
assert_allowlisting_enabled(pool_address);

Expand All @@ -1545,7 +1559,7 @@ module aptos_framework::delegation_pool {
owner: &signer,
delegator_address: address,
) acquires DelegationPoolOwnership, DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage, DelegationPoolAllowlisting {
check_signer_permission(owner);
check_delegation_pool_management_permission(owner);
let pool_address = get_owned_pool_address(signer::address_of(owner));
assert_allowlisting_enabled(pool_address);
assert!(
Expand All @@ -1570,7 +1584,7 @@ module aptos_framework::delegation_pool {
pool_address: address,
amount: u64
) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage, DelegationPoolAllowlisting {
check_signer_permission(delegator);
check_stake_management_permission(delegator);
// short-circuit if amount to add is 0 so no event is emitted
if (amount == 0) { return };

Expand Down Expand Up @@ -1628,7 +1642,7 @@ module aptos_framework::delegation_pool {
pool_address: address,
amount: u64
) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
check_signer_permission(delegator);
check_stake_management_permission(delegator);
// short-circuit if amount to unlock is 0 so no event is emitted
if (amount == 0) { return };

Expand Down Expand Up @@ -1690,7 +1704,7 @@ module aptos_framework::delegation_pool {
pool_address: address,
amount: u64
) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage, DelegationPoolAllowlisting {
check_signer_permission(delegator);
check_stake_management_permission(delegator);
// short-circuit if amount to reactivate is 0 so no event is emitted
if (amount == 0) { return };

Expand Down Expand Up @@ -1741,7 +1755,7 @@ module aptos_framework::delegation_pool {
pool_address: address,
amount: u64
) acquires DelegationPool, GovernanceRecords, BeneficiaryForOperator, NextCommissionPercentage {
check_signer_permission(delegator);
check_stake_management_permission(delegator);
assert!(amount > 0, error::invalid_argument(EWITHDRAW_ZERO_STAKE));
// synchronize delegation and stake pools before any user operation
synchronize_delegation_pool(pool_address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module aptos_framework::object_code_deployment {
metadata_serialized: vector<u8>,
code: vector<vector<u8>>,
) {
code::check_signer_permission(publisher);
code::check_code_publishing_permission(publisher);
assert!(
features::is_object_code_deployment_enabled(),
error::unavailable(EOBJECT_CODE_DEPLOYMENT_NOT_SUPPORTED),
Expand Down Expand Up @@ -123,7 +123,7 @@ module aptos_framework::object_code_deployment {
code: vector<vector<u8>>,
code_object: Object<PackageRegistry>,
) acquires ManagingRefs {
code::check_signer_permission(publisher);
code::check_code_publishing_permission(publisher);
let publisher_address = signer::address_of(publisher);
assert!(
object::is_owner(code_object, publisher_address),
Expand Down
Loading

0 comments on commit 16346c7

Please sign in to comment.