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

Bump test-tube, remove deprecated and add new Mint with recipient message #42

Merged
merged 1 commit into from
Nov 8, 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
63 changes: 39 additions & 24 deletions contract/Cargo.lock

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

4 changes: 2 additions & 2 deletions contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ incremental = false
overflow-checks = true

[dependencies]
coreum-wasm-sdk = "0.2.0"
coreum-wasm-sdk = "0.2.3"
cosmwasm-schema = "1.4.1"
cosmwasm-std = { version = "1.4.1", features = ["cosmwasm_1_1"] }
cw-ownable = "0.5.1"
Expand All @@ -37,5 +37,5 @@ sha2 = "0.10.8"
thiserror = "1.0.49"

[dev-dependencies]
coreum-test-tube = "3.0.0"
coreum-test-tube = "3.0.1"
rand = "0.8.5"
59 changes: 22 additions & 37 deletions contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use coreum_wasm_sdk::{
core::{CoreumMsg, CoreumQueries, CoreumResult},
};
use cosmwasm_std::{
coin, coins, entry_point, to_binary, Addr, Binary, CosmosMsg, Deps, DepsMut, Empty, Env,
coin, entry_point, to_json_binary, Addr, Binary, CosmosMsg, Deps, DepsMut, Empty, Env,
MessageInfo, Order, Response, StdResult, Uint128,
};
use cw2::set_contract_version;
Expand Down Expand Up @@ -109,8 +109,10 @@ pub fn instantiate(
initial_amount: Uint128::zero(),
description: None,
features: Some(vec![MINTING, BURNING, IBC]),
burn_rate: Some("0.0".to_string()),
send_commission_rate: Some("0.0".to_string()),
burn_rate: "0.0".to_string(),
send_commission_rate: "0.0".to_string(),
uri: None,
uri_hash: None,
}));

let xrp_in_coreum = format!("{}-{}", XRP_SUBUNIT, env.contract.address).to_lowercase();
Expand Down Expand Up @@ -285,8 +287,10 @@ fn register_xrpl_token(
initial_amount: Uint128::zero(),
description: None,
features: Some(vec![MINTING, BURNING, IBC]),
burn_rate: Some("0.0".to_string()),
send_commission_rate: Some("0.0".to_string()),
burn_rate: "0.0".to_string(),
send_commission_rate: "0.0".to_string(),
uri: None,
uri_hash: None,
}));

// Denom that token will have in Coreum
Expand Down Expand Up @@ -382,12 +386,12 @@ fn save_evidence(deps: DepsMut, sender: Addr, evidence: Evidence) -> CoreumResul
}

if threshold_reached {
response = add_mint_and_send(
response,
amount_to_send,
token.coreum_denom,
recipient.clone(),
);
let mint_msg = CosmosMsg::from(CoreumMsg::AssetFT(assetft::Msg::Mint {
coin: coin(amount_to_send.u128(), token.coreum_denom),
recipient: Some(recipient.to_string()),
}));

response = response.add_message(mint_msg)
}

response = response
Expand Down Expand Up @@ -539,17 +543,17 @@ fn register_signature(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Config {} => to_binary(&query_config(deps)?),
QueryMsg::Config {} => to_json_binary(&query_config(deps)?),
QueryMsg::XRPLTokens { offset, limit } => {
to_binary(&query_xrpl_tokens(deps, offset, limit)?)
to_json_binary(&query_xrpl_tokens(deps, offset, limit)?)
}
QueryMsg::CoreumTokens { offset, limit } => {
to_binary(&query_coreum_tokens(deps, offset, limit)?)
to_json_binary(&query_coreum_tokens(deps, offset, limit)?)
}
QueryMsg::CoreumToken { denom } => to_binary(&query_coreum_token(deps, denom)?),
QueryMsg::Ownership {} => to_binary(&get_ownership(deps.storage)?),
QueryMsg::PendingOperations {} => to_binary(&query_pending_operations(deps)?),
QueryMsg::AvailableTickets {} => to_binary(&query_available_tickets(deps)?),
QueryMsg::CoreumToken { denom } => to_json_binary(&query_coreum_token(deps, denom)?),
QueryMsg::Ownership {} => to_json_binary(&get_ownership(deps.storage)?),
QueryMsg::PendingOperations {} => to_json_binary(&query_pending_operations(deps)?),
QueryMsg::AvailableTickets {} => to_json_binary(&query_available_tickets(deps)?),
}
}

Expand Down Expand Up @@ -632,25 +636,6 @@ fn check_issue_fee(deps: &DepsMut<CoreumQueries>, info: &MessageInfo) -> Result<
Ok(())
}

// TODO(keyleu): In the future we might have a way to do this in one instruction.
fn add_mint_and_send(
response: Response<CoreumMsg>,
amount: Uint128,
denom: String,
recipient: Addr,
) -> Response<CoreumMsg> {
let mint_msg = CosmosMsg::from(CoreumMsg::AssetFT(assetft::Msg::Mint {
coin: coin(amount.u128(), denom.clone()),
}));

let send_msg = CosmosMsg::Bank(cosmwasm_std::BankMsg::Send {
to_address: recipient.to_string(),
amount: coins(amount.u128(), denom),
});

response.add_messages([mint_msg, send_msg])
}

pub fn build_xrpl_token_key(issuer: String, currency: String) -> String {
// Issuer+currency is the key we use to find an XRPL
let mut key = issuer;
Expand Down
2 changes: 2 additions & 0 deletions contract/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ mod tests {
],
burn_rate: "0".to_string(),
send_commission_rate: "0".to_string(),
uri: "".to_string(),
uri_hash: "".to_string(),
version: 1
}
);
Expand Down
Loading