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

genesis correction #581

Merged
merged 5 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ import (

cwasm "github.com/comdex-official/comdex/app/wasm"

mv5 "github.com/comdex-official/comdex/app/upgrades/mainnet/v5"
tv1_0_0 "github.com/comdex-official/comdex/app/upgrades/testnet/v1_0_0"
tv2_0_0 "github.com/comdex-official/comdex/app/upgrades/testnet/v2_0_0"
tv3_0_0 "github.com/comdex-official/comdex/app/upgrades/testnet/v3_0_0"
Expand Down Expand Up @@ -1287,8 +1288,8 @@ func upgradeHandlers(upgradeInfo storetypes.UpgradeInfo, a *App, storeUpgrades *
},
}

// prepare store for main net upgrade v5.0.0
/*case upgradeInfo.Name == mv5.UpgradeName && !a.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height):
// prepare store for main net upgrade v5.0.0
case upgradeInfo.Name == mv5.UpgradeName && !a.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height):
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{
assettypes.ModuleName,
Expand All @@ -1308,7 +1309,7 @@ func upgradeHandlers(upgradeInfo storetypes.UpgradeInfo, a *App, storeUpgrades *
icahosttypes.StoreKey,
authz.ModuleName,
},
}*/
}
}

return storeUpgrades
Expand Down
18 changes: 9 additions & 9 deletions app/upgrades/mainnet/v5/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ func InitializeStates(
}

assets := []assettypes.Asset{
{Name: "ATOM", Denom: "uatom", Decimals: sdk.NewInt(1000000), IsOnChain: false, IsOraclePriceRequired: true},
{Name: "CMDX", Denom: "ucmdx", Decimals: sdk.NewInt(1000000), IsOnChain: false, IsOraclePriceRequired: true},
{Name: "CMST", Denom: "ucmst", Decimals: sdk.NewInt(1000000), IsOnChain: false, IsOraclePriceRequired: false},
{Name: "OSMO", Denom: "uosmo", Decimals: sdk.NewInt(1000000), IsOnChain: false, IsOraclePriceRequired: true},
{Name: "CATOM", Denom: "ucatom", Decimals: sdk.NewInt(1000000), IsOnChain: false, IsOraclePriceRequired: false},
{Name: "CCMDX", Denom: "uccmdx", Decimals: sdk.NewInt(1000000), IsOnChain: false, IsOraclePriceRequired: false},
{Name: "CCMST", Denom: "uccmst", Decimals: sdk.NewInt(1000000), IsOnChain: false, IsOraclePriceRequired: false},
{Name: "COSMO", Denom: "ucosmo", Decimals: sdk.NewInt(1000000), IsOnChain: false, IsOraclePriceRequired: false},
{Name: "HARBOR", Denom: "uharbor", Decimals: sdk.NewInt(1000000), IsOnChain: true, IsOraclePriceRequired: false},
{Name: "ATOM", Denom: "uatom", Decimals: sdk.NewInt(1000000), IsOnChain: false, IsOraclePriceRequired: true, IsCdpMintable: false},
{Name: "CMDX", Denom: "ucmdx", Decimals: sdk.NewInt(1000000), IsOnChain: false, IsOraclePriceRequired: true, IsCdpMintable: false},
{Name: "CMST", Denom: "ucmst", Decimals: sdk.NewInt(1000000), IsOnChain: true, IsOraclePriceRequired: true, IsCdpMintable: true},
{Name: "OSMO", Denom: "uosmo", Decimals: sdk.NewInt(1000000), IsOnChain: false, IsOraclePriceRequired: true, IsCdpMintable: false},
{Name: "CATOM", Denom: "ucatom", Decimals: sdk.NewInt(1000000), IsOnChain: true, IsOraclePriceRequired: false, IsCdpMintable: true},
{Name: "CCMDX", Denom: "uccmdx", Decimals: sdk.NewInt(1000000), IsOnChain: true, IsOraclePriceRequired: false, IsCdpMintable: true},
{Name: "CCMST", Denom: "uccmst", Decimals: sdk.NewInt(1000000), IsOnChain: true, IsOraclePriceRequired: false, IsCdpMintable: true},
{Name: "COSMO", Denom: "ucosmo", Decimals: sdk.NewInt(1000000), IsOnChain: true, IsOraclePriceRequired: false, IsCdpMintable: true},
{Name: "HARBOR", Denom: "uharbor", Decimals: sdk.NewInt(1000000), IsOnChain: true, IsOraclePriceRequired: false, IsCdpMintable: false},
}

for _, asset := range assets {
Expand Down
6 changes: 4 additions & 2 deletions proto/comdex/auction/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ message GenesisState {
[ (gogoproto.moretags) = "yaml:\"protocolStatistics\"", (gogoproto.nullable) = false ];
repeated AuctionParams auctionParams = 5
[ (gogoproto.moretags) = "yaml:\"auctionParams\"", (gogoproto.nullable) = false ];
Params params = 6 [(gogoproto.nullable) = false];
uint64 UserBiddingID = 7 ;
repeated DutchAuction dutchLendAuction = 6
[ (gogoproto.moretags) = "yaml:\"dutchLendAuction\"", (gogoproto.nullable) = false ];
Params params = 7 [(gogoproto.nullable) = false];
uint64 UserBiddingID = 8 ;
}
1 change: 1 addition & 0 deletions proto/comdex/vault/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ message GenesisState {
(gogoproto.moretags) = "yaml:\"userVaultAssetMapping\"",
(gogoproto.nullable) = false
];
uint64 lengthOfVaults = 5 [ (gogoproto.moretags) = "yaml:\"lengthOfVaults\""];
}
25 changes: 12 additions & 13 deletions x/auction/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,37 @@ import (
func InitGenesis(ctx sdk.Context, k keeper.Keeper, state *types.GenesisState) {
k.SetParams(ctx, state.Params)
var auctionID uint64
var lendAuctionID uint64

for _, item := range state.SurplusAuction {
err := k.SetSurplusAuction(ctx, item)
if err != nil {
return
}
k.SetGenSurplusAuction(ctx, item)
}

for _, item := range state.DebtAuction {
err := k.SetDebtAuction(ctx, item)
if err != nil {
return
}
k.SetGenDebtAuction(ctx, item)
}

for _, item := range state.DutchAuction {
err := k.SetDutchAuction(ctx, item)
if err != nil {
return
}
k.SetGenDutchAuction(ctx, item)
auctionID = item.AuctionId
}

k.SetAuctionID(ctx, auctionID)
k.SetUserBiddingID(ctx, state.UserBiddingID)

for _, item := range state.ProtocolStatistics {
k.SetProtocolStatistics(ctx, item.AppId, item.AssetId, sdk.Int(item.Loss))
k.SetGenProtocolStatistics(ctx, item.AppId, item.AssetId, item.Loss)
}

for _, item := range state.AuctionParams {
k.SetAuctionParams(ctx, item)
}

for _, item := range state.DutchAuction {
k.SetGenLendDutchLendAuction(ctx, item)
lendAuctionID = item.AuctionId
}
k.SetLendAuctionID(ctx,lendAuctionID)
}

func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
Expand All @@ -52,6 +50,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
k.GetAllDutchAuctions(ctx),
k.GetAllProtocolStat(ctx),
k.GetAllAuctionParams(ctx),
k.GetDutchLendAuctions(ctx,3),
k.GetParams(ctx),
k.GetUserBiddingID(ctx),
)
Expand Down
57 changes: 57 additions & 0 deletions x/auction/keeper/genesis_store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package keeper

import (
auctiontypes "github.com/comdex-official/comdex/x/auction/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func (k Keeper) SetGenSurplusAuction(ctx sdk.Context, auction auctiontypes.SurplusAuction) {
var (
store = k.Store(ctx)
key = auctiontypes.AuctionKey(auction.AppId, "surplus", auction.AuctionId)
value = k.cdc.MustMarshal(&auction)
)
store.Set(key, value)
}

func (k Keeper) SetGenDebtAuction(ctx sdk.Context, auction auctiontypes.DebtAuction) {
var (
store = k.Store(ctx)
key = auctiontypes.AuctionKey(auction.AppId, "debt", auction.AuctionId)
value = k.cdc.MustMarshal(&auction)
)
store.Set(key, value)
}

func (k Keeper) SetGenDutchAuction(ctx sdk.Context, auction auctiontypes.DutchAuction) {
var (
store = k.Store(ctx)
key = auctiontypes.AuctionKey(auction.AppId, "dutch", auction.AuctionId)
value = k.cdc.MustMarshal(&auction)
)

store.Set(key, value)
}

func (k Keeper) SetGenProtocolStatistics(ctx sdk.Context, appID, assetID uint64, amount sdk.Dec) {
var (
store = k.Store(ctx)
key = auctiontypes.ProtocolStatisticsKey(appID, assetID)
)
var stats auctiontypes.ProtocolStatistics
stats.AppId = appID
stats.AssetId = assetID
stats.Loss = amount
value := k.cdc.MustMarshal(&stats)
store.Set(key, value)
}

func (k Keeper) SetGenLendDutchLendAuction(ctx sdk.Context, auction auctiontypes.DutchAuction) {
var (
store = k.Store(ctx)
key = auctiontypes.LendAuctionKey(auction.AppId, "dutch", auction.AuctionId)
value = k.cdc.MustMarshal(&auction)
)

store.Set(key, value)
}
34 changes: 28 additions & 6 deletions x/auction/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,18 +502,40 @@ func (q QueryServer) QueryDutchLendBiddings(c context.Context, req *types.QueryD
}

var (
ctx = sdk.UnwrapSDKContext(c)
item []types.DutchBiddings
ctx = sdk.UnwrapSDKContext(c)
key []byte
items []types.DutchBiddings
)
if req.History {
item = q.GetHistoryDutchLendUserBiddings(ctx, req.Bidder, req.AppId)
key = types.HistoryLendUserAuctionTypeKey(req.Bidder, req.AppId, types.DutchString)
} else {
item = q.GetDutchLendUserBiddings(ctx, req.Bidder, req.AppId)
key = types.LendUserAuctionTypeKey(req.Bidder, req.AppId, types.DutchString)
}

pagination, err := query.FilteredPaginate(
prefix.NewStore(q.Store(ctx), key),
req.Pagination,
func(_, value []byte, accumulate bool) (bool, error) {
var item types.DutchBiddings
if err := q.cdc.Unmarshal(value, &item); err != nil {
return false, err
}

if accumulate {
items = append(items, item)
}

return true, nil
},
)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &types.QueryDutchLendBiddingsResponse{
Bidder: req.Bidder,
Biddings: item,
Bidder: req.Bidder,
Biddings: items,
Pagination: pagination,
}, nil
}

Expand Down
4 changes: 3 additions & 1 deletion x/auction/types/genesis.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package types

func NewGenesisState(surplusAuction []SurplusAuction, debtAuction []DebtAuction, dutchAuction []DutchAuction, protocolStatistics []ProtocolStatistics, auctionParams []AuctionParams, params Params, userBiddingID uint64) *GenesisState {
func NewGenesisState(surplusAuction []SurplusAuction, debtAuction []DebtAuction, dutchAuction []DutchAuction, protocolStatistics []ProtocolStatistics, auctionParams []AuctionParams, dutchLendAuction []DutchAuction, params Params, userBiddingID uint64) *GenesisState {
return &GenesisState{
SurplusAuction: surplusAuction,
DebtAuction: debtAuction,
DutchAuction: dutchAuction,
ProtocolStatistics: protocolStatistics,
AuctionParams: auctionParams,
DutchLendAuction: dutchLendAuction,
Params: params,
UserBiddingID: userBiddingID,
}
Expand All @@ -20,6 +21,7 @@ func DefaultGenesisState() *GenesisState {
[]DutchAuction{},
[]ProtocolStatistics{},
[]AuctionParams{},
[]DutchAuction{},
DefaultParams(),
UserBiddingID,
)
Expand Down
Loading