From 04fd6a82bcd9ddc6c4b90bed128499b396f1f387 Mon Sep 17 00:00:00 2001 From: mr-t Date: Sun, 21 Jan 2024 22:29:41 +0100 Subject: [PATCH 1/3] new CW721_ADMIN store --- .../src/testing/integration_tests.rs | 23 ++++-- packages/ics721/schema/ics721.json | 71 ++++++++++++------- packages/ics721/schema/raw/execute.json | 25 ------- packages/ics721/schema/raw/instantiate.json | 7 ++ packages/ics721/schema/raw/query.json | 14 ++++ .../schema/raw/response_to_cw721_admin.json | 25 +++++++ packages/ics721/src/execute.rs | 44 ++++++++++-- packages/ics721/src/msg.rs | 8 +++ packages/ics721/src/query.rs | 5 +- packages/ics721/src/state.rs | 2 + packages/ics721/src/testing/contract.rs | 10 ++- packages/ics721/src/testing/ibc_tests.rs | 1 + .../ics721/src/testing/integration_tests.rs | 36 ++++++++-- 13 files changed, 204 insertions(+), 67 deletions(-) create mode 100644 packages/ics721/schema/raw/response_to_cw721_admin.json diff --git a/contracts/sg-ics721/src/testing/integration_tests.rs b/contracts/sg-ics721/src/testing/integration_tests.rs index 90cb9fa8..796a0619 100644 --- a/contracts/sg-ics721/src/testing/integration_tests.rs +++ b/contracts/sg-ics721/src/testing/integration_tests.rs @@ -338,6 +338,9 @@ impl Test { false => None, }; + let admin = admin_and_pauser + .clone() + .map(|p| app.api().addr_make(&p).to_string()); let ics721 = app .instantiate_contract( ics721_id, @@ -346,9 +349,8 @@ impl Test { cw721_base_code_id: source_cw721_id, incoming_proxy, outgoing_proxy, - pauser: admin_and_pauser - .clone() - .map(|p| app.api().addr_make(&p).to_string()), + pauser: admin.clone(), + cw721_admin: admin, }, &[], "sg-ics721", @@ -452,6 +454,13 @@ impl Test { .unwrap() } + fn query_cw721_admin(&mut self) -> Option { + self.app + .wrap() + .query_wasm_smart(self.ics721.clone(), &QueryMsg::Cw721Admin {}) + .unwrap() + } + fn query_nft_contracts(&mut self) -> Vec<(String, Addr)> { self.app .wrap() @@ -2337,6 +2346,7 @@ fn test_pause() { incoming_proxy: None, outgoing_proxy: None, cw721_base_code_id: None, + cw721_admin: None, }) .unwrap(), } @@ -2378,9 +2388,10 @@ fn test_migration() { assert_eq!(cw721_code_id, test.source_cw721_id); // migrate changes + let admin = test.app.api().addr_make(ICS721_ADMIN_AND_PAUSER); test.app .execute( - test.app.api().addr_make(ICS721_ADMIN_AND_PAUSER), + admin.clone(), WasmMsg::Migrate { contract_addr: test.ics721.to_string(), new_code_id: test.ics721_id, @@ -2389,6 +2400,7 @@ fn test_migration() { incoming_proxy: None, outgoing_proxy: None, cw721_base_code_id: Some(12345678), + cw721_admin: Some(admin.to_string()), }) .unwrap(), } @@ -2402,6 +2414,7 @@ fn test_migration() { assert!(proxy.is_none()); let cw721_code_id = test.query_cw721_id(); assert_eq!(cw721_code_id, 12345678); + assert_eq!(test.query_cw721_admin(), Some(admin),); // migrate without changing code id test.app @@ -2415,6 +2428,7 @@ fn test_migration() { incoming_proxy: None, outgoing_proxy: None, cw721_base_code_id: None, + cw721_admin: Some("".to_string()), }) .unwrap(), } @@ -2428,4 +2442,5 @@ fn test_migration() { assert!(proxy.is_none()); let cw721_code_id = test.query_cw721_id(); assert_eq!(cw721_code_id, 12345678); + assert_eq!(test.query_cw721_admin(), None,); } diff --git a/packages/ics721/schema/ics721.json b/packages/ics721/schema/ics721.json index 863f9db2..bc19702d 100644 --- a/packages/ics721/schema/ics721.json +++ b/packages/ics721/schema/ics721.json @@ -10,6 +10,13 @@ "cw721_base_code_id" ], "properties": { + "cw721_admin": { + "description": "The admin address for instantiating new cw721 contracts. In case of None, contract is immutable.", + "type": [ + "string", + "null" + ] + }, "cw721_base_code_id": { "description": "Code ID of cw721-ics contract. A new cw721-ics will be instantiated for each new IBCd NFT classID.\n\nNOTE: this _must_ correspond to the cw721-base contract. Using a regular cw721 may cause the ICS 721 interface implemented by this contract to stop working, and IBCd away NFTs to be unreturnable as cw721 does not have a mint method in the spec.", "type": "integer", @@ -167,31 +174,6 @@ } }, "additionalProperties": false - }, - { - "type": "object", - "required": [ - "receive_proxy_nft" - ], - "properties": { - "receive_proxy_nft": { - "type": "object", - "required": [ - "eyeball", - "msg" - ], - "properties": { - "eyeball": { - "type": "string" - }, - "msg": { - "$ref": "#/definitions/Cw721ReceiveMsg" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false } ], "definitions": { @@ -921,6 +903,20 @@ }, "additionalProperties": false }, + { + "description": "Gets the admin address for instantiating new cw721 contracts. In case of None, contract is immutable.", + "type": "object", + "required": [ + "cw721_admin" + ], + "properties": { + "cw721_admin": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, { "description": "Gets a list of classID as key (from NonFungibleTokenPacketData) and cw721 contract as value (instantiated for that classID).", "type": "object", @@ -1129,6 +1125,31 @@ } } }, + "cw721_admin": { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Nullable_Nullable_Addr", + "anyOf": [ + { + "anyOf": [ + { + "$ref": "#/definitions/Addr" + }, + { + "type": "null" + } + ] + }, + { + "type": "null" + } + ], + "definitions": { + "Addr": { + "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", + "type": "string" + } + } + }, "cw721_code_id": { "$schema": "http://json-schema.org/draft-07/schema#", "title": "uint64", diff --git a/packages/ics721/schema/raw/execute.json b/packages/ics721/schema/raw/execute.json index 6e99d45c..19cdd78d 100644 --- a/packages/ics721/schema/raw/execute.json +++ b/packages/ics721/schema/raw/execute.json @@ -41,31 +41,6 @@ } }, "additionalProperties": false - }, - { - "type": "object", - "required": [ - "receive_proxy_nft" - ], - "properties": { - "receive_proxy_nft": { - "type": "object", - "required": [ - "eyeball", - "msg" - ], - "properties": { - "eyeball": { - "type": "string" - }, - "msg": { - "$ref": "#/definitions/Cw721ReceiveMsg" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false } ], "definitions": { diff --git a/packages/ics721/schema/raw/instantiate.json b/packages/ics721/schema/raw/instantiate.json index f431f451..52fd2a18 100644 --- a/packages/ics721/schema/raw/instantiate.json +++ b/packages/ics721/schema/raw/instantiate.json @@ -6,6 +6,13 @@ "cw721_base_code_id" ], "properties": { + "cw721_admin": { + "description": "The admin address for instantiating new cw721 contracts. In case of None, contract is immutable.", + "type": [ + "string", + "null" + ] + }, "cw721_base_code_id": { "description": "Code ID of cw721-ics contract. A new cw721-ics will be instantiated for each new IBCd NFT classID.\n\nNOTE: this _must_ correspond to the cw721-base contract. Using a regular cw721 may cause the ICS 721 interface implemented by this contract to stop working, and IBCd away NFTs to be unreturnable as cw721 does not have a mint method in the spec.", "type": "integer", diff --git a/packages/ics721/schema/raw/query.json b/packages/ics721/schema/raw/query.json index 9a6d14f2..0bcdce7e 100644 --- a/packages/ics721/schema/raw/query.json +++ b/packages/ics721/schema/raw/query.json @@ -189,6 +189,20 @@ }, "additionalProperties": false }, + { + "description": "Gets the admin address for instantiating new cw721 contracts. In case of None, contract is immutable.", + "type": "object", + "required": [ + "cw721_admin" + ], + "properties": { + "cw721_admin": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, { "description": "Gets a list of classID as key (from NonFungibleTokenPacketData) and cw721 contract as value (instantiated for that classID).", "type": "object", diff --git a/packages/ics721/schema/raw/response_to_cw721_admin.json b/packages/ics721/schema/raw/response_to_cw721_admin.json new file mode 100644 index 00000000..bbbfb8ea --- /dev/null +++ b/packages/ics721/schema/raw/response_to_cw721_admin.json @@ -0,0 +1,25 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Nullable_Nullable_Addr", + "anyOf": [ + { + "anyOf": [ + { + "$ref": "#/definitions/Addr" + }, + { + "type": "null" + } + ] + }, + { + "type": "null" + } + ], + "definitions": { + "Addr": { + "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", + "type": "string" + } + } +} diff --git a/packages/ics721/src/execute.rs b/packages/ics721/src/execute.rs index 9eb345ac..9d39d5ab 100644 --- a/packages/ics721/src/execute.rs +++ b/packages/ics721/src/execute.rs @@ -20,8 +20,8 @@ use crate::{ msg::{CallbackMsg, ExecuteMsg, InstantiateMsg, MigrateMsg}, state::{ CollectionData, UniversalAllNftInfoResponse, CLASS_ID_TO_CLASS, CLASS_ID_TO_NFT_CONTRACT, - CW721_CODE_ID, INCOMING_PROXY, NFT_CONTRACT_TO_CLASS_ID, OUTGOING_CLASS_TOKEN_TO_CHANNEL, - OUTGOING_PROXY, PO, TOKEN_METADATA, + CW721_ADMIN, CW721_CODE_ID, INCOMING_PROXY, NFT_CONTRACT_TO_CLASS_ID, + OUTGOING_CLASS_TOKEN_TO_CHANNEL, OUTGOING_PROXY, PO, TOKEN_METADATA, }, token_types::{VoucherCreation, VoucherRedemption}, ContractError, @@ -62,10 +62,23 @@ where )); } + CW721_ADMIN.save( + deps.storage, + &msg.cw721_admin + .as_ref() + .map(|h| deps.api.addr_validate(h)) + .transpose()?, + )?; + Ok(Response::default() .add_submessages(proxies_instantiate) .add_attribute("method", "instantiate") - .add_attribute("cw721_code_id", msg.cw721_base_code_id.to_string())) + .add_attribute("cw721_code_id", msg.cw721_base_code_id.to_string()) + .add_attribute( + "cw721_admin", + msg.cw721_admin + .map_or_else(|| "immutable".to_string(), |or| or), + )) } fn execute( @@ -323,9 +336,10 @@ where CLASS_ID_TO_NFT_CONTRACT.save(deps.storage, class_id.clone(), &cw721_addr)?; NFT_CONTRACT_TO_CLASS_ID.save(deps.storage, cw721_addr, &class_id)?; + let admin = CW721_ADMIN.load(deps.storage)?.map(|a| a.to_string()); let message = SubMsg::::reply_on_success( WasmMsg::Instantiate2 { - admin: None, + admin, code_id: cw721_code_id, msg: self.init_msg(deps.as_ref(), &env, &class)?, funds: vec![], @@ -471,6 +485,7 @@ where incoming_proxy, outgoing_proxy, cw721_base_code_id, + cw721_admin, } => { // disables incoming proxy if none is provided! INCOMING_PROXY.save( @@ -492,6 +507,14 @@ where if let Some(cw721_base_code_id) = cw721_base_code_id { CW721_CODE_ID.save(deps.storage, &cw721_base_code_id)?; } + if let Some(cw721_admin) = cw721_admin.clone() { + if cw721_admin.is_empty() { + CW721_ADMIN.save(deps.storage, &None)?; + } else { + CW721_ADMIN + .save(deps.storage, &Some(deps.api.addr_validate(&cw721_admin)?))?; + } + } Ok(Response::default() .add_attribute("method", "migrate") .add_attribute("pauser", pauser.map_or_else(|| "none".to_string(), |or| or)) @@ -506,6 +529,19 @@ where .add_attribute( "cw721_base_code_id", cw721_base_code_id.map_or_else(|| "none".to_string(), |or| or.to_string()), + ) + .add_attribute( + "cw721_admin", + cw721_admin.map_or_else( + || "none".to_string(), + |or| { + if or.is_empty() { + "immutable".to_string() + } else { + or + } + }, + ), )) } } diff --git a/packages/ics721/src/msg.rs b/packages/ics721/src/msg.rs index f5a9401f..c7a902cc 100644 --- a/packages/ics721/src/msg.rs +++ b/packages/ics721/src/msg.rs @@ -29,6 +29,8 @@ pub struct InstantiateMsg { /// right to do so again. A new pauser may be later nominated by /// the CosmWasm level admin via a migration. pub pauser: Option, + /// The admin address for instantiating new cw721 contracts. In case of None, contract is immutable. + pub cw721_admin: Option, } #[cw_serde] @@ -133,6 +135,10 @@ pub enum QueryMsg { #[returns(u64)] Cw721CodeId {}, + /// Gets the admin address for instantiating new cw721 contracts. In case of None, contract is immutable. + #[returns(Option>)] + Cw721Admin {}, + /// Gets a list of classID as key (from /// NonFungibleTokenPacketData) and cw721 contract as value /// (instantiated for that classID). @@ -181,5 +187,7 @@ pub enum MigrateMsg { /// this contract to stop working, and IBCd away NFTs to be /// unreturnable as cw721 does not have a mint method in the spec. cw721_base_code_id: Option, + /// The admin address for instantiating new cw721 contracts. In case of "", contract is immutable. + cw721_admin: Option, }, } diff --git a/packages/ics721/src/query.rs b/packages/ics721/src/query.rs index 37c43e16..bab390da 100644 --- a/packages/ics721/src/query.rs +++ b/packages/ics721/src/query.rs @@ -4,8 +4,8 @@ use cw_storage_plus::Map; use crate::{ msg::QueryMsg, state::{ - UniversalAllNftInfoResponse, CLASS_ID_TO_CLASS, CLASS_ID_TO_NFT_CONTRACT, CW721_CODE_ID, - INCOMING_CLASS_TOKEN_TO_CHANNEL, INCOMING_PROXY, NFT_CONTRACT_TO_CLASS_ID, + UniversalAllNftInfoResponse, CLASS_ID_TO_CLASS, CLASS_ID_TO_NFT_CONTRACT, CW721_ADMIN, + CW721_CODE_ID, INCOMING_CLASS_TOKEN_TO_CHANNEL, INCOMING_PROXY, NFT_CONTRACT_TO_CLASS_ID, OUTGOING_CLASS_TOKEN_TO_CHANNEL, OUTGOING_PROXY, PO, TOKEN_METADATA, }, }; @@ -34,6 +34,7 @@ pub trait Ics721Query { QueryMsg::OutgoingProxy {} => to_json_binary(&OUTGOING_PROXY.load(deps.storage)?), QueryMsg::IncomingProxy {} => to_json_binary(&INCOMING_PROXY.load(deps.storage)?), QueryMsg::Cw721CodeId {} => to_json_binary(&self.query_cw721_code_id(deps)?), + QueryMsg::Cw721Admin {} => to_json_binary(&CW721_ADMIN.load(deps.storage)?), QueryMsg::NftContracts { start_after, limit } => { to_json_binary(&self.query_nft_contracts(deps, start_after, limit)?) } diff --git a/packages/ics721/src/state.rs b/packages/ics721/src/state.rs index bc75a832..d254f6ea 100644 --- a/packages/ics721/src/state.rs +++ b/packages/ics721/src/state.rs @@ -38,6 +38,8 @@ pub const INCOMING_CLASS_TOKEN_TO_CHANNEL: Map<(ClassId, TokenId), String> = Map /// is `None`) is stored in this map. When the token is returned to /// it's source chain, the metadata is removed from the map. pub const TOKEN_METADATA: Map<(ClassId, TokenId), Option> = Map::new("j"); +/// The admin address for instantiating new cw721 contracts. In case of None, contract is immutable. +pub const CW721_ADMIN: Item> = Item::new("l"); #[derive(Deserialize)] pub struct UniversalAllNftInfoResponse { diff --git a/packages/ics721/src/testing/contract.rs b/packages/ics721/src/testing/contract.rs index 7d5acb48..d76bb9bd 100644 --- a/packages/ics721/src/testing/contract.rs +++ b/packages/ics721/src/testing/contract.rs @@ -16,7 +16,7 @@ use crate::{ msg::InstantiateMsg, query::Ics721Query, state::{ - CollectionData, CLASS_ID_TO_CLASS, CW721_CODE_ID, INCOMING_PROXY, + CollectionData, CLASS_ID_TO_CLASS, CW721_ADMIN, CW721_CODE_ID, INCOMING_PROXY, OUTGOING_CLASS_TOKEN_TO_CHANNEL, OUTGOING_PROXY, PO, }, utils::get_collection_data, @@ -513,6 +513,7 @@ fn test_instantiate() { incoming_proxy: Some(incoming_proxy_init_msg.clone()), outgoing_proxy: Some(outgoing_proxy_init_msg.clone()), pauser: Some(PAUSER_ADDR.to_string()), + cw721_admin: Some(ADMIN_ADDR.to_string()), }; let response = Ics721Contract {} .instantiate(deps.as_mut(), env.clone(), info, msg.clone()) @@ -531,7 +532,8 @@ fn test_instantiate() { INSTANTIATE_OUTGOING_PROXY_REPLY_ID, )) .add_attribute("method", "instantiate") - .add_attribute("cw721_code_id", msg.cw721_base_code_id.to_string()); + .add_attribute("cw721_code_id", msg.cw721_base_code_id.to_string()) + .add_attribute("cw721_admin", ADMIN_ADDR); assert_eq!(response, expected_response); assert_eq!(CW721_CODE_ID.load(&deps.storage).unwrap(), 0); // incoming and outgoing proxy initially set to None and set later in sub msg @@ -542,4 +544,8 @@ fn test_instantiate() { Some(Addr::unchecked(PAUSER_ADDR)) ); assert!(!PO.paused.load(&deps.storage).unwrap()); + assert_eq!( + CW721_ADMIN.load(&deps.storage).unwrap(), + Some(Addr::unchecked(ADMIN_ADDR.to_string())) + ); } diff --git a/packages/ics721/src/testing/ibc_tests.rs b/packages/ics721/src/testing/ibc_tests.rs index 39ced734..b7c3ed55 100644 --- a/packages/ics721/src/testing/ibc_tests.rs +++ b/packages/ics721/src/testing/ibc_tests.rs @@ -108,6 +108,7 @@ fn do_instantiate(deps: DepsMut, env: Env, sender: &str) -> StdResult incoming_proxy: None, outgoing_proxy: None, pauser: None, + cw721_admin: None, }; Ics721Contract::default().instantiate(deps, env, mock_info(sender, &[]), msg) } diff --git a/packages/ics721/src/testing/integration_tests.rs b/packages/ics721/src/testing/integration_tests.rs index f6814f2c..fa5cf077 100644 --- a/packages/ics721/src/testing/integration_tests.rs +++ b/packages/ics721/src/testing/integration_tests.rs @@ -33,6 +33,7 @@ use ics721_types::{ use super::contract::Ics721Contract; const ICS721_CREATOR: &str = "ics721-creator"; +const ICS721_ADMIN: &str = "ics721-admin"; const CONTRACT_NAME: &str = "crates.io:ics721-base"; const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -340,6 +341,9 @@ impl Test { false => None, }; + let admin = admin_and_pauser + .clone() + .map(|p| app.api().addr_make(&p).to_string()); let ics721 = app .instantiate_contract( ics721_id, @@ -348,9 +352,8 @@ impl Test { cw721_base_code_id: source_cw721_id, incoming_proxy, outgoing_proxy, - pauser: admin_and_pauser - .clone() - .map(|p| app.api().addr_make(&p).to_string()), + pauser: admin.clone(), + cw721_admin: admin, }, &[], "ics721-base", @@ -461,6 +464,13 @@ impl Test { .unwrap() } + fn query_cw721_admin(&mut self) -> Option { + self.app + .wrap() + .query_wasm_smart(self.ics721.clone(), &QueryMsg::Cw721Admin {}) + .unwrap() + } + fn query_nft_contracts(&mut self) -> Vec<(String, Addr)> { self.app .wrap() @@ -570,7 +580,14 @@ fn outgoing_proxy_contract() -> Box> { #[test] fn test_instantiate() { - let mut test = Test::new(true, true, None, None, cw721_base_contract(), true); + let mut test = Test::new( + true, + true, + None, + Some(ICS721_ADMIN.to_string()), + cw721_base_contract(), + true, + ); // check stores are properly initialized let cw721_id = test.query_cw721_id(); @@ -585,6 +602,8 @@ fn test_instantiate() { assert!(outgoing_proxy.is_some()); let incoming_proxy = test.query_incoming_proxy(); assert!(incoming_proxy.is_some()); + let cw721_admin = test.query_cw721_admin(); + assert_eq!(cw721_admin, Some(test.app.api().addr_make(ICS721_ADMIN))); } #[test] @@ -2072,6 +2091,7 @@ fn test_pause() { incoming_proxy: None, outgoing_proxy: None, cw721_base_code_id: None, + cw721_admin: None, }) .unwrap(), } @@ -2114,9 +2134,10 @@ fn test_migration() { assert_eq!(cw721_code_id, test.source_cw721_id); // migrate changes + let admin = test.app.api().addr_make(ICS721_ADMIN_AND_PAUSER); test.app .execute( - test.app.api().addr_make(ICS721_ADMIN_AND_PAUSER), + admin.clone(), WasmMsg::Migrate { contract_addr: test.ics721.to_string(), new_code_id: test.ics721_id, @@ -2125,6 +2146,7 @@ fn test_migration() { incoming_proxy: None, outgoing_proxy: None, cw721_base_code_id: Some(12345678), + cw721_admin: Some(admin.to_string()), }) .unwrap(), } @@ -2138,8 +2160,10 @@ fn test_migration() { assert!(proxy.is_none()); let cw721_code_id = test.query_cw721_id(); assert_eq!(cw721_code_id, 12345678); + assert_eq!(test.query_cw721_admin(), Some(admin),); // migrate without changing code id + println!(">>>>>>> migrate without changing code id"); test.app .execute( test.app.api().addr_make(ICS721_ADMIN_AND_PAUSER), @@ -2151,6 +2175,7 @@ fn test_migration() { incoming_proxy: None, outgoing_proxy: None, cw721_base_code_id: None, + cw721_admin: Some("".to_string()), }) .unwrap(), } @@ -2164,4 +2189,5 @@ fn test_migration() { assert!(proxy.is_none()); let cw721_code_id = test.query_cw721_id(); assert_eq!(cw721_code_id, 12345678); + assert_eq!(test.query_cw721_admin(), None,); } From 5016c3af2cf2e520e24ccfcb80ec2080685b3bb8 Mon Sep 17 00:00:00 2001 From: mr-t Date: Sun, 21 Jan 2024 22:44:51 +0100 Subject: [PATCH 2/3] use latest optimizer version --- justfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/justfile b/justfile index cdb51921..d8674d1c 100644 --- a/justfile +++ b/justfile @@ -1,7 +1,7 @@ set dotenv-load platform := if arch() =~ "aarch64" {"linux/arm64"} else {"linux/amd64"} -image := if arch() =~ "aarch64" {"cosmwasm/workspace-optimizer-arm64:0.14.0"} else {"cosmwasm/workspace-optimizer:0.14.0"} +image := if arch() =~ "aarch64" {"cosmwasm/workspace-optimizer-arm64:0.15.0"} else {"cosmwasm/workspace-optimizer:0.15.0"} alias log := optimize-watch From b5c4acb6f8ca081ad5e8aa2d741cd465ace78ee8 Mon Sep 17 00:00:00 2001 From: mr-t Date: Mon, 22 Jan 2024 20:00:59 +0100 Subject: [PATCH 3/3] rename CW721_ADMIN > ADMIN_USED_FOR_CW721 --- packages/ics721/src/execute.rs | 14 ++++++++------ packages/ics721/src/query.rs | 9 +++++---- packages/ics721/src/state.rs | 2 +- packages/ics721/src/testing/contract.rs | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/ics721/src/execute.rs b/packages/ics721/src/execute.rs index 9d39d5ab..4c46ada9 100644 --- a/packages/ics721/src/execute.rs +++ b/packages/ics721/src/execute.rs @@ -19,8 +19,8 @@ use crate::{ }, msg::{CallbackMsg, ExecuteMsg, InstantiateMsg, MigrateMsg}, state::{ - CollectionData, UniversalAllNftInfoResponse, CLASS_ID_TO_CLASS, CLASS_ID_TO_NFT_CONTRACT, - CW721_ADMIN, CW721_CODE_ID, INCOMING_PROXY, NFT_CONTRACT_TO_CLASS_ID, + CollectionData, UniversalAllNftInfoResponse, ADMIN_USED_FOR_CW721, CLASS_ID_TO_CLASS, + CLASS_ID_TO_NFT_CONTRACT, CW721_CODE_ID, INCOMING_PROXY, NFT_CONTRACT_TO_CLASS_ID, OUTGOING_CLASS_TOKEN_TO_CHANNEL, OUTGOING_PROXY, PO, TOKEN_METADATA, }, token_types::{VoucherCreation, VoucherRedemption}, @@ -62,7 +62,7 @@ where )); } - CW721_ADMIN.save( + ADMIN_USED_FOR_CW721.save( deps.storage, &msg.cw721_admin .as_ref() @@ -336,7 +336,9 @@ where CLASS_ID_TO_NFT_CONTRACT.save(deps.storage, class_id.clone(), &cw721_addr)?; NFT_CONTRACT_TO_CLASS_ID.save(deps.storage, cw721_addr, &class_id)?; - let admin = CW721_ADMIN.load(deps.storage)?.map(|a| a.to_string()); + let admin = ADMIN_USED_FOR_CW721 + .load(deps.storage)? + .map(|a| a.to_string()); let message = SubMsg::::reply_on_success( WasmMsg::Instantiate2 { admin, @@ -509,9 +511,9 @@ where } if let Some(cw721_admin) = cw721_admin.clone() { if cw721_admin.is_empty() { - CW721_ADMIN.save(deps.storage, &None)?; + ADMIN_USED_FOR_CW721.save(deps.storage, &None)?; } else { - CW721_ADMIN + ADMIN_USED_FOR_CW721 .save(deps.storage, &Some(deps.api.addr_validate(&cw721_admin)?))?; } } diff --git a/packages/ics721/src/query.rs b/packages/ics721/src/query.rs index bab390da..e31a93ec 100644 --- a/packages/ics721/src/query.rs +++ b/packages/ics721/src/query.rs @@ -4,9 +4,10 @@ use cw_storage_plus::Map; use crate::{ msg::QueryMsg, state::{ - UniversalAllNftInfoResponse, CLASS_ID_TO_CLASS, CLASS_ID_TO_NFT_CONTRACT, CW721_ADMIN, - CW721_CODE_ID, INCOMING_CLASS_TOKEN_TO_CHANNEL, INCOMING_PROXY, NFT_CONTRACT_TO_CLASS_ID, - OUTGOING_CLASS_TOKEN_TO_CHANNEL, OUTGOING_PROXY, PO, TOKEN_METADATA, + UniversalAllNftInfoResponse, ADMIN_USED_FOR_CW721, CLASS_ID_TO_CLASS, + CLASS_ID_TO_NFT_CONTRACT, CW721_CODE_ID, INCOMING_CLASS_TOKEN_TO_CHANNEL, INCOMING_PROXY, + NFT_CONTRACT_TO_CLASS_ID, OUTGOING_CLASS_TOKEN_TO_CHANNEL, OUTGOING_PROXY, PO, + TOKEN_METADATA, }, }; use ics721_types::token_types::{Class, ClassId, ClassToken, Token, TokenId}; @@ -34,7 +35,7 @@ pub trait Ics721Query { QueryMsg::OutgoingProxy {} => to_json_binary(&OUTGOING_PROXY.load(deps.storage)?), QueryMsg::IncomingProxy {} => to_json_binary(&INCOMING_PROXY.load(deps.storage)?), QueryMsg::Cw721CodeId {} => to_json_binary(&self.query_cw721_code_id(deps)?), - QueryMsg::Cw721Admin {} => to_json_binary(&CW721_ADMIN.load(deps.storage)?), + QueryMsg::Cw721Admin {} => to_json_binary(&ADMIN_USED_FOR_CW721.load(deps.storage)?), QueryMsg::NftContracts { start_after, limit } => { to_json_binary(&self.query_nft_contracts(deps, start_after, limit)?) } diff --git a/packages/ics721/src/state.rs b/packages/ics721/src/state.rs index d254f6ea..739f7568 100644 --- a/packages/ics721/src/state.rs +++ b/packages/ics721/src/state.rs @@ -39,7 +39,7 @@ pub const INCOMING_CLASS_TOKEN_TO_CHANNEL: Map<(ClassId, TokenId), String> = Map /// it's source chain, the metadata is removed from the map. pub const TOKEN_METADATA: Map<(ClassId, TokenId), Option> = Map::new("j"); /// The admin address for instantiating new cw721 contracts. In case of None, contract is immutable. -pub const CW721_ADMIN: Item> = Item::new("l"); +pub const ADMIN_USED_FOR_CW721: Item> = Item::new("l"); #[derive(Deserialize)] pub struct UniversalAllNftInfoResponse { diff --git a/packages/ics721/src/testing/contract.rs b/packages/ics721/src/testing/contract.rs index d76bb9bd..4e0da119 100644 --- a/packages/ics721/src/testing/contract.rs +++ b/packages/ics721/src/testing/contract.rs @@ -16,7 +16,7 @@ use crate::{ msg::InstantiateMsg, query::Ics721Query, state::{ - CollectionData, CLASS_ID_TO_CLASS, CW721_ADMIN, CW721_CODE_ID, INCOMING_PROXY, + CollectionData, ADMIN_USED_FOR_CW721, CLASS_ID_TO_CLASS, CW721_CODE_ID, INCOMING_PROXY, OUTGOING_CLASS_TOKEN_TO_CHANNEL, OUTGOING_PROXY, PO, }, utils::get_collection_data, @@ -545,7 +545,7 @@ fn test_instantiate() { ); assert!(!PO.paused.load(&deps.storage).unwrap()); assert_eq!( - CW721_ADMIN.load(&deps.storage).unwrap(), + ADMIN_USED_FOR_CW721.load(&deps.storage).unwrap(), Some(Addr::unchecked(ADMIN_ADDR.to_string())) ); }