@instadapp/interop-x 0.0.0-dev.73da8c9 → 0.0.0-dev.73e5298
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/package.json +18 -16
- 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 +11 -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 +75 -24
- package/dist/src/net/peer/index.js +2 -1
- package/dist/src/net/pool/index.js +18 -2
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +8 -2
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
- package/dist/src/net/protocol/index.js +51 -1
- package/dist/src/tasks/AutoUpdateTask.js +70 -0
- package/dist/src/tasks/BaseTask.js +11 -3
- package/dist/src/tasks/InteropXContract/ProcessBridgeRequestEvents.js +158 -0
- 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 +18 -8
- 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 +62 -47
- package/package.json +18 -16
- 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 +11 -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 +96 -26
- package/src/net/peer/index.ts +2 -1
- package/src/net/pool/index.ts +25 -5
- package/src/net/protocol/dial/SignatureDialProtocol.ts +10 -4
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
- package/src/net/protocol/index.ts +67 -1
- package/src/tasks/AutoUpdateTask.ts +82 -0
- package/src/tasks/BaseTask.ts +13 -3
- package/src/tasks/InteropXContract/ProcessBridgeRequestEvents.ts +226 -0
- 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 +27 -9
- 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 +103 -66
- 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/InteropXGateway/ProcessDepositEvents.js +0 -158
- 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/InteropXGateway/ProcessDepositEvents.ts +0 -253
- 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
@@ -23,13 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
23
|
return result;
|
24
24
|
};
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
exports.
|
26
|
+
exports.InteropXContract__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
|
33
|
-
Object.defineProperty(exports, "
|
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; } });
|
32
|
+
var InteropXContract__factory_1 = require("./factories/InteropXContract__factory");
|
33
|
+
Object.defineProperty(exports, "InteropXContract__factory", { enumerable: true, get: function () { return InteropXContract__factory_1.InteropXContract__factory; } });
|
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.getContract = 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,62 +102,48 @@ 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
|
-
if (transaction.action != 'deposit') {
|
109
|
-
throw new Error('Invalid action');
|
110
|
-
}
|
111
|
-
if (transaction.action === 'deposit' && transaction.sourceStatus === 'pending') {
|
112
|
-
throw Error('Cannot build data for pending deposit transaction');
|
113
|
-
}
|
114
|
-
if (!transaction.submitEvent) {
|
115
|
-
throw Error('Cannot build data for transaction without submitEvent');
|
116
|
-
}
|
117
|
-
const token = constants_1.tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
|
118
|
-
if (!token) {
|
119
|
-
throw Error('Cannot build data for transaction without token');
|
120
|
-
}
|
121
|
-
const itoken = constants_1.itokens[transaction.targetChainId].find(itoken => itoken.symbol.toLowerCase() === token.symbol.toLowerCase());
|
122
|
-
if (!itoken) {
|
123
|
-
throw Error('Cannot build data for transaction without itoken');
|
124
|
-
}
|
125
|
-
const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, exports.getRpcProviderUrl)(transaction.targetChainId));
|
126
|
-
const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
|
127
|
-
const interopBridgeContract = getContract(itoken.address, abi_1.default.interopBridgeToken, targetWallet);
|
128
|
-
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.sourceTransactionHash);
|
129
|
-
transactions.push({
|
130
|
-
to: itoken.address,
|
131
|
-
data: data,
|
132
|
-
value: '0',
|
133
|
-
operation: ethers_multisend_1.OperationType.Call,
|
134
|
-
});
|
135
|
-
return (0, ethers_multisend_1.encodeMulti)(transactions).data;
|
136
|
-
};
|
137
|
-
exports.buildDataForTransaction = buildDataForTransaction;
|
114
|
+
class ContractError extends Error {
|
115
|
+
}
|
116
|
+
exports.ContractError = ContractError;
|
138
117
|
function getContract(address, contractInterface, signerOrProvider) {
|
139
118
|
if (!ethers_1.ethers.utils.getAddress(address) || address === ethers_1.ethers.constants.AddressZero) {
|
140
119
|
throw Error(`Invalid 'address' parameter '${address}'.`);
|
141
120
|
}
|
142
121
|
const contract = new ethers_1.ethers.Contract(address, contractInterface, signerOrProvider);
|
122
|
+
// Make sure the contract properties is writable
|
123
|
+
const desc = Object.getOwnPropertyDescriptor(contract, 'functions');
|
124
|
+
if (!desc || desc.writable !== true) {
|
125
|
+
return contract;
|
126
|
+
}
|
143
127
|
return new Proxy(contract, {
|
144
128
|
get(target, prop, receiver) {
|
145
129
|
const value = Reflect.get(target, prop, receiver);
|
146
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
|
+
}
|
147
137
|
return async (...args) => {
|
148
138
|
try {
|
149
|
-
return await value.bind(contract)(...args);
|
139
|
+
return await (0, async_retry_1.default)(async () => await value.bind(contract)(...args), { retries: isConstant ? 1 : 3 });
|
150
140
|
}
|
151
141
|
catch (error) {
|
152
|
-
|
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;
|
153
147
|
}
|
154
148
|
};
|
155
149
|
}
|
@@ -161,10 +155,14 @@ function getContract(address, contractInterface, signerOrProvider) {
|
|
161
155
|
if (typeof value === 'function') {
|
162
156
|
return async (...args) => {
|
163
157
|
try {
|
164
|
-
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 });
|
165
159
|
}
|
166
160
|
catch (error) {
|
167
|
-
|
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;
|
168
166
|
}
|
169
167
|
};
|
170
168
|
}
|
@@ -176,3 +174,20 @@ function getContract(address, contractInterface, signerOrProvider) {
|
|
176
174
|
});
|
177
175
|
}
|
178
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.73e5298",
|
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,10 +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",
|
51
|
+
"patch-package": "^6.4.7",
|
52
|
+
"postinstall-postinstall": "^2.1.0",
|
49
53
|
"sequelize": "6.18.0",
|
50
|
-
"sqlite3": "^5.0.
|
54
|
+
"sqlite3": "^5.0.8",
|
51
55
|
"waait": "^1.0.5"
|
52
56
|
},
|
53
57
|
"bin": {
|
@@ -58,15 +62,13 @@
|
|
58
62
|
"@typechain/ethers-v5": "^10.0.0",
|
59
63
|
"@types/bn.js": "^5.1.0",
|
60
64
|
"@types/fs-extra": "^9.0.13",
|
61
|
-
"@types/node": "^17.0.
|
62
|
-
"nodemon": "^2.0.
|
63
|
-
"patch-package": "^6.4.7",
|
64
|
-
"postinstall-postinstall": "^2.1.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
|
}
|