Skip to content

Commit

Permalink
feat(modules): add oracle module
Browse files Browse the repository at this point in the history
  • Loading branch information
SpekalsG3 committed Oct 1, 2024
1 parent 96e17bc commit 7937df9
Show file tree
Hide file tree
Showing 146 changed files with 35,053 additions and 101 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ build/

dist/
data/

.envrc
68 changes: 37 additions & 31 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ import (
ibccm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
"github.com/spf13/cast"

"github.com/archway-network/archway/app/appconst"
"github.com/archway-network/archway/app/keepers"
"github.com/archway-network/archway/x/cwfees"
"github.com/archway-network/archway/x/genmsg"
Expand Down Expand Up @@ -154,6 +155,10 @@ import (
cwicakeeper "github.com/archway-network/archway/x/cwica/keeper"
cwicatypes "github.com/archway-network/archway/x/cwica/types"

oracle "github.com/archway-network/archway/x/oracle"
oraclekeeper "github.com/archway-network/archway/x/oracle/keeper"
oracletypes "github.com/archway-network/archway/x/oracle/types"

extendedGov "github.com/archway-network/archway/x/gov"

"github.com/CosmWasm/wasmd/x/wasm"
Expand All @@ -162,35 +167,6 @@ import (
archway "github.com/archway-network/archway/types"
)

const appName = "Archway"

// We pull these out so we can set them with LDFLAGS in the Makefile
var (
NodeDir = ".archway"
Bech32Prefix = "archway"
)

// These constants are derived from the above variables.
// These are the ones we will want to use in the code, based on
// any overrides above
var (
// DefaultNodeHome default home directories for archwayd
DefaultNodeHome = os.ExpandEnv("$HOME/") + NodeDir

// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address
Bech32PrefixAccAddr = Bech32Prefix
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
Bech32PrefixAccPub = Bech32Prefix + sdk.PrefixPublic
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
Bech32PrefixValAddr = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixOperator
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
Bech32PrefixValPub = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixOperator + sdk.PrefixPublic
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
Bech32PrefixConsAddr = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
Bech32PrefixConsPub = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic
)

var (
// ModuleBasics defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration
Expand Down Expand Up @@ -229,6 +205,7 @@ var (
cwfees.AppModule{},
cwica.AppModuleBasic{},
cwerrors.AppModuleBasic{},
oracle.AppModuleBasic{},
)

// module account permissions
Expand All @@ -247,6 +224,7 @@ var (
wasmdTypes.ModuleName: {authtypes.Burner},
rewardsTypes.TreasuryCollector: {authtypes.Burner},
callbackTypes.ModuleName: nil,
oracletypes.ModuleName: nil,
}
)

Expand Down Expand Up @@ -317,7 +295,7 @@ func NewArchwayApp(
std.RegisterLegacyAminoCodec(legacyAmino)
std.RegisterInterfaces(interfaceRegistry)

bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
bApp := baseapp.NewBaseApp(appconst.AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)
Expand All @@ -335,6 +313,7 @@ func NewArchwayApp(
icacontrollertypes.StoreKey, icahosttypes.StoreKey, ibcfeetypes.StoreKey, crisistypes.StoreKey, group.StoreKey, nftkeeper.StoreKey, cwicatypes.StoreKey,

trackingTypes.StoreKey, rewardsTypes.StoreKey, callbackTypes.StoreKey, cwfees.ModuleName, cwerrorsTypes.StoreKey,
oracletypes.StoreKey,
)
tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey, cwerrorsTypes.TStoreKey)
memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -672,8 +651,19 @@ func NewArchwayApp(
logger,
)

app.Keepers.OracleKeeper = oraclekeeper.NewKeeper(
appCodec,
keys[oracletypes.StoreKey],
app.Keepers.AccountKeeper,
app.Keepers.BankKeeper,
app.Keepers.DistrKeeper,
app.Keepers.StakingKeeper,
app.Keepers.SlashingKeeper,
distrtypes.ModuleName,
)

app.Keepers.IBCHooksKeeper = ibchookskeeper.NewKeeper(keys[ibchookstypes.StoreKey])
ics20WasmHooks := ibchooks.NewWasmHooks(&app.Keepers.IBCHooksKeeper, nil, Bech32Prefix)
ics20WasmHooks := ibchooks.NewWasmHooks(&app.Keepers.IBCHooksKeeper, nil, appconst.Bech32Prefix)
hooksIcs4Wrapper := ibchooks.NewICS4Middleware(app.Keepers.IBCKeeper.ChannelKeeper, ics20WasmHooks)

var transferStack porttypes.IBCModule
Expand Down Expand Up @@ -759,6 +749,7 @@ func NewArchwayApp(
cwica.NewAppModule(appCodec, app.Keepers.CWICAKeeper, app.Keepers.AccountKeeper),
cwerrors.NewAppModule(app.appCodec, app.Keepers.CWErrorsKeeper, app.Keepers.WASMKeeper),
crisis.NewAppModule(&app.Keepers.CrisisKeeper, skipGenesisInvariants, app.getSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them
oracle.NewAppModule(appCodec, app.Keepers.OracleKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper),
)

// BasicModuleManager defines the module BasicManager is in charge of setting up basic,
Expand Down Expand Up @@ -801,6 +792,7 @@ func NewArchwayApp(
paramstypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
oracletypes.ModuleName,
// additional non simd modules
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
Expand Down Expand Up @@ -836,6 +828,7 @@ func NewArchwayApp(
upgradetypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
oracletypes.ModuleName,
// wasm
ibchookstypes.ModuleName,
wasmdTypes.ModuleName,
Expand Down Expand Up @@ -876,6 +869,7 @@ func NewArchwayApp(
upgradetypes.ModuleName,
vestingtypes.ModuleName,
consensusparamtypes.ModuleName,
oracletypes.ModuleName,
// additional non simd modules
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
Expand Down Expand Up @@ -1219,5 +1213,17 @@ func getAcceptedStargateQueries() wasmdKeeper.AcceptedStargateQueries {
"/archway.cwerrors.v1.Query/Errors": &cwerrorsTypes.QueryErrorsRequest{},
"/archway.callback.v1.Query/EstimateCallbackFees": &callbackTypes.QueryEstimateCallbackFeesRequest{},
"/archway.callback.v1.Query/Params": &callbackTypes.QueryParamsRequest{},
"/archway.oracle.v1.Query/ExchangeRate": new(oracletypes.QueryExchangeRateResponse),
"/archway.oracle.v1.Query/ExchangeRateTwap": new(oracletypes.QueryExchangeRateResponse),
"/archway.oracle.v1.Query/ExchangeRates": new(oracletypes.QueryExchangeRatesResponse),
"/archway.oracle.v1.Query/Actives": new(oracletypes.QueryActivesResponse),
"/archway.oracle.v1.Query/VoteTargets": new(oracletypes.QueryVoteTargetsResponse),
"/archway.oracle.v1.Query/FeederDelegation": new(oracletypes.QueryFeederDelegationResponse),
"/archway.oracle.v1.Query/MissCounter": new(oracletypes.QueryMissCounterResponse),
"/archway.oracle.v1.Query/AggregatePrevote": new(oracletypes.QueryAggregatePrevoteResponse),
"/archway.oracle.v1.Query/AggregatePrevotes": new(oracletypes.QueryAggregatePrevotesResponse),
"/archway.oracle.v1.Query/AggregateVote": new(oracletypes.QueryAggregateVoteResponse),
"/archway.oracle.v1.Query/AggregateVotes": new(oracletypes.QueryAggregateVotesResponse),
"/archway.oracle.v1.Query/Params": new(oracletypes.QueryParamsResponse),
}
}
36 changes: 36 additions & 0 deletions app/appconst/appconst.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package appconst

import (
"os"

sdk "github.com/cosmos/cosmos-sdk/types"
)

const AppName = "Archway"

// We pull these out so we can set them with LDFLAGS in the Makefile
var (
NodeDir = ".archway"
Bech32Prefix = "archway"
)

// These constants are derived from the above variables.
// These are the ones we will want to use in the code, based on
// any overrides above
var (
// DefaultNodeHome default home directories for archwayd
DefaultNodeHome = os.ExpandEnv("$HOME/") + NodeDir

// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address
Bech32PrefixAccAddr = Bech32Prefix
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
Bech32PrefixAccPub = Bech32Prefix + sdk.PrefixPublic
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
Bech32PrefixValAddr = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixOperator
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
Bech32PrefixValPub = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixOperator + sdk.PrefixPublic
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
Bech32PrefixConsAddr = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
Bech32PrefixConsPub = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic
)
2 changes: 2 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
callbackKeeper "github.com/archway-network/archway/x/callback/keeper"
cwerrorsKeeper "github.com/archway-network/archway/x/cwerrors/keeper"
cwicaKeeper "github.com/archway-network/archway/x/cwica/keeper"
oracleKeeper "github.com/archway-network/archway/x/oracle/keeper"
rewardsKeeper "github.com/archway-network/archway/x/rewards/keeper"
trackingKeeper "github.com/archway-network/archway/x/tracking/keeper"
)
Expand Down Expand Up @@ -69,4 +70,5 @@ type ArchwayKeepers struct {
CallbackKeeper callbackKeeper.Keeper
CWErrorsKeeper cwerrorsKeeper.Keeper
CWICAKeeper cwicaKeeper.Keeper
OracleKeeper oracleKeeper.Keeper
}
16 changes: 16 additions & 0 deletions app/prefix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package app

import (
"github.com/CosmWasm/wasmd/app"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func SetPrefixes() {
cfg := sdk.GetConfig()
cfg.SetBech32PrefixForAccount(app.Bech32PrefixAccAddr, app.Bech32PrefixAccPub)
cfg.SetBech32PrefixForValidator(app.Bech32PrefixValAddr, app.Bech32PrefixValPub)
cfg.SetBech32PrefixForConsensusNode(app.Bech32PrefixConsAddr, app.Bech32PrefixConsPub)
cfg.SetAddressVerifier(wasmtypes.VerifyAddressLen())
cfg.Seal()
}
3 changes: 2 additions & 1 deletion app/swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/cosmos/cosmos-sdk/server/api"

"github.com/archway-network/archway/app/appconst"
"github.com/archway-network/archway/docs"
"github.com/archway-network/archway/pkg/openapiconsole"
)
Expand All @@ -13,6 +14,6 @@ import (
func RegisterSwaggerAPI(apiSvr *api.Server) error {
// register app's OpenAPI routes.
apiSvr.Router.Handle("/static/swagger.min.json", http.FileServer(http.FS(docs.Docs)))
apiSvr.Router.HandleFunc("/", openapiconsole.Handler(appName+" Swagger UI", "/static/swagger.min.json"))
apiSvr.Router.HandleFunc("/", openapiconsole.Handler(appconst.AppName+" Swagger UI", "/static/swagger.min.json"))
return nil
}
4 changes: 2 additions & 2 deletions cmd/archwayd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"

"github.com/archway-network/archway/app"
"github.com/archway-network/archway/app/appconst"
)

const ArchwayASCII = `
Expand All @@ -29,7 +29,7 @@ func main() {

rootCmd.AddCommand(ensureLibWasmVM())

if err := svrcmd.Execute(rootCmd, "ARCHWAY", app.DefaultNodeHome); err != nil {
if err := svrcmd.Execute(rootCmd, "ARCHWAY", appconst.DefaultNodeHome); err != nil {
_, _ = fmt.Fprintln(rootCmd.OutOrStderr(), err)
os.Exit(1)
}
Expand Down
18 changes: 6 additions & 12 deletions cmd/archwayd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/server"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -33,21 +32,16 @@ import (

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

"github.com/archway-network/archway/app"
"github.com/archway-network/archway/app/appconst"
"github.com/archway-network/archway/app/params"
)

// NewRootCmd creates a new root command for archwayd. It is called once in the
// main function.
func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
cfg := sdk.GetConfig()
cfg.SetBech32PrefixForAccount(app.Bech32PrefixAccAddr, app.Bech32PrefixAccPub)
cfg.SetBech32PrefixForValidator(app.Bech32PrefixValAddr, app.Bech32PrefixValPub)
cfg.SetBech32PrefixForConsensusNode(app.Bech32PrefixConsAddr, app.Bech32PrefixConsPub)
cfg.SetAddressVerifier(wasmtypes.VerifyAddressLen())
cfg.Seal()
app.SetPrefixes()

encodingConfig := app.MakeEncodingConfig()
tempApp := app.NewArchwayApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, nil, tempDir(), 0, encodingConfig, simtestutil.NewAppOptionsWithFlagHome(tempDir()), []wasmkeeper.Option{})
Expand All @@ -59,7 +53,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
WithLegacyAmino(encodingConfig.Amino).
WithInput(os.Stdin).
WithAccountRetriever(authtypes.AccountRetriever{}).
WithHomeDir(app.DefaultNodeHome).
WithHomeDir(appconst.DefaultNodeHome).
WithViper("")

rootCmd := &cobra.Command{
Expand Down Expand Up @@ -123,7 +117,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {

func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
rootCmd.AddCommand(
genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
genutilcli.InitCmd(app.ModuleBasics, appconst.DefaultNodeHome),
tmcli.NewCompletionCmd(rootCmd, true),
// testnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}),
debug.Cmd(),
Expand All @@ -133,7 +127,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
ac := appCreator{
encCfg: encodingConfig,
}
server.AddCommands(rootCmd, app.DefaultNodeHome, ac.newApp, ac.appExport, addModuleInitFlags)
server.AddCommands(rootCmd, appconst.DefaultNodeHome, ac.newApp, ac.appExport, addModuleInitFlags)

// add keybase, auxiliary RPC, query, and tx child commands
rootCmd.AddCommand(
Expand Down Expand Up @@ -201,7 +195,7 @@ func txCommand() *cobra.Command {
}

func genesisCommand(encodingConfig params.EncodingConfig, cmds ...*cobra.Command) *cobra.Command {
cmd := genutilcli.GenesisCoreCommand(encodingConfig.TxConfig, app.ModuleBasics, app.DefaultNodeHome)
cmd := genutilcli.GenesisCoreCommand(encodingConfig.TxConfig, app.ModuleBasics, appconst.DefaultNodeHome)

for _, sub_cmd := range cmds {
cmd.AddCommand(sub_cmd)
Expand Down
Loading

0 comments on commit 7937df9

Please sign in to comment.