@instadapp/interop-x 0.0.0-dev.99c6cb0 → 0.0.0-dev.9d8d8b4

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 (306) hide show
  1. package/.github/workflows/ci.yml +19 -0
  2. package/dist/package.json +12 -3
  3. package/dist/src/abi/aaveV2Resolver.json +832 -0
  4. package/dist/src/abi/aaveV3Resolver.json +628 -0
  5. package/dist/src/abi/balanceResolver.json +211 -0
  6. package/dist/src/abi/connectors/index.js +36 -0
  7. package/dist/src/abi/connectors/v1/aave.js +148 -0
  8. package/dist/src/abi/connectors/v1/aave_claim.js +4 -0
  9. package/dist/src/abi/connectors/v1/aave_migrate.js +109 -0
  10. package/dist/src/abi/connectors/v1/aave_polygon_migrate.js +110 -0
  11. package/dist/src/abi/connectors/v1/aave_stake.js +4 -0
  12. package/dist/src/abi/connectors/v1/aave_v1_import.js +54 -0
  13. package/dist/src/abi/connectors/v1/aave_v2.js +230 -0
  14. package/dist/src/abi/connectors/v1/aave_v2_import.js +59 -0
  15. package/dist/src/abi/connectors/v1/authority.js +100 -0
  16. package/dist/src/abi/connectors/v1/basic.js +136 -0
  17. package/dist/src/abi/connectors/v1/chi.js +36 -0
  18. package/dist/src/abi/connectors/v1/comp.js +4 -0
  19. package/dist/src/abi/connectors/v1/compound.js +4 -0
  20. package/dist/src/abi/connectors/v1/compoundImport.js +69 -0
  21. package/dist/src/abi/connectors/v1/compoundImport_v2.js +4 -0
  22. package/dist/src/abi/connectors/v1/compound_old.js +448 -0
  23. package/dist/src/abi/connectors/v1/curve.js +140 -0
  24. package/dist/src/abi/connectors/v1/curve_claim.js +63 -0
  25. package/dist/src/abi/connectors/v1/curve_gauge.js +158 -0
  26. package/dist/src/abi/connectors/v1/curve_sbtc.js +140 -0
  27. package/dist/src/abi/connectors/v1/curve_susd.js +140 -0
  28. package/dist/src/abi/connectors/v1/curve_three.js +79 -0
  29. package/dist/src/abi/connectors/v1/curve_y.js +140 -0
  30. package/dist/src/abi/connectors/v1/dsa_migrate_v1_to_v2.js +4 -0
  31. package/dist/src/abi/connectors/v1/dydx.js +148 -0
  32. package/dist/src/abi/connectors/v1/dydx_flash.js +52 -0
  33. package/dist/src/abi/connectors/v1/fee.js +50 -0
  34. package/dist/src/abi/connectors/v1/gelato.js +1138 -0
  35. package/dist/src/abi/connectors/v1/index.js +58 -0
  36. package/dist/src/abi/connectors/v1/instapool.js +439 -0
  37. package/dist/src/abi/connectors/v1/instapool_v2.js +126 -0
  38. package/dist/src/abi/connectors/v1/kyber.js +117 -0
  39. package/dist/src/abi/connectors/v1/maker.js +480 -0
  40. package/dist/src/abi/connectors/v1/maker_old.js +300 -0
  41. package/dist/src/abi/connectors/v1/math.js +43 -0
  42. package/dist/src/abi/connectors/v1/migrate.js +46 -0
  43. package/dist/src/abi/connectors/v1/oasis.js +198 -0
  44. package/dist/src/abi/connectors/v1/oneInch.js +160 -0
  45. package/dist/src/abi/connectors/v1/polygon_bridge.js +4 -0
  46. package/dist/src/abi/connectors/v1/refinance.js +4 -0
  47. package/dist/src/abi/connectors/v1/staking.js +220 -0
  48. package/dist/src/abi/connectors/v1/swerve.js +179 -0
  49. package/dist/src/abi/connectors/v1/uniswap.js +297 -0
  50. package/dist/src/abi/connectors/v2/1INCH-A.js +4 -0
  51. package/dist/src/abi/connectors/v2/1INCH-B.js +4 -0
  52. package/dist/src/abi/connectors/v2/AAVE-CLAIM-A.js +4 -0
  53. package/dist/src/abi/connectors/v2/AAVE-CLAIM-B.js +166 -0
  54. package/dist/src/abi/connectors/v2/AAVE-STAKE-A.js +4 -0
  55. package/dist/src/abi/connectors/v2/AAVE-V1-A.js +130 -0
  56. package/dist/src/abi/connectors/v2/AAVE-V1-IMPORT-A.js +4 -0
  57. package/dist/src/abi/connectors/v2/AAVE-V2-A.js +230 -0
  58. package/dist/src/abi/connectors/v2/AAVE-V2-IMPORT-A.js +4 -0
  59. package/dist/src/abi/connectors/v2/AAVE-V2-IMPORT-B.js +225 -0
  60. package/dist/src/abi/connectors/v2/AUTHORITY-A.js +100 -0
  61. package/dist/src/abi/connectors/v2/B-COMPOUND-A.js +4 -0
  62. package/dist/src/abi/connectors/v2/B-LIQUITY-A.js +4 -0
  63. package/dist/src/abi/connectors/v2/B-MAKERDAO-A.js +4 -0
  64. package/dist/src/abi/connectors/v2/BASIC-A.js +136 -0
  65. package/dist/src/abi/connectors/v2/BASIC-B.js +4 -0
  66. package/dist/src/abi/connectors/v2/BASIC-C.js +4 -0
  67. package/dist/src/abi/connectors/v2/COMP-A.js +4 -0
  68. package/dist/src/abi/connectors/v2/COMPOUND-A.js +4 -0
  69. package/dist/src/abi/connectors/v2/COMPOUND-IMPORT-A.js +4 -0
  70. package/dist/src/abi/connectors/v2/COMPOUND-IMPORT-B.js +195 -0
  71. package/dist/src/abi/connectors/v2/G-UNISWAP-A.js +4 -0
  72. package/dist/src/abi/connectors/v2/GELATO-AAVE-A.js +4 -0
  73. package/dist/src/abi/connectors/v2/INST-A.js +4 -0
  74. package/dist/src/abi/connectors/v2/INST-LM-A.js +4 -0
  75. package/dist/src/abi/connectors/v2/INST-STAKING-A.js +4 -0
  76. package/dist/src/abi/connectors/v2/INST-STAKING-B.js +4 -0
  77. package/dist/src/abi/connectors/v2/INSTAPOOL-A.js +4 -0
  78. package/dist/src/abi/connectors/v2/LIQUITY-A.js +4 -0
  79. package/dist/src/abi/connectors/v2/MAKERDAO-A.js +4 -0
  80. package/dist/src/abi/connectors/v2/MAKERDAO-CLAIM-A.js +136 -0
  81. package/dist/src/abi/connectors/v2/PARASWAP-A.js +4 -0
  82. package/dist/src/abi/connectors/v2/POLYGON-BRIDGE-A.js +4 -0
  83. package/dist/src/abi/connectors/v2/REFINANCE-A.js +4 -0
  84. package/dist/src/abi/connectors/v2/REFLEXER-A.js +4 -0
  85. package/dist/src/abi/connectors/v2/STAKE-ERC20-A.js +4 -0
  86. package/dist/src/abi/connectors/v2/UNISWAP-A.js +297 -0
  87. package/dist/src/abi/connectors/v2/UNISWAP-V2-A.js +4 -0
  88. package/dist/src/abi/connectors/v2/UNISWAP-V3-A.js +4 -0
  89. package/dist/src/abi/connectors/v2/UNISWAP-V3-STAKE-A.js +4 -0
  90. package/dist/src/abi/connectors/v2/WETH-A.js +4 -0
  91. package/dist/src/abi/connectors/v2/YEARN-VAULT-A.js +4 -0
  92. package/dist/src/abi/connectors/v2/index.js +89 -0
  93. package/dist/src/abi/index.js +12 -2
  94. package/dist/src/abi/instList.json +232 -0
  95. package/dist/src/abi/interopX.json +1436 -0
  96. package/dist/src/api/index.js +8 -1
  97. package/dist/src/constants/addresses.js +12 -7
  98. package/dist/src/constants/blockConfirmations.js +8 -0
  99. package/dist/src/constants/capPerChain.js +8 -0
  100. package/dist/src/constants/index.js +3 -0
  101. package/dist/src/constants/tokens.js +0 -7
  102. package/dist/src/constants/wrappedNativeToken.js +8 -0
  103. package/dist/src/crons/index.js +3 -0
  104. package/dist/src/crons/prices.js +16 -0
  105. package/dist/src/db/models/transaction.js +25 -15
  106. package/dist/src/errors/index.js +30 -0
  107. package/dist/src/gnosis/actions/aaveV2/index.js +11 -0
  108. package/dist/src/gnosis/actions/aaveV2/source.js +98 -0
  109. package/dist/src/gnosis/actions/aaveV2/target.js +100 -0
  110. package/dist/src/gnosis/actions/aaveV3/index.js +11 -0
  111. package/dist/src/gnosis/actions/aaveV3/source.js +74 -0
  112. package/dist/src/gnosis/actions/aaveV3/target.js +87 -0
  113. package/dist/src/gnosis/actions/index.js +4 -2
  114. package/dist/src/index.js +2 -1
  115. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +2 -2
  116. package/dist/src/providers/index.js +17 -0
  117. package/dist/src/providers/retry-provider.js +45 -0
  118. package/dist/src/services/Prices.js +74 -0
  119. package/dist/src/services/index.js +8 -0
  120. package/dist/src/tasks/InteropX/ProcessSubmitEvents.js +274 -0
  121. package/dist/src/tasks/InteropX/ProcessValidateEvents.js +203 -0
  122. package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +113 -0
  123. package/dist/src/tasks/{InteropXContract/SyncBridgeRequestEvents.js → InteropX/SyncLogSubmitEvents.js} +26 -16
  124. package/dist/src/tasks/{InteropXContract/SyncBridgeRequestSentEvents.js → InteropX/SyncLogValidateEvents.js} +42 -26
  125. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +6 -3
  126. package/dist/src/tasks/index.js +19 -12
  127. package/dist/src/typechain/{InteropXContract.js → AaveV2Resolver.js} +0 -0
  128. package/dist/src/typechain/AaveV3Resolver.js +2 -0
  129. package/dist/src/typechain/BalanceResolver.js +2 -0
  130. package/dist/src/typechain/InstList.js +2 -0
  131. package/dist/src/typechain/InteropX.js +2 -0
  132. package/dist/src/typechain/factories/AaveV2Resolver__factory.js +1191 -0
  133. package/dist/src/typechain/factories/AaveV3Resolver__factory.js +887 -0
  134. package/dist/src/typechain/factories/BalanceResolver__factory.js +228 -0
  135. package/dist/src/typechain/factories/InstList__factory.js +249 -0
  136. package/dist/src/typechain/factories/InteropX__factory.js +1928 -0
  137. package/dist/src/typechain/factories/index.js +11 -3
  138. package/dist/src/typechain/index.js +11 -3
  139. package/dist/src/utils/async.js +18 -0
  140. package/dist/src/utils/dsa.js +36 -0
  141. package/dist/src/utils/formatting.js +67 -0
  142. package/dist/src/utils/gnosis.js +87 -0
  143. package/dist/src/utils/http.js +10 -0
  144. package/dist/src/utils/index.js +22 -183
  145. package/dist/src/utils/interop.js +16 -0
  146. package/dist/src/utils/tokens.js +22 -0
  147. package/dist/src/utils/validate.js +111 -0
  148. package/dist/src/utils/web3.js +93 -0
  149. package/package.json +12 -3
  150. package/src/abi/aaveV2Resolver.json +832 -0
  151. package/src/abi/aaveV3Resolver.json +628 -0
  152. package/src/abi/balanceResolver.json +211 -0
  153. package/src/abi/connectors/index.ts +14 -0
  154. package/src/abi/connectors/v1/aave.ts +147 -0
  155. package/src/abi/connectors/v1/aave_claim.ts +3 -0
  156. package/src/abi/connectors/v1/aave_migrate.ts +108 -0
  157. package/src/abi/connectors/v1/aave_polygon_migrate.ts +109 -0
  158. package/src/abi/connectors/v1/aave_stake.ts +3 -0
  159. package/src/abi/connectors/v1/aave_v1_import.ts +53 -0
  160. package/src/abi/connectors/v1/aave_v2.ts +229 -0
  161. package/src/abi/connectors/v1/aave_v2_import.ts +58 -0
  162. package/src/abi/connectors/v1/authority.ts +99 -0
  163. package/src/abi/connectors/v1/basic.ts +135 -0
  164. package/src/abi/connectors/v1/chi.ts +35 -0
  165. package/src/abi/connectors/v1/comp.ts +3 -0
  166. package/src/abi/connectors/v1/compound.ts +3 -0
  167. package/src/abi/connectors/v1/compoundImport.ts +68 -0
  168. package/src/abi/connectors/v1/compoundImport_v2.ts +3 -0
  169. package/src/abi/connectors/v1/compound_old.ts +447 -0
  170. package/src/abi/connectors/v1/curve.ts +139 -0
  171. package/src/abi/connectors/v1/curve_claim.ts +62 -0
  172. package/src/abi/connectors/v1/curve_gauge.ts +157 -0
  173. package/src/abi/connectors/v1/curve_sbtc.ts +139 -0
  174. package/src/abi/connectors/v1/curve_susd.ts +139 -0
  175. package/src/abi/connectors/v1/curve_three.ts +78 -0
  176. package/src/abi/connectors/v1/curve_y.ts +139 -0
  177. package/src/abi/connectors/v1/dsa_migrate_v1_to_v2.ts +3 -0
  178. package/src/abi/connectors/v1/dydx.ts +147 -0
  179. package/src/abi/connectors/v1/dydx_flash.ts +51 -0
  180. package/src/abi/connectors/v1/fee.ts +49 -0
  181. package/src/abi/connectors/v1/gelato.ts +1137 -0
  182. package/src/abi/connectors/v1/index.ts +42 -0
  183. package/src/abi/connectors/v1/instapool.ts +438 -0
  184. package/src/abi/connectors/v1/instapool_v2.ts +125 -0
  185. package/src/abi/connectors/v1/kyber.ts +116 -0
  186. package/src/abi/connectors/v1/maker.ts +479 -0
  187. package/src/abi/connectors/v1/maker_old.ts +299 -0
  188. package/src/abi/connectors/v1/math.ts +42 -0
  189. package/src/abi/connectors/v1/migrate.ts +45 -0
  190. package/src/abi/connectors/v1/oasis.ts +197 -0
  191. package/src/abi/connectors/v1/oneInch.ts +159 -0
  192. package/src/abi/connectors/v1/polygon_bridge.ts +3 -0
  193. package/src/abi/connectors/v1/refinance.ts +3 -0
  194. package/src/abi/connectors/v1/staking.ts +219 -0
  195. package/src/abi/connectors/v1/swerve.ts +178 -0
  196. package/src/abi/connectors/v1/uniswap.ts +297 -0
  197. package/src/abi/connectors/v2/1INCH-A.ts +3 -0
  198. package/src/abi/connectors/v2/1INCH-B.ts +3 -0
  199. package/src/abi/connectors/v2/AAVE-CLAIM-A.ts +3 -0
  200. package/src/abi/connectors/v2/AAVE-CLAIM-B.ts +165 -0
  201. package/src/abi/connectors/v2/AAVE-STAKE-A.ts +3 -0
  202. package/src/abi/connectors/v2/AAVE-V1-A.ts +130 -0
  203. package/src/abi/connectors/v2/AAVE-V1-IMPORT-A.ts +3 -0
  204. package/src/abi/connectors/v2/AAVE-V2-A.ts +229 -0
  205. package/src/abi/connectors/v2/AAVE-V2-IMPORT-A.ts +3 -0
  206. package/src/abi/connectors/v2/AAVE-V2-IMPORT-B.ts +224 -0
  207. package/src/abi/connectors/v2/AUTHORITY-A.ts +99 -0
  208. package/src/abi/connectors/v2/B-COMPOUND-A.ts +3 -0
  209. package/src/abi/connectors/v2/B-LIQUITY-A.ts +3 -0
  210. package/src/abi/connectors/v2/B-MAKERDAO-A.ts +3 -0
  211. package/src/abi/connectors/v2/BASIC-A.ts +135 -0
  212. package/src/abi/connectors/v2/BASIC-B.ts +3 -0
  213. package/src/abi/connectors/v2/BASIC-C.ts +3 -0
  214. package/src/abi/connectors/v2/COMP-A.ts +3 -0
  215. package/src/abi/connectors/v2/COMPOUND-A.ts +3 -0
  216. package/src/abi/connectors/v2/COMPOUND-IMPORT-A.ts +3 -0
  217. package/src/abi/connectors/v2/COMPOUND-IMPORT-B.ts +194 -0
  218. package/src/abi/connectors/v2/G-UNISWAP-A.ts +3 -0
  219. package/src/abi/connectors/v2/GELATO-AAVE-A.ts +3 -0
  220. package/src/abi/connectors/v2/INST-A.ts +3 -0
  221. package/src/abi/connectors/v2/INST-LM-A.ts +3 -0
  222. package/src/abi/connectors/v2/INST-STAKING-A.ts +3 -0
  223. package/src/abi/connectors/v2/INST-STAKING-B.ts +3 -0
  224. package/src/abi/connectors/v2/INSTAPOOL-A.ts +3 -0
  225. package/src/abi/connectors/v2/LIQUITY-A.ts +3 -0
  226. package/src/abi/connectors/v2/MAKERDAO-A.ts +3 -0
  227. package/src/abi/connectors/v2/MAKERDAO-CLAIM-A.ts +135 -0
  228. package/src/abi/connectors/v2/PARASWAP-A.ts +3 -0
  229. package/src/abi/connectors/v2/POLYGON-BRIDGE-A.ts +3 -0
  230. package/src/abi/connectors/v2/REFINANCE-A.ts +3 -0
  231. package/src/abi/connectors/v2/REFLEXER-A.ts +3 -0
  232. package/src/abi/connectors/v2/STAKE-ERC20-A.ts +3 -0
  233. package/src/abi/connectors/v2/UNISWAP-A.ts +297 -0
  234. package/src/abi/connectors/v2/UNISWAP-V2-A.ts +3 -0
  235. package/src/abi/connectors/v2/UNISWAP-V3-A.ts +3 -0
  236. package/src/abi/connectors/v2/UNISWAP-V3-STAKE-A.ts +3 -0
  237. package/src/abi/connectors/v2/WETH-A.ts +3 -0
  238. package/src/abi/connectors/v2/YEARN-VAULT-A.ts +3 -0
  239. package/src/abi/connectors/v2/index.ts +87 -0
  240. package/src/abi/index.ts +15 -5
  241. package/src/abi/instList.json +232 -0
  242. package/src/abi/interopX.json +1436 -0
  243. package/src/api/index.ts +9 -1
  244. package/src/constants/addresses.ts +24 -8
  245. package/src/constants/blockConfirmations.ts +5 -0
  246. package/src/constants/capPerChain.ts +5 -0
  247. package/src/constants/index.ts +3 -0
  248. package/src/constants/tokens.ts +0 -7
  249. package/src/constants/wrappedNativeToken.ts +5 -0
  250. package/src/crons/index.ts +1 -0
  251. package/src/crons/prices.ts +12 -0
  252. package/src/db/models/transaction.ts +147 -94
  253. package/src/errors/index.ts +26 -0
  254. package/src/gnosis/actions/aaveV2/index.ts +9 -0
  255. package/src/gnosis/actions/aaveV2/source.ts +171 -0
  256. package/src/gnosis/actions/aaveV2/target.ts +160 -0
  257. package/src/gnosis/actions/aaveV3/index.ts +9 -0
  258. package/src/gnosis/actions/aaveV3/source.ts +119 -0
  259. package/src/gnosis/actions/aaveV3/target.ts +142 -0
  260. package/src/gnosis/actions/index.ts +4 -2
  261. package/src/index.ts +1 -0
  262. package/src/net/protocol/dial/SignatureDialProtocol.ts +3 -2
  263. package/src/providers/index.ts +1 -0
  264. package/src/providers/retry-provider.ts +51 -0
  265. package/src/services/Prices.ts +89 -0
  266. package/src/services/index.ts +1 -0
  267. package/src/tasks/InteropX/ProcessSubmitEvents.ts +386 -0
  268. package/src/tasks/InteropX/ProcessValidateEvents.ts +297 -0
  269. package/src/tasks/InteropX/SyncLogExecuteEvents.ts +161 -0
  270. package/src/tasks/InteropX/SyncLogSubmitEvents.ts +138 -0
  271. package/src/tasks/InteropX/SyncLogValidateEvents.ts +151 -0
  272. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +6 -3
  273. package/src/tasks/index.ts +20 -12
  274. package/src/typechain/AaveV2Resolver.ts +1017 -0
  275. package/src/typechain/AaveV3Resolver.ts +935 -0
  276. package/src/typechain/BalanceResolver.ts +266 -0
  277. package/src/typechain/InstList.ts +402 -0
  278. package/src/typechain/InteropX.ts +1216 -0
  279. package/src/typechain/factories/AaveV2Resolver__factory.ts +1198 -0
  280. package/src/typechain/factories/AaveV3Resolver__factory.ts +894 -0
  281. package/src/typechain/factories/BalanceResolver__factory.ts +235 -0
  282. package/src/typechain/factories/InstList__factory.ts +253 -0
  283. package/src/typechain/factories/InteropX__factory.ts +1932 -0
  284. package/src/typechain/factories/index.ts +5 -1
  285. package/src/typechain/index.ts +10 -2
  286. package/src/utils/async.ts +22 -0
  287. package/src/utils/dsa.ts +56 -0
  288. package/src/utils/formatting.ts +68 -0
  289. package/src/utils/gnosis.ts +166 -0
  290. package/src/utils/http.ts +6 -0
  291. package/src/utils/index.ts +9 -268
  292. package/src/utils/interop.ts +28 -0
  293. package/src/utils/tokens.ts +21 -0
  294. package/src/utils/validate.ts +179 -0
  295. package/src/utils/web3.ts +132 -0
  296. package/dist/src/abi/interopXContract.json +0 -454
  297. package/dist/src/gnosis/actions/withdraw/index.js +0 -55
  298. package/dist/src/tasks/InteropXContract/ProcessBridgeRequestEvents.js +0 -152
  299. package/dist/src/typechain/factories/InteropXContract__factory.js +0 -635
  300. package/src/abi/interopXContract.json +0 -454
  301. package/src/gnosis/actions/withdraw/index.ts +0 -77
  302. package/src/tasks/InteropXContract/ProcessBridgeRequestEvents.ts +0 -216
  303. package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +0 -115
  304. package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +0 -121
  305. package/src/typechain/InteropXContract.ts +0 -680
  306. package/src/typechain/factories/InteropXContract__factory.ts +0 -642
@@ -40,9 +40,9 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
40
40
  }
41
41
  const { data: gnosisData } = await (0, gnosis_1.buildGnosisAction)(transaction, data.type);
42
42
  const signedData = await (0, utils_1.signGnosisSafeTx)({
43
- to: constants_1.addresses[transaction.sourceChainId].multisend,
43
+ to: constants_1.addresses[data.chainId].multisend,
44
44
  data: gnosisData,
45
- chainId: transaction.sourceChainId,
45
+ chainId: data.chainId,
46
46
  safeTxGas: data.safeTxGas,
47
47
  nonce: data.safeNonce,
48
48
  }, { signer });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./retry-provider"), exports);
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.JsonRpcRetryProvider = exports.retryOperation = exports.promiseTimeout = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const waait_1 = __importDefault(require("waait"));
9
+ const bluebird_1 = __importDefault(require("bluebird"));
10
+ function promiseTimeout(ms, promise) {
11
+ return bluebird_1.default.resolve(promise).timeout(ms);
12
+ }
13
+ exports.promiseTimeout = promiseTimeout;
14
+ function retryOperation(retriesLeft, operation, options) {
15
+ return new Promise((resolve, reject) => {
16
+ const { timeouts } = options;
17
+ // Find the timeout for this specific iteration
18
+ const timeout = timeouts[timeouts.length - retriesLeft];
19
+ // Wrap the original operation in a timeout
20
+ const execution = promiseTimeout(timeout, operation());
21
+ // If the promise is successful, resolve it and bubble the result up
22
+ return execution.then(resolve).catch((reason) => {
23
+ // If there are any retries left, we call the same retryOperation function again,
24
+ // but decrementing the number of retries left by 1
25
+ if (retriesLeft - 1 > 0) {
26
+ // Delay the new attempt slightly
27
+ return (0, waait_1.default)(options.delay || 50)
28
+ .then(retryOperation.bind(null, retriesLeft - 1, operation, options))
29
+ .then(resolve)
30
+ .catch(reject);
31
+ }
32
+ // Reject (and bubble the result up) if there are no more retries
33
+ return reject(reason);
34
+ });
35
+ });
36
+ }
37
+ exports.retryOperation = retryOperation;
38
+ class JsonRpcRetryProvider extends ethers_1.ethers.providers.JsonRpcProvider {
39
+ perform(method, params) {
40
+ const timeouts = [5000, 10000];
41
+ const operation = () => super.perform(method, params);
42
+ return retryOperation(2, operation, { timeouts, delay: 50 });
43
+ }
44
+ }
45
+ exports.JsonRpcRetryProvider = JsonRpcRetryProvider;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const web3_utils_1 = __importDefault(require("web3-utils"));
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const constants_1 = require("@/constants");
10
+ const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
11
+ const config_1 = __importDefault(require("@/config"));
12
+ const utils_1 = require("@/utils");
13
+ const basePath = (0, expand_home_dir_1.default)(`~/.interop-x/data/${config_1.default.publicAddress}/${config_1.default.staging ? 'staging' : ''}`);
14
+ const mainnetPricesFilePath = path_1.default.resolve(basePath, "./mainnetPrices.json");
15
+ const networkTokenPricesFilePath = path_1.default.resolve(basePath, "./networkTokenPrices.json");
16
+ class Prices {
17
+ static async fetch() {
18
+ if (!fs_1.default.existsSync(mainnetPricesFilePath)) {
19
+ fs_1.default.writeFileSync(mainnetPricesFilePath, JSON.stringify({}));
20
+ }
21
+ if (!fs_1.default.existsSync(networkTokenPricesFilePath)) {
22
+ fs_1.default.writeFileSync(networkTokenPricesFilePath, JSON.stringify({}));
23
+ }
24
+ this.mainnetPrices = JSON.parse(fs_1.default.readFileSync(mainnetPricesFilePath, "utf8"));
25
+ this.networkTokenPrices = JSON.parse(fs_1.default.readFileSync(networkTokenPricesFilePath, "utf8"));
26
+ try {
27
+ const path = constants_1.tokens["1"]
28
+ .filter((a) => a.symbol !== "ETH")
29
+ .map((token) => token.address)
30
+ .join(",");
31
+ const [response, ethResponse, avaxResponse, polygonResponse] = await Promise.all([
32
+ utils_1.http.get("https://api.coingecko.com/api/v3/simple/token_price/ethereum", {
33
+ params: { contract_addresses: path, vs_currencies: "usd" },
34
+ }),
35
+ utils_1.http.get("https://api.coingecko.com/api/v3/simple/price", {
36
+ params: { ids: "ethereum", vs_currencies: "usd" },
37
+ }),
38
+ utils_1.http.get("https://api.coingecko.com/api/v3/simple/price", {
39
+ params: { ids: "avalanche-2", vs_currencies: "usd" },
40
+ }),
41
+ utils_1.http.get("https://api.coingecko.com/api/v3/simple/price", {
42
+ params: { ids: "matic-network", vs_currencies: "usd" },
43
+ }),
44
+ ]);
45
+ this.networkTokenPrices = {
46
+ "1": ethResponse.data.ethereum.usd.toString(),
47
+ "137": polygonResponse.data["matic-network"].usd.toString(),
48
+ "43114": avaxResponse.data["avalanche-2"].usd.toString(),
49
+ };
50
+ const data = response.data;
51
+ for (const key in data) {
52
+ const _key = web3_utils_1.default.toChecksumAddress(key);
53
+ if (!data[key].usd)
54
+ continue;
55
+ this.mainnetPrices[_key] = data[key].usd.toString();
56
+ }
57
+ this.mainnetPrices["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"] =
58
+ ethResponse.data.ethereum.usd.toString();
59
+ }
60
+ catch (error) { }
61
+ fs_1.default.writeFileSync(mainnetPricesFilePath, JSON.stringify(this.mainnetPrices));
62
+ fs_1.default.writeFileSync(networkTokenPricesFilePath, JSON.stringify(this.networkTokenPrices));
63
+ return this.mainnetPrices;
64
+ }
65
+ static getMainnetPrices() {
66
+ return this.mainnetPrices;
67
+ }
68
+ static getNetworkTokenPrices() {
69
+ return this.networkTokenPrices;
70
+ }
71
+ }
72
+ Prices.mainnetPrices = {};
73
+ Prices.networkTokenPrices = {};
74
+ exports.default = Prices;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Prices = void 0;
7
+ var Prices_1 = require("./Prices");
8
+ Object.defineProperty(exports, "Prices", { enumerable: true, get: function () { return __importDefault(Prices_1).default; } });
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const BaseTask_1 = require("../BaseTask");
7
+ const logger_1 = __importDefault(require("@/logger"));
8
+ const ethers_1 = require("ethers");
9
+ const abi_1 = __importDefault(require("@/abi"));
10
+ const db_1 = require("@/db");
11
+ const utils_1 = require("@/utils");
12
+ const constants_1 = require("@/constants");
13
+ const config_1 = __importDefault(require("@/config"));
14
+ const moment_1 = __importDefault(require("moment"));
15
+ const sequelize_1 = require("sequelize");
16
+ const gnosis_1 = require("@/gnosis");
17
+ const net_1 = require("@/net");
18
+ const waait_1 = __importDefault(require("waait"));
19
+ const errors_1 = require("@/errors");
20
+ const bignumber_js_1 = require("bignumber.js");
21
+ const dedent_1 = __importDefault(require("dedent"));
22
+ const providers_1 = require("@/providers");
23
+ class ProcessSubmitEvents extends BaseTask_1.BaseTask {
24
+ constructor({ chainId }) {
25
+ super({
26
+ logger: new logger_1.default("InteropX::ProcessSubmitEvents"),
27
+ });
28
+ this.leadNodeOnly = true;
29
+ this.blockConfirmationsCount = 12;
30
+ this.chainId = chainId;
31
+ }
32
+ async pollHandler() {
33
+ var _a;
34
+ const currentBlockNumber = await this.sourceProvider.getBlockNumber();
35
+ const transaction = await db_1.Transaction.findOne({
36
+ where: {
37
+ status: "pending",
38
+ sourceStatus: "pending",
39
+ sourceChainId: this.chainId,
40
+ submitBlockNumber: {
41
+ [sequelize_1.Op.lt]: currentBlockNumber - this.blockConfirmationsCount,
42
+ },
43
+ sourceDelayUntil: {
44
+ [sequelize_1.Op.or]: {
45
+ [sequelize_1.Op.is]: null,
46
+ [sequelize_1.Op.lt]: new Date(),
47
+ },
48
+ },
49
+ submitEvent: { $ne: null },
50
+ createdAt: {
51
+ [sequelize_1.Op.gt]: (0, moment_1.default)().subtract({ hours: 12 }).toDate(),
52
+ },
53
+ },
54
+ });
55
+ if (!transaction) {
56
+ return;
57
+ }
58
+ this.logger.debug(`Processing transaction ${transaction.transactionHash}`);
59
+ transaction.sourceStatus = "proccessing";
60
+ await transaction.save();
61
+ const { submitEvent: { position, sourceChainId, targetChainId, sourceDsaId } } = transaction;
62
+ try {
63
+ (0, utils_1.validateChains)({ sourceChainId, targetChainId });
64
+ }
65
+ catch (error) {
66
+ transaction.sourceErrors = [error.message];
67
+ transaction.sourceStatus = "failed";
68
+ transaction.targetStatus = "failed";
69
+ transaction.status = "failed";
70
+ await transaction.save();
71
+ return;
72
+ }
73
+ const walletBalance = (await this.sourceWallet.getBalance()).toString();
74
+ const currentGasPrice = (await this.sourceWallet.getGasPrice()).toString();
75
+ const minBalanceRequired = new bignumber_js_1.BigNumber(currentGasPrice)
76
+ .multipliedBy(4000000)
77
+ .multipliedBy(2); // 2x balance
78
+ if (new bignumber_js_1.BigNumber(walletBalance).isLessThan(minBalanceRequired)) {
79
+ console.log((0, dedent_1.default) `Not enough balance in wallet ${(0, utils_1.getExplorerUrl)(sourceChainId, '/address/' + this.sourceWallet.address)} on ${(0, utils_1.chainIdToName)(sourceChainId)}
80
+ Balance: ${ethers_1.ethers.utils.parseEther(walletBalance)} ${(0, utils_1.getChainIdNativeSymbol)(sourceChainId)}
81
+ Required Balance: ${ethers_1.ethers.utils.parseEther(minBalanceRequired.toString())}
82
+ Require more: ${ethers_1.ethers.utils.parseEther(minBalanceRequired.minus(walletBalance).toString())}`);
83
+ transaction.sourceDelayUntil = (0, moment_1.default)().add({ minutes: 5 }).toDate();
84
+ transaction.sourceStatus = "pending";
85
+ await transaction.save();
86
+ return;
87
+ }
88
+ try {
89
+ await (0, utils_1.validateLiquidityCap)(position, sourceChainId, targetChainId);
90
+ }
91
+ catch (error) {
92
+ transaction.sourceErrors = [error.message];
93
+ transaction.sourceStatus = "failed";
94
+ transaction.targetStatus = "failed";
95
+ transaction.status = "failed";
96
+ await transaction.save();
97
+ return;
98
+ }
99
+ try {
100
+ await (0, utils_1.validateSourceLiquidity)({
101
+ position,
102
+ sourceChainId,
103
+ sourceDsaId,
104
+ sourceProvider: this.sourceProvider,
105
+ });
106
+ }
107
+ catch (error) {
108
+ if (error instanceof errors_1.UnsupportedChaindIdError) {
109
+ console.log(`Dropping transaction ${transaction.transactionHash}`);
110
+ transaction.sourceErrors = [error.message];
111
+ transaction.sourceStatus = "failed";
112
+ transaction.targetStatus = "failed";
113
+ transaction.status = "failed";
114
+ await transaction.save();
115
+ }
116
+ else {
117
+ transaction.sourceStatus = "pending";
118
+ transaction.sourceErrors = [error.message];
119
+ transaction.sourceDelayUntil = (0, moment_1.default)().add({ minutes: 5 }).toDate();
120
+ await transaction.save();
121
+ console.log("[validateSourceLiquidity][Warning]", error.message);
122
+ return;
123
+ }
124
+ }
125
+ const ownersThreshold = await this.sourceGnosisContract.getThreshold();
126
+ await (0, waait_1.default)(10000);
127
+ this.logger.debug(`Build gnosis action for ${transaction.transactionHash}`);
128
+ let data, logs = [];
129
+ try {
130
+ ({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction, "source"));
131
+ }
132
+ catch (error) {
133
+ if (error instanceof errors_1.LiquidityError) {
134
+ await transaction.save();
135
+ transaction.sourceDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
136
+ transaction.sourceStatus = "pending";
137
+ await transaction.save();
138
+ throw error;
139
+ return;
140
+ }
141
+ transaction.sourceStatus = "failed";
142
+ transaction.sourceErrors = [error.message];
143
+ transaction.targetStatus = "failed";
144
+ transaction.status = "failed";
145
+ await transaction.save();
146
+ net_1.protocol.sendTransaction(transaction);
147
+ return;
148
+ }
149
+ this.logger.debug(`Generating gnosis tx for ${transaction.transactionHash}`);
150
+ let gnosisTx = await (0, utils_1.generateGnosisTransaction)({
151
+ baseGas: "0",
152
+ data,
153
+ gasPrice: "0",
154
+ gasToken: "0x0000000000000000000000000000000000000000",
155
+ nonce: "0",
156
+ operation: "1",
157
+ refundReceiver: "0x0000000000000000000000000000000000000000",
158
+ safeAddress: this.sourceGnosisContract.address,
159
+ safeTxGas: "79668",
160
+ to: constants_1.addresses[transaction.sourceChainId].multisend,
161
+ value: "0",
162
+ }, this.sourceGnosisContract);
163
+ async function getGnosisOwnerPeerIds({ gnosisContract }) {
164
+ const owners = await gnosisContract
165
+ .getOwners()
166
+ .then((owners) => owners.map((owner) => owner.toLowerCase()));
167
+ return net_1.peerPool.activePeers
168
+ .filter((peer) => owners.includes(peer.publicAddress.toLowerCase()))
169
+ .map((peer) => peer.id);
170
+ }
171
+ const ownerPeerIds = await getGnosisOwnerPeerIds({
172
+ gnosisContract: this.sourceGnosisContract,
173
+ });
174
+ console.log(`Collecting signatures for execution ${transaction.transactionHash} `);
175
+ console.log(ownerPeerIds);
176
+ console.log(data);
177
+ const message = (0, utils_1.generateGnosisSignatureMessage)({
178
+ to: constants_1.addresses[this.chainId].multisend,
179
+ data,
180
+ chainId: this.chainId,
181
+ safeTxGas: gnosisTx.safeTxGas,
182
+ nonce: gnosisTx.safeNonce,
183
+ });
184
+ const signatures = await net_1.protocol.requestSignatures({
185
+ type: "source",
186
+ transactionHash: transaction.transactionHash,
187
+ safeTxGas: gnosisTx.safeTxGas,
188
+ safeNonce: gnosisTx.nonce,
189
+ chainId: this.chainId,
190
+ }, ownerPeerIds);
191
+ const validSignatures = signatures
192
+ .filter((s) => !!s.data && s.data !== "0x")
193
+ .filter((s) => {
194
+ try {
195
+ const address = (0, utils_1.getGnosisSignatureAddress)({
196
+ message,
197
+ signature: s.data,
198
+ chainId: this.chainId,
199
+ });
200
+ return (address === null || address === void 0 ? void 0 : address.toLowerCase()) === s.signer.toLowerCase();
201
+ }
202
+ catch (error) {
203
+ return false;
204
+ }
205
+ });
206
+ console.log({
207
+ signatures,
208
+ validSignatures,
209
+ ownersThreshold: ownersThreshold.toString(),
210
+ });
211
+ if (validSignatures.length === 0 ||
212
+ ownersThreshold.gt(validSignatures.length)) {
213
+ await transaction.save();
214
+ transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
215
+ transaction.sourceStatus = "pending";
216
+ await transaction.save();
217
+ const errorMessage = (_a = signatures.find((s) => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
218
+ throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage} ` : ""));
219
+ }
220
+ console.log(`Executing transaction for execution ${transaction.transactionHash}`);
221
+ const { data: txData } = await this.sourceGnosisContract.populateTransaction.execTransaction(gnosisTx.to, gnosisTx.value, gnosisTx.data, gnosisTx.operation, gnosisTx.safeTxGas, gnosisTx.baseGas, gnosisTx.gasPrice, gnosisTx.gasToken, gnosisTx.refundReceiver, (0, utils_1.buildSignatureBytes)(validSignatures));
222
+ const [gasPrice, gasLimit] = await Promise.all([
223
+ this.sourceProvider.getGasPrice(),
224
+ this.sourceProvider.estimateGas({
225
+ from: this.sourceWallet.address,
226
+ to: this.sourceGnosisContract.address,
227
+ data: txData,
228
+ }),
229
+ ]);
230
+ const txSent = await this.sourceWallet.sendTransaction({
231
+ from: this.sourceWallet.address,
232
+ to: this.sourceGnosisContract.address,
233
+ gasPrice: gasPrice.mul(120).div(100),
234
+ gasLimit: 5000000,
235
+ data: txData,
236
+ });
237
+ console.log(txSent);
238
+ const receipt = await txSent.wait();
239
+ const parsedLogs = [];
240
+ receipt.logs.forEach((log) => {
241
+ try {
242
+ parsedLogs.push(this.sourceGnosisContract.interface.parseLog(log));
243
+ }
244
+ catch (e) { }
245
+ });
246
+ if (parsedLogs.find((e) => e.name === "ExecutionSuccess")) {
247
+ console.log("ExecutionSuccess");
248
+ transaction.sourceStatus = "success";
249
+ if (txSent.blockNumber)
250
+ transaction.sourceBlockNumber = txSent.blockNumber;
251
+ transaction.sourceTransactionHash = txSent.hash;
252
+ transaction.sourceLogs = logs;
253
+ await transaction.save();
254
+ }
255
+ else {
256
+ console.log("ExecutionFailure");
257
+ transaction.sourceStatus = "failed";
258
+ if (txSent.blockNumber)
259
+ transaction.sourceBlockNumber = txSent.blockNumber;
260
+ transaction.sourceTransactionHash = txSent.hash;
261
+ transaction.status = "failed";
262
+ await transaction.save();
263
+ }
264
+ net_1.protocol.sendTransaction(transaction);
265
+ }
266
+ async start() {
267
+ this.blockConfirmationsCount = constants_1.blockConfirmations[this.chainId] + 1;
268
+ this.sourceProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
269
+ this.sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, this.sourceProvider);
270
+ this.sourceGnosisContract = (0, utils_1.getContract)(constants_1.addresses[this.chainId].gnosisSafe, abi_1.default.gnosisSafe, this.sourceWallet);
271
+ await super.start();
272
+ }
273
+ }
274
+ exports.default = ProcessSubmitEvents;
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const BaseTask_1 = require("../BaseTask");
7
+ const logger_1 = __importDefault(require("@/logger"));
8
+ const ethers_1 = require("ethers");
9
+ const abi_1 = __importDefault(require("@/abi"));
10
+ const db_1 = require("@/db");
11
+ const utils_1 = require("@/utils");
12
+ const constants_1 = require("@/constants");
13
+ const config_1 = __importDefault(require("@/config"));
14
+ const moment_1 = __importDefault(require("moment"));
15
+ const sequelize_1 = require("sequelize");
16
+ const gnosis_1 = require("@/gnosis");
17
+ const net_1 = require("@/net");
18
+ const waait_1 = __importDefault(require("waait"));
19
+ const errors_1 = require("@/errors");
20
+ const providers_1 = require("@/providers");
21
+ class ProcessValidateEvents extends BaseTask_1.BaseTask {
22
+ constructor({ chainId }) {
23
+ super({
24
+ logger: new logger_1.default("InteropX::ProcessValidateEvents"),
25
+ });
26
+ this.leadNodeOnly = true;
27
+ this.blockConfirmationsCount = 12;
28
+ this.chainId = chainId;
29
+ }
30
+ async pollHandler() {
31
+ var _a;
32
+ const currentBlockNumber = await this.sourceProvider.getBlockNumber();
33
+ const transaction = await db_1.Transaction.findOne({
34
+ where: {
35
+ status: "pending",
36
+ sourceStatus: "success",
37
+ targetStatus: "pending",
38
+ sourceChainId: this.chainId,
39
+ sourceBlockNumber: {
40
+ [sequelize_1.Op.lt]: currentBlockNumber - this.blockConfirmationsCount,
41
+ },
42
+ targetDelayUntil: {
43
+ [sequelize_1.Op.or]: {
44
+ [sequelize_1.Op.is]: null,
45
+ [sequelize_1.Op.lt]: new Date(),
46
+ },
47
+ },
48
+ submitEvent: { $ne: null },
49
+ validateEvent: { $ne: null },
50
+ createdAt: {
51
+ [sequelize_1.Op.gt]: (0, moment_1.default)().subtract({ hours: 12 }).toDate(),
52
+ },
53
+ },
54
+ });
55
+ if (!transaction) {
56
+ return;
57
+ }
58
+ this.logger.debug(`Processing transaction ${transaction.transactionHash}`);
59
+ transaction.targetStatus = "proccessing";
60
+ await transaction.save();
61
+ const { sourceChainId, targetChainId } = transaction.validateEvent;
62
+ const targetProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
63
+ const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetProvider);
64
+ const targetGnosisContract = (0, utils_1.getContract)(constants_1.addresses[targetChainId].gnosisSafe, abi_1.default.gnosisSafe, targetWallet);
65
+ const ownersThreshold = await targetGnosisContract.getThreshold();
66
+ await (0, waait_1.default)(10000);
67
+ this.logger.debug(`Build gnosis action for ${transaction.transactionHash}`);
68
+ let data, logs = [];
69
+ try {
70
+ ({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction, "target"));
71
+ }
72
+ catch (error) {
73
+ if (error instanceof errors_1.LiquidityError) {
74
+ await transaction.save();
75
+ transaction.targetDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
76
+ transaction.targetStatus = "pending";
77
+ await transaction.save();
78
+ throw error;
79
+ return;
80
+ }
81
+ transaction.targetStatus = "failed";
82
+ transaction.targetErrors = [error.message];
83
+ transaction.status = "failed";
84
+ await transaction.save();
85
+ net_1.protocol.sendTransaction(transaction);
86
+ return;
87
+ }
88
+ this.logger.debug(`Generating gnosis tx for ${transaction.transactionHash}`);
89
+ let gnosisTx = await (0, utils_1.generateGnosisTransaction)({
90
+ baseGas: "0",
91
+ data,
92
+ gasPrice: "0",
93
+ gasToken: "0x0000000000000000000000000000000000000000",
94
+ nonce: "0",
95
+ operation: "1",
96
+ refundReceiver: "0x0000000000000000000000000000000000000000",
97
+ safeAddress: targetGnosisContract.address,
98
+ safeTxGas: "79668",
99
+ to: constants_1.addresses[transaction.targetChainId].multisend,
100
+ value: "0",
101
+ }, targetGnosisContract);
102
+ const ownerPeerIds = await (0, utils_1.getGnosisOwnerPeerIds)({
103
+ gnosisContract: targetGnosisContract,
104
+ });
105
+ console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
106
+ console.log(ownerPeerIds);
107
+ const message = (0, utils_1.generateGnosisSignatureMessage)({
108
+ to: constants_1.addresses[targetChainId].multisend,
109
+ data,
110
+ chainId: targetChainId,
111
+ safeTxGas: gnosisTx.safeTxGas,
112
+ nonce: gnosisTx.safeNonce,
113
+ });
114
+ const signatures = await net_1.protocol.requestSignatures({
115
+ type: "target",
116
+ transactionHash: transaction.transactionHash,
117
+ safeTxGas: gnosisTx.safeTxGas,
118
+ safeNonce: gnosisTx.nonce,
119
+ chainId: targetChainId,
120
+ }, ownerPeerIds);
121
+ const validSignatures = signatures
122
+ .filter((s) => !!s.data && s.data !== "0x")
123
+ .filter((s) => {
124
+ try {
125
+ const address = (0, utils_1.getGnosisSignatureAddress)({
126
+ message,
127
+ signature: s.data,
128
+ chainId: targetChainId,
129
+ });
130
+ return (address === null || address === void 0 ? void 0 : address.toLowerCase()) === s.signer.toLowerCase();
131
+ }
132
+ catch (error) {
133
+ return false;
134
+ }
135
+ });
136
+ console.log({
137
+ signatures,
138
+ validSignatures,
139
+ ownersThreshold: ownersThreshold.toString(),
140
+ });
141
+ if (validSignatures.length === 0 ||
142
+ ownersThreshold.gt(validSignatures.length)) {
143
+ await transaction.save();
144
+ transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
145
+ transaction.targetStatus = "pending";
146
+ await transaction.save();
147
+ const errorMessage = (_a = signatures.find((s) => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
148
+ throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ""));
149
+ }
150
+ console.log(`Executing transaction for execution ${transaction.transactionHash}`);
151
+ const { data: txData } = await targetGnosisContract.populateTransaction.execTransaction(gnosisTx.to, gnosisTx.value, gnosisTx.data, gnosisTx.operation, gnosisTx.safeTxGas, gnosisTx.baseGas, gnosisTx.gasPrice, gnosisTx.gasToken, gnosisTx.refundReceiver, (0, utils_1.buildSignatureBytes)(validSignatures));
152
+ const [gasPrice, gasLimit] = await Promise.all([
153
+ targetProvider.getGasPrice(),
154
+ targetProvider.estimateGas({
155
+ from: targetWallet.address,
156
+ to: targetGnosisContract.address,
157
+ data: txData,
158
+ }),
159
+ ]);
160
+ const txSent = await targetWallet.sendTransaction({
161
+ from: targetWallet.address,
162
+ to: targetGnosisContract.address,
163
+ gasPrice: gasPrice.mul(120).div(100),
164
+ gasLimit: 5000000,
165
+ data: txData,
166
+ });
167
+ console.log(txSent);
168
+ const receipt = await txSent.wait();
169
+ const parsedLogs = [];
170
+ receipt.logs.forEach((log) => {
171
+ try {
172
+ parsedLogs.push(targetGnosisContract.interface.parseLog(log));
173
+ }
174
+ catch (e) { }
175
+ });
176
+ if (parsedLogs.find((e) => e.name === "ExecutionSuccess")) {
177
+ console.log("ExecutionSuccess");
178
+ transaction.targetStatus = "success";
179
+ transaction.status = "success";
180
+ if (txSent.blockNumber)
181
+ transaction.targetBlockNumber = txSent.blockNumber;
182
+ transaction.targetTransactionHash = txSent.hash;
183
+ transaction.targetLogs = logs;
184
+ await transaction.save();
185
+ }
186
+ else {
187
+ console.log("ExecutionFailure");
188
+ transaction.targetStatus = "failed";
189
+ if (txSent.blockNumber)
190
+ transaction.targetBlockNumber = txSent.blockNumber;
191
+ transaction.targetTransactionHash = txSent.hash;
192
+ transaction.status = "failed";
193
+ await transaction.save();
194
+ }
195
+ net_1.protocol.sendTransaction(transaction);
196
+ }
197
+ async start() {
198
+ this.blockConfirmationsCount = constants_1.blockConfirmations[this.chainId] + 1;
199
+ this.sourceProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
200
+ await super.start();
201
+ }
202
+ }
203
+ exports.default = ProcessValidateEvents;