Skip to content

Commit

Permalink
feat: slinky patch (#40)
Browse files Browse the repository at this point in the history
* slinky patch

* add missing timestamp market

* bump OPinit
  • Loading branch information
beer-1 authored May 10, 2024
1 parent 81e0ae4 commit 26a3f86
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 64 deletions.
24 changes: 21 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ import (
auctionante "github.com/skip-mev/block-sdk/v2/x/auction/ante"
auctionkeeper "github.com/skip-mev/block-sdk/v2/x/auction/keeper"
auctiontypes "github.com/skip-mev/block-sdk/v2/x/auction/types"
marketmap "github.com/skip-mev/slinky/x/marketmap"
marketmapkeeper "github.com/skip-mev/slinky/x/marketmap/keeper"
marketmaptypes "github.com/skip-mev/slinky/x/marketmap/types"
"github.com/skip-mev/slinky/x/oracle"
oraclekeeper "github.com/skip-mev/slinky/x/oracle/keeper"
oracletypes "github.com/skip-mev/slinky/x/oracle/types"
Expand Down Expand Up @@ -236,6 +239,7 @@ type MinitiaApp struct {
AuctionKeeper *auctionkeeper.Keeper // x/auction keeper used to process bids for TOB auctions
PacketForwardKeeper *packetforwardkeeper.Keeper
OracleKeeper *oraclekeeper.Keeper // x/oracle keeper used for the slinky oracle
MarketMapKeeper *marketmapkeeper.Keeper
ForwardingKeeper *forwardingkeeper.Keeper

// make scoped keepers public for test purposes
Expand Down Expand Up @@ -293,7 +297,7 @@ func NewMinitiaApp(
feegrant.StoreKey, icahosttypes.StoreKey, icacontrollertypes.StoreKey,
icaauthtypes.StoreKey, ibcfeetypes.StoreKey, movetypes.StoreKey, opchildtypes.StoreKey,
auctiontypes.StoreKey, packetforwardtypes.StoreKey, oracletypes.StoreKey,
ibchookstypes.StoreKey, forwardingtypes.StoreKey,
ibchookstypes.StoreKey, forwardingtypes.StoreKey, marketmaptypes.StoreKey,
)
tkeys := storetypes.NewTransientStoreKeys(forwardingtypes.TransientStoreKey)
memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -371,14 +375,25 @@ func NewMinitiaApp(
/////////////////////////////////

// initialize oracle keeper
marketMapKeeper := marketmapkeeper.NewKeeper(
runtime.NewKVStoreService(keys[marketmaptypes.StoreKey]),
appCodec,
authorityAccAddr,
)
app.MarketMapKeeper = marketMapKeeper

oracleKeeper := oraclekeeper.NewKeeper(
runtime.NewKVStoreService(keys[oracletypes.StoreKey]),
appCodec,
nil,
marketMapKeeper,
authorityAccAddr,
)
app.OracleKeeper = &oracleKeeper

// Add the oracle keeper as a hook to market map keeper so new market map entries can be created
// and propogated to the oracle keeper.
app.MarketMapKeeper.SetHooks(app.OracleKeeper.Hooks())

app.OPChildKeeper = opchildkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[opchildtypes.StoreKey]),
Expand Down Expand Up @@ -741,6 +756,7 @@ func NewMinitiaApp(
forwarding.NewAppModule(app.ForwardingKeeper),
// slinky modules
oracle.NewAppModule(appCodec, *app.OracleKeeper),
marketmap.NewAppModule(appCodec, app.MarketMapKeeper),
)

if err := app.setupIndexer(appOpts, homePath, ac, vc, appCodec); err != nil {
Expand Down Expand Up @@ -775,6 +791,7 @@ func NewMinitiaApp(
movetypes.ModuleName,
ibcexported.ModuleName,
oracletypes.ModuleName,
marketmaptypes.ModuleName,
)

app.ModuleManager.SetOrderEndBlockers(
Expand All @@ -783,6 +800,7 @@ func NewMinitiaApp(
feegrant.ModuleName,
group.ModuleName,
oracletypes.ModuleName,
marketmaptypes.ModuleName,
forwardingtypes.ModuleName,
)

Expand All @@ -797,7 +815,7 @@ func NewMinitiaApp(
upgradetypes.ModuleName, feegrant.ModuleName, consensusparamtypes.ModuleName, ibcexported.ModuleName,
ibctransfertypes.ModuleName, ibcnfttransfertypes.ModuleName, icatypes.ModuleName, icaauthtypes.ModuleName,
ibcfeetypes.ModuleName, consensusparamtypes.ModuleName, auctiontypes.ModuleName, oracletypes.ModuleName,
packetforwardtypes.ModuleName, ibchookstypes.ModuleName, forwardingtypes.ModuleName,
marketmaptypes.ModuleName, packetforwardtypes.ModuleName, ibchookstypes.ModuleName, forwardingtypes.ModuleName,
}

app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...)
Expand Down
60 changes: 54 additions & 6 deletions app/genesis.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package app

import (
"encoding/hex"
"encoding/json"

"cosmossdk.io/core/address"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/module"
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
Expand All @@ -14,11 +16,13 @@ import (

l2slinky "github.com/initia-labs/OPinit/x/opchild/l2slinky"
opchildtypes "github.com/initia-labs/OPinit/x/opchild/types"
"github.com/initia-labs/initia/app/genesis_markets"
movetypes "github.com/initia-labs/initia/x/move/types"
"github.com/initia-labs/movevm/precompile"

auctiontypes "github.com/skip-mev/block-sdk/v2/x/auction/types"
slinkytypes "github.com/skip-mev/slinky/pkg/types"
marketmaptypes "github.com/skip-mev/slinky/x/marketmap/types"
oracletypes "github.com/skip-mev/slinky/x/oracle/types"
)

Expand All @@ -32,30 +36,74 @@ import (
type GenesisState map[string]json.RawMessage

// NewDefaultGenesisState generates the default state for the application.
func NewDefaultGenesisState(cdc codec.JSONCodec, mbm module.BasicManager, denom string) GenesisState {
func NewDefaultGenesisState(cdc codec.Codec, mbm module.BasicManager, denom string) GenesisState {
return GenesisState(mbm.DefaultGenesis(cdc)).
ConfigureMinGasPrices(cdc).
ConfigureICA(cdc).
ConfigureMoveStdlib(cdc).
ConfigureIBCAllowedClients(cdc).
ConfigureAuctionFee(cdc, denom).
AddTimestampCurrencyPair(cdc)
AddMarketData(cdc, cdc.InterfaceRegistry().SigningContext().AddressCodec())
}

func (genState GenesisState) AddTimestampCurrencyPair(cdc codec.JSONCodec) GenesisState {
func (genState GenesisState) AddMarketData(cdc codec.JSONCodec, ac address.Codec) GenesisState {
var oracleGenState oracletypes.GenesisState
cdc.MustUnmarshalJSON(genState[oracletypes.ModuleName], &oracleGenState)

cp, err := slinkytypes.CurrencyPairFromString(l2slinky.ReservedCPTimestamp)
var marketGenState marketmaptypes.GenesisState
cdc.MustUnmarshalJSON(genState[marketmaptypes.ModuleName], &marketGenState)

// Load initial markets
markets, err := genesis_markets.ReadMarketsFromFile(genesis_markets.GenesisMarkets)
if err != nil {
panic(err)
}
marketGenState.MarketMap = genesis_markets.ToMarketMap(markets)

// Skip Admin account.
adminAddrBz, err := hex.DecodeString("51B89E89D58FFB3F9DB66263FF10A216CF388A0E")
if err != nil {
panic(err)
}

oracleGenState.CurrencyPairGenesis = append(oracleGenState.CurrencyPairGenesis, oracletypes.CurrencyPairGenesis{
adminAddr, err := ac.BytesToString(adminAddrBz)
if err != nil {
panic(err)
}

marketGenState.Params.MarketAuthorities = []string{adminAddr}
marketGenState.Params.Admin = adminAddr

var id uint64

// Initialize all markets plus ReservedCPTimestamp
currencyPairGenesis := make([]oracletypes.CurrencyPairGenesis, len(markets)+1)
cp, err := slinkytypes.CurrencyPairFromString(l2slinky.ReservedCPTimestamp)
if err != nil {
panic(err)
}
currencyPairGenesis[id] = oracletypes.CurrencyPairGenesis{
CurrencyPair: cp,
CurrencyPairPrice: nil,
Nonce: 0,
})
Id: id,
}
id++
for i, market := range markets {
currencyPairGenesis[i+1] = oracletypes.CurrencyPairGenesis{
CurrencyPair: market.Ticker.CurrencyPair,
CurrencyPairPrice: nil,
Nonce: 0,
Id: id,
}
id++
}

oracleGenState.CurrencyPairGenesis = currencyPairGenesis
oracleGenState.NextId = id

// write the updates to genState
genState[marketmaptypes.ModuleName] = cdc.MustMarshalJSON(&marketGenState)
genState[oracletypes.ModuleName] = cdc.MustMarshalJSON(&oracleGenState)
return genState
}
Expand Down
37 changes: 18 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
cosmossdk.io/tools/confix v0.1.1
cosmossdk.io/x/feegrant v0.1.0
cosmossdk.io/x/upgrade v0.1.1
github.com/cometbft/cometbft v0.38.6
github.com/cometbft/cometbft v0.38.7
github.com/cosmos/cosmos-db v1.0.2
github.com/cosmos/cosmos-sdk v0.50.6
github.com/cosmos/go-bip39 v1.0.0
Expand All @@ -25,8 +25,8 @@ require (
github.com/cosmos/ibc-go/v8 v8.2.0
github.com/golang/mock v1.6.0
github.com/gorilla/mux v1.8.1
github.com/initia-labs/OPinit v0.2.8
github.com/initia-labs/initia v0.2.8
github.com/initia-labs/OPinit v0.2.9
github.com/initia-labs/initia v0.2.9
github.com/initia-labs/kvindexer v0.1.3
github.com/initia-labs/kvindexer/submodules/block v0.1.0
github.com/initia-labs/kvindexer/submodules/move-nft v0.1.2
Expand All @@ -38,7 +38,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/rakyll/statik v0.1.7
github.com/skip-mev/block-sdk/v2 v2.1.1
github.com/skip-mev/slinky v0.3.2
github.com/skip-mev/slinky v0.4.2
github.com/spf13/cast v1.6.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
Expand All @@ -54,7 +54,7 @@ require (
cloud.google.com/go/storage v1.37.0 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/x/tx v0.13.2 // indirect
cosmossdk.io/x/tx v0.13.3 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
Expand Down Expand Up @@ -91,10 +91,10 @@ require (
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.1.2 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/interchain-security/v5 v5.0.0-alpha1 // indirect
github.com/cosmos/interchain-security/v5 v5.0.0-rc0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/cosmos/relayer/v2 v2.5.2 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect
github.com/creachadair/atomicfile v0.3.1 // indirect
github.com/creachadair/tomledit v0.0.24 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
Expand All @@ -107,8 +107,8 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
github.com/emicklei/dot v1.6.1 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/ethereum/go-ethereum v1.13.14 // indirect
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
github.com/ethereum/go-ethereum v1.14.2 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand Down Expand Up @@ -141,7 +141,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.7.3 // indirect
github.com/hashicorp/go-getter v1.7.4 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-metrics v0.5.3 // indirect
Expand Down Expand Up @@ -181,7 +181,7 @@ require (
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/petermattis/goid v0.0.0-20231207134359-e60b3f734c67 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
Expand Down Expand Up @@ -217,21 +217,21 @@ require (
go.opentelemetry.io/otel/trace v1.22.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.162.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240304212257-790db918fca8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down Expand Up @@ -261,9 +261,8 @@ replace (

// initia custom
replace (
github.com/cometbft/cometbft => github.com/initia-labs/cometbft v0.0.0-20240425025334-db711cb7c25d
github.com/cometbft/cometbft => github.com/initia-labs/cometbft v0.0.0-20240503082631-d98d5e638a38
github.com/cosmos/cosmos-sdk => github.com/initia-labs/cosmos-sdk v0.0.0-20240502043911-a4bdb8e06769
github.com/cosmos/iavl => github.com/initia-labs/iavl v0.0.0-20240415085037-7e81233cdd9e
github.com/cosmos/ibc-go/v8 => github.com/initia-labs/ibc-go/v8 v8.0.0-20240419124350-4275a05abe2c
github.com/skip-mev/slinky => github.com/initia-labs/slinky v0.0.0-20240418051646-d45167cc66b1
)
Loading

0 comments on commit 26a3f86

Please sign in to comment.