Skip to content

Commit

Permalink
Merge PR: v0.11.0 migrate feature (#313)
Browse files Browse the repository at this point in the history
* v0.11 migrate feature

* fix staking migrate issue

* update genesis.json

* update comments

* delete history migrate

Co-authored-by: Zhong Qiu <[email protected]>
  • Loading branch information
ilovers and zhongqiuwood authored Aug 5, 2020
1 parent 7b42378 commit 811f2b5
Show file tree
Hide file tree
Showing 48 changed files with 622 additions and 2,317 deletions.
14 changes: 6 additions & 8 deletions app/genesis/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
},
"debug": null,
"dex": {
"max_token_pair_id": "0",
"operators": null,
"params": {
"delist_max_deposit_period": "86400000000000",
"delist_min_deposit": [
Expand All @@ -72,6 +74,10 @@
"amount": "20000.00000000",
"denom": "okt"
},
"register_operator_fee": {
"amount": "0.00000000",
"denom": "okt"
},
"transfer_ownership_fee": {
"amount": "10.00000000",
"denom": "okt"
Expand Down Expand Up @@ -206,12 +212,6 @@
"voting_period": "259200000000000"
}
},
"poolswap": {
"params": {
"fee_rate": "0.00300000"
},
"swap_token_pair_records": null
},
"slashing": {
"missed_blocks": {},
"params": {
Expand Down Expand Up @@ -280,8 +280,6 @@
"original_total_supply": "1000000000.00000000",
"owner": "okchain10q0rk5qnyag7wfvvt7rtphlw589m7frsmyq4ya",
"symbol": "okt",
"total_supply": "1000000000.00000000",
"type": "0",
"whole_name": "OKT"
}
]
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/okex/cosmos-sdk v0.37.9-okchain7 h1:Y6bGsI6qy4gccPSEDfZ40BNhk3mnODl6RKnC063tLiA=
github.com/okex/cosmos-sdk v0.37.9-okchain7/go.mod h1:HjW0+Q5rWWm+4CaK8f5CIN/xf38vkPA2xue1PB5Nk3A=
github.com/okex/cosmos-sdk v0.37.9-okchain8 h1:wefXKagVlmm5KVNzXBrlqvh17axzmZSTBsbES30Ma0w=
github.com/okex/cosmos-sdk v0.37.9-okchain8/go.mod h1:HjW0+Q5rWWm+4CaK8f5CIN/xf38vkPA2xue1PB5Nk3A=
github.com/okex/iavl v0.12.4-okchain h1:BAFmygzhx6k4KGnLrY87ZrJvRSb+wf8Oo4e2KhUwXcU=
github.com/okex/iavl v0.12.4-okchain/go.mod h1:8LHakzt8/0G3/I8FUU0ReNx98S/EP6eyPJkAUvEXT/o=
github.com/okex/tendermint v0.32.10-okchain1 h1:mEsl6YGb7mCkJaXZxnIZO6/jmF947X39wFa4oI8gKgE=
Expand Down
2 changes: 1 addition & 1 deletion x/dex/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
ordertypes "github.com/okex/okchain/x/order/types"
)

// GenesisState - all slashing state that must be provided at genesis
// GenesisState - all dex state that must be provided at genesis
type GenesisState struct {
Params Params `json:"params"`
TokenPairs []*TokenPair `json:"token_pairs"`
Expand Down
71 changes: 71 additions & 0 deletions x/dex/legacy/v0_10/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package v0_10

import (
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
)

const ModuleName = "dex"

type (
// GenesisState - all dex state that must be provided at genesis
GenesisState struct {
Params Params `json:"params"`
TokenPairs []*TokenPair `json:"token_pairs"`
WithdrawInfos WithdrawInfos `json:"withdraw_infos"`
ProductLocks ProductLockMap `json:"product_locks"`
}

// Params defines param object
Params struct {
ListFee sdk.DecCoin `json:"list_fee"`
TransferOwnershipFee sdk.DecCoin `json:"transfer_ownership_fee"`

// maximum period for okt holders to deposit on a dex delist proposal
DelistMaxDepositPeriod time.Duration `json:"delist_max_deposit_period"`
// minimum deposit for a critical dex delist proposal to enter voting period
DelistMinDeposit sdk.DecCoins `json:"delist_min_deposit"`
// length of the critical voting period for dex delist proposal
DelistVotingPeriod time.Duration `json:"delist_voting_period"`

WithdrawPeriod time.Duration `json:"withdraw_period"`
}

// TokenPair represents token pair object
TokenPair struct {
BaseAssetSymbol string `json:"base_asset_symbol"`
QuoteAssetSymbol string `json:"quote_asset_symbol"`
InitPrice sdk.Dec `json:"price"`
MaxPriceDigit int64 `json:"max_price_digit"`
MaxQuantityDigit int64 `json:"max_size_digit"`
MinQuantity sdk.Dec `json:"min_trade_size"`
ID uint64 `json:"token_pair_id"`
Delisting bool `json:"delisting"`
Owner sdk.AccAddress `json:"owner"`
Deposits sdk.DecCoin `json:"deposits"`
BlockHeight int64 `json:"block_height"`
}

// WithdrawInfo represents infos for withdrawing
WithdrawInfo struct {
Owner sdk.AccAddress `json:"owner"`
Deposits sdk.DecCoin `json:"deposits"`
CompleteTime time.Time `json:"complete_time"`
}

// WithdrawInfos defines list of WithdrawInfo
WithdrawInfos []WithdrawInfo

ProductLock struct {
BlockHeight int64
Price sdk.Dec
Quantity sdk.Dec
BuyExecuted sdk.Dec
SellExecuted sdk.Dec
}

ProductLockMap struct {
Data map[string]*ProductLock
}
)
50 changes: 50 additions & 0 deletions x/dex/legacy/v0_11/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package v0_11

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/okex/okchain/x/common"
"github.com/okex/okchain/x/dex/legacy/v0_10"
)

func Migrate(oldGenState v0_10.GenesisState) GenesisState {
params := Params{
ListFee: oldGenState.Params.ListFee,
TransferOwnershipFee: oldGenState.Params.TransferOwnershipFee,
DelistMaxDepositPeriod: oldGenState.Params.DelistMaxDepositPeriod,
DelistMinDeposit: oldGenState.Params.DelistMinDeposit,
DelistVotingPeriod: oldGenState.Params.DelistVotingPeriod,
WithdrawPeriod: oldGenState.Params.WithdrawPeriod,
RegisterOperatorFee: sdk.NewDecCoinFromDec(common.NativeToken, sdk.ZeroDec()),
}

operatorMap := make(map[string]struct{})
var operators DEXOperators
var maxTokenPairID uint64 = 0
for _, pair := range oldGenState.TokenPairs {
if pair.ID > maxTokenPairID {
maxTokenPairID = pair.ID
}

if _, exist := operatorMap[pair.Owner.String()]; exist {
continue
}
operatorMap[pair.Owner.String()] = struct{}{}
operator := DEXOperator{
Address: pair.Owner,
HandlingFeeAddress: pair.Owner,
Website: "",
InitHeight: pair.BlockHeight,
TxHash: "",
}
operators = append(operators, operator)
}

return GenesisState{
Params: params,
TokenPairs: oldGenState.TokenPairs,
WithdrawInfos: oldGenState.WithdrawInfos,
ProductLocks: oldGenState.ProductLocks,
Operators: operators,
MaxTokenPairID: maxTokenPairID,
}
}
53 changes: 53 additions & 0 deletions x/dex/legacy/v0_11/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package v0_11

import (
"time"

"github.com/okex/okchain/x/dex/legacy/v0_10"

sdk "github.com/cosmos/cosmos-sdk/types"
)

const (
ModuleName = "dex"
)

type (
// GenesisState - all dex state that must be provided at genesis
GenesisState struct {
Params Params `json:"params"`
TokenPairs []*v0_10.TokenPair `json:"token_pairs"`
WithdrawInfos v0_10.WithdrawInfos `json:"withdraw_infos"`
ProductLocks v0_10.ProductLockMap `json:"product_locks"`
Operators DEXOperators `json:"operators"`
MaxTokenPairID uint64 `json:"max_token_pair_id" yaml:"max_token_pair_id"`
}

// Params defines param object
Params struct {
ListFee sdk.DecCoin `json:"list_fee"`
TransferOwnershipFee sdk.DecCoin `json:"transfer_ownership_fee"`
RegisterOperatorFee sdk.DecCoin `json:"register_operator_fee"`

// maximum period for okt holders to deposit on a dex delist proposal
DelistMaxDepositPeriod time.Duration `json:"delist_max_deposit_period"`
// minimum deposit for a critical dex delist proposal to enter voting period
DelistMinDeposit sdk.DecCoins `json:"delist_min_deposit"`
// length of the critical voting period for dex delist proposal
DelistVotingPeriod time.Duration `json:"delist_voting_period"`

WithdrawPeriod time.Duration `json:"withdraw_period"`
}

// OperatorAddress sdk.ValAddress `json:"operator_address" yaml:"operator_address"`
DEXOperator struct {
Address sdk.AccAddress `json:"address"`
HandlingFeeAddress sdk.AccAddress `json:"handling_fee_address"`
Website string `json:"website"`
InitHeight int64 `json:"init_height"`
TxHash string `json:"tx_hash"`
}

// nolint
DEXOperators []DEXOperator
)
34 changes: 0 additions & 34 deletions x/dex/legacy/v0_9/migrate.go

This file was deleted.

19 changes: 0 additions & 19 deletions x/dex/legacy/v0_9/types.go

This file was deleted.

3 changes: 1 addition & 2 deletions x/dex/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ var (
type Params struct {
ListFee sdk.DecCoin `json:"list_fee"`
TransferOwnershipFee sdk.DecCoin `json:"transfer_ownership_fee"`
//DelistFee sdk.DecCoins `json:"delist_fee"`
RegisterOperatorFee sdk.DecCoin `json:"register_operator_fee"`
RegisterOperatorFee sdk.DecCoin `json:"register_operator_fee"`

// maximum period for okt holders to deposit on a dex delist proposal
DelistMaxDepositPeriod time.Duration `json:"delist_max_deposit_period"`
Expand Down
Loading

0 comments on commit 811f2b5

Please sign in to comment.