@instadapp/interop-x 0.0.0-dev.de23e71 → 0.0.0-dev.e33810b

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 (69) hide show
  1. package/dist/package.json +13 -12
  2. package/dist/src/abi/index.js +2 -4
  3. package/dist/src/abi/interopXContract.json +454 -0
  4. package/dist/src/constants/addresses.js +3 -3
  5. package/dist/src/constants/index.js +0 -1
  6. package/dist/src/constants/tokens.js +31 -1
  7. package/dist/src/db/models/transaction.js +19 -11
  8. package/dist/src/gnosis/actions/index.js +0 -2
  9. package/dist/src/gnosis/actions/withdraw/index.js +55 -0
  10. package/dist/src/gnosis/index.js +4 -4
  11. package/dist/src/index.js +4 -2
  12. package/dist/src/net/protocol/dial/SignatureDialProtocol.js +6 -2
  13. package/dist/src/tasks/{InteropBridge/ProcessWithdrawEvents.js → InteropXContract/ProcessBridgeRequestEvents.js} +42 -52
  14. package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
  15. package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +90 -0
  16. package/dist/src/tasks/index.js +13 -30
  17. package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
  18. package/dist/src/typechain/factories/InteropXContract__factory.js +635 -0
  19. package/dist/src/typechain/factories/index.js +3 -5
  20. package/dist/src/typechain/index.js +3 -5
  21. package/dist/src/utils/index.js +37 -8
  22. package/package.json +13 -12
  23. package/src/abi/index.ts +2 -4
  24. package/src/abi/interopXContract.json +454 -0
  25. package/src/constants/addresses.ts +3 -3
  26. package/src/constants/index.ts +0 -1
  27. package/src/constants/tokens.ts +32 -2
  28. package/src/db/models/transaction.ts +58 -27
  29. package/src/gnosis/actions/index.ts +0 -2
  30. package/src/gnosis/actions/withdraw/index.ts +77 -0
  31. package/src/gnosis/index.ts +5 -5
  32. package/src/index.ts +3 -1
  33. package/src/net/protocol/dial/SignatureDialProtocol.ts +6 -2
  34. package/src/tasks/{InteropBridge/ProcessWithdrawEvents.ts → InteropXContract/ProcessBridgeRequestEvents.ts} +66 -99
  35. package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +115 -0
  36. package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +121 -0
  37. package/src/tasks/index.ts +15 -37
  38. package/src/typechain/InteropXContract.ts +680 -0
  39. package/src/typechain/factories/InteropXContract__factory.ts +642 -0
  40. package/src/typechain/factories/index.ts +1 -2
  41. package/src/typechain/index.ts +2 -4
  42. package/src/utils/index.ts +78 -8
  43. package/dist/src/abi/interopBridgeToken.json +0 -298
  44. package/dist/src/abi/interopXGateway.json +0 -184
  45. package/dist/src/constants/itokens.js +0 -13
  46. package/dist/src/gnosis/actions/deposit.js +0 -48
  47. package/dist/src/gnosis/actions/withdraw.js +0 -50
  48. package/dist/src/tasks/InteropBridge/SyncBurnEvents.js +0 -71
  49. package/dist/src/tasks/InteropBridge/SyncMintEvents.js +0 -67
  50. package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +0 -164
  51. package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -74
  52. package/dist/src/tasks/InteropXGateway/SyncWithdrawtEvents.js +0 -72
  53. package/dist/src/typechain/InteropXGateway.js +0 -2
  54. package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -471
  55. package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
  56. package/src/abi/interopBridgeToken.json +0 -298
  57. package/src/abi/interopXGateway.json +0 -184
  58. package/src/constants/itokens.ts +0 -10
  59. package/src/gnosis/actions/deposit.ts +0 -63
  60. package/src/gnosis/actions/withdraw.ts +0 -67
  61. package/src/tasks/InteropBridge/SyncBurnEvents.ts +0 -119
  62. package/src/tasks/InteropBridge/SyncMintEvents.ts +0 -99
  63. package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -260
  64. package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -124
  65. package/src/tasks/InteropXGateway/SyncWithdrawtEvents.ts +0 -105
  66. package/src/typechain/InteropBridgeToken.ts +0 -692
  67. package/src/typechain/InteropXGateway.ts +0 -407
  68. package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -478
  69. 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": "uint32",
39
- "name": "sourceChainId",
40
- "type": "uint32"
41
- },
42
- {
43
- "indexed": true,
44
- "internalType": "uint32",
45
- "name": "targetChainId",
46
- "type": "uint32"
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": "uint32",
76
- "name": "sourceChainId",
77
- "type": "uint32"
78
- },
79
- {
80
- "indexed": false,
81
- "internalType": "uint32",
82
- "name": "targetChainId",
83
- "type": "uint32"
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": "uint32", "name": "chainId_", "type": "uint32" }
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": "uint32", "name": "chainId_", "type": "uint32" }
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": "uint32", "name": "chainId_", "type": "uint32" },
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: '0x62C0045f3277E7067cAcad3c8038eEaBB1Bd92D1',
6
- symbol: 'USDC',
7
- }
8
- ],
9
- 43114: []
10
- };
@@ -1,63 +0,0 @@
1
- import abi from "@/abi";
2
- import config from "@/config";
3
- import { itokens, tokens } from "@/constants";
4
- import { Transaction } from "@/db";
5
- import { InteropBridgeToken } from "@/typechain";
6
- import { ChainId } from "@/types";
7
- import { getContract, getRpcProviderUrl } from "@/utils";
8
- import { ethers } from "ethers";
9
- import { MetaTransaction, OperationType } from "ethers-multisend";
10
-
11
- export default async function (transaction: Transaction, type: 'source' | 'target') {
12
- const transactions: MetaTransaction[] = [];
13
- const logs: any[] = [];
14
-
15
- if (transaction.sourceStatus === 'pending') {
16
- throw Error('Cannot build data for pending deposit transaction');
17
- }
18
-
19
- if (!transaction.submitEvent) {
20
- throw Error('Cannot build data for transaction without submitEvent');
21
- }
22
-
23
-
24
- const token = tokens[transaction.sourceChainId].find(token => token.address.toLowerCase() === transaction.submitEvent.token.toLowerCase());
25
-
26
- if (!token) {
27
- throw Error(`Unsupported token ${transaction.submitEvent.token}`);
28
- }
29
-
30
- const itoken = itokens[transaction.targetChainId].find(t => t.symbol.toLowerCase() === token.symbol.toLowerCase());
31
-
32
- if (!itoken) {
33
- throw Error(`Unsupported itoken ${token.symbol}`);
34
- }
35
-
36
- const targetChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(transaction.targetChainId as ChainId));
37
- const targetWallet = new ethers.Wallet(config.privateKey, targetChainProvider);
38
- const interopBridgeContract = getContract<InteropBridgeToken>(itoken.address, abi.interopBridgeToken, targetWallet);
39
-
40
- const { data } = await interopBridgeContract.populateTransaction.mint(
41
- transaction.submitEvent.user,
42
- ethers.BigNumber.from(transaction.submitEvent.amount.toString()),
43
- ethers.BigNumber.from(transaction.submitEvent.sourceChainId.toString()),
44
- transaction.submitTransactionHash,
45
- );
46
-
47
- transactions.push({
48
- to: itoken.address,
49
- data: data!,
50
- value: '0',
51
- operation: OperationType.Call,
52
- });
53
-
54
- logs.push({
55
- type: 'mint', // mint, approved, burn, transfer, borrow, swap, repay, collected, traded, .....
56
- message: `Minted ${transaction.submitEvent.amount / 10 ** token.decimals} ${token.symbol} to ${transaction.submitEvent.user}`,
57
- })
58
-
59
- return {
60
- transactions,
61
- logs,
62
- }
63
- }
@@ -1,67 +0,0 @@
1
- import abi from "@/abi";
2
- import config from "@/config";
3
- import { addresses, itokens, tokens } from "@/constants";
4
- import { Transaction } from "@/db";
5
- import { InteropXGateway } from "@/typechain";
6
- import { ChainId } from "@/types";
7
- import { getContract, getRpcProviderUrl } from "@/utils";
8
- import { ethers } from "ethers";
9
- import { MetaTransaction, OperationType } from "ethers-multisend";
10
-
11
- export default async function (transaction: Transaction, type: 'source' | 'target') {
12
- const transactions: MetaTransaction[] = [];
13
- const logs: any[] = [];
14
-
15
- if (transaction.action !== 'withdraw') {
16
- throw new Error(`Invalid action: ${transaction.action}`)
17
- }
18
-
19
- if (transaction.action === 'withdraw' && transaction.sourceStatus === 'pending') {
20
- throw Error('Cannot build data for pending withdraw transaction');
21
- }
22
-
23
- if (!transaction.submitEvent) {
24
- throw Error('Cannot build data for transaction without submitEvent');
25
- }
26
-
27
- const { to, amount, sourceChainId, targetChainId, itoken: itokenAddress } = transaction.submitEvent;
28
-
29
- const itoken = itokens[sourceChainId].find(token => token.address.toLowerCase() === itokenAddress.toLowerCase());
30
-
31
- if (!itoken) {
32
- throw Error(`Unsupported itoken ${itokenAddress}`);
33
- }
34
-
35
- const token = tokens[targetChainId].find(t => t.symbol.toLowerCase() === itoken.symbol.toLowerCase());
36
-
37
- if (!token) {
38
- throw Error(`Unsupported token ${itoken.symbol}`);
39
- }
40
-
41
- const targetChainProvider = new ethers.providers.JsonRpcProvider(getRpcProviderUrl(targetChainId as ChainId));
42
- const targetWallet = new ethers.Wallet(config.privateKey, targetChainProvider);
43
- const gatewayAddress = addresses[targetChainId].interopXGateway;
44
- const interopBridgeContract = getContract<InteropXGateway>(gatewayAddress, abi.interopXGateway, targetWallet);
45
-
46
- const { data } = await interopBridgeContract.populateTransaction.systemWithdraw(
47
- ethers.BigNumber.from(amount.toString()),
48
- to,
49
- token.address,
50
- ethers.BigNumber.from(sourceChainId.toString()),
51
- transaction.submitTransactionHash,
52
- );
53
-
54
- transactions.push({
55
- to: gatewayAddress,
56
- data: data!,
57
- value: '0',
58
- operation: OperationType.Call,
59
- });
60
-
61
- logs.push({
62
- type: 'transfer',
63
- message: `Transfer ${amount / 10 ** token.decimals} ${token.symbol} to ${to}`,
64
- })
65
-
66
- return { transactions, logs }
67
- }
@@ -1,119 +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 { ChainId } from "@/types";
8
- import config from "@/config";
9
- import { InteropBridgeToken } from "@/typechain";
10
-
11
- class SyncBurnEvents extends BaseTask {
12
- contractAddress: string;
13
- provider: ethers.providers.JsonRpcProvider;
14
- contract: InteropBridgeToken;
15
- chainId: ChainId;
16
- itokenAddress: string;
17
-
18
- constructor({ chainId, itokenAddress }: { chainId: ChainId, itokenAddress: string }) {
19
- super({
20
- logger: new Logger("InteropBridgeToken::SyncBurnEvents"),
21
- })
22
- this.chainId = chainId;
23
- this.itokenAddress = itokenAddress;
24
- }
25
-
26
- async pollHandler() {
27
- const currentBlock = await this.provider.getBlockNumber();
28
-
29
- const events = await this.contract.queryFilter(
30
- this.contract.filters.Burn(),
31
- currentBlock - 2000,
32
- currentBlock,
33
- );
34
-
35
- let processedEvents = 0;
36
-
37
- for (const event of events) {
38
-
39
- try {
40
- if (!event.args) {
41
- continue;
42
- }
43
-
44
- const { to, amount, sourceChainId, targetChainId } = event.args;
45
-
46
- const uniqueIdentifier = {
47
- action: 'withdraw',
48
- submitTransactionHash: event.transactionHash,
49
- sourceChainId: sourceChainId,
50
- targetChainId: targetChainId,
51
- }
52
-
53
- if (await Transaction.findOne({ where: uniqueIdentifier })) {
54
- continue;
55
- }
56
-
57
- const tx = await event.getTransaction()
58
-
59
- await Transaction.create({
60
- ...uniqueIdentifier,
61
- transactionHash: generateInteropTransactionHash(uniqueIdentifier),
62
- from: tx.from,
63
- to,
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
- targetStatus: "uninitialised",
73
-
74
- submitEvent: {
75
- to,
76
- amount: amount.toString(),
77
- itoken: this.itokenAddress,
78
- sourceChainId: sourceChainId,
79
- targetChainId: targetChainId,
80
- },
81
-
82
- sourceEvent: {
83
- to,
84
- amount: amount.toString(),
85
- itoken: this.itokenAddress,
86
- sourceChainId: sourceChainId,
87
- targetChainId: targetChainId,
88
- },
89
- status: "pending",
90
- })
91
-
92
- this.logger.info(
93
- `Withdraw queued: ${event.transactionHash} ${event.blockNumber}`
94
- );
95
- } catch (error) {
96
- this.logger.error(error);
97
- }
98
- }
99
-
100
- if (processedEvents > 0)
101
- this.logger.info(`${processedEvents} events processed`);
102
- }
103
-
104
- async start(): Promise<void> {
105
- this.provider = new ethers.providers.JsonRpcProvider(
106
- getRpcProviderUrl(this.chainId)
107
- );
108
-
109
- this.contract = getContract<InteropBridgeToken>(
110
- this.itokenAddress,
111
- abi.interopBridgeToken,
112
- new ethers.Wallet(config.privateKey!, this.provider)
113
- );
114
-
115
- await super.start()
116
- }
117
- }
118
-
119
- export default SyncBurnEvents;
@@ -1,99 +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 { getContract, getRpcProviderUrl } from "@/utils";
7
- import { ChainId } from "@/types";
8
- import config from "@/config";
9
- import { InteropBridgeToken } from "@/typechain";
10
-
11
- class SyncMintEvents extends BaseTask {
12
- contractAddress: string;
13
- provider: ethers.providers.JsonRpcProvider;
14
- contract: InteropBridgeToken;
15
- chainId: ChainId;
16
- itokenAddress: string;
17
-
18
- constructor({ chainId, itokenAddress }: { chainId: ChainId, itokenAddress: string }) {
19
- super({
20
- logger: new Logger("InteropBridgeToken::SyncMintEvents"),
21
- })
22
- this.chainId = chainId;
23
- this.itokenAddress = itokenAddress;
24
- }
25
-
26
- async pollHandler() {
27
- const currentBlock = await this.provider.getBlockNumber();
28
-
29
- const events = await this.contract.queryFilter(
30
- this.contract.filters.Mint(),
31
- currentBlock - 500,
32
- currentBlock,
33
- );
34
-
35
- for (const event of events) {
36
-
37
- try {
38
- if (!event.args) {
39
- continue;
40
- }
41
-
42
- const { sourceChainId, targetChainId, amount, to, submitTransactionHash } = event.args;
43
-
44
- const uniqueIdentifier = {
45
- action: 'deposit',
46
- submitTransactionHash: submitTransactionHash,
47
- sourceChainId: sourceChainId,
48
- targetChainId: targetChainId,
49
-
50
- targetEvent: null
51
- }
52
-
53
- const transaction = await Transaction.findOne({ where: uniqueIdentifier });
54
-
55
- if(! transaction){
56
- return;
57
- }
58
-
59
- const tx = await event.getTransaction()
60
-
61
- transaction.targetStatus = 'success'
62
- transaction.targetErrors = []
63
- transaction.targetTransactionHash = tx.hash
64
- transaction.targetEvent = {
65
- sourceChainId,
66
- targetChainId,
67
- amount: amount.toString(),
68
- to,
69
- submitTransactionHash
70
- }
71
- transaction.status = 'success'
72
-
73
- await transaction.save()
74
-
75
- this.logger.info(
76
- `Mint confirmation received: ${transaction.transactionHash} `
77
- );
78
- } catch (error) {
79
- this.logger.error(error);
80
- }
81
- }
82
- }
83
-
84
- async start(): Promise<void> {
85
- this.provider = new ethers.providers.JsonRpcProvider(
86
- getRpcProviderUrl(this.chainId)
87
- );
88
-
89
- this.contract = getContract<InteropBridgeToken>(
90
- this.itokenAddress,
91
- abi.interopBridgeToken,
92
- new ethers.Wallet(config.privateKey!, this.provider)
93
- );
94
-
95
- await super.start()
96
- }
97
- }
98
-
99
- export default SyncMintEvents;