From bc04121ae591dae60495eb5bb5dd77106ce4b691 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Wed, 12 Jul 2023 22:42:49 +0100 Subject: [PATCH] Add NUT cmdline flag for Bridge pool transfers --- apps/src/lib/cli.rs | 8 ++++++++ shared/src/ledger/args.rs | 5 +++++ shared/src/ledger/eth_bridge/bridge_pool.rs | 9 ++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/apps/src/lib/cli.rs b/apps/src/lib/cli.rs index 241524d881e..99b96eb2fc2 100644 --- a/apps/src/lib/cli.rs +++ b/apps/src/lib/cli.rs @@ -2349,6 +2349,7 @@ pub mod args { pub const NET_ADDRESS: Arg = arg("net-address"); pub const NAMADA_START_TIME: ArgOpt = arg_opt("time"); pub const NO_CONVERSIONS: ArgFlag = flag("no-conversions"); + pub const NUT: ArgFlag = flag("nut"); pub const OUT_FILE_PATH_OPT: ArgOpt = arg_opt("out-file-path"); pub const OWNER: Arg = arg("owner"); pub const OWNER_OPT: ArgOpt = OWNER.opt(); @@ -2613,6 +2614,7 @@ pub mod args { impl CliToSdk> for EthereumBridgePool { fn to_sdk(self, ctx: &mut Context) -> EthereumBridgePool { EthereumBridgePool:: { + nut: self.nut, tx: self.tx.to_sdk(ctx), asset: self.asset, recipient: self.recipient, @@ -2635,6 +2637,7 @@ pub mod args { let gas_amount = FEE_AMOUNT.parse(matches).amount; let gas_payer = FEE_PAYER.parse(matches); let code_path = PathBuf::from(TX_BRIDGE_POOL_WASM); + let nut = NUT.parse(matches); Self { tx, asset, @@ -2644,6 +2647,7 @@ pub mod args { gas_amount, gas_payer, code_path, + nut, } } @@ -2678,6 +2682,10 @@ pub mod args { "The Namada address of the account paying the fee.", ), ) + .arg(NUT.def().help( + "Add Non Usable Tokens (NUTs) to the Bridge pool. These \ + are usually obtained from invalid transfers to Namada.", + )) } } diff --git a/shared/src/ledger/args.rs b/shared/src/ledger/args.rs index cb71e65b9c2..c35d06a74cf 100644 --- a/shared/src/ledger/args.rs +++ b/shared/src/ledger/args.rs @@ -611,6 +611,11 @@ pub struct RecommendBatch { /// A transfer to be added to the Ethereum bridge pool. #[derive(Clone, Debug)] pub struct EthereumBridgePool { + /// Whether the transfer is for a NUT. + /// + /// By default, we add wrapped ERC20s onto the + /// Bridge pool. + pub nut: bool, /// The args for building a tx to the bridge pool pub tx: Tx, /// The type of token diff --git a/shared/src/ledger/eth_bridge/bridge_pool.rs b/shared/src/ledger/eth_bridge/bridge_pool.rs index f976cd7af43..4a1b7abbdd4 100644 --- a/shared/src/ledger/eth_bridge/bridge_pool.rs +++ b/shared/src/ledger/eth_bridge/bridge_pool.rs @@ -47,6 +47,7 @@ pub async fn build_bridge_pool_tx< args: args::EthereumBridgePool, ) -> Result<(Tx, Option
, common::PublicKey), Error> { let args::EthereumBridgePool { + nut, ref tx, asset, recipient, @@ -66,9 +67,11 @@ pub async fn build_bridge_pool_tx< recipient, sender, amount, - // TODO: dispatch on the transfer kind, based - // on CLI arguments - kind: TransferToEthereumKind::Erc20, + kind: if nut { + TransferToEthereumKind::Nut + } else { + TransferToEthereumKind::Erc20 + }, }, gas_fee: GasFee { amount: gas_amount,