@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
@@ -0,0 +1,105 @@
|
|
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 sequelize_1 = require("sequelize");
|
15
|
+
class SyncLogValidateEvents extends BaseTask_1.BaseTask {
|
16
|
+
constructor({ chainId }) {
|
17
|
+
super({
|
18
|
+
logger: new logger_1.default("InteropX::SyncLogValidateEvents"),
|
19
|
+
});
|
20
|
+
this.chainId = chainId;
|
21
|
+
}
|
22
|
+
async pollHandler() {
|
23
|
+
const currentBlock = await this.provider.getBlockNumber();
|
24
|
+
const events = await this.contract.queryFilter(this.contract.filters.LogValidate(), currentBlock - 2000, currentBlock);
|
25
|
+
let processedEvents = 0;
|
26
|
+
for (const event of events) {
|
27
|
+
try {
|
28
|
+
if (!event.args) {
|
29
|
+
continue;
|
30
|
+
}
|
31
|
+
const { sourceSpells, position, actionId, actionIdHash, sourceSender, sourceDsaId, targetDsaId, sourceChainId, targetChainId, vnonce, metadata, } = event.args;
|
32
|
+
const uniqueIdentifier = {
|
33
|
+
actionId,
|
34
|
+
vnonce: vnonce.toString(),
|
35
|
+
sourceSender: sourceSender.toString(),
|
36
|
+
sourceChainId: sourceChainId.toNumber(),
|
37
|
+
targetChainId: targetChainId.toNumber(),
|
38
|
+
sourceDsaId: sourceDsaId.toString(),
|
39
|
+
targetDsaId: targetDsaId.toString(),
|
40
|
+
};
|
41
|
+
let transactionHash = (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier);
|
42
|
+
const transaction = await db_1.Transaction.findOne({
|
43
|
+
where: {
|
44
|
+
transactionHash,
|
45
|
+
validateEvent: { [sequelize_1.Op.eq]: null },
|
46
|
+
},
|
47
|
+
});
|
48
|
+
if (!transaction) {
|
49
|
+
continue;
|
50
|
+
}
|
51
|
+
if (transaction.sourceStatus != "success") {
|
52
|
+
transaction.sourceStatus = "success";
|
53
|
+
}
|
54
|
+
if (!transaction.sourceCreatedAt) {
|
55
|
+
transaction.sourceCreatedAt = new Date();
|
56
|
+
}
|
57
|
+
transaction.sourceTransactionHash = event.transactionHash;
|
58
|
+
transaction.sourceBlockNumber = event.blockNumber;
|
59
|
+
transaction.sourceLogs = [];
|
60
|
+
(transaction.validateEvent = {
|
61
|
+
actionId,
|
62
|
+
actionIdHashHash: actionIdHash,
|
63
|
+
actionIdHash,
|
64
|
+
vnonce: vnonce.toString(),
|
65
|
+
sourceSpells: sourceSpells.map(({ connector, data }) => ({
|
66
|
+
connector,
|
67
|
+
data,
|
68
|
+
})),
|
69
|
+
position: {
|
70
|
+
withdraw: position.withdraw.map((v) => ({
|
71
|
+
sourceToken: v.sourceToken,
|
72
|
+
targetToken: v.targetToken,
|
73
|
+
amount: v.amount.toString(),
|
74
|
+
})),
|
75
|
+
supply: position.supply.map((v) => ({
|
76
|
+
sourceToken: v.sourceToken,
|
77
|
+
targetToken: v.targetToken,
|
78
|
+
amount: v.amount.toString(),
|
79
|
+
})),
|
80
|
+
},
|
81
|
+
sourceChainId: sourceChainId.toNumber(),
|
82
|
+
targetChainId: targetChainId.toNumber(),
|
83
|
+
sourceSender,
|
84
|
+
sourceDsaId: sourceDsaId.toString(),
|
85
|
+
targetDsaId: targetDsaId.toString(),
|
86
|
+
metadata,
|
87
|
+
}),
|
88
|
+
await transaction.save();
|
89
|
+
this.logger.info(`New InteropX tranaction: ${transactionHash} `);
|
90
|
+
}
|
91
|
+
catch (error) {
|
92
|
+
this.logger.error(error);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
if (processedEvents > 0)
|
96
|
+
this.logger.info(`${processedEvents} events processed`);
|
97
|
+
}
|
98
|
+
async start() {
|
99
|
+
this.contractAddress = constants_1.addresses[this.chainId].interopX;
|
100
|
+
this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
|
101
|
+
this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopX, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
|
102
|
+
await super.start();
|
103
|
+
}
|
104
|
+
}
|
105
|
+
exports.default = SyncLogValidateEvents;
|
package/dist/src/tasks/index.js
CHANGED
@@ -8,6 +8,9 @@ const waait_1 = __importDefault(require("waait"));
|
|
8
8
|
const SyncTransactionStatusTask_1 = __importDefault(require("./Transactions/SyncTransactionStatusTask"));
|
9
9
|
const AutoUpdateTask_1 = __importDefault(require("./AutoUpdateTask"));
|
10
10
|
const SyncLogSubmitEvents_1 = __importDefault(require("./InteropX/SyncLogSubmitEvents"));
|
11
|
+
const ProcessSubmitSubmitEvents_1 = __importDefault(require("./InteropX/ProcessSubmitSubmitEvents"));
|
12
|
+
const SyncLogValidateEvents_1 = __importDefault(require("./InteropX/SyncLogValidateEvents"));
|
13
|
+
const ProcessValidateEvents_1 = __importDefault(require("./InteropX/ProcessValidateEvents"));
|
11
14
|
class Tasks {
|
12
15
|
constructor() {
|
13
16
|
this.tasks = [
|
@@ -16,6 +19,12 @@ class Tasks {
|
|
16
19
|
// InteropX
|
17
20
|
new SyncLogSubmitEvents_1.default({ chainId: 137 }),
|
18
21
|
new SyncLogSubmitEvents_1.default({ chainId: 43114 }),
|
22
|
+
new ProcessSubmitSubmitEvents_1.default({ chainId: 137 }),
|
23
|
+
new ProcessSubmitSubmitEvents_1.default({ chainId: 43114 }),
|
24
|
+
new SyncLogValidateEvents_1.default({ chainId: 137 }),
|
25
|
+
new SyncLogValidateEvents_1.default({ chainId: 43114 }),
|
26
|
+
new ProcessValidateEvents_1.default({ chainId: 137 }),
|
27
|
+
new ProcessValidateEvents_1.default({ chainId: 43114 }),
|
19
28
|
new SyncTransactionStatusTask_1.default(),
|
20
29
|
];
|
21
30
|
}
|
package/dist/src/utils/index.js
CHANGED
@@ -13,6 +13,7 @@ const constants_1 = require("@/constants");
|
|
13
13
|
const ethers_1 = require("ethers");
|
14
14
|
const async_retry_1 = __importDefault(require("async-retry"));
|
15
15
|
const connectors_1 = require("@/abi/connectors");
|
16
|
+
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
16
17
|
exports.http = axios_1.default.create();
|
17
18
|
(0, axios_retry_1.default)(exports.http, { retries: 3, retryDelay: axios_retry_1.default.exponentialDelay });
|
18
19
|
function shortenHash(hash, length = 4) {
|
@@ -208,8 +209,8 @@ const encodeConnectorMethod = (params) => {
|
|
208
209
|
const connectorInterface = getInterface(connectors_1.connectors.versions[2][params.connector], params.method);
|
209
210
|
if (!connectorInterface)
|
210
211
|
throw new Error(`ConnectorInterface '${params.method}' not found`);
|
211
|
-
|
212
|
-
return
|
212
|
+
//@ts-ignore
|
213
|
+
return web3_eth_abi_1.default.encodeFunctionCall(connectorInterface, params.args);
|
213
214
|
};
|
214
215
|
exports.encodeConnectorMethod = encodeConnectorMethod;
|
215
216
|
const getInterface = (abiItems, method) => {
|
package/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": {
|
@@ -8,7 +8,7 @@ export const addresses = {
|
|
8
8
|
43114: {
|
9
9
|
gnosisSafe: '0x31d7a5194Fe60AC209Cf1Ce2d539C9A60662Ed6b',
|
10
10
|
multisend: '0x998739BFdAAdde7C933B942a68053933098f9EDa',
|
11
|
-
interopX: '
|
11
|
+
interopX: '0xA82A87096709E3D8648c9d9a22f31133bC4B6d32',
|
12
12
|
dsaAddress: '0xFcB7d826E32081c4799de2f83b47b49df600dc8c',
|
13
13
|
}
|
14
14
|
} as Record<number, { gnosisSafe: string, multisend: string, interopX: string, dsaAddress: string }>
|
package/src/constants/index.ts
CHANGED
@@ -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
|
+
);
|
@@ -32,6 +32,9 @@ export default async function (transaction: Transaction) {
|
|
32
32
|
config.privateKey,
|
33
33
|
sourceChainProvider
|
34
34
|
);
|
35
|
+
const dsaAddress = addresses[sourceChainId].dsaAddress;
|
36
|
+
const sourceUserAddress =
|
37
|
+
Number(sourceDsaId) == 0 ? sourceSender : dsaAddress;
|
35
38
|
const interopAddress = addresses[sourceChainId].interopX;
|
36
39
|
const contract = getContract<InteropX>(
|
37
40
|
interopAddress,
|
@@ -40,7 +43,7 @@ export default async function (transaction: Transaction) {
|
|
40
43
|
);
|
41
44
|
|
42
45
|
const sourceSpells: any[] = [];
|
43
|
-
const commonSpells = [];
|
46
|
+
const commonSpells: any[] = [];
|
44
47
|
|
45
48
|
for (const withdraw of position.withdraw) {
|
46
49
|
let spellData = {
|
@@ -50,9 +53,20 @@ export default async function (transaction: Transaction) {
|
|
50
53
|
};
|
51
54
|
|
52
55
|
sourceSpells.push({
|
53
|
-
connector: spellData.
|
56
|
+
connector: spellData.connector,
|
54
57
|
data: encodeConnectorMethod(spellData),
|
55
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
|
+
});
|
56
70
|
}
|
57
71
|
|
58
72
|
for (const supply of position.supply) {
|
@@ -63,18 +77,18 @@ export default async function (transaction: Transaction) {
|
|
63
77
|
};
|
64
78
|
|
65
79
|
sourceSpells.push({
|
66
|
-
connector: spellDataWithdraw.
|
80
|
+
connector: spellDataWithdraw.connector,
|
67
81
|
data: encodeConnectorMethod(spellDataWithdraw),
|
68
82
|
});
|
69
83
|
|
70
84
|
let spellDataBasicWithdraw = {
|
71
85
|
connector: "BASIC-A",
|
72
86
|
method: "withdraw",
|
73
|
-
args: [supply.sourceToken, supply.amount,
|
87
|
+
args: [supply.sourceToken, supply.amount, dsaAddress, "0", "0"],
|
74
88
|
};
|
75
89
|
|
76
90
|
sourceSpells.push({
|
77
|
-
connector: spellDataBasicWithdraw.
|
91
|
+
connector: spellDataBasicWithdraw.connector,
|
78
92
|
data: encodeConnectorMethod(spellDataBasicWithdraw),
|
79
93
|
});
|
80
94
|
}
|
@@ -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
|
+
interopAddress,
|
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
|
}
|
@@ -12,6 +12,7 @@ export interface ISignatureRequest {
|
|
12
12
|
transactionHash: string
|
13
13
|
safeTxGas: string
|
14
14
|
safeNonce: string
|
15
|
+
chainId: number
|
15
16
|
}
|
16
17
|
export interface ISignatureResponse {
|
17
18
|
signer: string,
|
@@ -54,9 +55,9 @@ export class SignatureDialProtocol extends BaseDialProtocol<ISignatureRequest, I
|
|
54
55
|
const { data: gnosisData } = await buildGnosisAction(transaction, data.type);
|
55
56
|
|
56
57
|
const signedData = await signGnosisSafeTx({
|
57
|
-
to: addresses[
|
58
|
+
to: addresses[data.chainId].multisend,
|
58
59
|
data: gnosisData,
|
59
|
-
chainId:
|
60
|
+
chainId: data.chainId as ChainId,
|
60
61
|
safeTxGas: data.safeTxGas,
|
61
62
|
nonce: data.safeNonce,
|
62
63
|
}, { signer });
|