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
Merged

Conversation

forcodedancing
Copy link
Contributor

@forcodedancing forcodedancing commented Mar 18, 2020

Description

support busd pair listing and trading

Rationale

we will have a BEP for supporting BUSD pairs, to bring more market liquidity and trading choices for users.

Example

BUSD-BD1 --- XYZ-000
or
XYZ000 --- BUSD-BD1
pairs can be listed and traded.

Changes

Notable changes:

  • add configuration to app.toml for indicating which BUSD is the correct one we are going to support. Considering there could be different BUSD tokens in one chain or cross chains.
  • add a flag for upgrade [the BEP_BUSD flag will be renamed once we have the final BEP NO.]
  • change listing/proposing logic a bit
  • change fee calculation

Preflight checks

  • build passed (make build)
  • tests passed (make test)
  • integration tests passed (make integration_test)
  • manual transaction test passed (cli invoke)

Already reviewed by

...

Related issues

... reference related issue #'s here ...

George added 2 commits March 17, 2020 16:52
add busd pair support, following changes not implmented yet
1) a method to define the standard BUSD token
2) BEP number change
add configuration to indicate the correct BUSD token
@forcodedancing forcodedancing changed the title Support busd pair listing and trading [WIP] Support busd pair listing and trading Mar 18, 2020
@forcodedancing forcodedancing changed the title [WIP] Support busd pair listing and trading Support busd pair listing and trading Mar 26, 2020

if foundFirstPair {
var intermediateTmp int64
if intermediateAmount.IsInt64() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conversion may be omitted since big.Int can be passed to below calculations

Copy link
Contributor Author

@forcodedancing forcodedancing Mar 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, i don't get your point. This sentence "amount = utils.CalBigNotional(market.LastTradePrice, intermediateTmp)" needs an int64.

require.Nil(t, err)
}

func TestKeeper_CanDelistTradingPair_SupportBUSD(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need test a negative case: If only ABC_XYZ and XYZ_BUSD are listed, then delisting XYZ_BUSD before delisting ABC_XYZ should throw error
I think keeper.CanDelistTradingPair need to be modified to pass this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest design is that "for listing ABC_XYZ there should be ABC/BNB and XYZ/BNB pairs, BUSD pairs do not help on this". To make this clear, new test cases are added for both listing and delisting.

@@ -358,7 +362,9 @@ type UpgradeConfig struct {
// Hubble Upgrade
BEP12Height int64 `mapstructure:"BEP12Height"`
// Archimedes Upgrade
BEP3Height int64 `mapstructure:"BEP3Height"`
BEP3Height int64 `mapstructure:"BEP3Height"`
BEP_BUSDHeight int64 `mapstructure:"BEP_BUSDHeight"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please follow the naming convension

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, will rename it after we have the BEP finalized. Or, can we have the BEP NO. now?

@@ -392,6 +399,16 @@ func defaultQueryConfig() *QueryConfig {
}
}

type GovConfig struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's not a gov related config. can you create a DexConfig instead and remember the update the config template above.

@@ -392,6 +399,16 @@ func defaultQueryConfig() *QueryConfig {
}
}

type GovConfig struct {
SupportedListAgainstSymbols []string `mapstructure:"SupportedListAgainstSymbols"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we just simplify the config to BusdSymbol. I don't think we would support multiple assets, or if we want to support multiple assets, we need to have a more reasonable solution instead of the config way.

@rickyyangz
Copy link
Contributor

besides the fee change, the most important part is the listing rule. I do not see any related changes.

@forcodedancing
Copy link
Contributor Author

besides the fee change, the most important part is the listing rule. I do not see any related changes.

This file: plugins/dex/order/keeper.go
Func: CanListTradingPair

} else {
// for BUSD pairs, it is possible that there is no trading pair between BNB and inAsset, e.g., BUSD -> XYZ
if sdk.IsUpgrade(upgrade.BEP_BUSD) {
for _, symbol := range m.GovSupportedSymbols {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to check all the symbols. Each TradeTransfer has both in and out asset symbol and quantity, you just need to use the opposite quantity to calc the native fee. we can talk offline

} else {
// for BUSD pairs, it is possible that there is no trading pair between BNB and inAsset, e.g., BUSD -> XYZ
if sdk.IsUpgrade(upgrade.BEP_BUSD) {
for _, symbol := range m.GovSupportedSymbols {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -143,15 +147,44 @@ func (m *FeeManager) calcNativeFee(inSymbol string, inQty int64, engines map[str
if engine, ok := engines[utils.Assets2TradingPair(inSymbol, types.NativeTokenSymbol)]; ok {
// XYZ_BNB
nativeNotional = utils.CalBigNotional(engine.LastTradePrice, inQty)
} else {
} else if engine, ok := engines[utils.Assets2TradingPair(types.NativeTokenSymbol, inSymbol)]; ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you help extract such code into a method, like getEngine, I see we have so many places using that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

if sdk.IsUpgrade(upgrade.BEP_BUSD) {
if baseAsset == kp.BUSDSymbol || quoteAsset == kp.BUSDSymbol {
if kp.PairMapper.Exists(ctx, types.NativeTokenSymbol, kp.BUSDSymbol) ||
kp.PairMapper.Exists(ctx, kp.BUSDSymbol, types.NativeTokenSymbol) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you help refactor these codes

if kp.PairMapper.Exists(ctx, symbolA, symbolB) || kp.PairMapper.Exists(ctx, symbolB, symbolA)

into a method like kp.PairExists(ctx, symbolA, symbolB). we have many code pieces like that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

@@ -66,7 +67,7 @@ func CreateMatchEng(pairSymbol string, basePrice, lotSize int64) *me.MatchEng {

// NewKeeper - Returns the Keeper
func NewKeeper(key sdk.StoreKey, am auth.AccountKeeper, tradingPairMapper store.TradingPairMapper, codespace sdk.CodespaceType,
concurrency uint, cdc *wire.Codec, collectOrderInfoForPublish bool) *Keeper {
concurrency uint, busdSymbol string, cdc *wire.Codec, collectOrderInfoForPublish bool) *Keeper {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest not adding a parameter to the keeper. Actually a keeper can work without a busdsymbol.
so adding a method like SetBusdSymbol to set it may be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -360,7 +368,9 @@ type UpgradeConfig struct {
// Hubble Upgrade
BEP12Height int64 `mapstructure:"BEP12Height"`
// Archimedes Upgrade
BEP3Height int64 `mapstructure:"BEP3Height"`
BEP3Height int64 `mapstructure:"BEP3Height"`
BEP70Height int64 `mapstructure:"BEP70Height"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you put the config after bep67, we group these configs by upgrade name

@@ -379,6 +389,7 @@ func defaultUpgradeConfig() *UpgradeConfig {
BEP19Height: 1,
BEP12Height: 1,
BEP3Height: 1,
BEP70Height: 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -17,6 +17,9 @@ const (
BEP12 = "BEP12" // https://github.com/binance-chain/BEPs/pull/17
// Archimedes Upgrade
BEP3 = "BEP3" // https://github.com/binance-chain/BEPs/pull/30
// BUSD Pair Upgrade
BEP70 = "BEP70" // supporting listing and trading BUSD pairs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@forcodedancing forcodedancing merged commit 3e4d4c0 into develop Apr 27, 2020
@EnderCrypto EnderCrypto changed the title Support busd pair listing and trading BEP70 - Support busd pair listing and trading Jun 2, 2020
@EnderCrypto EnderCrypto mentioned this pull request Jun 2, 2020
@unclezoro unclezoro deleted the support_busd branch May 10, 2022 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants