Skip to content

Commit

Permalink
0.7.2 Upgrade (#756)
Browse files Browse the repository at this point in the history
* delete recent price from db when delisting (#753)

delete recent price from db when delisting

* bump up version

* update changelog

* delete recent price key when recent price map is empty (#760)

* Force match all BEP2 symbols on BEP8 upgrade height to update last ma… (#758)

 Force match all BEP2 symbols on BEP8 upgrade height to update last match height

* Fix mini msg (#762)

* fix unfreeze err msg; adjust mini issue/list fee; update changelog
  • Loading branch information
EnderCrypto authored and forcodedancing committed May 19, 2022
1 parent 2cb437e commit e72fa70
Show file tree
Hide file tree
Showing 30 changed files with 409 additions and 166 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.7.2
BUG FIXES
* [\#753](https://github.com/binance-chain/node/pull/753) [\#760](https://github.com/binance-chain/node/pull/760) [Dex] Delete recent price from db when delisting
* [\#758](https://github.com/binance-chain/node/pull/758) [Dex] Force match all BEP2 symbols on BEP8 upgrade height to update last match height
* [\#762](https://github.com/binance-chain/node/pull/762) [Dex] Fix mini msg
## 0.7.0
FEATURES
* [\#725](https://github.com/binance-chain/node/pull/725) [Token] [Dex] BEP8 - Mini-BEP2 token features
Expand Down
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/binance-chain/node/plugins/dex"
"github.com/binance-chain/node/plugins/dex/list"
"github.com/binance-chain/node/plugins/dex/order"
dextypes "github.com/binance-chain/node/plugins/dex/types"
"github.com/binance-chain/node/plugins/ico"
"github.com/binance-chain/node/plugins/param"
"github.com/binance-chain/node/plugins/param/paramhub"
Expand Down Expand Up @@ -295,7 +296,7 @@ func SetUpgradeConfig(upgradeConfig *config.UpgradeConfig) {
issue.IssueMiniMsg{}.Type(),
issue.IssueTinyMsg{}.Type(),
seturi.SetURIMsg{}.Type(),
list.ListMiniMsg{}.Type(),
dextypes.ListMiniMsg{}.Type(),
)
}

Expand Down
2 changes: 1 addition & 1 deletion common/types/mini_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (

MiniTokenMinExecutionAmount int64 = 1e8 // 1 with 8 decimal digits
MiniTokenSupplyUpperBound int64 = 1000000e8 // 1m with 8 decimal digits
TinyTokenSupplyUpperBound int64 = 10000e8 // 10k with 8 decimal digits
TinyTokenSupplyUpperBound int64 = 10000e8 // 10k with 8 decimal digits
MaxTokenURILength = 2048

TinyRangeType SupplyRangeType = 1
Expand Down
8 changes: 8 additions & 0 deletions integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ function prepare_node() {
#$(cd "./${home}/config" && sed -i -e "s/db_backend = \"goleveldb\"/db_backend = \"boltdb\"/g" config.toml)
$(cd "./${home}/config" && sed -i -e "s/log_level = \"main\:info,state\:info,\*\:error\"/log_level = \"*\:debug\"/g" config.toml)
$(cd "./${home}/config" && sed -i -e 's/"voting_period": "1209600000000000"/"voting_period": "5000000000"/g' genesis.json)
$(cd "./${home}/config" && sed -i -e "s/BEP3Height = 9223372036854775807/BEP3Height = 1/g" app.toml)
$(cd "./${home}/config" && sed -i -e "s/BEP8Height = 9223372036854775807/BEP8Height = 1/g" app.toml)
$(cd "./${home}/config" && sed -i -e "s/BEP67Height = 9223372036854775807/BEP67Height = 1/g" app.toml)
$(cd "./${home}/config" && sed -i -e "s/BEP70Height = 9223372036854775807/BEP70Height = 1/g" app.toml)

# stop and start node
ps -ef | grep bnbchaind | grep testnoded | awk '{print $2}' | xargs kill -9
Expand Down Expand Up @@ -328,6 +332,10 @@ result=$(expect ./issue_mini.exp MBC MiniBitcoin 900000000000 true alice ${chain
mbc_symbol=$(echo "${result}" | tail -n 1 | grep -o "MBC-[0-9A-Z]*M")
check_operation "Issue Mini Token" "${result}" "${chain_operation_words}"

sleep 1s
# mint token
result=$(expect ./seturi.exp ${mbc_symbol} 10000000000 alice ${chain_id} ${cli_home})
check_operation "Mint Token" "${result}" "${chain_operation_words}"

sleep 1s
# send
Expand Down
17 changes: 17 additions & 0 deletions networks/demo/seturi.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/expect

set symbol [lindex $argv 0]
set amount [lindex $argv 1]
set from [lindex $argv 2]
set chain_id [lindex $argv 3]
set home [lindex $argv 4]

set timeout 30
if {"${home}" == ""} {
spawn ./bnbcli token mint -s $symbol -n $amount --from $from --chain-id $chain_id
} else {
spawn ./bnbcli token mint --home $home -s $symbol -n $amount --from $from --chain-id $chain_id
}
expect "Password*"
send "12345678\r"
interact
2 changes: 1 addition & 1 deletion plugins/dex/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,4 @@ func listPairs(keeper *DexKeeper, ctx sdk.Context, abciPrefix string) []types.Tr
}
}
return rs
}
}
7 changes: 4 additions & 3 deletions plugins/dex/client/cli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"errors"

"strings"

"github.com/spf13/cobra"
Expand All @@ -10,7 +11,7 @@ import (
"github.com/binance-chain/node/common/client"
"github.com/binance-chain/node/common/types"
"github.com/binance-chain/node/common/utils"
"github.com/binance-chain/node/plugins/dex/list"
dextypes "github.com/binance-chain/node/plugins/dex/types"
"github.com/binance-chain/node/wire"
)

Expand Down Expand Up @@ -57,7 +58,7 @@ func listTradingPairCmd(cdc *wire.Codec) *cobra.Command {
return errors.New("proposal id should larger than zero")
}

msg := list.NewMsg(from, proposalId, baseAsset, quoteAsset, initPrice)
msg := dextypes.NewListMsg(from, proposalId, baseAsset, quoteAsset, initPrice)
err = client.SendOrPrintTx(cliCtx, txbldr, msg)
if err != nil {
return err
Expand Down Expand Up @@ -107,7 +108,7 @@ func listMiniTradingPairCmd(cdc *wire.Codec) *cobra.Command {
return err
}

msg := list.NewListMiniMsg(from, baseAsset, quoteAsset, initPrice)
msg := dextypes.NewListMiniMsg(from, baseAsset, quoteAsset, initPrice)
err = client.SendOrPrintTx(cliCtx, txbldr, msg)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions plugins/dex/list/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
func NewHandler(keeper *order.DexKeeper, tokenMapper tokens.Mapper, govKeeper gov.Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
switch msg := msg.(type) {
case ListMsg:
case types.ListMsg:
return handleList(ctx, keeper, tokenMapper, govKeeper, msg)
case ListMiniMsg:
case types.ListMiniMsg:
return handleListMini(ctx, keeper, tokenMapper, msg)
default:
errMsg := fmt.Sprintf("Unrecognized dex msg type: %v", reflect.TypeOf(msg).Name())
Expand All @@ -32,7 +32,7 @@ func NewHandler(keeper *order.DexKeeper, tokenMapper tokens.Mapper, govKeeper go
}
}

func checkListProposal(ctx sdk.Context, govKeeper gov.Keeper, msg ListMsg) error {
func checkListProposal(ctx sdk.Context, govKeeper gov.Keeper, msg types.ListMsg) error {
proposal := govKeeper.GetProposal(ctx, msg.ProposalId)
if proposal == nil {
return fmt.Errorf("proposal %d does not exist", msg.ProposalId)
Expand Down Expand Up @@ -77,7 +77,7 @@ func checkListProposal(ctx sdk.Context, govKeeper gov.Keeper, msg ListMsg) error
}

func handleList(ctx sdk.Context, keeper *order.DexKeeper, tokenMapper tokens.Mapper, govKeeper gov.Keeper,
msg ListMsg) sdk.Result {
msg types.ListMsg) sdk.Result {
if err := checkListProposal(ctx, govKeeper, msg); err != nil {
return types.ErrInvalidProposal(err.Error()).Result()
}
Expand Down
15 changes: 14 additions & 1 deletion plugins/dex/list/handler_mini.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@ package list

import (
"github.com/binance-chain/node/common/log"
ctypes "github.com/binance-chain/node/common/types"
"github.com/binance-chain/node/common/upgrade"
"github.com/binance-chain/node/plugins/dex/order"
"github.com/binance-chain/node/plugins/dex/types"
"github.com/binance-chain/node/plugins/tokens"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func handleListMini(ctx sdk.Context, dexKeeper *order.DexKeeper, tokenMapper tokens.Mapper,
msg ListMiniMsg) sdk.Result {
msg types.ListMiniMsg) sdk.Result {

// before BEP70 upgraded, we only support listing mini token against NativeToken
if sdk.IsUpgrade(upgrade.BEP70) {
if ctypes.NativeTokenSymbol != msg.QuoteAssetSymbol && order.BUSDSymbol != msg.QuoteAssetSymbol {
return sdk.ErrInvalidCoins("quote token is not valid ").Result()
}
} else {
if ctypes.NativeTokenSymbol != msg.QuoteAssetSymbol {
return sdk.ErrInvalidCoins("quote token is not valid ").Result()
}
}

if err := dexKeeper.CanListTradingPair(ctx, msg.BaseAssetSymbol, msg.QuoteAssetSymbol); err != nil {
return sdk.ErrInvalidCoins(err.Error()).Result()
Expand Down
58 changes: 53 additions & 5 deletions plugins/dex/list/handler_mini_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import (
"github.com/tendermint/tendermint/libs/log"

"github.com/binance-chain/node/common/types"
common "github.com/binance-chain/node/common/types"
"github.com/binance-chain/node/common/upgrade"
"github.com/binance-chain/node/plugins/dex/order"
dextypes "github.com/binance-chain/node/plugins/dex/types"
"github.com/binance-chain/node/plugins/tokens"
)

Expand Down Expand Up @@ -59,13 +62,58 @@ func TestHandleListMiniIdenticalSymbols(t *testing.T) {
ms, orderKeeper, tokenMapper, _ := MakeKeepers(cdc)
ctx := sdk.NewContext(ms, abci.Header{}, sdk.RunTxModeDeliver, log.NewNopLogger())
setupForMini(ctx, tokenMapper, t)
result := handleListMini(ctx, orderKeeper, tokenMapper, ListMiniMsg{
result := handleListMini(ctx, orderKeeper, tokenMapper, dextypes.ListMiniMsg{
From: sdk.AccAddress("testacc"),
BaseAssetSymbol: "BTC-000M",
QuoteAssetSymbol: "BTC-000M",
InitPrice: 1000,
})
require.Contains(t, result.Log, "base asset symbol should not be identical to quote asset symbol")
require.Contains(t, result.Log, "quote token is not valid")
}

func TestMiniWrongQuoteAssetSymbol(t *testing.T) {
setChainVersion()
defer resetChainVersion()
cdc := MakeCodec()
ms, orderKeeper, tokenMapper, _ := MakeKeepers(cdc)
ctx := sdk.NewContext(ms, abci.Header{}, sdk.RunTxModeDeliver, log.NewNopLogger())
setupForMini(ctx, tokenMapper, t)
result := handleListMini(ctx, orderKeeper, tokenMapper, dextypes.ListMiniMsg{
From: sdk.AccAddress("testacc"),
BaseAssetSymbol: "BTC-000M",
QuoteAssetSymbol: "ETH-000M",
InitPrice: 1000,
})
require.Contains(t, result.Log, "quote token is not valid")
}

func TestMiniBUSDQuote(t *testing.T) {
setChainVersion()
defer resetChainVersion()
cdc := MakeCodec()
ms, orderKeeper, tokenMapper, _ := MakeKeepers(cdc)
ctx := sdk.NewContext(ms, abci.Header{}, sdk.RunTxModeDeliver, log.NewNopLogger())
setupForMini(ctx, tokenMapper, t)
result := handleListMini(ctx, orderKeeper, tokenMapper, dextypes.ListMiniMsg{
From: sdk.AccAddress("testacc"),
BaseAssetSymbol: "BTC-000M",
QuoteAssetSymbol: "BUSD-000",
InitPrice: 1000,
})
require.Contains(t, result.Log, "quote token is not valid")

order.BUSDSymbol = "BUSD-000"
busd, _ := common.NewToken("BUSD", "BUSD-000", 10000000000, nil, false)
tokenMapper.NewToken(ctx, busd)
pair := dextypes.NewTradingPair(types.NativeTokenSymbol, "BUSD-000", 1000)
orderKeeper.PairMapper.AddTradingPair(ctx, pair)
result = handleListMini(ctx, orderKeeper, tokenMapper, dextypes.ListMiniMsg{
From: sdk.AccAddress("testacc"),
BaseAssetSymbol: "BTC-000M",
QuoteAssetSymbol: "BUSD-000",
InitPrice: 1000,
})
require.Equal(t, true, result.IsOK())
}

func TestHandleListMiniWrongBaseSymbol(t *testing.T) {
Expand All @@ -75,7 +123,7 @@ func TestHandleListMiniWrongBaseSymbol(t *testing.T) {
ms, orderKeeper, tokenMapper, _ := MakeKeepers(cdc)
ctx := sdk.NewContext(ms, abci.Header{}, sdk.RunTxModeDeliver, log.NewNopLogger())
setupForMini(ctx, tokenMapper, t)
result := handleListMini(ctx, orderKeeper, tokenMapper, ListMiniMsg{
result := handleListMini(ctx, orderKeeper, tokenMapper, dextypes.ListMiniMsg{
From: sdk.AccAddress("testacc"),
BaseAssetSymbol: "BTC",
QuoteAssetSymbol: "BNB",
Expand All @@ -92,7 +140,7 @@ func TestHandleListMiniRight(t *testing.T) {
ms, orderKeeper, tokenMapper, _ := MakeKeepers(cdc)
ctx := sdk.NewContext(ms, abci.Header{}, sdk.RunTxModeDeliver, log.NewNopLogger())
setupForMini(ctx, tokenMapper, t)
result := handleListMini(ctx, orderKeeper, tokenMapper, ListMiniMsg{
result := handleListMini(ctx, orderKeeper, tokenMapper, dextypes.ListMiniMsg{
From: sdk.AccAddress("testacc"),
BaseAssetSymbol: "BTC-000M",
QuoteAssetSymbol: "BNB",
Expand All @@ -108,7 +156,7 @@ func TestHandleListTinyRight(t *testing.T) {
ms, orderKeeper, tokenMapper, _ := MakeKeepers(cdc)
ctx := sdk.NewContext(ms, abci.Header{}, sdk.RunTxModeDeliver, log.NewNopLogger())
setupForMini(ctx, tokenMapper, t)
result := handleListMini(ctx, orderKeeper, tokenMapper, ListMiniMsg{
result := handleListMini(ctx, orderKeeper, tokenMapper, dextypes.ListMiniMsg{
From: sdk.AccAddress("testacc"),
BaseAssetSymbol: "ETH-000M",
QuoteAssetSymbol: "BNB",
Expand Down
Loading

0 comments on commit e72fa70

Please sign in to comment.