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

Update tx confirmation blocks #818

Merged
merged 1 commit into from
Sep 11, 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
3 changes: 2 additions & 1 deletion apps/web/src/bridges/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { getBalance } from "../utils";
import { Address, PublicClient as ViemPublicClient, TransactionReceipt, createPublicClient, http } from "viem";
import { PublicClient as WagmiPublicClient, WalletClient } from "wagmi";
import { CONFIRMATION_BLOCKS } from "../config";

export abstract class BaseBridge {
protected logo: BridgeLogo = { symbol: "", horizontal: "" };
Expand Down Expand Up @@ -210,7 +211,7 @@ export abstract class BaseBridge {
account: owner,
});
const hash = await this.walletClient.writeContract(request);
return this.publicClient.waitForTransactionReceipt({ hash });
return this.publicClient.waitForTransactionReceipt({ hash, confirmations: CONFIRMATION_BLOCKS });
}
}

Expand Down
11 changes: 6 additions & 5 deletions apps/web/src/bridges/lnbridge-v3.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CONFIRMATION_BLOCKS } from "../config";
import { BridgeConstructorArgs, GetFeeArgs, MessageChannel, Token, TransferOptions } from "../types";
import { LnBridgeBase } from "./lnbridge-base";
import { Address, Hex, TransactionReceipt, encodeFunctionData, encodePacked, keccak256 } from "viem";
Expand Down Expand Up @@ -54,7 +55,7 @@ export class LnBridgeV3 extends LnBridgeBase {
return this.sourcePublicClient.estimateContractGas(defaultParams);
} else if (this.walletClient) {
const hash = await this.walletClient.writeContract(defaultParams);
return this.sourcePublicClient.waitForTransactionReceipt({ hash });
return this.sourcePublicClient.waitForTransactionReceipt({ hash, confirmations: CONFIRMATION_BLOCKS });
}
}
}
Expand Down Expand Up @@ -124,7 +125,7 @@ export class LnBridgeV3 extends LnBridgeBase {
],
gas: this.getTxGasLimit(),
});
return this.publicClient.waitForTransactionReceipt({ hash });
return this.publicClient.waitForTransactionReceipt({ hash, confirmations: CONFIRMATION_BLOCKS });
}
}

Expand All @@ -140,7 +141,7 @@ export class LnBridgeV3 extends LnBridgeBase {
value: this.sourceToken.type === "native" ? amount : undefined,
gas: this.getTxGasLimit(),
});
return this.publicClient.waitForTransactionReceipt({ hash });
return this.publicClient.waitForTransactionReceipt({ hash, confirmations: CONFIRMATION_BLOCKS });
}
}

Expand All @@ -154,7 +155,7 @@ export class LnBridgeV3 extends LnBridgeBase {
functionName: "withdrawPenaltyReserve",
args: [this.sourceToken.address, amount],
});
return this.publicClient.waitForTransactionReceipt({ hash });
return this.publicClient.waitForTransactionReceipt({ hash, confirmations: CONFIRMATION_BLOCKS });
}
}

Expand Down Expand Up @@ -208,7 +209,7 @@ export class LnBridgeV3 extends LnBridgeBase {
value: messageFee,
gas: this.getTxGasLimit(),
});
return this.publicClient.waitForTransactionReceipt({ hash });
return this.publicClient.waitForTransactionReceipt({ hash, confirmations: CONFIRMATION_BLOCKS });
}
}
}
9 changes: 5 additions & 4 deletions apps/web/src/bridges/lnv2-default.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Address, Hex, TransactionReceipt } from "viem";
import { LnBridgeBase } from "./lnbridge-base";
import { BridgeConstructorArgs, TransferOptions } from "../types/bridge";
import { CONFIRMATION_BLOCKS } from "../config";

export class LnBridgeV2Default extends LnBridgeBase {
constructor(args: BridgeConstructorArgs) {
Expand Down Expand Up @@ -53,7 +54,7 @@ export class LnBridgeV2Default extends LnBridgeBase {
return this.sourcePublicClient.estimateContractGas(defaultParams);
} else if (this.walletClient) {
const hash = await this.walletClient.writeContract(defaultParams);
return this.sourcePublicClient.waitForTransactionReceipt({ hash });
return this.sourcePublicClient.waitForTransactionReceipt({ hash, confirmations: CONFIRMATION_BLOCKS });
}
}
}
Expand All @@ -77,7 +78,7 @@ export class LnBridgeV2Default extends LnBridgeBase {
value: this.targetToken.type === "native" ? margin : undefined,
gas: this.getTxGasLimit(),
});
return this.publicClient.waitForTransactionReceipt({ hash });
return this.publicClient.waitForTransactionReceipt({ hash, confirmations: CONFIRMATION_BLOCKS });
}
}

Expand All @@ -99,7 +100,7 @@ export class LnBridgeV2Default extends LnBridgeBase {
args: [BigInt(this.targetChain.id), this.sourceToken.address, this.targetToken.address, baseFee, feeRate],
gas: this.getTxGasLimit(),
});
return this.publicClient.waitForTransactionReceipt({ hash });
return this.publicClient.waitForTransactionReceipt({ hash, confirmations: CONFIRMATION_BLOCKS });
}
}

Expand All @@ -124,7 +125,7 @@ export class LnBridgeV2Default extends LnBridgeBase {
gas: this.getTxGasLimit(),
value: fee,
});
return this.publicClient.waitForTransactionReceipt({ hash });
return this.publicClient.waitForTransactionReceipt({ hash, confirmations: CONFIRMATION_BLOCKS });
}
}
}
5 changes: 3 additions & 2 deletions apps/web/src/bridges/lnv2-opposite.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Address, TransactionReceipt } from "viem";
import { LnBridgeBase } from "./lnbridge-base";
import { BridgeConstructorArgs, TransferOptions } from "../types/bridge";
import { CONFIRMATION_BLOCKS } from "../config";

export class LnBridgeV2Opposite extends LnBridgeBase {
constructor(args: BridgeConstructorArgs) {
Expand Down Expand Up @@ -53,7 +54,7 @@ export class LnBridgeV2Opposite extends LnBridgeBase {
return this.sourcePublicClient.estimateContractGas(defaultParams);
} else if (this.walletClient) {
const hash = await this.walletClient.writeContract(defaultParams);
return this.sourcePublicClient.waitForTransactionReceipt({ hash });
return this.sourcePublicClient.waitForTransactionReceipt({ hash, confirmations: CONFIRMATION_BLOCKS });
}
}
}
Expand Down Expand Up @@ -84,7 +85,7 @@ export class LnBridgeV2Opposite extends LnBridgeBase {
value: this.sourceToken.type === "native" ? margin : undefined,
gas: this.getTxGasLimit(),
});
return this.publicClient.waitForTransactionReceipt({ hash });
return this.publicClient.waitForTransactionReceipt({ hash, confirmations: CONFIRMATION_BLOCKS });
}
}
}
3 changes: 2 additions & 1 deletion apps/web/src/components/faucet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import abi from "../abi/faucet";
import Tooltip from "../ui/tooltip";
import CountLoading from "../ui/count-loading";
import Modal from "../ui/modal";
import { CONFIRMATION_BLOCKS } from "../config";

interface Props {
sourceChain: ChainConfig;
Expand Down Expand Up @@ -40,7 +41,7 @@ export default function Faucet({ sourceChain, sourceToken, onSuccess = () => und
functionName: "faucet",
args: [1n <= allow ? allow - 1n : allow],
});
const receipt = await publicClient.waitForTransactionReceipt({ hash });
const receipt = await publicClient.waitForTransactionReceipt({ hash, confirmations: CONFIRMATION_BLOCKS });
notifyTransaction(receipt, sourceChain);
setBusy(false);

Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/config/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export const FEE_RATE_BASE = 1000;
export const FEE_RATE_MIN = 0;
export const FEE_RATE_MAX = 0.25 * FEE_RATE_BASE; // 0.25%
export const FEE_RATE_MAX_V3 = 100 * FEE_RATE_BASE; // 100%

export const CONFIRMATION_BLOCKS = 2;
3 changes: 2 additions & 1 deletion apps/web/src/hooks/use-allowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import abi from "../abi/erc20";
import { ChainConfig, Token } from "../types";
import { usePublicClient, useWalletClient } from "wagmi";
import { notifyError } from "../utils";
import { CONFIRMATION_BLOCKS } from "../config";

export function useAllowance(
chain: ChainConfig,
Expand Down Expand Up @@ -56,7 +57,7 @@ export function useAllowance(
functionName: "approve",
args: [spender, amount],
});
const receipt = await publicClient.waitForTransactionReceipt({ hash });
const receipt = await publicClient.waitForTransactionReceipt({ hash, confirmations: CONFIRMATION_BLOCKS });

if (receipt.status === "success") {
setAllowance(
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-core/src/i-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export abstract class IBridge {
publicClient,
walletClient: this.walletClient,
}).write.approve([spender, amount], { account: owner, chain });
return publicClient.waitForTransactionReceipt({ hash });
return publicClient.waitForTransactionReceipt({ hash, confirmations: 2 });
}
}

Expand Down
Loading