@instadapp/interop-x 0.0.0-dev.6ea4ee5 → 0.0.0-dev.73e5298

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.
Files changed (99) hide show
  1. package/bin/interop-x +1 -1
  2. package/dist/package.json +74 -0
  3. package/dist/{abi → src/abi}/erc20.json +0 -0
  4. package/dist/{abi → src/abi}/gnosisSafe.json +0 -0
  5. package/dist/{abi → src/abi}/index.js +2 -4
  6. package/dist/src/abi/interopXContract.json +454 -0
  7. package/dist/src/alias.js +10 -0
  8. package/dist/src/api/index.js +36 -0
  9. package/dist/{config → src/config}/index.js +11 -1
  10. package/dist/src/constants/addresses.js +20 -0
  11. package/dist/{constants → src/constants}/index.js +0 -0
  12. package/dist/{constants → src/constants}/tokens.js +62 -39
  13. package/dist/{db → src/db}/index.js +0 -0
  14. package/dist/{db → src/db}/models/index.js +0 -0
  15. package/dist/{db → src/db}/models/transaction.js +27 -9
  16. package/dist/{db → src/db}/sequelize.js +1 -1
  17. package/dist/src/gnosis/actions/index.js +9 -0
  18. package/dist/src/gnosis/actions/withdraw/index.js +115 -0
  19. package/dist/src/gnosis/index.js +20 -0
  20. package/dist/src/index.js +119 -0
  21. package/dist/{logger → src/logger}/index.js +0 -0
  22. package/dist/{net → src/net}/index.js +0 -0
  23. package/dist/{net → src/net}/peer/index.js +8 -3
  24. package/dist/{net → src/net}/pool/index.js +32 -9
  25. package/dist/{net → src/net}/protocol/dial/BaseDialProtocol.js +0 -0
  26. package/dist/{net → src/net}/protocol/dial/SignatureDialProtocol.js +21 -12
  27. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
  28. package/dist/{net → src/net}/protocol/index.js +51 -1
  29. package/dist/src/tasks/AutoUpdateTask.js +70 -0
  30. package/dist/{tasks → src/tasks}/BaseTask.js +12 -4
  31. package/dist/src/tasks/InteropXContract/ProcessBridgeRequestEvents.js +158 -0
  32. package/dist/src/tasks/InteropXContract/SyncBridgeCommittedEvents.js +93 -0
  33. package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
  34. package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +90 -0
  35. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +57 -0
  36. package/dist/src/tasks/index.js +41 -0
  37. package/dist/{typechain → src/typechain}/Erc20.js +0 -0
  38. package/dist/{typechain → src/typechain}/GnosisSafe.js +0 -0
  39. package/dist/{typechain/InteropBridgeToken.js → src/typechain/InteropXContract.js} +0 -0
  40. package/dist/{typechain → src/typechain}/common.js +0 -0
  41. package/dist/{typechain → src/typechain}/factories/Erc20__factory.js +0 -0
  42. package/dist/{typechain → src/typechain}/factories/GnosisSafe__factory.js +0 -0
  43. package/dist/src/typechain/factories/InteropXContract__factory.js +635 -0
  44. package/dist/src/typechain/factories/index.js +12 -0
  45. package/dist/{typechain → src/typechain}/index.js +3 -5
  46. package/dist/{types.js → src/types.js} +0 -0
  47. package/dist/src/utils/index.js +193 -0
  48. package/package.json +23 -15
  49. package/patches/@ethersproject+properties+5.6.0.patch +13 -0
  50. package/src/abi/index.ts +2 -4
  51. package/src/abi/interopXContract.json +454 -0
  52. package/src/alias.ts +6 -0
  53. package/src/api/index.ts +36 -0
  54. package/src/config/index.ts +11 -1
  55. package/src/constants/addresses.ts +8 -16
  56. package/src/constants/tokens.ts +63 -40
  57. package/src/db/models/transaction.ts +78 -25
  58. package/src/db/sequelize.ts +1 -1
  59. package/src/gnosis/actions/index.ts +5 -0
  60. package/src/gnosis/actions/withdraw/index.ts +155 -0
  61. package/src/gnosis/index.ts +19 -0
  62. package/src/index.ts +101 -24
  63. package/src/net/peer/index.ts +9 -7
  64. package/src/net/pool/index.ts +41 -11
  65. package/src/net/protocol/dial/SignatureDialProtocol.ts +23 -13
  66. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
  67. package/src/net/protocol/index.ts +67 -1
  68. package/src/tasks/AutoUpdateTask.ts +82 -0
  69. package/src/tasks/BaseTask.ts +14 -4
  70. package/src/tasks/InteropXContract/ProcessBridgeRequestEvents.ts +226 -0
  71. package/src/tasks/InteropXContract/SyncBridgeCommittedEvents.ts +125 -0
  72. package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +115 -0
  73. package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +121 -0
  74. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +69 -0
  75. package/src/tasks/index.ts +28 -5
  76. package/src/typechain/InteropXContract.ts +680 -0
  77. package/src/typechain/factories/InteropXContract__factory.ts +642 -0
  78. package/src/typechain/factories/index.ts +1 -2
  79. package/src/typechain/index.ts +2 -4
  80. package/src/utils/index.ts +153 -7
  81. package/tsconfig.json +7 -2
  82. package/dist/abi/interopBridgeToken.json +0 -286
  83. package/dist/abi/interopXGateway.json +0 -184
  84. package/dist/constants/addresses.js +0 -28
  85. package/dist/index.js +0 -63
  86. package/dist/tasks/InteropXGateway/SyncDepositEvents.js +0 -79
  87. package/dist/tasks/index.js +0 -27
  88. package/dist/typechain/InteropXGateway.js +0 -2
  89. package/dist/typechain/factories/InteropBridgeToken__factory.js +0 -459
  90. package/dist/typechain/factories/InteropXGateway__factory.js +0 -265
  91. package/dist/typechain/factories/index.js +0 -14
  92. package/dist/utils/index.js +0 -101
  93. package/src/abi/interopBridgeToken.json +0 -286
  94. package/src/abi/interopXGateway.json +0 -184
  95. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -114
  96. package/src/typechain/InteropBridgeToken.ts +0 -686
  97. package/src/typechain/InteropXGateway.ts +0 -407
  98. package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
  99. package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -0,0 +1,193 @@
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.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
+ /**
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
+ exports.http = axios_1.default.create();
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;
27
+ function short(buffer) {
28
+ return buffer.toString('hex').slice(0, 8) + '...';
29
+ }
30
+ exports.short = short;
31
+ 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 }) => {
32
+ const gnosisSafe = constants_1.addresses[chainId].gnosisSafe;
33
+ const domain = {
34
+ verifyingContract: gnosisSafe,
35
+ chainId,
36
+ };
37
+ const types = {
38
+ SafeTx: [
39
+ { type: 'address', name: 'to' },
40
+ { type: 'uint256', name: 'value' },
41
+ { type: 'bytes', name: 'data' },
42
+ { type: 'uint8', name: 'operation' },
43
+ { type: 'uint256', name: 'safeTxGas' },
44
+ { type: 'uint256', name: 'baseGas' },
45
+ { type: 'uint256', name: 'gasPrice' },
46
+ { type: 'address', name: 'gasToken' },
47
+ { type: 'address', name: 'refundReceiver' },
48
+ { type: 'uint256', name: 'nonce' },
49
+ ],
50
+ };
51
+ const message = {
52
+ baseGas,
53
+ data,
54
+ gasPrice,
55
+ gasToken,
56
+ nonce: Number(nonce),
57
+ operation,
58
+ refundReceiver,
59
+ safeAddress: gnosisSafe,
60
+ safeTxGas: String(safeTxGas),
61
+ to,
62
+ value,
63
+ };
64
+ return await signer._signTypedData(domain, types, message);
65
+ };
66
+ exports.signGnosisSafeTx = signGnosisSafeTx;
67
+ const getRpcProviderUrl = (chainId) => {
68
+ switch (chainId) {
69
+ case 1:
70
+ return 'https://rpc.ankr.com/eth';
71
+ case 137:
72
+ return 'https://rpc.ankr.com/polygon';
73
+ case 43114:
74
+ return 'https://rpc.ankr.com/avalanche';
75
+ default:
76
+ throw new Error(`Unknown chainId: ${chainId}`);
77
+ }
78
+ };
79
+ exports.getRpcProviderUrl = getRpcProviderUrl;
80
+ const buildSignatureBytes = (signatures) => {
81
+ signatures.sort((left, right) => left.signer.toLowerCase().localeCompare(right.signer.toLowerCase()));
82
+ let signatureBytes = "0x";
83
+ for (const sig of signatures) {
84
+ signatureBytes += sig.data.slice(2);
85
+ }
86
+ return signatureBytes;
87
+ };
88
+ exports.buildSignatureBytes = buildSignatureBytes;
89
+ /**
90
+ * Call an async function with a maximum time limit (in milliseconds) for the timeout
91
+ * Resolved promise for async function call, or an error if time limit reached
92
+ */
93
+ const asyncCallWithTimeout = async (asyncPromise, timeout) => {
94
+ let timeoutHandle;
95
+ const timeoutPromise = new Promise((_resolve, reject) => {
96
+ timeoutHandle = setTimeout(() => reject(new Error('Async call timeout limit reached')), timeout);
97
+ });
98
+ return Promise.race([asyncPromise, timeoutPromise]).then(result => {
99
+ clearTimeout(timeoutHandle);
100
+ return result;
101
+ });
102
+ };
103
+ exports.asyncCallWithTimeout = asyncCallWithTimeout;
104
+ const generateInteropTransactionHash = (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),
109
+ String(data.sourceChainId),
110
+ String(data.targetChainId),
111
+ ]);
112
+ };
113
+ exports.generateInteropTransactionHash = generateInteropTransactionHash;
114
+ class ContractError extends Error {
115
+ }
116
+ exports.ContractError = ContractError;
117
+ function getContract(address, contractInterface, signerOrProvider) {
118
+ if (!ethers_1.ethers.utils.getAddress(address) || address === ethers_1.ethers.constants.AddressZero) {
119
+ throw Error(`Invalid 'address' parameter '${address}'.`);
120
+ }
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
+ }
127
+ return new Proxy(contract, {
128
+ get(target, prop, receiver) {
129
+ const value = Reflect.get(target, prop, receiver);
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
+ }
137
+ return async (...args) => {
138
+ try {
139
+ return await (0, async_retry_1.default)(async () => await value.bind(contract)(...args), { retries: isConstant ? 1 : 3 });
140
+ }
141
+ catch (error) {
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;
147
+ }
148
+ };
149
+ }
150
+ if (typeof value === 'object' && ['populateTransaction', 'estimateGas', 'functions', 'callStatic'].includes(String(prop))) {
151
+ const parentProp = String(prop);
152
+ return new Proxy(value, {
153
+ get(target, prop, receiver) {
154
+ const value = Reflect.get(target, prop, receiver);
155
+ if (typeof value === 'function') {
156
+ return async (...args) => {
157
+ try {
158
+ return await (0, async_retry_1.default)(async () => await value.bind(contract)(...args), { retries: parentProp === 'callStatic' ? 3 : 1 });
159
+ }
160
+ catch (error) {
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;
166
+ }
167
+ };
168
+ }
169
+ }
170
+ });
171
+ }
172
+ return value;
173
+ },
174
+ });
175
+ }
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.6ea4ee5",
3
+ "version": "0.0.0-dev.73e5298",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -11,8 +11,9 @@
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'",
15
- "prepublishOnly": "yarn build"
14
+ "generate-abi-types": "rimraf src/typechain && typechain --target=ethers-v5 'src/abi/*.json' --out-dir 'src/typechain'",
15
+ "prepublishOnly": "yarn build",
16
+ "postinstall": "patch-package"
16
17
  },
17
18
  "nodemonConfig": {
18
19
  "watch": [
@@ -23,15 +24,19 @@
23
24
  },
24
25
  "dependencies": {
25
26
  "@achingbrain/libp2p-gossipsub": "^0.12.2",
26
- "axios": "^0.27.1",
27
- "axios-retry": "^3.2.4",
28
- "bignumber.js": "^9.0.2",
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",
29
32
  "chalk": "4.1.2",
30
- "dotenv": "^16.0.0",
33
+ "dotenv": "^16.0.1",
31
34
  "ethereumjs-util": "^7.1.4",
32
- "ethers": "^5.6.4",
35
+ "ethers": "^5.6.5",
33
36
  "ethers-multisend": "^2.1.1",
34
37
  "expand-home-dir": "^0.0.3",
38
+ "fastify": "^3.29.0",
39
+ "fs-extra": "^10.1.0",
35
40
  "libp2p": "^0.36.2",
36
41
  "libp2p-bootstrap": "^0.14.0",
37
42
  "libp2p-kad-dht": "^0.28.6",
@@ -41,26 +46,29 @@
41
46
  "libp2p-pubsub-peer-discovery": "^4.0.0",
42
47
  "libp2p-tcp": "^0.17.2",
43
48
  "libp2p-websockets": "^0.16.2",
44
- "luxon": "^2.3.2",
49
+ "luxon": "^2.4.0",
45
50
  "module-alias": "^2.2.2",
46
- "sequelize": "^6.19.0",
47
- "sqlite3": "^5.0.5",
51
+ "patch-package": "^6.4.7",
52
+ "postinstall-postinstall": "^2.1.0",
53
+ "sequelize": "6.18.0",
54
+ "sqlite3": "^5.0.8",
48
55
  "waait": "^1.0.5"
49
56
  },
50
57
  "bin": {
51
- "interop-node": "bin/interop-x"
58
+ "interop-x": "bin/interop-x",
59
+ "interopx": "bin/interop-x"
52
60
  },
53
61
  "devDependencies": {
54
62
  "@typechain/ethers-v5": "^10.0.0",
55
63
  "@types/bn.js": "^5.1.0",
56
64
  "@types/fs-extra": "^9.0.13",
57
- "@types/node": "^17.0.17",
58
- "nodemon": "^2.0.15",
65
+ "@types/node": "^17.0.33",
66
+ "nodemon": "^2.0.16",
59
67
  "replace-in-file": "^6.3.2",
60
68
  "rimraf": "^3.0.2",
61
69
  "ts-node": "^10.5.0",
62
70
  "tsconfig-paths": "^3.12.0",
63
71
  "typechain": "^8.0.0",
64
- "typescript": "^4.5.5"
72
+ "typescript": "^4.6.4"
65
73
  }
66
74
  }
@@ -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;
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 interopXGateway from "./interopXGateway.json";
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
- interopXGateway,
10
- interopBridgeToken,
8
+ interopXContract,
11
9
  }