@instadapp/interop-x 0.0.0-dev.e916c22 → 0.0.0-dev.ea4acf6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. package/dist/package.json +9 -2
  2. package/dist/src/abi/aaveV2Resolver.json +832 -0
  3. package/dist/src/abi/aaveV3Resolver.json +628 -0
  4. package/dist/src/abi/balanceResolver.json +211 -0
  5. package/dist/src/abi/index.js +6 -0
  6. package/dist/src/api/index.js +7 -0
  7. package/dist/src/constants/addresses.js +6 -0
  8. package/dist/src/constants/capPerChain.js +8 -0
  9. package/dist/src/constants/index.js +2 -0
  10. package/dist/src/constants/tokens.js +44 -44
  11. package/dist/src/constants/wrappedNativeToken.js +8 -0
  12. package/dist/src/crons/index.js +3 -0
  13. package/dist/src/crons/prices.js +16 -0
  14. package/dist/src/db/models/transaction.js +1 -1
  15. package/dist/src/errors/index.js +30 -0
  16. package/dist/src/gnosis/actions/aaveV2/source.js +26 -1
  17. package/dist/src/gnosis/actions/aaveV2/target.js +18 -4
  18. package/dist/src/gnosis/actions/aaveV3/index.js +11 -0
  19. package/dist/src/gnosis/actions/aaveV3/source.js +74 -0
  20. package/dist/src/gnosis/actions/aaveV3/target.js +87 -0
  21. package/dist/src/gnosis/actions/index.js +2 -0
  22. package/dist/src/index.js +2 -1
  23. package/dist/src/providers/index.js +17 -0
  24. package/dist/src/providers/retry-provider.js +45 -0
  25. package/dist/src/services/Prices.js +74 -0
  26. package/dist/src/services/index.js +8 -0
  27. package/dist/src/tasks/InteropX/{ProcessSubmitSubmitEvents.js → ProcessSubmitEvents.js} +108 -14
  28. package/dist/src/tasks/InteropX/ProcessValidateEvents.js +30 -10
  29. package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +3 -2
  30. package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +3 -2
  31. package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +3 -2
  32. package/dist/src/tasks/index.js +3 -4
  33. package/dist/src/typechain/AaveV2Resolver.js +2 -0
  34. package/dist/src/typechain/AaveV3Resolver.js +2 -0
  35. package/dist/src/typechain/BalanceResolver.js +2 -0
  36. package/dist/src/typechain/factories/AaveV2Resolver__factory.js +1191 -0
  37. package/dist/src/typechain/factories/AaveV3Resolver__factory.js +887 -0
  38. package/dist/src/typechain/factories/BalanceResolver__factory.js +228 -0
  39. package/dist/src/typechain/factories/index.js +7 -1
  40. package/dist/src/typechain/index.js +7 -1
  41. package/dist/src/utils/async.js +18 -0
  42. package/dist/src/utils/dsa.js +36 -0
  43. package/dist/src/utils/formatting.js +67 -0
  44. package/dist/src/utils/gnosis.js +87 -0
  45. package/dist/src/utils/http.js +10 -0
  46. package/dist/src/utils/index.js +22 -220
  47. package/dist/src/utils/interop.js +16 -0
  48. package/dist/src/utils/tokens.js +22 -0
  49. package/dist/src/utils/validate.js +111 -0
  50. package/dist/src/utils/web3.js +93 -0
  51. package/package.json +9 -2
  52. package/src/abi/aaveV2Resolver.json +832 -0
  53. package/src/abi/aaveV3Resolver.json +628 -0
  54. package/src/abi/balanceResolver.json +211 -0
  55. package/src/abi/index.ts +6 -0
  56. package/src/api/index.ts +8 -0
  57. package/src/constants/addresses.ts +18 -1
  58. package/src/constants/capPerChain.ts +5 -0
  59. package/src/constants/index.ts +2 -0
  60. package/src/constants/tokens.ts +44 -44
  61. package/src/constants/wrappedNativeToken.ts +5 -0
  62. package/src/crons/index.ts +1 -0
  63. package/src/crons/prices.ts +12 -0
  64. package/src/db/models/transaction.ts +1 -1
  65. package/src/errors/index.ts +26 -0
  66. package/src/gnosis/actions/aaveV2/source.ts +56 -3
  67. package/src/gnosis/actions/aaveV2/target.ts +30 -11
  68. package/src/gnosis/actions/aaveV3/index.ts +9 -0
  69. package/src/gnosis/actions/aaveV3/source.ts +119 -0
  70. package/src/gnosis/actions/aaveV3/target.ts +142 -0
  71. package/src/gnosis/actions/index.ts +2 -0
  72. package/src/index.ts +1 -0
  73. package/src/providers/index.ts +1 -0
  74. package/src/providers/retry-provider.ts +51 -0
  75. package/src/services/Prices.ts +89 -0
  76. package/src/services/index.ts +1 -0
  77. package/src/tasks/InteropX/{ProcessSubmitSubmitEvents.ts → ProcessSubmitEvents.ts} +135 -20
  78. package/src/tasks/InteropX/ProcessValidateEvents.ts +42 -19
  79. package/src/tasks/InteropX/SyncLogExecuteEvents.ts +5 -6
  80. package/src/tasks/InteropX/SyncLogSubmitEvents.ts +6 -7
  81. package/src/tasks/InteropX/SyncLogValidateEvents.ts +6 -7
  82. package/src/tasks/index.ts +3 -4
  83. package/src/typechain/AaveV2Resolver.ts +1017 -0
  84. package/src/typechain/AaveV3Resolver.ts +935 -0
  85. package/src/typechain/BalanceResolver.ts +266 -0
  86. package/src/typechain/factories/AaveV2Resolver__factory.ts +1198 -0
  87. package/src/typechain/factories/AaveV3Resolver__factory.ts +894 -0
  88. package/src/typechain/factories/BalanceResolver__factory.ts +235 -0
  89. package/src/typechain/factories/index.ts +3 -0
  90. package/src/typechain/index.ts +6 -0
  91. package/src/utils/async.ts +22 -0
  92. package/src/utils/dsa.ts +56 -0
  93. package/src/utils/formatting.ts +68 -0
  94. package/src/utils/gnosis.ts +166 -0
  95. package/src/utils/http.ts +6 -0
  96. package/src/utils/index.ts +9 -365
  97. package/src/utils/interop.ts +28 -0
  98. package/src/utils/tokens.ts +21 -0
  99. package/src/utils/validate.ts +179 -0
  100. package/src/utils/web3.ts +132 -0
@@ -0,0 +1,87 @@
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 abi_1 = __importDefault(require("@/abi"));
7
+ const config_1 = __importDefault(require("@/config"));
8
+ const constants_1 = require("@/constants");
9
+ const providers_1 = require("@/providers");
10
+ const utils_1 = require("@/utils");
11
+ const ethers_1 = require("ethers");
12
+ const ethers_multisend_1 = require("ethers-multisend");
13
+ async function default_1(transaction) {
14
+ const transactions = [];
15
+ const logs = [];
16
+ const { sourceSpells, position, actionId, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata, } = transaction.validateEvent;
17
+ const targetChainProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
18
+ const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
19
+ const targetInstListContract = (0, utils_1.getContract)(constants_1.addresses[targetChainId].instList, abi_1.default.instList, targetChainProvider);
20
+ const targetDsaAddress = await targetInstListContract.accountAddr(targetDsaId);
21
+ const dsaAddress = constants_1.addresses[targetChainId].dsaAddress;
22
+ const interopAddress = constants_1.addresses[targetChainId].interopX;
23
+ const contract = (0, utils_1.getContract)(interopAddress, abi_1.default.interopX, targetWallet);
24
+ const targetSpells = [];
25
+ const commonSpells = [];
26
+ for (const supplyToken of position.supply) {
27
+ let spellData = {
28
+ connector: "AAVE-V3-A",
29
+ method: "deposit",
30
+ args: [supplyToken.targetToken, supplyToken.amount, "0", "0"],
31
+ };
32
+ targetSpells.push({
33
+ connector: spellData.connector,
34
+ data: (0, utils_1.encodeConnectorMethod)(spellData),
35
+ });
36
+ let spellDataBasicWithdraw = {
37
+ connector: "BASIC-A",
38
+ method: "withdraw",
39
+ args: [supplyToken.targetToken, supplyToken.amount, targetDsaAddress, "0", "0"],
40
+ };
41
+ commonSpells.push({
42
+ connector: spellDataBasicWithdraw.connector,
43
+ data: (0, utils_1.encodeConnectorMethod)(spellDataBasicWithdraw),
44
+ });
45
+ }
46
+ for (const withdrawToken of position.withdraw) {
47
+ let spellData = {
48
+ connector: "AAVE-V3-A",
49
+ method: "borrow",
50
+ args: [
51
+ withdrawToken.targetToken,
52
+ withdrawToken.amount,
53
+ "2",
54
+ "0",
55
+ "0",
56
+ ],
57
+ };
58
+ targetSpells.push({
59
+ connector: spellData.connector,
60
+ data: (0, utils_1.encodeConnectorMethod)(spellData),
61
+ });
62
+ let spellData2 = {
63
+ connector: "BASIC-A",
64
+ method: "withdraw",
65
+ args: [
66
+ withdrawToken.targetToken,
67
+ withdrawToken.amount,
68
+ dsaAddress,
69
+ "0",
70
+ "0",
71
+ ],
72
+ };
73
+ targetSpells.push({
74
+ connector: spellData2.connector,
75
+ data: (0, utils_1.encodeConnectorMethod)(spellData2),
76
+ });
77
+ }
78
+ const { data } = await contract.populateTransaction.targetAction(sourceSpells, targetSpells, commonSpells, position, actionId, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata);
79
+ transactions.push({
80
+ to: interopAddress,
81
+ data: data,
82
+ value: "0",
83
+ operation: ethers_multisend_1.OperationType.Call,
84
+ });
85
+ return { transactions, logs };
86
+ }
87
+ exports.default = default_1;
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const aaveV2_1 = __importDefault(require("./aaveV2"));
7
+ const aaveV3_1 = __importDefault(require("./aaveV3"));
7
8
  exports.default = {
8
9
  'A:AAVE-V2:AAVE-V2': aaveV2_1.default,
10
+ 'A:AAVE-V3:AAVE-V3': aaveV3_1.default,
9
11
  };
package/dist/src/index.js CHANGED
@@ -13,7 +13,7 @@ const package_json_1 = __importDefault(require("../package.json"));
13
13
  dotenv_1.default.config();
14
14
  const logger_1 = __importDefault(require("@/logger"));
15
15
  const logger = new logger_1.default('Process');
16
- const GIT_SHORT_HASH = 'e916c22';
16
+ const GIT_SHORT_HASH = 'ea4acf6';
17
17
  const printUsage = () => {
18
18
  console.log();
19
19
  console.log(`Interop X Node (v${package_json_1.default.version} - rev.${GIT_SHORT_HASH})`);
@@ -69,6 +69,7 @@ const net_1 = require("@/net");
69
69
  const api_1 = require("@/api");
70
70
  const db_1 = require("./db");
71
71
  const utils_1 = require("./utils");
72
+ require("./crons");
72
73
  async function main() {
73
74
  (0, net_1.startPeer)({});
74
75
  const tasks = new tasks_1.Tasks();
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./retry-provider"), exports);
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.JsonRpcRetryProvider = exports.retryOperation = exports.promiseTimeout = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const waait_1 = __importDefault(require("waait"));
9
+ const bluebird_1 = __importDefault(require("bluebird"));
10
+ function promiseTimeout(ms, promise) {
11
+ return bluebird_1.default.resolve(promise).timeout(ms);
12
+ }
13
+ exports.promiseTimeout = promiseTimeout;
14
+ function retryOperation(retriesLeft, operation, options) {
15
+ return new Promise((resolve, reject) => {
16
+ const { timeouts } = options;
17
+ // Find the timeout for this specific iteration
18
+ const timeout = timeouts[timeouts.length - retriesLeft];
19
+ // Wrap the original operation in a timeout
20
+ const execution = promiseTimeout(timeout, operation());
21
+ // If the promise is successful, resolve it and bubble the result up
22
+ return execution.then(resolve).catch((reason) => {
23
+ // If there are any retries left, we call the same retryOperation function again,
24
+ // but decrementing the number of retries left by 1
25
+ if (retriesLeft - 1 > 0) {
26
+ // Delay the new attempt slightly
27
+ return (0, waait_1.default)(options.delay || 50)
28
+ .then(retryOperation.bind(null, retriesLeft - 1, operation, options))
29
+ .then(resolve)
30
+ .catch(reject);
31
+ }
32
+ // Reject (and bubble the result up) if there are no more retries
33
+ return reject(reason);
34
+ });
35
+ });
36
+ }
37
+ exports.retryOperation = retryOperation;
38
+ class JsonRpcRetryProvider extends ethers_1.ethers.providers.JsonRpcProvider {
39
+ perform(method, params) {
40
+ const timeouts = [5000, 10000];
41
+ const operation = () => super.perform(method, params);
42
+ return retryOperation(2, operation, { timeouts, delay: 50 });
43
+ }
44
+ }
45
+ exports.JsonRpcRetryProvider = JsonRpcRetryProvider;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const web3_utils_1 = __importDefault(require("web3-utils"));
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const constants_1 = require("@/constants");
10
+ const expand_home_dir_1 = __importDefault(require("expand-home-dir"));
11
+ const config_1 = __importDefault(require("@/config"));
12
+ const utils_1 = require("@/utils");
13
+ const basePath = (0, expand_home_dir_1.default)(`~/.interop-x/data/${config_1.default.publicAddress}/${config_1.default.staging ? 'staging' : ''}`);
14
+ const mainnetPricesFilePath = path_1.default.resolve(basePath, "./mainnetPrices.json");
15
+ const networkTokenPricesFilePath = path_1.default.resolve(basePath, "./networkTokenPrices.json");
16
+ class Prices {
17
+ static async fetch() {
18
+ if (!fs_1.default.existsSync(mainnetPricesFilePath)) {
19
+ fs_1.default.writeFileSync(mainnetPricesFilePath, JSON.stringify({}));
20
+ }
21
+ if (!fs_1.default.existsSync(networkTokenPricesFilePath)) {
22
+ fs_1.default.writeFileSync(networkTokenPricesFilePath, JSON.stringify({}));
23
+ }
24
+ this.mainnetPrices = JSON.parse(fs_1.default.readFileSync(mainnetPricesFilePath, "utf8"));
25
+ this.networkTokenPrices = JSON.parse(fs_1.default.readFileSync(networkTokenPricesFilePath, "utf8"));
26
+ try {
27
+ const path = constants_1.tokens["1"]
28
+ .filter((a) => a.symbol !== "ETH")
29
+ .map((token) => token.address)
30
+ .join(",");
31
+ const [response, ethResponse, avaxResponse, polygonResponse] = await Promise.all([
32
+ utils_1.http.get("https://api.coingecko.com/api/v3/simple/token_price/ethereum", {
33
+ params: { contract_addresses: path, vs_currencies: "usd" },
34
+ }),
35
+ utils_1.http.get("https://api.coingecko.com/api/v3/simple/price", {
36
+ params: { ids: "ethereum", vs_currencies: "usd" },
37
+ }),
38
+ utils_1.http.get("https://api.coingecko.com/api/v3/simple/price", {
39
+ params: { ids: "avalanche-2", vs_currencies: "usd" },
40
+ }),
41
+ utils_1.http.get("https://api.coingecko.com/api/v3/simple/price", {
42
+ params: { ids: "matic-network", vs_currencies: "usd" },
43
+ }),
44
+ ]);
45
+ this.networkTokenPrices = {
46
+ "1": ethResponse.data.ethereum.usd.toString(),
47
+ "137": polygonResponse.data["matic-network"].usd.toString(),
48
+ "43114": avaxResponse.data["avalanche-2"].usd.toString(),
49
+ };
50
+ const data = response.data;
51
+ for (const key in data) {
52
+ const _key = web3_utils_1.default.toChecksumAddress(key);
53
+ if (!data[key].usd)
54
+ continue;
55
+ this.mainnetPrices[_key] = data[key].usd.toString();
56
+ }
57
+ this.mainnetPrices["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"] =
58
+ ethResponse.data.ethereum.usd.toString();
59
+ }
60
+ catch (error) { }
61
+ fs_1.default.writeFileSync(mainnetPricesFilePath, JSON.stringify(this.mainnetPrices));
62
+ fs_1.default.writeFileSync(networkTokenPricesFilePath, JSON.stringify(this.networkTokenPrices));
63
+ return this.mainnetPrices;
64
+ }
65
+ static getMainnetPrices() {
66
+ return this.mainnetPrices;
67
+ }
68
+ static getNetworkTokenPrices() {
69
+ return this.networkTokenPrices;
70
+ }
71
+ }
72
+ Prices.mainnetPrices = {};
73
+ Prices.networkTokenPrices = {};
74
+ exports.default = Prices;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Prices = void 0;
7
+ var Prices_1 = require("./Prices");
8
+ Object.defineProperty(exports, "Prices", { enumerable: true, get: function () { return __importDefault(Prices_1).default; } });
@@ -16,10 +16,14 @@ const sequelize_1 = require("sequelize");
16
16
  const gnosis_1 = require("@/gnosis");
17
17
  const net_1 = require("@/net");
18
18
  const waait_1 = __importDefault(require("waait"));
19
- class ProcessSubmitSubmitEvents extends BaseTask_1.BaseTask {
19
+ const errors_1 = require("@/errors");
20
+ const bignumber_js_1 = require("bignumber.js");
21
+ const dedent_1 = __importDefault(require("dedent"));
22
+ const providers_1 = require("@/providers");
23
+ class ProcessSubmitEvents extends BaseTask_1.BaseTask {
20
24
  constructor({ chainId }) {
21
25
  super({
22
- logger: new logger_1.default("InteropX::ProcessSubmitSubmitEvents"),
26
+ logger: new logger_1.default("InteropX::ProcessSubmitEvents"),
23
27
  });
24
28
  this.leadNodeOnly = true;
25
29
  this.blockConfirmationsCount = 12;
@@ -54,6 +58,70 @@ class ProcessSubmitSubmitEvents extends BaseTask_1.BaseTask {
54
58
  this.logger.debug(`Processing transaction ${transaction.transactionHash}`);
55
59
  transaction.sourceStatus = "proccessing";
56
60
  await transaction.save();
61
+ const { submitEvent: { position, sourceChainId, targetChainId, sourceDsaId } } = transaction;
62
+ try {
63
+ (0, utils_1.validateChains)({ sourceChainId, targetChainId });
64
+ }
65
+ catch (error) {
66
+ transaction.sourceErrors = [error.message];
67
+ transaction.sourceStatus = "failed";
68
+ transaction.targetStatus = "failed";
69
+ transaction.status = "failed";
70
+ await transaction.save();
71
+ return;
72
+ }
73
+ const walletBalance = (await this.sourceWallet.getBalance()).toString();
74
+ const currentGasPrice = (await this.sourceWallet.getGasPrice()).toString();
75
+ const minBalanceRequired = new bignumber_js_1.BigNumber(currentGasPrice)
76
+ .multipliedBy(4000000)
77
+ .multipliedBy(2); // 2x balance
78
+ if (new bignumber_js_1.BigNumber(walletBalance).isLessThan(minBalanceRequired)) {
79
+ console.log((0, dedent_1.default) `Not enough balance in wallet ${(0, utils_1.getExplorerUrl)(sourceChainId, '/address/' + this.sourceWallet.address)} on ${(0, utils_1.chainIdToName)(sourceChainId)}
80
+ Balance: ${ethers_1.ethers.utils.parseEther(walletBalance)} ${(0, utils_1.getChainIdNativeSymbol)(sourceChainId)}
81
+ Required Balance: ${ethers_1.ethers.utils.parseEther(minBalanceRequired.toString())}
82
+ Require more: ${ethers_1.ethers.utils.parseEther(minBalanceRequired.minus(walletBalance).toString())}`);
83
+ transaction.sourceDelayUntil = (0, moment_1.default)().add({ minutes: 5 }).toDate();
84
+ transaction.sourceStatus = "pending";
85
+ await transaction.save();
86
+ return;
87
+ }
88
+ try {
89
+ await (0, utils_1.validateLiquidityCap)(position, sourceChainId, targetChainId);
90
+ }
91
+ catch (error) {
92
+ transaction.sourceErrors = [error.message];
93
+ transaction.sourceStatus = "failed";
94
+ transaction.targetStatus = "failed";
95
+ transaction.status = "failed";
96
+ await transaction.save();
97
+ return;
98
+ }
99
+ try {
100
+ await (0, utils_1.validateSourceLiquidity)({
101
+ position,
102
+ sourceChainId,
103
+ sourceDsaId,
104
+ sourceProvider: this.sourceProvider,
105
+ });
106
+ }
107
+ catch (error) {
108
+ if (error instanceof errors_1.UnsupportedChaindIdError) {
109
+ console.log(`Dropping transaction ${transaction.transactionHash}`);
110
+ transaction.sourceErrors = [error.message];
111
+ transaction.sourceStatus = "failed";
112
+ transaction.targetStatus = "failed";
113
+ transaction.status = "failed";
114
+ await transaction.save();
115
+ }
116
+ else {
117
+ transaction.sourceStatus = "pending";
118
+ transaction.sourceErrors = [error.message];
119
+ transaction.sourceDelayUntil = (0, moment_1.default)().add({ minutes: 5 }).toDate();
120
+ await transaction.save();
121
+ console.log("[validateSourceLiquidity][Warning]", error.message);
122
+ return;
123
+ }
124
+ }
57
125
  const ownersThreshold = await this.sourceGnosisContract.getThreshold();
58
126
  await (0, waait_1.default)(10000);
59
127
  this.logger.debug(`Build gnosis action for ${transaction.transactionHash}`);
@@ -62,7 +130,7 @@ class ProcessSubmitSubmitEvents extends BaseTask_1.BaseTask {
62
130
  ({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction, "source"));
63
131
  }
64
132
  catch (error) {
65
- if (error instanceof utils_1.LiquidityError) {
133
+ if (error instanceof errors_1.LiquidityError) {
66
134
  await transaction.save();
67
135
  transaction.sourceDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
68
136
  transaction.sourceStatus = "pending";
@@ -92,14 +160,26 @@ class ProcessSubmitSubmitEvents extends BaseTask_1.BaseTask {
92
160
  to: constants_1.addresses[transaction.sourceChainId].multisend,
93
161
  value: "0",
94
162
  }, this.sourceGnosisContract);
95
- const owners = await this.sourceGnosisContract
96
- .getOwners()
97
- .then((owners) => owners.map((owner) => owner.toLowerCase()));
98
- const ownerPeerIds = net_1.peerPool.activePeers
99
- .filter((peer) => owners.includes(peer.publicAddress.toLowerCase()))
100
- .map((peer) => peer.id);
101
- console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
163
+ async function getGnosisOwnerPeerIds({ gnosisContract }) {
164
+ const owners = await gnosisContract
165
+ .getOwners()
166
+ .then((owners) => owners.map((owner) => owner.toLowerCase()));
167
+ return net_1.peerPool.activePeers
168
+ .filter((peer) => owners.includes(peer.publicAddress.toLowerCase()))
169
+ .map((peer) => peer.id);
170
+ }
171
+ const ownerPeerIds = await getGnosisOwnerPeerIds({
172
+ gnosisContract: this.sourceGnosisContract,
173
+ });
174
+ console.log(`Collecting signatures for execution ${transaction.transactionHash} `);
102
175
  console.log(ownerPeerIds);
176
+ const message = (0, utils_1.generateGnosisSignatureMessage)({
177
+ to: constants_1.addresses[this.chainId].multisend,
178
+ data,
179
+ chainId: this.chainId,
180
+ safeTxGas: gnosisTx.safeTxGas,
181
+ nonce: gnosisTx.safeNonce,
182
+ });
103
183
  const signatures = await net_1.protocol.requestSignatures({
104
184
  type: "source",
105
185
  transactionHash: transaction.transactionHash,
@@ -107,7 +187,21 @@ class ProcessSubmitSubmitEvents extends BaseTask_1.BaseTask {
107
187
  safeNonce: gnosisTx.nonce,
108
188
  chainId: this.chainId,
109
189
  }, ownerPeerIds);
110
- const validSignatures = signatures.filter((s) => !!s.data && s.data !== "0x");
190
+ const validSignatures = signatures
191
+ .filter((s) => !!s.data && s.data !== "0x")
192
+ .filter((s) => {
193
+ try {
194
+ const address = (0, utils_1.getGnosisSignatureAddress)({
195
+ message,
196
+ signature: s.data,
197
+ chainId: this.chainId,
198
+ });
199
+ return (address === null || address === void 0 ? void 0 : address.toLowerCase()) === s.signer.toLowerCase();
200
+ }
201
+ catch (error) {
202
+ return false;
203
+ }
204
+ });
111
205
  console.log({
112
206
  signatures,
113
207
  validSignatures,
@@ -120,7 +214,7 @@ class ProcessSubmitSubmitEvents extends BaseTask_1.BaseTask {
120
214
  transaction.sourceStatus = "pending";
121
215
  await transaction.save();
122
216
  const errorMessage = (_a = signatures.find((s) => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
123
- throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ""));
217
+ throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage} ` : ""));
124
218
  }
125
219
  console.log(`Executing transaction for execution ${transaction.transactionHash}`);
126
220
  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));
@@ -170,10 +264,10 @@ class ProcessSubmitSubmitEvents extends BaseTask_1.BaseTask {
170
264
  }
171
265
  async start() {
172
266
  this.blockConfirmationsCount = constants_1.blockConfirmations[this.chainId] + 1;
173
- this.sourceProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
267
+ this.sourceProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
174
268
  this.sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, this.sourceProvider);
175
269
  this.sourceGnosisContract = (0, utils_1.getContract)(constants_1.addresses[this.chainId].gnosisSafe, abi_1.default.gnosisSafe, this.sourceWallet);
176
270
  await super.start();
177
271
  }
178
272
  }
179
- exports.default = ProcessSubmitSubmitEvents;
273
+ exports.default = ProcessSubmitEvents;
@@ -16,6 +16,8 @@ const sequelize_1 = require("sequelize");
16
16
  const gnosis_1 = require("@/gnosis");
17
17
  const net_1 = require("@/net");
18
18
  const waait_1 = __importDefault(require("waait"));
19
+ const errors_1 = require("@/errors");
20
+ const providers_1 = require("@/providers");
19
21
  class ProcessValidateEvents extends BaseTask_1.BaseTask {
20
22
  constructor({ chainId }) {
21
23
  super({
@@ -57,7 +59,7 @@ class ProcessValidateEvents extends BaseTask_1.BaseTask {
57
59
  transaction.targetStatus = "proccessing";
58
60
  await transaction.save();
59
61
  const { sourceChainId, targetChainId } = transaction.validateEvent;
60
- const targetProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
62
+ const targetProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
61
63
  const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetProvider);
62
64
  const targetGnosisContract = (0, utils_1.getContract)(constants_1.addresses[targetChainId].gnosisSafe, abi_1.default.gnosisSafe, targetWallet);
63
65
  const ownersThreshold = await targetGnosisContract.getThreshold();
@@ -68,7 +70,7 @@ class ProcessValidateEvents extends BaseTask_1.BaseTask {
68
70
  ({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction, "target"));
69
71
  }
70
72
  catch (error) {
71
- if (error instanceof utils_1.LiquidityError) {
73
+ if (error instanceof errors_1.LiquidityError) {
72
74
  await transaction.save();
73
75
  transaction.targetDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
74
76
  transaction.targetStatus = "pending";
@@ -97,14 +99,18 @@ class ProcessValidateEvents extends BaseTask_1.BaseTask {
97
99
  to: constants_1.addresses[transaction.targetChainId].multisend,
98
100
  value: "0",
99
101
  }, targetGnosisContract);
100
- const owners = await targetGnosisContract
101
- .getOwners()
102
- .then((owners) => owners.map((owner) => owner.toLowerCase()));
103
- const ownerPeerIds = net_1.peerPool.activePeers
104
- .filter((peer) => owners.includes(peer.publicAddress.toLowerCase()))
105
- .map((peer) => peer.id);
102
+ const ownerPeerIds = await (0, utils_1.getGnosisOwnerPeerIds)({
103
+ gnosisContract: targetGnosisContract,
104
+ });
106
105
  console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
107
106
  console.log(ownerPeerIds);
107
+ const message = (0, utils_1.generateGnosisSignatureMessage)({
108
+ to: constants_1.addresses[targetChainId].multisend,
109
+ data,
110
+ chainId: targetChainId,
111
+ safeTxGas: gnosisTx.safeTxGas,
112
+ nonce: gnosisTx.safeNonce,
113
+ });
108
114
  const signatures = await net_1.protocol.requestSignatures({
109
115
  type: "target",
110
116
  transactionHash: transaction.transactionHash,
@@ -112,7 +118,21 @@ class ProcessValidateEvents extends BaseTask_1.BaseTask {
112
118
  safeNonce: gnosisTx.nonce,
113
119
  chainId: targetChainId,
114
120
  }, ownerPeerIds);
115
- const validSignatures = signatures.filter((s) => !!s.data && s.data !== "0x");
121
+ const validSignatures = signatures
122
+ .filter((s) => !!s.data && s.data !== "0x")
123
+ .filter((s) => {
124
+ try {
125
+ const address = (0, utils_1.getGnosisSignatureAddress)({
126
+ message,
127
+ signature: s.data,
128
+ chainId: targetChainId,
129
+ });
130
+ return (address === null || address === void 0 ? void 0 : address.toLowerCase()) === s.signer.toLowerCase();
131
+ }
132
+ catch (error) {
133
+ return false;
134
+ }
135
+ });
116
136
  console.log({
117
137
  signatures,
118
138
  validSignatures,
@@ -176,7 +196,7 @@ class ProcessValidateEvents extends BaseTask_1.BaseTask {
176
196
  }
177
197
  async start() {
178
198
  this.blockConfirmationsCount = constants_1.blockConfirmations[this.chainId] + 1;
179
- this.sourceProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
199
+ this.sourceProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
180
200
  await super.start();
181
201
  }
182
202
  }
@@ -12,6 +12,7 @@ const utils_1 = require("@/utils");
12
12
  const constants_1 = require("@/constants");
13
13
  const config_1 = __importDefault(require("@/config"));
14
14
  const sequelize_1 = require("sequelize");
15
+ const providers_1 = require("@/providers");
15
16
  class SyncLogExecuteEvents extends BaseTask_1.BaseTask {
16
17
  constructor({ targetChainId }) {
17
18
  super({
@@ -93,7 +94,7 @@ class SyncLogExecuteEvents extends BaseTask_1.BaseTask {
93
94
  metadata,
94
95
  };
95
96
  await transaction.save();
96
- this.logger.info(`New InteropX tranaction: ${transactionHash} `);
97
+ this.logger.info(`New InteropX transaction: ${transactionHash} `);
97
98
  }
98
99
  catch (error) {
99
100
  this.logger.error(error);
@@ -104,7 +105,7 @@ class SyncLogExecuteEvents extends BaseTask_1.BaseTask {
104
105
  }
105
106
  async start() {
106
107
  this.contractAddress = constants_1.addresses[this.targetChainId].interopX;
107
- this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.targetChainId));
108
+ this.provider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(this.targetChainId));
108
109
  this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopX, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
109
110
  await super.start();
110
111
  }
@@ -11,6 +11,7 @@ const db_1 = require("@/db");
11
11
  const utils_1 = require("@/utils");
12
12
  const constants_1 = require("@/constants");
13
13
  const config_1 = __importDefault(require("@/config"));
14
+ const providers_1 = require("@/providers");
14
15
  class SyncLogSubmitEvents extends BaseTask_1.BaseTask {
15
16
  constructor({ chainId }) {
16
17
  super({
@@ -68,7 +69,7 @@ class SyncLogSubmitEvents extends BaseTask_1.BaseTask {
68
69
  targetDsaId: targetDsaId.toString(),
69
70
  metadata,
70
71
  } }));
71
- this.logger.info(`New InteropX tranaction: ${transactionHash} `);
72
+ this.logger.info(`New InteropX transaction: ${transactionHash} `);
72
73
  }
73
74
  catch (error) {
74
75
  this.logger.error(error);
@@ -79,7 +80,7 @@ class SyncLogSubmitEvents extends BaseTask_1.BaseTask {
79
80
  }
80
81
  async start() {
81
82
  this.contractAddress = constants_1.addresses[this.chainId].interopX;
82
- this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
83
+ this.provider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
83
84
  this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopX, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
84
85
  await super.start();
85
86
  }
@@ -12,6 +12,7 @@ const utils_1 = require("@/utils");
12
12
  const constants_1 = require("@/constants");
13
13
  const config_1 = __importDefault(require("@/config"));
14
14
  const sequelize_1 = require("sequelize");
15
+ const providers_1 = require("@/providers");
15
16
  class SyncLogValidateEvents extends BaseTask_1.BaseTask {
16
17
  constructor({ chainId }) {
17
18
  super({
@@ -86,7 +87,7 @@ class SyncLogValidateEvents extends BaseTask_1.BaseTask {
86
87
  metadata,
87
88
  };
88
89
  await transaction.save();
89
- this.logger.info(`New InteropX tranaction: ${transactionHash} `);
90
+ this.logger.info(`New InteropX transaction: ${transactionHash} `);
90
91
  }
91
92
  catch (error) {
92
93
  this.logger.error(error);
@@ -97,7 +98,7 @@ class SyncLogValidateEvents extends BaseTask_1.BaseTask {
97
98
  }
98
99
  async start() {
99
100
  this.contractAddress = constants_1.addresses[this.chainId].interopX;
100
- this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
101
+ this.provider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
101
102
  this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopX, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
102
103
  await super.start();
103
104
  }
@@ -8,20 +8,19 @@ const waait_1 = __importDefault(require("waait"));
8
8
  const SyncTransactionStatusTask_1 = __importDefault(require("./Transactions/SyncTransactionStatusTask"));
9
9
  const AutoUpdateTask_1 = __importDefault(require("./AutoUpdateTask"));
10
10
  const SyncLogSubmitEvents_1 = __importDefault(require("./InteropX/SyncLogSubmitEvents"));
11
- const ProcessSubmitSubmitEvents_1 = __importDefault(require("./InteropX/ProcessSubmitSubmitEvents"));
11
+ const ProcessSubmitEvents_1 = __importDefault(require("./InteropX/ProcessSubmitEvents"));
12
12
  const SyncLogValidateEvents_1 = __importDefault(require("./InteropX/SyncLogValidateEvents"));
13
13
  const ProcessValidateEvents_1 = __importDefault(require("./InteropX/ProcessValidateEvents"));
14
14
  const SyncLogExecuteEvents_1 = __importDefault(require("./InteropX/SyncLogExecuteEvents"));
15
15
  class Tasks {
16
16
  constructor() {
17
17
  this.tasks = [
18
- // new SyncTransactionStatusTask(),
19
18
  new AutoUpdateTask_1.default(),
20
19
  // InteropX
21
20
  new SyncLogSubmitEvents_1.default({ chainId: 137 }),
22
21
  new SyncLogSubmitEvents_1.default({ chainId: 43114 }),
23
- new ProcessSubmitSubmitEvents_1.default({ chainId: 137 }),
24
- new ProcessSubmitSubmitEvents_1.default({ chainId: 43114 }),
22
+ new ProcessSubmitEvents_1.default({ chainId: 137 }),
23
+ new ProcessSubmitEvents_1.default({ chainId: 43114 }),
25
24
  new SyncLogValidateEvents_1.default({ chainId: 137 }),
26
25
  new SyncLogValidateEvents_1.default({ chainId: 43114 }),
27
26
  new ProcessValidateEvents_1.default({ chainId: 137 }),
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });