@instadapp/interop-x 0.0.0-dev.8a9ef54 → 0.0.0-dev.8cb1c22
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 +2 -1
- package/dist/src/constants/addresses.js +1 -1
- package/dist/src/constants/blockConfirmations.js +8 -0
- package/dist/src/constants/index.js +1 -0
- package/dist/src/db/models/transaction.js +11 -7
- package/dist/src/gnosis/actions/aaveV2/source.js +15 -4
- package/dist/src/gnosis/actions/aaveV2/target.js +77 -0
- package/dist/src/gnosis/actions/index.js +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +2 -2
- package/dist/src/tasks/InteropX/ProcessSubmitSubmitEvents.js +179 -0
- package/dist/src/tasks/InteropX/ProcessValidateEvents.js +183 -0
- package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +2 -1
- package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +105 -0
- package/dist/src/tasks/index.js +9 -0
- package/dist/src/utils/index.js +3 -2
- package/package.json +2 -1
- package/src/constants/addresses.ts +1 -1
- package/src/constants/blockConfirmations.ts +5 -0
- package/src/constants/index.ts +1 -0
- package/src/db/models/transaction.ts +113 -80
- package/src/gnosis/actions/aaveV2/source.ts +19 -5
- package/src/gnosis/actions/aaveV2/target.ts +121 -2
- package/src/gnosis/actions/index.ts +1 -1
- package/src/net/protocol/dial/SignatureDialProtocol.ts +3 -2
- package/src/tasks/InteropX/ProcessSubmitSubmitEvents.ts +269 -0
- package/src/tasks/InteropX/ProcessValidateEvents.ts +274 -0
- package/src/tasks/InteropX/SyncLogSubmitEvents.ts +3 -2
- package/src/tasks/InteropX/SyncLogValidateEvents.ts +152 -0
- package/src/tasks/index.ts +12 -0
- package/src/utils/index.ts +3 -3
package/dist/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@instadapp/interop-x",
|
3
|
-
"version": "0.0.0-dev.
|
3
|
+
"version": "0.0.0-dev.8cb1c22",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"engines": {
|
@@ -53,6 +53,7 @@
|
|
53
53
|
"sequelize": "6.18.0",
|
54
54
|
"sqlite3": "^5.0.8",
|
55
55
|
"waait": "^1.0.5",
|
56
|
+
"web3-eth-abi": "^1.7.3",
|
56
57
|
"web3-utils": "^1.7.3"
|
57
58
|
},
|
58
59
|
"bin": {
|
@@ -11,7 +11,7 @@ exports.addresses = {
|
|
11
11
|
43114: {
|
12
12
|
gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
|
13
13
|
multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
|
14
|
-
interopX: '
|
14
|
+
interopX: '0xA82A87096709E3D8648c9d9a22f31133bC4B6d32',
|
15
15
|
dsaAddress: '0xFcB7d826E32081c4799de2f83b47b49df600dc8c',
|
16
16
|
}
|
17
17
|
};
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./addresses"), exports);
|
18
18
|
__exportStar(require("./tokens"), exports);
|
19
|
+
__exportStar(require("./blockConfirmations"), exports);
|
@@ -10,7 +10,7 @@ Transaction.init({
|
|
10
10
|
id: {
|
11
11
|
type: sequelize_2.DataTypes.INTEGER,
|
12
12
|
autoIncrement: true,
|
13
|
-
primaryKey: true
|
13
|
+
primaryKey: true,
|
14
14
|
},
|
15
15
|
transactionHash: sequelize_2.DataTypes.STRING,
|
16
16
|
actionId: sequelize_2.DataTypes.STRING,
|
@@ -26,7 +26,7 @@ Transaction.init({
|
|
26
26
|
sourceBlockNumber: sequelize_2.DataTypes.NUMBER,
|
27
27
|
sourceStatus: {
|
28
28
|
type: sequelize_2.DataTypes.STRING,
|
29
|
-
defaultValue:
|
29
|
+
defaultValue: "pending",
|
30
30
|
},
|
31
31
|
sourceErrors: {
|
32
32
|
type: sequelize_2.DataTypes.JSON,
|
@@ -38,7 +38,7 @@ Transaction.init({
|
|
38
38
|
},
|
39
39
|
sourceCreatedAt: {
|
40
40
|
type: sequelize_2.DataTypes.DATE,
|
41
|
-
defaultValue: Date.now()
|
41
|
+
defaultValue: Date.now(),
|
42
42
|
},
|
43
43
|
sourceDelayUntil: sequelize_2.DataTypes.STRING,
|
44
44
|
targetChainId: sequelize_2.DataTypes.NUMBER,
|
@@ -47,7 +47,7 @@ Transaction.init({
|
|
47
47
|
targetBlockNumber: sequelize_2.DataTypes.NUMBER,
|
48
48
|
targetStatus: {
|
49
49
|
type: sequelize_2.DataTypes.STRING,
|
50
|
-
defaultValue:
|
50
|
+
defaultValue: "pending",
|
51
51
|
},
|
52
52
|
targetErrors: {
|
53
53
|
type: sequelize_2.DataTypes.JSON,
|
@@ -61,12 +61,16 @@ Transaction.init({
|
|
61
61
|
targetDelayUntil: sequelize_2.DataTypes.DATE,
|
62
62
|
submitEvent: {
|
63
63
|
type: sequelize_2.DataTypes.JSON,
|
64
|
-
allowNull: false
|
64
|
+
allowNull: false,
|
65
|
+
},
|
66
|
+
validateEvent: {
|
67
|
+
type: sequelize_2.DataTypes.JSON,
|
68
|
+
allowNull: true,
|
65
69
|
},
|
66
70
|
status: {
|
67
71
|
type: sequelize_2.DataTypes.STRING,
|
68
|
-
defaultValue:
|
72
|
+
defaultValue: "pending",
|
69
73
|
},
|
70
74
|
createdAt: sequelize_2.DataTypes.DATE,
|
71
75
|
updatedAt: sequelize_2.DataTypes.DATE,
|
72
|
-
}, { sequelize: sequelize_1.sequelize, tableName:
|
76
|
+
}, { sequelize: sequelize_1.sequelize, tableName: "transactions" });
|
@@ -15,6 +15,8 @@ async function default_1(transaction) {
|
|
15
15
|
const { position, actionId, actionIdHashHash, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata, } = transaction.submitEvent;
|
16
16
|
const sourceChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(sourceChainId));
|
17
17
|
const sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, sourceChainProvider);
|
18
|
+
const dsaAddress = constants_1.addresses[sourceChainId].dsaAddress;
|
19
|
+
const sourceUserAddress = Number(sourceDsaId) == 0 ? sourceSender : dsaAddress;
|
18
20
|
const interopAddress = constants_1.addresses[sourceChainId].interopX;
|
19
21
|
const contract = (0, utils_1.getContract)(interopAddress, abi_1.default.interopX, sourceWallet);
|
20
22
|
const sourceSpells = [];
|
@@ -26,9 +28,18 @@ async function default_1(transaction) {
|
|
26
28
|
args: [withdraw.sourceToken, withdraw.amount, "2", "0", "0"],
|
27
29
|
};
|
28
30
|
sourceSpells.push({
|
29
|
-
connector: spellData.
|
31
|
+
connector: spellData.connector,
|
30
32
|
data: (0, utils_1.encodeConnectorMethod)(spellData),
|
31
33
|
});
|
34
|
+
let spellDataBasicWithdraw = {
|
35
|
+
connector: "BASIC-A",
|
36
|
+
method: "withdraw",
|
37
|
+
args: [withdraw.sourceToken, withdraw.amount, sourceUserAddress, "0", "0"],
|
38
|
+
};
|
39
|
+
commonSpells.push({
|
40
|
+
connector: spellDataBasicWithdraw.connector,
|
41
|
+
data: (0, utils_1.encodeConnectorMethod)(spellDataBasicWithdraw),
|
42
|
+
});
|
32
43
|
}
|
33
44
|
for (const supply of position.supply) {
|
34
45
|
let spellDataWithdraw = {
|
@@ -37,16 +48,16 @@ async function default_1(transaction) {
|
|
37
48
|
args: [supply.sourceToken, supply.amount, "0", "0"],
|
38
49
|
};
|
39
50
|
sourceSpells.push({
|
40
|
-
connector: spellDataWithdraw.
|
51
|
+
connector: spellDataWithdraw.connector,
|
41
52
|
data: (0, utils_1.encodeConnectorMethod)(spellDataWithdraw),
|
42
53
|
});
|
43
54
|
let spellDataBasicWithdraw = {
|
44
55
|
connector: "BASIC-A",
|
45
56
|
method: "withdraw",
|
46
|
-
args: [supply.sourceToken, supply.amount,
|
57
|
+
args: [supply.sourceToken, supply.amount, dsaAddress, "0", "0"],
|
47
58
|
};
|
48
59
|
sourceSpells.push({
|
49
|
-
connector: spellDataBasicWithdraw.
|
60
|
+
connector: spellDataBasicWithdraw.connector,
|
50
61
|
data: (0, utils_1.encodeConnectorMethod)(spellDataBasicWithdraw),
|
51
62
|
});
|
52
63
|
}
|
@@ -1,8 +1,85 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
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 utils_1 = require("@/utils");
|
10
|
+
const ethers_1 = require("ethers");
|
11
|
+
const ethers_multisend_1 = require("ethers-multisend");
|
3
12
|
async function default_1(transaction) {
|
4
13
|
const transactions = [];
|
5
14
|
const logs = [];
|
15
|
+
const { sourceSpells, position, actionId, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata, } = transaction.validateEvent;
|
16
|
+
const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
|
17
|
+
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
18
|
+
const dsaAddress = constants_1.addresses[targetChainId].dsaAddress;
|
19
|
+
const sourceUserAddress = Number(sourceDsaId) == 0 ? sourceSender : dsaAddress;
|
20
|
+
const interopAddress = constants_1.addresses[targetChainId].interopX;
|
21
|
+
const contract = (0, utils_1.getContract)(interopAddress, abi_1.default.interopX, targetWallet);
|
22
|
+
const targetSpells = [];
|
23
|
+
const commonSpells = [];
|
24
|
+
for (const supplyToken of position.supply) {
|
25
|
+
let spellData = {
|
26
|
+
connector: "AAVE-V2-A",
|
27
|
+
method: "deposit",
|
28
|
+
args: [supplyToken.targetToken, supplyToken.amount, "0", "0"],
|
29
|
+
};
|
30
|
+
targetSpells.push({
|
31
|
+
connector: spellData.connector,
|
32
|
+
data: (0, utils_1.encodeConnectorMethod)(spellData),
|
33
|
+
});
|
34
|
+
let spellDataBasicWithdraw = {
|
35
|
+
connector: "BASIC-A",
|
36
|
+
method: "withdraw",
|
37
|
+
args: [supplyToken.targetToken, supplyToken.amount, sourceUserAddress, "0", "0"],
|
38
|
+
};
|
39
|
+
commonSpells.push({
|
40
|
+
connector: spellDataBasicWithdraw.connector,
|
41
|
+
data: (0, utils_1.encodeConnectorMethod)(spellDataBasicWithdraw),
|
42
|
+
});
|
43
|
+
}
|
44
|
+
for (const withdrawToken of position.withdraw) {
|
45
|
+
let spellData = {
|
46
|
+
connector: "AAVE-V2-A",
|
47
|
+
method: "borrow",
|
48
|
+
args: [
|
49
|
+
withdrawToken.targetToken,
|
50
|
+
withdrawToken.amount,
|
51
|
+
"2",
|
52
|
+
"0",
|
53
|
+
"0",
|
54
|
+
],
|
55
|
+
};
|
56
|
+
targetSpells.push({
|
57
|
+
connector: spellData.connector,
|
58
|
+
data: (0, utils_1.encodeConnectorMethod)(spellData),
|
59
|
+
});
|
60
|
+
let spellData2 = {
|
61
|
+
connector: "BASIC-A",
|
62
|
+
method: "withdraw",
|
63
|
+
args: [
|
64
|
+
withdrawToken.targetToken,
|
65
|
+
withdrawToken.amount,
|
66
|
+
interopAddress,
|
67
|
+
"0",
|
68
|
+
"0",
|
69
|
+
],
|
70
|
+
};
|
71
|
+
targetSpells.push({
|
72
|
+
connector: spellData.connector,
|
73
|
+
data: (0, utils_1.encodeConnectorMethod)(spellData2),
|
74
|
+
});
|
75
|
+
}
|
76
|
+
const { data } = await contract.populateTransaction.targetAction(sourceSpells, targetSpells, commonSpells, position, actionId, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata);
|
77
|
+
transactions.push({
|
78
|
+
to: interopAddress,
|
79
|
+
data: data,
|
80
|
+
value: "0",
|
81
|
+
operation: ethers_multisend_1.OperationType.Call,
|
82
|
+
});
|
6
83
|
return { transactions, logs };
|
7
84
|
}
|
8
85
|
exports.default = default_1;
|
@@ -5,5 +5,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
const aaveV2_1 = __importDefault(require("./aaveV2"));
|
7
7
|
exports.default = {
|
8
|
-
'AAVE-V2:AAVE-V2': aaveV2_1.default,
|
8
|
+
'A:AAVE-V2:AAVE-V2': aaveV2_1.default,
|
9
9
|
};
|
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 = '8cb1c22';
|
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})`);
|
@@ -40,9 +40,9 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
|
|
40
40
|
}
|
41
41
|
const { data: gnosisData } = await (0, gnosis_1.buildGnosisAction)(transaction, data.type);
|
42
42
|
const signedData = await (0, utils_1.signGnosisSafeTx)({
|
43
|
-
to: constants_1.addresses[
|
43
|
+
to: constants_1.addresses[data.chainId].multisend,
|
44
44
|
data: gnosisData,
|
45
|
-
chainId:
|
45
|
+
chainId: data.chainId,
|
46
46
|
safeTxGas: data.safeTxGas,
|
47
47
|
nonce: data.safeNonce,
|
48
48
|
}, { signer });
|
@@ -0,0 +1,179 @@
|
|
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
|
+
class ProcessSubmitSubmitEvents extends BaseTask_1.BaseTask {
|
20
|
+
constructor({ chainId }) {
|
21
|
+
super({
|
22
|
+
logger: new logger_1.default("InteropX::ProcessSubmitSubmitEvents"),
|
23
|
+
});
|
24
|
+
this.leadNodeOnly = true;
|
25
|
+
this.blockConfirmationsCount = 12;
|
26
|
+
this.chainId = chainId;
|
27
|
+
}
|
28
|
+
async pollHandler() {
|
29
|
+
var _a;
|
30
|
+
const currentBlockNumber = await this.sourceProvider.getBlockNumber();
|
31
|
+
const transaction = await db_1.Transaction.findOne({
|
32
|
+
where: {
|
33
|
+
status: "pending",
|
34
|
+
sourceStatus: "pending",
|
35
|
+
sourceChainId: this.chainId,
|
36
|
+
submitBlockNumber: {
|
37
|
+
[sequelize_1.Op.lt]: currentBlockNumber - this.blockConfirmationsCount,
|
38
|
+
},
|
39
|
+
sourceDelayUntil: {
|
40
|
+
[sequelize_1.Op.or]: {
|
41
|
+
[sequelize_1.Op.is]: null,
|
42
|
+
[sequelize_1.Op.lt]: new Date(),
|
43
|
+
},
|
44
|
+
},
|
45
|
+
submitEvent: { $ne: null },
|
46
|
+
createdAt: {
|
47
|
+
[sequelize_1.Op.gt]: (0, moment_1.default)().subtract({ hours: 12 }).toDate(),
|
48
|
+
},
|
49
|
+
},
|
50
|
+
});
|
51
|
+
if (!transaction) {
|
52
|
+
return;
|
53
|
+
}
|
54
|
+
this.logger.debug(`Processing transaction ${transaction.transactionHash}`);
|
55
|
+
transaction.sourceStatus = "proccessing";
|
56
|
+
await transaction.save();
|
57
|
+
const ownersThreshold = await this.sourceGnosisContract.getThreshold();
|
58
|
+
await (0, waait_1.default)(10000);
|
59
|
+
this.logger.debug(`Build gnosis action for ${transaction.transactionHash}`);
|
60
|
+
let data, logs = [];
|
61
|
+
try {
|
62
|
+
({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction, "source"));
|
63
|
+
}
|
64
|
+
catch (error) {
|
65
|
+
if (error instanceof utils_1.LiquidityError) {
|
66
|
+
await transaction.save();
|
67
|
+
transaction.sourceDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
|
68
|
+
transaction.sourceStatus = "pending";
|
69
|
+
await transaction.save();
|
70
|
+
throw error;
|
71
|
+
return;
|
72
|
+
}
|
73
|
+
transaction.sourceStatus = "failed";
|
74
|
+
transaction.sourceErrors = [error.message];
|
75
|
+
transaction.targetStatus = "failed";
|
76
|
+
transaction.status = "failed";
|
77
|
+
await transaction.save();
|
78
|
+
net_1.protocol.sendTransaction(transaction);
|
79
|
+
return;
|
80
|
+
}
|
81
|
+
this.logger.debug(`Generating gnosis tx for ${transaction.transactionHash}`);
|
82
|
+
let gnosisTx = await (0, utils_1.generateGnosisTransaction)({
|
83
|
+
baseGas: "0",
|
84
|
+
data,
|
85
|
+
gasPrice: "0",
|
86
|
+
gasToken: "0x0000000000000000000000000000000000000000",
|
87
|
+
nonce: "0",
|
88
|
+
operation: "1",
|
89
|
+
refundReceiver: "0x0000000000000000000000000000000000000000",
|
90
|
+
safeAddress: this.sourceGnosisContract.address,
|
91
|
+
safeTxGas: "79668",
|
92
|
+
to: constants_1.addresses[transaction.sourceChainId].multisend,
|
93
|
+
value: "0",
|
94
|
+
}, 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}`);
|
102
|
+
console.log(ownerPeerIds);
|
103
|
+
const signatures = await net_1.protocol.requestSignatures({
|
104
|
+
type: "source",
|
105
|
+
transactionHash: transaction.transactionHash,
|
106
|
+
safeTxGas: gnosisTx.safeTxGas,
|
107
|
+
safeNonce: gnosisTx.nonce,
|
108
|
+
chainId: this.chainId,
|
109
|
+
}, ownerPeerIds);
|
110
|
+
const validSignatures = signatures.filter((s) => !!s.data && s.data !== "0x");
|
111
|
+
console.log({
|
112
|
+
signatures,
|
113
|
+
validSignatures,
|
114
|
+
ownersThreshold: ownersThreshold.toString(),
|
115
|
+
});
|
116
|
+
if (validSignatures.length === 0 ||
|
117
|
+
ownersThreshold.gt(validSignatures.length)) {
|
118
|
+
await transaction.save();
|
119
|
+
transaction.sourceDelayUntil = new Date(Date.now() + 30 * 1000);
|
120
|
+
transaction.sourceStatus = "pending";
|
121
|
+
await transaction.save();
|
122
|
+
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}` : ""));
|
124
|
+
}
|
125
|
+
console.log(`Executing transaction for execution ${transaction.transactionHash}`);
|
126
|
+
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));
|
127
|
+
const [gasPrice, gasLimit] = await Promise.all([
|
128
|
+
this.sourceProvider.getGasPrice(),
|
129
|
+
this.sourceProvider.estimateGas({
|
130
|
+
from: this.sourceWallet.address,
|
131
|
+
to: this.sourceGnosisContract.address,
|
132
|
+
data: txData,
|
133
|
+
}),
|
134
|
+
]);
|
135
|
+
const txSent = await this.sourceWallet.sendTransaction({
|
136
|
+
from: this.sourceWallet.address,
|
137
|
+
to: this.sourceGnosisContract.address,
|
138
|
+
gasPrice: gasPrice.mul(120).div(100),
|
139
|
+
gasLimit: 5000000,
|
140
|
+
data: txData,
|
141
|
+
});
|
142
|
+
console.log(txSent);
|
143
|
+
const receipt = await txSent.wait();
|
144
|
+
const parsedLogs = [];
|
145
|
+
receipt.logs.forEach((log) => {
|
146
|
+
try {
|
147
|
+
parsedLogs.push(this.sourceGnosisContract.interface.parseLog(log));
|
148
|
+
}
|
149
|
+
catch (e) { }
|
150
|
+
});
|
151
|
+
if (parsedLogs.find((e) => e.name === "ExecutionSuccess")) {
|
152
|
+
console.log("ExecutionSuccess");
|
153
|
+
transaction.sourceStatus = "success";
|
154
|
+
if (txSent.blockNumber)
|
155
|
+
transaction.sourceBlockNumber = txSent.blockNumber;
|
156
|
+
transaction.sourceTransactionHash = txSent.hash;
|
157
|
+
transaction.sourceLogs = logs;
|
158
|
+
await transaction.save();
|
159
|
+
}
|
160
|
+
else {
|
161
|
+
console.log("ExecutionFailure");
|
162
|
+
transaction.sourceStatus = "failed";
|
163
|
+
if (txSent.blockNumber)
|
164
|
+
transaction.sourceBlockNumber = txSent.blockNumber;
|
165
|
+
transaction.sourceTransactionHash = txSent.hash;
|
166
|
+
transaction.status = "failed";
|
167
|
+
await transaction.save();
|
168
|
+
}
|
169
|
+
net_1.protocol.sendTransaction(transaction);
|
170
|
+
}
|
171
|
+
async start() {
|
172
|
+
this.blockConfirmationsCount = constants_1.blockConfirmations[this.chainId] + 1;
|
173
|
+
this.sourceProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
174
|
+
this.sourceWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, this.sourceProvider);
|
175
|
+
this.sourceGnosisContract = (0, utils_1.getContract)(constants_1.addresses[this.chainId].gnosisSafe, abi_1.default.gnosisSafe, this.sourceWallet);
|
176
|
+
await super.start();
|
177
|
+
}
|
178
|
+
}
|
179
|
+
exports.default = ProcessSubmitSubmitEvents;
|
@@ -0,0 +1,183 @@
|
|
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
|
+
class ProcessValidateEvents extends BaseTask_1.BaseTask {
|
20
|
+
constructor({ chainId }) {
|
21
|
+
super({
|
22
|
+
logger: new logger_1.default("InteropX::ProcessValidateEvents"),
|
23
|
+
});
|
24
|
+
this.leadNodeOnly = true;
|
25
|
+
this.blockConfirmationsCount = 12;
|
26
|
+
this.chainId = chainId;
|
27
|
+
}
|
28
|
+
async pollHandler() {
|
29
|
+
var _a;
|
30
|
+
const currentBlockNumber = await this.sourceProvider.getBlockNumber();
|
31
|
+
const transaction = await db_1.Transaction.findOne({
|
32
|
+
where: {
|
33
|
+
status: "pending",
|
34
|
+
sourceStatus: "success",
|
35
|
+
targetStatus: "pending",
|
36
|
+
sourceChainId: this.chainId,
|
37
|
+
sourceBlockNumber: {
|
38
|
+
[sequelize_1.Op.lt]: currentBlockNumber - this.blockConfirmationsCount,
|
39
|
+
},
|
40
|
+
targetDelayUntil: {
|
41
|
+
[sequelize_1.Op.or]: {
|
42
|
+
[sequelize_1.Op.is]: null,
|
43
|
+
[sequelize_1.Op.lt]: new Date(),
|
44
|
+
},
|
45
|
+
},
|
46
|
+
submitEvent: { $ne: null },
|
47
|
+
validateEvent: { $ne: null },
|
48
|
+
createdAt: {
|
49
|
+
[sequelize_1.Op.gt]: (0, moment_1.default)().subtract({ hours: 12 }).toDate(),
|
50
|
+
},
|
51
|
+
},
|
52
|
+
});
|
53
|
+
if (!transaction) {
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
this.logger.debug(`Processing transaction ${transaction.transactionHash}`);
|
57
|
+
transaction.targetStatus = "proccessing";
|
58
|
+
await transaction.save();
|
59
|
+
const { sourceChainId, targetChainId } = transaction.validateEvent;
|
60
|
+
const targetProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(targetChainId));
|
61
|
+
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetProvider);
|
62
|
+
const targetGnosisContract = (0, utils_1.getContract)(constants_1.addresses[targetChainId].gnosisSafe, abi_1.default.gnosisSafe, targetWallet);
|
63
|
+
const ownersThreshold = await targetGnosisContract.getThreshold();
|
64
|
+
await (0, waait_1.default)(10000);
|
65
|
+
this.logger.debug(`Build gnosis action for ${transaction.transactionHash}`);
|
66
|
+
let data, logs = [];
|
67
|
+
try {
|
68
|
+
({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction, "target"));
|
69
|
+
}
|
70
|
+
catch (error) {
|
71
|
+
if (error instanceof utils_1.LiquidityError) {
|
72
|
+
await transaction.save();
|
73
|
+
transaction.targetDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
|
74
|
+
transaction.targetStatus = "pending";
|
75
|
+
await transaction.save();
|
76
|
+
throw error;
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
transaction.targetStatus = "failed";
|
80
|
+
transaction.targetErrors = [error.message];
|
81
|
+
transaction.status = "failed";
|
82
|
+
await transaction.save();
|
83
|
+
net_1.protocol.sendTransaction(transaction);
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
this.logger.debug(`Generating gnosis tx for ${transaction.transactionHash}`);
|
87
|
+
let gnosisTx = await (0, utils_1.generateGnosisTransaction)({
|
88
|
+
baseGas: "0",
|
89
|
+
data,
|
90
|
+
gasPrice: "0",
|
91
|
+
gasToken: "0x0000000000000000000000000000000000000000",
|
92
|
+
nonce: "0",
|
93
|
+
operation: "1",
|
94
|
+
refundReceiver: "0x0000000000000000000000000000000000000000",
|
95
|
+
safeAddress: targetGnosisContract.address,
|
96
|
+
safeTxGas: "79668",
|
97
|
+
to: constants_1.addresses[transaction.targetChainId].multisend,
|
98
|
+
value: "0",
|
99
|
+
}, 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);
|
106
|
+
console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
|
107
|
+
console.log(ownerPeerIds);
|
108
|
+
const signatures = await net_1.protocol.requestSignatures({
|
109
|
+
type: "target",
|
110
|
+
transactionHash: transaction.transactionHash,
|
111
|
+
safeTxGas: gnosisTx.safeTxGas,
|
112
|
+
safeNonce: gnosisTx.nonce,
|
113
|
+
chainId: targetChainId,
|
114
|
+
}, ownerPeerIds);
|
115
|
+
const validSignatures = signatures.filter((s) => !!s.data && s.data !== "0x");
|
116
|
+
console.log({
|
117
|
+
signatures,
|
118
|
+
validSignatures,
|
119
|
+
ownersThreshold: ownersThreshold.toString(),
|
120
|
+
});
|
121
|
+
if (validSignatures.length === 0 ||
|
122
|
+
ownersThreshold.gt(validSignatures.length)) {
|
123
|
+
await transaction.save();
|
124
|
+
transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
|
125
|
+
transaction.targetStatus = "pending";
|
126
|
+
await transaction.save();
|
127
|
+
const errorMessage = (_a = signatures.find((s) => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
|
128
|
+
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ""));
|
129
|
+
}
|
130
|
+
console.log(`Executing transaction for execution ${transaction.transactionHash}`);
|
131
|
+
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));
|
132
|
+
const [gasPrice, gasLimit] = await Promise.all([
|
133
|
+
targetProvider.getGasPrice(),
|
134
|
+
targetProvider.estimateGas({
|
135
|
+
from: targetWallet.address,
|
136
|
+
to: targetGnosisContract.address,
|
137
|
+
data: txData,
|
138
|
+
}),
|
139
|
+
]);
|
140
|
+
const txSent = await targetWallet.sendTransaction({
|
141
|
+
from: targetWallet.address,
|
142
|
+
to: targetGnosisContract.address,
|
143
|
+
gasPrice: gasPrice.mul(120).div(100),
|
144
|
+
gasLimit: 5000000,
|
145
|
+
data: txData,
|
146
|
+
});
|
147
|
+
console.log(txSent);
|
148
|
+
const receipt = await txSent.wait();
|
149
|
+
const parsedLogs = [];
|
150
|
+
receipt.logs.forEach((log) => {
|
151
|
+
try {
|
152
|
+
parsedLogs.push(targetGnosisContract.interface.parseLog(log));
|
153
|
+
}
|
154
|
+
catch (e) { }
|
155
|
+
});
|
156
|
+
if (parsedLogs.find((e) => e.name === "ExecutionSuccess")) {
|
157
|
+
console.log("ExecutionSuccess");
|
158
|
+
transaction.targetStatus = "success";
|
159
|
+
transaction.status = "success";
|
160
|
+
if (txSent.blockNumber)
|
161
|
+
transaction.targetBlockNumber = txSent.blockNumber;
|
162
|
+
transaction.targetTransactionHash = txSent.hash;
|
163
|
+
transaction.targetLogs = logs;
|
164
|
+
await transaction.save();
|
165
|
+
}
|
166
|
+
else {
|
167
|
+
console.log("ExecutionFailure");
|
168
|
+
transaction.targetStatus = "failed";
|
169
|
+
if (txSent.blockNumber)
|
170
|
+
transaction.targetBlockNumber = txSent.blockNumber;
|
171
|
+
transaction.targetTransactionHash = txSent.hash;
|
172
|
+
transaction.status = "failed";
|
173
|
+
await transaction.save();
|
174
|
+
}
|
175
|
+
net_1.protocol.sendTransaction(transaction);
|
176
|
+
}
|
177
|
+
async start() {
|
178
|
+
this.blockConfirmationsCount = constants_1.blockConfirmations[this.chainId] + 1;
|
179
|
+
this.sourceProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
180
|
+
await super.start();
|
181
|
+
}
|
182
|
+
}
|
183
|
+
exports.default = ProcessValidateEvents;
|
@@ -20,7 +20,7 @@ class SyncLogSubmitEvents extends BaseTask_1.BaseTask {
|
|
20
20
|
}
|
21
21
|
async pollHandler() {
|
22
22
|
const currentBlock = await this.provider.getBlockNumber();
|
23
|
-
const events = await this.contract.queryFilter(this.contract.filters.LogSubmit(),
|
23
|
+
const events = await this.contract.queryFilter(this.contract.filters.LogSubmit(), currentBlock - 2000, currentBlock);
|
24
24
|
let processedEvents = 0;
|
25
25
|
for (const event of events) {
|
26
26
|
try {
|
@@ -47,6 +47,7 @@ class SyncLogSubmitEvents extends BaseTask_1.BaseTask {
|
|
47
47
|
await db_1.Transaction.create(Object.assign(Object.assign({ transactionHash }, uniqueIdentifier), { submitChainId: this.chainId, submitTransactionHash: event.transactionHash, submitBlockNumber: event.blockNumber, submitCreatedAt: new Date(), submitEvent: {
|
48
48
|
actionId,
|
49
49
|
actionIdHashHash,
|
50
|
+
actionIdHash: actionIdHashHash,
|
50
51
|
vnonce: vnonce.toString(),
|
51
52
|
position: {
|
52
53
|
withdraw: position.withdraw.map((v) => ({
|