Skip to content

Commit

Permalink
refactor(asset-pair)!: refactors common.AssetPair as an extension of …
Browse files Browse the repository at this point in the history
…string (#1154)

* refactor: common.AssetPair as string

* feat: add common AssetPair proto methods

* refactor: common.AssetPair as string

* fix: broken tests

* chore: update changelog

* fix: linting workflow caching

* fix: localnet script

* fix: simulation test creates borked vpool
  • Loading branch information
k-yang authored Jan 24, 2023
1 parent 357161f commit 64cc878
Show file tree
Hide file tree
Showing 125 changed files with 2,185 additions and 2,595 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ jobs:
- uses: actions/setup-go@v3
with:
go-version: 1.19
cache: true

- uses: actions/checkout@v3

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.49
version: latest

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### API Breaking

* [#1154](https://github.com/NibiruChain/nibiru/pull/1154) - refactor(asset-pair)!: refactors `common.AssetPair` as an extension of string

### CI

* [#1032](https://github.com/NibiruChain/nibiru/pull/1107) - ci: Create e2e wasm contract test

### Improvements

* [#1134](https://github.com/NibiruChain/nibiru/pull/1134) - refactor: remove panics from vpool and spillovers from the perp module. It's now impossible to call functions in x/perp that would panic in vpool.
Expand Down
17 changes: 0 additions & 17 deletions proto/common/common.proto

This file was deleted.

5 changes: 4 additions & 1 deletion proto/oracle/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ message GenesisState {
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 string pairs = 7;
repeated string pairs = 7 [
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];
repeated PairReward pair_rewards = 8 [(gogoproto.nullable) = false];
}

Expand Down
17 changes: 13 additions & 4 deletions proto/oracle/v1beta1/oracle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ message Params {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
repeated string whitelist = 4 [
(gogoproto.moretags) = "yaml:\"whitelist\""
repeated string whitelist = 4 [
(gogoproto.moretags) = "yaml:\"whitelist\"",
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair"
];
string slash_fraction = 5 [
(gogoproto.moretags) = "yaml:\"slash_fraction\"",
Expand Down Expand Up @@ -82,7 +83,12 @@ message ExchangeRateTuple {
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

string pair = 1 [(gogoproto.moretags) = "yaml:\"pair\""];
string pair = 1 [
(gogoproto.moretags) = "yaml:\"pair\"",
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];

string exchange_rate = 2 [
(gogoproto.moretags) = "yaml:\"exchange_rate\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
Expand All @@ -94,7 +100,10 @@ message ExchangeRateTuple {
// which provide prices faithfully for different pairs.
message PairReward {
// pair defines the pair for which we incentivize validator to provide prices for.
string pair = 1;
string pair = 1 [
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];
// id uniquely identifies the rewards instance of the pair
uint64 id = 2;
// vote_periods defines the vote periods left in which rewards will be distributed.
Expand Down
21 changes: 15 additions & 6 deletions proto/oracle/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ option go_package = "github.com/NibiruChain/nibiru/x/oracle/types";
service Query {
// ExchangeRate returns exchange rate of a pair
rpc ExchangeRate(QueryExchangeRateRequest) returns (QueryExchangeRateResponse) {
option (google.api.http).get = "/nibiru/oracle/v1beta1/pairs/{pair}/exchange_rate";
option (google.api.http).get = "/nibiru/oracle/v1beta1/exchange_rate";
}

// ExchangeRateTwap returns exchange rate of a pair
// ExchangeRateTwap returns twap exchange rate of a pair
rpc ExchangeRateTwap(QueryExchangeRateRequest) returns (QueryExchangeRateResponse) {
option (google.api.http).get = "/nibiru/oracle/v1beta1/pairs/{pair}/exchange_rate";
option (google.api.http).get = "/nibiru/oracle/v1beta1/exchange_rate_twap";
}

// ExchangeRates returns exchange rates of all pairs
Expand Down Expand Up @@ -77,7 +77,10 @@ message QueryExchangeRateRequest {
option (gogoproto.goproto_getters) = false;

// pair defines the pair to query for.
string pair = 1;
string pair = 1 [
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];
}

// QueryExchangeRateResponse is response type for the
Expand Down Expand Up @@ -108,7 +111,10 @@ message QueryActivesRequest {}
// Query/Actives RPC method.
message QueryActivesResponse {
// actives defines a list of the pair which oracle prices agreed upon.
repeated string actives = 1;
repeated string actives = 1 [
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];
}

// QueryVoteTargetsRequest is the request type for the Query/VoteTargets RPC method.
Expand All @@ -119,7 +125,10 @@ message QueryVoteTargetsRequest {}
message QueryVoteTargetsResponse {
// vote_targets defines a list of the pairs in which everyone
// should vote in the current vote period.
repeated string vote_targets = 1;
repeated string vote_targets = 1 [
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];
}

// QueryFeederDelegationRequest is the request type for the Query/FeederDelegation RPC method.
Expand Down
7 changes: 6 additions & 1 deletion proto/oracle/v1beta1/state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ option go_package = "github.com/NibiruChain/nibiru/x/oracle/types";

// a snapshot of the prices at a given point in time
message PriceSnapshot {
string pair = 1;
string pair = 1 [
(gogoproto.moretags) = "yaml:\"pair\"",
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];

string price = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false];
Expand Down
26 changes: 20 additions & 6 deletions proto/perp/v1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package nibiru.perp.v1;
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/v1beta1/coin.proto";
import "common/common.proto";
import "perp/v1/state.proto";

option go_package = "github.com/NibiruChain/nibiru/x/perp/types";
Expand All @@ -14,7 +13,10 @@ option go_package = "github.com/NibiruChain/nibiru/x/perp/types";
// TODO: Is there a way to split this into different events without creating too much complexity?
message PositionChangedEvent {
// identifier of the corresponding virtual pool for the position
string pair = 1;
string pair = 1 [
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];

// owner of the position.
string trader_address = 2;
Expand Down Expand Up @@ -106,7 +108,10 @@ message PositionChangedEvent {
// Emitted when a position is liquidated.
message PositionLiquidatedEvent {
// identifier of the corresponding virtual pool for the position
string pair = 1;
string pair = 1 [
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];

// owner of the position.
string trader_address = 2;
Expand Down Expand Up @@ -184,7 +189,10 @@ message PositionLiquidatedEvent {
// Emitted when a position is settled.
message PositionSettledEvent {
// Identifier for the virtual pool of the position.
string pair = 1;
string pair = 1 [
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];

// Owner of the position.
string trader_address = 2;
Expand All @@ -201,7 +209,10 @@ message PositionSettledEvent {
message FundingRateChangedEvent {

// The pair for which the funding rate was calculated.
string pair = 1;
string pair = 1 [
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];

// The mark price of the pair.
string mark_price = 2 [
Expand Down Expand Up @@ -243,7 +254,10 @@ message FundingRateChangedEvent {
}

message MetricsEvent {
string pair = 1;
string pair = 1 [
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];

// Sum of all active position sizes for the pair.
string net_size = 2 [
Expand Down
1 change: 0 additions & 1 deletion proto/perp/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package nibiru.perp.v1;
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/v1beta1/coin.proto";
import "common/common.proto";
import "perp/v1/state.proto";

option go_package = "github.com/NibiruChain/nibiru/x/perp/types";
Expand Down
15 changes: 12 additions & 3 deletions proto/perp/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ message QueryPositionsResponse {
// QueryPositionRequest is the request type for the position of the x/perp
// module account.
message QueryPositionRequest {
string token_pair = 1;
string pair = 1 [
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];

string trader = 2;
}
Expand Down Expand Up @@ -110,7 +113,10 @@ message QueryPositionResponse {

message QueryCumulativePremiumFractionRequest {
// the pair to query for
string pair = 1;
string pair = 1 [
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];
}

message QueryCumulativePremiumFractionResponse {
Expand All @@ -130,7 +136,10 @@ message QueryCumulativePremiumFractionResponse {

message QueryMetricsRequest {
// the pair to query for
string pair = 1;
string pair = 1 [
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];
}

message QueryMetricsResponse {
Expand Down
18 changes: 13 additions & 5 deletions proto/perp/v1/state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "google/protobuf/duration.proto";
import "common/common.proto";

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

Expand Down Expand Up @@ -90,13 +89,16 @@ message Position {
string trader_address = 1;

// pair identifies the pair associated with this position
common.AssetPair pair = 2 [ (gogoproto.nullable) = false ];
string pair = 2 [
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];

// Position size.
string size = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
]; // signed int
];

// Amount of margin remaining in the position.
string margin = 4 [
Expand All @@ -123,7 +125,10 @@ message Position {
}

message PairMetadata {
common.AssetPair pair = 1 [ (gogoproto.nullable) = false ];
string pair = 1 [
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];

// Latest cumulative premium fraction for a given pair.
// Calculated once per funding rate interval.
Expand Down Expand Up @@ -230,7 +235,10 @@ message LiquidateResp {
// PoolMetrics is a structure that displays a snapshot of perp metrics for each pair.
message Metrics {
// Pair identifier for the two assets. Always in format 'base:quote'
string pair = 1;
string pair = 1 [
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/x/common.AssetPair",
(gogoproto.nullable) = false
];

// Sum of all active position sizes for the pair.
string net_size = 2 [
Expand Down
Loading

0 comments on commit 64cc878

Please sign in to comment.