Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module aptos_framework::governed_gas_pool {
#[test_only]
use aptos_framework::aptos_coin::Self;

friend aptos_framework::stake;

const MODULE_SALT: vector<u8> = b"aptos_framework::governed_gas_pool";

/// The Governed Gas Pool
Expand Down Expand Up @@ -170,6 +172,27 @@ module aptos_framework::governed_gas_pool {
coin::balance<CoinType>(pool_address)
}

/// Withdraws coins from the governed gas pool.
///
/// This function allows friend modules to withdraw a specified amount of a given
/// `CoinType` from the governed gas pool. It uses the internal signer of the
/// governed gas pool to authorize the withdrawal.
///
/// @param amount The amount of coins to withdraw from the pool.
/// @return A `Coin<CoinType>` resource containing the withdrawn amount.
public(friend) fun withdraw_from_pool<CoinType>(
Comment thread
areshand marked this conversation as resolved.
Outdated
amount: u64
Comment thread
areshand marked this conversation as resolved.
): Coin<CoinType> acquires GovernedGasPool {
let s = governed_gas_signer(); // uses the private signer function

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert the pool has sufficient balance for the withdraw?

coin::withdraw<CoinType>(&s, amount)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a dedicated event for withdraw from GGP for accounting purpose

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an event to GGP is a little more complicated than expected. Creating the event handler in the unit test need to have the sender account created, and the framework account is not for most of the test that use the staking.
I've tested, and I get the MISSING_DATA (code 4008) error when the handler is created.

To solve this, you need to add this line in all test that fails: aptos_framework::account::create_account_for_test(@aptos_framework);

I've tested using account::new_event_handle<>() and event::new_event_handle<>() , the account must be created to create the handler.

What do you think, I add the create_account_for_test in all failing test (all test that use the GGP) ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I push the account implementation with 2 tests updated.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct, it uses the resource account pattern https://aptos.dev/build/smart-contracts/resource-accounts

What do you think, I add the create_account_for_test in all failing test (all test that use the GGP) ?

It might seem clunky but it's correct, so I would say yes.

}

/// Register Aptos coin with Gouverned gas signer.
Comment thread
areshand marked this conversation as resolved.
Outdated
public(friend) fun register_coin<CoinType>() acquires GovernedGasPool {
Comment thread
areshand marked this conversation as resolved.
let s = governed_gas_signer();
coin::register<CoinType>(&s);
}

#[test_only]
/// The AptosCoin mint capability
struct AptosCoinMintCapability has key {
Expand Down Expand Up @@ -361,4 +384,4 @@ module aptos_framework::governed_gas_pool {
// initialize the governed gas pool again, no abort
initialize(aptos_framework, vector::empty<u8>());
}
}
}
Loading