@instadapp/interop-x 0.0.0-dev.b70f25f → 0.0.0-dev.bfeca30
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 +14 -13
- 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 +3 -0
- package/dist/src/config/index.js +10 -1
- package/dist/src/constants/addresses.js +3 -3
- package/dist/src/constants/index.js +0 -1
- package/dist/src/constants/tokens.js +31 -1
- 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 +55 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +34 -22
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +9 -10
- package/dist/src/net/protocol/dial/{SignatureDialProtocol.1.js → TransactionStatusDialProtocol.js} +2 -0
- package/dist/src/net/protocol/index.js +17 -7
- package/dist/src/tasks/AutoUpdateTask.js +34 -12
- package/dist/src/tasks/BaseTask.js +4 -0
- package/dist/src/tasks/{InteropXGateway/ProcessDepositEvents.js → InteropXContract/ProcessBridgeRequestEvents.js} +54 -51
- package/dist/src/tasks/InteropXContract/SyncBridgeCommittedEvents.js +92 -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 +2 -0
- package/dist/src/tasks/index.js +16 -19
- 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 +37 -89
- package/package.json +14 -13
- 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 +3 -0
- package/src/config/index.ts +9 -1
- package/src/constants/addresses.ts +3 -3
- package/src/constants/index.ts +0 -1
- package/src/constants/tokens.ts +32 -2
- package/src/db/models/transaction.ts +76 -27
- package/src/gnosis/actions/index.ts +5 -0
- package/src/gnosis/actions/withdraw/index.ts +77 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +47 -26
- package/src/net/protocol/dial/SignatureDialProtocol.ts +11 -13
- package/src/net/protocol/dial/{SignatureDialProtocol.1.ts → TransactionStatusDialProtocol.ts} +3 -1
- package/src/net/protocol/index.ts +17 -7
- package/src/tasks/AutoUpdateTask.ts +36 -15
- package/src/tasks/BaseTask.ts +5 -0
- package/src/tasks/{InteropBridge/ProcessWithdrawEvents.ts → InteropXContract/ProcessBridgeRequestEvents.ts} +79 -94
- package/src/tasks/InteropXContract/SyncBridgeCommittedEvents.ts +124 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +115 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +121 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +2 -0
- package/src/tasks/index.ts +21 -20
- 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 +75 -126
- 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 -146
- package/dist/src/tasks/InteropBridge/SyncWithdrawEvents.js +0 -69
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -74
- 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 -119
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -243
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -124
- 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.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,9 +11,7 @@ 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 });
|
19
17
|
function shortenHash(hash, length = 4) {
|
@@ -104,92 +102,18 @@ const asyncCallWithTimeout = async (asyncPromise, timeout) => {
|
|
104
102
|
};
|
105
103
|
exports.asyncCallWithTimeout = asyncCallWithTimeout;
|
106
104
|
const generateInteropTransactionHash = (data) => {
|
107
|
-
return ethers_1.ethers.utils.solidityKeccak256(['string', 'string', 'string', 'string'], [
|
108
|
-
String(data.
|
109
|
-
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),
|
110
109
|
String(data.sourceChainId),
|
111
110
|
String(data.targetChainId),
|
112
111
|
]);
|
113
112
|
};
|
114
113
|
exports.generateInteropTransactionHash = generateInteropTransactionHash;
|
115
|
-
|
116
|
-
|
117
|
-
|
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, chainId, itoken: itokenAddress } = transaction.submitEvent;
|
171
|
-
const itoken = constants_1.itokens[transaction.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[chainId].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)(transaction.targetChainId));
|
180
|
-
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
181
|
-
const gatewayAddress = constants_1.addresses[chainId].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(transaction.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;
|
114
|
+
class ContractError extends Error {
|
115
|
+
}
|
116
|
+
exports.ContractError = ContractError;
|
193
117
|
function getContract(address, contractInterface, signerOrProvider) {
|
194
118
|
if (!ethers_1.ethers.utils.getAddress(address) || address === ethers_1.ethers.constants.AddressZero) {
|
195
119
|
throw Error(`Invalid 'address' parameter '${address}'.`);
|
@@ -204,12 +128,22 @@ function getContract(address, contractInterface, signerOrProvider) {
|
|
204
128
|
get(target, prop, receiver) {
|
205
129
|
const value = Reflect.get(target, prop, receiver);
|
206
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
|
+
}
|
207
137
|
return async (...args) => {
|
208
138
|
try {
|
209
|
-
return await value.bind(contract)(...args);
|
139
|
+
return await (0, async_retry_1.default)(async () => await value.bind(contract)(...args), { retries: isConstant ? 1 : 3 });
|
210
140
|
}
|
211
141
|
catch (error) {
|
212
|
-
|
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;
|
213
147
|
}
|
214
148
|
};
|
215
149
|
}
|
@@ -221,10 +155,14 @@ function getContract(address, contractInterface, signerOrProvider) {
|
|
221
155
|
if (typeof value === 'function') {
|
222
156
|
return async (...args) => {
|
223
157
|
try {
|
224
|
-
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 });
|
225
159
|
}
|
226
160
|
catch (error) {
|
227
|
-
|
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;
|
228
166
|
}
|
229
167
|
};
|
230
168
|
}
|
@@ -236,3 +174,13 @@ function getContract(address, contractInterface, signerOrProvider) {
|
|
236
174
|
});
|
237
175
|
}
|
238
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;
|
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.bfeca30",
|
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
|
},
|
@@ -25,17 +25,18 @@
|
|
25
25
|
"dependencies": {
|
26
26
|
"@achingbrain/libp2p-gossipsub": "^0.12.2",
|
27
27
|
"@fastify/cors": "^7.0.0",
|
28
|
+
"async-retry": "^1.3.3",
|
28
29
|
"await-spawn": "^4.0.2",
|
29
|
-
"axios": "^0.27.
|
30
|
-
"axios-retry": "^3.2.
|
31
|
-
"bignumber.js": "^9.0.2",
|
30
|
+
"axios": "^0.27.2",
|
31
|
+
"axios-retry": "^3.2.5",
|
32
32
|
"chalk": "4.1.2",
|
33
|
-
"dotenv": "^16.0.
|
33
|
+
"dotenv": "^16.0.1",
|
34
34
|
"ethereumjs-util": "^7.1.4",
|
35
|
-
"ethers": "^5.6.
|
35
|
+
"ethers": "^5.6.5",
|
36
36
|
"ethers-multisend": "^2.1.1",
|
37
37
|
"expand-home-dir": "^0.0.3",
|
38
|
-
"fastify": "^3.
|
38
|
+
"fastify": "^3.29.0",
|
39
|
+
"fs-extra": "^10.1.0",
|
39
40
|
"libp2p": "^0.36.2",
|
40
41
|
"libp2p-bootstrap": "^0.14.0",
|
41
42
|
"libp2p-kad-dht": "^0.28.6",
|
@@ -45,12 +46,12 @@
|
|
45
46
|
"libp2p-pubsub-peer-discovery": "^4.0.0",
|
46
47
|
"libp2p-tcp": "^0.17.2",
|
47
48
|
"libp2p-websockets": "^0.16.2",
|
48
|
-
"luxon": "^2.
|
49
|
+
"luxon": "^2.4.0",
|
49
50
|
"module-alias": "^2.2.2",
|
50
51
|
"patch-package": "^6.4.7",
|
51
52
|
"postinstall-postinstall": "^2.1.0",
|
52
53
|
"sequelize": "6.18.0",
|
53
|
-
"sqlite3": "^5.0.
|
54
|
+
"sqlite3": "^5.0.8",
|
54
55
|
"waait": "^1.0.5"
|
55
56
|
},
|
56
57
|
"bin": {
|
@@ -61,13 +62,13 @@
|
|
61
62
|
"@typechain/ethers-v5": "^10.0.0",
|
62
63
|
"@types/bn.js": "^5.1.0",
|
63
64
|
"@types/fs-extra": "^9.0.13",
|
64
|
-
"@types/node": "^17.0.
|
65
|
-
"nodemon": "^2.0.
|
65
|
+
"@types/node": "^17.0.33",
|
66
|
+
"nodemon": "^2.0.16",
|
66
67
|
"replace-in-file": "^6.3.2",
|
67
68
|
"rimraf": "^3.0.2",
|
68
69
|
"ts-node": "^10.5.0",
|
69
70
|
"tsconfig-paths": "^3.12.0",
|
70
71
|
"typechain": "^8.0.0",
|
71
|
-
"typescript": "^4.
|
72
|
+
"typescript": "^4.6.4"
|
72
73
|
}
|
73
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
|
}
|