Skip to content

Commit

Permalink
Merge pull request #134 from movementlabsxyz/add-burn-from
Browse files Browse the repository at this point in the history
Add Mint To
  • Loading branch information
l-monninger authored Feb 4, 2025
2 parents fb1d8c5 + 8612e6a commit 991668f
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 106 deletions.
123 changes: 73 additions & 50 deletions aptos-move/framework/aptos-framework/doc/native_bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,47 @@



- [Module `0x1::native_bridge`](#module-0x1native_bridge)
- [Struct `BridgeConfigRelayerUpdated`](#struct-bridgeconfigrelayerupdated)
- [Struct `BridgeFeeChangedEvent`](#struct-bridgefeechangedevent)
- [Struct `BridgeRiskDenominatorChangedEvent`](#struct-bridgeriskdenominatorchangedevent)
- [Struct `BridgeInsuranceFundChangedEvent`](#struct-bridgeinsurancefundchangedevent)
- [Struct `BridgeTransferInitiatedEvent`](#struct-bridgetransferinitiatedevent)
- [Struct `BridgeTransferCompletedEvent`](#struct-bridgetransfercompletedevent)
- [Resource `BridgeEvents`](#resource-bridgeevents)
- [Resource `AptosCoinBurnCapability`](#resource-aptoscoinburncapability)
- [Resource `AptosCoinMintCapability`](#resource-aptoscoinmintcapability)
- [Resource `AptosFABurnCapabilities`](#resource-aptosfaburncapabilities)
- [Resource `AptosFAMintCapabilities`](#resource-aptosfamintcapabilities)
- [Resource `Nonce`](#resource-nonce)
- [Resource `SmartTableWrapper`](#resource-smarttablewrapper)
- [Struct `OutboundTransfer`](#struct-outboundtransfer)
- [Resource `BridgeConfig`](#resource-bridgeconfig)
- [Constants](#constants)
- [Function `initialize`](#function-initialize)
- [Function `normalize_u64_to_32_bytes`](#function-normalize_u64_to_32_bytes)
- [Function `is_inbound_nonce_set`](#function-is_inbound_nonce_set)
- [Function `create_details`](#function-create_details)
- [Function `add`](#function-add)
- [Function `set_bridge_transfer_id_to_inbound_nonce`](#function-set_bridge_transfer_id_to_inbound_nonce)
- [Function `assert_valid_bridge_transfer_id`](#function-assert_valid_bridge_transfer_id)
- [Function `bridge_transfer_id`](#function-bridge_transfer_id)
- [Function `bridge_relayer`](#function-bridge_relayer)
- [Function `insurance_fund`](#function-insurance_fund)
- [Function `risk_denominator`](#function-risk_denominator)
- [Function `bridge_fee`](#function-bridge_fee)
- [Function `get_bridge_transfer_details_from_nonce`](#function-get_bridge_transfer_details_from_nonce)
- [Function `get_inbound_nonce_from_bridge_transfer_id`](#function-get_inbound_nonce_from_bridge_transfer_id)
- [Function `increment_and_get_nonce`](#function-increment_and_get_nonce)
- [Function `store_aptos_coin_burn_cap`](#function-store_aptos_coin_burn_cap)
- [Function `store_aptos_coin_mint_cap`](#function-store_aptos_coin_mint_cap)
- [Function `mint`](#function-mint)
- [Function `burn_from`](#function-burn_from)
- [Function `burn`](#function-burn)
- [Function `burn_internal`](#function-burn_internal)
- [Function `initiate_bridge_transfer`](#function-initiate_bridge_transfer)
- [Function `complete_bridge_transfer`](#function-complete_bridge_transfer)
- [Function `charge_bridge_fee`](#function-charge_bridge_fee)
- [Function `update_bridge_relayer`](#function-update_bridge_relayer)
- [Function `update_bridge_fee`](#function-update_bridge_fee)
- [Function `update_insurance_fund`](#function-update_insurance_fund)
- [Function `update_risk_denominator`](#function-update_risk_denominator)
- [Function `assert_is_caller_relayer`](#function-assert_is_caller_relayer)
- [Function `assert_rate_limit_budget_not_exceeded`](#function-assert_rate_limit_budget_not_exceeded)
- [Function `test_normalize_u64_to_32_bytes_helper`](#function-test_normalize_u64_to_32_bytes_helper)
- [Resource `AptosCoinBurnCapability`](#0x1_native_bridge_AptosCoinBurnCapability)
- [Resource `AptosCoinMintCapability`](#0x1_native_bridge_AptosCoinMintCapability)
- [Resource `AptosFABurnCapabilities`](#0x1_native_bridge_AptosFABurnCapabilities)
- [Resource `AptosFAMintCapabilities`](#0x1_native_bridge_AptosFAMintCapabilities)
- [Struct `BridgeTransferInitiatedEvent`](#0x1_native_bridge_BridgeTransferInitiatedEvent)
- [Struct `BridgeTransferCompletedEvent`](#0x1_native_bridge_BridgeTransferCompletedEvent)
- [Resource `BridgeEvents`](#0x1_native_bridge_BridgeEvents)
- [Resource `Nonce`](#0x1_native_bridge_Nonce)
- [Resource `SmartTableWrapper`](#0x1_native_bridge_SmartTableWrapper)
- [Struct `OutboundTransfer`](#0x1_native_bridge_OutboundTransfer)
- [Resource `BridgeConfig`](#0x1_native_bridge_BridgeConfig)
- [Struct `BridgeConfigRelayerUpdated`](#0x1_native_bridge_BridgeConfigRelayerUpdated)
- [Struct `BridgeFeeChangedEvent`](#0x1_native_bridge_BridgeFeeChangedEvent)
- [Constants](#@Constants_0)
- [Function `normalize_u64_to_32_bytes`](#0x1_native_bridge_normalize_u64_to_32_bytes)
- [Function `is_inbound_nonce_set`](#0x1_native_bridge_is_inbound_nonce_set)
- [Function `create_details`](#0x1_native_bridge_create_details)
- [Function `add`](#0x1_native_bridge_add)
- [Function `set_bridge_transfer_id_to_inbound_nonce`](#0x1_native_bridge_set_bridge_transfer_id_to_inbound_nonce)
- [Function `assert_valid_bridge_transfer_id`](#0x1_native_bridge_assert_valid_bridge_transfer_id)
- [Function `bridge_transfer_id`](#0x1_native_bridge_bridge_transfer_id)
- [Function `get_bridge_transfer_details_from_nonce`](#0x1_native_bridge_get_bridge_transfer_details_from_nonce)
- [Function `get_inbound_nonce_from_bridge_transfer_id`](#0x1_native_bridge_get_inbound_nonce_from_bridge_transfer_id)
- [Function `increment_and_get_nonce`](#0x1_native_bridge_increment_and_get_nonce)
- [Function `initialize`](#0x1_native_bridge_initialize)
- [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)
- [Function `initiate_bridge_transfer`](#0x1_native_bridge_initiate_bridge_transfer)
- [Function `complete_bridge_transfer`](#0x1_native_bridge_complete_bridge_transfer)
- [Function `charge_bridge_fee`](#0x1_native_bridge_charge_bridge_fee)
- [Function `update_bridge_relayer`](#0x1_native_bridge_update_bridge_relayer)
- [Function `update_bridge_fee`](#0x1_native_bridge_update_bridge_fee)
- [Function `bridge_relayer`](#0x1_native_bridge_bridge_relayer)
- [Function `bridge_fee`](#0x1_native_bridge_bridge_fee)
- [Function `assert_is_caller_relayer`](#0x1_native_bridge_assert_is_caller_relayer)
- [Function `test_normalize_u64_to_32_bytes_helper`](#0x1_native_bridge_test_normalize_u64_to_32_bytes_helper)


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



</details>

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

## 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.


<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)
</code></pre>



<details>
<summary>Implementation</summary>


<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> {
<a href="system_addresses.md#0x1_system_addresses_assert_aptos_framework">system_addresses::assert_aptos_framework</a>(aptos_framework);
<a href="native_bridge.md#0x1_native_bridge_mint">mint</a>(recipient, amount);
}
</code></pre>



</details>

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


<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)
<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)
</code></pre>


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


<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> {
<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> {
<a href="system_addresses.md#0x1_system_addresses_assert_aptos_framework">system_addresses::assert_aptos_framework</a>(aptos_framework);
<a href="native_bridge.md#0x1_native_bridge_burn_internal">burn_internal</a>(from, amount);
}
Expand Down
28 changes: 23 additions & 5 deletions aptos-move/framework/aptos-framework/sources/native_bridge.move
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,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.
Expand All @@ -418,19 +428,27 @@ 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<AptosCoinMintCapability>(@aptos_framework).mint_cap
));
}
}

/// 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.
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);
}
Expand Down Expand Up @@ -559,7 +577,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<BridgeEvents>(@aptos_framework);
Expand All @@ -585,7 +603,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
}

Expand Down Expand Up @@ -857,7 +875,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -5801,17 +5765,6 @@ mod decoder {
}
}

pub fn native_bridge_burn_from(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
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<EntryFunctionCall> {
Expand Down Expand Up @@ -6872,10 +6825,6 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
"multisig_account_vote_transanction".to_string(),
Box::new(decoder::multisig_account_vote_transanction),
);
map.insert(
"native_bridge_burn_from".to_string(),
Box::new(decoder::native_bridge_burn_from),
);
map.insert(
"native_bridge_complete_bridge_transfer".to_string(),
Box::new(decoder::native_bridge_complete_bridge_transfer),
Expand Down

0 comments on commit 991668f

Please sign in to comment.