@instadapp/interop-x 0.0.0-dev.32db40c → 0.0.0-dev.373a918
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 +1 -1
- package/dist/src/abi/index.js +2 -0
- package/dist/src/abi/instList.json +232 -0
- package/dist/src/constants/addresses.js +4 -2
- package/dist/src/db/models/transaction.js +11 -7
- package/dist/src/gnosis/actions/aaveV2/source.js +4 -4
- package/dist/src/gnosis/actions/aaveV2/target.js +78 -0
- package/dist/src/index.js +1 -1
- package/dist/src/tasks/InteropX/ProcessSubmitSubmitEvents.js +1 -2
- package/dist/src/tasks/InteropX/ProcessValidateEvents.js +183 -0
- package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +1 -0
- package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +105 -0
- package/dist/src/tasks/index.js +6 -0
- package/dist/src/typechain/InstList.js +2 -0
- package/dist/src/typechain/factories/InstList__factory.js +249 -0
- package/dist/src/typechain/factories/index.js +3 -1
- package/dist/src/typechain/index.js +3 -1
- package/package.json +1 -1
- package/src/abi/index.ts +2 -0
- package/src/abi/instList.json +232 -0
- package/src/constants/addresses.ts +5 -3
- package/src/db/models/transaction.ts +113 -80
- package/src/gnosis/actions/aaveV2/source.ts +4 -4
- package/src/gnosis/actions/aaveV2/target.ts +130 -2
- package/src/tasks/InteropX/ProcessSubmitSubmitEvents.ts +1 -2
- package/src/tasks/InteropX/ProcessValidateEvents.ts +274 -0
- package/src/tasks/InteropX/SyncLogSubmitEvents.ts +1 -0
- package/src/tasks/InteropX/SyncLogValidateEvents.ts +152 -0
- package/src/tasks/index.ts +8 -0
- package/src/typechain/InstList.ts +402 -0
- package/src/typechain/factories/InstList__factory.ts +253 -0
- package/src/typechain/factories/index.ts +1 -0
- package/src/typechain/index.ts +2 -0
package/dist/package.json
CHANGED
package/dist/src/abi/index.js
CHANGED
@@ -7,9 +7,11 @@ const gnosisSafe_json_1 = __importDefault(require("./gnosisSafe.json"));
|
|
7
7
|
const erc20_json_1 = __importDefault(require("./erc20.json"));
|
8
8
|
const interopX_json_1 = __importDefault(require("./interopX.json"));
|
9
9
|
const connectors_1 = require("./connectors");
|
10
|
+
const instList_json_1 = __importDefault(require("./instList.json"));
|
10
11
|
exports.default = {
|
11
12
|
gnosisSafe: gnosisSafe_json_1.default,
|
12
13
|
erc20: erc20_json_1.default,
|
13
14
|
interopX: interopX_json_1.default,
|
14
15
|
connectors: connectors_1.connectors,
|
16
|
+
instList: instList_json_1.default,
|
15
17
|
};
|
@@ -0,0 +1,232 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"inputs": [
|
4
|
+
{
|
5
|
+
"internalType": "address",
|
6
|
+
"name": "_instaIndex",
|
7
|
+
"type": "address"
|
8
|
+
}
|
9
|
+
],
|
10
|
+
"stateMutability": "nonpayable",
|
11
|
+
"type": "constructor"
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"inputs": [
|
15
|
+
{
|
16
|
+
"internalType": "uint64",
|
17
|
+
"name": "",
|
18
|
+
"type": "uint64"
|
19
|
+
}
|
20
|
+
],
|
21
|
+
"name": "accountAddr",
|
22
|
+
"outputs": [
|
23
|
+
{
|
24
|
+
"internalType": "address",
|
25
|
+
"name": "",
|
26
|
+
"type": "address"
|
27
|
+
}
|
28
|
+
],
|
29
|
+
"stateMutability": "view",
|
30
|
+
"type": "function"
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"inputs": [
|
34
|
+
{
|
35
|
+
"internalType": "address",
|
36
|
+
"name": "",
|
37
|
+
"type": "address"
|
38
|
+
}
|
39
|
+
],
|
40
|
+
"name": "accountID",
|
41
|
+
"outputs": [
|
42
|
+
{
|
43
|
+
"internalType": "uint64",
|
44
|
+
"name": "",
|
45
|
+
"type": "uint64"
|
46
|
+
}
|
47
|
+
],
|
48
|
+
"stateMutability": "view",
|
49
|
+
"type": "function"
|
50
|
+
},
|
51
|
+
{
|
52
|
+
"inputs": [
|
53
|
+
{
|
54
|
+
"internalType": "uint64",
|
55
|
+
"name": "",
|
56
|
+
"type": "uint64"
|
57
|
+
}
|
58
|
+
],
|
59
|
+
"name": "accountLink",
|
60
|
+
"outputs": [
|
61
|
+
{
|
62
|
+
"internalType": "address",
|
63
|
+
"name": "first",
|
64
|
+
"type": "address"
|
65
|
+
},
|
66
|
+
{
|
67
|
+
"internalType": "address",
|
68
|
+
"name": "last",
|
69
|
+
"type": "address"
|
70
|
+
},
|
71
|
+
{
|
72
|
+
"internalType": "uint64",
|
73
|
+
"name": "count",
|
74
|
+
"type": "uint64"
|
75
|
+
}
|
76
|
+
],
|
77
|
+
"stateMutability": "view",
|
78
|
+
"type": "function"
|
79
|
+
},
|
80
|
+
{
|
81
|
+
"inputs": [
|
82
|
+
{
|
83
|
+
"internalType": "uint64",
|
84
|
+
"name": "",
|
85
|
+
"type": "uint64"
|
86
|
+
},
|
87
|
+
{
|
88
|
+
"internalType": "address",
|
89
|
+
"name": "",
|
90
|
+
"type": "address"
|
91
|
+
}
|
92
|
+
],
|
93
|
+
"name": "accountList",
|
94
|
+
"outputs": [
|
95
|
+
{
|
96
|
+
"internalType": "address",
|
97
|
+
"name": "prev",
|
98
|
+
"type": "address"
|
99
|
+
},
|
100
|
+
{
|
101
|
+
"internalType": "address",
|
102
|
+
"name": "next",
|
103
|
+
"type": "address"
|
104
|
+
}
|
105
|
+
],
|
106
|
+
"stateMutability": "view",
|
107
|
+
"type": "function"
|
108
|
+
},
|
109
|
+
{
|
110
|
+
"inputs": [],
|
111
|
+
"name": "accounts",
|
112
|
+
"outputs": [
|
113
|
+
{
|
114
|
+
"internalType": "uint64",
|
115
|
+
"name": "",
|
116
|
+
"type": "uint64"
|
117
|
+
}
|
118
|
+
],
|
119
|
+
"stateMutability": "view",
|
120
|
+
"type": "function"
|
121
|
+
},
|
122
|
+
{
|
123
|
+
"inputs": [
|
124
|
+
{
|
125
|
+
"internalType": "address",
|
126
|
+
"name": "_owner",
|
127
|
+
"type": "address"
|
128
|
+
}
|
129
|
+
],
|
130
|
+
"name": "addAuth",
|
131
|
+
"outputs": [],
|
132
|
+
"stateMutability": "nonpayable",
|
133
|
+
"type": "function"
|
134
|
+
},
|
135
|
+
{
|
136
|
+
"inputs": [
|
137
|
+
{
|
138
|
+
"internalType": "address",
|
139
|
+
"name": "_account",
|
140
|
+
"type": "address"
|
141
|
+
}
|
142
|
+
],
|
143
|
+
"name": "init",
|
144
|
+
"outputs": [],
|
145
|
+
"stateMutability": "nonpayable",
|
146
|
+
"type": "function"
|
147
|
+
},
|
148
|
+
{
|
149
|
+
"inputs": [],
|
150
|
+
"name": "instaIndex",
|
151
|
+
"outputs": [
|
152
|
+
{
|
153
|
+
"internalType": "address",
|
154
|
+
"name": "",
|
155
|
+
"type": "address"
|
156
|
+
}
|
157
|
+
],
|
158
|
+
"stateMutability": "view",
|
159
|
+
"type": "function"
|
160
|
+
},
|
161
|
+
{
|
162
|
+
"inputs": [
|
163
|
+
{
|
164
|
+
"internalType": "address",
|
165
|
+
"name": "_owner",
|
166
|
+
"type": "address"
|
167
|
+
}
|
168
|
+
],
|
169
|
+
"name": "removeAuth",
|
170
|
+
"outputs": [],
|
171
|
+
"stateMutability": "nonpayable",
|
172
|
+
"type": "function"
|
173
|
+
},
|
174
|
+
{
|
175
|
+
"inputs": [
|
176
|
+
{
|
177
|
+
"internalType": "address",
|
178
|
+
"name": "",
|
179
|
+
"type": "address"
|
180
|
+
}
|
181
|
+
],
|
182
|
+
"name": "userLink",
|
183
|
+
"outputs": [
|
184
|
+
{
|
185
|
+
"internalType": "uint64",
|
186
|
+
"name": "first",
|
187
|
+
"type": "uint64"
|
188
|
+
},
|
189
|
+
{
|
190
|
+
"internalType": "uint64",
|
191
|
+
"name": "last",
|
192
|
+
"type": "uint64"
|
193
|
+
},
|
194
|
+
{
|
195
|
+
"internalType": "uint64",
|
196
|
+
"name": "count",
|
197
|
+
"type": "uint64"
|
198
|
+
}
|
199
|
+
],
|
200
|
+
"stateMutability": "view",
|
201
|
+
"type": "function"
|
202
|
+
},
|
203
|
+
{
|
204
|
+
"inputs": [
|
205
|
+
{
|
206
|
+
"internalType": "address",
|
207
|
+
"name": "",
|
208
|
+
"type": "address"
|
209
|
+
},
|
210
|
+
{
|
211
|
+
"internalType": "uint64",
|
212
|
+
"name": "",
|
213
|
+
"type": "uint64"
|
214
|
+
}
|
215
|
+
],
|
216
|
+
"name": "userList",
|
217
|
+
"outputs": [
|
218
|
+
{
|
219
|
+
"internalType": "uint64",
|
220
|
+
"name": "prev",
|
221
|
+
"type": "uint64"
|
222
|
+
},
|
223
|
+
{
|
224
|
+
"internalType": "uint64",
|
225
|
+
"name": "next",
|
226
|
+
"type": "uint64"
|
227
|
+
}
|
228
|
+
],
|
229
|
+
"stateMutability": "view",
|
230
|
+
"type": "function"
|
231
|
+
}
|
232
|
+
]
|
@@ -7,11 +7,13 @@ exports.addresses = {
|
|
7
7
|
multisend: '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761',
|
8
8
|
interopX: '0xDB6083df37C5F224a3dF84A4B5f9fB60b6c8670a',
|
9
9
|
dsaAddress: '0x9Fbd453a8e7a158510fBae5D9935958507cf4b19',
|
10
|
+
instList: "0x839c2D3aDe63DF5b0b8F3E57D5e145057Ab41556",
|
10
11
|
},
|
11
12
|
43114: {
|
12
13
|
gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
|
13
14
|
multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
|
14
|
-
interopX: '
|
15
|
-
dsaAddress: '
|
15
|
+
interopX: '0xA82A87096709E3D8648c9d9a22f31133bC4B6d32',
|
16
|
+
dsaAddress: '0x053949Af585bDF29A7bdFB97568F953770028D2b',
|
17
|
+
instList: "0x9926955e0Dd681Dc303370C52f4Ad0a4dd061687",
|
16
18
|
}
|
17
19
|
};
|
@@ -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" });
|
@@ -28,7 +28,7 @@ async function default_1(transaction) {
|
|
28
28
|
args: [withdraw.sourceToken, withdraw.amount, "2", "0", "0"],
|
29
29
|
};
|
30
30
|
sourceSpells.push({
|
31
|
-
connector: spellData.
|
31
|
+
connector: spellData.connector,
|
32
32
|
data: (0, utils_1.encodeConnectorMethod)(spellData),
|
33
33
|
});
|
34
34
|
let spellDataBasicWithdraw = {
|
@@ -37,7 +37,7 @@ async function default_1(transaction) {
|
|
37
37
|
args: [withdraw.sourceToken, withdraw.amount, sourceUserAddress, "0", "0"],
|
38
38
|
};
|
39
39
|
commonSpells.push({
|
40
|
-
connector: spellDataBasicWithdraw.
|
40
|
+
connector: spellDataBasicWithdraw.connector,
|
41
41
|
data: (0, utils_1.encodeConnectorMethod)(spellDataBasicWithdraw),
|
42
42
|
});
|
43
43
|
}
|
@@ -48,7 +48,7 @@ async function default_1(transaction) {
|
|
48
48
|
args: [supply.sourceToken, supply.amount, "0", "0"],
|
49
49
|
};
|
50
50
|
sourceSpells.push({
|
51
|
-
connector: spellDataWithdraw.
|
51
|
+
connector: spellDataWithdraw.connector,
|
52
52
|
data: (0, utils_1.encodeConnectorMethod)(spellDataWithdraw),
|
53
53
|
});
|
54
54
|
let spellDataBasicWithdraw = {
|
@@ -57,7 +57,7 @@ async function default_1(transaction) {
|
|
57
57
|
args: [supply.sourceToken, supply.amount, dsaAddress, "0", "0"],
|
58
58
|
};
|
59
59
|
sourceSpells.push({
|
60
|
-
connector: spellDataBasicWithdraw.
|
60
|
+
connector: spellDataBasicWithdraw.connector,
|
61
61
|
data: (0, utils_1.encodeConnectorMethod)(spellDataBasicWithdraw),
|
62
62
|
});
|
63
63
|
}
|
@@ -1,8 +1,86 @@
|
|
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 targetInstListContract = (0, utils_1.getContract)(constants_1.addresses[targetChainId].instList, abi_1.default.instList, targetChainProvider);
|
19
|
+
const targetDsaAddress = await targetInstListContract.accountAddr(targetDsaId);
|
20
|
+
const dsaAddress = constants_1.addresses[targetChainId].dsaAddress;
|
21
|
+
const interopAddress = constants_1.addresses[targetChainId].interopX;
|
22
|
+
const contract = (0, utils_1.getContract)(interopAddress, abi_1.default.interopX, targetWallet);
|
23
|
+
const targetSpells = [];
|
24
|
+
const commonSpells = [];
|
25
|
+
for (const supplyToken of position.supply) {
|
26
|
+
let spellData = {
|
27
|
+
connector: "AAVE-V2-A",
|
28
|
+
method: "deposit",
|
29
|
+
args: [supplyToken.targetToken, supplyToken.amount, "0", "0"],
|
30
|
+
};
|
31
|
+
targetSpells.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: [supplyToken.targetToken, supplyToken.amount, targetDsaAddress, "0", "0"],
|
39
|
+
};
|
40
|
+
commonSpells.push({
|
41
|
+
connector: spellDataBasicWithdraw.connector,
|
42
|
+
data: (0, utils_1.encodeConnectorMethod)(spellDataBasicWithdraw),
|
43
|
+
});
|
44
|
+
}
|
45
|
+
for (const withdrawToken of position.withdraw) {
|
46
|
+
let spellData = {
|
47
|
+
connector: "AAVE-V2-A",
|
48
|
+
method: "borrow",
|
49
|
+
args: [
|
50
|
+
withdrawToken.targetToken,
|
51
|
+
withdrawToken.amount,
|
52
|
+
"2",
|
53
|
+
"0",
|
54
|
+
"0",
|
55
|
+
],
|
56
|
+
};
|
57
|
+
targetSpells.push({
|
58
|
+
connector: spellData.connector,
|
59
|
+
data: (0, utils_1.encodeConnectorMethod)(spellData),
|
60
|
+
});
|
61
|
+
let spellData2 = {
|
62
|
+
connector: "BASIC-A",
|
63
|
+
method: "withdraw",
|
64
|
+
args: [
|
65
|
+
withdrawToken.targetToken,
|
66
|
+
withdrawToken.amount,
|
67
|
+
dsaAddress,
|
68
|
+
"0",
|
69
|
+
"0",
|
70
|
+
],
|
71
|
+
};
|
72
|
+
targetSpells.push({
|
73
|
+
connector: spellData.connector,
|
74
|
+
data: (0, utils_1.encodeConnectorMethod)(spellData2),
|
75
|
+
});
|
76
|
+
}
|
77
|
+
const { data } = await contract.populateTransaction.targetAction(sourceSpells, targetSpells, commonSpells, position, actionId, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata);
|
78
|
+
transactions.push({
|
79
|
+
to: interopAddress,
|
80
|
+
data: data,
|
81
|
+
value: "0",
|
82
|
+
operation: ethers_multisend_1.OperationType.Call,
|
83
|
+
});
|
6
84
|
return { transactions, logs };
|
7
85
|
}
|
8
86
|
exports.default = default_1;
|
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 = '373a918';
|
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})`);
|
@@ -136,7 +136,7 @@ class ProcessSubmitSubmitEvents extends BaseTask_1.BaseTask {
|
|
136
136
|
from: this.sourceWallet.address,
|
137
137
|
to: this.sourceGnosisContract.address,
|
138
138
|
gasPrice: gasPrice.mul(120).div(100),
|
139
|
-
gasLimit:
|
139
|
+
gasLimit: 5000000,
|
140
140
|
data: txData,
|
141
141
|
});
|
142
142
|
console.log(txSent);
|
@@ -163,7 +163,6 @@ class ProcessSubmitSubmitEvents extends BaseTask_1.BaseTask {
|
|
163
163
|
if (txSent.blockNumber)
|
164
164
|
transaction.sourceBlockNumber = txSent.blockNumber;
|
165
165
|
transaction.sourceTransactionHash = txSent.hash;
|
166
|
-
transaction.sourceTransactionHash = txSent.hash;
|
167
166
|
transaction.status = "failed";
|
168
167
|
await transaction.save();
|
169
168
|
}
|
@@ -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;
|
@@ -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) => ({
|