Skip to content

Commit 991668f

Browse files
authored
Merge pull request #134 from movementlabsxyz/add-burn-from
Add Mint To
2 parents fb1d8c5 + 8612e6a commit 991668f

File tree

3 files changed

+96
-106
lines changed

3 files changed

+96
-106
lines changed

aptos-move/framework/aptos-framework/doc/native_bridge.md

Lines changed: 73 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,47 @@
55

66

77

8-
- [Module `0x1::native_bridge`](#module-0x1native_bridge)
9-
- [Struct `BridgeConfigRelayerUpdated`](#struct-bridgeconfigrelayerupdated)
10-
- [Struct `BridgeFeeChangedEvent`](#struct-bridgefeechangedevent)
11-
- [Struct `BridgeRiskDenominatorChangedEvent`](#struct-bridgeriskdenominatorchangedevent)
12-
- [Struct `BridgeInsuranceFundChangedEvent`](#struct-bridgeinsurancefundchangedevent)
13-
- [Struct `BridgeTransferInitiatedEvent`](#struct-bridgetransferinitiatedevent)
14-
- [Struct `BridgeTransferCompletedEvent`](#struct-bridgetransfercompletedevent)
15-
- [Resource `BridgeEvents`](#resource-bridgeevents)
16-
- [Resource `AptosCoinBurnCapability`](#resource-aptoscoinburncapability)
17-
- [Resource `AptosCoinMintCapability`](#resource-aptoscoinmintcapability)
18-
- [Resource `AptosFABurnCapabilities`](#resource-aptosfaburncapabilities)
19-
- [Resource `AptosFAMintCapabilities`](#resource-aptosfamintcapabilities)
20-
- [Resource `Nonce`](#resource-nonce)
21-
- [Resource `SmartTableWrapper`](#resource-smarttablewrapper)
22-
- [Struct `OutboundTransfer`](#struct-outboundtransfer)
23-
- [Resource `BridgeConfig`](#resource-bridgeconfig)
24-
- [Constants](#constants)
25-
- [Function `initialize`](#function-initialize)
26-
- [Function `normalize_u64_to_32_bytes`](#function-normalize_u64_to_32_bytes)
27-
- [Function `is_inbound_nonce_set`](#function-is_inbound_nonce_set)
28-
- [Function `create_details`](#function-create_details)
29-
- [Function `add`](#function-add)
30-
- [Function `set_bridge_transfer_id_to_inbound_nonce`](#function-set_bridge_transfer_id_to_inbound_nonce)
31-
- [Function `assert_valid_bridge_transfer_id`](#function-assert_valid_bridge_transfer_id)
32-
- [Function `bridge_transfer_id`](#function-bridge_transfer_id)
33-
- [Function `bridge_relayer`](#function-bridge_relayer)
34-
- [Function `insurance_fund`](#function-insurance_fund)
35-
- [Function `risk_denominator`](#function-risk_denominator)
36-
- [Function `bridge_fee`](#function-bridge_fee)
37-
- [Function `get_bridge_transfer_details_from_nonce`](#function-get_bridge_transfer_details_from_nonce)
38-
- [Function `get_inbound_nonce_from_bridge_transfer_id`](#function-get_inbound_nonce_from_bridge_transfer_id)
39-
- [Function `increment_and_get_nonce`](#function-increment_and_get_nonce)
40-
- [Function `store_aptos_coin_burn_cap`](#function-store_aptos_coin_burn_cap)
41-
- [Function `store_aptos_coin_mint_cap`](#function-store_aptos_coin_mint_cap)
42-
- [Function `mint`](#function-mint)
43-
- [Function `burn_from`](#function-burn_from)
44-
- [Function `burn`](#function-burn)
45-
- [Function `burn_internal`](#function-burn_internal)
46-
- [Function `initiate_bridge_transfer`](#function-initiate_bridge_transfer)
47-
- [Function `complete_bridge_transfer`](#function-complete_bridge_transfer)
48-
- [Function `charge_bridge_fee`](#function-charge_bridge_fee)
49-
- [Function `update_bridge_relayer`](#function-update_bridge_relayer)
50-
- [Function `update_bridge_fee`](#function-update_bridge_fee)
51-
- [Function `update_insurance_fund`](#function-update_insurance_fund)
52-
- [Function `update_risk_denominator`](#function-update_risk_denominator)
53-
- [Function `assert_is_caller_relayer`](#function-assert_is_caller_relayer)
54-
- [Function `assert_rate_limit_budget_not_exceeded`](#function-assert_rate_limit_budget_not_exceeded)
55-
- [Function `test_normalize_u64_to_32_bytes_helper`](#function-test_normalize_u64_to_32_bytes_helper)
8+
- [Resource `AptosCoinBurnCapability`](#0x1_native_bridge_AptosCoinBurnCapability)
9+
- [Resource `AptosCoinMintCapability`](#0x1_native_bridge_AptosCoinMintCapability)
10+
- [Resource `AptosFABurnCapabilities`](#0x1_native_bridge_AptosFABurnCapabilities)
11+
- [Resource `AptosFAMintCapabilities`](#0x1_native_bridge_AptosFAMintCapabilities)
12+
- [Struct `BridgeTransferInitiatedEvent`](#0x1_native_bridge_BridgeTransferInitiatedEvent)
13+
- [Struct `BridgeTransferCompletedEvent`](#0x1_native_bridge_BridgeTransferCompletedEvent)
14+
- [Resource `BridgeEvents`](#0x1_native_bridge_BridgeEvents)
15+
- [Resource `Nonce`](#0x1_native_bridge_Nonce)
16+
- [Resource `SmartTableWrapper`](#0x1_native_bridge_SmartTableWrapper)
17+
- [Struct `OutboundTransfer`](#0x1_native_bridge_OutboundTransfer)
18+
- [Resource `BridgeConfig`](#0x1_native_bridge_BridgeConfig)
19+
- [Struct `BridgeConfigRelayerUpdated`](#0x1_native_bridge_BridgeConfigRelayerUpdated)
20+
- [Struct `BridgeFeeChangedEvent`](#0x1_native_bridge_BridgeFeeChangedEvent)
21+
- [Constants](#@Constants_0)
22+
- [Function `normalize_u64_to_32_bytes`](#0x1_native_bridge_normalize_u64_to_32_bytes)
23+
- [Function `is_inbound_nonce_set`](#0x1_native_bridge_is_inbound_nonce_set)
24+
- [Function `create_details`](#0x1_native_bridge_create_details)
25+
- [Function `add`](#0x1_native_bridge_add)
26+
- [Function `set_bridge_transfer_id_to_inbound_nonce`](#0x1_native_bridge_set_bridge_transfer_id_to_inbound_nonce)
27+
- [Function `assert_valid_bridge_transfer_id`](#0x1_native_bridge_assert_valid_bridge_transfer_id)
28+
- [Function `bridge_transfer_id`](#0x1_native_bridge_bridge_transfer_id)
29+
- [Function `get_bridge_transfer_details_from_nonce`](#0x1_native_bridge_get_bridge_transfer_details_from_nonce)
30+
- [Function `get_inbound_nonce_from_bridge_transfer_id`](#0x1_native_bridge_get_inbound_nonce_from_bridge_transfer_id)
31+
- [Function `increment_and_get_nonce`](#0x1_native_bridge_increment_and_get_nonce)
32+
- [Function `initialize`](#0x1_native_bridge_initialize)
33+
- [Function `store_aptos_coin_burn_cap`](#0x1_native_bridge_store_aptos_coin_burn_cap)
34+
- [Function `store_aptos_coin_mint_cap`](#0x1_native_bridge_store_aptos_coin_mint_cap)
35+
- [Function `mint`](#0x1_native_bridge_mint)
36+
- [Function `mint_from`](#0x1_native_bridge_mint_from)
37+
- [Function `burn_from`](#0x1_native_bridge_burn_from)
38+
- [Function `burn`](#0x1_native_bridge_burn)
39+
- [Function `burn_internal`](#0x1_native_bridge_burn_internal)
40+
- [Function `initiate_bridge_transfer`](#0x1_native_bridge_initiate_bridge_transfer)
41+
- [Function `complete_bridge_transfer`](#0x1_native_bridge_complete_bridge_transfer)
42+
- [Function `charge_bridge_fee`](#0x1_native_bridge_charge_bridge_fee)
43+
- [Function `update_bridge_relayer`](#0x1_native_bridge_update_bridge_relayer)
44+
- [Function `update_bridge_fee`](#0x1_native_bridge_update_bridge_fee)
45+
- [Function `bridge_relayer`](#0x1_native_bridge_bridge_relayer)
46+
- [Function `bridge_fee`](#0x1_native_bridge_bridge_fee)
47+
- [Function `assert_is_caller_relayer`](#0x1_native_bridge_assert_is_caller_relayer)
48+
- [Function `test_normalize_u64_to_32_bytes_helper`](#0x1_native_bridge_test_normalize_u64_to_32_bytes_helper)
5649

5750

5851
<pre><code><b>use</b> <a href="account.md#0x1_account">0x1::account</a>;
@@ -1427,6 +1420,36 @@ Mints a specified amount of AptosCoin to a recipient's address.
14271420

14281421

14291422

1423+
</details>
1424+
1425+
<a id="0x1_native_bridge_mint_from"></a>
1426+
1427+
## Function `mint_from`
1428+
1429+
Mints a specified amount of AptosCoin to a recipient's address.
1430+
1431+
@param core_resource The signer representing the core resource account.
1432+
@param recipient The address of the recipient to mint coins to.
1433+
@param amount The amount of AptosCoin to mint.
1434+
1435+
1436+
<pre><code><b>public</b> <b>fun</b> <a href="native_bridge.md#0x1_native_bridge_mint_from">mint_from</a>(aptos_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, recipient: <b>address</b>, amount: u64)
1437+
</code></pre>
1438+
1439+
1440+
1441+
<details>
1442+
<summary>Implementation</summary>
1443+
1444+
1445+
<pre><code><b>public</b> <b>fun</b> <a href="native_bridge.md#0x1_native_bridge_mint_from">mint_from</a>(aptos_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, recipient: <b>address</b>, amount: u64) <b>acquires</b> <a href="native_bridge.md#0x1_native_bridge_AptosCoinMintCapability">AptosCoinMintCapability</a> {
1446+
<a href="system_addresses.md#0x1_system_addresses_assert_aptos_framework">system_addresses::assert_aptos_framework</a>(aptos_framework);
1447+
<a href="native_bridge.md#0x1_native_bridge_mint">mint</a>(recipient, amount);
1448+
}
1449+
</code></pre>
1450+
1451+
1452+
14301453
</details>
14311454

14321455
<a id="0x1_native_bridge_burn_from"></a>
@@ -1441,7 +1464,7 @@ Burns a specified amount of AptosCoin from an address.
14411464
@abort If the burn capability is not available.
14421465

14431466

1444-
<pre><code><b>public</b> entry <b>fun</b> <a href="native_bridge.md#0x1_native_bridge_burn_from">burn_from</a>(aptos_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, from: <b>address</b>, amount: u64)
1467+
<pre><code><b>public</b> <b>fun</b> <a href="native_bridge.md#0x1_native_bridge_burn_from">burn_from</a>(aptos_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, from: <b>address</b>, amount: u64)
14451468
</code></pre>
14461469

14471470

@@ -1450,7 +1473,7 @@ Burns a specified amount of AptosCoin from an address.
14501473
<summary>Implementation</summary>
14511474

14521475

1453-
<pre><code><b>public</b> entry <b>fun</b> <a href="native_bridge.md#0x1_native_bridge_burn_from">burn_from</a>(aptos_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, from: <b>address</b>, amount: u64) <b>acquires</b> <a href="native_bridge.md#0x1_native_bridge_AptosCoinBurnCapability">AptosCoinBurnCapability</a> {
1476+
<pre><code><b>public</b> <b>fun</b> <a href="native_bridge.md#0x1_native_bridge_burn_from">burn_from</a>(aptos_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, from: <b>address</b>, amount: u64) <b>acquires</b> <a href="native_bridge.md#0x1_native_bridge_AptosCoinBurnCapability">AptosCoinBurnCapability</a> {
14541477
<a href="system_addresses.md#0x1_system_addresses_assert_aptos_framework">system_addresses::assert_aptos_framework</a>(aptos_framework);
14551478
<a href="native_bridge.md#0x1_native_bridge_burn_internal">burn_internal</a>(from, amount);
14561479
}

aptos-move/framework/aptos-framework/sources/native_bridge.move

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,16 @@ module aptos_framework::native_bridge {
410410
move_to(aptos_framework, AptosCoinMintCapability { mint_cap })
411411
}
412412

413+
/// Mints a specified amount of AptosCoin to a recipient's address.
414+
///
415+
/// @param core_resource The signer representing the core resource account.
416+
/// @param recipient The address of the recipient to mint coins to.
417+
/// @param amount The amount of AptosCoin to mint.
418+
public fun mint_to(aptos_framework: &signer, recipient: address, amount: u64) acquires AptosCoinMintCapability {
419+
system_addresses::assert_aptos_framework(aptos_framework);
420+
mint_internal(recipient, amount);
421+
}
422+
413423
/// Mints a specified amount of AptosCoin to a recipient's address.
414424
///
415425
/// @param recipient The address of the recipient to mint coins to.
@@ -418,19 +428,27 @@ module aptos_framework::native_bridge {
418428
public(friend) fun mint(recipient: address, amount: u64) acquires AptosCoinMintCapability {
419429
assert!(features::abort_native_bridge_enabled(), ENATIVE_BRIDGE_NOT_ENABLED);
420430

431+
mint_internal(recipient, amount);
432+
}
433+
434+
/// Mints a specified amount of AptosCoin to a recipient's address.
435+
///
436+
/// @param recipient The address of the recipient to mint coins to.
437+
/// @param amount The amount of AptosCoin to mint.
438+
fun mint_internal(recipient: address, amount: u64) acquires AptosCoinMintCapability {
421439
coin::deposit(recipient, coin::mint(
422440
amount,
423441
&borrow_global<AptosCoinMintCapability>(@aptos_framework).mint_cap
424442
));
425-
}
443+
}
426444

427445
/// Burns a specified amount of AptosCoin from an address.
428446
///
429447
/// @param core_resource The signer representing the core resource account.
430448
/// @param from The address from which to burn AptosCoin.
431449
/// @param amount The amount of AptosCoin to burn.
432450
/// @abort If the burn capability is not available.
433-
public entry fun burn_from(aptos_framework: &signer, from: address, amount: u64) acquires AptosCoinBurnCapability {
451+
public fun burn_from(aptos_framework: &signer, from: address, amount: u64) acquires AptosCoinBurnCapability {
434452
system_addresses::assert_aptos_framework(aptos_framework);
435453
burn_internal(from, amount);
436454
}
@@ -559,7 +577,7 @@ module aptos_framework::native_bridge {
559577
set_bridge_transfer_id_to_inbound_nonce(bridge_transfer_id, nonce);
560578

561579
// Mint to the recipient
562-
mint(recipient, amount);
580+
mint_internal(recipient, amount);
563581

564582
// Emit the event
565583
let bridge_events = borrow_global_mut<BridgeEvents>(@aptos_framework);
@@ -585,7 +603,7 @@ module aptos_framework::native_bridge {
585603
let bridge_relayer = bridge_relayer();
586604
assert!(amount > bridge_fee, EINVALID_AMOUNT);
587605
let new_amount = amount - bridge_fee;
588-
mint(bridge_relayer, bridge_fee);
606+
mint_internal(bridge_relayer, bridge_fee);
589607
new_amount
590608
}
591609

@@ -857,7 +875,7 @@ module aptos_framework::native_bridge {
857875
// Mint coins to the sender to ensure they have sufficient balance
858876
let account_balance = amount + 1;
859877
// Mint some coins
860-
mint(sender_address, account_balance);
878+
mint_internal(sender_address, account_balance);
861879

862880
// Specify the recipient and transfer amount
863881
let recipient = ethereum::eth_address_20_bytes();

aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -667,17 +667,6 @@ pub enum EntryFunctionCall {
667667
approved: bool,
668668
},
669669

670-
/// Burns a specified amount of AptosCoin from an address.
671-
///
672-
/// @param core_resource The signer representing the core resource account.
673-
/// @param from The address from which to burn AptosCoin.
674-
/// @param amount The amount of AptosCoin to burn.
675-
/// @abort If the burn capability is not available.
676-
NativeBridgeBurnFrom {
677-
from: AccountAddress,
678-
amount: u64,
679-
},
680-
681670
/// Completes a bridge transfer on the destination chain.
682671
683672
/// @param caller The signer representing the bridge relayer.
@@ -1461,7 +1450,6 @@ impl EntryFunctionCall {
14611450
sequence_number,
14621451
approved,
14631452
} => multisig_account_vote_transanction(multisig_account, sequence_number, approved),
1464-
NativeBridgeBurnFrom { from, amount } => native_bridge_burn_from(from, amount),
14651453
NativeBridgeCompleteBridgeTransfer {
14661454
bridge_transfer_id,
14671455
initiator,
@@ -3510,30 +3498,6 @@ pub fn multisig_account_vote_transanction(
35103498
))
35113499
}
35123500

3513-
/// Burns a specified amount of AptosCoin from an address.
3514-
///
3515-
/// @param core_resource The signer representing the core resource account.
3516-
/// @param from The address from which to burn AptosCoin.
3517-
/// @param amount The amount of AptosCoin to burn.
3518-
/// @abort If the burn capability is not available.
3519-
pub fn native_bridge_burn_from(from: AccountAddress, amount: u64) -> TransactionPayload {
3520-
TransactionPayload::EntryFunction(EntryFunction::new(
3521-
ModuleId::new(
3522-
AccountAddress::new([
3523-
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,
3524-
0, 0, 0, 1,
3525-
]),
3526-
ident_str!("native_bridge").to_owned(),
3527-
),
3528-
ident_str!("burn_from").to_owned(),
3529-
vec![],
3530-
vec![
3531-
bcs::to_bytes(&from).unwrap(),
3532-
bcs::to_bytes(&amount).unwrap(),
3533-
],
3534-
))
3535-
}
3536-
35373501
/// Completes a bridge transfer on the destination chain.
35383502
///
35393503
/// @param caller The signer representing the bridge relayer.
@@ -5801,17 +5765,6 @@ mod decoder {
58015765
}
58025766
}
58035767

5804-
pub fn native_bridge_burn_from(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
5805-
if let TransactionPayload::EntryFunction(script) = payload {
5806-
Some(EntryFunctionCall::NativeBridgeBurnFrom {
5807-
from: bcs::from_bytes(script.args().get(0)?).ok()?,
5808-
amount: bcs::from_bytes(script.args().get(1)?).ok()?,
5809-
})
5810-
} else {
5811-
None
5812-
}
5813-
}
5814-
58155768
pub fn native_bridge_complete_bridge_transfer(
58165769
payload: &TransactionPayload,
58175770
) -> Option<EntryFunctionCall> {
@@ -6872,10 +6825,6 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
68726825
"multisig_account_vote_transanction".to_string(),
68736826
Box::new(decoder::multisig_account_vote_transanction),
68746827
);
6875-
map.insert(
6876-
"native_bridge_burn_from".to_string(),
6877-
Box::new(decoder::native_bridge_burn_from),
6878-
);
68796828
map.insert(
68806829
"native_bridge_complete_bridge_transfer".to_string(),
68816830
Box::new(decoder::native_bridge_complete_bridge_transfer),

0 commit comments

Comments
 (0)