Skip to content

Commit

Permalink
internalCanUpdate uses OIMF; need to fix e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyding committed Mar 19, 2024
1 parent 6bcd294 commit 6b03c0a
Show file tree
Hide file tree
Showing 19 changed files with 1,232 additions and 58 deletions.
85 changes: 79 additions & 6 deletions protocol/mocks/PerpetualsKeeper.go

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

40 changes: 40 additions & 0 deletions protocol/testutil/constants/perpetuals.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package constants

import (
"math/big"

"github.com/dydxprotocol/v4-chain/protocol/dtypes"
perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types"
)
Expand Down Expand Up @@ -81,6 +83,15 @@ var LiquidityTiers = []perptypes.LiquidityTier{
MaintenanceFractionPpm: 1_000_000,
ImpactNotional: 50_454_000_000,
},
{
Id: 9,
Name: "9",
InitialMarginPpm: 200_000, // 20%
MaintenanceFractionPpm: 500_000, // 20% * 0.5 = 10%
ImpactNotional: 2_500_000_000,
OpenInterestUpperCap: 50_000_000_000_000, // 50mm USDC
OpenInterestLowerCap: 25_000_000_000_000, // 25mm USDC
},
{
Id: 101,
Name: "101",
Expand All @@ -90,6 +101,22 @@ var LiquidityTiers = []perptypes.LiquidityTier{
},
}

// Perpetual OI setup in tests
var (
BtcUsd_OpenInterest1_AtomicRes8 = perptypes.OpenInterestDelta{
PerpetualId: 0,
BaseQuantumsDelta: big.NewInt(100_000_000),
}
EthUsd_OpenInterest1_AtomicRes9 = perptypes.OpenInterestDelta{
PerpetualId: 1,
BaseQuantumsDelta: big.NewInt(1_000_000_000),
}
DefaultTestPerpOIs = []perptypes.OpenInterestDelta{
BtcUsd_OpenInterest1_AtomicRes8,
EthUsd_OpenInterest1_AtomicRes9,
}
)

// Perpetual genesis parameters.
const TestFundingRateClampFactorPpm = 6_000_000
const TestPremiumVoteClampFactorPpm = 60_000_000
Expand Down Expand Up @@ -237,6 +264,19 @@ var (
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
BtcUsd_20PercentInitial_10PercentMaintenance_25mmLowerCap_50mmUpperCap = perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Id: 0,
Ticker: "BTC-USD 20/10 margin requirements",
MarketId: uint32(0),
AtomicResolution: int32(-8),
DefaultFundingPpm: int32(0),
LiquidityTier: uint32(9),
MarketType: perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS,
},
FundingIndex: dtypes.ZeroInt(),
OpenInterest: dtypes.ZeroInt(),
}
BtcUsd_NoMarginRequirement = perptypes.Perpetual{
Params: perptypes.PerpetualParams{
Id: 0,
Expand Down
28 changes: 28 additions & 0 deletions protocol/testutil/perpetuals/perpetuals.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ package perpetuals

import (
"math/big"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"

"github.com/dydxprotocol/v4-chain/protocol/dtypes"
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants"
perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types"
)

Expand Down Expand Up @@ -114,3 +119,26 @@ func abs(n int64) int64 {
}
return n
}

func SetUpDefaultPerpOIsForTest(
t *testing.T,
ctx sdk.Context,
k perptypes.PerpetualsKeeper,
perps []perptypes.Perpetual,
) {
for _, perpOI := range constants.DefaultTestPerpOIs {
for _, perp := range perps {
if perp.Params.Id != perpOI.PerpetualId {
continue
}
// If the perpetual exists in input, set up the open interest.
require.NoError(t,
k.ModifyOpenInterest(
ctx,
perp.Params.Id,
perpOI.BaseQuantumsDelta,
),
)
}
}
}
Loading

0 comments on commit 6b03c0a

Please sign in to comment.