@getomnichain/omnichain 0.2.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 (296) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +66 -0
  3. package/dist/abstract_gas_pricing.d.ts +31 -0
  4. package/dist/abstract_gas_pricing.d.ts.map +1 -0
  5. package/dist/abstract_gas_pricing.js +22 -0
  6. package/dist/abstract_gas_pricing.js.map +1 -0
  7. package/dist/address.d.ts +10 -0
  8. package/dist/address.d.ts.map +1 -0
  9. package/dist/address.factory.d.ts +26 -0
  10. package/dist/address.factory.d.ts.map +1 -0
  11. package/dist/address.factory.js +75 -0
  12. package/dist/address.factory.js.map +1 -0
  13. package/dist/address.js +13 -0
  14. package/dist/address.js.map +1 -0
  15. package/dist/address_field.decorator.d.ts +17 -0
  16. package/dist/address_field.decorator.d.ts.map +1 -0
  17. package/dist/address_field.decorator.js +34 -0
  18. package/dist/address_field.decorator.js.map +1 -0
  19. package/dist/chain.base.d.ts +79 -0
  20. package/dist/chain.base.d.ts.map +1 -0
  21. package/dist/chain.base.js +113 -0
  22. package/dist/chain.base.js.map +1 -0
  23. package/dist/chain_ids.d.ts +122 -0
  24. package/dist/chain_ids.d.ts.map +1 -0
  25. package/dist/chain_ids.js +193 -0
  26. package/dist/chain_ids.js.map +1 -0
  27. package/dist/errors.d.ts +42 -0
  28. package/dist/errors.d.ts.map +1 -0
  29. package/dist/errors.js +62 -0
  30. package/dist/errors.js.map +1 -0
  31. package/dist/evm/evm_address.d.ts +11 -0
  32. package/dist/evm/evm_address.d.ts.map +1 -0
  33. package/dist/evm/evm_address.js +56 -0
  34. package/dist/evm/evm_address.js.map +1 -0
  35. package/dist/evm/evm_chain.d.ts +123 -0
  36. package/dist/evm/evm_chain.d.ts.map +1 -0
  37. package/dist/evm/evm_chain.js +685 -0
  38. package/dist/evm/evm_chain.js.map +1 -0
  39. package/dist/evm/evm_chains.d.ts +83 -0
  40. package/dist/evm/evm_chains.d.ts.map +1 -0
  41. package/dist/evm/evm_chains.js +493 -0
  42. package/dist/evm/evm_chains.js.map +1 -0
  43. package/dist/evm/evm_gas_estimate.d.ts +45 -0
  44. package/dist/evm/evm_gas_estimate.d.ts.map +1 -0
  45. package/dist/evm/evm_gas_estimate.js +70 -0
  46. package/dist/evm/evm_gas_estimate.js.map +1 -0
  47. package/dist/evm/evm_gas_pricing.d.ts +40 -0
  48. package/dist/evm/evm_gas_pricing.d.ts.map +1 -0
  49. package/dist/evm/evm_gas_pricing.js +56 -0
  50. package/dist/evm/evm_gas_pricing.js.map +1 -0
  51. package/dist/evm/evm_token.d.ts +7 -0
  52. package/dist/evm/evm_token.d.ts.map +1 -0
  53. package/dist/evm/evm_token.js +22 -0
  54. package/dist/evm/evm_token.js.map +1 -0
  55. package/dist/evm/evm_tokens.d.ts +81 -0
  56. package/dist/evm/evm_tokens.d.ts.map +1 -0
  57. package/dist/evm/evm_tokens.js +104 -0
  58. package/dist/evm/evm_tokens.js.map +1 -0
  59. package/dist/evm/evm_transaction_status.d.ts +108 -0
  60. package/dist/evm/evm_transaction_status.d.ts.map +1 -0
  61. package/dist/evm/evm_transaction_status.js +177 -0
  62. package/dist/evm/evm_transaction_status.js.map +1 -0
  63. package/dist/evm/index.d.ts +10 -0
  64. package/dist/evm/index.d.ts.map +1 -0
  65. package/dist/evm/index.js +10 -0
  66. package/dist/evm/index.js.map +1 -0
  67. package/dist/evm/unsigned_evm_transaction.d.ts +19 -0
  68. package/dist/evm/unsigned_evm_transaction.d.ts.map +1 -0
  69. package/dist/evm/unsigned_evm_transaction.js +18 -0
  70. package/dist/evm/unsigned_evm_transaction.js.map +1 -0
  71. package/dist/index.d.ts +18 -0
  72. package/dist/index.d.ts.map +1 -0
  73. package/dist/index.js +18 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/is_address.decorator.d.ts +3 -0
  76. package/dist/is_address.decorator.d.ts.map +1 -0
  77. package/dist/is_address.decorator.js +51 -0
  78. package/dist/is_address.decorator.js.map +1 -0
  79. package/dist/network_type.d.ts +73 -0
  80. package/dist/network_type.d.ts.map +1 -0
  81. package/dist/network_type.js +144 -0
  82. package/dist/network_type.js.map +1 -0
  83. package/dist/priority.d.ts +23 -0
  84. package/dist/priority.d.ts.map +1 -0
  85. package/dist/priority.js +23 -0
  86. package/dist/priority.js.map +1 -0
  87. package/dist/solana/index.d.ts +9 -0
  88. package/dist/solana/index.d.ts.map +1 -0
  89. package/dist/solana/index.js +9 -0
  90. package/dist/solana/index.js.map +1 -0
  91. package/dist/solana/solana_address.d.ts +20 -0
  92. package/dist/solana/solana_address.d.ts.map +1 -0
  93. package/dist/solana/solana_address.js +45 -0
  94. package/dist/solana/solana_address.js.map +1 -0
  95. package/dist/solana/solana_chain.d.ts +213 -0
  96. package/dist/solana/solana_chain.d.ts.map +1 -0
  97. package/dist/solana/solana_chain.js +704 -0
  98. package/dist/solana/solana_chain.js.map +1 -0
  99. package/dist/solana/solana_chains.d.ts +24 -0
  100. package/dist/solana/solana_chains.d.ts.map +1 -0
  101. package/dist/solana/solana_chains.js +84 -0
  102. package/dist/solana/solana_chains.js.map +1 -0
  103. package/dist/solana/solana_gas_pricing.d.ts +30 -0
  104. package/dist/solana/solana_gas_pricing.d.ts.map +1 -0
  105. package/dist/solana/solana_gas_pricing.js +26 -0
  106. package/dist/solana/solana_gas_pricing.js.map +1 -0
  107. package/dist/solana/solana_token.d.ts +19 -0
  108. package/dist/solana/solana_token.d.ts.map +1 -0
  109. package/dist/solana/solana_token.js +34 -0
  110. package/dist/solana/solana_token.js.map +1 -0
  111. package/dist/solana/solana_tokens.d.ts +22 -0
  112. package/dist/solana/solana_tokens.d.ts.map +1 -0
  113. package/dist/solana/solana_tokens.js +26 -0
  114. package/dist/solana/solana_tokens.js.map +1 -0
  115. package/dist/solana/solana_transaction_status.d.ts +59 -0
  116. package/dist/solana/solana_transaction_status.d.ts.map +1 -0
  117. package/dist/solana/solana_transaction_status.js +144 -0
  118. package/dist/solana/solana_transaction_status.js.map +1 -0
  119. package/dist/solana/unsigned_solana_transaction.d.ts +31 -0
  120. package/dist/solana/unsigned_solana_transaction.d.ts.map +1 -0
  121. package/dist/solana/unsigned_solana_transaction.js +26 -0
  122. package/dist/solana/unsigned_solana_transaction.js.map +1 -0
  123. package/dist/token.d.ts +35 -0
  124. package/dist/token.d.ts.map +1 -0
  125. package/dist/token.js +62 -0
  126. package/dist/token.js.map +1 -0
  127. package/dist/ton/index.d.ts +2 -0
  128. package/dist/ton/index.d.ts.map +1 -0
  129. package/dist/ton/index.js +2 -0
  130. package/dist/ton/index.js.map +1 -0
  131. package/dist/ton/ton_address.d.ts +10 -0
  132. package/dist/ton/ton_address.d.ts.map +1 -0
  133. package/dist/ton/ton_address.js +53 -0
  134. package/dist/ton/ton_address.js.map +1 -0
  135. package/dist/transaction_status.d.ts +140 -0
  136. package/dist/transaction_status.d.ts.map +1 -0
  137. package/dist/transaction_status.js +271 -0
  138. package/dist/transaction_status.js.map +1 -0
  139. package/dist/unsigned_transaction.d.ts +7 -0
  140. package/dist/unsigned_transaction.d.ts.map +1 -0
  141. package/dist/unsigned_transaction.js +9 -0
  142. package/dist/unsigned_transaction.js.map +1 -0
  143. package/dist/utxo/btc/btc_address.d.ts +15 -0
  144. package/dist/utxo/btc/btc_address.d.ts.map +1 -0
  145. package/dist/utxo/btc/btc_address.js +39 -0
  146. package/dist/utxo/btc/btc_address.js.map +1 -0
  147. package/dist/utxo/btc/btc_chain.d.ts +34 -0
  148. package/dist/utxo/btc/btc_chain.d.ts.map +1 -0
  149. package/dist/utxo/btc/btc_chain.js +62 -0
  150. package/dist/utxo/btc/btc_chain.js.map +1 -0
  151. package/dist/utxo/btc/btc_chains.d.ts +25 -0
  152. package/dist/utxo/btc/btc_chains.d.ts.map +1 -0
  153. package/dist/utxo/btc/btc_chains.js +43 -0
  154. package/dist/utxo/btc/btc_chains.js.map +1 -0
  155. package/dist/utxo/btc/btc_token.d.ts +6 -0
  156. package/dist/utxo/btc/btc_token.d.ts.map +1 -0
  157. package/dist/utxo/btc/btc_token.js +11 -0
  158. package/dist/utxo/btc/btc_token.js.map +1 -0
  159. package/dist/utxo/btc/index.d.ts +14 -0
  160. package/dist/utxo/btc/index.d.ts.map +1 -0
  161. package/dist/utxo/btc/index.js +14 -0
  162. package/dist/utxo/btc/index.js.map +1 -0
  163. package/dist/utxo/btc/network_params.d.ts +50 -0
  164. package/dist/utxo/btc/network_params.d.ts.map +1 -0
  165. package/dist/utxo/btc/network_params.js +188 -0
  166. package/dist/utxo/btc/network_params.js.map +1 -0
  167. package/dist/utxo/btc/tools/asset_outpoint.d.ts +7 -0
  168. package/dist/utxo/btc/tools/asset_outpoint.d.ts.map +1 -0
  169. package/dist/utxo/btc/tools/asset_outpoint.js +12 -0
  170. package/dist/utxo/btc/tools/asset_outpoint.js.map +1 -0
  171. package/dist/utxo/btc/tools/bitcoin_core.tool.d.ts +41 -0
  172. package/dist/utxo/btc/tools/bitcoin_core.tool.d.ts.map +1 -0
  173. package/dist/utxo/btc/tools/bitcoin_core.tool.js +172 -0
  174. package/dist/utxo/btc/tools/bitcoin_core.tool.js.map +1 -0
  175. package/dist/utxo/btc/tools/esplora.tool.d.ts +27 -0
  176. package/dist/utxo/btc/tools/esplora.tool.d.ts.map +1 -0
  177. package/dist/utxo/btc/tools/esplora.tool.js +113 -0
  178. package/dist/utxo/btc/tools/esplora.tool.js.map +1 -0
  179. package/dist/utxo/btc/tools/inscription_index.d.ts +6 -0
  180. package/dist/utxo/btc/tools/inscription_index.d.ts.map +1 -0
  181. package/dist/utxo/btc/tools/inscription_index.js +2 -0
  182. package/dist/utxo/btc/tools/inscription_index.js.map +1 -0
  183. package/dist/utxo/btc/tools/ordiscan.tool.d.ts +19 -0
  184. package/dist/utxo/btc/tools/ordiscan.tool.d.ts.map +1 -0
  185. package/dist/utxo/btc/tools/ordiscan.tool.js +53 -0
  186. package/dist/utxo/btc/tools/ordiscan.tool.js.map +1 -0
  187. package/dist/utxo/btc/tools/rare_sat_index.d.ts +6 -0
  188. package/dist/utxo/btc/tools/rare_sat_index.d.ts.map +1 -0
  189. package/dist/utxo/btc/tools/rare_sat_index.js +2 -0
  190. package/dist/utxo/btc/tools/rare_sat_index.js.map +1 -0
  191. package/dist/utxo/btc/tools/rune_index.d.ts +6 -0
  192. package/dist/utxo/btc/tools/rune_index.d.ts.map +1 -0
  193. package/dist/utxo/btc/tools/rune_index.js +2 -0
  194. package/dist/utxo/btc/tools/rune_index.js.map +1 -0
  195. package/dist/utxo/btc/tools/unisat.tool.d.ts +18 -0
  196. package/dist/utxo/btc/tools/unisat.tool.d.ts.map +1 -0
  197. package/dist/utxo/btc/tools/unisat.tool.js +49 -0
  198. package/dist/utxo/btc/tools/unisat.tool.js.map +1 -0
  199. package/dist/utxo/coin_selection.d.ts +29 -0
  200. package/dist/utxo/coin_selection.d.ts.map +1 -0
  201. package/dist/utxo/coin_selection.js +156 -0
  202. package/dist/utxo/coin_selection.js.map +1 -0
  203. package/dist/utxo/doge/doge_chains.d.ts +17 -0
  204. package/dist/utxo/doge/doge_chains.d.ts.map +1 -0
  205. package/dist/utxo/doge/doge_chains.js +28 -0
  206. package/dist/utxo/doge/doge_chains.js.map +1 -0
  207. package/dist/utxo/doge/index.d.ts +3 -0
  208. package/dist/utxo/doge/index.d.ts.map +1 -0
  209. package/dist/utxo/doge/index.js +3 -0
  210. package/dist/utxo/doge/index.js.map +1 -0
  211. package/dist/utxo/doge/network_params.d.ts +4 -0
  212. package/dist/utxo/doge/network_params.d.ts.map +1 -0
  213. package/dist/utxo/doge/network_params.js +24 -0
  214. package/dist/utxo/doge/network_params.js.map +1 -0
  215. package/dist/utxo/ecc.d.ts +2 -0
  216. package/dist/utxo/ecc.d.ts.map +1 -0
  217. package/dist/utxo/ecc.js +11 -0
  218. package/dist/utxo/ecc.js.map +1 -0
  219. package/dist/utxo/fee.d.ts +12 -0
  220. package/dist/utxo/fee.d.ts.map +1 -0
  221. package/dist/utxo/fee.js +51 -0
  222. package/dist/utxo/fee.js.map +1 -0
  223. package/dist/utxo/index.d.ts +20 -0
  224. package/dist/utxo/index.d.ts.map +1 -0
  225. package/dist/utxo/index.js +20 -0
  226. package/dist/utxo/index.js.map +1 -0
  227. package/dist/utxo/ltc/index.d.ts +3 -0
  228. package/dist/utxo/ltc/index.d.ts.map +1 -0
  229. package/dist/utxo/ltc/index.js +3 -0
  230. package/dist/utxo/ltc/index.js.map +1 -0
  231. package/dist/utxo/ltc/ltc_chains.d.ts +17 -0
  232. package/dist/utxo/ltc/ltc_chains.d.ts.map +1 -0
  233. package/dist/utxo/ltc/ltc_chains.js +28 -0
  234. package/dist/utxo/ltc/ltc_chains.js.map +1 -0
  235. package/dist/utxo/ltc/network_params.d.ts +4 -0
  236. package/dist/utxo/ltc/network_params.d.ts.map +1 -0
  237. package/dist/utxo/ltc/network_params.js +27 -0
  238. package/dist/utxo/ltc/network_params.js.map +1 -0
  239. package/dist/utxo/script.d.ts +16 -0
  240. package/dist/utxo/script.d.ts.map +1 -0
  241. package/dist/utxo/script.js +52 -0
  242. package/dist/utxo/script.js.map +1 -0
  243. package/dist/utxo/tools/broadcaster.d.ts +6 -0
  244. package/dist/utxo/tools/broadcaster.d.ts.map +1 -0
  245. package/dist/utxo/tools/broadcaster.js +2 -0
  246. package/dist/utxo/tools/broadcaster.js.map +1 -0
  247. package/dist/utxo/tools/chain_tip_provider.d.ts +5 -0
  248. package/dist/utxo/tools/chain_tip_provider.d.ts.map +1 -0
  249. package/dist/utxo/tools/chain_tip_provider.js +2 -0
  250. package/dist/utxo/tools/chain_tip_provider.js.map +1 -0
  251. package/dist/utxo/tools/fee_estimator.d.ts +6 -0
  252. package/dist/utxo/tools/fee_estimator.d.ts.map +1 -0
  253. package/dist/utxo/tools/fee_estimator.js +2 -0
  254. package/dist/utxo/tools/fee_estimator.js.map +1 -0
  255. package/dist/utxo/tools/raw_transaction_provider.d.ts +8 -0
  256. package/dist/utxo/tools/raw_transaction_provider.d.ts.map +1 -0
  257. package/dist/utxo/tools/raw_transaction_provider.js +2 -0
  258. package/dist/utxo/tools/raw_transaction_provider.js.map +1 -0
  259. package/dist/utxo/tools/utxo_provider.d.ts +7 -0
  260. package/dist/utxo/tools/utxo_provider.d.ts.map +1 -0
  261. package/dist/utxo/tools/utxo_provider.js +2 -0
  262. package/dist/utxo/tools/utxo_provider.js.map +1 -0
  263. package/dist/utxo/unsigned_utxo_transaction.d.ts +32 -0
  264. package/dist/utxo/unsigned_utxo_transaction.d.ts.map +1 -0
  265. package/dist/utxo/unsigned_utxo_transaction.js +32 -0
  266. package/dist/utxo/unsigned_utxo_transaction.js.map +1 -0
  267. package/dist/utxo/utxo.d.ts +43 -0
  268. package/dist/utxo/utxo.d.ts.map +1 -0
  269. package/dist/utxo/utxo.js +2 -0
  270. package/dist/utxo/utxo.js.map +1 -0
  271. package/dist/utxo/utxo_chain.d.ts +102 -0
  272. package/dist/utxo/utxo_chain.d.ts.map +1 -0
  273. package/dist/utxo/utxo_chain.js +524 -0
  274. package/dist/utxo/utxo_chain.js.map +1 -0
  275. package/dist/utxo/utxo_chains.d.ts +29 -0
  276. package/dist/utxo/utxo_chains.d.ts.map +1 -0
  277. package/dist/utxo/utxo_chains.js +63 -0
  278. package/dist/utxo/utxo_chains.js.map +1 -0
  279. package/dist/utxo/utxo_gas_pricing.d.ts +22 -0
  280. package/dist/utxo/utxo_gas_pricing.d.ts.map +1 -0
  281. package/dist/utxo/utxo_gas_pricing.js +20 -0
  282. package/dist/utxo/utxo_gas_pricing.js.map +1 -0
  283. package/dist/utxo/utxo_network_params.d.ts +25 -0
  284. package/dist/utxo/utxo_network_params.d.ts.map +1 -0
  285. package/dist/utxo/utxo_network_params.js +15 -0
  286. package/dist/utxo/utxo_network_params.js.map +1 -0
  287. package/dist/utxo/utxo_transaction_status.d.ts +73 -0
  288. package/dist/utxo/utxo_transaction_status.d.ts.map +1 -0
  289. package/dist/utxo/utxo_transaction_status.js +89 -0
  290. package/dist/utxo/utxo_transaction_status.js.map +1 -0
  291. package/docs/PUBLISHING.md +119 -0
  292. package/docs/README.md +273 -0
  293. package/docs/evm.md +205 -0
  294. package/docs/solana.md +220 -0
  295. package/docs/utxo.md +364 -0
  296. package/package.json +94 -0
@@ -0,0 +1,26 @@
1
+ import { PublicKey } from '@solana/web3.js';
2
+ import { NetworkType } from "../network_type.js";
3
+ import { UnsignedTransaction } from "../unsigned_transaction.js";
4
+ export class UnsignedSolanaTransaction extends UnsignedTransaction {
5
+ transaction;
6
+ feePayer;
7
+ recentBlockhash;
8
+ lastValidBlockHeight;
9
+ instructions;
10
+ constructor(init) {
11
+ super(init.chainId, NetworkType.SOLANA);
12
+ this.transaction = init.transaction;
13
+ this.feePayer = init.feePayer;
14
+ this.recentBlockhash = init.recentBlockhash;
15
+ this.lastValidBlockHeight = init.lastValidBlockHeight;
16
+ this.instructions = init.instructions;
17
+ }
18
+ /** Serializes the message (without signatures). Useful for off-line signers / tests. */
19
+ messageBytes() {
20
+ return this.transaction.message.serialize();
21
+ }
22
+ get feePayerPubkey() {
23
+ return new PublicKey(this.feePayer);
24
+ }
25
+ }
26
+ //# sourceMappingURL=unsigned_solana_transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unsigned_solana_transaction.js","sourceRoot":"","sources":["../../solana/unsigned_solana_transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAgD,MAAM,iBAAiB,CAAC;AAE1F,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAoBjE,MAAM,OAAO,yBAA0B,SAAQ,mBAAmB;IACvD,WAAW,CAAuB;IAClC,QAAQ,CAAS;IACjB,eAAe,CAAS;IACxB,oBAAoB,CAAS;IAC7B,YAAY,CAA2B;IAEhD,YAAY,IAAmC;QAC7C,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;QACxC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACpC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAC5C,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,CAAC;QACtD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;IACxC,CAAC;IAED,wFAAwF;IACxF,YAAY;QACV,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;IAC9C,CAAC;IAED,IAAI,cAAc;QAChB,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;CACF"}
@@ -0,0 +1,35 @@
1
+ export declare abstract class Token {
2
+ readonly chainId: number;
3
+ readonly symbol: string;
4
+ readonly identifier?: string;
5
+ readonly decimals: number;
6
+ protected constructor(chainId: number, symbol: string, identifier: string | undefined, decimals: number);
7
+ isNative(): boolean;
8
+ /**
9
+ * Identity is `(chainId, symbol, identifier)` — decimals is deliberately
10
+ * NOT part of equality. Mirrors omnichain-py/base/base.py:60-65
11
+ * (`AbstractAsset.__eq__`).
12
+ *
13
+ * **Do NOT use `equals` as a precondition for amount scaling** — two Token
14
+ * instances can compare equal while disagreeing on decimals. For that
15
+ * safety check use `strictEquals(other)` (which includes decimals).
16
+ *
17
+ * For identifier-only comparison (ignoring both symbol drift and decimals),
18
+ * use `sameAsset(other)`.
19
+ */
20
+ equals(other: Token): boolean;
21
+ /**
22
+ * Strict equality including `decimals`. Use before parseUnits-style
23
+ * conversions where a mismatched decimals would silently mis-scale amounts.
24
+ */
25
+ strictEquals(other: Token): boolean;
26
+ /**
27
+ * Identifier-only equality — same chain + same contract address / mint /
28
+ * native marker, regardless of symbol drift (e.g. `'USDT'` vs `'USD₮0'`
29
+ * for Arbitrum USDT). Useful for registry / lookup paths where the
30
+ * consumer might not know the canonical symbol.
31
+ */
32
+ sameAsset(other: Token): boolean;
33
+ toString(): string;
34
+ }
35
+ //# sourceMappingURL=token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../token.ts"],"names":[],"mappings":"AAEA,8BAAsB,KAAK;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE1B,SAAS,aACP,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,QAAQ,EAAE,MAAM;IAoBlB,QAAQ,IAAI,OAAO;IAInB;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAQ7B;;;OAGG;IACH,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAInC;;;;;OAKG;IACH,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAIhC,QAAQ,IAAI,MAAM;CAGnB"}
package/dist/token.js ADDED
@@ -0,0 +1,62 @@
1
+ import { ChainError, ChainErrorKinds } from "./errors.js";
2
+ export class Token {
3
+ chainId;
4
+ symbol;
5
+ identifier;
6
+ decimals;
7
+ constructor(chainId, symbol, identifier, decimals) {
8
+ if (!Number.isInteger(chainId)) {
9
+ throw new ChainError(ChainErrorKinds.InvalidArgument, 'Token chainId must be an integer');
10
+ }
11
+ if (!symbol) {
12
+ throw new ChainError(ChainErrorKinds.InvalidArgument, 'Token symbol is required');
13
+ }
14
+ if (!Number.isInteger(decimals) || decimals < 0) {
15
+ throw new ChainError(ChainErrorKinds.InvalidArgument, 'Token decimals must be a non-negative integer');
16
+ }
17
+ this.chainId = chainId;
18
+ this.symbol = symbol;
19
+ this.identifier = identifier;
20
+ this.decimals = decimals;
21
+ }
22
+ isNative() {
23
+ return this.identifier === undefined;
24
+ }
25
+ /**
26
+ * Identity is `(chainId, symbol, identifier)` — decimals is deliberately
27
+ * NOT part of equality. Mirrors omnichain-py/base/base.py:60-65
28
+ * (`AbstractAsset.__eq__`).
29
+ *
30
+ * **Do NOT use `equals` as a precondition for amount scaling** — two Token
31
+ * instances can compare equal while disagreeing on decimals. For that
32
+ * safety check use `strictEquals(other)` (which includes decimals).
33
+ *
34
+ * For identifier-only comparison (ignoring both symbol drift and decimals),
35
+ * use `sameAsset(other)`.
36
+ */
37
+ equals(other) {
38
+ return (this.chainId === other.chainId &&
39
+ this.symbol === other.symbol &&
40
+ this.identifier === other.identifier);
41
+ }
42
+ /**
43
+ * Strict equality including `decimals`. Use before parseUnits-style
44
+ * conversions where a mismatched decimals would silently mis-scale amounts.
45
+ */
46
+ strictEquals(other) {
47
+ return this.equals(other) && this.decimals === other.decimals;
48
+ }
49
+ /**
50
+ * Identifier-only equality — same chain + same contract address / mint /
51
+ * native marker, regardless of symbol drift (e.g. `'USDT'` vs `'USD₮0'`
52
+ * for Arbitrum USDT). Useful for registry / lookup paths where the
53
+ * consumer might not know the canonical symbol.
54
+ */
55
+ sameAsset(other) {
56
+ return this.chainId === other.chainId && this.identifier === other.identifier;
57
+ }
58
+ toString() {
59
+ return `Token[chainId=${this.chainId}, symbol=${this.symbol}, identifier=${this.identifier ?? 'NATIVE'}, decimals=${this.decimals}]`;
60
+ }
61
+ }
62
+ //# sourceMappingURL=token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.js","sourceRoot":"","sources":["../token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,OAAgB,KAAK;IAChB,OAAO,CAAS;IAChB,MAAM,CAAS;IACf,UAAU,CAAU;IACpB,QAAQ,CAAS;IAE1B,YACE,OAAe,EACf,MAAc,EACd,UAA8B,EAC9B,QAAgB;QAEhB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;IAChF,CAAC;IAED,QAAQ;QACN,OAAO,iBAAiB,IAAI,CAAC,OAAO,YAAY,IAAI,CAAC,MAAM,gBAAgB,IAAI,CAAC,UAAU,IAAI,QAAQ,cAAc,IAAI,CAAC,QAAQ,GAAG,CAAC;IACvI,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export * from './ton_address.ts';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../ton/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./ton_address.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../ton/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { NetworkType } from '../network_type.ts';
2
+ import { Address } from '../address.ts';
3
+ export declare class TonAddress extends Address {
4
+ constructor(raw: string);
5
+ canonical(): string;
6
+ get networkType(): NetworkType;
7
+ private static assertValid;
8
+ private static assertUserFriendlyChecksum;
9
+ }
10
+ //# sourceMappingURL=ton_address.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ton_address.d.ts","sourceRoot":"","sources":["../../ton/ton_address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAOxC,qBAAa,UAAW,SAAQ,OAAO;gBACzB,GAAG,EAAE,MAAM;IAKvB,SAAS,IAAI,MAAM;IAInB,IAAI,WAAW,IAAI,WAAW,CAE7B;IAED,OAAO,CAAC,MAAM,CAAC,WAAW;IAY1B,OAAO,CAAC,MAAM,CAAC,0BAA0B;CAc1C"}
@@ -0,0 +1,53 @@
1
+ import { NetworkType } from "../network_type.js";
2
+ import { Address } from "../address.js";
3
+ const TON_USER_FRIENDLY_REGEX = /^[A-Za-z0-9_-]{48}$/;
4
+ const TON_RAW_REGEX = /^-?\d+:[a-fA-F0-9]{64}$/;
5
+ const USER_FRIENDLY_BYTE_LENGTH = 36;
6
+ const CRC_POLYNOMIAL = 0x1021;
7
+ export class TonAddress extends Address {
8
+ constructor(raw) {
9
+ super(raw);
10
+ TonAddress.assertValid(raw);
11
+ }
12
+ canonical() {
13
+ return this.raw;
14
+ }
15
+ get networkType() {
16
+ return NetworkType.TON;
17
+ }
18
+ static assertValid(raw) {
19
+ if (typeof raw !== 'string') {
20
+ throw new Error(`Invalid TON address: not a string`);
21
+ }
22
+ if (TON_RAW_REGEX.test(raw))
23
+ return;
24
+ if (TON_USER_FRIENDLY_REGEX.test(raw)) {
25
+ TonAddress.assertUserFriendlyChecksum(raw);
26
+ return;
27
+ }
28
+ throw new Error(`Invalid TON address: "${raw}"`);
29
+ }
30
+ static assertUserFriendlyChecksum(userFriendly) {
31
+ const bytes = Buffer.from(userFriendly.replace(/-/g, '+').replace(/_/g, '/'), 'base64');
32
+ if (bytes.length !== USER_FRIENDLY_BYTE_LENGTH) {
33
+ throw new Error(`Invalid TON address: "${userFriendly}"`);
34
+ }
35
+ const claimedCrc = (bytes[34] << 8) | bytes[35];
36
+ const computedCrc = crc16CcittXmodem(bytes.subarray(0, 34));
37
+ if (claimedCrc !== computedCrc) {
38
+ throw new Error(`Invalid TON address checksum: "${userFriendly}"`);
39
+ }
40
+ }
41
+ }
42
+ function crc16CcittXmodem(bytes) {
43
+ let crc = 0;
44
+ for (const byte of bytes) {
45
+ crc ^= byte << 8;
46
+ for (let bit = 0; bit < 8; bit++) {
47
+ crc =
48
+ (crc & 0x8000) !== 0 ? ((crc << 1) ^ CRC_POLYNOMIAL) & 0xffff : (crc << 1) & 0xffff;
49
+ }
50
+ }
51
+ return crc;
52
+ }
53
+ //# sourceMappingURL=ton_address.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ton_address.js","sourceRoot":"","s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,CAAC;YAC/C,MAAM,IAAI,KAAK,CAAC,yBAAyB,YAAY,GAAG,CAAC,CAAC;QAC5D,CAAC;QACD,MAAM,UAAU,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC;QAChD,MAAM,WAAW,GAAG,gBAAgB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QAC5D,IAAI,UAAU,KAAK,WAAW,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,kCAAkC,YAAY,GAAG,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;CACF;AAED,SAAS,gBAAgB,CAAC,KAAiB;IACzC,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,GAAG,IAAI,IAAI,IAAI,CAAC,CAAC;QACjB,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC;YACjC,GAAG;gBACD,CAAC,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,cAAc,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC;QACxF,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,140 @@
1
+ import { Decimal } from 'decimal.js';
2
+ import { Token } from './token.ts';
3
+ /**
4
+ * Exact `Decimal → bigint minor-units` conversion. Uses `toFixed(decimals,
5
+ * ROUND_DOWN)` — this path is NOT bounded by `Decimal.precision` — plus
6
+ * a string shift, so `new Decimal('123.456789012345678901')` with
7
+ * `decimals=18` yields exactly `123456789012345678901n` instead of the
8
+ * `.mul(1e18).trunc()` path's rounded-then-truncated `123456789012345678900n`.
9
+ * Verified against decimal.js 10.6.0.
10
+ */
11
+ export declare function hrDecimalToMinorUnits(hr: Decimal, decimals: number): bigint;
12
+ /**
13
+ * Exact `bigint minor-units → decimal-string` for human-readable display.
14
+ * Bypasses `Decimal.div` (also precision-bounded at 20), so
15
+ * `AssetBalanceChange.fromMr(123_456_789_012_345_678_901n, 18)` renders
16
+ * as `"123.456789012345678901"` — no wei lost.
17
+ */
18
+ export declare function minorUnitsToHrString(mr: bigint, decimals: number): string;
19
+ export declare const TransactionStatusTypes: {
20
+ readonly Success: "Success";
21
+ readonly Failed: "Failed";
22
+ readonly Pending: "Pending";
23
+ readonly NotFound: "NotFound";
24
+ };
25
+ export type TransactionStatusType = (typeof TransactionStatusTypes)[keyof typeof TransactionStatusTypes];
26
+ /**
27
+ * Stable identity key for a token in `NestedBalanceChanges`. Uses
28
+ * `(chainId, identifier)` — matches `Token.sameAsset` identity. `symbol`
29
+ * comes from a live `contract.symbol()` on EVM and falls back to
30
+ * `UNKNOWN_<hex>` on RPC failure, so keying on it produces different keys
31
+ * for the same asset across transient RPC health. `decimals` is likewise
32
+ * omitted (already dropped in iter 1) — Solana `uiTokenAmount.decimals`
33
+ * variance would otherwise split one asset into two non-cancelling rows.
34
+ * `symbol`/`decimals` are preserved on the stored entry's `token` for display.
35
+ */
36
+ export declare function assetHashOf(token: Token): string;
37
+ export interface AssetBalanceChangeEntry {
38
+ token: Token;
39
+ change: AssetBalanceChange;
40
+ }
41
+ export type NestedBalanceChanges = Map<string, Map<string, AssetBalanceChangeEntry>>;
42
+ /**
43
+ * Per-(wallet, asset) balance delta. Source of truth is `balanceChangeMr`
44
+ * (bigint minor units) — exact and native to every on-chain representation.
45
+ *
46
+ * Wave 2B adds the Python-parity `balanceChangeHr: Decimal` accessor as a
47
+ * lazy getter derived from `mr / 10^decimals`. Storage flip vs Python
48
+ * (which stores `balance_change_hr: Decimal` and computes `mr` in the
49
+ * constructor): decimal.js defaults to 20 significant digits, so
50
+ * 18-decimal amounts ≥ ~100 tokens silently truncate on Decimal → bigint
51
+ * round-trip. Storing bigint keeps every wei/lamport/satoshi exact; the
52
+ * Decimal getter inherits decimal.js precision limits but never influences
53
+ * `.balanceChangeMr` on read.
54
+ */
55
+ export declare class AssetBalanceChange {
56
+ readonly balanceChangeMr: bigint;
57
+ readonly decimals: number;
58
+ constructor(balanceChangeMr: bigint, decimals: number);
59
+ static zero(decimals?: number): AssetBalanceChange;
60
+ static fromMr(balanceChangeMr: bigint, decimals: number): AssetBalanceChange;
61
+ /**
62
+ * Python-parity factory (`AssetBalanceChange.__init__` in
63
+ * `base/base.py:239-247` takes `balance_change_hr: Decimal`). Accepts a
64
+ * `Decimal` directly or any string/number that `new Decimal(...)`
65
+ * parses. Rounds sub-minor-unit fractional bits DOWN matching Python's
66
+ * `hr_to_mr`. Uses the exact string-shift path (`toFixed(decimals,
67
+ * ROUND_DOWN)` + digit concat) rather than `.mul(10^d).trunc()` — the
68
+ * `.mul` route is precision-bounded by decimal.js's 20-sig-digit
69
+ * default and would round the last wei on 18-decimal amounts ≥
70
+ * ~100 tokens.
71
+ */
72
+ static fromHr(balanceChangeHr: Decimal | string | number, decimals: number): AssetBalanceChange;
73
+ /**
74
+ * Human-readable amount as a `Decimal` — mirrors Python's
75
+ * `AbstractAssetBalanceChange.balance_change_hr`. Derived lazily from
76
+ * the bigint source-of-truth via an EXACT string-shift path
77
+ * (`minorUnitsToHrString`) so the returned `Decimal` carries every
78
+ * wei/lamport/satoshi. Note: consumers reading the `Decimal` and
79
+ * feeding it back through decimal.js arithmetic (`.mul`, `.div`)
80
+ * may still lose precision at decimal.js's 20-sig-digit default —
81
+ * for exact reconciliation stay on `balanceChangeMr`.
82
+ */
83
+ get balanceChangeHr(): Decimal;
84
+ /**
85
+ * Sum two changes. Uses `this.decimals` for the result — mirrors Python
86
+ * `AbstractAssetBalanceChange.__add__` (base/base.py:239-311) which
87
+ * uses `self._decimals`. No decimals-mismatch check; consumers that
88
+ * care compare `.decimals` themselves before adding.
89
+ */
90
+ add(other: AssetBalanceChange): AssetBalanceChange;
91
+ /**
92
+ * Merge `change` into `balanceChanges[wallet][assetHash]`. Mirrors
93
+ * Python `AssetBalanceChange.upsert` (base/base.py:255-287): mutating,
94
+ * returns void; zero-net collapses both the asset row and the wallet
95
+ * row (when the wallet's inner map empties); on non-zero-net merge the
96
+ * newer `change.decimals` wins (Python uses `change._decimals`, not
97
+ * `existing._decimals`).
98
+ *
99
+ * No decimals-mismatch throw. Python does not check either — the newer
100
+ * change's decimals silently win. Consumers with a decimals-consistency
101
+ * requirement enforce it externally.
102
+ */
103
+ static upsert(balanceChanges: NestedBalanceChanges, wallet: string, token: Token, change: AssetBalanceChange): void;
104
+ toString(): string;
105
+ }
106
+ export interface TransactionErrorInfo {
107
+ code?: string;
108
+ reason?: string;
109
+ }
110
+ export interface TransactionStatusInit {
111
+ chainId: number;
112
+ status: TransactionStatusType;
113
+ inclusionAt?: Date | null;
114
+ error?: TransactionErrorInfo | null;
115
+ balanceChanges?: NestedBalanceChanges | null;
116
+ }
117
+ export declare abstract class TransactionStatus {
118
+ readonly chainId: number;
119
+ readonly status: TransactionStatusType;
120
+ readonly inclusionAt: Date | null;
121
+ readonly error: TransactionErrorInfo | null;
122
+ readonly balanceChanges: NestedBalanceChanges | null;
123
+ protected constructor(init: TransactionStatusInit);
124
+ }
125
+ export declare function isSuccess(s: TransactionStatus): s is TransactionStatus & {
126
+ balanceChanges: NestedBalanceChanges;
127
+ error: null;
128
+ };
129
+ export declare function isFailed(s: TransactionStatus): s is TransactionStatus & {
130
+ balanceChanges: null;
131
+ error: TransactionErrorInfo;
132
+ };
133
+ export declare function isPending(s: TransactionStatus): s is TransactionStatus & {
134
+ balanceChanges: null;
135
+ error: null;
136
+ };
137
+ export declare function isNotFound(s: TransactionStatus): s is TransactionStatus & {
138
+ balanceChanges: null;
139
+ };
140
+ //# sourceMappingURL=transaction_status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction_status.d.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C,IAAI,iBAAiB,GAAG;IAAE,cAAc,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,oBAAoB,CAAA;CAAE,CAEhF;AAED,wBAAgB,SAAS,CACvB,CAAC,EAAE,iBAAiB,GACnB,CAAC,IAAI,iBAAiB,GAAG;IAAE,cAAc,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAE,CAEhE;AAED,wBAAgB,UAAU,CACxB,CAAC,EAAE,iBAAiB,GACnB,CAAC,IAAI,iBAAiB,GAAG;IAAE,cAAc,EAAE,IAAI,CAAA;CAAE,CAEnD"}
@@ -0,0 +1,271 @@
1
+ import { Decimal } from 'decimal.js';
2
+ import { ChainError, ChainErrorKinds } from "./errors.js";
3
+ /**
4
+ * Exact `Decimal → bigint minor-units` conversion. Uses `toFixed(decimals,
5
+ * ROUND_DOWN)` — this path is NOT bounded by `Decimal.precision` — plus
6
+ * a string shift, so `new Decimal('123.456789012345678901')` with
7
+ * `decimals=18` yields exactly `123456789012345678901n` instead of the
8
+ * `.mul(1e18).trunc()` path's rounded-then-truncated `123456789012345678900n`.
9
+ * Verified against decimal.js 10.6.0.
10
+ */
11
+ export function hrDecimalToMinorUnits(hr, decimals) {
12
+ // toFixed always emits a plain decimal representation (never scientific).
13
+ // ROUND_DOWN = 1 truncates toward zero, matching Python's `hr_to_mr`.
14
+ const fixed = hr.toFixed(decimals, Decimal.ROUND_DOWN);
15
+ const negative = fixed.startsWith('-');
16
+ const unsigned = negative ? fixed.slice(1) : fixed;
17
+ const dot = unsigned.indexOf('.');
18
+ const intPart = dot === -1 ? unsigned : unsigned.slice(0, dot);
19
+ const fracPart = dot === -1 ? '' : unsigned.slice(dot + 1);
20
+ const padded = fracPart.padEnd(decimals, '0').slice(0, decimals);
21
+ const digits = (intPart + padded).replace(/^0+(?=\d)/, '') || '0';
22
+ const mag = BigInt(digits);
23
+ return negative ? -mag : mag;
24
+ }
25
+ /**
26
+ * Exact `bigint minor-units → decimal-string` for human-readable display.
27
+ * Bypasses `Decimal.div` (also precision-bounded at 20), so
28
+ * `AssetBalanceChange.fromMr(123_456_789_012_345_678_901n, 18)` renders
29
+ * as `"123.456789012345678901"` — no wei lost.
30
+ */
31
+ export function minorUnitsToHrString(mr, decimals) {
32
+ const negative = mr < 0n;
33
+ const digits = (negative ? -mr : mr).toString();
34
+ if (decimals === 0)
35
+ return negative ? `-${digits}` : digits;
36
+ const padded = digits.padStart(decimals + 1, '0');
37
+ const intPart = padded.slice(0, padded.length - decimals);
38
+ const fracPart = padded.slice(padded.length - decimals).replace(/0+$/, '');
39
+ const s = fracPart.length === 0 ? intPart : `${intPart}.${fracPart}`;
40
+ return negative ? `-${s}` : s;
41
+ }
42
+ export const TransactionStatusTypes = {
43
+ Success: 'Success',
44
+ Failed: 'Failed',
45
+ Pending: 'Pending',
46
+ NotFound: 'NotFound',
47
+ };
48
+ /**
49
+ * Stable identity key for a token in `NestedBalanceChanges`. Uses
50
+ * `(chainId, identifier)` — matches `Token.sameAsset` identity. `symbol`
51
+ * comes from a live `contract.symbol()` on EVM and falls back to
52
+ * `UNKNOWN_<hex>` on RPC failure, so keying on it produces different keys
53
+ * for the same asset across transient RPC health. `decimals` is likewise
54
+ * omitted (already dropped in iter 1) — Solana `uiTokenAmount.decimals`
55
+ * variance would otherwise split one asset into two non-cancelling rows.
56
+ * `symbol`/`decimals` are preserved on the stored entry's `token` for display.
57
+ */
58
+ export function assetHashOf(token) {
59
+ return `${token.chainId}_${token.identifier ?? ''}`;
60
+ }
61
+ /**
62
+ * Per-(wallet, asset) balance delta. Source of truth is `balanceChangeMr`
63
+ * (bigint minor units) — exact and native to every on-chain representation.
64
+ *
65
+ * Wave 2B adds the Python-parity `balanceChangeHr: Decimal` accessor as a
66
+ * lazy getter derived from `mr / 10^decimals`. Storage flip vs Python
67
+ * (which stores `balance_change_hr: Decimal` and computes `mr` in the
68
+ * constructor): decimal.js defaults to 20 significant digits, so
69
+ * 18-decimal amounts ≥ ~100 tokens silently truncate on Decimal → bigint
70
+ * round-trip. Storing bigint keeps every wei/lamport/satoshi exact; the
71
+ * Decimal getter inherits decimal.js precision limits but never influences
72
+ * `.balanceChangeMr` on read.
73
+ */
74
+ export class AssetBalanceChange {
75
+ balanceChangeMr;
76
+ decimals;
77
+ constructor(balanceChangeMr, decimals) {
78
+ if (!Number.isInteger(decimals) || decimals < 0) {
79
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `AssetBalanceChange decimals must be a non-negative integer, got ${decimals}`);
80
+ }
81
+ this.balanceChangeMr = balanceChangeMr;
82
+ this.decimals = decimals;
83
+ }
84
+ static zero(decimals = 0) {
85
+ return new AssetBalanceChange(0n, decimals);
86
+ }
87
+ static fromMr(balanceChangeMr, decimals) {
88
+ return new AssetBalanceChange(balanceChangeMr, decimals);
89
+ }
90
+ /**
91
+ * Python-parity factory (`AssetBalanceChange.__init__` in
92
+ * `base/base.py:239-247` takes `balance_change_hr: Decimal`). Accepts a
93
+ * `Decimal` directly or any string/number that `new Decimal(...)`
94
+ * parses. Rounds sub-minor-unit fractional bits DOWN matching Python's
95
+ * `hr_to_mr`. Uses the exact string-shift path (`toFixed(decimals,
96
+ * ROUND_DOWN)` + digit concat) rather than `.mul(10^d).trunc()` — the
97
+ * `.mul` route is precision-bounded by decimal.js's 20-sig-digit
98
+ * default and would round the last wei on 18-decimal amounts ≥
99
+ * ~100 tokens.
100
+ */
101
+ static fromHr(balanceChangeHr, decimals) {
102
+ // Nested-copy-safe: for Decimal-shaped objects use string round-trip
103
+ // via toString() (exact and always reparseable), not `instanceof`
104
+ // which fails on a Decimal from a duplicated decimal.js copy in
105
+ // the consumer tree. Strings and numbers go straight through
106
+ // decimal.js's own constructor.
107
+ let hr;
108
+ try {
109
+ if (typeof balanceChangeHr === 'object' &&
110
+ balanceChangeHr !== null &&
111
+ typeof balanceChangeHr.toFixed === 'function' &&
112
+ typeof balanceChangeHr.toString === 'function') {
113
+ hr = new Decimal(balanceChangeHr.toString());
114
+ }
115
+ else {
116
+ hr = new Decimal(balanceChangeHr);
117
+ }
118
+ }
119
+ catch (err) {
120
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `AssetBalanceChange.fromHr: unparseable input ${String(balanceChangeHr)}`, undefined, err instanceof Error ? err : undefined);
121
+ }
122
+ if (!hr.isFinite()) {
123
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `AssetBalanceChange.fromHr: input must be finite (got ${hr.toString()})`);
124
+ }
125
+ if (!Number.isInteger(decimals) || decimals < 0) {
126
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `AssetBalanceChange.fromHr: decimals must be a non-negative integer (got ${decimals})`);
127
+ }
128
+ return new AssetBalanceChange(hrDecimalToMinorUnits(hr, decimals), decimals);
129
+ }
130
+ /**
131
+ * Human-readable amount as a `Decimal` — mirrors Python's
132
+ * `AbstractAssetBalanceChange.balance_change_hr`. Derived lazily from
133
+ * the bigint source-of-truth via an EXACT string-shift path
134
+ * (`minorUnitsToHrString`) so the returned `Decimal` carries every
135
+ * wei/lamport/satoshi. Note: consumers reading the `Decimal` and
136
+ * feeding it back through decimal.js arithmetic (`.mul`, `.div`)
137
+ * may still lose precision at decimal.js's 20-sig-digit default —
138
+ * for exact reconciliation stay on `balanceChangeMr`.
139
+ */
140
+ get balanceChangeHr() {
141
+ return new Decimal(minorUnitsToHrString(this.balanceChangeMr, this.decimals));
142
+ }
143
+ /**
144
+ * Sum two changes. Uses `this.decimals` for the result — mirrors Python
145
+ * `AbstractAssetBalanceChange.__add__` (base/base.py:239-311) which
146
+ * uses `self._decimals`. No decimals-mismatch check; consumers that
147
+ * care compare `.decimals` themselves before adding.
148
+ */
149
+ add(other) {
150
+ return new AssetBalanceChange(this.balanceChangeMr + other.balanceChangeMr, this.decimals);
151
+ }
152
+ /**
153
+ * Merge `change` into `balanceChanges[wallet][assetHash]`. Mirrors
154
+ * Python `AssetBalanceChange.upsert` (base/base.py:255-287): mutating,
155
+ * returns void; zero-net collapses both the asset row and the wallet
156
+ * row (when the wallet's inner map empties); on non-zero-net merge the
157
+ * newer `change.decimals` wins (Python uses `change._decimals`, not
158
+ * `existing._decimals`).
159
+ *
160
+ * No decimals-mismatch throw. Python does not check either — the newer
161
+ * change's decimals silently win. Consumers with a decimals-consistency
162
+ * requirement enforce it externally.
163
+ */
164
+ static upsert(balanceChanges, wallet, token, change) {
165
+ const hash = assetHashOf(token);
166
+ let perWallet = balanceChanges.get(wallet);
167
+ if (!perWallet) {
168
+ perWallet = new Map();
169
+ balanceChanges.set(wallet, perWallet);
170
+ }
171
+ const existing = perWallet.get(hash);
172
+ if (!existing) {
173
+ // Symmetric with the zero-net merge branch below: don't create a
174
+ // "no change" row for a zero delta. balanceChangesExcludingFees
175
+ // can hit this when a fee_payer with no existing row is credited
176
+ // with fee_lamports === 0n (subsidised chains). If the perWallet
177
+ // Map was just created for this insert, drop it to keep the
178
+ // container empty.
179
+ if (change.balanceChangeMr === 0n) {
180
+ if (perWallet.size === 0)
181
+ balanceChanges.delete(wallet);
182
+ return;
183
+ }
184
+ perWallet.set(hash, { token, change });
185
+ return;
186
+ }
187
+ const netMr = existing.change.balanceChangeMr + change.balanceChangeMr;
188
+ if (netMr === 0n) {
189
+ perWallet.delete(hash);
190
+ if (perWallet.size === 0)
191
+ balanceChanges.delete(wallet);
192
+ return;
193
+ }
194
+ perWallet.set(hash, {
195
+ token,
196
+ change: new AssetBalanceChange(netMr, change.decimals),
197
+ });
198
+ }
199
+ toString() {
200
+ // Emit both the exact bigint (never lossy) and the human-readable
201
+ // string derived via minorUnitsToHrString (also exact — no decimal.js
202
+ // rounding). Neither field can drop wei.
203
+ return `[change:${minorUnitsToHrString(this.balanceChangeMr, this.decimals)}(hr) / ${this.balanceChangeMr}(mr)]`;
204
+ }
205
+ }
206
+ export class TransactionStatus {
207
+ chainId;
208
+ status;
209
+ inclusionAt;
210
+ error;
211
+ balanceChanges;
212
+ constructor(init) {
213
+ const { chainId, status } = init;
214
+ const inclusionAt = init.inclusionAt ?? null;
215
+ const error = init.error ?? null;
216
+ const balanceChanges = init.balanceChanges ?? null;
217
+ switch (status) {
218
+ case TransactionStatusTypes.Success:
219
+ if (balanceChanges === null) {
220
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `TransactionStatus(Success) requires balanceChanges; chainId=${chainId}`);
221
+ }
222
+ if (error !== null) {
223
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `TransactionStatus(Success) must have null error; chainId=${chainId}`);
224
+ }
225
+ break;
226
+ case TransactionStatusTypes.Failed:
227
+ if (balanceChanges !== null) {
228
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `TransactionStatus(Failed) must have null balanceChanges; chainId=${chainId}`);
229
+ }
230
+ if (error === null) {
231
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `TransactionStatus(Failed) requires error; chainId=${chainId}`);
232
+ }
233
+ break;
234
+ case TransactionStatusTypes.NotFound:
235
+ if (balanceChanges !== null) {
236
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `TransactionStatus(NotFound) must have null balanceChanges; chainId=${chainId}`);
237
+ }
238
+ break;
239
+ case TransactionStatusTypes.Pending:
240
+ if (balanceChanges !== null) {
241
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `TransactionStatus(Pending) must have null balanceChanges; chainId=${chainId}`);
242
+ }
243
+ if (error !== null) {
244
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `TransactionStatus(Pending) must have null error; chainId=${chainId}`);
245
+ }
246
+ break;
247
+ default: {
248
+ const _exhaustive = status;
249
+ throw new ChainError(ChainErrorKinds.InvalidArgument, `Unknown TransactionStatusType: ${String(_exhaustive)}`);
250
+ }
251
+ }
252
+ this.chainId = chainId;
253
+ this.status = status;
254
+ this.inclusionAt = inclusionAt;
255
+ this.error = error;
256
+ this.balanceChanges = balanceChanges;
257
+ }
258
+ }
259
+ export function isSuccess(s) {
260
+ return s.status === TransactionStatusTypes.Success;
261
+ }
262
+ export function isFailed(s) {
263
+ return s.status === TransactionStatusTypes.Failed;
264
+ }
265
+ export function isPending(s) {
266
+ return s.status === TransactionStatusTypes.Pending;
267
+ }
268
+ export function isNotFound(s) {
269
+ return s.status === TransactionStatusTypes.NotFound;
270
+ }
271
+ //# sourceMappingURL=transaction_status.js.map