Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions aptos-move/framework/aptos-framework/doc/aptos_governance.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ on a proposal multiple times as long as the total voting power of these votes do
- [Function `initialize`](#0x1_aptos_governance_initialize)
- [Function `update_governance_config`](#0x1_aptos_governance_update_governance_config)
- [Function `initialize_partial_voting`](#0x1_aptos_governance_initialize_partial_voting)
- [Function `partial_voting_initialized`](#0x1_aptos_governance_partial_voting_initialized)
- [Function `initialize_partial_voting_if_needed`](#0x1_aptos_governance_initialize_partial_voting_if_needed)
- [Function `get_voting_duration_secs`](#0x1_aptos_governance_get_voting_duration_secs)
- [Function `get_min_voting_threshold`](#0x1_aptos_governance_get_min_voting_threshold)
- [Function `get_required_proposer_stake`](#0x1_aptos_governance_get_required_proposer_stake)
Expand Down Expand Up @@ -72,6 +74,8 @@ on a proposal multiple times as long as the total voting power of these votes do
- [Function `initialize`](#@Specification_1_initialize)
- [Function `update_governance_config`](#@Specification_1_update_governance_config)
- [Function `initialize_partial_voting`](#@Specification_1_initialize_partial_voting)
- [Function `partial_voting_initialized`](#@Specification_1_partial_voting_initialized)
- [Function `initialize_partial_voting_if_needed`](#@Specification_1_initialize_partial_voting_if_needed)
- [Function `get_voting_duration_secs`](#@Specification_1_get_voting_duration_secs)
- [Function `get_min_voting_threshold`](#@Specification_1_get_min_voting_threshold)
- [Function `get_required_proposer_stake`](#@Specification_1_get_required_proposer_stake)
Expand Down Expand Up @@ -1099,6 +1103,65 @@ proposals with a signer for the aptos_framework (0x1) account.



</details>

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

## Function `partial_voting_initialized`



<pre><code>#[view]
<b>public</b> <b>fun</b> <a href="aptos_governance.md#0x1_aptos_governance_partial_voting_initialized">partial_voting_initialized</a>(): bool
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="aptos_governance.md#0x1_aptos_governance_partial_voting_initialized">partial_voting_initialized</a>(): bool {
<b>exists</b>&lt;<a href="aptos_governance.md#0x1_aptos_governance_VotingRecordsV2">VotingRecordsV2</a>&gt;(@aptos_framework)
}
</code></pre>



</details>

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

## Function `initialize_partial_voting_if_needed`

Initializes the state for Aptos Governance partial voting if it has not already been initialized.
This can only be called with a signer for the aptos_framework (0x1) account.


<pre><code><b>public</b> <b>fun</b> <a href="aptos_governance.md#0x1_aptos_governance_initialize_partial_voting_if_needed">initialize_partial_voting_if_needed</a>(aptos_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="aptos_governance.md#0x1_aptos_governance_initialize_partial_voting_if_needed">initialize_partial_voting_if_needed</a>(
aptos_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>,
) {
<a href="system_addresses.md#0x1_system_addresses_assert_aptos_framework">system_addresses::assert_aptos_framework</a>(aptos_framework);

<b>if</b> (!<a href="aptos_governance.md#0x1_aptos_governance_partial_voting_initialized">partial_voting_initialized</a>()) {
<b>move_to</b>(aptos_framework, <a href="aptos_governance.md#0x1_aptos_governance_VotingRecordsV2">VotingRecordsV2</a> {
votes: <a href="../../aptos-stdlib/doc/smart_table.md#0x1_smart_table_new">smart_table::new</a>(),
});
}
}
</code></pre>



</details>

<a id="0x1_aptos_governance_get_voting_duration_secs"></a>
Expand Down Expand Up @@ -2319,6 +2382,44 @@ Abort if structs have already been created.



<a id="@Specification_1_partial_voting_initialized"></a>

### Function `partial_voting_initialized`


<pre><code>#[view]
<b>public</b> <b>fun</b> <a href="aptos_governance.md#0x1_aptos_governance_partial_voting_initialized">partial_voting_initialized</a>(): bool
</code></pre>




<pre><code><b>pragma</b> opaque;
<b>aborts_if</b> <b>false</b>;
<b>ensures</b> result == <b>exists</b>&lt;<a href="aptos_governance.md#0x1_aptos_governance_VotingRecordsV2">VotingRecordsV2</a>&gt;(@aptos_framework);
</code></pre>



<a id="@Specification_1_initialize_partial_voting_if_needed"></a>

### Function `initialize_partial_voting_if_needed`


<pre><code><b>public</b> <b>fun</b> <a href="aptos_governance.md#0x1_aptos_governance_initialize_partial_voting_if_needed">initialize_partial_voting_if_needed</a>(aptos_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>)
</code></pre>


Signer address must be @aptos_framework.


<pre><code><b>let</b> addr = <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(aptos_framework);
<b>aborts_if</b> addr != @aptos_framework;
<b>ensures</b> <b>exists</b>&lt;<a href="aptos_governance.md#0x1_aptos_governance_VotingRecordsV2">VotingRecordsV2</a>&gt;(@aptos_framework);
</code></pre>




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

Expand Down
61 changes: 60 additions & 1 deletion aptos-move/framework/aptos-framework/doc/delegation_pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ transferred to A
- [Function `owner_cap_exists`](#0x1_delegation_pool_owner_cap_exists)
- [Function `get_owned_pool_address`](#0x1_delegation_pool_get_owned_pool_address)
- [Function `delegation_pool_exists`](#0x1_delegation_pool_delegation_pool_exists)
- [Function `governance_records_initialized`](#0x1_delegation_pool_governance_records_initialized)
- [Function `partial_governance_voting_enabled`](#0x1_delegation_pool_partial_governance_voting_enabled)
- [Function `observed_lockup_cycle`](#0x1_delegation_pool_observed_lockup_cycle)
- [Function `is_next_commission_percentage_effective`](#0x1_delegation_pool_is_next_commission_percentage_effective)
Expand Down Expand Up @@ -179,6 +180,7 @@ transferred to A
- [Function `initialize_delegation_pool`](#0x1_delegation_pool_initialize_delegation_pool)
- [Function `beneficiary_for_operator`](#0x1_delegation_pool_beneficiary_for_operator)
- [Function `enable_partial_governance_voting`](#0x1_delegation_pool_enable_partial_governance_voting)
- [Function `enable_partial_governance_voting_if_needed`](#0x1_delegation_pool_enable_partial_governance_voting_if_needed)
- [Function `vote`](#0x1_delegation_pool_vote)
- [Function `create_proposal`](#0x1_delegation_pool_create_proposal)
- [Function `assert_owner_cap_exists`](#0x1_delegation_pool_assert_owner_cap_exists)
Expand Down Expand Up @@ -2120,6 +2122,32 @@ Return whether a delegation pool exists at supplied address <code>addr</code>.



</details>

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

## Function `governance_records_initialized`

Return whether a delegation pool has governance records initialized.


<pre><code>#[view]
<b>public</b> <b>fun</b> <a href="delegation_pool.md#0x1_delegation_pool_governance_records_initialized">governance_records_initialized</a>(pool_address: <b>address</b>): bool
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="delegation_pool.md#0x1_delegation_pool_governance_records_initialized">governance_records_initialized</a>(pool_address: <b>address</b>): bool {
<b>exists</b>&lt;<a href="delegation_pool.md#0x1_delegation_pool_GovernanceRecords">GovernanceRecords</a>&gt;(pool_address)
}
</code></pre>



</details>

<a id="0x1_delegation_pool_partial_governance_voting_enabled"></a>
Expand All @@ -2140,7 +2168,7 @@ Return whether a delegation pool has already enabled partial governance voting.


<pre><code><b>public</b> <b>fun</b> <a href="delegation_pool.md#0x1_delegation_pool_partial_governance_voting_enabled">partial_governance_voting_enabled</a>(pool_address: <b>address</b>): bool {
<b>exists</b>&lt;<a href="delegation_pool.md#0x1_delegation_pool_GovernanceRecords">GovernanceRecords</a>&gt;(pool_address) && <a href="stake.md#0x1_stake_get_delegated_voter">stake::get_delegated_voter</a>(pool_address) == pool_address
<a href="delegation_pool.md#0x1_delegation_pool_governance_records_initialized">governance_records_initialized</a>(pool_address) && <a href="stake.md#0x1_stake_get_delegated_voter">stake::get_delegated_voter</a>(pool_address) == pool_address
}
</code></pre>

Expand Down Expand Up @@ -3083,6 +3111,37 @@ The existing voter will be replaced. The function is permissionless.



</details>

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

## Function `enable_partial_governance_voting_if_needed`

Enable partial governance voting on a delegation pool if it has not already been initialized.
This is intended for idempotent migration scripts over existing delegation pools.


<pre><code><b>public</b> entry <b>fun</b> <a href="delegation_pool.md#0x1_delegation_pool_enable_partial_governance_voting_if_needed">enable_partial_governance_voting_if_needed</a>(pool_address: <b>address</b>)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> entry <b>fun</b> <a href="delegation_pool.md#0x1_delegation_pool_enable_partial_governance_voting_if_needed">enable_partial_governance_voting_if_needed</a>(
pool_address: <b>address</b>,
) <b>acquires</b> <a href="delegation_pool.md#0x1_delegation_pool_DelegationPool">DelegationPool</a>, <a href="delegation_pool.md#0x1_delegation_pool_GovernanceRecords">GovernanceRecords</a>, <a href="delegation_pool.md#0x1_delegation_pool_BeneficiaryForOperator">BeneficiaryForOperator</a>, <a href="delegation_pool.md#0x1_delegation_pool_NextCommissionPercentage">NextCommissionPercentage</a> {
<a href="delegation_pool.md#0x1_delegation_pool_assert_delegation_pool_exists">assert_delegation_pool_exists</a>(pool_address);
<b>if</b> (!<a href="delegation_pool.md#0x1_delegation_pool_governance_records_initialized">governance_records_initialized</a>(pool_address)) {
<a href="delegation_pool.md#0x1_delegation_pool_enable_partial_governance_voting">enable_partial_governance_voting</a>(pool_address);
}
}
</code></pre>



</details>

<a id="0x1_delegation_pool_vote"></a>
Expand Down
16 changes: 16 additions & 0 deletions aptos-move/framework/aptos-framework/doc/staking_contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,16 @@ Store amount must be at least the min stake required for a stake pool to join th



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

Beneficiary cannot be a reserved address that cannot receive coin distributions.


<pre><code><b>const</b> <a href="staking_contract.md#0x1_staking_contract_EINVALID_BENEFICIARY_ADDRESS">EINVALID_BENEFICIARY_ADDRESS</a>: u64 = 10;
</code></pre>



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

Caller must be either the staker, operator, or beneficiary.
Expand Down Expand Up @@ -2283,6 +2293,12 @@ the beneficiary. An operator can set one beneficiary for staking contract pools,
<b>assert</b>!(<a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_operator_beneficiary_change_enabled">features::operator_beneficiary_change_enabled</a>(), std::error::invalid_state(
<a href="staking_contract.md#0x1_staking_contract_EOPERATOR_BENEFICIARY_CHANGE_NOT_SUPPORTED">EOPERATOR_BENEFICIARY_CHANGE_NOT_SUPPORTED</a>
));
// @vm_reserved can never have an <a href="account.md#0x1_account">account</a> created for it, so it can't receive <a href="coin.md#0x1_coin">coin</a> distributions.
// Allowing it <b>as</b> a beneficiary would permanently brick distribution for the staking contract.
<b>assert</b>!(
new_beneficiary != @vm_reserved,
<a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="staking_contract.md#0x1_staking_contract_EINVALID_BENEFICIARY_ADDRESS">EINVALID_BENEFICIARY_ADDRESS</a>),
);
// The beneficiay <b>address</b> of an operator is stored under the operator's <b>address</b>.
// So, the operator does not need <b>to</b> be validated <b>with</b> respect <b>to</b> a staking pool.
<b>let</b> operator_addr = <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(operator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,12 @@ pub enum EntryFunctionCall {
pool_address: AccountAddress,
},

/// Enable partial governance voting on a delegation pool if it has not already been initialized.
/// This is intended for idempotent migration scripts over existing delegation pools.
DelegationPoolEnablePartialGovernanceVotingIfNeeded {
pool_address: AccountAddress,
},

/// Evict a delegator that is not allowlisted by unlocking their entire stake.
DelegationPoolEvictDelegator {
delegator_address: AccountAddress,
Expand Down Expand Up @@ -1657,6 +1663,9 @@ impl EntryFunctionCall {
DelegationPoolEnablePartialGovernanceVoting { pool_address } => {
delegation_pool_enable_partial_governance_voting(pool_address)
},
DelegationPoolEnablePartialGovernanceVotingIfNeeded { pool_address } => {
delegation_pool_enable_partial_governance_voting_if_needed(pool_address)
},
DelegationPoolEvictDelegator { delegator_address } => {
delegation_pool_evict_delegator(delegator_address)
},
Expand Down Expand Up @@ -3498,6 +3507,25 @@ pub fn delegation_pool_enable_partial_governance_voting(
))
}

/// Enable partial governance voting on a delegation pool if it has not already been initialized.
/// This is intended for idempotent migration scripts over existing delegation pools.
pub fn delegation_pool_enable_partial_governance_voting_if_needed(
pool_address: AccountAddress,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("delegation_pool").to_owned(),
),
ident_str!("enable_partial_governance_voting_if_needed").to_owned(),
vec![],
vec![bcs::to_bytes(&pool_address).unwrap()],
))
}

/// Evict a delegator that is not allowlisted by unlocking their entire stake.
pub fn delegation_pool_evict_delegator(delegator_address: AccountAddress) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
Expand Down Expand Up @@ -6722,6 +6750,20 @@ mod decoder {
}
}

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

pub fn delegation_pool_evict_delegator(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
Expand Down Expand Up @@ -8390,6 +8432,10 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
"delegation_pool_enable_partial_governance_voting".to_string(),
Box::new(decoder::delegation_pool_enable_partial_governance_voting),
);
map.insert(
"delegation_pool_enable_partial_governance_voting_if_needed".to_string(),
Box::new(decoder::delegation_pool_enable_partial_governance_voting_if_needed),
);
map.insert(
"delegation_pool_evict_delegator".to_string(),
Box::new(decoder::delegation_pool_evict_delegator),
Expand Down
1 change: 1 addition & 0 deletions aptos-move/framework/move-stdlib/doc/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ Lifetime: transient

Whether the Atomic bridge is available
Lifetime: transient
Deprecated in favor of <code><a href="features.md#0x1_features_ALLOW_SERIALIZED_SCRIPT_ARGS">ALLOW_SERIALIZED_SCRIPT_ARGS</a></code> as feature flag 72


<pre><code><b>const</b> <a href="features.md#0x1_features_NATIVE_BRIDGE">NATIVE_BRIDGE</a>: u64 = 72;
Expand Down
Loading