tapimo 0.2.0 → 0.4.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 (362) hide show
  1. package/README.md +36 -8
  2. package/dist/ApiKey.d.ts +1 -0
  3. package/dist/ApiKey.d.ts.map +1 -1
  4. package/dist/ApiKey.js +5 -2
  5. package/dist/ApiKey.js.map +1 -1
  6. package/dist/ApiKeys.d.ts +28 -1
  7. package/dist/ApiKeys.d.ts.map +1 -1
  8. package/dist/ApiKeys.js +34 -1
  9. package/dist/ApiKeys.js.map +1 -1
  10. package/dist/App.d.ts +7532 -4850
  11. package/dist/App.d.ts.map +1 -1
  12. package/dist/App.js +11 -3
  13. package/dist/App.js.map +1 -1
  14. package/dist/Scope.d.ts +11 -2
  15. package/dist/Scope.d.ts.map +1 -1
  16. package/dist/Scope.js +14 -3
  17. package/dist/Scope.js.map +1 -1
  18. package/dist/admin/App.d.ts +63 -53
  19. package/dist/admin/App.d.ts.map +1 -1
  20. package/dist/admin/apps/api-keys.d.ts +7 -0
  21. package/dist/admin/apps/api-keys.d.ts.map +1 -1
  22. package/dist/admin/apps/scopes.d.ts +8 -0
  23. package/dist/admin/apps/scopes.d.ts.map +1 -1
  24. package/dist/admin/apps/scopes.js +3 -0
  25. package/dist/admin/apps/scopes.js.map +1 -1
  26. package/dist/admin/apps/verified-tokens.d.ts +57 -57
  27. package/dist/admin/ui.generated.d.ts +1 -1
  28. package/dist/admin/ui.generated.js +13 -13
  29. package/dist/admin/ui.generated.js.map +1 -1
  30. package/dist/analytics/Analytics.d.ts +151 -0
  31. package/dist/analytics/Analytics.d.ts.map +1 -0
  32. package/dist/analytics/Analytics.js +212 -0
  33. package/dist/analytics/Analytics.js.map +1 -0
  34. package/dist/analytics/tables/requestEvents.d.ts +215 -0
  35. package/dist/analytics/tables/requestEvents.d.ts.map +1 -0
  36. package/dist/analytics/tables/requestEvents.js +264 -0
  37. package/dist/analytics/tables/requestEvents.js.map +1 -0
  38. package/dist/apps/data/App.d.ts +1049 -624
  39. package/dist/apps/data/App.d.ts.map +1 -1
  40. package/dist/apps/data/App.js +36 -0
  41. package/dist/apps/data/App.js.map +1 -1
  42. package/dist/apps/data/FundingRouteProviders.d.ts +54 -0
  43. package/dist/apps/data/FundingRouteProviders.d.ts.map +1 -0
  44. package/dist/apps/data/FundingRouteProviders.js +355 -0
  45. package/dist/apps/data/FundingRouteProviders.js.map +1 -0
  46. package/dist/apps/data/index.d.ts +1 -0
  47. package/dist/apps/data/index.d.ts.map +1 -1
  48. package/dist/apps/data/index.js +1 -0
  49. package/dist/apps/data/index.js.map +1 -1
  50. package/dist/apps/data/routes/balances.d.ts +45 -45
  51. package/dist/apps/data/routes/coingecko.d.ts +176 -176
  52. package/dist/apps/data/routes/exchanges.d.ts +455 -455
  53. package/dist/apps/data/routes/fee-amm.d.ts +101 -101
  54. package/dist/apps/data/routes/funding.d.ts +843 -0
  55. package/dist/apps/data/routes/funding.d.ts.map +1 -0
  56. package/dist/apps/data/routes/funding.js +443 -0
  57. package/dist/apps/data/routes/funding.js.map +1 -0
  58. package/dist/apps/data/routes/indexer.d.ts +5 -5
  59. package/dist/apps/data/routes/receipts.d.ts.map +1 -1
  60. package/dist/apps/data/routes/receipts.js +2 -8
  61. package/dist/apps/data/routes/receipts.js.map +1 -1
  62. package/dist/apps/data/routes/rpc.d.ts +29 -36
  63. package/dist/apps/data/routes/rpc.d.ts.map +1 -1
  64. package/dist/apps/data/routes/rpc.js +29 -1
  65. package/dist/apps/data/routes/rpc.js.map +1 -1
  66. package/dist/apps/data/routes/tokenlist.d.ts +36 -36
  67. package/dist/apps/data/routes/transfers.d.ts +56 -56
  68. package/dist/apps/data/routes/verified-tokens.d.ts +36 -36
  69. package/dist/apps/data/routes/webhooks.d.ts +45 -45
  70. package/dist/apps/data/routes/webhooks.d.ts.map +1 -1
  71. package/dist/apps/data/routes/webhooks.js +8 -8
  72. package/dist/apps/data/routes/webhooks.js.map +1 -1
  73. package/dist/apps/docs/App.d.ts +5 -3
  74. package/dist/apps/docs/App.d.ts.map +1 -1
  75. package/dist/apps/docs/App.js +28 -96
  76. package/dist/apps/docs/App.js.map +1 -1
  77. package/dist/apps/docs/reference.d.ts +21 -0
  78. package/dist/apps/docs/reference.d.ts.map +1 -0
  79. package/dist/apps/docs/reference.js +112 -0
  80. package/dist/apps/docs/reference.js.map +1 -0
  81. package/dist/apps/index.d.ts +3 -2
  82. package/dist/apps/index.d.ts.map +1 -1
  83. package/dist/apps/index.js +3 -2
  84. package/dist/apps/index.js.map +1 -1
  85. package/dist/apps/{platform → management}/App.d.ts +3015 -738
  86. package/dist/apps/management/App.d.ts.map +1 -0
  87. package/dist/apps/{platform → management}/App.js +20 -10
  88. package/dist/apps/management/App.js.map +1 -0
  89. package/dist/apps/management/Billing.d.ts +279 -0
  90. package/dist/apps/management/Billing.d.ts.map +1 -0
  91. package/dist/apps/management/Billing.js +477 -0
  92. package/dist/apps/management/Billing.js.map +1 -0
  93. package/dist/apps/management/index.d.ts +3 -0
  94. package/dist/apps/management/index.d.ts.map +1 -0
  95. package/dist/apps/management/index.js +3 -0
  96. package/dist/apps/management/index.js.map +1 -0
  97. package/dist/apps/{platform → management}/routes/api-keys.d.ts +341 -49
  98. package/dist/apps/management/routes/api-keys.d.ts.map +1 -0
  99. package/dist/apps/{platform → management}/routes/api-keys.js +116 -14
  100. package/dist/apps/management/routes/api-keys.js.map +1 -0
  101. package/dist/apps/management/routes/billing.d.ts +1520 -0
  102. package/dist/apps/management/routes/billing.d.ts.map +1 -0
  103. package/dist/apps/management/routes/billing.js +795 -0
  104. package/dist/apps/management/routes/billing.js.map +1 -0
  105. package/dist/apps/{platform → management}/routes/invitations.d.ts +202 -84
  106. package/dist/apps/management/routes/invitations.d.ts.map +1 -0
  107. package/dist/apps/{platform → management}/routes/invitations.js +59 -1
  108. package/dist/apps/management/routes/invitations.js.map +1 -0
  109. package/dist/apps/{platform → management}/routes/me.d.ts +17 -17
  110. package/dist/apps/management/routes/me.d.ts.map +1 -0
  111. package/dist/apps/management/routes/me.js.map +1 -0
  112. package/dist/apps/management/routes/members.d.ts.map +1 -0
  113. package/dist/apps/management/routes/members.js.map +1 -0
  114. package/dist/apps/{platform → management}/routes/orgs.d.ts +50 -36
  115. package/dist/apps/management/routes/orgs.d.ts.map +1 -0
  116. package/dist/apps/{platform → management}/routes/orgs.js +14 -3
  117. package/dist/apps/management/routes/orgs.js.map +1 -0
  118. package/dist/apps/{platform → management}/routes/projects.d.ts +97 -97
  119. package/dist/apps/{platform → management}/routes/projects.d.ts.map +1 -1
  120. package/dist/apps/management/routes/projects.js.map +1 -0
  121. package/dist/apps/management/routes/scopes.d.ts +107 -0
  122. package/dist/apps/management/routes/scopes.d.ts.map +1 -0
  123. package/dist/apps/management/routes/scopes.js +66 -0
  124. package/dist/apps/management/routes/scopes.js.map +1 -0
  125. package/dist/apps/management/routes/usage.d.ts +588 -0
  126. package/dist/apps/management/routes/usage.d.ts.map +1 -0
  127. package/dist/apps/management/routes/usage.js +391 -0
  128. package/dist/apps/management/routes/usage.js.map +1 -0
  129. package/dist/apps/mcp.d.ts +76 -0
  130. package/dist/apps/mcp.d.ts.map +1 -0
  131. package/dist/apps/mcp.js +188 -0
  132. package/dist/apps/mcp.js.map +1 -0
  133. package/dist/apps/relay/App.d.ts +4 -1
  134. package/dist/apps/relay/App.d.ts.map +1 -1
  135. package/dist/apps/relay/App.js +118 -10
  136. package/dist/apps/relay/App.js.map +1 -1
  137. package/dist/apps/relay/Sponsorships.d.ts.map +1 -1
  138. package/dist/apps/relay/Sponsorships.js +2 -1
  139. package/dist/apps/relay/Sponsorships.js.map +1 -1
  140. package/dist/cli/Cli.d.ts +8 -1
  141. package/dist/cli/Cli.d.ts.map +1 -1
  142. package/dist/cli/Cli.js +11 -3
  143. package/dist/cli/Cli.js.map +1 -1
  144. package/dist/cli/commands/admin.d.ts +4 -0
  145. package/dist/cli/commands/admin.d.ts.map +1 -1
  146. package/dist/cli/commands/admin.js +80 -1
  147. package/dist/cli/commands/admin.js.map +1 -1
  148. package/dist/db/Db.d.ts +7 -0
  149. package/dist/db/Db.d.ts.map +1 -1
  150. package/dist/db/Db.js +126 -0
  151. package/dist/db/Db.js.map +1 -1
  152. package/dist/db/Schema.d.ts +79 -0
  153. package/dist/db/Schema.d.ts.map +1 -1
  154. package/dist/db/Schema.js +88 -2
  155. package/dist/db/Schema.js.map +1 -1
  156. package/dist/db/tables/billingSettings.d.ts +55 -0
  157. package/dist/db/tables/billingSettings.d.ts.map +1 -0
  158. package/dist/db/tables/billingSettings.js +70 -0
  159. package/dist/db/tables/billingSettings.js.map +1 -0
  160. package/dist/db/tables/invitations.js +2 -2
  161. package/dist/db/tables/invitations.js.map +1 -1
  162. package/dist/db/tables/organizations.d.ts +6 -2
  163. package/dist/db/tables/organizations.d.ts.map +1 -1
  164. package/dist/db/tables/organizations.js +10 -4
  165. package/dist/db/tables/organizations.js.map +1 -1
  166. package/dist/db/tables/projects.js +2 -2
  167. package/dist/db/tables/projects.js.map +1 -1
  168. package/dist/db/tables/requestUsage.d.ts +121 -0
  169. package/dist/db/tables/requestUsage.d.ts.map +1 -0
  170. package/dist/db/tables/requestUsage.js +150 -0
  171. package/dist/db/tables/requestUsage.js.map +1 -0
  172. package/dist/db/tables/sponsoredTransactions.d.ts +119 -0
  173. package/dist/db/tables/sponsoredTransactions.d.ts.map +1 -1
  174. package/dist/db/tables/sponsoredTransactions.js +155 -2
  175. package/dist/db/tables/sponsoredTransactions.js.map +1 -1
  176. package/dist/db/tables/stripeCustomers.d.ts +81 -0
  177. package/dist/db/tables/stripeCustomers.d.ts.map +1 -0
  178. package/dist/db/tables/stripeCustomers.js +120 -0
  179. package/dist/db/tables/stripeCustomers.js.map +1 -0
  180. package/dist/db/tables/users.js +2 -2
  181. package/dist/db/tables/users.js.map +1 -1
  182. package/dist/handlers/internal/sponsorship.d.ts +5 -2
  183. package/dist/handlers/internal/sponsorship.d.ts.map +1 -1
  184. package/dist/handlers/internal/sponsorship.js +19 -5
  185. package/dist/handlers/internal/sponsorship.js.map +1 -1
  186. package/dist/handlers/internal/utils.d.ts +10 -3
  187. package/dist/handlers/internal/utils.d.ts.map +1 -1
  188. package/dist/handlers/internal/utils.js +14 -6
  189. package/dist/handlers/internal/utils.js.map +1 -1
  190. package/dist/index.d.ts +1 -0
  191. package/dist/index.d.ts.map +1 -1
  192. package/dist/index.js +1 -0
  193. package/dist/index.js.map +1 -1
  194. package/dist/internal/Auth.d.ts +18 -4
  195. package/dist/internal/Auth.d.ts.map +1 -1
  196. package/dist/internal/Auth.js +149 -77
  197. package/dist/internal/Auth.js.map +1 -1
  198. package/dist/internal/Cache.d.ts.map +1 -1
  199. package/dist/internal/Cache.js +4 -1
  200. package/dist/internal/Cache.js.map +1 -1
  201. package/dist/internal/EdgeCache.d.ts +10 -0
  202. package/dist/internal/EdgeCache.d.ts.map +1 -1
  203. package/dist/internal/EdgeCache.js +39 -8
  204. package/dist/internal/EdgeCache.js.map +1 -1
  205. package/dist/internal/Fees.d.ts +27 -0
  206. package/dist/internal/Fees.d.ts.map +1 -0
  207. package/dist/internal/Fees.js +48 -0
  208. package/dist/internal/Fees.js.map +1 -0
  209. package/dist/internal/FundingRoutes.d.ts +915 -0
  210. package/dist/internal/FundingRoutes.d.ts.map +1 -0
  211. package/dist/internal/FundingRoutes.js +625 -0
  212. package/dist/internal/FundingRoutes.js.map +1 -0
  213. package/dist/internal/Id.d.ts +15 -0
  214. package/dist/internal/Id.d.ts.map +1 -0
  215. package/dist/internal/Id.js +22 -0
  216. package/dist/internal/Id.js.map +1 -0
  217. package/dist/internal/Log.d.ts +2 -0
  218. package/dist/internal/Log.d.ts.map +1 -1
  219. package/dist/internal/Log.js +3 -0
  220. package/dist/internal/Log.js.map +1 -1
  221. package/dist/internal/OpenApi.d.ts +10 -1
  222. package/dist/internal/OpenApi.d.ts.map +1 -1
  223. package/dist/internal/OpenApi.js +8 -1
  224. package/dist/internal/OpenApi.js.map +1 -1
  225. package/dist/internal/RateLimit.d.ts +25 -0
  226. package/dist/internal/RateLimit.d.ts.map +1 -1
  227. package/dist/internal/RateLimit.js +51 -0
  228. package/dist/internal/RateLimit.js.map +1 -1
  229. package/dist/internal/Response.d.ts +1 -1
  230. package/dist/internal/Response.d.ts.map +1 -1
  231. package/dist/internal/Schema.d.ts +8 -0
  232. package/dist/internal/Schema.d.ts.map +1 -1
  233. package/dist/internal/Schema.js +7 -0
  234. package/dist/internal/Schema.js.map +1 -1
  235. package/dist/internal/Webhooks.d.ts.map +1 -1
  236. package/dist/internal/Webhooks.js +3 -3
  237. package/dist/internal/Webhooks.js.map +1 -1
  238. package/package.json +8 -7
  239. package/src/ApiKey.ts +9 -2
  240. package/src/ApiKeys.test.ts +51 -0
  241. package/src/ApiKeys.ts +50 -1
  242. package/src/App.test.ts +33 -86718
  243. package/src/App.ts +26 -8
  244. package/src/Client.test-d.ts +353 -2
  245. package/src/Scope.ts +16 -3
  246. package/src/admin/apps/scopes.test.ts +6 -0
  247. package/src/admin/apps/scopes.ts +3 -0
  248. package/src/admin/ui/src/components/Page.tsx +2 -3
  249. package/src/admin/ui/src/routes/__root.tsx +2 -2
  250. package/src/admin/ui/src/routes/api-keys.tsx +2 -2
  251. package/src/admin/ui.generated.ts +13 -13
  252. package/src/analytics/Analytics.test.ts +527 -0
  253. package/src/analytics/Analytics.ts +318 -0
  254. package/src/analytics/tables/requestEvents.ts +523 -0
  255. package/src/apps/composition.test.ts +26 -13
  256. package/src/apps/data/App.test.ts +72 -0
  257. package/src/apps/data/App.ts +37 -0
  258. package/src/apps/data/FundingRouteProviders.test.ts +281 -0
  259. package/src/apps/data/FundingRouteProviders.ts +459 -0
  260. package/src/apps/data/index.ts +1 -0
  261. package/src/apps/data/routes/funding.test.ts +314 -0
  262. package/src/apps/data/routes/funding.ts +698 -0
  263. package/src/apps/data/routes/receipts.ts +2 -9
  264. package/src/apps/data/routes/rpc.test.ts +78 -2
  265. package/src/apps/data/routes/rpc.ts +31 -1
  266. package/src/apps/data/routes/webhooks.test.ts +1 -1
  267. package/src/apps/data/routes/webhooks.ts +11 -8
  268. package/src/apps/docs/App.ts +30 -101
  269. package/src/apps/docs/reference.ts +132 -0
  270. package/src/apps/index.ts +3 -2
  271. package/src/apps/{platform → management}/App.ts +56 -17
  272. package/src/apps/management/Billing.test.ts +530 -0
  273. package/src/apps/management/Billing.ts +682 -0
  274. package/src/apps/management/index.ts +2 -0
  275. package/src/apps/{platform → management}/routes/api-keys.test.ts +172 -9
  276. package/src/apps/{platform → management}/routes/api-keys.ts +137 -21
  277. package/src/apps/management/routes/billing.test.ts +1100 -0
  278. package/src/apps/management/routes/billing.ts +966 -0
  279. package/src/apps/{platform → management}/routes/invitations.test.ts +55 -7
  280. package/src/apps/{platform → management}/routes/invitations.ts +69 -1
  281. package/src/apps/management/routes/me.test.ts +351 -0
  282. package/src/apps/{platform → management}/routes/orgs.ts +26 -4
  283. package/src/apps/management/routes/scopes.test.ts +29 -0
  284. package/src/apps/management/routes/scopes.ts +85 -0
  285. package/src/apps/management/routes/usage.test.ts +422 -0
  286. package/src/apps/management/routes/usage.ts +527 -0
  287. package/src/apps/mcp.test.ts +206 -0
  288. package/src/apps/mcp.ts +250 -0
  289. package/src/apps/relay/App.test.ts +457 -8
  290. package/src/apps/relay/App.ts +120 -12
  291. package/src/apps/relay/Sponsorships.test.ts +1 -1
  292. package/src/apps/relay/Sponsorships.ts +2 -1
  293. package/src/cli/Cli.test.ts +25 -2
  294. package/src/cli/Cli.ts +17 -2
  295. package/src/cli/commands/admin.test.ts +83 -0
  296. package/src/cli/commands/admin.ts +89 -1
  297. package/src/db/Db.ts +137 -0
  298. package/src/db/Schema.ts +104 -2
  299. package/src/db/tables/billingSettings.test.ts +87 -0
  300. package/src/db/tables/billingSettings.ts +108 -0
  301. package/src/db/tables/invitations.ts +2 -2
  302. package/src/db/tables/organizations.test.ts +1 -1
  303. package/src/db/tables/organizations.ts +15 -5
  304. package/src/db/tables/projects.ts +2 -2
  305. package/src/db/tables/requestUsage.ts +231 -0
  306. package/src/db/tables/sponsoredTransactions.test.ts +108 -1
  307. package/src/db/tables/sponsoredTransactions.ts +230 -2
  308. package/src/db/tables/stripeCustomers.test.ts +109 -0
  309. package/src/db/tables/stripeCustomers.ts +162 -0
  310. package/src/db/tables/users.ts +2 -2
  311. package/src/handlers/internal/sponsorship.ts +34 -7
  312. package/src/handlers/internal/utils.ts +19 -7
  313. package/src/index.ts +1 -0
  314. package/src/internal/Auth.test.ts +175 -25
  315. package/src/internal/Auth.ts +176 -87
  316. package/src/internal/Cache.ts +5 -1
  317. package/src/internal/EdgeCache.test.ts +27 -4
  318. package/src/internal/EdgeCache.ts +47 -9
  319. package/src/internal/Fees.test.ts +32 -0
  320. package/src/internal/Fees.ts +51 -0
  321. package/src/internal/FundingRoutes.test.ts +213 -0
  322. package/src/internal/FundingRoutes.ts +898 -0
  323. package/src/internal/Id.test.ts +17 -0
  324. package/src/internal/Id.ts +24 -0
  325. package/src/internal/Log.test.ts +1 -0
  326. package/src/internal/Log.ts +5 -0
  327. package/src/internal/OpenApi.ts +12 -1
  328. package/src/internal/RateLimit.test.ts +84 -0
  329. package/src/internal/RateLimit.ts +70 -0
  330. package/src/internal/Response.ts +1 -1
  331. package/src/internal/Schema.ts +8 -0
  332. package/src/internal/Webhooks.test.ts +3 -3
  333. package/src/internal/Webhooks.ts +3 -3
  334. package/dist/apps/platform/App.d.ts.map +0 -1
  335. package/dist/apps/platform/App.js.map +0 -1
  336. package/dist/apps/platform/index.d.ts +0 -2
  337. package/dist/apps/platform/index.d.ts.map +0 -1
  338. package/dist/apps/platform/index.js +0 -2
  339. package/dist/apps/platform/index.js.map +0 -1
  340. package/dist/apps/platform/routes/api-keys.d.ts.map +0 -1
  341. package/dist/apps/platform/routes/api-keys.js.map +0 -1
  342. package/dist/apps/platform/routes/invitations.d.ts.map +0 -1
  343. package/dist/apps/platform/routes/invitations.js.map +0 -1
  344. package/dist/apps/platform/routes/me.d.ts.map +0 -1
  345. package/dist/apps/platform/routes/me.js.map +0 -1
  346. package/dist/apps/platform/routes/members.d.ts.map +0 -1
  347. package/dist/apps/platform/routes/members.js.map +0 -1
  348. package/dist/apps/platform/routes/orgs.d.ts.map +0 -1
  349. package/dist/apps/platform/routes/orgs.js.map +0 -1
  350. package/dist/apps/platform/routes/projects.js.map +0 -1
  351. package/src/apps/platform/index.ts +0 -1
  352. package/src/apps/platform/routes/me.test.ts +0 -121
  353. /package/dist/apps/{platform → management}/routes/me.js +0 -0
  354. /package/dist/apps/{platform → management}/routes/members.d.ts +0 -0
  355. /package/dist/apps/{platform → management}/routes/members.js +0 -0
  356. /package/dist/apps/{platform → management}/routes/projects.js +0 -0
  357. /package/src/apps/{platform → management}/routes/me.ts +0 -0
  358. /package/src/apps/{platform → management}/routes/members.test.ts +0 -0
  359. /package/src/apps/{platform → management}/routes/members.ts +0 -0
  360. /package/src/apps/{platform → management}/routes/orgs.test.ts +0 -0
  361. /package/src/apps/{platform → management}/routes/projects.test.ts +0 -0
  362. /package/src/apps/{platform → management}/routes/projects.ts +0 -0
@@ -0,0 +1,898 @@
1
+ /** Tempo mainnet as a CAIP-2 chain reference. */
2
+ const destinationChain = {
3
+ addressFormat: 'evm',
4
+ id: 'eip155:4217',
5
+ kind: 'evm',
6
+ name: 'Tempo',
7
+ } as const
8
+
9
+ /** Tempo token used when the caller omits `destinationToken`. */
10
+ const defaultDestinationToken = 'usdce'
11
+
12
+ /** Source chains accepted by the funding route inventory. */
13
+ const sourceChains = [
14
+ {
15
+ addressFormat: 'evm',
16
+ aliases: ['ethereum', 'eth', 'eip155:1'],
17
+ id: 'eip155:1',
18
+ kind: 'evm',
19
+ name: 'Ethereum',
20
+ providerIds: {
21
+ across: '1',
22
+ bridge: 'ethereum',
23
+ bungee: '1',
24
+ lifi: '1',
25
+ relay: '1',
26
+ },
27
+ slug: 'ethereum',
28
+ tokens: [
29
+ {
30
+ address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
31
+ coingeckoId: 'usd-coin',
32
+ decimals: 6,
33
+ name: 'USD Coin',
34
+ standard: 'ERC-20',
35
+ symbol: 'USDC',
36
+ },
37
+ {
38
+ address: '0xdac17f958d2ee523a2206206994597c13d831ec7',
39
+ coingeckoId: 'tether',
40
+ decimals: 6,
41
+ name: 'Tether USD',
42
+ standard: 'ERC-20',
43
+ symbol: 'USDT',
44
+ },
45
+ {
46
+ address: '0x6c3ea9036406852006290770bedfcaba0e23a0e8',
47
+ coingeckoId: 'paypal-usd',
48
+ decimals: 6,
49
+ name: 'PayPal USD',
50
+ standard: 'ERC-20',
51
+ symbol: 'PYUSD',
52
+ },
53
+ {
54
+ address: '0x1abaea1f7c830bd89acc67ec4af516284b1bc33c',
55
+ coingeckoId: 'euro-coin',
56
+ decimals: 6,
57
+ name: 'Euro Coin',
58
+ standard: 'ERC-20',
59
+ symbol: 'EURC',
60
+ },
61
+ {
62
+ address: '0x6b175474e89094c44da98b954eedeac495271d0f',
63
+ coingeckoId: 'dai',
64
+ decimals: 18,
65
+ name: 'Dai Stablecoin',
66
+ standard: 'ERC-20',
67
+ symbol: 'DAI',
68
+ },
69
+ ],
70
+ },
71
+ {
72
+ addressFormat: 'evm',
73
+ aliases: ['base', 'eip155:8453'],
74
+ id: 'eip155:8453',
75
+ kind: 'evm',
76
+ name: 'Base',
77
+ providerIds: {
78
+ across: '8453',
79
+ bridge: 'base',
80
+ bungee: '8453',
81
+ lifi: '8453',
82
+ relay: '8453',
83
+ },
84
+ slug: 'base',
85
+ tokens: [
86
+ {
87
+ address: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
88
+ coingeckoId: 'usd-coin',
89
+ decimals: 6,
90
+ name: 'USD Coin',
91
+ standard: 'ERC-20',
92
+ symbol: 'USDC',
93
+ },
94
+ {
95
+ address: '0xfde4c96c8593536e31f229ea8f37b2ada2699bb2',
96
+ coingeckoId: 'tether',
97
+ decimals: 6,
98
+ name: 'Tether USD',
99
+ standard: 'ERC-20',
100
+ symbol: 'USDT',
101
+ },
102
+ {
103
+ address: '0x60a3e35cc302bfa44cb288bc5a4f316fdb1adb42',
104
+ coingeckoId: 'euro-coin',
105
+ decimals: 6,
106
+ name: 'Euro Coin',
107
+ standard: 'ERC-20',
108
+ symbol: 'EURC',
109
+ },
110
+ ],
111
+ },
112
+ {
113
+ addressFormat: 'evm',
114
+ aliases: ['bnb', 'bsc', 'eip155:56'],
115
+ id: 'eip155:56',
116
+ kind: 'evm',
117
+ name: 'BNB Smart Chain',
118
+ providerIds: {
119
+ across: '56',
120
+ bungee: '56',
121
+ lifi: '56',
122
+ relay: '56',
123
+ },
124
+ slug: 'bnb',
125
+ tokens: [
126
+ {
127
+ address: '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d',
128
+ coingeckoId: 'usd-coin',
129
+ decimals: 18,
130
+ name: 'Binance-Peg USD Coin',
131
+ standard: 'BEP-20',
132
+ symbol: 'USDC',
133
+ },
134
+ {
135
+ address: '0x55d398326f99059ff775485246999027b3197955',
136
+ coingeckoId: 'tether',
137
+ decimals: 18,
138
+ name: 'Tether USD',
139
+ standard: 'BEP-20',
140
+ symbol: 'USDT',
141
+ },
142
+ ],
143
+ },
144
+ {
145
+ addressFormat: 'solana',
146
+ aliases: ['solana', 'solana:mainnet'],
147
+ id: 'solana:mainnet',
148
+ kind: 'solana',
149
+ name: 'Solana',
150
+ providerIds: {
151
+ bridge: 'solana',
152
+ relay: 'solana',
153
+ },
154
+ slug: 'solana',
155
+ tokens: [
156
+ {
157
+ address: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
158
+ coingeckoId: 'usd-coin',
159
+ decimals: 6,
160
+ name: 'USD Coin',
161
+ standard: 'SPL',
162
+ symbol: 'USDC',
163
+ },
164
+ {
165
+ address: 'Es9vMFrzaCERmJfrF4H2FYD4KCo3LwC1uix9YEaQ8t1v',
166
+ coingeckoId: 'tether',
167
+ decimals: 6,
168
+ name: 'Tether USD',
169
+ standard: 'SPL',
170
+ symbol: 'USDT',
171
+ },
172
+ ],
173
+ },
174
+ {
175
+ addressFormat: 'tron',
176
+ aliases: ['tron', 'tron:mainnet'],
177
+ id: 'tron:mainnet',
178
+ kind: 'tron',
179
+ name: 'Tron',
180
+ providerIds: {
181
+ bridge: 'tron',
182
+ relay: 'tron',
183
+ },
184
+ slug: 'tron',
185
+ tokens: [
186
+ {
187
+ address: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',
188
+ coingeckoId: 'tether',
189
+ decimals: 6,
190
+ name: 'Tether USD',
191
+ standard: 'TRC-20',
192
+ symbol: 'USDT',
193
+ },
194
+ ],
195
+ },
196
+ ] as const
197
+
198
+ /** Tempo destination tokens supported by the initial funding route inventory. */
199
+ const destinationTokens = [
200
+ {
201
+ address: '0x20c0000000000000000000000000000000000000',
202
+ decimals: 6,
203
+ name: 'pathUSD',
204
+ slug: 'pathusd',
205
+ standard: 'TIP-20',
206
+ symbol: 'pathUSD',
207
+ },
208
+ {
209
+ address: '0x20c000000000000000000000b9537d11c60e8b50',
210
+ decimals: 6,
211
+ name: 'Bridged USDC (Stargate)',
212
+ slug: 'usdce',
213
+ standard: 'TIP-20',
214
+ symbol: 'USDC.e',
215
+ },
216
+ {
217
+ address: '0x20c0000000000000000000001621e21f71cf12fb',
218
+ decimals: 6,
219
+ name: 'Bridged EURC',
220
+ slug: 'eurce',
221
+ standard: 'TIP-20',
222
+ symbol: 'EURC.e',
223
+ },
224
+ {
225
+ address: '0x20c00000000000000000000014f22ca97301eb73',
226
+ decimals: 6,
227
+ name: 'USDT0',
228
+ slug: 'usdt0',
229
+ standard: 'TIP-20',
230
+ symbol: 'USDT0',
231
+ },
232
+ {
233
+ address: '0x20c0000000000000000000003554d28269e0f3c2',
234
+ decimals: 6,
235
+ name: 'frxUSD',
236
+ slug: 'frxusd',
237
+ standard: 'TIP-20',
238
+ symbol: 'frxUSD',
239
+ },
240
+ ] as const
241
+
242
+ /** Providers exposed by the generic provider catalog. */
243
+ const providers = [
244
+ {
245
+ capabilities: ['fundingRoutes'],
246
+ id: 'across',
247
+ kind: 'intentBridge',
248
+ name: 'Across',
249
+ requiresApiKey: true,
250
+ status: 'inventoryOnly',
251
+ },
252
+ {
253
+ capabilities: ['fundingRoutes'],
254
+ id: 'relay',
255
+ kind: 'solverNetwork',
256
+ name: 'Relay',
257
+ requiresApiKey: false,
258
+ status: 'inventoryOnly',
259
+ },
260
+ {
261
+ capabilities: ['fundingRoutes'],
262
+ id: 'bridge',
263
+ kind: 'enterpriseTransfer',
264
+ name: 'Bridge.xyz',
265
+ requiresApiKey: true,
266
+ status: 'inventoryOnly',
267
+ },
268
+ {
269
+ capabilities: ['fundingRoutes'],
270
+ id: 'bungee',
271
+ kind: 'aggregator',
272
+ name: 'Bungee',
273
+ requiresApiKey: false,
274
+ status: 'inventoryOnly',
275
+ },
276
+ {
277
+ capabilities: ['fundingRoutes'],
278
+ id: 'lifi',
279
+ kind: 'aggregator',
280
+ name: 'LI.FI',
281
+ requiresApiKey: true,
282
+ status: 'planned',
283
+ },
284
+ ] as const
285
+
286
+ type TokenInput = (typeof sourceChains)[number]['tokens'][number]
287
+ type DestinationTokenInput = (typeof destinationTokens)[number]
288
+ type ProviderInput = (typeof providers)[number]
289
+ type SourceChainInput = (typeof sourceChains)[number]
290
+
291
+ /** Provider ids accepted by the funding route inventory. */
292
+ export type ProviderId = ProviderInput['id']
293
+
294
+ /** Provider-specific route status for the requested amount. */
295
+ export type RouteStatus = 'available' | 'thin' | 'unknown' | 'unavailable' | 'error'
296
+
297
+ /** Machine-readable route quality tier. */
298
+ export type QualityTier = 'liquid' | 'thin' | 'unknown' | 'unavailable' | 'error'
299
+
300
+ /** Response expansions accepted by funding route discovery. */
301
+ export type Include = 'quotes'
302
+
303
+ /** Normalized chain reference passed to provider adapters. */
304
+ export type ChainRef = ReturnType<typeof formatChain> | typeof destinationChain
305
+
306
+ /** Normalized token amount passed to provider adapters. */
307
+ export type TokenAmount = ReturnType<typeof resolveSourceAmount>
308
+
309
+ /** Normalized token reference passed to provider adapters. */
310
+ export type TokenRef = ReturnType<typeof formatDestinationToken> | ReturnType<typeof formatSourceToken>
311
+
312
+ /** A normalized funding route candidate returned by route discovery. */
313
+ export type RouteCandidate = ReturnType<typeof formatRouteCandidate>
314
+
315
+ /** Cache policy for a single funding route discovery request. */
316
+ export type CachePolicy = {
317
+ /** Whether provider adapters should bypass their own quote or inventory caches. */
318
+ bypass: boolean
319
+ }
320
+
321
+ /** Normalized caller request passed to provider adapters. */
322
+ export type QuoteRequest = {
323
+ /** Optional Tempo destination token symbol, address, or token key. */
324
+ destinationToken?: string | undefined
325
+ /** Response expansions requested by the caller. */
326
+ include: readonly Include[]
327
+ /** Maximum number of route candidates requested by the caller. */
328
+ limit: number
329
+ /** Optional provider id filter. */
330
+ provider?: string | undefined
331
+ /** Source amount as supplied by the caller. */
332
+ sourceAmount: string
333
+ /** Unit used by {@link sourceAmount}. */
334
+ sourceAmountUnits: SourceAmountUnits
335
+ /** Chain alias or CAIP-2 source chain id. */
336
+ sourceChain: string
337
+ /** Source token symbol, contract address, mint, or Tempo token key. */
338
+ sourceToken: string
339
+ }
340
+
341
+ /** Input passed to a provider adapter for one static route candidate probe. */
342
+ export type QuoteProbeInput = {
343
+ /** Cache policy for provider-side inventory, quote, and liquidity lookups. */
344
+ cache: CachePolicy
345
+ /** Destination chain, always Tempo mainnet in V1. */
346
+ destinationChain: ChainRef
347
+ /** Tempo token expected from this route. */
348
+ destinationToken: TokenRef
349
+ /** Response expansions requested by the caller. */
350
+ include: readonly Include[]
351
+ /** Normalized caller request that produced this route candidate. */
352
+ request: QuoteRequest
353
+ /** Static candidate being enriched with live provider information. */
354
+ route: RouteCandidate
355
+ /** Source amount in base units and display form. */
356
+ sourceAmount: TokenAmount
357
+ /** Chain where the caller currently holds funds. */
358
+ sourceChain: ChainRef
359
+ /** Token the caller currently holds. */
360
+ sourceToken: TokenRef
361
+ }
362
+
363
+ /** Provider-specific source amount limits, expressed in source base units. */
364
+ export type QuoteProbeLimits = {
365
+ /** Provider-reported instant source amount capacity. */
366
+ instantSourceAmount?: string | null | undefined
367
+ /** Provider-reported maximum source amount. */
368
+ maxSourceAmount?: string | null | undefined
369
+ /** Provider-reported minimum source amount. */
370
+ minSourceAmount?: string | null | undefined
371
+ }
372
+
373
+ /** Quote probe data returned by a provider adapter. */
374
+ export type QuoteProbeResult = {
375
+ /** Stable route error code when status is `error`. */
376
+ errorCode?: string | null | undefined
377
+ /** Provider quote expiry timestamp. */
378
+ expiresAt?: string | null | undefined
379
+ /** Provider-reported source amount limits. */
380
+ limits?: QuoteProbeLimits | null | undefined
381
+ /** Slippage-adjusted minimum destination amount in base units. */
382
+ minimumOutputAmount?: string | null | undefined
383
+ /** Expected destination amount in base units. */
384
+ outputAmount?: string | null | undefined
385
+ /** Expected destination amount rendered with destination token decimals. */
386
+ outputAmountFormatted?: string | null | undefined
387
+ /** Timestamp for the live quote or route probe. */
388
+ sampledAt: string
389
+ /** Provider-specific route status for the requested amount. */
390
+ status: RouteStatus
391
+ /** Provider-backed route quality metadata. */
392
+ quality?: {
393
+ /** Available USD capacity, when available. */
394
+ availableVolumeUsd?: string | null | undefined
395
+ /** Estimated settlement time in seconds, when known. */
396
+ estimatedSeconds?: number | null | undefined
397
+ /** Estimated fee in basis points, when known. */
398
+ feeBps?: number | null | undefined
399
+ /** 24h routed volume in USD, when available. */
400
+ historicalVolumeUsd24h?: string | null | undefined
401
+ /** Instant USD capacity, when available. */
402
+ instantVolumeUsd?: string | null | undefined
403
+ /** Where the live liquidity or support signal came from. */
404
+ liquiditySource: string
405
+ /** Explainable route score from 0 to 100, when enough signals are available. */
406
+ score?: number | null | undefined
407
+ /** Provider-specific quote source or endpoint detail. */
408
+ sourceDetail?: string | null | undefined
409
+ /** Machine-readable route quality tier. */
410
+ tier?: QualityTier | undefined
411
+ }
412
+ }
413
+
414
+ /** Adapter used to enrich a static route candidate with live provider information. */
415
+ export type ProviderAdapter = {
416
+ /** Probes provider-backed quote information for one static candidate. */
417
+ probeQuote(input: QuoteProbeInput, signal: AbortSignal): Promise<QuoteProbeResult>
418
+ }
419
+
420
+ /** Provider adapter registry, keyed by provider id. Missing adapters leave routes static. */
421
+ export type ProviderAdapters = Partial<Record<ProviderId, ProviderAdapter>>
422
+
423
+ /** Static provider support rows used until live quote adapters are configured. */
424
+ const inventory: readonly InventoryEntry[] = [
425
+ { destinationToken: 'usdce', provider: 'across', sourceChains: ['ethereum', 'base', 'bnb'], sourceTokens: ['USDC'] }, // prettier-ignore
426
+ { destinationToken: 'usdce', provider: 'relay', sourceChains: ['ethereum', 'base', 'bnb'], sourceTokens: ['USDC', 'USDT'] }, // prettier-ignore
427
+ { destinationToken: 'usdce', provider: 'bridge', sourceChains: ['ethereum', 'base', 'solana'], sourceTokens: ['USDC'] }, // prettier-ignore
428
+ { destinationToken: 'usdce', provider: 'bridge', sourceChains: ['ethereum', 'solana', 'tron'], sourceTokens: ['USDT'] }, // prettier-ignore
429
+ { destinationToken: 'usdce', provider: 'bungee', sourceChains: ['ethereum', 'base', 'bnb'], sourceTokens: ['USDC'] }, // prettier-ignore
430
+ ]
431
+
432
+ type InventoryEntry = {
433
+ destinationToken: string
434
+ provider: ProviderInput['id']
435
+ sourceChains: readonly string[]
436
+ sourceTokens: readonly string[]
437
+ }
438
+
439
+ const defaultAdapterTimeoutMs = 750
440
+ const includes = ['quotes'] as const
441
+
442
+ /** Lists normalized chains and source tokens that can fund Tempo. */
443
+ export function listChains() {
444
+ return sourceChains.map((chain) => ({
445
+ ...formatChain(chain),
446
+ tokens: chain.tokens.map((token) => formatSourceToken(chain, token)),
447
+ }))
448
+ }
449
+
450
+ /** Lists providers, optionally filtered by one provider capability. */
451
+ export function listProviders(options: listProviders.Options = {}) {
452
+ return providers
453
+ .filter((provider) =>
454
+ options.capability === undefined ? true : provider.capabilities.includes(options.capability),
455
+ )
456
+ .map((provider) => ({
457
+ ...formatProvider(provider),
458
+ status: options.adapters?.[provider.id] ? ('configured' as const) : provider.status,
459
+ }))
460
+ }
461
+
462
+ export declare namespace listProviders {
463
+ /** Options for listing providers. */
464
+ type Options = {
465
+ /** Provider adapters configured for this deployment. */
466
+ adapters?: ProviderAdapters | undefined
467
+ /** Provider capability to require. */
468
+ capability?: Capability | undefined
469
+ }
470
+ }
471
+
472
+ /** Parses the comma-separated `include` query parameter. */
473
+ export function parseInclude(input: string | undefined) {
474
+ if (input === undefined || input.trim() === '') return []
475
+ const parsed = input.split(',').map((part) => part.trim()).filter(Boolean)
476
+ for (const include of parsed)
477
+ if (!(includes as readonly string[]).includes(include)) throw new UnsupportedIncludeError()
478
+ return [...new Set(parsed)] as readonly Include[]
479
+ }
480
+
481
+ /** Lists funding route candidates, enriching static inventory when adapters are configured. */
482
+ export async function listRoutes(options: listRoutes.Options) {
483
+ const routes = listStaticRoutes(options)
484
+ const adapterEntries = Object.entries(options.adapters ?? {})
485
+ if (adapterEntries.length === 0) return routes
486
+
487
+ return Promise.all(
488
+ routes.map((route) =>
489
+ enrichRoute(route, {
490
+ adapters: options.adapters ?? {},
491
+ cache: options.cache ?? { bypass: false },
492
+ include: options.include ?? [],
493
+ request: {
494
+ destinationToken: options.destinationToken,
495
+ include: options.include ?? [],
496
+ limit: options.limit,
497
+ provider: options.provider,
498
+ sourceAmount: options.sourceAmount,
499
+ sourceAmountUnits: options.sourceAmountUnits,
500
+ sourceChain: options.sourceChain,
501
+ sourceToken: options.sourceToken,
502
+ },
503
+ timeoutMs: options.adapterTimeoutMs ?? defaultAdapterTimeoutMs,
504
+ }),
505
+ ),
506
+ )
507
+ }
508
+
509
+ /** Lists static funding route candidates for a normalized caller request. */
510
+ export function listStaticRoutes(options: listStaticRoutes.Options) {
511
+ const sourceChain = resolveSourceChain(options.sourceChain)
512
+ const sourceToken = resolveSourceToken(sourceChain, options.sourceToken)
513
+ const destinationToken = resolveDestinationToken(options.destinationToken)
514
+ const provider = options.provider ? resolveProvider(options.provider) : undefined
515
+
516
+ if (!sourceToken) {
517
+ validateSourceAmountSyntax(options.sourceAmount, options.sourceAmountUnits)
518
+ return []
519
+ }
520
+
521
+ const sourceAmount = resolveSourceAmount({
522
+ amount: options.sourceAmount,
523
+ token: sourceToken,
524
+ units: options.sourceAmountUnits,
525
+ })
526
+
527
+ return inventory
528
+ .filter((entry) => entry.sourceChains.includes(sourceChain.slug))
529
+ .filter((entry) => entry.sourceTokens.includes(sourceToken.symbol))
530
+ .filter((entry) => entry.destinationToken === destinationToken.slug)
531
+ .filter((entry) => provider === undefined || entry.provider === provider.id)
532
+ .slice(0, options.limit)
533
+ .map((entry) =>
534
+ formatRouteCandidate({
535
+ destinationToken,
536
+ provider: providers.find((candidate) => candidate.id === entry.provider)!,
537
+ sourceAmount,
538
+ sourceChain,
539
+ sourceToken,
540
+ }),
541
+ )
542
+ }
543
+
544
+ export declare namespace listStaticRoutes {
545
+ /** Options for listing static funding routes. */
546
+ type Options = {
547
+ /** Optional Tempo destination token symbol, address, or token key. */
548
+ destinationToken?: string | undefined
549
+ /** Maximum number of route candidates to return. */
550
+ limit: number
551
+ /** Optional provider id filter. */
552
+ provider?: string | undefined
553
+ /** Source amount as supplied by the caller. */
554
+ sourceAmount: string
555
+ /** Unit used by {@link sourceAmount}. */
556
+ sourceAmountUnits: SourceAmountUnits
557
+ /** Chain alias or CAIP-2 source chain id. */
558
+ sourceChain: string
559
+ /** Source token symbol, contract address, mint, or Tempo token key. */
560
+ sourceToken: string
561
+ }
562
+ }
563
+
564
+ export declare namespace listRoutes {
565
+ /** Options for listing funding routes. */
566
+ type Options = listStaticRoutes.Options & {
567
+ /** Provider adapters used to enrich static inventory with live data. */
568
+ adapters?: ProviderAdapters | undefined
569
+ /** Per-provider quote timeout in milliseconds. */
570
+ adapterTimeoutMs?: number | undefined
571
+ /** Cache policy for provider-side inventory, quote, and liquidity lookups. */
572
+ cache?: CachePolicy | undefined
573
+ /** Response expansions requested by the caller. */
574
+ include?: readonly Include[] | undefined
575
+ }
576
+ }
577
+
578
+ /** Provider capability identifiers accepted by the generic provider catalog. */
579
+ export type Capability = 'fundingRoutes'
580
+
581
+ /** Source amount unit accepted by the funding route request. */
582
+ export type SourceAmountUnits = 'baseUnits' | 'decimal'
583
+
584
+ function tokenKey(chain: { id: string }, token: TokenInput | DestinationTokenInput) {
585
+ const standard =
586
+ token.standard === 'SPL' ? 'spl' : token.standard === 'TRC-20' ? 'trc20' : 'erc20'
587
+ return `${chain.id}/${standard}:${token.address}`
588
+ }
589
+
590
+ function decimalFromBaseUnits(baseUnits: string, decimals: number) {
591
+ const padded = baseUnits.padStart(decimals + 1, '0')
592
+ const whole = decimals === 0 ? padded : padded.slice(0, -decimals)
593
+ const fraction = decimals === 0 ? '' : padded.slice(-decimals).replace(/0+$/, '')
594
+ return fraction ? `${whole}.${fraction}` : whole
595
+ }
596
+
597
+ async function enrichRoute(
598
+ route: RouteCandidate,
599
+ options: {
600
+ adapters: ProviderAdapters
601
+ cache: CachePolicy
602
+ include: readonly Include[]
603
+ request: QuoteRequest
604
+ timeoutMs: number
605
+ },
606
+ ) {
607
+ const adapter = options.adapters[route.provider.id as ProviderId]
608
+ if (!adapter) return route
609
+
610
+ try {
611
+ const quote = await quoteWithTimeout(
612
+ adapter,
613
+ {
614
+ cache: options.cache,
615
+ destinationChain: route.destinationChain,
616
+ destinationToken: route.destinationToken,
617
+ include: options.include,
618
+ request: options.request,
619
+ route,
620
+ sourceAmount: route.sourceAmount,
621
+ sourceChain: route.sourceChain,
622
+ sourceToken: route.sourceToken,
623
+ },
624
+ options.timeoutMs,
625
+ )
626
+ return {
627
+ ...route,
628
+ errorCode: quote.errorCode ?? null,
629
+ quality: {
630
+ ...route.quality,
631
+ ...(quote.status === 'error' ? { tier: 'error' as const } : {}),
632
+ ...quote.quality,
633
+ },
634
+ quote: quote.status === 'error' ? null : formatRouteQuote(route, quote),
635
+ status: quote.status,
636
+ }
637
+ } catch (cause) {
638
+ return markRouteError(route, cause instanceof ProviderAdapterTimeoutError ? 'provider_timeout' : 'provider_error') // prettier-ignore
639
+ }
640
+ }
641
+
642
+ function formatChain(chain: SourceChainInput) {
643
+ const { addressFormat, id, kind, name, providerIds } = chain
644
+ return { addressFormat, id, kind, name, providerIds }
645
+ }
646
+
647
+ function formatDestinationToken(token: DestinationTokenInput) {
648
+ return {
649
+ address: token.address,
650
+ decimals: token.decimals,
651
+ metadata: {},
652
+ name: token.name,
653
+ standard: token.standard,
654
+ symbol: token.symbol,
655
+ tokenKey: tokenKey(destinationChain, token),
656
+ verified: true,
657
+ }
658
+ }
659
+
660
+ function formatProvider(provider: ProviderInput) {
661
+ const { id, kind, name, requiresApiKey, status } = provider
662
+ return { capabilities: [...provider.capabilities], id, kind, name, requiresApiKey, status }
663
+ }
664
+
665
+ function formatProviderRef(provider: ProviderInput) {
666
+ const { id, kind, name, requiresApiKey } = provider
667
+ return { id, kind, name, requiresApiKey }
668
+ }
669
+
670
+ function formatRouteCandidate(options: {
671
+ destinationToken: DestinationTokenInput
672
+ provider: ProviderInput
673
+ sourceAmount: ReturnType<typeof resolveSourceAmount>
674
+ sourceChain: SourceChainInput
675
+ sourceToken: TokenInput
676
+ }) {
677
+ return {
678
+ destinationChain,
679
+ destinationToken: formatDestinationToken(options.destinationToken),
680
+ errorCode: null,
681
+ id: [
682
+ options.sourceChain.slug,
683
+ options.sourceToken.symbol.toLowerCase(),
684
+ 'tempo',
685
+ options.destinationToken.slug,
686
+ options.provider.id,
687
+ ].join('-'),
688
+ provider: formatProviderRef(options.provider),
689
+ quality: {
690
+ availableVolumeUsd: null,
691
+ estimatedSeconds: null,
692
+ feeBps: null,
693
+ historicalVolumeUsd24h: null,
694
+ instantVolumeUsd: null,
695
+ liquiditySource: 'staticInventory',
696
+ score: null,
697
+ sourceDetail: null,
698
+ tier: 'unknown',
699
+ },
700
+ quote: null,
701
+ sourceAmount: options.sourceAmount,
702
+ sourceChain: formatChain(options.sourceChain),
703
+ sourceToken: formatSourceToken(options.sourceChain, options.sourceToken),
704
+ status: 'unknown',
705
+ } as const
706
+ }
707
+
708
+ function formatSourceToken(chain: SourceChainInput, token: TokenInput) {
709
+ return {
710
+ address: token.address,
711
+ decimals: token.decimals,
712
+ metadata: { coingeckoId: token.coingeckoId },
713
+ name: token.name,
714
+ standard: token.standard,
715
+ symbol: token.symbol,
716
+ tokenKey: tokenKey(chain, token),
717
+ verified: true,
718
+ }
719
+ }
720
+
721
+ function normalizeInput(value: string) {
722
+ return value.trim().toLowerCase()
723
+ }
724
+
725
+ function parseBaseUnits(value: string) {
726
+ if (!/^\d+$/.test(value) || BigInt(value) <= 0n) throw new InvalidAmountError()
727
+ return BigInt(value).toString()
728
+ }
729
+
730
+ function parseDecimalUnits(value: string, decimals: number) {
731
+ if (!/^\d+(\.\d+)?$/.test(value)) throw new InvalidAmountError()
732
+ const [whole, fraction = ''] = value.split('.')
733
+ if (fraction.length > decimals) throw new InvalidAmountError()
734
+ const baseUnits = BigInt(`${whole}${fraction.padEnd(decimals, '0')}`)
735
+ if (baseUnits <= 0n) throw new InvalidAmountError()
736
+ return baseUnits.toString()
737
+ }
738
+
739
+ function formatRouteQuote(route: RouteCandidate, quote: QuoteProbeResult) {
740
+ return {
741
+ expiresAt: quote.expiresAt ?? null,
742
+ inputAmount: route.sourceAmount.amount,
743
+ limits: quote.limits
744
+ ? {
745
+ instantSourceAmount: quote.limits.instantSourceAmount ?? null,
746
+ maxSourceAmount: quote.limits.maxSourceAmount ?? null,
747
+ minSourceAmount: quote.limits.minSourceAmount ?? null,
748
+ }
749
+ : null,
750
+ minimumOutputAmount: quote.minimumOutputAmount ?? null,
751
+ outputAmount: quote.outputAmount ?? null,
752
+ outputAmountFormatted: quote.outputAmountFormatted ?? null,
753
+ sampledAt: quote.sampledAt,
754
+ } as const
755
+ }
756
+
757
+ function markRouteError(route: RouteCandidate, errorCode: string) {
758
+ return {
759
+ ...route,
760
+ errorCode,
761
+ quality: {
762
+ ...route.quality,
763
+ liquiditySource: 'providerError',
764
+ score: null,
765
+ sourceDetail: null,
766
+ tier: 'error' as const,
767
+ },
768
+ quote: null,
769
+ status: 'error' as const,
770
+ }
771
+ }
772
+
773
+ function quoteWithTimeout(adapter: ProviderAdapter, input: QuoteProbeInput, timeoutMs: number) {
774
+ const controller = new AbortController()
775
+ const timeout = setTimeout(() => controller.abort(), timeoutMs)
776
+ return Promise.race([
777
+ adapter.probeQuote(input, controller.signal),
778
+ new Promise<never>((_, reject) => {
779
+ if (controller.signal.aborted) {
780
+ reject(new ProviderAdapterTimeoutError())
781
+ return
782
+ }
783
+ controller.signal.addEventListener('abort', () => reject(new ProviderAdapterTimeoutError()), {
784
+ once: true,
785
+ })
786
+ }),
787
+ ]).finally(() => clearTimeout(timeout))
788
+ }
789
+
790
+ function resolveDestinationToken(input: string | undefined) {
791
+ if (input === undefined) return destinationTokens.find((token) => token.slug === defaultDestinationToken)! // prettier-ignore
792
+ const normalized = normalizeInput(input)
793
+ const token = destinationTokens.find(
794
+ (candidate) =>
795
+ candidate.slug === normalized ||
796
+ candidate.symbol.toLowerCase() === normalized ||
797
+ candidate.address === normalized ||
798
+ tokenKey(destinationChain, candidate).toLowerCase() === normalized,
799
+ )
800
+ if (!token) throw new UnsupportedDestinationTokenError()
801
+ return token
802
+ }
803
+
804
+ function resolveProvider(input: string) {
805
+ const provider = providers.find((candidate) => candidate.id === normalizeInput(input))
806
+ if (!provider) throw new UnsupportedProviderError()
807
+ return provider
808
+ }
809
+
810
+ function resolveSourceAmount(options: resolveSourceAmount.Options) {
811
+ const amount =
812
+ options.units === 'baseUnits'
813
+ ? parseBaseUnits(options.amount)
814
+ : parseDecimalUnits(options.amount, options.token.decimals)
815
+ return {
816
+ amount,
817
+ formatted: decimalFromBaseUnits(amount, options.token.decimals),
818
+ usd: null,
819
+ }
820
+ }
821
+
822
+ declare namespace resolveSourceAmount {
823
+ type Options = {
824
+ amount: string
825
+ token: TokenInput
826
+ units: SourceAmountUnits
827
+ }
828
+ }
829
+
830
+ function resolveSourceToken(chain: SourceChainInput, input: string) {
831
+ const trimmed = input.trim()
832
+ const normalized = trimmed.toLowerCase()
833
+ return chain.tokens.find(
834
+ (token) =>
835
+ token.symbol.toLowerCase() === normalized ||
836
+ matchesTokenIdentifier(chain, token.address, trimmed, normalized) ||
837
+ matchesTokenIdentifier(chain, tokenKey(chain, token), trimmed, normalized),
838
+ )
839
+ }
840
+
841
+ function matchesTokenIdentifier(
842
+ chain: SourceChainInput,
843
+ candidate: string,
844
+ trimmed: string,
845
+ normalized: string,
846
+ ) {
847
+ return chain.kind === 'evm' ? candidate.toLowerCase() === normalized : candidate === trimmed
848
+ }
849
+
850
+ function resolveSourceChain(input: string) {
851
+ const normalized = normalizeInput(input)
852
+ const chain = sourceChains.find(
853
+ (candidate) =>
854
+ candidate.id === normalized || (candidate.aliases as readonly string[]).includes(normalized),
855
+ )
856
+ if (!chain) throw new UnsupportedSourceChainError()
857
+ return chain
858
+ }
859
+
860
+ function validateSourceAmountSyntax(value: string, units: SourceAmountUnits) {
861
+ if (units === 'baseUnits') {
862
+ parseBaseUnits(value)
863
+ return
864
+ }
865
+ if (!/^\d+(\.\d+)?$/.test(value)) throw new InvalidAmountError()
866
+ const [whole, fraction = ''] = value.split('.')
867
+ if (BigInt(`${whole}${fraction}`) <= 0n) throw new InvalidAmountError()
868
+ }
869
+
870
+ /** Error thrown when the caller supplies an unsupported destination token. */
871
+ export class UnsupportedDestinationTokenError extends Error {
872
+ override name = 'FundingRoutes.UnsupportedDestinationTokenError'
873
+ }
874
+
875
+ /** Error thrown when the caller supplies an invalid source amount. */
876
+ export class InvalidAmountError extends Error {
877
+ override name = 'FundingRoutes.InvalidAmountError'
878
+ }
879
+
880
+ /** Error thrown internally when a provider adapter exceeds its route quote timeout. */
881
+ export class ProviderAdapterTimeoutError extends Error {
882
+ override name = 'FundingRoutes.ProviderAdapterTimeoutError'
883
+ }
884
+
885
+ /** Error thrown when the caller filters to an unknown provider. */
886
+ export class UnsupportedProviderError extends Error {
887
+ override name = 'FundingRoutes.UnsupportedProviderError'
888
+ }
889
+
890
+ /** Error thrown when the caller requests an unsupported include expansion. */
891
+ export class UnsupportedIncludeError extends Error {
892
+ override name = 'FundingRoutes.UnsupportedIncludeError'
893
+ }
894
+
895
+ /** Error thrown when the caller supplies an unsupported source chain. */
896
+ export class UnsupportedSourceChainError extends Error {
897
+ override name = 'FundingRoutes.UnsupportedSourceChainError'
898
+ }