From 66bd0cdfd1350b9de2d1959cfdf6be6057f18c96 Mon Sep 17 00:00:00 2001 From: mr-t Date: Mon, 27 Nov 2023 08:55:18 +0100 Subject: [PATCH 1/3] use creator of ics721 for collection info --- contracts/sg-ics721/src/execute.rs | 24 ++++--------------- .../src/testing/integration_tests.rs | 22 ++--------------- 2 files changed, 6 insertions(+), 40 deletions(-) diff --git a/contracts/sg-ics721/src/execute.rs b/contracts/sg-ics721/src/execute.rs index 4af1d16e..6b934e42 100644 --- a/contracts/sg-ics721/src/execute.rs +++ b/contracts/sg-ics721/src/execute.rs @@ -1,9 +1,6 @@ use cosmwasm_std::{from_json, to_json_binary, Addr, Binary, Deps, DepsMut, Env, StdResult}; use ics721::{ - execute::Ics721Execute, - state::CollectionData, - token_types::Class, - utils::{convert_owner_chain_address, get_collection_data}, + execute::Ics721Execute, state::CollectionData, token_types::Class, utils::get_collection_data, }; use sg721_base::msg::{CollectionInfoResponse, QueryMsg}; @@ -47,6 +44,9 @@ impl Ics721Execute for SgIcs721Contract { symbol: class.id.clone().into(), minter: env.contract.address.to_string(), collection_info: sg721::CollectionInfo { + // source owner could be: 1. regular owner, 2. contract, or 3. multisig + // bech32 calculation for 2. and 3. leads to unknown address + // therefore, we use ics721 creator as owner creator: ics721_contract_info.creator, description: "".to_string(), image: "https://arkprotocol.io".to_string(), @@ -62,22 +62,6 @@ impl Ics721Execute for SgIcs721Contract { let class_data_result: StdResult = from_json(binary); if class_data_result.is_ok() { let class_data = class_data_result?; - match class_data.owner { - Some(owner) => - // owner from source chain is used - { - instantiate_msg.collection_info.creator = - convert_owner_chain_address(env, owner.as_str())? - } - None => - // ics721 creator is used, in case of none - { - let ics721_contract_info = deps - .querier - .query_wasm_contract_info(env.contract.address.to_string())?; - instantiate_msg.collection_info.creator = ics721_contract_info.creator; - } - } // set name and symbol instantiate_msg.symbol = class_data.symbol; instantiate_msg.name = class_data.name; diff --git a/contracts/sg-ics721/src/testing/integration_tests.rs b/contracts/sg-ics721/src/testing/integration_tests.rs index 547afc64..409729aa 100644 --- a/contracts/sg-ics721/src/testing/integration_tests.rs +++ b/contracts/sg-ics721/src/testing/integration_tests.rs @@ -846,20 +846,12 @@ fn test_do_instantiate_and_mint() { .wrap() .query_wasm_smart(nft_contract.clone(), &Sg721QueryMsg::CollectionInfo {}) .unwrap(); - let (_source_hrp, source_data, source_variant) = bech32::decode( - test.app - .api() - .addr_make(COLLECTION_OWNER_SOURCE_CHAIN) - .as_str(), - ) - .unwrap(); - let target_owner = bech32::encode(BECH32_PREFIX_HRP, source_data, source_variant).unwrap(); assert_eq!( collection_info, CollectionInfoResponse { // creator based on owner from collection in soure chain - creator: target_owner, // creator is set to owner as defined by ClassData + creator: test.app.api().addr_make(ICS721_CREATOR).to_string(), description: "".to_string(), image: "https://arkprotocol.io".to_string(), external_link: None, @@ -1705,20 +1697,10 @@ fn test_do_instantiate_and_mint_no_instantiate() { .wrap() .query_wasm_smart(nft_contract.clone(), &Sg721QueryMsg::CollectionInfo {}) .unwrap(); - let (_source_hrp, source_data, source_variant) = bech32::decode( - test.app - .api() - .addr_make(COLLECTION_OWNER_SOURCE_CHAIN) - .as_str(), - ) - .unwrap(); - let target_owner = bech32::encode(BECH32_PREFIX_HRP, source_data, source_variant).unwrap(); - assert_eq!( collection_info, CollectionInfoResponse { - // creator is set to owner as defined by ClassData in 1st transfer! - creator: target_owner, + creator: test.app.api().addr_make(ICS721_CREATOR).to_string(), description: "".to_string(), image: "https://arkprotocol.io".to_string(), external_link: None, From 9c9b0564d2100d0c7248a417a4918a3e88c28627 Mon Sep 17 00:00:00 2001 From: mr-t Date: Mon, 27 Nov 2023 09:03:27 +0100 Subject: [PATCH 2/3] typo --- contracts/sg-ics721/src/execute.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/sg-ics721/src/execute.rs b/contracts/sg-ics721/src/execute.rs index 6b934e42..9e611778 100644 --- a/contracts/sg-ics721/src/execute.rs +++ b/contracts/sg-ics721/src/execute.rs @@ -44,7 +44,7 @@ impl Ics721Execute for SgIcs721Contract { symbol: class.id.clone().into(), minter: env.contract.address.to_string(), collection_info: sg721::CollectionInfo { - // source owner could be: 1. regular owner, 2. contract, or 3. multisig + // source owner could be: 1. regular wallet, 2. contract, or 3. multisig // bech32 calculation for 2. and 3. leads to unknown address // therefore, we use ics721 creator as owner creator: ics721_contract_info.creator, From 75acead038b643ca584383e51afe2929b43f71cc Mon Sep 17 00:00:00 2001 From: mr-t Date: Mon, 27 Nov 2023 09:58:28 +0100 Subject: [PATCH 3/3] use ok() --- contracts/sg-ics721/src/execute.rs | 20 +++++++++----------- packages/ics721/src/execute.rs | 16 ++++++++-------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/contracts/sg-ics721/src/execute.rs b/contracts/sg-ics721/src/execute.rs index 9e611778..2605a99a 100644 --- a/contracts/sg-ics721/src/execute.rs +++ b/contracts/sg-ics721/src/execute.rs @@ -37,9 +37,8 @@ impl Ics721Execute for SgIcs721Contract { let ics721_contract_info = deps .querier .query_wasm_contract_info(env.contract.address.to_string())?; + // use by default ClassId, in case there's no class data with name and symbol let mut instantiate_msg = sg721::InstantiateMsg { - // source chain may not send optional collection data - // if not, by default class id is used for name and symbol name: class.id.clone().into(), symbol: class.id.clone().into(), minter: env.contract.address.to_string(), @@ -57,15 +56,14 @@ impl Ics721Execute for SgIcs721Contract { }, }; - // unwrapped to collection data and in case of success, set creator, name and symbol - if let Some(binary) = class.data.clone() { - let class_data_result: StdResult = from_json(binary); - if class_data_result.is_ok() { - let class_data = class_data_result?; - // set name and symbol - instantiate_msg.symbol = class_data.symbol; - instantiate_msg.name = class_data.name; - } + // use collection data for setting name and symbol + let collection_data = class + .data + .clone() + .and_then(|binary| from_json::(binary).ok()); + if let Some(collection_data) = collection_data { + instantiate_msg.name = collection_data.name; + instantiate_msg.symbol = collection_data.symbol; } to_json_binary(&instantiate_msg) diff --git a/packages/ics721/src/execute.rs b/packages/ics721/src/execute.rs index 79c6c3e3..575cf191 100644 --- a/packages/ics721/src/execute.rs +++ b/packages/ics721/src/execute.rs @@ -332,14 +332,14 @@ where minter: env.contract.address.to_string(), }; - // unwrapped to collection data and in case of success, set name and symbol - if let Some(binary) = class.data.clone() { - let class_data_result: StdResult = from_json(binary); - if class_data_result.is_ok() { - let class_data = class_data_result?; - instantiate_msg.symbol = class_data.symbol; - instantiate_msg.name = class_data.name; - } + // use collection data for setting name and symbol + let collection_data = class + .data + .clone() + .and_then(|binary| from_json::(binary).ok()); + if let Some(collection_data) = collection_data { + instantiate_msg.name = collection_data.name; + instantiate_msg.symbol = collection_data.symbol; } to_json_binary(&instantiate_msg)