@instadapp/interop-x 0.0.0-dev.ef78459 → 0.0.0-dev.f0a6281
Sign up to get free protection for your applications and to get access to all the features.
- package/.env.example +2 -1
- package/bin/interop-x +1 -1
- package/dist/package.json +73 -0
- package/dist/src/abi/erc20.json +350 -0
- package/dist/src/abi/gnosisSafe.json +747 -0
- package/dist/src/abi/index.js +15 -0
- package/dist/src/abi/interopBridgeToken.json +298 -0
- package/dist/src/abi/interopXGateway.json +184 -0
- package/dist/src/api/index.js +33 -0
- package/dist/src/config/index.js +31 -0
- package/dist/src/constants/addresses.js +20 -0
- package/dist/{constants → src/constants}/index.js +2 -0
- package/dist/src/constants/itokens.js +13 -0
- package/dist/src/constants/tokens.js +107 -0
- package/dist/{db → src/db}/index.js +0 -0
- package/dist/{db → src/db}/models/index.js +1 -1
- package/dist/src/db/models/transaction.js +54 -0
- package/dist/{db → src/db}/sequelize.js +2 -1
- package/dist/src/index.js +130 -0
- package/dist/{logger → src/logger}/index.js +0 -0
- package/dist/{net → src/net}/index.js +0 -0
- package/dist/{net → src/net}/peer/index.js +8 -3
- package/dist/{net → src/net}/pool/index.js +32 -9
- package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +0 -0
- package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +20 -12
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +28 -0
- package/dist/{net → src/net}/protocol/index.js +44 -4
- package/dist/src/tasks/AutoUpdateTask.js +70 -0
- package/dist/{tasks → src/tasks}/BaseTask.js +13 -5
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +146 -0
- package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +71 -0
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +161 -0
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +74 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +53 -0
- package/dist/src/tasks/index.js +44 -0
- package/dist/src/typechain/Erc20.js +2 -0
- package/dist/src/typechain/GnosisSafe.js +2 -0
- package/dist/src/typechain/InteropBridgeToken.js +2 -0
- package/dist/src/typechain/InteropXGateway.js +2 -0
- package/dist/src/typechain/common.js +2 -0
- package/dist/src/typechain/factories/Erc20__factory.js +367 -0
- package/dist/src/typechain/factories/GnosisSafe__factory.js +1174 -0
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +471 -0
- package/dist/src/typechain/factories/InteropXGateway__factory.js +265 -0
- package/dist/src/typechain/factories/index.js +14 -0
- package/dist/src/typechain/index.js +35 -0
- package/dist/{types.js → src/types.js} +0 -0
- package/dist/src/utils/index.js +238 -0
- package/package.json +18 -10
- package/patches/@ethersproject+properties+5.6.0.patch +13 -0
- package/src/abi/erc20.json +350 -0
- package/src/abi/gnosisSafe.json +747 -0
- package/src/abi/index.ts +11 -0
- package/src/abi/interopBridgeToken.json +298 -0
- package/src/abi/interopXGateway.json +184 -0
- package/src/api/index.ts +33 -0
- package/src/config/index.ts +17 -1
- package/src/constants/addresses.ts +9 -2
- package/src/constants/index.ts +2 -0
- package/src/constants/itokens.ts +10 -0
- package/src/constants/tokens.ts +104 -0
- package/src/db/models/index.ts +1 -1
- package/src/db/models/transaction.ts +96 -0
- package/src/db/sequelize.ts +2 -1
- package/src/index.ts +119 -7
- package/src/net/peer/index.ts +9 -7
- package/src/net/pool/index.ts +41 -11
- package/src/net/protocol/dial/SignatureDialProtocol.ts +24 -15
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +31 -0
- package/src/net/protocol/index.ts +60 -4
- package/src/tasks/AutoUpdateTask.ts +82 -0
- package/src/tasks/BaseTask.ts +15 -6
- package/src/tasks/InteropBridge/ProcessWithdrawEvents.ts +231 -0
- package/src/tasks/InteropBridge/SyncWithdrawEvents.ts +121 -0
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +256 -0
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +124 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +65 -0
- package/src/tasks/index.ts +26 -1
- package/src/typechain/Erc20.ts +491 -0
- package/src/typechain/GnosisSafe.ts +1728 -0
- package/src/typechain/InteropBridgeToken.ts +692 -0
- package/src/typechain/InteropXGateway.ts +407 -0
- package/src/typechain/common.ts +44 -0
- package/src/typechain/factories/Erc20__factory.ts +368 -0
- package/src/typechain/factories/GnosisSafe__factory.ts +1178 -0
- package/src/typechain/factories/InteropBridgeToken__factory.ts +478 -0
- package/src/typechain/factories/InteropXGateway__factory.ts +272 -0
- package/src/typechain/factories/index.ts +7 -0
- package/src/typechain/index.ts +12 -0
- package/src/types.ts +1 -1
- package/src/utils/index.ts +206 -3
- package/dist/config/index.js +0 -17
- package/dist/constants/addresses.js +0 -13
- package/dist/db/models/execution.js +0 -38
- package/dist/index.js +0 -43
- package/dist/tasks/index.js +0 -19
- package/dist/utils/index.js +0 -89
- package/src/db/models/execution.ts +0 -57
@@ -0,0 +1,265 @@
|
|
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.InteropXGateway__factory = void 0;
|
7
|
+
const ethers_1 = require("ethers");
|
8
|
+
const _abi = [
|
9
|
+
{
|
10
|
+
inputs: [
|
11
|
+
{
|
12
|
+
internalType: "address",
|
13
|
+
name: "__owner",
|
14
|
+
type: "address",
|
15
|
+
},
|
16
|
+
],
|
17
|
+
stateMutability: "nonpayable",
|
18
|
+
type: "constructor",
|
19
|
+
},
|
20
|
+
{
|
21
|
+
anonymous: false,
|
22
|
+
inputs: [
|
23
|
+
{
|
24
|
+
indexed: false,
|
25
|
+
internalType: "address",
|
26
|
+
name: "user",
|
27
|
+
type: "address",
|
28
|
+
},
|
29
|
+
{
|
30
|
+
indexed: true,
|
31
|
+
internalType: "address",
|
32
|
+
name: "token",
|
33
|
+
type: "address",
|
34
|
+
},
|
35
|
+
{
|
36
|
+
indexed: false,
|
37
|
+
internalType: "uint256",
|
38
|
+
name: "amount",
|
39
|
+
type: "uint256",
|
40
|
+
},
|
41
|
+
{
|
42
|
+
indexed: true,
|
43
|
+
internalType: "uint256",
|
44
|
+
name: "vnonce",
|
45
|
+
type: "uint256",
|
46
|
+
},
|
47
|
+
{
|
48
|
+
indexed: false,
|
49
|
+
internalType: "uint32",
|
50
|
+
name: "sourceChainId",
|
51
|
+
type: "uint32",
|
52
|
+
},
|
53
|
+
{
|
54
|
+
indexed: true,
|
55
|
+
internalType: "uint32",
|
56
|
+
name: "targetChainId",
|
57
|
+
type: "uint32",
|
58
|
+
},
|
59
|
+
],
|
60
|
+
name: "LogGatewayDeposit",
|
61
|
+
type: "event",
|
62
|
+
},
|
63
|
+
{
|
64
|
+
anonymous: false,
|
65
|
+
inputs: [
|
66
|
+
{
|
67
|
+
indexed: false,
|
68
|
+
internalType: "address",
|
69
|
+
name: "user",
|
70
|
+
type: "address",
|
71
|
+
},
|
72
|
+
{
|
73
|
+
indexed: true,
|
74
|
+
internalType: "address",
|
75
|
+
name: "token",
|
76
|
+
type: "address",
|
77
|
+
},
|
78
|
+
{
|
79
|
+
indexed: false,
|
80
|
+
internalType: "uint256",
|
81
|
+
name: "amount",
|
82
|
+
type: "uint256",
|
83
|
+
},
|
84
|
+
{
|
85
|
+
indexed: true,
|
86
|
+
internalType: "uint32",
|
87
|
+
name: "sourceChainId",
|
88
|
+
type: "uint32",
|
89
|
+
},
|
90
|
+
{
|
91
|
+
indexed: false,
|
92
|
+
internalType: "uint32",
|
93
|
+
name: "targetChainId",
|
94
|
+
type: "uint32",
|
95
|
+
},
|
96
|
+
{
|
97
|
+
indexed: true,
|
98
|
+
internalType: "bytes32",
|
99
|
+
name: "transactionHash",
|
100
|
+
type: "bytes32",
|
101
|
+
},
|
102
|
+
],
|
103
|
+
name: "LogGatewayWithdraw",
|
104
|
+
type: "event",
|
105
|
+
},
|
106
|
+
{
|
107
|
+
anonymous: false,
|
108
|
+
inputs: [
|
109
|
+
{
|
110
|
+
indexed: true,
|
111
|
+
internalType: "address",
|
112
|
+
name: "previousOwner",
|
113
|
+
type: "address",
|
114
|
+
},
|
115
|
+
{
|
116
|
+
indexed: true,
|
117
|
+
internalType: "address",
|
118
|
+
name: "newOwner",
|
119
|
+
type: "address",
|
120
|
+
},
|
121
|
+
],
|
122
|
+
name: "OwnershipTransferred",
|
123
|
+
type: "event",
|
124
|
+
},
|
125
|
+
{
|
126
|
+
inputs: [],
|
127
|
+
name: "_vnonce",
|
128
|
+
outputs: [
|
129
|
+
{
|
130
|
+
internalType: "uint256",
|
131
|
+
name: "",
|
132
|
+
type: "uint256",
|
133
|
+
},
|
134
|
+
],
|
135
|
+
stateMutability: "view",
|
136
|
+
type: "function",
|
137
|
+
},
|
138
|
+
{
|
139
|
+
inputs: [
|
140
|
+
{
|
141
|
+
internalType: "address",
|
142
|
+
name: "token_",
|
143
|
+
type: "address",
|
144
|
+
},
|
145
|
+
{
|
146
|
+
internalType: "uint256",
|
147
|
+
name: "amount_",
|
148
|
+
type: "uint256",
|
149
|
+
},
|
150
|
+
{
|
151
|
+
internalType: "uint32",
|
152
|
+
name: "chainId_",
|
153
|
+
type: "uint32",
|
154
|
+
},
|
155
|
+
],
|
156
|
+
name: "deposit",
|
157
|
+
outputs: [],
|
158
|
+
stateMutability: "nonpayable",
|
159
|
+
type: "function",
|
160
|
+
},
|
161
|
+
{
|
162
|
+
inputs: [
|
163
|
+
{
|
164
|
+
internalType: "address",
|
165
|
+
name: "to_",
|
166
|
+
type: "address",
|
167
|
+
},
|
168
|
+
{
|
169
|
+
internalType: "address",
|
170
|
+
name: "token_",
|
171
|
+
type: "address",
|
172
|
+
},
|
173
|
+
{
|
174
|
+
internalType: "uint256",
|
175
|
+
name: "amount_",
|
176
|
+
type: "uint256",
|
177
|
+
},
|
178
|
+
{
|
179
|
+
internalType: "uint32",
|
180
|
+
name: "chainId_",
|
181
|
+
type: "uint32",
|
182
|
+
},
|
183
|
+
],
|
184
|
+
name: "depositFor",
|
185
|
+
outputs: [],
|
186
|
+
stateMutability: "nonpayable",
|
187
|
+
type: "function",
|
188
|
+
},
|
189
|
+
{
|
190
|
+
inputs: [],
|
191
|
+
name: "owner",
|
192
|
+
outputs: [
|
193
|
+
{
|
194
|
+
internalType: "address",
|
195
|
+
name: "",
|
196
|
+
type: "address",
|
197
|
+
},
|
198
|
+
],
|
199
|
+
stateMutability: "view",
|
200
|
+
type: "function",
|
201
|
+
},
|
202
|
+
{
|
203
|
+
inputs: [],
|
204
|
+
name: "renounceOwnership",
|
205
|
+
outputs: [],
|
206
|
+
stateMutability: "nonpayable",
|
207
|
+
type: "function",
|
208
|
+
},
|
209
|
+
{
|
210
|
+
inputs: [
|
211
|
+
{
|
212
|
+
internalType: "uint256",
|
213
|
+
name: "amount_",
|
214
|
+
type: "uint256",
|
215
|
+
},
|
216
|
+
{
|
217
|
+
internalType: "address",
|
218
|
+
name: "user_",
|
219
|
+
type: "address",
|
220
|
+
},
|
221
|
+
{
|
222
|
+
internalType: "address",
|
223
|
+
name: "token_",
|
224
|
+
type: "address",
|
225
|
+
},
|
226
|
+
{
|
227
|
+
internalType: "uint32",
|
228
|
+
name: "chainId_",
|
229
|
+
type: "uint32",
|
230
|
+
},
|
231
|
+
{
|
232
|
+
internalType: "bytes32",
|
233
|
+
name: "transactionHash_",
|
234
|
+
type: "bytes32",
|
235
|
+
},
|
236
|
+
],
|
237
|
+
name: "systemWithdraw",
|
238
|
+
outputs: [],
|
239
|
+
stateMutability: "nonpayable",
|
240
|
+
type: "function",
|
241
|
+
},
|
242
|
+
{
|
243
|
+
inputs: [
|
244
|
+
{
|
245
|
+
internalType: "address",
|
246
|
+
name: "newOwner",
|
247
|
+
type: "address",
|
248
|
+
},
|
249
|
+
],
|
250
|
+
name: "transferOwnership",
|
251
|
+
outputs: [],
|
252
|
+
stateMutability: "nonpayable",
|
253
|
+
type: "function",
|
254
|
+
},
|
255
|
+
];
|
256
|
+
class InteropXGateway__factory {
|
257
|
+
static createInterface() {
|
258
|
+
return new ethers_1.utils.Interface(_abi);
|
259
|
+
}
|
260
|
+
static connect(address, signerOrProvider) {
|
261
|
+
return new ethers_1.Contract(address, _abi, signerOrProvider);
|
262
|
+
}
|
263
|
+
}
|
264
|
+
exports.InteropXGateway__factory = InteropXGateway__factory;
|
265
|
+
InteropXGateway__factory.abi = _abi;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.InteropXGateway__factory = exports.InteropBridgeToken__factory = exports.GnosisSafe__factory = exports.Erc20__factory = void 0;
|
4
|
+
/* Autogenerated file. Do not edit manually. */
|
5
|
+
/* tslint:disable */
|
6
|
+
/* eslint-disable */
|
7
|
+
var Erc20__factory_1 = require("./Erc20__factory");
|
8
|
+
Object.defineProperty(exports, "Erc20__factory", { enumerable: true, get: function () { return Erc20__factory_1.Erc20__factory; } });
|
9
|
+
var GnosisSafe__factory_1 = require("./GnosisSafe__factory");
|
10
|
+
Object.defineProperty(exports, "GnosisSafe__factory", { enumerable: true, get: function () { return GnosisSafe__factory_1.GnosisSafe__factory; } });
|
11
|
+
var InteropBridgeToken__factory_1 = require("./InteropBridgeToken__factory");
|
12
|
+
Object.defineProperty(exports, "InteropBridgeToken__factory", { enumerable: true, get: function () { return InteropBridgeToken__factory_1.InteropBridgeToken__factory; } });
|
13
|
+
var InteropXGateway__factory_1 = require("./InteropXGateway__factory");
|
14
|
+
Object.defineProperty(exports, "InteropXGateway__factory", { enumerable: true, get: function () { return InteropXGateway__factory_1.InteropXGateway__factory; } });
|
@@ -0,0 +1,35 @@
|
|
1
|
+
"use strict";
|
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]; } };
|
7
|
+
}
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.InteropXGateway__factory = exports.InteropBridgeToken__factory = exports.GnosisSafe__factory = exports.Erc20__factory = exports.factories = void 0;
|
27
|
+
exports.factories = __importStar(require("./factories"));
|
28
|
+
var Erc20__factory_1 = require("./factories/Erc20__factory");
|
29
|
+
Object.defineProperty(exports, "Erc20__factory", { enumerable: true, get: function () { return Erc20__factory_1.Erc20__factory; } });
|
30
|
+
var GnosisSafe__factory_1 = require("./factories/GnosisSafe__factory");
|
31
|
+
Object.defineProperty(exports, "GnosisSafe__factory", { enumerable: true, get: function () { return GnosisSafe__factory_1.GnosisSafe__factory; } });
|
32
|
+
var InteropBridgeToken__factory_1 = require("./factories/InteropBridgeToken__factory");
|
33
|
+
Object.defineProperty(exports, "InteropBridgeToken__factory", { enumerable: true, get: function () { return InteropBridgeToken__factory_1.InteropBridgeToken__factory; } });
|
34
|
+
var InteropXGateway__factory_1 = require("./factories/InteropXGateway__factory");
|
35
|
+
Object.defineProperty(exports, "InteropXGateway__factory", { enumerable: true, get: function () { return InteropXGateway__factory_1.InteropXGateway__factory; } });
|
File without changes
|
@@ -0,0 +1,238 @@
|
|
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.getContract = exports.buildWithdrawDataForTransaction = exports.buildDepositDataForTransaction = exports.buildDataForTransaction = exports.generateInteropTransactionHash = exports.asyncCallWithTimeout = exports.buildSignatureBytes = exports.getRpcProviderUrl = exports.signGnosisSafeTx = exports.short = exports.shortenHash = exports.http = void 0;
|
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 ethers_multisend_1 = require("ethers-multisend");
|
15
|
+
const config_1 = __importDefault(require("@/config"));
|
16
|
+
const abi_1 = __importDefault(require("@/abi"));
|
17
|
+
exports.http = axios_1.default.create();
|
18
|
+
(0, axios_retry_1.default)(exports.http, { retries: 3, retryDelay: axios_retry_1.default.exponentialDelay });
|
19
|
+
function shortenHash(hash, length = 4) {
|
20
|
+
if (!hash)
|
21
|
+
return;
|
22
|
+
if (hash.length < 12)
|
23
|
+
return hash;
|
24
|
+
const beginningChars = hash.startsWith("0x") ? length + 2 : length;
|
25
|
+
const shortened = hash.substr(0, beginningChars) + "…" + hash.substr(-length);
|
26
|
+
return shortened;
|
27
|
+
}
|
28
|
+
exports.shortenHash = shortenHash;
|
29
|
+
function short(buffer) {
|
30
|
+
return buffer.toString('hex').slice(0, 8) + '...';
|
31
|
+
}
|
32
|
+
exports.short = short;
|
33
|
+
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 }) => {
|
34
|
+
const gnosisSafe = constants_1.addresses[chainId].gnosisSafe;
|
35
|
+
const domain = {
|
36
|
+
verifyingContract: gnosisSafe,
|
37
|
+
chainId,
|
38
|
+
};
|
39
|
+
const types = {
|
40
|
+
SafeTx: [
|
41
|
+
{ type: 'address', name: 'to' },
|
42
|
+
{ type: 'uint256', name: 'value' },
|
43
|
+
{ type: 'bytes', name: 'data' },
|
44
|
+
{ type: 'uint8', name: 'operation' },
|
45
|
+
{ type: 'uint256', name: 'safeTxGas' },
|
46
|
+
{ type: 'uint256', name: 'baseGas' },
|
47
|
+
{ type: 'uint256', name: 'gasPrice' },
|
48
|
+
{ type: 'address', name: 'gasToken' },
|
49
|
+
{ type: 'address', name: 'refundReceiver' },
|
50
|
+
{ type: 'uint256', name: 'nonce' },
|
51
|
+
],
|
52
|
+
};
|
53
|
+
const message = {
|
54
|
+
baseGas,
|
55
|
+
data,
|
56
|
+
gasPrice,
|
57
|
+
gasToken,
|
58
|
+
nonce: Number(nonce),
|
59
|
+
operation,
|
60
|
+
refundReceiver,
|
61
|
+
safeAddress: gnosisSafe,
|
62
|
+
safeTxGas: String(safeTxGas),
|
63
|
+
to,
|
64
|
+
value,
|
65
|
+
};
|
66
|
+
return await signer._signTypedData(domain, types, message);
|
67
|
+
};
|
68
|
+
exports.signGnosisSafeTx = signGnosisSafeTx;
|
69
|
+
const getRpcProviderUrl = (chainId) => {
|
70
|
+
switch (chainId) {
|
71
|
+
case 1:
|
72
|
+
return 'https://rpc.ankr.com/eth';
|
73
|
+
case 137:
|
74
|
+
return 'https://rpc.ankr.com/polygon';
|
75
|
+
case 43114:
|
76
|
+
return 'https://rpc.ankr.com/avalanche';
|
77
|
+
default:
|
78
|
+
throw new Error(`Unknown chainId: ${chainId}`);
|
79
|
+
}
|
80
|
+
};
|
81
|
+
exports.getRpcProviderUrl = getRpcProviderUrl;
|
82
|
+
const buildSignatureBytes = (signatures) => {
|
83
|
+
signatures.sort((left, right) => left.signer.toLowerCase().localeCompare(right.signer.toLowerCase()));
|
84
|
+
let signatureBytes = "0x";
|
85
|
+
for (const sig of signatures) {
|
86
|
+
signatureBytes += sig.data.slice(2);
|
87
|
+
}
|
88
|
+
return signatureBytes;
|
89
|
+
};
|
90
|
+
exports.buildSignatureBytes = buildSignatureBytes;
|
91
|
+
/**
|
92
|
+
* Call an async function with a maximum time limit (in milliseconds) for the timeout
|
93
|
+
* Resolved promise for async function call, or an error if time limit reached
|
94
|
+
*/
|
95
|
+
const asyncCallWithTimeout = async (asyncPromise, timeout) => {
|
96
|
+
let timeoutHandle;
|
97
|
+
const timeoutPromise = new Promise((_resolve, reject) => {
|
98
|
+
timeoutHandle = setTimeout(() => reject(new Error('Async call timeout limit reached')), timeout);
|
99
|
+
});
|
100
|
+
return Promise.race([asyncPromise, timeoutPromise]).then(result => {
|
101
|
+
clearTimeout(timeoutHandle);
|
102
|
+
return result;
|
103
|
+
});
|
104
|
+
};
|
105
|
+
exports.asyncCallWithTimeout = asyncCallWithTimeout;
|
106
|
+
const generateInteropTransactionHash = (data) => {
|
107
|
+
return ethers_1.ethers.utils.solidityKeccak256(['string', 'string', 'string', 'string'], [
|
108
|
+
String(data.action),
|
109
|
+
String(data.submitTransactionHash),
|
110
|
+
String(data.sourceChainId),
|
111
|
+
String(data.targetChainId),
|
112
|
+
]);
|
113
|
+
};
|
114
|
+
exports.generateInteropTransactionHash = generateInteropTransactionHash;
|
115
|
+
const buildDataForTransaction = async (transaction, type) => {
|
116
|
+
type = type || transaction.sourceStatus === 'pending' ? 'source' : 'target';
|
117
|
+
switch (transaction.action) {
|
118
|
+
case "deposit":
|
119
|
+
return await (0, exports.buildDepositDataForTransaction)(transaction, type);
|
120
|
+
case "withdraw":
|
121
|
+
return await (0, exports.buildWithdrawDataForTransaction)(transaction, type);
|
122
|
+
default:
|
123
|
+
throw new Error(`Unknown action: ${transaction.action}`);
|
124
|
+
}
|
125
|
+
};
|
126
|
+
exports.buildDataForTransaction = buildDataForTransaction;
|
127
|
+
const buildDepositDataForTransaction = async (transaction, type) => {
|
128
|
+
const transactions = [];
|
129
|
+
if (transaction.action !== 'deposit') {
|
130
|
+
throw new Error(`Invalid action: ${transaction.action}`);
|
131
|
+
}
|
132
|
+
if (transaction.action === 'deposit' && transaction.sourceStatus === 'pending') {
|
133
|
+
throw Error('Cannot build data for pending deposit transaction');
|
134
|
+
}
|
135
|
+
if (!transaction.submitEvent) {
|
136
|
+
throw Error('Cannot build data for transaction without submitEvent');
|
137
|
+
}
|
138
|
+
const token = constants_1.tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
|
139
|
+
if (!token) {
|
140
|
+
throw Error('Cannot build data for transaction without token');
|
141
|
+
}
|
142
|
+
const itoken = constants_1.itokens[transaction.targetChainId].find(itoken => itoken.symbol.toLowerCase() === token.symbol.toLowerCase());
|
143
|
+
if (!itoken) {
|
144
|
+
throw Error('Cannot build data for transaction without itoken');
|
145
|
+
}
|
146
|
+
const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, exports.getRpcProviderUrl)(transaction.targetChainId));
|
147
|
+
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
148
|
+
const interopBridgeContract = getContract(itoken.address, abi_1.default.interopBridgeToken, targetWallet);
|
149
|
+
const { data } = await interopBridgeContract.populateTransaction.mint(transaction.submitEvent.user, ethers_1.ethers.BigNumber.from(transaction.submitEvent.amount.toString()), ethers_1.ethers.BigNumber.from(transaction.submitEvent.sourceChainId.toString()), transaction.submitTransactionHash);
|
150
|
+
transactions.push({
|
151
|
+
to: itoken.address,
|
152
|
+
data: data,
|
153
|
+
value: '0',
|
154
|
+
operation: ethers_multisend_1.OperationType.Call,
|
155
|
+
});
|
156
|
+
return (0, ethers_multisend_1.encodeMulti)(transactions).data;
|
157
|
+
};
|
158
|
+
exports.buildDepositDataForTransaction = buildDepositDataForTransaction;
|
159
|
+
const buildWithdrawDataForTransaction = async (transaction, type) => {
|
160
|
+
const transactions = [];
|
161
|
+
if (transaction.action !== 'withdraw') {
|
162
|
+
throw new Error(`Invalid action: ${transaction.action}`);
|
163
|
+
}
|
164
|
+
if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
|
165
|
+
throw Error('Cannot build data for pending withdraw transaction');
|
166
|
+
}
|
167
|
+
if (!transaction.submitEvent) {
|
168
|
+
throw Error('Cannot build data for transaction without submitEvent');
|
169
|
+
}
|
170
|
+
const { to, amount, sourceChainId, targetChainId, itoken: itokenAddress } = transaction.submitEvent;
|
171
|
+
const itoken = constants_1.itokens[sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
|
172
|
+
if (!itoken) {
|
173
|
+
throw Error('Cannot build data for transaction without itoken');
|
174
|
+
}
|
175
|
+
const token = constants_1.tokens[targetChainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
|
176
|
+
if (!token) {
|
177
|
+
throw Error('Cannot build data for transaction without token');
|
178
|
+
}
|
179
|
+
const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, exports.getRpcProviderUrl)(targetChainId));
|
180
|
+
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
181
|
+
const gatewayAddress = constants_1.addresses[targetChainId].interopXGateway;
|
182
|
+
const interopBridgeContract = getContract(gatewayAddress, abi_1.default.interopXGateway, targetWallet);
|
183
|
+
const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(ethers_1.ethers.BigNumber.from(amount.toString()), to, token.address, ethers_1.ethers.BigNumber.from(sourceChainId.toString()), transaction.submitTransactionHash);
|
184
|
+
transactions.push({
|
185
|
+
to: gatewayAddress,
|
186
|
+
data: data,
|
187
|
+
value: '0',
|
188
|
+
operation: ethers_multisend_1.OperationType.Call,
|
189
|
+
});
|
190
|
+
return (0, ethers_multisend_1.encodeMulti)(transactions).data;
|
191
|
+
};
|
192
|
+
exports.buildWithdrawDataForTransaction = buildWithdrawDataForTransaction;
|
193
|
+
function getContract(address, contractInterface, signerOrProvider) {
|
194
|
+
if (!ethers_1.ethers.utils.getAddress(address) || address === ethers_1.ethers.constants.AddressZero) {
|
195
|
+
throw Error(`Invalid 'address' parameter '${address}'.`);
|
196
|
+
}
|
197
|
+
const contract = new ethers_1.ethers.Contract(address, contractInterface, signerOrProvider);
|
198
|
+
// Make sure the contract properties is writable
|
199
|
+
const desc = Object.getOwnPropertyDescriptor(contract, 'functions');
|
200
|
+
if (!desc || desc.writable !== true) {
|
201
|
+
return contract;
|
202
|
+
}
|
203
|
+
return new Proxy(contract, {
|
204
|
+
get(target, prop, receiver) {
|
205
|
+
const value = Reflect.get(target, prop, receiver);
|
206
|
+
if (typeof value === 'function' && (contract.functions.hasOwnProperty(prop) || ['queryFilter'].includes(String(prop)))) {
|
207
|
+
return async (...args) => {
|
208
|
+
try {
|
209
|
+
return await value.bind(contract)(...args);
|
210
|
+
}
|
211
|
+
catch (error) {
|
212
|
+
throw new Error(`Error calling "${String(prop)}" on "${address}": ${error.reason || error.message}`);
|
213
|
+
}
|
214
|
+
};
|
215
|
+
}
|
216
|
+
if (typeof value === 'object' && ['populateTransaction', 'estimateGas', 'functions', 'callStatic'].includes(String(prop))) {
|
217
|
+
const parentProp = String(prop);
|
218
|
+
return new Proxy(value, {
|
219
|
+
get(target, prop, receiver) {
|
220
|
+
const value = Reflect.get(target, prop, receiver);
|
221
|
+
if (typeof value === 'function') {
|
222
|
+
return async (...args) => {
|
223
|
+
try {
|
224
|
+
return await value.bind(contract)(...args);
|
225
|
+
}
|
226
|
+
catch (error) {
|
227
|
+
throw new Error(`Error calling "${String(prop)}" using "${parentProp}" on "${address}": ${error.reason || error.message}`);
|
228
|
+
}
|
229
|
+
};
|
230
|
+
}
|
231
|
+
}
|
232
|
+
});
|
233
|
+
}
|
234
|
+
return value;
|
235
|
+
},
|
236
|
+
});
|
237
|
+
}
|
238
|
+
exports.getContract = getContract;
|
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.f0a6281",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"engines": {
|
@@ -9,9 +9,11 @@
|
|
9
9
|
},
|
10
10
|
"scripts": {
|
11
11
|
"start": "yarn build && node bin/interop-x",
|
12
|
-
"build": "export GIT_REF=$(git rev-parse --short HEAD) && rimraf ./dist && tsc -p tsconfig.json && replace-in-file '@GIT_SHORT_HASH@' $GIT_REF ./dist/**/*.js",
|
13
|
-
"dev": "NODE_ENV=development nodemon",
|
14
|
-
"
|
12
|
+
"build": "yarn generate-abi-types && export GIT_REF=$(git rev-parse --short HEAD) && rimraf ./dist && tsc -p tsconfig.json && replace-in-file '@GIT_SHORT_HASH@' $GIT_REF ./dist/**/*.js",
|
13
|
+
"dev": "yarn generate-abi-types && NODE_ENV=development nodemon",
|
14
|
+
"generate-abi-types": "typechain --target=ethers-v5 'src/abi/*.json' --out-dir 'src/typechain'",
|
15
|
+
"prepublishOnly": "yarn build",
|
16
|
+
"postinstall": "patch-package"
|
15
17
|
},
|
16
18
|
"nodemonConfig": {
|
17
19
|
"watch": [
|
@@ -22,15 +24,18 @@
|
|
22
24
|
},
|
23
25
|
"dependencies": {
|
24
26
|
"@achingbrain/libp2p-gossipsub": "^0.12.2",
|
27
|
+
"@fastify/cors": "^7.0.0",
|
28
|
+
"await-spawn": "^4.0.2",
|
25
29
|
"axios": "^0.27.1",
|
26
30
|
"axios-retry": "^3.2.4",
|
27
|
-
"bignumber.js": "^9.0.2",
|
28
31
|
"chalk": "4.1.2",
|
29
32
|
"dotenv": "^16.0.0",
|
30
33
|
"ethereumjs-util": "^7.1.4",
|
31
34
|
"ethers": "^5.6.4",
|
32
35
|
"ethers-multisend": "^2.1.1",
|
33
36
|
"expand-home-dir": "^0.0.3",
|
37
|
+
"fastify": "^3.28.0",
|
38
|
+
"fs-extra": "^10.1.0",
|
34
39
|
"libp2p": "^0.36.2",
|
35
40
|
"libp2p-bootstrap": "^0.14.0",
|
36
41
|
"libp2p-kad-dht": "^0.28.6",
|
@@ -42,14 +47,19 @@
|
|
42
47
|
"libp2p-websockets": "^0.16.2",
|
43
48
|
"luxon": "^2.3.2",
|
44
49
|
"module-alias": "^2.2.2",
|
45
|
-
"
|
50
|
+
"patch-package": "^6.4.7",
|
51
|
+
"postinstall-postinstall": "^2.1.0",
|
52
|
+
"sequelize": "6.18.0",
|
46
53
|
"sqlite3": "^5.0.5",
|
47
54
|
"waait": "^1.0.5"
|
48
55
|
},
|
49
56
|
"bin": {
|
50
|
-
"interop-
|
57
|
+
"interop-x": "bin/interop-x",
|
58
|
+
"interopx": "bin/interop-x"
|
51
59
|
},
|
52
60
|
"devDependencies": {
|
61
|
+
"@typechain/ethers-v5": "^10.0.0",
|
62
|
+
"@types/bn.js": "^5.1.0",
|
53
63
|
"@types/fs-extra": "^9.0.13",
|
54
64
|
"@types/node": "^17.0.17",
|
55
65
|
"nodemon": "^2.0.15",
|
@@ -57,9 +67,7 @@
|
|
57
67
|
"rimraf": "^3.0.2",
|
58
68
|
"ts-node": "^10.5.0",
|
59
69
|
"tsconfig-paths": "^3.12.0",
|
70
|
+
"typechain": "^8.0.0",
|
60
71
|
"typescript": "^4.5.5"
|
61
|
-
},
|
62
|
-
"_moduleAliases": {
|
63
|
-
"@/": "./"
|
64
72
|
}
|
65
73
|
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
diff --git a/node_modules/@ethersproject/properties/lib/index.js b/node_modules/@ethersproject/properties/lib/index.js
|
2
|
+
index 41e0b52..4c7a9e3 100644
|
3
|
+
--- a/node_modules/@ethersproject/properties/lib/index.js
|
4
|
+
+++ b/node_modules/@ethersproject/properties/lib/index.js
|
5
|
+
@@ -44,7 +44,7 @@ function defineReadOnly(object, name, value) {
|
6
|
+
Object.defineProperty(object, name, {
|
7
|
+
enumerable: true,
|
8
|
+
value: value,
|
9
|
+
- writable: false,
|
10
|
+
+ writable: true,
|
11
|
+
});
|
12
|
+
}
|
13
|
+
exports.defineReadOnly = defineReadOnly;
|