Skip to content

Commit

Permalink
fix: update cw20 msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrizsabin committed Aug 28, 2024
1 parent 0e3672a commit 687bdd0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 27 deletions.
2 changes: 1 addition & 1 deletion contracts/token-contracts/cw-hub-bnusd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ cw-common = { path = "../../cw-common" }
hex = "0.4.3"
debug_print = {workspace=true}
cw_ibc_rlp_lib = {git = "https://github.com/icon-project/IBC-Integration.git", branch="main", package = "common"}
cw20-adapter = { git= "https://github.com/InjectiveLabs/cw20-adapter.git",branch="master", features=["library"]}
# cw20-base = { path = "../../cw20-base" }


Expand All @@ -59,7 +60,6 @@ cw-xcall-multi = {package="cw-xcall", git="https://github.com/icon-project/xcall
cw-common-ibc = {package="cw-common", git = "https://github.com/icon-project/IBC-Integration.git", branch="main" }
cw_xcall_ibc_connection = { git = "https://github.com/icon-project/IBC-Integration.git", package = "cw-mock-ibc-connection", branch="feat/mock-ibc-connection-balanced-test" }
cw_mock_ibc_core = { git = "https://github.com/icon-project/IBC-Integration.git", branch="main", package="cw-mock-ibc-core" }
cw20-adapter = { git= "https://github.com/InjectiveLabs/cw20-adapter.git",branch="master", features=["library"]}
anyhow = { version = "1.0", default-features = false }
getrandom = { version = "0.2", features = ["custom"] }
cw-xcall-manager = { path = "../../core-contracts/cw-xcall-manager" }
Expand Down
6 changes: 3 additions & 3 deletions contracts/token-contracts/cw-hub-bnusd/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ mod execute {

#[cfg(feature = "injective")]
{
let adapter = CW20_ADAPTER.load(deps.storage)?;
let (adpater_funds, other) = adapter.split_adapter_funds(&info);
let adapter: CW20Adapter = CW20_ADAPTER.load(deps.storage)?;
let (_adpater_funds, other) = adapter.split_adapter_funds(&info);
info.funds = other;
}

Expand Down Expand Up @@ -378,7 +378,7 @@ mod execute {
.expect("Failed To Increase Allowance")
.add_attribute("method", "cross_transfer")
.add_event(event);
if (tf_tokens > 0) {
if tf_tokens > 0 {
response = response.add_submessage(adapter.redeem(tf_tokens, &info.sender));
}
response = response.add_submessage(sub_message);
Expand Down
27 changes: 5 additions & 22 deletions contracts/token-contracts/cw-hub-bnusd/src/cw20_adapter.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::SubMsg;
use cosmwasm_std::{coin, to_binary, Addr, BankMsg, Binary, CosmosMsg, Deps, Env, WasmMsg};
use cosmwasm_std::{Coin, MessageInfo, Uint128};
use cosmwasm_std::{coin, to_binary, Addr, BankMsg, Binary, CosmosMsg, WasmMsg};
use cosmwasm_std::{Coin, MessageInfo};
use cw20_adapter::msg::ExecuteMsg as Cw20AdapterMsg;
use cw_common::hub_token_msg::ExecuteMsg as TokenExecuteMsg;

#[cw_serde]
pub enum RegistryExecuteMsg {
/// Registers a new CW-20 contract that will be handled by the adapter
RegisterCw20Contract { addr: Addr },
/// Impl of Receiver CW-20 interface. Should be called by CW-20 contract only!! (never directly). Msg is ignored
Receive {
sender: String,
amount: Uint128,
msg: Binary,
},
/// Called to redeem TF tokens. Will send CW-20 tokens to "recipient" address (or sender if not provided). Will use transfer method
RedeemAndTransfer { recipient: Option<String> },
/// Called to redeem TF tokens. Will call Send method of CW:20 to send CW-20 tokens to "recipient" address. Submessage will be passed to send method (can be empty)
RedeemAndSend { recipient: String, submsg: Binary },
/// Updates stored metadata
UpdateMetadata { addr: Addr },
}

#[cw_serde]
pub struct CW20Adapter {
token_contract: Addr,
Expand All @@ -38,7 +21,7 @@ impl CW20Adapter {
// convert specified TF tokens to our token and transfer to receiver
pub fn redeem(&self, amount: u128, receiver: &Addr) -> SubMsg {
let fund = coin(amount, self.denom());
let message = RegistryExecuteMsg::RedeemAndTransfer {
let message = Cw20AdapterMsg::RedeemAndTransfer {
recipient: Some(receiver.to_string()),
};

Expand All @@ -59,7 +42,7 @@ impl CW20Adapter {
pub fn receive(&self, receiver: &Addr, amount: u128) -> SubMsg {
let msg = CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: self.adapter_contract.to_string(),
msg: to_binary(&RegistryExecuteMsg::Receive {
msg: to_binary(&Cw20AdapterMsg::Receive {
sender: receiver.to_string(),
amount: amount.into(),
msg: Binary::default(),
Expand Down
2 changes: 1 addition & 1 deletion contracts/token-contracts/cw-hub-bnusd/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{Addr, Event, MessageInfo};
use cosmwasm_std::{Addr, Event};
use cw_common::network_address::NetworkAddress;
use debug_print::debug_println;

Expand Down

0 comments on commit 687bdd0

Please sign in to comment.