@ledgerhq/coin-solana 0.37.0-nightly.20251120023735 → 0.37.0-nightly.20251121023744
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 +11 -7
- package/lib/bridge/bridge.d.ts.map +1 -1
- package/lib/bridge/bridge.js +1 -1
- package/lib/bridge/bridge.js.map +1 -1
- package/lib/bridge/js.d.ts +1 -2
- package/lib/bridge/js.d.ts.map +1 -1
- package/lib/bridge/js.js +1 -3
- package/lib/bridge/js.js.map +1 -1
- package/lib/cli-transaction.js +2 -2
- package/lib/cli-transaction.js.map +1 -1
- package/lib/helpers/token.js +2 -2
- package/lib/helpers/token.js.map +1 -1
- package/lib/preload-data.d.ts.map +1 -1
- package/lib/preload-data.js +0 -1
- package/lib/preload-data.js.map +1 -1
- package/lib/preload.d.ts +1 -5
- package/lib/preload.d.ts.map +1 -1
- package/lib/preload.js +1 -105
- package/lib/preload.js.map +1 -1
- package/lib/prepareTransaction.js +2 -2
- package/lib/prepareTransaction.js.map +1 -1
- package/lib/synchronization.js +2 -2
- package/lib/synchronization.js.map +1 -1
- package/lib/transaction.js +2 -2
- package/lib/transaction.js.map +1 -1
- package/lib/types.d.ts +0 -2
- package/lib/types.d.ts.map +1 -1
- package/lib-es/bridge/bridge.d.ts.map +1 -1
- package/lib-es/bridge/bridge.js +2 -2
- package/lib-es/bridge/bridge.js.map +1 -1
- package/lib-es/bridge/js.d.ts +1 -2
- package/lib-es/bridge/js.d.ts.map +1 -1
- package/lib-es/bridge/js.js +1 -3
- package/lib-es/bridge/js.js.map +1 -1
- package/lib-es/cli-transaction.js +1 -1
- package/lib-es/cli-transaction.js.map +1 -1
- package/lib-es/helpers/token.js +1 -1
- package/lib-es/helpers/token.js.map +1 -1
- package/lib-es/preload-data.d.ts.map +1 -1
- package/lib-es/preload-data.js +0 -1
- package/lib-es/preload-data.js.map +1 -1
- package/lib-es/preload.d.ts +1 -5
- package/lib-es/preload.d.ts.map +1 -1
- package/lib-es/preload.js +1 -79
- package/lib-es/preload.js.map +1 -1
- package/lib-es/prepareTransaction.js +1 -1
- package/lib-es/prepareTransaction.js.map +1 -1
- package/lib-es/synchronization.js +1 -1
- package/lib-es/synchronization.js.map +1 -1
- package/lib-es/transaction.js +1 -1
- package/lib-es/transaction.js.map +1 -1
- package/lib-es/types.d.ts +0 -2
- package/lib-es/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/bridge/bridge.ts +3 -2
- package/src/bridge/js.ts +0 -4
- package/src/cli-transaction.ts +1 -1
- package/src/helpers/token.ts +1 -1
- package/src/preload-data.ts +0 -1
- package/src/preload.test.ts +121 -12
- package/src/preload.ts +1 -108
- package/src/prepareTransaction.ts +1 -1
- package/src/synchronization.ts +1 -1
- package/src/tests/tokens-bridge.unit.test.ts +11 -16
- package/src/transaction.ts +1 -1
- package/src/types.ts +0 -2
- package/lib/cryptoAssetsStore.d.ts +0 -5
- package/lib/cryptoAssetsStore.d.ts.map +0 -1
- package/lib/cryptoAssetsStore.js +0 -17
- package/lib/cryptoAssetsStore.js.map +0 -1
- package/lib-es/cryptoAssetsStore.d.ts +0 -5
- package/lib-es/cryptoAssetsStore.d.ts.map +0 -1
- package/lib-es/cryptoAssetsStore.js +0 -12
- package/lib-es/cryptoAssetsStore.js.map +0 -1
- package/src/cryptoAssetsStore.test.ts +0 -19
- package/src/cryptoAssetsStore.ts +0 -16
- package/src/tests/preload.unit.test.ts +0 -182
package/src/preload.ts
CHANGED
|
@@ -1,81 +1,13 @@
|
|
|
1
1
|
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
2
|
import { flow } from "lodash/fp";
|
|
3
3
|
import { ChainAPI } from "./network";
|
|
4
|
-
import { log } from "@ledgerhq/logs";
|
|
5
4
|
import { setSolanaPreloadData as setPreloadData } from "./preload-data";
|
|
6
5
|
import { SolanaPreloadData, SolanaPreloadDataV1 } from "./types";
|
|
7
|
-
import {
|
|
8
|
-
assertUnreachable,
|
|
9
|
-
clusterByCurrencyId,
|
|
10
|
-
profitableValidators,
|
|
11
|
-
ledgerFirstValidators,
|
|
12
|
-
} from "./utils";
|
|
6
|
+
import { clusterByCurrencyId, profitableValidators, ledgerFirstValidators } from "./utils";
|
|
13
7
|
import { getValidators, ValidatorsAppValidator } from "./network/validator-app";
|
|
14
|
-
import spltokensList, { hash as embeddedHash, SPLToken } from "@ledgerhq/cryptoassets/data/spl";
|
|
15
|
-
import { fetchTokensFromCALService } from "@ledgerhq/cryptoassets/crypto-assets-importer/fetch/index";
|
|
16
|
-
import { getCALHash, setCALHash } from "./logic";
|
|
17
|
-
import { addTokens, convertSplTokens } from "@ledgerhq/cryptoassets/legacy/legacy-utils";
|
|
18
|
-
import { AxiosError } from "axios";
|
|
19
|
-
|
|
20
|
-
let shouldSkipTokenLoading = false;
|
|
21
|
-
|
|
22
|
-
export function setShouldSkipTokenLoading(skip: boolean): void {
|
|
23
|
-
shouldSkipTokenLoading = skip;
|
|
24
|
-
}
|
|
25
8
|
|
|
26
9
|
export const PRELOAD_MAX_AGE = 15 * 60 * 1000; // 15min
|
|
27
10
|
|
|
28
|
-
export const fetchSPLTokens: (
|
|
29
|
-
currency: CryptoCurrency,
|
|
30
|
-
) => Promise<SPLToken[] | null> = async currency => {
|
|
31
|
-
const latestCALHash = getCALHash(currency);
|
|
32
|
-
const calHash = latestCALHash || embeddedHash;
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
const { tokens, hash } = await fetchTokensFromCALService(
|
|
36
|
-
{ blockchain_name: "solana" },
|
|
37
|
-
["id", "network", "name", "ticker", "contract_address", "decimals"],
|
|
38
|
-
calHash,
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const splTokens: SPLToken[] = tokens.map(token => [
|
|
42
|
-
token.id,
|
|
43
|
-
token.network,
|
|
44
|
-
token.name,
|
|
45
|
-
token.ticker,
|
|
46
|
-
token.contract_address,
|
|
47
|
-
token.decimals,
|
|
48
|
-
]);
|
|
49
|
-
|
|
50
|
-
setCALHash(currency, hash || "");
|
|
51
|
-
log("solana/preload", "preload " + splTokens.length + " tokens");
|
|
52
|
-
|
|
53
|
-
if (!shouldSkipTokenLoading) {
|
|
54
|
-
addTokens(splTokens.map(convertSplTokens));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return splTokens;
|
|
58
|
-
} catch (e) {
|
|
59
|
-
if (e instanceof AxiosError && e.response?.status === 304) {
|
|
60
|
-
log(
|
|
61
|
-
"solana/preload",
|
|
62
|
-
`loading existing fallback tokens for solana with hash ${latestCALHash || embeddedHash}`,
|
|
63
|
-
);
|
|
64
|
-
if (!latestCALHash) {
|
|
65
|
-
setCALHash(currency, embeddedHash);
|
|
66
|
-
if (!shouldSkipTokenLoading) {
|
|
67
|
-
addTokens(spltokensList.map(convertSplTokens));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return spltokensList;
|
|
71
|
-
}
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
log("solana/preload", `failure to retrieve tokens for solana`, e);
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
11
|
export async function preloadWithAPI(
|
|
80
12
|
currency: CryptoCurrency,
|
|
81
13
|
getAPI: () => Promise<ChainAPI>,
|
|
@@ -87,13 +19,10 @@ export async function preloadWithAPI(
|
|
|
87
19
|
const validators: ValidatorsAppValidator[] =
|
|
88
20
|
cluster === "devnet" ? await loadDevnetValidators(api) : await getValidators(cluster);
|
|
89
21
|
|
|
90
|
-
const splTokens = await fetchSPLTokens(currency);
|
|
91
|
-
|
|
92
22
|
const data: SolanaPreloadData = {
|
|
93
23
|
version: "1",
|
|
94
24
|
validatorsWithMeta: [],
|
|
95
25
|
validators: cluster === "mainnet-beta" ? preprocessMainnetValidators(validators) : validators,
|
|
96
|
-
splTokens,
|
|
97
26
|
};
|
|
98
27
|
|
|
99
28
|
setPreloadData(data, currency);
|
|
@@ -117,39 +46,3 @@ async function loadDevnetValidators(api: ChainAPI) {
|
|
|
117
46
|
}));
|
|
118
47
|
return validators;
|
|
119
48
|
}
|
|
120
|
-
|
|
121
|
-
export function hydrate(data: SolanaPreloadData | undefined, currency: CryptoCurrency): void {
|
|
122
|
-
// https://ledgerhq.atlassian.net/browse/LIVE-11568 covers unknown case where version is undefined
|
|
123
|
-
if (!data || !data.version) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
switch (data.version) {
|
|
128
|
-
case "1":
|
|
129
|
-
hydrateV1(data, currency);
|
|
130
|
-
return;
|
|
131
|
-
case "2":
|
|
132
|
-
throw new Error("version 2 for now exists only to support discriminated union");
|
|
133
|
-
default:
|
|
134
|
-
return assertUnreachable(data);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function hydrateV1(data: SolanaPreloadDataV1, currency: CryptoCurrency) {
|
|
139
|
-
if (Array.isArray(data.splTokens)) {
|
|
140
|
-
if (!shouldSkipTokenLoading) {
|
|
141
|
-
addTokens(data.splTokens.map(convertSplTokens));
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
log("solana/preload", `hydrate ${data.splTokens.length} tokens`);
|
|
145
|
-
setPreloadData(data, currency);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (!shouldSkipTokenLoading) {
|
|
150
|
-
addTokens(spltokensList.map(convertSplTokens));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
log("solana/preload", `hydrate fallback ${spltokensList.length} embedded tokens`);
|
|
154
|
-
setPreloadData(data, currency);
|
|
155
|
-
}
|
|
@@ -81,7 +81,7 @@ import { TokenAccountInfo } from "./network/chain/account/token";
|
|
|
81
81
|
import { deriveRawCommandDescriptor, toLiveTransaction } from "./rawTransaction";
|
|
82
82
|
import BigNumber from "bignumber.js";
|
|
83
83
|
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/formatCurrencyUnit";
|
|
84
|
-
import { getCryptoAssetsStore } from "
|
|
84
|
+
import { getCryptoAssetsStore } from "@ledgerhq/cryptoassets/state";
|
|
85
85
|
|
|
86
86
|
async function deriveCommandDescriptor(
|
|
87
87
|
mainAccount: SolanaAccount,
|
package/src/synchronization.ts
CHANGED
|
@@ -50,7 +50,7 @@ import { getStakeAccounts } from "./network/chain/stake-activation/rpc";
|
|
|
50
50
|
import { tryParseAsMintAccount } from "./network/chain/account";
|
|
51
51
|
import ky from "ky";
|
|
52
52
|
import { isSignaturesForAddressResponse } from "./utils";
|
|
53
|
-
import { getCryptoAssetsStore } from "
|
|
53
|
+
import { getCryptoAssetsStore } from "@ledgerhq/cryptoassets/state";
|
|
54
54
|
|
|
55
55
|
export async function getAccount(
|
|
56
56
|
address: string,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "../types";
|
|
12
12
|
|
|
13
13
|
import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
14
|
-
import type { Account
|
|
14
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
15
15
|
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
|
|
16
16
|
import {
|
|
17
17
|
SolanaRecipientMemoIsRequired,
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
} from "@solana/spl-token";
|
|
33
33
|
import { calculateToken2022TransferFees } from "../helpers/token";
|
|
34
34
|
import { PARSED_PROGRAMS } from "../network/chain/program/constants";
|
|
35
|
-
import {
|
|
35
|
+
import { setupMockCryptoAssetsStore } from "@ledgerhq/cryptoassets/cal-client/test-helpers";
|
|
36
36
|
import usdcTokenData from "../__fixtures__/solana-spl-epjfwdd5aufqssqem2qn1xzybapc8g4weggkzwytdt1v.json";
|
|
37
37
|
|
|
38
38
|
const USDC_TOKEN = usdcTokenData as unknown as TokenCurrency;
|
|
@@ -64,20 +64,15 @@ const mainAccId = encodeAccountId({
|
|
|
64
64
|
|
|
65
65
|
const wSolSubAccId = encodeAccountIdWithTokenAccountAddress(mainAccId, testData.ataAddress1);
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
() =>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
},
|
|
77
|
-
findTokenById: async () => undefined,
|
|
78
|
-
getTokensSyncHash: (_: string) => Promise.resolve("0"),
|
|
79
|
-
}) as CryptoAssetsStore,
|
|
80
|
-
);
|
|
67
|
+
setupMockCryptoAssetsStore({
|
|
68
|
+
findTokenByAddressInCurrency: async (address: string, _currencyId: string) => {
|
|
69
|
+
if (address === "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v") {
|
|
70
|
+
return USDC_TOKEN;
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
},
|
|
74
|
+
getTokensSyncHash: async () => "0",
|
|
75
|
+
});
|
|
81
76
|
|
|
82
77
|
// Create a mock token for testing
|
|
83
78
|
const wSolToken: TokenCurrency = {
|
package/src/transaction.ts
CHANGED
|
@@ -25,7 +25,7 @@ import type { Account } from "@ledgerhq/types-live";
|
|
|
25
25
|
import { findSubAccountById, getAccountCurrency } from "@ledgerhq/coin-framework/account";
|
|
26
26
|
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies";
|
|
27
27
|
import { assertUnreachable } from "./utils";
|
|
28
|
-
import { getCryptoAssetsStore } from "
|
|
28
|
+
import { getCryptoAssetsStore } from "@ledgerhq/cryptoassets/state";
|
|
29
29
|
|
|
30
30
|
export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
|
|
31
31
|
const common = fromTransactionCommonRaw(tr);
|
package/src/types.ts
CHANGED
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
import { ValidatorsAppValidator } from "./network/validator-app";
|
|
14
14
|
import { TokenAccountState } from "./network/chain/account/token";
|
|
15
15
|
import { PARSED_PROGRAMS } from "./network/chain/program/constants";
|
|
16
|
-
import type { SPLToken } from "@ledgerhq/cryptoassets/data/spl";
|
|
17
16
|
|
|
18
17
|
export type TransferCommand = {
|
|
19
18
|
kind: "transfer";
|
|
@@ -307,7 +306,6 @@ export type SolanaPreloadDataV1 = {
|
|
|
307
306
|
version: "1";
|
|
308
307
|
validatorsWithMeta: SolanaValidatorWithMeta[];
|
|
309
308
|
validators: ValidatorsAppValidator[];
|
|
310
|
-
splTokens: SPLToken[] | null;
|
|
311
309
|
};
|
|
312
310
|
|
|
313
311
|
// exists for discriminated union to work
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { CryptoAssetsStore, CryptoAssetsStoreGetter } from "@ledgerhq/types-live";
|
|
2
|
-
export declare const CRYPTO_ASSETS_STORE_NO_SET_ERROR_MESSAGE = "CryptoAssetsStore is not set. Please call setCryptoAssetsStore first on coin solana";
|
|
3
|
-
export declare function setCryptoAssetsStoreGetter(cryptoAssetsStoreGetter: CryptoAssetsStoreGetter): void;
|
|
4
|
-
export declare function getCryptoAssetsStore(): CryptoAssetsStore;
|
|
5
|
-
//# sourceMappingURL=cryptoAssetsStore.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cryptoAssetsStore.d.ts","sourceRoot":"","sources":["../src/cryptoAssetsStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAElF,eAAO,MAAM,wCAAwC,wFACkC,CAAC;AAGxF,wBAAgB,0BAA0B,CAAC,uBAAuB,EAAE,uBAAuB,GAAG,IAAI,CAEjG;AAED,wBAAgB,oBAAoB,IAAI,iBAAiB,CAKxD"}
|
package/lib/cryptoAssetsStore.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCryptoAssetsStore = exports.setCryptoAssetsStoreGetter = exports.CRYPTO_ASSETS_STORE_NO_SET_ERROR_MESSAGE = void 0;
|
|
4
|
-
exports.CRYPTO_ASSETS_STORE_NO_SET_ERROR_MESSAGE = "CryptoAssetsStore is not set. Please call setCryptoAssetsStore first on coin solana";
|
|
5
|
-
let getStore;
|
|
6
|
-
function setCryptoAssetsStoreGetter(cryptoAssetsStoreGetter) {
|
|
7
|
-
getStore = cryptoAssetsStoreGetter;
|
|
8
|
-
}
|
|
9
|
-
exports.setCryptoAssetsStoreGetter = setCryptoAssetsStoreGetter;
|
|
10
|
-
function getCryptoAssetsStore() {
|
|
11
|
-
if (!getStore) {
|
|
12
|
-
throw new Error(exports.CRYPTO_ASSETS_STORE_NO_SET_ERROR_MESSAGE);
|
|
13
|
-
}
|
|
14
|
-
return getStore();
|
|
15
|
-
}
|
|
16
|
-
exports.getCryptoAssetsStore = getCryptoAssetsStore;
|
|
17
|
-
//# sourceMappingURL=cryptoAssetsStore.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cryptoAssetsStore.js","sourceRoot":"","sources":["../src/cryptoAssetsStore.ts"],"names":[],"mappings":";;;AAEa,QAAA,wCAAwC,GACnD,qFAAqF,CAAC;AAExF,IAAI,QAAiC,CAAC;AACtC,SAAgB,0BAA0B,CAAC,uBAAgD;IACzF,QAAQ,GAAG,uBAAuB,CAAC;AACrC,CAAC;AAFD,gEAEC;AAED,SAAgB,oBAAoB;IAClC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,gDAAwC,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,QAAQ,EAAE,CAAC;AACpB,CAAC;AALD,oDAKC"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { CryptoAssetsStore, CryptoAssetsStoreGetter } from "@ledgerhq/types-live";
|
|
2
|
-
export declare const CRYPTO_ASSETS_STORE_NO_SET_ERROR_MESSAGE = "CryptoAssetsStore is not set. Please call setCryptoAssetsStore first on coin solana";
|
|
3
|
-
export declare function setCryptoAssetsStoreGetter(cryptoAssetsStoreGetter: CryptoAssetsStoreGetter): void;
|
|
4
|
-
export declare function getCryptoAssetsStore(): CryptoAssetsStore;
|
|
5
|
-
//# sourceMappingURL=cryptoAssetsStore.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cryptoAssetsStore.d.ts","sourceRoot":"","sources":["../src/cryptoAssetsStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAElF,eAAO,MAAM,wCAAwC,wFACkC,CAAC;AAGxF,wBAAgB,0BAA0B,CAAC,uBAAuB,EAAE,uBAAuB,GAAG,IAAI,CAEjG;AAED,wBAAgB,oBAAoB,IAAI,iBAAiB,CAKxD"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export const CRYPTO_ASSETS_STORE_NO_SET_ERROR_MESSAGE = "CryptoAssetsStore is not set. Please call setCryptoAssetsStore first on coin solana";
|
|
2
|
-
let getStore;
|
|
3
|
-
export function setCryptoAssetsStoreGetter(cryptoAssetsStoreGetter) {
|
|
4
|
-
getStore = cryptoAssetsStoreGetter;
|
|
5
|
-
}
|
|
6
|
-
export function getCryptoAssetsStore() {
|
|
7
|
-
if (!getStore) {
|
|
8
|
-
throw new Error(CRYPTO_ASSETS_STORE_NO_SET_ERROR_MESSAGE);
|
|
9
|
-
}
|
|
10
|
-
return getStore();
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=cryptoAssetsStore.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cryptoAssetsStore.js","sourceRoot":"","sources":["../src/cryptoAssetsStore.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,wCAAwC,GACnD,qFAAqF,CAAC;AAExF,IAAI,QAAiC,CAAC;AACtC,MAAM,UAAU,0BAA0B,CAAC,uBAAgD;IACzF,QAAQ,GAAG,uBAAuB,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,oBAAoB;IAClC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,QAAQ,EAAE,CAAC;AACpB,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { CryptoAssetsStore } from "@ledgerhq/types-live";
|
|
2
|
-
import {
|
|
3
|
-
CRYPTO_ASSETS_STORE_NO_SET_ERROR_MESSAGE,
|
|
4
|
-
getCryptoAssetsStore,
|
|
5
|
-
setCryptoAssetsStoreGetter,
|
|
6
|
-
} from "./cryptoAssetsStore";
|
|
7
|
-
|
|
8
|
-
describe("cryptoAssetsStore", () => {
|
|
9
|
-
it("should throw an error when CryptoAssetsStoreGetter is not set", () => {
|
|
10
|
-
expect(() => getCryptoAssetsStore()).toThrow(CRYPTO_ASSETS_STORE_NO_SET_ERROR_MESSAGE);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it("should return the CryptoAssetsStoreGetter set", () => {
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
15
|
-
const store = {} as CryptoAssetsStore;
|
|
16
|
-
setCryptoAssetsStoreGetter(() => store);
|
|
17
|
-
expect(getCryptoAssetsStore()).toEqual(store);
|
|
18
|
-
});
|
|
19
|
-
});
|
package/src/cryptoAssetsStore.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { CryptoAssetsStore, CryptoAssetsStoreGetter } from "@ledgerhq/types-live";
|
|
2
|
-
|
|
3
|
-
export const CRYPTO_ASSETS_STORE_NO_SET_ERROR_MESSAGE =
|
|
4
|
-
"CryptoAssetsStore is not set. Please call setCryptoAssetsStore first on coin solana";
|
|
5
|
-
|
|
6
|
-
let getStore: CryptoAssetsStoreGetter;
|
|
7
|
-
export function setCryptoAssetsStoreGetter(cryptoAssetsStoreGetter: CryptoAssetsStoreGetter): void {
|
|
8
|
-
getStore = cryptoAssetsStoreGetter;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function getCryptoAssetsStore(): CryptoAssetsStore {
|
|
12
|
-
if (!getStore) {
|
|
13
|
-
throw new Error(CRYPTO_ASSETS_STORE_NO_SET_ERROR_MESSAGE);
|
|
14
|
-
}
|
|
15
|
-
return getStore();
|
|
16
|
-
}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
jest.useFakeTimers();
|
|
2
|
-
|
|
3
|
-
import { jlpDefinition, soEthDefinition, graphitDefinition } from "./preload.fixtures";
|
|
4
|
-
import axios, { AxiosResponse } from "axios";
|
|
5
|
-
import {
|
|
6
|
-
convertSplTokens,
|
|
7
|
-
__clearAllLists,
|
|
8
|
-
addTokens,
|
|
9
|
-
} from "@ledgerhq/cryptoassets/legacy/legacy-utils";
|
|
10
|
-
import { fetchSPLTokens, hydrate, preloadWithAPI } from "../preload";
|
|
11
|
-
import { __resetCALHash, getCALHash, setCALHash } from "../logic";
|
|
12
|
-
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
13
|
-
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
|
|
14
|
-
import { ChainAPI } from "../network";
|
|
15
|
-
|
|
16
|
-
jest.mock("axios");
|
|
17
|
-
const mockedAxios = jest.mocked(axios);
|
|
18
|
-
mockedAxios.AxiosError = jest.requireActual("axios").AxiosError;
|
|
19
|
-
|
|
20
|
-
jest.mock("@ledgerhq/cryptoassets/legacy/legacy-utils", () => {
|
|
21
|
-
const actual = jest.requireActual("@ledgerhq/cryptoassets/legacy/legacy-utils");
|
|
22
|
-
return {
|
|
23
|
-
...actual,
|
|
24
|
-
addTokens: jest.fn(),
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
jest.mock("@ledgerhq/cryptoassets/data/spl", () => ({
|
|
29
|
-
__esModule: true, // Ensures the mock is treated as an ES module
|
|
30
|
-
default: [jlpDefinition, soEthDefinition], // Mocked as an array
|
|
31
|
-
|
|
32
|
-
get hash() {
|
|
33
|
-
return "initialStateSolana"; // Mocked hash value
|
|
34
|
-
},
|
|
35
|
-
}));
|
|
36
|
-
const mockCurrency: CryptoCurrency = getCryptoCurrencyById("solana");
|
|
37
|
-
|
|
38
|
-
const mockAPI = {
|
|
39
|
-
getVoteAccounts: jest.fn(),
|
|
40
|
-
} as unknown as ChainAPI;
|
|
41
|
-
|
|
42
|
-
const mockGetAPI = jest.fn(() => Promise.resolve(mockAPI));
|
|
43
|
-
jest.mock("../network/validator-app", () => ({
|
|
44
|
-
getValidators: jest.fn(() => [{ commission: 50 }, { commission: 90 }, { commission: 110 }]),
|
|
45
|
-
}));
|
|
46
|
-
|
|
47
|
-
describe("Solana Family", () => {
|
|
48
|
-
beforeEach(() => {
|
|
49
|
-
__clearAllLists();
|
|
50
|
-
mockedAxios.get.mockImplementation(async (url, { params, headers } = {}) => {
|
|
51
|
-
if (url !== "https://crypto-assets-service.api.ledger.com/v1/tokens")
|
|
52
|
-
throw new Error("UNEXPECTED URL");
|
|
53
|
-
|
|
54
|
-
if (params.blockchain_name === "solana") {
|
|
55
|
-
if (headers?.["If-None-Match"] === "newStateSolana")
|
|
56
|
-
throw new axios.AxiosError("", "", undefined, undefined, {
|
|
57
|
-
status: 304,
|
|
58
|
-
} as AxiosResponse);
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
data: [jlpDefinition, soEthDefinition].map(tokenDef => ({
|
|
62
|
-
network: tokenDef[1],
|
|
63
|
-
id: tokenDef[0],
|
|
64
|
-
ticker: tokenDef[3],
|
|
65
|
-
decimals: tokenDef[5],
|
|
66
|
-
name: tokenDef[2],
|
|
67
|
-
contract_address: tokenDef[4],
|
|
68
|
-
})),
|
|
69
|
-
headers: { ["etag"]: "newStateSolana" },
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
afterEach(() => {
|
|
76
|
-
jest.restoreAllMocks();
|
|
77
|
-
__resetCALHash();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe("fetchSPLTokens", () => {
|
|
81
|
-
beforeEach(() => {
|
|
82
|
-
jest.mocked(addTokens).mockClear();
|
|
83
|
-
});
|
|
84
|
-
it("should return the embedded tokens if there is no update on remote and tokens are not loaded", async () => {
|
|
85
|
-
mockedAxios.get.mockImplementationOnce((url, { headers } = {}) => {
|
|
86
|
-
if (headers?.["If-None-Match"] === "initialStateSolana")
|
|
87
|
-
throw new axios.AxiosError("", "", undefined, undefined, {
|
|
88
|
-
status: 304,
|
|
89
|
-
} as AxiosResponse);
|
|
90
|
-
throw new Error("unexpected");
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
expect(getCALHash(mockCurrency)).toBe("");
|
|
94
|
-
const tokens = await fetchSPLTokens(mockCurrency);
|
|
95
|
-
expect(tokens).toEqual([jlpDefinition, soEthDefinition]);
|
|
96
|
-
expect(getCALHash(mockCurrency)).toBe("initialStateSolana");
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("should return nothing if loaded tokens are up to date with remote already", async () => {
|
|
100
|
-
setCALHash(mockCurrency, "newStateSolana");
|
|
101
|
-
|
|
102
|
-
const tokens = await fetchSPLTokens(mockCurrency);
|
|
103
|
-
expect(tokens).toEqual(null);
|
|
104
|
-
expect(getCALHash(mockCurrency)).toBe("newStateSolana");
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("should return the content of the remote CAL", async () => {
|
|
108
|
-
setCALHash(mockCurrency, "initialStateSolana");
|
|
109
|
-
|
|
110
|
-
const tokens = await fetchSPLTokens(mockCurrency);
|
|
111
|
-
expect(tokens).toEqual([jlpDefinition, soEthDefinition]);
|
|
112
|
-
expect(getCALHash(mockCurrency)).toBe("newStateSolana");
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it("should return nothing and maintain the saved CAL hash if the CAL service is down", async () => {
|
|
116
|
-
mockedAxios.get.mockImplementation(() => {
|
|
117
|
-
throw new Error();
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
setCALHash(mockCurrency, "anything");
|
|
121
|
-
const tokens = await fetchSPLTokens(mockCurrency);
|
|
122
|
-
expect(tokens).toEqual(null);
|
|
123
|
-
expect(getCALHash(mockCurrency)).toBe("anything");
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe("preloadWithAPI", () => {
|
|
128
|
-
beforeEach(() => {
|
|
129
|
-
jest.mocked(addTokens).mockClear();
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("should return void when fetch is hitting cache", async () => {
|
|
133
|
-
setCALHash(mockCurrency, "newStateSolana");
|
|
134
|
-
const data = await preloadWithAPI(mockCurrency, mockGetAPI);
|
|
135
|
-
expect(data.splTokens).toEqual(null);
|
|
136
|
-
expect(addTokens).not.toHaveBeenCalled();
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it("should return and register the new SPL tokens", async () => {
|
|
140
|
-
setCALHash(mockCurrency, "initialStateSolana");
|
|
141
|
-
const data = await preloadWithAPI(mockCurrency, mockGetAPI);
|
|
142
|
-
expect(data.splTokens).toEqual([jlpDefinition, soEthDefinition]);
|
|
143
|
-
expect(addTokens).toHaveBeenCalledTimes(1);
|
|
144
|
-
expect(addTokens).toHaveBeenCalledWith([
|
|
145
|
-
convertSplTokens(jlpDefinition),
|
|
146
|
-
convertSplTokens(soEthDefinition),
|
|
147
|
-
]);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe("hydrate", () => {
|
|
152
|
-
beforeEach(() => {
|
|
153
|
-
jest.mocked(addTokens).mockClear();
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("should not do anything", async () => {
|
|
157
|
-
hydrate(undefined, mockCurrency);
|
|
158
|
-
expect(addTokens).toHaveBeenCalledTimes(0);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it("should register SPL tokens from embedded with null", async () => {
|
|
162
|
-
hydrate(
|
|
163
|
-
{ version: "1", validators: [], validatorsWithMeta: [], splTokens: null },
|
|
164
|
-
mockCurrency,
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
expect(addTokens).toHaveBeenCalledWith([
|
|
168
|
-
convertSplTokens(jlpDefinition),
|
|
169
|
-
convertSplTokens(soEthDefinition),
|
|
170
|
-
]);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("should register SPL tokens", async () => {
|
|
174
|
-
hydrate(
|
|
175
|
-
{ version: "1", validators: [], validatorsWithMeta: [], splTokens: [graphitDefinition] },
|
|
176
|
-
mockCurrency,
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
expect(addTokens).toHaveBeenCalledWith([convertSplTokens(graphitDefinition)]);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
});
|