Skip to content

Commit

Permalink
Adjust price impact for swap out token decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
Sluder committed Nov 23, 2023
1 parent f3e5ebe commit ab36ce5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/dex/wingriders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ab36ce5

Please sign in to comment.