@@ -17,12 +17,13 @@ import {
1717} from '@mark/core' ;
1818import { ProcessingContext } from '../init' ;
1919import { submitTransactionWithLogging } from '../helpers/transactions' ;
20- import { RebalanceTransactionMemo , buildTransactionsForAction } from '@mark/rebalance' ;
21- import { createRebalanceOperation , TransactionReceipt } from '@mark/database' ;
20+ import { buildTransactionsForAction } from '@mark/rebalance' ;
21+ import { TransactionReceipt } from '@mark/database' ;
2222import { getBridgeTypeFromTag } from './helpers' ;
2323import { RebalanceRunState } from './types' ;
2424import { runThresholdRebalance , ThresholdRebalanceDescriptor } from './thresholdEngine' ;
2525import { runCallbackLoop , RebalanceOperation } from './callbackEngine' ;
26+ import { executeEvmBridge } from './bridgeExecution' ;
2627
2728/**
2829 * Descriptor that parameterizes the generic Aave token rebalancer for a specific flow.
@@ -252,13 +253,12 @@ export const executeStargateBridgeForAaveToken = async (
252253 const { config, chainService, fillServiceChainService, logger, requestId, rebalance } = context ;
253254 const tokenConfig = descriptor . getConfig ( config ) ! ;
254255 const bridgeConfig = tokenConfig . bridge ;
255- const actions : RebalanceAction [ ] = [ ] ;
256256
257257 const bridgeType = SupportedBridge . Stargate ;
258258 const adapter = rebalance . getAdapter ( bridgeType ) ;
259259 if ( ! adapter ) {
260260 logger . error ( 'Stargate adapter not found' , { requestId } ) ;
261- return actions ;
261+ return [ ] ;
262262 }
263263
264264 // Select the correct chain service based on whether the sender is the fill service address
@@ -273,7 +273,7 @@ export const executeStargateBridgeForAaveToken = async (
273273 senderAddress,
274274 fillerSenderAddress,
275275 } ) ;
276- return actions ;
276+ return [ ] ;
277277 }
278278
279279 const sourceTokenAddress = getTokenAddressFromConfig ( descriptor . sourceTokenTickerHash , MAINNET_CHAIN_ID , config ) ! ;
@@ -300,122 +300,37 @@ export const executeStargateBridgeForAaveToken = async (
300300 } ) ;
301301
302302 try {
303- // Get quote
304- const receivedAmountStr = await adapter . getReceivedAmount ( amount . toString ( ) , route ) ;
305- logger . info ( 'Received Stargate quote' , {
306- requestId,
307- amountToBridge : amount . toString ( ) ,
308- receivedAmount : receivedAmountStr ,
309- } ) ;
310-
311- // Check slippage
312- const receivedAmount = BigInt ( receivedAmountStr ) ;
313- const slippage = BigInt ( slippageDbps ) ;
314- const minimumAcceptableAmount = amount - ( amount * slippage ) / DBPS_MULTIPLIER ;
315-
316- if ( receivedAmount < minimumAcceptableAmount ) {
317- logger . warn ( 'Stargate quote does not meet slippage requirements' , {
318- requestId,
319- amountToBridge : amount . toString ( ) ,
320- receivedAmount : receivedAmount . toString ( ) ,
321- minimumAcceptableAmount : minimumAcceptableAmount . toString ( ) ,
322- slippageDbps,
323- } ) ;
324- return actions ;
325- }
326-
327- // Get bridge transactions
328- const bridgeTxRequests = await adapter . send ( senderAddress , recipientAddress , amount . toString ( ) , route ) ;
329- if ( ! bridgeTxRequests . length ) {
330- logger . error ( 'No bridge transactions returned from Stargate adapter' , { requestId } ) ;
331- return actions ;
332- }
333-
334- logger . info ( 'Prepared Stargate bridge transactions' , {
335- requestId,
336- transactionCount : bridgeTxRequests . length ,
337- } ) ;
338-
339- // Execute bridge transactions
340- let receipt : TransactionReceipt | undefined ;
341- let effectiveBridgedAmount = amount . toString ( ) ;
342-
343- for ( const { transaction, memo, effectiveAmount } of bridgeTxRequests ) {
344- logger . info ( 'Submitting Stargate bridge transaction' , {
345- requestId,
346- memo,
347- to : transaction . to ,
348- } ) ;
349-
350- const result = await submitTransactionWithLogging ( {
351- chainService : selectedChainService ,
352- logger,
353- chainId : MAINNET_CHAIN_ID ,
354- txRequest : {
355- to : transaction . to ! ,
356- data : transaction . data ! ,
357- value : ( transaction . value || 0 ) . toString ( ) ,
358- chainId : Number ( MAINNET_CHAIN_ID ) ,
359- from : senderAddress ,
360- funcSig : transaction . funcSig || '' ,
361- } ,
362- zodiacConfig : { walletType : WalletType . EOA } ,
363- context : { requestId, route, bridgeType, transactionType : memo } ,
364- } ) ;
365-
366- logger . info ( 'Successfully submitted Stargate bridge transaction' , {
367- requestId,
368- memo,
369- transactionHash : result . hash ,
370- } ) ;
371-
372- if ( memo === RebalanceTransactionMemo . Rebalance ) {
373- receipt = result . receipt ! as unknown as TransactionReceipt ;
374- if ( effectiveAmount ) {
375- effectiveBridgedAmount = effectiveAmount ;
376- }
377- }
378- }
379-
380- // Create database record
381- await createRebalanceOperation ( {
382- earmarkId : null ,
383- originChainId : route . origin ,
384- destinationChainId : route . destination ,
385- tickerHash : descriptor . sourceTokenTickerHash ,
386- amount : effectiveBridgedAmount ,
387- slippage : slippageDbps ,
388- status : RebalanceOperationStatus . PENDING ,
389- bridge : descriptor . bridgeTag ,
390- transactions : receipt ? { [ MAINNET_CHAIN_ID ] : receipt } : undefined ,
391- recipient : recipientAddress ,
392- } ) ;
393-
394- logger . info ( `Successfully created ${ descriptor . name } rebalance operation` , {
395- requestId,
396- originTxHash : receipt ?. transactionHash ,
397- amountToBridge : effectiveBridgedAmount ,
398- bridge : descriptor . bridgeTag ,
399- } ) ;
400-
401- actions . push ( {
402- bridge : bridgeType ,
403- amount : amount . toString ( ) ,
404- origin : route . origin ,
405- destination : route . destination ,
406- asset : route . asset ,
407- transaction : receipt ?. transactionHash || '' ,
303+ const result = await executeEvmBridge ( {
304+ context,
305+ adapter,
306+ route,
307+ amount,
308+ sender : senderAddress ,
408309 recipient : recipientAddress ,
310+ slippageTolerance : BigInt ( slippageDbps ) ,
311+ slippageMultiplier : DBPS_MULTIPLIER ,
312+ chainService : selectedChainService ,
313+ senderConfig : {
314+ address : senderAddress ,
315+ label : isFillerSender ? 'fill-service' : 'market-maker' ,
316+ } ,
317+ dbRecord : {
318+ earmarkId : null ,
319+ tickerHash : descriptor . sourceTokenTickerHash ,
320+ bridgeTag : descriptor . bridgeTag ,
321+ status : RebalanceOperationStatus . PENDING ,
322+ } ,
323+ label : `Stargate ${ descriptor . name } ` ,
409324 } ) ;
325+ return result . actions ;
410326 } catch ( error ) {
411327 logger . error ( `Failed to execute Stargate bridge for ${ descriptor . name } ` , {
412328 requestId,
413329 route,
414330 error : jsonifyError ( error ) ,
415331 } ) ;
332+ return [ ] ;
416333 }
417-
418- return actions ;
419334} ;
420335
421336/**
@@ -468,11 +383,12 @@ async function processAaveTokenOperation(
468383 const selectedChainService = isForFillService && fillServiceChainService ? fillServiceChainService : chainService ;
469384
470385 if ( isForFillService && ! fillServiceChainService ) {
471- logger . warn ( `Fill service chain service not available for ${ descriptor . name } callback, using main chain service ` , {
386+ logger . error ( `Fill service chain service not available for ${ descriptor . name } callback, skipping ` , {
472387 ...logContext ,
473388 recipient : operation . recipient ,
474389 fsAddress,
475390 } ) ;
391+ return ;
476392 }
477393
478394 const bridgeType = operation . bridge ? getBridgeTypeFromTag ( operation . bridge ) : undefined ;
0 commit comments