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

BEP70 - Support busd pair listing and trading #710

Merged
merged 13 commits into from
Apr 27, 2020
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ vendor
*.swp
.vscode/*.json

# Test generate tmp files
app/data
app/apptest/data
app_test/data
plugins/param/data
plugins/tokens/data
10 changes: 8 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ type BinanceChain struct {
publicationConfig *config.PublicationConfig
publisher pub.MarketDataPublisher

dexConfig *config.DexConfig

// Unlike tendermint, we don't need implement a no-op metrics, usage of this field should
// check nil-ness to know whether metrics collection is turn on
// TODO(#246): make it an aggregated wrapper of all component metrics (i.e. DexKeeper, StakeKeeper)
Expand All @@ -119,6 +121,7 @@ func NewBinanceChain(logger log.Logger, db dbm.DB, traceStore io.Writer, baseApp
upgradeConfig: ServerContext.UpgradeConfig,
abciQueryBlackList: getABCIQueryBlackList(ServerContext.QueryConfig),
publicationConfig: ServerContext.PublicationConfig,
dexConfig: ServerContext.DexConfig,
}
// set upgrade config
SetUpgradeConfig(app.upgradeConfig)
Expand Down Expand Up @@ -264,6 +267,8 @@ func SetUpgradeConfig(upgradeConfig *config.UpgradeConfig) {
upgrade.Mgr.AddUpgradeHeight(upgrade.ListingRuleUpgrade, upgradeConfig.ListingRuleUpgradeHeight)
upgrade.Mgr.AddUpgradeHeight(upgrade.FixZeroBalance, upgradeConfig.FixZeroBalanceHeight)
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP67, upgradeConfig.BEP67Height)
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP70, upgradeConfig.BEP70Height)


// register store keys of upgrade
upgrade.Mgr.RegisterStoreKeys(upgrade.BEP9, common.TimeLockStoreKey.Name())
Expand Down Expand Up @@ -303,9 +308,10 @@ func (app *BinanceChain) initRunningMode() {

func (app *BinanceChain) initDex(pairMapper dex.TradingPairMapper) {
app.DexKeeper = dex.NewOrderKeeper(common.DexStoreKey, app.AccountKeeper, pairMapper,
app.RegisterCodespace(dex.DefaultCodespace), app.baseConfig.OrderKeeperConcurrency, app.Codec,
app.publicationConfig.ShouldPublishAny())
app.RegisterCodespace(dex.DefaultCodespace), app.baseConfig.OrderKeeperConcurrency,
app.Codec, app.publicationConfig.ShouldPublishAny())
app.DexKeeper.SubscribeParamChange(app.ParamHub)
app.DexKeeper.SetBUSDSymbol(app.dexConfig.BUSDSymbol)

// do not proceed if we are in a unit test and `CheckState` is unset.
if app.CheckState == nil {
Expand Down
25 changes: 23 additions & 2 deletions app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ BEP6Height = {{ .UpgradeConfig.BEP6Height }}
BEP9Height = {{ .UpgradeConfig.BEP9Height }}
# Block height of BEP10 upgrade
BEP10Height = {{ .UpgradeConfig.BEP10Height }}
# Block height of BEP19Height upgrade
# Block height of BEP19 upgrade
BEP19Height = {{ .UpgradeConfig.BEP19Height }}
# Block height of BEP12 upgrade
BEP12Height = {{ .UpgradeConfig.BEP12Height }}
Expand All @@ -69,6 +69,8 @@ ListingRuleUpgradeHeight = {{ .UpgradeConfig.ListingRuleUpgradeHeight }}
FixZeroBalanceHeight = {{ .UpgradeConfig.FixZeroBalanceHeight }}
# Block height of BEP67 upgrade
BEP67Height = {{ .UpgradeConfig.BEP67Height }}
# Block height of BEP70 upgrade
BEP70Height = {{ .UpgradeConfig.BEP70Height }}

[query]
# ABCI query interface black list, suggested value: ["custom/gov/proposals", "custom/timelock/timelocks", "custom/atomicSwap/swapcreator", "custom/atomicSwap/swaprecipient"]
Expand Down Expand Up @@ -154,6 +156,10 @@ logFileRoot = "{{ .LogConfig.LogFileRoot }}"
logFilePath = "{{ .LogConfig.LogFilePath }}"
# Number of logs keep in memory before writing to file
logBuffSize = {{ .LogConfig.LogBuffSize }}

[dex]
# The suffixed symbol of BUSD
BUSDSymbol = "{{ .DexConfig.BUSDSymbol }}"
`

type BinanceChainContext struct {
Expand All @@ -180,6 +186,7 @@ type BinanceChainConfig struct {
*BaseConfig `mapstructure:"base"`
*UpgradeConfig `mapstructure:"upgrade"`
*QueryConfig `mapstructure:"query"`
*DexConfig `mapstructure:"dex"`
}

func DefaultBinanceChainConfig() *BinanceChainConfig {
Expand All @@ -190,6 +197,7 @@ func DefaultBinanceChainConfig() *BinanceChainConfig {
BaseConfig: defaultBaseConfig(),
UpgradeConfig: defaultUpgradeConfig(),
QueryConfig: defaultQueryConfig(),
DexConfig: defaultGovConfig(),
}
}

Expand Down Expand Up @@ -360,14 +368,16 @@ type UpgradeConfig struct {
// Hubble Upgrade
BEP12Height int64 `mapstructure:"BEP12Height"`
// Archimedes Upgrade
BEP3Height int64 `mapstructure:"BEP3Height"`
BEP3Height int64 `mapstructure:"BEP3Height"`

// TODO: add upgrade name
FixSignBytesOverflowHeight int64 `mapstructure:"FixSignBytesOverflowHeight"`
LotSizeUpgradeHeight int64 `mapstructure:"LotSizeUpgradeHeight"`
ListingRuleUpgradeHeight int64 `mapstructure:"ListingRuleUpgradeHeight"`
FixZeroBalanceHeight int64 `mapstructure:"FixZeroBalanceHeight"`

BEP67Height int64 `mapstructure:"BEP67Height"`
BEP70Height int64 `mapstructure:"BEP70Height"`
}

func defaultUpgradeConfig() *UpgradeConfig {
Expand All @@ -384,6 +394,7 @@ func defaultUpgradeConfig() *UpgradeConfig {
ListingRuleUpgradeHeight: math.MaxInt64,
FixZeroBalanceHeight: math.MaxInt64,
BEP67Height: 1,
BEP70Height: 1,
}
}

Expand All @@ -397,6 +408,16 @@ func defaultQueryConfig() *QueryConfig {
}
}

type DexConfig struct {
BUSDSymbol string `mapstructure:"BUSDSymbol"`
}

func defaultGovConfig() *DexConfig {
return &DexConfig{
BUSDSymbol: "",
}
}

func (context *BinanceChainContext) ParseAppConfigInPlace() error {
// this piece of code should be consistent with bindFlagsLoadViper
// vendor/github.com/tendermint/tendermint/libs/cli/setup.go:125
Expand Down
4 changes: 4 additions & 0 deletions common/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ const (
BEP12 = "BEP12" // https://github.com/binance-chain/BEPs/pull/17
// Archimedes Upgrade
BEP3 = "BEP3" // https://github.com/binance-chain/BEPs/pull/30


// TODO: add upgrade name
FixSignBytesOverflow = sdk.FixSignBytesOverflow
LotSizeOptimization = "LotSizeOptimization"
ListingRuleUpgrade = "ListingRuleUpgrade" // Remove restriction that only the owner of base asset can list trading pair
FixZeroBalance = "FixZeroBalance"

BEP67 = "BEP67" // https://github.com/binance-chain/BEPs/pull/67
// BUSD Pair Upgrade
BEP70 = "BEP70" // https://github.com/binance-chain/BEPs/pull/70
)

func UpgradeBEP10(before func(), after func()) {
Expand Down
Loading