-
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
Changes from 2 commits
57b3caa
fc1ffd4
ddbeca3
8ed1e06
0e46d38
018598e
65ae54a
53e2c6e
7b9e938
ba142c2
c1fa20a
72f09d9
5d9010b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,8 @@ LotSizeUpgradeHeight = {{ .UpgradeConfig.LotSizeUpgradeHeight }} | |
ListingRuleUpgradeHeight = {{ .UpgradeConfig.ListingRuleUpgradeHeight }} | ||
# Block height of FixZeroBalanceHeight upgrade | ||
FixZeroBalanceHeight = {{ .UpgradeConfig.FixZeroBalanceHeight }} | ||
# Block height to BEP_BUSD upgrade | ||
BEP_BUSDHeight = {{ .UpgradeConfig.BEP_BUSDHeight }} | ||
|
||
[query] | ||
# ABCI query interface black list, suggested value: ["custom/gov/proposals", "custom/timelock/timelocks", "custom/atomicSwap/swapcreator", "custom/atomicSwap/swaprecipient"] | ||
|
@@ -178,6 +180,7 @@ type BinanceChainConfig struct { | |
*BaseConfig `mapstructure:"base"` | ||
*UpgradeConfig `mapstructure:"upgrade"` | ||
*QueryConfig `mapstructure:"query"` | ||
*GovConfig `mapstructure:"gov"` | ||
} | ||
|
||
func DefaultBinanceChainConfig() *BinanceChainConfig { | ||
|
@@ -188,6 +191,7 @@ func DefaultBinanceChainConfig() *BinanceChainConfig { | |
BaseConfig: defaultBaseConfig(), | ||
UpgradeConfig: defaultUpgradeConfig(), | ||
QueryConfig: defaultQueryConfig(), | ||
GovConfig: defaultGovConfig(), | ||
} | ||
} | ||
|
||
|
@@ -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"` | ||
|
||
// TODO: add upgrade name | ||
FixSignBytesOverflowHeight int64 `mapstructure:"FixSignBytesOverflowHeight"` | ||
LotSizeUpgradeHeight int64 `mapstructure:"LotSizeUpgradeHeight"` | ||
|
@@ -375,6 +381,7 @@ func defaultUpgradeConfig() *UpgradeConfig { | |
BEP19Height: 1, | ||
BEP12Height: 1, | ||
BEP3Height: 1, | ||
BEP_BUSDHeight: 1, | ||
FixSignBytesOverflowHeight: math.MaxInt64, | ||
LotSizeUpgradeHeight: math.MaxInt64, | ||
ListingRuleUpgradeHeight: math.MaxInt64, | ||
|
@@ -392,6 +399,16 @@ func defaultQueryConfig() *QueryConfig { | |
} | ||
} | ||
|
||
type GovConfig struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
SupportedListAgainstSymbols []string `mapstructure:"SupportedListAgainstSymbols"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
|
||
func defaultGovConfig() *GovConfig { | ||
return &GovConfig{ | ||
SupportedListAgainstSymbols: nil, | ||
} | ||
} | ||
|
||
func (context *BinanceChainContext) ParseAppConfigInPlace() error { | ||
// this piece of code should be consistent with bindFlagsLoadViper | ||
// vendor/github.com/tendermint/tendermint/libs/cli/setup.go:125 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ import ( | |
"math" | ||
"math/big" | ||
|
||
"github.com/binance-chain/node/common/upgrade" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
tmlog "github.com/tendermint/tendermint/libs/log" | ||
|
@@ -42,16 +44,18 @@ var ( | |
) | ||
|
||
type FeeManager struct { | ||
cdc *wire.Codec | ||
logger tmlog.Logger | ||
FeeConfig FeeConfig | ||
cdc *wire.Codec | ||
logger tmlog.Logger | ||
FeeConfig FeeConfig | ||
GovSupportedSymbols []string | ||
} | ||
|
||
func NewFeeManager(cdc *wire.Codec, storeKey sdk.StoreKey, logger tmlog.Logger) *FeeManager { | ||
func NewFeeManager(cdc *wire.Codec, storeKey sdk.StoreKey, sybmols []string, logger tmlog.Logger) *FeeManager { | ||
return &FeeManager{ | ||
cdc: cdc, | ||
logger: logger, | ||
FeeConfig: NewFeeConfig(), | ||
cdc: cdc, | ||
logger: logger, | ||
FeeConfig: NewFeeConfig(), | ||
GovSupportedSymbols: sybmols, | ||
} | ||
} | ||
|
||
|
@@ -134,7 +138,7 @@ func (m *FeeManager) calcTradeFeeForSingleTransfer(balances sdk.Coins, tran *Tra | |
} | ||
|
||
func (m *FeeManager) calcNativeFee(inSymbol string, inQty int64, engines map[string]*matcheng.MatchEng) (fee int64, isOverflow bool) { | ||
var nativeNotional *big.Int | ||
var nativeNotional = big.NewInt(0) | ||
if isNativeToken(inSymbol) { | ||
nativeNotional = big.NewInt(inQty) | ||
} else { | ||
|
@@ -143,15 +147,58 @@ 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 commentThe reason will be displayed to describe this comment to others. Learn more. could you help extract such code into a method, like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure |
||
// BNB_XYZ | ||
engine := engines[utils.Assets2TradingPair(types.NativeTokenSymbol, inSymbol)] | ||
var amount big.Int | ||
nativeNotional = amount.Div( | ||
amount.Mul( | ||
big.NewInt(inQty), | ||
big.NewInt(cmnUtils.Fixed8One.ToInt64())), | ||
big.NewInt(engine.LastTradePrice)) | ||
} 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 commentThe reason will be displayed to describe this comment to others. Learn more. no need to check all the symbols. Each TradeTransfer has both |
||
var foundFirstPair, foundSecondPair bool | ||
var intermediateAmount = big.NewInt(0) | ||
|
||
if market, ok := engines[utils.Assets2TradingPair(symbol, inSymbol)]; ok { | ||
foundFirstPair = true | ||
var tmp big.Int | ||
intermediateAmount = tmp.Div(tmp.Mul( | ||
big.NewInt(inQty), | ||
big.NewInt(cmnUtils.Fixed8One.ToInt64())), | ||
big.NewInt(market.LastTradePrice)) | ||
} else if market, ok := engines[utils.Assets2TradingPair(inSymbol, symbol)]; ok { | ||
foundFirstPair = true | ||
intermediateAmount = utils.CalBigNotional(market.LastTradePrice, inQty) | ||
} | ||
|
||
if foundFirstPair { | ||
var intermediateTmp int64 | ||
if intermediateAmount.IsInt64() { | ||
intermediateTmp = intermediateAmount.Int64() | ||
} else { | ||
intermediateTmp = math.MaxInt64 | ||
} | ||
if market, ok := engines[utils.Assets2TradingPair(types.NativeTokenSymbol, symbol)]; ok { | ||
foundSecondPair = true | ||
var tmp big.Int | ||
nativeNotional = tmp.Div(tmp.Mul( | ||
big.NewInt(intermediateTmp), | ||
big.NewInt(cmnUtils.Fixed8One.ToInt64())), | ||
big.NewInt(market.LastTradePrice)) | ||
} else if market, ok := engines[utils.Assets2TradingPair(symbol, types.NativeTokenSymbol)]; ok { | ||
foundSecondPair = true | ||
nativeNotional = utils.CalBigNotional(market.LastTradePrice, intermediateTmp) | ||
} | ||
} | ||
|
||
if foundFirstPair && foundSecondPair { | ||
break | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
@@ -238,18 +285,62 @@ func (m *FeeManager) CalcFixedFee(balances sdk.Coins, eventType transferEventTyp | |
} else { | ||
// the amount may overflow int64, so use big.Int instead. | ||
// TODO: (perf) may remove the big.Int use to improve the performance | ||
var amount *big.Int | ||
var amount = big.NewInt(0) | ||
if market, ok := engines[utils.Assets2TradingPair(inAsset, types.NativeTokenSymbol)]; ok { | ||
// XYZ_BNB | ||
var tmp big.Int | ||
amount = tmp.Div(tmp.Mul( | ||
big.NewInt(feeAmount), | ||
big.NewInt(cmnUtils.Fixed8One.ToInt64())), | ||
big.NewInt(market.LastTradePrice)) | ||
} else { | ||
} else if market, ok := engines[utils.Assets2TradingPair(types.NativeTokenSymbol, inAsset)]; ok { | ||
// BNB_XYZ | ||
market = engines[utils.Assets2TradingPair(types.NativeTokenSymbol, inAsset)] | ||
amount = utils.CalBigNotional(market.LastTradePrice, feeAmount) | ||
} 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 commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
var foundFirstPair, foundSecondPair bool | ||
var intermediateAmount = big.NewInt(0) | ||
|
||
if market, ok := engines[utils.Assets2TradingPair(symbol, types.NativeTokenSymbol)]; ok { | ||
foundFirstPair = true | ||
var tmp big.Int | ||
intermediateAmount = tmp.Div(tmp.Mul( | ||
big.NewInt(feeAmount), | ||
big.NewInt(cmnUtils.Fixed8One.ToInt64())), | ||
big.NewInt(market.LastTradePrice)) | ||
} else if market, ok := engines[utils.Assets2TradingPair(types.NativeTokenSymbol, symbol)]; ok { | ||
foundFirstPair = true | ||
intermediateAmount = utils.CalBigNotional(market.LastTradePrice, feeAmount) | ||
} | ||
|
||
if foundFirstPair { | ||
var intermediateTmp int64 | ||
if intermediateAmount.IsInt64() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
intermediateTmp = intermediateAmount.Int64() | ||
} else { | ||
intermediateTmp = math.MaxInt64 | ||
} | ||
|
||
if market, ok := engines[utils.Assets2TradingPair(inAsset, symbol)]; ok { | ||
foundSecondPair = true | ||
var tmp big.Int | ||
amount = tmp.Div(tmp.Mul( | ||
big.NewInt(intermediateTmp), | ||
big.NewInt(cmnUtils.Fixed8One.ToInt64())), | ||
big.NewInt(market.LastTradePrice)) | ||
} else if market, ok := engines[utils.Assets2TradingPair(symbol, inAsset)]; ok { | ||
foundSecondPair = true | ||
amount = utils.CalBigNotional(market.LastTradePrice, intermediateTmp) | ||
} | ||
} | ||
|
||
if foundFirstPair && foundSecondPair { | ||
break | ||
} | ||
} | ||
} | ||
} | ||
|
||
if amount.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.
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?