Skip to content

Commit

Permalink
Merge pull request #439 from comdex-official/feature/dev
Browse files Browse the repository at this point in the history
Feature/dev
  • Loading branch information
dheerajkd30 authored Sep 7, 2022
2 parents d1872b4 + 807bdec commit 0cd22d6
Show file tree
Hide file tree
Showing 42 changed files with 2,174 additions and 694 deletions.
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ linters:
#- goconst
#- gocritic
#- gocyclo
- godot
#- godot
- godox
#- goerr113
- gofmt
Expand Down Expand Up @@ -69,7 +69,7 @@ linters:
- typecheck
- unconvert
#- unparam
- unused
#- unused - will be enabled later
- varcheck
- whitespace
#- wsl
6 changes: 4 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,8 +1144,8 @@ func (a *App) ModuleAccountsPermissions() map[string][]string {

func (a *App) registerUpgradeHandlers() {
a.UpgradeKeeper.SetUpgradeHandler(
tv4_0_0.UpgradeNameV4_1_0,
tv4_0_0.CreateUpgradeHandlerV410(a.mm, a.configurator, a.Rewardskeeper, a.LiquidityKeeper),
tv4_0_0.UpgradeNameV4_2_0,
tv4_0_0.CreateUpgradeHandlerV420(a.mm, a.configurator),
)

// When a planned update height is reached, the old binary will panic
Expand Down Expand Up @@ -1215,6 +1215,8 @@ func upgradeHandlers(upgradeInfo storetypes.UpgradeInfo, a *App, storeUpgrades *
}
case upgradeInfo.Name == tv4_0_0.UpgradeNameV4_1_0 && !a.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height):
storeUpgrades = &storetypes.StoreUpgrades{}
case upgradeInfo.Name == tv4_0_0.UpgradeNameV4_2_0 && !a.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height):
storeUpgrades = &storetypes.StoreUpgrades{}
}
return storeUpgrades
}
14 changes: 14 additions & 0 deletions app/upgrades/testnet/v4_0_0/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,17 @@ const (
}
}'`
)

const (
UpgradeNameV4_2_0 = "v4.2.0"
UpgradeHeightV4_2_0 = "" // replace this height
UpgradeInfoV4_2_0 = `'{
"binaries": {
"darwin/arm64":"",
"darwin/x86_64":"",
"linux/arm64":"",
"linux/x86_64":"",
"windows/x86_64":""
}
}'`
)
19 changes: 18 additions & 1 deletion app/upgrades/testnet/v4_0_0/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func CreateSwapFeeGauge(
_ = rewardsKeeper.CreateNewGauge(ctx, newGauge, true)
}

// CreateUpgradeHandler creates an SDK upgrade handler for v4_0_1
// CreateUpgradeHandler creates an SDK upgrade handler for v4_1_0
func CreateUpgradeHandlerV410(
mm *module.Manager,
configurator module.Configurator,
Expand All @@ -74,3 +74,20 @@ func CreateUpgradeHandlerV410(
return newVM, err
}
}

// CreateUpgradeHandler creates an SDK upgrade handler for v4_2_0
func CreateUpgradeHandlerV420(
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// This change is only for testnet upgrade

newVM, err := mm.RunMigrations(ctx, configurator, fromVM)

if err != nil {
return newVM, err
}
return newVM, err
}
}
33 changes: 31 additions & 2 deletions proto/comdex/lend/v1beta1/lend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,19 @@ message LendAsset {
uint64 app_id = 10
[(gogoproto.customname) = "AppID", (gogoproto.moretags) = "yaml:\"app_id\""];

string cpool_name = 11 [
string global_index = 11 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"global_index\""
];

google.protobuf.Timestamp last_interaction_time = 12 [
(gogoproto.nullable) = false,
(gogoproto.stdtime) = true,
(gogoproto.moretags) = "yaml:\"last_interaction_time\""
];

string cpool_name = 13 [
(gogoproto.customname) = "CPoolName",
(gogoproto.moretags) = "yaml:\"cpool_name\""
];
Expand Down Expand Up @@ -124,7 +136,24 @@ message BorrowAsset {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"
];

string cpool_name = 12 [
string global_index = 12 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"global_index\""
];
string reserve_global_index = 13 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"reserve_global_index\""
];

google.protobuf.Timestamp last_interaction_time = 14 [
(gogoproto.nullable) = false,
(gogoproto.stdtime) = true,
(gogoproto.moretags) = "yaml:\"last_interaction_time\""
];

string cpool_name = 15 [
(gogoproto.customname) = "CPoolName",
(gogoproto.moretags) = "yaml:\"cpool_name\""
];
Expand Down
20 changes: 19 additions & 1 deletion proto/comdex/lend/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ service Msg {

// FundModuleAccounts funds an existing module account
rpc FundModuleAccounts(MsgFundModuleAccounts) returns (MsgFundModuleAccountsResponse);

rpc CalculateBorrowInterest(MsgCalculateBorrowInterest) returns (MsgCalculateBorrowInterestResponse);

rpc CalculateLendRewards(MsgCalculateLendRewards) returns (MsgCalculateLendRewardsResponse);
}

message MsgLend {
Expand Down Expand Up @@ -111,6 +115,16 @@ message MsgFundModuleAccounts {
cosmos.base.v1beta1.Coin amount = 4 [(gogoproto.nullable) = false];
}

message MsgCalculateBorrowInterest {
string borrower = 1;
uint64 borrow_id = 2;
}

message MsgCalculateLendRewards{
string lender = 1;
uint64 lend_id = 2;
}

message MsgLendResponse {}

message MsgWithdrawResponse {}
Expand All @@ -131,4 +145,8 @@ message MsgCloseBorrowResponse {}

message MsgBorrowAlternateResponse {}

message MsgFundModuleAccountsResponse {}
message MsgFundModuleAccountsResponse {}

message MsgCalculateBorrowInterestResponse {}

message MsgCalculateLendRewardsResponse {}
8 changes: 4 additions & 4 deletions x/auction/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package cli

import (
"github.com/cosmos/cosmos-sdk/client"
"strings"
"github.com/spf13/cobra"
"strings"
)

func GetQueryCmd() *cobra.Command {
Expand Down Expand Up @@ -56,12 +56,12 @@ func GetTxCmd() *cobra.Command {
return cmd
}

func ParseStringFromString(s string, seperator string) ([]string, error) {
func ParseStringFromString(s string, separator string) ([]string, error) {
var parsedStrings []string
for _, s := range strings.Split(s, seperator) {
for _, s := range strings.Split(s, separator) {
s = strings.TrimSpace(s)

parsedStrings = append(parsedStrings, s)
}
return parsedStrings, nil
}
}
4 changes: 2 additions & 2 deletions x/auction/keeper/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ func (k Keeper) UpdateCollateralLockedAmountLockerMapping(ctx sdk.Context, appMa
func (k Keeper) GetAllAuctionMappingForApp(ctx sdk.Context) (collectorAuctionLookupTable []types.AppAssetIdToAuctionLookupTable, found bool) {
return k.collector.GetAllAuctionMappingForApp(ctx)
}
func (k Keeper) DeleteLockedVault(ctx sdk.Context, appId, id uint64) {
k.liquidation.DeleteLockedVault(ctx, appId, id)
func (k Keeper) DeleteLockedVault(ctx sdk.Context, appID, id uint64) {
k.liquidation.DeleteLockedVault(ctx, appID, id)
}

func (k Keeper) DeleteUserVaultExtendedPairMapping(ctx sdk.Context, address string, appID uint64, pairVaultID uint64) {
Expand Down
4 changes: 2 additions & 2 deletions x/auction/keeper/surplus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ func (s *KeeperTestSuite) TestSurplusActivator() {
surplusAuction, err := k.GetSurplusAuction(*ctx, appId, auctionMappingId, auctionId)
s.Require().NoError(err)

collectorLookUp, found := collectorKeeper.GetCollectorLookupTable(*ctx, 1,2)
collectorLookUp, found := collectorKeeper.GetCollectorLookupTable(*ctx, 1, 2)
s.Require().True(found)

netFees, found := k.GetNetFeeCollectedData(*ctx, uint64(1),2)
netFees, found := k.GetNetFeeCollectedData(*ctx, uint64(1), 2)
s.Require().True(found)

s.Require().Equal(surplusAuction.AppId, appId)
Expand Down
4 changes: 2 additions & 2 deletions x/collector/keeper/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func (k Keeper) GetLockerLookupTable(ctx sdk.Context, appID, assetID uint64) (lo
return k.locker.GetLockerLookupTable(ctx, appID, assetID)
}

func (k Keeper) GetReward(ctx sdk.Context, appId, assetID uint64) (rewards rewardstypes.InternalRewards, found bool) {
return k.rewards.GetReward(ctx, appId, assetID)
func (k Keeper) GetReward(ctx sdk.Context, appID, assetID uint64) (rewards rewardstypes.InternalRewards, found bool) {
return k.rewards.GetReward(ctx, appID, assetID)
}

func (k Keeper) GetLocker(ctx sdk.Context, lockerID uint64) (locker lockertypes.Locker, found bool) {
Expand Down
2 changes: 1 addition & 1 deletion x/esm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (k Keeper) CalculateCollateral(ctx sdk.Context, appID uint64, amount sdk.Co
if err2 != nil {
return err2
}
data.Amount = data.Amount.Sub((sdk.Int(tokenQuant)))
data.Amount = data.Amount.Sub(tokenQuant)
esmDataAfterCoolOff.CollateralAsset = append(esmDataAfterCoolOff.CollateralAsset[:i], esmDataAfterCoolOff.CollateralAsset[i+1:]...)
esmDataAfterCoolOff.CollateralAsset = append(esmDataAfterCoolOff.CollateralAsset[:i+1], esmDataAfterCoolOff.CollateralAsset[i:]...)
esmDataAfterCoolOff.CollateralAsset[i] = data
Expand Down
15 changes: 2 additions & 13 deletions x/lend/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,11 @@ func BeginBlocker(ctx sdk.Context, _ abci.RequestBeginBlock, k keeper.Keeper) {
defer telemetry.ModuleMeasureSince(types.ModuleName, ctx.BlockTime(), telemetry.MetricKeyBeginBlocker)

_ = utils.ApplyFuncIfNoError(ctx, func(ctx sdk.Context) error {
err := k.IterateLends(ctx)
if err != nil {
ctx.Logger().Error("error in Iterate Lends")
}
err = k.IterateBorrows(ctx)
if err != nil {
ctx.Logger().Error("error in Iterate Borrows")
}
err = k.ReBalanceStableRates(ctx)

err := k.ReBalanceStableRates(ctx)
if err != nil {
ctx.Logger().Error("error in ReBalance Stable Rates")
}
err = k.SetLastInterestTime(ctx, ctx.BlockTime().Unix())
if err != nil {
ctx.Logger().Error("error in SetLastInterestTime")
}
return nil
})
}
58 changes: 56 additions & 2 deletions x/lend/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ func GetTxCmd() *cobra.Command {

cmd.AddCommand(
txLend(),
txWithdraw(), //withdraw collateral partially or fully
txWithdraw(),
txDeposit(),
txCloseLend(),
txBorrowAsset(),
txDrawAsset(),
txRepayAsset(), //including functionality of both repaying and closing position
txRepayAsset(),
txDepositBorrowAsset(),
txCloseBorrowAsset(),
txBorrowAssetAlternate(),
txFundModuleAccounts(),
txCalculateBorrowInterest(),
txCalculateLendRewards(),
)

return cmd
Expand Down Expand Up @@ -917,3 +919,55 @@ func NewAddAuctionParams(clientCtx client.Context, txf tx.Factory, fs *flag.Flag

return txf, msg, nil
}

func txCalculateBorrowInterest() *cobra.Command {
cmd := &cobra.Command{
Use: "calculate-borrow-interest [borrow-id] ",
Short: " calculate borrow interest for a borrow position",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

borrowID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}

msg := types.NewMsgCalculateBorrowInterest(ctx.GetFromAddress().String(), borrowID)

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

flags.AddTxFlagsToCmd(cmd)
return cmd
}

func txCalculateLendRewards() *cobra.Command {
cmd := &cobra.Command{
Use: "calculate-lend-rewards [lend-id] ",
Short: " calculate lend rewards for a lend position",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

borrowID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}

msg := types.NewMsgCalculateLendRewards(ctx.GetFromAddress().String(), borrowID)

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

flags.AddTxFlagsToCmd(cmd)
return cmd
}
4 changes: 2 additions & 2 deletions x/lend/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
lends, _ := k.GetLends(ctx)
userDeposit, _ := k.GetUserDepositStats(ctx)
reserveDeposit, _ := k.GetReserveDepositStats(ctx)
buyBackDeposir, _ := k.GetBuyBackDepositStats(ctx)
buyBackDeposit, _ := k.GetBuyBackDepositStats(ctx)
borrowDeposit, _ := k.GetBorrowStats(ctx)
return types.NewGenesisState(
k.GetAllBorrow(ctx),
Expand All @@ -101,7 +101,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
lends,
userDeposit,
reserveDeposit,
buyBackDeposir,
buyBackDeposit,
borrowDeposit,
k.GetLendPairs(ctx),
k.GetAllAssetRatesStats(ctx),
Expand Down
8 changes: 8 additions & 0 deletions x/lend/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
res, err := server.FundModuleAccounts(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)

case *types.MsgCalculateBorrowInterest:
res, err := server.CalculateBorrowInterest(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)

case *types.MsgCalculateLendRewards:
res, err := server.CalculateLendRewards(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)

default:
errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg)
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg)
Expand Down
Loading

0 comments on commit 0cd22d6

Please sign in to comment.