@ledgerhq/coin-tezos 6.5.0 → 6.6.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 +13 -0
- package/jest.integ.config.js +1 -0
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +188 -40
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +79 -10
- package/lib/api/index.test.js.map +1 -1
- package/lib/api/types.d.ts +7 -5
- 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 +56 -10
- 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 +249 -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 +48 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +112 -0
- package/lib/utils.js.map +1 -0
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +189 -41
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +79 -10
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/api/types.d.ts +7 -5
- 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 +56 -10
- 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 +221 -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 +48 -0
- package/lib-es/utils.d.ts.map +1 -0
- package/lib-es/utils.js +105 -0
- package/lib-es/utils.js.map +1 -0
- package/package.json +9 -12
- package/src/api/index.test.ts +87 -15
- package/src/api/index.ts +204 -55
- package/src/api/types.ts +11 -6
- 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 +57 -9
- package/src/logic/validateIntent.test.ts +262 -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 +115 -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/logic/getBalance.ts
CHANGED
|
@@ -6,5 +6,5 @@ import api from "../network/tzkt";
|
|
|
6
6
|
*/
|
|
7
7
|
export async function getBalance(address: string): Promise<bigint> {
|
|
8
8
|
const apiAccount = await api.getAccountByAddress(address);
|
|
9
|
-
return apiAccount.type === "user" ? BigInt(apiAccount.balance) :
|
|
9
|
+
return apiAccount.type === "user" ? BigInt(apiAccount.balance) : -1n;
|
|
10
10
|
}
|
|
@@ -0,0 +1,145 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
package/src/logic/index.ts
CHANGED
|
@@ -7,3 +7,5 @@ export { estimateFees } from "./estimateFees";
|
|
|
7
7
|
export { getBalance } from "./getBalance";
|
|
8
8
|
export { lastBlock } from "./lastBlock";
|
|
9
9
|
export { listOperations } from "./listOperations";
|
|
10
|
+
export { validateIntent } from "./validateIntent";
|
|
11
|
+
export { getStakes } from "./getStakes";
|
|
@@ -83,45 +83,50 @@ describe("listOperations", () => {
|
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
it.each([
|
|
86
|
-
["undelegate", undelegate],
|
|
87
|
-
["delegate", delegate],
|
|
88
|
-
["transfer", transfer],
|
|
89
|
-
])(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
86
|
+
["undelegate", undelegate, "DELEGATE", "DELEGATE"],
|
|
87
|
+
["delegate", delegate, "UNDELEGATE", "UNDELEGATE"],
|
|
88
|
+
["transfer", transfer, "OUT", undefined],
|
|
89
|
+
])(
|
|
90
|
+
"should return %s operation with proper recipient list",
|
|
91
|
+
async (_label, operation, expectedType, expectedLedgerOpType) => {
|
|
92
|
+
// Given
|
|
93
|
+
mockNetworkGetTransactions.mockResolvedValue([operation]);
|
|
94
|
+
// When
|
|
95
|
+
const [results] = await listOperations("any address", options);
|
|
96
|
+
// Then
|
|
97
|
+
expect(results).toEqual([
|
|
98
|
+
{
|
|
99
|
+
id: `${operation.hash}-${operation.id}`,
|
|
100
|
+
asset: { type: "native" },
|
|
101
|
+
details: {
|
|
102
|
+
counter: operation.counter,
|
|
103
|
+
gasLimit: operation.gasLimit,
|
|
104
|
+
storageLimit: operation.storageLimit,
|
|
105
|
+
status: operation.status,
|
|
106
|
+
ledgerOpType: expectedLedgerOpType,
|
|
107
|
+
},
|
|
108
|
+
senders: [someSenderAddress],
|
|
109
|
+
recipients: [someDestinationAddress],
|
|
110
|
+
tx: {
|
|
111
|
+
block: {
|
|
112
|
+
hash: operation.block,
|
|
113
|
+
height: operation.level,
|
|
114
|
+
time: new Date(operation.timestamp),
|
|
115
|
+
},
|
|
116
|
+
date: new Date(operation.timestamp),
|
|
117
|
+
hash: operation.hash,
|
|
118
|
+
fees: BigInt(
|
|
119
|
+
(operation.allocationFee ?? 0) +
|
|
120
|
+
(operation.bakerFee ?? 0) +
|
|
121
|
+
(operation.storageFee ?? 0),
|
|
122
|
+
),
|
|
111
123
|
},
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
fees: BigInt(
|
|
115
|
-
(operation.allocationFee ?? 0) +
|
|
116
|
-
(operation.bakerFee ?? 0) +
|
|
117
|
-
(operation.storageFee ?? 0),
|
|
118
|
-
),
|
|
124
|
+
type: expectedType,
|
|
125
|
+
value: BigInt(operation.amount),
|
|
119
126
|
},
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
]);
|
|
124
|
-
});
|
|
127
|
+
]);
|
|
128
|
+
},
|
|
129
|
+
);
|
|
125
130
|
|
|
126
131
|
it.each([
|
|
127
132
|
["undelegate", undelegate],
|
|
@@ -142,23 +147,28 @@ describe("listOperations", () => {
|
|
|
142
147
|
);
|
|
143
148
|
|
|
144
149
|
it.each([
|
|
145
|
-
["undelegate", undelegate],
|
|
146
|
-
["delegate", delegate],
|
|
147
|
-
["transfer", transfer],
|
|
148
|
-
["reveal", reveal],
|
|
149
|
-
])(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
150
|
+
["undelegate", undelegate, "DELEGATE"],
|
|
151
|
+
["delegate", delegate, "UNDELEGATE"],
|
|
152
|
+
["transfer", transfer, undefined],
|
|
153
|
+
["reveal", reveal, "REVEAL"],
|
|
154
|
+
])(
|
|
155
|
+
"should return %s operation with expected details",
|
|
156
|
+
async (_label, operation, expectedLedgerOpType) => {
|
|
157
|
+
// Given
|
|
158
|
+
mockNetworkGetTransactions.mockResolvedValue([operation]);
|
|
159
|
+
// When
|
|
160
|
+
const [results, _] = await listOperations("any address", options);
|
|
161
|
+
// Then
|
|
162
|
+
expect(results.length).toEqual(1);
|
|
163
|
+
expect(results[0].details).toEqual({
|
|
164
|
+
counter: 65214462,
|
|
165
|
+
gasLimit: 4,
|
|
166
|
+
storageLimit: 5,
|
|
167
|
+
status: operation.status,
|
|
168
|
+
ledgerOpType: expectedLedgerOpType,
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
);
|
|
162
172
|
|
|
163
173
|
it.each([
|
|
164
174
|
{ ...undelegate, newDelegate: null, prevDelegate: null },
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
isAPITransactionType,
|
|
11
11
|
} from "../network/types";
|
|
12
12
|
import { Operation } from "@ledgerhq/coin-framework/api/types";
|
|
13
|
-
// import { TezosAsset } from "../api/types";
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* Returns list of "Transfer", "Delegate" and "Undelegate" Operations associated to an account.
|
|
@@ -38,11 +37,15 @@ export async function listOperations(
|
|
|
38
37
|
options = { ...options, lastId: JSON.parse(token) };
|
|
39
38
|
}
|
|
40
39
|
const operations = await tzkt.getAccountOperations(address, options);
|
|
41
|
-
|
|
40
|
+
|
|
41
|
+
// Apply limit after fetching since tzkt API might not respect the limit parameter
|
|
42
|
+
const limitedOperations = limit ? operations.slice(0, limit) : operations;
|
|
43
|
+
|
|
44
|
+
const lastOperation = limitedOperations.at(-1);
|
|
42
45
|
// it's important to get the last id from the **unfiltered** operation list
|
|
43
46
|
// otherwise we might miss operations
|
|
44
47
|
const nextToken = lastOperation ? JSON.stringify(lastOperation?.id) : "";
|
|
45
|
-
const filteredOperations =
|
|
48
|
+
const filteredOperations = limitedOperations
|
|
46
49
|
.filter(op => isAPITransactionType(op) || isAPIDelegationType(op) || isAPIRevealType(op))
|
|
47
50
|
.reduce((acc, op) => acc.concat(convertOperation(address, op)), [] as Operation[]);
|
|
48
51
|
const sortedOperations = filteredOperations.sort(
|
|
@@ -51,12 +54,29 @@ export async function listOperations(
|
|
|
51
54
|
return [sortedOperations, nextToken];
|
|
52
55
|
}
|
|
53
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Helper function to get the ledgerOpType for an operation
|
|
59
|
+
*/
|
|
60
|
+
function getLedgerOpType(
|
|
61
|
+
operation: APITransactionType | APIDelegationType | APIRevealType,
|
|
62
|
+
normalizedType: Operation["type"],
|
|
63
|
+
): string | undefined {
|
|
64
|
+
if (isAPIDelegationType(operation)) {
|
|
65
|
+
return operation.newDelegate?.address ? "DELEGATE" : "UNDELEGATE";
|
|
66
|
+
} else if (isAPIRevealType(operation)) {
|
|
67
|
+
return "REVEAL";
|
|
68
|
+
} else if (normalizedType === "FEES") {
|
|
69
|
+
return "FEES";
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
54
74
|
// note that "initiator" of APITransactionType is never used in the conversion
|
|
55
75
|
function convertOperation(
|
|
56
76
|
address: string,
|
|
57
77
|
operation: APITransactionType | APIDelegationType | APIRevealType,
|
|
58
78
|
): Operation {
|
|
59
|
-
const { hash, sender,
|
|
79
|
+
const { hash, sender, id } = operation;
|
|
60
80
|
|
|
61
81
|
let targetAddress = undefined;
|
|
62
82
|
if (isAPITransactionType(operation)) {
|
|
@@ -66,22 +86,48 @@ function convertOperation(
|
|
|
66
86
|
targetAddress = operation?.newDelegate?.address || operation?.prevDelegate?.address;
|
|
67
87
|
}
|
|
68
88
|
|
|
69
|
-
const recipients = [];
|
|
89
|
+
const recipients = targetAddress ? [targetAddress] : [];
|
|
70
90
|
if (!targetAddress) {
|
|
71
91
|
log("coin:tezos", "(logic/operations): No target address found for operation", operation);
|
|
72
|
-
} else {
|
|
73
|
-
recipients.push(targetAddress);
|
|
74
92
|
}
|
|
75
93
|
|
|
76
94
|
const senders = sender?.address ? [sender.address] : [];
|
|
77
95
|
|
|
78
|
-
const amount = isAPIRevealType(operation) ?
|
|
96
|
+
const amount = isAPIRevealType(operation) ? 0n : BigInt(operation.amount);
|
|
79
97
|
|
|
80
98
|
const fee =
|
|
81
99
|
BigInt(operation.storageFee ?? 0) +
|
|
82
100
|
BigInt(operation.bakerFee ?? 0) +
|
|
83
101
|
BigInt(operation.allocationFee ?? 0);
|
|
84
102
|
|
|
103
|
+
// Determine operation type inline
|
|
104
|
+
let normalizedType: Operation["type"];
|
|
105
|
+
if (isAPIDelegationType(operation)) {
|
|
106
|
+
normalizedType = operation.newDelegate?.address ? "DELEGATE" : "UNDELEGATE";
|
|
107
|
+
} else if (isAPITransactionType(operation)) {
|
|
108
|
+
const isOut = sender?.address === address;
|
|
109
|
+
const isIn = targetAddress === address;
|
|
110
|
+
|
|
111
|
+
if ((isOut && isIn) || amount === 0n) {
|
|
112
|
+
normalizedType = "FEES";
|
|
113
|
+
} else if (isOut) {
|
|
114
|
+
normalizedType = "OUT";
|
|
115
|
+
} else if (isIn) {
|
|
116
|
+
normalizedType = "IN";
|
|
117
|
+
} else {
|
|
118
|
+
normalizedType = "OUT"; // fallback
|
|
119
|
+
}
|
|
120
|
+
} else if (isAPIRevealType(operation)) {
|
|
121
|
+
normalizedType = "REVEAL";
|
|
122
|
+
} else {
|
|
123
|
+
// fallback for unknown types
|
|
124
|
+
log("coin:tezos", "(logic/operations): Unknown operation type, defaulting to OUT");
|
|
125
|
+
normalizedType = "OUT";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Tezos uses "applied" for every sucess operation (something else=failed )
|
|
129
|
+
const hasFailed = operation.status && operation.status !== "applied";
|
|
130
|
+
|
|
85
131
|
return {
|
|
86
132
|
id: `${hash ?? ""}-${id}`,
|
|
87
133
|
asset: { type: "native" },
|
|
@@ -97,7 +143,7 @@ function convertOperation(
|
|
|
97
143
|
},
|
|
98
144
|
date: new Date(operation.timestamp),
|
|
99
145
|
},
|
|
100
|
-
type:
|
|
146
|
+
type: normalizedType,
|
|
101
147
|
value: amount,
|
|
102
148
|
senders: senders,
|
|
103
149
|
recipients: recipients,
|
|
@@ -105,6 +151,8 @@ function convertOperation(
|
|
|
105
151
|
counter: operation.counter,
|
|
106
152
|
gasLimit: operation.gasLimit,
|
|
107
153
|
storageLimit: operation.storageLimit,
|
|
154
|
+
status: hasFailed ? "failed" : operation.status,
|
|
155
|
+
ledgerOpType: getLedgerOpType(operation, normalizedType),
|
|
108
156
|
},
|
|
109
157
|
};
|
|
110
158
|
}
|