diff --git a/packages/arb-token-bridge-ui/src/token-bridge-sdk/BridgeTransferStarter.ts b/packages/arb-token-bridge-ui/src/token-bridge-sdk/BridgeTransferStarter.ts index 80dc0eb0ba..6d13154098 100644 --- a/packages/arb-token-bridge-ui/src/token-bridge-sdk/BridgeTransferStarter.ts +++ b/packages/arb-token-bridge-ui/src/token-bridge-sdk/BridgeTransferStarter.ts @@ -1,6 +1,7 @@ import { Provider, TransactionRequest } from '@ethersproject/providers' import { BigNumber, ContractTransaction, Signer } from 'ethers' import { Config } from 'wagmi' +import { SimulateContractReturnType } from '@wagmi/core' import { MergedTransaction } from '../state/app/state' import { @@ -58,6 +59,14 @@ export type TransferOverrides = { excessFeeRefundAddress?: string } +export type TransferPrepareTxRequestProps = { + amount: BigNumber + from: string + destinationAddress?: string + overrides?: TransferOverrides + wagmiConfig?: Config +} + export type TransferProps = { amount: BigNumber signer: Signer @@ -169,6 +178,16 @@ export abstract class BridgeTransferStarter { props: ApproveTokenProps ): Promise + // not marking this as abstract for now, as we need a dummy implementation for every class + // only cctp is going to override it for now, and we'll do the same for others one by one + // finally, once we have all implementations we'll mark it as abstract + public async transferPrepareTxRequest( + // eslint-disable-next-line @typescript-eslint/no-unused-vars + props?: TransferPrepareTxRequestProps + ): Promise { + return {} as TransactionRequest | SimulateContractReturnType + } + public abstract transferEstimateGas( props: TransferEstimateGasProps ): Promise diff --git a/packages/arb-token-bridge-ui/src/token-bridge-sdk/CctpTransferStarter.ts b/packages/arb-token-bridge-ui/src/token-bridge-sdk/CctpTransferStarter.ts index ae651eac7f..6b80b4fe08 100644 --- a/packages/arb-token-bridge-ui/src/token-bridge-sdk/CctpTransferStarter.ts +++ b/packages/arb-token-bridge-ui/src/token-bridge-sdk/CctpTransferStarter.ts @@ -8,6 +8,7 @@ import { ApproveTokenProps, BridgeTransferStarter, RequiresTokenApprovalProps, + TransferPrepareTxRequestProps, TransferProps, TransferType } from './BridgeTransferStarter' @@ -85,16 +86,14 @@ export class CctpTransferStarter extends BridgeTransferStarter { return undefined } - public async transfer({ - signer, + public async transferPrepareTxRequest({ + from, amount, destinationAddress, wagmiConfig - }: TransferProps & { wagmiConfig: Config }) { + }: TransferPrepareTxRequestProps & { wagmiConfig: Config }) { const sourceChainId = await this.getSourceChainId() - const address = await getAddressFromSigner(signer) - // cctp has an upper limit for transfer const burnLimit = await fetchPerMessageBurnLimit({ sourceChainId, @@ -111,10 +110,8 @@ export class CctpTransferStarter extends BridgeTransferStarter { ) } - const recipient = destinationAddress ?? address - + const recipient = destinationAddress ?? from // burn token on the selected chain to be transferred from cctp contracts to the other chain - // CCTP uses 32 bytes addresses, while EVEM uses 20 bytes addresses const mintRecipient = utils.hexlify(utils.zeroPad(recipient, 32)) as Address @@ -126,7 +123,7 @@ export class CctpTransferStarter extends BridgeTransferStarter { sourceChainId }) - const { request } = await simulateContract(wagmiConfig, { + return simulateContract(wagmiConfig, { address: tokenMessengerContractAddress, abi: TokenMessengerAbi, functionName: 'depositForBurn', @@ -137,6 +134,20 @@ export class CctpTransferStarter extends BridgeTransferStarter { usdcContractAddress ] }) + } + + async transfer({ + signer, + amount, + destinationAddress, + wagmiConfig + }: TransferProps & { wagmiConfig: Config }) { + const { request } = await this.transferPrepareTxRequest({ + from: await getAddressFromSigner(signer), + amount, + destinationAddress, + wagmiConfig + }) const depositForBurnTx = await writeContract(wagmiConfig, request)