From f345c4fa9fac4e5f227064ec73dd69d1cf084421 Mon Sep 17 00:00:00 2001 From: primata Date: Mon, 3 Feb 2025 11:58:11 +0800 Subject: [PATCH 1/2] feat: add mint_to --- .../aptos-framework/doc/native_bridge.md | 37 ++++++++++++-- .../sources/native_bridge.move | 22 +++++++- .../src/aptos_framework_sdk_builder.rs | 51 ------------------- 3 files changed, 54 insertions(+), 56 deletions(-) diff --git a/aptos-move/framework/aptos-framework/doc/native_bridge.md b/aptos-move/framework/aptos-framework/doc/native_bridge.md index 2c10e6019cc1e..aaa3b417e86a7 100644 --- a/aptos-move/framework/aptos-framework/doc/native_bridge.md +++ b/aptos-move/framework/aptos-framework/doc/native_bridge.md @@ -33,6 +33,7 @@ - [Function `store_aptos_coin_burn_cap`](#0x1_native_bridge_store_aptos_coin_burn_cap) - [Function `store_aptos_coin_mint_cap`](#0x1_native_bridge_store_aptos_coin_mint_cap) - [Function `mint`](#0x1_native_bridge_mint) +- [Function `mint_from`](#0x1_native_bridge_mint_from) - [Function `burn_from`](#0x1_native_bridge_burn_from) - [Function `burn`](#0x1_native_bridge_burn) - [Function `burn_internal`](#0x1_native_bridge_burn_internal) @@ -1124,6 +1125,36 @@ Mints a specified amount of AptosCoin to a recipient's address. + + + + +## Function `mint_from` + +Mints a specified amount of AptosCoin to a recipient's address. + +@param core_resource The signer representing the core resource account. +@param recipient The address of the recipient to mint coins to. +@param amount The amount of AptosCoin to mint. + + +
public fun mint_from(aptos_framework: &signer, recipient: address, amount: u64)
+
+ + + +
+Implementation + + +
public fun mint_from(aptos_framework: &signer, recipient: address, amount: u64) acquires AptosCoinMintCapability {
+    system_addresses::assert_aptos_framework(aptos_framework);
+    mint(recipient, amount);
+}
+
+ + +
@@ -1138,7 +1169,7 @@ Burns a specified amount of AptosCoin from an address. @abort If the burn capability is not available. -
public entry fun burn_from(core_resource: &signer, from: address, amount: u64)
+
public fun burn_from(aptos_framework: &signer, from: address, amount: u64)
 
@@ -1147,8 +1178,8 @@ Burns a specified amount of AptosCoin from an address. Implementation -
public entry fun burn_from(core_resource: &signer, from: address, amount: u64) acquires AptosCoinBurnCapability {
-    system_addresses::assert_core_resource(core_resource);
+
public fun burn_from(aptos_framework: &signer, from: address, amount: u64) acquires AptosCoinBurnCapability {
+    system_addresses::assert_aptos_framework(aptos_framework);
     burn_internal(from, amount);
 }
 
diff --git a/aptos-move/framework/aptos-framework/sources/native_bridge.move b/aptos-move/framework/aptos-framework/sources/native_bridge.move index 3da93d510b500..031fc486a46a6 100644 --- a/aptos-move/framework/aptos-framework/sources/native_bridge.move +++ b/aptos-move/framework/aptos-framework/sources/native_bridge.move @@ -335,6 +335,16 @@ module aptos_framework::native_bridge { move_to(aptos_framework, AptosCoinMintCapability { mint_cap }) } + /// Mints a specified amount of AptosCoin to a recipient's address. + /// + /// @param core_resource The signer representing the core resource account. + /// @param recipient The address of the recipient to mint coins to. + /// @param amount The amount of AptosCoin to mint. + public fun mint_to(aptos_framework: &signer, recipient: address, amount: u64) acquires AptosCoinMintCapability { + system_addresses::assert_aptos_framework(aptos_framework); + mint_internal(recipient, amount); + } + /// Mints a specified amount of AptosCoin to a recipient's address. /// /// @param recipient The address of the recipient to mint coins to. @@ -343,11 +353,19 @@ module aptos_framework::native_bridge { public(friend) fun mint(recipient: address, amount: u64) acquires AptosCoinMintCapability { assert!(features::abort_native_bridge_enabled(), ENATIVE_BRIDGE_NOT_ENABLED); + mint_internal(recipient, amount); + } + + /// Mints a specified amount of AptosCoin to a recipient's address. + /// + /// @param recipient The address of the recipient to mint coins to. + /// @param amount The amount of AptosCoin to mint. + fun mint_internal(recipient: address, amount: u64) acquires AptosCoinMintCapability { coin::deposit(recipient, coin::mint( amount, &borrow_global(@aptos_framework).mint_cap )); - } + } /// Burns a specified amount of AptosCoin from an address. /// @@ -355,7 +373,7 @@ module aptos_framework::native_bridge { /// @param from The address from which to burn AptosCoin. /// @param amount The amount of AptosCoin to burn. /// @abort If the burn capability is not available. - public entry fun burn_from(aptos_framework: &signer, from: address, amount: u64) acquires AptosCoinBurnCapability { + public fun burn_from(aptos_framework: &signer, from: address, amount: u64) acquires AptosCoinBurnCapability { system_addresses::assert_aptos_framework(aptos_framework); burn_internal(from, amount); } diff --git a/aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs b/aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs index 2dcc9a5e369b7..6db6ebe02e1fd 100644 --- a/aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs +++ b/aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs @@ -667,17 +667,6 @@ pub enum EntryFunctionCall { approved: bool, }, - /// Burns a specified amount of AptosCoin from an address. - /// - /// @param core_resource The signer representing the core resource account. - /// @param from The address from which to burn AptosCoin. - /// @param amount The amount of AptosCoin to burn. - /// @abort If the burn capability is not available. - NativeBridgeBurnFrom { - from: AccountAddress, - amount: u64, - }, - /// Completes a bridge transfer on the destination chain. /// @param caller The signer representing the bridge relayer. @@ -1461,7 +1450,6 @@ impl EntryFunctionCall { sequence_number, approved, } => multisig_account_vote_transanction(multisig_account, sequence_number, approved), - NativeBridgeBurnFrom { from, amount } => native_bridge_burn_from(from, amount), NativeBridgeCompleteBridgeTransfer { bridge_transfer_id, initiator, @@ -3510,30 +3498,6 @@ pub fn multisig_account_vote_transanction( )) } -/// Burns a specified amount of AptosCoin from an address. -/// -/// @param core_resource The signer representing the core resource account. -/// @param from The address from which to burn AptosCoin. -/// @param amount The amount of AptosCoin to burn. -/// @abort If the burn capability is not available. -pub fn native_bridge_burn_from(from: AccountAddress, amount: u64) -> TransactionPayload { - TransactionPayload::EntryFunction(EntryFunction::new( - ModuleId::new( - AccountAddress::new([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, - ]), - ident_str!("native_bridge").to_owned(), - ), - ident_str!("burn_from").to_owned(), - vec![], - vec![ - bcs::to_bytes(&from).unwrap(), - bcs::to_bytes(&amount).unwrap(), - ], - )) -} - /// Completes a bridge transfer on the destination chain. /// /// @param caller The signer representing the bridge relayer. @@ -5801,17 +5765,6 @@ mod decoder { } } - pub fn native_bridge_burn_from(payload: &TransactionPayload) -> Option { - if let TransactionPayload::EntryFunction(script) = payload { - Some(EntryFunctionCall::NativeBridgeBurnFrom { - from: bcs::from_bytes(script.args().get(0)?).ok()?, - amount: bcs::from_bytes(script.args().get(1)?).ok()?, - }) - } else { - None - } - } - pub fn native_bridge_complete_bridge_transfer( payload: &TransactionPayload, ) -> Option { @@ -6872,10 +6825,6 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy Date: Mon, 3 Feb 2025 13:31:10 +0800 Subject: [PATCH 2/2] use mint internal through out code --- .../framework/aptos-framework/sources/native_bridge.move | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aptos-move/framework/aptos-framework/sources/native_bridge.move b/aptos-move/framework/aptos-framework/sources/native_bridge.move index 031fc486a46a6..f176c8c8b2746 100644 --- a/aptos-move/framework/aptos-framework/sources/native_bridge.move +++ b/aptos-move/framework/aptos-framework/sources/native_bridge.move @@ -499,7 +499,7 @@ module aptos_framework::native_bridge { set_bridge_transfer_id_to_inbound_nonce(bridge_transfer_id, nonce); // Mint to the recipient - mint(recipient, amount); + mint_internal(recipient, amount); // Emit the event let bridge_events = borrow_global_mut(@aptos_framework); @@ -525,7 +525,7 @@ module aptos_framework::native_bridge { let bridge_relayer = bridge_relayer(); assert!(amount > bridge_fee, EINVALID_AMOUNT); let new_amount = amount - bridge_fee; - mint(bridge_relayer, bridge_fee); + mint_internal(bridge_relayer, bridge_fee); new_amount } @@ -688,7 +688,7 @@ module aptos_framework::native_bridge { // Mint coins to the sender to ensure they have sufficient balance let account_balance = amount + 1; // Mint some coins - mint(sender_address, account_balance); + mint_internal(sender_address, account_balance); // Specify the recipient and transfer amount let recipient = ethereum::eth_address_20_bytes();