Skip to content

Commit

Permalink
Move osmomath into its own go.mod (#3771)
Browse files Browse the repository at this point in the history
* Move osmomath into its own go.mod

* Fix go mods

* fix osmomath test build

* Tryfix e2e test

* Try removing osmomath from the copy line?

* Add osmomath to first copy

* Try another layer

* Make build work off of tagged releases

* Switch prod and E2E builds to ignore go work

* Fix merge conflict

* Add root dir to go work

* Fix conflict

(cherry picked from commit 079702e)

# Conflicts:
#	go.mod
#	go.sum
#	osmomath/decimal_test.go
#	osmomath/exp2_test.go
#	x/gamm/keeper/pool_service.go
#	x/gamm/pool-models/stableswap/pool_test.go
#	x/twap/logic.go
#	x/twap/strategy.go
#	x/twap/strategy_test.go
  • Loading branch information
ValarDragon authored and mergify[bot] committed Dec 21, 2022
1 parent 3298fba commit 3393a88
Show file tree
Hide file tree
Showing 25 changed files with 1,761 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ BUILD_TARGETS := build install
build: BUILD_ARGS=-o $(BUILDDIR)/

$(BUILD_TARGETS): check_version go.sum $(BUILDDIR)/
go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...
GOWORK=off go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...

$(BUILDDIR)/:
mkdir -p $(BUILDDIR)/
Expand Down
2 changes: 1 addition & 1 deletion app/apptesting/gamm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package apptesting
import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/osmosis-labs/osmosis/v13/osmomath"
"github.com/osmosis-labs/osmosis/osmomath"
gammkeeper "github.com/osmosis-labs/osmosis/v13/x/gamm/keeper"
"github.com/osmosis-labs/osmosis/v13/x/gamm/pool-models/balancer"
"github.com/osmosis-labs/osmosis/v13/x/gamm/pool-models/stableswap"
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ require (
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/mattn/go-sqlite3 v1.14.16
github.com/ory/dockertest/v3 v3.9.1
<<<<<<< HEAD
github.com/osmosis-labs/go-mutesting v0.0.0-20220811235203-65a53b4ea8e3
=======
github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3
github.com/osmosis-labs/osmosis/osmomath v0.0.1
>>>>>>> 079702ea (Move osmomath into its own go.mod (#3771))
github.com/pkg/errors v0.9.1
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.5.0
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,15 @@ github.com/ory/dockertest/v3 v3.9.1 h1:v4dkG+dlu76goxMiTT2j8zV7s4oPPEppKT8K8p2f1
github.com/ory/dockertest/v3 v3.9.1/go.mod h1:42Ir9hmvaAPm0Mgibk6mBPi7SFvTXxEcnztDYOJ//uM=
github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20221118211718-545aed73e94e h1:A3byMZpvq21iI7yWJUNdHw0nf8jVAbVUsWY9twnXSXE=
github.com/osmosis-labs/cosmos-sdk v0.45.1-0.20221118211718-545aed73e94e/go.mod h1:rud0OaBIuq3+qOqtwT4SR7Q7iSzRp7w41fjninTjfnQ=
<<<<<<< HEAD
github.com/osmosis-labs/go-mutesting v0.0.0-20220811235203-65a53b4ea8e3 h1:/imbKy8s1I+z7wx4FbRHOXK2v82xesUCz2EPUqfBDIg=
github.com/osmosis-labs/go-mutesting v0.0.0-20220811235203-65a53b4ea8e3/go.mod h1:lV6KnqXYD/ayTe7310MHtM3I2q8Z6bBfMAi+bhwPYtI=
=======
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.1 h1:23X7pPCnyzQHEYCY0YbbVVESq84cGftvacO/Wswd3A0=
github.com/osmosis-labs/osmosis/osmomath v0.0.1/go.mod h1:IpoXO7lvmfsBFfQzaqovs541hpqtrnM+GJSZDi/TZtc=
>>>>>>> 079702ea (Move osmomath into its own go.mod (#3771))
github.com/osmosis-labs/wasmd v0.29.2-osmo-v13 h1:HvxAks1ctB3nBx1cXqcmfA0g0BKe7Og77OA2j2rxaJk=
github.com/osmosis-labs/wasmd v0.29.2-osmo-v13/go.mod h1:UlLBU5vuHncwQUM9W8lw+2mEptEMFxxfVWupZ6sXtn4=
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
Expand Down
4 changes: 4 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
go 1.18

use ./osmomath
use .
45 changes: 45 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
github.com/CosmWasm/wasmvm v1.1.1 h1:0xtdrmmsP9fibe+x42WcMkp5aQ738BICgcH3FNVLzm4=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
github.com/Workiva/go-datastructures v1.0.53 h1:J6Y/52yX10Xc5JjXmGtWoSSxs3mZnGSaq37xZZh7Yig=
github.com/adlio/schema v1.3.3 h1:oBJn8I02PyTB466pZO1UZEn1TV5XLlifBSyMrmHl/1I=
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/cenkalti/backoff/v4 v4.1.1 h1:G2HAfAmvm/GcKan2oOQpBXOd2tT2G57ZnZGWa1PxPBQ=
github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4=
github.com/coinbase/rosetta-sdk-go v0.7.0 h1:lmTO/JEpCvZgpbkOITL95rA80CPKb5CtMzLaqF2mCNg=
github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg=
github.com/cosmos/gogoproto v1.4.2 h1:UeGRcmFW41l0G0MiefWhkPEVEwvu78SZsHBvI78dAYw=
github.com/cosmos/ibc-go/v3 v3.4.0 h1:ha3cqEG36pqMWqA1D+kxDWBTZXpeFMd/aZIQF7I0xro=
github.com/creachadair/taskgroup v0.3.2 h1:zlfutDS+5XG40AOxcHDSThxKzns8Tnr9jnr6VqkYlkM=
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f h1:U5y3Y5UE0w7amNe7Z5G/twsBW0KEalRQXZzf8ufSh9I=
github.com/docker/cli v20.10.17+incompatible h1:eO2KS7ZFeov5UJeaDmIs1NFEDRf32PaqRpvoEkKBy5M=
github.com/docker/docker v20.10.19+incompatible h1:lzEmjivyNHFHMNAFLXORMBXyGIhw/UP4DvJwvyKYq64=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/google/orderedcode v0.0.1 h1:UzfcAexk9Vhv8+9pNOgRu41f16lHq725vPwnSeiG/Us=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/improbable-eng/grpc-web v0.15.0 h1:BN+7z6uNXZ1tQGcNAuaU1YjsLTApzkjt2tzCixLaUPQ=
github.com/lib/pq v1.10.6 h1:jbk+ZieJ0D7EVGJYpL9QTz7/YW6UHbmdnZWYyK5cdBs=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae h1:O4SWKdcHVCvYqyDV+9CJA1fcDN2L11Bule0iFy3YlAI=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/image-spec v1.1.0-rc2 h1:2zx/Stx4Wc5pIPDvIxHXvXtQFW/7XWJGmnM7r3wg034=
github.com/opencontainers/runc v1.1.3 h1:vIXrkId+0/J2Ymu2m7VjGvbSlAId9XNRPhn2p4b+d8w=
github.com/ory/dockertest v3.3.5+incompatible h1:iLLK6SQwIhcbrG783Dghaaa3WPzGc+4Emza6EbVUUGA=
github.com/ory/dockertest/v3 v3.9.1 h1:v4dkG+dlu76goxMiTT2j8zV7s4oPPEppKT8K8p2f1kY=
github.com/otiai10/copy v1.7.0 h1:hVoPiN+t+7d2nzzwMiDHPSOogsWAStewq3TwU05+clE=
github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U=
github.com/rs/zerolog v1.27.0 h1:1T7qCieN22GVc8S4Q2yuexzBb1EqjbgjSH9RohbMjKs=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo=
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
nhooyr.io/websocket v1.8.6 h1:s+C3xAMLwGmlI31Nyn/eAehUlZPwfYZu2JXM621Q5/k=
nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g=
124 changes: 120 additions & 4 deletions osmomath/decimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ import (
"github.com/stretchr/testify/suite"
"gopkg.in/yaml.v2"

<<<<<<< HEAD
"github.com/osmosis-labs/osmosis/v13/osmomath"
gammtypes "github.com/osmosis-labs/osmosis/v13/x/gamm/types"
=======
"github.com/osmosis-labs/osmosis/osmomath"
>>>>>>> 079702ea (Move osmomath into its own go.mod (#3771))
)

type decimalTestSuite struct {
Expand Down Expand Up @@ -719,7 +723,7 @@ func (s *decimalTestSuite) TestLog2() {
expected: osmomath.MustNewDecFromStr("99.525973560175362367047484597337715868"),
},
"log_2{Max Spot Price} = 128": {
initialValue: osmomath.BigDecFromSDKDec(gammtypes.MaxSpotPrice), // 2^128 - 1
initialValue: osmomath.BigDecFromSDKDec(osmomath.MaxSpotPrice), // 2^128 - 1
// From: https://www.wolframalpha.com/input?i=log+base+2+of+%28%282%5E128%29+-+1%29+38+digits
expected: osmomath.MustNewDecFromStr("128"),
},
Expand Down Expand Up @@ -1062,21 +1066,21 @@ func (s *decimalTestSuite) TestPowerInteger() {
"geom twap overflow: 2^log_2{max spot price + 1}": {
base: osmomath.TwoBigDec,
// add 1 for simplicity of calculation to isolate overflow.
exponent: uint64(osmomath.BigDecFromSDKDec(gammtypes.MaxSpotPrice).Add(osmomath.OneDec()).LogBase2().TruncateInt().Uint64()),
exponent: uint64(osmomath.BigDecFromSDKDec(osmomath.MaxSpotPrice).Add(osmomath.OneDec()).LogBase2().TruncateInt().Uint64()),

// https://www.wolframalpha.com/input?i=2%5E%28floor%28+log+base+2+%282%5E128%29%29%29+++39+digits
expectedResult: osmomath.MustNewDecFromStr("340282366920938463463374607431768211456"),
},
"geom twap overflow: 2^log_2{max spot price}": {
base: osmomath.TwoBigDec,
exponent: uint64(osmomath.BigDecFromSDKDec(gammtypes.MaxSpotPrice).LogBase2().TruncateInt().Uint64()),
exponent: uint64(osmomath.BigDecFromSDKDec(osmomath.MaxSpotPrice).LogBase2().TruncateInt().Uint64()),

// https://www.wolframalpha.com/input?i=2%5E%28floor%28+log+base+2+%282%5E128+-+1%29%29%29+++39+digits
expectedResult: osmomath.MustNewDecFromStr("170141183460469231731687303715884105728"),
},
"geom twap overflow: 2^log_2{max spot price / 2 - 2017}": { // 2017 is prime.
base: osmomath.TwoBigDec,
exponent: uint64(osmomath.BigDecFromSDKDec(gammtypes.MaxSpotPrice.Quo(sdk.NewDec(2)).Sub(sdk.NewDec(2017))).LogBase2().TruncateInt().Uint64()),
exponent: uint64(osmomath.BigDecFromSDKDec(osmomath.MaxSpotPrice.Quo(sdk.NewDec(2)).Sub(sdk.NewDec(2017))).LogBase2().TruncateInt().Uint64()),

// https://www.wolframalpha.com/input?i=e%5E10+41+digits
expectedResult: osmomath.MustNewDecFromStr("85070591730234615865843651857942052864"),
Expand Down Expand Up @@ -1260,3 +1264,115 @@ func (s *decimalTestSuite) TestPowerInteger_Mutation() {
})
}
}
<<<<<<< HEAD
=======

func (s *decimalTestSuite) TestPower() {
tests := map[string]struct {
base osmomath.BigDec
exponent osmomath.BigDec
expectedResult osmomath.BigDec
expectPanic bool
errTolerance osmomath.ErrTolerance
}{
// N.B.: integer exponents are tested under TestPowerInteger.

"3 ^ 2 = 9 (integer base and integer exponent)": {
base: osmomath.NewBigDec(3),
exponent: osmomath.NewBigDec(2),

expectedResult: osmomath.NewBigDec(9),

errTolerance: zeroAdditiveErrTolerance,
},
"2^0.5 (base of 2 and non-integer exponent)": {
base: osmomath.MustNewDecFromStr("2"),
exponent: osmomath.MustNewDecFromStr("0.5"),

// https://www.wolframalpha.com/input?i=2%5E0.5+37+digits
expectedResult: osmomath.MustNewDecFromStr("1.414213562373095048801688724209698079"),

errTolerance: osmomath.ErrTolerance{
AdditiveTolerance: minDecTolerance,
RoundingDir: osmomath.RoundDown,
},
},
"3^0.33 (integer base other than 2 and non-integer exponent)": {
base: osmomath.MustNewDecFromStr("3"),
exponent: osmomath.MustNewDecFromStr("0.33"),

// https://www.wolframalpha.com/input?i=3%5E0.33+37+digits
expectedResult: osmomath.MustNewDecFromStr("1.436977652184851654252692986409357265"),

errTolerance: osmomath.ErrTolerance{
AdditiveTolerance: minDecTolerance,
RoundingDir: osmomath.RoundDown,
},
},
"e^0.98999 (non-integer base and non-integer exponent)": {
base: osmomath.EulersNumber,
exponent: osmomath.MustNewDecFromStr("0.9899"),

// https://www.wolframalpha.com/input?i=e%5E0.9899+37+digits
expectedResult: osmomath.MustNewDecFromStr("2.690965362357751196751808686902156603"),

errTolerance: osmomath.ErrTolerance{
AdditiveTolerance: minDecTolerance,
RoundingDir: osmomath.RoundUnconstrained,
},
},
"10^0.001 (small non-integer exponent)": {
base: osmomath.NewBigDec(10),
exponent: osmomath.MustNewDecFromStr("0.001"),

// https://www.wolframalpha.com/input?i=10%5E0.001+37+digits
expectedResult: osmomath.MustNewDecFromStr("1.002305238077899671915404889328110554"),

errTolerance: osmomath.ErrTolerance{
AdditiveTolerance: minDecTolerance,
RoundingDir: osmomath.RoundUnconstrained,
},
},
"13^100.7777 (large non-integer exponent)": {
base: osmomath.NewBigDec(13),
exponent: osmomath.MustNewDecFromStr("100.7777"),

// https://www.wolframalpha.com/input?i=13%5E100.7777+37+digits
expectedResult: osmomath.MustNewDecFromStr("1.822422110233759706998600329118969132").Mul(osmomath.NewBigDec(10).PowerInteger(112)),

errTolerance: osmomath.ErrTolerance{
MultiplicativeTolerance: minDecTolerance,
RoundingDir: osmomath.RoundDown,
},
},
"large non-integer exponent with large non-integer base - panics": {
base: osmomath.MustNewDecFromStr("169.137"),
exponent: osmomath.MustNewDecFromStr("100.7777"),

expectPanic: true,
},
"negative base - panic": {
base: osmomath.NewBigDec(-3),
exponent: osmomath.MustNewDecFromStr("4"),

expectPanic: true,
},
"negative exponent - panic": {
base: osmomath.NewBigDec(1),
exponent: osmomath.MustNewDecFromStr("-4"),

expectPanic: true,
},
}

for name, tc := range tests {
tc := tc
s.Run(name, func() {
osmomath.ConditionalPanic(s.T(), tc.expectPanic, func() {
actualResult := tc.base.Power(tc.exponent)
s.Require().Equal(0, tc.errTolerance.CompareBigDec(tc.expectedResult, actualResult))
})
})
}
}
>>>>>>> 079702ea (Move osmomath into its own go.mod (#3771))
Loading

0 comments on commit 3393a88

Please sign in to comment.