From 208f4870c0fbac1d0e133fc4b60fa9a709270805 Mon Sep 17 00:00:00 2001 From: Pratik Date: Mon, 6 Nov 2023 10:45:08 +0530 Subject: [PATCH 01/10] added auction migration for V2 --- .../testnet/v13/auctions_migration.go | 168 ++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 app/upgrades/testnet/v13/auctions_migration.go diff --git a/app/upgrades/testnet/v13/auctions_migration.go b/app/upgrades/testnet/v13/auctions_migration.go new file mode 100644 index 000000000..9ff001b15 --- /dev/null +++ b/app/upgrades/testnet/v13/auctions_migration.go @@ -0,0 +1,168 @@ +package v13 + +import ( + assetkeeper "github.com/comdex-official/comdex/x/asset/keeper" + auctionkeeperold "github.com/comdex-official/comdex/x/auction/keeper" + auctionkeeper "github.com/comdex-official/comdex/x/auctionsV2/keeper" + auctionsV2types "github.com/comdex-official/comdex/x/auctionsV2/types" + liquidationkeeperold "github.com/comdex-official/comdex/x/liquidation/keeper" + liquidationtypesold "github.com/comdex-official/comdex/x/liquidation/types" + liquidationkeeper "github.com/comdex-official/comdex/x/liquidationsV2/keeper" + liquidationtypes "github.com/comdex-official/comdex/x/liquidationsV2/types" + marketkeeper "github.com/comdex-official/comdex/x/market/keeper" + vaultkeeper "github.com/comdex-official/comdex/x/vault/keeper" + vaultTypes "github.com/comdex-official/comdex/x/vault/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "time" +) + +func ReturnCoin(ctx sdk.Context, assetKeeper assetkeeper.Keeper, assetID uint64, amount sdk.Int) sdk.Coin { + asset, _ := assetKeeper.GetAsset(ctx, assetID) + return sdk.NewCoin(asset.Denom, amount) +} + +func MigrateAuctionsHarbor( + ctx sdk.Context, + assetKeeper assetkeeper.Keeper, + auctionKeeperOld auctionkeeperold.Keeper, + auctionKeeper auctionkeeper.Keeper, + liquidationKeeperOld liquidationkeeperold.Keeper, + liquidationKeeper liquidationkeeper.Keeper, + marketKeeper marketkeeper.Keeper, + vaultKeeper vaultkeeper.Keeper, +) { + // first get all the auctions and their locked vaults and set them in new LiquidationsV2, + // if locked vault is not available create a new locked vault + // get all the auction and set them accordingly in new auctionV2 + + auctionsOld := auctionKeeperOld.GetDutchAuctions(ctx, 2) + if len(auctionsOld) != 0 { + for _, auction := range auctionsOld { + liquidationData, found := liquidationKeeperOld.GetLockedVault(ctx, 2, auction.LockedVaultId) + if !found { + //todo + // create logic for generating locked vault from auction data + var vault vaultTypes.Vault + userVaults, _ := vaultKeeper.GetUserAppMappingData(ctx, auction.VaultOwner.String(), 2) + // loop into vaults and check if asset in and asset out are matching + for _, userVaultMap := range userVaults { + extPair, _ := assetKeeper.GetPairsVault(ctx, userVaultMap.ExtendedPairId) + pair, _ := assetKeeper.GetPair(ctx, extPair.PairId) + if pair.AssetIn == auction.AssetInId && pair.AssetOut == auction.AssetOutId { + vault, _ = vaultKeeper.GetVault(ctx, userVaultMap.VaultId) + } + } + extPair, _ := assetKeeper.GetPairsVault(ctx, vault.ExtendedPairVaultID) + pair, _ := assetKeeper.GetPair(ctx, extPair.PairId) + assetIn, _ := assetKeeper.GetAsset(ctx, pair.AssetIn) + totalIn, _ := marketKeeper.CalcAssetPrice(ctx, assetIn.Id, vault.AmountIn) + + totalFees := vault.InterestAccumulated.Add(vault.ClosingFeeAccumulated) + liquidationData = liquidationtypesold.LockedVault{ + AppId: 2, + OriginalVaultId: vault.Id, + ExtendedPairId: vault.ExtendedPairVaultID, + Owner: vault.Owner, + AmountIn: vault.AmountIn, + AmountOut: vault.AmountOut, + UpdatedAmountOut: vault.AmountOut.Add(vault.InterestAccumulated), + Initiator: "liquidationV1", + IsAuctionComplete: false, + IsAuctionInProgress: true, + CrAtLiquidation: sdk.ZeroDec(), + CurrentCollaterlisationRatio: sdk.ZeroDec(), + CollateralToBeAuctioned: totalIn, + LiquidationTimestamp: ctx.BlockTime(), + SellOffHistory: nil, + InterestAccumulated: totalFees, + Kind: nil, + } + } + + lockedVaultID := liquidationKeeper.GetLockedVaultID(ctx) + extPair, _ := assetKeeper.GetPairsVault(ctx, liquidationData.ExtendedPairId) + pair, _ := assetKeeper.GetPair(ctx, extPair.PairId) + feesToBeCollected := sdk.NewDecFromInt(liquidationData.AmountOut).Mul(extPair.LiquidationPenalty).TruncateInt() + newLockedVault := liquidationtypes.LockedVault{ + LockedVaultId: lockedVaultID + 1, + AppId: 2, + OriginalVaultId: liquidationData.OriginalVaultId, + ExtendedPairId: liquidationData.ExtendedPairId, + Owner: liquidationData.Owner, + CollateralToken: ReturnCoin(ctx, assetKeeper, pair.AssetIn, liquidationData.AmountIn), + DebtToken: ReturnCoin(ctx, assetKeeper, pair.AssetOut, liquidationData.AmountOut), + CurrentCollaterlisationRatio: liquidationData.CrAtLiquidation, + CollateralToBeAuctioned: ReturnCoin(ctx, assetKeeper, pair.AssetIn, liquidationData.AmountIn), + TargetDebt: ReturnCoin(ctx, assetKeeper, pair.AssetOut, liquidationData.AmountOut.Add(feesToBeCollected)), + LiquidationTimestamp: liquidationData.LiquidationTimestamp, + IsInternalKeeper: false, + InternalKeeperAddress: "", + ExternalKeeperAddress: "", + FeeToBeCollected: feesToBeCollected, + BonusToBeGiven: sdk.ZeroInt(), + InitiatorType: "vault", + AuctionType: true, + IsDebtCmst: true, + CollateralAssetId: pair.AssetIn, + DebtAssetId: pair.AssetOut, + } + // set locked vault id + liquidationKeeper.SetLockedVaultID(ctx, newLockedVault.LockedVaultId) + // set new locked vault + liquidationKeeper.SetLockedVault(ctx, newLockedVault) + + // now migrate old auctions data to new module + auctionID := auctionKeeper.GetAuctionID(ctx) + + twaDataCollateral, found := marketKeeper.GetTwa(ctx, newLockedVault.CollateralAssetId) + if !found || !twaDataCollateral.IsPriceActive { + return + } + twaDataDebt, found := marketKeeper.GetTwa(ctx, newLockedVault.DebtAssetId) + if !found || !twaDataDebt.IsPriceActive { + return + } + liquidationWhitelistingAppData, _ := liquidationKeeper.GetLiquidationWhiteListing(ctx, liquidationData.AppId) + dutchAuctionParams := liquidationWhitelistingAppData.DutchAuctionParam + auctionParams, _ := auctionKeeper.GetAuctionParams(ctx) + + CollateralTokenInitialPrice := auctionKeeper.GetCollalteralTokenInitialPrice(sdk.NewIntFromUint64(twaDataCollateral.Twa), dutchAuctionParams.Premium) + + newAuction := auctionsV2types.Auction{ + AuctionId: auctionID + 1, + CollateralToken: auction.OutflowTokenCurrentAmount, // outflow + DebtToken: auction.InflowTokenCurrentAmount, // inflow + ActiveBiddingId: 0, + BiddingIds: nil, + CollateralTokenAuctionPrice: CollateralTokenInitialPrice, + CollateralTokenOraclePrice: sdk.NewDecFromInt(sdk.NewInt(int64(twaDataCollateral.Twa))), + DebtTokenOraclePrice: sdk.NewDecFromInt(sdk.NewInt(int64(twaDataDebt.Twa))), + LockedVaultId: newLockedVault.LockedVaultId, + StartTime: ctx.BlockTime(), + EndTime: ctx.BlockTime().Add(time.Second * time.Duration(auctionParams.AuctionDurationSeconds)), + AppId: newLockedVault.AppId, + AuctionType: newLockedVault.AuctionType, + CollateralAssetId: newLockedVault.CollateralAssetId, + DebtAssetId: newLockedVault.DebtAssetId, + BonusAmount: newLockedVault.BonusToBeGiven, + CollateralTokenInitialPrice: CollateralTokenInitialPrice, + } + // update auction ID + auctionKeeper.SetAuctionID(ctx, newAuction.AuctionId) + + // migrate old auctions to new module + err := auctionKeeper.SetAuction(ctx, newAuction) + if err != nil { + return + } + + // delete old auctions and locked vaults + // first create a history of both of them then delete + liquidationKeeperOld.SetLockedVaultHistory(ctx, liquidationData, liquidationData.LockedVaultId) + err = auctionKeeperOld.SetHistoryDutchAuction(ctx, auction) + if err != nil { + return + } + } + } +} From eb247c155bb1de7afa95f56b3b24ffc5d067f65f Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Tue, 7 Nov 2023 15:51:40 +0530 Subject: [PATCH 02/10] v13 mainnet upgrade handler added --- .../mainnet/v13/auctions_migration.go | 168 +++++++++++ app/upgrades/mainnet/v13/constants.go | 15 + app/upgrades/mainnet/v13/upgrade_test.go | 64 ++++ app/upgrades/mainnet/v13/upgrades.go | 282 ++++++++++++++++++ 4 files changed, 529 insertions(+) create mode 100644 app/upgrades/mainnet/v13/auctions_migration.go create mode 100644 app/upgrades/mainnet/v13/constants.go create mode 100644 app/upgrades/mainnet/v13/upgrade_test.go create mode 100644 app/upgrades/mainnet/v13/upgrades.go diff --git a/app/upgrades/mainnet/v13/auctions_migration.go b/app/upgrades/mainnet/v13/auctions_migration.go new file mode 100644 index 000000000..9ff001b15 --- /dev/null +++ b/app/upgrades/mainnet/v13/auctions_migration.go @@ -0,0 +1,168 @@ +package v13 + +import ( + assetkeeper "github.com/comdex-official/comdex/x/asset/keeper" + auctionkeeperold "github.com/comdex-official/comdex/x/auction/keeper" + auctionkeeper "github.com/comdex-official/comdex/x/auctionsV2/keeper" + auctionsV2types "github.com/comdex-official/comdex/x/auctionsV2/types" + liquidationkeeperold "github.com/comdex-official/comdex/x/liquidation/keeper" + liquidationtypesold "github.com/comdex-official/comdex/x/liquidation/types" + liquidationkeeper "github.com/comdex-official/comdex/x/liquidationsV2/keeper" + liquidationtypes "github.com/comdex-official/comdex/x/liquidationsV2/types" + marketkeeper "github.com/comdex-official/comdex/x/market/keeper" + vaultkeeper "github.com/comdex-official/comdex/x/vault/keeper" + vaultTypes "github.com/comdex-official/comdex/x/vault/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "time" +) + +func ReturnCoin(ctx sdk.Context, assetKeeper assetkeeper.Keeper, assetID uint64, amount sdk.Int) sdk.Coin { + asset, _ := assetKeeper.GetAsset(ctx, assetID) + return sdk.NewCoin(asset.Denom, amount) +} + +func MigrateAuctionsHarbor( + ctx sdk.Context, + assetKeeper assetkeeper.Keeper, + auctionKeeperOld auctionkeeperold.Keeper, + auctionKeeper auctionkeeper.Keeper, + liquidationKeeperOld liquidationkeeperold.Keeper, + liquidationKeeper liquidationkeeper.Keeper, + marketKeeper marketkeeper.Keeper, + vaultKeeper vaultkeeper.Keeper, +) { + // first get all the auctions and their locked vaults and set them in new LiquidationsV2, + // if locked vault is not available create a new locked vault + // get all the auction and set them accordingly in new auctionV2 + + auctionsOld := auctionKeeperOld.GetDutchAuctions(ctx, 2) + if len(auctionsOld) != 0 { + for _, auction := range auctionsOld { + liquidationData, found := liquidationKeeperOld.GetLockedVault(ctx, 2, auction.LockedVaultId) + if !found { + //todo + // create logic for generating locked vault from auction data + var vault vaultTypes.Vault + userVaults, _ := vaultKeeper.GetUserAppMappingData(ctx, auction.VaultOwner.String(), 2) + // loop into vaults and check if asset in and asset out are matching + for _, userVaultMap := range userVaults { + extPair, _ := assetKeeper.GetPairsVault(ctx, userVaultMap.ExtendedPairId) + pair, _ := assetKeeper.GetPair(ctx, extPair.PairId) + if pair.AssetIn == auction.AssetInId && pair.AssetOut == auction.AssetOutId { + vault, _ = vaultKeeper.GetVault(ctx, userVaultMap.VaultId) + } + } + extPair, _ := assetKeeper.GetPairsVault(ctx, vault.ExtendedPairVaultID) + pair, _ := assetKeeper.GetPair(ctx, extPair.PairId) + assetIn, _ := assetKeeper.GetAsset(ctx, pair.AssetIn) + totalIn, _ := marketKeeper.CalcAssetPrice(ctx, assetIn.Id, vault.AmountIn) + + totalFees := vault.InterestAccumulated.Add(vault.ClosingFeeAccumulated) + liquidationData = liquidationtypesold.LockedVault{ + AppId: 2, + OriginalVaultId: vault.Id, + ExtendedPairId: vault.ExtendedPairVaultID, + Owner: vault.Owner, + AmountIn: vault.AmountIn, + AmountOut: vault.AmountOut, + UpdatedAmountOut: vault.AmountOut.Add(vault.InterestAccumulated), + Initiator: "liquidationV1", + IsAuctionComplete: false, + IsAuctionInProgress: true, + CrAtLiquidation: sdk.ZeroDec(), + CurrentCollaterlisationRatio: sdk.ZeroDec(), + CollateralToBeAuctioned: totalIn, + LiquidationTimestamp: ctx.BlockTime(), + SellOffHistory: nil, + InterestAccumulated: totalFees, + Kind: nil, + } + } + + lockedVaultID := liquidationKeeper.GetLockedVaultID(ctx) + extPair, _ := assetKeeper.GetPairsVault(ctx, liquidationData.ExtendedPairId) + pair, _ := assetKeeper.GetPair(ctx, extPair.PairId) + feesToBeCollected := sdk.NewDecFromInt(liquidationData.AmountOut).Mul(extPair.LiquidationPenalty).TruncateInt() + newLockedVault := liquidationtypes.LockedVault{ + LockedVaultId: lockedVaultID + 1, + AppId: 2, + OriginalVaultId: liquidationData.OriginalVaultId, + ExtendedPairId: liquidationData.ExtendedPairId, + Owner: liquidationData.Owner, + CollateralToken: ReturnCoin(ctx, assetKeeper, pair.AssetIn, liquidationData.AmountIn), + DebtToken: ReturnCoin(ctx, assetKeeper, pair.AssetOut, liquidationData.AmountOut), + CurrentCollaterlisationRatio: liquidationData.CrAtLiquidation, + CollateralToBeAuctioned: ReturnCoin(ctx, assetKeeper, pair.AssetIn, liquidationData.AmountIn), + TargetDebt: ReturnCoin(ctx, assetKeeper, pair.AssetOut, liquidationData.AmountOut.Add(feesToBeCollected)), + LiquidationTimestamp: liquidationData.LiquidationTimestamp, + IsInternalKeeper: false, + InternalKeeperAddress: "", + ExternalKeeperAddress: "", + FeeToBeCollected: feesToBeCollected, + BonusToBeGiven: sdk.ZeroInt(), + InitiatorType: "vault", + AuctionType: true, + IsDebtCmst: true, + CollateralAssetId: pair.AssetIn, + DebtAssetId: pair.AssetOut, + } + // set locked vault id + liquidationKeeper.SetLockedVaultID(ctx, newLockedVault.LockedVaultId) + // set new locked vault + liquidationKeeper.SetLockedVault(ctx, newLockedVault) + + // now migrate old auctions data to new module + auctionID := auctionKeeper.GetAuctionID(ctx) + + twaDataCollateral, found := marketKeeper.GetTwa(ctx, newLockedVault.CollateralAssetId) + if !found || !twaDataCollateral.IsPriceActive { + return + } + twaDataDebt, found := marketKeeper.GetTwa(ctx, newLockedVault.DebtAssetId) + if !found || !twaDataDebt.IsPriceActive { + return + } + liquidationWhitelistingAppData, _ := liquidationKeeper.GetLiquidationWhiteListing(ctx, liquidationData.AppId) + dutchAuctionParams := liquidationWhitelistingAppData.DutchAuctionParam + auctionParams, _ := auctionKeeper.GetAuctionParams(ctx) + + CollateralTokenInitialPrice := auctionKeeper.GetCollalteralTokenInitialPrice(sdk.NewIntFromUint64(twaDataCollateral.Twa), dutchAuctionParams.Premium) + + newAuction := auctionsV2types.Auction{ + AuctionId: auctionID + 1, + CollateralToken: auction.OutflowTokenCurrentAmount, // outflow + DebtToken: auction.InflowTokenCurrentAmount, // inflow + ActiveBiddingId: 0, + BiddingIds: nil, + CollateralTokenAuctionPrice: CollateralTokenInitialPrice, + CollateralTokenOraclePrice: sdk.NewDecFromInt(sdk.NewInt(int64(twaDataCollateral.Twa))), + DebtTokenOraclePrice: sdk.NewDecFromInt(sdk.NewInt(int64(twaDataDebt.Twa))), + LockedVaultId: newLockedVault.LockedVaultId, + StartTime: ctx.BlockTime(), + EndTime: ctx.BlockTime().Add(time.Second * time.Duration(auctionParams.AuctionDurationSeconds)), + AppId: newLockedVault.AppId, + AuctionType: newLockedVault.AuctionType, + CollateralAssetId: newLockedVault.CollateralAssetId, + DebtAssetId: newLockedVault.DebtAssetId, + BonusAmount: newLockedVault.BonusToBeGiven, + CollateralTokenInitialPrice: CollateralTokenInitialPrice, + } + // update auction ID + auctionKeeper.SetAuctionID(ctx, newAuction.AuctionId) + + // migrate old auctions to new module + err := auctionKeeper.SetAuction(ctx, newAuction) + if err != nil { + return + } + + // delete old auctions and locked vaults + // first create a history of both of them then delete + liquidationKeeperOld.SetLockedVaultHistory(ctx, liquidationData, liquidationData.LockedVaultId) + err = auctionKeeperOld.SetHistoryDutchAuction(ctx, auction) + if err != nil { + return + } + } + } +} diff --git a/app/upgrades/mainnet/v13/constants.go b/app/upgrades/mainnet/v13/constants.go new file mode 100644 index 000000000..907aeb69b --- /dev/null +++ b/app/upgrades/mainnet/v13/constants.go @@ -0,0 +1,15 @@ +package v13 + +const ( + UpgradeName = "v13.1.0" + UpgradeHeight = "" + UpgradeInfo = `'{ + "binaries": { + "darwin/arm64":"", + "darwin/x86_64":"", + "linux/arm64":"", + "linux/x86_64":"", + "windows/x86_64":"" + } + }'` +) diff --git a/app/upgrades/mainnet/v13/upgrade_test.go b/app/upgrades/mainnet/v13/upgrade_test.go new file mode 100644 index 000000000..be9f1a70f --- /dev/null +++ b/app/upgrades/mainnet/v13/upgrade_test.go @@ -0,0 +1,64 @@ +package v13_test + +import ( + "testing" + + "github.com/stretchr/testify/suite" + + "github.com/comdex-official/comdex/app" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + v13 "github.com/comdex-official/comdex/app/upgrades/testnet/v13" +) + +type UpgradeTestSuite struct { + app.KeeperTestHelper +} + +func (s *UpgradeTestSuite) SetupTest() { + s.Setup() +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(UpgradeTestSuite)) +} + +// Ensures the test does not error out. +func (s *UpgradeTestSuite) TestUpgrade() { + s.Setup() + + preUpgradeChecks(s) + + upgradeHeight := int64(5) + s.ConfirmUpgradeSucceeded(v13.UpgradeName, upgradeHeight) + + postUpgradeChecks(s) +} + +func preUpgradeChecks(s *UpgradeTestSuite) { + + mp := s.App.MintKeeper.GetParams(s.Ctx) + s.Require().Equal(mp.BlocksPerYear, uint64(6311520)) + + sp := s.App.SlashingKeeper.GetParams(s.Ctx) + s.Require().Equal(sp.SignedBlocksWindow, int64(100)) + +} + +func postUpgradeChecks(s *UpgradeTestSuite) { + + // Ensure the gov params have MinInitialDepositRatio added + gp := s.App.GovKeeper.GetParams(s.Ctx) + s.Require().Equal(gp.MinInitialDepositRatio, "0.200000000000000000") + + // Ensure the mint params have doubled + mp := s.App.MintKeeper.GetParams(s.Ctx) + s.Require().Equal(mp.BlocksPerYear, uint64(6311520*2)) + + // Ensure the slashing params have doubled + sp := s.App.SlashingKeeper.GetParams(s.Ctx) + s.Require().Equal(sp.SignedBlocksWindow, int64(100*2)) + + // Ensure the wasm Permissionless + wp := s.App.WasmKeeper.GetParams(s.Ctx) + s.Require().Equal(wp.CodeUploadAccess, wasmtypes.AllowEverybody) +} diff --git a/app/upgrades/mainnet/v13/upgrades.go b/app/upgrades/mainnet/v13/upgrades.go new file mode 100644 index 000000000..cf4dddb21 --- /dev/null +++ b/app/upgrades/mainnet/v13/upgrades.go @@ -0,0 +1,282 @@ +package v13 + +import ( + "fmt" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + assetkeeper "github.com/comdex-official/comdex/x/asset/keeper" + assettypes "github.com/comdex-official/comdex/x/asset/types" + auctionV2keeper "github.com/comdex-official/comdex/x/auctionsV2/keeper" + auctionsV2types "github.com/comdex-official/comdex/x/auctionsV2/types" + bandoraclemodulekeeper "github.com/comdex-official/comdex/x/bandoracle/keeper" + lendkeeper "github.com/comdex-official/comdex/x/lend/keeper" + lendtypes "github.com/comdex-official/comdex/x/lend/types" + liquidationV2keeper "github.com/comdex-official/comdex/x/liquidationsV2/keeper" + liquidationV2types "github.com/comdex-official/comdex/x/liquidationsV2/types" + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" + consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" + govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" + mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + icqkeeper "github.com/cosmos/ibc-apps/modules/async-icq/v7/keeper" + icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types" + exported "github.com/cosmos/ibc-go/v7/modules/core/exported" + ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" + ibctmmigrations "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint/migrations" +) + +func CreateUpgradeHandlerV13( + mm *module.Manager, + configurator module.Configurator, + cdc codec.Codec, + capabilityStoreKey *storetypes.KVStoreKey, + capabilityKeeper *capabilitykeeper.Keeper, + wasmKeeper wasmkeeper.Keeper, + paramsKeeper paramskeeper.Keeper, + consensusParamsKeeper consensusparamkeeper.Keeper, + IBCKeeper ibckeeper.Keeper, + icqkeeper *icqkeeper.Keeper, + GovKeeper govkeeper.Keeper, + StakingKeeper stakingkeeper.Keeper, + MintKeeper mintkeeper.Keeper, + SlashingKeeper slashingkeeper.Keeper, + bandoracleKeeper bandoraclemodulekeeper.Keeper, + assetKeeper assetkeeper.Keeper, + lendKeeper lendkeeper.Keeper, + liquidationV2Keeper liquidationV2keeper.Keeper, + auctionV2Keeper auctionV2keeper.Keeper, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + ctx.Logger().Info("Applying main net upgrade - v.13.1.0") + logger := ctx.Logger().With("upgrade", UpgradeName) + + // Migrate Tendermint consensus parameters from x/params module to a deprecated x/consensus module. + // The old params module is required to still be imported in your app.go in order to handle this migration. + ctx.Logger().Info("Migrating tendermint consensus params from x/params to x/consensus...") + legacyParamSubspace := paramsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) + baseapp.MigrateParams(ctx, legacyParamSubspace, &consensusParamsKeeper) + + // ibc v4-to-v5 + // https://github.com/cosmos/ibc-go/blob/v7.1.0/docs/migrations/v4-to-v5.md + // -- nothing -- + + // TODO: check if v5-v6 is required ?? + // https://github.com/cosmos/ibc-go/blob/v7.1.0/docs/migrations/v5-to-v6.md + + // ibc v6-to-v7 + // https://github.com/cosmos/ibc-go/blob/v7.1.0/docs/migrations/v6-to-v7.md#chains + // (optional) prune expired tendermint consensus states to save storage space + ctx.Logger().Info("Pruning expired tendermint consensus states...") + if _, err := ibctmmigrations.PruneExpiredConsensusStates(ctx, cdc, IBCKeeper.ClientKeeper); err != nil { + return nil, err + } + + // ibc v7-to-v7.1 + // https://github.com/cosmos/ibc-go/blob/v7.1.0/docs/migrations/v7-to-v7_1.md#09-localhost-migration + // explicitly update the IBC 02-client params, adding the localhost client type + params := IBCKeeper.ClientKeeper.GetParams(ctx) + params.AllowedClients = append(params.AllowedClients, exported.Localhost) + IBCKeeper.ClientKeeper.SetParams(ctx, params) + logger.Info(fmt.Sprintf("updated ibc client params %v", params)) + + // icq params set + icqparams := icqtypes.DefaultParams() + icqparams.AllowQueries = append(icqparams.AllowQueries, "/cosmwasm.wasm.v1.Query/SmartContractState") + icqkeeper.SetParams(ctx, icqparams) + + // Run migrations + logger.Info(fmt.Sprintf("pre migrate version map: %v", fromVM)) + vm, err := mm.RunMigrations(ctx, configurator, fromVM) + if err != nil { + return nil, err + } + logger.Info(fmt.Sprintf("post migrate version map: %v", vm)) + + //TODO: confirm the initial deposit + // update gov params to use a 20% initial deposit ratio, allowing us to remote the ante handler + govParams := GovKeeper.GetParams(ctx) + govParams.MinInitialDepositRatio = sdk.NewDec(20).Quo(sdk.NewDec(100)).String() + if err := GovKeeper.SetParams(ctx, govParams); err != nil { + return nil, err + } + logger.Info(fmt.Sprintf("updated gov params to %v", govParams)) + + // x/Mint + // Double blocks per year (from 6 seconds to 3 = 2x blocks per year) + mintParams := MintKeeper.GetParams(ctx) + mintParams.BlocksPerYear *= 2 + if err = MintKeeper.SetParams(ctx, mintParams); err != nil { + return nil, err + } + logger.Info(fmt.Sprintf("updated minted blocks per year logic to %v", mintParams)) + + // x/Slashing + // Double slashing window due to double blocks per year + slashingParams := SlashingKeeper.GetParams(ctx) + slashingParams.SignedBlocksWindow *= 2 + if err := SlashingKeeper.SetParams(ctx, slashingParams); err != nil { + return nil, err + } + logger.Info(fmt.Sprintf("updated slashing params to %v", slashingParams)) + + // update wasm to permissionless + wasmParams := wasmKeeper.GetParams(ctx) + wasmParams.CodeUploadAccess = wasmtypes.AllowEverybody + wasmKeeper.SetParams(ctx, wasmParams) + logger.Info(fmt.Sprintf("updated wasm params to %v", wasmParams)) + + // update discard BH of oracle + bandData := bandoracleKeeper.GetFetchPriceMsg(ctx) + if bandData.Size() > 0 { + bandData.AcceptedHeightDiff = 6000 + bandoracleKeeper.SetFetchPriceMsg(ctx, bandData) + logger.Info(fmt.Sprintf("updated bandData to %v", bandData)) + } + + UpdateLendParams(ctx, lendKeeper, assetKeeper) + InitializeStates(ctx, liquidationV2Keeper, auctionV2Keeper) + + return vm, err + } +} + +func UpdateLendParams( + ctx sdk.Context, + lendKeeper lendkeeper.Keeper, + assetKeeper assetkeeper.Keeper, +) { + + cSTATOM := assettypes.Asset{ + Name: "CSTATOM", + Denom: "ucstatom", + Decimals: sdk.NewInt(1000000), + IsOnChain: true, + IsOraclePriceRequired: false, + IsCdpMintable: true, + } + err := assetKeeper.AddAssetRecords(ctx, cSTATOM) + if err != nil { + fmt.Println(err) + } + assetID := assetKeeper.GetAssetID(ctx) + + assetRatesParamsSTAtom := lendtypes.AssetRatesParams{ + AssetID: 14, + UOptimal: newDec("0.75"), + Base: newDec("0.002"), + Slope1: newDec("0.07"), + Slope2: newDec("1.25"), + EnableStableBorrow: false, + Ltv: newDec("0.7"), + LiquidationThreshold: newDec("0.75"), + LiquidationPenalty: newDec("0.05"), + LiquidationBonus: newDec("0.05"), + ReserveFactor: newDec("0.2"), + CAssetID: assetID, + IsIsolated: false, + } + lendKeeper.SetAssetRatesParams(ctx, assetRatesParamsSTAtom) + + assetRatesParamsCmdx, _ := lendKeeper.GetAssetRatesParams(ctx, 2) + assetRatesParamsCmdx.LiquidationPenalty = newDec("0.075") + assetRatesParamsCmdx.LiquidationBonus = newDec("0.075") + lendKeeper.SetAssetRatesParams(ctx, assetRatesParamsCmdx) + + assetRatesParamsCmst, _ := lendKeeper.GetAssetRatesParams(ctx, 3) + assetRatesParamsCmst.LiquidationPenalty = newDec("0.05") + assetRatesParamsCmst.LiquidationBonus = newDec("0.05") + lendKeeper.SetAssetRatesParams(ctx, assetRatesParamsCmst) + + cAXLUSDC := assettypes.Asset{ + Name: "CAXLUSDC", + Denom: "ucaxlusdc", + Decimals: sdk.NewInt(1000000), + IsOnChain: true, + IsOraclePriceRequired: false, + IsCdpMintable: true, + } + err = assetKeeper.AddAssetRecords(ctx, cAXLUSDC) + if err != nil { + fmt.Println(err) + } +} + +func InitializeStates( + ctx sdk.Context, + liquidationKeeper liquidationV2keeper.Keeper, + auctionKeeper auctionV2keeper.Keeper, +) { + dutchAuctionParams := liquidationV2types.DutchAuctionParam{ + Premium: newDec("1.15"), + Discount: newDec("0.7"), + DecrementFactor: sdk.NewInt(1), + } + englishAuctionParams := liquidationV2types.EnglishAuctionParam{DecrementFactor: sdk.NewInt(1)} + + harborParams := liquidationV2types.LiquidationWhiteListing{ + AppId: 2, + Initiator: true, + IsDutchActivated: true, + DutchAuctionParam: &dutchAuctionParams, + IsEnglishActivated: true, + EnglishAuctionParam: &englishAuctionParams, + KeeeperIncentive: sdk.ZeroDec(), + } + + commodoParams := liquidationV2types.LiquidationWhiteListing{ + AppId: 3, + Initiator: true, + IsDutchActivated: true, + DutchAuctionParam: &dutchAuctionParams, + IsEnglishActivated: false, + EnglishAuctionParam: nil, + KeeeperIncentive: sdk.ZeroDec(), + } + + liquidationKeeper.SetLiquidationWhiteListing(ctx, harborParams) + liquidationKeeper.SetLiquidationWhiteListing(ctx, commodoParams) + + appReserveFundsTxDataHbr, found := liquidationKeeper.GetAppReserveFundsTxData(ctx, 2) + if !found { + appReserveFundsTxDataHbr.AppId = 2 + } + appReserveFundsTxDataHbr.AssetTxData = append(appReserveFundsTxDataHbr.AssetTxData, liquidationV2types.AssetTxData{}) + liquidationKeeper.SetAppReserveFundsTxData(ctx, appReserveFundsTxDataHbr) + + appReserveFundsTxDataCmdo, found := liquidationKeeper.GetAppReserveFundsTxData(ctx, 3) + if !found { + appReserveFundsTxDataCmdo.AppId = 3 + } + appReserveFundsTxDataCmdo.AssetTxData = append(appReserveFundsTxDataCmdo.AssetTxData, liquidationV2types.AssetTxData{}) + liquidationKeeper.SetAppReserveFundsTxData(ctx, appReserveFundsTxDataCmdo) + + auctionParams := auctionsV2types.AuctionParams{ + AuctionDurationSeconds: 18000, + Step: newDec("0.1"), + WithdrawalFee: newDec("0.0005"), + ClosingFee: newDec("0.0005"), + MinUsdValueLeft: 100000, + BidFactor: newDec("0.01"), + LiquidationPenalty: newDec("0.1"), + AuctionBonus: newDec("0.0"), + } + auctionKeeper.SetAuctionParams(ctx, auctionParams) + auctionKeeper.SetParams(ctx, auctionsV2types.Params{}) + auctionKeeper.SetAuctionID(ctx, 0) + auctionKeeper.SetUserBidID(ctx, 0) + +} + +func newDec(i string) sdk.Dec { + dec, _ := sdk.NewDecFromStr(i) + return dec +} From 3877dbdd5acc44f26814a06dc52d9d13ad7559a0 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Tue, 7 Nov 2023 16:00:47 +0530 Subject: [PATCH 03/10] testnet upgrade tc commented --- app/upgrades/testnet/v13/upgrade_test.go | 88 ++++++++++++------------ 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/app/upgrades/testnet/v13/upgrade_test.go b/app/upgrades/testnet/v13/upgrade_test.go index be9f1a70f..41cbb1b72 100644 --- a/app/upgrades/testnet/v13/upgrade_test.go +++ b/app/upgrades/testnet/v13/upgrade_test.go @@ -1,64 +1,64 @@ package v13_test -import ( - "testing" +// import ( +// "testing" - "github.com/stretchr/testify/suite" +// "github.com/stretchr/testify/suite" - "github.com/comdex-official/comdex/app" - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - v13 "github.com/comdex-official/comdex/app/upgrades/testnet/v13" -) +// "github.com/comdex-official/comdex/app" +// wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" +// v13 "github.com/comdex-official/comdex/app/upgrades/testnet/v13" +// ) -type UpgradeTestSuite struct { - app.KeeperTestHelper -} +// type UpgradeTestSuite struct { +// app.KeeperTestHelper +// } -func (s *UpgradeTestSuite) SetupTest() { - s.Setup() -} +// func (s *UpgradeTestSuite) SetupTest() { +// s.Setup() +// } -func TestKeeperTestSuite(t *testing.T) { - suite.Run(t, new(UpgradeTestSuite)) -} +// func TestKeeperTestSuite(t *testing.T) { +// suite.Run(t, new(UpgradeTestSuite)) +// } -// Ensures the test does not error out. -func (s *UpgradeTestSuite) TestUpgrade() { - s.Setup() +// // Ensures the test does not error out. +// func (s *UpgradeTestSuite) TestUpgrade() { +// s.Setup() - preUpgradeChecks(s) +// preUpgradeChecks(s) - upgradeHeight := int64(5) - s.ConfirmUpgradeSucceeded(v13.UpgradeName, upgradeHeight) +// upgradeHeight := int64(5) +// s.ConfirmUpgradeSucceeded(v13.UpgradeName, upgradeHeight) - postUpgradeChecks(s) -} +// postUpgradeChecks(s) +// } -func preUpgradeChecks(s *UpgradeTestSuite) { +// func preUpgradeChecks(s *UpgradeTestSuite) { - mp := s.App.MintKeeper.GetParams(s.Ctx) - s.Require().Equal(mp.BlocksPerYear, uint64(6311520)) +// mp := s.App.MintKeeper.GetParams(s.Ctx) +// s.Require().Equal(mp.BlocksPerYear, uint64(6311520)) - sp := s.App.SlashingKeeper.GetParams(s.Ctx) - s.Require().Equal(sp.SignedBlocksWindow, int64(100)) +// sp := s.App.SlashingKeeper.GetParams(s.Ctx) +// s.Require().Equal(sp.SignedBlocksWindow, int64(100)) -} +// } -func postUpgradeChecks(s *UpgradeTestSuite) { +// func postUpgradeChecks(s *UpgradeTestSuite) { - // Ensure the gov params have MinInitialDepositRatio added - gp := s.App.GovKeeper.GetParams(s.Ctx) - s.Require().Equal(gp.MinInitialDepositRatio, "0.200000000000000000") +// // Ensure the gov params have MinInitialDepositRatio added +// gp := s.App.GovKeeper.GetParams(s.Ctx) +// s.Require().Equal(gp.MinInitialDepositRatio, "0.200000000000000000") - // Ensure the mint params have doubled - mp := s.App.MintKeeper.GetParams(s.Ctx) - s.Require().Equal(mp.BlocksPerYear, uint64(6311520*2)) +// // Ensure the mint params have doubled +// mp := s.App.MintKeeper.GetParams(s.Ctx) +// s.Require().Equal(mp.BlocksPerYear, uint64(6311520*2)) - // Ensure the slashing params have doubled - sp := s.App.SlashingKeeper.GetParams(s.Ctx) - s.Require().Equal(sp.SignedBlocksWindow, int64(100*2)) +// // Ensure the slashing params have doubled +// sp := s.App.SlashingKeeper.GetParams(s.Ctx) +// s.Require().Equal(sp.SignedBlocksWindow, int64(100*2)) - // Ensure the wasm Permissionless - wp := s.App.WasmKeeper.GetParams(s.Ctx) - s.Require().Equal(wp.CodeUploadAccess, wasmtypes.AllowEverybody) -} +// // Ensure the wasm Permissionless +// wp := s.App.WasmKeeper.GetParams(s.Ctx) +// s.Require().Equal(wp.CodeUploadAccess, wasmtypes.AllowEverybody) +// } From e690ca4f704613a9dbf29de63fca1f33267a87aa Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Tue, 7 Nov 2023 16:05:31 +0530 Subject: [PATCH 04/10] mainnet upgrade tc fixed --- app/upgrades/mainnet/v13/upgrade_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/upgrades/mainnet/v13/upgrade_test.go b/app/upgrades/mainnet/v13/upgrade_test.go index be9f1a70f..ab5bdca26 100644 --- a/app/upgrades/mainnet/v13/upgrade_test.go +++ b/app/upgrades/mainnet/v13/upgrade_test.go @@ -7,7 +7,7 @@ import ( "github.com/comdex-official/comdex/app" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - v13 "github.com/comdex-official/comdex/app/upgrades/testnet/v13" + v13 "github.com/comdex-official/comdex/app/upgrades/mainnet/v13" ) type UpgradeTestSuite struct { From df21563fccf640ebe435480d2bafbfff7c6ee524 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Mon, 13 Nov 2023 16:59:25 +0530 Subject: [PATCH 05/10] migration func called --- app/app.go | 2 +- app/upgrades/mainnet/v13/upgrades.go | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/app.go b/app/app.go index 322306fc9..4e9e01997 100644 --- a/app/app.go +++ b/app/app.go @@ -1457,7 +1457,7 @@ func (a *App) ModuleAccountsPermissions() map[string][]string { func (a *App) registerUpgradeHandlers() { a.UpgradeKeeper.SetUpgradeHandler( mv13.UpgradeName, - mv13.CreateUpgradeHandlerV13(a.mm, a.configurator, a.cdc, a.keys[capabilitytypes.ModuleName], a.CapabilityKeeper, a.WasmKeeper, a.ParamsKeeper, a.ConsensusParamsKeeper, *a.IbcKeeper, a.ICQKeeper, a.GovKeeper, *a.StakingKeeper, a.MintKeeper, a.SlashingKeeper, a.BandoracleKeeper, a.AssetKeeper, a.LendKeeper, a.NewliqKeeper, a.NewaucKeeper), + mv13.CreateUpgradeHandlerV13(a.mm, a.configurator, a.cdc, a.keys[capabilitytypes.ModuleName], a.CapabilityKeeper, a.WasmKeeper, a.ParamsKeeper, a.ConsensusParamsKeeper, *a.IbcKeeper, a.ICQKeeper, a.GovKeeper, *a.StakingKeeper, a.MintKeeper, a.SlashingKeeper, a.BandoracleKeeper, a.AssetKeeper, a.LendKeeper, a.NewliqKeeper, a.NewaucKeeper, a.AuctionKeeper, a.LiquidationKeeper, a.MarketKeeper, a.VaultKeeper), ) // 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 diff --git a/app/upgrades/mainnet/v13/upgrades.go b/app/upgrades/mainnet/v13/upgrades.go index 2027daa90..e0a2f5a05 100644 --- a/app/upgrades/mainnet/v13/upgrades.go +++ b/app/upgrades/mainnet/v13/upgrades.go @@ -6,13 +6,17 @@ import ( wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" assetkeeper "github.com/comdex-official/comdex/x/asset/keeper" assettypes "github.com/comdex-official/comdex/x/asset/types" + auctionkeeperold "github.com/comdex-official/comdex/x/auction/keeper" auctionV2keeper "github.com/comdex-official/comdex/x/auctionsV2/keeper" auctionsV2types "github.com/comdex-official/comdex/x/auctionsV2/types" bandoraclemodulekeeper "github.com/comdex-official/comdex/x/bandoracle/keeper" lendkeeper "github.com/comdex-official/comdex/x/lend/keeper" lendtypes "github.com/comdex-official/comdex/x/lend/types" + liquidationkeeperold "github.com/comdex-official/comdex/x/liquidation/keeper" liquidationV2keeper "github.com/comdex-official/comdex/x/liquidationsV2/keeper" liquidationV2types "github.com/comdex-official/comdex/x/liquidationsV2/types" + marketkeeper "github.com/comdex-official/comdex/x/market/keeper" + vaultkeeper "github.com/comdex-official/comdex/x/vault/keeper" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" @@ -54,6 +58,10 @@ func CreateUpgradeHandlerV13( lendKeeper lendkeeper.Keeper, liquidationV2Keeper liquidationV2keeper.Keeper, auctionV2Keeper auctionV2keeper.Keeper, + auctionKeeperOld auctionkeeperold.Keeper, + liquidationKeeperOld liquidationkeeperold.Keeper, + marketKeeper marketkeeper.Keeper, + vaultKeeper vaultkeeper.Keeper, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { ctx.Logger().Info("Applying main net upgrade - v.13.2.0") @@ -144,6 +152,7 @@ func CreateUpgradeHandlerV13( UpdateLendParams(ctx, lendKeeper, assetKeeper) InitializeStates(ctx, liquidationV2Keeper, auctionV2Keeper) + MigrateAuctionsHarbor(ctx, assetKeeper, auctionKeeperOld, auctionV2Keeper, liquidationKeeperOld, liquidationV2Keeper, marketKeeper, vaultKeeper) return vm, err } @@ -223,7 +232,7 @@ func InitializeStates( englishAuctionParams := liquidationV2types.EnglishAuctionParam{DecrementFactor: sdk.NewInt(1)} harborParams := liquidationV2types.LiquidationWhiteListing{ - AppId: 2, + AppId: 1, Initiator: true, IsDutchActivated: true, DutchAuctionParam: &dutchAuctionParams, @@ -245,9 +254,9 @@ func InitializeStates( liquidationKeeper.SetLiquidationWhiteListing(ctx, harborParams) liquidationKeeper.SetLiquidationWhiteListing(ctx, commodoParams) - appReserveFundsTxDataHbr, found := liquidationKeeper.GetAppReserveFundsTxData(ctx, 2) + appReserveFundsTxDataHbr, found := liquidationKeeper.GetAppReserveFundsTxData(ctx, 1) if !found { - appReserveFundsTxDataHbr.AppId = 2 + appReserveFundsTxDataHbr.AppId = 1 } appReserveFundsTxDataHbr.AssetTxData = append(appReserveFundsTxDataHbr.AssetTxData, liquidationV2types.AssetTxData{}) liquidationKeeper.SetAppReserveFundsTxData(ctx, appReserveFundsTxDataHbr) From cf2a656f8574ec19b01b1fa6f40b96b0cc84c929 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Mon, 13 Nov 2023 17:02:39 +0530 Subject: [PATCH 06/10] migration func called --- app/upgrades/mainnet/v13/upgrades.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/upgrades/mainnet/v13/upgrades.go b/app/upgrades/mainnet/v13/upgrades.go index e0a2f5a05..b22f9c2bd 100644 --- a/app/upgrades/mainnet/v13/upgrades.go +++ b/app/upgrades/mainnet/v13/upgrades.go @@ -232,7 +232,7 @@ func InitializeStates( englishAuctionParams := liquidationV2types.EnglishAuctionParam{DecrementFactor: sdk.NewInt(1)} harborParams := liquidationV2types.LiquidationWhiteListing{ - AppId: 1, + AppId: 2, Initiator: true, IsDutchActivated: true, DutchAuctionParam: &dutchAuctionParams, @@ -254,9 +254,9 @@ func InitializeStates( liquidationKeeper.SetLiquidationWhiteListing(ctx, harborParams) liquidationKeeper.SetLiquidationWhiteListing(ctx, commodoParams) - appReserveFundsTxDataHbr, found := liquidationKeeper.GetAppReserveFundsTxData(ctx, 1) + appReserveFundsTxDataHbr, found := liquidationKeeper.GetAppReserveFundsTxData(ctx, 2) if !found { - appReserveFundsTxDataHbr.AppId = 1 + appReserveFundsTxDataHbr.AppId = 2 } appReserveFundsTxDataHbr.AssetTxData = append(appReserveFundsTxDataHbr.AssetTxData, liquidationV2types.AssetTxData{}) liquidationKeeper.SetAppReserveFundsTxData(ctx, appReserveFundsTxDataHbr) From 15d4bf66ffa9da38dc256a343565f7e1bbb2c1f7 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Mon, 13 Nov 2023 17:03:41 +0530 Subject: [PATCH 07/10] code commented for testing --- .../mainnet/v13/auctions_migration.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app/upgrades/mainnet/v13/auctions_migration.go b/app/upgrades/mainnet/v13/auctions_migration.go index 9ff001b15..cd5287dcc 100644 --- a/app/upgrades/mainnet/v13/auctions_migration.go +++ b/app/upgrades/mainnet/v13/auctions_migration.go @@ -11,7 +11,6 @@ import ( liquidationtypes "github.com/comdex-official/comdex/x/liquidationsV2/types" marketkeeper "github.com/comdex-official/comdex/x/market/keeper" vaultkeeper "github.com/comdex-official/comdex/x/vault/keeper" - vaultTypes "github.com/comdex-official/comdex/x/vault/types" sdk "github.com/cosmos/cosmos-sdk/types" "time" ) @@ -42,16 +41,16 @@ func MigrateAuctionsHarbor( if !found { //todo // create logic for generating locked vault from auction data - var vault vaultTypes.Vault - userVaults, _ := vaultKeeper.GetUserAppMappingData(ctx, auction.VaultOwner.String(), 2) + // var vault vaultTypes.Vault + // userVaults, _ := vaultKeeper.GetUserAppMappingData(ctx, auction.VaultOwner.String(), 1) // loop into vaults and check if asset in and asset out are matching - for _, userVaultMap := range userVaults { - extPair, _ := assetKeeper.GetPairsVault(ctx, userVaultMap.ExtendedPairId) - pair, _ := assetKeeper.GetPair(ctx, extPair.PairId) - if pair.AssetIn == auction.AssetInId && pair.AssetOut == auction.AssetOutId { - vault, _ = vaultKeeper.GetVault(ctx, userVaultMap.VaultId) - } - } + // for _, userVaultMap := range userVaults { + // extPair, _ := assetKeeper.GetPairsVault(ctx, userVaultMap.ExtendedPairId) + // pair, _ := assetKeeper.GetPair(ctx, extPair.PairId) + // if pair.AssetIn == auction.AssetInId && pair.AssetOut == auction.AssetOutId { + // vault, _ = vaultKeeper.GetVault(ctx, userVaultMap.VaultId) + // } + // } extPair, _ := assetKeeper.GetPairsVault(ctx, vault.ExtendedPairVaultID) pair, _ := assetKeeper.GetPair(ctx, extPair.PairId) assetIn, _ := assetKeeper.GetAsset(ctx, pair.AssetIn) From 4306f81f754620919874fc5293344482721c50d2 Mon Sep 17 00:00:00 2001 From: Pratik Date: Fri, 24 Nov 2023 14:37:34 +0530 Subject: [PATCH 08/10] upgrade refactor --- app/app.go | 4 +- .../mainnet/v13/auctions_migration.go | 167 ------------------ app/upgrades/mainnet/v13/upgrades.go | 15 -- x/auctionsV2/keeper/bid.go | 7 +- x/auctionsV2/types/errors.go | 1 + x/lend/keeper/keeper.go | 2 +- 6 files changed, 9 insertions(+), 187 deletions(-) delete mode 100644 app/upgrades/mainnet/v13/auctions_migration.go diff --git a/app/app.go b/app/app.go index 4e9e01997..ae67a13ea 100644 --- a/app/app.go +++ b/app/app.go @@ -198,8 +198,8 @@ import ( cwasm "github.com/comdex-official/comdex/app/wasm" - tv13 "github.com/comdex-official/comdex/app/upgrades/testnet/v13" mv13 "github.com/comdex-official/comdex/app/upgrades/mainnet/v13" + tv13 "github.com/comdex-official/comdex/app/upgrades/testnet/v13" ) const ( @@ -1457,7 +1457,7 @@ func (a *App) ModuleAccountsPermissions() map[string][]string { func (a *App) registerUpgradeHandlers() { a.UpgradeKeeper.SetUpgradeHandler( mv13.UpgradeName, - mv13.CreateUpgradeHandlerV13(a.mm, a.configurator, a.cdc, a.keys[capabilitytypes.ModuleName], a.CapabilityKeeper, a.WasmKeeper, a.ParamsKeeper, a.ConsensusParamsKeeper, *a.IbcKeeper, a.ICQKeeper, a.GovKeeper, *a.StakingKeeper, a.MintKeeper, a.SlashingKeeper, a.BandoracleKeeper, a.AssetKeeper, a.LendKeeper, a.NewliqKeeper, a.NewaucKeeper, a.AuctionKeeper, a.LiquidationKeeper, a.MarketKeeper, a.VaultKeeper), + mv13.CreateUpgradeHandlerV13(a.mm, a.configurator, a.cdc, a.WasmKeeper, a.ParamsKeeper, a.ConsensusParamsKeeper, *a.IbcKeeper, a.ICQKeeper, a.GovKeeper, a.MintKeeper, a.SlashingKeeper, a.BandoracleKeeper, a.AssetKeeper, a.LendKeeper, a.NewliqKeeper, a.NewaucKeeper), ) // 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 diff --git a/app/upgrades/mainnet/v13/auctions_migration.go b/app/upgrades/mainnet/v13/auctions_migration.go deleted file mode 100644 index cd5287dcc..000000000 --- a/app/upgrades/mainnet/v13/auctions_migration.go +++ /dev/null @@ -1,167 +0,0 @@ -package v13 - -import ( - assetkeeper "github.com/comdex-official/comdex/x/asset/keeper" - auctionkeeperold "github.com/comdex-official/comdex/x/auction/keeper" - auctionkeeper "github.com/comdex-official/comdex/x/auctionsV2/keeper" - auctionsV2types "github.com/comdex-official/comdex/x/auctionsV2/types" - liquidationkeeperold "github.com/comdex-official/comdex/x/liquidation/keeper" - liquidationtypesold "github.com/comdex-official/comdex/x/liquidation/types" - liquidationkeeper "github.com/comdex-official/comdex/x/liquidationsV2/keeper" - liquidationtypes "github.com/comdex-official/comdex/x/liquidationsV2/types" - marketkeeper "github.com/comdex-official/comdex/x/market/keeper" - vaultkeeper "github.com/comdex-official/comdex/x/vault/keeper" - sdk "github.com/cosmos/cosmos-sdk/types" - "time" -) - -func ReturnCoin(ctx sdk.Context, assetKeeper assetkeeper.Keeper, assetID uint64, amount sdk.Int) sdk.Coin { - asset, _ := assetKeeper.GetAsset(ctx, assetID) - return sdk.NewCoin(asset.Denom, amount) -} - -func MigrateAuctionsHarbor( - ctx sdk.Context, - assetKeeper assetkeeper.Keeper, - auctionKeeperOld auctionkeeperold.Keeper, - auctionKeeper auctionkeeper.Keeper, - liquidationKeeperOld liquidationkeeperold.Keeper, - liquidationKeeper liquidationkeeper.Keeper, - marketKeeper marketkeeper.Keeper, - vaultKeeper vaultkeeper.Keeper, -) { - // first get all the auctions and their locked vaults and set them in new LiquidationsV2, - // if locked vault is not available create a new locked vault - // get all the auction and set them accordingly in new auctionV2 - - auctionsOld := auctionKeeperOld.GetDutchAuctions(ctx, 2) - if len(auctionsOld) != 0 { - for _, auction := range auctionsOld { - liquidationData, found := liquidationKeeperOld.GetLockedVault(ctx, 2, auction.LockedVaultId) - if !found { - //todo - // create logic for generating locked vault from auction data - // var vault vaultTypes.Vault - // userVaults, _ := vaultKeeper.GetUserAppMappingData(ctx, auction.VaultOwner.String(), 1) - // loop into vaults and check if asset in and asset out are matching - // for _, userVaultMap := range userVaults { - // extPair, _ := assetKeeper.GetPairsVault(ctx, userVaultMap.ExtendedPairId) - // pair, _ := assetKeeper.GetPair(ctx, extPair.PairId) - // if pair.AssetIn == auction.AssetInId && pair.AssetOut == auction.AssetOutId { - // vault, _ = vaultKeeper.GetVault(ctx, userVaultMap.VaultId) - // } - // } - extPair, _ := assetKeeper.GetPairsVault(ctx, vault.ExtendedPairVaultID) - pair, _ := assetKeeper.GetPair(ctx, extPair.PairId) - assetIn, _ := assetKeeper.GetAsset(ctx, pair.AssetIn) - totalIn, _ := marketKeeper.CalcAssetPrice(ctx, assetIn.Id, vault.AmountIn) - - totalFees := vault.InterestAccumulated.Add(vault.ClosingFeeAccumulated) - liquidationData = liquidationtypesold.LockedVault{ - AppId: 2, - OriginalVaultId: vault.Id, - ExtendedPairId: vault.ExtendedPairVaultID, - Owner: vault.Owner, - AmountIn: vault.AmountIn, - AmountOut: vault.AmountOut, - UpdatedAmountOut: vault.AmountOut.Add(vault.InterestAccumulated), - Initiator: "liquidationV1", - IsAuctionComplete: false, - IsAuctionInProgress: true, - CrAtLiquidation: sdk.ZeroDec(), - CurrentCollaterlisationRatio: sdk.ZeroDec(), - CollateralToBeAuctioned: totalIn, - LiquidationTimestamp: ctx.BlockTime(), - SellOffHistory: nil, - InterestAccumulated: totalFees, - Kind: nil, - } - } - - lockedVaultID := liquidationKeeper.GetLockedVaultID(ctx) - extPair, _ := assetKeeper.GetPairsVault(ctx, liquidationData.ExtendedPairId) - pair, _ := assetKeeper.GetPair(ctx, extPair.PairId) - feesToBeCollected := sdk.NewDecFromInt(liquidationData.AmountOut).Mul(extPair.LiquidationPenalty).TruncateInt() - newLockedVault := liquidationtypes.LockedVault{ - LockedVaultId: lockedVaultID + 1, - AppId: 2, - OriginalVaultId: liquidationData.OriginalVaultId, - ExtendedPairId: liquidationData.ExtendedPairId, - Owner: liquidationData.Owner, - CollateralToken: ReturnCoin(ctx, assetKeeper, pair.AssetIn, liquidationData.AmountIn), - DebtToken: ReturnCoin(ctx, assetKeeper, pair.AssetOut, liquidationData.AmountOut), - CurrentCollaterlisationRatio: liquidationData.CrAtLiquidation, - CollateralToBeAuctioned: ReturnCoin(ctx, assetKeeper, pair.AssetIn, liquidationData.AmountIn), - TargetDebt: ReturnCoin(ctx, assetKeeper, pair.AssetOut, liquidationData.AmountOut.Add(feesToBeCollected)), - LiquidationTimestamp: liquidationData.LiquidationTimestamp, - IsInternalKeeper: false, - InternalKeeperAddress: "", - ExternalKeeperAddress: "", - FeeToBeCollected: feesToBeCollected, - BonusToBeGiven: sdk.ZeroInt(), - InitiatorType: "vault", - AuctionType: true, - IsDebtCmst: true, - CollateralAssetId: pair.AssetIn, - DebtAssetId: pair.AssetOut, - } - // set locked vault id - liquidationKeeper.SetLockedVaultID(ctx, newLockedVault.LockedVaultId) - // set new locked vault - liquidationKeeper.SetLockedVault(ctx, newLockedVault) - - // now migrate old auctions data to new module - auctionID := auctionKeeper.GetAuctionID(ctx) - - twaDataCollateral, found := marketKeeper.GetTwa(ctx, newLockedVault.CollateralAssetId) - if !found || !twaDataCollateral.IsPriceActive { - return - } - twaDataDebt, found := marketKeeper.GetTwa(ctx, newLockedVault.DebtAssetId) - if !found || !twaDataDebt.IsPriceActive { - return - } - liquidationWhitelistingAppData, _ := liquidationKeeper.GetLiquidationWhiteListing(ctx, liquidationData.AppId) - dutchAuctionParams := liquidationWhitelistingAppData.DutchAuctionParam - auctionParams, _ := auctionKeeper.GetAuctionParams(ctx) - - CollateralTokenInitialPrice := auctionKeeper.GetCollalteralTokenInitialPrice(sdk.NewIntFromUint64(twaDataCollateral.Twa), dutchAuctionParams.Premium) - - newAuction := auctionsV2types.Auction{ - AuctionId: auctionID + 1, - CollateralToken: auction.OutflowTokenCurrentAmount, // outflow - DebtToken: auction.InflowTokenCurrentAmount, // inflow - ActiveBiddingId: 0, - BiddingIds: nil, - CollateralTokenAuctionPrice: CollateralTokenInitialPrice, - CollateralTokenOraclePrice: sdk.NewDecFromInt(sdk.NewInt(int64(twaDataCollateral.Twa))), - DebtTokenOraclePrice: sdk.NewDecFromInt(sdk.NewInt(int64(twaDataDebt.Twa))), - LockedVaultId: newLockedVault.LockedVaultId, - StartTime: ctx.BlockTime(), - EndTime: ctx.BlockTime().Add(time.Second * time.Duration(auctionParams.AuctionDurationSeconds)), - AppId: newLockedVault.AppId, - AuctionType: newLockedVault.AuctionType, - CollateralAssetId: newLockedVault.CollateralAssetId, - DebtAssetId: newLockedVault.DebtAssetId, - BonusAmount: newLockedVault.BonusToBeGiven, - CollateralTokenInitialPrice: CollateralTokenInitialPrice, - } - // update auction ID - auctionKeeper.SetAuctionID(ctx, newAuction.AuctionId) - - // migrate old auctions to new module - err := auctionKeeper.SetAuction(ctx, newAuction) - if err != nil { - return - } - - // delete old auctions and locked vaults - // first create a history of both of them then delete - liquidationKeeperOld.SetLockedVaultHistory(ctx, liquidationData, liquidationData.LockedVaultId) - err = auctionKeeperOld.SetHistoryDutchAuction(ctx, auction) - if err != nil { - return - } - } - } -} diff --git a/app/upgrades/mainnet/v13/upgrades.go b/app/upgrades/mainnet/v13/upgrades.go index b22f9c2bd..849cdb4e0 100644 --- a/app/upgrades/mainnet/v13/upgrades.go +++ b/app/upgrades/mainnet/v13/upgrades.go @@ -6,30 +6,23 @@ import ( wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" assetkeeper "github.com/comdex-official/comdex/x/asset/keeper" assettypes "github.com/comdex-official/comdex/x/asset/types" - auctionkeeperold "github.com/comdex-official/comdex/x/auction/keeper" auctionV2keeper "github.com/comdex-official/comdex/x/auctionsV2/keeper" auctionsV2types "github.com/comdex-official/comdex/x/auctionsV2/types" bandoraclemodulekeeper "github.com/comdex-official/comdex/x/bandoracle/keeper" lendkeeper "github.com/comdex-official/comdex/x/lend/keeper" lendtypes "github.com/comdex-official/comdex/x/lend/types" - liquidationkeeperold "github.com/comdex-official/comdex/x/liquidation/keeper" liquidationV2keeper "github.com/comdex-official/comdex/x/liquidationsV2/keeper" liquidationV2types "github.com/comdex-official/comdex/x/liquidationsV2/types" - marketkeeper "github.com/comdex-official/comdex/x/market/keeper" - vaultkeeper "github.com/comdex-official/comdex/x/vault/keeper" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" - storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" icqkeeper "github.com/cosmos/ibc-apps/modules/async-icq/v7/keeper" icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types" @@ -42,15 +35,12 @@ func CreateUpgradeHandlerV13( mm *module.Manager, configurator module.Configurator, cdc codec.Codec, - capabilityStoreKey *storetypes.KVStoreKey, - capabilityKeeper *capabilitykeeper.Keeper, wasmKeeper wasmkeeper.Keeper, paramsKeeper paramskeeper.Keeper, consensusParamsKeeper consensusparamkeeper.Keeper, IBCKeeper ibckeeper.Keeper, icqkeeper *icqkeeper.Keeper, GovKeeper govkeeper.Keeper, - StakingKeeper stakingkeeper.Keeper, MintKeeper mintkeeper.Keeper, SlashingKeeper slashingkeeper.Keeper, bandoracleKeeper bandoraclemodulekeeper.Keeper, @@ -58,10 +48,6 @@ func CreateUpgradeHandlerV13( lendKeeper lendkeeper.Keeper, liquidationV2Keeper liquidationV2keeper.Keeper, auctionV2Keeper auctionV2keeper.Keeper, - auctionKeeperOld auctionkeeperold.Keeper, - liquidationKeeperOld liquidationkeeperold.Keeper, - marketKeeper marketkeeper.Keeper, - vaultKeeper vaultkeeper.Keeper, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { ctx.Logger().Info("Applying main net upgrade - v.13.2.0") @@ -152,7 +138,6 @@ func CreateUpgradeHandlerV13( UpdateLendParams(ctx, lendKeeper, assetKeeper) InitializeStates(ctx, liquidationV2Keeper, auctionV2Keeper) - MigrateAuctionsHarbor(ctx, assetKeeper, auctionKeeperOld, auctionV2Keeper, liquidationKeeperOld, liquidationV2Keeper, marketKeeper, vaultKeeper) return vm, err } diff --git a/x/auctionsV2/keeper/bid.go b/x/auctionsV2/keeper/bid.go index ac1fc3139..c8294ce95 100644 --- a/x/auctionsV2/keeper/bid.go +++ b/x/auctionsV2/keeper/bid.go @@ -24,7 +24,10 @@ func (k Keeper) PlaceDutchAuctionBid(ctx sdk.Context, auctionID uint64, bidder s if bid.Denom != auctionData.DebtToken.Denom { return bidId, types.ErrorUnknownDebtToken } - liquidationData, _ := k.LiquidationsV2.GetLockedVault(ctx, auctionData.AppId, auctionData.LockedVaultId) + liquidationData, found := k.LiquidationsV2.GetLockedVault(ctx, auctionData.AppId, auctionData.LockedVaultId) + if !found { + return 0, types.ErrorInGettingLockedVault + } //Price data of the token from market module debtToken, _ := k.market.GetTwa(ctx, auctionData.DebtAssetId) debtPrice := sdk.NewDecFromInt(sdk.NewInt(int64(debtToken.Twa))) @@ -163,7 +166,7 @@ func (k Keeper) PlaceDutchAuctionBid(ctx sdk.Context, auctionID uint64, bidder s if keeperIncentive.GT(sdk.ZeroInt()) { liquidationPenalty = liquidationPenalty.Sub(sdk.NewCoin(auctionData.DebtToken.Denom, keeperIncentive)) addr, _ := sdk.AccAddressFromBech32(liquidationData.InternalKeeperAddress) - err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, auctionsV2types.ModuleName, addr, sdk.NewCoins(sdk.NewCoin(auctionData.DebtToken.Denom, keeperIncentive))) + err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, auctionsV2types.ModuleName, addr, sdk.NewCoins(sdk.NewCoin(auctionData.DebtToken.Denom, keeperIncentive))) if err != nil { return bidId, err } diff --git a/x/auctionsV2/types/errors.go b/x/auctionsV2/types/errors.go index 8cfad6775..6bc42a077 100644 --- a/x/auctionsV2/types/errors.go +++ b/x/auctionsV2/types/errors.go @@ -23,4 +23,5 @@ var ( ErrorDiscountGreaterThanMaxDiscount = sdkerrors.Register(ModuleName, 713, "Premium discount entered is greater than max discount") ErrAuctionLookupTableNotFound = sdkerrors.Register(ModuleName, 714, "auctionLookupTable not found") ErrorUnableToSetNetFees = sdkerrors.Register(ModuleName, 715, "Unable To set net fees collected after auction closed") + ErrorInGettingLockedVault = sdkerrors.Register(ModuleName, 716, "error in bid dutch auction - locked vault not found") ) diff --git a/x/lend/keeper/keeper.go b/x/lend/keeper/keeper.go index ff09f8d0c..a2f14e8e2 100644 --- a/x/lend/keeper/keeper.go +++ b/x/lend/keeper/keeper.go @@ -1633,7 +1633,7 @@ func (k Keeper) RemoveFaultyAuctions(ctx sdk.Context) error { //send debt from reserve to the pool err := k.bank.SendCoinsFromModuleToModule(ctx, reserveModuleName, cPoolModuleName, sdk.NewCoins(dutchAuction.InflowTokenTargetAmount)) if err != nil { - return err + continue } //send collateral to the reserve from auction module outflow_token_current_amount err = k.bank.SendCoinsFromModuleToModule(ctx, auctiontypes.ModuleName, reserveModuleName, sdk.NewCoins(dutchAuction.OutflowTokenCurrentAmount)) From 1d96d5937bb63fbc80d17f7c04e4deae63998836 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Thu, 7 Dec 2023 13:05:48 +0530 Subject: [PATCH 09/10] 3sec BT, permissionless removed from current upgrade --- app/app.go | 2 +- app/upgrades/mainnet/v13/upgrade_test.go | 19 ----------- app/upgrades/mainnet/v13/upgrades.go | 43 ------------------------ cmd/comdex/root.go | 12 +++---- x/bandoracle/abci.go | 4 +-- x/market/abci.go | 4 +-- 6 files changed, 11 insertions(+), 73 deletions(-) diff --git a/app/app.go b/app/app.go index ae67a13ea..9d5223c92 100644 --- a/app/app.go +++ b/app/app.go @@ -1457,7 +1457,7 @@ func (a *App) ModuleAccountsPermissions() map[string][]string { func (a *App) registerUpgradeHandlers() { a.UpgradeKeeper.SetUpgradeHandler( mv13.UpgradeName, - mv13.CreateUpgradeHandlerV13(a.mm, a.configurator, a.cdc, a.WasmKeeper, a.ParamsKeeper, a.ConsensusParamsKeeper, *a.IbcKeeper, a.ICQKeeper, a.GovKeeper, a.MintKeeper, a.SlashingKeeper, a.BandoracleKeeper, a.AssetKeeper, a.LendKeeper, a.NewliqKeeper, a.NewaucKeeper), + mv13.CreateUpgradeHandlerV13(a.mm, a.configurator, a.cdc, a.ParamsKeeper, a.ConsensusParamsKeeper, *a.IbcKeeper, a.ICQKeeper, a.GovKeeper, a.AssetKeeper, a.LendKeeper, a.NewliqKeeper, a.NewaucKeeper), ) // 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 diff --git a/app/upgrades/mainnet/v13/upgrade_test.go b/app/upgrades/mainnet/v13/upgrade_test.go index ab5bdca26..41fe9e288 100644 --- a/app/upgrades/mainnet/v13/upgrade_test.go +++ b/app/upgrades/mainnet/v13/upgrade_test.go @@ -6,7 +6,6 @@ import ( "github.com/stretchr/testify/suite" "github.com/comdex-official/comdex/app" - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" v13 "github.com/comdex-official/comdex/app/upgrades/mainnet/v13" ) @@ -36,12 +35,6 @@ func (s *UpgradeTestSuite) TestUpgrade() { func preUpgradeChecks(s *UpgradeTestSuite) { - mp := s.App.MintKeeper.GetParams(s.Ctx) - s.Require().Equal(mp.BlocksPerYear, uint64(6311520)) - - sp := s.App.SlashingKeeper.GetParams(s.Ctx) - s.Require().Equal(sp.SignedBlocksWindow, int64(100)) - } func postUpgradeChecks(s *UpgradeTestSuite) { @@ -49,16 +42,4 @@ func postUpgradeChecks(s *UpgradeTestSuite) { // Ensure the gov params have MinInitialDepositRatio added gp := s.App.GovKeeper.GetParams(s.Ctx) s.Require().Equal(gp.MinInitialDepositRatio, "0.200000000000000000") - - // Ensure the mint params have doubled - mp := s.App.MintKeeper.GetParams(s.Ctx) - s.Require().Equal(mp.BlocksPerYear, uint64(6311520*2)) - - // Ensure the slashing params have doubled - sp := s.App.SlashingKeeper.GetParams(s.Ctx) - s.Require().Equal(sp.SignedBlocksWindow, int64(100*2)) - - // Ensure the wasm Permissionless - wp := s.App.WasmKeeper.GetParams(s.Ctx) - s.Require().Equal(wp.CodeUploadAccess, wasmtypes.AllowEverybody) } diff --git a/app/upgrades/mainnet/v13/upgrades.go b/app/upgrades/mainnet/v13/upgrades.go index 849cdb4e0..02d1350e0 100644 --- a/app/upgrades/mainnet/v13/upgrades.go +++ b/app/upgrades/mainnet/v13/upgrades.go @@ -2,13 +2,10 @@ package v13 import ( "fmt" - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" assetkeeper "github.com/comdex-official/comdex/x/asset/keeper" assettypes "github.com/comdex-official/comdex/x/asset/types" auctionV2keeper "github.com/comdex-official/comdex/x/auctionsV2/keeper" auctionsV2types "github.com/comdex-official/comdex/x/auctionsV2/types" - bandoraclemodulekeeper "github.com/comdex-official/comdex/x/bandoracle/keeper" lendkeeper "github.com/comdex-official/comdex/x/lend/keeper" lendtypes "github.com/comdex-official/comdex/x/lend/types" liquidationV2keeper "github.com/comdex-official/comdex/x/liquidationsV2/keeper" @@ -19,10 +16,8 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" - mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" icqkeeper "github.com/cosmos/ibc-apps/modules/async-icq/v7/keeper" icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types" @@ -35,15 +30,11 @@ func CreateUpgradeHandlerV13( mm *module.Manager, configurator module.Configurator, cdc codec.Codec, - wasmKeeper wasmkeeper.Keeper, paramsKeeper paramskeeper.Keeper, consensusParamsKeeper consensusparamkeeper.Keeper, IBCKeeper ibckeeper.Keeper, icqkeeper *icqkeeper.Keeper, GovKeeper govkeeper.Keeper, - MintKeeper mintkeeper.Keeper, - SlashingKeeper slashingkeeper.Keeper, - bandoracleKeeper bandoraclemodulekeeper.Keeper, assetKeeper assetkeeper.Keeper, lendKeeper lendkeeper.Keeper, liquidationV2Keeper liquidationV2keeper.Keeper, @@ -63,7 +54,6 @@ func CreateUpgradeHandlerV13( // https://github.com/cosmos/ibc-go/blob/v7.1.0/docs/migrations/v4-to-v5.md // -- nothing -- - // TODO: check if v5-v6 is required ?? // https://github.com/cosmos/ibc-go/blob/v7.1.0/docs/migrations/v5-to-v6.md // ibc v6-to-v7 @@ -95,7 +85,6 @@ func CreateUpgradeHandlerV13( } logger.Info(fmt.Sprintf("post migrate version map: %v", vm)) - //TODO: confirm the initial deposit // update gov params to use a 20% initial deposit ratio, allowing us to remote the ante handler govParams := GovKeeper.GetParams(ctx) govParams.MinInitialDepositRatio = sdk.NewDec(20).Quo(sdk.NewDec(100)).String() @@ -104,38 +93,6 @@ func CreateUpgradeHandlerV13( } logger.Info(fmt.Sprintf("updated gov params to %v", govParams)) - // x/Mint - // Double blocks per year (from 6 seconds to 3 = 2x blocks per year) - mintParams := MintKeeper.GetParams(ctx) - mintParams.BlocksPerYear *= 2 - if err = MintKeeper.SetParams(ctx, mintParams); err != nil { - return nil, err - } - logger.Info(fmt.Sprintf("updated minted blocks per year logic to %v", mintParams)) - - // x/Slashing - // Double slashing window due to double blocks per year - slashingParams := SlashingKeeper.GetParams(ctx) - slashingParams.SignedBlocksWindow *= 2 - if err := SlashingKeeper.SetParams(ctx, slashingParams); err != nil { - return nil, err - } - logger.Info(fmt.Sprintf("updated slashing params to %v", slashingParams)) - - // update wasm to permissionless - wasmParams := wasmKeeper.GetParams(ctx) - wasmParams.CodeUploadAccess = wasmtypes.AllowEverybody - wasmKeeper.SetParams(ctx, wasmParams) - logger.Info(fmt.Sprintf("updated wasm params to %v", wasmParams)) - - // update discard BH of oracle - bandData := bandoracleKeeper.GetFetchPriceMsg(ctx) - if bandData.Size() > 0 { - bandData.AcceptedHeightDiff = 6000 - bandoracleKeeper.SetFetchPriceMsg(ctx, bandData) - logger.Info(fmt.Sprintf("updated bandData to %v", bandData)) - } - UpdateLendParams(ctx, lendKeeper, assetKeeper) InitializeStates(ctx, liquidationV2Keeper, auctionV2Keeper) diff --git a/cmd/comdex/root.go b/cmd/comdex/root.go index edae184a6..6dbdaa3dd 100644 --- a/cmd/comdex/root.go +++ b/cmd/comdex/root.go @@ -5,7 +5,7 @@ import ( "io" "os" "path/filepath" - "time" + // "time" "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" @@ -76,13 +76,13 @@ func NewRootCmd() (*cobra.Command, comdex.EncodingConfig) { return err } // 2 seconds + 1 second tendermint = 3 second blocks - timeoutCommit := 2 * time.Second + // timeoutCommit := 2 * time.Second customAppTemplate, customAppConfig := initAppConfig() - customTMConfig := initTendermintConfig(timeoutCommit) + customTMConfig := initTendermintConfig() // Force faster block times - os.Setenv("COMDEX_CONSENSUS_TIMEOUT_COMMIT", cast.ToString(timeoutCommit)) + // os.Setenv("COMDEX_CONSENSUS_TIMEOUT_COMMIT", cast.ToString(timeoutCommit)) return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig) }, @@ -92,7 +92,7 @@ func NewRootCmd() (*cobra.Command, comdex.EncodingConfig) { return root, encodingConfig } -func initTendermintConfig(timeoutCommit time.Duration) *tmcfg.Config { +func initTendermintConfig() *tmcfg.Config { cfg := tmcfg.DefaultConfig() // these values put a higher strain on node memory @@ -100,7 +100,7 @@ func initTendermintConfig(timeoutCommit time.Duration) *tmcfg.Config { // cfg.P2P.MaxNumOutboundPeers = 40 // While this is set, it only applies to new configs. - cfg.Consensus.TimeoutCommit = timeoutCommit + // cfg.Consensus.TimeoutCommit = timeoutCommit return cfg } diff --git a/x/bandoracle/abci.go b/x/bandoracle/abci.go index 270093bc0..5b80f7e63 100644 --- a/x/bandoracle/abci.go +++ b/x/bandoracle/abci.go @@ -14,8 +14,8 @@ func BeginBlocker(ctx sdk.Context, _ abci.RequestBeginBlock, k keeper.Keeper) { block := k.GetLastBlockHeight(ctx) if block != types.Int64Zero { - // if ctx.BlockHeight()%types.Int64Forty == types.Int64Zero && ctx.BlockHeight() != block { - if ctx.BlockHeight()%types.Int64Forty == types.Int64Zero { + // if ctx.BlockHeight()%types.Int64Twenty == types.Int64Zero && ctx.BlockHeight() != block { + if ctx.BlockHeight()%types.Int64Twenty == types.Int64Zero { if !k.GetCheckFlag(ctx) { msg := k.GetFetchPriceMsg(ctx) _, err := k.FetchPrice(ctx, msg) diff --git a/x/market/abci.go b/x/market/abci.go index 4cfdfdc47..f94063ab3 100644 --- a/x/market/abci.go +++ b/x/market/abci.go @@ -17,8 +17,8 @@ func BeginBlocker(ctx sdk.Context, _ abci.RequestBeginBlock, k keeper.Keeper, ba if bandKeeper.GetOracleValidationResult(ctx) { block := bandKeeper.GetLastBlockHeight(ctx) if block != types.Int64Zero { - // if ctx.BlockHeight()%types.Int64Forty == types.Int64Zero && ctx.BlockHeight() != block && bandKeeper.GetCheckFlag(ctx) { - if ctx.BlockHeight()%types.Int64Forty == types.Int64Zero { + // if ctx.BlockHeight()%types.Int64Twenty == types.Int64Zero && ctx.BlockHeight() != block && bandKeeper.GetCheckFlag(ctx) { + if ctx.BlockHeight()%types.Int64Twenty == types.Int64Zero { discardData := bandKeeper.GetDiscardData(ctx) if discardData.DiscardBool { allTwa := k.GetAllTwa(ctx) From c93077a6964280be92882f54c67a0935ff4839b0 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Thu, 7 Dec 2023 19:49:49 +0530 Subject: [PATCH 10/10] add MacOS ledger support --- go.mod | 6 +++--- go.sum | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index b7760336b..cf8b0c370 100644 --- a/go.mod +++ b/go.mod @@ -96,7 +96,7 @@ require ( github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/iavl v0.20.0 // indirect - github.com/cosmos/ledger-cosmos-go v0.12.2 // indirect + github.com/cosmos/ledger-cosmos-go v0.12.4 // indirect github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect github.com/creachadair/taskgroup v0.4.2 // indirect github.com/curioswitch/go-reassign v0.2.0 // indirect @@ -287,8 +287,8 @@ require ( github.com/uudashr/gocognit v1.0.6 // indirect github.com/yagipy/maintidx v1.0.0 // indirect github.com/yeya24/promlinter v0.2.0 // indirect - github.com/zondax/hid v0.9.1 // indirect - github.com/zondax/ledger-go v0.14.1 // indirect + github.com/zondax/hid v0.9.2 // indirect + github.com/zondax/ledger-go v0.14.3 // indirect gitlab.com/bosi/decorder v0.2.3 // indirect go.etcd.io/bbolt v1.3.7 // indirect go.opencensus.io v0.24.0 // indirect diff --git a/go.sum b/go.sum index a48c03ea1..663be8fee 100644 --- a/go.sum +++ b/go.sum @@ -1110,8 +1110,8 @@ github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980 github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo= github.com/cosmos/keyring v1.2.0/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA= github.com/cosmos/ledger-cosmos-go v0.12.1/go.mod h1:dhO6kj+Y+AHIOgAe4L9HL/6NDdyyth4q238I9yFpD2g= -github.com/cosmos/ledger-cosmos-go v0.12.2 h1:/XYaBlE2BJxtvpkHiBm97gFGSGmYGKunKyF3nNqAXZA= -github.com/cosmos/ledger-cosmos-go v0.12.2/go.mod h1:ZcqYgnfNJ6lAXe4HPtWgarNEY+B74i+2/8MhZw4ziiI= +github.com/cosmos/ledger-cosmos-go v0.12.4 h1:drvWt+GJP7Aiw550yeb3ON/zsrgW0jgh5saFCr7pDnw= +github.com/cosmos/ledger-cosmos-go v0.12.4/go.mod h1:fjfVWRf++Xkygt9wzCsjEBdjcf7wiiY35fv3ctT+k4M= github.com/cosmos/rosetta-sdk-go v0.9.0/go.mod h1:2v41yXL25xxAXrczVSnbDHcQH9CgildruDlGQGKW/JU= github.com/cosmos/rosetta-sdk-go v0.10.0 h1:E5RhTruuoA7KTIXUcMicL76cffyeoyvNybzUGSKFTcM= github.com/cosmos/rosetta-sdk-go v0.10.0/go.mod h1:SImAZkb96YbwvoRkzSMQB6noNJXFgWl/ENIznEoYQI4= @@ -3024,11 +3024,12 @@ github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQ github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43/go.mod h1:aX5oPXxHm3bOH+xeAttToC8pqch2ScQN/JoXYupl6xs= github.com/yvasiyarov/gorelic v0.0.0-20141212073537-a9bba5b9ab50/go.mod h1:NUSPSUX/bi6SeDMUh6brw0nXpxHnc96TguQh0+r/ssA= github.com/yvasiyarov/newrelic_platform_go v0.0.0-20140908184405-b21fdbd4370f/go.mod h1:GlGEuHIJweS1mbCqG+7vt2nvWLzLLnRHbXz5JKd/Qbg= -github.com/zondax/hid v0.9.1 h1:gQe66rtmyZ8VeGFcOpbuH3r7erYtNEAezCAYu8LdkJo= github.com/zondax/hid v0.9.1/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= +github.com/zondax/hid v0.9.2 h1:WCJFnEDMiqGF64nlZz28E9qLVZ0KSJ7xpc5DLEyma2U= +github.com/zondax/hid v0.9.2/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= github.com/zondax/ledger-go v0.14.0/go.mod h1:fZ3Dqg6qcdXWSOJFKMG8GCTnD7slO/RL2feOQv8K320= -github.com/zondax/ledger-go v0.14.1 h1:Pip65OOl4iJ84WTpA4BKChvOufMhhbxED3BaihoZN4c= -github.com/zondax/ledger-go v0.14.1/go.mod h1:fZ3Dqg6qcdXWSOJFKMG8GCTnD7slO/RL2feOQv8K320= +github.com/zondax/ledger-go v0.14.3 h1:wEpJt2CEcBJ428md/5MgSLsXLBos98sBOyxNmCjfUCw= +github.com/zondax/ledger-go v0.14.3/go.mod h1:IKKaoxupuB43g4NxeQmbLXv7T9AlQyie1UpHb342ycI= gitlab.com/bosi/decorder v0.2.1/go.mod h1:6C/nhLSbF6qZbYD8bRmISBwc6vcWdNsiIBkRvjJFrH0= gitlab.com/bosi/decorder v0.2.3 h1:gX4/RgK16ijY8V+BRQHAySfQAb354T7/xQpDB2n10P0= gitlab.com/bosi/decorder v0.2.3/go.mod h1:9K1RB5+VPNQYtXtTDAzd2OEftsZb1oV0IrJrzChSdGE=