@ton/appkit 0.0.5-alpha.3 → 1.0.0-alpha.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 (428) hide show
  1. package/.turbo/turbo-build.log +4 -4
  2. package/CHANGELOG.md +132 -0
  3. package/dist/cjs/actions/index.d.ts +8 -0
  4. package/dist/cjs/actions/index.d.ts.map +1 -1
  5. package/dist/cjs/actions/index.js +18 -2
  6. package/dist/cjs/actions/jettons/create-transfer-jetton-transaction.d.ts +1 -1
  7. package/dist/cjs/actions/jettons/create-transfer-jetton-transaction.d.ts.map +1 -1
  8. package/dist/cjs/actions/jettons/create-transfer-jetton-transaction.js +17 -5
  9. package/dist/cjs/actions/jettons/get-jetton-balance.d.ts +1 -1
  10. package/dist/cjs/actions/jettons/get-jetton-balance.d.ts.map +1 -1
  11. package/dist/cjs/actions/jettons/get-jetton-balance.js +8 -3
  12. package/dist/cjs/actions/jettons/get-jetton-info.d.ts.map +1 -1
  13. package/dist/cjs/actions/jettons/get-jetton-info.js +15 -6
  14. package/dist/cjs/actions/jettons/get-jetton-wallet-address.d.ts +1 -1
  15. package/dist/cjs/actions/jettons/get-jetton-wallet-address.d.ts.map +1 -1
  16. package/dist/cjs/actions/jettons/get-jetton-wallet-address.js +15 -4
  17. package/dist/cjs/actions/nft/get-nft.d.ts +1 -1
  18. package/dist/cjs/actions/nft/get-nft.d.ts.map +1 -1
  19. package/dist/cjs/actions/staking/get-staking-provider-metadata.d.ts +19 -0
  20. package/dist/cjs/actions/staking/get-staking-provider-metadata.d.ts.map +1 -0
  21. package/dist/cjs/actions/staking/get-staking-provider-metadata.js +18 -0
  22. package/dist/cjs/actions/staking/get-staking-provider.d.ts +21 -0
  23. package/dist/cjs/actions/staking/get-staking-provider.d.ts.map +1 -0
  24. package/dist/cjs/actions/staking/get-staking-provider.js +17 -0
  25. package/dist/cjs/actions/staking/get-staking-providers.d.ts +3 -2
  26. package/dist/cjs/actions/staking/get-staking-providers.d.ts.map +1 -1
  27. package/dist/cjs/actions/staking/get-staking-providers.js +2 -2
  28. package/dist/cjs/actions/staking/set-default-staking-provider.d.ts +18 -0
  29. package/dist/cjs/actions/staking/set-default-staking-provider.d.ts.map +1 -0
  30. package/dist/cjs/actions/staking/set-default-staking-provider.js +18 -0
  31. package/dist/cjs/actions/staking/watch-staking-providers.d.ts +17 -0
  32. package/dist/cjs/actions/staking/watch-staking-providers.d.ts.map +1 -0
  33. package/dist/cjs/actions/staking/watch-staking-providers.js +28 -0
  34. package/dist/cjs/actions/swap/get-swap-provider.d.ts +15 -0
  35. package/dist/cjs/actions/swap/get-swap-provider.d.ts.map +1 -0
  36. package/dist/cjs/actions/swap/get-swap-provider.js +14 -0
  37. package/dist/cjs/actions/swap/get-swap-providers.d.ts +15 -0
  38. package/dist/cjs/actions/swap/get-swap-providers.d.ts.map +1 -0
  39. package/dist/cjs/actions/swap/get-swap-providers.js +17 -0
  40. package/dist/cjs/actions/swap/get-swap-quote.d.ts.map +1 -1
  41. package/dist/cjs/actions/swap/get-swap-quote.js +6 -1
  42. package/dist/cjs/actions/swap/set-default-swap-provider.d.ts +18 -0
  43. package/dist/cjs/actions/swap/set-default-swap-provider.d.ts.map +1 -0
  44. package/dist/cjs/actions/swap/set-default-swap-provider.js +18 -0
  45. package/dist/cjs/actions/swap/watch-swap-providers.d.ts +17 -0
  46. package/dist/cjs/actions/swap/watch-swap-providers.d.ts.map +1 -0
  47. package/dist/cjs/actions/swap/watch-swap-providers.js +29 -0
  48. package/dist/cjs/connectors/tonconnect/connectors/ton-connect-connector.js +2 -2
  49. package/dist/cjs/core/app-kit/constants/events.d.ts +0 -6
  50. package/dist/cjs/core/app-kit/constants/events.d.ts.map +1 -1
  51. package/dist/cjs/core/app-kit/constants/events.js +1 -7
  52. package/dist/cjs/core/app-kit/index.d.ts +2 -2
  53. package/dist/cjs/core/app-kit/index.d.ts.map +1 -1
  54. package/dist/cjs/core/app-kit/index.js +1 -2
  55. package/dist/cjs/core/app-kit/services/app-kit.d.ts +3 -1
  56. package/dist/cjs/core/app-kit/services/app-kit.d.ts.map +1 -1
  57. package/dist/cjs/core/app-kit/services/app-kit.js +4 -2
  58. package/dist/cjs/core/app-kit/types/config.d.ts +4 -2
  59. package/dist/cjs/core/app-kit/types/config.d.ts.map +1 -1
  60. package/dist/cjs/core/app-kit/types/events.d.ts +2 -7
  61. package/dist/cjs/core/app-kit/types/events.d.ts.map +1 -1
  62. package/dist/cjs/core/cache/adapters/lru-app-kit-cache.d.ts +20 -0
  63. package/dist/cjs/core/cache/adapters/lru-app-kit-cache.d.ts.map +1 -0
  64. package/dist/cjs/core/cache/adapters/lru-app-kit-cache.js +32 -0
  65. package/dist/cjs/core/cache/adapters/lru-app-kit-cache.test.d.ts +9 -0
  66. package/dist/cjs/core/cache/adapters/lru-app-kit-cache.test.d.ts.map +1 -0
  67. package/dist/cjs/core/cache/adapters/lru-app-kit-cache.test.js +68 -0
  68. package/dist/cjs/core/cache/index.d.ts +11 -0
  69. package/dist/cjs/core/cache/index.d.ts.map +1 -0
  70. package/dist/cjs/core/cache/index.js +14 -0
  71. package/dist/cjs/core/cache/types/app-kit-cache.d.ts +14 -0
  72. package/dist/cjs/core/cache/types/app-kit-cache.d.ts.map +1 -0
  73. package/dist/cjs/core/cache/types/app-kit-cache.js +9 -0
  74. package/dist/cjs/core/cache/utils/get-cache-key.d.ts +9 -0
  75. package/dist/cjs/core/cache/utils/get-cache-key.d.ts.map +1 -0
  76. package/dist/cjs/core/cache/utils/get-cache-key.js +12 -0
  77. package/dist/cjs/core/cache/utils/get-cache-key.test.d.ts +9 -0
  78. package/dist/cjs/core/cache/utils/get-cache-key.test.d.ts.map +1 -0
  79. package/dist/cjs/core/cache/utils/get-cache-key.test.js +30 -0
  80. package/dist/cjs/index.d.ts +1 -0
  81. package/dist/cjs/index.d.ts.map +1 -1
  82. package/dist/cjs/index.js +1 -0
  83. package/dist/cjs/queries/balances/get-balance-by-address.d.ts.map +1 -1
  84. package/dist/cjs/queries/balances/get-balance-by-address.js +9 -3
  85. package/dist/cjs/queries/index.d.ts +0 -1
  86. package/dist/cjs/queries/index.d.ts.map +1 -1
  87. package/dist/cjs/queries/index.js +1 -3
  88. package/dist/cjs/queries/jettons/get-jetton-balance-by-address.d.ts.map +1 -1
  89. package/dist/cjs/queries/jettons/get-jetton-balance-by-address.js +11 -11
  90. package/dist/cjs/queries/jettons/get-jetton-info.d.ts.map +1 -1
  91. package/dist/cjs/queries/jettons/get-jetton-info.js +5 -1
  92. package/dist/cjs/queries/jettons/get-jetton-wallet-address.d.ts.map +1 -1
  93. package/dist/cjs/queries/jettons/get-jetton-wallet-address.js +6 -1
  94. package/dist/cjs/queries/jettons/get-jettons-by-address.d.ts.map +1 -1
  95. package/dist/cjs/queries/jettons/get-jettons-by-address.js +9 -3
  96. package/dist/cjs/queries/nft/get-nft.d.ts +1 -1
  97. package/dist/cjs/queries/nft/get-nft.d.ts.map +1 -1
  98. package/dist/cjs/queries/nft/get-nft.js +5 -1
  99. package/dist/cjs/queries/nft/get-nfts-by-address.d.ts.map +1 -1
  100. package/dist/cjs/queries/nft/get-nfts-by-address.js +5 -1
  101. package/dist/cjs/queries/staking/get-staked-balance.d.ts +1 -1
  102. package/dist/cjs/queries/staking/get-staked-balance.d.ts.map +1 -1
  103. package/dist/cjs/queries/staking/get-staked-balance.js +7 -1
  104. package/dist/cjs/queries/staking/get-staking-provider-info.d.ts +1 -1
  105. package/dist/cjs/queries/staking/get-staking-provider-info.d.ts.map +1 -1
  106. package/dist/cjs/queries/staking/get-staking-provider-info.js +3 -1
  107. package/dist/cjs/queries/staking/get-staking-quote.d.ts +1 -1
  108. package/dist/cjs/queries/staking/get-staking-quote.d.ts.map +1 -1
  109. package/dist/cjs/queries/staking/get-staking-quote.js +8 -2
  110. package/dist/cjs/queries/swap/get-swap-quote.d.ts.map +1 -1
  111. package/dist/cjs/queries/swap/get-swap-quote.js +1 -1
  112. package/dist/cjs/staking/index.d.ts +2 -2
  113. package/dist/cjs/staking/index.d.ts.map +1 -1
  114. package/dist/cjs/staking/index.js +3 -1
  115. package/dist/cjs/swap/index.d.ts +2 -1
  116. package/dist/cjs/swap/index.d.ts.map +1 -1
  117. package/dist/cjs/swap/index.js +6 -0
  118. package/dist/cjs/types/connector.d.ts +0 -1
  119. package/dist/cjs/types/connector.d.ts.map +1 -1
  120. package/dist/cjs/types/primitives.d.ts +1 -1
  121. package/dist/cjs/types/primitives.d.ts.map +1 -1
  122. package/dist/cjs/utils/address/is-valid-address.d.ts +11 -0
  123. package/dist/cjs/utils/address/is-valid-address.d.ts.map +1 -0
  124. package/dist/cjs/utils/address/is-valid-address.js +38 -0
  125. package/dist/cjs/utils/address/to-bounceble-address.d.ts +11 -0
  126. package/dist/cjs/utils/address/to-bounceble-address.d.ts.map +1 -0
  127. package/dist/cjs/utils/address/to-bounceble-address.js +36 -0
  128. package/dist/cjs/utils/address/to-non-bounceble-address.d.ts +11 -0
  129. package/dist/cjs/utils/address/to-non-bounceble-address.d.ts.map +1 -0
  130. package/dist/cjs/utils/address/to-non-bounceble-address.js +36 -0
  131. package/dist/cjs/utils/amount/calc-fiat-value.d.ts +13 -0
  132. package/dist/cjs/utils/amount/calc-fiat-value.d.ts.map +1 -0
  133. package/dist/cjs/utils/amount/calc-fiat-value.js +22 -0
  134. package/dist/cjs/utils/amount/calc-fiat-value.test.d.ts +9 -0
  135. package/dist/cjs/utils/amount/calc-fiat-value.test.d.ts.map +1 -0
  136. package/dist/cjs/utils/amount/calc-fiat-value.test.js +39 -0
  137. package/dist/cjs/utils/amount/format-large-value.d.ts +9 -0
  138. package/dist/cjs/utils/amount/format-large-value.d.ts.map +1 -0
  139. package/dist/cjs/utils/amount/format-large-value.js +40 -0
  140. package/dist/cjs/utils/amount/format-large-value.test.d.ts +9 -0
  141. package/dist/cjs/utils/amount/format-large-value.test.d.ts.map +1 -0
  142. package/dist/cjs/utils/amount/format-large-value.test.js +43 -0
  143. package/dist/cjs/utils/amount/truncate-decimals.d.ts +9 -0
  144. package/dist/cjs/utils/amount/truncate-decimals.d.ts.map +1 -0
  145. package/dist/cjs/utils/amount/truncate-decimals.js +59 -0
  146. package/dist/cjs/utils/amount/truncate-decimals.test.d.ts +9 -0
  147. package/dist/cjs/utils/amount/truncate-decimals.test.d.ts.map +1 -0
  148. package/dist/cjs/utils/amount/truncate-decimals.test.js +83 -0
  149. package/dist/cjs/utils/balance/calc-max-spendable.d.ts +33 -0
  150. package/dist/cjs/utils/balance/calc-max-spendable.d.ts.map +1 -0
  151. package/dist/cjs/utils/balance/calc-max-spendable.js +29 -0
  152. package/dist/cjs/utils/balance/calc-max-spendable.test.d.ts +9 -0
  153. package/dist/cjs/utils/balance/calc-max-spendable.test.d.ts.map +1 -0
  154. package/dist/cjs/utils/balance/calc-max-spendable.test.js +38 -0
  155. package/dist/cjs/utils/balance/get-ton-shortfall.d.ts +58 -0
  156. package/dist/cjs/utils/balance/get-ton-shortfall.d.ts.map +1 -0
  157. package/dist/cjs/utils/balance/get-ton-shortfall.js +46 -0
  158. package/dist/cjs/utils/balance/get-ton-shortfall.test.d.ts +9 -0
  159. package/dist/cjs/utils/balance/get-ton-shortfall.test.d.ts.map +1 -0
  160. package/dist/cjs/utils/balance/get-ton-shortfall.test.js +133 -0
  161. package/dist/cjs/utils/functions/debounce.d.ts +80 -0
  162. package/dist/cjs/utils/functions/debounce.d.ts.map +1 -0
  163. package/dist/cjs/utils/functions/debounce.js +107 -0
  164. package/dist/cjs/utils/index.d.ts +10 -0
  165. package/dist/cjs/utils/index.d.ts.map +1 -1
  166. package/dist/cjs/utils/index.js +10 -0
  167. package/dist/cjs/utils/jetton/jetton-info.d.ts +2 -1
  168. package/dist/cjs/utils/jetton/jetton-info.d.ts.map +1 -1
  169. package/dist/cjs/utils/jetton/jetton-info.js +11 -1
  170. package/dist/cjs/utils/jetton/jetton-info.test.d.ts +9 -0
  171. package/dist/cjs/utils/jetton/jetton-info.test.d.ts.map +1 -0
  172. package/dist/cjs/utils/jetton/jetton-info.test.js +54 -0
  173. package/dist/cjs/utils/predicate/is-number.d.ts +9 -0
  174. package/dist/cjs/utils/predicate/is-number.d.ts.map +1 -0
  175. package/dist/cjs/utils/predicate/is-number.js +20 -0
  176. package/dist/cjs/utils/predicate/is-string.d.ts +1 -1
  177. package/dist/cjs/utils/predicate/is-string.d.ts.map +1 -1
  178. package/dist/cjs/utils/predicate/is-string.js +4 -3
  179. package/dist/esm/actions/index.d.ts +8 -0
  180. package/dist/esm/actions/index.d.ts.map +1 -1
  181. package/dist/esm/actions/index.js +8 -0
  182. package/dist/esm/actions/jettons/create-transfer-jetton-transaction.d.ts +1 -1
  183. package/dist/esm/actions/jettons/create-transfer-jetton-transaction.d.ts.map +1 -1
  184. package/dist/esm/actions/jettons/create-transfer-jetton-transaction.js +17 -5
  185. package/dist/esm/actions/jettons/get-jetton-balance.d.ts +1 -1
  186. package/dist/esm/actions/jettons/get-jetton-balance.d.ts.map +1 -1
  187. package/dist/esm/actions/jettons/get-jetton-balance.js +7 -2
  188. package/dist/esm/actions/jettons/get-jetton-info.d.ts.map +1 -1
  189. package/dist/esm/actions/jettons/get-jetton-info.js +15 -6
  190. package/dist/esm/actions/jettons/get-jetton-wallet-address.d.ts +1 -1
  191. package/dist/esm/actions/jettons/get-jetton-wallet-address.d.ts.map +1 -1
  192. package/dist/esm/actions/jettons/get-jetton-wallet-address.js +15 -4
  193. package/dist/esm/actions/nft/get-nft.d.ts +1 -1
  194. package/dist/esm/actions/nft/get-nft.d.ts.map +1 -1
  195. package/dist/esm/actions/staking/get-staking-provider-metadata.d.ts +19 -0
  196. package/dist/esm/actions/staking/get-staking-provider-metadata.d.ts.map +1 -0
  197. package/dist/esm/actions/staking/get-staking-provider-metadata.js +14 -0
  198. package/dist/esm/actions/staking/get-staking-provider.d.ts +21 -0
  199. package/dist/esm/actions/staking/get-staking-provider.d.ts.map +1 -0
  200. package/dist/esm/actions/staking/get-staking-provider.js +13 -0
  201. package/dist/esm/actions/staking/get-staking-providers.d.ts +3 -2
  202. package/dist/esm/actions/staking/get-staking-providers.d.ts.map +1 -1
  203. package/dist/esm/actions/staking/get-staking-providers.js +2 -2
  204. package/dist/esm/actions/staking/set-default-staking-provider.d.ts +18 -0
  205. package/dist/esm/actions/staking/set-default-staking-provider.d.ts.map +1 -0
  206. package/dist/esm/actions/staking/set-default-staking-provider.js +14 -0
  207. package/dist/esm/actions/staking/watch-staking-providers.d.ts +17 -0
  208. package/dist/esm/actions/staking/watch-staking-providers.d.ts.map +1 -0
  209. package/dist/esm/actions/staking/watch-staking-providers.js +24 -0
  210. package/dist/esm/actions/swap/get-swap-provider.d.ts +15 -0
  211. package/dist/esm/actions/swap/get-swap-provider.d.ts.map +1 -0
  212. package/dist/esm/actions/swap/get-swap-provider.js +10 -0
  213. package/dist/esm/actions/swap/get-swap-providers.d.ts +15 -0
  214. package/dist/esm/actions/swap/get-swap-providers.d.ts.map +1 -0
  215. package/dist/esm/actions/swap/get-swap-providers.js +13 -0
  216. package/dist/esm/actions/swap/get-swap-quote.d.ts.map +1 -1
  217. package/dist/esm/actions/swap/get-swap-quote.js +6 -1
  218. package/dist/esm/actions/swap/set-default-swap-provider.d.ts +18 -0
  219. package/dist/esm/actions/swap/set-default-swap-provider.d.ts.map +1 -0
  220. package/dist/esm/actions/swap/set-default-swap-provider.js +14 -0
  221. package/dist/esm/actions/swap/watch-swap-providers.d.ts +17 -0
  222. package/dist/esm/actions/swap/watch-swap-providers.d.ts.map +1 -0
  223. package/dist/esm/actions/swap/watch-swap-providers.js +25 -0
  224. package/dist/esm/connectors/tonconnect/connectors/ton-connect-connector.js +2 -2
  225. package/dist/esm/core/app-kit/constants/events.d.ts +0 -6
  226. package/dist/esm/core/app-kit/constants/events.d.ts.map +1 -1
  227. package/dist/esm/core/app-kit/constants/events.js +0 -6
  228. package/dist/esm/core/app-kit/index.d.ts +2 -2
  229. package/dist/esm/core/app-kit/index.d.ts.map +1 -1
  230. package/dist/esm/core/app-kit/index.js +1 -1
  231. package/dist/esm/core/app-kit/services/app-kit.d.ts +3 -1
  232. package/dist/esm/core/app-kit/services/app-kit.d.ts.map +1 -1
  233. package/dist/esm/core/app-kit/services/app-kit.js +4 -2
  234. package/dist/esm/core/app-kit/types/config.d.ts +4 -2
  235. package/dist/esm/core/app-kit/types/config.d.ts.map +1 -1
  236. package/dist/esm/core/app-kit/types/events.d.ts +2 -7
  237. package/dist/esm/core/app-kit/types/events.d.ts.map +1 -1
  238. package/dist/esm/core/cache/adapters/lru-app-kit-cache.d.ts +20 -0
  239. package/dist/esm/core/cache/adapters/lru-app-kit-cache.d.ts.map +1 -0
  240. package/dist/esm/core/cache/adapters/lru-app-kit-cache.js +28 -0
  241. package/dist/esm/core/cache/adapters/lru-app-kit-cache.test.d.ts +9 -0
  242. package/dist/esm/core/cache/adapters/lru-app-kit-cache.test.d.ts.map +1 -0
  243. package/dist/esm/core/cache/adapters/lru-app-kit-cache.test.js +66 -0
  244. package/dist/esm/core/cache/index.d.ts +11 -0
  245. package/dist/esm/core/cache/index.d.ts.map +1 -0
  246. package/dist/esm/core/cache/index.js +9 -0
  247. package/dist/esm/core/cache/types/app-kit-cache.d.ts +14 -0
  248. package/dist/esm/core/cache/types/app-kit-cache.d.ts.map +1 -0
  249. package/dist/esm/core/cache/types/app-kit-cache.js +8 -0
  250. package/dist/esm/core/cache/utils/get-cache-key.d.ts +9 -0
  251. package/dist/esm/core/cache/utils/get-cache-key.d.ts.map +1 -0
  252. package/dist/esm/core/cache/utils/get-cache-key.js +8 -0
  253. package/dist/esm/core/cache/utils/get-cache-key.test.d.ts +9 -0
  254. package/dist/esm/core/cache/utils/get-cache-key.test.d.ts.map +1 -0
  255. package/dist/esm/core/cache/utils/get-cache-key.test.js +28 -0
  256. package/dist/esm/index.d.ts +1 -0
  257. package/dist/esm/index.d.ts.map +1 -1
  258. package/dist/esm/index.js +1 -0
  259. package/dist/esm/queries/balances/get-balance-by-address.d.ts.map +1 -1
  260. package/dist/esm/queries/balances/get-balance-by-address.js +10 -4
  261. package/dist/esm/queries/index.d.ts +0 -1
  262. package/dist/esm/queries/index.d.ts.map +1 -1
  263. package/dist/esm/queries/index.js +0 -1
  264. package/dist/esm/queries/jettons/get-jetton-balance-by-address.d.ts.map +1 -1
  265. package/dist/esm/queries/jettons/get-jetton-balance-by-address.js +12 -12
  266. package/dist/esm/queries/jettons/get-jetton-info.d.ts.map +1 -1
  267. package/dist/esm/queries/jettons/get-jetton-info.js +6 -2
  268. package/dist/esm/queries/jettons/get-jetton-wallet-address.d.ts.map +1 -1
  269. package/dist/esm/queries/jettons/get-jetton-wallet-address.js +7 -2
  270. package/dist/esm/queries/jettons/get-jettons-by-address.d.ts.map +1 -1
  271. package/dist/esm/queries/jettons/get-jettons-by-address.js +10 -4
  272. package/dist/esm/queries/nft/get-nft.d.ts +1 -1
  273. package/dist/esm/queries/nft/get-nft.d.ts.map +1 -1
  274. package/dist/esm/queries/nft/get-nft.js +6 -2
  275. package/dist/esm/queries/nft/get-nfts-by-address.d.ts.map +1 -1
  276. package/dist/esm/queries/nft/get-nfts-by-address.js +6 -2
  277. package/dist/esm/queries/staking/get-staked-balance.d.ts +1 -1
  278. package/dist/esm/queries/staking/get-staked-balance.d.ts.map +1 -1
  279. package/dist/esm/queries/staking/get-staked-balance.js +8 -2
  280. package/dist/esm/queries/staking/get-staking-provider-info.d.ts +1 -1
  281. package/dist/esm/queries/staking/get-staking-provider-info.d.ts.map +1 -1
  282. package/dist/esm/queries/staking/get-staking-provider-info.js +4 -2
  283. package/dist/esm/queries/staking/get-staking-quote.d.ts +1 -1
  284. package/dist/esm/queries/staking/get-staking-quote.d.ts.map +1 -1
  285. package/dist/esm/queries/staking/get-staking-quote.js +9 -3
  286. package/dist/esm/queries/swap/get-swap-quote.d.ts.map +1 -1
  287. package/dist/esm/queries/swap/get-swap-quote.js +1 -1
  288. package/dist/esm/staking/index.d.ts +2 -2
  289. package/dist/esm/staking/index.d.ts.map +1 -1
  290. package/dist/esm/staking/index.js +1 -1
  291. package/dist/esm/swap/index.d.ts +2 -1
  292. package/dist/esm/swap/index.d.ts.map +1 -1
  293. package/dist/esm/swap/index.js +1 -1
  294. package/dist/esm/types/connector.d.ts +0 -1
  295. package/dist/esm/types/connector.d.ts.map +1 -1
  296. package/dist/esm/types/primitives.d.ts +1 -1
  297. package/dist/esm/types/primitives.d.ts.map +1 -1
  298. package/dist/esm/utils/address/is-valid-address.d.ts +11 -0
  299. package/dist/esm/utils/address/is-valid-address.d.ts.map +1 -0
  300. package/dist/esm/utils/address/is-valid-address.js +33 -0
  301. package/dist/esm/utils/address/to-bounceble-address.d.ts +11 -0
  302. package/dist/esm/utils/address/to-bounceble-address.d.ts.map +1 -0
  303. package/dist/esm/utils/address/to-bounceble-address.js +31 -0
  304. package/dist/esm/utils/address/to-non-bounceble-address.d.ts +11 -0
  305. package/dist/esm/utils/address/to-non-bounceble-address.d.ts.map +1 -0
  306. package/dist/esm/utils/address/to-non-bounceble-address.js +31 -0
  307. package/dist/esm/utils/amount/calc-fiat-value.d.ts +13 -0
  308. package/dist/esm/utils/amount/calc-fiat-value.d.ts.map +1 -0
  309. package/dist/esm/utils/amount/calc-fiat-value.js +19 -0
  310. package/dist/esm/utils/amount/calc-fiat-value.test.d.ts +9 -0
  311. package/dist/esm/utils/amount/calc-fiat-value.test.d.ts.map +1 -0
  312. package/dist/esm/utils/amount/calc-fiat-value.test.js +37 -0
  313. package/dist/esm/utils/amount/format-large-value.d.ts +9 -0
  314. package/dist/esm/utils/amount/format-large-value.d.ts.map +1 -0
  315. package/dist/esm/utils/amount/format-large-value.js +36 -0
  316. package/dist/esm/utils/amount/format-large-value.test.d.ts +9 -0
  317. package/dist/esm/utils/amount/format-large-value.test.d.ts.map +1 -0
  318. package/dist/esm/utils/amount/format-large-value.test.js +41 -0
  319. package/dist/esm/utils/amount/truncate-decimals.d.ts +9 -0
  320. package/dist/esm/utils/amount/truncate-decimals.d.ts.map +1 -0
  321. package/dist/esm/utils/amount/truncate-decimals.js +55 -0
  322. package/dist/esm/utils/amount/truncate-decimals.test.d.ts +9 -0
  323. package/dist/esm/utils/amount/truncate-decimals.test.d.ts.map +1 -0
  324. package/dist/esm/utils/amount/truncate-decimals.test.js +81 -0
  325. package/dist/esm/utils/balance/calc-max-spendable.d.ts +33 -0
  326. package/dist/esm/utils/balance/calc-max-spendable.d.ts.map +1 -0
  327. package/dist/esm/utils/balance/calc-max-spendable.js +25 -0
  328. package/dist/esm/utils/balance/calc-max-spendable.test.d.ts +9 -0
  329. package/dist/esm/utils/balance/calc-max-spendable.test.d.ts.map +1 -0
  330. package/dist/esm/utils/balance/calc-max-spendable.test.js +36 -0
  331. package/dist/esm/utils/balance/get-ton-shortfall.d.ts +58 -0
  332. package/dist/esm/utils/balance/get-ton-shortfall.d.ts.map +1 -0
  333. package/dist/esm/utils/balance/get-ton-shortfall.js +42 -0
  334. package/dist/esm/utils/balance/get-ton-shortfall.test.d.ts +9 -0
  335. package/dist/esm/utils/balance/get-ton-shortfall.test.d.ts.map +1 -0
  336. package/dist/esm/utils/balance/get-ton-shortfall.test.js +131 -0
  337. package/dist/esm/utils/functions/debounce.d.ts +80 -0
  338. package/dist/esm/utils/functions/debounce.d.ts.map +1 -0
  339. package/dist/esm/utils/functions/debounce.js +103 -0
  340. package/dist/esm/utils/index.d.ts +10 -0
  341. package/dist/esm/utils/index.d.ts.map +1 -1
  342. package/dist/esm/utils/index.js +10 -0
  343. package/dist/esm/utils/jetton/jetton-info.d.ts +2 -1
  344. package/dist/esm/utils/jetton/jetton-info.d.ts.map +1 -1
  345. package/dist/esm/utils/jetton/jetton-info.js +9 -0
  346. package/dist/esm/utils/jetton/jetton-info.test.d.ts +9 -0
  347. package/dist/esm/utils/jetton/jetton-info.test.d.ts.map +1 -0
  348. package/dist/esm/utils/jetton/jetton-info.test.js +52 -0
  349. package/dist/esm/utils/predicate/is-number.d.ts +9 -0
  350. package/dist/esm/utils/predicate/is-number.d.ts.map +1 -0
  351. package/dist/esm/utils/predicate/is-number.js +16 -0
  352. package/dist/esm/utils/predicate/is-string.d.ts +1 -1
  353. package/dist/esm/utils/predicate/is-string.d.ts.map +1 -1
  354. package/dist/esm/utils/predicate/is-string.js +2 -2
  355. package/docs/actions.md +57 -9
  356. package/docs/swap.md +4 -4
  357. package/package.json +4 -3
  358. package/src/actions/index.ts +32 -0
  359. package/src/actions/jettons/create-transfer-jetton-transaction.ts +22 -6
  360. package/src/actions/jettons/get-jetton-balance.ts +10 -3
  361. package/src/actions/jettons/get-jetton-info.ts +18 -6
  362. package/src/actions/jettons/get-jetton-wallet-address.ts +19 -5
  363. package/src/actions/nft/get-nft.ts +1 -1
  364. package/src/actions/staking/get-staking-provider-metadata.ts +32 -0
  365. package/src/actions/staking/get-staking-provider.ts +30 -0
  366. package/src/actions/staking/get-staking-providers.ts +5 -3
  367. package/src/actions/staking/set-default-staking-provider.ts +26 -0
  368. package/src/actions/staking/watch-staking-providers.ts +39 -0
  369. package/src/actions/swap/get-swap-provider.ts +21 -0
  370. package/src/actions/swap/get-swap-providers.ts +20 -0
  371. package/src/actions/swap/get-swap-quote.ts +7 -1
  372. package/src/actions/swap/set-default-swap-provider.ts +26 -0
  373. package/src/actions/swap/watch-swap-providers.ts +38 -0
  374. package/src/connectors/tonconnect/connectors/ton-connect-connector.ts +2 -2
  375. package/src/core/app-kit/constants/events.ts +0 -7
  376. package/src/core/app-kit/index.ts +1 -2
  377. package/src/core/app-kit/services/app-kit.ts +7 -3
  378. package/src/core/app-kit/types/config.ts +4 -2
  379. package/src/core/app-kit/types/events.ts +2 -10
  380. package/src/core/cache/adapters/lru-app-kit-cache.test.ts +77 -0
  381. package/src/core/cache/adapters/lru-app-kit-cache.ts +38 -0
  382. package/src/core/cache/index.ts +12 -0
  383. package/src/core/cache/types/app-kit-cache.ts +14 -0
  384. package/src/core/cache/utils/get-cache-key.test.ts +34 -0
  385. package/src/core/cache/utils/get-cache-key.ts +12 -0
  386. package/src/index.ts +1 -0
  387. package/src/queries/balances/get-balance-by-address.ts +11 -4
  388. package/src/queries/index.ts +0 -6
  389. package/src/queries/jettons/get-jetton-balance-by-address.ts +13 -12
  390. package/src/queries/jettons/get-jetton-info.ts +6 -2
  391. package/src/queries/jettons/get-jetton-wallet-address.ts +7 -2
  392. package/src/queries/jettons/get-jettons-by-address.ts +18 -4
  393. package/src/queries/nft/get-nft.ts +7 -3
  394. package/src/queries/nft/get-nfts-by-address.ts +6 -2
  395. package/src/queries/staking/get-staked-balance.ts +10 -3
  396. package/src/queries/staking/get-staking-provider-info.ts +5 -2
  397. package/src/queries/staking/get-staking-quote.ts +13 -4
  398. package/src/queries/swap/get-swap-quote.ts +3 -1
  399. package/src/staking/index.ts +10 -1
  400. package/src/swap/index.ts +2 -4
  401. package/src/types/connector.ts +0 -1
  402. package/src/types/primitives.ts +1 -1
  403. package/src/utils/address/is-valid-address.ts +40 -0
  404. package/src/utils/address/to-bounceble-address.ts +35 -0
  405. package/src/utils/address/to-non-bounceble-address.ts +35 -0
  406. package/src/utils/amount/calc-fiat-value.test.ts +46 -0
  407. package/src/utils/amount/calc-fiat-value.ts +18 -0
  408. package/src/utils/amount/format-large-value.test.ts +50 -0
  409. package/src/utils/amount/format-large-value.ts +43 -0
  410. package/src/utils/amount/truncate-decimals.test.ts +97 -0
  411. package/src/utils/amount/truncate-decimals.ts +56 -0
  412. package/src/utils/balance/calc-max-spendable.test.ts +46 -0
  413. package/src/utils/balance/calc-max-spendable.ts +44 -0
  414. package/src/utils/balance/get-ton-shortfall.test.ts +148 -0
  415. package/src/utils/balance/get-ton-shortfall.ts +82 -0
  416. package/src/utils/functions/debounce.ts +169 -0
  417. package/src/utils/index.ts +10 -0
  418. package/src/utils/jetton/jetton-info.test.ts +65 -0
  419. package/src/utils/jetton/jetton-info.ts +12 -1
  420. package/src/utils/predicate/is-number.ts +19 -0
  421. package/src/utils/predicate/is-string.ts +2 -2
  422. package/dist/cjs/queries/staking/get-staking-providers.d.ts +0 -20
  423. package/dist/cjs/queries/staking/get-staking-providers.d.ts.map +0 -1
  424. package/dist/cjs/queries/staking/get-staking-providers.js +0 -25
  425. package/dist/esm/queries/staking/get-staking-providers.d.ts +0 -20
  426. package/dist/esm/queries/staking/get-staking-providers.d.ts.map +0 -1
  427. package/dist/esm/queries/staking/get-staking-providers.js +0 -20
  428. package/src/queries/staking/get-staking-providers.ts +0 -52
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Copyright (c) TonTech.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { describe, expect, it } from 'vitest';
9
+ import { calcMaxSpendable, DEFAULT_TON_FEE_RESERVE_NANOS } from './calc-max-spendable';
10
+ const TON = { address: 'ton', decimals: 9 };
11
+ const JETTON = { address: 'EQA_jetton', decimals: 6 };
12
+ describe('calcMaxSpendable', () => {
13
+ it('returns balance minus the TON fee reserve for native TON', () => {
14
+ // 1 TON balance, default reserve 0.1 TON → 0.9 TON spendable.
15
+ expect(calcMaxSpendable({ balance: '1', token: TON })).toBe('0.9');
16
+ });
17
+ it('returns the full balance for a jetton (no reserve)', () => {
18
+ expect(calcMaxSpendable({ balance: '100', token: JETTON })).toBe('100');
19
+ });
20
+ it('clamps to zero when balance is below the reserve', () => {
21
+ expect(calcMaxSpendable({ balance: '0.05', token: TON })).toBe('0');
22
+ });
23
+ it('clamps to zero when balance equals the reserve', () => {
24
+ expect(calcMaxSpendable({ balance: '0.1', token: TON })).toBe('0');
25
+ });
26
+ it('respects a custom feeReserveNanos', () => {
27
+ // 1 TON balance, 0.5 TON reserve → 0.5 TON spendable.
28
+ expect(calcMaxSpendable({ balance: '1', token: TON, feeReserveNanos: 500000000n })).toBe('0.5');
29
+ });
30
+ it('ignores feeReserveNanos for jettons', () => {
31
+ expect(calcMaxSpendable({ balance: '100', token: JETTON, feeReserveNanos: 999999999999n })).toBe('100');
32
+ });
33
+ it('exports a sane default reserve', () => {
34
+ expect(DEFAULT_TON_FEE_RESERVE_NANOS).toBe(100000000n);
35
+ });
36
+ });
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Copyright (c) TonTech.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ /** Default extra TON buffer added on top of built transaction outflow when checking balance before sending. */
9
+ export declare const DEFAULT_GAS_BUFFER_NANOS = 100000000n;
10
+ /**
11
+ * Default extra headroom baked into the suggested reduced amount, on top of the gas buffer.
12
+ * Covers quote/gas drift between the current built tx and the one that will actually be sent
13
+ * after the amount changes. 0.02 TON.
14
+ */
15
+ export declare const DEFAULT_SAFETY_MARGIN_NANOS = 20000000n;
16
+ export type TonShortfall = {
17
+ mode: 'reduce';
18
+ requiredNanos: bigint;
19
+ suggestedFromAmount: string;
20
+ } | {
21
+ mode: 'topup';
22
+ requiredNanos: bigint;
23
+ suggestedFromAmount: '';
24
+ };
25
+ export interface GetTonShortfallParams {
26
+ /** Messages of the built transaction. Each `amount` is the TON value in nanos attached to the message. */
27
+ messages: Array<{
28
+ amount: string;
29
+ }>;
30
+ /** User's current TON balance as a decimal string (same format `formatUnits(balance, 9)` returns). */
31
+ tonBalance: string | undefined;
32
+ /** The outgoing token — `{ address: 'ton' }` when the user spends TON, otherwise a jetton. */
33
+ fromToken: {
34
+ address: string;
35
+ };
36
+ /** Amount the user intends to spend in `fromToken` units, as a decimal string. */
37
+ fromAmount: string;
38
+ /**
39
+ * Extra TON headroom on top of built-tx outflow when checking balance before sending.
40
+ * Defaults to {@link DEFAULT_GAS_BUFFER_NANOS}.
41
+ */
42
+ gasBufferNanos?: bigint;
43
+ /**
44
+ * Extra headroom baked into the suggested reduced amount, on top of the gas buffer.
45
+ * Defaults to {@link DEFAULT_SAFETY_MARGIN_NANOS}.
46
+ */
47
+ safetyMarginNanos?: bigint;
48
+ }
49
+ /**
50
+ * Check whether the user's TON balance covers the built transaction.
51
+ * - Returns `null` if the balance is sufficient.
52
+ * - Returns `{ mode: 'reduce', ... }` with a smaller suggested `fromAmount` when `fromToken` is TON
53
+ * and the balance is enough to cover at least gas (user can fix it by reducing the amount).
54
+ * - Returns `{ mode: 'topup', ... }` when `fromToken` is a jetton (reducing jetton amount won't free up TON gas),
55
+ * or when `fromToken` is TON but the balance can't even cover gas (reducing won't help — user must top up).
56
+ */
57
+ export declare const getTonShortfall: ({ messages, tonBalance, fromToken, fromAmount, gasBufferNanos, safetyMarginNanos, }: GetTonShortfallParams) => TonShortfall | undefined;
58
+ //# sourceMappingURL=get-ton-shortfall.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-ton-shortfall.d.ts","sourceRoot":"","sources":["../../../../src/utils/balance/get-ton-shortfall.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,+GAA+G;AAC/G,eAAO,MAAM,wBAAwB,aAAe,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,YAAc,CAAC;AAEvD,MAAM,MAAM,YAAY,GAClB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,mBAAmB,EAAE,MAAM,CAAA;CAAE,GACtE;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,mBAAmB,EAAE,EAAE,CAAA;CAAE,CAAC;AAExE,MAAM,WAAW,qBAAqB;IAClC,0GAA0G;IAC1G,QAAQ,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACpC,sGAAsG;IACtG,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,8FAA8F;IAC9F,SAAS,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/B,kFAAkF;IAClF,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,qFAO7B,qBAAqB,KAAG,YAAY,GAAG,SAqBzC,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Copyright (c) TonTech.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { formatUnits, parseUnits } from '@ton/walletkit';
9
+ /** Default extra TON buffer added on top of built transaction outflow when checking balance before sending. */
10
+ export const DEFAULT_GAS_BUFFER_NANOS = 100000000n;
11
+ /**
12
+ * Default extra headroom baked into the suggested reduced amount, on top of the gas buffer.
13
+ * Covers quote/gas drift between the current built tx and the one that will actually be sent
14
+ * after the amount changes. 0.02 TON.
15
+ */
16
+ export const DEFAULT_SAFETY_MARGIN_NANOS = 20000000n;
17
+ /**
18
+ * Check whether the user's TON balance covers the built transaction.
19
+ * - Returns `null` if the balance is sufficient.
20
+ * - Returns `{ mode: 'reduce', ... }` with a smaller suggested `fromAmount` when `fromToken` is TON
21
+ * and the balance is enough to cover at least gas (user can fix it by reducing the amount).
22
+ * - Returns `{ mode: 'topup', ... }` when `fromToken` is a jetton (reducing jetton amount won't free up TON gas),
23
+ * or when `fromToken` is TON but the balance can't even cover gas (reducing won't help — user must top up).
24
+ */
25
+ export const getTonShortfall = ({ messages, tonBalance, fromToken, fromAmount, gasBufferNanos = DEFAULT_GAS_BUFFER_NANOS, safetyMarginNanos = DEFAULT_SAFETY_MARGIN_NANOS, }) => {
26
+ const totalOutNanos = messages.reduce((acc, m) => acc + BigInt(m.amount), 0n);
27
+ const requiredNanos = totalOutNanos + gasBufferNanos;
28
+ const tonBalanceNanos = tonBalance ? parseUnits(tonBalance, 9) : 0n;
29
+ if (tonBalanceNanos >= requiredNanos)
30
+ return;
31
+ if (fromToken.address === 'ton') {
32
+ const gasOnlyNanos = totalOutNanos - parseUnits(fromAmount, 9);
33
+ const nonSwapReservedNanos = gasOnlyNanos + gasBufferNanos + safetyMarginNanos;
34
+ // Balance can't cover even gas for a minimal outgoing tx — reducing the amount won't help.
35
+ if (tonBalanceNanos <= nonSwapReservedNanos) {
36
+ return { mode: 'topup', requiredNanos, suggestedFromAmount: '' };
37
+ }
38
+ const suggestedFromAmount = formatUnits(tonBalanceNanos - nonSwapReservedNanos, 9);
39
+ return { mode: 'reduce', requiredNanos, suggestedFromAmount };
40
+ }
41
+ return { mode: 'topup', requiredNanos, suggestedFromAmount: '' };
42
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) TonTech.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=get-ton-shortfall.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-ton-shortfall.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/balance/get-ton-shortfall.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Copyright (c) TonTech.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { describe, expect, it } from 'vitest';
9
+ import { DEFAULT_GAS_BUFFER_NANOS, DEFAULT_SAFETY_MARGIN_NANOS, getTonShortfall } from './get-ton-shortfall';
10
+ const TON = { address: 'ton' };
11
+ const JETTON = { address: 'EQA_jetton_address' };
12
+ // Helper — convert a decimal string of TON to nanos as a string (for message amounts).
13
+ const toNanos = (ton) => BigInt(Math.round(Number(ton) * 1e9)).toString();
14
+ describe('getTonShortfall', () => {
15
+ it('returns undefined when TON balance covers the built transaction', () => {
16
+ // Swap 1 TON, total tx outflow 1.3 TON (1 TON swap + 0.3 TON attached gas), balance 2 TON.
17
+ const result = getTonShortfall({
18
+ messages: [{ amount: toNanos('1.3') }],
19
+ tonBalance: '2',
20
+ fromToken: TON,
21
+ fromAmount: '1',
22
+ });
23
+ expect(result).toBeUndefined();
24
+ });
25
+ it('returns topup when fromToken is a jetton and TON balance is below outflow + buffer', () => {
26
+ // Jetton swap, tx needs 0.05 TON for gas, user has 0 TON.
27
+ const result = getTonShortfall({
28
+ messages: [{ amount: toNanos('0.05') }],
29
+ tonBalance: '0',
30
+ fromToken: JETTON,
31
+ fromAmount: '100',
32
+ });
33
+ expect(result).toEqual({
34
+ mode: 'topup',
35
+ requiredNanos: 50000000n + DEFAULT_GAS_BUFFER_NANOS,
36
+ suggestedFromAmount: '',
37
+ });
38
+ });
39
+ it('returns reduce for TON-from when balance covers gas but not full amount', () => {
40
+ // User wants 1 TON swap, total outflow 1.3 TON, has 1 TON. Gas only = 0.3 TON.
41
+ // Balance (1) > nonSwapReserved (0.3 gas + 0.1 buffer + 0.02 safety = 0.42) → reduce mode.
42
+ const result = getTonShortfall({
43
+ messages: [{ amount: toNanos('1.3') }],
44
+ tonBalance: '1',
45
+ fromToken: TON,
46
+ fromAmount: '1',
47
+ });
48
+ expect(result?.mode).toBe('reduce');
49
+ if (result?.mode !== 'reduce')
50
+ return;
51
+ // Suggested = 1 - 0.42 = 0.58
52
+ expect(result.suggestedFromAmount).toBe('0.58');
53
+ expect(result.requiredNanos).toBe(1300000000n + DEFAULT_GAS_BUFFER_NANOS);
54
+ });
55
+ it('returns topup for TON-from when balance cannot cover even gas (reducing would not help)', () => {
56
+ // User wants 1 TON swap, total outflow 1.3 TON → gas = 0.3 TON. Balance 0.2 TON.
57
+ // nonSwapReserved = 0.3 + 0.1 buffer + 0.02 safety = 0.42 TON → balance (0.2) <= 0.42 → topup.
58
+ const result = getTonShortfall({
59
+ messages: [{ amount: toNanos('1.3') }],
60
+ tonBalance: '0.2',
61
+ fromToken: TON,
62
+ fromAmount: '1',
63
+ });
64
+ expect(result).toEqual({
65
+ mode: 'topup',
66
+ requiredNanos: 1300000000n + DEFAULT_GAS_BUFFER_NANOS,
67
+ suggestedFromAmount: '',
68
+ });
69
+ });
70
+ it('treats an undefined tonBalance as zero', () => {
71
+ const result = getTonShortfall({
72
+ messages: [{ amount: toNanos('0.05') }],
73
+ tonBalance: undefined,
74
+ fromToken: JETTON,
75
+ fromAmount: '100',
76
+ });
77
+ expect(result?.mode).toBe('topup');
78
+ });
79
+ it('sums amounts across multiple messages', () => {
80
+ // Two messages attaching 0.6 TON each → totalOut = 1.2 TON. Balance 1 TON → shortfall.
81
+ const result = getTonShortfall({
82
+ messages: [{ amount: toNanos('0.6') }, { amount: toNanos('0.6') }],
83
+ tonBalance: '1',
84
+ fromToken: JETTON,
85
+ fromAmount: '100',
86
+ });
87
+ expect(result?.mode).toBe('topup');
88
+ expect(result?.requiredNanos).toBe(1200000000n + DEFAULT_GAS_BUFFER_NANOS);
89
+ });
90
+ it('respects a custom gasBufferNanos', () => {
91
+ const baseParams = {
92
+ messages: [{ amount: toNanos('1.3') }],
93
+ tonBalance: '1.3',
94
+ fromToken: TON,
95
+ fromAmount: '1',
96
+ };
97
+ // With the default buffer (0.1 TON), balance 1.3 is insufficient (needs 1.4).
98
+ expect(getTonShortfall(baseParams)?.mode).toBe('reduce');
99
+ // With a zero buffer, 1.3 TON balance covers the 1.3 TON outflow exactly.
100
+ expect(getTonShortfall({ ...baseParams, gasBufferNanos: 0n })).toBeUndefined();
101
+ });
102
+ it('respects a custom safetyMarginNanos in the reduce branch', () => {
103
+ // Default margin: suggested = balance - gas - buffer - 0.02 = 1 - 0.3 - 0.1 - 0.02 = 0.58
104
+ // Zero margin: suggested = balance - gas - buffer = 1 - 0.3 - 0.1 = 0.6
105
+ const baseParams = {
106
+ messages: [{ amount: toNanos('1.3') }],
107
+ tonBalance: '1',
108
+ fromToken: TON,
109
+ fromAmount: '1',
110
+ };
111
+ const withDefault = getTonShortfall(baseParams);
112
+ expect(withDefault?.mode === 'reduce' ? withDefault.suggestedFromAmount : null).toBe('0.58');
113
+ const withZero = getTonShortfall({ ...baseParams, safetyMarginNanos: 0n });
114
+ expect(withZero?.mode === 'reduce' ? withZero.suggestedFromAmount : null).toBe('0.6');
115
+ });
116
+ it('flips from reduce to topup when a large custom safetyMarginNanos eats the balance', () => {
117
+ // Balance 1 TON, gas 0.3 TON, buffer 0.1 TON. With a 1 TON safety margin, nonSwapReserved becomes 1.4 TON → topup.
118
+ const result = getTonShortfall({
119
+ messages: [{ amount: toNanos('1.3') }],
120
+ tonBalance: '1',
121
+ fromToken: TON,
122
+ fromAmount: '1',
123
+ safetyMarginNanos: 1000000000n,
124
+ });
125
+ expect(result?.mode).toBe('topup');
126
+ });
127
+ it('exports sane default constants', () => {
128
+ expect(DEFAULT_GAS_BUFFER_NANOS).toBe(100000000n);
129
+ expect(DEFAULT_SAFETY_MARGIN_NANOS).toBe(20000000n);
130
+ });
131
+ });
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Copyright (c) TonTech.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ export interface DebounceOptions {
9
+ /**
10
+ * An optional AbortSignal to cancel the debounced function.
11
+ */
12
+ signal?: AbortSignal;
13
+ /**
14
+ * An optional array specifying whether the function should be invoked on the leading edge, trailing edge, or both.
15
+ * If `edges` include "leading", the function will be invoked at the start of the delay period.
16
+ * If `edges` include "trailing", the function will be invoked at the end of the delay period.
17
+ * If both "leading" and "trailing" are included, the function will be invoked at both the start and end of the delay period.
18
+ * @default ["trailing"]
19
+ */
20
+ edges?: Array<'leading' | 'trailing'>;
21
+ }
22
+ export interface DebouncedFunction<F extends (...args: unknown[]) => void> {
23
+ (...args: Parameters<F>): void;
24
+ /**
25
+ * Schedules the execution of the debounced function after the specified debounced delay.
26
+ * This method resets any existing timer, ensuring that the function is only invoked
27
+ * after the delay has elapsed since the last call to the debounced function.
28
+ * It is typically called internally whenever the debounced function is invoked.
29
+ *
30
+ * @returns {void}
31
+ */
32
+ schedule: () => void;
33
+ /**
34
+ * Cancels any pending execution of the debounced function.
35
+ * This method clears the active timer and resets any stored context or arguments.
36
+ */
37
+ cancel: () => void;
38
+ /**
39
+ * Immediately invokes the debounced function if there is a pending execution.
40
+ * This method executes the function right away if there is a pending execution.
41
+ */
42
+ flush: () => void;
43
+ }
44
+ /**
45
+ * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
46
+ * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`
47
+ * method to cancel any pending execution.
48
+ *
49
+ * @template F - The type of function.
50
+ * @param {F} func - The function to debounce.
51
+ * @param {number} debounceMs - The number of milliseconds to delay.
52
+ * @param {DebounceOptions} options - The options object
53
+ * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.
54
+ * @returns A new debounced function with a `cancel` method.
55
+ *
56
+ * @example
57
+ * const debouncedFunction = debounce(() => {
58
+ * console.log('Function executed');
59
+ * }, 1000);
60
+ *
61
+ * // Will log 'Function executed' after 1 second if not called again in that time
62
+ * debouncedFunction();
63
+ *
64
+ * // Will not log anything as the previous call is canceled
65
+ * debouncedFunction.cancel();
66
+ *
67
+ * // With AbortSignal
68
+ * const controller = new AbortController();
69
+ * const signal = controller.signal;
70
+ * const debouncedWithSignal = debounce(() => {
71
+ * console.log('Function executed');
72
+ * }, 1000, { signal });
73
+ *
74
+ * debouncedWithSignal();
75
+ *
76
+ * // Will cancel the debounced function call
77
+ * controller.abort();
78
+ */
79
+ export declare const debounce: <F extends (...args: unknown[]) => void>(func: F, debounceMs: number, { signal, edges }?: DebounceOptions) => DebouncedFunction<F>;
80
+ //# sourceMappingURL=debounce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debounce.d.ts","sourceRoot":"","sources":["../../../../src/utils/functions/debounce.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,eAAe;IAC5B;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IAErB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,UAAU,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI;IACrE,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAE/B;;;;;;;OAOG;IACH,QAAQ,EAAE,MAAM,IAAI,CAAC;IAErB;;;OAGG;IACH,MAAM,EAAE,MAAM,IAAI,CAAC;IAEnB;;;OAGG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EAC3D,MAAM,CAAC,EACP,YAAY,MAAM,EAClB,oBAAmB,eAAoB,KACxC,iBAAiB,CAAC,CAAC,CA+ErB,CAAC"}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Copyright (c) TonTech.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ /**
9
+ * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
10
+ * have elapsed since the last time the debounced function was invoked. The debounced function also has a `cancel`
11
+ * method to cancel any pending execution.
12
+ *
13
+ * @template F - The type of function.
14
+ * @param {F} func - The function to debounce.
15
+ * @param {number} debounceMs - The number of milliseconds to delay.
16
+ * @param {DebounceOptions} options - The options object
17
+ * @param {AbortSignal} options.signal - An optional AbortSignal to cancel the debounced function.
18
+ * @returns A new debounced function with a `cancel` method.
19
+ *
20
+ * @example
21
+ * const debouncedFunction = debounce(() => {
22
+ * console.log('Function executed');
23
+ * }, 1000);
24
+ *
25
+ * // Will log 'Function executed' after 1 second if not called again in that time
26
+ * debouncedFunction();
27
+ *
28
+ * // Will not log anything as the previous call is canceled
29
+ * debouncedFunction.cancel();
30
+ *
31
+ * // With AbortSignal
32
+ * const controller = new AbortController();
33
+ * const signal = controller.signal;
34
+ * const debouncedWithSignal = debounce(() => {
35
+ * console.log('Function executed');
36
+ * }, 1000, { signal });
37
+ *
38
+ * debouncedWithSignal();
39
+ *
40
+ * // Will cancel the debounced function call
41
+ * controller.abort();
42
+ */
43
+ export const debounce = (func, debounceMs, { signal, edges } = {}) => {
44
+ let pendingThis = undefined;
45
+ let pendingArgs = null;
46
+ const leading = edges != null && edges.includes('leading');
47
+ const trailing = edges == null || edges.includes('trailing');
48
+ const invoke = () => {
49
+ if (pendingArgs !== null) {
50
+ func.apply(pendingThis, pendingArgs);
51
+ pendingThis = undefined;
52
+ pendingArgs = null;
53
+ }
54
+ };
55
+ const onTimerEnd = () => {
56
+ if (trailing) {
57
+ invoke();
58
+ }
59
+ cancel();
60
+ };
61
+ let timeoutId = null;
62
+ const schedule = () => {
63
+ if (timeoutId != null) {
64
+ clearTimeout(timeoutId);
65
+ }
66
+ timeoutId = setTimeout(() => {
67
+ timeoutId = null;
68
+ onTimerEnd();
69
+ }, debounceMs);
70
+ };
71
+ const cancelTimer = () => {
72
+ if (timeoutId !== null) {
73
+ clearTimeout(timeoutId);
74
+ timeoutId = null;
75
+ }
76
+ };
77
+ const cancel = () => {
78
+ cancelTimer();
79
+ pendingThis = undefined;
80
+ pendingArgs = null;
81
+ };
82
+ const flush = () => {
83
+ invoke();
84
+ };
85
+ const debounced = function (...args) {
86
+ if (signal?.aborted) {
87
+ return;
88
+ }
89
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
90
+ pendingThis = this;
91
+ pendingArgs = args;
92
+ const isFirstCall = timeoutId == null;
93
+ schedule();
94
+ if (leading && isFirstCall) {
95
+ invoke();
96
+ }
97
+ };
98
+ debounced.schedule = schedule;
99
+ debounced.cancel = cancel;
100
+ debounced.flush = flush;
101
+ signal?.addEventListener('abort', cancel, { once: true });
102
+ return debounced;
103
+ };
@@ -6,14 +6,24 @@
6
6
  *
7
7
  */
8
8
  export { formatUnits, parseUnits, compareAddress } from '@ton/walletkit';
9
+ export * from './address/is-valid-address';
10
+ export * from './address/to-bounceble-address';
11
+ export * from './address/to-non-bounceble-address';
12
+ export * from './amount/calc-fiat-value';
13
+ export * from './amount/format-large-value';
14
+ export * from './amount/truncate-decimals';
9
15
  export * from './amount/validate-numeric-string';
16
+ export * from './balance/calc-max-spendable';
17
+ export * from './balance/get-ton-shortfall';
10
18
  export * from './arrays/key-by';
11
19
  export * from './arrays/random-from-array';
12
20
  export * from './errors/get-error-message';
21
+ export * from './functions/debounce';
13
22
  export * from './functions/noop';
14
23
  export * from './jetton/jetton-info';
15
24
  export * from './nft/nft-info';
16
25
  export * from './object/map-values';
26
+ export * from './predicate/is-number';
17
27
  export * from './predicate/is-string';
18
28
  export * from './promise/cancel-promise';
19
29
  export * from './promise/sleep';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEzE,cAAc,kCAAkC,CAAC;AACjD,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEzE,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oCAAoC,CAAC;AACnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC"}
@@ -6,14 +6,24 @@
6
6
  *
7
7
  */
8
8
  export { formatUnits, parseUnits, compareAddress } from '@ton/walletkit';
9
+ export * from './address/is-valid-address';
10
+ export * from './address/to-bounceble-address';
11
+ export * from './address/to-non-bounceble-address';
12
+ export * from './amount/calc-fiat-value';
13
+ export * from './amount/format-large-value';
14
+ export * from './amount/truncate-decimals';
9
15
  export * from './amount/validate-numeric-string';
16
+ export * from './balance/calc-max-spendable';
17
+ export * from './balance/get-ton-shortfall';
10
18
  export * from './arrays/key-by';
11
19
  export * from './arrays/random-from-array';
12
20
  export * from './errors/get-error-message';
21
+ export * from './functions/debounce';
13
22
  export * from './functions/noop';
14
23
  export * from './jetton/jetton-info';
15
24
  export * from './nft/nft-info';
16
25
  export * from './object/map-values';
26
+ export * from './predicate/is-number';
17
27
  export * from './predicate/is-string';
18
28
  export * from './promise/cancel-promise';
19
29
  export * from './promise/sleep';
@@ -5,7 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { Jetton } from '@ton/walletkit';
8
+ import type { Jetton, JettonInfo } from '../../types/jetton';
9
+ export declare const isJettonInfo: (value: unknown) => value is JettonInfo;
9
10
  export declare const getJettonsSymbol: (jetton: Jetton) => string | undefined;
10
11
  export declare const getJettonsName: (jetton: Jetton) => string | undefined;
11
12
  export declare const getJettonsImage: (jetton: Jetton) => string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"jetton-info.d.ts","sourceRoot":"","sources":["../../../../src/utils/jetton/jetton-info.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,KAAG,MAAM,GAAG,SAM1D,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,KAAG,MAAM,GAAG,SAMxD,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,KAAG,MAAM,GAAG,SAazD,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,QAAQ,MAAM;;;;;;;;;;CAkBpD,CAAC"}
1
+ {"version":3,"file":"jetton-info.d.ts","sourceRoot":"","sources":["../../../../src/utils/jetton/jetton-info.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE7D,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,UAStD,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,KAAG,MAAM,GAAG,SAM1D,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,KAAG,MAAM,GAAG,SAMxD,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,KAAG,MAAM,GAAG,SAazD,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,QAAQ,MAAM;;;;;;;;;;CAkBpD,CAAC"}
@@ -5,6 +5,15 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
+ export const isJettonInfo = (value) => {
9
+ if (typeof value !== 'object' || value === null)
10
+ return false;
11
+ const v = value;
12
+ return (typeof v.address === 'string' &&
13
+ typeof v.name === 'string' &&
14
+ typeof v.symbol === 'string' &&
15
+ typeof v.description === 'string');
16
+ };
8
17
  export const getJettonsSymbol = (jetton) => {
9
18
  if (!jetton?.info?.symbol) {
10
19
  return;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) TonTech.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=jetton-info.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jetton-info.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/jetton/jetton-info.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Copyright (c) TonTech.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { describe, expect, it } from 'vitest';
9
+ import { isJettonInfo } from './jetton-info';
10
+ describe('isJettonInfo', () => {
11
+ it('should return true for a valid JettonInfo object', () => {
12
+ expect(isJettonInfo({
13
+ address: 'EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs',
14
+ name: 'Tether USD',
15
+ symbol: 'USDT',
16
+ description: 'Tether USD stablecoin',
17
+ })).toBe(true);
18
+ });
19
+ it('should return true when optional fields are present', () => {
20
+ expect(isJettonInfo({
21
+ address: 'EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs',
22
+ name: 'Tether USD',
23
+ symbol: 'USDT',
24
+ description: 'Tether USD stablecoin',
25
+ decimals: 6,
26
+ image: 'https://example.com/image.png',
27
+ uri: 'https://example.com/meta.json',
28
+ })).toBe(true);
29
+ });
30
+ it('should return false for null', () => {
31
+ expect(isJettonInfo(null)).toBe(false);
32
+ });
33
+ it('should return false for primitives', () => {
34
+ expect(isJettonInfo('string')).toBe(false);
35
+ expect(isJettonInfo(42)).toBe(false);
36
+ expect(isJettonInfo(true)).toBe(false);
37
+ expect(isJettonInfo(undefined)).toBe(false);
38
+ });
39
+ it('should return false when required string fields are missing', () => {
40
+ expect(isJettonInfo({ name: 'Test', symbol: 'TST', description: 'desc' })).toBe(false);
41
+ expect(isJettonInfo({ address: 'EQ...', symbol: 'TST', description: 'desc' })).toBe(false);
42
+ expect(isJettonInfo({ address: 'EQ...', name: 'Test', description: 'desc' })).toBe(false);
43
+ expect(isJettonInfo({ address: 'EQ...', name: 'Test', symbol: 'TST' })).toBe(false);
44
+ });
45
+ it('should return false when required fields are not strings', () => {
46
+ expect(isJettonInfo({ address: 1, name: 'Test', symbol: 'TST', description: 'desc' })).toBe(false);
47
+ expect(isJettonInfo({ address: 'EQ...', name: null, symbol: 'TST', description: 'desc' })).toBe(false);
48
+ });
49
+ it('should return false for an empty object', () => {
50
+ expect(isJettonInfo({})).toBe(false);
51
+ });
52
+ });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) TonTech.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ export declare const isNumber: (value: unknown) => value is number;
9
+ //# sourceMappingURL=is-number.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-number.d.ts","sourceRoot":"","sources":["../../../../src/utils/predicate/is-number.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAUlD,CAAC"}