aptos-labs / aptos-core

Aptos is a layer 1 blockchain built to support the widespread use of blockchain through better technology and user experience.
https://aptosfoundation.org
Other
6.17k stars 3.64k forks source link

[APT-4] [Feature Request] Add non-entry `mint_coins`, `burn_coins` functions to `managed_coin.move` module #5912

Open mkurnikov opened 1 year ago

mkurnikov commented 1 year ago

🚀 Feature Request

Add

public fun mint_coin<CoinType>(account: &signer, amount: u64): Coin<CoinType> {}

public fun burn_coin<CoinType>(account: &signer, coin: Coin<CoinType>) {}

to the aptos_framework::managed_coin module.

Motivation

Is your feature request related to a problem? Please describe.

Aptos has a nice managed_coin.move that removes a need to re-implement the CoinCapabilities resource in every single package for tests. It would be nice to have module-level mint and burn functions to be able to work with the Coin<CoinType> resource, not with coin balances.

APT-4

gregnazario commented 1 year ago

So to clarify the request is to allow Mint and Burn outside the confines of the CoinStore similar to the last line of mint / burn, but without interacting with a CoinStore.

I can see the use case for the Burn, but likely for minting, it may be more intentional to always store it in the CoinStore which is the storage location for managed coins, unless it is to support other coin stores.

mkurnikov commented 1 year ago

I assume the original intention of the managed_coin.move was to support easier token creation, mint/burn are supposed to be called as a transaction runs, that's why they're entry.

My use-case for the module is tests, next call after mint_coins would be to put this coin resource object into some module-level function.

Yes, I would like to have the same mint function, but without coin::deposit in the end, just

        let coins_minted = coin::mint(amount, &capabilities.mint_cap);
        coins_minted

Now I need to write this function

    fun mint_coins<CoinType>(admin: &signer, amount: u64): Coin<CoinType> {
        let admin_addr = signer::address_of(admin);
        if (!coin::is_account_registered<CoinType>(admin_addr)) {
            coin::register<CoinType>(admin);
        };
        managed_coin::mint<CoinType>(admin, admin_addr, amount);
        coin::withdraw<CoinType>(admin, amount)
    }

which is really sub-optimal.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 45 days with no activity. Remove the stale label or comment - otherwise this will be closed in 15 days.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 45 days with no activity. Remove the stale label or comment - otherwise this will be closed in 15 days.