@instadapp/interop-x 0.0.0-dev.f0a6281 → 0.0.0-dev.f39d622
Sign up to get free protection for your applications and to get access to all the features.
- package/.github/workflows/ci.yml +19 -0
- package/dist/package.json +21 -13
- package/dist/src/abi/aaveV2Resolver.json +832 -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 +10 -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 +10 -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 +41 -15
- 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 +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 +8 -18
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +9 -10
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +2 -0
- package/dist/src/net/protocol/index.js +15 -5
- package/dist/src/services/Prices.js +74 -0
- package/dist/src/services/index.js +8 -0
- package/dist/src/tasks/InteropX/ProcessSubmitEvents.js +244 -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 +20 -19
- package/dist/src/typechain/{InteropBridgeToken.js → AaveV2Resolver.js} +0 -0
- package/dist/src/typechain/{InteropXGateway.js → BalanceResolver.js} +0 -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/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 +9 -5
- package/dist/src/typechain/index.js +9 -5
- package/dist/src/utils/async.js +18 -0
- package/dist/src/utils/dsa.js +24 -0
- package/dist/src/utils/formatting.js +67 -0
- package/dist/src/utils/gnosis.js +62 -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 +21 -13
- package/src/abi/aaveV2Resolver.json +832 -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 +13 -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 +21 -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 +159 -65
- package/src/errors/index.ts +26 -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 +7 -17
- package/src/net/protocol/dial/SignatureDialProtocol.ts +12 -13
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +3 -1
- package/src/net/protocol/index.ts +16 -6
- package/src/services/Prices.ts +89 -0
- package/src/services/index.ts +1 -0
- package/src/tasks/InteropX/ProcessSubmitEvents.ts +344 -0
- package/src/tasks/InteropX/ProcessValidateEvents.ts +271 -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 +25 -20
- package/src/typechain/AaveV2Resolver.ts +1017 -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/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 +4 -2
- package/src/typechain/index.ts +8 -4
- package/src/utils/async.ts +22 -0
- package/src/utils/dsa.ts +30 -0
- package/src/utils/formatting.ts +68 -0
- package/src/utils/gnosis.ts +123 -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 +173 -0
- package/src/utils/web3.ts +132 -0
- package/tsconfig.json +7 -2
- package/dist/src/abi/interopBridgeToken.json +0 -298
- 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 -71
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +0 -161
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -74
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -471
- package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
- package/src/abi/interopBridgeToken.json +0 -298
- 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 -121
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -256
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -124
- package/src/typechain/InteropBridgeToken.ts +0 -692
- package/src/typechain/InteropXGateway.ts +0 -407
- package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -478
- package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -10,12 +10,17 @@ const config_1 = __importDefault(require("@/config"));
|
|
10
10
|
const db_1 = require("@/db");
|
11
11
|
const utils_1 = require("@/utils");
|
12
12
|
const constants_1 = require("@/constants");
|
13
|
+
const gnosis_1 = require("@/gnosis");
|
13
14
|
class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
14
15
|
constructor(libp2p) {
|
15
16
|
super(libp2p, '/interop-x/signatures');
|
16
17
|
this.timeout = 30000;
|
17
18
|
}
|
18
19
|
async response(data) {
|
20
|
+
console.log({
|
21
|
+
tag: 'SignatureDialProtocol',
|
22
|
+
data
|
23
|
+
});
|
19
24
|
const signer = config_1.default.wallet;
|
20
25
|
let transaction;
|
21
26
|
let maxTimeout = 20000;
|
@@ -33,17 +38,11 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
|
33
38
|
error: 'Event not found'
|
34
39
|
};
|
35
40
|
}
|
36
|
-
|
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 });
|
@@ -18,9 +18,11 @@ class TransactionStatusDialProtocol extends BaseDialProtocol_1.BaseDialProtocol
|
|
18
18
|
sourceStatus: transaction.sourceStatus,
|
19
19
|
sourceTransactionHash: transaction.sourceTransactionHash,
|
20
20
|
sourceErrors: transaction.sourceErrors,
|
21
|
+
sourceLogs: transaction.sourceLogs,
|
21
22
|
targetStatus: transaction.targetStatus,
|
22
23
|
targetTransactionHash: transaction.targetTransactionHash,
|
23
24
|
targetErrors: transaction.targetErrors,
|
25
|
+
targetLogs: transaction.targetLogs,
|
24
26
|
status: transaction.status,
|
25
27
|
};
|
26
28
|
}
|
@@ -31,21 +31,31 @@ class Protocol extends stream_1.EventEmitter {
|
|
31
31
|
encode: (transaction) => [
|
32
32
|
Buffer.from(transaction.transactionHash),
|
33
33
|
Buffer.from(transaction.sourceStatus),
|
34
|
-
Buffer.from(transaction.sourceTransactionHash),
|
34
|
+
Buffer.from(transaction.sourceTransactionHash || ''),
|
35
35
|
transaction.sourceErrors ? transaction.sourceErrors.map((e) => Buffer.from(e)) : [],
|
36
|
+
transaction.sourceLogs ? transaction.sourceLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
|
36
37
|
Buffer.from(transaction.targetStatus),
|
37
|
-
Buffer.from(transaction.targetTransactionHash),
|
38
|
+
Buffer.from(transaction.targetTransactionHash || ''),
|
38
39
|
transaction.targetErrors ? transaction.targetErrors.map((e) => Buffer.from(e)) : [],
|
40
|
+
transaction.targetLogs ? transaction.targetLogs.map((e) => [Buffer.from(e.type), Buffer.from(e.message)]) : [],
|
39
41
|
Buffer.from(transaction.status),
|
40
42
|
],
|
41
|
-
decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, targetStatus, targetTransactionHash, targetErrors, status]) => ({
|
43
|
+
decode: ([transactionHash, sourceStatus, sourceTransactionHash, sourceErrors, sourceLogs, targetStatus, targetTransactionHash, targetErrors, targetLogs, status]) => ({
|
42
44
|
transactionHash: transactionHash.toString(),
|
43
45
|
sourceStatus: sourceStatus.toString(),
|
44
|
-
sourceTransactionHash: sourceTransactionHash.toString(),
|
46
|
+
sourceTransactionHash: sourceTransactionHash.toString() || null,
|
45
47
|
sourceErrors: sourceErrors.map((e) => e.toString()),
|
48
|
+
sourceLogs: sourceLogs.map(e => ({
|
49
|
+
type: e[0].toString(),
|
50
|
+
message: e[1].toString(),
|
51
|
+
})),
|
46
52
|
targetStatus: targetStatus.toString(),
|
47
|
-
targetTransactionHash: targetTransactionHash.toString(),
|
53
|
+
targetTransactionHash: targetTransactionHash.toString() || null,
|
48
54
|
targetErrors: targetErrors.map((e) => e.toString()),
|
55
|
+
targetLogs: targetLogs.map(e => ({
|
56
|
+
type: e[0].toString(),
|
57
|
+
message: e[1].toString(),
|
58
|
+
})),
|
49
59
|
status: status.toString(),
|
50
60
|
}),
|
51
61
|
},
|
@@ -0,0 +1,74 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const web3_utils_1 = __importDefault(require("web3-utils"));
|
7
|
+
const path_1 = __importDefault(require("path"));
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
9
|
+
const constants_1 = require("@/constants");
|
10
|
+
const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
|
11
|
+
const config_1 = __importDefault(require("@/config"));
|
12
|
+
const utils_1 = require("@/utils");
|
13
|
+
const basePath = (0, expand_home_dir_1.default)(`~/.interop-x/data/${config_1.default.publicAddress}/${config_1.default.staging ? 'staging' : ''}`);
|
14
|
+
const mainnetPricesFilePath = path_1.default.resolve(basePath, "./mainnetPrices.json");
|
15
|
+
const networkTokenPricesFilePath = path_1.default.resolve(basePath, "./networkTokenPrices.json");
|
16
|
+
class Prices {
|
17
|
+
static async fetch() {
|
18
|
+
if (!fs_1.default.existsSync(mainnetPricesFilePath)) {
|
19
|
+
fs_1.default.writeFileSync(mainnetPricesFilePath, JSON.stringify({}));
|
20
|
+
}
|
21
|
+
if (!fs_1.default.existsSync(networkTokenPricesFilePath)) {
|
22
|
+
fs_1.default.writeFileSync(networkTokenPricesFilePath, JSON.stringify({}));
|
23
|
+
}
|
24
|
+
this.mainnetPrices = JSON.parse(fs_1.default.readFileSync(mainnetPricesFilePath, "utf8"));
|
25
|
+
this.networkTokenPrices = JSON.parse(fs_1.default.readFileSync(networkTokenPricesFilePath, "utf8"));
|
26
|
+
try {
|
27
|
+
const path = constants_1.tokens["1"]
|
28
|
+
.filter((a) => a.symbol !== "ETH")
|
29
|
+
.map((token) => token.address)
|
30
|
+
.join(",");
|
31
|
+
const [response, ethResponse, avaxResponse, polygonResponse] = await Promise.all([
|
32
|
+
utils_1.http.get("https://api.coingecko.com/api/v3/simple/token_price/ethereum", {
|
33
|
+
params: { contract_addresses: path, vs_currencies: "usd" },
|
34
|
+
}),
|
35
|
+
utils_1.http.get("https://api.coingecko.com/api/v3/simple/price", {
|
36
|
+
params: { ids: "ethereum", vs_currencies: "usd" },
|
37
|
+
}),
|
38
|
+
utils_1.http.get("https://api.coingecko.com/api/v3/simple/price", {
|
39
|
+
params: { ids: "avalanche-2", vs_currencies: "usd" },
|
40
|
+
}),
|
41
|
+
utils_1.http.get("https://api.coingecko.com/api/v3/simple/price", {
|
42
|
+
params: { ids: "matic-network", vs_currencies: "usd" },
|
43
|
+
}),
|
44
|
+
]);
|
45
|
+
this.networkTokenPrices = {
|
46
|
+
"1": ethResponse.data.ethereum.usd.toString(),
|
47
|
+
"137": polygonResponse.data["matic-network"].usd.toString(),
|
48
|
+
"43114": avaxResponse.data["avalanche-2"].usd.toString(),
|
49
|
+
};
|
50
|
+
const data = response.data;
|
51
|
+
for (const key in data) {
|
52
|
+
const _key = web3_utils_1.default.toChecksumAddress(key);
|
53
|
+
if (!data[key].usd)
|
54
|
+
continue;
|
55
|
+
this.mainnetPrices[_key] = data[key].usd.toString();
|
56
|
+
}
|
57
|
+
this.mainnetPrices["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"] =
|
58
|
+
ethResponse.data.ethereum.usd.toString();
|
59
|
+
}
|
60
|
+
catch (error) { }
|
61
|
+
fs_1.default.writeFileSync(mainnetPricesFilePath, JSON.stringify(this.mainnetPrices));
|
62
|
+
fs_1.default.writeFileSync(networkTokenPricesFilePath, JSON.stringify(this.networkTokenPrices));
|
63
|
+
return this.mainnetPrices;
|
64
|
+
}
|
65
|
+
static getMainnetPrices() {
|
66
|
+
return this.mainnetPrices;
|
67
|
+
}
|
68
|
+
static getNetworkTokenPrices() {
|
69
|
+
return this.networkTokenPrices;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
Prices.mainnetPrices = {};
|
73
|
+
Prices.networkTokenPrices = {};
|
74
|
+
exports.default = Prices;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.Prices = void 0;
|
7
|
+
var Prices_1 = require("./Prices");
|
8
|
+
Object.defineProperty(exports, "Prices", { enumerable: true, get: function () { return __importDefault(Prices_1).default; } });
|
@@ -0,0 +1,244 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const BaseTask_1 = require("../BaseTask");
|
7
|
+
const logger_1 = __importDefault(require("@/logger"));
|
8
|
+
const ethers_1 = require("ethers");
|
9
|
+
const abi_1 = __importDefault(require("@/abi"));
|
10
|
+
const db_1 = require("@/db");
|
11
|
+
const utils_1 = require("@/utils");
|
12
|
+
const constants_1 = require("@/constants");
|
13
|
+
const config_1 = __importDefault(require("@/config"));
|
14
|
+
const moment_1 = __importDefault(require("moment"));
|
15
|
+
const sequelize_1 = require("sequelize");
|
16
|
+
const gnosis_1 = require("@/gnosis");
|
17
|
+
const net_1 = require("@/net");
|
18
|
+
const waait_1 = __importDefault(require("waait"));
|
19
|
+
const errors_1 = require("@/errors");
|
20
|
+
const bignumber_js_1 = require("bignumber.js");
|
21
|
+
const dedent_1 = __importDefault(require("dedent"));
|
22
|
+
class ProcessSubmitEvents extends BaseTask_1.BaseTask {
|
23
|
+
constructor({ chainId }) {
|
24
|
+
super({
|
25
|
+
logger: new logger_1.default("InteropX::ProcessSubmitEvents"),
|
26
|
+
});
|
27
|
+
this.leadNodeOnly = true;
|
28
|
+
this.blockConfirmationsCount = 12;
|
29
|
+
this.chainId = chainId;
|
30
|
+
}
|
31
|
+
async pollHandler() {
|
32
|
+
var _a;
|
33
|
+
const currentBlockNumber = await this.sourceProvider.getBlockNumber();
|
34
|
+
const transaction = await db_1.Transaction.findOne({
|
35
|
+
where: {
|
36
|
+
status: "pending",
|
37
|
+
sourceStatus: "pending",
|
38
|
+
sourceChainId: this.chainId,
|
39
|
+
submitBlockNumber: {
|
40
|
+
[sequelize_1.Op.lt]: currentBlockNumber - this.blockConfirmationsCount,
|
41
|
+
},
|
42
|
+
sourceDelayUntil: {
|
43
|
+
[sequelize_1.Op.or]: {
|
44
|
+
[sequelize_1.Op.is]: null,
|
45
|
+
[sequelize_1.Op.lt]: new Date(),
|
46
|
+
},
|
47
|
+
},
|
48
|
+
submitEvent: { $ne: null },
|
49
|
+
createdAt: {
|
50
|
+
[sequelize_1.Op.gt]: (0, moment_1.default)().subtract({ hours: 12 }).toDate(),
|
51
|
+
},
|
52
|
+
},
|
53
|
+
});
|
54
|
+
if (!transaction) {
|
55
|
+
return;
|
56
|
+
}
|
57
|
+
this.logger.debug(`Processing transaction ${transaction.transactionHash}`);
|
58
|
+
transaction.sourceStatus = "proccessing";
|
59
|
+
await transaction.save();
|
60
|
+
const { submitEvent: { position, sourceChainId, targetChainId } } = transaction;
|
61
|
+
try {
|
62
|
+
(0, utils_1.validateChains)({ sourceChainId, targetChainId });
|
63
|
+
}
|
64
|
+
catch (error) {
|
65
|
+
transaction.sourceErrors = [error.message];
|
66
|
+
transaction.sourceStatus = "failed";
|
67
|
+
transaction.targetStatus = "failed";
|
68
|
+
transaction.status = "failed";
|
69
|
+
await transaction.save();
|
70
|
+
return;
|
71
|
+
}
|
72
|
+
const walletBalance = (await this.sourceWallet.getBalance()).toString();
|
73
|
+
const currentGasPrice = (await this.sourceWallet.getGasPrice()).toString();
|
74
|
+
const minBalanceRequired = new bignumber_js_1.BigNumber(currentGasPrice)
|
75
|
+
.multipliedBy(4000000)
|
76
|
+
.multipliedBy(2); // 2x balance
|
77
|
+
if (new bignumber_js_1.BigNumber(walletBalance).isLessThan(minBalanceRequired)) {
|
78
|
+
console.log((0, dedent_1.default) `Not enough balance in wallet ${(0, utils_1.getExplorerUrl)(sourceChainId, '/address/' + this.sourceWallet.address)} on ${(0, utils_1.chainIdToName)(sourceChainId)}
|
79
|
+
Balance: ${ethers_1.ethers.utils.parseEther(walletBalance)} ${(0, utils_1.getChainIdNativeSymbol)(sourceChainId)}
|
80
|
+
Required Balance: ${ethers_1.ethers.utils.parseEther(minBalanceRequired.toString())}
|
81
|
+
Require more: ${ethers_1.ethers.utils.parseEther(minBalanceRequired.minus(walletBalance).toString())}`);
|
82
|
+
transaction.sourceDelayUntil = (0, moment_1.default)().add({ minutes: 5 }).toDate();
|
83
|
+
transaction.sourceStatus = "pending";
|
84
|
+
await transaction.save();
|
85
|
+
return;
|
86
|
+
}
|
87
|
+
try {
|
88
|
+
await (0, utils_1.validateLiquidityCap)(position, sourceChainId, targetChainId);
|
89
|
+
}
|
90
|
+
catch (error) {
|
91
|
+
transaction.sourceErrors = [error.message];
|
92
|
+
transaction.sourceStatus = "failed";
|
93
|
+
transaction.targetStatus = "failed";
|
94
|
+
transaction.status = "failed";
|
95
|
+
await transaction.save();
|
96
|
+
return;
|
97
|
+
}
|
98
|
+
try {
|
99
|
+
await (0, utils_1.validateSourceLiquidity)({
|
100
|
+
position,
|
101
|
+
sourceChainId,
|
102
|
+
sourceProvider: this.sourceProvider,
|
103
|
+
});
|
104
|
+
}
|
105
|
+
catch (error) {
|
106
|
+
if (error instanceof errors_1.UnsupportedChaindIdError) {
|
107
|
+
console.log(`Dropping transaction ${transaction.transactionHash}`);
|
108
|
+
transaction.sourceErrors = [error.message];
|
109
|
+
transaction.sourceStatus = "failed";
|
110
|
+
transaction.targetStatus = "failed";
|
111
|
+
transaction.status = "failed";
|
112
|
+
await transaction.save();
|
113
|
+
}
|
114
|
+
else {
|
115
|
+
transaction.sourceStatus = "pending";
|
116
|
+
transaction.sourceDelayUntil = (0, moment_1.default)().add({ minutes: 5 }).toDate();
|
117
|
+
await transaction.save();
|
118
|
+
console.log("[validateSourceLiquidity][Warning]", error.message);
|
119
|
+
return;
|
120
|
+
}
|
121
|
+
}
|
122
|
+
const ownersThreshold = await this.sourceGnosisContract.getThreshold();
|
123
|
+
await (0, waait_1.default)(10000);
|
124
|
+
this.logger.debug(`Build gnosis action for ${transaction.transactionHash}`);
|
125
|
+
let data, logs = [];
|
126
|
+
try {
|
127
|
+
({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction, "source"));
|
128
|
+
}
|
129
|
+
catch (error) {
|
130
|
+
if (error instanceof errors_1.LiquidityError) {
|
131
|
+
await transaction.save();
|
132
|
+
transaction.sourceDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
|
133
|
+
transaction.sourceStatus = "pending";
|
134
|
+
await transaction.save();
|
135
|
+
throw error;
|
136
|
+
return;
|
137
|
+
}
|
138
|
+
transaction.sourceStatus = "failed";
|
139
|
+
transaction.sourceErrors = [error.message];
|
140
|
+
transaction.targetStatus = "failed";
|
141
|
+
transaction.status = "failed";
|
142
|
+
await transaction.save();
|
143
|
+
net_1.protocol.sendTransaction(transaction);
|
144
|
+
return;
|
145
|
+
}
|
146
|
+
this.logger.debug(`Generating gnosis tx for ${transaction.transactionHash}`);
|
147
|
+
let gnosisTx = await (0, utils_1.generateGnosisTransaction)({
|
148
|
+
baseGas: "0",
|
149
|
+
data,
|
150
|
+
gasPrice: "0",
|
151
|
+
gasToken: "0x0000000000000000000000000000000000000000",
|
152
|
+
nonce: "0",
|
153
|
+
operation: "1",
|
154
|
+
refundReceiver: "0x0000000000000000000000000000000000000000",
|
155
|
+
safeAddress: this.sourceGnosisContract.address,
|
156
|
+
safeTxGas: "79668",
|
157
|
+
to: constants_1.addresses[transaction.sourceChainId].multisend,
|
158
|
+
value: "0",
|
159
|
+
}, this.sourceGnosisContract);
|
160
|
+
const owners = await this.sourceGnosisContract
|
161
|
+
.getOwners()
|
162
|
+
.then((owners) => owners.map((owner) => owner.toLowerCase()));
|
163
|
+
const ownerPeerIds = net_1.peerPool.activePeers
|
164
|
+
.filter((peer) => owners.includes(peer.publicAddress.toLowerCase()))
|
165
|
+
.map((peer) => peer.id);
|
166
|
+
console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
|
167
|
+
console.log(ownerPeerIds);
|
168
|
+
const signatures = await net_1.protocol.requestSignatures({
|
169
|
+
type: "source",
|
170
|
+
transactionHash: transaction.transactionHash,
|
171
|
+
safeTxGas: gnosisTx.safeTxGas,
|
172
|
+
safeNonce: gnosisTx.nonce,
|
173
|
+
chainId: this.chainId,
|
174
|
+
}, ownerPeerIds);
|
175
|
+
const validSignatures = signatures.filter((s) => !!s.data && s.data !== "0x");
|
176
|
+
console.log({
|
177
|
+
signatures,
|
178
|
+
validSignatures,
|
179
|
+
ownersThreshold: ownersThreshold.toString(),
|
180
|
+
});
|
181
|
+
if (validSignatures.length === 0 ||
|
182
|
+
ownersThreshold.gt(validSignatures.length)) {
|
183
|
+
await transaction.save();
|
184
|
+
transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
|
185
|
+
transaction.sourceStatus = "pending";
|
186
|
+
await transaction.save();
|
187
|
+
const errorMessage = (_a = signatures.find((s) => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
|
188
|
+
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ""));
|
189
|
+
}
|
190
|
+
console.log(`Executing transaction for execution ${transaction.transactionHash}`);
|
191
|
+
const { data: txData } = await this.sourceGnosisContract.populateTransaction.execTransaction(gnosisTx.to, gnosisTx.value, gnosisTx.data, gnosisTx.operation, gnosisTx.safeTxGas, gnosisTx.baseGas, gnosisTx.gasPrice, gnosisTx.gasToken, gnosisTx.refundReceiver, (0, utils_1.buildSignatureBytes)(validSignatures));
|
192
|
+
const [gasPrice, gasLimit] = await Promise.all([
|
193
|
+
this.sourceProvider.getGasPrice(),
|
194
|
+
this.sourceProvider.estimateGas({
|
195
|
+
from: this.sourceWallet.address,
|
196
|
+
to: this.sourceGnosisContract.address,
|
197
|
+
data: txData,
|
198
|
+
}),
|
199
|
+
]);
|
200
|
+
const txSent = await this.sourceWallet.sendTransaction({
|
201
|
+
from: this.sourceWallet.address,
|
202
|
+
to: this.sourceGnosisContract.address,
|
203
|
+
gasPrice: gasPrice.mul(120).div(100),
|
204
|
+
gasLimit: 5000000,
|
205
|
+
data: txData,
|
206
|
+
});
|
207
|
+
console.log(txSent);
|
208
|
+
const receipt = await txSent.wait();
|
209
|
+
const parsedLogs = [];
|
210
|
+
receipt.logs.forEach((log) => {
|
211
|
+
try {
|
212
|
+
parsedLogs.push(this.sourceGnosisContract.interface.parseLog(log));
|
213
|
+
}
|
214
|
+
catch (e) { }
|
215
|
+
});
|
216
|
+
if (parsedLogs.find((e) => e.name === "ExecutionSuccess")) {
|
217
|
+
console.log("ExecutionSuccess");
|
218
|
+
transaction.sourceStatus = "success";
|
219
|
+
if (txSent.blockNumber)
|
220
|
+
transaction.sourceBlockNumber = txSent.blockNumber;
|
221
|
+
transaction.sourceTransactionHash = txSent.hash;
|
222
|
+
transaction.sourceLogs = logs;
|
223
|
+
await transaction.save();
|
224
|
+
}
|
225
|
+
else {
|
226
|
+
console.log("ExecutionFailure");
|
227
|
+
transaction.sourceStatus = "failed";
|
228
|
+
if (txSent.blockNumber)
|
229
|
+
transaction.sourceBlockNumber = txSent.blockNumber;
|
230
|
+
transaction.sourceTransactionHash = txSent.hash;
|
231
|
+
transaction.status = "failed";
|
232
|
+
await transaction.save();
|
233
|
+
}
|
234
|
+
net_1.protocol.sendTransaction(transaction);
|
235
|
+
}
|
236
|
+
async start() {
|
237
|
+
this.blockConfirmationsCount = constants_1.blockConfirmations[this.chainId] + 1;
|
238
|
+
this.sourceProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
239
|
+
this.sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, this.sourceProvider);
|
240
|
+
this.sourceGnosisContract = (0, utils_1.getContract)(constants_1.addresses[this.chainId].gnosisSafe, abi_1.default.gnosisSafe, this.sourceWallet);
|
241
|
+
await super.start();
|
242
|
+
}
|
243
|
+
}
|
244
|
+
exports.default = ProcessSubmitEvents;
|
@@ -0,0 +1,184 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const BaseTask_1 = require("../BaseTask");
|
7
|
+
const logger_1 = __importDefault(require("@/logger"));
|
8
|
+
const ethers_1 = require("ethers");
|
9
|
+
const abi_1 = __importDefault(require("@/abi"));
|
10
|
+
const db_1 = require("@/db");
|
11
|
+
const utils_1 = require("@/utils");
|
12
|
+
const constants_1 = require("@/constants");
|
13
|
+
const config_1 = __importDefault(require("@/config"));
|
14
|
+
const moment_1 = __importDefault(require("moment"));
|
15
|
+
const sequelize_1 = require("sequelize");
|
16
|
+
const gnosis_1 = require("@/gnosis");
|
17
|
+
const net_1 = require("@/net");
|
18
|
+
const waait_1 = __importDefault(require("waait"));
|
19
|
+
const errors_1 = require("@/errors");
|
20
|
+
class ProcessValidateEvents extends BaseTask_1.BaseTask {
|
21
|
+
constructor({ chainId }) {
|
22
|
+
super({
|
23
|
+
logger: new logger_1.default("InteropX::ProcessValidateEvents"),
|
24
|
+
});
|
25
|
+
this.leadNodeOnly = true;
|
26
|
+
this.blockConfirmationsCount = 12;
|
27
|
+
this.chainId = chainId;
|
28
|
+
}
|
29
|
+
async pollHandler() {
|
30
|
+
var _a;
|
31
|
+
const currentBlockNumber = await this.sourceProvider.getBlockNumber();
|
32
|
+
const transaction = await db_1.Transaction.findOne({
|
33
|
+
where: {
|
34
|
+
status: "pending",
|
35
|
+
sourceStatus: "success",
|
36
|
+
targetStatus: "pending",
|
37
|
+
sourceChainId: this.chainId,
|
38
|
+
sourceBlockNumber: {
|
39
|
+
[sequelize_1.Op.lt]: currentBlockNumber - this.blockConfirmationsCount,
|
40
|
+
},
|
41
|
+
targetDelayUntil: {
|
42
|
+
[sequelize_1.Op.or]: {
|
43
|
+
[sequelize_1.Op.is]: null,
|
44
|
+
[sequelize_1.Op.lt]: new Date(),
|
45
|
+
},
|
46
|
+
},
|
47
|
+
submitEvent: { $ne: null },
|
48
|
+
validateEvent: { $ne: null },
|
49
|
+
createdAt: {
|
50
|
+
[sequelize_1.Op.gt]: (0, moment_1.default)().subtract({ hours: 12 }).toDate(),
|
51
|
+
},
|
52
|
+
},
|
53
|
+
});
|
54
|
+
if (!transaction) {
|
55
|
+
return;
|
56
|
+
}
|
57
|
+
this.logger.debug(`Processing transaction ${transaction.transactionHash}`);
|
58
|
+
transaction.targetStatus = "proccessing";
|
59
|
+
await transaction.save();
|
60
|
+
const { sourceChainId, targetChainId } = transaction.validateEvent;
|
61
|
+
const targetProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
|
62
|
+
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetProvider);
|
63
|
+
const targetGnosisContract = (0, utils_1.getContract)(constants_1.addresses[targetChainId].gnosisSafe, abi_1.default.gnosisSafe, targetWallet);
|
64
|
+
const ownersThreshold = await targetGnosisContract.getThreshold();
|
65
|
+
await (0, waait_1.default)(10000);
|
66
|
+
this.logger.debug(`Build gnosis action for ${transaction.transactionHash}`);
|
67
|
+
let data, logs = [];
|
68
|
+
try {
|
69
|
+
({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction, "target"));
|
70
|
+
}
|
71
|
+
catch (error) {
|
72
|
+
if (error instanceof errors_1.LiquidityError) {
|
73
|
+
await transaction.save();
|
74
|
+
transaction.targetDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
|
75
|
+
transaction.targetStatus = "pending";
|
76
|
+
await transaction.save();
|
77
|
+
throw error;
|
78
|
+
return;
|
79
|
+
}
|
80
|
+
transaction.targetStatus = "failed";
|
81
|
+
transaction.targetErrors = [error.message];
|
82
|
+
transaction.status = "failed";
|
83
|
+
await transaction.save();
|
84
|
+
net_1.protocol.sendTransaction(transaction);
|
85
|
+
return;
|
86
|
+
}
|
87
|
+
this.logger.debug(`Generating gnosis tx for ${transaction.transactionHash}`);
|
88
|
+
let gnosisTx = await (0, utils_1.generateGnosisTransaction)({
|
89
|
+
baseGas: "0",
|
90
|
+
data,
|
91
|
+
gasPrice: "0",
|
92
|
+
gasToken: "0x0000000000000000000000000000000000000000",
|
93
|
+
nonce: "0",
|
94
|
+
operation: "1",
|
95
|
+
refundReceiver: "0x0000000000000000000000000000000000000000",
|
96
|
+
safeAddress: targetGnosisContract.address,
|
97
|
+
safeTxGas: "79668",
|
98
|
+
to: constants_1.addresses[transaction.targetChainId].multisend,
|
99
|
+
value: "0",
|
100
|
+
}, targetGnosisContract);
|
101
|
+
const owners = await targetGnosisContract
|
102
|
+
.getOwners()
|
103
|
+
.then((owners) => owners.map((owner) => owner.toLowerCase()));
|
104
|
+
const ownerPeerIds = net_1.peerPool.activePeers
|
105
|
+
.filter((peer) => owners.includes(peer.publicAddress.toLowerCase()))
|
106
|
+
.map((peer) => peer.id);
|
107
|
+
console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
|
108
|
+
console.log(ownerPeerIds);
|
109
|
+
const signatures = await net_1.protocol.requestSignatures({
|
110
|
+
type: "target",
|
111
|
+
transactionHash: transaction.transactionHash,
|
112
|
+
safeTxGas: gnosisTx.safeTxGas,
|
113
|
+
safeNonce: gnosisTx.nonce,
|
114
|
+
chainId: targetChainId,
|
115
|
+
}, ownerPeerIds);
|
116
|
+
const validSignatures = signatures.filter((s) => !!s.data && s.data !== "0x");
|
117
|
+
console.log({
|
118
|
+
signatures,
|
119
|
+
validSignatures,
|
120
|
+
ownersThreshold: ownersThreshold.toString(),
|
121
|
+
});
|
122
|
+
if (validSignatures.length === 0 ||
|
123
|
+
ownersThreshold.gt(validSignatures.length)) {
|
124
|
+
await transaction.save();
|
125
|
+
transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
|
126
|
+
transaction.targetStatus = "pending";
|
127
|
+
await transaction.save();
|
128
|
+
const errorMessage = (_a = signatures.find((s) => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
|
129
|
+
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ""));
|
130
|
+
}
|
131
|
+
console.log(`Executing transaction for execution ${transaction.transactionHash}`);
|
132
|
+
const { data: txData } = await targetGnosisContract.populateTransaction.execTransaction(gnosisTx.to, gnosisTx.value, gnosisTx.data, gnosisTx.operation, gnosisTx.safeTxGas, gnosisTx.baseGas, gnosisTx.gasPrice, gnosisTx.gasToken, gnosisTx.refundReceiver, (0, utils_1.buildSignatureBytes)(validSignatures));
|
133
|
+
const [gasPrice, gasLimit] = await Promise.all([
|
134
|
+
targetProvider.getGasPrice(),
|
135
|
+
targetProvider.estimateGas({
|
136
|
+
from: targetWallet.address,
|
137
|
+
to: targetGnosisContract.address,
|
138
|
+
data: txData,
|
139
|
+
}),
|
140
|
+
]);
|
141
|
+
const txSent = await targetWallet.sendTransaction({
|
142
|
+
from: targetWallet.address,
|
143
|
+
to: targetGnosisContract.address,
|
144
|
+
gasPrice: gasPrice.mul(120).div(100),
|
145
|
+
gasLimit: 5000000,
|
146
|
+
data: txData,
|
147
|
+
});
|
148
|
+
console.log(txSent);
|
149
|
+
const receipt = await txSent.wait();
|
150
|
+
const parsedLogs = [];
|
151
|
+
receipt.logs.forEach((log) => {
|
152
|
+
try {
|
153
|
+
parsedLogs.push(targetGnosisContract.interface.parseLog(log));
|
154
|
+
}
|
155
|
+
catch (e) { }
|
156
|
+
});
|
157
|
+
if (parsedLogs.find((e) => e.name === "ExecutionSuccess")) {
|
158
|
+
console.log("ExecutionSuccess");
|
159
|
+
transaction.targetStatus = "success";
|
160
|
+
transaction.status = "success";
|
161
|
+
if (txSent.blockNumber)
|
162
|
+
transaction.targetBlockNumber = txSent.blockNumber;
|
163
|
+
transaction.targetTransactionHash = txSent.hash;
|
164
|
+
transaction.targetLogs = logs;
|
165
|
+
await transaction.save();
|
166
|
+
}
|
167
|
+
else {
|
168
|
+
console.log("ExecutionFailure");
|
169
|
+
transaction.targetStatus = "failed";
|
170
|
+
if (txSent.blockNumber)
|
171
|
+
transaction.targetBlockNumber = txSent.blockNumber;
|
172
|
+
transaction.targetTransactionHash = txSent.hash;
|
173
|
+
transaction.status = "failed";
|
174
|
+
await transaction.save();
|
175
|
+
}
|
176
|
+
net_1.protocol.sendTransaction(transaction);
|
177
|
+
}
|
178
|
+
async start() {
|
179
|
+
this.blockConfirmationsCount = constants_1.blockConfirmations[this.chainId] + 1;
|
180
|
+
this.sourceProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
181
|
+
await super.start();
|
182
|
+
}
|
183
|
+
}
|
184
|
+
exports.default = ProcessValidateEvents;
|