Skip to content

Commit

Permalink
Merge pull request #679 from comdex-official/stability_upgrade
Browse files Browse the repository at this point in the history
Stability upgrade
  • Loading branch information
dheerajkd30 authored Feb 6, 2023
2 parents 0e2649c + 018de33 commit 3bc3994
Show file tree
Hide file tree
Showing 10 changed files with 532 additions and 69 deletions.
7 changes: 7 additions & 0 deletions proto/comdex/vault/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ message MsgVaultInterestCalcRequest {
}

message MsgVaultInterestCalcResponse{}
// need to remove later
message MsgCorrectStabilityFeesRequest {
string from = 1 [ (gogoproto.moretags) = "yaml:\"from\"" ];
}

message MsgCorrectStabilityFeesResponse{}

service Msg {
rpc MsgCreate(MsgCreateRequest) returns (MsgCreateResponse);
Expand All @@ -202,4 +208,5 @@ service Msg {
rpc MsgDepositStableMint(MsgDepositStableMintRequest) returns (MsgDepositStableMintResponse);
rpc MsgWithdrawStableMint(MsgWithdrawStableMintRequest) returns (MsgWithdrawStableMintResponse);
rpc MsgVaultInterestCalc(MsgVaultInterestCalcRequest) returns (MsgVaultInterestCalcResponse);
rpc MsgCorrectStabilityFees(MsgCorrectStabilityFeesRequest) returns (MsgCorrectStabilityFeesResponse); // need to remove later
}
27 changes: 27 additions & 0 deletions x/vault/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func GetTxCmd() *cobra.Command {
DepositStableMint(),
WithdrawStableMint(),
CalculateInterest(),
CorrectStabilityFees(),
)

return cmd
Expand Down Expand Up @@ -500,3 +501,29 @@ func CalculateInterest() *cobra.Command {
flags.AddTxFlagsToCmd(cmd)
return cmd
}

// need to remove later
func CorrectStabilityFees() *cobra.Command {
cmd := &cobra.Command{
Use: "correct-fees",
Short: "correct stability fees",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgCorrectStabilityFeesRequest(ctx.FromAddress)

if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(ctx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)
return cmd
}
3 changes: 3 additions & 0 deletions x/vault/expected/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package expected
import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/comdex-official/comdex/app/wasm/bindings"
assettypes "github.com/comdex-official/comdex/x/asset/types"
esmtypes "github.com/comdex-official/comdex/x/esm/types"
rewardstypes "github.com/comdex-official/comdex/x/rewards/types"
Expand All @@ -26,6 +27,8 @@ type AssetKeeper interface {
GetPair(ctx sdk.Context, id uint64) (assettypes.Pair, bool)
GetApp(ctx sdk.Context, id uint64) (assettypes.AppData, bool)
GetPairsVault(ctx sdk.Context, pairID uint64) (assettypes.ExtendedPairVault, bool)
SetPairsVault(ctx sdk.Context, app assettypes.ExtendedPairVault)
WasmUpdatePairsVault(ctx sdk.Context, updatePairVault *bindings.MsgUpdatePairsVault) error
}

type MarketKeeper interface {
Expand Down
3 changes: 3 additions & 0 deletions x/vault/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
case *types.MsgVaultInterestCalcRequest:
res, err := server.MsgVaultInterestCalc(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgCorrectStabilityFeesRequest: // need to remove later
res, err := server.MsgCorrectStabilityFees(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
default:
return nil, errors.Wrapf(types.ErrorUnknownMsgType, "%T", msg)
}
Expand Down
56 changes: 56 additions & 0 deletions x/vault/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package keeper

import (
"context"
"fmt"
"strconv"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/comdex-official/comdex/app/wasm/bindings"
collectortypes "github.com/comdex-official/comdex/x/collector/types"
esmtypes "github.com/comdex-official/comdex/x/esm/types"
rewardstypes "github.com/comdex-official/comdex/x/rewards/types"
Expand Down Expand Up @@ -1451,3 +1453,57 @@ func (k msgServer) MsgVaultInterestCalc(c context.Context, msg *types.MsgVaultIn

return &types.MsgVaultInterestCalcResponse{}, nil
}

// need to remove later
func (k msgServer) MsgCorrectStabilityFees(c context.Context, msg *types.MsgCorrectStabilityFeesRequest) (*types.MsgCorrectStabilityFeesResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
if msg.From == "comdex1ma05aft9x20xjx2jd4spms03rcuewk5r0elvx7" {
extPairs := []*bindings.MsgUpdatePairsVault{
{
AppID: 2, ExtPairID: 2, StabilityFee: sdk.MustNewDecFromStr("0.01"), ClosingFee: sdk.ZeroDec(), LiquidationPenalty: sdk.MustNewDecFromStr("0.15"),
DrawDownFee: sdk.MustNewDecFromStr("0.005"), IsVaultActive: true, DebtCeiling: sdk.NewInt(250000000000), DebtFloor: sdk.NewInt(50000000), MinCr: sdk.MustNewDecFromStr("1.4"),
MinUsdValueLeft: 100000,
},
{
AppID: 2, ExtPairID: 3, StabilityFee: sdk.MustNewDecFromStr("0.005"), ClosingFee: sdk.ZeroDec(), LiquidationPenalty: sdk.MustNewDecFromStr("0.15"),
DrawDownFee: sdk.MustNewDecFromStr("0.005"), IsVaultActive: true, DebtCeiling: sdk.NewInt(350000000000), DebtFloor: sdk.NewInt(50000000), MinCr: sdk.MustNewDecFromStr("1.7"),
MinUsdValueLeft: 100000,
},
{
AppID: 2, ExtPairID: 4, StabilityFee: sdk.MustNewDecFromStr("0.0025"), ClosingFee: sdk.ZeroDec(), LiquidationPenalty: sdk.MustNewDecFromStr("0.15"),
DrawDownFee: sdk.MustNewDecFromStr("0.005"), IsVaultActive: true, DebtCeiling: sdk.NewInt(400000000000), DebtFloor: sdk.NewInt(50000000), MinCr: sdk.MustNewDecFromStr("2"),
MinUsdValueLeft: 100000,
},
{
AppID: 2, ExtPairID: 5, StabilityFee: sdk.MustNewDecFromStr("0.01"), ClosingFee: sdk.ZeroDec(), LiquidationPenalty: sdk.MustNewDecFromStr("0.15"),
DrawDownFee: sdk.MustNewDecFromStr("0.005"), IsVaultActive: true, DebtCeiling: sdk.NewInt(250000000000), DebtFloor: sdk.NewInt(50000000), MinCr: sdk.MustNewDecFromStr("1.5"),
MinUsdValueLeft: 100000,
},
{
AppID: 2, ExtPairID: 6, StabilityFee: sdk.MustNewDecFromStr("0.005"), ClosingFee: sdk.ZeroDec(), LiquidationPenalty: sdk.MustNewDecFromStr("0.15"),
DrawDownFee: sdk.MustNewDecFromStr("0.005"), IsVaultActive: true, DebtCeiling: sdk.NewInt(350000000000), DebtFloor: sdk.NewInt(50000000), MinCr: sdk.MustNewDecFromStr("1.8"),
MinUsdValueLeft: 100000,
},
{
AppID: 2, ExtPairID: 7, StabilityFee: sdk.MustNewDecFromStr("0.0025"), ClosingFee: sdk.ZeroDec(), LiquidationPenalty: sdk.MustNewDecFromStr("0.15"),
DrawDownFee: sdk.MustNewDecFromStr("0.005"), IsVaultActive: true, DebtCeiling: sdk.NewInt(400000000000), DebtFloor: sdk.NewInt(50000000), MinCr: sdk.MustNewDecFromStr("2.1"),
MinUsdValueLeft: 100000,
},
}
for _, extPair := range extPairs {
err := k.asset.WasmUpdatePairsVault(ctx, extPair)
if err != nil {
fmt.Println("err in updating extended pair ", extPair.ExtPairID)
}
}
stAtomPair, found := k.asset.GetPairsVault(ctx, 11)
if found {
stAtomPair.PairId = 9
k.asset.SetPairsVault(ctx, stAtomPair)
}
} else {
return &types.MsgCorrectStabilityFeesResponse{}, types.ErrorInvalidFrom
}

return &types.MsgCorrectStabilityFeesResponse{}, nil
}
2 changes: 2 additions & 0 deletions x/vault/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgDepositStableMintRequest{}, "comdex/vault/MsgDepositStableMintRequest", nil)
cdc.RegisterConcrete(&MsgWithdrawStableMintRequest{}, "comdex/vault/MsgWithdrawStableMintRequest", nil)
cdc.RegisterConcrete(&MsgVaultInterestCalcRequest{}, "comdex/vault/MsgVaultInterestCalcRequest", nil)
cdc.RegisterConcrete(&MsgCorrectStabilityFeesRequest{}, "comdex/vault/MsgCorrectStabilityFeesRequest", nil) // need to remove later
}

func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
Expand All @@ -37,6 +38,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
&MsgDepositStableMintRequest{},
&MsgWithdrawStableMintRequest{},
&MsgVaultInterestCalcRequest{},
&MsgCorrectStabilityFeesRequest{}, // need to remove later
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
Expand Down
23 changes: 12 additions & 11 deletions x/vault/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ const (
)

var (
TypeMsgCreateRequest = ModuleName + ":create"
TypeMsgDepositRequest = ModuleName + ":deposit"
TypeMsgWithdrawRequest = ModuleName + ":withdraw"
TypeMsgDrawRequest = ModuleName + ":draw"
TypeMsgRepayRequest = ModuleName + ":repay"
TypeMsgLiquidateRequest = ModuleName + ":liquidate"
TypeMsgDepositDrawRequest = ModuleName + ":deposit_draw"
TypeMsgCreateStableMintRequest = ModuleName + ":create_stablemint"
TypeMsgDepositStableMintRequest = ModuleName + ":deposit_stablemint"
TypeMsgWithdrawStableMintRequest = ModuleName + ":withdraw_stablemint"
TypeMsgVaultInterestCalcRequest = ModuleName + ":calculate_interest"
TypeMsgCreateRequest = ModuleName + ":create"
TypeMsgDepositRequest = ModuleName + ":deposit"
TypeMsgWithdrawRequest = ModuleName + ":withdraw"
TypeMsgDrawRequest = ModuleName + ":draw"
TypeMsgRepayRequest = ModuleName + ":repay"
TypeMsgLiquidateRequest = ModuleName + ":liquidate"
TypeMsgDepositDrawRequest = ModuleName + ":deposit_draw"
TypeMsgCreateStableMintRequest = ModuleName + ":create_stablemint"
TypeMsgDepositStableMintRequest = ModuleName + ":deposit_stablemint"
TypeMsgWithdrawStableMintRequest = ModuleName + ":withdraw_stablemint"
TypeMsgVaultInterestCalcRequest = ModuleName + ":calculate_interest"
TypeMsgCorrectStabilityFeesRequest = ModuleName + ":correct-fees" // need to remove later
)

var (
Expand Down
42 changes: 42 additions & 0 deletions x/vault/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var (
_ sdk.Msg = (*MsgDepositStableMintRequest)(nil)
_ sdk.Msg = (*MsgWithdrawStableMintRequest)(nil)
_ sdk.Msg = (*MsgVaultInterestCalcRequest)(nil)
_ sdk.Msg = (*MsgCorrectStabilityFeesRequest)(nil)
)

func NewMsgCreateRequest(
Expand Down Expand Up @@ -616,3 +617,44 @@ func (m *MsgVaultInterestCalcRequest) GetSigners() []sdk.AccAddress {

return []sdk.AccAddress{from}
}

// need to remove later
func NewMsgCorrectStabilityFeesRequest(
from sdk.AccAddress,
) *MsgCorrectStabilityFeesRequest {
return &MsgCorrectStabilityFeesRequest{
From: from.String(),
}
}

func (m *MsgCorrectStabilityFeesRequest) Route() string {
return RouterKey
}

func (m *MsgCorrectStabilityFeesRequest) Type() string {
return TypeMsgCorrectStabilityFeesRequest
}

func (m *MsgCorrectStabilityFeesRequest) ValidateBasic() error {
if m.From == "" {
return errors.Wrap(ErrorInvalidFrom, "from cannot be empty")
}
if _, err := sdk.AccAddressFromBech32(m.From); err != nil {
return errors.Wrapf(ErrorInvalidFrom, "%s", err)
}

return nil
}

func (m *MsgCorrectStabilityFeesRequest) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m))
}

func (m *MsgCorrectStabilityFeesRequest) GetSigners() []sdk.AccAddress {
from, err := sdk.AccAddressFromBech32(m.From)
if err != nil {
panic(err)
}

return []sdk.AccAddress{from}
}
Loading

0 comments on commit 3bc3994

Please sign in to comment.