tapimo 0.7.1 → 0.8.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 (786) hide show
  1. package/README.md +10 -7
  2. package/dist/ApiKey.d.ts +3 -0
  3. package/dist/ApiKey.d.ts.map +1 -1
  4. package/dist/ApiKey.js +10 -0
  5. package/dist/ApiKey.js.map +1 -1
  6. package/dist/ApiKeys.d.ts +29 -8
  7. package/dist/ApiKeys.d.ts.map +1 -1
  8. package/dist/ApiKeys.js +24 -5
  9. package/dist/ApiKeys.js.map +1 -1
  10. package/dist/App.d.ts +20680 -15487
  11. package/dist/App.d.ts.map +1 -1
  12. package/dist/App.js +250 -129
  13. package/dist/App.js.map +1 -1
  14. package/dist/Assets.d.ts +10 -0
  15. package/dist/Assets.d.ts.map +1 -1
  16. package/dist/Assets.js +17 -4
  17. package/dist/Assets.js.map +1 -1
  18. package/dist/Scope.d.ts +19 -8
  19. package/dist/Scope.d.ts.map +1 -1
  20. package/dist/Scope.js +25 -9
  21. package/dist/Scope.js.map +1 -1
  22. package/dist/Webhooks.d.ts +1 -1
  23. package/dist/admin/App.d.ts +667 -76
  24. package/dist/admin/App.d.ts.map +1 -1
  25. package/dist/admin/App.js +12 -2
  26. package/dist/admin/App.js.map +1 -1
  27. package/dist/admin/apps/api-keys.d.ts +107 -11
  28. package/dist/admin/apps/api-keys.d.ts.map +1 -1
  29. package/dist/admin/apps/api-keys.js +145 -32
  30. package/dist/admin/apps/api-keys.js.map +1 -1
  31. package/dist/admin/apps/earn-vaults.d.ts +1069 -0
  32. package/dist/admin/apps/earn-vaults.d.ts.map +1 -0
  33. package/dist/admin/apps/earn-vaults.js +409 -0
  34. package/dist/admin/apps/earn-vaults.js.map +1 -0
  35. package/dist/admin/apps/organizations.d.ts +2 -0
  36. package/dist/admin/apps/organizations.d.ts.map +1 -1
  37. package/dist/admin/apps/verified-tokens.d.ts +74 -74
  38. package/dist/admin/ui.generated.d.ts +1 -1
  39. package/dist/admin/ui.generated.d.ts.map +1 -1
  40. package/dist/admin/ui.generated.js +99 -43
  41. package/dist/admin/ui.generated.js.map +1 -1
  42. package/dist/analytics/Analytics.d.ts +4 -0
  43. package/dist/analytics/Analytics.d.ts.map +1 -1
  44. package/dist/analytics/Analytics.js +21 -2
  45. package/dist/analytics/Analytics.js.map +1 -1
  46. package/dist/analytics/tables/requestEvents.d.ts +22 -1
  47. package/dist/analytics/tables/requestEvents.d.ts.map +1 -1
  48. package/dist/analytics/tables/requestEvents.js +59 -39
  49. package/dist/analytics/tables/requestEvents.js.map +1 -1
  50. package/dist/apps/Zones.d.ts +8335 -0
  51. package/dist/apps/Zones.d.ts.map +1 -0
  52. package/dist/apps/Zones.js +38 -0
  53. package/dist/apps/Zones.js.map +1 -0
  54. package/dist/apps/data/App.d.ts +5666 -3934
  55. package/dist/apps/data/App.d.ts.map +1 -1
  56. package/dist/apps/data/App.js +90 -22
  57. package/dist/apps/data/App.js.map +1 -1
  58. package/dist/apps/data/FxOracle.d.ts +1 -1
  59. package/dist/apps/data/FxOracle.d.ts.map +1 -1
  60. package/dist/apps/data/index.d.ts +0 -1
  61. package/dist/apps/data/index.d.ts.map +1 -1
  62. package/dist/apps/data/index.js +0 -1
  63. package/dist/apps/data/index.js.map +1 -1
  64. package/dist/apps/data/routes/activities.d.ts +56 -56
  65. package/dist/apps/data/routes/activities.d.ts.map +1 -1
  66. package/dist/apps/data/routes/activities.js +130 -65
  67. package/dist/apps/data/routes/activities.js.map +1 -1
  68. package/dist/apps/data/routes/addresses.d.ts +65 -65
  69. package/dist/apps/data/routes/balances.d.ts +14 -14
  70. package/dist/apps/data/routes/balances.js +5 -5
  71. package/dist/apps/data/routes/balances.js.map +1 -1
  72. package/dist/apps/data/routes/blocks.d.ts +39 -39
  73. package/dist/apps/data/routes/coingecko.d.ts +54 -54
  74. package/dist/apps/data/routes/coingecko.d.ts.map +1 -1
  75. package/dist/apps/data/routes/coingecko.js +62 -35
  76. package/dist/apps/data/routes/coingecko.js.map +1 -1
  77. package/dist/apps/data/routes/earn.d.ts +2574 -0
  78. package/dist/apps/data/routes/earn.d.ts.map +1 -0
  79. package/dist/apps/data/routes/earn.js +1574 -0
  80. package/dist/apps/data/routes/earn.js.map +1 -0
  81. package/dist/apps/data/routes/exchanges.d.ts +1626 -719
  82. package/dist/apps/data/routes/exchanges.d.ts.map +1 -1
  83. package/dist/apps/data/routes/exchanges.js +656 -193
  84. package/dist/apps/data/routes/exchanges.js.map +1 -1
  85. package/dist/apps/data/routes/fee-amm.d.ts +108 -108
  86. package/dist/apps/data/routes/fee-amm.d.ts.map +1 -1
  87. package/dist/apps/data/routes/fee-amm.js +59 -8
  88. package/dist/apps/data/routes/fee-amm.js.map +1 -1
  89. package/dist/apps/data/routes/indexer.d.ts +35 -35
  90. package/dist/apps/data/routes/indexer.d.ts.map +1 -1
  91. package/dist/apps/data/routes/indexer.js +23 -3
  92. package/dist/apps/data/routes/indexer.js.map +1 -1
  93. package/dist/apps/data/routes/receipts.d.ts +33 -33
  94. package/dist/apps/data/routes/receipts.d.ts.map +1 -1
  95. package/dist/apps/data/routes/receipts.js +11 -11
  96. package/dist/apps/data/routes/receipts.js.map +1 -1
  97. package/dist/apps/data/routes/rpc.d.ts +6 -6
  98. package/dist/apps/data/routes/rpc.d.ts.map +1 -1
  99. package/dist/apps/data/routes/rpc.js +214 -22
  100. package/dist/apps/data/routes/rpc.js.map +1 -1
  101. package/dist/apps/data/routes/tokenlist.d.ts +1 -1
  102. package/dist/apps/data/routes/tokenlist.d.ts.map +1 -1
  103. package/dist/apps/data/routes/tokenlist.js +39 -8
  104. package/dist/apps/data/routes/tokenlist.js.map +1 -1
  105. package/dist/apps/data/routes/tokens.d.ts +115 -87
  106. package/dist/apps/data/routes/tokens.d.ts.map +1 -1
  107. package/dist/apps/data/routes/tokens.js +194 -91
  108. package/dist/apps/data/routes/tokens.js.map +1 -1
  109. package/dist/apps/data/routes/transactions.d.ts +54 -54
  110. package/dist/apps/data/routes/transactions.d.ts.map +1 -1
  111. package/dist/apps/data/routes/transactions.js +78 -39
  112. package/dist/apps/data/routes/transactions.js.map +1 -1
  113. package/dist/apps/data/routes/transfers.d.ts +76 -27
  114. package/dist/apps/data/routes/transfers.d.ts.map +1 -1
  115. package/dist/apps/data/routes/transfers.js +165 -67
  116. package/dist/apps/data/routes/transfers.js.map +1 -1
  117. package/dist/apps/data/routes/valuation.d.ts +42 -42
  118. package/dist/apps/data/routes/valuation.js +2 -2
  119. package/dist/apps/data/routes/valuation.js.map +1 -1
  120. package/dist/apps/data/routes/verified-tokens.d.ts +36 -36
  121. package/dist/apps/data/routes/webhooks.d.ts +370 -368
  122. package/dist/apps/data/routes/webhooks.d.ts.map +1 -1
  123. package/dist/apps/data/routes/webhooks.js +161 -59
  124. package/dist/apps/data/routes/webhooks.js.map +1 -1
  125. package/dist/apps/data/routes/zones.d.ts +281 -0
  126. package/dist/apps/data/routes/zones.d.ts.map +1 -0
  127. package/dist/apps/data/routes/zones.js +252 -0
  128. package/dist/apps/data/routes/zones.js.map +1 -0
  129. package/dist/apps/docs/reference.js +6 -5
  130. package/dist/apps/docs/reference.js.map +1 -1
  131. package/dist/apps/funding/Access.d.ts +16 -0
  132. package/dist/apps/funding/Access.d.ts.map +1 -0
  133. package/dist/apps/funding/Access.js +22 -0
  134. package/dist/apps/funding/Access.js.map +1 -0
  135. package/dist/apps/funding/App.d.ts +3183 -0
  136. package/dist/apps/funding/App.d.ts.map +1 -0
  137. package/dist/apps/funding/App.js +46 -0
  138. package/dist/apps/funding/App.js.map +1 -0
  139. package/dist/apps/funding/Inventory.d.ts +5 -0
  140. package/dist/apps/funding/Inventory.d.ts.map +1 -0
  141. package/dist/apps/funding/Inventory.js +25 -0
  142. package/dist/apps/funding/Inventory.js.map +1 -0
  143. package/dist/apps/funding/ProviderAttempts.d.ts +5 -0
  144. package/dist/apps/funding/ProviderAttempts.d.ts.map +1 -0
  145. package/dist/apps/funding/ProviderAttempts.js +24 -0
  146. package/dist/apps/funding/ProviderAttempts.js.map +1 -0
  147. package/dist/apps/funding/index.d.ts +2 -0
  148. package/dist/apps/funding/index.d.ts.map +1 -0
  149. package/dist/apps/funding/index.js +2 -0
  150. package/dist/apps/funding/index.js.map +1 -0
  151. package/dist/apps/funding/routes/chains.d.ts +169 -0
  152. package/dist/apps/funding/routes/chains.d.ts.map +1 -0
  153. package/dist/apps/funding/routes/chains.js +80 -0
  154. package/dist/apps/funding/routes/chains.js.map +1 -0
  155. package/dist/apps/funding/routes/deposit-addresses.d.ts +2388 -0
  156. package/dist/apps/funding/routes/deposit-addresses.d.ts.map +1 -0
  157. package/dist/apps/funding/routes/deposit-addresses.js +860 -0
  158. package/dist/apps/funding/routes/deposit-addresses.js.map +1 -0
  159. package/dist/apps/funding/routes/providers.d.ts +91 -0
  160. package/dist/apps/funding/routes/providers.d.ts.map +1 -0
  161. package/dist/apps/funding/routes/providers.js +56 -0
  162. package/dist/apps/funding/routes/providers.js.map +1 -0
  163. package/dist/apps/{data/routes/funding.d.ts → funding/routes/quotes.d.ts} +26 -396
  164. package/dist/apps/funding/routes/quotes.d.ts.map +1 -0
  165. package/dist/apps/funding/routes/quotes.js +188 -0
  166. package/dist/apps/funding/routes/quotes.js.map +1 -0
  167. package/dist/apps/funding/routes/transfers.d.ts +1999 -0
  168. package/dist/apps/funding/routes/transfers.d.ts.map +1 -0
  169. package/dist/apps/funding/routes/transfers.js +614 -0
  170. package/dist/apps/funding/routes/transfers.js.map +1 -0
  171. package/dist/apps/index.d.ts +3 -1
  172. package/dist/apps/index.d.ts.map +1 -1
  173. package/dist/apps/index.js +3 -1
  174. package/dist/apps/index.js.map +1 -1
  175. package/dist/apps/management/App.d.ts +839 -574
  176. package/dist/apps/management/App.d.ts.map +1 -1
  177. package/dist/apps/management/Billing.d.ts +8 -0
  178. package/dist/apps/management/Billing.d.ts.map +1 -1
  179. package/dist/apps/management/Billing.js +12 -0
  180. package/dist/apps/management/Billing.js.map +1 -1
  181. package/dist/apps/management/Error.d.ts +12 -0
  182. package/dist/apps/management/Error.d.ts.map +1 -0
  183. package/dist/apps/management/Error.js +10 -0
  184. package/dist/apps/management/Error.js.map +1 -0
  185. package/dist/apps/management/routes/api-keys.d.ts +296 -19
  186. package/dist/apps/management/routes/api-keys.d.ts.map +1 -1
  187. package/dist/apps/management/routes/api-keys.js +77 -9
  188. package/dist/apps/management/routes/api-keys.js.map +1 -1
  189. package/dist/apps/management/routes/billing.d.ts +119 -119
  190. package/dist/apps/management/routes/faucet.d.ts +35 -35
  191. package/dist/apps/management/routes/invitations.d.ts +17 -17
  192. package/dist/apps/management/routes/invitations.d.ts.map +1 -1
  193. package/dist/apps/management/routes/invitations.js +4 -10
  194. package/dist/apps/management/routes/invitations.js.map +1 -1
  195. package/dist/apps/management/routes/invite-links.d.ts +38 -38
  196. package/dist/apps/management/routes/me.d.ts +6 -6
  197. package/dist/apps/management/routes/members.d.ts +69 -69
  198. package/dist/apps/management/routes/orgs.d.ts +16 -16
  199. package/dist/apps/management/routes/orgs.d.ts.map +1 -1
  200. package/dist/apps/management/routes/orgs.js +2 -8
  201. package/dist/apps/management/routes/orgs.js.map +1 -1
  202. package/dist/apps/management/routes/projects.d.ts +19 -19
  203. package/dist/apps/management/routes/scopes.d.ts +1 -1
  204. package/dist/apps/management/routes/scopes.js +2 -2
  205. package/dist/apps/management/routes/scopes.js.map +1 -1
  206. package/dist/apps/management/routes/usage.d.ts +72 -72
  207. package/dist/apps/management/routes/verified-token-requests.d.ts +18 -18
  208. package/dist/apps/management/routes/webhooks.d.ts +122 -122
  209. package/dist/apps/management/routes/webhooks.d.ts.map +1 -1
  210. package/dist/apps/management/routes/webhooks.js +15 -3
  211. package/dist/apps/management/routes/webhooks.js.map +1 -1
  212. package/dist/apps/mcp.d.ts +2 -3
  213. package/dist/apps/mcp.d.ts.map +1 -1
  214. package/dist/apps/mcp.js +16 -14
  215. package/dist/apps/mcp.js.map +1 -1
  216. package/dist/apps/metadata.d.ts +4 -0
  217. package/dist/apps/metadata.d.ts.map +1 -1
  218. package/dist/apps/metadata.js +10 -0
  219. package/dist/apps/metadata.js.map +1 -1
  220. package/dist/apps/mpp/App.d.ts +57 -58
  221. package/dist/apps/mpp/App.d.ts.map +1 -1
  222. package/dist/apps/mpp/App.js +192 -27
  223. package/dist/apps/mpp/App.js.map +1 -1
  224. package/dist/apps/mpp/Mpp.d.ts +0 -20
  225. package/dist/apps/mpp/Mpp.d.ts.map +1 -1
  226. package/dist/apps/mpp/Mpp.js +0 -24
  227. package/dist/apps/mpp/Mpp.js.map +1 -1
  228. package/dist/apps/mpp/internal/Adapter.d.ts +40 -0
  229. package/dist/apps/mpp/internal/Adapter.d.ts.map +1 -0
  230. package/dist/apps/mpp/internal/Adapter.js +66 -0
  231. package/dist/apps/mpp/internal/Adapter.js.map +1 -0
  232. package/dist/apps/mpp/internal/Error.d.ts +4 -0
  233. package/dist/apps/mpp/internal/Error.d.ts.map +1 -0
  234. package/dist/apps/mpp/internal/Error.js +41 -0
  235. package/dist/apps/mpp/internal/Error.js.map +1 -0
  236. package/dist/apps/mpp/internal/Idempotency.d.ts +33 -0
  237. package/dist/apps/mpp/internal/Idempotency.d.ts.map +1 -0
  238. package/dist/apps/mpp/internal/Idempotency.js +28 -0
  239. package/dist/apps/mpp/internal/Idempotency.js.map +1 -0
  240. package/dist/apps/mpp/internal/Policy.d.ts +46 -0
  241. package/dist/apps/mpp/internal/Policy.d.ts.map +1 -0
  242. package/dist/apps/mpp/internal/Policy.js +57 -0
  243. package/dist/apps/mpp/internal/Policy.js.map +1 -0
  244. package/dist/apps/mpp/internal/ScreenManager.d.ts +27 -0
  245. package/dist/apps/mpp/internal/ScreenManager.d.ts.map +1 -0
  246. package/dist/apps/mpp/internal/ScreenManager.js +18 -0
  247. package/dist/apps/mpp/internal/ScreenManager.js.map +1 -0
  248. package/dist/apps/mpp/internal/Screening.d.ts +35 -0
  249. package/dist/apps/mpp/internal/Screening.d.ts.map +1 -0
  250. package/dist/apps/mpp/internal/Screening.js +20 -0
  251. package/dist/apps/mpp/internal/Screening.js.map +1 -0
  252. package/dist/apps/mpp/internal/Sponsorship.d.ts +36 -0
  253. package/dist/apps/mpp/internal/Sponsorship.d.ts.map +1 -0
  254. package/dist/apps/mpp/internal/Sponsorship.js +103 -0
  255. package/dist/apps/mpp/internal/Sponsorship.js.map +1 -0
  256. package/dist/apps/mpp/internal/Utils.d.ts +7 -0
  257. package/dist/apps/mpp/internal/Utils.d.ts.map +1 -0
  258. package/dist/apps/mpp/internal/Utils.js +24 -0
  259. package/dist/apps/mpp/internal/Utils.js.map +1 -0
  260. package/dist/apps/relay/App.js +183 -23
  261. package/dist/apps/relay/App.js.map +1 -1
  262. package/dist/apps/relay/Sponsorships.d.ts +4 -0
  263. package/dist/apps/relay/Sponsorships.d.ts.map +1 -1
  264. package/dist/apps/relay/Sponsorships.js +15 -6
  265. package/dist/apps/relay/Sponsorships.js.map +1 -1
  266. package/dist/cloudflare.d.ts +50 -0
  267. package/dist/cloudflare.d.ts.map +1 -1
  268. package/dist/cloudflare.js +178 -0
  269. package/dist/cloudflare.js.map +1 -1
  270. package/dist/db/Db.d.ts +22 -0
  271. package/dist/db/Db.d.ts.map +1 -1
  272. package/dist/db/Db.js +379 -0
  273. package/dist/db/Db.js.map +1 -1
  274. package/dist/db/Schema.d.ts +933 -1
  275. package/dist/db/Schema.d.ts.map +1 -1
  276. package/dist/db/Schema.js +289 -1
  277. package/dist/db/Schema.js.map +1 -1
  278. package/dist/db/tables/earnVaults.d.ts +68 -0
  279. package/dist/db/tables/earnVaults.d.ts.map +1 -0
  280. package/dist/db/tables/earnVaults.js +72 -0
  281. package/dist/db/tables/earnVaults.js.map +1 -0
  282. package/dist/db/tables/fundingCatalog.d.ts +56 -0
  283. package/dist/db/tables/fundingCatalog.d.ts.map +1 -0
  284. package/dist/db/tables/fundingCatalog.js +85 -0
  285. package/dist/db/tables/fundingCatalog.js.map +1 -0
  286. package/dist/db/tables/fundingDepositAddresses.d.ts +172 -0
  287. package/dist/db/tables/fundingDepositAddresses.d.ts.map +1 -0
  288. package/dist/db/tables/fundingDepositAddresses.js +218 -0
  289. package/dist/db/tables/fundingDepositAddresses.js.map +1 -0
  290. package/dist/db/tables/fundingDepositRequestObservations.d.ts +45 -0
  291. package/dist/db/tables/fundingDepositRequestObservations.d.ts.map +1 -0
  292. package/dist/db/tables/fundingDepositRequestObservations.js +46 -0
  293. package/dist/db/tables/fundingDepositRequestObservations.js.map +1 -0
  294. package/dist/db/tables/fundingDeposits.d.ts +171 -0
  295. package/dist/db/tables/fundingDeposits.d.ts.map +1 -0
  296. package/dist/db/tables/fundingDeposits.js +182 -0
  297. package/dist/db/tables/fundingDeposits.js.map +1 -0
  298. package/dist/db/tables/fundingIdempotency.d.ts +91 -0
  299. package/dist/db/tables/fundingIdempotency.d.ts.map +1 -0
  300. package/dist/db/tables/fundingIdempotency.js +103 -0
  301. package/dist/db/tables/fundingIdempotency.js.map +1 -0
  302. package/dist/db/tables/fundingTransferEvents.d.ts +12 -0
  303. package/dist/db/tables/fundingTransferEvents.d.ts.map +1 -0
  304. package/dist/db/tables/fundingTransferEvents.js +18 -0
  305. package/dist/db/tables/fundingTransferEvents.js.map +1 -0
  306. package/dist/db/tables/fundingTransferTransactions.d.ts +15 -0
  307. package/dist/db/tables/fundingTransferTransactions.d.ts.map +1 -0
  308. package/dist/db/tables/fundingTransferTransactions.js +27 -0
  309. package/dist/db/tables/fundingTransferTransactions.js.map +1 -0
  310. package/dist/db/tables/fundingTransfers.d.ts +82 -0
  311. package/dist/db/tables/fundingTransfers.d.ts.map +1 -0
  312. package/dist/db/tables/fundingTransfers.js +89 -0
  313. package/dist/db/tables/fundingTransfers.js.map +1 -0
  314. package/dist/db/tables/organizations.d.ts +8 -0
  315. package/dist/db/tables/organizations.d.ts.map +1 -1
  316. package/dist/db/tables/organizations.js +16 -0
  317. package/dist/db/tables/organizations.js.map +1 -1
  318. package/dist/db/tables/projects.d.ts +8 -0
  319. package/dist/db/tables/projects.d.ts.map +1 -1
  320. package/dist/db/tables/projects.js +16 -0
  321. package/dist/db/tables/projects.js.map +1 -1
  322. package/dist/db/tables/requestUsage.d.ts +13 -0
  323. package/dist/db/tables/requestUsage.d.ts.map +1 -1
  324. package/dist/db/tables/requestUsage.js +16 -0
  325. package/dist/db/tables/requestUsage.js.map +1 -1
  326. package/dist/db/tables/sponsoredTransactions.d.ts +2 -2
  327. package/dist/db/tables/sponsoredTransactions.d.ts.map +1 -1
  328. package/dist/db/tables/sponsoredTransactions.js +1 -1
  329. package/dist/db/tables/sponsoredTransactions.js.map +1 -1
  330. package/dist/db/tables/users.d.ts +8 -0
  331. package/dist/db/tables/users.d.ts.map +1 -1
  332. package/dist/db/tables/users.js +16 -0
  333. package/dist/db/tables/users.js.map +1 -1
  334. package/dist/db/tables/verifiedTokens.d.ts +14 -7
  335. package/dist/db/tables/verifiedTokens.d.ts.map +1 -1
  336. package/dist/db/tables/verifiedTokens.js +9 -7
  337. package/dist/db/tables/verifiedTokens.js.map +1 -1
  338. package/dist/db/tables/webhookSubscriptions.d.ts +31 -1
  339. package/dist/db/tables/webhookSubscriptions.d.ts.map +1 -1
  340. package/dist/db/tables/webhookSubscriptions.js +24 -3
  341. package/dist/db/tables/webhookSubscriptions.js.map +1 -1
  342. package/dist/handlers/relay.js +108 -108
  343. package/dist/handlers/relay.js.map +1 -1
  344. package/dist/internal/Auth.d.ts +37 -11
  345. package/dist/internal/Auth.d.ts.map +1 -1
  346. package/dist/internal/Auth.js +75 -16
  347. package/dist/internal/Auth.js.map +1 -1
  348. package/dist/internal/Cache.d.ts.map +1 -1
  349. package/dist/internal/Cache.js +17 -11
  350. package/dist/internal/Cache.js.map +1 -1
  351. package/dist/internal/Cursor.js +1 -1
  352. package/dist/internal/Cursor.js.map +1 -1
  353. package/dist/internal/EarnRates.d.ts +89 -0
  354. package/dist/internal/EarnRates.d.ts.map +1 -0
  355. package/dist/internal/EarnRates.js +266 -0
  356. package/dist/internal/EarnRates.js.map +1 -0
  357. package/dist/internal/EarnVaults.d.ts +171 -0
  358. package/dist/internal/EarnVaults.d.ts.map +1 -0
  359. package/dist/internal/EarnVaults.js +547 -0
  360. package/dist/internal/EarnVaults.js.map +1 -0
  361. package/dist/internal/EdgeCache.d.ts +10 -3
  362. package/dist/internal/EdgeCache.d.ts.map +1 -1
  363. package/dist/internal/EdgeCache.js +43 -11
  364. package/dist/internal/EdgeCache.js.map +1 -1
  365. package/dist/internal/Id.d.ts +11 -0
  366. package/dist/internal/Id.d.ts.map +1 -1
  367. package/dist/internal/Id.js +13 -0
  368. package/dist/internal/Id.js.map +1 -1
  369. package/dist/internal/Idempotency.d.ts +83 -0
  370. package/dist/internal/Idempotency.d.ts.map +1 -0
  371. package/dist/internal/Idempotency.js +113 -0
  372. package/dist/internal/Idempotency.js.map +1 -0
  373. package/dist/internal/IpAllowlist.d.ts +15 -0
  374. package/dist/internal/IpAllowlist.d.ts.map +1 -0
  375. package/dist/internal/IpAllowlist.js +27 -0
  376. package/dist/internal/IpAllowlist.js.map +1 -0
  377. package/dist/internal/Log.d.ts +64 -9
  378. package/dist/internal/Log.d.ts.map +1 -1
  379. package/dist/internal/Log.js +29 -7
  380. package/dist/internal/Log.js.map +1 -1
  381. package/dist/internal/MetricSink.d.ts.map +1 -1
  382. package/dist/internal/MetricSink.js +47 -1
  383. package/dist/internal/MetricSink.js.map +1 -1
  384. package/dist/internal/OpenApi.d.ts +2 -2
  385. package/dist/internal/OpenApi.d.ts.map +1 -1
  386. package/dist/internal/OpenApi.js +4 -1
  387. package/dist/internal/OpenApi.js.map +1 -1
  388. package/dist/internal/Provider.d.ts +14 -0
  389. package/dist/internal/Provider.d.ts.map +1 -0
  390. package/dist/internal/Provider.js +5 -0
  391. package/dist/internal/Provider.js.map +1 -0
  392. package/dist/internal/Schema.d.ts +6 -1
  393. package/dist/internal/Schema.d.ts.map +1 -1
  394. package/dist/internal/Schema.js +20 -11
  395. package/dist/internal/Schema.js.map +1 -1
  396. package/dist/internal/Store.d.ts +6 -0
  397. package/dist/internal/Store.d.ts.map +1 -1
  398. package/dist/internal/Store.js +35 -0
  399. package/dist/internal/Store.js.map +1 -1
  400. package/dist/internal/Tidx.d.ts +49 -24
  401. package/dist/internal/Tidx.d.ts.map +1 -1
  402. package/dist/internal/Tidx.js +90 -12
  403. package/dist/internal/Tidx.js.map +1 -1
  404. package/dist/internal/Viem.d.ts +90 -65
  405. package/dist/internal/Viem.d.ts.map +1 -1
  406. package/dist/internal/Viem.js +90 -12
  407. package/dist/internal/Viem.js.map +1 -1
  408. package/dist/internal/WebhookDestination.d.ts.map +1 -1
  409. package/dist/internal/WebhookDestination.js +34 -28
  410. package/dist/internal/WebhookDestination.js.map +1 -1
  411. package/dist/internal/Webhooks.d.ts +9 -0
  412. package/dist/internal/Webhooks.d.ts.map +1 -1
  413. package/dist/internal/Webhooks.js +15 -10
  414. package/dist/internal/Webhooks.js.map +1 -1
  415. package/dist/internal/exchange/Provider.d.ts +219 -0
  416. package/dist/internal/exchange/Provider.d.ts.map +1 -0
  417. package/dist/internal/exchange/Provider.js +117 -0
  418. package/dist/internal/exchange/Provider.js.map +1 -0
  419. package/dist/internal/exchange/index.d.ts +2 -0
  420. package/dist/internal/exchange/index.d.ts.map +1 -0
  421. package/dist/internal/exchange/index.js +2 -0
  422. package/dist/internal/exchange/index.js.map +1 -0
  423. package/dist/internal/exchange/providers/uniswap.d.ts +57 -0
  424. package/dist/internal/exchange/providers/uniswap.d.ts.map +1 -0
  425. package/dist/internal/exchange/providers/uniswap.js +553 -0
  426. package/dist/internal/exchange/providers/uniswap.js.map +1 -0
  427. package/dist/internal/funding/Action.d.ts +55 -0
  428. package/dist/internal/funding/Action.d.ts.map +1 -0
  429. package/dist/internal/funding/Action.js +74 -0
  430. package/dist/internal/funding/Action.js.map +1 -0
  431. package/dist/internal/funding/Catalog.d.ts +107 -0
  432. package/dist/internal/funding/Catalog.d.ts.map +1 -0
  433. package/dist/internal/funding/Catalog.js +270 -0
  434. package/dist/internal/funding/Catalog.js.map +1 -0
  435. package/dist/internal/funding/Chain.d.ts +76 -0
  436. package/dist/internal/funding/Chain.d.ts.map +1 -0
  437. package/dist/internal/funding/Chain.js +38 -0
  438. package/dist/internal/funding/Chain.js.map +1 -0
  439. package/dist/internal/funding/Deposit.d.ts +408 -0
  440. package/dist/internal/funding/Deposit.d.ts.map +1 -0
  441. package/dist/internal/funding/Deposit.js +318 -0
  442. package/dist/internal/funding/Deposit.js.map +1 -0
  443. package/dist/internal/funding/DepositAddress.d.ts +345 -0
  444. package/dist/internal/funding/DepositAddress.d.ts.map +1 -0
  445. package/dist/internal/funding/DepositAddress.js +189 -0
  446. package/dist/internal/funding/DepositAddress.js.map +1 -0
  447. package/dist/internal/funding/Evidence.d.ts +48 -0
  448. package/dist/internal/funding/Evidence.d.ts.map +1 -0
  449. package/dist/internal/funding/Evidence.js +315 -0
  450. package/dist/internal/funding/Evidence.js.map +1 -0
  451. package/dist/internal/funding/Provider.d.ts +1288 -0
  452. package/dist/internal/funding/Provider.d.ts.map +1 -0
  453. package/dist/internal/funding/Provider.js +1086 -0
  454. package/dist/internal/funding/Provider.js.map +1 -0
  455. package/dist/internal/funding/Reconciliation.d.ts +127 -0
  456. package/dist/internal/funding/Reconciliation.d.ts.map +1 -0
  457. package/dist/internal/funding/Reconciliation.js +885 -0
  458. package/dist/internal/funding/Reconciliation.js.map +1 -0
  459. package/dist/internal/funding/Route.d.ts +21 -0
  460. package/dist/internal/funding/Route.d.ts.map +1 -0
  461. package/dist/internal/funding/Route.js +5 -0
  462. package/dist/internal/funding/Route.js.map +1 -0
  463. package/dist/internal/funding/SourceObservation.d.ts +108 -0
  464. package/dist/internal/funding/SourceObservation.d.ts.map +1 -0
  465. package/dist/internal/funding/SourceObservation.js +143 -0
  466. package/dist/internal/funding/SourceObservation.js.map +1 -0
  467. package/dist/internal/funding/Subsidy.d.ts +113 -0
  468. package/dist/internal/funding/Subsidy.d.ts.map +1 -0
  469. package/dist/internal/funding/Subsidy.js +138 -0
  470. package/dist/internal/funding/Subsidy.js.map +1 -0
  471. package/dist/internal/funding/Token.d.ts +41 -0
  472. package/dist/internal/funding/Token.d.ts.map +1 -0
  473. package/dist/internal/funding/Token.js +22 -0
  474. package/dist/internal/funding/Token.js.map +1 -0
  475. package/dist/internal/funding/Transfer.d.ts +643 -0
  476. package/dist/internal/funding/Transfer.d.ts.map +1 -0
  477. package/dist/internal/funding/Transfer.js +332 -0
  478. package/dist/internal/funding/Transfer.js.map +1 -0
  479. package/dist/internal/funding/index.d.ts +14 -0
  480. package/dist/internal/funding/index.d.ts.map +1 -0
  481. package/dist/internal/funding/index.js +14 -0
  482. package/dist/internal/funding/index.js.map +1 -0
  483. package/dist/internal/funding/providers/across.d.ts +21 -0
  484. package/dist/internal/funding/providers/across.d.ts.map +1 -0
  485. package/dist/internal/funding/providers/across.js +117 -0
  486. package/dist/internal/funding/providers/across.js.map +1 -0
  487. package/dist/internal/funding/providers/relay.d.ts +88 -0
  488. package/dist/internal/funding/providers/relay.d.ts.map +1 -0
  489. package/dist/internal/funding/providers/relay.js +871 -0
  490. package/dist/internal/funding/providers/relay.js.map +1 -0
  491. package/dist/internal/funding/providers/rhino.d.ts +15 -0
  492. package/dist/internal/funding/providers/rhino.d.ts.map +1 -0
  493. package/dist/internal/funding/providers/rhino.js +116 -0
  494. package/dist/internal/funding/providers/rhino.js.map +1 -0
  495. package/dist/internal/funding/providers/squid.d.ts +19 -0
  496. package/dist/internal/funding/providers/squid.d.ts.map +1 -0
  497. package/dist/internal/funding/providers/squid.js +120 -0
  498. package/dist/internal/funding/providers/squid.js.map +1 -0
  499. package/dist/internal/funding/providers/symbiosis.d.ts +20 -0
  500. package/dist/internal/funding/providers/symbiosis.d.ts.map +1 -0
  501. package/dist/internal/funding/providers/symbiosis.js +176 -0
  502. package/dist/internal/funding/providers/symbiosis.js.map +1 -0
  503. package/dist/internal/index.d.ts +5 -1
  504. package/dist/internal/index.d.ts.map +1 -1
  505. package/dist/internal/index.js +5 -1
  506. package/dist/internal/index.js.map +1 -1
  507. package/dist/internal/webhookDestinations/url.js +61 -57
  508. package/dist/internal/webhookDestinations/url.js.map +1 -1
  509. package/dist/providers/index.d.ts +43 -0
  510. package/dist/providers/index.d.ts.map +1 -0
  511. package/dist/providers/index.js +19 -0
  512. package/dist/providers/index.js.map +1 -0
  513. package/package.json +10 -5
  514. package/src/ApiKey.test.ts +35 -0
  515. package/src/ApiKey.ts +27 -0
  516. package/src/ApiKeys.test.ts +40 -7
  517. package/src/ApiKeys.ts +46 -10
  518. package/src/App.test.ts +108 -15
  519. package/src/App.ts +296 -138
  520. package/src/Assets.ts +29 -4
  521. package/src/Client.test-d.ts +809 -37
  522. package/src/Scope.test.ts +19 -0
  523. package/src/Scope.ts +28 -11
  524. package/src/Webhooks.test.ts +25 -0
  525. package/src/Webhooks.ts +1 -1
  526. package/src/admin/App.test.ts +9 -2
  527. package/src/admin/App.ts +32 -9
  528. package/src/admin/apps/api-keys.test.ts +190 -22
  529. package/src/admin/apps/api-keys.ts +170 -28
  530. package/src/admin/apps/earn-vaults.test.ts +338 -0
  531. package/src/admin/apps/earn-vaults.ts +572 -0
  532. package/src/admin/apps/scopes.test.ts +16 -1
  533. package/src/admin/ui/plugin.ts +2 -2
  534. package/src/admin/ui/src/components/EarnVaultForm.tsx +137 -0
  535. package/src/admin/ui/src/components/MobileProfile.tsx +2 -2
  536. package/src/admin/ui/src/components/Page.tsx +1 -1
  537. package/src/admin/ui/src/components/ThemeToggle.tsx +1 -1
  538. package/src/admin/ui/src/lib/api-keys.ts +37 -7
  539. package/src/admin/ui/src/lib/client.ts +1 -1
  540. package/src/admin/ui/src/lib/config.ts +1 -1
  541. package/src/admin/ui/src/lib/early-access.ts +8 -9
  542. package/src/admin/ui/src/lib/earn-vaults.ts +207 -0
  543. package/src/admin/ui/src/lib/format.ts +13 -0
  544. package/src/admin/ui/src/lib/organizations.test.ts +14 -4
  545. package/src/admin/ui/src/lib/organizations.ts +7 -1
  546. package/src/admin/ui/src/lib/response.ts +22 -0
  547. package/src/admin/ui/src/lib/scopes.test.ts +19 -11
  548. package/src/admin/ui/src/lib/scopes.ts +28 -7
  549. package/src/admin/ui/src/lib/verified-tokens.ts +10 -9
  550. package/src/admin/ui/src/routeTree.gen.ts +70 -7
  551. package/src/admin/ui/src/router.tsx +2 -2
  552. package/src/admin/ui/src/routes/__root.tsx +9 -8
  553. package/src/admin/ui/src/routes/api-keys.tsx +475 -64
  554. package/src/admin/ui/src/routes/early-access.tsx +5 -12
  555. package/src/admin/ui/src/routes/earn.vaults.tsx +348 -0
  556. package/src/admin/ui/src/routes/earn.vaults_.$vaultId.edit.tsx +154 -0
  557. package/src/admin/ui/src/routes/earn.vaults_.new.tsx +190 -0
  558. package/src/admin/ui/src/routes/organizations.tsx +4 -7
  559. package/src/admin/ui/src/routes/organizations_.$orgId.tsx +56 -54
  560. package/src/admin/ui/src/routes/verified-tokens.tsx +4 -4
  561. package/src/admin/ui/vite.config.ts +4 -1
  562. package/src/admin/ui.generated.ts +113 -43
  563. package/src/analytics/Analytics.test.ts +69 -10
  564. package/src/analytics/Analytics.ts +24 -1
  565. package/src/analytics/tables/requestEvents.ts +79 -37
  566. package/src/apps/Zones.test.ts +33 -0
  567. package/src/apps/Zones.ts +40 -0
  568. package/src/apps/composition.test.ts +184 -3
  569. package/src/apps/data/App.test.ts +28 -23
  570. package/src/apps/data/App.ts +95 -36
  571. package/src/apps/data/FxOracle.ts +1 -1
  572. package/src/apps/data/index.ts +0 -1
  573. package/src/apps/data/routes/activities.test.ts +82 -6
  574. package/src/apps/data/routes/activities.ts +131 -71
  575. package/src/apps/data/routes/balances.test.ts +50 -37
  576. package/src/apps/data/routes/balances.ts +5 -5
  577. package/src/apps/data/routes/blocks.test.ts +2 -0
  578. package/src/apps/data/routes/coingecko.test.ts +22 -0
  579. package/src/apps/data/routes/coingecko.ts +84 -48
  580. package/src/apps/data/routes/earn.test.ts +1391 -0
  581. package/src/apps/data/routes/earn.ts +2188 -0
  582. package/src/apps/data/routes/exchanges.test.ts +82 -33
  583. package/src/apps/data/routes/exchanges.ts +842 -227
  584. package/src/apps/data/routes/fee-amm.test.ts +4 -6
  585. package/src/apps/data/routes/fee-amm.ts +69 -12
  586. package/src/apps/data/routes/indexer.test.ts +43 -34
  587. package/src/apps/data/routes/indexer.ts +21 -3
  588. package/src/apps/data/routes/receipts.test.ts +5 -3
  589. package/src/apps/data/routes/receipts.ts +13 -11
  590. package/src/apps/data/routes/rpc.test.ts +446 -28
  591. package/src/apps/data/routes/rpc.ts +245 -25
  592. package/src/apps/data/routes/tokenlist.ts +72 -19
  593. package/src/apps/data/routes/tokens.test.ts +6 -8
  594. package/src/apps/data/routes/tokens.ts +258 -86
  595. package/src/apps/data/routes/transactions.test.ts +2 -0
  596. package/src/apps/data/routes/transactions.ts +77 -42
  597. package/src/apps/data/routes/transfers.test.ts +166 -4
  598. package/src/apps/data/routes/transfers.ts +216 -78
  599. package/src/apps/data/routes/valuation.test.ts +62 -9
  600. package/src/apps/data/routes/valuation.ts +2 -2
  601. package/src/apps/data/routes/webhooks.test.ts +386 -43
  602. package/src/apps/data/routes/webhooks.ts +172 -71
  603. package/src/apps/data/routes/zones.test.ts +473 -0
  604. package/src/apps/data/routes/zones.ts +338 -0
  605. package/src/apps/docs/reference.ts +8 -6
  606. package/src/apps/funding/Access.ts +26 -0
  607. package/src/apps/funding/App.test.ts +78 -0
  608. package/src/apps/funding/App.ts +63 -0
  609. package/src/apps/funding/Inventory.ts +30 -0
  610. package/src/apps/funding/ProviderAttempts.ts +26 -0
  611. package/src/apps/funding/index.ts +1 -0
  612. package/src/apps/funding/routes/chains.test.ts +78 -0
  613. package/src/apps/funding/routes/chains.ts +101 -0
  614. package/src/apps/funding/routes/deposit-addresses.test.ts +1628 -0
  615. package/src/apps/funding/routes/deposit-addresses.ts +1015 -0
  616. package/src/apps/funding/routes/providers.test.ts +165 -0
  617. package/src/apps/funding/routes/providers.ts +73 -0
  618. package/src/apps/funding/routes/quotes.test.ts +511 -0
  619. package/src/apps/funding/routes/quotes.ts +205 -0
  620. package/src/apps/funding/routes/transfers.test.ts +1255 -0
  621. package/src/apps/funding/routes/transfers.ts +704 -0
  622. package/src/apps/index.ts +3 -1
  623. package/src/apps/management/Billing.test.ts +29 -0
  624. package/src/apps/management/Billing.ts +23 -0
  625. package/src/apps/management/Error.ts +12 -0
  626. package/src/apps/management/routes/api-keys.test.ts +103 -3
  627. package/src/apps/management/routes/api-keys.ts +98 -10
  628. package/src/apps/management/routes/invitations.ts +4 -11
  629. package/src/apps/management/routes/orgs.ts +2 -9
  630. package/src/apps/management/routes/scopes.test.ts +7 -2
  631. package/src/apps/management/routes/scopes.ts +2 -2
  632. package/src/apps/management/routes/webhooks.test.ts +6 -1
  633. package/src/apps/management/routes/webhooks.ts +15 -3
  634. package/src/apps/mcp.test.ts +17 -2
  635. package/src/apps/mcp.ts +18 -13
  636. package/src/apps/metadata.ts +12 -0
  637. package/src/apps/mpp/App.ts +276 -29
  638. package/src/apps/mpp/Mpp.test.ts +631 -26
  639. package/src/apps/mpp/Mpp.ts +0 -42
  640. package/src/apps/mpp/internal/Adapter.ts +108 -3
  641. package/src/apps/mpp/internal/Error.test.ts +33 -0
  642. package/src/apps/mpp/internal/Error.ts +44 -6
  643. package/src/apps/mpp/internal/Idempotency.test.ts +213 -0
  644. package/src/apps/mpp/internal/Idempotency.ts +59 -5
  645. package/src/apps/mpp/internal/Policy.test.ts +128 -0
  646. package/src/apps/mpp/internal/Policy.ts +98 -0
  647. package/src/apps/mpp/internal/ScreenManager.test.ts +68 -0
  648. package/src/apps/mpp/internal/ScreenManager.ts +41 -0
  649. package/src/apps/mpp/internal/Screening.ts +40 -3
  650. package/src/apps/mpp/internal/Sponsorship.ts +144 -0
  651. package/src/apps/mpp/internal/Utils.ts +30 -0
  652. package/src/apps/relay/App.test.ts +493 -62
  653. package/src/apps/relay/App.ts +233 -23
  654. package/src/apps/relay/Sponsorships.test.ts +49 -0
  655. package/src/apps/relay/Sponsorships.ts +18 -6
  656. package/src/cloudflare.ts +279 -0
  657. package/src/db/Db.ts +501 -0
  658. package/src/db/Schema.ts +349 -2
  659. package/src/db/tables/earnVaults.test.ts +185 -0
  660. package/src/db/tables/earnVaults.ts +151 -0
  661. package/src/db/tables/fundingCatalog.test.ts +108 -0
  662. package/src/db/tables/fundingCatalog.ts +157 -0
  663. package/src/db/tables/fundingDepositAddresses.test.ts +580 -0
  664. package/src/db/tables/fundingDepositAddresses.ts +404 -0
  665. package/src/db/tables/fundingDepositRequestObservations.test.ts +106 -0
  666. package/src/db/tables/fundingDepositRequestObservations.ts +99 -0
  667. package/src/db/tables/fundingDeposits.test.ts +399 -0
  668. package/src/db/tables/fundingDeposits.ts +373 -0
  669. package/src/db/tables/fundingIdempotency.test.ts +182 -0
  670. package/src/db/tables/fundingIdempotency.ts +180 -0
  671. package/src/db/tables/fundingTransferEvents.ts +28 -0
  672. package/src/db/tables/fundingTransferTransactions.test.ts +69 -0
  673. package/src/db/tables/fundingTransferTransactions.ts +37 -0
  674. package/src/db/tables/fundingTransfers.test.ts +89 -0
  675. package/src/db/tables/fundingTransfers.ts +153 -0
  676. package/src/db/tables/organizations.ts +16 -0
  677. package/src/db/tables/projects.ts +16 -0
  678. package/src/db/tables/requestUsage.ts +23 -0
  679. package/src/db/tables/sponsoredTransactions.test.ts +11 -0
  680. package/src/db/tables/sponsoredTransactions.ts +3 -3
  681. package/src/db/tables/users.ts +16 -0
  682. package/src/db/tables/verifiedTokens.ts +19 -14
  683. package/src/db/tables/webhookSubscriptions.ts +58 -3
  684. package/src/handlers/relay.test.ts +2 -0
  685. package/src/handlers/relay.ts +95 -99
  686. package/src/internal/Auth.test.ts +225 -5
  687. package/src/internal/Auth.ts +109 -20
  688. package/src/internal/Cache.test.ts +37 -3
  689. package/src/internal/Cache.ts +14 -10
  690. package/src/internal/Cursor.test.ts +2 -2
  691. package/src/internal/Cursor.ts +1 -1
  692. package/src/internal/EarnRates.test.ts +125 -0
  693. package/src/internal/EarnRates.ts +409 -0
  694. package/src/internal/EarnVaults.test.ts +195 -0
  695. package/src/internal/EarnVaults.ts +876 -0
  696. package/src/internal/EdgeCache.test.ts +26 -7
  697. package/src/internal/EdgeCache.ts +48 -9
  698. package/src/internal/Id.ts +14 -0
  699. package/src/internal/Idempotency.test.ts +109 -0
  700. package/src/internal/Idempotency.ts +237 -0
  701. package/src/internal/IpAllowlist.test.ts +52 -0
  702. package/src/internal/IpAllowlist.ts +39 -0
  703. package/src/internal/Log.test-d.ts +41 -8
  704. package/src/internal/Log.test.ts +196 -9
  705. package/src/internal/Log.ts +124 -17
  706. package/src/internal/MetricSink.test.ts +244 -4
  707. package/src/internal/MetricSink.ts +51 -1
  708. package/src/internal/OpenApi.ts +4 -1
  709. package/src/internal/Provider.test.ts +17 -0
  710. package/src/internal/Provider.ts +17 -0
  711. package/src/internal/Schema.ts +27 -17
  712. package/src/internal/Store.test.ts +25 -0
  713. package/src/internal/Store.ts +46 -0
  714. package/src/internal/Tidx.local.test.ts +78 -3
  715. package/src/internal/Tidx.test.ts +240 -18
  716. package/src/internal/Tidx.ts +129 -33
  717. package/src/internal/VerifiedTokens.test.ts +15 -0
  718. package/src/internal/Viem.test.ts +198 -17
  719. package/src/internal/Viem.ts +127 -28
  720. package/src/internal/WebhookDestination.ts +25 -23
  721. package/src/internal/Webhooks.test.ts +59 -0
  722. package/src/internal/Webhooks.ts +34 -10
  723. package/src/internal/exchange/Provider.test.ts +216 -0
  724. package/src/internal/exchange/Provider.ts +326 -0
  725. package/src/internal/exchange/index.test.ts +6 -0
  726. package/src/internal/exchange/index.ts +1 -0
  727. package/src/internal/exchange/providers/uniswap.test.ts +122 -0
  728. package/src/internal/exchange/providers/uniswap.ts +682 -0
  729. package/src/internal/funding/Action.test.ts +138 -0
  730. package/src/internal/funding/Action.ts +117 -0
  731. package/src/internal/funding/Catalog.test.ts +311 -0
  732. package/src/internal/funding/Catalog.ts +347 -0
  733. package/src/internal/funding/Chain.test.ts +79 -0
  734. package/src/internal/funding/Chain.ts +120 -0
  735. package/src/internal/funding/Deposit.test.ts +26 -0
  736. package/src/internal/funding/Deposit.ts +522 -0
  737. package/src/internal/funding/DepositAddress.test.ts +18 -0
  738. package/src/internal/funding/DepositAddress.ts +312 -0
  739. package/src/internal/funding/Evidence.test.ts +297 -0
  740. package/src/internal/funding/Evidence.ts +425 -0
  741. package/src/internal/funding/Provider.test.ts +1328 -0
  742. package/src/internal/funding/Provider.ts +1911 -0
  743. package/src/internal/funding/Reconciliation.local.test.ts +511 -0
  744. package/src/internal/funding/Reconciliation.test.ts +3037 -0
  745. package/src/internal/funding/Reconciliation.ts +1202 -0
  746. package/src/internal/funding/Route.test.ts +66 -0
  747. package/src/internal/funding/Route.ts +29 -0
  748. package/src/internal/funding/SourceObservation.test.ts +301 -0
  749. package/src/internal/funding/SourceObservation.ts +267 -0
  750. package/src/internal/funding/Subsidy.local.test.ts +152 -0
  751. package/src/internal/funding/Subsidy.test.ts +75 -0
  752. package/src/internal/funding/Subsidy.ts +260 -0
  753. package/src/internal/funding/Token.test.ts +47 -0
  754. package/src/internal/funding/Token.ts +59 -0
  755. package/src/internal/funding/Transfer.test.ts +369 -0
  756. package/src/internal/funding/Transfer.ts +522 -0
  757. package/src/internal/funding/index.test.ts +21 -0
  758. package/src/internal/funding/index.ts +13 -0
  759. package/src/internal/funding/providers/across.ts +149 -0
  760. package/src/{apps/data/FundingQuoteProviders.test.ts → internal/funding/providers/index.test.ts} +178 -157
  761. package/src/internal/funding/providers/relay.test.ts +564 -0
  762. package/src/internal/funding/providers/relay.ts +1060 -0
  763. package/src/internal/funding/providers/rhino.ts +139 -0
  764. package/src/internal/funding/providers/squid.ts +151 -0
  765. package/src/internal/funding/providers/symbiosis.ts +221 -0
  766. package/src/internal/index.test.ts +5 -1
  767. package/src/internal/index.ts +5 -1
  768. package/src/internal/webhookDestinations/url.ts +49 -45
  769. package/src/providers/index.test.ts +14 -0
  770. package/src/providers/index.ts +54 -0
  771. package/dist/apps/data/FundingQuoteProviders.d.ts +0 -174
  772. package/dist/apps/data/FundingQuoteProviders.d.ts.map +0 -1
  773. package/dist/apps/data/FundingQuoteProviders.js +0 -775
  774. package/dist/apps/data/FundingQuoteProviders.js.map +0 -1
  775. package/dist/apps/data/routes/funding.d.ts.map +0 -1
  776. package/dist/apps/data/routes/funding.js +0 -410
  777. package/dist/apps/data/routes/funding.js.map +0 -1
  778. package/dist/internal/FundingQuotes.d.ts +0 -864
  779. package/dist/internal/FundingQuotes.d.ts.map +0 -1
  780. package/dist/internal/FundingQuotes.js +0 -672
  781. package/dist/internal/FundingQuotes.js.map +0 -1
  782. package/src/apps/data/FundingQuoteProviders.ts +0 -1043
  783. package/src/apps/data/routes/funding.test.ts +0 -503
  784. package/src/apps/data/routes/funding.ts +0 -604
  785. package/src/internal/FundingQuotes.test.ts +0 -456
  786. package/src/internal/FundingQuotes.ts +0 -944
@@ -0,0 +1,885 @@
1
+ import { Hex } from 'ox';
2
+ import * as Db from '../../db/Db.js';
3
+ import * as FundingDepositAddresses from '../../db/tables/fundingDepositAddresses.js';
4
+ import * as FundingDepositRequestObservations from '../../db/tables/fundingDepositRequestObservations.js';
5
+ import * as FundingDeposits from '../../db/tables/fundingDeposits.js';
6
+ import * as Value from '../Value.js';
7
+ import * as Deposit from './Deposit.js';
8
+ import * as Provider from './Provider.js';
9
+ import * as Subsidy from './Subsidy.js';
10
+ const defaultBatchSize = 25;
11
+ const defaultLeaseMs = 2 * 60_000;
12
+ const defaultPollIntervalMs = 60_000;
13
+ const followUpDelaySeconds = { delivery: 1, provider: 5, settlement: 2 };
14
+ const maximumPages = 100;
15
+ const maximumFollowUpAttempts = 6;
16
+ /** Creates a reusable-address reconciliation tracker. */
17
+ export function createTracker(options) {
18
+ const now = options.now ?? (() => new Date());
19
+ const batchSize = options.batchSize ?? defaultBatchSize;
20
+ const leaseMs = options.leaseMs ?? defaultLeaseMs;
21
+ const pollIntervalMs = options.pollIntervalMs ?? defaultPollIntervalMs;
22
+ const record = (outcome, providerId, trigger) => {
23
+ options.metrics?.count('funding_deposit_reconciliation_count', 1, {
24
+ outcome,
25
+ provider: providerId,
26
+ trigger,
27
+ });
28
+ };
29
+ return {
30
+ async reconcile(message) {
31
+ const database = Db.get(options.db);
32
+ const startedAt = now();
33
+ // Legacy poll messages carry a lease version; legacy webhook messages do not.
34
+ const trigger = (() => {
35
+ if (message.trigger)
36
+ return message.trigger;
37
+ if (message.pollLeaseVersion !== undefined)
38
+ return 'poll';
39
+ return 'webhook';
40
+ })();
41
+ const claimed = await claim(database, message, {
42
+ leaseUntil: new Date(startedAt.getTime() + leaseMs).toISOString(),
43
+ now: startedAt.toISOString(),
44
+ });
45
+ if (!claimed)
46
+ return { type: 'busy' };
47
+ const provider = options.providers.find((candidate) => candidate.id === claimed.providerId);
48
+ if (!provider || !Provider.canListDepositAddressRequests(provider)) {
49
+ await fail(database, claimed, startedAt, pollIntervalMs);
50
+ record('provider_unavailable', claimed.providerId, trigger);
51
+ return { type: 'provider_unavailable' };
52
+ }
53
+ const heartbeat = maintainLease(database, claimed, { leaseMs, now });
54
+ try {
55
+ await heartbeat.ready();
56
+ const requests = await listRequests(provider, {
57
+ address: claimed,
58
+ requestId: message.requestId,
59
+ signal: options.signal,
60
+ });
61
+ if (trigger === 'poll')
62
+ await FundingDepositRequestObservations.observePoll(database, {
63
+ depositAddressId: claimed.id,
64
+ observedAt: now().toISOString(),
65
+ providerRequestIds: requests.requests.map((request) => request.id),
66
+ });
67
+ const webhookUpdateObserved = (() => {
68
+ const timing = message.webhookTiming;
69
+ if (!timing)
70
+ return true;
71
+ if (!message.requestId)
72
+ return false;
73
+ // Relay can send a webhook before its requests API indexes the same update.
74
+ return requests.requests.some((request) => request.id === message.requestId && request.updatedAt >= timing.providerUpdatedAt);
75
+ })();
76
+ heartbeat.assert();
77
+ let created = 0;
78
+ let updated = 0;
79
+ const pendingRequestIds = new Set([
80
+ ...requests.pendingRequestIds,
81
+ ...(message.requestId ? [message.requestId] : []),
82
+ ]);
83
+ let followUpKind;
84
+ for (const request of requests.requests) {
85
+ const result = await reconcileRequest(database, {
86
+ address: claimed,
87
+ metrics: options.metrics,
88
+ provider,
89
+ request,
90
+ signal: options.signal,
91
+ subsidies: options.subsidies,
92
+ trigger,
93
+ verifyTransfers: options.verifyTransfers,
94
+ });
95
+ heartbeat.assert();
96
+ created += result.created;
97
+ updated += result.updated;
98
+ if (result.terminal)
99
+ pendingRequestIds.delete(request.id);
100
+ else {
101
+ pendingRequestIds.add(request.id);
102
+ followUpKind = result.followUp ?? followUpKind ?? 'provider';
103
+ }
104
+ }
105
+ const awaitsProvider = await FundingDeposits.hasUnattributed(database, claimed.id);
106
+ if (message.requestId && message.webhookTiming && !webhookUpdateObserved)
107
+ pendingRequestIds.add(message.requestId);
108
+ if (created > 0)
109
+ options.metrics?.count('funding_deposit_detection_count', created, {
110
+ provider: claimed.providerId,
111
+ trigger,
112
+ });
113
+ const leaseFailure = await heartbeat.stop();
114
+ if (leaseFailure !== undefined)
115
+ throw leaseFailure;
116
+ const completedAt = now();
117
+ const stored = await FundingDepositAddresses.completePoll(database, {
118
+ id: claimed.id,
119
+ lastPolledAt: completedAt.toISOString(),
120
+ nextPollAt: new Date(completedAt.getTime() + pollIntervalMs).toISOString(),
121
+ pollLeaseVersion: claimed.pollLeaseVersion,
122
+ providerRequestIds: claimed.providerRequestIds,
123
+ providerState: reconciliationState(claimed.providerState, {
124
+ pendingRequestIds: [...pendingRequestIds],
125
+ requests,
126
+ ...(message.webhookTiming && message.requestId && webhookUpdateObserved
127
+ ? {
128
+ webhookTiming: {
129
+ ...message.webhookTiming,
130
+ reconciliationCompletedAt: completedAt.toISOString(),
131
+ requestId: message.requestId,
132
+ },
133
+ }
134
+ : {}),
135
+ }),
136
+ });
137
+ if (!stored)
138
+ return { type: 'stale' };
139
+ if (pendingRequestIds.size > 0 || awaitsProvider) {
140
+ const followUp = nextFollowUp(message, followUpKind ?? 'provider');
141
+ if (followUp)
142
+ await options
143
+ .dispatch({
144
+ addressId: claimed.id,
145
+ followUp: followUp.state,
146
+ ...(message.requestId ? { requestId: message.requestId } : {}),
147
+ trigger,
148
+ type: 'funding:deposit-address:reconcile',
149
+ ...(message.webhookTiming && !webhookUpdateObserved
150
+ ? { webhookTiming: message.webhookTiming }
151
+ : {}),
152
+ }, { delaySeconds: followUp.delaySeconds })
153
+ .catch((cause) => {
154
+ record('follow_up_enqueue_failed', claimed.providerId, trigger);
155
+ throw cause;
156
+ });
157
+ record(followUp ? 'follow_up_enqueued' : 'follow_up_exhausted', claimed.providerId, trigger);
158
+ }
159
+ if (message.webhookTiming && webhookUpdateObserved)
160
+ recordWebhookLatency(options.metrics, {
161
+ completedAt,
162
+ providerId: claimed.providerId,
163
+ timing: message.webhookTiming,
164
+ });
165
+ record('completed', claimed.providerId, trigger);
166
+ options.metrics?.histogram('funding_deposit_reconciliation_duration_ms', completedAt.getTime() - startedAt.getTime(), { provider: claimed.providerId, trigger });
167
+ return { created, type: 'completed', updated };
168
+ }
169
+ catch (cause) {
170
+ const leaseFailure = await heartbeat.stop();
171
+ await fail(database, claimed, now(), pollIntervalMs);
172
+ record('failed', claimed.providerId, trigger);
173
+ throw leaseFailure ?? cause;
174
+ }
175
+ finally {
176
+ options.metrics?.flush();
177
+ }
178
+ },
179
+ async tick() {
180
+ const database = Db.get(options.db);
181
+ const startedAt = now();
182
+ const leaseUntil = new Date(startedAt.getTime() + leaseMs).toISOString();
183
+ let claimed = 0;
184
+ let failed = 0;
185
+ for (const provider of options.providers) {
186
+ if (!Provider.canListDepositAddressRequests(provider))
187
+ continue;
188
+ const records = await FundingDepositAddresses.claimDue(database, {
189
+ leaseUntil,
190
+ limit: Math.max(0, batchSize - claimed),
191
+ now: startedAt.toISOString(),
192
+ providerId: provider.id,
193
+ });
194
+ for (const address of records) {
195
+ claimed += 1;
196
+ options.metrics?.histogram('funding_deposit_poll_lag_ms', Math.max(0, startedAt.getTime() - new Date(address.nextPollAt).getTime()), { provider: provider.id });
197
+ try {
198
+ await options.dispatch({
199
+ addressId: address.id,
200
+ pollLeaseVersion: address.pollLeaseVersion,
201
+ trigger: 'poll',
202
+ type: 'funding:deposit-address:reconcile',
203
+ });
204
+ record('enqueued', provider.id, 'poll');
205
+ }
206
+ catch {
207
+ failed += 1;
208
+ await fail(database, address, startedAt, pollIntervalMs);
209
+ record('enqueue_failed', provider.id, 'poll');
210
+ }
211
+ }
212
+ if (claimed >= batchSize)
213
+ break;
214
+ }
215
+ options.metrics?.flush();
216
+ return { claimed, failed };
217
+ },
218
+ };
219
+ }
220
+ async function claim(db, message, options) {
221
+ if (message.pollLeaseVersion === undefined)
222
+ return FundingDepositAddresses.claim(db, {
223
+ id: message.addressId,
224
+ leaseUntil: options.leaseUntil,
225
+ now: options.now,
226
+ });
227
+ const current = await FundingDepositAddresses.get(db, message.addressId);
228
+ if (!current?.pollLeaseUntil ||
229
+ current.pollLeaseUntil <= options.now ||
230
+ current.pollLeaseVersion !== message.pollLeaseVersion)
231
+ return undefined;
232
+ return current;
233
+ }
234
+ async function fail(db, address, now, pollIntervalMs) {
235
+ const delay = Math.min(pollIntervalMs * 2 ** address.pollFailureCount, 15 * 60_000);
236
+ return FundingDepositAddresses.failPoll(db, {
237
+ id: address.id,
238
+ nextPollAt: new Date(now.getTime() + delay).toISOString(),
239
+ pollLeaseVersion: address.pollLeaseVersion,
240
+ });
241
+ }
242
+ function maintainLease(db, address, options) {
243
+ let failure;
244
+ let stopped = false;
245
+ const extend = async () => {
246
+ if (stopped || failure !== undefined)
247
+ return;
248
+ const renewed = await FundingDepositAddresses.renewPoll(db, {
249
+ id: address.id,
250
+ leaseUntil: new Date(options.now().getTime() + options.leaseMs).toISOString(),
251
+ pollLeaseVersion: address.pollLeaseVersion,
252
+ });
253
+ if (!renewed)
254
+ failure = new StaleLeaseError();
255
+ };
256
+ const captureFailure = (cause) => {
257
+ failure = cause;
258
+ };
259
+ let renewal = extend().catch(captureFailure);
260
+ const timer = setInterval(() => {
261
+ renewal = renewal.then(extend).catch(captureFailure);
262
+ }, Math.max(1, Math.floor(options.leaseMs / 2)));
263
+ return {
264
+ assert() {
265
+ if (failure !== undefined)
266
+ throw failure;
267
+ },
268
+ async ready() {
269
+ await renewal;
270
+ if (failure !== undefined)
271
+ throw failure;
272
+ },
273
+ async stop() {
274
+ if (!stopped) {
275
+ stopped = true;
276
+ clearInterval(timer);
277
+ }
278
+ await renewal;
279
+ return failure;
280
+ },
281
+ };
282
+ }
283
+ async function listRequests(provider, options) {
284
+ const highWater = readHighWater(options.address.providerState);
285
+ const highWaterRequestIds = new Set(highWater.requestIds);
286
+ const pendingRequestIds = new Set(highWater.pendingRequestIds);
287
+ const requests = [];
288
+ let continuation;
289
+ for (let page = 0; page < maximumPages; page++) {
290
+ const result = await provider.listDepositAddressRequests({ address: options.address.address, ...(continuation ? { continuation } : {}) }, options.signal ?? new AbortController().signal);
291
+ requests.push(...result.requests.filter((request) => !highWater.updatedAt ||
292
+ request.updatedAt > highWater.updatedAt ||
293
+ (request.updatedAt === highWater.updatedAt &&
294
+ (!highWaterRequestIds.has(request.id) || pendingRequestIds.has(request.id)))));
295
+ const reached = result.requests.some((request) => highWater.updatedAt && request.updatedAt < highWater.updatedAt);
296
+ continuation = result.continuation;
297
+ if (!continuation || reached)
298
+ break;
299
+ if (page === maximumPages - 1)
300
+ throw new PaginationLimitError();
301
+ }
302
+ const observed = new Set(requests.map((request) => request.id));
303
+ for (const requestId of unique([
304
+ ...highWater.pendingRequestIds,
305
+ ...(options.requestId ? [options.requestId] : []),
306
+ ])) {
307
+ if (observed.has(requestId))
308
+ continue;
309
+ const result = await provider.listDepositAddressRequests({ address: options.address.address, requestId }, options.signal ?? new AbortController().signal);
310
+ requests.push(...result.requests);
311
+ }
312
+ const addressRequests = requests.filter((request) => !highWater.pendingRequestIds.includes(request.id));
313
+ const newest = addressRequests.reduce((value, request) => (!value || request.updatedAt > value ? request.updatedAt : value), highWater.updatedAt);
314
+ return {
315
+ highWaterRequestIds: newest
316
+ ? unique([
317
+ ...(newest === highWater.updatedAt ? highWater.requestIds : []),
318
+ ...addressRequests
319
+ .filter((request) => request.updatedAt === newest)
320
+ .map((request) => request.id),
321
+ ])
322
+ : [],
323
+ highWaterUpdatedAt: newest,
324
+ pendingRequestIds: highWater.pendingRequestIds,
325
+ requests,
326
+ };
327
+ }
328
+ function readHighWater(state) {
329
+ if (!state || typeof state !== 'object')
330
+ return { pendingRequestIds: [], requestIds: [] };
331
+ const reconciliation = state['reconciliation'];
332
+ if (!reconciliation || typeof reconciliation !== 'object')
333
+ return { pendingRequestIds: [], requestIds: [] };
334
+ const pendingRequestIds = 'pendingRequestIds' in reconciliation && Array.isArray(reconciliation.pendingRequestIds)
335
+ ? reconciliation.pendingRequestIds.filter((value) => typeof value === 'string')
336
+ : [];
337
+ const requestIds = 'requestIds' in reconciliation && Array.isArray(reconciliation.requestIds)
338
+ ? reconciliation.requestIds.filter((value) => typeof value === 'string')
339
+ : [];
340
+ return {
341
+ pendingRequestIds,
342
+ requestIds,
343
+ ...('updatedAt' in reconciliation && typeof reconciliation.updatedAt === 'string'
344
+ ? { updatedAt: reconciliation.updatedAt }
345
+ : {}),
346
+ };
347
+ }
348
+ function reconciliationState(state, options) {
349
+ const current = state && typeof state === 'object' ? state : {};
350
+ const reconciliation = (() => {
351
+ const value = current['reconciliation'];
352
+ if (value && typeof value === 'object')
353
+ return value;
354
+ return {};
355
+ })();
356
+ return {
357
+ ...current,
358
+ reconciliation: {
359
+ ...reconciliation,
360
+ pendingRequestIds: options.pendingRequestIds,
361
+ requestIds: options.requests.highWaterRequestIds,
362
+ ...(options.requests.highWaterUpdatedAt
363
+ ? { updatedAt: options.requests.highWaterUpdatedAt }
364
+ : {}),
365
+ ...(options.webhookTiming ? { webhookTiming: options.webhookTiming } : {}),
366
+ },
367
+ };
368
+ }
369
+ async function observeProviderDelivery(options, verified) {
370
+ const [entry] = verified;
371
+ if (!entry ||
372
+ verified.length !== 1 ||
373
+ options.address.deliveryStrategy !== 'provider' ||
374
+ options.address.providerOutputToken.tokenKey !==
375
+ options.address.snapshot.destinationToken.tokenKey ||
376
+ (options.request.status === 'success' &&
377
+ options.request.destinationTransactionHashes.length > 0) ||
378
+ !options.provider ||
379
+ !Provider.canObserveDepositAddressRequest(options.provider))
380
+ return undefined;
381
+ const result = await options.provider
382
+ .observeDepositAddressRequest({
383
+ address: options.address.address,
384
+ destinationChain: options.address.snapshot.destinationChain,
385
+ destinationToken: options.address.providerOutputToken,
386
+ providerState: entry.deposit.providerState ?? undefined,
387
+ recipient: options.address.recipient,
388
+ refundAddress: options.address.refundAddress,
389
+ request: options.request,
390
+ source: entry.source,
391
+ sourceChain: options.address.snapshot.sourceChain,
392
+ sourceToken: options.address.snapshot.sourceToken,
393
+ }, options.signal ?? new AbortController().signal)
394
+ .catch((cause) => {
395
+ if (options.signal?.aborted)
396
+ throw cause;
397
+ return undefined;
398
+ });
399
+ options.metrics?.count('funding_deposit_delivery_observation_count', 1, {
400
+ outcome: result?.type ?? 'failed',
401
+ provider: options.address.providerId,
402
+ });
403
+ return result;
404
+ }
405
+ /** Reconciles one provider request against verified chain evidence. */
406
+ export async function reconcileRequest(db, options) {
407
+ const trigger = options.trigger ?? 'poll';
408
+ const observation = await FundingDepositRequestObservations.get(db, {
409
+ depositAddressId: options.address.id,
410
+ providerRequestId: options.request.id,
411
+ });
412
+ if (observation)
413
+ await FundingDeposits.recordRequestObservation(db, {
414
+ depositAddressId: observation.depositAddressId,
415
+ ...(observation.pollObservedAt ? { pollObservedAt: observation.pollObservedAt } : {}),
416
+ providerRequestId: observation.providerRequestId,
417
+ ...(observation.webhookReceivedAt
418
+ ? { webhookReceivedAt: observation.webhookReceivedAt }
419
+ : {}),
420
+ });
421
+ let created = 0;
422
+ let followUp;
423
+ const observed = [];
424
+ // Persist provider observations first so transient chain failures do not hide acknowledged deposits.
425
+ for (const transactionHash of unique(options.request.sourceTransactionHashes)) {
426
+ const deposits = await FundingDeposits.withSourceTransaction(db, {
427
+ depositAddressId: options.address.id,
428
+ fn: async (tx) => {
429
+ let records = await FundingDeposits.listByProviderObservation(tx, {
430
+ depositAddressId: options.address.id,
431
+ providerRequestId: options.request.id,
432
+ sourceTransactionHash: transactionHash,
433
+ });
434
+ if (records.length === 0)
435
+ records = await FundingDeposits.listBySourceTransaction(tx, {
436
+ depositAddressId: options.address.id,
437
+ sourceTransactionHash: transactionHash,
438
+ });
439
+ if (records.length > 0)
440
+ return records;
441
+ created += 1;
442
+ return [
443
+ await Deposit.create(tx, {
444
+ detectionTrigger: trigger,
445
+ now: new Date(options.request.createdAt),
446
+ ...(observation?.pollObservedAt ? { pollObservedAt: observation.pollObservedAt } : {}),
447
+ providerRequestId: options.request.id,
448
+ snapshot: {
449
+ depositAddressId: options.address.id,
450
+ destinationChain: options.address.snapshot.destinationChain,
451
+ destinationToken: options.address.snapshot.destinationToken,
452
+ provider: options.address.snapshot.provider,
453
+ recipient: options.address.recipient,
454
+ refundAddress: options.address.refundAddress,
455
+ sourceChain: options.address.snapshot.sourceChain,
456
+ sourceToken: options.address.snapshot.sourceToken,
457
+ sourceTransactionHashes: [transactionHash],
458
+ },
459
+ sourceTransactionHash: transactionHash,
460
+ ...(observation?.webhookReceivedAt
461
+ ? { webhookReceivedAt: observation.webhookReceivedAt }
462
+ : {}),
463
+ }),
464
+ ];
465
+ },
466
+ sourceTransactionHash: transactionHash,
467
+ });
468
+ observed.push({ deposits, transactionHash, transfers: [] });
469
+ }
470
+ const sources = await Promise.all(observed.map(async (source) => ({
471
+ ...source,
472
+ transfers: await options.verifyTransfers({
473
+ chain: options.address.snapshot.sourceChain,
474
+ recipient: options.address.address,
475
+ token: options.address.snapshot.sourceToken,
476
+ transactionHash: source.transactionHash,
477
+ }),
478
+ })));
479
+ const sourceEvidenceComplete = sources.length > 0 && sources.every((source) => source.transfers.length > 0);
480
+ let terminal = sourceEvidenceComplete;
481
+ const updatedIds = new Set();
482
+ const verified = [];
483
+ for (const source of sources) {
484
+ const transfers = [...source.transfers].sort((left, right) => left.transferIndex - right.transferIndex);
485
+ for (const [providerTransferIndex, transfer] of transfers.entries()) {
486
+ const required = destinationBaseUnits(BigInt(transfer.amount), options.address.snapshot.sourceToken.decimals, options.address.snapshot.destinationToken.decimals);
487
+ const sourceAmount = Value.tokenAmount({
488
+ baseUnits: transfer.amount,
489
+ currency: options.address.snapshot.sourceToken.currency,
490
+ decimals: options.address.snapshot.sourceToken.decimals,
491
+ });
492
+ const destinationAmountRequired = Value.tokenAmount({
493
+ baseUnits: required,
494
+ currency: options.address.snapshot.destinationToken.currency,
495
+ decimals: options.address.snapshot.destinationToken.decimals,
496
+ });
497
+ // Bind the placeholder to transfers in deterministic log order when one transaction contains several deposits.
498
+ let deposit = source.deposits.find((record) => record.providerRequestId === null
499
+ ? record.sourceTransferIndex === transfer.transferIndex
500
+ : record.providerTransferIndex === providerTransferIndex);
501
+ if (!deposit) {
502
+ deposit = await Deposit.create(db, {
503
+ detectionTrigger: trigger,
504
+ now: new Date(options.request.createdAt),
505
+ ...(observation?.pollObservedAt ? { pollObservedAt: observation.pollObservedAt } : {}),
506
+ providerRequestId: options.request.id,
507
+ providerTransferIndex,
508
+ snapshot: {
509
+ depositAddressId: options.address.id,
510
+ ...(options.address.snapshot.subsidize ? { destinationAmountRequired } : {}),
511
+ destinationChain: options.address.snapshot.destinationChain,
512
+ destinationToken: options.address.snapshot.destinationToken,
513
+ provider: options.address.snapshot.provider,
514
+ recipient: options.address.recipient,
515
+ refundAddress: options.address.refundAddress,
516
+ ...(transfer.sender ? { sender: transfer.sender } : {}),
517
+ sourceAmount,
518
+ sourceChain: options.address.snapshot.sourceChain,
519
+ sourceToken: options.address.snapshot.sourceToken,
520
+ sourceTransactionHashes: [transfer.transactionHash],
521
+ },
522
+ sourceTransactionHash: transfer.transactionHash,
523
+ sourceTransferIndex: transfer.transferIndex,
524
+ ...(observation?.webhookReceivedAt
525
+ ? { webhookReceivedAt: observation.webhookReceivedAt }
526
+ : {}),
527
+ });
528
+ source.deposits.push(deposit);
529
+ created += 1;
530
+ }
531
+ if (!Deposit.isTerminal(deposit.status)) {
532
+ const result = await Deposit.transition(db, {
533
+ expectedVersion: deposit.version,
534
+ id: deposit.id,
535
+ providerRequestId: options.request.id,
536
+ providerRequestIds: unique([...deposit.providerRequestIds, options.request.id]),
537
+ providerTransferIndex,
538
+ snapshot: {
539
+ ...deposit.snapshot,
540
+ ...(options.address.snapshot.subsidize ? { destinationAmountRequired } : {}),
541
+ ...(transfer.sender ? { sender: transfer.sender } : {}),
542
+ sourceAmount,
543
+ },
544
+ sourceTransferIndex: transfer.transferIndex,
545
+ status: deposit.status === 'detected' ? 'bridging' : deposit.status,
546
+ });
547
+ if (result.type === 'applied') {
548
+ deposit = result.record;
549
+ updatedIds.add(deposit.id);
550
+ }
551
+ }
552
+ verified.push({ deposit, required, source: transfer, sourceAmount: BigInt(transfer.amount) });
553
+ }
554
+ }
555
+ if (verified.length === 0)
556
+ return { created, terminal: false, updated: updatedIds.size };
557
+ if (!sourceEvidenceComplete)
558
+ return { created, terminal: false, updated: updatedIds.size };
559
+ const deliveryObservation = await observeProviderDelivery(options, verified);
560
+ if (deliveryObservation?.type === 'pending')
561
+ followUp = 'delivery';
562
+ const destinationTransactionHashes = unique([
563
+ ...options.request.destinationTransactionHashes,
564
+ ...(deliveryObservation?.type === 'verified'
565
+ ? deliveryObservation.destinationTransactionHashes
566
+ : []),
567
+ ]);
568
+ const destinationEvidence = await Promise.all(destinationTransactionHashes.map((transactionHash) => options.verifyTransfers({
569
+ chain: options.address.snapshot.destinationChain,
570
+ recipient: options.address.recipient,
571
+ token: options.address.providerOutputToken,
572
+ transactionHash,
573
+ })));
574
+ const destinationTransfers = destinationEvidence.flat();
575
+ const providerEvidenceComplete = (options.request.status === 'success' || deliveryObservation?.type === 'verified') &&
576
+ destinationEvidence.length > 0 &&
577
+ destinationEvidence.every((transfers) => transfers.length > 0);
578
+ const providerOutput = destinationTransfers.reduce((total, transfer) => total + BigInt(transfer.amount), 0n);
579
+ const totalRequired = verified.reduce((total, entry) => total + entry.required, 0n);
580
+ let allocated = 0n;
581
+ let cumulativeRequired = 0n;
582
+ for (const entry of verified) {
583
+ const { required, sourceAmount } = entry;
584
+ cumulativeRequired += required;
585
+ const nextAllocated = totalRequired === 0n ? 0n : (providerOutput * cumulativeRequired) / totalRequired;
586
+ const delivered = nextAllocated - allocated;
587
+ allocated = nextAllocated;
588
+ const { deposit } = entry;
589
+ if (Deposit.isTerminal(deposit.status))
590
+ continue;
591
+ const settlement = await reconcileSubsidy({
592
+ address: options.address,
593
+ delivered,
594
+ deposit,
595
+ providerEvidenceComplete,
596
+ required,
597
+ sourceAmount,
598
+ subsidies: options.subsidies,
599
+ verifyTransfers: options.verifyTransfers,
600
+ });
601
+ if (settlement.outcome)
602
+ options.metrics?.count('funding_deposit_subsidy_count', 1, {
603
+ outcome: settlement.outcome,
604
+ provider: options.address.providerId,
605
+ });
606
+ if (settlement.status === 'bridging' || settlement.status === 'settling')
607
+ terminal = false;
608
+ if (settlement.status === 'settling')
609
+ followUp = 'settlement';
610
+ const destinationAmount = Value.tokenAmount({
611
+ baseUnits: delivered + settlement.delivered,
612
+ currency: options.address.snapshot.destinationToken.currency,
613
+ decimals: options.address.snapshot.destinationToken.decimals,
614
+ });
615
+ const result = await Deposit.transition(db, {
616
+ expectedVersion: deposit.version,
617
+ id: deposit.id,
618
+ ...(delivered > 0n
619
+ ? {
620
+ providerOutputAmount: Value.tokenAmount({
621
+ baseUnits: delivered,
622
+ currency: options.address.providerOutputToken.currency,
623
+ decimals: options.address.providerOutputToken.decimals,
624
+ }),
625
+ }
626
+ : {}),
627
+ providerRequestIds: unique([...deposit.providerRequestIds, options.request.id]),
628
+ ...(deliveryObservation?.providerState
629
+ ? {
630
+ providerState: {
631
+ ...deposit.providerState,
632
+ ...deliveryObservation.providerState,
633
+ },
634
+ }
635
+ : {}),
636
+ providerTransactionHashes: unique([
637
+ ...deposit.providerTransactionHashes,
638
+ ...options.request.destinationTransactionHashes,
639
+ ...(deliveryObservation?.providerTransactionHashes ?? []),
640
+ ]),
641
+ ...(settlement.settlementTransaction
642
+ ? { settlementTransaction: settlement.settlementTransaction }
643
+ : {}),
644
+ ...(settlement.settlementTransactionHash
645
+ ? { settlementTransactionHash: settlement.settlementTransactionHash }
646
+ : {}),
647
+ snapshot: {
648
+ ...deposit.snapshot,
649
+ ...(delivered + settlement.delivered > 0n ? { destinationAmount } : {}),
650
+ ...(settlement.status === 'completed' && !options.address.snapshot.subsidize
651
+ ? { destinationAmountRequired: destinationAmount }
652
+ : {}),
653
+ destinationTransactionHashes: unique([
654
+ ...(deposit.snapshot.destinationTransactionHashes ?? []),
655
+ ...destinationTransfers.map((evidence) => evidence.transactionHash),
656
+ ...settlement.destinationTransactionHashes,
657
+ ]),
658
+ },
659
+ status: settlement.status,
660
+ ...(settlement.statusReason ? { statusReason: settlement.statusReason } : {}),
661
+ ...(settlement.subsidyAmount ? { subsidyAmount: settlement.subsidyAmount } : {}),
662
+ ...(settlement.tempoGasPaid ? { tempoGasPaid: settlement.tempoGasPaid } : {}),
663
+ });
664
+ if (result.type === 'applied') {
665
+ updatedIds.add(deposit.id);
666
+ if (settlement.broadcast && options.subsidies) {
667
+ await options.subsidies.broadcast(settlement.broadcast).catch((cause) => {
668
+ options.metrics?.count('funding_deposit_subsidy_count', 1, {
669
+ outcome: 'broadcast_failed',
670
+ provider: options.address.providerId,
671
+ });
672
+ throw cause;
673
+ });
674
+ options.metrics?.count('funding_deposit_subsidy_count', 1, {
675
+ outcome: 'broadcast',
676
+ provider: options.address.providerId,
677
+ });
678
+ }
679
+ }
680
+ }
681
+ return { created, ...(followUp ? { followUp } : {}), terminal, updated: updatedIds.size };
682
+ }
683
+ async function reconcileSubsidy(options) {
684
+ const empty = { delivered: 0n, destinationTransactionHashes: [] };
685
+ if (options.required === 0n)
686
+ return {
687
+ ...empty,
688
+ status: 'action-required',
689
+ statusReason: {
690
+ code: 'source_amount_not_supported',
691
+ message: 'The source amount is smaller than one destination-token base unit.',
692
+ },
693
+ };
694
+ const deficit = options.required > options.delivered ? options.required - options.delivered : 0n;
695
+ const subsidyAmount = options.deposit.subsidyAmount ??
696
+ Value.tokenAmount({
697
+ baseUnits: deficit,
698
+ currency: options.address.snapshot.destinationToken.currency,
699
+ decimals: options.address.snapshot.destinationToken.decimals,
700
+ });
701
+ if (options.deposit.settlementTransaction && options.deposit.settlementTransactionHash) {
702
+ if (!options.subsidies)
703
+ return {
704
+ ...empty,
705
+ outcome: 'unavailable',
706
+ status: 'action-required',
707
+ statusReason: {
708
+ code: 'subsidy_failed',
709
+ message: 'Tempo subsidy settlement is unavailable.',
710
+ },
711
+ subsidyAmount,
712
+ };
713
+ const hash = options.deposit.settlementTransactionHash;
714
+ const status = await options.subsidies.status({ hash });
715
+ if (status.type === 'reverted')
716
+ return {
717
+ ...empty,
718
+ outcome: 'reverted',
719
+ status: 'action-required',
720
+ statusReason: {
721
+ code: 'subsidy_failed',
722
+ message: 'Tempo could not deliver the required subsidy.',
723
+ },
724
+ subsidyAmount,
725
+ tempoGasPaid: status.tempoGasPaid,
726
+ };
727
+ if (status.type === 'pending')
728
+ return {
729
+ ...empty,
730
+ broadcast: {
731
+ hash,
732
+ transaction: options.deposit.settlementTransaction,
733
+ },
734
+ outcome: 'pending',
735
+ status: 'settling',
736
+ subsidyAmount,
737
+ };
738
+ const transfers = await options.verifyTransfers({
739
+ chain: options.address.snapshot.destinationChain,
740
+ recipient: options.address.recipient,
741
+ token: options.address.snapshot.destinationToken,
742
+ transactionHash: hash,
743
+ });
744
+ const delivered = transfers.reduce((total, transfer) => total + BigInt(transfer.amount), 0n);
745
+ return {
746
+ delivered,
747
+ destinationTransactionHashes: transfers.map((transfer) => transfer.transactionHash),
748
+ outcome: options.delivered + delivered >= options.required ? 'completed' : 'underfilled',
749
+ status: options.delivered + delivered >= options.required ? 'completed' : 'settling',
750
+ subsidyAmount,
751
+ tempoGasPaid: status.tempoGasPaid,
752
+ };
753
+ }
754
+ if (options.delivered >= options.required)
755
+ return { ...empty, status: 'completed' };
756
+ if (!options.address.snapshot.subsidize) {
757
+ if (!options.providerEvidenceComplete)
758
+ return { ...empty, status: 'bridging' };
759
+ if (options.delivered > 0n)
760
+ return { ...empty, status: 'completed' };
761
+ return {
762
+ ...empty,
763
+ status: 'action-required',
764
+ statusReason: {
765
+ code: 'delivery_failed',
766
+ message: 'The provider completed without delivering destination funds.',
767
+ },
768
+ };
769
+ }
770
+ if (!options.providerEvidenceComplete)
771
+ return { ...empty, status: 'bridging' };
772
+ if (!options.subsidies)
773
+ return {
774
+ ...empty,
775
+ outcome: 'unavailable',
776
+ status: 'action-required',
777
+ statusReason: {
778
+ code: 'subsidy_failed',
779
+ message: 'Tempo subsidy settlement is unavailable.',
780
+ },
781
+ };
782
+ if (!Subsidy.supports(options.subsidies.policy, {
783
+ amount: options.sourceAmount.toString(),
784
+ destinationToken: options.address.snapshot.destinationToken,
785
+ sourceToken: options.address.snapshot.sourceToken,
786
+ }))
787
+ return {
788
+ ...empty,
789
+ outcome: 'unsupported',
790
+ status: 'action-required',
791
+ statusReason: {
792
+ code: 'source_amount_not_supported',
793
+ message: 'The source amount is outside the subsidized deposit limit.',
794
+ },
795
+ };
796
+ const prepared = await options.subsidies
797
+ .prepare({
798
+ amount: deficit,
799
+ depositId: options.deposit.id,
800
+ recipient: options.address.recipient,
801
+ token: options.address.snapshot.destinationToken.address,
802
+ })
803
+ .catch((cause) => {
804
+ if (cause instanceof Subsidy.BalanceUnavailableError)
805
+ return undefined;
806
+ if (cause instanceof Subsidy.LiquidityUnavailableError)
807
+ return null;
808
+ throw cause;
809
+ });
810
+ if (prepared === null)
811
+ return {
812
+ ...empty,
813
+ outcome: 'liquidity_unavailable',
814
+ status: 'settling',
815
+ subsidyAmount,
816
+ };
817
+ if (!prepared)
818
+ return {
819
+ ...empty,
820
+ outcome: 'balance_unavailable',
821
+ status: 'action-required',
822
+ statusReason: {
823
+ code: 'subsidy_balance_unavailable',
824
+ message: 'Tempo lacks enough pathUSD for the required subsidy.',
825
+ },
826
+ subsidyAmount,
827
+ };
828
+ return {
829
+ ...empty,
830
+ broadcast: prepared,
831
+ outcome: 'prepared',
832
+ settlementTransaction: prepared.transaction,
833
+ settlementTransactionHash: prepared.hash,
834
+ status: 'settling',
835
+ subsidyAmount,
836
+ };
837
+ }
838
+ function destinationBaseUnits(amount, sourceDecimals, destinationDecimals) {
839
+ if (destinationDecimals >= sourceDecimals)
840
+ return amount * 10n ** BigInt(destinationDecimals - sourceDecimals);
841
+ const divisor = 10n ** BigInt(sourceDecimals - destinationDecimals);
842
+ // Destination tokens cannot represent finer source precision, so retain only
843
+ // the amount expressible in destination base units.
844
+ return amount / divisor;
845
+ }
846
+ function unique(values) {
847
+ return [...new Set(values)];
848
+ }
849
+ function nextFollowUp(message, kind) {
850
+ const attempt = message.followUp?.kind === kind ? message.followUp.attempt + 1 : 0;
851
+ if (attempt >= maximumFollowUpAttempts)
852
+ return undefined;
853
+ return { delaySeconds: followUpDelaySeconds[kind], state: { attempt, kind } };
854
+ }
855
+ function recordWebhookLatency(metrics, options) {
856
+ if (!metrics)
857
+ return;
858
+ const completedAt = options.completedAt.getTime();
859
+ const enqueuedAt = Date.parse(options.timing.enqueuedAt);
860
+ const providerUpdatedAt = Date.parse(options.timing.providerUpdatedAt);
861
+ const receivedAt = Date.parse(options.timing.receivedAt);
862
+ const sentAt = Date.parse(options.timing.sentAt);
863
+ const segments = [
864
+ { from: providerUpdatedAt, segment: 'provider_to_sent', to: sentAt },
865
+ { from: sentAt, segment: 'sent_to_received', to: receivedAt },
866
+ { from: receivedAt, segment: 'received_to_enqueued', to: enqueuedAt },
867
+ { from: enqueuedAt, segment: 'enqueued_to_reconciled', to: completedAt },
868
+ { from: providerUpdatedAt, segment: 'provider_to_reconciled', to: completedAt },
869
+ ];
870
+ for (const segment of segments)
871
+ metrics.histogram('funding_deposit_webhook_latency_ms', Math.max(0, segment.to - segment.from), {
872
+ provider: options.providerId,
873
+ segment: segment.segment,
874
+ status: options.timing.providerStatus,
875
+ });
876
+ }
877
+ /** Provider pagination exceeded the bounded reconciliation limit. */
878
+ export class PaginationLimitError extends Error {
879
+ name = 'Funding.Reconciliation.PaginationLimitError';
880
+ }
881
+ /** The reconciliation lease was claimed by another worker. */
882
+ export class StaleLeaseError extends Error {
883
+ name = 'Funding.Reconciliation.StaleLeaseError';
884
+ }
885
+ //# sourceMappingURL=Reconciliation.js.map