tapimo 0.0.2 → 0.1.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 (265) hide show
  1. package/README.md +11 -2
  2. package/dist/ApiKey.d.ts +12 -11
  3. package/dist/ApiKey.d.ts.map +1 -1
  4. package/dist/ApiKey.js +10 -12
  5. package/dist/ApiKey.js.map +1 -1
  6. package/dist/ApiKeys.d.ts +139 -0
  7. package/dist/ApiKeys.d.ts.map +1 -0
  8. package/dist/ApiKeys.js +166 -0
  9. package/dist/ApiKeys.js.map +1 -0
  10. package/dist/App.d.ts +920 -910
  11. package/dist/App.d.ts.map +1 -1
  12. package/dist/App.js +36 -12
  13. package/dist/App.js.map +1 -1
  14. package/dist/Handler.d.ts +86 -0
  15. package/dist/Handler.d.ts.map +1 -0
  16. package/dist/Handler.js +83 -0
  17. package/dist/Handler.js.map +1 -0
  18. package/dist/Scope.d.ts +4 -1
  19. package/dist/Scope.d.ts.map +1 -1
  20. package/dist/Scope.js +5 -1
  21. package/dist/Scope.js.map +1 -1
  22. package/dist/Webhooks.d.ts +3 -5
  23. package/dist/Webhooks.d.ts.map +1 -1
  24. package/dist/Webhooks.js +9 -2
  25. package/dist/Webhooks.js.map +1 -1
  26. package/dist/admin/Access.d.ts +1 -3
  27. package/dist/admin/Access.d.ts.map +1 -1
  28. package/dist/admin/Access.js +1 -3
  29. package/dist/admin/Access.js.map +1 -1
  30. package/dist/admin/App.d.ts +98 -209
  31. package/dist/admin/App.d.ts.map +1 -1
  32. package/dist/admin/App.js +2 -4
  33. package/dist/admin/App.js.map +1 -1
  34. package/dist/admin/apps/api-keys.d.ts +7 -5
  35. package/dist/admin/apps/api-keys.d.ts.map +1 -1
  36. package/dist/admin/apps/api-keys.js +8 -9
  37. package/dist/admin/apps/api-keys.js.map +1 -1
  38. package/dist/admin/apps/scopes.d.ts +3 -0
  39. package/dist/admin/apps/scopes.d.ts.map +1 -1
  40. package/dist/admin/apps/verified-tokens.d.ts +101 -215
  41. package/dist/admin/apps/verified-tokens.d.ts.map +1 -1
  42. package/dist/admin/apps/verified-tokens.js +17 -38
  43. package/dist/admin/apps/verified-tokens.js.map +1 -1
  44. package/dist/admin/ui.generated.d.ts +1 -1
  45. package/dist/admin/ui.generated.js +1 -1
  46. package/dist/apps/balances.d.ts +2 -2
  47. package/dist/apps/receipts.d.ts +43 -43
  48. package/dist/apps/tokens.d.ts +454 -454
  49. package/dist/apps/transactions.d.ts +43 -43
  50. package/dist/apps/transfers.d.ts +29 -29
  51. package/dist/apps/webhooks.d.ts +5 -2
  52. package/dist/apps/webhooks.d.ts.map +1 -1
  53. package/dist/apps/webhooks.js +38 -34
  54. package/dist/apps/webhooks.js.map +1 -1
  55. package/dist/{Cli.d.ts → cli/Cli.d.ts} +13 -2
  56. package/dist/cli/Cli.d.ts.map +1 -0
  57. package/dist/cli/Cli.js +19 -0
  58. package/dist/cli/Cli.js.map +1 -0
  59. package/dist/cli/bin.d.ts +3 -0
  60. package/dist/cli/bin.d.ts.map +1 -0
  61. package/dist/cli/bin.js +4 -0
  62. package/dist/cli/bin.js.map +1 -0
  63. package/dist/cli/commands/admin.d.ts +15 -0
  64. package/dist/cli/commands/admin.d.ts.map +1 -0
  65. package/dist/cli/commands/admin.js +60 -0
  66. package/dist/cli/commands/admin.js.map +1 -0
  67. package/dist/cloudflare.d.ts +7 -0
  68. package/dist/cloudflare.d.ts.map +1 -1
  69. package/dist/cloudflare.js +9 -0
  70. package/dist/cloudflare.js.map +1 -1
  71. package/dist/db/Db.d.ts +103 -0
  72. package/dist/db/Db.d.ts.map +1 -0
  73. package/dist/db/Db.js +274 -0
  74. package/dist/db/Db.js.map +1 -0
  75. package/dist/db/Schema.d.ts +88 -0
  76. package/dist/db/Schema.d.ts.map +1 -0
  77. package/dist/db/Schema.js +130 -0
  78. package/dist/db/Schema.js.map +1 -0
  79. package/dist/db/tables/organizations.d.ts +79 -0
  80. package/dist/db/tables/organizations.d.ts.map +1 -0
  81. package/dist/db/tables/organizations.js +81 -0
  82. package/dist/db/tables/organizations.js.map +1 -0
  83. package/dist/db/tables/verifiedTokens.d.ts +53 -0
  84. package/dist/db/tables/verifiedTokens.d.ts.map +1 -0
  85. package/dist/db/tables/verifiedTokens.js +74 -0
  86. package/dist/db/tables/verifiedTokens.js.map +1 -0
  87. package/dist/db/tables/webhookDeliveries.d.ts +71 -0
  88. package/dist/db/tables/webhookDeliveries.d.ts.map +1 -0
  89. package/dist/db/tables/webhookDeliveries.js +119 -0
  90. package/dist/db/tables/webhookDeliveries.js.map +1 -0
  91. package/dist/db/tables/webhookSubscriptions.d.ts +158 -0
  92. package/dist/db/tables/webhookSubscriptions.d.ts.map +1 -0
  93. package/dist/db/tables/webhookSubscriptions.js +272 -0
  94. package/dist/db/tables/webhookSubscriptions.js.map +1 -0
  95. package/dist/handlers/internal/executionError.d.ts +25 -0
  96. package/dist/handlers/internal/executionError.d.ts.map +1 -0
  97. package/dist/handlers/internal/executionError.js +184 -0
  98. package/dist/handlers/internal/executionError.js.map +1 -0
  99. package/dist/handlers/internal/multisig.d.ts +237 -0
  100. package/dist/handlers/internal/multisig.d.ts.map +1 -0
  101. package/dist/handlers/internal/multisig.js +567 -0
  102. package/dist/handlers/internal/multisig.js.map +1 -0
  103. package/dist/handlers/internal/requestListener.d.ts +124 -0
  104. package/dist/handlers/internal/requestListener.d.ts.map +1 -0
  105. package/dist/handlers/internal/requestListener.js +173 -0
  106. package/dist/handlers/internal/requestListener.js.map +1 -0
  107. package/dist/handlers/internal/sponsorship.d.ts +83 -0
  108. package/dist/handlers/internal/sponsorship.d.ts.map +1 -0
  109. package/dist/handlers/internal/sponsorship.js +103 -0
  110. package/dist/handlers/internal/sponsorship.js.map +1 -0
  111. package/dist/handlers/internal/types.d.ts +284 -0
  112. package/dist/handlers/internal/types.d.ts.map +1 -0
  113. package/dist/handlers/internal/types.js +2 -0
  114. package/dist/handlers/internal/types.js.map +1 -0
  115. package/dist/handlers/internal/utils.d.ts +34 -0
  116. package/dist/handlers/internal/utils.d.ts.map +1 -0
  117. package/dist/handlers/internal/utils.js +131 -0
  118. package/dist/handlers/internal/utils.js.map +1 -0
  119. package/dist/handlers/relay.d.ts +119 -0
  120. package/dist/handlers/relay.d.ts.map +1 -0
  121. package/dist/handlers/relay.js +1264 -0
  122. package/dist/handlers/relay.js.map +1 -0
  123. package/dist/index.d.ts +4 -2
  124. package/dist/index.d.ts.map +1 -1
  125. package/dist/index.js +4 -2
  126. package/dist/index.js.map +1 -1
  127. package/dist/internal/Auth.d.ts +16 -10
  128. package/dist/internal/Auth.d.ts.map +1 -1
  129. package/dist/internal/Auth.js +72 -12
  130. package/dist/internal/Auth.js.map +1 -1
  131. package/dist/internal/RpcSchema.d.ts +10 -0
  132. package/dist/internal/RpcSchema.d.ts.map +1 -0
  133. package/dist/internal/RpcSchema.js +2 -0
  134. package/dist/internal/RpcSchema.js.map +1 -0
  135. package/dist/internal/Store.d.ts +42 -3
  136. package/dist/internal/Store.d.ts.map +1 -1
  137. package/dist/internal/Store.js +65 -3
  138. package/dist/internal/Store.js.map +1 -1
  139. package/dist/internal/VerifiedTokens.d.ts +15 -34
  140. package/dist/internal/VerifiedTokens.d.ts.map +1 -1
  141. package/dist/internal/VerifiedTokens.js +115 -159
  142. package/dist/internal/VerifiedTokens.js.map +1 -1
  143. package/dist/internal/Webhooks.d.ts +49 -35
  144. package/dist/internal/Webhooks.d.ts.map +1 -1
  145. package/dist/internal/Webhooks.js +92 -205
  146. package/dist/internal/Webhooks.js.map +1 -1
  147. package/package.json +7 -2
  148. package/src/ApiKey.test.ts +3 -3
  149. package/src/ApiKey.ts +10 -12
  150. package/src/ApiKeys.test.ts +175 -0
  151. package/src/ApiKeys.ts +205 -0
  152. package/src/App.test-d.ts +1 -1
  153. package/src/App.test.ts +10768 -351
  154. package/src/App.ts +79 -36
  155. package/src/Client.test-d.ts +1 -1
  156. package/src/Handler.ts +154 -0
  157. package/src/Scope.ts +5 -1
  158. package/src/Webhooks.test.ts +8 -7
  159. package/src/Webhooks.ts +11 -5
  160. package/src/admin/Access.ts +1 -3
  161. package/src/admin/App.ts +19 -24
  162. package/src/admin/apps/api-keys.test.ts +19 -18
  163. package/src/admin/apps/api-keys.ts +8 -9
  164. package/src/admin/apps/scopes.test.ts +4 -0
  165. package/src/admin/apps/verified-tokens.test.ts +3 -30
  166. package/src/admin/apps/verified-tokens.ts +17 -36
  167. package/src/admin/ui.generated.ts +1 -1
  168. package/src/apps/balances.test.ts +4 -3
  169. package/src/apps/blocks.test.ts +1 -1
  170. package/src/apps/exchanges.test.ts +1 -1
  171. package/src/apps/indexer.test.ts +1 -1
  172. package/src/apps/receipts.test.ts +1 -1
  173. package/src/apps/rpc.test.ts +100 -10
  174. package/src/apps/tokenlist.test.ts +5 -7
  175. package/src/apps/tokens.test.ts +4 -3
  176. package/src/apps/transactions.test.ts +1 -1
  177. package/src/apps/transfers.test.ts +1 -1
  178. package/src/apps/verified-tokens.test.ts +24 -12
  179. package/src/apps/webhooks.test.ts +130 -143
  180. package/src/apps/webhooks.ts +45 -47
  181. package/src/{Cli.test.ts → cli/Cli.test.ts} +10 -9
  182. package/src/{Cli.ts → cli/Cli.ts} +16 -9
  183. package/src/cli/bin.ts +4 -0
  184. package/src/cli/commands/admin.test.ts +71 -0
  185. package/src/cli/commands/admin.ts +60 -0
  186. package/src/cloudflare.ts +10 -0
  187. package/src/db/Db.test.ts +84 -0
  188. package/src/db/Db.ts +383 -0
  189. package/src/db/Schema.ts +164 -0
  190. package/src/db/tables/organizations.test.ts +124 -0
  191. package/src/db/tables/organizations.ts +127 -0
  192. package/src/db/tables/verifiedTokens.ts +111 -0
  193. package/src/db/tables/webhookDeliveries.ts +159 -0
  194. package/src/db/tables/webhookSubscriptions.ts +358 -0
  195. package/src/handlers/internal/executionError.ts +205 -0
  196. package/src/handlers/internal/multisig.localnet.test.ts +146 -0
  197. package/src/handlers/internal/multisig.test.ts +744 -0
  198. package/src/handlers/internal/multisig.ts +858 -0
  199. package/src/handlers/internal/relay.localnet.test.ts +2035 -0
  200. package/src/handlers/internal/requestListener.ts +273 -0
  201. package/src/handlers/internal/sponsorship.ts +186 -0
  202. package/src/handlers/internal/types.ts +378 -0
  203. package/src/handlers/internal/utils.ts +153 -0
  204. package/src/handlers/relay.ts +1605 -0
  205. package/src/index.ts +4 -2
  206. package/src/internal/Auth.test.ts +21 -21
  207. package/src/internal/Auth.ts +92 -19
  208. package/src/internal/RateLimit.test.ts +1 -1
  209. package/src/internal/RpcSchema.ts +10 -0
  210. package/src/internal/Store.test.ts +98 -10
  211. package/src/internal/Store.ts +112 -6
  212. package/src/internal/VerifiedTokens.test.ts +99 -115
  213. package/src/internal/VerifiedTokens.ts +123 -175
  214. package/src/internal/Webhooks.test.ts +107 -107
  215. package/src/internal/Webhooks.ts +102 -220
  216. package/dist/ApiKeySource.d.ts +0 -166
  217. package/dist/ApiKeySource.d.ts.map +0 -1
  218. package/dist/ApiKeySource.js +0 -234
  219. package/dist/ApiKeySource.js.map +0 -1
  220. package/dist/Cli.d.ts.map +0 -1
  221. package/dist/Cli.js +0 -13
  222. package/dist/Cli.js.map +0 -1
  223. package/seeds/31318/icons/0x20c0000000000000000000000000000000000000.svg +0 -1
  224. package/seeds/31318/icons/0x20c0000000000000000000000000000000000001.svg +0 -1
  225. package/seeds/31318/icons/0x20c0000000000000000000000000000000000002.svg +0 -1
  226. package/seeds/31318/icons/0x20c0000000000000000000000000000000000003.svg +0 -1
  227. package/seeds/31318/verified-tokens.json +0 -30
  228. package/seeds/4217/icons/0x20c0000000000000000000000000000000000000.svg +0 -25
  229. package/seeds/4217/icons/0x20c000000000000000000000048c8f36df1c9a4a.svg +0 -1
  230. package/seeds/4217/icons/0x20c0000000000000000000000520792dcccccccc.svg +0 -1
  231. package/seeds/4217/icons/0x20c0000000000000000000000a6da882d075a4c3.svg +0 -4
  232. package/seeds/4217/icons/0x20c000000000000000000000111111111e910f0f.svg +0 -30
  233. package/seeds/4217/icons/0x20c00000000000000000000014f22ca97301eb73.svg +0 -1
  234. package/seeds/4217/icons/0x20c0000000000000000000001621e21f71cf12fb.svg +0 -1
  235. package/seeds/4217/icons/0x20c0000000000000000000002f52d5cc21a3207b.svg +0 -1
  236. package/seeds/4217/icons/0x20c0000000000000000000003158081efd85bfc2.svg +0 -11
  237. package/seeds/4217/icons/0x20c0000000000000000000003554d28269e0f3c2.svg +0 -1
  238. package/seeds/4217/icons/0x20c000000000000000000000383a23bacb546ab9.svg +0 -1
  239. package/seeds/4217/icons/0x20c00000000000000000000042109aef2f8b28e1.png +0 -0
  240. package/seeds/4217/icons/0x20c0000000000000000000005c0bac7cef389a11.svg +0 -1
  241. package/seeds/4217/icons/0x20c0000000000000000000006fd9a167923ba194.png +0 -0
  242. package/seeds/4217/icons/0x20c0000000000000000000007f7ba549dd0251b9.svg +0 -1
  243. package/seeds/4217/icons/0x20c0000000000000000000008191667423f70e67.svg +0 -5
  244. package/seeds/4217/icons/0x20c0000000000000000000008ee4fcff88888888.svg +0 -1
  245. package/seeds/4217/icons/0x20c0000000000000000000009a4a4b17e0dc6651.svg +0 -1
  246. package/seeds/4217/icons/0x20c000000000000000000000ab02d39df30bd17e.svg +0 -1
  247. package/seeds/4217/icons/0x20c000000000000000000000ae247a1130450f09.svg +0 -1
  248. package/seeds/4217/icons/0x20c000000000000000000000aeed2ec36a54d0e5.svg +0 -1
  249. package/seeds/4217/icons/0x20c000000000000000000000b9537d11c60e8b50.svg +0 -1
  250. package/seeds/4217/icons/0x20c000000000000000000000bd95bfb69fbe6ce3.svg +0 -1
  251. package/seeds/4217/icons/0x20c000000000000000000000c412ec89d0c08be5.svg +0 -1
  252. package/seeds/4217/icons/0x20c000000000000000000000f047dd7018e50367.png +0 -0
  253. package/seeds/4217/verified-tokens.json +0 -177
  254. package/seeds/42431/icons/0x20c0000000000000000000000000000000000000.svg +0 -25
  255. package/seeds/42431/icons/0x20c0000000000000000000000000000000000001.svg +0 -1
  256. package/seeds/42431/icons/0x20c0000000000000000000000000000000000002.svg +0 -1
  257. package/seeds/42431/icons/0x20c0000000000000000000000000000000000003.svg +0 -1
  258. package/seeds/42431/icons/0x20c0000000000000000000009e8d7eb59b783726.svg +0 -1
  259. package/seeds/42431/icons/0x20c000000000000000000000d72572838bbee59c.svg +0 -1
  260. package/seeds/42431/verified-tokens.json +0 -44
  261. package/seeds/openrpc/README.md +0 -27
  262. package/seeds/openrpc/execution-apis.json +0 -8989
  263. package/src/ApiKeySource.test-d.ts +0 -11
  264. package/src/ApiKeySource.test.ts +0 -295
  265. package/src/ApiKeySource.ts +0 -303
@@ -0,0 +1,158 @@
1
+ import type { Selectable } from 'kysely';
2
+ import type * as Webhooks from '../../internal/Webhooks.js';
3
+ import type * as Db from '../Db.js';
4
+ import type * as db_Schema from '../Schema.js';
5
+ /** Columns of the `webhook_subscriptions` table, derived from `Schema.WebhookSubscription`. */
6
+ export type Table = db_Schema.WebhookSubscription;
7
+ /** A stored webhook-subscription row. */
8
+ export type Record = Selectable<Table>;
9
+ /** Maps an owner union to its stored `ownerId` column value. */
10
+ export declare function ownerId(owner: Webhooks.Owner): string;
11
+ /** Maps a stored row to the domain subscription (null columns → absent fields). */
12
+ export declare function toSubscription(row: Record): Webhooks.Subscription;
13
+ /**
14
+ * Inserts a subscription row from its domain value.
15
+ *
16
+ * @param db - The database.
17
+ * @param subscription - The subscription to insert.
18
+ */
19
+ export declare function insert(db: Db.Db, subscription: Webhooks.Subscription): Promise<void>;
20
+ /**
21
+ * Reads an owner's subscription by id; expired rows never match (query-time
22
+ * expiry, same read semantics as the old store TTL).
23
+ *
24
+ * @param db - The database.
25
+ * @param owner - The authenticated owner.
26
+ * @param id - The subscription id (`wh_…`).
27
+ * @param now - ISO timestamp expiry is evaluated against.
28
+ * @returns The subscription, or `null` when absent (or not the owner's).
29
+ */
30
+ export declare function get(db: Db.Db, owner: Webhooks.Owner, id: string, now: string): Promise<Webhooks.Subscription | null>;
31
+ /**
32
+ * Lists an owner's live subscriptions, newest first, with keyset paging
33
+ * (`id < cursor` — ids embed a zero-padded timestamp, so lexical order is
34
+ * chronological).
35
+ *
36
+ * @param db - The database.
37
+ * @param owner - The authenticated owner.
38
+ * @param options - Paging options plus the expiry timestamp.
39
+ * @returns The subscriptions.
40
+ */
41
+ export declare function list(db: Db.Db, owner: Webhooks.Owner, options: list.Options): Promise<Webhooks.Subscription[]>;
42
+ export declare namespace list {
43
+ /** Options for {@link list}. */
44
+ type Options = {
45
+ /** Return subscriptions older than this id (keyset paging, newest first). */
46
+ cursor?: string | undefined;
47
+ /** Maximum subscriptions to return. */
48
+ limit?: number | undefined;
49
+ /** ISO timestamp expiry is evaluated against. */
50
+ now: string;
51
+ /** Rows to skip from the head (positional pagination; exclusive with `cursor`). */
52
+ offset?: number | undefined;
53
+ };
54
+ }
55
+ /**
56
+ * Counts an owner's live subscriptions.
57
+ *
58
+ * @param db - The database.
59
+ * @param owner - The authenticated owner.
60
+ * @param now - ISO timestamp expiry is evaluated against.
61
+ * @returns The count.
62
+ */
63
+ export declare function count(db: Db.Db, owner: Webhooks.Owner, now: string): Promise<number>;
64
+ /**
65
+ * Applies a column patch to a subscription. Only the provided columns are
66
+ * written; `context: null` clears the stored context.
67
+ *
68
+ * @param db - The database.
69
+ * @param id - The subscription id (`wh_…`).
70
+ * @param set - The columns to write.
71
+ * @returns The updated row's subscription, or `undefined` when absent.
72
+ */
73
+ export declare function update(db: Db.Db, id: string, set: update.Set): Promise<Webhooks.Subscription | undefined>;
74
+ export declare namespace update {
75
+ /** Columns writable by a subscription patch. */
76
+ type Set = {
77
+ /** New human context; null clears it. */
78
+ context?: Webhooks.Context | null | undefined;
79
+ /** New delivery destination. */
80
+ destination?: Webhooks.Destination | undefined;
81
+ /** New filter predicates. */
82
+ filters?: Webhooks.Subscription['filters'] | undefined;
83
+ /** New lifecycle status. */
84
+ status?: Webhooks.Status | undefined;
85
+ /** Mutation timestamp (ISO). */
86
+ updatedAt: string;
87
+ };
88
+ }
89
+ /**
90
+ * Deletes an owner's live subscription; delivery rows cascade via the FK.
91
+ *
92
+ * @param db - The database.
93
+ * @param owner - The authenticated owner.
94
+ * @param id - The subscription id (`wh_…`).
95
+ * @param now - ISO timestamp expiry is evaluated against.
96
+ * @returns Whether a row was deleted.
97
+ */
98
+ export declare function remove(db: Db.Db, owner: Webhooks.Owner, id: string, now: string): Promise<boolean>;
99
+ /**
100
+ * Lists live `active` subscriptions for a `(chainId, eventType)` stream — the
101
+ * poller's per-stream lookup, served by the partial status index.
102
+ *
103
+ * @param db - The database.
104
+ * @param chainId - Chain the stream belongs to.
105
+ * @param eventType - Event type of the stream.
106
+ * @param now - ISO timestamp expiry is evaluated against.
107
+ * @returns The subscriptions, in id (chronological) order.
108
+ */
109
+ export declare function listActive(db: Db.Db, chainId: number, eventType: Webhooks.EventType, now: string): Promise<Webhooks.Subscription[]>;
110
+ /**
111
+ * Reads a subscription's poller cursor.
112
+ *
113
+ * @param db - The database.
114
+ * @param id - The subscription id (`wh_…`).
115
+ * @returns The cursor, or `null` when unset (or the row is absent).
116
+ */
117
+ export declare function getCursor(db: Db.Db, id: string): Promise<string | null>;
118
+ /**
119
+ * Writes a subscription's poller cursor. Deliberately does not touch
120
+ * `updatedAt` — the cursor advances every tick and is not a user mutation.
121
+ *
122
+ * @param db - The database.
123
+ * @param id - The subscription id (`wh_…`).
124
+ * @param cursor - The keyset cursor to store.
125
+ */
126
+ export declare function setCursor(db: Db.Db, id: string, cursor: string): Promise<void>;
127
+ /**
128
+ * Records a successful delivery: resets the consecutive-failure counter and
129
+ * stamps `lastDeliveryAt`.
130
+ *
131
+ * @param db - The database.
132
+ * @param id - The subscription id (`wh_…`).
133
+ * @param now - Delivery timestamp (ISO).
134
+ * @returns The updated subscription, or `undefined` when the row is absent.
135
+ */
136
+ export declare function recordSuccess(db: Db.Db, id: string, now: string): Promise<Webhooks.Subscription | undefined>;
137
+ /**
138
+ * Records a failed delivery: atomically increments the consecutive-failure
139
+ * counter and disables the subscription once it reaches `maxFailures` (raw
140
+ * fragments use storage column names — they bypass the camelCase mapping).
141
+ *
142
+ * @param db - The database.
143
+ * @param id - The subscription id (`wh_…`).
144
+ * @param maxFailures - Consecutive failures before auto-disabling.
145
+ * @param now - Failure timestamp (ISO).
146
+ * @returns The updated subscription, or `undefined` when the row is absent.
147
+ */
148
+ export declare function recordFailure(db: Db.Db, id: string, maxFailures: number, now: string): Promise<Webhooks.Subscription | undefined>;
149
+ /**
150
+ * Deletes expired subscriptions (their delivery rows cascade). Called
151
+ * best-effort from the poller tick.
152
+ *
153
+ * @param db - The database.
154
+ * @param now - ISO timestamp expiry is evaluated against.
155
+ * @returns The number of rows deleted.
156
+ */
157
+ export declare function pruneExpired(db: Db.Db, now: string): Promise<number>;
158
+ //# sourceMappingURL=webhookSubscriptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhookSubscriptions.d.ts","sourceRoot":"","sources":["../../../src/db/tables/webhookSubscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAqB,UAAU,EAAE,MAAM,QAAQ,CAAA;AAG3D,OAAO,KAAK,KAAK,QAAQ,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,KAAK,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,KAAK,KAAK,SAAS,MAAM,cAAc,CAAA;AAE9C,+FAA+F;AAC/F,MAAM,MAAM,KAAK,GAAG,SAAS,CAAC,mBAAmB,CAAA;AAEjD,yCAAyC;AACzC,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;AAEtC,gEAAgE;AAChE,wBAAgB,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,GAAG,MAAM,CAErD;AAED,mFAAmF;AACnF,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAC,YAAY,CAoBjE;AAED;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,YAAY,EAAE,QAAQ,CAA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GAAG,EAAE,MAAM,GACV,OAAO,CAAC,QAAQ,CAAC,YAAY,GAAG,SAAS,CAAC,CAQ5C;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,aAAa,CACjC,EAAE,EAAE,EAAE,CAAC,EAAE,EACT,EAAE,EAAE,MAAM,EACV,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,QAAQ,CAAC,YAAY,GAAG,SAAS,CAAC,CAY5C;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAO1E"}
@@ -0,0 +1,272 @@
1
+ import { sql } from 'kysely';
2
+ /** Maps an owner union to its stored `ownerId` column value. */
3
+ export function ownerId(owner) {
4
+ return owner.type === 'api_key' ? owner.orgId : owner.payer;
5
+ }
6
+ /** Maps a stored row to the domain subscription (null columns → absent fields). */
7
+ export function toSubscription(row) {
8
+ return {
9
+ chainId: row.chainId,
10
+ ...(row.context === null ? {} : { context: row.context }),
11
+ createdAt: row.createdAt,
12
+ destination: row.destination,
13
+ eventType: row.eventType,
14
+ ...(row.expiresAt === null ? {} : { expiresAt: row.expiresAt }),
15
+ failureCount: row.failureCount,
16
+ filters: row.filters,
17
+ id: row.id,
18
+ ...(row.lastDeliveryAt === null ? {} : { lastDeliveryAt: row.lastDeliveryAt }),
19
+ owner: row.ownerType === 'api_key'
20
+ ? { orgId: row.ownerId, type: 'api_key' }
21
+ : { payer: row.ownerId, type: 'mpp' },
22
+ secret: row.secret,
23
+ status: row.status,
24
+ updatedAt: row.updatedAt,
25
+ };
26
+ }
27
+ /**
28
+ * Inserts a subscription row from its domain value.
29
+ *
30
+ * @param db - The database.
31
+ * @param subscription - The subscription to insert.
32
+ */
33
+ export async function insert(db, subscription) {
34
+ await db.kysely
35
+ .insertInto('webhook_subscriptions')
36
+ .values({
37
+ chainId: subscription.chainId,
38
+ context: subscription.context ?? null,
39
+ createdAt: subscription.createdAt,
40
+ destination: subscription.destination,
41
+ eventType: subscription.eventType,
42
+ expiresAt: subscription.expiresAt ?? null,
43
+ failureCount: subscription.failureCount,
44
+ filters: subscription.filters,
45
+ id: subscription.id,
46
+ lastDeliveryAt: subscription.lastDeliveryAt ?? null,
47
+ ownerId: ownerId(subscription.owner),
48
+ ownerType: subscription.owner.type,
49
+ pollerCursor: null,
50
+ secret: subscription.secret,
51
+ status: subscription.status,
52
+ updatedAt: subscription.updatedAt,
53
+ })
54
+ .execute();
55
+ }
56
+ /**
57
+ * Reads an owner's subscription by id; expired rows never match (query-time
58
+ * expiry, same read semantics as the old store TTL).
59
+ *
60
+ * @param db - The database.
61
+ * @param owner - The authenticated owner.
62
+ * @param id - The subscription id (`wh_…`).
63
+ * @param now - ISO timestamp expiry is evaluated against.
64
+ * @returns The subscription, or `null` when absent (or not the owner's).
65
+ */
66
+ export async function get(db, owner, id, now) {
67
+ const row = await db.kysely
68
+ .selectFrom('webhook_subscriptions')
69
+ .selectAll()
70
+ .where('id', '=', id)
71
+ .where('ownerType', '=', owner.type)
72
+ .where('ownerId', '=', ownerId(owner))
73
+ .where(live(now))
74
+ .executeTakeFirst();
75
+ return row ? toSubscription(row) : null;
76
+ }
77
+ /**
78
+ * Lists an owner's live subscriptions, newest first, with keyset paging
79
+ * (`id < cursor` — ids embed a zero-padded timestamp, so lexical order is
80
+ * chronological).
81
+ *
82
+ * @param db - The database.
83
+ * @param owner - The authenticated owner.
84
+ * @param options - Paging options plus the expiry timestamp.
85
+ * @returns The subscriptions.
86
+ */
87
+ export async function list(db, owner, options) {
88
+ let query = db.kysely
89
+ .selectFrom('webhook_subscriptions')
90
+ .selectAll()
91
+ .where('ownerType', '=', owner.type)
92
+ .where('ownerId', '=', ownerId(owner))
93
+ .where(live(options.now))
94
+ .orderBy('id', 'desc');
95
+ if (options.cursor)
96
+ query = query.where('id', '<', options.cursor);
97
+ if (options.offset)
98
+ query = query.offset(options.offset);
99
+ if (options.limit !== undefined)
100
+ query = query.limit(options.limit);
101
+ return (await query.execute()).map(toSubscription);
102
+ }
103
+ /**
104
+ * Counts an owner's live subscriptions.
105
+ *
106
+ * @param db - The database.
107
+ * @param owner - The authenticated owner.
108
+ * @param now - ISO timestamp expiry is evaluated against.
109
+ * @returns The count.
110
+ */
111
+ export async function count(db, owner, now) {
112
+ const row = await db.kysely
113
+ .selectFrom('webhook_subscriptions')
114
+ .select((eb) => eb.fn.countAll().as('count'))
115
+ .where('ownerType', '=', owner.type)
116
+ .where('ownerId', '=', ownerId(owner))
117
+ .where(live(now))
118
+ .executeTakeFirstOrThrow();
119
+ return Number(row.count);
120
+ }
121
+ /**
122
+ * Applies a column patch to a subscription. Only the provided columns are
123
+ * written; `context: null` clears the stored context.
124
+ *
125
+ * @param db - The database.
126
+ * @param id - The subscription id (`wh_…`).
127
+ * @param set - The columns to write.
128
+ * @returns The updated row's subscription, or `undefined` when absent.
129
+ */
130
+ export async function update(db, id, set) {
131
+ const row = await db.kysely
132
+ .updateTable('webhook_subscriptions')
133
+ .set(set)
134
+ .where('id', '=', id)
135
+ .returningAll()
136
+ .executeTakeFirst();
137
+ return row ? toSubscription(row) : undefined;
138
+ }
139
+ /**
140
+ * Deletes an owner's live subscription; delivery rows cascade via the FK.
141
+ *
142
+ * @param db - The database.
143
+ * @param owner - The authenticated owner.
144
+ * @param id - The subscription id (`wh_…`).
145
+ * @param now - ISO timestamp expiry is evaluated against.
146
+ * @returns Whether a row was deleted.
147
+ */
148
+ export async function remove(db, owner, id, now) {
149
+ const result = await db.kysely
150
+ .deleteFrom('webhook_subscriptions')
151
+ .where('id', '=', id)
152
+ .where('ownerType', '=', owner.type)
153
+ .where('ownerId', '=', ownerId(owner))
154
+ .where(live(now))
155
+ .executeTakeFirst();
156
+ return result.numDeletedRows > 0n;
157
+ }
158
+ /**
159
+ * Lists live `active` subscriptions for a `(chainId, eventType)` stream — the
160
+ * poller's per-stream lookup, served by the partial status index.
161
+ *
162
+ * @param db - The database.
163
+ * @param chainId - Chain the stream belongs to.
164
+ * @param eventType - Event type of the stream.
165
+ * @param now - ISO timestamp expiry is evaluated against.
166
+ * @returns The subscriptions, in id (chronological) order.
167
+ */
168
+ export async function listActive(db, chainId, eventType, now) {
169
+ const rows = await db.kysely
170
+ .selectFrom('webhook_subscriptions')
171
+ .selectAll()
172
+ .where('chainId', '=', chainId)
173
+ .where('eventType', '=', eventType)
174
+ .where('status', '=', 'active')
175
+ .where(live(now))
176
+ .orderBy('id')
177
+ .execute();
178
+ return rows.map(toSubscription);
179
+ }
180
+ /**
181
+ * Reads a subscription's poller cursor.
182
+ *
183
+ * @param db - The database.
184
+ * @param id - The subscription id (`wh_…`).
185
+ * @returns The cursor, or `null` when unset (or the row is absent).
186
+ */
187
+ export async function getCursor(db, id) {
188
+ const row = await db.kysely
189
+ .selectFrom('webhook_subscriptions')
190
+ .select('pollerCursor')
191
+ .where('id', '=', id)
192
+ .executeTakeFirst();
193
+ return row?.pollerCursor ?? null;
194
+ }
195
+ /**
196
+ * Writes a subscription's poller cursor. Deliberately does not touch
197
+ * `updatedAt` — the cursor advances every tick and is not a user mutation.
198
+ *
199
+ * @param db - The database.
200
+ * @param id - The subscription id (`wh_…`).
201
+ * @param cursor - The keyset cursor to store.
202
+ */
203
+ export async function setCursor(db, id, cursor) {
204
+ await db.kysely
205
+ .updateTable('webhook_subscriptions')
206
+ .set({ pollerCursor: cursor })
207
+ .where('id', '=', id)
208
+ .execute();
209
+ }
210
+ /**
211
+ * Records a successful delivery: resets the consecutive-failure counter and
212
+ * stamps `lastDeliveryAt`.
213
+ *
214
+ * @param db - The database.
215
+ * @param id - The subscription id (`wh_…`).
216
+ * @param now - Delivery timestamp (ISO).
217
+ * @returns The updated subscription, or `undefined` when the row is absent.
218
+ */
219
+ export async function recordSuccess(db, id, now) {
220
+ const row = await db.kysely
221
+ .updateTable('webhook_subscriptions')
222
+ .set({ failureCount: 0, lastDeliveryAt: now, updatedAt: now })
223
+ .where('id', '=', id)
224
+ .returningAll()
225
+ .executeTakeFirst();
226
+ return row ? toSubscription(row) : undefined;
227
+ }
228
+ /**
229
+ * Records a failed delivery: atomically increments the consecutive-failure
230
+ * counter and disables the subscription once it reaches `maxFailures` (raw
231
+ * fragments use storage column names — they bypass the camelCase mapping).
232
+ *
233
+ * @param db - The database.
234
+ * @param id - The subscription id (`wh_…`).
235
+ * @param maxFailures - Consecutive failures before auto-disabling.
236
+ * @param now - Failure timestamp (ISO).
237
+ * @returns The updated subscription, or `undefined` when the row is absent.
238
+ */
239
+ export async function recordFailure(db, id, maxFailures, now) {
240
+ const row = await db.kysely
241
+ .updateTable('webhook_subscriptions')
242
+ .set({
243
+ failureCount: sql `failure_count + 1`,
244
+ status: sql `CASE WHEN failure_count + 1 >= ${maxFailures} THEN 'disabled' ELSE status END`,
245
+ updatedAt: now,
246
+ })
247
+ .where('id', '=', id)
248
+ .returningAll()
249
+ .executeTakeFirst();
250
+ return row ? toSubscription(row) : undefined;
251
+ }
252
+ /**
253
+ * Deletes expired subscriptions (their delivery rows cascade). Called
254
+ * best-effort from the poller tick.
255
+ *
256
+ * @param db - The database.
257
+ * @param now - ISO timestamp expiry is evaluated against.
258
+ * @returns The number of rows deleted.
259
+ */
260
+ export async function pruneExpired(db, now) {
261
+ const result = await db.kysely
262
+ .deleteFrom('webhook_subscriptions')
263
+ .where('expiresAt', 'is not', null)
264
+ .where('expiresAt', '<=', now)
265
+ .executeTakeFirst();
266
+ return Number(result.numDeletedRows);
267
+ }
268
+ /** Live-row predicate: no expiry, or expiry strictly in the future. */
269
+ function live(now) {
270
+ return (eb) => eb.or([eb('expiresAt', 'is', null), eb('expiresAt', '>', now)]);
271
+ }
272
+ //# sourceMappingURL=webhookSubscriptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhookSubscriptions.js","sourceRoot":"","sources":["../../../src/db/tables/webhookSubscriptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,QA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AE,QAAQ,EAAE,IAAI,CAAC;SAClC,KAAK,CAAC,WAAW,EAAE,IAAI,EAAE,GAAG,CAAC;SAC7B,gBAAgB,EAAE,CAAA;IACrB,OAAO,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;AACtC,CAAC;AAED,uEAAuE;AACvE,SAAS,IAAI,CAAC,GAAW;IACvB,OAAO,CAAC,EAA2D,EAAE,EAAE,CACrE,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;AACnE,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { type DecodeErrorResultReturnType, type Hex } from 'viem';
2
+ import { Abis } from 'viem/tempo';
3
+ import type { OneOf, UnionOmit } from './types.js';
4
+ type AllAbis = typeof Abis.abis;
5
+ type AbiErrorName = Extract<AllAbis[number], {
6
+ type: 'error';
7
+ }>['name'];
8
+ /** Decoded execution error from a Tempo precompile revert. */
9
+ export type ExecutionError = OneOf<(DecodeErrorResultReturnType<AllAbis> & {
10
+ data: Hex;
11
+ message: string;
12
+ }) | {
13
+ errorName: 'unknown';
14
+ message: string;
15
+ }>;
16
+ /** RPC-serialized execution error (bigints and numbers as hex). */
17
+ export type Rpc = UnionOmit<ExecutionError, 'args'>;
18
+ /** Human-readable messages keyed by ABI error name. */
19
+ export declare const messages: Record<AbiErrorName, string>;
20
+ /** Parse a viem error into a structured execution error. */
21
+ export declare function parse(error: Error): ExecutionError;
22
+ /** Serializes an ExecutionError for RPC transport (bigints/numbers → hex). */
23
+ export declare function serialize(preimage: ExecutionError): Rpc;
24
+ export {};
25
+ //# sourceMappingURL=executionError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executionError.d.ts","sourceRoot":"","sources":["../../../src/handlers/internal/executionError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,2BAA2B,EAAE,KAAK,GAAG,EAAqB,MAAM,MAAM,CAAA;AACpF,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEjC,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAElD,KAAK,OAAO,GAAG,OAAO,IAAI,CAAC,IAAI,CAAA;AAC/B,KAAK,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC,MAAM,CAAC,CAAA;AAEvE,8DAA8D;AAC9D,MAAM,MAAM,cAAc,GAAG,KAAK,CAC9B,CAAC,2BAA2B,CAAC,OAAO,CAAC,GAAG;IACtC,IAAI,EAAE,GAAG,CAAA;IACT,OAAO,EAAE,MAAM,CAAA;CAChB,CAAC,GACF;IAAE,SAAS,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAC5C,CAAA;AAED,mEAAmE;AACnE,MAAM,MAAM,GAAG,GAAG,SAAS,CAAC,cAAc,EAAE,MAAM,CAAC,CAAA;AAEnD,uDAAuD;AACvD,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAkHjD,CAAA;AAWD,4DAA4D;AAC5D,wBAAgB,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,cAAc,CA+BlD;AAED,8EAA8E;AAC9E,wBAAgB,SAAS,CAAC,QAAQ,EAAE,cAAc,GAAG,GAAG,CAQvD"}
@@ -0,0 +1,184 @@
1
+ import { decodeErrorResult } from 'viem';
2
+ import { Abis } from 'viem/tempo';
3
+ /** Human-readable messages keyed by ABI error name. */
4
+ export const messages = {
5
+ AddressAlreadyHasValidator: 'This address already has a validator.',
6
+ AddressNotReserved: 'Address is not reserved.',
7
+ AddressReserved: 'Address is reserved.',
8
+ AlreadyInitialized: 'Already initialized.',
9
+ AmountExceedsDeposit: 'Amount exceeds deposit.',
10
+ AmountNotIncreasing: 'Amount is not increasing.',
11
+ BelowMinimumOrderSize: 'Order size is below the minimum allowed ({0}).',
12
+ CallNotAllowed: 'This call is not allowed.',
13
+ CannotChangeWithinBlock: 'Cannot change within the same block.',
14
+ CaptureAmountInvalid: 'Capture amount is invalid.',
15
+ ChannelAlreadyExists: 'Channel already exists.',
16
+ ChannelNotFound: 'Channel not found.',
17
+ CloseNotReady: 'Channel is not ready to close.',
18
+ ContractPaused: 'Contract is paused.',
19
+ DepositOverflow: 'Deposit overflow.',
20
+ DivisionByZero: 'Division by zero.',
21
+ EmptyV1ValidatorSet: 'Validator set is empty.',
22
+ ExpiringNonceHashNotSet: 'Expiring nonce hash is not set.',
23
+ ExpiringNonceReplay: 'Expiring nonce has already been used.',
24
+ ExpiringNonceSetFull: 'Expiring nonce set is full.',
25
+ ExpiryInPast: 'Expiry is in the past.',
26
+ IdenticalAddresses: 'Addresses must be different.',
27
+ IdenticalTokens: 'Cannot swap a token for itself — input and output tokens must be different.',
28
+ IncompatiblePolicyType: 'Incompatible policy type.',
29
+ IngressAlreadyExists: 'Ingress "{0}" already exists.',
30
+ InsufficientAllowance: 'Insufficient allowance.',
31
+ InsufficientBalance: 'Insufficient balance. Required: {1}, available: {0}.',
32
+ InsufficientFeeTokenBalance: 'Insufficient fee token balance.',
33
+ InsufficientLiquidity: 'Not enough liquidity in the order book to fill this trade.',
34
+ InsufficientOutput: 'The output amount is below the slippage minimum — try increasing slippage tolerance.',
35
+ InsufficientReserves: 'Insufficient reserves.',
36
+ InvalidAmount: 'Invalid amount.',
37
+ InvalidBaseToken: 'This token is not a valid base token for the requested pair.',
38
+ InvalidCallScope: 'Invalid call scope.',
39
+ InvalidClaimAddress: 'Invalid claim address.',
40
+ InvalidCurrency: 'Invalid currency.',
41
+ InvalidExpiringNonceExpiry: 'Invalid expiring nonce expiry.',
42
+ InvalidFlipTick: 'The flip-order price tick is invalid.',
43
+ InvalidFormat: 'Invalid format.',
44
+ InvalidKeyAuthorizationWitness: 'Invalid key authorization witness.',
45
+ InvalidKeyId: 'Invalid key ID.',
46
+ InvalidLogoURI: 'Invalid logo URI.',
47
+ InvalidMasterAddress: 'Invalid master address.',
48
+ InvalidMigrationIndex: 'Invalid migration index.',
49
+ InvalidNonceKey: 'Invalid nonce key.',
50
+ InvalidOwner: 'Invalid owner.',
51
+ InvalidPayee: 'Invalid payee.',
52
+ InvalidPayload: 'Invalid payload.',
53
+ InvalidPolicyType: 'Invalid policy type.',
54
+ InvalidPublicKey: 'Invalid public key.',
55
+ InvalidQuoteToken: 'Invalid quote token.',
56
+ InvalidReceipt: 'Invalid receipt.',
57
+ InvalidReceivePolicyType: 'Invalid receive policy type.',
58
+ InvalidRecipient: 'Invalid recipient.',
59
+ InvalidRecoveryAuthority: 'Invalid recovery authority.',
60
+ InvalidSignature: 'Invalid signature.',
61
+ InvalidSignatureFormat: 'Invalid signature format.',
62
+ InvalidSignatureType: 'Invalid signature type.',
63
+ InvalidSpendingLimit: 'Invalid spending limit.',
64
+ InvalidSupplyCap: 'Invalid supply cap.',
65
+ InvalidSwapCalculation: 'Invalid swap calculation.',
66
+ InvalidTick: 'The price tick is invalid.',
67
+ InvalidToken: 'This token is not supported on the exchange.',
68
+ InvalidTransferPolicyId: 'Invalid transfer policy.',
69
+ InvalidValidatorAddress: 'Invalid validator address.',
70
+ KeyAlreadyExists: 'Key already exists.',
71
+ KeyAlreadyRevoked: 'Key has already been revoked.',
72
+ KeyAuthorizationWitnessAlreadyBurned: 'Key authorization witness has already been burned.',
73
+ KeyExpired: 'Key has expired.',
74
+ KeyNotFound: 'Key not found.',
75
+ LegacyAuthorizeKeySelectorChanged: 'Legacy authorize key selector changed to {0}.',
76
+ LogoURITooLong: 'Logo URI is too long.',
77
+ MasterIdCollision: 'Master ID collision with {0}.',
78
+ MaxInputExceeded: 'The required input exceeds the slippage maximum — try increasing slippage tolerance.',
79
+ MigrationNotComplete: 'Migration is not complete.',
80
+ NoOptedInSupply: 'No opted-in supply.',
81
+ NonceOverflow: 'Nonce overflow.',
82
+ NotHostPort: '"{1}" is not a valid host:port for {0}.',
83
+ NotInitialized: 'Not initialized.',
84
+ NotIp: '"{0}" is not a valid IP address.',
85
+ NotIpPort: '"{1}" is not a valid IP:port for {0}.',
86
+ NotPayeeOrOperator: 'Not payee or operator.',
87
+ NotPayer: 'Not payer.',
88
+ OrderDoesNotExist: 'No order exists with the given ID.',
89
+ OrderNotStale: 'This order is not yet eligible for stale-cleanup.',
90
+ PairAlreadyExists: 'A trading pair for these tokens has already been created.',
91
+ PairDoesNotExist: 'No trading pair exists for these tokens.',
92
+ PermitExpired: 'Permit has expired.',
93
+ PolicyForbids: 'Forbidden by policy.',
94
+ PolicyNotFound: 'Policy not found.',
95
+ PolicyNotSimple: 'Policy is not a simple policy.',
96
+ ProofOfWorkFailed: 'Proof of work failed.',
97
+ ProtectedAddress: 'Address is protected.',
98
+ ProtocolNonceNotSupported: 'Protocol nonce is not supported.',
99
+ PublicKeyAlreadyExists: 'Public key already exists.',
100
+ SignatureTypeMismatch: 'Signature type mismatch. Expected {0}, got {1}.',
101
+ SpendingLimitExceeded: 'Spending limit exceeded.',
102
+ SupplyCapExceeded: 'Supply cap exceeded.',
103
+ TickOutOfBounds: 'Price tick {0} is outside the allowed range.',
104
+ TokenAlreadyExists: 'Token {0} already exists.',
105
+ Unauthorized: 'Unauthorized.',
106
+ UnauthorizedCaller: 'Unauthorized caller.',
107
+ UnauthorizedClaimer: 'Unauthorized claimer.',
108
+ Uninitialized: 'Uninitialized.',
109
+ ValidatorAlreadyDeactivated: 'Validator is already deactivated.',
110
+ ValidatorAlreadyExists: 'Validator already exists.',
111
+ ValidatorNotFound: 'Validator not found.',
112
+ VirtualAddressNotAllowed: 'Virtual address is not allowed.',
113
+ VirtualAddressUnregistered: 'Virtual address is not registered.',
114
+ ZeroDeposit: 'Deposit cannot be zero.',
115
+ ZeroPublicKey: 'Public key cannot be zero.',
116
+ };
117
+ /** Interpolate `{0}`, `{1}`, … placeholders with args. */
118
+ function interpolate(template, args) {
119
+ if (!args)
120
+ return template;
121
+ return template.replace(/\{(\d+)\}/g, (_, i) => {
122
+ const v = args[Number(i)];
123
+ return v === undefined ? `{${i}}` : String(v);
124
+ });
125
+ }
126
+ /** Parse a viem error into a structured execution error. */
127
+ export function parse(error) {
128
+ const raw = error.details ??
129
+ error.shortMessage ??
130
+ error.message;
131
+ const data = extractRevertData(error);
132
+ if (data) {
133
+ try {
134
+ const decoded = decodeErrorResult({ abi: Abis.abis, data });
135
+ const template = messages[decoded.errorName];
136
+ return {
137
+ ...decoded,
138
+ data,
139
+ message: template
140
+ ? interpolate(template, decoded.args)
141
+ : raw.replace(/^execution reverted:\s*/i, ''),
142
+ };
143
+ }
144
+ catch { }
145
+ }
146
+ // Fallback: extract error name from human-readable revert message.
147
+ const nameMatch = /:\s*(\w+)\(\w+/.exec(raw);
148
+ const errorName = nameMatch?.[1];
149
+ if (errorName && errorName in messages)
150
+ return { errorName: 'unknown', message: messages[errorName] };
151
+ return {
152
+ errorName: 'unknown',
153
+ message: raw.replace(/^execution reverted:\s*/i, ''),
154
+ };
155
+ }
156
+ /** Serializes an ExecutionError for RPC transport (bigints/numbers → hex). */
157
+ export function serialize(preimage) {
158
+ if (preimage.errorName === 'unknown')
159
+ return { errorName: 'unknown', message: preimage.message };
160
+ return {
161
+ errorName: preimage.errorName,
162
+ abiItem: preimage.abiItem,
163
+ message: preimage.message,
164
+ data: preimage.data,
165
+ };
166
+ }
167
+ function extractRevertData(error) {
168
+ if (!error || typeof error !== 'object')
169
+ return null;
170
+ const e = error;
171
+ if (typeof e['data'] === 'string' && e['data'].startsWith('0x'))
172
+ return e['data'];
173
+ if (e['cause'])
174
+ return extractRevertData(e['cause']);
175
+ if (e['error'])
176
+ return extractRevertData(e['error']);
177
+ if (typeof e['walk'] === 'function') {
178
+ const inner = e.walk((e) => typeof e['data'] === 'string');
179
+ if (inner)
180
+ return extractRevertData(inner);
181
+ }
182
+ return null;
183
+ }
184
+ //# sourceMappingURL=executionError.js.map