Commit 1f09757c authored by Moody Salem's avatar Moody Salem

fix(lp fee): correct the computation of the realized LP fee

parent 7e49babf
import { ChainId, JSBI, Pair, Route, Token, TokenAmount, Trade, TradeType } from '@uniswap/sdk'
import { computeTradePriceBreakdown } from './prices'
describe('prices', () => {
const token1 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000001', 18)
const token2 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000002', 18)
const token3 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000003', 18)
const pair12 = new Pair(new TokenAmount(token1, JSBI.BigInt(10000)), new TokenAmount(token2, JSBI.BigInt(20000)))
const pair23 = new Pair(new TokenAmount(token2, JSBI.BigInt(20000)), new TokenAmount(token3, JSBI.BigInt(30000)))
describe('computeTradePriceBreakdown', () => {
it('returns undefined for undefined', () => {
expect(computeTradePriceBreakdown(undefined)).toEqual({
priceImpactWithoutFee: undefined,
realizedLPFee: undefined
})
})
it('correct realized lp fee for single hop', () => {
expect(
computeTradePriceBreakdown(
new Trade(new Route([pair12], token1), new TokenAmount(token1, JSBI.BigInt(1000)), TradeType.EXACT_INPUT)
).realizedLPFee
).toEqual(new TokenAmount(token1, JSBI.BigInt(3)))
})
it('correct realized lp fee for double hop', () => {
expect(
computeTradePriceBreakdown(
new Trade(
new Route([pair12, pair23], token1),
new TokenAmount(token1, JSBI.BigInt(1000)),
TradeType.EXACT_INPUT
)
).realizedLPFee
).toEqual(new TokenAmount(token1, JSBI.BigInt(5)))
})
})
})
...@@ -18,7 +18,7 @@ export function computeTradePriceBreakdown( ...@@ -18,7 +18,7 @@ export function computeTradePriceBreakdown(
: ONE_HUNDRED_PERCENT.subtract( : ONE_HUNDRED_PERCENT.subtract(
trade.route.pairs.reduce<Fraction>( trade.route.pairs.reduce<Fraction>(
(currentFee: Fraction): Fraction => currentFee.multiply(INPUT_FRACTION_AFTER_FEE), (currentFee: Fraction): Fraction => currentFee.multiply(INPUT_FRACTION_AFTER_FEE),
INPUT_FRACTION_AFTER_FEE ONE_HUNDRED_PERCENT
) )
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment