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

ibc: transparent address support #1950

Merged
merged 20 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 8 additions & 0 deletions .changeset/wet-wombats-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@penumbra-zone/protobuf': major
'@penumbra-zone/services': minor
'minifront': minor
'@penumbra-zone/wasm': minor
---

support transparent addresses for usdc noble IBC withdrawals"
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 { 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 @@
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 @@
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
30 changes: 27 additions & 3 deletions apps/minifront/src/state/ibc-out.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {
BalancesResponse,
TransactionPlannerRequest,
TransparentAddressRequest,
} from '@penumbra-zone/protobuf/penumbra/view/v1/view_pb';
import { BigNumber } from 'bignumber.js';
import { ClientState } from '@penumbra-zone/protobuf/ibc/lightclients/tendermint/v1/tendermint_pb';
Expand All @@ -24,14 +25,14 @@
import { BLOCKS_PER_HOUR } from './constants';
import { createZQuery, ZQueryState } from '@penumbra-zone/zquery';
import { getChains } from '../fetchers/registry';
import { bech32ChainIds } from './shared';
import { penumbra } from '../penumbra';
import {
IbcChannelService,
IbcClientService,
IbcConnectionService,
ViewService,
} from '@penumbra-zone/protobuf';
import { bech32ChainIds } from './shared';

export const { chains, useChains } = createZQuery({
name: 'chains',
Expand Down Expand Up @@ -206,7 +207,7 @@
}

const addressIndex = getAddressIndex(selection.accountAddress);
const { address: returnAddress } = await penumbra
let { address: returnAddress } = await penumbra
.service(ViewService)
.ephemeralAddress({ addressIndex });
if (!returnAddress) {
Expand All @@ -215,20 +216,43 @@

const { timeoutHeight, timeoutTime } = await getTimeout(chain.channelId);

// Request transparent address from view service
const { address: t_addr, encoding: _encoding } = await penumbra

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

View workflow job for this annotation

GitHub Actions / Lint

'_encoding' is assigned a value but never used
.service(ViewService)
.transparentAddress(new TransparentAddressRequest({}));
if (!t_addr) {
throw new Error('Error with generating IBC transparent address');
}

// IBC-related fields
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 a transparent (t-addr) address
// to ensure bech32m encoding compatibility.
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;
// Set the return address to the t-addr.
returnAddress = t_addr;
}

return new TransactionPlannerRequest({
ics20Withdrawals: [
{
amount: toBaseUnit(
BigNumber(amount),
getDisplayDenomExponentFromValueView(selection.balanceView),
),
denom: { denom: getMetadata(selection.balanceView).base },
denom: { denom },
destinationChainAddress,
returnAddress,
timeoutHeight,
timeoutTime,
sourceChannel: chain.channelId,
useCompatAddress: bech32ChainIds.includes(chain.chainId),
TalDerei marked this conversation as resolved.
Show resolved Hide resolved
useTransparentAddress,
TalDerei marked this conversation as resolved.
Show resolved Hide resolved
},
],
source: addressIndex,
Expand Down
2 changes: 1 addition & 1 deletion packages/protobuf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"gen:ibc": "buf generate buf.build/cosmos/ibc:7ab44ae956a0488ea04e04511efa5f70",
"gen:ics23": "buf generate buf.build/cosmos/ics23:55085f7c710a45f58fa09947208eb70b",
"gen:noble": "buf generate buf.build/noble-assets/forwarding:5a8609a6772d417584a9c60cd8b80881",
"gen:penumbra": "buf generate buf.build/penumbra-zone/penumbra:37cef73133644d9dbdeae95b644db3ec",
"gen:penumbra": "buf generate buf.build/penumbra-zone/penumbra:0a56a4f32c244e7eb277e02f6e85afbd",
"lint": "eslint src",
"lint:fix": "eslint src --fix",
"lint:strict": "tsc --noEmit && eslint src --max-warnings 0",
Expand Down
2 changes: 2 additions & 0 deletions packages/services/src/view-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { unclaimedSwaps } from './unclaimed-swaps.js';
import { walletId } from './wallet-id.js';
import { witness } from './witness.js';
import { witnessAndBuild } from './witness-and-build.js';
import { transparentAddress } from './transparent-address.js';

export type Impl = ServiceImpl<typeof ViewService>;

Expand Down Expand Up @@ -62,4 +63,5 @@ export const viewImpl: Impl = {
walletId,
witness,
witnessAndBuild,
transparentAddress,
};
13 changes: 13 additions & 0 deletions packages/services/src/view-service/transparent-address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Impl } from './index.js';
import { fvkCtx } from '../ctx/full-viewing-key.js';
import { getTransparentAddress } from '@penumbra-zone/wasm/keys';

export const transparentAddress: Impl['transparentAddress'] = async (_, ctx) => {
const fvk = await ctx.values.get(fvkCtx)();
const t_addr = getTransparentAddress(fvk);

return {
address: t_addr.address,
encoding: t_addr.encoding,
};
};
Loading
Loading