From ab36ce55c88ca48103ee653ccc701cb2a6b88860 Mon Sep 17 00:00:00 2001 From: Sluder Date: Wed, 22 Nov 2023 23:09:43 -0500 Subject: [PATCH] Adjust price impact for swap out token decimals --- src/dex/wingriders.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dex/wingriders.ts b/src/dex/wingriders.ts index 4548ddc..13e98be 100644 --- a/src/dex/wingriders.ts +++ b/src/dex/wingriders.ts @@ -177,9 +177,13 @@ export class WingRiders extends BaseDex { } priceImpactPercent(liquidityPool: LiquidityPool, swapInToken: Token, swapInAmount: bigint): number { + const swapOutTokenDecimals: number = tokensMatch(liquidityPool.assetA, swapInToken) + ? (liquidityPool.assetB === 'lovelace' ? 6 : liquidityPool.assetB.decimals) + : (liquidityPool.assetA === 'lovelace' ? 6 : liquidityPool.assetA.decimals) + const estimatedReceive: bigint = this.estimatedReceive(liquidityPool, swapInToken, swapInAmount); const swapPrice: number = (Number(swapInAmount) / 10**(swapInToken === 'lovelace' ? 6 : swapInToken.decimals)) - / Number(estimatedReceive); + / (Number(estimatedReceive) / 10**swapOutTokenDecimals); const poolPrice: number = tokensMatch(liquidityPool.assetA, swapInToken) ? liquidityPool.price : (1 / liquidityPool.price);