@@ -11,6 +11,7 @@ import {
1111 decodeSurplusFlag ,
1212 encodeSurplusArg ,
1313} from './encoding/flags' ;
14+ import { logger } from './logger' ;
1415import { CrocPoolView } from './pool' ;
1516import { CrocSlotReader } from './slots' ;
1617import {
@@ -401,34 +402,100 @@ export class CrocSwapPlan {
401402 async calcImpact ( ) : Promise < CrocImpact > {
402403 const TIP = 0 ;
403404 const limitPrice = this . sellBase ? MAX_SQRT_PRICE : MIN_SQRT_PRICE ;
404-
405- const impact = await (
406- await this . context
407- ) . slipQuery . calcImpact (
408- this . baseToken . tokenAddr ,
409- this . quoteToken . tokenAddr ,
410- this . poolIndex ,
411- this . sellBase ,
412- this . qtyInBase ,
413- await this . qty ,
414- TIP ,
415- limitPrice ,
416- ) ;
417-
418- const baseQty = this . baseToken . toDisplay ( impact . baseFlow . abs ( ) ) ;
419- const quoteQty = this . quoteToken . toDisplay ( impact . quoteFlow . abs ( ) ) ;
420- const spotPrice = decodeCrocPrice ( impact . finalPrice ) ;
421-
422- const startPrice = this . poolView . displayPrice ( ) ;
423- const finalPrice = this . poolView . toDisplayPrice ( spotPrice ) ;
424-
425- return {
426- sellQty : this . sellBase ? await baseQty : await quoteQty ,
427- buyQty : this . sellBase ? await quoteQty : await baseQty ,
428- finalPrice : await finalPrice ,
429- percentChange :
430- ( ( await finalPrice ) - ( await startPrice ) ) / ( await startPrice ) ,
431- } ;
405+ const qty = await this . qty ;
406+
407+ try {
408+ console . log (
409+ `this.baseToken.tokenAddr: ${
410+ this . baseToken . tokenAddr
411+ } , this.quoteToken.tokenAddr: ${
412+ this . quoteToken . tokenAddr
413+ } , this.poolIndex: ${ this . poolIndex } , this.sellBase: ${
414+ this . sellBase
415+ } , this.qtyInBase: ${ this . qtyInBase } , qty: ${ await this
416+ . qty } , TIP: ${ TIP } , limitPrice: ${ limitPrice } `,
417+ ) ;
418+
419+ const impact = await (
420+ await this . context
421+ ) . slipQuery . calcImpact (
422+ this . baseToken . tokenAddr ,
423+ this . quoteToken . tokenAddr ,
424+ this . poolIndex ,
425+ this . sellBase ,
426+ this . qtyInBase ,
427+ qty ,
428+ TIP ,
429+ limitPrice ,
430+ ) ;
431+
432+ const baseQty = this . baseToken . toDisplay ( impact . baseFlow . abs ( ) ) ;
433+ const quoteQty = this . quoteToken . toDisplay ( impact . quoteFlow . abs ( ) ) ;
434+ const spotPrice = decodeCrocPrice ( impact . finalPrice ) ;
435+
436+ const startPrice = this . poolView . displayPrice ( ) ;
437+ const finalPrice = this . poolView . toDisplayPrice ( spotPrice ) ;
438+
439+ logger ( 'info' , 'calcImpact' , {
440+ data : {
441+ baseToken : this . baseToken . tokenAddr ,
442+ quoteToken : this . quoteToken . tokenAddr ,
443+ poolIndex : this . poolIndex ,
444+ sellBase : this . sellBase ,
445+ qtyInBase : this . qtyInBase ,
446+ qty,
447+ TIP ,
448+ limitPrice,
449+ network : process . env . REACT_APP_NETWORK ,
450+ } ,
451+ dataFormatted : {
452+ baseToken : this . baseToken . tokenAddr ,
453+ quoteToken : this . quoteToken . tokenAddr ,
454+ poolIndex : this . poolIndex ,
455+ sellBase : this . sellBase ,
456+ qtyInBase : this . qtyInBase ,
457+ qty : qty . toString ( ) ,
458+ TIP ,
459+ limitPrice : limitPrice . toString ( ) ,
460+ network : process . env . REACT_APP_NETWORK ,
461+ } ,
462+ } ) ;
463+ return {
464+ sellQty : this . sellBase ? await baseQty : await quoteQty ,
465+ buyQty : this . sellBase ? await quoteQty : await baseQty ,
466+ finalPrice : await finalPrice ,
467+ percentChange :
468+ ( ( await finalPrice ) - ( await startPrice ) ) / ( await startPrice ) ,
469+ } ;
470+ } catch ( error ) {
471+ logger ( 'error' , 'calcImpact' , {
472+ data : {
473+ baseToken : this . baseToken . tokenAddr ,
474+ quoteToken : this . quoteToken . tokenAddr ,
475+ poolIndex : this . poolIndex ,
476+ sellBase : this . sellBase ,
477+ qtyInBase : this . qtyInBase ,
478+ qty,
479+ TIP ,
480+ limitPrice,
481+ network : process . env . REACT_APP_NETWORK ,
482+ error,
483+ } ,
484+ dataFormatted : {
485+ baseToken : this . baseToken . tokenAddr ,
486+ quoteToken : this . quoteToken . tokenAddr ,
487+ poolIndex : this . poolIndex ,
488+ sellBase : this . sellBase ,
489+ qtyInBase : this . qtyInBase ,
490+ qty : qty . toString ( ) ,
491+ TIP ,
492+ limitPrice : limitPrice . toString ( ) ,
493+ network : process . env . REACT_APP_NETWORK ,
494+ error,
495+ } ,
496+ } ) ;
497+ throw error ;
498+ }
432499 }
433500
434501 public maskSurplusArgs ( args ?: CrocSwapExecOpts ) : number {
0 commit comments