@@ -8,7 +8,7 @@ import { EIP155_CHAINS, TEIP155Chain } from '@/data/EIP155Data'
8
8
9
9
const BASE_URL = 'https://api.socket.tech/v2'
10
10
const WHITELIST_BRIDGES = 'across'
11
- const AMOUNT_MULTIPLIER = 1.1
11
+ const AMOUNT_MULTIPLIER = 1.05
12
12
13
13
export const supportedAssets : Record < string , Record < number , Hex > > = {
14
14
USDC : {
@@ -246,7 +246,8 @@ async function getBridgeStatus(params: BridgeStatusParams): Promise<any> {
246
246
export async function bridgeFunds ( bridgingParams : BridgingParams , wallet : EIP155Lib | SmartAccountLib ) : Promise < void > {
247
247
performance . mark ( 'startGetQuote' )
248
248
console . log ( 'Bridging funds' , bridgingParams ) ;
249
- bridgingParams . amount = Math . round ( bridgingParams . amount * 1.1 )
249
+ const originalAmount = bridgingParams . amount
250
+ bridgingParams . amount = Math . round ( originalAmount * AMOUNT_MULTIPLIER )
250
251
const quote = await getQuote ( bridgingParams )
251
252
performance . mark ( 'endGetQuote' )
252
253
console . log ( 'Fetched quote' , quote ) ;
@@ -255,7 +256,6 @@ export async function bridgeFunds(bridgingParams: BridgingParams, wallet: EIP155
255
256
if ( ! route ) {
256
257
throw new Error ( "No routes found" ) ;
257
258
}
258
-
259
259
performance . mark ( 'startGetRouteTransactionData' )
260
260
const apiReturnData = await getRouteTransactionData ( route ) ;
261
261
performance . mark ( 'endGetRouteTransactionData' )
@@ -267,6 +267,7 @@ export async function bridgeFunds(bridgingParams: BridgingParams, wallet: EIP155
267
267
const walletAddress = wallet . getAddress ( )
268
268
performance . mark ( 'endGetWalletAddress' )
269
269
console . log ( { approvalData} ) ;
270
+ let currentNonce = await sourceChainProvider . getTransactionCount ( walletAddress )
270
271
// approvalData from apiReturnData is null for native tokens
271
272
// Values are returned for ERC20 tokens but token allowance needs to be checked
272
273
if ( approvalData !== null ) {
@@ -311,13 +312,15 @@ export async function bridgeFunds(bridgingParams: BridgingParams, wallet: EIP155
311
312
data : approvalTransactionData . result ?. data ,
312
313
gasPrice : gasPrice ,
313
314
gasLimit : gasEstimate ,
315
+ nonce : currentNonce ,
314
316
} )
315
317
const receipt = typeof hash === 'string' ? hash : hash ?. hash
316
318
performance . mark ( 'endApprovalTransactionSend' )
317
319
console . log ( "Approval Transaction" , { receipt} ) ;
320
+ currentNonce ++
318
321
}
319
322
}
320
-
323
+
321
324
performance . mark ( 'startBridgingTransactionGasEstimate' )
322
325
const gasPrice = await sourceChainProvider . getGasPrice ( ) ;
323
326
let gasEstimate = BigInt ( '0x029a6b' ) * BigInt ( 4 )
@@ -344,6 +347,7 @@ export async function bridgeFunds(bridgingParams: BridgingParams, wallet: EIP155
344
347
value : apiReturnData . result . value ,
345
348
gasPrice : gasPrice ,
346
349
gasLimit : gasEstimate ,
350
+ nonce : currentNonce
347
351
} ) ;
348
352
const receipt = typeof hash === 'string' ? hash : hash ?. hash
349
353
console . log ( "Bridging Transaction : " , { receipt} ) ;
@@ -352,20 +356,15 @@ export async function bridgeFunds(bridgingParams: BridgingParams, wallet: EIP155
352
356
performance . mark ( 'startBridgingTransactionCheck' )
353
357
let interations = 0
354
358
while ( interations < 20 ) {
355
- const status = await getBridgeStatus ( {
356
- transactionHash : receipt ,
357
- fromChainId : bridgingParams . fromChainId ,
358
- toChainId : bridgingParams . toChainId
359
- } ) ;
360
- console . log (
361
- `SOURCE TX : ${ status . result . sourceTxStatus } \nDEST TX : ${ status . result . destinationTxStatus } `
362
- ) ;
363
- if ( status . result . destinationTxStatus == "COMPLETED" ) {
364
- console . log ( "BRIDGE COMPLETED. DEST TX HASH :" , status . result . destinationTransactionHash ) ;
365
- performance . mark ( 'endBridgingTransactionCheck' )
366
- printMeasurements ( )
367
- return
368
- }
359
+ const balance = await getErc20TokenBalance ( bridgingParams . toAssetAddress as Hex , bridgingParams . toChainId , walletAddress as Hex , false )
360
+ console . log ( 'Checking destination address' , { balance, originalAmount} ) ;
361
+
362
+ if ( balance >= originalAmount ) {
363
+ console . log ( 'Bridging completed' ) ;
364
+ performance . mark ( 'endBridgingTransactionCheck' )
365
+ printMeasurements ( )
366
+ return
367
+ }
369
368
await new Promise ( resolve => setTimeout ( resolve , 1500 ) ) ;
370
369
interations ++
371
370
}
0 commit comments