Skip to content

Commit

Permalink
[fix] make the max supply unlimited
Browse files Browse the repository at this point in the history
  • Loading branch information
lightmark committed Jul 10, 2024
1 parent 68bd244 commit 57d7a68
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions aptos-move/framework/aptos-framework/doc/fungible_asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -3321,12 +3321,12 @@ Destroy an empty fungible asset.

<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="fungible_asset.md#0x1_fungible_asset_deposit_internal">deposit_internal</a>(store_addr: <b>address</b>, fa: <a href="fungible_asset.md#0x1_fungible_asset_FungibleAsset">FungibleAsset</a>) <b>acquires</b> <a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>, <a href="fungible_asset.md#0x1_fungible_asset_ConcurrentFungibleBalance">ConcurrentFungibleBalance</a> {
<b>let</b> <a href="fungible_asset.md#0x1_fungible_asset_FungibleAsset">FungibleAsset</a> { metadata, amount } = fa;
<b>if</b> (amount == 0) <b>return</b>;

<b>assert</b>!(<b>exists</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>&gt;(store_addr), <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_not_found">error::not_found</a>(<a href="fungible_asset.md#0x1_fungible_asset_EFUNGIBLE_STORE_EXISTENCE">EFUNGIBLE_STORE_EXISTENCE</a>));
<b>let</b> store = <b>borrow_global_mut</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_FungibleStore">FungibleStore</a>&gt;(store_addr);
<b>assert</b>!(metadata == store.metadata, <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_invalid_argument">error::invalid_argument</a>(<a href="fungible_asset.md#0x1_fungible_asset_EFUNGIBLE_ASSET_AND_STORE_MISMATCH">EFUNGIBLE_ASSET_AND_STORE_MISMATCH</a>));

<b>if</b> (amount == 0) <b>return</b>;

<b>if</b> (store.balance == 0 && <a href="fungible_asset.md#0x1_fungible_asset_concurrent_fungible_balance_exists_inline">concurrent_fungible_balance_exists_inline</a>(store_addr)) {
<b>let</b> balance_resource = <b>borrow_global_mut</b>&lt;<a href="fungible_asset.md#0x1_fungible_asset_ConcurrentFungibleBalance">ConcurrentFungibleBalance</a>&gt;(store_addr);
<a href="aggregator_v2.md#0x1_aggregator_v2_add">aggregator_v2::add</a>(&<b>mut</b> balance_resource.balance, amount);
Expand Down
4 changes: 3 additions & 1 deletion aptos-move/framework/aptos-framework/sources/coin.move
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ module aptos_framework::coin {
};
primary_fungible_store::create_primary_store_enabled_fungible_asset(
&metadata_object_cref,
option::map(coin_supply<CoinType>(), |_| MAX_U128),
option::none(),
name<CoinType>(),
symbol<CoinType>(),
decimals<CoinType>(),
Expand Down Expand Up @@ -2079,7 +2079,9 @@ module aptos_framework::coin {
ensure_paired_metadata<FakeMoney>();
let (mint_ref, mint_ref_receipt) = get_paired_mint_ref(&mint_cap);
let (burn_ref, burn_ref_receipt) = get_paired_burn_ref(&burn_cap);
// make sure the minted amount is greater than current coin supply.
let fungible_asset = fungible_asset::mint(&mint_ref, 50);
assert!(option::is_none(&fungible_asset::maximum(ensure_paired_metadata<FakeMoney>())), 0);
assert!(supply<FakeMoney>() == option::some(150), 0);
assert!(coin_supply<FakeMoney>() == option::some(100), 0);
assert!(fungible_asset::supply(ensure_paired_metadata<FakeMoney>()) == option::some(50), 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,12 +1011,12 @@ module aptos_framework::fungible_asset {

public(friend) fun deposit_internal(store_addr: address, fa: FungibleAsset) acquires FungibleStore, ConcurrentFungibleBalance {
let FungibleAsset { metadata, amount } = fa;
if (amount == 0) return;

assert!(exists<FungibleStore>(store_addr), error::not_found(EFUNGIBLE_STORE_EXISTENCE));
let store = borrow_global_mut<FungibleStore>(store_addr);
assert!(metadata == store.metadata, error::invalid_argument(EFUNGIBLE_ASSET_AND_STORE_MISMATCH));

if (amount == 0) return;

if (store.balance == 0 && concurrent_fungible_balance_exists_inline(store_addr)) {
let balance_resource = borrow_global_mut<ConcurrentFungibleBalance>(store_addr);
aggregator_v2::add(&mut balance_resource.balance, amount);
Expand Down

0 comments on commit 57d7a68

Please sign in to comment.