Skip to content

Commit

Permalink
fix(bridge): bridge Ui should estimate gas not used hardcoded gas lim…
Browse files Browse the repository at this point in the history
…it (#12962)

* bridge estimate gas

* test
  • Loading branch information
cyberhorsey authored Jan 17, 2023
1 parent 7692ac8 commit 1eb3c6f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
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

0 comments on commit 1eb3c6f

Please sign in to comment.