Created
May 22, 2022 15:37
-
-
Save karzak/9eaffefe0047f2c113710ce15b39a425 to your computer and use it in GitHub Desktop.
Calculating UST/LUNA Deposits in AMM Pools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module github.com/kava-labs/kava-testnet-scripts/kava-9/terra-snapshots | |
go 1.18 | |
require ( | |
github.com/cosmos/cosmos-sdk v0.44.5 | |
github.com/kava-labs/kava v0.16.1 | |
github.com/tendermint/tendermint v0.34.15 | |
) | |
require ( | |
filippo.io/edwards25519 v1.0.0-beta.2 // indirect | |
github.com/99designs/keyring v1.1.6 // indirect | |
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect | |
github.com/DataDog/zstd v1.4.5 // indirect | |
github.com/armon/go-metrics v0.3.9 // indirect | |
github.com/beorn7/perks v1.0.1 // indirect | |
github.com/bgentry/speakeasy v0.1.0 // indirect | |
github.com/btcsuite/btcd v0.22.0-beta // indirect | |
github.com/cespare/xxhash v1.1.0 // indirect | |
github.com/cespare/xxhash/v2 v2.1.2 // indirect | |
github.com/confio/ics23/go v0.6.6 // indirect | |
github.com/cosmos/btcutil v1.0.4 // indirect | |
github.com/cosmos/cosmos-proto v0.0.0-20211020182451-c7ca7198c2f8 // indirect | |
github.com/cosmos/go-bip39 v1.0.0 // indirect | |
github.com/cosmos/iavl v0.17.3 // indirect | |
github.com/cosmos/ibc-go v1.2.5 // indirect | |
github.com/cosmos/ledger-cosmos-go v0.11.1 // indirect | |
github.com/cosmos/ledger-go v0.9.2 // indirect | |
github.com/danieljoos/wincred v1.0.2 // indirect | |
github.com/davecgh/go-spew v1.1.1 // indirect | |
github.com/dgraph-io/badger/v2 v2.2007.2 // indirect | |
github.com/dgraph-io/ristretto v0.0.3 // indirect | |
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect | |
github.com/dustin/go-humanize v1.0.0 // indirect | |
github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b // indirect | |
github.com/felixge/httpsnoop v1.0.1 // indirect | |
github.com/fsnotify/fsnotify v1.5.1 // indirect | |
github.com/go-kit/kit v0.12.0 // indirect | |
github.com/go-kit/log v0.2.0 // indirect | |
github.com/go-logfmt/logfmt v0.5.1 // indirect | |
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect | |
github.com/gogo/gateway v1.1.0 // indirect | |
github.com/gogo/protobuf v1.3.3 // indirect | |
github.com/golang/protobuf v1.5.2 // indirect | |
github.com/golang/snappy v0.0.3 // indirect | |
github.com/google/btree v1.0.0 // indirect | |
github.com/gorilla/handlers v1.5.1 // indirect | |
github.com/gorilla/mux v1.8.0 // indirect | |
github.com/gorilla/websocket v1.4.2 // indirect | |
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect | |
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect | |
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect | |
github.com/gtank/merlin v0.1.1 // indirect | |
github.com/gtank/ristretto255 v0.1.2 // indirect | |
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect | |
github.com/hashicorp/golang-lru v0.5.4 // indirect | |
github.com/hashicorp/hcl v1.0.0 // indirect | |
github.com/hdevalence/ed25519consensus v0.0.0-20210204194344-59a8610d2b87 // indirect | |
github.com/inconshreveable/mousetrap v1.0.0 // indirect | |
github.com/jmhodges/levigo v1.0.0 // indirect | |
github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d // indirect | |
github.com/libp2p/go-buffer-pool v0.0.2 // indirect | |
github.com/magiconair/properties v1.8.5 // indirect | |
github.com/mattn/go-isatty v0.0.14 // indirect | |
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect | |
github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 // indirect | |
github.com/mitchellh/mapstructure v1.4.2 // indirect | |
github.com/mtibben/percent v0.2.1 // indirect | |
github.com/pelletier/go-toml v1.9.4 // 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 | |
github.com/prometheus/client_golang v1.11.0 // indirect | |
github.com/prometheus/client_model v0.2.0 // indirect | |
github.com/prometheus/common v0.30.0 // indirect | |
github.com/prometheus/procfs v0.7.3 // indirect | |
github.com/rakyll/statik v0.1.7 // indirect | |
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect | |
github.com/regen-network/cosmos-proto v0.3.1 // indirect | |
github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa // indirect | |
github.com/spf13/afero v1.6.0 // indirect | |
github.com/spf13/cast v1.4.1 // indirect | |
github.com/spf13/cobra v1.2.1 // indirect | |
github.com/spf13/jwalterweatherman v1.1.0 // indirect | |
github.com/spf13/pflag v1.0.5 // indirect | |
github.com/spf13/viper v1.9.0 // indirect | |
github.com/stretchr/testify v1.7.0 // indirect | |
github.com/subosito/gotenv v1.2.0 // indirect | |
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca // indirect | |
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect | |
github.com/tendermint/btcd v0.1.1 // indirect | |
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 // indirect | |
github.com/tendermint/go-amino v0.16.0 // indirect | |
github.com/tendermint/tm-db v0.6.6 // indirect | |
github.com/zondax/hid v0.9.0 // indirect | |
go.etcd.io/bbolt v1.3.6 // indirect | |
golang.org/x/crypto v0.0.0-20210915214749-c084706c2272 // indirect | |
golang.org/x/net v0.0.0-20211005001312-d4b1ae081e3b // indirect | |
golang.org/x/sys v0.0.0-20211004093028-2c5d950f24ef // indirect | |
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect | |
golang.org/x/text v0.3.7 // indirect | |
google.golang.org/genproto v0.0.0-20210917145530-b395a37504d4 // indirect | |
google.golang.org/grpc v1.42.0 // indirect | |
google.golang.org/protobuf v1.27.1 // indirect | |
gopkg.in/ini.v1 v1.63.2 // indirect | |
gopkg.in/yaml.v2 v2.4.0 // indirect | |
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect | |
sigs.k8s.io/yaml v1.2.0 // indirect | |
) | |
replace ( | |
// Use the cosmos keyring code | |
github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 | |
// Use patched version based on v0.44.5 - note: not state compatiable | |
github.com/cosmos/cosmos-sdk => github.com/kava-labs/cosmos-sdk v0.44.5-kava.1 | |
// See https://github.com/cosmos/cosmos-sdk/pull/10401, https://github.com/cosmos/cosmos-sdk/commit/0592ba6158cd0bf49d894be1cef4faeec59e8320 | |
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0 | |
// Use the cosmos modified protobufs | |
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 | |
// Fix rocksdb for high traffic situations | |
github.com/tecbot/gorocksdb => github.com/cosmos/gorocksdb v1.2.0 | |
// Make sure that only one version of tendermint is imported | |
github.com/tendermint/tendermint => github.com/tendermint/tendermint v0.34.15 | |
// Make sure that we use grpc compatible with cosmos | |
google.golang.org/grpc => google.golang.org/grpc v1.33.2 | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
sdk "github.com/cosmos/cosmos-sdk/types" | |
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" | |
tmjson "github.com/tendermint/tendermint/libs/json" | |
tmtypes "github.com/tendermint/tendermint/types" | |
"github.com/kava-labs/kava/app" | |
swaptypes "github.com/kava-labs/kava/x/swap/types" | |
) | |
func main() { | |
app.SetSDKConfig() | |
genFile := "./1375287-export.json" | |
genDoc, err := tmtypes.GenesisDocFromFile(genFile) | |
if err != nil { | |
panic(err) | |
} | |
encodingConfig := app.MakeEncodingConfig() | |
var appMap genutiltypes.AppMap | |
err = tmjson.Unmarshal(genDoc.AppState, &appMap) | |
if err != nil { | |
panic(err) | |
} | |
genState := app.GenesisState(appMap) | |
var swapGenState swaptypes.GenesisState | |
encodingConfig.Marshaler.MustUnmarshalJSON(genState[swaptypes.ModuleName], &swapGenState) | |
ustUsdxPoolNmae := "ibc/B448C0CA358B958301D328CCDC5D5AD642FC30A6D3AE106FF721DB315F3DDE5C:usdx" | |
lunaUsdxPoolName := "ibc/B8AF5D92165F35AB31F3FC7C7B444B9D240760FA5D406C49D24862BD0284E395:usdx" | |
var ustPoolRecord swaptypes.PoolRecord | |
var lunaPoolRecord swaptypes.PoolRecord | |
for _, pr := range swapGenState.GetPoolRecords() { | |
if pr.PoolID == ustUsdxPoolNmae { | |
ustPoolRecord = pr | |
} | |
if pr.PoolID == lunaUsdxPoolName { | |
lunaPoolRecord = pr | |
} | |
} | |
var ustShareRecords swaptypes.ShareRecords | |
var lunaShareRecords swaptypes.ShareRecords | |
for _, sr := range swapGenState.GetShareRecords() { | |
if sr.PoolID == ustUsdxPoolNmae { | |
ustShareRecords = append(ustShareRecords, sr) | |
} | |
if sr.PoolID == lunaUsdxPoolName { | |
lunaShareRecords = append(lunaShareRecords, sr) | |
} | |
} | |
USTpool, err := swaptypes.NewDenominatedPoolWithExistingShares(ustPoolRecord.Reserves(), ustPoolRecord.TotalShares) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("%s\n", USTpool.Reserves()) | |
lunaPool, err := swaptypes.NewDenominatedPoolWithExistingShares(lunaPoolRecord.Reserves(), lunaPoolRecord.TotalShares) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("%s\n", lunaPool.Reserves()) | |
ustPoolDeposits := make(map[string]sdk.Coin) | |
lunaPoolDeposits := make(map[string]sdk.Coin) | |
for _, sr := range ustShareRecords { | |
ustPoolDeposits[sr.Depositor.String()] = USTpool.ShareValue(sr.SharesOwned)[0] | |
} | |
for _, sr := range lunaShareRecords { | |
lunaPoolDeposits[sr.Depositor.String()] = lunaPool.ShareValue(sr.SharesOwned)[0] | |
} | |
items := 0 | |
for k, v := range ustPoolDeposits { | |
if items < 10 { | |
fmt.Printf("Depositor: %s\tAmount: %s\n", k, v) | |
} | |
items++ | |
} | |
items = 0 | |
for k, v := range lunaPoolDeposits { | |
if items < 10 { | |
fmt.Printf("Depositor: %s\tAmount: %s\n", k, v) | |
} | |
items++ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment