From ce5d4859a77631ec406ccb5d571efcd91e5fd2f8 Mon Sep 17 00:00:00 2001 From: Korbinian Date: Thu, 19 Sep 2024 03:59:14 +0300 Subject: [PATCH] feat(bridge-ui): add padding when claiming to smart contract (#18141) Co-authored-by: Karim --- .github/workflows/repo--vercel-deploy.yml | 3 +++ packages/bridge-ui/src/libs/bridge/Bridge.ts | 21 +++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/repo--vercel-deploy.yml b/.github/workflows/repo--vercel-deploy.yml index 345fffeebc..4d06f1852e 100644 --- a/.github/workflows/repo--vercel-deploy.yml +++ b/.github/workflows/repo--vercel-deploy.yml @@ -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 diff --git a/packages/bridge-ui/src/libs/bridge/Bridge.ts b/packages/bridge-ui/src/libs/bridge/Bridge.ts index 1bcf689b9a..5e73e5d268 100644 --- a/packages/bridge-ui/src/libs/bridge/Bridge.ts +++ b/packages/bridge-ui/src/libs/bridge/Bridge.ts @@ -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'; @@ -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, @@ -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, { @@ -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,