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

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.8a0297a",
3
+ "version": "0.0.0-dev.8f86e9f",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -46,7 +46,7 @@
46
46
  "libp2p-websockets": "^0.16.2",
47
47
  "luxon": "^2.3.2",
48
48
  "module-alias": "^2.2.2",
49
- "sequelize": "^6.19.0",
49
+ "sequelize": "6.18.0",
50
50
  "sqlite3": "^5.0.5",
51
51
  "waait": "^1.0.5"
52
52
  },
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.8a0297a)`);
43
+ logger.debug(`Starting Interop X Node (v${package_json_1.default.version} - rev.8f86e9f)`);
44
44
  const tasks_1 = require("@/tasks");
45
45
  const net_1 = require("@/net");
46
46
  const api_1 = require("@/api");
@@ -101,13 +101,13 @@ class PeerPool {
101
101
  return this.activePeers.map((p) => p.id);
102
102
  }
103
103
  cleanup() {
104
- let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60;
105
- this.peers.forEach((peerInfo) => {
106
- if (peerInfo.updated.getTime() < compDate) {
107
- console.log(`Peer ${peerInfo.id} idle for ${this.PEERS_CLEANUP_TIME_LIMIT} minutes`);
108
- this.remove(peerInfo);
109
- }
110
- });
104
+ // let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
105
+ // this.peers.forEach((peerInfo) => {
106
+ // if (peerInfo.updated.getTime() < compDate) {
107
+ // console.log(`Peer ${peerInfo.id} idle for ${this.PEERS_CLEANUP_TIME_LIMIT} minutes`)
108
+ // this.remove(peerInfo)
109
+ // }
110
+ // })
111
111
  }
112
112
  }
113
113
  exports.PeerPool = PeerPool;
@@ -34,11 +34,11 @@ class SignatureDialProtocol extends BaseDialProtocol_1.BaseDialProtocol {
34
34
  };
35
35
  }
36
36
  const signedData = await (0, utils_1.signGnosisSafeTx)({
37
- //TODO: chain id depends on event type
38
37
  to: constants_1.addresses[transaction.sourceChainId].multisend,
39
- data: (0, utils_1.buildDataForTransaction)(transaction, data.type),
40
- chainId: transaction.sourceChainId,
38
+ data: await (0, utils_1.buildDataForTransaction)(transaction, data.type),
39
+ chainId: transaction.targetChainId,
41
40
  safeTxGas: data.safeTxGas,
41
+ nonce: data.safeNonce,
42
42
  }, { signer });
43
43
  return {
44
44
  signer: signer.address,
@@ -43,6 +43,12 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
43
43
  sourceCreatedAt: {
44
44
  [sequelize_1.Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
45
45
  },
46
+ targetDelayUntil: {
47
+ [sequelize_1.Op.or]: {
48
+ [sequelize_1.Op.is]: null,
49
+ [sequelize_1.Op.lt]: new Date(),
50
+ }
51
+ },
46
52
  sourceBlockNumber: {
47
53
  [sequelize_1.Op.lt]: blockNumber - 12,
48
54
  },
@@ -77,6 +83,7 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
77
83
  const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
78
84
  const ownerPeerIds = net_1.peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id);
79
85
  console.log(`Collecting signatures for execution ${transaction.transactionHash}`);
86
+ console.log(ownerPeerIds);
80
87
  const signatures = await net_1.protocol.requestSignatures({
81
88
  type: 'source',
82
89
  transactionHash: transaction.transactionHash,
@@ -88,7 +95,7 @@ class ProcessDepositEvents extends BaseTask_1.BaseTask {
88
95
  if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
89
96
  await transaction.save();
90
97
  transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
91
- transaction.targetStatus = 'pending';
98
+ transaction.targetStatus = 'uninitialised';
92
99
  await transaction.save();
93
100
  const errorMessage = (_a = signatures.find(s => !!s.error)) === null || _a === void 0 ? void 0 : _a.error;
94
101
  throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
@@ -45,14 +45,14 @@ class SyncDepositEvents extends BaseTask_1.BaseTask {
45
45
  sourceChainId: sourceChainId.toString(),
46
46
  targetChainId: targetChainId.toString(),
47
47
  token: token,
48
- ammout: amount.toString(),
48
+ amount: amount.toString(),
49
49
  vnonce: vnonce.toString(),
50
50
  }, sourceEvent: {
51
51
  user,
52
52
  sourceChainId: sourceChainId.toString(),
53
53
  targetChainId: targetChainId.toString(),
54
54
  token: token,
55
- ammout: amount.toString(),
55
+ amount: amount.toString(),
56
56
  vnonce: vnonce.toString(),
57
57
  }, status: "pending" }));
58
58
  this.logger.info(`Execution queued: ${event.transactionHash} ${event.blockNumber}`);
@@ -125,7 +125,7 @@ const buildDataForTransaction = async (transaction, type) => {
125
125
  const targetChainProvider = new ethers_1.ethers.providers.JsonRpcProvider((0, exports.getRpcProviderUrl)(transaction.targetChainId));
126
126
  const targetWallet = new ethers_1.ethers.Wallet(config_1.default.privateKey, targetChainProvider);
127
127
  const interopBridgeContract = getContract(itoken.address, abi_1.default.interopBridgeToken, targetWallet);
128
- const { data } = await interopBridgeContract.populateTransaction.mint(transaction.submitEvent.user, ethers_1.ethers.BigNumber.from(transaction.submitEvent.amount), transaction.sourceChainId, transaction.sourceTransactionHash);
128
+ const { data } = await interopBridgeContract.populateTransaction.mint(transaction.submitEvent.user, ethers_1.ethers.BigNumber.from(transaction.submitEvent.amount.toString()), ethers_1.ethers.BigNumber.from(transaction.submitEvent.sourceChainId.toString()), transaction.sourceTransactionHash);
129
129
  transactions.push({
130
130
  to: itoken.address,
131
131
  data: data,
@@ -143,10 +143,10 @@ function getContract(address, contractInterface, signerOrProvider) {
143
143
  return new Proxy(contract, {
144
144
  get(target, prop, receiver) {
145
145
  const value = Reflect.get(target, prop, receiver);
146
- if (typeof value === 'function' && contract.functions.hasOwnProperty(prop)) {
146
+ if (typeof value === 'function' && (contract.functions.hasOwnProperty(prop) || ['queryFilter'].includes(String(prop)))) {
147
147
  return async (...args) => {
148
148
  try {
149
- return await value(...args);
149
+ return await value.bind(contract)(...args);
150
150
  }
151
151
  catch (error) {
152
152
  throw new Error(`Error calling "${String(prop)}" on "${address}": ${error.reason || error.message}`);
@@ -161,7 +161,7 @@ function getContract(address, contractInterface, signerOrProvider) {
161
161
  if (typeof value === 'function') {
162
162
  return async (...args) => {
163
163
  try {
164
- return await value(...args);
164
+ return await value.bind(contract)(...args);
165
165
  }
166
166
  catch (error) {
167
167
  throw new Error(`Error calling "${String(prop)}" using "${parentProp}" on "${address}": ${error.reason || error.message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instadapp/interop-x",
3
- "version": "0.0.0-dev.8a0297a",
3
+ "version": "0.0.0-dev.8f86e9f",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -46,7 +46,7 @@
46
46
  "libp2p-websockets": "^0.16.2",
47
47
  "luxon": "^2.3.2",
48
48
  "module-alias": "^2.2.2",
49
- "sequelize": "^6.19.0",
49
+ "sequelize": "6.18.0",
50
50
  "sqlite3": "^5.0.5",
51
51
  "waait": "^1.0.5"
52
52
  },
@@ -124,14 +124,14 @@ export class PeerPool {
124
124
 
125
125
 
126
126
  cleanup() {
127
- let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
128
-
129
- this.peers.forEach((peerInfo) => {
130
- if (peerInfo.updated.getTime() < compDate) {
131
- console.log(`Peer ${peerInfo.id} idle for ${this.PEERS_CLEANUP_TIME_LIMIT} minutes`)
132
- this.remove(peerInfo)
133
- }
134
- })
127
+ // let compDate = Date.now() - this.PEERS_CLEANUP_TIME_LIMIT * 60
128
+
129
+ // this.peers.forEach((peerInfo) => {
130
+ // if (peerInfo.updated.getTime() < compDate) {
131
+ // console.log(`Peer ${peerInfo.id} idle for ${this.PEERS_CLEANUP_TIME_LIMIT} minutes`)
132
+ // this.remove(peerInfo)
133
+ // }
134
+ // })
135
135
  }
136
136
  }
137
137
 
@@ -48,11 +48,11 @@ export class SignatureDialProtocol extends BaseDialProtocol<ISignatureRequest, I
48
48
  }
49
49
 
50
50
  const signedData = await signGnosisSafeTx({
51
- //TODO: chain id depends on event type
52
51
  to: addresses[transaction.sourceChainId].multisend,
53
- data: buildDataForTransaction(transaction, data.type),
54
- chainId: transaction.sourceChainId as ChainId,
52
+ data: await buildDataForTransaction(transaction, data.type),
53
+ chainId: transaction.targetChainId as ChainId,
55
54
  safeTxGas: data.safeTxGas,
55
+ nonce: data.safeNonce,
56
56
  }, { signer });
57
57
 
58
58
  return {
@@ -79,6 +79,12 @@ class ProcessDepositEvents extends BaseTask {
79
79
  sourceCreatedAt: {
80
80
  [Op.gte]: new Date(Date.now() - 12 * 60 * 60 * 1000),
81
81
  },
82
+ targetDelayUntil: {
83
+ [Op.or]: {
84
+ [Op.is]: null,
85
+ [Op.lt]: new Date(),
86
+ }
87
+ },
82
88
  sourceBlockNumber: {
83
89
  [Op.lt]: blockNumber - 12,
84
90
  },
@@ -135,6 +141,8 @@ class ProcessDepositEvents extends BaseTask {
135
141
 
136
142
  console.log(`Collecting signatures for execution ${transaction.transactionHash}`)
137
143
 
144
+ console.log(ownerPeerIds);
145
+
138
146
  const signatures = await protocol.requestSignatures({
139
147
  type: 'source',
140
148
  transactionHash: transaction.transactionHash,
@@ -150,7 +158,7 @@ class ProcessDepositEvents extends BaseTask {
150
158
  if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
151
159
  await transaction.save();
152
160
  transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
153
- transaction.targetStatus = 'pending'
161
+ transaction.targetStatus = 'uninitialised'
154
162
 
155
163
  await transaction.save();
156
164
  const errorMessage = signatures.find(s => !!s.error)?.error;
@@ -77,7 +77,7 @@ class SyncDepositEvents extends BaseTask {
77
77
  sourceChainId: sourceChainId.toString(),
78
78
  targetChainId: targetChainId.toString(),
79
79
  token: token,
80
- ammout: amount.toString(),
80
+ amount: amount.toString(),
81
81
  vnonce: vnonce.toString(),
82
82
  },
83
83
 
@@ -86,7 +86,7 @@ class SyncDepositEvents extends BaseTask {
86
86
  sourceChainId: sourceChainId.toString(),
87
87
  targetChainId: targetChainId.toString(),
88
88
  token: token,
89
- ammout: amount.toString(),
89
+ amount: amount.toString(),
90
90
  vnonce: vnonce.toString(),
91
91
  },
92
92
  status: "pending",
@@ -169,8 +169,8 @@ export const buildDataForTransaction = async (transaction: Transaction, type?: '
169
169
 
170
170
  const { data } = await interopBridgeContract.populateTransaction.mint(
171
171
  transaction.submitEvent.user,
172
- ethers.BigNumber.from(transaction.submitEvent.amount),
173
- transaction.sourceChainId,
172
+ ethers.BigNumber.from(transaction.submitEvent.amount.toString()),
173
+ ethers.BigNumber.from(transaction.submitEvent.sourceChainId.toString()),
174
174
  transaction.sourceTransactionHash,
175
175
  );
176
176
 
@@ -201,10 +201,10 @@ export function getContract<TContract extends ethers.Contract>(address: string,
201
201
  get(target, prop, receiver) {
202
202
  const value = Reflect.get(target, prop, receiver);
203
203
 
204
- if (typeof value === 'function' && contract.functions.hasOwnProperty(prop)) {
204
+ if (typeof value === 'function' && (contract.functions.hasOwnProperty(prop) || ['queryFilter'].includes(String(prop)))) {
205
205
  return async (...args: any[]) => {
206
206
  try {
207
- return await value(...args);
207
+ return await value.bind(contract)(...args);
208
208
  } catch (error) {
209
209
  throw new Error(`Error calling "${String(prop)}" on "${address}": ${error.reason || error.message}`)
210
210
  }
@@ -222,7 +222,7 @@ export function getContract<TContract extends ethers.Contract>(address: string,
222
222
  if (typeof value === 'function') {
223
223
  return async (...args: any[]) => {
224
224
  try {
225
- return await value(...args);
225
+ return await value.bind(contract)(...args);
226
226
  } catch (error) {
227
227
  throw new Error(`Error calling "${String(prop)}" using "${parentProp}" on "${address}": ${error.reason || error.message}`)
228
228
  }