@ledgerhq/cryptoassets 13.30.0 → 13.31.0-nightly.0
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/CHANGELOG.md +8 -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 +14 -14
- package/lib/api-token-converter.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/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 +11 -0
- package/lib/legacy/legacy-state.d.ts.map +1 -0
- package/lib/legacy/legacy-state.js +14 -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 +455 -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 +470 -0
- package/lib/legacy/legacy.test.js.map +1 -0
- package/lib/tokens.d.ts +27 -49
- package/lib/tokens.d.ts.map +1 -1
- package/lib/tokens.js +55 -490
- 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 +1 -1
- package/lib-es/api-token-converter.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/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 +11 -0
- package/lib-es/legacy/legacy-state.d.ts.map +1 -0
- package/lib-es/legacy/legacy-state.js +11 -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 +434 -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 +468 -0
- package/lib-es/legacy/legacy.test.js.map +1 -0
- package/lib-es/tokens.d.ts +27 -49
- package/lib-es/tokens.d.ts.map +1 -1
- package/lib-es/tokens.js +31 -462
- 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 +2 -4
- package/src/abandonseed.ts +4 -1
- package/src/api-token-converter.ts +1 -1
- package/src/currencies.ts +92 -10
- package/src/legacy/legacy-data.ts +119 -0
- package/src/legacy/legacy-state.ts +12 -0
- package/src/legacy/legacy-utils.ts +574 -0
- package/src/legacy/legacy.test.ts +586 -0
- package/src/tokens.test.ts +1 -1
- package/src/tokens.ts +76 -573
package/src/tokens.ts
CHANGED
|
@@ -1,171 +1,74 @@
|
|
|
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
|
-
|
|
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 {
|
|
27
|
+
tokensByAddress,
|
|
28
|
+
tokensByCurrencyAddress,
|
|
29
|
+
tokensById,
|
|
30
|
+
tokensByTicker,
|
|
31
|
+
} from "./legacy/legacy-state";
|
|
32
|
+
import { initializeLegacyTokens } from "./legacy/legacy-data";
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
addTokens,
|
|
36
|
+
convertERC20,
|
|
37
|
+
convertAlgorandASATokens,
|
|
38
|
+
convertVechainToken,
|
|
39
|
+
convertTRONTokens,
|
|
40
|
+
convertMultiversXESDTTokens,
|
|
41
|
+
convertCardanoNativeTokens,
|
|
42
|
+
convertStellarTokens,
|
|
43
|
+
convertJettonToken,
|
|
44
|
+
convertSplTokens,
|
|
45
|
+
convertSuiTokens,
|
|
46
|
+
convertAptCoinTokens,
|
|
47
|
+
convertAptFaTokens,
|
|
48
|
+
convertHederaTokens,
|
|
49
|
+
__clearAllLists,
|
|
50
|
+
};
|
|
146
51
|
|
|
147
|
-
|
|
148
|
-
*
|
|
149
|
-
*/
|
|
150
|
-
export function listTokenTypesForCryptoCurrency(currency: CryptoCurrency): string[] {
|
|
151
|
-
return currency.tokenTypes || [];
|
|
152
|
-
}
|
|
52
|
+
initializeLegacyTokens(addTokens);
|
|
153
53
|
|
|
154
54
|
/**
|
|
155
|
-
*
|
|
55
|
+
* @deprecated this function must not be used and will be replaced by `getCryptoAssetsStore().findTokenById(id)` in https://github.com/LedgerHQ/ledger-live/pull/11905
|
|
156
56
|
*/
|
|
157
57
|
export function findTokenByTicker(ticker: string): TokenCurrency | undefined {
|
|
158
58
|
return tokensByTicker[ticker];
|
|
159
59
|
}
|
|
160
60
|
|
|
161
61
|
/**
|
|
162
|
-
*
|
|
62
|
+
* @deprecated Please do `await getCryptoAssetsStore().findTokenById(id)` instead to anticipate https://github.com/LedgerHQ/ledger-live/pull/11905
|
|
163
63
|
*/
|
|
164
64
|
export function findTokenById(id: string): TokenCurrency | undefined {
|
|
165
65
|
return tokensById[id];
|
|
166
66
|
}
|
|
167
67
|
|
|
168
68
|
let deprecatedDisplayed = false;
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated This function will be removed when https://github.com/LedgerHQ/ledger-live/pull/11905 lands
|
|
71
|
+
*/
|
|
169
72
|
export function findTokenByAddress(address: string): TokenCurrency | undefined {
|
|
170
73
|
if (!deprecatedDisplayed) {
|
|
171
74
|
deprecatedDisplayed = true;
|
|
@@ -174,6 +77,9 @@ export function findTokenByAddress(address: string): TokenCurrency | undefined {
|
|
|
174
77
|
return tokensByAddress[address.toLowerCase()];
|
|
175
78
|
}
|
|
176
79
|
|
|
80
|
+
/**
|
|
81
|
+
* @deprecated Please do `await getCryptoAssetsStore().findTokenByAddress(address, currencyId)` instead to anticipate https://github.com/LedgerHQ/ledger-live/pull/11905
|
|
82
|
+
*/
|
|
177
83
|
export function findTokenByAddressInCurrency(
|
|
178
84
|
address: string,
|
|
179
85
|
currencyId: string,
|
|
@@ -182,12 +88,12 @@ export function findTokenByAddressInCurrency(
|
|
|
182
88
|
}
|
|
183
89
|
|
|
184
90
|
/**
|
|
185
|
-
*
|
|
91
|
+
* @deprecated This function will be removed when https://github.com/LedgerHQ/ledger-live/pull/11905 lands
|
|
186
92
|
*/
|
|
187
93
|
export const hasTokenId = (id: string): boolean => id in tokensById;
|
|
188
94
|
|
|
189
95
|
/**
|
|
190
|
-
*
|
|
96
|
+
* @deprecated Please use `await getCryptoAssetsStore().findTokenById(id)` instead to anticipate https://github.com/LedgerHQ/ledger-live/pull/11905
|
|
191
97
|
*/
|
|
192
98
|
export function getTokenById(id: string): TokenCurrency {
|
|
193
99
|
const currency = findTokenById(id);
|
|
@@ -199,431 +105,28 @@ export function getTokenById(id: string): TokenCurrency {
|
|
|
199
105
|
return currency;
|
|
200
106
|
}
|
|
201
107
|
|
|
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
108
|
/**
|
|
216
|
-
*
|
|
217
|
-
*
|
|
109
|
+
* @deprecated This function is deprecated. See https://ledgerhq.atlassian.net/browse/LIVE-21646
|
|
110
|
+
* Tokens will no longer be listable as we moved to DaDa API when possible / or CAL API directly.
|
|
218
111
|
*/
|
|
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
|
-
};
|
|
112
|
+
export function listTokens(options?: Partial<TokensListOptions>): TokenCurrency[] {
|
|
113
|
+
return listTokensLegacy(options);
|
|
571
114
|
}
|
|
572
115
|
|
|
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
|
-
};
|
|
116
|
+
/**
|
|
117
|
+
* @deprecated This function is deprecated. See https://ledgerhq.atlassian.net/browse/LIVE-21646
|
|
118
|
+
* Tokens will no longer be listable as we moved to DaDa API when possible / or CAL API directly.
|
|
119
|
+
*/
|
|
120
|
+
export function listTokensForCryptoCurrency(
|
|
121
|
+
currency: CryptoCurrency,
|
|
122
|
+
options?: Partial<TokensListOptions>,
|
|
123
|
+
): TokenCurrency[] {
|
|
124
|
+
return listTokensForCryptoCurrencyLegacy(currency, options);
|
|
600
125
|
}
|
|
601
126
|
|
|
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
|
-
};
|
|
127
|
+
/**
|
|
128
|
+
* @deprecated Prefer using currency.tokenTypes directly.
|
|
129
|
+
*/
|
|
130
|
+
export function listTokenTypesForCryptoCurrency(currency: CryptoCurrency): string[] {
|
|
131
|
+
return currency.tokenTypes || [];
|
|
629
132
|
}
|