Skip to content

Commit

Permalink
feat(bridge-ui): add padding when claiming to smart contract (#18141)
Browse files Browse the repository at this point in the history
Co-authored-by: Karim <[email protected]>
  • Loading branch information
KorbinianK and Karim authored Sep 19, 2024
1 parent 9f99099 commit ce5d485
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/repo--vercel-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
run: |
echo "Vercel Project ID: ${{ env.VERCEL_PROJECT_ID }}"
- name: Install Git
run: sudo apt-get update && sudo apt-get install -y git

- name: Checkout repository
uses: actions/checkout@v4

Expand Down
21 changes: 18 additions & 3 deletions packages/bridge-ui/src/libs/bridge/Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { routingContractsMap } from '$bridgeConfig';
import { MessageStatusError, ProcessMessageError, ReleaseError, WrongChainError, WrongOwnerError } from '$libs/error';
import type { BridgeProver } from '$libs/proof';
import { getConnectedWallet } from '$libs/util/getConnectedWallet';
import { isSmartContract } from '$libs/util/isSmartContract';
import { getLogger } from '$libs/util/logger';
import { config } from '$libs/wagmi';

Expand Down Expand Up @@ -262,6 +263,11 @@ export abstract class Bridge {
console.error('Failed to estimate gas, using fallback', error);
estimatedGas = 1_300_000n;
}

if (message.to && (await isSmartContract(message.to, Number(message.destChainId)))) {
log(`Recipient is a smart contract, increasing fees by 5 percent`);
estimatedGas = (estimatedGas * 105n) / 100n;
}
if (force) {
return await writeContract(config, {
address: bridgeContract.address,
Expand Down Expand Up @@ -293,10 +299,13 @@ export abstract class Bridge {

if (!message) throw new ProcessMessageError('Message is not defined');

const estimatedGas = await bridgeContract.estimateGas.retryMessage([message, isFinalAttempt], {
let estimatedGas = await bridgeContract.estimateGas.retryMessage([message, isFinalAttempt], {
account: client.account,
});

if (message.to && (await isSmartContract(message.to, Number(message.destChainId)))) {
log(`Recipient is a smart contract, increasing fees by 5 percent`);
estimatedGas = (estimatedGas * 105n) / 100n;
}
log('Estimated gas for retryMessage', estimatedGas);

const { request } = await simulateContract(config, {
Expand All @@ -319,9 +328,15 @@ export abstract class Bridge {

log('Estimating gas for recallMessage', bridgeContract.address, [message, proof]);

const estimatedGas = await bridgeContract.estimateGas.recallMessage([message, proof], { account: client.account });
let estimatedGas = await bridgeContract.estimateGas.recallMessage([message, proof], { account: client.account });
log('Estimated gas for recallMessage', estimatedGas);

if (message.from && (await isSmartContract(message.from, Number(message.srcChainId)))) {
log(`Sender is a smart contract, increasing fees by 5 percent`);
estimatedGas = (estimatedGas * 105n) / 100n;
}
log('Estimated gas for retryMessage', estimatedGas);

const { request } = await simulateContract(config, {
address: bridgeContract.address,
abi: bridgeContract.abi,
Expand Down

0 comments on commit ce5d485

Please sign in to comment.