@ledgerhq/coin-tezos 6.6.0 → 6.7.0-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 +4 -30
- package/CHANGELOG.md +15 -0
- package/jest.integ.config.js +1 -0
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.integ.test.js +6 -0
- package/lib/api/index.integ.test.js.map +1 -1
- package/lib/api/index.js +221 -40
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +84 -10
- package/lib/api/index.test.js.map +1 -1
- package/lib/api/types.d.ts +7 -6
- package/lib/api/types.d.ts.map +1 -1
- package/lib/config.d.ts +4 -3
- 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 +1 -3
- package/lib/index.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +7 -0
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/craftTransaction.test.js +1 -0
- 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 +8 -2
- package/lib/logic/estimateFees.integ.test.js.map +1 -1
- package/lib/logic/estimateFees.js +119 -45
- 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/getStakes.d.ts +3 -0
- package/lib/logic/getStakes.d.ts.map +1 -0
- package/lib/logic/getStakes.js +26 -0
- package/lib/logic/getStakes.js.map +1 -0
- package/lib/logic/getStakes.test.d.ts +2 -0
- package/lib/logic/getStakes.test.d.ts.map +1 -0
- package/lib/logic/getStakes.test.js +133 -0
- package/lib/logic/getStakes.test.js.map +1 -0
- package/lib/logic/index.d.ts +2 -0
- package/lib/logic/index.d.ts.map +1 -1
- package/lib/logic/index.js +5 -1
- package/lib/logic/index.js.map +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +69 -11
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/listOperations.test.js +14 -10
- package/lib/logic/listOperations.test.js.map +1 -1
- package/lib/logic/validateIntent.d.ts +3 -0
- package/lib/logic/validateIntent.d.ts.map +1 -0
- package/lib/logic/validateIntent.js +179 -0
- package/lib/logic/validateIntent.js.map +1 -0
- package/lib/logic/validateIntent.test.d.ts +2 -0
- package/lib/logic/validateIntent.test.d.ts.map +1 -0
- package/lib/logic/validateIntent.test.js +261 -0
- package/lib/logic/validateIntent.test.js.map +1 -0
- package/{lib-es/bridge → lib}/transaction.d.ts +1 -1
- package/lib/transaction.d.ts.map +1 -0
- package/lib/{bridge/transaction.js → transaction.js} +3 -3
- package/lib/transaction.js.map +1 -0
- package/lib/types/bridge.d.ts +3 -0
- 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 +1 -0
- package/lib/types/bridge.fixture.js.map +1 -1
- package/lib/types/bridge.js.map +1 -1
- package/lib/utils.d.ts +50 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +111 -0
- package/lib/utils.js.map +1 -0
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.integ.test.js +6 -0
- package/lib-es/api/index.integ.test.js.map +1 -1
- package/lib-es/api/index.js +222 -41
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +84 -10
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/api/types.d.ts +7 -6
- package/lib-es/api/types.d.ts.map +1 -1
- package/lib-es/config.d.ts +4 -3
- 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 +7 -0
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/craftTransaction.test.js +1 -0
- 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 +8 -2
- package/lib-es/logic/estimateFees.integ.test.js.map +1 -1
- package/lib-es/logic/estimateFees.js +119 -45
- 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/getStakes.d.ts +3 -0
- package/lib-es/logic/getStakes.d.ts.map +1 -0
- package/lib-es/logic/getStakes.js +20 -0
- package/lib-es/logic/getStakes.js.map +1 -0
- package/lib-es/logic/getStakes.test.d.ts +2 -0
- package/lib-es/logic/getStakes.test.d.ts.map +1 -0
- package/lib-es/logic/getStakes.test.js +128 -0
- package/lib-es/logic/getStakes.test.js.map +1 -0
- package/lib-es/logic/index.d.ts +2 -0
- package/lib-es/logic/index.d.ts.map +1 -1
- package/lib-es/logic/index.js +2 -0
- 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 +69 -11
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/listOperations.test.js +14 -10
- package/lib-es/logic/listOperations.test.js.map +1 -1
- package/lib-es/logic/validateIntent.d.ts +3 -0
- package/lib-es/logic/validateIntent.d.ts.map +1 -0
- package/lib-es/logic/validateIntent.js +173 -0
- package/lib-es/logic/validateIntent.js.map +1 -0
- package/lib-es/logic/validateIntent.test.d.ts +2 -0
- package/lib-es/logic/validateIntent.test.d.ts.map +1 -0
- package/lib-es/logic/validateIntent.test.js +233 -0
- package/lib-es/logic/validateIntent.test.js.map +1 -0
- package/{lib/bridge → lib-es}/transaction.d.ts +1 -1
- package/lib-es/transaction.d.ts.map +1 -0
- package/lib-es/{bridge/transaction.js → transaction.js} +3 -3
- package/lib-es/transaction.js.map +1 -0
- package/lib-es/types/bridge.d.ts +3 -0
- 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 +1 -0
- package/lib-es/types/bridge.fixture.js.map +1 -1
- package/lib-es/types/bridge.js.map +1 -1
- package/lib-es/utils.d.ts +50 -0
- package/lib-es/utils.d.ts.map +1 -0
- package/lib-es/utils.js +100 -0
- package/lib-es/utils.js.map +1 -0
- package/package.json +8 -11
- package/src/api/index.integ.test.ts +8 -1
- package/src/api/index.test.ts +93 -16
- package/src/api/index.ts +248 -55
- package/src/api/types.ts +11 -7
- package/src/config.ts +9 -2
- package/src/index.ts +1 -2
- package/src/logic/craftTransaction.test.ts +1 -0
- package/src/logic/craftTransaction.ts +8 -0
- package/src/logic/estimateFees.integ.test.ts +8 -2
- package/src/logic/estimateFees.ts +140 -49
- package/src/logic/getBalance.ts +1 -1
- package/src/logic/getStakes.test.ts +145 -0
- package/src/logic/getStakes.ts +20 -0
- package/src/logic/index.ts +2 -0
- package/src/logic/listOperations.test.ts +64 -54
- package/src/logic/listOperations.ts +70 -10
- package/src/logic/validateIntent.test.ts +274 -0
- package/src/logic/validateIntent.ts +207 -0
- package/src/{bridge/transaction.ts → transaction.ts} +4 -4
- package/src/types/bridge.fixture.ts +1 -0
- package/src/types/bridge.ts +6 -1
- package/src/utils.ts +111 -0
- package/lib/bridge/broadcast.d.ts +0 -4
- package/lib/bridge/broadcast.d.ts.map +0 -1
- package/lib/bridge/broadcast.js +0 -11
- package/lib/bridge/broadcast.js.map +0 -1
- package/lib/bridge/broadcast.test.d.ts +0 -2
- package/lib/bridge/broadcast.test.d.ts.map +0 -1
- package/lib/bridge/broadcast.test.js +0 -36
- package/lib/bridge/broadcast.test.js.map +0 -1
- package/lib/bridge/buildOptimisticOperation.d.ts +0 -4
- package/lib/bridge/buildOptimisticOperation.d.ts.map +0 -1
- package/lib/bridge/buildOptimisticOperation.js +0 -28
- package/lib/bridge/buildOptimisticOperation.js.map +0 -1
- package/lib/bridge/createTransaction.d.ts +0 -4
- package/lib/bridge/createTransaction.d.ts.map +0 -1
- package/lib/bridge/createTransaction.js +0 -24
- package/lib/bridge/createTransaction.js.map +0 -1
- package/lib/bridge/estimateMaxSpendable.d.ts +0 -5
- package/lib/bridge/estimateMaxSpendable.d.ts.map +0 -1
- package/lib/bridge/estimateMaxSpendable.js +0 -30
- package/lib/bridge/estimateMaxSpendable.js.map +0 -1
- package/lib/bridge/getFeesForTransaction.d.ts +0 -21
- package/lib/bridge/getFeesForTransaction.d.ts.map +0 -1
- package/lib/bridge/getFeesForTransaction.js +0 -39
- package/lib/bridge/getFeesForTransaction.js.map +0 -1
- package/lib/bridge/getTransactionStatus.d.ts +0 -4
- package/lib/bridge/getTransactionStatus.d.ts.map +0 -1
- package/lib/bridge/getTransactionStatus.js +0 -108
- package/lib/bridge/getTransactionStatus.js.map +0 -1
- package/lib/bridge/getTransactionStatus.test.d.ts +0 -2
- package/lib/bridge/getTransactionStatus.test.d.ts.map +0 -1
- package/lib/bridge/getTransactionStatus.test.js +0 -107
- package/lib/bridge/getTransactionStatus.test.js.map +0 -1
- package/lib/bridge/index.d.ts +0 -10
- package/lib/bridge/index.d.ts.map +0 -1
- package/lib/bridge/index.js +0 -59
- package/lib/bridge/index.js.map +0 -1
- package/lib/bridge/logic.d.ts +0 -10
- package/lib/bridge/logic.d.ts.map +0 -1
- package/lib/bridge/logic.js +0 -155
- package/lib/bridge/logic.js.map +0 -1
- package/lib/bridge/preload.d.ts +0 -9
- package/lib/bridge/preload.d.ts.map +0 -1
- package/lib/bridge/preload.js +0 -23
- package/lib/bridge/preload.js.map +0 -1
- package/lib/bridge/prepareTransaction.d.ts +0 -5
- package/lib/bridge/prepareTransaction.d.ts.map +0 -1
- package/lib/bridge/prepareTransaction.integ.test.d.ts +0 -2
- package/lib/bridge/prepareTransaction.integ.test.d.ts.map +0 -1
- package/lib/bridge/prepareTransaction.integ.test.js +0 -34
- package/lib/bridge/prepareTransaction.integ.test.js.map +0 -1
- package/lib/bridge/prepareTransaction.js +0 -57
- package/lib/bridge/prepareTransaction.js.map +0 -1
- package/lib/bridge/prepareTransaction.test.d.ts +0 -2
- package/lib/bridge/prepareTransaction.test.d.ts.map +0 -1
- package/lib/bridge/prepareTransaction.test.js +0 -178
- package/lib/bridge/prepareTransaction.test.js.map +0 -1
- package/lib/bridge/serialization.d.ts +0 -7
- package/lib/bridge/serialization.d.ts.map +0 -1
- package/lib/bridge/serialization.js +0 -26
- package/lib/bridge/serialization.js.map +0 -1
- package/lib/bridge/signOperation.d.ts +0 -16
- package/lib/bridge/signOperation.d.ts.map +0 -1
- package/lib/bridge/signOperation.js +0 -88
- package/lib/bridge/signOperation.js.map +0 -1
- package/lib/bridge/signOperation.test.d.ts +0 -2
- package/lib/bridge/signOperation.test.d.ts.map +0 -1
- package/lib/bridge/signOperation.test.js +0 -283
- package/lib/bridge/signOperation.test.js.map +0 -1
- package/lib/bridge/synchronization.d.ts +0 -5
- package/lib/bridge/synchronization.d.ts.map +0 -1
- package/lib/bridge/synchronization.integ.test.d.ts +0 -2
- package/lib/bridge/synchronization.integ.test.d.ts.map +0 -1
- package/lib/bridge/synchronization.integ.test.js +0 -32
- package/lib/bridge/synchronization.integ.test.js.map +0 -1
- package/lib/bridge/synchronization.js +0 -100
- package/lib/bridge/synchronization.js.map +0 -1
- package/lib/bridge/transaction.d.ts.map +0 -1
- package/lib/bridge/transaction.js.map +0 -1
- package/lib-es/bridge/broadcast.d.ts +0 -4
- package/lib-es/bridge/broadcast.d.ts.map +0 -1
- package/lib-es/bridge/broadcast.js +0 -7
- package/lib-es/bridge/broadcast.js.map +0 -1
- package/lib-es/bridge/broadcast.test.d.ts +0 -2
- package/lib-es/bridge/broadcast.test.d.ts.map +0 -1
- package/lib-es/bridge/broadcast.test.js +0 -31
- package/lib-es/bridge/broadcast.test.js.map +0 -1
- package/lib-es/bridge/buildOptimisticOperation.d.ts +0 -4
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +0 -1
- package/lib-es/bridge/buildOptimisticOperation.js +0 -21
- package/lib-es/bridge/buildOptimisticOperation.js.map +0 -1
- package/lib-es/bridge/createTransaction.d.ts +0 -4
- package/lib-es/bridge/createTransaction.d.ts.map +0 -1
- package/lib-es/bridge/createTransaction.js +0 -17
- package/lib-es/bridge/createTransaction.js.map +0 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts +0 -5
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +0 -1
- package/lib-es/bridge/estimateMaxSpendable.js +0 -23
- package/lib-es/bridge/estimateMaxSpendable.js.map +0 -1
- package/lib-es/bridge/getFeesForTransaction.d.ts +0 -21
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +0 -1
- package/lib-es/bridge/getFeesForTransaction.js +0 -33
- package/lib-es/bridge/getFeesForTransaction.js.map +0 -1
- package/lib-es/bridge/getTransactionStatus.d.ts +0 -4
- package/lib-es/bridge/getTransactionStatus.d.ts.map +0 -1
- package/lib-es/bridge/getTransactionStatus.js +0 -101
- package/lib-es/bridge/getTransactionStatus.js.map +0 -1
- package/lib-es/bridge/getTransactionStatus.test.d.ts +0 -2
- package/lib-es/bridge/getTransactionStatus.test.d.ts.map +0 -1
- package/lib-es/bridge/getTransactionStatus.test.js +0 -102
- package/lib-es/bridge/getTransactionStatus.test.js.map +0 -1
- package/lib-es/bridge/index.d.ts +0 -10
- package/lib-es/bridge/index.d.ts.map +0 -1
- package/lib-es/bridge/index.js +0 -53
- package/lib-es/bridge/index.js.map +0 -1
- package/lib-es/bridge/logic.d.ts +0 -10
- package/lib-es/bridge/logic.d.ts.map +0 -1
- package/lib-es/bridge/logic.js +0 -145
- package/lib-es/bridge/logic.js.map +0 -1
- package/lib-es/bridge/preload.d.ts +0 -9
- package/lib-es/bridge/preload.d.ts.map +0 -1
- package/lib-es/bridge/preload.js +0 -17
- package/lib-es/bridge/preload.js.map +0 -1
- package/lib-es/bridge/prepareTransaction.d.ts +0 -5
- package/lib-es/bridge/prepareTransaction.d.ts.map +0 -1
- package/lib-es/bridge/prepareTransaction.integ.test.d.ts +0 -2
- package/lib-es/bridge/prepareTransaction.integ.test.d.ts.map +0 -1
- package/lib-es/bridge/prepareTransaction.integ.test.js +0 -29
- package/lib-es/bridge/prepareTransaction.integ.test.js.map +0 -1
- package/lib-es/bridge/prepareTransaction.js +0 -50
- package/lib-es/bridge/prepareTransaction.js.map +0 -1
- package/lib-es/bridge/prepareTransaction.test.d.ts +0 -2
- package/lib-es/bridge/prepareTransaction.test.d.ts.map +0 -1
- package/lib-es/bridge/prepareTransaction.test.js +0 -173
- package/lib-es/bridge/prepareTransaction.test.js.map +0 -1
- package/lib-es/bridge/serialization.d.ts +0 -7
- package/lib-es/bridge/serialization.d.ts.map +0 -1
- package/lib-es/bridge/serialization.js +0 -20
- package/lib-es/bridge/serialization.js.map +0 -1
- package/lib-es/bridge/signOperation.d.ts +0 -16
- package/lib-es/bridge/signOperation.d.ts.map +0 -1
- package/lib-es/bridge/signOperation.js +0 -83
- package/lib-es/bridge/signOperation.js.map +0 -1
- package/lib-es/bridge/signOperation.test.d.ts +0 -2
- package/lib-es/bridge/signOperation.test.d.ts.map +0 -1
- package/lib-es/bridge/signOperation.test.js +0 -255
- package/lib-es/bridge/signOperation.test.js.map +0 -1
- package/lib-es/bridge/synchronization.d.ts +0 -5
- package/lib-es/bridge/synchronization.d.ts.map +0 -1
- package/lib-es/bridge/synchronization.integ.test.d.ts +0 -2
- package/lib-es/bridge/synchronization.integ.test.d.ts.map +0 -1
- package/lib-es/bridge/synchronization.integ.test.js +0 -27
- package/lib-es/bridge/synchronization.integ.test.js.map +0 -1
- package/lib-es/bridge/synchronization.js +0 -70
- package/lib-es/bridge/synchronization.js.map +0 -1
- package/lib-es/bridge/transaction.d.ts.map +0 -1
- package/lib-es/bridge/transaction.js.map +0 -1
- package/src/bridge/broadcast.test.ts +0 -36
- package/src/bridge/broadcast.ts +0 -13
- package/src/bridge/buildOptimisticOperation.ts +0 -28
- package/src/bridge/createTransaction.ts +0 -19
- package/src/bridge/estimateMaxSpendable.ts +0 -37
- package/src/bridge/getFeesForTransaction.ts +0 -49
- package/src/bridge/getTransactionStatus.test.ts +0 -124
- package/src/bridge/getTransactionStatus.ts +0 -123
- package/src/bridge/index.ts +0 -74
- package/src/bridge/logic.ts +0 -171
- package/src/bridge/preload.ts +0 -18
- package/src/bridge/prepareTransaction.integ.test.ts +0 -35
- package/src/bridge/prepareTransaction.test.ts +0 -205
- package/src/bridge/prepareTransaction.ts +0 -69
- package/src/bridge/serialization.ts +0 -27
- package/src/bridge/signOperation.test.ts +0 -284
- package/src/bridge/signOperation.ts +0 -130
- package/src/bridge/synchronization.integ.test.ts +0 -33
- package/src/bridge/synchronization.ts +0 -100
package/src/api/index.test.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Operation } from "@ledgerhq/coin-framework/api/types";
|
|
|
2
2
|
import type { APIAccount } from "../network/types";
|
|
3
3
|
import networkApi from "../network/tzkt";
|
|
4
4
|
import { createApi } from "./index";
|
|
5
|
-
import
|
|
5
|
+
import { TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
6
6
|
|
|
7
7
|
const DEFAULT_ESTIMATED_FEES = 300n;
|
|
8
8
|
const DEFAULT_GAS_LIMIT = 30n;
|
|
@@ -24,11 +24,18 @@ jest.mock("../logic", () => ({
|
|
|
24
24
|
rawEncode: () => Promise.resolve("tz1heMGVHQnx7ALDcDKqez8fan64Eyicw4DJ"),
|
|
25
25
|
}));
|
|
26
26
|
|
|
27
|
-
jest
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
jest.spyOn(networkApi, "getAccountByAddress").mockResolvedValue({
|
|
28
|
+
type: "user",
|
|
29
|
+
balance: 1000,
|
|
30
|
+
revealed: true,
|
|
31
|
+
address: "tz1test",
|
|
32
|
+
publicKey: "edpktest",
|
|
33
|
+
counter: 0,
|
|
34
|
+
delegationLevel: 0,
|
|
35
|
+
delegationTime: "2021-01-01T00:00:00Z",
|
|
36
|
+
numTransactions: 0,
|
|
37
|
+
firstActivityTime: "2021-01-01T00:00:00Z",
|
|
38
|
+
} as APIAccount);
|
|
32
39
|
|
|
33
40
|
const api = createApi({
|
|
34
41
|
baker: {
|
|
@@ -94,12 +101,28 @@ describe("Testing craftTransaction function", () => {
|
|
|
94
101
|
beforeEach(() => jest.clearAllMocks());
|
|
95
102
|
|
|
96
103
|
it("should use estimated fees when user does not provide them for crafting a transaction ", async () => {
|
|
97
|
-
logicEstimateFees.mockResolvedValue({
|
|
98
|
-
|
|
104
|
+
logicEstimateFees.mockResolvedValue({
|
|
105
|
+
estimatedFees: DEFAULT_ESTIMATED_FEES,
|
|
106
|
+
gasLimit: DEFAULT_GAS_LIMIT,
|
|
107
|
+
storageLimit: DEFAULT_STORAGE_LIMIT,
|
|
108
|
+
});
|
|
109
|
+
await api.craftTransaction({
|
|
110
|
+
intentType: "transaction",
|
|
111
|
+
type: "send",
|
|
112
|
+
sender: "tz1test",
|
|
113
|
+
recipient: "tz1recipient",
|
|
114
|
+
amount: 1000n,
|
|
115
|
+
} as TransactionIntent);
|
|
99
116
|
expect(logicEstimateFees).toHaveBeenCalledTimes(1);
|
|
100
117
|
expect(logicCraftTransactionMock).toHaveBeenCalledWith(
|
|
101
|
-
expect.
|
|
102
|
-
expect.objectContaining({
|
|
118
|
+
expect.objectContaining({ address: "tz1test" }),
|
|
119
|
+
expect.objectContaining({
|
|
120
|
+
fee: expect.objectContaining({
|
|
121
|
+
fees: DEFAULT_ESTIMATED_FEES.toString(),
|
|
122
|
+
gasLimit: DEFAULT_GAS_LIMIT.toString(),
|
|
123
|
+
storageLimit: DEFAULT_STORAGE_LIMIT.toString(),
|
|
124
|
+
}),
|
|
125
|
+
}),
|
|
103
126
|
);
|
|
104
127
|
});
|
|
105
128
|
|
|
@@ -110,10 +133,23 @@ describe("Testing craftTransaction function", () => {
|
|
|
110
133
|
estimatedFees: DEFAULT_ESTIMATED_FEES,
|
|
111
134
|
gasLimit: DEFAULT_GAS_LIMIT,
|
|
112
135
|
storageLimit: DEFAULT_STORAGE_LIMIT,
|
|
136
|
+
parameters: {
|
|
137
|
+
gasLimit: DEFAULT_GAS_LIMIT,
|
|
138
|
+
storageLimit: DEFAULT_STORAGE_LIMIT,
|
|
139
|
+
},
|
|
113
140
|
});
|
|
114
|
-
await api.craftTransaction(
|
|
115
|
-
|
|
116
|
-
|
|
141
|
+
await api.craftTransaction(
|
|
142
|
+
{
|
|
143
|
+
intentType: "transaction",
|
|
144
|
+
type: "send",
|
|
145
|
+
sender: "tz1test",
|
|
146
|
+
recipient: "tz1recipient",
|
|
147
|
+
amount: 1000n,
|
|
148
|
+
} as TransactionIntent,
|
|
149
|
+
{
|
|
150
|
+
value: customFees,
|
|
151
|
+
},
|
|
152
|
+
);
|
|
117
153
|
expect(logicEstimateFees).toHaveBeenCalledTimes(1);
|
|
118
154
|
expect(logicCraftTransactionMock).toHaveBeenCalledWith(
|
|
119
155
|
expect.any(Object),
|
|
@@ -138,7 +174,13 @@ describe("Testing estimateFees function", () => {
|
|
|
138
174
|
gasLimit: DEFAULT_GAS_LIMIT,
|
|
139
175
|
storageLimit: DEFAULT_STORAGE_LIMIT,
|
|
140
176
|
});
|
|
141
|
-
const result = await api.estimateFees({
|
|
177
|
+
const result = await api.estimateFees({
|
|
178
|
+
intentType: "transaction",
|
|
179
|
+
type: "send",
|
|
180
|
+
sender: "tz1test",
|
|
181
|
+
recipient: "tz1recipient",
|
|
182
|
+
amount: 1000n,
|
|
183
|
+
} as TransactionIntent);
|
|
142
184
|
expect(result).toEqual({
|
|
143
185
|
value: DEFAULT_ESTIMATED_FEES,
|
|
144
186
|
parameters: {
|
|
@@ -149,9 +191,44 @@ describe("Testing estimateFees function", () => {
|
|
|
149
191
|
});
|
|
150
192
|
|
|
151
193
|
it("should throw taquito errors", async () => {
|
|
152
|
-
logicEstimateFees.mockResolvedValue({
|
|
194
|
+
logicEstimateFees.mockResolvedValue({
|
|
195
|
+
estimatedFees: DEFAULT_ESTIMATED_FEES,
|
|
196
|
+
gasLimit: DEFAULT_GAS_LIMIT,
|
|
197
|
+
storageLimit: DEFAULT_STORAGE_LIMIT,
|
|
198
|
+
taquitoError: "test",
|
|
199
|
+
});
|
|
153
200
|
await expect(
|
|
154
|
-
api.estimateFees({
|
|
201
|
+
api.estimateFees({
|
|
202
|
+
intentType: "transaction",
|
|
203
|
+
type: "send",
|
|
204
|
+
sender: "tz1test",
|
|
205
|
+
recipient: "tz1recipient",
|
|
206
|
+
amount: 1000n,
|
|
207
|
+
} as TransactionIntent),
|
|
155
208
|
).rejects.toThrow("Fees estimation failed: test");
|
|
156
209
|
});
|
|
210
|
+
|
|
211
|
+
it("should not throw for delegate.unchanged errors", async () => {
|
|
212
|
+
logicEstimateFees.mockResolvedValue({
|
|
213
|
+
estimatedFees: DEFAULT_ESTIMATED_FEES,
|
|
214
|
+
gasLimit: DEFAULT_GAS_LIMIT,
|
|
215
|
+
storageLimit: DEFAULT_STORAGE_LIMIT,
|
|
216
|
+
taquitoError: "proto.022-PsRiotum.delegate.unchanged",
|
|
217
|
+
});
|
|
218
|
+
const result = await api.estimateFees({
|
|
219
|
+
intentType: "staking",
|
|
220
|
+
type: "delegate",
|
|
221
|
+
sender: "tz1test",
|
|
222
|
+
recipient: "tz1validator",
|
|
223
|
+
amount: 0n,
|
|
224
|
+
} as TransactionIntent);
|
|
225
|
+
|
|
226
|
+
expect(result).toEqual({
|
|
227
|
+
value: DEFAULT_ESTIMATED_FEES,
|
|
228
|
+
parameters: {
|
|
229
|
+
gasLimit: DEFAULT_GAS_LIMIT,
|
|
230
|
+
storageLimit: DEFAULT_STORAGE_LIMIT,
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
});
|
|
157
234
|
});
|
package/src/api/index.ts
CHANGED
|
@@ -21,11 +21,22 @@ import {
|
|
|
21
21
|
lastBlock,
|
|
22
22
|
listOperations,
|
|
23
23
|
rawEncode,
|
|
24
|
+
validateIntent,
|
|
25
|
+
getStakes,
|
|
24
26
|
} from "../logic";
|
|
27
|
+
import { getTezosToolkit } from "../logic/tezosToolkit";
|
|
25
28
|
import api from "../network/tzkt";
|
|
26
29
|
import type { TezosApi, TezosFeeEstimation } from "./types";
|
|
27
|
-
import { FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
28
|
-
import {
|
|
30
|
+
import type { FeeEstimation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
31
|
+
import { RecommendUndelegation } from "@ledgerhq/errors";
|
|
32
|
+
import { validatePublicKey, ValidationResult, getPkhfromPk } from "@taquito/utils";
|
|
33
|
+
import { getRevealFee } from "@taquito/taquito";
|
|
34
|
+
import {
|
|
35
|
+
DUST_MARGIN_MUTEZ,
|
|
36
|
+
hasEmptyBalance,
|
|
37
|
+
mapIntentTypeToTezosMode,
|
|
38
|
+
normalizePublicKeyForAddress,
|
|
39
|
+
} from "../utils";
|
|
29
40
|
|
|
30
41
|
export function createApi(config: TezosConfig): TezosApi {
|
|
31
42
|
coinConfig.setCoinConfig(() => ({ ...config, status: { type: "active" } }));
|
|
@@ -34,35 +45,66 @@ export function createApi(config: TezosConfig): TezosApi {
|
|
|
34
45
|
broadcast,
|
|
35
46
|
combine,
|
|
36
47
|
craftTransaction: craft,
|
|
48
|
+
craftRawTransaction: (
|
|
49
|
+
_transaction: string,
|
|
50
|
+
_sender: string,
|
|
51
|
+
_publicKey: string,
|
|
52
|
+
_sequence: number,
|
|
53
|
+
): Promise<CraftedTransaction> => {
|
|
54
|
+
throw new Error("craftRawTransaction is not supported");
|
|
55
|
+
},
|
|
37
56
|
estimateFees: estimate,
|
|
38
57
|
getBalance: balance,
|
|
39
58
|
lastBlock,
|
|
40
59
|
listOperations: operations,
|
|
60
|
+
getStakes,
|
|
61
|
+
validateIntent,
|
|
62
|
+
// required by signer to compute next valid sequence/counter
|
|
63
|
+
getSequence: async (address: string) => {
|
|
64
|
+
const accountInfo = await api.getAccountByAddress(address);
|
|
65
|
+
return accountInfo.type === "user" ? accountInfo.counter + 1 : 0;
|
|
66
|
+
},
|
|
41
67
|
getBlock(_height): Promise<Block> {
|
|
42
68
|
throw new Error("getBlock is not supported");
|
|
43
69
|
},
|
|
44
70
|
getBlockInfo(_height: number): Promise<BlockInfo> {
|
|
45
71
|
throw new Error("getBlockInfo is not supported");
|
|
46
72
|
},
|
|
47
|
-
getStakes(_address: string, _cursor?: Cursor): Promise<Page<Stake>> {
|
|
48
|
-
throw new Error("getStakes is not supported");
|
|
49
|
-
},
|
|
50
73
|
getRewards(_address: string, _cursor?: Cursor): Promise<Page<Reward>> {
|
|
51
74
|
throw new Error("getRewards is not supported");
|
|
52
75
|
},
|
|
53
76
|
};
|
|
54
77
|
}
|
|
55
78
|
|
|
56
|
-
function isTezosTransactionType(
|
|
57
|
-
|
|
79
|
+
function isTezosTransactionType(
|
|
80
|
+
type: string,
|
|
81
|
+
): type is "send" | "delegate" | "undelegate" | "stake" | "unstake" {
|
|
82
|
+
return ["send", "delegate", "undelegate", "stake", "unstake"].includes(type);
|
|
58
83
|
}
|
|
59
84
|
|
|
60
85
|
async function balance(address: string): Promise<Balance[]> {
|
|
61
86
|
const value = await getBalance(address);
|
|
87
|
+
const accountInfo = await api.getAccountByAddress(address);
|
|
88
|
+
// tzkt returns `type: "empty"` for untouched accounts; legacy logic returns -1 in that case
|
|
89
|
+
// the generic bridge expects non-negative balances
|
|
90
|
+
const normalized = value < 0n ? 0n : value;
|
|
91
|
+
// include stake information so ui can reflect delegation on account page
|
|
92
|
+
const stake: Stake | undefined =
|
|
93
|
+
accountInfo.type === "user" && accountInfo.delegate?.address
|
|
94
|
+
? {
|
|
95
|
+
uid: address,
|
|
96
|
+
address,
|
|
97
|
+
delegate: accountInfo.delegate.address,
|
|
98
|
+
state: "active",
|
|
99
|
+
asset: { type: "native" },
|
|
100
|
+
amount: BigInt(accountInfo.balance ?? 0),
|
|
101
|
+
}
|
|
102
|
+
: undefined;
|
|
62
103
|
return [
|
|
63
104
|
{
|
|
64
|
-
value,
|
|
105
|
+
value: normalized,
|
|
65
106
|
asset: { type: "native" },
|
|
107
|
+
stake,
|
|
66
108
|
},
|
|
67
109
|
];
|
|
68
110
|
}
|
|
@@ -75,64 +117,214 @@ async function craft(
|
|
|
75
117
|
throw new IncorrectTypeError(transactionIntent.type);
|
|
76
118
|
}
|
|
77
119
|
|
|
78
|
-
//
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
120
|
+
// Always estimate to get gasLimit/storageLimit
|
|
121
|
+
const estimation = await estimate(transactionIntent);
|
|
122
|
+
const fee = {
|
|
123
|
+
fees: (customFees?.value ?? estimation.value).toString(),
|
|
124
|
+
gasLimit: estimation.parameters?.gasLimit?.toString(),
|
|
125
|
+
storageLimit: estimation.parameters?.storageLimit?.toString(),
|
|
126
|
+
};
|
|
84
127
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
{
|
|
88
|
-
type: transactionIntent.type,
|
|
89
|
-
recipient: transactionIntent.recipient,
|
|
90
|
-
amount: transactionIntent.amount,
|
|
91
|
-
fee,
|
|
92
|
-
},
|
|
93
|
-
);
|
|
128
|
+
// Map generic staking intents to tezos modes
|
|
129
|
+
const mappedType = mapIntentTypeToTezosMode(transactionIntent.type);
|
|
94
130
|
|
|
95
|
-
|
|
131
|
+
// Guard: send max is incompatible with delegated accounts
|
|
132
|
+
let amountToUse = transactionIntent.amount;
|
|
133
|
+
if (mappedType === "send" && transactionIntent.useAllAmount) {
|
|
134
|
+
const senderInfo = await api.getAccountByAddress(transactionIntent.sender);
|
|
135
|
+
if (senderInfo.type === "user" && senderInfo.delegate?.address) {
|
|
136
|
+
throw new RecommendUndelegation();
|
|
137
|
+
}
|
|
138
|
+
if (senderInfo.type === "user") {
|
|
139
|
+
// Use the amount calculated by the estimation which includes proper buffers and adjustments
|
|
140
|
+
if (estimation.parameters?.amount !== undefined) {
|
|
141
|
+
amountToUse = estimation.parameters.amount;
|
|
142
|
+
} else {
|
|
143
|
+
// Fallback to the original calculation if estimation doesn't provide amount
|
|
144
|
+
const bal = BigInt(senderInfo.balance);
|
|
145
|
+
const feeBI = BigInt(fee.fees || "0");
|
|
146
|
+
const dustMargin = BigInt(DUST_MARGIN_MUTEZ);
|
|
147
|
+
const totalToDeduct = feeBI + dustMargin;
|
|
148
|
+
amountToUse = bal > totalToDeduct ? bal - totalToDeduct : 0n;
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
amountToUse = 0n;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const accountForCraft = {
|
|
156
|
+
address: transactionIntent.sender,
|
|
157
|
+
};
|
|
158
|
+
const senderApiAcc = await api.getAccountByAddress(transactionIntent.sender);
|
|
159
|
+
const needsReveal = senderApiAcc.type === "user" && !senderApiAcc.revealed;
|
|
160
|
+
const totalFee = Number(fee.fees || "0");
|
|
161
|
+
|
|
162
|
+
let txFee: number;
|
|
163
|
+
if (customFees) {
|
|
164
|
+
txFee = needsReveal ? Math.max(totalFee - getRevealFee(transactionIntent.sender), 0) : totalFee;
|
|
165
|
+
} else if (estimation.parameters?.txFee !== undefined) {
|
|
166
|
+
txFee = Number(estimation.parameters.txFee);
|
|
167
|
+
} else {
|
|
168
|
+
const calculatedTxFee = needsReveal
|
|
169
|
+
? Math.max(totalFee - getRevealFee(transactionIntent.sender), 0)
|
|
170
|
+
: totalFee;
|
|
171
|
+
txFee = calculatedTxFee;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const txForCraft = {
|
|
175
|
+
type: mappedType,
|
|
176
|
+
recipient: transactionIntent.recipient,
|
|
177
|
+
amount: amountToUse,
|
|
178
|
+
fee: { ...fee, fees: txFee.toString() },
|
|
179
|
+
};
|
|
180
|
+
const publicKeyForCraft =
|
|
181
|
+
needsReveal && transactionIntent.senderPublicKey
|
|
182
|
+
? (() => {
|
|
183
|
+
// Accept either base58 or hex from device, and map curve using sender address
|
|
184
|
+
let pk = transactionIntent.senderPublicKey;
|
|
185
|
+
if (validatePublicKey(pk) !== ValidationResult.VALID) {
|
|
186
|
+
pk = normalizePublicKeyForAddress(pk, transactionIntent.sender) || pk;
|
|
187
|
+
}
|
|
188
|
+
// Verify the public key matches the sender address to avoid inconsistent_hash
|
|
189
|
+
let isPublicKeyValid = false;
|
|
190
|
+
try {
|
|
191
|
+
const derived = getPkhfromPk(pk);
|
|
192
|
+
isPublicKeyValid = derived === transactionIntent.sender;
|
|
193
|
+
} catch {
|
|
194
|
+
// getPkhfromPk failed = will fallback to basic validation below
|
|
195
|
+
isPublicKeyValid = false;
|
|
196
|
+
}
|
|
96
197
|
|
|
198
|
+
if (!isPublicKeyValid) {
|
|
199
|
+
// If derivation failed/doesn't match, check if the key is atleast valid format
|
|
200
|
+
if (validatePublicKey(pk) !== ValidationResult.VALID) {
|
|
201
|
+
throw new Error("Unable to normalize sender public key");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return { publicKey: pk, publicKeyHash: transactionIntent.sender };
|
|
205
|
+
})()
|
|
206
|
+
: undefined;
|
|
207
|
+
const { contents } = await craftTransaction(accountForCraft, txForCraft, publicKeyForCraft);
|
|
208
|
+
const tx = await rawEncode(contents);
|
|
97
209
|
return { transaction: tx };
|
|
98
210
|
}
|
|
99
211
|
|
|
100
212
|
async function estimate(transactionIntent: TransactionIntent): Promise<TezosFeeEstimation> {
|
|
213
|
+
// avoid taquito error when estimating a 0-amount transfer during input
|
|
214
|
+
const config = coinConfig.getCoinConfig();
|
|
215
|
+
if (
|
|
216
|
+
transactionIntent.type === "send" &&
|
|
217
|
+
transactionIntent.amount === 0n &&
|
|
218
|
+
!transactionIntent.useAllAmount
|
|
219
|
+
) {
|
|
220
|
+
return {
|
|
221
|
+
value: BigInt(DUST_MARGIN_MUTEZ),
|
|
222
|
+
parameters: {
|
|
223
|
+
gasLimit: 10000n,
|
|
224
|
+
storageLimit: 300n,
|
|
225
|
+
amount: 0n,
|
|
226
|
+
txFee: BigInt(DUST_MARGIN_MUTEZ),
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
}
|
|
101
230
|
const senderAccountInfo = await api.getAccountByAddress(transactionIntent.sender);
|
|
231
|
+
// If the sender is not a user account, return default estimation values
|
|
232
|
+
if (senderAccountInfo.type !== "user") {
|
|
233
|
+
return {
|
|
234
|
+
value: BigInt(DUST_MARGIN_MUTEZ),
|
|
235
|
+
parameters: {
|
|
236
|
+
gasLimit: 10000n,
|
|
237
|
+
storageLimit: 300n,
|
|
238
|
+
amount: 0n,
|
|
239
|
+
txFee: BigInt(DUST_MARGIN_MUTEZ),
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
}
|
|
102
243
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
transactionIntent.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
amount: transactionIntent.amount,
|
|
122
|
-
},
|
|
123
|
-
});
|
|
244
|
+
try {
|
|
245
|
+
const estimation = await estimateFees({
|
|
246
|
+
account: {
|
|
247
|
+
address: transactionIntent.sender,
|
|
248
|
+
revealed: senderAccountInfo.revealed,
|
|
249
|
+
balance: BigInt(senderAccountInfo.balance),
|
|
250
|
+
// try intent public key first and fallback to tzkt public key
|
|
251
|
+
xpub: transactionIntent.senderPublicKey ?? senderAccountInfo.publicKey,
|
|
252
|
+
},
|
|
253
|
+
transaction: {
|
|
254
|
+
// reuse the same mapping as craft
|
|
255
|
+
mode: mapIntentTypeToTezosMode(transactionIntent.type),
|
|
256
|
+
recipient: transactionIntent.recipient,
|
|
257
|
+
amount: transactionIntent.amount,
|
|
258
|
+
// legacy estimator needs this flag to pre-estimate fees
|
|
259
|
+
useAllAmount: !!transactionIntent.useAllAmount,
|
|
260
|
+
},
|
|
261
|
+
});
|
|
124
262
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
263
|
+
if (
|
|
264
|
+
estimation.taquitoError &&
|
|
265
|
+
!estimation.taquitoError.includes("delegate.unchanged") &&
|
|
266
|
+
!estimation.taquitoError.includes("subtraction_underflow") &&
|
|
267
|
+
!estimation.taquitoError.includes("balance_too_low")
|
|
268
|
+
) {
|
|
269
|
+
throw new Error(`Fees estimation failed: ${estimation.taquitoError}`);
|
|
270
|
+
}
|
|
128
271
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
272
|
+
return {
|
|
273
|
+
value: estimation.estimatedFees,
|
|
274
|
+
parameters: {
|
|
275
|
+
gasLimit: estimation.gasLimit,
|
|
276
|
+
storageLimit: estimation.storageLimit,
|
|
277
|
+
amount: estimation.amount,
|
|
278
|
+
txFee: estimation.fees,
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
} catch (error: any) {
|
|
282
|
+
// Handle PublicKeyNotFoundError
|
|
283
|
+
if (error?.message?.includes("Public key not found")) {
|
|
284
|
+
const apiAccount = await api.getAccountByAddress(transactionIntent.recipient);
|
|
285
|
+
const storageLimit =
|
|
286
|
+
!hasEmptyBalance(apiAccount) || transactionIntent.type === "stake" ? 0n : 277n;
|
|
287
|
+
|
|
288
|
+
// Check if account needs reveal for proper fee calculation
|
|
289
|
+
const senderApiAcc = await api.getAccountByAddress(transactionIntent.sender);
|
|
290
|
+
const needsReveal = senderApiAcc.type === "user" && !senderApiAcc.revealed;
|
|
291
|
+
|
|
292
|
+
// Production-calibrated fallback fee when Taquito estimation fails (~388 mutez observed)
|
|
293
|
+
const DEFAULT_TX_FEE_FALLBACK = 388;
|
|
294
|
+
let baseTxFee: bigint;
|
|
295
|
+
|
|
296
|
+
try {
|
|
297
|
+
const toolkit = getTezosToolkit();
|
|
298
|
+
const simpleEstimate = await toolkit.estimate.transfer({
|
|
299
|
+
to: transactionIntent.recipient,
|
|
300
|
+
amount: Number(transactionIntent.amount),
|
|
301
|
+
mutez: true,
|
|
302
|
+
source: transactionIntent.sender,
|
|
303
|
+
});
|
|
304
|
+
// Use Taquito estimation, respecting minFees from config
|
|
305
|
+
baseTxFee = BigInt(Math.max(config.fees.minFees, simpleEstimate.suggestedFeeMutez));
|
|
306
|
+
} catch {
|
|
307
|
+
// Fallback to production-calibrated default if estimation fails
|
|
308
|
+
baseTxFee = BigInt(Math.max(DEFAULT_TX_FEE_FALLBACK, config.fees.minFees));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const revealFee = needsReveal ? BigInt(getRevealFee(transactionIntent.sender)) : 0n;
|
|
312
|
+
const totalFee = baseTxFee + revealFee;
|
|
313
|
+
|
|
314
|
+
return {
|
|
315
|
+
value: totalFee,
|
|
316
|
+
parameters: {
|
|
317
|
+
gasLimit: 10000n,
|
|
318
|
+
storageLimit,
|
|
319
|
+
amount: 0n,
|
|
320
|
+
txFee: baseTxFee,
|
|
321
|
+
},
|
|
322
|
+
};
|
|
323
|
+
} else {
|
|
324
|
+
// Re-throw other errors
|
|
325
|
+
throw error;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
136
328
|
}
|
|
137
329
|
|
|
138
330
|
async function operations(
|
|
@@ -145,5 +337,6 @@ async function operations(
|
|
|
145
337
|
sort: pagination.order === "asc" ? "Ascending" : "Descending",
|
|
146
338
|
minHeight: pagination.minHeight,
|
|
147
339
|
});
|
|
340
|
+
|
|
148
341
|
return [operations, newNextCursor || ""];
|
|
149
342
|
}
|
package/src/api/types.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Api, FeeEstimation } from "@ledgerhq/coin-framework/api/types";
|
|
2
2
|
|
|
3
|
-
export type TezosFeeParameters = {
|
|
4
|
-
|
|
3
|
+
export type TezosFeeParameters = {
|
|
4
|
+
gasLimit: bigint;
|
|
5
|
+
storageLimit: bigint;
|
|
6
|
+
amount?: bigint;
|
|
7
|
+
txFee?: bigint;
|
|
8
|
+
};
|
|
9
|
+
export type TezosFeeEstimation = FeeEstimation & {
|
|
10
|
+
parameters?: TezosFeeParameters & Record<string, unknown>;
|
|
11
|
+
};
|
|
5
12
|
|
|
6
13
|
export type TezosSender = { address: string; xpub?: string };
|
|
7
|
-
export type TezosTransactionIntent = TransactionIntent;
|
|
8
14
|
|
|
9
|
-
export type TezosApi =
|
|
10
|
-
estimateFees: (transactionIntent: TezosTransactionIntent) => Promise<TezosFeeEstimation>;
|
|
11
|
-
};
|
|
15
|
+
export type TezosApi = Api;
|
package/src/config.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import buildCoinConfig, {
|
|
1
|
+
import buildCoinConfig, {
|
|
2
|
+
type CoinConfig,
|
|
3
|
+
type CurrencyConfig,
|
|
4
|
+
} from "@ledgerhq/coin-framework/config";
|
|
5
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
6
|
|
|
3
7
|
export type TezosConfig = {
|
|
4
8
|
baker: {
|
|
@@ -22,6 +26,9 @@ export type TezosConfig = {
|
|
|
22
26
|
|
|
23
27
|
export type TezosCoinConfig = CurrencyConfig & TezosConfig;
|
|
24
28
|
|
|
25
|
-
const coinConfig
|
|
29
|
+
const coinConfig: {
|
|
30
|
+
setCoinConfig: (config: CoinConfig<TezosCoinConfig>) => void;
|
|
31
|
+
getCoinConfig: (currency?: CryptoCurrency) => TezosCoinConfig;
|
|
32
|
+
} = buildCoinConfig<TezosCoinConfig>();
|
|
26
33
|
|
|
27
34
|
export default coinConfig;
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { getRevealFee } from "@taquito/taquito";
|
|
|
3
3
|
import coinConfig from "../config";
|
|
4
4
|
import { UnsupportedTransactionMode } from "../types/errors";
|
|
5
5
|
import { getTezosToolkit } from "./tezosToolkit";
|
|
6
|
+
import { createMockSigner } from "../utils";
|
|
6
7
|
|
|
7
8
|
export type TransactionFee = {
|
|
8
9
|
fees?: string;
|
|
@@ -37,6 +38,13 @@ export async function craftTransaction(
|
|
|
37
38
|
|
|
38
39
|
const tezosToolkit = getTezosToolkit();
|
|
39
40
|
|
|
41
|
+
// Configure signer for Taquito operations (same as in estimateFees)
|
|
42
|
+
if (publicKey) {
|
|
43
|
+
tezosToolkit.setProvider({
|
|
44
|
+
signer: createMockSigner(publicKey.publicKeyHash, publicKey.publicKey),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
40
48
|
const sourceData = await tezosToolkit.rpc.getContract(address);
|
|
41
49
|
const counter = account.counter ?? Number(sourceData.counter);
|
|
42
50
|
|
|
@@ -22,7 +22,10 @@ describe("estimateFees", () => {
|
|
|
22
22
|
},
|
|
23
23
|
];
|
|
24
24
|
|
|
25
|
-
it.each(
|
|
25
|
+
it.each([
|
|
26
|
+
[accounts[0], "with xpub"],
|
|
27
|
+
[accounts[1], "without xpub"],
|
|
28
|
+
])("returns correct value %s", async (account, _description) => {
|
|
26
29
|
// Given
|
|
27
30
|
const transaction = {
|
|
28
31
|
mode: "send",
|
|
@@ -42,7 +45,10 @@ describe("estimateFees", () => {
|
|
|
42
45
|
});
|
|
43
46
|
});
|
|
44
47
|
|
|
45
|
-
it.each(
|
|
48
|
+
it.each([
|
|
49
|
+
[accounts[0], "with xpub"],
|
|
50
|
+
[accounts[1], "without xpub"],
|
|
51
|
+
])("returns correct value when useAllAmount %s", async (account, _description) => {
|
|
46
52
|
// Given
|
|
47
53
|
const transaction = {
|
|
48
54
|
mode: "send",
|