Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add oracle module #392

Merged
merged 6 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ linters:
- gosimple
- govet
- ineffassign
- interfacer
- maligned
- misspell
- nakedret
Expand Down
4 changes: 2 additions & 2 deletions contrib/devtools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ tools-stamp: statik runsim
statik: $(STATIK)
$(STATIK):
@echo "Installing statik..."
@(cd /tmp && go get github.com/rakyll/statik@v0.1.6)
@(cd /tmp && go install github.com/rakyll/statik@v0.1.6)

# Install the runsim binary with a temporary workaround of entering an outside
# directory as the "go get" command ignores the -mod option and will polute the
Expand All @@ -79,7 +79,7 @@ $(STATIK):
runsim: $(RUNSIM)
$(RUNSIM):
@echo "Installing runsim..."
@(cd /tmp && go get github.com/cosmos/tools/cmd/runsim@v1.0.0)
@(cd /tmp && go install github.com/cosmos/tools/cmd/runsim@v1.0.0)

tools-clean:
rm -f $(STATIK) $(GOLANGCI_LINT) $(RUNSIM)
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/persistenceOne/persistence-sdk/v2
go 1.19

require (
cosmossdk.io/errors v1.0.0-beta.7
cosmossdk.io/math v1.0.0-beta.3
github.com/armon/go-metrics v0.4.1
github.com/cosmos/cosmos-proto v1.0.0-alpha8
Expand All @@ -15,6 +16,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/pkg/errors v0.9.1
github.com/rakyll/statik v0.1.7
github.com/regen-network/cosmos-proto v0.3.1
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
Expand All @@ -27,6 +29,7 @@ require (
google.golang.org/grpc v1.52.0
google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
sigs.k8s.io/yaml v1.3.0
)

Expand All @@ -36,7 +39,6 @@ require (
cloud.google.com/go/compute/metadata v0.2.1 // indirect
cloud.google.com/go/iam v0.7.0 // indirect
cloud.google.com/go/storage v1.27.0 // indirect
cosmossdk.io/errors v1.0.0-beta.7 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
Expand Down Expand Up @@ -128,7 +130,6 @@ require (
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
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
Expand All @@ -154,7 +155,6 @@ require (
google.golang.org/api v0.102.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
)

Expand Down
35 changes: 35 additions & 0 deletions proto/persistence/oracle/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
syntax = "proto3";
package persistence.oracle.v1beta1;

import "gogoproto/gogo.proto";
import "persistence/oracle/v1beta1/oracle.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/persistenceOne/persistence-sdk/v2/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];
}

// 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 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string validator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MissCounter defines an miss counter and validator address pair used in
// oracle module's genesis state. It stores the number of vote periods missed by a validator
// in a slash window.
message MissCounter {
string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
uint64 miss_counter = 2;
}
105 changes: 105 additions & 0 deletions proto/persistence/oracle/v1beta1/oracle.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
syntax = "proto3";
package persistence.oracle.v1beta1;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/persistenceOne/persistence-sdk/v2/x/oracle/types";

// Params defines the parameters for the oracle module.
// https://classic-docs.terra.money/docs/develop/module-specifications/spec-oracle.html#parameters
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 Denom accept_list = 5 [
(gogoproto.moretags) = "yaml:\"accept_list\"",
(gogoproto.castrepeated) = "DenomList",
(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
];
}

// Denom - the object to hold configurations of each denom
message Denom {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

string base_denom = 1 [(gogoproto.moretags) = "yaml:\"base_denom\""];
string symbol_denom = 2 [(gogoproto.moretags) = "yaml:\"symbol_denom\""];
uint32 exponent = 3 [(gogoproto.moretags) = "yaml:\"exponent\""];
}

// AggregateExchangeRatePrevote -
// 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}:{exchange
// rate}{denom},...,{exchange rate}{denom}:{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\"",
(cosmos_proto.scalar) = "cosmos.AddressString"
];
uint64 submit_block = 3 [(gogoproto.moretags) = "yaml:\"submit_block\""];
}

// AggregateExchangeRateVote - struct for voting on
// the exchange rates of USD denominated in various 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\"",
(cosmos_proto.scalar) = "cosmos.AddressString"
];
}

// 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 denom = 1 [(gogoproto.moretags) = "yaml:\"denom\""];
string exchange_rate = 2 [
(gogoproto.moretags) = "yaml:\"exchange_rate\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}