@instadapp/interop-x 0.0.0-dev.f39d622 → 0.0.0-dev.f45bd03
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/dist/package.json +4 -2
- package/dist/src/abi/aaveV3Resolver.json +628 -0
- package/dist/src/abi/index.js +2 -0
- package/dist/src/constants/addresses.js +4 -2
- package/dist/src/db/models/transaction.js +1 -1
- package/dist/src/gnosis/actions/aaveV2/source.js +26 -1
- package/dist/src/gnosis/actions/aaveV2/target.js +16 -1
- package/dist/src/gnosis/actions/aaveV3/index.js +11 -0
- package/dist/src/gnosis/actions/aaveV3/source.js +74 -0
- package/dist/src/gnosis/actions/aaveV3/target.js +87 -0
- package/dist/src/gnosis/actions/index.js +2 -0
- package/dist/src/index.js +1 -1
- package/dist/src/providers/index.js +17 -0
- package/dist/src/providers/retry-provider.js +45 -0
- package/dist/src/tasks/InteropX/ProcessSubmitEvents.js +38 -10
- package/dist/src/tasks/InteropX/ProcessValidateEvents.js +28 -9
- package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +2 -1
- package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +2 -1
- package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +2 -1
- package/dist/src/typechain/AaveV3Resolver.js +2 -0
- package/dist/src/typechain/factories/AaveV3Resolver__factory.js +887 -0
- package/dist/src/typechain/factories/index.js +3 -1
- package/dist/src/typechain/index.js +3 -1
- package/dist/src/utils/gnosis.js +42 -17
- package/dist/src/utils/validate.js +10 -14
- package/package.json +4 -2
- package/src/abi/aaveV3Resolver.json +628 -0
- package/src/abi/index.ts +2 -0
- package/src/constants/addresses.ts +6 -3
- package/src/db/models/transaction.ts +1 -1
- package/src/gnosis/actions/aaveV2/source.ts +58 -2
- package/src/gnosis/actions/aaveV2/target.ts +29 -2
- package/src/gnosis/actions/aaveV3/index.ts +9 -0
- package/src/gnosis/actions/aaveV3/source.ts +119 -0
- package/src/gnosis/actions/aaveV3/target.ts +142 -0
- package/src/gnosis/actions/index.ts +2 -0
- package/src/providers/index.ts +1 -0
- package/src/providers/retry-provider.ts +51 -0
- package/src/tasks/InteropX/ProcessSubmitEvents.ts +52 -13
- package/src/tasks/InteropX/ProcessValidateEvents.ts +39 -13
- package/src/tasks/InteropX/SyncLogExecuteEvents.ts +3 -2
- package/src/tasks/InteropX/SyncLogSubmitEvents.ts +3 -2
- package/src/tasks/InteropX/SyncLogValidateEvents.ts +3 -2
- package/src/typechain/AaveV3Resolver.ts +935 -0
- package/src/typechain/factories/AaveV3Resolver__factory.ts +894 -0
- package/src/typechain/factories/index.ts +1 -0
- package/src/typechain/index.ts +2 -0
- package/src/utils/gnosis.ts +75 -32
- package/src/utils/validate.ts +17 -19
@@ -8,7 +8,8 @@ exports.addresses = {
|
|
8
8
|
interopX: '0xDB6083df37C5F224a3dF84A4B5f9fB60b6c8670a',
|
9
9
|
dsaAddress: '0x9Fbd453a8e7a158510fBae5D9935958507cf4b19',
|
10
10
|
instList: "0x839c2D3aDe63DF5b0b8F3E57D5e145057Ab41556",
|
11
|
-
|
11
|
+
aaveV2Resolver: "0x0731c1d0154C2bE74d50e2083Df10aa531AAbb10",
|
12
|
+
aaveV3Resolver: "0x1bD311bd5aD4DCfE18bCb55d42F0a3c714E2bfDe",
|
12
13
|
balanceResolver: "0xecc3991846bB21717B95A593Fd86C5930A491F95",
|
13
14
|
},
|
14
15
|
43114: {
|
@@ -17,7 +18,8 @@ exports.addresses = {
|
|
17
18
|
interopX: '0xA82A87096709E3D8648c9d9a22f31133bC4B6d32',
|
18
19
|
dsaAddress: '0x995e67a652d2be45a8bff438b3dfac66dfff1c46',
|
19
20
|
instList: "0x9926955e0Dd681Dc303370C52f4Ad0a4dd061687",
|
20
|
-
|
21
|
+
aaveV2Resolver: "0x7C5C59944263311a1e350E3B871B0d1d8E9A513E",
|
22
|
+
aaveV3Resolver: "0xB0862d7dB941698A0A92F8dF6672F4B56A5F5b02",
|
21
23
|
balanceResolver: "0xD45dFA34cEeAB567208041331F5ed9916C23b1E8",
|
22
24
|
}
|
23
25
|
};
|
@@ -40,7 +40,7 @@ Transaction.init({
|
|
40
40
|
type: sequelize_2.DataTypes.DATE,
|
41
41
|
defaultValue: Date.now(),
|
42
42
|
},
|
43
|
-
sourceDelayUntil: sequelize_2.DataTypes.
|
43
|
+
sourceDelayUntil: sequelize_2.DataTypes.DATE,
|
44
44
|
targetChainId: sequelize_2.DataTypes.NUMBER,
|
45
45
|
targetDsaId: sequelize_2.DataTypes.STRING,
|
46
46
|
targetTransactionHash: sequelize_2.DataTypes.STRING,
|
@@ -6,19 +6,44 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const abi_1 = __importDefault(require("@/abi"));
|
7
7
|
const config_1 = __importDefault(require("@/config"));
|
8
8
|
const constants_1 = require("@/constants");
|
9
|
+
const providers_1 = require("@/providers");
|
9
10
|
const utils_1 = require("@/utils");
|
10
11
|
const ethers_1 = require("ethers");
|
11
12
|
const ethers_multisend_1 = require("ethers-multisend");
|
13
|
+
const safeUserRatioGap = "800000000000000000";
|
12
14
|
async function default_1(transaction) {
|
13
15
|
const transactions = [];
|
14
16
|
const logs = [];
|
15
17
|
const { position, actionId, actionIdHashHash, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata, } = transaction.submitEvent;
|
16
|
-
const sourceChainProvider = new
|
18
|
+
const sourceChainProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(sourceChainId));
|
17
19
|
const sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, sourceChainProvider);
|
20
|
+
const targetChainProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
|
21
|
+
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
18
22
|
const dsaAddress = constants_1.addresses[sourceChainId].dsaAddress;
|
19
23
|
const sourceUserAddress = Number(sourceDsaId) == 0 ? sourceSender : dsaAddress;
|
20
24
|
const interopAddress = constants_1.addresses[sourceChainId].interopX;
|
21
25
|
const contract = (0, utils_1.getContract)(interopAddress, abi_1.default.interopX, sourceWallet);
|
26
|
+
const sourceResolverContract = (0, utils_1.getContract)(constants_1.addresses[sourceChainId].aaveV2Resolver, abi_1.default.aaveV2Resolver, sourceWallet);
|
27
|
+
const targetResolverContract = (0, utils_1.getContract)(constants_1.addresses[targetChainId].aaveV2Resolver, abi_1.default.aaveV2Resolver, targetWallet);
|
28
|
+
const sourceAavePosition = await sourceResolverContract.checkAavePosition(sourceUserAddress, position, safeUserRatioGap, false);
|
29
|
+
const userSourceAaveIsOk = sourceAavePosition.isOk;
|
30
|
+
if (!userSourceAaveIsOk) {
|
31
|
+
throw new Error("Source chain aave position is not safe to migrate.");
|
32
|
+
}
|
33
|
+
const targetInstListContract = (0, utils_1.getContract)(constants_1.addresses[targetChainId].instList, abi_1.default.instList, targetChainProvider);
|
34
|
+
const targetDsaAddress = await targetInstListContract.accountAddr(targetDsaId);
|
35
|
+
const targetAavePosition = await targetResolverContract
|
36
|
+
.checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true);
|
37
|
+
const userTargetAaveIsOk = targetAavePosition.isOk;
|
38
|
+
if (!userTargetAaveIsOk) {
|
39
|
+
throw new Error("Target chain aave position will not be safe after migration.");
|
40
|
+
}
|
41
|
+
const targetAavePositionWithFee = await targetResolverContract
|
42
|
+
.checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true);
|
43
|
+
const userTargetAaveIsOkWithFee = targetAavePositionWithFee.isOk;
|
44
|
+
if (!userTargetAaveIsOkWithFee) {
|
45
|
+
throw new Error("Target chain aave position will not be safe after migration due to minimum fee.");
|
46
|
+
}
|
22
47
|
const sourceSpells = [];
|
23
48
|
const commonSpells = [];
|
24
49
|
for (const withdraw of position.withdraw) {
|
@@ -6,17 +6,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const abi_1 = __importDefault(require("@/abi"));
|
7
7
|
const config_1 = __importDefault(require("@/config"));
|
8
8
|
const constants_1 = require("@/constants");
|
9
|
+
const providers_1 = require("@/providers");
|
9
10
|
const utils_1 = require("@/utils");
|
10
11
|
const ethers_1 = require("ethers");
|
11
12
|
const ethers_multisend_1 = require("ethers-multisend");
|
13
|
+
const safeUserRatioGap = "800000000000000000";
|
12
14
|
async function default_1(transaction) {
|
13
15
|
const transactions = [];
|
14
16
|
const logs = [];
|
15
17
|
const { sourceSpells, position, actionId, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata, } = transaction.validateEvent;
|
16
|
-
const targetChainProvider = new
|
18
|
+
const targetChainProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
|
17
19
|
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
20
|
+
const targetResolverContract = (0, utils_1.getContract)(constants_1.addresses[targetChainId].aaveV2Resolver, abi_1.default.aaveV2Resolver, targetWallet);
|
18
21
|
const targetInstListContract = (0, utils_1.getContract)(constants_1.addresses[targetChainId].instList, abi_1.default.instList, targetChainProvider);
|
19
22
|
const targetDsaAddress = await targetInstListContract.accountAddr(targetDsaId);
|
23
|
+
const targetAavePosition = await targetResolverContract
|
24
|
+
.checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true);
|
25
|
+
const userTargetAaveIsOk = targetAavePosition.isOk;
|
26
|
+
if (!userTargetAaveIsOk) {
|
27
|
+
throw new Error("Target chain aave position will not be safe after migration.");
|
28
|
+
}
|
29
|
+
const targetAavePositionWithFee = await targetResolverContract
|
30
|
+
.checkAavePosition(targetDsaAddress, position, safeUserRatioGap, true);
|
31
|
+
const userTargetAaveIsOkWithFee = targetAavePositionWithFee.isOk;
|
32
|
+
if (!userTargetAaveIsOkWithFee) {
|
33
|
+
throw new Error("Target chain aave position will not be safe after migration due to minimum fee.");
|
34
|
+
}
|
20
35
|
const dsaAddress = constants_1.addresses[targetChainId].dsaAddress;
|
21
36
|
const interopAddress = constants_1.addresses[targetChainId].interopX;
|
22
37
|
const contract = (0, utils_1.getContract)(interopAddress, abi_1.default.interopX, targetWallet);
|
@@ -0,0 +1,11 @@
|
|
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 source_1 = __importDefault(require("./source"));
|
7
|
+
const target_1 = __importDefault(require("./target"));
|
8
|
+
async function default_1(transaction, type) {
|
9
|
+
return type === 'source' ? (0, source_1.default)(transaction) : (0, target_1.default)(transaction);
|
10
|
+
}
|
11
|
+
exports.default = default_1;
|
@@ -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 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 { position, actionId, actionIdHashHash, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata, } = transaction.submitEvent;
|
17
|
+
const sourceChainProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(sourceChainId));
|
18
|
+
const sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, sourceChainProvider);
|
19
|
+
const dsaAddress = constants_1.addresses[sourceChainId].dsaAddress;
|
20
|
+
const sourceUserAddress = Number(sourceDsaId) == 0 ? sourceSender : dsaAddress;
|
21
|
+
const interopAddress = constants_1.addresses[sourceChainId].interopX;
|
22
|
+
const contract = (0, utils_1.getContract)(interopAddress, abi_1.default.interopX, sourceWallet);
|
23
|
+
const sourceSpells = [];
|
24
|
+
const commonSpells = [];
|
25
|
+
for (const withdraw of position.withdraw) {
|
26
|
+
let spellData = {
|
27
|
+
connector: "AAVE-V3-A",
|
28
|
+
method: "payback",
|
29
|
+
args: [withdraw.sourceToken, withdraw.amount, "2", "0", "0"],
|
30
|
+
};
|
31
|
+
sourceSpells.push({
|
32
|
+
connector: spellData.connector,
|
33
|
+
data: (0, utils_1.encodeConnectorMethod)(spellData),
|
34
|
+
});
|
35
|
+
let spellDataBasicWithdraw = {
|
36
|
+
connector: "BASIC-A",
|
37
|
+
method: "withdraw",
|
38
|
+
args: [withdraw.sourceToken, withdraw.amount, sourceUserAddress, "0", "0"],
|
39
|
+
};
|
40
|
+
commonSpells.push({
|
41
|
+
connector: spellDataBasicWithdraw.connector,
|
42
|
+
data: (0, utils_1.encodeConnectorMethod)(spellDataBasicWithdraw),
|
43
|
+
});
|
44
|
+
}
|
45
|
+
for (const supply of position.supply) {
|
46
|
+
let spellDataWithdraw = {
|
47
|
+
connector: "AAVE-V3-A",
|
48
|
+
method: "withdraw",
|
49
|
+
args: [supply.sourceToken, supply.amount, "0", "0"],
|
50
|
+
};
|
51
|
+
sourceSpells.push({
|
52
|
+
connector: spellDataWithdraw.connector,
|
53
|
+
data: (0, utils_1.encodeConnectorMethod)(spellDataWithdraw),
|
54
|
+
});
|
55
|
+
let spellDataBasicWithdraw = {
|
56
|
+
connector: "BASIC-A",
|
57
|
+
method: "withdraw",
|
58
|
+
args: [supply.sourceToken, supply.amount, dsaAddress, "0", "0"],
|
59
|
+
};
|
60
|
+
sourceSpells.push({
|
61
|
+
connector: spellDataBasicWithdraw.connector,
|
62
|
+
data: (0, utils_1.encodeConnectorMethod)(spellDataBasicWithdraw),
|
63
|
+
});
|
64
|
+
}
|
65
|
+
const { data } = await contract.populateTransaction.sourceAction(sourceSpells, commonSpells, position, actionId, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata);
|
66
|
+
transactions.push({
|
67
|
+
to: interopAddress,
|
68
|
+
data: data,
|
69
|
+
value: "0",
|
70
|
+
operation: ethers_multisend_1.OperationType.Call,
|
71
|
+
});
|
72
|
+
return { transactions, logs };
|
73
|
+
}
|
74
|
+
exports.default = default_1;
|
@@ -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: spellData.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 = '
|
16
|
+
const GIT_SHORT_HASH = 'f45bd03';
|
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})`);
|
@@ -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;
|
@@ -19,6 +19,7 @@ const waait_1 = __importDefault(require("waait"));
|
|
19
19
|
const errors_1 = require("@/errors");
|
20
20
|
const bignumber_js_1 = require("bignumber.js");
|
21
21
|
const dedent_1 = __importDefault(require("dedent"));
|
22
|
+
const providers_1 = require("@/providers");
|
22
23
|
class ProcessSubmitEvents extends BaseTask_1.BaseTask {
|
23
24
|
constructor({ chainId }) {
|
24
25
|
super({
|
@@ -113,6 +114,7 @@ class ProcessSubmitEvents extends BaseTask_1.BaseTask {
|
|
113
114
|
}
|
114
115
|
else {
|
115
116
|
transaction.sourceStatus = "pending";
|
117
|
+
transaction.sourceErrors = [error.message];
|
116
118
|
transaction.sourceDelayUntil = (0, moment_1.default)().add({ minutes: 5 }).toDate();
|
117
119
|
await transaction.save();
|
118
120
|
console.log("[validateSourceLiquidity][Warning]", error.message);
|
@@ -157,14 +159,26 @@ class ProcessSubmitEvents extends BaseTask_1.BaseTask {
|
|
157
159
|
to: constants_1.addresses[transaction.sourceChainId].multisend,
|
158
160
|
value: "0",
|
159
161
|
}, this.sourceGnosisContract);
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
162
|
+
async function getGnosisOwnerPeerIds({ gnosisContract }) {
|
163
|
+
const owners = await gnosisContract
|
164
|
+
.getOwners()
|
165
|
+
.then((owners) => owners.map((owner) => owner.toLowerCase()));
|
166
|
+
return net_1.peerPool.activePeers
|
167
|
+
.filter((peer) => owners.includes(peer.publicAddress.toLowerCase()))
|
168
|
+
.map((peer) => peer.id);
|
169
|
+
}
|
170
|
+
const ownerPeerIds = await getGnosisOwnerPeerIds({
|
171
|
+
gnosisContract: this.sourceGnosisContract,
|
172
|
+
});
|
173
|
+
console.log(`Collecting signatures for execution ${transaction.transactionHash} `);
|
167
174
|
console.log(ownerPeerIds);
|
175
|
+
const message = (0, utils_1.generateGnosisSignatureMessage)({
|
176
|
+
to: constants_1.addresses[data.chainId].multisend,
|
177
|
+
data,
|
178
|
+
chainId: this.chainId,
|
179
|
+
safeTxGas: gnosisTx.safeTxGas,
|
180
|
+
nonce: gnosisTx.safeNonce,
|
181
|
+
});
|
168
182
|
const signatures = await net_1.protocol.requestSignatures({
|
169
183
|
type: "source",
|
170
184
|
transactionHash: transaction.transactionHash,
|
@@ -172,7 +186,21 @@ class ProcessSubmitEvents extends BaseTask_1.BaseTask {
|
|
172
186
|
safeNonce: gnosisTx.nonce,
|
173
187
|
chainId: this.chainId,
|
174
188
|
}, ownerPeerIds);
|
175
|
-
const validSignatures = signatures
|
189
|
+
const validSignatures = signatures
|
190
|
+
.filter((s) => !!s.data && s.data !== "0x")
|
191
|
+
.filter((s) => {
|
192
|
+
try {
|
193
|
+
const address = (0, utils_1.getGnosisSignatureAddress)({
|
194
|
+
message,
|
195
|
+
signature: s.data,
|
196
|
+
chainId: this.chainId,
|
197
|
+
});
|
198
|
+
return (address === null || address === void 0 ? void 0 : address.toLowerCase()) === s.signer.toLowerCase();
|
199
|
+
}
|
200
|
+
catch (error) {
|
201
|
+
return false;
|
202
|
+
}
|
203
|
+
});
|
176
204
|
console.log({
|
177
205
|
signatures,
|
178
206
|
validSignatures,
|
@@ -185,7 +213,7 @@ class ProcessSubmitEvents extends BaseTask_1.BaseTask {
|
|
185
213
|
transaction.sourceStatus = "pending";
|
186
214
|
await transaction.save();
|
187
215
|
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}` : ""));
|
216
|
+
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage} ` : ""));
|
189
217
|
}
|
190
218
|
console.log(`Executing transaction for execution ${transaction.transactionHash}`);
|
191
219
|
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));
|
@@ -235,7 +263,7 @@ class ProcessSubmitEvents extends BaseTask_1.BaseTask {
|
|
235
263
|
}
|
236
264
|
async start() {
|
237
265
|
this.blockConfirmationsCount = constants_1.blockConfirmations[this.chainId] + 1;
|
238
|
-
this.sourceProvider = new
|
266
|
+
this.sourceProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
239
267
|
this.sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, this.sourceProvider);
|
240
268
|
this.sourceGnosisContract = (0, utils_1.getContract)(constants_1.addresses[this.chainId].gnosisSafe, abi_1.default.gnosisSafe, this.sourceWallet);
|
241
269
|
await super.start();
|
@@ -17,6 +17,7 @@ const gnosis_1 = require("@/gnosis");
|
|
17
17
|
const net_1 = require("@/net");
|
18
18
|
const waait_1 = __importDefault(require("waait"));
|
19
19
|
const errors_1 = require("@/errors");
|
20
|
+
const providers_1 = require("@/providers");
|
20
21
|
class ProcessValidateEvents extends BaseTask_1.BaseTask {
|
21
22
|
constructor({ chainId }) {
|
22
23
|
super({
|
@@ -58,7 +59,7 @@ class ProcessValidateEvents extends BaseTask_1.BaseTask {
|
|
58
59
|
transaction.targetStatus = "proccessing";
|
59
60
|
await transaction.save();
|
60
61
|
const { sourceChainId, targetChainId } = transaction.validateEvent;
|
61
|
-
const targetProvider = new
|
62
|
+
const targetProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
|
62
63
|
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetProvider);
|
63
64
|
const targetGnosisContract = (0, utils_1.getContract)(constants_1.addresses[targetChainId].gnosisSafe, abi_1.default.gnosisSafe, targetWallet);
|
64
65
|
const ownersThreshold = await targetGnosisContract.getThreshold();
|
@@ -98,14 +99,18 @@ class ProcessValidateEvents extends BaseTask_1.BaseTask {
|
|
98
99
|
to: constants_1.addresses[transaction.targetChainId].multisend,
|
99
100
|
value: "0",
|
100
101
|
}, targetGnosisContract);
|
101
|
-
const
|
102
|
-
|
103
|
-
|
104
|
-
const ownerPeerIds = net_1.peerPool.activePeers
|
105
|
-
.filter((peer) => owners.includes(peer.publicAddress.toLowerCase()))
|
106
|
-
.map((peer) => peer.id);
|
102
|
+
const ownerPeerIds = await (0, utils_1.getGnosisOwnerPeerIds)({
|
103
|
+
gnosisContract: targetGnosisContract,
|
104
|
+
});
|
107
105
|
console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
|
108
106
|
console.log(ownerPeerIds);
|
107
|
+
const message = (0, utils_1.generateGnosisSignatureMessage)({
|
108
|
+
to: constants_1.addresses[data.chainId].multisend,
|
109
|
+
data,
|
110
|
+
chainId: this.chainId,
|
111
|
+
safeTxGas: gnosisTx.safeTxGas,
|
112
|
+
nonce: gnosisTx.safeNonce,
|
113
|
+
});
|
109
114
|
const signatures = await net_1.protocol.requestSignatures({
|
110
115
|
type: "target",
|
111
116
|
transactionHash: transaction.transactionHash,
|
@@ -113,7 +118,21 @@ class ProcessValidateEvents extends BaseTask_1.BaseTask {
|
|
113
118
|
safeNonce: gnosisTx.nonce,
|
114
119
|
chainId: targetChainId,
|
115
120
|
}, ownerPeerIds);
|
116
|
-
const validSignatures = signatures
|
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: this.chainId,
|
129
|
+
});
|
130
|
+
return (address === null || address === void 0 ? void 0 : address.toLowerCase()) === s.signer.toLowerCase();
|
131
|
+
}
|
132
|
+
catch (error) {
|
133
|
+
return false;
|
134
|
+
}
|
135
|
+
});
|
117
136
|
console.log({
|
118
137
|
signatures,
|
119
138
|
validSignatures,
|
@@ -177,7 +196,7 @@ class ProcessValidateEvents extends BaseTask_1.BaseTask {
|
|
177
196
|
}
|
178
197
|
async start() {
|
179
198
|
this.blockConfirmationsCount = constants_1.blockConfirmations[this.chainId] + 1;
|
180
|
-
this.sourceProvider = new
|
199
|
+
this.sourceProvider = new providers_1.JsonRpcRetryProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
181
200
|
await super.start();
|
182
201
|
}
|
183
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({
|
@@ -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
|
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({
|
@@ -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
|
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({
|
@@ -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
|
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
|
}
|