tapimo 0.7.0 → 0.7.2

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 (689) hide show
  1. package/dist/ApiKeys.d.ts +24 -7
  2. package/dist/ApiKeys.d.ts.map +1 -1
  3. package/dist/ApiKeys.js +17 -5
  4. package/dist/ApiKeys.js.map +1 -1
  5. package/dist/App.d.ts +12104 -7861
  6. package/dist/App.d.ts.map +1 -1
  7. package/dist/App.js +191 -128
  8. package/dist/App.js.map +1 -1
  9. package/dist/Assets.d.ts +10 -0
  10. package/dist/Assets.d.ts.map +1 -1
  11. package/dist/Assets.js +17 -4
  12. package/dist/Assets.js.map +1 -1
  13. package/dist/Scope.d.ts +19 -8
  14. package/dist/Scope.d.ts.map +1 -1
  15. package/dist/Scope.js +25 -9
  16. package/dist/Scope.js.map +1 -1
  17. package/dist/Webhooks.d.ts +1 -1
  18. package/dist/admin/App.d.ts +601 -20
  19. package/dist/admin/App.d.ts.map +1 -1
  20. package/dist/admin/App.js +12 -2
  21. package/dist/admin/App.js.map +1 -1
  22. package/dist/admin/apps/api-keys.d.ts +94 -11
  23. package/dist/admin/apps/api-keys.d.ts.map +1 -1
  24. package/dist/admin/apps/api-keys.js +141 -32
  25. package/dist/admin/apps/api-keys.js.map +1 -1
  26. package/dist/admin/apps/earn-vaults.d.ts +1069 -0
  27. package/dist/admin/apps/earn-vaults.d.ts.map +1 -0
  28. package/dist/admin/apps/earn-vaults.js +409 -0
  29. package/dist/admin/apps/earn-vaults.js.map +1 -0
  30. package/dist/admin/apps/verified-tokens.d.ts +166 -166
  31. package/dist/admin/ui.generated.d.ts +1 -1
  32. package/dist/admin/ui.generated.d.ts.map +1 -1
  33. package/dist/admin/ui.generated.js +151 -95
  34. package/dist/admin/ui.generated.js.map +1 -1
  35. package/dist/analytics/Analytics.d.ts +2 -0
  36. package/dist/analytics/Analytics.d.ts.map +1 -1
  37. package/dist/analytics/Analytics.js +18 -2
  38. package/dist/analytics/Analytics.js.map +1 -1
  39. package/dist/analytics/tables/requestEvents.d.ts +22 -1
  40. package/dist/analytics/tables/requestEvents.d.ts.map +1 -1
  41. package/dist/analytics/tables/requestEvents.js +59 -39
  42. package/dist/analytics/tables/requestEvents.js.map +1 -1
  43. package/dist/apps/Zones.d.ts +8335 -0
  44. package/dist/apps/Zones.d.ts.map +1 -0
  45. package/dist/apps/Zones.js +38 -0
  46. package/dist/apps/Zones.js.map +1 -0
  47. package/dist/apps/data/App.d.ts +14377 -10165
  48. package/dist/apps/data/App.d.ts.map +1 -1
  49. package/dist/apps/data/App.js +91 -19
  50. package/dist/apps/data/App.js.map +1 -1
  51. package/dist/apps/data/FxOracle.d.ts +1 -1
  52. package/dist/apps/data/FxOracle.d.ts.map +1 -1
  53. package/dist/apps/data/index.d.ts +0 -1
  54. package/dist/apps/data/index.d.ts.map +1 -1
  55. package/dist/apps/data/index.js +0 -1
  56. package/dist/apps/data/index.js.map +1 -1
  57. package/dist/apps/data/routes/activities.d.ts +32 -32
  58. package/dist/apps/data/routes/activities.d.ts.map +1 -1
  59. package/dist/apps/data/routes/activities.js +130 -65
  60. package/dist/apps/data/routes/activities.js.map +1 -1
  61. package/dist/apps/data/routes/addresses.d.ts +312 -312
  62. package/dist/apps/data/routes/balances.d.ts +18 -18
  63. package/dist/apps/data/routes/balances.js +5 -5
  64. package/dist/apps/data/routes/balances.js.map +1 -1
  65. package/dist/apps/data/routes/coingecko.d.ts +176 -176
  66. package/dist/apps/data/routes/coingecko.d.ts.map +1 -1
  67. package/dist/apps/data/routes/coingecko.js +62 -35
  68. package/dist/apps/data/routes/coingecko.js.map +1 -1
  69. package/dist/apps/data/routes/earn.d.ts +2144 -0
  70. package/dist/apps/data/routes/earn.d.ts.map +1 -0
  71. package/dist/apps/data/routes/earn.js +947 -0
  72. package/dist/apps/data/routes/earn.js.map +1 -0
  73. package/dist/apps/data/routes/exchanges.d.ts +1231 -324
  74. package/dist/apps/data/routes/exchanges.d.ts.map +1 -1
  75. package/dist/apps/data/routes/exchanges.js +656 -193
  76. package/dist/apps/data/routes/exchanges.js.map +1 -1
  77. package/dist/apps/data/routes/fee-amm.d.ts.map +1 -1
  78. package/dist/apps/data/routes/fee-amm.js +59 -8
  79. package/dist/apps/data/routes/fee-amm.js.map +1 -1
  80. package/dist/apps/data/routes/funding.d.ts +4092 -387
  81. package/dist/apps/data/routes/funding.d.ts.map +1 -1
  82. package/dist/apps/data/routes/funding.js +1403 -256
  83. package/dist/apps/data/routes/funding.js.map +1 -1
  84. package/dist/apps/data/routes/indexer.d.ts +5 -5
  85. package/dist/apps/data/routes/indexer.d.ts.map +1 -1
  86. package/dist/apps/data/routes/indexer.js +19 -2
  87. package/dist/apps/data/routes/indexer.js.map +1 -1
  88. package/dist/apps/data/routes/receipts.d.ts +265 -265
  89. package/dist/apps/data/routes/receipts.d.ts.map +1 -1
  90. package/dist/apps/data/routes/receipts.js +11 -11
  91. package/dist/apps/data/routes/receipts.js.map +1 -1
  92. package/dist/apps/data/routes/rpc.d.ts +5 -5
  93. package/dist/apps/data/routes/rpc.d.ts.map +1 -1
  94. package/dist/apps/data/routes/rpc.js +211 -22
  95. package/dist/apps/data/routes/rpc.js.map +1 -1
  96. package/dist/apps/data/routes/tokenlist.d.ts +36 -36
  97. package/dist/apps/data/routes/tokenlist.d.ts.map +1 -1
  98. package/dist/apps/data/routes/tokenlist.js +49 -9
  99. package/dist/apps/data/routes/tokenlist.js.map +1 -1
  100. package/dist/apps/data/routes/tokens.d.ts +116 -88
  101. package/dist/apps/data/routes/tokens.d.ts.map +1 -1
  102. package/dist/apps/data/routes/tokens.js +198 -91
  103. package/dist/apps/data/routes/tokens.js.map +1 -1
  104. package/dist/apps/data/routes/transactions.d.ts +55 -55
  105. package/dist/apps/data/routes/transactions.d.ts.map +1 -1
  106. package/dist/apps/data/routes/transactions.js +78 -39
  107. package/dist/apps/data/routes/transactions.js.map +1 -1
  108. package/dist/apps/data/routes/transfers.d.ts +78 -29
  109. package/dist/apps/data/routes/transfers.d.ts.map +1 -1
  110. package/dist/apps/data/routes/transfers.js +165 -67
  111. package/dist/apps/data/routes/transfers.js.map +1 -1
  112. package/dist/apps/data/routes/valuation.d.ts +10 -10
  113. package/dist/apps/data/routes/valuation.js +2 -2
  114. package/dist/apps/data/routes/valuation.js.map +1 -1
  115. package/dist/apps/data/routes/verified-tokens.d.ts.map +1 -1
  116. package/dist/apps/data/routes/verified-tokens.js +34 -9
  117. package/dist/apps/data/routes/verified-tokens.js.map +1 -1
  118. package/dist/apps/data/routes/webhooks.d.ts +5 -3
  119. package/dist/apps/data/routes/webhooks.d.ts.map +1 -1
  120. package/dist/apps/data/routes/webhooks.js +175 -65
  121. package/dist/apps/data/routes/webhooks.js.map +1 -1
  122. package/dist/apps/data/routes/zones.d.ts +281 -0
  123. package/dist/apps/data/routes/zones.d.ts.map +1 -0
  124. package/dist/apps/data/routes/zones.js +252 -0
  125. package/dist/apps/data/routes/zones.js.map +1 -0
  126. package/dist/apps/docs/reference.js +6 -5
  127. package/dist/apps/docs/reference.js.map +1 -1
  128. package/dist/apps/index.d.ts +2 -1
  129. package/dist/apps/index.d.ts.map +1 -1
  130. package/dist/apps/index.js +2 -1
  131. package/dist/apps/index.js.map +1 -1
  132. package/dist/apps/management/App.d.ts +670 -670
  133. package/dist/apps/management/Billing.d.ts +8 -0
  134. package/dist/apps/management/Billing.d.ts.map +1 -1
  135. package/dist/apps/management/Billing.js +12 -0
  136. package/dist/apps/management/Billing.js.map +1 -1
  137. package/dist/apps/management/Error.d.ts +12 -0
  138. package/dist/apps/management/Error.d.ts.map +1 -0
  139. package/dist/apps/management/Error.js +10 -0
  140. package/dist/apps/management/Error.js.map +1 -0
  141. package/dist/apps/management/routes/api-keys.d.ts +5 -5
  142. package/dist/apps/management/routes/api-keys.d.ts.map +1 -1
  143. package/dist/apps/management/routes/api-keys.js +2 -8
  144. package/dist/apps/management/routes/api-keys.js.map +1 -1
  145. package/dist/apps/management/routes/billing.d.ts +119 -119
  146. package/dist/apps/management/routes/faucet.d.ts +35 -35
  147. package/dist/apps/management/routes/invitations.d.ts +62 -62
  148. package/dist/apps/management/routes/invitations.d.ts.map +1 -1
  149. package/dist/apps/management/routes/invitations.js +4 -10
  150. package/dist/apps/management/routes/invitations.js.map +1 -1
  151. package/dist/apps/management/routes/invite-links.d.ts +30 -30
  152. package/dist/apps/management/routes/me.d.ts +6 -6
  153. package/dist/apps/management/routes/members.d.ts +78 -78
  154. package/dist/apps/management/routes/orgs.d.ts +48 -48
  155. package/dist/apps/management/routes/orgs.d.ts.map +1 -1
  156. package/dist/apps/management/routes/orgs.js +2 -8
  157. package/dist/apps/management/routes/orgs.js.map +1 -1
  158. package/dist/apps/management/routes/projects.d.ts +9 -9
  159. package/dist/apps/management/routes/scopes.js +2 -2
  160. package/dist/apps/management/routes/scopes.js.map +1 -1
  161. package/dist/apps/management/routes/usage.d.ts +80 -80
  162. package/dist/apps/management/routes/verified-token-requests.d.ts +36 -36
  163. package/dist/apps/management/routes/webhooks.d.ts +50 -50
  164. package/dist/apps/management/routes/webhooks.d.ts.map +1 -1
  165. package/dist/apps/management/routes/webhooks.js +15 -3
  166. package/dist/apps/management/routes/webhooks.js.map +1 -1
  167. package/dist/apps/mpp/App.d.ts +55 -56
  168. package/dist/apps/mpp/App.d.ts.map +1 -1
  169. package/dist/apps/mpp/App.js +192 -27
  170. package/dist/apps/mpp/App.js.map +1 -1
  171. package/dist/apps/mpp/Mpp.d.ts +0 -20
  172. package/dist/apps/mpp/Mpp.d.ts.map +1 -1
  173. package/dist/apps/mpp/Mpp.js +0 -24
  174. package/dist/apps/mpp/Mpp.js.map +1 -1
  175. package/dist/apps/mpp/internal/Adapter.d.ts +40 -0
  176. package/dist/apps/mpp/internal/Adapter.d.ts.map +1 -0
  177. package/dist/apps/mpp/internal/Adapter.js +66 -0
  178. package/dist/apps/mpp/internal/Adapter.js.map +1 -0
  179. package/dist/apps/mpp/internal/Error.d.ts +4 -0
  180. package/dist/apps/mpp/internal/Error.d.ts.map +1 -0
  181. package/dist/apps/mpp/internal/Error.js +41 -0
  182. package/dist/apps/mpp/internal/Error.js.map +1 -0
  183. package/dist/apps/mpp/internal/Idempotency.d.ts +33 -0
  184. package/dist/apps/mpp/internal/Idempotency.d.ts.map +1 -0
  185. package/dist/apps/mpp/internal/Idempotency.js +28 -0
  186. package/dist/apps/mpp/internal/Idempotency.js.map +1 -0
  187. package/dist/apps/mpp/internal/Policy.d.ts +46 -0
  188. package/dist/apps/mpp/internal/Policy.d.ts.map +1 -0
  189. package/dist/apps/mpp/internal/Policy.js +57 -0
  190. package/dist/apps/mpp/internal/Policy.js.map +1 -0
  191. package/dist/apps/mpp/internal/ScreenManager.d.ts +27 -0
  192. package/dist/apps/mpp/internal/ScreenManager.d.ts.map +1 -0
  193. package/dist/apps/mpp/internal/ScreenManager.js +18 -0
  194. package/dist/apps/mpp/internal/ScreenManager.js.map +1 -0
  195. package/dist/apps/mpp/internal/Screening.d.ts +35 -0
  196. package/dist/apps/mpp/internal/Screening.d.ts.map +1 -0
  197. package/dist/apps/mpp/internal/Screening.js +20 -0
  198. package/dist/apps/mpp/internal/Screening.js.map +1 -0
  199. package/dist/apps/mpp/internal/Sponsorship.d.ts +36 -0
  200. package/dist/apps/mpp/internal/Sponsorship.d.ts.map +1 -0
  201. package/dist/apps/mpp/internal/Sponsorship.js +103 -0
  202. package/dist/apps/mpp/internal/Sponsorship.js.map +1 -0
  203. package/dist/apps/mpp/internal/Utils.d.ts +7 -0
  204. package/dist/apps/mpp/internal/Utils.d.ts.map +1 -0
  205. package/dist/apps/mpp/internal/Utils.js +24 -0
  206. package/dist/apps/mpp/internal/Utils.js.map +1 -0
  207. package/dist/apps/relay/App.js +184 -24
  208. package/dist/apps/relay/App.js.map +1 -1
  209. package/dist/apps/relay/Sponsorships.d.ts +4 -0
  210. package/dist/apps/relay/Sponsorships.d.ts.map +1 -1
  211. package/dist/apps/relay/Sponsorships.js +16 -7
  212. package/dist/apps/relay/Sponsorships.js.map +1 -1
  213. package/dist/db/Db.d.ts +20 -0
  214. package/dist/db/Db.d.ts.map +1 -1
  215. package/dist/db/Db.js +342 -0
  216. package/dist/db/Db.js.map +1 -1
  217. package/dist/db/Schema.d.ts +921 -1
  218. package/dist/db/Schema.d.ts.map +1 -1
  219. package/dist/db/Schema.js +269 -1
  220. package/dist/db/Schema.js.map +1 -1
  221. package/dist/db/tables/earnVaults.d.ts +68 -0
  222. package/dist/db/tables/earnVaults.d.ts.map +1 -0
  223. package/dist/db/tables/earnVaults.js +72 -0
  224. package/dist/db/tables/earnVaults.js.map +1 -0
  225. package/dist/db/tables/fundingCatalog.d.ts +56 -0
  226. package/dist/db/tables/fundingCatalog.d.ts.map +1 -0
  227. package/dist/db/tables/fundingCatalog.js +85 -0
  228. package/dist/db/tables/fundingCatalog.js.map +1 -0
  229. package/dist/db/tables/fundingDepositAddresses.d.ts +159 -0
  230. package/dist/db/tables/fundingDepositAddresses.d.ts.map +1 -0
  231. package/dist/db/tables/fundingDepositAddresses.js +206 -0
  232. package/dist/db/tables/fundingDepositAddresses.js.map +1 -0
  233. package/dist/db/tables/fundingDeposits.d.ts +115 -0
  234. package/dist/db/tables/fundingDeposits.d.ts.map +1 -0
  235. package/dist/db/tables/fundingDeposits.js +100 -0
  236. package/dist/db/tables/fundingDeposits.js.map +1 -0
  237. package/dist/db/tables/fundingIdempotency.d.ts +91 -0
  238. package/dist/db/tables/fundingIdempotency.d.ts.map +1 -0
  239. package/dist/db/tables/fundingIdempotency.js +103 -0
  240. package/dist/db/tables/fundingIdempotency.js.map +1 -0
  241. package/dist/db/tables/fundingTransferEvents.d.ts +12 -0
  242. package/dist/db/tables/fundingTransferEvents.d.ts.map +1 -0
  243. package/dist/db/tables/fundingTransferEvents.js +18 -0
  244. package/dist/db/tables/fundingTransferEvents.js.map +1 -0
  245. package/dist/db/tables/fundingTransferTransactions.d.ts +15 -0
  246. package/dist/db/tables/fundingTransferTransactions.d.ts.map +1 -0
  247. package/dist/db/tables/fundingTransferTransactions.js +27 -0
  248. package/dist/db/tables/fundingTransferTransactions.js.map +1 -0
  249. package/dist/db/tables/fundingTransfers.d.ts +82 -0
  250. package/dist/db/tables/fundingTransfers.d.ts.map +1 -0
  251. package/dist/db/tables/fundingTransfers.js +89 -0
  252. package/dist/db/tables/fundingTransfers.js.map +1 -0
  253. package/dist/db/tables/organizations.d.ts +8 -0
  254. package/dist/db/tables/organizations.d.ts.map +1 -1
  255. package/dist/db/tables/organizations.js +35 -0
  256. package/dist/db/tables/organizations.js.map +1 -1
  257. package/dist/db/tables/projects.d.ts +8 -0
  258. package/dist/db/tables/projects.d.ts.map +1 -1
  259. package/dist/db/tables/projects.js +16 -0
  260. package/dist/db/tables/projects.js.map +1 -1
  261. package/dist/db/tables/requestUsage.d.ts +13 -0
  262. package/dist/db/tables/requestUsage.d.ts.map +1 -1
  263. package/dist/db/tables/requestUsage.js +16 -0
  264. package/dist/db/tables/requestUsage.js.map +1 -1
  265. package/dist/db/tables/sponsoredTransactions.d.ts +4 -2
  266. package/dist/db/tables/sponsoredTransactions.d.ts.map +1 -1
  267. package/dist/db/tables/sponsoredTransactions.js +14 -4
  268. package/dist/db/tables/sponsoredTransactions.js.map +1 -1
  269. package/dist/db/tables/users.d.ts +8 -0
  270. package/dist/db/tables/users.d.ts.map +1 -1
  271. package/dist/db/tables/users.js +16 -0
  272. package/dist/db/tables/users.js.map +1 -1
  273. package/dist/db/tables/verifiedTokens.d.ts +14 -7
  274. package/dist/db/tables/verifiedTokens.d.ts.map +1 -1
  275. package/dist/db/tables/verifiedTokens.js +9 -7
  276. package/dist/db/tables/verifiedTokens.js.map +1 -1
  277. package/dist/db/tables/webhookSubscriptions.d.ts +31 -1
  278. package/dist/db/tables/webhookSubscriptions.d.ts.map +1 -1
  279. package/dist/db/tables/webhookSubscriptions.js +24 -3
  280. package/dist/db/tables/webhookSubscriptions.js.map +1 -1
  281. package/dist/handlers/relay.js +108 -108
  282. package/dist/handlers/relay.js.map +1 -1
  283. package/dist/internal/Auth.d.ts +26 -0
  284. package/dist/internal/Auth.d.ts.map +1 -1
  285. package/dist/internal/Auth.js +35 -2
  286. package/dist/internal/Auth.js.map +1 -1
  287. package/dist/internal/Cache.d.ts.map +1 -1
  288. package/dist/internal/Cache.js +16 -10
  289. package/dist/internal/Cache.js.map +1 -1
  290. package/dist/internal/Cursor.js +1 -1
  291. package/dist/internal/Cursor.js.map +1 -1
  292. package/dist/internal/EarnRates.d.ts +89 -0
  293. package/dist/internal/EarnRates.d.ts.map +1 -0
  294. package/dist/internal/EarnRates.js +266 -0
  295. package/dist/internal/EarnRates.js.map +1 -0
  296. package/dist/internal/EarnVaults.d.ts +171 -0
  297. package/dist/internal/EarnVaults.d.ts.map +1 -0
  298. package/dist/internal/EarnVaults.js +547 -0
  299. package/dist/internal/EarnVaults.js.map +1 -0
  300. package/dist/internal/EdgeCache.d.ts +9 -2
  301. package/dist/internal/EdgeCache.d.ts.map +1 -1
  302. package/dist/internal/EdgeCache.js +36 -9
  303. package/dist/internal/EdgeCache.js.map +1 -1
  304. package/dist/internal/Id.d.ts +11 -0
  305. package/dist/internal/Id.d.ts.map +1 -1
  306. package/dist/internal/Id.js +13 -0
  307. package/dist/internal/Id.js.map +1 -1
  308. package/dist/internal/Idempotency.d.ts +83 -0
  309. package/dist/internal/Idempotency.d.ts.map +1 -0
  310. package/dist/internal/Idempotency.js +113 -0
  311. package/dist/internal/Idempotency.js.map +1 -0
  312. package/dist/internal/Log.d.ts +64 -9
  313. package/dist/internal/Log.d.ts.map +1 -1
  314. package/dist/internal/Log.js +29 -7
  315. package/dist/internal/Log.js.map +1 -1
  316. package/dist/internal/MetricSink.d.ts.map +1 -1
  317. package/dist/internal/MetricSink.js +47 -1
  318. package/dist/internal/MetricSink.js.map +1 -1
  319. package/dist/internal/OpenApi.d.ts +1 -1
  320. package/dist/internal/OpenApi.d.ts.map +1 -1
  321. package/dist/internal/OpenApi.js +3 -0
  322. package/dist/internal/OpenApi.js.map +1 -1
  323. package/dist/internal/Provider.d.ts +14 -0
  324. package/dist/internal/Provider.d.ts.map +1 -0
  325. package/dist/internal/Provider.js +5 -0
  326. package/dist/internal/Provider.js.map +1 -0
  327. package/dist/internal/Schema.d.ts +8 -3
  328. package/dist/internal/Schema.d.ts.map +1 -1
  329. package/dist/internal/Schema.js +24 -13
  330. package/dist/internal/Schema.js.map +1 -1
  331. package/dist/internal/Store.d.ts +6 -0
  332. package/dist/internal/Store.d.ts.map +1 -1
  333. package/dist/internal/Store.js +35 -0
  334. package/dist/internal/Store.js.map +1 -1
  335. package/dist/internal/Tidx.d.ts +43 -24
  336. package/dist/internal/Tidx.d.ts.map +1 -1
  337. package/dist/internal/Tidx.js +79 -11
  338. package/dist/internal/Tidx.js.map +1 -1
  339. package/dist/internal/Viem.d.ts +82 -65
  340. package/dist/internal/Viem.d.ts.map +1 -1
  341. package/dist/internal/Viem.js +83 -12
  342. package/dist/internal/Viem.js.map +1 -1
  343. package/dist/internal/WebhookDestination.d.ts.map +1 -1
  344. package/dist/internal/WebhookDestination.js +34 -28
  345. package/dist/internal/WebhookDestination.js.map +1 -1
  346. package/dist/internal/Webhooks.d.ts +9 -0
  347. package/dist/internal/Webhooks.d.ts.map +1 -1
  348. package/dist/internal/Webhooks.js +15 -10
  349. package/dist/internal/Webhooks.js.map +1 -1
  350. package/dist/internal/exchange/Provider.d.ts +219 -0
  351. package/dist/internal/exchange/Provider.d.ts.map +1 -0
  352. package/dist/internal/exchange/Provider.js +117 -0
  353. package/dist/internal/exchange/Provider.js.map +1 -0
  354. package/dist/internal/exchange/index.d.ts +2 -0
  355. package/dist/internal/exchange/index.d.ts.map +1 -0
  356. package/dist/internal/exchange/index.js +2 -0
  357. package/dist/internal/exchange/index.js.map +1 -0
  358. package/dist/internal/exchange/providers/uniswap.d.ts +57 -0
  359. package/dist/internal/exchange/providers/uniswap.d.ts.map +1 -0
  360. package/dist/internal/exchange/providers/uniswap.js +553 -0
  361. package/dist/internal/exchange/providers/uniswap.js.map +1 -0
  362. package/dist/internal/funding/Action.d.ts +55 -0
  363. package/dist/internal/funding/Action.d.ts.map +1 -0
  364. package/dist/internal/funding/Action.js +74 -0
  365. package/dist/internal/funding/Action.js.map +1 -0
  366. package/dist/internal/funding/Catalog.d.ts +107 -0
  367. package/dist/internal/funding/Catalog.d.ts.map +1 -0
  368. package/dist/internal/funding/Catalog.js +270 -0
  369. package/dist/internal/funding/Catalog.js.map +1 -0
  370. package/dist/internal/funding/Chain.d.ts +76 -0
  371. package/dist/internal/funding/Chain.d.ts.map +1 -0
  372. package/dist/internal/funding/Chain.js +38 -0
  373. package/dist/internal/funding/Chain.js.map +1 -0
  374. package/dist/internal/funding/Deposit.d.ts +366 -0
  375. package/dist/internal/funding/Deposit.d.ts.map +1 -0
  376. package/dist/internal/funding/Deposit.js +286 -0
  377. package/dist/internal/funding/Deposit.js.map +1 -0
  378. package/dist/internal/funding/DepositAddress.d.ts +345 -0
  379. package/dist/internal/funding/DepositAddress.d.ts.map +1 -0
  380. package/dist/internal/funding/DepositAddress.js +189 -0
  381. package/dist/internal/funding/DepositAddress.js.map +1 -0
  382. package/dist/internal/funding/Evidence.d.ts +52 -0
  383. package/dist/internal/funding/Evidence.d.ts.map +1 -0
  384. package/dist/internal/funding/Evidence.js +314 -0
  385. package/dist/internal/funding/Evidence.js.map +1 -0
  386. package/dist/internal/funding/Provider.d.ts +1186 -0
  387. package/dist/internal/funding/Provider.d.ts.map +1 -0
  388. package/dist/internal/funding/Provider.js +1081 -0
  389. package/dist/internal/funding/Provider.js.map +1 -0
  390. package/dist/internal/funding/Reconciliation.d.ts +113 -0
  391. package/dist/internal/funding/Reconciliation.d.ts.map +1 -0
  392. package/dist/internal/funding/Reconciliation.js +676 -0
  393. package/dist/internal/funding/Reconciliation.js.map +1 -0
  394. package/dist/internal/funding/Route.d.ts +21 -0
  395. package/dist/internal/funding/Route.d.ts.map +1 -0
  396. package/dist/internal/funding/Route.js +5 -0
  397. package/dist/internal/funding/Route.js.map +1 -0
  398. package/dist/internal/funding/Subsidy.d.ts +113 -0
  399. package/dist/internal/funding/Subsidy.d.ts.map +1 -0
  400. package/dist/internal/funding/Subsidy.js +138 -0
  401. package/dist/internal/funding/Subsidy.js.map +1 -0
  402. package/dist/internal/funding/Token.d.ts +41 -0
  403. package/dist/internal/funding/Token.d.ts.map +1 -0
  404. package/dist/internal/funding/Token.js +22 -0
  405. package/dist/internal/funding/Token.js.map +1 -0
  406. package/dist/internal/funding/Transfer.d.ts +643 -0
  407. package/dist/internal/funding/Transfer.d.ts.map +1 -0
  408. package/dist/internal/funding/Transfer.js +332 -0
  409. package/dist/internal/funding/Transfer.js.map +1 -0
  410. package/dist/internal/funding/index.d.ts +13 -0
  411. package/dist/internal/funding/index.d.ts.map +1 -0
  412. package/dist/internal/funding/index.js +13 -0
  413. package/dist/internal/funding/index.js.map +1 -0
  414. package/dist/internal/funding/providers/across.d.ts +21 -0
  415. package/dist/internal/funding/providers/across.d.ts.map +1 -0
  416. package/dist/internal/funding/providers/across.js +117 -0
  417. package/dist/internal/funding/providers/across.js.map +1 -0
  418. package/dist/internal/funding/providers/relay.d.ts +46 -0
  419. package/dist/internal/funding/providers/relay.d.ts.map +1 -0
  420. package/dist/internal/funding/providers/relay.js +464 -0
  421. package/dist/internal/funding/providers/relay.js.map +1 -0
  422. package/dist/internal/funding/providers/rhino.d.ts +15 -0
  423. package/dist/internal/funding/providers/rhino.d.ts.map +1 -0
  424. package/dist/internal/funding/providers/rhino.js +116 -0
  425. package/dist/internal/funding/providers/rhino.js.map +1 -0
  426. package/dist/internal/funding/providers/squid.d.ts +19 -0
  427. package/dist/internal/funding/providers/squid.d.ts.map +1 -0
  428. package/dist/internal/funding/providers/squid.js +120 -0
  429. package/dist/internal/funding/providers/squid.js.map +1 -0
  430. package/dist/internal/funding/providers/symbiosis.d.ts +20 -0
  431. package/dist/internal/funding/providers/symbiosis.d.ts.map +1 -0
  432. package/dist/internal/funding/providers/symbiosis.js +176 -0
  433. package/dist/internal/funding/providers/symbiosis.js.map +1 -0
  434. package/dist/internal/index.d.ts +5 -1
  435. package/dist/internal/index.d.ts.map +1 -1
  436. package/dist/internal/index.js +5 -1
  437. package/dist/internal/index.js.map +1 -1
  438. package/dist/internal/webhookDestinations/url.js +61 -57
  439. package/dist/internal/webhookDestinations/url.js.map +1 -1
  440. package/dist/providers/index.d.ts +43 -0
  441. package/dist/providers/index.d.ts.map +1 -0
  442. package/dist/providers/index.js +19 -0
  443. package/dist/providers/index.js.map +1 -0
  444. package/package.json +9 -4
  445. package/src/ApiKeys.test.ts +11 -7
  446. package/src/ApiKeys.ts +37 -9
  447. package/src/App.test.ts +85 -10
  448. package/src/App.ts +224 -137
  449. package/src/Assets.ts +29 -4
  450. package/src/Client.test-d.ts +650 -30
  451. package/src/Scope.test.ts +19 -0
  452. package/src/Scope.ts +28 -11
  453. package/src/Webhooks.test.ts +25 -0
  454. package/src/Webhooks.ts +1 -1
  455. package/src/admin/App.test.ts +9 -2
  456. package/src/admin/App.ts +32 -9
  457. package/src/admin/apps/api-keys.test.ts +167 -23
  458. package/src/admin/apps/api-keys.ts +166 -28
  459. package/src/admin/apps/earn-vaults.test.ts +338 -0
  460. package/src/admin/apps/earn-vaults.ts +572 -0
  461. package/src/admin/apps/scopes.test.ts +16 -1
  462. package/src/admin/ui/plugin.ts +2 -2
  463. package/src/admin/ui/src/components/EarnVaultForm.tsx +137 -0
  464. package/src/admin/ui/src/components/MobileProfile.tsx +2 -2
  465. package/src/admin/ui/src/components/Page.tsx +1 -1
  466. package/src/admin/ui/src/components/ThemeToggle.tsx +1 -1
  467. package/src/admin/ui/src/lib/api-keys.ts +37 -7
  468. package/src/admin/ui/src/lib/client.ts +1 -1
  469. package/src/admin/ui/src/lib/config.ts +1 -1
  470. package/src/admin/ui/src/lib/early-access.ts +8 -9
  471. package/src/admin/ui/src/lib/earn-vaults.ts +207 -0
  472. package/src/admin/ui/src/lib/format.ts +13 -0
  473. package/src/admin/ui/src/lib/organizations.test.ts +14 -4
  474. package/src/admin/ui/src/lib/organizations.ts +7 -1
  475. package/src/admin/ui/src/lib/response.ts +22 -0
  476. package/src/admin/ui/src/lib/scopes.test.ts +19 -11
  477. package/src/admin/ui/src/lib/scopes.ts +28 -7
  478. package/src/admin/ui/src/lib/verified-tokens.ts +10 -9
  479. package/src/admin/ui/src/routeTree.gen.ts +70 -7
  480. package/src/admin/ui/src/router.tsx +2 -2
  481. package/src/admin/ui/src/routes/__root.tsx +9 -8
  482. package/src/admin/ui/src/routes/api-keys.tsx +475 -64
  483. package/src/admin/ui/src/routes/early-access.tsx +5 -12
  484. package/src/admin/ui/src/routes/earn.vaults.tsx +348 -0
  485. package/src/admin/ui/src/routes/earn.vaults_.$vaultId.edit.tsx +154 -0
  486. package/src/admin/ui/src/routes/earn.vaults_.new.tsx +190 -0
  487. package/src/admin/ui/src/routes/organizations.tsx +4 -7
  488. package/src/admin/ui/src/routes/organizations_.$orgId.tsx +56 -54
  489. package/src/admin/ui/src/routes/verified-tokens.tsx +4 -4
  490. package/src/admin/ui/vite.config.ts +4 -1
  491. package/src/admin/ui.generated.ts +189 -95
  492. package/src/analytics/Analytics.test.ts +69 -10
  493. package/src/analytics/Analytics.ts +20 -1
  494. package/src/analytics/tables/requestEvents.ts +79 -37
  495. package/src/apps/Zones.test.ts +33 -0
  496. package/src/apps/Zones.ts +40 -0
  497. package/src/apps/composition.test.ts +84 -1
  498. package/src/apps/data/App.test.ts +38 -9
  499. package/src/apps/data/App.ts +96 -33
  500. package/src/apps/data/FxOracle.ts +1 -1
  501. package/src/apps/data/index.ts +0 -1
  502. package/src/apps/data/routes/activities.test.ts +82 -6
  503. package/src/apps/data/routes/activities.ts +131 -71
  504. package/src/apps/data/routes/balances.test.ts +50 -37
  505. package/src/apps/data/routes/balances.ts +5 -5
  506. package/src/apps/data/routes/blocks.test.ts +2 -0
  507. package/src/apps/data/routes/coingecko.test.ts +22 -0
  508. package/src/apps/data/routes/coingecko.ts +84 -48
  509. package/src/apps/data/routes/earn.test.ts +1108 -0
  510. package/src/apps/data/routes/earn.ts +1391 -0
  511. package/src/apps/data/routes/exchanges.test.ts +82 -33
  512. package/src/apps/data/routes/exchanges.ts +842 -227
  513. package/src/apps/data/routes/fee-amm.test.ts +4 -6
  514. package/src/apps/data/routes/fee-amm.ts +69 -12
  515. package/src/apps/data/routes/funding.test.ts +2712 -221
  516. package/src/apps/data/routes/funding.ts +1604 -387
  517. package/src/apps/data/routes/indexer.test.ts +43 -34
  518. package/src/apps/data/routes/indexer.ts +19 -2
  519. package/src/apps/data/routes/receipts.test.ts +5 -3
  520. package/src/apps/data/routes/receipts.ts +13 -11
  521. package/src/apps/data/routes/rpc.test.ts +446 -28
  522. package/src/apps/data/routes/rpc.ts +243 -25
  523. package/src/apps/data/routes/tokenlist.test.ts +15 -0
  524. package/src/apps/data/routes/tokenlist.ts +88 -22
  525. package/src/apps/data/routes/tokens.ts +262 -86
  526. package/src/apps/data/routes/transactions.test.ts +2 -0
  527. package/src/apps/data/routes/transactions.ts +77 -42
  528. package/src/apps/data/routes/transfers.test.ts +166 -4
  529. package/src/apps/data/routes/transfers.ts +216 -78
  530. package/src/apps/data/routes/valuation.test.ts +62 -9
  531. package/src/apps/data/routes/valuation.ts +2 -2
  532. package/src/apps/data/routes/verified-tokens.test.ts +51 -0
  533. package/src/apps/data/routes/verified-tokens.ts +52 -15
  534. package/src/apps/data/routes/webhooks.test.ts +432 -33
  535. package/src/apps/data/routes/webhooks.ts +189 -79
  536. package/src/apps/data/routes/zones.test.ts +473 -0
  537. package/src/apps/data/routes/zones.ts +338 -0
  538. package/src/apps/docs/reference.ts +8 -6
  539. package/src/apps/index.ts +2 -1
  540. package/src/apps/management/Billing.test.ts +29 -0
  541. package/src/apps/management/Billing.ts +23 -0
  542. package/src/apps/management/Error.ts +12 -0
  543. package/src/apps/management/routes/api-keys.test.ts +5 -3
  544. package/src/apps/management/routes/api-keys.ts +2 -9
  545. package/src/apps/management/routes/invitations.ts +4 -11
  546. package/src/apps/management/routes/orgs.ts +2 -9
  547. package/src/apps/management/routes/scopes.test.ts +7 -2
  548. package/src/apps/management/routes/scopes.ts +2 -2
  549. package/src/apps/management/routes/webhooks.test.ts +6 -1
  550. package/src/apps/management/routes/webhooks.ts +15 -3
  551. package/src/apps/mpp/App.ts +276 -29
  552. package/src/apps/mpp/Mpp.test.ts +631 -26
  553. package/src/apps/mpp/Mpp.ts +0 -42
  554. package/src/apps/mpp/internal/Adapter.ts +108 -3
  555. package/src/apps/mpp/internal/Error.test.ts +33 -0
  556. package/src/apps/mpp/internal/Error.ts +44 -6
  557. package/src/apps/mpp/internal/Idempotency.test.ts +213 -0
  558. package/src/apps/mpp/internal/Idempotency.ts +59 -5
  559. package/src/apps/mpp/internal/Policy.test.ts +122 -0
  560. package/src/apps/mpp/internal/Policy.ts +98 -0
  561. package/src/apps/mpp/internal/ScreenManager.test.ts +68 -0
  562. package/src/apps/mpp/internal/ScreenManager.ts +41 -0
  563. package/src/apps/mpp/internal/Screening.ts +40 -3
  564. package/src/apps/mpp/internal/Sponsorship.ts +144 -0
  565. package/src/apps/mpp/internal/Utils.ts +30 -0
  566. package/src/apps/relay/App.test.ts +495 -64
  567. package/src/apps/relay/App.ts +234 -24
  568. package/src/apps/relay/Sponsorships.test.ts +51 -0
  569. package/src/apps/relay/Sponsorships.ts +19 -7
  570. package/src/db/Db.ts +439 -0
  571. package/src/db/Schema.ts +325 -2
  572. package/src/db/tables/earnVaults.test.ts +185 -0
  573. package/src/db/tables/earnVaults.ts +151 -0
  574. package/src/db/tables/fundingCatalog.test.ts +108 -0
  575. package/src/db/tables/fundingCatalog.ts +157 -0
  576. package/src/db/tables/fundingDepositAddresses.test.ts +580 -0
  577. package/src/db/tables/fundingDepositAddresses.ts +376 -0
  578. package/src/db/tables/fundingDeposits.test.ts +261 -0
  579. package/src/db/tables/fundingDeposits.ts +229 -0
  580. package/src/db/tables/fundingIdempotency.test.ts +182 -0
  581. package/src/db/tables/fundingIdempotency.ts +180 -0
  582. package/src/db/tables/fundingTransferEvents.ts +28 -0
  583. package/src/db/tables/fundingTransferTransactions.test.ts +69 -0
  584. package/src/db/tables/fundingTransferTransactions.ts +37 -0
  585. package/src/db/tables/fundingTransfers.test.ts +89 -0
  586. package/src/db/tables/fundingTransfers.ts +153 -0
  587. package/src/db/tables/organizations.test.ts +88 -0
  588. package/src/db/tables/organizations.ts +42 -1
  589. package/src/db/tables/projects.ts +16 -0
  590. package/src/db/tables/requestUsage.ts +23 -0
  591. package/src/db/tables/sponsoredTransactions.test.ts +52 -2
  592. package/src/db/tables/sponsoredTransactions.ts +18 -6
  593. package/src/db/tables/users.ts +16 -0
  594. package/src/db/tables/verifiedTokens.ts +19 -14
  595. package/src/db/tables/webhookSubscriptions.ts +58 -3
  596. package/src/handlers/relay.test.ts +2 -0
  597. package/src/handlers/relay.ts +95 -99
  598. package/src/internal/Auth.test.ts +48 -0
  599. package/src/internal/Auth.ts +61 -2
  600. package/src/internal/Cache.ts +13 -9
  601. package/src/internal/Cursor.test.ts +2 -2
  602. package/src/internal/Cursor.ts +1 -1
  603. package/src/internal/EarnRates.test.ts +125 -0
  604. package/src/internal/EarnRates.ts +409 -0
  605. package/src/internal/EarnVaults.test.ts +195 -0
  606. package/src/internal/EarnVaults.ts +876 -0
  607. package/src/internal/EdgeCache.test.ts +37 -5
  608. package/src/internal/EdgeCache.ts +39 -7
  609. package/src/internal/Id.ts +14 -0
  610. package/src/internal/Idempotency.test.ts +109 -0
  611. package/src/internal/Idempotency.ts +237 -0
  612. package/src/internal/Log.test-d.ts +41 -8
  613. package/src/internal/Log.test.ts +189 -8
  614. package/src/internal/Log.ts +124 -17
  615. package/src/internal/MetricSink.test.ts +244 -4
  616. package/src/internal/MetricSink.ts +51 -1
  617. package/src/internal/OpenApi.ts +3 -0
  618. package/src/internal/Provider.test.ts +17 -0
  619. package/src/internal/Provider.ts +17 -0
  620. package/src/internal/Schema.test.ts +13 -0
  621. package/src/internal/Schema.ts +41 -24
  622. package/src/internal/Store.test.ts +25 -0
  623. package/src/internal/Store.ts +46 -0
  624. package/src/internal/Tidx.local.test.ts +78 -3
  625. package/src/internal/Tidx.test.ts +212 -18
  626. package/src/internal/Tidx.ts +112 -32
  627. package/src/internal/VerifiedTokens.test.ts +15 -0
  628. package/src/internal/Viem.test.ts +170 -17
  629. package/src/internal/Viem.ts +111 -28
  630. package/src/internal/WebhookDestination.ts +25 -23
  631. package/src/internal/Webhooks.test.ts +59 -0
  632. package/src/internal/Webhooks.ts +34 -10
  633. package/src/internal/exchange/Provider.test.ts +216 -0
  634. package/src/internal/exchange/Provider.ts +326 -0
  635. package/src/internal/exchange/index.test.ts +6 -0
  636. package/src/internal/exchange/index.ts +1 -0
  637. package/src/internal/exchange/providers/uniswap.test.ts +122 -0
  638. package/src/internal/exchange/providers/uniswap.ts +682 -0
  639. package/src/internal/funding/Action.test.ts +138 -0
  640. package/src/internal/funding/Action.ts +117 -0
  641. package/src/internal/funding/Catalog.test.ts +311 -0
  642. package/src/internal/funding/Catalog.ts +347 -0
  643. package/src/internal/funding/Chain.test.ts +79 -0
  644. package/src/internal/funding/Chain.ts +120 -0
  645. package/src/internal/funding/Deposit.test.ts +26 -0
  646. package/src/internal/funding/Deposit.ts +453 -0
  647. package/src/internal/funding/DepositAddress.test.ts +18 -0
  648. package/src/internal/funding/DepositAddress.ts +312 -0
  649. package/src/internal/funding/Evidence.test.ts +297 -0
  650. package/src/internal/funding/Evidence.ts +430 -0
  651. package/src/internal/funding/Provider.test.ts +1328 -0
  652. package/src/internal/funding/Provider.ts +1796 -0
  653. package/src/internal/funding/Reconciliation.local.test.ts +504 -0
  654. package/src/internal/funding/Reconciliation.test.ts +2020 -0
  655. package/src/internal/funding/Reconciliation.ts +930 -0
  656. package/src/internal/funding/Route.test.ts +66 -0
  657. package/src/internal/funding/Route.ts +29 -0
  658. package/src/internal/funding/Subsidy.local.test.ts +152 -0
  659. package/src/internal/funding/Subsidy.test.ts +75 -0
  660. package/src/internal/funding/Subsidy.ts +260 -0
  661. package/src/internal/funding/Token.test.ts +47 -0
  662. package/src/internal/funding/Token.ts +59 -0
  663. package/src/internal/funding/Transfer.test.ts +369 -0
  664. package/src/internal/funding/Transfer.ts +522 -0
  665. package/src/internal/funding/index.test.ts +20 -0
  666. package/src/internal/funding/index.ts +12 -0
  667. package/src/internal/funding/providers/across.ts +149 -0
  668. package/src/{apps/data/FundingQuoteProviders.test.ts → internal/funding/providers/index.test.ts} +178 -157
  669. package/src/internal/funding/providers/relay.test.ts +474 -0
  670. package/src/internal/funding/providers/relay.ts +559 -0
  671. package/src/internal/funding/providers/rhino.ts +139 -0
  672. package/src/internal/funding/providers/squid.ts +151 -0
  673. package/src/internal/funding/providers/symbiosis.ts +221 -0
  674. package/src/internal/index.test.ts +5 -1
  675. package/src/internal/index.ts +5 -1
  676. package/src/internal/webhookDestinations/url.ts +49 -45
  677. package/src/providers/index.test.ts +14 -0
  678. package/src/providers/index.ts +54 -0
  679. package/dist/apps/data/FundingQuoteProviders.d.ts +0 -174
  680. package/dist/apps/data/FundingQuoteProviders.d.ts.map +0 -1
  681. package/dist/apps/data/FundingQuoteProviders.js +0 -775
  682. package/dist/apps/data/FundingQuoteProviders.js.map +0 -1
  683. package/dist/internal/FundingQuotes.d.ts +0 -864
  684. package/dist/internal/FundingQuotes.d.ts.map +0 -1
  685. package/dist/internal/FundingQuotes.js +0 -672
  686. package/dist/internal/FundingQuotes.js.map +0 -1
  687. package/src/apps/data/FundingQuoteProviders.ts +0 -1043
  688. package/src/internal/FundingQuotes.test.ts +0 -456
  689. package/src/internal/FundingQuotes.ts +0 -944
@@ -1,1043 +0,0 @@
1
- import * as z from 'zod/mini'
2
-
3
- import * as FundingQuotes from '../../internal/FundingQuotes.js'
4
- import * as Store from '../../internal/Store.js'
5
-
6
- type Fetch = typeof globalThis.fetch
7
-
8
- const defaultFetch: Fetch = (input, init) => globalThis.fetch(input, init)
9
-
10
- const defaultAcrossBaseUrl = 'https://app.across.to/api'
11
- const defaultRelayBaseUrl = 'https://api.relay.link'
12
- const defaultRhinoBaseUrl = 'https://api.rhino.fi/bridge'
13
- const defaultSquidBaseUrl = 'https://v2.api.squidrouter.com/v2'
14
- const defaultSymbiosisBaseUrl = 'https://api.symbiosis.finance/crosschain'
15
- // Keep one upstream slot free for deployment smoke tests and operational probes.
16
- const symbiosisRateLimit = 4
17
- const symbiosisRateLimitWindowMs = 1_000
18
- const providerOperations = {
19
- across: 'swap/approval',
20
- relay: 'quote/v2',
21
- rhino: 'quote/bridge-swap/public',
22
- squid: 'v2/route',
23
- symbiosis: 'v2/quote',
24
- } as const
25
-
26
- /** Returns the stable upstream operation used by a funding quote provider. */
27
- export function providerOperation(provider: FundingQuotes.ProviderId) {
28
- return providerOperations[provider]
29
- }
30
-
31
- namespace schema {
32
- const IntegerString = z.string().check(z.regex(/^\d+$/))
33
-
34
- const AcrossToken = z.object({
35
- address: z.string(),
36
- chainId: z.number().check(z.int(), z.nonnegative()),
37
- decimals: z.number().check(z.int(), z.nonnegative()),
38
- })
39
-
40
- export const AcrossQuote = z.object({
41
- amountType: z.literal('exactInput'),
42
- expectedFillTime: z.number().check(z.int(), z.nonnegative()),
43
- expectedOutputAmount: IntegerString,
44
- inputAmount: IntegerString,
45
- inputToken: AcrossToken,
46
- minOutputAmount: IntegerString,
47
- outputToken: AcrossToken,
48
- quoteExpiryTimestamp: z.number().check(z.int(), z.nonnegative()),
49
- })
50
-
51
- export const RhinoQuote = z.object({
52
- _tag: z.literal('bridge'),
53
- chainIn: z.string(),
54
- chainOut: z.string(),
55
- estimatedDuration: z.optional(z.nullable(z.number().check(z.nonnegative()))),
56
- payAmount: z.string().check(z.regex(/^\d+(\.\d+)?$/)),
57
- receiveAmount: z.string().check(z.regex(/^\d+(\.\d+)?$/)),
58
- token: z.string(),
59
- })
60
-
61
- const SquidToken = z.object({
62
- address: z.string(),
63
- chainId: z.union([z.string(), z.number().check(z.int(), z.nonnegative())]),
64
- decimals: z.number().check(z.int(), z.nonnegative()),
65
- })
66
-
67
- export const SquidQuote = z.object({
68
- route: z.object({
69
- estimate: z.object({
70
- estimatedRouteDuration: z.number().check(z.nonnegative()),
71
- fromAmount: IntegerString,
72
- fromToken: SquidToken,
73
- toAmount: IntegerString,
74
- toAmountMin: IntegerString,
75
- toToken: SquidToken,
76
- }),
77
- }),
78
- })
79
-
80
- export const SymbiosisToken = z.object({
81
- address: z.string(),
82
- chainId: z.number().check(z.int(), z.nonnegative()),
83
- decimals: z.number().check(z.int(), z.nonnegative()),
84
- })
85
-
86
- const SymbiosisTokenAmount = z.extend(SymbiosisToken, { amount: IntegerString })
87
-
88
- export const SymbiosisQuote = z.object({
89
- estimatedTime: z.optional(z.number().check(z.nonnegative())),
90
- kind: z.union([z.literal('bridge'), z.literal('crosschain-swap'), z.literal('intent-swap')]),
91
- routes: z
92
- .array(
93
- z.object({
94
- tokens: z.array(SymbiosisToken).check(z.minLength(1)),
95
- }),
96
- )
97
- .check(z.minLength(1)),
98
- tokenAmountOut: SymbiosisTokenAmount,
99
- tokenAmountOutMin: SymbiosisTokenAmount,
100
- tx: z.object({ chainId: z.number().check(z.int(), z.nonnegative()) }),
101
- type: z.union([z.literal('evm'), z.literal('tron')]),
102
- })
103
- }
104
-
105
- /** Creates the live funding quote adapters configured for this deployment. */
106
- export function createAdapters(options: createAdapters.Options = {}) {
107
- return {
108
- ...(options.across ? { across: across(options.across) } : {}),
109
- ...(options.relay ? { relay: relay(options.relay) } : {}),
110
- ...(options.rhino ? { rhino: rhino(options.rhino) } : {}),
111
- ...(options.squid ? { squid: squid(options.squid) } : {}),
112
- ...(options.symbiosis ? { symbiosis: symbiosis(options.symbiosis) } : {}),
113
- } satisfies FundingQuotes.ProviderAdapters
114
- }
115
-
116
- export declare namespace createAdapters {
117
- /** Provider adapter factory options. Omit a provider to leave it unconfigured. */
118
- type Options = {
119
- /** Across quote adapter options. */
120
- across?: across.Options | false | undefined
121
- /** Relay quote adapter options. */
122
- relay?: relay.Options | false | undefined
123
- /** Rhino quote adapter options. */
124
- rhino?: rhino.Options | false | undefined
125
- /** Squid quote adapter options. */
126
- squid?: squid.Options | false | undefined
127
- /** Symbiosis quote adapter options. */
128
- symbiosis?: symbiosis.Options | false | undefined
129
- }
130
- }
131
-
132
- /** Resolves all-or-none Across deployment configuration. */
133
- export function configureAcross(options: configureAcross.Options = {}): across.Options | undefined {
134
- const configured = [options.apiKey, options.integratorId, options.userAddress].filter(Boolean)
135
- if (configured.length === 0) return undefined
136
- if (!options.apiKey || !options.integratorId || !options.userAddress)
137
- throw new ProviderConfigurationError()
138
- return {
139
- apiKey: options.apiKey,
140
- integratorId: options.integratorId,
141
- userAddress: options.userAddress,
142
- }
143
- }
144
-
145
- export declare namespace configureAcross {
146
- /** Optional deployment bindings required together to enable Across. */
147
- type Options = {
148
- /** Across API key binding. */
149
- apiKey?: string | undefined
150
- /** Across integrator id binding. */
151
- integratorId?: string | undefined
152
- /** Across quote-user binding. */
153
- userAddress?: string | undefined
154
- }
155
- }
156
-
157
- /** Resolves all-or-none Squid deployment configuration. */
158
- export function configureSquid(options: configureSquid.Options = {}): squid.Options | undefined {
159
- const configured = [options.integratorId, options.userAddress].filter(Boolean)
160
- if (configured.length === 0) return undefined
161
- if (!options.integratorId || !options.userAddress) throw new ProviderConfigurationError()
162
- return {
163
- integratorId: options.integratorId,
164
- userAddress: options.userAddress,
165
- }
166
- }
167
-
168
- export declare namespace configureSquid {
169
- /** Optional deployment bindings required together to enable Squid. */
170
- type Options = {
171
- /** Squid integrator id binding. */
172
- integratorId?: string | undefined
173
- /** Squid quote-user binding. */
174
- userAddress?: string | undefined
175
- }
176
- }
177
-
178
- /** Resolves Symbiosis deployment configuration. */
179
- export function configureSymbiosis(
180
- options: configureSymbiosis.Options = {},
181
- ): symbiosis.Options | undefined {
182
- if (!options.userAddress) return undefined
183
- return { userAddress: options.userAddress }
184
- }
185
-
186
- export declare namespace configureSymbiosis {
187
- /** Optional deployment binding required to enable Symbiosis. */
188
- type Options = {
189
- /** Symbiosis quote-user binding. */
190
- userAddress?: string | undefined
191
- }
192
- }
193
-
194
- /** Creates an Across quote adapter backed by `/swap/approval`. */
195
- export function across(options: across.Options): FundingQuotes.ProviderAdapter {
196
- assertAcrossConfiguration(options)
197
- const baseUrl = normalizeBaseUrl(options.baseUrl ?? defaultAcrossBaseUrl)
198
- const fetcher = options.fetch ?? defaultFetch
199
- const now = options.now ?? (() => new Date())
200
-
201
- return {
202
- async probeQuote({ candidate }, signal) {
203
- const destinationChainId = eip155ChainId(candidate.destinationChain)
204
- const originChainId = providerChainId(candidate.sourceChain, 'across')
205
- const url = new URL(`${baseUrl}/swap/approval`)
206
- url.search = new URLSearchParams({
207
- amount: candidate.sourceAmount.amount,
208
- depositor: options.userAddress,
209
- destinationChainId,
210
- inputToken: candidate.sourceToken.address,
211
- integratorId: options.integratorId,
212
- originChainId,
213
- outputToken: candidate.destinationToken.address,
214
- recipient: options.userAddress,
215
- skipOriginTxEstimation: 'true',
216
- strictTradeType: 'true',
217
- tradeType: 'exactInput',
218
- }).toString()
219
-
220
- try {
221
- const quote = await requestJson(url, {
222
- fetcher,
223
- headers: { Authorization: `Bearer ${options.apiKey}` },
224
- signal,
225
- })
226
- return formatAcrossResult(candidate, quote, now())
227
- } catch (cause) {
228
- const unavailable = providerUnavailable(cause, [
229
- 'AMOUNT_TOO_HIGH',
230
- 'AMOUNT_TOO_LOW',
231
- 'INSUFFICIENT_LIQUIDITY',
232
- 'NO_QUOTES',
233
- 'NO_ROUTE',
234
- 'UNSUPPORTED_ROUTE',
235
- ])
236
- if (!unavailable) throw cause
237
- return unavailableResult({
238
- detail: 'across:swap-approval',
239
- message: unavailable,
240
- now: now(),
241
- source: 'providerQuote',
242
- })
243
- }
244
- },
245
- }
246
- }
247
-
248
- export declare namespace across {
249
- /** Across quote adapter options. */
250
- type Options = {
251
- /** Across API key sent as a bearer token. */
252
- apiKey: string
253
- /** Override for tests or Across test environments. */
254
- baseUrl?: string | undefined
255
- /** Fetch implementation override for tests. */
256
- fetch?: Fetch | undefined
257
- /** Across integrator id sent as the required query parameter. */
258
- integratorId: string
259
- /** Clock override for deterministic tests. */
260
- now?: (() => Date) | undefined
261
- /** Probe wallet address used as the Across depositor and recipient. */
262
- userAddress: string
263
- }
264
- }
265
-
266
- /** Creates a Relay quote adapter backed by `/quote/v2`. */
267
- export function relay(options: relay.Options): FundingQuotes.ProviderAdapter {
268
- const baseUrl = normalizeBaseUrl(options.baseUrl ?? defaultRelayBaseUrl)
269
- const fetcher = options.fetch ?? defaultFetch
270
- const now = options.now ?? (() => new Date())
271
-
272
- return {
273
- async probeQuote({ candidate }, signal) {
274
- const originChainId = providerChainId(candidate.sourceChain, 'relay')
275
- const destinationChainId = eip155ChainId(candidate.destinationChain)
276
- const headers = relayHeaders(options.apiKey)
277
-
278
- try {
279
- const quote = await requestJson(new URL(`${baseUrl}/quote/v2`), {
280
- body: {
281
- amount: candidate.sourceAmount.amount,
282
- destinationChainId: Number(destinationChainId),
283
- destinationCurrency: candidate.destinationToken.address,
284
- originChainId: Number(originChainId),
285
- originCurrency: candidate.sourceToken.address,
286
- recipient: options.recipientAddress ?? options.userAddress,
287
- tradeType: 'EXACT_INPUT',
288
- user: options.userAddress,
289
- },
290
- fetcher,
291
- headers,
292
- method: 'POST',
293
- signal,
294
- })
295
- return formatRelayResult(quote, now())
296
- } catch (cause) {
297
- const unavailable = providerUnavailable(cause, [
298
- 'NO_QUOTES',
299
- 'NO_ROUTE',
300
- 'UNSUPPORTED_ROUTE',
301
- ])
302
- if (!unavailable) throw cause
303
- return unavailableResult({
304
- detail: 'relay:quote-v2',
305
- message: unavailable,
306
- now: now(),
307
- source: 'providerQuote',
308
- })
309
- }
310
- },
311
- }
312
- }
313
-
314
- export declare namespace relay {
315
- /** Relay quote adapter options. */
316
- type Options = {
317
- /** Probe wallet address required by Relay's quote API. */
318
- userAddress: string
319
- /** Optional recipient override; defaults to `userAddress`. */
320
- recipientAddress?: string | undefined
321
- /** Optional Relay API key for higher rate limits. */
322
- apiKey?: string | undefined
323
- /** Override for tests or Relay testnet environments. */
324
- baseUrl?: string | undefined
325
- /** Fetch implementation override for tests. */
326
- fetch?: Fetch | undefined
327
- /** Clock override for deterministic tests. */
328
- now?: (() => Date) | undefined
329
- }
330
- }
331
-
332
- /** Creates a Rhino quote adapter backed by the public bridge-and-swap quote endpoint. */
333
- export function rhino(options: rhino.Options = {}): FundingQuotes.ProviderAdapter {
334
- const baseUrl = normalizeBaseUrl(options.baseUrl ?? defaultRhinoBaseUrl)
335
- const fetcher = options.fetch ?? defaultFetch
336
- const now = options.now ?? (() => new Date())
337
-
338
- return {
339
- async probeQuote({ cache, candidate }, signal) {
340
- const chainIn = providerChainReference(candidate.sourceChain, 'rhino')
341
- const tokenOut = rhinoToken(candidate.destinationToken)
342
- const url = new URL(`${baseUrl}/quote/bridge-swap/public`)
343
- url.search = new URLSearchParams({
344
- amount: candidate.sourceAmount.formatted,
345
- amountNative: '0',
346
- chainIn,
347
- chainOut: 'TEMPO',
348
- mode: 'pay',
349
- tokenIn: candidate.sourceToken.symbol,
350
- tokenOut,
351
- }).toString()
352
-
353
- try {
354
- const quote = await requestJson(url, {
355
- fetcher,
356
- headers: cache.bypass ? { 'cache-control': 'no-cache' } : undefined,
357
- signal,
358
- })
359
- return formatRhinoResult(candidate, quote, { chainIn, now: now(), tokenOut })
360
- } catch (cause) {
361
- const unavailable = providerUnavailable(cause, ['NoRouteFoundError'])
362
- if (!unavailable) throw cause
363
- return unavailableResult({
364
- detail: 'rhino:bridge-swap-public',
365
- message: unavailable,
366
- now: now(),
367
- source: 'providerQuote',
368
- })
369
- }
370
- },
371
- }
372
- }
373
-
374
- export declare namespace rhino {
375
- /** Rhino public quote adapter options. */
376
- type Options = {
377
- /** Override for tests or Rhino test environments. */
378
- baseUrl?: string | undefined
379
- /** Fetch implementation override for tests. */
380
- fetch?: Fetch | undefined
381
- /** Clock override for deterministic tests. */
382
- now?: (() => Date) | undefined
383
- }
384
- }
385
-
386
- /** Creates a Squid quote adapter backed by `/v2/route`. */
387
- export function squid(options: squid.Options): FundingQuotes.ProviderAdapter {
388
- assertSquidConfiguration(options)
389
- const baseUrl = normalizeBaseUrl(options.baseUrl ?? defaultSquidBaseUrl)
390
- const fetcher = options.fetch ?? defaultFetch
391
- const now = options.now ?? (() => new Date())
392
-
393
- return {
394
- async probeQuote({ candidate }, signal) {
395
- const fromChain = eip155ChainId(candidate.sourceChain)
396
- const toChain = eip155ChainId(candidate.destinationChain)
397
-
398
- try {
399
- const quote = await requestJson(new URL(`${baseUrl}/route`), {
400
- body: {
401
- fromAddress: options.userAddress,
402
- fromAmount: candidate.sourceAmount.amount,
403
- fromChain,
404
- fromToken: candidate.sourceToken.address,
405
- quoteOnly: true,
406
- // V1 quotes use a fixed 1% tolerance; callers cannot customize execution policy.
407
- slippage: 1,
408
- toAddress: options.userAddress,
409
- toChain,
410
- toToken: candidate.destinationToken.address,
411
- },
412
- fetcher,
413
- headers: { 'x-integrator-id': options.integratorId },
414
- method: 'POST',
415
- signal,
416
- })
417
- return formatSquidResult(candidate, quote, now())
418
- } catch (cause) {
419
- const unavailable =
420
- providerUnavailable(cause, [
421
- 'NO_ROUTE',
422
- 'NO_ROUTE_FOUND',
423
- 'ROUTE_NOT_FOUND',
424
- 'UNSUPPORTED_ROUTE',
425
- ]) ?? squidUnavailable(cause)
426
- if (!unavailable) throw cause
427
- return unavailableResult({
428
- detail: 'squid:route-v2',
429
- message: unavailable,
430
- now: now(),
431
- source: 'providerQuote',
432
- })
433
- }
434
- },
435
- }
436
- }
437
-
438
- export declare namespace squid {
439
- /** Squid quote adapter options. */
440
- type Options = {
441
- /** Override for tests or Squid test environments. */
442
- baseUrl?: string | undefined
443
- /** Fetch implementation override for tests. */
444
- fetch?: Fetch | undefined
445
- /** Squid integrator id sent in the required request header. */
446
- integratorId: string
447
- /** Clock override for deterministic tests. */
448
- now?: (() => Date) | undefined
449
- /** Probe wallet address used as the Squid sender and recipient. */
450
- userAddress: string
451
- }
452
- }
453
-
454
- /** Creates a Symbiosis quote adapter backed by `/v2/quote`. */
455
- export function symbiosis(options: symbiosis.Options): FundingQuotes.ProviderAdapter {
456
- assertUserAddress(options.userAddress)
457
- const baseUrl = normalizeBaseUrl(options.baseUrl ?? defaultSymbiosisBaseUrl)
458
- const fetcher = options.fetch ?? defaultFetch
459
- const now = options.now ?? (() => new Date())
460
- const rateLimitStore = options.rateLimitStore ?? Store.memory()
461
-
462
- return {
463
- async probeQuote({ candidate }, signal) {
464
- const fromChainId = Number(providerChainId(candidate.sourceChain, 'symbiosis'))
465
- const fromToken = symbiosisSourceToken(candidate.sourceChain, candidate.sourceToken)
466
- const toChainId = Number(eip155ChainId(candidate.destinationChain))
467
-
468
- try {
469
- await consumeSymbiosisQuota(rateLimitStore, now())
470
- const quote = await requestJson(new URL(`${baseUrl}/v2/quote`), {
471
- body: {
472
- from: options.userAddress,
473
- slippage: 100,
474
- to: options.userAddress,
475
- tokenAmountIn: {
476
- address: fromToken,
477
- amount: candidate.sourceAmount.amount,
478
- chainId: fromChainId,
479
- decimals: candidate.sourceToken.decimals,
480
- symbol: candidate.sourceToken.symbol,
481
- },
482
- tokenOut: {
483
- address: candidate.destinationToken.address,
484
- chainId: toChainId,
485
- decimals: candidate.destinationToken.decimals,
486
- symbol: candidate.destinationToken.symbol,
487
- },
488
- },
489
- fetcher,
490
- headers: { 'x-partner-id': 'tempo' },
491
- method: 'POST',
492
- signal,
493
- })
494
- return formatSymbiosisResult(candidate, quote, now())
495
- } catch (cause) {
496
- const unavailable =
497
- providerUnavailable(cause, [
498
- 'AMOUNT_TOO_LOW',
499
- 'NO_ROUTE',
500
- 'NO_ROUTE_FOUND',
501
- 'ROUTE_NOT_FOUND',
502
- 'UNSUPPORTED_ROUTE',
503
- ]) ?? symbiosisUnavailable(cause)
504
- if (!unavailable) throw cause
505
- return unavailableResult({
506
- detail: 'symbiosis:quote-v2',
507
- message: unavailable,
508
- now: now(),
509
- source: 'providerQuote',
510
- })
511
- }
512
- },
513
- }
514
- }
515
-
516
- export declare namespace symbiosis {
517
- /** Symbiosis quote adapter options. */
518
- type Options = {
519
- /** Override for tests or Symbiosis test environments. */
520
- baseUrl?: string | undefined
521
- /** Fetch implementation override for tests. */
522
- fetch?: Fetch | undefined
523
- /** Clock override for deterministic tests. */
524
- now?: (() => Date) | undefined
525
- /** Atomic store used to enforce the provider-wide quote quota. */
526
- rateLimitStore?: Store.Store | undefined
527
- /** Probe wallet address used as the Symbiosis sender and recipient. */
528
- userAddress: string
529
- }
530
- }
531
-
532
- /** Returns bounded provider failure details suitable for structured request logs. */
533
- export function providerFailure(options: providerFailure.Options): providerFailure.Result {
534
- const operation = providerOperation(options.provider)
535
- if (
536
- options.cause instanceof FundingQuotes.ProviderAdapterTimeoutError ||
537
- (options.cause instanceof DOMException && options.cause.name === 'AbortError')
538
- )
539
- return { failure: 'timeout', id: options.provider, operation }
540
- if (options.cause instanceof ProviderResponseError) {
541
- const code = providerErrorCode(options.cause.body)
542
- return {
543
- ...(code === undefined ? {} : { code }),
544
- failure: 'http',
545
- id: options.provider,
546
- operation,
547
- status: options.cause.status,
548
- }
549
- }
550
- if (options.cause instanceof ProviderPayloadError)
551
- return { failure: 'payload', id: options.provider, operation }
552
- if (options.cause instanceof ProviderRateLimitError)
553
- return { failure: 'rate_limit', id: options.provider, operation }
554
- if (options.cause instanceof TypeError)
555
- return { failure: 'network', id: options.provider, operation }
556
- return { failure: 'unknown', id: options.provider, operation }
557
- }
558
-
559
- export declare namespace providerFailure {
560
- /** Inputs used to classify a provider failure. */
561
- type Options = FundingQuotes.ProviderFailure
562
-
563
- /** Bounded provider failure fields. */
564
- type Result = {
565
- /** Stable provider error code, when one is safe to retain. */
566
- code?: string | undefined
567
- /** Failure boundary that rejected the provider request. */
568
- failure: 'http' | 'network' | 'payload' | 'rate_limit' | 'timeout' | 'unknown'
569
- /** Provider identifier. */
570
- id: FundingQuotes.ProviderId
571
- /** Provider operation identifier. */
572
- operation: (typeof providerOperations)[FundingQuotes.ProviderId]
573
- /** Upstream HTTP status, when a response was received. */
574
- status?: number | undefined
575
- }
576
- }
577
-
578
- function formatAcrossResult(
579
- candidate: FundingQuotes.QuoteCandidate,
580
- quote: unknown,
581
- now: Date,
582
- ): FundingQuotes.QuoteProbeResult {
583
- const parsed = schema.AcrossQuote.safeParse(quote)
584
- if (!parsed.success) throw new ProviderPayloadError()
585
- const response = parsed.data
586
- const expiresAt = new Date(response.quoteExpiryTimestamp * 1_000)
587
- if (
588
- response.inputAmount !== candidate.sourceAmount.amount ||
589
- !matchesToken(response.inputToken, candidate.sourceChain, candidate.sourceToken) ||
590
- !matchesToken(response.outputToken, candidate.destinationChain, candidate.destinationToken) ||
591
- BigInt(response.expectedOutputAmount) <= 0n ||
592
- BigInt(response.minOutputAmount) <= 0n ||
593
- BigInt(response.minOutputAmount) > BigInt(response.expectedOutputAmount) ||
594
- Number.isNaN(expiresAt.getTime()) ||
595
- response.quoteExpiryTimestamp * 1_000 <= now.getTime()
596
- )
597
- throw new ProviderPayloadError()
598
-
599
- return {
600
- expiresAt: expiresAt.toISOString(),
601
- minimumOutputAmount: response.minOutputAmount,
602
- outputAmount: response.expectedOutputAmount,
603
- quality: {
604
- estimatedSeconds: response.expectedFillTime,
605
- liquiditySource: 'providerQuote',
606
- sourceDetail: 'across:swap-approval',
607
- tier: 'liquid',
608
- },
609
- sampledAt: now.toISOString(),
610
- status: 'available',
611
- }
612
- }
613
-
614
- function formatRelayResult(quote: unknown, now: Date): FundingQuotes.QuoteProbeResult {
615
- const details = record(record(quote)['details'])
616
- const currencyOut = record(details['currencyOut'])
617
- const outputAmount = decimalString(currencyOut['amount'])
618
- const status = outputAmount
619
- ? { status: 'available' as const, tier: 'liquid' as const }
620
- : { status: 'unknown' as const, tier: 'unknown' as const }
621
-
622
- return {
623
- minimumOutputAmount: decimalString(currencyOut['minimumAmount']),
624
- outputAmount,
625
- quality: {
626
- estimatedSeconds: nonnegativeInteger(details['timeEstimate']),
627
- liquiditySource: 'providerQuote',
628
- sourceDetail: 'relay:quote-v2',
629
- tier: status.tier,
630
- },
631
- sampledAt: now.toISOString(),
632
- status: status.status,
633
- }
634
- }
635
-
636
- function formatRhinoResult(
637
- candidate: FundingQuotes.QuoteCandidate,
638
- quote: unknown,
639
- options: { chainIn: string; now: Date; tokenOut: string },
640
- ): FundingQuotes.QuoteProbeResult {
641
- const parsed = schema.RhinoQuote.safeParse(quote)
642
- if (!parsed.success) throw new ProviderPayloadError()
643
- const response = parsed.data
644
- const inputAmount = baseUnitsFromDecimal(response.payAmount, candidate.sourceToken.decimals)
645
- const outputAmount = baseUnitsFromDecimal(
646
- response.receiveAmount,
647
- candidate.destinationToken.decimals,
648
- )
649
- if (
650
- response.chainIn !== options.chainIn ||
651
- response.chainOut !== 'TEMPO' ||
652
- response.token !== options.tokenOut ||
653
- inputAmount !== candidate.sourceAmount.amount ||
654
- outputAmount === undefined ||
655
- BigInt(outputAmount) <= 0n
656
- )
657
- throw new ProviderPayloadError()
658
-
659
- return {
660
- outputAmount,
661
- quality: {
662
- ...(response.estimatedDuration === undefined || response.estimatedDuration === null
663
- ? {}
664
- : { estimatedSeconds: Math.ceil(response.estimatedDuration / 1_000) }),
665
- liquiditySource: 'providerQuote',
666
- sourceDetail: 'rhino:bridge-swap-public',
667
- tier: 'liquid',
668
- },
669
- sampledAt: options.now.toISOString(),
670
- status: 'available',
671
- }
672
- }
673
-
674
- function formatSquidResult(
675
- candidate: FundingQuotes.QuoteCandidate,
676
- quote: unknown,
677
- now: Date,
678
- ): FundingQuotes.QuoteProbeResult {
679
- const parsed = schema.SquidQuote.safeParse(quote)
680
- if (!parsed.success) throw new ProviderPayloadError()
681
- const response = parsed.data.route.estimate
682
- if (
683
- response.fromAmount !== candidate.sourceAmount.amount ||
684
- !matchesSquidToken(response.fromToken, candidate.sourceChain, candidate.sourceToken) ||
685
- !matchesSquidToken(response.toToken, candidate.destinationChain, candidate.destinationToken) ||
686
- BigInt(response.toAmount) <= 0n ||
687
- BigInt(response.toAmountMin) <= 0n ||
688
- BigInt(response.toAmountMin) > BigInt(response.toAmount)
689
- )
690
- throw new ProviderPayloadError()
691
-
692
- return {
693
- minimumOutputAmount: response.toAmountMin,
694
- outputAmount: response.toAmount,
695
- quality: {
696
- estimatedSeconds: Math.ceil(response.estimatedRouteDuration),
697
- liquiditySource: 'providerQuote',
698
- sourceDetail: 'squid:route-v2',
699
- tier: 'liquid',
700
- },
701
- sampledAt: now.toISOString(),
702
- status: 'available',
703
- }
704
- }
705
-
706
- function formatSymbiosisResult(
707
- candidate: FundingQuotes.QuoteCandidate,
708
- quote: unknown,
709
- now: Date,
710
- ): FundingQuotes.QuoteProbeResult {
711
- const parsed = schema.SymbiosisQuote.safeParse(quote)
712
- if (!parsed.success) throw new ProviderPayloadError()
713
- const response = parsed.data
714
- const sourceChainId = Number(providerChainId(candidate.sourceChain, 'symbiosis'))
715
- const sourceToken = symbiosisSourceToken(candidate.sourceChain, candidate.sourceToken)
716
- const firstToken = response.routes[0]!.tokens[0]!
717
- const lastRoute = response.routes[response.routes.length - 1]!
718
- const lastToken = lastRoute.tokens[lastRoute.tokens.length - 1]!
719
- if (
720
- response.tx.chainId !== sourceChainId ||
721
- response.type !== candidate.sourceChain.kind ||
722
- !matchesSymbiosisToken(firstToken, {
723
- address: sourceToken,
724
- chainId: sourceChainId,
725
- decimals: candidate.sourceToken.decimals,
726
- }) ||
727
- !matchesSymbiosisToken(lastToken, {
728
- address: candidate.destinationToken.address,
729
- chainId: Number(eip155ChainId(candidate.destinationChain)),
730
- decimals: candidate.destinationToken.decimals,
731
- }) ||
732
- !matchesSymbiosisToken(response.tokenAmountOut, {
733
- address: candidate.destinationToken.address,
734
- chainId: Number(eip155ChainId(candidate.destinationChain)),
735
- decimals: candidate.destinationToken.decimals,
736
- }) ||
737
- !matchesSymbiosisToken(response.tokenAmountOutMin, {
738
- address: candidate.destinationToken.address,
739
- chainId: Number(eip155ChainId(candidate.destinationChain)),
740
- decimals: candidate.destinationToken.decimals,
741
- }) ||
742
- BigInt(response.tokenAmountOut.amount) <= 0n ||
743
- BigInt(response.tokenAmountOutMin.amount) <= 0n ||
744
- BigInt(response.tokenAmountOutMin.amount) > BigInt(response.tokenAmountOut.amount)
745
- )
746
- throw new ProviderPayloadError()
747
-
748
- return {
749
- minimumOutputAmount: response.tokenAmountOutMin.amount,
750
- outputAmount: response.tokenAmountOut.amount,
751
- quality: {
752
- ...(response.estimatedTime === undefined
753
- ? {}
754
- : { estimatedSeconds: Math.ceil(response.estimatedTime) }),
755
- liquiditySource: 'providerQuote',
756
- sourceDetail: 'symbiosis:quote-v2',
757
- tier: 'liquid',
758
- },
759
- sampledAt: now.toISOString(),
760
- status: 'available',
761
- }
762
- }
763
-
764
- function unavailableResult(options: {
765
- detail: string
766
- message: string
767
- now: Date
768
- source: string
769
- }): FundingQuotes.QuoteProbeResult {
770
- return {
771
- quality: {
772
- liquiditySource: options.source,
773
- sourceDetail: `${options.detail}:${options.message}`,
774
- tier: 'unavailable',
775
- },
776
- sampledAt: options.now.toISOString(),
777
- status: 'unavailable',
778
- }
779
- }
780
-
781
- async function requestJson(
782
- url: URL,
783
- options: {
784
- body?: unknown
785
- fetcher: Fetch
786
- headers?: Record<string, string> | undefined
787
- method?: string | undefined
788
- signal: AbortSignal
789
- },
790
- ) {
791
- const headers = { accept: 'application/json', ...options.headers }
792
- const init: RequestInit = {
793
- headers:
794
- options.body === undefined ? headers : { ...headers, 'content-type': 'application/json' },
795
- method: options.method ?? 'GET',
796
- signal: options.signal,
797
- }
798
- if (options.body !== undefined) init.body = JSON.stringify(options.body)
799
- const response = await options.fetcher(url, init)
800
- const text = await response.text()
801
- const body = parseJson(text)
802
- if (!response.ok) throw new ProviderResponseError(response.status, body)
803
- return body
804
- }
805
-
806
- function relayHeaders(apiKey: string | undefined): Record<string, string> | undefined {
807
- return apiKey ? { 'x-api-key': apiKey } : undefined
808
- }
809
-
810
- function providerUnavailable(cause: unknown, codes: readonly string[]) {
811
- if (!(cause instanceof ProviderResponseError) || cause.status < 400 || cause.status >= 500)
812
- return undefined
813
- const code = providerErrorCode(cause.body)
814
- if (code && codes.includes(code)) return code
815
- return undefined
816
- }
817
-
818
- function providerErrorCode(input: unknown) {
819
- const body = record(input)
820
- const error = record(body['error'])
821
- const code =
822
- stringValue(body['_tag']) ??
823
- stringValue(body['code']) ??
824
- stringValue(body['errorCode']) ??
825
- stringValue(body['errorType']) ??
826
- stringValue(body['type']) ??
827
- stringValue(error['code']) ??
828
- stringValue(error['type'])
829
- return code && /^[A-Za-z0-9_.:-]{1,64}$/.test(code) ? code : undefined
830
- }
831
-
832
- function squidUnavailable(cause: unknown) {
833
- if (!(cause instanceof ProviderResponseError) || cause.status !== 400) return undefined
834
- const body = record(cause.body)
835
- if (
836
- body['type'] === 'BAD_REQUEST' &&
837
- body['message'] === 'Please increase the swap amount and try again.'
838
- )
839
- return 'AMOUNT_TOO_LOW'
840
- return undefined
841
- }
842
-
843
- function symbiosisUnavailable(cause: unknown) {
844
- if (!(cause instanceof ProviderResponseError) || cause.status !== 400) return undefined
845
- const body = record(cause.body)
846
- if (body['message'] === 'Amount is too low to cover fees') return 'AMOUNT_TOO_LOW'
847
- return undefined
848
- }
849
-
850
- async function consumeSymbiosisQuota(store: Store.Store, now: Date) {
851
- const time = now.getTime()
852
- const bucket = Math.floor(time / symbiosisRateLimitWindowMs)
853
- const count = await Store.increment(store, `funding:symbiosis:quote:${bucket}`, {
854
- ttl: symbiosisRateLimitWindowMs * 2,
855
- })
856
- if (count > symbiosisRateLimit) throw new ProviderRateLimitError()
857
- }
858
-
859
- function providerChainId(
860
- quoteChain: FundingQuotes.QuoteCandidate['sourceChain'],
861
- provider: string,
862
- ) {
863
- const providerIds = quoteChain.providerIds as Record<string, string> | undefined
864
- const id = providerIds?.[provider]
865
- if (id && /^\d+$/.test(id)) return id
866
- return eip155ChainId(quoteChain)
867
- }
868
-
869
- function providerChainReference(
870
- quoteChain: FundingQuotes.QuoteCandidate['sourceChain'],
871
- provider: string,
872
- ) {
873
- const providerIds = quoteChain.providerIds as Record<string, string> | undefined
874
- const id = providerIds?.[provider]
875
- if (!id) throw new UnsupportedProviderChainError()
876
- return id
877
- }
878
-
879
- function rhinoToken(token: FundingQuotes.TokenRef) {
880
- const tokens: Record<string, string> = {
881
- '0x20c00000000000000000000014f22ca97301eb73': 'USDT',
882
- '0x20c000000000000000000000b9537d11c60e8b50': 'USDC',
883
- }
884
- const id = tokens[token.address.toLowerCase()]
885
- if (!id) throw new UnsupportedProviderTokenError()
886
- return id
887
- }
888
-
889
- function symbiosisSourceToken(chain: FundingQuotes.ChainRef, token: FundingQuotes.TokenRef) {
890
- if (chain.kind !== 'tron') return token.address
891
- const tokens: Record<string, string> = {
892
- TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t: '0xa614f803b6fd780986a42c78ec9c7f77e6ded13c',
893
- }
894
- const id = tokens[token.address]
895
- if (!id) throw new UnsupportedProviderTokenError()
896
- return id
897
- }
898
-
899
- function matchesToken(
900
- token: z.output<typeof schema.AcrossQuote>['inputToken'],
901
- chain: FundingQuotes.ChainRef,
902
- expected: FundingQuotes.TokenRef,
903
- ) {
904
- return (
905
- token.address.toLowerCase() === expected.address.toLowerCase() &&
906
- token.chainId === Number(eip155ChainId(chain)) &&
907
- token.decimals === expected.decimals
908
- )
909
- }
910
-
911
- function matchesSquidToken(
912
- token: z.output<typeof schema.SquidQuote>['route']['estimate']['fromToken'],
913
- chain: FundingQuotes.ChainRef,
914
- expected: FundingQuotes.TokenRef,
915
- ) {
916
- return (
917
- token.address.toLowerCase() === expected.address.toLowerCase() &&
918
- String(token.chainId) === eip155ChainId(chain) &&
919
- token.decimals === expected.decimals
920
- )
921
- }
922
-
923
- function matchesSymbiosisToken(
924
- token: z.output<typeof schema.SymbiosisToken>,
925
- options: matchesSymbiosisToken.Options,
926
- ) {
927
- return (
928
- token.address.toLowerCase() === options.address.toLowerCase() &&
929
- token.chainId === options.chainId &&
930
- token.decimals === options.decimals
931
- )
932
- }
933
-
934
- declare namespace matchesSymbiosisToken {
935
- /** Expected provider token identity. */
936
- type Options = {
937
- /** Provider-specific token address. */
938
- address: string
939
- /** Provider-specific chain id. */
940
- chainId: number
941
- /** Token decimal precision. */
942
- decimals: number
943
- }
944
- }
945
-
946
- function eip155ChainId(chain: { id: string; kind: string }) {
947
- if (chain.kind !== 'evm') throw new UnsupportedProviderChainError()
948
- const match = /^eip155:(\d+)$/.exec(chain.id)
949
- if (!match?.[1]) throw new UnsupportedProviderChainError()
950
- return match[1]
951
- }
952
-
953
- function normalizeBaseUrl(input: string) {
954
- return input.replace(/\/+$/, '')
955
- }
956
-
957
- function parseJson(input: string) {
958
- if (!input) return null
959
- try {
960
- return JSON.parse(input) as unknown
961
- } catch {
962
- return input
963
- }
964
- }
965
-
966
- function record(input: unknown): Record<string, unknown> {
967
- return input && typeof input === 'object' && !Array.isArray(input)
968
- ? (input as Record<string, unknown>)
969
- : {}
970
- }
971
-
972
- function stringValue(input: unknown) {
973
- return typeof input === 'string' && input.length > 0 ? input : undefined
974
- }
975
-
976
- function decimalString(input: unknown) {
977
- if (typeof input === 'string' && /^\d+(\.\d+)?$/.test(input)) return input
978
- if (typeof input === 'number' && Number.isFinite(input) && input >= 0) return String(input)
979
- return undefined
980
- }
981
-
982
- function nonnegativeInteger(input: unknown) {
983
- if (typeof input === 'number' && Number.isSafeInteger(input) && input >= 0) return input
984
- if (typeof input === 'string' && /^\d+$/.test(input)) return Number(input)
985
- return undefined
986
- }
987
-
988
- function baseUnitsFromDecimal(value: string, decimals: number) {
989
- if (!/^\d+(\.\d+)?$/.test(value)) return undefined
990
- const [whole, fraction = ''] = value.split('.')
991
- const significantFraction = fraction.replace(/0+$/, '')
992
- if (significantFraction.length > decimals) return undefined
993
- return BigInt(`${whole}${significantFraction.padEnd(decimals, '0')}`).toString()
994
- }
995
-
996
- function assertAcrossConfiguration(options: across.Options) {
997
- if (
998
- options.apiKey.length === 0 ||
999
- !/^0x[\da-fA-F]{4}$/.test(options.integratorId) ||
1000
- !/^0x[\da-fA-F]{40}$/.test(options.userAddress)
1001
- )
1002
- throw new ProviderConfigurationError()
1003
- }
1004
-
1005
- function assertSquidConfiguration(options: squid.Options) {
1006
- if (options.integratorId.length === 0) throw new ProviderConfigurationError()
1007
- assertUserAddress(options.userAddress)
1008
- }
1009
-
1010
- function assertUserAddress(userAddress: string) {
1011
- if (!/^0x[\da-fA-F]{40}$/.test(userAddress)) throw new ProviderConfigurationError()
1012
- }
1013
-
1014
- class ProviderConfigurationError extends Error {
1015
- override name = 'FundingQuoteProviders.ProviderConfigurationError'
1016
- }
1017
-
1018
- class ProviderPayloadError extends Error {
1019
- override name = 'FundingQuoteProviders.ProviderPayloadError'
1020
- }
1021
-
1022
- class ProviderRateLimitError extends Error {
1023
- override name = 'FundingQuoteProviders.ProviderRateLimitError'
1024
- }
1025
-
1026
- class ProviderResponseError extends Error {
1027
- override name = 'FundingQuoteProviders.ProviderResponseError'
1028
-
1029
- constructor(
1030
- readonly status: number,
1031
- readonly body: unknown,
1032
- ) {
1033
- super(`Provider request failed with status ${status}`)
1034
- }
1035
- }
1036
-
1037
- class UnsupportedProviderChainError extends Error {
1038
- override name = 'FundingQuoteProviders.UnsupportedProviderChainError'
1039
- }
1040
-
1041
- class UnsupportedProviderTokenError extends Error {
1042
- override name = 'FundingQuoteProviders.UnsupportedProviderTokenError'
1043
- }