Skip to content

Commit 12e11a0

Browse files
committed
fix(wallet)_: update tokens' postfix from decimals to l1 chain based mark
Changes include: - 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.
1 parent cfe596e commit 12e11a0

File tree

11 files changed

+67
-38
lines changed

11 files changed

+67
-38
lines changed

contracts/balancechecker/address.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var contractDataByChainID = map[uint64]common.Address{
2222
wallet_common.BaseSepolia: common.HexToAddress("0x84A1C94fcc5EcFA292771f6aE7Fbf24ec062D34e"),
2323
wallet_common.StatusNetworkSepolia: common.HexToAddress("0x84A1C94fcc5EcFA292771f6aE7Fbf24ec062D34e"),
2424
wallet_common.BSCTestnet: common.HexToAddress("0xaf9ac152537801c562c0ea14ad186f4f4946b53d"),
25-
777333: common.HexToAddress("0x0000000000000000000000000000000010777333"),
25+
wallet_common.TestnetChainID: common.HexToAddress("0x0000000000000000000000000000000010777333"),
2626
}
2727

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

contracts/ethscan/address.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var contractDataByChainID = map[uint64]ContractData{
2727
wallet_common.BaseSepolia: {common.HexToAddress("0xc68c1e011cfE059EB94C8915c291502288704D89"), 20_078_235},
2828
wallet_common.StatusNetworkSepolia: {common.HexToAddress("0xc68c1e011cfE059EB94C8915c291502288704D89"), 1_753_813},
2929
wallet_common.BSCTestnet: {common.HexToAddress("0x71cfeb2ab5a3505f80b4c86f8ccd0a4b29f62447"), 49_365_870},
30-
777333: {common.HexToAddress("0x0000000000000000000000000000000000777333"), 50}, // unit tests
30+
wallet_common.TestnetChainID: {common.HexToAddress("0x0000000000000000000000000000000000777333"), 50}, // unit tests
3131
}
3232

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

services/wallet/common/const.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const (
4242
BaseMainnet uint64 = 8453
4343
BaseSepolia uint64 = 84532
4444
StatusNetworkSepolia uint64 = 1660990954
45+
TestnetChainID uint64 = 777333
4546
)
4647

4748
var (
@@ -117,6 +118,7 @@ func AllChainIDs() []ChainID {
117118
ChainID(StatusNetworkSepolia),
118119
ChainID(BSCMainnet),
119120
ChainID(BSCTestnet),
121+
ChainID(TestnetChainID),
120122
}
121123
}
122124

services/wallet/market/market_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,18 @@ func TestSymbolsMapping(t *testing.T) {
305305
require.Equal(t, expectedProviderSymbolsToSymbols, providerSymbolsToSymbols)
306306

307307
// symbols with decimals
308-
symbols = []string{"SNT", "DAI", "USDC(6)", "USDC(18)", "ANYTHING"}
308+
symbols = []string{"SNT", "DAI", "USDC (EVM)", "USDC (BSC)", "ANYTHING"}
309309
expectedSymbolsToProviderSymbols = map[string]string{
310-
"SNT": "SNT",
311-
"DAI": "DAI",
312-
"USDC(6)": "USDC",
313-
"USDC(18)": "USDC",
314-
"ANYTHING": "ANYTHING",
310+
"SNT": "SNT",
311+
"DAI": "DAI",
312+
"USDC (EVM)": "USDC",
313+
"USDC (BSC)": "USDC",
314+
"ANYTHING": "ANYTHING",
315315
}
316316
expectedProviderSymbolsToSymbols = map[string][]string{
317317
"SNT": {"SNT"},
318318
"DAI": {"DAI"},
319-
"USDC": {"USDC(6)", "USDC(18)"},
319+
"USDC": {"USDC (EVM)", "USDC (BSC)"},
320320
"ANYTHING": {"ANYTHING"},
321321
}
322322
symbolsToProviderSymbols, providerSymbolsToSymbols, err = marketManager.symbolProviderSymbolMaps(symbols)

services/wallet/router/router.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ func (r *Router) resolveRoutes(ctx context.Context, input *requests.RouteInputPa
928928
suggestedRoutes, allRoutes = newSuggestedRoutes(input, candidates, prices)
929929

930930
defer func() {
931-
if suggestedRoutes.Best != nil && len(suggestedRoutes.Best) > 0 {
931+
if len(suggestedRoutes.Best) > 0 {
932932
sort.Slice(suggestedRoutes.Best, func(i, j int) bool {
933933
iChain := getChainPriority(suggestedRoutes.Best[i].FromChain.ChainID)
934934
jChain := getChainPriority(suggestedRoutes.Best[j].FromChain.ChainID)

services/wallet/router/router_test_data.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2940,8 +2940,8 @@ func getNoBalanceTestParamsList() []noBalanceTestParams {
29402940
AddrTo: common.HexToAddress("0x2"),
29412941
AmountIn: (*hexutil.Big)(big.NewInt(testAmount100USDC)),
29422942
TokenID: walletCommon.UsdcSymbol,
2943-
DisabledFromChainIDs: []uint64{walletCommon.EthereumMainnet, walletCommon.ArbitrumMainnet, walletCommon.BaseMainnet},
2944-
DisabledToChainIDs: []uint64{walletCommon.EthereumMainnet, walletCommon.ArbitrumMainnet, walletCommon.BaseMainnet},
2943+
DisabledFromChainIDs: []uint64{walletCommon.EthereumMainnet, walletCommon.ArbitrumMainnet, walletCommon.BaseMainnet, walletCommon.BSCMainnet},
2944+
DisabledToChainIDs: []uint64{walletCommon.EthereumMainnet, walletCommon.ArbitrumMainnet, walletCommon.BaseMainnet, walletCommon.BSCMainnet},
29452945

29462946
TestsMode: true,
29472947
TestParams: &requests.RouterTestParams{
@@ -3026,8 +3026,8 @@ func getNoBalanceTestParamsList() []noBalanceTestParams {
30263026
AddrTo: common.HexToAddress("0x2"),
30273027
AmountIn: (*hexutil.Big)(big.NewInt(testAmount100USDC)),
30283028
TokenID: walletCommon.UsdcSymbol,
3029-
DisabledFromChainIDs: []uint64{walletCommon.BaseMainnet},
3030-
DisabledToChainIDs: []uint64{walletCommon.EthereumMainnet, walletCommon.ArbitrumMainnet, walletCommon.BaseMainnet},
3029+
DisabledFromChainIDs: []uint64{walletCommon.BaseMainnet, walletCommon.BSCMainnet},
3030+
DisabledToChainIDs: []uint64{walletCommon.EthereumMainnet, walletCommon.ArbitrumMainnet, walletCommon.BaseMainnet, walletCommon.BSCMainnet},
30313031

30323032
TestsMode: true,
30333033
TestParams: &requests.RouterTestParams{
@@ -3089,7 +3089,7 @@ func getNoBalanceTestParamsList() []noBalanceTestParams {
30893089
AddrTo: common.HexToAddress("0x2"),
30903090
AmountIn: (*hexutil.Big)(big.NewInt(testAmount100USDC)),
30913091
TokenID: walletCommon.UsdcSymbol,
3092-
DisabledToChainIDs: []uint64{walletCommon.EthereumMainnet, walletCommon.ArbitrumMainnet, walletCommon.BaseMainnet},
3092+
DisabledToChainIDs: []uint64{walletCommon.EthereumMainnet, walletCommon.ArbitrumMainnet, walletCommon.BaseMainnet, walletCommon.BSCMainnet},
30933093

30943094
TestsMode: true,
30953095
TestParams: &requests.RouterTestParams{

services/wallet/token/token-lists/builder.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/status-im/status-go/logutils"
1111
"github.com/status-im/status-go/multiaccounts/settings"
12+
"github.com/status-im/status-go/services/wallet/common"
1213
defaulttokenlists "github.com/status-im/status-go/services/wallet/token/token-lists/default-lists"
1314
"github.com/status-im/status-go/services/wallet/token/token-lists/fetcher"
1415
tokenTypes "github.com/status-im/status-go/services/wallet/token/types"
@@ -28,6 +29,8 @@ func (t *TokenLists) rebuildTokensMap(fetchedLists []fetcher.FetchedTokenList) e
2829
list.Source = fetchedTokenList.SourceURL
2930
list.FetchedTimestamp = fetchedTokenList.Fetched.Format(time.RFC3339)
3031

32+
list.Tokens = filterTokens(list.Tokens)
33+
3134
processTokenPegs(list.Tokens)
3235

3336
t.tokensListsMu.Lock()
@@ -100,6 +103,24 @@ func (t *TokenLists) rebuildTokensListsMap() error {
100103
return t.rebuildTokensMap(tokensListsForProcessing)
101104
}
102105

106+
func filterTokens(tokens []*tokenTypes.Token) []*tokenTypes.Token {
107+
var filteredTokens []*tokenTypes.Token
108+
for _, token := range tokens {
109+
found := false
110+
for _, chainID := range common.AllChainIDs() {
111+
if token.ChainID == uint64(chainID) {
112+
found = true
113+
break
114+
}
115+
}
116+
if !found {
117+
continue
118+
}
119+
filteredTokens = append(filteredTokens, token)
120+
}
121+
return filteredTokens
122+
}
123+
103124
func processTokenPegs(tokens []*tokenTypes.Token) {
104125
for _, token := range tokens {
105126
token.PegSymbol = tokenTypes.GetTokenPegSymbol(token.Symbol)

services/wallet/token/token-lists/token_collision_solving.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"golang.org/x/exp/maps"
99

10+
walletCommon "github.com/status-im/status-go/services/wallet/common"
1011
defaulttokenlists "github.com/status-im/status-go/services/wallet/token/token-lists/default-lists"
1112
tokenTypes "github.com/status-im/status-go/services/wallet/token/types"
1213
)
@@ -57,7 +58,12 @@ func getSymbolChainPair(token *tokenTypes.Token) string {
5758
}
5859

5960
func makeUniqueSymbol(token *tokenTypes.Token) string {
60-
return fmt.Sprintf("%s(%d)", token.Symbol, token.Decimals)
61+
// Based on proposal here https://discord.com/channels/1210237582470807632/1363907888082321448/1364611566753812601
62+
l1Chain := "EVM"
63+
if token.ChainID == walletCommon.BSCMainnet || token.ChainID == walletCommon.BSCTestnet {
64+
l1Chain = "BSC"
65+
}
66+
return fmt.Sprintf("%s (%s)", token.Symbol, l1Chain)
6167
}
6268

6369
func removeDuplicateSymbolOnTheSameChain(tokens []*tokenTypes.Token) []*tokenTypes.Token {

services/wallet/token/token-lists/token_collision_solving_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func TestTokenExistence(t *testing.T) {
106106
func TestSolvingDecimalsCollision(t *testing.T) {
107107
tokens := []*tokenTypes.Token{
108108
{
109-
ChainID: walletCommon.EthereumMainnet,
109+
ChainID: walletCommon.BSCMainnet,
110110
Address: common.HexToAddress("0x1"),
111111
Symbol: "ETH1",
112112
Decimals: 18,

services/wallet/token/types/token_peg.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@ package tokentypes
22

33
func getTokenPegMap() map[string]string {
44
return map[string]string{
5-
"aUSDC": "USD",
6-
"DAI": "USD",
7-
"EURC": "EUR",
8-
"SAI": "USD",
9-
"sUSD": "USD",
10-
"PAXG": "XAU",
11-
"TCAD": "CAD",
12-
"TUSD": "USD",
13-
"TGBP": "GBP",
14-
"TAUD": "AUD",
15-
"USDC": "USD",
16-
"USDD": "USD",
17-
"USDS": "USD",
18-
"USDT": "USD",
19-
"USDT(6)": "USD",
20-
"USDT(18)": "USD",
21-
"USDP": "USD",
22-
"USDSC": "USD",
23-
"USDSC(6)": "USD",
24-
"USDSC(18)": "USD",
5+
"aUSDC": "USD",
6+
"DAI": "USD",
7+
"EURC": "EUR",
8+
"SAI": "USD",
9+
"sUSD": "USD",
10+
"PAXG": "XAU",
11+
"TCAD": "CAD",
12+
"TUSD": "USD",
13+
"TGBP": "GBP",
14+
"TAUD": "AUD",
15+
"USDC": "USD",
16+
"USDD": "USD",
17+
"USDS": "USD",
18+
"USDT": "USD",
19+
"USDT (EVM)": "USD",
20+
"USDT (BSC)": "USD",
21+
"USDP": "USD",
22+
"USDSC": "USD",
23+
"USDSC (EVM)": "USD",
24+
"USDSC (BSC)": "USD",
2525
}
2626
}
2727

services/wallet/transfer/commands_sequential_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func (tc *TestClient) GetBaseFeeFromBlock(ctx context.Context, blockNumber *big.
323323
}
324324

325325
func (tc *TestClient) NetworkID() uint64 {
326-
return 777333
326+
return walletcommon.TestnetChainID
327327
}
328328

329329
func (tc *TestClient) ToBigInt() *big.Int {

0 commit comments

Comments
 (0)