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

♻️ Replace custom impl of Coins with cw_std Coins #33

Merged
merged 1 commit into from
Jul 26, 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
14 changes: 7 additions & 7 deletions contracts/entry-point/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use crate::{
state::{BLOCKED_CONTRACT_ADDRESSES, IBC_TRANSFER_CONTRACT_ADDRESS, SWAP_VENUE_MAP},
};
use cosmwasm_std::{
to_binary, Addr, BankMsg, Binary, Coin, DepsMut, Env, MessageInfo, Response, Uint128, WasmMsg,
to_binary, Addr, BankMsg, Binary, Coin, Coins, DepsMut, Env, MessageInfo, Response, Uint128,
WasmMsg,
};
use cw_utils::one_coin;
use skip::{
coins::Coins,
entry_point::{Action, Affiliate, ExecuteMsg},
ibc::{ExecuteMsg as IbcTransferExecuteMsg, IbcInfo, IbcTransfer},
swap::{
Expand Down Expand Up @@ -52,7 +52,7 @@ pub fn execute_swap_and_action(
// is an IBC transfer, otherwise set it to None
let ibc_fees = match &post_swap_action {
Action::IbcTransfer { ibc_info } => ibc_info.fee.clone().try_into()?,
_ => Coins::new(),
_ => Coins::default(),
};

// Process the fee swap if it exists
Expand All @@ -75,7 +75,7 @@ pub fn execute_swap_and_action(
// with the IBC fees from the remaining coin received amount
remaining_coin_received.amount = remaining_coin_received
.amount
.checked_sub(ibc_fees.get_amount(&remaining_coin_received.denom))?;
.checked_sub(ibc_fees.amount_of(&remaining_coin_received.denom))?;
}

// Create the user swap message
Expand Down Expand Up @@ -288,7 +288,7 @@ fn verify_and_create_ibc_transfer_adapter_msg(
// Get the amount of the IBC fee payment that matches
// the denom of the ibc transfer out coin.
// If there is no denom match, then default to zero.
let transfer_out_coin_ibc_fee_amount = ibc_fees_map.get_amount(&min_coin.denom);
let transfer_out_coin_ibc_fee_amount = ibc_fees_map.amount_of(&min_coin.denom);

// Subtract the IBC fee amount from the transfer out coin
transfer_out_coin.amount = transfer_out_coin
Expand All @@ -305,7 +305,7 @@ fn verify_and_create_ibc_transfer_adapter_msg(
// (which is the transfer out coin plus the IBC fee amounts)
// using a map for convenience, and then converting to a vector of coins
let mut ibc_msg_funds_map = ibc_fees_map;
ibc_msg_funds_map.add_coin(&transfer_out_coin)?;
ibc_msg_funds_map.add(transfer_out_coin.clone())?;

// Convert the map to a vector of coins
let ibc_msg_funds: Vec<Coin> = ibc_msg_funds_map.into();
Expand Down Expand Up @@ -410,7 +410,7 @@ fn verify_and_create_fee_swap_msg(
)?;

// Verify the fee swap coin out amount less than or equal to the ibc fee amount
if fee_swap.coin_out.amount > ibc_fees.get_amount(&fee_swap.coin_out.denom) {
if fee_swap.coin_out.amount > ibc_fees.amount_of(&fee_swap.coin_out.denom) {
return Err(ContractError::FeeSwapCoinOutGreaterThanIbcFee);
}

Expand Down
5 changes: 2 additions & 3 deletions contracts/networks/osmosis/ibc-transfer/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ use crate::{
},
};
use cosmwasm_std::{
entry_point, to_binary, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo,
Reply, Response, SubMsg, SubMsgResult,
entry_point, to_binary, BankMsg, Binary, Coin, Coins, CosmosMsg, Deps, DepsMut, Env,
MessageInfo, Reply, Response, SubMsg, SubMsgResult,
};
use ibc_proto::ibc::applications::transfer::v1::{MsgTransfer, MsgTransferResponse};
use prost::Message;
use serde_cw_value::Value;
use skip::{
coins::Coins,
ibc::{
AckID, ExecuteMsg, IbcFee, IbcInfo, IbcLifecycleComplete, InstantiateMsg,
OsmosisQueryMsg as QueryMsg,
Expand Down
74 changes: 0 additions & 74 deletions packages/skip/src/coins.rs

This file was deleted.

18 changes: 17 additions & 1 deletion packages/skip/src/ibc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::proto_coin::ProtoCoin;
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::Coin;
use cosmwasm_std::{Coin, Coins, StdError};
use neutron_proto::neutron::feerefunder::Fee as NeutronFee;
use std::convert::From;

Expand Down Expand Up @@ -84,6 +84,22 @@ impl From<IbcFee> for NeutronFee {
}
}

// Converts an IbcFee struct to a Coins struct
impl TryFrom<IbcFee> for Coins {
type Error = StdError;

fn try_from(ibc_fee: IbcFee) -> Result<Self, Self::Error> {
let mut ibc_fees = Coins::default();

[ibc_fee.recv_fee, ibc_fee.ack_fee, ibc_fee.timeout_fee]
.into_iter()
.flatten()
.try_for_each(|coin| ibc_fees.add(coin))?;

Ok(ibc_fees)
}
}

#[cw_serde]
pub struct IbcInfo {
pub source_channel: String,
Expand Down
1 change: 0 additions & 1 deletion packages/skip/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod coins;
pub mod entry_point;
pub mod error;
pub mod ibc;
Expand Down