Skip to content

Commit

Permalink
Merge branch 'main' into adam/display
Browse files Browse the repository at this point in the history
  • Loading branch information
toteki authored Sep 27, 2023
2 parents 186a88d + 498bd30 commit f2697be
Show file tree
Hide file tree
Showing 34 changed files with 1,160 additions and 340 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: "1.20"
go-version: "1.21"
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/setup-go@v4
with:
go-version: "1.20"
go-version: "1.21"
cache: true

- uses: actions/checkout@v4
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/govulncheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Tests
on:
pull_request:
types: [opened, synchronize, reopened, labeled]
merge_group:
types: [checks_requested]

concurrency:
group: ci-${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
govulncheck:
runs-on: ubuntu-latest
name: Run govulncheck
steps:
- uses: actions/checkout@v4
- uses: technote-space/[email protected]
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- uses: golang/[email protected]
id: govulncheck
if: env.GIT_DIFF
with:
go-version-input: 1.21
go-package: ./...
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/setup-go@v4
if: env.GIT_DIFF
with:
go-version: "1.20"
go-version: "1.21"
cache: true

- name: golangci-lint main
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-umee.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version: "1.20"
go-version: "1.21"
cache: true

- name: Set Env
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/simulations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/setup-go@v4
with:
go-version: "1.20"
go-version: "1.21"

- name: Install runsim
run: export GO111MODULE="on" && go install github.com/cosmos/tools/cmd/[email protected]
Expand All @@ -39,7 +39,7 @@ jobs:
- uses: actions/setup-go@v4
if: env.GIT_DIFF
with:
go-version: "1.20"
go-version: "1.21"
cache: true
- name: Test application non-determinism
if: env.GIT_DIFF
Expand All @@ -63,7 +63,7 @@ jobs:
- uses: actions/setup-go@v4
if: env.GIT_DIFF
with:
go-version: "1.20"
go-version: "1.21"
cache: true
- uses: actions/cache@v3
if: env.GIT_DIFF
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
- uses: actions/setup-go@v4
if: env.GIT_DIFF
with:
go-version: "1.20"
go-version: "1.21"
cache: true
- uses: actions/cache@v3
if: env.GIT_DIFF
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
- uses: actions/setup-go@v4
if: env.GIT_DIFF
with:
go-version: "1.20"
go-version: "1.21"
cache: true
- uses: actions/cache@v3
if: env.GIT_DIFF
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/setup-go@v4
with:
go-version: "1.20"
go-version: "1.21"
- uses: actions/cache@v3
id: cache-go-tparse
with:
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
if: steps.cache-binaries.outputs.cache-hit != 'true' && env.GIT_DIFF
uses: actions/setup-go@v4
with:
go-version: "1.20"
go-version: "1.21"
cache: true
env:
GOOS: ${{ matrix.targetos }}
Expand All @@ -76,7 +76,7 @@ jobs:
- uses: actions/setup-go@v4
if: env.GIT_DIFF
with:
go-version: "1.20"
go-version: "1.21"
cache: true
- name: Test and Create Coverage Report
if: env.GIT_DIFF
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
- uses: actions/setup-go@v4
if: env.GIT_DIFF
with:
go-version: "1.20"
go-version: "1.21"
cache: true

- name: Test E2E
Expand Down
5 changes: 2 additions & 3 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,8 @@ func IntegrationTestNetworkConfig() network.Config {
// execute ballot voting and thus clear out previous exchange rates, since we
// are not running a price-feeder.
oracleGenState.Params.VotePeriod = 1000
oracleGenState.ExchangeRates = append(oracleGenState.ExchangeRates, oracletypes.NewExchangeRateTuple(
params.DisplayDenom, sdk.MustNewDecFromStr("34.21"),
))
oracleGenState.ExchangeRates = append(oracleGenState.ExchangeRates, oracletypes.NewDenomExchangeRate(
params.DisplayDenom, sdk.MustNewDecFromStr("34.21"), time.Now()))
// Set mock historic medians to satisfy leverage module's 24 median requirement
for i := 1; i <= 24; i++ {
median := oracletypes.Price{
Expand Down
23 changes: 8 additions & 15 deletions proto/umee/oracle/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,15 @@ option (gogoproto.goproto_getters_all) = false;

// GenesisState defines the oracle module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
repeated FeederDelegation feeder_delegations = 2
[(gogoproto.nullable) = false];
// TODO: need to update this to save data with timestamp
repeated ExchangeRateTuple exchange_rates = 3 [
(gogoproto.castrepeated) = "ExchangeRateTuples",
(gogoproto.nullable) = false
];
Params params = 1 [(gogoproto.nullable) = false];
repeated FeederDelegation feeder_delegations = 2 [(gogoproto.nullable) = false];
repeated DenomExchangeRate exchange_rates = 3 [(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 Price medians = 7 [(gogoproto.nullable) = false];
repeated Price historic_prices = 8 [(gogoproto.nullable) = false];
repeated Price medianDeviations = 9 [(gogoproto.nullable) = false];
repeated AggregateExchangeRatePrevote aggregate_exchange_rate_prevotes = 5 [(gogoproto.nullable) = false];
repeated AggregateExchangeRateVote aggregate_exchange_rate_votes = 6 [(gogoproto.nullable) = false];
repeated Price medians = 7 [(gogoproto.nullable) = false];
repeated Price historic_prices = 8 [(gogoproto.nullable) = false];
repeated Price medianDeviations = 9 [(gogoproto.nullable) = false];
// Historic Avg Counter params
AvgCounterParams avg_counter_params = 10 [
(gogoproto.moretags) = "yaml:\"avg_counter_params\"",
Expand Down
8 changes: 4 additions & 4 deletions proto/umee/oracle/v1/oracle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ message AvgCounter {
google.protobuf.Timestamp start = 3 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
}

// ExchangeRate stores exchange rate with timestamp
message ExchangeRate {
// DenomExchangeRate stores exchange rate with timestamp
message DenomExchangeRate {
option (gogoproto.equal) = false;
option (gogoproto.goproto_stringer) = false;

string rate = 1 [
string denom = 1 [(gogoproto.moretags) = "yaml:\"denom\""];
string rate = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
Expand Down
28 changes: 28 additions & 0 deletions proto/umee/oracle/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,34 @@ service Query {
option (google.api.http).get =
"/umee/historacle/v1/avg_price/{denom}";
}

// ExgRatesWithTimestamp returns exchange rates of all denoms with timestamp,
// or, if specified, returns a single denom
rpc ExgRatesWithTimestamp(QueryExgRatesWithTimestamp)
returns (QueryExgRatesWithTimestampResponse) {
option (google.api.http).get =
"/umee/oracle/v1/denoms/exg_rates_timestamp";
}
}

// QueryExgRatesWithTimestamp is the request type for the Query/ExchangeRatesWithTimestamp RPC
// method.
message QueryExgRatesWithTimestamp {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// denom defines the denomination to query for.
string denom = 1;
}

// QueryExgRatesWithTimestampResponse is response type for the
// Query/ExchangeRatesWithTimestamp RPC method.
message QueryExgRatesWithTimestampResponse {
// exchange_rates defines a list of the exchange rate for all whitelisted
// denoms with timestamp
repeated DenomExchangeRate exg_rates = 1 [
(gogoproto.nullable) = false
];
}

// QueryExchangeRates is the request type for the Query/ExchangeRate RPC
Expand Down
4 changes: 2 additions & 2 deletions x/leverage/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package simulation_test
import (
"math/rand"
"testing"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
Expand Down Expand Up @@ -32,8 +33,7 @@ type SimTestSuite struct {
func (s *SimTestSuite) SetupTest() {
checkTx := false
app := umeeapp.Setup(s.T())
ctx := app.NewContext(checkTx, tmproto.Header{})

ctx := app.NewContext(checkTx, tmproto.Header{Time: time.Now()})
leverage.InitGenesis(ctx, app.LeverageKeeper, *types.DefaultGenesis())

// Use default umee token for sim tests
Expand Down
1 change: 1 addition & 0 deletions x/oracle/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func CalcPrices(ctx sdk.Context, params types.Params, k keeper.Keeper) error {
if err != nil {
return err
}
// save the exchange rate to store with denom and timestamp
k.SetExchangeRateWithEvent(ctx, denom, exchangeRate)

if k.IsPeriodLastBlock(ctx, params.HistoricStampPeriod) {
Expand Down
10 changes: 7 additions & 3 deletions x/oracle/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package oracle_test
import (
"fmt"
"testing"
"time"

"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -43,6 +44,7 @@ func (s *IntegrationTestSuite) SetupTest() {
app := umeeapp.Setup(s.T())
ctx := app.NewContext(isCheckTx, tmproto.Header{
ChainID: fmt.Sprintf("test-chain-%s", tmrand.Str(4)),
Time: time.Now(),
})

oracle.InitGenesis(ctx, app.OracleKeeper, *types.DefaultGenesisState())
Expand Down Expand Up @@ -156,7 +158,9 @@ func (s *IntegrationTestSuite) TestEndBlockerVoteThreshold() {
for _, denom := range app.OracleKeeper.AcceptList(ctx) {
rate, err := app.OracleKeeper.GetExchangeRate(ctx, denom.SymbolDenom)
s.Require().NoError(err)
s.Require().Equal(types.ExchangeRate{Rate: sdk.OneDec(), Timestamp: ctx.BlockTime()},
s.Require().Equal(types.ExchangeRate{
Rate: sdk.OneDec(),
Timestamp: ctx.BlockTime()},
rate)
}

Expand Down Expand Up @@ -237,8 +241,8 @@ func (s *IntegrationTestSuite) TestEndBlockerVoteThreshold() {
rate, err := app.OracleKeeper.GetExchangeRate(ctx, "umee")
s.Require().NoError(err)
s.Require().Equal(types.ExchangeRate{Rate: sdk.OneDec(), Timestamp: ctx.BlockTime()}, rate)
rate, err = app.OracleKeeper.GetExchangeRate(ctx, "atom")
s.Require().ErrorIs(err, types.ErrUnknownDenom.Wrap("atom"))
rate, err = app.OracleKeeper.GetExchangeRate(ctx, "ATOM")
s.Require().ErrorIs(err, types.ErrUnknownDenom.Wrap("ATOM"))
s.Require().Equal(types.ExchangeRate{}, rate)
}

Expand Down
32 changes: 32 additions & 0 deletions x/oracle/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func GetQueryCmd() *cobra.Command {
QueryMissCounter(),
QuerySlashWindow(),
QueryHistoricAvgPrice(),
QueryExchangeRatesWithTimestamp(),
)

return cmd
Expand Down Expand Up @@ -300,3 +301,34 @@ func QueryHistoricAvgPrice() *cobra.Command {
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

// QueryExchangeRatesWithTimestamp implements the query rate command.
func QueryExchangeRatesWithTimestamp() *cobra.Command {
cmd := &cobra.Command{
Use: "exg-rates-timestamp [denom]",
Args: cobra.MaximumNArgs(1),
Short: "Query the exchange rates with timestamp",
Long: strings.TrimSpace(`
Query the current exchange rates of assets based on USD with timestamp.
You can find the current list of active denoms by running
$ umeed query oracle exg-rates-timestamp
`),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
query := &types.QueryExgRatesWithTimestamp{}
if len(args) > 0 {
query.Denom = args[0]
}
res, err := queryClient.ExgRatesWithTimestamp(cmd.Context(), query)
return cli.PrintOrErr(res, err, clientCtx)
},
}

flags.AddQueryFlagsToCmd(cmd)
return cmd
}
Loading

0 comments on commit f2697be

Please sign in to comment.