Skip to content

Commit

Permalink
fix inbound / outbound ibc transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
TalDerei committed Dec 19, 2024
1 parent 640fbd1 commit 10ffb2c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
25 changes: 22 additions & 3 deletions apps/minifront/src/state/ibc-in/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { MsgTransfer } from 'cosmjs-types/ibc/applications/transfer/v1/tx';
import { parseRevisionNumberFromChainId } from './parse-revision-number-from-chain-id';
import { bech32ChainIds } from '../shared.ts';
import { penumbra } from '../../penumbra.ts';
import { TendermintProxyService } from '@penumbra-zone/protobuf';
import { TendermintProxyService, ViewService } from '@penumbra-zone/protobuf';
import { TransparentAddressRequest } from '@penumbra-zone/protobuf/penumbra/view/v1/view_pb';

export interface IbcInSlice {
selectedChain?: ChainInfo;
Expand Down Expand Up @@ -198,7 +199,7 @@ async function execute(
throw new Error('Penumbra chain id could not be retrieved');
}

const penumbraAddress = await getPenumbraAddress(account, selectedChain.chainId);
let penumbraAddress = await getPenumbraAddress(account, selectedChain.chainId);
if (!penumbraAddress) {
throw new Error('Penumbra address not available');
}
Expand All @@ -207,11 +208,29 @@ async function execute(
const assetMetadata = augmentToAsset(coin.raw.denom, selectedChain.chainName);

const transferToken = fromDisplayAmount(assetMetadata, coin.displayDenom, amount);

const { address: t_addr, encoding: encoding } = await penumbra
.service(ViewService)
.transparentAddress(new TransparentAddressRequest({}));
if (!t_addr) {
throw new Error('Error with generating IBC transparent address');
}

// Temporary: detect USDC Noble inbound transfers, and use transparent (t-addr) encoding
// to ensure bech32m encoding compatibility.
if (
transferToken.denom.includes('uusdc') &&
(selectedChain.chainId == 'noble-1' || selectedChain.chainId == 'grand-1')

Check failure on line 223 in apps/minifront/src/state/ibc-in/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Expected '===' and instead saw '=='

Check failure on line 223 in apps/minifront/src/state/ibc-in/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Expected '===' and instead saw '=='
) {
// Set the reciever address to the t-addr encoding.
penumbraAddress = encoding;
}

const params: MsgTransfer = {
sourcePort: 'transfer',
sourceChannel: await getCounterpartyChannelId(selectedChain, penumbraChainId),
sender,
receiver: penumbraAddress,
receiver: penumbraAddress!,

Check failure on line 233 in apps/minifront/src/state/ibc-in/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Forbidden non-null assertion

Check failure on line 233 in apps/minifront/src/state/ibc-in/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

This assertion is unnecessary since it does not change the type of the expression
token: transferToken,
timeoutHeight,
timeoutTimestamp,
Expand Down
5 changes: 2 additions & 3 deletions apps/minifront/src/state/ibc-out.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,9 @@ const getPlanRequest = async ({
let denom = getMetadata(selection.balanceView).base;

Check failure on line 228 in apps/minifront/src/state/ibc-out.ts

View workflow job for this annotation

GitHub Actions / Lint

'denom' is never reassigned. Use 'const' instead
let useTransparentAddress = false;

// Temporary: detect USDC Noble withdrawals, and use transparent (t-addr) addresses
// Temporary: detect USDC Noble withdrawals, and use a transparent (t-addr) address
// to ensure bech32m encoding compatibility.

if (denom.includes('uusdc') && chain.chainId == 'noble-1') {
if (denom.includes('uusdc') && (chain.chainId == 'noble-1' || chain.chainId == 'grand-1')) {

Check failure on line 233 in apps/minifront/src/state/ibc-out.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected '===' and instead saw '=='

Check failure on line 233 in apps/minifront/src/state/ibc-out.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected '===' and instead saw '=='
// Use the t-addr for USDC withdrawals, and don't override existing
// 'useCompatAddress' field to maintain backwards compatibility.
useTransparentAddress = true;
Expand Down

0 comments on commit 10ffb2c

Please sign in to comment.