@ledgerhq/coin-aptos 3.0.0-nightly.3 → 3.0.1-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/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +7 -1
- package/CHANGELOG.md +78 -20
- package/lib/__tests__/network/client.test.js +2 -0
- package/lib/__tests__/network/client.test.js.map +1 -1
- package/lib/__tests__/network/validators.test.js +12 -8
- package/lib/__tests__/network/validators.test.js.map +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +6 -0
- package/lib/api/index.js.map +1 -1
- package/lib/network/client.d.ts.map +1 -1
- package/lib/network/client.js +13 -2
- package/lib/network/client.js.map +1 -1
- package/lib/network/graphql/queries.d.ts +0 -3
- package/lib/network/graphql/queries.d.ts.map +1 -1
- package/lib/network/graphql/queries.js +3 -56
- package/lib/network/graphql/queries.js.map +1 -1
- package/lib/network/graphql/types.d.ts +0 -49
- package/lib/network/graphql/types.d.ts.map +1 -1
- package/lib/network/validators.d.ts.map +1 -1
- package/lib/network/validators.js +10 -5
- package/lib/network/validators.js.map +1 -1
- package/lib/preload.d.ts.map +1 -1
- package/lib/preload.js +5 -1
- package/lib/preload.js.map +1 -1
- package/lib-es/__tests__/network/client.test.js +2 -0
- package/lib-es/__tests__/network/client.test.js.map +1 -1
- package/lib-es/__tests__/network/validators.test.js +12 -8
- package/lib-es/__tests__/network/validators.test.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +6 -0
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/network/client.d.ts.map +1 -1
- package/lib-es/network/client.js +14 -3
- package/lib-es/network/client.js.map +1 -1
- package/lib-es/network/graphql/queries.d.ts +0 -3
- package/lib-es/network/graphql/queries.d.ts.map +1 -1
- package/lib-es/network/graphql/queries.js +2 -55
- package/lib-es/network/graphql/queries.js.map +1 -1
- package/lib-es/network/graphql/types.d.ts +0 -49
- package/lib-es/network/graphql/types.d.ts.map +1 -1
- package/lib-es/network/validators.d.ts.map +1 -1
- package/lib-es/network/validators.js +10 -5
- package/lib-es/network/validators.js.map +1 -1
- package/lib-es/preload.d.ts.map +1 -1
- package/lib-es/preload.js +5 -1
- package/lib-es/preload.js.map +1 -1
- package/package.json +12 -11
- package/src/__tests__/network/client.test.ts +2 -0
- package/src/__tests__/network/validators.test.ts +12 -8
- package/src/api/index.ts +15 -1
- package/src/network/client.ts +18 -4
- package/src/network/graphql/queries.ts +2 -58
- package/src/network/graphql/types.ts +0 -58
- package/src/network/validators.ts +16 -6
- package/src/preload.ts +5 -1
|
@@ -18,10 +18,6 @@ export type Scalars = {
|
|
|
18
18
|
timestamp: any;
|
|
19
19
|
timestamptz: any;
|
|
20
20
|
};
|
|
21
|
-
export type GetAccountTransactionsDataQueryVariables = Exact<{
|
|
22
|
-
address?: InputMaybe<Scalars["String"]>;
|
|
23
|
-
limit?: InputMaybe<Scalars["Int"]>;
|
|
24
|
-
}>;
|
|
25
21
|
export type GetAccountTransactionsDataQuery = {
|
|
26
22
|
account_transactions: Array<{
|
|
27
23
|
transaction_version: number;
|
|
@@ -37,32 +33,6 @@ export type GetAccountTransactionsDataGtQuery = {
|
|
|
37
33
|
transaction_version: number;
|
|
38
34
|
}>;
|
|
39
35
|
};
|
|
40
|
-
export type GetAccountTransactionsDataLtQueryVariables = Exact<{
|
|
41
|
-
address?: InputMaybe<Scalars["String"]>;
|
|
42
|
-
limit?: InputMaybe<Scalars["Int"]>;
|
|
43
|
-
lt?: InputMaybe<Scalars["bigint"]>;
|
|
44
|
-
}>;
|
|
45
|
-
export type GetAccountTransactionsDataLtQuery = {
|
|
46
|
-
account_transactions: Array<{
|
|
47
|
-
transaction_version: number;
|
|
48
|
-
}>;
|
|
49
|
-
};
|
|
50
|
-
export type DelegatedStakingActivity = {
|
|
51
|
-
amount: number;
|
|
52
|
-
delegator_address: string;
|
|
53
|
-
event_index: number;
|
|
54
|
-
event_type: string;
|
|
55
|
-
pool_address: string;
|
|
56
|
-
transaction_version: bigint;
|
|
57
|
-
};
|
|
58
|
-
export type GetDelegatedStakingActivitiesQuery = {
|
|
59
|
-
delegated_staking_activities: Array<DelegatedStakingActivity>;
|
|
60
|
-
};
|
|
61
|
-
export type PartitionedDelegatedStakingActivities = Record<string, DelegatedStakingActivity[]>;
|
|
62
|
-
export type StakePrincipals = {
|
|
63
|
-
activePrincipals: number;
|
|
64
|
-
pendingInactivePrincipals: number;
|
|
65
|
-
};
|
|
66
36
|
export type StakeDetails = {
|
|
67
37
|
active: number;
|
|
68
38
|
inactive: number;
|
|
@@ -70,22 +40,6 @@ export type StakeDetails = {
|
|
|
70
40
|
canWithdrawPendingInactive: boolean;
|
|
71
41
|
poolAddress: string;
|
|
72
42
|
};
|
|
73
|
-
export type GetNumActiveDelegatorPerPoolQuery = {
|
|
74
|
-
num_active_delegator_per_pool: Array<{
|
|
75
|
-
pool_address: string;
|
|
76
|
-
num_active_delegator: number;
|
|
77
|
-
}>;
|
|
78
|
-
delegated_staking_pools: Array<{
|
|
79
|
-
staking_pool_address: string;
|
|
80
|
-
current_staking_pool: {
|
|
81
|
-
operator_address: string;
|
|
82
|
-
operator_aptos_name: Array<{
|
|
83
|
-
domain: string;
|
|
84
|
-
is_primary: boolean;
|
|
85
|
-
}>;
|
|
86
|
-
};
|
|
87
|
-
}>;
|
|
88
|
-
};
|
|
89
43
|
export type GetCurrentDelegatorBalancesQuery = {
|
|
90
44
|
current_delegator_balances: Array<{
|
|
91
45
|
current_pool_balance: {
|
|
@@ -104,9 +58,6 @@ export type GetCurrentDelegatorBalancesQuery = {
|
|
|
104
58
|
};
|
|
105
59
|
}>;
|
|
106
60
|
};
|
|
107
|
-
export interface DelegationPoolAddress {
|
|
108
|
-
staking_pool_address: string;
|
|
109
|
-
}
|
|
110
61
|
interface CurrentPoolBalance {
|
|
111
62
|
total_coins: string;
|
|
112
63
|
operator_commission_percentage: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/network/graphql/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAChC,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC;AACrC,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AACnF,qEAAqE;AACrE,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,GAAG,CAAC;IACZ,KAAK,EAAE,GAAG,CAAC;IACX,OAAO,EAAE,GAAG,CAAC;IACb,SAAS,EAAE,GAAG,CAAC;IACf,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/network/graphql/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAChC,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC;AACrC,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AACnF,qEAAqE;AACrE,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,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F,MAAM,EAAE,MAAM,CAAC;QACf,iBAAiB,EAAE,MAAM,CAAC;QAC1B,qBAAqB,EAAE;YACrB,mBAAmB,EAAE;gBACnB,kBAAkB,EAAE,MAAM,CAAC;gBAC3B,SAAS,EAAE,OAAO,CAAC;aACpB,CAAC;SACH,CAAC;KACH,CAAC,CAAC;CACJ,CAAC;AAEF,UAAU,kBAAkB;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,8BAA8B,EAAE,MAAM,CAAC;IACvC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,mBAAmB;IAC3B,mBAAmB,EAAE,iBAAiB,CAAC;CACxC;AAED,UAAU,iBAAiB;IACzB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oBAAoB,EAAE,kBAAkB,CAAC;IACzC,qBAAqB,EAAE,mBAAmB,CAAC;CAC5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/network/validators.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/network/validators.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAM1C,wBAAsB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAiCjF"}
|
|
@@ -4,13 +4,10 @@ import { GetCurrentDelegatorBalancesData } from "./graphql/queries";
|
|
|
4
4
|
import { isTestnet } from "../logic/isTestnet";
|
|
5
5
|
import { APTOS_EXPLORER_ACCOUNT_URL } from "../constants";
|
|
6
6
|
import { formatUnlockTime } from "../logic/staking";
|
|
7
|
+
import { makeLRUCache, minutes } from "@ledgerhq/live-network/cache";
|
|
7
8
|
export async function getValidators(currencyId) {
|
|
8
9
|
const api = new AptosAPI(currencyId);
|
|
9
|
-
const
|
|
10
|
-
const queryResponse = await api.apolloClient.query({
|
|
11
|
-
query: query,
|
|
12
|
-
fetchPolicy: "network-only",
|
|
13
|
-
});
|
|
10
|
+
const queryResponse = await cachedValidators(api, currencyId);
|
|
14
11
|
const stakingData = queryResponse.data.current_delegator_balances;
|
|
15
12
|
const list = await Promise.all(stakingData.map(async (pool) => {
|
|
16
13
|
const aptosName = pool.staking_pool_metadata.operator_aptos_name;
|
|
@@ -32,4 +29,12 @@ export async function getValidators(currencyId) {
|
|
|
32
29
|
}));
|
|
33
30
|
return list.sort((a, b) => b.activeStake.toNumber() - a.activeStake.toNumber());
|
|
34
31
|
}
|
|
32
|
+
const fetchValidatorsData = async (api, _currencyId) => {
|
|
33
|
+
const query = GetCurrentDelegatorBalancesData;
|
|
34
|
+
return await api.apolloClient.query({
|
|
35
|
+
query: query,
|
|
36
|
+
fetchPolicy: "network-only",
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const cachedValidators = makeLRUCache(fetchValidatorsData, (_api, currencyId) => currencyId, minutes(30));
|
|
35
40
|
//# sourceMappingURL=validators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/network/validators.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,+BAA+B,EAAE,MAAM,mBAAmB,CAAC;AAGpE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version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Z,CAAC"}
|
package/lib-es/preload.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preload.d.ts","sourceRoot":"","sources":["../src/preload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAkB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"preload.d.ts","sourceRoot":"","sources":["../src/preload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAkB,MAAM,SAAS,CAAC;AAI3D,eAAO,MAAM,eAAe,QAAiB,CAAC;AAE9C,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAc/F;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,gBAAgB,EAAE,QAAQ,EAAE,cAAc,GAAG,IAAI,CAE9E"}
|
package/lib-es/preload.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { setAptosPreloadData } from "./preload-data";
|
|
2
2
|
import { getValidators } from "./network/validators";
|
|
3
|
+
import { getEnv } from "@ledgerhq/live-env";
|
|
3
4
|
export const PRELOAD_MAX_AGE = 15 * 60 * 1000; // 15min
|
|
4
5
|
export async function preloadWithValidators(currency) {
|
|
5
|
-
|
|
6
|
+
let validators = [];
|
|
7
|
+
if (getEnv("APTOS_ENABLE_STAKING") === true) {
|
|
8
|
+
validators = await getValidators(currency.id);
|
|
9
|
+
}
|
|
6
10
|
const data = {
|
|
7
11
|
validatorsWithMeta: [],
|
|
8
12
|
validators,
|
package/lib-es/preload.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preload.js","sourceRoot":"","sources":["../src/preload.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"preload.js","sourceRoot":"","sources":["../src/preload.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,QAAQ;AAEvD,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,QAAwB;IAClE,IAAI,UAAU,GAAqB,EAAE,CAAC;IACtC,IAAI,MAAM,CAAC,sBAAsB,CAAC,KAAK,IAAI,EAAE,CAAC;QAC5C,UAAU,GAAG,MAAM,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAChD,CAAC;IAED,MAAM,IAAI,GAAqB;QAC7B,kBAAkB,EAAE,EAAE;QACtB,UAAU;KACX,CAAC;IAEF,mBAAmB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAEpC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,IAAsB,EAAE,QAAwB;IACtE,mBAAmB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACtC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-aptos",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1-nightly.0",
|
|
4
4
|
"description": "Ledger Aptos Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -86,23 +86,24 @@
|
|
|
86
86
|
"license": "Apache-2.0",
|
|
87
87
|
"dependencies": {
|
|
88
88
|
"@apollo/client": "^3.12.6",
|
|
89
|
-
"@aptos-labs/ts-sdk": "^1.
|
|
89
|
+
"@aptos-labs/ts-sdk": "^3.1.3",
|
|
90
90
|
"@noble/hashes": "1.7.0",
|
|
91
91
|
"bignumber.js": "^9.1.2",
|
|
92
92
|
"expect": "^27.4.6",
|
|
93
|
+
"got": "11.8.2",
|
|
93
94
|
"graphql": "^16.10.0",
|
|
94
95
|
"invariant": "^2.2.4",
|
|
95
96
|
"lodash": "^4.17.21",
|
|
96
97
|
"rxjs": "^7.8.1",
|
|
97
|
-
"@ledgerhq/coin-framework": "^6.0.
|
|
98
|
-
"@ledgerhq/cryptoassets": "^13.
|
|
99
|
-
"@ledgerhq/types-cryptoassets": "^7.
|
|
100
|
-
"@ledgerhq/devices": "8.4.
|
|
101
|
-
"@ledgerhq/errors": "^6.
|
|
102
|
-
"@ledgerhq/live-env": "^2.
|
|
103
|
-
"@ledgerhq/live-network": "^2.0.
|
|
98
|
+
"@ledgerhq/coin-framework": "^6.0.1-nightly.0",
|
|
99
|
+
"@ledgerhq/cryptoassets": "^13.24.1-nightly.0",
|
|
100
|
+
"@ledgerhq/types-cryptoassets": "^7.25.0",
|
|
101
|
+
"@ledgerhq/devices": "8.4.9-nightly.1",
|
|
102
|
+
"@ledgerhq/errors": "^6.24.0-nightly.0",
|
|
103
|
+
"@ledgerhq/live-env": "^2.14.0-nightly.0",
|
|
104
|
+
"@ledgerhq/live-network": "^2.0.15-nightly.0",
|
|
104
105
|
"@ledgerhq/logs": "^6.13.0",
|
|
105
|
-
"@ledgerhq/types-live": "^6.
|
|
106
|
+
"@ledgerhq/types-live": "^6.80.0"
|
|
106
107
|
},
|
|
107
108
|
"devDependencies": {
|
|
108
109
|
"@faker-js/faker": "^9.4.0",
|
|
@@ -115,7 +116,7 @@
|
|
|
115
116
|
"react": "^18.3.1",
|
|
116
117
|
"ts-jest": "^29.2.5",
|
|
117
118
|
"@ledgerhq/disable-network-setup": "^0.0.0",
|
|
118
|
-
"@ledgerhq/types-cryptoassets": "^7.
|
|
119
|
+
"@ledgerhq/types-cryptoassets": "^7.25.0"
|
|
119
120
|
},
|
|
120
121
|
"scripts": {
|
|
121
122
|
"clean": "rimraf lib lib-es",
|
|
@@ -865,6 +865,7 @@ describe("Aptos API", () => {
|
|
|
865
865
|
const txs: AptosTransaction[] = [
|
|
866
866
|
{
|
|
867
867
|
version: "2532591427",
|
|
868
|
+
replay_protection_nonce: "replay_protection_nonce",
|
|
868
869
|
hash: "0x3f35",
|
|
869
870
|
state_change_hash: "0xb480",
|
|
870
871
|
event_root_hash: "0x3fa1",
|
|
@@ -1078,6 +1079,7 @@ describe("Aptos API", () => {
|
|
|
1078
1079
|
},
|
|
1079
1080
|
{
|
|
1080
1081
|
version: "2532549325",
|
|
1082
|
+
replay_protection_nonce: "replay_protection_nonce",
|
|
1081
1083
|
hash: "0x9a6b",
|
|
1082
1084
|
state_change_hash: "0xa424",
|
|
1083
1085
|
event_root_hash: "0x0321",
|
|
@@ -83,23 +83,27 @@ describe("getValidators", () => {
|
|
|
83
83
|
},
|
|
84
84
|
];
|
|
85
85
|
|
|
86
|
-
it("returns the correct information", async () => {
|
|
86
|
+
it("returns the correct information and caches the 2nd call", async () => {
|
|
87
87
|
mockedAptos.mockImplementation(() => ({
|
|
88
88
|
getAccountResource: async () => ({ locked_until_secs: "1750051574" }),
|
|
89
89
|
}));
|
|
90
90
|
|
|
91
|
+
const mockedGetValidatorsQuery = jest.fn().mockImplementation(async () => ({
|
|
92
|
+
data: {
|
|
93
|
+
current_delegator_balances,
|
|
94
|
+
},
|
|
95
|
+
}));
|
|
91
96
|
mockedApolloClient.mockImplementation(() => ({
|
|
92
|
-
query:
|
|
93
|
-
data: {
|
|
94
|
-
current_delegator_balances,
|
|
95
|
-
},
|
|
96
|
-
}),
|
|
97
|
+
query: mockedGetValidatorsQuery,
|
|
97
98
|
}));
|
|
98
99
|
|
|
99
100
|
jest.useFakeTimers().setSystemTime(new Date("2025-05-15"));
|
|
100
101
|
|
|
101
|
-
const
|
|
102
|
+
const validators1 = await getValidators("aptos");
|
|
103
|
+
const validators2 = await getValidators("aptos");
|
|
102
104
|
|
|
103
|
-
expect(
|
|
105
|
+
expect(validators1).toMatchObject(expectedResponse);
|
|
106
|
+
expect(validators1).toMatchObject(validators2);
|
|
107
|
+
expect(mockedGetValidatorsQuery.mock.calls.length).toBe(1);
|
|
104
108
|
});
|
|
105
109
|
});
|
package/src/api/index.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
AlpacaApi,
|
|
3
|
+
Block,
|
|
4
|
+
BlockInfo,
|
|
5
|
+
Cursor,
|
|
6
|
+
Stake,
|
|
7
|
+
Reward,
|
|
8
|
+
Page,
|
|
9
|
+
} from "@ledgerhq/coin-framework/api/index";
|
|
2
10
|
import type { AptosConfig as AptosConfigApi } from "../config";
|
|
3
11
|
import type { Balance, Pagination, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
4
12
|
import coinConfig from "../config";
|
|
@@ -28,5 +36,11 @@ export function createApi(config: AptosConfigApi): AlpacaApi {
|
|
|
28
36
|
getBlockInfo(_height: number): Promise<BlockInfo> {
|
|
29
37
|
throw new Error("getBlockInfo is not supported");
|
|
30
38
|
},
|
|
39
|
+
getStakes(_address: string, _cursor?: Cursor): Promise<Page<Stake>> {
|
|
40
|
+
throw new Error("getStakes is not supported");
|
|
41
|
+
},
|
|
42
|
+
getRewards(_address: string, _cursor?: Cursor): Promise<Page<Reward>> {
|
|
43
|
+
throw new Error("getRewards is not supported");
|
|
44
|
+
},
|
|
31
45
|
};
|
|
32
46
|
}
|
package/src/network/client.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
Hex,
|
|
19
19
|
postAptosFullNode,
|
|
20
20
|
type PendingTransactionResponse,
|
|
21
|
+
Network,
|
|
21
22
|
} from "@aptos-labs/ts-sdk";
|
|
22
23
|
import { getEnv } from "@ledgerhq/live-env";
|
|
23
24
|
import network from "@ledgerhq/live-network";
|
|
@@ -59,6 +60,8 @@ const getIndexerEndpoint = (currencyId: string) =>
|
|
|
59
60
|
isTestnet(currencyId)
|
|
60
61
|
? getEnv("APTOS_TESTNET_INDEXER_ENDPOINT")
|
|
61
62
|
: getEnv("APTOS_INDEXER_ENDPOINT");
|
|
63
|
+
const getNetwork = (currencyId: string) =>
|
|
64
|
+
isTestnet(currencyId) ? Network.TESTNET : Network.MAINNET;
|
|
62
65
|
|
|
63
66
|
export class AptosAPI {
|
|
64
67
|
private readonly aptosConfig: AptosConfig;
|
|
@@ -67,10 +70,18 @@ export class AptosAPI {
|
|
|
67
70
|
readonly apolloClient: ApolloClient<object>;
|
|
68
71
|
|
|
69
72
|
constructor(currencyIdOrSettings: AptosSettings | string) {
|
|
73
|
+
const appVersion = getEnv("LEDGER_CLIENT_VERSION");
|
|
74
|
+
|
|
70
75
|
if (typeof currencyIdOrSettings === "string") {
|
|
71
76
|
this.aptosConfig = new AptosConfig({
|
|
77
|
+
network: getNetwork(currencyIdOrSettings),
|
|
72
78
|
fullnode: getApiEndpoint(currencyIdOrSettings),
|
|
73
79
|
indexer: getIndexerEndpoint(currencyIdOrSettings),
|
|
80
|
+
clientConfig: {
|
|
81
|
+
HEADERS: {
|
|
82
|
+
"X-Ledger-Client-Version": appVersion,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
74
85
|
});
|
|
75
86
|
} else {
|
|
76
87
|
this.aptosConfig = new AptosConfig(currencyIdOrSettings);
|
|
@@ -81,7 +92,7 @@ export class AptosAPI {
|
|
|
81
92
|
uri: this.aptosConfig.indexer ?? "",
|
|
82
93
|
cache: new InMemoryCache(),
|
|
83
94
|
headers: {
|
|
84
|
-
"
|
|
95
|
+
"X-Ledger-Client-Version": appVersion,
|
|
85
96
|
},
|
|
86
97
|
});
|
|
87
98
|
}
|
|
@@ -298,9 +309,12 @@ export class AptosAPI {
|
|
|
298
309
|
});
|
|
299
310
|
|
|
300
311
|
return Promise.all(
|
|
301
|
-
queryResponse.data.account_transactions
|
|
302
|
-
|
|
303
|
-
|
|
312
|
+
queryResponse.data.account_transactions
|
|
313
|
+
.slice()
|
|
314
|
+
.sort((a, b) => b.transaction_version - a.transaction_version)
|
|
315
|
+
.map(({ transaction_version }) => {
|
|
316
|
+
return this.richItemByVersion(transaction_version);
|
|
317
|
+
}),
|
|
304
318
|
);
|
|
305
319
|
}
|
|
306
320
|
|
|
@@ -1,28 +1,8 @@
|
|
|
1
1
|
import { gql } from "@apollo/client";
|
|
2
2
|
|
|
3
|
-
export const GetDelegatedStakingActivities = gql`
|
|
4
|
-
query getDelegatedStakingActivities($delegatorAddress: String) {
|
|
5
|
-
delegated_staking_activities(
|
|
6
|
-
where: { delegator_address: { _eq: $delegatorAddress } }
|
|
7
|
-
order_by: { transaction_version: asc }
|
|
8
|
-
) {
|
|
9
|
-
amount
|
|
10
|
-
delegator_address
|
|
11
|
-
event_index
|
|
12
|
-
event_type
|
|
13
|
-
pool_address
|
|
14
|
-
transaction_version
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
`;
|
|
18
|
-
|
|
19
3
|
export const GetAccountTransactionsData = gql`
|
|
20
4
|
query GetAccountTransactionsData($address: String, $limit: Int) {
|
|
21
|
-
account_transactions(
|
|
22
|
-
where: { account_address: { _eq: $address } }
|
|
23
|
-
order_by: { transaction_version: desc }
|
|
24
|
-
limit: $limit
|
|
25
|
-
) {
|
|
5
|
+
account_transactions(where: { account_address: { _eq: $address } }, limit: $limit) {
|
|
26
6
|
transaction_version
|
|
27
7
|
__typename
|
|
28
8
|
}
|
|
@@ -33,7 +13,6 @@ export const GetAccountTransactionsDataGt = gql`
|
|
|
33
13
|
query GetAccountTransactionsDataGt($address: String, $limit: Int, $gt: bigint) {
|
|
34
14
|
account_transactions(
|
|
35
15
|
where: { account_address: { _eq: $address }, transaction_version: { _gt: $gt } }
|
|
36
|
-
order_by: { transaction_version: desc }
|
|
37
16
|
limit: $limit
|
|
38
17
|
) {
|
|
39
18
|
transaction_version
|
|
@@ -42,44 +21,9 @@ export const GetAccountTransactionsDataGt = gql`
|
|
|
42
21
|
}
|
|
43
22
|
`;
|
|
44
23
|
|
|
45
|
-
export const GetAccountTransactionsDataLt = gql`
|
|
46
|
-
query GetAccountTransactionsDataLt($address: String, $limit: Int, $lt: bigint) {
|
|
47
|
-
account_transactions(
|
|
48
|
-
where: { account_address: { _eq: $address }, transaction_version: { _lt: $lt } }
|
|
49
|
-
order_by: { transaction_version: desc }
|
|
50
|
-
limit: $limit
|
|
51
|
-
) {
|
|
52
|
-
transaction_version
|
|
53
|
-
__typename
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
`;
|
|
57
|
-
|
|
58
|
-
export const GetNumActiveDelegatorPerPoolData = gql`
|
|
59
|
-
query GetNumActiveDelegatorPerPoolData {
|
|
60
|
-
num_active_delegator_per_pool {
|
|
61
|
-
num_active_delegator
|
|
62
|
-
pool_address
|
|
63
|
-
}
|
|
64
|
-
delegated_staking_pools {
|
|
65
|
-
staking_pool_address
|
|
66
|
-
current_staking_pool {
|
|
67
|
-
operator_address
|
|
68
|
-
operator_aptos_name(where: { is_active: { _eq: true } }) {
|
|
69
|
-
domain
|
|
70
|
-
is_primary
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
`;
|
|
76
|
-
|
|
77
24
|
export const GetCurrentDelegatorBalancesData = gql`
|
|
78
25
|
query GetCurrentDelegatorBalances {
|
|
79
|
-
current_delegator_balances(
|
|
80
|
-
distinct_on: pool_address
|
|
81
|
-
order_by: { current_pool_balance: { total_coins: desc }, pool_address: asc }
|
|
82
|
-
) {
|
|
26
|
+
current_delegator_balances(distinct_on: pool_address) {
|
|
83
27
|
current_pool_balance {
|
|
84
28
|
total_coins
|
|
85
29
|
operator_commission_percentage
|
|
@@ -15,11 +15,6 @@ export type Scalars = {
|
|
|
15
15
|
timestamptz: any;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
export type GetAccountTransactionsDataQueryVariables = Exact<{
|
|
19
|
-
address?: InputMaybe<Scalars["String"]>;
|
|
20
|
-
limit?: InputMaybe<Scalars["Int"]>;
|
|
21
|
-
}>;
|
|
22
|
-
|
|
23
18
|
export type GetAccountTransactionsDataQuery = {
|
|
24
19
|
account_transactions: Array<{
|
|
25
20
|
transaction_version: number;
|
|
@@ -38,38 +33,6 @@ export type GetAccountTransactionsDataGtQuery = {
|
|
|
38
33
|
}>;
|
|
39
34
|
};
|
|
40
35
|
|
|
41
|
-
export type GetAccountTransactionsDataLtQueryVariables = Exact<{
|
|
42
|
-
address?: InputMaybe<Scalars["String"]>;
|
|
43
|
-
limit?: InputMaybe<Scalars["Int"]>;
|
|
44
|
-
lt?: InputMaybe<Scalars["bigint"]>;
|
|
45
|
-
}>;
|
|
46
|
-
|
|
47
|
-
export type GetAccountTransactionsDataLtQuery = {
|
|
48
|
-
account_transactions: Array<{
|
|
49
|
-
transaction_version: number;
|
|
50
|
-
}>;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export type DelegatedStakingActivity = {
|
|
54
|
-
amount: number;
|
|
55
|
-
delegator_address: string;
|
|
56
|
-
event_index: number;
|
|
57
|
-
event_type: string;
|
|
58
|
-
pool_address: string;
|
|
59
|
-
transaction_version: bigint;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export type GetDelegatedStakingActivitiesQuery = {
|
|
63
|
-
delegated_staking_activities: Array<DelegatedStakingActivity>;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export type PartitionedDelegatedStakingActivities = Record<string, DelegatedStakingActivity[]>;
|
|
67
|
-
|
|
68
|
-
export type StakePrincipals = {
|
|
69
|
-
activePrincipals: number;
|
|
70
|
-
pendingInactivePrincipals: number;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
36
|
export type StakeDetails = {
|
|
74
37
|
active: number;
|
|
75
38
|
inactive: number;
|
|
@@ -78,23 +41,6 @@ export type StakeDetails = {
|
|
|
78
41
|
poolAddress: string;
|
|
79
42
|
};
|
|
80
43
|
|
|
81
|
-
export type GetNumActiveDelegatorPerPoolQuery = {
|
|
82
|
-
num_active_delegator_per_pool: Array<{
|
|
83
|
-
pool_address: string;
|
|
84
|
-
num_active_delegator: number;
|
|
85
|
-
}>;
|
|
86
|
-
delegated_staking_pools: Array<{
|
|
87
|
-
staking_pool_address: string;
|
|
88
|
-
current_staking_pool: {
|
|
89
|
-
operator_address: string;
|
|
90
|
-
operator_aptos_name: Array<{
|
|
91
|
-
domain: string;
|
|
92
|
-
is_primary: boolean;
|
|
93
|
-
}>;
|
|
94
|
-
};
|
|
95
|
-
}>;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
44
|
export type GetCurrentDelegatorBalancesQuery = {
|
|
99
45
|
current_delegator_balances: Array<{
|
|
100
46
|
current_pool_balance: {
|
|
@@ -114,10 +60,6 @@ export type GetCurrentDelegatorBalancesQuery = {
|
|
|
114
60
|
}>;
|
|
115
61
|
};
|
|
116
62
|
|
|
117
|
-
export interface DelegationPoolAddress {
|
|
118
|
-
staking_pool_address: string;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
63
|
interface CurrentPoolBalance {
|
|
122
64
|
total_coins: string;
|
|
123
65
|
operator_commission_percentage: string;
|
|
@@ -6,15 +6,11 @@ import { AptosValidator } from "../types";
|
|
|
6
6
|
import { isTestnet } from "../logic/isTestnet";
|
|
7
7
|
import { APTOS_EXPLORER_ACCOUNT_URL } from "../constants";
|
|
8
8
|
import { formatUnlockTime } from "../logic/staking";
|
|
9
|
+
import { makeLRUCache, minutes } from "@ledgerhq/live-network/cache";
|
|
9
10
|
|
|
10
11
|
export async function getValidators(currencyId: string): Promise<AptosValidator[]> {
|
|
11
12
|
const api = new AptosAPI(currencyId);
|
|
12
|
-
const
|
|
13
|
-
const queryResponse = await api.apolloClient.query<GetCurrentDelegatorBalancesQuery, object>({
|
|
14
|
-
query: query,
|
|
15
|
-
fetchPolicy: "network-only",
|
|
16
|
-
});
|
|
17
|
-
|
|
13
|
+
const queryResponse = await cachedValidators(api, currencyId);
|
|
18
14
|
const stakingData: CurrentDelegatorBalance[] = queryResponse.data.current_delegator_balances;
|
|
19
15
|
|
|
20
16
|
const list: AptosValidator[] = await Promise.all(
|
|
@@ -46,3 +42,17 @@ export async function getValidators(currencyId: string): Promise<AptosValidator[
|
|
|
46
42
|
|
|
47
43
|
return list.sort((a, b) => b.activeStake.toNumber() - a.activeStake.toNumber());
|
|
48
44
|
}
|
|
45
|
+
|
|
46
|
+
const fetchValidatorsData = async (api: AptosAPI, _currencyId: string) => {
|
|
47
|
+
const query = GetCurrentDelegatorBalancesData;
|
|
48
|
+
return await api.apolloClient.query<GetCurrentDelegatorBalancesQuery, object>({
|
|
49
|
+
query: query,
|
|
50
|
+
fetchPolicy: "network-only",
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const cachedValidators = makeLRUCache(
|
|
55
|
+
fetchValidatorsData,
|
|
56
|
+
(_api: AptosAPI, currencyId: string) => currencyId,
|
|
57
|
+
minutes(30),
|
|
58
|
+
);
|
package/src/preload.ts
CHANGED
|
@@ -2,11 +2,15 @@ import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
|
2
2
|
import { setAptosPreloadData } from "./preload-data";
|
|
3
3
|
import { AptosPreloadData, AptosValidator } from "./types";
|
|
4
4
|
import { getValidators } from "./network/validators";
|
|
5
|
+
import { getEnv } from "@ledgerhq/live-env";
|
|
5
6
|
|
|
6
7
|
export const PRELOAD_MAX_AGE = 15 * 60 * 1000; // 15min
|
|
7
8
|
|
|
8
9
|
export async function preloadWithValidators(currency: CryptoCurrency): Promise<AptosPreloadData> {
|
|
9
|
-
|
|
10
|
+
let validators: AptosValidator[] = [];
|
|
11
|
+
if (getEnv("APTOS_ENABLE_STAKING") === true) {
|
|
12
|
+
validators = await getValidators(currency.id);
|
|
13
|
+
}
|
|
10
14
|
|
|
11
15
|
const data: AptosPreloadData = {
|
|
12
16
|
validatorsWithMeta: [],
|