@otim/utils 0.0.4 → 0.0.6

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