@ledgerhq/coin-tezos 6.6.0-nightly.1 → 6.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +30 -4
- package/CHANGELOG.md +17 -8
- package/jest.integ.config.js +0 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +40 -188
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +10 -79
- package/lib/api/index.test.js.map +1 -1
- package/lib/api/types.d.ts +5 -7
- package/lib/api/types.d.ts.map +1 -1
- package/lib/bridge/broadcast.d.ts +4 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +11 -0
- package/lib/bridge/broadcast.js.map +1 -0
- package/lib/bridge/broadcast.test.d.ts +2 -0
- package/lib/bridge/broadcast.test.d.ts.map +1 -0
- package/lib/bridge/broadcast.test.js +36 -0
- package/lib/bridge/broadcast.test.js.map +1 -0
- package/lib/bridge/buildOptimisticOperation.d.ts +4 -0
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib/bridge/buildOptimisticOperation.js +28 -0
- package/lib/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib/bridge/createTransaction.d.ts +4 -0
- package/lib/bridge/createTransaction.d.ts.map +1 -0
- package/lib/bridge/createTransaction.js +24 -0
- package/lib/bridge/createTransaction.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.d.ts +5 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.js +30 -0
- package/lib/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib/bridge/getFeesForTransaction.d.ts +21 -0
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -0
- package/lib/bridge/getFeesForTransaction.js +39 -0
- package/lib/bridge/getFeesForTransaction.js.map +1 -0
- package/lib/bridge/getTransactionStatus.d.ts +4 -0
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.js +108 -0
- package/lib/bridge/getTransactionStatus.js.map +1 -0
- package/lib/bridge/getTransactionStatus.test.d.ts +2 -0
- package/lib/bridge/getTransactionStatus.test.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.test.js +107 -0
- package/lib/bridge/getTransactionStatus.test.js.map +1 -0
- package/lib/bridge/index.d.ts +10 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +59 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge/logic.d.ts +10 -0
- package/lib/bridge/logic.d.ts.map +1 -0
- package/lib/bridge/logic.js +155 -0
- package/lib/bridge/logic.js.map +1 -0
- package/lib/bridge/preload.d.ts +9 -0
- package/lib/bridge/preload.d.ts.map +1 -0
- package/lib/bridge/preload.js +23 -0
- package/lib/bridge/preload.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts +5 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.integ.test.d.ts +2 -0
- package/lib/bridge/prepareTransaction.integ.test.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.integ.test.js +34 -0
- package/lib/bridge/prepareTransaction.integ.test.js.map +1 -0
- package/lib/bridge/prepareTransaction.js +57 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/prepareTransaction.test.d.ts +2 -0
- package/lib/bridge/prepareTransaction.test.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.test.js +178 -0
- package/lib/bridge/prepareTransaction.test.js.map +1 -0
- package/lib/bridge/serialization.d.ts +7 -0
- package/lib/bridge/serialization.d.ts.map +1 -0
- package/lib/bridge/serialization.js +26 -0
- package/lib/bridge/serialization.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +16 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +88 -0
- package/lib/bridge/signOperation.js.map +1 -0
- package/lib/bridge/signOperation.test.d.ts +2 -0
- package/lib/bridge/signOperation.test.d.ts.map +1 -0
- package/lib/bridge/signOperation.test.js +283 -0
- package/lib/bridge/signOperation.test.js.map +1 -0
- package/lib/bridge/synchronization.d.ts +5 -0
- package/lib/bridge/synchronization.d.ts.map +1 -0
- package/lib/bridge/synchronization.integ.test.d.ts +2 -0
- package/lib/bridge/synchronization.integ.test.d.ts.map +1 -0
- package/lib/bridge/synchronization.integ.test.js +32 -0
- package/lib/bridge/synchronization.integ.test.js.map +1 -0
- package/lib/bridge/synchronization.js +100 -0
- package/lib/bridge/synchronization.js.map +1 -0
- package/lib/{transaction.d.ts → bridge/transaction.d.ts} +1 -1
- package/lib/bridge/transaction.d.ts.map +1 -0
- package/lib/{transaction.js → bridge/transaction.js} +3 -3
- package/lib/bridge/transaction.js.map +1 -0
- package/lib/config.d.ts +3 -4
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +0 -7
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/craftTransaction.test.js +0 -1
- package/lib/logic/craftTransaction.test.js.map +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.integ.test.js +2 -8
- package/lib/logic/estimateFees.integ.test.js.map +1 -1
- package/lib/logic/estimateFees.js +45 -119
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.js +1 -1
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/index.d.ts +0 -2
- package/lib/logic/index.d.ts.map +1 -1
- package/lib/logic/index.js +1 -5
- package/lib/logic/index.js.map +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +10 -56
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/listOperations.test.js +10 -14
- package/lib/logic/listOperations.test.js.map +1 -1
- package/lib/types/bridge.d.ts +0 -3
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib/types/bridge.fixture.d.ts.map +1 -1
- package/lib/types/bridge.fixture.js +0 -1
- package/lib/types/bridge.fixture.js.map +1 -1
- package/lib/types/bridge.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +41 -189
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +10 -79
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/api/types.d.ts +5 -7
- package/lib-es/api/types.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.d.ts +4 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.js +7 -0
- package/lib-es/bridge/broadcast.js.map +1 -0
- package/lib-es/bridge/broadcast.test.d.ts +2 -0
- package/lib-es/bridge/broadcast.test.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.test.js +31 -0
- package/lib-es/bridge/broadcast.test.js.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts +4 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.js +21 -0
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib-es/bridge/createTransaction.d.ts +4 -0
- package/lib-es/bridge/createTransaction.d.ts.map +1 -0
- package/lib-es/bridge/createTransaction.js +17 -0
- package/lib-es/bridge/createTransaction.js.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts +5 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.js +23 -0
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib-es/bridge/getFeesForTransaction.d.ts +21 -0
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -0
- package/lib-es/bridge/getFeesForTransaction.js +33 -0
- package/lib-es/bridge/getFeesForTransaction.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.js +101 -0
- package/lib-es/bridge/getTransactionStatus.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.test.d.ts +2 -0
- package/lib-es/bridge/getTransactionStatus.test.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.test.js +102 -0
- package/lib-es/bridge/getTransactionStatus.test.js.map +1 -0
- package/lib-es/bridge/index.d.ts +10 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +53 -0
- package/lib-es/bridge/index.js.map +1 -0
- package/lib-es/bridge/logic.d.ts +10 -0
- package/lib-es/bridge/logic.d.ts.map +1 -0
- package/lib-es/bridge/logic.js +145 -0
- package/lib-es/bridge/logic.js.map +1 -0
- package/lib-es/bridge/preload.d.ts +9 -0
- package/lib-es/bridge/preload.d.ts.map +1 -0
- package/lib-es/bridge/preload.js +17 -0
- package/lib-es/bridge/preload.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts +5 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.integ.test.d.ts +2 -0
- package/lib-es/bridge/prepareTransaction.integ.test.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.integ.test.js +29 -0
- package/lib-es/bridge/prepareTransaction.integ.test.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.js +50 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.test.d.ts +2 -0
- package/lib-es/bridge/prepareTransaction.test.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.test.js +173 -0
- package/lib-es/bridge/prepareTransaction.test.js.map +1 -0
- 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 +20 -0
- package/lib-es/bridge/serialization.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +16 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +83 -0
- package/lib-es/bridge/signOperation.js.map +1 -0
- package/lib-es/bridge/signOperation.test.d.ts +2 -0
- package/lib-es/bridge/signOperation.test.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.test.js +255 -0
- package/lib-es/bridge/signOperation.test.js.map +1 -0
- package/lib-es/bridge/synchronization.d.ts +5 -0
- package/lib-es/bridge/synchronization.d.ts.map +1 -0
- package/lib-es/bridge/synchronization.integ.test.d.ts +2 -0
- package/lib-es/bridge/synchronization.integ.test.d.ts.map +1 -0
- package/lib-es/bridge/synchronization.integ.test.js +27 -0
- package/lib-es/bridge/synchronization.integ.test.js.map +1 -0
- package/lib-es/bridge/synchronization.js +70 -0
- package/lib-es/bridge/synchronization.js.map +1 -0
- package/lib-es/{transaction.d.ts → bridge/transaction.d.ts} +1 -1
- package/lib-es/bridge/transaction.d.ts.map +1 -0
- package/lib-es/{transaction.js → bridge/transaction.js} +3 -3
- package/lib-es/bridge/transaction.js.map +1 -0
- package/lib-es/config.d.ts +3 -4
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/index.d.ts +1 -1
- package/lib-es/index.d.ts.map +1 -1
- package/lib-es/index.js +1 -1
- package/lib-es/index.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +0 -7
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/craftTransaction.test.js +0 -1
- package/lib-es/logic/craftTransaction.test.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.integ.test.js +2 -8
- package/lib-es/logic/estimateFees.integ.test.js.map +1 -1
- package/lib-es/logic/estimateFees.js +45 -119
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.js +1 -1
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/index.d.ts +0 -2
- package/lib-es/logic/index.d.ts.map +1 -1
- package/lib-es/logic/index.js +0 -2
- package/lib-es/logic/index.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +10 -56
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/listOperations.test.js +10 -14
- package/lib-es/logic/listOperations.test.js.map +1 -1
- package/lib-es/types/bridge.d.ts +0 -3
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/lib-es/types/bridge.fixture.d.ts.map +1 -1
- package/lib-es/types/bridge.fixture.js +0 -1
- package/lib-es/types/bridge.fixture.js.map +1 -1
- package/lib-es/types/bridge.js.map +1 -1
- package/package.json +14 -11
- package/src/api/index.test.ts +15 -87
- package/src/api/index.ts +55 -204
- package/src/api/types.ts +6 -11
- package/src/bridge/broadcast.test.ts +36 -0
- package/src/bridge/broadcast.ts +13 -0
- package/src/bridge/buildOptimisticOperation.ts +28 -0
- package/src/bridge/createTransaction.ts +19 -0
- package/src/bridge/estimateMaxSpendable.ts +37 -0
- package/src/bridge/getFeesForTransaction.ts +49 -0
- package/src/bridge/getTransactionStatus.test.ts +124 -0
- package/src/bridge/getTransactionStatus.ts +123 -0
- package/src/bridge/index.ts +74 -0
- package/src/bridge/logic.ts +171 -0
- package/src/bridge/preload.ts +18 -0
- package/src/bridge/prepareTransaction.integ.test.ts +35 -0
- package/src/bridge/prepareTransaction.test.ts +205 -0
- package/src/bridge/prepareTransaction.ts +69 -0
- package/src/bridge/serialization.ts +27 -0
- package/src/bridge/signOperation.test.ts +284 -0
- package/src/bridge/signOperation.ts +130 -0
- package/src/bridge/synchronization.integ.test.ts +33 -0
- package/src/bridge/synchronization.ts +100 -0
- package/src/{transaction.ts → bridge/transaction.ts} +4 -4
- package/src/config.ts +2 -9
- package/src/index.ts +2 -1
- package/src/logic/craftTransaction.test.ts +0 -1
- package/src/logic/craftTransaction.ts +0 -8
- package/src/logic/estimateFees.integ.test.ts +2 -8
- package/src/logic/estimateFees.ts +49 -140
- package/src/logic/getBalance.ts +1 -1
- package/src/logic/index.ts +0 -2
- package/src/logic/listOperations.test.ts +54 -64
- package/src/logic/listOperations.ts +9 -57
- package/src/types/bridge.fixture.ts +0 -1
- package/src/types/bridge.ts +1 -6
- package/lib/logic/getStakes.d.ts +0 -3
- package/lib/logic/getStakes.d.ts.map +0 -1
- package/lib/logic/getStakes.js +0 -26
- package/lib/logic/getStakes.js.map +0 -1
- package/lib/logic/getStakes.test.d.ts +0 -2
- package/lib/logic/getStakes.test.d.ts.map +0 -1
- package/lib/logic/getStakes.test.js +0 -133
- package/lib/logic/getStakes.test.js.map +0 -1
- package/lib/logic/validateIntent.d.ts +0 -3
- package/lib/logic/validateIntent.d.ts.map +0 -1
- package/lib/logic/validateIntent.js +0 -179
- package/lib/logic/validateIntent.js.map +0 -1
- package/lib/logic/validateIntent.test.d.ts +0 -2
- package/lib/logic/validateIntent.test.d.ts.map +0 -1
- package/lib/logic/validateIntent.test.js +0 -249
- package/lib/logic/validateIntent.test.js.map +0 -1
- package/lib/transaction.d.ts.map +0 -1
- package/lib/transaction.js.map +0 -1
- package/lib/utils.d.ts +0 -48
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js +0 -112
- package/lib/utils.js.map +0 -1
- package/lib-es/logic/getStakes.d.ts +0 -3
- package/lib-es/logic/getStakes.d.ts.map +0 -1
- package/lib-es/logic/getStakes.js +0 -20
- package/lib-es/logic/getStakes.js.map +0 -1
- package/lib-es/logic/getStakes.test.d.ts +0 -2
- package/lib-es/logic/getStakes.test.d.ts.map +0 -1
- package/lib-es/logic/getStakes.test.js +0 -128
- package/lib-es/logic/getStakes.test.js.map +0 -1
- package/lib-es/logic/validateIntent.d.ts +0 -3
- package/lib-es/logic/validateIntent.d.ts.map +0 -1
- package/lib-es/logic/validateIntent.js +0 -173
- package/lib-es/logic/validateIntent.js.map +0 -1
- package/lib-es/logic/validateIntent.test.d.ts +0 -2
- package/lib-es/logic/validateIntent.test.d.ts.map +0 -1
- package/lib-es/logic/validateIntent.test.js +0 -221
- package/lib-es/logic/validateIntent.test.js.map +0 -1
- package/lib-es/transaction.d.ts.map +0 -1
- package/lib-es/transaction.js.map +0 -1
- package/lib-es/utils.d.ts +0 -48
- package/lib-es/utils.d.ts.map +0 -1
- package/lib-es/utils.js +0 -105
- package/lib-es/utils.js.map +0 -1
- package/src/logic/getStakes.test.ts +0 -145
- package/src/logic/getStakes.ts +0 -20
- package/src/logic/validateIntent.test.ts +0 -262
- package/src/logic/validateIntent.ts +0 -207
- package/src/utils.ts +0 -115
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { createApi } from "../api/index";
|
|
2
|
-
import tzktApi from "../network/tzkt";
|
|
3
|
-
import coinConfig from "../config";
|
|
4
|
-
|
|
5
|
-
describe("getStakes", () => {
|
|
6
|
-
const api = createApi({
|
|
7
|
-
baker: { url: "http://baker.example.com" },
|
|
8
|
-
explorer: { url: "http://tezos.explorer.com", maxTxQuery: 100 },
|
|
9
|
-
node: { url: "http://tezos.node.com" },
|
|
10
|
-
fees: {
|
|
11
|
-
minGasLimit: 600,
|
|
12
|
-
minRevealGasLimit: 300,
|
|
13
|
-
minStorageLimit: 0,
|
|
14
|
-
minFees: 500,
|
|
15
|
-
minEstimatedFees: 500,
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const mockGetAccountByAddress = jest.spyOn(tzktApi, "getAccountByAddress");
|
|
20
|
-
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
jest.clearAllMocks();
|
|
23
|
-
|
|
24
|
-
coinConfig.setCoinConfig(() => ({
|
|
25
|
-
status: { type: "active" },
|
|
26
|
-
baker: { url: "http://baker.example.com" },
|
|
27
|
-
explorer: { url: "http://tezos.explorer.com", maxTxQuery: 100 },
|
|
28
|
-
node: { url: "http://tezos.node.com" },
|
|
29
|
-
fees: {
|
|
30
|
-
minGasLimit: 600,
|
|
31
|
-
minRevealGasLimit: 300,
|
|
32
|
-
minStorageLimit: 0,
|
|
33
|
-
minFees: 500,
|
|
34
|
-
minEstimatedFees: 500,
|
|
35
|
-
},
|
|
36
|
-
}));
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe("account types", () => {
|
|
40
|
-
it("should return empty stakes for non-delegated account", async () => {
|
|
41
|
-
mockGetAccountByAddress.mockResolvedValue({
|
|
42
|
-
type: "user",
|
|
43
|
-
address: "tz1WvvbEGpBXGeTVbLiR6DYBe1izmgiYuZbq",
|
|
44
|
-
publicKey: "edpk...",
|
|
45
|
-
balance: 1000000,
|
|
46
|
-
revealed: true,
|
|
47
|
-
counter: 0,
|
|
48
|
-
delegationLevel: 0,
|
|
49
|
-
delegationTime: "2021-01-01T00:00:00Z",
|
|
50
|
-
numTransactions: 0,
|
|
51
|
-
firstActivityTime: "2021-01-01T00:00:00Z",
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const result = await api.getStakes("tz1WvvbEGpBXGeTVbLiR6DYBe1izmgiYuZbq");
|
|
55
|
-
|
|
56
|
-
expect(result.items).toEqual([]);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("should return empty stakes for non user account", async () => {
|
|
60
|
-
mockGetAccountByAddress.mockResolvedValue({
|
|
61
|
-
type: "empty",
|
|
62
|
-
address: "tz1EmptyAccount",
|
|
63
|
-
counter: 0,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const result = await api.getStakes("tz1EmptyAccount");
|
|
67
|
-
|
|
68
|
-
expect(result.items).toEqual([]);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe("delegated accounts", () => {
|
|
73
|
-
it("should return stake for delegated account", async () => {
|
|
74
|
-
const address = "tz1TzrmTBSuiVHV2VfMnGRMYvTEPCP42oSM8";
|
|
75
|
-
const delegateAddress = "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx";
|
|
76
|
-
const balance = 5000000;
|
|
77
|
-
|
|
78
|
-
mockGetAccountByAddress.mockResolvedValue({
|
|
79
|
-
type: "user",
|
|
80
|
-
address,
|
|
81
|
-
publicKey: "edpk...",
|
|
82
|
-
balance,
|
|
83
|
-
revealed: true,
|
|
84
|
-
counter: 0,
|
|
85
|
-
delegate: {
|
|
86
|
-
alias: "Test Delegate",
|
|
87
|
-
address: delegateAddress,
|
|
88
|
-
active: true,
|
|
89
|
-
},
|
|
90
|
-
delegationLevel: 100,
|
|
91
|
-
delegationTime: "2021-01-01T00:00:00Z",
|
|
92
|
-
numTransactions: 10,
|
|
93
|
-
firstActivityTime: "2021-01-01T00:00:00Z",
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const result = await api.getStakes(address);
|
|
97
|
-
|
|
98
|
-
expect(result.items).toEqual([
|
|
99
|
-
expect.objectContaining({
|
|
100
|
-
uid: address,
|
|
101
|
-
address,
|
|
102
|
-
delegate: delegateAddress,
|
|
103
|
-
state: "active",
|
|
104
|
-
asset: { type: "native" },
|
|
105
|
-
amount: BigInt(balance),
|
|
106
|
-
}),
|
|
107
|
-
]);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it("should handle account with zero balance but delegation", async () => {
|
|
111
|
-
const address = "tz1ZeroBalanceAccount";
|
|
112
|
-
const delegateAddress = "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx";
|
|
113
|
-
|
|
114
|
-
mockGetAccountByAddress.mockResolvedValue({
|
|
115
|
-
type: "user",
|
|
116
|
-
address,
|
|
117
|
-
publicKey: "edpk...",
|
|
118
|
-
balance: 0,
|
|
119
|
-
revealed: true,
|
|
120
|
-
counter: 0,
|
|
121
|
-
delegate: {
|
|
122
|
-
alias: "Test Delegate",
|
|
123
|
-
address: delegateAddress,
|
|
124
|
-
active: true,
|
|
125
|
-
},
|
|
126
|
-
delegationLevel: 100,
|
|
127
|
-
delegationTime: "2021-01-01T00:00:00Z",
|
|
128
|
-
numTransactions: 0,
|
|
129
|
-
firstActivityTime: "2021-01-01T00:00:00Z",
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
const result = await api.getStakes(address);
|
|
133
|
-
|
|
134
|
-
expect(result.items).toHaveLength(1);
|
|
135
|
-
expect(result.items[0]).toMatchObject({
|
|
136
|
-
uid: address,
|
|
137
|
-
address,
|
|
138
|
-
delegate: delegateAddress,
|
|
139
|
-
state: "active",
|
|
140
|
-
asset: { type: "native" },
|
|
141
|
-
amount: BigInt(0),
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
});
|
package/src/logic/getStakes.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Cursor, Page, Stake } from "@ledgerhq/coin-framework/api/types";
|
|
2
|
-
import api from "../network/tzkt";
|
|
3
|
-
|
|
4
|
-
export async function getStakes(address: string, _cursor?: Cursor): Promise<Page<Stake>> {
|
|
5
|
-
// tezos exposes a single staking position via delegation when a delegate is set
|
|
6
|
-
const accountInfo = await api.getAccountByAddress(address);
|
|
7
|
-
if (accountInfo.type !== "user" || !accountInfo.delegate?.address) return { items: [] };
|
|
8
|
-
return {
|
|
9
|
-
items: [
|
|
10
|
-
{
|
|
11
|
-
uid: address,
|
|
12
|
-
address,
|
|
13
|
-
delegate: accountInfo.delegate.address,
|
|
14
|
-
state: "active",
|
|
15
|
-
asset: { type: "native" },
|
|
16
|
-
amount: BigInt(accountInfo.balance ?? 0),
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
};
|
|
20
|
-
}
|
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
import { validateIntent } from "./validateIntent";
|
|
2
|
-
import * as estimateFeesModule from "./estimateFees";
|
|
3
|
-
import tzktApi from "../network/tzkt";
|
|
4
|
-
import coinConfig from "../config";
|
|
5
|
-
import {
|
|
6
|
-
RecipientRequired,
|
|
7
|
-
InvalidAddress,
|
|
8
|
-
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
9
|
-
AmountRequired,
|
|
10
|
-
NotEnoughBalance,
|
|
11
|
-
} from "@ledgerhq/errors";
|
|
12
|
-
|
|
13
|
-
describe("validateIntent", () => {
|
|
14
|
-
const senderAddress = "tz1TzrmTBSuiVHV2VfMnGRMYvTEPCP42oSM8";
|
|
15
|
-
const validRecipient = "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx";
|
|
16
|
-
|
|
17
|
-
const mockEstimateFees = jest.spyOn(estimateFeesModule, "estimateFees");
|
|
18
|
-
const mockGetAccountByAddress = jest.spyOn(tzktApi, "getAccountByAddress");
|
|
19
|
-
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
jest.clearAllMocks();
|
|
22
|
-
|
|
23
|
-
coinConfig.setCoinConfig(() => ({
|
|
24
|
-
status: { type: "active" },
|
|
25
|
-
baker: { url: "http://baker.example.com" },
|
|
26
|
-
explorer: { url: "http://tezos.explorer.com", maxTxQuery: 100 },
|
|
27
|
-
node: { url: "http://tezos.node.com" },
|
|
28
|
-
fees: {
|
|
29
|
-
minGasLimit: 600,
|
|
30
|
-
minRevealGasLimit: 300,
|
|
31
|
-
minStorageLimit: 0,
|
|
32
|
-
minFees: 500,
|
|
33
|
-
minEstimatedFees: 500,
|
|
34
|
-
},
|
|
35
|
-
}));
|
|
36
|
-
|
|
37
|
-
mockEstimateFees.mockResolvedValue({
|
|
38
|
-
fees: BigInt(1000),
|
|
39
|
-
gasLimit: BigInt(10000),
|
|
40
|
-
storageLimit: BigInt(0),
|
|
41
|
-
estimatedFees: BigInt(1000),
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
mockGetAccountByAddress.mockResolvedValue({
|
|
45
|
-
type: "user",
|
|
46
|
-
address: senderAddress,
|
|
47
|
-
publicKey: "edpk...",
|
|
48
|
-
balance: 5000000,
|
|
49
|
-
revealed: true,
|
|
50
|
-
counter: 0,
|
|
51
|
-
delegationLevel: 0,
|
|
52
|
-
delegationTime: "2021-01-01T00:00:00Z",
|
|
53
|
-
numTransactions: 0,
|
|
54
|
-
firstActivityTime: "2021-01-01T00:00:00Z",
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe("recipient validation", () => {
|
|
59
|
-
it("should return RecipientRequired error when recipient is missing", async () => {
|
|
60
|
-
const result = await validateIntent({
|
|
61
|
-
asset: { type: "native" },
|
|
62
|
-
type: "send",
|
|
63
|
-
sender: senderAddress,
|
|
64
|
-
recipient: "",
|
|
65
|
-
amount: BigInt(1000),
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
expect(result.errors.recipient).toBeInstanceOf(RecipientRequired);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("should return InvalidAddress error for invalid recipient", async () => {
|
|
72
|
-
const result = await validateIntent({
|
|
73
|
-
asset: { type: "native" },
|
|
74
|
-
type: "send",
|
|
75
|
-
sender: senderAddress,
|
|
76
|
-
recipient: "invalid_address",
|
|
77
|
-
amount: BigInt(1000),
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
expect(result.errors.recipient).toBeInstanceOf(InvalidAddress);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("should return InvalidAddressBecauseDestinationIsAlsoSource when sender equals recipient", async () => {
|
|
84
|
-
const result = await validateIntent({
|
|
85
|
-
asset: { type: "native" },
|
|
86
|
-
type: "send",
|
|
87
|
-
sender: senderAddress,
|
|
88
|
-
recipient: senderAddress,
|
|
89
|
-
amount: BigInt(1000),
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
expect(result.errors.recipient).toBeInstanceOf(InvalidAddressBecauseDestinationIsAlsoSource);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe("amount validation", () => {
|
|
97
|
-
it("should return AmountRequired error when amount is zero and not useAllAmount", async () => {
|
|
98
|
-
const result = await validateIntent({
|
|
99
|
-
asset: { type: "native" },
|
|
100
|
-
type: "send",
|
|
101
|
-
sender: senderAddress,
|
|
102
|
-
recipient: validRecipient,
|
|
103
|
-
amount: BigInt(0),
|
|
104
|
-
useAllAmount: false,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
expect(result.errors.amount).toBeInstanceOf(AmountRequired);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it("should not return AmountRequired error when useAllAmount is true", async () => {
|
|
111
|
-
const result = await validateIntent({
|
|
112
|
-
asset: { type: "native" },
|
|
113
|
-
type: "send",
|
|
114
|
-
sender: senderAddress,
|
|
115
|
-
recipient: validRecipient,
|
|
116
|
-
amount: BigInt(0),
|
|
117
|
-
useAllAmount: true,
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
expect(result.errors.amount).toBeUndefined();
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
describe("balance validation", () => {
|
|
125
|
-
it("should return NotEnoughBalance error when amount exceeds balance", async () => {
|
|
126
|
-
const balance = 1000000; // 1 XTZ
|
|
127
|
-
const amount = 2000000; // 2 XTZ
|
|
128
|
-
|
|
129
|
-
mockGetAccountByAddress.mockResolvedValue({
|
|
130
|
-
type: "user",
|
|
131
|
-
address: senderAddress,
|
|
132
|
-
publicKey: "edpk...",
|
|
133
|
-
balance,
|
|
134
|
-
revealed: true,
|
|
135
|
-
counter: 0,
|
|
136
|
-
delegationLevel: 0,
|
|
137
|
-
delegationTime: "2021-01-01T00:00:00Z",
|
|
138
|
-
numTransactions: 0,
|
|
139
|
-
firstActivityTime: "2021-01-01T00:00:00Z",
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
const result = await validateIntent({
|
|
143
|
-
asset: { type: "native" },
|
|
144
|
-
type: "send",
|
|
145
|
-
sender: senderAddress,
|
|
146
|
-
recipient: validRecipient,
|
|
147
|
-
amount: BigInt(amount),
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
expect(result.errors.amount).toBeInstanceOf(NotEnoughBalance);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("should pass validation when amount is within balance", async () => {
|
|
154
|
-
const balance = 5000000; // 5 XTZ
|
|
155
|
-
const amount = 1000000; // 1 XTZ
|
|
156
|
-
|
|
157
|
-
mockGetAccountByAddress.mockResolvedValue({
|
|
158
|
-
type: "user",
|
|
159
|
-
address: senderAddress,
|
|
160
|
-
publicKey: "edpk...",
|
|
161
|
-
balance,
|
|
162
|
-
revealed: true,
|
|
163
|
-
counter: 0,
|
|
164
|
-
delegationLevel: 0,
|
|
165
|
-
delegationTime: "2021-01-01T00:00:00Z",
|
|
166
|
-
numTransactions: 0,
|
|
167
|
-
firstActivityTime: "2021-01-01T00:00:00Z",
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
const result = await validateIntent({
|
|
171
|
-
asset: { type: "native" },
|
|
172
|
-
type: "send",
|
|
173
|
-
sender: senderAddress,
|
|
174
|
-
recipient: validRecipient,
|
|
175
|
-
amount: BigInt(amount),
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
expect(result.errors.amount).toBeUndefined();
|
|
179
|
-
expect(result.amount).toBe(BigInt(amount));
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
describe("transaction types", () => {
|
|
184
|
-
it("should pass validation for delegate transaction", async () => {
|
|
185
|
-
const result = await validateIntent({
|
|
186
|
-
asset: { type: "native" },
|
|
187
|
-
type: "delegate",
|
|
188
|
-
sender: senderAddress,
|
|
189
|
-
recipient: validRecipient,
|
|
190
|
-
amount: BigInt(0),
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
expect(result.errors).toEqual({});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it("should pass validation for undelegate transaction", async () => {
|
|
197
|
-
const result = await validateIntent({
|
|
198
|
-
asset: { type: "native" },
|
|
199
|
-
type: "undelegate",
|
|
200
|
-
sender: senderAddress,
|
|
201
|
-
recipient: "",
|
|
202
|
-
amount: BigInt(0),
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
expect(result.errors).toEqual({});
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it("should handle stake intent (mapped to delegate)", async () => {
|
|
209
|
-
const result = await validateIntent({
|
|
210
|
-
asset: { type: "native" },
|
|
211
|
-
type: "stake",
|
|
212
|
-
sender: senderAddress,
|
|
213
|
-
recipient: validRecipient,
|
|
214
|
-
amount: BigInt(0),
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
expect(result.errors).toEqual({});
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it("should handle unstake intent (mapped to undelegate)", async () => {
|
|
221
|
-
const result = await validateIntent({
|
|
222
|
-
asset: { type: "native" },
|
|
223
|
-
type: "unstake",
|
|
224
|
-
sender: senderAddress,
|
|
225
|
-
recipient: "",
|
|
226
|
-
amount: BigInt(0),
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
expect(result.errors).toEqual({});
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
describe("successful validation", () => {
|
|
234
|
-
it("should return valid result with correct values", async () => {
|
|
235
|
-
const amount = BigInt(1000000);
|
|
236
|
-
const estimatedFees = BigInt(1500);
|
|
237
|
-
|
|
238
|
-
mockEstimateFees.mockResolvedValue({
|
|
239
|
-
fees: BigInt(1000),
|
|
240
|
-
gasLimit: BigInt(10000),
|
|
241
|
-
storageLimit: BigInt(0),
|
|
242
|
-
estimatedFees,
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
const result = await validateIntent({
|
|
246
|
-
asset: { type: "native" },
|
|
247
|
-
type: "send",
|
|
248
|
-
sender: senderAddress,
|
|
249
|
-
recipient: validRecipient,
|
|
250
|
-
amount,
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
expect(result).toMatchObject({
|
|
254
|
-
errors: {},
|
|
255
|
-
warnings: {},
|
|
256
|
-
estimatedFees,
|
|
257
|
-
amount,
|
|
258
|
-
totalSpent: amount + estimatedFees,
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
});
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import type { TransactionIntent, TransactionValidation } from "@ledgerhq/coin-framework/api/types";
|
|
2
|
-
import {
|
|
3
|
-
InvalidAddress,
|
|
4
|
-
RecipientRequired,
|
|
5
|
-
RecommendUndelegation,
|
|
6
|
-
NotEnoughBalance,
|
|
7
|
-
NotEnoughBalanceToDelegate,
|
|
8
|
-
AmountRequired,
|
|
9
|
-
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
10
|
-
} from "@ledgerhq/errors";
|
|
11
|
-
import { validateAddress, ValidationResult } from "@taquito/utils";
|
|
12
|
-
import api from "../network/tzkt";
|
|
13
|
-
import { estimateFees } from "./estimateFees";
|
|
14
|
-
import { InvalidAddressBecauseAlreadyDelegated } from "../types/errors";
|
|
15
|
-
import { mapIntentTypeToTezosMode } from "../utils";
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Validates basic recipient and amount for send transactions
|
|
19
|
-
*/
|
|
20
|
-
function validateBasicSendParams(intent: TransactionIntent): Record<string, Error> {
|
|
21
|
-
const errors: Record<string, Error> = {};
|
|
22
|
-
|
|
23
|
-
if (intent.type !== "send") {
|
|
24
|
-
return errors;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (!intent.recipient) {
|
|
28
|
-
errors.recipient = new RecipientRequired("");
|
|
29
|
-
} else if (validateAddress(intent.recipient) !== ValidationResult.VALID) {
|
|
30
|
-
errors.recipient = new InvalidAddress(undefined, { currencyName: "Tezos" });
|
|
31
|
-
} else if (intent.sender === intent.recipient) {
|
|
32
|
-
errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (intent.amount === 0n && !intent.useAllAmount) {
|
|
36
|
-
errors.amount = new AmountRequired();
|
|
37
|
-
} else if (intent.amount < 0n) {
|
|
38
|
-
errors.amount = new NotEnoughBalance();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return errors;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Validates specific transaction constraints based on account state
|
|
46
|
-
*/
|
|
47
|
-
function validateTransactionConstraints(
|
|
48
|
-
intent: TransactionIntent,
|
|
49
|
-
senderInfo: any,
|
|
50
|
-
): Record<string, Error> {
|
|
51
|
-
const errors: Record<string, Error> = {};
|
|
52
|
-
|
|
53
|
-
// send max not allowed on delegated accounts (must undelegate acc first)
|
|
54
|
-
if (intent.type === "send" && intent.useAllAmount) {
|
|
55
|
-
if (senderInfo.type === "user" && senderInfo.delegate?.address) {
|
|
56
|
-
errors.amount = new RecommendUndelegation();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// stake requires non-zero balance
|
|
61
|
-
if (intent.type === "stake") {
|
|
62
|
-
const balance = BigInt(senderInfo.balance || "0");
|
|
63
|
-
if (balance === 0n) {
|
|
64
|
-
errors.amount = new NotEnoughBalanceToDelegate();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return errors;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Maps Taquito-specific errors to our error types
|
|
73
|
-
*/
|
|
74
|
-
function mapTaquitoErrors(taquitoError: string, intentType: string): Record<string, Error> {
|
|
75
|
-
const errors: Record<string, Error> = {};
|
|
76
|
-
|
|
77
|
-
if (taquitoError.endsWith("balance_too_low") || taquitoError.endsWith("subtraction_underflow")) {
|
|
78
|
-
if (intentType === "stake") {
|
|
79
|
-
errors.amount = new NotEnoughBalanceToDelegate();
|
|
80
|
-
} else {
|
|
81
|
-
errors.amount = new NotEnoughBalance();
|
|
82
|
-
}
|
|
83
|
-
} else if (taquitoError.endsWith("delegate.unchanged") && intentType === "stake") {
|
|
84
|
-
errors.recipient = new InvalidAddressBecauseAlreadyDelegated();
|
|
85
|
-
} else if (taquitoError.includes("empty_implicit_contract")) {
|
|
86
|
-
errors.amount = new NotEnoughBalanceToDelegate();
|
|
87
|
-
} else {
|
|
88
|
-
errors.amount = new Error(taquitoError);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return errors;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Calculates final amounts based on transaction type
|
|
96
|
-
*/
|
|
97
|
-
function calculateAmounts(
|
|
98
|
-
intent: TransactionIntent,
|
|
99
|
-
senderInfo: any,
|
|
100
|
-
estimatedFees: bigint,
|
|
101
|
-
): { amount: bigint; totalSpent: bigint } {
|
|
102
|
-
if (intent.type === "stake" || intent.type === "unstake") {
|
|
103
|
-
const amount = BigInt(senderInfo.type === "user" ? senderInfo.balance : 0);
|
|
104
|
-
return { amount, totalSpent: estimatedFees };
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (intent.type === "send" && intent.useAllAmount) {
|
|
108
|
-
if (senderInfo.type === "user") {
|
|
109
|
-
const balance = BigInt(senderInfo.balance);
|
|
110
|
-
const amount = balance > estimatedFees ? balance - estimatedFees : 0n;
|
|
111
|
-
return { amount, totalSpent: amount + estimatedFees };
|
|
112
|
-
}
|
|
113
|
-
return { amount: 0n, totalSpent: 0n };
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const amount = intent.amount;
|
|
117
|
-
return { amount, totalSpent: amount + estimatedFees };
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Validates balance coverage for the transaction
|
|
122
|
-
*/
|
|
123
|
-
function validateBalanceCoverage(senderInfo: any, totalSpent: bigint): Record<string, Error> {
|
|
124
|
-
const errors: Record<string, Error> = {};
|
|
125
|
-
|
|
126
|
-
if (senderInfo.type === "user") {
|
|
127
|
-
const accountBalance = BigInt(senderInfo.balance);
|
|
128
|
-
if (totalSpent > accountBalance) {
|
|
129
|
-
errors.amount = new NotEnoughBalance();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return errors;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export async function validateIntent(intent: TransactionIntent): Promise<TransactionValidation> {
|
|
137
|
-
const errors: Record<string, Error> = {};
|
|
138
|
-
const warnings: Record<string, Error> = {};
|
|
139
|
-
let estimatedFees: bigint;
|
|
140
|
-
let amount: bigint;
|
|
141
|
-
let totalSpent: bigint;
|
|
142
|
-
|
|
143
|
-
// Basic validation for send transactions
|
|
144
|
-
const basicErrors = validateBasicSendParams(intent);
|
|
145
|
-
Object.assign(errors, basicErrors);
|
|
146
|
-
|
|
147
|
-
if (Object.keys(errors).length > 0) {
|
|
148
|
-
return { errors, warnings, estimatedFees: 0n, amount: 0n, totalSpent: 0n };
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
try {
|
|
152
|
-
// Get sender account information
|
|
153
|
-
const senderInfo = await api.getAccountByAddress(intent.sender);
|
|
154
|
-
if (senderInfo.type !== "user") throw new Error("unexpected account type");
|
|
155
|
-
|
|
156
|
-
// Validate transaction-specific constraints
|
|
157
|
-
const constraintErrors = validateTransactionConstraints(intent, senderInfo);
|
|
158
|
-
Object.assign(errors, constraintErrors);
|
|
159
|
-
|
|
160
|
-
if (Object.keys(errors).length > 0) {
|
|
161
|
-
return { errors, warnings, estimatedFees: 0n, amount: 0n, totalSpent: 0n };
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Estimate fees
|
|
165
|
-
if (senderInfo.revealed) {
|
|
166
|
-
const estimation = await estimateFees({
|
|
167
|
-
account: {
|
|
168
|
-
address: intent.sender,
|
|
169
|
-
revealed: senderInfo.revealed,
|
|
170
|
-
balance: BigInt(senderInfo.balance),
|
|
171
|
-
xpub: intent.senderPublicKey ?? senderInfo.publicKey,
|
|
172
|
-
},
|
|
173
|
-
transaction: {
|
|
174
|
-
mode: mapIntentTypeToTezosMode(intent.type),
|
|
175
|
-
recipient: intent.recipient,
|
|
176
|
-
amount: intent.amount,
|
|
177
|
-
useAllAmount: !!intent.useAllAmount,
|
|
178
|
-
},
|
|
179
|
-
});
|
|
180
|
-
estimatedFees = estimation.estimatedFees;
|
|
181
|
-
|
|
182
|
-
// Handle Taquito errors
|
|
183
|
-
if (estimation.taquitoError) {
|
|
184
|
-
const taquitoErrors = mapTaquitoErrors(estimation.taquitoError, intent.type);
|
|
185
|
-
Object.assign(errors, taquitoErrors);
|
|
186
|
-
}
|
|
187
|
-
} else {
|
|
188
|
-
estimatedFees = 2000n;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// Calculate final amounts
|
|
192
|
-
const amounts = calculateAmounts(intent, senderInfo, estimatedFees);
|
|
193
|
-
amount = amounts.amount;
|
|
194
|
-
totalSpent = amounts.totalSpent;
|
|
195
|
-
|
|
196
|
-
// Final balance validation
|
|
197
|
-
const balanceErrors = validateBalanceCoverage(senderInfo, totalSpent);
|
|
198
|
-
Object.assign(errors, balanceErrors);
|
|
199
|
-
} catch (e) {
|
|
200
|
-
errors.estimation = e as Error;
|
|
201
|
-
estimatedFees = 0n;
|
|
202
|
-
amount = intent.amount;
|
|
203
|
-
totalSpent = intent.amount;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return { errors, warnings, estimatedFees, amount, totalSpent };
|
|
207
|
-
}
|