Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/dev #439

Merged
merged 25 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8a5baca
codec changes
Aug 28, 2022
9312e79
adding ckt breaker in borrow liquidations
Aug 28, 2022
66276ec
updating RegisterLegacyAminoCodec
Aug 29, 2022
82a8cf2
Merge branch 'feature/dev' of https://github.com/comdex-official/comd…
Aug 29, 2022
ea83cfc
Adjusting bridged asset qty after auctions
Aug 30, 2022
03c65cd
Merge branch 'feature/dev' of https://github.com/comdex-official/comd…
Aug 30, 2022
b08018e
removed abci iterations for borrow positions
Sep 3, 2022
f9457b4
adding dummy prices
Sep 3, 2022
5d7a4f5
adding txn to calculate borrow interest
Sep 4, 2022
80bff65
Merge branch 'feature/dev' of https://github.com/comdex-official/comd…
Sep 4, 2022
625ef05
removing lend position iterations from abci
Sep 5, 2022
7a433a4
removing dummy prices
Sep 5, 2022
ecd150b
removing commented code from scripts
Sep 5, 2022
608ef53
renaming variables
Sep 5, 2022
51cd9c7
Merge pull request #436 from comdex-official/lend-codec-impl
dheerajkd30 Sep 5, 2022
e0403de
dd:refactor
dheerajkd30 Sep 5, 2022
f283ac1
exclude disabled pools from child pools
vishnukumavat Sep 6, 2022
7f6a233
avoid same pool id in child pools while gauge creation
vishnukumavat Sep 6, 2022
48176bb
added fn for stable borrow calculations
Sep 6, 2022
9b1bf56
Merge pull request #437 from comdex-official/bug_fix
dheerajkd30 Sep 6, 2022
959ef0a
added upgrades
Sep 6, 2022
2341634
testing upgrade
Sep 6, 2022
fec0bc3
testing upgrade
Sep 6, 2022
c705f1b
renaming version
Sep 7, 2022
807bdec
Merge pull request #438 from comdex-official/lend_upgrade
dheerajkd30 Sep 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
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