Skip to content

Commit

Permalink
initiate interfaces in margin keeper
Browse files Browse the repository at this point in the history
  • Loading branch information
kenta-elys committed Aug 31, 2023
1 parent dedafa6 commit de2fcf1
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 44 deletions.
2 changes: 1 addition & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions x/accountedpool/keeper/accounted_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (k Keeper) GetAccountedPool(
b := store.Get(types.AccountedPoolKey(
PoolId,
))

if b == nil {
return val, false
}
Expand Down
17 changes: 1 addition & 16 deletions x/accountedpool/keeper/invariant_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions x/accountedpool/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (

type (
Keeper struct {
types.InvariantChecker

cdc codec.BinaryCodec
storeKey storetypes.StoreKey
memKey storetypes.StoreKey
Expand Down
5 changes: 0 additions & 5 deletions x/accountedpool/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions x/accountedpool/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
19 changes: 18 additions & 1 deletion x/amm/types/query.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion x/margin/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewKeeper(
panic("authority is not a valid acc address")
}

return &Keeper{
keeper := &Keeper{
cdc: cdc,
storeKey: storeKey,
memKey: memKey,
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion x/margin/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 43 additions & 4 deletions x/margin/types/mocks/amm_keeper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions x/margin/types/mocks/position_checker.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/margin/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewParams() Params {
SqModifier: sdk.NewDec(1),
SafetyFactor: sdk.NewDec(1),
IncrementalInterestPaymentEnabled: true,
WhitelistingEnabled: true,
WhitelistingEnabled: false,
}
}

Expand Down
4 changes: 2 additions & 2 deletions x/margin/types/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
}
}
Expand Down

0 comments on commit de2fcf1

Please sign in to comment.