@ledgerhq/coin-solana 0.7.0-next.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 (521) hide show
  1. package/.eslintrc.js +20 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.unimportedrc.json +16 -0
  4. package/CHANGELOG.md +27 -0
  5. package/LICENSE.txt +21 -0
  6. package/jest.config.js +8 -0
  7. package/lib/api/cached.d.ts +3 -0
  8. package/lib/api/cached.d.ts.map +1 -0
  9. package/lib/api/cached.js +41 -0
  10. package/lib/api/cached.js.map +1 -0
  11. package/lib/api/chain/account/index.d.ts +2 -0
  12. package/lib/api/chain/account/index.d.ts.map +1 -0
  13. package/lib/api/chain/account/index.js +8 -0
  14. package/lib/api/chain/account/index.js.map +1 -0
  15. package/lib/api/chain/account/parser.d.ts +10 -0
  16. package/lib/api/chain/account/parser.d.ts.map +1 -0
  17. package/lib/api/chain/account/parser.js +56 -0
  18. package/lib/api/chain/account/parser.js.map +1 -0
  19. package/lib/api/chain/account/stake.d.ts +237 -0
  20. package/lib/api/chain/account/stake.d.ts.map +1 -0
  21. package/lib/api/chain/account/stake.js +38 -0
  22. package/lib/api/chain/account/stake.js.map +1 -0
  23. package/lib/api/chain/account/token.d.ts +116 -0
  24. package/lib/api/chain/account/token.d.ts.map +1 -0
  25. package/lib/api/chain/account/token.js +42 -0
  26. package/lib/api/chain/account/token.js.map +1 -0
  27. package/lib/api/chain/account/vote.d.ts +252 -0
  28. package/lib/api/chain/account/vote.d.ts.map +1 -0
  29. package/lib/api/chain/account/vote.js +44 -0
  30. package/lib/api/chain/account/vote.js.map +1 -0
  31. package/lib/api/chain/index.d.ts +29 -0
  32. package/lib/api/chain/index.d.ts.map +1 -0
  33. package/lib/api/chain/index.js +96 -0
  34. package/lib/api/chain/index.js.map +1 -0
  35. package/lib/api/chain/instruction/associated-token-account/index.d.ts +15 -0
  36. package/lib/api/chain/instruction/associated-token-account/index.d.ts.map +1 -0
  37. package/lib/api/chain/instruction/associated-token-account/index.js +21 -0
  38. package/lib/api/chain/instruction/associated-token-account/index.js.map +1 -0
  39. package/lib/api/chain/instruction/associated-token-account/types.d.ts +30 -0
  40. package/lib/api/chain/instruction/associated-token-account/types.d.ts.map +1 -0
  41. package/lib/api/chain/instruction/associated-token-account/types.js +19 -0
  42. package/lib/api/chain/instruction/associated-token-account/types.js.map +1 -0
  43. package/lib/api/chain/instruction/memo/index.d.ts +15 -0
  44. package/lib/api/chain/instruction/memo/index.d.ts.map +1 -0
  45. package/lib/api/chain/instruction/memo/index.js +14 -0
  46. package/lib/api/chain/instruction/memo/index.js.map +1 -0
  47. package/lib/api/chain/instruction/memo/types.d.ts +21 -0
  48. package/lib/api/chain/instruction/memo/types.d.ts.map +1 -0
  49. package/lib/api/chain/instruction/memo/types.js +16 -0
  50. package/lib/api/chain/instruction/memo/types.js.map +1 -0
  51. package/lib/api/chain/instruction/stake/index.d.ts +15 -0
  52. package/lib/api/chain/instruction/stake/index.d.ts.map +1 -0
  53. package/lib/api/chain/instruction/stake/index.js +20 -0
  54. package/lib/api/chain/instruction/stake/index.js.map +1 -0
  55. package/lib/api/chain/instruction/stake/types.d.ts +215 -0
  56. package/lib/api/chain/instruction/stake/types.d.ts.map +1 -0
  57. package/lib/api/chain/instruction/stake/types.js +80 -0
  58. package/lib/api/chain/instruction/stake/types.js.map +1 -0
  59. package/lib/api/chain/instruction/system/index.d.ts +15 -0
  60. package/lib/api/chain/instruction/system/index.d.ts.map +1 -0
  61. package/lib/api/chain/instruction/system/index.js +20 -0
  62. package/lib/api/chain/instruction/system/index.js.map +1 -0
  63. package/lib/api/chain/instruction/system/types.d.ts +298 -0
  64. package/lib/api/chain/instruction/system/types.d.ts.map +1 -0
  65. package/lib/api/chain/instruction/system/types.js +117 -0
  66. package/lib/api/chain/instruction/system/types.js.map +1 -0
  67. package/lib/api/chain/instruction/token/index.d.ts +15 -0
  68. package/lib/api/chain/instruction/token/index.d.ts.map +1 -0
  69. package/lib/api/chain/instruction/token/index.js +20 -0
  70. package/lib/api/chain/instruction/token/index.js.map +1 -0
  71. package/lib/api/chain/instruction/token/types.d.ts +497 -0
  72. package/lib/api/chain/instruction/token/types.d.ts.map +1 -0
  73. package/lib/api/chain/instruction/token/types.js +200 -0
  74. package/lib/api/chain/instruction/token/types.js.map +1 -0
  75. package/lib/api/chain/program/constants.d.ts +11 -0
  76. package/lib/api/chain/program/constants.d.ts.map +1 -0
  77. package/lib/api/chain/program/constants.js +14 -0
  78. package/lib/api/chain/program/constants.js.map +1 -0
  79. package/lib/api/chain/program/index.d.ts +2 -0
  80. package/lib/api/chain/program/index.d.ts.map +1 -0
  81. package/lib/api/chain/program/index.js +7 -0
  82. package/lib/api/chain/program/index.js.map +1 -0
  83. package/lib/api/chain/program/parser.d.ts +35 -0
  84. package/lib/api/chain/program/parser.d.ts.map +1 -0
  85. package/lib/api/chain/program/parser.js +66 -0
  86. package/lib/api/chain/program/parser.js.map +1 -0
  87. package/lib/api/chain/validators/bignum.d.ts +3 -0
  88. package/lib/api/chain/validators/bignum.d.ts.map +1 -0
  89. package/lib/api/chain/validators/bignum.js +11 -0
  90. package/lib/api/chain/validators/bignum.js.map +1 -0
  91. package/lib/api/chain/validators/index.d.ts +10 -0
  92. package/lib/api/chain/validators/index.d.ts.map +1 -0
  93. package/lib/api/chain/validators/index.js +10 -0
  94. package/lib/api/chain/validators/index.js.map +1 -0
  95. package/lib/api/chain/validators/pubkey.d.ts +3 -0
  96. package/lib/api/chain/validators/pubkey.d.ts.map +1 -0
  97. package/lib/api/chain/validators/pubkey.js +7 -0
  98. package/lib/api/chain/validators/pubkey.js.map +1 -0
  99. package/lib/api/chain/web3.d.ts +43 -0
  100. package/lib/api/chain/web3.d.ts.map +1 -0
  101. package/lib/api/chain/web3.js +272 -0
  102. package/lib/api/chain/web3.js.map +1 -0
  103. package/lib/api/index.d.ts +5 -0
  104. package/lib/api/index.d.ts.map +1 -0
  105. package/lib/api/index.js +25 -0
  106. package/lib/api/index.js.map +1 -0
  107. package/lib/api/logged.d.ts +3 -0
  108. package/lib/api/logged.d.ts.map +1 -0
  109. package/lib/api/logged.js +69 -0
  110. package/lib/api/logged.js.map +1 -0
  111. package/lib/api/queued.d.ts +3 -0
  112. package/lib/api/queued.d.ts.map +1 -0
  113. package/lib/api/queued.js +27 -0
  114. package/lib/api/queued.js.map +1 -0
  115. package/lib/api/traced.d.ts +3 -0
  116. package/lib/api/traced.d.ts.map +1 -0
  117. package/lib/api/traced.js +80 -0
  118. package/lib/api/traced.js.map +1 -0
  119. package/lib/bridge/bridge.d.ts +15 -0
  120. package/lib/bridge/bridge.d.ts.map +1 -0
  121. package/lib/bridge/bridge.js +134 -0
  122. package/lib/bridge/bridge.js.map +1 -0
  123. package/lib/bridge/js.d.ts +7 -0
  124. package/lib/bridge/js.d.ts.map +1 -0
  125. package/lib/bridge/js.js +28 -0
  126. package/lib/bridge/js.js.map +1 -0
  127. package/lib/bridge.integration.test.d.ts +4 -0
  128. package/lib/bridge.integration.test.d.ts.map +1 -0
  129. package/lib/bridge.integration.test.js +988 -0
  130. package/lib/bridge.integration.test.js.map +1 -0
  131. package/lib/broadcast.d.ts +7 -0
  132. package/lib/broadcast.d.ts.map +1 -0
  133. package/lib/broadcast.js +37 -0
  134. package/lib/broadcast.js.map +1 -0
  135. package/lib/buildTransaction.d.ts +5 -0
  136. package/lib/buildTransaction.d.ts.map +1 -0
  137. package/lib/buildTransaction.js +67 -0
  138. package/lib/buildTransaction.js.map +1 -0
  139. package/lib/cli-transaction.d.ts +19 -0
  140. package/lib/cli-transaction.d.ts.map +1 -0
  141. package/lib/cli-transaction.js +196 -0
  142. package/lib/cli-transaction.js.map +1 -0
  143. package/lib/createTransaction.d.ts +5 -0
  144. package/lib/createTransaction.d.ts.map +1 -0
  145. package/lib/createTransaction.js +19 -0
  146. package/lib/createTransaction.js.map +1 -0
  147. package/lib/datasets/solana.scanAccounts.1.d.ts +6 -0
  148. package/lib/datasets/solana.scanAccounts.1.d.ts.map +1 -0
  149. package/lib/datasets/solana.scanAccounts.1.js +12 -0
  150. package/lib/datasets/solana.scanAccounts.1.js.map +1 -0
  151. package/lib/deviceTransactionConfig.d.ts +10 -0
  152. package/lib/deviceTransactionConfig.d.ts.map +1 -0
  153. package/lib/deviceTransactionConfig.js +228 -0
  154. package/lib/deviceTransactionConfig.js.map +1 -0
  155. package/lib/errors.d.ts +61 -0
  156. package/lib/errors.d.ts.map +1 -0
  157. package/lib/errors.js +25 -0
  158. package/lib/errors.js.map +1 -0
  159. package/lib/estimateMaxSpendable.d.ts +11 -0
  160. package/lib/estimateMaxSpendable.d.ts.map +1 -0
  161. package/lib/estimateMaxSpendable.js +63 -0
  162. package/lib/estimateMaxSpendable.js.map +1 -0
  163. package/lib/getTransactionStatus.d.ts +5 -0
  164. package/lib/getTransactionStatus.d.ts.map +1 -0
  165. package/lib/getTransactionStatus.js +73 -0
  166. package/lib/getTransactionStatus.js.map +1 -0
  167. package/lib/hw-getAddress.d.ts +6 -0
  168. package/lib/hw-getAddress.d.ts.map +1 -0
  169. package/lib/hw-getAddress.js +28 -0
  170. package/lib/hw-getAddress.js.map +1 -0
  171. package/lib/logic.d.ts +29 -0
  172. package/lib/logic.d.ts.map +1 -0
  173. package/lib/logic.js +102 -0
  174. package/lib/logic.js.map +1 -0
  175. package/lib/preload-data.d.ts +7 -0
  176. package/lib/preload-data.d.ts.map +1 -0
  177. package/lib/preload-data.js +45 -0
  178. package/lib/preload-data.js.map +1 -0
  179. package/lib/preload.d.ts +7 -0
  180. package/lib/preload.d.ts.map +1 -0
  181. package/lib/preload.js +67 -0
  182. package/lib/preload.js.map +1 -0
  183. package/lib/preload.test.d.ts +2 -0
  184. package/lib/preload.test.d.ts.map +1 -0
  185. package/lib/preload.test.js +9 -0
  186. package/lib/preload.test.js.map +1 -0
  187. package/lib/prepareTransaction.d.ts +5 -0
  188. package/lib/prepareTransaction.d.ts.map +1 -0
  189. package/lib/prepareTransaction.js +500 -0
  190. package/lib/prepareTransaction.js.map +1 -0
  191. package/lib/serialization.d.ts +9 -0
  192. package/lib/serialization.d.ts.map +1 -0
  193. package/lib/serialization.js +69 -0
  194. package/lib/serialization.js.map +1 -0
  195. package/lib/signOperation.d.ts +7 -0
  196. package/lib/signOperation.d.ts.map +1 -0
  197. package/lib/signOperation.js +153 -0
  198. package/lib/signOperation.js.map +1 -0
  199. package/lib/signer.d.ts +11 -0
  200. package/lib/signer.d.ts.map +1 -0
  201. package/lib/signer.js +3 -0
  202. package/lib/signer.js.map +1 -0
  203. package/lib/specs.d.ts +7 -0
  204. package/lib/specs.d.ts.map +1 -0
  205. package/lib/specs.js +409 -0
  206. package/lib/specs.js.map +1 -0
  207. package/lib/speculos-deviceActions.d.ts +8 -0
  208. package/lib/speculos-deviceActions.d.ts.map +1 -0
  209. package/lib/speculos-deviceActions.js +217 -0
  210. package/lib/speculos-deviceActions.js.map +1 -0
  211. package/lib/synchronization.d.ts +5 -0
  212. package/lib/synchronization.d.ts.map +1 -0
  213. package/lib/synchronization.js +463 -0
  214. package/lib/synchronization.js.map +1 -0
  215. package/lib/transaction.d.ts +15 -0
  216. package/lib/transaction.d.ts.map +1 -0
  217. package/lib/transaction.js +154 -0
  218. package/lib/transaction.js.map +1 -0
  219. package/lib/tx-fees.d.ts +4 -0
  220. package/lib/tx-fees.d.ts.map +1 -0
  221. package/lib/tx-fees.js +167 -0
  222. package/lib/tx-fees.js.map +1 -0
  223. package/lib/types.d.ts +225 -0
  224. package/lib/types.d.ts.map +1 -0
  225. package/lib/types.js +3 -0
  226. package/lib/types.js.map +1 -0
  227. package/lib/utils.d.ts +24 -0
  228. package/lib/utils.d.ts.map +1 -0
  229. package/lib/utils.js +172 -0
  230. package/lib/utils.js.map +1 -0
  231. package/lib/validator-app/index.d.ts +22 -0
  232. package/lib/validator-app/index.d.ts.map +1 -0
  233. package/lib/validator-app/index.js +62 -0
  234. package/lib/validator-app/index.js.map +1 -0
  235. package/lib-es/api/cached.d.ts +3 -0
  236. package/lib-es/api/cached.d.ts.map +1 -0
  237. package/lib-es/api/cached.js +34 -0
  238. package/lib-es/api/cached.js.map +1 -0
  239. package/lib-es/api/chain/account/index.d.ts +2 -0
  240. package/lib-es/api/chain/account/index.d.ts.map +1 -0
  241. package/lib-es/api/chain/account/index.js +2 -0
  242. package/lib-es/api/chain/account/index.js.map +1 -0
  243. package/lib-es/api/chain/account/parser.d.ts +10 -0
  244. package/lib-es/api/chain/account/parser.d.ts.map +1 -0
  245. package/lib-es/api/chain/account/parser.js +48 -0
  246. package/lib-es/api/chain/account/parser.js.map +1 -0
  247. package/lib-es/api/chain/account/stake.d.ts +237 -0
  248. package/lib-es/api/chain/account/stake.d.ts.map +1 -0
  249. package/lib-es/api/chain/account/stake.js +35 -0
  250. package/lib-es/api/chain/account/stake.js.map +1 -0
  251. package/lib-es/api/chain/account/token.d.ts +116 -0
  252. package/lib-es/api/chain/account/token.d.ts.map +1 -0
  253. package/lib-es/api/chain/account/token.js +39 -0
  254. package/lib-es/api/chain/account/token.js.map +1 -0
  255. package/lib-es/api/chain/account/vote.d.ts +252 -0
  256. package/lib-es/api/chain/account/vote.d.ts.map +1 -0
  257. package/lib-es/api/chain/account/vote.js +41 -0
  258. package/lib-es/api/chain/account/vote.js.map +1 -0
  259. package/lib-es/api/chain/index.d.ts +29 -0
  260. package/lib-es/api/chain/index.d.ts.map +1 -0
  261. package/lib-es/api/chain/index.js +92 -0
  262. package/lib-es/api/chain/index.js.map +1 -0
  263. package/lib-es/api/chain/instruction/associated-token-account/index.d.ts +15 -0
  264. package/lib-es/api/chain/instruction/associated-token-account/index.d.ts.map +1 -0
  265. package/lib-es/api/chain/instruction/associated-token-account/index.js +17 -0
  266. package/lib-es/api/chain/instruction/associated-token-account/index.js.map +1 -0
  267. package/lib-es/api/chain/instruction/associated-token-account/types.d.ts +30 -0
  268. package/lib-es/api/chain/instruction/associated-token-account/types.d.ts.map +1 -0
  269. package/lib-es/api/chain/instruction/associated-token-account/types.js +16 -0
  270. package/lib-es/api/chain/instruction/associated-token-account/types.js.map +1 -0
  271. package/lib-es/api/chain/instruction/memo/index.d.ts +15 -0
  272. package/lib-es/api/chain/instruction/memo/index.d.ts.map +1 -0
  273. package/lib-es/api/chain/instruction/memo/index.js +10 -0
  274. package/lib-es/api/chain/instruction/memo/index.js.map +1 -0
  275. package/lib-es/api/chain/instruction/memo/types.d.ts +21 -0
  276. package/lib-es/api/chain/instruction/memo/types.d.ts.map +1 -0
  277. package/lib-es/api/chain/instruction/memo/types.js +13 -0
  278. package/lib-es/api/chain/instruction/memo/types.js.map +1 -0
  279. package/lib-es/api/chain/instruction/stake/index.d.ts +15 -0
  280. package/lib-es/api/chain/instruction/stake/index.d.ts.map +1 -0
  281. package/lib-es/api/chain/instruction/stake/index.js +16 -0
  282. package/lib-es/api/chain/instruction/stake/index.js.map +1 -0
  283. package/lib-es/api/chain/instruction/stake/types.d.ts +215 -0
  284. package/lib-es/api/chain/instruction/stake/types.d.ts.map +1 -0
  285. package/lib-es/api/chain/instruction/stake/types.js +77 -0
  286. package/lib-es/api/chain/instruction/stake/types.js.map +1 -0
  287. package/lib-es/api/chain/instruction/system/index.d.ts +15 -0
  288. package/lib-es/api/chain/instruction/system/index.d.ts.map +1 -0
  289. package/lib-es/api/chain/instruction/system/index.js +16 -0
  290. package/lib-es/api/chain/instruction/system/index.js.map +1 -0
  291. package/lib-es/api/chain/instruction/system/types.d.ts +298 -0
  292. package/lib-es/api/chain/instruction/system/types.d.ts.map +1 -0
  293. package/lib-es/api/chain/instruction/system/types.js +114 -0
  294. package/lib-es/api/chain/instruction/system/types.js.map +1 -0
  295. package/lib-es/api/chain/instruction/token/index.d.ts +15 -0
  296. package/lib-es/api/chain/instruction/token/index.d.ts.map +1 -0
  297. package/lib-es/api/chain/instruction/token/index.js +16 -0
  298. package/lib-es/api/chain/instruction/token/index.js.map +1 -0
  299. package/lib-es/api/chain/instruction/token/types.d.ts +497 -0
  300. package/lib-es/api/chain/instruction/token/types.d.ts.map +1 -0
  301. package/lib-es/api/chain/instruction/token/types.js +197 -0
  302. package/lib-es/api/chain/instruction/token/types.js.map +1 -0
  303. package/lib-es/api/chain/program/constants.d.ts +11 -0
  304. package/lib-es/api/chain/program/constants.d.ts.map +1 -0
  305. package/lib-es/api/chain/program/constants.js +11 -0
  306. package/lib-es/api/chain/program/constants.js.map +1 -0
  307. package/lib-es/api/chain/program/index.d.ts +2 -0
  308. package/lib-es/api/chain/program/index.d.ts.map +1 -0
  309. package/lib-es/api/chain/program/index.js +2 -0
  310. package/lib-es/api/chain/program/index.js.map +1 -0
  311. package/lib-es/api/chain/program/parser.d.ts +35 -0
  312. package/lib-es/api/chain/program/parser.d.ts.map +1 -0
  313. package/lib-es/api/chain/program/parser.js +61 -0
  314. package/lib-es/api/chain/program/parser.js.map +1 -0
  315. package/lib-es/api/chain/validators/bignum.d.ts +3 -0
  316. package/lib-es/api/chain/validators/bignum.d.ts.map +1 -0
  317. package/lib-es/api/chain/validators/bignum.js +8 -0
  318. package/lib-es/api/chain/validators/bignum.js.map +1 -0
  319. package/lib-es/api/chain/validators/index.d.ts +10 -0
  320. package/lib-es/api/chain/validators/index.d.ts.map +1 -0
  321. package/lib-es/api/chain/validators/index.js +7 -0
  322. package/lib-es/api/chain/validators/index.js.map +1 -0
  323. package/lib-es/api/chain/validators/pubkey.d.ts +3 -0
  324. package/lib-es/api/chain/validators/pubkey.d.ts.map +1 -0
  325. package/lib-es/api/chain/validators/pubkey.js +4 -0
  326. package/lib-es/api/chain/validators/pubkey.js.map +1 -0
  327. package/lib-es/api/chain/web3.d.ts +43 -0
  328. package/lib-es/api/chain/web3.d.ts.map +1 -0
  329. package/lib-es/api/chain/web3.js +249 -0
  330. package/lib-es/api/chain/web3.js.map +1 -0
  331. package/lib-es/api/index.d.ts +5 -0
  332. package/lib-es/api/index.d.ts.map +1 -0
  333. package/lib-es/api/index.js +5 -0
  334. package/lib-es/api/index.js.map +1 -0
  335. package/lib-es/api/logged.d.ts +3 -0
  336. package/lib-es/api/logged.d.ts.map +1 -0
  337. package/lib-es/api/logged.js +65 -0
  338. package/lib-es/api/logged.js.map +1 -0
  339. package/lib-es/api/queued.d.ts +3 -0
  340. package/lib-es/api/queued.d.ts.map +1 -0
  341. package/lib-es/api/queued.js +23 -0
  342. package/lib-es/api/queued.js.map +1 -0
  343. package/lib-es/api/traced.d.ts +3 -0
  344. package/lib-es/api/traced.d.ts.map +1 -0
  345. package/lib-es/api/traced.js +76 -0
  346. package/lib-es/api/traced.js.map +1 -0
  347. package/lib-es/bridge/bridge.d.ts +15 -0
  348. package/lib-es/bridge/bridge.d.ts.map +1 -0
  349. package/lib-es/bridge/bridge.js +127 -0
  350. package/lib-es/bridge/bridge.js.map +1 -0
  351. package/lib-es/bridge/js.d.ts +7 -0
  352. package/lib-es/bridge/js.d.ts.map +1 -0
  353. package/lib-es/bridge/js.js +24 -0
  354. package/lib-es/bridge/js.js.map +1 -0
  355. package/lib-es/bridge.integration.test.d.ts +4 -0
  356. package/lib-es/bridge.integration.test.d.ts.map +1 -0
  357. package/lib-es/bridge.integration.test.js +986 -0
  358. package/lib-es/bridge.integration.test.js.map +1 -0
  359. package/lib-es/broadcast.d.ts +7 -0
  360. package/lib-es/broadcast.d.ts.map +1 -0
  361. package/lib-es/broadcast.js +33 -0
  362. package/lib-es/broadcast.js.map +1 -0
  363. package/lib-es/buildTransaction.d.ts +5 -0
  364. package/lib-es/buildTransaction.d.ts.map +1 -0
  365. package/lib-es/buildTransaction.js +63 -0
  366. package/lib-es/buildTransaction.js.map +1 -0
  367. package/lib-es/cli-transaction.d.ts +19 -0
  368. package/lib-es/cli-transaction.d.ts.map +1 -0
  369. package/lib-es/cli-transaction.js +190 -0
  370. package/lib-es/cli-transaction.js.map +1 -0
  371. package/lib-es/createTransaction.d.ts +5 -0
  372. package/lib-es/createTransaction.d.ts.map +1 -0
  373. package/lib-es/createTransaction.js +15 -0
  374. package/lib-es/createTransaction.js.map +1 -0
  375. package/lib-es/datasets/solana.scanAccounts.1.d.ts +6 -0
  376. package/lib-es/datasets/solana.scanAccounts.1.d.ts.map +1 -0
  377. package/lib-es/datasets/solana.scanAccounts.1.js +10 -0
  378. package/lib-es/datasets/solana.scanAccounts.1.js.map +1 -0
  379. package/lib-es/deviceTransactionConfig.d.ts +10 -0
  380. package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
  381. package/lib-es/deviceTransactionConfig.js +223 -0
  382. package/lib-es/deviceTransactionConfig.js.map +1 -0
  383. package/lib-es/errors.d.ts +61 -0
  384. package/lib-es/errors.d.ts.map +1 -0
  385. package/lib-es/errors.js +22 -0
  386. package/lib-es/errors.js.map +1 -0
  387. package/lib-es/estimateMaxSpendable.d.ts +11 -0
  388. package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
  389. package/lib-es/estimateMaxSpendable.js +55 -0
  390. package/lib-es/estimateMaxSpendable.js.map +1 -0
  391. package/lib-es/getTransactionStatus.d.ts +5 -0
  392. package/lib-es/getTransactionStatus.d.ts.map +1 -0
  393. package/lib-es/getTransactionStatus.js +69 -0
  394. package/lib-es/getTransactionStatus.js.map +1 -0
  395. package/lib-es/hw-getAddress.d.ts +6 -0
  396. package/lib-es/hw-getAddress.d.ts.map +1 -0
  397. package/lib-es/hw-getAddress.js +23 -0
  398. package/lib-es/hw-getAddress.js.map +1 -0
  399. package/lib-es/logic.d.ts +29 -0
  400. package/lib-es/logic.d.ts.map +1 -0
  401. package/lib-es/logic.js +87 -0
  402. package/lib-es/logic.js.map +1 -0
  403. package/lib-es/preload-data.d.ts +7 -0
  404. package/lib-es/preload-data.d.ts.map +1 -0
  405. package/lib-es/preload-data.js +39 -0
  406. package/lib-es/preload-data.js.map +1 -0
  407. package/lib-es/preload.d.ts +7 -0
  408. package/lib-es/preload.d.ts.map +1 -0
  409. package/lib-es/preload.js +62 -0
  410. package/lib-es/preload.js.map +1 -0
  411. package/lib-es/preload.test.d.ts +2 -0
  412. package/lib-es/preload.test.d.ts.map +1 -0
  413. package/lib-es/preload.test.js +7 -0
  414. package/lib-es/preload.test.js.map +1 -0
  415. package/lib-es/prepareTransaction.d.ts +5 -0
  416. package/lib-es/prepareTransaction.d.ts.map +1 -0
  417. package/lib-es/prepareTransaction.js +497 -0
  418. package/lib-es/prepareTransaction.js.map +1 -0
  419. package/lib-es/serialization.d.ts +9 -0
  420. package/lib-es/serialization.d.ts.map +1 -0
  421. package/lib-es/serialization.js +60 -0
  422. package/lib-es/serialization.js.map +1 -0
  423. package/lib-es/signOperation.d.ts +7 -0
  424. package/lib-es/signOperation.d.ts.map +1 -0
  425. package/lib-es/signOperation.js +146 -0
  426. package/lib-es/signOperation.js.map +1 -0
  427. package/lib-es/signer.d.ts +11 -0
  428. package/lib-es/signer.d.ts.map +1 -0
  429. package/lib-es/signer.js +2 -0
  430. package/lib-es/signer.js.map +1 -0
  431. package/lib-es/specs.d.ts +7 -0
  432. package/lib-es/specs.d.ts.map +1 -0
  433. package/lib-es/specs.js +404 -0
  434. package/lib-es/specs.js.map +1 -0
  435. package/lib-es/speculos-deviceActions.d.ts +8 -0
  436. package/lib-es/speculos-deviceActions.d.ts.map +1 -0
  437. package/lib-es/speculos-deviceActions.js +211 -0
  438. package/lib-es/speculos-deviceActions.js.map +1 -0
  439. package/lib-es/synchronization.d.ts +5 -0
  440. package/lib-es/synchronization.d.ts.map +1 -0
  441. package/lib-es/synchronization.js +456 -0
  442. package/lib-es/synchronization.js.map +1 -0
  443. package/lib-es/transaction.d.ts +15 -0
  444. package/lib-es/transaction.d.ts.map +1 -0
  445. package/lib-es/transaction.js +148 -0
  446. package/lib-es/transaction.js.map +1 -0
  447. package/lib-es/tx-fees.d.ts +4 -0
  448. package/lib-es/tx-fees.d.ts.map +1 -0
  449. package/lib-es/tx-fees.js +160 -0
  450. package/lib-es/tx-fees.js.map +1 -0
  451. package/lib-es/types.d.ts +225 -0
  452. package/lib-es/types.d.ts.map +1 -0
  453. package/lib-es/types.js +2 -0
  454. package/lib-es/types.js.map +1 -0
  455. package/lib-es/utils.d.ts +24 -0
  456. package/lib-es/utils.d.ts.map +1 -0
  457. package/lib-es/utils.js +157 -0
  458. package/lib-es/utils.js.map +1 -0
  459. package/lib-es/validator-app/index.d.ts +22 -0
  460. package/lib-es/validator-app/index.d.ts.map +1 -0
  461. package/lib-es/validator-app/index.js +55 -0
  462. package/lib-es/validator-app/index.js.map +1 -0
  463. package/package.json +90 -0
  464. package/src/api/cached.ts +79 -0
  465. package/src/api/chain/account/index.ts +1 -0
  466. package/src/api/chain/account/parser.ts +63 -0
  467. package/src/api/chain/account/stake.ts +45 -0
  468. package/src/api/chain/account/token.ts +63 -0
  469. package/src/api/chain/account/vote.ts +55 -0
  470. package/src/api/chain/index.ts +212 -0
  471. package/src/api/chain/instruction/associated-token-account/index.ts +33 -0
  472. package/src/api/chain/instruction/associated-token-account/types.ts +23 -0
  473. package/src/api/chain/instruction/memo/index.ts +24 -0
  474. package/src/api/chain/instruction/memo/types.ts +18 -0
  475. package/src/api/chain/instruction/stake/index.ts +29 -0
  476. package/src/api/chain/instruction/stake/types.ts +95 -0
  477. package/src/api/chain/instruction/system/index.ts +30 -0
  478. package/src/api/chain/instruction/system/types.ts +141 -0
  479. package/src/api/chain/instruction/token/index.ts +30 -0
  480. package/src/api/chain/instruction/token/types.ts +222 -0
  481. package/src/api/chain/program/constants.ts +10 -0
  482. package/src/api/chain/program/index.ts +1 -0
  483. package/src/api/chain/program/parser.ts +120 -0
  484. package/src/api/chain/validators/bignum.ts +7 -0
  485. package/src/api/chain/validators/index.ts +9 -0
  486. package/src/api/chain/validators/pubkey.ts +8 -0
  487. package/src/api/chain/web3.ts +399 -0
  488. package/src/api/index.ts +4 -0
  489. package/src/api/logged.ts +70 -0
  490. package/src/api/queued.ts +25 -0
  491. package/src/api/traced.ts +89 -0
  492. package/src/bridge/bridge.ts +192 -0
  493. package/src/bridge/js.ts +42 -0
  494. package/src/bridge.integration.test.ts +1104 -0
  495. package/src/broadcast.ts +38 -0
  496. package/src/buildTransaction.ts +81 -0
  497. package/src/cli-transaction.ts +246 -0
  498. package/src/createTransaction.ts +18 -0
  499. package/src/datasets/solana.scanAccounts.1.ts +9 -0
  500. package/src/deviceTransactionConfig.ts +302 -0
  501. package/src/errors.ts +61 -0
  502. package/src/estimateMaxSpendable.ts +72 -0
  503. package/src/getTransactionStatus.ts +79 -0
  504. package/src/hw-getAddress.ts +22 -0
  505. package/src/logic.ts +123 -0
  506. package/src/preload-data.ts +46 -0
  507. package/src/preload.test.ts +14 -0
  508. package/src/preload.ts +74 -0
  509. package/src/prepareTransaction.ts +686 -0
  510. package/src/serialization.ts +81 -0
  511. package/src/signOperation.ts +315 -0
  512. package/src/signer.ts +10 -0
  513. package/src/specs.ts +514 -0
  514. package/src/speculos-deviceActions.ts +229 -0
  515. package/src/synchronization.ts +729 -0
  516. package/src/transaction.ts +199 -0
  517. package/src/tx-fees.ts +206 -0
  518. package/src/types.ts +291 -0
  519. package/src/utils.ts +176 -0
  520. package/src/validator-app/index.ts +79 -0
  521. package/tsconfig.json +13 -0
@@ -0,0 +1,120 @@
1
+ import { ParsedInstruction, PartiallyDecodedInstruction } from "@solana/web3.js";
2
+ import { parseSplTokenInstruction, TokenInstructionDescriptor } from "../instruction/token";
3
+ import { PARSED_PROGRAMS } from "./constants";
4
+ import {
5
+ AssociatedTokenAccountInstructionDescriptor,
6
+ parseAssociatedTokenAccountInstruction,
7
+ } from "../instruction/associated-token-account";
8
+ import { MemoInstructionDescriptor, parseSplMemoInstruction } from "../instruction/memo";
9
+ import { parseStakeInstruction, StakeInstructionDescriptor } from "../instruction/stake";
10
+ import { parseSystemInstruction, SystemInstructionDescriptor } from "../instruction/system";
11
+
12
+ type ParsedProgram =
13
+ | {
14
+ program: "system";
15
+ title: string;
16
+ instruction: SystemInstructionDescriptor;
17
+ }
18
+ | {
19
+ program: "spl-associated-token-account";
20
+ title: string;
21
+ instruction: AssociatedTokenAccountInstructionDescriptor;
22
+ }
23
+ | {
24
+ program: "spl-memo";
25
+ title: string;
26
+ instruction: MemoInstructionDescriptor;
27
+ }
28
+ | {
29
+ program: "stake";
30
+ title: string;
31
+ instruction: StakeInstructionDescriptor;
32
+ }
33
+ | {
34
+ program: "spl-token";
35
+ title: string;
36
+ instruction: TokenInstructionDescriptor;
37
+ }
38
+ | {
39
+ program: "unknown";
40
+ title: "Unknown";
41
+ instruction: undefined;
42
+ };
43
+
44
+ export const parse = (ix: ParsedInstruction | PartiallyDecodedInstruction): ParsedProgram => {
45
+ if ("parsed" in ix) {
46
+ const program: (typeof PARSED_PROGRAMS)[keyof typeof PARSED_PROGRAMS] = ix.program as any;
47
+
48
+ switch (program) {
49
+ case "system":
50
+ return {
51
+ program,
52
+ title: "System",
53
+ instruction: parseSystemInstruction({
54
+ ...ix,
55
+ program,
56
+ }),
57
+ };
58
+ case "spl-associated-token-account":
59
+ return {
60
+ program,
61
+ title: "Associated Token Account",
62
+ instruction: parseAssociatedTokenAccountInstruction({
63
+ ...ix,
64
+ program,
65
+ }),
66
+ };
67
+ case "spl-memo":
68
+ return {
69
+ program,
70
+ title: "Memo",
71
+ instruction: parseSplMemoInstruction({
72
+ ...ix,
73
+ program,
74
+ }),
75
+ };
76
+ case "stake":
77
+ return {
78
+ program,
79
+ title: "Stake",
80
+ instruction: parseStakeInstruction({
81
+ ...ix,
82
+ program,
83
+ }),
84
+ };
85
+ case "spl-token":
86
+ return {
87
+ program,
88
+ title: "Token",
89
+ instruction: parseSplTokenInstruction({
90
+ ...ix,
91
+ program,
92
+ }),
93
+ };
94
+ default:
95
+ return unknown();
96
+ }
97
+ }
98
+
99
+ return unknown();
100
+ };
101
+
102
+ export const parseQuiet = (ix: ParsedInstruction | PartiallyDecodedInstruction): ParsedProgram => {
103
+ try {
104
+ return parse(ix);
105
+ } catch (_) {
106
+ return unknown();
107
+ }
108
+ };
109
+
110
+ function unknown(): {
111
+ program: "unknown";
112
+ title: "Unknown";
113
+ instruction: undefined;
114
+ } {
115
+ return {
116
+ program: "unknown",
117
+ title: "Unknown",
118
+ instruction: undefined,
119
+ } as const;
120
+ }
@@ -0,0 +1,7 @@
1
+ import { coerce, instance, string } from "superstruct";
2
+ import { BigNumber } from "bignumber.js";
3
+
4
+ export const BigNumFromString = coerce(instance(BigNumber), string(), value => {
5
+ if (typeof value === "string") return new BigNumber(value, 10);
6
+ throw new Error("invalid big num");
7
+ });
@@ -0,0 +1,9 @@
1
+ /* eslint-disable @typescript-eslint/no-redeclare */
2
+
3
+ import { type, any, Infer, string } from "superstruct";
4
+
5
+ export type ParsedInfo = Infer<typeof ParsedInfo>;
6
+ export const ParsedInfo = type({
7
+ type: string(),
8
+ info: any(),
9
+ });
@@ -0,0 +1,8 @@
1
+ import { coerce, instance, string } from "superstruct";
2
+ import { PublicKey } from "@solana/web3.js";
3
+
4
+ export const PublicKeyFromString = coerce(
5
+ instance(PublicKey),
6
+ string(),
7
+ value => new PublicKey(value),
8
+ );
@@ -0,0 +1,399 @@
1
+ import {
2
+ createAssociatedTokenAccountInstruction,
3
+ createTransferCheckedInstruction,
4
+ getAssociatedTokenAddress,
5
+ } from "@solana/spl-token";
6
+ import {
7
+ ConfirmedSignatureInfo,
8
+ Connection,
9
+ ParsedTransactionWithMeta,
10
+ PublicKey,
11
+ StakeProgram,
12
+ SystemProgram,
13
+ TransactionInstruction,
14
+ } from "@solana/web3.js";
15
+ import chunk from "lodash/chunk";
16
+ import { ChainAPI } from ".";
17
+ import { Awaited } from "../../logic";
18
+ import {
19
+ StakeCreateAccountCommand,
20
+ StakeDelegateCommand,
21
+ StakeSplitCommand,
22
+ StakeUndelegateCommand,
23
+ StakeWithdrawCommand,
24
+ TokenCreateATACommand,
25
+ TokenTransferCommand,
26
+ TransferCommand,
27
+ } from "../../types";
28
+ import { drainSeqAsyncGen } from "../../utils";
29
+ import { parseTokenAccountInfo, tryParseAsTokenAccount, tryParseAsVoteAccount } from "./account";
30
+ import { parseStakeAccountInfo } from "./account/parser";
31
+ import { StakeAccountInfo } from "./account/stake";
32
+ import { TokenAccountInfo } from "./account/token";
33
+ import { VoteAccountInfo } from "./account/vote";
34
+
35
+ const MEMO_PROGRAM_ID = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr";
36
+
37
+ type ParsedOnChainTokenAccount = Awaited<
38
+ ReturnType<Connection["getParsedTokenAccountsByOwner"]>
39
+ >["value"][number];
40
+
41
+ type ParsedOnChainStakeAccount = Awaited<
42
+ ReturnType<Connection["getParsedProgramAccounts"]>
43
+ >[number];
44
+
45
+ export type ParsedOnChainTokenAccountWithInfo = {
46
+ onChainAcc: ParsedOnChainTokenAccount;
47
+ info: TokenAccountInfo;
48
+ };
49
+
50
+ export type ParsedOnChainStakeAccountWithInfo = {
51
+ onChainAcc: ParsedOnChainStakeAccount;
52
+ info: StakeAccountInfo;
53
+ };
54
+
55
+ export function toTokenAccountWithInfo(
56
+ onChainAcc: ParsedOnChainTokenAccount,
57
+ ): ParsedOnChainTokenAccountWithInfo {
58
+ const parsedInfo = onChainAcc.account.data.parsed.info;
59
+ const info = parseTokenAccountInfo(parsedInfo);
60
+ return { onChainAcc, info };
61
+ }
62
+
63
+ export function toStakeAccountWithInfo(
64
+ onChainAcc: ParsedOnChainStakeAccount,
65
+ ): ParsedOnChainStakeAccountWithInfo | undefined {
66
+ if ("parsed" in onChainAcc.account.data) {
67
+ const parsedInfo = onChainAcc.account.data.parsed.info;
68
+ const info = parseStakeAccountInfo(parsedInfo);
69
+ return { onChainAcc, info };
70
+ }
71
+ return undefined;
72
+ }
73
+
74
+ export type TransactionDescriptor = {
75
+ parsed: ParsedTransactionWithMeta;
76
+ info: ConfirmedSignatureInfo;
77
+ };
78
+
79
+ async function* getTransactionsBatched(
80
+ address: string,
81
+ untilTxSignature: string | undefined,
82
+ api: ChainAPI,
83
+ ): AsyncGenerator<TransactionDescriptor[], void, unknown> {
84
+ // as per Ledger team - last 100 operations is a sane limit to begin with
85
+ const signatures = await api.getSignaturesForAddress(address, {
86
+ ...(untilTxSignature ? { until: untilTxSignature } : {}),
87
+ limit: 100,
88
+ });
89
+
90
+ // max req payload is 50K, around 200 transactions atm
91
+ // requesting 100 at a time to give some space for payload to change in future
92
+ const batchSize = 100;
93
+
94
+ for (const signaturesInfoBatch of chunk(signatures, batchSize)) {
95
+ const transactions = await api.getParsedTransactions(
96
+ signaturesInfoBatch.map(tx => tx.signature),
97
+ );
98
+ const txsDetails = transactions.reduce((acc, tx, index) => {
99
+ if (tx && !tx.meta?.err && tx.blockTime) {
100
+ acc.push({
101
+ info: signaturesInfoBatch[index],
102
+ parsed: tx,
103
+ });
104
+ }
105
+ return acc;
106
+ }, [] as TransactionDescriptor[]);
107
+
108
+ yield txsDetails;
109
+ }
110
+ }
111
+
112
+ async function* getTransactionsGen(
113
+ address: string,
114
+ untilTxSignature: string | undefined,
115
+ api: ChainAPI,
116
+ ): AsyncGenerator<TransactionDescriptor, void, undefined> {
117
+ for await (const txDetailsBatch of getTransactionsBatched(address, untilTxSignature, api)) {
118
+ yield* txDetailsBatch;
119
+ }
120
+ }
121
+
122
+ export function getTransactions(
123
+ address: string,
124
+ untilTxSignature: string | undefined,
125
+ api: ChainAPI,
126
+ ): Promise<TransactionDescriptor[]> {
127
+ return drainSeqAsyncGen(getTransactionsGen(address, untilTxSignature, api));
128
+ }
129
+
130
+ export const buildTransferInstructions = ({
131
+ sender,
132
+ recipient,
133
+ amount,
134
+ memo,
135
+ }: TransferCommand): TransactionInstruction[] => {
136
+ const fromPublicKey = new PublicKey(sender);
137
+ const toPublicKey = new PublicKey(recipient);
138
+
139
+ const instructions: TransactionInstruction[] = [
140
+ SystemProgram.transfer({
141
+ fromPubkey: fromPublicKey,
142
+ toPubkey: toPublicKey,
143
+ lamports: amount,
144
+ }),
145
+ ];
146
+
147
+ if (memo) {
148
+ const memoIx = new TransactionInstruction({
149
+ keys: [],
150
+ programId: new PublicKey(MEMO_PROGRAM_ID),
151
+ data: Buffer.from(memo),
152
+ });
153
+ instructions.push(memoIx);
154
+ }
155
+
156
+ return instructions;
157
+ };
158
+
159
+ export const buildTokenTransferInstructions = (
160
+ command: TokenTransferCommand,
161
+ ): TransactionInstruction[] => {
162
+ const {
163
+ ownerAddress,
164
+ ownerAssociatedTokenAccountAddress,
165
+ amount,
166
+ recipientDescriptor,
167
+ mintAddress,
168
+ mintDecimals,
169
+ memo,
170
+ } = command;
171
+ const ownerPubkey = new PublicKey(ownerAddress);
172
+
173
+ const destinationPubkey = new PublicKey(recipientDescriptor.tokenAccAddress);
174
+
175
+ const instructions: TransactionInstruction[] = [];
176
+
177
+ const mintPubkey = new PublicKey(mintAddress);
178
+
179
+ if (recipientDescriptor.shouldCreateAsAssociatedTokenAccount) {
180
+ instructions.push(
181
+ createAssociatedTokenAccountInstruction(
182
+ ownerPubkey,
183
+ destinationPubkey,
184
+ ownerPubkey,
185
+ mintPubkey,
186
+ ),
187
+ );
188
+ }
189
+
190
+ instructions.push(
191
+ createTransferCheckedInstruction(
192
+ new PublicKey(ownerAssociatedTokenAccountAddress),
193
+ mintPubkey,
194
+ destinationPubkey,
195
+ ownerPubkey,
196
+ amount,
197
+ mintDecimals,
198
+ ),
199
+ );
200
+
201
+ if (memo) {
202
+ instructions.push(
203
+ new TransactionInstruction({
204
+ keys: [],
205
+ programId: new PublicKey(MEMO_PROGRAM_ID),
206
+ data: Buffer.from(memo),
207
+ }),
208
+ );
209
+ }
210
+
211
+ return instructions;
212
+ };
213
+
214
+ export async function findAssociatedTokenAccountPubkey(
215
+ ownerAddress: string,
216
+ mintAddress: string,
217
+ ): Promise<PublicKey> {
218
+ const ownerPubKey = new PublicKey(ownerAddress);
219
+ const mintPubkey = new PublicKey(mintAddress);
220
+
221
+ return getAssociatedTokenAddress(mintPubkey, ownerPubKey);
222
+ }
223
+
224
+ export const getMaybeTokenAccount = async (
225
+ address: string,
226
+ api: ChainAPI,
227
+ ): Promise<TokenAccountInfo | undefined | Error> => {
228
+ const accInfo = await api.getAccountInfo(address);
229
+
230
+ const tokenAccount =
231
+ accInfo !== null && "parsed" in accInfo.data ? tryParseAsTokenAccount(accInfo.data) : undefined;
232
+
233
+ return tokenAccount;
234
+ };
235
+
236
+ export async function getMaybeVoteAccount(
237
+ address: string,
238
+ api: ChainAPI,
239
+ ): Promise<VoteAccountInfo | undefined | Error> {
240
+ const accInfo = await api.getAccountInfo(address);
241
+ const voteAccount =
242
+ accInfo !== null && "parsed" in accInfo.data ? tryParseAsVoteAccount(accInfo.data) : undefined;
243
+
244
+ return voteAccount;
245
+ }
246
+
247
+ export function getStakeAccountMinimumBalanceForRentExemption(api: ChainAPI) {
248
+ return api.getMinimumBalanceForRentExemption(StakeProgram.space);
249
+ }
250
+
251
+ export async function getAccountMinimumBalanceForRentExemption(api: ChainAPI, address: string) {
252
+ const accInfo = await api.getAccountInfo(address);
253
+ const accSpace = accInfo !== null && "parsed" in accInfo.data ? accInfo.data.space : 0;
254
+
255
+ return api.getMinimumBalanceForRentExemption(accSpace);
256
+ }
257
+
258
+ export async function getStakeAccountAddressWithSeed({
259
+ fromAddress,
260
+ seed,
261
+ }: {
262
+ fromAddress: string;
263
+ seed: string;
264
+ }) {
265
+ const pubkey = await PublicKey.createWithSeed(
266
+ new PublicKey(fromAddress),
267
+ seed,
268
+ StakeProgram.programId,
269
+ );
270
+
271
+ return pubkey.toBase58();
272
+ }
273
+
274
+ export function buildCreateAssociatedTokenAccountInstruction({
275
+ mint,
276
+ owner,
277
+ associatedTokenAccountAddress,
278
+ }: TokenCreateATACommand): TransactionInstruction[] {
279
+ const ownerPubKey = new PublicKey(owner);
280
+ const mintPubkey = new PublicKey(mint);
281
+ const associatedTokenAccPubkey = new PublicKey(associatedTokenAccountAddress);
282
+
283
+ const instructions: TransactionInstruction[] = [
284
+ createAssociatedTokenAccountInstruction(
285
+ ownerPubKey,
286
+ associatedTokenAccPubkey,
287
+ ownerPubKey,
288
+ mintPubkey,
289
+ ),
290
+ ];
291
+
292
+ return instructions;
293
+ }
294
+
295
+ export function buildStakeDelegateInstructions({
296
+ authorizedAccAddr,
297
+ stakeAccAddr,
298
+ voteAccAddr,
299
+ }: StakeDelegateCommand): TransactionInstruction[] {
300
+ const tx = StakeProgram.delegate({
301
+ authorizedPubkey: new PublicKey(authorizedAccAddr),
302
+ stakePubkey: new PublicKey(stakeAccAddr),
303
+ votePubkey: new PublicKey(voteAccAddr),
304
+ });
305
+
306
+ return tx.instructions;
307
+ }
308
+
309
+ export function buildStakeUndelegateInstructions({
310
+ authorizedAccAddr,
311
+ stakeAccAddr,
312
+ }: StakeUndelegateCommand): TransactionInstruction[] {
313
+ const tx = StakeProgram.deactivate({
314
+ authorizedPubkey: new PublicKey(authorizedAccAddr),
315
+ stakePubkey: new PublicKey(stakeAccAddr),
316
+ });
317
+
318
+ return tx.instructions;
319
+ }
320
+
321
+ export function buildStakeWithdrawInstructions({
322
+ authorizedAccAddr,
323
+ stakeAccAddr,
324
+ amount,
325
+ toAccAddr,
326
+ }: StakeWithdrawCommand): TransactionInstruction[] {
327
+ const tx = StakeProgram.withdraw({
328
+ authorizedPubkey: new PublicKey(authorizedAccAddr),
329
+ stakePubkey: new PublicKey(stakeAccAddr),
330
+ lamports: amount,
331
+ toPubkey: new PublicKey(toAccAddr),
332
+ });
333
+
334
+ return tx.instructions;
335
+ }
336
+
337
+ export function buildStakeSplitInstructions({
338
+ authorizedAccAddr,
339
+ stakeAccAddr,
340
+ seed,
341
+ amount,
342
+ splitStakeAccAddr,
343
+ }: StakeSplitCommand): TransactionInstruction[] {
344
+ // HACK: switch to split_with_seed when supported by @solana/web3.js
345
+ const splitIx = StakeProgram.split({
346
+ authorizedPubkey: new PublicKey(authorizedAccAddr),
347
+ lamports: amount,
348
+ stakePubkey: new PublicKey(stakeAccAddr),
349
+ splitStakePubkey: new PublicKey(splitStakeAccAddr),
350
+ }).instructions[1];
351
+
352
+ if (splitIx === undefined) {
353
+ throw new Error("expected split instruction");
354
+ }
355
+
356
+ const allocateIx = SystemProgram.allocate({
357
+ accountPubkey: new PublicKey(splitStakeAccAddr),
358
+ basePubkey: new PublicKey(authorizedAccAddr),
359
+ programId: StakeProgram.programId,
360
+ seed,
361
+ space: StakeProgram.space,
362
+ });
363
+
364
+ return [allocateIx, splitIx];
365
+ }
366
+
367
+ export function buildStakeCreateAccountInstructions({
368
+ fromAccAddress,
369
+ stakeAccAddress,
370
+ seed,
371
+ amount,
372
+ stakeAccRentExemptAmount,
373
+ delegate,
374
+ }: StakeCreateAccountCommand): TransactionInstruction[] {
375
+ const fromPubkey = new PublicKey(fromAccAddress);
376
+ const stakePubkey = new PublicKey(stakeAccAddress);
377
+
378
+ const tx = StakeProgram.createAccountWithSeed({
379
+ fromPubkey,
380
+ stakePubkey,
381
+ basePubkey: fromPubkey,
382
+ seed,
383
+ lamports: amount + stakeAccRentExemptAmount,
384
+ authorized: {
385
+ staker: fromPubkey,
386
+ withdrawer: fromPubkey,
387
+ },
388
+ });
389
+
390
+ tx.add(
391
+ StakeProgram.delegate({
392
+ authorizedPubkey: fromPubkey,
393
+ stakePubkey,
394
+ votePubkey: new PublicKey(delegate.voteAccAddress),
395
+ }),
396
+ );
397
+
398
+ return tx.instructions;
399
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./chain/index";
2
+ export { cached } from "./cached";
3
+ export { queued } from "./queued";
4
+ export { logged } from "./logged";
@@ -0,0 +1,70 @@
1
+ import { ChainAPI } from "./chain";
2
+
3
+ //import fs from "fs";
4
+ import { Message, PublicKey } from "@solana/web3.js";
5
+ import { LATEST_BLOCKHASH_MOCK } from "./chain";
6
+
7
+ /* eslint-disable-next-line @typescript-eslint/no-unused-vars */
8
+ function write(file: string, str: string) {
9
+ // fs is not available on mobile
10
+ //fs.appendFileSync(file, str);
11
+ }
12
+
13
+ export function logged(api: ChainAPI, file: string): ChainAPI {
14
+ const proxy: ChainAPI = new Proxy(api, {
15
+ get(target, propKey, receiver) {
16
+ if (typeof propKey === "symbol") {
17
+ throw new Error("symbols not supported");
18
+ }
19
+ const targetValue = Reflect.get(target, propKey, receiver);
20
+ if (typeof targetValue === "function") {
21
+ const method: keyof ChainAPI = propKey as any;
22
+ return function (...args: unknown[]) {
23
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
24
+ // @ts-ignore: TS-2683
25
+ const result = targetValue.apply(this, args);
26
+ const log = (answer: unknown) => {
27
+ if (method === "getLatestBlockhash") {
28
+ // add getLatestBlockhash manually to mock data to with mocked block hash
29
+ return;
30
+ }
31
+
32
+ if (method === "getFeeForMessage") {
33
+ // getFeeForMessage arg message must be serialized since it's a class
34
+ if (args.length === 1 && args[0] instanceof Message) {
35
+ args[0].recentBlockhash = LATEST_BLOCKHASH_MOCK;
36
+ (args as any) = [args[0].serialize().toString("base64")];
37
+ } else {
38
+ throw new Error("unexpected getFeeForMessage function signature");
39
+ }
40
+ }
41
+ const paramsJson = JSON.stringify(args);
42
+ const publicKeytoJSON = PublicKey.prototype.toJSON;
43
+ // @ts-expect-error hack to temporary remove toJSON so it doesn't affect JSON.stringify
44
+ delete PublicKey.prototype.toJSON;
45
+ const answerJson = JSON.stringify(answer).replace(
46
+ /{"_bn":(".*?")}/g,
47
+ "new PublicKey(Buffer.from($1, 'hex'))",
48
+ );
49
+ PublicKey.prototype.toJSON = publicKeytoJSON;
50
+ const summaryJson = `{"method":"${method}", "params":${paramsJson},"answer":${answerJson}}`;
51
+ write(file, summaryJson + ",\n");
52
+ };
53
+ if (result instanceof Promise) {
54
+ return result.then(answer => {
55
+ log(answer);
56
+ return answer;
57
+ });
58
+ } else {
59
+ log(result);
60
+ return result;
61
+ }
62
+ };
63
+ } else {
64
+ return targetValue;
65
+ }
66
+ },
67
+ });
68
+
69
+ return proxy;
70
+ }
@@ -0,0 +1,25 @@
1
+ import { asyncQueue } from "../utils";
2
+ import { ChainAPI } from "./chain";
3
+
4
+ export function queued(api: ChainAPI, delayBetweenRuns = 100): ChainAPI {
5
+ const q = asyncQueue({
6
+ delayBetweenRuns,
7
+ });
8
+
9
+ const proxy: ChainAPI = new Proxy(api, {
10
+ get(target, propKey, receiver) {
11
+ const targetValue = Reflect.get(target, propKey, receiver);
12
+ if (typeof targetValue === "function") {
13
+ return function (...args: unknown[]) {
14
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
15
+ // @ts-ignore: TS-2683
16
+ return q.submit(() => targetValue.apply(this, args));
17
+ };
18
+ } else {
19
+ return targetValue;
20
+ }
21
+ },
22
+ });
23
+
24
+ return proxy;
25
+ }