From 687bdd098fe60b9ed4c6e861fb5f80e84c04e3aa Mon Sep 17 00:00:00 2001 From: ibrizsabin Date: Wed, 28 Aug 2024 12:39:49 +0545 Subject: [PATCH] fix: update cw20 msgs --- .../token-contracts/cw-hub-bnusd/Cargo.toml | 2 +- .../cw-hub-bnusd/src/contract.rs | 6 ++--- .../cw-hub-bnusd/src/cw20_adapter.rs | 27 ++++--------------- .../cw-hub-bnusd/src/events.rs | 2 +- 4 files changed, 10 insertions(+), 27 deletions(-) diff --git a/contracts/token-contracts/cw-hub-bnusd/Cargo.toml b/contracts/token-contracts/cw-hub-bnusd/Cargo.toml index e16f823..b4a8391 100644 --- a/contracts/token-contracts/cw-hub-bnusd/Cargo.toml +++ b/contracts/token-contracts/cw-hub-bnusd/Cargo.toml @@ -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" } @@ -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" } diff --git a/contracts/token-contracts/cw-hub-bnusd/src/contract.rs b/contracts/token-contracts/cw-hub-bnusd/src/contract.rs index 09fc5b4..47dd392 100644 --- a/contracts/token-contracts/cw-hub-bnusd/src/contract.rs +++ b/contracts/token-contracts/cw-hub-bnusd/src/contract.rs @@ -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; } @@ -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); diff --git a/contracts/token-contracts/cw-hub-bnusd/src/cw20_adapter.rs b/contracts/token-contracts/cw-hub-bnusd/src/cw20_adapter.rs index f6ac030..c6d91d3 100644 --- a/contracts/token-contracts/cw-hub-bnusd/src/cw20_adapter.rs +++ b/contracts/token-contracts/cw-hub-bnusd/src/cw20_adapter.rs @@ -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 }, - /// 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, @@ -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()), }; @@ -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(), diff --git a/contracts/token-contracts/cw-hub-bnusd/src/events.rs b/contracts/token-contracts/cw-hub-bnusd/src/events.rs index 45cb912..08c6d5c 100644 --- a/contracts/token-contracts/cw-hub-bnusd/src/events.rs +++ b/contracts/token-contracts/cw-hub-bnusd/src/events.rs @@ -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;