@instadapp/interop-x 0.0.0-dev.fabee70 → 0.0.0-dev.fac2c15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +19 -0
- package/dist/package.json +18 -14
- 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 +6 -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/config/index.js +10 -1
- package/dist/src/constants/addresses.js +6 -7
- package/dist/src/constants/blockConfirmations.js +8 -0
- package/dist/src/constants/index.js +1 -1
- package/dist/src/constants/tokens.js +62 -39
- package/dist/src/db/models/transaction.js +41 -15
- package/dist/src/errors/index.js +10 -0
- package/dist/src/gnosis/actions/aaveV2/index.js +11 -0
- package/dist/src/gnosis/actions/aaveV2/source.js +73 -0
- package/dist/src/gnosis/actions/aaveV2/target.js +86 -0
- package/dist/src/gnosis/actions/index.js +9 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +34 -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/tasks/AutoUpdateTask.js +20 -7
- package/dist/src/tasks/BaseTask.js +4 -0
- package/dist/src/tasks/InteropX/ProcessSubmitSubmitEvents.js +180 -0
- package/dist/src/tasks/InteropX/ProcessValidateEvents.js +184 -0
- package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +112 -0
- package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +87 -0
- package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +105 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +8 -3
- package/dist/src/tasks/index.js +21 -19
- package/dist/src/typechain/{InteropBridgeToken.js → InstList.js} +0 -0
- package/dist/src/typechain/{InteropXGateway.js → InteropX.js} +0 -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 +5 -5
- package/dist/src/typechain/index.js +5 -5
- package/dist/src/utils/async.js +18 -0
- package/dist/src/utils/dsa.js +24 -0
- package/dist/src/utils/formatting.js +17 -0
- package/dist/src/utils/gnosis.js +62 -0
- package/dist/src/utils/http.js +10 -0
- package/dist/src/utils/index.js +20 -235
- package/dist/src/utils/interop.js +16 -0
- package/dist/src/utils/web3.js +92 -0
- package/package.json +18 -14
- 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 +9 -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/config/index.ts +9 -1
- package/src/constants/addresses.ts +7 -8
- package/src/constants/blockConfirmations.ts +5 -0
- package/src/constants/index.ts +1 -1
- package/src/constants/tokens.ts +63 -40
- package/src/db/models/transaction.ts +159 -65
- package/src/errors/index.ts +6 -0
- package/src/gnosis/actions/aaveV2/index.ts +9 -0
- package/src/gnosis/actions/aaveV2/source.ts +118 -0
- package/src/gnosis/actions/aaveV2/target.ts +141 -0
- package/src/gnosis/actions/index.ts +5 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +47 -26
- 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/tasks/AutoUpdateTask.ts +24 -15
- package/src/tasks/BaseTask.ts +5 -0
- package/src/tasks/InteropX/ProcessSubmitSubmitEvents.ts +267 -0
- package/src/tasks/InteropX/ProcessValidateEvents.ts +272 -0
- package/src/tasks/InteropX/SyncLogExecuteEvents.ts +160 -0
- package/src/tasks/InteropX/SyncLogSubmitEvents.ts +137 -0
- package/src/tasks/InteropX/SyncLogValidateEvents.ts +150 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +8 -3
- package/src/tasks/index.ts +26 -20
- package/src/typechain/InstList.ts +402 -0
- package/src/typechain/InteropX.ts +1216 -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 +2 -2
- package/src/typechain/index.ts +4 -4
- package/src/utils/async.ts +22 -0
- package/src/utils/dsa.ts +30 -0
- package/src/utils/formatting.ts +15 -0
- package/src/utils/gnosis.ts +123 -0
- package/src/utils/http.ts +6 -0
- package/src/utils/index.ts +7 -319
- package/src/utils/interop.ts +28 -0
- package/src/utils/web3.ts +131 -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
package/dist/src/index.js
CHANGED
@@ -3,22 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
"@/logger": __dirname + "/logger",
|
10
|
-
"@/tasks": __dirname + "/tasks",
|
11
|
-
"@/utils": __dirname + "/utils",
|
12
|
-
"@/api": __dirname + "/api",
|
13
|
-
"@/net": __dirname + "/net",
|
14
|
-
"@/db": __dirname + "/db",
|
15
|
-
"@/config": __dirname + "/config",
|
16
|
-
"@/types": __dirname + "/types",
|
17
|
-
"@/abi": __dirname + "/abi",
|
18
|
-
"@/constants": __dirname + "/constants",
|
19
|
-
"@/typechain": __dirname + "/typechain"
|
20
|
-
});
|
21
|
-
(0, module_alias_1.default)();
|
6
|
+
require("./alias");
|
7
|
+
const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
22
9
|
const dotenv_1 = __importDefault(require("dotenv"));
|
23
10
|
const chalk_1 = __importDefault(require("chalk"));
|
24
11
|
const ethers_1 = require("ethers");
|
@@ -26,18 +13,39 @@ const package_json_1 = __importDefault(require("../package.json"));
|
|
26
13
|
dotenv_1.default.config();
|
27
14
|
const logger_1 = __importDefault(require("@/logger"));
|
28
15
|
const logger = new logger_1.default('Process');
|
16
|
+
const GIT_SHORT_HASH = 'fac2c15';
|
29
17
|
const printUsage = () => {
|
18
|
+
console.log();
|
19
|
+
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
20
|
+
console.log();
|
30
21
|
console.log('Usage:');
|
31
|
-
console.log('
|
32
|
-
console.log('
|
33
|
-
console.log(
|
34
|
-
console.log('
|
22
|
+
console.log(' interop-x help Show this message');
|
23
|
+
console.log(' interop-x version Print out the installed version of Interop X');
|
24
|
+
console.log();
|
25
|
+
console.log(' interop-x down Put the node into maintenance mode');
|
26
|
+
console.log(' interop-x up Take the node out of maintenance mode');
|
27
|
+
console.log();
|
28
|
+
console.log(' PRIVATE_KEY=abcd1234 interop-x Start the node with the given private key');
|
29
|
+
console.log(' PRIVATE_KEY=abcd1234 STAGING=true interop-x Start the node in staging mode');
|
30
|
+
console.log(' PRIVATE_KEY=abcd1234 AUTO_UPDATE=true interop-x Start the node in auto update mode');
|
31
|
+
console.log(' PRIVATE_KEY=abcd1234 API_HOST=0.0.0.0 API_PORT=8080 interop-x Start the node with custom API host and port');
|
32
|
+
console.log();
|
35
33
|
};
|
36
34
|
if (process.argv.at(-1) === 'help') {
|
37
35
|
printUsage();
|
38
36
|
process.exit(0);
|
39
37
|
}
|
40
|
-
const
|
38
|
+
const basePath = (0, expand_home_dir_1.default)(`~/.interop-x`);
|
39
|
+
if (process.argv.at(-1) === 'down') {
|
40
|
+
fs_extra_1.default.outputFileSync(basePath + '/maintenance', Date.now().toString());
|
41
|
+
console.log(chalk_1.default.red('Maintenance mode enabled'));
|
42
|
+
process.exit(0);
|
43
|
+
}
|
44
|
+
if (process.argv.at(-1) === 'up') {
|
45
|
+
fs_extra_1.default.removeSync(basePath + '/maintenance');
|
46
|
+
console.log(chalk_1.default.green('Maintenance mode disabled'));
|
47
|
+
process.exit(0);
|
48
|
+
}
|
41
49
|
if (process.argv.at(-1) === 'version') {
|
42
50
|
console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
|
43
51
|
process.exit(0);
|
@@ -64,7 +72,9 @@ const utils_1 = require("./utils");
|
|
64
72
|
async function main() {
|
65
73
|
(0, net_1.startPeer)({});
|
66
74
|
const tasks = new tasks_1.Tasks();
|
67
|
-
|
75
|
+
setTimeout(() => {
|
76
|
+
tasks.start();
|
77
|
+
}, 10000);
|
68
78
|
(0, api_1.startApiServer)();
|
69
79
|
net_1.protocol.on('TransactionStatus', async (payload) => {
|
70
80
|
if (!net_1.peerPool.isLeadNode(payload.peerId)) {
|
@@ -82,9 +92,11 @@ async function main() {
|
|
82
92
|
transaction.sourceStatus = payload.data.sourceStatus;
|
83
93
|
transaction.sourceTransactionHash = payload.data.sourceTransactionHash;
|
84
94
|
transaction.sourceErrors = payload.data.sourceErrors;
|
95
|
+
transaction.sourceLogs = payload.data.sourceLogs;
|
85
96
|
transaction.targetStatus = payload.data.targetStatus;
|
86
97
|
transaction.targetTransactionHash = payload.data.targetTransactionHash;
|
87
98
|
transaction.targetErrors = payload.data.targetErrors;
|
99
|
+
transaction.targetLogs = payload.data.targetLogs;
|
88
100
|
transaction.status = payload.data.status;
|
89
101
|
await transaction.save();
|
90
102
|
});
|
@@ -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
|
-
|
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[
|
45
|
-
data:
|
46
|
-
chainId:
|
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 });
|
package/dist/src/net/protocol/dial/{SignatureDialProtocol.1.js → TransactionStatusDialProtocol.js}
RENAMED
@@ -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
|
}
|
@@ -10,7 +10,7 @@ const SignatureDialProtocol_1 = require("./dial/SignatureDialProtocol");
|
|
10
10
|
const __1 = require("..");
|
11
11
|
const config_1 = __importDefault(require("@/config"));
|
12
12
|
const types_1 = require("@/types");
|
13
|
-
const
|
13
|
+
const TransactionStatusDialProtocol_1 = require("./dial/TransactionStatusDialProtocol");
|
14
14
|
class Protocol extends stream_1.EventEmitter {
|
15
15
|
constructor() {
|
16
16
|
super(...arguments);
|
@@ -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
|
},
|
@@ -65,7 +75,7 @@ class Protocol extends stream_1.EventEmitter {
|
|
65
75
|
});
|
66
76
|
});
|
67
77
|
this.signature = new SignatureDialProtocol_1.SignatureDialProtocol(this.libp2p);
|
68
|
-
this.transactionStatus = new
|
78
|
+
this.transactionStatus = new TransactionStatusDialProtocol_1.TransactionStatusDialProtocol(this.libp2p);
|
69
79
|
}
|
70
80
|
init() {
|
71
81
|
this.libp2p.pubsub.subscribe(this.topic);
|
@@ -5,18 +5,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
const BaseTask_1 = require("./BaseTask");
|
7
7
|
const logger_1 = __importDefault(require("@/logger"));
|
8
|
-
const utils_1 = require("@/utils");
|
9
8
|
const await_spawn_1 = __importDefault(require("await-spawn"));
|
9
|
+
const child_process_1 = require("child_process");
|
10
10
|
const config_1 = __importDefault(require("@/config"));
|
11
11
|
const waait_1 = __importDefault(require("waait"));
|
12
12
|
const package_json_1 = __importDefault(require("../../package.json"));
|
13
13
|
const currentVersion = package_json_1.default.version;
|
14
|
+
const tag = config_1.default.staging ? 'dev' : 'latest';
|
14
15
|
class AutoUpdateTask extends BaseTask_1.BaseTask {
|
15
16
|
constructor() {
|
16
17
|
super({
|
17
18
|
logger: new logger_1.default("AutoUpdateTask"),
|
18
19
|
});
|
19
|
-
this.pollIntervalMs = 60 *
|
20
|
+
this.pollIntervalMs = 60 * 10 * 1000;
|
20
21
|
}
|
21
22
|
prePollHandler() {
|
22
23
|
return config_1.default.autoUpdate && !config_1.default.isLeadNode();
|
@@ -31,15 +32,24 @@ class AutoUpdateTask extends BaseTask_1.BaseTask {
|
|
31
32
|
return currentVersion;
|
32
33
|
}
|
33
34
|
}
|
35
|
+
async getLatestVersion() {
|
36
|
+
try {
|
37
|
+
const stdout = await (0, await_spawn_1.default)('npm', ['view', `${package_json_1.default.name}@${tag}`, 'version']);
|
38
|
+
return stdout.toString().trim();
|
39
|
+
}
|
40
|
+
catch (error) {
|
41
|
+
this.logger.error(error);
|
42
|
+
return currentVersion;
|
43
|
+
}
|
44
|
+
}
|
34
45
|
async pollHandler() {
|
35
|
-
const
|
36
|
-
const version = data['dist-tags'].latest;
|
46
|
+
const version = await this.getLatestVersion();
|
37
47
|
if (version === currentVersion) {
|
38
48
|
return;
|
39
49
|
}
|
40
50
|
this.logger.warn(`New version ${version} available.`);
|
41
51
|
this.logger.info('Updating...');
|
42
|
-
await (0, await_spawn_1.default)('npm', ['-g', 'install',
|
52
|
+
await (0, await_spawn_1.default)('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
|
43
53
|
await (0, waait_1.default)(5000);
|
44
54
|
if (version !== await this.getInstalledVersion()) {
|
45
55
|
this.logger.warn(`failed to install ${version}, retrying in 5 minutes`);
|
@@ -47,10 +57,13 @@ class AutoUpdateTask extends BaseTask_1.BaseTask {
|
|
47
57
|
}
|
48
58
|
this.logger.warn(`Installed version ${version}`);
|
49
59
|
this.logger.warn(`Restarting...`);
|
50
|
-
|
60
|
+
// TODO: its restarting in the bg, but it should be in the fg
|
61
|
+
const subprocess = (0, child_process_1.spawn)(process.argv[0], process.argv.slice(1), {
|
51
62
|
cwd: process.cwd(),
|
52
|
-
stdio: "inherit"
|
63
|
+
stdio: "inherit",
|
64
|
+
// shell: process.env.SHELL,
|
53
65
|
});
|
66
|
+
subprocess.unref();
|
54
67
|
process.exit();
|
55
68
|
}
|
56
69
|
}
|
@@ -35,6 +35,10 @@ class BaseTask extends events_1.default {
|
|
35
35
|
}
|
36
36
|
}
|
37
37
|
prePollHandler() {
|
38
|
+
if (config_1.default.isMaintenanceMode()) {
|
39
|
+
this.logger.warn('Maintenance mode is enabled. Skipping task.');
|
40
|
+
return false;
|
41
|
+
}
|
38
42
|
if (this.exceptLeadNode) {
|
39
43
|
return !config_1.default.isLeadNode();
|
40
44
|
}
|
@@ -0,0 +1,180 @@
|
|
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 ProcessSubmitEvents extends BaseTask_1.BaseTask {
|
21
|
+
constructor({ chainId }) {
|
22
|
+
super({
|
23
|
+
logger: new logger_1.default("InteropX::ProcessSubmitSubmitEvents"),
|
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: "pending",
|
36
|
+
sourceChainId: this.chainId,
|
37
|
+
submitBlockNumber: {
|
38
|
+
[sequelize_1.Op.lt]: currentBlockNumber - this.blockConfirmationsCount,
|
39
|
+
},
|
40
|
+
sourceDelayUntil: {
|
41
|
+
[sequelize_1.Op.or]: {
|
42
|
+
[sequelize_1.Op.is]: null,
|
43
|
+
[sequelize_1.Op.lt]: new Date(),
|
44
|
+
},
|
45
|
+
},
|
46
|
+
submitEvent: { $ne: null },
|
47
|
+
createdAt: {
|
48
|
+
[sequelize_1.Op.gt]: (0, moment_1.default)().subtract({ hours: 12 }).toDate(),
|
49
|
+
},
|
50
|
+
},
|
51
|
+
});
|
52
|
+
if (!transaction) {
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
this.logger.debug(`Processing transaction ${transaction.transactionHash}`);
|
56
|
+
transaction.sourceStatus = "proccessing";
|
57
|
+
await transaction.save();
|
58
|
+
const ownersThreshold = await this.sourceGnosisContract.getThreshold();
|
59
|
+
await (0, waait_1.default)(10000);
|
60
|
+
this.logger.debug(`Build gnosis action for ${transaction.transactionHash}`);
|
61
|
+
let data, logs = [];
|
62
|
+
try {
|
63
|
+
({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction, "source"));
|
64
|
+
}
|
65
|
+
catch (error) {
|
66
|
+
if (error instanceof errors_1.LiquidityError) {
|
67
|
+
await transaction.save();
|
68
|
+
transaction.sourceDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
|
69
|
+
transaction.sourceStatus = "pending";
|
70
|
+
await transaction.save();
|
71
|
+
throw error;
|
72
|
+
return;
|
73
|
+
}
|
74
|
+
transaction.sourceStatus = "failed";
|
75
|
+
transaction.sourceErrors = [error.message];
|
76
|
+
transaction.targetStatus = "failed";
|
77
|
+
transaction.status = "failed";
|
78
|
+
await transaction.save();
|
79
|
+
net_1.protocol.sendTransaction(transaction);
|
80
|
+
return;
|
81
|
+
}
|
82
|
+
this.logger.debug(`Generating gnosis tx for ${transaction.transactionHash}`);
|
83
|
+
let gnosisTx = await (0, utils_1.generateGnosisTransaction)({
|
84
|
+
baseGas: "0",
|
85
|
+
data,
|
86
|
+
gasPrice: "0",
|
87
|
+
gasToken: "0x0000000000000000000000000000000000000000",
|
88
|
+
nonce: "0",
|
89
|
+
operation: "1",
|
90
|
+
refundReceiver: "0x0000000000000000000000000000000000000000",
|
91
|
+
safeAddress: this.sourceGnosisContract.address,
|
92
|
+
safeTxGas: "79668",
|
93
|
+
to: constants_1.addresses[transaction.sourceChainId].multisend,
|
94
|
+
value: "0",
|
95
|
+
}, this.sourceGnosisContract);
|
96
|
+
const owners = await this.sourceGnosisContract
|
97
|
+
.getOwners()
|
98
|
+
.then((owners) => owners.map((owner) => owner.toLowerCase()));
|
99
|
+
const ownerPeerIds = net_1.peerPool.activePeers
|
100
|
+
.filter((peer) => owners.includes(peer.publicAddress.toLowerCase()))
|
101
|
+
.map((peer) => peer.id);
|
102
|
+
console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
|
103
|
+
console.log(ownerPeerIds);
|
104
|
+
const signatures = await net_1.protocol.requestSignatures({
|
105
|
+
type: "source",
|
106
|
+
transactionHash: transaction.transactionHash,
|
107
|
+
safeTxGas: gnosisTx.safeTxGas,
|
108
|
+
safeNonce: gnosisTx.nonce,
|
109
|
+
chainId: this.chainId,
|
110
|
+
}, ownerPeerIds);
|
111
|
+
const validSignatures = signatures.filter((s) => !!s.data && s.data !== "0x");
|
112
|
+
console.log({
|
113
|
+
signatures,
|
114
|
+
validSignatures,
|
115
|
+
ownersThreshold: ownersThreshold.toString(),
|
116
|
+
});
|
117
|
+
if (validSignatures.length === 0 ||
|
118
|
+
ownersThreshold.gt(validSignatures.length)) {
|
119
|
+
await transaction.save();
|
120
|
+
transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
|
121
|
+
transaction.sourceStatus = "pending";
|
122
|
+
await transaction.save();
|
123
|
+
const errorMessage = (_a = signatures.find((s) => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
|
124
|
+
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ""));
|
125
|
+
}
|
126
|
+
console.log(`Executing transaction for execution ${transaction.transactionHash}`);
|
127
|
+
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));
|
128
|
+
const [gasPrice, gasLimit] = await Promise.all([
|
129
|
+
this.sourceProvider.getGasPrice(),
|
130
|
+
this.sourceProvider.estimateGas({
|
131
|
+
from: this.sourceWallet.address,
|
132
|
+
to: this.sourceGnosisContract.address,
|
133
|
+
data: txData,
|
134
|
+
}),
|
135
|
+
]);
|
136
|
+
const txSent = await this.sourceWallet.sendTransaction({
|
137
|
+
from: this.sourceWallet.address,
|
138
|
+
to: this.sourceGnosisContract.address,
|
139
|
+
gasPrice: gasPrice.mul(120).div(100),
|
140
|
+
gasLimit: 5000000,
|
141
|
+
data: txData,
|
142
|
+
});
|
143
|
+
console.log(txSent);
|
144
|
+
const receipt = await txSent.wait();
|
145
|
+
const parsedLogs = [];
|
146
|
+
receipt.logs.forEach((log) => {
|
147
|
+
try {
|
148
|
+
parsedLogs.push(this.sourceGnosisContract.interface.parseLog(log));
|
149
|
+
}
|
150
|
+
catch (e) { }
|
151
|
+
});
|
152
|
+
if (parsedLogs.find((e) => e.name === "ExecutionSuccess")) {
|
153
|
+
console.log("ExecutionSuccess");
|
154
|
+
transaction.sourceStatus = "success";
|
155
|
+
if (txSent.blockNumber)
|
156
|
+
transaction.sourceBlockNumber = txSent.blockNumber;
|
157
|
+
transaction.sourceTransactionHash = txSent.hash;
|
158
|
+
transaction.sourceLogs = logs;
|
159
|
+
await transaction.save();
|
160
|
+
}
|
161
|
+
else {
|
162
|
+
console.log("ExecutionFailure");
|
163
|
+
transaction.sourceStatus = "failed";
|
164
|
+
if (txSent.blockNumber)
|
165
|
+
transaction.sourceBlockNumber = txSent.blockNumber;
|
166
|
+
transaction.sourceTransactionHash = txSent.hash;
|
167
|
+
transaction.status = "failed";
|
168
|
+
await transaction.save();
|
169
|
+
}
|
170
|
+
net_1.protocol.sendTransaction(transaction);
|
171
|
+
}
|
172
|
+
async start() {
|
173
|
+
this.blockConfirmationsCount = constants_1.blockConfirmations[this.chainId] + 1;
|
174
|
+
this.sourceProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
175
|
+
this.sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, this.sourceProvider);
|
176
|
+
this.sourceGnosisContract = (0, utils_1.getContract)(constants_1.addresses[this.chainId].gnosisSafe, abi_1.default.gnosisSafe, this.sourceWallet);
|
177
|
+
await super.start();
|
178
|
+
}
|
179
|
+
}
|
180
|
+
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;
|