1- import { Config , simulateContract , writeContract } from '@wagmi/core'
1+ import {
2+ Config ,
3+ simulateContract ,
4+ SimulateContractReturnType ,
5+ writeContract
6+ } from '@wagmi/core'
27import { BigNumber , constants , utils } from 'ethers'
38import { TransactionRequest } from '@ethersproject/providers'
49import { ERC20__factory } from '@arbitrum/sdk/dist/lib/abi/factories/ERC20__factory'
@@ -8,6 +13,7 @@ import {
813 ApproveTokenProps ,
914 BridgeTransferStarter ,
1015 RequiresTokenApprovalProps ,
16+ TransferPrepareTxRequestProps ,
1117 TransferProps ,
1218 TransferType
1319} from './BridgeTransferStarter'
@@ -85,16 +91,14 @@ export class CctpTransferStarter extends BridgeTransferStarter {
8591 return undefined
8692 }
8793
88- public async transfer ( {
89- signer ,
94+ public async transferPrepareTxRequest ( {
95+ from ,
9096 amount,
9197 destinationAddress,
9298 wagmiConfig
93- } : TransferProps & { wagmiConfig : Config } ) {
99+ } : TransferPrepareTxRequestProps & { wagmiConfig : Config } ) {
94100 const sourceChainId = await this . getSourceChainId ( )
95101
96- const address = await getAddressFromSigner ( signer )
97-
98102 // cctp has an upper limit for transfer
99103 const burnLimit = await fetchPerMessageBurnLimit ( {
100104 sourceChainId,
@@ -111,10 +115,8 @@ export class CctpTransferStarter extends BridgeTransferStarter {
111115 )
112116 }
113117
114- const recipient = destinationAddress ?? address
115-
118+ const recipient = destinationAddress ?? from
116119 // burn token on the selected chain to be transferred from cctp contracts to the other chain
117-
118120 // CCTP uses 32 bytes addresses, while EVEM uses 20 bytes addresses
119121 const mintRecipient = utils . hexlify ( utils . zeroPad ( recipient , 32 ) ) as Address
120122
@@ -138,6 +140,22 @@ export class CctpTransferStarter extends BridgeTransferStarter {
138140 ]
139141 } )
140142
143+ return request as unknown as SimulateContractReturnType [ 'request' ]
144+ }
145+
146+ async transfer ( {
147+ signer,
148+ amount,
149+ destinationAddress,
150+ wagmiConfig
151+ } : TransferProps & { wagmiConfig : Config } ) {
152+ const request = await this . transferPrepareTxRequest ( {
153+ from : await getAddressFromSigner ( signer ) ,
154+ amount,
155+ destinationAddress,
156+ wagmiConfig
157+ } )
158+
141159 const depositForBurnTx = await writeContract ( wagmiConfig , request )
142160
143161 return {
0 commit comments