diff --git a/.changelog/unreleased/SDK/2308-fix-ibc-gen-shielded.md b/.changelog/unreleased/SDK/2308-fix-ibc-gen-shielded.md new file mode 100644 index 0000000000..5e65bcff6f --- /dev/null +++ b/.changelog/unreleased/SDK/2308-fix-ibc-gen-shielded.md @@ -0,0 +1,2 @@ +- ibc-gen-shielded can set non-Namada token + ([\#2308](https://github.com/anoma/namada/issues/2308)) \ No newline at end of file diff --git a/.changelog/unreleased/bug-fixes/2308-fix-ibc-gen-shielded.md b/.changelog/unreleased/bug-fixes/2308-fix-ibc-gen-shielded.md new file mode 100644 index 0000000000..9386818074 --- /dev/null +++ b/.changelog/unreleased/bug-fixes/2308-fix-ibc-gen-shielded.md @@ -0,0 +1,2 @@ +- Non-Namada token can be given to ibc-gen-shielded + ([\#2308](https://github.com/anoma/namada/issues/2308)) \ No newline at end of file diff --git a/apps/src/lib/cli.rs b/apps/src/lib/cli.rs index 50e3f06ec4..6c0fe2ea10 100644 --- a/apps/src/lib/cli.rs +++ b/apps/src/lib/cli.rs @@ -3034,6 +3034,7 @@ pub mod args { pub const TM_ADDRESS: Arg = arg("tm-address"); pub const TOKEN_OPT: ArgOpt = TOKEN.opt(); pub const TOKEN: Arg = arg("token"); + pub const TOKEN_STR: Arg = arg("token"); pub const TRANSFER_SOURCE: Arg = arg("source"); pub const TRANSFER_TARGET: Arg = arg("target"); pub const TRANSPARENT: ArgFlag = flag("transparent"); @@ -5532,7 +5533,7 @@ pub mod args { query, output_folder: self.output_folder, target: chain_ctx.get(&self.target), - token: chain_ctx.get(&self.token), + token: self.token, amount: self.amount, port_id: self.port_id, channel_id: self.channel_id, @@ -5545,7 +5546,7 @@ pub mod args { let query = Query::parse(matches); let output_folder = OUTPUT_FOLDER_PATH.parse(matches); let target = TRANSFER_TARGET.parse(matches); - let token = TOKEN.parse(matches); + let token = TOKEN_STR.parse(matches); let amount = InputAmount::Unvalidated(AMOUNT.parse(matches)); let port_id = PORT_ID.parse(matches); let channel_id = CHANNEL_ID.parse(matches); diff --git a/sdk/src/args.rs b/sdk/src/args.rs index 73353df983..1a7621060f 100644 --- a/sdk/src/args.rs +++ b/sdk/src/args.rs @@ -2397,8 +2397,8 @@ pub struct GenIbcShieldedTransafer { pub output_folder: Option, /// The target address pub target: C::TransferTarget, - /// The token address - pub token: C::Address, + /// The token address which could be a non-namada address + pub token: String, /// Transferred token amount pub amount: InputAmount, /// Port ID via which the token is received diff --git a/sdk/src/rpc.rs b/sdk/src/rpc.rs index 90d5701a5e..2bb7192a89 100644 --- a/sdk/src/rpc.rs +++ b/sdk/src/rpc.rs @@ -1214,12 +1214,14 @@ pub async fn format_denominated_amount( /// Look up the IBC denomination from a IbcToken. pub async fn query_ibc_denom( context: &N, - token: &Address, + token: impl AsRef, owner: Option<&Address>, ) -> String { - let hash = match token { - Address::Internal(InternalAddress::IbcToken(hash)) => hash.to_string(), - _ => return token.to_string(), + let hash = match Address::decode(token.as_ref()) { + Ok(Address::Internal(InternalAddress::IbcToken(hash))) => { + hash.to_string() + } + _ => return token.as_ref().to_string(), }; if let Some(owner) = owner { @@ -1246,5 +1248,5 @@ pub async fn query_ibc_denom( } } - token.to_string() + token.as_ref().to_string() } diff --git a/sdk/src/tx.rs b/sdk/src/tx.rs index e5df2dcb51..66a7c39dc1 100644 --- a/sdk/src/tx.rs +++ b/sdk/src/tx.rs @@ -2038,7 +2038,8 @@ pub async fn build_ibc_transfer( .map_err(|e| Error::from(QueryError::Wasm(e.to_string())))?; let ibc_denom = - rpc::query_ibc_denom(context, &args.token, Some(&source)).await; + rpc::query_ibc_denom(context, &args.token.to_string(), Some(&source)) + .await; let token = PrefixedCoin { denom: ibc_denom.parse().expect("Invalid IBC denom"), // Set the IBC amount as an integer diff --git a/tests/src/e2e/ibc_tests.rs b/tests/src/e2e/ibc_tests.rs index 5f3f92a72e..60f053ebee 100644 --- a/tests/src/e2e/ibc_tests.rs +++ b/tests/src/e2e/ibc_tests.rs @@ -206,7 +206,7 @@ fn run_ledger_ibc() -> Result<()> { &port_id_b, &channel_id_b, )?; - check_shielded_balances(&port_id_b, &channel_id_b, &test_b)?; + check_shielded_balances(&port_id_b, &channel_id_b, &test_a, &test_b)?; // Skip tests for closing a channel and timeout_on_close since the transfer // channel cannot be closed @@ -1021,6 +1021,8 @@ fn shielded_transfer( // It will send 10 BTC from Chain A to PA(B) on Chain B let rpc_b = get_actor_rpc(test_b, Who::Validator(0)); let output_folder = test_b.test_dir.path().to_string_lossy(); + // PA(B) on Chain B will receive BTC on chain A + let token_addr = find_address(test_a, BTC)?; let amount = Amount::native_whole(10).to_string_native(); let args = [ "ibc-gen-shielded", @@ -1029,7 +1031,7 @@ fn shielded_transfer( "--target", AB_PAYMENT_ADDRESS, "--token", - BTC, + &token_addr.to_string(), "--amount", &amount, "--port-id", @@ -1512,16 +1514,19 @@ fn check_balances_after_back( fn check_shielded_balances( dest_port_id: &PortId, dest_channel_id: &ChannelId, + test_a: &Test, test_b: &Test, ) -> Result<()> { // Check the balance on Chain B - let rpc_b = get_actor_rpc(test_b, Who::Validator(0)); + let rpc_b = get_actor_rpc(test_b, &Who::Validator(0)); + // PA(B) on Chain B has received BTC on chain A + let token_addr = find_address(test_a, BTC)?.to_string(); let query_args = vec![ "balance", "--owner", AB_VIEWING_KEY, "--token", - BTC, + &token_addr, "--no-conversions", "--node", &rpc_b,