@instadapp/interop-x 0.0.0-dev.ee3d74b → 0.0.0-dev.ef38dfb
Sign up to get free protection for your applications and to get access to all the features.
- 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 +10 -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 +15 -3
- 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 +10 -1
- 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 +20 -219
- package/dist/src/utils/interop.js +16 -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 +6 -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 +20 -3
- package/src/tasks/InteropX/ProcessValidateEvents.ts +274 -0
- package/src/tasks/InteropX/SyncLogExecuteEvents.ts +162 -0
- package/src/tasks/InteropX/SyncLogSubmitEvents.ts +1 -0
- package/src/tasks/InteropX/SyncLogValidateEvents.ts +152 -0
- package/src/tasks/index.ts +13 -1
- 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 +7 -365
- package/src/utils/interop.ts +28 -0
- package/src/utils/web3.ts +131 -0
@@ -0,0 +1,249 @@
|
|
1
|
+
"use strict";
|
2
|
+
/* Autogenerated file. Do not edit manually. */
|
3
|
+
/* tslint:disable */
|
4
|
+
/* eslint-disable */
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.InstList__factory = void 0;
|
7
|
+
const ethers_1 = require("ethers");
|
8
|
+
const _abi = [
|
9
|
+
{
|
10
|
+
inputs: [
|
11
|
+
{
|
12
|
+
internalType: "address",
|
13
|
+
name: "_instaIndex",
|
14
|
+
type: "address",
|
15
|
+
},
|
16
|
+
],
|
17
|
+
stateMutability: "nonpayable",
|
18
|
+
type: "constructor",
|
19
|
+
},
|
20
|
+
{
|
21
|
+
inputs: [
|
22
|
+
{
|
23
|
+
internalType: "uint64",
|
24
|
+
name: "",
|
25
|
+
type: "uint64",
|
26
|
+
},
|
27
|
+
],
|
28
|
+
name: "accountAddr",
|
29
|
+
outputs: [
|
30
|
+
{
|
31
|
+
internalType: "address",
|
32
|
+
name: "",
|
33
|
+
type: "address",
|
34
|
+
},
|
35
|
+
],
|
36
|
+
stateMutability: "view",
|
37
|
+
type: "function",
|
38
|
+
},
|
39
|
+
{
|
40
|
+
inputs: [
|
41
|
+
{
|
42
|
+
internalType: "address",
|
43
|
+
name: "",
|
44
|
+
type: "address",
|
45
|
+
},
|
46
|
+
],
|
47
|
+
name: "accountID",
|
48
|
+
outputs: [
|
49
|
+
{
|
50
|
+
internalType: "uint64",
|
51
|
+
name: "",
|
52
|
+
type: "uint64",
|
53
|
+
},
|
54
|
+
],
|
55
|
+
stateMutability: "view",
|
56
|
+
type: "function",
|
57
|
+
},
|
58
|
+
{
|
59
|
+
inputs: [
|
60
|
+
{
|
61
|
+
internalType: "uint64",
|
62
|
+
name: "",
|
63
|
+
type: "uint64",
|
64
|
+
},
|
65
|
+
],
|
66
|
+
name: "accountLink",
|
67
|
+
outputs: [
|
68
|
+
{
|
69
|
+
internalType: "address",
|
70
|
+
name: "first",
|
71
|
+
type: "address",
|
72
|
+
},
|
73
|
+
{
|
74
|
+
internalType: "address",
|
75
|
+
name: "last",
|
76
|
+
type: "address",
|
77
|
+
},
|
78
|
+
{
|
79
|
+
internalType: "uint64",
|
80
|
+
name: "count",
|
81
|
+
type: "uint64",
|
82
|
+
},
|
83
|
+
],
|
84
|
+
stateMutability: "view",
|
85
|
+
type: "function",
|
86
|
+
},
|
87
|
+
{
|
88
|
+
inputs: [
|
89
|
+
{
|
90
|
+
internalType: "uint64",
|
91
|
+
name: "",
|
92
|
+
type: "uint64",
|
93
|
+
},
|
94
|
+
{
|
95
|
+
internalType: "address",
|
96
|
+
name: "",
|
97
|
+
type: "address",
|
98
|
+
},
|
99
|
+
],
|
100
|
+
name: "accountList",
|
101
|
+
outputs: [
|
102
|
+
{
|
103
|
+
internalType: "address",
|
104
|
+
name: "prev",
|
105
|
+
type: "address",
|
106
|
+
},
|
107
|
+
{
|
108
|
+
internalType: "address",
|
109
|
+
name: "next",
|
110
|
+
type: "address",
|
111
|
+
},
|
112
|
+
],
|
113
|
+
stateMutability: "view",
|
114
|
+
type: "function",
|
115
|
+
},
|
116
|
+
{
|
117
|
+
inputs: [],
|
118
|
+
name: "accounts",
|
119
|
+
outputs: [
|
120
|
+
{
|
121
|
+
internalType: "uint64",
|
122
|
+
name: "",
|
123
|
+
type: "uint64",
|
124
|
+
},
|
125
|
+
],
|
126
|
+
stateMutability: "view",
|
127
|
+
type: "function",
|
128
|
+
},
|
129
|
+
{
|
130
|
+
inputs: [
|
131
|
+
{
|
132
|
+
internalType: "address",
|
133
|
+
name: "_owner",
|
134
|
+
type: "address",
|
135
|
+
},
|
136
|
+
],
|
137
|
+
name: "addAuth",
|
138
|
+
outputs: [],
|
139
|
+
stateMutability: "nonpayable",
|
140
|
+
type: "function",
|
141
|
+
},
|
142
|
+
{
|
143
|
+
inputs: [
|
144
|
+
{
|
145
|
+
internalType: "address",
|
146
|
+
name: "_account",
|
147
|
+
type: "address",
|
148
|
+
},
|
149
|
+
],
|
150
|
+
name: "init",
|
151
|
+
outputs: [],
|
152
|
+
stateMutability: "nonpayable",
|
153
|
+
type: "function",
|
154
|
+
},
|
155
|
+
{
|
156
|
+
inputs: [],
|
157
|
+
name: "instaIndex",
|
158
|
+
outputs: [
|
159
|
+
{
|
160
|
+
internalType: "address",
|
161
|
+
name: "",
|
162
|
+
type: "address",
|
163
|
+
},
|
164
|
+
],
|
165
|
+
stateMutability: "view",
|
166
|
+
type: "function",
|
167
|
+
},
|
168
|
+
{
|
169
|
+
inputs: [
|
170
|
+
{
|
171
|
+
internalType: "address",
|
172
|
+
name: "_owner",
|
173
|
+
type: "address",
|
174
|
+
},
|
175
|
+
],
|
176
|
+
name: "removeAuth",
|
177
|
+
outputs: [],
|
178
|
+
stateMutability: "nonpayable",
|
179
|
+
type: "function",
|
180
|
+
},
|
181
|
+
{
|
182
|
+
inputs: [
|
183
|
+
{
|
184
|
+
internalType: "address",
|
185
|
+
name: "",
|
186
|
+
type: "address",
|
187
|
+
},
|
188
|
+
],
|
189
|
+
name: "userLink",
|
190
|
+
outputs: [
|
191
|
+
{
|
192
|
+
internalType: "uint64",
|
193
|
+
name: "first",
|
194
|
+
type: "uint64",
|
195
|
+
},
|
196
|
+
{
|
197
|
+
internalType: "uint64",
|
198
|
+
name: "last",
|
199
|
+
type: "uint64",
|
200
|
+
},
|
201
|
+
{
|
202
|
+
internalType: "uint64",
|
203
|
+
name: "count",
|
204
|
+
type: "uint64",
|
205
|
+
},
|
206
|
+
],
|
207
|
+
stateMutability: "view",
|
208
|
+
type: "function",
|
209
|
+
},
|
210
|
+
{
|
211
|
+
inputs: [
|
212
|
+
{
|
213
|
+
internalType: "address",
|
214
|
+
name: "",
|
215
|
+
type: "address",
|
216
|
+
},
|
217
|
+
{
|
218
|
+
internalType: "uint64",
|
219
|
+
name: "",
|
220
|
+
type: "uint64",
|
221
|
+
},
|
222
|
+
],
|
223
|
+
name: "userList",
|
224
|
+
outputs: [
|
225
|
+
{
|
226
|
+
internalType: "uint64",
|
227
|
+
name: "prev",
|
228
|
+
type: "uint64",
|
229
|
+
},
|
230
|
+
{
|
231
|
+
internalType: "uint64",
|
232
|
+
name: "next",
|
233
|
+
type: "uint64",
|
234
|
+
},
|
235
|
+
],
|
236
|
+
stateMutability: "view",
|
237
|
+
type: "function",
|
238
|
+
},
|
239
|
+
];
|
240
|
+
class InstList__factory {
|
241
|
+
static createInterface() {
|
242
|
+
return new ethers_1.utils.Interface(_abi);
|
243
|
+
}
|
244
|
+
static connect(address, signerOrProvider) {
|
245
|
+
return new ethers_1.Contract(address, _abi, signerOrProvider);
|
246
|
+
}
|
247
|
+
}
|
248
|
+
exports.InstList__factory = InstList__factory;
|
249
|
+
InstList__factory.abi = _abi;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.InteropX__factory = exports.GnosisSafe__factory = exports.Erc20__factory = void 0;
|
3
|
+
exports.InteropX__factory = exports.InstList__factory = exports.GnosisSafe__factory = exports.Erc20__factory = void 0;
|
4
4
|
/* Autogenerated file. Do not edit manually. */
|
5
5
|
/* tslint:disable */
|
6
6
|
/* eslint-disable */
|
@@ -8,5 +8,7 @@ var Erc20__factory_1 = require("./Erc20__factory");
|
|
8
8
|
Object.defineProperty(exports, "Erc20__factory", { enumerable: true, get: function () { return Erc20__factory_1.Erc20__factory; } });
|
9
9
|
var GnosisSafe__factory_1 = require("./GnosisSafe__factory");
|
10
10
|
Object.defineProperty(exports, "GnosisSafe__factory", { enumerable: true, get: function () { return GnosisSafe__factory_1.GnosisSafe__factory; } });
|
11
|
+
var InstList__factory_1 = require("./InstList__factory");
|
12
|
+
Object.defineProperty(exports, "InstList__factory", { enumerable: true, get: function () { return InstList__factory_1.InstList__factory; } });
|
11
13
|
var InteropX__factory_1 = require("./InteropX__factory");
|
12
14
|
Object.defineProperty(exports, "InteropX__factory", { enumerable: true, get: function () { return InteropX__factory_1.InteropX__factory; } });
|
@@ -23,11 +23,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
23
|
return result;
|
24
24
|
};
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
exports.InteropX__factory = exports.GnosisSafe__factory = exports.Erc20__factory = exports.factories = void 0;
|
26
|
+
exports.InteropX__factory = exports.InstList__factory = exports.GnosisSafe__factory = exports.Erc20__factory = exports.factories = void 0;
|
27
27
|
exports.factories = __importStar(require("./factories"));
|
28
28
|
var Erc20__factory_1 = require("./factories/Erc20__factory");
|
29
29
|
Object.defineProperty(exports, "Erc20__factory", { enumerable: true, get: function () { return Erc20__factory_1.Erc20__factory; } });
|
30
30
|
var GnosisSafe__factory_1 = require("./factories/GnosisSafe__factory");
|
31
31
|
Object.defineProperty(exports, "GnosisSafe__factory", { enumerable: true, get: function () { return GnosisSafe__factory_1.GnosisSafe__factory; } });
|
32
|
+
var InstList__factory_1 = require("./factories/InstList__factory");
|
33
|
+
Object.defineProperty(exports, "InstList__factory", { enumerable: true, get: function () { return InstList__factory_1.InstList__factory; } });
|
32
34
|
var InteropX__factory_1 = require("./factories/InteropX__factory");
|
33
35
|
Object.defineProperty(exports, "InteropX__factory", { enumerable: true, get: function () { return InteropX__factory_1.InteropX__factory; } });
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.asyncCallWithTimeout = void 0;
|
4
|
+
/**
|
5
|
+
* Call an async function with a maximum time limit (in milliseconds) for the timeout
|
6
|
+
* Resolved promise for async function call, or an error if time limit reached
|
7
|
+
*/
|
8
|
+
const asyncCallWithTimeout = async (asyncPromise, timeout) => {
|
9
|
+
let timeoutHandle;
|
10
|
+
const timeoutPromise = new Promise((_resolve, reject) => {
|
11
|
+
timeoutHandle = setTimeout(() => reject(new Error("Async call timeout limit reached")), timeout);
|
12
|
+
});
|
13
|
+
return Promise.race([asyncPromise, timeoutPromise]).then((result) => {
|
14
|
+
clearTimeout(timeoutHandle);
|
15
|
+
return result;
|
16
|
+
});
|
17
|
+
};
|
18
|
+
exports.asyncCallWithTimeout = asyncCallWithTimeout;
|
@@ -0,0 +1,24 @@
|
|
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
|
+
exports.encodeConnectorMethod = void 0;
|
7
|
+
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
8
|
+
const connectors_1 = require("@/abi/connectors");
|
9
|
+
const encodeConnectorMethod = (params) => {
|
10
|
+
const connectorInterface = getInterface(connectors_1.connectors.versions[2][params.connector], params.method);
|
11
|
+
if (!connectorInterface)
|
12
|
+
throw new Error(`ConnectorInterface '${params.method}' not found`);
|
13
|
+
//@ts-ignore
|
14
|
+
return web3_eth_abi_1.default.encodeFunctionCall(connectorInterface, params.args);
|
15
|
+
};
|
16
|
+
exports.encodeConnectorMethod = encodeConnectorMethod;
|
17
|
+
const getInterface = (abiItems, method) => {
|
18
|
+
const abiItem = abiItems.find((abiItem) => abiItem.name === method);
|
19
|
+
if (!abiItem) {
|
20
|
+
console.error(`${method} is an invalid method.`);
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
return abiItem;
|
24
|
+
};
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.short = exports.shortenHash = void 0;
|
4
|
+
function shortenHash(hash, length = 4) {
|
5
|
+
if (!hash)
|
6
|
+
return;
|
7
|
+
if (hash.length < 12)
|
8
|
+
return hash;
|
9
|
+
const beginningChars = hash.startsWith("0x") ? length + 2 : length;
|
10
|
+
const shortened = hash.substr(0, beginningChars) + "…" + hash.substr(-length);
|
11
|
+
return shortened;
|
12
|
+
}
|
13
|
+
exports.shortenHash = shortenHash;
|
14
|
+
function short(buffer) {
|
15
|
+
return buffer.toString("hex").slice(0, 8) + "...";
|
16
|
+
}
|
17
|
+
exports.short = short;
|
@@ -0,0 +1,62 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.generateGnosisTransaction = exports.signGnosisSafeTx = exports.buildSignatureBytes = void 0;
|
4
|
+
const constants_1 = require("@/constants");
|
5
|
+
const ethers_1 = require("ethers");
|
6
|
+
const buildSignatureBytes = (signatures) => {
|
7
|
+
signatures.sort((left, right) => left.signer.toLowerCase().localeCompare(right.signer.toLowerCase()));
|
8
|
+
let signatureBytes = "0x";
|
9
|
+
for (const sig of signatures) {
|
10
|
+
signatureBytes += sig.data.slice(2);
|
11
|
+
}
|
12
|
+
return signatureBytes;
|
13
|
+
};
|
14
|
+
exports.buildSignatureBytes = buildSignatureBytes;
|
15
|
+
const signGnosisSafeTx = async ({ to, data = null, value = "0", operation = "1", baseGas = "0", gasPrice = "0", gasToken = "0x0000000000000000000000000000000000000000", refundReceiver = "0x0000000000000000000000000000000000000000", safeTxGas = "79668", nonce = "0", chainId = 137, }, { signer }) => {
|
16
|
+
const gnosisSafe = constants_1.addresses[chainId].gnosisSafe;
|
17
|
+
const domain = {
|
18
|
+
verifyingContract: gnosisSafe,
|
19
|
+
chainId,
|
20
|
+
};
|
21
|
+
const types = {
|
22
|
+
SafeTx: [
|
23
|
+
{ type: "address", name: "to" },
|
24
|
+
{ type: "uint256", name: "value" },
|
25
|
+
{ type: "bytes", name: "data" },
|
26
|
+
{ type: "uint8", name: "operation" },
|
27
|
+
{ type: "uint256", name: "safeTxGas" },
|
28
|
+
{ type: "uint256", name: "baseGas" },
|
29
|
+
{ type: "uint256", name: "gasPrice" },
|
30
|
+
{ type: "address", name: "gasToken" },
|
31
|
+
{ type: "address", name: "refundReceiver" },
|
32
|
+
{ type: "uint256", name: "nonce" },
|
33
|
+
],
|
34
|
+
};
|
35
|
+
const message = {
|
36
|
+
baseGas,
|
37
|
+
data,
|
38
|
+
gasPrice,
|
39
|
+
gasToken,
|
40
|
+
nonce: Number(nonce),
|
41
|
+
operation,
|
42
|
+
refundReceiver,
|
43
|
+
safeAddress: gnosisSafe,
|
44
|
+
safeTxGas: String(safeTxGas),
|
45
|
+
to,
|
46
|
+
value,
|
47
|
+
};
|
48
|
+
return await signer._signTypedData(domain, types, message);
|
49
|
+
};
|
50
|
+
exports.signGnosisSafeTx = signGnosisSafeTx;
|
51
|
+
const generateGnosisTransaction = async (transactionData, safeContract) => {
|
52
|
+
console.log(transactionData);
|
53
|
+
let isExecuted = await safeContract.dataHashes(await safeContract.getTransactionHash(transactionData.to, transactionData.value, transactionData.data, transactionData.operation, transactionData.safeTxGas, transactionData.baseGas, transactionData.gasPrice, transactionData.gasToken, transactionData.refundReceiver, transactionData.nonce));
|
54
|
+
while (isExecuted == 1) {
|
55
|
+
transactionData.safeTxGas = ethers_1.ethers.BigNumber.from(String(transactionData.safeTxGas))
|
56
|
+
.add(1)
|
57
|
+
.toString();
|
58
|
+
isExecuted = await safeContract.dataHashes(await safeContract.getTransactionHash(transactionData.to, transactionData.value, transactionData.data, transactionData.operation, transactionData.safeTxGas, transactionData.baseGas, transactionData.gasPrice, transactionData.gasToken, transactionData.refundReceiver, transactionData.nonce));
|
59
|
+
}
|
60
|
+
return transactionData;
|
61
|
+
};
|
62
|
+
exports.generateGnosisTransaction = generateGnosisTransaction;
|
@@ -0,0 +1,10 @@
|
|
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
|
+
exports.http = void 0;
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
8
|
+
const axios_retry_1 = __importDefault(require("axios-retry"));
|
9
|
+
exports.http = axios_1.default.create();
|
10
|
+
(0, axios_retry_1.default)(exports.http, { retries: 3, retryDelay: axios_retry_1.default.exponentialDelay });
|
package/dist/src/utils/index.js
CHANGED
@@ -1,222 +1,23 @@
|
|
1
1
|
"use strict";
|
2
|
-
var
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
/**
|
8
|
-
* @module util
|
9
|
-
*/
|
10
|
-
const axios_1 = __importDefault(require("axios"));
|
11
|
-
const axios_retry_1 = __importDefault(require("axios-retry"));
|
12
|
-
const constants_1 = require("@/constants");
|
13
|
-
const ethers_1 = require("ethers");
|
14
|
-
const async_retry_1 = __importDefault(require("async-retry"));
|
15
|
-
const connectors_1 = require("@/abi/connectors");
|
16
|
-
exports.http = axios_1.default.create();
|
17
|
-
(0, axios_retry_1.default)(exports.http, { retries: 3, retryDelay: axios_retry_1.default.exponentialDelay });
|
18
|
-
function shortenHash(hash, length = 4) {
|
19
|
-
if (!hash)
|
20
|
-
return;
|
21
|
-
if (hash.length < 12)
|
22
|
-
return hash;
|
23
|
-
const beginningChars = hash.startsWith("0x") ? length + 2 : length;
|
24
|
-
const shortened = hash.substr(0, beginningChars) + "…" + hash.substr(-length);
|
25
|
-
return shortened;
|
26
|
-
}
|
27
|
-
exports.shortenHash = shortenHash;
|
28
|
-
function short(buffer) {
|
29
|
-
return buffer.toString("hex").slice(0, 8) + "...";
|
30
|
-
}
|
31
|
-
exports.short = short;
|
32
|
-
const signGnosisSafeTx = async ({ to, data = null, value = "0", operation = "1", baseGas = "0", gasPrice = "0", gasToken = "0x0000000000000000000000000000000000000000", refundReceiver = "0x0000000000000000000000000000000000000000", safeTxGas = "79668", nonce = "0", chainId = 137, }, { signer }) => {
|
33
|
-
const gnosisSafe = constants_1.addresses[chainId].gnosisSafe;
|
34
|
-
const domain = {
|
35
|
-
verifyingContract: gnosisSafe,
|
36
|
-
chainId,
|
37
|
-
};
|
38
|
-
const types = {
|
39
|
-
SafeTx: [
|
40
|
-
{ type: "address", name: "to" },
|
41
|
-
{ type: "uint256", name: "value" },
|
42
|
-
{ type: "bytes", name: "data" },
|
43
|
-
{ type: "uint8", name: "operation" },
|
44
|
-
{ type: "uint256", name: "safeTxGas" },
|
45
|
-
{ type: "uint256", name: "baseGas" },
|
46
|
-
{ type: "uint256", name: "gasPrice" },
|
47
|
-
{ type: "address", name: "gasToken" },
|
48
|
-
{ type: "address", name: "refundReceiver" },
|
49
|
-
{ type: "uint256", name: "nonce" },
|
50
|
-
],
|
51
|
-
};
|
52
|
-
const message = {
|
53
|
-
baseGas,
|
54
|
-
data,
|
55
|
-
gasPrice,
|
56
|
-
gasToken,
|
57
|
-
nonce: Number(nonce),
|
58
|
-
operation,
|
59
|
-
refundReceiver,
|
60
|
-
safeAddress: gnosisSafe,
|
61
|
-
safeTxGas: String(safeTxGas),
|
62
|
-
to,
|
63
|
-
value,
|
64
|
-
};
|
65
|
-
return await signer._signTypedData(domain, types, message);
|
66
|
-
};
|
67
|
-
exports.signGnosisSafeTx = signGnosisSafeTx;
|
68
|
-
const getRpcProviderUrl = (chainId) => {
|
69
|
-
switch (chainId) {
|
70
|
-
case 1:
|
71
|
-
return "https://rpc.ankr.com/eth";
|
72
|
-
case 137:
|
73
|
-
return "https://rpc.ankr.com/polygon";
|
74
|
-
case 43114:
|
75
|
-
return "https://rpc.ankr.com/avalanche";
|
76
|
-
default:
|
77
|
-
throw new Error(`Unknown chainId: ${chainId}`);
|
78
|
-
}
|
79
|
-
};
|
80
|
-
exports.getRpcProviderUrl = getRpcProviderUrl;
|
81
|
-
const buildSignatureBytes = (signatures) => {
|
82
|
-
signatures.sort((left, right) => left.signer.toLowerCase().localeCompare(right.signer.toLowerCase()));
|
83
|
-
let signatureBytes = "0x";
|
84
|
-
for (const sig of signatures) {
|
85
|
-
signatureBytes += sig.data.slice(2);
|
86
|
-
}
|
87
|
-
return signatureBytes;
|
88
|
-
};
|
89
|
-
exports.buildSignatureBytes = buildSignatureBytes;
|
90
|
-
/**
|
91
|
-
* Call an async function with a maximum time limit (in milliseconds) for the timeout
|
92
|
-
* Resolved promise for async function call, or an error if time limit reached
|
93
|
-
*/
|
94
|
-
const asyncCallWithTimeout = async (asyncPromise, timeout) => {
|
95
|
-
let timeoutHandle;
|
96
|
-
const timeoutPromise = new Promise((_resolve, reject) => {
|
97
|
-
timeoutHandle = setTimeout(() => reject(new Error("Async call timeout limit reached")), timeout);
|
98
|
-
});
|
99
|
-
return Promise.race([asyncPromise, timeoutPromise]).then((result) => {
|
100
|
-
clearTimeout(timeoutHandle);
|
101
|
-
return result;
|
102
|
-
});
|
103
|
-
};
|
104
|
-
exports.asyncCallWithTimeout = asyncCallWithTimeout;
|
105
|
-
const generateInteropTransactionHash = (data) => {
|
106
|
-
return ethers_1.ethers.utils.solidityKeccak256(Array.from({ length: 7 }, () => "string"), [
|
107
|
-
String(data.actionId),
|
108
|
-
String(data.vnonce),
|
109
|
-
String(data.sourceSender),
|
110
|
-
String(data.sourceChainId),
|
111
|
-
String(data.sourceDsaId),
|
112
|
-
String(data.targetChainId),
|
113
|
-
String(data.targetDsaId),
|
114
|
-
]);
|
115
|
-
};
|
116
|
-
exports.generateInteropTransactionHash = generateInteropTransactionHash;
|
117
|
-
class ContractError extends Error {
|
118
|
-
}
|
119
|
-
exports.ContractError = ContractError;
|
120
|
-
function getContract(address, contractInterface, signerOrProvider) {
|
121
|
-
if (!ethers_1.ethers.utils.getAddress(address) ||
|
122
|
-
address === ethers_1.ethers.constants.AddressZero) {
|
123
|
-
throw Error(`Invalid 'address' parameter '${address}'.`);
|
124
|
-
}
|
125
|
-
const contract = new ethers_1.ethers.Contract(address, contractInterface, signerOrProvider);
|
126
|
-
// Make sure the contract properties is writable
|
127
|
-
const desc = Object.getOwnPropertyDescriptor(contract, "functions");
|
128
|
-
if (!desc || desc.writable !== true) {
|
129
|
-
return contract;
|
130
|
-
}
|
131
|
-
return new Proxy(contract, {
|
132
|
-
get(target, prop, receiver) {
|
133
|
-
const value = Reflect.get(target, prop, receiver);
|
134
|
-
if (typeof value === "function" &&
|
135
|
-
(contract.functions.hasOwnProperty(prop) ||
|
136
|
-
["queryFilter"].includes(String(prop)))) {
|
137
|
-
let isConstant = false;
|
138
|
-
try {
|
139
|
-
isConstant = contract.interface.getFunction(String(prop)).constant;
|
140
|
-
}
|
141
|
-
catch (error) { }
|
142
|
-
return async (...args) => {
|
143
|
-
try {
|
144
|
-
return await (0, async_retry_1.default)(async () => await value.bind(contract)(...args), { retries: isConstant ? 1 : 3 });
|
145
|
-
}
|
146
|
-
catch (error) {
|
147
|
-
const err = new ContractError(`Error calling "${String(prop)}" on "${address}": ${error.reason || error.message}`);
|
148
|
-
err.method = String(prop);
|
149
|
-
err.address = address;
|
150
|
-
err.args = [...args];
|
151
|
-
throw err;
|
152
|
-
}
|
153
|
-
};
|
154
|
-
}
|
155
|
-
if (typeof value === "object" &&
|
156
|
-
[
|
157
|
-
"populateTransaction",
|
158
|
-
"estimateGas",
|
159
|
-
"functions",
|
160
|
-
"callStatic",
|
161
|
-
].includes(String(prop))) {
|
162
|
-
const parentProp = String(prop);
|
163
|
-
return new Proxy(value, {
|
164
|
-
get(target, prop, receiver) {
|
165
|
-
const value = Reflect.get(target, prop, receiver);
|
166
|
-
if (typeof value === "function") {
|
167
|
-
return async (...args) => {
|
168
|
-
try {
|
169
|
-
return await (0, async_retry_1.default)(async () => await value.bind(contract)(...args), { retries: parentProp === "callStatic" ? 3 : 1 });
|
170
|
-
}
|
171
|
-
catch (error) {
|
172
|
-
const err = new ContractError(`Error calling "${String(prop)}" using "${parentProp}" on "${address}": ${error.reason || error.message}`);
|
173
|
-
err.method = String(prop);
|
174
|
-
err.address = address;
|
175
|
-
err.args = [...args];
|
176
|
-
throw err;
|
177
|
-
}
|
178
|
-
};
|
179
|
-
}
|
180
|
-
},
|
181
|
-
});
|
182
|
-
}
|
183
|
-
return value;
|
184
|
-
},
|
185
|
-
});
|
186
|
-
}
|
187
|
-
exports.getContract = getContract;
|
188
|
-
const generateGnosisTransaction = async (transactionData, safeContract) => {
|
189
|
-
console.log(transactionData);
|
190
|
-
let isExecuted = await safeContract.dataHashes(await safeContract.getTransactionHash(transactionData.to, transactionData.value, transactionData.data, transactionData.operation, transactionData.safeTxGas, transactionData.baseGas, transactionData.gasPrice, transactionData.gasToken, transactionData.refundReceiver, transactionData.nonce));
|
191
|
-
while (isExecuted == 1) {
|
192
|
-
transactionData.safeTxGas = ethers_1.ethers.BigNumber.from(String(transactionData.safeTxGas))
|
193
|
-
.add(1)
|
194
|
-
.toString();
|
195
|
-
isExecuted = await safeContract.dataHashes(await safeContract.getTransactionHash(transactionData.to, transactionData.value, transactionData.data, transactionData.operation, transactionData.safeTxGas, transactionData.baseGas, transactionData.gasPrice, transactionData.gasToken, transactionData.refundReceiver, transactionData.nonce));
|
196
|
-
}
|
197
|
-
return transactionData;
|
198
|
-
};
|
199
|
-
exports.generateGnosisTransaction = generateGnosisTransaction;
|
200
|
-
class LiquidityError extends Error {
|
201
|
-
constructor(message) {
|
202
|
-
super(message || "Not enough liquidity");
|
203
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
204
|
-
}
|
205
|
-
}
|
206
|
-
exports.LiquidityError = LiquidityError;
|
207
|
-
const encodeConnectorMethod = (params) => {
|
208
|
-
const connectorInterface = getInterface(connectors_1.connectors.versions[2][params.connector], params.method);
|
209
|
-
if (!connectorInterface)
|
210
|
-
throw new Error(`ConnectorInterface '${params.method}' not found`);
|
211
|
-
const iface = new ethers_1.ethers.utils.Interface(connectorInterface);
|
212
|
-
return iface.encodeFunctionData(params.method, params.args);
|
213
|
-
};
|
214
|
-
exports.encodeConnectorMethod = encodeConnectorMethod;
|
215
|
-
const getInterface = (abiItems, method) => {
|
216
|
-
const abiItem = abiItems.find((abiItem) => abiItem.name === method);
|
217
|
-
if (!abiItem) {
|
218
|
-
console.error(`${method} is an invalid method.`);
|
219
|
-
return;
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
220
7
|
}
|
221
|
-
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
222
15
|
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./async"), exports);
|
18
|
+
__exportStar(require("./dsa"), exports);
|
19
|
+
__exportStar(require("./formatting"), exports);
|
20
|
+
__exportStar(require("./gnosis"), exports);
|
21
|
+
__exportStar(require("./http"), exports);
|
22
|
+
__exportStar(require("./interop"), exports);
|
23
|
+
__exportStar(require("./web3"), exports);
|
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.generateInteropTransactionHash = void 0;
|
4
|
+
const ethers_1 = require("ethers");
|
5
|
+
const generateInteropTransactionHash = (data) => {
|
6
|
+
return ethers_1.ethers.utils.solidityKeccak256(Array.from({ length: 7 }, () => "string"), [
|
7
|
+
String(data.actionId),
|
8
|
+
String(data.vnonce),
|
9
|
+
String(data.sourceSender),
|
10
|
+
String(data.sourceChainId),
|
11
|
+
String(data.sourceDsaId),
|
12
|
+
String(data.targetChainId),
|
13
|
+
String(data.targetDsaId),
|
14
|
+
]);
|
15
|
+
};
|
16
|
+
exports.generateInteropTransactionHash = generateInteropTransactionHash;
|