diff --git a/Makefile b/Makefile index ed122769529..384a0eaeabf 100644 --- a/Makefile +++ b/Makefile @@ -446,9 +446,24 @@ localnet-state-export-stop: localnet-state-export-clean: localnet-clean -# create 1000 concentrated-liquidity positions in localosmosis at pool id 1 +# create 100 concentrated-liquidity positions in localosmosis at pool id 1 localnet-cl-create-positions: - go run tests/cl-go-client/main.go + go run tests/cl-go-client/main.go --operation 0 + +# does 100 small randomized swaps in localosmosis at pool id 1 +localnet-cl-small-swap: + go run tests/cl-go-client/main.go --operation 1 + +# does 100 large swaps where the output of the previous swap is swapped back at the +# next swap. localosmosis at pool id 1 +localnet-cl-large-swap: + go run tests/cl-go-client/main.go --operation 2 + +# does both of localnet-cl-create-positions and localnet-cl-small-swap +localnet-cl-positions-small-swaps: localnet-cl-create-positions localnet-cl-small-swap + +# does both of localnet-cl-create-positions and localnet-cl-large-swap +localnet-cl-positions-large-swaps: localnet-cl-create-positions localnet-cl-large-swap # This script retrieves Uniswap v3 Ethereum position data # from subgraph. It uses WETH / USDC pool. This is helpful diff --git a/tests/cl-go-client/README.md b/tests/cl-go-client/README.md index 75d7c60898f..ddcd6f3522a 100644 --- a/tests/cl-go-client/README.md +++ b/tests/cl-go-client/README.md @@ -24,8 +24,36 @@ make localnet-keys See `tests/localosmosis` for more info. +## Testnet Setup + +Configure a different `osmosisd` environment with configs. + +```bash +make set-env .osmosisd-testnet-script + +osmosisd init test-script + +cd $HOME/.osmosisd-testnet-script/config + +nano client.toml +``` + +Replace node RPC with the testnet value and save, + +Next, manually edit the `localosmosisFromHomePath` variable in the script: + + +Set the value to `.osmosisd-testnet-script` and save. + +Now, you are able to run this script on testnet. This assummes that +testnet accounts have been set up with the default test accounts +and balances. By default, we mean accounts created with +`make localnet-keys`. + ## Running +### Crete Positions + ```bash make localnet-cl-create-positions ``` @@ -33,4 +61,53 @@ make localnet-cl-create-positions In the current state, it does the following: - Queries status of the chain to make sure it's running. - Queries pool with id 1. If does not exist, creates it -- Sets up one CL position +- Sets up 100 CL positions (count configured at the top of the file) + +### Make Small Randomized Swaps + +```bash +make localnet-cl-small-swap +``` + +In the current state, it does the following: +- Queries status of the chain to make sure it's running. +- Queries pool with id 1. +- Performs 100 randomized swaps against the pool with id 1. + +Note that this script does not set up positions, assumming they are +already set up. + +### Create Positions and Make Small Randomized Swaps + +```bash +make localnet-cl-positions-small-swaps +``` + +This script runs "Create Positions" and "Make Small Randomized Swaps" scripts in sequence. + +### Make Large Invertible Swaps + +```bash +make localnet-cl-large-swap +``` + +In the current state, it does the following: +- Queries status of the chain to make sure it's running. +- Queries pool with id 1. +- Performs 100 large swaps where the output of the previous swap is swapped back at the +next swap. + +In other words, it takes one large amount and swaps it into the pool. Then, takes output token +and swaps it back while accounting for the spread factor. This is done to +ensure that we cross ticks while minimizing the chance of running out of funds or liquidity. + +Note that this script does not set up positions, assumming they are +already set up. + +### Create Positions and Make Large Invertible Swaps + +```bash +make localnet-cl-positions-large-swaps +``` + +This script runs "Create Positions" and "Make Large Invertible Swaps" scripts in sequence. diff --git a/tests/cl-go-client/go.mod b/tests/cl-go-client/go.mod index 9ef435a9fd5..1cc2a5f7204 100644 --- a/tests/cl-go-client/go.mod +++ b/tests/cl-go-client/go.mod @@ -5,7 +5,7 @@ go 1.20 require ( github.com/cosmos/cosmos-sdk v0.47.2 github.com/ignite/cli v0.23.0 - github.com/osmosis-labs/osmosis/v15 v15.0.0-20230601221251-b764323ce770 + github.com/osmosis-labs/osmosis/v15 v15.0.0-20230602143948-7c9acb65e46c ) @@ -79,7 +79,7 @@ require ( github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.17 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect github.com/minio/highwayhash v1.0.2 // indirect @@ -87,9 +87,9 @@ require ( github.com/mtibben/percent v0.2.1 // indirect github.com/nxadm/tail v1.4.8 // indirect github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516205127-c213fddde069 // indirect - github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230529060317-d6d2dda0fb22 // indirect + github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230606194542-47ea1e2c85ca // indirect github.com/osmosis-labs/osmosis/v16 v16.0.0-20230603032959-4d2ba21b8d1e // indirect - github.com/pelletier/go-toml/v2 v2.0.6 // indirect + github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect @@ -103,13 +103,13 @@ require ( github.com/rs/cors v1.8.2 // indirect github.com/rs/zerolog v1.27.0 // indirect github.com/sasha-s/go-deadlock v0.3.1 // indirect - github.com/spf13/afero v1.9.3 // indirect + github.com/spf13/afero v1.9.5 // indirect github.com/spf13/cast v1.5.1 // indirect github.com/spf13/cobra v1.7.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/spf13/viper v1.15.0 // indirect - github.com/stretchr/testify v1.8.3 // indirect + github.com/spf13/viper v1.16.0 // indirect + github.com/stretchr/testify v1.8.4 // indirect github.com/subosito/gotenv v1.4.2 // indirect github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect github.com/tendermint/btcd v0.1.1 // indirect @@ -123,16 +123,16 @@ require ( github.com/zondax/ledger-go v0.14.1 // indirect go.etcd.io/bbolt v1.3.6 // indirect go.opencensus.io v0.24.0 // indirect - golang.org/x/crypto v0.5.0 // indirect + golang.org/x/crypto v0.9.0 // indirect golang.org/x/exp v0.0.0-20230131160201-f062dba9d201 // indirect golang.org/x/mod v0.10.0 // indirect - golang.org/x/net v0.9.0 // indirect + golang.org/x/net v0.10.0 // indirect golang.org/x/sync v0.1.0 // indirect - golang.org/x/sys v0.7.0 // indirect - golang.org/x/term v0.7.0 // indirect + golang.org/x/sys v0.8.0 // indirect + golang.org/x/term v0.8.0 // indirect golang.org/x/text v0.9.0 // indirect - google.golang.org/genproto v0.0.0-20230125152338-dcaf20b6aeaa // indirect - google.golang.org/grpc v1.53.0 // indirect + google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect + google.golang.org/grpc v1.55.0 // indirect google.golang.org/protobuf v1.30.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/tests/cl-go-client/go.sum b/tests/cl-go-client/go.sum index 8d9f0192f84..f8fa21d7348 100644 --- a/tests/cl-go-client/go.sum +++ b/tests/cl-go-client/go.sum @@ -601,6 +601,7 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= @@ -691,6 +692,7 @@ github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516205127-c213fddde06 github.com/osmosis-labs/osmosis/osmomath v0.0.3-dev.0.20230516205127-c213fddde069/go.mod h1:a7lhiXRpn8QJ21OhFpaEnUNErTSIafaYpp02q6uI/Dk= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230529060317-d6d2dda0fb22 h1:I14d+U4gDSL5dHoQ3G+kGLhZP5Zj3mOxMb/97Xflusc= github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230529060317-d6d2dda0fb22/go.mod h1:GIvgXqD8NOtrpu5bJ052tZxWLFj4ekpi1BMwEHIvXVU= +github.com/osmosis-labs/osmosis/osmoutils v0.0.0-20230606194542-47ea1e2c85ca/go.mod h1:FqFOfj9+e5S1I7hR3baGUHrqje3g32EOHAXoOf7R00M= github.com/osmosis-labs/osmosis/v16 v16.0.0-20230602200356-bdf5b96b3674 h1:sCXD8SajkGC3AmHrwiklgTWHZUXcSHm8YFJKbvw6Lk4= github.com/osmosis-labs/osmosis/v16 v16.0.0-20230602200356-bdf5b96b3674/go.mod h1:Vg+05vXFc682OEF52HTqhEKF+deQ0GSt9rkisCFJ8Ug= github.com/osmosis-labs/osmosis/v16 v16.0.0-20230603032959-4d2ba21b8d1e h1:Rbkpe0cLh67eyWpCMN8u/6xDNHlWimrLceMEhtNJ0TI= @@ -710,6 +712,7 @@ github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtP github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU= github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= +github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= github.com/peterh/liner v1.0.1-0.20180619022028-8c1271fcf47f/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc= github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= @@ -814,6 +817,7 @@ github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2 github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.9.3 h1:41FoI0fD7OR7mGcKE/aOiLkGreyf8ifIOQmJANWogMk= github.com/spf13/afero v1.9.3/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y= +github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= @@ -831,6 +835,7 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/spf13/viper v1.15.0 h1:js3yy885G8xwJa6iOISGFwd+qlUo5AvyXb7CiihdtiU= github.com/spf13/viper v1.15.0/go.mod h1:fFcTBJxvhhzSJiZy8n+PeW6t8l+KeT/uTARa0jHOQLA= +github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg= github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.5 h1:KKUqeGhVBK38+1LwThC8IeIcsJZ6COX5kvhiJroFqCM= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= @@ -853,6 +858,7 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= @@ -954,8 +960,10 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= +golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -1048,8 +1056,10 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1149,12 +1159,15 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1313,6 +1326,7 @@ google.golang.org/genproto v0.0.0-20210126160654-44e461bb6506/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20230125152338-dcaf20b6aeaa h1:qQPhfbPO23fwm/9lQr91L1u62Zo6cm+zI+slZT+uf+o= google.golang.org/genproto v0.0.0-20230125152338-dcaf20b6aeaa/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= +google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU= google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= diff --git a/tests/cl-go-client/main.go b/tests/cl-go-client/main.go index 6c49011886d..16364af7aca 100644 --- a/tests/cl-go-client/main.go +++ b/tests/cl-go-client/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "flag" "fmt" "log" "math" @@ -22,6 +23,23 @@ import ( poolmanagertypes "github.com/osmosis-labs/osmosis/v16/x/poolmanager/types" ) +// operation defines the desired operation to be run by this script. +type operation int + +const ( + // createPositions creates positions in the CL pool with id expectedPoolId. + createPositions operation = iota + + // makeManySmallSwaps makes many swaps in the CL pool with id expectedPoolId. + makeManySmallSwaps + + // makeManyLargeSwaps makes many large swaps in the CL pool with id expectedPoolId. + // it takes one large amount and swaps it into the pool. Then, takes output token + // and swaps it back while accounting for the spread factor. This is done to + // ensure that we cross ticks while minimizing the chance of running out of funds or liquidity. + makeManyInvertibleLargeSwaps +) + const ( expectedPoolId uint64 = 1 addressPrefix = "osmo" @@ -31,19 +49,31 @@ const ( denom1 = "uusdc" tickSpacing int64 = 100 accountNamePrefix = "lo-test" - numPositions = 1_000 + numPositions = 100 + numSwaps = 100 minAmountDeposited = int64(1_000_000) randSeed = 1 maxAmountDeposited = 1_00_000_000 + maxAmountSingleSwap = 1_000_000 + largeSwapAmount = 90_000_000_000 ) var ( - defaultAccountName = fmt.Sprintf("%s%d", accountNamePrefix, 1) - defaultMinAmount = sdk.ZeroInt() - accountMutex sync.Mutex + defaultAccountName = fmt.Sprintf("%s%d", accountNamePrefix, 1) + defaultMinAmount = sdk.ZeroInt() + defaultSpreadFactor = sdk.MustNewDecFromStr("0.001") + accountMutex sync.Mutex ) func main() { + var ( + desiredOperation int + ) + + flag.IntVar(&desiredOperation, "operation", 0, fmt.Sprintf("operation to run:\ncreate positions: %v, make many swaps: %v", createPositions, makeManySmallSwaps)) + + flag.Parse() + ctx := context.Background() clientHome := getClientHomePath() @@ -89,11 +119,25 @@ func main() { } } - minTick, maxTick := cltypes.MinTick, cltypes.MaxTick - log.Println(minTick, " ", maxTick) - rand.Seed(randSeed) + switch operation(desiredOperation) { + case createPositions: + createManyRandomPositions(igniteClient, expectedPoolId, numPositions) + return + case makeManySmallSwaps: + swapRandomSmallAmountsContinuously(igniteClient, expectedPoolId, numSwaps) + return + case makeManyInvertibleLargeSwaps: + swapGivenLargeAmountsBothDirections(igniteClient, expectedPoolId, numSwaps, largeSwapAmount) + default: + log.Fatalf("invalid operation: %d", desiredOperation) + } +} + +func createManyRandomPositions(igniteClient cosmosclient.Client, poolId uint64, numPositions int) { + minTick, maxTick := cltypes.MinTick, cltypes.MaxTick + log.Println(minTick, " ", maxTick) for i := 0; i < numPositions; i++ { var ( // 1 to 9. These are localosmosis keyring test accounts with names such as: @@ -112,18 +156,79 @@ func main() { tokensDesired = sdk.NewCoins(tokenDesired0, tokenDesired1) ) - log.Println("creating position: pool id", expectedPoolId, "accountName", accountName, "lowerTick", lowerTick, "upperTick", upperTick, "token0Desired", tokenDesired0, "tokenDesired1", tokenDesired1, "defaultMinAmount", defaultMinAmount) + runMessageWithRetries(func() error { + _, _, _, err := createPosition(igniteClient, expectedPoolId, accountName, lowerTick, upperTick, tokensDesired, defaultMinAmount, defaultMinAmount) + return err + }) + } +} + +func swapRandomSmallAmountsContinuously(igniteClient cosmosclient.Client, poolId uint64, numSwaps int) { + for i := 0; i < numSwaps; i++ { + var ( + randAccountNum = rand.Intn(8) + 1 + accountName = fmt.Sprintf("%s%d", accountNamePrefix, randAccountNum) + + isToken0In = rand.Intn(2) == 0 + + tokenOutMinAmount = sdk.OneInt() + ) + + tokenInDenom := denom0 + tokenOutDenom := denom1 + if !isToken0In { + tokenInDenom = denom1 + tokenOutDenom = denom0 + } + tokenInCoin := sdk.NewCoin(tokenInDenom, sdk.NewInt(rand.Int63n(maxAmountSingleSwap))) + + runMessageWithRetries(func() error { + _, err := makeSwap(igniteClient, expectedPoolId, accountName, tokenInCoin, tokenOutDenom, tokenOutMinAmount) + return err + }) + } + + log.Println("finished swapping, num swaps done", numSwaps) +} + +func swapGivenLargeAmountsBothDirections(igniteClient cosmosclient.Client, poolId uint64, numSwaps int, largeStartAmount int64) { + var ( + randAccountNum = rand.Intn(8) + 1 + accountName = fmt.Sprintf("%s%d", accountNamePrefix, randAccountNum) + + isToken0In = rand.Intn(2) == 0 + + tokenOutMinAmount = sdk.OneInt() + ) + + tokenInDenom := denom0 + tokenOutDenom := denom1 + if !isToken0In { + tokenInDenom = denom1 + tokenOutDenom = denom0 + } + + tokenInCoin := sdk.NewCoin(tokenInDenom, sdk.NewInt(largeStartAmount)) + + for i := 0; i < numSwaps; i++ { + runMessageWithRetries(func() error { + tokenOut, err := makeSwap(igniteClient, expectedPoolId, accountName, tokenInCoin, tokenOutDenom, tokenOutMinAmount) - maxRetries := 100 - for j := 0; j < maxRetries; j++ { - amt0, amt1, liquidity := createPosition(igniteClient, expectedPoolId, accountName, lowerTick, upperTick, tokensDesired, defaultMinAmount, defaultMinAmount) if err == nil { - log.Println("created position: amt0", amt0, "amt1", amt1, "liquidity", liquidity) - break + // Swap the resulting amount out back while accounting for spread factor. + // This is to make sure we can continue swapping back and forth and not run + // out of funds or liquidity. + tempTokenInDenom := tokenInCoin.Denom + // new token in = token out / (1 - spread factor) + tokenInCoin = sdk.NewCoin(tokenOutDenom, tokenOut.ToDec().Quo(sdk.OneDec().Sub(defaultSpreadFactor)).RoundInt()) + tokenOutDenom = tempTokenInDenom } - time.Sleep(8 * time.Second) - } + + return err + }) } + + log.Println("finished swapping, num swaps done", numSwaps) } func createPool(igniteClient cosmosclient.Client, accountName string) uint64 { @@ -132,7 +237,7 @@ func createPool(igniteClient cosmosclient.Client, accountName string) uint64 { Denom1: denom0, Denom0: denom1, TickSpacing: 1, - SpreadFactor: sdk.ZeroDec(), + SpreadFactor: defaultSpreadFactor, } txResp, err := igniteClient.BroadcastTx(accountName, msg) if err != nil { @@ -145,11 +250,13 @@ func createPool(igniteClient cosmosclient.Client, accountName string) uint64 { return resp.PoolID } -func createPosition(client cosmosclient.Client, poolId uint64, senderKeyringAccountName string, lowerTick int64, upperTick int64, tokensProvided sdk.Coins, tokenMinAmount0, tokenMinAmount1 sdk.Int) (amountCreated0, amountCreated1 sdk.Int, liquidityCreated sdk.Dec) { +func createPosition(client cosmosclient.Client, poolId uint64, senderKeyringAccountName string, lowerTick int64, upperTick int64, tokensProvided sdk.Coins, tokenMinAmount0, tokenMinAmount1 sdk.Int) (amountCreated0, amountCreated1 sdk.Int, liquidityCreated sdk.Dec, err error) { accountMutex.Lock() // Lock access to getAccountAddressFromKeyring senderAddress := getAccountAddressFromKeyring(client, senderKeyringAccountName) accountMutex.Unlock() // Unlock access to getAccountAddressFromKeyring + log.Println("creating position: pool id", expectedPoolId, "accountName", senderKeyringAccountName, "lowerTick", lowerTick, "upperTick", upperTick, "token0Desired", tokensProvided[0], "tokenDesired1", tokensProvided[1], "defaultMinAmount", defaultMinAmount) + msg := &cltypes.MsgCreatePosition{ PoolId: poolId, Sender: senderAddress, @@ -161,13 +268,45 @@ func createPosition(client cosmosclient.Client, poolId uint64, senderKeyringAcco } txResp, err := client.BroadcastTx(senderKeyringAccountName, msg) if err != nil { - log.Fatal(err) + return sdk.Int{}, sdk.Int{}, sdk.Dec{}, err } resp := cltypes.MsgCreatePositionResponse{} if err := txResp.Decode(&resp); err != nil { - log.Fatal(err) + return sdk.Int{}, sdk.Int{}, sdk.Dec{}, err } - return resp.Amount0, resp.Amount1, resp.LiquidityCreated + log.Println("created position: amt0", resp.Amount0, "amt1", resp.Amount1, "liquidity", resp.LiquidityCreated) + return resp.Amount0, resp.Amount1, resp.LiquidityCreated, nil +} + +func makeSwap(client cosmosclient.Client, poolId uint64, senderKeyringAccountName string, tokenInCoin sdk.Coin, tokenOutDenom string, tokenOutMinAmount sdk.Int) (sdk.Int, error) { + accountMutex.Lock() // Lock access to getAccountAddressFromKeyring + senderAddress := getAccountAddressFromKeyring(client, senderKeyringAccountName) + accountMutex.Unlock() // Unlock access to getAccountAddressFromKeyring + + log.Println("making swap in: pool id", expectedPoolId, "tokenIn", tokenInCoin, "tokenOutDenom", tokenOutDenom, "tokenOutMinAmount", tokenOutMinAmount, "from", senderKeyringAccountName) + + msg := &poolmanagertypes.MsgSwapExactAmountIn{ + Sender: senderAddress, + Routes: []poolmanagertypes.SwapAmountInRoute{ + { + PoolId: expectedPoolId, + TokenOutDenom: tokenOutDenom, + }, + }, + TokenIn: tokenInCoin, + TokenOutMinAmount: tokenOutMinAmount, + } + txResp, err := client.BroadcastTx(senderKeyringAccountName, msg) + if err != nil { + return sdk.Int{}, err + } + resp := poolmanagertypes.MsgSwapExactAmountInResponse{} + if err := txResp.Decode(&resp); err != nil { + return sdk.Int{}, err + } + + log.Println("swap made, token out amount: ", resp.TokenOutAmount) + return resp.TokenOutAmount, nil } func getAccountAddressFromKeyring(igniteClient cosmosclient.Client, accountName string) string { @@ -193,6 +332,24 @@ func getClientHomePath() string { return currentUser.HomeDir + localosmosisFromHomePath } +func runMessageWithRetries(runMsg func() error) { + maxRetries := 100 + var err error + for j := 0; j < maxRetries; j++ { + err := runMsg() + if err != nil { + log.Println("retrying, error occurred while creating position: ", err) + time.Sleep(8 * time.Second) + } else { + time.Sleep(200 * time.Millisecond) + break + } + } + if err != nil { + log.Fatal(err) + } +} + func roundTickDown(tickIndex int64, tickSpacing int64) int64 { // Round the tick index down to the nearest tick spacing if the tickIndex is in between authorized tick values // Note that this is Euclidean modulus.