diff --git a/Cargo.lock b/Cargo.lock index f876c5d992..f4f3c04864 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10172,6 +10172,7 @@ dependencies = [ "starcoin-config", "starcoin-consensus", "starcoin-crypto", + "starcoin-logger", "starcoin-state-api", "starcoin-transaction-builder", "starcoin-types", diff --git a/asset-mapping/Cargo.toml b/asset-mapping/Cargo.toml index 792f7192f1..927efd14a1 100644 --- a/asset-mapping/Cargo.toml +++ b/asset-mapping/Cargo.toml @@ -15,11 +15,12 @@ bcs-ext = { workspace = true } forkable-jellyfish-merkle = { workspace = true } starcoin-transaction-builder = { workspace = true } starcoin-chain = { workspace = true } +starcoin-config = { workspace = true } starcoin-consensus = { workspace = true } starcoin-crypto = { workspace = true } -starcoin-types = { workspace = true } +starcoin-cached-packages = { workspace = true } +starcoin-logger = { workspace = true } starcoin-state-api = { workspace = true } +starcoin-types = { workspace = true } starcoin-vm-types = { workspace = true } -starcoin-config = { workspace = true } -test-helper = { workspace = true } -starcoin-cached-packages = { workspace = true } \ No newline at end of file +test-helper = { workspace = true } \ No newline at end of file diff --git a/asset-mapping/src/lib.rs b/asset-mapping/src/lib.rs index 54bfd18358..4cb9704ccf 100644 --- a/asset-mapping/src/lib.rs +++ b/asset-mapping/src/lib.rs @@ -126,8 +126,10 @@ fn test_asset_mapping_for_specified_coin_type() -> Result<()> { #[test] fn test_asset_mapping_whole_process() -> Result<()> { + starcoin_logger::init_for_test(); + let block_gas_limit: u64 = 10000000; - let initial_balance: u128 = 1000000000000; + let initial_balance: u128 = 100000000000; // 1000 STC let receiver = AccountAddress::from_str("0xd0c5a06ae6100ce115cad1600fe59e96").unwrap(); // Create a source BlockChain @@ -202,10 +204,19 @@ fn test_asset_mapping_whole_process() -> Result<()> { .get_sequence_number(genesis_address())? }; - // Transfer STC from association account to receiver account - let peer_to_peer_txn = - { local_build_peer_to_peer_from_association(&block_chain, receiver, 1, &net)? }; - local_block_chain_excecute_txn(&mut block_chain, peer_to_peer_txn)?; + { + // Transfer STC from association account to receiver account + let peer_to_peer_txn = + { local_build_peer_to_peer_from_association(&block_chain, receiver, 1, &net)? }; + local_block_chain_excecute_txn(&mut block_chain, peer_to_peer_txn)?; + } + + { + // Transfer STC from association account to framework account for gas fee + let peer_to_peer_txn = + { local_build_peer_to_peer_from_association(&block_chain, AccountAddress::from_hex_literal("0x1").unwrap(), 1000000000, &net)? }; + local_block_chain_excecute_txn(&mut block_chain, peer_to_peer_txn)?; + } // Verify proof and assign asset mapping to receiver account local_block_chain_excecute_txn( @@ -221,7 +232,7 @@ fn test_asset_mapping_whole_process() -> Result<()> { ), genesis_sequence_number, DEFAULT_MAX_GAS_AMOUNT, - block_gas_limit, + 1, DEFAULT_EXPIRATION_TIME, net.chain_id(), ), @@ -265,14 +276,13 @@ fn local_block_chain_excecute_txn( chain: &mut BlockChain, txn: SignedUserTransaction, ) -> Result<()> { - let block_gas_limit: u64 = 10000000; let (block_template, excluded) = chain .create_block_template( account_config::association_address(), None, vec![txn], vec![], - Some(block_gas_limit), + Some(DEFAULT_MAX_GAS_AMOUNT), None, ) .unwrap(); diff --git a/config/src/genesis_config.rs b/config/src/genesis_config.rs index 98a1531027..3b9ad4b6cd 100644 --- a/config/src/genesis_config.rs +++ b/config/src/genesis_config.rs @@ -1173,7 +1173,7 @@ pub static G_MAIN_CONFIG: Lazy = Lazy::new(|| { }, transaction_timeout: ONE_DAY, dag_effective_height: u64::MAX, - // TODO(BobOng): to confirm the asset mapping proof root hash + // TODO(BobOng): [asset-mapping] To confirm the asset mapping proof root hash asset_mapping_root_hash: HashValue::zero(), } }); diff --git a/vm/framework/starcoin-framework/doc/asset_mapping.md b/vm/framework/starcoin-framework/doc/asset_mapping.md index fb0ec67b38..ddcc566050 100644 --- a/vm/framework/starcoin-framework/doc/asset_mapping.md +++ b/vm/framework/starcoin-framework/doc/asset_mapping.md @@ -10,17 +10,15 @@ with proof verification. - [Resource `AssetMappingStore`](#0x1_asset_mapping_AssetMappingStore) -- [Resource `AssetMappingPool`](#0x1_asset_mapping_AssetMappingPool) - [Resource `AssetMappingProof`](#0x1_asset_mapping_AssetMappingProof) -- [Resource `AssetMappingCoinType`](#0x1_asset_mapping_AssetMappingCoinType) +- [Resource `AssetMappingPool`](#0x1_asset_mapping_AssetMappingPool) - [Constants](#@Constants_0) - [Function `initialize`](#0x1_asset_mapping_initialize) - [Function `create_store_from_coin`](#0x1_asset_mapping_create_store_from_coin) -- [Function `create_store_for_type`](#0x1_asset_mapping_create_store_for_type) -- [Function `balance`](#0x1_asset_mapping_balance) +- [Function `create_store_for_coin_type`](#0x1_asset_mapping_create_store_for_coin_type) +- [Function `fungible_store_balance`](#0x1_asset_mapping_fungible_store_balance) - [Function `assign_to_account_with_proof`](#0x1_asset_mapping_assign_to_account_with_proof) - [Function `assign_to_account`](#0x1_asset_mapping_assign_to_account) -- [Function `split_proof_siblings_from_vec`](#0x1_asset_mapping_split_proof_siblings_from_vec) - [Function `calculation_proof`](#0x1_asset_mapping_calculation_proof) @@ -48,6 +46,7 @@ AssetMappingStore represents a store for mapped assets Contains: - extend_ref: Reference for extending object capabilities - fungible_store: The actual store holding fungible assets +- fungible_metadata: The type of fungible assets
struct AssetMappingStore has store, key
@@ -72,34 +71,8 @@ Contains:
 
- - - - - - - -## Resource `AssetMappingPool` - -AssetMappingPool manages a collection of asset mapping stores -Contains: -- proof_root: Root hash for proof verification -- anchor_height: Block height anchor for the mapping -- token_stores: Smart table mapping metadata to stores - - -
struct AssetMappingPool has store, key
-
- - - -
-Fields - - -
-token_stores: smart_table::SmartTable<object::Object<fungible_asset::Metadata>, asset_mapping::AssetMappingStore> +fungible_metadata: object::Object<fungible_asset::Metadata>
@@ -136,15 +109,15 @@ Contains:
- + -## Resource `AssetMappingCoinType` +## Resource `AssetMappingPool` AssetMappingCoinType represents a mapping that from old version token types to now version asset stores eg. 0x1::STC::STC -> 0x1::starcoin_coin::STC -
struct AssetMappingCoinType has store, key
+
struct AssetMappingPool has store, key
 
@@ -155,7 +128,7 @@ eg. 0x1::STC::STC -> 0x1::starcoin_coin::STC
-token_mapping: smart_table::SmartTable<string::String, object::Object<fungible_asset::Metadata>> +token_mapping: smart_table::SmartTable<string::String, asset_mapping::AssetMappingStore>
@@ -170,11 +143,20 @@ eg. 0x1::STC::STC -> 0x1::starcoin_coin::STC ## Constants + + + + +
const EINVALID_ASSET_MAPPING_POOL: u64 = 104;
+
+ + + -
const EINVALID_NOT_PROOF: u64 = 102;
+
const EINVALID_NOT_PROOF: u64 = 103;
 
@@ -222,14 +204,11 @@ Verifies the framework signer and creates a new AssetMappingPool signer::address_of(framework) == system_addresses::get_starcoin_framework(), error::unauthenticated(EINVALID_SIGNER) ); - move_to(framework, AssetMappingPool { - token_stores: smart_table::new<Object<Metadata>, AssetMappingStore>(), - }); move_to(framework, AssetMappingProof { proof_root, }); - move_to(framework, AssetMappingCoinType { - token_mapping: smart_table::new<string::String, Object<Metadata>>(), + move_to(framework, AssetMappingPool { + token_mapping: smart_table::new<string::String, AssetMappingStore>(), }) }
@@ -250,7 +229,7 @@ Requirements: - Converts coin to fungible asset and stores it -
public fun create_store_from_coin<T: key>(token_issuer: &signer, old_token_str: string::String, coin: coin::Coin<T>)
+
public fun create_store_from_coin<T: key>(token_issuer: &signer, old_token_str: vector<u8>, coin: coin::Coin<T>)
 
@@ -261,9 +240,11 @@ Requirements:
public fun create_store_from_coin<T: key>(
     token_issuer: &signer,
-    old_token_str: string::String,
+    old_token_str: vector<u8>,
     coin: coin::Coin<T>
-) acquires AssetMappingPool, AssetMappingCoinType {
+) acquires AssetMappingPool {
+    debug::print(&string::utf8(b"asset_mapping::create_store_from_coin | entered"));
+
     let token_issuer_addr = signer::address_of(token_issuer);
     assert!(
         token_issuer_addr == stc_util::token_issuer<T>(),
@@ -271,20 +252,43 @@ Requirements:
     );
 
     let fungible_asset = coin::coin_to_fungible_asset(coin);
-    let token_stores =
-        &mut borrow_global_mut<AssetMappingPool>(system_addresses::get_starcoin_framework()).token_stores;
 
-    let (metadata, fungible_store, extend_ref) = create_store_for_type<T>(token_issuer);
-    fungible_asset::deposit(fungible_store, fungible_asset);
-    smart_table::add(token_stores, metadata, AssetMappingStore {
-        extend_ref,
+    let (
+        fungible_metadata,
         fungible_store,
-    });
+        extend_ref
+    ) = create_store_for_coin_type<T>(token_issuer);
+
+    debug::print(&string::utf8(b"asset_mapping::create_store_from_coin | created token store"));
+    debug::print(&fungible_store);
+
+    fungible_asset::deposit(fungible_store, fungible_asset);
+
+    // debug::print(&string::utf8(b"asset_mapping::create_store_from_coin | withdraw test begin"));
+    // {
+    //     let test_fa = fungible_asset::withdraw(
+    //         &object::generate_signer_for_extending(&extend_ref),
+    //         fungible_store,
+    //         10000
+    //     );
+    //     assert!(fungible_asset::amount(&test_fa) == 10000, 10000);
+    //     fungible_asset::deposit(fungible_store, test_fa);
+    // };
+    // debug::print(&string::utf8(b"asset_mapping::create_store_from_coin | withdraw test end"));
 
     // Add token mapping coin type
     let asset_coin_type =
-        borrow_global_mut<AssetMappingCoinType>(system_addresses::get_starcoin_framework());
-    smart_table::add(&mut asset_coin_type.token_mapping, old_token_str, metadata);
+        borrow_global_mut<AssetMappingPool>(system_addresses::get_starcoin_framework());
+    smart_table::add(
+        &mut asset_coin_type.token_mapping,
+        string::utf8(old_token_str),
+        AssetMappingStore {
+            fungible_store,
+            fungible_metadata,
+            extend_ref,
+        }
+    );
+    debug::print(&string::utf8(b"asset_mapping::create_store_from_coin | exited"));
 }
 
@@ -292,9 +296,9 @@ Requirements: - + -## Function `create_store_for_type` +## Function `create_store_for_coin_type` Creates a store for a specific token type @param framework - The framework signer @@ -304,7 +308,7 @@ Creates a store for a specific token type - extend_ref: Extension reference for the store -
fun create_store_for_type<T>(framework: &signer): (object::Object<fungible_asset::Metadata>, object::Object<fungible_asset::FungibleStore>, object::ExtendRef)
+
fun create_store_for_coin_type<T>(framework: &signer): (object::Object<fungible_asset::Metadata>, object::Object<fungible_asset::FungibleStore>, object::ExtendRef)
 
@@ -313,8 +317,8 @@ Creates a store for a specific token type Implementation -
fun create_store_for_type<T>(framework: &signer): (Object<Metadata>, Object<FungibleStore>, ExtendRef) {
-    debug::print(&std::string::utf8(b"asset_mapping::create_store_for_type | entered"));
+
fun create_store_for_coin_type<T>(framework: &signer): (Object<Metadata>, Object<FungibleStore>, ExtendRef) {
+    debug::print(&std::string::utf8(b"asset_mapping::create_store_for_type | entered"));
 
     let metadata = coin::ensure_paired_metadata<T>();
     let construct_ref = object::create_object_from_account(framework);
@@ -323,7 +327,7 @@ Creates a store for a specific token type
 
     // Generate extend reference
     let extend_ref = object::generate_extend_ref(&construct_ref);
-    debug::print(&std::string::utf8(b"asset_mapping::create_store_for_type | exited"));
+    debug::print(&std::string::utf8(b"asset_mapping::create_store_for_type | exited"));
 
     (metadata, store, extend_ref)
 }
@@ -333,15 +337,15 @@ Creates a store for a specific token type
 
 
 
-
+
 
-## Function `balance`
+## Function `fungible_store_balance`
 
 Retrieves the balance for a specific token type
 @returns Current balance of the token in the mapping pool
 
 
-
fun balance<T>(): u64
+
fun fungible_store_balance(old_asset_str: vector<u8>): u64
 
@@ -350,10 +354,12 @@ Retrieves the balance for a specific token type Implementation -
fun balance<T>(): u64 acquires AssetMappingPool {
-    let metadata = coin::ensure_paired_metadata<T>();
+
fun fungible_store_balance(old_asset_str: vector<u8>): u64 acquires AssetMappingPool {
+    // let metadata = coin::ensure_paired_metadata<T>();
     let pool = borrow_global<AssetMappingPool>(system_addresses::get_starcoin_framework());
-    fungible_asset::balance(smart_table::borrow(&pool.token_stores, metadata).fungible_store)
+    let fungible_asset_store =
+        smart_table::borrow(&pool.token_mapping, string::utf8(old_asset_str)).fungible_store;
+    fungible_asset::balance(fungible_asset_store)
 }
 
@@ -384,7 +390,7 @@ Retrieves the balance for a specific token type proof_value_hash: vector<u8>, proof_siblings: vector<u8>, amount: u64 -) acquires AssetMappingPool, AssetMappingCoinType, AssetMappingProof { +) acquires AssetMappingPool, AssetMappingProof { assert!( exists<AssetMappingProof>(system_addresses::get_starcoin_framework()), error::invalid_state(EINVALID_PROOF_ROOT) @@ -392,7 +398,7 @@ Retrieves the balance for a specific token type // Verify that the token type of the request mapping is the passed-in verification type assert!( - calculation_proof(proof_path_hash, proof_value_hash, split_proof_siblings_from_vec(proof_siblings)), + calculation_proof(proof_path_hash, proof_value_hash, starcoin_proof_verifier::split(proof_siblings)), error::unauthenticated(EINVALID_NOT_PROOF) ); @@ -418,7 +424,7 @@ Requirements: - Sufficient balance must exist -
fun assign_to_account(token_issuer: &signer, receiper: address, old_token_str: vector<u8>, amount: u64)
+
public fun assign_to_account(token_issuer: &signer, receiver: address, old_token_str: vector<u8>, amount: u64)
 
@@ -427,50 +433,43 @@ Requirements: Implementation -
fun assign_to_account(
+
public fun assign_to_account(
     token_issuer: &signer,
-    receiper: address,
+    receiver: address,
     old_token_str: vector<u8>,
     amount: u64
-) acquires AssetMappingPool, AssetMappingCoinType {
-    let coin_type_mapping = borrow_global<AssetMappingCoinType>(system_addresses::get_starcoin_framework());
-    let metadata = smart_table::borrow(&coin_type_mapping.token_mapping, string::utf8(old_token_str));
-    let mapping_pool = borrow_global_mut<AssetMappingPool>(signer::address_of(token_issuer));
-    let mapping_store = smart_table::borrow_mut(
-        &mut mapping_pool.token_stores,
-        *metadata
-    );
-
-    let store_signer = object::generate_signer_for_extending(&mapping_store.extend_ref);
-    fungible_asset::deposit(
-        primary_fungible_store::ensure_primary_store_exists(receiper, *metadata),
-        fungible_asset::withdraw(&store_signer, mapping_store.fungible_store, amount)
-    )
-}
-
- - - - - - - -## Function `split_proof_siblings_from_vec` - - - -
fun split_proof_siblings_from_vec(_siblings: vector<u8>): vector<vector<u8>>
-
+) acquires AssetMappingPool { + debug::print(&string::utf8(b"asset_mapping::assign_to_account | entered")); + assert!( + exists<AssetMappingPool>(signer::address_of(token_issuer)), + error::invalid_state(EINVALID_ASSET_MAPPING_POOL) + ); + let coin_type_mapping = + borrow_global<AssetMappingPool>(system_addresses::get_starcoin_framework()); + debug::print(&string::utf8(b"asset_mapping::assign_to_account | coin_type_mapping")); -
-Implementation + let mapping_store = smart_table::borrow( + &coin_type_mapping.token_mapping, + string::utf8(old_token_str) + ); + debug::print(&string::utf8(b"asset_mapping::assign_to_account | metadata")); + debug::print(&fungible_asset::is_frozen(mapping_store.fungible_store)); + + debug::print(&string::utf8(b"asset_mapping::assign_to_account | fungible_asset::withdraw:")); + let mapping_fa = fungible_asset::withdraw( + &object::generate_signer_for_extending(&mapping_store.extend_ref), + mapping_store.fungible_store, + amount + ); + debug::print(&string::utf8(b"asset_mapping::assign_to_account | Getting receiver fungible store: ")); + let target_store = + primary_fungible_store::ensure_primary_store_exists(receiver, mapping_store.fungible_metadata); -
fun split_proof_siblings_from_vec(_siblings: vector<u8>): vector<vector<u8>> {
-    // TODO(BobOng): implement this function
-    vector::empty()
+    fungible_asset::deposit(target_store, mapping_fa);
+    debug::print(&string::utf8(b"asset_mapping::assign_to_account | exited"));
 }
 
diff --git a/vm/framework/starcoin-framework/doc/coin.md b/vm/framework/starcoin-framework/doc/coin.md index 5ed62c57e5..b93e67c8ee 100644 --- a/vm/framework/starcoin-framework/doc/coin.md +++ b/vm/framework/starcoin-framework/doc/coin.md @@ -1450,12 +1450,25 @@ Create STC pairing by passing StarcoinCoin. let map = borrow_global_mut<CoinConversionMap>(@starcoin_framework); let type = type_info::type_of<CoinType>(); if (!table::contains(&map.coin_to_fungible_asset_map, type)) { + debug::print( + &std::string::utf8(b"coin::create_and_return_paired_metadata_if_not_exist | map not contain type") + ); let is_stc = is_stc<CoinType>(); assert!(!is_stc || allow_stc_creation, error::invalid_state(EAPT_PAIRING_IS_NOT_ENABLED)); let metadata_object_cref = if (is_stc) { + debug::print( + &std::string::utf8( + b"coin::create_and_return_paired_metadata_if_not_exist | type is stc, create sticky object at 0x1" + ) + ); object::create_sticky_object_at_address(@starcoin_framework, @starcoin_fungible_asset) } else { + debug::print( + &std::string::utf8( + b"coin::create_and_return_paired_metadata_if_not_exist | type is not stc, create new asset sub object" + ) + ); object::create_named_object( &create_signer::create_signer(@starcoin_fungible_asset), *string::bytes(&type_info::type_name<CoinType>()) diff --git a/vm/framework/starcoin-framework/doc/fungible_asset.md b/vm/framework/starcoin-framework/doc/fungible_asset.md index be6434bb05..38d8d52948 100644 --- a/vm/framework/starcoin-framework/doc/fungible_asset.md +++ b/vm/framework/starcoin-framework/doc/fungible_asset.md @@ -2593,6 +2593,9 @@ Applications can use this to create multiple stores for isolating fungible asset constructor_ref: &ConstructorRef, metadata: Object<T>, ): Object<FungibleStore> { + debug::print(&string::utf8(b"fungible_asset::create_store | entered")); + debug::print(constructor_ref); + let store_obj = &object::generate_signer(constructor_ref); move_to(store_obj, FungibleStore { metadata: object::convert(metadata), @@ -2610,6 +2613,8 @@ Applications can use this to create multiple stores for isolating fungible asset }); }; + debug::print(&string::utf8(b"fungible_asset::create_store | exited")); + object::object_from_constructor_ref<FungibleStore>(constructor_ref) }
@@ -2635,6 +2640,9 @@ Used to delete a store. Requires the store to be completely empty prior to remo
public fun remove_store(delete_ref: &DeleteRef) acquires FungibleStore, FungibleAssetEvents, ConcurrentFungibleBalance {
+    debug::print(&string::utf8(b"fungible_asset::remove_store | entered"));
+    debug::print(delete_ref);
+
     let store = &object::object_from_delete_ref<FungibleStore>(delete_ref);
     let addr = object::object_address(store);
     let FungibleStore { metadata: _, balance, frozen: _ }
@@ -2657,6 +2665,7 @@ Used to delete a store.  Requires the store to be completely empty prior to remo
         event::destroy_handle(withdraw_events);
         event::destroy_handle(frozen_events);
     };
+    debug::print(&string::utf8(b"fungible_asset::remove_store | exited"));
 }
 
@@ -2779,8 +2788,11 @@ Deposit amount of the fungible asset to store.
public fun deposit<T: key>(store: Object<T>, fa: FungibleAsset) acquires FungibleStore, DispatchFunctionStore, ConcurrentFungibleBalance {
+    debug::print(&string::utf8(b"fungible_asset::deposit | entered"));
+    debug::print(&store);
     deposit_sanity_check(store, true);
     deposit_internal(object::object_address(&store), fa);
+    debug::print(&string::utf8(b"fungible_asset::deposit | exited"));
 }
 
@@ -3564,8 +3576,11 @@ Decrease the supply of a fungible asset by burning.
inline fun borrow_store_resource<T: key>(store: &Object<T>): &FungibleStore acquires FungibleStore {
+    debug::print(&string::utf8(b"fungible_asset::borrow_store_resource | entered"));
     let store_addr = object::object_address(store);
+    debug::print(&store_addr);
     assert!(exists<FungibleStore>(store_addr), error::not_found(EFUNGIBLE_STORE_EXISTENCE));
+    debug::print(&string::utf8(b"fungible_asset::borrow_store_resource | exited"));
     borrow_global<FungibleStore>(store_addr)
 }
 
diff --git a/vm/framework/starcoin-framework/doc/object.md b/vm/framework/starcoin-framework/doc/object.md index 3a043c2b8c..d9bc8d748e 100644 --- a/vm/framework/starcoin-framework/doc/object.md +++ b/vm/framework/starcoin-framework/doc/object.md @@ -139,6 +139,7 @@ make it so that a reference to a global object can be returned from a function. use 0x1::bcs; use 0x1::bcs_util; use 0x1::create_signer; +use 0x1::debug; use 0x1::error; use 0x1::event; use 0x1::features; @@ -146,6 +147,7 @@ make it so that a reference to a global object can be returned from a function. use 0x1::guid; use 0x1::hash; use 0x1::signer; +use 0x1::string; use 0x1::transaction_context; use 0x1::vector;
@@ -1329,7 +1331,9 @@ doesn't have the same bottlenecks. object: address, can_delete: bool, ): ConstructorRef { - // debug::print(&string::utf8(b"object::create_object_internal | entered")); + debug::print(&string::utf8(b"object::create_object_internal | entered")); + debug::print(&creator_address); + debug::print(&object); assert!(!exists<ObjectCore>(object), error::already_exists(EOBJECT_EXISTS)); @@ -1347,7 +1351,7 @@ doesn't have the same bottlenecks. }, ); - // debug::print(&string::utf8(b"object::create_object_internal | exited")); + debug::print(&string::utf8(b"object::create_object_internal | exited")); ConstructorRef { self: object, can_delete } }
diff --git a/vm/framework/starcoin-framework/doc/primary_fungible_store.md b/vm/framework/starcoin-framework/doc/primary_fungible_store.md index 5043b16dca..347e673d26 100644 --- a/vm/framework/starcoin-framework/doc/primary_fungible_store.md +++ b/vm/framework/starcoin-framework/doc/primary_fungible_store.md @@ -117,6 +117,7 @@ so that users can easily deposit/withdraw/transfer fungible assets. icon_uri: String, project_uri: String, ) { + debug::print(&string::utf8(b"primary_fungible_store::create_primary_store_enabled_fungible_asset | entered")); fungible_asset::add_fungibility( constructor_ref, maximum_supply, @@ -130,6 +131,7 @@ so that users can easily deposit/withdraw/transfer fungible assets. move_to(metadata_obj, DeriveRefPod { metadata_derive_ref: object::generate_derive_ref(constructor_ref), }); + debug::print(&string::utf8(b"primary_fungible_store::create_primary_store_enabled_fungible_asset | exited")); }
@@ -158,6 +160,8 @@ Ensure that the primary store object for the given address exists. If it doesn't metadata: Object<T>, ): Object<FungibleStore> acquires DeriveRefPod { debug::print(&string::utf8(b"primary_fungible_store::ensure_primary_store_exists | entered")); + debug::print(&owner); + let store_addr = primary_store_address(owner, metadata); let ret = if (fungible_asset::store_exists(store_addr)) { object::address_to_object(store_addr) @@ -198,13 +202,22 @@ Create a primary store object to hold fungible asset for the given address. debug::print(&metadata); let metadata_addr = object::object_address(&metadata); + debug::print(&string::utf8(b"primary_fungible_store::create_primary_store | 1")); + debug::print(&metadata_addr); + object::address_to_object<Metadata>(metadata_addr); + + debug::print(&string::utf8(b"primary_fungible_store::create_primary_store | 2")); let derive_ref = &borrow_global<DeriveRefPod>(metadata_addr).metadata_derive_ref; let constructor_ref = &object::create_user_derived_object(owner_addr, derive_ref); + + debug::print(&string::utf8(b"primary_fungible_store::create_primary_store | 3")); // Disable ungated transfer as deterministic stores shouldn't be transferrable. let transfer_ref = &object::generate_transfer_ref(constructor_ref); object::disable_ungated_transfer(transfer_ref); + debug::print(&string::utf8(b"primary_fungible_store::create_primary_store | 4")); + let ret = fungible_asset::create_store(constructor_ref, metadata); debug::print(&string::utf8(b"primary_fungible_store::create_primary_store | exited")); debug::print(&ret); diff --git a/vm/framework/starcoin-framework/doc/starcoin_account.md b/vm/framework/starcoin-framework/doc/starcoin_account.md index a8bd45c9de..66ead12446 100644 --- a/vm/framework/starcoin-framework/doc/starcoin_account.md +++ b/vm/framework/starcoin-framework/doc/starcoin_account.md @@ -693,7 +693,12 @@ Ensure that APT Primary FungibleStore exists (and create if it doesn't) if (fungible_asset::store_exists(store_addr)) { store_addr } else { - object::object_address(&primary_fungible_store::create_primary_store(owner, object::address_to_object<Metadata>(@starcoin_fungible_asset))) + object::object_address( + &primary_fungible_store::create_primary_store( + owner, + object::address_to_object<Metadata>(@starcoin_fungible_asset) + ) + ) } }
diff --git a/vm/framework/starcoin-framework/doc/stc_genesis.md b/vm/framework/starcoin-framework/doc/stc_genesis.md index cd89e4268f..9d59577a9d 100644 --- a/vm/framework/starcoin-framework/doc/stc_genesis.md +++ b/vm/framework/starcoin-framework/doc/stc_genesis.md @@ -387,11 +387,11 @@ Overall governance allocation strategy: time_mint_stc_amount: u128, time_mint_stc_period: u64, ) { - // TODO(BobOng): To confirm how many STC put into asset mapping pool - let asset_mapping_coin = coin::extract<STC>(&mut total_supply_stc, 1000000000); + // TODO(BobOng): [asset-mapping] To confirm how many STC put into asset mapping pool, now is 10,000,000,000 STC + let asset_mapping_coin = coin::extract<STC>(&mut total_supply_stc, 100000000000000000); asset_mapping::create_store_from_coin<STC>( starcoin_framework, - std::string::utf8(b"0x1::STC::STC"), + b"0x1::STC::STC", asset_mapping_coin ); diff --git a/vm/framework/starcoin-framework/integration-tests/asset_mapping/basic.exp b/vm/framework/starcoin-framework/integration-tests/asset_mapping/basic.exp new file mode 100644 index 0000000000..f616e9079c --- /dev/null +++ b/vm/framework/starcoin-framework/integration-tests/asset_mapping/basic.exp @@ -0,0 +1,17 @@ +processed 4 tasks + +task 3 'run'. lines 7-19: +{ + "gas_used": 2260938, + "status": { + "MoveAbort": { + "location": { + "Module": { + "address": "0x00000000000000000000000000000001", + "name": "fungible_asset" + } + }, + "abort_code": "393239" + } + } +} diff --git a/vm/framework/starcoin-framework/integration-tests/asset_mapping/basic.move b/vm/framework/starcoin-framework/integration-tests/asset_mapping/basic.move new file mode 100644 index 0000000000..b8e6551594 --- /dev/null +++ b/vm/framework/starcoin-framework/integration-tests/asset_mapping/basic.move @@ -0,0 +1,19 @@ +//# init -n dev + +//# faucet --addr alice --amount 100 + +//# faucet --addr Genesis + +//# run --signers Genesis +script { + use starcoin_framework::starcoin_coin::STC; + use starcoin_framework::coin; + use starcoin_framework::asset_mapping; + + fun test_asset_mapping_assign_to_account_with_proof(framework: signer) { + assert!(coin::balance(@alice) == 100, 10001); + asset_mapping::assign_to_account(&framework, @alice, b"0x1::STC::STC", 100); + assert!(coin::balance(@alice) == 200, 10002); + } +} +// check: EXECUTED \ No newline at end of file diff --git a/vm/framework/starcoin-framework/sources/asset_mapping.move b/vm/framework/starcoin-framework/sources/asset_mapping.move index 2ffa35260f..eb83046f51 100644 --- a/vm/framework/starcoin-framework/sources/asset_mapping.move +++ b/vm/framework/starcoin-framework/sources/asset_mapping.move @@ -7,7 +7,6 @@ module starcoin_framework::asset_mapping { use std::error; use std::signer; use std::string; - use std::vector; use starcoin_framework::coin; use starcoin_framework::fungible_asset::{Self, FungibleStore, Metadata}; @@ -19,6 +18,8 @@ module starcoin_framework::asset_mapping { use starcoin_std::debug; use starcoin_std::smart_table; + #[test_only] + use std::vector; #[test_only] use starcoin_framework::account; #[test_only] @@ -32,18 +33,11 @@ module starcoin_framework::asset_mapping { /// Contains: /// - extend_ref: Reference for extending object capabilities /// - fungible_store: The actual store holding fungible assets + /// - fungible_metadata: The type of fungible assets struct AssetMappingStore has key, store { extend_ref: ExtendRef, fungible_store: Object, - } - - /// AssetMappingPool manages a collection of asset mapping stores - /// Contains: - /// - proof_root: Root hash for proof verification - /// - anchor_height: Block height anchor for the mapping - /// - token_stores: Smart table mapping metadata to stores - struct AssetMappingPool has key, store { - token_stores: smart_table::SmartTable, AssetMappingStore>, + fungible_metadata: Object, } struct AssetMappingProof has key, store { @@ -53,14 +47,15 @@ module starcoin_framework::asset_mapping { /// AssetMappingCoinType represents a mapping that from old version token types to now version asset stores /// eg. 0x1::STC::STC -> 0x1::starcoin_coin::STC /// - struct AssetMappingCoinType has key, store { - token_mapping: smart_table::SmartTable>, + struct AssetMappingPool has key, store { + token_mapping: smart_table::SmartTable, } /// Error code for invalid signer const EINVALID_SIGNER: u64 = 101; - const EINVALID_NOT_PROOF: u64 = 102; const EINVALID_PROOF_ROOT: u64 = 102; + const EINVALID_NOT_PROOF: u64 = 103; + const EINVALID_ASSET_MAPPING_POOL: u64 = 104; /// Initializes the asset mapping pool /// @param framework - The framework signer @@ -71,14 +66,11 @@ module starcoin_framework::asset_mapping { signer::address_of(framework) == system_addresses::get_starcoin_framework(), error::unauthenticated(EINVALID_SIGNER) ); - move_to(framework, AssetMappingPool { - token_stores: smart_table::new, AssetMappingStore>(), - }); move_to(framework, AssetMappingProof { proof_root, }); - move_to(framework, AssetMappingCoinType { - token_mapping: smart_table::new>(), + move_to(framework, AssetMappingPool { + token_mapping: smart_table::new(), }) } @@ -90,9 +82,11 @@ module starcoin_framework::asset_mapping { /// - Converts coin to fungible asset and stores it public fun create_store_from_coin( token_issuer: &signer, - old_token_str: string::String, + old_token_str: vector, coin: coin::Coin - ) acquires AssetMappingPool, AssetMappingCoinType { + ) acquires AssetMappingPool { + debug::print(&string::utf8(b"asset_mapping::create_store_from_coin | entered")); + let token_issuer_addr = signer::address_of(token_issuer); assert!( token_issuer_addr == stc_util::token_issuer(), @@ -100,20 +94,31 @@ module starcoin_framework::asset_mapping { ); let fungible_asset = coin::coin_to_fungible_asset(coin); - let token_stores = - &mut borrow_global_mut(system_addresses::get_starcoin_framework()).token_stores; - let (metadata, fungible_store, extend_ref) = create_store_for_type(token_issuer); - fungible_asset::deposit(fungible_store, fungible_asset); - smart_table::add(token_stores, metadata, AssetMappingStore { - extend_ref, + let ( + fungible_metadata, fungible_store, - }); + extend_ref + ) = create_store_for_coin_type(token_issuer); + + debug::print(&string::utf8(b"asset_mapping::create_store_from_coin | created token store")); + debug::print(&fungible_store); + + fungible_asset::deposit(fungible_store, fungible_asset); // Add token mapping coin type let asset_coin_type = - borrow_global_mut(system_addresses::get_starcoin_framework()); - smart_table::add(&mut asset_coin_type.token_mapping, old_token_str, metadata); + borrow_global_mut(system_addresses::get_starcoin_framework()); + smart_table::add( + &mut asset_coin_type.token_mapping, + string::utf8(old_token_str), + AssetMappingStore { + fungible_store, + fungible_metadata, + extend_ref, + } + ); + debug::print(&string::utf8(b"asset_mapping::create_store_from_coin | exited")); } /// Creates a store for a specific token type @@ -122,7 +127,7 @@ module starcoin_framework::asset_mapping { /// - metadata: Token metadata object /// - store: Created fungible store /// - extend_ref: Extension reference for the store - fun create_store_for_type(framework: &signer): (Object, Object, ExtendRef) { + fun create_store_for_coin_type(framework: &signer): (Object, Object, ExtendRef) { debug::print(&std::string::utf8(b"asset_mapping::create_store_for_type | entered")); let metadata = coin::ensure_paired_metadata(); @@ -139,10 +144,12 @@ module starcoin_framework::asset_mapping { /// Retrieves the balance for a specific token type /// @returns Current balance of the token in the mapping pool - fun balance(): u64 acquires AssetMappingPool { - let metadata = coin::ensure_paired_metadata(); + fun fungible_store_balance(old_asset_str: vector): u64 acquires AssetMappingPool { + // let metadata = coin::ensure_paired_metadata(); let pool = borrow_global(system_addresses::get_starcoin_framework()); - fungible_asset::balance(smart_table::borrow(&pool.token_stores, metadata).fungible_store) + let fungible_asset_store = + smart_table::borrow(&pool.token_mapping, string::utf8(old_asset_str)).fungible_store; + fungible_asset::balance(fungible_asset_store) } public entry fun assign_to_account_with_proof( @@ -153,7 +160,7 @@ module starcoin_framework::asset_mapping { proof_value_hash: vector, proof_siblings: vector, amount: u64 - ) acquires AssetMappingPool, AssetMappingCoinType, AssetMappingProof { + ) acquires AssetMappingPool, AssetMappingProof { assert!( exists(system_addresses::get_starcoin_framework()), error::invalid_state(EINVALID_PROOF_ROOT) @@ -161,7 +168,7 @@ module starcoin_framework::asset_mapping { // Verify that the token type of the request mapping is the passed-in verification type assert!( - calculation_proof(proof_path_hash, proof_value_hash, split_proof_siblings_from_vec(proof_siblings)), + calculation_proof(proof_path_hash, proof_value_hash, starcoin_proof_verifier::split(proof_siblings)), error::unauthenticated(EINVALID_NOT_PROOF) ); @@ -176,30 +183,43 @@ module starcoin_framework::asset_mapping { /// Requirements: /// - Valid proof must be provided /// - Sufficient balance must exist - fun assign_to_account( + public fun assign_to_account( token_issuer: &signer, - receiper: address, + receiver: address, old_token_str: vector, amount: u64 - ) acquires AssetMappingPool, AssetMappingCoinType { - let coin_type_mapping = borrow_global(system_addresses::get_starcoin_framework()); - let metadata = smart_table::borrow(&coin_type_mapping.token_mapping, string::utf8(old_token_str)); - let mapping_pool = borrow_global_mut(signer::address_of(token_issuer)); - let mapping_store = smart_table::borrow_mut( - &mut mapping_pool.token_stores, - *metadata + ) acquires AssetMappingPool { + debug::print(&string::utf8(b"asset_mapping::assign_to_account | entered")); + + assert!( + exists(signer::address_of(token_issuer)), + error::invalid_state(EINVALID_ASSET_MAPPING_POOL) ); - let store_signer = object::generate_signer_for_extending(&mapping_store.extend_ref); - fungible_asset::deposit( - primary_fungible_store::ensure_primary_store_exists(receiper, *metadata), - fungible_asset::withdraw(&store_signer, mapping_store.fungible_store, amount) - ) - } + let coin_type_mapping = + borrow_global(system_addresses::get_starcoin_framework()); + debug::print(&string::utf8(b"asset_mapping::assign_to_account | coin_type_mapping")); + + let mapping_store = smart_table::borrow( + &coin_type_mapping.token_mapping, + string::utf8(old_token_str) + ); + debug::print(&string::utf8(b"asset_mapping::assign_to_account | metadata")); + debug::print(&fungible_asset::is_frozen(mapping_store.fungible_store)); - fun split_proof_siblings_from_vec(_siblings: vector): vector> { - // TODO(BobOng): implement this function - vector::empty() + debug::print(&string::utf8(b"asset_mapping::assign_to_account | fungible_asset::withdraw:")); + let mapping_fa = fungible_asset::withdraw( + &object::generate_signer_for_extending(&mapping_store.extend_ref), + mapping_store.fungible_store, + amount + ); + debug::print(&string::utf8(b"asset_mapping::assign_to_account | Getting receiver fungible store: ")); + + let target_store = + primary_fungible_store::ensure_primary_store_exists(receiver, mapping_store.fungible_metadata); + + fungible_asset::deposit(target_store, mapping_fa); + debug::print(&string::utf8(b"asset_mapping::assign_to_account | exited")); } /// Computes and verifies the provided proof @@ -228,40 +248,47 @@ module starcoin_framework::asset_mapping { fun test_asset_mapping_create_store_from_coin( framework: &signer, alice: &signer - ) acquires AssetMappingPool, AssetMappingCoinType { + ) acquires AssetMappingPool { debug::print(&std::string::utf8(b"asset_mapping::test_asset_mapping_create_store_from_coin | entered")); let amount = 10000000000; Self::initialize(framework, vector::empty()); + debug::print(&std::string::utf8(b"asset_mapping::test_asset_mapping_create_store_from_coin | before create_account_for_test")); // create genesis account account::create_account_for_test(signer::address_of(framework)); + debug::print(&std::string::utf8(b"asset_mapping::test_asset_mapping_create_store_from_coin | starcoin_coin::initialize_for_test")); + let (burn_cap, mint_cap) = starcoin_coin::initialize_for_test(framework); + + debug::print(&std::string::utf8(b"asset_mapping::test_asset_mapping_create_store_from_coin | coin::register(framework)")); coin::register(framework); + + debug::print(&std::string::utf8(b"asset_mapping::test_asset_mapping_create_store_from_coin | starcoin_coin::mint")); starcoin_coin::mint(framework, signer::address_of(framework), amount); + debug::print(&std::string::utf8(b"asset_mapping::test_asset_mapping_create_store_from_coin | after coin::register(framework) and mint")); // Construct Old token string - let old_token_str = string::utf8(b"0x00000000000000000000000000000001::starcoin_coin::STC"); - + let old_token_str = b"0x00000000000000000000000000000001::starcoin_coin::STC"; let coin = coin::withdraw(framework, amount); - create_store_from_coin( + Self::create_store_from_coin( framework, old_token_str, coin ); - assert!(Self::balance() == amount, 10001); + assert!(Self::fungible_store_balance(old_token_str) == amount, 10001); // Assign to alice let alice_addr = signer::address_of(alice); - assign_to_account( + Self::assign_to_account( framework, alice_addr, - *string::bytes(&old_token_str), + old_token_str, amount ); - assert!(Self::balance() == 0, 10002); + assert!(Self::fungible_store_balance(old_token_str) == 0, 10002); let stc_metadata = coin::ensure_paired_metadata(); assert!(primary_fungible_store::balance(alice_addr, stc_metadata) == amount, 10003); diff --git a/vm/framework/starcoin-framework/sources/coin.move b/vm/framework/starcoin-framework/sources/coin.move index acfe84336e..48e2fd6116 100644 --- a/vm/framework/starcoin-framework/sources/coin.move +++ b/vm/framework/starcoin-framework/sources/coin.move @@ -321,12 +321,25 @@ module starcoin_framework::coin { let map = borrow_global_mut(@starcoin_framework); let type = type_info::type_of(); if (!table::contains(&map.coin_to_fungible_asset_map, type)) { + debug::print( + &std::string::utf8(b"coin::create_and_return_paired_metadata_if_not_exist | map not contain type") + ); let is_stc = is_stc(); assert!(!is_stc || allow_stc_creation, error::invalid_state(EAPT_PAIRING_IS_NOT_ENABLED)); let metadata_object_cref = if (is_stc) { + debug::print( + &std::string::utf8( + b"coin::create_and_return_paired_metadata_if_not_exist | type is stc, create sticky object at 0x1" + ) + ); object::create_sticky_object_at_address(@starcoin_framework, @starcoin_fungible_asset) } else { + debug::print( + &std::string::utf8( + b"coin::create_and_return_paired_metadata_if_not_exist | type is not stc, create new asset sub object" + ) + ); object::create_named_object( &create_signer::create_signer(@starcoin_fungible_asset), *string::bytes(&type_info::type_name()) diff --git a/vm/framework/starcoin-framework/sources/fungible_asset.move b/vm/framework/starcoin-framework/sources/fungible_asset.move index 85d56e2483..54089ea199 100644 --- a/vm/framework/starcoin-framework/sources/fungible_asset.move +++ b/vm/framework/starcoin-framework/sources/fungible_asset.move @@ -746,6 +746,9 @@ module starcoin_framework::fungible_asset { constructor_ref: &ConstructorRef, metadata: Object, ): Object { + debug::print(&string::utf8(b"fungible_asset::create_store | entered")); + debug::print(constructor_ref); + let store_obj = &object::generate_signer(constructor_ref); move_to(store_obj, FungibleStore { metadata: object::convert(metadata), @@ -763,11 +766,16 @@ module starcoin_framework::fungible_asset { }); }; + debug::print(&string::utf8(b"fungible_asset::create_store | exited")); + object::object_from_constructor_ref(constructor_ref) } /// Used to delete a store. Requires the store to be completely empty prior to removing it public fun remove_store(delete_ref: &DeleteRef) acquires FungibleStore, FungibleAssetEvents, ConcurrentFungibleBalance { + debug::print(&string::utf8(b"fungible_asset::remove_store | entered")); + debug::print(delete_ref); + let store = &object::object_from_delete_ref(delete_ref); let addr = object::object_address(store); let FungibleStore { metadata: _, balance, frozen: _ } @@ -790,6 +798,7 @@ module starcoin_framework::fungible_asset { event::destroy_handle(withdraw_events); event::destroy_handle(frozen_events); }; + debug::print(&string::utf8(b"fungible_asset::remove_store | exited")); } /// Withdraw `amount` of the fungible asset from `store` by the owner. @@ -832,8 +841,11 @@ module starcoin_framework::fungible_asset { /// Deposit `amount` of the fungible asset to `store`. public fun deposit(store: Object, fa: FungibleAsset) acquires FungibleStore, DispatchFunctionStore, ConcurrentFungibleBalance { + debug::print(&string::utf8(b"fungible_asset::deposit | entered")); + debug::print(&store); deposit_sanity_check(store, true); deposit_internal(object::object_address(&store), fa); + debug::print(&string::utf8(b"fungible_asset::deposit | exited")); } /// Mint the specified `amount` of the fungible asset. @@ -1137,8 +1149,11 @@ module starcoin_framework::fungible_asset { } inline fun borrow_store_resource(store: &Object): &FungibleStore acquires FungibleStore { + debug::print(&string::utf8(b"fungible_asset::borrow_store_resource | entered")); let store_addr = object::object_address(store); + debug::print(&store_addr); assert!(exists(store_addr), error::not_found(EFUNGIBLE_STORE_EXISTENCE)); + debug::print(&string::utf8(b"fungible_asset::borrow_store_resource | exited")); borrow_global(store_addr) } diff --git a/vm/framework/starcoin-framework/sources/object.move b/vm/framework/starcoin-framework/sources/object.move index eab7b2c453..23671a14ad 100644 --- a/vm/framework/starcoin-framework/sources/object.move +++ b/vm/framework/starcoin-framework/sources/object.move @@ -19,6 +19,7 @@ module starcoin_framework::object { use std::error; use std::hash; use std::signer; + use std::string; use std::vector; use starcoin_framework::account; @@ -27,10 +28,9 @@ module starcoin_framework::object { use starcoin_framework::event; use starcoin_framework::guid; use starcoin_framework::transaction_context; + use starcoin_std::debug; use starcoin_std::from_bcs; - #[test_only] - use std::debug; #[test_only] use std::option::{Self, Option}; @@ -332,7 +332,9 @@ module starcoin_framework::object { object: address, can_delete: bool, ): ConstructorRef { - // debug::print(&string::utf8(b"object::create_object_internal | entered")); + debug::print(&string::utf8(b"object::create_object_internal | entered")); + debug::print(&creator_address); + debug::print(&object); assert!(!exists(object), error::already_exists(EOBJECT_EXISTS)); @@ -350,7 +352,7 @@ module starcoin_framework::object { }, ); - // debug::print(&string::utf8(b"object::create_object_internal | exited")); + debug::print(&string::utf8(b"object::create_object_internal | exited")); ConstructorRef { self: object, can_delete } } diff --git a/vm/framework/starcoin-framework/sources/primary_fungible_store.move b/vm/framework/starcoin-framework/sources/primary_fungible_store.move index a2cf51daa2..eb5afa7e67 100644 --- a/vm/framework/starcoin-framework/sources/primary_fungible_store.move +++ b/vm/framework/starcoin-framework/sources/primary_fungible_store.move @@ -41,6 +41,7 @@ module starcoin_framework::primary_fungible_store { icon_uri: String, project_uri: String, ) { + debug::print(&string::utf8(b"primary_fungible_store::create_primary_store_enabled_fungible_asset | entered")); fungible_asset::add_fungibility( constructor_ref, maximum_supply, @@ -54,6 +55,7 @@ module starcoin_framework::primary_fungible_store { move_to(metadata_obj, DeriveRefPod { metadata_derive_ref: object::generate_derive_ref(constructor_ref), }); + debug::print(&string::utf8(b"primary_fungible_store::create_primary_store_enabled_fungible_asset | exited")); } /// Ensure that the primary store object for the given address exists. If it doesn't, create it. @@ -62,6 +64,8 @@ module starcoin_framework::primary_fungible_store { metadata: Object, ): Object acquires DeriveRefPod { debug::print(&string::utf8(b"primary_fungible_store::ensure_primary_store_exists | entered")); + debug::print(&owner); + let store_addr = primary_store_address(owner, metadata); let ret = if (fungible_asset::store_exists(store_addr)) { object::address_to_object(store_addr) @@ -82,13 +86,22 @@ module starcoin_framework::primary_fungible_store { debug::print(&metadata); let metadata_addr = object::object_address(&metadata); + debug::print(&string::utf8(b"primary_fungible_store::create_primary_store | 1")); + debug::print(&metadata_addr); + object::address_to_object(metadata_addr); + + debug::print(&string::utf8(b"primary_fungible_store::create_primary_store | 2")); let derive_ref = &borrow_global(metadata_addr).metadata_derive_ref; let constructor_ref = &object::create_user_derived_object(owner_addr, derive_ref); + + debug::print(&string::utf8(b"primary_fungible_store::create_primary_store | 3")); // Disable ungated transfer as deterministic stores shouldn't be transferrable. let transfer_ref = &object::generate_transfer_ref(constructor_ref); object::disable_ungated_transfer(transfer_ref); + debug::print(&string::utf8(b"primary_fungible_store::create_primary_store | 4")); + let ret = fungible_asset::create_store(constructor_ref, metadata); debug::print(&string::utf8(b"primary_fungible_store::create_primary_store | exited")); debug::print(&ret); diff --git a/vm/framework/starcoin-framework/sources/starcoin_account.move b/vm/framework/starcoin-framework/sources/starcoin_account.move index 95987c7b35..f14e941bea 100644 --- a/vm/framework/starcoin-framework/sources/starcoin_account.move +++ b/vm/framework/starcoin-framework/sources/starcoin_account.move @@ -246,7 +246,12 @@ module starcoin_framework::starcoin_account { if (fungible_asset::store_exists(store_addr)) { store_addr } else { - object::object_address(&primary_fungible_store::create_primary_store(owner, object::address_to_object(@starcoin_fungible_asset))) + object::object_address( + &primary_fungible_store::create_primary_store( + owner, + object::address_to_object(@starcoin_fungible_asset) + ) + ) } } diff --git a/vm/framework/starcoin-framework/sources/starcoin_coin.move b/vm/framework/starcoin-framework/sources/starcoin_coin.move index 56776a12fb..6b52b84303 100644 --- a/vm/framework/starcoin-framework/sources/starcoin_coin.move +++ b/vm/framework/starcoin-framework/sources/starcoin_coin.move @@ -156,6 +156,8 @@ module starcoin_framework::starcoin_coin { use starcoin_framework::aggregator_factory; #[test_only] use starcoin_framework::fungible_asset::FungibleAsset; + #[test_only] + use starcoin_std::debug; #[test_only] public fun mint_stc_fa_for_test(amount: u64): FungibleAsset acquires MintCapStore { @@ -185,10 +187,13 @@ module starcoin_framework::starcoin_coin { #[test_only] public fun initialize_for_test(starcoin_framework: &signer): (BurnCapability, MintCapability) { + debug::print(&string::utf8(b"starcoin_coin::initialize_for_test | entered")); aggregator_factory::initialize_aggregator_factory_for_test(starcoin_framework); let (burn_cap, mint_cap) = initialize(starcoin_framework); coin::create_coin_conversion_map(starcoin_framework); coin::create_pairing(starcoin_framework); + + debug::print(&string::utf8(b"starcoin_coin::initialize_for_test | exited")); (burn_cap, mint_cap) } diff --git a/vm/framework/starcoin-framework/sources/stc/stc_genesis.move b/vm/framework/starcoin-framework/sources/stc/stc_genesis.move index 04cd99f4eb..5d19898250 100644 --- a/vm/framework/starcoin-framework/sources/stc/stc_genesis.move +++ b/vm/framework/starcoin-framework/sources/stc/stc_genesis.move @@ -303,11 +303,11 @@ module starcoin_framework::stc_genesis { time_mint_stc_amount: u128, time_mint_stc_period: u64, ) { - // TODO(BobOng): To confirm how many STC put into asset mapping pool - let asset_mapping_coin = coin::extract(&mut total_supply_stc, 1000000000); + // TODO(BobOng): [asset-mapping] To confirm how many STC put into asset mapping pool, now is 10,000,000,000 STC + let asset_mapping_coin = coin::extract(&mut total_supply_stc, 100000000000000000); asset_mapping::create_store_from_coin( starcoin_framework, - std::string::utf8(b"0x1::STC::STC"), + b"0x1::STC::STC", asset_mapping_coin );