@instadapp/interop-x 0.0.0-dev.0b0cc3f → 0.0.0-dev.107fdbd
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/.env.example +2 -1
- package/.github/workflows/ci.yml +19 -0
- package/bin/interop-x +1 -1
- package/dist/package.json +75 -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/{abi → src/abi}/erc20.json +0 -0
- package/dist/{abi → src/abi}/gnosisSafe.json +0 -0
- package/dist/{abi → src/abi}/index.js +4 -4
- package/dist/src/abi/interopX.json +1436 -0
- package/dist/src/alias.js +10 -0
- package/dist/src/api/index.js +36 -0
- package/dist/src/config/index.js +31 -0
- package/dist/src/constants/addresses.js +17 -0
- package/dist/{constants → src/constants}/index.js +1 -0
- package/dist/src/constants/tokens.js +130 -0
- package/dist/{db → src/db}/index.js +0 -0
- package/dist/{db → src/db}/models/index.js +0 -0
- package/dist/{db → src/db}/models/transaction.js +29 -9
- package/dist/{db → src/db}/sequelize.js +2 -1
- package/dist/src/gnosis/actions/aaveV2/index.js +11 -0
- package/dist/src/gnosis/actions/aaveV2/source.js +62 -0
- package/dist/src/gnosis/actions/aaveV2/target.js +8 -0
- package/dist/src/gnosis/actions/index.js +9 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +119 -0
- package/dist/{logger → src/logger}/index.js +0 -0
- package/dist/{net → src/net}/index.js +0 -0
- package/dist/{net → src/net}/peer/index.js +8 -3
- package/dist/{net → src/net}/pool/index.js +32 -9
- package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +0 -0
- package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +21 -12
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
- package/dist/{net → src/net}/protocol/index.js +51 -1
- package/dist/src/tasks/AutoUpdateTask.js +70 -0
- package/dist/{tasks → src/tasks}/BaseTask.js +12 -4
- package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +84 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +58 -0
- package/dist/src/tasks/index.js +34 -0
- package/dist/{typechain → src/typechain}/Erc20.js +0 -0
- package/dist/{typechain → src/typechain}/GnosisSafe.js +0 -0
- package/dist/{typechain/InteropBridgeToken.js → src/typechain/InteropX.js} +0 -0
- package/dist/{typechain → src/typechain}/common.js +0 -0
- package/dist/{typechain → src/typechain}/factories/Erc20__factory.js +0 -0
- package/dist/{typechain → src/typechain}/factories/GnosisSafe__factory.js +0 -0
- package/dist/src/typechain/factories/InteropX__factory.js +1928 -0
- package/dist/src/typechain/factories/index.js +12 -0
- package/dist/{typechain → src/typechain}/index.js +3 -5
- package/dist/{types.js → src/types.js} +0 -0
- package/dist/src/utils/index.js +222 -0
- package/package.json +25 -29
- package/patches/@ethersproject+properties+5.6.0.patch +13 -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 +7 -7
- package/src/abi/interopX.json +1436 -0
- package/src/alias.ts +6 -0
- package/src/api/index.ts +36 -0
- package/src/config/index.ts +17 -1
- package/src/constants/addresses.ts +5 -16
- package/src/constants/index.ts +1 -0
- package/src/constants/tokens.ts +127 -0
- package/src/db/models/transaction.ts +69 -25
- package/src/db/sequelize.ts +2 -1
- package/src/gnosis/actions/aaveV2/index.ts +9 -0
- package/src/gnosis/actions/aaveV2/source.ts +104 -0
- package/src/gnosis/actions/aaveV2/target.ts +13 -0
- package/src/gnosis/actions/index.ts +5 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +107 -7
- package/src/net/peer/index.ts +9 -7
- package/src/net/pool/index.ts +41 -11
- package/src/net/protocol/dial/SignatureDialProtocol.ts +23 -13
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
- package/src/net/protocol/index.ts +67 -1
- package/src/tasks/AutoUpdateTask.ts +82 -0
- package/src/tasks/BaseTask.ts +14 -4
- package/src/tasks/InteropX/SyncLogSubmitEvents.ts +136 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +70 -0
- package/src/tasks/index.ts +17 -5
- package/src/typechain/InteropX.ts +1216 -0
- package/src/typechain/factories/InteropX__factory.ts +1932 -0
- package/src/typechain/factories/index.ts +1 -2
- package/src/typechain/index.ts +2 -4
- package/src/utils/index.ts +281 -45
- package/tsconfig.json +7 -2
- package/dist/abi/interopBridgeToken.json +0 -286
- package/dist/abi/interopXGateway.json +0 -184
- package/dist/config/index.js +0 -17
- package/dist/constants/addresses.js +0 -28
- package/dist/index.js +0 -43
- package/dist/tasks/InteropXGateway/SyncDepositEvents.js +0 -79
- package/dist/tasks/index.js +0 -27
- package/dist/typechain/InteropXGateway.js +0 -2
- package/dist/typechain/factories/InteropBridgeToken__factory.js +0 -459
- package/dist/typechain/factories/InteropXGateway__factory.js +0 -265
- package/dist/typechain/factories/index.js +0 -14
- package/dist/utils/index.js +0 -101
- package/src/abi/interopBridgeToken.json +0 -286
- package/src/abi/interopXGateway.json +0 -184
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -114
- 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
|
@@ -8,38 +8,47 @@ const BaseDialProtocol_1 = require("./BaseDialProtocol");
|
|
|
8
8
|
const waait_1 = __importDefault(require("waait"));
|
|
9
9
|
const config_1 = __importDefault(require("@/config"));
|
|
10
10
|
const db_1 = require("@/db");
|
|
11
|
+
const utils_1 = require("@/utils");
|
|
12
|
+
const constants_1 = require("@/constants");
|
|
13
|
+
const gnosis_1 = require("@/gnosis");
|
|
11
14
|
class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
|
12
15
|
constructor(libp2p) {
|
|
13
16
|
super(libp2p, '/interop-x/signatures');
|
|
14
17
|
this.timeout = 30000;
|
|
15
18
|
}
|
|
16
19
|
async response(data) {
|
|
20
|
+
console.log({
|
|
21
|
+
tag: 'SignatureDialProtocol',
|
|
22
|
+
data
|
|
23
|
+
});
|
|
17
24
|
const signer = config_1.default.wallet;
|
|
18
|
-
let
|
|
25
|
+
let transaction;
|
|
19
26
|
let maxTimeout = 20000;
|
|
20
27
|
do {
|
|
21
|
-
|
|
22
|
-
if (!
|
|
28
|
+
transaction = await db_1.Transaction.findOne({ where: { transactionHash: data.transactionHash } });
|
|
29
|
+
if (!transaction) {
|
|
23
30
|
await (0, waait_1.default)(1000);
|
|
24
31
|
maxTimeout -= 1000;
|
|
25
32
|
}
|
|
26
|
-
} while (!
|
|
27
|
-
if (!
|
|
33
|
+
} while (!transaction && maxTimeout > 0);
|
|
34
|
+
if (!transaction) {
|
|
28
35
|
return {
|
|
29
36
|
signer: signer.address,
|
|
30
37
|
data: null,
|
|
31
38
|
error: 'Event not found'
|
|
32
39
|
};
|
|
33
40
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
const { data: gnosisData } = await (0, gnosis_1.buildGnosisAction)(transaction, data.type);
|
|
42
|
+
const signedData = await (0, utils_1.signGnosisSafeTx)({
|
|
43
|
+
to: constants_1.addresses[transaction.sourceChainId].multisend,
|
|
44
|
+
data: gnosisData,
|
|
45
|
+
chainId: transaction.sourceChainId,
|
|
46
|
+
safeTxGas: data.safeTxGas,
|
|
47
|
+
nonce: data.safeNonce,
|
|
48
|
+
}, { signer });
|
|
40
49
|
return {
|
|
41
50
|
signer: signer.address,
|
|
42
|
-
data:
|
|
51
|
+
data: signedData
|
|
43
52
|
};
|
|
44
53
|
}
|
|
45
54
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionStatusDialProtocol = void 0;
|
|
4
|
+
const BaseDialProtocol_1 = require("./BaseDialProtocol");
|
|
5
|
+
const db_1 = require("@/db");
|
|
6
|
+
class TransactionStatusDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
|
7
|
+
constructor(libp2p) {
|
|
8
|
+
super(libp2p, '/interop-x/transaction-status');
|
|
9
|
+
this.timeout = 30000;
|
|
10
|
+
}
|
|
11
|
+
async response(transactionHash) {
|
|
12
|
+
const transaction = await db_1.Transaction.findOne({ where: { transactionHash } });
|
|
13
|
+
if (!transaction) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
transactionHash: transaction.transactionHash,
|
|
18
|
+
sourceStatus: transaction.sourceStatus,
|
|
19
|
+
sourceTransactionHash: transaction.sourceTransactionHash,
|
|
20
|
+
sourceErrors: transaction.sourceErrors,
|
|
21
|
+
sourceLogs: transaction.sourceLogs,
|
|
22
|
+
targetStatus: transaction.targetStatus,
|
|
23
|
+
targetTransactionHash: transaction.targetTransactionHash,
|
|
24
|
+
targetErrors: transaction.targetErrors,
|
|
25
|
+
targetLogs: transaction.targetLogs,
|
|
26
|
+
status: transaction.status,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.TransactionStatusDialProtocol = TransactionStatusDialProtocol;
|
|
@@ -10,13 +10,14 @@ 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 TransactionStatusDialProtocol_1 = require("./dial/TransactionStatusDialProtocol");
|
|
13
14
|
class Protocol extends stream_1.EventEmitter {
|
|
14
15
|
constructor() {
|
|
15
16
|
super(...arguments);
|
|
16
17
|
this.protocolMessages = [
|
|
17
18
|
{
|
|
18
19
|
name: 'PeerInfo',
|
|
19
|
-
code:
|
|
20
|
+
code: 0x01,
|
|
20
21
|
encode: (info) => [
|
|
21
22
|
Buffer.from(info.publicAddress),
|
|
22
23
|
],
|
|
@@ -24,6 +25,40 @@ class Protocol extends stream_1.EventEmitter {
|
|
|
24
25
|
publicAddress: publicAddress.toString(),
|
|
25
26
|
}),
|
|
26
27
|
},
|
|
28
|
+
{
|
|
29
|
+
name: 'TransactionStatus',
|
|
30
|
+
code: 0x02,
|
|
31
|
+
encode: (transaction) => [
|
|
32
|
+
Buffer.from(transaction.transactionHash),
|
|
33
|
+
Buffer.from(transaction.sourceStatus),
|
|
34
|
+
Buffer.from(transaction.sourceTransactionHash || ''),
|
|
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)]) : [],
|
|
37
|
+
Buffer.from(transaction.targetStatus),
|
|
38
|
+
Buffer.from(transaction.targetTransactionHash || ''),
|
|
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)]) : [],
|
|
41
|
+
Buffer.from(transaction.status),
|
|
42
|
+
],
|
|
43
|
+
decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, sourceLogs, targetStatus, targetTransactionHash, targetErrors, targetLogs, status]) => ({
|
|
44
|
+
transactionHash: transactionHash.toString(),
|
|
45
|
+
sourceStatus: sourceStatus.toString(),
|
|
46
|
+
sourceTransactionHash: sourceTransactionHash.toString() || null,
|
|
47
|
+
sourceErrors: sourceErrors.map((e) => e.toString()),
|
|
48
|
+
sourceLogs: sourceLogs.map(e => ({
|
|
49
|
+
type: e[0].toString(),
|
|
50
|
+
message: e[1].toString(),
|
|
51
|
+
})),
|
|
52
|
+
targetStatus: targetStatus.toString(),
|
|
53
|
+
targetTransactionHash: targetTransactionHash.toString() || null,
|
|
54
|
+
targetErrors: targetErrors.map((e) => e.toString()),
|
|
55
|
+
targetLogs: targetLogs.map(e => ({
|
|
56
|
+
type: e[0].toString(),
|
|
57
|
+
message: e[1].toString(),
|
|
58
|
+
})),
|
|
59
|
+
status: status.toString(),
|
|
60
|
+
}),
|
|
61
|
+
},
|
|
27
62
|
];
|
|
28
63
|
}
|
|
29
64
|
start({ libp2p, topic = null, }) {
|
|
@@ -40,6 +75,7 @@ class Protocol extends stream_1.EventEmitter {
|
|
|
40
75
|
});
|
|
41
76
|
});
|
|
42
77
|
this.signature = new SignatureDialProtocol_1.SignatureDialProtocol(this.libp2p);
|
|
78
|
+
this.transactionStatus = new TransactionStatusDialProtocol_1.TransactionStatusDialProtocol(this.libp2p);
|
|
43
79
|
}
|
|
44
80
|
init() {
|
|
45
81
|
this.libp2p.pubsub.subscribe(this.topic);
|
|
@@ -75,6 +111,11 @@ class Protocol extends stream_1.EventEmitter {
|
|
|
75
111
|
const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(data)]);
|
|
76
112
|
this.libp2p.pubsub.publish(this.topic, encoded);
|
|
77
113
|
}
|
|
114
|
+
sendTransaction(transaction) {
|
|
115
|
+
const message = this.protocolMessages.find((m) => m.name === 'TransactionStatus');
|
|
116
|
+
const encoded = ethereumjs_util_1.rlp.encode([message.code, message.encode(transaction)]);
|
|
117
|
+
this.libp2p.pubsub.publish(this.topic, encoded);
|
|
118
|
+
}
|
|
78
119
|
async requestSignatures(data, peerIds) {
|
|
79
120
|
try {
|
|
80
121
|
peerIds = peerIds || __1.peerPool.activePeerIds;
|
|
@@ -88,5 +129,14 @@ class Protocol extends stream_1.EventEmitter {
|
|
|
88
129
|
return [];
|
|
89
130
|
}
|
|
90
131
|
}
|
|
132
|
+
async requestTransactionStatus(transactionHash, peerId) {
|
|
133
|
+
try {
|
|
134
|
+
return await this.transactionStatus.send(transactionHash, peerId);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.log(error);
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
91
141
|
}
|
|
92
142
|
exports.protocol = new Protocol();
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const BaseTask_1 = require("./BaseTask");
|
|
7
|
+
const logger_1 = __importDefault(require("@/logger"));
|
|
8
|
+
const await_spawn_1 = __importDefault(require("await-spawn"));
|
|
9
|
+
const child_process_1 = require("child_process");
|
|
10
|
+
const config_1 = __importDefault(require("@/config"));
|
|
11
|
+
const waait_1 = __importDefault(require("waait"));
|
|
12
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
|
13
|
+
const currentVersion = package_json_1.default.version;
|
|
14
|
+
const tag = config_1.default.staging ? 'dev' : 'latest';
|
|
15
|
+
class AutoUpdateTask extends BaseTask_1.BaseTask {
|
|
16
|
+
constructor() {
|
|
17
|
+
super({
|
|
18
|
+
logger: new logger_1.default("AutoUpdateTask"),
|
|
19
|
+
});
|
|
20
|
+
this.pollIntervalMs = 60 * 10 * 1000;
|
|
21
|
+
}
|
|
22
|
+
prePollHandler() {
|
|
23
|
+
return config_1.default.autoUpdate && !config_1.default.isLeadNode();
|
|
24
|
+
}
|
|
25
|
+
async getInstalledVersion() {
|
|
26
|
+
try {
|
|
27
|
+
const stdout = await (0, await_spawn_1.default)('npm', ['-g', 'ls', '--depth=0', '--json']);
|
|
28
|
+
return JSON.parse(stdout.toString()).dependencies[package_json_1.default.name].version;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
this.logger.error(error);
|
|
32
|
+
return currentVersion;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async getLatestVersion() {
|
|
36
|
+
try {
|
|
37
|
+
const stdout = await (0, await_spawn_1.default)('npm', ['view', `${package_json_1.default.name}@${tag}`, 'version']);
|
|
38
|
+
return stdout.toString().trim();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
this.logger.error(error);
|
|
42
|
+
return currentVersion;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async pollHandler() {
|
|
46
|
+
const version = await this.getLatestVersion();
|
|
47
|
+
if (version === currentVersion) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.logger.warn(`New version ${version} available.`);
|
|
51
|
+
this.logger.info('Updating...');
|
|
52
|
+
await (0, await_spawn_1.default)('npm', ['-g', 'install', `@instadapp/interop-x@${tag}`, '-f']);
|
|
53
|
+
await (0, waait_1.default)(5000);
|
|
54
|
+
if (version !== await this.getInstalledVersion()) {
|
|
55
|
+
this.logger.warn(`failed to install ${version}, retrying in 5 minutes`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.logger.warn(`Installed version ${version}`);
|
|
59
|
+
this.logger.warn(`Restarting...`);
|
|
60
|
+
// TODO: its restarting in the bg, but it should be in the fg
|
|
61
|
+
const subprocess = (0, child_process_1.spawn)(process.argv[0], process.argv.slice(1), {
|
|
62
|
+
cwd: process.cwd(),
|
|
63
|
+
stdio: "inherit",
|
|
64
|
+
// shell: process.env.SHELL,
|
|
65
|
+
});
|
|
66
|
+
subprocess.unref();
|
|
67
|
+
process.exit();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.default = AutoUpdateTask;
|
|
@@ -14,6 +14,7 @@ class BaseTask extends events_1.default {
|
|
|
14
14
|
this.started = false;
|
|
15
15
|
this.pollIntervalMs = 10 * 1000;
|
|
16
16
|
this.leadNodeOnly = false;
|
|
17
|
+
this.exceptLeadNode = false;
|
|
17
18
|
this.logger = logger !== null && logger !== void 0 ? logger : new logger_1.default('BaseTask');
|
|
18
19
|
}
|
|
19
20
|
async pollCheck() {
|
|
@@ -28,16 +29,23 @@ class BaseTask extends events_1.default {
|
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
catch (err) {
|
|
31
|
-
this.logger.error(`poll check error
|
|
32
|
+
this.logger.error(`poll check error:\n${err.message}\ntrace: ${err.stack}`);
|
|
32
33
|
}
|
|
33
34
|
await this.postPollHandler();
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
prePollHandler() {
|
|
37
|
-
if (
|
|
38
|
-
|
|
38
|
+
if (config_1.default.isMaintenanceMode()) {
|
|
39
|
+
this.logger.warn('Maintenance mode is enabled. Skipping task.');
|
|
40
|
+
return false;
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
if (this.exceptLeadNode) {
|
|
43
|
+
return !config_1.default.isLeadNode();
|
|
44
|
+
}
|
|
45
|
+
if (this.leadNodeOnly) {
|
|
46
|
+
return config_1.default.isLeadNode();
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
41
49
|
}
|
|
42
50
|
async pollHandler() {
|
|
43
51
|
this.logger.warn('pollHandler not implemented');
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
class SyncLogSubmitEvents extends BaseTask_1.BaseTask {
|
|
15
|
+
constructor({ chainId }) {
|
|
16
|
+
super({
|
|
17
|
+
logger: new logger_1.default("InteropX::SyncLogSubmitEvents"),
|
|
18
|
+
});
|
|
19
|
+
this.chainId = chainId;
|
|
20
|
+
}
|
|
21
|
+
async pollHandler() {
|
|
22
|
+
const currentBlock = await this.provider.getBlockNumber();
|
|
23
|
+
const events = await this.contract.queryFilter(this.contract.filters.LogSubmit(), currentBlock - 2000, currentBlock);
|
|
24
|
+
let processedEvents = 0;
|
|
25
|
+
for (const event of events) {
|
|
26
|
+
try {
|
|
27
|
+
if (!event.args) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const { position, actionId, actionIdHashHash, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata, } = event.args;
|
|
31
|
+
const uniqueIdentifier = {
|
|
32
|
+
actionId,
|
|
33
|
+
vnonce: vnonce.toString(),
|
|
34
|
+
sourceSender: sourceSender.toString(),
|
|
35
|
+
sourceChainId: sourceChainId.toNumber(),
|
|
36
|
+
targetChainId: targetChainId.toNumber(),
|
|
37
|
+
sourceDsaId: sourceDsaId.toString(),
|
|
38
|
+
targetDsaId: targetDsaId.toString(),
|
|
39
|
+
};
|
|
40
|
+
let transactionHash = (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier);
|
|
41
|
+
const transaction = await db_1.Transaction.findOne({ where: { transactionHash } });
|
|
42
|
+
if (transaction) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
await db_1.Transaction.create(Object.assign(Object.assign({ transactionHash }, uniqueIdentifier), { submitChainId: this.chainId, submitTransactionHash: event.transactionHash, submitBlockNumber: event.blockNumber, submitCreatedAt: new Date(), submitEvent: {
|
|
46
|
+
actionId,
|
|
47
|
+
actionIdHashHash,
|
|
48
|
+
vnonce: vnonce.toString(),
|
|
49
|
+
position: {
|
|
50
|
+
withdraw: position.withdraw.map((v) => ({
|
|
51
|
+
sourceToken: v.sourceToken,
|
|
52
|
+
targetToken: v.targetToken,
|
|
53
|
+
amount: v.amount.toString()
|
|
54
|
+
})),
|
|
55
|
+
supply: position.supply.map((v) => ({
|
|
56
|
+
sourceToken: v.sourceToken,
|
|
57
|
+
targetToken: v.targetToken,
|
|
58
|
+
amount: v.amount.toString()
|
|
59
|
+
})),
|
|
60
|
+
},
|
|
61
|
+
sourceChainId: sourceChainId.toNumber(),
|
|
62
|
+
targetChainId: targetChainId.toNumber(),
|
|
63
|
+
sourceSender,
|
|
64
|
+
sourceDsaId: sourceDsaId.toString(),
|
|
65
|
+
targetDsaId: targetDsaId.toString(),
|
|
66
|
+
metadata,
|
|
67
|
+
} }));
|
|
68
|
+
this.logger.info(`New InteropX tranaction: ${transactionHash} `);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
this.logger.error(error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (processedEvents > 0)
|
|
75
|
+
this.logger.info(`${processedEvents} events processed`);
|
|
76
|
+
}
|
|
77
|
+
async start() {
|
|
78
|
+
this.contractAddress = constants_1.addresses[this.chainId].interopX;
|
|
79
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
|
80
|
+
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopX, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
|
81
|
+
await super.start();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.default = SyncLogSubmitEvents;
|
|
@@ -0,0 +1,58 @@
|
|
|
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 net_1 = require("@/net");
|
|
9
|
+
const db_1 = require("@/db");
|
|
10
|
+
const sequelize_1 = require("sequelize");
|
|
11
|
+
class SyncTransactionStatusTask extends BaseTask_1.BaseTask {
|
|
12
|
+
constructor() {
|
|
13
|
+
super({
|
|
14
|
+
logger: new logger_1.default("SyncTransactionStatusTask"),
|
|
15
|
+
});
|
|
16
|
+
this.pollIntervalMs = 60 * 1000;
|
|
17
|
+
this.exceptLeadNode = true;
|
|
18
|
+
}
|
|
19
|
+
async pollHandler() {
|
|
20
|
+
// if transaction is pending for more than 1 hour, check lead node for status
|
|
21
|
+
const leadNode = net_1.peerPool.getLeadPeer();
|
|
22
|
+
if (!leadNode) {
|
|
23
|
+
console.log("No lead node found");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const transaction = await db_1.Transaction.findOne({
|
|
27
|
+
where: {
|
|
28
|
+
status: {
|
|
29
|
+
[sequelize_1.Op.notIn]: ['success', 'failed'],
|
|
30
|
+
},
|
|
31
|
+
createdAt: {
|
|
32
|
+
[sequelize_1.Op.lt]: new Date(Date.now() - 15 * 60 * 1000),
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
if (!transaction) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.logger.info(`Requesting transaction status for ${transaction.transactionHash}`);
|
|
40
|
+
const transactionStatus = await net_1.protocol.requestTransactionStatus(transaction.transactionHash, leadNode.id);
|
|
41
|
+
if (!transactionStatus) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
this.logger.info(`Received transaction status for ${transaction.transactionHash}`);
|
|
45
|
+
transaction.sourceStatus = transactionStatus.sourceStatus;
|
|
46
|
+
transaction.sourceTransactionHash = transactionStatus.sourceTransactionHash;
|
|
47
|
+
transaction.sourceErrors = transactionStatus.sourceErrors;
|
|
48
|
+
transaction.sourceLogs = transactionStatus.sourceLogs;
|
|
49
|
+
transaction.targetStatus = transactionStatus.targetStatus;
|
|
50
|
+
transaction.targetTransactionHash = transactionStatus.targetTransactionHash;
|
|
51
|
+
transaction.targetErrors = transactionStatus.targetErrors;
|
|
52
|
+
transaction.targetLogs = transactionStatus.targetLogs;
|
|
53
|
+
transaction.status = transactionStatus.status;
|
|
54
|
+
await transaction.save();
|
|
55
|
+
this.logger.info(`Updated transaction status for ${transaction.transactionHash}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.default = SyncTransactionStatusTask;
|
|
@@ -0,0 +1,34 @@
|
|
|
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.Tasks = void 0;
|
|
7
|
+
const waait_1 = __importDefault(require("waait"));
|
|
8
|
+
const SyncTransactionStatusTask_1 = __importDefault(require("./Transactions/SyncTransactionStatusTask"));
|
|
9
|
+
const AutoUpdateTask_1 = __importDefault(require("./AutoUpdateTask"));
|
|
10
|
+
const SyncLogSubmitEvents_1 = __importDefault(require("./InteropX/SyncLogSubmitEvents"));
|
|
11
|
+
class Tasks {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.tasks = [
|
|
14
|
+
// new SyncTransactionStatusTask(),
|
|
15
|
+
new AutoUpdateTask_1.default(),
|
|
16
|
+
// InteropX
|
|
17
|
+
new SyncLogSubmitEvents_1.default({ chainId: 137 }),
|
|
18
|
+
new SyncLogSubmitEvents_1.default({ chainId: 43114 }),
|
|
19
|
+
new SyncTransactionStatusTask_1.default(),
|
|
20
|
+
];
|
|
21
|
+
}
|
|
22
|
+
async start() {
|
|
23
|
+
for (const task of this.tasks) {
|
|
24
|
+
try {
|
|
25
|
+
task.start();
|
|
26
|
+
await (0, waait_1.default)(1000);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error(`Error starting task: ${task.constructor.name}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.Tasks = Tasks;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|