@instadapp/interop-x 0.0.0-dev.59f84ce → 0.0.0-dev.5a90c8d

Sign up to get free protection for your applications and to get access to all the features.
Files changed (295) hide show
  1. package/.github/workflows/ci.yml +19 -0
  2. package/dist/package.json +22 -12
  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 -2
  93. package/dist/src/abi/instList.json +232 -0
  94. package/dist/src/abi/interopX.json +1436 -0
  95. package/dist/src/api/index.js +8 -1
  96. package/dist/src/constants/addresses.js +10 -7
  97. package/dist/src/constants/blockConfirmations.js +8 -0
  98. package/dist/src/constants/capPerChain.js +8 -0
  99. package/dist/src/constants/index.js +3 -0
  100. package/dist/src/constants/tokens.js +30 -7
  101. package/dist/src/constants/wrappedNativeToken.js +8 -0
  102. package/dist/src/crons/index.js +3 -0
  103. package/dist/src/crons/prices.js +16 -0
  104. package/dist/src/db/models/transaction.js +25 -17
  105. package/dist/src/errors/index.js +30 -0
  106. package/dist/src/gnosis/actions/aaveV2/index.js +11 -0
  107. package/dist/src/gnosis/actions/aaveV2/source.js +74 -0
  108. package/dist/src/gnosis/actions/aaveV2/target.js +87 -0
  109. package/dist/src/gnosis/actions/index.js +2 -2
  110. package/dist/src/gnosis/index.js +4 -4
  111. package/dist/src/index.js +5 -2
  112. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +6 -2
  113. package/dist/src/providers/index.js +17 -0
  114. package/dist/src/providers/retry-provider.js +45 -0
  115. package/dist/src/services/Prices.js +74 -0
  116. package/dist/src/services/index.js +8 -0
  117. package/dist/src/tasks/InteropX/ProcessSubmitEvents.js +245 -0
  118. package/dist/src/tasks/InteropX/ProcessValidateEvents.js +185 -0
  119. package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +113 -0
  120. package/dist/src/tasks/{InteropXContract/SyncBridgeRequestEvents.js → InteropX/SyncLogSubmitEvents.js} +29 -19
  121. package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +106 -0
  122. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +6 -3
  123. package/dist/src/tasks/index.js +20 -8
  124. package/dist/src/typechain/{InteropXContract.js → AaveV2Resolver.js} +0 -0
  125. package/dist/src/typechain/BalanceResolver.js +2 -0
  126. package/dist/src/typechain/InstList.js +2 -0
  127. package/dist/src/typechain/InteropX.js +2 -0
  128. package/dist/src/typechain/factories/AaveV2Resolver__factory.js +1191 -0
  129. package/dist/src/typechain/factories/BalanceResolver__factory.js +228 -0
  130. package/dist/src/typechain/factories/InstList__factory.js +249 -0
  131. package/dist/src/typechain/factories/InteropX__factory.js +1928 -0
  132. package/dist/src/typechain/factories/index.js +9 -3
  133. package/dist/src/typechain/index.js +9 -3
  134. package/dist/src/utils/async.js +18 -0
  135. package/dist/src/utils/dsa.js +24 -0
  136. package/dist/src/utils/formatting.js +67 -0
  137. package/dist/src/utils/gnosis.js +62 -0
  138. package/dist/src/utils/http.js +10 -0
  139. package/dist/src/utils/index.js +22 -165
  140. package/dist/src/utils/interop.js +16 -0
  141. package/dist/src/utils/tokens.js +22 -0
  142. package/dist/src/utils/validate.js +111 -0
  143. package/dist/src/utils/web3.js +93 -0
  144. package/package.json +22 -12
  145. package/src/abi/aaveV2Resolver.json +832 -0
  146. package/src/abi/balanceResolver.json +211 -0
  147. package/src/abi/connectors/index.ts +14 -0
  148. package/src/abi/connectors/v1/aave.ts +147 -0
  149. package/src/abi/connectors/v1/aave_claim.ts +3 -0
  150. package/src/abi/connectors/v1/aave_migrate.ts +108 -0
  151. package/src/abi/connectors/v1/aave_polygon_migrate.ts +109 -0
  152. package/src/abi/connectors/v1/aave_stake.ts +3 -0
  153. package/src/abi/connectors/v1/aave_v1_import.ts +53 -0
  154. package/src/abi/connectors/v1/aave_v2.ts +229 -0
  155. package/src/abi/connectors/v1/aave_v2_import.ts +58 -0
  156. package/src/abi/connectors/v1/authority.ts +99 -0
  157. package/src/abi/connectors/v1/basic.ts +135 -0
  158. package/src/abi/connectors/v1/chi.ts +35 -0
  159. package/src/abi/connectors/v1/comp.ts +3 -0
  160. package/src/abi/connectors/v1/compound.ts +3 -0
  161. package/src/abi/connectors/v1/compoundImport.ts +68 -0
  162. package/src/abi/connectors/v1/compoundImport_v2.ts +3 -0
  163. package/src/abi/connectors/v1/compound_old.ts +447 -0
  164. package/src/abi/connectors/v1/curve.ts +139 -0
  165. package/src/abi/connectors/v1/curve_claim.ts +62 -0
  166. package/src/abi/connectors/v1/curve_gauge.ts +157 -0
  167. package/src/abi/connectors/v1/curve_sbtc.ts +139 -0
  168. package/src/abi/connectors/v1/curve_susd.ts +139 -0
  169. package/src/abi/connectors/v1/curve_three.ts +78 -0
  170. package/src/abi/connectors/v1/curve_y.ts +139 -0
  171. package/src/abi/connectors/v1/dsa_migrate_v1_to_v2.ts +3 -0
  172. package/src/abi/connectors/v1/dydx.ts +147 -0
  173. package/src/abi/connectors/v1/dydx_flash.ts +51 -0
  174. package/src/abi/connectors/v1/fee.ts +49 -0
  175. package/src/abi/connectors/v1/gelato.ts +1137 -0
  176. package/src/abi/connectors/v1/index.ts +42 -0
  177. package/src/abi/connectors/v1/instapool.ts +438 -0
  178. package/src/abi/connectors/v1/instapool_v2.ts +125 -0
  179. package/src/abi/connectors/v1/kyber.ts +116 -0
  180. package/src/abi/connectors/v1/maker.ts +479 -0
  181. package/src/abi/connectors/v1/maker_old.ts +299 -0
  182. package/src/abi/connectors/v1/math.ts +42 -0
  183. package/src/abi/connectors/v1/migrate.ts +45 -0
  184. package/src/abi/connectors/v1/oasis.ts +197 -0
  185. package/src/abi/connectors/v1/oneInch.ts +159 -0
  186. package/src/abi/connectors/v1/polygon_bridge.ts +3 -0
  187. package/src/abi/connectors/v1/refinance.ts +3 -0
  188. package/src/abi/connectors/v1/staking.ts +219 -0
  189. package/src/abi/connectors/v1/swerve.ts +178 -0
  190. package/src/abi/connectors/v1/uniswap.ts +297 -0
  191. package/src/abi/connectors/v2/1INCH-A.ts +3 -0
  192. package/src/abi/connectors/v2/1INCH-B.ts +3 -0
  193. package/src/abi/connectors/v2/AAVE-CLAIM-A.ts +3 -0
  194. package/src/abi/connectors/v2/AAVE-CLAIM-B.ts +165 -0
  195. package/src/abi/connectors/v2/AAVE-STAKE-A.ts +3 -0
  196. package/src/abi/connectors/v2/AAVE-V1-A.ts +130 -0
  197. package/src/abi/connectors/v2/AAVE-V1-IMPORT-A.ts +3 -0
  198. package/src/abi/connectors/v2/AAVE-V2-A.ts +229 -0
  199. package/src/abi/connectors/v2/AAVE-V2-IMPORT-A.ts +3 -0
  200. package/src/abi/connectors/v2/AAVE-V2-IMPORT-B.ts +224 -0
  201. package/src/abi/connectors/v2/AUTHORITY-A.ts +99 -0
  202. package/src/abi/connectors/v2/B-COMPOUND-A.ts +3 -0
  203. package/src/abi/connectors/v2/B-LIQUITY-A.ts +3 -0
  204. package/src/abi/connectors/v2/B-MAKERDAO-A.ts +3 -0
  205. package/src/abi/connectors/v2/BASIC-A.ts +135 -0
  206. package/src/abi/connectors/v2/BASIC-B.ts +3 -0
  207. package/src/abi/connectors/v2/BASIC-C.ts +3 -0
  208. package/src/abi/connectors/v2/COMP-A.ts +3 -0
  209. package/src/abi/connectors/v2/COMPOUND-A.ts +3 -0
  210. package/src/abi/connectors/v2/COMPOUND-IMPORT-A.ts +3 -0
  211. package/src/abi/connectors/v2/COMPOUND-IMPORT-B.ts +194 -0
  212. package/src/abi/connectors/v2/G-UNISWAP-A.ts +3 -0
  213. package/src/abi/connectors/v2/GELATO-AAVE-A.ts +3 -0
  214. package/src/abi/connectors/v2/INST-A.ts +3 -0
  215. package/src/abi/connectors/v2/INST-LM-A.ts +3 -0
  216. package/src/abi/connectors/v2/INST-STAKING-A.ts +3 -0
  217. package/src/abi/connectors/v2/INST-STAKING-B.ts +3 -0
  218. package/src/abi/connectors/v2/INSTAPOOL-A.ts +3 -0
  219. package/src/abi/connectors/v2/LIQUITY-A.ts +3 -0
  220. package/src/abi/connectors/v2/MAKERDAO-A.ts +3 -0
  221. package/src/abi/connectors/v2/MAKERDAO-CLAIM-A.ts +135 -0
  222. package/src/abi/connectors/v2/PARASWAP-A.ts +3 -0
  223. package/src/abi/connectors/v2/POLYGON-BRIDGE-A.ts +3 -0
  224. package/src/abi/connectors/v2/REFINANCE-A.ts +3 -0
  225. package/src/abi/connectors/v2/REFLEXER-A.ts +3 -0
  226. package/src/abi/connectors/v2/STAKE-ERC20-A.ts +3 -0
  227. package/src/abi/connectors/v2/UNISWAP-A.ts +297 -0
  228. package/src/abi/connectors/v2/UNISWAP-V2-A.ts +3 -0
  229. package/src/abi/connectors/v2/UNISWAP-V3-A.ts +3 -0
  230. package/src/abi/connectors/v2/UNISWAP-V3-STAKE-A.ts +3 -0
  231. package/src/abi/connectors/v2/WETH-A.ts +3 -0
  232. package/src/abi/connectors/v2/YEARN-VAULT-A.ts +3 -0
  233. package/src/abi/connectors/v2/index.ts +87 -0
  234. package/src/abi/index.ts +13 -5
  235. package/src/abi/instList.json +232 -0
  236. package/src/abi/interopX.json +1436 -0
  237. package/src/api/index.ts +9 -1
  238. package/src/constants/addresses.ts +21 -8
  239. package/src/constants/blockConfirmations.ts +5 -0
  240. package/src/constants/capPerChain.ts +5 -0
  241. package/src/constants/index.ts +3 -0
  242. package/src/constants/tokens.ts +31 -8
  243. package/src/constants/wrappedNativeToken.ts +5 -0
  244. package/src/crons/index.ts +1 -0
  245. package/src/crons/prices.ts +12 -0
  246. package/src/db/models/transaction.ts +146 -90
  247. package/src/errors/index.ts +26 -0
  248. package/src/gnosis/actions/aaveV2/index.ts +9 -0
  249. package/src/gnosis/actions/aaveV2/source.ts +119 -0
  250. package/src/gnosis/actions/aaveV2/target.ts +142 -0
  251. package/src/gnosis/actions/index.ts +2 -2
  252. package/src/gnosis/index.ts +5 -5
  253. package/src/index.ts +4 -1
  254. package/src/net/protocol/dial/SignatureDialProtocol.ts +7 -2
  255. package/src/providers/index.ts +1 -0
  256. package/src/providers/retry-provider.ts +51 -0
  257. package/src/services/Prices.ts +89 -0
  258. package/src/services/index.ts +1 -0
  259. package/src/tasks/InteropX/ProcessSubmitEvents.ts +345 -0
  260. package/src/tasks/InteropX/ProcessValidateEvents.ts +272 -0
  261. package/src/tasks/InteropX/SyncLogExecuteEvents.ts +161 -0
  262. package/src/tasks/InteropX/SyncLogSubmitEvents.ts +138 -0
  263. package/src/tasks/InteropX/SyncLogValidateEvents.ts +151 -0
  264. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +6 -3
  265. package/src/tasks/index.ts +24 -9
  266. package/src/typechain/AaveV2Resolver.ts +1017 -0
  267. package/src/typechain/BalanceResolver.ts +266 -0
  268. package/src/typechain/InstList.ts +402 -0
  269. package/src/typechain/InteropX.ts +1216 -0
  270. package/src/typechain/factories/AaveV2Resolver__factory.ts +1198 -0
  271. package/src/typechain/factories/BalanceResolver__factory.ts +235 -0
  272. package/src/typechain/factories/InstList__factory.ts +253 -0
  273. package/src/typechain/factories/InteropX__factory.ts +1932 -0
  274. package/src/typechain/factories/index.ts +4 -1
  275. package/src/typechain/index.ts +8 -2
  276. package/src/utils/async.ts +22 -0
  277. package/src/utils/dsa.ts +30 -0
  278. package/src/utils/formatting.ts +68 -0
  279. package/src/utils/gnosis.ts +123 -0
  280. package/src/utils/http.ts +6 -0
  281. package/src/utils/index.ts +9 -240
  282. package/src/utils/interop.ts +28 -0
  283. package/src/utils/tokens.ts +21 -0
  284. package/src/utils/validate.ts +174 -0
  285. package/src/utils/web3.ts +132 -0
  286. package/dist/src/abi/interopXContract.json +0 -391
  287. package/dist/src/gnosis/actions/withdraw/index.js +0 -41
  288. package/dist/src/tasks/InteropXContract/ProcessBridgeRequestEvents.js +0 -146
  289. package/dist/src/typechain/factories/InteropXContract__factory.js +0 -526
  290. package/src/abi/interopXContract.json +0 -391
  291. package/src/gnosis/actions/withdraw/index.ts +0 -56
  292. package/src/tasks/InteropXContract/ProcessBridgeRequestEvents.ts +0 -208
  293. package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +0 -116
  294. package/src/typechain/InteropXContract.ts +0 -524
  295. package/src/typechain/factories/InteropXContract__factory.ts +0 -533
@@ -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,245 @@
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
+ const owners = await this.sourceGnosisContract
162
+ .getOwners()
163
+ .then((owners) => owners.map((owner) => owner.toLowerCase()));
164
+ const ownerPeerIds = net_1.peerPool.activePeers
165
+ .filter((peer) => owners.includes(peer.publicAddress.toLowerCase()))
166
+ .map((peer) => peer.id);
167
+ console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
168
+ console.log(ownerPeerIds);
169
+ const signatures = await net_1.protocol.requestSignatures({
170
+ type: "source",
171
+ transactionHash: transaction.transactionHash,
172
+ safeTxGas: gnosisTx.safeTxGas,
173
+ safeNonce: gnosisTx.nonce,
174
+ chainId: this.chainId,
175
+ }, ownerPeerIds);
176
+ const validSignatures = signatures.filter((s) => !!s.data && s.data !== "0x");
177
+ console.log({
178
+ signatures,
179
+ validSignatures,
180
+ ownersThreshold: ownersThreshold.toString(),
181
+ });
182
+ if (validSignatures.length === 0 ||
183
+ ownersThreshold.gt(validSignatures.length)) {
184
+ await transaction.save();
185
+ transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
186
+ transaction.sourceStatus = "pending";
187
+ await transaction.save();
188
+ const errorMessage = (_a = signatures.find((s) => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
189
+ throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ""));
190
+ }
191
+ console.log(`Executing transaction for execution ${transaction.transactionHash}`);
192
+ 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));
193
+ const [gasPrice, gasLimit] = await Promise.all([
194
+ this.sourceProvider.getGasPrice(),
195
+ this.sourceProvider.estimateGas({
196
+ from: this.sourceWallet.address,
197
+ to: this.sourceGnosisContract.address,
198
+ data: txData,
199
+ }),
200
+ ]);
201
+ const txSent = await this.sourceWallet.sendTransaction({
202
+ from: this.sourceWallet.address,
203
+ to: this.sourceGnosisContract.address,
204
+ gasPrice: gasPrice.mul(120).div(100),
205
+ gasLimit: 5000000,
206
+ data: txData,
207
+ });
208
+ console.log(txSent);
209
+ const receipt = await txSent.wait();
210
+ const parsedLogs = [];
211
+ receipt.logs.forEach((log) => {
212
+ try {
213
+ parsedLogs.push(this.sourceGnosisContract.interface.parseLog(log));
214
+ }
215
+ catch (e) { }
216
+ });
217
+ if (parsedLogs.find((e) => e.name === "ExecutionSuccess")) {
218
+ console.log("ExecutionSuccess");
219
+ transaction.sourceStatus = "success";
220
+ if (txSent.blockNumber)
221
+ transaction.sourceBlockNumber = txSent.blockNumber;
222
+ transaction.sourceTransactionHash = txSent.hash;
223
+ transaction.sourceLogs = logs;
224
+ await transaction.save();
225
+ }
226
+ else {
227
+ console.log("ExecutionFailure");
228
+ transaction.sourceStatus = "failed";
229
+ if (txSent.blockNumber)
230
+ transaction.sourceBlockNumber = txSent.blockNumber;
231
+ transaction.sourceTransactionHash = txSent.hash;
232
+ transaction.status = "failed";
233
+ await transaction.save();
234
+ }
235
+ net_1.protocol.sendTransaction(transaction);
236
+ }
237
+ async start() {
238
+ this.blockConfirmationsCount = constants_1.blockConfirmations[this.chainId] + 1;
239
+ this.sourceProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
240
+ this.sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, this.sourceProvider);
241
+ this.sourceGnosisContract = (0, utils_1.getContract)(constants_1.addresses[this.chainId].gnosisSafe, abi_1.default.gnosisSafe, this.sourceWallet);
242
+ await super.start();
243
+ }
244
+ }
245
+ exports.default = ProcessSubmitEvents;
@@ -0,0 +1,185 @@
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 owners = await targetGnosisContract
103
+ .getOwners()
104
+ .then((owners) => owners.map((owner) => owner.toLowerCase()));
105
+ const ownerPeerIds = net_1.peerPool.activePeers
106
+ .filter((peer) => owners.includes(peer.publicAddress.toLowerCase()))
107
+ .map((peer) => peer.id);
108
+ console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
109
+ console.log(ownerPeerIds);
110
+ const signatures = await net_1.protocol.requestSignatures({
111
+ type: "target",
112
+ transactionHash: transaction.transactionHash,
113
+ safeTxGas: gnosisTx.safeTxGas,
114
+ safeNonce: gnosisTx.nonce,
115
+ chainId: targetChainId,
116
+ }, ownerPeerIds);
117
+ const validSignatures = signatures.filter((s) => !!s.data && s.data !== "0x");
118
+ console.log({
119
+ signatures,
120
+ validSignatures,
121
+ ownersThreshold: ownersThreshold.toString(),
122
+ });
123
+ if (validSignatures.length === 0 ||
124
+ ownersThreshold.gt(validSignatures.length)) {
125
+ await transaction.save();
126
+ transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
127
+ transaction.targetStatus = "pending";
128
+ await transaction.save();
129
+ const errorMessage = (_a = signatures.find((s) => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
130
+ throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ""));
131
+ }
132
+ console.log(`Executing transaction for execution ${transaction.transactionHash}`);
133
+ 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));
134
+ const [gasPrice, gasLimit] = await Promise.all([
135
+ targetProvider.getGasPrice(),
136
+ targetProvider.estimateGas({
137
+ from: targetWallet.address,
138
+ to: targetGnosisContract.address,
139
+ data: txData,
140
+ }),
141
+ ]);
142
+ const txSent = await targetWallet.sendTransaction({
143
+ from: targetWallet.address,
144
+ to: targetGnosisContract.address,
145
+ gasPrice: gasPrice.mul(120).div(100),
146
+ gasLimit: 5000000,
147
+ data: txData,
148
+ });
149
+ console.log(txSent);
150
+ const receipt = await txSent.wait();
151
+ const parsedLogs = [];
152
+ receipt.logs.forEach((log) => {
153
+ try {
154
+ parsedLogs.push(targetGnosisContract.interface.parseLog(log));
155
+ }
156
+ catch (e) { }
157
+ });
158
+ if (parsedLogs.find((e) => e.name === "ExecutionSuccess")) {
159
+ console.log("ExecutionSuccess");
160
+ transaction.targetStatus = "success";
161
+ transaction.status = "success";
162
+ if (txSent.blockNumber)
163
+ transaction.targetBlockNumber = txSent.blockNumber;
164
+ transaction.targetTransactionHash = txSent.hash;
165
+ transaction.targetLogs = logs;
166
+ await transaction.save();
167
+ }
168
+ else {
169
+ console.log("ExecutionFailure");
170
+ transaction.targetStatus = "failed";
171
+ if (txSent.blockNumber)
172
+ transaction.targetBlockNumber = txSent.blockNumber;
173
+ transaction.targetTransactionHash = txSent.hash;
174
+ transaction.status = "failed";
175
+ await transaction.save();
176
+ }
177
+ net_1.protocol.sendTransaction(transaction);
178
+ }
179
+ async start() {
180
+ this.blockConfirmationsCount = constants_1.blockConfirmations[this.chainId] + 1;
181
+ this.sourceProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
182
+ await super.start();
183
+ }
184
+ }
185
+ exports.default = ProcessValidateEvents;
@@ -0,0 +1,113 @@
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 sequelize_1 = require("sequelize");
15
+ const providers_1 = require("@/providers");
16
+ class SyncLogExecuteEvents extends BaseTask_1.BaseTask {
17
+ constructor({ targetChainId }) {
18
+ super({
19
+ logger: new logger_1.default("InteropX::SyncLogExecuteEvents"),
20
+ });
21
+ this.targetChainId = targetChainId;
22
+ }
23
+ async pollHandler() {
24
+ const currentBlock = await this.provider.getBlockNumber();
25
+ const events = await this.contract.queryFilter(this.contract.filters.LogExecute(), currentBlock - 2000, currentBlock);
26
+ let processedEvents = 0;
27
+ for (const event of events) {
28
+ try {
29
+ if (!event.args) {
30
+ continue;
31
+ }
32
+ const { sourceSpells, targetSpells, position, actionId, actionIdHash, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata, } = event.args;
33
+ const uniqueIdentifier = {
34
+ actionId,
35
+ vnonce: vnonce.toString(),
36
+ sourceSender: sourceSender.toString(),
37
+ sourceChainId: sourceChainId.toNumber(),
38
+ targetChainId: targetChainId.toNumber(),
39
+ sourceDsaId: sourceDsaId.toString(),
40
+ targetDsaId: targetDsaId.toString(),
41
+ };
42
+ let transactionHash = (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier);
43
+ const transaction = await db_1.Transaction.findOne({
44
+ where: {
45
+ transactionHash,
46
+ executeEvent: { [sequelize_1.Op.eq]: null },
47
+ },
48
+ });
49
+ if (!transaction) {
50
+ continue;
51
+ }
52
+ if (transaction.targetStatus != "success") {
53
+ transaction.targetStatus = "success";
54
+ }
55
+ if (transaction.status != "success") {
56
+ transaction.status = "success";
57
+ }
58
+ if (!transaction.targetCreatedAt) {
59
+ transaction.targetCreatedAt = new Date();
60
+ }
61
+ transaction.targetTransactionHash = event.transactionHash;
62
+ transaction.targetBlockNumber = event.blockNumber;
63
+ transaction.targetLogs = [];
64
+ transaction.executeEvent = {
65
+ actionId,
66
+ actionIdHashHash: actionIdHash,
67
+ actionIdHash,
68
+ vnonce: vnonce.toString(),
69
+ sourceSpells: sourceSpells.map(({ connector, data }) => ({
70
+ connector,
71
+ data,
72
+ })),
73
+ targetSpells: targetSpells.map(({ connector, data }) => ({
74
+ connector,
75
+ data,
76
+ })),
77
+ position: {
78
+ withdraw: position.withdraw.map((v) => ({
79
+ sourceToken: v.sourceToken,
80
+ targetToken: v.targetToken,
81
+ amount: v.amount.toString(),
82
+ })),
83
+ supply: position.supply.map((v) => ({
84
+ sourceToken: v.sourceToken,
85
+ targetToken: v.targetToken,
86
+ amount: v.amount.toString(),
87
+ })),
88
+ },
89
+ sourceChainId: sourceChainId.toNumber(),
90
+ targetChainId: targetChainId.toNumber(),
91
+ sourceSender,
92
+ sourceDsaId: sourceDsaId.toString(),
93
+ targetDsaId: targetDsaId.toString(),
94
+ metadata,
95
+ };
96
+ await transaction.save();
97
+ this.logger.info(`New InteropX tranaction: ${transactionHash} `);
98
+ }
99
+ catch (error) {
100
+ this.logger.error(error);
101
+ }
102
+ }
103
+ if (processedEvents > 0)
104
+ this.logger.info(`${processedEvents} events processed`);
105
+ }
106
+ async start() {
107
+ this.contractAddress = constants_1.addresses[this.targetChainId].interopX;
108
+ this.provider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(this.targetChainId));
109
+ this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopX, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
110
+ await super.start();
111
+ }
112
+ }
113
+ exports.default = SyncLogExecuteEvents;