From b15444a374045baca919662abab75a54ab3f2dd7 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 24 Nov 2024 20:15:32 -0500 Subject: [PATCH] Version bump --- package.json | 2 +- src/dex/wingriders-v2.ts | 7 ++++++- src/dex/wingriders.ts | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index c990309..044721a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@indigo-labs/dexter", - "version": "5.4.7", + "version": "5.4.8", "license": "MIT", "author": "Zachary Sluder", "keywords": [ diff --git a/src/dex/wingriders-v2.ts b/src/dex/wingriders-v2.ts index 26905a5..9c3bd72 100644 --- a/src/dex/wingriders-v2.ts +++ b/src/dex/wingriders-v2.ts @@ -181,8 +181,13 @@ export class WingRidersV2 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) / Number(estimatedReceive); + const swapPrice: number = (Number(swapInAmount) / 10**(swapInToken === 'lovelace' ? 6 : swapInToken.decimals)) + / (Number(estimatedReceive) / 10**swapOutTokenDecimals); const poolPrice: number = tokensMatch(liquidityPool.assetA, swapInToken) ? liquidityPool.price : (1 / liquidityPool.price); diff --git a/src/dex/wingriders.ts b/src/dex/wingriders.ts index 851e4cd..a7c6665 100644 --- a/src/dex/wingriders.ts +++ b/src/dex/wingriders.ts @@ -184,8 +184,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) / Number(estimatedReceive); + const swapPrice: number = (Number(swapInAmount) / 10**(swapInToken === 'lovelace' ? 6 : swapInToken.decimals)) + / (Number(estimatedReceive) / 10**swapOutTokenDecimals); const poolPrice: number = tokensMatch(liquidityPool.assetA, swapInToken) ? liquidityPool.price : (1 / liquidityPool.price);