Skip to content

Commit

Permalink
Merge pull request #686 from comdex-official/feature/dev
Browse files Browse the repository at this point in the history
Feature/dev
  • Loading branch information
dheerajkd30 authored Feb 17, 2023
2 parents 454e063 + 808328e commit aeab794
Show file tree
Hide file tree
Showing 62 changed files with 9,425 additions and 2,995 deletions.
15 changes: 11 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"sort"
"strings"

paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"

"github.com/gorilla/mux"
"github.com/spf13/cast"

Expand Down Expand Up @@ -72,7 +74,6 @@ import (
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
Expand Down Expand Up @@ -169,6 +170,7 @@ import (
mv6 "github.com/comdex-official/comdex/app/upgrades/mainnet/v6"
mv7 "github.com/comdex-official/comdex/app/upgrades/mainnet/v7"
mv8 "github.com/comdex-official/comdex/app/upgrades/mainnet/v8"
tv9 "github.com/comdex-official/comdex/app/upgrades/testnet/v9_0_0"
)

const (
Expand Down Expand Up @@ -203,6 +205,8 @@ func GetGovProposalHandlers() []govclient.ProposalHandler {
lendclient.AddAuctionParamsHandler,
lendclient.AddMultipleAssetToPairHandler,
lendclient.AddMultipleLendPairsHandler,
lendclient.AddPoolPairsHandler,
lendclient.AddAssetRatesPoolPairsHandler,
paramsclient.ProposalHandler,
distrclient.ProposalHandler,
upgradeclient.ProposalHandler,
Expand Down Expand Up @@ -1211,8 +1215,8 @@ func (a *App) ModuleAccountsPermissions() map[string][]string {

func (a *App) registerUpgradeHandlers() {
a.UpgradeKeeper.SetUpgradeHandler(
mv8.UpgradeName811,
mv8.CreateUpgradeHandler811(a.mm, a.configurator, a.AssetKeeper, a.LendKeeper, a.AuctionKeeper),
tv9.UpgradeName,
tv9.CreateUpgradeHandlerV900Beta(a.mm, a.configurator, a.AssetKeeper),
)
// When a planned update height is reached, the old binary will panic
// writing on disk the height and name of the update that triggered it
Expand Down Expand Up @@ -1271,9 +1275,12 @@ func upgradeHandlers(upgradeInfo storetypes.UpgradeInfo, a *App, storeUpgrades *

case upgradeInfo.Name == mv8.UpgradeName810 && !a.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height):
storeUpgrades = &storetypes.StoreUpgrades{}

case upgradeInfo.Name == mv8.UpgradeName811 && !a.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height):
storeUpgrades = &storetypes.StoreUpgrades{}

case upgradeInfo.Name == tv9.UpgradeName && !a.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height):
storeUpgrades = &storetypes.StoreUpgrades{}
}

return storeUpgrades
Expand Down
15 changes: 15 additions & 0 deletions app/upgrades/testnet/v9_0_0/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package v9_0_0 //nolint:revive,stylecheck

const (
UpgradeName = "v9.0.0"
UpgradeHeight = ""
UpgradeInfo = `'{
"binaries": {
"darwin/arm64":"",
"darwin/x86_64":"",
"linux/arm64":"",
"linux/x86_64":"",
"windows/x86_64":""
}
}'`
)
71 changes: 71 additions & 0 deletions app/upgrades/testnet/v9_0_0/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package v9_0_0 //nolint:revive,stylecheck

import (
assetkeeper "github.com/comdex-official/comdex/x/asset/keeper"
assettypes "github.com/comdex-official/comdex/x/asset/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

func UpdateDenomAndAddAsset(ctx sdk.Context, assetKeeper assetkeeper.Keeper) {
asset, found := assetKeeper.GetAsset(ctx, 17)
if found {
asset.Denom = "ibc/50EF138042B553362774A8A9DE967F610E52CAEB3BA864881C9A1436DED98075"
assetKeeper.SetAsset(ctx, asset)
}

assetGDAI := assettypes.Asset{Name: "GDAI", Denom: "ibc/109DD45CF4093BEB472784A0C5B5F4643140900020B74B102B842A4BE2AE45DA", Decimals: sdk.NewInt(1000000000000000000), IsOnChain: false, IsOraclePriceRequired: true, IsCdpMintable: false}

err := assetKeeper.AddAssetRecords(ctx, assetGDAI)
if err != nil {
return
}
getGDAI, found := assetKeeper.GetAssetForDenom(ctx, "ibc/109DD45CF4093BEB472784A0C5B5F4643140900020B74B102B842A4BE2AE45DA")
if !found {
return
}
var (
id = assetKeeper.GetPairID(ctx)
pairGDAI = assettypes.Pair{
Id: id + 1,
AssetIn: getGDAI.Id,
AssetOut: 3,
}
)

assetKeeper.SetPairID(ctx, pairGDAI.Id)
assetKeeper.SetPair(ctx, pairGDAI)

getSTOSMO, found := assetKeeper.GetAssetForDenom(ctx, "ibc/CC482813CC038C614C2615A997621EA5E605ADCCD4040B83B0468BD72533A165")
if !found {
return
}

var (
id2 = assetKeeper.GetPairID(ctx)
pairSTOSMO = assettypes.Pair{
Id: id2 + 1,
AssetIn: getSTOSMO.Id,
AssetOut: 3,
}
)

assetKeeper.SetPairID(ctx, pairSTOSMO.Id)
assetKeeper.SetPair(ctx, pairSTOSMO)
}

func CreateUpgradeHandlerV900Beta(
mm *module.Manager,
configurator module.Configurator,
assetKeeper assetkeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
vm, err := mm.RunMigrations(ctx, configurator, fromVM)
if err != nil {
return nil, err
}
UpdateDenomAndAddAsset(ctx, assetKeeper)
return vm, err
}
}
6 changes: 6 additions & 0 deletions proto/comdex/asset/v1beta1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,10 @@ message AddAssetInAppProposal {
string title = 1 [(gogoproto.moretags) = "yaml:\"title\""];
string description = 2 [(gogoproto.moretags) = "yaml:\"description\""];
AppData app = 3 [(gogoproto.nullable) = false];
}

message AddMultipleAssetsPairsProposal {
string title = 1 [(gogoproto.moretags) = "yaml:\"title\""];
string description = 2 [(gogoproto.moretags) = "yaml:\"description\""];
repeated AssetPair assetsPair = 3 [(gogoproto.nullable) = false];
}
14 changes: 14 additions & 0 deletions proto/comdex/asset/v1beta1/pair.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,18 @@ message PairInfo{
string denom_in = 3 [(gogoproto.moretags) = "yaml:\"denom\""];
uint64 asset_out = 4 [(gogoproto.moretags) = "yaml:\"asset_out\""];
string denom_out = 5 [(gogoproto.moretags) = "yaml:\"denom\""];
}

message AssetPair {
uint64 id = 1;
string name = 2 [(gogoproto.moretags) = "yaml:\"name\""];
string denom = 3 [(gogoproto.moretags) = "yaml:\"denom\""];
string decimals = 4 [
(gogoproto.moretags) = "yaml:\"decimals\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false];
bool is_on_chain = 5 [(gogoproto.moretags) = "yaml:\"is_on_chain\""];
bool is_oracle_price_required = 6 [(gogoproto.moretags) = "yaml:\"is_oracle_price_required\""];
bool is_cdp_mintable = 7 [(gogoproto.moretags) = "yaml:\"is_cdp_mintable\""];
uint64 asset_out = 8 [(gogoproto.moretags) = "yaml:\"asset_out\""];
}
12 changes: 12 additions & 0 deletions proto/comdex/lend/v1beta1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,15 @@ message AddAuctionParamsProposal {
string description = 2 [(gogoproto.moretags) = "yaml:\"description\""];
AuctionParams AuctionParams = 3 [(gogoproto.nullable) = false];
}

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

message AddAssetRatesPoolPairsProposal {
string title = 1 [(gogoproto.moretags) = "yaml:\"title\""];
string description = 2 [(gogoproto.moretags) = "yaml:\"description\""];
AssetRatesPoolPairs AssetRatesPoolPairs = 3 [(gogoproto.nullable) = false];
}
164 changes: 163 additions & 1 deletion proto/comdex/lend/v1beta1/lend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -577,4 +577,166 @@ message AssetToPairSingleMapping{
(gogoproto.customname) = "PairID",
(gogoproto.moretags) = "yaml:\"pair_id\""
];
}
}

message PoolPairs {
uint64 pool_id = 1 [
(gogoproto.customname) = "PoolID",
(gogoproto.moretags) = "yaml:\"pool_id\""
];

string module_name = 2 [
(gogoproto.customname) = "ModuleName",
(gogoproto.moretags) = "yaml:\"module_name\""
];

string cpool_name = 3 [
(gogoproto.customname) = "CPoolName",
(gogoproto.moretags) = "yaml:\"cpool_name\""
];

repeated AssetDataPoolMapping asset_data = 4 [
(gogoproto.customname) = "AssetData",
(gogoproto.moretags) = "yaml:\"asset_data\""
];

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

message PoolInterestData {
uint64 asset_id = 1 [
(gogoproto.customname) = "AssetID",
(gogoproto.moretags) = "yaml:\"asset_id\""
];
string lend_interest = 2 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"lend_interest\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"
];
}

message PoolInterest {
uint64 pool_id = 1 [
(gogoproto.customname) = "PoolID",
(gogoproto.moretags) = "yaml:\"pool_id\""
];
repeated PoolInterestData pool_interest_data = 2 [
(gogoproto.nullable) = false,
(gogoproto.customname) = "PoolInterestData",
(gogoproto.moretags) = "yaml:\"pool_interest_data\""
];
}

message PoolInterestDataB {
uint64 asset_id = 1 [
(gogoproto.customname) = "AssetID",
(gogoproto.moretags) = "yaml:\"asset_id\""
];
string borrow_interest = 2 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"borrow_interest\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"
];
}

message PoolInterestB {
uint64 pool_id = 1 [
(gogoproto.customname) = "PoolID",
(gogoproto.moretags) = "yaml:\"pool_id\""
];
repeated PoolInterestDataB pool_interest_data = 2 [
(gogoproto.nullable) = false,
(gogoproto.customname) = "PoolInterestData",
(gogoproto.moretags) = "yaml:\"pool_interest_data\""
];
}

message AssetRatesPoolPairs {
uint64 asset_id = 1 [
(gogoproto.customname) = "AssetID",
(gogoproto.moretags) = "yaml:\"asset_id\""
];
string u_optimal = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"u_optimal\""
];
string base = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"base\""
];
string slope1 = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"slope1\""
];
string slope2 = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"slope2\""
];
bool enable_stable_borrow = 6 [
(gogoproto.moretags) = "yaml:\"enable_stable_borrow\""
];
string stable_base = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"stable_base\""
];
string stable_slope1 = 8 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"stable_slope1\""
];
string stable_slope2 = 9 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"stable_slope2\""
];
string ltv = 10 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"ltv\""
];
string liquidation_threshold = 11 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"liquidation_threshold\""
];
string liquidation_penalty = 12 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"liquidation_penalty\""
];
string liquidation_bonus = 13 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"liquidation_bonus\""
];
string reserve_factor = 14 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"reserve_factor\""
];
uint64 c_asset_id = 15 [
(gogoproto.customname) = "CAssetID",
(gogoproto.moretags) = "yaml:\"c_asset_id\""
];

string module_name = 16 [
(gogoproto.customname) = "ModuleName",
(gogoproto.moretags) = "yaml:\"module_name\""
];
string cpool_name = 17 [
(gogoproto.customname) = "CPoolName",
(gogoproto.moretags) = "yaml:\"cpool_name\""
];
repeated AssetDataPoolMapping asset_data = 18 [
(gogoproto.customname) = "AssetData",
(gogoproto.moretags) = "yaml:\"asset_data\""
];
uint64 min_usd_value_left = 19 [
(gogoproto.moretags) = "yaml:\"min_usd_value_left\""];
}
Loading

0 comments on commit aeab794

Please sign in to comment.