Skip to content

Commit e454b4b

Browse files
authored
Zilliqa chain type: support for ZRC-2 (#3202)
* Zilliqa chain type: support for ZRC-2 * add zrc-2 address * add socket support and token select info * add token types to watchlist notification settings * add token tag * add is fungible helper * aboba * review fixes
1 parent 43a77c2 commit e454b4b

Some content is hidden

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

47 files changed

+450
-182
lines changed

configs/app/chain.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { RollupType } from 'types/client/rollup';
2+
import type { AdditionalTokenType } from 'types/client/token';
23
import type { NetworkVerificationType, NetworkVerificationTypeEnvs } from 'types/networks';
34

45
import { urlValidator } from 'toolkit/components/forms/validators/url';
@@ -48,6 +49,7 @@ const chain = Object.freeze({
4849
},
4950
hasMultipleGasCurrencies: getEnvValue('NEXT_PUBLIC_NETWORK_MULTIPLE_GAS_CURRENCIES') === 'true',
5051
tokenStandard: getEnvValue('NEXT_PUBLIC_NETWORK_TOKEN_STANDARD_NAME') || 'ERC',
52+
additionalTokenTypes: parseEnvJson<Array<AdditionalTokenType>>(getEnvValue('NEXT_PUBLIC_NETWORK_ADDITIONAL_TOKEN_TYPES')) || [],
5153
rpcUrls,
5254
isTestnet: getEnvValue('NEXT_PUBLIC_IS_TESTNET') === 'true',
5355
verificationType,

configs/envs/.env.zilliqa

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ NEXT_PUBLIC_VIEWS_ADDRESS_BECH_32_PREFIX=zil
5151
NEXT_PUBLIC_VIEWS_ADDRESS_FORMAT=["base16", "bech32"]
5252
NEXT_PUBLIC_VIEWS_CONTRACT_DECODED_BYTECODE_ENABLED=true
5353
NEXT_PUBLIC_VIEWS_TOKEN_SCAM_TOGGLE_ENABLED=true
54-
NEXT_PUBLIC_VISUALIZE_API_HOST=https://visualizer.services.blockscout.com
54+
NEXT_PUBLIC_VISUALIZE_API_HOST=https://visualizer.services.blockscout.com
55+
NEXT_PUBLIC_NETWORK_ADDITIONAL_TOKEN_TYPES=[{'id':'ZRC-2','name':'ZRC-2'}]

deploy/tools/envs-validator/schemas/chain.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,13 @@ export default yup.object({
4242
otherwise: (schema) => schema,
4343
}),
4444
NEXT_PUBLIC_NETWORK_TOKEN_STANDARD_NAME: yup.string(),
45+
NEXT_PUBLIC_NETWORK_ADDITIONAL_TOKEN_TYPES: yup
46+
.array()
47+
.transform(replaceQuotes)
48+
.json()
49+
.of(yup.object({
50+
id: yup.string().required(),
51+
name: yup.string().required(),
52+
}).noUnknown(true)),
4553
NEXT_PUBLIC_IS_TESTNET: yup.boolean(),
4654
});

docs/ENVS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ Also, be aware that if you customize the name of the currency or any of its deno
119119
| NEXT_PUBLIC_NETWORK_MULTIPLE_GAS_CURRENCIES | `boolean` | Set to `true` for networks where users can pay transaction fees in either the native coin or ERC-20 tokens. | - | `false` | `true` | v1.33.0+ |
120120
| NEXT_PUBLIC_NETWORK_VERIFICATION_TYPE | `validation` \| `mining` \| 'fee reception' | Verification type in the network. Irrelevant for Arbitrum (verification type is always `posting`) and ZkEvm (verification type is always `sequencing`) L2s | - | `mining` | `validation` | v1.0.x+ |
121121
| NEXT_PUBLIC_NETWORK_TOKEN_STANDARD_NAME | `string` | Name of the standard for creating tokens | - | `ERC` | `BEP` | v1.31.0+ |
122+
| NEXT_PUBLIC_NETWORK_ADDITIONAL_TOKEN_TYPES | `Array<{id: string; name: string;}>` | List of additional **ERC-20-like (fungible)** token types supported by the explorer UI (extends token type filters/labels). *Note: the token type id must also be supported by the backend API responses and filters.* | - | `[]` | `'[{"id":"ERC-777","name":"ERC-777"}]'` | v2.6.0+ |
122123
| NEXT_PUBLIC_IS_TESTNET | `boolean`| Set to true if network is testnet | - | `false` | `true` | v1.0.x+ |
123124

124125
&nbsp;

lib/token/tokenTypes.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,41 @@ import type { NFTTokenType, TokenType } from 'types/api/token';
33
import config from 'configs/app';
44

55
const tokenStandardName = config.chain.tokenStandard;
6+
const additionalTokenTypes = config.chain.additionalTokenTypes;
67

7-
export const NFT_TOKEN_TYPES: Record<NFTTokenType, string > = {
8+
export const NFT_TOKEN_TYPES: Record<NFTTokenType, string> = {
89
'ERC-721': `${ tokenStandardName }-721`,
910
'ERC-1155': `${ tokenStandardName }-1155`,
1011
'ERC-404': `${ tokenStandardName }-404`,
1112
};
1213

13-
export const TOKEN_TYPES: Record<TokenType, string > = {
14+
export const TOKEN_TYPES: Record<string, string> = {
1415
'ERC-20': `${ tokenStandardName }-20`,
16+
...additionalTokenTypes.reduce((result, item) => {
17+
result[item.id] = item.name;
18+
return result;
19+
}, {} as Record<string, string>),
1520
...NFT_TOKEN_TYPES,
1621
};
1722

18-
export const NFT_TOKEN_TYPE_IDS: Array<NFTTokenType> = [ 'ERC-721', 'ERC-1155', 'ERC-404' ];
19-
export const TOKEN_TYPE_IDS: Array<TokenType> = [ 'ERC-20', ...NFT_TOKEN_TYPE_IDS ];
23+
export const NFT_TOKEN_TYPE_IDS: Array<NFTTokenType> = Object.keys(NFT_TOKEN_TYPES) as Array<NFTTokenType>;
24+
export const TOKEN_TYPE_IDS = Object.keys(TOKEN_TYPES);
2025

21-
export function getTokenTypeName(typeId: TokenType) {
22-
return TOKEN_TYPES[typeId];
26+
export function getTokenTypeName(typeId: string) {
27+
return TOKEN_TYPES[typeId] || typeId;
28+
}
29+
30+
export function isFungibleTokenType(typeId: TokenType): boolean {
31+
return typeId === 'ERC-20' || additionalTokenTypes.some((item) => item.id === typeId);
32+
}
33+
34+
export function hasTokenTransferValue(typeId: TokenType) {
35+
if (typeId === 'ERC-20' || typeId === 'ERC-1155' || typeId === 'ERC-404') {
36+
return true;
37+
}
38+
return additionalTokenTypes.some((item) => item.id === typeId);
39+
}
40+
41+
export function hasTokenIds(typeId: TokenType) {
42+
return typeId === 'ERC-1155' || typeId === 'ERC-404';
2343
}

mocks/tokens/tokenInfo.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const tokenInfo: TokenInfo = {
88
holders_count: '46554',
99
name: 'ARIANEE',
1010
symbol: 'ARIA',
11-
type: 'ERC-20' as const,
11+
type: 'ERC-20',
1212
total_supply: '1235',
1313
icon_url: 'http://localhost:3000/token-icon.png',
1414
reputation: 'ok',
@@ -19,7 +19,7 @@ export const tokenCounters: TokenCounters = {
1919
transfers_count: '88282281',
2020
};
2121

22-
export const tokenInfoERC20a: TokenInfo<'ERC-20'> = {
22+
export const tokenInfoERC20a: TokenInfo = {
2323
address_hash: '0xb2a90505dc6680a7a695f7975d0d32EeF610f456',
2424
circulating_market_cap: '117268489.23970924',
2525
decimals: '18',
@@ -28,12 +28,12 @@ export const tokenInfoERC20a: TokenInfo<'ERC-20'> = {
2828
name: 'hyfi.token',
2929
symbol: 'HyFi',
3030
total_supply: '369000000000000000000000000',
31-
type: 'ERC-20' as const,
31+
type: 'ERC-20',
3232
icon_url: 'http://localhost:3000/token-icon.png',
3333
reputation: 'ok',
3434
};
3535

36-
export const tokenInfoERC20b: TokenInfo<'ERC-20'> = {
36+
export const tokenInfoERC20b: TokenInfo = {
3737
address_hash: '0xc1116c98ba622a6218433fF90a2E40DEa482d7A7',
3838
circulating_market_cap: '115060192.36105014',
3939
decimals: '6',
@@ -42,12 +42,12 @@ export const tokenInfoERC20b: TokenInfo<'ERC-20'> = {
4242
name: 'USD Coin',
4343
symbol: 'USDC',
4444
total_supply: '900000000000000000000000000',
45-
type: 'ERC-20' as const,
45+
type: 'ERC-20',
4646
icon_url: null,
4747
reputation: 'ok',
4848
};
4949

50-
export const tokenInfoERC20c: TokenInfo<'ERC-20'> = {
50+
export const tokenInfoERC20c: TokenInfo = {
5151
address_hash: '0xc1116c98ba622a6218433fF90a2E40DEa482d7A8',
5252
circulating_market_cap: null,
5353
decimals: '18',
@@ -56,12 +56,12 @@ export const tokenInfoERC20c: TokenInfo<'ERC-20'> = {
5656
name: 'Ethereum',
5757
symbol: 'ETH',
5858
total_supply: '1000000000000000000000000',
59-
type: 'ERC-20' as const,
59+
type: 'ERC-20',
6060
icon_url: null,
6161
reputation: 'ok',
6262
};
6363

64-
export const tokenInfoERC20d: TokenInfo<'ERC-20'> = {
64+
export const tokenInfoERC20d: TokenInfo = {
6565
address_hash: '0xCc7bb2D219A0FC08033E130629C2B854b7bA9196',
6666
circulating_market_cap: null,
6767
decimals: '18',
@@ -70,12 +70,12 @@ export const tokenInfoERC20d: TokenInfo<'ERC-20'> = {
7070
name: 'Zeta',
7171
symbol: 'ZETA',
7272
total_supply: '2100000000000000000000000000',
73-
type: 'ERC-20' as const,
73+
type: 'ERC-20',
7474
icon_url: null,
7575
reputation: 'ok',
7676
};
7777

78-
export const tokenInfoERC20LongSymbol: TokenInfo<'ERC-20'> = {
78+
export const tokenInfoERC20LongSymbol: TokenInfo = {
7979
address_hash: '0xCc7bb2D219A0FC08033E130629C2B854b7bA9197',
8080
circulating_market_cap: '112855875.75888918',
8181
decimals: '18',
@@ -84,12 +84,12 @@ export const tokenInfoERC20LongSymbol: TokenInfo<'ERC-20'> = {
8484
name: 'Zeta',
8585
symbol: 'ipfs://QmUpFUfVKDCWeZQk5pvDFUxnpQP9N6eLSHhNUy49T1JVtY',
8686
total_supply: '2100000000000000000000000000',
87-
type: 'ERC-20' as const,
87+
type: 'ERC-20',
8888
icon_url: null,
8989
reputation: 'ok',
9090
};
9191

92-
export const tokenInfoERC721a: TokenInfo<'ERC-721'> = {
92+
export const tokenInfoERC721a: TokenInfo = {
9393
address_hash: '0xDe7cAc71E072FCBd4453E5FB3558C2684d1F88A0',
9494
circulating_market_cap: null,
9595
decimals: null,
@@ -98,12 +98,12 @@ export const tokenInfoERC721a: TokenInfo<'ERC-721'> = {
9898
name: 'HyFi Athena',
9999
symbol: 'HYFI_ATHENA',
100100
total_supply: '105',
101-
type: 'ERC-721' as const,
101+
type: 'ERC-721',
102102
icon_url: null,
103103
reputation: 'ok',
104104
};
105105

106-
export const tokenInfoERC721b: TokenInfo<'ERC-721'> = {
106+
export const tokenInfoERC721b: TokenInfo = {
107107
address_hash: '0xA8d5C7beEA8C9bB57f5fBa35fB638BF45550b11F',
108108
circulating_market_cap: null,
109109
decimals: null,
@@ -112,12 +112,12 @@ export const tokenInfoERC721b: TokenInfo<'ERC-721'> = {
112112
name: 'World Of Women Galaxy',
113113
symbol: 'WOWG',
114114
total_supply: null,
115-
type: 'ERC-721' as const,
115+
type: 'ERC-721',
116116
icon_url: null,
117117
reputation: 'ok',
118118
};
119119

120-
export const tokenInfoERC721c: TokenInfo<'ERC-721'> = {
120+
export const tokenInfoERC721c: TokenInfo = {
121121
address_hash: '0x47646F1d7dc4Dd2Db5a41D092e2Cf966e27A4992',
122122
circulating_market_cap: null,
123123
decimals: null,
@@ -126,12 +126,12 @@ export const tokenInfoERC721c: TokenInfo<'ERC-721'> = {
126126
name: 'Puma',
127127
symbol: 'PUMA',
128128
total_supply: null,
129-
type: 'ERC-721' as const,
129+
type: 'ERC-721',
130130
icon_url: null,
131131
reputation: 'ok',
132132
};
133133

134-
export const tokenInfoERC721LongSymbol: TokenInfo<'ERC-721'> = {
134+
export const tokenInfoERC721LongSymbol: TokenInfo = {
135135
address_hash: '0x47646F1d7dc4Dd2Db5a41D092e2Cf966e27A4993',
136136
circulating_market_cap: null,
137137
decimals: null,
@@ -140,12 +140,12 @@ export const tokenInfoERC721LongSymbol: TokenInfo<'ERC-721'> = {
140140
name: 'Puma',
141141
symbol: 'ipfs://QmUpFUfVKDCWeZQk5pvDFUxnpQP9N6eLSHhNUy49T1JVtY',
142142
total_supply: null,
143-
type: 'ERC-721' as const,
143+
type: 'ERC-721',
144144
icon_url: null,
145145
reputation: 'ok',
146146
};
147147

148-
export const tokenInfoERC1155a: TokenInfo<'ERC-1155'> = {
148+
export const tokenInfoERC1155a: TokenInfo = {
149149
address_hash: '0x4b333DEd10c7ca855EA2C8D4D90A0a8b73788c8e',
150150
circulating_market_cap: null,
151151
decimals: null,
@@ -154,12 +154,12 @@ export const tokenInfoERC1155a: TokenInfo<'ERC-1155'> = {
154154
name: 'HyFi Membership',
155155
symbol: 'HYFI_MEMBERSHIP',
156156
total_supply: '482',
157-
type: 'ERC-1155' as const,
157+
type: 'ERC-1155',
158158
icon_url: null,
159159
reputation: 'ok',
160160
};
161161

162-
export const tokenInfoERC1155b: TokenInfo<'ERC-1155'> = {
162+
export const tokenInfoERC1155b: TokenInfo = {
163163
address_hash: '0xf4b71b179132ad457f6bcae2a55efa9e4b26eefc',
164164
circulating_market_cap: null,
165165
decimals: null,
@@ -168,12 +168,12 @@ export const tokenInfoERC1155b: TokenInfo<'ERC-1155'> = {
168168
name: 'WinkyVerse Collections',
169169
symbol: 'WVC',
170170
total_supply: '4943',
171-
type: 'ERC-1155' as const,
171+
type: 'ERC-1155',
172172
icon_url: null,
173173
reputation: 'ok',
174174
};
175175

176-
export const tokenInfoERC1155WithoutName: TokenInfo<'ERC-1155'> = {
176+
export const tokenInfoERC1155WithoutName: TokenInfo = {
177177
address_hash: '0x4b333DEd10c7ca855EA2C8D4D90A0a8b73788c8a',
178178
circulating_market_cap: null,
179179
decimals: null,
@@ -182,12 +182,12 @@ export const tokenInfoERC1155WithoutName: TokenInfo<'ERC-1155'> = {
182182
name: null,
183183
symbol: null,
184184
total_supply: '482',
185-
type: 'ERC-1155' as const,
185+
type: 'ERC-1155',
186186
icon_url: null,
187187
reputation: 'ok',
188188
};
189189

190-
export const tokenInfoERC404: TokenInfo<'ERC-404'> = {
190+
export const tokenInfoERC404: TokenInfo = {
191191
address_hash: '0xB5C457dDB4cE3312a6C5a2b056a1652bd542a208',
192192
circulating_market_cap: '0.0',
193193
decimals: '18',
@@ -197,27 +197,27 @@ export const tokenInfoERC404: TokenInfo<'ERC-404'> = {
197197
name: 'OMNI404',
198198
symbol: 'O404',
199199
total_supply: '6482275000000000000',
200-
type: 'ERC-404' as const,
200+
type: 'ERC-404',
201201
reputation: 'ok',
202202
};
203203

204-
export const bridgedTokenA: TokenInfo<'ERC-20'> = {
204+
export const bridgedTokenA: TokenInfo = {
205205
...tokenInfoERC20a,
206206
is_bridged: true,
207207
origin_chain_id: '1',
208208
bridge_type: 'omni',
209209
foreign_address: '0x4b333DEd10c7ca855EA2C8D4D90A0a8b73788c8b',
210210
};
211211

212-
export const bridgedTokenB: TokenInfo<'ERC-20'> = {
212+
export const bridgedTokenB: TokenInfo = {
213213
...tokenInfoERC20b,
214214
is_bridged: true,
215215
origin_chain_id: '56',
216216
bridge_type: 'omni',
217217
foreign_address: '0xf4b71b179132ad457f6bcae2a55efa9e4b26eefd',
218218
};
219219

220-
export const bridgedTokenC: TokenInfo<'ERC-20'> = {
220+
export const bridgedTokenC: TokenInfo = {
221221
...tokenInfoERC20d,
222222
is_bridged: true,
223223
origin_chain_id: '99',

mocks/tokens/tokenTransfer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export const erc1155A: TokenTransfer = {
154154
export const erc1155B: TokenTransfer = {
155155
...erc1155A,
156156
token: {
157-
...(erc1155A.token as TokenInfo<'ERC-1155'>),
157+
...(erc1155A.token as TokenInfo),
158158
name: 'SastanaNFT',
159159
symbol: 'ipfs://QmUpFUfVKDCWeZQk5pvDFUxnpQP9N6eLSHhNUy49T1JVtY',
160160
},
@@ -164,7 +164,7 @@ export const erc1155B: TokenTransfer = {
164164
export const erc1155C: TokenTransfer = {
165165
...erc1155A,
166166
token: {
167-
...(erc1155A.token as TokenInfo<'ERC-1155'>),
167+
...(erc1155A.token as TokenInfo),
168168
name: 'SastanaNFT',
169169
symbol: 'ipfs://QmUpFUfVKDCWeZQk5pvDFUxnpQP9N6eLSHhNUy49T1JVtY',
170170
},
@@ -174,7 +174,7 @@ export const erc1155C: TokenTransfer = {
174174
export const erc1155D: TokenTransfer = {
175175
...erc1155A,
176176
token: {
177-
...(erc1155A.token as TokenInfo<'ERC-1155'>),
177+
...(erc1155A.token as TokenInfo),
178178
name: 'SastanaNFT',
179179
symbol: 'ipfs://QmUpFUfVKDCWeZQk5pvDFUxnpQP9N6eLSHhNUy49T1JVtY',
180180
},
@@ -235,7 +235,7 @@ export const erc404A: TokenTransfer = {
235235
export const erc404B: TokenTransfer = {
236236
...erc404A,
237237
token: {
238-
...(erc404A.token as TokenInfo<'ERC-404'>),
238+
...(erc404A.token as TokenInfo),
239239
name: 'SastanaNFT',
240240
symbol: 'ipfs://QmUpFUfVKDCWeZQk5pvDFUxnpQP9N6eLSHhNUy49T1JVtY',
241241
},

playwright/fixtures/socketServer.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ export const joinChannel = async(socket: WebSocket, channelName: string) => {
6060

6161
export function sendMessage(socket: WebSocket, channel: Channel, msg: 'coin_balance', payload: { coin_balance: AddressCoinBalanceHistoryItem }): void;
6262
export function sendMessage(socket: WebSocket, channel: Channel, msg: 'token_balance', payload: { block_number: number }): void;
63-
export function sendMessage(socket: WebSocket, channel: Channel, msg: 'updated_token_balances_erc_20', payload: AddressTokensBalancesSocketMessage): void;
64-
export function sendMessage(socket: WebSocket, channel: Channel, msg: 'updated_token_balances_erc_721', payload: AddressTokensBalancesSocketMessage): void;
65-
export function sendMessage(socket: WebSocket, channel: Channel, msg: 'updated_token_balances_erc_1155', payload: AddressTokensBalancesSocketMessage): void;
66-
export function sendMessage(socket: WebSocket, channel: Channel, msg: 'updated_token_balances_erc_404', payload: AddressTokensBalancesSocketMessage): void;
63+
export function sendMessage(socket: WebSocket, channel: Channel, msg: `updated_token_balances_${ string }`, payload: AddressTokensBalancesSocketMessage): void;
6764
export function sendMessage(socket: WebSocket, channel: Channel, msg: 'transaction', payload: { transaction: number }): void;
6865
export function sendMessage(socket: WebSocket, channel: Channel, msg: 'transaction', payload: { transactions: Array<Transaction> }): void;
6966
export function sendMessage(socket: WebSocket, channel: Channel, msg: 'pending_transaction', payload: { pending_transaction: number }): void;

0 commit comments

Comments
 (0)