Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyding committed Mar 19, 2024
1 parent 6bcd294 commit 721cd18
Show file tree
Hide file tree
Showing 17 changed files with 1,266 additions and 64 deletions.
22 changes: 22 additions & 0 deletions protocol/testutil/constants/perpetuals.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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 Down Expand Up @@ -237,6 +246,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
3 changes: 3 additions & 0 deletions protocol/x/clob/keeper/deleveraging.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ func (k Keeper) OffsetSubaccountPerpetualPosition(
deltaBaseQuantums,
deltaQuoteQuantums,
); err == nil {
fmt.Printf("!! ProcessDeleveraging succeeced\n")
// Update the remaining liquidatable quantums.
deltaQuantumsRemaining.Sub(deltaQuantumsRemaining, deltaBaseQuantums)
fills = append(fills, types.MatchPerpetualDeleveraging_Fill{
Expand Down Expand Up @@ -428,6 +429,7 @@ func (k Keeper) OffsetSubaccountPerpetualPosition(
),
)
} else {
fmt.Printf("!! ProcessDeleveraging failed, err = %v\n", err)
// If an error is returned, it's likely because the subaccounts' bankruptcy prices do not overlap.
// TODO(CLOB-75): Support deleveraging subaccounts with non overlapping bankruptcy prices.
liquidatedSubaccount := k.subaccountsKeeper.GetSubaccount(ctx, liquidatedSubaccountId)
Expand Down Expand Up @@ -581,6 +583,7 @@ func (k Keeper) ProcessDeleveraging(
}

// Apply the update.
// TODO(): OIMF?
success, successPerUpdate, err := k.subaccountsKeeper.UpdateSubaccounts(ctx, updates, satypes.Match)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 721cd18

Please sign in to comment.