@instadapp/interop-x 0.0.0-dev.f0a6281 → 0.0.0-dev.f39d622

Sign up to get free protection for your applications and to get access to all the features.
Files changed (308) hide show
  1. package/.github/workflows/ci.yml +19 -0
  2. package/dist/package.json +21 -13
  3. package/dist/src/abi/aaveV2Resolver.json +832 -0
  4. package/dist/src/abi/balanceResolver.json +211 -0
  5. package/dist/src/abi/connectors/index.js +36 -0
  6. package/dist/src/abi/connectors/v1/aave.js +148 -0
  7. package/dist/src/abi/connectors/v1/aave_claim.js +4 -0
  8. package/dist/src/abi/connectors/v1/aave_migrate.js +109 -0
  9. package/dist/src/abi/connectors/v1/aave_polygon_migrate.js +110 -0
  10. package/dist/src/abi/connectors/v1/aave_stake.js +4 -0
  11. package/dist/src/abi/connectors/v1/aave_v1_import.js +54 -0
  12. package/dist/src/abi/connectors/v1/aave_v2.js +230 -0
  13. package/dist/src/abi/connectors/v1/aave_v2_import.js +59 -0
  14. package/dist/src/abi/connectors/v1/authority.js +100 -0
  15. package/dist/src/abi/connectors/v1/basic.js +136 -0
  16. package/dist/src/abi/connectors/v1/chi.js +36 -0
  17. package/dist/src/abi/connectors/v1/comp.js +4 -0
  18. package/dist/src/abi/connectors/v1/compound.js +4 -0
  19. package/dist/src/abi/connectors/v1/compoundImport.js +69 -0
  20. package/dist/src/abi/connectors/v1/compoundImport_v2.js +4 -0
  21. package/dist/src/abi/connectors/v1/compound_old.js +448 -0
  22. package/dist/src/abi/connectors/v1/curve.js +140 -0
  23. package/dist/src/abi/connectors/v1/curve_claim.js +63 -0
  24. package/dist/src/abi/connectors/v1/curve_gauge.js +158 -0
  25. package/dist/src/abi/connectors/v1/curve_sbtc.js +140 -0
  26. package/dist/src/abi/connectors/v1/curve_susd.js +140 -0
  27. package/dist/src/abi/connectors/v1/curve_three.js +79 -0
  28. package/dist/src/abi/connectors/v1/curve_y.js +140 -0
  29. package/dist/src/abi/connectors/v1/dsa_migrate_v1_to_v2.js +4 -0
  30. package/dist/src/abi/connectors/v1/dydx.js +148 -0
  31. package/dist/src/abi/connectors/v1/dydx_flash.js +52 -0
  32. package/dist/src/abi/connectors/v1/fee.js +50 -0
  33. package/dist/src/abi/connectors/v1/gelato.js +1138 -0
  34. package/dist/src/abi/connectors/v1/index.js +58 -0
  35. package/dist/src/abi/connectors/v1/instapool.js +439 -0
  36. package/dist/src/abi/connectors/v1/instapool_v2.js +126 -0
  37. package/dist/src/abi/connectors/v1/kyber.js +117 -0
  38. package/dist/src/abi/connectors/v1/maker.js +480 -0
  39. package/dist/src/abi/connectors/v1/maker_old.js +300 -0
  40. package/dist/src/abi/connectors/v1/math.js +43 -0
  41. package/dist/src/abi/connectors/v1/migrate.js +46 -0
  42. package/dist/src/abi/connectors/v1/oasis.js +198 -0
  43. package/dist/src/abi/connectors/v1/oneInch.js +160 -0
  44. package/dist/src/abi/connectors/v1/polygon_bridge.js +4 -0
  45. package/dist/src/abi/connectors/v1/refinance.js +4 -0
  46. package/dist/src/abi/connectors/v1/staking.js +220 -0
  47. package/dist/src/abi/connectors/v1/swerve.js +179 -0
  48. package/dist/src/abi/connectors/v1/uniswap.js +297 -0
  49. package/dist/src/abi/connectors/v2/1INCH-A.js +4 -0
  50. package/dist/src/abi/connectors/v2/1INCH-B.js +4 -0
  51. package/dist/src/abi/connectors/v2/AAVE-CLAIM-A.js +4 -0
  52. package/dist/src/abi/connectors/v2/AAVE-CLAIM-B.js +166 -0
  53. package/dist/src/abi/connectors/v2/AAVE-STAKE-A.js +4 -0
  54. package/dist/src/abi/connectors/v2/AAVE-V1-A.js +130 -0
  55. package/dist/src/abi/connectors/v2/AAVE-V1-IMPORT-A.js +4 -0
  56. package/dist/src/abi/connectors/v2/AAVE-V2-A.js +230 -0
  57. package/dist/src/abi/connectors/v2/AAVE-V2-IMPORT-A.js +4 -0
  58. package/dist/src/abi/connectors/v2/AAVE-V2-IMPORT-B.js +225 -0
  59. package/dist/src/abi/connectors/v2/AUTHORITY-A.js +100 -0
  60. package/dist/src/abi/connectors/v2/B-COMPOUND-A.js +4 -0
  61. package/dist/src/abi/connectors/v2/B-LIQUITY-A.js +4 -0
  62. package/dist/src/abi/connectors/v2/B-MAKERDAO-A.js +4 -0
  63. package/dist/src/abi/connectors/v2/BASIC-A.js +136 -0
  64. package/dist/src/abi/connectors/v2/BASIC-B.js +4 -0
  65. package/dist/src/abi/connectors/v2/BASIC-C.js +4 -0
  66. package/dist/src/abi/connectors/v2/COMP-A.js +4 -0
  67. package/dist/src/abi/connectors/v2/COMPOUND-A.js +4 -0
  68. package/dist/src/abi/connectors/v2/COMPOUND-IMPORT-A.js +4 -0
  69. package/dist/src/abi/connectors/v2/COMPOUND-IMPORT-B.js +195 -0
  70. package/dist/src/abi/connectors/v2/G-UNISWAP-A.js +4 -0
  71. package/dist/src/abi/connectors/v2/GELATO-AAVE-A.js +4 -0
  72. package/dist/src/abi/connectors/v2/INST-A.js +4 -0
  73. package/dist/src/abi/connectors/v2/INST-LM-A.js +4 -0
  74. package/dist/src/abi/connectors/v2/INST-STAKING-A.js +4 -0
  75. package/dist/src/abi/connectors/v2/INST-STAKING-B.js +4 -0
  76. package/dist/src/abi/connectors/v2/INSTAPOOL-A.js +4 -0
  77. package/dist/src/abi/connectors/v2/LIQUITY-A.js +4 -0
  78. package/dist/src/abi/connectors/v2/MAKERDAO-A.js +4 -0
  79. package/dist/src/abi/connectors/v2/MAKERDAO-CLAIM-A.js +136 -0
  80. package/dist/src/abi/connectors/v2/PARASWAP-A.js +4 -0
  81. package/dist/src/abi/connectors/v2/POLYGON-BRIDGE-A.js +4 -0
  82. package/dist/src/abi/connectors/v2/REFINANCE-A.js +4 -0
  83. package/dist/src/abi/connectors/v2/REFLEXER-A.js +4 -0
  84. package/dist/src/abi/connectors/v2/STAKE-ERC20-A.js +4 -0
  85. package/dist/src/abi/connectors/v2/UNISWAP-A.js +297 -0
  86. package/dist/src/abi/connectors/v2/UNISWAP-V2-A.js +4 -0
  87. package/dist/src/abi/connectors/v2/UNISWAP-V3-A.js +4 -0
  88. package/dist/src/abi/connectors/v2/UNISWAP-V3-STAKE-A.js +4 -0
  89. package/dist/src/abi/connectors/v2/WETH-A.js +4 -0
  90. package/dist/src/abi/connectors/v2/YEARN-VAULT-A.js +4 -0
  91. package/dist/src/abi/connectors/v2/index.js +89 -0
  92. package/dist/src/abi/index.js +10 -4
  93. package/dist/src/abi/instList.json +232 -0
  94. package/dist/src/abi/interopX.json +1436 -0
  95. package/dist/src/alias.js +10 -0
  96. package/dist/src/api/index.js +10 -0
  97. package/dist/src/constants/addresses.js +10 -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 -1
  101. package/dist/src/constants/tokens.js +30 -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 +41 -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 +73 -0
  109. package/dist/src/gnosis/actions/aaveV2/target.js +86 -0
  110. package/dist/src/gnosis/actions/index.js +9 -0
  111. package/dist/src/gnosis/index.js +20 -0
  112. package/dist/src/index.js +8 -18
  113. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +9 -10
  114. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +2 -0
  115. package/dist/src/net/protocol/index.js +15 -5
  116. package/dist/src/services/Prices.js +74 -0
  117. package/dist/src/services/index.js +8 -0
  118. package/dist/src/tasks/InteropX/ProcessSubmitEvents.js +244 -0
  119. package/dist/src/tasks/InteropX/ProcessValidateEvents.js +184 -0
  120. package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +112 -0
  121. package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +87 -0
  122. package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +105 -0
  123. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +8 -3
  124. package/dist/src/tasks/index.js +20 -19
  125. package/dist/src/typechain/{InteropBridgeToken.js → AaveV2Resolver.js} +0 -0
  126. package/dist/src/typechain/{InteropXGateway.js → BalanceResolver.js} +0 -0
  127. package/dist/src/typechain/InstList.js +2 -0
  128. package/dist/src/typechain/InteropX.js +2 -0
  129. package/dist/src/typechain/factories/AaveV2Resolver__factory.js +1191 -0
  130. package/dist/src/typechain/factories/BalanceResolver__factory.js +228 -0
  131. package/dist/src/typechain/factories/InstList__factory.js +249 -0
  132. package/dist/src/typechain/factories/InteropX__factory.js +1928 -0
  133. package/dist/src/typechain/factories/index.js +9 -5
  134. package/dist/src/typechain/index.js +9 -5
  135. package/dist/src/utils/async.js +18 -0
  136. package/dist/src/utils/dsa.js +24 -0
  137. package/dist/src/utils/formatting.js +67 -0
  138. package/dist/src/utils/gnosis.js +62 -0
  139. package/dist/src/utils/http.js +10 -0
  140. package/dist/src/utils/index.js +22 -235
  141. package/dist/src/utils/interop.js +16 -0
  142. package/dist/src/utils/tokens.js +22 -0
  143. package/dist/src/utils/validate.js +111 -0
  144. package/dist/src/utils/web3.js +93 -0
  145. package/package.json +21 -13
  146. package/src/abi/aaveV2Resolver.json +832 -0
  147. package/src/abi/balanceResolver.json +211 -0
  148. package/src/abi/connectors/index.ts +14 -0
  149. package/src/abi/connectors/v1/aave.ts +147 -0
  150. package/src/abi/connectors/v1/aave_claim.ts +3 -0
  151. package/src/abi/connectors/v1/aave_migrate.ts +108 -0
  152. package/src/abi/connectors/v1/aave_polygon_migrate.ts +109 -0
  153. package/src/abi/connectors/v1/aave_stake.ts +3 -0
  154. package/src/abi/connectors/v1/aave_v1_import.ts +53 -0
  155. package/src/abi/connectors/v1/aave_v2.ts +229 -0
  156. package/src/abi/connectors/v1/aave_v2_import.ts +58 -0
  157. package/src/abi/connectors/v1/authority.ts +99 -0
  158. package/src/abi/connectors/v1/basic.ts +135 -0
  159. package/src/abi/connectors/v1/chi.ts +35 -0
  160. package/src/abi/connectors/v1/comp.ts +3 -0
  161. package/src/abi/connectors/v1/compound.ts +3 -0
  162. package/src/abi/connectors/v1/compoundImport.ts +68 -0
  163. package/src/abi/connectors/v1/compoundImport_v2.ts +3 -0
  164. package/src/abi/connectors/v1/compound_old.ts +447 -0
  165. package/src/abi/connectors/v1/curve.ts +139 -0
  166. package/src/abi/connectors/v1/curve_claim.ts +62 -0
  167. package/src/abi/connectors/v1/curve_gauge.ts +157 -0
  168. package/src/abi/connectors/v1/curve_sbtc.ts +139 -0
  169. package/src/abi/connectors/v1/curve_susd.ts +139 -0
  170. package/src/abi/connectors/v1/curve_three.ts +78 -0
  171. package/src/abi/connectors/v1/curve_y.ts +139 -0
  172. package/src/abi/connectors/v1/dsa_migrate_v1_to_v2.ts +3 -0
  173. package/src/abi/connectors/v1/dydx.ts +147 -0
  174. package/src/abi/connectors/v1/dydx_flash.ts +51 -0
  175. package/src/abi/connectors/v1/fee.ts +49 -0
  176. package/src/abi/connectors/v1/gelato.ts +1137 -0
  177. package/src/abi/connectors/v1/index.ts +42 -0
  178. package/src/abi/connectors/v1/instapool.ts +438 -0
  179. package/src/abi/connectors/v1/instapool_v2.ts +125 -0
  180. package/src/abi/connectors/v1/kyber.ts +116 -0
  181. package/src/abi/connectors/v1/maker.ts +479 -0
  182. package/src/abi/connectors/v1/maker_old.ts +299 -0
  183. package/src/abi/connectors/v1/math.ts +42 -0
  184. package/src/abi/connectors/v1/migrate.ts +45 -0
  185. package/src/abi/connectors/v1/oasis.ts +197 -0
  186. package/src/abi/connectors/v1/oneInch.ts +159 -0
  187. package/src/abi/connectors/v1/polygon_bridge.ts +3 -0
  188. package/src/abi/connectors/v1/refinance.ts +3 -0
  189. package/src/abi/connectors/v1/staking.ts +219 -0
  190. package/src/abi/connectors/v1/swerve.ts +178 -0
  191. package/src/abi/connectors/v1/uniswap.ts +297 -0
  192. package/src/abi/connectors/v2/1INCH-A.ts +3 -0
  193. package/src/abi/connectors/v2/1INCH-B.ts +3 -0
  194. package/src/abi/connectors/v2/AAVE-CLAIM-A.ts +3 -0
  195. package/src/abi/connectors/v2/AAVE-CLAIM-B.ts +165 -0
  196. package/src/abi/connectors/v2/AAVE-STAKE-A.ts +3 -0
  197. package/src/abi/connectors/v2/AAVE-V1-A.ts +130 -0
  198. package/src/abi/connectors/v2/AAVE-V1-IMPORT-A.ts +3 -0
  199. package/src/abi/connectors/v2/AAVE-V2-A.ts +229 -0
  200. package/src/abi/connectors/v2/AAVE-V2-IMPORT-A.ts +3 -0
  201. package/src/abi/connectors/v2/AAVE-V2-IMPORT-B.ts +224 -0
  202. package/src/abi/connectors/v2/AUTHORITY-A.ts +99 -0
  203. package/src/abi/connectors/v2/B-COMPOUND-A.ts +3 -0
  204. package/src/abi/connectors/v2/B-LIQUITY-A.ts +3 -0
  205. package/src/abi/connectors/v2/B-MAKERDAO-A.ts +3 -0
  206. package/src/abi/connectors/v2/BASIC-A.ts +135 -0
  207. package/src/abi/connectors/v2/BASIC-B.ts +3 -0
  208. package/src/abi/connectors/v2/BASIC-C.ts +3 -0
  209. package/src/abi/connectors/v2/COMP-A.ts +3 -0
  210. package/src/abi/connectors/v2/COMPOUND-A.ts +3 -0
  211. package/src/abi/connectors/v2/COMPOUND-IMPORT-A.ts +3 -0
  212. package/src/abi/connectors/v2/COMPOUND-IMPORT-B.ts +194 -0
  213. package/src/abi/connectors/v2/G-UNISWAP-A.ts +3 -0
  214. package/src/abi/connectors/v2/GELATO-AAVE-A.ts +3 -0
  215. package/src/abi/connectors/v2/INST-A.ts +3 -0
  216. package/src/abi/connectors/v2/INST-LM-A.ts +3 -0
  217. package/src/abi/connectors/v2/INST-STAKING-A.ts +3 -0
  218. package/src/abi/connectors/v2/INST-STAKING-B.ts +3 -0
  219. package/src/abi/connectors/v2/INSTAPOOL-A.ts +3 -0
  220. package/src/abi/connectors/v2/LIQUITY-A.ts +3 -0
  221. package/src/abi/connectors/v2/MAKERDAO-A.ts +3 -0
  222. package/src/abi/connectors/v2/MAKERDAO-CLAIM-A.ts +135 -0
  223. package/src/abi/connectors/v2/PARASWAP-A.ts +3 -0
  224. package/src/abi/connectors/v2/POLYGON-BRIDGE-A.ts +3 -0
  225. package/src/abi/connectors/v2/REFINANCE-A.ts +3 -0
  226. package/src/abi/connectors/v2/REFLEXER-A.ts +3 -0
  227. package/src/abi/connectors/v2/STAKE-ERC20-A.ts +3 -0
  228. package/src/abi/connectors/v2/UNISWAP-A.ts +297 -0
  229. package/src/abi/connectors/v2/UNISWAP-V2-A.ts +3 -0
  230. package/src/abi/connectors/v2/UNISWAP-V3-A.ts +3 -0
  231. package/src/abi/connectors/v2/UNISWAP-V3-STAKE-A.ts +3 -0
  232. package/src/abi/connectors/v2/WETH-A.ts +3 -0
  233. package/src/abi/connectors/v2/YEARN-VAULT-A.ts +3 -0
  234. package/src/abi/connectors/v2/index.ts +87 -0
  235. package/src/abi/index.ts +13 -7
  236. package/src/abi/instList.json +232 -0
  237. package/src/abi/interopX.json +1436 -0
  238. package/src/alias.ts +6 -0
  239. package/src/api/index.ts +11 -0
  240. package/src/constants/addresses.ts +21 -8
  241. package/src/constants/blockConfirmations.ts +5 -0
  242. package/src/constants/capPerChain.ts +5 -0
  243. package/src/constants/index.ts +3 -1
  244. package/src/constants/tokens.ts +31 -8
  245. package/src/constants/wrappedNativeToken.ts +5 -0
  246. package/src/crons/index.ts +1 -0
  247. package/src/crons/prices.ts +12 -0
  248. package/src/db/models/transaction.ts +159 -65
  249. package/src/errors/index.ts +26 -0
  250. package/src/gnosis/actions/aaveV2/index.ts +9 -0
  251. package/src/gnosis/actions/aaveV2/source.ts +118 -0
  252. package/src/gnosis/actions/aaveV2/target.ts +141 -0
  253. package/src/gnosis/actions/index.ts +5 -0
  254. package/src/gnosis/index.ts +19 -0
  255. package/src/index.ts +7 -17
  256. package/src/net/protocol/dial/SignatureDialProtocol.ts +12 -13
  257. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +3 -1
  258. package/src/net/protocol/index.ts +16 -6
  259. package/src/services/Prices.ts +89 -0
  260. package/src/services/index.ts +1 -0
  261. package/src/tasks/InteropX/ProcessSubmitEvents.ts +344 -0
  262. package/src/tasks/InteropX/ProcessValidateEvents.ts +271 -0
  263. package/src/tasks/InteropX/SyncLogExecuteEvents.ts +160 -0
  264. package/src/tasks/InteropX/SyncLogSubmitEvents.ts +137 -0
  265. package/src/tasks/InteropX/SyncLogValidateEvents.ts +150 -0
  266. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +8 -3
  267. package/src/tasks/index.ts +25 -20
  268. package/src/typechain/AaveV2Resolver.ts +1017 -0
  269. package/src/typechain/BalanceResolver.ts +266 -0
  270. package/src/typechain/InstList.ts +402 -0
  271. package/src/typechain/InteropX.ts +1216 -0
  272. package/src/typechain/factories/AaveV2Resolver__factory.ts +1198 -0
  273. package/src/typechain/factories/BalanceResolver__factory.ts +235 -0
  274. package/src/typechain/factories/InstList__factory.ts +253 -0
  275. package/src/typechain/factories/InteropX__factory.ts +1932 -0
  276. package/src/typechain/factories/index.ts +4 -2
  277. package/src/typechain/index.ts +8 -4
  278. package/src/utils/async.ts +22 -0
  279. package/src/utils/dsa.ts +30 -0
  280. package/src/utils/formatting.ts +68 -0
  281. package/src/utils/gnosis.ts +123 -0
  282. package/src/utils/http.ts +6 -0
  283. package/src/utils/index.ts +9 -319
  284. package/src/utils/interop.ts +28 -0
  285. package/src/utils/tokens.ts +21 -0
  286. package/src/utils/validate.ts +173 -0
  287. package/src/utils/web3.ts +132 -0
  288. package/tsconfig.json +7 -2
  289. package/dist/src/abi/interopBridgeToken.json +0 -298
  290. package/dist/src/abi/interopXGateway.json +0 -184
  291. package/dist/src/constants/itokens.js +0 -13
  292. package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +0 -146
  293. package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +0 -71
  294. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +0 -161
  295. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -74
  296. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -471
  297. package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
  298. package/src/abi/interopBridgeToken.json +0 -298
  299. package/src/abi/interopXGateway.json +0 -184
  300. package/src/constants/itokens.ts +0 -10
  301. package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +0 -231
  302. package/src/tasks/InteropBridge/SyncWithdrawEvents.ts +0 -121
  303. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -256
  304. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -124
  305. package/src/typechain/InteropBridgeToken.ts +0 -692
  306. package/src/typechain/InteropXGateway.ts +0 -407
  307. package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -478
  308. package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -10,12 +10,17 @@ const config_1 = __importDefault(require("@/config"));
10
10
  const db_1 = require("@/db");
11
11
  const utils_1 = require("@/utils");
12
12
  const constants_1 = require("@/constants");
13
+ const gnosis_1 = require("@/gnosis");
13
14
  class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
14
15
  constructor(libp2p) {
15
16
  super(libp2p, '/interop-x/signatures');
16
17
  this.timeout = 30000;
17
18
  }
18
19
  async response(data) {
20
+ console.log({
21
+ tag: 'SignatureDialProtocol',
22
+ data
23
+ });
19
24
  const signer = config_1.default.wallet;
20
25
  let transaction;
21
26
  let maxTimeout = 20000;
@@ -33,17 +38,11 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
33
38
  error: 'Event not found'
34
39
  };
35
40
  }
36
- console.log("signing:", {
37
- to: constants_1.addresses[transaction.targetChainId].multisend,
38
- data: await (0, utils_1.buildDataForTransaction)(transaction, data.type),
39
- chainId: transaction.targetChainId,
40
- safeTxGas: data.safeTxGas,
41
- nonce: data.safeNonce,
42
- });
41
+ const { data: gnosisData } = await (0, gnosis_1.buildGnosisAction)(transaction, data.type);
43
42
  const signedData = await (0, utils_1.signGnosisSafeTx)({
44
- to: constants_1.addresses[transaction.targetChainId].multisend,
45
- data: await (0, utils_1.buildDataForTransaction)(transaction, data.type),
46
- chainId: transaction.targetChainId,
43
+ to: constants_1.addresses[data.chainId].multisend,
44
+ data: gnosisData,
45
+ chainId: data.chainId,
47
46
  safeTxGas: data.safeTxGas,
48
47
  nonce: data.safeNonce,
49
48
  }, { signer });
@@ -18,9 +18,11 @@ class TransactionStatusDialProtocol extends BaseDialProtocol_1.BaseDialProtocol
18
18
  sourceStatus: transaction.sourceStatus,
19
19
  sourceTransactionHash: transaction.sourceTransactionHash,
20
20
  sourceErrors: transaction.sourceErrors,
21
+ sourceLogs: transaction.sourceLogs,
21
22
  targetStatus: transaction.targetStatus,
22
23
  targetTransactionHash: transaction.targetTransactionHash,
23
24
  targetErrors: transaction.targetErrors,
25
+ targetLogs: transaction.targetLogs,
24
26
  status: transaction.status,
25
27
  };
26
28
  }
@@ -31,21 +31,31 @@ class Protocol extends stream_1.EventEmitter {
31
31
  encode: (transaction) => [
32
32
  Buffer.from(transaction.transactionHash),
33
33
  Buffer.from(transaction.sourceStatus),
34
- Buffer.from(transaction.sourceTransactionHash),
34
+ Buffer.from(transaction.sourceTransactionHash || ''),
35
35
  transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
36
+ transaction.sourceLogs ? transaction.sourceLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
36
37
  Buffer.from(transaction.targetStatus),
37
- Buffer.from(transaction.targetTransactionHash),
38
+ Buffer.from(transaction.targetTransactionHash || ''),
38
39
  transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
40
+ transaction.targetLogs ? transaction.targetLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
39
41
  Buffer.from(transaction.status),
40
42
  ],
41
- decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, targetStatus, targetTransactionHash, targetErrors, status]) => ({
43
+ decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, sourceLogs, targetStatus, targetTransactionHash, targetErrors, targetLogs, status]) => ({
42
44
  transactionHash: transactionHash.toString(),
43
45
  sourceStatus: sourceStatus.toString(),
44
- sourceTransactionHash: sourceTransactionHash.toString(),
46
+ sourceTransactionHash: sourceTransactionHash.toString() || null,
45
47
  sourceErrors: sourceErrors.map((e) => e.toString()),
48
+ sourceLogs: sourceLogs.map(e => ({
49
+ type: e[0].toString(),
50
+ message: e[1].toString(),
51
+ })),
46
52
  targetStatus: targetStatus.toString(),
47
- targetTransactionHash: targetTransactionHash.toString(),
53
+ targetTransactionHash: targetTransactionHash.toString() || null,
48
54
  targetErrors: targetErrors.map((e) => e.toString()),
55
+ targetLogs: targetLogs.map(e => ({
56
+ type: e[0].toString(),
57
+ message: e[1].toString(),
58
+ })),
49
59
  status: status.toString(),
50
60
  }),
51
61
  },
@@ -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,244 @@
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
+ class ProcessSubmitEvents extends BaseTask_1.BaseTask {
23
+ constructor({ chainId }) {
24
+ super({
25
+ logger: new logger_1.default("InteropX::ProcessSubmitEvents"),
26
+ });
27
+ this.leadNodeOnly = true;
28
+ this.blockConfirmationsCount = 12;
29
+ this.chainId = chainId;
30
+ }
31
+ async pollHandler() {
32
+ var _a;
33
+ const currentBlockNumber = await this.sourceProvider.getBlockNumber();
34
+ const transaction = await db_1.Transaction.findOne({
35
+ where: {
36
+ status: "pending",
37
+ sourceStatus: "pending",
38
+ sourceChainId: this.chainId,
39
+ submitBlockNumber: {
40
+ [sequelize_1.Op.lt]: currentBlockNumber - this.blockConfirmationsCount,
41
+ },
42
+ sourceDelayUntil: {
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
+ createdAt: {
50
+ [sequelize_1.Op.gt]: (0, moment_1.default)().subtract({ hours: 12 }).toDate(),
51
+ },
52
+ },
53
+ });
54
+ if (!transaction) {
55
+ return;
56
+ }
57
+ this.logger.debug(`Processing transaction ${transaction.transactionHash}`);
58
+ transaction.sourceStatus = "proccessing";
59
+ await transaction.save();
60
+ const { submitEvent: { position, sourceChainId, targetChainId } } = transaction;
61
+ try {
62
+ (0, utils_1.validateChains)({ sourceChainId, targetChainId });
63
+ }
64
+ catch (error) {
65
+ transaction.sourceErrors = [error.message];
66
+ transaction.sourceStatus = "failed";
67
+ transaction.targetStatus = "failed";
68
+ transaction.status = "failed";
69
+ await transaction.save();
70
+ return;
71
+ }
72
+ const walletBalance = (await this.sourceWallet.getBalance()).toString();
73
+ const currentGasPrice = (await this.sourceWallet.getGasPrice()).toString();
74
+ const minBalanceRequired = new bignumber_js_1.BigNumber(currentGasPrice)
75
+ .multipliedBy(4000000)
76
+ .multipliedBy(2); // 2x balance
77
+ if (new bignumber_js_1.BigNumber(walletBalance).isLessThan(minBalanceRequired)) {
78
+ 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)}
79
+ Balance: ${ethers_1.ethers.utils.parseEther(walletBalance)} ${(0, utils_1.getChainIdNativeSymbol)(sourceChainId)}
80
+ Required Balance: ${ethers_1.ethers.utils.parseEther(minBalanceRequired.toString())}
81
+ Require more: ${ethers_1.ethers.utils.parseEther(minBalanceRequired.minus(walletBalance).toString())}`);
82
+ transaction.sourceDelayUntil = (0, moment_1.default)().add({ minutes: 5 }).toDate();
83
+ transaction.sourceStatus = "pending";
84
+ await transaction.save();
85
+ return;
86
+ }
87
+ try {
88
+ await (0, utils_1.validateLiquidityCap)(position, sourceChainId, targetChainId);
89
+ }
90
+ catch (error) {
91
+ transaction.sourceErrors = [error.message];
92
+ transaction.sourceStatus = "failed";
93
+ transaction.targetStatus = "failed";
94
+ transaction.status = "failed";
95
+ await transaction.save();
96
+ return;
97
+ }
98
+ try {
99
+ await (0, utils_1.validateSourceLiquidity)({
100
+ position,
101
+ sourceChainId,
102
+ sourceProvider: this.sourceProvider,
103
+ });
104
+ }
105
+ catch (error) {
106
+ if (error instanceof errors_1.UnsupportedChaindIdError) {
107
+ console.log(`Dropping transaction ${transaction.transactionHash}`);
108
+ transaction.sourceErrors = [error.message];
109
+ transaction.sourceStatus = "failed";
110
+ transaction.targetStatus = "failed";
111
+ transaction.status = "failed";
112
+ await transaction.save();
113
+ }
114
+ else {
115
+ transaction.sourceStatus = "pending";
116
+ transaction.sourceDelayUntil = (0, moment_1.default)().add({ minutes: 5 }).toDate();
117
+ await transaction.save();
118
+ console.log("[validateSourceLiquidity][Warning]", error.message);
119
+ return;
120
+ }
121
+ }
122
+ const ownersThreshold = await this.sourceGnosisContract.getThreshold();
123
+ await (0, waait_1.default)(10000);
124
+ this.logger.debug(`Build gnosis action for ${transaction.transactionHash}`);
125
+ let data, logs = [];
126
+ try {
127
+ ({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction, "source"));
128
+ }
129
+ catch (error) {
130
+ if (error instanceof errors_1.LiquidityError) {
131
+ await transaction.save();
132
+ transaction.sourceDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
133
+ transaction.sourceStatus = "pending";
134
+ await transaction.save();
135
+ throw error;
136
+ return;
137
+ }
138
+ transaction.sourceStatus = "failed";
139
+ transaction.sourceErrors = [error.message];
140
+ transaction.targetStatus = "failed";
141
+ transaction.status = "failed";
142
+ await transaction.save();
143
+ net_1.protocol.sendTransaction(transaction);
144
+ return;
145
+ }
146
+ this.logger.debug(`Generating gnosis tx for ${transaction.transactionHash}`);
147
+ let gnosisTx = await (0, utils_1.generateGnosisTransaction)({
148
+ baseGas: "0",
149
+ data,
150
+ gasPrice: "0",
151
+ gasToken: "0x0000000000000000000000000000000000000000",
152
+ nonce: "0",
153
+ operation: "1",
154
+ refundReceiver: "0x0000000000000000000000000000000000000000",
155
+ safeAddress: this.sourceGnosisContract.address,
156
+ safeTxGas: "79668",
157
+ to: constants_1.addresses[transaction.sourceChainId].multisend,
158
+ value: "0",
159
+ }, this.sourceGnosisContract);
160
+ const owners = await this.sourceGnosisContract
161
+ .getOwners()
162
+ .then((owners) => owners.map((owner) => owner.toLowerCase()));
163
+ const ownerPeerIds = net_1.peerPool.activePeers
164
+ .filter((peer) => owners.includes(peer.publicAddress.toLowerCase()))
165
+ .map((peer) => peer.id);
166
+ console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
167
+ console.log(ownerPeerIds);
168
+ const signatures = await net_1.protocol.requestSignatures({
169
+ type: "source",
170
+ transactionHash: transaction.transactionHash,
171
+ safeTxGas: gnosisTx.safeTxGas,
172
+ safeNonce: gnosisTx.nonce,
173
+ chainId: this.chainId,
174
+ }, ownerPeerIds);
175
+ const validSignatures = signatures.filter((s) => !!s.data && s.data !== "0x");
176
+ console.log({
177
+ signatures,
178
+ validSignatures,
179
+ ownersThreshold: ownersThreshold.toString(),
180
+ });
181
+ if (validSignatures.length === 0 ||
182
+ ownersThreshold.gt(validSignatures.length)) {
183
+ await transaction.save();
184
+ transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
185
+ transaction.sourceStatus = "pending";
186
+ await transaction.save();
187
+ const errorMessage = (_a = signatures.find((s) => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
188
+ throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ""));
189
+ }
190
+ console.log(`Executing transaction for execution ${transaction.transactionHash}`);
191
+ 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));
192
+ const [gasPrice, gasLimit] = await Promise.all([
193
+ this.sourceProvider.getGasPrice(),
194
+ this.sourceProvider.estimateGas({
195
+ from: this.sourceWallet.address,
196
+ to: this.sourceGnosisContract.address,
197
+ data: txData,
198
+ }),
199
+ ]);
200
+ const txSent = await this.sourceWallet.sendTransaction({
201
+ from: this.sourceWallet.address,
202
+ to: this.sourceGnosisContract.address,
203
+ gasPrice: gasPrice.mul(120).div(100),
204
+ gasLimit: 5000000,
205
+ data: txData,
206
+ });
207
+ console.log(txSent);
208
+ const receipt = await txSent.wait();
209
+ const parsedLogs = [];
210
+ receipt.logs.forEach((log) => {
211
+ try {
212
+ parsedLogs.push(this.sourceGnosisContract.interface.parseLog(log));
213
+ }
214
+ catch (e) { }
215
+ });
216
+ if (parsedLogs.find((e) => e.name === "ExecutionSuccess")) {
217
+ console.log("ExecutionSuccess");
218
+ transaction.sourceStatus = "success";
219
+ if (txSent.blockNumber)
220
+ transaction.sourceBlockNumber = txSent.blockNumber;
221
+ transaction.sourceTransactionHash = txSent.hash;
222
+ transaction.sourceLogs = logs;
223
+ await transaction.save();
224
+ }
225
+ else {
226
+ console.log("ExecutionFailure");
227
+ transaction.sourceStatus = "failed";
228
+ if (txSent.blockNumber)
229
+ transaction.sourceBlockNumber = txSent.blockNumber;
230
+ transaction.sourceTransactionHash = txSent.hash;
231
+ transaction.status = "failed";
232
+ await transaction.save();
233
+ }
234
+ net_1.protocol.sendTransaction(transaction);
235
+ }
236
+ async start() {
237
+ this.blockConfirmationsCount = constants_1.blockConfirmations[this.chainId] + 1;
238
+ this.sourceProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
239
+ this.sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, this.sourceProvider);
240
+ this.sourceGnosisContract = (0, utils_1.getContract)(constants_1.addresses[this.chainId].gnosisSafe, abi_1.default.gnosisSafe, this.sourceWallet);
241
+ await super.start();
242
+ }
243
+ }
244
+ exports.default = ProcessSubmitEvents;
@@ -0,0 +1,184 @@
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
+ class ProcessValidateEvents extends BaseTask_1.BaseTask {
21
+ constructor({ chainId }) {
22
+ super({
23
+ logger: new logger_1.default("InteropX::ProcessValidateEvents"),
24
+ });
25
+ this.leadNodeOnly = true;
26
+ this.blockConfirmationsCount = 12;
27
+ this.chainId = chainId;
28
+ }
29
+ async pollHandler() {
30
+ var _a;
31
+ const currentBlockNumber = await this.sourceProvider.getBlockNumber();
32
+ const transaction = await db_1.Transaction.findOne({
33
+ where: {
34
+ status: "pending",
35
+ sourceStatus: "success",
36
+ targetStatus: "pending",
37
+ sourceChainId: this.chainId,
38
+ sourceBlockNumber: {
39
+ [sequelize_1.Op.lt]: currentBlockNumber - this.blockConfirmationsCount,
40
+ },
41
+ targetDelayUntil: {
42
+ [sequelize_1.Op.or]: {
43
+ [sequelize_1.Op.is]: null,
44
+ [sequelize_1.Op.lt]: new Date(),
45
+ },
46
+ },
47
+ submitEvent: { $ne: null },
48
+ validateEvent: { $ne: null },
49
+ createdAt: {
50
+ [sequelize_1.Op.gt]: (0, moment_1.default)().subtract({ hours: 12 }).toDate(),
51
+ },
52
+ },
53
+ });
54
+ if (!transaction) {
55
+ return;
56
+ }
57
+ this.logger.debug(`Processing transaction ${transaction.transactionHash}`);
58
+ transaction.targetStatus = "proccessing";
59
+ await transaction.save();
60
+ const { sourceChainId, targetChainId } = transaction.validateEvent;
61
+ const targetProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
62
+ const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetProvider);
63
+ const targetGnosisContract = (0, utils_1.getContract)(constants_1.addresses[targetChainId].gnosisSafe, abi_1.default.gnosisSafe, targetWallet);
64
+ const ownersThreshold = await targetGnosisContract.getThreshold();
65
+ await (0, waait_1.default)(10000);
66
+ this.logger.debug(`Build gnosis action for ${transaction.transactionHash}`);
67
+ let data, logs = [];
68
+ try {
69
+ ({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction, "target"));
70
+ }
71
+ catch (error) {
72
+ if (error instanceof errors_1.LiquidityError) {
73
+ await transaction.save();
74
+ transaction.targetDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
75
+ transaction.targetStatus = "pending";
76
+ await transaction.save();
77
+ throw error;
78
+ return;
79
+ }
80
+ transaction.targetStatus = "failed";
81
+ transaction.targetErrors = [error.message];
82
+ transaction.status = "failed";
83
+ await transaction.save();
84
+ net_1.protocol.sendTransaction(transaction);
85
+ return;
86
+ }
87
+ this.logger.debug(`Generating gnosis tx for ${transaction.transactionHash}`);
88
+ let gnosisTx = await (0, utils_1.generateGnosisTransaction)({
89
+ baseGas: "0",
90
+ data,
91
+ gasPrice: "0",
92
+ gasToken: "0x0000000000000000000000000000000000000000",
93
+ nonce: "0",
94
+ operation: "1",
95
+ refundReceiver: "0x0000000000000000000000000000000000000000",
96
+ safeAddress: targetGnosisContract.address,
97
+ safeTxGas: "79668",
98
+ to: constants_1.addresses[transaction.targetChainId].multisend,
99
+ value: "0",
100
+ }, targetGnosisContract);
101
+ const owners = await targetGnosisContract
102
+ .getOwners()
103
+ .then((owners) => owners.map((owner) => owner.toLowerCase()));
104
+ const ownerPeerIds = net_1.peerPool.activePeers
105
+ .filter((peer) => owners.includes(peer.publicAddress.toLowerCase()))
106
+ .map((peer) => peer.id);
107
+ console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
108
+ console.log(ownerPeerIds);
109
+ const signatures = await net_1.protocol.requestSignatures({
110
+ type: "target",
111
+ transactionHash: transaction.transactionHash,
112
+ safeTxGas: gnosisTx.safeTxGas,
113
+ safeNonce: gnosisTx.nonce,
114
+ chainId: targetChainId,
115
+ }, ownerPeerIds);
116
+ const validSignatures = signatures.filter((s) => !!s.data && s.data !== "0x");
117
+ console.log({
118
+ signatures,
119
+ validSignatures,
120
+ ownersThreshold: ownersThreshold.toString(),
121
+ });
122
+ if (validSignatures.length === 0 ||
123
+ ownersThreshold.gt(validSignatures.length)) {
124
+ await transaction.save();
125
+ transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
126
+ transaction.targetStatus = "pending";
127
+ await transaction.save();
128
+ const errorMessage = (_a = signatures.find((s) => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
129
+ throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ""));
130
+ }
131
+ console.log(`Executing transaction for execution ${transaction.transactionHash}`);
132
+ 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));
133
+ const [gasPrice, gasLimit] = await Promise.all([
134
+ targetProvider.getGasPrice(),
135
+ targetProvider.estimateGas({
136
+ from: targetWallet.address,
137
+ to: targetGnosisContract.address,
138
+ data: txData,
139
+ }),
140
+ ]);
141
+ const txSent = await targetWallet.sendTransaction({
142
+ from: targetWallet.address,
143
+ to: targetGnosisContract.address,
144
+ gasPrice: gasPrice.mul(120).div(100),
145
+ gasLimit: 5000000,
146
+ data: txData,
147
+ });
148
+ console.log(txSent);
149
+ const receipt = await txSent.wait();
150
+ const parsedLogs = [];
151
+ receipt.logs.forEach((log) => {
152
+ try {
153
+ parsedLogs.push(targetGnosisContract.interface.parseLog(log));
154
+ }
155
+ catch (e) { }
156
+ });
157
+ if (parsedLogs.find((e) => e.name === "ExecutionSuccess")) {
158
+ console.log("ExecutionSuccess");
159
+ transaction.targetStatus = "success";
160
+ transaction.status = "success";
161
+ if (txSent.blockNumber)
162
+ transaction.targetBlockNumber = txSent.blockNumber;
163
+ transaction.targetTransactionHash = txSent.hash;
164
+ transaction.targetLogs = logs;
165
+ await transaction.save();
166
+ }
167
+ else {
168
+ console.log("ExecutionFailure");
169
+ transaction.targetStatus = "failed";
170
+ if (txSent.blockNumber)
171
+ transaction.targetBlockNumber = txSent.blockNumber;
172
+ transaction.targetTransactionHash = txSent.hash;
173
+ transaction.status = "failed";
174
+ await transaction.save();
175
+ }
176
+ net_1.protocol.sendTransaction(transaction);
177
+ }
178
+ async start() {
179
+ this.blockConfirmationsCount = constants_1.blockConfirmations[this.chainId] + 1;
180
+ this.sourceProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
181
+ await super.start();
182
+ }
183
+ }
184
+ exports.default = ProcessValidateEvents;