Skip to content

Commit

Permalink
fix fee calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Oct 9, 2023
1 parent bfc52ea commit a291e5b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,17 @@ hermes create channel --a-chain pion-1 --a-port transfer --b-port transfer --a-c
// created "channel-189 <-> channel-3235" for testnet

## 2. setup contracts
node ./lib/index.js setup_contracts "$MNEMONICS" "$ENDPOINT" "connection-120" "channel-189" "$IBC_DENOM" 1
node ./lib/index.js setup_contracts "$MNEMONICS" "$ENDPOINT" "connection-120" "channel-189" "$IBC_DENOM"

// Result contracts:
// {
// "creditsAddress": "neutron1n9hd7zmacfx0v2azep9e0xzwq5ya3n3c326uvpsy9jg22hy0nftq67fccf",
// "airdropAddress": "neutron1rvjk7kd7la4n39pqnmz434nxcf2f5sejm84ghs4s8vqfrnejxmxqarcqkq",
// "claimerAddress": "neutron1pnwclfjh998gtetemyte7xkyfjqpkfa3guq9gfpdduuuu90txmysw6p49s"
// }
// {"creditsAddress":"neutron10q0glxwhdn0mv29ggrzcwdy79e6gxv4046qxdjqgyvda5jh5jqfqfz85q7","airdropAddress":"neutron1u6pcnyzhjfz374pv6pudpt9l2gv4ydwkx86darsh9n70jksu0cys3wsnug","claimerAddress":"neutron1uwkmkxpnu9v7wvyxptgdpdhmadjxzxau5xgy2e76nx3flnpxv37ss09cny"}

## 3. run steps
CLAIMER_ADDRESS="neutron1pnwclfjh998gtetemyte7xkyfjqpkfa3guq9gfpdduuuu90txmysw6p49s"
CLAIMER_ADDRESS="neutron1uwkmkxpnu9v7wvyxptgdpdhmadjxzxau5xgy2e76nx3flnpxv37ss09cny"

node ./lib/index.js step_1 "$MNEMONICS" "$ENDPOINT" "$CLAIMER_ADDRESS"
node ./lib/index.js step_2 "$MNEMONICS" "$ENDPOINT" "$CLAIMER_ADDRESS"
//ICA address: {"port_id":"icacontroller-neutron1pnwclfjh998gtetemyte7xkyfjqpkfa3guq9gfpdduuuu90txmysw6p49s.neutron-funder","address":"cosmos1jdk6z4lf22danu25cn0efp48qh4khzskkyfrp8cvyxh8qvntzwdslwfmm7","controller_connection_id":"connection-120"}
ICA address: {"port_id":"icacontroller-neutron1uwkmkxpnu9v7wvyxptgdpdhmadjxzxau5xgy2e76nx3flnpxv37ss09cny.neutron-funder","address":"cosmos1ftcz03upaklszh7tmusl95qmmnmnknlyu4pa26a46vzzgq3y2fcshlp2cu","controller_connection_id":"connection-120"}

node ./lib/index.js step_3 "$MNEMONICS" "$ENDPOINT" "$CLAIMER_ADDRESS"
node ./lib/index.js step_4 "$MNEMONICS" "$ENDPOINT" "$CLAIMER_ADDRESS"
Expand Down
26 changes: 20 additions & 6 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cosmos_sdk_proto::cosmos::distribution::v1beta1::MsgFundCommunityPool;
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Binary, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdError,
StdResult, WasmMsg,
StdResult, Uint128, WasmMsg,
};
use cw2::set_contract_version;
use prost::Message;
Expand Down Expand Up @@ -132,7 +132,7 @@ fn execute_send_claimed_tokens_to_ica(
.querier
.query_balance(env.contract.address.clone(), NEUTRON_DENOM)?;

let fee_from_msg = info
let fee_funds = info
.funds
.iter()
.find(|c| c.denom == NEUTRON_DENOM)
Expand All @@ -144,14 +144,28 @@ fn execute_send_claimed_tokens_to_ica(
.clone();

let neutron_to_send = Coin::new(
(neutron_on_balance.amount - fee_from_msg.amount).u128(),
(neutron_on_balance.amount - fee_funds.amount).u128(),
NEUTRON_DENOM,
);
let ack_fee = fee_funds.amount / Uint128::new(2) + fee_funds.amount % Uint128::new(2);
let timeout_fee = fee_funds.amount / Uint128::new(2);
if ack_fee + timeout_fee != fee_funds.amount {
return Err(NeutronError::Std(StdError::generic_err(format!(
"incorrect total fee calculated: {:?}",
ack_fee + timeout_fee
))));
}

let fee = IbcFee {
recv_fee: vec![Coin::new(0, "untrn")],
ack_fee: vec![fee_from_msg.clone()],
timeout_fee: vec![fee_from_msg],
recv_fee: vec![Coin::new(0, NEUTRON_DENOM)],
ack_fee: vec![Coin {
amount: ack_fee,
denom: NEUTRON_DENOM.to_string(),
}],
timeout_fee: vec![Coin {
amount: timeout_fee,
denom: NEUTRON_DENOM.to_string(),
}],
};

TRANSFER_AMOUNT.save(deps.storage, &neutron_to_send.amount)?;
Expand Down

0 comments on commit a291e5b

Please sign in to comment.