@instadapp/interop-x 0.0.0-dev.6088815 → 0.0.0-dev.6a2c9c4
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 +16 -14
- package/dist/src/abi/index.js +2 -4
- package/dist/src/abi/interopXContract.json +454 -0
- package/dist/src/alias.js +10 -0
- package/dist/src/api/index.js +6 -3
- package/dist/src/config/index.js +10 -1
- package/dist/src/constants/addresses.js +7 -7
- package/dist/src/constants/index.js +0 -1
- package/dist/src/constants/tokens.js +62 -39
- package/dist/src/db/models/transaction.js +27 -11
- package/dist/src/gnosis/actions/index.js +9 -0
- package/dist/src/gnosis/actions/withdraw/index.js +115 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +39 -23
- package/dist/src/net/peer/index.js +2 -1
- package/dist/src/net/pool/index.js +7 -2
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +9 -10
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
- package/dist/src/net/protocol/index.js +26 -5
- package/dist/src/tasks/AutoUpdateTask.js +42 -18
- package/dist/src/tasks/BaseTask.js +11 -3
- package/dist/src/tasks/{InteropXGateway/ProcessDepositEvents.js → InteropXContract/ProcessBridgeRequestEvents.js} +61 -53
- package/dist/src/tasks/InteropXContract/SyncBridgeCommittedEvents.js +93 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +90 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +57 -0
- package/dist/src/tasks/index.js +16 -17
- package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
- package/dist/src/typechain/factories/InteropXContract__factory.js +635 -0
- package/dist/src/typechain/factories/index.js +3 -5
- package/dist/src/typechain/index.js +3 -5
- package/dist/src/utils/index.js +57 -92
- package/package.json +16 -14
- package/src/abi/index.ts +2 -4
- package/src/abi/interopXContract.json +454 -0
- package/src/alias.ts +6 -0
- package/src/api/index.ts +5 -2
- package/src/config/index.ts +9 -1
- package/src/constants/addresses.ts +8 -8
- package/src/constants/index.ts +0 -1
- package/src/constants/tokens.ts +63 -40
- package/src/db/models/transaction.ts +76 -27
- package/src/gnosis/actions/index.ts +5 -0
- package/src/gnosis/actions/withdraw/index.ts +155 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +52 -25
- package/src/net/peer/index.ts +2 -1
- package/src/net/pool/index.ts +7 -3
- package/src/net/protocol/dial/SignatureDialProtocol.ts +11 -13
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
- package/src/net/protocol/index.ts +28 -6
- package/src/tasks/AutoUpdateTask.ts +48 -21
- package/src/tasks/BaseTask.ts +13 -3
- package/src/tasks/{InteropBridge/ProcessWithdrawEvents.ts → InteropXContract/ProcessBridgeRequestEvents.ts} +88 -95
- package/src/tasks/InteropXContract/SyncBridgeCommittedEvents.ts +125 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +115 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +121 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +69 -0
- package/src/tasks/index.ts +21 -18
- package/src/typechain/InteropXContract.ts +680 -0
- package/src/typechain/factories/InteropXContract__factory.ts +642 -0
- package/src/typechain/factories/index.ts +1 -2
- package/src/typechain/index.ts +2 -4
- package/src/utils/index.ts +97 -129
- package/tsconfig.json +7 -2
- package/dist/src/abi/interopBridgeToken.json +0 -286
- package/dist/src/abi/interopXGateway.json +0 -184
- package/dist/src/constants/itokens.js +0 -13
- package/dist/src/tasks/InteropBridge/ProcessWithdrawEvents.js +0 -147
- package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +0 -70
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -75
- package/dist/src/typechain/InteropXGateway.js +0 -2
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -459
- package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
- package/src/abi/interopBridgeToken.json +0 -286
- package/src/abi/interopXGateway.json +0 -184
- package/src/constants/itokens.ts +0 -10
- package/src/tasks/InteropBridge/SyncWithdrawEvents.ts +0 -121
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -245
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -126
- package/src/typechain/InteropBridgeToken.ts +0 -686
- package/src/typechain/InteropXGateway.ts +0 -407
- package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
- package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
package/dist/src/utils/index.js
CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.
|
6
|
+
exports.LiquidityError = exports.generateGnosisTransaction = exports.getContract = exports.ContractError = exports.generateInteropTransactionHash = exports.asyncCallWithTimeout = exports.buildSignatureBytes = exports.getRpcProviderUrl = exports.signGnosisSafeTx = exports.short = exports.shortenHash = exports.http = void 0;
|
7
7
|
/**
|
8
8
|
* @module util
|
9
9
|
*/
|
@@ -11,11 +11,19 @@ const axios_1 = __importDefault(require("axios"));
|
|
11
11
|
const axios_retry_1 = __importDefault(require("axios-retry"));
|
12
12
|
const constants_1 = require("@/constants");
|
13
13
|
const ethers_1 = require("ethers");
|
14
|
-
const
|
15
|
-
const config_1 = __importDefault(require("@/config"));
|
16
|
-
const abi_1 = __importDefault(require("@/abi"));
|
14
|
+
const async_retry_1 = __importDefault(require("async-retry"));
|
17
15
|
exports.http = axios_1.default.create();
|
18
16
|
(0, axios_retry_1.default)(exports.http, { retries: 3, retryDelay: axios_retry_1.default.exponentialDelay });
|
17
|
+
function shortenHash(hash, length = 4) {
|
18
|
+
if (!hash)
|
19
|
+
return;
|
20
|
+
if (hash.length < 12)
|
21
|
+
return hash;
|
22
|
+
const beginningChars = hash.startsWith("0x") ? length + 2 : length;
|
23
|
+
const shortened = hash.substr(0, beginningChars) + "…" + hash.substr(-length);
|
24
|
+
return shortened;
|
25
|
+
}
|
26
|
+
exports.shortenHash = shortenHash;
|
19
27
|
function short(buffer) {
|
20
28
|
return buffer.toString('hex').slice(0, 8) + '...';
|
21
29
|
}
|
@@ -59,11 +67,11 @@ exports.signGnosisSafeTx = signGnosisSafeTx;
|
|
59
67
|
const getRpcProviderUrl = (chainId) => {
|
60
68
|
switch (chainId) {
|
61
69
|
case 1:
|
62
|
-
return 'https://rpc.
|
70
|
+
return 'https://rpc.ankr.com/eth';
|
63
71
|
case 137:
|
64
|
-
return 'https://rpc.
|
72
|
+
return 'https://rpc.ankr.com/polygon';
|
65
73
|
case 43114:
|
66
|
-
return 'https://rpc.
|
74
|
+
return 'https://rpc.ankr.com/avalanche';
|
67
75
|
default:
|
68
76
|
throw new Error(`Unknown chainId: ${chainId}`);
|
69
77
|
}
|
@@ -94,92 +102,18 @@ const asyncCallWithTimeout = async (asyncPromise, timeout) => {
|
|
94
102
|
};
|
95
103
|
exports.asyncCallWithTimeout = asyncCallWithTimeout;
|
96
104
|
const generateInteropTransactionHash = (data) => {
|
97
|
-
return ethers_1.ethers.utils.solidityKeccak256(['string', 'string', 'string', 'string'], [
|
98
|
-
String(data.
|
99
|
-
String(data.
|
105
|
+
return ethers_1.ethers.utils.solidityKeccak256(['string', 'string', 'string', 'string', 'string'], [
|
106
|
+
String(data.actionId),
|
107
|
+
String(data.bridger),
|
108
|
+
String(data.requestTransactionHash),
|
100
109
|
String(data.sourceChainId),
|
101
110
|
String(data.targetChainId),
|
102
111
|
]);
|
103
112
|
};
|
104
113
|
exports.generateInteropTransactionHash = generateInteropTransactionHash;
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
case "deposit":
|
109
|
-
return await (0, exports.buildDepositDataForTransaction)(transaction, type);
|
110
|
-
case "withdraw":
|
111
|
-
return await (0, exports.buildWithdrawDataForTransaction)(transaction, type);
|
112
|
-
default:
|
113
|
-
throw new Error(`Unknown action: ${transaction.action}`);
|
114
|
-
}
|
115
|
-
};
|
116
|
-
exports.buildDataForTransaction = buildDataForTransaction;
|
117
|
-
const buildDepositDataForTransaction = async (transaction, type) => {
|
118
|
-
const transactions = [];
|
119
|
-
if (transaction.action !== 'deposit') {
|
120
|
-
throw new Error(`Invalid action: ${transaction.action}`);
|
121
|
-
}
|
122
|
-
if (transaction.action === 'deposit' && transaction.sourceStatus === 'pending') {
|
123
|
-
throw Error('Cannot build data for pending deposit transaction');
|
124
|
-
}
|
125
|
-
if (!transaction.submitEvent) {
|
126
|
-
throw Error('Cannot build data for transaction without submitEvent');
|
127
|
-
}
|
128
|
-
const token = constants_1.tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
|
129
|
-
if (!token) {
|
130
|
-
throw Error('Cannot build data for transaction without token');
|
131
|
-
}
|
132
|
-
const itoken = constants_1.itokens[transaction.targetChainId].find(itoken => itoken.symbol.toLowerCase() === token.symbol.toLowerCase());
|
133
|
-
if (!itoken) {
|
134
|
-
throw Error('Cannot build data for transaction without itoken');
|
135
|
-
}
|
136
|
-
const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, exports.getRpcProviderUrl)(transaction.targetChainId));
|
137
|
-
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
138
|
-
const interopBridgeContract = getContract(itoken.address, abi_1.default.interopBridgeToken, targetWallet);
|
139
|
-
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);
|
140
|
-
transactions.push({
|
141
|
-
to: itoken.address,
|
142
|
-
data: data,
|
143
|
-
value: '0',
|
144
|
-
operation: ethers_multisend_1.OperationType.Call,
|
145
|
-
});
|
146
|
-
return (0, ethers_multisend_1.encodeMulti)(transactions).data;
|
147
|
-
};
|
148
|
-
exports.buildDepositDataForTransaction = buildDepositDataForTransaction;
|
149
|
-
const buildWithdrawDataForTransaction = async (transaction, type) => {
|
150
|
-
const transactions = [];
|
151
|
-
if (transaction.action !== 'withdraw') {
|
152
|
-
throw new Error(`Invalid action: ${transaction.action}`);
|
153
|
-
}
|
154
|
-
if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
|
155
|
-
throw Error('Cannot build data for pending withdraw transaction');
|
156
|
-
}
|
157
|
-
if (!transaction.submitEvent) {
|
158
|
-
throw Error('Cannot build data for transaction without submitEvent');
|
159
|
-
}
|
160
|
-
const { to, amount, chainId, itoken: itokenAddress } = transaction.submitEvent;
|
161
|
-
const itoken = constants_1.itokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
|
162
|
-
if (!itoken) {
|
163
|
-
throw Error('Cannot build data for transaction without itoken');
|
164
|
-
}
|
165
|
-
const token = constants_1.tokens[chainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
|
166
|
-
if (!token) {
|
167
|
-
throw Error('Cannot build data for transaction without token');
|
168
|
-
}
|
169
|
-
const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, exports.getRpcProviderUrl)(transaction.targetChainId));
|
170
|
-
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
171
|
-
const gatewayAddress = constants_1.addresses[chainId].interopXGateway;
|
172
|
-
const interopBridgeContract = getContract(gatewayAddress, abi_1.default.interopXGateway, targetWallet);
|
173
|
-
const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(ethers_1.ethers.BigNumber.from(amount.toString()), to, token.address, ethers_1.ethers.BigNumber.from(transaction.sourceChainId.toString()), transaction.submitTransactionHash);
|
174
|
-
transactions.push({
|
175
|
-
to: gatewayAddress,
|
176
|
-
data: data,
|
177
|
-
value: '0',
|
178
|
-
operation: ethers_multisend_1.OperationType.Call,
|
179
|
-
});
|
180
|
-
return (0, ethers_multisend_1.encodeMulti)(transactions).data;
|
181
|
-
};
|
182
|
-
exports.buildWithdrawDataForTransaction = buildWithdrawDataForTransaction;
|
114
|
+
class ContractError extends Error {
|
115
|
+
}
|
116
|
+
exports.ContractError = ContractError;
|
183
117
|
function getContract(address, contractInterface, signerOrProvider) {
|
184
118
|
if (!ethers_1.ethers.utils.getAddress(address) || address === ethers_1.ethers.constants.AddressZero) {
|
185
119
|
throw Error(`Invalid 'address' parameter '${address}'.`);
|
@@ -194,12 +128,22 @@ function getContract(address, contractInterface, signerOrProvider) {
|
|
194
128
|
get(target, prop, receiver) {
|
195
129
|
const value = Reflect.get(target, prop, receiver);
|
196
130
|
if (typeof value === 'function' && (contract.functions.hasOwnProperty(prop) || ['queryFilter'].includes(String(prop)))) {
|
131
|
+
let isConstant = false;
|
132
|
+
try {
|
133
|
+
isConstant = contract.interface.getFunction(String(prop)).constant;
|
134
|
+
}
|
135
|
+
catch (error) {
|
136
|
+
}
|
197
137
|
return async (...args) => {
|
198
138
|
try {
|
199
|
-
return await value.bind(contract)(...args);
|
139
|
+
return await (0, async_retry_1.default)(async () => await value.bind(contract)(...args), { retries: isConstant ? 1 : 3 });
|
200
140
|
}
|
201
141
|
catch (error) {
|
202
|
-
|
142
|
+
const err = new ContractError(`Error calling "${String(prop)}" on "${address}": ${error.reason || error.message}`);
|
143
|
+
err.method = String(prop);
|
144
|
+
err.address = address;
|
145
|
+
err.args = [...args];
|
146
|
+
throw err;
|
203
147
|
}
|
204
148
|
};
|
205
149
|
}
|
@@ -211,10 +155,14 @@ function getContract(address, contractInterface, signerOrProvider) {
|
|
211
155
|
if (typeof value === 'function') {
|
212
156
|
return async (...args) => {
|
213
157
|
try {
|
214
|
-
return await value.bind(contract)(...args);
|
158
|
+
return await (0, async_retry_1.default)(async () => await value.bind(contract)(...args), { retries: parentProp === 'callStatic' ? 3 : 1 });
|
215
159
|
}
|
216
160
|
catch (error) {
|
217
|
-
|
161
|
+
const err = new ContractError(`Error calling "${String(prop)}" using "${parentProp}" on "${address}": ${error.reason || error.message}`);
|
162
|
+
err.method = String(prop);
|
163
|
+
err.address = address;
|
164
|
+
err.args = [...args];
|
165
|
+
throw err;
|
218
166
|
}
|
219
167
|
};
|
220
168
|
}
|
@@ -226,3 +174,20 @@ function getContract(address, contractInterface, signerOrProvider) {
|
|
226
174
|
});
|
227
175
|
}
|
228
176
|
exports.getContract = getContract;
|
177
|
+
const generateGnosisTransaction = async (transactionData, safeContract) => {
|
178
|
+
console.log(transactionData);
|
179
|
+
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));
|
180
|
+
while (isExecuted == 1) {
|
181
|
+
transactionData.safeTxGas = ethers_1.ethers.BigNumber.from(String(transactionData.safeTxGas)).add(1).toString();
|
182
|
+
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));
|
183
|
+
}
|
184
|
+
return transactionData;
|
185
|
+
};
|
186
|
+
exports.generateGnosisTransaction = generateGnosisTransaction;
|
187
|
+
class LiquidityError extends Error {
|
188
|
+
constructor(message) {
|
189
|
+
super(message || 'Not enough liquidity');
|
190
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
191
|
+
}
|
192
|
+
}
|
193
|
+
exports.LiquidityError = LiquidityError;
|
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.6a2c9c4",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"engines": {
|
@@ -11,7 +11,7 @@
|
|
11
11
|
"start": "yarn build && node bin/interop-x",
|
12
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
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'",
|
14
|
+
"generate-abi-types": "rimraf src/typechain && typechain --target=ethers-v5 'src/abi/*.json' --out-dir 'src/typechain'",
|
15
15
|
"prepublishOnly": "yarn build",
|
16
16
|
"postinstall": "patch-package"
|
17
17
|
},
|
@@ -24,17 +24,19 @@
|
|
24
24
|
},
|
25
25
|
"dependencies": {
|
26
26
|
"@achingbrain/libp2p-gossipsub": "^0.12.2",
|
27
|
-
"
|
28
|
-
"
|
29
|
-
"
|
27
|
+
"@fastify/cors": "^7.0.0",
|
28
|
+
"async-retry": "^1.3.3",
|
29
|
+
"await-spawn": "^4.0.2",
|
30
|
+
"axios": "^0.27.2",
|
31
|
+
"axios-retry": "^3.2.5",
|
30
32
|
"chalk": "4.1.2",
|
31
|
-
"dotenv": "^16.0.
|
33
|
+
"dotenv": "^16.0.1",
|
32
34
|
"ethereumjs-util": "^7.1.4",
|
33
|
-
"ethers": "^5.6.
|
35
|
+
"ethers": "^5.6.5",
|
34
36
|
"ethers-multisend": "^2.1.1",
|
35
37
|
"expand-home-dir": "^0.0.3",
|
36
|
-
"fastify": "^3.
|
37
|
-
"
|
38
|
+
"fastify": "^3.29.0",
|
39
|
+
"fs-extra": "^10.1.0",
|
38
40
|
"libp2p": "^0.36.2",
|
39
41
|
"libp2p-bootstrap": "^0.14.0",
|
40
42
|
"libp2p-kad-dht": "^0.28.6",
|
@@ -44,12 +46,12 @@
|
|
44
46
|
"libp2p-pubsub-peer-discovery": "^4.0.0",
|
45
47
|
"libp2p-tcp": "^0.17.2",
|
46
48
|
"libp2p-websockets": "^0.16.2",
|
47
|
-
"luxon": "^2.
|
49
|
+
"luxon": "^2.4.0",
|
48
50
|
"module-alias": "^2.2.2",
|
49
51
|
"patch-package": "^6.4.7",
|
50
52
|
"postinstall-postinstall": "^2.1.0",
|
51
53
|
"sequelize": "6.18.0",
|
52
|
-
"sqlite3": "^5.0.
|
54
|
+
"sqlite3": "^5.0.8",
|
53
55
|
"waait": "^1.0.5"
|
54
56
|
},
|
55
57
|
"bin": {
|
@@ -60,13 +62,13 @@
|
|
60
62
|
"@typechain/ethers-v5": "^10.0.0",
|
61
63
|
"@types/bn.js": "^5.1.0",
|
62
64
|
"@types/fs-extra": "^9.0.13",
|
63
|
-
"@types/node": "^17.0.
|
64
|
-
"nodemon": "^2.0.
|
65
|
+
"@types/node": "^17.0.33",
|
66
|
+
"nodemon": "^2.0.16",
|
65
67
|
"replace-in-file": "^6.3.2",
|
66
68
|
"rimraf": "^3.0.2",
|
67
69
|
"ts-node": "^10.5.0",
|
68
70
|
"tsconfig-paths": "^3.12.0",
|
69
71
|
"typechain": "^8.0.0",
|
70
|
-
"typescript": "^4.
|
72
|
+
"typescript": "^4.6.4"
|
71
73
|
}
|
72
74
|
}
|
package/src/abi/index.ts
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
import gnosisSafe from "./gnosisSafe.json";
|
2
2
|
import erc20 from "./erc20.json";
|
3
|
-
import
|
4
|
-
import interopBridgeToken from "./interopBridgeToken.json";
|
3
|
+
import interopXContract from "./interopXContract.json";
|
5
4
|
|
6
5
|
export default {
|
7
6
|
gnosisSafe,
|
8
7
|
erc20,
|
9
|
-
|
10
|
-
interopBridgeToken,
|
8
|
+
interopXContract,
|
11
9
|
}
|