Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
swap-v2-sdk
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
swap-v2-sdk
Commits
986db18d
Unverified
Commit
986db18d
authored
Jan 23, 2020
by
Noah Zinsmeister
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pad sig figs with trailing 0s
remove minimumDecimalPlaces argument
parent
7309e5dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
10 deletions
+12
-10
formatOutputs.ts
src/utils/formatOutputs.ts
+4
-3
computation.test.ts
test/computation.test.ts
+8
-7
No files found.
src/utils/formatOutputs.ts
View file @
986db18d
...
@@ -15,8 +15,7 @@ export function formatSignificant(
...
@@ -15,8 +15,7 @@ export function formatSignificant(
denominator
:
BigintIsh
=
ONE
,
denominator
:
BigintIsh
=
ONE
,
significantDigits
:
number
,
significantDigits
:
number
,
format
:
object
=
{
groupSeparator
:
''
},
format
:
object
=
{
groupSeparator
:
''
},
roundingMode
:
number
=
Decimal
.
ROUND_HALF_UP
,
roundingMode
:
number
=
Decimal
.
ROUND_HALF_UP
minimumDecimalPlaces
:
number
=
0
):
string
{
):
string
{
invariant
(
Number
.
isInteger
(
significantDigits
),
`
${
significantDigits
}
is not an integer.`
)
invariant
(
Number
.
isInteger
(
significantDigits
),
`
${
significantDigits
}
is not an integer.`
)
invariant
(
significantDigits
>
0
,
`
${
significantDigits
}
isn't positive.`
)
invariant
(
significantDigits
>
0
,
`
${
significantDigits
}
isn't positive.`
)
...
@@ -28,7 +27,9 @@ export function formatSignificant(
...
@@ -28,7 +27,9 @@ export function formatSignificant(
.
div
(
denominatorParsed
.
toString
())
.
div
(
denominatorParsed
.
toString
())
.
toSignificantDigits
(
significantDigits
)
.
toSignificantDigits
(
significantDigits
)
return
quotient
.
toFormat
(
return
quotient
.
toFormat
(
minimumDecimalPlaces
>
quotient
.
decimalPlaces
()
?
minimumDecimalPlaces
:
quotient
.
decimalPlaces
(),
quotient
.
precision
(
true
)
>=
significantDigits
?
quotient
.
decimalPlaces
()
:
significantDigits
-
(
quotient
.
precision
(
true
)
-
quotient
.
decimalPlaces
()),
format
format
)
)
}
}
...
...
test/computation.test.ts
View file @
986db18d
...
@@ -77,12 +77,11 @@ describe('entities', () => {
...
@@ -77,12 +77,11 @@ describe('entities', () => {
expect
(
route
.
midPrice
.
formatSignificant
(
2
)).
toEqual
(
'
1200
'
)
expect
(
route
.
midPrice
.
formatSignificant
(
2
)).
toEqual
(
'
1200
'
)
expect
(
route
.
midPrice
.
formatSignificant
(
3
)).
toEqual
(
'
1230
'
)
expect
(
route
.
midPrice
.
formatSignificant
(
3
)).
toEqual
(
'
1230
'
)
expect
(
route
.
midPrice
.
formatSignificant
(
4
)).
toEqual
(
'
1234
'
)
expect
(
route
.
midPrice
.
formatSignificant
(
4
)).
toEqual
(
'
1234
'
)
expect
(
route
.
midPrice
.
formatSignificant
(
5
)).
toEqual
(
'
1234
'
)
expect
(
route
.
midPrice
.
formatSignificant
(
5
)).
toEqual
(
'
1234.0
'
)
expect
(
route
.
midPrice
.
formatSignificant
(
4
,
{
groupSeparator
:
'
,
'
})).
toEqual
(
'
1,234
'
)
expect
(
route
.
midPrice
.
formatSignificant
(
5
,
{
groupSeparator
:
'
,
'
})).
toEqual
(
'
1,234.0
'
)
expect
(
route
.
midPrice
.
formatSignificant
(
4
,
undefined
,
undefined
,
2
)).
toEqual
(
'
1234.00
'
)
expect
(
route
.
midPrice
.
invert
().
formatSignificant
(
1
)).
toEqual
(
'
0.0008
'
)
expect
(
route
.
midPrice
.
invert
().
formatSignificant
(
1
)).
toEqual
(
'
0.0008
'
)
expect
(
route
.
midPrice
.
invert
().
formatSignificant
(
2
)).
toEqual
(
'
0.00081
'
)
expect
(
route
.
midPrice
.
invert
().
formatSignificant
(
2
)).
toEqual
(
'
0.00081
'
)
expect
(
route
.
midPrice
.
invert
().
formatSignificant
(
3
)).
toEqual
(
'
0.00081
'
)
expect
(
route
.
midPrice
.
invert
().
formatSignificant
(
3
)).
toEqual
(
'
0.00081
0
'
)
expect
(
route
.
midPrice
.
invert
().
formatSignificant
(
4
)).
toEqual
(
'
0.0008104
'
)
expect
(
route
.
midPrice
.
invert
().
formatSignificant
(
4
)).
toEqual
(
'
0.0008104
'
)
expect
(
route
.
midPrice
.
invert
().
formatSignificant
(
4
,
undefined
,
1
)).
toEqual
(
'
0.0008103
'
)
expect
(
route
.
midPrice
.
invert
().
formatSignificant
(
4
,
undefined
,
1
)).
toEqual
(
'
0.0008103
'
)
expect
(
route
.
midPrice
.
invert
().
formatSignificant
(
5
)).
toEqual
(
'
0.00081037
'
)
expect
(
route
.
midPrice
.
invert
().
formatSignificant
(
5
)).
toEqual
(
'
0.00081037
'
)
...
@@ -93,6 +92,8 @@ describe('entities', () => {
...
@@ -93,6 +92,8 @@ describe('entities', () => {
expect
(
route
.
midPrice
.
formatFixed
(
2
,
{
groupSeparator
:
'
,
'
})).
toEqual
(
'
1,234.00
'
)
expect
(
route
.
midPrice
.
formatFixed
(
2
,
{
groupSeparator
:
'
,
'
})).
toEqual
(
'
1,234.00
'
)
expect
(
route
.
midPrice
.
invert
().
formatFixed
(
0
)).
toEqual
(
'
0
'
)
expect
(
route
.
midPrice
.
invert
().
formatFixed
(
0
)).
toEqual
(
'
0
'
)
expect
(
route
.
midPrice
.
invert
().
formatFixed
(
1
)).
toEqual
(
'
0.0
'
)
expect
(
route
.
midPrice
.
invert
().
formatFixed
(
1
)).
toEqual
(
'
0.0
'
)
expect
(
route
.
midPrice
.
invert
().
formatFixed
(
2
)).
toEqual
(
'
0.00
'
)
expect
(
route
.
midPrice
.
invert
().
formatFixed
(
3
)).
toEqual
(
'
0.001
'
)
expect
(
route
.
midPrice
.
invert
().
formatFixed
(
4
)).
toEqual
(
'
0.0008
'
)
expect
(
route
.
midPrice
.
invert
().
formatFixed
(
4
)).
toEqual
(
'
0.0008
'
)
expect
(
route
.
midPrice
.
invert
().
formatFixed
(
5
)).
toEqual
(
'
0.00081
'
)
expect
(
route
.
midPrice
.
invert
().
formatFixed
(
5
)).
toEqual
(
'
0.00081
'
)
expect
(
route
.
midPrice
.
invert
().
formatFixed
(
6
)).
toEqual
(
'
0.000810
'
)
expect
(
route
.
midPrice
.
invert
().
formatFixed
(
6
)).
toEqual
(
'
0.000810
'
)
...
@@ -123,7 +124,7 @@ describe('entities', () => {
...
@@ -123,7 +124,7 @@ describe('entities', () => {
).
toEqual
(
inputAmount
.
toString
())
).
toEqual
(
inputAmount
.
toString
())
expect
(
trade
.
nextMidPrice
.
formatSignificant
(
18
)).
toEqual
(
'
1.38958368072925352
'
)
expect
(
trade
.
nextMidPrice
.
formatSignificant
(
18
)).
toEqual
(
'
1.38958368072925352
'
)
expect
(
trade
.
nextMidPrice
.
invert
().
formatSignificant
(
18
)).
toEqual
(
'
0.71964
'
)
expect
(
trade
.
nextMidPrice
.
invert
().
formatSignificant
(
18
)).
toEqual
(
'
0.71964
0000000000000
'
)
expect
(
trade
.
slippage
.
formatSignificant
(
18
)).
toEqual
(
'
-16.8751042187760547
'
)
expect
(
trade
.
slippage
.
formatSignificant
(
18
)).
toEqual
(
'
-16.8751042187760547
'
)
...
@@ -152,7 +153,7 @@ describe('entities', () => {
...
@@ -152,7 +153,7 @@ describe('entities', () => {
).
toEqual
(
trade
.
inputAmount
.
toString
())
).
toEqual
(
trade
.
inputAmount
.
toString
())
expect
(
trade
.
nextMidPrice
.
formatSignificant
(
18
)).
toEqual
(
'
1.38958368072925352
'
)
expect
(
trade
.
nextMidPrice
.
formatSignificant
(
18
)).
toEqual
(
'
1.38958368072925352
'
)
expect
(
trade
.
nextMidPrice
.
invert
().
formatSignificant
(
18
)).
toEqual
(
'
0.71964
'
)
expect
(
trade
.
nextMidPrice
.
invert
().
formatSignificant
(
18
)).
toEqual
(
'
0.71964
0000000000000
'
)
expect
(
trade
.
slippage
.
formatSignificant
(
18
)).
toEqual
(
'
-16.8751042187760547
'
)
expect
(
trade
.
slippage
.
formatSignificant
(
18
)).
toEqual
(
'
-16.8751042187760547
'
)
...
@@ -175,7 +176,7 @@ describe('entities', () => {
...
@@ -175,7 +176,7 @@ describe('entities', () => {
const
trade
=
new
Trade
(
route
,
'
1
'
,
TradeType
.
EXACT_INPUT
)
const
trade
=
new
Trade
(
route
,
'
1
'
,
TradeType
.
EXACT_INPUT
)
expect
(
trade
.
slippage
.
formatSignificant
(
18
)).
toEqual
(
expect
(
trade
.
slippage
.
formatSignificant
(
18
)).
toEqual
(
tokens
[
1
].
decimals
===
9
?
'
-0.300000099400899902
'
:
'
-0.3000000000000001
'
tokens
[
1
].
decimals
===
9
?
'
-0.300000099400899902
'
:
'
-0.3000000000000001
00
'
)
)
}
}
})
})
...
...
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