Skip to content

Commit

Permalink
feat: add oracle module (#791)
Browse files Browse the repository at this point in the history
* add: init oracle

* chore: adjustments

* more cleanups

* remove: sdk.Handler

* add: tmp fixes

* add: adjust tests

* chore: cleanup naming

* chore: more cleanups

* chore: more cleanups 2

* chore: finalize denom cleanups

* change: rename Denom to Pair

* fix: change DenomList to PairList

* change: VoteForTally.Denom=>Pair

* change: func param rename

* chore: docs

* chore: more renaming

* chore: rename denoms to pairs in query.proto

* change: rename denom to pair in oracle.proto

* change: rename denom to pair in genesis.proto

* change: rename denom to pair in hash.go

* change: rename SetLunaExchangeRate to SetExchangeRate

* change: rename SetLunaExchangeRateWithEvent to SetExchangeRateWithEvent

* change: rename DeleteLunaExchangeRate to DeleteExchangeRate

* change: rename GetLunaExchangeRate to GetExchangeRate

* change: rename IterateLunaExchangeRates to IterateExchangeRates

* fix: remove unappliable test

* fix: keeper_test.go

* chore: renames and removing unused vars

* change: remove set denom metadata from whitelist apply

* change: ballot_test.go shouldn't check for denom registration

* change: rename denom.go to pair_list.go

* add: vote parsing and partial testing

* add: duplicates logic check

* change: ParseTuplesStr logic to use pairs instead of denoms

* fix: adjust msgs_test.go

* change: temp disable rewards for oracles

* fix: adjust abci test part 1

* chore: adjust test oracle drop and oracle tally and test oracle reward band

* chore: skip multireward test adjustment

* chore: adjust TestOracleExchangeRate test

* chore: adjust last abci_test.go

* fix: last tests

* chore: adjust keeper Msgserver FeederDelegation test

* chore: adjust final test

* chore: lint

* chore: CHANGELOG.md

* change: Rename ErrUnknownDenom to ErrUnknownPair

* fix: null prefix string key to avoid prefix overlaps

* chore: clear docs denom=>pair

* chore: params renaming

* chore: clear docs denom=>pair

* fix: null suffix string for tobin tax keys

* chore: return param rename

* remove: pair_list_test.go useless tests

* chore: remove deprecated rest handlers

* chore: rename AttributeKeyDenom=>Pair

* chore: rename OrganizeBallotByDenom=>Pair

* chore: rename denom to pair in ballot.go

* chore: address TODO on pair being wrong on default params

* chore: more denom=>pair renames

* chore: denom=>pair msg_server.go

* chore: more denom=>pair renames

* chore: rename denom=>pair params_test.go

* chore: rename denom=>pair ballot.go

* chore: rename denom=>pair keeper_test.go

* chore: rename denom=>pair params.go

* chore: rename denom=>pair params.go

* chore: cleanup interface expected_keeper.go

* chore: renames denom=>pair keys.go

* chore: renames denom=>pair tally.go

* chore: lint

* chore: rename denom=>pair vote_target.go

* chore: rename denom=>pair querier.go

* chore: rename denom=>pair genesis.go

* change: rename references of sdk.DecCoins to ExchangeRateTuples from queries

* chore: refactor confusing tests

* chore: refactor confusing tests 2

* chore: refactor confusing tests 3

* remove l mentions

* remove messages array

* refactor exchange rate tuple function

* remove dead code

* change voter to feeder as in the message

* finish review Aggregate Exchange PreVote

* linter

* remove mentions to l

* refactor variable names in oracle abci

* Remove common.MicroUnit

* Clean up calls to sdk.NewDec

* Remove more usages of common.MicroUnit

* chore: cleanup TestOracleThreshold test

* add exchange rate vote

* change l mention

* fix comment

* remove mentions to l

* add: more tests

* chore: todo context

* chore: more cleanups

* chore: krw renames

* chore: remove references of Terra

* chore: more renamings

* chore: correct proto docs

* Remove references to Terra Luna

* Remove usages of terra, luna, and denom in docs

* Update 02_state.md

* Fix documentation regarding ordering of pair and exchange_rate

* Refactor OrganizeBallotByPair and struct name

Co-authored-by: Agent Smith <[email protected]>
Co-authored-by: NibiruHeisenberg <[email protected]>
  • Loading branch information
3 people authored Aug 9, 2022
1 parent 5b2f6a4 commit 8036504
Show file tree
Hide file tree
Showing 99 changed files with 19,067 additions and 180 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#801](https://github.com/NibiruChain/nibiru/pull/801) - remove unused pair constants
* [#788](https://github.com/NibiruChain/nibiru/pull/788) - add --overwrite flag to the nibid init call of localnet.sh

### Features
* [#791](https://github.com/NibiruChain/nibiru/pull/791) Add the x/oracle module

## [v0.12.1](https://github.com/NibiruChain/nibiru/releases/tag/v0.12.1) - 2022-08-04

* [#796](https://github.com/NibiruChain/nibiru/pull/796) - fix bug that caused that epochKeeper was nil when running epoch hook from Perp module
Expand Down
4 changes: 3 additions & 1 deletion app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ type AnteHandlerOptions struct {
IBCKeeper *ibckeeper.Keeper
}

/* NewAnteHandler returns and AnteHandler that checks and increments sequence
/*
NewAnteHandler returns and AnteHandler that checks and increments sequence
numbers, checks signatures and account numbers, and deducts fees from the first signer.
*/
func NewAnteHandler(options AnteHandlerOptions) (sdk.AnteHandler, error) {
Expand Down
3 changes: 2 additions & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func (app *NibiruApp) ExportAppStateAndValidators(

// prepare for fresh start at zero height
// NOTE zero height genesis is a temporary feature which will be deprecated
// in favor of export at a block height
//
// in favor of export at a block height
func (app *NibiruApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
applyAllowedAddrs := false

Expand Down
19 changes: 12 additions & 7 deletions app/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ import (
"github.com/NibiruChain/nibiru/x/testutil/testapp"
)

/* SetupTestingApp returns the TestingApp and default genesis state used to
initialize the testing app. */
/*
SetupTestingApp returns the TestingApp and default genesis state used to
initialize the testing app.
*/
func SetupNibiruTestingApp() (
testingApp ibctesting.TestingApp,
defaultGenesis map[string]json.RawMessage,
Expand Down Expand Up @@ -86,11 +89,13 @@ func TestIBCTestSuite(t *testing.T) {
suite.Run(t, new(IBCTestSuite))
}

/* NewIBCTestingTransferPath returns a "path" for testing.
A path contains two endpoints, 'EndpointA' and 'EndpointB' that correspond
to the order of the chains passed into the ibctesting.NewPath function.
A path is a pointer, and its values will be filled in as necessary during
the setup portion of testing.
/*
NewIBCTestingTransferPath returns a "path" for testing.
A path contains two endpoints, 'EndpointA' and 'EndpointB' that correspond
to the order of the chains passed into the ibctesting.NewPath function.
A path is a pointer, and its values will be filled in as necessary during
the setup portion of testing.
*/
func NewIBCTestingTransferPath(
chainA, chainB *ibctesting.TestChain,
Expand Down
9 changes: 5 additions & 4 deletions cmd/nibid/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,11 @@ commands, then builds the rosetta root command given a protocol buffers
serializer/deserializer.
Args:
rootCmd: The root command called once in the 'main.go' of 'nibid'.
encodingConfig: EncodingConfig specifies the concrete encoding types to use
for a given app. This is provided for compatibility between protobuf and
amino implementations.
rootCmd: The root command called once in the 'main.go' of 'nibid'.
encodingConfig: EncodingConfig specifies the concrete encoding types to use
for a given app. This is provided for compatibility between protobuf and
amino implementations.
*/
func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
cfg := sdk.GetConfig()
Expand Down
43 changes: 43 additions & 0 deletions proto/oracle/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
syntax = "proto3";
package nibiru.oracle.v1beta1;

import "gogoproto/gogo.proto";
import "oracle/v1beta1/oracle.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/NibiruChain/nibiru/x/oracle/types";

// GenesisState defines the oracle module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
repeated FeederDelegation feeder_delegations = 2 [(gogoproto.nullable) = false];
repeated ExchangeRateTuple exchange_rates = 3
[(gogoproto.castrepeated) = "ExchangeRateTuples", (gogoproto.nullable) = false];
repeated MissCounter miss_counters = 4 [(gogoproto.nullable) = false];
repeated AggregateExchangeRatePrevote aggregate_exchange_rate_prevotes = 5 [(gogoproto.nullable) = false];
repeated AggregateExchangeRateVote aggregate_exchange_rate_votes = 6 [(gogoproto.nullable) = false];
repeated TobinTax tobin_taxes = 7 [(gogoproto.nullable) = false];
}

// FeederDelegation is the address for where oracle feeder authority are
// delegated to. By default this struct is only used at genesis to feed in
// default feeder addresses.
message FeederDelegation {
string feeder_address = 1;
string validator_address = 2;
}

// MissCounter defines an miss counter and validator address pair used in
// oracle module's genesis state
message MissCounter {
string validator_address = 1;
uint64 miss_counter = 2;
}

// TobinTax defines a pair and tobin_tax pair used in
// oracle module's genesis state
message TobinTax {
string pair = 1;
string tobin_tax = 2
[(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
}
99 changes: 99 additions & 0 deletions proto/oracle/v1beta1/oracle.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
syntax = "proto3";
package nibiru.oracle.v1beta1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/NibiruChain/nibiru/x/oracle/types";

// Params defines the parameters for the oracle module.
message Params {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;

uint64 vote_period = 1 [(gogoproto.moretags) = "yaml:\"vote_period\""];
string vote_threshold = 2 [
(gogoproto.moretags) = "yaml:\"vote_threshold\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string reward_band = 3 [
(gogoproto.moretags) = "yaml:\"reward_band\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
uint64 reward_distribution_window = 4 [(gogoproto.moretags) = "yaml:\"reward_distribution_window\""];
repeated Pair whitelist = 5 [
(gogoproto.moretags) = "yaml:\"whitelist\"",
(gogoproto.castrepeated) = "PairList",
(gogoproto.nullable) = false
];
string slash_fraction = 6 [
(gogoproto.moretags) = "yaml:\"slash_fraction\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
uint64 slash_window = 7 [(gogoproto.moretags) = "yaml:\"slash_window\""];
string min_valid_per_window = 8 [
(gogoproto.moretags) = "yaml:\"min_valid_per_window\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

// Pair is the object that holds configuration of each pair.
message Pair {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

string name = 1 [(gogoproto.moretags) = "yaml:\"name\""];
string tobin_tax = 2 [
(gogoproto.moretags) = "yaml:\"tobin_tax\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

// struct for aggregate prevoting on the ExchangeRateVote.
// The purpose of aggregate prevote is to hide vote exchange rates with hash
// which is formatted as hex string in SHA256("{salt}:({pair},{exchange_rate})|...,({pair},{exchange_rate}):{voter}")
message AggregateExchangeRatePrevote {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

string hash = 1 [(gogoproto.moretags) = "yaml:\"hash\""];
string voter = 2 [(gogoproto.moretags) = "yaml:\"voter\""];
uint64 submit_block = 3 [(gogoproto.moretags) = "yaml:\"submit_block\""];
}

// MsgAggregateExchangeRateVote - struct for voting on
// the exchange rates different assets.
message AggregateExchangeRateVote {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

repeated ExchangeRateTuple exchange_rate_tuples = 1 [
(gogoproto.moretags) = "yaml:\"exchange_rate_tuples\"",
(gogoproto.castrepeated) = "ExchangeRateTuples",
(gogoproto.nullable) = false
];

string voter = 2 [(gogoproto.moretags) = "yaml:\"voter\""];
}

// ExchangeRateTuple - struct to store interpreted exchange rates data to store
message ExchangeRateTuple {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

string pair = 1 [(gogoproto.moretags) = "yaml:\"pair\""];
string exchange_rate = 2 [
(gogoproto.moretags) = "yaml:\"exchange_rate\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}
Loading

0 comments on commit 8036504

Please sign in to comment.