From 69995558d4b65547d0f430e396fa48c30a9adc8d Mon Sep 17 00:00:00 2001 From: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com> Date: Fri, 13 Oct 2023 09:24:02 +0200 Subject: [PATCH] refactor: remaining refactoring --- docs/static/openapi.yml | 411 +++++++++++++++------ proto/elys/margin/tx.proto | 2 - proto/elys/margin/types.proto | 10 - x/accountedpool/keeper/hooks_margin.go | 6 +- x/margin/keeper/close.go | 16 +- x/margin/keeper/close_short.go | 10 +- x/margin/keeper/estimate_and_repay.go | 4 +- x/margin/keeper/force_close_long.go | 9 +- x/margin/keeper/force_close_short.go | 9 +- x/margin/keeper/generate_open_event.go | 14 +- x/margin/keeper/handle_interest_payment.go | 2 +- x/margin/keeper/invariant_check.go | 4 +- x/margin/keeper/keeper.go | 36 +- x/margin/keeper/keeper_test.go | 8 +- x/margin/keeper/open.go | 2 +- x/margin/keeper/open_consolidate.go | 5 + x/margin/keeper/open_consolidate_long.go | 11 +- x/margin/keeper/open_consolidate_short.go | 19 + x/margin/keeper/open_short_process.go | 2 +- x/margin/keeper/repay.go | 4 +- x/margin/keeper/take_out_custody.go | 4 +- x/margin/keeper/update_mtp_health.go | 10 +- x/margin/types/add_or_append_coin.go | 14 + x/margin/types/add_or_append_coin_test.go | 51 +++ x/margin/types/hooks.go | 8 +- x/margin/types/tx.pb.go | 187 +++------- x/margin/types/types.go | 13 +- x/margin/types/types.pb.go | 28 +- 28 files changed, 519 insertions(+), 380 deletions(-) create mode 100644 x/margin/keeper/open_consolidate_short.go create mode 100644 x/margin/types/add_or_append_coin.go create mode 100644 x/margin/types/add_or_append_coin_test.go diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index 4404a52be..81268f228 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -40293,21 +40293,30 @@ paths: properties: address: type: string - collateral_assets: - type: array - items: - type: string - collateral_amounts: + collaterals: type: array items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the + custom method + + signatures required by gogoproto. liabilities: type: string interest_paid_collaterals: type: array items: type: string - interest_paid_custodys: + interest_paid_custodies: type: array items: type: string @@ -40315,14 +40324,23 @@ paths: type: array items: type: string - custody_assets: - type: array - items: - type: string - custody_amounts: + custodies: type: array items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the + custom method + + signatures required by gogoproto. leverages: type: array items: @@ -40393,21 +40411,31 @@ paths: properties: address: type: string - collateral_assets: + collaterals: type: array items: - type: string - collateral_amounts: - type: array - items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an + amount. + + + NOTE: The amount field is an Int which implements the + custom method + + signatures required by gogoproto. liabilities: type: string interest_paid_collaterals: type: array items: type: string - interest_paid_custodys: + interest_paid_custodies: type: array items: type: string @@ -40415,14 +40443,24 @@ paths: type: array items: type: string - custody_assets: - type: array - items: - type: string - custody_amounts: + custodies: type: array items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an + amount. + + + NOTE: The amount field is an Int which implements the + custom method + + signatures required by gogoproto. leverages: type: array items: @@ -40573,21 +40611,31 @@ paths: properties: address: type: string - collateral_assets: - type: array - items: - type: string - collateral_amounts: + collaterals: type: array items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an + amount. + + + NOTE: The amount field is an Int which implements the + custom method + + signatures required by gogoproto. liabilities: type: string interest_paid_collaterals: type: array items: type: string - interest_paid_custodys: + interest_paid_custodies: type: array items: type: string @@ -40595,14 +40643,24 @@ paths: type: array items: type: string - custody_assets: - type: array - items: - type: string - custody_amounts: + custodies: type: array items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an + amount. + + + NOTE: The amount field is an Int which implements the + custom method + + signatures required by gogoproto. leverages: type: array items: @@ -40851,6 +40909,9 @@ paths: type: string asset_denom: type: string + lastHeightInterestRateComputed: + type: string + format: int64 default: description: An unexpected error response. schema: @@ -40919,6 +40980,9 @@ paths: type: string asset_denom: type: string + lastHeightInterestRateComputed: + type: string + format: int64 pagination: type: object properties: @@ -41041,21 +41105,31 @@ paths: properties: address: type: string - collateral_assets: - type: array - items: - type: string - collateral_amounts: + collaterals: type: array items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an + amount. + + + NOTE: The amount field is an Int which implements the + custom method + + signatures required by gogoproto. liabilities: type: string interest_paid_collaterals: type: array items: type: string - interest_paid_custodys: + interest_paid_custodies: type: array items: type: string @@ -41063,14 +41137,24 @@ paths: type: array items: type: string - custody_assets: - type: array - items: - type: string - custody_amounts: + custodies: type: array items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an + amount. + + + NOTE: The amount field is an Int which implements the + custom method + + signatures required by gogoproto. leverages: type: array items: @@ -83706,21 +83790,27 @@ definitions: properties: address: type: string - collateral_assets: - type: array - items: - type: string - collateral_amounts: + collaterals: type: array items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: |- + Coin defines a token with a denomination and an amount. + + NOTE: The amount field is an Int which implements the custom method + signatures required by gogoproto. liabilities: type: string interest_paid_collaterals: type: array items: type: string - interest_paid_custodys: + interest_paid_custodies: type: array items: type: string @@ -83728,14 +83818,20 @@ definitions: type: array items: type: string - custody_assets: - type: array - items: - type: string - custody_amounts: + custodies: type: array items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: |- + Coin defines a token with a denomination and an amount. + + NOTE: The amount field is an Int which implements the custom method + signatures required by gogoproto. leverages: type: array items: @@ -83767,21 +83863,30 @@ definitions: properties: address: type: string - collateral_assets: - type: array - items: - type: string - collateral_amounts: + collaterals: type: array items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the custom + method + + signatures required by gogoproto. liabilities: type: string interest_paid_collaterals: type: array items: type: string - interest_paid_custodys: + interest_paid_custodies: type: array items: type: string @@ -83789,14 +83894,23 @@ definitions: type: array items: type: string - custody_assets: - type: array - items: - type: string - custody_amounts: + custodies: type: array items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the custom + method + + signatures required by gogoproto. leverages: type: array items: @@ -83955,6 +84069,9 @@ definitions: type: string asset_denom: type: string + lastHeightInterestRateComputed: + type: string + format: int64 elys.margin.PoolAsset: type: object properties: @@ -83987,21 +84104,30 @@ definitions: properties: address: type: string - collateral_assets: - type: array - items: - type: string - collateral_amounts: + collaterals: type: array items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the custom + method + + signatures required by gogoproto. liabilities: type: string interest_paid_collaterals: type: array items: type: string - interest_paid_custodys: + interest_paid_custodies: type: array items: type: string @@ -84009,14 +84135,23 @@ definitions: type: array items: type: string - custody_assets: + custodies: type: array items: - type: string - custody_amounts: - type: array - items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the custom + method + + signatures required by gogoproto. leverages: type: array items: @@ -84076,21 +84211,30 @@ definitions: properties: address: type: string - collateral_assets: - type: array - items: - type: string - collateral_amounts: + collaterals: type: array items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the custom + method + + signatures required by gogoproto. liabilities: type: string interest_paid_collaterals: type: array items: type: string - interest_paid_custodys: + interest_paid_custodies: type: array items: type: string @@ -84098,14 +84242,23 @@ definitions: type: array items: type: string - custody_assets: - type: array - items: - type: string - custody_amounts: + custodies: type: array items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the custom + method + + signatures required by gogoproto. leverages: type: array items: @@ -84165,21 +84318,30 @@ definitions: properties: address: type: string - collateral_assets: - type: array - items: - type: string - collateral_amounts: + collaterals: type: array items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the custom + method + + signatures required by gogoproto. liabilities: type: string interest_paid_collaterals: type: array items: type: string - interest_paid_custodys: + interest_paid_custodies: type: array items: type: string @@ -84187,14 +84349,23 @@ definitions: type: array items: type: string - custody_assets: + custodies: type: array items: - type: string - custody_amounts: - type: array - items: - type: string + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the custom + method + + signatures required by gogoproto. leverages: type: array items: @@ -84280,6 +84451,9 @@ definitions: type: string asset_denom: type: string + lastHeightInterestRateComputed: + type: string + format: int64 pagination: type: object properties: @@ -84340,6 +84514,9 @@ definitions: type: string asset_denom: type: string + lastHeightInterestRateComputed: + type: string + format: int64 elys.margin.StatusResponse: type: object properties: diff --git a/proto/elys/margin/tx.proto b/proto/elys/margin/tx.proto index b3231706d..f3fa2f4d8 100644 --- a/proto/elys/margin/tx.proto +++ b/proto/elys/margin/tx.proto @@ -31,8 +31,6 @@ message MsgOpenResponse {} message MsgClose { string creator = 1; uint64 id = 2; - string collateralAsset = 3; - string custodyAsset = 4; } message MsgCloseResponse {} diff --git a/proto/elys/margin/types.proto b/proto/elys/margin/types.proto index 6b7187afc..82ee0a6aa 100644 --- a/proto/elys/margin/types.proto +++ b/proto/elys/margin/types.proto @@ -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 @@ -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 diff --git a/x/accountedpool/keeper/hooks_margin.go b/x/accountedpool/keeper/hooks_margin.go index ba61058e3..9704c360b 100644 --- a/x/accountedpool/keeper/hooks_margin.go +++ b/x/accountedpool/keeper/hooks_margin.go @@ -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) } @@ -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) { diff --git a/x/margin/keeper/close.go b/x/margin/keeper/close.go index 5acc8aaea..5c2c0a887 100644 --- a/x/margin/keeper/close.go +++ b/x/margin/keeper/close.go @@ -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()), )) diff --git a/x/margin/keeper/close_short.go b/x/margin/keeper/close_short.go index 7dff7a26a..a9e87906e 100644 --- a/x/margin/keeper/close_short.go +++ b/x/margin/keeper/close_short.go @@ -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 @@ -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 { diff --git a/x/margin/keeper/estimate_and_repay.go b/x/margin/keeper/estimate_and_repay.go index 16ee4e795..ee0d57fe6 100644 --- a/x/margin/keeper/estimate_and_repay.go +++ b/x/margin/keeper/estimate_and_repay.go @@ -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 } diff --git a/x/margin/keeper/force_close_long.go b/x/margin/keeper/force_close_long.go index c6cb5b7be..50a714d53 100644 --- a/x/margin/keeper/force_close_long.go +++ b/x/margin/keeper/force_close_long.go @@ -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 @@ -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 { diff --git a/x/margin/keeper/force_close_short.go b/x/margin/keeper/force_close_short.go index 97dd2c6ee..1b0a13f02 100644 --- a/x/margin/keeper/force_close_short.go +++ b/x/margin/keeper/force_close_short.go @@ -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 @@ -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 { diff --git a/x/margin/keeper/generate_open_event.go b/x/margin/keeper/generate_open_event.go index 2bfb2c97a..5a3438eae 100644 --- a/x/margin/keeper/generate_open_event.go +++ b/x/margin/keeper/generate_open_event.go @@ -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()), ) diff --git a/x/margin/keeper/handle_interest_payment.go b/x/margin/keeper/handle_interest_payment.go index 89d7b8856..edfbda1e9 100644 --- a/x/margin/keeper/handle_interest_payment.go +++ b/x/margin/keeper/handle_interest_payment.go @@ -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 diff --git a/x/margin/keeper/invariant_check.go b/x/margin/keeper/invariant_check.go index 18fd96af7..d04020316 100644 --- a/x/margin/keeper/invariant_check.go +++ b/x/margin/keeper/invariant_check.go @@ -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)) } } diff --git a/x/margin/keeper/keeper.go b/x/margin/keeper/keeper.go index 9a173d525..d3f429f70 100644 --- a/x/margin/keeper/keeper.go +++ b/x/margin/keeper/keeper.go @@ -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 { @@ -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 } @@ -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 @@ -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 } @@ -299,9 +299,9 @@ 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 @@ -309,36 +309,36 @@ func (k Keeper) IncrementalInterestPayment(ctx sdk.Context, collateralAsset stri 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 } diff --git a/x/margin/keeper/keeper_test.go b/x/margin/keeper/keeper_test.go index 965645f2d..5d41592f9 100644 --- a/x/margin/keeper/keeper_test.go +++ b/x/margin/keeper/keeper_test.go @@ -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, diff --git a/x/margin/keeper/open.go b/x/margin/keeper/open.go index eb202afa7..8dcac3fe2 100644 --- a/x/margin/keeper/open.go +++ b/x/margin/keeper/open.go @@ -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 diff --git a/x/margin/keeper/open_consolidate.go b/x/margin/keeper/open_consolidate.go index caaed8616..0e7c3306f 100644 --- a/x/margin/keeper/open_consolidate.go +++ b/x/margin/keeper/open_consolidate.go @@ -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()) } diff --git a/x/margin/keeper/open_consolidate_long.go b/x/margin/keeper/open_consolidate_long.go index 1e692b7f3..ac67d4cfd 100644 --- a/x/margin/keeper/open_consolidate_long.go +++ b/x/margin/keeper/open_consolidate_long.go @@ -1,8 +1,6 @@ package keeper import ( - "golang.org/x/exp/slices" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/elys-network/elys/x/margin/types" ) @@ -14,13 +12,8 @@ func (k Keeper) OpenConsolidateLong(ctx sdk.Context, poolId uint64, mtp *types.M collateralAmountDec := sdk.NewDecFromBigInt(msg.CollateralAmount.BigInt()) mtp.Leverages = append(mtp.Leverages, leverage) - if !slices.Contains(mtp.CollateralAssets, msg.CollateralAsset) { - mtp.CollateralAssets = append(mtp.CollateralAssets, msg.CollateralAsset) - } - - if !slices.Contains(mtp.CustodyAssets, msg.BorrowAsset) { - mtp.CollateralAssets = append(mtp.CustodyAssets, msg.BorrowAsset) - } + mtp.Collaterals = types.AddOrAppendCoin(mtp.Collaterals, sdk.NewCoin(msg.CollateralAsset, sdk.NewInt(0))) + mtp.Custodies = types.AddOrAppendCoin(mtp.Custodies, sdk.NewCoin(msg.BorrowAsset, sdk.NewInt(0))) return k.ProcessOpenLong(ctx, mtp, leverage, eta, collateralAmountDec, poolId, msg) } diff --git a/x/margin/keeper/open_consolidate_short.go b/x/margin/keeper/open_consolidate_short.go new file mode 100644 index 000000000..115fa5546 --- /dev/null +++ b/x/margin/keeper/open_consolidate_short.go @@ -0,0 +1,19 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/elys-network/elys/x/margin/types" +) + +func (k Keeper) OpenConsolidateShort(ctx sdk.Context, poolId uint64, mtp *types.MTP, msg *types.MsgOpen) (*types.MTP, error) { + maxLeverage := k.OpenShortChecker.GetMaxLeverageParam(ctx) + leverage := sdk.MinDec(msg.Leverage, maxLeverage) + eta := leverage.Sub(sdk.OneDec()) + collateralAmountDec := sdk.NewDecFromBigInt(msg.CollateralAmount.BigInt()) + mtp.Leverages = append(mtp.Leverages, leverage) + + mtp.Collaterals = types.AddOrAppendCoin(mtp.Collaterals, sdk.NewCoin(msg.CollateralAsset, sdk.NewInt(0))) + mtp.Custodies = types.AddOrAppendCoin(mtp.Custodies, sdk.NewCoin(msg.BorrowAsset, sdk.NewInt(0))) + + return k.ProcessOpenShort(ctx, mtp, leverage, eta, collateralAmountDec, poolId, msg) +} diff --git a/x/margin/keeper/open_short_process.go b/x/margin/keeper/open_short_process.go index 5ce15fb65..7f201b4a1 100644 --- a/x/margin/keeper/open_short_process.go +++ b/x/margin/keeper/open_short_process.go @@ -67,7 +67,7 @@ func (k Keeper) ProcessOpenShort(ctx sdk.Context, mtp *types.MTP, leverage sdk.D // if position is short then override the custody asset to the base currency if mtp.Position == types.Position_SHORT { - mtp.CustodyAssets = []string{ptypes.BaseCurrency} + mtp.Custodies = sdk.NewCoins(sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(0))) } // Borrow the asset the user wants to short. diff --git a/x/margin/keeper/repay.go b/x/margin/keeper/repay.go index 4cd79ee58..a9dc2a21c 100644 --- a/x/margin/keeper/repay.go +++ b/x/margin/keeper/repay.go @@ -16,7 +16,7 @@ func (k Keeper) Repay(ctx sdk.Context, mtp *types.MTP, pool *types.Pool, ammPool if collateralAsset != ptypes.BaseCurrency { // swap to base currency - 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 err @@ -113,7 +113,7 @@ func (k Keeper) Repay(ctx sdk.Context, mtp *types.MTP, pool *types.Pool, ammPool returnAmount = C } - err = pool.UpdateBalance(ctx, mtp.CollateralAssets[collateralIndex], returnAmount, false) + err = pool.UpdateBalance(ctx, mtp.Collaterals[collateralIndex].Denom, returnAmount, false) if err != nil { return err } diff --git a/x/margin/keeper/take_out_custody.go b/x/margin/keeper/take_out_custody.go index 114d7cc0a..2e117a7cd 100644 --- a/x/margin/keeper/take_out_custody.go +++ b/x/margin/keeper/take_out_custody.go @@ -7,12 +7,12 @@ import ( func (k Keeper) TakeOutCustody(ctx sdk.Context, mtp types.MTP, pool *types.Pool, custodyAsset string) error { _, custodyIndex := k.GetMTPAssetIndex(&mtp, "", custodyAsset) - err := pool.UpdateBalance(ctx, mtp.CustodyAssets[custodyIndex], mtp.CustodyAmounts[custodyIndex], true) + err := pool.UpdateBalance(ctx, mtp.Custodies[custodyIndex].Denom, mtp.Custodies[custodyIndex].Amount, true) if err != nil { return err } - err = pool.UpdateCustody(ctx, mtp.CustodyAssets[custodyIndex], mtp.CustodyAmounts[custodyIndex], false) + err = pool.UpdateCustody(ctx, mtp.Custodies[custodyIndex].Denom, mtp.Custodies[custodyIndex].Amount, false) if err != nil { return err } diff --git a/x/margin/keeper/update_mtp_health.go b/x/margin/keeper/update_mtp_health.go index 8c4f5a240..d7ba83504 100644 --- a/x/margin/keeper/update_mtp_health.go +++ b/x/margin/keeper/update_mtp_health.go @@ -14,11 +14,11 @@ func (k Keeper) UpdateMTPHealth(ctx sdk.Context, mtp types.MTP, ammPool ammtypes return sdk.ZeroDec(), nil } // include unpaid interest in debt (from disabled incremental pay) - for i := range mtp.CollateralAssets { + for i := range mtp.Collaterals { if mtp.InterestUnpaidCollaterals[i].GT(sdk.ZeroInt()) { - unpaidCollaterals := sdk.NewCoin(mtp.CollateralAssets[i], mtp.InterestUnpaidCollaterals[i]) + unpaidCollaterals := sdk.NewCoin(mtp.Collaterals[i].Denom, mtp.InterestUnpaidCollaterals[i]) - if mtp.CollateralAssets[i] == ptypes.BaseCurrency { + if mtp.Collaterals[i].Denom == ptypes.BaseCurrency { xl = xl.Add(mtp.InterestUnpaidCollaterals[i]) } else { C, err := k.EstimateSwapGivenOut(ctx, unpaidCollaterals, ptypes.BaseCurrency, ammPool) @@ -32,8 +32,8 @@ func (k Keeper) UpdateMTPHealth(ctx sdk.Context, mtp types.MTP, ammPool ammtypes } custodyAmtInBaseCurrency := sdk.ZeroInt() - for i := range mtp.CustodyAssets { - custodyTokenIn := sdk.NewCoin(mtp.CustodyAssets[i], mtp.CustodyAmounts[i]) + for i := range mtp.Custodies { + custodyTokenIn := sdk.NewCoin(mtp.Custodies[i].Denom, mtp.Custodies[i].Amount) // All liabilty is in base currency C, err := k.EstimateSwapGivenOut(ctx, custodyTokenIn, ptypes.BaseCurrency, ammPool) if err != nil { diff --git a/x/margin/types/add_or_append_coin.go b/x/margin/types/add_or_append_coin.go new file mode 100644 index 000000000..bbd2cdebc --- /dev/null +++ b/x/margin/types/add_or_append_coin.go @@ -0,0 +1,14 @@ +package types + +import sdk "github.com/cosmos/cosmos-sdk/types" + +// Utility function to add a new coin or aggregate the amount if coin with same denom already exists +func AddOrAppendCoin(coins []sdk.Coin, coin sdk.Coin) []sdk.Coin { + for i, c := range coins { + if c.Denom == coin.Denom { + coins[i].Amount = c.Amount.Add(coin.Amount) + return coins + } + } + return append(coins, coin) +} diff --git a/x/margin/types/add_or_append_coin_test.go b/x/margin/types/add_or_append_coin_test.go new file mode 100644 index 000000000..06c3a7ade --- /dev/null +++ b/x/margin/types/add_or_append_coin_test.go @@ -0,0 +1,51 @@ +package types + +import ( + "reflect" + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func TestAddOrAppendCoin(t *testing.T) { + tests := []struct { + name string + coins sdk.Coins + newCoin sdk.Coin + expected sdk.Coins + }{ + { + name: "Append new coin", + coins: sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(100))), + newCoin: sdk.NewCoin("eth", sdk.NewInt(50)), + expected: sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(100)), sdk.NewCoin("eth", sdk.NewInt(50))), + }, + { + name: "Aggregate coin amount", + coins: sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(100))), + newCoin: sdk.NewCoin("atom", sdk.NewInt(50)), + expected: sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(150))), + }, + { + name: "Aggregate coin amount in larger slice", + coins: sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(100)), sdk.NewCoin("btc", sdk.NewInt(200)), sdk.NewCoin("eth", sdk.NewInt(300))), + newCoin: sdk.NewCoin("btc", sdk.NewInt(50)), + expected: sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(100)), sdk.NewCoin("btc", sdk.NewInt(250)), sdk.NewCoin("eth", sdk.NewInt(300))), + }, + { + name: "Append new coin to empty slice", + coins: sdk.NewCoins(), + newCoin: sdk.NewCoin("eth", sdk.NewInt(50)), + expected: sdk.NewCoins(sdk.NewCoin("eth", sdk.NewInt(50))), + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := AddOrAppendCoin(tt.coins, tt.newCoin) + if !reflect.DeepEqual(sdk.NewCoins(got...), tt.expected) { + t.Errorf("AddOrAppendCoin() = %v, expected %v", got, tt.expected) + } + }) + } +} diff --git a/x/margin/types/hooks.go b/x/margin/types/hooks.go index adde87679..e6141ce7b 100644 --- a/x/margin/types/hooks.go +++ b/x/margin/types/hooks.go @@ -6,8 +6,8 @@ import ( ) type MarginHooks interface { - // AfterMarginPositionOpended is called after OpenLong or OpenShort position. - AfterMarginPositionOpended(ctx sdk.Context, ammPool ammtypes.Pool, marginPool Pool) + // AfterMarginPositionOpen is called after OpenLong or OpenShort position. + AfterMarginPositionOpen(ctx sdk.Context, ammPool ammtypes.Pool, marginPool Pool) // AfterMarginPositionModified is called after a position gets modified. AfterMarginPositionModified(ctx sdk.Context, ammPool ammtypes.Pool, marginPool Pool) @@ -38,9 +38,9 @@ func NewMultiMarginHooks(hooks ...MarginHooks) MultiMarginHooks { return hooks } -func (h MultiMarginHooks) AfterMarginPositionOpended(ctx sdk.Context, ammPool ammtypes.Pool, marginPool Pool) { +func (h MultiMarginHooks) AfterMarginPositionOpen(ctx sdk.Context, ammPool ammtypes.Pool, marginPool Pool) { for i := range h { - h[i].AfterMarginPositionOpended(ctx, ammPool, marginPool) + h[i].AfterMarginPositionOpen(ctx, ammPool, marginPool) } } diff --git a/x/margin/types/tx.pb.go b/x/margin/types/tx.pb.go index 78d718482..f72af3428 100644 --- a/x/margin/types/tx.pb.go +++ b/x/margin/types/tx.pb.go @@ -136,10 +136,8 @@ func (m *MsgOpenResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgOpenResponse proto.InternalMessageInfo type MsgClose struct { - Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` - Id uint64 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"` - CollateralAsset string `protobuf:"bytes,3,opt,name=collateralAsset,proto3" json:"collateralAsset,omitempty"` - CustodyAsset string `protobuf:"bytes,4,opt,name=custodyAsset,proto3" json:"custodyAsset,omitempty"` + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + Id uint64 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"` } func (m *MsgClose) Reset() { *m = MsgClose{} } @@ -189,20 +187,6 @@ func (m *MsgClose) GetId() uint64 { return 0 } -func (m *MsgClose) GetCollateralAsset() string { - if m != nil { - return m.CollateralAsset - } - return "" -} - -func (m *MsgClose) GetCustodyAsset() string { - if m != nil { - return m.CustodyAsset - } - return "" -} - type MsgCloseResponse struct { } @@ -619,47 +603,46 @@ func init() { func init() { proto.RegisterFile("elys/margin/tx.proto", fileDescriptor_01b9dbed35cc5a15) } var fileDescriptor_01b9dbed35cc5a15 = []byte{ - // 631 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0xcd, 0x4e, 0xdb, 0x4c, - 0x14, 0x8d, 0x63, 0xfe, 0x72, 0x83, 0x80, 0x6f, 0xbe, 0x00, 0xc6, 0xa5, 0x26, 0x75, 0xab, 0x2a, - 0x12, 0xc2, 0x51, 0xe9, 0xae, 0x52, 0x17, 0x50, 0xba, 0xa0, 0x52, 0x04, 0xb2, 0x54, 0x55, 0x42, - 0x55, 0x25, 0x63, 0x4f, 0x8d, 0x85, 0xe3, 0xb1, 0x66, 0x26, 0x0d, 0xd9, 0xf6, 0x09, 0xfa, 0x4a, - 0xdd, 0xa1, 0xae, 0x58, 0x56, 0x5d, 0xa0, 0x8a, 0xbc, 0x48, 0xe5, 0xb1, 0xe3, 0x8c, 0x13, 0x13, - 0xd4, 0x45, 0x57, 0xc9, 0x9c, 0x73, 0xe7, 0xdc, 0x33, 0x77, 0x8e, 0x07, 0x1a, 0x38, 0x1c, 0xb0, - 0x76, 0xd7, 0xa1, 0x7e, 0x10, 0xb5, 0xf9, 0x95, 0x15, 0x53, 0xc2, 0x09, 0xaa, 0x27, 0xa8, 0x95, - 0xa2, 0x7a, 0xc3, 0x27, 0x3e, 0x11, 0x78, 0x3b, 0xf9, 0x97, 0x96, 0xe8, 0x9a, 0xbc, 0x31, 0x76, - 0xa8, 0xd3, 0x65, 0x19, 0xb3, 0x59, 0x90, 0x1c, 0xc4, 0x38, 0x23, 0xcc, 0x1f, 0x55, 0x58, 0xec, - 0x30, 0xff, 0x24, 0xc6, 0x11, 0xd2, 0x60, 0xd1, 0xa5, 0xd8, 0xe1, 0x84, 0x6a, 0x4a, 0x53, 0x69, - 0xd5, 0xec, 0xd1, 0x12, 0xb5, 0x60, 0xd5, 0x25, 0x61, 0xe8, 0x70, 0x4c, 0x9d, 0xf0, 0x80, 0x31, - 0xcc, 0xb5, 0xaa, 0xa8, 0x98, 0x84, 0xd1, 0x19, 0xac, 0x49, 0x50, 0x97, 0xf4, 0x22, 0xae, 0xa9, - 0x49, 0xe9, 0xa1, 0x75, 0x7d, 0xbb, 0x53, 0xf9, 0x75, 0xbb, 0xf3, 0xdc, 0x0f, 0xf8, 0x45, 0xef, - 0xdc, 0x72, 0x49, 0xb7, 0xed, 0x12, 0xd6, 0x25, 0x2c, 0xfb, 0xd9, 0x63, 0xde, 0x65, 0xe6, 0xed, - 0x38, 0xe2, 0xf6, 0x94, 0x0e, 0x6a, 0x42, 0xfd, 0x9c, 0x50, 0x4a, 0xfa, 0xa9, 0x83, 0x39, 0xe1, - 0x40, 0x86, 0xd0, 0x0b, 0x58, 0x8a, 0x09, 0x0b, 0x78, 0x40, 0x22, 0x6d, 0xbe, 0xa9, 0xb4, 0x56, - 0xf6, 0xd7, 0x2d, 0x69, 0x6c, 0xd6, 0x69, 0x46, 0xda, 0x79, 0x19, 0x7a, 0x07, 0x4b, 0x21, 0xfe, - 0x82, 0xa9, 0xe3, 0x63, 0x6d, 0xe1, 0xaf, 0x8d, 0x1e, 0x61, 0xd7, 0xce, 0xf7, 0x9b, 0xff, 0xc1, - 0x6a, 0x36, 0x4b, 0x1b, 0xb3, 0x98, 0x44, 0x0c, 0x9b, 0x5f, 0x15, 0x58, 0xea, 0x30, 0xff, 0x4d, - 0x48, 0x18, 0x9e, 0x31, 0xe0, 0x15, 0xa8, 0x06, 0x9e, 0x98, 0xe9, 0x9c, 0x5d, 0x0d, 0xbc, 0xb2, - 0x81, 0xab, 0xe5, 0x03, 0x37, 0x61, 0xd9, 0xed, 0x31, 0x4e, 0xbc, 0x81, 0x3c, 0x95, 0x02, 0x66, - 0x22, 0x58, 0x1b, 0x79, 0xc8, 0x8d, 0x7d, 0x14, 0x5e, 0xdf, 0xc7, 0x9e, 0xc3, 0xf1, 0xa9, 0x88, - 0x0a, 0xda, 0x86, 0x9a, 0xd3, 0xe3, 0x17, 0x84, 0x06, 0x7c, 0x90, 0x19, 0x1c, 0x03, 0x68, 0x17, - 0x16, 0xd2, 0x48, 0x09, 0x9b, 0xf5, 0xfd, 0xff, 0x8b, 0x93, 0x15, 0x94, 0x9d, 0x95, 0x98, 0x5b, - 0xb0, 0x39, 0xa1, 0x9e, 0x37, 0xfe, 0x0c, 0x2b, 0x63, 0x8a, 0x90, 0xf0, 0xa1, 0xbe, 0x0d, 0x98, - 0x8f, 0x93, 0x32, 0xad, 0xda, 0x54, 0x5b, 0x35, 0x3b, 0x5d, 0x24, 0x59, 0x70, 0x93, 0xf3, 0x78, - 0x42, 0x42, 0x53, 0x05, 0x27, 0x43, 0xa6, 0x06, 0x1b, 0xc5, 0x3e, 0xd2, 0xd1, 0x97, 0x3b, 0xcc, - 0xff, 0x70, 0x11, 0x70, 0x1c, 0x06, 0x8c, 0x3f, 0xd0, 0xdf, 0x02, 0xd4, 0x1f, 0x95, 0x62, 0xef, - 0xc0, 0xf3, 0x28, 0x66, 0x2c, 0x8b, 0x7f, 0x09, 0x63, 0x6e, 0x40, 0x43, 0x56, 0xcf, 0xbb, 0x7e, - 0x12, 0xe7, 0x3e, 0xc2, 0xfd, 0x7f, 0xd4, 0x37, 0x3d, 0xaf, 0xa4, 0x3f, 0xea, 0xbc, 0xff, 0x5d, - 0x05, 0xb5, 0xc3, 0x7c, 0xf4, 0x0a, 0xe6, 0xc4, 0x77, 0xde, 0x28, 0xdc, 0x5c, 0x96, 0x58, 0x7d, - 0xbb, 0x0c, 0x1d, 0x69, 0xa0, 0xd7, 0x30, 0x9f, 0x66, 0x78, 0x7d, 0xb2, 0x4c, 0xc0, 0xfa, 0xe3, - 0x52, 0x38, 0xdf, 0x6e, 0xc3, 0x72, 0x31, 0x6a, 0x93, 0xe5, 0x32, 0xab, 0x3f, 0x9b, 0xc5, 0xe6, - 0x9a, 0x27, 0x50, 0x97, 0x53, 0xf4, 0xe8, 0x9e, 0x4d, 0x09, 0xa9, 0x3f, 0x9d, 0x41, 0xe6, 0x82, - 0xc7, 0x50, 0x1b, 0x87, 0x62, 0x6b, 0x72, 0x47, 0x4e, 0xe9, 0x4f, 0xee, 0xa5, 0x64, 0x6f, 0xf2, - 0x4d, 0x4f, 0x79, 0x93, 0xc8, 0x69, 0x6f, 0x25, 0x77, 0x78, 0xf8, 0xf6, 0xfa, 0xce, 0x50, 0x6e, - 0xee, 0x0c, 0xe5, 0xf7, 0x9d, 0xa1, 0x7c, 0x1b, 0x1a, 0x95, 0x9b, 0xa1, 0x51, 0xf9, 0x39, 0x34, - 0x2a, 0x67, 0xbb, 0xd2, 0x33, 0x95, 0x08, 0xed, 0x45, 0x98, 0xf7, 0x09, 0xbd, 0x14, 0x8b, 0xf6, - 0x55, 0xe1, 0xd1, 0x3f, 0x5f, 0x10, 0xaf, 0xfe, 0xcb, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x88, - 0x9c, 0xb6, 0xab, 0x63, 0x06, 0x00, 0x00, + // 611 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x4f, 0x6b, 0xdb, 0x4e, + 0x10, 0xb5, 0xec, 0xfc, 0xf3, 0x38, 0x24, 0xf9, 0xed, 0xcf, 0x49, 0x14, 0x35, 0x55, 0x5c, 0xb5, + 0x14, 0x43, 0x88, 0x4c, 0xdd, 0x9e, 0x0a, 0x3d, 0x24, 0x4d, 0x0f, 0x29, 0x98, 0x04, 0x41, 0x29, + 0x84, 0x52, 0x90, 0xa5, 0xad, 0x2c, 0x22, 0x6b, 0xc5, 0xee, 0xba, 0x8e, 0xbf, 0x45, 0xbf, 0x52, + 0x6f, 0xa1, 0xa7, 0x1c, 0x4b, 0x0f, 0xa1, 0xd8, 0x5f, 0xa4, 0x68, 0x25, 0xcb, 0x2b, 0xdb, 0x71, + 0xe8, 0xa1, 0x27, 0x7b, 0xdf, 0x7b, 0xf3, 0x66, 0x76, 0x66, 0xb4, 0x50, 0xc5, 0xc1, 0x80, 0x35, + 0xba, 0x36, 0xf5, 0xfc, 0xb0, 0xc1, 0xaf, 0xcd, 0x88, 0x12, 0x4e, 0x50, 0x25, 0x46, 0xcd, 0x04, + 0xd5, 0xaa, 0x1e, 0xf1, 0x88, 0xc0, 0x1b, 0xf1, 0xbf, 0x44, 0xa2, 0xa9, 0x72, 0x60, 0x64, 0x53, + 0xbb, 0xcb, 0x52, 0x66, 0x37, 0x67, 0x39, 0x88, 0x70, 0x4a, 0x18, 0x3f, 0x8a, 0xb0, 0xda, 0x62, + 0xde, 0x79, 0x84, 0x43, 0xa4, 0xc2, 0xaa, 0x43, 0xb1, 0xcd, 0x09, 0x55, 0x95, 0x9a, 0x52, 0x2f, + 0x5b, 0xe3, 0x23, 0xaa, 0xc3, 0xa6, 0x43, 0x82, 0xc0, 0xe6, 0x98, 0xda, 0xc1, 0x31, 0x63, 0x98, + 0xab, 0x45, 0xa1, 0x98, 0x86, 0xd1, 0x25, 0x6c, 0x49, 0x50, 0x97, 0xf4, 0x42, 0xae, 0x96, 0x62, + 0xe9, 0x89, 0x79, 0x73, 0x77, 0x50, 0xf8, 0x75, 0x77, 0xf0, 0xdc, 0xf3, 0x79, 0xa7, 0xd7, 0x36, + 0x1d, 0xd2, 0x6d, 0x38, 0x84, 0x75, 0x09, 0x4b, 0x7f, 0x8e, 0x98, 0x7b, 0x95, 0xd6, 0x76, 0x16, + 0x72, 0x6b, 0xc6, 0x07, 0xd5, 0xa0, 0xd2, 0x26, 0x94, 0x92, 0x7e, 0x52, 0xc1, 0x92, 0xa8, 0x40, + 0x86, 0xd0, 0x0b, 0x58, 0x8b, 0x08, 0xf3, 0xb9, 0x4f, 0x42, 0x75, 0xb9, 0xa6, 0xd4, 0x37, 0x9a, + 0xdb, 0xa6, 0xd4, 0x36, 0xf3, 0x22, 0x25, 0xad, 0x4c, 0x86, 0xde, 0xc3, 0x5a, 0x80, 0xbf, 0x62, + 0x6a, 0x7b, 0x58, 0x5d, 0xf9, 0xeb, 0x42, 0x4f, 0xb1, 0x63, 0x65, 0xf1, 0xc6, 0x7f, 0xb0, 0x99, + 0xf6, 0xd2, 0xc2, 0x2c, 0x22, 0x21, 0xc3, 0xc6, 0x2b, 0x58, 0x6b, 0x31, 0xef, 0x6d, 0x40, 0x18, + 0x5e, 0xd0, 0xdf, 0x0d, 0x28, 0xfa, 0xae, 0x68, 0xe9, 0x92, 0x55, 0xf4, 0x5d, 0x03, 0xc1, 0xd6, + 0x38, 0x2a, 0x73, 0xfa, 0x24, 0xcc, 0x3f, 0x44, 0xae, 0xcd, 0xf1, 0x85, 0x98, 0x2d, 0xda, 0x87, + 0xb2, 0xdd, 0xe3, 0x1d, 0x42, 0x7d, 0x3e, 0x48, 0x2d, 0x27, 0x00, 0x3a, 0x84, 0x95, 0x64, 0x07, + 0x84, 0x71, 0xa5, 0xf9, 0x7f, 0xbe, 0x15, 0x82, 0xb2, 0x52, 0x89, 0xb1, 0x07, 0xbb, 0x53, 0xee, + 0x59, 0xe2, 0x2f, 0xb0, 0x31, 0xa1, 0x08, 0x09, 0x1e, 0xca, 0x5b, 0x85, 0xe5, 0x28, 0x96, 0xa9, + 0xc5, 0x5a, 0xa9, 0x5e, 0xb6, 0x92, 0x43, 0x3c, 0x3c, 0x27, 0xbe, 0x8f, 0x2b, 0x2c, 0xd4, 0x92, + 0xe0, 0x64, 0xc8, 0x50, 0x61, 0x27, 0x9f, 0x47, 0xba, 0xfa, 0x7a, 0x8b, 0x79, 0x1f, 0x3b, 0x3e, + 0xc7, 0x81, 0xcf, 0xf8, 0x03, 0xf9, 0x4d, 0x40, 0xfd, 0xb1, 0x14, 0xbb, 0xc7, 0xae, 0x4b, 0x31, + 0x63, 0xe9, 0xbe, 0xce, 0x61, 0x8c, 0x1d, 0xa8, 0xca, 0xee, 0x59, 0xd6, 0xcf, 0xe2, 0xde, 0xa7, + 0xb8, 0xff, 0x8f, 0xf2, 0x26, 0xf7, 0x95, 0xfc, 0xc7, 0x99, 0x9b, 0xdf, 0x4b, 0x50, 0x6a, 0x31, + 0x0f, 0xbd, 0x86, 0x25, 0xf1, 0x61, 0x56, 0x73, 0x93, 0x4b, 0x57, 0x4c, 0xdb, 0x9f, 0x87, 0x8e, + 0x3d, 0xd0, 0x1b, 0x58, 0x4e, 0xb6, 0x6e, 0x7b, 0x5a, 0x26, 0x60, 0xed, 0xf1, 0x5c, 0x38, 0x0b, + 0xb7, 0x60, 0x3d, 0xbf, 0x6a, 0xd3, 0x72, 0x99, 0xd5, 0x9e, 0x2d, 0x62, 0x33, 0xcf, 0x73, 0xa8, + 0xc8, 0x5b, 0xf4, 0xe8, 0x9e, 0xa0, 0x98, 0xd4, 0x9e, 0x2e, 0x20, 0x33, 0xc3, 0x33, 0x28, 0x4f, + 0x96, 0x62, 0x6f, 0x3a, 0x22, 0xa3, 0xb4, 0x27, 0xf7, 0x52, 0x72, 0x6d, 0xf2, 0xa4, 0x67, 0x6a, + 0x93, 0xc8, 0xd9, 0xda, 0xe6, 0xcc, 0xf0, 0xe4, 0xdd, 0xcd, 0x50, 0x57, 0x6e, 0x87, 0xba, 0xf2, + 0x7b, 0xa8, 0x2b, 0xdf, 0x46, 0x7a, 0xe1, 0x76, 0xa4, 0x17, 0x7e, 0x8e, 0xf4, 0xc2, 0xe5, 0xa1, + 0xf4, 0xae, 0xc4, 0x46, 0x47, 0x21, 0xe6, 0x7d, 0x42, 0xaf, 0xc4, 0xa1, 0x71, 0x9d, 0x7b, 0xa5, + 0xdb, 0x2b, 0xe2, 0x99, 0x7e, 0xf9, 0x27, 0x00, 0x00, 0xff, 0xff, 0x7f, 0xf5, 0x77, 0xa2, 0x14, + 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1034,20 +1017,6 @@ func (m *MsgClose) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.CustodyAsset) > 0 { - i -= len(m.CustodyAsset) - copy(dAtA[i:], m.CustodyAsset) - i = encodeVarintTx(dAtA, i, uint64(len(m.CustodyAsset))) - i-- - dAtA[i] = 0x22 - } - if len(m.CollateralAsset) > 0 { - i -= len(m.CollateralAsset) - copy(dAtA[i:], m.CollateralAsset) - i = encodeVarintTx(dAtA, i, uint64(len(m.CollateralAsset))) - i-- - dAtA[i] = 0x1a - } if m.Id != 0 { i = encodeVarintTx(dAtA, i, uint64(m.Id)) i-- @@ -1403,14 +1372,6 @@ func (m *MsgClose) Size() (n int) { if m.Id != 0 { n += 1 + sovTx(uint64(m.Id)) } - l = len(m.CollateralAsset) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - l = len(m.CustodyAsset) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } return n } @@ -1904,70 +1865,6 @@ func (m *MsgClose) Unmarshal(dAtA []byte) error { break } } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CollateralAsset", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.CollateralAsset = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CustodyAsset", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.CustodyAsset = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) diff --git a/x/margin/types/types.go b/x/margin/types/types.go index dea8236a2..855ecae1c 100644 --- a/x/margin/types/types.go +++ b/x/margin/types/types.go @@ -20,14 +20,12 @@ func GetPositionFromString(s string) Position { func NewMTP(signer string, collateralAsset string, borrowAsset string, position Position, leverage sdk.Dec, poolId uint64) *MTP { return &MTP{ Address: signer, - CollateralAssets: []string{collateralAsset}, - CollateralAmounts: []sdk.Int{sdk.ZeroInt()}, + Collaterals: sdk.NewCoins(sdk.NewCoin(collateralAsset, sdk.ZeroInt())), Liabilities: sdk.ZeroInt(), InterestPaidCollaterals: []sdk.Int{sdk.ZeroInt()}, - InterestPaidCustodys: []sdk.Int{sdk.ZeroInt()}, + InterestPaidCustodies: []sdk.Int{sdk.ZeroInt()}, InterestUnpaidCollaterals: []sdk.Int{sdk.ZeroInt()}, - CustodyAssets: []string{borrowAsset}, - CustodyAmounts: []sdk.Int{sdk.ZeroInt()}, + Custodies: sdk.NewCoins(sdk.NewCoin(borrowAsset, sdk.ZeroInt())), Leverages: []sdk.Dec{leverage}, MtpHealth: sdk.ZeroDec(), Position: position, @@ -38,10 +36,11 @@ func NewMTP(signer string, collateralAsset string, borrowAsset string, position } func (mtp MTP) Validate() error { - if len(mtp.CollateralAssets) < 1 { + if len(mtp.Collaterals) < 1 { return sdkerrors.Wrap(ErrMTPInvalid, "no asset specified") } - for _, asset := range mtp.CollateralAssets { + for _, collateral := range mtp.Collaterals { + asset := collateral.Denom if asset == "" { return sdkerrors.Wrap(ErrMTPInvalid, "no asset specified") } diff --git a/x/margin/types/types.pb.go b/x/margin/types/types.pb.go index 4cbf7d061..ef3d1a835 100644 --- a/x/margin/types/types.pb.go +++ b/x/margin/types/types.pb.go @@ -54,30 +54,20 @@ func (Position) EnumDescriptor() ([]byte, []int) { } type MTP struct { - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - Collaterals []types.Coin `protobuf:"bytes,2,rep,name=collaterals,proto3" json:"collaterals"` - // repeated string collateral_assets = 2; - // repeated string collateral_amounts = 3 [ - // (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", - // (gogoproto.nullable) = false - // ]; + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + Collaterals []types.Coin `protobuf:"bytes,2,rep,name=collaterals,proto3" json:"collaterals"` Liabilities github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,opt,name=liabilities,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"liabilities"` InterestPaidCollaterals []github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,rep,name=interest_paid_collaterals,json=interestPaidCollaterals,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"interest_paid_collaterals"` InterestPaidCustodies []github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,5,rep,name=interest_paid_custodies,json=interestPaidCustodies,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"interest_paid_custodies"` InterestUnpaidCollaterals []github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,6,rep,name=interest_unpaid_collaterals,json=interestUnpaidCollaterals,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"interest_unpaid_collaterals"` Custodies []types.Coin `protobuf:"bytes,7,rep,name=custodies,proto3" json:"custodies"` - // repeated string custody_assets = 8; - // repeated string custody_amounts = 9 [ - // (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", - // (gogoproto.nullable) = false - // ]; - Leverages []github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,8,rep,name=leverages,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"leverages"` - MtpHealth github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,9,opt,name=mtp_health,json=mtpHealth,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"mtp_health"` - Position Position `protobuf:"varint,10,opt,name=position,proto3,enum=elys.margin.Position" json:"position,omitempty"` - Id uint64 `protobuf:"varint,11,opt,name=id,proto3" json:"id,omitempty"` - AmmPoolId uint64 `protobuf:"varint,12,opt,name=amm_pool_id,json=ammPoolId,proto3" json:"amm_pool_id,omitempty"` - ConsolidateLeverage github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,13,opt,name=consolidate_leverage,json=consolidateLeverage,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"consolidate_leverage"` - SumCollateral github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,14,opt,name=sum_collateral,json=sumCollateral,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"sum_collateral"` + Leverages []github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,8,rep,name=leverages,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"leverages"` + MtpHealth github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,9,opt,name=mtp_health,json=mtpHealth,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"mtp_health"` + Position Position `protobuf:"varint,10,opt,name=position,proto3,enum=elys.margin.Position" json:"position,omitempty"` + Id uint64 `protobuf:"varint,11,opt,name=id,proto3" json:"id,omitempty"` + AmmPoolId uint64 `protobuf:"varint,12,opt,name=amm_pool_id,json=ammPoolId,proto3" json:"amm_pool_id,omitempty"` + ConsolidateLeverage github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,13,opt,name=consolidate_leverage,json=consolidateLeverage,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"consolidate_leverage"` + SumCollateral github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,14,opt,name=sum_collateral,json=sumCollateral,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"sum_collateral"` } func (m *MTP) Reset() { *m = MTP{} }