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 3, 2024
1 parent 7ec5b41 commit 579821d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
23 changes: 22 additions & 1 deletion aptos-move/framework/aptos-framework/doc/coin.md
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ Create APT pairing by passing <code>AptosCoin</code>.
};
<a href="primary_fungible_store.md#0x1_primary_fungible_store_create_primary_store_enabled_fungible_asset">primary_fungible_store::create_primary_store_enabled_fungible_asset</a>(
&metadata_object_cref,
<a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_map">option::map</a>(<a href="coin.md#0x1_coin_coin_supply">coin_supply</a>&lt;CoinType&gt;(), |_| <a href="coin.md#0x1_coin_MAX_U128">MAX_U128</a>),
<a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_none">option::none</a>(),
<a href="coin.md#0x1_coin_name">name</a>&lt;CoinType&gt;(),
<a href="coin.md#0x1_coin_symbol">symbol</a>&lt;CoinType&gt;(),
<a href="coin.md#0x1_coin_decimals">decimals</a>&lt;CoinType&gt;(),
Expand Down Expand Up @@ -4595,6 +4595,27 @@ The creator of <code>CoinType</code> must be <code>@aptos_framework</code>.
</code></pre>


Make sure <code>name</code> and <code>symbol</code> are legal length.
Only the creator of <code>CoinType</code> can initialize.


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


<pre><code><b>schema</b> <a href="coin.md#0x1_coin_InitializeInternalSchema">InitializeInternalSchema</a>&lt;CoinType&gt; {
<a href="account.md#0x1_account">account</a>: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>;
name: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;;
symbol: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;;
<b>let</b> account_addr = <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(<a href="account.md#0x1_account">account</a>);
<b>let</b> coin_address = <a href="../../aptos-stdlib/doc/type_info.md#0x1_type_info_type_of">type_info::type_of</a>&lt;CoinType&gt;().account_address;
<b>aborts_if</b> coin_address != account_addr;
<b>aborts_if</b> <b>exists</b>&lt;<a href="coin.md#0x1_coin_CoinInfo">CoinInfo</a>&lt;CoinType&gt;&gt;(account_addr);
<b>aborts_if</b> len(name) &gt; <a href="coin.md#0x1_coin_MAX_COIN_NAME_LENGTH">MAX_COIN_NAME_LENGTH</a>;
<b>aborts_if</b> len(symbol) &gt; <a href="coin.md#0x1_coin_MAX_COIN_SYMBOL_LENGTH">MAX_COIN_SYMBOL_LENGTH</a>;
}
</code></pre>



<a id="@Specification_1_initialize_internal"></a>

Expand Down
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
2 changes: 1 addition & 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
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 579821d

Please sign in to comment.