Skip to content

Commit dc4ea9f

Browse files
committed
feat: add init module hook for governed gas pool.
2 parents 86c53c2 + 991668f commit dc4ea9f

File tree

4 files changed

+72
-76
lines changed

4 files changed

+72
-76
lines changed

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

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,35 @@
55

66

77

8-
- [Struct `BridgeConfigRelayerUpdated`](#0x1_native_bridge_BridgeConfigRelayerUpdated)
9-
- [Struct `BridgeFeeChangedEvent`](#0x1_native_bridge_BridgeFeeChangedEvent)
10-
- [Struct `BridgeInsuranceBudgetDividerChangedEvent`](#0x1_native_bridge_BridgeInsuranceBudgetDividerChangedEvent)
11-
- [Struct `BridgeInsuranceFundChangedEvent`](#0x1_native_bridge_BridgeInsuranceFundChangedEvent)
12-
- [Struct `BridgeTransferInitiatedEvent`](#0x1_native_bridge_BridgeTransferInitiatedEvent)
13-
- [Struct `BridgeTransferCompletedEvent`](#0x1_native_bridge_BridgeTransferCompletedEvent)
14-
- [Resource `BridgeEvents`](#0x1_native_bridge_BridgeEvents)
158
- [Resource `AptosCoinBurnCapability`](#0x1_native_bridge_AptosCoinBurnCapability)
169
- [Resource `AptosCoinMintCapability`](#0x1_native_bridge_AptosCoinMintCapability)
1710
- [Resource `AptosFABurnCapabilities`](#0x1_native_bridge_AptosFABurnCapabilities)
1811
- [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)
1915
- [Resource `Nonce`](#0x1_native_bridge_Nonce)
20-
- [Resource `OutboundRateLimitBudget`](#0x1_native_bridge_OutboundRateLimitBudget)
21-
- [Resource `InboundRateLimitBudget`](#0x1_native_bridge_InboundRateLimitBudget)
2216
- [Resource `SmartTableWrapper`](#0x1_native_bridge_SmartTableWrapper)
2317
- [Struct `OutboundTransfer`](#0x1_native_bridge_OutboundTransfer)
2418
- [Resource `BridgeConfig`](#0x1_native_bridge_BridgeConfig)
19+
- [Struct `BridgeConfigRelayerUpdated`](#0x1_native_bridge_BridgeConfigRelayerUpdated)
20+
- [Struct `BridgeFeeChangedEvent`](#0x1_native_bridge_BridgeFeeChangedEvent)
2521
- [Constants](#@Constants_0)
26-
- [Function `initialize`](#0x1_native_bridge_initialize)
2722
- [Function `normalize_u64_to_32_bytes`](#0x1_native_bridge_normalize_u64_to_32_bytes)
2823
- [Function `is_inbound_nonce_set`](#0x1_native_bridge_is_inbound_nonce_set)
2924
- [Function `create_details`](#0x1_native_bridge_create_details)
3025
- [Function `add`](#0x1_native_bridge_add)
3126
- [Function `set_bridge_transfer_id_to_inbound_nonce`](#0x1_native_bridge_set_bridge_transfer_id_to_inbound_nonce)
3227
- [Function `assert_valid_bridge_transfer_id`](#0x1_native_bridge_assert_valid_bridge_transfer_id)
3328
- [Function `bridge_transfer_id`](#0x1_native_bridge_bridge_transfer_id)
34-
- [Function `bridge_relayer`](#0x1_native_bridge_bridge_relayer)
35-
- [Function `insurance_fund`](#0x1_native_bridge_insurance_fund)
36-
- [Function `insurance_budget_divider`](#0x1_native_bridge_insurance_budget_divider)
37-
- [Function `bridge_fee`](#0x1_native_bridge_bridge_fee)
3829
- [Function `get_bridge_transfer_details_from_nonce`](#0x1_native_bridge_get_bridge_transfer_details_from_nonce)
3930
- [Function `get_inbound_nonce_from_bridge_transfer_id`](#0x1_native_bridge_get_inbound_nonce_from_bridge_transfer_id)
4031
- [Function `increment_and_get_nonce`](#0x1_native_bridge_increment_and_get_nonce)
32+
- [Function `initialize`](#0x1_native_bridge_initialize)
4133
- [Function `store_aptos_coin_burn_cap`](#0x1_native_bridge_store_aptos_coin_burn_cap)
4234
- [Function `store_aptos_coin_mint_cap`](#0x1_native_bridge_store_aptos_coin_mint_cap)
4335
- [Function `mint`](#0x1_native_bridge_mint)
36+
- [Function `mint_from`](#0x1_native_bridge_mint_from)
4437
- [Function `burn_from`](#0x1_native_bridge_burn_from)
4538
- [Function `burn`](#0x1_native_bridge_burn)
4639
- [Function `burn_internal`](#0x1_native_bridge_burn_internal)
@@ -49,11 +42,9 @@
4942
- [Function `charge_bridge_fee`](#0x1_native_bridge_charge_bridge_fee)
5043
- [Function `update_bridge_relayer`](#0x1_native_bridge_update_bridge_relayer)
5144
- [Function `update_bridge_fee`](#0x1_native_bridge_update_bridge_fee)
52-
- [Function `update_insurance_fund`](#0x1_native_bridge_update_insurance_fund)
53-
- [Function `update_insurance_budget_divider`](#0x1_native_bridge_update_insurance_budget_divider)
45+
- [Function `bridge_relayer`](#0x1_native_bridge_bridge_relayer)
46+
- [Function `bridge_fee`](#0x1_native_bridge_bridge_fee)
5447
- [Function `assert_is_caller_relayer`](#0x1_native_bridge_assert_is_caller_relayer)
55-
- [Function `assert_outbound_rate_limit_budget_not_exceeded`](#0x1_native_bridge_assert_outbound_rate_limit_budget_not_exceeded)
56-
- [Function `assert_inbound_rate_limit_budget_not_exceeded`](#0x1_native_bridge_assert_inbound_rate_limit_budget_not_exceeded)
5748
- [Function `test_normalize_u64_to_32_bytes_helper`](#0x1_native_bridge_test_normalize_u64_to_32_bytes_helper)
5849

5950

@@ -1417,6 +1408,36 @@ Mints a specified amount of AptosCoin to a recipient's address.
14171408

14181409

14191410

1411+
</details>
1412+
1413+
<a id="0x1_native_bridge_mint_from"></a>
1414+
1415+
## Function `mint_from`
1416+
1417+
Mints a specified amount of AptosCoin to a recipient's address.
1418+
1419+
@param core_resource The signer representing the core resource account.
1420+
@param recipient The address of the recipient to mint coins to.
1421+
@param amount The amount of AptosCoin to mint.
1422+
1423+
1424+
<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)
1425+
</code></pre>
1426+
1427+
1428+
1429+
<details>
1430+
<summary>Implementation</summary>
1431+
1432+
1433+
<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> {
1434+
<a href="system_addresses.md#0x1_system_addresses_assert_aptos_framework">system_addresses::assert_aptos_framework</a>(aptos_framework);
1435+
<a href="native_bridge.md#0x1_native_bridge_mint">mint</a>(recipient, amount);
1436+
}
1437+
</code></pre>
1438+
1439+
1440+
14201441
</details>
14211442

14221443
<a id="0x1_native_bridge_burn_from"></a>
@@ -1431,7 +1452,7 @@ Burns a specified amount of AptosCoin from an address.
14311452
@abort If the burn capability is not available.
14321453

14331454

1434-
<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)
1455+
<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)
14351456
</code></pre>
14361457

14371458

@@ -1440,7 +1461,7 @@ Burns a specified amount of AptosCoin from an address.
14401461
<summary>Implementation</summary>
14411462

14421463

1443-
<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> {
1464+
<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> {
14441465
<a href="system_addresses.md#0x1_system_addresses_assert_aptos_framework">system_addresses::assert_aptos_framework</a>(aptos_framework);
14451466
<a href="native_bridge.md#0x1_native_bridge_burn_internal">burn_internal</a>(from, amount);
14461467
}

aptos-move/framework/aptos-framework/sources/governed_gas_pool.move

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ module aptos_framework::governed_gas_pool {
6565
});
6666
}
6767

68+
/// Initialize the governed gas pool as a module
69+
/// @param aptos_framework The signer of the aptos_framework module.
70+
public fun init_module(aptos_framework: &signer) {
71+
// Initialize the governed gas pool
72+
let seed : vector<u8> = b"aptos_framework::governed_gas_pool";
73+
initialize(aptos_framework, seed);
74+
}
75+
6876
/// Borrows the signer of the governed gas pool.
6977
/// @return The signer of the governed gas pool.
7078
fun governed_gas_signer(): signer acquires GovernedGasPool {

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
@@ -714,17 +714,6 @@ pub enum EntryFunctionCall {
714714
approved: bool,
715715
},
716716

717-
/// Burns a specified amount of AptosCoin from an address.
718-
///
719-
/// @param core_resource The signer representing the core resource account.
720-
/// @param from The address from which to burn AptosCoin.
721-
/// @param amount The amount of AptosCoin to burn.
722-
/// @abort If the burn capability is not available.
723-
NativeBridgeBurnFrom {
724-
from: AccountAddress,
725-
amount: u64,
726-
},
727-
728717
/// Completes a bridge transfer on the destination chain.
729718
730719
/// @param caller The signer representing the bridge relayer.
@@ -1563,7 +1552,6 @@ impl EntryFunctionCall {
15631552
sequence_number,
15641553
approved,
15651554
} => multisig_account_vote_transanction(multisig_account, sequence_number, approved),
1566-
NativeBridgeBurnFrom { from, amount } => native_bridge_burn_from(from, amount),
15671555
NativeBridgeCompleteBridgeTransfer {
15681556
bridge_transfer_id,
15691557
initiator,
@@ -3746,30 +3734,6 @@ pub fn multisig_account_vote_transanction(
37463734
))
37473735
}
37483736

3749-
/// Burns a specified amount of AptosCoin from an address.
3750-
///
3751-
/// @param core_resource The signer representing the core resource account.
3752-
/// @param from The address from which to burn AptosCoin.
3753-
/// @param amount The amount of AptosCoin to burn.
3754-
/// @abort If the burn capability is not available.
3755-
pub fn native_bridge_burn_from(from: AccountAddress, amount: u64) -> TransactionPayload {
3756-
TransactionPayload::EntryFunction(EntryFunction::new(
3757-
ModuleId::new(
3758-
AccountAddress::new([
3759-
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,
3760-
0, 0, 0, 1,
3761-
]),
3762-
ident_str!("native_bridge").to_owned(),
3763-
),
3764-
ident_str!("burn_from").to_owned(),
3765-
vec![],
3766-
vec![
3767-
bcs::to_bytes(&from).unwrap(),
3768-
bcs::to_bytes(&amount).unwrap(),
3769-
],
3770-
))
3771-
}
3772-
37733737
/// Completes a bridge transfer on the destination chain.
37743738
///
37753739
/// @param caller The signer representing the bridge relayer.
@@ -6178,17 +6142,6 @@ mod decoder {
61786142
}
61796143
}
61806144

6181-
pub fn native_bridge_burn_from(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
6182-
if let TransactionPayload::EntryFunction(script) = payload {
6183-
Some(EntryFunctionCall::NativeBridgeBurnFrom {
6184-
from: bcs::from_bytes(script.args().get(0)?).ok()?,
6185-
amount: bcs::from_bytes(script.args().get(1)?).ok()?,
6186-
})
6187-
} else {
6188-
None
6189-
}
6190-
}
6191-
61926145
pub fn native_bridge_complete_bridge_transfer(
61936146
payload: &TransactionPayload,
61946147
) -> Option<EntryFunctionCall> {
@@ -7307,10 +7260,6 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
73077260
"multisig_account_vote_transanction".to_string(),
73087261
Box::new(decoder::multisig_account_vote_transanction),
73097262
);
7310-
map.insert(
7311-
"native_bridge_burn_from".to_string(),
7312-
Box::new(decoder::native_bridge_burn_from),
7313-
);
73147263
map.insert(
73157264
"native_bridge_complete_bridge_transfer".to_string(),
73167265
Box::new(decoder::native_bridge_complete_bridge_transfer),

0 commit comments

Comments
 (0)