Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ibc-gen-shielded to receive a non-Namada token #2311

Merged
merged 5 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changelog/unreleased/SDK/2308-fix-ibc-gen-shielded.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- ibc-gen-shielded can set non-Namada token
([\#2308](https://github.com/anoma/namada/issues/2308))
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/2308-fix-ibc-gen-shielded.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Non-Namada token can be given to ibc-gen-shielded
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need another changelog for the sdk updates

([\#2308](https://github.com/anoma/namada/issues/2308))
5 changes: 3 additions & 2 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3164,6 +3164,7 @@ pub mod args {
pub const TM_ADDRESS: Arg<String> = arg("tm-address");
pub const TOKEN_OPT: ArgOpt<WalletAddress> = TOKEN.opt();
pub const TOKEN: Arg<WalletAddress> = arg("token");
pub const TOKEN_STR: Arg<String> = arg("token");
pub const TRANSFER_SOURCE: Arg<WalletTransferSource> = arg("source");
pub const TRANSFER_TARGET: Arg<WalletTransferTarget> = arg("target");
pub const TX_HASH: Arg<String> = arg("tx-hash");
Expand Down Expand Up @@ -5654,7 +5655,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,
Expand All @@ -5667,7 +5668,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);
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2418,8 +2418,8 @@ pub struct GenIbcShieldedTransafer<C: NamadaTypes = SdkTypes> {
pub output_folder: Option<PathBuf>,
/// 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
Expand Down
12 changes: 7 additions & 5 deletions sdk/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,12 +1163,14 @@ pub async fn format_denominated_amount(
/// Look up the IBC denomination from a IbcToken.
pub async fn query_ibc_denom<N: Namada>(
context: &N,
token: &Address,
token: impl AsRef<str>,
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 {
Expand All @@ -1195,5 +1197,5 @@ pub async fn query_ibc_denom<N: Namada>(
}
}

token.to_string()
token.as_ref().to_string()
}
3 changes: 2 additions & 1 deletion sdk/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,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
Expand Down
11 changes: 8 additions & 3 deletions tests/src/e2e/ibc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,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
Expand Down Expand Up @@ -1024,6 +1024,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",
Expand All @@ -1032,7 +1034,7 @@ fn shielded_transfer(
"--target",
AB_PAYMENT_ADDRESS,
"--token",
BTC,
&token_addr.to_string(),
"--amount",
&amount,
"--port-id",
Expand Down Expand Up @@ -1526,16 +1528,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));
// 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,
Expand Down
Loading