1
1
import { DutchOrder , FillInfo , OrderValidation } from '@uniswap/uniswapx-sdk'
2
+
2
3
import { Unit } from 'aws-embedded-metrics'
3
4
import { default as Logger } from 'bunyan'
4
5
import { ethers } from 'ethers'
@@ -95,7 +96,7 @@ export class CheckOrderStatusHandler extends SfnLambdaHandler<ContainerInjected,
95
96
gasCostInETH ,
96
97
receipt . effectiveGasPrice . toString ( ) ,
97
98
receipt . gasUsed . toString ( ) ,
98
- settledAmounts
99
+ settledAmounts . reduce ( ( prev , cur ) => ( prev && prev . amountOut > cur . amountOut ? prev : cur ) )
99
100
)
100
101
101
102
const percentDecayed = ( timestamp - order . decayStartTime ) / ( order . decayEndTime - order . decayStartTime )
@@ -197,7 +198,7 @@ export class CheckOrderStatusHandler extends SfnLambdaHandler<ContainerInjected,
197
198
gasCostInETH ,
198
199
receipt . effectiveGasPrice . toString ( ) ,
199
200
receipt . gasUsed . toString ( ) ,
200
- settledAmounts
201
+ settledAmounts . reduce ( ( prev , cur ) => ( prev && prev . amountOut > cur . amountOut ? prev : cur ) )
201
202
)
202
203
203
204
const percentDecayed =
@@ -374,37 +375,35 @@ export class CheckOrderStatusHandler extends SfnLambdaHandler<ContainerInjected,
374
375
gasCostInETH : string ,
375
376
gasPriceWei : string ,
376
377
gasUsed : string ,
377
- settledAmounts : SettledAmount [ ]
378
+ userAmount : SettledAmount
378
379
) : void {
379
- settledAmounts . forEach ( ( settledAmount ) => {
380
- log . info ( {
381
- orderInfo : {
382
- orderStatus : ORDER_STATUS . FILLED ,
383
- orderHash : fill . orderHash ,
384
- quoteId : quoteId ,
385
- filler : fill . filler ,
386
- nonce : fill . nonce . toString ( ) ,
387
- offerer : fill . swapper ,
388
- tokenIn : settledAmount . tokenIn ,
389
- amountIn : settledAmount . amountIn ,
390
- tokenOut : settledAmount . tokenOut ,
391
- amountOut : settledAmount . amountOut ,
392
- blockNumber : fill . blockNumber ,
393
- txHash : fill . txHash ,
394
- fillTimestamp : timestamp ,
395
- gasPriceWei : gasPriceWei ,
396
- gasUsed : gasUsed ,
397
- gasCostInETH : gasCostInETH ,
398
- logTime : Math . floor ( Date . now ( ) / 1000 ) . toString ( ) ,
399
- } ,
400
- } )
380
+ log . info ( {
381
+ orderInfo : {
382
+ orderStatus : ORDER_STATUS . FILLED ,
383
+ orderHash : fill . orderHash ,
384
+ quoteId : quoteId ,
385
+ filler : fill . filler ,
386
+ nonce : fill . nonce . toString ( ) ,
387
+ offerer : fill . swapper ,
388
+ tokenIn : userAmount . tokenIn ,
389
+ amountIn : userAmount . amountIn ,
390
+ tokenOut : userAmount . tokenOut ,
391
+ amountOut : userAmount . amountOut ,
392
+ blockNumber : fill . blockNumber ,
393
+ txHash : fill . txHash ,
394
+ fillTimestamp : timestamp ,
395
+ gasPriceWei : gasPriceWei ,
396
+ gasUsed : gasUsed ,
397
+ gasCostInETH : gasCostInETH ,
398
+ logTime : Math . floor ( Date . now ( ) / 1000 ) . toString ( ) ,
399
+ } ,
401
400
} )
402
401
}
403
402
404
403
public getSettledAmounts ( fill : FillInfo , fillTimestamp : number , parsedOrder : DutchOrder ) : SettledAmount [ ] {
405
404
const nativeOutputs = parsedOrder . info . outputs . filter ( ( output ) => output . token . toLowerCase ( ) === NATIVE_ADDRESS )
406
405
const settledAmounts : SettledAmount [ ] = [ ]
407
- let amountIn : string | undefined
406
+ let amountIn : string
408
407
if ( parsedOrder . info . input . endAmount . eq ( parsedOrder . info . input . startAmount ) ) {
409
408
// If the order is EXACT_INPUT then the input will not decay and resolves to the startAmount/endAmount.
410
409
amountIn = parsedOrder . info . input . startAmount . toString ( )
@@ -428,10 +427,12 @@ export class CheckOrderStatusHandler extends SfnLambdaHandler<ContainerInjected,
428
427
} else {
429
428
// If the order is EXACT_OUTPUT we will have all the ERC20 transfers in the fill logs,
430
429
// only log the amountIn that matches the order input token.
430
+
431
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
431
432
const input = fill . inputs . find (
432
433
( input ) => input . token . toLowerCase ( ) === parsedOrder . info . input . token . toLowerCase ( )
433
- )
434
- amountIn = input ? .amount . toString ( )
434
+ ) !
435
+ amountIn = input . amount . toString ( )
435
436
436
437
// Add all the native outputs to the settledAmounts as they are not included in the fill logs.
437
438
// The amount is just the startAmount because the order is EXACT_OUTPUT so there is no decay on the outputs.
0 commit comments