Skip to content

Commit

Permalink
add effective SP
Browse files Browse the repository at this point in the history
  • Loading branch information
franzns committed Feb 2, 2024
1 parent 4ed6801 commit cb3cf8a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modules/sor/sor.gql
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type GqlSorGetSwaps {
swapAmountScaled: BigDecimal!
returnAmount: AmountHumanReadable!
returnAmountScaled: BigDecimal!
effectivePrice: AmountHumanReadable!
effectivePriceReversed: AmountHumanReadable!
routes: [GqlSorSwapRoute!]!
priceImpact: AmountHumanReadable!
}
Expand Down
8 changes: 8 additions & 0 deletions modules/sor/sorV2/sorV2.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ export class SorV2Service implements SwapService {
const returnAmount = swap.swapKind === SwapKind.GivenIn ? outputAmount : inputAmount;
const swapAmount = swap.swapKind === SwapKind.GivenIn ? inputAmount : outputAmount;

const effectivePrice = inputAmount.divDownFixed(outputAmount.amount);
const effectivePriceReversed = outputAmount.divDownFixed(inputAmount.amount);

console.log(effectivePrice.amount);
console.log(effectivePriceReversed.amount);

const routes = mapRoutes(
swap.swaps,
inputAmount.amount.toString(),
Expand Down Expand Up @@ -206,6 +212,8 @@ export class SorV2Service implements SwapService {
swapAmountScaled: swapAmount.amount.toString(),
returnAmount: formatUnits(returnAmount.amount, returnAmount.token.decimals),
returnAmountScaled: returnAmount.amount.toString(),
effectivePrice: formatUnits(effectivePrice.amount, effectivePrice.token.decimals),
effectivePriceReversed: formatUnits(effectivePriceReversed.amount, effectivePriceReversed.token.decimals),
routes: routes.map((route) => ({
...route,
hops: route.hops.map((hop) => ({
Expand Down
2 changes: 2 additions & 0 deletions modules/sor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export const zeroResponseV2 = (swapType: GqlSorSwapType, tokenIn: string, tokenO
swapAmountScaled: '0',
returnAmount: '0',
returnAmountScaled: '0',
effectivePrice: '0',
effectivePriceReversed: '0',
routes: [],
priceImpact: '0',
};
Expand Down

0 comments on commit cb3cf8a

Please sign in to comment.