Skip to content

Commit

Permalink
Merge branch 'master' into sluder/sign-type-error
Browse files Browse the repository at this point in the history
  • Loading branch information
Sluder authored Jul 18, 2023
2 parents 75ec57a + 182f955 commit 3c904fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to Dexter will be documented in this file.

## [UNRELEASED]

- Fix for WingRiders price impact calculation when using a non ADA swap in token.

## [v2.0.0]

- Adjust Kupo & Blockfrost data providers to accept an optional `RequestConfig`.
Expand Down
9 changes: 6 additions & 3 deletions src/dex/wingriders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { Asset, Token } from './models/asset';
import { LiquidityPool } from './models/liquidity-pool';
import { BaseDataProvider } from '@providers/data/base-data-provider';
import { correspondingReserves } from '@app/utils';
import { correspondingReserves, tokensMatch } from '@app/utils';
import { AddressType, DatumParameterKey } from '@app/constants';
import { DefinitionBuilder } from '@app/definition-builder';
import order from '@dex/definitions/wingriders/order';
Expand Down Expand Up @@ -160,9 +160,12 @@ export class WingRiders extends BaseDex {
priceImpactPercent(liquidityPool: LiquidityPool, swapInToken: Token, swapInAmount: bigint): number {
const estimatedReceive: bigint = this.estimatedReceive(liquidityPool, swapInToken, swapInAmount);
const swapPrice: number = Number(swapInAmount) / Number(estimatedReceive);
const poolPrice: number = tokensMatch(liquidityPool.assetA, swapInToken)
? liquidityPool.price
: (1 / liquidityPool.price);

return Math.abs(swapPrice - liquidityPool.price)
/ ((swapPrice + liquidityPool.price) / 2)
return Math.abs(swapPrice - poolPrice)
/ ((swapPrice + poolPrice) / 2)
* 100;
}

Expand Down

0 comments on commit 3c904fa

Please sign in to comment.