@ledgerhq/cryptoassets 13.32.0-nightly.2 → 13.32.0-nightly.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,351 +1,298 @@
1
- import { convertApiToken, type ApiTokenData } from "./api-token-converter";
1
+ import { convertApiToken, legacyIdToApiId, type ApiTokenData } from "./api-token-converter";
2
+
3
+ describe("legacyIdToApiId", () => {
4
+ it("should transform MultiversX to elrond format", () => {
5
+ expect(legacyIdToApiId("multiversx/esdt/USDC-c76f1f")).toBe("elrond/esdt/USDC-c76f1f");
6
+ });
7
+
8
+ it("should transform Stellar to lowercase", () => {
9
+ expect(
10
+ legacyIdToApiId(
11
+ "stellar/asset/USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
12
+ ),
13
+ ).toBe("stellar/asset/usdc:ga5zsejyb37jrc5avcia5mop4rhtm335x2kgx3ihojapp5re34k4kzvn");
14
+ });
15
+
16
+ it("should not transform other IDs", () => {
17
+ expect(legacyIdToApiId("ethereum/erc20/usdc")).toBe("ethereum/erc20/usdc");
18
+ expect(legacyIdToApiId("ton/jetton/test")).toBe("ton/jetton/test");
19
+ });
20
+ });
2
21
 
3
22
  describe("convertApiToken", () => {
4
- describe("ERC20 tokens", () => {
5
- it("should convert ERC20 token correctly", () => {
23
+ describe("MultiversX transformation", () => {
24
+ it("should transform elrond ID to multiversx", () => {
6
25
  const apiToken: ApiTokenData = {
7
- id: "ethereum/erc20/usdc",
8
- contractAddress: "0xA0b86a33E6441E6e96481a83b9ceaaA8d547B8cf",
26
+ id: "elrond/esdt/USDC-c76f1f",
27
+ contractAddress: "USDC-c76f1f",
9
28
  name: "USD Coin",
10
29
  ticker: "USDC",
11
30
  units: [{ code: "USDC", name: "USD Coin", magnitude: 6 }],
12
- standard: "erc20",
13
- };
14
-
15
- const result = convertApiToken(apiToken);
16
-
17
- expect(result).toBeDefined();
18
- expect(result?.type).toBe("TokenCurrency");
19
- expect(result?.id).toBe("ethereum/erc20/usdc");
20
- expect(result?.contractAddress).toBe("0xA0b86a33E6441E6e96481a83b9ceaaA8d547B8cf");
21
- expect(result?.ticker).toBe("USDC");
22
- expect(result?.name).toBe("USD Coin");
23
- expect(result?.parentCurrency?.id).toBe("ethereum");
24
- expect(result?.tokenType).toBe("erc20");
25
- });
26
-
27
- it("should convert BEP20 token correctly", () => {
28
- const apiToken: ApiTokenData = {
29
- id: "bsc/bep20/usdt",
30
- contractAddress: "0x55d398326f99059fF775485246999027B3197955",
31
- name: "Tether USD",
32
- ticker: "USDT",
33
- units: [{ code: "USDT", name: "Tether USD", magnitude: 18 }],
34
- standard: "bep20",
31
+ standard: "esdt",
35
32
  };
36
33
 
37
34
  const result = convertApiToken(apiToken);
38
35
 
39
- expect(result).toBeDefined();
40
- expect(result?.type).toBe("TokenCurrency");
41
- expect(result?.parentCurrency?.id).toBe("bsc");
42
- expect(result?.tokenType).toBe("bep20");
36
+ expect(result?.id).toBe("multiversx/esdt/USDC-c76f1f");
37
+ expect(result?.parentCurrency?.id).toBe("elrond");
38
+ expect(result?.tokenType).toBe("esdt");
43
39
  });
44
40
  });
45
41
 
46
- describe("SPL tokens", () => {
47
- it("should convert SPL token correctly", () => {
42
+ describe("Stellar transformation", () => {
43
+ it("should transform lowercase stellar to mixed-case format", () => {
48
44
  const apiToken: ApiTokenData = {
49
- id: "solana/spl/usdc",
50
- contractAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
45
+ id: "stellar/asset/usdc:ga5zsejyb37jrc5avcia5mop4rhtm335x2kgx3ihojapp5re34k4kzvn",
46
+ contractAddress: "USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
51
47
  name: "USD Coin",
52
48
  ticker: "USDC",
53
- units: [{ code: "USDC", name: "USD Coin", magnitude: 6 }],
54
- standard: "spl",
49
+ units: [{ code: "USDC", name: "USD Coin", magnitude: 7 }],
50
+ standard: "asset",
55
51
  };
56
52
 
57
53
  const result = convertApiToken(apiToken);
58
54
 
59
- expect(result).toBeDefined();
60
- expect(result?.type).toBe("TokenCurrency");
61
- expect(result?.parentCurrency?.id).toBe("solana");
62
- expect(result?.tokenType).toBe("spl");
55
+ expect(result?.id).toBe(
56
+ "stellar/asset/USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
57
+ );
58
+ expect(result?.tokenType).toBe("stellar");
63
59
  });
64
- });
65
60
 
66
- describe("Jetton tokens", () => {
67
- it("should convert Jetton token correctly", () => {
61
+ it("should keep already uppercase stellar suffix", () => {
68
62
  const apiToken: ApiTokenData = {
69
- id: "ton/jetton/usdt",
70
- contractAddress: "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs",
71
- name: "Tether USD",
72
- ticker: "USDT",
73
- units: [{ code: "USDT", name: "Tether USD", magnitude: 6 }],
74
- standard: "jetton",
63
+ id: "stellar/asset/USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
64
+ contractAddress: "USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
65
+ name: "USD Coin",
66
+ ticker: "USDC",
67
+ units: [{ code: "USDC", name: "USD Coin", magnitude: 7 }],
68
+ standard: "asset",
75
69
  };
76
70
 
77
71
  const result = convertApiToken(apiToken);
78
72
 
79
- expect(result).toBeDefined();
80
- expect(result?.type).toBe("TokenCurrency");
81
- expect(result?.parentCurrency?.id).toBe("ton");
82
- expect(result?.tokenType).toBe("jetton");
73
+ expect(result?.id).toBe(
74
+ "stellar/asset/USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
75
+ );
76
+ expect(result?.tokenType).toBe("stellar");
83
77
  });
84
- });
85
78
 
86
- describe("ASA tokens", () => {
87
- it("should convert ASA token correctly", () => {
79
+ it("should handle stellar standard without transformation", () => {
88
80
  const apiToken: ApiTokenData = {
89
- id: "algorand/asa/31566704",
90
- contractAddress: "31566704",
91
- name: "USDC",
81
+ id: "stellar/asset/USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
82
+ contractAddress: "USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
83
+ name: "USD Coin",
92
84
  ticker: "USDC",
93
- units: [{ code: "USDC", name: "USDC", magnitude: 6 }],
94
- standard: "asa",
85
+ units: [{ code: "USDC", name: "USD Coin", magnitude: 7 }],
86
+ standard: "stellar",
95
87
  };
96
88
 
97
89
  const result = convertApiToken(apiToken);
98
90
 
99
- expect(result).toBeDefined();
100
- expect(result?.type).toBe("TokenCurrency");
101
- expect(result?.id).toBe("algorand/asa/31566704");
102
- expect(result?.parentCurrency?.id).toBe("algorand");
103
- expect(result?.tokenType).toBe("asa");
91
+ expect(result?.tokenType).toBe("stellar");
104
92
  });
105
93
  });
106
94
 
107
- describe("ESDT tokens", () => {
108
- it("should convert ESDT token correctly", () => {
95
+ describe("Cardano transformation", () => {
96
+ it("should reconstruct contractAddress from policyId + tokenIdentifier", () => {
109
97
  const apiToken: ApiTokenData = {
110
- id: "elrond/esdt/USDC-c76f1f",
111
- contractAddress: "USDC-c76f1f",
112
- name: "WrappedUSDC",
113
- ticker: "USDC",
114
- units: [{ code: "USDC", name: "WrappedUSDC", magnitude: 6 }],
115
- standard: "esdt",
98
+ id: "cardano/native/policyId.assetName",
99
+ contractAddress: "policyId",
100
+ name: "Test Token",
101
+ ticker: "TEST",
102
+ units: [{ code: "TEST", name: "Test Token", magnitude: 6 }],
103
+ standard: "native",
104
+ tokenIdentifier: ".assetName",
116
105
  };
117
106
 
118
107
  const result = convertApiToken(apiToken);
119
108
 
120
- expect(result).toBeDefined();
121
- expect(result?.type).toBe("TokenCurrency");
122
- expect(result?.id).toBe("multiversx/esdt/USDC-c76f1f");
123
- expect(result?.parentCurrency?.id).toBe("elrond");
124
- expect(result?.tokenType).toBe("esdt");
109
+ expect(result?.contractAddress).toBe("policyId.assetName");
110
+ expect(result?.tokenType).toBe("native");
125
111
  });
126
- });
127
112
 
128
- describe("TRON tokens", () => {
129
- it("should convert TRC20 token correctly", () => {
113
+ it("should not reconstruct if tokenIdentifier is missing", () => {
130
114
  const apiToken: ApiTokenData = {
131
- id: "tron/trc20/usdt",
132
- contractAddress: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
133
- name: "Tether USD",
134
- ticker: "USDT",
135
- units: [{ code: "USDT", name: "Tether USD", magnitude: 6 }],
136
- standard: "trc20",
115
+ id: "cardano/native/policyId",
116
+ contractAddress: "policyId",
117
+ name: "Test Token",
118
+ ticker: "TEST",
119
+ units: [{ code: "TEST", name: "Test Token", magnitude: 6 }],
120
+ standard: "native",
137
121
  };
138
122
 
139
123
  const result = convertApiToken(apiToken);
140
124
 
141
- expect(result).toBeDefined();
142
- expect(result?.type).toBe("TokenCurrency");
143
- expect(result?.id).toBe("tron/trc20/usdt");
144
- expect(result?.parentCurrency?.id).toBe("tron");
145
- expect(result?.tokenType).toBe("trc20");
125
+ expect(result?.contractAddress).toBe("policyId");
146
126
  });
127
+ });
147
128
 
148
- it("should convert TRC10 token correctly", () => {
129
+ describe("Sui transformation", () => {
130
+ it("should transform coin standard to sui for sui tokens", () => {
149
131
  const apiToken: ApiTokenData = {
150
- id: "tron/trc10/1002000",
151
- contractAddress: "1002000",
152
- name: "BitTorrent",
153
- ticker: "BTT",
154
- units: [{ code: "BTT", name: "BitTorrent", magnitude: 6 }],
155
- standard: "trc10",
132
+ id: "sui/coin/0x2::sui::SUI",
133
+ contractAddress: "0x2::sui::SUI",
134
+ name: "Sui",
135
+ ticker: "SUI",
136
+ units: [{ code: "SUI", name: "Sui", magnitude: 9 }],
137
+ standard: "coin",
156
138
  };
157
139
 
158
140
  const result = convertApiToken(apiToken);
159
141
 
160
- expect(result).toBeDefined();
161
- expect(result?.type).toBe("TokenCurrency");
162
- expect(result?.id).toBe("tron/trc10/1002000");
163
- expect(result?.parentCurrency?.id).toBe("tron");
164
- expect(result?.tokenType).toBe("trc10");
142
+ expect(result?.tokenType).toBe("sui");
165
143
  });
166
- });
167
144
 
168
- describe("VeChain tokens", () => {
169
- it("should convert VIP180 token correctly", () => {
145
+ it("should not transform coin standard for non-sui tokens", () => {
170
146
  const apiToken: ApiTokenData = {
171
- id: "vechain/vip180/vtho",
172
- contractAddress: "0x0000000000000000000000000000456E65726779",
173
- name: "VeThor Token",
174
- ticker: "VTHO",
175
- units: [{ code: "VTHO", name: "VeThor Token", magnitude: 18 }],
176
- standard: "vip180",
147
+ id: "aptos/coin/0x1::aptos_coin::AptosCoin",
148
+ contractAddress: "0x1::aptos_coin::AptosCoin",
149
+ name: "Aptos Coin",
150
+ ticker: "APT",
151
+ units: [{ code: "APT", name: "Aptos Coin", magnitude: 8 }],
152
+ standard: "coin",
177
153
  };
178
154
 
179
155
  const result = convertApiToken(apiToken);
180
156
 
181
- expect(result).toBeDefined();
182
- expect(result?.type).toBe("TokenCurrency");
183
- expect(result?.id).toBe("vechain/vip180/vtho");
184
- expect(result?.parentCurrency?.id).toBe("vechain");
185
- expect(result?.tokenType).toBe("vip180");
157
+ expect(result?.tokenType).toBe("coin");
186
158
  });
187
159
  });
188
160
 
189
- describe("Cardano native tokens", () => {
190
- it("should convert Cardano native token correctly", () => {
161
+ describe("TON Jetton transformation", () => {
162
+ it("should remove name prefix from jetton ID", () => {
191
163
  const apiToken: ApiTokenData = {
192
- id: "cardano/native/f43a62fdc3965df486de8a0d32fe800963589c41b38946602a0dc535.41474958",
193
- contractAddress: "f43a62fdc3965df486de8a0d32fe800963589c41b38946602a0dc535.41474958",
194
- name: "AGIX",
195
- ticker: "AGIX",
196
- units: [{ code: "AGIX", name: "AGIX", magnitude: 8 }],
197
- standard: "native",
164
+ id: "ton/jetton/catizen_eqd-cvr0nz6xayrbvbhz-abtrrc6si5tvhvvpeqrav9uaad7",
165
+ contractAddress: "eqd-cvr0nz6xayrbvbhz-abtrrc6si5tvhvvpeqrav9uaad7",
166
+ name: "Catizen",
167
+ ticker: "CATI",
168
+ units: [{ code: "CATI", name: "Catizen", magnitude: 9 }],
169
+ standard: "jetton",
198
170
  };
199
171
 
200
172
  const result = convertApiToken(apiToken);
201
173
 
202
- expect(result).toBeDefined();
203
- expect(result?.type).toBe("TokenCurrency");
204
- expect(result?.id).toBe(
205
- "cardano/native/f43a62fdc3965df486de8a0d32fe800963589c41b38946602a0dc53541474958",
206
- );
207
- expect(result?.parentCurrency?.id).toBe("cardano");
208
- expect(result?.tokenType).toBe("native");
174
+ expect(result?.id).toBe("ton/jetton/eqd-cvr0nz6xayrbvbhz-abtrrc6si5tvhvvpeqrav9uaad7");
209
175
  });
210
176
 
211
- it("should return undefined for non-cardano native tokens", () => {
177
+ it("should not transform jetton ID without underscore", () => {
212
178
  const apiToken: ApiTokenData = {
213
- id: "ethereum/native/test",
214
- contractAddress: "test",
215
- name: "Test Token",
179
+ id: "ton/jetton/eqdtest",
180
+ contractAddress: "eqdtest",
181
+ name: "Test",
216
182
  ticker: "TEST",
217
- units: [{ code: "TEST", name: "Test Token", magnitude: 18 }],
218
- standard: "native",
183
+ units: [{ code: "TEST", name: "Test", magnitude: 9 }],
184
+ standard: "jetton",
219
185
  };
220
186
 
221
187
  const result = convertApiToken(apiToken);
222
188
 
223
- expect(result).toBeUndefined();
189
+ expect(result?.id).toBe("ton/jetton/eqdtest");
224
190
  });
225
191
  });
226
192
 
227
- describe("Stellar tokens", () => {
228
- it("should convert Stellar token correctly", () => {
193
+ describe("ledgerSignature handling", () => {
194
+ it("should include ledgerSignature when provided", () => {
229
195
  const apiToken: ApiTokenData = {
230
- id: "stellar/asset/USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
231
- contractAddress: "USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
196
+ id: "ethereum/erc20/usdc",
197
+ contractAddress: "0xA0b86",
232
198
  name: "USD Coin",
233
199
  ticker: "USDC",
234
- units: [{ code: "USDC", name: "USD Coin", magnitude: 7 }],
235
- standard: "stellar",
200
+ units: [{ code: "USDC", name: "USD Coin", magnitude: 6 }],
201
+ standard: "erc20",
202
+ ledgerSignature: "3045022100...",
236
203
  };
237
204
 
238
205
  const result = convertApiToken(apiToken);
239
206
 
240
- expect(result).toBeDefined();
241
- expect(result?.type).toBe("TokenCurrency");
242
- expect(result?.id).toBe(
243
- "stellar/asset/USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
244
- );
245
- expect(result?.parentCurrency?.id).toBe("stellar");
246
- expect(result?.tokenType).toBe("stellar");
207
+ expect(result?.ledgerSignature).toBe("3045022100...");
247
208
  });
248
- });
249
209
 
250
- describe("Aptos tokens", () => {
251
- it("should convert Aptos coin token correctly", () => {
210
+ it("should not include ledgerSignature when not provided", () => {
252
211
  const apiToken: ApiTokenData = {
253
- id: "aptos/coin/0x1::aptos_coin::AptosCoin",
254
- contractAddress: "0x1::aptos_coin::AptosCoin",
255
- name: "Aptos Coin",
256
- ticker: "APT",
257
- units: [{ code: "APT", name: "Aptos Coin", magnitude: 8 }],
258
- standard: "coin",
212
+ id: "ethereum/erc20/usdc",
213
+ contractAddress: "0xA0b86",
214
+ name: "USD Coin",
215
+ ticker: "USDC",
216
+ units: [{ code: "USDC", name: "USD Coin", magnitude: 6 }],
217
+ standard: "erc20",
259
218
  };
260
219
 
261
220
  const result = convertApiToken(apiToken);
262
221
 
263
- expect(result).toBeDefined();
264
- expect(result?.type).toBe("TokenCurrency");
265
- expect(result?.parentCurrency?.id).toBe("aptos");
266
- expect(result?.tokenType).toBe("coin");
222
+ expect(result?.ledgerSignature).toBeUndefined();
267
223
  });
224
+ });
268
225
 
269
- it("should convert Aptos fungible asset correctly", () => {
226
+ describe("disableCountervalue handling", () => {
227
+ it("should set disableCountervalue for testnet currencies", () => {
270
228
  const apiToken: ApiTokenData = {
271
- id: "aptos/fungible_asset/0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT",
272
- contractAddress:
273
- "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT",
274
- name: "Tether USD",
275
- ticker: "USDT",
276
- units: [{ code: "USDT", name: "Tether USD", magnitude: 6 }],
277
- standard: "fungible_asset",
229
+ id: "ethereum_sepolia/erc20/usdc",
230
+ contractAddress: "0x123",
231
+ name: "USD Coin",
232
+ ticker: "USDC",
233
+ units: [{ code: "USDC", name: "USD Coin", magnitude: 6 }],
234
+ standard: "erc20",
278
235
  };
279
236
 
280
237
  const result = convertApiToken(apiToken);
281
238
 
282
- expect(result).toBeDefined();
283
- expect(result?.type).toBe("TokenCurrency");
284
- expect(result?.parentCurrency?.id).toBe("aptos");
285
- expect(result?.tokenType).toBe("fungible_asset");
239
+ expect(result?.disableCountervalue).toBe(true);
286
240
  });
287
- });
288
241
 
289
- describe("Sui tokens", () => {
290
- it("should convert Sui token correctly", () => {
242
+ it("should respect explicit disableCountervalue flag", () => {
291
243
  const apiToken: ApiTokenData = {
292
- id: "sui/sui/0x2::sui::SUI",
293
- contractAddress: "0x2::sui::SUI",
294
- name: "Sui",
295
- ticker: "SUI",
296
- units: [{ code: "SUI", name: "Sui", magnitude: 9 }],
297
- standard: "sui",
244
+ id: "ethereum/erc20/test",
245
+ contractAddress: "0x123",
246
+ name: "Test Token",
247
+ ticker: "TEST",
248
+ units: [{ code: "TEST", name: "Test Token", magnitude: 18 }],
249
+ standard: "erc20",
250
+ disableCountervalue: true,
298
251
  };
299
252
 
300
253
  const result = convertApiToken(apiToken);
301
254
 
302
- expect(result).toBeDefined();
303
- expect(result?.type).toBe("TokenCurrency");
304
- expect(result?.parentCurrency?.id).toBe("sui");
305
- expect(result?.tokenType).toBe("sui");
255
+ expect(result?.disableCountervalue).toBe(true);
306
256
  });
307
257
  });
308
258
 
309
- describe("Unknown token standards", () => {
259
+ describe("Edge cases", () => {
310
260
  it("should return undefined for unknown parent currency", () => {
311
261
  const apiToken: ApiTokenData = {
312
- id: "nonexistent/unknown/test",
313
- contractAddress: "0x123...",
314
- name: "Test Token",
262
+ id: "unknowncurrency/erc20/test",
263
+ contractAddress: "0x123",
264
+ name: "Test",
315
265
  ticker: "TEST",
316
- units: [{ code: "TEST", name: "Test Token", magnitude: 18 }],
317
- standard: "unknown",
266
+ units: [{ code: "TEST", name: "Test", magnitude: 18 }],
267
+ standard: "erc20",
318
268
  };
319
269
 
320
270
  const result = convertApiToken(apiToken);
321
271
 
322
272
  expect(result).toBeUndefined();
323
273
  });
324
- });
325
274
 
326
- describe("Edge cases", () => {
327
275
  it("should handle delisted tokens", () => {
328
276
  const apiToken: ApiTokenData = {
329
- id: "ethereum/erc20/test",
330
- contractAddress: "0x123...",
331
- name: "Test Token",
332
- ticker: "TEST",
333
- units: [{ code: "TEST", name: "Test Token", magnitude: 18 }],
277
+ id: "ethereum/erc20/old",
278
+ contractAddress: "0x123",
279
+ name: "Old Token",
280
+ ticker: "OLD",
281
+ units: [{ code: "OLD", name: "Old Token", magnitude: 18 }],
334
282
  standard: "erc20",
335
283
  delisted: true,
336
284
  };
337
285
 
338
286
  const result = convertApiToken(apiToken);
339
287
 
340
- expect(result).toBeDefined();
341
288
  expect(result?.delisted).toBe(true);
342
289
  });
343
290
 
344
- it("should handle missing units gracefully", () => {
291
+ it("should handle empty units array", () => {
345
292
  const apiToken: ApiTokenData = {
346
293
  id: "ethereum/erc20/test",
347
- contractAddress: "0x123...",
348
- name: "Test Token",
294
+ contractAddress: "0x123",
295
+ name: "Test",
349
296
  ticker: "TEST",
350
297
  units: [],
351
298
  standard: "erc20",
@@ -353,23 +300,72 @@ describe("convertApiToken", () => {
353
300
 
354
301
  const result = convertApiToken(apiToken);
355
302
 
356
- expect(result).toBeDefined();
303
+ expect(result?.units).toEqual([]);
357
304
  });
305
+ });
358
306
 
359
- it("should handle complex token identifiers", () => {
307
+ describe("Standard token types", () => {
308
+ it("should convert ERC20 token", () => {
360
309
  const apiToken: ApiTokenData = {
361
- id: "cardano/native/policy123.asset456",
362
- contractAddress: "policy123.asset456",
363
- name: "Complex Token",
364
- ticker: "COMPLEX",
365
- units: [{ code: "COMPLEX", name: "Complex Token", magnitude: 6 }],
366
- standard: "native",
310
+ id: "ethereum/erc20/usdc",
311
+ contractAddress: "0xA0b86",
312
+ name: "USD Coin",
313
+ ticker: "USDC",
314
+ units: [{ code: "USDC", name: "USD Coin", magnitude: 6 }],
315
+ standard: "erc20",
316
+ };
317
+
318
+ const result = convertApiToken(apiToken);
319
+
320
+ expect(result?.type).toBe("TokenCurrency");
321
+ expect(result?.tokenType).toBe("erc20");
322
+ expect(result?.parentCurrency?.id).toBe("ethereum");
323
+ });
324
+
325
+ it("should convert SPL token", () => {
326
+ const apiToken: ApiTokenData = {
327
+ id: "solana/spl/usdc",
328
+ contractAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
329
+ name: "USD Coin",
330
+ ticker: "USDC",
331
+ units: [{ code: "USDC", name: "USD Coin", magnitude: 6 }],
332
+ standard: "spl",
333
+ };
334
+
335
+ const result = convertApiToken(apiToken);
336
+
337
+ expect(result?.tokenType).toBe("spl");
338
+ expect(result?.parentCurrency?.id).toBe("solana");
339
+ });
340
+
341
+ it("should convert TRC20 token", () => {
342
+ const apiToken: ApiTokenData = {
343
+ id: "tron/trc20/usdt",
344
+ contractAddress: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
345
+ name: "Tether USD",
346
+ ticker: "USDT",
347
+ units: [{ code: "USDT", name: "Tether USD", magnitude: 6 }],
348
+ standard: "trc20",
367
349
  };
368
350
 
369
351
  const result = convertApiToken(apiToken);
370
352
 
371
- expect(result).toBeDefined();
372
- expect(result?.id).toBe("cardano/native/policy123asset456");
353
+ expect(result?.tokenType).toBe("trc20");
354
+ });
355
+
356
+ it("should convert ASA token", () => {
357
+ const apiToken: ApiTokenData = {
358
+ id: "algorand/asa/31566704",
359
+ contractAddress: "31566704",
360
+ name: "USDC",
361
+ ticker: "USDC",
362
+ units: [{ code: "USDC", name: "USDC", magnitude: 6 }],
363
+ standard: "asa",
364
+ };
365
+
366
+ const result = convertApiToken(apiToken);
367
+
368
+ expect(result?.tokenType).toBe("asa");
373
369
  });
374
370
  });
375
371
  });