@instadapp/interop-x 0.0.0-dev.e53015f → 0.0.0-dev.ea4acf6
Sign up to get free protection for your applications and to get access to all the features.
- package/.github/workflows/ci.yml +19 -0
- package/dist/package.json +23 -13
- package/dist/src/abi/aaveV2Resolver.json +832 -0
- package/dist/src/abi/aaveV3Resolver.json +628 -0
- package/dist/src/abi/balanceResolver.json +211 -0
- package/dist/src/abi/connectors/index.js +36 -0
- package/dist/src/abi/connectors/v1/aave.js +148 -0
- package/dist/src/abi/connectors/v1/aave_claim.js +4 -0
- package/dist/src/abi/connectors/v1/aave_migrate.js +109 -0
- package/dist/src/abi/connectors/v1/aave_polygon_migrate.js +110 -0
- package/dist/src/abi/connectors/v1/aave_stake.js +4 -0
- package/dist/src/abi/connectors/v1/aave_v1_import.js +54 -0
- package/dist/src/abi/connectors/v1/aave_v2.js +230 -0
- package/dist/src/abi/connectors/v1/aave_v2_import.js +59 -0
- package/dist/src/abi/connectors/v1/authority.js +100 -0
- package/dist/src/abi/connectors/v1/basic.js +136 -0
- package/dist/src/abi/connectors/v1/chi.js +36 -0
- package/dist/src/abi/connectors/v1/comp.js +4 -0
- package/dist/src/abi/connectors/v1/compound.js +4 -0
- package/dist/src/abi/connectors/v1/compoundImport.js +69 -0
- package/dist/src/abi/connectors/v1/compoundImport_v2.js +4 -0
- package/dist/src/abi/connectors/v1/compound_old.js +448 -0
- package/dist/src/abi/connectors/v1/curve.js +140 -0
- package/dist/src/abi/connectors/v1/curve_claim.js +63 -0
- package/dist/src/abi/connectors/v1/curve_gauge.js +158 -0
- package/dist/src/abi/connectors/v1/curve_sbtc.js +140 -0
- package/dist/src/abi/connectors/v1/curve_susd.js +140 -0
- package/dist/src/abi/connectors/v1/curve_three.js +79 -0
- package/dist/src/abi/connectors/v1/curve_y.js +140 -0
- package/dist/src/abi/connectors/v1/dsa_migrate_v1_to_v2.js +4 -0
- package/dist/src/abi/connectors/v1/dydx.js +148 -0
- package/dist/src/abi/connectors/v1/dydx_flash.js +52 -0
- package/dist/src/abi/connectors/v1/fee.js +50 -0
- package/dist/src/abi/connectors/v1/gelato.js +1138 -0
- package/dist/src/abi/connectors/v1/index.js +58 -0
- package/dist/src/abi/connectors/v1/instapool.js +439 -0
- package/dist/src/abi/connectors/v1/instapool_v2.js +126 -0
- package/dist/src/abi/connectors/v1/kyber.js +117 -0
- package/dist/src/abi/connectors/v1/maker.js +480 -0
- package/dist/src/abi/connectors/v1/maker_old.js +300 -0
- package/dist/src/abi/connectors/v1/math.js +43 -0
- package/dist/src/abi/connectors/v1/migrate.js +46 -0
- package/dist/src/abi/connectors/v1/oasis.js +198 -0
- package/dist/src/abi/connectors/v1/oneInch.js +160 -0
- package/dist/src/abi/connectors/v1/polygon_bridge.js +4 -0
- package/dist/src/abi/connectors/v1/refinance.js +4 -0
- package/dist/src/abi/connectors/v1/staking.js +220 -0
- package/dist/src/abi/connectors/v1/swerve.js +179 -0
- package/dist/src/abi/connectors/v1/uniswap.js +297 -0
- package/dist/src/abi/connectors/v2/1INCH-A.js +4 -0
- package/dist/src/abi/connectors/v2/1INCH-B.js +4 -0
- package/dist/src/abi/connectors/v2/AAVE-CLAIM-A.js +4 -0
- package/dist/src/abi/connectors/v2/AAVE-CLAIM-B.js +166 -0
- package/dist/src/abi/connectors/v2/AAVE-STAKE-A.js +4 -0
- package/dist/src/abi/connectors/v2/AAVE-V1-A.js +130 -0
- package/dist/src/abi/connectors/v2/AAVE-V1-IMPORT-A.js +4 -0
- package/dist/src/abi/connectors/v2/AAVE-V2-A.js +230 -0
- package/dist/src/abi/connectors/v2/AAVE-V2-IMPORT-A.js +4 -0
- package/dist/src/abi/connectors/v2/AAVE-V2-IMPORT-B.js +225 -0
- package/dist/src/abi/connectors/v2/AUTHORITY-A.js +100 -0
- package/dist/src/abi/connectors/v2/B-COMPOUND-A.js +4 -0
- package/dist/src/abi/connectors/v2/B-LIQUITY-A.js +4 -0
- package/dist/src/abi/connectors/v2/B-MAKERDAO-A.js +4 -0
- package/dist/src/abi/connectors/v2/BASIC-A.js +136 -0
- package/dist/src/abi/connectors/v2/BASIC-B.js +4 -0
- package/dist/src/abi/connectors/v2/BASIC-C.js +4 -0
- package/dist/src/abi/connectors/v2/COMP-A.js +4 -0
- package/dist/src/abi/connectors/v2/COMPOUND-A.js +4 -0
- package/dist/src/abi/connectors/v2/COMPOUND-IMPORT-A.js +4 -0
- package/dist/src/abi/connectors/v2/COMPOUND-IMPORT-B.js +195 -0
- package/dist/src/abi/connectors/v2/G-UNISWAP-A.js +4 -0
- package/dist/src/abi/connectors/v2/GELATO-AAVE-A.js +4 -0
- package/dist/src/abi/connectors/v2/INST-A.js +4 -0
- package/dist/src/abi/connectors/v2/INST-LM-A.js +4 -0
- package/dist/src/abi/connectors/v2/INST-STAKING-A.js +4 -0
- package/dist/src/abi/connectors/v2/INST-STAKING-B.js +4 -0
- package/dist/src/abi/connectors/v2/INSTAPOOL-A.js +4 -0
- package/dist/src/abi/connectors/v2/LIQUITY-A.js +4 -0
- package/dist/src/abi/connectors/v2/MAKERDAO-A.js +4 -0
- package/dist/src/abi/connectors/v2/MAKERDAO-CLAIM-A.js +136 -0
- package/dist/src/abi/connectors/v2/PARASWAP-A.js +4 -0
- package/dist/src/abi/connectors/v2/POLYGON-BRIDGE-A.js +4 -0
- package/dist/src/abi/connectors/v2/REFINANCE-A.js +4 -0
- package/dist/src/abi/connectors/v2/REFLEXER-A.js +4 -0
- package/dist/src/abi/connectors/v2/STAKE-ERC20-A.js +4 -0
- package/dist/src/abi/connectors/v2/UNISWAP-A.js +297 -0
- package/dist/src/abi/connectors/v2/UNISWAP-V2-A.js +4 -0
- package/dist/src/abi/connectors/v2/UNISWAP-V3-A.js +4 -0
- package/dist/src/abi/connectors/v2/UNISWAP-V3-STAKE-A.js +4 -0
- package/dist/src/abi/connectors/v2/WETH-A.js +4 -0
- package/dist/src/abi/connectors/v2/YEARN-VAULT-A.js +4 -0
- package/dist/src/abi/connectors/v2/index.js +89 -0
- package/dist/src/abi/index.js +12 -4
- package/dist/src/abi/instList.json +232 -0
- package/dist/src/abi/interopX.json +1436 -0
- package/dist/src/alias.js +10 -0
- package/dist/src/api/index.js +10 -0
- package/dist/src/constants/addresses.js +12 -7
- package/dist/src/constants/blockConfirmations.js +8 -0
- package/dist/src/constants/capPerChain.js +8 -0
- package/dist/src/constants/index.js +3 -1
- package/dist/src/constants/tokens.js +30 -7
- package/dist/src/constants/wrappedNativeToken.js +8 -0
- package/dist/src/crons/index.js +3 -0
- package/dist/src/crons/prices.js +16 -0
- package/dist/src/db/models/transaction.js +42 -16
- package/dist/src/errors/index.js +30 -0
- package/dist/src/gnosis/actions/aaveV2/index.js +11 -0
- package/dist/src/gnosis/actions/aaveV2/source.js +98 -0
- package/dist/src/gnosis/actions/aaveV2/target.js +100 -0
- package/dist/src/gnosis/actions/aaveV3/index.js +11 -0
- package/dist/src/gnosis/actions/aaveV3/source.js +74 -0
- package/dist/src/gnosis/actions/aaveV3/target.js +87 -0
- package/dist/src/gnosis/actions/index.js +11 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +24 -22
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +9 -10
- package/dist/src/net/protocol/dial/{SignatureDialProtocol.1.js → TransactionStatusDialProtocol.js} +2 -0
- package/dist/src/net/protocol/index.js +17 -7
- package/dist/src/providers/index.js +17 -0
- package/dist/src/providers/retry-provider.js +45 -0
- package/dist/src/services/Prices.js +74 -0
- package/dist/src/services/index.js +8 -0
- package/dist/src/tasks/AutoUpdateTask.js +6 -2
- package/dist/src/tasks/InteropX/ProcessSubmitEvents.js +273 -0
- package/dist/src/tasks/InteropX/ProcessValidateEvents.js +203 -0
- package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +113 -0
- package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +88 -0
- package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +106 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +8 -3
- package/dist/src/tasks/index.js +20 -19
- package/dist/src/typechain/{InteropBridgeToken.js → AaveV2Resolver.js} +0 -0
- package/dist/src/typechain/{InteropXGateway.js → AaveV3Resolver.js} +0 -0
- package/dist/src/typechain/BalanceResolver.js +2 -0
- package/dist/src/typechain/InstList.js +2 -0
- package/dist/src/typechain/InteropX.js +2 -0
- package/dist/src/typechain/factories/AaveV2Resolver__factory.js +1191 -0
- package/dist/src/typechain/factories/AaveV3Resolver__factory.js +887 -0
- package/dist/src/typechain/factories/BalanceResolver__factory.js +228 -0
- package/dist/src/typechain/factories/InstList__factory.js +249 -0
- package/dist/src/typechain/factories/InteropX__factory.js +1928 -0
- package/dist/src/typechain/factories/index.js +11 -5
- package/dist/src/typechain/index.js +11 -5
- package/dist/src/utils/async.js +18 -0
- package/dist/src/utils/dsa.js +36 -0
- package/dist/src/utils/formatting.js +67 -0
- package/dist/src/utils/gnosis.js +87 -0
- package/dist/src/utils/http.js +10 -0
- package/dist/src/utils/index.js +22 -235
- package/dist/src/utils/interop.js +16 -0
- package/dist/src/utils/tokens.js +22 -0
- package/dist/src/utils/validate.js +111 -0
- package/dist/src/utils/web3.js +93 -0
- package/package.json +23 -13
- package/src/abi/aaveV2Resolver.json +832 -0
- package/src/abi/aaveV3Resolver.json +628 -0
- package/src/abi/balanceResolver.json +211 -0
- package/src/abi/connectors/index.ts +14 -0
- package/src/abi/connectors/v1/aave.ts +147 -0
- package/src/abi/connectors/v1/aave_claim.ts +3 -0
- package/src/abi/connectors/v1/aave_migrate.ts +108 -0
- package/src/abi/connectors/v1/aave_polygon_migrate.ts +109 -0
- package/src/abi/connectors/v1/aave_stake.ts +3 -0
- package/src/abi/connectors/v1/aave_v1_import.ts +53 -0
- package/src/abi/connectors/v1/aave_v2.ts +229 -0
- package/src/abi/connectors/v1/aave_v2_import.ts +58 -0
- package/src/abi/connectors/v1/authority.ts +99 -0
- package/src/abi/connectors/v1/basic.ts +135 -0
- package/src/abi/connectors/v1/chi.ts +35 -0
- package/src/abi/connectors/v1/comp.ts +3 -0
- package/src/abi/connectors/v1/compound.ts +3 -0
- package/src/abi/connectors/v1/compoundImport.ts +68 -0
- package/src/abi/connectors/v1/compoundImport_v2.ts +3 -0
- package/src/abi/connectors/v1/compound_old.ts +447 -0
- package/src/abi/connectors/v1/curve.ts +139 -0
- package/src/abi/connectors/v1/curve_claim.ts +62 -0
- package/src/abi/connectors/v1/curve_gauge.ts +157 -0
- package/src/abi/connectors/v1/curve_sbtc.ts +139 -0
- package/src/abi/connectors/v1/curve_susd.ts +139 -0
- package/src/abi/connectors/v1/curve_three.ts +78 -0
- package/src/abi/connectors/v1/curve_y.ts +139 -0
- package/src/abi/connectors/v1/dsa_migrate_v1_to_v2.ts +3 -0
- package/src/abi/connectors/v1/dydx.ts +147 -0
- package/src/abi/connectors/v1/dydx_flash.ts +51 -0
- package/src/abi/connectors/v1/fee.ts +49 -0
- package/src/abi/connectors/v1/gelato.ts +1137 -0
- package/src/abi/connectors/v1/index.ts +42 -0
- package/src/abi/connectors/v1/instapool.ts +438 -0
- package/src/abi/connectors/v1/instapool_v2.ts +125 -0
- package/src/abi/connectors/v1/kyber.ts +116 -0
- package/src/abi/connectors/v1/maker.ts +479 -0
- package/src/abi/connectors/v1/maker_old.ts +299 -0
- package/src/abi/connectors/v1/math.ts +42 -0
- package/src/abi/connectors/v1/migrate.ts +45 -0
- package/src/abi/connectors/v1/oasis.ts +197 -0
- package/src/abi/connectors/v1/oneInch.ts +159 -0
- package/src/abi/connectors/v1/polygon_bridge.ts +3 -0
- package/src/abi/connectors/v1/refinance.ts +3 -0
- package/src/abi/connectors/v1/staking.ts +219 -0
- package/src/abi/connectors/v1/swerve.ts +178 -0
- package/src/abi/connectors/v1/uniswap.ts +297 -0
- package/src/abi/connectors/v2/1INCH-A.ts +3 -0
- package/src/abi/connectors/v2/1INCH-B.ts +3 -0
- package/src/abi/connectors/v2/AAVE-CLAIM-A.ts +3 -0
- package/src/abi/connectors/v2/AAVE-CLAIM-B.ts +165 -0
- package/src/abi/connectors/v2/AAVE-STAKE-A.ts +3 -0
- package/src/abi/connectors/v2/AAVE-V1-A.ts +130 -0
- package/src/abi/connectors/v2/AAVE-V1-IMPORT-A.ts +3 -0
- package/src/abi/connectors/v2/AAVE-V2-A.ts +229 -0
- package/src/abi/connectors/v2/AAVE-V2-IMPORT-A.ts +3 -0
- package/src/abi/connectors/v2/AAVE-V2-IMPORT-B.ts +224 -0
- package/src/abi/connectors/v2/AUTHORITY-A.ts +99 -0
- package/src/abi/connectors/v2/B-COMPOUND-A.ts +3 -0
- package/src/abi/connectors/v2/B-LIQUITY-A.ts +3 -0
- package/src/abi/connectors/v2/B-MAKERDAO-A.ts +3 -0
- package/src/abi/connectors/v2/BASIC-A.ts +135 -0
- package/src/abi/connectors/v2/BASIC-B.ts +3 -0
- package/src/abi/connectors/v2/BASIC-C.ts +3 -0
- package/src/abi/connectors/v2/COMP-A.ts +3 -0
- package/src/abi/connectors/v2/COMPOUND-A.ts +3 -0
- package/src/abi/connectors/v2/COMPOUND-IMPORT-A.ts +3 -0
- package/src/abi/connectors/v2/COMPOUND-IMPORT-B.ts +194 -0
- package/src/abi/connectors/v2/G-UNISWAP-A.ts +3 -0
- package/src/abi/connectors/v2/GELATO-AAVE-A.ts +3 -0
- package/src/abi/connectors/v2/INST-A.ts +3 -0
- package/src/abi/connectors/v2/INST-LM-A.ts +3 -0
- package/src/abi/connectors/v2/INST-STAKING-A.ts +3 -0
- package/src/abi/connectors/v2/INST-STAKING-B.ts +3 -0
- package/src/abi/connectors/v2/INSTAPOOL-A.ts +3 -0
- package/src/abi/connectors/v2/LIQUITY-A.ts +3 -0
- package/src/abi/connectors/v2/MAKERDAO-A.ts +3 -0
- package/src/abi/connectors/v2/MAKERDAO-CLAIM-A.ts +135 -0
- package/src/abi/connectors/v2/PARASWAP-A.ts +3 -0
- package/src/abi/connectors/v2/POLYGON-BRIDGE-A.ts +3 -0
- package/src/abi/connectors/v2/REFINANCE-A.ts +3 -0
- package/src/abi/connectors/v2/REFLEXER-A.ts +3 -0
- package/src/abi/connectors/v2/STAKE-ERC20-A.ts +3 -0
- package/src/abi/connectors/v2/UNISWAP-A.ts +297 -0
- package/src/abi/connectors/v2/UNISWAP-V2-A.ts +3 -0
- package/src/abi/connectors/v2/UNISWAP-V3-A.ts +3 -0
- package/src/abi/connectors/v2/UNISWAP-V3-STAKE-A.ts +3 -0
- package/src/abi/connectors/v2/WETH-A.ts +3 -0
- package/src/abi/connectors/v2/YEARN-VAULT-A.ts +3 -0
- package/src/abi/connectors/v2/index.ts +87 -0
- package/src/abi/index.ts +15 -7
- package/src/abi/instList.json +232 -0
- package/src/abi/interopX.json +1436 -0
- package/src/alias.ts +6 -0
- package/src/api/index.ts +11 -0
- package/src/constants/addresses.ts +24 -8
- package/src/constants/blockConfirmations.ts +5 -0
- package/src/constants/capPerChain.ts +5 -0
- package/src/constants/index.ts +3 -1
- package/src/constants/tokens.ts +31 -8
- package/src/constants/wrappedNativeToken.ts +5 -0
- package/src/crons/index.ts +1 -0
- package/src/crons/prices.ts +12 -0
- package/src/db/models/transaction.ts +160 -66
- package/src/errors/index.ts +26 -0
- package/src/gnosis/actions/aaveV2/index.ts +9 -0
- package/src/gnosis/actions/aaveV2/source.ts +171 -0
- package/src/gnosis/actions/aaveV2/target.ts +160 -0
- package/src/gnosis/actions/aaveV3/index.ts +9 -0
- package/src/gnosis/actions/aaveV3/source.ts +119 -0
- package/src/gnosis/actions/aaveV3/target.ts +142 -0
- package/src/gnosis/actions/index.ts +7 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +31 -23
- package/src/net/protocol/dial/SignatureDialProtocol.ts +12 -13
- package/src/net/protocol/dial/{SignatureDialProtocol.1.ts → TransactionStatusDialProtocol.ts} +3 -1
- package/src/net/protocol/index.ts +17 -7
- package/src/providers/index.ts +1 -0
- package/src/providers/retry-provider.ts +51 -0
- package/src/services/Prices.ts +89 -0
- package/src/services/index.ts +1 -0
- package/src/tasks/AutoUpdateTask.ts +12 -9
- package/src/tasks/InteropX/ProcessSubmitEvents.ts +384 -0
- package/src/tasks/InteropX/ProcessValidateEvents.ts +297 -0
- package/src/tasks/InteropX/SyncLogExecuteEvents.ts +161 -0
- package/src/tasks/InteropX/SyncLogSubmitEvents.ts +138 -0
- package/src/tasks/InteropX/SyncLogValidateEvents.ts +151 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +8 -3
- package/src/tasks/index.ts +25 -20
- package/src/typechain/AaveV2Resolver.ts +1017 -0
- package/src/typechain/AaveV3Resolver.ts +935 -0
- package/src/typechain/BalanceResolver.ts +266 -0
- package/src/typechain/InstList.ts +402 -0
- package/src/typechain/InteropX.ts +1216 -0
- package/src/typechain/factories/AaveV2Resolver__factory.ts +1198 -0
- package/src/typechain/factories/AaveV3Resolver__factory.ts +894 -0
- package/src/typechain/factories/BalanceResolver__factory.ts +235 -0
- package/src/typechain/factories/InstList__factory.ts +253 -0
- package/src/typechain/factories/InteropX__factory.ts +1932 -0
- package/src/typechain/factories/index.ts +5 -2
- package/src/typechain/index.ts +10 -4
- package/src/utils/async.ts +22 -0
- package/src/utils/dsa.ts +56 -0
- package/src/utils/formatting.ts +68 -0
- package/src/utils/gnosis.ts +166 -0
- package/src/utils/http.ts +6 -0
- package/src/utils/index.ts +9 -319
- package/src/utils/interop.ts +28 -0
- package/src/utils/tokens.ts +21 -0
- package/src/utils/validate.ts +179 -0
- package/src/utils/web3.ts +132 -0
- package/tsconfig.json +7 -2
- package/dist/src/abi/interopBridgeToken.json +0 -286
- package/dist/src/abi/interopXGateway.json +0 -184
- package/dist/src/constants/itokens.js +0 -13
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +0 -146
- package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +0 -69
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +0 -149
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -74
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -459
- package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
- package/src/abi/interopBridgeToken.json +0 -286
- package/src/abi/interopXGateway.json +0 -184
- package/src/constants/itokens.ts +0 -10
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +0 -231
- package/src/tasks/InteropBridge/SyncWithdrawEvents.ts +0 -119
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -243
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -124
- package/src/typechain/InteropBridgeToken.ts +0 -686
- package/src/typechain/InteropXGateway.ts +0 -407
- package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
- package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -0,0 +1,384 @@
|
|
1
|
+
import { BaseTask } from "../BaseTask";
|
2
|
+
import Logger from "@/logger";
|
3
|
+
import { ethers, Wallet } from "ethers";
|
4
|
+
import abi from "@/abi";
|
5
|
+
import { Transaction } from "@/db";
|
6
|
+
import {
|
7
|
+
buildSignatureBytes,
|
8
|
+
chainIdToName,
|
9
|
+
generateGnosisSignatureMessage,
|
10
|
+
generateGnosisTransaction,
|
11
|
+
getChainIdNativeSymbol,
|
12
|
+
getContract,
|
13
|
+
getExplorerUrl,
|
14
|
+
getRpcProviderUrl,
|
15
|
+
Signature,
|
16
|
+
validateChains,
|
17
|
+
validateLiquidityCap,
|
18
|
+
validateSourceLiquidity,
|
19
|
+
getGnosisSignatureAddress,
|
20
|
+
} from "@/utils";
|
21
|
+
import { addresses, blockConfirmations } from "@/constants";
|
22
|
+
import { ChainId } from "@/types";
|
23
|
+
import config from "@/config";
|
24
|
+
import { GnosisSafe, InteropX } from "@/typechain";
|
25
|
+
import moment from "moment";
|
26
|
+
import { Op } from "sequelize";
|
27
|
+
import { buildGnosisAction } from "@/gnosis";
|
28
|
+
import { peerPool, protocol } from "@/net";
|
29
|
+
import { LogDescription } from "ethers/lib/utils";
|
30
|
+
import wait from "waait";
|
31
|
+
import { LiquidityError, UnsupportedChaindIdError } from "@/errors";
|
32
|
+
import { BigNumber } from "bignumber.js";
|
33
|
+
import dedent from "dedent";
|
34
|
+
import { JsonRpcRetryProvider } from "@/providers";
|
35
|
+
|
36
|
+
export default class ProcessSubmitEvents extends BaseTask {
|
37
|
+
sourceProvider: JsonRpcRetryProvider;
|
38
|
+
sourceGnosisContract: GnosisSafe;
|
39
|
+
sourceWallet: Wallet;
|
40
|
+
chainId: ChainId;
|
41
|
+
leadNodeOnly: boolean = true;
|
42
|
+
blockConfirmationsCount: number = 12;
|
43
|
+
|
44
|
+
constructor({ chainId }: { chainId: ChainId }) {
|
45
|
+
super({
|
46
|
+
logger: new Logger("InteropX::ProcessSubmitEvents"),
|
47
|
+
});
|
48
|
+
this.chainId = chainId;
|
49
|
+
}
|
50
|
+
|
51
|
+
async pollHandler() {
|
52
|
+
const currentBlockNumber = await this.sourceProvider.getBlockNumber();
|
53
|
+
|
54
|
+
const transaction = await Transaction.findOne({
|
55
|
+
where: {
|
56
|
+
status: "pending",
|
57
|
+
sourceStatus: "pending",
|
58
|
+
sourceChainId: this.chainId,
|
59
|
+
submitBlockNumber: {
|
60
|
+
[Op.lt]: currentBlockNumber - this.blockConfirmationsCount,
|
61
|
+
},
|
62
|
+
sourceDelayUntil: {
|
63
|
+
[Op.or]: {
|
64
|
+
[Op.is]: null,
|
65
|
+
[Op.lt]: new Date(),
|
66
|
+
},
|
67
|
+
},
|
68
|
+
|
69
|
+
submitEvent: { $ne: null },
|
70
|
+
|
71
|
+
createdAt: {
|
72
|
+
[Op.gt]: moment().subtract({ hours: 12 }).toDate(),
|
73
|
+
},
|
74
|
+
},
|
75
|
+
});
|
76
|
+
|
77
|
+
if (!transaction) {
|
78
|
+
return;
|
79
|
+
}
|
80
|
+
|
81
|
+
this.logger.debug(`Processing transaction ${transaction.transactionHash}`);
|
82
|
+
|
83
|
+
transaction.sourceStatus = "proccessing";
|
84
|
+
await transaction.save();
|
85
|
+
|
86
|
+
const { submitEvent: { position, sourceChainId, targetChainId, sourceDsaId } } = transaction;
|
87
|
+
try {
|
88
|
+
validateChains({ sourceChainId, targetChainId });
|
89
|
+
} catch (error) {
|
90
|
+
transaction.sourceErrors = [error.message];
|
91
|
+
transaction.sourceStatus = "failed";
|
92
|
+
transaction.targetStatus = "failed";
|
93
|
+
transaction.status = "failed";
|
94
|
+
await transaction.save();
|
95
|
+
return;
|
96
|
+
}
|
97
|
+
|
98
|
+
const walletBalance = (await this.sourceWallet.getBalance()).toString();
|
99
|
+
const currentGasPrice = (await this.sourceWallet.getGasPrice()).toString()
|
100
|
+
|
101
|
+
const minBalanceRequired = new BigNumber(currentGasPrice)
|
102
|
+
.multipliedBy(4_000_000)
|
103
|
+
.multipliedBy(2) // 2x balance
|
104
|
+
|
105
|
+
if (
|
106
|
+
new BigNumber(walletBalance).isLessThan(minBalanceRequired)
|
107
|
+
) {
|
108
|
+
console.log(
|
109
|
+
dedent`Not enough balance in wallet ${getExplorerUrl(sourceChainId, '/address/' + this.sourceWallet.address)} on ${chainIdToName(sourceChainId)}
|
110
|
+
Balance: ${ethers.utils.parseEther(walletBalance)} ${getChainIdNativeSymbol(sourceChainId)}
|
111
|
+
Required Balance: ${ethers.utils.parseEther(minBalanceRequired.toString())}
|
112
|
+
Require more: ${ethers.utils.parseEther(minBalanceRequired.minus(walletBalance).toString())}`
|
113
|
+
);
|
114
|
+
transaction.sourceDelayUntil = moment().add({ minutes: 5 }).toDate();
|
115
|
+
transaction.sourceStatus = "pending";
|
116
|
+
await transaction.save();
|
117
|
+
return;
|
118
|
+
}
|
119
|
+
|
120
|
+
try {
|
121
|
+
await validateLiquidityCap(position, sourceChainId, targetChainId);
|
122
|
+
} catch (error) {
|
123
|
+
transaction.sourceErrors = [error.message];
|
124
|
+
transaction.sourceStatus = "failed";
|
125
|
+
transaction.targetStatus = "failed";
|
126
|
+
transaction.status = "failed";
|
127
|
+
await transaction.save();
|
128
|
+
return;
|
129
|
+
}
|
130
|
+
|
131
|
+
try {
|
132
|
+
await validateSourceLiquidity({
|
133
|
+
position,
|
134
|
+
sourceChainId,
|
135
|
+
sourceDsaId,
|
136
|
+
sourceProvider: this.sourceProvider,
|
137
|
+
});
|
138
|
+
} catch (error) {
|
139
|
+
if (error instanceof UnsupportedChaindIdError) {
|
140
|
+
console.log(`Dropping transaction ${transaction.transactionHash}`);
|
141
|
+
|
142
|
+
transaction.sourceErrors = [error.message];
|
143
|
+
transaction.sourceStatus = "failed";
|
144
|
+
transaction.targetStatus = "failed";
|
145
|
+
transaction.status = "failed";
|
146
|
+
await transaction.save();
|
147
|
+
} else {
|
148
|
+
transaction.sourceStatus = "pending";
|
149
|
+
transaction.sourceErrors = [error.message];
|
150
|
+
transaction.sourceDelayUntil = moment().add({ minutes: 5 }).toDate();
|
151
|
+
await transaction.save();
|
152
|
+
|
153
|
+
console.log("[validateSourceLiquidity][Warning]", error.message);
|
154
|
+
return;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
const ownersThreshold = await this.sourceGnosisContract.getThreshold();
|
159
|
+
await wait(10000);
|
160
|
+
|
161
|
+
this.logger.debug(`Build gnosis action for ${transaction.transactionHash}`);
|
162
|
+
|
163
|
+
let data,
|
164
|
+
logs = [];
|
165
|
+
|
166
|
+
try {
|
167
|
+
({ data, logs } = await buildGnosisAction(transaction, "source"));
|
168
|
+
} catch (error) {
|
169
|
+
if (error instanceof LiquidityError) {
|
170
|
+
await transaction.save();
|
171
|
+
transaction.sourceDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
|
172
|
+
transaction.sourceStatus = "pending";
|
173
|
+
|
174
|
+
await transaction.save();
|
175
|
+
|
176
|
+
throw error;
|
177
|
+
return;
|
178
|
+
}
|
179
|
+
|
180
|
+
transaction.sourceStatus = "failed";
|
181
|
+
transaction.sourceErrors = [error.message];
|
182
|
+
transaction.targetStatus = "failed";
|
183
|
+
|
184
|
+
transaction.status = "failed";
|
185
|
+
await transaction.save();
|
186
|
+
protocol.sendTransaction(transaction);
|
187
|
+
return;
|
188
|
+
}
|
189
|
+
|
190
|
+
this.logger.debug(
|
191
|
+
`Generating gnosis tx for ${transaction.transactionHash}`
|
192
|
+
);
|
193
|
+
|
194
|
+
let gnosisTx = await generateGnosisTransaction(
|
195
|
+
{
|
196
|
+
baseGas: "0",
|
197
|
+
data,
|
198
|
+
gasPrice: "0",
|
199
|
+
gasToken: "0x0000000000000000000000000000000000000000",
|
200
|
+
nonce: "0",
|
201
|
+
operation: "1",
|
202
|
+
refundReceiver: "0x0000000000000000000000000000000000000000",
|
203
|
+
safeAddress: this.sourceGnosisContract.address,
|
204
|
+
safeTxGas: "79668",
|
205
|
+
to: addresses[transaction.sourceChainId].multisend,
|
206
|
+
value: "0",
|
207
|
+
},
|
208
|
+
this.sourceGnosisContract
|
209
|
+
);
|
210
|
+
|
211
|
+
|
212
|
+
async function getGnosisOwnerPeerIds({
|
213
|
+
gnosisContract
|
214
|
+
}) {
|
215
|
+
const owners = await gnosisContract
|
216
|
+
.getOwners()
|
217
|
+
.then((owners) => owners.map((owner) => owner.toLowerCase()));
|
218
|
+
|
219
|
+
return peerPool.activePeers
|
220
|
+
.filter((peer) => owners.includes(peer.publicAddress.toLowerCase()))
|
221
|
+
.map((peer) => peer.id);
|
222
|
+
}
|
223
|
+
|
224
|
+
const ownerPeerIds = await getGnosisOwnerPeerIds({
|
225
|
+
gnosisContract: this.sourceGnosisContract,
|
226
|
+
});
|
227
|
+
|
228
|
+
console.log(
|
229
|
+
`Collecting signatures for execution ${transaction.transactionHash} `
|
230
|
+
);
|
231
|
+
|
232
|
+
console.log(ownerPeerIds);
|
233
|
+
|
234
|
+
const message = generateGnosisSignatureMessage({
|
235
|
+
to: addresses[this.chainId].multisend,
|
236
|
+
data,
|
237
|
+
chainId: this.chainId,
|
238
|
+
safeTxGas: gnosisTx.safeTxGas,
|
239
|
+
nonce: gnosisTx.safeNonce,
|
240
|
+
});
|
241
|
+
|
242
|
+
const signatures = await protocol.requestSignatures(
|
243
|
+
{
|
244
|
+
type: "source",
|
245
|
+
transactionHash: transaction.transactionHash,
|
246
|
+
safeTxGas: gnosisTx.safeTxGas,
|
247
|
+
safeNonce: gnosisTx.nonce,
|
248
|
+
chainId: this.chainId,
|
249
|
+
},
|
250
|
+
ownerPeerIds
|
251
|
+
);
|
252
|
+
|
253
|
+
const validSignatures = signatures
|
254
|
+
.filter(
|
255
|
+
(s) => !!s.data && s.data !== "0x"
|
256
|
+
)
|
257
|
+
.filter((s) => {
|
258
|
+
|
259
|
+
try {
|
260
|
+
|
261
|
+
const address = getGnosisSignatureAddress({
|
262
|
+
message,
|
263
|
+
signature: s.data!,
|
264
|
+
chainId: this.chainId,
|
265
|
+
})
|
266
|
+
|
267
|
+
return address?.toLowerCase() === s.signer.toLowerCase();
|
268
|
+
|
269
|
+
} catch (error) {
|
270
|
+
return false
|
271
|
+
}
|
272
|
+
|
273
|
+
}) as Signature[];
|
274
|
+
|
275
|
+
console.log({
|
276
|
+
signatures,
|
277
|
+
validSignatures,
|
278
|
+
ownersThreshold: ownersThreshold.toString(),
|
279
|
+
});
|
280
|
+
|
281
|
+
if (
|
282
|
+
validSignatures.length === 0 ||
|
283
|
+
ownersThreshold.gt(validSignatures.length)
|
284
|
+
) {
|
285
|
+
await transaction.save();
|
286
|
+
transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
|
287
|
+
transaction.sourceStatus = "pending";
|
288
|
+
|
289
|
+
await transaction.save();
|
290
|
+
const errorMessage = signatures.find((s) => !!s.error)?.error;
|
291
|
+
throw new Error(
|
292
|
+
`Not enough signatures` + (errorMessage ? `: ${errorMessage} ` : "")
|
293
|
+
);
|
294
|
+
}
|
295
|
+
|
296
|
+
console.log(
|
297
|
+
`Executing transaction for execution ${transaction.transactionHash}`
|
298
|
+
);
|
299
|
+
|
300
|
+
const { data: txData } =
|
301
|
+
await this.sourceGnosisContract.populateTransaction.execTransaction(
|
302
|
+
gnosisTx.to,
|
303
|
+
gnosisTx.value,
|
304
|
+
gnosisTx.data,
|
305
|
+
gnosisTx.operation,
|
306
|
+
gnosisTx.safeTxGas,
|
307
|
+
gnosisTx.baseGas,
|
308
|
+
gnosisTx.gasPrice,
|
309
|
+
gnosisTx.gasToken,
|
310
|
+
gnosisTx.refundReceiver,
|
311
|
+
buildSignatureBytes(validSignatures)
|
312
|
+
);
|
313
|
+
|
314
|
+
const [gasPrice, gasLimit] = await Promise.all([
|
315
|
+
this.sourceProvider.getGasPrice(),
|
316
|
+
this.sourceProvider.estimateGas({
|
317
|
+
from: this.sourceWallet.address,
|
318
|
+
to: this.sourceGnosisContract.address,
|
319
|
+
data: txData,
|
320
|
+
}),
|
321
|
+
]);
|
322
|
+
|
323
|
+
const txSent = await this.sourceWallet.sendTransaction({
|
324
|
+
from: this.sourceWallet.address,
|
325
|
+
to: this.sourceGnosisContract.address,
|
326
|
+
gasPrice: gasPrice.mul(120).div(100),
|
327
|
+
gasLimit: 5_000_000,//gasLimit.mul(120).div(100),
|
328
|
+
data: txData,
|
329
|
+
});
|
330
|
+
|
331
|
+
console.log(txSent);
|
332
|
+
|
333
|
+
const receipt = await txSent.wait();
|
334
|
+
|
335
|
+
const parsedLogs: LogDescription[] = [];
|
336
|
+
|
337
|
+
receipt.logs.forEach((log) => {
|
338
|
+
try {
|
339
|
+
parsedLogs.push(this.sourceGnosisContract.interface.parseLog(log));
|
340
|
+
} catch (e) { }
|
341
|
+
});
|
342
|
+
|
343
|
+
if (parsedLogs.find((e) => e.name === "ExecutionSuccess")) {
|
344
|
+
console.log("ExecutionSuccess");
|
345
|
+
transaction.sourceStatus = "success";
|
346
|
+
if (txSent.blockNumber)
|
347
|
+
transaction.sourceBlockNumber = txSent.blockNumber;
|
348
|
+
transaction.sourceTransactionHash = txSent.hash;
|
349
|
+
transaction.sourceLogs = logs;
|
350
|
+
await transaction.save();
|
351
|
+
} else {
|
352
|
+
console.log("ExecutionFailure");
|
353
|
+
transaction.sourceStatus = "failed";
|
354
|
+
if (txSent.blockNumber)
|
355
|
+
transaction.sourceBlockNumber = txSent.blockNumber;
|
356
|
+
transaction.sourceTransactionHash = txSent.hash;
|
357
|
+
transaction.status = "failed";
|
358
|
+
await transaction.save();
|
359
|
+
}
|
360
|
+
|
361
|
+
protocol.sendTransaction(transaction);
|
362
|
+
}
|
363
|
+
|
364
|
+
async start(): Promise<void> {
|
365
|
+
this.blockConfirmationsCount = blockConfirmations[this.chainId] + 1;
|
366
|
+
|
367
|
+
this.sourceProvider = new JsonRpcRetryProvider(
|
368
|
+
getRpcProviderUrl(this.chainId)
|
369
|
+
);
|
370
|
+
|
371
|
+
this.sourceWallet = new ethers.Wallet(
|
372
|
+
config.privateKey!,
|
373
|
+
this.sourceProvider
|
374
|
+
);
|
375
|
+
|
376
|
+
this.sourceGnosisContract = getContract<GnosisSafe>(
|
377
|
+
addresses[this.chainId].gnosisSafe,
|
378
|
+
abi.gnosisSafe,
|
379
|
+
this.sourceWallet
|
380
|
+
);
|
381
|
+
|
382
|
+
await super.start();
|
383
|
+
}
|
384
|
+
}
|
@@ -0,0 +1,297 @@
|
|
1
|
+
import { BaseTask } from "../BaseTask";
|
2
|
+
import Logger from "@/logger";
|
3
|
+
import { ethers, Wallet } from "ethers";
|
4
|
+
import abi from "@/abi";
|
5
|
+
import { Transaction } from "@/db";
|
6
|
+
import {
|
7
|
+
buildSignatureBytes,
|
8
|
+
generateGnosisSignatureMessage,
|
9
|
+
generateGnosisTransaction,
|
10
|
+
getContract,
|
11
|
+
getGnosisOwnerPeerIds,
|
12
|
+
getGnosisSignatureAddress,
|
13
|
+
getRpcProviderUrl,
|
14
|
+
Signature,
|
15
|
+
} from "@/utils";
|
16
|
+
import { addresses, blockConfirmations } from "@/constants";
|
17
|
+
import { ChainId } from "@/types";
|
18
|
+
import config from "@/config";
|
19
|
+
import { GnosisSafe, InteropX } from "@/typechain";
|
20
|
+
import moment from "moment";
|
21
|
+
import { Op } from "sequelize";
|
22
|
+
import { buildGnosisAction } from "@/gnosis";
|
23
|
+
import { peerPool, protocol } from "@/net";
|
24
|
+
import { LogDescription } from "ethers/lib/utils";
|
25
|
+
import wait from "waait";
|
26
|
+
import { LiquidityError } from "@/errors";
|
27
|
+
import { JsonRpcRetryProvider } from "@/providers";
|
28
|
+
|
29
|
+
export default class ProcessValidateEvents extends BaseTask {
|
30
|
+
sourceProvider: JsonRpcRetryProvider;
|
31
|
+
chainId: ChainId;
|
32
|
+
leadNodeOnly: boolean = true;
|
33
|
+
blockConfirmationsCount: number = 12;
|
34
|
+
|
35
|
+
constructor({ chainId }: { chainId: ChainId }) {
|
36
|
+
super({
|
37
|
+
logger: new Logger("InteropX::ProcessValidateEvents"),
|
38
|
+
});
|
39
|
+
this.chainId = chainId;
|
40
|
+
}
|
41
|
+
|
42
|
+
async pollHandler() {
|
43
|
+
const currentBlockNumber = await this.sourceProvider.getBlockNumber();
|
44
|
+
|
45
|
+
const transaction = await Transaction.findOne({
|
46
|
+
where: {
|
47
|
+
status: "pending",
|
48
|
+
sourceStatus: "success",
|
49
|
+
targetStatus: "pending",
|
50
|
+
sourceChainId: this.chainId,
|
51
|
+
sourceBlockNumber: {
|
52
|
+
[Op.lt]: currentBlockNumber - this.blockConfirmationsCount,
|
53
|
+
},
|
54
|
+
targetDelayUntil: {
|
55
|
+
[Op.or]: {
|
56
|
+
[Op.is]: null,
|
57
|
+
[Op.lt]: new Date(),
|
58
|
+
},
|
59
|
+
},
|
60
|
+
|
61
|
+
submitEvent: { $ne: null },
|
62
|
+
validateEvent: { $ne: null },
|
63
|
+
|
64
|
+
createdAt: {
|
65
|
+
[Op.gt]: moment().subtract({ hours: 12 }).toDate(),
|
66
|
+
},
|
67
|
+
},
|
68
|
+
});
|
69
|
+
|
70
|
+
if (!transaction) {
|
71
|
+
return;
|
72
|
+
}
|
73
|
+
|
74
|
+
this.logger.debug(`Processing transaction ${transaction.transactionHash}`);
|
75
|
+
|
76
|
+
transaction.targetStatus = "proccessing";
|
77
|
+
await transaction.save();
|
78
|
+
|
79
|
+
const { sourceChainId, targetChainId } = transaction.validateEvent
|
80
|
+
|
81
|
+
const targetProvider = new JsonRpcRetryProvider(
|
82
|
+
getRpcProviderUrl(targetChainId as ChainId)
|
83
|
+
);
|
84
|
+
|
85
|
+
const targetWallet = new ethers.Wallet(
|
86
|
+
config.privateKey!,
|
87
|
+
targetProvider
|
88
|
+
);
|
89
|
+
|
90
|
+
const targetGnosisContract = getContract<GnosisSafe>(
|
91
|
+
addresses[targetChainId].gnosisSafe,
|
92
|
+
abi.gnosisSafe,
|
93
|
+
targetWallet
|
94
|
+
);
|
95
|
+
|
96
|
+
const ownersThreshold = await targetGnosisContract.getThreshold();
|
97
|
+
await wait(10000);
|
98
|
+
|
99
|
+
this.logger.debug(`Build gnosis action for ${transaction.transactionHash}`);
|
100
|
+
|
101
|
+
let data,
|
102
|
+
logs = [];
|
103
|
+
|
104
|
+
try {
|
105
|
+
({ data, logs } = await buildGnosisAction(transaction, "target"));
|
106
|
+
} catch (error) {
|
107
|
+
if (error instanceof LiquidityError) {
|
108
|
+
await transaction.save();
|
109
|
+
transaction.targetDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
|
110
|
+
transaction.targetStatus = "pending";
|
111
|
+
|
112
|
+
await transaction.save();
|
113
|
+
|
114
|
+
throw error;
|
115
|
+
return;
|
116
|
+
}
|
117
|
+
|
118
|
+
transaction.targetStatus = "failed";
|
119
|
+
transaction.targetErrors = [error.message];
|
120
|
+
transaction.status = "failed";
|
121
|
+
await transaction.save();
|
122
|
+
protocol.sendTransaction(transaction);
|
123
|
+
return;
|
124
|
+
}
|
125
|
+
|
126
|
+
this.logger.debug(
|
127
|
+
`Generating gnosis tx for ${transaction.transactionHash}`
|
128
|
+
);
|
129
|
+
|
130
|
+
let gnosisTx = await generateGnosisTransaction(
|
131
|
+
{
|
132
|
+
baseGas: "0",
|
133
|
+
data,
|
134
|
+
gasPrice: "0",
|
135
|
+
gasToken: "0x0000000000000000000000000000000000000000",
|
136
|
+
nonce: "0",
|
137
|
+
operation: "1",
|
138
|
+
refundReceiver: "0x0000000000000000000000000000000000000000",
|
139
|
+
safeAddress: targetGnosisContract.address,
|
140
|
+
safeTxGas: "79668",
|
141
|
+
to: addresses[transaction.targetChainId].multisend,
|
142
|
+
value: "0",
|
143
|
+
},
|
144
|
+
targetGnosisContract
|
145
|
+
);
|
146
|
+
|
147
|
+
const ownerPeerIds = await getGnosisOwnerPeerIds({
|
148
|
+
gnosisContract: targetGnosisContract,
|
149
|
+
});
|
150
|
+
|
151
|
+
console.log(
|
152
|
+
`Collecting signatures for execution ${transaction.transactionHash}`
|
153
|
+
);
|
154
|
+
|
155
|
+
console.log(ownerPeerIds);
|
156
|
+
|
157
|
+
const message = generateGnosisSignatureMessage({
|
158
|
+
to: addresses[targetChainId].multisend,
|
159
|
+
data,
|
160
|
+
chainId: targetChainId as ChainId,
|
161
|
+
safeTxGas: gnosisTx.safeTxGas,
|
162
|
+
nonce: gnosisTx.safeNonce,
|
163
|
+
});
|
164
|
+
|
165
|
+
const signatures = await protocol.requestSignatures(
|
166
|
+
{
|
167
|
+
type: "target",
|
168
|
+
transactionHash: transaction.transactionHash,
|
169
|
+
safeTxGas: gnosisTx.safeTxGas,
|
170
|
+
safeNonce: gnosisTx.nonce,
|
171
|
+
chainId: targetChainId,
|
172
|
+
},
|
173
|
+
ownerPeerIds
|
174
|
+
);
|
175
|
+
|
176
|
+
const validSignatures = signatures
|
177
|
+
.filter(
|
178
|
+
(s) => !!s.data && s.data !== "0x"
|
179
|
+
)
|
180
|
+
.filter((s) => {
|
181
|
+
|
182
|
+
try {
|
183
|
+
|
184
|
+
const address = getGnosisSignatureAddress({
|
185
|
+
message,
|
186
|
+
signature: s.data!,
|
187
|
+
chainId: targetChainId as ChainId,
|
188
|
+
})
|
189
|
+
|
190
|
+
return address?.toLowerCase() === s.signer.toLowerCase();
|
191
|
+
|
192
|
+
} catch (error) {
|
193
|
+
return false
|
194
|
+
}
|
195
|
+
|
196
|
+
}) as Signature[];
|
197
|
+
|
198
|
+
console.log({
|
199
|
+
signatures,
|
200
|
+
validSignatures,
|
201
|
+
ownersThreshold: ownersThreshold.toString(),
|
202
|
+
});
|
203
|
+
|
204
|
+
if (
|
205
|
+
validSignatures.length === 0 ||
|
206
|
+
ownersThreshold.gt(validSignatures.length)
|
207
|
+
) {
|
208
|
+
await transaction.save();
|
209
|
+
transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
|
210
|
+
transaction.targetStatus = "pending";
|
211
|
+
|
212
|
+
await transaction.save();
|
213
|
+
const errorMessage = signatures.find((s) => !!s.error)?.error;
|
214
|
+
throw new Error(
|
215
|
+
`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : "")
|
216
|
+
);
|
217
|
+
}
|
218
|
+
|
219
|
+
console.log(
|
220
|
+
`Executing transaction for execution ${transaction.transactionHash}`
|
221
|
+
);
|
222
|
+
|
223
|
+
const { data: txData } =
|
224
|
+
await targetGnosisContract.populateTransaction.execTransaction(
|
225
|
+
gnosisTx.to,
|
226
|
+
gnosisTx.value,
|
227
|
+
gnosisTx.data,
|
228
|
+
gnosisTx.operation,
|
229
|
+
gnosisTx.safeTxGas,
|
230
|
+
gnosisTx.baseGas,
|
231
|
+
gnosisTx.gasPrice,
|
232
|
+
gnosisTx.gasToken,
|
233
|
+
gnosisTx.refundReceiver,
|
234
|
+
buildSignatureBytes(validSignatures)
|
235
|
+
);
|
236
|
+
|
237
|
+
const [gasPrice, gasLimit] = await Promise.all([
|
238
|
+
targetProvider.getGasPrice(),
|
239
|
+
targetProvider.estimateGas({
|
240
|
+
from: targetWallet.address,
|
241
|
+
to: targetGnosisContract.address,
|
242
|
+
data: txData,
|
243
|
+
}),
|
244
|
+
]);
|
245
|
+
|
246
|
+
const txSent = await targetWallet.sendTransaction({
|
247
|
+
from: targetWallet.address,
|
248
|
+
to: targetGnosisContract.address,
|
249
|
+
gasPrice: gasPrice.mul(120).div(100),
|
250
|
+
gasLimit: 5_000_000,//gasLimit.mul(120).div(100),
|
251
|
+
data: txData,
|
252
|
+
});
|
253
|
+
|
254
|
+
console.log(txSent);
|
255
|
+
|
256
|
+
const receipt = await txSent.wait();
|
257
|
+
|
258
|
+
const parsedLogs: LogDescription[] = [];
|
259
|
+
|
260
|
+
receipt.logs.forEach((log) => {
|
261
|
+
try {
|
262
|
+
parsedLogs.push(targetGnosisContract.interface.parseLog(log));
|
263
|
+
} catch (e) { }
|
264
|
+
});
|
265
|
+
|
266
|
+
if (parsedLogs.find((e) => e.name === "ExecutionSuccess")) {
|
267
|
+
console.log("ExecutionSuccess");
|
268
|
+
transaction.targetStatus = "success";
|
269
|
+
transaction.status = "success";
|
270
|
+
if (txSent.blockNumber)
|
271
|
+
transaction.targetBlockNumber = txSent.blockNumber;
|
272
|
+
transaction.targetTransactionHash = txSent.hash;
|
273
|
+
transaction.targetLogs = logs;
|
274
|
+
await transaction.save();
|
275
|
+
} else {
|
276
|
+
console.log("ExecutionFailure");
|
277
|
+
transaction.targetStatus = "failed";
|
278
|
+
if (txSent.blockNumber)
|
279
|
+
transaction.targetBlockNumber = txSent.blockNumber;
|
280
|
+
transaction.targetTransactionHash = txSent.hash;
|
281
|
+
transaction.status = "failed";
|
282
|
+
await transaction.save();
|
283
|
+
}
|
284
|
+
|
285
|
+
protocol.sendTransaction(transaction);
|
286
|
+
}
|
287
|
+
|
288
|
+
async start(): Promise<void> {
|
289
|
+
this.blockConfirmationsCount = blockConfirmations[this.chainId] + 1;
|
290
|
+
|
291
|
+
this.sourceProvider = new JsonRpcRetryProvider(
|
292
|
+
getRpcProviderUrl(this.chainId)
|
293
|
+
);
|
294
|
+
|
295
|
+
await super.start();
|
296
|
+
}
|
297
|
+
}
|