@ledgerhq/coin-aptos 2.5.1 → 2.5.2-nightly.1
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 +5 -8
- package/CHANGELOG.md +18 -0
- package/lib/__tests__/bridge/deviceTransactionConfig.test.js +115 -30
- package/lib/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -1
- package/lib/__tests__/bridge/getFeesForTransaction.test.js +10 -10
- package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/getTransactionStatus.test.js +193 -2
- package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
- package/lib/__tests__/bridge/index.test.js +4 -1
- package/lib/__tests__/bridge/index.test.js.map +1 -1
- package/lib/__tests__/bridge/logic.test.js +9 -9
- package/lib/__tests__/bridge/logic.test.js.map +1 -1
- package/lib/__tests__/bridge/prepareTransaction.test.js +1 -0
- package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -1
- package/lib/__tests__/bridge/serialization.d.ts +2 -0
- package/lib/__tests__/bridge/serialization.d.ts.map +1 -0
- package/lib/__tests__/bridge/serialization.js +91 -0
- package/lib/__tests__/bridge/serialization.js.map +1 -0
- package/lib/__tests__/bridge/synchronisation.test.js +763 -23
- package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib/__tests__/logic/staking.test.d.ts +2 -0
- package/lib/__tests__/logic/staking.test.d.ts.map +1 -0
- package/lib/__tests__/logic/staking.test.js +202 -0
- package/lib/__tests__/logic/staking.test.js.map +1 -0
- package/lib/__tests__/network/client.test.js +3 -3
- package/lib/__tests__/network/validators.test.d.ts +2 -0
- package/lib/__tests__/network/validators.test.d.ts.map +1 -0
- package/lib/__tests__/network/validators.test.js +98 -0
- package/lib/__tests__/network/validators.test.js.map +1 -0
- package/lib/__tests__/utils/IconGenerator.test.d.ts +2 -0
- package/lib/__tests__/utils/IconGenerator.test.d.ts.map +1 -0
- package/lib/__tests__/utils/IconGenerator.test.js +14 -0
- package/lib/__tests__/utils/IconGenerator.test.js.map +1 -0
- package/lib/__tests__/utils/index.test.d.ts +2 -0
- package/lib/__tests__/utils/index.test.d.ts.map +1 -0
- package/lib/__tests__/utils/index.test.js +11 -0
- package/lib/__tests__/utils/index.test.js.map +1 -0
- package/lib/bridge/bridge.fixture.d.ts.map +1 -1
- package/lib/bridge/bridge.fixture.js +12 -0
- package/lib/bridge/bridge.fixture.js.map +1 -1
- package/lib/bridge/deviceTransactionConfig.d.ts +7 -8
- package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/bridge/deviceTransactionConfig.js +83 -16
- package/lib/bridge/deviceTransactionConfig.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.d.ts +4 -4
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +1 -1
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib/bridge/getFeesForTransaction.js +8 -4
- package/lib/bridge/getFeesForTransaction.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts +2 -3
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +139 -25
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/index.d.ts +3 -3
- package/lib/bridge/index.d.ts.map +1 -1
- package/lib/bridge/index.js +9 -2
- package/lib/bridge/index.js.map +1 -1
- package/lib/bridge/logic.d.ts +3 -3
- package/lib/bridge/logic.d.ts.map +1 -1
- package/lib/bridge/logic.js +23 -9
- package/lib/bridge/logic.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts +2 -3
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +46 -10
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/serialization.d.ts +7 -0
- package/lib/bridge/serialization.d.ts.map +1 -0
- package/lib/bridge/serialization.js +51 -0
- package/lib/bridge/serialization.js.map +1 -0
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +17 -5
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts +6 -4
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +51 -4
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/constants.d.ts +25 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +54 -8
- package/lib/constants.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -15
- package/lib/index.js.map +1 -1
- package/lib/logic/buildTransaction.d.ts.map +1 -1
- package/lib/logic/buildTransaction.js +42 -19
- package/lib/logic/buildTransaction.js.map +1 -1
- package/lib/logic/getCoinAndAmounts.d.ts +2 -0
- package/lib/logic/getCoinAndAmounts.d.ts.map +1 -1
- package/lib/logic/getCoinAndAmounts.js +65 -38
- package/lib/logic/getCoinAndAmounts.js.map +1 -1
- package/lib/logic/staking.d.ts +12 -0
- package/lib/logic/staking.d.ts.map +1 -0
- package/lib/logic/staking.js +81 -0
- package/lib/logic/staking.js.map +1 -0
- package/lib/logic/transactionsToOperations.js +3 -3
- package/lib/logic/transactionsToOperations.js.map +1 -1
- package/lib/network/client.d.ts +4 -1
- package/lib/network/client.d.ts.map +1 -1
- package/lib/network/client.js +32 -1
- package/lib/network/client.js.map +1 -1
- package/lib/network/graphql/queries.d.ts +2 -0
- package/lib/network/graphql/queries.d.ts.map +1 -1
- package/lib/network/graphql/queries.js +42 -2
- package/lib/network/graphql/queries.js.map +1 -1
- package/lib/network/graphql/types.d.ts +57 -6
- package/lib/network/graphql/types.d.ts.map +1 -1
- package/lib/network/index.d.ts.map +1 -1
- package/lib/network/index.js.map +1 -1
- package/lib/network/validators.d.ts +3 -0
- package/lib/network/validators.d.ts.map +1 -0
- package/lib/network/validators.js +42 -0
- package/lib/network/validators.js.map +1 -0
- package/lib/preload-data.d.ts +7 -0
- package/lib/preload-data.d.ts.map +1 -0
- package/lib/preload-data.js +42 -0
- package/lib/preload-data.js.map +1 -0
- package/lib/preload.d.ts +6 -0
- package/lib/preload.d.ts.map +1 -0
- package/lib/preload.js +21 -0
- package/lib/preload.js.map +1 -0
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib/test/bridgeDatasetTest.js +1 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -1
- package/lib/types/index.d.ts +92 -8
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js.map +1 -1
- package/lib/utils/IconGenerator.d.ts +12 -0
- package/lib/utils/IconGenerator.d.ts.map +1 -0
- package/lib/utils/IconGenerator.js +138 -0
- package/lib/utils/IconGenerator.js.map +1 -0
- package/lib/utils/index.d.ts +3 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/lib/utils/index.js +31 -0
- package/lib/utils/index.js.map +1 -0
- package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js +113 -8
- package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -1
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +10 -10
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/getTransactionStatus.test.js +194 -3
- package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
- package/lib-es/__tests__/bridge/index.test.js +4 -1
- package/lib-es/__tests__/bridge/index.test.js.map +1 -1
- package/lib-es/__tests__/bridge/logic.test.js +10 -10
- package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
- package/lib-es/__tests__/bridge/prepareTransaction.test.js +1 -0
- package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -1
- package/lib-es/__tests__/bridge/serialization.d.ts +2 -0
- package/lib-es/__tests__/bridge/serialization.d.ts.map +1 -0
- package/lib-es/__tests__/bridge/serialization.js +86 -0
- package/lib-es/__tests__/bridge/serialization.js.map +1 -0
- package/lib-es/__tests__/bridge/synchronisation.test.js +763 -23
- package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
- package/lib-es/__tests__/logic/staking.test.d.ts +2 -0
- package/lib-es/__tests__/logic/staking.test.d.ts.map +1 -0
- package/lib-es/__tests__/logic/staking.test.js +197 -0
- package/lib-es/__tests__/logic/staking.test.js.map +1 -0
- package/lib-es/__tests__/network/client.test.js +3 -3
- package/lib-es/__tests__/network/validators.test.d.ts +2 -0
- package/lib-es/__tests__/network/validators.test.d.ts.map +1 -0
- package/lib-es/__tests__/network/validators.test.js +93 -0
- package/lib-es/__tests__/network/validators.test.js.map +1 -0
- package/lib-es/__tests__/utils/IconGenerator.test.d.ts +2 -0
- package/lib-es/__tests__/utils/IconGenerator.test.d.ts.map +1 -0
- package/lib-es/__tests__/utils/IconGenerator.test.js +12 -0
- package/lib-es/__tests__/utils/IconGenerator.test.js.map +1 -0
- package/lib-es/__tests__/utils/index.test.d.ts +2 -0
- package/lib-es/__tests__/utils/index.test.d.ts.map +1 -0
- package/lib-es/__tests__/utils/index.test.js +9 -0
- package/lib-es/__tests__/utils/index.test.js.map +1 -0
- package/lib-es/bridge/bridge.fixture.d.ts.map +1 -1
- package/lib-es/bridge/bridge.fixture.js +12 -0
- package/lib-es/bridge/bridge.fixture.js.map +1 -1
- package/lib-es/bridge/deviceTransactionConfig.d.ts +7 -8
- package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -1
- package/lib-es/bridge/deviceTransactionConfig.js +83 -14
- package/lib-es/bridge/deviceTransactionConfig.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -4
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
- package/lib-es/bridge/getFeesForTransaction.js +9 -5
- package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts +2 -3
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +140 -26
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/index.d.ts +3 -3
- package/lib-es/bridge/index.d.ts.map +1 -1
- package/lib-es/bridge/index.js +9 -2
- package/lib-es/bridge/index.js.map +1 -1
- package/lib-es/bridge/logic.d.ts +3 -3
- package/lib-es/bridge/logic.d.ts.map +1 -1
- package/lib-es/bridge/logic.js +23 -9
- package/lib-es/bridge/logic.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.d.ts +2 -3
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +46 -10
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/serialization.d.ts +7 -0
- package/lib-es/bridge/serialization.d.ts.map +1 -0
- package/lib-es/bridge/serialization.js +41 -0
- package/lib-es/bridge/serialization.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +17 -5
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts +6 -4
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +49 -3
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/constants.d.ts +25 -1
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +53 -7
- package/lib-es/constants.js.map +1 -1
- package/lib-es/index.d.ts +0 -1
- package/lib-es/index.d.ts.map +1 -1
- package/lib-es/index.js +0 -1
- package/lib-es/index.js.map +1 -1
- package/lib-es/logic/buildTransaction.d.ts.map +1 -1
- package/lib-es/logic/buildTransaction.js +42 -19
- package/lib-es/logic/buildTransaction.js.map +1 -1
- package/lib-es/logic/getCoinAndAmounts.d.ts +2 -0
- package/lib-es/logic/getCoinAndAmounts.d.ts.map +1 -1
- package/lib-es/logic/getCoinAndAmounts.js +66 -39
- package/lib-es/logic/getCoinAndAmounts.js.map +1 -1
- package/lib-es/logic/staking.d.ts +12 -0
- package/lib-es/logic/staking.d.ts.map +1 -0
- package/lib-es/logic/staking.js +67 -0
- package/lib-es/logic/staking.js.map +1 -0
- package/lib-es/logic/transactionsToOperations.js +4 -4
- package/lib-es/logic/transactionsToOperations.js.map +1 -1
- package/lib-es/network/client.d.ts +4 -1
- package/lib-es/network/client.d.ts.map +1 -1
- package/lib-es/network/client.js +32 -1
- package/lib-es/network/client.js.map +1 -1
- package/lib-es/network/graphql/queries.d.ts +2 -0
- package/lib-es/network/graphql/queries.d.ts.map +1 -1
- package/lib-es/network/graphql/queries.js +41 -1
- package/lib-es/network/graphql/queries.js.map +1 -1
- package/lib-es/network/graphql/types.d.ts +57 -6
- package/lib-es/network/graphql/types.d.ts.map +1 -1
- package/lib-es/network/index.d.ts.map +1 -1
- package/lib-es/network/index.js.map +1 -1
- package/lib-es/network/validators.d.ts +3 -0
- package/lib-es/network/validators.d.ts.map +1 -0
- package/lib-es/network/validators.js +35 -0
- package/lib-es/network/validators.js.map +1 -0
- package/lib-es/preload-data.d.ts +7 -0
- package/lib-es/preload-data.d.ts.map +1 -0
- package/lib-es/preload-data.js +36 -0
- package/lib-es/preload-data.js.map +1 -0
- package/lib-es/preload.d.ts +6 -0
- package/lib-es/preload.d.ts.map +1 -0
- package/lib-es/preload.js +16 -0
- package/lib-es/preload.js.map +1 -0
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib-es/test/bridgeDatasetTest.js +1 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -1
- package/lib-es/types/index.d.ts +92 -8
- package/lib-es/types/index.d.ts.map +1 -1
- package/lib-es/types/index.js.map +1 -1
- package/lib-es/utils/IconGenerator.d.ts +12 -0
- package/lib-es/utils/IconGenerator.d.ts.map +1 -0
- package/lib-es/utils/IconGenerator.js +134 -0
- package/lib-es/utils/IconGenerator.js.map +1 -0
- package/lib-es/utils/index.d.ts +3 -0
- package/lib-es/utils/index.d.ts.map +1 -0
- package/lib-es/utils/index.js +13 -0
- package/lib-es/utils/index.js.map +1 -0
- package/package.json +14 -9
- package/src/__tests__/bridge/deviceTransactionConfig.test.ts +120 -8
- package/src/__tests__/bridge/getFeesForTransaction.test.ts +10 -10
- package/src/__tests__/bridge/getTransactionStatus.test.ts +247 -3
- package/src/__tests__/bridge/index.test.ts +5 -1
- package/src/__tests__/bridge/logic.test.ts +10 -10
- package/src/__tests__/bridge/prepareTransaction.test.ts +4 -4
- package/src/__tests__/bridge/serialization.ts +103 -0
- package/src/__tests__/bridge/synchronisation.test.ts +798 -32
- package/src/__tests__/logic/staking.test.ts +221 -0
- package/src/__tests__/network/client.test.ts +3 -3
- package/src/__tests__/network/validators.test.ts +105 -0
- package/src/__tests__/utils/IconGenerator.test.ts +13 -0
- package/src/__tests__/utils/index.test.ts +11 -0
- package/src/bridge/bridge.fixture.ts +12 -0
- package/src/bridge/deviceTransactionConfig.ts +90 -21
- package/src/bridge/estimateMaxSpendable.ts +5 -5
- package/src/bridge/getFeesForTransaction.ts +17 -5
- package/src/bridge/getTransactionStatus.ts +208 -32
- package/src/bridge/index.ts +14 -5
- package/src/bridge/logic.ts +28 -12
- package/src/bridge/prepareTransaction.ts +72 -24
- package/src/bridge/serialization.ts +52 -0
- package/src/bridge/signOperation.ts +20 -7
- package/src/bridge/synchronisation.ts +69 -12
- package/src/constants.ts +64 -2
- package/src/index.ts +0 -2
- package/src/logic/buildTransaction.ts +49 -24
- package/src/logic/getCoinAndAmounts.ts +91 -41
- package/src/logic/staking.ts +105 -0
- package/src/logic/transactionsToOperations.ts +5 -5
- package/src/network/client.ts +44 -4
- package/src/network/graphql/queries.ts +46 -1
- package/src/network/graphql/types.ts +63 -6
- package/src/network/index.ts +1 -0
- package/src/network/validators.ts +48 -0
- package/src/preload-data.ts +43 -0
- package/src/preload.ts +23 -0
- package/src/test/bridgeDatasetTest.ts +1 -0
- package/src/types/index.ts +106 -8
- package/src/utils/IconGenerator.ts +166 -0
- package/src/utils/index.ts +16 -0
package/src/network/client.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ApolloClient, InMemoryCache } from "@apollo/client";
|
|
2
|
-
|
|
3
2
|
import {
|
|
4
3
|
type AccountData,
|
|
5
4
|
Aptos,
|
|
@@ -9,6 +8,7 @@ import {
|
|
|
9
8
|
type InputEntryFunctionData,
|
|
10
9
|
type InputGenerateTransactionOptions,
|
|
11
10
|
MimeType,
|
|
11
|
+
MoveStructId,
|
|
12
12
|
type RawTransaction,
|
|
13
13
|
type SimpleTransaction,
|
|
14
14
|
type TransactionResponse,
|
|
@@ -30,7 +30,12 @@ import {
|
|
|
30
30
|
ESTIMATE_GAS_MUL,
|
|
31
31
|
TOKEN_TYPE,
|
|
32
32
|
} from "../constants";
|
|
33
|
-
import type {
|
|
33
|
+
import type {
|
|
34
|
+
AptosBalance,
|
|
35
|
+
AptosTransaction,
|
|
36
|
+
StakePoolResource,
|
|
37
|
+
TransactionOptions,
|
|
38
|
+
} from "../types";
|
|
34
39
|
import { GetAccountTransactionsData, GetAccountTransactionsDataGt } from "./graphql/queries";
|
|
35
40
|
import type {
|
|
36
41
|
GetAccountTransactionsDataQuery,
|
|
@@ -59,7 +64,8 @@ const getIndexerEndpoint = (currencyId: string) =>
|
|
|
59
64
|
export class AptosAPI {
|
|
60
65
|
private readonly aptosConfig: AptosConfig;
|
|
61
66
|
private readonly aptosClient: Aptos;
|
|
62
|
-
|
|
67
|
+
|
|
68
|
+
readonly apolloClient: ApolloClient<object>;
|
|
63
69
|
|
|
64
70
|
constructor(currencyIdOrSettings: AptosSettings | string) {
|
|
65
71
|
if (typeof currencyIdOrSettings === "string") {
|
|
@@ -211,7 +217,9 @@ export class AptosAPI {
|
|
|
211
217
|
const simulation = await this.simulateTransaction(publicKeyEd, tx);
|
|
212
218
|
const completedTx = simulation[0];
|
|
213
219
|
|
|
214
|
-
const gasLimit = new BigNumber(completedTx.gas_used)
|
|
220
|
+
const gasLimit = new BigNumber(completedTx.gas_used)
|
|
221
|
+
.multipliedBy(ESTIMATE_GAS_MUL)
|
|
222
|
+
.integerValue();
|
|
215
223
|
const gasPrice = new BigNumber(completedTx.gas_unit_price);
|
|
216
224
|
|
|
217
225
|
const expectedGas = gasPrice.multipliedBy(gasLimit);
|
|
@@ -226,6 +234,38 @@ export class AptosAPI {
|
|
|
226
234
|
};
|
|
227
235
|
}
|
|
228
236
|
|
|
237
|
+
async getNextUnlockTime(stakingPoolAddress: string): Promise<string | undefined> {
|
|
238
|
+
const resourceType: MoveStructId = "0x1::stake::StakePool";
|
|
239
|
+
try {
|
|
240
|
+
const resource = await this.aptosClient.getAccountResource<StakePoolResource>({
|
|
241
|
+
accountAddress: stakingPoolAddress,
|
|
242
|
+
resourceType,
|
|
243
|
+
});
|
|
244
|
+
return resource.locked_until_secs;
|
|
245
|
+
} catch (error) {
|
|
246
|
+
log("error", "Failed to fetch StakePool resource:", { error });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async getDelegatorBalanceInPool(
|
|
251
|
+
poolAddress: string,
|
|
252
|
+
delegatorAddress: string,
|
|
253
|
+
): Promise<Array<string>> {
|
|
254
|
+
try {
|
|
255
|
+
// Query the delegator balance in the pool
|
|
256
|
+
return await this.aptosClient.view<[string]>({
|
|
257
|
+
payload: {
|
|
258
|
+
function: "0x1::delegation_pool::get_stake",
|
|
259
|
+
typeArguments: [],
|
|
260
|
+
functionArguments: [poolAddress, delegatorAddress],
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
} catch (error) {
|
|
264
|
+
log("error", "Failed to fetch delegation_pool::get_stake", { error });
|
|
265
|
+
return ["0", "0", "0"];
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
229
269
|
async listOperations(
|
|
230
270
|
rawAddress: string,
|
|
231
271
|
pagination: Pagination,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// We need to target CJS for the CJS build of the lib
|
|
2
1
|
import { gql } from "@apollo/client";
|
|
3
2
|
|
|
4
3
|
export const GetDelegatedStakingActivities = gql`
|
|
@@ -16,6 +15,7 @@ export const GetDelegatedStakingActivities = gql`
|
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
`;
|
|
18
|
+
|
|
19
19
|
export const GetAccountTransactionsData = gql`
|
|
20
20
|
query GetAccountTransactionsData($address: String, $limit: Int) {
|
|
21
21
|
account_transactions(
|
|
@@ -28,6 +28,7 @@ export const GetAccountTransactionsData = gql`
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
`;
|
|
31
|
+
|
|
31
32
|
export const GetAccountTransactionsDataGt = gql`
|
|
32
33
|
query GetAccountTransactionsDataGt($address: String, $limit: Int, $gt: bigint) {
|
|
33
34
|
account_transactions(
|
|
@@ -40,6 +41,7 @@ export const GetAccountTransactionsDataGt = gql`
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
`;
|
|
44
|
+
|
|
43
45
|
export const GetAccountTransactionsDataLt = gql`
|
|
44
46
|
query GetAccountTransactionsDataLt($address: String, $limit: Int, $lt: bigint) {
|
|
45
47
|
account_transactions(
|
|
@@ -52,3 +54,46 @@ export const GetAccountTransactionsDataLt = gql`
|
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
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
|
+
export const GetCurrentDelegatorBalancesData = gql`
|
|
78
|
+
query GetCurrentDelegatorBalances {
|
|
79
|
+
current_delegator_balances(
|
|
80
|
+
distinct_on: pool_address
|
|
81
|
+
order_by: { current_pool_balance: { total_coins: desc }, pool_address: asc }
|
|
82
|
+
) {
|
|
83
|
+
current_pool_balance {
|
|
84
|
+
total_coins
|
|
85
|
+
operator_commission_percentage
|
|
86
|
+
staking_pool_address
|
|
87
|
+
total_shares
|
|
88
|
+
}
|
|
89
|
+
shares
|
|
90
|
+
delegator_address
|
|
91
|
+
staking_pool_metadata {
|
|
92
|
+
operator_aptos_name {
|
|
93
|
+
domain_with_suffix
|
|
94
|
+
is_active
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
`;
|
|
@@ -21,9 +21,7 @@ export type GetAccountTransactionsDataQueryVariables = Exact<{
|
|
|
21
21
|
}>;
|
|
22
22
|
|
|
23
23
|
export type GetAccountTransactionsDataQuery = {
|
|
24
|
-
__typename?: "query_root";
|
|
25
24
|
account_transactions: Array<{
|
|
26
|
-
__typename?: "account_transactions";
|
|
27
25
|
transaction_version: number;
|
|
28
26
|
}>;
|
|
29
27
|
};
|
|
@@ -35,9 +33,7 @@ export type GetAccountTransactionsDataGtQueryVariables = Exact<{
|
|
|
35
33
|
}>;
|
|
36
34
|
|
|
37
35
|
export type GetAccountTransactionsDataGtQuery = {
|
|
38
|
-
__typename?: "query_root";
|
|
39
36
|
account_transactions: Array<{
|
|
40
|
-
__typename?: "account_transactions";
|
|
41
37
|
transaction_version: number;
|
|
42
38
|
}>;
|
|
43
39
|
};
|
|
@@ -49,9 +45,7 @@ export type GetAccountTransactionsDataLtQueryVariables = Exact<{
|
|
|
49
45
|
}>;
|
|
50
46
|
|
|
51
47
|
export type GetAccountTransactionsDataLtQuery = {
|
|
52
|
-
__typename?: "query_root";
|
|
53
48
|
account_transactions: Array<{
|
|
54
|
-
__typename?: "account_transactions";
|
|
55
49
|
transaction_version: number;
|
|
56
50
|
}>;
|
|
57
51
|
};
|
|
@@ -83,3 +77,66 @@ export type StakeDetails = {
|
|
|
83
77
|
canWithdrawPendingInactive: boolean;
|
|
84
78
|
poolAddress: string;
|
|
85
79
|
};
|
|
80
|
+
|
|
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
|
+
export type GetCurrentDelegatorBalancesQuery = {
|
|
99
|
+
current_delegator_balances: Array<{
|
|
100
|
+
current_pool_balance: {
|
|
101
|
+
total_coins: string;
|
|
102
|
+
operator_commission_percentage: string;
|
|
103
|
+
staking_pool_address: string;
|
|
104
|
+
total_shares: string;
|
|
105
|
+
};
|
|
106
|
+
shares: string;
|
|
107
|
+
delegator_address: string;
|
|
108
|
+
staking_pool_metadata: {
|
|
109
|
+
operator_aptos_name: {
|
|
110
|
+
domain_with_suffix: string;
|
|
111
|
+
is_active: boolean;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
}>;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export interface DelegationPoolAddress {
|
|
118
|
+
staking_pool_address: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
interface CurrentPoolBalance {
|
|
122
|
+
total_coins: string;
|
|
123
|
+
operator_commission_percentage: string;
|
|
124
|
+
staking_pool_address: string;
|
|
125
|
+
total_shares: string;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
interface StakingPoolMetadata {
|
|
129
|
+
operator_aptos_name: OperatorAptosName;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
interface OperatorAptosName {
|
|
133
|
+
domain_with_suffix: string;
|
|
134
|
+
is_active: boolean;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface CurrentDelegatorBalance {
|
|
138
|
+
shares: string;
|
|
139
|
+
delegator_address: string;
|
|
140
|
+
current_pool_balance: CurrentPoolBalance;
|
|
141
|
+
staking_pool_metadata: StakingPoolMetadata;
|
|
142
|
+
}
|
package/src/network/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { Account } from "@ledgerhq/types-live";
|
|
|
11
11
|
import { AptosSigner } from "../types";
|
|
12
12
|
import { sha3_256 as sha3Hash } from "@noble/hashes/sha3";
|
|
13
13
|
import { combineSignedTransaction } from "../logic/combine";
|
|
14
|
+
|
|
14
15
|
export * from "./client";
|
|
15
16
|
|
|
16
17
|
export async function signTransaction(
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { AptosAPI } from "../network";
|
|
3
|
+
import { GetCurrentDelegatorBalancesData } from "./graphql/queries";
|
|
4
|
+
import { CurrentDelegatorBalance, GetCurrentDelegatorBalancesQuery } from "./graphql/types";
|
|
5
|
+
import { AptosValidator } from "../types";
|
|
6
|
+
import { isTestnet } from "../logic/isTestnet";
|
|
7
|
+
import { APTOS_EXPLORER_ACCOUNT_URL } from "../constants";
|
|
8
|
+
import { formatUnlockTime } from "../logic/staking";
|
|
9
|
+
|
|
10
|
+
export async function getValidators(currencyId: string): Promise<AptosValidator[]> {
|
|
11
|
+
const api = new AptosAPI(currencyId);
|
|
12
|
+
const query = GetCurrentDelegatorBalancesData;
|
|
13
|
+
const queryResponse = await api.apolloClient.query<GetCurrentDelegatorBalancesQuery, object>({
|
|
14
|
+
query: query,
|
|
15
|
+
fetchPolicy: "network-only",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const stakingData: CurrentDelegatorBalance[] = queryResponse.data.current_delegator_balances;
|
|
19
|
+
|
|
20
|
+
const list: AptosValidator[] = await Promise.all(
|
|
21
|
+
stakingData.map(async pool => {
|
|
22
|
+
const aptosName = pool.staking_pool_metadata.operator_aptos_name;
|
|
23
|
+
const naming =
|
|
24
|
+
Array.isArray(aptosName) && aptosName.length > 0 && aptosName[0].domain_with_suffix
|
|
25
|
+
? aptosName[0].domain_with_suffix
|
|
26
|
+
: pool.current_pool_balance.staking_pool_address;
|
|
27
|
+
|
|
28
|
+
const url = `${APTOS_EXPLORER_ACCOUNT_URL}/${pool.current_pool_balance.staking_pool_address}?network=${isTestnet(currencyId) ? "testnet" : "mainnet"}`;
|
|
29
|
+
|
|
30
|
+
const unblockdata = await api.getNextUnlockTime(
|
|
31
|
+
pool.current_pool_balance.staking_pool_address,
|
|
32
|
+
);
|
|
33
|
+
const nextUnlockTime = unblockdata ? formatUnlockTime(unblockdata) : undefined; //`${30}d ${20}h ${30}m`;
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
commission: BigNumber(pool.current_pool_balance.operator_commission_percentage).div(100),
|
|
37
|
+
activeStake: BigNumber(pool.current_pool_balance.total_coins),
|
|
38
|
+
address: pool.current_pool_balance.staking_pool_address,
|
|
39
|
+
name: naming,
|
|
40
|
+
shares: pool.current_pool_balance.total_shares,
|
|
41
|
+
wwwUrl: url,
|
|
42
|
+
nextUnlockTime: nextUnlockTime,
|
|
43
|
+
};
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return list.sort((a, b) => b.activeStake.toNumber() - a.activeStake.toNumber());
|
|
48
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
|
+
import { BehaviorSubject, Observable } from "rxjs";
|
|
3
|
+
import { AptosPreloadData } from "./types";
|
|
4
|
+
|
|
5
|
+
const initialData: AptosPreloadData = {
|
|
6
|
+
validatorsWithMeta: [],
|
|
7
|
+
validators: [],
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const dataByCurrency = new Map<string, AptosPreloadData>([
|
|
11
|
+
["aptos", initialData],
|
|
12
|
+
["aptos_testnet", initialData],
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
const dataUpdatesByCurrency = new Map([
|
|
16
|
+
["aptos", new BehaviorSubject<AptosPreloadData>(initialData)],
|
|
17
|
+
["aptos_testnet", new BehaviorSubject<AptosPreloadData>(initialData)],
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
export function setAptosPreloadData(data: AptosPreloadData, currency: CryptoCurrency): void {
|
|
21
|
+
dataByCurrency.set(currency.id, data ?? initialData);
|
|
22
|
+
const subject = dataUpdatesByCurrency.get(currency.id);
|
|
23
|
+
if (subject === undefined) {
|
|
24
|
+
throw new Error(`unsupported currency ${currency.id}`);
|
|
25
|
+
}
|
|
26
|
+
subject.next(data);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getAptosPreloadData(currency: CryptoCurrency): Observable<AptosPreloadData> {
|
|
30
|
+
const subject = dataUpdatesByCurrency.get(currency.id);
|
|
31
|
+
if (subject === undefined) {
|
|
32
|
+
throw new Error(`unsupported currency ${currency.id}`);
|
|
33
|
+
}
|
|
34
|
+
return subject.asObservable();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getCurrentAptosPreloadData(currency: CryptoCurrency): AptosPreloadData {
|
|
38
|
+
const data = dataByCurrency.get(currency.id);
|
|
39
|
+
if (data === undefined) {
|
|
40
|
+
throw new Error(`unsupported currency ${currency.id}`);
|
|
41
|
+
}
|
|
42
|
+
return data;
|
|
43
|
+
}
|
package/src/preload.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
|
+
import { setAptosPreloadData } from "./preload-data";
|
|
3
|
+
import { AptosPreloadData, AptosValidator } from "./types";
|
|
4
|
+
import { getValidators } from "./network/validators";
|
|
5
|
+
|
|
6
|
+
export const PRELOAD_MAX_AGE = 15 * 60 * 1000; // 15min
|
|
7
|
+
|
|
8
|
+
export async function preloadWithValidators(currency: CryptoCurrency): Promise<AptosPreloadData> {
|
|
9
|
+
const validators: AptosValidator[] = await getValidators(currency.id);
|
|
10
|
+
|
|
11
|
+
const data: AptosPreloadData = {
|
|
12
|
+
validatorsWithMeta: [],
|
|
13
|
+
validators,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
setAptosPreloadData(data, currency);
|
|
17
|
+
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function hydrate(data: AptosPreloadData, currency: CryptoCurrency): void {
|
|
22
|
+
setAptosPreloadData(data, currency);
|
|
23
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { UserTransactionResponse } from "@aptos-labs/ts-sdk";
|
|
2
2
|
import type {
|
|
3
3
|
Account,
|
|
4
|
+
AccountRaw,
|
|
4
5
|
Operation,
|
|
5
6
|
TransactionCommon,
|
|
6
7
|
TransactionCommonRaw,
|
|
@@ -8,6 +9,7 @@ import type {
|
|
|
8
9
|
TransactionStatusCommonRaw,
|
|
9
10
|
} from "@ledgerhq/types-live";
|
|
10
11
|
import type { BigNumber } from "bignumber.js";
|
|
12
|
+
|
|
11
13
|
export * from "./signer";
|
|
12
14
|
export * from "./bridge";
|
|
13
15
|
|
|
@@ -18,9 +20,15 @@ export type AptosTransaction = UserTransactionResponse & {
|
|
|
18
20
|
};
|
|
19
21
|
};
|
|
20
22
|
|
|
21
|
-
export type AptosOperation = Operation
|
|
23
|
+
export type AptosOperation = Operation<AptosOperationExtra>;
|
|
24
|
+
|
|
25
|
+
export type AptosOperationRaw = Operation<AptosOperationExtraRaw>;
|
|
26
|
+
|
|
27
|
+
export type AptosAccount = Account & { aptosResources: AptosResources };
|
|
22
28
|
|
|
23
|
-
export type
|
|
29
|
+
export type AptosAccountRaw = AccountRaw & {
|
|
30
|
+
aptosResources: AptosResourcesRaw;
|
|
31
|
+
};
|
|
24
32
|
|
|
25
33
|
export type TransactionStatus = TransactionStatusCommon;
|
|
26
34
|
|
|
@@ -43,19 +51,14 @@ export type AptosAddress = {
|
|
|
43
51
|
path: string;
|
|
44
52
|
};
|
|
45
53
|
|
|
46
|
-
export interface TransactionOptions {
|
|
47
|
-
maxGasAmount: string;
|
|
48
|
-
gasUnitPrice: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
54
|
export type TransactionErrors = {
|
|
52
55
|
maxGasAmount?: string;
|
|
53
56
|
gasUnitPrice?: string;
|
|
54
57
|
};
|
|
55
58
|
|
|
56
59
|
export type Transaction = TransactionCommon & {
|
|
57
|
-
mode: string;
|
|
58
60
|
family: "aptos";
|
|
61
|
+
mode: string;
|
|
59
62
|
fees?: BigNumber | null;
|
|
60
63
|
options: TransactionOptions;
|
|
61
64
|
errors?: TransactionErrors;
|
|
@@ -87,6 +90,101 @@ export type AptosMoveResource = {
|
|
|
87
90
|
[key: string]: AptosMoveResourceData;
|
|
88
91
|
};
|
|
89
92
|
|
|
93
|
+
export type AptosOperationExtra = {
|
|
94
|
+
stake?: ExtraStakeInfo;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export type ExtraStakeInfo = {
|
|
98
|
+
address: string;
|
|
99
|
+
amount: BigNumber;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export type AptosOperationExtraRaw = {
|
|
103
|
+
stake?: ExtraStakeInfoRaw;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export type ExtraStakeInfoRaw = {
|
|
107
|
+
address: string;
|
|
108
|
+
amount: string;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export type AptosResources = {
|
|
112
|
+
activeBalance: BigNumber;
|
|
113
|
+
inactiveBalance: BigNumber;
|
|
114
|
+
pendingInactiveBalance: BigNumber;
|
|
115
|
+
stakingPositions: AptosStakingPosition[];
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export type AptosResourcesRaw = {
|
|
119
|
+
activeBalance: string;
|
|
120
|
+
pendingInactiveBalance: string;
|
|
121
|
+
inactiveBalance: string;
|
|
122
|
+
stakingPositions: {
|
|
123
|
+
active: string;
|
|
124
|
+
pendingInactive: string;
|
|
125
|
+
inactive: string;
|
|
126
|
+
validatorId: string;
|
|
127
|
+
}[];
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export type AptosStakingPosition = {
|
|
131
|
+
active: BigNumber;
|
|
132
|
+
inactive: BigNumber;
|
|
133
|
+
pendingInactive: BigNumber;
|
|
134
|
+
validatorId: string;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export type AptosMappedStakingPosition = AptosStakingPosition & {
|
|
138
|
+
formattedAmount: string;
|
|
139
|
+
formattedPending: string;
|
|
140
|
+
formattedAvailable: string;
|
|
141
|
+
rank: number;
|
|
142
|
+
validator: AptosValidator | null | undefined;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export type AptosValidator = {
|
|
146
|
+
activeStake: BigNumber;
|
|
147
|
+
commission: BigNumber;
|
|
148
|
+
address: string;
|
|
149
|
+
name?: string | undefined;
|
|
150
|
+
shares: string;
|
|
151
|
+
avatarUrl?: string | undefined;
|
|
152
|
+
wwwUrl?: string | undefined;
|
|
153
|
+
nextUnlockTime?: string | undefined;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export type AptosValidatorRaw = {
|
|
157
|
+
active_stake?: number | null;
|
|
158
|
+
commission?: number | null;
|
|
159
|
+
addr?: string | null;
|
|
160
|
+
name?: string | null;
|
|
161
|
+
shares: string;
|
|
162
|
+
avatar_url?: string | null;
|
|
163
|
+
www_url?: string | null;
|
|
164
|
+
nextUnlockTime?: string | undefined;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export type AptosValidatorWithMeta = {
|
|
168
|
+
validator: AptosValidator;
|
|
169
|
+
meta: {
|
|
170
|
+
name?: string;
|
|
171
|
+
img?: string;
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export type AptosPreloadData = {
|
|
176
|
+
validatorsWithMeta: AptosValidatorWithMeta[];
|
|
177
|
+
validators: AptosValidator[];
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
export interface TransactionOptions {
|
|
181
|
+
maxGasAmount: string;
|
|
182
|
+
gasUnitPrice: string;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface StakePoolResource {
|
|
186
|
+
locked_until_secs: string;
|
|
187
|
+
}
|
|
90
188
|
export type AptosBalance = {
|
|
91
189
|
contractAddress: string;
|
|
92
190
|
amount: BigNumber;
|