Skip to content

Commit

Permalink
[FA] get rid of migration flag
Browse files Browse the repository at this point in the history
  • Loading branch information
lightmark committed Nov 13, 2024
1 parent d7c3996 commit 77a70c2
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 153 deletions.
2 changes: 1 addition & 1 deletion aptos-move/e2e-move-tests/src/tests/fee_payer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn test_existing_account_with_fee_payer_aborts() {

let output = h.run_raw(transaction);
// Alice has an insufficient balance, trying to 1 when she has 0.
assert_abort!(output.status(), 65542);
assert_abort!(output.status(), 65540);

let alice_after = h.read_aptos_balance(alice.address());
let bob_after = h.read_aptos_balance(bob.address());
Expand Down
3 changes: 1 addition & 2 deletions aptos-move/e2e-move-tests/src/tests/fungible_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ fn test_basic_fungible_token() {
// A simple test to verify gas paying still work for prologue and epilogue.
#[test]
fn test_coin_to_fungible_asset_migration() {
let mut h = MoveHarness::new();

let mut h = MoveHarness::new_with_features(vec![], vec![FeatureFlag::NEW_ACCOUNTS_DEFAULT_TO_FA_APT_STORE]);
let alice = h.new_account_at(AccountAddress::from_hex_literal("0xcafe").unwrap());
let alice_primary_store_addr =
account_address::create_derived_object_address(*alice.address(), AccountAddress::TEN);
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/e2e-move-tests/src/tests/module_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn test_module_event_enabled() {
vec![bcs::to_bytes(&10u64).unwrap()],
);
let events = h.get_events();
assert_eq!(events.len(), 13);
assert_eq!(events.len(), 15);
let my_event_tag = TypeTag::from_str("0xcafe::event::MyEvent").unwrap();
let mut count = 0;
for event in events.iter() {
Expand Down
2 changes: 1 addition & 1 deletion aptos-move/e2e-move-tests/src/tests/state_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use move_core_types::{account_address::AccountAddress, parser::parse_struct_tag}

#[test]
fn test_metadata_tracking() {
let mut harness = MoveHarness::new();
let mut harness = MoveHarness::new_with_features(vec![], vec![FeatureFlag::NEW_ACCOUNTS_DEFAULT_TO_FA_APT_STORE]);
harness.new_epoch(); // so that timestamp is not 0 (rather, 7200000001)
let timestamp = CurrentTimeMicroseconds {
microseconds: 7200000001,
Expand Down
4 changes: 3 additions & 1 deletion aptos-move/e2e-move-tests/src/tests/token_event_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ fn test_token_creation_with_token_events_store() {
h.create_transaction_payload(&acc, aptos_token_stdlib::token_opt_in_direct_transfer(true));
let (_, mut events) = h.run_with_events(signed_txn);
// First one is always the 0x1::transaction_fee::FeeStatement
let _event = events.pop().unwrap();
let _ = events.pop().unwrap();
// Second one is fungible asset withdraw.
let _ = events.pop().unwrap();
let event = events.pop().unwrap();
assert_eq!(
"0x3::token_event_store::OptInTransfer".to_string(),
Expand Down
4 changes: 1 addition & 3 deletions aptos-move/framework/aptos-framework/doc/aptos_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,7 @@ By default, this returns true if an account has not explicitly set whether the c


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="aptos_account.md#0x1_aptos_account_register_apt">register_apt</a>(account_signer: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>) {
<b>if</b> (<a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_new_accounts_default_to_fa_apt_store_enabled">features::new_accounts_default_to_fa_apt_store_enabled</a>()) {
<a href="aptos_account.md#0x1_aptos_account_ensure_primary_fungible_store_exists">ensure_primary_fungible_store_exists</a>(<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(account_signer));
} <b>else</b> {
<b>if</b> (!<a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_new_accounts_default_to_fa_apt_store_enabled">features::new_accounts_default_to_fa_apt_store_enabled</a>()) {
<a href="coin.md#0x1_coin_register">coin::register</a>&lt;AptosCoin&gt;(account_signer);
}
}
Expand Down
103 changes: 41 additions & 62 deletions aptos-move/framework/aptos-framework/doc/coin.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ This module provides the foundation for typesafe Coins.
- [Struct `WithdrawEvent`](#0x1_coin_WithdrawEvent)
- [Struct `CoinEventHandleDeletion`](#0x1_coin_CoinEventHandleDeletion)
- [Struct `PairCreation`](#0x1_coin_PairCreation)
- [Resource `MigrationFlag`](#0x1_coin_MigrationFlag)
- [Struct `MintCapability`](#0x1_coin_MintCapability)
- [Struct `FreezeCapability`](#0x1_coin_FreezeCapability)
- [Struct `BurnCapability`](#0x1_coin_BurnCapability)
Expand All @@ -29,6 +28,7 @@ This module provides the foundation for typesafe Coins.
- [Struct `MintRefReceipt`](#0x1_coin_MintRefReceipt)
- [Struct `TransferRefReceipt`](#0x1_coin_TransferRefReceipt)
- [Struct `BurnRefReceipt`](#0x1_coin_BurnRefReceipt)
- [Resource `MigrationFlag`](#0x1_coin_MigrationFlag)
- [Resource `Ghost$supply`](#0x1_coin_Ghost$supply)
- [Resource `Ghost$aggregate_supply`](#0x1_coin_Ghost$aggregate_supply)
- [Constants](#@Constants_0)
Expand Down Expand Up @@ -621,35 +621,6 @@ Module event emitted when a new pair of coin and fungible asset is created.
</dl>


</details>

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

## Resource `MigrationFlag`

The flag the existence of which indicates the primary fungible store is created by the migration from CoinStore.


<pre><code>#[resource_group_member(#[group = <a href="object.md#0x1_object_ObjectGroup">0x1::object::ObjectGroup</a>])]
<b>struct</b> <a href="coin.md#0x1_coin_MigrationFlag">MigrationFlag</a> <b>has</b> key
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code>dummy_field: bool</code>
</dt>
<dd>

</dd>
</dl>


</details>

<a id="0x1_coin_MintCapability"></a>
Expand Down Expand Up @@ -916,6 +887,36 @@ The hot potato receipt for flash borrowing BurnRef.
</dl>


</details>

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

## Resource `MigrationFlag`

The flag the existence of which indicates the primary fungible store is created by the migration from CoinStore.


<pre><code>#[resource_group_member(#[group = <a href="object.md#0x1_object_ObjectGroup">0x1::object::ObjectGroup</a>])]
#[deprecated]
<b>struct</b> <a href="coin.md#0x1_coin_MigrationFlag">MigrationFlag</a> <b>has</b> key
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code>dummy_field: bool</code>
</dt>
<dd>

</dd>
</dl>


</details>

<a id="0x1_coin_Ghost$supply"></a>
Expand Down Expand Up @@ -2038,7 +2039,6 @@ or disallow upgradability of total supply.

<b>let</b> metadata = <a href="coin.md#0x1_coin_ensure_paired_metadata">ensure_paired_metadata</a>&lt;CoinType&gt;();
<b>let</b> store = <a href="primary_fungible_store.md#0x1_primary_fungible_store_ensure_primary_store_exists">primary_fungible_store::ensure_primary_store_exists</a>(<a href="account.md#0x1_account">account</a>, metadata);
<b>let</b> store_address = <a href="object.md#0x1_object_object_address">object::object_address</a>(&store);
<b>if</b> (<b>exists</b>&lt;<a href="coin.md#0x1_coin_CoinStore">CoinStore</a>&lt;CoinType&gt;&gt;(<a href="account.md#0x1_account">account</a>)) {
<b>let</b> <a href="coin.md#0x1_coin_CoinStore">CoinStore</a>&lt;CoinType&gt; { <a href="coin.md#0x1_coin">coin</a>, frozen, deposit_events, withdraw_events } = <b>move_from</b>&lt;<a href="coin.md#0x1_coin_CoinStore">CoinStore</a>&lt;CoinType&gt;&gt;(
<a href="account.md#0x1_account">account</a>
Expand Down Expand Up @@ -2068,9 +2068,6 @@ or disallow upgradability of total supply.
<a href="fungible_asset.md#0x1_fungible_asset_set_frozen_flag_internal">fungible_asset::set_frozen_flag_internal</a>(store, frozen);
}
};
<b>if</b> (!<b>exists</b>&lt;<a href="coin.md#0x1_coin_MigrationFlag">MigrationFlag</a>&gt;(store_address)) {
<b>move_to</b>(&<a href="create_signer.md#0x1_create_signer_create_signer">create_signer::create_signer</a>(store_address), <a href="coin.md#0x1_coin_MigrationFlag">MigrationFlag</a> {});
}
}
</code></pre>

Expand Down Expand Up @@ -2625,11 +2622,13 @@ Deposit the coin balance into the recipient's account and emit an event.
account_address: <b>address</b>,
metadata: Object&lt;Metadata&gt;
): bool {
<b>let</b> primary_store_address = <a href="primary_fungible_store.md#0x1_primary_fungible_store_primary_store_address">primary_fungible_store::primary_store_address</a>&lt;Metadata&gt;(account_address, metadata);
<a href="fungible_asset.md#0x1_fungible_asset_store_exists">fungible_asset::store_exists</a>(primary_store_address) && (
// migration flag is needed, until we start defaulting new accounts <b>to</b> APT PFS
<a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_new_accounts_default_to_fa_apt_store_enabled">features::new_accounts_default_to_fa_apt_store_enabled</a>() || <b>exists</b>&lt;<a href="coin.md#0x1_coin_MigrationFlag">MigrationFlag</a>&gt;(primary_store_address)
)
<a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_new_accounts_default_to_fa_apt_store_enabled">features::new_accounts_default_to_fa_apt_store_enabled</a>() || {
<b>let</b> primary_store_address = <a href="primary_fungible_store.md#0x1_primary_fungible_store_primary_store_address">primary_fungible_store::primary_store_address</a>&lt;Metadata&gt;(
account_address,
metadata
);
<a href="fungible_asset.md#0x1_fungible_asset_store_exists">fungible_asset::store_exists</a>(primary_store_address)
}
}
</code></pre>

Expand Down Expand Up @@ -2669,7 +2668,7 @@ This is for internal use only and doesn't emit an DepositEvent.
)) {
<b>let</b> fa = <a href="coin.md#0x1_coin_coin_to_fungible_asset">coin_to_fungible_asset</a>(<a href="coin.md#0x1_coin">coin</a>);
<b>let</b> metadata = <a href="fungible_asset.md#0x1_fungible_asset_asset_metadata">fungible_asset::asset_metadata</a>(&fa);
<b>let</b> store = <a href="primary_fungible_store.md#0x1_primary_fungible_store_primary_store">primary_fungible_store::primary_store</a>(account_addr, metadata);
<b>let</b> store = <a href="primary_fungible_store.md#0x1_primary_fungible_store_ensure_primary_store_exists">primary_fungible_store::ensure_primary_store_exists</a>(account_addr, metadata);
<a href="fungible_asset.md#0x1_fungible_asset_deposit_internal">fungible_asset::deposit_internal</a>(<a href="object.md#0x1_object_object_address">object::object_address</a>(&store), fa);
} <b>else</b> {
<b>abort</b> <a href="../../aptos-stdlib/../move-stdlib/doc/error.md#0x1_error_not_found">error::not_found</a>(<a href="coin.md#0x1_coin_ECOIN_STORE_NOT_PUBLISHED">ECOIN_STORE_NOT_PUBLISHED</a>)
Expand Down Expand Up @@ -3782,7 +3781,8 @@ Get address by reflection.

<pre><code><b>fun</b> <a href="coin.md#0x1_coin_spec_is_account_registered">spec_is_account_registered</a>&lt;CoinType&gt;(account_addr: <b>address</b>): bool {
<b>let</b> paired_metadata_opt = <a href="coin.md#0x1_coin_spec_paired_metadata">spec_paired_metadata</a>&lt;CoinType&gt;();
<b>exists</b>&lt;<a href="coin.md#0x1_coin_CoinStore">CoinStore</a>&lt;CoinType&gt;&gt;(account_addr) || (<a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_spec_is_some">option::spec_is_some</a>(
<b>exists</b>&lt;<a href="coin.md#0x1_coin_CoinStore">CoinStore</a>&lt;CoinType&gt;&gt;(account_addr) || <a href="../../aptos-stdlib/../move-stdlib/doc/features.md#0x1_features_spec_new_accounts_default_to_fa_apt_store_enabled">features::spec_new_accounts_default_to_fa_apt_store_enabled</a>(
) || (<a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_spec_is_some">option::spec_is_some</a>(
paired_metadata_opt
) && <a href="primary_fungible_store.md#0x1_primary_fungible_store_spec_primary_store_exists">primary_fungible_store::spec_primary_store_exists</a>(account_addr, <a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_spec_borrow">option::spec_borrow</a>(paired_metadata_opt)))
}
Expand Down Expand Up @@ -4195,27 +4195,6 @@ 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
1 change: 0 additions & 1 deletion aptos-move/framework/aptos-framework/sources/account.move
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,6 @@ module aptos_framework::account {
create_account_unchecked(addr);
register_coin<FakeCoin>(addr);

let eventhandle = &borrow_global<Account>(addr).coin_register_events;
let event = CoinRegister { account: addr, type_info: type_info::type_of<FakeCoin>() };

let events = event::emitted_events<CoinRegister>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,7 @@ module aptos_framework::aptos_account {
}

public(friend) fun register_apt(account_signer: &signer) {
if (features::new_accounts_default_to_fa_apt_store_enabled()) {
ensure_primary_fungible_store_exists(signer::address_of(account_signer));
} else {
if (!features::new_accounts_default_to_fa_apt_store_enabled()) {
coin::register<AptosCoin>(account_signer);
}
}
Expand Down Expand Up @@ -320,7 +318,6 @@ module aptos_framework::aptos_account {
let (resource_account, _) = account::create_resource_account(alice, vector[]);
let resource_acc_addr = signer::address_of(&resource_account);
let (burn_cap, mint_cap) = aptos_framework::aptos_coin::initialize_for_test(core);
assert!(!coin::is_account_registered<AptosCoin>(resource_acc_addr), 0);

create_account(signer::address_of(alice));
coin::deposit(signer::address_of(alice), coin::mint(10000, &mint_cap));
Expand Down
Loading

0 comments on commit 77a70c2

Please sign in to comment.