diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index 4404a52be..1733bc3da 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -40293,36 +40293,93 @@ 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: + 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. + interest_paid_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. interest_unpaid_collaterals: type: array items: - type: string - custody_assets: - type: array - items: - type: string - custody_amounts: + 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. + 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,36 +40450,98 @@ 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: + 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. + interest_paid_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. interest_unpaid_collaterals: type: array items: - type: string - custody_assets: - type: array - items: - type: string - custody_amounts: + 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. + 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,36 +40692,98 @@ 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: + 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. + interest_paid_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. interest_unpaid_collaterals: type: array items: - type: string - custody_assets: - type: array - items: - type: string - custody_amounts: + 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. + 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 +41032,9 @@ paths: type: string asset_denom: type: string + lastHeightInterestRateComputed: + type: string + format: int64 default: description: An unexpected error response. schema: @@ -40919,6 +41103,9 @@ paths: type: string asset_denom: type: string + lastHeightInterestRateComputed: + type: string + format: int64 pagination: type: object properties: @@ -41041,36 +41228,98 @@ 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: + 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. + interest_paid_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. interest_unpaid_collaterals: type: array items: - type: string - custody_assets: - type: array - items: - type: string - custody_amounts: + 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. + 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,36 +83955,78 @@ 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: + 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. + interest_paid_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. interest_unpaid_collaterals: type: array items: - type: string - custody_assets: - type: array - items: - type: string - custody_amounts: + 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. + 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,36 +84058,93 @@ 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: + 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. + interest_paid_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. interest_unpaid_collaterals: type: array items: - type: string - custody_assets: - type: array - items: - type: string - custody_amounts: + 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. + 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 +84303,9 @@ definitions: type: string asset_denom: type: string + lastHeightInterestRateComputed: + type: string + format: int64 elys.margin.PoolAsset: type: object properties: @@ -83987,36 +84338,93 @@ definitions: 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: + 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. + interest_paid_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. interest_unpaid_collaterals: type: array items: - type: string - custody_assets: - type: array - items: - type: string - custody_amounts: + 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. + 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: @@ -84076,36 +84484,93 @@ 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: + 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. + interest_paid_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. interest_unpaid_collaterals: type: array items: - type: string - custody_assets: - type: array - items: - type: string - custody_amounts: + 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. + 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,36 +84630,93 @@ 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: + 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. + interest_paid_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. interest_unpaid_collaterals: type: array items: - type: string - custody_assets: - type: array - items: - type: string - custody_amounts: + 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. + 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: @@ -84280,6 +84802,9 @@ definitions: type: string asset_denom: type: string + lastHeightInterestRateComputed: + type: string + format: int64 pagination: type: object properties: @@ -84340,6 +84865,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 a92c899f8..8a9976ea5 100644 --- a/proto/elys/margin/types.proto +++ b/proto/elys/margin/types.proto @@ -5,6 +5,7 @@ package elys.margin; option go_package = "github.com/elys-network/elys/x/margin/types"; import "gogoproto/gogo.proto"; +import "cosmos/base/v1beta1/coin.proto"; enum Position { UNSPECIFIED = 0; @@ -14,48 +15,41 @@ enum Position { message MTP { string address = 1; - repeated string collateral_assets = 2; - repeated string collateral_amounts = 3 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + repeated cosmos.base.v1beta1.Coin collaterals = 2 [ (gogoproto.nullable) = false ]; - string liabilities = 4 [ + string liabilities = 3 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false ]; - repeated string interest_paid_collaterals = 5 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + repeated cosmos.base.v1beta1.Coin interest_paid_collaterals = 4 [ (gogoproto.nullable) = false ]; - repeated string interest_paid_custodys = 6 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + repeated cosmos.base.v1beta1.Coin interest_paid_custodies = 5 [ (gogoproto.nullable) = false ]; - repeated string interest_unpaid_collaterals = 7 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + repeated cosmos.base.v1beta1.Coin interest_unpaid_collaterals = 6 [ (gogoproto.nullable) = false ]; - repeated string custody_assets = 8; - repeated string custody_amounts = 9 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + repeated cosmos.base.v1beta1.Coin custodies = 7 [ (gogoproto.nullable) = false ]; - repeated string leverages = 10 [ + repeated string leverages = 8 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false ]; - string mtp_health = 11 [ + string mtp_health = 9 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false ]; - Position position = 12; - uint64 id = 13; - uint64 amm_pool_id = 14; - string consolidate_leverage = 15 [ + Position position = 10; + uint64 id = 11; + uint64 amm_pool_id = 12; + string consolidate_leverage = 13 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false ]; - string sum_collateral = 16 [ + string sum_collateral = 14 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (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/client/cli/query_mtp_test.go b/x/margin/client/cli/query_mtp_test.go index 89a25525d..db2d4c786 100644 --- a/x/margin/client/cli/query_mtp_test.go +++ b/x/margin/client/cli/query_mtp_test.go @@ -37,14 +37,12 @@ func networkWithMTPObjects(t *testing.T, n int) (*network.Network, []*types.MTP) for i := 0; i < n; i++ { mtp := types.MTP{ Address: addr[i].String(), - CollateralAssets: []string{paramtypes.BaseCurrency}, - CollateralAmounts: []sdk.Int{sdk.NewInt(0)}, + Collaterals: []sdk.Coin{sdk.NewCoin(paramtypes.BaseCurrency, sdk.NewInt(0))}, Liabilities: sdk.NewInt(0), - InterestPaidCollaterals: []sdk.Int{sdk.NewInt(0)}, - InterestPaidCustodys: []sdk.Int{sdk.NewInt(0)}, - InterestUnpaidCollaterals: []sdk.Int{sdk.NewInt(0)}, - CustodyAssets: []string{"ATOM"}, - CustodyAmounts: []sdk.Int{sdk.NewInt(0)}, + InterestPaidCollaterals: []sdk.Coin{sdk.NewCoin(paramtypes.BaseCurrency, sdk.NewInt(0))}, + InterestPaidCustodies: []sdk.Coin{sdk.NewCoin("ATOM", sdk.NewInt(0))}, + InterestUnpaidCollaterals: []sdk.Coin{sdk.NewCoin(paramtypes.BaseCurrency, sdk.NewInt(0))}, + Custodies: []sdk.Coin{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/begin_blocker_process_mtp.go b/x/margin/keeper/begin_blocker_process_mtp.go index ed211480c..db9f37d37 100644 --- a/x/margin/keeper/begin_blocker_process_mtp.go +++ b/x/margin/keeper/begin_blocker_process_mtp.go @@ -27,7 +27,8 @@ func BeginBlockerProcessMTP(ctx sdk.Context, k Keeper, mtp *types.MTP, pool type mtp.MtpHealth = h // compute interest // TODO: missing fields - for _, custodyAsset := range mtp.CustodyAssets { + for _, custody := range mtp.Custodies { + custodyAsset := custody.Denom // Retrieve AmmPool ammPool, err := k.CloseLongChecker.GetAmmPool(ctx, mtp.AmmPoolId, custodyAsset) if err != nil { @@ -35,7 +36,8 @@ func BeginBlockerProcessMTP(ctx sdk.Context, k Keeper, mtp *types.MTP, pool type return } - for _, collateralAsset := range mtp.CollateralAssets { + for _, collateral := range mtp.Collaterals { + collateralAsset := collateral.Denom // Handle Interest if within epoch position if err := k.CloseLongChecker.HandleInterest(ctx, mtp, &pool, ammPool, collateralAsset, custodyAsset); err != nil { ctx.Logger().Error(errors.Wrap(err, fmt.Sprintf("error handling interest payment: %s", collateralAsset)).Error()) diff --git a/x/margin/keeper/calc_mtp_consolidate_collateral.go b/x/margin/keeper/calc_mtp_consolidate_collateral.go index f8a796c11..f39ed92af 100644 --- a/x/margin/keeper/calc_mtp_consolidate_collateral.go +++ b/x/margin/keeper/calc_mtp_consolidate_collateral.go @@ -8,17 +8,17 @@ import ( func (k Keeper) CalcMTPConsolidateCollateral(ctx sdk.Context, mtp *types.MTP) error { consolidateCollateral := sdk.ZeroInt() - for i, asset := range mtp.CollateralAssets { - if asset == ptypes.BaseCurrency { - consolidateCollateral = consolidateCollateral.Add(mtp.CollateralAmounts[i]) + for _, asset := range mtp.Collaterals { + if asset.Denom == ptypes.BaseCurrency { + consolidateCollateral = consolidateCollateral.Add(asset.Amount) } else { // swap into base currency - _, ammPool, _, err := k.OpenChecker.PreparePools(ctx, asset) + _, ammPool, _, err := k.OpenChecker.PreparePools(ctx, asset.Denom) if err != nil { return err } - collateralAmtIn := sdk.NewCoin(asset, mtp.CollateralAmounts[i]) + collateralAmtIn := sdk.NewCoin(asset.Denom, asset.Amount) C, err := k.EstimateSwapGivenOut(ctx, collateralAmtIn, ptypes.BaseCurrency, ammPool) if err != nil { return err diff --git a/x/margin/keeper/calc_mtp_interest_liabilities.go b/x/margin/keeper/calc_mtp_interest_liabilities.go index 2739afb74..3f09a54da 100644 --- a/x/margin/keeper/calc_mtp_interest_liabilities.go +++ b/x/margin/keeper/calc_mtp_interest_liabilities.go @@ -17,11 +17,11 @@ func (k Keeper) CalcMTPInterestLiabilities(ctx sdk.Context, mtp *types.MTP, inte collateralIndex, _ := k.GetMTPAssetIndex(mtp, collateralAsset, "") unpaidCollaterals := sdk.ZeroInt() // Calculate collateral interests in base currency - if mtp.CollateralAssets[collateralIndex] == ptypes.BaseCurrency { - unpaidCollaterals = unpaidCollaterals.Add(mtp.InterestUnpaidCollaterals[collateralIndex]) + if mtp.Collaterals[collateralIndex].Denom == ptypes.BaseCurrency { + unpaidCollaterals = unpaidCollaterals.Add(mtp.InterestUnpaidCollaterals[collateralIndex].Amount) } else { // Liability is in base currency, so convert it to base currency - unpaidCollateralIn := sdk.NewCoin(mtp.CollateralAssets[collateralIndex], mtp.InterestUnpaidCollaterals[collateralIndex]) + unpaidCollateralIn := sdk.NewCoin(mtp.Collaterals[collateralIndex].Denom, mtp.InterestUnpaidCollaterals[collateralIndex].Amount) C, err := k.EstimateSwapGivenOut(ctx, unpaidCollateralIn, ptypes.BaseCurrency, ammPool) if err != nil { return sdk.ZeroInt() diff --git a/x/margin/keeper/close.go b/x/margin/keeper/close.go index 5acc8aaea..cfb4eb207 100644 --- a/x/margin/keeper/close.go +++ b/x/margin/keeper/close.go @@ -31,20 +31,22 @@ func (k Keeper) Close(ctx sdk.Context, msg *types.MsgClose) (*types.MsgCloseResp return nil, sdkerrors.Wrap(types.ErrInvalidPosition, mtp.Position.String()) } + collateralIndex := len(mtp.Collaterals) - 1 + custodyIndex := len(mtp.Custodies) - 1 + mtpPosIndex := len(mtp.Leverages) - 1 + ctx.EventManager().EmitEvent(sdk.NewEvent(types.EventClose, 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", closedMtp.Collaterals[collateralIndex].String()), + sdk.NewAttribute("custody", closedMtp.Custodies[custodyIndex].String()), sdk.NewAttribute("repay_amount", repayAmount.String()), - sdk.NewAttribute("leverage", closedMtp.Leverages[0].String()), + sdk.NewAttribute("leverage", closedMtp.Leverages[mtpPosIndex].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[collateralIndex].String()), + sdk.NewAttribute("interest_paid_custody", mtp.InterestPaidCustodies[custodyIndex].String()), + sdk.NewAttribute("interest_unpaid_collateral", closedMtp.InterestUnpaidCollaterals[collateralIndex].String()), sdk.NewAttribute("health", closedMtp.MtpHealth.String()), )) diff --git a/x/margin/keeper/close_long.go b/x/margin/keeper/close_long.go index 3aaf5532e..330352c44 100644 --- a/x/margin/keeper/close_long.go +++ b/x/margin/keeper/close_long.go @@ -20,14 +20,16 @@ func (k Keeper) CloseLong(ctx sdk.Context, msg *types.MsgClose) (*types.MTP, sdk } repayAmount := sdk.ZeroInt() - for _, custodyAsset := range mtp.CustodyAssets { + for _, custody := range mtp.Custodies { + custodyAsset := custody.Denom // Retrieve AmmPool ammPool, err := k.CloseLongChecker.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.CloseLongChecker.HandleInterest(ctx, &mtp, &pool, ammPool, collateralAsset, custodyAsset); err != nil { return nil, sdk.ZeroInt(), err @@ -40,7 +42,8 @@ func (k Keeper) CloseLong(ctx sdk.Context, msg *types.MsgClose) (*types.MTP, sdk 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.CloseLongChecker.EstimateAndRepay(ctx, mtp, pool, ammPool, collateralAsset, custodyAsset) if err != nil { diff --git a/x/margin/keeper/close_long_test.go b/x/margin/keeper/close_long_test.go index bf1a52192..df8c1a206 100644 --- a/x/margin/keeper/close_long_test.go +++ b/x/margin/keeper/close_long_test.go @@ -89,15 +89,15 @@ func TestCloseLong_AmmPoolNotFound(t *testing.T) { Id: 1, } mtp = types.MTP{ - AmmPoolId: 2, - CustodyAssets: []string{"uatom"}, + AmmPoolId: 2, + Custodies: []sdk.Coin{sdk.NewCoin("uatom", sdk.NewInt(0))}, } ) // Mock behavior mockChecker.On("GetMTP", ctx, msg.Creator, msg.Id).Return(mtp, nil) mockChecker.On("GetPool", ctx, mtp.AmmPoolId).Return(types.Pool{}, true) - mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.CustodyAssets[0]).Return(ammtypes.Pool{}, sdkerrors.Wrap(types.ErrPoolDoesNotExist, mtp.CustodyAssets[0])) + mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.Custodies[0].Denom).Return(ammtypes.Pool{}, sdkerrors.Wrap(types.ErrPoolDoesNotExist, mtp.Custodies[0].Denom)) _, _, err := k.CloseLong(ctx, msg) @@ -122,9 +122,9 @@ func TestCloseLong_ErrorHandleInterest(t *testing.T) { Id: 1, } mtp = types.MTP{ - AmmPoolId: 2, - CustodyAssets: []string{"uatom"}, - CollateralAssets: []string{ptypes.BaseCurrency}, + AmmPoolId: 2, + Collaterals: []sdk.Coin{sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(0))}, + Custodies: []sdk.Coin{sdk.NewCoin("uatom", sdk.NewInt(0))}, } pool = types.Pool{ InterestRate: math.LegacyNewDec(2), @@ -135,8 +135,8 @@ func TestCloseLong_ErrorHandleInterest(t *testing.T) { // Mock behavior mockChecker.On("GetMTP", ctx, msg.Creator, msg.Id).Return(mtp, nil) mockChecker.On("GetPool", ctx, mtp.AmmPoolId).Return(pool, true) - mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.CustodyAssets[0]).Return(ammPool, nil) - mockChecker.On("HandleInterest", ctx, &mtp, &pool, ammPool, mtp.CollateralAssets[0], mtp.CustodyAssets[0]).Return(errors.New("error executing handle interest")) + mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.Custodies[0].Denom).Return(ammPool, nil) + mockChecker.On("HandleInterest", ctx, &mtp, &pool, ammPool, mtp.Collaterals[0].Denom, mtp.Custodies[0].Denom).Return(errors.New("error executing handle interest")) _, _, err := k.CloseLong(ctx, msg) @@ -161,9 +161,9 @@ func TestCloseLong_ErrorTakeOutCustody(t *testing.T) { Id: 1, } mtp = types.MTP{ - AmmPoolId: 2, - CustodyAssets: []string{"uatom"}, - CollateralAssets: []string{ptypes.BaseCurrency}, + AmmPoolId: 2, + Collaterals: []sdk.Coin{sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(0))}, + Custodies: []sdk.Coin{sdk.NewCoin("uatom", sdk.NewInt(0))}, } pool = types.Pool{ InterestRate: math.LegacyNewDec(2), @@ -174,9 +174,9 @@ func TestCloseLong_ErrorTakeOutCustody(t *testing.T) { // Mock behavior mockChecker.On("GetMTP", ctx, msg.Creator, msg.Id).Return(mtp, nil) mockChecker.On("GetPool", ctx, mtp.AmmPoolId).Return(pool, true) - mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.CustodyAssets[0]).Return(ammPool, nil) - mockChecker.On("HandleInterest", ctx, &mtp, &pool, ammPool, mtp.CollateralAssets[0], mtp.CustodyAssets[0]).Return(nil) - mockChecker.On("TakeOutCustody", ctx, mtp, &pool, mtp.CustodyAssets[0]).Return(errors.New("error executing take out custody")) + mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.Custodies[0].Denom).Return(ammPool, nil) + mockChecker.On("HandleInterest", ctx, &mtp, &pool, ammPool, mtp.Collaterals[0].Denom, mtp.Custodies[0].Denom).Return(nil) + mockChecker.On("TakeOutCustody", ctx, mtp, &pool, mtp.Custodies[0].Denom).Return(errors.New("error executing take out custody")) _, _, err := k.CloseLong(ctx, msg) @@ -201,9 +201,9 @@ func TestCloseLong_ErrorEstimateAndRepay(t *testing.T) { Id: 1, } mtp = types.MTP{ - AmmPoolId: 2, - CustodyAssets: []string{"uatom"}, - CollateralAssets: []string{ptypes.BaseCurrency}, + AmmPoolId: 2, + Collaterals: []sdk.Coin{sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(0))}, + Custodies: []sdk.Coin{sdk.NewCoin("uatom", sdk.NewInt(0))}, } pool = types.Pool{ InterestRate: math.LegacyNewDec(2), @@ -214,10 +214,10 @@ func TestCloseLong_ErrorEstimateAndRepay(t *testing.T) { // Mock behavior mockChecker.On("GetMTP", ctx, msg.Creator, msg.Id).Return(mtp, nil) mockChecker.On("GetPool", ctx, mtp.AmmPoolId).Return(pool, true) - mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.CustodyAssets[0]).Return(ammPool, nil) - mockChecker.On("HandleInterest", ctx, &mtp, &pool, ammPool, mtp.CollateralAssets[0], mtp.CustodyAssets[0]).Return(nil) - mockChecker.On("TakeOutCustody", ctx, mtp, &pool, mtp.CustodyAssets[0]).Return(nil) - mockChecker.On("EstimateAndRepay", ctx, mtp, pool, ammPool, mtp.CollateralAssets[0], mtp.CustodyAssets[0]).Return(sdk.Int{}, errors.New("error executing estimate and repay")) + mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.Custodies[0].Denom).Return(ammPool, nil) + mockChecker.On("HandleInterest", ctx, &mtp, &pool, ammPool, mtp.Collaterals[0].Denom, mtp.Custodies[0].Denom).Return(nil) + mockChecker.On("TakeOutCustody", ctx, mtp, &pool, mtp.Custodies[0].Denom).Return(nil) + mockChecker.On("EstimateAndRepay", ctx, mtp, pool, ammPool, mtp.Collaterals[0].Denom, mtp.Custodies[0].Denom).Return(sdk.Int{}, errors.New("error executing estimate and repay")) _, _, err := k.CloseLong(ctx, msg) @@ -242,9 +242,9 @@ func TestCloseLong_SuccessfulClosingLongPosition(t *testing.T) { Id: 1, } mtp = types.MTP{ - AmmPoolId: 2, - CustodyAssets: []string{"uatom"}, - CollateralAssets: []string{ptypes.BaseCurrency}, + AmmPoolId: 2, + Collaterals: []sdk.Coin{sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(0))}, + Custodies: []sdk.Coin{sdk.NewCoin("uatom", sdk.NewInt(0))}, } pool = types.Pool{ InterestRate: math.LegacyNewDec(2), @@ -256,10 +256,10 @@ func TestCloseLong_SuccessfulClosingLongPosition(t *testing.T) { // Mock behavior mockChecker.On("GetMTP", ctx, msg.Creator, msg.Id).Return(mtp, nil) mockChecker.On("GetPool", ctx, mtp.AmmPoolId).Return(pool, true) - mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.CustodyAssets[0]).Return(ammPool, nil) - mockChecker.On("HandleInterest", ctx, &mtp, &pool, ammPool, mtp.CollateralAssets[0], mtp.CustodyAssets[0]).Return(nil) - mockChecker.On("TakeOutCustody", ctx, mtp, &pool, mtp.CustodyAssets[0]).Return(nil) - mockChecker.On("EstimateAndRepay", ctx, mtp, pool, ammPool, mtp.CollateralAssets[0], mtp.CustodyAssets[0]).Return(repayAmount, nil) + mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.Custodies[0].Denom).Return(ammPool, nil) + mockChecker.On("HandleInterest", ctx, &mtp, &pool, ammPool, mtp.Collaterals[0].Denom, mtp.Custodies[0].Denom).Return(nil) + mockChecker.On("TakeOutCustody", ctx, mtp, &pool, mtp.Custodies[0].Denom).Return(nil) + mockChecker.On("EstimateAndRepay", ctx, mtp, pool, ammPool, mtp.Collaterals[0].Denom, mtp.Custodies[0].Denom).Return(repayAmount, nil) mtpOut, repayAmountOut, err := k.CloseLong(ctx, msg) 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/close_short_test.go b/x/margin/keeper/close_short_test.go index e8892dc7d..aa51a5441 100644 --- a/x/margin/keeper/close_short_test.go +++ b/x/margin/keeper/close_short_test.go @@ -89,15 +89,15 @@ func TestCloseShort_AmmPoolNotFound(t *testing.T) { Id: 1, } mtp = types.MTP{ - AmmPoolId: 2, - CustodyAssets: []string{"uatom"}, + AmmPoolId: 2, + Custodies: []sdk.Coin{sdk.NewCoin("uatom", sdk.NewInt(0))}, } ) // Mock behavior mockChecker.On("GetMTP", ctx, msg.Creator, msg.Id).Return(mtp, nil) mockChecker.On("GetPool", ctx, mtp.AmmPoolId).Return(types.Pool{}, true) - mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.CustodyAssets[0]).Return(ammtypes.Pool{}, sdkerrors.Wrap(types.ErrPoolDoesNotExist, mtp.CustodyAssets[0])) + mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.Custodies[0].Denom).Return(ammtypes.Pool{}, sdkerrors.Wrap(types.ErrPoolDoesNotExist, mtp.Custodies[0].Denom)) _, _, err := k.CloseShort(ctx, msg) @@ -122,9 +122,9 @@ func TestCloseShort_ErrorHandleInterest(t *testing.T) { Id: 1, } mtp = types.MTP{ - AmmPoolId: 2, - CustodyAssets: []string{"uatom"}, - CollateralAssets: []string{ptypes.BaseCurrency}, + AmmPoolId: 2, + Custodies: []sdk.Coin{sdk.NewCoin("uatom", sdk.NewInt(0))}, + Collaterals: []sdk.Coin{sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(0))}, } pool = types.Pool{ InterestRate: math.LegacyNewDec(2), @@ -135,8 +135,8 @@ func TestCloseShort_ErrorHandleInterest(t *testing.T) { // Mock behavior mockChecker.On("GetMTP", ctx, msg.Creator, msg.Id).Return(mtp, nil) mockChecker.On("GetPool", ctx, mtp.AmmPoolId).Return(pool, true) - mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.CustodyAssets[0]).Return(ammPool, nil) - mockChecker.On("HandleInterest", ctx, &mtp, &pool, ammPool, mtp.CollateralAssets[0], mtp.CustodyAssets[0]).Return(errors.New("error executing handle interest")) + mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.Custodies[0].Denom).Return(ammPool, nil) + mockChecker.On("HandleInterest", ctx, &mtp, &pool, ammPool, mtp.Collaterals[0].Denom, mtp.Custodies[0].Denom).Return(errors.New("error executing handle interest")) _, _, err := k.CloseShort(ctx, msg) @@ -161,9 +161,9 @@ func TestCloseShort_ErrorTakeOutCustody(t *testing.T) { Id: 1, } mtp = types.MTP{ - AmmPoolId: 2, - CustodyAssets: []string{"uatom"}, - CollateralAssets: []string{ptypes.BaseCurrency}, + AmmPoolId: 2, + Custodies: []sdk.Coin{sdk.NewCoin("uatom", sdk.NewInt(0))}, + Collaterals: []sdk.Coin{sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(0))}, } pool = types.Pool{ InterestRate: math.LegacyNewDec(2), @@ -174,9 +174,9 @@ func TestCloseShort_ErrorTakeOutCustody(t *testing.T) { // Mock behavior mockChecker.On("GetMTP", ctx, msg.Creator, msg.Id).Return(mtp, nil) mockChecker.On("GetPool", ctx, mtp.AmmPoolId).Return(pool, true) - mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.CustodyAssets[0]).Return(ammPool, nil) - mockChecker.On("HandleInterest", ctx, &mtp, &pool, ammPool, mtp.CollateralAssets[0], mtp.CustodyAssets[0]).Return(nil) - mockChecker.On("TakeOutCustody", ctx, mtp, &pool, mtp.CustodyAssets[0]).Return(errors.New("error executing take out custody")) + mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.Custodies[0].Denom).Return(ammPool, nil) + mockChecker.On("HandleInterest", ctx, &mtp, &pool, ammPool, mtp.Collaterals[0].Denom, mtp.Custodies[0].Denom).Return(nil) + mockChecker.On("TakeOutCustody", ctx, mtp, &pool, mtp.Custodies[0].Denom).Return(errors.New("error executing take out custody")) _, _, err := k.CloseShort(ctx, msg) @@ -201,9 +201,9 @@ func TestCloseShort_ErrorEstimateAndRepay(t *testing.T) { Id: 1, } mtp = types.MTP{ - AmmPoolId: 2, - CustodyAssets: []string{"uatom"}, - CollateralAssets: []string{ptypes.BaseCurrency}, + AmmPoolId: 2, + Custodies: []sdk.Coin{sdk.NewCoin("uatom", sdk.NewInt(0))}, + Collaterals: []sdk.Coin{sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(0))}, } pool = types.Pool{ InterestRate: math.LegacyNewDec(2), @@ -214,10 +214,10 @@ func TestCloseShort_ErrorEstimateAndRepay(t *testing.T) { // Mock behavior mockChecker.On("GetMTP", ctx, msg.Creator, msg.Id).Return(mtp, nil) mockChecker.On("GetPool", ctx, mtp.AmmPoolId).Return(pool, true) - mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.CustodyAssets[0]).Return(ammPool, nil) - mockChecker.On("HandleInterest", ctx, &mtp, &pool, ammPool, mtp.CollateralAssets[0], mtp.CustodyAssets[0]).Return(nil) - mockChecker.On("TakeOutCustody", ctx, mtp, &pool, mtp.CustodyAssets[0]).Return(nil) - mockChecker.On("EstimateAndRepay", ctx, mtp, pool, ammPool, mtp.CollateralAssets[0], mtp.CustodyAssets[0]).Return(sdk.Int{}, errors.New("error executing estimate and repay")) + mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.Custodies[0].Denom).Return(ammPool, nil) + mockChecker.On("HandleInterest", ctx, &mtp, &pool, ammPool, mtp.Collaterals[0].Denom, mtp.Custodies[0].Denom).Return(nil) + mockChecker.On("TakeOutCustody", ctx, mtp, &pool, mtp.Custodies[0].Denom).Return(nil) + mockChecker.On("EstimateAndRepay", ctx, mtp, pool, ammPool, mtp.Collaterals[0].Denom, mtp.Custodies[0].Denom).Return(sdk.Int{}, errors.New("error executing estimate and repay")) _, _, err := k.CloseShort(ctx, msg) @@ -242,9 +242,9 @@ func TestCloseShort_SuccessfulClosingLongPosition(t *testing.T) { Id: 1, } mtp = types.MTP{ - AmmPoolId: 2, - CustodyAssets: []string{"uatom"}, - CollateralAssets: []string{ptypes.BaseCurrency}, + AmmPoolId: 2, + Custodies: []sdk.Coin{sdk.NewCoin("uatom", sdk.NewInt(0))}, + Collaterals: []sdk.Coin{sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(0))}, } pool = types.Pool{ InterestRate: math.LegacyNewDec(2), @@ -256,10 +256,10 @@ func TestCloseShort_SuccessfulClosingLongPosition(t *testing.T) { // Mock behavior mockChecker.On("GetMTP", ctx, msg.Creator, msg.Id).Return(mtp, nil) mockChecker.On("GetPool", ctx, mtp.AmmPoolId).Return(pool, true) - mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.CustodyAssets[0]).Return(ammPool, nil) - mockChecker.On("HandleInterest", ctx, &mtp, &pool, ammPool, mtp.CollateralAssets[0], mtp.CustodyAssets[0]).Return(nil) - mockChecker.On("TakeOutCustody", ctx, mtp, &pool, mtp.CustodyAssets[0]).Return(nil) - mockChecker.On("EstimateAndRepay", ctx, mtp, pool, ammPool, mtp.CollateralAssets[0], mtp.CustodyAssets[0]).Return(repayAmount, nil) + mockChecker.On("GetAmmPool", ctx, mtp.AmmPoolId, mtp.Custodies[0].Denom).Return(ammPool, nil) + mockChecker.On("HandleInterest", ctx, &mtp, &pool, ammPool, mtp.Collaterals[0].Denom, mtp.Custodies[0].Denom).Return(nil) + mockChecker.On("TakeOutCustody", ctx, mtp, &pool, mtp.Custodies[0].Denom).Return(nil) + mockChecker.On("EstimateAndRepay", ctx, mtp, pool, ammPool, mtp.Collaterals[0].Denom, mtp.Custodies[0].Denom).Return(repayAmount, nil) mtpOut, repayAmountOut, err := k.CloseShort(ctx, msg) 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..9ea746672 100644 --- a/x/margin/keeper/generate_open_event.go +++ b/x/margin/keeper/generate_open_event.go @@ -8,22 +8,20 @@ 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", mtp.Collaterals[collateralIndex].String()), + sdk.NewAttribute("custody", mtp.Custodies[custodyIndex].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/get_mtp_asset_index.go b/x/margin/keeper/get_mtp_asset_index.go index 8095ef792..8c447e612 100644 --- a/x/margin/keeper/get_mtp_asset_index.go +++ b/x/margin/keeper/get_mtp_asset_index.go @@ -8,15 +8,15 @@ import ( func (k Keeper) GetMTPAssetIndex(mtp *types.MTP, collateralAsset string, borrowAsset string) (int, int) { collateralIndex := -1 borrowIndex := -1 - for i, asset := range mtp.CollateralAssets { - if asset == collateralAsset { + for i, asset := range mtp.Collaterals { + if asset.Denom == collateralAsset { collateralIndex = i break } } - for i, asset := range mtp.CustodyAssets { - if asset == borrowAsset { + for i, asset := range mtp.Custodies { + if asset.Denom == borrowAsset { borrowIndex = i break } diff --git a/x/margin/keeper/handle_interest_payment.go b/x/margin/keeper/handle_interest_payment.go index 89d7b8856..0d7bf5d4c 100644 --- a/x/margin/keeper/handle_interest_payment.go +++ b/x/margin/keeper/handle_interest_payment.go @@ -25,8 +25,8 @@ func (k Keeper) HandleInterestPayment(ctx sdk.Context, collateralAsset string, c } // collateralAsset is in base currency - if mtp.CollateralAssets[collateralIndex] == ptypes.BaseCurrency { - mtp.InterestUnpaidCollaterals[collateralIndex] = interestPayment + if mtp.Collaterals[collateralIndex].Denom == ptypes.BaseCurrency { + mtp.InterestUnpaidCollaterals[collateralIndex].Amount = interestPayment } else { // swap amtTokenIn := sdk.NewCoin(ptypes.BaseCurrency, interestPayment) @@ -35,7 +35,7 @@ func (k Keeper) HandleInterestPayment(ctx sdk.Context, collateralAsset string, c return sdk.ZeroInt() } - mtp.InterestUnpaidCollaterals[collateralIndex] = interestPayment + mtp.InterestUnpaidCollaterals[collateralIndex].Amount = interestPayment } } return sdk.ZeroInt() 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/invariant_check_test.go b/x/margin/keeper/invariant_check_test.go index 640de2b07..b23c9b601 100644 --- a/x/margin/keeper/invariant_check_test.go +++ b/x/margin/keeper/invariant_check_test.go @@ -29,9 +29,9 @@ func TestCheckBalanceInvariant_InvalidBalance(t *testing.T) { // Create a pool // Mint 100000USDC - usdcToken := sdk.NewCoins(sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(100000))) + usdcToken := []sdk.Coin{sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(100000))} // Mint 100000ATOM - atomToken := sdk.NewCoins(sdk.NewCoin(ptypes.ATOM, sdk.NewInt(100000))) + atomToken := []sdk.Coin{sdk.NewCoin(ptypes.ATOM, sdk.NewInt(100000))} err := app.BankKeeper.MintCoins(ctx, types.ModuleName, usdcToken) require.NoError(t, err) diff --git a/x/margin/keeper/keeper.go b/x/margin/keeper/keeper.go index 9a173d525..0e5e7ede0 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 } @@ -264,11 +264,11 @@ func (k Keeper) IncrementalInterestPayment(ctx sdk.Context, collateralAsset stri collateralIndex, custodyIndex := k.GetMTPAssetIndex(mtp, collateralAsset, custodyAsset) // 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 { - interestPayment = interestPayment.Add(mtp.InterestUnpaidCollaterals[collateralIndex]) + if mtp.InterestUnpaidCollaterals[collateralIndex].Amount.GT(sdk.ZeroInt()) { + if mtp.Collaterals[collateralIndex].Denom == ptypes.BaseCurrency { + interestPayment = interestPayment.Add(mtp.InterestUnpaidCollaterals[collateralIndex].Amount) } else { - unpaidCollateralIn := sdk.NewCoin(mtp.CollateralAssets[collateralIndex], mtp.InterestUnpaidCollaterals[collateralIndex]) + unpaidCollateralIn := sdk.NewCoin(mtp.Collaterals[collateralIndex].Denom, mtp.InterestUnpaidCollaterals[collateralIndex].Amount) 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 } @@ -296,49 +296,49 @@ func (k Keeper) IncrementalInterestPayment(ctx sdk.Context, collateralAsset stri } // if paying unpaid interest reset to 0 - mtp.InterestUnpaidCollaterals[collateralIndex] = sdk.ZeroInt() + mtp.InterestUnpaidCollaterals[collateralIndex].Amount = 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) + mtp.InterestUnpaidCollaterals[collateralIndex].Amount = 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) + mtp.InterestPaidCollaterals[collateralIndex].Amount = mtp.InterestPaidCollaterals[collateralIndex].Amount.Add(interestPayment) // add payment to total paid - custody - mtp.InterestPaidCustodys[custodyIndex] = mtp.InterestPaidCustodys[custodyIndex].Add(interestPaymentCustody) + mtp.InterestPaidCustodies[custodyIndex].Amount = mtp.InterestPaidCustodies[custodyIndex].Amount.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..4751e244c 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.Coin{sdk.NewCoin(paramtypes.BaseCurrency, sdk.NewInt(0))}, Liabilities: sdk.NewInt(0), - InterestPaidCollaterals: []sdk.Int{sdk.NewInt(0)}, - InterestPaidCustodys: []sdk.Int{sdk.NewInt(0)}, - InterestUnpaidCollaterals: []sdk.Int{sdk.NewInt(0)}, - CustodyAssets: []string{"ATOM"}, - CustodyAmounts: []sdk.Int{sdk.NewInt(0)}, + InterestPaidCollaterals: []sdk.Coin{sdk.NewCoin(paramtypes.BaseCurrency, sdk.NewInt(0))}, + InterestPaidCustodies: []sdk.Coin{sdk.NewCoin("ATOM", sdk.NewInt(0))}, + InterestUnpaidCollaterals: []sdk.Coin{sdk.NewCoin(paramtypes.BaseCurrency, sdk.NewInt(0))}, + Custodies: []sdk.Coin{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_long_test.go b/x/margin/keeper/open_long_test.go index 9edbb62d8..8b586893e 100644 --- a/x/margin/keeper/open_long_test.go +++ b/x/margin/keeper/open_long_test.go @@ -64,6 +64,8 @@ func TestOpenLong_PoolDisabled(t *testing.T) { msg = &types.MsgOpen{ Leverage: math.LegacyNewDec(10), CollateralAmount: math.NewInt(1), + CollateralAsset: "aaa", + BorrowAsset: "bbb", } poolId = uint64(42) ) @@ -417,9 +419,9 @@ func TestOpenLong_BaseCurrency_Collateral(t *testing.T) { // Create a pool // Mint 100000USDC - usdcToken := sdk.NewCoins(sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(100000))) + usdcToken := []sdk.Coin{sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(100000))} // Mint 100000ATOM - atomToken := sdk.NewCoins(sdk.NewCoin(ptypes.ATOM, sdk.NewInt(100000))) + atomToken := []sdk.Coin{sdk.NewCoin(ptypes.ATOM, sdk.NewInt(100000))} err := app.BankKeeper.MintCoins(ctx, ammtypes.ModuleName, usdcToken) require.NoError(t, err) @@ -521,9 +523,9 @@ func TestOpenLong_ATOM_Collateral(t *testing.T) { // Create a pool // Mint 100000USDC - usdcToken := sdk.NewCoins(sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(100000))) + usdcToken := []sdk.Coin{sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(100000))} // Mint 100000ATOM - atomToken := sdk.NewCoins(sdk.NewCoin(ptypes.ATOM, sdk.NewInt(100000))) + atomToken := []sdk.Coin{sdk.NewCoin(ptypes.ATOM, sdk.NewInt(100000))} err := app.BankKeeper.MintCoins(ctx, ammtypes.ModuleName, usdcToken) require.NoError(t, err) diff --git a/x/margin/keeper/open_short_process.go b/x/margin/keeper/open_short_process.go index 5ce15fb65..b3f55a5f5 100644 --- a/x/margin/keeper/open_short_process.go +++ b/x/margin/keeper/open_short_process.go @@ -67,7 +67,8 @@ 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.Coin{sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(0))} + mtp.InterestPaidCustodies = []sdk.Coin{sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(0))} } // Borrow the asset the user wants to short. diff --git a/x/margin/keeper/open_short_test.go b/x/margin/keeper/open_short_test.go index 85e20b77f..ab6654f56 100644 --- a/x/margin/keeper/open_short_test.go +++ b/x/margin/keeper/open_short_test.go @@ -65,6 +65,8 @@ func TestOpenShort_PoolDisabled(t *testing.T) { msg = &types.MsgOpen{ Leverage: math.LegacyNewDec(10), CollateralAmount: math.NewInt(1), + CollateralAsset: "aaa", + BorrowAsset: "bbb", } poolId = uint64(42) ) @@ -442,9 +444,9 @@ func TestOpenShort_BaseCurrency_Collateral(t *testing.T) { // Create a pool // Mint 100000USDC - usdcToken := sdk.NewCoins(sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(100000))) + usdcToken := []sdk.Coin{sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(100000))} // Mint 100000ATOM - atomToken := sdk.NewCoins(sdk.NewCoin(ptypes.ATOM, sdk.NewInt(100000))) + atomToken := []sdk.Coin{sdk.NewCoin(ptypes.ATOM, sdk.NewInt(100000))} err := app.BankKeeper.MintCoins(ctx, ammtypes.ModuleName, usdcToken) require.NoError(t, err) @@ -546,9 +548,9 @@ func TestOpenShort_ATOM_Collateral(t *testing.T) { // Create a pool // Mint 100000USDC - usdcToken := sdk.NewCoins(sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(100000))) + usdcToken := []sdk.Coin{sdk.NewCoin(ptypes.BaseCurrency, sdk.NewInt(100000))} // Mint 100000ATOM - atomToken := sdk.NewCoins(sdk.NewCoin(ptypes.ATOM, sdk.NewInt(100000))) + atomToken := []sdk.Coin{sdk.NewCoin(ptypes.ATOM, sdk.NewInt(100000))} err := app.BankKeeper.MintCoins(ctx, ammtypes.ModuleName, usdcToken) require.NoError(t, err) diff --git a/x/margin/keeper/repay.go b/x/margin/keeper/repay.go index 4cd79ee58..da1748fb4 100644 --- a/x/margin/keeper/repay.go +++ b/x/margin/keeper/repay.go @@ -16,13 +16,13 @@ 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].Amount) C, err := k.EstimateSwapGivenOut(ctx, unpaidCollateralIn, ptypes.BaseCurrency, ammPool) if err != nil { return err } - InterestUnpaidCollateral = C + InterestUnpaidCollateral.Amount = C } var err error @@ -32,21 +32,21 @@ func (k Keeper) Repay(ctx sdk.Context, mtp *types.MTP, pool *types.Pool, ammPool } have := repayAmount - owe := Liabilities.Add(InterestUnpaidCollateral) + owe := Liabilities.Add(InterestUnpaidCollateral.Amount) if have.LT(Liabilities) { //can't afford principle liability returnAmount = sdk.ZeroInt() debtP = Liabilities.Sub(have) - debtI = InterestUnpaidCollateral + debtI = InterestUnpaidCollateral.Amount } else if have.LT(owe) { // v principle liability; x excess liability returnAmount = sdk.ZeroInt() debtP = sdk.ZeroInt() - debtI = Liabilities.Add(InterestUnpaidCollateral).Sub(have) + debtI = Liabilities.Add(InterestUnpaidCollateral.Amount).Sub(have) } else { // can afford both - returnAmount = have.Sub(Liabilities).Sub(InterestUnpaidCollateral) + returnAmount = have.Sub(Liabilities).Sub(InterestUnpaidCollateral.Amount) debtP = sdk.ZeroInt() debtI = sdk.ZeroInt() } @@ -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..ce61bafa0 100644 --- a/x/margin/keeper/update_mtp_health.go +++ b/x/margin/keeper/update_mtp_health.go @@ -14,12 +14,12 @@ 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 { - if mtp.InterestUnpaidCollaterals[i].GT(sdk.ZeroInt()) { - unpaidCollaterals := sdk.NewCoin(mtp.CollateralAssets[i], mtp.InterestUnpaidCollaterals[i]) + for i := range mtp.Collaterals { + if mtp.InterestUnpaidCollaterals[i].Amount.GT(sdk.ZeroInt()) { + unpaidCollaterals := sdk.NewCoin(mtp.Collaterals[i].Denom, mtp.InterestUnpaidCollaterals[i].Amount) - if mtp.CollateralAssets[i] == ptypes.BaseCurrency { - xl = xl.Add(mtp.InterestUnpaidCollaterals[i]) + if mtp.Collaterals[i].Denom == ptypes.BaseCurrency { + xl = xl.Add(mtp.InterestUnpaidCollaterals[i].Amount) } else { C, err := k.EstimateSwapGivenOut(ctx, unpaidCollaterals, ptypes.BaseCurrency, ammPool) if err != nil { @@ -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..349dc72aa --- /dev/null +++ b/x/margin/types/add_or_append_coin.go @@ -0,0 +1,8 @@ +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.Coins, coin sdk.Coin) sdk.Coins { + return coins.Add(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,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x8b, 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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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..4b5726b9a 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.Coin{sdk.NewCoin(collateralAsset, sdk.ZeroInt())}, Liabilities: sdk.ZeroInt(), - InterestPaidCollaterals: []sdk.Int{sdk.ZeroInt()}, - InterestPaidCustodys: []sdk.Int{sdk.ZeroInt()}, - InterestUnpaidCollaterals: []sdk.Int{sdk.ZeroInt()}, - CustodyAssets: []string{borrowAsset}, - CustodyAmounts: []sdk.Int{sdk.ZeroInt()}, + InterestPaidCollaterals: []sdk.Coin{sdk.NewCoin(collateralAsset, sdk.ZeroInt())}, + InterestPaidCustodies: []sdk.Coin{sdk.NewCoin(borrowAsset, sdk.ZeroInt())}, + InterestUnpaidCollaterals: []sdk.Coin{sdk.NewCoin(collateralAsset, sdk.ZeroInt())}, + Custodies: []sdk.Coin{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 28fdb3277..f1e1564cf 100644 --- a/x/margin/types/types.pb.go +++ b/x/margin/types/types.pb.go @@ -6,6 +6,7 @@ package types import ( fmt "fmt" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" io "io" @@ -54,21 +55,19 @@ func (Position) EnumDescriptor() ([]byte, []int) { type MTP struct { Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - CollateralAssets []string `protobuf:"bytes,2,rep,name=collateral_assets,json=collateralAssets,proto3" json:"collateral_assets,omitempty"` - CollateralAmounts []github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,rep,name=collateral_amounts,json=collateralAmounts,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"collateral_amounts"` - Liabilities github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,opt,name=liabilities,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"liabilities"` - InterestPaidCollaterals []github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,5,rep,name=interest_paid_collaterals,json=interestPaidCollaterals,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"interest_paid_collaterals"` - InterestPaidCustodys []github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,6,rep,name=interest_paid_custodys,json=interestPaidCustodys,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"interest_paid_custodys"` - InterestUnpaidCollaterals []github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,7,rep,name=interest_unpaid_collaterals,json=interestUnpaidCollaterals,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"interest_unpaid_collaterals"` - CustodyAssets []string `protobuf:"bytes,8,rep,name=custody_assets,json=custodyAssets,proto3" json:"custody_assets,omitempty"` - CustodyAmounts []github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,9,rep,name=custody_amounts,json=custodyAmounts,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"custody_amounts"` - Leverages []github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,10,rep,name=leverages,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"leverages"` - MtpHealth github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,11,opt,name=mtp_health,json=mtpHealth,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"mtp_health"` - Position Position `protobuf:"varint,12,opt,name=position,proto3,enum=elys.margin.Position" json:"position,omitempty"` - Id uint64 `protobuf:"varint,13,opt,name=id,proto3" json:"id,omitempty"` - AmmPoolId uint64 `protobuf:"varint,14,opt,name=amm_pool_id,json=ammPoolId,proto3" json:"amm_pool_id,omitempty"` - ConsolidateLeverage github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,15,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,16,opt,name=sum_collateral,json=sumCollateral,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"sum_collateral"` + 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 []types.Coin `protobuf:"bytes,4,rep,name=interest_paid_collaterals,json=interestPaidCollaterals,proto3" json:"interest_paid_collaterals"` + InterestPaidCustodies []types.Coin `protobuf:"bytes,5,rep,name=interest_paid_custodies,json=interestPaidCustodies,proto3" json:"interest_paid_custodies"` + InterestUnpaidCollaterals []types.Coin `protobuf:"bytes,6,rep,name=interest_unpaid_collaterals,json=interestUnpaidCollaterals,proto3" json:"interest_unpaid_collaterals"` + Custodies []types.Coin `protobuf:"bytes,7,rep,name=custodies,proto3" json:"custodies"` + 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{} } @@ -111,16 +110,37 @@ func (m *MTP) GetAddress() string { return "" } -func (m *MTP) GetCollateralAssets() []string { +func (m *MTP) GetCollaterals() []types.Coin { if m != nil { - return m.CollateralAssets + return m.Collaterals } return nil } -func (m *MTP) GetCustodyAssets() []string { +func (m *MTP) GetInterestPaidCollaterals() []types.Coin { if m != nil { - return m.CustodyAssets + return m.InterestPaidCollaterals + } + return nil +} + +func (m *MTP) GetInterestPaidCustodies() []types.Coin { + if m != nil { + return m.InterestPaidCustodies + } + return nil +} + +func (m *MTP) GetInterestUnpaidCollaterals() []types.Coin { + if m != nil { + return m.InterestUnpaidCollaterals + } + return nil +} + +func (m *MTP) GetCustodies() []types.Coin { + if m != nil { + return m.Custodies } return nil } @@ -199,44 +219,44 @@ func init() { func init() { proto.RegisterFile("elys/margin/types.proto", fileDescriptor_cd1c09c977f732f9) } var fileDescriptor_cd1c09c977f732f9 = []byte{ - // 591 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xdf, 0x4e, 0xdb, 0x3e, - 0x14, 0xc7, 0x9b, 0xf2, 0xaf, 0x39, 0xfd, 0x51, 0xfa, 0xf3, 0xd8, 0xf0, 0x36, 0x29, 0x54, 0x48, - 0x9b, 0xaa, 0x21, 0xda, 0x8d, 0x3d, 0x01, 0xff, 0x36, 0x2a, 0x15, 0x88, 0x02, 0x08, 0x69, 0xd2, - 0x14, 0x99, 0xda, 0x6a, 0x3d, 0xec, 0x38, 0x8a, 0x1d, 0x36, 0xde, 0x62, 0x8f, 0xc5, 0x25, 0x97, - 0xd3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04, 0xa7, 0xc4, - 0x30, 0x3f, 0x1f, 0x05, 0x2f, 0x95, 0xea, 0xfd, 0x49, 0x81, 0xd5, 0xcf, 0x50, 0xe8, 0x14, 0x1a, - 0x3a, 0x96, 0x05, 0x1b, 0xe1, 0x66, 0xa9, 0x9b, 0xb7, 0xa8, 0x63, 0x39, 0xb5, 0xce, 0xda, 0x26, - 0xd8, 0x67, 0x23, 0x6e, 0x58, 0x9f, 0x6b, 0x93, 0xd8, 0xe8, 0x92, 0xa4, 0xba, 0x2a, 0xf2, 0x05, - 0xd7, 0x06, 0x5b, 0x63, 0x1b, 0x4d, 0xa2, 0x49, 0xd9, 0x9b, 0xb7, 0x50, 0xcb, 0xf7, 0x0c, 0x2d, - 0x41, 0xfd, 0xf4, 0xf0, 0xd8, 0xdd, 0xdb, 0xe9, 0x7d, 0xe8, 0xed, 0xed, 0x36, 0x2b, 0xa8, 0x06, - 0xb3, 0xfd, 0xa3, 0xc3, 0x8f, 0x4d, 0x0b, 0xd9, 0x30, 0x77, 0xbc, 0x7f, 0xe4, 0x9d, 0x34, 0xab, - 0xdb, 0x7b, 0xd7, 0x77, 0x8e, 0x75, 0x73, 0xe7, 0x58, 0xbf, 0xee, 0x1c, 0xeb, 0xfb, 0xbd, 0x53, - 0xb9, 0xb9, 0x77, 0x2a, 0x3f, 0xee, 0x9d, 0xca, 0xa7, 0xf5, 0x42, 0xdb, 0xc9, 0xa1, 0x6c, 0x04, - 0xcc, 0x7c, 0x55, 0xd1, 0x45, 0xba, 0xe8, 0x7e, 0x7b, 0xf0, 0xa2, 0x9e, 0xcf, 0xa7, 0xef, 0xe5, - 0xfb, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x49, 0x3f, 0x3a, 0xe7, 0x6d, 0x05, 0x00, 0x00, + // 583 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x4f, 0x4f, 0xdb, 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, 0x79, 0x75, 0x96, 0xb3, 0xab, 0xe7, 0xfd, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x69, + 0x5d, 0x19, 0x84, 0xd8, 0x04, 0x00, 0x00, } func (m *MTP) Marshal() (dAtA []byte, err error) { @@ -268,9 +288,7 @@ func (m *MTP) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintTypes(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0x82 + dAtA[i] = 0x72 { size := m.ConsolidateLeverage.Size() i -= size @@ -280,21 +298,21 @@ func (m *MTP) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintTypes(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x7a + dAtA[i] = 0x6a if m.AmmPoolId != 0 { i = encodeVarintTypes(dAtA, i, uint64(m.AmmPoolId)) i-- - dAtA[i] = 0x70 + dAtA[i] = 0x60 } if m.Id != 0 { i = encodeVarintTypes(dAtA, i, uint64(m.Id)) i-- - dAtA[i] = 0x68 + dAtA[i] = 0x58 } if m.Position != 0 { i = encodeVarintTypes(dAtA, i, uint64(m.Position)) i-- - dAtA[i] = 0x60 + dAtA[i] = 0x50 } { size := m.MtpHealth.Size() @@ -305,7 +323,7 @@ func (m *MTP) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintTypes(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x5a + dAtA[i] = 0x4a if len(m.Leverages) > 0 { for iNdEx := len(m.Leverages) - 1; iNdEx >= 0; iNdEx-- { { @@ -317,72 +335,63 @@ func (m *MTP) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintTypes(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x52 + dAtA[i] = 0x42 } } - if len(m.CustodyAmounts) > 0 { - for iNdEx := len(m.CustodyAmounts) - 1; iNdEx >= 0; iNdEx-- { + if len(m.Custodies) > 0 { + for iNdEx := len(m.Custodies) - 1; iNdEx >= 0; iNdEx-- { { - size := m.CustodyAmounts[iNdEx].Size() - i -= size - if _, err := m.CustodyAmounts[iNdEx].MarshalTo(dAtA[i:]); err != nil { + size, err := m.Custodies[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { return 0, err } + i -= size i = encodeVarintTypes(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x4a - } - } - if len(m.CustodyAssets) > 0 { - for iNdEx := len(m.CustodyAssets) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.CustodyAssets[iNdEx]) - copy(dAtA[i:], m.CustodyAssets[iNdEx]) - i = encodeVarintTypes(dAtA, i, uint64(len(m.CustodyAssets[iNdEx]))) - i-- - dAtA[i] = 0x42 + dAtA[i] = 0x3a } } if len(m.InterestUnpaidCollaterals) > 0 { for iNdEx := len(m.InterestUnpaidCollaterals) - 1; iNdEx >= 0; iNdEx-- { { - size := m.InterestUnpaidCollaterals[iNdEx].Size() - i -= size - if _, err := m.InterestUnpaidCollaterals[iNdEx].MarshalTo(dAtA[i:]); err != nil { + size, err := m.InterestUnpaidCollaterals[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { return 0, err } + i -= size i = encodeVarintTypes(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x3a + dAtA[i] = 0x32 } } - if len(m.InterestPaidCustodys) > 0 { - for iNdEx := len(m.InterestPaidCustodys) - 1; iNdEx >= 0; iNdEx-- { + if len(m.InterestPaidCustodies) > 0 { + for iNdEx := len(m.InterestPaidCustodies) - 1; iNdEx >= 0; iNdEx-- { { - size := m.InterestPaidCustodys[iNdEx].Size() - i -= size - if _, err := m.InterestPaidCustodys[iNdEx].MarshalTo(dAtA[i:]); err != nil { + size, err := m.InterestPaidCustodies[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { return 0, err } + i -= size i = encodeVarintTypes(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x32 + dAtA[i] = 0x2a } } if len(m.InterestPaidCollaterals) > 0 { for iNdEx := len(m.InterestPaidCollaterals) - 1; iNdEx >= 0; iNdEx-- { { - size := m.InterestPaidCollaterals[iNdEx].Size() - i -= size - if _, err := m.InterestPaidCollaterals[iNdEx].MarshalTo(dAtA[i:]); err != nil { + size, err := m.InterestPaidCollaterals[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { return 0, err } + i -= size i = encodeVarintTypes(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x2a + dAtA[i] = 0x22 } } { @@ -394,27 +403,18 @@ func (m *MTP) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintTypes(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x22 - if len(m.CollateralAmounts) > 0 { - for iNdEx := len(m.CollateralAmounts) - 1; iNdEx >= 0; iNdEx-- { + dAtA[i] = 0x1a + if len(m.Collaterals) > 0 { + for iNdEx := len(m.Collaterals) - 1; iNdEx >= 0; iNdEx-- { { - size := m.CollateralAmounts[iNdEx].Size() - i -= size - if _, err := m.CollateralAmounts[iNdEx].MarshalTo(dAtA[i:]); err != nil { + size, err := m.Collaterals[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { return 0, err } + i -= size i = encodeVarintTypes(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x1a - } - } - if len(m.CollateralAssets) > 0 { - for iNdEx := len(m.CollateralAssets) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.CollateralAssets[iNdEx]) - copy(dAtA[i:], m.CollateralAssets[iNdEx]) - i = encodeVarintTypes(dAtA, i, uint64(len(m.CollateralAssets[iNdEx]))) - i-- dAtA[i] = 0x12 } } @@ -481,14 +481,8 @@ func (m *MTP) Size() (n int) { if l > 0 { n += 1 + l + sovTypes(uint64(l)) } - if len(m.CollateralAssets) > 0 { - for _, s := range m.CollateralAssets { - l = len(s) - n += 1 + l + sovTypes(uint64(l)) - } - } - if len(m.CollateralAmounts) > 0 { - for _, e := range m.CollateralAmounts { + if len(m.Collaterals) > 0 { + for _, e := range m.Collaterals { l = e.Size() n += 1 + l + sovTypes(uint64(l)) } @@ -501,8 +495,8 @@ func (m *MTP) Size() (n int) { n += 1 + l + sovTypes(uint64(l)) } } - if len(m.InterestPaidCustodys) > 0 { - for _, e := range m.InterestPaidCustodys { + if len(m.InterestPaidCustodies) > 0 { + for _, e := range m.InterestPaidCustodies { l = e.Size() n += 1 + l + sovTypes(uint64(l)) } @@ -513,14 +507,8 @@ func (m *MTP) Size() (n int) { n += 1 + l + sovTypes(uint64(l)) } } - if len(m.CustodyAssets) > 0 { - for _, s := range m.CustodyAssets { - l = len(s) - n += 1 + l + sovTypes(uint64(l)) - } - } - if len(m.CustodyAmounts) > 0 { - for _, e := range m.CustodyAmounts { + if len(m.Custodies) > 0 { + for _, e := range m.Custodies { l = e.Size() n += 1 + l + sovTypes(uint64(l)) } @@ -545,7 +533,7 @@ func (m *MTP) Size() (n int) { l = m.ConsolidateLeverage.Size() n += 1 + l + sovTypes(uint64(l)) l = m.SumCollateral.Size() - n += 2 + l + sovTypes(uint64(l)) + n += 1 + l + sovTypes(uint64(l)) return n } @@ -633,41 +621,9 @@ func (m *MTP) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CollateralAssets", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - 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 ErrInvalidLengthTypes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.CollateralAssets = append(m.CollateralAssets, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CollateralAmounts", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Collaterals", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -677,29 +633,27 @@ func (m *MTP) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - var v github_com_cosmos_cosmos_sdk_types.Int - m.CollateralAmounts = append(m.CollateralAmounts, v) - if err := m.CollateralAmounts[len(m.CollateralAmounts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Collaterals = append(m.Collaterals, types.Coin{}) + if err := m.Collaterals[len(m.Collaterals)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 4: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Liabilities", wireType) } @@ -733,11 +687,11 @@ func (m *MTP) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 5: + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field InterestPaidCollaterals", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -747,33 +701,31 @@ func (m *MTP) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - var v github_com_cosmos_cosmos_sdk_types.Int - m.InterestPaidCollaterals = append(m.InterestPaidCollaterals, v) + m.InterestPaidCollaterals = append(m.InterestPaidCollaterals, types.Coin{}) if err := m.InterestPaidCollaterals[len(m.InterestPaidCollaterals)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 6: + case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InterestPaidCustodys", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field InterestPaidCustodies", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -783,33 +735,31 @@ func (m *MTP) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - var v github_com_cosmos_cosmos_sdk_types.Int - m.InterestPaidCustodys = append(m.InterestPaidCustodys, v) - if err := m.InterestPaidCustodys[len(m.InterestPaidCustodys)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.InterestPaidCustodies = append(m.InterestPaidCustodies, types.Coin{}) + if err := m.InterestPaidCustodies[len(m.InterestPaidCustodies)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 7: + case 6: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field InterestUnpaidCollaterals", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -819,65 +769,31 @@ func (m *MTP) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - var v github_com_cosmos_cosmos_sdk_types.Int - m.InterestUnpaidCollaterals = append(m.InterestUnpaidCollaterals, v) + m.InterestUnpaidCollaterals = append(m.InterestUnpaidCollaterals, types.Coin{}) if err := m.InterestUnpaidCollaterals[len(m.InterestUnpaidCollaterals)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 8: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CustodyAssets", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - 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 ErrInvalidLengthTypes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.CustodyAssets = append(m.CustodyAssets, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 9: + case 7: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CustodyAmounts", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Custodies", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -887,29 +803,27 @@ func (m *MTP) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - var v github_com_cosmos_cosmos_sdk_types.Int - m.CustodyAmounts = append(m.CustodyAmounts, v) - if err := m.CustodyAmounts[len(m.CustodyAmounts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Custodies = append(m.Custodies, types.Coin{}) + if err := m.Custodies[len(m.Custodies)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 10: + case 8: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Leverages", wireType) } @@ -945,7 +859,7 @@ func (m *MTP) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 11: + case 9: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field MtpHealth", wireType) } @@ -979,7 +893,7 @@ func (m *MTP) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 12: + case 10: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field Position", wireType) } @@ -998,7 +912,7 @@ func (m *MTP) Unmarshal(dAtA []byte) error { break } } - case 13: + case 11: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) } @@ -1017,7 +931,7 @@ func (m *MTP) Unmarshal(dAtA []byte) error { break } } - case 14: + case 12: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field AmmPoolId", wireType) } @@ -1036,7 +950,7 @@ func (m *MTP) Unmarshal(dAtA []byte) error { break } } - case 15: + case 13: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field ConsolidateLeverage", wireType) } @@ -1070,7 +984,7 @@ func (m *MTP) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 16: + case 14: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field SumCollateral", wireType) }