@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.
Files changed (48) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/lib/__tests__/unit/utils.unit.test.d.ts +2 -0
  3. package/lib/__tests__/unit/utils.unit.test.d.ts.map +1 -0
  4. package/lib/__tests__/unit/utils.unit.test.js +16 -0
  5. package/lib/__tests__/unit/utils.unit.test.js.map +1 -0
  6. package/lib/__tests__/unit/validator-app.unit.test.d.ts +2 -0
  7. package/lib/__tests__/unit/validator-app.unit.test.d.ts.map +1 -0
  8. package/lib/__tests__/unit/validator-app.unit.test.js +169 -0
  9. package/lib/__tests__/unit/validator-app.unit.test.js.map +1 -0
  10. package/lib/buildTransaction.d.ts.map +1 -1
  11. package/lib/buildTransaction.js +5 -3
  12. package/lib/buildTransaction.js.map +1 -1
  13. package/lib/network/validator-app/index.d.ts +1 -0
  14. package/lib/network/validator-app/index.d.ts.map +1 -1
  15. package/lib/network/validator-app/index.js +32 -6
  16. package/lib/network/validator-app/index.js.map +1 -1
  17. package/lib/signOperation.test.js +2 -2
  18. package/lib/signOperation.test.js.map +1 -1
  19. package/lib/utils.d.ts.map +1 -1
  20. package/lib/utils.js +4 -2
  21. package/lib/utils.js.map +1 -1
  22. package/lib-es/__tests__/unit/utils.unit.test.d.ts +2 -0
  23. package/lib-es/__tests__/unit/utils.unit.test.d.ts.map +1 -0
  24. package/lib-es/__tests__/unit/utils.unit.test.js +14 -0
  25. package/lib-es/__tests__/unit/utils.unit.test.js.map +1 -0
  26. package/lib-es/__tests__/unit/validator-app.unit.test.d.ts +2 -0
  27. package/lib-es/__tests__/unit/validator-app.unit.test.d.ts.map +1 -0
  28. package/lib-es/__tests__/unit/validator-app.unit.test.js +144 -0
  29. package/lib-es/__tests__/unit/validator-app.unit.test.js.map +1 -0
  30. package/lib-es/buildTransaction.d.ts.map +1 -1
  31. package/lib-es/buildTransaction.js +5 -3
  32. package/lib-es/buildTransaction.js.map +1 -1
  33. package/lib-es/network/validator-app/index.d.ts +1 -0
  34. package/lib-es/network/validator-app/index.d.ts.map +1 -1
  35. package/lib-es/network/validator-app/index.js +32 -6
  36. package/lib-es/network/validator-app/index.js.map +1 -1
  37. package/lib-es/signOperation.test.js +1 -1
  38. package/lib-es/signOperation.test.js.map +1 -1
  39. package/lib-es/utils.d.ts.map +1 -1
  40. package/lib-es/utils.js +4 -2
  41. package/lib-es/utils.js.map +1 -1
  42. package/package.json +8 -8
  43. package/src/__tests__/unit/utils.unit.test.ts +19 -0
  44. package/src/__tests__/unit/validator-app.unit.test.ts +170 -0
  45. package/src/buildTransaction.ts +5 -3
  46. package/src/network/validator-app/index.ts +42 -6
  47. package/src/signOperation.test.ts +1 -1
  48. package/src/utils.ts +4 -2
@@ -1,4 +1,4 @@
1
- import network from "@ledgerhq/live-network/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 response = await network({
45
- method: "GET",
46
- url: URLS.validatorList(cluster),
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
- response.status === 200 ? (response.data as ValidatorsAppValidatorRaw[]) : [];
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/lib/index";
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: 9079057178046828,
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: 10001001000098,
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;