@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.
Files changed (330) hide show
  1. package/.unimportedrc.json +4 -30
  2. package/CHANGELOG.md +13 -0
  3. package/jest.integ.config.js +1 -0
  4. package/lib/api/index.d.ts.map +1 -1
  5. package/lib/api/index.js +188 -40
  6. package/lib/api/index.js.map +1 -1
  7. package/lib/api/index.test.js +79 -10
  8. package/lib/api/index.test.js.map +1 -1
  9. package/lib/api/types.d.ts +7 -5
  10. package/lib/api/types.d.ts.map +1 -1
  11. package/lib/config.d.ts +4 -3
  12. package/lib/config.d.ts.map +1 -1
  13. package/lib/config.js.map +1 -1
  14. package/lib/index.d.ts +1 -1
  15. package/lib/index.d.ts.map +1 -1
  16. package/lib/index.js +1 -3
  17. package/lib/index.js.map +1 -1
  18. package/lib/logic/craftTransaction.d.ts.map +1 -1
  19. package/lib/logic/craftTransaction.js +7 -0
  20. package/lib/logic/craftTransaction.js.map +1 -1
  21. package/lib/logic/craftTransaction.test.js +1 -0
  22. package/lib/logic/craftTransaction.test.js.map +1 -1
  23. package/lib/logic/estimateFees.d.ts.map +1 -1
  24. package/lib/logic/estimateFees.integ.test.js +8 -2
  25. package/lib/logic/estimateFees.integ.test.js.map +1 -1
  26. package/lib/logic/estimateFees.js +119 -45
  27. package/lib/logic/estimateFees.js.map +1 -1
  28. package/lib/logic/getBalance.js +1 -1
  29. package/lib/logic/getBalance.js.map +1 -1
  30. package/lib/logic/getStakes.d.ts +3 -0
  31. package/lib/logic/getStakes.d.ts.map +1 -0
  32. package/lib/logic/getStakes.js +26 -0
  33. package/lib/logic/getStakes.js.map +1 -0
  34. package/lib/logic/getStakes.test.d.ts +2 -0
  35. package/lib/logic/getStakes.test.d.ts.map +1 -0
  36. package/lib/logic/getStakes.test.js +133 -0
  37. package/lib/logic/getStakes.test.js.map +1 -0
  38. package/lib/logic/index.d.ts +2 -0
  39. package/lib/logic/index.d.ts.map +1 -1
  40. package/lib/logic/index.js +5 -1
  41. package/lib/logic/index.js.map +1 -1
  42. package/lib/logic/listOperations.d.ts.map +1 -1
  43. package/lib/logic/listOperations.js +56 -10
  44. package/lib/logic/listOperations.js.map +1 -1
  45. package/lib/logic/listOperations.test.js +14 -10
  46. package/lib/logic/listOperations.test.js.map +1 -1
  47. package/lib/logic/validateIntent.d.ts +3 -0
  48. package/lib/logic/validateIntent.d.ts.map +1 -0
  49. package/lib/logic/validateIntent.js +179 -0
  50. package/lib/logic/validateIntent.js.map +1 -0
  51. package/lib/logic/validateIntent.test.d.ts +2 -0
  52. package/lib/logic/validateIntent.test.d.ts.map +1 -0
  53. package/lib/logic/validateIntent.test.js +249 -0
  54. package/lib/logic/validateIntent.test.js.map +1 -0
  55. package/{lib-es/bridge → lib}/transaction.d.ts +1 -1
  56. package/lib/transaction.d.ts.map +1 -0
  57. package/lib/{bridge/transaction.js → transaction.js} +3 -3
  58. package/lib/transaction.js.map +1 -0
  59. package/lib/types/bridge.d.ts +3 -0
  60. package/lib/types/bridge.d.ts.map +1 -1
  61. package/lib/types/bridge.fixture.d.ts.map +1 -1
  62. package/lib/types/bridge.fixture.js +1 -0
  63. package/lib/types/bridge.fixture.js.map +1 -1
  64. package/lib/types/bridge.js.map +1 -1
  65. package/lib/utils.d.ts +48 -0
  66. package/lib/utils.d.ts.map +1 -0
  67. package/lib/utils.js +112 -0
  68. package/lib/utils.js.map +1 -0
  69. package/lib-es/api/index.d.ts.map +1 -1
  70. package/lib-es/api/index.js +189 -41
  71. package/lib-es/api/index.js.map +1 -1
  72. package/lib-es/api/index.test.js +79 -10
  73. package/lib-es/api/index.test.js.map +1 -1
  74. package/lib-es/api/types.d.ts +7 -5
  75. package/lib-es/api/types.d.ts.map +1 -1
  76. package/lib-es/config.d.ts +4 -3
  77. package/lib-es/config.d.ts.map +1 -1
  78. package/lib-es/config.js.map +1 -1
  79. package/lib-es/index.d.ts +1 -1
  80. package/lib-es/index.d.ts.map +1 -1
  81. package/lib-es/index.js +1 -1
  82. package/lib-es/index.js.map +1 -1
  83. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  84. package/lib-es/logic/craftTransaction.js +7 -0
  85. package/lib-es/logic/craftTransaction.js.map +1 -1
  86. package/lib-es/logic/craftTransaction.test.js +1 -0
  87. package/lib-es/logic/craftTransaction.test.js.map +1 -1
  88. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  89. package/lib-es/logic/estimateFees.integ.test.js +8 -2
  90. package/lib-es/logic/estimateFees.integ.test.js.map +1 -1
  91. package/lib-es/logic/estimateFees.js +119 -45
  92. package/lib-es/logic/estimateFees.js.map +1 -1
  93. package/lib-es/logic/getBalance.js +1 -1
  94. package/lib-es/logic/getBalance.js.map +1 -1
  95. package/lib-es/logic/getStakes.d.ts +3 -0
  96. package/lib-es/logic/getStakes.d.ts.map +1 -0
  97. package/lib-es/logic/getStakes.js +20 -0
  98. package/lib-es/logic/getStakes.js.map +1 -0
  99. package/lib-es/logic/getStakes.test.d.ts +2 -0
  100. package/lib-es/logic/getStakes.test.d.ts.map +1 -0
  101. package/lib-es/logic/getStakes.test.js +128 -0
  102. package/lib-es/logic/getStakes.test.js.map +1 -0
  103. package/lib-es/logic/index.d.ts +2 -0
  104. package/lib-es/logic/index.d.ts.map +1 -1
  105. package/lib-es/logic/index.js +2 -0
  106. package/lib-es/logic/index.js.map +1 -1
  107. package/lib-es/logic/listOperations.d.ts.map +1 -1
  108. package/lib-es/logic/listOperations.js +56 -10
  109. package/lib-es/logic/listOperations.js.map +1 -1
  110. package/lib-es/logic/listOperations.test.js +14 -10
  111. package/lib-es/logic/listOperations.test.js.map +1 -1
  112. package/lib-es/logic/validateIntent.d.ts +3 -0
  113. package/lib-es/logic/validateIntent.d.ts.map +1 -0
  114. package/lib-es/logic/validateIntent.js +173 -0
  115. package/lib-es/logic/validateIntent.js.map +1 -0
  116. package/lib-es/logic/validateIntent.test.d.ts +2 -0
  117. package/lib-es/logic/validateIntent.test.d.ts.map +1 -0
  118. package/lib-es/logic/validateIntent.test.js +221 -0
  119. package/lib-es/logic/validateIntent.test.js.map +1 -0
  120. package/{lib/bridge → lib-es}/transaction.d.ts +1 -1
  121. package/lib-es/transaction.d.ts.map +1 -0
  122. package/lib-es/{bridge/transaction.js → transaction.js} +3 -3
  123. package/lib-es/transaction.js.map +1 -0
  124. package/lib-es/types/bridge.d.ts +3 -0
  125. package/lib-es/types/bridge.d.ts.map +1 -1
  126. package/lib-es/types/bridge.fixture.d.ts.map +1 -1
  127. package/lib-es/types/bridge.fixture.js +1 -0
  128. package/lib-es/types/bridge.fixture.js.map +1 -1
  129. package/lib-es/types/bridge.js.map +1 -1
  130. package/lib-es/utils.d.ts +48 -0
  131. package/lib-es/utils.d.ts.map +1 -0
  132. package/lib-es/utils.js +105 -0
  133. package/lib-es/utils.js.map +1 -0
  134. package/package.json +9 -12
  135. package/src/api/index.test.ts +87 -15
  136. package/src/api/index.ts +204 -55
  137. package/src/api/types.ts +11 -6
  138. package/src/config.ts +9 -2
  139. package/src/index.ts +1 -2
  140. package/src/logic/craftTransaction.test.ts +1 -0
  141. package/src/logic/craftTransaction.ts +8 -0
  142. package/src/logic/estimateFees.integ.test.ts +8 -2
  143. package/src/logic/estimateFees.ts +140 -49
  144. package/src/logic/getBalance.ts +1 -1
  145. package/src/logic/getStakes.test.ts +145 -0
  146. package/src/logic/getStakes.ts +20 -0
  147. package/src/logic/index.ts +2 -0
  148. package/src/logic/listOperations.test.ts +64 -54
  149. package/src/logic/listOperations.ts +57 -9
  150. package/src/logic/validateIntent.test.ts +262 -0
  151. package/src/logic/validateIntent.ts +207 -0
  152. package/src/{bridge/transaction.ts → transaction.ts} +4 -4
  153. package/src/types/bridge.fixture.ts +1 -0
  154. package/src/types/bridge.ts +6 -1
  155. package/src/utils.ts +115 -0
  156. package/lib/bridge/broadcast.d.ts +0 -4
  157. package/lib/bridge/broadcast.d.ts.map +0 -1
  158. package/lib/bridge/broadcast.js +0 -11
  159. package/lib/bridge/broadcast.js.map +0 -1
  160. package/lib/bridge/broadcast.test.d.ts +0 -2
  161. package/lib/bridge/broadcast.test.d.ts.map +0 -1
  162. package/lib/bridge/broadcast.test.js +0 -36
  163. package/lib/bridge/broadcast.test.js.map +0 -1
  164. package/lib/bridge/buildOptimisticOperation.d.ts +0 -4
  165. package/lib/bridge/buildOptimisticOperation.d.ts.map +0 -1
  166. package/lib/bridge/buildOptimisticOperation.js +0 -28
  167. package/lib/bridge/buildOptimisticOperation.js.map +0 -1
  168. package/lib/bridge/createTransaction.d.ts +0 -4
  169. package/lib/bridge/createTransaction.d.ts.map +0 -1
  170. package/lib/bridge/createTransaction.js +0 -24
  171. package/lib/bridge/createTransaction.js.map +0 -1
  172. package/lib/bridge/estimateMaxSpendable.d.ts +0 -5
  173. package/lib/bridge/estimateMaxSpendable.d.ts.map +0 -1
  174. package/lib/bridge/estimateMaxSpendable.js +0 -30
  175. package/lib/bridge/estimateMaxSpendable.js.map +0 -1
  176. package/lib/bridge/getFeesForTransaction.d.ts +0 -21
  177. package/lib/bridge/getFeesForTransaction.d.ts.map +0 -1
  178. package/lib/bridge/getFeesForTransaction.js +0 -39
  179. package/lib/bridge/getFeesForTransaction.js.map +0 -1
  180. package/lib/bridge/getTransactionStatus.d.ts +0 -4
  181. package/lib/bridge/getTransactionStatus.d.ts.map +0 -1
  182. package/lib/bridge/getTransactionStatus.js +0 -108
  183. package/lib/bridge/getTransactionStatus.js.map +0 -1
  184. package/lib/bridge/getTransactionStatus.test.d.ts +0 -2
  185. package/lib/bridge/getTransactionStatus.test.d.ts.map +0 -1
  186. package/lib/bridge/getTransactionStatus.test.js +0 -107
  187. package/lib/bridge/getTransactionStatus.test.js.map +0 -1
  188. package/lib/bridge/index.d.ts +0 -10
  189. package/lib/bridge/index.d.ts.map +0 -1
  190. package/lib/bridge/index.js +0 -59
  191. package/lib/bridge/index.js.map +0 -1
  192. package/lib/bridge/logic.d.ts +0 -10
  193. package/lib/bridge/logic.d.ts.map +0 -1
  194. package/lib/bridge/logic.js +0 -155
  195. package/lib/bridge/logic.js.map +0 -1
  196. package/lib/bridge/preload.d.ts +0 -9
  197. package/lib/bridge/preload.d.ts.map +0 -1
  198. package/lib/bridge/preload.js +0 -23
  199. package/lib/bridge/preload.js.map +0 -1
  200. package/lib/bridge/prepareTransaction.d.ts +0 -5
  201. package/lib/bridge/prepareTransaction.d.ts.map +0 -1
  202. package/lib/bridge/prepareTransaction.integ.test.d.ts +0 -2
  203. package/lib/bridge/prepareTransaction.integ.test.d.ts.map +0 -1
  204. package/lib/bridge/prepareTransaction.integ.test.js +0 -34
  205. package/lib/bridge/prepareTransaction.integ.test.js.map +0 -1
  206. package/lib/bridge/prepareTransaction.js +0 -57
  207. package/lib/bridge/prepareTransaction.js.map +0 -1
  208. package/lib/bridge/prepareTransaction.test.d.ts +0 -2
  209. package/lib/bridge/prepareTransaction.test.d.ts.map +0 -1
  210. package/lib/bridge/prepareTransaction.test.js +0 -178
  211. package/lib/bridge/prepareTransaction.test.js.map +0 -1
  212. package/lib/bridge/serialization.d.ts +0 -7
  213. package/lib/bridge/serialization.d.ts.map +0 -1
  214. package/lib/bridge/serialization.js +0 -26
  215. package/lib/bridge/serialization.js.map +0 -1
  216. package/lib/bridge/signOperation.d.ts +0 -16
  217. package/lib/bridge/signOperation.d.ts.map +0 -1
  218. package/lib/bridge/signOperation.js +0 -88
  219. package/lib/bridge/signOperation.js.map +0 -1
  220. package/lib/bridge/signOperation.test.d.ts +0 -2
  221. package/lib/bridge/signOperation.test.d.ts.map +0 -1
  222. package/lib/bridge/signOperation.test.js +0 -283
  223. package/lib/bridge/signOperation.test.js.map +0 -1
  224. package/lib/bridge/synchronization.d.ts +0 -5
  225. package/lib/bridge/synchronization.d.ts.map +0 -1
  226. package/lib/bridge/synchronization.integ.test.d.ts +0 -2
  227. package/lib/bridge/synchronization.integ.test.d.ts.map +0 -1
  228. package/lib/bridge/synchronization.integ.test.js +0 -32
  229. package/lib/bridge/synchronization.integ.test.js.map +0 -1
  230. package/lib/bridge/synchronization.js +0 -100
  231. package/lib/bridge/synchronization.js.map +0 -1
  232. package/lib/bridge/transaction.d.ts.map +0 -1
  233. package/lib/bridge/transaction.js.map +0 -1
  234. package/lib-es/bridge/broadcast.d.ts +0 -4
  235. package/lib-es/bridge/broadcast.d.ts.map +0 -1
  236. package/lib-es/bridge/broadcast.js +0 -7
  237. package/lib-es/bridge/broadcast.js.map +0 -1
  238. package/lib-es/bridge/broadcast.test.d.ts +0 -2
  239. package/lib-es/bridge/broadcast.test.d.ts.map +0 -1
  240. package/lib-es/bridge/broadcast.test.js +0 -31
  241. package/lib-es/bridge/broadcast.test.js.map +0 -1
  242. package/lib-es/bridge/buildOptimisticOperation.d.ts +0 -4
  243. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +0 -1
  244. package/lib-es/bridge/buildOptimisticOperation.js +0 -21
  245. package/lib-es/bridge/buildOptimisticOperation.js.map +0 -1
  246. package/lib-es/bridge/createTransaction.d.ts +0 -4
  247. package/lib-es/bridge/createTransaction.d.ts.map +0 -1
  248. package/lib-es/bridge/createTransaction.js +0 -17
  249. package/lib-es/bridge/createTransaction.js.map +0 -1
  250. package/lib-es/bridge/estimateMaxSpendable.d.ts +0 -5
  251. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +0 -1
  252. package/lib-es/bridge/estimateMaxSpendable.js +0 -23
  253. package/lib-es/bridge/estimateMaxSpendable.js.map +0 -1
  254. package/lib-es/bridge/getFeesForTransaction.d.ts +0 -21
  255. package/lib-es/bridge/getFeesForTransaction.d.ts.map +0 -1
  256. package/lib-es/bridge/getFeesForTransaction.js +0 -33
  257. package/lib-es/bridge/getFeesForTransaction.js.map +0 -1
  258. package/lib-es/bridge/getTransactionStatus.d.ts +0 -4
  259. package/lib-es/bridge/getTransactionStatus.d.ts.map +0 -1
  260. package/lib-es/bridge/getTransactionStatus.js +0 -101
  261. package/lib-es/bridge/getTransactionStatus.js.map +0 -1
  262. package/lib-es/bridge/getTransactionStatus.test.d.ts +0 -2
  263. package/lib-es/bridge/getTransactionStatus.test.d.ts.map +0 -1
  264. package/lib-es/bridge/getTransactionStatus.test.js +0 -102
  265. package/lib-es/bridge/getTransactionStatus.test.js.map +0 -1
  266. package/lib-es/bridge/index.d.ts +0 -10
  267. package/lib-es/bridge/index.d.ts.map +0 -1
  268. package/lib-es/bridge/index.js +0 -53
  269. package/lib-es/bridge/index.js.map +0 -1
  270. package/lib-es/bridge/logic.d.ts +0 -10
  271. package/lib-es/bridge/logic.d.ts.map +0 -1
  272. package/lib-es/bridge/logic.js +0 -145
  273. package/lib-es/bridge/logic.js.map +0 -1
  274. package/lib-es/bridge/preload.d.ts +0 -9
  275. package/lib-es/bridge/preload.d.ts.map +0 -1
  276. package/lib-es/bridge/preload.js +0 -17
  277. package/lib-es/bridge/preload.js.map +0 -1
  278. package/lib-es/bridge/prepareTransaction.d.ts +0 -5
  279. package/lib-es/bridge/prepareTransaction.d.ts.map +0 -1
  280. package/lib-es/bridge/prepareTransaction.integ.test.d.ts +0 -2
  281. package/lib-es/bridge/prepareTransaction.integ.test.d.ts.map +0 -1
  282. package/lib-es/bridge/prepareTransaction.integ.test.js +0 -29
  283. package/lib-es/bridge/prepareTransaction.integ.test.js.map +0 -1
  284. package/lib-es/bridge/prepareTransaction.js +0 -50
  285. package/lib-es/bridge/prepareTransaction.js.map +0 -1
  286. package/lib-es/bridge/prepareTransaction.test.d.ts +0 -2
  287. package/lib-es/bridge/prepareTransaction.test.d.ts.map +0 -1
  288. package/lib-es/bridge/prepareTransaction.test.js +0 -173
  289. package/lib-es/bridge/prepareTransaction.test.js.map +0 -1
  290. package/lib-es/bridge/serialization.d.ts +0 -7
  291. package/lib-es/bridge/serialization.d.ts.map +0 -1
  292. package/lib-es/bridge/serialization.js +0 -20
  293. package/lib-es/bridge/serialization.js.map +0 -1
  294. package/lib-es/bridge/signOperation.d.ts +0 -16
  295. package/lib-es/bridge/signOperation.d.ts.map +0 -1
  296. package/lib-es/bridge/signOperation.js +0 -83
  297. package/lib-es/bridge/signOperation.js.map +0 -1
  298. package/lib-es/bridge/signOperation.test.d.ts +0 -2
  299. package/lib-es/bridge/signOperation.test.d.ts.map +0 -1
  300. package/lib-es/bridge/signOperation.test.js +0 -255
  301. package/lib-es/bridge/signOperation.test.js.map +0 -1
  302. package/lib-es/bridge/synchronization.d.ts +0 -5
  303. package/lib-es/bridge/synchronization.d.ts.map +0 -1
  304. package/lib-es/bridge/synchronization.integ.test.d.ts +0 -2
  305. package/lib-es/bridge/synchronization.integ.test.d.ts.map +0 -1
  306. package/lib-es/bridge/synchronization.integ.test.js +0 -27
  307. package/lib-es/bridge/synchronization.integ.test.js.map +0 -1
  308. package/lib-es/bridge/synchronization.js +0 -70
  309. package/lib-es/bridge/synchronization.js.map +0 -1
  310. package/lib-es/bridge/transaction.d.ts.map +0 -1
  311. package/lib-es/bridge/transaction.js.map +0 -1
  312. package/src/bridge/broadcast.test.ts +0 -36
  313. package/src/bridge/broadcast.ts +0 -13
  314. package/src/bridge/buildOptimisticOperation.ts +0 -28
  315. package/src/bridge/createTransaction.ts +0 -19
  316. package/src/bridge/estimateMaxSpendable.ts +0 -37
  317. package/src/bridge/getFeesForTransaction.ts +0 -49
  318. package/src/bridge/getTransactionStatus.test.ts +0 -124
  319. package/src/bridge/getTransactionStatus.ts +0 -123
  320. package/src/bridge/index.ts +0 -74
  321. package/src/bridge/logic.ts +0 -171
  322. package/src/bridge/preload.ts +0 -18
  323. package/src/bridge/prepareTransaction.integ.test.ts +0 -35
  324. package/src/bridge/prepareTransaction.test.ts +0 -205
  325. package/src/bridge/prepareTransaction.ts +0 -69
  326. package/src/bridge/serialization.ts +0 -27
  327. package/src/bridge/signOperation.test.ts +0 -284
  328. package/src/bridge/signOperation.ts +0 -130
  329. package/src/bridge/synchronization.integ.test.ts +0 -33
  330. package/src/bridge/synchronization.ts +0 -100
@@ -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) : BigInt(-1);
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
+ }
@@ -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
- ])("should return %s operation with proper recipient list", async (_label, operation) => {
90
- // Given
91
- mockNetworkGetTransactions.mockResolvedValue([operation]);
92
- // When
93
- const [results] = await listOperations("any address", options);
94
- // Then
95
- expect(results).toEqual([
96
- {
97
- id: `${operation.hash}-${operation.id}`,
98
- asset: { type: "native" },
99
- details: {
100
- counter: operation.counter,
101
- gasLimit: operation.gasLimit,
102
- storageLimit: operation.storageLimit,
103
- },
104
- senders: [someSenderAddress],
105
- recipients: [someDestinationAddress],
106
- tx: {
107
- block: {
108
- hash: operation.block,
109
- height: operation.level,
110
- time: new Date(operation.timestamp),
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
- date: new Date(operation.timestamp),
113
- hash: operation.hash,
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
- type: operation.type,
121
- value: BigInt(operation.amount),
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
- ])("should return %s operation with expected details", async (_label, operation) => {
150
- // Given
151
- mockNetworkGetTransactions.mockResolvedValue([operation]);
152
- // When
153
- const [results, _] = await listOperations("any address", options);
154
- // Then
155
- expect(results.length).toEqual(1);
156
- expect(results[0].details).toEqual({
157
- counter: 65214462,
158
- gasLimit: 4,
159
- storageLimit: 5,
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
- const lastOperation = operations.slice(-1)[0];
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 = operations
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, type, id } = operation;
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) ? BigInt(0) : BigInt(operation.amount);
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: 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
  }