@otim/utils 0.0.2-development.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 (421) hide show
  1. package/LICENSE +201 -0
  2. package/dist/api/api.d.mts +18 -0
  3. package/dist/api/api.d.ts +18 -0
  4. package/dist/api/api.d.ts.map +1 -0
  5. package/dist/api/core/error.d.mts +74 -0
  6. package/dist/api/core/error.d.ts +74 -0
  7. package/dist/api/core/error.d.ts.map +1 -0
  8. package/dist/api/core/index.d.mts +4 -0
  9. package/dist/api/core/index.d.ts +4 -0
  10. package/dist/api/core/index.d.ts.map +1 -0
  11. package/dist/api/core/instance.d.mts +13 -0
  12. package/dist/api/core/instance.d.ts +13 -0
  13. package/dist/api/core/instance.d.ts.map +1 -0
  14. package/dist/api/core/service.d.mts +51 -0
  15. package/dist/api/core/service.d.ts +51 -0
  16. package/dist/api/core/service.d.ts.map +1 -0
  17. package/dist/api/index.d.mts +7 -0
  18. package/dist/api/index.d.ts +7 -0
  19. package/dist/api/index.d.ts.map +1 -0
  20. package/dist/api/index.js +2061 -0
  21. package/dist/api/index.js.map +7 -0
  22. package/dist/api/index.mjs +2030 -0
  23. package/dist/api/index.mjs.map +7 -0
  24. package/dist/api/schemas/account.d.mts +44 -0
  25. package/dist/api/schemas/account.d.ts +44 -0
  26. package/dist/api/schemas/account.d.ts.map +1 -0
  27. package/dist/api/schemas/activity.d.mts +277 -0
  28. package/dist/api/schemas/activity.d.ts +277 -0
  29. package/dist/api/schemas/activity.d.ts.map +1 -0
  30. package/dist/api/schemas/auth.d.mts +127 -0
  31. package/dist/api/schemas/auth.d.ts +127 -0
  32. package/dist/api/schemas/auth.d.ts.map +1 -0
  33. package/dist/api/schemas/chain.d.mts +15 -0
  34. package/dist/api/schemas/chain.d.ts +15 -0
  35. package/dist/api/schemas/chain.d.ts.map +1 -0
  36. package/dist/api/schemas/config.d.mts +33 -0
  37. package/dist/api/schemas/config.d.ts +33 -0
  38. package/dist/api/schemas/config.d.ts.map +1 -0
  39. package/dist/api/schemas/contacts.d.mts +27 -0
  40. package/dist/api/schemas/contacts.d.ts +27 -0
  41. package/dist/api/schemas/contacts.d.ts.map +1 -0
  42. package/dist/api/schemas/index.d.mts +12 -0
  43. package/dist/api/schemas/index.d.ts +12 -0
  44. package/dist/api/schemas/index.d.ts.map +1 -0
  45. package/dist/api/schemas/instruction.d.mts +446 -0
  46. package/dist/api/schemas/instruction.d.ts +446 -0
  47. package/dist/api/schemas/instruction.d.ts.map +1 -0
  48. package/dist/api/schemas/integration.d.mts +166 -0
  49. package/dist/api/schemas/integration.d.ts +166 -0
  50. package/dist/api/schemas/integration.d.ts.map +1 -0
  51. package/dist/api/schemas/operating-account.d.mts +11 -0
  52. package/dist/api/schemas/operating-account.d.ts +11 -0
  53. package/dist/api/schemas/operating-account.d.ts.map +1 -0
  54. package/dist/api/schemas/payments.d.mts +196 -0
  55. package/dist/api/schemas/payments.d.ts +196 -0
  56. package/dist/api/schemas/payments.d.ts.map +1 -0
  57. package/dist/api/schemas/transaction.d.mts +37 -0
  58. package/dist/api/schemas/transaction.d.ts +37 -0
  59. package/dist/api/schemas/transaction.d.ts.map +1 -0
  60. package/dist/api/services/account.d.mts +8 -0
  61. package/dist/api/services/account.d.ts +8 -0
  62. package/dist/api/services/account.d.ts.map +1 -0
  63. package/dist/api/services/activity.d.mts +7 -0
  64. package/dist/api/services/activity.d.ts +7 -0
  65. package/dist/api/services/activity.d.ts.map +1 -0
  66. package/dist/api/services/auth.d.mts +12 -0
  67. package/dist/api/services/auth.d.ts +12 -0
  68. package/dist/api/services/auth.d.ts.map +1 -0
  69. package/dist/api/services/base.d.mts +10 -0
  70. package/dist/api/services/base.d.ts +10 -0
  71. package/dist/api/services/base.d.ts.map +1 -0
  72. package/dist/api/services/config.d.mts +10 -0
  73. package/dist/api/services/config.d.ts +10 -0
  74. package/dist/api/services/config.d.ts.map +1 -0
  75. package/dist/api/services/contacts.d.mts +8 -0
  76. package/dist/api/services/contacts.d.ts +8 -0
  77. package/dist/api/services/contacts.d.ts.map +1 -0
  78. package/dist/api/services/developer.d.mts +6 -0
  79. package/dist/api/services/developer.d.ts +6 -0
  80. package/dist/api/services/developer.d.ts.map +1 -0
  81. package/dist/api/services/index.d.mts +13 -0
  82. package/dist/api/services/index.d.ts +13 -0
  83. package/dist/api/services/index.d.ts.map +1 -0
  84. package/dist/api/services/instruction.d.mts +12 -0
  85. package/dist/api/services/instruction.d.ts +12 -0
  86. package/dist/api/services/instruction.d.ts.map +1 -0
  87. package/dist/api/services/integration.d.mts +8 -0
  88. package/dist/api/services/integration.d.ts +8 -0
  89. package/dist/api/services/integration.d.ts.map +1 -0
  90. package/dist/api/services/operating-account.d.mts +8 -0
  91. package/dist/api/services/operating-account.d.ts +8 -0
  92. package/dist/api/services/operating-account.d.ts.map +1 -0
  93. package/dist/api/services/payments.d.mts +13 -0
  94. package/dist/api/services/payments.d.ts +13 -0
  95. package/dist/api/services/payments.d.ts.map +1 -0
  96. package/dist/api/services/transaction.d.mts +8 -0
  97. package/dist/api/services/transaction.d.ts +8 -0
  98. package/dist/api/services/transaction.d.ts.map +1 -0
  99. package/dist/api/services/uniswap-token-list-service.d.mts +66 -0
  100. package/dist/api/services/uniswap-token-list-service.d.ts +66 -0
  101. package/dist/api/services/uniswap-token-list-service.d.ts.map +1 -0
  102. package/dist/api/utils/index.d.mts +2 -0
  103. package/dist/api/utils/index.d.ts +2 -0
  104. package/dist/api/utils/index.d.ts.map +1 -0
  105. package/dist/api/utils/pagination.d.mts +32 -0
  106. package/dist/api/utils/pagination.d.ts +32 -0
  107. package/dist/api/utils/pagination.d.ts.map +1 -0
  108. package/dist/chains/config/all-chains.d.mts +4243 -0
  109. package/dist/chains/config/all-chains.d.ts +4243 -0
  110. package/dist/chains/config/all-chains.d.ts.map +1 -0
  111. package/dist/chains/config/custom-chains.d.mts +49 -0
  112. package/dist/chains/config/custom-chains.d.ts +49 -0
  113. package/dist/chains/config/custom-chains.d.ts.map +1 -0
  114. package/dist/chains/config/mainnet-chains.d.mts +1063 -0
  115. package/dist/chains/config/mainnet-chains.d.ts +1063 -0
  116. package/dist/chains/config/mainnet-chains.d.ts.map +1 -0
  117. package/dist/chains/config/supported-chains.d.mts +2172 -0
  118. package/dist/chains/config/supported-chains.d.ts +2172 -0
  119. package/dist/chains/config/supported-chains.d.ts.map +1 -0
  120. package/dist/chains/config/testnet-chains.d.mts +1110 -0
  121. package/dist/chains/config/testnet-chains.d.ts +1110 -0
  122. package/dist/chains/config/testnet-chains.d.ts.map +1 -0
  123. package/dist/chains/index.d.mts +16 -0
  124. package/dist/chains/index.d.ts +16 -0
  125. package/dist/chains/index.d.ts.map +1 -0
  126. package/dist/chains/index.js +490 -0
  127. package/dist/chains/index.js.map +7 -0
  128. package/dist/chains/index.mjs +505 -0
  129. package/dist/chains/index.mjs.map +7 -0
  130. package/dist/chains/lambda/chain-mapping.d.mts +55 -0
  131. package/dist/chains/lambda/chain-mapping.d.ts +55 -0
  132. package/dist/chains/lambda/chain-mapping.d.ts.map +1 -0
  133. package/dist/chains/lambda/index.d.mts +2 -0
  134. package/dist/chains/lambda/index.d.ts +2 -0
  135. package/dist/chains/lambda/index.d.ts.map +1 -0
  136. package/dist/chains/tokens/chain-tokens.d.mts +6 -0
  137. package/dist/chains/tokens/chain-tokens.d.ts +6 -0
  138. package/dist/chains/tokens/chain-tokens.d.ts.map +1 -0
  139. package/dist/chains/tokens/token-addresses.d.mts +8 -0
  140. package/dist/chains/tokens/token-addresses.d.ts +8 -0
  141. package/dist/chains/tokens/token-addresses.d.ts.map +1 -0
  142. package/dist/chains/tokens/token-metadata.d.mts +5 -0
  143. package/dist/chains/tokens/token-metadata.d.ts +5 -0
  144. package/dist/chains/tokens/token-metadata.d.ts.map +1 -0
  145. package/dist/chains/types.d.mts +23 -0
  146. package/dist/chains/types.d.ts +23 -0
  147. package/dist/chains/types.d.ts.map +1 -0
  148. package/dist/chains/utils/filter-tokens.d.mts +3 -0
  149. package/dist/chains/utils/filter-tokens.d.ts +3 -0
  150. package/dist/chains/utils/filter-tokens.d.ts.map +1 -0
  151. package/dist/chains/utils/stablecoin.d.mts +7 -0
  152. package/dist/chains/utils/stablecoin.d.ts +7 -0
  153. package/dist/chains/utils/stablecoin.d.ts.map +1 -0
  154. package/dist/chains/utils/token-maps.d.mts +10 -0
  155. package/dist/chains/utils/token-maps.d.ts +10 -0
  156. package/dist/chains/utils/token-maps.d.ts.map +1 -0
  157. package/dist/constants.d.mts +31 -0
  158. package/dist/constants.d.ts +31 -0
  159. package/dist/constants.d.ts.map +1 -0
  160. package/dist/constants.js +47 -0
  161. package/dist/constants.js.map +7 -0
  162. package/dist/constants.mjs +26 -0
  163. package/dist/constants.mjs.map +7 -0
  164. package/dist/env.d.mts +17 -0
  165. package/dist/env.d.ts +17 -0
  166. package/dist/env.d.ts.map +1 -0
  167. package/dist/formatters/index.d.mts +2 -0
  168. package/dist/formatters/index.d.ts +2 -0
  169. package/dist/formatters/index.d.ts.map +1 -0
  170. package/dist/formatters/index.js +19 -0
  171. package/dist/formatters/index.js.map +7 -0
  172. package/dist/formatters/index.mjs +1 -0
  173. package/dist/formatters/index.mjs.map +7 -0
  174. package/dist/helpers/address.d.mts +7 -0
  175. package/dist/helpers/address.d.ts +7 -0
  176. package/dist/helpers/address.d.ts.map +1 -0
  177. package/dist/helpers/blockchain.d.mts +41 -0
  178. package/dist/helpers/blockchain.d.ts +41 -0
  179. package/dist/helpers/blockchain.d.ts.map +1 -0
  180. package/dist/helpers/date.d.mts +70 -0
  181. package/dist/helpers/date.d.ts +70 -0
  182. package/dist/helpers/date.d.ts.map +1 -0
  183. package/dist/helpers/datetime.d.mts +57 -0
  184. package/dist/helpers/datetime.d.ts +57 -0
  185. package/dist/helpers/datetime.d.ts.map +1 -0
  186. package/dist/helpers/domain.d.mts +2 -0
  187. package/dist/helpers/domain.d.ts +2 -0
  188. package/dist/helpers/domain.d.ts.map +1 -0
  189. package/dist/helpers/index.d.mts +19 -0
  190. package/dist/helpers/index.d.ts +19 -0
  191. package/dist/helpers/index.d.ts.map +1 -0
  192. package/dist/helpers/index.js +1322 -0
  193. package/dist/helpers/index.js.map +7 -0
  194. package/dist/helpers/index.mjs +1294 -0
  195. package/dist/helpers/index.mjs.map +7 -0
  196. package/dist/helpers/intl.d.mts +20 -0
  197. package/dist/helpers/intl.d.ts +20 -0
  198. package/dist/helpers/intl.d.ts.map +1 -0
  199. package/dist/helpers/logger.d.mts +26 -0
  200. package/dist/helpers/logger.d.ts +26 -0
  201. package/dist/helpers/logger.d.ts.map +1 -0
  202. package/dist/helpers/mask-options.d.mts +10 -0
  203. package/dist/helpers/mask-options.d.ts +10 -0
  204. package/dist/helpers/mask-options.d.ts.map +1 -0
  205. package/dist/helpers/num-formatter.d.mts +3 -0
  206. package/dist/helpers/num-formatter.d.ts +3 -0
  207. package/dist/helpers/num-formatter.d.ts.map +1 -0
  208. package/dist/helpers/polling.d.mts +39 -0
  209. package/dist/helpers/polling.d.ts +39 -0
  210. package/dist/helpers/polling.d.ts.map +1 -0
  211. package/dist/helpers/random.d.mts +10 -0
  212. package/dist/helpers/random.d.ts +10 -0
  213. package/dist/helpers/random.d.ts.map +1 -0
  214. package/dist/helpers/sdk-loader.d.mts +25 -0
  215. package/dist/helpers/sdk-loader.d.ts +25 -0
  216. package/dist/helpers/sdk-loader.d.ts.map +1 -0
  217. package/dist/helpers/signatures.d.mts +17 -0
  218. package/dist/helpers/signatures.d.ts +17 -0
  219. package/dist/helpers/signatures.d.ts.map +1 -0
  220. package/dist/helpers/string.d.mts +17 -0
  221. package/dist/helpers/string.d.ts +17 -0
  222. package/dist/helpers/string.d.ts.map +1 -0
  223. package/dist/helpers/types.d.mts +39 -0
  224. package/dist/helpers/types.d.ts +39 -0
  225. package/dist/helpers/types.d.ts.map +1 -0
  226. package/dist/helpers/url.d.mts +11 -0
  227. package/dist/helpers/url.d.ts +11 -0
  228. package/dist/helpers/url.d.ts.map +1 -0
  229. package/dist/helpers/window.d.mts +37 -0
  230. package/dist/helpers/window.d.ts +37 -0
  231. package/dist/helpers/window.d.ts.map +1 -0
  232. package/dist/helpers/zod.d.mts +30 -0
  233. package/dist/helpers/zod.d.ts +30 -0
  234. package/dist/helpers/zod.d.ts.map +1 -0
  235. package/dist/index.d.mts +1 -0
  236. package/dist/index.d.ts +1 -0
  237. package/dist/index.d.ts.map +1 -0
  238. package/dist/index.js +2 -0
  239. package/dist/index.js.map +7 -0
  240. package/dist/index.mjs +1 -0
  241. package/dist/index.mjs.map +7 -0
  242. package/dist/instructions/actions/index.d.mts +5 -0
  243. package/dist/instructions/actions/index.d.ts +5 -0
  244. package/dist/instructions/actions/index.d.ts.map +1 -0
  245. package/dist/instructions/actions/refuel/index.d.mts +15 -0
  246. package/dist/instructions/actions/refuel/index.d.ts +15 -0
  247. package/dist/instructions/actions/refuel/index.d.ts.map +1 -0
  248. package/dist/instructions/actions/swap/index.d.mts +19 -0
  249. package/dist/instructions/actions/swap/index.d.ts +19 -0
  250. package/dist/instructions/actions/swap/index.d.ts.map +1 -0
  251. package/dist/instructions/actions/sweep/index.d.mts +16 -0
  252. package/dist/instructions/actions/sweep/index.d.ts +16 -0
  253. package/dist/instructions/actions/sweep/index.d.ts.map +1 -0
  254. package/dist/instructions/actions/transfer/index.d.mts +13 -0
  255. package/dist/instructions/actions/transfer/index.d.ts +13 -0
  256. package/dist/instructions/actions/transfer/index.d.ts.map +1 -0
  257. package/dist/instructions/activate.d.mts +84 -0
  258. package/dist/instructions/activate.d.ts +84 -0
  259. package/dist/instructions/activate.d.ts.map +1 -0
  260. package/dist/instructions/build.d.mts +146 -0
  261. package/dist/instructions/build.d.ts +146 -0
  262. package/dist/instructions/build.d.ts.map +1 -0
  263. package/dist/instructions/constants.d.mts +9 -0
  264. package/dist/instructions/constants.d.ts +9 -0
  265. package/dist/instructions/constants.d.ts.map +1 -0
  266. package/dist/instructions/contracts/artifacts/abi/build-instruction-action-arguments-abi.d.mts +609 -0
  267. package/dist/instructions/contracts/artifacts/abi/build-instruction-action-arguments-abi.d.ts +609 -0
  268. package/dist/instructions/contracts/artifacts/abi/build-instruction-action-arguments-abi.d.ts.map +1 -0
  269. package/dist/instructions/index.d.mts +6 -0
  270. package/dist/instructions/index.d.ts +6 -0
  271. package/dist/instructions/index.d.ts.map +1 -0
  272. package/dist/instructions/index.js +1152 -0
  273. package/dist/instructions/index.js.map +7 -0
  274. package/dist/instructions/index.mjs +1119 -0
  275. package/dist/instructions/index.mjs.map +7 -0
  276. package/dist/instructions/types.d.mts +289 -0
  277. package/dist/instructions/types.d.ts +289 -0
  278. package/dist/instructions/types.d.ts.map +1 -0
  279. package/dist/payments/action-names.d.mts +16 -0
  280. package/dist/payments/action-names.d.ts +16 -0
  281. package/dist/payments/action-names.d.ts.map +1 -0
  282. package/dist/payments/actions/index.d.mts +5 -0
  283. package/dist/payments/actions/index.d.ts +5 -0
  284. package/dist/payments/actions/index.d.ts.map +1 -0
  285. package/dist/payments/actions/sweep-cctp.d.mts +15 -0
  286. package/dist/payments/actions/sweep-cctp.d.ts +15 -0
  287. package/dist/payments/actions/sweep-cctp.d.ts.map +1 -0
  288. package/dist/payments/actions/sweep-erc20.d.mts +12 -0
  289. package/dist/payments/actions/sweep-erc20.d.ts +12 -0
  290. package/dist/payments/actions/sweep-erc20.d.ts.map +1 -0
  291. package/dist/payments/actions/sweep-uniswap-v3.d.mts +17 -0
  292. package/dist/payments/actions/sweep-uniswap-v3.d.ts +17 -0
  293. package/dist/payments/actions/sweep-uniswap-v3.d.ts.map +1 -0
  294. package/dist/payments/actions/sweep.d.mts +12 -0
  295. package/dist/payments/actions/sweep.d.ts +12 -0
  296. package/dist/payments/actions/sweep.d.ts.map +1 -0
  297. package/dist/payments/build.d.mts +27 -0
  298. package/dist/payments/build.d.ts +27 -0
  299. package/dist/payments/build.d.ts.map +1 -0
  300. package/dist/payments/chain-token-config-builder.d.mts +10 -0
  301. package/dist/payments/chain-token-config-builder.d.ts +10 -0
  302. package/dist/payments/chain-token-config-builder.d.ts.map +1 -0
  303. package/dist/payments/comprehensive-payment-request.d.mts +25 -0
  304. package/dist/payments/comprehensive-payment-request.d.ts +25 -0
  305. package/dist/payments/comprehensive-payment-request.d.ts.map +1 -0
  306. package/dist/payments/config/cctp.d.mts +14 -0
  307. package/dist/payments/config/cctp.d.ts +14 -0
  308. package/dist/payments/config/cctp.d.ts.map +1 -0
  309. package/dist/payments/config/index.d.mts +3 -0
  310. package/dist/payments/config/index.d.ts +3 -0
  311. package/dist/payments/config/index.d.ts.map +1 -0
  312. package/dist/payments/config/tokens.d.mts +14 -0
  313. package/dist/payments/config/tokens.d.ts +14 -0
  314. package/dist/payments/config/tokens.d.ts.map +1 -0
  315. package/dist/payments/index.d.mts +16 -0
  316. package/dist/payments/index.d.ts +16 -0
  317. package/dist/payments/index.d.ts.map +1 -0
  318. package/dist/payments/index.js +1303 -0
  319. package/dist/payments/index.js.map +7 -0
  320. package/dist/payments/index.mjs +1281 -0
  321. package/dist/payments/index.mjs.map +7 -0
  322. package/dist/payments/instruction-registry.d.mts +19 -0
  323. package/dist/payments/instruction-registry.d.ts +19 -0
  324. package/dist/payments/instruction-registry.d.ts.map +1 -0
  325. package/dist/payments/payment-metadata-builder.d.mts +56 -0
  326. package/dist/payments/payment-metadata-builder.d.ts +56 -0
  327. package/dist/payments/payment-metadata-builder.d.ts.map +1 -0
  328. package/dist/payments/payment-metadata.d.mts +15 -0
  329. package/dist/payments/payment-metadata.d.ts +15 -0
  330. package/dist/payments/payment-metadata.d.ts.map +1 -0
  331. package/dist/payments/payment-request-token-resolver.d.mts +25 -0
  332. package/dist/payments/payment-request-token-resolver.d.ts +25 -0
  333. package/dist/payments/payment-request-token-resolver.d.ts.map +1 -0
  334. package/dist/payments/types.d.mts +40 -0
  335. package/dist/payments/types.d.ts +40 -0
  336. package/dist/payments/types.d.ts.map +1 -0
  337. package/dist/payments/validation.d.mts +19 -0
  338. package/dist/payments/validation.d.ts +19 -0
  339. package/dist/payments/validation.d.ts.map +1 -0
  340. package/dist/schemas/account.d.mts +9 -0
  341. package/dist/schemas/account.d.ts +9 -0
  342. package/dist/schemas/account.d.ts.map +1 -0
  343. package/dist/schemas/brand.d.mts +7 -0
  344. package/dist/schemas/brand.d.ts +7 -0
  345. package/dist/schemas/brand.d.ts.map +1 -0
  346. package/dist/schemas/contact.d.mts +18 -0
  347. package/dist/schemas/contact.d.ts +18 -0
  348. package/dist/schemas/contact.d.ts.map +1 -0
  349. package/dist/schemas/index.d.mts +10 -0
  350. package/dist/schemas/index.d.ts +10 -0
  351. package/dist/schemas/index.d.ts.map +1 -0
  352. package/dist/schemas/index.js +433 -0
  353. package/dist/schemas/index.js.map +7 -0
  354. package/dist/schemas/index.mjs +410 -0
  355. package/dist/schemas/index.mjs.map +7 -0
  356. package/dist/schemas/instruction.d.mts +248 -0
  357. package/dist/schemas/instruction.d.ts +248 -0
  358. package/dist/schemas/instruction.d.ts.map +1 -0
  359. package/dist/schemas/misc.d.mts +36 -0
  360. package/dist/schemas/misc.d.ts +36 -0
  361. package/dist/schemas/misc.d.ts.map +1 -0
  362. package/dist/schemas/payment.d.mts +64 -0
  363. package/dist/schemas/payment.d.ts +64 -0
  364. package/dist/schemas/payment.d.ts.map +1 -0
  365. package/dist/schemas/token.d.mts +17 -0
  366. package/dist/schemas/token.d.ts +17 -0
  367. package/dist/schemas/token.d.ts.map +1 -0
  368. package/dist/schemas/transaction.d.mts +65 -0
  369. package/dist/schemas/transaction.d.ts +65 -0
  370. package/dist/schemas/transaction.d.ts.map +1 -0
  371. package/dist/schemas/user.d.mts +24 -0
  372. package/dist/schemas/user.d.ts +24 -0
  373. package/dist/schemas/user.d.ts.map +1 -0
  374. package/dist/server/client.d.mts +3 -0
  375. package/dist/server/client.d.ts +3 -0
  376. package/dist/server/client.d.ts.map +1 -0
  377. package/dist/server/index.d.mts +3 -0
  378. package/dist/server/index.d.ts +3 -0
  379. package/dist/server/index.d.ts.map +1 -0
  380. package/dist/server/index.js +420 -0
  381. package/dist/server/index.js.map +7 -0
  382. package/dist/server/index.mjs +389 -0
  383. package/dist/server/index.mjs.map +7 -0
  384. package/dist/server/routes/account.d.mts +4 -0
  385. package/dist/server/routes/account.d.ts +4 -0
  386. package/dist/server/routes/account.d.ts.map +1 -0
  387. package/dist/server/routes/auth.d.mts +28 -0
  388. package/dist/server/routes/auth.d.ts +28 -0
  389. package/dist/server/routes/auth.d.ts.map +1 -0
  390. package/dist/server/routes/bridge.d.mts +192 -0
  391. package/dist/server/routes/bridge.d.ts +192 -0
  392. package/dist/server/routes/bridge.d.ts.map +1 -0
  393. package/dist/server/routes/config.d.mts +3 -0
  394. package/dist/server/routes/config.d.ts +3 -0
  395. package/dist/server/routes/config.d.ts.map +1 -0
  396. package/dist/server/routes/index.d.mts +8 -0
  397. package/dist/server/routes/index.d.ts +8 -0
  398. package/dist/server/routes/index.d.ts.map +1 -0
  399. package/dist/server/routes/instruction.d.mts +4 -0
  400. package/dist/server/routes/instruction.d.ts +4 -0
  401. package/dist/server/routes/instruction.d.ts.map +1 -0
  402. package/dist/server/routes/integration.d.mts +4 -0
  403. package/dist/server/routes/integration.d.ts +4 -0
  404. package/dist/server/routes/integration.d.ts.map +1 -0
  405. package/dist/server/routes/payments.d.mts +4 -0
  406. package/dist/server/routes/payments.d.ts +4 -0
  407. package/dist/server/routes/payments.d.ts.map +1 -0
  408. package/dist/server/routes/verify.d.mts +3 -0
  409. package/dist/server/routes/verify.d.ts +3 -0
  410. package/dist/server/routes/verify.d.ts.map +1 -0
  411. package/dist/wallet/wagmi/config.d.mts +18 -0
  412. package/dist/wallet/wagmi/config.d.ts +18 -0
  413. package/dist/wallet/wagmi/config.d.ts.map +1 -0
  414. package/dist/wallet/wagmi/index.d.mts +2 -0
  415. package/dist/wallet/wagmi/index.d.ts +2 -0
  416. package/dist/wallet/wagmi/index.d.ts.map +1 -0
  417. package/dist/wallet/wagmi/index.js +429 -0
  418. package/dist/wallet/wagmi/index.js.map +7 -0
  419. package/dist/wallet/wagmi/index.mjs +431 -0
  420. package/dist/wallet/wagmi/index.mjs.map +7 -0
  421. package/package.json +222 -0
@@ -0,0 +1,1303 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
31
+
32
+ // src/payments/index.ts
33
+ var payments_exports = {};
34
+ __export(payments_exports, {
35
+ DefaultCCTPConfig: () => DefaultCCTPConfig,
36
+ PaymentAction: () => PaymentAction,
37
+ SignatureValidator: () => SignatureValidator,
38
+ UniswapV3FeeTier: () => UniswapV3FeeTier,
39
+ addActionNamesToInstructions: () => addActionNamesToInstructions,
40
+ assertMinimumSignatures: () => assertMinimumSignatures,
41
+ assertSignatureCount: () => assertSignatureCount,
42
+ buildInvoiceMetadata: () => buildInvoiceMetadata,
43
+ buildPaymentMetadata: () => buildPaymentMetadata,
44
+ createChainTokenConfigs: () => createChainTokenConfigs,
45
+ createComprehensivePaymentRequest: () => createComprehensivePaymentRequest,
46
+ createDefaultFee: () => createDefaultFee,
47
+ createFeeWithToken: () => createFeeWithToken,
48
+ createPaymentRequestBuildPayload: () => createPaymentRequestBuildPayload,
49
+ createSweepActionArguments: () => createSweepActionArguments,
50
+ createSweepCCTPActionArguments: () => createSweepCCTPActionArguments,
51
+ createSweepERC20ActionArguments: () => createSweepERC20ActionArguments,
52
+ createSweepUniswapV3ActionArguments: () => createSweepUniswapV3ActionArguments,
53
+ createTokenIdentifier: () => createTokenIdentifier,
54
+ defaultCCTPConfig: () => defaultCCTPConfig,
55
+ extractActionNamesMap: () => extractActionNamesMap,
56
+ getRecommendedFeeTier: () => getRecommendedFeeTier,
57
+ instructionRegistry: () => instructionRegistry,
58
+ isNativeToken: () => isNativeToken,
59
+ resolvePreferredStablecoin: () => resolvePreferredStablecoin,
60
+ validatePaymentMetadata: () => validatePaymentMetadata
61
+ });
62
+ module.exports = __toCommonJS(payments_exports);
63
+
64
+ // src/payments/types.ts
65
+ var PaymentAction = {
66
+ Sweep: "sweep",
67
+ SweepCCTP: "sweepCCTP",
68
+ SweepERC20: "sweepERC20",
69
+ SweepUniswapV3: "sweepUniswapV3"
70
+ };
71
+ var UniswapV3FeeTier = {
72
+ Lowest: "100",
73
+ Low: "500",
74
+ Medium: "3000",
75
+ High: "10000"
76
+ };
77
+
78
+ // src/payments/config/cctp.ts
79
+ var import_chains = require("viem/chains");
80
+ var cctpSupportedChains = /* @__PURE__ */ new Set([
81
+ import_chains.mainnet.id,
82
+ import_chains.optimism.id,
83
+ import_chains.arbitrum.id,
84
+ import_chains.base.id,
85
+ import_chains.sepolia.id,
86
+ import_chains.optimismSepolia.id,
87
+ import_chains.arbitrumSepolia.id,
88
+ import_chains.baseSepolia.id
89
+ ]);
90
+ var cctpDomainMapping = {
91
+ [import_chains.mainnet.id]: 0,
92
+ [import_chains.optimism.id]: 2,
93
+ [import_chains.arbitrum.id]: 3,
94
+ [import_chains.base.id]: 6,
95
+ [import_chains.sepolia.id]: 0,
96
+ [import_chains.optimismSepolia.id]: 2,
97
+ [import_chains.arbitrumSepolia.id]: 3,
98
+ [import_chains.baseSepolia.id]: 6
99
+ };
100
+ var DefaultCCTPConfig = class {
101
+ constructor() {
102
+ __publicField(this, "supportedChainIds");
103
+ this.supportedChainIds = cctpSupportedChains;
104
+ }
105
+ isSupported(chainId) {
106
+ return this.supportedChainIds.has(chainId);
107
+ }
108
+ getDomain(chainId) {
109
+ return cctpDomainMapping[chainId] ?? null;
110
+ }
111
+ };
112
+ var defaultCCTPConfig = new DefaultCCTPConfig();
113
+
114
+ // src/helpers/blockchain.ts
115
+ var import_viem = require("viem");
116
+ var DEFAULT_ADDRESS = "0x0000000000000000000000000000000000000000";
117
+
118
+ // src/helpers/date.ts
119
+ var import_zod = __toESM(require("zod"));
120
+ var iso8601DateSchema = import_zod.default.string().regex(
121
+ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/,
122
+ "Must be a valid ISO 8601 date format (e.g., 2024-12-31T23:59:59.000Z)"
123
+ );
124
+ var TimeUnit = {
125
+ Day: "day",
126
+ Month: "month",
127
+ Year: "year"
128
+ };
129
+ var units = {
130
+ [TimeUnit.Day]: {
131
+ one: "day",
132
+ other: "days"
133
+ },
134
+ [TimeUnit.Month]: {
135
+ one: "month",
136
+ other: "months"
137
+ },
138
+ [TimeUnit.Year]: {
139
+ one: "year",
140
+ other: "years"
141
+ }
142
+ };
143
+ var isDateInvalid = (date) => {
144
+ return date.toString() === "Invalid Date";
145
+ };
146
+ var isValidDate = (date) => {
147
+ return !isDateInvalid(date) && !isNaN(date.getTime());
148
+ };
149
+
150
+ // src/helpers/types.ts
151
+ var isNumber = (value) => typeof value === "number";
152
+
153
+ // src/chains/utils/stablecoin.ts
154
+ var stablecoinSymbols = ["USDC", "USDT"];
155
+ function isStablecoin(symbol) {
156
+ if (typeof symbol === "string") {
157
+ return stablecoinSymbols.includes(
158
+ symbol
159
+ );
160
+ }
161
+ return symbol.every(
162
+ (s) => stablecoinSymbols.includes(s)
163
+ );
164
+ }
165
+
166
+ // src/payments/config/tokens.ts
167
+ function getRecommendedFeeTier(tokenIn, tokenOut) {
168
+ if (isStablecoin([tokenIn, tokenOut])) {
169
+ return UniswapV3FeeTier.Low;
170
+ }
171
+ return UniswapV3FeeTier.Medium;
172
+ }
173
+
174
+ // src/payments/build.ts
175
+ var DEFAULT_SET_EPHEMERAL_TARGET = true;
176
+ function createPaymentRequestBuildPayload(params) {
177
+ const {
178
+ payerAddress = null,
179
+ completionInstructions,
180
+ instructions = [],
181
+ metadata = {}
182
+ } = params;
183
+ return {
184
+ payerAddress,
185
+ completionInstructions: completionInstructions.map(processInstruction),
186
+ instructions: instructions.map(processInstruction),
187
+ metadata
188
+ };
189
+ }
190
+ function processInstruction(spec) {
191
+ return {
192
+ chainId: spec.chainId,
193
+ salt: spec.salt ?? generateRandomSalt(),
194
+ maxExecutions: spec.maxExecutions,
195
+ actionArguments: spec.actionArguments,
196
+ setEphemeralTarget: spec.setEphemeralTarget ?? DEFAULT_SET_EPHEMERAL_TARGET
197
+ };
198
+ }
199
+ function generateRandomSalt() {
200
+ return Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
201
+ }
202
+ function createDefaultFee(executionFee = 0, maxBaseFeePerGas = "0x0", maxPriorityFeePerGas = "0x0", token = DEFAULT_ADDRESS) {
203
+ return {
204
+ token,
205
+ executionFee,
206
+ maxBaseFeePerGas,
207
+ maxPriorityFeePerGas
208
+ };
209
+ }
210
+ function createFeeWithToken(token, maxPriorityFeePerGas) {
211
+ return createDefaultFee(0, "0x0", maxPriorityFeePerGas ?? "0x0", token);
212
+ }
213
+
214
+ // src/payments/comprehensive-payment-request.ts
215
+ var import_viem3 = require("viem");
216
+
217
+ // src/payments/actions/sweep-cctp.ts
218
+ var import_viem2 = require("viem");
219
+ function createSweepCCTPActionArguments(payload) {
220
+ const cctpConfig = payload.cctpConfig ?? defaultCCTPConfig;
221
+ const destinationDomain = resolveCCTPDomain(
222
+ payload.destinationChainId,
223
+ cctpConfig
224
+ );
225
+ return {
226
+ [PaymentAction.SweepCCTP]: {
227
+ token: payload.token,
228
+ destinationDomain,
229
+ /* CCTP requires the recipient address to be padded to 32 bytes */
230
+ destinationMintRecipient: (0, import_viem2.pad)(payload.destinationMintRecipient, {
231
+ size: 32
232
+ }),
233
+ threshold: payload.threshold,
234
+ endBalance: payload.endBalance,
235
+ fee: payload.fee
236
+ }
237
+ };
238
+ }
239
+ function resolveCCTPDomain(destinationChainId, cctpConfig) {
240
+ const domain = cctpConfig.getDomain(destinationChainId);
241
+ if (domain === null) {
242
+ throw new Error(`Chain ${destinationChainId} does not support CCTP`);
243
+ }
244
+ return domain;
245
+ }
246
+
247
+ // src/payments/actions/sweep-erc20.ts
248
+ function createSweepERC20ActionArguments(payload) {
249
+ return {
250
+ [PaymentAction.SweepERC20]: {
251
+ token: payload.token,
252
+ target: payload.target,
253
+ threshold: payload.threshold,
254
+ endBalance: payload.endBalance,
255
+ fee: payload.fee
256
+ }
257
+ };
258
+ }
259
+
260
+ // src/payments/actions/sweep-uniswap-v3.ts
261
+ function createSweepUniswapV3ActionArguments(payload) {
262
+ return {
263
+ [PaymentAction.SweepUniswapV3]: {
264
+ recipient: payload.recipient,
265
+ tokenIn: payload.tokenIn,
266
+ tokenOut: payload.tokenOut,
267
+ feeTier: payload.feeTier,
268
+ threshold: payload.threshold,
269
+ endBalance: payload.endBalance,
270
+ floorAmountOut: payload.floorAmountOut,
271
+ meanPriceLookBack: payload.meanPriceLookBack,
272
+ maxPriceDeviationBps: payload.maxPriceDeviationBps,
273
+ fee: payload.fee
274
+ }
275
+ };
276
+ }
277
+
278
+ // src/payments/comprehensive-payment-request.ts
279
+ var USDC_SYMBOL = "USDC";
280
+ var USDT_SYMBOL = "USDT";
281
+ var MINIMUM_THRESHOLD = 1n;
282
+ var UNISWAP_MEAN_PRICE_LOOKBACK = 600;
283
+ var ZERO_BALANCE = 0n;
284
+ var USDT_MAX_PRICE_DEVIATION_BPS = 200;
285
+ var DEFAULT_MAX_PRICE_DEVIATION_BPS = 500;
286
+ var STABLE_SLIPPAGE_BPS = 1;
287
+ var NON_STABLE_SLIPPAGE_BPS = 50;
288
+ function createComprehensivePaymentRequest(params) {
289
+ const {
290
+ settlementChainId,
291
+ recipient,
292
+ amount,
293
+ ephemeralWalletAddress,
294
+ chainTokenConfigs,
295
+ payerAddress,
296
+ metadata,
297
+ feeToken,
298
+ cctpConfig = defaultCCTPConfig
299
+ } = params;
300
+ validateSettlementChainSupport(settlementChainId, cctpConfig);
301
+ const settlementConfig = findChainConfig(
302
+ settlementChainId,
303
+ chainTokenConfigs
304
+ );
305
+ const settlementUSDC = findSettlementUSDC(settlementConfig);
306
+ const threshold = calculateThreshold(amount, settlementUSDC.decimals);
307
+ const instructionFee = createFeeWithToken(feeToken);
308
+ const completionInstructions = createCompletionInstructions(
309
+ settlementChainId,
310
+ settlementUSDC.address,
311
+ recipient,
312
+ threshold,
313
+ instructionFee,
314
+ chainTokenConfigs
315
+ );
316
+ const instructions = createCrossChainInstructions(
317
+ chainTokenConfigs,
318
+ settlementChainId,
319
+ ephemeralWalletAddress,
320
+ instructionFee,
321
+ cctpConfig
322
+ );
323
+ return createPaymentRequestBuildPayload({
324
+ payerAddress,
325
+ completionInstructions,
326
+ instructions,
327
+ metadata
328
+ });
329
+ }
330
+ function validateSettlementChainSupport(chainId, cctpConfig) {
331
+ if (!cctpConfig.isSupported(chainId)) {
332
+ throw new Error(`Settlement chain ${chainId} does not support CCTP`);
333
+ }
334
+ }
335
+ function findChainConfig(chainId, configs) {
336
+ const config = configs.find((c) => c.chainId === chainId);
337
+ if (!config) {
338
+ throw new Error(
339
+ `Settlement chain ${chainId} not found in chain token configs`
340
+ );
341
+ }
342
+ return config;
343
+ }
344
+ function findSettlementUSDC(settlementConfig) {
345
+ const usdc = settlementConfig.tokens.find(
346
+ (token) => token.symbol.toUpperCase() === USDC_SYMBOL
347
+ );
348
+ if (!usdc) {
349
+ throw new Error(
350
+ `Settlement chain ${settlementConfig.chainId} does not have USDC configured`
351
+ );
352
+ }
353
+ return {
354
+ address: usdc.address,
355
+ decimals: usdc.decimals
356
+ };
357
+ }
358
+ function calculateThreshold(amount, decimals) {
359
+ return (0, import_viem3.toHex)((0, import_viem3.parseUnits)(amount, decimals));
360
+ }
361
+ function createCompletionInstructions(settlementChainId, settlementUSDCAddress, recipient, threshold, instructionFee, chainTokenConfigs) {
362
+ const instructions = [];
363
+ instructions.push(
364
+ createSettlementSweepInstruction(
365
+ settlementChainId,
366
+ settlementUSDCAddress,
367
+ recipient,
368
+ threshold,
369
+ instructionFee
370
+ )
371
+ );
372
+ const swapInstructions = createTokenSwapInstructions(
373
+ settlementChainId,
374
+ chainTokenConfigs,
375
+ recipient,
376
+ threshold,
377
+ instructionFee
378
+ );
379
+ instructions.push(...swapInstructions);
380
+ return instructions;
381
+ }
382
+ function createSettlementSweepInstruction(chainId, tokenAddress, recipient, threshold, fee) {
383
+ return {
384
+ chainId,
385
+ maxExecutions: 1,
386
+ actionArguments: createSweepERC20ActionArguments({
387
+ chainId,
388
+ maxExecutions: 1,
389
+ token: tokenAddress,
390
+ target: recipient,
391
+ threshold,
392
+ endBalance: (0, import_viem3.toHex)(ZERO_BALANCE),
393
+ fee
394
+ }),
395
+ setEphemeralTarget: false
396
+ };
397
+ }
398
+ function createTokenSwapInstructions(settlementChainId, chainTokenConfigs, settlementRecipient, threshold, instructionFee) {
399
+ const swapInstructions = [];
400
+ const settlementConfig = chainTokenConfigs.find(
401
+ (c) => c.chainId === settlementChainId
402
+ );
403
+ if (!settlementConfig) {
404
+ return swapInstructions;
405
+ }
406
+ const settlementUSDC = settlementConfig.tokens.find(
407
+ (t) => t.symbol.toUpperCase() === USDC_SYMBOL
408
+ );
409
+ if (!settlementUSDC) {
410
+ return swapInstructions;
411
+ }
412
+ for (const sourceToken of settlementConfig.tokens) {
413
+ if (sourceToken.symbol.toUpperCase() === USDC_SYMBOL) {
414
+ continue;
415
+ }
416
+ const swapInstruction = createSwapInstruction(
417
+ settlementChainId,
418
+ sourceToken,
419
+ settlementUSDC,
420
+ settlementRecipient,
421
+ threshold,
422
+ instructionFee
423
+ );
424
+ swapInstructions.push(swapInstruction);
425
+ }
426
+ return swapInstructions;
427
+ }
428
+ function createSwapInstruction(chainId, tokenIn, tokenOut, settlementRecipient, threshold, fee) {
429
+ const { instruction } = createSwapInstructionWithFloor(
430
+ chainId,
431
+ tokenIn,
432
+ tokenOut,
433
+ settlementRecipient,
434
+ threshold,
435
+ fee,
436
+ false
437
+ );
438
+ return instruction;
439
+ }
440
+ function createSwapInstructionWithFloor(chainId, tokenIn, tokenOut, recipient, threshold, fee, setEphemeralTarget) {
441
+ const feeTier = getRecommendedFeeTier(
442
+ tokenIn.symbol.toUpperCase(),
443
+ USDC_SYMBOL
444
+ );
445
+ const isStableToStableSwap = isStablecoin([
446
+ tokenIn.symbol.toUpperCase(),
447
+ tokenOut.symbol.toUpperCase()
448
+ ]);
449
+ const slippageBps = isStableToStableSwap ? STABLE_SLIPPAGE_BPS : NON_STABLE_SLIPPAGE_BPS;
450
+ const maxPriceDeviationBps = tokenIn.symbol.toUpperCase() === USDT_SYMBOL ? USDT_MAX_PRICE_DEVIATION_BPS : DEFAULT_MAX_PRICE_DEVIATION_BPS;
451
+ const baseAmount = BigInt(threshold);
452
+ const afterFeeAmount = baseAmount * BigInt(1e6 - Number(feeTier)) / 1000000n;
453
+ const floorAmountOut = afterFeeAmount * BigInt(1e4 - slippageBps) / 10000n;
454
+ const instruction = {
455
+ chainId,
456
+ maxExecutions: 1,
457
+ actionArguments: createSweepUniswapV3ActionArguments({
458
+ chainId,
459
+ maxExecutions: 1,
460
+ recipient,
461
+ tokenIn: tokenIn.address,
462
+ tokenOut: tokenOut.address,
463
+ feeTier,
464
+ threshold,
465
+ endBalance: (0, import_viem3.toHex)(ZERO_BALANCE),
466
+ floorAmountOut: (0, import_viem3.toHex)(floorAmountOut),
467
+ meanPriceLookBack: UNISWAP_MEAN_PRICE_LOOKBACK,
468
+ maxPriceDeviationBps,
469
+ fee
470
+ }),
471
+ setEphemeralTarget
472
+ };
473
+ return { instruction, floorAmountOut };
474
+ }
475
+ function createCrossChainSwapInstructions(chainConfig, chainUSDC, ephemeralWalletAddress, instructionFee) {
476
+ const swapInstructions = [];
477
+ for (const sourceToken of chainConfig.tokens) {
478
+ if (sourceToken.symbol.toUpperCase() === USDC_SYMBOL) {
479
+ continue;
480
+ }
481
+ const feeTier = getRecommendedFeeTier(
482
+ sourceToken.symbol.toUpperCase(),
483
+ USDC_SYMBOL
484
+ );
485
+ const maxPriceDeviationBps = sourceToken.symbol.toUpperCase() === USDT_SYMBOL ? USDT_MAX_PRICE_DEVIATION_BPS : DEFAULT_MAX_PRICE_DEVIATION_BPS;
486
+ const instruction = {
487
+ chainId: chainConfig.chainId,
488
+ maxExecutions: 1,
489
+ actionArguments: createSweepUniswapV3ActionArguments({
490
+ chainId: chainConfig.chainId,
491
+ maxExecutions: 1,
492
+ recipient: ephemeralWalletAddress,
493
+ tokenIn: sourceToken.address,
494
+ tokenOut: chainUSDC.address,
495
+ feeTier,
496
+ threshold: (0, import_viem3.toHex)(MINIMUM_THRESHOLD),
497
+ endBalance: (0, import_viem3.toHex)(ZERO_BALANCE),
498
+ floorAmountOut: (0, import_viem3.toHex)(0n),
499
+ meanPriceLookBack: UNISWAP_MEAN_PRICE_LOOKBACK,
500
+ maxPriceDeviationBps,
501
+ fee: instructionFee
502
+ }),
503
+ setEphemeralTarget: true
504
+ };
505
+ swapInstructions.push(instruction);
506
+ }
507
+ return swapInstructions;
508
+ }
509
+ function createCrossChainInstructions(chainTokenConfigs, settlementChainId, ephemeralWalletAddress, instructionFee, cctpConfig) {
510
+ const instructions = [];
511
+ for (const chainConfig of chainTokenConfigs) {
512
+ if (chainConfig.chainId === settlementChainId) {
513
+ continue;
514
+ }
515
+ const chainUSDC = chainConfig.tokens.find(
516
+ (token) => token.symbol.toUpperCase() === USDC_SYMBOL
517
+ );
518
+ if (!chainUSDC || !cctpConfig.isSupported(chainConfig.chainId)) {
519
+ continue;
520
+ }
521
+ const swapInstructions = createCrossChainSwapInstructions(
522
+ chainConfig,
523
+ chainUSDC,
524
+ ephemeralWalletAddress,
525
+ instructionFee
526
+ );
527
+ instructions.push(...swapInstructions);
528
+ const bridgeInstruction = createCCTPBridgeInstruction(
529
+ chainConfig.chainId,
530
+ chainUSDC.address,
531
+ settlementChainId,
532
+ ephemeralWalletAddress,
533
+ (0, import_viem3.toHex)(MINIMUM_THRESHOLD),
534
+ instructionFee,
535
+ cctpConfig
536
+ );
537
+ instructions.push(bridgeInstruction);
538
+ }
539
+ return instructions;
540
+ }
541
+ function createCCTPBridgeInstruction(sourceChainId, tokenAddress, destinationChainId, ephemeralWalletAddress, threshold, fee, cctpConfig) {
542
+ return {
543
+ chainId: sourceChainId,
544
+ maxExecutions: 1,
545
+ actionArguments: createSweepCCTPActionArguments({
546
+ chainId: sourceChainId,
547
+ maxExecutions: 1,
548
+ token: tokenAddress,
549
+ destinationChainId,
550
+ destinationMintRecipient: ephemeralWalletAddress,
551
+ threshold,
552
+ endBalance: (0, import_viem3.toHex)(ZERO_BALANCE),
553
+ fee,
554
+ cctpConfig
555
+ }),
556
+ setEphemeralTarget: true
557
+ };
558
+ }
559
+
560
+ // src/payments/actions/sweep.ts
561
+ var import_viem4 = require("viem");
562
+ function createSweepActionArguments(payload) {
563
+ return {
564
+ [PaymentAction.Sweep]: {
565
+ target: payload.target,
566
+ threshold: payload.threshold,
567
+ endBalance: payload.endBalance,
568
+ gasLimit: (0, import_viem4.toHex)(payload.gasLimit),
569
+ fee: payload.fee
570
+ }
571
+ };
572
+ }
573
+
574
+ // src/instructions/contracts/schemas/eip-712/actions/deactivate-instruction.json
575
+ var deactivate_instruction_default = {
576
+ types: {
577
+ Instruction: [
578
+ { name: "salt", type: "uint256" },
579
+ { name: "maxExecutions", type: "uint256" },
580
+ { name: "action", type: "address" },
581
+ { name: "deactivateInstruction", type: "DeactivateInstruction" }
582
+ ],
583
+ DeactivateInstruction: [
584
+ { name: "instructionId", type: "bytes32" },
585
+ { name: "fee", type: "Fee" }
586
+ ],
587
+ Fee: [
588
+ { name: "token", type: "address" },
589
+ { name: "maxBaseFeePerGas", type: "uint256" },
590
+ { name: "maxPriorityFeePerGas", type: "uint256" },
591
+ { name: "executionFee", type: "uint256" }
592
+ ]
593
+ }
594
+ };
595
+
596
+ // src/instructions/contracts/schemas/eip-712/actions/refuel-erc20.json
597
+ var refuel_erc20_default = {
598
+ types: {
599
+ Instruction: [
600
+ { name: "salt", type: "uint256" },
601
+ { name: "maxExecutions", type: "uint256" },
602
+ { name: "action", type: "address" },
603
+ { name: "refuelERC20", type: "RefuelERC20" }
604
+ ],
605
+ RefuelERC20: [
606
+ { name: "token", type: "address" },
607
+ { name: "target", type: "address" },
608
+ { name: "threshold", type: "uint256" },
609
+ { name: "endBalance", type: "uint256" },
610
+ { name: "fee", type: "Fee" }
611
+ ],
612
+ Fee: [
613
+ { name: "token", type: "address" },
614
+ { name: "maxBaseFeePerGas", type: "uint256" },
615
+ { name: "maxPriorityFeePerGas", type: "uint256" },
616
+ { name: "executionFee", type: "uint256" }
617
+ ]
618
+ }
619
+ };
620
+
621
+ // src/instructions/contracts/schemas/eip-712/actions/refuel.json
622
+ var refuel_default = {
623
+ types: {
624
+ Instruction: [
625
+ { name: "salt", type: "uint256" },
626
+ { name: "maxExecutions", type: "uint256" },
627
+ { name: "action", type: "address" },
628
+ { name: "refuel", type: "Refuel" }
629
+ ],
630
+ Refuel: [
631
+ { name: "target", type: "address" },
632
+ { name: "threshold", type: "uint256" },
633
+ { name: "endBalance", type: "uint256" },
634
+ { name: "gasLimit", type: "uint256" },
635
+ { name: "fee", type: "Fee" }
636
+ ],
637
+ Fee: [
638
+ { name: "token", type: "address" },
639
+ { name: "maxBaseFeePerGas", type: "uint256" },
640
+ { name: "maxPriorityFeePerGas", type: "uint256" },
641
+ { name: "executionFee", type: "uint256" }
642
+ ]
643
+ }
644
+ };
645
+
646
+ // src/instructions/contracts/schemas/eip-712/actions/sweep-cctp.json
647
+ var sweep_cctp_default = {
648
+ types: {
649
+ Instruction: [
650
+ { name: "salt", type: "uint256" },
651
+ { name: "maxExecutions", type: "uint256" },
652
+ { name: "action", type: "address" },
653
+ { name: "sweepCCTP", type: "SweepCCTP" }
654
+ ],
655
+ SweepCCTP: [
656
+ { name: "token", type: "address" },
657
+ { name: "destinationDomain", type: "uint32" },
658
+ { name: "destinationMintRecipient", type: "bytes32" },
659
+ { name: "threshold", type: "uint256" },
660
+ { name: "endBalance", type: "uint256" },
661
+ { name: "fee", type: "Fee" }
662
+ ],
663
+ Fee: [
664
+ { name: "token", type: "address" },
665
+ { name: "maxBaseFeePerGas", type: "uint256" },
666
+ { name: "maxPriorityFeePerGas", type: "uint256" },
667
+ { name: "executionFee", type: "uint256" }
668
+ ]
669
+ }
670
+ };
671
+
672
+ // src/instructions/contracts/schemas/eip-712/actions/sweep-deposit-account-erc20.json
673
+ var sweep_deposit_account_erc20_default = {
674
+ types: {
675
+ Instruction: [
676
+ { name: "salt", type: "uint256" },
677
+ { name: "maxExecutions", type: "uint256" },
678
+ { name: "action", type: "address" },
679
+ { name: "sweepDepositAccountERC20", type: "SweepDepositAccountERC20" }
680
+ ],
681
+ SweepDepositAccountERC20: [
682
+ { name: "token", type: "address" },
683
+ { name: "depositor", type: "address" },
684
+ { name: "recipient", type: "address" },
685
+ { name: "threshold", type: "uint256" },
686
+ { name: "fee", type: "Fee" }
687
+ ],
688
+ Fee: [
689
+ { name: "token", type: "address" },
690
+ { name: "maxBaseFeePerGas", type: "uint256" },
691
+ { name: "maxPriorityFeePerGas", type: "uint256" },
692
+ { name: "executionFee", type: "uint256" }
693
+ ]
694
+ }
695
+ };
696
+
697
+ // src/instructions/contracts/schemas/eip-712/actions/sweep-deposit-account.json
698
+ var sweep_deposit_account_default = {
699
+ types: {
700
+ Instruction: [
701
+ { name: "salt", type: "uint256" },
702
+ { name: "maxExecutions", type: "uint256" },
703
+ { name: "action", type: "address" },
704
+ { name: "sweepDepositAccount", type: "SweepDepositAccount" }
705
+ ],
706
+ SweepDepositAccount: [
707
+ { name: "depositor", type: "address" },
708
+ { name: "recipient", type: "address" },
709
+ { name: "threshold", type: "uint256" },
710
+ { name: "fee", type: "Fee" }
711
+ ],
712
+ Fee: [
713
+ { name: "token", type: "address" },
714
+ { name: "maxBaseFeePerGas", type: "uint256" },
715
+ { name: "maxPriorityFeePerGas", type: "uint256" },
716
+ { name: "executionFee", type: "uint256" }
717
+ ]
718
+ }
719
+ };
720
+
721
+ // src/instructions/contracts/schemas/eip-712/actions/sweep-erc20.json
722
+ var sweep_erc20_default = {
723
+ types: {
724
+ Instruction: [
725
+ { name: "salt", type: "uint256" },
726
+ { name: "maxExecutions", type: "uint256" },
727
+ { name: "action", type: "address" },
728
+ { name: "sweepERC20", type: "SweepERC20" }
729
+ ],
730
+ SweepERC20: [
731
+ { name: "token", type: "address" },
732
+ { name: "target", type: "address" },
733
+ { name: "threshold", type: "uint256" },
734
+ { name: "endBalance", type: "uint256" },
735
+ { name: "fee", type: "Fee" }
736
+ ],
737
+ Fee: [
738
+ { name: "token", type: "address" },
739
+ { name: "maxBaseFeePerGas", type: "uint256" },
740
+ { name: "maxPriorityFeePerGas", type: "uint256" },
741
+ { name: "executionFee", type: "uint256" }
742
+ ]
743
+ }
744
+ };
745
+
746
+ // src/instructions/contracts/schemas/eip-712/actions/sweep-skip-cctp-deposit-account.json
747
+ var sweep_skip_cctp_deposit_account_default = {
748
+ types: {
749
+ Instruction: [
750
+ { name: "salt", type: "uint256" },
751
+ { name: "maxExecutions", type: "uint256" },
752
+ { name: "action", type: "address" },
753
+ {
754
+ name: "sweepSkipCCTPDepositAccount",
755
+ type: "SweepSkipCCTPDepositAccount"
756
+ }
757
+ ],
758
+ SweepSkipCCTPDepositAccount: [
759
+ { name: "depositor", type: "address" },
760
+ { name: "destinationDomain", type: "uint32" },
761
+ { name: "destinationMintRecipient", type: "bytes32" },
762
+ { name: "threshold", type: "uint256" },
763
+ { name: "fee", type: "Fee" }
764
+ ],
765
+ Fee: [
766
+ { name: "token", type: "address" },
767
+ { name: "maxBaseFeePerGas", type: "uint256" },
768
+ { name: "maxPriorityFeePerGas", type: "uint256" },
769
+ { name: "executionFee", type: "uint256" }
770
+ ]
771
+ }
772
+ };
773
+
774
+ // src/instructions/contracts/schemas/eip-712/actions/sweep-uniswap-v3.json
775
+ var sweep_uniswap_v3_default = {
776
+ types: {
777
+ Instruction: [
778
+ { name: "salt", type: "uint256" },
779
+ { name: "maxExecutions", type: "uint256" },
780
+ { name: "action", type: "address" },
781
+ { name: "sweepUniswapV3", type: "SweepUniswapV3" }
782
+ ],
783
+ SweepUniswapV3: [
784
+ { name: "recipient", type: "address" },
785
+ { name: "tokenIn", type: "address" },
786
+ { name: "tokenOut", type: "address" },
787
+ { name: "feeTier", type: "uint24" },
788
+ { name: "threshold", type: "uint256" },
789
+ { name: "endBalance", type: "uint256" },
790
+ { name: "floorAmountOut", type: "uint256" },
791
+ { name: "meanPriceLookBack", type: "uint32" },
792
+ { name: "maxPriceDeviationBPS", type: "uint32" },
793
+ { name: "fee", type: "Fee" }
794
+ ],
795
+ Fee: [
796
+ { name: "token", type: "address" },
797
+ { name: "maxBaseFeePerGas", type: "uint256" },
798
+ { name: "maxPriorityFeePerGas", type: "uint256" },
799
+ { name: "executionFee", type: "uint256" }
800
+ ]
801
+ }
802
+ };
803
+
804
+ // src/instructions/contracts/schemas/eip-712/actions/sweep.json
805
+ var sweep_default = {
806
+ types: {
807
+ Instruction: [
808
+ { name: "salt", type: "uint256" },
809
+ { name: "maxExecutions", type: "uint256" },
810
+ { name: "action", type: "address" },
811
+ { name: "sweep", type: "Sweep" }
812
+ ],
813
+ Sweep: [
814
+ { name: "target", type: "address" },
815
+ { name: "threshold", type: "uint256" },
816
+ { name: "endBalance", type: "uint256" },
817
+ { name: "gasLimit", type: "uint256" },
818
+ { name: "fee", type: "Fee" }
819
+ ],
820
+ Fee: [
821
+ { name: "token", type: "address" },
822
+ { name: "maxBaseFeePerGas", type: "uint256" },
823
+ { name: "maxPriorityFeePerGas", type: "uint256" },
824
+ { name: "executionFee", type: "uint256" }
825
+ ]
826
+ }
827
+ };
828
+
829
+ // src/instructions/contracts/schemas/eip-712/actions/transfer-erc20.json
830
+ var transfer_erc20_default = {
831
+ types: {
832
+ Instruction: [
833
+ { name: "salt", type: "uint256" },
834
+ { name: "maxExecutions", type: "uint256" },
835
+ { name: "action", type: "address" },
836
+ { name: "transferERC20", type: "TransferERC20" }
837
+ ],
838
+ TransferERC20: [
839
+ { name: "token", type: "address" },
840
+ { name: "target", type: "address" },
841
+ { name: "value", type: "uint256" },
842
+ { name: "schedule", type: "Schedule" },
843
+ { name: "fee", type: "Fee" }
844
+ ],
845
+ Schedule: [
846
+ { name: "startAt", type: "uint256" },
847
+ { name: "startBy", type: "uint256" },
848
+ { name: "interval", type: "uint256" },
849
+ { name: "timeout", type: "uint256" }
850
+ ],
851
+ Fee: [
852
+ { name: "token", type: "address" },
853
+ { name: "maxBaseFeePerGas", type: "uint256" },
854
+ { name: "maxPriorityFeePerGas", type: "uint256" },
855
+ { name: "executionFee", type: "uint256" }
856
+ ]
857
+ }
858
+ };
859
+
860
+ // src/instructions/contracts/schemas/eip-712/actions/transfer.json
861
+ var transfer_default = {
862
+ types: {
863
+ Instruction: [
864
+ { name: "salt", type: "uint256" },
865
+ { name: "maxExecutions", type: "uint256" },
866
+ { name: "action", type: "address" },
867
+ { name: "transfer", type: "Transfer" }
868
+ ],
869
+ Transfer: [
870
+ { name: "target", type: "address" },
871
+ { name: "value", type: "uint256" },
872
+ { name: "gasLimit", type: "uint256" },
873
+ { name: "schedule", type: "Schedule" },
874
+ { name: "fee", type: "Fee" }
875
+ ],
876
+ Schedule: [
877
+ { name: "startAt", type: "uint256" },
878
+ { name: "startBy", type: "uint256" },
879
+ { name: "interval", type: "uint256" },
880
+ { name: "timeout", type: "uint256" }
881
+ ],
882
+ Fee: [
883
+ { name: "token", type: "address" },
884
+ { name: "maxBaseFeePerGas", type: "uint256" },
885
+ { name: "maxPriorityFeePerGas", type: "uint256" },
886
+ { name: "executionFee", type: "uint256" }
887
+ ]
888
+ }
889
+ };
890
+
891
+ // src/instructions/contracts/schemas/eip-712/actions/uniswap-v3-exact-input.json
892
+ var uniswap_v3_exact_input_default = {
893
+ types: {
894
+ Instruction: [
895
+ { name: "salt", type: "uint256" },
896
+ { name: "maxExecutions", type: "uint256" },
897
+ { name: "action", type: "address" },
898
+ { name: "uniswapV3ExactInput", type: "UniswapV3ExactInput" }
899
+ ],
900
+ UniswapV3ExactInput: [
901
+ { name: "recipient", type: "address" },
902
+ { name: "tokenIn", type: "address" },
903
+ { name: "tokenOut", type: "address" },
904
+ { name: "feeTier", type: "uint24" },
905
+ { name: "amountIn", type: "uint256" },
906
+ { name: "floorAmountOut", type: "uint256" },
907
+ { name: "meanPriceLookBack", type: "uint32" },
908
+ { name: "maxPriceDeviationBPS", type: "uint32" },
909
+ { name: "schedule", type: "Schedule" },
910
+ { name: "fee", type: "Fee" }
911
+ ],
912
+ Schedule: [
913
+ { name: "startAt", type: "uint256" },
914
+ { name: "startBy", type: "uint256" },
915
+ { name: "interval", type: "uint256" },
916
+ { name: "timeout", type: "uint256" }
917
+ ],
918
+ Fee: [
919
+ { name: "token", type: "address" },
920
+ { name: "maxBaseFeePerGas", type: "uint256" },
921
+ { name: "maxPriorityFeePerGas", type: "uint256" },
922
+ { name: "executionFee", type: "uint256" }
923
+ ]
924
+ }
925
+ };
926
+
927
+ // src/instructions/types.ts
928
+ var eip712TypesMap = {
929
+ refuel: refuel_default,
930
+ refuelERC20: refuel_erc20_default,
931
+ transfer: transfer_default,
932
+ transferERC20: transfer_erc20_default,
933
+ uniswapV3ExactInput: uniswap_v3_exact_input_default,
934
+ sweep: sweep_default,
935
+ sweepERC20: sweep_erc20_default,
936
+ sweepCCTP: sweep_cctp_default,
937
+ sweepUniswapV3: sweep_uniswap_v3_default,
938
+ sweepDepositAccount: sweep_deposit_account_default,
939
+ sweepDepositAccountERC20: sweep_deposit_account_erc20_default,
940
+ sweepSkipCCTPDepositAccount: sweep_skip_cctp_deposit_account_default,
941
+ deactivateInstruction: deactivate_instruction_default
942
+ };
943
+
944
+ // src/payments/instruction-registry.ts
945
+ var feeAbiComponent = {
946
+ name: "fee",
947
+ type: "tuple",
948
+ components: [
949
+ { name: "token", type: "address" },
950
+ { name: "maxBaseFeePerGas", type: "uint256" },
951
+ { name: "maxPriorityFeePerGas", type: "uint256" },
952
+ { name: "executionFee", type: "uint256" }
953
+ ]
954
+ };
955
+ var sweepAbi = [
956
+ {
957
+ type: "tuple",
958
+ components: [
959
+ { name: "target", type: "address" },
960
+ { name: "threshold", type: "uint256" },
961
+ { name: "endBalance", type: "uint256" },
962
+ { name: "gasLimit", type: "uint256" },
963
+ feeAbiComponent
964
+ ]
965
+ }
966
+ ];
967
+ var sweepERC20Abi = [
968
+ {
969
+ type: "tuple",
970
+ components: [
971
+ { name: "token", type: "address" },
972
+ { name: "target", type: "address" },
973
+ { name: "threshold", type: "uint256" },
974
+ { name: "endBalance", type: "uint256" },
975
+ feeAbiComponent
976
+ ]
977
+ }
978
+ ];
979
+ var sweepCCTPAbi = [
980
+ {
981
+ type: "tuple",
982
+ components: [
983
+ { name: "token", type: "address" },
984
+ { name: "destinationDomain", type: "uint32" },
985
+ { name: "destinationMintRecipient", type: "bytes32" },
986
+ { name: "threshold", type: "uint256" },
987
+ { name: "endBalance", type: "uint256" },
988
+ feeAbiComponent
989
+ ]
990
+ }
991
+ ];
992
+ var sweepUniswapV3Abi = [
993
+ {
994
+ type: "tuple",
995
+ components: [
996
+ { name: "recipient", type: "address" },
997
+ { name: "tokenIn", type: "address" },
998
+ { name: "tokenOut", type: "address" },
999
+ { name: "feeTier", type: "uint24" },
1000
+ { name: "threshold", type: "uint256" },
1001
+ { name: "endBalance", type: "uint256" },
1002
+ { name: "floorAmountOut", type: "uint256" },
1003
+ { name: "meanPriceLookBack", type: "uint32" },
1004
+ { name: "maxPriceDeviationBPS", type: "uint32" },
1005
+ feeAbiComponent
1006
+ ]
1007
+ }
1008
+ ];
1009
+ var sweepDepositAccountAbi = [
1010
+ {
1011
+ type: "tuple",
1012
+ components: [
1013
+ { name: "depositor", type: "address" },
1014
+ { name: "recipient", type: "address" },
1015
+ { name: "threshold", type: "uint256" },
1016
+ feeAbiComponent
1017
+ ]
1018
+ }
1019
+ ];
1020
+ var sweepDepositAccountERC20Abi = [
1021
+ {
1022
+ type: "tuple",
1023
+ components: [
1024
+ { name: "token", type: "address" },
1025
+ { name: "depositor", type: "address" },
1026
+ { name: "recipient", type: "address" },
1027
+ { name: "threshold", type: "uint256" },
1028
+ feeAbiComponent
1029
+ ]
1030
+ }
1031
+ ];
1032
+ var sweepSkipCCTPDepositAccountAbi = [
1033
+ {
1034
+ type: "tuple",
1035
+ components: [
1036
+ { name: "depositor", type: "address" },
1037
+ { name: "destinationDomain", type: "uint32" },
1038
+ { name: "destinationMintRecipient", type: "bytes32" },
1039
+ { name: "threshold", type: "uint256" },
1040
+ feeAbiComponent
1041
+ ]
1042
+ }
1043
+ ];
1044
+ var actionAbiMap = {
1045
+ sweep: sweepAbi,
1046
+ sweepERC20: sweepERC20Abi,
1047
+ sweepCCTP: sweepCCTPAbi,
1048
+ sweepUniswapV3: sweepUniswapV3Abi,
1049
+ sweepDepositAccount: sweepDepositAccountAbi,
1050
+ sweepDepositAccountERC20: sweepDepositAccountERC20Abi,
1051
+ sweepSkipCCTPDepositAccount: sweepSkipCCTPDepositAccountAbi
1052
+ };
1053
+ var InstructionTypeRegistry = class {
1054
+ constructor() {
1055
+ __publicField(this, "registry", /* @__PURE__ */ new Map());
1056
+ this.initializeDefaultTypes();
1057
+ }
1058
+ register(actionName, definition) {
1059
+ this.registry.set(actionName, definition);
1060
+ }
1061
+ get(actionName) {
1062
+ const definition = this.registry.get(actionName);
1063
+ if (!definition) {
1064
+ throw this.createUnsupportedTypeError(actionName);
1065
+ }
1066
+ return definition;
1067
+ }
1068
+ has(actionName) {
1069
+ return this.registry.has(actionName);
1070
+ }
1071
+ getAvailableTypes() {
1072
+ return Array.from(this.registry.keys());
1073
+ }
1074
+ initializeDefaultTypes() {
1075
+ const actionNames = Object.keys(actionAbiMap);
1076
+ for (const actionName of actionNames) {
1077
+ const abi = actionAbiMap[actionName];
1078
+ const eip712Types = eip712TypesMap[actionName];
1079
+ if (abi && eip712Types) {
1080
+ this.register(actionName, { abi, eip712Types });
1081
+ }
1082
+ }
1083
+ }
1084
+ createUnsupportedTypeError(actionName) {
1085
+ const availableTypes = this.getAvailableTypes().join(", ");
1086
+ return new Error(
1087
+ `Unsupported instruction type: ${actionName}. Available: ${availableTypes}`
1088
+ );
1089
+ }
1090
+ };
1091
+ var instructionRegistry = new InstructionTypeRegistry();
1092
+
1093
+ // src/payments/action-names.ts
1094
+ function addActionNamesToInstructions(buildResponse, actionNames) {
1095
+ const completionInstructionCount = buildResponse.completionInstructions.length;
1096
+ return {
1097
+ ...buildResponse,
1098
+ completionInstructions: buildResponse.completionInstructions.map(
1099
+ (instruction, index) => ({
1100
+ ...instruction,
1101
+ actionName: actionNames[index]
1102
+ })
1103
+ ),
1104
+ instructions: buildResponse.instructions.map((instruction, index) => ({
1105
+ ...instruction,
1106
+ actionName: actionNames[completionInstructionCount + index]
1107
+ }))
1108
+ };
1109
+ }
1110
+ function extractActionNamesMap(completionInstructions, instructions = []) {
1111
+ const allInstructions = [...completionInstructions, ...instructions];
1112
+ return allInstructions.reduce(
1113
+ (actionNamesMap, instruction, index) => {
1114
+ const actionName = getFirstActionArgumentKey(instruction.actionArguments);
1115
+ if (actionName) {
1116
+ actionNamesMap[index] = actionName;
1117
+ }
1118
+ return actionNamesMap;
1119
+ },
1120
+ {}
1121
+ );
1122
+ }
1123
+ function getFirstActionArgumentKey(actionArguments) {
1124
+ const keys = Object.keys(actionArguments);
1125
+ return keys[0];
1126
+ }
1127
+
1128
+ // src/payments/validation.ts
1129
+ var SignatureValidator = class {
1130
+ static assertExactCount(context) {
1131
+ if (context.received !== context.expected) {
1132
+ throw new Error(
1133
+ `Signature count mismatch: expected ${context.expected}, received ${context.received}`
1134
+ );
1135
+ }
1136
+ }
1137
+ static assertMinimumCount(context) {
1138
+ if (context.received < context.expected) {
1139
+ throw new Error(
1140
+ `Insufficient signatures: expected at least ${context.expected}, received ${context.received}`
1141
+ );
1142
+ }
1143
+ }
1144
+ };
1145
+ function assertSignatureCount(signatures, expectedCount) {
1146
+ SignatureValidator.assertExactCount({
1147
+ expected: expectedCount,
1148
+ received: signatures.length
1149
+ });
1150
+ }
1151
+ function assertMinimumSignatures(signatures, minimumCount) {
1152
+ SignatureValidator.assertMinimumCount({
1153
+ expected: minimumCount,
1154
+ received: signatures.length
1155
+ });
1156
+ }
1157
+
1158
+ // src/payments/chain-token-config-builder.ts
1159
+ function createChainTokenConfigs(tokens) {
1160
+ const tokensByChain = groupTokensByChainId(tokens);
1161
+ return convertToChainConfigs(tokensByChain);
1162
+ }
1163
+ function groupTokensByChainId(tokens) {
1164
+ const grouped = /* @__PURE__ */ new Map();
1165
+ for (const token of tokens) {
1166
+ const chainTokens = grouped.get(token.chainId) ?? [];
1167
+ chainTokens.push(token);
1168
+ grouped.set(token.chainId, chainTokens);
1169
+ }
1170
+ return grouped;
1171
+ }
1172
+ function convertToChainConfigs(tokensByChain) {
1173
+ return Array.from(tokensByChain.entries()).map(([chainId, tokens]) => ({
1174
+ chainId,
1175
+ tokens: tokens.map((token) => ({
1176
+ symbol: token.symbol,
1177
+ address: token.address,
1178
+ decimals: token.decimals
1179
+ }))
1180
+ }));
1181
+ }
1182
+
1183
+ // src/payments/payment-request-token-resolver.ts
1184
+ function isNativeToken(token) {
1185
+ if (!token) {
1186
+ return false;
1187
+ }
1188
+ return token.symbol === "ETH" || token.address.toLowerCase() === DEFAULT_ADDRESS.toLowerCase();
1189
+ }
1190
+ function resolvePreferredStablecoin({
1191
+ preferredToken,
1192
+ getStablecoinBySymbol
1193
+ }) {
1194
+ const stablecoin = getValidStablecoin(preferredToken);
1195
+ if (stablecoin) {
1196
+ return stablecoin;
1197
+ }
1198
+ return getDefaultStablecoin(getStablecoinBySymbol);
1199
+ }
1200
+ function getValidStablecoin(token) {
1201
+ if (!token || isNativeToken(token) || !isStablecoin(token.symbol)) {
1202
+ return null;
1203
+ }
1204
+ return token;
1205
+ }
1206
+ function getDefaultStablecoin(getStablecoinBySymbol) {
1207
+ const usdc = getStablecoinBySymbol("USDC");
1208
+ if (usdc) {
1209
+ return usdc;
1210
+ }
1211
+ const usdt = getStablecoinBySymbol("USDT");
1212
+ if (usdt) {
1213
+ return usdt;
1214
+ }
1215
+ return null;
1216
+ }
1217
+ function createTokenIdentifier(chainId, tokenAddress) {
1218
+ return `${chainId}:${tokenAddress}`;
1219
+ }
1220
+
1221
+ // src/payments/payment-metadata-builder.ts
1222
+ var DEFAULT_CURRENCY = "USD";
1223
+ function isValidAmount(value) {
1224
+ return isNumber(value) && Number.isFinite(value);
1225
+ }
1226
+ function buildPaymentMetadata(params) {
1227
+ const {
1228
+ note,
1229
+ tokenSymbol,
1230
+ dueDate,
1231
+ amountInUSD,
1232
+ hasInvoiceMetadata = false,
1233
+ fromAccountAddress
1234
+ } = params;
1235
+ const metadata = {
1236
+ token: tokenSymbol
1237
+ };
1238
+ if (!hasInvoiceMetadata) {
1239
+ if (isValidAmount(amountInUSD)) {
1240
+ metadata.amountDue = amountInUSD.toFixed(2);
1241
+ }
1242
+ metadata.currency = DEFAULT_CURRENCY;
1243
+ }
1244
+ if (dueDate) {
1245
+ metadata.dueDate = dueDate;
1246
+ }
1247
+ if (note) {
1248
+ metadata.note = note;
1249
+ }
1250
+ if (fromAccountAddress) {
1251
+ metadata.fromAccountAddress = fromAccountAddress;
1252
+ }
1253
+ return metadata;
1254
+ }
1255
+ function buildInvoiceMetadata(params) {
1256
+ const { invoiceMetadata, baseMetadata } = params;
1257
+ return {
1258
+ ...baseMetadata,
1259
+ /**
1260
+ * Invoice amounts/dates are authoritative - they override any manually
1261
+ * entered values to prevent sync issues with external systems
1262
+ */
1263
+ amountDue: Number(invoiceMetadata.amount).toFixed(2),
1264
+ currency: invoiceMetadata.currency,
1265
+ dueDate: invoiceMetadata.dueDate,
1266
+ /** Preserve user's manual note if invoice doesn't provide one */
1267
+ note: invoiceMetadata.description ?? baseMetadata.note,
1268
+ /** Track integration source for reconciliation and debugging */
1269
+ source: invoiceMetadata.source,
1270
+ invoiceId: invoiceMetadata.invoiceId,
1271
+ invoiceNumber: invoiceMetadata.invoiceNumber
1272
+ };
1273
+ }
1274
+ function validatePaymentMetadata(metadata) {
1275
+ const errors = [];
1276
+ const token = metadata["token"];
1277
+ if (!token || typeof token !== "string") {
1278
+ errors.push("Token symbol is required");
1279
+ }
1280
+ const amountDue = metadata["amountDue"];
1281
+ if (amountDue !== void 0 && amountDue !== null) {
1282
+ const amount = typeof amountDue === "string" ? parseFloat(amountDue) : Number(amountDue);
1283
+ if (!isValidAmount(amount) || amount < 0) {
1284
+ errors.push("Amount must be a valid positive number");
1285
+ }
1286
+ }
1287
+ const dueDate = metadata["dueDate"];
1288
+ if (dueDate !== void 0 && dueDate !== null) {
1289
+ if (typeof dueDate !== "string") {
1290
+ errors.push("Due date must be a string");
1291
+ } else {
1292
+ const date = new Date(dueDate);
1293
+ if (!isValidDate(date)) {
1294
+ errors.push("Due date must be a valid ISO date string");
1295
+ }
1296
+ }
1297
+ }
1298
+ return {
1299
+ isValid: errors.length === 0,
1300
+ errors
1301
+ };
1302
+ }
1303
+ //# sourceMappingURL=index.js.map