@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
|
@@ -4,8 +4,8 @@ import type { GetAccountShape } from "@ledgerhq/coin-framework/bridge/jsHelpers"
|
|
|
4
4
|
import { mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
5
5
|
import { AptosAPI } from "../network";
|
|
6
6
|
import { txsToOps } from "./logic";
|
|
7
|
-
import type { AptosAccount } from "../types";
|
|
8
|
-
import {
|
|
7
|
+
import type { AptosAccount, AptosStakingPosition } from "../types";
|
|
8
|
+
import { Operation, TokenAccount } from "@ledgerhq/types-live";
|
|
9
9
|
import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
10
10
|
import {
|
|
11
11
|
decodeTokenAccountId,
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
} from "@ledgerhq/coin-framework/account/index";
|
|
15
15
|
import { AccountShapeInfo } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
16
16
|
import BigNumber from "bignumber.js";
|
|
17
|
+
import { getEnv } from "@ledgerhq/live-env";
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* List of properties of a sub account that can be updated when 2 "identical" accounts are found
|
|
@@ -29,7 +30,7 @@ const updatableSubAccountProperties: { name: string; isOps: boolean }[] = [
|
|
|
29
30
|
* In charge of smartly merging sub accounts while maintaining references as much as possible
|
|
30
31
|
*/
|
|
31
32
|
export const mergeSubAccounts = (
|
|
32
|
-
initialAccount:
|
|
33
|
+
initialAccount: AptosAccount | undefined,
|
|
33
34
|
newSubAccounts: TokenAccount[],
|
|
34
35
|
): Array<TokenAccount> => {
|
|
35
36
|
const oldSubAccounts: Array<TokenAccount> | undefined = initialAccount?.subAccounts;
|
|
@@ -127,7 +128,7 @@ export const getSubAccountShape = async (
|
|
|
127
128
|
* Getting all token related operations in order to provide TokenAccounts
|
|
128
129
|
*/
|
|
129
130
|
export const getSubAccounts = async (
|
|
130
|
-
infos: AccountShapeInfo<
|
|
131
|
+
infos: AccountShapeInfo<AptosAccount>,
|
|
131
132
|
address: string,
|
|
132
133
|
accountId: string,
|
|
133
134
|
lastTokenOperations: Operation[],
|
|
@@ -158,7 +159,9 @@ export const getSubAccounts = async (
|
|
|
158
159
|
return Promise.all(subAccountsPromises);
|
|
159
160
|
};
|
|
160
161
|
|
|
161
|
-
export const getAccountShape: GetAccountShape = async
|
|
162
|
+
export const getAccountShape: GetAccountShape<AptosAccount> = async (
|
|
163
|
+
info: AccountShapeInfo<AptosAccount>,
|
|
164
|
+
) => {
|
|
162
165
|
const { address, initialAccount, currency, derivationMode, rest } = info;
|
|
163
166
|
|
|
164
167
|
const publicKey =
|
|
@@ -183,11 +186,11 @@ export const getAccountShape: GetAccountShape = async info => {
|
|
|
183
186
|
const aptosClient = new AptosAPI(currency.id);
|
|
184
187
|
const { balance, transactions, blockHeight } = await aptosClient.getAccountInfo(address);
|
|
185
188
|
|
|
186
|
-
const [newOperations, tokenOperations]: [
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
);
|
|
189
|
+
const [newOperations, tokenOperations, stakingOperations]: [
|
|
190
|
+
Operation[],
|
|
191
|
+
Operation[],
|
|
192
|
+
Operation[],
|
|
193
|
+
] = txsToOps(info, accountId, transactions);
|
|
191
194
|
const operations = mergeOps(oldOperations, newOperations);
|
|
192
195
|
|
|
193
196
|
const newSubAccounts = await getSubAccounts(info, address, accountId, tokenOperations);
|
|
@@ -196,24 +199,78 @@ export const getAccountShape: GetAccountShape = async info => {
|
|
|
196
199
|
? newSubAccounts
|
|
197
200
|
: mergeSubAccounts(initialAccount, newSubAccounts);
|
|
198
201
|
|
|
199
|
-
operations
|
|
202
|
+
operations?.forEach(op => {
|
|
200
203
|
const subOperations = inferSubOperations(op.hash, subAccounts);
|
|
201
204
|
op.subOperations =
|
|
202
205
|
subOperations.length === 1 ? subOperations : subOperations.filter(op => !!op.blockHash);
|
|
203
206
|
});
|
|
204
207
|
|
|
208
|
+
const stakingPositions: AptosStakingPosition[] = [];
|
|
209
|
+
let activeBalance = BigNumber(0);
|
|
210
|
+
let inactiveBalance = BigNumber(0);
|
|
211
|
+
let pendingInactiveBalance = BigNumber(0);
|
|
212
|
+
|
|
213
|
+
if (getEnv("APTOS_ENABLE_STAKING") === true) {
|
|
214
|
+
const stakingPoolAddresses = getStakingPoolAddresses(stakingOperations);
|
|
215
|
+
for (const stakingPoolAddress of stakingPoolAddresses) {
|
|
216
|
+
const [active_string, inactive_string, pending_inactive_string] =
|
|
217
|
+
await aptosClient.getDelegatorBalanceInPool(stakingPoolAddress, address);
|
|
218
|
+
|
|
219
|
+
const active = BigNumber(active_string);
|
|
220
|
+
const inactive = BigNumber(inactive_string);
|
|
221
|
+
const pendingInactive = BigNumber(pending_inactive_string);
|
|
222
|
+
|
|
223
|
+
stakingPositions.push({
|
|
224
|
+
active,
|
|
225
|
+
inactive,
|
|
226
|
+
pendingInactive,
|
|
227
|
+
validatorId: stakingPoolAddress,
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
activeBalance = activeBalance.plus(active);
|
|
231
|
+
inactiveBalance = inactiveBalance.plus(inactive);
|
|
232
|
+
pendingInactiveBalance = pendingInactiveBalance.plus(pendingInactive);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const aptosResources = {
|
|
237
|
+
activeBalance,
|
|
238
|
+
inactiveBalance,
|
|
239
|
+
pendingInactiveBalance,
|
|
240
|
+
stakingPositions,
|
|
241
|
+
};
|
|
242
|
+
|
|
205
243
|
const shape: Partial<AptosAccount> = {
|
|
206
244
|
type: "Account",
|
|
207
245
|
id: accountId,
|
|
208
246
|
xpub,
|
|
209
|
-
balance: balance
|
|
247
|
+
balance: balance
|
|
248
|
+
.plus(aptosResources.activeBalance)
|
|
249
|
+
.plus(aptosResources.pendingInactiveBalance)
|
|
250
|
+
.plus(aptosResources.inactiveBalance),
|
|
210
251
|
spendableBalance: balance,
|
|
211
252
|
operations,
|
|
212
253
|
operationsCount: operations.length,
|
|
213
254
|
blockHeight,
|
|
214
255
|
lastSyncDate: new Date(),
|
|
215
256
|
subAccounts,
|
|
257
|
+
aptosResources,
|
|
216
258
|
};
|
|
217
259
|
|
|
218
260
|
return shape;
|
|
219
261
|
};
|
|
262
|
+
|
|
263
|
+
export const getStakingPoolAddresses = (stakingOperations: Operation[]): string[] => {
|
|
264
|
+
const stakingPoolsAddrs: string[] = [];
|
|
265
|
+
|
|
266
|
+
for (const op of stakingOperations) {
|
|
267
|
+
if (!op.recipients.length) continue;
|
|
268
|
+
|
|
269
|
+
const poolAddress = op.recipients[0];
|
|
270
|
+
if (poolAddress === "0x1") continue;
|
|
271
|
+
|
|
272
|
+
if (!stakingPoolsAddrs.includes(poolAddress)) stakingPoolsAddrs.push(poolAddress);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return stakingPoolsAddrs;
|
|
276
|
+
};
|
package/src/constants.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { MoveStructId } from "@aptos-labs/ts-sdk";
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
3
|
|
|
4
|
-
export const ESTIMATE_GAS_MUL = new BigNumber(1.
|
|
4
|
+
export const ESTIMATE_GAS_MUL = new BigNumber(1.1); // define buffer for gas estimation change here, if needed
|
|
5
|
+
export const ESTIMATE_GAS_MUL_FOR_STAKING = new BigNumber(3); // gas multiplier for staking operations
|
|
5
6
|
|
|
6
7
|
export const LOAD_LIMIT = 10;
|
|
7
8
|
|
|
@@ -13,6 +14,10 @@ export enum TX_STATUS {
|
|
|
13
14
|
|
|
14
15
|
export const WRITE_RESOURCE = "write_resource";
|
|
15
16
|
|
|
17
|
+
export const APTOS_NON_HARDENED_DERIVATION_PATH_REGEX = /^44'\/637'\/[0-9]+'\/[0-9]+\/[0-9]+$/;
|
|
18
|
+
export const APTOS_NON_HARDENED_DERIVATION_PATH = "44'/637'/0'/0/0";
|
|
19
|
+
export const APTOS_HARDENED_DERIVATION_PATH = "44'/637'/0'/0'/0'";
|
|
20
|
+
|
|
16
21
|
export const COIN_TRANSFER_TYPES: MoveStructId[] = [
|
|
17
22
|
"0x1::aptos_account::transfer",
|
|
18
23
|
"0x1::aptos_account::transfer_coins",
|
|
@@ -28,9 +33,45 @@ export const BATCH_TRANSFER_TYPES: MoveStructId[] = [
|
|
|
28
33
|
|
|
29
34
|
export const DELEGATION_POOL_TYPES: MoveStructId[] = [
|
|
30
35
|
"0x1::delegation_pool::add_stake",
|
|
36
|
+
"0x1::delegation_pool::reactivate_stake",
|
|
37
|
+
"0x1::delegation_pool::unlock",
|
|
31
38
|
"0x1::delegation_pool::withdraw",
|
|
32
39
|
];
|
|
33
40
|
|
|
41
|
+
export const ADD_STAKE_EVENTS = [
|
|
42
|
+
"0x1::stake::AddStake",
|
|
43
|
+
"0x1::stake::AddStakeEvent",
|
|
44
|
+
"0x1::delegation_pool::AddStake",
|
|
45
|
+
"0x1::delegation_pool::AddStakeEvent",
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
export const REACTIVATE_STAKE_EVENTS = [
|
|
49
|
+
"0x1::stake::ReactivateStake",
|
|
50
|
+
"0x1::stake::ReactivateStakeEvent",
|
|
51
|
+
"0x1::delegation_pool::ReactivateStake",
|
|
52
|
+
"0x1::delegation_pool::ReactivateStakeEvent",
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
export const UNLOCK_STAKE_EVENTS = [
|
|
56
|
+
"0x1::stake::UnlockStake",
|
|
57
|
+
"0x1::stake::UnlockStakeEvent",
|
|
58
|
+
"0x1::delegation_pool::UnlockStake",
|
|
59
|
+
"0x1::delegation_pool::UnlockStakeEvent",
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
export const WITHDRAW_STAKE_EVENTS = [
|
|
63
|
+
"0x1::stake::WithdrawStake",
|
|
64
|
+
"0x1::stake::WithdrawStakeEvent",
|
|
65
|
+
"0x1::delegation_pool::WithdrawStake",
|
|
66
|
+
"0x1::delegation_pool::WithdrawStakeEvent",
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
export const STAKING_EVENTS = ADD_STAKE_EVENTS.concat(
|
|
70
|
+
REACTIVATE_STAKE_EVENTS,
|
|
71
|
+
UNLOCK_STAKE_EVENTS,
|
|
72
|
+
WITHDRAW_STAKE_EVENTS,
|
|
73
|
+
);
|
|
74
|
+
|
|
34
75
|
export const APTOS_ASSET_ID: MoveStructId = "0x1::aptos_coin::AptosCoin";
|
|
35
76
|
|
|
36
77
|
export const APTOS_COIN_CHANGE: MoveStructId = `0x1::coin::CoinStore<${APTOS_ASSET_ID}>`;
|
|
@@ -39,12 +80,33 @@ export const APTOS_FUNGIBLE_STORE: MoveStructId = "0x1::fungible_asset::Fungible
|
|
|
39
80
|
|
|
40
81
|
export const APTOS_OBJECT_CORE: MoveStructId = "0x1::object::ObjectCore";
|
|
41
82
|
|
|
42
|
-
export enum
|
|
83
|
+
export enum OP_TYPE {
|
|
43
84
|
IN = "IN",
|
|
44
85
|
OUT = "OUT",
|
|
86
|
+
STAKE = "STAKE",
|
|
87
|
+
UNSTAKE = "UNSTAKE",
|
|
88
|
+
WITHDRAW = "WITHDRAW",
|
|
45
89
|
UNKNOWN = "UNKNOWN",
|
|
46
90
|
}
|
|
47
91
|
|
|
92
|
+
export const SUPPORTED_TOKEN_TYPES = ["coin", "fungible_asset"];
|
|
93
|
+
|
|
94
|
+
export const STAKING_TX_MODES = ["stake", "unstake", "restake", "withdraw"];
|
|
95
|
+
|
|
96
|
+
export const APTOS_PRECISION = 8;
|
|
97
|
+
export const APTOS_MINIMUM_RESTAKE = BigNumber(1);
|
|
98
|
+
export const APTOS_MINIMUM_RESTAKE_IN_OCTAS = APTOS_MINIMUM_RESTAKE.shiftedBy(APTOS_PRECISION);
|
|
99
|
+
export const APTOS_DELEGATION_RESERVE = BigNumber(0.05);
|
|
100
|
+
export const APTOS_DELEGATION_RESERVE_IN_OCTAS =
|
|
101
|
+
APTOS_DELEGATION_RESERVE.shiftedBy(APTOS_PRECISION);
|
|
102
|
+
export const MIN_COINS_ON_SHARES_POOL = BigNumber(11);
|
|
103
|
+
export const MIN_COINS_ON_SHARES_POOL_IN_OCTAS =
|
|
104
|
+
MIN_COINS_ON_SHARES_POOL.shiftedBy(APTOS_PRECISION);
|
|
105
|
+
export const MIN_AMOUNT_TO_UNSTAKE = BigNumber(10);
|
|
106
|
+
export const MIN_AMOUNT_TO_UNSTAKE_IN_OCTAS = MIN_AMOUNT_TO_UNSTAKE.shiftedBy(APTOS_PRECISION);
|
|
107
|
+
|
|
108
|
+
export const APTOS_EXPLORER_ACCOUNT_URL = "https://explorer.aptoslabs.com/account";
|
|
109
|
+
|
|
48
110
|
export enum TOKEN_TYPE {
|
|
49
111
|
COIN = "coin",
|
|
50
112
|
FUNGIBLE_ASSET = "fungible_asset",
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { APTOS_ASSET_ID, TOKEN_TYPE } from "../constants";
|
|
|
5
5
|
import type { AptosAPI } from "../network";
|
|
6
6
|
import { normalizeTransactionOptions } from "./normalizeTransactionOptions";
|
|
7
7
|
import type { Transaction } from "../types";
|
|
8
|
-
import type BigNumber from "bignumber.js";
|
|
9
8
|
|
|
10
9
|
const buildTransaction = async (
|
|
11
10
|
account: Account,
|
|
@@ -20,10 +19,9 @@ const buildTransaction = async (
|
|
|
20
19
|
const payloadTokenType = (subAccount?.token?.tokenType as TOKEN_TYPE) ?? tokenType;
|
|
21
20
|
|
|
22
21
|
const txPayload = getPayload({
|
|
23
|
-
|
|
24
|
-
recipient: transaction.recipient,
|
|
25
|
-
contractAddress: payloadContracAddress,
|
|
22
|
+
transaction,
|
|
26
23
|
tokenType: payloadTokenType,
|
|
24
|
+
contractAddress: payloadContracAddress,
|
|
27
25
|
});
|
|
28
26
|
|
|
29
27
|
const txOptions = normalizeTransactionOptions(transaction.options);
|
|
@@ -33,33 +31,60 @@ const buildTransaction = async (
|
|
|
33
31
|
return tx;
|
|
34
32
|
};
|
|
35
33
|
|
|
36
|
-
const getPayload = (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
contractAddress
|
|
40
|
-
|
|
34
|
+
const getPayload = ({
|
|
35
|
+
transaction,
|
|
36
|
+
tokenType,
|
|
37
|
+
contractAddress,
|
|
38
|
+
}: {
|
|
39
|
+
transaction: Transaction;
|
|
40
|
+
tokenType: TOKEN_TYPE;
|
|
41
|
+
contractAddress: string | undefined;
|
|
41
42
|
}): InputEntryFunctionData => {
|
|
42
|
-
|
|
43
|
-
throw new Error(`Token type ${args.tokenType} not supported`);
|
|
44
|
-
}
|
|
43
|
+
const { amount, recipient, mode } = transaction;
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
switch (mode) {
|
|
46
|
+
case "stake":
|
|
47
|
+
return {
|
|
48
|
+
function: "0x1::delegation_pool::add_stake",
|
|
49
|
+
typeArguments: [],
|
|
50
|
+
functionArguments: [recipient, amount.toString()],
|
|
51
|
+
};
|
|
52
|
+
case "unstake":
|
|
53
|
+
return {
|
|
54
|
+
function: "0x1::delegation_pool::unlock",
|
|
55
|
+
typeArguments: [],
|
|
56
|
+
functionArguments: [recipient, amount.toString()],
|
|
57
|
+
};
|
|
58
|
+
case "restake":
|
|
59
|
+
return {
|
|
60
|
+
function: "0x1::delegation_pool::reactivate_stake",
|
|
61
|
+
typeArguments: [],
|
|
62
|
+
functionArguments: [recipient, amount.toString()],
|
|
63
|
+
};
|
|
64
|
+
case "withdraw":
|
|
65
|
+
return {
|
|
66
|
+
function: "0x1::delegation_pool::withdraw",
|
|
67
|
+
typeArguments: [],
|
|
68
|
+
functionArguments: [recipient, amount.toString()],
|
|
69
|
+
};
|
|
70
|
+
case "send":
|
|
71
|
+
if (tokenType !== undefined && !isTokenType(tokenType)) {
|
|
72
|
+
throw new Error(`Token type ${tokenType} not supported`);
|
|
73
|
+
}
|
|
53
74
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
75
|
+
if (tokenType === TOKEN_TYPE.FUNGIBLE_ASSET) {
|
|
76
|
+
return {
|
|
77
|
+
function: "0x1::primary_fungible_store::transfer",
|
|
78
|
+
typeArguments: ["0x1::fungible_asset::Metadata"],
|
|
79
|
+
functionArguments: [contractAddress, recipient, amount.toString()],
|
|
80
|
+
};
|
|
81
|
+
}
|
|
57
82
|
}
|
|
58
83
|
|
|
59
84
|
return {
|
|
60
85
|
function: "0x1::aptos_account::transfer_coins",
|
|
61
|
-
typeArguments: [
|
|
62
|
-
functionArguments: [
|
|
86
|
+
typeArguments: [contractAddress ?? APTOS_ASSET_ID],
|
|
87
|
+
functionArguments: [recipient, amount.toString()],
|
|
63
88
|
};
|
|
64
89
|
};
|
|
65
90
|
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ADD_STAKE_EVENTS,
|
|
4
|
+
APTOS_ASSET_ID,
|
|
5
|
+
APTOS_FUNGIBLE_STORE,
|
|
6
|
+
APTOS_OBJECT_CORE,
|
|
7
|
+
OP_TYPE,
|
|
8
|
+
REACTIVATE_STAKE_EVENTS,
|
|
9
|
+
STAKING_EVENTS,
|
|
10
|
+
UNLOCK_STAKE_EVENTS,
|
|
11
|
+
WITHDRAW_STAKE_EVENTS,
|
|
12
|
+
} from "../constants";
|
|
3
13
|
import {
|
|
4
14
|
AptosFungibleoObjectCoreResourceData,
|
|
5
15
|
AptosFungibleStoreResourceData,
|
|
@@ -94,48 +104,88 @@ export function getEventFAAddress(
|
|
|
94
104
|
export function getCoinAndAmounts(
|
|
95
105
|
tx: AptosTransaction,
|
|
96
106
|
address: string,
|
|
97
|
-
): {
|
|
107
|
+
): {
|
|
108
|
+
coin_id: string | null;
|
|
109
|
+
amount_in: BigNumber;
|
|
110
|
+
amount_out: BigNumber;
|
|
111
|
+
type: OP_TYPE;
|
|
112
|
+
} {
|
|
98
113
|
let coin_id: string | null = null;
|
|
99
114
|
let amount_in = BigNumber(0);
|
|
100
115
|
let amount_out = BigNumber(0);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
116
|
+
let type = OP_TYPE.UNKNOWN;
|
|
117
|
+
|
|
118
|
+
// Check if it is a staking transaction
|
|
119
|
+
const stakingTx = !!tx.events.find(event => STAKING_EVENTS.includes(event.type));
|
|
120
|
+
|
|
121
|
+
// Collect all events related to the address and calculate the overall amounts
|
|
122
|
+
if (stakingTx) {
|
|
123
|
+
tx.events.forEach(event => {
|
|
124
|
+
if (ADD_STAKE_EVENTS.includes(event.type) && tx.sender === address && amount_out.isZero()) {
|
|
125
|
+
coin_id = APTOS_ASSET_ID;
|
|
126
|
+
type = OP_TYPE.STAKE;
|
|
127
|
+
amount_out = amount_out.plus(event.data.amount_added || event.data.amount);
|
|
128
|
+
} else if (
|
|
129
|
+
REACTIVATE_STAKE_EVENTS.includes(event.type) &&
|
|
130
|
+
tx.sender === address &&
|
|
131
|
+
amount_out.isZero()
|
|
132
|
+
) {
|
|
133
|
+
coin_id = APTOS_ASSET_ID;
|
|
134
|
+
type = OP_TYPE.STAKE;
|
|
135
|
+
amount_out = amount_out.plus(event.data.amount_reactivated || event.data.amount);
|
|
136
|
+
} else if (
|
|
137
|
+
UNLOCK_STAKE_EVENTS.includes(event.type) &&
|
|
138
|
+
tx.sender === address &&
|
|
139
|
+
amount_in.isZero()
|
|
140
|
+
) {
|
|
141
|
+
coin_id = APTOS_ASSET_ID;
|
|
142
|
+
type = OP_TYPE.UNSTAKE;
|
|
143
|
+
amount_in = amount_in.plus(event.data.amount_unlocked || event.data.amount);
|
|
144
|
+
} else if (
|
|
145
|
+
WITHDRAW_STAKE_EVENTS.includes(event.type) &&
|
|
146
|
+
tx.sender === address &&
|
|
147
|
+
amount_in.isZero()
|
|
148
|
+
) {
|
|
149
|
+
coin_id = APTOS_ASSET_ID;
|
|
150
|
+
type = OP_TYPE.WITHDRAW;
|
|
151
|
+
amount_in = amount_in.plus(event.data.amount_withdrawn || event.data.amount);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
} else {
|
|
155
|
+
tx.events.forEach(event => {
|
|
156
|
+
if (
|
|
157
|
+
event.type === "0x1::coin::WithdrawEvent" &&
|
|
158
|
+
compareAddress(event.guid.account_address, address)
|
|
159
|
+
) {
|
|
160
|
+
coin_id = getResourceAddress(tx, event, "withdraw_events", getEventCoinAddress);
|
|
161
|
+
amount_out = amount_out.plus(event.data.amount);
|
|
162
|
+
} else if (
|
|
163
|
+
event.type === "0x1::coin::DepositEvent" &&
|
|
164
|
+
compareAddress(event.guid.account_address, address)
|
|
165
|
+
) {
|
|
166
|
+
coin_id = getResourceAddress(tx, event, "deposit_events", getEventCoinAddress);
|
|
167
|
+
amount_in = amount_in.plus(event.data.amount);
|
|
168
|
+
} else if (
|
|
169
|
+
event.type === "0x1::fungible_asset::Withdraw" &&
|
|
170
|
+
checkFAOwner(tx, event, address)
|
|
171
|
+
) {
|
|
172
|
+
coin_id = getResourceAddress(tx, event, "withdraw_events", getEventFAAddress);
|
|
173
|
+
amount_out = amount_out.plus(event.data.amount);
|
|
174
|
+
} else if (
|
|
175
|
+
event.type === "0x1::fungible_asset::Deposit" &&
|
|
176
|
+
checkFAOwner(tx, event, address)
|
|
177
|
+
) {
|
|
178
|
+
coin_id = getResourceAddress(tx, event, "deposit_events", getEventFAAddress);
|
|
179
|
+
amount_in = amount_in.plus(event.data.amount);
|
|
180
|
+
} else if (event.type === "0x1::transaction_fee::FeeStatement" && tx.sender === address) {
|
|
181
|
+
coin_id ??= APTOS_ASSET_ID;
|
|
182
|
+
if (coin_id === APTOS_ASSET_ID) {
|
|
183
|
+
const fees = BigNumber(tx.gas_unit_price).times(BigNumber(tx.gas_used));
|
|
184
|
+
amount_out = amount_out.plus(fees);
|
|
136
185
|
}
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return { coin_id, amount_in, amount_out, type };
|
|
141
191
|
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { Unit } from "@ledgerhq/types-cryptoassets";
|
|
3
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/formatCurrencyUnit";
|
|
4
|
+
import {
|
|
5
|
+
AptosAccount,
|
|
6
|
+
AptosMappedStakingPosition,
|
|
7
|
+
AptosStakingPosition,
|
|
8
|
+
AptosValidator,
|
|
9
|
+
} from "../types";
|
|
10
|
+
import { MIN_COINS_ON_SHARES_POOL_IN_OCTAS } from "../constants";
|
|
11
|
+
import { getMaxSendBalance } from "../bridge/logic";
|
|
12
|
+
|
|
13
|
+
export const mapStakingPositions = (
|
|
14
|
+
stakingPositions: AptosStakingPosition[],
|
|
15
|
+
validators: AptosValidator[],
|
|
16
|
+
unit: Unit,
|
|
17
|
+
): AptosMappedStakingPosition[] => {
|
|
18
|
+
return stakingPositions.map(sp => {
|
|
19
|
+
const rank = validators.findIndex(v => v.address === sp.validatorId);
|
|
20
|
+
const validator = validators[rank] ?? sp;
|
|
21
|
+
const formatConfig = {
|
|
22
|
+
disableRounding: false,
|
|
23
|
+
alwaysShowSign: false,
|
|
24
|
+
showCode: true,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
...sp,
|
|
29
|
+
formattedAmount: formatCurrencyUnit(unit, sp.active, formatConfig),
|
|
30
|
+
formattedPending: formatCurrencyUnit(unit, sp.pendingInactive, formatConfig),
|
|
31
|
+
formattedAvailable: formatCurrencyUnit(unit, sp.inactive, formatConfig),
|
|
32
|
+
rank,
|
|
33
|
+
validator,
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const canStake = (account: AptosAccount): boolean => {
|
|
39
|
+
return getMaxSendBalance(account) > MIN_COINS_ON_SHARES_POOL_IN_OCTAS;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const canUnstake = (
|
|
43
|
+
stakingPosition: AptosMappedStakingPosition | AptosStakingPosition,
|
|
44
|
+
): boolean => {
|
|
45
|
+
return stakingPosition.active.gt(0);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const canWithdraw = (
|
|
49
|
+
stakingPosition: AptosMappedStakingPosition | AptosStakingPosition,
|
|
50
|
+
): boolean => {
|
|
51
|
+
return stakingPosition.inactive.gt(0);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const canRestake = (
|
|
55
|
+
stakingPosition: AptosMappedStakingPosition | AptosStakingPosition,
|
|
56
|
+
): boolean => {
|
|
57
|
+
return stakingPosition.pendingInactive.gt(0);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const getStakingPosition = (account: AptosAccount, validatorAddress: string) =>
|
|
61
|
+
(account.aptosResources?.stakingPositions ?? []).find(
|
|
62
|
+
stakingPosition => stakingPosition.validatorId === validatorAddress,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
export const getDelegationOpMaxAmount = (
|
|
66
|
+
account: AptosAccount,
|
|
67
|
+
validatorAddress: string,
|
|
68
|
+
mode: string,
|
|
69
|
+
): BigNumber => {
|
|
70
|
+
let maxAmount: BigNumber | undefined;
|
|
71
|
+
|
|
72
|
+
const stakingPosition = getStakingPosition(account, validatorAddress);
|
|
73
|
+
|
|
74
|
+
switch (mode) {
|
|
75
|
+
case "unstake":
|
|
76
|
+
maxAmount = stakingPosition?.active;
|
|
77
|
+
break;
|
|
78
|
+
case "withdraw":
|
|
79
|
+
maxAmount = stakingPosition?.inactive;
|
|
80
|
+
break;
|
|
81
|
+
case "restake":
|
|
82
|
+
maxAmount = stakingPosition?.pendingInactive;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (maxAmount === undefined || maxAmount.lt(0)) {
|
|
86
|
+
return new BigNumber(0);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return maxAmount;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const formatUnlockTime = (epochSecs: string): string => {
|
|
93
|
+
const unlockTime = parseInt(epochSecs, 10) * 1000; // Convert to ms
|
|
94
|
+
const now = Date.now();
|
|
95
|
+
const diffMs = unlockTime - now;
|
|
96
|
+
|
|
97
|
+
if (diffMs <= 0) return "Unlocked";
|
|
98
|
+
|
|
99
|
+
const totalMinutes = Math.floor(diffMs / (1000 * 60));
|
|
100
|
+
const days = Math.floor(totalMinutes / (60 * 24));
|
|
101
|
+
const hours = Math.floor((totalMinutes % (60 * 24)) / 60);
|
|
102
|
+
const minutes = totalMinutes % 60;
|
|
103
|
+
|
|
104
|
+
return `${days}d ${hours}h ${minutes}m`;
|
|
105
|
+
};
|
|
@@ -3,7 +3,7 @@ import { Operation } from "@ledgerhq/coin-framework/api/types";
|
|
|
3
3
|
import { AptosAsset } from "../types/assets";
|
|
4
4
|
import BigNumber from "bignumber.js";
|
|
5
5
|
import { EntryFunctionPayloadResponse, InputEntryFunctionData } from "@aptos-labs/ts-sdk";
|
|
6
|
-
import { APTOS_ASSET_ID,
|
|
6
|
+
import { APTOS_ASSET_ID, OP_TYPE } from "../constants";
|
|
7
7
|
import { compareAddress, getCoinAndAmounts } from "./getCoinAndAmounts";
|
|
8
8
|
import { calculateAmount } from "./calculateAmount";
|
|
9
9
|
import { processRecipients } from "./processRecipients";
|
|
@@ -18,12 +18,12 @@ export const convertFunctionPayloadResponseToInputEntryFunctionData = (
|
|
|
18
18
|
functionArguments: payload.arguments,
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
const detectType = (address: string, tx: AptosTransaction, value: BigNumber):
|
|
22
|
-
let type = compareAddress(tx.sender, address) ?
|
|
21
|
+
const detectType = (address: string, tx: AptosTransaction, value: BigNumber): OP_TYPE => {
|
|
22
|
+
let type = compareAddress(tx.sender, address) ? OP_TYPE.OUT : OP_TYPE.IN;
|
|
23
23
|
|
|
24
24
|
if (!value) {
|
|
25
25
|
// skip transaction that result no Aptos change
|
|
26
|
-
type =
|
|
26
|
+
type = OP_TYPE.UNKNOWN;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
return type;
|
|
@@ -88,7 +88,7 @@ export function transactionsToOperations(
|
|
|
88
88
|
|
|
89
89
|
processRecipients(payload, address, op, function_address);
|
|
90
90
|
|
|
91
|
-
if (op.type !==
|
|
91
|
+
if (op.type !== OP_TYPE.UNKNOWN && coin_id !== null) {
|
|
92
92
|
if (coin_id === APTOS_ASSET_ID) {
|
|
93
93
|
acc.push(op);
|
|
94
94
|
return acc;
|