@waiaas/daemon 2.11.0-rc.8 → 2.11.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 (414) hide show
  1. package/README.md +5 -5
  2. package/dist/api/middleware/address-validation.d.ts +6 -33
  3. package/dist/api/middleware/address-validation.d.ts.map +1 -1
  4. package/dist/api/middleware/address-validation.js +5 -129
  5. package/dist/api/middleware/address-validation.js.map +1 -1
  6. package/dist/api/middleware/host-guard.d.ts +1 -1
  7. package/dist/api/middleware/host-guard.js +2 -2
  8. package/dist/api/middleware/host-guard.js.map +1 -1
  9. package/dist/api/middleware/index.d.ts +1 -0
  10. package/dist/api/middleware/index.d.ts.map +1 -1
  11. package/dist/api/middleware/index.js +1 -0
  12. package/dist/api/middleware/index.js.map +1 -1
  13. package/dist/api/middleware/master-auth.d.ts +2 -5
  14. package/dist/api/middleware/master-auth.d.ts.map +1 -1
  15. package/dist/api/middleware/master-auth.js.map +1 -1
  16. package/dist/api/middleware/rate-limiter.d.ts +51 -0
  17. package/dist/api/middleware/rate-limiter.d.ts.map +1 -0
  18. package/dist/api/middleware/rate-limiter.js +146 -0
  19. package/dist/api/middleware/rate-limiter.js.map +1 -0
  20. package/dist/api/middleware/siwe-verify.d.ts +6 -26
  21. package/dist/api/middleware/siwe-verify.d.ts.map +1 -1
  22. package/dist/api/middleware/siwe-verify.js +5 -50
  23. package/dist/api/middleware/siwe-verify.js.map +1 -1
  24. package/dist/api/routes/actions.d.ts +1 -0
  25. package/dist/api/routes/actions.d.ts.map +1 -1
  26. package/dist/api/routes/actions.js +52 -4
  27. package/dist/api/routes/actions.js.map +1 -1
  28. package/dist/api/routes/admin-actions.d.ts +1 -0
  29. package/dist/api/routes/admin-actions.d.ts.map +1 -1
  30. package/dist/api/routes/admin-actions.js +3 -3
  31. package/dist/api/routes/admin-actions.js.map +1 -1
  32. package/dist/api/routes/admin-auth.d.ts.map +1 -1
  33. package/dist/api/routes/admin-auth.js +12 -7
  34. package/dist/api/routes/admin-auth.js.map +1 -1
  35. package/dist/api/routes/admin-credentials.js +2 -2
  36. package/dist/api/routes/admin-credentials.js.map +1 -1
  37. package/dist/api/routes/admin-monitoring.d.ts +10 -0
  38. package/dist/api/routes/admin-monitoring.d.ts.map +1 -1
  39. package/dist/api/routes/admin-monitoring.js +59 -14
  40. package/dist/api/routes/admin-monitoring.js.map +1 -1
  41. package/dist/api/routes/admin-notifications.d.ts.map +1 -1
  42. package/dist/api/routes/admin-notifications.js +2 -15
  43. package/dist/api/routes/admin-notifications.js.map +1 -1
  44. package/dist/api/routes/admin-settings.d.ts.map +1 -1
  45. package/dist/api/routes/admin-settings.js +90 -1
  46. package/dist/api/routes/admin-settings.js.map +1 -1
  47. package/dist/api/routes/admin-wallets.d.ts +16 -1
  48. package/dist/api/routes/admin-wallets.d.ts.map +1 -1
  49. package/dist/api/routes/admin-wallets.js +64 -75
  50. package/dist/api/routes/admin-wallets.js.map +1 -1
  51. package/dist/api/routes/admin.d.ts +1 -0
  52. package/dist/api/routes/admin.d.ts.map +1 -1
  53. package/dist/api/routes/admin.js.map +1 -1
  54. package/dist/api/routes/credentials.js +2 -2
  55. package/dist/api/routes/credentials.js.map +1 -1
  56. package/dist/api/routes/defi-positions.js.map +1 -1
  57. package/dist/api/routes/nfts.js.map +1 -1
  58. package/dist/api/routes/openapi-schemas.d.ts +412 -12
  59. package/dist/api/routes/openapi-schemas.d.ts.map +1 -1
  60. package/dist/api/routes/openapi-schemas.js +38 -5
  61. package/dist/api/routes/openapi-schemas.js.map +1 -1
  62. package/dist/api/routes/policies.d.ts +2 -0
  63. package/dist/api/routes/policies.d.ts.map +1 -1
  64. package/dist/api/routes/policies.js +55 -6
  65. package/dist/api/routes/policies.js.map +1 -1
  66. package/dist/api/routes/rpc-proxy.js.map +1 -1
  67. package/dist/api/routes/sessions.d.ts.map +1 -1
  68. package/dist/api/routes/sessions.js +47 -28
  69. package/dist/api/routes/sessions.js.map +1 -1
  70. package/dist/api/routes/staking.d.ts.map +1 -1
  71. package/dist/api/routes/staking.js +4 -76
  72. package/dist/api/routes/staking.js.map +1 -1
  73. package/dist/api/routes/tokens.d.ts.map +1 -1
  74. package/dist/api/routes/tokens.js.map +1 -1
  75. package/dist/api/routes/transactions.d.ts +1 -0
  76. package/dist/api/routes/transactions.d.ts.map +1 -1
  77. package/dist/api/routes/transactions.js +8 -2
  78. package/dist/api/routes/transactions.js.map +1 -1
  79. package/dist/api/routes/userop.d.ts.map +1 -1
  80. package/dist/api/routes/userop.js +0 -2
  81. package/dist/api/routes/userop.js.map +1 -1
  82. package/dist/api/routes/wallet-apps.d.ts.map +1 -1
  83. package/dist/api/routes/wallet-apps.js +20 -13
  84. package/dist/api/routes/wallet-apps.js.map +1 -1
  85. package/dist/api/routes/wallet.js.map +1 -1
  86. package/dist/api/routes/wallets.d.ts.map +1 -1
  87. package/dist/api/routes/wallets.js +3 -0
  88. package/dist/api/routes/wallets.js.map +1 -1
  89. package/dist/api/routes/wc.d.ts.map +1 -1
  90. package/dist/api/routes/wc.js +13 -8
  91. package/dist/api/routes/wc.js.map +1 -1
  92. package/dist/api/routes/x402.d.ts.map +1 -1
  93. package/dist/api/routes/x402.js +1 -2
  94. package/dist/api/routes/x402.js.map +1 -1
  95. package/dist/api/server.d.ts +8 -4
  96. package/dist/api/server.d.ts.map +1 -1
  97. package/dist/api/server.js +46 -5
  98. package/dist/api/server.js.map +1 -1
  99. package/dist/constants.d.ts +1 -1
  100. package/dist/constants.d.ts.map +1 -1
  101. package/dist/constants.js +1 -1
  102. package/dist/constants.js.map +1 -1
  103. package/dist/infrastructure/action/action-provider-registry.d.ts.map +1 -1
  104. package/dist/infrastructure/action/action-provider-registry.js +2 -3
  105. package/dist/infrastructure/action/action-provider-registry.js.map +1 -1
  106. package/dist/infrastructure/action/builtin-metadata.d.ts +22 -0
  107. package/dist/infrastructure/action/builtin-metadata.d.ts.map +1 -0
  108. package/dist/infrastructure/action/builtin-metadata.js +29 -0
  109. package/dist/infrastructure/action/builtin-metadata.js.map +1 -0
  110. package/dist/infrastructure/adapter-pool.d.ts +2 -1
  111. package/dist/infrastructure/adapter-pool.d.ts.map +1 -1
  112. package/dist/infrastructure/adapter-pool.js.map +1 -1
  113. package/dist/infrastructure/auth/address-validation.d.ts +38 -0
  114. package/dist/infrastructure/auth/address-validation.d.ts.map +1 -0
  115. package/dist/infrastructure/auth/address-validation.js +134 -0
  116. package/dist/infrastructure/auth/address-validation.js.map +1 -0
  117. package/dist/infrastructure/auth/siwe-verify.d.ts +34 -0
  118. package/dist/infrastructure/auth/siwe-verify.d.ts.map +1 -0
  119. package/dist/infrastructure/auth/siwe-verify.js +58 -0
  120. package/dist/infrastructure/auth/siwe-verify.js.map +1 -0
  121. package/dist/infrastructure/auth/types.d.ts +12 -0
  122. package/dist/infrastructure/auth/types.d.ts.map +1 -0
  123. package/dist/infrastructure/auth/types.js +8 -0
  124. package/dist/infrastructure/auth/types.js.map +1 -0
  125. package/dist/infrastructure/config/loader.d.ts +1 -10
  126. package/dist/infrastructure/config/loader.d.ts.map +1 -1
  127. package/dist/infrastructure/config/loader.js +0 -2
  128. package/dist/infrastructure/config/loader.js.map +1 -1
  129. package/dist/infrastructure/database/migrate.d.ts +6 -18
  130. package/dist/infrastructure/database/migrate.d.ts.map +1 -1
  131. package/dist/infrastructure/database/migrate.js +25 -2856
  132. package/dist/infrastructure/database/migrate.js.map +1 -1
  133. package/dist/infrastructure/database/migrations/v11-v20.d.ts +17 -0
  134. package/dist/infrastructure/database/migrations/v11-v20.d.ts.map +1 -0
  135. package/dist/infrastructure/database/migrations/v11-v20.js +295 -0
  136. package/dist/infrastructure/database/migrations/v11-v20.js.map +1 -0
  137. package/dist/infrastructure/database/migrations/v2-v10.d.ts +16 -0
  138. package/dist/infrastructure/database/migrations/v2-v10.d.ts.map +1 -0
  139. package/dist/infrastructure/database/migrations/v2-v10.js +539 -0
  140. package/dist/infrastructure/database/migrations/v2-v10.js.map +1 -0
  141. package/dist/infrastructure/database/migrations/v21-v30.d.ts +17 -0
  142. package/dist/infrastructure/database/migrations/v21-v30.d.ts.map +1 -0
  143. package/dist/infrastructure/database/migrations/v21-v30.js +507 -0
  144. package/dist/infrastructure/database/migrations/v21-v30.js.map +1 -0
  145. package/dist/infrastructure/database/migrations/v31-v40.d.ts +17 -0
  146. package/dist/infrastructure/database/migrations/v31-v40.d.ts.map +1 -0
  147. package/dist/infrastructure/database/migrations/v31-v40.js +203 -0
  148. package/dist/infrastructure/database/migrations/v31-v40.js.map +1 -0
  149. package/dist/infrastructure/database/migrations/v41-v50.d.ts +17 -0
  150. package/dist/infrastructure/database/migrations/v41-v50.d.ts.map +1 -0
  151. package/dist/infrastructure/database/migrations/v41-v50.js +188 -0
  152. package/dist/infrastructure/database/migrations/v41-v50.js.map +1 -0
  153. package/dist/infrastructure/database/migrations/v51-v59.d.ts +17 -0
  154. package/dist/infrastructure/database/migrations/v51-v59.d.ts.map +1 -0
  155. package/dist/infrastructure/database/migrations/v51-v59.js +420 -0
  156. package/dist/infrastructure/database/migrations/v51-v59.js.map +1 -0
  157. package/dist/infrastructure/database/schema-ddl.d.ts +24 -0
  158. package/dist/infrastructure/database/schema-ddl.d.ts.map +1 -0
  159. package/dist/infrastructure/database/schema-ddl.js +596 -0
  160. package/dist/infrastructure/database/schema-ddl.js.map +1 -0
  161. package/dist/infrastructure/database/schema.d.ts +38 -0
  162. package/dist/infrastructure/database/schema.d.ts.map +1 -1
  163. package/dist/infrastructure/database/schema.js +2 -0
  164. package/dist/infrastructure/database/schema.js.map +1 -1
  165. package/dist/infrastructure/jwt/jwt-secret-manager.d.ts.map +1 -1
  166. package/dist/infrastructure/jwt/jwt-secret-manager.js +16 -3
  167. package/dist/infrastructure/jwt/jwt-secret-manager.js.map +1 -1
  168. package/dist/infrastructure/nft/alchemy-nft-indexer.d.ts.map +1 -1
  169. package/dist/infrastructure/nft/alchemy-nft-indexer.js +0 -1
  170. package/dist/infrastructure/nft/alchemy-nft-indexer.js.map +1 -1
  171. package/dist/infrastructure/nft/helius-nft-indexer.d.ts.map +1 -1
  172. package/dist/infrastructure/nft/helius-nft-indexer.js +1 -2
  173. package/dist/infrastructure/nft/helius-nft-indexer.js.map +1 -1
  174. package/dist/infrastructure/nft/nft-indexer-client.d.ts.map +1 -1
  175. package/dist/infrastructure/nft/nft-indexer-client.js +0 -2
  176. package/dist/infrastructure/nft/nft-indexer-client.js.map +1 -1
  177. package/dist/infrastructure/security/ssrf-guard.d.ts +33 -0
  178. package/dist/infrastructure/security/ssrf-guard.d.ts.map +1 -0
  179. package/dist/infrastructure/security/ssrf-guard.js +244 -0
  180. package/dist/infrastructure/security/ssrf-guard.js.map +1 -0
  181. package/dist/infrastructure/settings/hot-reload.d.ts +1 -1
  182. package/dist/infrastructure/settings/hot-reload.d.ts.map +1 -1
  183. package/dist/infrastructure/settings/hot-reload.js +0 -2
  184. package/dist/infrastructure/settings/hot-reload.js.map +1 -1
  185. package/dist/infrastructure/settings/index.d.ts +2 -2
  186. package/dist/infrastructure/settings/index.d.ts.map +1 -1
  187. package/dist/infrastructure/settings/index.js +1 -1
  188. package/dist/infrastructure/settings/index.js.map +1 -1
  189. package/dist/infrastructure/settings/setting-keys.d.ts +14 -0
  190. package/dist/infrastructure/settings/setting-keys.d.ts.map +1 -1
  191. package/dist/infrastructure/settings/setting-keys.js +296 -214
  192. package/dist/infrastructure/settings/setting-keys.js.map +1 -1
  193. package/dist/infrastructure/settings/settings-service.d.ts +6 -1
  194. package/dist/infrastructure/settings/settings-service.d.ts.map +1 -1
  195. package/dist/infrastructure/settings/settings-service.js +15 -5
  196. package/dist/infrastructure/settings/settings-service.js.map +1 -1
  197. package/dist/infrastructure/telegram/telegram-bot-service.d.ts.map +1 -1
  198. package/dist/infrastructure/telegram/telegram-bot-service.js +3 -2
  199. package/dist/infrastructure/telegram/telegram-bot-service.js.map +1 -1
  200. package/dist/infrastructure/token-registry/builtin-tokens.d.ts.map +1 -1
  201. package/dist/infrastructure/token-registry/builtin-tokens.js +4 -7
  202. package/dist/infrastructure/token-registry/builtin-tokens.js.map +1 -1
  203. package/dist/lifecycle/daemon-pipeline.d.ts +49 -0
  204. package/dist/lifecycle/daemon-pipeline.d.ts.map +1 -0
  205. package/dist/lifecycle/daemon-pipeline.js +281 -0
  206. package/dist/lifecycle/daemon-pipeline.js.map +1 -0
  207. package/dist/lifecycle/daemon-shutdown.d.ts +14 -0
  208. package/dist/lifecycle/daemon-shutdown.d.ts.map +1 -0
  209. package/dist/lifecycle/daemon-shutdown.js +176 -0
  210. package/dist/lifecycle/daemon-shutdown.js.map +1 -0
  211. package/dist/lifecycle/daemon-startup.d.ts +15 -0
  212. package/dist/lifecycle/daemon-startup.d.ts.map +1 -0
  213. package/dist/lifecycle/daemon-startup.js +1527 -0
  214. package/dist/lifecycle/daemon-startup.js.map +1 -0
  215. package/dist/lifecycle/daemon.d.ts +171 -114
  216. package/dist/lifecycle/daemon.d.ts.map +1 -1
  217. package/dist/lifecycle/daemon.js +22 -1904
  218. package/dist/lifecycle/daemon.js.map +1 -1
  219. package/dist/notifications/channels/discord.d.ts.map +1 -1
  220. package/dist/notifications/channels/discord.js +1 -0
  221. package/dist/notifications/channels/discord.js.map +1 -1
  222. package/dist/notifications/channels/slack.d.ts.map +1 -1
  223. package/dist/notifications/channels/slack.js +1 -0
  224. package/dist/notifications/channels/slack.js.map +1 -1
  225. package/dist/notifications/index.d.ts +0 -1
  226. package/dist/notifications/index.d.ts.map +1 -1
  227. package/dist/notifications/index.js +0 -1
  228. package/dist/notifications/index.js.map +1 -1
  229. package/dist/notifications/notification-service.d.ts.map +1 -1
  230. package/dist/notifications/notification-service.js +8 -6
  231. package/dist/notifications/notification-service.js.map +1 -1
  232. package/dist/pipeline/database-policy-engine.d.ts +18 -438
  233. package/dist/pipeline/database-policy-engine.d.ts.map +1 -1
  234. package/dist/pipeline/database-policy-engine.js +154 -1321
  235. package/dist/pipeline/database-policy-engine.js.map +1 -1
  236. package/dist/pipeline/dry-run.d.ts +5 -2
  237. package/dist/pipeline/dry-run.d.ts.map +1 -1
  238. package/dist/pipeline/dry-run.js +102 -8
  239. package/dist/pipeline/dry-run.js.map +1 -1
  240. package/dist/pipeline/evaluators/allowed-tokens.d.ts +28 -0
  241. package/dist/pipeline/evaluators/allowed-tokens.d.ts.map +1 -0
  242. package/dist/pipeline/evaluators/allowed-tokens.js +129 -0
  243. package/dist/pipeline/evaluators/allowed-tokens.js.map +1 -0
  244. package/dist/pipeline/evaluators/approved-spenders.d.ts +26 -0
  245. package/dist/pipeline/evaluators/approved-spenders.d.ts.map +1 -0
  246. package/dist/pipeline/evaluators/approved-spenders.js +115 -0
  247. package/dist/pipeline/evaluators/approved-spenders.js.map +1 -0
  248. package/dist/pipeline/evaluators/contract-whitelist.d.ts +28 -0
  249. package/dist/pipeline/evaluators/contract-whitelist.d.ts.map +1 -0
  250. package/dist/pipeline/evaluators/contract-whitelist.js +168 -0
  251. package/dist/pipeline/evaluators/contract-whitelist.js.map +1 -0
  252. package/dist/pipeline/evaluators/helpers.d.ts +9 -0
  253. package/dist/pipeline/evaluators/helpers.d.ts.map +1 -0
  254. package/dist/pipeline/evaluators/helpers.js +13 -0
  255. package/dist/pipeline/evaluators/helpers.js.map +1 -0
  256. package/dist/pipeline/evaluators/lending-asset-whitelist.d.ts +18 -0
  257. package/dist/pipeline/evaluators/lending-asset-whitelist.d.ts.map +1 -0
  258. package/dist/pipeline/evaluators/lending-asset-whitelist.js +44 -0
  259. package/dist/pipeline/evaluators/lending-asset-whitelist.js.map +1 -0
  260. package/dist/pipeline/evaluators/lending-ltv-limit.d.ts +24 -0
  261. package/dist/pipeline/evaluators/lending-ltv-limit.d.ts.map +1 -0
  262. package/dist/pipeline/evaluators/lending-ltv-limit.js +130 -0
  263. package/dist/pipeline/evaluators/lending-ltv-limit.js.map +1 -0
  264. package/dist/pipeline/evaluators/spending-limit.d.ts +46 -0
  265. package/dist/pipeline/evaluators/spending-limit.d.ts.map +1 -0
  266. package/dist/pipeline/evaluators/spending-limit.js +241 -0
  267. package/dist/pipeline/evaluators/spending-limit.js.map +1 -0
  268. package/dist/pipeline/evaluators/types.d.ts +71 -0
  269. package/dist/pipeline/evaluators/types.d.ts.map +1 -0
  270. package/dist/pipeline/evaluators/types.js +7 -0
  271. package/dist/pipeline/evaluators/types.js.map +1 -0
  272. package/dist/pipeline/external-action-pipeline.js.map +1 -1
  273. package/dist/pipeline/gas-condition-tracker.d.ts +1 -1
  274. package/dist/pipeline/gas-condition-tracker.js +1 -1
  275. package/dist/pipeline/pipeline-helpers.d.ts +146 -0
  276. package/dist/pipeline/pipeline-helpers.d.ts.map +1 -0
  277. package/dist/pipeline/pipeline-helpers.js +260 -0
  278. package/dist/pipeline/pipeline-helpers.js.map +1 -0
  279. package/dist/pipeline/pipeline.d.ts +1 -0
  280. package/dist/pipeline/pipeline.d.ts.map +1 -1
  281. package/dist/pipeline/pipeline.js +3 -2
  282. package/dist/pipeline/pipeline.js.map +1 -1
  283. package/dist/pipeline/resolve-effective-amount-usd.d.ts.map +1 -1
  284. package/dist/pipeline/resolve-effective-amount-usd.js +4 -10
  285. package/dist/pipeline/resolve-effective-amount-usd.js.map +1 -1
  286. package/dist/pipeline/sign-message.js +1 -1
  287. package/dist/pipeline/sign-message.js.map +1 -1
  288. package/dist/pipeline/sleep.d.ts +1 -5
  289. package/dist/pipeline/sleep.d.ts.map +1 -1
  290. package/dist/pipeline/sleep.js +2 -7
  291. package/dist/pipeline/sleep.js.map +1 -1
  292. package/dist/pipeline/stage1-validate.d.ts +8 -0
  293. package/dist/pipeline/stage1-validate.d.ts.map +1 -0
  294. package/dist/pipeline/stage1-validate.js +69 -0
  295. package/dist/pipeline/stage1-validate.js.map +1 -0
  296. package/dist/pipeline/stage2-auth.d.ts +12 -0
  297. package/dist/pipeline/stage2-auth.d.ts.map +1 -0
  298. package/dist/pipeline/stage2-auth.js +18 -0
  299. package/dist/pipeline/stage2-auth.js.map +1 -0
  300. package/dist/pipeline/stage3-policy.d.ts +26 -0
  301. package/dist/pipeline/stage3-policy.d.ts.map +1 -0
  302. package/dist/pipeline/stage3-policy.js +384 -0
  303. package/dist/pipeline/stage3-policy.js.map +1 -0
  304. package/dist/pipeline/stage4-wait.d.ts +8 -0
  305. package/dist/pipeline/stage4-wait.d.ts.map +1 -0
  306. package/dist/pipeline/stage4-wait.js +87 -0
  307. package/dist/pipeline/stage4-wait.js.map +1 -0
  308. package/dist/pipeline/stage5-execute.d.ts +120 -0
  309. package/dist/pipeline/stage5-execute.d.ts.map +1 -0
  310. package/dist/pipeline/stage5-execute.js +1070 -0
  311. package/dist/pipeline/stage5-execute.js.map +1 -0
  312. package/dist/pipeline/stage6-confirm.d.ts +11 -0
  313. package/dist/pipeline/stage6-confirm.d.ts.map +1 -0
  314. package/dist/pipeline/stage6-confirm.js +110 -0
  315. package/dist/pipeline/stage6-confirm.js.map +1 -0
  316. package/dist/pipeline/stages.d.ts +11 -245
  317. package/dist/pipeline/stages.d.ts.map +1 -1
  318. package/dist/pipeline/stages.js +11 -1896
  319. package/dist/pipeline/stages.js.map +1 -1
  320. package/dist/rpc-proxy/sync-pipeline.js +2 -2
  321. package/dist/rpc-proxy/sync-pipeline.js.map +1 -1
  322. package/dist/services/autostop/autostop-service.d.ts +4 -1
  323. package/dist/services/autostop/autostop-service.d.ts.map +1 -1
  324. package/dist/services/autostop/autostop-service.js +27 -7
  325. package/dist/services/autostop/autostop-service.js.map +1 -1
  326. package/dist/services/defi/position-tracker.d.ts +5 -0
  327. package/dist/services/defi/position-tracker.d.ts.map +1 -1
  328. package/dist/services/defi/position-tracker.js +41 -6
  329. package/dist/services/defi/position-tracker.js.map +1 -1
  330. package/dist/services/defi/position-write-queue.d.ts.map +1 -1
  331. package/dist/services/defi/position-write-queue.js +3 -2
  332. package/dist/services/defi/position-write-queue.js.map +1 -1
  333. package/dist/services/incoming/__tests__/integration-wiring.test.js +58 -0
  334. package/dist/services/incoming/__tests__/integration-wiring.test.js.map +1 -1
  335. package/dist/services/incoming/incoming-tx-monitor-service.d.ts.map +1 -1
  336. package/dist/services/incoming/incoming-tx-monitor-service.js +11 -14
  337. package/dist/services/incoming/incoming-tx-monitor-service.js.map +1 -1
  338. package/dist/services/incoming/incoming-tx-workers.d.ts +2 -2
  339. package/dist/services/incoming/incoming-tx-workers.d.ts.map +1 -1
  340. package/dist/services/incoming/incoming-tx-workers.js +1 -1
  341. package/dist/services/incoming/incoming-tx-workers.js.map +1 -1
  342. package/dist/services/incoming/safety-rules.d.ts.map +1 -1
  343. package/dist/services/incoming/safety-rules.js +3 -2
  344. package/dist/services/incoming/safety-rules.js.map +1 -1
  345. package/dist/services/incoming/subscription-multiplexer.d.ts +2 -6
  346. package/dist/services/incoming/subscription-multiplexer.d.ts.map +1 -1
  347. package/dist/services/incoming/subscription-multiplexer.js +1 -3
  348. package/dist/services/incoming/subscription-multiplexer.js.map +1 -1
  349. package/dist/services/monitoring/balance-monitor-service.d.ts.map +1 -1
  350. package/dist/services/monitoring/balance-monitor-service.js +2 -2
  351. package/dist/services/monitoring/balance-monitor-service.js.map +1 -1
  352. package/dist/services/signing-sdk/approval-channel-router.d.ts +7 -7
  353. package/dist/services/signing-sdk/approval-channel-router.d.ts.map +1 -1
  354. package/dist/services/signing-sdk/approval-channel-router.js +13 -13
  355. package/dist/services/signing-sdk/approval-channel-router.js.map +1 -1
  356. package/dist/services/signing-sdk/channels/index.d.ts +2 -2
  357. package/dist/services/signing-sdk/channels/index.d.ts.map +1 -1
  358. package/dist/services/signing-sdk/channels/index.js +1 -1
  359. package/dist/services/signing-sdk/channels/index.js.map +1 -1
  360. package/dist/services/signing-sdk/channels/push-relay-signing-channel.d.ts +59 -0
  361. package/dist/services/signing-sdk/channels/push-relay-signing-channel.d.ts.map +1 -0
  362. package/dist/services/signing-sdk/channels/push-relay-signing-channel.js +190 -0
  363. package/dist/services/signing-sdk/channels/push-relay-signing-channel.js.map +1 -0
  364. package/dist/services/signing-sdk/channels/telegram-signing-channel.d.ts +1 -1
  365. package/dist/services/signing-sdk/channels/telegram-signing-channel.js +1 -1
  366. package/dist/services/signing-sdk/channels/wallet-notification-channel.d.ts +6 -7
  367. package/dist/services/signing-sdk/channels/wallet-notification-channel.d.ts.map +1 -1
  368. package/dist/services/signing-sdk/channels/wallet-notification-channel.js +38 -55
  369. package/dist/services/signing-sdk/channels/wallet-notification-channel.js.map +1 -1
  370. package/dist/services/signing-sdk/index.d.ts +3 -3
  371. package/dist/services/signing-sdk/index.d.ts.map +1 -1
  372. package/dist/services/signing-sdk/index.js +2 -2
  373. package/dist/services/signing-sdk/index.js.map +1 -1
  374. package/dist/services/signing-sdk/preset-auto-setup.js +2 -2
  375. package/dist/services/signing-sdk/preset-auto-setup.js.map +1 -1
  376. package/dist/services/signing-sdk/sign-request-builder.d.ts +2 -2
  377. package/dist/services/signing-sdk/sign-request-builder.d.ts.map +1 -1
  378. package/dist/services/signing-sdk/sign-request-builder.js +17 -25
  379. package/dist/services/signing-sdk/sign-request-builder.js.map +1 -1
  380. package/dist/services/signing-sdk/wallet-app-service.d.ts +4 -0
  381. package/dist/services/signing-sdk/wallet-app-service.d.ts.map +1 -1
  382. package/dist/services/signing-sdk/wallet-app-service.js +12 -5
  383. package/dist/services/signing-sdk/wallet-app-service.js.map +1 -1
  384. package/dist/services/staking/aggregate-staking-balance.d.ts +24 -0
  385. package/dist/services/staking/aggregate-staking-balance.d.ts.map +1 -0
  386. package/dist/services/staking/aggregate-staking-balance.js +82 -0
  387. package/dist/services/staking/aggregate-staking-balance.js.map +1 -0
  388. package/dist/services/wc-session-service.d.ts.map +1 -1
  389. package/dist/services/wc-session-service.js +2 -1
  390. package/dist/services/wc-session-service.js.map +1 -1
  391. package/dist/services/wc-signing-bridge.js +2 -2
  392. package/dist/services/wc-signing-bridge.js.map +1 -1
  393. package/dist/services/x402/payment-signer.d.ts.map +1 -1
  394. package/dist/services/x402/payment-signer.js +2 -5
  395. package/dist/services/x402/payment-signer.js.map +1 -1
  396. package/dist/services/x402/ssrf-guard.d.ts +4 -23
  397. package/dist/services/x402/ssrf-guard.d.ts.map +1 -1
  398. package/dist/services/x402/ssrf-guard.js +3 -232
  399. package/dist/services/x402/ssrf-guard.js.map +1 -1
  400. package/dist/signing/capabilities/eip712-signer.d.ts.map +1 -1
  401. package/dist/signing/capabilities/eip712-signer.js +2 -0
  402. package/dist/signing/capabilities/eip712-signer.js.map +1 -1
  403. package/package.json +5 -5
  404. package/public/admin/assets/index-CpFF2lCo.js +3 -0
  405. package/public/admin/index.html +1 -1
  406. package/dist/notifications/channels/ntfy.d.ts +0 -13
  407. package/dist/notifications/channels/ntfy.d.ts.map +0 -1
  408. package/dist/notifications/channels/ntfy.js +0 -74
  409. package/dist/notifications/channels/ntfy.js.map +0 -1
  410. package/dist/services/signing-sdk/channels/ntfy-signing-channel.d.ts +0 -66
  411. package/dist/services/signing-sdk/channels/ntfy-signing-channel.d.ts.map +0 -1
  412. package/dist/services/signing-sdk/channels/ntfy-signing-channel.js +0 -270
  413. package/dist/services/signing-sdk/channels/ntfy-signing-channel.js.map +0 -1
  414. package/public/admin/assets/index-CQ3i4P2U.js +0 -3
@@ -1,40 +1,15 @@
1
1
  /**
2
2
  * DatabasePolicyEngine - v1.2 DB-backed policy engine with network scoping.
3
3
  *
4
- * Evaluates transactions against policies stored in the policies table.
5
- * Supports SPENDING_LIMIT (4-tier classification), WHITELIST (address filtering),
6
- * ALLOWED_NETWORKS (network whitelist, permissive default),
7
- * ALLOWED_TOKENS (token transfer whitelist, default deny),
8
- * CONTRACT_WHITELIST (contract call whitelist, default deny),
9
- * METHOD_WHITELIST (optional method-level restriction for contract calls),
10
- * APPROVED_SPENDERS (approve spender whitelist, default deny),
11
- * APPROVE_AMOUNT_LIMIT (unlimited approve block + amount cap),
12
- * and APPROVE_TIER_OVERRIDE (forced tier for APPROVE transactions).
13
- *
14
- * Algorithm:
15
- * 1. Load enabled policies for wallet (wallet-specific + global), ORDER BY priority DESC
16
- * 2. If no policies found, return INSTANT passthrough (Phase 7 compat)
17
- * 3. Resolve overrides: 4-level priority (wallet+network > wallet+null > global+network > global+null)
18
- * 4. Evaluate WHITELIST: deny if toAddress not in allowed_addresses
19
- * 4a.5. Evaluate ALLOWED_NETWORKS: deny if network not in allowed list (permissive default)
20
- * 4b. Evaluate ALLOWED_TOKENS: deny TOKEN_TRANSFER if no policy or token not whitelisted
21
- * 4c. Evaluate CONTRACT_WHITELIST: deny CONTRACT_CALL if no policy or contract not whitelisted
22
- * 4d. Evaluate METHOD_WHITELIST: deny CONTRACT_CALL if method selector not whitelisted (optional)
23
- * 4e. Evaluate APPROVED_SPENDERS: deny APPROVE if no policy or spender not approved
24
- * 4f. Evaluate APPROVE_AMOUNT_LIMIT: deny APPROVE if unlimited or exceeds max amount
25
- * 4g. Evaluate APPROVE_TIER_OVERRIDE: force tier for APPROVE (defaults to APPROVAL, skips SPENDING_LIMIT)
26
- * 4h. Evaluate LENDING_ASSET_WHITELIST: deny lending action if asset not whitelisted (default-deny)
27
- * 4h-b. Evaluate LENDING_LTV_LIMIT: deny borrow if projected LTV exceeds maxLtv
28
- * 4i. Evaluate PERP_ALLOWED_MARKETS: deny perp action if market not whitelisted (default-deny)
29
- * 4i-b. Evaluate PERP_MAX_LEVERAGE: deny open/modify if leverage exceeds max
30
- * 4i-c. Evaluate PERP_MAX_POSITION_USD: deny open/modify if position USD exceeds max
31
- * 5. Evaluate SPENDING_LIMIT: classify amount into INSTANT/NOTIFY/DELAY/APPROVAL
32
- * (skip for non-spending lending actions: supply/repay/withdraw)
4
+ * This file contains the orchestration class that dispatches to evaluator modules
5
+ * in the evaluators/ directory. Each policy type has its own evaluator file.
33
6
  *
34
- * TOCTOU Prevention (evaluateAndReserve):
35
- * Uses BEGIN IMMEDIATE to serialize concurrent policy evaluations.
36
- * reserved_amount tracks pending amounts to prevent two requests from both passing
37
- * under the same spending limit.
7
+ * Evaluates transactions against policies stored in the policies table.
8
+ * Supports SPENDING_LIMIT, WHITELIST, ALLOWED_NETWORKS, ALLOWED_TOKENS,
9
+ * CONTRACT_WHITELIST, METHOD_WHITELIST, APPROVED_SPENDERS, APPROVE_AMOUNT_LIMIT,
10
+ * APPROVE_TIER_OVERRIDE, LENDING_ASSET_WHITELIST, LENDING_LTV_LIMIT,
11
+ * PERP_ALLOWED_MARKETS, PERP_MAX_LEVERAGE, PERP_MAX_POSITION_USD,
12
+ * VENUE_WHITELIST, ACTION_CATEGORY_LIMIT, and REPUTATION_THRESHOLD.
38
13
  *
39
14
  * @see docs/33-time-lock-approval-mechanism.md
40
15
  * @see docs/71-policy-engine-network-extension-design.md
@@ -45,66 +20,8 @@ import type { Database as SQLiteDatabase } from 'better-sqlite3';
45
20
  import type * as schema from '../infrastructure/database/schema.js';
46
21
  import type { SettingsService } from '../infrastructure/settings/settings-service.js';
47
22
  import type { ReputationCacheService } from '../services/erc8004/reputation-cache-service.js';
48
- /** Perp max leverage restriction rules (Phase 297). */
49
- export interface PerpMaxLeverageRules {
50
- maxLeverage: number;
51
- warningLeverage?: number;
52
- }
53
- /** Perp max position USD restriction rules (Phase 297). */
54
- export interface PerpMaxPositionUsdRules {
55
- maxPositionUsd: number;
56
- warningPositionUsd?: number;
57
- }
58
- /** Perp allowed markets whitelist rules (Phase 297). */
59
- export interface PerpAllowedMarketsRules {
60
- markets: Array<{
61
- market: string;
62
- name?: string;
63
- }>;
64
- }
65
- /** Transaction parameter for policy evaluation. */
66
- interface TransactionParam {
67
- type: string;
68
- amount: string;
69
- toAddress: string;
70
- chain: string;
71
- /** Resolved network for ALLOWED_NETWORKS evaluation + network scoping. */
72
- network?: string;
73
- /** Token address for ALLOWED_TOKENS evaluation (TOKEN_TRANSFER only). */
74
- tokenAddress?: string;
75
- /** CAIP-19 asset identifier for ALLOWED_TOKENS 4-scenario matching (TOKEN_TRANSFER only). */
76
- assetId?: string;
77
- /** Contract address for CONTRACT_WHITELIST evaluation (CONTRACT_CALL only). */
78
- contractAddress?: string;
79
- /** Function selector (4-byte hex, e.g. '0x12345678') for METHOD_WHITELIST evaluation (CONTRACT_CALL only). */
80
- selector?: string;
81
- /** Spender address for APPROVED_SPENDERS evaluation (APPROVE only). */
82
- spenderAddress?: string;
83
- /** Approve amount in raw units for APPROVE_AMOUNT_LIMIT evaluation (APPROVE only). */
84
- approveAmount?: string;
85
- /** Token decimals for token_limits human-readable conversion (TOKEN_TRANSFER/APPROVE only). */
86
- tokenDecimals?: number;
87
- /** Action provider name for provider-trust policy bypass (set by ActionProviderRegistry). */
88
- actionProvider?: string;
89
- /** Action name for lending policy evaluation (supply/borrow/repay/withdraw). Set by ActionProviderRegistry. */
90
- actionName?: string;
91
- /** Leverage for perp policy evaluation (open_position/modify_position). Set by ActionProviderRegistry. */
92
- perpLeverage?: number;
93
- /** Position size in USD for perp policy evaluation. Set by ActionProviderRegistry. */
94
- perpSizeUsd?: number;
95
- /** Venue identifier for VENUE_WHITELIST evaluation (signedData/signedHttp only). */
96
- venue?: string;
97
- /** Action category for ACTION_CATEGORY_LIMIT evaluation (e.g., 'trade', 'withdraw'). */
98
- actionCategory?: string;
99
- /** Notional USD value for ACTION_CATEGORY_LIMIT evaluation. */
100
- notionalUsd?: number;
101
- /** Leverage for off-chain action (for policy context). */
102
- leverage?: number;
103
- /** Expiry timestamp (ISO string) for off-chain action. */
104
- expiry?: string;
105
- /** Whether the off-chain action has withdrawal capability. */
106
- hasWithdrawCapability?: boolean;
107
- }
23
+ import type { PolicyRow, TransactionParam, ParseRulesContext } from './evaluators/types.js';
24
+ export type { PolicyRow, TransactionParam, ParseRulesContext };
108
25
  /**
109
26
  * DB-backed policy engine with SPENDING_LIMIT 4-tier, WHITELIST, ALLOWED_NETWORKS,
110
27
  * ALLOWED_TOKENS, CONTRACT_WHITELIST, METHOD_WHITELIST, APPROVED_SPENDERS,
@@ -112,9 +29,6 @@ interface TransactionParam {
112
29
  *
113
30
  * Network scoping: policies can target specific networks via the `network` column.
114
31
  * 4-level override priority: wallet+network > wallet+null > global+network > global+null.
115
- *
116
- * Constructor takes a Drizzle DB instance typed with the full schema,
117
- * and optionally a raw better-sqlite3 Database instance for BEGIN IMMEDIATE transactions.
118
32
  */
119
33
  export declare class DatabasePolicyEngine implements IPolicyEngine {
120
34
  private readonly db;
@@ -122,364 +36,30 @@ export declare class DatabasePolicyEngine implements IPolicyEngine {
122
36
  private readonly settingsService;
123
37
  private readonly reputationCacheService;
124
38
  constructor(db: BetterSQLite3Database<typeof schema>, sqlite?: SQLiteDatabase, settingsService?: SettingsService, reputationCacheService?: ReputationCacheService);
39
+ /** Evaluator context with parseRules + settingsService access. */
40
+ private get ctx();
125
41
  /**
126
- * Evaluate a transaction against DB-stored policies.
42
+ * Parse policy rules JSON with Zod validation.
43
+ * Throws POLICY_RULES_CORRUPT on invalid JSON or schema mismatch.
127
44
  */
128
- evaluate(walletId: string, transaction: TransactionParam): Promise<PolicyEvaluation>;
45
+ private parseRules;
129
46
  /**
130
- * Evaluate a batch of instructions using 2-stage policy evaluation.
131
- *
132
- * Phase A: Evaluate each instruction individually against its applicable policies.
133
- * All-or-Nothing: if any instruction is denied, entire batch is denied.
134
- *
135
- * Phase B: Sum native amounts (TRANSFER.amount) and evaluate
136
- * aggregate against SPENDING_LIMIT. If batch contains APPROVE, apply
137
- * APPROVE_TIER_OVERRIDE and take max(amount tier, approve tier).
138
- *
139
- * @param walletId - Wallet whose policies to evaluate
140
- * @param instructions - Array of instruction parameters (same shape as TransactionParam)
141
- * @returns PolicyEvaluation with final tier or denial with violation details
47
+ * Evaluate a transaction against DB-stored policies.
142
48
  */
49
+ evaluate(walletId: string, transaction: TransactionParam): Promise<PolicyEvaluation>;
143
50
  evaluateBatch(walletId: string, instructions: TransactionParam[], batchUsdAmount?: number): Promise<PolicyEvaluation>;
144
- /**
145
- * Evaluate applicable policies for a single instruction in a batch.
146
- *
147
- * Only evaluates type-specific policies:
148
- * - TRANSFER: WHITELIST
149
- * - TOKEN_TRANSFER: WHITELIST + ALLOWED_TOKENS
150
- * - CONTRACT_CALL: CONTRACT_WHITELIST + METHOD_WHITELIST
151
- * - APPROVE: APPROVED_SPENDERS + APPROVE_AMOUNT_LIMIT
152
- *
153
- * Does NOT evaluate SPENDING_LIMIT (that's Phase B aggregate) or
154
- * APPROVE_TIER_OVERRIDE (that's Phase B).
155
- *
156
- * Returns null if all policies pass, PolicyEvaluation with allowed=false if denied.
157
- */
158
51
  private evaluateInstructionPolicies;
159
- /**
160
- * Evaluate transaction and reserve amount atomically using BEGIN IMMEDIATE.
161
- *
162
- * This method:
163
- * 1. Begins an IMMEDIATE transaction (exclusive write lock)
164
- * 2. Loads policies (same as evaluate)
165
- * 3. For SPENDING_LIMIT: computes current reserved total from PENDING/QUEUED txs
166
- * 4. Adds current request amount to reserved total
167
- * 5. Evaluates against limits with reserved total considered
168
- * 6. If allowed: sets reserved_amount on the transaction row
169
- * 7. Commits
170
- *
171
- * @param walletId - The wallet whose policies to evaluate
172
- * @param transaction - Transaction details for evaluation
173
- * @param txId - The transaction ID to update with reserved_amount
174
- * @returns PolicyEvaluation result
175
- * @throws Error if sqlite instance not provided in constructor
176
- */
177
52
  evaluateAndReserve(walletId: string, transaction: TransactionParam, txId: string, usdAmount?: number, reputationFloorTier?: PolicyTier): PolicyEvaluation;
178
- /**
179
- * Release a reserved amount on a transaction.
180
- * Called when transaction reaches FAILED/CANCELLED/EXPIRED state.
181
- *
182
- * @param txId - The transaction ID to clear reservation for
183
- */
184
53
  releaseReservation(txId: string): void;
185
- /**
186
- * Get cumulative USD spent by wallet within a time window.
187
- * Includes both confirmed amounts (amount_usd) and pending reservations (reserved_amount_usd).
188
- *
189
- * CONFIRMED/SIGNED: counted via amount_usd (confirmed or about to be broadcasted).
190
- * PENDING/QUEUED: counted via reserved_amount_usd (awaiting processing, not yet confirmed).
191
- * Deduplication: SIGNED is in the first query only (amount_usd). PENDING/QUEUED in second only.
192
- */
193
54
  private getCumulativeUsdSpent;
194
- /**
195
- * Resolve policy overrides with 4-level priority:
196
- * 1. wallet-specific + network-specific (highest)
197
- * 2. wallet-specific + all-networks
198
- * 3. global + network-specific
199
- * 4. global + all-networks (lowest)
200
- *
201
- * For each policy type, one policy is selected.
202
- * Lower priority entries are inserted first, higher priority entries overwrite.
203
- * Key: typeMap[row.type] (same as current -- no composite key needed, PLCY-D03).
204
- *
205
- * Backward compat: when all policies have network=NULL,
206
- * phases 2+4 collapse into current 2-level (wallet > global) behavior.
207
- */
208
55
  private resolveOverrides;
209
- /**
210
- * Evaluate ALLOWED_NETWORKS policy.
211
- *
212
- * Logic:
213
- * - Applies to ALL 5 transaction types (TRANSFER, TOKEN_TRANSFER, CONTRACT_CALL, APPROVE, BATCH)
214
- * - If no ALLOWED_NETWORKS policy exists: return null (permissive default -- all networks allowed)
215
- * - If policy exists: check if resolvedNetwork is in rules.networks[].network
216
- * -> If found: return null (continue to next evaluation)
217
- * -> If not found: deny with reason 'Network not in allowed list'
218
- * - Comparison: case-insensitive (toLowerCase)
219
- * - Tier: INSTANT (immediate denial)
220
- *
221
- * Returns PolicyEvaluation if denied, null if allowed (or no policy).
222
- */
223
- private evaluateAllowedNetworks;
224
- /**
225
- * Evaluate WHITELIST policy.
226
- * Returns PolicyEvaluation if denied, null if allowed (or no whitelist).
227
- */
228
- private evaluateWhitelist;
229
- /**
230
- * Evaluate ALLOWED_TOKENS policy with 4-scenario matching matrix (PLCY-03).
231
- *
232
- * Logic:
233
- * - Only applies to TOKEN_TRANSFER transaction type
234
- * - If transaction type is TOKEN_TRANSFER and no ALLOWED_TOKENS policy exists:
235
- * -> deny with reason 'Token transfer not allowed: no ALLOWED_TOKENS policy configured'
236
- * - If ALLOWED_TOKENS policy exists, match using 4-scenario matrix:
237
- * Scenario 1: Policy assetId + TX assetId -> exact CAIP-19 string match
238
- * Scenario 2: Policy assetId + TX address only -> extract address from policy assetId, compare lowercase
239
- * Scenario 3: Policy address only + TX assetId -> extract address from TX assetId, compare lowercase
240
- * Scenario 4: Policy address only + TX address only -> current behavior (case-insensitive)
241
- * - EVM addresses normalized to lowercase for comparison (PLCY-04)
242
- *
243
- * Returns PolicyEvaluation if denied, null if allowed (or not applicable).
244
- */
245
- private evaluateAllowedTokens;
246
- /**
247
- * Evaluate CONTRACT_WHITELIST policy.
248
- *
249
- * Logic:
250
- * - Only applies to CONTRACT_CALL transaction type
251
- * - Provider-trust: if transaction has actionProvider and the provider is enabled
252
- * in SettingsService, skip CONTRACT_WHITELIST entirely (trusted provider bypass)
253
- * - If transaction type is CONTRACT_CALL and no CONTRACT_WHITELIST policy exists:
254
- * -> deny with reason 'Contract calls disabled: no CONTRACT_WHITELIST policy configured'
255
- * - If CONTRACT_WHITELIST policy exists, check if contract address is in rules.contracts[].address:
256
- * -> If found: return null (continue to next evaluation)
257
- * -> If not found: deny with reason 'Contract not whitelisted: {address}'
258
- * - For non-CONTRACT_CALL types: return null (not applicable)
259
- *
260
- * Returns PolicyEvaluation if denied, null if allowed (or not applicable).
261
- */
262
- private evaluateContractWhitelist;
263
- /**
264
- * Evaluate METHOD_WHITELIST policy.
265
- *
266
- * Logic:
267
- * - Only applies to CONTRACT_CALL transaction type
268
- * - If no METHOD_WHITELIST policy exists: return null (method restriction is optional)
269
- * - If METHOD_WHITELIST policy exists, find matching entry for transaction's contract address:
270
- * -> If no entry for this contract: return null (no method restriction for this contract)
271
- * -> If entry found, check if transaction's selector is in entry.selectors:
272
- * -> If found: return null (method allowed)
273
- * -> If not found: deny with reason 'Method not whitelisted: {selector} on contract {address}'
274
- *
275
- * Returns PolicyEvaluation if denied, null if allowed (or not applicable).
276
- */
277
- private evaluateMethodWhitelist;
278
- /**
279
- * Evaluate APPROVED_SPENDERS policy.
280
- *
281
- * Logic:
282
- * - Only applies to APPROVE transaction type
283
- * - If transaction type is APPROVE and no APPROVED_SPENDERS policy exists:
284
- * -> deny with reason 'Token approvals disabled: no APPROVED_SPENDERS policy configured'
285
- * - If APPROVED_SPENDERS policy exists, check if transaction's spenderAddress is in rules.spenders[]:
286
- * -> If found: return null (continue evaluation)
287
- * -> If not found: deny with reason 'Spender not in approved list: {address}'
288
- * - Case-insensitive comparison (EVM addresses)
289
- *
290
- * Returns PolicyEvaluation if denied, null if allowed (or not applicable).
291
- */
292
- private evaluateApprovedSpenders;
293
- /**
294
- * Evaluate APPROVE_AMOUNT_LIMIT policy.
295
- *
296
- * Logic:
297
- * - Only applies to APPROVE transaction type
298
- * - Checks for unlimited approve amounts (>= UNLIMITED_THRESHOLD)
299
- * - Checks for amount cap (maxAmount)
300
- * - If no policy exists: default block_unlimited=true (block unlimited approvals)
301
- *
302
- * Returns PolicyEvaluation if denied, null if allowed (or not applicable).
303
- */
304
- private evaluateApproveAmountLimit;
305
- /**
306
- * Evaluate APPROVE_TIER_OVERRIDE policy.
307
- *
308
- * Logic:
309
- * - Only applies to APPROVE transaction type
310
- * - If APPROVE_TIER_OVERRIDE policy exists: return configured tier (FINAL, skips SPENDING_LIMIT)
311
- * - If no APPROVE_TIER_OVERRIDE policy exists: return null (Phase 236: fall through to SPENDING_LIMIT
312
- * for token_limits evaluation; if no SPENDING_LIMIT either, INSTANT passthrough)
313
- *
314
- * Phase 236 change: Previously defaulted to APPROVAL when no override policy existed.
315
- * Now falls through to SPENDING_LIMIT to allow token_limits evaluation for APPROVE transactions.
316
- *
317
- * Returns PolicyEvaluation if override policy exists, null otherwise.
318
- */
319
- private evaluateApproveTierOverride;
320
- /**
321
- * Evaluate SPENDING_LIMIT policy.
322
- * Returns PolicyEvaluation with tier classification, or null if no spending limit.
323
- *
324
- * Phase 127: usdAmount가 전달되고 rules에 USD 임계값이 설정되어 있으면,
325
- * 네이티브 티어와 USD 티어 중 더 보수적인(높은) 티어를 채택한다.
326
- *
327
- * Phase 236: tokenContext가 전달되고 rules에 token_limits가 설정되어 있으면,
328
- * evaluateTokenTier()를 사용하여 토큰별 human-readable 한도를 평가한다.
329
- */
330
- private evaluateSpendingLimit;
331
- /**
332
- * Evaluate token-specific tier using token_limits with CAIP-19 key matching.
333
- * Returns PolicyTier if a matching token limit is found, null otherwise (-> raw fallback).
334
- *
335
- * Matching priority:
336
- * 1. Exact CAIP-19 asset ID match (TOKEN_TRANSFER, APPROVE)
337
- * 2. "native:{chain}" match (TRANSFER)
338
- * 3. "native" shorthand match (TRANSFER, only when policy has network set)
339
- * 4. No match -> return null (caller falls back to raw fields)
340
- */
341
- private evaluateTokenTier;
342
- /**
343
- * Evaluate native amount tier (extracted from evaluateSpendingLimit).
344
- * Phase 236: proper undefined guards for optional raw fields.
345
- */
346
- private evaluateNativeTier;
347
- /**
348
- * Check if rules have any USD thresholds configured.
349
- */
350
- private hasUsdThresholds;
351
- /**
352
- * Evaluate USD amount tier.
353
- */
354
- private evaluateUsdTier;
355
- /**
356
- * Build tokenContext from TransactionParam for evaluateTokenTier().
357
- * Phase 236: Extracts relevant fields and attaches the policy's network.
358
- */
359
- private buildTokenContext;
360
- /**
361
- * Evaluate LENDING_ASSET_WHITELIST policy.
362
- *
363
- * Logic:
364
- * - Only applies to lending actions (supply/borrow/repay/withdraw)
365
- * - If no LENDING_ASSET_WHITELIST policy exists: deny (default-deny per CLAUDE.md)
366
- * - If policy exists: check if target contract address is in rules.assets[].address
367
- *
368
- * Returns PolicyEvaluation if denied, null if allowed (or not applicable).
369
- */
370
- private evaluateLendingAssetWhitelist;
371
- /**
372
- * Evaluate LENDING_LTV_LIMIT policy for borrow actions.
373
- *
374
- * Logic:
375
- * - Only applies to borrow actions
376
- * - Reads cached LENDING positions from defi_positions table
377
- * - Calculates projected LTV = (currentDebtUsd + newBorrowUsd) / totalCollateralUsd
378
- * - Denies if projected LTV > maxLtv
379
- * - Returns DELAY tier if projected LTV > warningLtv
380
- *
381
- * @param usdAmount - USD value of the new borrow (from pipeline IPriceOracle, LEND-09)
382
- * Returns PolicyEvaluation if denied/escalated, null if allowed (or not applicable).
383
- */
384
- private evaluateLendingLtvLimit;
385
- /**
386
- * Evaluate PERP_ALLOWED_MARKETS policy.
387
- *
388
- * Logic:
389
- * - Only applies to perp actions (suffix matching: open_position, close_position,
390
- * modify_position, add_margin, withdraw_margin)
391
- * - If no PERP_ALLOWED_MARKETS policy exists: deny (default-deny per CLAUDE.md)
392
- * - If policy exists: check if transaction's market (from actionName prefix or params)
393
- * is in rules.markets[].market (case-insensitive)
394
- *
395
- * Market identification: TransactionParam.contractAddress is used as the market
396
- * identifier for perp actions (the protocol program/contract address).
397
- */
398
- private evaluatePerpAllowedMarkets;
399
- /**
400
- * Evaluate PERP_MAX_LEVERAGE policy.
401
- *
402
- * Logic:
403
- * - Only applies to open_position and modify_position (suffix matching)
404
- * - Reads perpLeverage from TransactionParam
405
- * - Denies if perpLeverage > rules.maxLeverage
406
- * - Returns DELAY tier if perpLeverage > rules.warningLeverage (optional)
407
- */
408
- private evaluatePerpMaxLeverage;
409
- /**
410
- * Evaluate PERP_MAX_POSITION_USD policy.
411
- *
412
- * Logic:
413
- * - Only applies to open_position and modify_position (suffix matching)
414
- * - Reads perpSizeUsd from TransactionParam
415
- * - Denies if perpSizeUsd > rules.maxPositionUsd
416
- * - Returns DELAY tier if perpSizeUsd > rules.warningPositionUsd (optional)
417
- */
418
- private evaluatePerpMaxPositionUsd;
419
- /**
420
- * Evaluate REPUTATION_THRESHOLD policy.
421
- *
422
- * Logic:
423
- * - Find REPUTATION_THRESHOLD policy in resolved list
424
- * - If not found or check_counterparty=false, return null (skip)
425
- * - Resolve counterparty agentId from toAddress via agent_identities table
426
- * - If no agentId found, treat as unrated
427
- * - If no reputationCacheService, treat as unrated
428
- * - Lookup reputation score via cache
429
- * - If null (unrated/RPC failure), return unrated_tier
430
- * - If score < min_score, return below_threshold_tier
431
- * - If score >= min_score, return null (pass, continue evaluation)
432
- *
433
- * Returns the reputation floor tier (PolicyTier) or null if no escalation needed.
434
- * The caller applies maxTier to the final result.
435
- */
436
56
  private evaluateReputationThreshold;
437
- /**
438
- * Resolve ERC-8004 agentId from a counterparty address.
439
- *
440
- * Looks up agent_identities table via wallet publicKey join to find
441
- * the chain_agent_id for the counterparty. Case-insensitive for EVM addresses.
442
- *
443
- * @returns chain_agent_id string if found, null otherwise
444
- */
445
57
  private resolveAgentIdFromAddress;
446
- /**
447
- * Pre-fetch reputation floor tier for use in evaluateAndReserve (synchronous context).
448
- *
449
- * Called from stage3Policy before entering the IMMEDIATE transaction, since
450
- * evaluateReputationThreshold is async (RPC call) but evaluateAndReserve is sync.
451
- *
452
- * @returns Object with tier and notification context if escalation needed, undefined otherwise
453
- */
454
58
  prefetchReputationTier(walletId: string, transaction: TransactionParam, reputationCache: ReputationCacheService): Promise<{
455
59
  tier: PolicyTier;
456
60
  score?: string;
457
61
  threshold?: string;
458
62
  } | undefined>;
459
- /**
460
- * Evaluate VENUE_WHITELIST policy (default-deny when enabled).
461
- *
462
- * Logic:
463
- * - If transaction has no venue (contractCall) -> return null (skip)
464
- * - If venue_whitelist_enabled setting is not 'true' -> return null (disabled)
465
- * - Find VENUE_WHITELIST policy in resolved list
466
- * - If no policy found + venue present -> DENY (default-deny)
467
- * - If policy found + venue in whitelist -> return null (allowed)
468
- * - If policy found + venue not in whitelist -> DENY
469
- */
470
- private evaluateVenueWhitelist;
471
- /**
472
- * Evaluate ACTION_CATEGORY_LIMIT policy (per-action, daily, monthly USD limits).
473
- *
474
- * Logic:
475
- * - If transaction has no actionCategory or notionalUsd -> return null (skip)
476
- * - Find ACTION_CATEGORY_LIMIT policies matching transaction.actionCategory
477
- * - Check per_action_limit_usd: deny if notionalUsd exceeds
478
- * - Check daily_limit_usd: query cumulative notionalUsd for category today
479
- * - Check monthly_limit_usd: query cumulative notionalUsd for category this month
480
- * - On exceed: return tier_on_exceed (default 'DELAY')
481
- */
482
- private evaluateActionCategoryLimit;
63
+ private buildTokenContext;
483
64
  }
484
- export {};
485
65
  //# sourceMappingURL=database-policy-engine.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"database-policy-engine.d.ts","sourceRoot":"","sources":["../../src/pipeline/database-policy-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,KAAK,EAA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