diff --git a/packages/bridge-ui/src/abi/index.ts b/packages/bridge-ui/src/abi/index.ts index 68b536b3958..7f3cb19c9cb 100644 --- a/packages/bridge-ui/src/abi/index.ts +++ b/packages/bridge-ui/src/abi/index.ts @@ -525,15 +525,30 @@ export const bridgeAbi = [ anonymous: false, inputs: [ { - name: 'messageId', - internalType: 'uint256', - type: 'uint256', + name: 'msgHash', + internalType: 'bytes32', + type: 'bytes32', indexed: true, }, { - name: 'gasMeasured', - internalType: 'uint256', - type: 'uint256', + name: 'stats', + internalType: 'struct Bridge.GasStats', + type: 'tuple', + components: [ + { name: 'start', internalType: 'uint256', type: 'uint256' }, + { + name: 'beforeInvocation', + internalType: 'uint256', + type: 'uint256', + }, + { name: 'afterInvocation', internalType: 'uint256', type: 'uint256' }, + { + name: 'gasUsedInFeeCalc', + internalType: 'uint256', + type: 'uint256', + }, + { name: 'end', internalType: 'uint256', type: 'uint256' }, + ], indexed: false, }, { @@ -565,6 +580,32 @@ export const bridgeAbi = [ ], name: 'Initialized', }, + { + type: 'event', + anonymous: false, + inputs: [ + { + name: 'message', + internalType: 'struct IBridge.Message', + type: 'tuple', + components: [ + { name: 'id', internalType: 'uint64', type: 'uint64' }, + { name: 'fee', internalType: 'uint64', type: 'uint64' }, + { name: 'gasLimit', internalType: 'uint32', type: 'uint32' }, + { name: 'from', internalType: 'address', type: 'address' }, + { name: 'srcChainId', internalType: 'uint64', type: 'uint64' }, + { name: 'srcOwner', internalType: 'address', type: 'address' }, + { name: 'destChainId', internalType: 'uint64', type: 'uint64' }, + { name: 'destOwner', internalType: 'address', type: 'address' }, + { name: 'to', internalType: 'address', type: 'address' }, + { name: 'value', internalType: 'uint256', type: 'uint256' }, + { name: 'data', internalType: 'bytes', type: 'bytes' }, + ], + indexed: false, + }, + ], + name: 'MessageProcessed', + }, { type: 'event', anonymous: false, @@ -3174,6 +3215,13 @@ export const erc20Abi = [ outputs: [{ name: '', internalType: 'uint48', type: 'uint48' }], stateMutability: 'view', }, + { + type: 'function', + inputs: [], + name: 'currentSnapshotId', + outputs: [{ name: '', internalType: 'uint256', type: 'uint256' }], + stateMutability: 'view', + }, { type: 'function', inputs: [], @@ -3283,6 +3331,13 @@ export const erc20Abi = [ outputs: [], stateMutability: 'nonpayable', }, + { + type: 'function', + inputs: [{ name: 'addr', internalType: 'address', type: 'address' }], + name: 'isAuthorizedForSnapshot', + outputs: [{ name: '', internalType: 'bool', type: 'bool' }], + stateMutability: 'view', + }, { type: 'function', inputs: [], diff --git a/packages/bridge-ui/src/app.config.ts b/packages/bridge-ui/src/app.config.ts index 0afc7671bcc..9f55fa25d4e 100644 --- a/packages/bridge-ui/src/app.config.ts +++ b/packages/bridge-ui/src/app.config.ts @@ -1,4 +1,5 @@ export const recommendProcessingFeeConfig = { + GAS_RESERVE: 650_000, // based on Bridge.sol ethGasLimit: BigInt(900_000), erc20NotDeployedGasLimit: BigInt(1_650_000), erc20DeployedGasLimit: BigInt(1_100_000), diff --git a/packages/bridge-ui/src/libs/bridge/ERC20Bridge.ts b/packages/bridge-ui/src/libs/bridge/ERC20Bridge.ts index d55da9eb659..a5329724d02 100644 --- a/packages/bridge-ui/src/libs/bridge/ERC20Bridge.ts +++ b/packages/bridge-ui/src/libs/bridge/ERC20Bridge.ts @@ -36,11 +36,13 @@ export class ERC20Bridge extends Bridge { }); const gasLimit = !isTokenAlreadyDeployed - ? BigInt(bridgeService.noERC20TokenDeployedGasLimit) + ? Number(bridgeService.noERC20TokenDeployedGasLimit) : fee > 0 - ? bridgeService.noOwnerGasLimit + ? Number(bridgeService.noOwnerGasLimit) : BigInt(0); + log('Calculated gasLimit for message', gasLimit); + const sendERC20Args: BridgeTransferOp = { destChainId: BigInt(destChainId), destOwner: to, @@ -127,13 +129,7 @@ export class ERC20Bridge extends Bridge { if (!wallet || !wallet.account || !wallet.chain) throw new Error('Wallet is not connected'); - const txHash = await writeContract(config, { - address: tokenAddress, - abi: erc20Abi, - functionName: 'approve', - args: [spenderAddress, amount], - chainId: wallet.chain.id, - }); + const txHash = await writeContract(config, request); log('Transaction hash for approve call', txHash); diff --git a/packages/bridge-ui/src/libs/bridge/ETHBridge.ts b/packages/bridge-ui/src/libs/bridge/ETHBridge.ts index a37bb5d7e73..4c1b42de226 100644 --- a/packages/bridge-ui/src/libs/bridge/ETHBridge.ts +++ b/packages/bridge-ui/src/libs/bridge/ETHBridge.ts @@ -2,6 +2,7 @@ import { getWalletClient, simulateContract, writeContract } from '@wagmi/core'; import { getContract, UserRejectedRequestError } from 'viem'; import { bridgeAbi } from '$abi'; +import { recommendProcessingFeeConfig } from '$config'; import { BridgePausedError, SendMessageError } from '$libs/error'; import type { BridgeProver } from '$libs/proof'; import { isBridgePaused } from '$libs/util/checkForPausedContracts'; @@ -56,16 +57,18 @@ export class ETHBridge extends Bridge { id: BigInt(0), // will be set in contract }; - const getMinGasLimit = await bridgeContract.read.getMessageMinGasLimit([message]); - log('Min gas limit for message', getMinGasLimit); - - // set msg.gasLimit to 105% of getMinGasLimit - const gasLimitPercentage = 105; - const getMinGasLimitPercentage = (getMinGasLimit * gasLimitPercentage) / 100; - // round it to the nearest integer - const gasLimit = Math.round(getMinGasLimitPercentage); + const minGasLimit = await bridgeContract.read.getMessageMinGasLimit([message]); + log('Min gas limit for message', minGasLimit); + const gasLimit = recommendProcessingFeeConfig.GAS_RESERVE + minGasLimit; log('Calculated gasLimit for message', gasLimit); + + // // set msg.gasLimit to 105% of getMinGasLimit + // const gasLimitPercentage = 105; + // const getMinGasLimitPercentage = (getMinGasLimit * gasLimitPercentage) / 100; + // // round it to the nearest integer + // const gasLimit = Math.round(getMinGasLimitPercentage); + message.gasLimit = gasLimit; log('Preparing transaction with message', message);