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

Deposit/Withdraw fixes #3662

Merged
merged 4 commits into from
Aug 4, 2024
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: 1 addition & 1 deletion packages/bridge/src/axelar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ export class AxelarBridgeProvider implements BridgeProvider {
});

const timeoutHeight = await this.ctx.getTimeoutHeight({
destinationAddress: depositAddress,
chainId: toChain.chainId.toString(),
});

const ibcAsset = getAssetFromAssetList({
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge/src/ibc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class IbcBridgeProvider implements BridgeProvider {
const { sourceChannel, sourcePort, address } = this.getIbcSource(params);

const timeoutHeight = await this.ctx.getTimeoutHeight({
destinationAddress: params.toAddress,
chainId: params.toChain.chainId.toString(),
});

const { typeUrl, value: msg } = cosmosMsgOpts.ibcTransfer.messageComposer({
Expand Down
5 changes: 2 additions & 3 deletions packages/bridge/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ export interface BridgeProviderContext {
assetLists: AssetList[];
chainList: Chain[];

/** Provides current timeout height for a chain of the ID
* parsed from the bech32 config of the given destinationAddress. */
getTimeoutHeight(params: { destinationAddress: string }): Promise<{
/** Provides current timeout height for a chain of given chainId. */
getTimeoutHeight(params: { chainId: string }): Promise<{
revisionNumber: string | undefined;
revisionHeight: string;
}>;
Expand Down
5 changes: 3 additions & 2 deletions packages/bridge/src/skip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ export class SkipBridgeProvider implements BridgeProvider {
if (
msg.includes(
"no single-tx routes found, to enable multi-tx routes set allow_multi_tx to true"
)
) ||
msg.includes("no routes found")
) {
throw new BridgeQuoteError({
bridgeId: SkipBridgeProvider.ID,
Expand Down Expand Up @@ -493,7 +494,7 @@ export class SkipBridgeProvider implements BridgeProvider {
// is an ibc transfer

const timeoutHeight = await this.ctx.getTimeoutHeight({
destinationAddress: messageData.receiver,
chainId: messageData.chain_id,
});

const { typeUrl, value } = cosmosMsgOpts.ibcTransfer.messageComposer({
Expand Down
4 changes: 3 additions & 1 deletion packages/bridge/src/squid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ export class SquidBridgeProvider implements BridgeProvider {
: await this.createCosmosTransaction(
transactionRequest.data,
fromAddress,
toChain.chainId.toString(),
{ denom: fromAsset.address, amount: fromAmount }
// TODO: uncomment when we're able to find a way to get gas limit from Squid
// or get it ourselves
Expand Down Expand Up @@ -494,6 +495,7 @@ export class SquidBridgeProvider implements BridgeProvider {
async createCosmosTransaction(
data: string,
fromAddress: string,
toChainId: string,
fromCoin: {
denom: string;
amount: string;
Expand Down Expand Up @@ -532,7 +534,7 @@ export class SquidBridgeProvider implements BridgeProvider {
};

const timeoutHeight = await this.ctx.getTimeoutHeight({
destinationAddress: ibcData.msg.receiver,
chainId: toChainId,
});

const { typeUrl, value: msg } =
Expand Down
5 changes: 1 addition & 4 deletions packages/server/src/queries/complex/get-timeout-height.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ import { queryRPCStatus } from "../../queries/cosmos";
export async function getTimeoutHeight({
chainList,
chainId,
destinationAddress,
}: {
chainList: Chain[];
chainId?: string;
destinationAddress?: string;
chainId: string;
}) {
const destinationCosmosChain = getChain({
chainList,
chainId,
destinationAddress,
});

if (!destinationCosmosChain) {
Expand Down
4 changes: 4 additions & 0 deletions packages/utils/src/chain-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export function getChain<Chain extends ChainType>({
}: {
chainId?: string;
chainName?: string;
/**
* WARNING: bech32 prefix may be the same across different chains,
* retulting in the use of an unintended chain.
*/
destinationAddress?: string;
chainList: Chain[];
}): Chain | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ export const useBridgesSupportedAssets = ({
);

const isLoading = useMemo(
() =>
supportedAssetsResults.some(
(data): data is NonNullable<Required<typeof data>> =>
!isNil(data) && data.isLoading
),
() => supportedAssetsResults.some((data) => isNil(data) || data.isLoading),
[supportedAssetsResults]
);

Expand Down
14 changes: 4 additions & 10 deletions packages/web/server/api/routers/bridge-transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ export const bridgeTransferRouter = createTRPCRouter({
...ctx,
env: IS_TESTNET ? "testnet" : "mainnet",
cache: lruCache,
getTimeoutHeight: ({ destinationAddress }) =>
getTimeoutHeight({ ...ctx, destinationAddress }),
getTimeoutHeight: (params) => getTimeoutHeight({ ...ctx, ...params }),
}
);

Expand Down Expand Up @@ -330,8 +329,7 @@ export const bridgeTransferRouter = createTRPCRouter({
...ctx,
env: IS_TESTNET ? "testnet" : "mainnet",
cache: lruCache,
getTimeoutHeight: ({ destinationAddress }) =>
getTimeoutHeight({ ...ctx, destinationAddress }),
getTimeoutHeight: (params) => getTimeoutHeight({ ...ctx, ...params }),
}
);

Expand Down Expand Up @@ -455,9 +453,7 @@ export const bridgeTransferRouter = createTRPCRouter({
...ctx,
env: IS_TESTNET ? "testnet" : "mainnet",
cache: lruCache,
getTimeoutHeight: ({ destinationAddress }) =>
// passes testnet chains if IS_TESTNET
getTimeoutHeight({ ...ctx, destinationAddress }),
getTimeoutHeight: (params) => getTimeoutHeight({ ...ctx, ...params }),
}
);

Expand Down Expand Up @@ -498,9 +494,7 @@ export const bridgeTransferRouter = createTRPCRouter({
...ctx,
env: IS_TESTNET ? "testnet" : "mainnet",
cache: lruCache,
getTimeoutHeight: ({ destinationAddress }) =>
// passes testnet chains if IS_TESTNET
getTimeoutHeight({ ...ctx, destinationAddress }),
getTimeoutHeight: (params) => getTimeoutHeight({ ...ctx, ...params }),
}
);

Expand Down