Skip to content

Commit 9f7d514

Browse files
committed
Tests masp frontend fee for ibc transactions
1 parent 32c44b4 commit 9f7d514

File tree

6 files changed

+246
-28
lines changed

6 files changed

+246
-28
lines changed

.github/workflows/scripts/e2e.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"e2e::eth_bridge_tests::everything": 4,
3+
"e2e::ibc_tests::frontend_sus_fee": 415,
34
"e2e::ibc_tests::ibc_transfers": 414,
45
"e2e::ibc_tests::ibc_nft_transfers": 224,
56
"e2e::ibc_tests::pgf_over_ibc": 415,

crates/apps/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ mainnet = ["namada_apps_lib/mainnet"]
5454
jemalloc = ["namada_node/jemalloc"]
5555
migrations = ["namada_apps_lib/migrations"]
5656
namada-eth-bridge = ["namada_apps_lib/namada-eth-bridge"]
57+
# FIXME: how to enforce this in ci?
58+
testing = ["namada_apps_lib/testing"]
5759

5860
[dependencies]
5961
namada_apps_lib.workspace = true

crates/apps_lib/src/cli.rs

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3551,6 +3551,9 @@ pub mod args {
35513551
#[cfg(any(test, feature = "testing"))]
35523552
pub const FRONTEND_SUS_FEE: ArgOpt<WalletAddress> =
35533553
arg_opt("frontend-sus-fee");
3554+
#[cfg(any(test, feature = "testing"))]
3555+
pub const FRONTEND_SUS_FEE_IBC: ArgOpt<WalletTransferTarget> =
3556+
arg_opt("frontend-sus-fee-ibc");
35543557
pub const FULL_RESET: ArgFlag = flag("full-reset");
35553558
pub const GAS_LIMIT: ArgDefault<GasLimit> = arg_default(
35563559
"gas-limit",
@@ -5237,7 +5240,9 @@ pub mod args {
52375240
let source = TRANSFER_SOURCE.parse(matches);
52385241
let receiver = RECEIVER.parse(matches);
52395242
let token = TOKEN.parse(matches);
5240-
let amount = InputAmount::Unvalidated(AMOUNT.parse(matches));
5243+
5244+
let raw_amount = AMOUNT.parse(matches);
5245+
let amount = InputAmount::Unvalidated(raw_amount);
52415246
let port_id = PORT_ID.parse(matches);
52425247
let channel_id = CHANNEL_ID.parse(matches);
52435248
let timeout_height = TIMEOUT_HEIGHT.parse(matches);
@@ -5253,6 +5258,28 @@ pub mod args {
52535258
let ibc_memo = IBC_MEMO.parse(matches);
52545259
let gas_spending_key = GAS_SPENDING_KEY.parse(matches);
52555260
let tx_code_path = PathBuf::from(TX_IBC_WASM);
5261+
// FIXME: this api is to confusing, split the amount into two,
5262+
// source amount and target amount
5263+
#[cfg(any(test, feature = "testing"))]
5264+
let frontend_sus_fee =
5265+
FRONTEND_SUS_FEE.parse(matches).map(|target|
5266+
// Take a constant fee of 1 on top of the input amount
5267+
TxTransparentTarget {
5268+
target,
5269+
token: token.clone(),
5270+
amount: InputAmount::Unvalidated(
5271+
token::DenominatedAmount::new(
5272+
1.into(),
5273+
raw_amount.denom(),
5274+
),
5275+
),
5276+
});
5277+
5278+
#[cfg(not(any(test, feature = "testing")))]
5279+
let frontend_sus_fee = None;
5280+
5281+
eprintln!("AMOUNT IN CLI: {:#?}", amount); //FIXME: remove
5282+
52565283
Self {
52575284
tx,
52585285
source,
@@ -5263,12 +5290,13 @@ pub mod args {
52635290
channel_id,
52645291
timeout_height,
52655292
timeout_sec_offset,
5293+
// FIXME: check this refund, we should not refund the fee
52665294
refund_target,
52675295
ibc_shielding_data,
52685296
ibc_memo,
52695297
gas_spending_key,
52705298
tx_code_path,
5271-
frontend_sus_fee: None,
5299+
frontend_sus_fee,
52725300
}
52735301
}
52745302

@@ -7312,6 +7340,9 @@ pub mod args {
73127340
) -> Result<GenIbcShieldingTransfer<SdkTypes>, Self::Error> {
73137341
let query = self.query.to_sdk(ctx)?;
73147342
let chain_ctx = ctx.borrow_chain_or_exit();
7343+
let frontend_sus_fee = self
7344+
.frontend_sus_fee
7345+
.map(|(target, amount)| (chain_ctx.get(&target), amount));
73157346

73167347
Ok(GenIbcShieldingTransfer::<SdkTypes> {
73177348
query,
@@ -7333,7 +7364,7 @@ pub mod args {
73337364
IbcShieldingTransferAsset::Address(chain_ctx.get(&addr))
73347365
}
73357366
},
7336-
frontend_sus_fee: None,
7367+
frontend_sus_fee,
73377368
})
73387369
}
73397370
}
@@ -7344,7 +7375,8 @@ pub mod args {
73447375
let output_folder = OUTPUT_FOLDER_PATH.parse(matches);
73457376
let target = TRANSFER_TARGET.parse(matches);
73467377
let token = TOKEN_STR.parse(matches);
7347-
let amount = InputAmount::Unvalidated(AMOUNT.parse(matches));
7378+
let raw_amount = AMOUNT.parse(matches);
7379+
let amount = InputAmount::Unvalidated(raw_amount);
73487380
let expiration = EXPIRATION_OPT.parse(matches);
73497381
let port_id = PORT_ID.parse(matches);
73507382
let channel_id = CHANNEL_ID.parse(matches);
@@ -7357,6 +7389,27 @@ pub mod args {
73577389
None => TxExpiration::Default,
73587390
}
73597391
};
7392+
// FIXME: this api is to confusing, split the amount into two,
7393+
// source amount and target amount
7394+
#[cfg(any(test, feature = "testing"))]
7395+
let frontend_sus_fee = FRONTEND_SUS_FEE_IBC.parse(matches).map(
7396+
|target| // Take a constant fee of 1 on top of the input amount
7397+
(
7398+
target,
7399+
//FIXME: this means we can't do anything when it comes to nfts for this frontend fee
7400+
InputAmount::Unvalidated(
7401+
token::DenominatedAmount::new(
7402+
1.into(),
7403+
raw_amount.denom(),
7404+
),
7405+
),
7406+
),
7407+
);
7408+
7409+
#[cfg(not(any(test, feature = "testing")))]
7410+
let frontend_sus_fee = None;
7411+
7412+
eprintln!("AMOUNT IN CLI: {:#?}", amount); //FIXME: remove
73607413

73617414
Self {
73627415
query,
@@ -7369,12 +7422,13 @@ pub mod args {
73697422
channel_id,
73707423
token,
73717424
},
7372-
frontend_sus_fee: None,
7425+
frontend_sus_fee,
73737426
}
73747427
}
73757428

73767429
fn def(app: App) -> App {
7377-
app.add_args::<Query<CliTypes>>()
7430+
let app = app
7431+
.add_args::<Query<CliTypes>>()
73787432
.arg(OUTPUT_FOLDER_PATH.def().help(wrap!(
73797433
"The output folder path where the artifact will be stored."
73807434
)))
@@ -7410,7 +7464,15 @@ pub mod args {
74107464
)))
74117465
.arg(CHANNEL_ID.def().help(wrap!(
74127466
"The channel ID via which the token is received."
7413-
)))
7467+
)));
7468+
7469+
#[cfg(any(test, feature = "testing"))]
7470+
let app = app.arg(FRONTEND_SUS_FEE_IBC.def().help(wrap!(
7471+
"The optional address of the frontend provider that will take \
7472+
the masp sustainability fee."
7473+
)));
7474+
7475+
app
74147476
}
74157477
}
74167478

crates/sdk/src/args.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ pub struct TxOsmosisSwap<C: NamadaTypes = SdkTypes> {
556556
/// NOTE: if the swap is shielded (from MASP to MASP), no sustainability
557557
/// fee should be taken
558558
// FIXME: try to join this with recipient
559-
pub frontend_sus_fee: Option<TxTransparentTarget<C>>,
559+
pub frontend_sus_fee: Option<(C::TransferTarget, InputAmount)>,
560560
}
561561

562562
impl TxOsmosisSwap<SdkTypes> {
@@ -841,6 +841,7 @@ pub struct TxIbcTransfer<C: NamadaTypes = SdkTypes> {
841841
// FIXME: this should probably be an either with ibc_shielding_data. Yes
842842
// but there would still be the room for errors, maybe need marker traits?
843843
// Not sure...
844+
// FIXME: support this in the client for testing only
844845
pub frontend_sus_fee: Option<TxTransparentTarget<C>>,
845846
/// Path to the TX WASM code file
846847
pub tx_code_path: PathBuf,
@@ -3263,10 +3264,12 @@ pub struct GenIbcShieldingTransfer<C: NamadaTypes = SdkTypes> {
32633264
pub expiration: TxExpiration,
32643265
/// Asset to shield over IBC to Namada
32653266
pub asset: IbcShieldingTransferAsset<C>,
3266-
/// The optional data for the frontend sustainability fee
3267+
/// The optional data for the frontend sustainability fee (the target and
3268+
/// the amount, the token must be the same as the one involved in the
3269+
/// shielding transaction since ics-20 only supports a single asset)
32673270
/// NOTE: if the shielding operation is part of a swap, and this is
32683271
/// shielded (from MASP to MASP), no sustainability fee should be taken
3269-
pub frontend_sus_fee: Option<TxTransparentTarget<C>>,
3272+
pub frontend_sus_fee: Option<(C::TransferTarget, InputAmount)>,
32703273
}
32713274

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

crates/sdk/src/tx.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4247,32 +4247,32 @@ pub async fn gen_ibc_shielding_transfer<N: Namada>(
42474247
.precompute_asset_types(context.client(), tokens)
42484248
.await;
42494249

4250-
// FIXME: need to adjust this
4251-
let extra_target = match &args.frontend_sus_fee {
4252-
Some(TxTransparentTarget {
4253-
target,
4254-
token,
4255-
amount,
4256-
}) => {
4250+
let (extra_target, source_amount) = match &args.frontend_sus_fee {
4251+
Some((target, amount)) => {
42574252
// Validate the amount given
4258-
let validated_amount =
4259-
validate_amount(context, amount.to_owned(), token, false)
4253+
let validated_fee_amount =
4254+
validate_amount(context, amount.to_owned(), &token, false)
42604255
.await?;
4256+
let source_amount =
4257+
checked!(validated_amount + validated_fee_amount)?;
42614258

4262-
vec![(
4263-
TransferTarget::Address(target.to_owned()),
4264-
token.to_owned(),
4265-
validated_amount,
4266-
)]
4259+
(
4260+
vec![(
4261+
target.to_owned(),
4262+
token.to_owned(),
4263+
validated_fee_amount,
4264+
)],
4265+
source_amount,
4266+
)
42674267
}
4268-
None => vec![],
4268+
None => (vec![], validated_amount),
42694269
};
42704270

42714271
let masp_transfer_data = MaspTransferData {
42724272
sources: vec![(
42734273
TransferSource::Address(source.clone()),
42744274
token.clone(),
4275-
validated_amount,
4275+
source_amount,
42764276
)],
42774277
targets: [
42784278
extra_target,
@@ -4281,6 +4281,9 @@ pub async fn gen_ibc_shielding_transfer<N: Namada>(
42814281
.concat(),
42824282
};
42834283

4284+
// eprintln!("MASP TRANSFER DATA: {:#?}", masp_transfer_data); //FIXME:
4285+
// remove
4286+
42844287
let shielded_transfer = {
42854288
let mut shielded = context.shielded_mut().await;
42864289
shielded
@@ -4296,6 +4299,9 @@ pub async fn gen_ibc_shielding_transfer<N: Namada>(
42964299
.map_err(|err| TxSubmitError::MaspError(err.to_string()))?
42974300
};
42984301

4302+
// eprintln!("GENERATED MASP BUNDLE: {:#?}", shielded_transfer); //FIXME:
4303+
// remove
4304+
42994305
Ok(shielded_transfer.map(|st| st.masp_tx))
43004306
}
43014307

0 commit comments

Comments
 (0)