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

adding pool Depreciate poposal #761

Merged
merged 25 commits into from
Jul 6, 2023
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
eaa8f13
adding pool Depreciate poposal
pratikasr May 8, 2023
622c4ee
updating depreciate pool in msg server
pratikasr May 8, 2023
62c0e4c
excluding dep pools while pair creation
pratikasr May 18, 2023
7cf12b3
adding BeginBlocker fn for DeletePoolAndTransferFunds
pratikasr May 19, 2023
fc67e3c
added check if pool exists before adding a proposal
pratikasr May 19, 2023
dc33ec8
minor refactor
pratikasr May 19, 2023
28058a2
added isolated mode for V2 lend module
pratikasr May 23, 2023
f8f6029
adding e-mode for lend module V2
pratikasr May 24, 2023
92fee65
added proposal for eMode pairs
pratikasr May 24, 2023
bf54f9d
gov proposal cli added for enabling E Mode pairs
pratikasr May 24, 2023
a0f8ac9
updated testcase for Isolated Mode & E Mode
pratikasr May 25, 2023
643fe65
minor refactor
pratikasr May 26, 2023
b10e9bb
minor refactor
pratikasr May 26, 2023
bab624e
resolved missing URL for AddEModePairsProposal
pratikasr May 26, 2023
8a8e555
Merge branch 'feature/dev' of https://github.com/comdex-official/comd…
pratikasr Jun 1, 2023
2ad74c2
adding repay-withdraw
pratikasr Jun 1, 2023
aa25e8e
updating repay-withdraw testcase
pratikasr Jun 1, 2023
e831a96
updated testcase for pool depreciate
pratikasr Jun 2, 2023
9d5938e
adding migrations code for lend pairs
pratikasr Jun 5, 2023
aa20981
adding v12 upgrade code
pratikasr Jun 5, 2023
6c27a72
Merge branch 'feature/dev' into pool-depreciate
pratikasr Jun 5, 2023
4537162
refactoring app.go
pratikasr Jun 5, 2023
9485ce6
updating migrate.go
pratikasr Jun 8, 2023
e48ff5b
updating genesis
pratikasr Jul 5, 2023
c718e44
resolving conflicts
pratikasr Jul 5, 2023
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
17 changes: 13 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ func GetGovProposalHandlers() []govclient.ProposalHandler {
lendclient.AddMultipleLendPairsHandler,
lendclient.AddPoolPairsHandler,
lendclient.AddAssetRatesPoolPairsHandler,
lendclient.AddDepreciatePoolsHandler,
lendclient.AddEModePairsHandler,
paramsclient.ProposalHandler,
distrclient.ProposalHandler,
upgradeclient.ProposalHandler,
Expand Down Expand Up @@ -1382,10 +1384,13 @@ func (a *App) registerUpgradeHandlers() {
panic(err)
}

a.UpgradeKeeper.SetUpgradeHandler(
mv12.UpgradeName,
mv12.CreateUpgradeHandlerV12(a.mm, a.configurator, a.ICQKeeper),
)
switch {
case upgradeInfo.Name == mv12.UpgradeName:
a.UpgradeKeeper.SetUpgradeHandler(
mv12.UpgradeName,
mv12.CreateUpgradeHandlerV12(a.mm, a.configurator, a.ICQKeeper),
)
}

var storeUpgrades *storetypes.StoreUpgrades

Expand All @@ -1404,6 +1409,10 @@ func upgradeHandlers(upgradeInfo storetypes.UpgradeInfo, a *App, storeUpgrades *
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{icqtypes.StoreKey},
}
case upgradeInfo.Name == mv12.UpgradeName && !a.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height):
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{},
}
}
return storeUpgrades
}
6 changes: 6 additions & 0 deletions app/upgrades/mainnet/v12/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import (
icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v4/types"
)

// An error occurred during the creation of the CMST/STJUNO pair, as it was mistakenly created in the Harbor app (ID-2) instead of the cSwap app (ID-1).
// As a result, the transaction fee was charged to the creator of the pair, who is entitled to a refund.
// The provided code is designed to initiate the refund process.
// The transaction hash for the pair creation is EF408AD53B8BB0469C2A593E4792CB45552BD6495753CC2C810A1E4D82F3982F.
// MintScan - https://www.mintscan.io/comdex/txs/EF408AD53B8BB0469C2A593E4792CB45552BD6495753CC2C810A1E4D82F3982F

func CreateUpgradeHandlerV12(
mm *module.Manager,
configurator module.Configurator,
Expand Down
3 changes: 2 additions & 1 deletion proto/comdex/lend/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ message GenesisState {
[ (gogoproto.moretags) = "yaml:\"reserveBal\"", (gogoproto.nullable) = false ];
repeated AllReserveStats allReserveStats = 15
[ (gogoproto.moretags) = "yaml:\"allReserveStats\"", (gogoproto.nullable) = false ];

PoolDepreciate poolDepreciate = 16
[ (gogoproto.moretags) = "yaml:\"poolDepreciate\"", (gogoproto.nullable) = false ];
}
12 changes: 12 additions & 0 deletions proto/comdex/lend/v1beta1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,16 @@ message AddAssetRatesPoolPairsProposal {
string title = 1 [(gogoproto.moretags) = "yaml:\"title\""];
string description = 2 [(gogoproto.moretags) = "yaml:\"description\""];
AssetRatesPoolPairs AssetRatesPoolPairs = 3 [(gogoproto.nullable) = false];
}

message AddPoolDepreciateProposal {
string title = 1 [(gogoproto.moretags) = "yaml:\"title\""];
string description = 2 [(gogoproto.moretags) = "yaml:\"description\""];
PoolDepreciate PoolDepreciate = 3 [(gogoproto.nullable) = false];
}

message AddEModePairsProposal {
string title = 1 [(gogoproto.moretags) = "yaml:\"title\""];
string description = 2 [(gogoproto.moretags) = "yaml:\"description\""];
EModePairsForProposal EModePairsForProposal = 3 [(gogoproto.nullable) = false];
}
77 changes: 75 additions & 2 deletions proto/comdex/lend/v1beta1/lend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ message Extended_Pair {

uint64 min_usd_value_left = 6 [
(gogoproto.moretags) = "yaml:\"min_usd_value_left\""];

bool is_e_mode_enabled = 7 [
(gogoproto.moretags) = "yaml:\"is_e_mode_enabled\""
];
}

message AssetToPairMapping{
Expand Down Expand Up @@ -366,7 +370,24 @@ message AssetRatesParams{//AssetRatesStats
(gogoproto.customname) = "CAssetID",
(gogoproto.moretags) = "yaml:\"c_asset_id\""
];

bool is_isolated = 16 [
(gogoproto.moretags) = "yaml:\"is_isolated\""
];
string e_ltv = 17 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"e_ltv\""
];
string e_liquidation_threshold = 18 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"e_liquidation_threshold\""
];
string e_liquidation_penalty = 19 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"e_liquidation_penalty\""
];
}

message ReserveBuybackAssetData{// BalanceStats
Expand Down Expand Up @@ -738,5 +759,57 @@ message AssetRatesPoolPairs {
(gogoproto.moretags) = "yaml:\"asset_data\""
];
uint64 min_usd_value_left = 19 [
(gogoproto.moretags) = "yaml:\"min_usd_value_left\""];
(gogoproto.moretags) = "yaml:\"min_usd_value_left\""
];
bool is_isolated = 20 [
(gogoproto.moretags) = "yaml:\"is_isolated\""
];
}

message PoolDepreciate{
repeated IndividualPoolDepreciate individual_pool_depreciate = 1 [
(gogoproto.nullable) = false,
(gogoproto.customname) = "IndividualPoolDepreciate",
(gogoproto.moretags) = "yaml:\"individual_pool_depreciate\""
];
}

message IndividualPoolDepreciate{
uint64 pool_id = 1 [
(gogoproto.customname) = "PoolID",
(gogoproto.moretags) = "yaml:\"pool_id\""
];
bool is_pool_depreciated = 2 [
(gogoproto.moretags) = "yaml:\"is_pool_depreciated\""
];
}

message EModePairsForProposal {
repeated EModePairs e_mode_pairs = 1 [
(gogoproto.nullable) = false,
(gogoproto.customname) = "EModePairs",
(gogoproto.moretags) = "yaml:\"e_mode_pairs\""
];
}

message EModePairs {
uint64 pair_id = 1 [
(gogoproto.customname) = "PairID",
(gogoproto.moretags) = "yaml:\"pair_id\""
];
string e_ltv = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"e_ltv\""
];
string e_liquidation_threshold = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"e_liquidation_threshold\""
];
string e_liquidation_penalty = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"e_liquidation_penalty\""
];
}
9 changes: 9 additions & 0 deletions proto/comdex/lend/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ service Msg {

rpc FundReserveAccounts(MsgFundReserveAccounts) returns (MsgFundReserveAccountsResponse);

rpc RepayWithdraw(MsgRepayWithdraw) returns (MsgRepayWithdrawResponse);

}

message MsgLend {
Expand Down Expand Up @@ -126,6 +128,11 @@ message MsgFundReserveAccounts {
cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false];
}

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

message MsgLendResponse {}

message MsgWithdrawResponse {}
Expand All @@ -151,3 +158,5 @@ message MsgFundModuleAccountsResponse {}
message MsgCalculateInterestAndRewardsResponse {}

message MsgFundReserveAccountsResponse {}

message MsgRepayWithdrawResponse {}
24 changes: 24 additions & 0 deletions x/lend/abci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package lend

import (
utils "github.com/comdex-official/comdex/types"
"github.com/comdex-official/comdex/x/lend/keeper"
"github.com/comdex-official/comdex/x/lend/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
)

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 {
if ctx.BlockHeight()%14400 == 0 {
err := k.DeletePoolAndTransferInterest(ctx)
if err != nil {
return err
}
}
return nil
})
}
48 changes: 48 additions & 0 deletions x/lend/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const (
FlagSetAuctionParamsFile = "add-auction-params-file"
FlagAddLendPoolPairsFile = "add-lend-pool-pairs-file"
FlagAddAssetRatesPoolPairsFile = "add-asset-rates-pool-pairs-file"
FlagDepreciatePoolsFile = "depreciate-pools-file"
FlagAddEModePairsFile = "e-mode-pairs-file"
)

func ParseUint64SliceFromString(s string, separator string) ([]uint64, error) {
Expand Down Expand Up @@ -98,6 +100,34 @@ func FlagSetAuctionParams() *flag.FlagSet {
return fs
}

func FlagSetDepreciatePoolsMapping() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)

fs.String(FlagDepreciatePoolsFile, "", "depreciates existing pool, json file path")
return fs
}

func FlagAddEModePairs() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)

fs.String(FlagAddEModePairsFile, "", "enable e-mode for a pair, json file path")
return fs
}

func ParseDecSliceFromStringForDec(s string, separator string) ([]sdk.Dec, error) {
var newParsedDec []sdk.Dec
for _, s := range strings.Split(s, separator) {
s = strings.TrimSpace(s)

parsed, err := sdk.NewDecFromStr(s)
if err != nil {
return []sdk.Dec{}, err
}
newParsedDec = append(newParsedDec, parsed)
}
return newParsedDec, nil
}

type addNewLendPairsInputs struct {
AssetIn string `json:"asset_in"`
AssetOut string `json:"asset_out"`
Expand Down Expand Up @@ -189,7 +219,25 @@ type addAssetRatesPoolPairsInputs struct {
SupplyCap string `json:"supply_cap"`
CPoolName string `json:"c_pool_name"`
MinUSDValueLeft string `json:"min_usd_value_left"`
IsIsolated string `json:"is_isolated"`
Title string
Description string
Deposit string
}

type addDepreciatePoolsInputs struct {
PoolID string `json:"pool_id"`
Title string
Description string
Deposit string
}

type addEModePairsInputs struct {
PairID string `json:"pair_id"`
ELTV string `json:"e_ltv"`
ELiquidationThreshold string `json:"e_liquidation_threshold"`
ELiquidationPenalty string `json:"e_liquidation_penalty"`
Title string
Description string
Deposit string
}
Loading