Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
1f09757c
Unverified
Commit
1f09757c
authored
Jun 12, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(lp fee): correct the computation of the realized LP fee
parent
7e49babf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
1 deletion
+41
-1
prices.test.ts
src/utils/prices.test.ts
+40
-0
prices.ts
src/utils/prices.ts
+1
-1
No files found.
src/utils/prices.test.ts
0 → 100644
View file @
1f09757c
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
)))
})
})
})
src/utils/prices.ts
View file @
1f09757c
...
@@ -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
)
)
)
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment