Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Register
Sign in
Toggle navigation
Menu
Open sidebar
Tiger Ton
osmosis
Commits
d812334d
Unverified
Commit
d812334d
authored
2 years ago
by
alpo
Committed by
GitHub
2 years ago
Browse files
Options
Download
Email Patches
Plain Diff
remove all uses of two-asset binary search solver (#3084)
parent
4a67cddb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
x/gamm/pool-models/stableswap/amm.go
+0
-38
x/gamm/pool-models/stableswap/amm.go
x/gamm/pool-models/stableswap/amm_bench_test.go
+0
-6
x/gamm/pool-models/stableswap/amm_bench_test.go
x/gamm/pool-models/stableswap/amm_test.go
+0
-22
x/gamm/pool-models/stableswap/amm_test.go
with
0 additions
and
66 deletions
+0
-66
x/gamm/pool-models/stableswap/amm.go
+
0
-
38
View file @
d812334d
...
...
@@ -64,9 +64,6 @@ func cfmmConstantMulti(xReserve, yReserve, u, v osmomath.BigDec) osmomath.BigDec
// and the following expression for `a` in multi-asset pools:
// xyz(x^2 + y^2 + w) = (x - a)(y + b)z((x - a)^2 + (y + b)^2 + w)
func
solveCfmm
(
xReserve
,
yReserve
osmomath
.
BigDec
,
remReserves
[]
osmomath
.
BigDec
,
yIn
osmomath
.
BigDec
)
osmomath
.
BigDec
{
if
len
(
remReserves
)
==
0
{
return
solveCFMMBinarySearch
(
cfmmConstant
)(
xReserve
,
yReserve
,
yIn
)
}
wSumSquares
:=
osmomath
.
ZeroDec
()
for
_
,
assetReserve
:=
range
remReserves
{
wSumSquares
=
wSumSquares
.
Add
(
assetReserve
.
Mul
(
assetReserve
))
...
...
@@ -161,41 +158,6 @@ var (
k_threshold
=
osmomath
.
NewDecWithPrec
(
1
,
1
)
// Correct within a factor of 1 * 10^{-1}
)
// solveCFMMBinarySearch searches the correct dx using binary search over constant K.
// added for future extension
func
solveCFMMBinarySearch
(
constantFunction
func
(
osmomath
.
BigDec
,
osmomath
.
BigDec
)
osmomath
.
BigDec
)
func
(
osmomath
.
BigDec
,
osmomath
.
BigDec
,
osmomath
.
BigDec
)
osmomath
.
BigDec
{
return
func
(
xReserve
,
yReserve
,
yIn
osmomath
.
BigDec
)
osmomath
.
BigDec
{
if
!
xReserve
.
IsPositive
()
||
!
yReserve
.
IsPositive
()
{
panic
(
"invalid input: reserves and input must be positive"
)
}
else
if
yIn
.
Abs
()
.
GTE
(
yReserve
)
{
panic
(
"cannot input more than pool reserves"
)
}
k
:=
constantFunction
(
xReserve
,
yReserve
)
yFinal
:=
yReserve
.
Add
(
yIn
)
xLowEst
:=
osmomath
.
ZeroDec
()
// we set upper bound at 2 * xReserve to accommodate negative yIns
xHighEst
:=
xReserve
.
Mul
(
osmomath
.
NewBigDec
(
2
))
maxIterations
:=
256
errTolerance
:=
osmoutils
.
ErrTolerance
{
AdditiveTolerance
:
sdk
.
OneInt
(),
MultiplicativeTolerance
:
sdk
.
Dec
{}}
// create single-input CFMM to pass into binary search
calc_x_est
:=
func
(
xEst
osmomath
.
BigDec
)
(
osmomath
.
BigDec
,
error
)
{
return
constantFunction
(
xEst
,
yFinal
),
nil
}
x_est
,
err
:=
osmoutils
.
BinarySearchBigDec
(
calc_x_est
,
xLowEst
,
xHighEst
,
k
,
errTolerance
,
maxIterations
)
if
err
!=
nil
{
panic
(
err
)
}
xOut
:=
xReserve
.
Sub
(
x_est
)
if
xOut
.
GTE
(
xReserve
)
{
panic
(
"invalid output: greater than full pool reserves"
)
}
return
xOut
}
}
// solveCFMMBinarySearch searches the correct dx using binary search over constant K.
// added for future extension
func
solveCFMMBinarySearchMulti
(
xReserve
,
yReserve
,
wSumSquares
,
yIn
osmomath
.
BigDec
)
osmomath
.
BigDec
{
...
...
This diff is collapsed.
Click to expand it.
x/gamm/pool-models/stableswap/amm_bench_test.go
+
0
-
6
View file @
d812334d
...
...
@@ -14,12 +14,6 @@ func BenchmarkCFMM(b *testing.B) {
}
}
func
BenchmarkBinarySearchTwoAsset
(
b
*
testing
.
B
)
{
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
runCalcTwoAsset
(
solveCFMMBinarySearch
(
cfmmConstant
))
}
}
func
BenchmarkBinarySearchMultiAsset
(
b
*
testing
.
B
)
{
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
runCalcMultiAsset
(
solveCFMMBinarySearchMulti
)
...
...
This diff is collapsed.
Click to expand it.
x/gamm/pool-models/stableswap/amm_test.go
+
0
-
22
View file @
d812334d
...
...
@@ -406,28 +406,6 @@ func TestCFMMInvariantTwoAssets(t *testing.T) {
}
}
func
TestCFMMInvariantTwoAssetsBinarySearch
(
t
*
testing
.
T
)
{
kErrTolerance
:=
osmomath
.
OneDec
()
tests
:=
twoAssetCFMMTestCases
for
name
,
test
:=
range
tests
{
t
.
Run
(
name
,
func
(
t
*
testing
.
T
)
{
// system under test
sut
:=
func
()
{
// using two-asset binary search cfmm solver
k0
:=
cfmmConstant
(
test
.
xReserve
,
test
.
yReserve
)
xOut
:=
solveCFMMBinarySearch
(
cfmmConstant
)(
test
.
xReserve
,
test
.
yReserve
,
test
.
yIn
)
k1
:=
cfmmConstant
(
test
.
xReserve
.
Sub
(
xOut
),
test
.
yReserve
.
Add
(
test
.
yIn
))
osmomath
.
DecApproxEq
(
t
,
k0
,
k1
,
kErrTolerance
)
}
osmoassert
.
ConditionalPanic
(
t
,
test
.
expectPanic
,
sut
)
})
}
}
func
TestCFMMInvariantTwoAssetsDirect
(
t
*
testing
.
T
)
{
kErrTolerance
:=
osmomath
.
OneDec
()
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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