From 871e72d1a78d9edf1aa2fb5bb259c8eec195a1cd Mon Sep 17 00:00:00 2001 From: Aaron Gao Date: Tue, 30 Apr 2024 23:07:40 -0600 Subject: [PATCH] [hotfix] create a different struct for module events instead of reusing v1 and other fixes --- .../tests/aptos_test_harness/table.exp | 40 +- .../aptos-framework/doc/delegation_pool.md | 340 +++++++++++++- .../aptos-framework/doc/multisig_account.md | 10 + .../aptos-framework/doc/reconfiguration.md | 13 +- .../sources/delegation_pool.move | 59 ++- .../sources/multisig_account.move | 10 + .../sources/reconfiguration.move | 13 +- aptos-move/framework/aptos-token/doc/token.md | 415 +++++++++++++++++- .../aptos-token/doc/token_transfers.md | 159 ++++++- .../framework/aptos-token/sources/token.move | 131 +++++- .../aptos-token/sources/token_transfers.move | 48 +- 11 files changed, 1178 insertions(+), 60 deletions(-) diff --git a/aptos-move/aptos-transactional-test-harness/tests/aptos_test_harness/table.exp b/aptos-move/aptos-transactional-test-harness/tests/aptos_test_harness/table.exp index 5ece525a662c6e..b0352e4c592883 100644 --- a/aptos-move/aptos-transactional-test-harness/tests/aptos_test_harness/table.exp +++ b/aptos-move/aptos-transactional-test-harness/tests/aptos_test_harness/table.exp @@ -2,6 +2,10 @@ processed 8 tasks task 1 'run'. lines 6-8: Events: +{ + type: 0x3::token::CreateCollection + data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b7300006400000000000000" +} { key: 0400000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6 seq_num: 0 @@ -10,24 +14,36 @@ Events: } { type: 0x1::transaction_fee::FeeStatement - data: "64000000000000000400000000000000020000000000000028720100000000000000000000000000" + data: "65000000000000000400000000000000030000000000000028720100000000000000000000000000" }mutable inputs after call: local#0: 0 return values: 0 task 2 'run'. lines 9-9: Events: +{ + type: 0x3::token::CreateTokenData + data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00640000000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6010000000000000000000000000000000a6765656b5f746f6b656e0000000000000000" +} { key: 0500000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6 seq_num: 0 type: 0x3::token::CreateTokenDataEvent data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00640000000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6010000000000000000000000000000000a6765656b5f746f6b656e0000000000000000" } +{ + type: 0x3::token::MintToken + data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e0a00000000000000" +} { key: 0600000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6 seq_num: 0 type: 0x3::token::MintTokenEvent data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e0a00000000000000" } +{ + type: 0x3::token::Deposit + data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000a00000000000000" +} { key: 0700000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6 seq_num: 0 @@ -36,7 +52,7 @@ Events: } { type: 0x1::transaction_fee::FeeStatement - data: "9b0000000000000006000000000000000300000000000000c83a0200000000000000000000000000" + data: "9c0000000000000007000000000000000400000000000000c83a0200000000000000000000000000" }mutable inputs after call: local#0: 0 return values: 0 @@ -82,12 +98,20 @@ task 4 'view_table'. lines 13-15: task 5 'run'. lines 16-18: Events: +{ + type: 0x3::token::Withdraw + data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000100000000000000" +} { key: 0800000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6 seq_num: 0 type: 0x3::token::WithdrawEvent data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000100000000000000" } +{ + type: 0x3::token_transfers::TokenOffer + data: "9c3b634ac05d0af393e0f93b9b19b61e7cac1c519f566276aa0c6fd15dac12aaf75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000100000000000000" +} { key: 0b00000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6 seq_num: 0 @@ -96,18 +120,26 @@ Events: } { type: 0x1::transaction_fee::FeeStatement - data: "6b000000000000000500000000000000030000000000000018820100000000000000000000000000" + data: "6c000000000000000600000000000000040000000000000018820100000000000000000000000000" }mutable inputs after call: local#0: 0 return values: 0 task 6 'run'. lines 19-19: Events: +{ + type: 0x3::token::Deposit + data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000100000000000000" +} { key: 04000000000000009c3b634ac05d0af393e0f93b9b19b61e7cac1c519f566276aa0c6fd15dac12aa seq_num: 0 type: 0x3::token::DepositEvent data: "f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000100000000000000" } +{ + type: 0x3::token_transfers::TokenClaim + data: "9c3b634ac05d0af393e0f93b9b19b61e7cac1c519f566276aa0c6fd15dac12aaf75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb60b6170746f735f70756e6b730a6765656b5f746f6b656e00000000000000000100000000000000" +} { key: 0d00000000000000f75daa73fc071f93593335eb9033da804777eb94491650dd3f095ce6f778acb6 seq_num: 0 @@ -116,7 +148,7 @@ Events: } { type: 0x1::transaction_fee::FeeStatement - data: "6b0000000000000005000000000000000300000000000000b88201000000000058bb000000000000" + data: "6c0000000000000006000000000000000400000000000000b88201000000000058bb000000000000" }mutable inputs after call: local#0: 0 return values: 0 diff --git a/aptos-move/framework/aptos-framework/doc/delegation_pool.md b/aptos-move/framework/aptos-framework/doc/delegation_pool.md index bab9d467506bc8..779852aa4bd728 100644 --- a/aptos-move/framework/aptos-framework/doc/delegation_pool.md +++ b/aptos-move/framework/aptos-framework/doc/delegation_pool.md @@ -124,14 +124,21 @@ transferred to A - [Resource `BeneficiaryForOperator`](#0x1_delegation_pool_BeneficiaryForOperator) - [Resource `NextCommissionPercentage`](#0x1_delegation_pool_NextCommissionPercentage) - [Resource `DelegationPoolAllowlisting`](#0x1_delegation_pool_DelegationPoolAllowlisting) +- [Struct `AddStake`](#0x1_delegation_pool_AddStake) - [Struct `AddStakeEvent`](#0x1_delegation_pool_AddStakeEvent) +- [Struct `ReactivateStake`](#0x1_delegation_pool_ReactivateStake) - [Struct `ReactivateStakeEvent`](#0x1_delegation_pool_ReactivateStakeEvent) +- [Struct `UnlockStake`](#0x1_delegation_pool_UnlockStake) - [Struct `UnlockStakeEvent`](#0x1_delegation_pool_UnlockStakeEvent) +- [Struct `WithdrawStake`](#0x1_delegation_pool_WithdrawStake) - [Struct `WithdrawStakeEvent`](#0x1_delegation_pool_WithdrawStakeEvent) - [Struct `DistributeCommissionEvent`](#0x1_delegation_pool_DistributeCommissionEvent) - [Struct `DistributeCommission`](#0x1_delegation_pool_DistributeCommission) +- [Struct `Vote`](#0x1_delegation_pool_Vote) - [Struct `VoteEvent`](#0x1_delegation_pool_VoteEvent) +- [Struct `CreateProposal`](#0x1_delegation_pool_CreateProposal) - [Struct `CreateProposalEvent`](#0x1_delegation_pool_CreateProposalEvent) +- [Struct `DelegateVotingPower`](#0x1_delegation_pool_DelegateVotingPower) - [Struct `DelegateVotingPowerEvent`](#0x1_delegation_pool_DelegateVotingPowerEvent) - [Struct `SetBeneficiaryForOperator`](#0x1_delegation_pool_SetBeneficiaryForOperator) - [Struct `CommissionPercentageChange`](#0x1_delegation_pool_CommissionPercentageChange) @@ -670,6 +677,52 @@ evicted later by the pool owner. + + + + +## Struct `AddStake` + + + +
#[event]
+struct AddStake has drop, store
+
+ + + +
+Fields + + +
+
+pool_address: address +
+
+ +
+
+delegator_address: address +
+
+ +
+
+amount_added: u64 +
+
+ +
+
+add_stake_fee: u64 +
+
+ +
+
+ +
@@ -678,8 +731,7 @@ evicted later by the pool owner. -
#[event]
-struct AddStakeEvent has drop, store
+
struct AddStakeEvent has drop, store
 
@@ -716,6 +768,46 @@ evicted later by the pool owner. + + + + +## Struct `ReactivateStake` + + + +
#[event]
+struct ReactivateStake has drop, store
+
+ + + +
+Fields + + +
+
+pool_address: address +
+
+ +
+
+delegator_address: address +
+
+ +
+
+amount_reactivated: u64 +
+
+ +
+
+ +
@@ -724,8 +816,7 @@ evicted later by the pool owner. -
#[event]
-struct ReactivateStakeEvent has drop, store
+
struct ReactivateStakeEvent has drop, store
 
@@ -756,6 +847,46 @@ evicted later by the pool owner. + + + + +## Struct `UnlockStake` + + + +
#[event]
+struct UnlockStake has drop, store
+
+ + + +
+Fields + + +
+
+pool_address: address +
+
+ +
+
+delegator_address: address +
+
+ +
+
+amount_unlocked: u64 +
+
+ +
+
+ +
@@ -764,8 +895,7 @@ evicted later by the pool owner. -
#[event]
-struct UnlockStakeEvent has drop, store
+
struct UnlockStakeEvent has drop, store
 
@@ -796,6 +926,46 @@ evicted later by the pool owner. + + + + +## Struct `WithdrawStake` + + + +
#[event]
+struct WithdrawStake has drop, store
+
+ + + +
+Fields + + +
+
+pool_address: address +
+
+ +
+
+delegator_address: address +
+
+ +
+
+amount_withdrawn: u64 +
+
+ +
+
+ +
@@ -804,8 +974,7 @@ evicted later by the pool owner. -
#[event]
-struct WithdrawStakeEvent has drop, store
+
struct WithdrawStakeEvent has drop, store
 
@@ -934,6 +1103,58 @@ evicted later by the pool owner. + + + + +## Struct `Vote` + + + +
#[event]
+struct Vote has drop, store
+
+ + + +
+Fields + + +
+
+voter: address +
+
+ +
+
+proposal_id: u64 +
+
+ +
+
+delegation_pool: address +
+
+ +
+
+num_votes: u64 +
+
+ +
+
+should_pass: bool +
+
+ +
+
+ +
@@ -942,8 +1163,7 @@ evicted later by the pool owner. -
#[event]
-struct VoteEvent has drop, store
+
struct VoteEvent has drop, store
 
@@ -986,6 +1206,46 @@ evicted later by the pool owner. + + + + +## Struct `CreateProposal` + + + +
#[event]
+struct CreateProposal has drop, store
+
+ + + +
+Fields + + +
+
+proposal_id: u64 +
+
+ +
+
+voter: address +
+
+ +
+
+delegation_pool: address +
+
+ +
+
+ +
@@ -994,8 +1254,7 @@ evicted later by the pool owner. -
#[event]
-struct CreateProposalEvent has drop, store
+
struct CreateProposalEvent has drop, store
 
@@ -1026,6 +1285,46 @@ evicted later by the pool owner. + + + + +## Struct `DelegateVotingPower` + + + +
#[event]
+struct DelegateVotingPower has drop, store
+
+ + + +
+Fields + + +
+
+pool_address: address +
+
+ +
+
+delegator: address +
+
+ +
+
+voter: address +
+
+ +
+
+ +
@@ -1034,8 +1333,7 @@ evicted later by the pool owner. -
#[event]
-struct DelegateVotingPowerEvent has drop, store
+
struct DelegateVotingPowerEvent has drop, store
 
@@ -2633,7 +2931,7 @@ Vote on a proposal with a voter's voting power. To successfully vote, the follow if (features::module_event_migration_enabled()) { event::emit( - VoteEvent { + Vote { voter: voter_address, proposal_id, delegation_pool: pool_address, @@ -2712,7 +3010,7 @@ voting power in THIS delegation pool must be not less than the minimum required if (features::module_event_migration_enabled()) { event::emit( - CreateProposalEvent { + CreateProposal { proposal_id, voter: voter_addr, delegation_pool: pool_address, @@ -3680,7 +3978,7 @@ this change won't take effects until the next lockup period. }; if (features::module_event_migration_enabled()) { - event::emit(DelegateVotingPowerEvent { + event::emit(DelegateVotingPower { pool_address, delegator: delegator_address, voter: new_voter, @@ -3935,7 +4233,7 @@ Add amount of coins to the delegation pool pool_addressif (features::module_event_migration_enabled()) { event::emit( - AddStakeEvent { + AddStake { pool_address, delegator_address, amount_added: amount, @@ -4039,7 +4337,7 @@ at most how much active stake there is on the stake pool. if (features::module_event_migration_enabled()) { event::emit( - UnlockStakeEvent { + UnlockStake { pool_address, delegator_address, amount_unlocked: amount, @@ -4109,7 +4407,7 @@ Move amount of coins from pending_inactive to active. if (features::module_event_migration_enabled()) { event::emit( - ReactivateStakeEvent { + ReactivateStake { pool_address, delegator_address, amount_reactivated: amount, @@ -4234,7 +4532,7 @@ Withdraw amount of owned inactive stake from the delegation pool at if (features::module_event_migration_enabled()) { event::emit( - WithdrawStakeEvent { + WithdrawStake { pool_address, delegator_address, amount_withdrawn: amount, diff --git a/aptos-move/framework/aptos-framework/doc/multisig_account.md b/aptos-move/framework/aptos-framework/doc/multisig_account.md index 97ef3cef67eee3..ad1a376c19d47f 100644 --- a/aptos-move/framework/aptos-framework/doc/multisig_account.md +++ b/aptos-move/framework/aptos-framework/doc/multisig_account.md @@ -3196,6 +3196,16 @@ This function is private so no other code can call this beside the VM itself as let (num_approvals, _) = remove_executed_transaction(multisig_account_resource); if(features::multisig_v2_enhancement_feature_enabled() && implicit_approval) { + if (std::features::module_event_migration_enabled()) { + emit( + Vote { + multisig_account, + owner: executor, + sequence_number, + approved: true, + } + ); + }; num_approvals = num_approvals + 1; emit_event( &mut multisig_account_resource.vote_events, diff --git a/aptos-move/framework/aptos-framework/doc/reconfiguration.md b/aptos-move/framework/aptos-framework/doc/reconfiguration.md index e8bcf138c083ac..3415e0a820de1f 100644 --- a/aptos-move/framework/aptos-framework/doc/reconfiguration.md +++ b/aptos-move/framework/aptos-framework/doc/reconfiguration.md @@ -421,13 +421,6 @@ Signal validators to start using new configuration. Must be called from friend c }; config_ref.epoch = config_ref.epoch + 1; - event::emit_event<NewEpochEvent>( - &mut config_ref.events, - NewEpochEvent { - epoch: config_ref.epoch, - }, - ); - if (std::features::module_event_migration_enabled()) { event::emit( NewEpoch { @@ -435,6 +428,12 @@ Signal validators to start using new configuration. Must be called from friend c }, ); }; + event::emit_event<NewEpochEvent>( + &mut config_ref.events, + NewEpochEvent { + epoch: config_ref.epoch, + }, + ); reconfiguration_state::on_reconfig_finish(); } diff --git a/aptos-move/framework/aptos-framework/sources/delegation_pool.move b/aptos-move/framework/aptos-framework/sources/delegation_pool.move index b6dc4b21823c82..eba02f6e32c3f7 100644 --- a/aptos-move/framework/aptos-framework/sources/delegation_pool.move +++ b/aptos-move/framework/aptos-framework/sources/delegation_pool.move @@ -347,6 +347,13 @@ module aptos_framework::delegation_pool { } #[event] + struct AddStake has drop, store { + pool_address: address, + delegator_address: address, + amount_added: u64, + add_stake_fee: u64, + } + struct AddStakeEvent has drop, store { pool_address: address, delegator_address: address, @@ -355,6 +362,12 @@ module aptos_framework::delegation_pool { } #[event] + struct ReactivateStake has drop, store { + pool_address: address, + delegator_address: address, + amount_reactivated: u64, + } + struct ReactivateStakeEvent has drop, store { pool_address: address, delegator_address: address, @@ -362,6 +375,12 @@ module aptos_framework::delegation_pool { } #[event] + struct UnlockStake has drop, store { + pool_address: address, + delegator_address: address, + amount_unlocked: u64, + } + struct UnlockStakeEvent has drop, store { pool_address: address, delegator_address: address, @@ -369,6 +388,12 @@ module aptos_framework::delegation_pool { } #[event] + struct WithdrawStake has drop, store { + pool_address: address, + delegator_address: address, + amount_withdrawn: u64, + } + struct WithdrawStakeEvent has drop, store { pool_address: address, delegator_address: address, @@ -393,6 +418,14 @@ module aptos_framework::delegation_pool { } #[event] + struct Vote has drop, store { + voter: address, + proposal_id: u64, + delegation_pool: address, + num_votes: u64, + should_pass: bool, + } + struct VoteEvent has drop, store { voter: address, proposal_id: u64, @@ -402,6 +435,12 @@ module aptos_framework::delegation_pool { } #[event] + struct CreateProposal has drop, store { + proposal_id: u64, + voter: address, + delegation_pool: address, + } + struct CreateProposalEvent has drop, store { proposal_id: u64, voter: address, @@ -409,6 +448,12 @@ module aptos_framework::delegation_pool { } #[event] + struct DelegateVotingPower has drop, store { + pool_address: address, + delegator: address, + voter: address, + } + struct DelegateVotingPowerEvent has drop, store { pool_address: address, delegator: address, @@ -906,7 +951,7 @@ module aptos_framework::delegation_pool { if (features::module_event_migration_enabled()) { event::emit( - VoteEvent { + Vote { voter: voter_address, proposal_id, delegation_pool: pool_address, @@ -965,7 +1010,7 @@ module aptos_framework::delegation_pool { if (features::module_event_migration_enabled()) { event::emit( - CreateProposalEvent { + CreateProposal { proposal_id, voter: voter_addr, delegation_pool: pool_address, @@ -1373,7 +1418,7 @@ module aptos_framework::delegation_pool { }; if (features::module_event_migration_enabled()) { - event::emit(DelegateVotingPowerEvent { + event::emit(DelegateVotingPower { pool_address, delegator: delegator_address, voter: new_voter, @@ -1508,7 +1553,7 @@ module aptos_framework::delegation_pool { if (features::module_event_migration_enabled()) { event::emit( - AddStakeEvent { + AddStake { pool_address, delegator_address, amount_added: amount, @@ -1572,7 +1617,7 @@ module aptos_framework::delegation_pool { if (features::module_event_migration_enabled()) { event::emit( - UnlockStakeEvent { + UnlockStake { pool_address, delegator_address, amount_unlocked: amount, @@ -1622,7 +1667,7 @@ module aptos_framework::delegation_pool { if (features::module_event_migration_enabled()) { event::emit( - ReactivateStakeEvent { + ReactivateStake { pool_address, delegator_address, amount_reactivated: amount, @@ -1707,7 +1752,7 @@ module aptos_framework::delegation_pool { if (features::module_event_migration_enabled()) { event::emit( - WithdrawStakeEvent { + WithdrawStake { pool_address, delegator_address, amount_withdrawn: amount, diff --git a/aptos-move/framework/aptos-framework/sources/multisig_account.move b/aptos-move/framework/aptos-framework/sources/multisig_account.move index b8a6200400960d..af9ca489ce8ae3 100644 --- a/aptos-move/framework/aptos-framework/sources/multisig_account.move +++ b/aptos-move/framework/aptos-framework/sources/multisig_account.move @@ -1180,6 +1180,16 @@ module aptos_framework::multisig_account { let (num_approvals, _) = remove_executed_transaction(multisig_account_resource); if(features::multisig_v2_enhancement_feature_enabled() && implicit_approval) { + if (std::features::module_event_migration_enabled()) { + emit( + Vote { + multisig_account, + owner: executor, + sequence_number, + approved: true, + } + ); + }; num_approvals = num_approvals + 1; emit_event( &mut multisig_account_resource.vote_events, diff --git a/aptos-move/framework/aptos-framework/sources/reconfiguration.move b/aptos-move/framework/aptos-framework/sources/reconfiguration.move index 528da4a6d66594..04a48b6466e754 100644 --- a/aptos-move/framework/aptos-framework/sources/reconfiguration.move +++ b/aptos-move/framework/aptos-framework/sources/reconfiguration.move @@ -156,13 +156,6 @@ module aptos_framework::reconfiguration { }; config_ref.epoch = config_ref.epoch + 1; - event::emit_event( - &mut config_ref.events, - NewEpochEvent { - epoch: config_ref.epoch, - }, - ); - if (std::features::module_event_migration_enabled()) { event::emit( NewEpoch { @@ -170,6 +163,12 @@ module aptos_framework::reconfiguration { }, ); }; + event::emit_event( + &mut config_ref.events, + NewEpochEvent { + epoch: config_ref.epoch, + }, + ); reconfiguration_state::on_reconfig_finish(); } diff --git a/aptos-move/framework/aptos-token/doc/token.md b/aptos-move/framework/aptos-token/doc/token.md index f3bf10a96269a7..af496bd937b73a 100644 --- a/aptos-move/framework/aptos-token/doc/token.md +++ b/aptos-move/framework/aptos-token/doc/token.md @@ -19,12 +19,19 @@ Checkout our developer doc on our token standard https://aptos.dev/standards - [Struct `CollectionData`](#0x3_token_CollectionData) - [Struct `WithdrawCapability`](#0x3_token_WithdrawCapability) - [Struct `DepositEvent`](#0x3_token_DepositEvent) +- [Struct `Deposit`](#0x3_token_Deposit) - [Struct `WithdrawEvent`](#0x3_token_WithdrawEvent) +- [Struct `Withdraw`](#0x3_token_Withdraw) - [Struct `CreateTokenDataEvent`](#0x3_token_CreateTokenDataEvent) +- [Struct `CreateTokenData`](#0x3_token_CreateTokenData) - [Struct `MintTokenEvent`](#0x3_token_MintTokenEvent) +- [Struct `MintToken`](#0x3_token_MintToken) - [Struct `BurnTokenEvent`](#0x3_token_BurnTokenEvent) +- [Struct `BurnToken`](#0x3_token_BurnToken) - [Struct `MutateTokenPropertyMapEvent`](#0x3_token_MutateTokenPropertyMapEvent) +- [Struct `MutateTokenPropertyMap`](#0x3_token_MutateTokenPropertyMap) - [Struct `CreateCollectionEvent`](#0x3_token_CreateCollectionEvent) +- [Struct `CreateCollection`](#0x3_token_CreateCollection) - [Constants](#@Constants_0) - [Function `create_collection_script`](#0x3_token_create_collection_script) - [Function `create_token_script`](#0x3_token_create_token_script) @@ -178,6 +185,7 @@ Checkout our developer doc on our token standard https://aptos.dev/standards
use 0x1::account;
 use 0x1::error;
 use 0x1::event;
+use 0x1::features;
 use 0x1::option;
 use 0x1::signer;
 use 0x1::string;
@@ -740,6 +748,41 @@ Set of data sent to the event stream during a receive
 
 
 
+
+Fields + + +
+
+id: token::TokenId +
+
+ +
+
+amount: u64 +
+
+ +
+
+ + +
+ + + +## Struct `Deposit` + +Set of data sent to the event stream during a receive + + +
#[event]
+struct Deposit has drop, store
+
+ + +
Fields @@ -774,6 +817,41 @@ Set of data sent to the event stream during a withdrawal +
+Fields + + +
+
+id: token::TokenId +
+
+ +
+
+amount: u64 +
+
+ +
+
+ + +
+ + + +## Struct `Withdraw` + +Set of data sent to the event stream during a withdrawal + + +
#[event]
+struct Withdraw has drop, store
+
+ + +
Fields @@ -808,6 +886,100 @@ token creation event id of token created +
+Fields + + +
+
+id: token::TokenDataId +
+
+ +
+
+description: string::String +
+
+ +
+
+maximum: u64 +
+
+ +
+
+uri: string::String +
+
+ +
+
+royalty_payee_address: address +
+
+ +
+
+royalty_points_denominator: u64 +
+
+ +
+
+royalty_points_numerator: u64 +
+
+ +
+
+name: string::String +
+
+ +
+
+mutability_config: token::TokenMutabilityConfig +
+
+ +
+
+property_keys: vector<string::String> +
+
+ +
+
+property_values: vector<vector<u8>> +
+
+ +
+
+property_types: vector<string::String> +
+
+ +
+
+ + +
+ + + +## Struct `CreateTokenData` + + + +
#[event]
+struct CreateTokenData has drop, store
+
+ + +
Fields @@ -902,6 +1074,40 @@ mint token event. This event triggered when creator adds more supply to existing +
+Fields + + +
+
+id: token::TokenDataId +
+
+ +
+
+amount: u64 +
+
+ +
+
+ + +
+ + + +## Struct `MintToken` + + + +
#[event]
+struct MintToken has drop, store
+
+ + +
Fields @@ -935,6 +1141,40 @@ mint token event. This event triggered when creator adds more supply to existing +
+Fields + + +
+
+id: token::TokenId +
+
+ +
+
+amount: u64 +
+
+ +
+
+ + +
+ + + +## Struct `BurnToken` + + + +
#[event]
+struct BurnToken has drop, store
+
+ + +
Fields @@ -968,6 +1208,58 @@ mint token event. This event triggered when creator adds more supply to existing +
+Fields + + +
+
+old_id: token::TokenId +
+
+ +
+
+new_id: token::TokenId +
+
+ +
+
+keys: vector<string::String> +
+
+ +
+
+values: vector<vector<u8>> +
+
+ +
+
+types: vector<string::String> +
+
+ +
+
+ + +
+ + + +## Struct `MutateTokenPropertyMap` + + + +
#[event]
+struct MutateTokenPropertyMap has drop, store
+
+ + +
Fields @@ -1020,6 +1312,58 @@ create collection event with creator address and collection name +
+Fields + + +
+
+creator: address +
+
+ +
+
+collection_name: string::String +
+
+ +
+
+uri: string::String +
+
+ +
+
+description: string::String +
+
+ +
+
+maximum: u64 +
+
+ +
+
+ + +
+ + + +## Struct `CreateCollection` + + + +
#[event]
+struct CreateCollection has drop, store
+
+ + +
Fields @@ -1906,9 +2250,12 @@ The token is owned at address owner // Burn the tokens. let Token { id: _, amount: burned_amount, token_properties: _ } = withdraw_with_event_internal(owner, token_id, amount); let token_store = borrow_global_mut<TokenStore>(owner); + if (std::features::module_event_migration_enabled()) { + event::emit(BurnToken { id: token_id, amount: burned_amount }); + }; event::emit_event<BurnTokenEvent>( &mut token_store.burn_events, - BurnTokenEvent { id: token_id, amount: burned_amount }, + BurnTokenEvent { id: token_id, amount: burned_amount } ); if (token_data.maximum > 0) { @@ -1992,9 +2339,12 @@ Burn a token by the token owner // Burn the tokens. let Token { id: _, amount: burned_amount, token_properties: _ } = withdraw_token(owner, token_id, amount); let token_store = borrow_global_mut<TokenStore>(signer::address_of(owner)); + if (std::features::module_event_migration_enabled()) { + event::emit(BurnToken { id: token_id, amount: burned_amount }); + }; event::emit_event<BurnTokenEvent>( &mut token_store.burn_events, - BurnTokenEvent { id: token_id, amount: burned_amount }, + BurnTokenEvent { id: token_id, amount: burned_amount } ); // Decrease the supply correspondingly by the amount of tokens burned. @@ -2386,6 +2736,15 @@ Mutate the token_properties of one token. }; direct_deposit(token_owner, new_token); update_token_property_internal(token_owner, new_token_id, keys, values, types); + if (std::features::module_event_migration_enabled()) { + event::emit(MutateTokenPropertyMap { + old_id: token_id, + new_id: new_token_id, + keys, + values, + types + }); + }; event::emit_event<MutateTokenPropertyMapEvent>( &mut borrow_global_mut<TokenStore>(token_owner).mutate_token_property_events, MutateTokenPropertyMapEvent { @@ -2404,6 +2763,15 @@ Mutate the token_properties of one token. } else { // only 1 copy for the token with property verion bigger than 0 update_token_property_internal(token_owner, token_id, keys, values, types); + if (std::features::module_event_migration_enabled()) { + event::emit(MutateTokenPropertyMap { + old_id: token_id, + new_id: token_id, + keys, + values, + types + }); + }; event::emit_event<MutateTokenPropertyMapEvent>( &mut borrow_global_mut<TokenStore>(token_owner).mutate_token_property_events, MutateTokenPropertyMapEvent { @@ -2899,6 +3267,17 @@ Create a new collection to hold tokens table::add(collection_data, name, collection); let collection_handle = borrow_global_mut<Collections>(account_addr); + if (std::features::module_event_migration_enabled()) { + event::emit( + CreateCollection { + creator: account_addr, + collection_name: name, + uri, + description, + maximum, + } + ); + }; event::emit_event<CreateCollectionEvent>( &mut collection_handle.create_collection_events, CreateCollectionEvent { @@ -3055,6 +3434,24 @@ Create a new collection to hold tokens }; table::add(&mut collections.token_data, token_data_id, token_data); + if (std::features::module_event_migration_enabled()) { + event::emit( + CreateTokenData { + id: token_data_id, + description, + maximum, + uri, + royalty_payee_address, + royalty_points_denominator, + royalty_points_numerator, + name, + mutability_config: token_mutate_config, + property_keys, + property_values, + property_types, + } + ); + }; event::emit_event<CreateTokenDataEvent>( &mut collections.create_token_data_events, @@ -3397,6 +3794,9 @@ return the TokenId for a given Token // we add more tokens with property_version 0 let token_id = create_token_id(token_data_id, 0); + if (std::features::module_event_migration_enabled()) { + event::emit(MintToken { id: token_data_id, amount }) + }; event::emit_event<MintTokenEvent>( &mut borrow_global_mut<Collections>(creator_addr).mint_token_events, MintTokenEvent { @@ -3461,6 +3861,9 @@ create tokens and directly deposite to receiver's address. The receiver should o // we add more tokens with property_version 0 let token_id = create_token_id(token_data_id, 0); + if (std::features::module_event_migration_enabled()) { + event::emit(MintToken { id: token_data_id, amount }) + }; event::emit_event<MintTokenEvent>( &mut borrow_global_mut<Collections>(creator_addr).mint_token_events, MintTokenEvent { @@ -4346,9 +4749,12 @@ return if the collection maximum is mutable with collection mutability config ); let token_store = borrow_global_mut<TokenStore>(account_addr); + if (std::features::module_event_migration_enabled()) { + event::emit(Withdraw { id, amount }) + }; event::emit_event<WithdrawEvent>( &mut token_store.withdraw_events, - WithdrawEvent { id, amount }, + WithdrawEvent { id, amount } ); let tokens = &mut borrow_global_mut<TokenStore>(account_addr).tokens; assert!( @@ -4425,6 +4831,9 @@ Deposit the token balance into the recipients account and emit an event. assert!(token.amount > 0, error::invalid_argument(ETOKEN_CANNOT_HAVE_ZERO_AMOUNT)); let token_store = borrow_global_mut<TokenStore>(account_addr); + if (std::features::module_event_migration_enabled()) { + event::emit(Deposit { id: token.id, amount: token.amount }); + }; event::emit_event<DepositEvent>( &mut token_store.deposit_events, DepositEvent { id: token.id, amount: token.amount }, diff --git a/aptos-move/framework/aptos-token/doc/token_transfers.md b/aptos-move/framework/aptos-token/doc/token_transfers.md index a01d9c238dabaf..4a83d05aa54166 100644 --- a/aptos-move/framework/aptos-token/doc/token_transfers.md +++ b/aptos-move/framework/aptos-token/doc/token_transfers.md @@ -8,9 +8,12 @@ This module provides the foundation for transferring of Tokens - [Resource `PendingClaims`](#0x3_token_transfers_PendingClaims) - [Struct `TokenOfferId`](#0x3_token_transfers_TokenOfferId) +- [Struct `TokenOffer`](#0x3_token_transfers_TokenOffer) - [Struct `TokenOfferEvent`](#0x3_token_transfers_TokenOfferEvent) - [Struct `TokenCancelOfferEvent`](#0x3_token_transfers_TokenCancelOfferEvent) +- [Struct `TokenCancelOffer`](#0x3_token_transfers_TokenCancelOffer) - [Struct `TokenClaimEvent`](#0x3_token_transfers_TokenClaimEvent) +- [Struct `TokenClaim`](#0x3_token_transfers_TokenClaim) - [Constants](#@Constants_0) - [Function `initialize_token_transfers`](#0x3_token_transfers_initialize_token_transfers) - [Function `create_token_offer_id`](#0x3_token_transfers_create_token_offer_id) @@ -34,6 +37,7 @@ This module provides the foundation for transferring of Tokens
use 0x1::account;
 use 0x1::error;
 use 0x1::event;
+use 0x1::features;
 use 0x1::signer;
 use 0x1::string;
 use 0x1::table;
@@ -93,8 +97,7 @@ This module provides the foundation for transferring of Tokens
 
 
 
-
#[event]
-struct TokenOfferId has copy, drop, store
+
struct TokenOfferId has copy, drop, store
 
@@ -119,6 +122,46 @@ This module provides the foundation for transferring of Tokens +
+ + + +## Struct `TokenOffer` + + + +
#[event]
+struct TokenOffer has drop, store
+
+ + + +
+Fields + + +
+
+to_address: address +
+
+ +
+
+token_id: token::TokenId +
+
+ +
+
+amount: u64 +
+
+ +
+
+ +
@@ -127,8 +170,7 @@ This module provides the foundation for transferring of Tokens -
#[event]
-struct TokenOfferEvent has drop, store
+
struct TokenOfferEvent has drop, store
 
@@ -167,8 +209,47 @@ This module provides the foundation for transferring of Tokens +
struct TokenCancelOfferEvent has drop, store
+
+ + + +
+Fields + + +
+
+to_address: address +
+
+ +
+
+token_id: token::TokenId +
+
+ +
+
+amount: u64 +
+
+ +
+
+ + +
+ + + +## Struct `TokenCancelOffer` + + +
#[event]
-struct TokenCancelOfferEvent has drop, store
+struct TokenCancelOffer has drop, store
 
@@ -207,8 +288,47 @@ This module provides the foundation for transferring of Tokens +
struct TokenClaimEvent has drop, store
+
+ + + +
+Fields + + +
+
+to_address: address +
+
+ +
+
+token_id: token::TokenId +
+
+ +
+
+amount: u64 +
+
+ +
+
+ + +
+ + + +## Struct `TokenClaim` + + +
#[event]
-struct TokenClaimEvent has drop, store
+struct TokenClaim has drop, store
 
@@ -385,6 +505,15 @@ Token offer doesn't exist token::merge(dst_token, token); }; + if (std::features::module_event_migration_enabled()) { + event::emit( + TokenOffer { + to_address: receiver, + token_id, + amount, + } + ) + }; event::emit_event<TokenOfferEvent>( &mut borrow_global_mut<PendingClaims>(sender_addr).offer_events, TokenOfferEvent { @@ -461,6 +590,15 @@ Token offer doesn't exist let amount = token::get_token_amount(&tokens); token::deposit_token(receiver, tokens); + if (std::features::module_event_migration_enabled()) { + event::emit( + TokenClaim { + to_address: signer::address_of(receiver), + token_id, + amount, + } + ) + }; event::emit_event<TokenClaimEvent>( &mut borrow_global_mut<PendingClaims>(sender).claim_events, TokenClaimEvent { @@ -537,6 +675,15 @@ Token offer doesn't exist let amount = token::get_token_amount(&token); token::deposit_token(sender, token); + if (std::features::module_event_migration_enabled()) { + event::emit( + TokenCancelOffer { + to_address: receiver, + token_id, + amount, + }, + ) + }; event::emit_event<TokenCancelOfferEvent>( &mut borrow_global_mut<PendingClaims>(sender_addr).cancel_offer_events, TokenCancelOfferEvent { diff --git a/aptos-move/framework/aptos-token/sources/token.move b/aptos-move/framework/aptos-token/sources/token.move index 8841b3498e20af..d11f69a3793517 100644 --- a/aptos-move/framework/aptos-token/sources/token.move +++ b/aptos-move/framework/aptos-token/sources/token.move @@ -289,12 +289,26 @@ module aptos_token::token { amount: u64, } + #[event] + /// Set of data sent to the event stream during a receive + struct Deposit has drop, store { + id: TokenId, + amount: u64, + } + /// Set of data sent to the event stream during a withdrawal struct WithdrawEvent has drop, store { id: TokenId, amount: u64, } + #[event] + /// Set of data sent to the event stream during a withdrawal + struct Withdraw has drop, store { + id: TokenId, + amount: u64, + } + /// token creation event id of token created struct CreateTokenDataEvent has drop, store { id: TokenDataId, @@ -311,18 +325,46 @@ module aptos_token::token { property_types: vector, } + #[event] + struct CreateTokenData has drop, store { + id: TokenDataId, + description: String, + maximum: u64, + uri: String, + royalty_payee_address: address, + royalty_points_denominator: u64, + royalty_points_numerator: u64, + name: String, + mutability_config: TokenMutabilityConfig, + property_keys: vector, + property_values: vector>, + property_types: vector, + } + /// mint token event. This event triggered when creator adds more supply to existing token struct MintTokenEvent has drop, store { id: TokenDataId, amount: u64, } + #[event] + struct MintToken has drop, store { + id: TokenDataId, + amount: u64, + } + /// struct BurnTokenEvent has drop, store { id: TokenId, amount: u64, } + #[event] + struct BurnToken has drop, store { + id: TokenId, + amount: u64, + } + /// struct MutateTokenPropertyMapEvent has drop, store { old_id: TokenId, @@ -332,6 +374,15 @@ module aptos_token::token { types: vector, } + #[event] + struct MutateTokenPropertyMap has drop, store { + old_id: TokenId, + new_id: TokenId, + keys: vector, + values: vector>, + types: vector, + } + /// create collection event with creator address and collection name struct CreateCollectionEvent has drop, store { creator: address, @@ -341,6 +392,15 @@ module aptos_token::token { maximum: u64, } + #[event] + struct CreateCollection has drop, store { + creator: address, + collection_name: String, + uri: String, + description: String, + maximum: u64, + } + // // Creator Entry functions // @@ -539,9 +599,12 @@ module aptos_token::token { // Burn the tokens. let Token { id: _, amount: burned_amount, token_properties: _ } = withdraw_with_event_internal(owner, token_id, amount); let token_store = borrow_global_mut(owner); + if (std::features::module_event_migration_enabled()) { + event::emit(BurnToken { id: token_id, amount: burned_amount }); + }; event::emit_event( &mut token_store.burn_events, - BurnTokenEvent { id: token_id, amount: burned_amount }, + BurnTokenEvent { id: token_id, amount: burned_amount } ); if (token_data.maximum > 0) { @@ -605,9 +668,12 @@ module aptos_token::token { // Burn the tokens. let Token { id: _, amount: burned_amount, token_properties: _ } = withdraw_token(owner, token_id, amount); let token_store = borrow_global_mut(signer::address_of(owner)); + if (std::features::module_event_migration_enabled()) { + event::emit(BurnToken { id: token_id, amount: burned_amount }); + }; event::emit_event( &mut token_store.burn_events, - BurnTokenEvent { id: token_id, amount: burned_amount }, + BurnTokenEvent { id: token_id, amount: burned_amount } ); // Decrease the supply correspondingly by the amount of tokens burned. @@ -825,6 +891,15 @@ module aptos_token::token { }; direct_deposit(token_owner, new_token); update_token_property_internal(token_owner, new_token_id, keys, values, types); + if (std::features::module_event_migration_enabled()) { + event::emit(MutateTokenPropertyMap { + old_id: token_id, + new_id: new_token_id, + keys, + values, + types + }); + }; event::emit_event( &mut borrow_global_mut(token_owner).mutate_token_property_events, MutateTokenPropertyMapEvent { @@ -843,6 +918,15 @@ module aptos_token::token { } else { // only 1 copy for the token with property verion bigger than 0 update_token_property_internal(token_owner, token_id, keys, values, types); + if (std::features::module_event_migration_enabled()) { + event::emit(MutateTokenPropertyMap { + old_id: token_id, + new_id: token_id, + keys, + values, + types + }); + }; event::emit_event( &mut borrow_global_mut(token_owner).mutate_token_property_events, MutateTokenPropertyMapEvent { @@ -1059,6 +1143,17 @@ module aptos_token::token { table::add(collection_data, name, collection); let collection_handle = borrow_global_mut(account_addr); + if (std::features::module_event_migration_enabled()) { + event::emit( + CreateCollection { + creator: account_addr, + collection_name: name, + uri, + description, + maximum, + } + ); + }; event::emit_event( &mut collection_handle.create_collection_events, CreateCollectionEvent { @@ -1155,6 +1250,24 @@ module aptos_token::token { }; table::add(&mut collections.token_data, token_data_id, token_data); + if (std::features::module_event_migration_enabled()) { + event::emit( + CreateTokenData { + id: token_data_id, + description, + maximum, + uri, + royalty_payee_address, + royalty_points_denominator, + royalty_points_numerator, + name, + mutability_config: token_mutate_config, + property_keys, + property_values, + property_types, + } + ); + }; event::emit_event( &mut collections.create_token_data_events, @@ -1277,6 +1390,9 @@ module aptos_token::token { // we add more tokens with property_version 0 let token_id = create_token_id(token_data_id, 0); + if (std::features::module_event_migration_enabled()) { + event::emit(MintToken { id: token_data_id, amount }) + }; event::emit_event( &mut borrow_global_mut(creator_addr).mint_token_events, MintTokenEvent { @@ -1321,6 +1437,9 @@ module aptos_token::token { // we add more tokens with property_version 0 let token_id = create_token_id(token_data_id, 0); + if (std::features::module_event_migration_enabled()) { + event::emit(MintToken { id: token_data_id, amount }) + }; event::emit_event( &mut borrow_global_mut(creator_addr).mint_token_events, MintTokenEvent { @@ -1588,9 +1707,12 @@ module aptos_token::token { ); let token_store = borrow_global_mut(account_addr); + if (std::features::module_event_migration_enabled()) { + event::emit(Withdraw { id, amount }) + }; event::emit_event( &mut token_store.withdraw_events, - WithdrawEvent { id, amount }, + WithdrawEvent { id, amount } ); let tokens = &mut borrow_global_mut(account_addr).tokens; assert!( @@ -1627,6 +1749,9 @@ module aptos_token::token { assert!(token.amount > 0, error::invalid_argument(ETOKEN_CANNOT_HAVE_ZERO_AMOUNT)); let token_store = borrow_global_mut(account_addr); + if (std::features::module_event_migration_enabled()) { + event::emit(Deposit { id: token.id, amount: token.amount }); + }; event::emit_event( &mut token_store.deposit_events, DepositEvent { id: token.id, amount: token.amount }, diff --git a/aptos-move/framework/aptos-token/sources/token_transfers.move b/aptos-move/framework/aptos-token/sources/token_transfers.move index 5b58becb605c96..b255de3a204a4b 100644 --- a/aptos-move/framework/aptos-token/sources/token_transfers.move +++ b/aptos-move/framework/aptos-token/sources/token_transfers.move @@ -22,20 +22,24 @@ module aptos_token::token_transfers { claim_events: EventHandle, } - #[event] struct TokenOfferId has copy, drop, store { to_addr: address, token_id: TokenId, } #[event] + struct TokenOffer has drop, store { + to_address: address, + token_id: TokenId, + amount: u64, + } + struct TokenOfferEvent has drop, store { to_address: address, token_id: TokenId, amount: u64, } - #[event] struct TokenCancelOfferEvent has drop, store { to_address: address, token_id: TokenId, @@ -43,12 +47,25 @@ module aptos_token::token_transfers { } #[event] + struct TokenCancelOffer has drop, store { + to_address: address, + token_id: TokenId, + amount: u64, + } + struct TokenClaimEvent has drop, store { to_address: address, token_id: TokenId, amount: u64, } + #[event] + struct TokenClaim has drop, store { + to_address: address, + token_id: TokenId, + amount: u64, + } + fun initialize_token_transfers(account: &signer) { move_to( account, @@ -103,6 +120,15 @@ module aptos_token::token_transfers { token::merge(dst_token, token); }; + if (std::features::module_event_migration_enabled()) { + event::emit( + TokenOffer { + to_address: receiver, + token_id, + amount, + } + ) + }; event::emit_event( &mut borrow_global_mut(sender_addr).offer_events, TokenOfferEvent { @@ -139,6 +165,15 @@ module aptos_token::token_transfers { let amount = token::get_token_amount(&tokens); token::deposit_token(receiver, tokens); + if (std::features::module_event_migration_enabled()) { + event::emit( + TokenClaim { + to_address: signer::address_of(receiver), + token_id, + amount, + } + ) + }; event::emit_event( &mut borrow_global_mut(sender).claim_events, TokenClaimEvent { @@ -176,6 +211,15 @@ module aptos_token::token_transfers { let amount = token::get_token_amount(&token); token::deposit_token(sender, token); + if (std::features::module_event_migration_enabled()) { + event::emit( + TokenCancelOffer { + to_address: receiver, + token_id, + amount, + }, + ) + }; event::emit_event( &mut borrow_global_mut(sender_addr).cancel_offer_events, TokenCancelOfferEvent {