-
Notifications
You must be signed in to change notification settings - Fork 41
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
Conversation
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
plugins/dex/order/fee.go
Outdated
|
||
if foundFirstPair { | ||
var intermediateTmp int64 | ||
if intermediateAmount.IsInt64() { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
app/config/config.go
Outdated
@@ -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"` |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
app/config/config.go
Outdated
@@ -392,6 +399,16 @@ func defaultQueryConfig() *QueryConfig { | |||
} | |||
} | |||
|
|||
type GovConfig struct { |
There was a problem hiding this comment.
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.
app/config/config.go
Outdated
@@ -392,6 +399,16 @@ func defaultQueryConfig() *QueryConfig { | |||
} | |||
} | |||
|
|||
type GovConfig struct { | |||
SupportedListAgainstSymbols []string `mapstructure:"SupportedListAgainstSymbols"` |
There was a problem hiding this comment.
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.
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 |
plugins/dex/order/fee.go
Outdated
} 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 { |
There was a problem hiding this comment.
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
plugins/dex/order/fee.go
Outdated
} 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
plugins/dex/order/fee.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
plugins/dex/order/keeper.go
Outdated
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it
plugins/dex/order/keeper.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
app/config/config.go
Outdated
@@ -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"` |
There was a problem hiding this comment.
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
app/config/config.go
Outdated
@@ -379,6 +389,7 @@ func defaultUpgradeConfig() *UpgradeConfig { | |||
BEP19Height: 1, | |||
BEP12Height: 1, | |||
BEP3Height: 1, | |||
BEP70Height: 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
common/upgrade/upgrade.go
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
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:
Preflight checks
make build
)make test
)make integration_test
)Already reviewed by
...
Related issues
... reference related issue #'s here ...