Skip to content

Commit 5163085

Browse files
smohamedjavidsaledjenicdlipicar
authored
feat(wallet)_: Add BNB Smart Chain (#6466)
Changes include: - Adds BNB Smart Chain support - Replaced postfix for decimals collision, symbols include l1 chain based mark instead of decimals. - Token filtering logic added to ensure that only chains the app knows about are present (otherwise, it cannot guarantee uniqueness without decimals included). - Replaced hardcoded chain ID with a constant for `TestnetChainID` and added to `AllChainIDs`, which fixed tests balancechecker. - Updated no-balance tests for the router that were failing due to the new BSC chain added. --------- Signed-off-by: Mohamed Javid <[email protected]> Co-authored-by: Sale Djenic <[email protected]> Co-authored-by: Dario Gabriel Lipicar <[email protected]>
1 parent 0ded9fb commit 5163085

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1615
-402
lines changed

api/common/const.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ const (
1010
BaseChainID uint64 = 8453
1111
BaseSepoliaChainID uint64 = 84532
1212
StatusNetworkSepoliaChainID uint64 = 1660990954
13+
BNBSmartChainID uint64 = 56
14+
BNBSmartChainTestnetChainID uint64 = 97
1315
)

api/default_networks.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,71 @@ func statusNetworkSepolia(proxyHost string) params.Network {
380380
}
381381
}
382382

383+
func bnbSmartChain(proxyHost string) params.Network {
384+
const chainID = common.BNBSmartChainID
385+
const chainName = "bsc"
386+
const networkName = "mainnet"
387+
388+
rpcProviders := []params.RpcProvider{
389+
// Smart proxy provider
390+
*params.NewEthRpcProxyProvider(chainID, StatusSmartProxy, smartProxyUrl(proxyHost, chainName, networkName), false),
391+
// Direct providers
392+
*params.NewDirectProvider(chainID, DirectInfura, "https://bsc-mainnet.infura.io/v3/", true),
393+
*params.NewDirectProvider(chainID, DirectGrove, "https://bsc.rpc.grove.city/v1/", false),
394+
}
395+
396+
return params.Network{
397+
ChainID: chainID,
398+
ChainName: "Binance",
399+
RpcProviders: rpcProviders,
400+
BlockExplorerURL: "https://bscscan.com/",
401+
IconURL: "network/Network=bsc",
402+
ChainColor: "#f7bb0f",
403+
ShortName: "bsc",
404+
NativeCurrencyName: "BNB",
405+
NativeCurrencySymbol: "BNB",
406+
NativeCurrencyDecimals: 18,
407+
IsTest: false,
408+
Layer: 1,
409+
Enabled: true,
410+
RelatedChainID: common.BNBSmartChainTestnetChainID,
411+
IsActive: true,
412+
IsDeactivatable: true,
413+
}
414+
}
415+
416+
func bnbSmartChainTestnet(proxyHost string) params.Network {
417+
const chainID = common.BNBSmartChainTestnetChainID
418+
const chainName = "bsc"
419+
const networkName = "testnet"
420+
421+
rpcProviders := []params.RpcProvider{
422+
// Smart proxy provider
423+
*params.NewEthRpcProxyProvider(chainID, StatusSmartProxy, smartProxyUrl(proxyHost, chainName, networkName), false),
424+
// Direct providers
425+
*params.NewDirectProvider(chainID, DirectInfura, "https://bsc-testnet.infura.io/v3/", true),
426+
}
427+
428+
return params.Network{
429+
ChainID: chainID,
430+
ChainName: "Binance Testnet",
431+
RpcProviders: rpcProviders,
432+
BlockExplorerURL: "https://testnet.bscscan.com/",
433+
IconURL: "network/Network=bsc-test",
434+
ChainColor: "#f7bb0f",
435+
ShortName: "bsc",
436+
NativeCurrencyName: "BNB",
437+
NativeCurrencySymbol: "BNB",
438+
NativeCurrencyDecimals: 18,
439+
IsTest: true,
440+
Layer: 1,
441+
Enabled: true,
442+
RelatedChainID: common.BNBSmartChainID,
443+
IsActive: false,
444+
IsDeactivatable: true,
445+
}
446+
}
447+
383448
func defaultNetworks(proxyHost, stageName string) []params.Network {
384449
return []params.Network{
385450
mainnet(proxyHost, stageName),
@@ -391,6 +456,8 @@ func defaultNetworks(proxyHost, stageName string) []params.Network {
391456
base(proxyHost, stageName),
392457
baseSepolia(proxyHost, stageName),
393458
statusNetworkSepolia(proxyHost),
459+
bnbSmartChain(proxyHost),
460+
bnbSmartChainTestnet(proxyHost),
394461
}
395462
}
396463

api/default_networks_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestBuildDefaultNetworks(t *testing.T) {
2727

2828
actualNetworks := BuildDefaultNetworks(&request.WalletSecretsConfig)
2929

30-
require.Len(t, actualNetworks, 9)
30+
require.Len(t, actualNetworks, 11)
3131
for _, n := range actualNetworks {
3232
var err error
3333
switch n.ChainID {
@@ -40,6 +40,8 @@ func TestBuildDefaultNetworks(t *testing.T) {
4040
case common.BaseChainID:
4141
case common.BaseSepoliaChainID:
4242
case common.StatusNetworkSepoliaChainID:
43+
case common.BNBSmartChainID:
44+
case common.BNBSmartChainTestnetChainID:
4345
default:
4446
err = errors.Errorf("unexpected chain id: %d", n.ChainID)
4547
}

contracts/balancechecker/address.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ var contractDataByChainID = map[uint64]common.Address{
1515
wallet_common.OptimismMainnet: common.HexToAddress("0x55bD303eA3D50FC982A8a5b43972d7f38D129bbF"),
1616
wallet_common.ArbitrumMainnet: common.HexToAddress("0x54764eF12d29b249fDC7FC3caDc039955A396A8e"),
1717
wallet_common.BaseMainnet: common.HexToAddress("0x84A1C94fcc5EcFA292771f6aE7Fbf24ec062D34e"),
18+
wallet_common.BSCMainnet: common.HexToAddress("0xaf9ac152537801c562c0ea14ad186f4f4946b53d"),
1819
wallet_common.EthereumSepolia: common.HexToAddress("0x55bD303eA3D50FC982A8a5b43972d7f38D129bbF"),
1920
wallet_common.ArbitrumSepolia: common.HexToAddress("0x54764eF12d29b249fDC7FC3caDc039955A396A8e"),
2021
wallet_common.OptimismSepolia: common.HexToAddress("0x55bD303eA3D50FC982A8a5b43972d7f38D129bbF"),
2122
wallet_common.BaseSepolia: common.HexToAddress("0x84A1C94fcc5EcFA292771f6aE7Fbf24ec062D34e"),
2223
wallet_common.StatusNetworkSepolia: common.HexToAddress("0x84A1C94fcc5EcFA292771f6aE7Fbf24ec062D34e"),
23-
777333: common.HexToAddress("0x0000000000000000000000000000000010777333"),
24+
wallet_common.BSCTestnet: common.HexToAddress("0xaf9ac152537801c562c0ea14ad186f4f4946b53d"),
25+
wallet_common.TestnetChainID: common.HexToAddress("0x0000000000000000000000000000000010777333"),
2426
}
2527

2628
func ContractAddress(chainID uint64) (common.Address, error) {

contracts/community-tokens/deployer/address.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ var contractAddressByChainID = map[uint64]common.Address{
2020
walletCommon.OptimismSepolia: common.HexToAddress("0xcE2A896eEA2F585BC0C3753DC8116BbE2AbaE541"),
2121
walletCommon.BaseSepolia: common.HexToAddress("0x7Ff554af5b6624db2135E4364F416d1D397f43e6"),
2222
walletCommon.StatusNetworkSepolia: common.HexToAddress("0x06716eCfA9B5Ae0210F4c3279cA304A7F563c59e"),
23+
walletCommon.BSCMainnet: common.HexToAddress("0x76d0e484e7c3398922636960ab33bde6e9936d81"),
24+
walletCommon.BSCTestnet: common.HexToAddress("0x7Ff554af5b6624db2135E4364F416d1D397f43e6"),
2325
}
2426

2527
func ContractAddress(chainID uint64) (common.Address, error) {

contracts/ethscan/address.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ var contractDataByChainID = map[uint64]ContractData{
2020
wallet_common.OptimismMainnet: {common.HexToAddress("0x9e5076df494fc949abc4461f4e57592b81517d81"), 34_421_097},
2121
wallet_common.ArbitrumMainnet: {common.HexToAddress("0xbb85398092b83a016935a17fc857507b7851a071"), 70_031_945},
2222
wallet_common.BaseMainnet: {common.HexToAddress("0xc68c1e011cfE059EB94C8915c291502288704D89"), 24_567_587},
23+
wallet_common.BSCMainnet: {common.HexToAddress("0x71cfeb2ab5a3505f80b4c86f8ccd0a4b29f62447"), 47_746_468},
2324
wallet_common.EthereumSepolia: {common.HexToAddress("0xec21ebe1918e8975fc0cd0c7747d318c00c0acd5"), 4_366_506},
2425
wallet_common.ArbitrumSepolia: {common.HexToAddress("0xec21Ebe1918E8975FC0CD0c7747D318C00C0aCd5"), 553_947},
2526
wallet_common.OptimismSepolia: {common.HexToAddress("0xec21ebe1918e8975fc0cd0c7747d318c00c0acd5"), 7_362_011},
2627
wallet_common.BaseSepolia: {common.HexToAddress("0xc68c1e011cfE059EB94C8915c291502288704D89"), 20_078_235},
2728
wallet_common.StatusNetworkSepolia: {common.HexToAddress("0xc68c1e011cfE059EB94C8915c291502288704D89"), 1_753_813},
28-
777333: {common.HexToAddress("0x0000000000000000000000000000000000777333"), 50}, // unit tests
29+
wallet_common.BSCTestnet: {common.HexToAddress("0x71cfeb2ab5a3505f80b4c86f8ccd0a4b29f62447"), 49_365_870},
30+
wallet_common.TestnetChainID: {common.HexToAddress("0x0000000000000000000000000000000000777333"), 50}, // unit tests
2931
}
3032

3133
func ContractAddress(chainID uint64) (common.Address, error) {

contracts/hop/address.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const (
3232
)
3333

3434
var hopBridgeContractAddresses = map[string]map[uint64]map[string]common.Address{
35-
"USDC": {
35+
"USDC (EVM)": {
3636
walletCommon.EthereumMainnet: {
3737
L1CanonicalToken: common.HexToAddress("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"),
3838
CctpL1Bridge: common.HexToAddress("0x7e77461CA2a9d82d26FD5e0Da2243BF72eA45747"),
@@ -124,7 +124,7 @@ var hopBridgeContractAddresses = map[string]map[uint64]map[string]common.Address
124124
L2CanonicalToken: common.HexToAddress("0xB15312eA17d95375E64317C363A0e6304330D82e"),
125125
},
126126
},
127-
"USDT": {
127+
"USDT (EVM)": {
128128
walletCommon.EthereumMainnet: {
129129
L1CanonicalToken: common.HexToAddress("0xdAC17F958D2ee523a2206206994597C13D831ec7"),
130130
L1Bridge: common.HexToAddress("0x3E4a3a4796d16c0Cd582C382691998f7c06420B6"),
@@ -351,7 +351,7 @@ func isHTokenSend() bool {
351351
}
352352

353353
func shouldUseCctpBridge(symbol string) bool {
354-
if symbol == "USDC" {
354+
if symbol == "USDC (EVM)" {
355355
return true
356356
}
357357
return symbol == "USDC.e" && isHTokenSend()

services/wallet/activity/activity_v2.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ func getFinalizationPeriod(chainID wCommon.ChainID) int64 {
270270
switch uint64(chainID) {
271271
case wCommon.EthereumMainnet, wCommon.EthereumSepolia:
272272
return ac.L1FinalizationDuration
273+
case wCommon.BSCMainnet, wCommon.BSCTestnet:
274+
return ac.BSCFinalizationDuration
273275
}
274276

275277
return ac.L2FinalizationDuration

services/wallet/activity/common/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ const (
2929
)
3030

3131
const (
32-
L1FinalizationDuration = 960 // A block on layer 1 is every 12s, finalization require 64 blocks. A buffer of 16 blocks is added to not create false positives.
33-
L2FinalizationDuration = 648000 // 7.5 days in seconds for layer 2 finalization. 0.5 day is buffer to not create false positive.
32+
L1FinalizationDuration = 960 // A block on layer 1 is every 12s, finalization require 64 blocks. A buffer of 16 blocks is added to not create false positives.
33+
BSCFinalizationDuration = 9 // BSC uses Fast Finality, finalization time is 7.5 seconds approx. A buffer of 1.5 seconds is added to not create false positives.
34+
L2FinalizationDuration = 648000 // 7.5 days in seconds for layer 2 finalization. 0.5 day is buffer to not create false positive.
3435
)
3536

3637
const (

services/wallet/api.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,12 @@ func (api *API) SendRouterTransactionsWithSignatures(ctx context.Context, sendIn
707707
api.s.routeExecutionManager.SendRouterTransactionsWithSignatures(ctx, sendInputParams)
708708
}
709709

710+
// ReevaluateRouterPath reevaluates the tx-fields from the router path that matches the provided pathTxIdentity and sends signal.SuggestedRoutes.
711+
func (api *API) ReevaluateRouterPath(ctx context.Context, pathTxIdentity *requests.PathTxIdentity) error {
712+
logutils.ZapLogger().Debug("wallet.api.ReevaluateRouterPath")
713+
return api.s.routeExecutionManager.ReevaluateRouterPath(ctx, pathTxIdentity)
714+
}
715+
710716
func (api *API) GetMultiTransactions(ctx context.Context, transactionIDs []wcommon.MultiTransactionIDType) ([]*transfer.MultiTransaction, error) {
711717
logutils.ZapLogger().Debug("wallet.api.GetMultiTransactions", zap.Int("IDs.len", len(transactionIDs)))
712718
return api.s.transactionManager.GetMultiTransactions(ctx, transactionIDs)

services/wallet/common/const.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ const (
1717
StatusDomain = "stateofus.eth"
1818
EthDomain = "eth"
1919

20-
EthSymbol = "ETH"
21-
SntSymbol = "SNT"
22-
SttSymbol = "STT"
23-
UsdcSymbol = "USDC"
24-
HopSymbol = "HOP"
25-
DaiSymbol = "DAI"
20+
EthSymbol = "ETH"
21+
SntSymbol = "SNT"
22+
SttSymbol = "STT"
23+
UsdcSymbol = "USDC"
24+
UsdcSymbolEVM = "USDC (EVM)"
25+
HopSymbol = "HOP"
26+
DaiSymbol = "DAI"
27+
BNBSymbol = "BNB"
2628
)
2729

2830
type ChainID uint64
@@ -35,12 +37,13 @@ const (
3537
OptimismSepolia uint64 = 11155420
3638
ArbitrumMainnet uint64 = 42161
3739
ArbitrumSepolia uint64 = 421614
38-
BinanceChainID uint64 = 56 // obsolete?
39-
BinanceTestChainID uint64 = 97 // obsolete?
40+
BSCMainnet uint64 = 56
41+
BSCTestnet uint64 = 97
4042
AnvilMainnet uint64 = 31337
4143
BaseMainnet uint64 = 8453
4244
BaseSepolia uint64 = 84532
4345
StatusNetworkSepolia uint64 = 1660990954
46+
TestnetChainID uint64 = 777333
4447
)
4548

4649
var (
@@ -49,13 +52,15 @@ var (
4952
OptimismMainnet: true,
5053
ArbitrumMainnet: true,
5154
BaseMainnet: true,
55+
BSCMainnet: true,
5256
}
5357

5458
SupportedTestNetworks = map[uint64]bool{
5559
EthereumSepolia: true,
5660
OptimismSepolia: true,
5761
ArbitrumSepolia: true,
5862
BaseSepolia: true,
63+
BSCTestnet: true,
5964
StatusNetworkSepolia: true,
6065
}
6166
)
@@ -91,9 +96,9 @@ func (c ChainID) ToUint() uint64 {
9196

9297
func (c ChainID) IsMainnet() bool {
9398
switch uint64(c) {
94-
case EthereumMainnet, OptimismMainnet, ArbitrumMainnet, BaseMainnet:
99+
case EthereumMainnet, OptimismMainnet, ArbitrumMainnet, BaseMainnet, BSCMainnet:
95100
return true
96-
case EthereumSepolia, OptimismSepolia, ArbitrumSepolia, BaseSepolia, StatusNetworkSepolia:
101+
case EthereumSepolia, OptimismSepolia, ArbitrumSepolia, BaseSepolia, BSCTestnet, StatusNetworkSepolia:
97102
return false
98103
case UnknownChainID:
99104
return false
@@ -112,6 +117,10 @@ func AllChainIDs() []ChainID {
112117
ChainID(BaseMainnet),
113118
ChainID(BaseSepolia),
114119
ChainID(StatusNetworkSepolia),
120+
ChainID(BSCMainnet),
121+
ChainID(BSCTestnet),
122+
ChainID(TestnetChainID),
123+
ChainID(AnvilMainnet),
115124
}
116125
}
117126

@@ -121,4 +130,5 @@ var AverageBlockDurationForChain = map[ChainID]time.Duration{
121130
ChainID(OptimismMainnet): time.Duration(2000) * time.Millisecond,
122131
ChainID(ArbitrumMainnet): time.Duration(250) * time.Millisecond,
123132
ChainID(BaseMainnet): time.Duration(2000) * time.Millisecond,
133+
ChainID(BSCMainnet): time.Duration(3000) * time.Millisecond,
124134
}

0 commit comments

Comments
 (0)