Skip to content

Commit 1f09757

Browse files
committed
fix(lp fee): correct the computation of the realized LP fee
1 parent 7e49bab commit 1f09757

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/utils/prices.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { ChainId, JSBI, Pair, Route, Token, TokenAmount, Trade, TradeType } from '@uniswap/sdk'
2+
import { computeTradePriceBreakdown } from './prices'
3+
4+
describe('prices', () => {
5+
const token1 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000001', 18)
6+
const token2 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000002', 18)
7+
const token3 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000003', 18)
8+
9+
const pair12 = new Pair(new TokenAmount(token1, JSBI.BigInt(10000)), new TokenAmount(token2, JSBI.BigInt(20000)))
10+
const pair23 = new Pair(new TokenAmount(token2, JSBI.BigInt(20000)), new TokenAmount(token3, JSBI.BigInt(30000)))
11+
12+
describe('computeTradePriceBreakdown', () => {
13+
it('returns undefined for undefined', () => {
14+
expect(computeTradePriceBreakdown(undefined)).toEqual({
15+
priceImpactWithoutFee: undefined,
16+
realizedLPFee: undefined
17+
})
18+
})
19+
20+
it('correct realized lp fee for single hop', () => {
21+
expect(
22+
computeTradePriceBreakdown(
23+
new Trade(new Route([pair12], token1), new TokenAmount(token1, JSBI.BigInt(1000)), TradeType.EXACT_INPUT)
24+
).realizedLPFee
25+
).toEqual(new TokenAmount(token1, JSBI.BigInt(3)))
26+
})
27+
28+
it('correct realized lp fee for double hop', () => {
29+
expect(
30+
computeTradePriceBreakdown(
31+
new Trade(
32+
new Route([pair12, pair23], token1),
33+
new TokenAmount(token1, JSBI.BigInt(1000)),
34+
TradeType.EXACT_INPUT
35+
)
36+
).realizedLPFee
37+
).toEqual(new TokenAmount(token1, JSBI.BigInt(5)))
38+
})
39+
})
40+
})

src/utils/prices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function computeTradePriceBreakdown(
1818
: ONE_HUNDRED_PERCENT.subtract(
1919
trade.route.pairs.reduce<Fraction>(
2020
(currentFee: Fraction): Fraction => currentFee.multiply(INPUT_FRACTION_AFTER_FEE),
21-
INPUT_FRACTION_AFTER_FEE
21+
ONE_HUNDRED_PERCENT
2222
)
2323
)
2424

0 commit comments

Comments
 (0)