From 4cf6beffd31047f439bbbd1233e7743afa59ff25 Mon Sep 17 00:00:00 2001 From: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com> Date: Wed, 22 Nov 2023 11:59:46 +0100 Subject: [PATCH] feat: funding fee payment flow (#261) * feat: funding fee payment flow * test: fix tests * test: fix * test: fix --- docs/static/openapi.yml | 703 ++++++++++++++++++ proto/elys/margin/params.proto | 13 + proto/elys/margin/pool.proto | 5 + proto/elys/margin/types.proto | 14 + x/margin/client/cli/query_mtp_test.go | 4 + x/margin/keeper/begin_blocker.go | 2 + x/margin/keeper/begin_blocker_process_mtp.go | 29 +- .../calc_mtp_take_profit_liabilities.go | 2 +- x/margin/keeper/events.go | 21 +- .../keeper/handle_borrow_interest_payment.go | 2 +- .../keeper/handle_funding_fee_collection.go | 96 +++ .../keeper/handle_funding_fee_distribution.go | 98 +++ x/margin/keeper/keeper.go | 8 +- x/margin/keeper/open_short_process.go | 2 + x/margin/keeper/params.go | 21 + x/margin/keeper/update_funding_rate.go | 30 + x/margin/types/calc_funding_rate.go | 21 + x/margin/types/calc_funding_rate_test.go | 55 ++ x/margin/types/calc_take_amount.go | 18 + x/margin/types/params.go | 106 ++- x/margin/types/params.pb.go | 297 ++++++-- x/margin/types/pool.go | 16 +- x/margin/types/pool.pb.go | 117 ++- x/margin/types/types.go | 4 + x/margin/types/types.pb.go | 351 +++++++-- 25 files changed, 1868 insertions(+), 167 deletions(-) create mode 100644 x/margin/keeper/handle_funding_fee_collection.go create mode 100644 x/margin/keeper/handle_funding_fee_distribution.go create mode 100644 x/margin/keeper/update_funding_rate.go create mode 100644 x/margin/types/calc_funding_rate.go create mode 100644 x/margin/types/calc_funding_rate_test.go create mode 100644 x/margin/types/calc_take_amount.go diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index 347b58e0c..d66c5d82c 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -40704,6 +40704,78 @@ paths: type: string take_profit_price: type: string + take_profit_borrow_rate: + type: string + funding_fee_paid_collaterals: + type: array + items: + 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. + title: funding fee paid + funding_fee_paid_custodies: + type: array + items: + 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. + funding_fee_received_collaterals: + type: array + items: + 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. + title: funding fee received + funding_fee_received_custodies: + type: array + items: + 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. default: description: An unexpected error response. schema: @@ -40888,6 +40960,82 @@ paths: type: string take_profit_price: type: string + take_profit_borrow_rate: + type: string + funding_fee_paid_collaterals: + type: array + items: + 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. + title: funding fee paid + funding_fee_paid_custodies: + type: array + items: + 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. + funding_fee_received_collaterals: + type: array + items: + 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. + title: funding fee received + funding_fee_received_custodies: + type: array + items: + 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. pagination: type: object properties: @@ -41152,6 +41300,82 @@ paths: type: string take_profit_price: type: string + take_profit_borrow_rate: + type: string + funding_fee_paid_collaterals: + type: array + items: + 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. + title: funding fee paid + funding_fee_paid_custodies: + type: array + items: + 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. + funding_fee_received_collaterals: + type: array + items: + 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. + title: funding fee received + funding_fee_received_custodies: + type: array + items: + 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. pagination: type: object properties: @@ -41317,6 +41541,16 @@ paths: type: string broker_address: type: string + take_profit_borrow_interest_rate_min: + type: string + funding_fee_base_rate: + type: string + funding_fee_max_rate: + type: string + funding_fee_min_rate: + type: string + funding_fee_collection_address: + type: string description: ParamsResponse is response type for the Query/Params RPC method. default: description: An unexpected error response. @@ -41403,6 +41637,11 @@ paths: last_height_borrow_interest_rate_computed: type: string format: int64 + funding_rate: + type: string + title: >- + funding rate, if positive longs pay shorts, if negative + shorts pay longs default: description: An unexpected error response. schema: @@ -41495,6 +41734,11 @@ paths: last_height_borrow_interest_rate_computed: type: string format: int64 + funding_rate: + type: string + title: >- + funding rate, if positive longs pay shorts, if negative + shorts pay longs pagination: type: object properties: @@ -41754,6 +41998,82 @@ paths: type: string take_profit_price: type: string + take_profit_borrow_rate: + type: string + funding_fee_paid_collaterals: + type: array + items: + 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. + title: funding fee paid + funding_fee_paid_custodies: + type: array + items: + 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. + funding_fee_received_collaterals: + type: array + items: + 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. + title: funding fee received + funding_fee_received_custodies: + type: array + items: + 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. pagination: type: object properties: @@ -84701,6 +85021,66 @@ definitions: type: string take_profit_price: type: string + take_profit_borrow_rate: + type: string + funding_fee_paid_collaterals: + type: array + items: + 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. + title: funding fee paid + funding_fee_paid_custodies: + type: array + items: + 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. + funding_fee_received_collaterals: + type: array + items: + 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. + title: funding fee received + funding_fee_received_custodies: + type: array + items: + 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. elys.margin.MTPResponse: type: object properties: @@ -84840,6 +85220,78 @@ definitions: type: string take_profit_price: type: string + take_profit_borrow_rate: + type: string + funding_fee_paid_collaterals: + type: array + items: + 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. + title: funding fee paid + funding_fee_paid_custodies: + type: array + items: + 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. + funding_fee_received_collaterals: + type: array + items: + 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. + title: funding fee received + funding_fee_received_custodies: + type: array + items: + 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. elys.margin.MsgBrokerCloseResponse: type: object properties: @@ -84917,6 +85369,16 @@ definitions: type: string broker_address: type: string + take_profit_borrow_interest_rate_min: + type: string + funding_fee_base_rate: + type: string + funding_fee_max_rate: + type: string + funding_fee_min_rate: + type: string + funding_fee_collection_address: + type: string description: Params defines the parameters for the module. elys.margin.ParamsResponse: type: object @@ -84967,6 +85429,16 @@ definitions: type: string broker_address: type: string + take_profit_borrow_interest_rate_min: + type: string + funding_fee_base_rate: + type: string + funding_fee_max_rate: + type: string + funding_fee_min_rate: + type: string + funding_fee_collection_address: + type: string description: ParamsResponse is response type for the Query/Params RPC method. elys.margin.Pool: type: object @@ -85023,6 +85495,11 @@ definitions: last_height_borrow_interest_rate_computed: type: string format: int64 + funding_rate: + type: string + title: >- + funding rate, if positive longs pay shorts, if negative shorts pay + longs elys.margin.PoolAsset: type: object properties: @@ -85188,6 +85665,78 @@ definitions: type: string take_profit_price: type: string + take_profit_borrow_rate: + type: string + funding_fee_paid_collaterals: + type: array + items: + 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. + title: funding fee paid + funding_fee_paid_custodies: + type: array + items: + 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. + funding_fee_received_collaterals: + type: array + items: + 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. + title: funding fee received + funding_fee_received_custodies: + type: array + items: + 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. pagination: type: object properties: @@ -85355,6 +85904,78 @@ definitions: type: string take_profit_price: type: string + take_profit_borrow_rate: + type: string + funding_fee_paid_collaterals: + type: array + items: + 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. + title: funding fee paid + funding_fee_paid_custodies: + type: array + items: + 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. + funding_fee_received_collaterals: + type: array + items: + 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. + title: funding fee received + funding_fee_received_custodies: + type: array + items: + 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. pagination: type: object properties: @@ -85522,6 +86143,78 @@ definitions: type: string take_profit_price: type: string + take_profit_borrow_rate: + type: string + funding_fee_paid_collaterals: + type: array + items: + 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. + title: funding fee paid + funding_fee_paid_custodies: + type: array + items: + 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. + funding_fee_received_collaterals: + type: array + items: + 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. + title: funding fee received + funding_fee_received_custodies: + type: array + items: + 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. pagination: type: object properties: @@ -85608,6 +86301,11 @@ definitions: last_height_borrow_interest_rate_computed: type: string format: int64 + funding_rate: + type: string + title: >- + funding rate, if positive longs pay shorts, if negative shorts + pay longs pagination: type: object properties: @@ -85692,6 +86390,11 @@ definitions: last_height_borrow_interest_rate_computed: type: string format: int64 + funding_rate: + type: string + title: >- + funding rate, if positive longs pay shorts, if negative shorts pay + longs elys.margin.StatusResponse: type: object properties: diff --git a/proto/elys/margin/params.proto b/proto/elys/margin/params.proto index 6a6f69207..a51303877 100644 --- a/proto/elys/margin/params.proto +++ b/proto/elys/margin/params.proto @@ -68,4 +68,17 @@ message Params { (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false ]; + string funding_fee_base_rate = 22 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + string funding_fee_max_rate = 23 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + string funding_fee_min_rate = 24 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + string funding_fee_collection_address = 25; } diff --git a/proto/elys/margin/pool.proto b/proto/elys/margin/pool.proto index 29f1b5e9a..a4c14911a 100644 --- a/proto/elys/margin/pool.proto +++ b/proto/elys/margin/pool.proto @@ -48,5 +48,10 @@ message Pool { repeated PoolAsset pool_assets_long = 6 [(gogoproto.nullable) = false]; repeated PoolAsset pool_assets_short = 7 [(gogoproto.nullable) = false]; int64 last_height_borrow_interest_rate_computed = 8; + // funding rate, if positive longs pay shorts, if negative shorts pay longs + string funding_rate = 9 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; } diff --git a/proto/elys/margin/types.proto b/proto/elys/margin/types.proto index 87a5b3d0c..b2187efc8 100644 --- a/proto/elys/margin/types.proto +++ b/proto/elys/margin/types.proto @@ -68,6 +68,20 @@ message MTP { (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false ]; + // funding fee paid + repeated cosmos.base.v1beta1.Coin funding_fee_paid_collaterals = 19 [ + (gogoproto.nullable) = false + ]; + repeated cosmos.base.v1beta1.Coin funding_fee_paid_custodies = 20 [ + (gogoproto.nullable) = false + ]; + // funding fee received + repeated cosmos.base.v1beta1.Coin funding_fee_received_collaterals = 21 [ + (gogoproto.nullable) = false + ]; + repeated cosmos.base.v1beta1.Coin funding_fee_received_custodies = 22 [ + (gogoproto.nullable) = false + ]; } message WhiteList { diff --git a/x/margin/client/cli/query_mtp_test.go b/x/margin/client/cli/query_mtp_test.go index 7469eafb1..9e847a77a 100644 --- a/x/margin/client/cli/query_mtp_test.go +++ b/x/margin/client/cli/query_mtp_test.go @@ -54,6 +54,10 @@ func networkWithMTPObjects(t *testing.T, n int) (*network.Network, []*types.MTP) SumCollateral: sdk.ZeroInt(), TakeProfitPrice: sdk.MustNewDecFromStr(types.TakeProfitPriceDefault), TakeProfitBorrowRate: sdk.OneDec(), + FundingFeePaidCollaterals: []sdk.Coin{sdk.NewCoin(paramtypes.BaseCurrency, sdk.NewInt(0))}, + FundingFeePaidCustodies: []sdk.Coin{sdk.NewCoin("ATOM", sdk.NewInt(0))}, + FundingFeeReceivedCollaterals: []sdk.Coin{sdk.NewCoin(paramtypes.BaseCurrency, sdk.NewInt(0))}, + FundingFeeReceivedCustodies: []sdk.Coin{sdk.NewCoin("ATOM", sdk.NewInt(0))}, } mtps = append(mtps, &mtp) diff --git a/x/margin/keeper/begin_blocker.go b/x/margin/keeper/begin_blocker.go index 93ed4bc90..fd8b73b0b 100644 --- a/x/margin/keeper/begin_blocker.go +++ b/x/margin/keeper/begin_blocker.go @@ -45,12 +45,14 @@ func (k Keeper) BeginBlocker(ctx sdk.Context) { pool.BorrowInterestRate = rate pool.LastHeightBorrowInterestRateComputed = currentHeight _ = k.UpdatePoolHealth(ctx, &pool) + _ = k.UpdateFundingRate(ctx, &pool) // TODO: function missing // k.TrackSQBeginBlock(ctx, pool) mtps, _, _ := k.GetMTPsForPool(ctx, pool.AmmPoolId, nil) for _, mtp := range mtps { BeginBlockerProcessMTP(ctx, k, mtp, pool, ammPool, baseCurrency) } + _ = k.HandleFundingFeeDistribution(ctx, mtps, &pool, ammPool, baseCurrency) } k.SetPool(ctx, pool) } diff --git a/x/margin/keeper/begin_blocker_process_mtp.go b/x/margin/keeper/begin_blocker_process_mtp.go index 678a53c43..55cf3763c 100644 --- a/x/margin/keeper/begin_blocker_process_mtp.go +++ b/x/margin/keeper/begin_blocker_process_mtp.go @@ -44,7 +44,7 @@ func BeginBlockerProcessMTP(ctx sdk.Context, k Keeper, mtp *types.MTP, pool type for _, custody := range mtp.Custodies { custodyAsset := custody.Denom // Retrieve AmmPool - ammPool, err := k.CloseLongChecker.GetAmmPool(ctx, mtp.AmmPoolId, custodyAsset) + ammPool, err := k.GetAmmPool(ctx, mtp.AmmPoolId, custodyAsset) if err != nil { ctx.Logger().Error(errors.Wrap(err, fmt.Sprintf("error retrieving amm pool: %d", mtp.AmmPoolId)).Error()) return @@ -53,33 +53,46 @@ func BeginBlockerProcessMTP(ctx sdk.Context, k Keeper, mtp *types.MTP, pool type for _, collateral := range mtp.Collaterals { collateralAsset := collateral.Denom // Handle Borrow Interest if within epoch position - if err := k.CloseLongChecker.HandleBorrowInterest(ctx, mtp, &pool, ammPool, collateralAsset, custodyAsset); err != nil { + if err := k.HandleBorrowInterest(ctx, mtp, &pool, ammPool, collateralAsset, custodyAsset); err != nil { ctx.Logger().Error(errors.Wrap(err, fmt.Sprintf("error handling borrow interest payment: %s", collateralAsset)).Error()) return } + if err := k.HandleFundingFeeCollection(ctx, mtp, &pool, ammPool, collateralAsset, custodyAsset); err != nil { + ctx.Logger().Error(errors.Wrap(err, fmt.Sprintf("error handling funding fee collection: %s", collateralAsset)).Error()) + return + } } } _ = k.SetMTP(ctx, mtp) + var mustForceClose bool = false for _, custody := range mtp.Custodies { - assetPrice, err := k.EstimateSwapGivenOut(ctx, sdk.NewCoin(custody.Denom, sdk.NewInt(1)), baseCurrency, ammPool) + assetPrice, err := k.EstimateSwap(ctx, sdk.NewCoin(custody.Denom, sdk.OneInt()), baseCurrency, ammPool) if err != nil { - ctx.Logger().Error(errors.Wrap(err, fmt.Sprintf("error estimating swap given out: %s", custody.Denom)).Error()) - return + ctx.Logger().Error(errors.Wrap(err, fmt.Sprintf("error estimating swap: %s", custody.Denom)).Error()) + continue } if mtp.TakeProfitPrice.GT(sdk.NewDecFromInt(assetPrice)) { + // flag position as must force close + mustForceClose = true break } - ctx.Logger().Error(fmt.Sprintf("error executing force close on position %s because take profit price %s is less than asset price %s", mtp.String(), mtp.TakeProfitPrice.String(), sdk.NewDecFromInt(assetPrice).String())) - return + ctx.Logger().Error(fmt.Sprintf("skipping force close on position %s because take profit price %s is less than asset price %s", mtp.String(), mtp.TakeProfitPrice.String(), sdk.NewDecFromInt(assetPrice).String())) } // check MTP health against threshold safetyFactor := k.GetSafetyFactor(ctx) if mtp.MtpHealth.GT(safetyFactor) { - ctx.Logger().Error(errors.Wrap(types.ErrMTPHealthy, "error executing force close because mtp is healthy").Error()) + ctx.Logger().Error(errors.Wrap(types.ErrMTPHealthy, "skipping executing force close because mtp is healthy").Error()) + } else { + // flag position as must force close + mustForceClose = true + } + + // if flag is false, then skip force close + if !mustForceClose { return } diff --git a/x/margin/keeper/calc_mtp_take_profit_liabilities.go b/x/margin/keeper/calc_mtp_take_profit_liabilities.go index 4170b8720..320c06063 100644 --- a/x/margin/keeper/calc_mtp_take_profit_liabilities.go +++ b/x/margin/keeper/calc_mtp_take_profit_liabilities.go @@ -16,7 +16,7 @@ func (k Keeper) CalcMTPTakeProfitLiability(ctx sdk.Context, mtp *types.MTP, base } // convert custody amount to base currency - C, err := k.EstimateSwapGivenOut(ctx, takeProfitCustody, baseCurrency, ammPool) + C, err := k.EstimateSwap(ctx, takeProfitCustody, baseCurrency, ammPool) if err != nil { return sdk.ZeroInt(), err } diff --git a/x/margin/keeper/events.go b/x/margin/keeper/events.go index be3e0028a..fa70f06c8 100644 --- a/x/margin/keeper/events.go +++ b/x/margin/keeper/events.go @@ -1,6 +1,7 @@ package keeper import ( + "fmt" "strconv" sdk "github.com/cosmos/cosmos-sdk/types" @@ -20,16 +21,22 @@ func (k Keeper) EmitForceClose(ctx sdk.Context, mtp *types.MTP, repayAmount sdk. 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.CollateralAsset), - // sdk.NewAttribute("collateral_amount", mtp.CollateralAmount.String()), - // sdk.NewAttribute("custody_asset", mtp.CustodyAsset), - // sdk.NewAttribute("custody_amount", mtp.CustodyAmount.String()), + sdk.NewAttribute("collaterals", fmt.Sprintf("%s", mtp.Collaterals)), + sdk.NewAttribute("custodies", fmt.Sprintf("%s", mtp.Custodies)), sdk.NewAttribute("repay_amount", repayAmount.String()), - // sdk.NewAttribute("leverage", mtp.Leverage.String()), + sdk.NewAttribute("leverage", fmt.Sprintf("%s", mtp.Leverages)), sdk.NewAttribute("liabilities", mtp.Liabilities.String()), - // sdk.NewAttribute("borrow_interest_paid_collateral", mtp.BorrowInterestPaidCollateral.String()), - // sdk.NewAttribute("borrow_interest_paid_custody", mtp.BorrowInterestPaidCustody.String()), + sdk.NewAttribute("borrow_interest_paid_collaterals", fmt.Sprintf("%s", mtp.BorrowInterestPaidCollaterals)), + sdk.NewAttribute("borrow_interest_paid_custodies", fmt.Sprintf("%s", mtp.BorrowInterestPaidCustodies)), sdk.NewAttribute("health", mtp.MtpHealth.String()), sdk.NewAttribute("closer", closer), )) } + +func (k Keeper) EmitFundingFeePayment(ctx sdk.Context, mtp *types.MTP, takeAmount sdk.Int, takeAsset string, paymentType string) { + ctx.EventManager().EmitEvent(sdk.NewEvent(paymentType, + sdk.NewAttribute("id", strconv.FormatInt(int64(mtp.Id), 10)), + sdk.NewAttribute("payment_amount", takeAmount.String()), + sdk.NewAttribute("payment_asset", takeAsset), + )) +} diff --git a/x/margin/keeper/handle_borrow_interest_payment.go b/x/margin/keeper/handle_borrow_interest_payment.go index 047e85474..504eeb593 100644 --- a/x/margin/keeper/handle_borrow_interest_payment.go +++ b/x/margin/keeper/handle_borrow_interest_payment.go @@ -11,7 +11,7 @@ func (k Keeper) HandleBorrowInterestPayment(ctx sdk.Context, collateralAsset str incrementalBorrowInterestPaymentEnabled := k.GetIncrementalBorrowInterestPaymentEnabled(ctx) // if incremental payment on, pay interest if incrementalBorrowInterestPaymentEnabled { - finalBorrowInterestPayment, err := k.IncrementalBorrowInterestPayment(ctx, collateralAsset, custodyAsset, borrowInterestPayment, mtp, pool, ammPool) + finalBorrowInterestPayment, err := k.IncrementalBorrowInterestPayment(ctx, collateralAsset, custodyAsset, borrowInterestPayment, mtp, pool, ammPool, baseCurrency) if err != nil { ctx.Logger().Error(sdkerrors.Wrap(err, "error executing incremental borrow interest payment").Error()) } else { diff --git a/x/margin/keeper/handle_funding_fee_collection.go b/x/margin/keeper/handle_funding_fee_collection.go new file mode 100644 index 000000000..f4e624e3d --- /dev/null +++ b/x/margin/keeper/handle_funding_fee_collection.go @@ -0,0 +1,96 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + ammtypes "github.com/elys-network/elys/x/amm/types" + "github.com/elys-network/elys/x/margin/types" +) + +// HandleFundingFeeCollection handles funding fee collection +func (k Keeper) HandleFundingFeeCollection(ctx sdk.Context, mtp *types.MTP, pool *types.Pool, ammPool ammtypes.Pool, collateralAsset string, custodyAsset string) error { + // get funding rate + fundingRate := pool.FundingRate + + // if funding rate is zero, return + if fundingRate.IsZero() { + return nil + } + + // if funding rate is negative and mtp position is long or funding rate is positive and mtp position is short, return + if (fundingRate.IsNegative() && mtp.Position == types.Position_LONG) || (fundingRate.IsPositive() && mtp.Position == types.Position_SHORT) { + return nil + } + + // get indexes + collateralIndex, custodyIndex := types.GetMTPAssetIndex(mtp, collateralAsset, custodyAsset) + + // Calculate the take amount in custody asset + takeAmountCustody := types.CalcTakeAmount(mtp.Custodies[custodyIndex], custodyAsset, fundingRate) + + // Swap the take amount to collateral asset + takeAmountCollateralAmount, err := k.EstimateSwap(ctx, takeAmountCustody, collateralAsset, ammPool) + if err != nil { + return err + } + + // Create the take amount coin + takeAmountCollateral := sdk.NewCoin(collateralAsset, takeAmountCollateralAmount) + + // Get funding fee collection address + fundingFeeCollectionAddress := k.GetFundingFeeCollectionAddress(ctx) + + // Transfer take amount in collateral asset to funding fee collection address + _, err = k.TakeFundPayment(ctx, takeAmountCollateral.Amount, collateralAsset, sdk.OneDec(), fundingFeeCollectionAddress, &ammPool) + if err != nil { + return err + } + + // update mtp custody + mtp.Custodies[custodyIndex] = mtp.Custodies[custodyIndex].Sub(takeAmountCustody) + + // add payment to total funding fee paid in collateral asset + mtp.FundingFeePaidCollaterals[collateralIndex] = mtp.FundingFeePaidCollaterals[collateralIndex].Add(takeAmountCollateral) + + // add payment to total funding fee paid in custody asset + mtp.FundingFeePaidCustodies[custodyIndex] = mtp.FundingFeePaidCustodies[custodyIndex].Add(takeAmountCustody) + + // emit event + if !takeAmountCollateral.IsZero() { + k.EmitFundingFeePayment(ctx, mtp, takeAmountCustody.Amount, collateralAsset, types.EventIncrementalPayFund) + } + + // update pool custody balance + err = pool.UpdateCustody(ctx, custodyAsset, takeAmountCustody.Amount, false, mtp.Position) + if err != nil { + return err + } + + // update accounted balance for custody side + err = pool.UpdateBalance(ctx, custodyAsset, takeAmountCustody.Amount, false, mtp.Position) + if err != nil { + return err + } + + // update accounted balance for collateral side + err = pool.UpdateBalance(ctx, collateralAsset, takeAmountCollateral.Amount, false, mtp.Position) + if err != nil { + return err + } + + // apply changes to mtp object + err = k.SetMTP(ctx, mtp) + if err != nil { + return err + } + + // apply changes to pool object + k.SetPool(ctx, *pool) + + // update mtp health + _, err = k.UpdateMTPHealth(ctx, *mtp, ammPool, custodyAsset) + if err != nil { + return err + } + + return nil +} diff --git a/x/margin/keeper/handle_funding_fee_distribution.go b/x/margin/keeper/handle_funding_fee_distribution.go new file mode 100644 index 000000000..279da9ba4 --- /dev/null +++ b/x/margin/keeper/handle_funding_fee_distribution.go @@ -0,0 +1,98 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + ammtypes "github.com/elys-network/elys/x/amm/types" + "github.com/elys-network/elys/x/margin/types" +) + +// HandleFundingFeeDistribution handles funding fee distribution +func (k Keeper) HandleFundingFeeDistribution(ctx sdk.Context, mtps []*types.MTP, pool *types.Pool, ammPool ammtypes.Pool, baseCurrency string) error { + // get funding rate + fundingRate := pool.FundingRate + + // if funding rate is zero, return + if fundingRate.IsZero() { + return nil + } + + // account liabilities from long position + liabilitiesLong := sdk.ZeroInt() + for _, asset := range pool.PoolAssetsLong { + liabilitiesLong = liabilitiesLong.Add(asset.Liabilities) + } + + // account liabilities from short position + liabilitiesShort := sdk.ZeroInt() + for _, asset := range pool.PoolAssetsShort { + liabilitiesShort = liabilitiesShort.Add(asset.Liabilities) + } + + // get funding fee collection address + fundingFeeCollectionAddress := k.GetFundingFeeCollectionAddress(ctx) + + // get base currency balance + balance := k.bankKeeper.GetBalance(ctx, fundingFeeCollectionAddress, baseCurrency) + + // if balance is zero, return + if balance.IsZero() { + return nil + } + + for _, mtp := range mtps { + // if funding rate is negative and mtp position is short or funding rate is positive and mtp position is long, return + if (fundingRate.IsNegative() && mtp.Position == types.Position_SHORT) || (fundingRate.IsPositive() && mtp.Position == types.Position_LONG) { + return nil + } + + // get mtp address + mtpAddress, err := sdk.AccAddressFromBech32(mtp.Address) + if err != nil { + return err + } + + // calc funding fee share + fundingFeeShare := sdk.ZeroDec() + if fundingRate.IsNegative() && mtp.Position == types.Position_LONG { + fundingFeeShare = sdk.NewDecFromInt(mtp.Liabilities).Quo(sdk.NewDecFromInt(liabilitiesLong)) + } + if fundingRate.IsPositive() && mtp.Position == types.Position_SHORT { + fundingFeeShare = sdk.NewDecFromInt(mtp.Liabilities).Quo(sdk.NewDecFromInt(liabilitiesShort)) + } + + // if funding fee share is zero, skip mtp + if fundingFeeShare.IsZero() { + continue + } + + // calculate funding fee amount + fundingFeeAmount := sdk.NewCoin(baseCurrency, sdk.NewDecFromInt(balance.Amount).Mul(fundingFeeShare).TruncateInt()) + + // transfer funding fee amount to mtp address + if err := k.bankKeeper.SendCoins(ctx, fundingFeeCollectionAddress, mtpAddress, sdk.NewCoins(fundingFeeAmount)); err != nil { + return err + } + + // update received funding fee accounting buckets + for custodyIndex, _ := range mtp.Custodies { + for collateralIndex, collateral := range mtp.Collaterals { + // Swap the take amount to collateral asset + fundingFeeCollateralAmount, err := k.EstimateSwap(ctx, fundingFeeAmount, collateral.Denom, ammPool) + if err != nil { + return err + } + + // Create the take amount coin + fundingFeeCollateral := sdk.NewCoin(collateral.Denom, fundingFeeCollateralAmount) + + // add payment to total funding fee paid in collateral asset + mtp.FundingFeeReceivedCollaterals[collateralIndex] = mtp.FundingFeePaidCollaterals[collateralIndex].Add(fundingFeeCollateral) + + // add payment to total funding fee paid in custody asset + mtp.FundingFeeReceivedCustodies[custodyIndex] = mtp.FundingFeePaidCustodies[custodyIndex].Add(fundingFeeAmount) + } + } + } + + return nil +} diff --git a/x/margin/keeper/keeper.go b/x/margin/keeper/keeper.go index d2bb0d7f4..731996947 100644 --- a/x/margin/keeper/keeper.go +++ b/x/margin/keeper/keeper.go @@ -295,15 +295,9 @@ func (k Keeper) TakeInCustody(ctx sdk.Context, mtp types.MTP, pool *types.Pool) return nil } -func (k Keeper) IncrementalBorrowInterestPayment(ctx sdk.Context, collateralAsset string, custodyAsset string, borrowInterestPayment sdk.Int, mtp *types.MTP, pool *types.Pool, ammPool ammtypes.Pool) (sdk.Int, error) { +func (k Keeper) IncrementalBorrowInterestPayment(ctx sdk.Context, collateralAsset string, custodyAsset string, borrowInterestPayment sdk.Int, mtp *types.MTP, pool *types.Pool, ammPool ammtypes.Pool, baseCurrency string) (sdk.Int, error) { collateralIndex, custodyIndex := types.GetMTPAssetIndex(mtp, collateralAsset, custodyAsset) - entry, found := k.apKeeper.GetEntry(ctx, ptypes.BaseCurrency) - if !found { - return sdk.ZeroInt(), sdkerrors.Wrapf(assetprofiletypes.ErrAssetProfileNotFound, "asset %s not found", ptypes.BaseCurrency) - } - baseCurrency := entry.Denom - // if mtp has unpaid borrow interest, add to payment // convert it into base currency if mtp.BorrowInterestUnpaidCollaterals[collateralIndex].Amount.GT(sdk.ZeroInt()) { diff --git a/x/margin/keeper/open_short_process.go b/x/margin/keeper/open_short_process.go index 2581f5adc..857c6eaa1 100644 --- a/x/margin/keeper/open_short_process.go +++ b/x/margin/keeper/open_short_process.go @@ -69,6 +69,8 @@ func (k Keeper) ProcessOpenShort(ctx sdk.Context, mtp *types.MTP, leverage sdk.D mtp.Custodies = []sdk.Coin{sdk.NewCoin(baseCurrency, sdk.NewInt(0))} mtp.BorrowInterestPaidCustodies = []sdk.Coin{sdk.NewCoin(baseCurrency, sdk.NewInt(0))} mtp.TakeProfitCustodies = []sdk.Coin{sdk.NewCoin(baseCurrency, sdk.NewInt(0))} + mtp.FundingFeePaidCustodies = []sdk.Coin{sdk.NewCoin(baseCurrency, sdk.NewInt(0))} + mtp.FundingFeeReceivedCustodies = []sdk.Coin{sdk.NewCoin(baseCurrency, sdk.NewInt(0))} } // Borrow the asset the user wants to short. diff --git a/x/margin/keeper/params.go b/x/margin/keeper/params.go index e28b7a425..fc6718d74 100644 --- a/x/margin/keeper/params.go +++ b/x/margin/keeper/params.go @@ -155,3 +155,24 @@ func (k Keeper) GetBrokerAddress(ctx sdk.Context) sdk.AccAddress { func (k Keeper) GetTakeProfitBorrowInterestRateMin(ctx sdk.Context) sdk.Dec { return k.GetParams(ctx).TakeProfitBorrowInterestRateMin } + +func (k Keeper) GetFundingFeeBaseRate(ctx sdk.Context) sdk.Dec { + return k.GetParams(ctx).FundingFeeBaseRate +} + +func (k Keeper) GetFundingFeeMaxRate(ctx sdk.Context) sdk.Dec { + return k.GetParams(ctx).FundingFeeMaxRate +} + +func (k Keeper) GetFundingFeeMinRate(ctx sdk.Context) sdk.Dec { + return k.GetParams(ctx).FundingFeeMinRate +} + +func (k Keeper) GetFundingFeeCollectionAddress(ctx sdk.Context) sdk.AccAddress { + addr, err := sdk.AccAddressFromBech32(k.GetParams(ctx).FundingFeeCollectionAddress) + if err != nil { + panic(err) + } + + return addr +} diff --git a/x/margin/keeper/update_funding_rate.go b/x/margin/keeper/update_funding_rate.go new file mode 100644 index 000000000..b25aadf2e --- /dev/null +++ b/x/margin/keeper/update_funding_rate.go @@ -0,0 +1,30 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/elys-network/elys/x/margin/types" +) + +// UpdateFundingRate updates the funding rate of a pool +func (k Keeper) UpdateFundingRate(ctx sdk.Context, pool *types.Pool) error { + poolAssetsLong := pool.GetPoolAssets(types.Position_LONG) + poolAssetsShort := pool.GetPoolAssets(types.Position_SHORT) + + liabilitiesLong := sdk.ZeroInt() + for _, asset := range *poolAssetsLong { + liabilitiesLong = liabilitiesLong.Add(asset.Liabilities) + } + + liabilitiesShort := sdk.ZeroInt() + for _, asset := range *poolAssetsShort { + liabilitiesShort = liabilitiesShort.Add(asset.Liabilities) + } + + // get params + params := k.GetParams(ctx) + + // calculate and update funding fee + pool.FundingRate = types.CalcFundingRate(liabilitiesLong, liabilitiesShort, params.FundingFeeBaseRate, params.FundingFeeMaxRate, params.FundingFeeMinRate) + + return nil +} diff --git a/x/margin/types/calc_funding_rate.go b/x/margin/types/calc_funding_rate.go new file mode 100644 index 000000000..3697c661c --- /dev/null +++ b/x/margin/types/calc_funding_rate.go @@ -0,0 +1,21 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// CalculateFundingRate calculates and returns the funding rate based on long and short amounts +func CalcFundingRate(longAmount, shortAmount sdk.Int, baseRate, maxRate, minRate sdk.Dec) sdk.Dec { + var ratio sdk.Dec + + if longAmount.GT(shortAmount) { + ratio = sdk.NewDecFromInt(longAmount).Quo(sdk.NewDecFromInt(shortAmount)) + return sdk.MinDec(sdk.MaxDec(baseRate.Mul(ratio), minRate), maxRate) + } else if shortAmount.GT(longAmount) { + ratio = sdk.NewDecFromInt(shortAmount).Quo(sdk.NewDecFromInt(longAmount)) + return sdk.MinDec(sdk.MaxDec(baseRate.Mul(ratio).Neg(), minRate), maxRate) + } else { + // In case of exact equality, return the base rate + return baseRate + } +} diff --git a/x/margin/types/calc_funding_rate_test.go b/x/margin/types/calc_funding_rate_test.go new file mode 100644 index 000000000..b28804926 --- /dev/null +++ b/x/margin/types/calc_funding_rate_test.go @@ -0,0 +1,55 @@ +package types_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + types "github.com/elys-network/elys/x/margin/types" + "github.com/stretchr/testify/assert" +) + +func TestCalculateFundingRate(t *testing.T) { + baseRate := sdk.NewDecWithPrec(3, 4) // 0.03% + maxRate := sdk.NewDecWithPrec(1, 3) // 0.1% + minRate := sdk.NewDecWithPrec(-1, 3) // -0.1% + + // Test cases + tests := []struct { + name string + longAmount sdk.Int + shortAmount sdk.Int + expectedRate string + }{ + { + name: "Longs More Leveraged", + longAmount: sdk.NewInt(1000000), + shortAmount: sdk.NewInt(500000), + expectedRate: "0.000600000000000000", + }, + { + name: "Shorts More Leveraged", + longAmount: sdk.NewInt(500000), + shortAmount: sdk.NewInt(1000000), + expectedRate: "-0.000600000000000000", + }, + { + name: "Balanced Leveraging", + longAmount: sdk.NewInt(750000), + shortAmount: sdk.NewInt(750000), + expectedRate: "0.000300000000000000", + }, + { + name: "Extreme Long Leverage", + longAmount: sdk.NewInt(2000000), + shortAmount: sdk.NewInt(500000), + expectedRate: "0.001000000000000000", // Capped at maxRate + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actualRate := types.CalcFundingRate(tt.longAmount, tt.shortAmount, baseRate, maxRate, minRate) + assert.Equal(t, tt.expectedRate, actualRate.String()) + }) + } +} diff --git a/x/margin/types/calc_take_amount.go b/x/margin/types/calc_take_amount.go new file mode 100644 index 000000000..7026dca0c --- /dev/null +++ b/x/margin/types/calc_take_amount.go @@ -0,0 +1,18 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// CalcTakeAmount calculates the take amount in the custody asset based on the funding rate +func CalcTakeAmount(custodyAmount sdk.Coin, custodyAsset string, fundingRate sdk.Dec) sdk.Coin { + absoluteFundingRate := fundingRate.Abs() + + // Calculate the take amount + takeAmountValue := sdk.NewDecFromInt(custodyAmount.Amount).Mul(absoluteFundingRate).TruncateInt() + + // Create the take amount coin + takeAmount := sdk.NewCoin(custodyAsset, takeAmountValue) + + return takeAmount +} diff --git a/x/margin/types/params.go b/x/margin/types/params.go index 3db7d727f..55bda3b7a 100644 --- a/x/margin/types/params.go +++ b/x/margin/types/params.go @@ -11,6 +11,10 @@ import ( var _ paramtypes.ParamSet = (*Params)(nil) +const ( + ZeroAddress = "elys1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnrec2l" +) + var ( KeyLeverageMax = []byte("LeverageMax") KeyBorrowInterestRateMax = []byte("BorrowInterestRateMax") @@ -33,6 +37,10 @@ var ( KeyInvariantCheckEpoch = []byte("InvariantCheckEpoch") KeyBrokerAddress = []byte("BrokerAddress") KeyTakeProfitBorrowInterestRateMin = []byte("TakeProfitBorrowInterestRateMin") + KeyFundingFeeBaseRate = []byte("FundingFeeBaseRate") + KeyFundingFeeMinRate = []byte("FundingFeeMinRate") + KeyFundingFeeMaxRate = []byte("FundingFeeMaxRate") + KeyFundingFeeCollectionAddress = []byte("FundingFeeCollectionAddress") ) // ParamKeyTable the param key table for launch module @@ -43,26 +51,30 @@ func ParamKeyTable() paramtypes.KeyTable { // NewParams creates a new Params instance func NewParams() Params { return Params{ + FundingFeeCollectionAddress: ZeroAddress, + FundingFeeMinRate: sdk.NewDecWithPrec(-1, 3), // -0.1% + FundingFeeMaxRate: sdk.NewDecWithPrec(1, 3), // 0.1% + FundingFeeBaseRate: sdk.NewDecWithPrec(3, 4), // 0.03% TakeProfitBorrowInterestRateMin: sdk.OneDec(), - BorrowInterestRateDecrease: sdk.MustNewDecFromStr("0.000000000333333333"), - BorrowInterestRateIncrease: sdk.MustNewDecFromStr("0.000000000333333333"), - BorrowInterestRateMax: sdk.MustNewDecFromStr("0.000000270000000000"), - BorrowInterestRateMin: sdk.MustNewDecFromStr("0.000000030000000000"), - BrokerAddress: "elys1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnrec2l", + BorrowInterestRateDecrease: sdk.NewDecWithPrec(33, 10), + BorrowInterestRateIncrease: sdk.NewDecWithPrec(33, 10), + BorrowInterestRateMax: sdk.NewDecWithPrec(27, 7), + BorrowInterestRateMin: sdk.NewDecWithPrec(3, 8), + BrokerAddress: ZeroAddress, EpochLength: (int64)(1), - ForceCloseFundAddress: "elys1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnrec2l", + ForceCloseFundAddress: ZeroAddress, ForceCloseFundPercentage: sdk.OneDec(), - HealthGainFactor: sdk.MustNewDecFromStr("0.000000022000000000"), + HealthGainFactor: sdk.NewDecWithPrec(22, 8), IncrementalBorrowInterestPaymentEnabled: true, - IncrementalBorrowInterestPaymentFundAddress: "elys1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnrec2l", - IncrementalBorrowInterestPaymentFundPercentage: sdk.MustNewDecFromStr("0.350000000000000000"), + IncrementalBorrowInterestPaymentFundAddress: ZeroAddress, + IncrementalBorrowInterestPaymentFundPercentage: sdk.NewDecWithPrec(35, 1), // 35% InvariantCheckEpoch: epochtypes.DayEpochID, LeverageMax: sdk.NewDec(10), MaxOpenPositions: (int64)(9999), PoolOpenThreshold: sdk.OneDec(), - RemovalQueueThreshold: sdk.MustNewDecFromStr("0.350000000000000000"), - SafetyFactor: sdk.MustNewDecFromStr("1.050000000000000000"), - SqModifier: sdk.MustNewDecFromStr("10000000000000000000000000.000000000000000000"), + RemovalQueueThreshold: sdk.NewDecWithPrec(35, 1), // 35% + SafetyFactor: sdk.MustNewDecFromStr("1.050000000000000000"), // 5% + SqModifier: sdk.MustNewDecFromStr("10000000000000000000000000"), WhitelistingEnabled: false, } } @@ -96,6 +108,10 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { paramtypes.NewParamSetPair(KeyInvariantCheckEpoch, &p.InvariantCheckEpoch, validateInvariantCheckEpoch), paramtypes.NewParamSetPair(KeyBrokerAddress, &p.BrokerAddress, validateBrokerAddress), paramtypes.NewParamSetPair(KeyTakeProfitBorrowInterestRateMin, &p.TakeProfitBorrowInterestRateMin, validateTakeProfitBorrowInterestRateMin), + paramtypes.NewParamSetPair(KeyFundingFeeBaseRate, &p.FundingFeeBaseRate, validateBorrowInterestRateMax), + paramtypes.NewParamSetPair(KeyFundingFeeMinRate, &p.FundingFeeMinRate, validateBorrowInterestRateMax), + paramtypes.NewParamSetPair(KeyFundingFeeMaxRate, &p.FundingFeeMaxRate, validateBorrowInterestRateMax), + paramtypes.NewParamSetPair(KeyFundingFeeCollectionAddress, &p.FundingFeeCollectionAddress, validateFundingFeeCollectionAddress), } } @@ -164,6 +180,18 @@ func (p Params) Validate() error { if err := validateTakeProfitBorrowInterestRateMin(p.TakeProfitBorrowInterestRateMin); err != nil { return err } + if err := validateFundingFeeBaseRate(p.FundingFeeBaseRate); err != nil { + return err + } + if err := validateFundingFeeMinRate(p.FundingFeeMinRate); err != nil { + return err + } + if err := validateFundingFeeMaxRate(p.FundingFeeMaxRate); err != nil { + return err + } + if err := validateFundingFeeCollectionAddress(p.FundingFeeCollectionAddress); err != nil { + return err + } return nil } @@ -458,3 +486,57 @@ func validateTakeProfitBorrowInterestRateMin(i interface{}) error { return nil } + +func validateFundingFeeBaseRate(i interface{}) error { + v, ok := i.(sdk.Dec) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + if v.IsNil() { + return fmt.Errorf("funding fee base rate must be not nil") + } + if v.IsNegative() { + return fmt.Errorf("funding fee base rate must be positive: %s", v) + } + + return nil +} + +func validateFundingFeeMinRate(i interface{}) error { + v, ok := i.(sdk.Dec) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + if v.IsNil() { + return fmt.Errorf("funding fee min rate must be not nil") + } + if v.IsPositive() { + return fmt.Errorf("funding fee min rate must be negative: %s", v) + } + + return nil +} + +func validateFundingFeeMaxRate(i interface{}) error { + v, ok := i.(sdk.Dec) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + if v.IsNil() { + return fmt.Errorf("funding fee max rate must be not nil") + } + if v.IsNegative() { + return fmt.Errorf("funding fee max rate must be positive: %s", v) + } + + return nil +} + +func validateFundingFeeCollectionAddress(i interface{}) error { + _, ok := i.(string) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + return nil +} diff --git a/x/margin/types/params.pb.go b/x/margin/types/params.pb.go index b0dfb8c34..b1108ee24 100644 --- a/x/margin/types/params.pb.go +++ b/x/margin/types/params.pb.go @@ -47,6 +47,10 @@ type Params struct { InvariantCheckEpoch string `protobuf:"bytes,19,opt,name=invariant_check_epoch,json=invariantCheckEpoch,proto3" json:"invariant_check_epoch,omitempty"` BrokerAddress string `protobuf:"bytes,20,opt,name=broker_address,json=brokerAddress,proto3" json:"broker_address,omitempty"` TakeProfitBorrowInterestRateMin github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,21,opt,name=take_profit_borrow_interest_rate_min,json=takeProfitBorrowInterestRateMin,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"take_profit_borrow_interest_rate_min"` + FundingFeeBaseRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,22,opt,name=funding_fee_base_rate,json=fundingFeeBaseRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"funding_fee_base_rate"` + FundingFeeMaxRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,23,opt,name=funding_fee_max_rate,json=fundingFeeMaxRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"funding_fee_max_rate"` + FundingFeeMinRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,24,opt,name=funding_fee_min_rate,json=fundingFeeMinRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"funding_fee_min_rate"` + FundingFeeCollectionAddress string `protobuf:"bytes,25,opt,name=funding_fee_collection_address,json=fundingFeeCollectionAddress,proto3" json:"funding_fee_collection_address,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -137,6 +141,13 @@ func (m *Params) GetBrokerAddress() string { return "" } +func (m *Params) GetFundingFeeCollectionAddress() string { + if m != nil { + return m.FundingFeeCollectionAddress + } + return "" +} + func init() { proto.RegisterType((*Params)(nil), "elys.margin.Params") } @@ -144,52 +155,57 @@ func init() { func init() { proto.RegisterFile("elys/margin/params.proto", fileDescriptor_f427d3667a99d828) } var fileDescriptor_f427d3667a99d828 = []byte{ - // 712 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x95, 0x4b, 0x4f, 0x2b, 0x37, - 0x14, 0x80, 0x33, 0x85, 0x52, 0x70, 0x02, 0x05, 0x87, 0xa8, 0x16, 0x55, 0x13, 0x5a, 0xf5, 0x81, - 0x44, 0x49, 0xda, 0xb2, 0xa8, 0xd4, 0x5d, 0xc3, 0xa3, 0x42, 0x2a, 0x22, 0xa4, 0x5d, 0x55, 0xa8, - 0x96, 0x33, 0x73, 0x32, 0x63, 0x65, 0xc6, 0x9e, 0xd8, 0x0e, 0x24, 0x8b, 0xfe, 0x87, 0x2e, 0x2b, - 0x75, 0xd3, 0x9f, 0xc3, 0xaa, 0x62, 0x79,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0xc3, 0x06, 0x40, 0x63, 0x25, - 0xfb, 0xdc, 0xd0, 0x27, 0x1b, 0x42, 0xad, 0xd0, 0xbe, 0x36, 0x12, 0x76, 0xc7, 0xa2, 0xdb, 0x8f, - 0xb5, 0x86, 0x9f, 0x66, 0xff, 0xf9, 0xaf, 0x51, 0x6a, 0xef, 0x9d, 0x5f, 0xd5, 0x9d, 0x8b, 0xab, - 0xba, 0xf3, 0xe6, 0xaa, 0xee, 0xfc, 0x7d, 0x5d, 0x2f, 0x5d, 0x5c, 0xd7, 0x4b, 0xaf, 0xae, 0xeb, - 0xa5, 0x3f, 0x36, 0x6f, 0x89, 0x92, 0xc6, 0xbc, 0x25, 0xc0, 0x9c, 0x49, 0x35, 0xb0, 0x1f, 0xad, - 0x71, 0xde, 0xc1, 0xad, 0xb1, 0x37, 0x67, 0xdb, 0xf3, 0xf6, 0xdb, 0x00, 0x00, 0x00, 0xff, 0xff, - 0xb8, 0x3a, 0x22, 0x04, 0xdd, 0x07, 0x00, 0x00, + // 798 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x96, 0x4f, 0x6f, 0x1b, 0x45, + 0x14, 0xc0, 0xbd, 0xb4, 0x84, 0x76, 0xec, 0x94, 0x64, 0x6c, 0xd3, 0xa1, 0x15, 0x76, 0x40, 0xfc, + 0x89, 0x14, 0x6a, 0x03, 0x3d, 0x20, 0x71, 0xc3, 0x6e, 0x82, 0x2a, 0x11, 0xd5, 0x35, 0x9c, 0x50, + 0xc5, 0x68, 0xbc, 0xfb, 0x76, 0x77, 0xe4, 0xdd, 0x99, 0xf5, 0xcc, 0x38, 0xb1, 0x0f, 0x7c, 0x07, + 0x8e, 0x48, 0x5c, 0xf8, 0x18, 0x7c, 0x84, 0x1e, 0x7b, 0x44, 0x1c, 0x2a, 0x94, 0x7c, 0x11, 0x34, + 0xb3, 0xbb, 0xb6, 0xdb, 0xa4, 0x10,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 0x84, 0x63, 0x60, 0x89, + 0x89, 0x69, 0xc4, 0xb8, 0xa0, 0x21, 0xf3, 0x8d, 0x54, 0x64, 0xab, 0x92, 0x67, 0x27, 0x27, 0x7d, + 0xc7, 0xb8, 0x38, 0x72, 0x1c, 0xfc, 0x21, 0x6a, 0x40, 0x26, 0xfd, 0x98, 0x26, 0x20, 0x22, 0x13, + 0x93, 0x77, 0xf6, 0xbc, 0xfd, 0x6b, 0xe3, 0xba, 0x1b, 0xfb, 0xde, 0x0d, 0xe1, 0x10, 0xdd, 0x56, + 0x90, 0xca, 0x13, 0x96, 0xd0, 0xd9, 0x1c, 0xe6, 0x40, 0x4d, 0xac, 0x40, 0xc7, 0x32, 0x09, 0xc8, + 0x8d, 0x6a, 0xed, 0x2c, 0x70, 0x8f, 0x2d, 0xed, 0xc7, 0x12, 0x86, 0x3f, 0x47, 0x38, 0x65, 0x0b, + 0x2a, 0x33, 0x10, 0x34, 0x93, 0x9a, 0x1b, 0x2e, 0x85, 0x26, 0x37, 0x5d, 0x42, 0x3b, 0x29, 0x5b, + 0x3c, 0xca, 0x40, 0x8c, 0xca, 0x71, 0xfc, 0x33, 0x6a, 0x66, 0x52, 0x26, 0xf9, 0xf4, 0x75, 0x46, + 0xa8, 0x52, 0x46, 0xbb, 0x16, 0x65, 0xf9, 0xeb, 0x6c, 0x52, 0x74, 0x37, 0x94, 0xca, 0x07, 0xea, + 0x27, 0x52, 0x03, 0x0d, 0xe7, 0x22, 0xa0, 0x19, 0x28, 0x1f, 0x84, 0x61, 0x11, 0x90, 0x7a, 0x25, + 0x0f, 0x71, 0xc8, 0xa1, 0x25, 0x1e, 0xcd, 0x45, 0x30, 0x5a, 0xf1, 0xf0, 0xd7, 0x88, 0x5c, 0xd0, + 0xb1, 0x20, 0x50, 0xa0, 0x35, 0x69, 0x58, 0xd7, 0xb8, 0xfd, 0xe2, 0xda, 0x6f, 0xf3, 0x20, 0xfe, + 0xdd, 0x43, 0xf7, 0xdd, 0x81, 0x4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 0x84, 0x76, 0xa5, 0x7d, 0xed, + 0x5a, 0xf6, 0xc8, 0xa1, 0x07, 0x97, 0x7e, 0x1a, 0x18, 0x6a, 0xdb, 0x33, 0x65, 0xf7, 0x21, 0x04, + 0xa0, 0x13, 0xa6, 0xc1, 0x39, 0xc9, 0x7b, 0x95, 0x7c, 0xb8, 0x80, 0x1d, 0x01, 0x0c, 0x98, 0x06, + 0x6b, 0xc1, 0x14, 0xb5, 0x36, 0x15, 0xf6, 0xd5, 0xe5, 0x0c, 0xb7, 0xab, 0xbd, 0x81, 0xd6, 0x86, + 0x63, 0xb6, 0xb8, 0x54, 0xc0, 0x45, 0x2e, 0x20, 0xaf, 0x2d, 0xe0, 0xc2, 0x09, 0x86, 0xa8, 0xb3, + 0x29, 0xf0, 0x65, 0x92, 0x80, 0x6f, 0xdf, 0xae, 0xab, 0xd6, 0xbe, 0xef, 0x5a, 0x7b, 0x77, 0xbd, + 0x74, 0xb8, 0x9a, 0x53, 0x34, 0xfa, 0x9b, 0xeb, 0xbf, 0xfd, 0xd1, 0xad, 0x0d, 0x0e, 0x9f, 0x9e, + 0x75, 0xbc, 0x67, 0x67, 0x1d, 0xef, 0x9f, 0xb3, 0x8e, 0xf7, 0xeb, 0x79, 0xa7, 0xf6, 0xec, 0xbc, + 0x53, 0xfb, 0xeb, 0xbc, 0x53, 0xfb, 0xe9, 0x60, 0x23, 0x3f, 0x7b, 0x05, 0xba, 0x27, 0xc0, 0x9c, + 0x4a, 0x35, 0x75, 0x3f, 0xfa, 0x8b, 0xf2, 0xae, 0xe4, 0x12, 0x9d, 0x6c, 0xb9, 0x8b, 0xd0, 0xfd, + 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x55, 0x81, 0xfd, 0x84, 0x47, 0x09, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -212,6 +228,51 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.FundingFeeCollectionAddress) > 0 { + i -= len(m.FundingFeeCollectionAddress) + copy(dAtA[i:], m.FundingFeeCollectionAddress) + i = encodeVarintParams(dAtA, i, uint64(len(m.FundingFeeCollectionAddress))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xca + } + { + size := m.FundingFeeMinRate.Size() + i -= size + if _, err := m.FundingFeeMinRate.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xc2 + { + size := m.FundingFeeMaxRate.Size() + i -= size + if _, err := m.FundingFeeMaxRate.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xba + { + size := m.FundingFeeBaseRate.Size() + i -= size + if _, err := m.FundingFeeBaseRate.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xb2 { size := m.TakeProfitBorrowInterestRateMin.Size() i -= size @@ -486,6 +547,16 @@ func (m *Params) Size() (n int) { } l = m.TakeProfitBorrowInterestRateMin.Size() n += 2 + l + sovParams(uint64(l)) + l = m.FundingFeeBaseRate.Size() + n += 2 + l + sovParams(uint64(l)) + l = m.FundingFeeMaxRate.Size() + n += 2 + l + sovParams(uint64(l)) + l = m.FundingFeeMinRate.Size() + n += 2 + l + sovParams(uint64(l)) + l = len(m.FundingFeeCollectionAddress) + if l > 0 { + n += 2 + l + sovParams(uint64(l)) + } return n } @@ -1172,6 +1243,140 @@ func (m *Params) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 22: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FundingFeeBaseRate", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + 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 ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.FundingFeeBaseRate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 23: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FundingFeeMaxRate", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + 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 ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.FundingFeeMaxRate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 24: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FundingFeeMinRate", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + 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 ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.FundingFeeMinRate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 25: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FundingFeeCollectionAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + 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 ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FundingFeeCollectionAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/x/margin/types/pool.go b/x/margin/types/pool.go index 4f5c59c7c..458f8551c 100644 --- a/x/margin/types/pool.go +++ b/x/margin/types/pool.go @@ -8,13 +8,15 @@ import ( func NewPool(poolId uint64) Pool { return Pool{ - AmmPoolId: poolId, - Health: sdk.NewDec(100), - Enabled: true, - Closed: false, - BorrowInterestRate: sdk.NewDecFromIntWithPrec(sdk.NewInt(1), 1), - PoolAssetsLong: []PoolAsset{}, - PoolAssetsShort: []PoolAsset{}, + AmmPoolId: poolId, + Health: sdk.NewDec(100), + Enabled: true, + Closed: false, + BorrowInterestRate: sdk.NewDecFromIntWithPrec(sdk.NewInt(1), 1), + PoolAssetsLong: []PoolAsset{}, + PoolAssetsShort: []PoolAsset{}, + LastHeightBorrowInterestRateComputed: 0, + FundingRate: sdk.ZeroDec(), } } diff --git a/x/margin/types/pool.pb.go b/x/margin/types/pool.pb.go index 3c18a2b62..fe4596b7a 100644 --- a/x/margin/types/pool.pb.go +++ b/x/margin/types/pool.pb.go @@ -83,6 +83,8 @@ type Pool struct { PoolAssetsLong []PoolAsset `protobuf:"bytes,6,rep,name=pool_assets_long,json=poolAssetsLong,proto3" json:"pool_assets_long"` PoolAssetsShort []PoolAsset `protobuf:"bytes,7,rep,name=pool_assets_short,json=poolAssetsShort,proto3" json:"pool_assets_short"` LastHeightBorrowInterestRateComputed int64 `protobuf:"varint,8,opt,name=last_height_borrow_interest_rate_computed,json=lastHeightBorrowInterestRateComputed,proto3" json:"last_height_borrow_interest_rate_computed,omitempty"` + // funding rate, if positive longs pay shorts, if negative shorts pay longs + FundingRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,9,opt,name=funding_rate,json=fundingRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"funding_rate"` } func (m *Pool) Reset() { *m = Pool{} } @@ -168,41 +170,42 @@ func init() { func init() { proto.RegisterFile("elys/margin/pool.proto", fileDescriptor_030dd771f91c2bb4) } var fileDescriptor_030dd771f91c2bb4 = []byte{ - // 541 bytes of a gzipped FileDescriptorProto + // 559 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xcb, 0x6e, 0xd3, 0x4c, - 0x14, 0xc7, 0xe3, 0x2f, 0xf9, 0x72, 0x99, 0x70, 0xeb, 0xb4, 0x0d, 0x16, 0x0b, 0x27, 0xaa, 0x10, - 0x0a, 0x42, 0xb5, 0x25, 0x78, 0x02, 0xdc, 0x52, 0x25, 0x52, 0x17, 0x91, 0xbb, 0x40, 0x62, 0xc1, - 0x30, 0xb6, 0xa7, 0xb6, 0x95, 0xb1, 0x8f, 0xe5, 0x99, 0xa8, 0xe4, 0x2d, 0x78, 0xac, 0xb2, 0xeb, - 0x12, 0xb1, 0xa8, 0x50, 0xb2, 0xe6, 0x1d, 0xd0, 0x4c, 0x6c, 0x6a, 0x2e, 0x0b, 0xe4, 0x55, 0x32, - 0xc7, 0x73, 0x7e, 0xe7, 0x7f, 0xfe, 0x73, 0x66, 0xd0, 0x88, 0xf1, 0xb5, 0x70, 0x52, 0x5a, 0x44, - 0x49, 0xe6, 0xe4, 0x00, 0xdc, 0xce, 0x0b, 0x90, 0x80, 0x87, 0x2a, 0x6e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82, 0x2c, 0x9e, 0xd1, 0x30, 0xe3, 0x99, 0xcc, 0x98, 0xb0, 0x8d, 0x81, + 0x31, 0xec, 0xfb, 0xee, 0xf5, 0xed, 0x51, 0xe7, 0xdb, 0xed, 0xd1, 0xd3, 0x24, 0x93, 0xe9, 0x3c, + 0x74, 0x23, 0xc8, 0xbd, 0x08, 0x44, 0x0e, 0xa2, 0xfe, 0x39, 0x11, 0xf1, 0xcc, 0x93, 0x8b, 0x92, + 0x09, 0x77, 0x5c, 0xc8, 0xa0, 0x89, 0xc0, 0x23, 0xd4, 0x8b, 0xe6, 0x42, 0x42, 0xbc, 0xb0, 0xff, + 0x6b, 0x45, 0xdb, 0x84, 0xe3, 0x29, 0x7a, 0x24, 0xe9, 0x8c, 0x91, 0xb2, 0x82, 0x69, 0x26, 0x49, + 0xb3, 0xce, 0xad, 0x56, 0xe4, 0x03, 0x85, 0x9b, 0x68, 0xda, 0x45, 0xa3, 0xe2, 0xf7, 0x68, 0xaf, + 0x99, 0x67, 0x53, 0xbd, 0xd9, 0x2a, 0xc7, 0xee, 0x5d, 0x8e, 0xd3, 0xba, 0x8f, 0x4b, 0x74, 0x8f, + 0x2a, 0xb3, 0x49, 0x48, 0x39, 0x2d, 0x22, 0x66, 0xff, 0xdf, 0x8a, 0xbc, 0xa3, 0x21, 0xfe, 0x9a, + 0x81, 0x43, 0x74, 0x10, 0x72, 0x88, 0x66, 0x24, 0x84, 0xaa, 0x82, 0x2b, 0x92, 0x15, 0x92, 0x55, + 0x4c, 0x48, 0xbb, 0xdb, 0x0a, 0xbe, 0xa7, 0x61, 0xbe, 0x66, 0x8d, 0x6b, 0x14, 0x3e, 0x42, 0xd6, + 0xba, 0xf0, 0x98, 0x15, 0x90, 0xdb, 0x3d, 0x45, 0x0e, 0x90, 0x96, 0xce, 0x94, 0x72, 0xfc, 0xd9, + 0x44, 0xa6, 0x9a, 0x25, 0xec, 0x20, 0x8b, 0xe6, 0x39, 0x51, 0x93, 0x48, 0xb2, 0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, 0x2f, 0x1d, 0xe3, 0x66, 0xe9, 0x18, 0xdf, 0x97, 0x8e, 0xf1, 0x69, 0xe5, + 0x74, 0x6e, 0x56, 0x4e, 0xe7, 0xeb, 0xca, 0xe9, 0xbc, 0x7b, 0xde, 0xc0, 0xa9, 0xf6, 0x4f, 0x0a, + 0x26, 0xaf, 0xa0, 0x9a, 0xe9, 0x85, 0xf7, 0x71, 0xf3, 0xfa, 0x69, 0x6e, 0xd8, 0xd5, 0x8f, 0xdb, + 0xcb, 0x1f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe1, 0xa8, 0x24, 0xe9, 0x19, 0x05, 0x00, 0x00, } func (m *PoolAsset) Marshal() (dAtA []byte, err error) { @@ -315,6 +318,16 @@ func (m *Pool) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size := m.FundingRate.Size() + i -= size + if _, err := m.FundingRate.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPool(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x4a if m.LastHeightBorrowInterestRateComputed != 0 { i = encodeVarintPool(dAtA, i, uint64(m.LastHeightBorrowInterestRateComputed)) i-- @@ -466,6 +479,8 @@ func (m *Pool) Size() (n int) { if m.LastHeightBorrowInterestRateComputed != 0 { n += 1 + sovPool(uint64(m.LastHeightBorrowInterestRateComputed)) } + l = m.FundingRate.Size() + n += 1 + l + sovPool(uint64(l)) return n } @@ -1004,6 +1019,40 @@ func (m *Pool) Unmarshal(dAtA []byte) error { break } } + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FundingRate", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPool + } + 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 ErrInvalidLengthPool + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPool + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.FundingRate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipPool(dAtA[iNdEx:]) diff --git a/x/margin/types/types.go b/x/margin/types/types.go index 532e8319c..205f6669b 100644 --- a/x/margin/types/types.go +++ b/x/margin/types/types.go @@ -36,6 +36,10 @@ func NewMTP(signer string, collateralAsset string, borrowAsset string, position SumCollateral: sdk.ZeroInt(), TakeProfitPrice: takeProfitPrice, TakeProfitBorrowRate: sdk.OneDec(), + FundingFeePaidCollaterals: []sdk.Coin{sdk.NewCoin(collateralAsset, sdk.ZeroInt())}, + FundingFeePaidCustodies: []sdk.Coin{sdk.NewCoin(borrowAsset, sdk.ZeroInt())}, + FundingFeeReceivedCollaterals: []sdk.Coin{sdk.NewCoin(collateralAsset, sdk.ZeroInt())}, + FundingFeeReceivedCustodies: []sdk.Coin{sdk.NewCoin(borrowAsset, sdk.ZeroInt())}, } } diff --git a/x/margin/types/types.pb.go b/x/margin/types/types.pb.go index 1f73662a9..3e3404b11 100644 --- a/x/margin/types/types.pb.go +++ b/x/margin/types/types.pb.go @@ -72,6 +72,12 @@ type MTP struct { 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"` TakeProfitPrice github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,17,opt,name=take_profit_price,json=takeProfitPrice,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"take_profit_price"` TakeProfitBorrowRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,18,opt,name=take_profit_borrow_rate,json=takeProfitBorrowRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"take_profit_borrow_rate"` + // funding fee paid + FundingFeePaidCollaterals []types.Coin `protobuf:"bytes,19,rep,name=funding_fee_paid_collaterals,json=fundingFeePaidCollaterals,proto3" json:"funding_fee_paid_collaterals"` + FundingFeePaidCustodies []types.Coin `protobuf:"bytes,20,rep,name=funding_fee_paid_custodies,json=fundingFeePaidCustodies,proto3" json:"funding_fee_paid_custodies"` + // funding fee received + FundingFeeReceivedCollaterals []types.Coin `protobuf:"bytes,21,rep,name=funding_fee_received_collaterals,json=fundingFeeReceivedCollaterals,proto3" json:"funding_fee_received_collaterals"` + FundingFeeReceivedCustodies []types.Coin `protobuf:"bytes,22,rep,name=funding_fee_received_custodies,json=fundingFeeReceivedCustodies,proto3" json:"funding_fee_received_custodies"` } func (m *MTP) Reset() { *m = MTP{} } @@ -177,6 +183,34 @@ func (m *MTP) GetAmmPoolId() uint64 { return 0 } +func (m *MTP) GetFundingFeePaidCollaterals() []types.Coin { + if m != nil { + return m.FundingFeePaidCollaterals + } + return nil +} + +func (m *MTP) GetFundingFeePaidCustodies() []types.Coin { + if m != nil { + return m.FundingFeePaidCustodies + } + return nil +} + +func (m *MTP) GetFundingFeeReceivedCollaterals() []types.Coin { + if m != nil { + return m.FundingFeeReceivedCollaterals + } + return nil +} + +func (m *MTP) GetFundingFeeReceivedCustodies() []types.Coin { + if m != nil { + return m.FundingFeeReceivedCustodies + } + return nil +} + type WhiteList struct { ValidatorList []string `protobuf:"bytes,1,rep,name=validator_list,json=validatorList,proto3" json:"validator_list,omitempty"` } @@ -230,50 +264,55 @@ func init() { func init() { proto.RegisterFile("elys/margin/types.proto", fileDescriptor_cd1c09c977f732f9) } var fileDescriptor_cd1c09c977f732f9 = []byte{ - // 674 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x95, 0xc1, 0x4e, 0xdb, 0x4a, - 0x14, 0x86, 0xe3, 0x24, 0x40, 0x7c, 0x7c, 0x09, 0x61, 0x00, 0x31, 0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x79, 0x07, - 0xb5, 0xf1, 0xda, 0xd1, 0x02, 0x68, 0xa7, 0x87, 0xc7, 0xd6, 0xde, 0x4e, 0xe7, 0x53, 0x67, 0x6f, - 0xb7, 0x51, 0x42, 0x35, 0xa8, 0x76, 0x8f, 0x0e, 0x3f, 0x37, 0x14, 0xa4, 0xc2, 0xcc, 0xf1, 0xfe, - 0x91, 0x7d, 0xd2, 0x28, 0xb7, 0xf7, 0x6e, 0xee, 0x75, 0xe5, 0xf6, 0x5e, 0x57, 0x7e, 0xde, 0xeb, - 0xca, 0xb7, 0x07, 0xbd, 0x74, 0xfb, 0xa0, 0x97, 0xbe, 0x3f, 0xe8, 0xa5, 0xb3, 0xb7, 0x05, 0xf7, - 0x49, 0xae, 0x36, 0x43, 0x2a, 0xaf, 0x78, 0x7c, 0x91, 0x5e, 0x98, 0x5f, 0x9f, 0x9c, 0x31, 0xbd, - 0xd9, 0xf4, 0x84, 0x78, 0xff, 0x3b, 0x00, 0x00, 0xff, 0xff, 0x50, 0x10, 0xa2, 0x49, 0x7f, 0x06, - 0x00, 0x00, + // 753 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x95, 0x5f, 0x4f, 0xda, 0x50, + 0x18, 0xc6, 0x29, 0xa0, 0xc2, 0x61, 0x20, 0x1e, 0x61, 0x56, 0xb7, 0x55, 0x62, 0xb2, 0x85, 0x6c, + 0xb1, 0x9d, 0xee, 0x7a, 0x17, 0xc3, 0x3f, 0x93, 0x04, 0xb5, 0xa9, 0x9a, 0x25, 0x66, 0x49, 0x77, + 0x68, 0x0f, 0x70, 0x62, 0xdb, 0xd3, 0xf4, 0x1c, 0x70, 0x7e, 0x8b, 0x7d, 0x2c, 0x2f, 0xbd, 0x5c, + 0x76, 0x61, 0x16, 0xfd, 0x18, 0xbb, 0x59, 0x5a, 0x0a, 0x2d, 0xc8, 0x45, 0xe5, 0x0a, 0xda, 0x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xdd, 0x45, 0xc4, 0xd4, 0xe3, 0x4e, 0xb3, 0xc9, 0x9c, 0xbe, 0x19, + 0x82, 0x9a, 0x21, 0x47, 0x45, 0xc4, 0xdc, 0x8b, 0x79, 0x37, 0x81, 0x34, 0x5b, 0xa9, 0xcf, 0x38, + 0x35, 0xfd, 0x72, 0x16, 0x92, 0xe9, 0xbc, 0x9a, 0xa1, 0x33, 0x62, 0x40, 0x0b, 0x6c, 0x4d, 0xab, + 0xf4, 0x9d, 0x27, 0x15, 0x2d, 0x26, 0x53, 0xda, 0x9c, 0x54, 0xba, 0x08, 0x40, 0xf1, 0x9a, 0x3e, + 0x83, 0x7c, 0x64, 0x7f, 0x29, 0x19, 0x34, 0x7a, 0x02, 0x76, 0xc0, 0x1a, 0x47, 0x57, 0x58, 0x77, + 0x3d, 0xda, 0x21, 0x5c, 0x8f, 0x1f, 0x6d, 0x6e, 0xae, 0xa3, 0xad, 0xfa, 0x38, 0x35, 0xa0, 0xb5, + 0x62, 0x87, 0x7c, 0x06, 0xaa, 0x71, 0x9d, 0xc8, 0x72, 0x3e, 0x99, 0xe5, 0xd5, 0x08, 0x1b, 0xbd, + 0xe9, 0x16, 0xc8, 0x5b, 0x78, 0x80, 0x3d, 0xd4, 0xc5, 0x4c, 0x04, 0xb5, 0xcc, 0x33, 0xed, 0xee, + 0x63, 0x43, 0x8b, 0x00, 0xf0, 0x18, 0x00, 0x9b, 0xbb, 0x7a, 0x0f, 0x23, 0x8b, 0xf7, 0xc4, 0xc2, + 0xb3, 0xab, 0x0f, 0x70, 0x36, 0x77, 0x8f, 0x02, 0x00, 0xdc, 0x01, 0x39, 0x97, 0x32, 0xc2, 0x09, + 0x75, 0xc4, 0x17, 0x35, 0xa1, 0x5e, 0xda, 0xad, 0xca, 0xb1, 0x1e, 0x97, 0xd5, 0x70, 0x51, 0x1b, + 0x6f, 0x83, 0x25, 0x90, 0x26, 0xa6, 0x58, 0xac, 0x09, 0xf5, 0xac, 0x96, 0x26, 0x26, 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, 0x5b, 0x84, 0x71, 0xf8, 0x16, 0x94, 0x06, 0x28, 0x88, 0x32, 0xf5, 0x74, 0x8b, + 0x30, 0x2e, 0x0a, 0xfe, 0x78, 0xd0, 0x8a, 0xe3, 0xbb, 0xfe, 0xb6, 0xf7, 0x1f, 0x41, 0x6e, 0xd4, + 0x86, 0x70, 0x19, 0x14, 0x2e, 0x4e, 0xce, 0xd4, 0x83, 0xbd, 0xe6, 0x61, 0xf3, 0x60, 0xbf, 0x9c, + 0x82, 0x39, 0x90, 0x6d, 0x9d, 0x9e, 0x7c, 0x2d, 0x0b, 0x30, 0x0f, 0x16, 0xce, 0x8e, 0x4e, 0xb5, + 0xf3, 0x72, 0xba, 0x71, 0x70, 0xfb, 0x20, 0x09, 0x77, 0x0f, 0x92, 0xf0, 0xf7, 0x41, 0x12, 0x7e, + 0x3d, 0x4a, 0xa9, 0xbb, 0x47, 0x29, 0xf5, 0xfb, 0x51, 0x4a, 0x5d, 0x7e, 0x88, 0xa5, 0xc9, 0xef, + 0xf3, 0x6d, 0x07, 0xf3, 0x6b, 0xea, 0x5d, 0x05, 0x17, 0xca, 0xcf, 0x89, 0x6f, 0x7e, 0x7b, 0x31, + 0xf8, 0x62, 0x7f, 0xfa, 0x1f, 0x00, 0x00, 0xff, 0xff, 0x17, 0xea, 0x43, 0xef, 0x0f, 0x08, 0x00, + 0x00, } func (m *MTP) Marshal() (dAtA []byte, err error) { @@ -296,6 +335,70 @@ func (m *MTP) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.FundingFeeReceivedCustodies) > 0 { + for iNdEx := len(m.FundingFeeReceivedCustodies) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.FundingFeeReceivedCustodies[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xb2 + } + } + if len(m.FundingFeeReceivedCollaterals) > 0 { + for iNdEx := len(m.FundingFeeReceivedCollaterals) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.FundingFeeReceivedCollaterals[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xaa + } + } + if len(m.FundingFeePaidCustodies) > 0 { + for iNdEx := len(m.FundingFeePaidCustodies) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.FundingFeePaidCustodies[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xa2 + } + } + if len(m.FundingFeePaidCollaterals) > 0 { + for iNdEx := len(m.FundingFeePaidCollaterals) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.FundingFeePaidCollaterals[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x9a + } + } { size := m.TakeProfitBorrowRate.Size() i -= size @@ -613,6 +716,30 @@ func (m *MTP) Size() (n int) { n += 2 + l + sovTypes(uint64(l)) l = m.TakeProfitBorrowRate.Size() n += 2 + l + sovTypes(uint64(l)) + if len(m.FundingFeePaidCollaterals) > 0 { + for _, e := range m.FundingFeePaidCollaterals { + l = e.Size() + n += 2 + l + sovTypes(uint64(l)) + } + } + if len(m.FundingFeePaidCustodies) > 0 { + for _, e := range m.FundingFeePaidCustodies { + l = e.Size() + n += 2 + l + sovTypes(uint64(l)) + } + } + if len(m.FundingFeeReceivedCollaterals) > 0 { + for _, e := range m.FundingFeeReceivedCollaterals { + l = e.Size() + n += 2 + l + sovTypes(uint64(l)) + } + } + if len(m.FundingFeeReceivedCustodies) > 0 { + for _, e := range m.FundingFeeReceivedCustodies { + l = e.Size() + n += 2 + l + sovTypes(uint64(l)) + } + } return n } @@ -1233,6 +1360,142 @@ func (m *MTP) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 19: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FundingFeePaidCollaterals", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FundingFeePaidCollaterals = append(m.FundingFeePaidCollaterals, types.Coin{}) + if err := m.FundingFeePaidCollaterals[len(m.FundingFeePaidCollaterals)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 20: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FundingFeePaidCustodies", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FundingFeePaidCustodies = append(m.FundingFeePaidCustodies, types.Coin{}) + if err := m.FundingFeePaidCustodies[len(m.FundingFeePaidCustodies)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 21: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FundingFeeReceivedCollaterals", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FundingFeeReceivedCollaterals = append(m.FundingFeeReceivedCollaterals, types.Coin{}) + if err := m.FundingFeeReceivedCollaterals[len(m.FundingFeeReceivedCollaterals)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 22: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FundingFeeReceivedCustodies", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FundingFeeReceivedCustodies = append(m.FundingFeeReceivedCustodies, types.Coin{}) + if err := m.FundingFeeReceivedCustodies[len(m.FundingFeeReceivedCustodies)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:])