Skip to content

Commit

Permalink
adding SORv2 priceImpact in basis points (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbronco authored Dec 14, 2023
1 parent 9e7752d commit 67ca94e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion modules/beethoven/balancer-sor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export class BalancerSorService {
marketSp: string;
swaps: SwapV2[];
tokenAddresses: string[];
priceImpact?: string;
}): GqlSorGetSwapsResponse {
const {
tokenIn,
Expand All @@ -164,6 +165,7 @@ export class BalancerSorService {
marketSp,
swaps,
tokenAddresses,
priceImpact: rawPriceImpact,
} = swapData;

const tokenInAmountFixed = formatFixed(tokenInAmtEvm, this.getTokenDecimals(tokenIn, tokens));
Expand Down Expand Up @@ -214,7 +216,7 @@ export class BalancerSorService {
})),
effectivePrice: effectivePrice.toString(),
effectivePriceReversed: effectivePriceReversed.toString(),
priceImpact: priceImpact.toString(),
priceImpact: rawPriceImpact ? rawPriceImpact : priceImpact.toString(),
};
}

Expand Down
2 changes: 2 additions & 0 deletions modules/sor/sorV2/sorV2.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class SwapResultV2 implements SwapResult {
): Promise<GqlSorGetSwapsResponse> {
const sor = new BalancerSorService();
const tokens = await tokenService.getTokens();
const priceImpact = swap.priceImpact.percentage.toFixed(4);
let poolIds: string[];
if (swap.isBatchSwap) {
const swaps = swap.swaps as BatchSwapStep[];
Expand Down Expand Up @@ -130,6 +131,7 @@ class SwapResultV2 implements SwapResult {
marketSp: '0', // Daniel confirmed returning 0 should be fine here
swaps: this.mapSwaps(swap.swaps, swap.assets),
tokenAddresses: swap.assets,
priceImpact,
};
return sor.formatResponse(swapData);
}
Expand Down

0 comments on commit 67ca94e

Please sign in to comment.