Skip to content

Commit

Permalink
refactor: remaining refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmic-vagabond committed Oct 13, 2023
1 parent ad1538e commit 6999555
Show file tree
Hide file tree
Showing 28 changed files with 519 additions and 380 deletions.
411 changes: 294 additions & 117 deletions docs/static/openapi.yml

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions proto/elys/margin/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ message MsgOpenResponse {}
message MsgClose {
string creator = 1;
uint64 id = 2;
string collateralAsset = 3;
string custodyAsset = 4;
}

message MsgCloseResponse {}
Expand Down
10 changes: 0 additions & 10 deletions proto/elys/margin/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ enum Position {
message MTP {
string address = 1;
repeated cosmos.base.v1beta1.Coin collaterals = 2 [(gogoproto.nullable) = false];
// repeated string collateral_assets = 2;
// repeated string collateral_amounts = 3 [
// (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
// (gogoproto.nullable) = false
// ];
string liabilities = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
Expand All @@ -38,11 +33,6 @@ message MTP {
(gogoproto.nullable) = false
];
repeated cosmos.base.v1beta1.Coin custodies = 7 [(gogoproto.nullable) = false];
// repeated string custody_assets = 8;
// repeated string custody_amounts = 9 [
// (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
// (gogoproto.nullable) = false
// ];
repeated string leverages = 8 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
Expand Down
6 changes: 3 additions & 3 deletions x/accountedpool/keeper/hooks_margin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
margintypes "github.com/elys-network/elys/x/margin/types"
)

func (k Keeper) AfterMarginPositionOpended(ctx sdk.Context, ammPool ammtypes.Pool, marginPool margintypes.Pool) {
func (k Keeper) AfterMarginPositionOpen(ctx sdk.Context, ammPool ammtypes.Pool, marginPool margintypes.Pool) {
k.UpdateAccountedPool(ctx, ammPool, marginPool)
}

Expand Down Expand Up @@ -50,8 +50,8 @@ func (k Keeper) MarginHooks() MarginHooks {
return MarginHooks{k}
}

func (h MarginHooks) AfterMarginPositionOpended(ctx sdk.Context, ammPool ammtypes.Pool, marginPool margintypes.Pool) {
h.k.AfterMarginPositionOpended(ctx, ammPool, marginPool)
func (h MarginHooks) AfterMarginPositionOpen(ctx sdk.Context, ammPool ammtypes.Pool, marginPool margintypes.Pool) {
h.k.AfterMarginPositionOpen(ctx, ammPool, marginPool)
}

func (h MarginHooks) AfterMarginPositionModified(ctx sdk.Context, ammPool ammtypes.Pool, marginPool margintypes.Pool) {
Expand Down
16 changes: 8 additions & 8 deletions x/margin/keeper/close.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ func (k Keeper) Close(ctx sdk.Context, msg *types.MsgClose) (*types.MsgCloseResp
sdk.NewAttribute("id", strconv.FormatInt(int64(closedMtp.Id), 10)),
sdk.NewAttribute("position", closedMtp.Position.String()),
sdk.NewAttribute("address", closedMtp.Address),
sdk.NewAttribute("collateral_asset", closedMtp.CollateralAssets[0]),
sdk.NewAttribute("collateral_amount", closedMtp.CollateralAmounts[0].String()),
sdk.NewAttribute("custody_asset", closedMtp.CustodyAssets[0]),
sdk.NewAttribute("custody_amount", closedMtp.CustodyAmounts[0].String()),
// sdk.NewAttribute("collateral_asset", closedMtp.CollateralAssets[0]),
// sdk.NewAttribute("collateral_amount", closedMtp.CollateralAmounts[0].String()),
// sdk.NewAttribute("custody_asset", closedMtp.CustodyAssets[0]),
// sdk.NewAttribute("custody_amount", closedMtp.CustodyAmounts[0].String()),
sdk.NewAttribute("repay_amount", repayAmount.String()),
sdk.NewAttribute("leverage", closedMtp.Leverages[0].String()),
// sdk.NewAttribute("leverage", closedMtp.Leverages[0].String()),
sdk.NewAttribute("liabilities", closedMtp.Liabilities.String()),
sdk.NewAttribute("interest_paid_collateral", mtp.InterestPaidCollaterals[0].String()),
sdk.NewAttribute("interest_paid_custody", mtp.InterestPaidCustodys[0].String()),
sdk.NewAttribute("interest_unpaid_collateral", closedMtp.InterestUnpaidCollaterals[0].String()),
// sdk.NewAttribute("interest_paid_collateral", mtp.InterestPaidCollaterals[0].String()),
// sdk.NewAttribute("interest_paid_custody", mtp.InterestPaidCustodys[0].String()),
// sdk.NewAttribute("interest_unpaid_collateral", closedMtp.InterestUnpaidCollaterals[0].String()),
sdk.NewAttribute("health", closedMtp.MtpHealth.String()),
))

Expand Down
10 changes: 6 additions & 4 deletions x/margin/keeper/close_short.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ func (k Keeper) CloseShort(ctx sdk.Context, msg *types.MsgClose) (*types.MTP, sd
}

repayAmount := sdk.ZeroInt()
for _, custodyAsset := range mtp.CustodyAssets {
for _, custody := range mtp.Custodies {
custodyAsset := custody.Denom
// Retrieve AmmPool
ammPool, err := k.CloseShortChecker.GetAmmPool(ctx, mtp.AmmPoolId, custodyAsset)
if err != nil {
return nil, sdk.ZeroInt(), err
}

for _, collateralAsset := range mtp.CollateralAssets {

for _, collateral := range mtp.Collaterals {
collateralAsset := collateral.Denom
// Handle Interest if within epoch position
if err := k.CloseShortChecker.HandleInterest(ctx, &mtp, &pool, ammPool, collateralAsset, custodyAsset); err != nil {
return nil, sdk.ZeroInt(), err
Expand All @@ -41,7 +42,8 @@ func (k Keeper) CloseShort(ctx sdk.Context, msg *types.MsgClose) (*types.MTP, sd
return nil, sdk.ZeroInt(), err
}

for _, collateralAsset := range mtp.CollateralAssets {
for _, collateral := range mtp.Collaterals {
collateralAsset := collateral.Denom
// Estimate swap and repay
repayAmt, err := k.CloseShortChecker.EstimateAndRepay(ctx, mtp, pool, ammPool, collateralAsset, custodyAsset)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions x/margin/keeper/estimate_and_repay.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

func (k Keeper) EstimateAndRepay(ctx sdk.Context, mtp types.MTP, pool types.Pool, ammPool ammtypes.Pool, collateralAsset string, custodyAsset string) (sdk.Int, error) {
collateralIndex, custodyIndex := k.GetMTPAssetIndex(&mtp, collateralAsset, custodyAsset)
cutodyAmtTokenIn := sdk.NewCoin(mtp.CustodyAssets[custodyIndex], mtp.CustodyAmounts[custodyIndex])
repayAmount, err := k.EstimateSwap(ctx, cutodyAmtTokenIn, mtp.CollateralAssets[collateralIndex], ammPool)
cutodyAmtTokenIn := sdk.NewCoin(mtp.Custodies[custodyIndex].Denom, mtp.Custodies[custodyIndex].Amount)
repayAmount, err := k.EstimateSwap(ctx, cutodyAmtTokenIn, mtp.Collaterals[collateralIndex].Denom, ammPool)
if err != nil {
return sdk.ZeroInt(), err
}
Expand Down
9 changes: 6 additions & 3 deletions x/margin/keeper/force_close_long.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ func (k Keeper) ForceCloseLong(ctx sdk.Context, mtp *types.MTP, pool *types.Pool

if epochPosition > 0 {
repayAmount := sdk.ZeroInt()
for _, custodyAsset := range mtp.CustodyAssets {
for _, custody := range mtp.Custodies {
custodyAsset := custody.Denom
// Retrieve AmmPool
ammPool, err := k.GetAmmPool(ctx, mtp.AmmPoolId, custodyAsset)
if err != nil {
return math.ZeroInt(), err
}

for _, collateralAsset := range mtp.CollateralAssets {
for _, collateral := range mtp.Collaterals {
collateralAsset := collateral.Denom
// Handle Interest if within epoch position
if err := k.HandleInterest(ctx, mtp, pool, ammPool, collateralAsset, custodyAsset); err != nil {
return math.ZeroInt(), err
Expand All @@ -39,7 +41,8 @@ func (k Keeper) ForceCloseLong(ctx sdk.Context, mtp *types.MTP, pool *types.Pool
return math.ZeroInt(), err
}

for _, collateralAsset := range mtp.CollateralAssets {
for _, collateral := range mtp.Collaterals {
collateralAsset := collateral.Denom
// Estimate swap and repay
repayAmt, err := k.EstimateAndRepay(ctx, *mtp, *pool, ammPool, collateralAsset, custodyAsset)
if err != nil {
Expand Down
9 changes: 6 additions & 3 deletions x/margin/keeper/force_close_short.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ func (k Keeper) ForceCloseShort(ctx sdk.Context, mtp *types.MTP, pool *types.Poo

if epochPosition > 0 {
repayAmount := sdk.ZeroInt()
for _, custodyAsset := range mtp.CustodyAssets {
for _, custody := range mtp.Custodies {
custodyAsset := custody.Denom
// Retrieve AmmPool
ammPool, err := k.GetAmmPool(ctx, mtp.AmmPoolId, custodyAsset)
if err != nil {
return math.ZeroInt(), err
}

for _, collateralAsset := range mtp.CollateralAssets {
for _, collateral := range mtp.Collaterals {
collateralAsset := collateral.Denom
// Handle Interest if within epoch position
if err := k.HandleInterest(ctx, mtp, pool, ammPool, collateralAsset, custodyAsset); err != nil {
return math.ZeroInt(), err
Expand All @@ -39,7 +41,8 @@ func (k Keeper) ForceCloseShort(ctx sdk.Context, mtp *types.MTP, pool *types.Poo
return math.ZeroInt(), err
}

for _, collateralAsset := range mtp.CollateralAssets {
for _, collateral := range mtp.Collaterals {
collateralAsset := collateral.Denom
// Estimate swap and repay
repayAmt, err := k.EstimateAndRepay(ctx, *mtp, *pool, ammPool, collateralAsset, custodyAsset)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions x/margin/keeper/generate_open_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ import (
)

func (k Keeper) GenerateOpenEvent(mtp *types.MTP) sdk.Event {
collateralIndex := len(mtp.CollateralAssets) - 1
custodyIndex := len(mtp.CustodyAssets) - 1
collateralIndex := len(mtp.Collaterals) - 1
custodyIndex := len(mtp.Custodies) - 1
mtpPosIndex := len(mtp.Leverages) - 1

return sdk.NewEvent(types.EventOpen,
sdk.NewAttribute("id", strconv.FormatInt(int64(mtp.Id), 10)),
sdk.NewAttribute("position", mtp.Position.String()),
sdk.NewAttribute("address", mtp.Address),
sdk.NewAttribute("collateral_asset", mtp.CollateralAssets[collateralIndex]),
sdk.NewAttribute("collateral_amount", mtp.CollateralAmounts[collateralIndex].String()),
sdk.NewAttribute("custody_asset", mtp.CustodyAssets[custodyIndex]),
sdk.NewAttribute("custody_amount", mtp.CustodyAmounts[custodyIndex].String()),
sdk.NewAttribute("collateral_asset", mtp.Collaterals[collateralIndex].Denom),
sdk.NewAttribute("collateral_amount", mtp.Collaterals[collateralIndex].Amount.String()),
sdk.NewAttribute("custody_asset", mtp.Custodies[custodyIndex].Denom),
sdk.NewAttribute("custody_amount", mtp.Custodies[custodyIndex].Amount.String()),
sdk.NewAttribute("leverage", mtp.Leverages[mtpPosIndex].String()),
sdk.NewAttribute("liabilities", mtp.Liabilities.String()),
sdk.NewAttribute("interest_paid_collateral", mtp.InterestPaidCollaterals[collateralIndex].String()),
sdk.NewAttribute("interest_paid_custody", mtp.InterestPaidCustodys[custodyIndex].String()),
sdk.NewAttribute("interest_paid_custody", mtp.InterestPaidCustodies[custodyIndex].String()),
sdk.NewAttribute("interest_unpaid_collateral", mtp.InterestUnpaidCollaterals[collateralIndex].String()),
sdk.NewAttribute("health", mtp.MtpHealth.String()),
)
Expand Down
2 changes: 1 addition & 1 deletion x/margin/keeper/handle_interest_payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (k Keeper) HandleInterestPayment(ctx sdk.Context, collateralAsset string, c
}

// collateralAsset is in base currency
if mtp.CollateralAssets[collateralIndex] == ptypes.BaseCurrency {
if mtp.Collaterals[collateralIndex].Denom == ptypes.BaseCurrency {
mtp.InterestUnpaidCollaterals[collateralIndex] = interestPayment
} else {
// swap
Expand Down
4 changes: 2 additions & 2 deletions x/margin/keeper/invariant_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func (k Keeper) AmmPoolBalanceCheck(ctx sdk.Context, poolId uint64) error {
continue
}

for i := range mtp.CollateralAssets {
mtpCollateralBalances = mtpCollateralBalances.Add(sdk.NewCoin(mtp.CollateralAssets[i], mtp.CollateralAmounts[i]))
for i := range mtp.Collaterals {
mtpCollateralBalances = mtpCollateralBalances.Add(sdk.NewCoin(mtp.Collaterals[i].Denom, mtp.Collaterals[i].Amount))
}
}

Expand Down
36 changes: 18 additions & 18 deletions x/margin/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ func (k Keeper) Borrow(ctx sdk.Context, collateralAsset string, custodyAsset str
return sdkerrors.Wrap(types.ErrBalanceNotAvailable, "MTP collateral or custody invalid!")
}

mtp.CollateralAmounts[collateralIndex] = mtp.CollateralAmounts[collateralIndex].Add(collateralAmount)
mtp.Collaterals[collateralIndex].Amount = mtp.Collaterals[collateralIndex].Amount.Add(collateralAmount)
mtp.Liabilities = mtp.Liabilities.Add(sdk.NewIntFromBigInt(liabilitiesDec.TruncateInt().BigInt()))
mtp.CustodyAmounts[custodyIndex] = mtp.CustodyAmounts[custodyIndex].Add(custodyAmount)
mtp.Custodies[custodyIndex].Amount = mtp.Custodies[custodyIndex].Amount.Add(custodyAmount)
mtp.Leverages = append(mtp.Leverages, eta.Add(sdk.OneDec()))

// print mtp.CustodyAmount
ctx.Logger().Info(fmt.Sprintf("mtp.CustodyAmount: %s", mtp.CustodyAmounts[custodyIndex].String()))
ctx.Logger().Info(fmt.Sprintf("mtp.CustodyAmount: %s", mtp.Custodies[custodyIndex].Amount.String()))

h, err := k.UpdateMTPHealth(ctx, *mtp, *ammPool) // set mtp in func or return h?
if err != nil {
Expand Down Expand Up @@ -244,12 +244,12 @@ func (k Keeper) CalculatePoolHealth(ctx sdk.Context, pool *types.Pool) sdk.Dec {
}

func (k Keeper) TakeInCustody(ctx sdk.Context, mtp types.MTP, pool *types.Pool) error {
for i := range mtp.CustodyAssets {
err := pool.UpdateBalance(ctx, mtp.CustodyAssets[i], mtp.CustodyAmounts[i], false)
for i := range mtp.Custodies {
err := pool.UpdateBalance(ctx, mtp.Custodies[i].Denom, mtp.Custodies[i].Amount, false)
if err != nil {
return nil
}
err = pool.UpdateCustody(ctx, mtp.CustodyAssets[i], mtp.CustodyAmounts[i], true)
err = pool.UpdateCustody(ctx, mtp.Custodies[i].Denom, mtp.Custodies[i].Amount, true)
if err != nil {
return nil
}
Expand All @@ -265,10 +265,10 @@ func (k Keeper) IncrementalInterestPayment(ctx sdk.Context, collateralAsset stri
// if mtp has unpaid interest, add to payment
// convert it into base currency
if mtp.InterestUnpaidCollaterals[collateralIndex].GT(sdk.ZeroInt()) {
if mtp.CollateralAssets[collateralIndex] == ptypes.BaseCurrency {
if mtp.Collaterals[collateralIndex].Denom == ptypes.BaseCurrency {
interestPayment = interestPayment.Add(mtp.InterestUnpaidCollaterals[collateralIndex])
} else {
unpaidCollateralIn := sdk.NewCoin(mtp.CollateralAssets[collateralIndex], mtp.InterestUnpaidCollaterals[collateralIndex])
unpaidCollateralIn := sdk.NewCoin(mtp.Collaterals[collateralIndex].Denom, mtp.InterestUnpaidCollaterals[collateralIndex])
C, err := k.EstimateSwapGivenOut(ctx, unpaidCollateralIn, ptypes.BaseCurrency, ammPool)
if err != nil {
return sdk.ZeroInt(), err
Expand All @@ -280,7 +280,7 @@ func (k Keeper) IncrementalInterestPayment(ctx sdk.Context, collateralAsset stri

interestPaymentTokenIn := sdk.NewCoin(ptypes.BaseCurrency, interestPayment)
// swap interest payment to custody asset for payment
interestPaymentCustody, err := k.EstimateSwap(ctx, interestPaymentTokenIn, mtp.CustodyAssets[custodyIndex], ammPool)
interestPaymentCustody, err := k.EstimateSwap(ctx, interestPaymentTokenIn, mtp.Custodies[custodyIndex].Denom, ammPool)
if err != nil {
return sdk.ZeroInt(), err
}
Expand All @@ -299,46 +299,46 @@ func (k Keeper) IncrementalInterestPayment(ctx sdk.Context, collateralAsset stri
mtp.InterestUnpaidCollaterals[collateralIndex] = sdk.ZeroInt()

// edge case, not enough custody to cover payment
if interestPaymentCustody.GT(mtp.CustodyAmounts[custodyIndex]) {
if interestPaymentCustody.GT(mtp.Custodies[custodyIndex].Amount) {
// swap custody amount to collateral for updating interest unpaid
custodyAmtTokenIn := sdk.NewCoin(mtp.CustodyAssets[custodyIndex], mtp.CustodyAmounts[custodyIndex])
custodyAmtTokenIn := sdk.NewCoin(mtp.Custodies[custodyIndex].Denom, mtp.Custodies[custodyIndex].Amount)
custodyAmountCollateral, err := k.EstimateSwap(ctx, custodyAmtTokenIn, collateralAsset, ammPool) // may need spot price here to not deduct fee
if err != nil {
return sdk.ZeroInt(), err
}
mtp.InterestUnpaidCollaterals[collateralIndex] = interestPayment.Sub(custodyAmountCollateral)

interestPayment = custodyAmountCollateral
interestPaymentCustody = mtp.CustodyAmounts[custodyIndex]
interestPaymentCustody = mtp.Custodies[custodyIndex].Amount
}

// add payment to total paid - collateral
mtp.InterestPaidCollaterals[collateralIndex] = mtp.InterestPaidCollaterals[collateralIndex].Add(interestPayment)

// add payment to total paid - custody
mtp.InterestPaidCustodys[custodyIndex] = mtp.InterestPaidCustodys[custodyIndex].Add(interestPaymentCustody)
mtp.InterestPaidCustodies[custodyIndex] = mtp.InterestPaidCustodies[custodyIndex].Add(interestPaymentCustody)

// deduct interest payment from custody amount
mtp.CustodyAmounts[custodyIndex] = mtp.CustodyAmounts[custodyIndex].Sub(interestPaymentCustody)
mtp.Custodies[custodyIndex].Amount = mtp.Custodies[custodyIndex].Amount.Sub(interestPaymentCustody)

takePercentage := k.GetIncrementalInterestPaymentFundPercentage(ctx)
fundAddr := k.GetIncrementalInterestPaymentFundAddress(ctx)
takeAmount, err := k.TakeFundPayment(ctx, interestPaymentCustody, mtp.CustodyAssets[custodyIndex], takePercentage, fundAddr, &ammPool)
takeAmount, err := k.TakeFundPayment(ctx, interestPaymentCustody, mtp.Custodies[custodyIndex].Denom, takePercentage, fundAddr, &ammPool)
if err != nil {
return sdk.ZeroInt(), err
}
actualInterestPaymentCustody := interestPaymentCustody.Sub(takeAmount)

if !takeAmount.IsZero() {
k.EmitFundPayment(ctx, mtp, takeAmount, mtp.CustodyAssets[custodyIndex], types.EventIncrementalPayFund)
k.EmitFundPayment(ctx, mtp, takeAmount, mtp.Custodies[custodyIndex].Denom, types.EventIncrementalPayFund)
}

err = pool.UpdateCustody(ctx, mtp.CustodyAssets[custodyIndex], interestPaymentCustody, false)
err = pool.UpdateCustody(ctx, mtp.Custodies[custodyIndex].Denom, interestPaymentCustody, false)
if err != nil {
return sdk.ZeroInt(), err
}

err = pool.UpdateBalance(ctx, mtp.CustodyAssets[custodyIndex], actualInterestPaymentCustody, true)
err = pool.UpdateBalance(ctx, mtp.Custodies[custodyIndex].Denom, actualInterestPaymentCustody, true)
if err != nil {
return sdk.ZeroInt(), err
}
Expand Down
8 changes: 3 additions & 5 deletions x/margin/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ func TestSetGetMTP(t *testing.T) {
for i := 0; i < 2; i++ {
mtp := types.MTP{
Address: addr[i].String(),
CollateralAssets: []string{paramtypes.BaseCurrency},
CollateralAmounts: []sdk.Int{sdk.NewInt(0)},
Collaterals: sdk.NewCoins(sdk.NewCoin(paramtypes.BaseCurrency, sdk.NewInt(0))),
Liabilities: sdk.NewInt(0),
InterestPaidCollaterals: []sdk.Int{sdk.NewInt(0)},
InterestPaidCustodys: []sdk.Int{sdk.NewInt(0)},
InterestPaidCustodies: []sdk.Int{sdk.NewInt(0)},
InterestUnpaidCollaterals: []sdk.Int{sdk.NewInt(0)},
CustodyAssets: []string{"ATOM"},
CustodyAmounts: []sdk.Int{sdk.NewInt(0)},
Custodies: sdk.NewCoins(sdk.NewCoin("ATOM", sdk.NewInt(0))),
Leverages: []sdk.Dec{sdk.NewDec(0)},
MtpHealth: sdk.NewDec(0),
Position: types.Position_LONG,
Expand Down
2 changes: 1 addition & 1 deletion x/margin/keeper/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (k Keeper) Open(ctx sdk.Context, msg *types.MsgOpen) (*types.MsgOpenRespons
k.OpenChecker.EmitOpenEvent(ctx, mtp)

if k.hooks != nil {
k.hooks.AfterMarginPositionOpended(ctx, ammPool, pool)
k.hooks.AfterMarginPositionOpen(ctx, ammPool, pool)
}

return &types.MsgOpenResponse{}, nil
Expand Down
5 changes: 5 additions & 0 deletions x/margin/keeper/open_consolidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func (k Keeper) OpenConsolidate(ctx sdk.Context, mtp *types.MTP, msg *types.MsgO
if err != nil {
return nil, err
}
case types.Position_SHORT:
mtp, err = k.OpenConsolidateShort(ctx, poolId, mtp, msg)
if err != nil {
return nil, err
}
default:
return nil, sdkerrors.Wrap(types.ErrInvalidPosition, msg.Position.String())
}
Expand Down
Loading

0 comments on commit 6999555

Please sign in to comment.