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(bridge): bridge Ui should estimate gas not used hardcoded gas limit #12962

Merged
merged 2 commits into from
Jan 17, 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: 1 addition & 1 deletion packages/bridge-ui/src/erc20/bridge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe("bridge tests", () => {
"0xfake",
opts.tokenAddress,
opts.amountInWei,
BigNumber.from(100000),
BigNumber.from(140000),
opts.processingFeeInWei,
"0xfake",
opts.memo,
Expand Down
15 changes: 8 additions & 7 deletions packages/bridge-ui/src/erc20/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ERC20Bridge implements Bridge {
callValue: 0,
processingFee: opts.processingFeeInWei ?? BigNumber.from(0),
gasLimit: opts.processingFeeInWei
? BigNumber.from(100000)
? BigNumber.from(140000)
: BigNumber.from(0),
memo: opts.memo ?? "",
};
Expand Down Expand Up @@ -103,7 +103,9 @@ class ERC20Bridge implements Bridge {
throw Error("token vault does not have required allowance");
}

const { contract, owner, message } = await ERC20Bridge.prepareTransaction(opts);
const { contract, owner, message } = await ERC20Bridge.prepareTransaction(
opts
);

const tx = await contract.sendERC20(
message.destChainId,
Expand All @@ -123,8 +125,9 @@ class ERC20Bridge implements Bridge {
}

async EstimateGas(opts: BridgeOpts): Promise<BigNumber> {

const { contract, owner, message } = await ERC20Bridge.prepareTransaction(opts);
const { contract, owner, message } = await ERC20Bridge.prepareTransaction(
opts
);

const gasEstimate = await contract.estimateGas.sendERC20(
message.destChainId,
Expand Down Expand Up @@ -178,9 +181,7 @@ class ERC20Bridge implements Bridge {
chains[opts.message.destChainId.toNumber()].headerSyncAddress,
});

return await contract.processMessage(opts.message, proof, {
gasLimit: BigNumber.from(1200000),
});
return await contract.processMessage(opts.message, proof);
} else {
return await contract.retryMessage(opts.message, false);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-ui/src/eth/bridge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe("bridge tests", () => {
expect(mockContract.sendEther).toHaveBeenCalledWith(
opts.toChainId,
wallet.getAddress(),
BigNumber.from(100000),
BigNumber.from(140000),
opts.processingFeeInWei,
wallet.getAddress(),
"memo",
Expand Down
18 changes: 11 additions & 7 deletions packages/bridge-ui/src/eth/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class ETHBridge implements BridgeInterface {
this.prover = prover;
}

static async prepareTransaction(opts: BridgeOpts): Promise<{contract: Contract, message: any, owner: string}> {
static async prepareTransaction(
opts: BridgeOpts
): Promise<{ contract: Contract; message: any; owner: string }> {
const contract: Contract = new Contract(
opts.tokenVaultAddress,
TokenVault,
Expand All @@ -38,7 +40,7 @@ class ETHBridge implements BridgeInterface {
callValue: 0,
processingFee: opts.processingFeeInWei ?? BigNumber.from(0),
gasLimit: opts.processingFeeInWei
? BigNumber.from(100000)
? BigNumber.from(140000)
: BigNumber.from(0),
memo: opts.memo ?? "",
};
Expand All @@ -56,7 +58,9 @@ class ETHBridge implements BridgeInterface {
}

async Bridge(opts: BridgeOpts): Promise<Transaction> {
const { contract, owner, message } = await ETHBridge.prepareTransaction(opts);
const { contract, owner, message } = await ETHBridge.prepareTransaction(
opts
);

const tx = await contract.sendEther(
message.destChainId,
Expand All @@ -76,7 +80,9 @@ class ETHBridge implements BridgeInterface {
}

async EstimateGas(opts: BridgeOpts): Promise<BigNumber> {
const { contract, owner, message } = await ETHBridge.prepareTransaction(opts);
const { contract, owner, message } = await ETHBridge.prepareTransaction(
opts
);

const gasEstimate = await contract.estimateGas.sendEther(
message.destChainId,
Expand Down Expand Up @@ -129,9 +135,7 @@ class ETHBridge implements BridgeInterface {

const proof = await this.prover.GenerateProof(proofOpts);

return await contract.processMessage(opts.message, proof, {
gasLimit: BigNumber.from(1000000),
});
return await contract.processMessage(opts.message, proof);
} else {
return await contract.retryMessage(opts.message);
}
Expand Down