From f50052b95b8b1209bc8778a19647ed2d8cc3149a Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 16:47:47 +0900 Subject: [PATCH 01/27] Speedup quo round up --- osmomath/decimal.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/osmomath/decimal.go b/osmomath/decimal.go index cb6eb82bcdd..64c04d3ac25 100644 --- a/osmomath/decimal.go +++ b/osmomath/decimal.go @@ -502,11 +502,12 @@ func (d BigDec) QuoTruncateDecMut(d2 Dec) BigDec { // quotient, round up func (d BigDec) QuoRoundUp(d2 BigDec) BigDec { - // multiply precision twice - mul := new(big.Int).Mul(d.i, squaredPrecisionReuse) + mul := new(big.Int).Mul(d.i, defaultBigDecPrecisionReuse) - quo := mul.Quo(mul, d2.i) - chopped := chopPrecisionAndRoundUpMut(quo, defaultBigDecPrecisionReuse) + chopped, rem := mul.QuoRem(mul, d2.i, new(big.Int)) + if rem.Sign() > 0 { + chopped.Add(chopped, oneInt) + } if chopped.BitLen() > maxDecBitLen { panic("Int overflow") @@ -517,10 +518,12 @@ func (d BigDec) QuoRoundUp(d2 BigDec) BigDec { // quotient, round up (mutative) func (d BigDec) QuoRoundUpMut(d2 BigDec) BigDec { // multiply precision twice - d.i.Mul(d.i, squaredPrecisionReuse) - d.i.Quo(d.i, d2.i) + d.i.Mul(d.i, defaultBigDecPrecisionReuse) + _, rem := d.i.QuoRem(d.i, d2.i, new(big.Int)) - chopPrecisionAndRoundUpMut(d.i, defaultBigDecPrecisionReuse) + if rem.Sign() > 0 { + d.i.Add(d.i, oneInt) + } if d.i.BitLen() > maxDecBitLen { panic("Int overflow") From e34072860178c26ff76cdc0ceced66bd27ade137 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 17:14:21 +0900 Subject: [PATCH 02/27] Code reuse --- CHANGELOG.md | 2 +- osmomath/decimal.go | 97 +++++++++++++++------------------------------ 2 files changed, 32 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8ff0eb8aef..a6911b45971 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,7 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### State Compatible -* [#8006](https://github.com/osmosis-labs/osmosis/pull/8006) Speedup many BigDec operations +* [#8006](https://github.com/osmosis-labs/osmosis/pull/8006), [#8014](https://github.com/osmosis-labs/osmosis/pull/8014) Speedup many BigDec operations ## v24.0.1 diff --git a/osmomath/decimal.go b/osmomath/decimal.go index 64c04d3ac25..788a411ef56 100644 --- a/osmomath/decimal.go +++ b/osmomath/decimal.go @@ -294,9 +294,7 @@ func (d BigDec) Add(d2 BigDec) BigDec { func (d BigDec) AddMut(d2 BigDec) BigDec { d.i.Add(d.i, d2.i) - if d.i.BitLen() > maxDecBitLen { - panic("Int overflow") - } + assertMaxBitLen(d.i) return d } @@ -310,10 +308,7 @@ func (d BigDec) Sub(d2 BigDec) BigDec { func (d BigDec) SubMut(d2 BigDec) BigDec { res := d.i.Sub(d.i, d2.i) - - if res.BitLen() > maxDecBitLen { - panic("Int overflow") - } + assertMaxBitLen(res) return BigDec{res} } @@ -344,9 +339,7 @@ func (d BigDec) MulMut(d2 BigDec) BigDec { d.i.Mul(d.i, d2.i) d.i = chopPrecisionAndRound(d.i) - if d.i.BitLen() > maxDecBitLen { - panic("Int overflow") - } + assertMaxBitLen(d.i) return BigDec{d.i} } @@ -360,9 +353,7 @@ func (d BigDec) MulDecMut(d2 Dec) BigDec { d.i.Mul(d.i, d2.BigIntMut()) d.i = chopPrecisionAndRoundSdkDec(d.i) - if d.i.BitLen() > maxDecBitLen { - panic("Int overflow") - } + assertMaxBitLen(d.i) return BigDec{d.i} } @@ -370,20 +361,14 @@ func (d BigDec) MulDecMut(d2 Dec) BigDec { func (d BigDec) MulTruncate(d2 BigDec) BigDec { mul := new(big.Int).Mul(d.i, d2.i) chopped := chopPrecisionAndTruncateMut(mul, defaultBigDecPrecisionReuse) - - if chopped.BitLen() > maxDecBitLen { - panic("Int overflow") - } + assertMaxBitLen(chopped) return BigDec{chopped} } func (d BigDec) MulTruncateDec(d2 Dec) BigDec { mul := new(big.Int).Mul(d.i, d2.BigIntMut()) chopped := chopPrecisionAndTruncateMut(mul, precisionReuseSDKDec) - - if chopped.BitLen() > maxDecBitLen { - panic("Int overflow") - } + assertMaxBitLen(chopped) return BigDec{chopped} } @@ -391,20 +376,14 @@ func (d BigDec) MulTruncateDec(d2 Dec) BigDec { func (d BigDec) MulRoundUp(d2 BigDec) BigDec { mul := new(big.Int).Mul(d.i, d2.i) chopped := chopPrecisionAndRoundUpMut(mul, defaultBigDecPrecisionReuse) - - if chopped.BitLen() > maxDecBitLen { - panic("Int overflow") - } + assertMaxBitLen(chopped) return BigDec{chopped} } // multiplication func (d BigDec) MulInt(i BigInt) BigDec { mul := new(big.Int).Mul(d.i, i.i) - - if mul.BitLen() > maxDecBitLen { - panic("Int overflow") - } + assertMaxBitLen(mul) return BigDec{mul} } @@ -412,10 +391,7 @@ func (d BigDec) MulInt(i BigInt) BigDec { func (d BigDec) MulInt64(i int64) BigDec { bi := big.NewInt(i) mul := bi.Mul(d.i, bi) - - if mul.BitLen() > maxDecBitLen { - panic("Int overflow") - } + assertMaxBitLen(mul) return BigDec{mul} } @@ -434,9 +410,7 @@ func (d BigDec) QuoMut(d2 BigDec) BigDec { d.i.Quo(d.i, d2.i) chopPrecisionAndRound(d.i) - if d.i.BitLen() > maxDecBitLen { - panic("Int overflow") - } + assertMaxBitLen(d.i) return d } func (d BigDec) QuoRaw(d2 int64) BigDec { @@ -445,10 +419,7 @@ func (d BigDec) QuoRaw(d2 int64) BigDec { quo := mul.Quo(mul, big.NewInt(d2)) chopped := chopPrecisionAndRound(quo) - - if chopped.BitLen() > maxDecBitLen { - panic("Int overflow") - } + assertMaxBitLen(chopped) return BigDec{chopped} } @@ -457,10 +428,7 @@ func (d BigDec) QuoTruncate(d2 BigDec) BigDec { // multiply precision twice mul := new(big.Int).Mul(d.i, defaultBigDecPrecisionReuse) quo := mul.Quo(mul, d2.i) - - if quo.BitLen() > maxDecBitLen { - panic("Int overflow") - } + assertMaxBitLen(quo) return BigDec{quo} } @@ -470,9 +438,7 @@ func (d BigDec) QuoTruncateMut(d2 BigDec) BigDec { d.i.Mul(d.i, defaultBigDecPrecisionReuse) d.i.Quo(d.i, d2.i) - if d.i.BitLen() > maxDecBitLen { - panic("Int overflow") - } + assertMaxBitLen(d.i) return d } @@ -481,10 +447,7 @@ func (d BigDec) QuoTruncateDec(d2 Dec) BigDec { // multiply Dec Precision mul := new(big.Int).Mul(d.i, precisionReuseSDKDec) quo := mul.Quo(mul, d2.BigIntMut()) - - if quo.BitLen() > maxDecBitLen { - panic("Int overflow") - } + assertMaxBitLen(quo) return BigDec{quo} } @@ -494,9 +457,7 @@ func (d BigDec) QuoTruncateDecMut(d2 Dec) BigDec { d.i.Mul(d.i, precisionReuseSDKDec) d.i.Quo(d.i, d2.BigIntMut()) - if d.i.BitLen() > maxDecBitLen { - panic("Int overflow") - } + assertMaxBitLen(d.i) return d } @@ -509,9 +470,7 @@ func (d BigDec) QuoRoundUp(d2 BigDec) BigDec { chopped.Add(chopped, oneInt) } - if chopped.BitLen() > maxDecBitLen { - panic("Int overflow") - } + assertMaxBitLen(chopped) return BigDec{chopped} } @@ -525,9 +484,7 @@ func (d BigDec) QuoRoundUpMut(d2 BigDec) BigDec { d.i.Add(d.i, oneInt) } - if d.i.BitLen() > maxDecBitLen { - panic("Int overflow") - } + assertMaxBitLen(d.i) return BigDec{d.i} } @@ -591,6 +548,12 @@ func (d BigDec) ApproxRoot(root uint64) (guess BigDec, err error) { return guess, nil } +func assertMaxBitLen(i *big.Int) { + if i.BitLen() > maxDecBitLen { + panic("Int overflow") + } +} + // ApproxSqrt is a wrapper around ApproxRoot for the common special case // of finding the square root of a number. It returns -(sqrt(abs(d)) if input is negative. // TODO: Optimize this to be faster just using native big int sqrt. @@ -866,6 +829,13 @@ func chopPrecisionAndRoundUpDec(d *big.Int) *big.Int { return chopPrecisionAndRoundUpMut(copy, precisionReuseSDKDec) } +func incBasedOnRem(rem *big.Int, d *big.Int) *big.Int { + if rem.Sign() == 0 { + return d + } + return d.Add(d, oneInt) +} + // chopPrecisionAndRoundUp removes a Precision amount of rightmost digits and rounds up. // Mutates input d. // Mutations occur: @@ -884,12 +854,7 @@ func chopPrecisionAndRoundUpMut(d *big.Int, precisionReuse *big.Int) *big.Int { // get the truncated quotient and remainder _, rem := d.QuoRem(d, precisionReuse, big.NewInt(0)) - - if rem.Sign() == 0 { // remainder is zero - return d - } - - return d.Add(d, oneInt) + return incBasedOnRem(rem, d) } func chopPrecisionAndRoundNonMutative(d *big.Int) *big.Int { From 4ff1858769bedab997aac9af55f2da05bbb429a0 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 17:15:48 +0900 Subject: [PATCH 03/27] Missed a code re-use point --- osmomath/decimal.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/osmomath/decimal.go b/osmomath/decimal.go index 788a411ef56..f51a21a7393 100644 --- a/osmomath/decimal.go +++ b/osmomath/decimal.go @@ -480,10 +480,7 @@ func (d BigDec) QuoRoundUpMut(d2 BigDec) BigDec { d.i.Mul(d.i, defaultBigDecPrecisionReuse) _, rem := d.i.QuoRem(d.i, d2.i, new(big.Int)) - if rem.Sign() > 0 { - d.i.Add(d.i, oneInt) - } - + d.i = incBasedOnRem(rem, d.i) assertMaxBitLen(d.i) return BigDec{d.i} } From 5fbf7ee099695126d8cb159ceb4479ce06ee5b46 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 17:37:51 +0900 Subject: [PATCH 04/27] Add future notes --- osmomath/decimal.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osmomath/decimal.go b/osmomath/decimal.go index f51a21a7393..26d0a563d0f 100644 --- a/osmomath/decimal.go +++ b/osmomath/decimal.go @@ -44,12 +44,14 @@ var ( squaredPrecisionReuse = new(big.Int).Mul(defaultBigDecPrecisionReuse, defaultBigDecPrecisionReuse) bigDecDecPrecisionFactorDiff = new(big.Int).Exp(big.NewInt(10), big.NewInt(BigDecPrecision-DecPrecision), nil) + tenTimesPrecision = new(big.Int).Exp(big.NewInt(10), big.NewInt(BigDecPrecision+1), nil) fivePrecision = new(big.Int).Quo(defaultBigDecPrecisionReuse, big.NewInt(2)) fivePrecisionSDKDec = new(big.Int).Quo(precisionReuseSDKDec, big.NewInt(2)) precisionMultipliers []*big.Int zeroInt = big.NewInt(0) oneInt = big.NewInt(1) + fiveInt = big.NewInt(5) tenInt = big.NewInt(10) // log_2(e) @@ -405,6 +407,7 @@ func (d BigDec) Quo(d2 BigDec) BigDec { // mutative quotient func (d BigDec) QuoMut(d2 BigDec) BigDec { // multiply precision twice + // TODO: Use lower overhead thing here d.i.Mul(d.i, squaredPrecisionReuse) d.i.Quo(d.i, d2.i) @@ -415,6 +418,7 @@ func (d BigDec) QuoMut(d2 BigDec) BigDec { } func (d BigDec) QuoRaw(d2 int64) BigDec { // multiply precision, so we can chop it later + // TODO: There is certainly more efficient ways to do this, come back later mul := new(big.Int).Mul(d.i, defaultBigDecPrecisionReuse) quo := mul.Quo(mul, big.NewInt(d2)) @@ -476,7 +480,6 @@ func (d BigDec) QuoRoundUp(d2 BigDec) BigDec { // quotient, round up (mutative) func (d BigDec) QuoRoundUpMut(d2 BigDec) BigDec { - // multiply precision twice d.i.Mul(d.i, defaultBigDecPrecisionReuse) _, rem := d.i.QuoRem(d.i, d2.i, new(big.Int)) From 590a939240de1a5bb44692abff28ad8278ebcb2c Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 17:44:26 +0900 Subject: [PATCH 05/27] Comment cleanup --- osmomath/decimal.go | 1 - 1 file changed, 1 deletion(-) diff --git a/osmomath/decimal.go b/osmomath/decimal.go index 26d0a563d0f..ec02faed4c1 100644 --- a/osmomath/decimal.go +++ b/osmomath/decimal.go @@ -429,7 +429,6 @@ func (d BigDec) QuoRaw(d2 int64) BigDec { // quotient truncate func (d BigDec) QuoTruncate(d2 BigDec) BigDec { - // multiply precision twice mul := new(big.Int).Mul(d.i, defaultBigDecPrecisionReuse) quo := mul.Quo(mul, d2.i) assertMaxBitLen(quo) From cacbcfec78d1cd678b4dd36498667ea20b36ffd3 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Apr 2024 08:50:00 +0000 Subject: [PATCH 06/27] Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- osmomath/go.mod | 2 +- osmomath/go.sum | 4 ++-- osmoutils/go.mod | 6 +++--- osmoutils/go.sum | 12 ++++++------ x/epochs/go.mod | 4 ++-- x/epochs/go.sum | 8 ++++---- x/ibc-hooks/go.mod | 4 ++-- x/ibc-hooks/go.sum | 8 ++++---- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index c3beb1348a9..32400018b8c 100644 --- a/go.mod +++ b/go.mod @@ -30,10 +30,10 @@ require ( github.com/mattn/go-sqlite3 v1.14.17 github.com/ory/dockertest/v3 v3.10.0 github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240410095049-0ddea0b91fb3 - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240410095049-0ddea0b91fb3 - github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240410095049-0ddea0b91fb3 - github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240410095049-0ddea0b91fb3 + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de + github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411084426-590a939240de + github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411084426-590a939240de github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 github.com/pkg/errors v0.9.1 github.com/rakyll/statik v0.1.7 diff --git a/go.sum b/go.sum index a118a8629d6..4f1c8b6ef08 100644 --- a/go.sum +++ b/go.sum @@ -1517,14 +1517,14 @@ github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0c github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:YlmchqTmlwdWSmrRmXKR+PcU96ntOd8u10vTaTZdcNY= github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3/go.mod h1:lV6KnqXYD/ayTe7310MHtM3I2q8Z6bBfMAi+bhwPYtI= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240410095049-0ddea0b91fb3 h1:2FRCIC8gXSACn9SMmZivBXYdND/O/xrYK9rRzdY/fSY= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240410095049-0ddea0b91fb3/go.mod h1:I1Nw0VK1JOaZH5f0AFl4iFB2Qp2ckbH9a3Z4UZLpDbs= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240410095049-0ddea0b91fb3 h1:dJFXQbBbMZ9UDtIMseoGlBg4fe5rSui7x3x9baAGw9w= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240410095049-0ddea0b91fb3/go.mod h1:fo3rKZIybC/tRMX09a0W/1UBl9meK1+T4PmWs1wErHI= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240410095049-0ddea0b91fb3 h1:UGxPvBFipIM8q3SJUYRjSP0+D/3Y8BkZGLvO+ov/fYs= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240410095049-0ddea0b91fb3/go.mod h1:N2+CB3wWEN/HmtWNK9DjAN1WGLgqeRiGjs+ZhK3RXdQ= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240410095049-0ddea0b91fb3 h1:QHtWt4M49bYH64Vy0DetURTtLGUIGWTpLOBIH9q/bhQ= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240410095049-0ddea0b91fb3/go.mod h1:C4/AaeluMrYxFehK61WGXVG7DvofFUyit7Xb0QKyQPA= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de h1:BmR5g0KhFaIW2XheFb2sjWdklPlxi2Z+CRSjf/VDxmM= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de/go.mod h1:EH4baEX2mKDDDgcXQEk5gLQ+ECdDIr89Gtib5a+b3B4= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de h1:SPkrgdKuSqcgLb69n/nB9ET1HBkJKryezfBCCs2y55U= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de/go.mod h1:n4M42bFg0gv2DYTTkQKkMbK1yoQgf4b2tXKbDQaYgDA= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411084426-590a939240de h1:17qcDGmHmZppIq6Eg6UVapGhEciJIFYnqanYjy6es4w= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411084426-590a939240de/go.mod h1:87lVvPi4rmay0Dg5sOy/zVpCFqVfWXA9imScZxpqLYk= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411084426-590a939240de h1:y6NbCB3jQH4EOHOmmYUmFBm36u25l9bckDKT6C3qhdw= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411084426-590a939240de/go.mod h1:DjJDDKxBPqLWPKKecDXBnM1kN4hi5XiLB7yAQqRpSRQ= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 h1:mvkk1A/jIe+lsFFpRNfyd9UfvhagATdpnjy8K7kANeo= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04/go.mod h1:mYYf7pYb7sGJ9zYIOw2aYlIl5cgKT0K93rZx4LvDAuA= github.com/osmosis-labs/wasmd v0.45.0-osmo h1:NIp7pvJV5HuBN1HwPgEmXKQM2TjVIVdJErIHnB9IMO8= diff --git a/osmomath/go.mod b/osmomath/go.mod index 66f19755b04..bd276bf5a91 100644 --- a/osmomath/go.mod +++ b/osmomath/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( cosmossdk.io/math v1.3.0 github.com/cosmos/cosmos-sdk v0.47.8 - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240410095049-0ddea0b91fb3 + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de github.com/stretchr/testify v1.9.0 gopkg.in/yaml.v2 v2.4.0 diff --git a/osmomath/go.sum b/osmomath/go.sum index 68a8ecb58aa..1144ef5d5f3 100644 --- a/osmomath/go.sum +++ b/osmomath/go.sum @@ -263,8 +263,8 @@ github.com/onsi/gomega v1.28.1 h1:MijcGUbfYuznzK/5R4CPNoUP/9Xvuo20sXfEm6XxoTA= github.com/onsi/gomega v1.28.1/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240410095049-0ddea0b91fb3 h1:dJFXQbBbMZ9UDtIMseoGlBg4fe5rSui7x3x9baAGw9w= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240410095049-0ddea0b91fb3/go.mod h1:fo3rKZIybC/tRMX09a0W/1UBl9meK1+T4PmWs1wErHI= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de h1:SPkrgdKuSqcgLb69n/nB9ET1HBkJKryezfBCCs2y55U= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de/go.mod h1:n4M42bFg0gv2DYTTkQKkMbK1yoQgf4b2tXKbDQaYgDA= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= diff --git a/osmoutils/go.mod b/osmoutils/go.mod index 01270a88eca..2992f0dbff2 100644 --- a/osmoutils/go.mod +++ b/osmoutils/go.mod @@ -13,7 +13,7 @@ require ( github.com/cosmos/gogoproto v1.4.11 github.com/cosmos/iavl v1.1.2-0.20240405173644-e52f7630d3b7 github.com/cosmos/ibc-go/v7 v7.4.0 - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240410095049-0ddea0b91fb3 + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de github.com/osmosis-labs/osmosis/v24 v24.0.0-rc0 github.com/spf13/cast v1.6.0 github.com/spf13/cobra v1.8.0 @@ -155,8 +155,8 @@ require ( github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae // indirect github.com/onsi/gomega v1.28.1 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect - github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240410095049-0ddea0b91fb3 // indirect - github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240410095049-0ddea0b91fb3 // indirect + github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411084426-590a939240de // indirect + github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411084426-590a939240de // indirect github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect diff --git a/osmoutils/go.sum b/osmoutils/go.sum index 17baedcec64..ebd90a26391 100644 --- a/osmoutils/go.sum +++ b/osmoutils/go.sum @@ -1283,14 +1283,14 @@ github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2 h1:3k4I3zCxdNP+mjhR7AtKr1PPu github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2/go.mod h1:fE+yBeExsJHA35plOZ7FmC/JejO5UdEHNcwO3dj2wc8= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240410095049-0ddea0b91fb3 h1:2FRCIC8gXSACn9SMmZivBXYdND/O/xrYK9rRzdY/fSY= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240410095049-0ddea0b91fb3/go.mod h1:I1Nw0VK1JOaZH5f0AFl4iFB2Qp2ckbH9a3Z4UZLpDbs= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de h1:BmR5g0KhFaIW2XheFb2sjWdklPlxi2Z+CRSjf/VDxmM= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de/go.mod h1:EH4baEX2mKDDDgcXQEk5gLQ+ECdDIr89Gtib5a+b3B4= github.com/osmosis-labs/osmosis/v24 v24.0.0-rc0 h1:wAcm5rvcAMwSPFWgzUr/lR7U+e+4PvZ8fkehhpwiJho= github.com/osmosis-labs/osmosis/v24 v24.0.0-rc0/go.mod h1:5QdPU/ttG3dPeg1EtX/LVT7yuxdz3E+BXnEqxwgh+ec= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240410095049-0ddea0b91fb3 h1:UGxPvBFipIM8q3SJUYRjSP0+D/3Y8BkZGLvO+ov/fYs= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240410095049-0ddea0b91fb3/go.mod h1:N2+CB3wWEN/HmtWNK9DjAN1WGLgqeRiGjs+ZhK3RXdQ= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240410095049-0ddea0b91fb3 h1:QHtWt4M49bYH64Vy0DetURTtLGUIGWTpLOBIH9q/bhQ= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240410095049-0ddea0b91fb3/go.mod h1:C4/AaeluMrYxFehK61WGXVG7DvofFUyit7Xb0QKyQPA= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411084426-590a939240de h1:17qcDGmHmZppIq6Eg6UVapGhEciJIFYnqanYjy6es4w= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411084426-590a939240de/go.mod h1:87lVvPi4rmay0Dg5sOy/zVpCFqVfWXA9imScZxpqLYk= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411084426-590a939240de h1:y6NbCB3jQH4EOHOmmYUmFBm36u25l9bckDKT6C3qhdw= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411084426-590a939240de/go.mod h1:DjJDDKxBPqLWPKKecDXBnM1kN4hi5XiLB7yAQqRpSRQ= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 h1:mvkk1A/jIe+lsFFpRNfyd9UfvhagATdpnjy8K7kANeo= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04/go.mod h1:mYYf7pYb7sGJ9zYIOw2aYlIl5cgKT0K93rZx4LvDAuA= github.com/osmosis-labs/wasmd v0.45.0-osmo h1:NIp7pvJV5HuBN1HwPgEmXKQM2TjVIVdJErIHnB9IMO8= diff --git a/x/epochs/go.mod b/x/epochs/go.mod index a04515c8527..a3d96124c0b 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -9,7 +9,7 @@ require ( github.com/cosmos/gogoproto v1.4.11 github.com/golang/protobuf v1.5.4 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240410095049-0ddea0b91fb3 + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de github.com/spf13/cobra v1.8.0 github.com/stretchr/testify v1.9.0 golang.org/x/exp v0.0.0-20230905200255-921286631fa9 @@ -111,7 +111,7 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mtibben/percent v0.2.1 // indirect github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae // indirect - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240410095049-0ddea0b91fb3 // indirect + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect github.com/pkg/errors v0.9.1 // indirect diff --git a/x/epochs/go.sum b/x/epochs/go.sum index 2b5519021b7..b259b4b58b7 100644 --- a/x/epochs/go.sum +++ b/x/epochs/go.sum @@ -1224,10 +1224,10 @@ github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2 h1:3k4I3zCxdNP+mjhR7AtKr1PPu github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2/go.mod h1:fE+yBeExsJHA35plOZ7FmC/JejO5UdEHNcwO3dj2wc8= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240410095049-0ddea0b91fb3 h1:2FRCIC8gXSACn9SMmZivBXYdND/O/xrYK9rRzdY/fSY= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240410095049-0ddea0b91fb3/go.mod h1:I1Nw0VK1JOaZH5f0AFl4iFB2Qp2ckbH9a3Z4UZLpDbs= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240410095049-0ddea0b91fb3 h1:dJFXQbBbMZ9UDtIMseoGlBg4fe5rSui7x3x9baAGw9w= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240410095049-0ddea0b91fb3/go.mod h1:fo3rKZIybC/tRMX09a0W/1UBl9meK1+T4PmWs1wErHI= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de h1:BmR5g0KhFaIW2XheFb2sjWdklPlxi2Z+CRSjf/VDxmM= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de/go.mod h1:EH4baEX2mKDDDgcXQEk5gLQ+ECdDIr89Gtib5a+b3B4= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de h1:SPkrgdKuSqcgLb69n/nB9ET1HBkJKryezfBCCs2y55U= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de/go.mod h1:n4M42bFg0gv2DYTTkQKkMbK1yoQgf4b2tXKbDQaYgDA= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= diff --git a/x/ibc-hooks/go.mod b/x/ibc-hooks/go.mod index e9e59f8b99f..f57f7e4667d 100644 --- a/x/ibc-hooks/go.mod +++ b/x/ibc-hooks/go.mod @@ -11,8 +11,8 @@ require ( github.com/cosmos/gogoproto v1.4.11 github.com/cosmos/ibc-go/v7 v7.4.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240410095049-0ddea0b91fb3 - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240410095049-0ddea0b91fb3 + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de github.com/spf13/cobra v1.8.0 google.golang.org/grpc v1.62.1 google.golang.org/protobuf v1.33.0 diff --git a/x/ibc-hooks/go.sum b/x/ibc-hooks/go.sum index c76ba5f3f36..712b484efbe 100644 --- a/x/ibc-hooks/go.sum +++ b/x/ibc-hooks/go.sum @@ -1239,10 +1239,10 @@ github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2 h1:3k4I3zCxdNP+mjhR7AtKr1PPu github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2/go.mod h1:fE+yBeExsJHA35plOZ7FmC/JejO5UdEHNcwO3dj2wc8= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240410095049-0ddea0b91fb3 h1:2FRCIC8gXSACn9SMmZivBXYdND/O/xrYK9rRzdY/fSY= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240410095049-0ddea0b91fb3/go.mod h1:I1Nw0VK1JOaZH5f0AFl4iFB2Qp2ckbH9a3Z4UZLpDbs= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240410095049-0ddea0b91fb3 h1:dJFXQbBbMZ9UDtIMseoGlBg4fe5rSui7x3x9baAGw9w= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240410095049-0ddea0b91fb3/go.mod h1:fo3rKZIybC/tRMX09a0W/1UBl9meK1+T4PmWs1wErHI= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de h1:BmR5g0KhFaIW2XheFb2sjWdklPlxi2Z+CRSjf/VDxmM= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de/go.mod h1:EH4baEX2mKDDDgcXQEk5gLQ+ECdDIr89Gtib5a+b3B4= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de h1:SPkrgdKuSqcgLb69n/nB9ET1HBkJKryezfBCCs2y55U= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de/go.mod h1:n4M42bFg0gv2DYTTkQKkMbK1yoQgf4b2tXKbDQaYgDA= github.com/osmosis-labs/wasmd v0.45.0-osmo h1:NIp7pvJV5HuBN1HwPgEmXKQM2TjVIVdJErIHnB9IMO8= github.com/osmosis-labs/wasmd v0.45.0-osmo/go.mod h1:J6eRvwii5T1WxhetZkBg1kOJS3GTn1Bw2OLyZBb8EVU= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= From 8b87e7b9bcac2b2b61c388ddd28331d6bea85f02 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 18:09:19 +0900 Subject: [PATCH 07/27] Add new fn: NewBigDecFromDecMulDec --- osmomath/decimal.go | 5 ++ osmomath/decimal_test.go | 47 +++++++++++++++++++ .../swapstrategy/one_for_zero.go | 2 +- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/osmomath/decimal.go b/osmomath/decimal.go index ec02faed4c1..52498d103af 100644 --- a/osmomath/decimal.go +++ b/osmomath/decimal.go @@ -174,6 +174,11 @@ func NewBigDecFromIntWithPrec(i BigInt, prec int64) BigDec { } } +func NewBigDecFromDecMulDec(a, b Dec) BigDec { + newBi := new(big.Int).Mul(a.BigIntMut(), b.BigIntMut()) + return BigDec{newBi} +} + // create a decimal from an input decimal string. // valid must come in the form: // diff --git a/osmomath/decimal_test.go b/osmomath/decimal_test.go index 9d927a7a408..34349434a44 100644 --- a/osmomath/decimal_test.go +++ b/osmomath/decimal_test.go @@ -178,6 +178,53 @@ func (s *decimalTestSuite) TestNewDecFromStr() { } } +var interestingDecNumbers = []string{ + "123456789012345678901234567890123456.123456789012345678", + "111111111111111111111111111111111111.111111111111111111", + "999999999999999999999999999999999999.999999999999999999", + "314159265358979323846264338327950288.419716939937510582", // Approximation of Pi + "161803398874989484820458683436563811.772030917980576286", // Approximation of Phi + "271828182845904523536028747135266249.775724709369995957", // Approximation of e + "101010101010101010101010101010101010.101010101010101010", // Binary pattern + "123456789987654321123456789987654321.123456789987654321", // Ascending and descending pattern + "112358132134558914423337761098715972.584418167651094617", // Inspired by Fibonacci sequence + "142857142857142857142857142857142857.142857142857142857", // Repeating decimal for 1/7 +} + +var interestingDecNumbersDec = []osmomath.Dec{} + +func init() { + for _, str := range interestingDecNumbers { + d, err := osmomath.NewDecFromStr(str) + if err != nil { + panic(fmt.Sprintf("error parsing decimal string %v: %v", str, err)) + } + interestingDecNumbersDec = append(interestingDecNumbersDec, d) + } +} + +func (s *decimalTestSuite) TestNewBigDecFromDecMulDec() { + type testcase struct { + s1, s2 osmomath.Dec + } + tests := []testcase{} + for _, d1 := range interestingDecNumbersDec { + for _, d2 := range interestingDecNumbersDec { + tests = append(tests, testcase{d1, d2}) + } + } + for _, tc := range tests { + s.Run(fmt.Sprintf("d1=%v, d2=%v", tc.s1, tc.s2), func() { + s1D := osmomath.BigDecFromDec(tc.s1) + s2D := osmomath.BigDecFromDec(tc.s2) + expected := s1D.MulMut(s2D) + actual := osmomath.NewBigDecFromDecMulDec(tc.s1, tc.s2) + s.Require().True(expected.Equal(actual), "expected %v, got %v", expected, actual) + }) + } + s.Require().True(len(tests) > 20) +} + func (s *decimalTestSuite) TestDecString() { tests := []struct { d osmomath.BigDec diff --git a/x/concentrated-liquidity/swapstrategy/one_for_zero.go b/x/concentrated-liquidity/swapstrategy/one_for_zero.go index 53bebd04df6..1f01654c803 100644 --- a/x/concentrated-liquidity/swapstrategy/one_for_zero.go +++ b/x/concentrated-liquidity/swapstrategy/one_for_zero.go @@ -62,13 +62,13 @@ func (s oneForZeroStrategy) GetSqrtTargetPrice(nextTickSqrtPrice osmomath.BigDec func (s oneForZeroStrategy) ComputeSwapWithinBucketOutGivenIn(sqrtPriceCurrent, sqrtPriceTarget osmomath.BigDec, liquidity, amountOneInRemaining osmomath.Dec) (osmomath.BigDec, osmomath.Dec, osmomath.Dec, osmomath.Dec) { // TODO: Change to Dec liquidityBigDec := osmomath.BigDecFromDec(liquidity) + // TODO: Undo this cast, and do NewBigDecFromDecMulDec in line 72 amountOneInRemainingBigDec := osmomath.BigDecFromDec(amountOneInRemaining) // Estimate the amount of token one needed until the target sqrt price is reached. amountOneIn := math.CalcAmount1Delta(liquidityBigDec, sqrtPriceTarget, sqrtPriceCurrent, true) // Calculate sqrtPriceNext on the amount of token remaining after spread reward. - // TODO: Use MulTruncateDec amountOneInRemainingLessSpreadReward := amountOneInRemainingBigDec.MulTruncate(oneBigDec.Sub(osmomath.BigDecFromDec(s.spreadFactor))) var sqrtPriceNext osmomath.BigDec From 87a067fe18f04e5613bb91ca0dca631c62f474ac Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Apr 2024 09:15:03 +0000 Subject: [PATCH 08/27] Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- osmomath/go.mod | 2 +- osmomath/go.sum | 4 ++-- osmoutils/go.mod | 6 +++--- osmoutils/go.sum | 12 ++++++------ x/epochs/go.mod | 4 ++-- x/epochs/go.sum | 8 ++++---- x/ibc-hooks/go.mod | 4 ++-- x/ibc-hooks/go.sum | 8 ++++---- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index 32400018b8c..0757203ace2 100644 --- a/go.mod +++ b/go.mod @@ -30,10 +30,10 @@ require ( github.com/mattn/go-sqlite3 v1.14.17 github.com/ory/dockertest/v3 v3.10.0 github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de - github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411084426-590a939240de - github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411084426-590a939240de + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b + github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411090936-c4c24f07055b + github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411090936-c4c24f07055b github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 github.com/pkg/errors v0.9.1 github.com/rakyll/statik v0.1.7 diff --git a/go.sum b/go.sum index 4f1c8b6ef08..b817e277ea8 100644 --- a/go.sum +++ b/go.sum @@ -1517,14 +1517,14 @@ github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0c github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:YlmchqTmlwdWSmrRmXKR+PcU96ntOd8u10vTaTZdcNY= github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3/go.mod h1:lV6KnqXYD/ayTe7310MHtM3I2q8Z6bBfMAi+bhwPYtI= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de h1:BmR5g0KhFaIW2XheFb2sjWdklPlxi2Z+CRSjf/VDxmM= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de/go.mod h1:EH4baEX2mKDDDgcXQEk5gLQ+ECdDIr89Gtib5a+b3B4= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de h1:SPkrgdKuSqcgLb69n/nB9ET1HBkJKryezfBCCs2y55U= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de/go.mod h1:n4M42bFg0gv2DYTTkQKkMbK1yoQgf4b2tXKbDQaYgDA= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411084426-590a939240de h1:17qcDGmHmZppIq6Eg6UVapGhEciJIFYnqanYjy6es4w= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411084426-590a939240de/go.mod h1:87lVvPi4rmay0Dg5sOy/zVpCFqVfWXA9imScZxpqLYk= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411084426-590a939240de h1:y6NbCB3jQH4EOHOmmYUmFBm36u25l9bckDKT6C3qhdw= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411084426-590a939240de/go.mod h1:DjJDDKxBPqLWPKKecDXBnM1kN4hi5XiLB7yAQqRpSRQ= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b h1:xoqEpefWRr/5REEbrtBIswKMgrbOMVszAVO91qPBDE0= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b/go.mod h1:QgluPESktAZYPQHPwLU7woP0+VeUNCfZpjwoQJnqJr4= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b h1:+zYuf/AGc9R9h3RiWQfgxnuEBtzLmnz0kdgw7K+JWAA= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b/go.mod h1:QqH0gW3eEHooG/xCD0JFNgBpLPURn/JKn1+AC6Dicso= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411090936-c4c24f07055b h1:HoDVffelEvLknLRIRKvljGko+bH0nHEanMAymJ6aVlc= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411090936-c4c24f07055b/go.mod h1:5dRIQromRQsNafy0N4FC8NNCwRdKcc9pU2j8Pw7bP/Q= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411090936-c4c24f07055b h1:pyvSeAadOf7hrBHs0yimVqQiRhIIycfazp+3WdG3S14= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411090936-c4c24f07055b/go.mod h1:Yy0I5hWPtCgL9BR7yeRieio8cLfxkXGNzENhtj/8FU0= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 h1:mvkk1A/jIe+lsFFpRNfyd9UfvhagATdpnjy8K7kANeo= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04/go.mod h1:mYYf7pYb7sGJ9zYIOw2aYlIl5cgKT0K93rZx4LvDAuA= github.com/osmosis-labs/wasmd v0.45.0-osmo h1:NIp7pvJV5HuBN1HwPgEmXKQM2TjVIVdJErIHnB9IMO8= diff --git a/osmomath/go.mod b/osmomath/go.mod index bd276bf5a91..603044d195f 100644 --- a/osmomath/go.mod +++ b/osmomath/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( cosmossdk.io/math v1.3.0 github.com/cosmos/cosmos-sdk v0.47.8 - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b github.com/stretchr/testify v1.9.0 gopkg.in/yaml.v2 v2.4.0 diff --git a/osmomath/go.sum b/osmomath/go.sum index 1144ef5d5f3..233789a8e9f 100644 --- a/osmomath/go.sum +++ b/osmomath/go.sum @@ -263,8 +263,8 @@ github.com/onsi/gomega v1.28.1 h1:MijcGUbfYuznzK/5R4CPNoUP/9Xvuo20sXfEm6XxoTA= github.com/onsi/gomega v1.28.1/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de h1:SPkrgdKuSqcgLb69n/nB9ET1HBkJKryezfBCCs2y55U= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de/go.mod h1:n4M42bFg0gv2DYTTkQKkMbK1yoQgf4b2tXKbDQaYgDA= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b h1:+zYuf/AGc9R9h3RiWQfgxnuEBtzLmnz0kdgw7K+JWAA= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b/go.mod h1:QqH0gW3eEHooG/xCD0JFNgBpLPURn/JKn1+AC6Dicso= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= diff --git a/osmoutils/go.mod b/osmoutils/go.mod index 2992f0dbff2..04bf7cfa8e6 100644 --- a/osmoutils/go.mod +++ b/osmoutils/go.mod @@ -13,7 +13,7 @@ require ( github.com/cosmos/gogoproto v1.4.11 github.com/cosmos/iavl v1.1.2-0.20240405173644-e52f7630d3b7 github.com/cosmos/ibc-go/v7 v7.4.0 - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b github.com/osmosis-labs/osmosis/v24 v24.0.0-rc0 github.com/spf13/cast v1.6.0 github.com/spf13/cobra v1.8.0 @@ -155,8 +155,8 @@ require ( github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae // indirect github.com/onsi/gomega v1.28.1 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect - github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411084426-590a939240de // indirect - github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411084426-590a939240de // indirect + github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411090936-c4c24f07055b // indirect + github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411090936-c4c24f07055b // indirect github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect diff --git a/osmoutils/go.sum b/osmoutils/go.sum index ebd90a26391..40c7e2ccf1a 100644 --- a/osmoutils/go.sum +++ b/osmoutils/go.sum @@ -1283,14 +1283,14 @@ github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2 h1:3k4I3zCxdNP+mjhR7AtKr1PPu github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2/go.mod h1:fE+yBeExsJHA35plOZ7FmC/JejO5UdEHNcwO3dj2wc8= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de h1:BmR5g0KhFaIW2XheFb2sjWdklPlxi2Z+CRSjf/VDxmM= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de/go.mod h1:EH4baEX2mKDDDgcXQEk5gLQ+ECdDIr89Gtib5a+b3B4= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b h1:xoqEpefWRr/5REEbrtBIswKMgrbOMVszAVO91qPBDE0= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b/go.mod h1:QgluPESktAZYPQHPwLU7woP0+VeUNCfZpjwoQJnqJr4= github.com/osmosis-labs/osmosis/v24 v24.0.0-rc0 h1:wAcm5rvcAMwSPFWgzUr/lR7U+e+4PvZ8fkehhpwiJho= github.com/osmosis-labs/osmosis/v24 v24.0.0-rc0/go.mod h1:5QdPU/ttG3dPeg1EtX/LVT7yuxdz3E+BXnEqxwgh+ec= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411084426-590a939240de h1:17qcDGmHmZppIq6Eg6UVapGhEciJIFYnqanYjy6es4w= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411084426-590a939240de/go.mod h1:87lVvPi4rmay0Dg5sOy/zVpCFqVfWXA9imScZxpqLYk= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411084426-590a939240de h1:y6NbCB3jQH4EOHOmmYUmFBm36u25l9bckDKT6C3qhdw= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411084426-590a939240de/go.mod h1:DjJDDKxBPqLWPKKecDXBnM1kN4hi5XiLB7yAQqRpSRQ= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411090936-c4c24f07055b h1:HoDVffelEvLknLRIRKvljGko+bH0nHEanMAymJ6aVlc= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411090936-c4c24f07055b/go.mod h1:5dRIQromRQsNafy0N4FC8NNCwRdKcc9pU2j8Pw7bP/Q= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411090936-c4c24f07055b h1:pyvSeAadOf7hrBHs0yimVqQiRhIIycfazp+3WdG3S14= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411090936-c4c24f07055b/go.mod h1:Yy0I5hWPtCgL9BR7yeRieio8cLfxkXGNzENhtj/8FU0= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 h1:mvkk1A/jIe+lsFFpRNfyd9UfvhagATdpnjy8K7kANeo= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04/go.mod h1:mYYf7pYb7sGJ9zYIOw2aYlIl5cgKT0K93rZx4LvDAuA= github.com/osmosis-labs/wasmd v0.45.0-osmo h1:NIp7pvJV5HuBN1HwPgEmXKQM2TjVIVdJErIHnB9IMO8= diff --git a/x/epochs/go.mod b/x/epochs/go.mod index a3d96124c0b..dfb29d03d22 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -9,7 +9,7 @@ require ( github.com/cosmos/gogoproto v1.4.11 github.com/golang/protobuf v1.5.4 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b github.com/spf13/cobra v1.8.0 github.com/stretchr/testify v1.9.0 golang.org/x/exp v0.0.0-20230905200255-921286631fa9 @@ -111,7 +111,7 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mtibben/percent v0.2.1 // indirect github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae // indirect - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de // indirect + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect github.com/pkg/errors v0.9.1 // indirect diff --git a/x/epochs/go.sum b/x/epochs/go.sum index b259b4b58b7..7aecbf92c4a 100644 --- a/x/epochs/go.sum +++ b/x/epochs/go.sum @@ -1224,10 +1224,10 @@ github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2 h1:3k4I3zCxdNP+mjhR7AtKr1PPu github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2/go.mod h1:fE+yBeExsJHA35plOZ7FmC/JejO5UdEHNcwO3dj2wc8= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de h1:BmR5g0KhFaIW2XheFb2sjWdklPlxi2Z+CRSjf/VDxmM= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de/go.mod h1:EH4baEX2mKDDDgcXQEk5gLQ+ECdDIr89Gtib5a+b3B4= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de h1:SPkrgdKuSqcgLb69n/nB9ET1HBkJKryezfBCCs2y55U= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de/go.mod h1:n4M42bFg0gv2DYTTkQKkMbK1yoQgf4b2tXKbDQaYgDA= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b h1:xoqEpefWRr/5REEbrtBIswKMgrbOMVszAVO91qPBDE0= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b/go.mod h1:QgluPESktAZYPQHPwLU7woP0+VeUNCfZpjwoQJnqJr4= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b h1:+zYuf/AGc9R9h3RiWQfgxnuEBtzLmnz0kdgw7K+JWAA= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b/go.mod h1:QqH0gW3eEHooG/xCD0JFNgBpLPURn/JKn1+AC6Dicso= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= diff --git a/x/ibc-hooks/go.mod b/x/ibc-hooks/go.mod index f57f7e4667d..e07e540cfc7 100644 --- a/x/ibc-hooks/go.mod +++ b/x/ibc-hooks/go.mod @@ -11,8 +11,8 @@ require ( github.com/cosmos/gogoproto v1.4.11 github.com/cosmos/ibc-go/v7 v7.4.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b github.com/spf13/cobra v1.8.0 google.golang.org/grpc v1.62.1 google.golang.org/protobuf v1.33.0 diff --git a/x/ibc-hooks/go.sum b/x/ibc-hooks/go.sum index 712b484efbe..b77d96e83b3 100644 --- a/x/ibc-hooks/go.sum +++ b/x/ibc-hooks/go.sum @@ -1239,10 +1239,10 @@ github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2 h1:3k4I3zCxdNP+mjhR7AtKr1PPu github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2/go.mod h1:fE+yBeExsJHA35plOZ7FmC/JejO5UdEHNcwO3dj2wc8= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de h1:BmR5g0KhFaIW2XheFb2sjWdklPlxi2Z+CRSjf/VDxmM= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411084426-590a939240de/go.mod h1:EH4baEX2mKDDDgcXQEk5gLQ+ECdDIr89Gtib5a+b3B4= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de h1:SPkrgdKuSqcgLb69n/nB9ET1HBkJKryezfBCCs2y55U= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411084426-590a939240de/go.mod h1:n4M42bFg0gv2DYTTkQKkMbK1yoQgf4b2tXKbDQaYgDA= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b h1:xoqEpefWRr/5REEbrtBIswKMgrbOMVszAVO91qPBDE0= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b/go.mod h1:QgluPESktAZYPQHPwLU7woP0+VeUNCfZpjwoQJnqJr4= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b h1:+zYuf/AGc9R9h3RiWQfgxnuEBtzLmnz0kdgw7K+JWAA= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b/go.mod h1:QqH0gW3eEHooG/xCD0JFNgBpLPURn/JKn1+AC6Dicso= github.com/osmosis-labs/wasmd v0.45.0-osmo h1:NIp7pvJV5HuBN1HwPgEmXKQM2TjVIVdJErIHnB9IMO8= github.com/osmosis-labs/wasmd v0.45.0-osmo/go.mod h1:J6eRvwii5T1WxhetZkBg1kOJS3GTn1Bw2OLyZBb8EVU= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= From d61aba4ce83f39aefc7d5577e3aee83e80b04332 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 18:19:58 +0900 Subject: [PATCH 09/27] Remove some extra ops from CL --- x/concentrated-liquidity/swapstrategy/one_for_zero.go | 5 ++--- x/concentrated-liquidity/swapstrategy/swap_strategy.go | 1 + x/concentrated-liquidity/swapstrategy/zero_for_one.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x/concentrated-liquidity/swapstrategy/one_for_zero.go b/x/concentrated-liquidity/swapstrategy/one_for_zero.go index 1f01654c803..684445edeeb 100644 --- a/x/concentrated-liquidity/swapstrategy/one_for_zero.go +++ b/x/concentrated-liquidity/swapstrategy/one_for_zero.go @@ -62,14 +62,13 @@ func (s oneForZeroStrategy) GetSqrtTargetPrice(nextTickSqrtPrice osmomath.BigDec func (s oneForZeroStrategy) ComputeSwapWithinBucketOutGivenIn(sqrtPriceCurrent, sqrtPriceTarget osmomath.BigDec, liquidity, amountOneInRemaining osmomath.Dec) (osmomath.BigDec, osmomath.Dec, osmomath.Dec, osmomath.Dec) { // TODO: Change to Dec liquidityBigDec := osmomath.BigDecFromDec(liquidity) - // TODO: Undo this cast, and do NewBigDecFromDecMulDec in line 72 - amountOneInRemainingBigDec := osmomath.BigDecFromDec(amountOneInRemaining) // Estimate the amount of token one needed until the target sqrt price is reached. amountOneIn := math.CalcAmount1Delta(liquidityBigDec, sqrtPriceTarget, sqrtPriceCurrent, true) // Calculate sqrtPriceNext on the amount of token remaining after spread reward. - amountOneInRemainingLessSpreadReward := amountOneInRemainingBigDec.MulTruncate(oneBigDec.Sub(osmomath.BigDecFromDec(s.spreadFactor))) + oneMinusTakerFee := oneDec.Sub(s.spreadFactor) + amountOneInRemainingLessSpreadReward := osmomath.NewBigDecFromDecMulDec(amountOneInRemaining, oneMinusTakerFee) var sqrtPriceNext osmomath.BigDec // If have more of the amount remaining after spread reward than estimated until target, diff --git a/x/concentrated-liquidity/swapstrategy/swap_strategy.go b/x/concentrated-liquidity/swapstrategy/swap_strategy.go index b691816f052..a6c120d8bc3 100644 --- a/x/concentrated-liquidity/swapstrategy/swap_strategy.go +++ b/x/concentrated-liquidity/swapstrategy/swap_strategy.go @@ -91,6 +91,7 @@ type SwapStrategy interface { var ( oneBigDec = osmomath.OneBigDec() + oneDec = osmomath.OneDec() ) // New returns a swap strategy based on the provided zeroForOne parameter diff --git a/x/concentrated-liquidity/swapstrategy/zero_for_one.go b/x/concentrated-liquidity/swapstrategy/zero_for_one.go index 1102d12ef51..33e6a19d939 100644 --- a/x/concentrated-liquidity/swapstrategy/zero_for_one.go +++ b/x/concentrated-liquidity/swapstrategy/zero_for_one.go @@ -61,13 +61,13 @@ func (s zeroForOneStrategy) GetSqrtTargetPrice(nextTickSqrtPrice osmomath.BigDec // - zeroForOneStrategy assumes moving to the left of the current square root price. func (s zeroForOneStrategy) ComputeSwapWithinBucketOutGivenIn(sqrtPriceCurrent, sqrtPriceTarget osmomath.BigDec, liquidity, amountZeroInRemaining osmomath.Dec) (osmomath.BigDec, osmomath.Dec, osmomath.Dec, osmomath.Dec) { liquidityBigDec := osmomath.BigDecFromDec(liquidity) - amountZeroInRemainingBigDec := osmomath.BigDecFromDec(amountZeroInRemaining) // Estimate the amount of token zero needed until the target sqrt price is reached. amountZeroIn := math.CalcAmount0Delta(liquidityBigDec, sqrtPriceTarget, sqrtPriceCurrent, true) // N.B.: if this is false, causes infinite loop // Calculate sqrtPriceNext on the amount of token remaining after spread reward. - amountZeroInRemainingLessSpreadReward := amountZeroInRemainingBigDec.Mul(oneBigDec.Sub(osmomath.BigDecFromDec(s.spreadFactor))) + oneMinusTakerFee := oneDec.Sub(s.spreadFactor) + amountZeroInRemainingLessSpreadReward := osmomath.NewBigDecFromDecMulDec(amountZeroInRemaining, oneMinusTakerFee) var sqrtPriceNext osmomath.BigDec // If have more of the amount remaining after spread reward than estimated until target, From b8e39bc2f81e3a34914b2af918d0d57f84bc41fd Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 18:30:19 +0900 Subject: [PATCH 10/27] Further perf notes --- x/concentrated-liquidity/math/math.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/concentrated-liquidity/math/math.go b/x/concentrated-liquidity/math/math.go index de58a333ae4..db782260ba4 100644 --- a/x/concentrated-liquidity/math/math.go +++ b/x/concentrated-liquidity/math/math.go @@ -79,6 +79,7 @@ func CalcAmount0Delta(liq, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) // The denominator is truncated to get a higher final amount. // Note that the order of divisions is important here. First, we divide by a larger number (sqrtPriceB) and then by a smaller number (sqrtPriceA). // This leads to a smaller error amplification. This only matters in cases where at least one of the sqrt prices is below 1. + // TODO (perf): Don't truncate after liq.MulRoundUp(diff), we actually scale by that in the next Quo // TODO (perf): QuoRoundUpMut with no reallocation. return liq.MulRoundUp(diff).QuoRoundUpMut(sqrtPriceB).QuoRoundUpMut(sqrtPriceA).CeilMut() } From 2c528700ffb8bbaa43431ef74ca58c3b36ad4ff1 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 18:37:00 +0900 Subject: [PATCH 11/27] Make faster QuoRoundUpNextIntMut --- osmomath/decimal.go | 10 ++++++ osmomath/decimal_test.go | 48 +++++++++++++++++++-------- x/concentrated-liquidity/math/math.go | 3 +- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/osmomath/decimal.go b/osmomath/decimal.go index 52498d103af..7e5b7be6fcd 100644 --- a/osmomath/decimal.go +++ b/osmomath/decimal.go @@ -492,6 +492,16 @@ func (d BigDec) QuoRoundUpMut(d2 BigDec) BigDec { return BigDec{d.i} } +// quotient, round up to next integer (mutative) +func (d BigDec) QuoRoundUpNextIntMut(d2 BigDec) BigDec { + _, rem := d.i.QuoRem(d.i, d2.i, new(big.Int)) + + d.i = incBasedOnRem(rem, d.i) + d.i.Mul(d.i, defaultBigDecPrecisionReuse) + assertMaxBitLen(d.i) + return BigDec{d.i} +} + // quotient func (d BigDec) QuoInt(i BigInt) BigDec { mul := new(big.Int).Quo(d.i, i.i) diff --git a/osmomath/decimal_test.go b/osmomath/decimal_test.go index 34349434a44..1a67c440b1c 100644 --- a/osmomath/decimal_test.go +++ b/osmomath/decimal_test.go @@ -179,27 +179,29 @@ func (s *decimalTestSuite) TestNewDecFromStr() { } var interestingDecNumbers = []string{ - "123456789012345678901234567890123456.123456789012345678", - "111111111111111111111111111111111111.111111111111111111", - "999999999999999999999999999999999999.999999999999999999", - "314159265358979323846264338327950288.419716939937510582", // Approximation of Pi - "161803398874989484820458683436563811.772030917980576286", // Approximation of Phi - "271828182845904523536028747135266249.775724709369995957", // Approximation of e - "101010101010101010101010101010101010.101010101010101010", // Binary pattern - "123456789987654321123456789987654321.123456789987654321", // Ascending and descending pattern - "112358132134558914423337761098715972.584418167651094617", // Inspired by Fibonacci sequence - "142857142857142857142857142857142857.142857142857142857", // Repeating decimal for 1/7 + "123456789012345678901234567890123456789012345678901234567890.123456789012345678901234567890123456", + "111111111111111111111111111111111111111111111111111111111111.111111111111111111111111111111111111", + "999999999999999999999999999999999999999999999999999999999999.999999999999999999999999999999999999", + "3141592653589793238462643383279502884197169399375105820974944.592307816406286208998628034825342117", // Approximation of Pi, extended + "1618033988749894848204586834365638117720309179805762862135448.622705260462818902449707207204189391", // Approximation of Phi, extended + "2718281828459045235360287471352662497757247093699959574966967.627724076630353547594571382178525166", // Approximation of e, extended + "101010101010101010101010101010101010101010101010101010101010.101010101010101010101010101010101010", // Binary pattern extended + "1234567899876543210123456789987654321012345678998765432101234.567899876543210123456789987654321012", // Ascending and descending pattern extended + "1123581321345589144233377610987159725844181676510946173113801.986211915342546982272763642843251547", // Inspired by Fibonacci sequence, creatively adjusted + "1428571428571428571428571428571428571428571428571428571428571.428571428571428571428571428571428571", // Repeating decimal for 1/7 extended } +var interestingDecNumbersBigDec = []osmomath.BigDec{} var interestingDecNumbersDec = []osmomath.Dec{} func init() { for _, str := range interestingDecNumbers { - d, err := osmomath.NewDecFromStr(str) + d, err := osmomath.NewBigDecFromStr(str) if err != nil { panic(fmt.Sprintf("error parsing decimal string %v: %v", str, err)) } - interestingDecNumbersDec = append(interestingDecNumbersDec, d) + interestingDecNumbersBigDec = append(interestingDecNumbersBigDec, d) + interestingDecNumbersDec = append(interestingDecNumbersDec, d.Dec()) } } @@ -213,6 +215,7 @@ func (s *decimalTestSuite) TestNewBigDecFromDecMulDec() { tests = append(tests, testcase{d1, d2}) } } + s.Require().True(len(tests) > 20, "no tests to run") for _, tc := range tests { s.Run(fmt.Sprintf("d1=%v, d2=%v", tc.s1, tc.s2), func() { s1D := osmomath.BigDecFromDec(tc.s1) @@ -222,7 +225,26 @@ func (s *decimalTestSuite) TestNewBigDecFromDecMulDec() { s.Require().True(expected.Equal(actual), "expected %v, got %v", expected, actual) }) } - s.Require().True(len(tests) > 20) +} + +func (s *decimalTestSuite) TestQuoRoundUpNextIntMut() { + type testcase struct { + s1, s2 osmomath.BigDec + } + tests := []testcase{} + for _, d1 := range interestingDecNumbersBigDec { + for _, d2 := range interestingDecNumbersBigDec { + tests = append(tests, testcase{d1, d2}) + } + } + s.Require().True(len(tests) > 20, "no tests to run") + for _, tc := range tests { + s.Run(fmt.Sprintf("d1=%v, d2=%v", tc.s1, tc.s2), func() { + expected := tc.s1.QuoRoundUp(tc.s2).CeilMut() + actual := tc.s1.QuoRoundUpNextIntMut(tc.s2) + s.Require().True(expected.Equal(actual), "expected %v, got %v", expected, actual) + }) + } } func (s *decimalTestSuite) TestDecString() { diff --git a/x/concentrated-liquidity/math/math.go b/x/concentrated-liquidity/math/math.go index db782260ba4..6e3484d1745 100644 --- a/x/concentrated-liquidity/math/math.go +++ b/x/concentrated-liquidity/math/math.go @@ -80,7 +80,8 @@ func CalcAmount0Delta(liq, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) // Note that the order of divisions is important here. First, we divide by a larger number (sqrtPriceB) and then by a smaller number (sqrtPriceA). // This leads to a smaller error amplification. This only matters in cases where at least one of the sqrt prices is below 1. // TODO (perf): Don't truncate after liq.MulRoundUp(diff), we actually scale by that in the next Quo - // TODO (perf): QuoRoundUpMut with no reallocation. + // TODO (perf): QuoRoundUpMut with no reallocation for internal scratch var. + // TODO (perf): Combine QuoRoundUpMut and CeilMut into one function. return liq.MulRoundUp(diff).QuoRoundUpMut(sqrtPriceB).QuoRoundUpMut(sqrtPriceA).CeilMut() } // These are truncated at precision end to round in favor of the pool when: From 7911f254b81c1ed8ecd33f288779c0cdd370ab1c Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Apr 2024 09:46:46 +0000 Subject: [PATCH 12/27] Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- osmomath/go.mod | 2 +- osmomath/go.sum | 4 ++-- osmoutils/go.mod | 6 +++--- osmoutils/go.sum | 12 ++++++------ x/epochs/go.mod | 4 ++-- x/epochs/go.sum | 8 ++++---- x/ibc-hooks/go.mod | 4 ++-- x/ibc-hooks/go.sum | 8 ++++---- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index 0757203ace2..35a37974b5a 100644 --- a/go.mod +++ b/go.mod @@ -30,10 +30,10 @@ require ( github.com/mattn/go-sqlite3 v1.14.17 github.com/ory/dockertest/v3 v3.10.0 github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b - github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411090936-c4c24f07055b - github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411090936-c4c24f07055b + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8 + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8 + github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411093700-2c528700ffb8 + github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411093700-2c528700ffb8 github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 github.com/pkg/errors v0.9.1 github.com/rakyll/statik v0.1.7 diff --git a/go.sum b/go.sum index b817e277ea8..90a54475c66 100644 --- a/go.sum +++ b/go.sum @@ -1517,14 +1517,14 @@ github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0c github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:YlmchqTmlwdWSmrRmXKR+PcU96ntOd8u10vTaTZdcNY= github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3/go.mod h1:lV6KnqXYD/ayTe7310MHtM3I2q8Z6bBfMAi+bhwPYtI= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b h1:xoqEpefWRr/5REEbrtBIswKMgrbOMVszAVO91qPBDE0= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b/go.mod h1:QgluPESktAZYPQHPwLU7woP0+VeUNCfZpjwoQJnqJr4= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b h1:+zYuf/AGc9R9h3RiWQfgxnuEBtzLmnz0kdgw7K+JWAA= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b/go.mod h1:QqH0gW3eEHooG/xCD0JFNgBpLPURn/JKn1+AC6Dicso= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411090936-c4c24f07055b h1:HoDVffelEvLknLRIRKvljGko+bH0nHEanMAymJ6aVlc= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411090936-c4c24f07055b/go.mod h1:5dRIQromRQsNafy0N4FC8NNCwRdKcc9pU2j8Pw7bP/Q= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411090936-c4c24f07055b h1:pyvSeAadOf7hrBHs0yimVqQiRhIIycfazp+3WdG3S14= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411090936-c4c24f07055b/go.mod h1:Yy0I5hWPtCgL9BR7yeRieio8cLfxkXGNzENhtj/8FU0= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8 h1:69V6PWMnpphBgCU4HPAc3pg7ZYr3lPbfEx1wcQ9JY5U= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8/go.mod h1:OYSoz1RjihXPt2VOKrLBHIeNuHyRMFCxFJQCuWeXxww= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8 h1:eq5YyHIxN1uLWVxLjaCyzqtWP4xFaqFg8F1HAsKf2gQ= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8/go.mod h1:Md+3fQfQQCR/IU0E0CbwGJ+Feu9NOSGhehkprBkNc94= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411093700-2c528700ffb8 h1:yS1GcPwqI2Fl7S9NNV2TjrKVVXu5dvcfOshyK5WN7HU= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411093700-2c528700ffb8/go.mod h1:sBce3HeShv9SN4M+5hu7JqBQBTY8OqJZdUiLT5vZ6zA= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411093700-2c528700ffb8 h1:iwcUcTChDR8X0ee8yzp/6QnVDA/VPi+Z51T3/MmdG9A= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411093700-2c528700ffb8/go.mod h1:vRiSKAWp1CBq+XJ1C2knGlYXj1Bl2Odwx5AlvONTp3A= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 h1:mvkk1A/jIe+lsFFpRNfyd9UfvhagATdpnjy8K7kANeo= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04/go.mod h1:mYYf7pYb7sGJ9zYIOw2aYlIl5cgKT0K93rZx4LvDAuA= github.com/osmosis-labs/wasmd v0.45.0-osmo h1:NIp7pvJV5HuBN1HwPgEmXKQM2TjVIVdJErIHnB9IMO8= diff --git a/osmomath/go.mod b/osmomath/go.mod index 603044d195f..e1869c5e948 100644 --- a/osmomath/go.mod +++ b/osmomath/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( cosmossdk.io/math v1.3.0 github.com/cosmos/cosmos-sdk v0.47.8 - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8 github.com/stretchr/testify v1.9.0 gopkg.in/yaml.v2 v2.4.0 diff --git a/osmomath/go.sum b/osmomath/go.sum index 233789a8e9f..d59284fabb7 100644 --- a/osmomath/go.sum +++ b/osmomath/go.sum @@ -263,8 +263,8 @@ github.com/onsi/gomega v1.28.1 h1:MijcGUbfYuznzK/5R4CPNoUP/9Xvuo20sXfEm6XxoTA= github.com/onsi/gomega v1.28.1/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b h1:+zYuf/AGc9R9h3RiWQfgxnuEBtzLmnz0kdgw7K+JWAA= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b/go.mod h1:QqH0gW3eEHooG/xCD0JFNgBpLPURn/JKn1+AC6Dicso= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8 h1:eq5YyHIxN1uLWVxLjaCyzqtWP4xFaqFg8F1HAsKf2gQ= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8/go.mod h1:Md+3fQfQQCR/IU0E0CbwGJ+Feu9NOSGhehkprBkNc94= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= diff --git a/osmoutils/go.mod b/osmoutils/go.mod index 04bf7cfa8e6..68940b6c51f 100644 --- a/osmoutils/go.mod +++ b/osmoutils/go.mod @@ -13,7 +13,7 @@ require ( github.com/cosmos/gogoproto v1.4.11 github.com/cosmos/iavl v1.1.2-0.20240405173644-e52f7630d3b7 github.com/cosmos/ibc-go/v7 v7.4.0 - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8 github.com/osmosis-labs/osmosis/v24 v24.0.0-rc0 github.com/spf13/cast v1.6.0 github.com/spf13/cobra v1.8.0 @@ -155,8 +155,8 @@ require ( github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae // indirect github.com/onsi/gomega v1.28.1 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect - github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411090936-c4c24f07055b // indirect - github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411090936-c4c24f07055b // indirect + github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411093700-2c528700ffb8 // indirect + github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411093700-2c528700ffb8 // indirect github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect diff --git a/osmoutils/go.sum b/osmoutils/go.sum index 40c7e2ccf1a..2701c50fdf6 100644 --- a/osmoutils/go.sum +++ b/osmoutils/go.sum @@ -1283,14 +1283,14 @@ github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2 h1:3k4I3zCxdNP+mjhR7AtKr1PPu github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2/go.mod h1:fE+yBeExsJHA35plOZ7FmC/JejO5UdEHNcwO3dj2wc8= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b h1:xoqEpefWRr/5REEbrtBIswKMgrbOMVszAVO91qPBDE0= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b/go.mod h1:QgluPESktAZYPQHPwLU7woP0+VeUNCfZpjwoQJnqJr4= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8 h1:69V6PWMnpphBgCU4HPAc3pg7ZYr3lPbfEx1wcQ9JY5U= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8/go.mod h1:OYSoz1RjihXPt2VOKrLBHIeNuHyRMFCxFJQCuWeXxww= github.com/osmosis-labs/osmosis/v24 v24.0.0-rc0 h1:wAcm5rvcAMwSPFWgzUr/lR7U+e+4PvZ8fkehhpwiJho= github.com/osmosis-labs/osmosis/v24 v24.0.0-rc0/go.mod h1:5QdPU/ttG3dPeg1EtX/LVT7yuxdz3E+BXnEqxwgh+ec= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411090936-c4c24f07055b h1:HoDVffelEvLknLRIRKvljGko+bH0nHEanMAymJ6aVlc= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411090936-c4c24f07055b/go.mod h1:5dRIQromRQsNafy0N4FC8NNCwRdKcc9pU2j8Pw7bP/Q= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411090936-c4c24f07055b h1:pyvSeAadOf7hrBHs0yimVqQiRhIIycfazp+3WdG3S14= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411090936-c4c24f07055b/go.mod h1:Yy0I5hWPtCgL9BR7yeRieio8cLfxkXGNzENhtj/8FU0= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411093700-2c528700ffb8 h1:yS1GcPwqI2Fl7S9NNV2TjrKVVXu5dvcfOshyK5WN7HU= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411093700-2c528700ffb8/go.mod h1:sBce3HeShv9SN4M+5hu7JqBQBTY8OqJZdUiLT5vZ6zA= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411093700-2c528700ffb8 h1:iwcUcTChDR8X0ee8yzp/6QnVDA/VPi+Z51T3/MmdG9A= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411093700-2c528700ffb8/go.mod h1:vRiSKAWp1CBq+XJ1C2knGlYXj1Bl2Odwx5AlvONTp3A= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 h1:mvkk1A/jIe+lsFFpRNfyd9UfvhagATdpnjy8K7kANeo= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04/go.mod h1:mYYf7pYb7sGJ9zYIOw2aYlIl5cgKT0K93rZx4LvDAuA= github.com/osmosis-labs/wasmd v0.45.0-osmo h1:NIp7pvJV5HuBN1HwPgEmXKQM2TjVIVdJErIHnB9IMO8= diff --git a/x/epochs/go.mod b/x/epochs/go.mod index dfb29d03d22..795900ef132 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -9,7 +9,7 @@ require ( github.com/cosmos/gogoproto v1.4.11 github.com/golang/protobuf v1.5.4 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8 github.com/spf13/cobra v1.8.0 github.com/stretchr/testify v1.9.0 golang.org/x/exp v0.0.0-20230905200255-921286631fa9 @@ -111,7 +111,7 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mtibben/percent v0.2.1 // indirect github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae // indirect - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b // indirect + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect github.com/pkg/errors v0.9.1 // indirect diff --git a/x/epochs/go.sum b/x/epochs/go.sum index 7aecbf92c4a..62adc96af53 100644 --- a/x/epochs/go.sum +++ b/x/epochs/go.sum @@ -1224,10 +1224,10 @@ github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2 h1:3k4I3zCxdNP+mjhR7AtKr1PPu github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2/go.mod h1:fE+yBeExsJHA35plOZ7FmC/JejO5UdEHNcwO3dj2wc8= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b h1:xoqEpefWRr/5REEbrtBIswKMgrbOMVszAVO91qPBDE0= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b/go.mod h1:QgluPESktAZYPQHPwLU7woP0+VeUNCfZpjwoQJnqJr4= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b h1:+zYuf/AGc9R9h3RiWQfgxnuEBtzLmnz0kdgw7K+JWAA= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b/go.mod h1:QqH0gW3eEHooG/xCD0JFNgBpLPURn/JKn1+AC6Dicso= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8 h1:69V6PWMnpphBgCU4HPAc3pg7ZYr3lPbfEx1wcQ9JY5U= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8/go.mod h1:OYSoz1RjihXPt2VOKrLBHIeNuHyRMFCxFJQCuWeXxww= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8 h1:eq5YyHIxN1uLWVxLjaCyzqtWP4xFaqFg8F1HAsKf2gQ= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8/go.mod h1:Md+3fQfQQCR/IU0E0CbwGJ+Feu9NOSGhehkprBkNc94= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= diff --git a/x/ibc-hooks/go.mod b/x/ibc-hooks/go.mod index e07e540cfc7..a38859e0196 100644 --- a/x/ibc-hooks/go.mod +++ b/x/ibc-hooks/go.mod @@ -11,8 +11,8 @@ require ( github.com/cosmos/gogoproto v1.4.11 github.com/cosmos/ibc-go/v7 v7.4.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8 + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8 github.com/spf13/cobra v1.8.0 google.golang.org/grpc v1.62.1 google.golang.org/protobuf v1.33.0 diff --git a/x/ibc-hooks/go.sum b/x/ibc-hooks/go.sum index b77d96e83b3..c9419dbb8d0 100644 --- a/x/ibc-hooks/go.sum +++ b/x/ibc-hooks/go.sum @@ -1239,10 +1239,10 @@ github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2 h1:3k4I3zCxdNP+mjhR7AtKr1PPu github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2/go.mod h1:fE+yBeExsJHA35plOZ7FmC/JejO5UdEHNcwO3dj2wc8= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b h1:xoqEpefWRr/5REEbrtBIswKMgrbOMVszAVO91qPBDE0= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411090936-c4c24f07055b/go.mod h1:QgluPESktAZYPQHPwLU7woP0+VeUNCfZpjwoQJnqJr4= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b h1:+zYuf/AGc9R9h3RiWQfgxnuEBtzLmnz0kdgw7K+JWAA= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411090936-c4c24f07055b/go.mod h1:QqH0gW3eEHooG/xCD0JFNgBpLPURn/JKn1+AC6Dicso= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8 h1:69V6PWMnpphBgCU4HPAc3pg7ZYr3lPbfEx1wcQ9JY5U= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8/go.mod h1:OYSoz1RjihXPt2VOKrLBHIeNuHyRMFCxFJQCuWeXxww= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8 h1:eq5YyHIxN1uLWVxLjaCyzqtWP4xFaqFg8F1HAsKf2gQ= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8/go.mod h1:Md+3fQfQQCR/IU0E0CbwGJ+Feu9NOSGhehkprBkNc94= github.com/osmosis-labs/wasmd v0.45.0-osmo h1:NIp7pvJV5HuBN1HwPgEmXKQM2TjVIVdJErIHnB9IMO8= github.com/osmosis-labs/wasmd v0.45.0-osmo/go.mod h1:J6eRvwii5T1WxhetZkBg1kOJS3GTn1Bw2OLyZBb8EVU= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= From 93041da643b2e43a86c11c5b1767171f862c07f8 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 18:50:55 +0900 Subject: [PATCH 13/27] Remove another 2 BigDec ops --- x/concentrated-liquidity/math/math.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/concentrated-liquidity/math/math.go b/x/concentrated-liquidity/math/math.go index 6e3484d1745..fcc82f228e2 100644 --- a/x/concentrated-liquidity/math/math.go +++ b/x/concentrated-liquidity/math/math.go @@ -81,8 +81,7 @@ func CalcAmount0Delta(liq, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) // This leads to a smaller error amplification. This only matters in cases where at least one of the sqrt prices is below 1. // TODO (perf): Don't truncate after liq.MulRoundUp(diff), we actually scale by that in the next Quo // TODO (perf): QuoRoundUpMut with no reallocation for internal scratch var. - // TODO (perf): Combine QuoRoundUpMut and CeilMut into one function. - return liq.MulRoundUp(diff).QuoRoundUpMut(sqrtPriceB).QuoRoundUpMut(sqrtPriceA).CeilMut() + return liq.MulRoundUp(diff).QuoRoundUpMut(sqrtPriceB).QuoRoundUpNextIntMut(sqrtPriceA) } // These are truncated at precision end to round in favor of the pool when: // - calculating amount out during swap From 67b62f5e4e2dba9f8fb9374e7b561f8139623d52 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 19:58:52 +0900 Subject: [PATCH 14/27] Add another dec op --- osmomath/decimal.go | 9 ++++++++- x/concentrated-liquidity/math/math.go | 2 +- x/concentrated-liquidity/swapstrategy/swap_strategy.go | 3 +-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/osmomath/decimal.go b/osmomath/decimal.go index 7e5b7be6fcd..8a6bb380f85 100644 --- a/osmomath/decimal.go +++ b/osmomath/decimal.go @@ -387,6 +387,14 @@ func (d BigDec) MulRoundUp(d2 BigDec) BigDec { return BigDec{chopped} } +// multiplication round up by Dec +func (d BigDec) MulRoundUpDec(d2 Dec) BigDec { + mul := new(big.Int).Mul(d.i, d2.BigIntMut()) + chopped := chopPrecisionAndRoundUpMut(mul, precisionReuseSDKDec) + assertMaxBitLen(chopped) + return BigDec{chopped} +} + // multiplication func (d BigDec) MulInt(i BigInt) BigDec { mul := new(big.Int).Mul(d.i, i.i) @@ -445,7 +453,6 @@ func (d BigDec) QuoTruncateMut(d2 BigDec) BigDec { // multiply bigDec precision d.i.Mul(d.i, defaultBigDecPrecisionReuse) d.i.Quo(d.i, d2.i) - assertMaxBitLen(d.i) return d } diff --git a/x/concentrated-liquidity/math/math.go b/x/concentrated-liquidity/math/math.go index fcc82f228e2..9959e511d2a 100644 --- a/x/concentrated-liquidity/math/math.go +++ b/x/concentrated-liquidity/math/math.go @@ -79,7 +79,7 @@ func CalcAmount0Delta(liq, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) // The denominator is truncated to get a higher final amount. // Note that the order of divisions is important here. First, we divide by a larger number (sqrtPriceB) and then by a smaller number (sqrtPriceA). // This leads to a smaller error amplification. This only matters in cases where at least one of the sqrt prices is below 1. - // TODO (perf): Don't truncate after liq.MulRoundUp(diff), we actually scale by that in the next Quo + // TODO (perf): Don't truncate after liq.MulRoundUp(diff), we actually scale by that in the next Quo. ALT: Switch liq to Dec // TODO (perf): QuoRoundUpMut with no reallocation for internal scratch var. return liq.MulRoundUp(diff).QuoRoundUpMut(sqrtPriceB).QuoRoundUpNextIntMut(sqrtPriceA) } diff --git a/x/concentrated-liquidity/swapstrategy/swap_strategy.go b/x/concentrated-liquidity/swapstrategy/swap_strategy.go index a6c120d8bc3..833993bee63 100644 --- a/x/concentrated-liquidity/swapstrategy/swap_strategy.go +++ b/x/concentrated-liquidity/swapstrategy/swap_strategy.go @@ -90,8 +90,7 @@ type SwapStrategy interface { } var ( - oneBigDec = osmomath.OneBigDec() - oneDec = osmomath.OneDec() + oneDec = osmomath.OneDec() ) // New returns a swap strategy based on the provided zeroForOne parameter From 7147aa7e679d10caff16f0491df19071e83b21b4 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Apr 2024 11:03:38 +0000 Subject: [PATCH 15/27] Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- osmomath/go.mod | 2 +- osmomath/go.sum | 4 ++-- osmoutils/go.mod | 6 +++--- osmoutils/go.sum | 12 ++++++------ x/epochs/go.mod | 4 ++-- x/epochs/go.sum | 8 ++++---- x/ibc-hooks/go.mod | 4 ++-- x/ibc-hooks/go.sum | 8 ++++---- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index 35a37974b5a..3f6b67ef53b 100644 --- a/go.mod +++ b/go.mod @@ -30,10 +30,10 @@ require ( github.com/mattn/go-sqlite3 v1.14.17 github.com/ory/dockertest/v3 v3.10.0 github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8 - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8 - github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411093700-2c528700ffb8 - github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411093700-2c528700ffb8 + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d + github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411105852-67b62f5e4e2d + github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411105852-67b62f5e4e2d github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 github.com/pkg/errors v0.9.1 github.com/rakyll/statik v0.1.7 diff --git a/go.sum b/go.sum index 90a54475c66..588cd322988 100644 --- a/go.sum +++ b/go.sum @@ -1517,14 +1517,14 @@ github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0c github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:YlmchqTmlwdWSmrRmXKR+PcU96ntOd8u10vTaTZdcNY= github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3/go.mod h1:lV6KnqXYD/ayTe7310MHtM3I2q8Z6bBfMAi+bhwPYtI= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8 h1:69V6PWMnpphBgCU4HPAc3pg7ZYr3lPbfEx1wcQ9JY5U= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8/go.mod h1:OYSoz1RjihXPt2VOKrLBHIeNuHyRMFCxFJQCuWeXxww= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8 h1:eq5YyHIxN1uLWVxLjaCyzqtWP4xFaqFg8F1HAsKf2gQ= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8/go.mod h1:Md+3fQfQQCR/IU0E0CbwGJ+Feu9NOSGhehkprBkNc94= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411093700-2c528700ffb8 h1:yS1GcPwqI2Fl7S9NNV2TjrKVVXu5dvcfOshyK5WN7HU= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411093700-2c528700ffb8/go.mod h1:sBce3HeShv9SN4M+5hu7JqBQBTY8OqJZdUiLT5vZ6zA= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411093700-2c528700ffb8 h1:iwcUcTChDR8X0ee8yzp/6QnVDA/VPi+Z51T3/MmdG9A= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411093700-2c528700ffb8/go.mod h1:vRiSKAWp1CBq+XJ1C2knGlYXj1Bl2Odwx5AlvONTp3A= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d h1:k3J4VI8QZZF80gF3SJEfYt/HOdCpU3NW4XitM1+vXzE= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d/go.mod h1:dSjXHGer8fQl6Vw8kupk9CvXzKsSWwB2hzMZpgZswWc= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d h1:lwtBMKPEVxDcSUolMzR7+6aveX4zPTlvz5/3waYOquw= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d/go.mod h1:9kSOdruRj1//uuOksPJYh3hxIixtgdPDr81FM0SEORs= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411105852-67b62f5e4e2d h1:2MF97QJkPhso2AfsXkvaVDkxYwUB1CfDeNbnmxFBlFw= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411105852-67b62f5e4e2d/go.mod h1:Dz+CcsgqR3YPCMiKwVntDS/ZUW5LCKfxTQH3Ou0k+gY= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411105852-67b62f5e4e2d h1:Pdly7whBu1L3CYDF+EqdEV20hWgdkRVKPkBOxYJN2aE= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411105852-67b62f5e4e2d/go.mod h1:7mDRJngtcnLVSmkz1rOG53qdSDc1rS0fUqED6zZdG4o= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 h1:mvkk1A/jIe+lsFFpRNfyd9UfvhagATdpnjy8K7kANeo= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04/go.mod h1:mYYf7pYb7sGJ9zYIOw2aYlIl5cgKT0K93rZx4LvDAuA= github.com/osmosis-labs/wasmd v0.45.0-osmo h1:NIp7pvJV5HuBN1HwPgEmXKQM2TjVIVdJErIHnB9IMO8= diff --git a/osmomath/go.mod b/osmomath/go.mod index e1869c5e948..f70c6cad335 100644 --- a/osmomath/go.mod +++ b/osmomath/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( cosmossdk.io/math v1.3.0 github.com/cosmos/cosmos-sdk v0.47.8 - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8 + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d github.com/stretchr/testify v1.9.0 gopkg.in/yaml.v2 v2.4.0 diff --git a/osmomath/go.sum b/osmomath/go.sum index d59284fabb7..606e18a0a22 100644 --- a/osmomath/go.sum +++ b/osmomath/go.sum @@ -263,8 +263,8 @@ github.com/onsi/gomega v1.28.1 h1:MijcGUbfYuznzK/5R4CPNoUP/9Xvuo20sXfEm6XxoTA= github.com/onsi/gomega v1.28.1/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8 h1:eq5YyHIxN1uLWVxLjaCyzqtWP4xFaqFg8F1HAsKf2gQ= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8/go.mod h1:Md+3fQfQQCR/IU0E0CbwGJ+Feu9NOSGhehkprBkNc94= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d h1:lwtBMKPEVxDcSUolMzR7+6aveX4zPTlvz5/3waYOquw= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d/go.mod h1:9kSOdruRj1//uuOksPJYh3hxIixtgdPDr81FM0SEORs= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= diff --git a/osmoutils/go.mod b/osmoutils/go.mod index 68940b6c51f..aa002b4ef4d 100644 --- a/osmoutils/go.mod +++ b/osmoutils/go.mod @@ -13,7 +13,7 @@ require ( github.com/cosmos/gogoproto v1.4.11 github.com/cosmos/iavl v1.1.2-0.20240405173644-e52f7630d3b7 github.com/cosmos/ibc-go/v7 v7.4.0 - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8 + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d github.com/osmosis-labs/osmosis/v24 v24.0.0-rc0 github.com/spf13/cast v1.6.0 github.com/spf13/cobra v1.8.0 @@ -155,8 +155,8 @@ require ( github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae // indirect github.com/onsi/gomega v1.28.1 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect - github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411093700-2c528700ffb8 // indirect - github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411093700-2c528700ffb8 // indirect + github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411105852-67b62f5e4e2d // indirect + github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411105852-67b62f5e4e2d // indirect github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect diff --git a/osmoutils/go.sum b/osmoutils/go.sum index 2701c50fdf6..28fa693d314 100644 --- a/osmoutils/go.sum +++ b/osmoutils/go.sum @@ -1283,14 +1283,14 @@ github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2 h1:3k4I3zCxdNP+mjhR7AtKr1PPu github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2/go.mod h1:fE+yBeExsJHA35plOZ7FmC/JejO5UdEHNcwO3dj2wc8= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8 h1:69V6PWMnpphBgCU4HPAc3pg7ZYr3lPbfEx1wcQ9JY5U= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8/go.mod h1:OYSoz1RjihXPt2VOKrLBHIeNuHyRMFCxFJQCuWeXxww= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d h1:k3J4VI8QZZF80gF3SJEfYt/HOdCpU3NW4XitM1+vXzE= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d/go.mod h1:dSjXHGer8fQl6Vw8kupk9CvXzKsSWwB2hzMZpgZswWc= github.com/osmosis-labs/osmosis/v24 v24.0.0-rc0 h1:wAcm5rvcAMwSPFWgzUr/lR7U+e+4PvZ8fkehhpwiJho= github.com/osmosis-labs/osmosis/v24 v24.0.0-rc0/go.mod h1:5QdPU/ttG3dPeg1EtX/LVT7yuxdz3E+BXnEqxwgh+ec= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411093700-2c528700ffb8 h1:yS1GcPwqI2Fl7S9NNV2TjrKVVXu5dvcfOshyK5WN7HU= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411093700-2c528700ffb8/go.mod h1:sBce3HeShv9SN4M+5hu7JqBQBTY8OqJZdUiLT5vZ6zA= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411093700-2c528700ffb8 h1:iwcUcTChDR8X0ee8yzp/6QnVDA/VPi+Z51T3/MmdG9A= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411093700-2c528700ffb8/go.mod h1:vRiSKAWp1CBq+XJ1C2knGlYXj1Bl2Odwx5AlvONTp3A= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411105852-67b62f5e4e2d h1:2MF97QJkPhso2AfsXkvaVDkxYwUB1CfDeNbnmxFBlFw= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411105852-67b62f5e4e2d/go.mod h1:Dz+CcsgqR3YPCMiKwVntDS/ZUW5LCKfxTQH3Ou0k+gY= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411105852-67b62f5e4e2d h1:Pdly7whBu1L3CYDF+EqdEV20hWgdkRVKPkBOxYJN2aE= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411105852-67b62f5e4e2d/go.mod h1:7mDRJngtcnLVSmkz1rOG53qdSDc1rS0fUqED6zZdG4o= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 h1:mvkk1A/jIe+lsFFpRNfyd9UfvhagATdpnjy8K7kANeo= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04/go.mod h1:mYYf7pYb7sGJ9zYIOw2aYlIl5cgKT0K93rZx4LvDAuA= github.com/osmosis-labs/wasmd v0.45.0-osmo h1:NIp7pvJV5HuBN1HwPgEmXKQM2TjVIVdJErIHnB9IMO8= diff --git a/x/epochs/go.mod b/x/epochs/go.mod index 795900ef132..c7ad59d7bc1 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -9,7 +9,7 @@ require ( github.com/cosmos/gogoproto v1.4.11 github.com/golang/protobuf v1.5.4 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8 + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d github.com/spf13/cobra v1.8.0 github.com/stretchr/testify v1.9.0 golang.org/x/exp v0.0.0-20230905200255-921286631fa9 @@ -111,7 +111,7 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mtibben/percent v0.2.1 // indirect github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae // indirect - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8 // indirect + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect github.com/pkg/errors v0.9.1 // indirect diff --git a/x/epochs/go.sum b/x/epochs/go.sum index 62adc96af53..a64a90a4e7d 100644 --- a/x/epochs/go.sum +++ b/x/epochs/go.sum @@ -1224,10 +1224,10 @@ github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2 h1:3k4I3zCxdNP+mjhR7AtKr1PPu github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2/go.mod h1:fE+yBeExsJHA35plOZ7FmC/JejO5UdEHNcwO3dj2wc8= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8 h1:69V6PWMnpphBgCU4HPAc3pg7ZYr3lPbfEx1wcQ9JY5U= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8/go.mod h1:OYSoz1RjihXPt2VOKrLBHIeNuHyRMFCxFJQCuWeXxww= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8 h1:eq5YyHIxN1uLWVxLjaCyzqtWP4xFaqFg8F1HAsKf2gQ= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8/go.mod h1:Md+3fQfQQCR/IU0E0CbwGJ+Feu9NOSGhehkprBkNc94= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d h1:k3J4VI8QZZF80gF3SJEfYt/HOdCpU3NW4XitM1+vXzE= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d/go.mod h1:dSjXHGer8fQl6Vw8kupk9CvXzKsSWwB2hzMZpgZswWc= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d h1:lwtBMKPEVxDcSUolMzR7+6aveX4zPTlvz5/3waYOquw= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d/go.mod h1:9kSOdruRj1//uuOksPJYh3hxIixtgdPDr81FM0SEORs= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= diff --git a/x/ibc-hooks/go.mod b/x/ibc-hooks/go.mod index a38859e0196..f40ad646c2e 100644 --- a/x/ibc-hooks/go.mod +++ b/x/ibc-hooks/go.mod @@ -11,8 +11,8 @@ require ( github.com/cosmos/gogoproto v1.4.11 github.com/cosmos/ibc-go/v7 v7.4.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8 - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8 + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d github.com/spf13/cobra v1.8.0 google.golang.org/grpc v1.62.1 google.golang.org/protobuf v1.33.0 diff --git a/x/ibc-hooks/go.sum b/x/ibc-hooks/go.sum index c9419dbb8d0..c80486c28f0 100644 --- a/x/ibc-hooks/go.sum +++ b/x/ibc-hooks/go.sum @@ -1239,10 +1239,10 @@ github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2 h1:3k4I3zCxdNP+mjhR7AtKr1PPu github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2/go.mod h1:fE+yBeExsJHA35plOZ7FmC/JejO5UdEHNcwO3dj2wc8= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8 h1:69V6PWMnpphBgCU4HPAc3pg7ZYr3lPbfEx1wcQ9JY5U= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411093700-2c528700ffb8/go.mod h1:OYSoz1RjihXPt2VOKrLBHIeNuHyRMFCxFJQCuWeXxww= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8 h1:eq5YyHIxN1uLWVxLjaCyzqtWP4xFaqFg8F1HAsKf2gQ= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411093700-2c528700ffb8/go.mod h1:Md+3fQfQQCR/IU0E0CbwGJ+Feu9NOSGhehkprBkNc94= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d h1:k3J4VI8QZZF80gF3SJEfYt/HOdCpU3NW4XitM1+vXzE= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d/go.mod h1:dSjXHGer8fQl6Vw8kupk9CvXzKsSWwB2hzMZpgZswWc= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d h1:lwtBMKPEVxDcSUolMzR7+6aveX4zPTlvz5/3waYOquw= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d/go.mod h1:9kSOdruRj1//uuOksPJYh3hxIixtgdPDr81FM0SEORs= github.com/osmosis-labs/wasmd v0.45.0-osmo h1:NIp7pvJV5HuBN1HwPgEmXKQM2TjVIVdJErIHnB9IMO8= github.com/osmosis-labs/wasmd v0.45.0-osmo/go.mod h1:J6eRvwii5T1WxhetZkBg1kOJS3GTn1Bw2OLyZBb8EVU= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= From 0d8f2635a4eb57987e65abe17965e6f98621bd14 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 20:54:29 +0900 Subject: [PATCH 16/27] Start moving some liquidity calls to Dec not BigDec --- x/concentrated-liquidity/math/math.go | 19 ++++------ x/concentrated-liquidity/math/math_test.go | 38 +++++++++++++++---- .../swapstrategy/one_for_zero.go | 2 +- 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/x/concentrated-liquidity/math/math.go b/x/concentrated-liquidity/math/math.go index 9959e511d2a..b624fa20053 100644 --- a/x/concentrated-liquidity/math/math.go +++ b/x/concentrated-liquidity/math/math.go @@ -81,7 +81,7 @@ func CalcAmount0Delta(liq, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) // This leads to a smaller error amplification. This only matters in cases where at least one of the sqrt prices is below 1. // TODO (perf): Don't truncate after liq.MulRoundUp(diff), we actually scale by that in the next Quo. ALT: Switch liq to Dec // TODO (perf): QuoRoundUpMut with no reallocation for internal scratch var. - return liq.MulRoundUp(diff).QuoRoundUpMut(sqrtPriceB).QuoRoundUpNextIntMut(sqrtPriceA) + return diff.MulRoundUp(liq).QuoRoundUpMut(sqrtPriceB).QuoRoundUpNextIntMut(sqrtPriceA) } // These are truncated at precision end to round in favor of the pool when: // - calculating amount out during swap @@ -89,7 +89,7 @@ func CalcAmount0Delta(liq, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) // Each intermediary step is truncated at precision end to get a smaller final amount. // Note that the order of divisions is important here. First, we divide by a larger number (sqrtPriceB) and then by a smaller number (sqrtPriceA). // This leads to a smaller error amplification. - return liq.MulTruncate(diff).QuoTruncateMut(sqrtPriceB).QuoTruncateMut(sqrtPriceA) + return diff.MulTruncate(liq).QuoTruncateMut(sqrtPriceB).QuoTruncateMut(sqrtPriceA) } // CalcAmount1Delta takes the asset with the smaller liquidity in the pool as well as the sqrtpCur and the nextPrice and calculates the amount of asset 1 @@ -97,12 +97,7 @@ func CalcAmount0Delta(liq, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) // sqrtPriceB is the larger of sqrtpCur and the nextPrice // CalcAmount1Delta = liq * (sqrtPriceB - sqrtPriceA) func CalcAmount1Delta(liq, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) osmomath.BigDec { - // make sqrtPriceA the smaller value amongst sqrtPriceA and sqrtPriceB - // TODO: Remove this GT check and just do .AbsMut - if sqrtPriceA.GT(sqrtPriceB) { - sqrtPriceA, sqrtPriceB = sqrtPriceB, sqrtPriceA - } - diff := sqrtPriceB.Sub(sqrtPriceA) + diff := sqrtPriceB.Sub(sqrtPriceA).AbsMut() // if calculating for amountIn, we round up // if calculating for amountOut, we don't round at all // this is to prevent removing more from the pool than expected due to rounding @@ -116,13 +111,13 @@ func CalcAmount1Delta(liq, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) // Examples include: // - calculating amountIn during swap // - adding liquidity (request user to provide more tokens in in favor of the pool) - return liq.Mul(diff).CeilMut() + return diff.MulMut(liq).CeilMut() } // This is truncated at precision end to round in favor of the pool when: // - calculating amount out during swap // - withdrawing liquidity // The denominator is rounded up to get a higher final amount. - return liq.MulTruncate(diff) + return diff.MulTruncate(liq) } // GetNextSqrtPriceFromAmount0InRoundingUp utilizes sqrtPriceCurrent, liquidity, and amount of denom0 that still needs @@ -167,8 +162,8 @@ func GetNextSqrtPriceFromAmount0OutRoundingUp(sqrtPriceCurrent, liquidity, amoun // When we swap for token zero out given token one in, the price is increasing and we need to move the sqrt price (increase it) less to // avoid overpaying out of the pool. Therefore, we round down. // sqrt_next = sqrt_cur + token_in / liq -func GetNextSqrtPriceFromAmount1InRoundingDown(sqrtPriceCurrent, liquidity, amountOneRemainingIn osmomath.BigDec) (sqrtPriceNext osmomath.BigDec) { - return sqrtPriceCurrent.Add(amountOneRemainingIn.QuoTruncate(liquidity)) +func GetNextSqrtPriceFromAmount1InRoundingDown(sqrtPriceCurrent osmomath.BigDec, liquidity osmomath.Dec, amountOneRemainingIn osmomath.BigDec) (sqrtPriceNext osmomath.BigDec) { + return sqrtPriceCurrent.Add(amountOneRemainingIn.QuoTruncateDec(liquidity)) } // GetNextSqrtPriceFromAmount1OutRoundingDown utilizes the current sqrtPriceCurrent, liquidity, and amount of denom1 that still needs diff --git a/x/concentrated-liquidity/math/math_test.go b/x/concentrated-liquidity/math/math_test.go index c8ed14afe8b..bc1bfb4e3c1 100644 --- a/x/concentrated-liquidity/math/math_test.go +++ b/x/concentrated-liquidity/math/math_test.go @@ -472,6 +472,13 @@ type sqrtRoundingTestCase struct { expected osmomath.BigDec } +type sqrtRoundingDecTestCase struct { + sqrtPriceCurrent osmomath.BigDec + liquidity osmomath.Dec + amountRemaining osmomath.BigDec + expected osmomath.BigDec +} + func runSqrtRoundingTestCase( t *testing.T, name string, @@ -487,6 +494,21 @@ func runSqrtRoundingTestCase( } } +func runSqrtRoundingDecTestCase( + t *testing.T, + name string, + fn func(osmomath.BigDec, osmomath.Dec, osmomath.BigDec) osmomath.BigDec, + cases map[string]sqrtRoundingDecTestCase, +) { + for name, tc := range cases { + tc := tc + t.Run(name, func(t *testing.T) { + sqrtPriceNext := fn(tc.sqrtPriceCurrent, tc.liquidity, tc.amountRemaining) + require.Equal(t, tc.expected.String(), sqrtPriceNext.String()) + }) + } +} + // Estimates are computed with x/concentrated-liquidity/python/clmath.py func TestGetNextSqrtPriceFromAmount0InRoundingUp(t *testing.T) { tests := map[string]sqrtRoundingTestCase{ @@ -554,39 +576,39 @@ func TestGetNextSqrtPriceFromAmount0OutRoundingUp(t *testing.T) { // Estimates are computed with x/concentrated-liquidity/python/clmath.py func TestGetNextSqrtPriceFromAmount1InRoundingDown(t *testing.T) { - tests := map[string]sqrtRoundingTestCase{ + tests := map[string]sqrtRoundingDecTestCase{ "rounded down at precision end": { sqrtPriceCurrent: sqrt5000BigDec, - liquidity: osmomath.MustNewBigDecFromStr("3035764687.503020836176699298"), + liquidity: osmomath.MustNewDecFromStr("3035764687.503020836176699298"), amountRemaining: osmomath.MustNewBigDecFromStr("8398"), expected: osmomath.MustNewBigDecFromStr("70.710680885008822823343339270800000167"), }, "no round up due zeroes at precision end": { sqrtPriceCurrent: osmomath.MustNewBigDecFromStr("2.5"), - liquidity: osmomath.MustNewBigDecFromStr("1"), + liquidity: osmomath.OneDec(), amountRemaining: osmomath.MustNewBigDecFromStr("10"), // sqrt_next = sqrt_cur + token_in / liq expected: osmomath.MustNewBigDecFromStr("12.5"), }, "happy path": { - liquidity: osmomath.MustNewBigDecFromStr("1519437308.014768571721000000"), // liquidity1 calculated above - sqrtPriceCurrent: sqrt5000BigDec, // 5000000000 + liquidity: osmomath.MustNewDecFromStr("1519437308.014768571721000000"), // liquidity1 calculated above + sqrtPriceCurrent: sqrt5000BigDec, // 5000000000 amountRemaining: osmomath.NewBigDec(42000000), // sqrt_next = sqrt_cur + token_in / liq // calculated with x/concentrated-liquidity/python/clmath.py round_decimal(sqrt_next, 36, ROUND_FLOOR) expected: osmomath.MustNewBigDecFromStr("70.738319930382329008049494613660784220"), }, "low price range": { - liquidity: smallLiquidity, + liquidity: smallLiquidity.Dec(), sqrtPriceCurrent: sqrtANearMin, amountRemaining: smallValue, // from clmath decimal import * // get_next_sqrt_price_from_amount1_in_round_down(liq, sqrtPriceA, amountRemaining) - expected: osmomath.MustNewBigDecFromStr("31964936923603.477920799226065501544948016880497639"), + expected: osmomath.MustNewBigDecFromStr("31964941472737.900293161392817774305123129525585219"), }, } - runSqrtRoundingTestCase(t, "TestGetNextSqrtPriceFromAmount1InRoundingDown", math.GetNextSqrtPriceFromAmount1InRoundingDown, tests) + runSqrtRoundingDecTestCase(t, "TestGetNextSqrtPriceFromAmount1InRoundingDown", math.GetNextSqrtPriceFromAmount1InRoundingDown, tests) } func TestGetNextSqrtPriceFromAmount1OutRoundingDown(t *testing.T) { diff --git a/x/concentrated-liquidity/swapstrategy/one_for_zero.go b/x/concentrated-liquidity/swapstrategy/one_for_zero.go index 684445edeeb..7bd454e3268 100644 --- a/x/concentrated-liquidity/swapstrategy/one_for_zero.go +++ b/x/concentrated-liquidity/swapstrategy/one_for_zero.go @@ -77,7 +77,7 @@ func (s oneForZeroStrategy) ComputeSwapWithinBucketOutGivenIn(sqrtPriceCurrent, sqrtPriceNext = sqrtPriceTarget } else { // Otherwise, compute the next sqrt price based on the amount remaining after spread reward. - sqrtPriceNext = math.GetNextSqrtPriceFromAmount1InRoundingDown(sqrtPriceCurrent, liquidityBigDec, amountOneInRemainingLessSpreadReward) + sqrtPriceNext = math.GetNextSqrtPriceFromAmount1InRoundingDown(sqrtPriceCurrent, liquidity, amountOneInRemainingLessSpreadReward) } hasReachedTarget := sqrtPriceTarget.Equal(sqrtPriceNext) From cb0fada2dee8049eb3337d38ff941bfa2fb9c105 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 21:55:12 +0900 Subject: [PATCH 17/27] One more BigDec x Dec op --- osmomath/decimal.go | 13 +++++++++++++ osmomath/decimal_test.go | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/osmomath/decimal.go b/osmomath/decimal.go index 8a6bb380f85..6bc7daa5a6d 100644 --- a/osmomath/decimal.go +++ b/osmomath/decimal.go @@ -489,6 +489,19 @@ func (d BigDec) QuoRoundUp(d2 BigDec) BigDec { return BigDec{chopped} } +// quotient, round up +func (d BigDec) QuoByDecRoundUp(d2 Dec) BigDec { + mul := new(big.Int).Mul(d.i, precisionReuseSDKDec) + + chopped, rem := mul.QuoRem(mul, d2.BigIntMut(), new(big.Int)) + if rem.Sign() > 0 { + chopped.Add(chopped, oneInt) + } + + assertMaxBitLen(chopped) + return BigDec{chopped} +} + // quotient, round up (mutative) func (d BigDec) QuoRoundUpMut(d2 BigDec) BigDec { d.i.Mul(d.i, defaultBigDecPrecisionReuse) diff --git a/osmomath/decimal_test.go b/osmomath/decimal_test.go index 1a67c440b1c..bd86623b1c5 100644 --- a/osmomath/decimal_test.go +++ b/osmomath/decimal_test.go @@ -535,6 +535,11 @@ func (s *decimalTestSuite) TestArithmetic() { s.Require().True(tc.expQuoRoundUp.Equal(resQuoRoundUp), "exp %v, res %v, tc %d", tc.expQuoRoundUp.String(), resQuoRoundUp.String(), tcIndex) + resQuoRoundUpDec := tc.d1.QuoByDecRoundUp(tc.d2.Dec()) + expResQuoRoundUpDec := tc.d1.QuoRoundUp(osmomath.BigDecFromDec(tc.d2.Dec())) + s.Require().True(expResQuoRoundUpDec.Equal(resQuoRoundUpDec), "exp %v, res %v, tc %d", + expResQuoRoundUpDec.String(), resQuoRoundUpDec.String(), tcIndex) + resQuoTruncate := tc.d1.QuoTruncate(tc.d2) s.Require().True(tc.expQuoTruncate.Equal(resQuoTruncate), "exp %v, res %v, tc %d", tc.expQuoTruncate.String(), resQuoTruncate.String(), tcIndex) From 5b391d2a6a79ad2d1364b82da666ccd4a827eb1d Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Apr 2024 13:00:28 +0000 Subject: [PATCH 18/27] Auto: update go.mod after push to dev/speedup_quoroundup that modified dependencies locally --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- osmomath/go.mod | 2 +- osmomath/go.sum | 4 ++-- osmoutils/go.mod | 6 +++--- osmoutils/go.sum | 12 ++++++------ x/epochs/go.mod | 4 ++-- x/epochs/go.sum | 8 ++++---- x/ibc-hooks/go.mod | 4 ++-- x/ibc-hooks/go.sum | 8 ++++---- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index 3f6b67ef53b..9894a0e35a8 100644 --- a/go.mod +++ b/go.mod @@ -30,10 +30,10 @@ require ( github.com/mattn/go-sqlite3 v1.14.17 github.com/ory/dockertest/v3 v3.10.0 github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d - github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411105852-67b62f5e4e2d - github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411105852-67b62f5e4e2d + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411125512-cb0fada2dee8 + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411125512-cb0fada2dee8 + github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411125512-cb0fada2dee8 + github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411125512-cb0fada2dee8 github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 github.com/pkg/errors v0.9.1 github.com/rakyll/statik v0.1.7 diff --git a/go.sum b/go.sum index 588cd322988..ff8c8c784ad 100644 --- a/go.sum +++ b/go.sum @@ -1517,14 +1517,14 @@ github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0c github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:YlmchqTmlwdWSmrRmXKR+PcU96ntOd8u10vTaTZdcNY= github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3/go.mod h1:lV6KnqXYD/ayTe7310MHtM3I2q8Z6bBfMAi+bhwPYtI= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d h1:k3J4VI8QZZF80gF3SJEfYt/HOdCpU3NW4XitM1+vXzE= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d/go.mod h1:dSjXHGer8fQl6Vw8kupk9CvXzKsSWwB2hzMZpgZswWc= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d h1:lwtBMKPEVxDcSUolMzR7+6aveX4zPTlvz5/3waYOquw= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d/go.mod h1:9kSOdruRj1//uuOksPJYh3hxIixtgdPDr81FM0SEORs= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411105852-67b62f5e4e2d h1:2MF97QJkPhso2AfsXkvaVDkxYwUB1CfDeNbnmxFBlFw= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411105852-67b62f5e4e2d/go.mod h1:Dz+CcsgqR3YPCMiKwVntDS/ZUW5LCKfxTQH3Ou0k+gY= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411105852-67b62f5e4e2d h1:Pdly7whBu1L3CYDF+EqdEV20hWgdkRVKPkBOxYJN2aE= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411105852-67b62f5e4e2d/go.mod h1:7mDRJngtcnLVSmkz1rOG53qdSDc1rS0fUqED6zZdG4o= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411125512-cb0fada2dee8 h1:p1jOOamB3IHz5qXeN50KJLEQmNx3PSz5wunNtUrSb4g= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411125512-cb0fada2dee8/go.mod h1:OQj1UyxCyuunzCPuYtbRGTvaL62OIznjQpXqdFDINbs= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411125512-cb0fada2dee8 h1:3BlWDp7ivc+gyjdIPxkcvcDBsATq8s+ZEUD1AxFuDzo= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411125512-cb0fada2dee8/go.mod h1:n41vW6Nr5BmO7jCrdEONyOrJ3PACRcOt/KvhVTrEfjo= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411125512-cb0fada2dee8 h1:/q88xaj3yRcGpFBHnsw/FetvA3f6qa8sKSPx7L12uKw= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411125512-cb0fada2dee8/go.mod h1:9eNG5sUawozrcuYUGhSQlsynneDXXfg7yzy7FnGa1sY= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411125512-cb0fada2dee8 h1:m3zpevamz76sscGFDpc4LzMGE18GCAm0oAZyYtcxok8= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411125512-cb0fada2dee8/go.mod h1:P6eRZizImh4d4nAW9iHYWFcXUJ+SQlRYqXXktlu9tuo= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 h1:mvkk1A/jIe+lsFFpRNfyd9UfvhagATdpnjy8K7kANeo= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04/go.mod h1:mYYf7pYb7sGJ9zYIOw2aYlIl5cgKT0K93rZx4LvDAuA= github.com/osmosis-labs/wasmd v0.45.0-osmo h1:NIp7pvJV5HuBN1HwPgEmXKQM2TjVIVdJErIHnB9IMO8= diff --git a/osmomath/go.mod b/osmomath/go.mod index f70c6cad335..7b57e6858b5 100644 --- a/osmomath/go.mod +++ b/osmomath/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( cosmossdk.io/math v1.3.0 github.com/cosmos/cosmos-sdk v0.47.8 - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411125512-cb0fada2dee8 github.com/stretchr/testify v1.9.0 gopkg.in/yaml.v2 v2.4.0 diff --git a/osmomath/go.sum b/osmomath/go.sum index 606e18a0a22..b81bc915830 100644 --- a/osmomath/go.sum +++ b/osmomath/go.sum @@ -263,8 +263,8 @@ github.com/onsi/gomega v1.28.1 h1:MijcGUbfYuznzK/5R4CPNoUP/9Xvuo20sXfEm6XxoTA= github.com/onsi/gomega v1.28.1/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d h1:lwtBMKPEVxDcSUolMzR7+6aveX4zPTlvz5/3waYOquw= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d/go.mod h1:9kSOdruRj1//uuOksPJYh3hxIixtgdPDr81FM0SEORs= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411125512-cb0fada2dee8 h1:3BlWDp7ivc+gyjdIPxkcvcDBsATq8s+ZEUD1AxFuDzo= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411125512-cb0fada2dee8/go.mod h1:n41vW6Nr5BmO7jCrdEONyOrJ3PACRcOt/KvhVTrEfjo= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= diff --git a/osmoutils/go.mod b/osmoutils/go.mod index aa002b4ef4d..671e734c699 100644 --- a/osmoutils/go.mod +++ b/osmoutils/go.mod @@ -13,7 +13,7 @@ require ( github.com/cosmos/gogoproto v1.4.11 github.com/cosmos/iavl v1.1.2-0.20240405173644-e52f7630d3b7 github.com/cosmos/ibc-go/v7 v7.4.0 - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411125512-cb0fada2dee8 github.com/osmosis-labs/osmosis/v24 v24.0.0-rc0 github.com/spf13/cast v1.6.0 github.com/spf13/cobra v1.8.0 @@ -155,8 +155,8 @@ require ( github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae // indirect github.com/onsi/gomega v1.28.1 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect - github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411105852-67b62f5e4e2d // indirect - github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411105852-67b62f5e4e2d // indirect + github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411125512-cb0fada2dee8 // indirect + github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411125512-cb0fada2dee8 // indirect github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect diff --git a/osmoutils/go.sum b/osmoutils/go.sum index 28fa693d314..60813be4d26 100644 --- a/osmoutils/go.sum +++ b/osmoutils/go.sum @@ -1283,14 +1283,14 @@ github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2 h1:3k4I3zCxdNP+mjhR7AtKr1PPu github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2/go.mod h1:fE+yBeExsJHA35plOZ7FmC/JejO5UdEHNcwO3dj2wc8= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d h1:k3J4VI8QZZF80gF3SJEfYt/HOdCpU3NW4XitM1+vXzE= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d/go.mod h1:dSjXHGer8fQl6Vw8kupk9CvXzKsSWwB2hzMZpgZswWc= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411125512-cb0fada2dee8 h1:p1jOOamB3IHz5qXeN50KJLEQmNx3PSz5wunNtUrSb4g= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411125512-cb0fada2dee8/go.mod h1:OQj1UyxCyuunzCPuYtbRGTvaL62OIznjQpXqdFDINbs= github.com/osmosis-labs/osmosis/v24 v24.0.0-rc0 h1:wAcm5rvcAMwSPFWgzUr/lR7U+e+4PvZ8fkehhpwiJho= github.com/osmosis-labs/osmosis/v24 v24.0.0-rc0/go.mod h1:5QdPU/ttG3dPeg1EtX/LVT7yuxdz3E+BXnEqxwgh+ec= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411105852-67b62f5e4e2d h1:2MF97QJkPhso2AfsXkvaVDkxYwUB1CfDeNbnmxFBlFw= -github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411105852-67b62f5e4e2d/go.mod h1:Dz+CcsgqR3YPCMiKwVntDS/ZUW5LCKfxTQH3Ou0k+gY= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411105852-67b62f5e4e2d h1:Pdly7whBu1L3CYDF+EqdEV20hWgdkRVKPkBOxYJN2aE= -github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411105852-67b62f5e4e2d/go.mod h1:7mDRJngtcnLVSmkz1rOG53qdSDc1rS0fUqED6zZdG4o= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411125512-cb0fada2dee8 h1:/q88xaj3yRcGpFBHnsw/FetvA3f6qa8sKSPx7L12uKw= +github.com/osmosis-labs/osmosis/x/epochs v0.0.8-0.20240411125512-cb0fada2dee8/go.mod h1:9eNG5sUawozrcuYUGhSQlsynneDXXfg7yzy7FnGa1sY= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411125512-cb0fada2dee8 h1:m3zpevamz76sscGFDpc4LzMGE18GCAm0oAZyYtcxok8= +github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.14-0.20240411125512-cb0fada2dee8/go.mod h1:P6eRZizImh4d4nAW9iHYWFcXUJ+SQlRYqXXktlu9tuo= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04 h1:mvkk1A/jIe+lsFFpRNfyd9UfvhagATdpnjy8K7kANeo= github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240404053421-41aab009fb04/go.mod h1:mYYf7pYb7sGJ9zYIOw2aYlIl5cgKT0K93rZx4LvDAuA= github.com/osmosis-labs/wasmd v0.45.0-osmo h1:NIp7pvJV5HuBN1HwPgEmXKQM2TjVIVdJErIHnB9IMO8= diff --git a/x/epochs/go.mod b/x/epochs/go.mod index c7ad59d7bc1..f034453d898 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -9,7 +9,7 @@ require ( github.com/cosmos/gogoproto v1.4.11 github.com/golang/protobuf v1.5.4 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411125512-cb0fada2dee8 github.com/spf13/cobra v1.8.0 github.com/stretchr/testify v1.9.0 golang.org/x/exp v0.0.0-20230905200255-921286631fa9 @@ -111,7 +111,7 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mtibben/percent v0.2.1 // indirect github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae // indirect - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d // indirect + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411125512-cb0fada2dee8 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect github.com/pkg/errors v0.9.1 // indirect diff --git a/x/epochs/go.sum b/x/epochs/go.sum index a64a90a4e7d..947765bbfa2 100644 --- a/x/epochs/go.sum +++ b/x/epochs/go.sum @@ -1224,10 +1224,10 @@ github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2 h1:3k4I3zCxdNP+mjhR7AtKr1PPu github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2/go.mod h1:fE+yBeExsJHA35plOZ7FmC/JejO5UdEHNcwO3dj2wc8= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d h1:k3J4VI8QZZF80gF3SJEfYt/HOdCpU3NW4XitM1+vXzE= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d/go.mod h1:dSjXHGer8fQl6Vw8kupk9CvXzKsSWwB2hzMZpgZswWc= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d h1:lwtBMKPEVxDcSUolMzR7+6aveX4zPTlvz5/3waYOquw= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d/go.mod h1:9kSOdruRj1//uuOksPJYh3hxIixtgdPDr81FM0SEORs= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411125512-cb0fada2dee8 h1:p1jOOamB3IHz5qXeN50KJLEQmNx3PSz5wunNtUrSb4g= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411125512-cb0fada2dee8/go.mod h1:OQj1UyxCyuunzCPuYtbRGTvaL62OIznjQpXqdFDINbs= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411125512-cb0fada2dee8 h1:3BlWDp7ivc+gyjdIPxkcvcDBsATq8s+ZEUD1AxFuDzo= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411125512-cb0fada2dee8/go.mod h1:n41vW6Nr5BmO7jCrdEONyOrJ3PACRcOt/KvhVTrEfjo= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= diff --git a/x/ibc-hooks/go.mod b/x/ibc-hooks/go.mod index f40ad646c2e..bd44b5066bc 100644 --- a/x/ibc-hooks/go.mod +++ b/x/ibc-hooks/go.mod @@ -11,8 +11,8 @@ require ( github.com/cosmos/gogoproto v1.4.11 github.com/cosmos/ibc-go/v7 v7.4.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d - github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d + github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411125512-cb0fada2dee8 + github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411125512-cb0fada2dee8 github.com/spf13/cobra v1.8.0 google.golang.org/grpc v1.62.1 google.golang.org/protobuf v1.33.0 diff --git a/x/ibc-hooks/go.sum b/x/ibc-hooks/go.sum index c80486c28f0..42719c8f03d 100644 --- a/x/ibc-hooks/go.sum +++ b/x/ibc-hooks/go.sum @@ -1239,10 +1239,10 @@ github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2 h1:3k4I3zCxdNP+mjhR7AtKr1PPu github.com/osmosis-labs/cometbft v0.37.4-v24-osmo-2/go.mod h1:fE+yBeExsJHA35plOZ7FmC/JejO5UdEHNcwO3dj2wc8= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5 h1:fnt89Cw+55vbnIEGkpCmj0cx/EaEnwHfYi4JN3rKkLU= github.com/osmosis-labs/cosmos-sdk v0.47.5-v24-osmo-5/go.mod h1:eSRUVYwL3eG1jnh01CnBbHiqOM3xJO49p5rTOrSFX1k= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d h1:k3J4VI8QZZF80gF3SJEfYt/HOdCpU3NW4XitM1+vXzE= -github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411105852-67b62f5e4e2d/go.mod h1:dSjXHGer8fQl6Vw8kupk9CvXzKsSWwB2hzMZpgZswWc= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d h1:lwtBMKPEVxDcSUolMzR7+6aveX4zPTlvz5/3waYOquw= -github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411105852-67b62f5e4e2d/go.mod h1:9kSOdruRj1//uuOksPJYh3hxIixtgdPDr81FM0SEORs= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411125512-cb0fada2dee8 h1:p1jOOamB3IHz5qXeN50KJLEQmNx3PSz5wunNtUrSb4g= +github.com/osmosis-labs/osmosis/osmomath v0.0.12-0.20240411125512-cb0fada2dee8/go.mod h1:OQj1UyxCyuunzCPuYtbRGTvaL62OIznjQpXqdFDINbs= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411125512-cb0fada2dee8 h1:3BlWDp7ivc+gyjdIPxkcvcDBsATq8s+ZEUD1AxFuDzo= +github.com/osmosis-labs/osmosis/osmoutils v0.0.12-0.20240411125512-cb0fada2dee8/go.mod h1:n41vW6Nr5BmO7jCrdEONyOrJ3PACRcOt/KvhVTrEfjo= github.com/osmosis-labs/wasmd v0.45.0-osmo h1:NIp7pvJV5HuBN1HwPgEmXKQM2TjVIVdJErIHnB9IMO8= github.com/osmosis-labs/wasmd v0.45.0-osmo/go.mod h1:J6eRvwii5T1WxhetZkBg1kOJS3GTn1Bw2OLyZBb8EVU= github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= From 6c7846fe31b1faea83060ab1c79ed4808edde8c6 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 22:03:03 +0900 Subject: [PATCH 19/27] Another liq BigDec -> Dec --- x/concentrated-liquidity/math/math.go | 4 ++-- x/concentrated-liquidity/math/math_test.go | 12 ++++++------ .../swapstrategy/zero_for_one.go | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/x/concentrated-liquidity/math/math.go b/x/concentrated-liquidity/math/math.go index b624fa20053..b645e147b8b 100644 --- a/x/concentrated-liquidity/math/math.go +++ b/x/concentrated-liquidity/math/math.go @@ -171,8 +171,8 @@ func GetNextSqrtPriceFromAmount1InRoundingDown(sqrtPriceCurrent osmomath.BigDec, // When we swap for token zero in given token one out, the price is decrearing and we need to move the price down enough // so that we get the desired output amount out. // sqrt_next = sqrt_cur - token_out / liq -func GetNextSqrtPriceFromAmount1OutRoundingDown(sqrtPriceCurrent, liquidity, amountOneRemainingOut osmomath.BigDec) (sqrtPriceNext osmomath.BigDec) { - return sqrtPriceCurrent.Sub(amountOneRemainingOut.QuoRoundUp(liquidity)) +func GetNextSqrtPriceFromAmount1OutRoundingDown(sqrtPriceCurrent osmomath.BigDec, liquidity osmomath.Dec, amountOneRemainingOut osmomath.BigDec) (sqrtPriceNext osmomath.BigDec) { + return sqrtPriceCurrent.Sub(amountOneRemainingOut.QuoByDecRoundUp(liquidity)) } // GetLiquidityFromAmounts takes the current sqrtPrice and the sqrtPrice for the upper and lower ticks as well as the amounts of asset0 and asset1 diff --git a/x/concentrated-liquidity/math/math_test.go b/x/concentrated-liquidity/math/math_test.go index bc1bfb4e3c1..7715fd2e875 100644 --- a/x/concentrated-liquidity/math/math_test.go +++ b/x/concentrated-liquidity/math/math_test.go @@ -612,23 +612,23 @@ func TestGetNextSqrtPriceFromAmount1InRoundingDown(t *testing.T) { } func TestGetNextSqrtPriceFromAmount1OutRoundingDown(t *testing.T) { - tests := map[string]sqrtRoundingTestCase{ + tests := map[string]sqrtRoundingDecTestCase{ "rounded down at precision end": { sqrtPriceCurrent: sqrt5000BigDec, - liquidity: osmomath.MustNewBigDecFromStr("3035764687.503020836176699298"), + liquidity: osmomath.MustNewDecFromStr("3035764687.503020836176699298"), amountRemaining: osmomath.MustNewBigDecFromStr("8398"), // round_osmo_prec_down(sqrtPriceCurrent - round_osmo_prec_up(tokenOut / liquidity)) expected: osmomath.MustNewBigDecFromStr("70.710675352300682056656660729199999832"), }, "no round up due zeroes at precision end": { sqrtPriceCurrent: osmomath.MustNewBigDecFromStr("12.5"), - liquidity: osmomath.MustNewBigDecFromStr("1"), + liquidity: osmomath.MustNewDecFromStr("1"), amountRemaining: osmomath.MustNewBigDecFromStr("10"), // round_osmo_prec_down(sqrtPriceCurrent - round_osmo_prec_up(tokenOut / liquidity)) expected: osmomath.MustNewBigDecFromStr("2.5"), }, "low price range": { - liquidity: smallLiquidity, + liquidity: smallLiquidity.Dec(), sqrtPriceCurrent: sqrtANearMin, amountRemaining: smallValue, // from clmath decimal import * @@ -636,8 +636,8 @@ func TestGetNextSqrtPriceFromAmount1OutRoundingDown(t *testing.T) { // While a negative sqrt price value is invalid and should be caught by the caller, // we mostly focus on testing rounding behavior and math correctness at low spot prices. // For the purposes of our test, this result is acceptable. - expected: osmomath.MustNewBigDecFromStr("-31964936923603.477920799226065453921424417717867010"), + expected: osmomath.MustNewBigDecFromStr("-31964941472737.900293161392817726681599530362954590"), }, } - runSqrtRoundingTestCase(t, "TestGetNextSqrtPriceFromAmount1OutRoundingDown", math.GetNextSqrtPriceFromAmount1OutRoundingDown, tests) + runSqrtRoundingDecTestCase(t, "TestGetNextSqrtPriceFromAmount1OutRoundingDown", math.GetNextSqrtPriceFromAmount1OutRoundingDown, tests) } diff --git a/x/concentrated-liquidity/swapstrategy/zero_for_one.go b/x/concentrated-liquidity/swapstrategy/zero_for_one.go index 33e6a19d939..2fe1bd4902c 100644 --- a/x/concentrated-liquidity/swapstrategy/zero_for_one.go +++ b/x/concentrated-liquidity/swapstrategy/zero_for_one.go @@ -139,7 +139,7 @@ func (s zeroForOneStrategy) ComputeSwapWithinBucketInGivenOut(sqrtPriceCurrent, sqrtPriceNext = sqrtPriceTarget } else { // Otherwise, compute the next sqrt price based on the amount remaining after spread reward. - sqrtPriceNext = math.GetNextSqrtPriceFromAmount1OutRoundingDown(sqrtPriceCurrent, liquidityBigDec, amountOneRemainingOutBigDec) + sqrtPriceNext = math.GetNextSqrtPriceFromAmount1OutRoundingDown(sqrtPriceCurrent, liquidity, amountOneRemainingOutBigDec) } hasReachedTarget := sqrtPriceTarget.Equal(sqrtPriceNext) From 0923f2bdcdafad84e92fbf95740e679764e223b9 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 22:10:34 +0900 Subject: [PATCH 20/27] Missed one step --- x/concentrated-liquidity/swaps_tick_cross_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/concentrated-liquidity/swaps_tick_cross_test.go b/x/concentrated-liquidity/swaps_tick_cross_test.go index 814c1db9082..af6fc07d1c4 100644 --- a/x/concentrated-liquidity/swaps_tick_cross_test.go +++ b/x/concentrated-liquidity/swaps_tick_cross_test.go @@ -1210,7 +1210,7 @@ func (s *KeeperTestSuite) TestSwaps_Contiguous_Initialized_TickSpacingOne() { // Round down since we want to overestimate the change in sqrt price stemming from the amount out going right-to-left // from the current sqrt price. This overestimated value is then used to calculate amount in charged on the user. // Since amount in is overestimated, this done in favor of the pool. - updatedNextCurSqrtPrice := math.GetNextSqrtPriceFromAmount1OutRoundingDown(nextSqrtPrice, liq, amountOutDifference) + updatedNextCurSqrtPrice := math.GetNextSqrtPriceFromAmount1OutRoundingDown(nextSqrtPrice, liq.Dec(), amountOutDifference) // Round up since we want to overestimate the amount in in favor of the pool. return math.CalcAmount0Delta(liq, updatedNextCurSqrtPrice, nextSqrtPrice, true).DecRoundUp(), updatedNextCurSqrtPrice } From ed9072db11f90fd6168e109a0a867df6451e0deb Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 22:24:56 +0900 Subject: [PATCH 21/27] Move another Liquidity BigDec -> Dec --- x/concentrated-liquidity/incentives_test.go | 2 +- x/concentrated-liquidity/math/math.go | 6 ++--- x/concentrated-liquidity/math/math_test.go | 22 +++++++++---------- x/concentrated-liquidity/model/pool.go | 4 ++-- x/concentrated-liquidity/model/pool_test.go | 8 +++---- x/concentrated-liquidity/position_test.go | 2 +- .../swaps_tick_cross_test.go | 12 +++++----- .../swapstrategy/one_for_zero.go | 6 ++--- .../swapstrategy/zero_for_one.go | 6 ++--- 9 files changed, 34 insertions(+), 34 deletions(-) diff --git a/x/concentrated-liquidity/incentives_test.go b/x/concentrated-liquidity/incentives_test.go index f61a92cc7ea..21c38bf6be5 100644 --- a/x/concentrated-liquidity/incentives_test.go +++ b/x/concentrated-liquidity/incentives_test.go @@ -3674,7 +3674,7 @@ func (s *KeeperTestSuite) TestIncentiveTruncation() { desiredCurrentSqrtPrice, err := math.TickToSqrtPrice(desiredCurrentTick) s.Require().NoError(err) - amount0 := math.CalcAmount0Delta(desiredLiquidity, desiredCurrentSqrtPrice, types.MaxSqrtPriceBigDec, true).Dec().TruncateInt() + amount0 := math.CalcAmount0Delta(desiredLiquidity.Dec(), desiredCurrentSqrtPrice, types.MaxSqrtPriceBigDec, true).Dec().TruncateInt() amount1 := math.CalcAmount1Delta(desiredLiquidity, types.MinSqrtPriceBigDec, desiredCurrentSqrtPrice, true).Dec().TruncateInt() lpCoins := sdk.NewCoins(sdk.NewCoin(ETH, amount0), sdk.NewCoin(USDC, amount1)) diff --git a/x/concentrated-liquidity/math/math.go b/x/concentrated-liquidity/math/math.go index b645e147b8b..d4bcaa5aef8 100644 --- a/x/concentrated-liquidity/math/math.go +++ b/x/concentrated-liquidity/math/math.go @@ -57,7 +57,7 @@ func Liquidity1(amount osmomath.Int, sqrtPriceA, sqrtPriceB osmomath.BigDec) osm // sqrtPriceA is the smaller of sqrtpCur and the nextPrice // sqrtPriceB is the larger of sqrtpCur and the nextPrice // CalcAmount0Delta = (liquidity * (sqrtPriceB - sqrtPriceA)) / (sqrtPriceB * sqrtPriceA) -func CalcAmount0Delta(liq, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) osmomath.BigDec { +func CalcAmount0Delta(liq osmomath.Dec, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) osmomath.BigDec { if sqrtPriceA.GT(sqrtPriceB) { sqrtPriceA, sqrtPriceB = sqrtPriceB, sqrtPriceA } @@ -81,7 +81,7 @@ func CalcAmount0Delta(liq, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) // This leads to a smaller error amplification. This only matters in cases where at least one of the sqrt prices is below 1. // TODO (perf): Don't truncate after liq.MulRoundUp(diff), we actually scale by that in the next Quo. ALT: Switch liq to Dec // TODO (perf): QuoRoundUpMut with no reallocation for internal scratch var. - return diff.MulRoundUp(liq).QuoRoundUpMut(sqrtPriceB).QuoRoundUpNextIntMut(sqrtPriceA) + return diff.MulRoundUpDec(liq).QuoRoundUpMut(sqrtPriceB).QuoRoundUpNextIntMut(sqrtPriceA) } // These are truncated at precision end to round in favor of the pool when: // - calculating amount out during swap @@ -89,7 +89,7 @@ func CalcAmount0Delta(liq, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) // Each intermediary step is truncated at precision end to get a smaller final amount. // Note that the order of divisions is important here. First, we divide by a larger number (sqrtPriceB) and then by a smaller number (sqrtPriceA). // This leads to a smaller error amplification. - return diff.MulTruncate(liq).QuoTruncateMut(sqrtPriceB).QuoTruncateMut(sqrtPriceA) + return diff.MulTruncateDec(liq).QuoTruncateMut(sqrtPriceB).QuoTruncateMut(sqrtPriceA) } // CalcAmount1Delta takes the asset with the smaller liquidity in the pool as well as the sqrtpCur and the nextPrice and calculates the amount of asset 1 diff --git a/x/concentrated-liquidity/math/math_test.go b/x/concentrated-liquidity/math/math_test.go index 7715fd2e875..2b00b91c2f4 100644 --- a/x/concentrated-liquidity/math/math_test.go +++ b/x/concentrated-liquidity/math/math_test.go @@ -124,7 +124,7 @@ func TestLiquidity0(t *testing.T) { // calcAmount0Delta = (liquidity * (sqrtPriceB - sqrtPriceA)) / (sqrtPriceB * sqrtPriceA) func TestCalcAmount0Delta(t *testing.T) { testCases := map[string]struct { - liquidity osmomath.BigDec + liquidity osmomath.Dec sqrtPA osmomath.BigDec sqrtPB osmomath.BigDec isWithTolerance bool @@ -132,16 +132,16 @@ func TestCalcAmount0Delta(t *testing.T) { amount0Expected osmomath.BigDec }{ "happy path": { - liquidity: osmomath.MustNewBigDecFromStr("1517882343.751510418088349649"), // we use the smaller liquidity between liq0 and liq1 - sqrtPA: sqrt5000BigDec, // 5000 - sqrtPB: sqrt5500BigDec, // 5500 + liquidity: osmomath.MustNewDecFromStr("1517882343.751510418088349649"), // we use the smaller liquidity between liq0 and liq1 + sqrtPA: sqrt5000BigDec, // 5000 + sqrtPB: sqrt5500BigDec, // 5500 roundUp: false, // calculated with x/concentrated-liquidity/python/clmath.py round_decimal(amount0, 36, ROUND_FLOOR) amount0Expected: osmomath.MustNewBigDecFromStr("998976.618347426388356629926969277767437533"), // truncated at precision end. isWithTolerance: false, }, "happy path, sqrtPriceA greater than sqrtPrice B": { // commute prior vector - liquidity: osmomath.MustNewBigDecFromStr("1517882343.751510418088349649"), + liquidity: osmomath.MustNewDecFromStr("1517882343.751510418088349649"), sqrtPA: sqrt5500BigDec, sqrtPB: sqrt5000BigDec, roundUp: false, @@ -160,7 +160,7 @@ func TestCalcAmount0Delta(t *testing.T) { // min_sqrt_p = Decimal("0.000000152731791058") // liq = Decimal("931361973132462178951297") // liq * (max_sqrt_p - min_sqrt_p) / (max_sqrt_p * min_sqrt_p) - liquidity: osmomath.MustNewBigDecFromStr("931361973132462178951297"), + liquidity: osmomath.MustNewDecFromStr("931361973132462178951297"), // price: 0.000000000000023327 sqrtPA: osmomath.MustNewBigDecFromStr("0.000000152731791058"), // price: 952361284325389721913 @@ -181,7 +181,7 @@ func TestCalcAmount0Delta(t *testing.T) { // min_sqrt_p = Decimal("0.000000152731791058") // liq = Decimal("931361973132462178951297") // liq * (max_sqrt_p - min_sqrt_p) / (max_sqrt_p * min_sqrt_p) - liquidity: osmomath.MustNewBigDecFromStr("931361973132462178951297"), + liquidity: osmomath.MustNewDecFromStr("931361973132462178951297"), // price: 0.000000000000023327 sqrtPA: osmomath.MustNewBigDecFromStr("0.000000152731791058"), // price: 952361284325389721913 @@ -200,7 +200,7 @@ func TestCalcAmount0Delta(t *testing.T) { // min_sqrt_p = Decimal("0.000000000000001409841835100661211756") // liq = Decimal("5000252259822539816806336.971796256914465071095518135400579243") // liq * (max_sqrt_p - min_sqrt_p) / (max_sqrt_p * min_sqrt_p) - liquidity: osmomath.MustNewBigDecFromStr("5000252259822539816806336.971796256914465071095518135400579243"), + liquidity: osmomath.MustNewDecFromStr("5000252259822539816806336.971796256914465071"), sqrtPA: osmomath.MustNewBigDecFromStr("0.00000099994999874993749609347654199"), sqrtPB: osmomath.MustNewBigDecFromStr("0.000000000000001409841835100661211756"), roundUp: true, @@ -216,7 +216,7 @@ func TestCalcAmount0Delta(t *testing.T) { // min_sqrt_p = Decimal("0.000000000000001409841835100661211756") // liq = Decimal("5000252259822539816806336.971796256914465071095518135400579243") // liq * (max_sqrt_p - min_sqrt_p) / (max_sqrt_p * min_sqrt_p) - liquidity: osmomath.MustNewBigDecFromStr("5000252259822539816806336.971796256914465071095518135400579243"), + liquidity: osmomath.MustNewDecFromStr("5000252259822539816806336.971796256914465071"), sqrtPA: osmomath.MustNewBigDecFromStr("0.00000099994999874993749609347654199"), sqrtPB: osmomath.MustNewBigDecFromStr("0.000000000000001409841835100661211756"), roundUp: false, @@ -224,14 +224,14 @@ func TestCalcAmount0Delta(t *testing.T) { amount0Expected: osmomath.MustNewBigDecFromStr("3546676037185128488234786333758360815266.999539026068480181194797910898392880"), }, "low price range": { - liquidity: smallLiquidity, + liquidity: smallLiquidity.Dec(), sqrtPA: sqrtANearMin, sqrtPB: sqrtBNearMin, roundUp: false, // from clmath decimal import * // from math import * // calc_amount_zero_delta(liq, sqrtPriceA, sqrtPriceB, False) - amount0Expected: osmomath.MustNewBigDecFromStr("12399.405290456300691064448232516066947340"), + amount0Expected: osmomath.MustNewBigDecFromStr("12399.403617882634341191547243098659145924"), }, } diff --git a/x/concentrated-liquidity/model/pool.go b/x/concentrated-liquidity/model/pool.go index 556a6a9c175..aa209237633 100644 --- a/x/concentrated-liquidity/model/pool.go +++ b/x/concentrated-liquidity/model/pool.go @@ -256,13 +256,13 @@ func (p Pool) CalcActualAmounts(ctx sdk.Context, lowerTick, upperTick int64, liq // if this is the case, we attempt to provide liquidity evenly between asset0 and asset1 // we also update the pool liquidity since the virtual liquidity is modified by this position's creation currentSqrtPrice := p.CurrentSqrtPrice - actualAmountDenom0 = math.CalcAmount0Delta(liquidityDeltaBigDec, currentSqrtPrice, sqrtPriceUpperTick, roundUp) + actualAmountDenom0 = math.CalcAmount0Delta(liquidityDelta, currentSqrtPrice, sqrtPriceUpperTick, roundUp) actualAmountDenom1 = math.CalcAmount1Delta(liquidityDeltaBigDec, currentSqrtPrice, sqrtPriceLowerTick, roundUp) } else if p.CurrentTick < lowerTick { // outcome two: position is below current price // this means position is solely made up of asset0 actualAmountDenom1 = osmomath.ZeroBigDec() - actualAmountDenom0 = math.CalcAmount0Delta(liquidityDeltaBigDec, sqrtPriceLowerTick, sqrtPriceUpperTick, roundUp) + actualAmountDenom0 = math.CalcAmount0Delta(liquidityDelta, sqrtPriceLowerTick, sqrtPriceUpperTick, roundUp) } else { // outcome three: position is above current price // this means position is solely made up of asset1 diff --git a/x/concentrated-liquidity/model/pool_test.go b/x/concentrated-liquidity/model/pool_test.go index 09dff9df73c..e075202b1a1 100644 --- a/x/concentrated-liquidity/model/pool_test.go +++ b/x/concentrated-liquidity/model/pool_test.go @@ -605,7 +605,7 @@ func (suite *ConcentratedPoolTestSuite) TestCalcActualAmounts() { liquidityDelta: defaultLiquidityDelta, shouldTestRoundingInvariant: true, - expectedAmount0: clmath.CalcAmount0Delta(defaultLiquidityDeltaBigDec, midSqrtPriceBigDec, upperSqrtPriceBigDec, true).Dec(), + expectedAmount0: clmath.CalcAmount0Delta(defaultLiquidityDelta, midSqrtPriceBigDec, upperSqrtPriceBigDec, true).Dec(), expectedAmount1: clmath.CalcAmount1Delta(defaultLiquidityDeltaBigDec, midSqrtPriceBigDec, lowerSqrtPriceBigDec, true).Dec(), }, "current in range, negative liquidity": { @@ -614,7 +614,7 @@ func (suite *ConcentratedPoolTestSuite) TestCalcActualAmounts() { upperTick: uppertick, liquidityDelta: defaultLiquidityDelta.Neg(), - expectedAmount0: clmath.CalcAmount0Delta(defaultLiquidityDeltaBigDec.Neg(), midSqrtPriceBigDec, upperSqrtPriceBigDec, false).Dec(), + expectedAmount0: clmath.CalcAmount0Delta(defaultLiquidityDelta.Neg(), midSqrtPriceBigDec, upperSqrtPriceBigDec, false).Dec(), expectedAmount1: clmath.CalcAmount1Delta(defaultLiquidityDeltaBigDec.Neg(), midSqrtPriceBigDec, lowerSqrtPriceBigDec, false).Dec(), }, "current below range, positive liquidity": { @@ -623,7 +623,7 @@ func (suite *ConcentratedPoolTestSuite) TestCalcActualAmounts() { upperTick: uppertick, liquidityDelta: defaultLiquidityDelta, - expectedAmount0: clmath.CalcAmount0Delta(defaultLiquidityDeltaBigDec, midSqrtPriceBigDec, upperSqrtPriceBigDec, true).Dec(), + expectedAmount0: clmath.CalcAmount0Delta(defaultLiquidityDelta, midSqrtPriceBigDec, upperSqrtPriceBigDec, true).Dec(), expectedAmount1: osmomath.ZeroDec(), }, "current below range, negative liquidity": { @@ -632,7 +632,7 @@ func (suite *ConcentratedPoolTestSuite) TestCalcActualAmounts() { upperTick: uppertick, liquidityDelta: defaultLiquidityDelta.Neg(), - expectedAmount0: clmath.CalcAmount0Delta(defaultLiquidityDeltaBigDec.Neg(), midSqrtPriceBigDec, upperSqrtPriceBigDec, false).Dec(), + expectedAmount0: clmath.CalcAmount0Delta(defaultLiquidityDelta.Neg(), midSqrtPriceBigDec, upperSqrtPriceBigDec, false).Dec(), expectedAmount1: osmomath.ZeroDec(), }, "current above range, positive liquidity": { diff --git a/x/concentrated-liquidity/position_test.go b/x/concentrated-liquidity/position_test.go index e7ffdd71d0c..ae211bb6f6b 100644 --- a/x/concentrated-liquidity/position_test.go +++ b/x/concentrated-liquidity/position_test.go @@ -2038,7 +2038,7 @@ func (s *KeeperTestSuite) TestNegativeTickRange_SpreadFactor() { s.Require().True(toTick < pool.GetCurrentTick()) - amountZeroIn := math.CalcAmount0Delta(osmomath.BigDecFromDec(pool.GetLiquidity()), pool.GetCurrentSqrtPrice(), s.tickToSqrtPrice(toTick), true) + amountZeroIn := math.CalcAmount0Delta(pool.GetLiquidity(), pool.GetCurrentSqrtPrice(), s.tickToSqrtPrice(toTick), true) coinZeroIn := sdk.NewCoin(denom0, amountZeroIn.Dec().TruncateInt()) return coinZeroIn diff --git a/x/concentrated-liquidity/swaps_tick_cross_test.go b/x/concentrated-liquidity/swaps_tick_cross_test.go index af6fc07d1c4..dd47718896b 100644 --- a/x/concentrated-liquidity/swaps_tick_cross_test.go +++ b/x/concentrated-liquidity/swaps_tick_cross_test.go @@ -293,7 +293,7 @@ func (s *KeeperTestSuite) computeSwapAmounts(poolId uint64, curSqrtPrice osmomat var isWithinDesiredBucketAfterSwap bool if isZeroForOne { // Round up so that we cross the tick by default. - curAmountIn := math.CalcAmount0Delta(osmomath.BigDecFromDec(currentLiquidity), curSqrtPrice, nextInitTickSqrtPrice, true).DecRoundUp() + curAmountIn := math.CalcAmount0Delta(currentLiquidity, curSqrtPrice, nextInitTickSqrtPrice, true).DecRoundUp() amountIn = amountIn.Add(curAmountIn) @@ -316,7 +316,7 @@ func (s *KeeperTestSuite) computeSwapAmounts(poolId uint64, curSqrtPrice osmomat nextInitTickSqrtPrice := s.tickToSqrtPrice(liquidityNetAmounts[i+1].TickIndex) // We discount by half so that we do no cross any tick and remain in the same bucket. - curAmountIn := math.CalcAmount0Delta(osmomath.BigDecFromDec(currentLiquidity), curSqrtPrice, nextInitTickSqrtPrice, true).QuoInt64(2).DecRoundUp() + curAmountIn := math.CalcAmount0Delta(currentLiquidity, curSqrtPrice, nextInitTickSqrtPrice, true).QuoInt64(2).DecRoundUp() amountIn = amountIn.Add(curAmountIn) } } else { @@ -409,7 +409,7 @@ func (s *KeeperTestSuite) computeSwapAmountsInGivenOut(poolId uint64, curSqrtPri } } else { // Round up so that we cross the tick by default. - curAmountOut := math.CalcAmount0Delta(currentLiquidity, curSqrtPrice, nextInitTickSqrtPrice, false) + curAmountOut := math.CalcAmount0Delta(currentLiquidity.Dec(), curSqrtPrice, nextInitTickSqrtPrice, false) amountOut = amountOut.Add(curAmountOut.Dec()) // The tick should be crossed if currentTick <= expectedTickToSwapTo, unless the intention @@ -643,7 +643,7 @@ func (s *KeeperTestSuite) TestSwapOutGivenIn_Tick_Initialization_And_Crossing() if tickToSwapTo < nr1Position.lowerTick { sqrtPriceLowerTickOne := s.tickToSqrtPrice(nr1Position.lowerTick) - amountZeroIn = math.CalcAmount0Delta(osmomath.BigDecFromDec(liquidity), sqrtPriceLowerTickOne, sqrtPriceStart, true).Dec() + amountZeroIn = math.CalcAmount0Delta(liquidity, sqrtPriceLowerTickOne, sqrtPriceStart, true).Dec() sqrtPriceStart = sqrtPriceLowerTickOne @@ -652,7 +652,7 @@ func (s *KeeperTestSuite) TestSwapOutGivenIn_Tick_Initialization_And_Crossing() // This is the total amount necessary to cross the lower tick of narrow position. // Note it is rounded up to ensure that the tick is crossed. - amountZeroIn = math.CalcAmount0Delta(osmomath.BigDecFromDec(liquidity), sqrtPriceTarget, sqrtPriceStart, true).DecRoundUp().Add(amountZeroIn) + amountZeroIn = math.CalcAmount0Delta(liquidity, sqrtPriceTarget, sqrtPriceStart, true).DecRoundUp().Add(amountZeroIn) tokenZeroIn := sdk.NewCoin(pool.GetToken0(), amountZeroIn.Ceil().TruncateInt()) @@ -1212,7 +1212,7 @@ func (s *KeeperTestSuite) TestSwaps_Contiguous_Initialized_TickSpacingOne() { // Since amount in is overestimated, this done in favor of the pool. updatedNextCurSqrtPrice := math.GetNextSqrtPriceFromAmount1OutRoundingDown(nextSqrtPrice, liq.Dec(), amountOutDifference) // Round up since we want to overestimate the amount in in favor of the pool. - return math.CalcAmount0Delta(liq, updatedNextCurSqrtPrice, nextSqrtPrice, true).DecRoundUp(), updatedNextCurSqrtPrice + return math.CalcAmount0Delta(liq.Dec(), updatedNextCurSqrtPrice, nextSqrtPrice, true).DecRoundUp(), updatedNextCurSqrtPrice } // Round up since we want to overestimate the change in sqrt price stemming from the amount out going left-to-right diff --git a/x/concentrated-liquidity/swapstrategy/one_for_zero.go b/x/concentrated-liquidity/swapstrategy/one_for_zero.go index 7bd454e3268..86a63402767 100644 --- a/x/concentrated-liquidity/swapstrategy/one_for_zero.go +++ b/x/concentrated-liquidity/swapstrategy/one_for_zero.go @@ -90,7 +90,7 @@ func (s oneForZeroStrategy) ComputeSwapWithinBucketOutGivenIn(sqrtPriceCurrent, } // Calculate the amount of the other token given the sqrt price range. - amountZeroOut := math.CalcAmount0Delta(liquidityBigDec, sqrtPriceNext, sqrtPriceCurrent, false) + amountZeroOut := math.CalcAmount0Delta(liquidity, sqrtPriceNext, sqrtPriceCurrent, false) // Round up to charge user more in pool's favor. amountInDecFinal := amountOneIn.DecRoundUp() @@ -129,7 +129,7 @@ func (s oneForZeroStrategy) ComputeSwapWithinBucketInGivenOut(sqrtPriceCurrent, // Estimate the amount of token zero needed until the target sqrt price is reached. // N.B.: contrary to out given in, we do not round up because we do not want to exceed the initial amount out at the end. - amountZeroOut := math.CalcAmount0Delta(liquidityBigDec, sqrtPriceTarget, sqrtPriceCurrent, false) + amountZeroOut := math.CalcAmount0Delta(liquidity, sqrtPriceTarget, sqrtPriceCurrent, false) // Calculate sqrtPriceNext on the amount of token remaining. Note that the // spread reward is not charged as amountRemaining is amountOut, and we only charge spread reward on @@ -151,7 +151,7 @@ func (s oneForZeroStrategy) ComputeSwapWithinBucketInGivenOut(sqrtPriceCurrent, // current swap step. if !hasReachedTarget { // N.B.: contrary to out given in, we do not round up because we do not want to exceed the initial amount out at the end. - amountZeroOut = math.CalcAmount0Delta(liquidityBigDec, sqrtPriceNext, sqrtPriceCurrent, false) + amountZeroOut = math.CalcAmount0Delta(liquidity, sqrtPriceNext, sqrtPriceCurrent, false) } // Calculate the amount of the other token given the sqrt price range. diff --git a/x/concentrated-liquidity/swapstrategy/zero_for_one.go b/x/concentrated-liquidity/swapstrategy/zero_for_one.go index 2fe1bd4902c..6ce281e368d 100644 --- a/x/concentrated-liquidity/swapstrategy/zero_for_one.go +++ b/x/concentrated-liquidity/swapstrategy/zero_for_one.go @@ -63,7 +63,7 @@ func (s zeroForOneStrategy) ComputeSwapWithinBucketOutGivenIn(sqrtPriceCurrent, liquidityBigDec := osmomath.BigDecFromDec(liquidity) // Estimate the amount of token zero needed until the target sqrt price is reached. - amountZeroIn := math.CalcAmount0Delta(liquidityBigDec, sqrtPriceTarget, sqrtPriceCurrent, true) // N.B.: if this is false, causes infinite loop + amountZeroIn := math.CalcAmount0Delta(liquidity, sqrtPriceTarget, sqrtPriceCurrent, true) // N.B.: if this is false, causes infinite loop // Calculate sqrtPriceNext on the amount of token remaining after spread reward. oneMinusTakerFee := oneDec.Sub(s.spreadFactor) @@ -85,7 +85,7 @@ func (s zeroForOneStrategy) ComputeSwapWithinBucketOutGivenIn(sqrtPriceCurrent, // to complete the swap step. This implies that some of the amount remaining after spread reward is left over after the // current swap step. if !hasReachedTarget { - amountZeroIn = math.CalcAmount0Delta(liquidityBigDec, sqrtPriceNext, sqrtPriceCurrent, true) // N.B.: if this is false, causes infinite loop + amountZeroIn = math.CalcAmount0Delta(liquidity, sqrtPriceNext, sqrtPriceCurrent, true) // N.B.: if this is false, causes infinite loop } // Calculate the amount of the other token given the sqrt price range. @@ -152,7 +152,7 @@ func (s zeroForOneStrategy) ComputeSwapWithinBucketInGivenOut(sqrtPriceCurrent, } // Calculate the amount of the other token given the sqrt price range. - amountZeroIn := math.CalcAmount0Delta(liquidityBigDec, sqrtPriceNext, sqrtPriceCurrent, true) + amountZeroIn := math.CalcAmount0Delta(liquidity, sqrtPriceNext, sqrtPriceCurrent, true) // Round up to charge user more in pool's favor. amountZeroInFinal := amountZeroIn.DecRoundUp() From bca4a54ac5d69f62086bff8840ae61242b796669 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 23:12:23 +0900 Subject: [PATCH 22/27] Minor spread reward update --- .../swapstrategy/spread_rewards.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/x/concentrated-liquidity/swapstrategy/spread_rewards.go b/x/concentrated-liquidity/swapstrategy/spread_rewards.go index a99e31d894a..47d8b3b54ba 100644 --- a/x/concentrated-liquidity/swapstrategy/spread_rewards.go +++ b/x/concentrated-liquidity/swapstrategy/spread_rewards.go @@ -23,17 +23,14 @@ import ( // If spread factor is negative, it panics. // If spread factor is 0, returns 0. Otherwise, computes and returns the spread factor charge per step. func computeSpreadRewardChargePerSwapStepOutGivenIn(hasReachedTarget bool, amountIn, amountSpecifiedRemaining, spreadFactor osmomath.Dec) osmomath.Dec { - spreadRewardChargeTotal := osmomath.ZeroDec() - - if spreadFactor.IsNegative() { + if spreadFactor.IsZero() { + return osmomath.ZeroDec() + } else if spreadFactor.IsNegative() { // This should never happen but is added as a defense-in-depth measure. panic(fmt.Errorf("spread factor must be non-negative, was (%s)", spreadFactor)) } - if spreadFactor.IsZero() { - return spreadRewardChargeTotal - } - + var spreadRewardChargeTotal osmomath.Dec if hasReachedTarget { // This branch implies two options: // 1) either sqrtPriceNextTick is reached @@ -61,6 +58,7 @@ func computeSpreadRewardChargePerSwapStepOutGivenIn(hasReachedTarget bool, amoun // Computes amountIn * spreadFactor / (1 - spreadFactor) where math operations round up // at precision end. This is necessary to ensure that the spread factor charge is always // rounded in favor of the pool. +// TODO: Change this fn to take in 1 - spreadFactor as it should already have been computed. func computeSpreadRewardChargeFromAmountIn(amountIn osmomath.Dec, spreadFactor osmomath.Dec) osmomath.Dec { return amountIn.MulRoundUp(spreadFactor).QuoRoundupMut(osmomath.OneDec().SubMut(spreadFactor)) } From 2b75b79bd9de3685d850859848842ff204f9fc90 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 11 Apr 2024 23:32:40 +0900 Subject: [PATCH 23/27] Make CalcAmount1Dec use Dec for Liquidity --- x/concentrated-liquidity/incentives_test.go | 2 +- x/concentrated-liquidity/math/math.go | 7 +++--- x/concentrated-liquidity/math/math_test.go | 22 ++++++++--------- x/concentrated-liquidity/model/pool.go | 9 ++++--- x/concentrated-liquidity/model/pool_test.go | 11 ++++----- x/concentrated-liquidity/position_test.go | 2 +- .../swaps_tick_cross_test.go | 24 ++++++++++--------- .../swapstrategy/one_for_zero.go | 9 +++---- .../swapstrategy/zero_for_one.go | 7 +++--- 9 files changed, 45 insertions(+), 48 deletions(-) diff --git a/x/concentrated-liquidity/incentives_test.go b/x/concentrated-liquidity/incentives_test.go index 21c38bf6be5..b460a1ec70b 100644 --- a/x/concentrated-liquidity/incentives_test.go +++ b/x/concentrated-liquidity/incentives_test.go @@ -3675,7 +3675,7 @@ func (s *KeeperTestSuite) TestIncentiveTruncation() { s.Require().NoError(err) amount0 := math.CalcAmount0Delta(desiredLiquidity.Dec(), desiredCurrentSqrtPrice, types.MaxSqrtPriceBigDec, true).Dec().TruncateInt() - amount1 := math.CalcAmount1Delta(desiredLiquidity, types.MinSqrtPriceBigDec, desiredCurrentSqrtPrice, true).Dec().TruncateInt() + amount1 := math.CalcAmount1Delta(desiredLiquidity.Dec(), types.MinSqrtPriceBigDec, desiredCurrentSqrtPrice, true).Dec().TruncateInt() lpCoins := sdk.NewCoins(sdk.NewCoin(ETH, amount0), sdk.NewCoin(USDC, amount1)) s.FundAcc(s.TestAccs[0], lpCoins) diff --git a/x/concentrated-liquidity/math/math.go b/x/concentrated-liquidity/math/math.go index d4bcaa5aef8..ff6d31e8af8 100644 --- a/x/concentrated-liquidity/math/math.go +++ b/x/concentrated-liquidity/math/math.go @@ -96,7 +96,7 @@ func CalcAmount0Delta(liq osmomath.Dec, sqrtPriceA, sqrtPriceB osmomath.BigDec, // sqrtPriceA is the smaller of sqrtpCur and the nextPrice // sqrtPriceB is the larger of sqrtpCur and the nextPrice // CalcAmount1Delta = liq * (sqrtPriceB - sqrtPriceA) -func CalcAmount1Delta(liq, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) osmomath.BigDec { +func CalcAmount1Delta(liq osmomath.Dec, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) osmomath.BigDec { diff := sqrtPriceB.Sub(sqrtPriceA).AbsMut() // if calculating for amountIn, we round up // if calculating for amountOut, we don't round at all @@ -111,13 +111,14 @@ func CalcAmount1Delta(liq, sqrtPriceA, sqrtPriceB osmomath.BigDec, roundUp bool) // Examples include: // - calculating amountIn during swap // - adding liquidity (request user to provide more tokens in in favor of the pool) - return diff.MulMut(liq).CeilMut() + // TODO: Make a MulDecCeilMut to save more internal ops + return diff.MulDecMut(liq).CeilMut() } // This is truncated at precision end to round in favor of the pool when: // - calculating amount out during swap // - withdrawing liquidity // The denominator is rounded up to get a higher final amount. - return diff.MulTruncate(liq) + return diff.MulTruncateDec(liq) } // GetNextSqrtPriceFromAmount0InRoundingUp utilizes sqrtPriceCurrent, liquidity, and amount of denom0 that still needs diff --git a/x/concentrated-liquidity/math/math_test.go b/x/concentrated-liquidity/math/math_test.go index 2b00b91c2f4..214ca3c33e4 100644 --- a/x/concentrated-liquidity/math/math_test.go +++ b/x/concentrated-liquidity/math/math_test.go @@ -267,7 +267,7 @@ func TestCalcAmount0Delta(t *testing.T) { // calcAmount1Delta = liq * (sqrtPriceB - sqrtPriceA) func TestCalcAmount1Delta(t *testing.T) { testCases := map[string]struct { - liquidity osmomath.BigDec + liquidity osmomath.Dec sqrtPA osmomath.BigDec sqrtPB osmomath.BigDec exactEqual bool @@ -275,9 +275,9 @@ func TestCalcAmount1Delta(t *testing.T) { amount1Expected osmomath.BigDec }{ "round down": { - liquidity: osmomath.MustNewBigDecFromStr("1517882343.751510418088349649"), // we use the smaller liquidity between liq0 and liq1 - sqrtPA: sqrt5000BigDec, // 5000 - sqrtPB: sqrt4545BigDec, // 4545 + liquidity: osmomath.MustNewDecFromStr("1517882343.751510418088349649"), // we use the smaller liquidity between liq0 and liq1 + sqrtPA: sqrt5000BigDec, // 5000 + sqrtPB: sqrt4545BigDec, // 4545 roundUp: false, // calculated with x/concentrated-liquidity/python/clmath.py amount1Expected: osmomath.MustNewBigDecFromStr("4999999999.999999999999999999696837821702147054"), @@ -292,7 +292,7 @@ func TestCalcAmount1Delta(t *testing.T) { // min_sqrt_p = Decimal("0.000000152731791058") // liq = Decimal("931361973132462178951297") // liq * (max_sqrt_p - min_sqrt_p) - liquidity: osmomath.MustNewBigDecFromStr("931361973132462178951297"), + liquidity: osmomath.MustNewDecFromStr("931361973132462178951297"), // price: 0.000000000000023327 sqrtPA: osmomath.MustNewBigDecFromStr("0.000000152731791058"), // price: 952361284325389721913 @@ -311,7 +311,7 @@ func TestCalcAmount1Delta(t *testing.T) { // min_sqrt_p = Decimal("0.000000152731791058") // liq = Decimal("931361973132462178951297") // liq * (max_sqrt_p - min_sqrt_p) - liquidity: osmomath.MustNewBigDecFromStr("931361973132462178951297"), + liquidity: osmomath.MustNewDecFromStr("931361973132462178951297"), // price: 0.000000000000023327 sqrtPA: osmomath.MustNewBigDecFromStr("0.000000152731791058"), // price: 952361284325389721913 @@ -320,24 +320,24 @@ func TestCalcAmount1Delta(t *testing.T) { amount1Expected: osmomath.MustNewBigDecFromStr("28742157707995443393876876754535992.801567623738751734").Ceil(), // round up at precision end. }, "low price range (no round up)": { - liquidity: smallLiquidity, + liquidity: smallLiquidity.Dec(), sqrtPA: sqrtANearMin, sqrtPB: sqrtBNearMin, roundUp: false, // from clmath decimal import * // from math import * // calc_amount_one_delta(liq, sqrtPriceA, sqrtPriceB, False) - amount1Expected: osmomath.MustNewBigDecFromStr("0.000000000000000000000000000103787162"), + amount1Expected: osmomath.MustNewBigDecFromStr("0.000000000000000000000000000103787148"), }, "low price range (with round up)": { - liquidity: smallLiquidity, + liquidity: smallLiquidity.Dec(), sqrtPA: sqrtANearMin, sqrtPB: sqrtBNearMin, roundUp: true, // from clmath decimal import * // calc_amount_one_delta(liq, sqrtPriceA, sqrtPriceB, False) - // Actual result: 0.000000000000000000000000000103787163 - amount1Expected: osmomath.MustNewBigDecFromStr("0.000000000000000000000000000103787163").Ceil(), + // Actual result: 0.000000000000000000000000000103787149 + amount1Expected: osmomath.MustNewBigDecFromStr("0.000000000000000000000000000103787149").Ceil(), }, } diff --git a/x/concentrated-liquidity/model/pool.go b/x/concentrated-liquidity/model/pool.go index aa209237633..e58d29039b8 100644 --- a/x/concentrated-liquidity/model/pool.go +++ b/x/concentrated-liquidity/model/pool.go @@ -246,9 +246,8 @@ func (p Pool) CalcActualAmounts(ctx sdk.Context, lowerTick, upperTick int64, liq roundUp := liquidityDelta.IsPositive() var ( - liquidityDeltaBigDec = osmomath.BigDecFromDec(liquidityDelta) - actualAmountDenom0 osmomath.BigDec - actualAmountDenom1 osmomath.BigDec + actualAmountDenom0 osmomath.BigDec + actualAmountDenom1 osmomath.BigDec ) if p.IsCurrentTickInRange(lowerTick, upperTick) { @@ -257,7 +256,7 @@ func (p Pool) CalcActualAmounts(ctx sdk.Context, lowerTick, upperTick int64, liq // we also update the pool liquidity since the virtual liquidity is modified by this position's creation currentSqrtPrice := p.CurrentSqrtPrice actualAmountDenom0 = math.CalcAmount0Delta(liquidityDelta, currentSqrtPrice, sqrtPriceUpperTick, roundUp) - actualAmountDenom1 = math.CalcAmount1Delta(liquidityDeltaBigDec, currentSqrtPrice, sqrtPriceLowerTick, roundUp) + actualAmountDenom1 = math.CalcAmount1Delta(liquidityDelta, currentSqrtPrice, sqrtPriceLowerTick, roundUp) } else if p.CurrentTick < lowerTick { // outcome two: position is below current price // this means position is solely made up of asset0 @@ -267,7 +266,7 @@ func (p Pool) CalcActualAmounts(ctx sdk.Context, lowerTick, upperTick int64, liq // outcome three: position is above current price // this means position is solely made up of asset1 actualAmountDenom0 = osmomath.ZeroBigDec() - actualAmountDenom1 = math.CalcAmount1Delta(liquidityDeltaBigDec, sqrtPriceLowerTick, sqrtPriceUpperTick, roundUp) + actualAmountDenom1 = math.CalcAmount1Delta(liquidityDelta, sqrtPriceLowerTick, sqrtPriceUpperTick, roundUp) } if roundUp { diff --git a/x/concentrated-liquidity/model/pool_test.go b/x/concentrated-liquidity/model/pool_test.go index e075202b1a1..0a33ec67284 100644 --- a/x/concentrated-liquidity/model/pool_test.go +++ b/x/concentrated-liquidity/model/pool_test.go @@ -574,8 +574,7 @@ func (suite *ConcentratedPoolTestSuite) TestCalcActualAmounts() { return sqrtPrice } - defaultLiquidityDelta = osmomath.NewDec(1000) - defaultLiquidityDeltaBigDec = osmomath.NewBigDec(1000) + defaultLiquidityDelta = osmomath.NewDec(1000) lowerTick = int64(-99) lowerSqrtPriceBigDec = tickToSqrtPrice(lowerTick) @@ -606,7 +605,7 @@ func (suite *ConcentratedPoolTestSuite) TestCalcActualAmounts() { shouldTestRoundingInvariant: true, expectedAmount0: clmath.CalcAmount0Delta(defaultLiquidityDelta, midSqrtPriceBigDec, upperSqrtPriceBigDec, true).Dec(), - expectedAmount1: clmath.CalcAmount1Delta(defaultLiquidityDeltaBigDec, midSqrtPriceBigDec, lowerSqrtPriceBigDec, true).Dec(), + expectedAmount1: clmath.CalcAmount1Delta(defaultLiquidityDelta, midSqrtPriceBigDec, lowerSqrtPriceBigDec, true).Dec(), }, "current in range, negative liquidity": { currentTick: midtick, @@ -615,7 +614,7 @@ func (suite *ConcentratedPoolTestSuite) TestCalcActualAmounts() { liquidityDelta: defaultLiquidityDelta.Neg(), expectedAmount0: clmath.CalcAmount0Delta(defaultLiquidityDelta.Neg(), midSqrtPriceBigDec, upperSqrtPriceBigDec, false).Dec(), - expectedAmount1: clmath.CalcAmount1Delta(defaultLiquidityDeltaBigDec.Neg(), midSqrtPriceBigDec, lowerSqrtPriceBigDec, false).Dec(), + expectedAmount1: clmath.CalcAmount1Delta(defaultLiquidityDelta.Neg(), midSqrtPriceBigDec, lowerSqrtPriceBigDec, false).Dec(), }, "current below range, positive liquidity": { currentTick: lowerTick, @@ -642,7 +641,7 @@ func (suite *ConcentratedPoolTestSuite) TestCalcActualAmounts() { liquidityDelta: defaultLiquidityDelta, expectedAmount0: osmomath.ZeroDec(), - expectedAmount1: clmath.CalcAmount1Delta(defaultLiquidityDeltaBigDec, lowerSqrtPriceBigDec, midSqrtPriceBigDec, true).Dec(), + expectedAmount1: clmath.CalcAmount1Delta(defaultLiquidityDelta, lowerSqrtPriceBigDec, midSqrtPriceBigDec, true).Dec(), }, "current above range, negative liquidity": { currentTick: uppertick, @@ -651,7 +650,7 @@ func (suite *ConcentratedPoolTestSuite) TestCalcActualAmounts() { liquidityDelta: defaultLiquidityDelta.Neg(), expectedAmount0: osmomath.ZeroDec(), - expectedAmount1: clmath.CalcAmount1Delta(defaultLiquidityDeltaBigDec.Neg(), lowerSqrtPriceBigDec, midSqrtPriceBigDec, false).Dec(), + expectedAmount1: clmath.CalcAmount1Delta(defaultLiquidityDelta.Neg(), lowerSqrtPriceBigDec, midSqrtPriceBigDec, false).Dec(), }, // errors diff --git a/x/concentrated-liquidity/position_test.go b/x/concentrated-liquidity/position_test.go index ae211bb6f6b..917bd2b1813 100644 --- a/x/concentrated-liquidity/position_test.go +++ b/x/concentrated-liquidity/position_test.go @@ -2054,7 +2054,7 @@ func (s *KeeperTestSuite) TestNegativeTickRange_SpreadFactor() { s.Require().True(toTick > pool.GetCurrentTick()) - amountOneIn := math.CalcAmount1Delta(osmomath.BigDecFromDec(pool.GetLiquidity()), pool.GetCurrentSqrtPrice(), s.tickToSqrtPrice(toTick), true) + amountOneIn := math.CalcAmount1Delta(pool.GetLiquidity(), pool.GetCurrentSqrtPrice(), s.tickToSqrtPrice(toTick), true) coinOneIn := sdk.NewCoin(denom1, amountOneIn.Dec().TruncateInt()) return coinOneIn diff --git a/x/concentrated-liquidity/swaps_tick_cross_test.go b/x/concentrated-liquidity/swaps_tick_cross_test.go index dd47718896b..1c799bf8521 100644 --- a/x/concentrated-liquidity/swaps_tick_cross_test.go +++ b/x/concentrated-liquidity/swaps_tick_cross_test.go @@ -321,7 +321,7 @@ func (s *KeeperTestSuite) computeSwapAmounts(poolId uint64, curSqrtPrice osmomat } } else { // Round up so that we cross the tick by default. - curAmountIn := math.CalcAmount1Delta(osmomath.BigDecFromDec(currentLiquidity), curSqrtPrice, nextInitTickSqrtPrice, true).Dec() + curAmountIn := math.CalcAmount1Delta(currentLiquidity, curSqrtPrice, nextInitTickSqrtPrice, true).Dec() amountIn = amountIn.Add(curAmountIn) // The tick should be crossed if currentTick <= expectedTickToSwapTo, unless the intention @@ -346,7 +346,7 @@ func (s *KeeperTestSuite) computeSwapAmounts(poolId uint64, curSqrtPrice osmomat return amountIn, currentLiquidity, curSqrtPrice } -func (s *KeeperTestSuite) computeSwapAmountsInGivenOut(poolId uint64, curSqrtPrice osmomath.BigDec, expectedTickToSwapTo int64, isZeroForOne bool, shouldStayWithinTheSameBucket bool) (osmomath.Dec, osmomath.BigDec, osmomath.BigDec) { +func (s *KeeperTestSuite) computeSwapAmountsInGivenOut(poolId uint64, curSqrtPrice osmomath.BigDec, expectedTickToSwapTo int64, isZeroForOne bool, shouldStayWithinTheSameBucket bool) (osmomath.Dec, osmomath.Dec, osmomath.BigDec) { pool, err := s.App.ConcentratedLiquidityKeeper.GetPoolById(s.Ctx, poolId) s.Require().NoError(err) @@ -368,7 +368,7 @@ func (s *KeeperTestSuite) computeSwapAmountsInGivenOut(poolId uint64, curSqrtPri } // Start from current pool liquidity and zero amount in. - currentLiquidity := osmomath.BigDecFromDec(pool.GetLiquidity()) + currentLiquidity := pool.GetLiquidity() amountOut := osmomath.ZeroDec() for i, liquidityNetEntry := range liquidityNetAmounts { @@ -391,7 +391,7 @@ func (s *KeeperTestSuite) computeSwapAmountsInGivenOut(poolId uint64, curSqrtPri if shouldCrossTick { // Runs regular tick crossing logic. curSqrtPrice = s.tickToSqrtPrice(nextInitializedTick) - currentLiquidity = currentLiquidity.Sub(osmomath.BigDecFromDec(liquidityNetEntry.LiquidityNet)) + currentLiquidity = currentLiquidity.Sub(liquidityNetEntry.LiquidityNet) currentTick = nextInitializedTick - 1 } @@ -409,7 +409,7 @@ func (s *KeeperTestSuite) computeSwapAmountsInGivenOut(poolId uint64, curSqrtPri } } else { // Round up so that we cross the tick by default. - curAmountOut := math.CalcAmount0Delta(currentLiquidity.Dec(), curSqrtPrice, nextInitTickSqrtPrice, false) + curAmountOut := math.CalcAmount0Delta(currentLiquidity, curSqrtPrice, nextInitTickSqrtPrice, false) amountOut = amountOut.Add(curAmountOut.Dec()) // The tick should be crossed if currentTick <= expectedTickToSwapTo, unless the intention @@ -418,7 +418,7 @@ func (s *KeeperTestSuite) computeSwapAmountsInGivenOut(poolId uint64, curSqrtPri if shouldCrossTick { // Runs regular tick crossing logic. curSqrtPrice = s.tickToSqrtPrice(nextInitializedTick) - currentLiquidity = currentLiquidity.Add(osmomath.BigDecFromDec(liquidityNetEntry.LiquidityNet)) + currentLiquidity = currentLiquidity.Add(liquidityNetEntry.LiquidityNet) currentTick = nextInitializedTick } @@ -734,7 +734,7 @@ func (s *KeeperTestSuite) TestSwapOutGivenIn_Tick_Initialization_And_Crossing() if tickToSwapTo >= nr1Position.upperTick { sqrtPriceUpperOne := s.tickToSqrtPrice(nr1Position.upperTick) - amountOneIn = math.CalcAmount1Delta(osmomath.BigDecFromDec(liquidity), sqrtPriceUpperOne, sqrtPriceStart, true).DecRoundUp() + amountOneIn = math.CalcAmount1Delta(liquidity, sqrtPriceUpperOne, sqrtPriceStart, true).DecRoundUp() sqrtPriceStart = sqrtPriceUpperOne @@ -743,7 +743,7 @@ func (s *KeeperTestSuite) TestSwapOutGivenIn_Tick_Initialization_And_Crossing() // This is the total amount necessary to cross the lower tick of narrow position. // Note it is rounded up to ensure that the tick is crossed. - amountOneIn = math.CalcAmount1Delta(osmomath.BigDecFromDec(liquidity), sqrtPriceTarget, sqrtPriceStart, true).DecRoundUp().Add(amountOneIn) + amountOneIn = math.CalcAmount1Delta(liquidity, sqrtPriceTarget, sqrtPriceStart, true).DecRoundUp().Add(amountOneIn) tokenOneIn := sdk.NewCoin(pool.GetToken1(), amountOneIn.Ceil().TruncateInt()) @@ -1201,6 +1201,7 @@ func (s *KeeperTestSuite) TestSwaps_Contiguous_Initialized_TickSpacingOne() { // estimateAmountInFromRounding is a helper to estimate the impact of amountOut rounding on the amountIn and next sqrt price. // This is necessary for correct amount in estimation to pre-fund the swapper account to. It is also required for updating // the "current sqrt price" for the next swap in the sequence as defined by our test configuration. + // TODO: Change type arg of liq estimateAmountInFromRounding := func(isZeroForOne bool, nextSqrtPrice osmomath.BigDec, liq osmomath.BigDec, amountOutDifference osmomath.BigDec) (osmomath.Dec, osmomath.BigDec) { if !liq.IsPositive() { return osmomath.ZeroDec(), nextSqrtPrice @@ -1220,7 +1221,7 @@ func (s *KeeperTestSuite) TestSwaps_Contiguous_Initialized_TickSpacingOne() { // Since amount in is overestimated, this is done in favor of the pool. updatedNextCurSqrtPrice := math.GetNextSqrtPriceFromAmount0OutRoundingUp(nextSqrtPrice, liq, amountOutDifference) // Round up since we want to overestimate the amount in in favor of the pool. - return math.CalcAmount1Delta(liq, updatedNextCurSqrtPrice, nextSqrtPrice, true).DecRoundUp(), updatedNextCurSqrtPrice + return math.CalcAmount1Delta(liq.Dec(), updatedNextCurSqrtPrice, nextSqrtPrice, true).DecRoundUp(), updatedNextCurSqrtPrice } for name, tc := range testcases { @@ -1277,7 +1278,8 @@ func (s *KeeperTestSuite) TestSwaps_Contiguous_Initialized_TickSpacingOne() { // properly estimating the next swap. This also allows us to precisely calculate by how many tokens in we need // to pre-fund the swapper account. amountOutDifference := amountOutRoundedUp.ToLegacyDec().Sub(amountOut) - amountInFromRounding, updatedNextCurSqrtPrice := estimateAmountInFromRounding(isZeroForOne, nextSqrtPrice, expectedLiquidity, osmomath.BigDecFromDec(amountOutDifference)) + liqBigDec := osmomath.BigDecFromDec(expectedLiquidity) // TODO: Delete + amountInFromRounding, updatedNextCurSqrtPrice := estimateAmountInFromRounding(isZeroForOne, nextSqrtPrice, liqBigDec, osmomath.BigDecFromDec(amountOutDifference)) amountInToPreFund := amountIn.Add(amountInFromRounding) // Perform the swap in the desired direction. @@ -1293,7 +1295,7 @@ func (s *KeeperTestSuite) TestSwaps_Contiguous_Initialized_TickSpacingOne() { // Validate that current tick and current liquidity are as expected. s.assertPoolTickEquals(poolId, expectedSwapEndTick) - s.assertPoolLiquidityEquals(poolId, expectedLiquidity.Dec()) + s.assertPoolLiquidityEquals(poolId, expectedLiquidity) // Update the current sqrt price and tick for next swap. curSqrtPrice = updatedNextCurSqrtPrice diff --git a/x/concentrated-liquidity/swapstrategy/one_for_zero.go b/x/concentrated-liquidity/swapstrategy/one_for_zero.go index 86a63402767..56aae1420ec 100644 --- a/x/concentrated-liquidity/swapstrategy/one_for_zero.go +++ b/x/concentrated-liquidity/swapstrategy/one_for_zero.go @@ -60,11 +60,8 @@ func (s oneForZeroStrategy) GetSqrtTargetPrice(nextTickSqrtPrice osmomath.BigDec // OneForZero details: // - oneForZeroStrategy assumes moving to the right of the current square root price. func (s oneForZeroStrategy) ComputeSwapWithinBucketOutGivenIn(sqrtPriceCurrent, sqrtPriceTarget osmomath.BigDec, liquidity, amountOneInRemaining osmomath.Dec) (osmomath.BigDec, osmomath.Dec, osmomath.Dec, osmomath.Dec) { - // TODO: Change to Dec - liquidityBigDec := osmomath.BigDecFromDec(liquidity) - // Estimate the amount of token one needed until the target sqrt price is reached. - amountOneIn := math.CalcAmount1Delta(liquidityBigDec, sqrtPriceTarget, sqrtPriceCurrent, true) + amountOneIn := math.CalcAmount1Delta(liquidity, sqrtPriceTarget, sqrtPriceCurrent, true) // Calculate sqrtPriceNext on the amount of token remaining after spread reward. oneMinusTakerFee := oneDec.Sub(s.spreadFactor) @@ -86,7 +83,7 @@ func (s oneForZeroStrategy) ComputeSwapWithinBucketOutGivenIn(sqrtPriceCurrent, // to complete the swap step. This implies that some of the amount remaining after spread reward is left over after the // current swap step. if !hasReachedTarget { - amountOneIn = math.CalcAmount1Delta(liquidityBigDec, sqrtPriceNext, sqrtPriceCurrent, true) // N.B.: if this is false, causes infinite loop + amountOneIn = math.CalcAmount1Delta(liquidity, sqrtPriceNext, sqrtPriceCurrent, true) // N.B.: if this is false, causes infinite loop } // Calculate the amount of the other token given the sqrt price range. @@ -155,7 +152,7 @@ func (s oneForZeroStrategy) ComputeSwapWithinBucketInGivenOut(sqrtPriceCurrent, } // Calculate the amount of the other token given the sqrt price range. - amountOneIn := math.CalcAmount1Delta(liquidityBigDec, sqrtPriceNext, sqrtPriceCurrent, true) + amountOneIn := math.CalcAmount1Delta(liquidity, sqrtPriceNext, sqrtPriceCurrent, true) // Round up to charge user more in pool's favor. amountOneInFinal := amountOneIn.DecRoundUp() diff --git a/x/concentrated-liquidity/swapstrategy/zero_for_one.go b/x/concentrated-liquidity/swapstrategy/zero_for_one.go index 6ce281e368d..3029b5e1978 100644 --- a/x/concentrated-liquidity/swapstrategy/zero_for_one.go +++ b/x/concentrated-liquidity/swapstrategy/zero_for_one.go @@ -89,7 +89,7 @@ func (s zeroForOneStrategy) ComputeSwapWithinBucketOutGivenIn(sqrtPriceCurrent, } // Calculate the amount of the other token given the sqrt price range. - amountOneOut := math.CalcAmount1Delta(liquidityBigDec, sqrtPriceNext, sqrtPriceCurrent, false) + amountOneOut := math.CalcAmount1Delta(liquidity, sqrtPriceNext, sqrtPriceCurrent, false) // Round up to charge user more in pool's favor. amountZeroInFinal := amountZeroIn.DecRoundUp() @@ -123,11 +123,10 @@ func (s zeroForOneStrategy) ComputeSwapWithinBucketOutGivenIn(sqrtPriceCurrent, // ZeroForOne details: // - zeroForOneStrategy assumes moving to the left of the current square root price. func (s zeroForOneStrategy) ComputeSwapWithinBucketInGivenOut(sqrtPriceCurrent, sqrtPriceTarget osmomath.BigDec, liquidity, amountOneRemainingOut osmomath.Dec) (osmomath.BigDec, osmomath.Dec, osmomath.Dec, osmomath.Dec) { - liquidityBigDec := osmomath.BigDecFromDec(liquidity) amountOneRemainingOutBigDec := osmomath.BigDecFromDec(amountOneRemainingOut) // Estimate the amount of token one needed until the target sqrt price is reached. - amountOneOut := math.CalcAmount1Delta(liquidityBigDec, sqrtPriceTarget, sqrtPriceCurrent, false) + amountOneOut := math.CalcAmount1Delta(liquidity, sqrtPriceTarget, sqrtPriceCurrent, false) // Calculate sqrtPriceNext on the amount of token remaining. Note that the // spread reward is not charged as amountRemaining is amountOut, and we only charge spread reward on @@ -148,7 +147,7 @@ func (s zeroForOneStrategy) ComputeSwapWithinBucketInGivenOut(sqrtPriceCurrent, // to complete the swap step. This implies that some of the amount remaining after spread reward is left over after the // current swap step. if !hasReachedTarget { - amountOneOut = math.CalcAmount1Delta(liquidityBigDec, sqrtPriceNext, sqrtPriceCurrent, false) + amountOneOut = math.CalcAmount1Delta(liquidity, sqrtPriceNext, sqrtPriceCurrent, false) } // Calculate the amount of the other token given the sqrt price range. From 6347c4aa942f240ac67795db0ae918a4bf6fced6 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Fri, 12 Apr 2024 00:33:15 +0900 Subject: [PATCH 24/27] Make one more op mutative --- x/concentrated-liquidity/math/math.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/concentrated-liquidity/math/math.go b/x/concentrated-liquidity/math/math.go index ff6d31e8af8..5a74b0aeb0a 100644 --- a/x/concentrated-liquidity/math/math.go +++ b/x/concentrated-liquidity/math/math.go @@ -164,7 +164,7 @@ func GetNextSqrtPriceFromAmount0OutRoundingUp(sqrtPriceCurrent, liquidity, amoun // avoid overpaying out of the pool. Therefore, we round down. // sqrt_next = sqrt_cur + token_in / liq func GetNextSqrtPriceFromAmount1InRoundingDown(sqrtPriceCurrent osmomath.BigDec, liquidity osmomath.Dec, amountOneRemainingIn osmomath.BigDec) (sqrtPriceNext osmomath.BigDec) { - return sqrtPriceCurrent.Add(amountOneRemainingIn.QuoTruncateDec(liquidity)) + return amountOneRemainingIn.QuoTruncateDec(liquidity).AddMut(sqrtPriceCurrent) } // GetNextSqrtPriceFromAmount1OutRoundingDown utilizes the current sqrtPriceCurrent, liquidity, and amount of denom1 that still needs From 8fce257fbb092c5e28fe610c249758ef70d5f364 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Fri, 12 Apr 2024 00:50:37 +0900 Subject: [PATCH 25/27] One more speedup --- x/concentrated-liquidity/math/math.go | 4 ++-- x/concentrated-liquidity/swapstrategy/one_for_zero.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x/concentrated-liquidity/math/math.go b/x/concentrated-liquidity/math/math.go index 5a74b0aeb0a..f7196eafcf3 100644 --- a/x/concentrated-liquidity/math/math.go +++ b/x/concentrated-liquidity/math/math.go @@ -145,13 +145,13 @@ func GetNextSqrtPriceFromAmount0InRoundingUp(sqrtPriceCurrent, liquidity, amount // When we swap for token one in given token zero out, the price is increasing and we need to move the price up enough // so that we get the desired output amount out. Therefore, we round up. // sqrt_next = liq * sqrt_cur / (liq - token_out * sqrt_cur) -func GetNextSqrtPriceFromAmount0OutRoundingUp(sqrtPriceCurrent, liquidity, amountZeroRemainingOut osmomath.BigDec) (sqrtPriceNext osmomath.BigDec) { +func GetNextSqrtPriceFromAmount0OutRoundingUp(sqrtPriceCurrent, liquidity osmomath.BigDec, amountZeroRemainingOut osmomath.Dec) (sqrtPriceNext osmomath.BigDec) { if amountZeroRemainingOut.IsZero() { return sqrtPriceCurrent } // mul round up to make the final denominator smaller and final result larger - product := amountZeroRemainingOut.MulRoundUp(sqrtPriceCurrent) + product := sqrtPriceCurrent.MulRoundUpDec(amountZeroRemainingOut) denominator := liquidity.Sub(product) // mul round up numerator to make the final result larger // quo round up to make the final result larger diff --git a/x/concentrated-liquidity/swapstrategy/one_for_zero.go b/x/concentrated-liquidity/swapstrategy/one_for_zero.go index 56aae1420ec..a4d24e5c204 100644 --- a/x/concentrated-liquidity/swapstrategy/one_for_zero.go +++ b/x/concentrated-liquidity/swapstrategy/one_for_zero.go @@ -138,7 +138,7 @@ func (s oneForZeroStrategy) ComputeSwapWithinBucketInGivenOut(sqrtPriceCurrent, sqrtPriceNext = sqrtPriceTarget } else { // Otherwise, compute the next sqrt price based on the amount remaining after spread reward. - sqrtPriceNext = math.GetNextSqrtPriceFromAmount0OutRoundingUp(sqrtPriceCurrent, liquidityBigDec, amountZeroRemainingOutBigDec) + sqrtPriceNext = math.GetNextSqrtPriceFromAmount0OutRoundingUp(sqrtPriceCurrent, liquidityBigDec, amountZeroRemainingOut) } hasReachedTarget := sqrtPriceTarget.Equal(sqrtPriceNext) From aabae0728d261ded9f998a96bd4bb68ead32a251 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Fri, 12 Apr 2024 01:09:21 +0900 Subject: [PATCH 26/27] Fix test --- x/concentrated-liquidity/math/math_test.go | 32 ++++++++++++++++--- .../swaps_tick_cross_test.go | 2 +- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/x/concentrated-liquidity/math/math_test.go b/x/concentrated-liquidity/math/math_test.go index 214ca3c33e4..bcf13685ddb 100644 --- a/x/concentrated-liquidity/math/math_test.go +++ b/x/concentrated-liquidity/math/math_test.go @@ -479,6 +479,13 @@ type sqrtRoundingDecTestCase struct { expected osmomath.BigDec } +type sqrtRoundingAmtDecTestCase struct { + sqrtPriceCurrent osmomath.BigDec + liquidity osmomath.BigDec + amountRemaining osmomath.Dec + expected osmomath.BigDec +} + func runSqrtRoundingTestCase( t *testing.T, name string, @@ -509,6 +516,21 @@ func runSqrtRoundingDecTestCase( } } +func runSqrtRoundingAmtDecTestCase( + t *testing.T, + name string, + fn func(osmomath.BigDec, osmomath.BigDec, osmomath.Dec) osmomath.BigDec, + cases map[string]sqrtRoundingAmtDecTestCase, +) { + for name, tc := range cases { + tc := tc + t.Run(name, func(t *testing.T) { + sqrtPriceNext := fn(tc.sqrtPriceCurrent, tc.liquidity, tc.amountRemaining) + require.Equal(t, tc.expected.String(), sqrtPriceNext.String()) + }) + } +} + // Estimates are computed with x/concentrated-liquidity/python/clmath.py func TestGetNextSqrtPriceFromAmount0InRoundingUp(t *testing.T) { tests := map[string]sqrtRoundingTestCase{ @@ -547,31 +569,31 @@ func TestGetNextSqrtPriceFromAmount0InRoundingUp(t *testing.T) { // Estimates are computed with x/concentrated-liquidity/python/clmath.py func TestGetNextSqrtPriceFromAmount0OutRoundingUp(t *testing.T) { - tests := map[string]sqrtRoundingTestCase{ + tests := map[string]sqrtRoundingAmtDecTestCase{ "rounded up at precision end": { sqrtPriceCurrent: sqrt5000BigDec, liquidity: osmomath.MustNewBigDecFromStr("3035764687.503020836176699298"), - amountRemaining: osmomath.MustNewBigDecFromStr("8398"), + amountRemaining: osmomath.MustNewDecFromStr("8398"), // get_next_sqrt_price_from_amount0_out_round_up(liquidity,sqrtPriceCurrent ,amountRemaining) expected: osmomath.MustNewBigDecFromStr("70.724512595179305565323229510645063950"), }, "no round up due zeroes at precision end": { sqrtPriceCurrent: osmomath.MustNewBigDecFromStr("2"), liquidity: osmomath.MustNewBigDecFromStr("10"), - amountRemaining: osmomath.MustNewBigDecFromStr("1"), + amountRemaining: osmomath.MustNewDecFromStr("1"), // liq * sqrt_cur / (liq + token_out * sqrt_cur) = 2.5 expected: osmomath.MustNewBigDecFromStr("2.5"), }, "low price range": { liquidity: smallLiquidity, sqrtPriceCurrent: sqrtANearMin, - amountRemaining: smallValue, + amountRemaining: smallValue.Dec(), // from clmath decimal import * // get_next_sqrt_price_from_amount0_out_round_up(liq, sqrtPriceA, amountRemaining) expected: osmomath.MustNewBigDecFromStr("0.000000000000000023829902587267894423"), }, } - runSqrtRoundingTestCase(t, "TestGetNextSqrtPriceFromAmount0OutRoundingUp", math.GetNextSqrtPriceFromAmount0OutRoundingUp, tests) + runSqrtRoundingAmtDecTestCase(t, "TestGetNextSqrtPriceFromAmount0OutRoundingUp", math.GetNextSqrtPriceFromAmount0OutRoundingUp, tests) } // Estimates are computed with x/concentrated-liquidity/python/clmath.py diff --git a/x/concentrated-liquidity/swaps_tick_cross_test.go b/x/concentrated-liquidity/swaps_tick_cross_test.go index 1c799bf8521..5613b892bdf 100644 --- a/x/concentrated-liquidity/swaps_tick_cross_test.go +++ b/x/concentrated-liquidity/swaps_tick_cross_test.go @@ -1219,7 +1219,7 @@ func (s *KeeperTestSuite) TestSwaps_Contiguous_Initialized_TickSpacingOne() { // Round up since we want to overestimate the change in sqrt price stemming from the amount out going left-to-right // from the current sqrt price. This overestimated value is then used to calculate amount in charged on the user. // Since amount in is overestimated, this is done in favor of the pool. - updatedNextCurSqrtPrice := math.GetNextSqrtPriceFromAmount0OutRoundingUp(nextSqrtPrice, liq, amountOutDifference) + updatedNextCurSqrtPrice := math.GetNextSqrtPriceFromAmount0OutRoundingUp(nextSqrtPrice, liq, amountOutDifference.Dec()) // Round up since we want to overestimate the amount in in favor of the pool. return math.CalcAmount1Delta(liq.Dec(), updatedNextCurSqrtPrice, nextSqrtPrice, true).DecRoundUp(), updatedNextCurSqrtPrice } From a33352f4b40b9a7f23ba1ad73480ae4a90b831f9 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Fri, 12 Apr 2024 19:09:29 +0900 Subject: [PATCH 27/27] Speedup SpotPrice impl --- osmomath/decimal.go | 5 +++++ x/concentrated-liquidity/model/pool.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/osmomath/decimal.go b/osmomath/decimal.go index 6bc7daa5a6d..3027a12fc8d 100644 --- a/osmomath/decimal.go +++ b/osmomath/decimal.go @@ -1247,6 +1247,11 @@ func (d BigDec) PowerInteger(power uint64) BigDec { func (d BigDec) PowerIntegerMut(power uint64) BigDec { if power == 0 { return OneBigDec() + } else if power == 1 { + return d + } else if power == 2 { + // save a oneBigDec allocation + return d.MulMut(d) } tmp := OneBigDec() diff --git a/x/concentrated-liquidity/model/pool.go b/x/concentrated-liquidity/model/pool.go index e58d29039b8..53f715c946c 100644 --- a/x/concentrated-liquidity/model/pool.go +++ b/x/concentrated-liquidity/model/pool.go @@ -125,7 +125,7 @@ func (p Pool) SpotPrice(ctx sdk.Context, quoteAssetDenom string, baseAssetDenom if baseAssetDenom == p.Token0 { return osmomath.BigDecFromDecMut(priceSquared.Dec()), nil } - return osmomath.BigDecFromDecMut(osmomath.OneBigDec().Quo(priceSquared).Dec()), nil + return osmomath.BigDecFromDecMut(osmomath.OneBigDec().QuoMut(priceSquared).Dec()), nil } // GetToken0 returns the token0 of the pool