eco-solver 0.0.1-security → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of eco-solver might be problematic. Click here for more details.

Files changed (244) hide show
  1. package/.eslintignore +8 -0
  2. package/.eslintrc.js +24 -0
  3. package/.github/workflows/ci.yaml +38 -0
  4. package/.nvmrc +1 -0
  5. package/.prettierignore +3 -0
  6. package/.prettierrc +8 -0
  7. package/Dockerfile +11 -0
  8. package/LICENSE +21 -0
  9. package/README.md +29 -5
  10. package/config/default.ts +135 -0
  11. package/config/development.ts +95 -0
  12. package/config/preproduction.ts +17 -0
  13. package/config/production.ts +17 -0
  14. package/config/staging.ts +17 -0
  15. package/config/test.ts +7 -0
  16. package/index.js +43 -0
  17. package/jest.config.ts +14 -0
  18. package/nest-cli.json +8 -0
  19. package/package.json +117 -6
  20. package/src/api/api.module.ts +27 -0
  21. package/src/api/balance.controller.ts +41 -0
  22. package/src/api/quote.controller.ts +54 -0
  23. package/src/api/tests/balance.controller.spec.ts +113 -0
  24. package/src/api/tests/quote.controller.spec.ts +83 -0
  25. package/src/app.module.ts +74 -0
  26. package/src/balance/balance.module.ts +14 -0
  27. package/src/balance/balance.service.ts +230 -0
  28. package/src/balance/balance.ws.service.ts +104 -0
  29. package/src/balance/types.ts +16 -0
  30. package/src/bullmq/bullmq.helper.ts +41 -0
  31. package/src/bullmq/processors/eth-ws.processor.ts +47 -0
  32. package/src/bullmq/processors/inbox.processor.ts +55 -0
  33. package/src/bullmq/processors/interval.processor.ts +54 -0
  34. package/src/bullmq/processors/processor.module.ts +14 -0
  35. package/src/bullmq/processors/signer.processor.ts +41 -0
  36. package/src/bullmq/processors/solve-intent.processor.ts +73 -0
  37. package/src/bullmq/processors/tests/solve-intent.processor.spec.ts +3 -0
  38. package/src/bullmq/utils/queue.ts +22 -0
  39. package/src/chain-monitor/chain-monitor.module.ts +12 -0
  40. package/src/chain-monitor/chain-sync.service.ts +134 -0
  41. package/src/chain-monitor/tests/chain-sync.service.spec.ts +190 -0
  42. package/src/commander/.eslintrc.js +6 -0
  43. package/src/commander/balance/balance-command.module.ts +12 -0
  44. package/src/commander/balance/balance.command.ts +73 -0
  45. package/src/commander/command-main.ts +15 -0
  46. package/src/commander/commander-app.module.ts +31 -0
  47. package/src/commander/eco-config.command.ts +20 -0
  48. package/src/commander/safe/safe-command.module.ts +11 -0
  49. package/src/commander/safe/safe.command.ts +70 -0
  50. package/src/commander/transfer/client.command.ts +24 -0
  51. package/src/commander/transfer/transfer-command.module.ts +26 -0
  52. package/src/commander/transfer/transfer.command.ts +138 -0
  53. package/src/commander/utils.ts +8 -0
  54. package/src/common/chains/definitions/arbitrum.ts +12 -0
  55. package/src/common/chains/definitions/base.ts +21 -0
  56. package/src/common/chains/definitions/eco.ts +54 -0
  57. package/src/common/chains/definitions/ethereum.ts +22 -0
  58. package/src/common/chains/definitions/helix.ts +53 -0
  59. package/src/common/chains/definitions/mantle.ts +12 -0
  60. package/src/common/chains/definitions/optimism.ts +22 -0
  61. package/src/common/chains/definitions/polygon.ts +12 -0
  62. package/src/common/chains/supported.ts +26 -0
  63. package/src/common/chains/transport.ts +19 -0
  64. package/src/common/errors/eco-error.ts +155 -0
  65. package/src/common/events/constants.ts +3 -0
  66. package/src/common/events/viem.ts +22 -0
  67. package/src/common/logging/eco-log-message.ts +74 -0
  68. package/src/common/redis/constants.ts +55 -0
  69. package/src/common/redis/redis-connection-utils.ts +106 -0
  70. package/src/common/routes/constants.ts +3 -0
  71. package/src/common/utils/objects.ts +34 -0
  72. package/src/common/utils/strings.ts +49 -0
  73. package/src/common/utils/tests/objects.spec.ts +23 -0
  74. package/src/common/utils/tests/strings.spec.ts +22 -0
  75. package/src/common/viem/contracts.ts +25 -0
  76. package/src/common/viem/tests/utils.spec.ts +115 -0
  77. package/src/common/viem/utils.ts +78 -0
  78. package/src/contracts/ERC20.contract.ts +389 -0
  79. package/src/contracts/EntryPoint.V6.contract.ts +1309 -0
  80. package/src/contracts/KernelAccount.abi.ts +87 -0
  81. package/src/contracts/OwnableExecutor.abi.ts +128 -0
  82. package/src/contracts/SimpleAccount.contract.ts +524 -0
  83. package/src/contracts/inbox.ts +8 -0
  84. package/src/contracts/index.ts +9 -0
  85. package/src/contracts/intent-source.ts +55 -0
  86. package/src/contracts/interfaces/index.ts +1 -0
  87. package/src/contracts/interfaces/prover.interface.ts +22 -0
  88. package/src/contracts/prover.ts +9 -0
  89. package/src/contracts/tests/erc20.contract.spec.ts +59 -0
  90. package/src/contracts/utils.ts +31 -0
  91. package/src/decoder/decoder.interface.ts +3 -0
  92. package/src/decoder/tests/utils.spec.ts +36 -0
  93. package/src/decoder/utils.ts +24 -0
  94. package/src/decorators/cacheable.decorator.ts +48 -0
  95. package/src/eco-configs/aws-config.service.ts +75 -0
  96. package/src/eco-configs/eco-config.module.ts +44 -0
  97. package/src/eco-configs/eco-config.service.ts +220 -0
  98. package/src/eco-configs/eco-config.types.ts +278 -0
  99. package/src/eco-configs/interfaces/config-source.interface.ts +3 -0
  100. package/src/eco-configs/tests/aws-config.service.spec.ts +52 -0
  101. package/src/eco-configs/tests/eco-config.service.spec.ts +137 -0
  102. package/src/eco-configs/tests/utils.spec.ts +84 -0
  103. package/src/eco-configs/utils.ts +49 -0
  104. package/src/fee/fee.module.ts +10 -0
  105. package/src/fee/fee.service.ts +467 -0
  106. package/src/fee/tests/fee.service.spec.ts +909 -0
  107. package/src/fee/tests/utils.spec.ts +49 -0
  108. package/src/fee/types.ts +44 -0
  109. package/src/fee/utils.ts +23 -0
  110. package/src/flags/flags.module.ts +10 -0
  111. package/src/flags/flags.service.ts +112 -0
  112. package/src/flags/tests/flags.service.spec.ts +68 -0
  113. package/src/flags/utils.ts +22 -0
  114. package/src/health/constants.ts +1 -0
  115. package/src/health/health.controller.ts +23 -0
  116. package/src/health/health.module.ts +25 -0
  117. package/src/health/health.service.ts +40 -0
  118. package/src/health/indicators/balance.indicator.ts +196 -0
  119. package/src/health/indicators/eco-redis.indicator.ts +23 -0
  120. package/src/health/indicators/git-commit.indicator.ts +67 -0
  121. package/src/health/indicators/mongodb.indicator.ts +11 -0
  122. package/src/health/indicators/permission.indicator.ts +64 -0
  123. package/src/intent/create-intent.service.ts +129 -0
  124. package/src/intent/feasable-intent.service.ts +80 -0
  125. package/src/intent/fulfill-intent.service.ts +318 -0
  126. package/src/intent/intent.controller.ts +199 -0
  127. package/src/intent/intent.module.ts +49 -0
  128. package/src/intent/schemas/intent-call-data.schema.ts +16 -0
  129. package/src/intent/schemas/intent-data.schema.ts +114 -0
  130. package/src/intent/schemas/intent-source.schema.ts +33 -0
  131. package/src/intent/schemas/intent-token-amount.schema.ts +14 -0
  132. package/src/intent/schemas/reward-data.schema.ts +48 -0
  133. package/src/intent/schemas/route-data.schema.ts +52 -0
  134. package/src/intent/schemas/watch-event.schema.ts +32 -0
  135. package/src/intent/tests/create-intent.service.spec.ts +215 -0
  136. package/src/intent/tests/feasable-intent.service.spec.ts +155 -0
  137. package/src/intent/tests/fulfill-intent.service.spec.ts +564 -0
  138. package/src/intent/tests/utils-intent.service.spec.ts +308 -0
  139. package/src/intent/tests/utils.spec.ts +62 -0
  140. package/src/intent/tests/validate-intent.service.spec.ts +297 -0
  141. package/src/intent/tests/validation.service.spec.ts +337 -0
  142. package/src/intent/utils-intent.service.ts +168 -0
  143. package/src/intent/utils.ts +37 -0
  144. package/src/intent/validate-intent.service.ts +176 -0
  145. package/src/intent/validation.sevice.ts +223 -0
  146. package/src/interceptors/big-int.interceptor.ts +30 -0
  147. package/src/intervals/interval.module.ts +18 -0
  148. package/src/intervals/retry-infeasable-intents.service.ts +89 -0
  149. package/src/intervals/tests/retry-infeasable-intents.service.spec.ts +167 -0
  150. package/src/kms/errors.ts +0 -0
  151. package/src/kms/kms.module.ts +12 -0
  152. package/src/kms/kms.service.ts +65 -0
  153. package/src/kms/tests/kms.service.spec.ts +60 -0
  154. package/src/liquidity-manager/jobs/check-balances-cron.job.ts +229 -0
  155. package/src/liquidity-manager/jobs/liquidity-manager.job.ts +52 -0
  156. package/src/liquidity-manager/jobs/rebalance.job.ts +61 -0
  157. package/src/liquidity-manager/liquidity-manager.module.ts +29 -0
  158. package/src/liquidity-manager/processors/base.processor.ts +117 -0
  159. package/src/liquidity-manager/processors/eco-protocol-intents.processor.ts +34 -0
  160. package/src/liquidity-manager/processors/grouped-jobs.processor.ts +103 -0
  161. package/src/liquidity-manager/queues/liquidity-manager.queue.ts +48 -0
  162. package/src/liquidity-manager/schemas/rebalance-token.schema.ts +32 -0
  163. package/src/liquidity-manager/schemas/rebalance.schema.ts +32 -0
  164. package/src/liquidity-manager/services/liquidity-manager.service.ts +188 -0
  165. package/src/liquidity-manager/services/liquidity-provider.service.ts +25 -0
  166. package/src/liquidity-manager/services/liquidity-providers/LiFi/lifi-provider.service.spec.ts +125 -0
  167. package/src/liquidity-manager/services/liquidity-providers/LiFi/lifi-provider.service.ts +117 -0
  168. package/src/liquidity-manager/services/liquidity-providers/LiFi/utils/get-transaction-hashes.ts +16 -0
  169. package/src/liquidity-manager/tests/liquidity-manager.service.spec.ts +142 -0
  170. package/src/liquidity-manager/types/token-state.enum.ts +5 -0
  171. package/src/liquidity-manager/types/types.d.ts +52 -0
  172. package/src/liquidity-manager/utils/address.ts +5 -0
  173. package/src/liquidity-manager/utils/math.ts +9 -0
  174. package/src/liquidity-manager/utils/serialize.spec.ts +24 -0
  175. package/src/liquidity-manager/utils/serialize.ts +47 -0
  176. package/src/liquidity-manager/utils/token.ts +91 -0
  177. package/src/main.ts +63 -0
  178. package/src/nest-redlock/nest-redlock.config.ts +14 -0
  179. package/src/nest-redlock/nest-redlock.interface.ts +5 -0
  180. package/src/nest-redlock/nest-redlock.module.ts +64 -0
  181. package/src/nest-redlock/nest-redlock.service.ts +59 -0
  182. package/src/prover/proof.service.ts +184 -0
  183. package/src/prover/prover.module.ts +10 -0
  184. package/src/prover/tests/proof.service.spec.ts +154 -0
  185. package/src/quote/dto/quote.intent.data.dto.ts +35 -0
  186. package/src/quote/dto/quote.reward.data.dto.ts +67 -0
  187. package/src/quote/dto/quote.route.data.dto.ts +71 -0
  188. package/src/quote/dto/types.ts +18 -0
  189. package/src/quote/errors.ts +215 -0
  190. package/src/quote/quote.module.ts +17 -0
  191. package/src/quote/quote.service.ts +299 -0
  192. package/src/quote/schemas/quote-call.schema.ts +16 -0
  193. package/src/quote/schemas/quote-intent.schema.ts +27 -0
  194. package/src/quote/schemas/quote-reward.schema.ts +24 -0
  195. package/src/quote/schemas/quote-route.schema.ts +30 -0
  196. package/src/quote/schemas/quote-token.schema.ts +14 -0
  197. package/src/quote/tests/quote.service.spec.ts +444 -0
  198. package/src/sign/atomic-signer.service.ts +24 -0
  199. package/src/sign/atomic.nonce.service.ts +114 -0
  200. package/src/sign/kms-account/kmsToAccount.ts +73 -0
  201. package/src/sign/kms-account/signKms.ts +30 -0
  202. package/src/sign/kms-account/signKmsTransaction.ts +37 -0
  203. package/src/sign/kms-account/signKmsTypedData.ts +21 -0
  204. package/src/sign/nonce.service.ts +89 -0
  205. package/src/sign/schemas/nonce.schema.ts +36 -0
  206. package/src/sign/sign.controller.ts +52 -0
  207. package/src/sign/sign.helper.ts +23 -0
  208. package/src/sign/sign.module.ts +27 -0
  209. package/src/sign/signer-kms.service.ts +27 -0
  210. package/src/sign/signer.service.ts +26 -0
  211. package/src/solver/filters/tests/valid-smart-wallet.service.spec.ts +87 -0
  212. package/src/solver/filters/valid-smart-wallet.service.ts +58 -0
  213. package/src/solver/solver.module.ts +10 -0
  214. package/src/transaction/multichain-public-client.service.ts +15 -0
  215. package/src/transaction/smart-wallets/kernel/actions/encodeData.kernel.ts +57 -0
  216. package/src/transaction/smart-wallets/kernel/create-kernel-client-v2.account.ts +183 -0
  217. package/src/transaction/smart-wallets/kernel/create.kernel.account.ts +270 -0
  218. package/src/transaction/smart-wallets/kernel/index.ts +2 -0
  219. package/src/transaction/smart-wallets/kernel/kernel-account-client-v2.service.ts +90 -0
  220. package/src/transaction/smart-wallets/kernel/kernel-account-client.service.ts +107 -0
  221. package/src/transaction/smart-wallets/kernel/kernel-account.client.ts +105 -0
  222. package/src/transaction/smart-wallets/kernel/kernel-account.config.ts +34 -0
  223. package/src/transaction/smart-wallets/simple-account/create.simple.account.ts +19 -0
  224. package/src/transaction/smart-wallets/simple-account/index.ts +2 -0
  225. package/src/transaction/smart-wallets/simple-account/simple-account-client.service.ts +42 -0
  226. package/src/transaction/smart-wallets/simple-account/simple-account.client.ts +83 -0
  227. package/src/transaction/smart-wallets/simple-account/simple-account.config.ts +5 -0
  228. package/src/transaction/smart-wallets/smart-wallet.types.ts +38 -0
  229. package/src/transaction/smart-wallets/utils.ts +14 -0
  230. package/src/transaction/transaction.module.ts +25 -0
  231. package/src/transaction/viem_multichain_client.service.ts +100 -0
  232. package/src/transforms/viem-address.decorator.ts +14 -0
  233. package/src/utils/bigint.ts +44 -0
  234. package/src/utils/types.ts +18 -0
  235. package/src/watch/intent/tests/watch-create-intent.service.spec.ts +257 -0
  236. package/src/watch/intent/tests/watch-fulfillment.service.spec.ts +141 -0
  237. package/src/watch/intent/watch-create-intent.service.ts +106 -0
  238. package/src/watch/intent/watch-event.service.ts +133 -0
  239. package/src/watch/intent/watch-fulfillment.service.ts +115 -0
  240. package/src/watch/watch.module.ts +13 -0
  241. package/test/app.e2e-spec.ts +21 -0
  242. package/test/jest-e2e.json +9 -0
  243. package/tsconfig.build.json +4 -0
  244. package/tsconfig.json +29 -0
@@ -0,0 +1,199 @@
1
+ import { Controller, Get } from '@nestjs/common'
2
+ import { WatchCreateIntentService } from '../watch/intent/watch-create-intent.service'
3
+ import { Network } from 'alchemy-sdk'
4
+ import { ValidateIntentService } from './validate-intent.service'
5
+ import { Logger } from '@nestjs/common'
6
+ import { EcoLogMessage } from '../common/logging/eco-log-message'
7
+ import { IntentSource } from '../eco-configs/eco-config.types'
8
+ import { IntentCreatedLog } from '../contracts'
9
+
10
+ @Controller('intent')
11
+ export class IntentSourceController {
12
+ private logger = new Logger(IntentSourceController.name)
13
+ constructor(
14
+ private readonly watchIntentService: WatchCreateIntentService,
15
+ private readonly validateService: ValidateIntentService,
16
+ ) {}
17
+
18
+ @Get()
19
+ async fakeIntent() {
20
+ const intent = intentPreprod
21
+ const si: IntentSource = {
22
+ network: intent[0].sourceNetwork as Network,
23
+ chainID: Number(intent[0].sourceChainID),
24
+ sourceAddress: '0x',
25
+ tokens: [],
26
+ provers: [],
27
+ }
28
+ this.logger.debug(
29
+ EcoLogMessage.fromDefault({
30
+ message: `fakeIntent intent`,
31
+ properties: {
32
+ si: si,
33
+ },
34
+ }),
35
+ )
36
+
37
+ return await this.watchIntentService.addJob(si)(intent)
38
+ // return this.wsService.addJob(Network.OPT_SEPOLIA)(intent)
39
+ }
40
+
41
+ @Get('process')
42
+ async fakeProcess() {
43
+ const hash = '0xe42305a292d4df6805f686b2d575b01bfcef35f22675a82aacffacb2122b890f'
44
+ return await this.validateService.validateIntent(hash)
45
+ // await this.intentQueue.add(QUEUES.SOURCE_INTENT.jobs.process_intent, hash, {
46
+ // jobId: hash,
47
+ // })
48
+ }
49
+ }
50
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
51
+ const intentSepolia = [
52
+ {
53
+ blockNumber: 17962391,
54
+ blockHash: '0xee4e51400ef5a10f3320acdd3185b81be256f72b38ce58e30e8bfc82bebf1fdf',
55
+ transactionIndex: 5,
56
+ removed: false,
57
+ address: '0xc135737f2a05b0f65c33dab7c60e63e3e2008c6c',
58
+ data: '0x000000000000000000000000448729e46c442b55c43218c6db91c4633d36dfc000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000002203b1577c45a6844d79e91e8aa32364e57ef8eb2885b839412eaaaca9e0b39e0900000000000000000000000007c6a40f388dfd4cf1a8456978c55227f3e968ab70000000000000000000000000000000000000000000000000',
59
+ topics: [
60
+ '0x653c41cbe9402a28b206076ac6e316307a1ef8f76f247c1da9fdc2f50a405819',
61
+ '0xbea19c3652e996e07102c0a264fc378fd7c5a3d7cf5ee9094c82fc17ad9b584b',
62
+ '0x0000000000000000000000000000000000000000000000000000000000014a34',
63
+ '0x0000000000000000000000000000000000000000000000000000000066fb14e6',
64
+ ],
65
+ transactionHash: '0xa3927752f5954956a8bdb232c05fb32ed43ce73fc57fad33575f6de488a6f819',
66
+ logIndex: 54,
67
+ sourceNetwork: 'opt-sepolia' as Network,
68
+ sourceChainID: 11155420,
69
+ } as unknown as IntentCreatedLog,
70
+ {
71
+ blockNumber: 17962148,
72
+ blockHash: '0xe571be8cc3d3d5e7125e1adf34949c8c5ed79212619986e08183e7194215f9ef',
73
+ transactionIndex: 3,
74
+ removed: false,
75
+ address: '0xc135737f2a05b0f65c33dab7c60e63e3e2008c6c',
76
+ data: '0x000000000000000000000000448729e46c442b55c43218c6db91c4633d36dfc000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000220d6d2d4c7071ecb71efe5d347b841cfe160f86eacc65af977178318d92cd2665c000000000000000000000000b31fd140643dbd868e7732eecb5ac9c859348eb90000000000000000000000000000000000000000000000000',
77
+ topics: [
78
+ '0x653c41cbe9402a28b206076ac6e316307a1ef8f76f247c1da9fdc2f50a405819',
79
+ '0x59f1406ab59d835cdbb5bd0bee0338fa1a1192537d6edc3cde81a783004fae55',
80
+ '0x0000000000000000000000000000000000000000000000000000000000014a34',
81
+ '0x0000000000000000000000000000000000000000000000000000000066fb1300',
82
+ ],
83
+ transactionHash: '0x3a9bd095198503ee742d40d6e53ecd51fca6bd0898a9519f253f4d41696f9da6',
84
+ logIndex: 10,
85
+ sourceNetwork: 'opt-sepolia' as Network,
86
+ sourceChainID: 11155420,
87
+ } as unknown as IntentCreatedLog,
88
+ ]
89
+
90
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
91
+ const intentMainnet = [
92
+ {
93
+ blockNumber: 20220263,
94
+ blockHash: '0x97e812234007ea7ec5fd148303eba2f4a66eee559a7513ee05463d1340e1da0f',
95
+ transactionIndex: 37,
96
+ removed: false,
97
+ address: '0x13727384eb72ee4de1332634957f5473e5f1d52a',
98
+ data: '0x00000000000000000000000035395d96fcb26d416fd5593cadec099cf6b2900700000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000002207b518f342018b98c52a34a7ef70864fb17154c485d3e0e2514804e6127347baf00000000000000000000000099b07ff401e2c73826f3043adab2ef37e53d4f23000000000000000000000000000000000000000000000000000000000000000100000000000000000000000094b008aa00579c1307b0ef2c499ad98a8ce58e58000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000044a9059cbb00000000000000000000000035395d96fcb26d416fd5593cadec099cf6b2900700000000000000000000000000000000000000000000000000000000001240fd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000001240fd',
99
+ topics: [
100
+ '0x653c41cbe9402a28b206076ac6e316307a1ef8f76f247c1da9fdc2f50a405819',
101
+ '0x0ad607c1c6b1257f303fd7df4eb3b2b34f6cbf44bea7ee472c80d09d3a78ec6c',
102
+ '0x000000000000000000000000000000000000000000000000000000000000000a',
103
+ '0x000000000000000000000000000000000000000000000000000000006705e4a9',
104
+ ],
105
+ transactionHash: '0x9fc8563025960dc7c5f2352581370bed98938fea61f156bddd94b7c636a712c0',
106
+ logIndex: 166,
107
+ sourceNetwork: 'base-mainnet' as Network,
108
+ sourceChainID: 8453,
109
+ } as unknown as IntentCreatedLog,
110
+ {
111
+ blockNumber: 20220263,
112
+ blockHash: '0x97e812234007ea7ec5fd148303eba2f4a66eee559a7513ee05463d1340e1da0f',
113
+ transactionIndex: 37,
114
+ removed: false,
115
+ address: '0x13727384eb72ee4de1332634957f5473e5f1d52a',
116
+ data: '0x00000000000000000000000035395d96fcb26d416fd5593cadec099cf6b2900700000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000220e7b20d93a3118925da179090f052bc426d516e46b502f8ca98569063535f018600000000000000000000000099b07ff401e2c73826f3043adab2ef37e53d4f23000000000000000000000000000000000000000000000000000000000000000100000000000000000000000094b008aa00579c1307b0ef2c499ad98a8ce58e58000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000044a9059cbb00000000000000000000000035395d96fcb26d416fd5593cadec099cf6b2900700000000000000000000000000000000000000000000000000000000003b90e3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000d9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000003b90e3',
117
+ topics: [
118
+ '0x653c41cbe9402a28b206076ac6e316307a1ef8f76f247c1da9fdc2f50a405819',
119
+ '0xae7027bea4a9a181da07e4bfcc8def155d49e57fec3319cfcbfc729828e995a9',
120
+ '0x000000000000000000000000000000000000000000000000000000000000000a',
121
+ '0x000000000000000000000000000000000000000000000000000000006705e4a9',
122
+ ],
123
+ transactionHash: '0x9fc8563025960dc7c5f2352581370bed98938fea61f156bddd94b7c636a712c0',
124
+ logIndex: 170,
125
+ sourceNetwork: 'base-mainnet' as Network,
126
+ sourceChainID: 8453,
127
+ } as unknown as IntentCreatedLog,
128
+ ]
129
+
130
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
131
+ const intentPreprod = [
132
+ {
133
+ eventName: 'IntentCreated',
134
+ args: {
135
+ _hash: '0x52b423ed4c168c87c01c74b4b029b43d6c30f28d9c243302a7b2a328ea077ad2',
136
+ _destinationChain: 8453n,
137
+ _expiryTime: 1729177919n,
138
+ _creator: '0xE105537f4Cc3474f62A10d6666CA99C472df23Ce',
139
+ _targets: ['0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'],
140
+ _data: [
141
+ '0xa9059cbb000000000000000000000000e105537f4cc3474f62a10d6666ca99c472df23ce00000000000000000000000000000000000000000000000000000000000186a0',
142
+ ],
143
+ _rewardTokens: ['0x7F5c764cBc14f9669B88837ca1490cCa17c31607'],
144
+ _rewardAmounts: [100000n],
145
+ nonce: '0xab2e7c93b77d291ccc2bb5e5e387766aa4ff230cfccbafafca668e41e7600161',
146
+ _prover: '0x99b07fF401E2c73826f3043AdaB2ef37e53d4f23',
147
+ },
148
+ address: '0x6d9eede368621f173e5c93384cfccbfee19f9609',
149
+ blockHash: '0xc3d3c86c06e97602532e5adc6e3368c797e0c6adb7c13d5d2f314c63535245cf',
150
+ blockNumber: 126184775n,
151
+ data: '0x000000000000000000000000e105537f4cc3474f62a10d6666ca99c472df23ce00000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000220ab2e7c93b77d291ccc2bb5e5e387766aa4ff230cfccbafafca668e41e760016100000000000000000000000099b07ff401e2c73826f3043adab2ef37e53d4f230000000000000000000000000000000000000000000000000000000000000001000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000e105537f4cc3474f62a10d6666ca99c472df23ce00000000000000000000000000000000000000000000000000000000000186a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000007f5c764cbc14f9669b88837ca1490cca17c31607000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000186a0',
152
+ logIndex: 38,
153
+ removed: false,
154
+ topics: [
155
+ '0x653c41cbe9402a28b206076ac6e316307a1ef8f76f247c1da9fdc2f50a405819',
156
+ '0x52b423ed4c168c87c01c74b4b029b43d6c30f28d9c243302a7b2a328ea077ad2',
157
+ '0x0000000000000000000000000000000000000000000000000000000000002105',
158
+ '0x000000000000000000000000000000000000000000000000000000006711293f',
159
+ ],
160
+ transactionHash: '0xdd34f28a776b334e108c4f2f7fce8172706f91cd6ceae6f3cdd982af90cb72f5',
161
+ transactionIndex: 15,
162
+ sourceChainID: 10,
163
+ sourceNetwork: 'opt-mainnet',
164
+ // "watchintent-0xdd34f28a776b334e108c4f2f7fce8172706f91cd6ceae6f3cdd982af90cb72f5-38"
165
+ } as unknown as IntentCreatedLog,
166
+ {
167
+ eventName: 'IntentCreated',
168
+ args: {
169
+ _hash: '0x5142534d8af59ce2916fc2a4c6b5767b10704befab006550905b343d05a71a14',
170
+ _destinationChain: '8453',
171
+ _expiryTime: '1729184897',
172
+ _creator: '0xE105537f4Cc3474f62A10d6666CA99C472df23Ce',
173
+ _targets: ['0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'],
174
+ _data: [
175
+ '0xa9059cbb000000000000000000000000e105537f4cc3474f62a10d6666ca99c472df23ce0000000000000000000000000000000000000000000000000000000000004e20',
176
+ ],
177
+ _rewardTokens: ['0x7F5c764cBc14f9669B88837ca1490cCa17c31607'],
178
+ _rewardAmounts: ['20000'],
179
+ nonce: '0xd08d78535e1b1ad9259940cf4a5f412310e10951b446c8c9ef99bde6ecb06e83',
180
+ _prover: '0x99b07fF401E2c73826f3043AdaB2ef37e53d4f23',
181
+ },
182
+ address: '0x6d9eede368621f173e5c93384cfccbfee19f9609',
183
+ topics: [
184
+ '0x653c41cbe9402a28b206076ac6e316307a1ef8f76f247c1da9fdc2f50a405819',
185
+ '0x5142534d8af59ce2916fc2a4c6b5767b10704befab006550905b343d05a71a14',
186
+ '0x0000000000000000000000000000000000000000000000000000000000002105',
187
+ '0x0000000000000000000000000000000000000000000000000000000067114481',
188
+ ],
189
+ data: '0x000000000000000000000000e105537f4cc3474f62a10d6666ca99c472df23ce00000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000220d08d78535e1b1ad9259940cf4a5f412310e10951b446c8c9ef99bde6ecb06e8300000000000000000000000099b07ff401e2c73826f3043adab2ef37e53d4f230000000000000000000000000000000000000000000000000000000000000001000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000e105537f4cc3474f62a10d6666ca99c472df23ce0000000000000000000000000000000000000000000000000000000000004e200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000007f5c764cbc14f9669b88837ca1490cca17c3160700000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000004e20',
190
+ blockNumber: '126188264',
191
+ transactionHash: '0x18a87f736d686808de36edae5788d1743be2ec61cfad327fb311856354815af0',
192
+ transactionIndex: 9,
193
+ blockHash: '0xbb4e270bd6de43134a0983198069a98b0f4c44987307ecc5c715bd091daea47b',
194
+ logIndex: 35,
195
+ removed: false,
196
+ sourceNetwork: 'opt-mainnet',
197
+ sourceChainID: 10,
198
+ } as unknown as IntentCreatedLog,
199
+ ]
@@ -0,0 +1,49 @@
1
+ import { Module } from '@nestjs/common'
2
+ import { initBullMQ } from '../bullmq/bullmq.helper'
3
+ import { QUEUES } from '../common/redis/constants'
4
+ import { IntentSourceModel, IntentSourceSchema } from './schemas/intent-source.schema'
5
+ import { ValidateIntentService } from './validate-intent.service'
6
+ import { FeasableIntentService } from './feasable-intent.service'
7
+ import { CreateIntentService } from './create-intent.service'
8
+ import { UtilsIntentService } from './utils-intent.service'
9
+ import { BalanceModule } from '../balance/balance.module'
10
+ import { FulfillIntentService } from './fulfill-intent.service'
11
+ import { ProverModule } from '../prover/prover.module'
12
+ import { TransactionModule } from '../transaction/transaction.module'
13
+ import { MongooseModule } from '@nestjs/mongoose'
14
+ import { SolverModule } from '../solver/solver.module'
15
+ import { FlagsModule } from '../flags/flags.module'
16
+ import { ValidationService } from '@/intent/validation.sevice'
17
+ import { FeeModule } from '@/fee/fee.module'
18
+
19
+ @Module({
20
+ imports: [
21
+ BalanceModule,
22
+ FeeModule,
23
+ FlagsModule,
24
+ MongooseModule.forFeature([{ name: IntentSourceModel.name, schema: IntentSourceSchema }]),
25
+ ProverModule,
26
+ SolverModule,
27
+ TransactionModule,
28
+ initBullMQ(QUEUES.SOURCE_INTENT),
29
+ ],
30
+ providers: [
31
+ CreateIntentService,
32
+ ValidateIntentService,
33
+ FeasableIntentService,
34
+ FulfillIntentService,
35
+ UtilsIntentService,
36
+ ValidationService,
37
+ ],
38
+ // controllers: [IntentSourceController],
39
+ exports: [
40
+ CreateIntentService,
41
+ ValidateIntentService,
42
+ FeasableIntentService,
43
+ FulfillIntentService,
44
+ UtilsIntentService,
45
+ ValidationService,
46
+ MongooseModule, //add IntentSourceModel to the rest of the modules that import intents
47
+ ],
48
+ })
49
+ export class IntentModule {}
@@ -0,0 +1,16 @@
1
+ import { CallDataInterface } from '@/contracts'
2
+ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
3
+ import { Hex } from 'viem'
4
+
5
+ @Schema({ timestamps: true })
6
+ export class TargetCallDataModel implements CallDataInterface {
7
+ @Prop({ required: true, type: String })
8
+ target: Hex
9
+ @Prop({ required: true, type: String })
10
+ data: Hex
11
+ @Prop({ required: true, type: BigInt })
12
+ value: bigint
13
+ }
14
+
15
+ export const TargetCallDataSchema = SchemaFactory.createForClass(TargetCallDataModel)
16
+ TargetCallDataSchema.index({ target: 1 }, { unique: false })
@@ -0,0 +1,114 @@
1
+ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
2
+ import { EcoError } from '@/common/errors/eco-error'
3
+ import { getAddress, Hex, Mutable } from 'viem'
4
+ import { IntentCreatedEventLog, CallDataInterface, RewardTokensInterface } from '@/contracts'
5
+ import { RouteDataModel, RouteDataSchema } from '@/intent/schemas/route-data.schema'
6
+ import { RewardDataModel, RewardDataModelSchema } from '@/intent/schemas/reward-data.schema'
7
+ import { encodeIntent, hashIntent, IntentType } from '@eco-foundation/routes-ts'
8
+
9
+ @Schema({ timestamps: true })
10
+ export class IntentDataModel implements IntentType {
11
+ @Prop({ required: true, type: String })
12
+ hash: Hex
13
+ @Prop({ required: true, type: RouteDataSchema })
14
+ route: RouteDataModel
15
+ @Prop({ required: true, type: RewardDataModelSchema })
16
+ reward: RewardDataModel
17
+ //log
18
+ @Prop({ required: true })
19
+ logIndex: number
20
+
21
+ constructor(
22
+ hash: Hex,
23
+ salt: Hex,
24
+ source: bigint,
25
+ destination: bigint,
26
+ inbox: Hex,
27
+ routeTokens: RewardTokensInterface[],
28
+ calls: CallDataInterface[],
29
+ creator: Hex,
30
+ prover: Hex,
31
+ deadline: bigint,
32
+ nativeValue: bigint,
33
+ rewardTokens: RewardTokensInterface[],
34
+ logIndex: number,
35
+ ) {
36
+ if (calls.length == 0 || rewardTokens.length == 0 || routeTokens.length == 0) {
37
+ throw EcoError.IntentSourceDataInvalidParams
38
+ }
39
+ this.hash = hash
40
+
41
+ this.route = new RouteDataModel(
42
+ salt,
43
+ source,
44
+ destination,
45
+ getAddress(inbox),
46
+ routeTokens.map((token) => {
47
+ token.token = getAddress(token.token)
48
+ return token
49
+ }),
50
+ calls.map((call) => {
51
+ call.target = getAddress(call.target)
52
+ return call
53
+ }),
54
+ )
55
+
56
+ this.reward = new RewardDataModel(
57
+ getAddress(creator),
58
+ getAddress(prover),
59
+ deadline,
60
+ nativeValue,
61
+ rewardTokens.map((token) => {
62
+ token.token = getAddress(token.token)
63
+ return token
64
+ }),
65
+ )
66
+
67
+ this.logIndex = logIndex
68
+ }
69
+
70
+ static fromEvent(event: IntentCreatedEventLog, logIndex: number): IntentDataModel {
71
+ const e = event.args
72
+ return new IntentDataModel(
73
+ e.hash,
74
+ e.salt,
75
+ e.source,
76
+ e.destination,
77
+ e.inbox,
78
+ e.routeTokens as Mutable<typeof e.routeTokens>,
79
+ e.calls as Mutable<typeof e.calls>,
80
+ e.creator,
81
+ e.prover,
82
+ e.deadline,
83
+ e.nativeValue,
84
+ e.rewardTokens as Mutable<typeof e.rewardTokens>,
85
+ logIndex,
86
+ )
87
+ }
88
+
89
+ static toChainIntent(intent: IntentDataModel): IntentType {
90
+ return {
91
+ route: intent.route,
92
+ reward: intent.reward,
93
+ }
94
+ }
95
+ }
96
+
97
+ export const IntentSourceDataSchema = SchemaFactory.createForClass(IntentDataModel)
98
+ IntentSourceDataSchema.index({ hash: 1 }, { unique: true })
99
+ IntentSourceDataSchema.index(
100
+ { source: 1, destination: 'ascending', deadline: 'ascending' },
101
+ { unique: false },
102
+ )
103
+
104
+ IntentSourceDataSchema.methods.getHash = function (): {
105
+ routeHash: Hex
106
+ rewardHash: Hex
107
+ intentHash: Hex
108
+ } {
109
+ return hashIntent(this)
110
+ }
111
+
112
+ IntentSourceDataSchema.methods.getEncoding = function (): Hex {
113
+ return encodeIntent(this)
114
+ }
@@ -0,0 +1,33 @@
1
+ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
2
+ import { WatchEventModel, WatchEventSchema } from './watch-event.schema'
3
+ import { IntentDataModel, IntentSourceDataSchema } from './intent-data.schema'
4
+ import { GetTransactionReceiptReturnType } from 'viem'
5
+
6
+ export type IntentSourceStatus =
7
+ | 'PENDING'
8
+ | 'SOLVED'
9
+ | 'EXPIRED'
10
+ | 'FAILED'
11
+ | 'INVALID'
12
+ | 'INFEASABLE'
13
+ | 'NON-BEND-WALLET'
14
+
15
+ @Schema({ timestamps: true })
16
+ export class IntentSourceModel {
17
+ @Prop({ required: true, type: WatchEventSchema })
18
+ event: WatchEventModel
19
+
20
+ @Prop({ required: true, type: IntentSourceDataSchema })
21
+ intent: IntentDataModel
22
+
23
+ @Prop({ type: Object })
24
+ receipt: GetTransactionReceiptReturnType
25
+
26
+ @Prop({ required: true, type: String })
27
+ status: IntentSourceStatus
28
+ }
29
+
30
+ export const IntentSourceSchema = SchemaFactory.createForClass(IntentSourceModel)
31
+
32
+ // Set collation options for case-insensitive search.
33
+ IntentSourceSchema.index({ status: 1 }, { unique: false })
@@ -0,0 +1,14 @@
1
+ import { RewardTokensInterface } from '@/contracts'
2
+ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
3
+ import { Hex } from 'viem'
4
+
5
+ @Schema({ timestamps: true })
6
+ export class TokenAmountDataModel implements RewardTokensInterface {
7
+ @Prop({ required: true, type: String })
8
+ token: Hex
9
+ @Prop({ required: true, type: BigInt })
10
+ amount: bigint
11
+ }
12
+
13
+ export const TokenAmountDataSchema = SchemaFactory.createForClass(TokenAmountDataModel)
14
+ TokenAmountDataSchema.index({ token: 1 }, { unique: false })
@@ -0,0 +1,48 @@
1
+ import {
2
+ TokenAmountDataModel,
3
+ TokenAmountDataSchema,
4
+ } from '@/intent/schemas/intent-token-amount.schema'
5
+ import { encodeReward, hashReward, RewardType } from '@eco-foundation/routes-ts'
6
+ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
7
+ import { Hex } from 'viem'
8
+
9
+ @Schema({ timestamps: true })
10
+ export class RewardDataModel implements RewardType {
11
+ @Prop({ required: true, type: String })
12
+ creator: Hex
13
+ @Prop({ required: true, type: String })
14
+ prover: Hex
15
+ @Prop({ required: true, type: BigInt })
16
+ deadline: bigint
17
+ @Prop({ required: true, type: BigInt })
18
+ nativeValue: bigint
19
+ @Prop({ required: true, type: [TokenAmountDataSchema] })
20
+ tokens: TokenAmountDataModel[]
21
+
22
+ constructor(
23
+ creator: Hex,
24
+ prover: Hex,
25
+ deadline: bigint,
26
+ nativeValue: bigint,
27
+ tokens: TokenAmountDataModel[],
28
+ ) {
29
+ this.creator = creator
30
+ this.prover = prover
31
+ this.deadline = deadline
32
+ this.nativeValue = nativeValue
33
+ this.tokens = tokens
34
+ }
35
+ }
36
+
37
+ export const RewardDataModelSchema = SchemaFactory.createForClass(RewardDataModel)
38
+ RewardDataModelSchema.index({ creator: 1 }, { unique: false })
39
+ RewardDataModelSchema.index({ prover: 1 }, { unique: false })
40
+ RewardDataModelSchema.index({ tokens: 1 }, { unique: false })
41
+
42
+ RewardDataModelSchema.methods.getHash = function (): Hex {
43
+ return hashReward(this)
44
+ }
45
+
46
+ RewardDataModelSchema.methods.getEncoding = function (): Hex {
47
+ return encodeReward(this)
48
+ }
@@ -0,0 +1,52 @@
1
+ import { TargetCallDataModel, TargetCallDataSchema } from '@/intent/schemas/intent-call-data.schema'
2
+ import {
3
+ TokenAmountDataModel,
4
+ TokenAmountDataSchema,
5
+ } from '@/intent/schemas/intent-token-amount.schema'
6
+ import { encodeRoute, hashRoute, RouteType } from '@eco-foundation/routes-ts'
7
+ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
8
+ import { Hex } from 'viem'
9
+
10
+ @Schema({ timestamps: true })
11
+ export class RouteDataModel implements RouteType {
12
+ @Prop({ required: true, type: String })
13
+ salt: Hex
14
+ @Prop({ required: true, type: BigInt })
15
+ source: bigint
16
+ @Prop({ required: true, type: BigInt })
17
+ destination: bigint
18
+ @Prop({ required: true, type: String })
19
+ inbox: Hex
20
+ @Prop({ required: true, type: [TokenAmountDataSchema] })
21
+ tokens: TokenAmountDataModel[]
22
+ @Prop({ required: true, type: [TargetCallDataSchema] })
23
+ calls: TargetCallDataModel[]
24
+
25
+ constructor(
26
+ salt: Hex,
27
+ source: bigint,
28
+ destination: bigint,
29
+ inbox: Hex,
30
+ routeTokens: TokenAmountDataModel[],
31
+ calls: TargetCallDataModel[],
32
+ ) {
33
+ this.salt = salt
34
+ this.source = source
35
+ this.destination = destination
36
+ this.tokens = routeTokens
37
+ this.inbox = inbox
38
+ this.calls = calls
39
+ }
40
+ }
41
+
42
+ export const RouteDataSchema = SchemaFactory.createForClass(RouteDataModel)
43
+ RouteDataSchema.index({ source: 1 }, { unique: false })
44
+ RouteDataSchema.index({ destination: 1 }, { unique: false })
45
+
46
+ RouteDataSchema.methods.getHash = function (): Hex {
47
+ return hashRoute(this)
48
+ }
49
+
50
+ RouteDataSchema.methods.getEncoding = function (): Hex {
51
+ return encodeRoute(this)
52
+ }
@@ -0,0 +1,32 @@
1
+ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
2
+ import { Network } from 'alchemy-sdk'
3
+ import { ViemEventLog } from '../../common/events/viem'
4
+ import { Hex } from 'viem'
5
+
6
+ @Schema()
7
+ export class WatchEventModel implements ViemEventLog {
8
+ @Prop({ required: true, type: BigInt })
9
+ sourceChainID: bigint
10
+ @Prop({ required: true, type: String })
11
+ sourceNetwork: Network
12
+ @Prop({ required: true, type: BigInt })
13
+ blockNumber: bigint
14
+ @Prop({ required: true, type: String })
15
+ blockHash: Hex
16
+ @Prop({ required: true })
17
+ transactionIndex: number
18
+ @Prop({ required: true })
19
+ removed: boolean
20
+ @Prop({ required: true, type: String })
21
+ address: Hex
22
+ @Prop({ required: true, type: String })
23
+ data: Hex
24
+ @Prop({ required: true })
25
+ topics: [] | [Hex, ...Hex[]]
26
+ @Prop({ required: true, type: String })
27
+ transactionHash: Hex
28
+ @Prop({ required: true })
29
+ logIndex: number
30
+ }
31
+ export const WatchEventSchema = SchemaFactory.createForClass(WatchEventModel)
32
+ WatchEventSchema.index({ transactionHash: 1 }, { unique: true })