@instadapp/interop-x 0.0.0-dev.868731f → 0.0.0-dev.8965b57

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 (80) hide show
  1. package/dist/package.json +8 -7
  2. package/dist/src/abi/index.js +2 -4
  3. package/dist/src/abi/interopXContract.json +391 -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 +3 -3
  8. package/dist/src/constants/index.js +0 -1
  9. package/dist/src/constants/tokens.js +31 -1
  10. package/dist/src/db/models/transaction.js +26 -10
  11. package/dist/src/gnosis/actions/index.js +9 -0
  12. package/dist/src/gnosis/actions/withdraw/index.js +55 -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 +25 -9
  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 +152 -0
  23. package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +77 -0
  24. package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +89 -0
  25. package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +55 -0
  26. package/dist/src/tasks/index.js +15 -8
  27. package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
  28. package/dist/src/typechain/factories/InteropXContract__factory.js +526 -0
  29. package/dist/src/typechain/factories/index.js +3 -5
  30. package/dist/src/typechain/index.js +3 -5
  31. package/dist/src/utils/index.js +32 -42
  32. package/package.json +8 -7
  33. package/src/abi/index.ts +2 -4
  34. package/src/abi/interopXContract.json +391 -0
  35. package/src/alias.ts +6 -0
  36. package/src/api/index.ts +5 -2
  37. package/src/config/index.ts +11 -1
  38. package/src/constants/addresses.ts +3 -3
  39. package/src/constants/index.ts +0 -1
  40. package/src/constants/tokens.ts +32 -2
  41. package/src/db/models/transaction.ts +64 -25
  42. package/src/gnosis/actions/index.ts +5 -0
  43. package/src/gnosis/actions/withdraw/index.ts +76 -0
  44. package/src/gnosis/index.ts +19 -0
  45. package/src/index.ts +96 -26
  46. package/src/net/peer/index.ts +2 -1
  47. package/src/net/pool/index.ts +33 -13
  48. package/src/net/protocol/dial/SignatureDialProtocol.ts +10 -4
  49. package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
  50. package/src/net/protocol/index.ts +67 -1
  51. package/src/tasks/AutoUpdateTask.ts +82 -0
  52. package/src/tasks/BaseTask.ts +13 -3
  53. package/src/tasks/InteropXContract/ProcessBridgeRequestEvents.ts +216 -0
  54. package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +114 -0
  55. package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +120 -0
  56. package/src/tasks/Transactions/SyncTransactionStatusTask.ts +67 -0
  57. package/src/tasks/index.ts +23 -9
  58. package/src/typechain/InteropXContract.ts +524 -0
  59. package/src/typechain/factories/InteropXContract__factory.ts +533 -0
  60. package/src/typechain/factories/index.ts +1 -2
  61. package/src/typechain/index.ts +2 -4
  62. package/src/utils/index.ts +67 -65
  63. package/tsconfig.json +7 -2
  64. package/dist/src/abi/interopBridgeToken.json +0 -286
  65. package/dist/src/abi/interopXGateway.json +0 -184
  66. package/dist/src/constants/itokens.js +0 -13
  67. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +0 -152
  68. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -75
  69. package/dist/src/typechain/InteropXGateway.js +0 -2
  70. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -459
  71. package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
  72. package/src/abi/interopBridgeToken.json +0 -286
  73. package/src/abi/interopXGateway.json +0 -184
  74. package/src/constants/itokens.ts +0 -10
  75. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -247
  76. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -126
  77. package/src/typechain/InteropBridgeToken.ts +0 -686
  78. package/src/typechain/InteropXGateway.ts +0 -407
  79. package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
  80. 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,10 +0,0 @@
1
- export const itokens = {
2
- 1: [],
3
- 137: [
4
- {
5
- address: '0x6c20F03598d5ABF729348E2868b0ff5e8A48aB1F',
6
- symbol: 'USDC',
7
- }
8
- ],
9
- 43114: []
10
- };
@@ -1,247 +0,0 @@
1
- import { BaseTask } from "../BaseTask";
2
- import Logger from '@/logger';
3
- import { BigNumber, ethers } from "ethers";
4
- import abi from "@/abi";
5
- import { Transaction } from "@/db";
6
- import { buildDataForTransaction, buildSignatureBytes, getContract, getRpcProviderUrl, Signature } from "@/utils";
7
- import { addresses } from "@/constants";
8
- import { ChainId } from "@/types";
9
- import config from "@/config";
10
- import { GnosisSafe, InteropXGateway } from "@/typechain";
11
- import { Op } from "sequelize";
12
- import wait from "waait";
13
- import { peerPool, protocol } from "@/net";
14
- import { LogDescription } from "ethers/lib/utils";
15
-
16
- const generateGnosisTransaction = async (transactionData: any, safeContract: GnosisSafe) => {
17
- console.log(transactionData);
18
-
19
- let isExecuted = await safeContract.dataHashes(
20
- await safeContract.getTransactionHash(
21
- transactionData.to,
22
- transactionData.value,
23
- transactionData.data,
24
- transactionData.operation,
25
- transactionData.safeTxGas,
26
- transactionData.baseGas,
27
- transactionData.gasPrice,
28
- transactionData.gasToken,
29
- transactionData.refundReceiver,
30
- transactionData.nonce
31
- )
32
- )
33
-
34
- while (isExecuted == 1) {
35
- transactionData.safeTxGas = BigNumber.from(String(transactionData.safeTxGas)).add(1).toString()
36
-
37
- isExecuted = await safeContract.dataHashes(
38
- await safeContract.getTransactionHash(
39
- transactionData.to,
40
- transactionData.value,
41
- transactionData.data,
42
- transactionData.operation,
43
- transactionData.safeTxGas,
44
- transactionData.baseGas,
45
- transactionData.gasPrice,
46
- transactionData.gasToken,
47
- transactionData.refundReceiver,
48
- transactionData.nonce
49
- )
50
- )
51
- }
52
-
53
- return transactionData
54
- }
55
-
56
- class ProcessDepositEvents extends BaseTask {
57
- contractAddress: string;
58
- provider: ethers.providers.JsonRpcProvider;
59
- contract: InteropXGateway;
60
- chainId: ChainId;
61
- leadNodeOnly = true
62
-
63
- constructor({ chainId }: { chainId: ChainId }) {
64
- super({
65
- logger: new Logger("InteropXGateway::ProcessDepositEvents"),
66
- })
67
- this.chainId = chainId;
68
- }
69
-
70
- async pollHandler() {
71
- const blockNumber = await this.provider.getBlockNumber()
72
-
73
- const transaction = await Transaction.findOne({
74
- where: {
75
- status: 'pending',
76
- sourceStatus: 'success',
77
- targetStatus: 'uninitialised',
78
- action: 'deposit',
79
- sourceCreatedAt: {
80
- [Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
81
- },
82
- sourceBlockNumber: {
83
- [Op.lt]: blockNumber - 12,
84
- },
85
- sourceChainId: this.chainId,
86
- }
87
- })
88
-
89
- if (!transaction) {
90
- return;
91
- }
92
-
93
-
94
- transaction.targetStatus = 'pending';
95
- await transaction.save();
96
-
97
-
98
- // refresh event data?
99
-
100
- const targetChainProvider = new ethers.providers.JsonRpcProvider(
101
- getRpcProviderUrl(transaction.targetChainId as ChainId)
102
- );
103
-
104
- const targetWallet = new ethers.Wallet(config.privateKey!, targetChainProvider);
105
-
106
- const safeAddress = addresses[transaction.targetChainId].gnosisSafe;
107
-
108
-
109
- const safeContract = getContract<GnosisSafe>(
110
- safeAddress,
111
- abi.gnosisSafe,
112
- targetWallet
113
- )
114
-
115
- const ownersThreshold = await safeContract.getThreshold();
116
- await wait(10000);
117
-
118
- let gnosisTx = await generateGnosisTransaction({
119
- baseGas: "0",
120
- data: await buildDataForTransaction(transaction),
121
- gasPrice: "0",
122
- gasToken: "0x0000000000000000000000000000000000000000",
123
- nonce: '0',
124
- operation: "1",
125
- refundReceiver: "0x0000000000000000000000000000000000000000",
126
- safeAddress: safeAddress,
127
- safeTxGas: "79668",
128
- to: addresses[transaction.targetChainId].multisend,
129
- value: "0",
130
- }, safeContract);
131
-
132
- const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
133
-
134
- const ownerPeerIds = peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id)
135
-
136
- console.log(`Collecting signatures for execution ${transaction.transactionHash}`)
137
-
138
- console.log(ownerPeerIds);
139
-
140
- const signatures = await protocol.requestSignatures({
141
- type: 'source',
142
- transactionHash: transaction.transactionHash,
143
- safeTxGas: gnosisTx.safeTxGas,
144
- safeNonce: gnosisTx.nonce
145
- }, ownerPeerIds)
146
-
147
-
148
- const validSignatures = signatures.filter(s => !!s.data && s.data !== '0x') as Signature[];
149
-
150
- console.log({ signatures, validSignatures, ownersThreshold: ownersThreshold.toString() });
151
-
152
- if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
153
- await transaction.save();
154
- transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
155
- transaction.targetStatus = 'pending'
156
-
157
- await transaction.save();
158
- const errorMessage = signatures.find(s => !!s.error)?.error;
159
- throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
160
- }
161
-
162
- const execTransactionParams = [
163
- gnosisTx.to,
164
- gnosisTx.value,
165
- gnosisTx.data,
166
- gnosisTx.operation,
167
- gnosisTx.safeTxGas,
168
- gnosisTx.baseGas,
169
- gnosisTx.gasPrice,
170
- gnosisTx.gasToken,
171
- gnosisTx.refundReceiver,
172
- buildSignatureBytes(validSignatures),
173
- ];
174
-
175
- console.log(`Executing transaction for execution ${transaction.transactionHash}`)
176
-
177
- console.log({
178
- execTransactionParams
179
- })
180
-
181
- const { data: txData } = await safeContract.populateTransaction.execTransaction(
182
- gnosisTx.to,
183
- gnosisTx.value,
184
- gnosisTx.data,
185
- gnosisTx.operation,
186
- gnosisTx.safeTxGas,
187
- gnosisTx.baseGas,
188
- gnosisTx.gasPrice,
189
- gnosisTx.gasToken,
190
- gnosisTx.refundReceiver,
191
- buildSignatureBytes(validSignatures)
192
- );
193
-
194
- console.log({
195
- from: targetWallet.address,
196
- gasPrice: BigNumber.from(120 * 10 ** 9).toString(),
197
- gasLimit: BigNumber.from(6_000_000).toString(),
198
- to: safeAddress,
199
- data: txData,
200
- })
201
- return;
202
-
203
- const txSent = await targetWallet.sendTransaction({
204
- from: targetWallet.address,
205
- gasPrice: BigNumber.from(120 * 10 ** 9),
206
- gasLimit: BigNumber.from(6_000_000),
207
- to: safeAddress,
208
- data: txData,
209
- })
210
-
211
- const receipt = await txSent.wait();
212
-
213
- const parsedLogs: LogDescription[] = [];
214
-
215
- receipt.logs.forEach((log) => {
216
- try {
217
- parsedLogs.push(safeContract.interface.parseLog(log));
218
- } catch (e) { }
219
- });
220
-
221
- if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
222
- console.log('ExecutionSuccess')
223
- } else {
224
- console.log('ExecutionFailure')
225
- }
226
- }
227
-
228
- async start(): Promise<void> {
229
- this.logger.info(`Starting execution watcher on interop chain`);
230
-
231
- this.contractAddress = addresses[this.chainId].interopXGateway;
232
-
233
- this.provider = new ethers.providers.JsonRpcProvider(
234
- getRpcProviderUrl(this.chainId)
235
- );
236
-
237
- this.contract = getContract<InteropXGateway>(
238
- this.contractAddress,
239
- abi.interopXGateway,
240
- new ethers.Wallet(config.privateKey!, this.provider)
241
- );
242
-
243
- await super.start()
244
- }
245
- }
246
-
247
- export default ProcessDepositEvents;
@@ -1,126 +0,0 @@
1
- import { BaseTask } from "../BaseTask";
2
- import Logger from '@/logger';
3
- import { ethers } from "ethers";
4
- import abi from "@/abi";
5
- import { Transaction } from "@/db";
6
- import { generateInteropTransactionHash, getContract, getRpcProviderUrl } from "@/utils";
7
- import { addresses } from "@/constants";
8
- import { ChainId } from "@/types";
9
- import config from "@/config";
10
- import { InteropXGateway } from "@/typechain";
11
-
12
- class SyncDepositEvents extends BaseTask {
13
- contractAddress: string;
14
- provider: ethers.providers.JsonRpcProvider;
15
- contract: InteropXGateway;
16
- chainId: ChainId;
17
-
18
- constructor({ chainId }: { chainId: ChainId }) {
19
- super({
20
- logger: new Logger("InteropXGateway::SyncDepositEvents"),
21
- })
22
- this.chainId = chainId;
23
- }
24
-
25
- async pollHandler() {
26
- const currentBlock = await this.provider.getBlockNumber();
27
-
28
- const events = await this.contract.queryFilter(
29
- this.contract.filters.LogGatewayDeposit(),
30
- currentBlock - 2000,
31
- currentBlock,
32
- );
33
-
34
- let processedEvents = 0;
35
-
36
- for (const event of events) {
37
-
38
- try {
39
- if (!event.args) {
40
- continue;
41
- }
42
-
43
- const { sourceChainId, targetChainId, user, vnonce, amount, token } = event.args;
44
-
45
- const uniqueIdentifier = {
46
- action: 'deposit',
47
- submitTransactionHash: event.transactionHash,
48
- sourceChainId: sourceChainId.toNumber(),
49
- targetChainId: targetChainId.toNumber(),
50
- }
51
-
52
- if (await Transaction.findOne({ where: uniqueIdentifier })) {
53
- continue;
54
- }
55
-
56
- const tx = await event.getTransaction()
57
-
58
- await Transaction.create({
59
- ...uniqueIdentifier,
60
- transactionHash: generateInteropTransactionHash(uniqueIdentifier),
61
- from: tx.from,
62
- to: user,
63
-
64
-
65
- submitTransactionHash: event.transactionHash,
66
- submitBlockNumber: event.blockNumber,
67
-
68
- // submit & source are the same
69
- sourceTransactionHash: event.transactionHash,
70
- sourceBlockNumber: event.blockNumber,
71
- sourceStatus: "success",
72
-
73
- targetStatus: "uninitialised",
74
-
75
- submitEvent: {
76
- user,
77
- sourceChainId: sourceChainId.toString(),
78
- targetChainId: targetChainId.toString(),
79
- token: token,
80
- amount: amount.toString(),
81
- vnonce: vnonce.toString(),
82
- },
83
-
84
- sourceEvent: {
85
- user,
86
- sourceChainId: sourceChainId.toString(),
87
- targetChainId: targetChainId.toString(),
88
- token: token,
89
- amount: amount.toString(),
90
- vnonce: vnonce.toString(),
91
- },
92
- status: "pending",
93
- })
94
-
95
- this.logger.info(
96
- `Execution queued: ${event.transactionHash} ${event.blockNumber}`
97
- );
98
- } catch (error) {
99
- this.logger.error(error);
100
- }
101
- }
102
-
103
- if (processedEvents > 0)
104
- this.logger.info(`${processedEvents} events processed`);
105
- }
106
-
107
- async start(): Promise<void> {
108
- this.logger.info(`Starting execution watcher on interop chain`);
109
-
110
- this.contractAddress = addresses[this.chainId].interopXGateway;
111
-
112
- this.provider = new ethers.providers.JsonRpcProvider(
113
- getRpcProviderUrl(this.chainId)
114
- );
115
-
116
- this.contract = getContract<InteropXGateway>(
117
- this.contractAddress,
118
- abi.interopXGateway,
119
- new ethers.Wallet(config.privateKey!, this.provider)
120
- );
121
-
122
- await super.start()
123
- }
124
- }
125
-
126
- export default SyncDepositEvents;