@instadapp/interop-x 0.0.0-dev.c279cb8 → 0.0.0-dev.c696e38
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/package.json +1 -1
- package/dist/src/constants/addresses.js +1 -1
- package/dist/src/db/models/transaction.js +11 -7
- package/dist/src/gnosis/actions/aaveV2/source.js +14 -16
- package/dist/src/gnosis/actions/aaveV2/target.js +77 -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/package.json +1 -1
- package/src/constants/addresses.ts +1 -1
- package/src/db/models/transaction.ts +113 -80
- package/src/gnosis/actions/aaveV2/source.ts +16 -18
- package/src/gnosis/actions/aaveV2/target.ts +121 -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
@@ -1,74 +1,100 @@
|
|
1
|
-
import { sequelize } from
|
2
|
-
import {
|
1
|
+
import { sequelize } from "@/db/sequelize";
|
2
|
+
import {
|
3
|
+
CreationOptional,
|
4
|
+
InferAttributes,
|
5
|
+
InferCreationAttributes,
|
6
|
+
Model,
|
7
|
+
DataTypes,
|
8
|
+
} from "sequelize";
|
3
9
|
|
4
10
|
export interface IPositionTokenInfo {
|
5
|
-
|
6
|
-
|
7
|
-
|
11
|
+
amount: string;
|
12
|
+
sourceToken: string;
|
13
|
+
targetToken: string;
|
8
14
|
}
|
9
15
|
|
10
16
|
export interface IPosition {
|
11
|
-
|
12
|
-
|
17
|
+
supply: IPositionTokenInfo[];
|
18
|
+
withdraw: IPositionTokenInfo[];
|
13
19
|
}
|
14
20
|
|
15
|
-
export class Transaction extends Model<
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
21
|
+
export class Transaction extends Model<
|
22
|
+
InferAttributes<Transaction>,
|
23
|
+
InferCreationAttributes<Transaction>
|
24
|
+
> {
|
25
|
+
declare id: CreationOptional<number>;
|
26
|
+
|
27
|
+
declare transactionHash: string;
|
28
|
+
declare vnonce: string;
|
29
|
+
declare actionId: string;
|
30
|
+
declare sourceSender: string;
|
31
|
+
|
32
|
+
declare submitChainId: number;
|
33
|
+
declare submitTransactionHash: string;
|
34
|
+
declare submitBlockNumber: number;
|
35
|
+
declare submitCreatedAt: Date;
|
36
|
+
|
37
|
+
declare sourceChainId: number;
|
38
|
+
declare sourceDsaId: string;
|
39
|
+
declare sourceTransactionHash: CreationOptional<string>;
|
40
|
+
declare sourceBlockNumber: CreationOptional<number>;
|
41
|
+
declare sourceStatus: CreationOptional<string>;
|
42
|
+
declare sourceErrors: CreationOptional<string[]>;
|
43
|
+
declare sourceLogs: CreationOptional<any[]>;
|
44
|
+
declare sourceCreatedAt: CreationOptional<Date>;
|
45
|
+
declare sourceDelayUntil: CreationOptional<Date>;
|
46
|
+
|
47
|
+
declare targetChainId: number;
|
48
|
+
declare targetDsaId: string;
|
49
|
+
declare targetTransactionHash: CreationOptional<string>;
|
50
|
+
declare targetBlockNumber: CreationOptional<number>;
|
51
|
+
declare targetStatus: CreationOptional<string>;
|
52
|
+
declare targetErrors: CreationOptional<string[]>;
|
53
|
+
declare targetLogs: CreationOptional<any[]>;
|
54
|
+
declare targetCreatedAt: CreationOptional<Date>;
|
55
|
+
declare targetDelayUntil: CreationOptional<Date>;
|
56
|
+
|
57
|
+
declare submitEvent: {
|
58
|
+
position: IPosition;
|
59
|
+
actionId: string;
|
60
|
+
actionIdHashHash: string;
|
61
|
+
actionIdHash: string;
|
62
|
+
sourceSender: string;
|
63
|
+
sourceDsaId: string;
|
64
|
+
targetDsaId: string;
|
65
|
+
sourceChainId: number;
|
66
|
+
targetChainId: number;
|
67
|
+
vnonce: string;
|
68
|
+
metadata: string;
|
69
|
+
};
|
70
|
+
|
71
|
+
declare validateEvent: CreationOptional<{
|
72
|
+
sourceSpells: Array<{ connector: string; data: string }>;
|
73
|
+
position: IPosition;
|
74
|
+
actionId: string;
|
75
|
+
actionIdHashHash: string;
|
76
|
+
actionIdHash: string;
|
77
|
+
sourceSender: string;
|
78
|
+
sourceDsaId: string;
|
79
|
+
targetDsaId: string;
|
80
|
+
sourceChainId: number;
|
81
|
+
targetChainId: number;
|
82
|
+
vnonce: string;
|
83
|
+
metadata: string;
|
84
|
+
}>;
|
85
|
+
|
86
|
+
declare status: CreationOptional<string>;
|
87
|
+
|
88
|
+
declare createdAt: CreationOptional<Date>;
|
89
|
+
declare updatedAt: CreationOptional<Date>;
|
65
90
|
}
|
66
91
|
|
67
|
-
Transaction.init(
|
92
|
+
Transaction.init(
|
93
|
+
{
|
68
94
|
id: {
|
69
|
-
|
70
|
-
|
71
|
-
|
95
|
+
type: DataTypes.INTEGER,
|
96
|
+
autoIncrement: true,
|
97
|
+
primaryKey: true,
|
72
98
|
},
|
73
99
|
|
74
100
|
transactionHash: DataTypes.STRING,
|
@@ -86,20 +112,20 @@ Transaction.init({
|
|
86
112
|
sourceTransactionHash: DataTypes.STRING,
|
87
113
|
sourceBlockNumber: DataTypes.NUMBER,
|
88
114
|
sourceStatus: {
|
89
|
-
|
90
|
-
|
115
|
+
type: DataTypes.STRING,
|
116
|
+
defaultValue: "pending",
|
91
117
|
},
|
92
118
|
sourceErrors: {
|
93
|
-
|
94
|
-
|
119
|
+
type: DataTypes.JSON,
|
120
|
+
// defaultValue: [],
|
95
121
|
},
|
96
122
|
sourceLogs: {
|
97
|
-
|
98
|
-
|
123
|
+
type: DataTypes.JSON,
|
124
|
+
// defaultValue: [],
|
99
125
|
},
|
100
126
|
sourceCreatedAt: {
|
101
|
-
|
102
|
-
|
127
|
+
type: DataTypes.DATE,
|
128
|
+
defaultValue: Date.now(),
|
103
129
|
},
|
104
130
|
sourceDelayUntil: DataTypes.STRING,
|
105
131
|
|
@@ -108,29 +134,36 @@ Transaction.init({
|
|
108
134
|
targetTransactionHash: DataTypes.STRING,
|
109
135
|
targetBlockNumber: DataTypes.NUMBER,
|
110
136
|
targetStatus: {
|
111
|
-
|
112
|
-
|
137
|
+
type: DataTypes.STRING,
|
138
|
+
defaultValue: "pending",
|
113
139
|
},
|
114
140
|
targetErrors: {
|
115
|
-
|
116
|
-
|
141
|
+
type: DataTypes.JSON,
|
142
|
+
// defaultValue: [],
|
117
143
|
},
|
118
144
|
targetLogs: {
|
119
|
-
|
120
|
-
|
145
|
+
type: DataTypes.JSON,
|
146
|
+
// defaultValue: [],
|
121
147
|
},
|
122
148
|
targetCreatedAt: DataTypes.DATE,
|
123
149
|
targetDelayUntil: DataTypes.DATE,
|
124
150
|
|
125
151
|
submitEvent: {
|
126
|
-
|
127
|
-
|
152
|
+
type: DataTypes.JSON,
|
153
|
+
allowNull: false,
|
154
|
+
},
|
155
|
+
|
156
|
+
validateEvent: {
|
157
|
+
type: DataTypes.JSON,
|
158
|
+
allowNull: true,
|
128
159
|
},
|
129
160
|
|
130
161
|
status: {
|
131
|
-
|
132
|
-
|
162
|
+
type: DataTypes.STRING,
|
163
|
+
defaultValue: "pending",
|
133
164
|
},
|
134
165
|
createdAt: DataTypes.DATE,
|
135
166
|
updatedAt: DataTypes.DATE,
|
136
|
-
},
|
167
|
+
},
|
168
|
+
{ sequelize, tableName: "transactions" }
|
169
|
+
);
|
@@ -53,9 +53,20 @@ export default async function (transaction: Transaction) {
|
|
53
53
|
};
|
54
54
|
|
55
55
|
sourceSpells.push({
|
56
|
-
connector: spellData.
|
56
|
+
connector: spellData.connector,
|
57
57
|
data: encodeConnectorMethod(spellData),
|
58
58
|
});
|
59
|
+
|
60
|
+
let spellDataBasicWithdraw = {
|
61
|
+
connector: "BASIC-A",
|
62
|
+
method: "withdraw",
|
63
|
+
args: [withdraw.sourceToken, withdraw.amount, sourceUserAddress, "0", "0"],
|
64
|
+
};
|
65
|
+
|
66
|
+
commonSpells.push({
|
67
|
+
connector: spellDataBasicWithdraw.connector,
|
68
|
+
data: encodeConnectorMethod(spellDataBasicWithdraw),
|
69
|
+
});
|
59
70
|
}
|
60
71
|
|
61
72
|
for (const supply of position.supply) {
|
@@ -66,35 +77,22 @@ export default async function (transaction: Transaction) {
|
|
66
77
|
};
|
67
78
|
|
68
79
|
sourceSpells.push({
|
69
|
-
connector: spellDataWithdraw.
|
80
|
+
connector: spellDataWithdraw.connector,
|
70
81
|
data: encodeConnectorMethod(spellDataWithdraw),
|
71
82
|
});
|
72
83
|
|
73
84
|
let spellDataBasicWithdraw = {
|
74
85
|
connector: "BASIC-A",
|
75
86
|
method: "withdraw",
|
76
|
-
args: [supply.sourceToken, supply.amount,
|
87
|
+
args: [supply.sourceToken, supply.amount, dsaAddress, "0", "0"],
|
77
88
|
};
|
78
89
|
|
79
|
-
|
80
|
-
connector: spellDataBasicWithdraw.
|
90
|
+
sourceSpells.push({
|
91
|
+
connector: spellDataBasicWithdraw.connector,
|
81
92
|
data: encodeConnectorMethod(spellDataBasicWithdraw),
|
82
93
|
});
|
83
94
|
}
|
84
95
|
|
85
|
-
// for (const withdraw of position.withdraw) {
|
86
|
-
// let spellDataBasicWithdraw = {
|
87
|
-
// connector: "BASIC-A",
|
88
|
-
// method: "withdraw",
|
89
|
-
// args: [withdraw.sourceToken, withdraw.amount, sourceUserAddress, "0", "0"],
|
90
|
-
// };
|
91
|
-
|
92
|
-
// commonSpells.push({
|
93
|
-
// connector: spellDataBasicWithdraw.method,
|
94
|
-
// data: encodeConnectorMethod(spellDataBasicWithdraw),
|
95
|
-
// });
|
96
|
-
// }
|
97
|
-
|
98
96
|
const { data } = await contract.populateTransaction.sourceAction(
|
99
97
|
sourceSpells,
|
100
98
|
commonSpells,
|
@@ -1,6 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import abi from "@/abi";
|
2
|
+
import config from "@/config";
|
3
|
+
import { addresses } from "@/constants";
|
3
4
|
import { Transaction } from "@/db";
|
5
|
+
import { InteropX } from "@/typechain";
|
6
|
+
import { ChainId } from "@/types";
|
7
|
+
import { encodeConnectorMethod, getContract, getRpcProviderUrl } from "@/utils";
|
8
|
+
import { ethers } from "ethers";
|
4
9
|
import { MetaTransaction, OperationType } from "ethers-multisend";
|
5
10
|
|
6
11
|
|
@@ -8,6 +13,120 @@ export default async function (transaction: Transaction) {
|
|
8
13
|
const transactions: MetaTransaction[] = [];
|
9
14
|
const logs: any[] = [];
|
10
15
|
|
16
|
+
const {
|
17
|
+
sourceSpells,
|
18
|
+
position,
|
19
|
+
actionId,
|
20
|
+
sourceSender,
|
21
|
+
sourceDsaId,
|
22
|
+
targetDsaId,
|
23
|
+
sourceChainId,
|
24
|
+
targetChainId,
|
25
|
+
vnonce,
|
26
|
+
metadata,
|
27
|
+
} = transaction.validateEvent;
|
28
|
+
|
29
|
+
const targetChainProvider = new ethers.providers.JsonRpcProvider(
|
30
|
+
getRpcProviderUrl(targetChainId as ChainId)
|
31
|
+
);
|
32
|
+
const targetWallet = new ethers.Wallet(
|
33
|
+
config.privateKey,
|
34
|
+
targetChainProvider
|
35
|
+
);
|
36
|
+
const dsaAddress = addresses[targetChainId].dsaAddress;
|
37
|
+
const sourceUserAddress = Number(sourceDsaId) == 0 ? sourceSender : dsaAddress;
|
38
|
+
const interopAddress = addresses[targetChainId].interopX;
|
39
|
+
const contract = getContract<InteropX>(
|
40
|
+
interopAddress,
|
41
|
+
abi.interopX,
|
42
|
+
targetWallet
|
43
|
+
);
|
44
|
+
|
45
|
+
const targetSpells: any[] = [];
|
46
|
+
const commonSpells: any[] = [];
|
47
|
+
|
48
|
+
for (const supplyToken of position.supply) {
|
49
|
+
let spellData = {
|
50
|
+
connector: "AAVE-V2-A",
|
51
|
+
method: "deposit",
|
52
|
+
args: [supplyToken.targetToken, supplyToken.amount, "0", "0"],
|
53
|
+
};
|
54
|
+
|
55
|
+
targetSpells.push({
|
56
|
+
connector: spellData.connector,
|
57
|
+
data: encodeConnectorMethod(spellData),
|
58
|
+
});
|
59
|
+
|
60
|
+
let spellDataBasicWithdraw = {
|
61
|
+
connector: "BASIC-A",
|
62
|
+
method: "withdraw",
|
63
|
+
args: [supplyToken.targetToken, supplyToken.amount, sourceUserAddress, "0", "0"],
|
64
|
+
};
|
65
|
+
|
66
|
+
commonSpells.push({
|
67
|
+
connector: spellDataBasicWithdraw.connector,
|
68
|
+
data: encodeConnectorMethod(spellDataBasicWithdraw),
|
69
|
+
});
|
70
|
+
}
|
71
|
+
|
72
|
+
for (const withdrawToken of position.withdraw) {
|
73
|
+
|
74
|
+
let spellData = {
|
75
|
+
connector: "AAVE-V2-A",
|
76
|
+
method: "borrow",
|
77
|
+
args: [
|
78
|
+
withdrawToken.targetToken,
|
79
|
+
withdrawToken.amount,
|
80
|
+
"2",
|
81
|
+
"0",
|
82
|
+
"0",
|
83
|
+
],
|
84
|
+
};
|
85
|
+
|
86
|
+
targetSpells.push({
|
87
|
+
connector: spellData.connector,
|
88
|
+
data: encodeConnectorMethod(spellData),
|
89
|
+
});
|
90
|
+
|
91
|
+
let spellData2 = {
|
92
|
+
connector: "BASIC-A",
|
93
|
+
method: "withdraw",
|
94
|
+
args: [
|
95
|
+
withdrawToken.targetToken,
|
96
|
+
withdrawToken.amount,
|
97
|
+
dsaAddress,
|
98
|
+
"0",
|
99
|
+
"0",
|
100
|
+
],
|
101
|
+
};
|
102
|
+
|
103
|
+
targetSpells.push({
|
104
|
+
connector: spellData.connector,
|
105
|
+
data: encodeConnectorMethod(spellData2),
|
106
|
+
});
|
107
|
+
}
|
108
|
+
|
109
|
+
const { data } = await contract.populateTransaction.targetAction(
|
110
|
+
sourceSpells,
|
111
|
+
targetSpells,
|
112
|
+
commonSpells,
|
113
|
+
position,
|
114
|
+
actionId,
|
115
|
+
sourceSender,
|
116
|
+
sourceDsaId,
|
117
|
+
targetDsaId,
|
118
|
+
sourceChainId,
|
119
|
+
targetChainId,
|
120
|
+
vnonce,
|
121
|
+
metadata
|
122
|
+
);
|
123
|
+
|
124
|
+
transactions.push({
|
125
|
+
to: interopAddress,
|
126
|
+
data: data!,
|
127
|
+
value: "0",
|
128
|
+
operation: OperationType.Call,
|
129
|
+
});
|
11
130
|
|
12
131
|
return { transactions, logs }
|
13
132
|
}
|
@@ -207,7 +207,7 @@ class ProcessSubmitSubmitEvents extends BaseTask {
|
|
207
207
|
from: this.sourceWallet.address,
|
208
208
|
to: this.sourceGnosisContract.address,
|
209
209
|
gasPrice: gasPrice.mul(120).div(100),
|
210
|
-
gasLimit: gasLimit.mul(120).div(100),
|
210
|
+
gasLimit: 5_000_000,//gasLimit.mul(120).div(100),
|
211
211
|
data: txData,
|
212
212
|
});
|
213
213
|
|
@@ -237,7 +237,6 @@ class ProcessSubmitSubmitEvents extends BaseTask {
|
|
237
237
|
if (txSent.blockNumber)
|
238
238
|
transaction.sourceBlockNumber = txSent.blockNumber;
|
239
239
|
transaction.sourceTransactionHash = txSent.hash;
|
240
|
-
transaction.sourceTransactionHash = txSent.hash;
|
241
240
|
transaction.status = "failed";
|
242
241
|
await transaction.save();
|
243
242
|
}
|