@ledgerhq/coin-aptos 2.5.1 → 2.5.2-nightly.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.unimportedrc.json +5 -8
- package/CHANGELOG.md +8 -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 +12 -7
- 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
|
@@ -12,9 +12,38 @@ import {
|
|
|
12
12
|
InvalidAddress,
|
|
13
13
|
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
14
14
|
NotEnoughBalance,
|
|
15
|
-
|
|
15
|
+
NotEnoughToRestake,
|
|
16
|
+
NotEnoughToStake,
|
|
17
|
+
NotEnoughToUnstake,
|
|
16
18
|
RecipientRequired,
|
|
17
19
|
} from "@ledgerhq/errors";
|
|
20
|
+
import { MIN_COINS_ON_SHARES_POOL } from "../../constants";
|
|
21
|
+
|
|
22
|
+
const aptosResources = {
|
|
23
|
+
activeBalance: BigNumber(45988443248),
|
|
24
|
+
pendingInactiveBalance: BigNumber(67874023),
|
|
25
|
+
inactiveBalance: BigNumber(567600900),
|
|
26
|
+
stakingPositions: [
|
|
27
|
+
{
|
|
28
|
+
active: BigNumber(123456789),
|
|
29
|
+
inactive: BigNumber(567567567),
|
|
30
|
+
pendingInactive: BigNumber(5345),
|
|
31
|
+
validatorId: "validator-1",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
active: BigNumber(3),
|
|
35
|
+
inactive: BigNumber(33333),
|
|
36
|
+
pendingInactive: BigNumber(67868678),
|
|
37
|
+
validatorId: "validator-2",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
active: BigNumber(45864986459),
|
|
41
|
+
inactive: BigNumber(0),
|
|
42
|
+
pendingInactive: BigNumber(0),
|
|
43
|
+
validatorId: "validator-3",
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
};
|
|
18
47
|
|
|
19
48
|
describe("getTransactionStatus Test", () => {
|
|
20
49
|
it("should return error for AmountRequired", async () => {
|
|
@@ -53,6 +82,7 @@ describe("getTransactionStatus Test", () => {
|
|
|
53
82
|
const expected = {
|
|
54
83
|
errors: {
|
|
55
84
|
fees: new FeeNotLoaded(),
|
|
85
|
+
amount: new NotEnoughBalance(),
|
|
56
86
|
},
|
|
57
87
|
warnings: {},
|
|
58
88
|
estimatedFees: BigNumber(0),
|
|
@@ -200,7 +230,7 @@ describe("getTransactionStatus Test", () => {
|
|
|
200
230
|
|
|
201
231
|
const expected = {
|
|
202
232
|
errors: {
|
|
203
|
-
amount: new
|
|
233
|
+
amount: new NotEnoughBalance(),
|
|
204
234
|
},
|
|
205
235
|
warnings: {},
|
|
206
236
|
estimatedFees: BigNumber(0),
|
|
@@ -225,6 +255,7 @@ describe("getTransactionStatus Test", () => {
|
|
|
225
255
|
const expected = {
|
|
226
256
|
errors: {
|
|
227
257
|
recipient: new RecipientRequired(),
|
|
258
|
+
amount: new NotEnoughBalance(),
|
|
228
259
|
},
|
|
229
260
|
warnings: {},
|
|
230
261
|
estimatedFees: BigNumber(2),
|
|
@@ -315,7 +346,6 @@ describe("getTransactionStatus Test", () => {
|
|
|
315
346
|
|
|
316
347
|
const transaction = createFixtureTransaction();
|
|
317
348
|
transaction.recipient = "0x" + "0".repeat(64);
|
|
318
|
-
transaction.amount = BigNumber(2);
|
|
319
349
|
transaction.fees = BigNumber(2);
|
|
320
350
|
transaction.useAllAmount = true;
|
|
321
351
|
|
|
@@ -331,4 +361,218 @@ describe("getTransactionStatus Test", () => {
|
|
|
331
361
|
|
|
332
362
|
expect(result).toEqual(expected);
|
|
333
363
|
});
|
|
364
|
+
|
|
365
|
+
it("should return not enough balance if trying to stake more than the current balance", async () => {
|
|
366
|
+
const account = createFixtureAccount({
|
|
367
|
+
balance: BigNumber(123456),
|
|
368
|
+
spendableBalance: BigNumber(123456),
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
const transaction = createFixtureTransaction({ mode: "stake", amount: BigNumber(123453336) });
|
|
372
|
+
|
|
373
|
+
const result = await getTransactionStatus(account, transaction);
|
|
374
|
+
|
|
375
|
+
const expected = {
|
|
376
|
+
errors: {
|
|
377
|
+
amount: new NotEnoughBalance(),
|
|
378
|
+
},
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
expect(result).toMatchObject(expected);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it(`should return not enough balance to stake if trying to stake less than ${MIN_COINS_ON_SHARES_POOL} APT`, async () => {
|
|
385
|
+
const account = createFixtureAccount({
|
|
386
|
+
balance: BigNumber(123456),
|
|
387
|
+
spendableBalance: BigNumber(123456),
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
const transaction = createFixtureTransaction({ mode: "stake", amount: BigNumber(5) });
|
|
391
|
+
|
|
392
|
+
const result = await getTransactionStatus(account, transaction);
|
|
393
|
+
|
|
394
|
+
const expected = {
|
|
395
|
+
errors: {
|
|
396
|
+
amount: new NotEnoughToStake(),
|
|
397
|
+
},
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
expect(result).toMatchObject(expected);
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it(`should return not enough balance to stake if trying to stake the max balance but it is less than ${MIN_COINS_ON_SHARES_POOL} APT`, async () => {
|
|
404
|
+
const account = createFixtureAccount({
|
|
405
|
+
balance: BigNumber(4),
|
|
406
|
+
spendableBalance: BigNumber(4),
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
const transaction = createFixtureTransaction({ mode: "stake", useAllAmount: true });
|
|
410
|
+
|
|
411
|
+
const result = await getTransactionStatus(account, transaction);
|
|
412
|
+
|
|
413
|
+
const expected = {
|
|
414
|
+
errors: {
|
|
415
|
+
amount: new NotEnoughToStake(),
|
|
416
|
+
},
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
expect(result).toMatchObject(expected);
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
it("should return an error if there's no staking position to restake", async () => {
|
|
423
|
+
const account = createFixtureAccount({
|
|
424
|
+
balance: BigNumber(4),
|
|
425
|
+
spendableBalance: BigNumber(4),
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
const transaction = createFixtureTransaction({ mode: "restake" });
|
|
429
|
+
|
|
430
|
+
const result = await getTransactionStatus(account, transaction);
|
|
431
|
+
|
|
432
|
+
const expected = {
|
|
433
|
+
errors: {
|
|
434
|
+
recipient: new RecipientRequired(),
|
|
435
|
+
},
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
expect(result).toMatchObject(expected);
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
it("should return an error if there's not enough pending inactive balance", async () => {
|
|
442
|
+
const account = createFixtureAccount({
|
|
443
|
+
balance: BigNumber(4),
|
|
444
|
+
spendableBalance: BigNumber(4),
|
|
445
|
+
aptosResources,
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
const transaction = createFixtureTransaction({
|
|
449
|
+
mode: "restake",
|
|
450
|
+
recipient: "validator-1",
|
|
451
|
+
amount: BigNumber(67874022223),
|
|
452
|
+
fees: BigNumber(1),
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
const result = await getTransactionStatus(account, transaction);
|
|
456
|
+
|
|
457
|
+
const expected = {
|
|
458
|
+
errors: {
|
|
459
|
+
amount: new NotEnoughBalance(),
|
|
460
|
+
},
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
expect(result).toMatchObject(expected);
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
it(`should return not enough amount if trying to restake but it is less than ${MIN_COINS_ON_SHARES_POOL} APT`, async () => {
|
|
467
|
+
const account = createFixtureAccount({
|
|
468
|
+
balance: BigNumber(4),
|
|
469
|
+
spendableBalance: BigNumber(4),
|
|
470
|
+
aptosResources,
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
const transaction = createFixtureTransaction({
|
|
474
|
+
mode: "restake",
|
|
475
|
+
recipient: "validator-2",
|
|
476
|
+
amount: BigNumber(4),
|
|
477
|
+
fees: BigNumber(1),
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
const result = await getTransactionStatus(account, transaction);
|
|
481
|
+
|
|
482
|
+
const expected = {
|
|
483
|
+
errors: {
|
|
484
|
+
amount: new NotEnoughToRestake(),
|
|
485
|
+
},
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
expect(result).toMatchObject(expected);
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
it("should return an error if there's no staking position to unstake", async () => {
|
|
492
|
+
const account = createFixtureAccount({
|
|
493
|
+
balance: BigNumber(4),
|
|
494
|
+
spendableBalance: BigNumber(4),
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
const transaction = createFixtureTransaction({ mode: "unstake" });
|
|
498
|
+
|
|
499
|
+
const result = await getTransactionStatus(account, transaction);
|
|
500
|
+
|
|
501
|
+
const expected = {
|
|
502
|
+
errors: {
|
|
503
|
+
recipient: new RecipientRequired(),
|
|
504
|
+
},
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
expect(result).toMatchObject(expected);
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
it(`should return not enough to unstake if the amount to unstake is less than ${MIN_COINS_ON_SHARES_POOL} APT`, async () => {
|
|
511
|
+
const account = createFixtureAccount({
|
|
512
|
+
balance: BigNumber(4),
|
|
513
|
+
spendableBalance: BigNumber(4),
|
|
514
|
+
aptosResources,
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
const transaction = createFixtureTransaction({
|
|
518
|
+
mode: "unstake",
|
|
519
|
+
recipient: "validator-2",
|
|
520
|
+
amount: BigNumber(2),
|
|
521
|
+
fees: BigNumber(0.5),
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
const result = await getTransactionStatus(account, transaction);
|
|
525
|
+
|
|
526
|
+
const expected = {
|
|
527
|
+
errors: {
|
|
528
|
+
amount: new NotEnoughToUnstake(),
|
|
529
|
+
},
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
expect(result).toMatchObject(expected);
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
it("should return an error if there's no staking position to withdraw", async () => {
|
|
536
|
+
const account = createFixtureAccount({
|
|
537
|
+
balance: BigNumber(4),
|
|
538
|
+
spendableBalance: BigNumber(4),
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
const transaction = createFixtureTransaction({ mode: "withdraw" });
|
|
542
|
+
|
|
543
|
+
const result = await getTransactionStatus(account, transaction);
|
|
544
|
+
|
|
545
|
+
const expected = {
|
|
546
|
+
errors: {
|
|
547
|
+
recipient: new RecipientRequired(),
|
|
548
|
+
},
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
expect(result).toMatchObject(expected);
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
it("should return an error if there's not enough inactive balance to withdraw", async () => {
|
|
555
|
+
const account = createFixtureAccount({
|
|
556
|
+
balance: BigNumber(4),
|
|
557
|
+
spendableBalance: BigNumber(4),
|
|
558
|
+
aptosResources,
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
const transaction = createFixtureTransaction({
|
|
562
|
+
mode: "restake",
|
|
563
|
+
recipient: "validator-1",
|
|
564
|
+
amount: BigNumber(56756756745),
|
|
565
|
+
fees: BigNumber(1),
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
const result = await getTransactionStatus(account, transaction);
|
|
569
|
+
|
|
570
|
+
const expected = {
|
|
571
|
+
errors: {
|
|
572
|
+
amount: new NotEnoughBalance(),
|
|
573
|
+
},
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
expect(result).toMatchObject(expected);
|
|
577
|
+
});
|
|
334
578
|
});
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
jest.mock("../../network/validators", () => ({
|
|
2
|
+
getValidators: jest.fn(() => Promise.resolve([])),
|
|
3
|
+
}));
|
|
4
|
+
|
|
1
5
|
import BigNumber from "bignumber.js";
|
|
2
6
|
import { createBridges } from "../../bridge";
|
|
3
7
|
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
|
|
@@ -11,7 +15,7 @@ describe("Aptos bridge interface ", () => {
|
|
|
11
15
|
const cryptoCurrency = getCryptoCurrencyById("aptos");
|
|
12
16
|
const result = bridge.currencyBridge.preload(cryptoCurrency);
|
|
13
17
|
expect(result).toBeInstanceOf(Promise);
|
|
14
|
-
await expect(result).resolves.
|
|
18
|
+
await expect(result).resolves.toMatchObject({ validatorsWithMeta: [] });
|
|
15
19
|
});
|
|
16
20
|
|
|
17
21
|
it("should have a hydrate method that is a function", () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EntryFunctionPayloadResponse } from "@aptos-labs/ts-sdk";
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
|
-
import { APTOS_COIN_CHANGE,
|
|
3
|
+
import { APTOS_COIN_CHANGE, OP_TYPE } from "../../constants";
|
|
4
4
|
import { getMaxSendBalance, getBlankOperation, txsToOps } from "../../bridge/logic";
|
|
5
5
|
import type { AptosTransaction, TransactionOptions } from "../../types";
|
|
6
6
|
import { createFixtureAccount, createFixtureTransaction } from "../../bridge/bridge.fixture";
|
|
@@ -19,7 +19,7 @@ describe("Aptos logic ", () => {
|
|
|
19
19
|
const transaction = createFixtureTransaction();
|
|
20
20
|
const gas = new BigNumber(200);
|
|
21
21
|
const gasPrice = new BigNumber(100);
|
|
22
|
-
const result = getMaxSendBalance(
|
|
22
|
+
const result = getMaxSendBalance(account, transaction, gas, gasPrice);
|
|
23
23
|
expect(result.isEqualTo(amount.minus(gas.multipliedBy(gasPrice)))).toBe(true);
|
|
24
24
|
});
|
|
25
25
|
|
|
@@ -28,7 +28,7 @@ describe("Aptos logic ", () => {
|
|
|
28
28
|
const transaction = createFixtureTransaction();
|
|
29
29
|
const gas = new BigNumber(200);
|
|
30
30
|
const gasPrice = new BigNumber(100);
|
|
31
|
-
const result = getMaxSendBalance(
|
|
31
|
+
const result = getMaxSendBalance(account, transaction, gas, gasPrice);
|
|
32
32
|
expect(result.isEqualTo(new BigNumber(0))).toBe(true);
|
|
33
33
|
});
|
|
34
34
|
|
|
@@ -37,7 +37,7 @@ describe("Aptos logic ", () => {
|
|
|
37
37
|
const transaction = createFixtureTransaction();
|
|
38
38
|
const gas = new BigNumber(200);
|
|
39
39
|
const gasPrice = new BigNumber(100);
|
|
40
|
-
const result = getMaxSendBalance(
|
|
40
|
+
const result = getMaxSendBalance(account, transaction, gas, gasPrice);
|
|
41
41
|
expect(result.isEqualTo(new BigNumber(0))).toBe(true);
|
|
42
42
|
});
|
|
43
43
|
|
|
@@ -46,7 +46,7 @@ describe("Aptos logic ", () => {
|
|
|
46
46
|
const transaction = createFixtureTransaction();
|
|
47
47
|
const gas = new BigNumber(200);
|
|
48
48
|
const gasPrice = new BigNumber(100);
|
|
49
|
-
const result = getMaxSendBalance(
|
|
49
|
+
const result = getMaxSendBalance(account, transaction, gas, gasPrice);
|
|
50
50
|
expect(result.isEqualTo(new BigNumber(0))).toBe(true);
|
|
51
51
|
});
|
|
52
52
|
|
|
@@ -56,7 +56,7 @@ describe("Aptos logic ", () => {
|
|
|
56
56
|
const transaction = createFixtureTransaction();
|
|
57
57
|
const gas = new BigNumber(0);
|
|
58
58
|
const gasPrice = new BigNumber(0);
|
|
59
|
-
const result = getMaxSendBalance(
|
|
59
|
+
const result = getMaxSendBalance(account, transaction, gas, gasPrice);
|
|
60
60
|
expect(result.isEqualTo(amount)).toBe(true);
|
|
61
61
|
});
|
|
62
62
|
});
|
|
@@ -225,7 +225,7 @@ describe("Aptos sync logic ", () => {
|
|
|
225
225
|
expect(result[0]).toEqual({
|
|
226
226
|
id: expect.any(String),
|
|
227
227
|
hash: "0x123",
|
|
228
|
-
type:
|
|
228
|
+
type: OP_TYPE.OUT,
|
|
229
229
|
value: new BigNumber(100),
|
|
230
230
|
fee: new BigNumber(20000),
|
|
231
231
|
blockHash: "0xabc",
|
|
@@ -424,7 +424,7 @@ describe("Aptos sync logic ", () => {
|
|
|
424
424
|
expect(result[0]).toEqual({
|
|
425
425
|
id: expect.any(String),
|
|
426
426
|
hash: "0x0189",
|
|
427
|
-
type:
|
|
427
|
+
type: OP_TYPE.OUT,
|
|
428
428
|
value: new BigNumber(20000),
|
|
429
429
|
fee: new BigNumber(20000),
|
|
430
430
|
blockHash: "0xc496",
|
|
@@ -722,7 +722,7 @@ describe("Aptos sync logic ", () => {
|
|
|
722
722
|
expect(tokenOps[0]).toEqual({
|
|
723
723
|
id: expect.any(String),
|
|
724
724
|
hash: "0x123",
|
|
725
|
-
type:
|
|
725
|
+
type: OP_TYPE.OUT,
|
|
726
726
|
value: new BigNumber(1500000),
|
|
727
727
|
fee: new BigNumber(20000),
|
|
728
728
|
blockHash: "0xabc",
|
|
@@ -1018,7 +1018,7 @@ describe("Aptos sync logic ", () => {
|
|
|
1018
1018
|
id: expect.any(String),
|
|
1019
1019
|
accountId: "token_account_id",
|
|
1020
1020
|
hash: "0x10c9",
|
|
1021
|
-
type:
|
|
1021
|
+
type: OP_TYPE.IN,
|
|
1022
1022
|
value: new BigNumber(193),
|
|
1023
1023
|
fee: new BigNumber(20000),
|
|
1024
1024
|
blockHash: "0xabc",
|
|
@@ -3,8 +3,7 @@ import { AptosAPI } from "../../network";
|
|
|
3
3
|
import { getEstimatedGas } from "../../bridge/getFeesForTransaction";
|
|
4
4
|
import { getMaxSendBalance } from "../../bridge/logic";
|
|
5
5
|
import BigNumber from "bignumber.js";
|
|
6
|
-
import type {
|
|
7
|
-
import type { Transaction } from "../../types";
|
|
6
|
+
import type { AptosAccount, Transaction } from "../../types";
|
|
8
7
|
|
|
9
8
|
jest.mock("../../network");
|
|
10
9
|
jest.mock("../../bridge/getFeesForTransaction");
|
|
@@ -12,7 +11,7 @@ jest.mock("../../bridge/logic");
|
|
|
12
11
|
|
|
13
12
|
describe("Aptos prepareTransaction", () => {
|
|
14
13
|
describe("prepareTransaction", () => {
|
|
15
|
-
let account:
|
|
14
|
+
let account: AptosAccount;
|
|
16
15
|
let transaction: Transaction;
|
|
17
16
|
|
|
18
17
|
beforeEach(() => {
|
|
@@ -33,13 +32,14 @@ describe("Aptos prepareTransaction", () => {
|
|
|
33
32
|
unit: { code: "APT", name: "Aptos", magnitude: 6 },
|
|
34
33
|
lastSyncDate: new Date(),
|
|
35
34
|
subAccounts: [],
|
|
36
|
-
} as unknown as
|
|
35
|
+
} as unknown as AptosAccount;
|
|
37
36
|
|
|
38
37
|
transaction = {
|
|
39
38
|
amount: new BigNumber(0),
|
|
40
39
|
recipient: "",
|
|
41
40
|
useAllAmount: false,
|
|
42
41
|
fees: new BigNumber(0),
|
|
42
|
+
mode: "send",
|
|
43
43
|
} as Transaction;
|
|
44
44
|
});
|
|
45
45
|
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import {
|
|
3
|
+
assignFromAccountRaw,
|
|
4
|
+
assignToAccountRaw,
|
|
5
|
+
fromAptosResourcesRaw,
|
|
6
|
+
toAptosResourcesRaw,
|
|
7
|
+
} from "../../bridge/serialization";
|
|
8
|
+
import { createFixtureAccount } from "../../bridge/bridge.fixture";
|
|
9
|
+
import { AccountRaw } from "@ledgerhq/types-live";
|
|
10
|
+
import { AptosAccountRaw } from "../../types";
|
|
11
|
+
|
|
12
|
+
describe("serialization", () => {
|
|
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 aptosResources = {
|
|
35
|
+
activeBalance: BigNumber(9834759839345),
|
|
36
|
+
inactiveBalance: BigNumber(789346249),
|
|
37
|
+
pendingInactiveBalance: BigNumber(0),
|
|
38
|
+
stakingPositions,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const aptosResourcesRaw = {
|
|
42
|
+
activeBalance: "9834759839345",
|
|
43
|
+
pendingInactiveBalance: "0",
|
|
44
|
+
inactiveBalance: "789346249",
|
|
45
|
+
stakingPositions: [
|
|
46
|
+
{
|
|
47
|
+
active: "123456789",
|
|
48
|
+
pendingInactive: "5345",
|
|
49
|
+
inactive: "567567567",
|
|
50
|
+
validatorId: "validator-1",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
active: "0",
|
|
54
|
+
pendingInactive: "67868678",
|
|
55
|
+
inactive: "33333",
|
|
56
|
+
validatorId: "validator-2",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
active: "45864986459",
|
|
60
|
+
pendingInactive: "0",
|
|
61
|
+
inactive: "0",
|
|
62
|
+
validatorId: "validator-3",
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const account = createFixtureAccount({ aptosResources });
|
|
68
|
+
|
|
69
|
+
const accountRaw = {
|
|
70
|
+
id: "1",
|
|
71
|
+
seedIdentifier: "seedIdentifier",
|
|
72
|
+
derivationMode: "",
|
|
73
|
+
index: 1,
|
|
74
|
+
freshAddress: "freshAddress",
|
|
75
|
+
freshAddressPath: "freshAddressPath",
|
|
76
|
+
balance: "1234",
|
|
77
|
+
blockHeight: 1,
|
|
78
|
+
currencyId: "aptos",
|
|
79
|
+
operations: [],
|
|
80
|
+
pendingOperations: [],
|
|
81
|
+
lastSyncDate: "",
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
it("toAptosResourcesRaw", () => {
|
|
85
|
+
expect(toAptosResourcesRaw(aptosResources)).toMatchObject(aptosResourcesRaw);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("fromAptosResourcesRaw", () => {
|
|
89
|
+
expect(fromAptosResourcesRaw(aptosResourcesRaw)).toMatchObject(aptosResources);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("assignToAccountRaw", () => {
|
|
93
|
+
assignToAccountRaw(account, accountRaw as AccountRaw);
|
|
94
|
+
expect((accountRaw as unknown as AptosAccountRaw).aptosResources).toMatchObject(
|
|
95
|
+
aptosResourcesRaw,
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("assignFromAccountRaw", () => {
|
|
100
|
+
assignFromAccountRaw(accountRaw as AccountRaw, account);
|
|
101
|
+
expect((account as unknown as AptosAccountRaw).aptosResources).toMatchObject(aptosResources);
|
|
102
|
+
});
|
|
103
|
+
});
|