Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Instantiate cw721 using CW721_CREATOR store #100

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
302 changes: 183 additions & 119 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ bech32 = "^0.9"
cosmwasm-std = "^1.5"
cosmwasm-schema = "^1.5"
cosmwasm-storage = "^1.5"
cw-ownable = "^0.5"
cw-paginate-storage = { version = "^2.4", git = "https://github.com/DA0-DA0/dao-contracts.git" }
cw-storage-plus = "1.1"
cw2 = "1.1"
cw721 = { git = "https://github.com/CosmWasm/cw-nfts", branch = "main"} # TODO switch to version 0.18.1/0.19.0, once released
cw721-016 = { version = "0.16.0", package = "cw721" }
cw721-base = { git = "https://github.com/CosmWasm/cw-nfts", branch = "main"} # TODO switch to version 0.18.1/0.19.0, once released
cw721-base-016 = { version = "0.16.0", package = "cw721-base" }
cw2 = "^1.1"
cw721 = { git = "https://github.com/arkprotocol/cw-nfts", branch = "collection-info"} # TODO switch to version 0.18.1/0.19.0, once released
cw721-base = { git = "https://github.com/arkprotocol/cw-nfts", branch = "collection-info"} # TODO switch to version 0.18.1/0.19.0, once released
cw721-016 = { git = "https://github.com/CosmWasm/cw-nfts", tag = "v0.16.0", package = "cw721" }
cw721-base-016 = { git = "https://github.com/CosmWasm/cw-nfts", tag = "v0.16.0", package = "cw721-base" }
cw-ics721-incoming-proxy = { git = "https://github.com/arkprotocol/cw-ics721-proxy.git", tag = "v0.1.0" }
cw-ics721-incoming-proxy-base = { git = "https://github.com/arkprotocol/cw-ics721-proxy.git", tag = "v0.1.0" }
cw-ics721-outgoing-proxy-rate-limit = { git = "https://github.com/arkprotocol/cw-ics721-proxy.git", tag = "v0.1.0" }
cw-ownable = "^0.5"
cw-paginate-storage = { version = "^2.4", git = "https://github.com/DA0-DA0/dao-contracts.git" }
cw-storage-plus = "^1.1"
cw-multi-test = { version = "^0.20", features = ["cosmwasm_1_2"] }
cw-utils = "^1.0"
sha2 = "^0.10"
Expand Down
20 changes: 14 additions & 6 deletions contracts/cw721-tester/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
use cosmwasm_schema::cw_serde;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response, StdResult};
use cosmwasm_std::{Binary, Deps, DepsMut, Empty, Env, MessageInfo, Response};
use cw2::set_contract_version;
use cw721_base::{msg, ContractError, Extension};
use cw721_base::{
error::ContractError, msg, DefaultOptionalCollectionExtension,
DefaultOptionalCollectionExtensionMsg, DefaultOptionalNftExtension,
DefaultOptionalNftExtensionMsg,
};
use cw_storage_plus::Item;

pub type ExecuteMsg = msg::ExecuteMsg<Extension, Empty>;
pub type QueryMsg = msg::QueryMsg<Empty>;
pub type ExecuteMsg =
msg::ExecuteMsg<DefaultOptionalNftExtensionMsg, DefaultOptionalCollectionExtensionMsg, Empty>;
pub type QueryMsg =
msg::QueryMsg<DefaultOptionalNftExtension, DefaultOptionalCollectionExtension, Empty>;

#[cw_serde]
pub struct InstantiateMsg {
Expand Down Expand Up @@ -36,10 +42,12 @@ pub fn instantiate(
deps.branch(),
env,
info,
msg::InstantiateMsg {
msg::InstantiateMsg::<DefaultOptionalCollectionExtensionMsg> {
name: msg.name,
symbol: msg.symbol,
minter: Some(msg.minter),
creator: None,
collection_info_extension: None,
withdraw_address: None,
},
)?;
Expand Down Expand Up @@ -71,6 +79,6 @@ pub fn execute(
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result<Binary, ContractError> {
cw721_base::entry::query(deps, env, msg)
}
32 changes: 23 additions & 9 deletions contracts/ics721-base-tester/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_json_binary, Binary, Deps, DepsMut, Env, IbcMsg, IbcTimeout, MessageInfo, Response,
to_json_binary, Binary, Deps, DepsMut, Empty, Env, IbcMsg, IbcTimeout, MessageInfo, Response,
StdResult, WasmMsg,
};
use cw2::set_contract_version;
use cw721::{DefaultOptionalCollectionExtensionMsg, DefaultOptionalNftExtensionMsg};
use ics721_types::ibc_types::{IbcOutgoingMsg, NonFungibleTokenPacketData};

use crate::{
Expand Down Expand Up @@ -63,7 +64,8 @@ pub fn execute(
}

mod receive_callbacks {
use cosmwasm_std::{ensure_eq, from_json, DepsMut, MessageInfo, Response};
use cosmwasm_std::{ensure_eq, from_json, DepsMut, Empty, MessageInfo, Response};
use cw721::{DefaultOptionalCollectionExtension, DefaultOptionalNftExtension};
use ics721_types::{
ibc_types::NonFungibleTokenPacketData,
types::{Ics721AckCallbackMsg, Ics721ReceiveCallbackMsg, Ics721Status},
Expand All @@ -77,7 +79,7 @@ mod receive_callbacks {

pub(crate) fn handle_receive_cw_callback(
deps: DepsMut,
_msg: cw721::Cw721ReceiveMsg,
_msg: cw721::receiver::Cw721ReceiveMsg,
) -> Result<Response, ContractError> {
// We got the callback, so its working
CW721_RECEIVE.save(deps.storage, &"success".to_string())?;
Expand Down Expand Up @@ -128,11 +130,15 @@ mod receive_callbacks {

NFT_CONTRACT.save(deps.storage, &deps.api.addr_validate(&nft_contract)?)?;

let owner: Option<cw721::OwnerOfResponse> = deps
let owner: Option<cw721::msg::OwnerOfResponse> = deps
.querier
.query_wasm_smart::<cw721::OwnerOfResponse>(
.query_wasm_smart::<cw721::msg::OwnerOfResponse>(
nft_contract,
&cw721::Cw721QueryMsg::OwnerOf {
&cw721::msg::Cw721QueryMsg::<
DefaultOptionalNftExtension,
DefaultOptionalCollectionExtension,
Empty,
>::OwnerOf {
token_id: packet.token_ids[0].clone().into(),
include_expired: None,
},
Expand Down Expand Up @@ -173,9 +179,13 @@ mod receive_callbacks {

let owner = deps
.querier
.query_wasm_smart::<cw721::OwnerOfResponse>(
.query_wasm_smart::<cw721::msg::OwnerOfResponse>(
nft_contract,
&cw721::Cw721QueryMsg::OwnerOf {
&cw721::msg::Cw721QueryMsg::<
DefaultOptionalNftExtension,
DefaultOptionalCollectionExtension,
Empty,
>::OwnerOf {
token_id: packet.token_ids[0].clone().into(),
include_expired: None,
},
Expand Down Expand Up @@ -217,7 +227,11 @@ fn execute_send_nft(
// Send send msg to cw721, send it to ics721 with the correct msg.
let msg = WasmMsg::Execute {
contract_addr: cw721,
msg: to_json_binary(&cw721::Cw721ExecuteMsg::SendNft {
msg: to_json_binary(&cw721::msg::Cw721ExecuteMsg::<
DefaultOptionalNftExtensionMsg,
DefaultOptionalCollectionExtensionMsg,
Empty,
>::SendNft {
contract: ics721,
token_id,
msg: to_json_binary(&IbcOutgoingMsg {
Expand Down
2 changes: 1 addition & 1 deletion contracts/ics721-base-tester/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct InstantiateMsg {
#[allow(clippy::large_enum_variant)] // `data` field is a bit large
// for clippy's taste.
pub enum ExecuteMsg {
ReceiveNft(cw721::Cw721ReceiveMsg),
ReceiveNft(cw721::receiver::Cw721ReceiveMsg),
Ics721ReceiveCallback(ics721_types::types::Ics721ReceiveCallbackMsg),
Ics721AckCallback(ics721_types::types::Ics721AckCallbackMsg),
SendNft {
Expand Down
4 changes: 2 additions & 2 deletions contracts/ics721-base-tester/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub const ACK_MODE: Item<AckMode> = Item::new("ack_mode");
pub const LAST_ACK: Item<AckMode> = Item::new("ack_mode");

pub const ICS721: Item<Addr> = Item::new("ics721");
pub const SENT_CALLBACK: Item<Option<cw721::OwnerOfResponse>> = Item::new("sent");
pub const RECEIVED_CALLBACK: Item<Option<cw721::OwnerOfResponse>> = Item::new("received");
pub const SENT_CALLBACK: Item<Option<cw721::msg::OwnerOfResponse>> = Item::new("sent");
pub const RECEIVED_CALLBACK: Item<Option<cw721::msg::OwnerOfResponse>> = Item::new("received");
pub const NFT_CONTRACT: Item<Addr> = Item::new("nft_contract");
pub const CW721_RECEIVE: Item<String> = Item::new("cw721_received");
2 changes: 1 addition & 1 deletion contracts/ics721-base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn execute(
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result<Binary, ContractError> {
Ics721Contract::default().query(deps, env, msg)
}

Expand Down
28 changes: 19 additions & 9 deletions contracts/sg-ics721/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use cosmwasm_std::{from_json, to_json_binary, Addr, Binary, Deps, DepsMut, Env, StdResult};
use ics721::{execute::Ics721Execute, state::CollectionData, utils::get_collection_data};
use ics721::{
execute::Ics721Execute,
state::{CollectionData, CW721_CREATOR},
utils::get_collection_data,
};
use ics721_types::token_types::Class;

use sg721_base::msg::{CollectionInfoResponse, QueryMsg};
Expand Down Expand Up @@ -33,20 +37,26 @@ impl Ics721Execute for SgIcs721Contract {
}

fn init_msg(&self, deps: Deps, env: &Env, class: &Class) -> StdResult<Binary> {
// ics721 creator is used, in case no source owner in class data is provided (e.g. due to nft-transfer module).
let ics721_contract_info = deps
.querier
.query_wasm_contract_info(env.contract.address.to_string())?;
let cw721_creator =
if let Some(creator) = CW721_CREATOR.load(deps.storage)?.map(|a| a.to_string()) {
creator
} else {
// NOTE: owner in class data comes from other chain and 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
let ics721_contract_info = deps
.querier
.query_wasm_contract_info(env.contract.address.to_string())?;
ics721_contract_info.creator
};
// use by default ClassId, in case there's no class data with name and symbol
let mut instantiate_msg = sg721::InstantiateMsg {
name: class.id.clone().into(),
symbol: class.id.clone().into(),
minter: env.contract.address.to_string(),
// creator: cw721_admin, // TODO: once sg721 migrates to cw721 v19, use cw721_admin for setting creator
collection_info: sg721::CollectionInfo {
// 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,
creator: cw721_creator,
description: "".to_string(),
// use Stargaze icon as placeholder
image: STARGAZE_ICON_PLACEHOLDER.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion contracts/sg-ics721/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn execute(
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result<Binary, ContractError> {
SgIcs721Contract::default().query(deps, env, msg)
}

Expand Down
Loading
Loading