@@ -110,6 +110,61 @@ describe('UniswapAPI', () => {
110110 expect ( quote . routes [ 0 ] ! . steps [ 0 ] ! . minAmountOut ) . toBe ( '994000' )
111111 } )
112112
113+ it ( 'tags Across bridge quotes so status polling uses the Across API' , async ( ) => {
114+ const fetch = jest . fn ( async ( ) =>
115+ makeResponse ( {
116+ requestId : 'request-id' ,
117+ routing : 'BRIDGE' ,
118+ quote : {
119+ chainId : 1 ,
120+ destinationChainId : 8453 ,
121+ input : { amount : '1000000' , token : tokenIn } ,
122+ output : { amount : '999000' , token : tokenIn , recipient : userAddress } ,
123+ swapper : userAddress ,
124+ tradeType : 'EXACT_INPUT' ,
125+ quoteId : 'quote-id' ,
126+ exclusiveRelayer : '0x1111111111111111111111111111111111111111' ,
127+ exclusivityDeadline : 100 ,
128+ fillDeadline : 200
129+ }
130+ } )
131+ )
132+ const uniswapApi = new UniswapAPI ( { fetch : fetch as any , apiKey : 'test-key' } )
133+
134+ const quote = await uniswapApi . quote ( {
135+ fromAsset : {
136+ address : tokenIn ,
137+ amount : 1000000n ,
138+ chainId : 1n ,
139+ decimals : 6 ,
140+ flags : { canTopUpGasTank : false , isFeeToken : false , onGasTank : false , rewardsType : null } ,
141+ marketDataIn : [ ] ,
142+ name : 'USDC' ,
143+ priceIn : [ { baseCurrency : 'usd' , price : 1 } ] ,
144+ symbol : 'USDC'
145+ } as any ,
146+ fromChainId : 1 ,
147+ fromTokenAddress : tokenIn ,
148+ toAsset : {
149+ address : tokenIn ,
150+ chainId : 8453 ,
151+ decimals : 6 ,
152+ name : 'USDC' ,
153+ symbol : 'USDC'
154+ } ,
155+ toChainId : 8453 ,
156+ toTokenAddress : tokenIn ,
157+ fromAmount : 1000000n ,
158+ userAddress,
159+ sort : 'output' ,
160+ isWrapOrUnwrap : false ,
161+ accountNativeBalance : 1n ,
162+ nativeSymbol : 'ETH'
163+ } )
164+
165+ expect ( quote . routes [ 0 ] ! . usedBridgeNames ) . toEqual ( [ 'across' ] )
166+ } )
167+
113168 it ( 'builds swap calldata and parses the approval spender' , async ( ) => {
114169 const spender = '0x1111111111111111111111111111111111111111'
115170 const fetch = ( jest . fn ( ) as any )
@@ -224,4 +279,49 @@ describe('UniswapAPI', () => {
224279 expect ( fetch ) . toHaveBeenCalledTimes ( 1 )
225280 expect ( tx . approvalData ) . toBe ( null )
226281 } )
282+
283+ describe ( 'getRouteStatus' , ( ) => {
284+ const txHash = '0x1111111111111111111111111111111111111111111111111111111111111111'
285+ const fillTxnRef = '0x2222222222222222222222222222222222222222222222222222222222222222'
286+
287+ it ( 'returns the source transaction id for same-chain swaps' , async ( ) => {
288+ const fetch = jest . fn ( )
289+ const uniswapApi = new UniswapAPI ( { fetch : fetch as any , apiKey : 'test-key' } )
290+
291+ await expect (
292+ uniswapApi . getRouteStatus ( { txHash, fromChainId : 1 , toChainId : 1 } )
293+ ) . resolves . toEqual ( { status : 'completed' , txnId : txHash } )
294+ expect ( fetch ) . not . toHaveBeenCalled ( )
295+ } )
296+
297+ it ( 'delegates Across bridge status checks to the Across API' , async ( ) => {
298+ const fetch = jest . fn ( async ( ) => makeResponse ( { status : 'filled' , fillTxnRef } ) )
299+ const uniswapApi = new UniswapAPI ( { fetch : fetch as any , apiKey : 'test-key' } )
300+
301+ await expect (
302+ uniswapApi . getRouteStatus ( { txHash, fromChainId : 1 , toChainId : 8453 , bridge : 'across' } )
303+ ) . resolves . toEqual ( { status : 'completed' , txnId : fillTxnRef } )
304+ expect ( fetch ) . toHaveBeenCalledWith (
305+ `https://app.across.to/api/deposit/status?depositTxnRef=${ txHash } `
306+ )
307+ } )
308+
309+ it ( 'uses the Uniswap status API for non-Across bridges' , async ( ) => {
310+ const fetch = jest . fn ( async ( ) =>
311+ makeResponse ( {
312+ requestId : 'request-id' ,
313+ swaps : [ { swapType : 'BRIDGE' , status : 'SUCCESS' , txHash : fillTxnRef } ]
314+ } )
315+ )
316+ const uniswapApi = new UniswapAPI ( { fetch : fetch as any , apiKey : 'test-key' } )
317+
318+ await expect (
319+ uniswapApi . getRouteStatus ( { txHash, fromChainId : 1 , toChainId : 8453 } )
320+ ) . resolves . toEqual ( { status : 'completed' , txnId : fillTxnRef } )
321+ expect ( fetch ) . toHaveBeenCalledWith (
322+ `https://trade-api.gateway.uniswap.org/v1/swaps?txHashes=${ txHash } &chainId=1` ,
323+ { headers : expect . any ( Object ) }
324+ )
325+ } )
326+ } )
227327} )
0 commit comments