@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
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import {
|
|
3
|
+
canRestake,
|
|
4
|
+
canStake,
|
|
5
|
+
canUnstake,
|
|
6
|
+
canWithdraw,
|
|
7
|
+
getDelegationOpMaxAmount,
|
|
8
|
+
mapStakingPositions,
|
|
9
|
+
} from "../../logic/staking";
|
|
10
|
+
import { createFixtureAccount } from "../../bridge/bridge.fixture";
|
|
11
|
+
import { MIN_COINS_ON_SHARES_POOL } from "../../constants";
|
|
12
|
+
|
|
13
|
+
const stakingPositions = [
|
|
14
|
+
{
|
|
15
|
+
active: BigNumber(123456789),
|
|
16
|
+
inactive: BigNumber(567567567),
|
|
17
|
+
pendingInactive: BigNumber(5345),
|
|
18
|
+
validatorId: "validator-1",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
active: BigNumber(0),
|
|
22
|
+
inactive: BigNumber(33333),
|
|
23
|
+
pendingInactive: BigNumber(67868678),
|
|
24
|
+
validatorId: "validator-2",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
active: BigNumber(45864986459),
|
|
28
|
+
inactive: BigNumber(0),
|
|
29
|
+
pendingInactive: BigNumber(0),
|
|
30
|
+
validatorId: "validator-3",
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
const nonBreakableSpace = " ";
|
|
35
|
+
|
|
36
|
+
describe("mapStakingPositions", () => {
|
|
37
|
+
it("returns the staking positions per validator", () => {
|
|
38
|
+
const validators = [
|
|
39
|
+
{
|
|
40
|
+
activeStake: BigNumber(8972343459783425),
|
|
41
|
+
commission: BigNumber(8),
|
|
42
|
+
address: "validator-1",
|
|
43
|
+
name: "validator-1",
|
|
44
|
+
shares: "no-shares",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
activeStake: BigNumber(172343459783425),
|
|
48
|
+
commission: BigNumber(8),
|
|
49
|
+
address: "validator-2",
|
|
50
|
+
name: "validator-2",
|
|
51
|
+
shares: "no-shares",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
activeStake: BigNumber(1743459783425),
|
|
55
|
+
commission: BigNumber(7),
|
|
56
|
+
address: "validator-3",
|
|
57
|
+
name: "validator-3",
|
|
58
|
+
shares: "no-shares",
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
const expected = [
|
|
63
|
+
{
|
|
64
|
+
active: BigNumber("123456789"),
|
|
65
|
+
inactive: BigNumber("567567567"),
|
|
66
|
+
pendingInactive: BigNumber("5345"),
|
|
67
|
+
validatorId: "validator-1",
|
|
68
|
+
formattedAmount: `1.23456${nonBreakableSpace}APT`,
|
|
69
|
+
formattedPending: `0.00005345${nonBreakableSpace}APT`,
|
|
70
|
+
formattedAvailable: `5.67567${nonBreakableSpace}APT`,
|
|
71
|
+
rank: 0,
|
|
72
|
+
validator: {
|
|
73
|
+
activeStake: BigNumber("8972343459783425"),
|
|
74
|
+
commission: BigNumber("8"),
|
|
75
|
+
address: "validator-1",
|
|
76
|
+
name: "validator-1",
|
|
77
|
+
shares: "no-shares",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
active: BigNumber("0"),
|
|
82
|
+
inactive: BigNumber("33333"),
|
|
83
|
+
pendingInactive: BigNumber("67868678"),
|
|
84
|
+
validatorId: "validator-2",
|
|
85
|
+
formattedAmount: `0${nonBreakableSpace}APT`,
|
|
86
|
+
formattedPending: `0.678686${nonBreakableSpace}APT`,
|
|
87
|
+
formattedAvailable: `0.00033333${nonBreakableSpace}APT`,
|
|
88
|
+
rank: 1,
|
|
89
|
+
validator: {
|
|
90
|
+
activeStake: BigNumber("172343459783425"),
|
|
91
|
+
commission: BigNumber("8"),
|
|
92
|
+
address: "validator-2",
|
|
93
|
+
name: "validator-2",
|
|
94
|
+
shares: "no-shares",
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
active: BigNumber("45864986459"),
|
|
99
|
+
inactive: BigNumber("0"),
|
|
100
|
+
pendingInactive: BigNumber("0"),
|
|
101
|
+
validatorId: "validator-3",
|
|
102
|
+
formattedAmount: `458.649${nonBreakableSpace}APT`,
|
|
103
|
+
formattedPending: `0${nonBreakableSpace}APT`,
|
|
104
|
+
formattedAvailable: `0${nonBreakableSpace}APT`,
|
|
105
|
+
rank: 2,
|
|
106
|
+
validator: {
|
|
107
|
+
activeStake: BigNumber("1743459783425"),
|
|
108
|
+
commission: BigNumber("7"),
|
|
109
|
+
address: "validator-3",
|
|
110
|
+
name: "validator-3",
|
|
111
|
+
shares: "no-shares",
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
expect(
|
|
117
|
+
mapStakingPositions(stakingPositions, validators, {
|
|
118
|
+
name: "Aptos",
|
|
119
|
+
code: "APT",
|
|
120
|
+
magnitude: 8,
|
|
121
|
+
}),
|
|
122
|
+
).toMatchObject(expected);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe("canStake", () => {
|
|
127
|
+
it(`returns false for an account with a balance with less than ${MIN_COINS_ON_SHARES_POOL} APT`, () => {
|
|
128
|
+
const account = createFixtureAccount({
|
|
129
|
+
balance: BigNumber(5),
|
|
130
|
+
spendableBalance: BigNumber(5),
|
|
131
|
+
});
|
|
132
|
+
const expected = canStake(account);
|
|
133
|
+
expect(expected).toBe(false);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it(`returns true for an account with balance with more than ${MIN_COINS_ON_SHARES_POOL} APT`, () => {
|
|
137
|
+
const account = createFixtureAccount({
|
|
138
|
+
balance: BigNumber(1212312312312),
|
|
139
|
+
spendableBalance: BigNumber(1212312312312),
|
|
140
|
+
});
|
|
141
|
+
const expected = canStake(account);
|
|
142
|
+
expect(expected).toBe(true);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe("canUnstake", () => {
|
|
147
|
+
it("returns true if there's no amount staked", () => {
|
|
148
|
+
const expected = canUnstake(stakingPositions[0]);
|
|
149
|
+
expect(expected).toBe(true);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("returns false if there's no amount staked", () => {
|
|
153
|
+
const expected = canUnstake(stakingPositions[1]);
|
|
154
|
+
expect(expected).toBe(false);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe("canWithdraw", () => {
|
|
159
|
+
it("returns true if there's no amount inactive", () => {
|
|
160
|
+
const expected = canWithdraw(stakingPositions[0]);
|
|
161
|
+
expect(expected).toBe(true);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("returns false if there's no amount inactive", () => {
|
|
165
|
+
const expected = canWithdraw(stakingPositions[2]);
|
|
166
|
+
expect(expected).toBe(false);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe("canRestake", () => {
|
|
171
|
+
it("returns true if there's no amount inactive", () => {
|
|
172
|
+
const expected = canRestake(stakingPositions[0]);
|
|
173
|
+
expect(expected).toBe(true);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("returns false if there's no amount inactive", () => {
|
|
177
|
+
const expected = canRestake(stakingPositions[2]);
|
|
178
|
+
expect(expected).toBe(false);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe("getDelegationOpMaxAmount", () => {
|
|
183
|
+
it("get maximum amount available to unstake", () => {
|
|
184
|
+
const account = createFixtureAccount({
|
|
185
|
+
aptosResources: {
|
|
186
|
+
activeBalance: BigNumber(45988443248),
|
|
187
|
+
pendingInactiveBalance: BigNumber(67874023),
|
|
188
|
+
inactiveBalance: BigNumber(567600900),
|
|
189
|
+
stakingPositions,
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
const expected = getDelegationOpMaxAmount(account, "validator-1", "unstake");
|
|
193
|
+
expect(expected).toEqual(BigNumber(123456789));
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("get maximum amount available to withdraw", () => {
|
|
197
|
+
const account = createFixtureAccount({
|
|
198
|
+
aptosResources: {
|
|
199
|
+
activeBalance: BigNumber(45988443248),
|
|
200
|
+
pendingInactiveBalance: BigNumber(67874023),
|
|
201
|
+
inactiveBalance: BigNumber(567600900),
|
|
202
|
+
stakingPositions,
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
const expected = getDelegationOpMaxAmount(account, "validator-1", "withdraw");
|
|
206
|
+
expect(expected).toEqual(BigNumber(567567567));
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("get maximum amount available to restake", () => {
|
|
210
|
+
const account = createFixtureAccount({
|
|
211
|
+
aptosResources: {
|
|
212
|
+
activeBalance: BigNumber(45988443248),
|
|
213
|
+
pendingInactiveBalance: BigNumber(67874023),
|
|
214
|
+
inactiveBalance: BigNumber(567600900),
|
|
215
|
+
stakingPositions,
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
const expected = getDelegationOpMaxAmount(account, "validator-1", "restake");
|
|
219
|
+
expect(expected).toEqual(BigNumber(5345));
|
|
220
|
+
});
|
|
221
|
+
});
|
|
@@ -649,7 +649,7 @@ describe("Aptos API", () => {
|
|
|
649
649
|
},
|
|
650
650
|
});
|
|
651
651
|
|
|
652
|
-
expect(fees.value.toString()).toEqual("
|
|
652
|
+
expect(fees.value.toString()).toEqual("44");
|
|
653
653
|
});
|
|
654
654
|
|
|
655
655
|
it("estimates the fees for token coin", async () => {
|
|
@@ -716,7 +716,7 @@ describe("Aptos API", () => {
|
|
|
716
716
|
},
|
|
717
717
|
});
|
|
718
718
|
|
|
719
|
-
expect(fees.value.toString()).toEqual("
|
|
719
|
+
expect(fees.value.toString()).toEqual("22");
|
|
720
720
|
});
|
|
721
721
|
|
|
722
722
|
it("estimates the fees for token FA", async () => {
|
|
@@ -782,7 +782,7 @@ describe("Aptos API", () => {
|
|
|
782
782
|
},
|
|
783
783
|
});
|
|
784
784
|
|
|
785
|
-
expect(fees.value.toString()).toEqual("
|
|
785
|
+
expect(fees.value.toString()).toEqual("33");
|
|
786
786
|
});
|
|
787
787
|
});
|
|
788
788
|
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Aptos } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import { ApolloClient } from "@apollo/client";
|
|
3
|
+
import { getValidators } from "../../network/validators";
|
|
4
|
+
import BigNumber from "bignumber.js";
|
|
5
|
+
|
|
6
|
+
jest.mock("@aptos-labs/ts-sdk");
|
|
7
|
+
let mockedAptos: jest.Mocked<any>;
|
|
8
|
+
|
|
9
|
+
jest.mock("@apollo/client");
|
|
10
|
+
let mockedApolloClient: jest.Mocked<any>;
|
|
11
|
+
|
|
12
|
+
describe("getValidators", () => {
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
mockedAptos = jest.mocked(Aptos);
|
|
15
|
+
mockedApolloClient = jest.mocked(ApolloClient);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterAll(() => {
|
|
19
|
+
jest.useRealTimers();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const current_delegator_balances = [
|
|
23
|
+
{
|
|
24
|
+
__typename: "current_delegator_balances",
|
|
25
|
+
current_pool_balance: {
|
|
26
|
+
__typename: "current_delegated_staking_pool_balances",
|
|
27
|
+
total_coins: 211045219713562,
|
|
28
|
+
operator_commission_percentage: 900,
|
|
29
|
+
staking_pool_address: "0x001232f58b963938486a11f88c1c36d61d82738b1828625a95a1e85b4c8d1282",
|
|
30
|
+
total_shares: 200020456320587.72,
|
|
31
|
+
},
|
|
32
|
+
shares: 94692342176,
|
|
33
|
+
delegator_address: "0xb1a1d4624c5163445c993d9db9cd5bd3fc6b2c5e85a14216c3781d04d4f92d08",
|
|
34
|
+
staking_pool_metadata: {
|
|
35
|
+
__typename: "current_staking_pool_voter",
|
|
36
|
+
operator_aptos_name: [],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
__typename: "current_delegator_balances",
|
|
41
|
+
current_pool_balance: {
|
|
42
|
+
__typename: "current_delegated_staking_pool_balances",
|
|
43
|
+
total_coins: 116781362397133,
|
|
44
|
+
operator_commission_percentage: 499,
|
|
45
|
+
staking_pool_address: "0x05dece2ed08c68f8730527e9b3ebb3536efc3361f4ef37ba0b16a3310db836af",
|
|
46
|
+
total_shares: 115552903623705.77,
|
|
47
|
+
},
|
|
48
|
+
shares: 15149284011,
|
|
49
|
+
delegator_address: "0x4ee1f2b7a1069a09b7d9c800928bfe851bc7649a0fb4e0d918554e0d445db4bc",
|
|
50
|
+
staking_pool_metadata: {
|
|
51
|
+
__typename: "current_staking_pool_voter",
|
|
52
|
+
operator_aptos_name: [
|
|
53
|
+
{
|
|
54
|
+
__typename: "current_aptos_names",
|
|
55
|
+
domain_with_suffix: "cryptomolot.apt",
|
|
56
|
+
is_active: true,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
const expectedResponse = [
|
|
64
|
+
{
|
|
65
|
+
activeStake: BigNumber(211045219713562),
|
|
66
|
+
address: "0x001232f58b963938486a11f88c1c36d61d82738b1828625a95a1e85b4c8d1282",
|
|
67
|
+
commission: BigNumber(9),
|
|
68
|
+
name: "0x001232f58b963938486a11f88c1c36d61d82738b1828625a95a1e85b4c8d1282",
|
|
69
|
+
nextUnlockTime: "32d 5h 26m",
|
|
70
|
+
shares: 200020456320587.72,
|
|
71
|
+
wwwUrl:
|
|
72
|
+
"https://explorer.aptoslabs.com/account/0x001232f58b963938486a11f88c1c36d61d82738b1828625a95a1e85b4c8d1282?network=mainnet",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
activeStake: BigNumber(116781362397133),
|
|
76
|
+
address: "0x05dece2ed08c68f8730527e9b3ebb3536efc3361f4ef37ba0b16a3310db836af",
|
|
77
|
+
commission: BigNumber(4.99),
|
|
78
|
+
name: "cryptomolot.apt",
|
|
79
|
+
nextUnlockTime: "32d 5h 26m",
|
|
80
|
+
shares: 115552903623705.77,
|
|
81
|
+
wwwUrl:
|
|
82
|
+
"https://explorer.aptoslabs.com/account/0x05dece2ed08c68f8730527e9b3ebb3536efc3361f4ef37ba0b16a3310db836af?network=mainnet",
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
it("returns the correct information", async () => {
|
|
87
|
+
mockedAptos.mockImplementation(() => ({
|
|
88
|
+
getAccountResource: async () => ({ locked_until_secs: "1750051574" }),
|
|
89
|
+
}));
|
|
90
|
+
|
|
91
|
+
mockedApolloClient.mockImplementation(() => ({
|
|
92
|
+
query: async () => ({
|
|
93
|
+
data: {
|
|
94
|
+
current_delegator_balances,
|
|
95
|
+
},
|
|
96
|
+
}),
|
|
97
|
+
}));
|
|
98
|
+
|
|
99
|
+
jest.useFakeTimers().setSystemTime(new Date("2025-05-15"));
|
|
100
|
+
|
|
101
|
+
const validators = await getValidators("aptos");
|
|
102
|
+
|
|
103
|
+
expect(validators).toMatchObject(expectedResponse);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IconGenerator } from "../../utils";
|
|
2
|
+
|
|
3
|
+
describe("IconGenerator", () => {
|
|
4
|
+
it("returns a picture bitmap", () => {
|
|
5
|
+
const icon = new IconGenerator("seed");
|
|
6
|
+
expect(icon).toBeInstanceOf(IconGenerator);
|
|
7
|
+
expect(icon.generate).toBeInstanceOf(Function);
|
|
8
|
+
|
|
9
|
+
const iconString = icon.generate();
|
|
10
|
+
expect(typeof iconString).toBe("string");
|
|
11
|
+
expect(iconString.startsWith("data:image/bmp;base64")).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { endpointByCurrencyId } from "../../utils";
|
|
2
|
+
|
|
3
|
+
describe("endpointByCurrencyId", () => {
|
|
4
|
+
it("gets the aptos endpoint based on the currency id", () => {
|
|
5
|
+
expect(endpointByCurrencyId("aptos")).toBe("https://apt.coin.ledger.com/node/v1");
|
|
6
|
+
expect(endpointByCurrencyId("aptos_testnet")).toBe("https://apt.coin.ledger-stg.com/node/v1");
|
|
7
|
+
expect(() => endpointByCurrencyId("NONE")).toThrow(
|
|
8
|
+
"unexpected currency id format <NONE>, should be like aptos[_testnet]",
|
|
9
|
+
);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -33,6 +33,12 @@ export function createFixtureAccount(account?: Partial<AptosAccount>): AptosAcco
|
|
|
33
33
|
lastSyncDate: new Date(),
|
|
34
34
|
balanceHistoryCache: emptyHistoryCache,
|
|
35
35
|
swapHistory: [],
|
|
36
|
+
aptosResources: {
|
|
37
|
+
stakingPositions: [],
|
|
38
|
+
activeBalance: BigNumber(0),
|
|
39
|
+
inactiveBalance: BigNumber(0),
|
|
40
|
+
pendingInactiveBalance: BigNumber(0),
|
|
41
|
+
},
|
|
36
42
|
...account,
|
|
37
43
|
};
|
|
38
44
|
}
|
|
@@ -90,6 +96,12 @@ export function createFixtureAccountWithSubAccount(
|
|
|
90
96
|
swapHistory: [],
|
|
91
97
|
},
|
|
92
98
|
],
|
|
99
|
+
aptosResources: {
|
|
100
|
+
stakingPositions: [],
|
|
101
|
+
activeBalance: BigNumber(0),
|
|
102
|
+
inactiveBalance: BigNumber(0),
|
|
103
|
+
pendingInactiveBalance: BigNumber(0),
|
|
104
|
+
},
|
|
93
105
|
...account,
|
|
94
106
|
};
|
|
95
107
|
}
|
|
@@ -1,28 +1,97 @@
|
|
|
1
1
|
import type { CommonDeviceTransactionField as DeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
|
|
2
|
-
import
|
|
2
|
+
import { Account, AccountLike } from "@ledgerhq/types-live";
|
|
3
|
+
import { Transaction } from "../types";
|
|
4
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/formatCurrencyUnit";
|
|
5
|
+
import { getAccountCurrency, getMainAccount } from "@ledgerhq/coin-framework/account/helpers";
|
|
3
6
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
function getDeviceTransactionConfig({
|
|
8
|
+
account,
|
|
9
|
+
parentAccount,
|
|
10
|
+
transaction,
|
|
11
|
+
}: {
|
|
12
|
+
account: AccountLike;
|
|
13
|
+
parentAccount: Account | null | undefined;
|
|
14
|
+
transaction: Transaction;
|
|
15
|
+
}): Array<DeviceTransactionField> {
|
|
16
|
+
const { mode } = transaction;
|
|
17
|
+
const fields: DeviceTransactionField[] = [];
|
|
18
|
+
const mainAccount = getMainAccount(account, parentAccount);
|
|
12
19
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
const { fees } = transaction;
|
|
21
|
+
if (fees) {
|
|
22
|
+
fields.push({
|
|
23
|
+
type: "text",
|
|
24
|
+
label: "Transaction Fee",
|
|
25
|
+
value: formatCurrencyUnit(getAccountCurrency(mainAccount).units[0], fees, {
|
|
26
|
+
showCode: true,
|
|
27
|
+
disableRounding: true,
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
18
31
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
if (mode === "send") {
|
|
33
|
+
if (account.type === "TokenAccount") {
|
|
34
|
+
fields.push({
|
|
35
|
+
type: "text",
|
|
36
|
+
label: "Type",
|
|
37
|
+
value: "Token transfer",
|
|
38
|
+
});
|
|
39
|
+
fields.push({
|
|
40
|
+
type: "text",
|
|
41
|
+
label: "Amount",
|
|
42
|
+
value: formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, {
|
|
43
|
+
showCode: true,
|
|
44
|
+
disableRounding: true,
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
47
|
+
} else if (account.type === "Account") {
|
|
48
|
+
fields.push({
|
|
49
|
+
type: "text",
|
|
50
|
+
label: "Amount",
|
|
51
|
+
value: formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, {
|
|
52
|
+
showCode: true,
|
|
53
|
+
disableRounding: true,
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
} else if ((mode === "stake" || mode === "restake") && account.type === "Account") {
|
|
58
|
+
fields.push({
|
|
59
|
+
type: "text",
|
|
60
|
+
label: "Delegate to",
|
|
61
|
+
value: transaction.recipient,
|
|
62
|
+
});
|
|
63
|
+
fields.push({
|
|
64
|
+
type: "text",
|
|
65
|
+
label: "Amount",
|
|
66
|
+
value: formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, {
|
|
67
|
+
showCode: true,
|
|
68
|
+
disableRounding: true,
|
|
69
|
+
}),
|
|
70
|
+
});
|
|
71
|
+
} else if (mode === "unstake" && account.type === "Account") {
|
|
72
|
+
fields.push({
|
|
73
|
+
type: "text",
|
|
74
|
+
label: "Undelegate from",
|
|
75
|
+
value: transaction.recipient,
|
|
76
|
+
});
|
|
77
|
+
fields.push({
|
|
78
|
+
type: "text",
|
|
79
|
+
label: "Amount",
|
|
80
|
+
value: formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, {
|
|
81
|
+
showCode: true,
|
|
82
|
+
disableRounding: true,
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
85
|
+
} else if (mode === "withdraw" && account.type === "Account") {
|
|
86
|
+
fields.push({
|
|
87
|
+
type: "text",
|
|
88
|
+
label: "Amount",
|
|
89
|
+
value: formatCurrencyUnit(getAccountCurrency(account).units[0], transaction.amount, {
|
|
90
|
+
showCode: true,
|
|
91
|
+
disableRounding: true,
|
|
92
|
+
}),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
26
95
|
|
|
27
96
|
return fields;
|
|
28
97
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AccountLike } from "@ledgerhq/types-live";
|
|
2
2
|
import { BigNumber } from "bignumber.js";
|
|
3
3
|
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
|
|
4
4
|
import { AptosAPI } from "../network";
|
|
5
5
|
import { getEstimatedGas } from "./getFeesForTransaction";
|
|
6
6
|
import { getMaxSendBalance } from "./logic";
|
|
7
|
-
import type { Transaction } from "../types";
|
|
8
7
|
import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../constants";
|
|
8
|
+
import type { AptosAccount, Transaction } from "../types";
|
|
9
9
|
|
|
10
10
|
const estimateMaxSpendable = async ({
|
|
11
11
|
account,
|
|
12
12
|
parentAccount,
|
|
13
13
|
transaction,
|
|
14
14
|
}: {
|
|
15
|
-
account: AccountLike
|
|
16
|
-
parentAccount?:
|
|
15
|
+
account: AccountLike<AptosAccount>;
|
|
16
|
+
parentAccount?: AptosAccount;
|
|
17
17
|
transaction?: Transaction;
|
|
18
18
|
}): Promise<BigNumber> => {
|
|
19
19
|
const mainAccount = getMainAccount(account, parentAccount);
|
|
@@ -30,7 +30,7 @@ const estimateMaxSpendable = async ({
|
|
|
30
30
|
gasUnitPrice = BigNumber(estimate.gasUnitPrice);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
return getMaxSendBalance(
|
|
33
|
+
return getMaxSendBalance(mainAccount, transaction, maxGasAmount, gasUnitPrice);
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
export default estimateMaxSpendable;
|
|
@@ -5,7 +5,13 @@ import BigNumber from "bignumber.js";
|
|
|
5
5
|
import { makeLRUCache, seconds } from "@ledgerhq/live-network/cache";
|
|
6
6
|
import { AptosAPI } from "../network";
|
|
7
7
|
import { getTokenAccount } from "./logic";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
DEFAULT_GAS,
|
|
10
|
+
DEFAULT_GAS_PRICE,
|
|
11
|
+
ESTIMATE_GAS_MUL,
|
|
12
|
+
ESTIMATE_GAS_MUL_FOR_STAKING,
|
|
13
|
+
STAKING_TX_MODES,
|
|
14
|
+
} from "../constants";
|
|
9
15
|
import type { Transaction, TransactionErrors } from "../types";
|
|
10
16
|
import buildTransaction from "../logic/buildTransaction";
|
|
11
17
|
|
|
@@ -38,14 +44,17 @@ export const getFee = async (
|
|
|
38
44
|
maxGasAmount: gasLimit.toString(),
|
|
39
45
|
gasUnitPrice: gasPrice.toString(),
|
|
40
46
|
};
|
|
47
|
+
|
|
41
48
|
if (account.xpub) {
|
|
42
49
|
try {
|
|
43
50
|
const publicKeyEd = new Ed25519PublicKey(account.xpub as string);
|
|
44
51
|
const tx = await buildTransaction(account, transaction, aptosClient);
|
|
45
|
-
const
|
|
46
|
-
const completedTx = simulation[0];
|
|
52
|
+
const [completedTx] = await aptosClient.simulateTransaction(publicKeyEd, tx);
|
|
47
53
|
|
|
48
|
-
|
|
54
|
+
const gasMultiplier = STAKING_TX_MODES.includes(transaction.mode)
|
|
55
|
+
? ESTIMATE_GAS_MUL_FOR_STAKING
|
|
56
|
+
: ESTIMATE_GAS_MUL;
|
|
57
|
+
gasLimit = new BigNumber(completedTx.gas_used).multipliedBy(gasMultiplier).integerValue();
|
|
49
58
|
gasPrice = new BigNumber(completedTx.gas_unit_price);
|
|
50
59
|
|
|
51
60
|
const expectedGas = gasPrice.multipliedBy(gasLimit);
|
|
@@ -55,9 +64,11 @@ export const getFee = async (
|
|
|
55
64
|
res.errors.maxGasAmount = "GasInsufficientBalance";
|
|
56
65
|
} else if (
|
|
57
66
|
!completedTx.vm_status.includes("INSUFFICIENT_BALANCE") &&
|
|
67
|
+
!completedTx.vm_status.includes("EDELEGATOR_ACTIVE_BALANCE_TOO_LOW") &&
|
|
68
|
+
!completedTx.vm_status.includes("EDELEGATOR_PENDING_INACTIVE_BALANCE_TOO_LOW") &&
|
|
58
69
|
!completedTx.vm_status.includes("0x203ed") // 0x203ed -> PROLOGUE_ECANT_PAY_GAS_DEPOSIT equivalent to INSUFFICIENT_BALANCE_FOR_TRANSACTION_FEE
|
|
59
70
|
) {
|
|
60
|
-
// INSUFFICIENT_BALANCE will be processed by getTransactionStatus
|
|
71
|
+
// INSUFFICIENT_BALANCE and EDELEGATOR_ACTIVE_BALANCE_TOO_LOW will be processed by getTransactionStatus
|
|
61
72
|
throw Error(`Simulation failed with following error: ${completedTx.vm_status}`);
|
|
62
73
|
}
|
|
63
74
|
}
|
|
@@ -70,6 +81,7 @@ export const getFee = async (
|
|
|
70
81
|
throw error;
|
|
71
82
|
}
|
|
72
83
|
}
|
|
84
|
+
|
|
73
85
|
return res;
|
|
74
86
|
};
|
|
75
87
|
|