|
| 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 | +}) |
0 commit comments