@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.
- package/dist/package.json +18 -16
- package/dist/src/abi/index.js +2 -4
- package/dist/src/abi/interopXContract.json +454 -0
- package/dist/src/alias.js +10 -0
- package/dist/src/api/index.js +6 -3
- package/dist/src/config/index.js +11 -1
- package/dist/src/constants/addresses.js +7 -7
- package/dist/src/constants/index.js +0 -1
- package/dist/src/constants/tokens.js +62 -39
- package/dist/src/db/models/transaction.js +27 -11
- package/dist/src/gnosis/actions/index.js +9 -0
- package/dist/src/gnosis/actions/withdraw/index.js +115 -0
- package/dist/src/gnosis/index.js +20 -0
- package/dist/src/index.js +75 -24
- package/dist/src/net/peer/index.js +2 -1
- package/dist/src/net/pool/index.js +18 -2
- package/dist/src/net/protocol/dial/SignatureDialProtocol.js +8 -2
- package/dist/src/net/protocol/dial/TransactionStatusDialProtocol.js +30 -0
- package/dist/src/net/protocol/index.js +51 -1
- package/dist/src/tasks/AutoUpdateTask.js +70 -0
- package/dist/src/tasks/BaseTask.js +11 -3
- package/dist/src/tasks/InteropXContract/ProcessBridgeRequestEvents.js +158 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeCommittedEvents.js +93 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestEvents.js +78 -0
- package/dist/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.js +90 -0
- package/dist/src/tasks/Transactions/SyncTransactionStatusTask.js +57 -0
- package/dist/src/tasks/index.js +18 -8
- package/dist/src/typechain/{InteropBridgeToken.js → InteropXContract.js} +0 -0
- package/dist/src/typechain/factories/InteropXContract__factory.js +635 -0
- package/dist/src/typechain/factories/index.js +3 -5
- package/dist/src/typechain/index.js +3 -5
- package/dist/src/utils/index.js +62 -47
- package/package.json +18 -16
- package/src/abi/index.ts +2 -4
- package/src/abi/interopXContract.json +454 -0
- package/src/alias.ts +6 -0
- package/src/api/index.ts +5 -2
- package/src/config/index.ts +11 -1
- package/src/constants/addresses.ts +8 -8
- package/src/constants/index.ts +0 -1
- package/src/constants/tokens.ts +63 -40
- package/src/db/models/transaction.ts +76 -27
- package/src/gnosis/actions/index.ts +5 -0
- package/src/gnosis/actions/withdraw/index.ts +155 -0
- package/src/gnosis/index.ts +19 -0
- package/src/index.ts +96 -26
- package/src/net/peer/index.ts +2 -1
- package/src/net/pool/index.ts +25 -5
- package/src/net/protocol/dial/SignatureDialProtocol.ts +10 -4
- package/src/net/protocol/dial/TransactionStatusDialProtocol.ts +33 -0
- package/src/net/protocol/index.ts +67 -1
- package/src/tasks/AutoUpdateTask.ts +82 -0
- package/src/tasks/BaseTask.ts +13 -3
- package/src/tasks/InteropXContract/ProcessBridgeRequestEvents.ts +226 -0
- package/src/tasks/InteropXContract/SyncBridgeCommittedEvents.ts +125 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestEvents.ts +115 -0
- package/src/tasks/InteropXContract/SyncBridgeRequestSentEvents.ts +121 -0
- package/src/tasks/Transactions/SyncTransactionStatusTask.ts +69 -0
- package/src/tasks/index.ts +27 -9
- package/src/typechain/InteropXContract.ts +680 -0
- package/src/typechain/factories/InteropXContract__factory.ts +642 -0
- package/src/typechain/factories/index.ts +1 -2
- package/src/typechain/index.ts +2 -4
- package/src/utils/index.ts +103 -66
- package/tsconfig.json +7 -2
- package/dist/src/abi/interopBridgeToken.json +0 -286
- package/dist/src/abi/interopXGateway.json +0 -184
- package/dist/src/constants/itokens.js +0 -13
- package/dist/src/tasks/InteropXGateway/ProcessDepositEvents.js +0 -158
- package/dist/src/tasks/InteropXGateway/SyncDepositEvents.js +0 -75
- package/dist/src/typechain/InteropXGateway.js +0 -2
- package/dist/src/typechain/factories/InteropBridgeToken__factory.js +0 -459
- package/dist/src/typechain/factories/InteropXGateway__factory.js +0 -265
- package/src/abi/interopBridgeToken.json +0 -286
- package/src/abi/interopXGateway.json +0 -184
- package/src/constants/itokens.ts +0 -10
- package/src/tasks/InteropXGateway/ProcessDepositEvents.ts +0 -253
- package/src/tasks/InteropXGateway/SyncDepositEvents.ts +0 -126
- package/src/typechain/InteropBridgeToken.ts +0 -686
- package/src/typechain/InteropXGateway.ts +0 -407
- package/src/typechain/factories/InteropBridgeToken__factory.ts +0 -466
- package/src/typechain/factories/InteropXGateway__factory.ts +0 -272
@@ -1,253 +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
|
-
targetDelayUntil: {
|
83
|
-
[Op.or]: {
|
84
|
-
[Op.is]: null,
|
85
|
-
[Op.lt]: new Date(),
|
86
|
-
}
|
87
|
-
},
|
88
|
-
sourceBlockNumber: {
|
89
|
-
[Op.lt]: blockNumber - 12,
|
90
|
-
},
|
91
|
-
sourceChainId: this.chainId,
|
92
|
-
}
|
93
|
-
})
|
94
|
-
|
95
|
-
if (!transaction) {
|
96
|
-
return;
|
97
|
-
}
|
98
|
-
|
99
|
-
|
100
|
-
transaction.targetStatus = 'pending';
|
101
|
-
await transaction.save();
|
102
|
-
|
103
|
-
|
104
|
-
// refresh event data?
|
105
|
-
|
106
|
-
const targetChainProvider = new ethers.providers.JsonRpcProvider(
|
107
|
-
getRpcProviderUrl(transaction.targetChainId as ChainId)
|
108
|
-
);
|
109
|
-
|
110
|
-
const targetWallet = new ethers.Wallet(config.privateKey!, targetChainProvider);
|
111
|
-
|
112
|
-
const safeAddress = addresses[transaction.targetChainId].gnosisSafe;
|
113
|
-
|
114
|
-
|
115
|
-
const safeContract = getContract<GnosisSafe>(
|
116
|
-
safeAddress,
|
117
|
-
abi.gnosisSafe,
|
118
|
-
targetWallet
|
119
|
-
)
|
120
|
-
|
121
|
-
const ownersThreshold = await safeContract.getThreshold();
|
122
|
-
await wait(10000);
|
123
|
-
|
124
|
-
let gnosisTx = await generateGnosisTransaction({
|
125
|
-
baseGas: "0",
|
126
|
-
data: await buildDataForTransaction(transaction),
|
127
|
-
gasPrice: "0",
|
128
|
-
gasToken: "0x0000000000000000000000000000000000000000",
|
129
|
-
nonce: '0',
|
130
|
-
operation: "1",
|
131
|
-
refundReceiver: "0x0000000000000000000000000000000000000000",
|
132
|
-
safeAddress: safeAddress,
|
133
|
-
safeTxGas: "79668",
|
134
|
-
to: addresses[transaction.targetChainId].multisend,
|
135
|
-
value: "0",
|
136
|
-
}, safeContract);
|
137
|
-
|
138
|
-
const owners = await safeContract.getOwners().then(owners => owners.map(owner => owner.toLowerCase()));
|
139
|
-
|
140
|
-
const ownerPeerIds = peerPool.activePeers.filter(peer => owners.includes(peer.publicAddress.toLowerCase())).map(peer => peer.id)
|
141
|
-
|
142
|
-
console.log(`Collecting signatures for execution ${transaction.transactionHash}`)
|
143
|
-
|
144
|
-
console.log(ownerPeerIds);
|
145
|
-
|
146
|
-
const signatures = await protocol.requestSignatures({
|
147
|
-
type: 'source',
|
148
|
-
transactionHash: transaction.transactionHash,
|
149
|
-
safeTxGas: gnosisTx.safeTxGas,
|
150
|
-
safeNonce: gnosisTx.nonce
|
151
|
-
}, ownerPeerIds)
|
152
|
-
|
153
|
-
|
154
|
-
const validSignatures = signatures.filter(s => !!s.data && s.data !== '0x') as Signature[];
|
155
|
-
|
156
|
-
console.log({ signatures, validSignatures, ownersThreshold: ownersThreshold.toString() });
|
157
|
-
|
158
|
-
if (validSignatures.length === 0 || ownersThreshold.gt(validSignatures.length)) {
|
159
|
-
await transaction.save();
|
160
|
-
transaction.targetDelayUntil = new Date(Date.now() + 30 * 1000);
|
161
|
-
transaction.targetStatus = 'uninitialised'
|
162
|
-
|
163
|
-
await transaction.save();
|
164
|
-
const errorMessage = signatures.find(s => !!s.error)?.error;
|
165
|
-
throw new Error(`Not enough signatures` + (errorMessage ? `: ${errorMessage}` : ''));
|
166
|
-
}
|
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
|
-
|
181
|
-
console.log(`Executing transaction for execution ${transaction.transactionHash}`)
|
182
|
-
|
183
|
-
console.log({
|
184
|
-
execTransactionParams
|
185
|
-
})
|
186
|
-
|
187
|
-
const { data: txData } = await safeContract.populateTransaction.execTransaction(
|
188
|
-
gnosisTx.to,
|
189
|
-
gnosisTx.value,
|
190
|
-
gnosisTx.data,
|
191
|
-
gnosisTx.operation,
|
192
|
-
gnosisTx.safeTxGas,
|
193
|
-
gnosisTx.baseGas,
|
194
|
-
gnosisTx.gasPrice,
|
195
|
-
gnosisTx.gasToken,
|
196
|
-
gnosisTx.refundReceiver,
|
197
|
-
buildSignatureBytes(validSignatures)
|
198
|
-
);
|
199
|
-
|
200
|
-
console.log({
|
201
|
-
from: targetWallet.address,
|
202
|
-
gasPrice: BigNumber.from(120 * 10 ** 9).toString(),
|
203
|
-
gasLimit: BigNumber.from(6_000_000).toString(),
|
204
|
-
to: safeAddress,
|
205
|
-
data: txData,
|
206
|
-
})
|
207
|
-
return;
|
208
|
-
|
209
|
-
const txSent = await targetWallet.sendTransaction({
|
210
|
-
from: targetWallet.address,
|
211
|
-
gasPrice: BigNumber.from(120 * 10 ** 9),
|
212
|
-
gasLimit: BigNumber.from(6_000_000),
|
213
|
-
to: safeAddress,
|
214
|
-
data: txData,
|
215
|
-
})
|
216
|
-
|
217
|
-
const receipt = await txSent.wait();
|
218
|
-
|
219
|
-
const parsedLogs: LogDescription[] = [];
|
220
|
-
|
221
|
-
receipt.logs.forEach((log) => {
|
222
|
-
try {
|
223
|
-
parsedLogs.push(safeContract.interface.parseLog(log));
|
224
|
-
} catch (e) { }
|
225
|
-
});
|
226
|
-
|
227
|
-
if (parsedLogs.find(e => e.name === 'ExecutionSuccess')) {
|
228
|
-
console.log('ExecutionSuccess')
|
229
|
-
} else {
|
230
|
-
console.log('ExecutionFailure')
|
231
|
-
}
|
232
|
-
}
|
233
|
-
|
234
|
-
async start(): Promise<void> {
|
235
|
-
this.logger.info(`Starting execution watcher on interop chain`);
|
236
|
-
|
237
|
-
this.contractAddress = addresses[this.chainId].interopXGateway;
|
238
|
-
|
239
|
-
this.provider = new ethers.providers.JsonRpcProvider(
|
240
|
-
getRpcProviderUrl(this.chainId)
|
241
|
-
);
|
242
|
-
|
243
|
-
this.contract = getContract<InteropXGateway>(
|
244
|
-
this.contractAddress,
|
245
|
-
abi.interopXGateway,
|
246
|
-
new ethers.Wallet(config.privateKey!, this.provider)
|
247
|
-
);
|
248
|
-
|
249
|
-
await super.start()
|
250
|
-
}
|
251
|
-
}
|
252
|
-
|
253
|
-
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;
|