@instadapp/interop-x 0.0.0-dev.ee3d74b → 0.0.0-dev.ef7acff
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 +3 -1
- package/dist/src/abi/index.js +2 -0
- package/dist/src/abi/instList.json +232 -0
- package/dist/src/api/index.js +7 -0
- package/dist/src/constants/addresses.js +4 -2
- package/dist/src/db/models/transaction.js +15 -7
- package/dist/src/errors/index.js +17 -0
- package/dist/src/gnosis/actions/aaveV2/source.js +15 -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 → ProcessSubmitEvents.js} +29 -5
- package/dist/src/tasks/InteropX/ProcessValidateEvents.js +184 -0
- package/dist/src/tasks/InteropX/SyncLogExecuteEvents.js +112 -0
- package/dist/src/tasks/InteropX/SyncLogSubmitEvents.js +1 -0
- package/dist/src/tasks/InteropX/SyncLogValidateEvents.js +105 -0
- package/dist/src/tasks/index.js +13 -5
- 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/dist/src/utils/async.js +18 -0
- package/dist/src/utils/dsa.js +24 -0
- package/dist/src/utils/formatting.js +17 -0
- package/dist/src/utils/gnosis.js +62 -0
- package/dist/src/utils/http.js +10 -0
- package/dist/src/utils/index.js +21 -219
- package/dist/src/utils/interop.js +16 -0
- package/dist/src/utils/validate.js +23 -0
- package/dist/src/utils/web3.js +92 -0
- package/package.json +3 -1
- package/src/abi/index.ts +2 -0
- package/src/abi/instList.json +232 -0
- package/src/api/index.ts +8 -0
- package/src/constants/addresses.ts +5 -3
- package/src/db/models/transaction.ts +134 -80
- package/src/errors/index.ts +13 -0
- package/src/gnosis/actions/aaveV2/source.ts +19 -5
- package/src/gnosis/actions/aaveV2/target.ts +130 -2
- package/src/tasks/InteropX/{ProcessSubmitSubmitEvents.ts → ProcessSubmitEvents.ts} +35 -7
- package/src/tasks/InteropX/ProcessValidateEvents.ts +272 -0
- package/src/tasks/InteropX/SyncLogExecuteEvents.ts +160 -0
- package/src/tasks/InteropX/SyncLogSubmitEvents.ts +3 -4
- package/src/tasks/InteropX/SyncLogValidateEvents.ts +150 -0
- package/src/tasks/index.ts +16 -5
- 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/src/utils/async.ts +22 -0
- package/src/utils/dsa.ts +30 -0
- package/src/utils/formatting.ts +15 -0
- package/src/utils/gnosis.ts +123 -0
- package/src/utils/http.ts +6 -0
- package/src/utils/index.ts +8 -365
- package/src/utils/interop.ts +28 -0
- package/src/utils/validate.ts +24 -0
- package/src/utils/web3.ts +131 -0
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.ef7acff",
|
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": {
|
@@ -61,6 +62,7 @@
|
|
61
62
|
},
|
62
63
|
"devDependencies": {
|
63
64
|
"@typechain/ethers-v5": "^10.0.0",
|
65
|
+
"@types/async-retry": "^1.4.4",
|
64
66
|
"@types/bn.js": "^5.1.0",
|
65
67
|
"@types/fs-extra": "^9.0.13",
|
66
68
|
"@types/node": "^17.0.33",
|
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
|
+
]
|
package/dist/src/api/index.js
CHANGED
@@ -25,6 +25,13 @@ const startApiServer = async () => {
|
|
25
25
|
]
|
26
26
|
});
|
27
27
|
});
|
28
|
+
server.get('/transactions/:transaction', async (req) => {
|
29
|
+
return await db_1.Transaction.findOne({
|
30
|
+
where: {
|
31
|
+
transactionHash: req.params.transaction
|
32
|
+
}
|
33
|
+
});
|
34
|
+
});
|
28
35
|
await server.listen(PORT, HOST);
|
29
36
|
logger.log(`RPC Server listening at http://${HOST}:${PORT}`);
|
30
37
|
}
|
@@ -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: '0x995e67a652d2be45a8bff438b3dfac66dfff1c46',
|
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,20 @@ 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,
|
69
|
+
},
|
70
|
+
executeEvent: {
|
71
|
+
type: sequelize_2.DataTypes.JSON,
|
72
|
+
allowNull: true,
|
65
73
|
},
|
66
74
|
status: {
|
67
75
|
type: sequelize_2.DataTypes.STRING,
|
68
|
-
defaultValue:
|
76
|
+
defaultValue: "pending",
|
69
77
|
},
|
70
78
|
createdAt: sequelize_2.DataTypes.DATE,
|
71
79
|
updatedAt: sequelize_2.DataTypes.DATE,
|
72
|
-
}, { sequelize: sequelize_1.sequelize, tableName:
|
80
|
+
}, { sequelize: sequelize_1.sequelize, tableName: "transactions" });
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.InvalidChaindIdError = exports.LiquidityError = void 0;
|
4
|
+
class LiquidityError extends Error {
|
5
|
+
constructor(message) {
|
6
|
+
super(message || "Not enough liquidity");
|
7
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
8
|
+
}
|
9
|
+
}
|
10
|
+
exports.LiquidityError = LiquidityError;
|
11
|
+
class InvalidChaindIdError extends Error {
|
12
|
+
constructor(message) {
|
13
|
+
super(message || "Invalid chain id");
|
14
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
exports.InvalidChaindIdError = InvalidChaindIdError;
|
@@ -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,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 = 'ef7acff';
|
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})`);
|
@@ -16,7 +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
|
-
|
19
|
+
const errors_1 = require("@/errors");
|
20
|
+
class ProcessSubmitEvents extends BaseTask_1.BaseTask {
|
20
21
|
constructor({ chainId }) {
|
21
22
|
super({
|
22
23
|
logger: new logger_1.default("InteropX::ProcessSubmitSubmitEvents"),
|
@@ -51,16 +52,30 @@ class ProcessSubmitSubmitEvents extends BaseTask_1.BaseTask {
|
|
51
52
|
if (!transaction) {
|
52
53
|
return;
|
53
54
|
}
|
55
|
+
this.logger.debug(`Processing transaction ${transaction.transactionHash}`);
|
54
56
|
transaction.sourceStatus = "proccessing";
|
55
57
|
await transaction.save();
|
58
|
+
const { sourceChainId, targetChainId } = transaction;
|
59
|
+
try {
|
60
|
+
(0, utils_1.validateChains)({ sourceChainId, targetChainId });
|
61
|
+
}
|
62
|
+
catch (error) {
|
63
|
+
transaction.sourceErrors = [error.message];
|
64
|
+
transaction.sourceStatus = "failed";
|
65
|
+
transaction.targetStatus = "failed";
|
66
|
+
transaction.status = "failed";
|
67
|
+
await transaction.save();
|
68
|
+
return;
|
69
|
+
}
|
56
70
|
const ownersThreshold = await this.sourceGnosisContract.getThreshold();
|
57
71
|
await (0, waait_1.default)(10000);
|
72
|
+
this.logger.debug(`Build gnosis action for ${transaction.transactionHash}`);
|
58
73
|
let data, logs = [];
|
59
74
|
try {
|
60
75
|
({ data, logs } = await (0, gnosis_1.buildGnosisAction)(transaction, "source"));
|
61
76
|
}
|
62
77
|
catch (error) {
|
63
|
-
if (error instanceof
|
78
|
+
if (error instanceof errors_1.LiquidityError) {
|
64
79
|
await transaction.save();
|
65
80
|
transaction.sourceDelayUntil = new Date(Date.now() + 60 * 5 * 1000);
|
66
81
|
transaction.sourceStatus = "pending";
|
@@ -76,6 +91,7 @@ class ProcessSubmitSubmitEvents extends BaseTask_1.BaseTask {
|
|
76
91
|
net_1.protocol.sendTransaction(transaction);
|
77
92
|
return;
|
78
93
|
}
|
94
|
+
this.logger.debug(`Generating gnosis tx for ${transaction.transactionHash}`);
|
79
95
|
let gnosisTx = await (0, utils_1.generateGnosisTransaction)({
|
80
96
|
baseGas: "0",
|
81
97
|
data,
|
@@ -121,10 +137,19 @@ class ProcessSubmitSubmitEvents extends BaseTask_1.BaseTask {
|
|
121
137
|
}
|
122
138
|
console.log(`Executing transaction for execution ${transaction.transactionHash}`);
|
123
139
|
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));
|
140
|
+
const [gasPrice, gasLimit] = await Promise.all([
|
141
|
+
this.sourceProvider.getGasPrice(),
|
142
|
+
this.sourceProvider.estimateGas({
|
143
|
+
from: this.sourceWallet.address,
|
144
|
+
to: this.sourceGnosisContract.address,
|
145
|
+
data: txData,
|
146
|
+
}),
|
147
|
+
]);
|
124
148
|
const txSent = await this.sourceWallet.sendTransaction({
|
125
149
|
from: this.sourceWallet.address,
|
126
|
-
gasPrice: ethers_1.ethers.BigNumber.from(120 * 10 ** 9),
|
127
150
|
to: this.sourceGnosisContract.address,
|
151
|
+
gasPrice: gasPrice.mul(120).div(100),
|
152
|
+
gasLimit: 5000000,
|
128
153
|
data: txData,
|
129
154
|
});
|
130
155
|
console.log(txSent);
|
@@ -151,7 +176,6 @@ class ProcessSubmitSubmitEvents extends BaseTask_1.BaseTask {
|
|
151
176
|
if (txSent.blockNumber)
|
152
177
|
transaction.sourceBlockNumber = txSent.blockNumber;
|
153
178
|
transaction.sourceTransactionHash = txSent.hash;
|
154
|
-
transaction.sourceTransactionHash = txSent.hash;
|
155
179
|
transaction.status = "failed";
|
156
180
|
await transaction.save();
|
157
181
|
}
|
@@ -165,4 +189,4 @@ class ProcessSubmitSubmitEvents extends BaseTask_1.BaseTask {
|
|
165
189
|
await super.start();
|
166
190
|
}
|
167
191
|
}
|
168
|
-
exports.default =
|
192
|
+
exports.default = ProcessSubmitEvents;
|