Skip to content

Commit 46dd514

Browse files
committed
Shielded frontend fee target for incoming IBC packets
1 parent 66a008d commit 46dd514

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

crates/apps_lib/src/cli.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3693,13 +3693,14 @@ pub mod args {
36933693
pub const TARGET: Arg<WalletAddress> = arg("target");
36943694
pub const TARGET_OPT: ArgOpt<WalletAddress> = arg_opt("target");
36953695
pub const TEMPLATES_PATH: Arg<PathBuf> = arg("templates-path");
3696+
// FIXME: add the test prelude in the cli args too
36963697
// WARNING: use only for testing purposes, MASP frontend fees don't make
36973698
// sense when operating from the CLI
36983699
pub const __TEST_FRONTEND_SUS_FEE: ArgOpt<WalletAddress> =
36993700
arg_opt("frontend-sus-fee");
37003701
// WARNING: use only for testing purposes, MASP frontend fees don't make
37013702
// sense when operating from the CLI
3702-
pub const __TEST_FRONTEND_SUS_FEE_IBC: ArgOpt<WalletAddress> =
3703+
pub const __TEST_FRONTEND_SUS_FEE_IBC: ArgOpt<WalletPaymentAddr> =
37033704
arg_opt("frontend-sus-fee-ibc");
37043705
pub const TIMEOUT_HEIGHT: ArgOpt<u64> = arg_opt("timeout-height");
37053706
pub const TIMEOUT_SEC_OFFSET: ArgOpt<u64> = arg_opt("timeout-sec-offset");
@@ -5200,6 +5201,12 @@ pub mod args {
52005201
let chain_ctx = ctx.borrow_mut_chain_or_exit();
52015202
let gas_spending_key =
52025203
self.gas_spending_key.map(|key| chain_ctx.get_cached(&key));
5204+
let frontend_sus_fee =
5205+
self.frontend_sus_fee.map(|fee| TxTransparentTarget {
5206+
target: chain_ctx.get(&fee.target),
5207+
token: chain_ctx.get(&fee.token),
5208+
amount: fee.amount,
5209+
});
52035210

52045211
Ok(TxIbcTransfer::<SdkTypes> {
52055212
tx,
@@ -5216,7 +5223,7 @@ pub mod args {
52165223
ibc_memo: self.ibc_memo,
52175224
gas_spending_key,
52185225
tx_code_path: self.tx_code_path.to_path_buf(),
5219-
frontend_sus_fee: None,
5226+
frontend_sus_fee,
52205227
})
52215228
}
52225229
}

crates/sdk/src/args.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ pub struct TxOsmosisSwap<C: NamadaTypes = SdkTypes> {
549549
/// The optional data for the frontend sustainability fee
550550
/// NOTE: if the swap is shielded (from MASP to MASP), no sustainability
551551
/// fee should be taken
552-
pub frontend_sus_fee: Option<(C::Address, InputAmount)>,
552+
pub frontend_sus_fee: Option<(C::PaymentAddress, InputAmount)>,
553553
}
554554

555555
impl TxOsmosisSwap<SdkTypes> {
@@ -3244,6 +3244,7 @@ pub struct GenIbcShieldingTransfer<C: NamadaTypes = SdkTypes> {
32443244
/// The output directory path to where serialize the data
32453245
pub output_folder: Option<PathBuf>,
32463246
/// The target address
3247+
// FIXME: why isn't this a payment address?
32473248
pub target: C::TransferTarget,
32483249
/// Transferred token amount
32493250
pub amount: InputAmount,
@@ -3256,7 +3257,7 @@ pub struct GenIbcShieldingTransfer<C: NamadaTypes = SdkTypes> {
32563257
/// shielding transaction since ics-20 only supports a single asset)
32573258
/// NOTE: if the shielding operation is part of a swap, and this is
32583259
/// shielded (from MASP to MASP), no sustainability fee should be taken
3259-
pub frontend_sus_fee: Option<(C::Address, InputAmount)>,
3260+
pub frontend_sus_fee: Option<(C::PaymentAddress, InputAmount)>,
32603261
}
32613262

32623263
/// IBC shielding transfer asset, to be used by [`GenIbcShieldingTransfer`]

crates/sdk/src/tx.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,14 +2843,21 @@ pub async fn build_ibc_transfer(
28432843
args.tx.force,
28442844
)
28452845
.await?;
2846+
2847+
masp_transfer_data.sources.push((
2848+
args.source.clone(),
2849+
args.token.clone(),
2850+
validated_amount,
2851+
));
28462852
masp_transfer_data.targets.push((
28472853
TransferTarget::Address(target.to_owned()),
28482854
token.to_owned(),
28492855
validated_amount,
28502856
));
28512857

28522858
transfer = transfer
2853-
.credit(
2859+
.transfer(
2860+
source.to_owned(),
28542861
target.to_owned(),
28552862
token.to_owned(),
28562863
validated_amount,
@@ -4243,7 +4250,7 @@ pub async fn gen_ibc_shielding_transfer<N: Namada>(
42434250

42444251
(
42454252
vec![(
4246-
TransferTarget::Address(target.to_owned()),
4253+
TransferTarget::PaymentAddress(target.to_owned()),
42474254
token.to_owned(),
42484255
validated_fee_amount,
42494256
)],

crates/tests/src/e2e/ibc_tests.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3211,7 +3211,7 @@ fn transfer_from_cosmos(
32113211
let chain_type =
32123212
CosmosChainType::chain_type(test.net.chain_id.as_str()).unwrap();
32133213
let rpc = format!("tcp://127.0.0.1:{}", chain_type.get_rpc_port_number());
3214-
// If the receiver is a pyament address we want to mask it to the more
3214+
// If the receiver is a payment address we want to mask it to the more
32153215
// general MASP internal address to improve on privacy
32163216
let receiver = match PaymentAddress::from_str(receiver.as_ref()) {
32173217
Ok(_) => MASP.to_string(),
@@ -3229,6 +3229,8 @@ fn transfer_from_cosmos(
32293229
sender.as_ref(),
32303230
"--gas-prices",
32313231
"0.001stake",
3232+
"--gas",
3233+
"250000",
32323234
"--node",
32333235
&rpc,
32343236
"--keyring-backend",
@@ -3828,7 +3830,7 @@ fn frontend_sus_fee() -> Result<()> {
38283830
100,
38293831
&port_id_namada,
38303832
&channel_id_namada,
3831-
Some(ESTER),
3833+
Some(AC_PAYMENT_ADDRESS),
38323834
)?;
38333835
transfer_from_cosmos(
38343836
&test_gaia,
@@ -3852,10 +3854,11 @@ fn frontend_sus_fee() -> Result<()> {
38523854
let ibc_denom_on_namada =
38533855
format!("{port_id_namada}/{channel_id_namada}/{COSMOS_COIN}");
38543856
check_shielded_balance(&test, AA_VIEWING_KEY, &ibc_denom_on_namada, 100)?;
3857+
check_shielded_balance(&test, AC_VIEWING_KEY, &ibc_denom_on_namada, 1)?;
38553858
check_cosmos_balance(&test_gaia, COSMOS_USER, COSMOS_COIN, 899)?;
3856-
check_balance(&test, ESTER, &ibc_denom_on_namada, 1)?;
38573859

3858-
// Unshielding transfer 10 samoleans from Namada to Gaia
3860+
// Unshielding transfer 10 samoleans from Namada to Gaia with transparent
3861+
// frontend fee FIXME: need to test also the transparent version
38593862
let gaia_receiver = find_cosmos_address(&test_gaia, COSMOS_USER)?;
38603863
transfer(
38613864
&test,
@@ -3881,8 +3884,9 @@ fn frontend_sus_fee() -> Result<()> {
38813884
&test,
38823885
)?;
38833886
check_shielded_balance(&test, AA_VIEWING_KEY, &ibc_denom_on_namada, 89)?;
3887+
check_shielded_balance(&test, AC_VIEWING_KEY, &ibc_denom_on_namada, 1)?;
3888+
check_balance(&test, ESTER, &ibc_denom_on_namada, 1)?;
38843889
check_cosmos_balance(&test_gaia, COSMOS_USER, COSMOS_COIN, 909)?;
3885-
check_balance(&test, ESTER, &ibc_denom_on_namada, 2)?;
38863890

38873891
Ok(())
38883892
}

0 commit comments

Comments
 (0)