@instadapp/interop-x 0.0.0-dev.8f86e9f → 0.0.0-dev.9b1fcb8

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.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/interop-x",
3
- "version": "0.0.0-dev.8f86e9f",
3
+ "version": "0.0.0-dev.9b1fcb8",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -5,7 +5,7 @@ exports.itokens = {
5
5
  1: [],
6
6
  137: [
7
7
  {
8
- address: '0x6c20F03598d5ABF729348E2868b0ff5e8A48aB1F',
8
+ address: '0xEab02fe1F016eE3e4106c1C6aad35FeEe657268E',
9
9
  symbol: 'USDC',
10
10
  }
11
11
  ],
package/dist/src/index.js CHANGED
@@ -40,7 +40,7 @@ catch (e) {
40
40
  logger.error('Invalid private key');
41
41
  process.exit(1);
42
42
  }
43
- logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.8f86e9f)`);
43
+ logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.9b1fcb8)`);
44
44
  const tasks_1 = require("@/tasks");
45
45
  const net_1 = require("@/net");
46
46
  const api_1 = require("@/api");
@@ -33,8 +33,15 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
33
33
  error: 'Event not found'
34
34
  };
35
35
  }
36
+ console.log("signing:", {
37
+ to: constants_1.addresses[transaction.targetChainId].multisend,
38
+ data: await (0, utils_1.buildDataForTransaction)(transaction, data.type),
39
+ chainId: transaction.targetChainId,
40
+ safeTxGas: data.safeTxGas,
41
+ nonce: data.safeNonce,
42
+ });
36
43
  const signedData = await (0, utils_1.signGnosisSafeTx)({
37
- to: constants_1.addresses[transaction.sourceChainId].multisend,
44
+ to: constants_1.addresses[transaction.targetChainId].multisend,
38
45
  data: await (0, utils_1.buildDataForTransaction)(transaction, data.type),
39
46
  chainId: transaction.targetChainId,
40
47
  safeTxGas: data.safeTxGas,
@@ -0,0 +1,68 @@
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 config_1 = __importDefault(require("@/config"));
13
+ class SyncWithdrawEvents extends BaseTask_1.BaseTask {
14
+ constructor({ chainId, itokenAddress }) {
15
+ super({
16
+ logger: new logger_1.default("InteropBridgeToken::SyncWithdrawEvents"),
17
+ });
18
+ this.chainId = chainId;
19
+ this.itokenAddress = itokenAddress;
20
+ }
21
+ async pollHandler() {
22
+ const currentBlock = await this.provider.getBlockNumber();
23
+ const events = await this.contract.queryFilter(this.contract.filters.Burn(), currentBlock - 2000, currentBlock);
24
+ let processedEvents = 0;
25
+ for (const event of events) {
26
+ try {
27
+ if (!event.args) {
28
+ continue;
29
+ }
30
+ const { to, amount, chainId } = event.args;
31
+ const uniqueIdentifier = {
32
+ action: 'withdraw',
33
+ submitTransactionHash: event.transactionHash,
34
+ sourceChainId: this.chainId,
35
+ targetChainId: chainId.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, 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
+ to,
45
+ amount: amount.toString(),
46
+ chainId: chainId.toString()
47
+ }, sourceEvent: {
48
+ to,
49
+ amount: amount.toString(),
50
+ chainId: chainId.toString(),
51
+ }, status: "pending" }));
52
+ this.logger.info(`Withdraw queued: ${event.transactionHash} ${event.blockNumber}`);
53
+ }
54
+ catch (error) {
55
+ this.logger.error(error);
56
+ }
57
+ }
58
+ if (processedEvents > 0)
59
+ this.logger.info(`${processedEvents} events processed`);
60
+ }
61
+ async start() {
62
+ this.logger.info(`Starting execution watcher on interop chain`);
63
+ this.provider = new ethers_1.ethers.providers.JsonRpcProvider((0, utils_1.getRpcProviderUrl)(this.chainId));
64
+ this.contract = (0, utils_1.getContract)(this.itokenAddress, abi_1.default.interopBridgeToken, new ethers_1.ethers.Wallet(config_1.default.privateKey, this.provider));
65
+ await super.start();
66
+ }
67
+ }
68
+ exports.default = SyncWithdrawEvents;
@@ -58,6 +58,7 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
58
58
  if (!transaction) {
59
59
  return;
60
60
  }
61
+ console.log(`Processing transaction ${transaction.transactionHash}`);
61
62
  transaction.targetStatus = 'pending';
62
63
  await transaction.save();
63
64
  // refresh event data?
@@ -100,35 +101,17 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
100
101
  const errorMessage = (_a = signatures.find(s => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
101
102
  throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
102
103
  }
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
104
  console.log(`Executing transaction for execution ${transaction.transactionHash}`);
116
- console.log({
117
- execTransactionParams
118
- });
119
105
  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
106
  console.log({
121
107
  from: targetWallet.address,
122
108
  gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9).toString(),
123
- gasLimit: ethers_1.BigNumber.from(6000000).toString(),
124
109
  to: safeAddress,
125
110
  data: txData,
126
111
  });
127
- return;
128
112
  const txSent = await targetWallet.sendTransaction({
129
113
  from: targetWallet.address,
130
114
  gasPrice: ethers_1.BigNumber.from(120 * 10 ** 9),
131
- gasLimit: ethers_1.BigNumber.from(6000000),
132
115
  to: safeAddress,
133
116
  data: txData,
134
117
  });
@@ -142,9 +125,15 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
142
125
  });
143
126
  if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
144
127
  console.log('ExecutionSuccess');
128
+ transaction.targetStatus = 'success';
129
+ transaction.status = 'success';
130
+ await transaction.save();
145
131
  }
146
132
  else {
147
133
  console.log('ExecutionFailure');
134
+ transaction.targetStatus = 'failed';
135
+ transaction.status = 'failed';
136
+ await transaction.save();
148
137
  }
149
138
  }
150
139
  async start() {
@@ -55,7 +55,7 @@ class SyncDepositEvents extends BaseTask_1.BaseTask {
55
55
  amount: amount.toString(),
56
56
  vnonce: vnonce.toString(),
57
57
  }, status: "pending" }));
58
- this.logger.info(`Execution queued: ${event.transactionHash} ${event.blockNumber}`);
58
+ this.logger.info(`Deposit queued: ${event.transactionHash} ${event.blockNumber}`);
59
59
  }
60
60
  catch (error) {
61
61
  this.logger.error(error);
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Tasks = void 0;
7
7
  const ProcessDepositEvents_1 = __importDefault(require("./InteropXGateway/ProcessDepositEvents"));
8
8
  const SyncDepositEvents_1 = __importDefault(require("./InteropXGateway/SyncDepositEvents"));
9
+ const SyncWithdrawEvents_1 = __importDefault(require("./InteropBridge/SyncWithdrawEvents"));
9
10
  class Tasks {
10
11
  constructor() {
11
12
  this.tasks = [
@@ -14,6 +15,10 @@ class Tasks {
14
15
  }),
15
16
  new ProcessDepositEvents_1.default({
16
17
  chainId: 43114
18
+ }),
19
+ new SyncWithdrawEvents_1.default({
20
+ chainId: 137,
21
+ itokenAddress: '0xEab02fe1F016eE3e4106c1C6aad35FeEe657268E',
17
22
  })
18
23
  ];
19
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/interop-x",
3
- "version": "0.0.0-dev.8f86e9f",
3
+ "version": "0.0.0-dev.9b1fcb8",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -2,7 +2,7 @@ export const itokens = {
2
2
  1: [],
3
3
  137: [
4
4
  {
5
- address: '0x6c20F03598d5ABF729348E2868b0ff5e8A48aB1F',
5
+ address: '0xEab02fe1F016eE3e4106c1C6aad35FeEe657268E',
6
6
  symbol: 'USDC',
7
7
  }
8
8
  ],
@@ -47,9 +47,17 @@ export class SignatureDialProtocol extends BaseDialProtocol<ISignatureRequest, I
47
47
  };
48
48
  }
49
49
 
50
+ console.log("signing:", {
51
+ to: addresses[transaction.targetChainId].multisend,
52
+ data: await buildDataForTransaction(transaction, data.type),
53
+ chainId: transaction.targetChainId as ChainId,
54
+ safeTxGas: data.safeTxGas,
55
+ nonce: data.safeNonce,
56
+ });
57
+
50
58
  const signedData = await signGnosisSafeTx({
51
- to: addresses[transaction.sourceChainId].multisend,
52
- data: await buildDataForTransaction(transaction, data.type),
59
+ to: addresses[transaction.targetChainId].multisend,
60
+ data: await buildDataForTransaction(transaction, data.type),
53
61
  chainId: transaction.targetChainId as ChainId,
54
62
  safeTxGas: data.safeTxGas,
55
63
  nonce: data.safeNonce,
@@ -0,0 +1,119 @@
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 SyncWithdrawEvents 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::SyncWithdrawEvents"),
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, chainId } = event.args;
45
+
46
+ const uniqueIdentifier = {
47
+ action: 'withdraw',
48
+ submitTransactionHash: event.transactionHash,
49
+ sourceChainId:this.chainId,
50
+ targetChainId: chainId.toNumber(),
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
+
66
+ submitTransactionHash: event.transactionHash,
67
+ submitBlockNumber: event.blockNumber,
68
+
69
+ // submit & source are the same
70
+ sourceTransactionHash: event.transactionHash,
71
+ sourceBlockNumber: event.blockNumber,
72
+ sourceStatus: "success",
73
+
74
+ targetStatus: "uninitialised",
75
+
76
+ submitEvent: {
77
+ to,
78
+ amount: amount.toString(),
79
+ chainId: chainId.toString()
80
+ },
81
+
82
+ sourceEvent: {
83
+ to,
84
+ amount: amount.toString(),
85
+ chainId: chainId.toString(),
86
+ },
87
+ status: "pending",
88
+ })
89
+
90
+ this.logger.info(
91
+ `Withdraw queued: ${event.transactionHash} ${event.blockNumber}`
92
+ );
93
+ } catch (error) {
94
+ this.logger.error(error);
95
+ }
96
+ }
97
+
98
+ if (processedEvents > 0)
99
+ this.logger.info(`${processedEvents} events processed`);
100
+ }
101
+
102
+ async start(): Promise<void> {
103
+ this.logger.info(`Starting execution watcher on interop chain`);
104
+
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 SyncWithdrawEvents;
@@ -96,11 +96,11 @@ class ProcessDepositEvents extends BaseTask {
96
96
  return;
97
97
  }
98
98
 
99
-
99
+ console.log(`Processing transaction ${transaction.transactionHash}`);
100
+
100
101
  transaction.targetStatus = 'pending';
101
102
  await transaction.save();
102
103
 
103
-
104
104
  // refresh event data?
105
105
 
106
106
  const targetChainProvider = new ethers.providers.JsonRpcProvider(
@@ -165,25 +165,9 @@ class ProcessDepositEvents extends BaseTask {
165
165
  throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
166
166
  }
167
167
 
168
- const execTransactionParams = [
169
- gnosisTx.to,
170
- gnosisTx.value,
171
- gnosisTx.data,
172
- gnosisTx.operation,
173
- gnosisTx.safeTxGas,
174
- gnosisTx.baseGas,
175
- gnosisTx.gasPrice,
176
- gnosisTx.gasToken,
177
- gnosisTx.refundReceiver,
178
- buildSignatureBytes(validSignatures),
179
- ];
180
168
 
181
169
  console.log(`Executing transaction for execution ${transaction.transactionHash}`)
182
170
 
183
- console.log({
184
- execTransactionParams
185
- })
186
-
187
171
  const { data: txData } = await safeContract.populateTransaction.execTransaction(
188
172
  gnosisTx.to,
189
173
  gnosisTx.value,
@@ -200,16 +184,14 @@ class ProcessDepositEvents extends BaseTask {
200
184
  console.log({
201
185
  from: targetWallet.address,
202
186
  gasPrice: BigNumber.from(120 * 10 ** 9).toString(),
203
- gasLimit: BigNumber.from(6_000_000).toString(),
204
187
  to: safeAddress,
205
188
  data: txData,
206
189
  })
207
- return;
190
+
208
191
 
209
192
  const txSent = await targetWallet.sendTransaction({
210
193
  from: targetWallet.address,
211
194
  gasPrice: BigNumber.from(120 * 10 ** 9),
212
- gasLimit: BigNumber.from(6_000_000),
213
195
  to: safeAddress,
214
196
  data: txData,
215
197
  })
@@ -226,8 +208,14 @@ class ProcessDepositEvents extends BaseTask {
226
208
 
227
209
  if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
228
210
  console.log('ExecutionSuccess')
211
+ transaction.targetStatus = 'success'
212
+ transaction.status = 'success'
213
+ await transaction.save();
229
214
  } else {
230
215
  console.log('ExecutionFailure')
216
+ transaction.targetStatus = 'failed'
217
+ transaction.status = 'failed'
218
+ await transaction.save();
231
219
  }
232
220
  }
233
221
 
@@ -93,7 +93,7 @@ class SyncDepositEvents extends BaseTask {
93
93
  })
94
94
 
95
95
  this.logger.info(
96
- `Execution queued: ${event.transactionHash} ${event.blockNumber}`
96
+ `Deposit queued: ${event.transactionHash} ${event.blockNumber}`
97
97
  );
98
98
  } catch (error) {
99
99
  this.logger.error(error);
@@ -1,6 +1,7 @@
1
1
  import { BaseTask } from "./BaseTask";
2
2
  import InteropXGatewayProcessDepositEvents from "./InteropXGateway/ProcessDepositEvents";
3
3
  import InteropXGatewaySyncDepositEvents from "./InteropXGateway/SyncDepositEvents";
4
+ import InteropBridgeSyncWithdrawEvents from "./InteropBridge/SyncWithdrawEvents";
4
5
 
5
6
  export class Tasks {
6
7
 
@@ -11,6 +12,11 @@ export class Tasks {
11
12
 
12
13
  new InteropXGatewayProcessDepositEvents({
13
14
  chainId: 43114
15
+ }),
16
+
17
+ new InteropBridgeSyncWithdrawEvents({
18
+ chainId: 137,
19
+ itokenAddress: '0xEab02fe1F016eE3e4106c1C6aad35FeEe657268E',
14
20
  })
15
21
  ];
16
22