@instadapp/interop-x 0.0.0-dev.a168c79 → 0.0.0-dev.a271713

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 (326) hide show
  1. package/.github/workflows/ci.yml +19 -0
  2. package/bin/interop-x +1 -1
  3. package/dist/package.json +30 -16
  4. package/dist/src/abi/aaveV2Resolver.json +832 -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 +10 -4
  94. package/dist/src/abi/instList.json +232 -0
  95. package/dist/src/abi/interopX.json +1436 -0
  96. package/dist/src/alias.js +10 -0
  97. package/dist/src/api/index.js +13 -3
  98. package/dist/src/config/index.js +11 -1
  99. package/dist/src/constants/addresses.js +10 -7
  100. package/dist/src/constants/blockConfirmations.js +8 -0
  101. package/dist/src/constants/capPerChain.js +8 -0
  102. package/dist/src/constants/index.js +3 -1
  103. package/dist/src/constants/tokens.js +30 -7
  104. package/dist/src/constants/wrappedNativeToken.js +8 -0
  105. package/dist/src/crons/index.js +3 -0
  106. package/dist/src/crons/prices.js +16 -0
  107. package/dist/src/db/models/transaction.js +41 -15
  108. package/dist/src/errors/index.js +30 -0
  109. package/dist/src/gnosis/actions/aaveV2/index.js +11 -0
  110. package/dist/src/gnosis/actions/aaveV2/source.js +74 -0
  111. package/dist/src/gnosis/actions/aaveV2/target.js +87 -0
  112. package/dist/src/gnosis/actions/aaveV3/index.js +11 -0
  113. package/dist/src/gnosis/actions/aaveV3/source.js +74 -0
  114. package/dist/src/gnosis/actions/aaveV3/target.js +87 -0
  115. package/dist/src/gnosis/actions/index.js +11 -0
  116. package/dist/src/gnosis/index.js +20 -0
  117. package/dist/src/index.js +76 -24
  118. package/dist/src/net/peer/index.js +8 -3
  119. package/dist/src/net/pool/index.js +32 -9
  120. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +10 -4
  121. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
  122. package/dist/src/net/protocol/index.js +51 -1
  123. package/dist/src/providers/index.js +17 -0
  124. package/dist/src/providers/retry-provider.js +45 -0
  125. package/dist/src/services/Prices.js +74 -0
  126. package/dist/src/services/index.js +8 -0
  127. package/dist/src/tasks/AutoUpdateTask.js +70 -0
  128. package/dist/src/tasks/BaseTask.js +12 -4
  129. package/dist/src/tasks/InteropX/ProcessSubmitEvents.js +271 -0
  130. package/dist/src/tasks/InteropX/ProcessValidateEvents.js +203 -0
  131. package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +113 -0
  132. package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +88 -0
  133. package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +106 -0
  134. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +58 -0
  135. package/dist/src/tasks/index.js +22 -4
  136. package/dist/src/typechain/{InteropBridgeToken.js → AaveV2Resolver.js} +0 -0
  137. package/dist/src/typechain/{InteropXGateway.js → BalanceResolver.js} +0 -0
  138. package/dist/src/typechain/InstList.js +2 -0
  139. package/dist/src/typechain/InteropX.js +2 -0
  140. package/dist/src/typechain/factories/AaveV2Resolver__factory.js +1191 -0
  141. package/dist/src/typechain/factories/BalanceResolver__factory.js +228 -0
  142. package/dist/src/typechain/factories/InstList__factory.js +249 -0
  143. package/dist/src/typechain/factories/InteropX__factory.js +1928 -0
  144. package/dist/src/typechain/factories/index.js +9 -5
  145. package/dist/src/typechain/index.js +9 -5
  146. package/dist/src/utils/async.js +18 -0
  147. package/dist/src/utils/dsa.js +24 -0
  148. package/dist/src/utils/formatting.js +67 -0
  149. package/dist/src/utils/gnosis.js +87 -0
  150. package/dist/src/utils/http.js +10 -0
  151. package/dist/src/utils/index.js +22 -134
  152. package/dist/src/utils/interop.js +16 -0
  153. package/dist/src/utils/tokens.js +22 -0
  154. package/dist/src/utils/validate.js +111 -0
  155. package/dist/src/utils/web3.js +93 -0
  156. package/package.json +30 -16
  157. package/patches/@ethersproject+properties+5.6.0.patch +13 -0
  158. package/src/abi/aaveV2Resolver.json +832 -0
  159. package/src/abi/balanceResolver.json +211 -0
  160. package/src/abi/connectors/index.ts +14 -0
  161. package/src/abi/connectors/v1/aave.ts +147 -0
  162. package/src/abi/connectors/v1/aave_claim.ts +3 -0
  163. package/src/abi/connectors/v1/aave_migrate.ts +108 -0
  164. package/src/abi/connectors/v1/aave_polygon_migrate.ts +109 -0
  165. package/src/abi/connectors/v1/aave_stake.ts +3 -0
  166. package/src/abi/connectors/v1/aave_v1_import.ts +53 -0
  167. package/src/abi/connectors/v1/aave_v2.ts +229 -0
  168. package/src/abi/connectors/v1/aave_v2_import.ts +58 -0
  169. package/src/abi/connectors/v1/authority.ts +99 -0
  170. package/src/abi/connectors/v1/basic.ts +135 -0
  171. package/src/abi/connectors/v1/chi.ts +35 -0
  172. package/src/abi/connectors/v1/comp.ts +3 -0
  173. package/src/abi/connectors/v1/compound.ts +3 -0
  174. package/src/abi/connectors/v1/compoundImport.ts +68 -0
  175. package/src/abi/connectors/v1/compoundImport_v2.ts +3 -0
  176. package/src/abi/connectors/v1/compound_old.ts +447 -0
  177. package/src/abi/connectors/v1/curve.ts +139 -0
  178. package/src/abi/connectors/v1/curve_claim.ts +62 -0
  179. package/src/abi/connectors/v1/curve_gauge.ts +157 -0
  180. package/src/abi/connectors/v1/curve_sbtc.ts +139 -0
  181. package/src/abi/connectors/v1/curve_susd.ts +139 -0
  182. package/src/abi/connectors/v1/curve_three.ts +78 -0
  183. package/src/abi/connectors/v1/curve_y.ts +139 -0
  184. package/src/abi/connectors/v1/dsa_migrate_v1_to_v2.ts +3 -0
  185. package/src/abi/connectors/v1/dydx.ts +147 -0
  186. package/src/abi/connectors/v1/dydx_flash.ts +51 -0
  187. package/src/abi/connectors/v1/fee.ts +49 -0
  188. package/src/abi/connectors/v1/gelato.ts +1137 -0
  189. package/src/abi/connectors/v1/index.ts +42 -0
  190. package/src/abi/connectors/v1/instapool.ts +438 -0
  191. package/src/abi/connectors/v1/instapool_v2.ts +125 -0
  192. package/src/abi/connectors/v1/kyber.ts +116 -0
  193. package/src/abi/connectors/v1/maker.ts +479 -0
  194. package/src/abi/connectors/v1/maker_old.ts +299 -0
  195. package/src/abi/connectors/v1/math.ts +42 -0
  196. package/src/abi/connectors/v1/migrate.ts +45 -0
  197. package/src/abi/connectors/v1/oasis.ts +197 -0
  198. package/src/abi/connectors/v1/oneInch.ts +159 -0
  199. package/src/abi/connectors/v1/polygon_bridge.ts +3 -0
  200. package/src/abi/connectors/v1/refinance.ts +3 -0
  201. package/src/abi/connectors/v1/staking.ts +219 -0
  202. package/src/abi/connectors/v1/swerve.ts +178 -0
  203. package/src/abi/connectors/v1/uniswap.ts +297 -0
  204. package/src/abi/connectors/v2/1INCH-A.ts +3 -0
  205. package/src/abi/connectors/v2/1INCH-B.ts +3 -0
  206. package/src/abi/connectors/v2/AAVE-CLAIM-A.ts +3 -0
  207. package/src/abi/connectors/v2/AAVE-CLAIM-B.ts +165 -0
  208. package/src/abi/connectors/v2/AAVE-STAKE-A.ts +3 -0
  209. package/src/abi/connectors/v2/AAVE-V1-A.ts +130 -0
  210. package/src/abi/connectors/v2/AAVE-V1-IMPORT-A.ts +3 -0
  211. package/src/abi/connectors/v2/AAVE-V2-A.ts +229 -0
  212. package/src/abi/connectors/v2/AAVE-V2-IMPORT-A.ts +3 -0
  213. package/src/abi/connectors/v2/AAVE-V2-IMPORT-B.ts +224 -0
  214. package/src/abi/connectors/v2/AUTHORITY-A.ts +99 -0
  215. package/src/abi/connectors/v2/B-COMPOUND-A.ts +3 -0
  216. package/src/abi/connectors/v2/B-LIQUITY-A.ts +3 -0
  217. package/src/abi/connectors/v2/B-MAKERDAO-A.ts +3 -0
  218. package/src/abi/connectors/v2/BASIC-A.ts +135 -0
  219. package/src/abi/connectors/v2/BASIC-B.ts +3 -0
  220. package/src/abi/connectors/v2/BASIC-C.ts +3 -0
  221. package/src/abi/connectors/v2/COMP-A.ts +3 -0
  222. package/src/abi/connectors/v2/COMPOUND-A.ts +3 -0
  223. package/src/abi/connectors/v2/COMPOUND-IMPORT-A.ts +3 -0
  224. package/src/abi/connectors/v2/COMPOUND-IMPORT-B.ts +194 -0
  225. package/src/abi/connectors/v2/G-UNISWAP-A.ts +3 -0
  226. package/src/abi/connectors/v2/GELATO-AAVE-A.ts +3 -0
  227. package/src/abi/connectors/v2/INST-A.ts +3 -0
  228. package/src/abi/connectors/v2/INST-LM-A.ts +3 -0
  229. package/src/abi/connectors/v2/INST-STAKING-A.ts +3 -0
  230. package/src/abi/connectors/v2/INST-STAKING-B.ts +3 -0
  231. package/src/abi/connectors/v2/INSTAPOOL-A.ts +3 -0
  232. package/src/abi/connectors/v2/LIQUITY-A.ts +3 -0
  233. package/src/abi/connectors/v2/MAKERDAO-A.ts +3 -0
  234. package/src/abi/connectors/v2/MAKERDAO-CLAIM-A.ts +135 -0
  235. package/src/abi/connectors/v2/PARASWAP-A.ts +3 -0
  236. package/src/abi/connectors/v2/POLYGON-BRIDGE-A.ts +3 -0
  237. package/src/abi/connectors/v2/REFINANCE-A.ts +3 -0
  238. package/src/abi/connectors/v2/REFLEXER-A.ts +3 -0
  239. package/src/abi/connectors/v2/STAKE-ERC20-A.ts +3 -0
  240. package/src/abi/connectors/v2/UNISWAP-A.ts +297 -0
  241. package/src/abi/connectors/v2/UNISWAP-V2-A.ts +3 -0
  242. package/src/abi/connectors/v2/UNISWAP-V3-A.ts +3 -0
  243. package/src/abi/connectors/v2/UNISWAP-V3-STAKE-A.ts +3 -0
  244. package/src/abi/connectors/v2/WETH-A.ts +3 -0
  245. package/src/abi/connectors/v2/YEARN-VAULT-A.ts +3 -0
  246. package/src/abi/connectors/v2/index.ts +87 -0
  247. package/src/abi/index.ts +13 -7
  248. package/src/abi/instList.json +232 -0
  249. package/src/abi/interopX.json +1436 -0
  250. package/src/alias.ts +6 -0
  251. package/src/api/index.ts +13 -2
  252. package/src/config/index.ts +11 -1
  253. package/src/constants/addresses.ts +21 -8
  254. package/src/constants/blockConfirmations.ts +5 -0
  255. package/src/constants/capPerChain.ts +5 -0
  256. package/src/constants/index.ts +3 -1
  257. package/src/constants/tokens.ts +31 -8
  258. package/src/constants/wrappedNativeToken.ts +5 -0
  259. package/src/crons/index.ts +1 -0
  260. package/src/crons/prices.ts +12 -0
  261. package/src/db/models/transaction.ts +159 -65
  262. package/src/errors/index.ts +26 -0
  263. package/src/gnosis/actions/aaveV2/index.ts +9 -0
  264. package/src/gnosis/actions/aaveV2/source.ts +119 -0
  265. package/src/gnosis/actions/aaveV2/target.ts +142 -0
  266. package/src/gnosis/actions/aaveV3/index.ts +9 -0
  267. package/src/gnosis/actions/aaveV3/source.ts +119 -0
  268. package/src/gnosis/actions/aaveV3/target.ts +142 -0
  269. package/src/gnosis/actions/index.ts +7 -0
  270. package/src/gnosis/index.ts +19 -0
  271. package/src/index.ts +97 -26
  272. package/src/net/peer/index.ts +9 -7
  273. package/src/net/pool/index.ts +41 -11
  274. package/src/net/protocol/dial/SignatureDialProtocol.ts +13 -6
  275. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
  276. package/src/net/protocol/index.ts +67 -1
  277. package/src/providers/index.ts +1 -0
  278. package/src/providers/retry-provider.ts +51 -0
  279. package/src/services/Prices.ts +89 -0
  280. package/src/services/index.ts +1 -0
  281. package/src/tasks/AutoUpdateTask.ts +82 -0
  282. package/src/tasks/BaseTask.ts +14 -4
  283. package/src/tasks/InteropX/ProcessSubmitEvents.ts +382 -0
  284. package/src/tasks/InteropX/ProcessValidateEvents.ts +297 -0
  285. package/src/tasks/InteropX/SyncLogExecuteEvents.ts +161 -0
  286. package/src/tasks/InteropX/SyncLogSubmitEvents.ts +138 -0
  287. package/src/tasks/InteropX/SyncLogValidateEvents.ts +151 -0
  288. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +70 -0
  289. package/src/tasks/index.ts +32 -5
  290. package/src/typechain/AaveV2Resolver.ts +1017 -0
  291. package/src/typechain/BalanceResolver.ts +266 -0
  292. package/src/typechain/InstList.ts +402 -0
  293. package/src/typechain/InteropX.ts +1216 -0
  294. package/src/typechain/factories/AaveV2Resolver__factory.ts +1198 -0
  295. package/src/typechain/factories/BalanceResolver__factory.ts +235 -0
  296. package/src/typechain/factories/InstList__factory.ts +253 -0
  297. package/src/typechain/factories/InteropX__factory.ts +1932 -0
  298. package/src/typechain/factories/index.ts +4 -2
  299. package/src/typechain/index.ts +8 -4
  300. package/src/utils/async.ts +22 -0
  301. package/src/utils/dsa.ts +30 -0
  302. package/src/utils/formatting.ts +68 -0
  303. package/src/utils/gnosis.ts +166 -0
  304. package/src/utils/http.ts +6 -0
  305. package/src/utils/index.ts +9 -185
  306. package/src/utils/interop.ts +28 -0
  307. package/src/utils/tokens.ts +21 -0
  308. package/src/utils/validate.ts +174 -0
  309. package/src/utils/web3.ts +132 -0
  310. package/tsconfig.json +7 -2
  311. package/dist/src/abi/interopBridgeToken.json +0 -286
  312. package/dist/src/abi/interopXGateway.json +0 -184
  313. package/dist/src/constants/itokens.js +0 -13
  314. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +0 -140
  315. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -75
  316. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -459
  317. package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
  318. package/src/abi/interopBridgeToken.json +0 -286
  319. package/src/abi/interopXGateway.json +0 -184
  320. package/src/constants/itokens.ts +0 -10
  321. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -232
  322. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -126
  323. package/src/typechain/InteropBridgeToken.ts +0 -686
  324. package/src/typechain/InteropXGateway.ts +0 -407
  325. package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
  326. package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -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,70 @@
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 await_spawn_1 = __importDefault(require("await-spawn"));
9
+ const child_process_1 = require("child_process");
10
+ const config_1 = __importDefault(require("@/config"));
11
+ const waait_1 = __importDefault(require("waait"));
12
+ const package_json_1 = __importDefault(require("../../package.json"));
13
+ const currentVersion = package_json_1.default.version;
14
+ const tag = config_1.default.staging ? 'dev' : 'latest';
15
+ class AutoUpdateTask extends BaseTask_1.BaseTask {
16
+ constructor() {
17
+ super({
18
+ logger: new logger_1.default("AutoUpdateTask"),
19
+ });
20
+ this.pollIntervalMs = 60 * 10 * 1000;
21
+ }
22
+ prePollHandler() {
23
+ return config_1.default.autoUpdate && !config_1.default.isLeadNode();
24
+ }
25
+ async getInstalledVersion() {
26
+ try {
27
+ const stdout = await (0, await_spawn_1.default)('npm', ['-g', 'ls', '--depth=0', '--json']);
28
+ return JSON.parse(stdout.toString()).dependencies[package_json_1.default.name].version;
29
+ }
30
+ catch (error) {
31
+ this.logger.error(error);
32
+ return currentVersion;
33
+ }
34
+ }
35
+ async getLatestVersion() {
36
+ try {
37
+ const stdout = await (0, await_spawn_1.default)('npm', ['view', `${package_json_1.default.name}@${tag}`, 'version']);
38
+ return stdout.toString().trim();
39
+ }
40
+ catch (error) {
41
+ this.logger.error(error);
42
+ return currentVersion;
43
+ }
44
+ }
45
+ async pollHandler() {
46
+ const version = await this.getLatestVersion();
47
+ if (version === currentVersion) {
48
+ return;
49
+ }
50
+ this.logger.warn(`New version ${version} available.`);
51
+ this.logger.info('Updating...');
52
+ await (0, await_spawn_1.default)('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
53
+ await (0, waait_1.default)(5000);
54
+ if (version !== await this.getInstalledVersion()) {
55
+ this.logger.warn(`failed to install ${version}, retrying in 5 minutes`);
56
+ return;
57
+ }
58
+ this.logger.warn(`Installed version ${version}`);
59
+ this.logger.warn(`Restarting...`);
60
+ // TODO: its restarting in the bg, but it should be in the fg
61
+ const subprocess = (0, child_process_1.spawn)(process.argv[0], process.argv.slice(1), {
62
+ cwd: process.cwd(),
63
+ stdio: "inherit",
64
+ // shell: process.env.SHELL,
65
+ });
66
+ subprocess.unref();
67
+ process.exit();
68
+ }
69
+ }
70
+ exports.default = AutoUpdateTask;
@@ -14,6 +14,7 @@ class BaseTask extends events_1.default {
14
14
  this.started = false;
15
15
  this.pollIntervalMs = 10 * 1000;
16
16
  this.leadNodeOnly = false;
17
+ this.exceptLeadNode = false;
17
18
  this.logger = logger !== null && logger !== void 0 ? logger : new logger_1.default('BaseTask');
18
19
  }
19
20
  async pollCheck() {
@@ -28,16 +29,23 @@ class BaseTask extends events_1.default {
28
29
  }
29
30
  }
30
31
  catch (err) {
31
- this.logger.error(`poll check error: ${err.message}\ntrace: ${err.stack}`);
32
+ this.logger.error(`poll check error:\n${err.message}\ntrace: ${err.stack}`);
32
33
  }
33
34
  await this.postPollHandler();
34
35
  }
35
36
  }
36
37
  prePollHandler() {
37
- if (!this.leadNodeOnly) {
38
- return true;
38
+ if (config_1.default.isMaintenanceMode()) {
39
+ this.logger.warn('Maintenance mode is enabled. Skipping task.');
40
+ return false;
39
41
  }
40
- return config_1.default.isLeadNode();
42
+ if (this.exceptLeadNode) {
43
+ return !config_1.default.isLeadNode();
44
+ }
45
+ if (this.leadNodeOnly) {
46
+ return config_1.default.isLeadNode();
47
+ }
48
+ return true;
41
49
  }
42
50
  async pollHandler() {
43
51
  this.logger.warn('pollHandler not implemented');
@@ -0,0 +1,271 @@
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 } } = 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
+ sourceProvider: this.sourceProvider,
104
+ });
105
+ }
106
+ catch (error) {
107
+ if (error instanceof errors_1.UnsupportedChaindIdError) {
108
+ console.log(`Dropping transaction ${transaction.transactionHash}`);
109
+ transaction.sourceErrors = [error.message];
110
+ transaction.sourceStatus = "failed";
111
+ transaction.targetStatus = "failed";
112
+ transaction.status = "failed";
113
+ await transaction.save();
114
+ }
115
+ else {
116
+ transaction.sourceStatus = "pending";
117
+ transaction.sourceDelayUntil = (0, moment_1.default)().add({ minutes: 5 }).toDate();
118
+ await transaction.save();
119
+ console.log("[validateSourceLiquidity][Warning]", error.message);
120
+ return;
121
+ }
122
+ }
123
+ const ownersThreshold = await this.sourceGnosisContract.getThreshold();
124
+ await (0, waait_1.default)(10000);
125
+ this.logger.debug(`Build gnosis action for ${transaction.transactionHash}`);
126
+ let data, logs = [];
127
+ try {
128
+ ({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction, "source"));
129
+ }
130
+ catch (error) {
131
+ if (error instanceof errors_1.LiquidityError) {
132
+ await transaction.save();
133
+ transaction.sourceDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
134
+ transaction.sourceStatus = "pending";
135
+ await transaction.save();
136
+ throw error;
137
+ return;
138
+ }
139
+ transaction.sourceStatus = "failed";
140
+ transaction.sourceErrors = [error.message];
141
+ transaction.targetStatus = "failed";
142
+ transaction.status = "failed";
143
+ await transaction.save();
144
+ net_1.protocol.sendTransaction(transaction);
145
+ return;
146
+ }
147
+ this.logger.debug(`Generating gnosis tx for ${transaction.transactionHash}`);
148
+ let gnosisTx = await (0, utils_1.generateGnosisTransaction)({
149
+ baseGas: "0",
150
+ data,
151
+ gasPrice: "0",
152
+ gasToken: "0x0000000000000000000000000000000000000000",
153
+ nonce: "0",
154
+ operation: "1",
155
+ refundReceiver: "0x0000000000000000000000000000000000000000",
156
+ safeAddress: this.sourceGnosisContract.address,
157
+ safeTxGas: "79668",
158
+ to: constants_1.addresses[transaction.sourceChainId].multisend,
159
+ value: "0",
160
+ }, this.sourceGnosisContract);
161
+ async function getGnosisOwnerPeerIds({ gnosisContract }) {
162
+ const owners = await gnosisContract
163
+ .getOwners()
164
+ .then((owners) => owners.map((owner) => owner.toLowerCase()));
165
+ return net_1.peerPool.activePeers
166
+ .filter((peer) => owners.includes(peer.publicAddress.toLowerCase()))
167
+ .map((peer) => peer.id);
168
+ }
169
+ const ownerPeerIds = await getGnosisOwnerPeerIds({
170
+ gnosisContract: this.sourceGnosisContract,
171
+ });
172
+ console.log(`Collecting signatures for execution ${transaction.transactionHash} `);
173
+ console.log(ownerPeerIds);
174
+ const message = (0, utils_1.generateGnosisSignatureMessage)({
175
+ to: constants_1.addresses[data.chainId].multisend,
176
+ data,
177
+ chainId: this.chainId,
178
+ safeTxGas: gnosisTx.safeTxGas,
179
+ nonce: gnosisTx.safeNonce,
180
+ });
181
+ const signatures = await net_1.protocol.requestSignatures({
182
+ type: "source",
183
+ transactionHash: transaction.transactionHash,
184
+ safeTxGas: gnosisTx.safeTxGas,
185
+ safeNonce: gnosisTx.nonce,
186
+ chainId: this.chainId,
187
+ }, ownerPeerIds);
188
+ const validSignatures = signatures
189
+ .filter((s) => !!s.data && s.data !== "0x")
190
+ .filter((s) => {
191
+ try {
192
+ const address = (0, utils_1.getGnosisSignatureAddress)({
193
+ message,
194
+ signature: s.data,
195
+ chainId: this.chainId,
196
+ });
197
+ return (address === null || address === void 0 ? void 0 : address.toLowerCase()) === s.signer.toLowerCase();
198
+ }
199
+ catch (error) {
200
+ return false;
201
+ }
202
+ });
203
+ console.log({
204
+ signatures,
205
+ validSignatures,
206
+ ownersThreshold: ownersThreshold.toString(),
207
+ });
208
+ if (validSignatures.length === 0 ||
209
+ ownersThreshold.gt(validSignatures.length)) {
210
+ await transaction.save();
211
+ transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
212
+ transaction.sourceStatus = "pending";
213
+ await transaction.save();
214
+ const errorMessage = (_a = signatures.find((s) => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
215
+ throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage} ` : ""));
216
+ }
217
+ console.log(`Executing transaction for execution ${transaction.transactionHash}`);
218
+ 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));
219
+ const [gasPrice, gasLimit] = await Promise.all([
220
+ this.sourceProvider.getGasPrice(),
221
+ this.sourceProvider.estimateGas({
222
+ from: this.sourceWallet.address,
223
+ to: this.sourceGnosisContract.address,
224
+ data: txData,
225
+ }),
226
+ ]);
227
+ const txSent = await this.sourceWallet.sendTransaction({
228
+ from: this.sourceWallet.address,
229
+ to: this.sourceGnosisContract.address,
230
+ gasPrice: gasPrice.mul(120).div(100),
231
+ gasLimit: 5000000,
232
+ data: txData,
233
+ });
234
+ console.log(txSent);
235
+ const receipt = await txSent.wait();
236
+ const parsedLogs = [];
237
+ receipt.logs.forEach((log) => {
238
+ try {
239
+ parsedLogs.push(this.sourceGnosisContract.interface.parseLog(log));
240
+ }
241
+ catch (e) { }
242
+ });
243
+ if (parsedLogs.find((e) => e.name === "ExecutionSuccess")) {
244
+ console.log("ExecutionSuccess");
245
+ transaction.sourceStatus = "success";
246
+ if (txSent.blockNumber)
247
+ transaction.sourceBlockNumber = txSent.blockNumber;
248
+ transaction.sourceTransactionHash = txSent.hash;
249
+ transaction.sourceLogs = logs;
250
+ await transaction.save();
251
+ }
252
+ else {
253
+ console.log("ExecutionFailure");
254
+ transaction.sourceStatus = "failed";
255
+ if (txSent.blockNumber)
256
+ transaction.sourceBlockNumber = txSent.blockNumber;
257
+ transaction.sourceTransactionHash = txSent.hash;
258
+ transaction.status = "failed";
259
+ await transaction.save();
260
+ }
261
+ net_1.protocol.sendTransaction(transaction);
262
+ }
263
+ async start() {
264
+ this.blockConfirmationsCount = constants_1.blockConfirmations[this.chainId] + 1;
265
+ this.sourceProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
266
+ this.sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, this.sourceProvider);
267
+ this.sourceGnosisContract = (0, utils_1.getContract)(constants_1.addresses[this.chainId].gnosisSafe, abi_1.default.gnosisSafe, this.sourceWallet);
268
+ await super.start();
269
+ }
270
+ }
271
+ 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[data.chainId].multisend,
109
+ data,
110
+ chainId: this.chainId,
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: this.chainId,
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;