diff --git a/README.md b/README.md index 7d38fd0..b3b2248 100644 --- a/README.md +++ b/README.md @@ -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" diff --git a/src/contract.rs b/src/contract.rs index e2f6127..2c02e5d 100644 --- a/src/contract.rs +++ b/src/contract.rs @@ -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; @@ -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) @@ -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)?;