diff --git a/proto/reserve/oracle/genesis.proto b/proto/reserve/oracle/genesis.proto index 8cc0749f..fe8cc23f 100644 --- a/proto/reserve/oracle/genesis.proto +++ b/proto/reserve/oracle/genesis.proto @@ -56,7 +56,7 @@ message BandPriceState { (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false ]; - uint64 resolve_time = 3; + int64 resolve_time = 3; uint64 request_ID = 4; PriceState price_state = 5 [ (gogoproto.nullable) = false ]; } diff --git a/proto/reserve/oracle/params.proto b/proto/reserve/oracle/params.proto index 6b8880c0..a603a8f8 100644 --- a/proto/reserve/oracle/params.proto +++ b/proto/reserve/oracle/params.proto @@ -3,6 +3,7 @@ package reserve.oracle; import "amino/amino.proto"; import "gogoproto/gogo.proto"; +import "google/protobuf/duration.proto"; option go_package = "github.com/onomyprotocol/reserve/x/oracle/types"; @@ -10,4 +11,7 @@ option go_package = "github.com/onomyprotocol/reserve/x/oracle/types"; message Params { option (amino.name) = "reserve/x/oracle/Params"; option (gogoproto.equal) = true; + + google.protobuf.Duration allowed_price_delay = 1 + [(gogoproto.nullable) = false, (amino.dont_omitempty) = true, (gogoproto.stdduration) = true]; } diff --git a/x/oracle/keeper/band_oracle.go b/x/oracle/keeper/band_oracle.go index dc8b5faf..6b55d8e9 100644 --- a/x/oracle/keeper/band_oracle.go +++ b/x/oracle/keeper/band_oracle.go @@ -311,33 +311,43 @@ func (k Keeper) AddNewSymbolToBandOracleRequest(ctx context.Context, symbol stri } // GetPrice fetches band ibc prices for a given pair in math.LegacyDec -func (k Keeper) GetPrice(ctx context.Context, base, quote string) *math.LegacyDec { +func (k Keeper) GetPrice(ctx context.Context, base, quote string) (price math.LegacyDec, err error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + allowedPriceDelay := k.GetParams(ctx).AllowedPriceDelay // query ref by using GetBandPriceState basePriceState := k.GetBandPriceState(ctx, base) if basePriceState == nil || basePriceState.Rate.IsZero() { - k.Logger(ctx).Info(fmt.Sprintf("Can not get price state of base denom %s: price state is nil or rate is zero", base)) - return nil + err = fmt.Errorf("can not get price state of base denom %s: price state is nil or rate is zero", base) + k.Logger(ctx).Info(err.Error()) + return price, err + } + if sdkCtx.BlockTime().Sub(time.Unix(basePriceState.ResolveTime, 0)) > allowedPriceDelay { + return price, fmt.Errorf("symbol %s old price state", base) } - if quote == types.QuoteUSD || quote == vaultstypes.DefaultMintDenoms[0] { - return &basePriceState.PriceState.Price + return basePriceState.PriceState.Price, nil } quotePriceState := k.GetBandPriceState(ctx, quote) if quotePriceState == nil || quotePriceState.Rate.IsZero() { - k.Logger(ctx).Info(fmt.Sprintf("Can not get price state of quote denom %s: price state is nil or rate is zero", quote)) - return nil + err = fmt.Errorf("can not get price state of base denom %s: price state is nil or rate is zero", quote) + k.Logger(ctx).Info(err.Error()) + return price, err + } + if sdkCtx.BlockTime().Sub(time.Unix(quotePriceState.ResolveTime, 0)) > allowedPriceDelay { + return price, fmt.Errorf("symbol %s old price state", quote) } baseRate := basePriceState.Rate.ToLegacyDec() quoteRate := quotePriceState.Rate.ToLegacyDec() if baseRate.IsNil() || quoteRate.IsNil() || !baseRate.IsPositive() || !quoteRate.IsPositive() { - return nil + return price, fmt.Errorf("get price error validate for baseRate %s(%s) or quoteRate %s(%s)", base, baseRate.String(), quote, quoteRate.String()) } - price := baseRate.Quo(quoteRate) - return &price + price = baseRate.Quo(quoteRate) + return price, nil } // RequestBandOraclePrices creates and sends an IBC packet to fetch band oracle price feed data through IBC. @@ -464,7 +474,7 @@ func (k *Keeper) updateBandPriceStates( var ( inputSymbols = input.PriceSymbols() requestID = packet.RequestID - resolveTime = uint64(packet.ResolveTime) + resolveTime = packet.ResolveTime symbols = make([]string, 0, len(inputSymbols)) prices = make([]math.LegacyDec, 0, len(inputSymbols)) ) diff --git a/x/oracle/keeper/band_oracle_test.go b/x/oracle/keeper/band_oracle_test.go index 3a19b8eb..ca5300ce 100644 --- a/x/oracle/keeper/band_oracle_test.go +++ b/x/oracle/keeper/band_oracle_test.go @@ -25,26 +25,28 @@ func TestBandPriceState(t *testing.T) { states := app.OracleKeeper.GetAllBandPriceStates(ctx) require.Equal(t, 0, len(states)) - price := app.OracleKeeper.GetPrice(ctx, "ATOM", "USD") - require.Nil(t, price) + _, err := app.OracleKeeper.GetPrice(ctx, "ATOM", "USD") + require.Error(t, err) bandPriceState := &types.BandPriceState{ Symbol: "ATOM", Rate: math.NewInt(10), - ResolveTime: 1, + ResolveTime: time.Now().Unix(), Request_ID: 1, PriceState: *types.NewPriceState(math.LegacyNewDec(10), 1), } // set band price state for ATOM - err := app.OracleKeeper.SetBandPriceState(ctx, "ATOM", bandPriceState) + err = app.OracleKeeper.SetBandPriceState(ctx, "ATOM", bandPriceState) require.NoError(t, err) data = app.OracleKeeper.GetBandPriceState(ctx, "ATOM") require.Equal(t, bandPriceState, data) - price = app.OracleKeeper.GetPrice(ctx, "ATOM", "USD") + price, err := app.OracleKeeper.GetPrice(ctx, "ATOM", "USD") + require.NoError(t, err) + expect := math.LegacyNewDec(10) - require.Equal(t, &expect, price) + require.Equal(t, expect, price) states = app.OracleKeeper.GetAllBandPriceStates(ctx) require.Equal(t, 1, len(states)) @@ -166,28 +168,28 @@ func TestGetPrice(t *testing.T) { bandPriceStateATOM := &types.BandPriceState{ Symbol: "ATOM", Rate: math.NewInt(10), - ResolveTime: 1, + ResolveTime: time.Now().Unix(), Request_ID: 1, PriceState: *types.NewPriceState(math.LegacyNewDec(10), 1), } bandPriceStateUSD := &types.BandPriceState{ Symbol: "USD", Rate: math.NewInt(1), - ResolveTime: 1, + ResolveTime: time.Now().Unix(), Request_ID: 1, PriceState: *types.NewPriceState(math.LegacyNewDec(1), 1), } bandPriceStateNOM := &types.BandPriceState{ Symbol: "NOM", Rate: math.NewInt(2), - ResolveTime: 1, + ResolveTime: time.Now().Unix(), Request_ID: 1, PriceState: *types.NewPriceState(math.LegacyNewDec(2), 1), } invalidPriceStateATOM := &types.BandPriceState{ Symbol: "ATOM", Rate: math.NewInt(0), // Invalid base rate - ResolveTime: 1, + ResolveTime: time.Now().Unix(), Request_ID: 1, PriceState: *types.NewPriceState(math.LegacyNewDec(0), 1), } @@ -203,7 +205,7 @@ func TestGetPrice(t *testing.T) { quoteSymbol string basePriceState *types.BandPriceState quotePriceState *types.BandPriceState - expectedPrice *math.LegacyDec + expectedPrice math.LegacyDec expectNil bool }{ // Return nil cases first @@ -213,7 +215,7 @@ func TestGetPrice(t *testing.T) { quoteSymbol: "USD", basePriceState: nil, quotePriceState: nil, - expectedPrice: nil, + expectedPrice: math.LegacyNewDec(-1), expectNil: true, }, { @@ -222,7 +224,7 @@ func TestGetPrice(t *testing.T) { quoteSymbol: "USD", basePriceState: invalidPriceStateATOM, quotePriceState: bandPriceStateUSD, - expectedPrice: nil, + expectedPrice: math.LegacyNewDec(-1), expectNil: true, }, { @@ -231,7 +233,7 @@ func TestGetPrice(t *testing.T) { quoteSymbol: "NOM", basePriceState: bandPriceStateATOM, quotePriceState: nil, - expectedPrice: nil, // Since NOM doesn't exist, expect nil + expectedPrice: math.LegacyNewDec(-1), // Since NOM doesn't exist, expect nil expectNil: true, }, // return a valid price @@ -241,7 +243,7 @@ func TestGetPrice(t *testing.T) { quoteSymbol: "NOM", basePriceState: bandPriceStateATOM, quotePriceState: bandPriceStateNOM, - expectedPrice: &expectedPrice05, // 10/2 = 5 + expectedPrice: expectedPrice05, // 10/2 = 5 expectNil: false, }, { @@ -250,7 +252,7 @@ func TestGetPrice(t *testing.T) { quoteSymbol: "USD", basePriceState: bandPriceStateATOM, quotePriceState: nil, - expectedPrice: &expectedPrice10, // Since quote = USD, we return base price directly + expectedPrice: expectedPrice10, // Since quote = USD, we return base price directly expectNil: false, }, { @@ -259,7 +261,7 @@ func TestGetPrice(t *testing.T) { quoteSymbol: "USD", basePriceState: bandPriceStateATOM, quotePriceState: bandPriceStateUSD, - expectedPrice: &expectedPrice10, + expectedPrice: expectedPrice10, expectNil: false, }, { @@ -268,7 +270,7 @@ func TestGetPrice(t *testing.T) { quoteSymbol: "ATOM", basePriceState: bandPriceStateUSD, quotePriceState: bandPriceStateATOM, - expectedPrice: &expectedPrice01, + expectedPrice: expectedPrice01, expectNil: false, }, } @@ -286,12 +288,13 @@ func TestGetPrice(t *testing.T) { } // Execute GetPrice - price := app.OracleKeeper.GetPrice(ctx, tc.baseSymbol, tc.quoteSymbol) + price, err := app.OracleKeeper.GetPrice(ctx, tc.baseSymbol, tc.quoteSymbol) // Check expectations if tc.expectNil { - require.Nil(t, price) + require.Error(t, err) } else { + require.NoError(t, err) require.NotNil(t, price) require.Equal(t, tc.expectedPrice, price) } @@ -299,6 +302,53 @@ func TestGetPrice(t *testing.T) { } } +func (s *KeeperTestSuite) TestPriceOld() { + s.SetupTest() + allowedPriceDelay := s.App.OracleKeeper.GetParams(s.Ctx).AllowedPriceDelay + var ( + timeLate = -allowedPriceDelay - time.Hour // 6h +1h =7h + priceNOM = math.LegacyNewDec(2) + ) + + PricesState := []*types.BandPriceState{ + { + Symbol: "ATOM", + Rate: math.NewInt(10), + ResolveTime: time.Now().Add(timeLate).Unix(), // old price + Request_ID: 1, + PriceState: *types.NewPriceState(math.LegacyNewDec(10), 1), + }, + { + Symbol: "USD", + Rate: math.NewInt(1), + ResolveTime: time.Now().Unix(), + Request_ID: 1, + PriceState: *types.NewPriceState(math.LegacyNewDec(1), 1), + }, + { + Symbol: "NOM", + Rate: math.NewInt(2), + ResolveTime: time.Now().Unix(), + Request_ID: 1, + PriceState: *types.NewPriceState(priceNOM, 1), + }, + } + + for _, priceState := range PricesState { + err := s.App.OracleKeeper.SetBandPriceState(s.Ctx, priceState.Symbol, priceState) + s.Require().NoError(err) + } + + // ATOM price old + _, err := s.App.OracleKeeper.GetPrice(s.Ctx, "ATOM", "USD") + s.Require().Error(err) + + // NOM price new (6h) + price, err := s.App.OracleKeeper.GetPrice(s.Ctx, "NOM", "USD") + s.Require().NoError(err) + s.Require().Equal(priceNOM, price) +} + func TestProcessBandOraclePrices(t *testing.T) { // Set up the application and context app := app.Setup(t, false) diff --git a/x/oracle/keeper/keeper_test.go b/x/oracle/keeper/keeper_test.go index 2ce7edb6..cc3facc0 100644 --- a/x/oracle/keeper/keeper_test.go +++ b/x/oracle/keeper/keeper_test.go @@ -5,12 +5,14 @@ import ( apptesting "github.com/onomyprotocol/reserve/app/apptesting" "github.com/onomyprotocol/reserve/x/oracle/keeper" + "github.com/onomyprotocol/reserve/x/oracle/types" testifysuite "github.com/stretchr/testify/suite" ) type KeeperTestSuite struct { apptesting.KeeperTestHelper - k keeper.Keeper + k keeper.Keeper + msgServer types.MsgServer } func TestKeeperTestSuite(t *testing.T) { @@ -20,4 +22,5 @@ func TestKeeperTestSuite(t *testing.T) { func (s *KeeperTestSuite) SetupTest() { s.Setup() s.k = s.App.OracleKeeper + s.msgServer = keeper.NewMsgServerImpl(s.k) } diff --git a/x/oracle/keeper/msg_server_test.go b/x/oracle/keeper/msg_server_test.go index ce350965..d4b11266 100644 --- a/x/oracle/keeper/msg_server_test.go +++ b/x/oracle/keeper/msg_server_test.go @@ -1,24 +1,27 @@ package keeper_test -// import ( -// "context" -// "testing" - -// "github.com/stretchr/testify/require" - -// keepertest "github.com/onomyprotocol/reserve/testutil/keeper" -// "github.com/onomyprotocol/reserve/x/oracle/keeper" -// "github.com/onomyprotocol/reserve/x/oracle/types" -// ) - -// func setupMsgServer(t testing.TB) (keeper.Keeper, types.MsgServer, context.Context) { -// k, ctx := keepertest.OracleKeeper(t) -// return k, keeper.NewMsgServerImpl(k), ctx -// } - -// func TestMsgServer(t *testing.T) { -// k, ms, ctx := setupMsgServer(t) -// require.NotNil(t, ms) -// require.NotNil(t, ctx) -// require.NotEmpty(t, k) -// } +import ( + "time" + + "github.com/onomyprotocol/reserve/x/oracle/types" +) + +func (s *KeeperTestSuite) TestUpdateParams() { + s.SetupTest() + + paramDefault := s.k.GetParams(s.Ctx) + s.Require().Equal(paramDefault.AllowedPriceDelay, types.DefauAllowedPriceDelay) + + allowedPriceDelayUpdate := time.Hour * 10 + + msgUpdateParams := types.MsgUpdateParams{ + Authority: s.k.GetAuthority(), + Params: types.NewParams(allowedPriceDelayUpdate), + } + + _, err := s.msgServer.UpdateParams(s.Ctx, &msgUpdateParams) + s.Require().NoError(err) + + paramsNew := s.k.GetParams(s.Ctx) + s.Require().Equal(paramsNew.AllowedPriceDelay, allowedPriceDelayUpdate) +} diff --git a/x/oracle/keeper/query.go b/x/oracle/keeper/query.go index ceff8c42..19a0ad0b 100644 --- a/x/oracle/keeper/query.go +++ b/x/oracle/keeper/query.go @@ -5,7 +5,6 @@ import ( "slices" "strconv" - errors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/onomyprotocol/reserve/x/oracle/types" ) @@ -25,9 +24,9 @@ func (k Keeper) BandPriceStates(c context.Context, _ *types.QueryBandPriceStates func (k Keeper) Price(c context.Context, q *types.QueryPriceRequest) (*types.QueryPriceResponse, error) { ctx := sdk.UnwrapSDKContext(c) - price := k.GetPrice(ctx, q.BaseDenom, q.QuoteDenom) - if price == nil || price.IsNil() { - return nil, errors.Wrapf(types.ErrInvalidOracle, "can not get price with base %s quote %s", q.BaseDenom, q.QuoteDenom) + price, err := k.GetPrice(ctx, q.BaseDenom, q.QuoteDenom) + if err != nil { + return nil, err } else { res := &types.QueryPriceResponse{ Price: price.String(), diff --git a/x/oracle/module/module_ibc_test.go b/x/oracle/module/module_ibc_test.go index 459ae014..5161475f 100644 --- a/x/oracle/module/module_ibc_test.go +++ b/x/oracle/module/module_ibc_test.go @@ -2,6 +2,7 @@ package oracle_test import ( "encoding/hex" + "time" "cosmossdk.io/math" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" @@ -265,7 +266,7 @@ func (suite *PriceRelayTestSuite) TestOnRecvPacket() { RequestID: 1, AnsCount: 1, RequestTime: 1000000000, - ResolveTime: 1000000000, + ResolveTime: time.Now().Unix(), ResolveStatus: oracletypes.RESOLVE_STATUS_SUCCESS, Result: result, } @@ -314,7 +315,8 @@ func (suite *PriceRelayTestSuite) TestOnRecvPacket() { suite.Require().True(ack.Success()) suite.Require().Equal(expectedAck, ack) - price := onomyApp.OracleKeeper.GetPrice(suite.chainO.GetContext(), "ATOM", "USD") + price, err := onomyApp.OracleKeeper.GetPrice(suite.chainO.GetContext(), "ATOM", "USD") + suite.Require().NoError(err) suite.Require().Equal("10.822375461000000000", price.String()) } else { suite.Require().False(ack.Success()) diff --git a/x/oracle/types/genesis.pb.go b/x/oracle/types/genesis.pb.go index a05de6ae..cbbfa637 100644 --- a/x/oracle/types/genesis.pb.go +++ b/x/oracle/types/genesis.pb.go @@ -227,7 +227,7 @@ func (m *BandOracleRequestParams) GetMinSourceCount() uint64 { type BandPriceState struct { Symbol string `protobuf:"bytes,1,opt,name=symbol,proto3" json:"symbol,omitempty"` Rate cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=rate,proto3,customtype=cosmossdk.io/math.Int" json:"rate"` - ResolveTime uint64 `protobuf:"varint,3,opt,name=resolve_time,json=resolveTime,proto3" json:"resolve_time,omitempty"` + ResolveTime int64 `protobuf:"varint,3,opt,name=resolve_time,json=resolveTime,proto3" json:"resolve_time,omitempty"` Request_ID uint64 `protobuf:"varint,4,opt,name=request_ID,json=requestID,proto3" json:"request_ID,omitempty"` PriceState PriceState `protobuf:"bytes,5,opt,name=price_state,json=priceState,proto3" json:"price_state"` } @@ -272,7 +272,7 @@ func (m *BandPriceState) GetSymbol() string { return "" } -func (m *BandPriceState) GetResolveTime() uint64 { +func (m *BandPriceState) GetResolveTime() int64 { if m != nil { return m.ResolveTime } @@ -607,66 +607,67 @@ func init() { func init() { proto.RegisterFile("reserve/oracle/genesis.proto", fileDescriptor_78a657bc7a2646c9) } var fileDescriptor_78a657bc7a2646c9 = []byte{ - // 944 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x55, 0xcd, 0x72, 0x1b, 0x45, - 0x10, 0xb6, 0x2c, 0x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2d, - 0xe0, 0xc9, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xea, 0x22, 0x58, 0xa9, 0x5c, 0x08, 0x00, 0x00, + // 946 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x55, 0xcd, 0x6e, 0xdb, 0x46, + 0x10, 0x36, 0x2d, 0x59, 0x16, 0x47, 0x86, 0x6c, 0x6f, 0x1d, 0x47, 0x95, 0x13, 0xd9, 0x51, 0x0f, + 0x15, 0x82, 0x96, 0x8c, 0x93, 0x53, 0x8e, 0x95, 0x0d, 0x04, 0x2c, 0x0c, 0x34, 0x58, 0x17, 0x3d, + 0xf4, 0x42, 0x2c, 0x97, 0x1b, 0x79, 0x6b, 0x92, 0xab, 0x72, 0x57, 0x42, 0xfc, 0x02, 0x3d, 0xf7, + 0x31, 0xda, 0x9e, 0xfa, 0x18, 0x39, 0xf4, 0x90, 0x63, 0xdb, 0x43, 0x1a, 0xd8, 0x87, 0xbe, 0x46, + 0xb1, 0x3f, 0xd4, 0x8f, 0xa3, 0x26, 0x3d, 0xf5, 0x22, 0x71, 0x67, 0xbe, 0x9d, 0x9d, 0x6f, 0xe7, + 0xfb, 0x48, 0xb8, 0x57, 0x32, 0xc9, 0xca, 0x29, 0x0b, 0x45, 0x49, 0x68, 0xc6, 0xc2, 0x11, 0x2b, + 0x98, 0xe4, 0x32, 0x18, 0x97, 0x42, 0x09, 0xd4, 0x76, 0xd9, 0xc0, 0x66, 0xbb, 0xbb, 0x24, 0xe7, + 0x85, 0x08, 0xcd, 0xaf, 0x85, 0x74, 0xf7, 0x46, 0x62, 0x24, 0xcc, 0x63, 0xa8, 0x9f, 0x5c, 0xf4, + 0xe0, 0x56, 0xd9, 0x31, 0x29, 0x49, 0xee, 0xaa, 0x76, 0x7b, 0x54, 0xc8, 0x5c, 0xc8, 0x30, 0x21, + 0x92, 0x85, 0xd3, 0xe3, 0x84, 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d, 0xf3, 0x7e, 0xbc, + 0xe9, 0xad, 0xbd, 0xbe, 0xe9, 0xad, 0xfd, 0x7e, 0xd3, 0x5b, 0xfb, 0x36, 0x5c, 0xe8, 0x5c, 0x14, + 0x22, 0xbf, 0x32, 0x5f, 0x69, 0x2a, 0xb2, 0xb0, 0xfa, 0xc8, 0xbf, 0xac, 0x3e, 0xf3, 0x86, 0x46, + 0xd2, 0x30, 0x80, 0x27, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, 0xe8, 0x26, 0xe3, 0x41, 0x5c, 0x08, + 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -1907,7 +1908,7 @@ func (m *BandPriceState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.ResolveTime |= uint64(b&0x7F) << shift + m.ResolveTime |= int64(b&0x7F) << shift if b < 0x80 { break } diff --git a/x/oracle/types/params.go b/x/oracle/types/params.go index 7fe25f9b..21c3e7e2 100644 --- a/x/oracle/types/params.go +++ b/x/oracle/types/params.go @@ -1,6 +1,8 @@ package types import ( + "time" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -25,6 +27,9 @@ var ( DefaultPrepareGas = uint64(20000) DefaultExecuteGas = uint64(100000) DefaultMinSourceCount = uint64(3) + + // Params + DefauAllowedPriceDelay = time.Hour * 6 ) // ParamKeyTable the param key table for launch module @@ -33,13 +38,15 @@ func ParamKeyTable() paramtypes.KeyTable { } // NewParams creates a new Params instance -func NewParams() Params { - return Params{} +func NewParams(allowed_price_delay time.Duration) Params { + return Params{ + AllowedPriceDelay: allowed_price_delay, + } } // DefaultParams returns a default set of parameters func DefaultParams() Params { - return NewParams() + return NewParams(DefauAllowedPriceDelay) } // ParamSetPairs get the params.ParamSet diff --git a/x/oracle/types/params.pb.go b/x/oracle/types/params.pb.go index 59c987d0..f8be0fc5 100644 --- a/x/oracle/types/params.pb.go +++ b/x/oracle/types/params.pb.go @@ -8,15 +8,19 @@ import ( _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" + github_com_cosmos_gogoproto_types "github.com/cosmos/gogoproto/types" + _ "google.golang.org/protobuf/types/known/durationpb" io "io" math "math" math_bits "math/bits" + time "time" ) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf +var _ = time.Kitchen // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -26,6 +30,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for the module. type Params struct { + AllowedPriceDelay time.Duration `protobuf:"bytes,1,opt,name=allowed_price_delay,json=allowedPriceDelay,proto3,stdduration" json:"allowed_price_delay"` } func (m *Params) Reset() { *m = Params{} } @@ -61,6 +66,13 @@ func (m *Params) XXX_DiscardUnknown() { var xxx_messageInfo_Params proto.InternalMessageInfo +func (m *Params) GetAllowedPriceDelay() time.Duration { + if m != nil { + return m.AllowedPriceDelay + } + return 0 +} + func init() { proto.RegisterType((*Params)(nil), "reserve.oracle.Params") } @@ -68,18 +80,24 @@ func init() { func init() { proto.RegisterFile("reserve/oracle/params.proto", fileDescriptor_0ad4cb2b8782abe8) } var fileDescriptor_0ad4cb2b8782abe8 = []byte{ - // 174 bytes of a gzipped FileDescriptorProto + // 265 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2e, 0x4a, 0x2d, 0x4e, 0x2d, 0x2a, 0x4b, 0xd5, 0xcf, 0x2f, 0x4a, 0x4c, 0xce, 0x49, 0xd5, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x83, 0x4a, 0xea, 0x41, 0x24, 0xa5, 0x04, 0x13, 0x73, 0x33, 0xf3, 0xf2, 0xf5, 0xc1, 0x24, 0x44, 0x89, 0x94, 0x48, 0x7a, 0x7e, 0x7a, 0x3e, - 0x98, 0xa9, 0x0f, 0x62, 0x41, 0x44, 0x95, 0xb4, 0xb8, 0xd8, 0x02, 0xc0, 0x06, 0x59, 0x29, 0xbc, - 0x58, 0x20, 0xcf, 0xd8, 0xf5, 0x7c, 0x83, 0x96, 0x38, 0xcc, 0xa2, 0x0a, 0x98, 0x55, 0x10, 0x15, - 0x4e, 0x9e, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, - 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xa5, 0x9f, 0x9e, 0x59, - 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x9f, 0x9f, 0x97, 0x9f, 0x5b, 0x09, 0x36, 0x3c, - 0x39, 0x3f, 0x47, 0x1f, 0xc3, 0xac, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0xb0, 0x02, 0x63, - 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x95, 0xbf, 0xc4, 0x08, 0xd5, 0x00, 0x00, 0x00, + 0x98, 0xa9, 0x0f, 0x62, 0x41, 0x45, 0xe5, 0xd2, 0xf3, 0xf3, 0xd3, 0x41, 0xa6, 0x81, 0x78, 0x49, + 0xa5, 0x69, 0xfa, 0x29, 0xa5, 0x45, 0x89, 0x25, 0x99, 0xf9, 0x79, 0x10, 0x79, 0xa5, 0x16, 0x46, + 0x2e, 0xb6, 0x00, 0xb0, 0x4d, 0x42, 0x11, 0x5c, 0xc2, 0x89, 0x39, 0x39, 0xf9, 0xe5, 0xa9, 0x29, + 0xf1, 0x05, 0x45, 0x99, 0xc9, 0xa9, 0xf1, 0x29, 0xa9, 0x39, 0x89, 0x95, 0x12, 0x8c, 0x0a, 0x8c, + 0x1a, 0xdc, 0x46, 0x92, 0x7a, 0x10, 0x83, 0xf4, 0x60, 0x06, 0xe9, 0xb9, 0x40, 0x0d, 0x72, 0xe2, + 0x3d, 0x71, 0x4f, 0x9e, 0x61, 0xc6, 0x7d, 0x79, 0xc6, 0x15, 0xcf, 0x37, 0x68, 0x31, 0x06, 0x09, + 0x42, 0x0d, 0x09, 0x00, 0x99, 0xe1, 0x02, 0x32, 0xc2, 0x4a, 0xe1, 0xc5, 0x02, 0x79, 0xc6, 0xae, + 0xe7, 0x1b, 0xb4, 0xc4, 0x61, 0x7e, 0xac, 0x80, 0xf9, 0x12, 0x62, 0xb7, 0x93, 0xe7, 0x89, 0x47, + 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, + 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0xe9, 0xa7, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, + 0x25, 0xe7, 0xe7, 0xea, 0xe7, 0xe7, 0xe5, 0xe7, 0x56, 0x82, 0x1d, 0x90, 0x9c, 0x9f, 0xa3, 0x8f, + 0x61, 0x56, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0x58, 0x81, 0x31, 0x20, 0x00, 0x00, 0xff, + 0xff, 0xd5, 0x02, 0xf0, 0xce, 0x50, 0x01, 0x00, 0x00, } func (this *Params) Equal(that interface{}) bool { @@ -101,6 +119,9 @@ func (this *Params) Equal(that interface{}) bool { } else if this == nil { return false } + if this.AllowedPriceDelay != that1.AllowedPriceDelay { + return false + } return true } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -123,6 +144,14 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + n1, err1 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(m.AllowedPriceDelay, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(m.AllowedPriceDelay):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintParams(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -143,6 +172,8 @@ func (m *Params) Size() (n int) { } var l int _ = l + l = github_com_cosmos_gogoproto_types.SizeOfStdDuration(m.AllowedPriceDelay) + n += 1 + l + sovParams(uint64(l)) return n } @@ -181,6 +212,39 @@ func (m *Params) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AllowedPriceDelay", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_cosmos_gogoproto_types.StdDurationUnmarshal(&m.AllowedPriceDelay, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/x/psm/keeper/abci.go b/x/psm/keeper/abci.go index c1d1ad96..2689433f 100644 --- a/x/psm/keeper/abci.go +++ b/x/psm/keeper/abci.go @@ -13,13 +13,13 @@ func (k Keeper) BeginBlocker(ctx context.Context) error { func (k Keeper) UpdatesStablecoinEpoch(ctx context.Context) error { updatePrice := func(info types.StablecoinInfo) bool { - price := k.OracleKeeper.GetPrice(ctx, info.Symbol, types.SymBolUSD) - if price == nil || price.IsNil() { + price, err := k.OracleKeeper.GetPrice(ctx, info.Symbol, types.SymBolUSD) + if err != nil { return false } - sc := k.stablecoinUpdate(ctx, *price, info) - err := k.StablecoinInfos.Set(ctx, sc.Denom, sc) + sc := k.stablecoinUpdate(ctx, price, info) + err = k.StablecoinInfos.Set(ctx, sc.Denom, sc) if err != nil { return false } diff --git a/x/psm/keeper/keeper_test.go b/x/psm/keeper/keeper_test.go index 84337c6f..f2b24d09 100644 --- a/x/psm/keeper/keeper_test.go +++ b/x/psm/keeper/keeper_test.go @@ -29,7 +29,7 @@ func (m MockOracleKeeper) SetPrice(ctx context.Context, denom string, price math m.prices[denom] = price } -func (s MockOracleKeeper) GetPrice(ctx context.Context, denom1 string, denom2 string) *math.LegacyDec { +func (s MockOracleKeeper) GetPrice(ctx context.Context, denom1 string, denom2 string) (math.LegacyDec, error) { price1, ok := s.prices[denom1] if !ok { @@ -40,7 +40,7 @@ func (s MockOracleKeeper) GetPrice(ctx context.Context, denom1 string, denom2 st panic("not found price " + denom2) } p := price1.Quo(price2) - return &p + return p, nil } func (s MockOracleKeeper) AddNewSymbolToBandOracleRequest(ctx context.Context, symbol string, oracleScriptId int64) error { diff --git a/x/psm/keeper/swap.go b/x/psm/keeper/swap.go index a214b6bc..95dcba90 100644 --- a/x/psm/keeper/swap.go +++ b/x/psm/keeper/swap.go @@ -4,9 +4,7 @@ import ( "context" "fmt" - "cosmossdk.io/errors" "cosmossdk.io/math" - oracletypes "github.com/onomyprotocol/reserve/x/oracle/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/onomyprotocol/reserve/x/psm/types" @@ -151,11 +149,11 @@ func (k Keeper) PayFeesIn(ctx context.Context, amount math.Int, denom string) (m // SwapToStablecoin return receiveAmount, fee, error func (k Keeper) calculateSwapToStablecoin(ctx context.Context, amount math.Int, sc types.StablecoinInfo) (math.Int, sdk.DecCoin, error) { - multiplier := k.OracleKeeper.GetPrice(ctx, sc.Symbol, types.SymBolUSD) - if multiplier == nil || multiplier.IsNil() { - return math.Int{}, sdk.DecCoin{}, errors.Wrapf(oracletypes.ErrInvalidOracle, "can not get price with base %s quote %s", sc.Symbol, types.ReserveStableCoinDenom) + multiplier, err := k.OracleKeeper.GetPrice(ctx, sc.Symbol, types.SymBolUSD) + if err != nil { + return math.Int{}, sdk.DecCoin{}, err } - amountStablecoin := amount.ToLegacyDec().Quo(*multiplier) + amountStablecoin := amount.ToLegacyDec().Quo(multiplier) fee, err := k.PayFeesOut(ctx, amountStablecoin.RoundInt(), sc.Denom) if err != nil { @@ -167,9 +165,9 @@ func (k Keeper) calculateSwapToStablecoin(ctx context.Context, amount math.Int, } func (k Keeper) calculateSwapToOnomyStableToken(ctx context.Context, stablecoin sdk.Coin, symBol string) (math.Int, sdk.DecCoin, error) { - multiplier := k.OracleKeeper.GetPrice(ctx, symBol, types.SymBolUSD) - if multiplier == nil || multiplier.IsNil() { - return math.Int{}, sdk.DecCoin{}, errors.Wrapf(oracletypes.ErrInvalidOracle, "can not get price with base %s quote %s", symBol, types.ReserveStableCoinDenom) + multiplier, err := k.OracleKeeper.GetPrice(ctx, symBol, types.SymBolUSD) + if err != nil { + return math.Int{}, sdk.DecCoin{}, err } amountnomUSD := multiplier.Mul(stablecoin.Amount.ToLegacyDec()) diff --git a/x/psm/types/expected_keepers.go b/x/psm/types/expected_keepers.go index 33bb2f4b..a49875c7 100644 --- a/x/psm/types/expected_keepers.go +++ b/x/psm/types/expected_keepers.go @@ -32,6 +32,6 @@ type ParamSubspace interface { } type OracleKeeper interface { - GetPrice(ctx context.Context, base, quote string) *math.LegacyDec + GetPrice(ctx context.Context, base, quote string) (math.LegacyDec, error) AddNewSymbolToBandOracleRequest(ctx context.Context, symbol string, oracleScriptId int64) error } diff --git a/x/vaults/keeper/mock/oracle_keeper.go b/x/vaults/keeper/mock/oracle_keeper.go index 4b295ff6..c250f3d2 100644 --- a/x/vaults/keeper/mock/oracle_keeper.go +++ b/x/vaults/keeper/mock/oracle_keeper.go @@ -16,7 +16,7 @@ func NewMockOracleKeeper() *MockOracleKeeper { } } -func (s *MockOracleKeeper) GetPrice(ctx context.Context, denom1 string, denom2 string) *math.LegacyDec { +func (s *MockOracleKeeper) GetPrice(ctx context.Context, denom1 string, denom2 string) (math.LegacyDec, error) { price1, ok := s.prices[denom1] if !ok { panic("not found price" + denom1) @@ -26,7 +26,7 @@ func (s *MockOracleKeeper) GetPrice(ctx context.Context, denom1 string, denom2 s panic("not found price" + denom2) } p := price1.Quo(price2) - return &p + return p, nil } func (s *MockOracleKeeper) SetPrice(denom string, price math.LegacyDec) { s.prices[denom] = price diff --git a/x/vaults/keeper/vault.go b/x/vaults/keeper/vault.go index 66f1a869..45ddabff 100644 --- a/x/vaults/keeper/vault.go +++ b/x/vaults/keeper/vault.go @@ -8,11 +8,9 @@ import ( "strconv" "time" - errors "cosmossdk.io/errors" "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" - oracletypes "github.com/onomyprotocol/reserve/x/oracle/types" "github.com/onomyprotocol/reserve/x/vaults/types" ) @@ -46,12 +44,12 @@ func (k *Keeper) CreateNewVault( } // Calculate collateral ratio - price := k.OracleKeeper.GetPrice(ctx, collateralSymbol, mintSymbol) - if price == nil || price.IsNil() { - return errors.Wrapf(oracletypes.ErrInvalidOracle, "CreateNewVault: can not get price with base %s quote %s", denom, types.DefaultMintDenoms) + price, err := k.OracleKeeper.GetPrice(ctx, collateralSymbol, mintSymbol) + if err != nil { + return err } // TODO: recalculate with denom decimal? - collateralValue := math.LegacyNewDecFromInt(collateral.Amount).Mul(*price) + collateralValue := math.LegacyNewDecFromInt(collateral.Amount).Mul(price) ratio := collateralValue.QuoInt(mint.Amount) if ratio.LT(vmParams.MinCollateralRatio) { @@ -187,11 +185,11 @@ func (k *Keeper) MintCoin( lockedCoin := vault.CollateralLocked collateralSymbol := vm.Symbol mintSymbol := vm.Params.MintSymbol - price := k.OracleKeeper.GetPrice(ctx, collateralSymbol, mintSymbol) - if price == nil || price.IsNil() { - return errors.Wrapf(oracletypes.ErrInvalidOracle, "MintCoin: can not get price with base %s quote %s", lockedCoin.Denom, types.DefaultMintDenoms) + price, err := k.OracleKeeper.GetPrice(ctx, collateralSymbol, mintSymbol) + if err != nil { + return err } - lockedValue := math.LegacyNewDecFromInt(lockedCoin.Amount).Mul(*price) + lockedValue := math.LegacyNewDecFromInt(lockedCoin.Amount).Mul(price) feeAmount := math.LegacyNewDecFromInt(mint.Amount).Mul(vm.Params.MintingFee).TruncateInt() feeCoin := sdk.NewCoin(mint.Denom, feeAmount) @@ -391,13 +389,13 @@ func (k *Keeper) WithdrawFromVault( newLock := vault.CollateralLocked.Sub(collateral) collateralSymbol := vm.Symbol mintSymbol := vm.Params.MintSymbol - price := k.OracleKeeper.GetPrice(ctx, collateralSymbol, mintSymbol) + price, err := k.OracleKeeper.GetPrice(ctx, collateralSymbol, mintSymbol) // defensive programming: should never happen since when withdraw should always have a valid oracle price - if price == nil || price.IsNil() { - return errors.Wrapf(oracletypes.ErrInvalidOracle, "WithdrawFromVault: can not get price with base %s quote %s", collateral.Denom, types.DefaultMintDenoms) + if err != nil { + return err } - newLockValue := math.LegacyNewDecFromInt(newLock.Amount).Mul(*price) + newLockValue := math.LegacyNewDecFromInt(newLock.Amount).Mul(price) // collateral ratio check if !vault.Debt.Amount.IsZero() { @@ -482,7 +480,6 @@ func (k *Keeper) shouldLiquidate( if math.LegacyNewDecFromInt(vault.Debt.Amount).Equal(math.LegacyZeroDec()) { return false, nil } - ratio := collateralValue.Quo(math.LegacyNewDecFromInt(vault.Debt.Amount)) if ratio.LTE(liquidationRatio) { @@ -509,11 +506,11 @@ func (k *Keeper) GetLiquidations( } collateralSymbol := vm.Symbol mintSymbol := vm.Params.MintSymbol - price := k.OracleKeeper.GetPrice(ctx, collateralSymbol, mintSymbol) - if price == nil || price.IsNil() { - return false, nil + price, err := k.OracleKeeper.GetPrice(ctx, collateralSymbol, mintSymbol) + if err != nil { + return false, err } - prices[vm.Denom] = *price + prices[vm.Denom] = price liquidationRatios[vm.Denom] = vm.Params.LiquidationRatio liquidations[vm.Denom] = types.NewEmptyLiquidation(vm.Denom, mintDenom) diff --git a/x/vaults/types/expected_keepers.go b/x/vaults/types/expected_keepers.go index f085a692..05333125 100644 --- a/x/vaults/types/expected_keepers.go +++ b/x/vaults/types/expected_keepers.go @@ -29,6 +29,6 @@ type BankKeeper interface { } type OracleKeeper interface { - GetPrice(ctx context.Context, base, quote string) *math.LegacyDec + GetPrice(ctx context.Context, base, quote string) (math.LegacyDec, error) AddNewSymbolToBandOracleRequest(ctx context.Context, symbol string, oracleScriptId int64) error }