@ledgerhq/cryptoassets 13.30.0 → 13.31.0-nightly.1
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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +32 -0
- package/README.md +0 -257
- package/lib/abandonseed.d.ts.map +1 -1
- package/lib/abandonseed.js +4 -1
- package/lib/abandonseed.js.map +1 -1
- package/lib/api-token-converter.js +15 -15
- package/lib/api-token-converter.js.map +1 -1
- package/lib/crypto-assets-importer/importers/sui/index.d.ts.map +1 -1
- package/lib/crypto-assets-importer/importers/sui/index.js +4 -1
- package/lib/crypto-assets-importer/importers/sui/index.js.map +1 -1
- package/lib/crypto-assets-importer/importers/sui/sui.test.js +14 -3
- package/lib/crypto-assets-importer/importers/sui/sui.test.js.map +1 -1
- package/lib/currencies.d.ts.map +1 -1
- package/lib/currencies.js +92 -10
- package/lib/currencies.js.map +1 -1
- package/lib/data/sui.d.ts +2 -1
- package/lib/data/sui.d.ts.map +1 -1
- package/lib/data/sui.js.map +1 -1
- package/lib/legacy/legacy-data.d.ts +25 -0
- package/lib/legacy/legacy-data.d.ts.map +1 -0
- package/lib/legacy/legacy-data.js +102 -0
- package/lib/legacy/legacy-data.js.map +1 -0
- package/lib/legacy/legacy-state.d.ts +9 -0
- package/lib/legacy/legacy-state.d.ts.map +1 -0
- package/lib/legacy/legacy-state.js +12 -0
- package/lib/legacy/legacy-state.js.map +1 -0
- package/lib/legacy/legacy-utils.d.ts +89 -0
- package/lib/legacy/legacy-utils.d.ts.map +1 -0
- package/lib/legacy/legacy-utils.js +448 -0
- package/lib/legacy/legacy-utils.js.map +1 -0
- package/lib/legacy/legacy.test.d.ts +2 -0
- package/lib/legacy/legacy.test.d.ts.map +1 -0
- package/lib/legacy/legacy.test.js +466 -0
- package/lib/legacy/legacy.test.js.map +1 -0
- package/lib/tokens.d.ts +20 -50
- package/lib/tokens.d.ts.map +1 -1
- package/lib/tokens.js +49 -503
- package/lib/tokens.js.map +1 -1
- package/lib/tokens.test.js +4 -3
- package/lib/tokens.test.js.map +1 -1
- package/lib-es/abandonseed.d.ts.map +1 -1
- package/lib-es/abandonseed.js +4 -1
- package/lib-es/abandonseed.js.map +1 -1
- package/lib-es/api-token-converter.js +2 -2
- package/lib-es/api-token-converter.js.map +1 -1
- package/lib-es/crypto-assets-importer/importers/sui/index.d.ts.map +1 -1
- package/lib-es/crypto-assets-importer/importers/sui/index.js +4 -1
- package/lib-es/crypto-assets-importer/importers/sui/index.js.map +1 -1
- package/lib-es/crypto-assets-importer/importers/sui/sui.test.js +14 -3
- package/lib-es/crypto-assets-importer/importers/sui/sui.test.js.map +1 -1
- package/lib-es/currencies.d.ts.map +1 -1
- package/lib-es/currencies.js +92 -10
- package/lib-es/currencies.js.map +1 -1
- package/lib-es/data/sui.d.ts +2 -1
- package/lib-es/data/sui.d.ts.map +1 -1
- package/lib-es/data/sui.js.map +1 -1
- package/lib-es/legacy/legacy-data.d.ts +25 -0
- package/lib-es/legacy/legacy-data.d.ts.map +1 -0
- package/lib-es/legacy/legacy-data.js +76 -0
- package/lib-es/legacy/legacy-data.js.map +1 -0
- package/lib-es/legacy/legacy-state.d.ts +9 -0
- package/lib-es/legacy/legacy-state.d.ts.map +1 -0
- package/lib-es/legacy/legacy-state.js +9 -0
- package/lib-es/legacy/legacy-state.js.map +1 -0
- package/lib-es/legacy/legacy-utils.d.ts +89 -0
- package/lib-es/legacy/legacy-utils.d.ts.map +1 -0
- package/lib-es/legacy/legacy-utils.js +427 -0
- package/lib-es/legacy/legacy-utils.js.map +1 -0
- package/lib-es/legacy/legacy.test.d.ts +2 -0
- package/lib-es/legacy/legacy.test.d.ts.map +1 -0
- package/lib-es/legacy/legacy.test.js +464 -0
- package/lib-es/legacy/legacy.test.js.map +1 -0
- package/lib-es/tokens.d.ts +20 -50
- package/lib-es/tokens.d.ts.map +1 -1
- package/lib-es/tokens.js +27 -475
- package/lib-es/tokens.js.map +1 -1
- package/lib-es/tokens.test.js +2 -1
- package/lib-es/tokens.test.js.map +1 -1
- package/package.json +3 -5
- package/src/abandonseed.ts +4 -1
- package/src/api-token-converter.ts +2 -2
- package/src/crypto-assets-importer/importers/sui/index.ts +6 -2
- package/src/crypto-assets-importer/importers/sui/sui.test.ts +15 -3
- package/src/currencies.ts +92 -10
- package/src/data/sui.ts +2 -1
- package/src/legacy/legacy-data.ts +119 -0
- package/src/legacy/legacy-state.ts +10 -0
- package/src/legacy/legacy-utils.ts +571 -0
- package/src/legacy/legacy.test.ts +580 -0
- package/src/tokens.test.ts +1 -1
- package/src/tokens.ts +67 -588
package/src/tokens.ts
CHANGED
|
@@ -1,179 +1,61 @@
|
|
|
1
|
-
import type { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
|
-
import cardanoNativeTokens, { CardanoNativeToken } from "./data/cardanoNative";
|
|
3
|
-
import { findCryptoCurrencyById, getCryptoCurrencyById } from "./currencies";
|
|
4
|
-
import jettonTokens, { TonJettonToken } from "./data/ton-jetton";
|
|
5
|
-
import { tokens as sepoliaTokens } from "./data/evm/11155111";
|
|
6
|
-
import stellarTokens, { StellarToken } from "./data/stellar";
|
|
7
|
-
import hederaTokens, { HederaToken } from "./data/hedera";
|
|
8
|
-
import vechainTokens, { Vip180Token } from "./data/vip180";
|
|
9
|
-
import esdttokens, { MultiversXESDTToken } from "./data/esdt";
|
|
10
|
-
import asatokens, { AlgorandASAToken } from "./data/asa";
|
|
11
|
-
import { tokens as polygonTokens } from "./data/evm/137";
|
|
12
|
-
import { tokens as sonicTokens } from "./data/evm/146";
|
|
13
|
-
import { tokens as coreTokens } from "./data/evm/1116";
|
|
14
|
-
import trc10tokens, { TRC10Token } from "./data/trc10";
|
|
15
|
-
import trc20tokens, { TRC20Token } from "./data/trc20";
|
|
16
|
-
import { tokens as mainnetTokens } from "./data/evm/1";
|
|
17
|
-
import { tokens as bnbTokens } from "./data/evm/56";
|
|
18
|
-
import { tokens as celoTokens } from "./data/evm/42220";
|
|
19
|
-
import filecoinTokens from "./data/filecoin-erc20";
|
|
20
|
-
import spltokens, { SPLToken } from "./data/spl";
|
|
21
|
-
import aptCoinTokens, { AptosToken as AptosCoinToken } from "./data/apt_coin";
|
|
22
|
-
import aptFATokens, { AptosToken as AptosFAToken } from "./data/apt_fungible_asset";
|
|
23
|
-
import suitokens, { SuiToken } from "./data/sui";
|
|
24
|
-
import { ERC20Token } from "./types";
|
|
25
|
-
import { getEnv } from "@ledgerhq/live-env";
|
|
26
|
-
|
|
27
|
-
const emptyArray = [];
|
|
28
|
-
const tokensArray: TokenCurrency[] = [];
|
|
29
|
-
const tokensArrayWithDelisted: TokenCurrency[] = [];
|
|
30
|
-
const tokensByCryptoCurrency: Record<string, TokenCurrency[]> = {};
|
|
31
|
-
const tokensByCryptoCurrencyWithDelisted: Record<string, TokenCurrency[]> = {};
|
|
32
|
-
const tokensById: Record<string, TokenCurrency> = {};
|
|
33
|
-
const tokensByTicker: Record<string, TokenCurrency> = {};
|
|
34
|
-
const tokensByAddress: Record<string, TokenCurrency> = {};
|
|
35
|
-
const tokensByCurrencyAddress: Record<string, TokenCurrency> = {};
|
|
36
|
-
const tokenListHashes = new Set();
|
|
37
|
-
|
|
38
|
-
// Ethereum mainnet tokens
|
|
39
|
-
addTokens(mainnetTokens.map(convertERC20));
|
|
40
|
-
// Ethereum Sepolia testnet tokens
|
|
41
|
-
addTokens(sepoliaTokens.map(convertERC20));
|
|
42
|
-
// Polygon tokens
|
|
43
|
-
addTokens(polygonTokens.map(convertERC20));
|
|
44
|
-
// Hedera tokens
|
|
45
|
-
addTokens(hederaTokens.map(convertHederaTokens));
|
|
46
|
-
// Binance Smart Chain tokens
|
|
47
|
-
addTokens(bnbTokens.map(convertERC20));
|
|
48
|
-
// Tron tokens
|
|
49
|
-
addTokens(trc10tokens.map(convertTRONTokens("trc10")));
|
|
50
|
-
addTokens(trc20tokens.map(convertTRONTokens("trc20")));
|
|
51
|
-
// Algoland tokens
|
|
52
|
-
addTokens(asatokens.map(convertAlgorandASATokens));
|
|
53
|
-
// MultiversX tokens
|
|
54
|
-
addTokens(esdttokens.map(convertMultiversXESDTTokens));
|
|
55
|
-
// Cardano tokens
|
|
56
|
-
addTokens(cardanoNativeTokens.map(convertCardanoNativeTokens));
|
|
57
|
-
// Stellar tokens
|
|
58
|
-
addTokens(stellarTokens.map(convertStellarTokens));
|
|
59
|
-
// VeChain tokens
|
|
60
|
-
addTokens(vechainTokens.map(convertVechainToken));
|
|
61
|
-
// Ton tokens
|
|
62
|
-
addTokens(jettonTokens.map(convertJettonToken));
|
|
63
|
-
// Filecoin tokens
|
|
64
|
-
addTokens(filecoinTokens.map(convertERC20));
|
|
65
|
-
// Solana tokens
|
|
66
|
-
addTokens(spltokens.map(convertSplTokens));
|
|
67
|
-
// Sonic
|
|
68
|
-
addTokens(sonicTokens.map(convertERC20));
|
|
69
|
-
// Core
|
|
70
|
-
addTokens(coreTokens.map(convertERC20));
|
|
71
|
-
// Celo
|
|
72
|
-
addTokens(celoTokens.map(convertERC20));
|
|
73
|
-
|
|
74
|
-
if (getEnv("SUI_ENABLE_TOKENS")) {
|
|
75
|
-
// Sui tokens
|
|
76
|
-
addTokens(suitokens.map(convertSuiTokens));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (getEnv("APTOS_ENABLE_TOKENS")) {
|
|
80
|
-
// Aptos Legacy Coin tokens
|
|
81
|
-
addTokens(aptCoinTokens.map(convertAptCoinTokens));
|
|
82
|
-
// Aptos fungible assets tokens
|
|
83
|
-
addTokens(aptFATokens.map(convertAptFaTokens));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
type TokensListOptions = {
|
|
87
|
-
withDelisted: boolean;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const defaultTokenListOptions: TokensListOptions = {
|
|
91
|
-
withDelisted: false,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export function createTokenHash(token: TokenCurrency): string {
|
|
95
|
-
return token
|
|
96
|
-
? `${token.id}${token.contractAddress}${token.delisted}${token.ticker}${token.ledgerSignature}`
|
|
97
|
-
: "";
|
|
98
|
-
}
|
|
99
|
-
|
|
100
1
|
/**
|
|
101
|
-
*
|
|
102
|
-
* @param obj
|
|
2
|
+
* BEWARE: this file will progressively disappear when https://github.com/LedgerHQ/ledger-live/pull/11905 lands
|
|
103
3
|
*/
|
|
104
|
-
const __clearObject = (obj: Record<string, TokenCurrency | TokenCurrency[]>): void => {
|
|
105
|
-
for (const key in obj) {
|
|
106
|
-
delete obj[key];
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* Only for jest purpose, clear all the init list
|
|
111
|
-
*/
|
|
112
|
-
export function __clearAllLists(): void {
|
|
113
|
-
tokensArray.length = 0;
|
|
114
|
-
tokensArrayWithDelisted.length = 0;
|
|
115
|
-
__clearObject(tokensByCryptoCurrency);
|
|
116
|
-
__clearObject(tokensByCryptoCurrencyWithDelisted);
|
|
117
|
-
__clearObject(tokensById);
|
|
118
|
-
__clearObject(tokensByTicker);
|
|
119
|
-
__clearObject(tokensByAddress);
|
|
120
|
-
__clearObject(tokensByCurrencyAddress);
|
|
121
|
-
tokenListHashes.clear();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
*
|
|
126
|
-
*/
|
|
127
|
-
export function listTokens(options?: Partial<TokensListOptions>): TokenCurrency[] {
|
|
128
|
-
const { withDelisted } = { ...defaultTokenListOptions, ...options };
|
|
129
|
-
return withDelisted ? tokensArrayWithDelisted : tokensArray;
|
|
130
|
-
}
|
|
131
4
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
5
|
+
import type { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
6
|
+
import {
|
|
7
|
+
addTokens,
|
|
8
|
+
listTokensLegacy,
|
|
9
|
+
listTokensForCryptoCurrencyLegacy,
|
|
10
|
+
type TokensListOptions,
|
|
11
|
+
__clearAllLists,
|
|
12
|
+
convertERC20,
|
|
13
|
+
convertAlgorandASATokens,
|
|
14
|
+
convertVechainToken,
|
|
15
|
+
convertTRONTokens,
|
|
16
|
+
convertMultiversXESDTTokens,
|
|
17
|
+
convertCardanoNativeTokens,
|
|
18
|
+
convertStellarTokens,
|
|
19
|
+
convertJettonToken,
|
|
20
|
+
convertSplTokens,
|
|
21
|
+
convertSuiTokens,
|
|
22
|
+
convertAptCoinTokens,
|
|
23
|
+
convertAptFaTokens,
|
|
24
|
+
convertHederaTokens,
|
|
25
|
+
} from "./legacy/legacy-utils";
|
|
26
|
+
import { tokensByCurrencyAddress, tokensById } from "./legacy/legacy-state";
|
|
27
|
+
import { initializeLegacyTokens } from "./legacy/legacy-data";
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
addTokens,
|
|
31
|
+
convertERC20,
|
|
32
|
+
convertAlgorandASATokens,
|
|
33
|
+
convertVechainToken,
|
|
34
|
+
convertTRONTokens,
|
|
35
|
+
convertMultiversXESDTTokens,
|
|
36
|
+
convertCardanoNativeTokens,
|
|
37
|
+
convertStellarTokens,
|
|
38
|
+
convertJettonToken,
|
|
39
|
+
convertSplTokens,
|
|
40
|
+
convertSuiTokens,
|
|
41
|
+
convertAptCoinTokens,
|
|
42
|
+
convertAptFaTokens,
|
|
43
|
+
convertHederaTokens,
|
|
44
|
+
__clearAllLists,
|
|
45
|
+
};
|
|
153
46
|
|
|
154
|
-
|
|
155
|
-
*
|
|
156
|
-
*/
|
|
157
|
-
export function findTokenByTicker(ticker: string): TokenCurrency | undefined {
|
|
158
|
-
return tokensByTicker[ticker];
|
|
159
|
-
}
|
|
47
|
+
initializeLegacyTokens(addTokens);
|
|
160
48
|
|
|
161
49
|
/**
|
|
162
|
-
*
|
|
50
|
+
* @deprecated Please do `await getCryptoAssetsStore().findTokenById(id)` instead to anticipate https://github.com/LedgerHQ/ledger-live/pull/11905
|
|
163
51
|
*/
|
|
164
52
|
export function findTokenById(id: string): TokenCurrency | undefined {
|
|
165
53
|
return tokensById[id];
|
|
166
54
|
}
|
|
167
55
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
deprecatedDisplayed = true;
|
|
172
|
-
console.warn("findTokenByAddress is deprecated. use findTokenByAddressInCurrency");
|
|
173
|
-
}
|
|
174
|
-
return tokensByAddress[address.toLowerCase()];
|
|
175
|
-
}
|
|
176
|
-
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated Please do `await getCryptoAssetsStore().findTokenByAddress(address, currencyId)` instead to anticipate https://github.com/LedgerHQ/ledger-live/pull/11905
|
|
58
|
+
*/
|
|
177
59
|
export function findTokenByAddressInCurrency(
|
|
178
60
|
address: string,
|
|
179
61
|
currencyId: string,
|
|
@@ -182,12 +64,12 @@ export function findTokenByAddressInCurrency(
|
|
|
182
64
|
}
|
|
183
65
|
|
|
184
66
|
/**
|
|
185
|
-
*
|
|
67
|
+
* @deprecated This function will be removed when https://github.com/LedgerHQ/ledger-live/pull/11905 lands
|
|
186
68
|
*/
|
|
187
69
|
export const hasTokenId = (id: string): boolean => id in tokensById;
|
|
188
70
|
|
|
189
71
|
/**
|
|
190
|
-
*
|
|
72
|
+
* @deprecated Please use `await getCryptoAssetsStore().findTokenById(id)` instead to anticipate https://github.com/LedgerHQ/ledger-live/pull/11905
|
|
191
73
|
*/
|
|
192
74
|
export function getTokenById(id: string): TokenCurrency {
|
|
193
75
|
const currency = findTokenById(id);
|
|
@@ -199,431 +81,28 @@ export function getTokenById(id: string): TokenCurrency {
|
|
|
199
81
|
return currency;
|
|
200
82
|
}
|
|
201
83
|
|
|
202
|
-
function removeTokenFromArray(array: TokenCurrency[], tokenId: string) {
|
|
203
|
-
if (array && array.length > 0) {
|
|
204
|
-
const index = array.findIndex(currentToken => currentToken && currentToken.id === tokenId);
|
|
205
|
-
if (index === -1) return array;
|
|
206
|
-
return array.splice(index, 1);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function removeTokenFromRecord(record: Record<string, TokenCurrency>, key: string) {
|
|
211
|
-
tokenListHashes.delete(record[key]);
|
|
212
|
-
delete record[key];
|
|
213
|
-
}
|
|
214
|
-
|
|
215
84
|
/**
|
|
216
|
-
*
|
|
217
|
-
*
|
|
85
|
+
* @deprecated This function is deprecated. See https://ledgerhq.atlassian.net/browse/LIVE-21646
|
|
86
|
+
* Tokens will no longer be listable as we moved to DaDa API when possible / or CAL API directly.
|
|
218
87
|
*/
|
|
219
|
-
function
|
|
220
|
-
|
|
221
|
-
const lowCaseContract = contractAddress.toLowerCase();
|
|
222
|
-
|
|
223
|
-
removeTokenFromRecord(tokensById, id);
|
|
224
|
-
removeTokenFromRecord(tokensByCurrencyAddress, parentCurrency.id + ":" + lowCaseContract);
|
|
225
|
-
removeTokenFromRecord(tokensByAddress, lowCaseContract);
|
|
226
|
-
removeTokenFromRecord(tokensByTicker, ticker);
|
|
227
|
-
removeTokenFromArray(tokensArray, id);
|
|
228
|
-
removeTokenFromArray(tokensArrayWithDelisted, id);
|
|
229
|
-
removeTokenFromArray(tokensByCryptoCurrency[parentCurrency.id], id);
|
|
230
|
-
removeTokenFromArray(tokensByCryptoCurrencyWithDelisted[parentCurrency.id], id);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export function addTokens(list: (TokenCurrency | undefined)[]): void {
|
|
234
|
-
list.forEach(token => {
|
|
235
|
-
if (!token) return;
|
|
236
|
-
const tokenHash = createTokenHash(token);
|
|
237
|
-
if (tokenListHashes.has(tokenHash)) return;
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* We clean all the reference of an existing token, if an hash doesn't match.
|
|
241
|
-
* Like this we can update any change from a already added token coming from Dynamic CAL
|
|
242
|
-
* and maintain it up to date without having to release a new version of LLD or LLM
|
|
243
|
-
*/
|
|
244
|
-
const { id, contractAddress, parentCurrency, delisted, ticker } = token;
|
|
245
|
-
if (tokensById[id]) removeTokenFromAllLists(token);
|
|
246
|
-
const lowCaseContract = contractAddress.toLowerCase();
|
|
247
|
-
|
|
248
|
-
if (!delisted) tokensArray.push(token);
|
|
249
|
-
tokensArrayWithDelisted.push(token);
|
|
250
|
-
tokensById[id] = token;
|
|
251
|
-
|
|
252
|
-
if (!tokensByTicker[ticker]) {
|
|
253
|
-
tokensByTicker[ticker] = token;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
tokensByAddress[lowCaseContract] = token;
|
|
257
|
-
tokensByCurrencyAddress[parentCurrency.id + ":" + lowCaseContract] = token;
|
|
258
|
-
|
|
259
|
-
if (!(parentCurrency.id in tokensByCryptoCurrency)) {
|
|
260
|
-
tokensByCryptoCurrency[parentCurrency.id] = [];
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (!(parentCurrency.id in tokensByCryptoCurrencyWithDelisted)) {
|
|
264
|
-
tokensByCryptoCurrencyWithDelisted[parentCurrency.id] = [];
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (!delisted) tokensByCryptoCurrency[parentCurrency.id].push(token);
|
|
268
|
-
tokensByCryptoCurrencyWithDelisted[parentCurrency.id].push(token);
|
|
269
|
-
|
|
270
|
-
tokenListHashes.add(tokenHash);
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
export function convertERC20([
|
|
275
|
-
parentCurrencyId,
|
|
276
|
-
token,
|
|
277
|
-
ticker,
|
|
278
|
-
magnitude,
|
|
279
|
-
name,
|
|
280
|
-
ledgerSignature,
|
|
281
|
-
contractAddress,
|
|
282
|
-
disableCountervalue,
|
|
283
|
-
delisted,
|
|
284
|
-
]: ERC20Token): TokenCurrency | undefined {
|
|
285
|
-
const parentCurrency = findCryptoCurrencyById(parentCurrencyId);
|
|
286
|
-
|
|
287
|
-
if (!parentCurrency) {
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const tokenType = parentCurrencyId === "bsc" ? "bep20" : "erc20";
|
|
292
|
-
|
|
293
|
-
return {
|
|
294
|
-
type: "TokenCurrency",
|
|
295
|
-
id: `${parentCurrencyId}/${tokenType}/${token}`,
|
|
296
|
-
ledgerSignature,
|
|
297
|
-
contractAddress,
|
|
298
|
-
parentCurrency,
|
|
299
|
-
tokenType,
|
|
300
|
-
name,
|
|
301
|
-
ticker,
|
|
302
|
-
delisted,
|
|
303
|
-
disableCountervalue: !!parentCurrency.isTestnetFor || !!disableCountervalue,
|
|
304
|
-
units: [
|
|
305
|
-
{
|
|
306
|
-
name,
|
|
307
|
-
code: ticker,
|
|
308
|
-
magnitude,
|
|
309
|
-
},
|
|
310
|
-
],
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
export function convertAlgorandASATokens([
|
|
315
|
-
id,
|
|
316
|
-
abbr,
|
|
317
|
-
name,
|
|
318
|
-
contractAddress,
|
|
319
|
-
precision,
|
|
320
|
-
]: AlgorandASAToken): TokenCurrency {
|
|
321
|
-
const parentCurrency = getCryptoCurrencyById("algorand");
|
|
322
|
-
|
|
323
|
-
return {
|
|
324
|
-
type: "TokenCurrency",
|
|
325
|
-
id: `algorand/asa/${id}`,
|
|
326
|
-
contractAddress,
|
|
327
|
-
parentCurrency,
|
|
328
|
-
tokenType: "asa",
|
|
329
|
-
name,
|
|
330
|
-
ticker: abbr,
|
|
331
|
-
disableCountervalue: false,
|
|
332
|
-
units: [
|
|
333
|
-
{
|
|
334
|
-
name,
|
|
335
|
-
code: abbr,
|
|
336
|
-
magnitude: precision,
|
|
337
|
-
},
|
|
338
|
-
],
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
export function convertVechainToken([
|
|
343
|
-
tokenIdenfitier,
|
|
344
|
-
ticker,
|
|
345
|
-
name,
|
|
346
|
-
contractAddress,
|
|
347
|
-
precision,
|
|
348
|
-
]: Vip180Token): TokenCurrency {
|
|
349
|
-
return {
|
|
350
|
-
type: "TokenCurrency",
|
|
351
|
-
id: `vechain/vip180/${tokenIdenfitier}`,
|
|
352
|
-
contractAddress: contractAddress,
|
|
353
|
-
parentCurrency: getCryptoCurrencyById("vechain"),
|
|
354
|
-
tokenType: "vip180",
|
|
355
|
-
name,
|
|
356
|
-
ticker,
|
|
357
|
-
disableCountervalue: false,
|
|
358
|
-
units: [
|
|
359
|
-
{
|
|
360
|
-
name,
|
|
361
|
-
code: ticker,
|
|
362
|
-
magnitude: precision,
|
|
363
|
-
},
|
|
364
|
-
],
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
export function convertTRONTokens(type: "trc10" | "trc20") {
|
|
369
|
-
return ([id, abbr, name, contractAddress, precision, delisted, ledgerSignature]:
|
|
370
|
-
| TRC10Token
|
|
371
|
-
| TRC20Token): TokenCurrency => {
|
|
372
|
-
const parentCurrency = getCryptoCurrencyById("tron");
|
|
373
|
-
|
|
374
|
-
return {
|
|
375
|
-
type: "TokenCurrency",
|
|
376
|
-
id: `tron/${type}/${id}`,
|
|
377
|
-
contractAddress,
|
|
378
|
-
parentCurrency,
|
|
379
|
-
tokenType: type,
|
|
380
|
-
name,
|
|
381
|
-
ticker: abbr,
|
|
382
|
-
delisted,
|
|
383
|
-
disableCountervalue: false,
|
|
384
|
-
ledgerSignature,
|
|
385
|
-
units: [
|
|
386
|
-
{
|
|
387
|
-
name,
|
|
388
|
-
code: abbr,
|
|
389
|
-
magnitude: precision,
|
|
390
|
-
},
|
|
391
|
-
],
|
|
392
|
-
};
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
export function convertMultiversXESDTTokens([
|
|
397
|
-
ticker,
|
|
398
|
-
identifier,
|
|
399
|
-
decimals,
|
|
400
|
-
signature,
|
|
401
|
-
name,
|
|
402
|
-
]: MultiversXESDTToken): TokenCurrency {
|
|
403
|
-
const MULTIVERSX_ESDT_CONTRACT = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u";
|
|
404
|
-
// const parentCurrency = getCryptoCurrencyById("multiversx");
|
|
405
|
-
const parentCurrency = getCryptoCurrencyById("elrond");
|
|
406
|
-
|
|
407
|
-
return {
|
|
408
|
-
type: "TokenCurrency",
|
|
409
|
-
id: `multiversx/esdt/${identifier}`,
|
|
410
|
-
contractAddress: MULTIVERSX_ESDT_CONTRACT,
|
|
411
|
-
ledgerSignature: signature,
|
|
412
|
-
parentCurrency,
|
|
413
|
-
tokenType: "esdt",
|
|
414
|
-
disableCountervalue: false,
|
|
415
|
-
name,
|
|
416
|
-
ticker,
|
|
417
|
-
units: [
|
|
418
|
-
{
|
|
419
|
-
name,
|
|
420
|
-
code: name,
|
|
421
|
-
magnitude: decimals,
|
|
422
|
-
},
|
|
423
|
-
],
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
export function convertSplTokens([
|
|
428
|
-
id,
|
|
429
|
-
network,
|
|
430
|
-
name,
|
|
431
|
-
symbol,
|
|
432
|
-
address,
|
|
433
|
-
decimals,
|
|
434
|
-
]: SPLToken): TokenCurrency {
|
|
435
|
-
return {
|
|
436
|
-
type: "TokenCurrency",
|
|
437
|
-
id,
|
|
438
|
-
contractAddress: address,
|
|
439
|
-
parentCurrency: getCryptoCurrencyById(network),
|
|
440
|
-
name,
|
|
441
|
-
tokenType: "spl",
|
|
442
|
-
ticker: symbol,
|
|
443
|
-
disableCountervalue: false,
|
|
444
|
-
units: [
|
|
445
|
-
{
|
|
446
|
-
name,
|
|
447
|
-
code: symbol,
|
|
448
|
-
magnitude: decimals,
|
|
449
|
-
},
|
|
450
|
-
],
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
function convertAptosTokens(
|
|
454
|
-
tokenType: "coin" | "fungible_asset",
|
|
455
|
-
[id, ticker, name, address, decimals, delisted]: AptosCoinToken | AptosFAToken,
|
|
456
|
-
): TokenCurrency {
|
|
457
|
-
return {
|
|
458
|
-
type: "TokenCurrency",
|
|
459
|
-
id,
|
|
460
|
-
contractAddress: address,
|
|
461
|
-
parentCurrency: getCryptoCurrencyById("aptos"),
|
|
462
|
-
name,
|
|
463
|
-
tokenType,
|
|
464
|
-
ticker,
|
|
465
|
-
disableCountervalue: false,
|
|
466
|
-
delisted,
|
|
467
|
-
units: [
|
|
468
|
-
{
|
|
469
|
-
name,
|
|
470
|
-
code: ticker,
|
|
471
|
-
magnitude: decimals,
|
|
472
|
-
},
|
|
473
|
-
],
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
export function convertAptCoinTokens(token: AptosCoinToken): TokenCurrency {
|
|
478
|
-
return convertAptosTokens("coin", token);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
export function convertAptFaTokens(token: AptosFAToken): TokenCurrency {
|
|
482
|
-
return convertAptosTokens("fungible_asset", token);
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
export function convertSuiTokens([id, name, ticker, address, decimals]: SuiToken): TokenCurrency {
|
|
486
|
-
return {
|
|
487
|
-
type: "TokenCurrency",
|
|
488
|
-
id,
|
|
489
|
-
contractAddress: address,
|
|
490
|
-
parentCurrency: getCryptoCurrencyById("sui"),
|
|
491
|
-
name,
|
|
492
|
-
tokenType: "sui",
|
|
493
|
-
ticker,
|
|
494
|
-
disableCountervalue: false,
|
|
495
|
-
units: [
|
|
496
|
-
{
|
|
497
|
-
name,
|
|
498
|
-
code: ticker,
|
|
499
|
-
magnitude: decimals,
|
|
500
|
-
},
|
|
501
|
-
],
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
function convertHederaTokens([
|
|
506
|
-
id,
|
|
507
|
-
tokenId,
|
|
508
|
-
name,
|
|
509
|
-
ticker,
|
|
510
|
-
network,
|
|
511
|
-
decimals,
|
|
512
|
-
delisted,
|
|
513
|
-
]: HederaToken): TokenCurrency {
|
|
514
|
-
return {
|
|
515
|
-
type: "TokenCurrency",
|
|
516
|
-
id,
|
|
517
|
-
contractAddress: tokenId,
|
|
518
|
-
parentCurrency: getCryptoCurrencyById(network),
|
|
519
|
-
tokenType: "hts",
|
|
520
|
-
name,
|
|
521
|
-
ticker,
|
|
522
|
-
delisted,
|
|
523
|
-
disableCountervalue: false,
|
|
524
|
-
units: [
|
|
525
|
-
{
|
|
526
|
-
name,
|
|
527
|
-
code: ticker,
|
|
528
|
-
magnitude: decimals,
|
|
529
|
-
},
|
|
530
|
-
],
|
|
531
|
-
};
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
export function convertCardanoNativeTokens([
|
|
535
|
-
parentCurrencyId,
|
|
536
|
-
policyId,
|
|
537
|
-
assetName,
|
|
538
|
-
name,
|
|
539
|
-
ticker,
|
|
540
|
-
decimals,
|
|
541
|
-
delisted,
|
|
542
|
-
]: CardanoNativeToken): TokenCurrency | undefined {
|
|
543
|
-
const assetId = policyId + assetName;
|
|
544
|
-
|
|
545
|
-
const parentCurrency = getCryptoCurrencyById(parentCurrencyId);
|
|
546
|
-
|
|
547
|
-
if (!parentCurrency) {
|
|
548
|
-
return;
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
return {
|
|
552
|
-
type: "TokenCurrency",
|
|
553
|
-
id: `${parentCurrencyId}/native/${assetId}`,
|
|
554
|
-
// Tracking and accounting of native tokens is natively supported by cardano ledger.
|
|
555
|
-
// As there's no contract for native tokens, using unique assetId in place of contractAddress
|
|
556
|
-
contractAddress: assetId,
|
|
557
|
-
parentCurrency,
|
|
558
|
-
tokenType: "native",
|
|
559
|
-
name,
|
|
560
|
-
ticker,
|
|
561
|
-
delisted,
|
|
562
|
-
disableCountervalue: false,
|
|
563
|
-
units: [
|
|
564
|
-
{
|
|
565
|
-
name,
|
|
566
|
-
code: ticker,
|
|
567
|
-
magnitude: decimals,
|
|
568
|
-
},
|
|
569
|
-
],
|
|
570
|
-
};
|
|
88
|
+
export function listTokens(options?: Partial<TokensListOptions>): TokenCurrency[] {
|
|
89
|
+
return listTokensLegacy(options);
|
|
571
90
|
}
|
|
572
91
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
// FIXME: to be discussed with CAL service as values are Uppercase IRL
|
|
583
|
-
return {
|
|
584
|
-
type: "TokenCurrency",
|
|
585
|
-
id: `stellar/asset/${assetCode.toUpperCase()}:${assetIssuer.toUpperCase()}`,
|
|
586
|
-
contractAddress: assetIssuer.toUpperCase(),
|
|
587
|
-
parentCurrency,
|
|
588
|
-
tokenType: assetType,
|
|
589
|
-
name,
|
|
590
|
-
ticker: assetCode,
|
|
591
|
-
disableCountervalue: false,
|
|
592
|
-
units: [
|
|
593
|
-
{
|
|
594
|
-
name,
|
|
595
|
-
code: assetCode,
|
|
596
|
-
magnitude: precision,
|
|
597
|
-
},
|
|
598
|
-
],
|
|
599
|
-
};
|
|
92
|
+
/**
|
|
93
|
+
* @deprecated This function is deprecated. See https://ledgerhq.atlassian.net/browse/LIVE-21646
|
|
94
|
+
* Tokens will no longer be listable as we moved to DaDa API when possible / or CAL API directly.
|
|
95
|
+
*/
|
|
96
|
+
export function listTokensForCryptoCurrency(
|
|
97
|
+
currency: CryptoCurrency,
|
|
98
|
+
options?: Partial<TokensListOptions>,
|
|
99
|
+
): TokenCurrency[] {
|
|
100
|
+
return listTokensForCryptoCurrencyLegacy(currency, options);
|
|
600
101
|
}
|
|
601
102
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
if (!parentCurrency) {
|
|
608
|
-
return;
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
return {
|
|
612
|
-
type: "TokenCurrency",
|
|
613
|
-
id: "ton/jetton/" + address.toLocaleLowerCase(),
|
|
614
|
-
contractAddress: address,
|
|
615
|
-
parentCurrency,
|
|
616
|
-
tokenType: "jetton",
|
|
617
|
-
name,
|
|
618
|
-
ticker,
|
|
619
|
-
delisted,
|
|
620
|
-
disableCountervalue: false,
|
|
621
|
-
units: [
|
|
622
|
-
{
|
|
623
|
-
name,
|
|
624
|
-
code: ticker,
|
|
625
|
-
magnitude,
|
|
626
|
-
},
|
|
627
|
-
],
|
|
628
|
-
};
|
|
103
|
+
/**
|
|
104
|
+
* @deprecated Prefer using currency.tokenTypes directly.
|
|
105
|
+
*/
|
|
106
|
+
export function listTokenTypesForCryptoCurrency(currency: CryptoCurrency): string[] {
|
|
107
|
+
return currency.tokenTypes || [];
|
|
629
108
|
}
|