Skip to content

Commit

Permalink
Merge pull request #71 from arkprotocol/main
Browse files Browse the repository at this point in the history
instantiate2
  • Loading branch information
humanalgorithm authored Nov 17, 2023
2 parents 5f44728 + f01048b commit 4fe21cc
Show file tree
Hide file tree
Showing 53 changed files with 2,701 additions and 1,334 deletions.
346 changes: 155 additions & 191 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@ cw721-base = "0.18"
cw721-base-016 = { version = "0.16.0", package = "cw721-base" }
cw721-proxy-derive = { git = "https://github.com/arkprotocol/cw721-proxy.git", tag = "v0.0.7" }
cw721-rate-limited-proxy = { git = "https://github.com/arkprotocol/cw721-proxy.git", tag = "v0.0.7" }
cw-multi-test = "0.16"
cw-multi-test = { version = "0.18", features = ["cosmwasm_1_2"] }
cw-utils = "1.0"
sha2 = "^0.10"
serde = "1.0"
thiserror = "1"
# Stargaze libs
sg-std = "3.0"
sg-std = "^3.2"
sg-multi-test = "^3.1"
sg721 = "^3.1"
sg721-240 = { version = "^2.4", package = "sg721" }
sg721-base = "^3.1"
sg721-base-240 = { version = "^2.4", package = "sg721-base" }
# packages and contracts
cw-cii = { path = "./packages/cw-cii" }
cw-pause-once = { path = "./packages/cw-pause-once" }
Expand Down
6 changes: 3 additions & 3 deletions contracts/ics721-base-tester/src/ack.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{to_binary, Binary};
use cosmwasm_std::{to_json_binary, Binary};

/// IBC ACK. See:
/// https://github.com/cosmos/cosmos-sdk/blob/f999b1ff05a4db4a338a855713864497bedd4396/proto/ibc/core/channel/v1/channel.proto#L141-L147
Expand All @@ -11,10 +11,10 @@ pub enum Ack {

pub fn make_ack_success() -> Binary {
let res = Ack::Result(b"1".into());
to_binary(&res).unwrap()
to_json_binary(&res).unwrap()
}

pub fn make_ack_fail(err: String) -> Binary {
let res = Ack::Error(err);
to_binary(&res).unwrap()
to_json_binary(&res).unwrap()
}
9 changes: 5 additions & 4 deletions contracts/ics721-base-tester/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Binary, Deps, DepsMut, Env, IbcMsg, IbcTimeout, MessageInfo, Response, StdResult,
to_json_binary, Binary, Deps, DepsMut, Env, IbcMsg, IbcTimeout, MessageInfo, Response,
StdResult,
};
use cw2::set_contract_version;
use ics721::ibc::NonFungibleTokenPacketData;
Expand Down Expand Up @@ -54,7 +55,7 @@ fn execute_send_packet(
.add_attribute("method", "send_packet")
.add_message(IbcMsg::SendPacket {
channel_id,
data: to_binary(&data)?,
data: to_json_binary(&data)?,
timeout,
}))
}
Expand All @@ -71,7 +72,7 @@ fn execute_set_ack_mode(deps: DepsMut, ack_mode: AckMode) -> Result<Response, Co
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::AckMode {} => to_binary(&ACK_MODE.load(deps.storage)?),
QueryMsg::LastAck {} => to_binary(&LAST_ACK.load(deps.storage)?),
QueryMsg::AckMode {} => to_json_binary(&ACK_MODE.load(deps.storage)?),
QueryMsg::LastAck {} => to_json_binary(&LAST_ACK.load(deps.storage)?),
}
}
4 changes: 2 additions & 2 deletions contracts/ics721-base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use cosmwasm_std::entry_point;
use cosmwasm_std::{
Binary, Deps, DepsMut, Env, IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg,
IbcChannelOpenMsg, IbcChannelOpenResponse, IbcPacketAckMsg, IbcPacketReceiveMsg,
IbcPacketTimeoutMsg, IbcReceiveResponse, MessageInfo, Reply, Response, StdResult,
IbcPacketTimeoutMsg, IbcReceiveResponse, MessageInfo, Never, Reply, Response, StdResult,
};
use cw2::set_contract_version;
use ics721::{
error::{ContractError, Never},
error::ContractError,
execute::Ics721Execute,
ibc::Ics721Ibc,
msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg},
Expand Down
3 changes: 1 addition & 2 deletions contracts/sg-ics721/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ cw-storage-plus = { workspace = true }
cw721 = { workspace = true}
cw721-rate-limited-proxy = { workspace = true }
cw721-base = { workspace = true}
sg721-240 = { workspace = true}
sg721-base-240 = { workspace = true, features = ["library"] }
sha2 = { workspace = true }
69 changes: 39 additions & 30 deletions contracts/sg-ics721/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{from_binary, to_binary, Addr, Binary, Deps, DepsMut, Env, StdResult};
use cosmwasm_std::{from_json, to_json_binary, Addr, Binary, Deps, DepsMut, Env, StdResult};
use ics721::{
execute::Ics721Execute,
state::CollectionData,
Expand Down Expand Up @@ -36,45 +36,54 @@ impl Ics721Execute for SgIcs721Contract {
}

fn init_msg(&self, deps: Deps, env: &Env, class: &Class) -> StdResult<Binary> {
let creator = match class.data.clone() {
None => {
// in case no class data is provided (e.g. due to nft-transfer module), ics721 creator is used.
let contract_info = deps
.querier
.query_wasm_contract_info(env.contract.address.to_string())?;
contract_info.creator
}
Some(data) => {
// class data may be any custom type. Check whether it is `ics721::state::CollectionData` or not.
let class_data_result: StdResult<CollectionData> = from_binary(&data);
if class_data_result.is_err() {
// this happens only for unknown class data, like source chain uses nft-transfer module
env.contract.address.to_string()
} else {
let class_data = class_data_result?;

match class_data.owner {
Some(owner) => convert_owner_chain_address(env, owner.as_str())?,
None => env.contract.address.to_string(),
}
}
}
};
to_binary(&sg721::InstantiateMsg {
// Name of the collection MUST be class_id as this is how
// we create a map entry on reply.
// 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 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(),
collection_info: sg721::CollectionInfo {
creator,
creator: ics721_contract_info.creator,
description: "".to_string(),
image: "https://arkprotocol.io".to_string(),
external_link: None,
explicit_content: None,
start_trading_time: None,
royalty_info: None,
},
})
};

// 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<CollectionData> = 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;
}
}

to_json_binary(&instantiate_msg)
}
}
4 changes: 2 additions & 2 deletions contracts/sg-ics721/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use cosmwasm_std::entry_point;
use cosmwasm_std::{
Binary, Deps, DepsMut, Env, IbcBasicResponse, IbcChannelCloseMsg, IbcChannelConnectMsg,
IbcChannelOpenMsg, IbcChannelOpenResponse, IbcPacketAckMsg, IbcPacketReceiveMsg,
IbcPacketTimeoutMsg, IbcReceiveResponse, MessageInfo, Reply, Response, StdResult,
IbcPacketTimeoutMsg, IbcReceiveResponse, MessageInfo, Never, Reply, Response, StdResult,
};
use cw2::set_contract_version;
use ics721::{
error::{ContractError, Never},
error::ContractError,
execute::Ics721Execute,
ibc::Ics721Ibc,
msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg},
Expand Down
Loading

0 comments on commit 4fe21cc

Please sign in to comment.