diff --git a/config.yml b/config.yml index a7e4a4de6..e36eb2eaf 100644 --- a/config.yml +++ b/config.yml @@ -357,5 +357,5 @@ genesis: sq_modifier: "1.0" safety_factor: "1.0" incremental_interest_payment_enabled: true - whitelisting_enabled: true + whitelisting_enabled: false chain_id: elystestnet-1 diff --git a/x/accountedpool/keeper/accounted_pool.go b/x/accountedpool/keeper/accounted_pool.go index 6d7d36853..5c336654f 100644 --- a/x/accountedpool/keeper/accounted_pool.go +++ b/x/accountedpool/keeper/accounted_pool.go @@ -26,6 +26,7 @@ func (k Keeper) GetAccountedPool( b := store.Get(types.AccountedPoolKey( PoolId, )) + if b == nil { return val, false } diff --git a/x/accountedpool/keeper/invariant_check_test.go b/x/accountedpool/keeper/invariant_check_test.go index a95023291..7ef1dca8b 100644 --- a/x/accountedpool/keeper/invariant_check_test.go +++ b/x/accountedpool/keeper/invariant_check_test.go @@ -12,7 +12,6 @@ import ( "github.com/stretchr/testify/require" margintypes "github.com/elys-network/elys/x/margin/types" - "github.com/elys-network/elys/x/margin/types/mocks" ) func TestCheckBalanceInvariant_InvalidBalance(t *testing.T) { @@ -101,23 +100,9 @@ func TestCheckBalanceInvariant_InvalidBalance(t *testing.T) { margintypes.Position_LONG, sdk.NewDec(5), ) - // Setup the mock checker - mockAuthorizationChecker := new(mocks.AuthorizationChecker) - mk.AuthorizationChecker = mockAuthorizationChecker - - // Mock behavior - mockAuthorizationChecker.On("IsWhitelistingEnabled", ctx).Return(true) - mockAuthorizationChecker.On("CheckIfWhitelisted", ctx, pool.GetAddress()).Return(true) - - // Setup the mock checker - mockPositionChecker := new(mocks.PositionChecker) - - // Mock behavior - mockPositionChecker.On("GetOpenMTPCount", ctx).Return(uint64(0)) - mockPositionChecker.On("GetMaxOpenPositions", ctx).Return(10) - mk.PositionChecker = mockPositionChecker _, err = mk.Open(ctx, msg2) + panic(err) require.NoError(t, err) mtps := mk.GetAllMTPs(ctx) diff --git a/x/accountedpool/keeper/keeper.go b/x/accountedpool/keeper/keeper.go index efd7afe72..504cc2818 100644 --- a/x/accountedpool/keeper/keeper.go +++ b/x/accountedpool/keeper/keeper.go @@ -14,8 +14,6 @@ import ( type ( Keeper struct { - types.InvariantChecker - cdc codec.BinaryCodec storeKey storetypes.StoreKey memKey storetypes.StoreKey diff --git a/x/accountedpool/types/expected_keepers.go b/x/accountedpool/types/expected_keepers.go index 3caaa6276..fe4eae176 100644 --- a/x/accountedpool/types/expected_keepers.go +++ b/x/accountedpool/types/expected_keepers.go @@ -53,8 +53,3 @@ type MarginKeeper interface { IsPoolClosed(ctx sdk.Context, poolId uint64) bool GetAllMTPs(ctx sdk.Context) []margintypes.MTP } - -//go:generate mockery --srcpkg . --name InvariantChecker --structname InvariantChecker --filename invariant_check.go --with-expecter -type InvariantChecker interface { - InvariantCheck(ctx sdk.Context) error -} diff --git a/x/accountedpool/types/keys.go b/x/accountedpool/types/keys.go index ce94a5a8f..65e087f95 100644 --- a/x/accountedpool/types/keys.go +++ b/x/accountedpool/types/keys.go @@ -2,7 +2,7 @@ package types const ( // ModuleName defines the module name - ModuleName = "tvl" + ModuleName = "poolaccounted" // StoreKey defines the primary module store key StoreKey = ModuleName @@ -11,10 +11,10 @@ const ( RouterKey = ModuleName // MemStoreKey defines the in-memory store key - MemStoreKey = "mem_tvl" + MemStoreKey = "mem_poolaccounted" - // ParamsKey is the prefix for parameters of margin module - ParamsKey = "tvl_params" + // ParamsKey is the prefix for parameters of poolaccounted module + ParamsKey = "poolaccounted_params" ) func KeyPrefix(p string) []byte { diff --git a/x/amm/types/query.pb.gw.go b/x/amm/types/query.pb.gw.go index 2babba22a..3b891ece9 100644 --- a/x/amm/types/query.pb.gw.go +++ b/x/amm/types/query.pb.gw.go @@ -20,6 +20,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" ) @@ -30,6 +31,7 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage +var _ = metadata.Join func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryParamsRequest @@ -232,12 +234,14 @@ func local_request_Query_DenomLiquidityAll_0(ctx context.Context, marshaler runt // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -245,6 +249,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -258,6 +263,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_Pool_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -265,6 +272,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_Pool_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -278,6 +286,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_PoolAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -285,6 +295,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_PoolAll_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -298,6 +309,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_DenomLiquidity_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -305,6 +318,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_DenomLiquidity_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) @@ -318,6 +332,8 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv mux.Handle("GET", pattern_Query_DenomLiquidityAll_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) if err != nil { @@ -325,6 +341,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } resp, md, err := local_request_Query_DenomLiquidityAll_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) diff --git a/x/margin/keeper/keeper.go b/x/margin/keeper/keeper.go index 5b595d0a3..4509324b6 100644 --- a/x/margin/keeper/keeper.go +++ b/x/margin/keeper/keeper.go @@ -54,7 +54,7 @@ func NewKeeper( panic("authority is not a valid acc address") } - return &Keeper{ + keeper := &Keeper{ cdc: cdc, storeKey: storeKey, memKey: memKey, @@ -64,6 +64,13 @@ func NewKeeper( oracleKeeper: oracleKeeper, apKeeper: apKeeper, } + + keeper.AuthorizationChecker = keeper + keeper.PositionChecker = keeper + keeper.PoolChecker = keeper + keeper.OpenLongChecker = keeper + + return keeper } func (k Keeper) Logger(ctx sdk.Context) log.Logger { diff --git a/x/margin/types/expected_keepers.go b/x/margin/types/expected_keepers.go index fdcb7bb59..1d449f58c 100644 --- a/x/margin/types/expected_keepers.go +++ b/x/margin/types/expected_keepers.go @@ -16,7 +16,7 @@ type AuthorizationChecker interface { //go:generate mockery --srcpkg . --name PositionChecker --structname PositionChecker --filename position_checker.go --with-expecter type PositionChecker interface { GetOpenMTPCount(ctx sdk.Context) uint64 - GetMaxOpenPositions(ctx sdk.Context) int + GetMaxOpenPositions(ctx sdk.Context) int64 } //go:generate mockery --srcpkg . --name PoolChecker --structname PoolChecker --filename pool_checker.go --with-expecter diff --git a/x/margin/types/mocks/amm_keeper.go b/x/margin/types/mocks/amm_keeper.go index 8d9cc0ee6..12be364ed 100644 --- a/x/margin/types/mocks/amm_keeper.go +++ b/x/margin/types/mocks/amm_keeper.go @@ -39,10 +39,6 @@ func (_m *AmmKeeper) GetAllPool(_a0 types.Context) []ammtypes.Pool { return r0 } -func (_m *AmmKeeper) GetPoolSnapshotOrSet(ctx types.Context, pool ammtypes.Pool) ammtypes.Pool { - return ammtypes.Pool{} -} - // AmmKeeper_GetAllPool_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAllPool' type AmmKeeper_GetAllPool_Call struct { *mock.Call @@ -169,6 +165,49 @@ func (_c *AmmKeeper_GetPool_Call) RunAndReturn(run func(types.Context, uint64) ( return _c } +// GetPoolSnapshotOrSet provides a mock function with given fields: ctx, pool +func (_m *AmmKeeper) GetPoolSnapshotOrSet(ctx types.Context, pool ammtypes.Pool) ammtypes.Pool { + ret := _m.Called(ctx, pool) + + var r0 ammtypes.Pool + if rf, ok := ret.Get(0).(func(types.Context, ammtypes.Pool) ammtypes.Pool); ok { + r0 = rf(ctx, pool) + } else { + r0 = ret.Get(0).(ammtypes.Pool) + } + + return r0 +} + +// AmmKeeper_GetPoolSnapshotOrSet_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPoolSnapshotOrSet' +type AmmKeeper_GetPoolSnapshotOrSet_Call struct { + *mock.Call +} + +// GetPoolSnapshotOrSet is a helper method to define mock.On call +// - ctx types.Context +// - pool ammtypes.Pool +func (_e *AmmKeeper_Expecter) GetPoolSnapshotOrSet(ctx interface{}, pool interface{}) *AmmKeeper_GetPoolSnapshotOrSet_Call { + return &AmmKeeper_GetPoolSnapshotOrSet_Call{Call: _e.mock.On("GetPoolSnapshotOrSet", ctx, pool)} +} + +func (_c *AmmKeeper_GetPoolSnapshotOrSet_Call) Run(run func(ctx types.Context, pool ammtypes.Pool)) *AmmKeeper_GetPoolSnapshotOrSet_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(types.Context), args[1].(ammtypes.Pool)) + }) + return _c +} + +func (_c *AmmKeeper_GetPoolSnapshotOrSet_Call) Return(val ammtypes.Pool) *AmmKeeper_GetPoolSnapshotOrSet_Call { + _c.Call.Return(val) + return _c +} + +func (_c *AmmKeeper_GetPoolSnapshotOrSet_Call) RunAndReturn(run func(types.Context, ammtypes.Pool) ammtypes.Pool) *AmmKeeper_GetPoolSnapshotOrSet_Call { + _c.Call.Return(run) + return _c +} + // IterateLiquidityPools provides a mock function with given fields: _a0, _a1 func (_m *AmmKeeper) IterateLiquidityPools(_a0 types.Context, _a1 func(ammtypes.Pool) bool) { _m.Called(_a0, _a1) diff --git a/x/margin/types/mocks/position_checker.go b/x/margin/types/mocks/position_checker.go index 2a47de92d..6132367bc 100644 --- a/x/margin/types/mocks/position_checker.go +++ b/x/margin/types/mocks/position_checker.go @@ -21,14 +21,14 @@ func (_m *PositionChecker) EXPECT() *PositionChecker_Expecter { } // GetMaxOpenPositions provides a mock function with given fields: ctx -func (_m *PositionChecker) GetMaxOpenPositions(ctx types.Context) int { +func (_m *PositionChecker) GetMaxOpenPositions(ctx types.Context) int64 { ret := _m.Called(ctx) - var r0 int - if rf, ok := ret.Get(0).(func(types.Context) int); ok { + var r0 int64 + if rf, ok := ret.Get(0).(func(types.Context) int64); ok { r0 = rf(ctx) } else { - r0 = ret.Get(0).(int) + r0 = ret.Get(0).(int64) } return r0 @@ -52,12 +52,12 @@ func (_c *PositionChecker_GetMaxOpenPositions_Call) Run(run func(ctx types.Conte return _c } -func (_c *PositionChecker_GetMaxOpenPositions_Call) Return(_a0 int) *PositionChecker_GetMaxOpenPositions_Call { +func (_c *PositionChecker_GetMaxOpenPositions_Call) Return(_a0 int64) *PositionChecker_GetMaxOpenPositions_Call { _c.Call.Return(_a0) return _c } -func (_c *PositionChecker_GetMaxOpenPositions_Call) RunAndReturn(run func(types.Context) int) *PositionChecker_GetMaxOpenPositions_Call { +func (_c *PositionChecker_GetMaxOpenPositions_Call) RunAndReturn(run func(types.Context) int64) *PositionChecker_GetMaxOpenPositions_Call { _c.Call.Return(run) return _c } diff --git a/x/margin/types/params.go b/x/margin/types/params.go index 557d14373..57b5d5cd6 100644 --- a/x/margin/types/params.go +++ b/x/margin/types/params.go @@ -56,7 +56,7 @@ func NewParams() Params { SqModifier: sdk.NewDec(1), SafetyFactor: sdk.NewDec(1), IncrementalInterestPaymentEnabled: true, - WhitelistingEnabled: true, + WhitelistingEnabled: false, } } diff --git a/x/margin/types/pool.go b/x/margin/types/pool.go index 44d6f1ede..66e98dd65 100644 --- a/x/margin/types/pool.go +++ b/x/margin/types/pool.go @@ -9,10 +9,10 @@ import ( func NewPool(poolId uint64) Pool { return Pool{ AmmPoolId: poolId, - Health: sdk.ZeroDec(), + Health: sdk.NewDec(100), Enabled: true, Closed: false, - InterestRate: sdk.ZeroDec(), + InterestRate: sdk.NewDecFromIntWithPrec(sdk.NewInt(1), 1), PoolAssets: []PoolAsset{}, } }