@ledgerhq/coin-solana 0.30.0 → 0.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 +16 -0
- package/lib/__tests__/unit/utils.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/utils.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/utils.unit.test.js +16 -0
- package/lib/__tests__/unit/utils.unit.test.js.map +1 -0
- package/lib/__tests__/unit/validator-app.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/validator-app.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/validator-app.unit.test.js +169 -0
- package/lib/__tests__/unit/validator-app.unit.test.js.map +1 -0
- package/lib/buildTransaction.d.ts.map +1 -1
- package/lib/buildTransaction.js +5 -3
- package/lib/buildTransaction.js.map +1 -1
- package/lib/network/validator-app/index.d.ts +1 -0
- package/lib/network/validator-app/index.d.ts.map +1 -1
- package/lib/network/validator-app/index.js +32 -6
- package/lib/network/validator-app/index.js.map +1 -1
- package/lib/signOperation.test.js +2 -2
- package/lib/signOperation.test.js.map +1 -1
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +4 -2
- package/lib/utils.js.map +1 -1
- package/lib-es/__tests__/unit/utils.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/utils.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/utils.unit.test.js +14 -0
- package/lib-es/__tests__/unit/utils.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/validator-app.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/validator-app.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/validator-app.unit.test.js +144 -0
- package/lib-es/__tests__/unit/validator-app.unit.test.js.map +1 -0
- package/lib-es/buildTransaction.d.ts.map +1 -1
- package/lib-es/buildTransaction.js +5 -3
- package/lib-es/buildTransaction.js.map +1 -1
- package/lib-es/network/validator-app/index.d.ts +1 -0
- package/lib-es/network/validator-app/index.d.ts.map +1 -1
- package/lib-es/network/validator-app/index.js +32 -6
- package/lib-es/network/validator-app/index.js.map +1 -1
- package/lib-es/signOperation.test.js +1 -1
- package/lib-es/signOperation.test.js.map +1 -1
- package/lib-es/utils.d.ts.map +1 -1
- package/lib-es/utils.js +4 -2
- package/lib-es/utils.js.map +1 -1
- package/package.json +8 -8
- package/src/__tests__/unit/utils.unit.test.ts +19 -0
- package/src/__tests__/unit/validator-app.unit.test.ts +170 -0
- package/src/buildTransaction.ts +5 -3
- package/src/network/validator-app/index.ts +42 -6
- package/src/signOperation.test.ts +1 -1
- package/src/utils.ts +4 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import network from "@ledgerhq/live-network
|
|
1
|
+
import network from "@ledgerhq/live-network";
|
|
2
2
|
import { Cluster } from "@solana/web3.js";
|
|
3
3
|
import { compact } from "lodash/fp";
|
|
4
4
|
import { getEnv } from "@ledgerhq/live-env";
|
|
@@ -24,6 +24,13 @@ export type ValidatorsAppValidator = {
|
|
|
24
24
|
name?: string | undefined;
|
|
25
25
|
avatarUrl?: string | undefined;
|
|
26
26
|
wwwUrl?: string | undefined;
|
|
27
|
+
apy?: number | undefined;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type ValidatorApyRaw = {
|
|
31
|
+
address: string;
|
|
32
|
+
delegator_apy: number;
|
|
33
|
+
name: string;
|
|
27
34
|
};
|
|
28
35
|
|
|
29
36
|
const URLS = {
|
|
@@ -36,18 +43,46 @@ const URLS = {
|
|
|
36
43
|
const baseUrl = getEnv("SOLANA_VALIDATORS_APP_BASE_URL");
|
|
37
44
|
return baseUrl;
|
|
38
45
|
},
|
|
46
|
+
validatorApylist: getEnv("SOLANA_VALIDATORS_SUMMARY_BASE_URL"),
|
|
39
47
|
};
|
|
40
48
|
|
|
49
|
+
async function fetchFigmentApy(
|
|
50
|
+
cluster: Extract<Cluster, "mainnet-beta" | "testnet">,
|
|
51
|
+
): Promise<Record<string, number>> {
|
|
52
|
+
if (cluster !== "mainnet-beta") return {};
|
|
53
|
+
try {
|
|
54
|
+
const response = await network({
|
|
55
|
+
method: "GET",
|
|
56
|
+
url: URLS.validatorApylist,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (response.status === 200 && Array.isArray(response.data)) {
|
|
60
|
+
return response.data.reduce((acc: Record<string, number>, item: ValidatorApyRaw) => {
|
|
61
|
+
if (typeof item.address === "string" && typeof item.delegator_apy === "number") {
|
|
62
|
+
acc[item.address] = item.delegator_apy;
|
|
63
|
+
}
|
|
64
|
+
return acc;
|
|
65
|
+
}, {});
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.warn("Failed to fetch Figment APY", error);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
|
|
41
74
|
export async function getValidators(
|
|
42
75
|
cluster: Extract<Cluster, "mainnet-beta" | "testnet">,
|
|
43
76
|
): Promise<ValidatorsAppValidator[]> {
|
|
44
|
-
const
|
|
45
|
-
method: "GET",
|
|
46
|
-
|
|
47
|
-
|
|
77
|
+
const [validatorsResponse, apyMap] = await Promise.all([
|
|
78
|
+
network({ method: "GET", url: URLS.validatorList(cluster) }),
|
|
79
|
+
fetchFigmentApy(cluster),
|
|
80
|
+
]);
|
|
48
81
|
|
|
49
82
|
const allRawValidators =
|
|
50
|
-
|
|
83
|
+
validatorsResponse.status === 200
|
|
84
|
+
? (validatorsResponse.data as ValidatorsAppValidatorRaw[])
|
|
85
|
+
: [];
|
|
51
86
|
|
|
52
87
|
// validators app data is not clean: random properties can randomly contain
|
|
53
88
|
// data, null, undefined
|
|
@@ -69,6 +104,7 @@ export async function getValidators(
|
|
|
69
104
|
name: validator.name ?? undefined,
|
|
70
105
|
avatarUrl: validator.avatar_url ?? undefined,
|
|
71
106
|
wwwUrl: validator.www_url ?? undefined,
|
|
107
|
+
apy: apyMap[validator.vote_account],
|
|
72
108
|
};
|
|
73
109
|
}
|
|
74
110
|
|
|
@@ -3,7 +3,7 @@ import { SolanaAddress } from "./signer";
|
|
|
3
3
|
import { buildSignOperation } from "./signOperation";
|
|
4
4
|
import { Account, Operation, OperationType, SignOperationEvent } from "@ledgerhq/types-live";
|
|
5
5
|
import { ChainAPI } from "./network";
|
|
6
|
-
import { DeviceModelId } from "@ledgerhq/devices
|
|
6
|
+
import { DeviceModelId } from "@ledgerhq/devices";
|
|
7
7
|
import { Transaction } from "./types";
|
|
8
8
|
import { BlockhashWithExpiryBlockHeight, VersionedTransaction } from "@solana/web3.js";
|
|
9
9
|
|
package/src/utils.ts
CHANGED
|
@@ -19,9 +19,10 @@ export const LEDGER_VALIDATOR_BY_FIGMENT: ValidatorsAppValidator = {
|
|
|
19
19
|
avatarUrl:
|
|
20
20
|
"https://s3.amazonaws.com/keybase_processed_uploads/3c47b62f3d28ecfd821536f69be82905_360_360.jpg",
|
|
21
21
|
wwwUrl: "https://www.ledger.com/staking",
|
|
22
|
-
activeStake:
|
|
22
|
+
activeStake: 8860644178046828,
|
|
23
23
|
commission: 7,
|
|
24
24
|
totalScore: 6,
|
|
25
|
+
apy: 0.078107,
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
export const LEDGER_VALIDATOR_BY_CHORUS_ONE: ValidatorsAppValidator = {
|
|
@@ -30,9 +31,10 @@ export const LEDGER_VALIDATOR_BY_CHORUS_ONE: ValidatorsAppValidator = {
|
|
|
30
31
|
avatarUrl:
|
|
31
32
|
"https://s3.amazonaws.com/keybase_processed_uploads/3c47b62f3d28ecfd821536f69be82905_360_360.jpg",
|
|
32
33
|
wwwUrl: "https://www.ledger.com/staking",
|
|
33
|
-
activeStake:
|
|
34
|
+
activeStake: 110738001000098,
|
|
34
35
|
commission: 7,
|
|
35
36
|
totalScore: 7,
|
|
37
|
+
apy: 0.07228,
|
|
36
38
|
};
|
|
37
39
|
|
|
38
40
|
export const LEDGER_VALIDATOR_DEFAULT = LEDGER_VALIDATOR_BY_FIGMENT;
|