@instadapp/interop-x 0.0.0-dev.73da8c9 → 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 (82) hide show
  1. package/dist/package.json +18 -16
  2. package/dist/src/abi/index.js +2 -4
  3. package/dist/src/abi/interopXContract.json +454 -0
  4. package/dist/src/alias.js +10 -0
  5. package/dist/src/api/index.js +6 -3
  6. package/dist/src/config/index.js +11 -1
  7. package/dist/src/constants/addresses.js +7 -7
  8. package/dist/src/constants/index.js +0 -1
  9. package/dist/src/constants/tokens.js +62 -39
  10. package/dist/src/db/models/transaction.js +27 -11
  11. package/dist/src/gnosis/actions/index.js +9 -0
  12. package/dist/src/gnosis/actions/withdraw/index.js +115 -0
  13. package/dist/src/gnosis/index.js +20 -0
  14. package/dist/src/index.js +75 -24
  15. package/dist/src/net/peer/index.js +2 -1
  16. package/dist/src/net/pool/index.js +18 -2
  17. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +8 -2
  18. package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
  19. package/dist/src/net/protocol/index.js +51 -1
  20. package/dist/src/tasks/AutoUpdateTask.js +70 -0
  21. package/dist/src/tasks/BaseTask.js +11 -3
  22. package/dist/src/tasks/InteropXContract/ProcessBridgeRequestEvents.js +158 -0
  23. package/dist/src/tasks/InteropXContract/SyncBridgeCommittedEvents.js +93 -0
  24. package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
  25. package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +90 -0
  26. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +57 -0
  27. package/dist/src/tasks/index.js +18 -8
  28. package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
  29. package/dist/src/typechain/factories/InteropXContract__factory.js +635 -0
  30. package/dist/src/typechain/factories/index.js +3 -5
  31. package/dist/src/typechain/index.js +3 -5
  32. package/dist/src/utils/index.js +62 -47
  33. package/package.json +18 -16
  34. package/src/abi/index.ts +2 -4
  35. package/src/abi/interopXContract.json +454 -0
  36. package/src/alias.ts +6 -0
  37. package/src/api/index.ts +5 -2
  38. package/src/config/index.ts +11 -1
  39. package/src/constants/addresses.ts +8 -8
  40. package/src/constants/index.ts +0 -1
  41. package/src/constants/tokens.ts +63 -40
  42. package/src/db/models/transaction.ts +76 -27
  43. package/src/gnosis/actions/index.ts +5 -0
  44. package/src/gnosis/actions/withdraw/index.ts +155 -0
  45. package/src/gnosis/index.ts +19 -0
  46. package/src/index.ts +96 -26
  47. package/src/net/peer/index.ts +2 -1
  48. package/src/net/pool/index.ts +25 -5
  49. package/src/net/protocol/dial/SignatureDialProtocol.ts +10 -4
  50. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
  51. package/src/net/protocol/index.ts +67 -1
  52. package/src/tasks/AutoUpdateTask.ts +82 -0
  53. package/src/tasks/BaseTask.ts +13 -3
  54. package/src/tasks/InteropXContract/ProcessBridgeRequestEvents.ts +226 -0
  55. package/src/tasks/InteropXContract/SyncBridgeCommittedEvents.ts +125 -0
  56. package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +115 -0
  57. package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +121 -0
  58. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +69 -0
  59. package/src/tasks/index.ts +27 -9
  60. package/src/typechain/InteropXContract.ts +680 -0
  61. package/src/typechain/factories/InteropXContract__factory.ts +642 -0
  62. package/src/typechain/factories/index.ts +1 -2
  63. package/src/typechain/index.ts +2 -4
  64. package/src/utils/index.ts +103 -66
  65. package/tsconfig.json +7 -2
  66. package/dist/src/abi/interopBridgeToken.json +0 -286
  67. package/dist/src/abi/interopXGateway.json +0 -184
  68. package/dist/src/constants/itokens.js +0 -13
  69. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +0 -158
  70. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -75
  71. package/dist/src/typechain/InteropXGateway.js +0 -2
  72. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -459
  73. package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
  74. package/src/abi/interopBridgeToken.json +0 -286
  75. package/src/abi/interopXGateway.json +0 -184
  76. package/src/constants/itokens.ts +0 -10
  77. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -253
  78. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -126
  79. package/src/typechain/InteropBridgeToken.ts +0 -686
  80. package/src/typechain/InteropXGateway.ts +0 -407
  81. package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
  82. package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -1,184 +0,0 @@
1
- [
2
- {
3
- "inputs": [
4
- { "internalType": "address", "name": "__owner", "type": "address" }
5
- ],
6
- "stateMutability": "nonpayable",
7
- "type": "constructor"
8
- },
9
- {
10
- "anonymous": false,
11
- "inputs": [
12
- {
13
- "indexed": false,
14
- "internalType": "address",
15
- "name": "user",
16
- "type": "address"
17
- },
18
- {
19
- "indexed": true,
20
- "internalType": "address",
21
- "name": "token",
22
- "type": "address"
23
- },
24
- {
25
- "indexed": false,
26
- "internalType": "uint256",
27
- "name": "amount",
28
- "type": "uint256"
29
- },
30
- {
31
- "indexed": true,
32
- "internalType": "uint256",
33
- "name": "vnonce",
34
- "type": "uint256"
35
- },
36
- {
37
- "indexed": false,
38
- "internalType": "uint256",
39
- "name": "sourceChainId",
40
- "type": "uint256"
41
- },
42
- {
43
- "indexed": true,
44
- "internalType": "uint256",
45
- "name": "targetChainId",
46
- "type": "uint256"
47
- }
48
- ],
49
- "name": "LogGatewayDeposit",
50
- "type": "event"
51
- },
52
- {
53
- "anonymous": false,
54
- "inputs": [
55
- {
56
- "indexed": false,
57
- "internalType": "address",
58
- "name": "user",
59
- "type": "address"
60
- },
61
- {
62
- "indexed": true,
63
- "internalType": "address",
64
- "name": "token",
65
- "type": "address"
66
- },
67
- {
68
- "indexed": false,
69
- "internalType": "uint256",
70
- "name": "amount",
71
- "type": "uint256"
72
- },
73
- {
74
- "indexed": true,
75
- "internalType": "uint256",
76
- "name": "sourceChainId",
77
- "type": "uint256"
78
- },
79
- {
80
- "indexed": false,
81
- "internalType": "uint256",
82
- "name": "targetChainId",
83
- "type": "uint256"
84
- },
85
- {
86
- "indexed": true,
87
- "internalType": "bytes32",
88
- "name": "transactionHash",
89
- "type": "bytes32"
90
- }
91
- ],
92
- "name": "LogGatewayWithdraw",
93
- "type": "event"
94
- },
95
- {
96
- "anonymous": false,
97
- "inputs": [
98
- {
99
- "indexed": true,
100
- "internalType": "address",
101
- "name": "previousOwner",
102
- "type": "address"
103
- },
104
- {
105
- "indexed": true,
106
- "internalType": "address",
107
- "name": "newOwner",
108
- "type": "address"
109
- }
110
- ],
111
- "name": "OwnershipTransferred",
112
- "type": "event"
113
- },
114
- {
115
- "inputs": [],
116
- "name": "_vnonce",
117
- "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
118
- "stateMutability": "view",
119
- "type": "function"
120
- },
121
- {
122
- "inputs": [
123
- { "internalType": "address", "name": "token_", "type": "address" },
124
- { "internalType": "uint256", "name": "amount_", "type": "uint256" },
125
- { "internalType": "uint256", "name": "chainId_", "type": "uint256" }
126
- ],
127
- "name": "deposit",
128
- "outputs": [],
129
- "stateMutability": "nonpayable",
130
- "type": "function"
131
- },
132
- {
133
- "inputs": [
134
- { "internalType": "address", "name": "to_", "type": "address" },
135
- { "internalType": "address", "name": "token_", "type": "address" },
136
- { "internalType": "uint256", "name": "amount_", "type": "uint256" },
137
- { "internalType": "uint256", "name": "chainId_", "type": "uint256" }
138
- ],
139
- "name": "depositFor",
140
- "outputs": [],
141
- "stateMutability": "nonpayable",
142
- "type": "function"
143
- },
144
- {
145
- "inputs": [],
146
- "name": "owner",
147
- "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
148
- "stateMutability": "view",
149
- "type": "function"
150
- },
151
- {
152
- "inputs": [],
153
- "name": "renounceOwnership",
154
- "outputs": [],
155
- "stateMutability": "nonpayable",
156
- "type": "function"
157
- },
158
- {
159
- "inputs": [
160
- { "internalType": "uint256", "name": "amount_", "type": "uint256" },
161
- { "internalType": "address", "name": "user_", "type": "address" },
162
- { "internalType": "address", "name": "token_", "type": "address" },
163
- { "internalType": "uint256", "name": "chainId_", "type": "uint256" },
164
- {
165
- "internalType": "bytes32",
166
- "name": "transactionHash_",
167
- "type": "bytes32"
168
- }
169
- ],
170
- "name": "systemWithdraw",
171
- "outputs": [],
172
- "stateMutability": "nonpayable",
173
- "type": "function"
174
- },
175
- {
176
- "inputs": [
177
- { "internalType": "address", "name": "newOwner", "type": "address" }
178
- ],
179
- "name": "transferOwnership",
180
- "outputs": [],
181
- "stateMutability": "nonpayable",
182
- "type": "function"
183
- }
184
- ]
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.itokens = void 0;
4
- exports.itokens = {
5
- 1: [],
6
- 137: [
7
- {
8
- address: '0x6c20F03598d5ABF729348E2868b0ff5e8A48aB1F',
9
- symbol: 'USDC',
10
- }
11
- ],
12
- 43114: []
13
- };
@@ -1,158 +0,0 @@
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
- const BaseTask_1 = require("../BaseTask");
7
- const logger_1 = __importDefault(require("@/logger"));
8
- const ethers_1 = require("ethers");
9
- const abi_1 = __importDefault(require("@/abi"));
10
- const db_1 = require("@/db");
11
- const utils_1 = require("@/utils");
12
- const constants_1 = require("@/constants");
13
- const config_1 = __importDefault(require("@/config"));
14
- const sequelize_1 = require("sequelize");
15
- const waait_1 = __importDefault(require("waait"));
16
- const net_1 = require("@/net");
17
- const generateGnosisTransaction = async (transactionData, safeContract) => {
18
- console.log(transactionData);
19
- 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));
20
- while (isExecuted == 1) {
21
- transactionData.safeTxGas = ethers_1.BigNumber.from(String(transactionData.safeTxGas)).add(1).toString();
22
- 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));
23
- }
24
- return transactionData;
25
- };
26
- class ProcessDepositEvents extends BaseTask_1.BaseTask {
27
- constructor({ chainId }) {
28
- super({
29
- logger: new logger_1.default("InteropXGateway::ProcessDepositEvents"),
30
- });
31
- this.leadNodeOnly = true;
32
- this.chainId = chainId;
33
- }
34
- async pollHandler() {
35
- var _a;
36
- const blockNumber = await this.provider.getBlockNumber();
37
- const transaction = await db_1.Transaction.findOne({
38
- where: {
39
- status: 'pending',
40
- sourceStatus: 'success',
41
- targetStatus: 'uninitialised',
42
- action: 'deposit',
43
- sourceCreatedAt: {
44
- [sequelize_1.Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
45
- },
46
- targetDelayUntil: {
47
- [sequelize_1.Op.or]: {
48
- [sequelize_1.Op.is]: null,
49
- [sequelize_1.Op.lt]: new Date(),
50
- }
51
- },
52
- sourceBlockNumber: {
53
- [sequelize_1.Op.lt]: blockNumber - 12,
54
- },
55
- sourceChainId: this.chainId,
56
- }
57
- });
58
- if (!transaction) {
59
- return;
60
- }
61
- transaction.targetStatus = 'pending';
62
- await transaction.save();
63
- // refresh event data?
64
- const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(transaction.targetChainId));
65
- const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
66
- const safeAddress = constants_1.addresses[transaction.targetChainId].gnosisSafe;
67
- const safeContract = (0, utils_1.getContract)(safeAddress, abi_1.default.gnosisSafe, targetWallet);
68
- const ownersThreshold = await safeContract.getThreshold();
69
- await (0, waait_1.default)(10000);
70
- let gnosisTx = await generateGnosisTransaction({
71
- baseGas: "0",
72
- data: await (0, utils_1.buildDataForTransaction)(transaction),
73
- gasPrice: "0",
74
- gasToken: "0x0000000000000000000000000000000000000000",
75
- nonce: '0',
76
- operation: "1",
77
- refundReceiver: "0x0000000000000000000000000000000000000000",
78
- safeAddress: safeAddress,
79
- safeTxGas: "79668",
80
- to: constants_1.addresses[transaction.targetChainId].multisend,
81
- value: "0",
82
- }, safeContract);
83
- const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
84
- const ownerPeerIds = net_1.peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id);
85
- console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
86
- console.log(ownerPeerIds);
87
- const signatures = await net_1.protocol.requestSignatures({
88
- type: 'source',
89
- transactionHash: transaction.transactionHash,
90
- safeTxGas: gnosisTx.safeTxGas,
91
- safeNonce: gnosisTx.nonce
92
- }, ownerPeerIds);
93
- const validSignatures = signatures.filter(s => !!s.data && s.data !== '0x');
94
- console.log({ signatures, validSignatures, ownersThreshold: ownersThreshold.toString() });
95
- if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
96
- await transaction.save();
97
- transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
98
- transaction.targetStatus = 'uninitialised';
99
- await transaction.save();
100
- const errorMessage = (_a = signatures.find(s => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
101
- throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
102
- }
103
- const execTransactionParams = [
104
- gnosisTx.to,
105
- gnosisTx.value,
106
- gnosisTx.data,
107
- gnosisTx.operation,
108
- gnosisTx.safeTxGas,
109
- gnosisTx.baseGas,
110
- gnosisTx.gasPrice,
111
- gnosisTx.gasToken,
112
- gnosisTx.refundReceiver,
113
- (0, utils_1.buildSignatureBytes)(validSignatures),
114
- ];
115
- console.log(`Executing transaction for execution ${transaction.transactionHash}`);
116
- console.log({
117
- execTransactionParams
118
- });
119
- const { data: txData } = await safeContract.populateTransaction.execTransaction(gnosisTx.to, gnosisTx.value, gnosisTx.data, gnosisTx.operation, gnosisTx.safeTxGas, gnosisTx.baseGas, gnosisTx.gasPrice, gnosisTx.gasToken, gnosisTx.refundReceiver, (0, utils_1.buildSignatureBytes)(validSignatures));
120
- console.log({
121
- from: targetWallet.address,
122
- gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9).toString(),
123
- gasLimit: ethers_1.BigNumber.from(6000000).toString(),
124
- to: safeAddress,
125
- data: txData,
126
- });
127
- return;
128
- const txSent = await targetWallet.sendTransaction({
129
- from: targetWallet.address,
130
- gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9),
131
- gasLimit: ethers_1.BigNumber.from(6000000),
132
- to: safeAddress,
133
- data: txData,
134
- });
135
- const receipt = await txSent.wait();
136
- const parsedLogs = [];
137
- receipt.logs.forEach((log) => {
138
- try {
139
- parsedLogs.push(safeContract.interface.parseLog(log));
140
- }
141
- catch (e) { }
142
- });
143
- if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
144
- console.log('ExecutionSuccess');
145
- }
146
- else {
147
- console.log('ExecutionFailure');
148
- }
149
- }
150
- async start() {
151
- this.logger.info(`Starting execution watcher on interop chain`);
152
- this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
153
- this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
154
- this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
155
- await super.start();
156
- }
157
- }
158
- exports.default = ProcessDepositEvents;
@@ -1,75 +0,0 @@
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
- const BaseTask_1 = require("../BaseTask");
7
- const logger_1 = __importDefault(require("@/logger"));
8
- const ethers_1 = require("ethers");
9
- const abi_1 = __importDefault(require("@/abi"));
10
- const db_1 = require("@/db");
11
- const utils_1 = require("@/utils");
12
- const constants_1 = require("@/constants");
13
- const config_1 = __importDefault(require("@/config"));
14
- class SyncDepositEvents extends BaseTask_1.BaseTask {
15
- constructor({ chainId }) {
16
- super({
17
- logger: new logger_1.default("InteropXGateway::SyncDepositEvents"),
18
- });
19
- this.chainId = chainId;
20
- }
21
- async pollHandler() {
22
- const currentBlock = await this.provider.getBlockNumber();
23
- const events = await this.contract.queryFilter(this.contract.filters.LogGatewayDeposit(), currentBlock - 2000, currentBlock);
24
- let processedEvents = 0;
25
- for (const event of events) {
26
- try {
27
- if (!event.args) {
28
- continue;
29
- }
30
- const { sourceChainId, targetChainId, user, vnonce, amount, token } = event.args;
31
- const uniqueIdentifier = {
32
- action: 'deposit',
33
- submitTransactionHash: event.transactionHash,
34
- sourceChainId: sourceChainId.toNumber(),
35
- targetChainId: targetChainId.toNumber(),
36
- };
37
- if (await db_1.Transaction.findOne({ where: uniqueIdentifier })) {
38
- continue;
39
- }
40
- const tx = await event.getTransaction();
41
- await db_1.Transaction.create(Object.assign(Object.assign({}, uniqueIdentifier), { transactionHash: (0, utils_1.generateInteropTransactionHash)(uniqueIdentifier), from: tx.from, to: user, submitTransactionHash: event.transactionHash, submitBlockNumber: event.blockNumber,
42
- // submit & source are the same
43
- sourceTransactionHash: event.transactionHash, sourceBlockNumber: event.blockNumber, sourceStatus: "success", targetStatus: "uninitialised", submitEvent: {
44
- user,
45
- sourceChainId: sourceChainId.toString(),
46
- targetChainId: targetChainId.toString(),
47
- token: token,
48
- amount: amount.toString(),
49
- vnonce: vnonce.toString(),
50
- }, sourceEvent: {
51
- user,
52
- sourceChainId: sourceChainId.toString(),
53
- targetChainId: targetChainId.toString(),
54
- token: token,
55
- amount: amount.toString(),
56
- vnonce: vnonce.toString(),
57
- }, status: "pending" }));
58
- this.logger.info(`Execution queued: ${event.transactionHash} ${event.blockNumber}`);
59
- }
60
- catch (error) {
61
- this.logger.error(error);
62
- }
63
- }
64
- if (processedEvents > 0)
65
- this.logger.info(`${processedEvents} events processed`);
66
- }
67
- async start() {
68
- this.logger.info(`Starting execution watcher on interop chain`);
69
- this.contractAddress = constants_1.addresses[this.chainId].interopXGateway;
70
- this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
71
- this.contract = (0, utils_1.getContract)(this.contractAddress, abi_1.default.interopXGateway, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
72
- await super.start();
73
- }
74
- }
75
- exports.default = SyncDepositEvents;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });