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

Add minting recipient for AssetNFT and AssetFT, and SetFrozen for AssetFT on wasm #703

Merged
merged 2 commits into from
Nov 7, 2023
Merged
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
22 changes: 11 additions & 11 deletions integration-tests/contracts/modules/ft/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions integration-tests/contracts/modules/ft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ backtraces = ["cosmwasm-std/backtraces"]
library = []

[dependencies]
cosmwasm-std = "1.4.1"
cosmwasm-storage = "1.4.1"
cosmwasm-std = "1.5.0"
cosmwasm-storage = "1.5.0"
cw-storage-plus = "1.1.0"
cw2 = "1.1.1"
thiserror = "1.0.50"
coreum-wasm-sdk = "0.2.1"
coreum-wasm-sdk = "0.2.3"
cosmwasm-schema = "1.4.1"
cw-ownable = "0.5.1"
8 changes: 2 additions & 6 deletions integration-tests/contracts/modules/ft/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ For more detailed information of the AssetFT module and functionality go to [Ass

# Messages

### Mint (amount) [Mint](https://github.com/CoreumFoundation/coreum/tree/master/x/asset/ft/spec#mint)
### Mint (amount, recipient) [Mint](https://github.com/CoreumFoundation/coreum/tree/master/x/asset/ft/spec#mint)

The contract (issuer) will mint the amount of tokens provided.
The contract (issuer) will mint the amount of tokens provided to the corresponding recipient.

### Burn (amount) [Burn](https://github.com/CoreumFoundation/coreum/tree/master/x/asset/ft/spec#burn)

Expand All @@ -55,10 +55,6 @@ Globally unfreezes the token.

Sets a whitelisted limit for an account.

### MintAndSend (account, amount)

Combines the Mint feature described above with a bank transfer for convenience.

# Queries

### Params
Expand Down
76 changes: 35 additions & 41 deletions integration-tests/contracts/modules/ft/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use coreum_wasm_sdk::assetft::{
};
use coreum_wasm_sdk::core::{CoreumMsg, CoreumQueries, CoreumResult};
use coreum_wasm_sdk::pagination::PageRequest;
use cosmwasm_std::{coin, entry_point, to_binary, Binary, Deps, QueryRequest, StdResult};
use cosmwasm_std::{Coin, DepsMut, Env, MessageInfo, Response, SubMsg};
use cosmwasm_std::{coin, entry_point, to_json_binary, Binary, Deps, QueryRequest, StdResult};
use cosmwasm_std::{DepsMut, Env, MessageInfo, Response};
use cw2::set_contract_version;
use cw_ownable::{assert_owner, initialize_owner};

Expand Down Expand Up @@ -62,27 +62,28 @@ pub fn execute(
msg: ExecuteMsg,
) -> CoreumResult<ContractError> {
match msg {
ExecuteMsg::Mint { amount } => mint(deps, info, amount),
ExecuteMsg::Mint { amount, recipient } => mint(deps, info, amount, recipient),
ExecuteMsg::Burn { amount } => burn(deps, info, amount),
ExecuteMsg::Freeze { account, amount } => freeze(deps, info, account, amount),
ExecuteMsg::Unfreeze { account, amount } => unfreeze(deps, info, account, amount),
ExecuteMsg::SetFrozen { account, amount } => set_frozen(deps, info, account, amount),
ExecuteMsg::GloballyFreeze {} => globally_freeze(deps, info),
ExecuteMsg::GloballyUnfreeze {} => globally_unfreeze(deps, info),
ExecuteMsg::SetWhitelistedLimit { account, amount } => {
set_whitelisted_limit(deps, info, account, amount)
}
ExecuteMsg::MintAndSend { account, amount } => mint_and_send(deps, info, account, amount),
ExecuteMsg::UpgradeTokenV1 { ibc_enabled } => upgrate_token_v1(deps, info, ibc_enabled),
}
}

// ********** Transactions **********

fn mint(deps: DepsMut, info: MessageInfo, amount: u128) -> CoreumResult<ContractError> {
fn mint(deps: DepsMut, info: MessageInfo, amount: u128, recipient: Option<String>) -> CoreumResult<ContractError> {
assert_owner(deps.storage, &info.sender)?;
let denom = DENOM.load(deps.storage)?;
let msg = CoreumMsg::AssetFT(assetft::Msg::Mint {
coin: coin(amount, denom.clone()),
recipient,
});

Ok(Response::new()
Expand Down Expand Up @@ -149,6 +150,27 @@ fn unfreeze(
.add_message(msg))
}

fn set_frozen(
deps: DepsMut,
info: MessageInfo,
account: String,
amount: u128,
) -> CoreumResult<ContractError> {
assert_owner(deps.storage, &info.sender)?;
let denom = DENOM.load(deps.storage)?;

let msg = CoreumMsg::AssetFT(assetft::Msg::SetFrozen {
account,
coin: coin(amount, denom.clone()),
});

Ok(Response::new()
.add_attribute("method", "set_frozen")
.add_attribute("denom", denom)
.add_attribute("amount", amount.to_string())
.add_message(msg))
}

fn globally_freeze(deps: DepsMut, info: MessageInfo) -> CoreumResult<ContractError> {
assert_owner(deps.storage, &info.sender)?;
let denom = DENOM.load(deps.storage)?;
Expand Down Expand Up @@ -198,34 +220,6 @@ fn set_whitelisted_limit(
.add_message(msg))
}

fn mint_and_send(
deps: DepsMut,
info: MessageInfo,
account: String,
amount: u128,
) -> CoreumResult<ContractError> {
assert_owner(deps.storage, &info.sender)?;
let denom = DENOM.load(deps.storage)?;

let mint_msg = SubMsg::new(CoreumMsg::AssetFT(assetft::Msg::Mint {
coin: coin(amount, denom.clone()),
}));

let send_msg = SubMsg::new(cosmwasm_std::BankMsg::Send {
to_address: account,
amount: vec![Coin {
amount: amount.into(),
denom: denom.clone(),
}],
});

Ok(Response::new()
.add_attribute("method", "mint_and_send")
.add_attribute("denom", denom)
.add_attribute("amount", amount.to_string())
.add_submessages([mint_msg, send_msg]))
}

fn upgrate_token_v1(
deps: DepsMut,
info: MessageInfo,
Expand All @@ -250,17 +244,17 @@ fn upgrate_token_v1(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps<CoreumQueries>, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Params {} => to_binary(&query_params(deps)?),
QueryMsg::Token {} => to_binary(&query_token(deps)?),
QueryMsg::Tokens { issuer } => to_binary(&query_tokens(deps, issuer)?),
QueryMsg::FrozenBalance { account } => to_binary(&query_frozen_balance(deps, account)?),
QueryMsg::Params {} => to_json_binary(&query_params(deps)?),
QueryMsg::Token {} => to_json_binary(&query_token(deps)?),
QueryMsg::Tokens { issuer } => to_json_binary(&query_tokens(deps, issuer)?),
QueryMsg::FrozenBalance { account } => to_json_binary(&query_frozen_balance(deps, account)?),
QueryMsg::WhitelistedBalance { account } => {
to_binary(&query_whitelisted_balance(deps, account)?)
to_json_binary(&query_whitelisted_balance(deps, account)?)
}
QueryMsg::Balance { account } => to_binary(&query_balance(deps, account)?),
QueryMsg::FrozenBalances { account } => to_binary(&query_frozen_balances(deps, account)?),
QueryMsg::Balance { account } => to_json_binary(&query_balance(deps, account)?),
QueryMsg::FrozenBalances { account } => to_json_binary(&query_frozen_balances(deps, account)?),
QueryMsg::WhitelistedBalances { account } => {
to_binary(&query_whitelisted_balances(deps, account)?)
to_json_binary(&query_whitelisted_balances(deps, account)?)
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions integration-tests/contracts/modules/ft/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ pub struct InstantiateMsg {

#[cw_serde]
pub enum ExecuteMsg {
Mint { amount: u128 },
Mint { amount: u128, recipient: Option<String> },
Burn { amount: u128 },
Freeze { account: String, amount: u128 },
Unfreeze { account: String, amount: u128 },
SetFrozen { account: String, amount: u128 },
GloballyFreeze {},
GloballyUnfreeze {},
SetWhitelistedLimit { account: String, amount: u128 },
// custom message we use to show the submission of multiple messages
MintAndSend { account: String, amount: u128 },
UpgradeTokenV1 { ibc_enabled: bool },
}

Expand Down
9 changes: 5 additions & 4 deletions integration-tests/contracts/modules/nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ type IssueNFTRequest struct {
//
//nolint:tagliatelle
type NftMintRequest struct {
ID string `json:"id"`
URI string `json:"uri"`
URIHash string `json:"uri_hash"`
Data string `json:"data"`
ID string `json:"id"`
URI string `json:"uri"`
URIHash string `json:"uri_hash"`
Data string `json:"data"`
Recipient string `json:"recipient"`
}

// NftIDRequest is used to query NFT with ID.
Expand Down
22 changes: 11 additions & 11 deletions integration-tests/contracts/modules/nft/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions integration-tests/contracts/modules/nft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ backtraces = ["cosmwasm-std/backtraces"]
library = []

[dependencies]
cosmwasm-std = "1.4.1"
cosmwasm-storage = "1.4.1"
cosmwasm-std = "1.5.0"
cosmwasm-storage = "1.5.0"
cw-storage-plus = "1.1.0"
cw2 = "1.1.1"
thiserror = { version = "1.0.50" }
coreum-wasm-sdk = "0.2.1"
cosmwasm-schema = "1.4.1"
coreum-wasm-sdk = "0.2.3"
cosmwasm-schema = "1.5.0"
cw-ownable = "0.5.1"
Loading