-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathorbiter.js
71 lines (60 loc) · 2.6 KB
/
orbiter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import * as ethers from "ethers"
import {getAmount} from "./common.js";
const orbiterContract = "0xe4edb277e41dc89ab076a1f049f4a3efa700bce8"
export default class Orbiter {
constructor(privateKey, fromChain, toChain) {
switch (fromChain) {
case 'arbitrum':
this.provider = new ethers.providers.JsonRpcProvider("https://rpc.ankr.com/arbitrum")
break
case 'optimism':
this.provider = new ethers.providers.JsonRpcProvider("https://rpc.ankr.com/optimism")
break
}
this.fromChain = fromChain
this.wallet = new ethers.Wallet(privateKey, this.provider)
this.bridgeCodes = {
ethereum: 9001,
arbitrum: 9002,
polygon: 9006,
optimism: 9007,
zksync: 9014,
bsc: 9015,
nova: 9016,
zkevm: 9017,
base: 9021,
zora: 9030
}
}
async getTxData(value, destinationChain) {
const amount = ethers.utils.parseEther(value.toString()).add(this.bridgeCodes[destinationChain])
const feeData = await this.provider.getFeeData()
return {
type: 2,
chainId: (await this.provider.getNetwork()).chainId,
nonce: await this.wallet.getTransactionCount(),
to: orbiterContract,
value: amount.toString(),
maxFeePerGas: feeData.maxFeePerGas.toString(),
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas.toString()
}
}
async bridge(destinationChain, minAmount, maxAmount) {
const amount = getAmount(minAmount, maxAmount)
if (amount < 0.005 || amount > 5) {
console.error(`[${this.wallet.address}] Лимит отправки 0.005 – 5 ETH | ${amount} ETH`)
} else {
console.info(`${this.wallet.address}: Orbiter ${this.fromChain} –> ${destinationChain} | ${amount} ETH`)
const txData = await this.getTxData(amount, destinationChain)
const balanceEth = ethers.utils.formatEther(await this.wallet.getBalance())
if (amount > balanceEth) {
console.error(`[${this.wallet.address}] Недостаточный баланс`)
} else {
txData.gasLimit = await this.provider.estimateGas(txData)
const signedTx = await this.wallet.signTransaction(txData)
const txResponse = await this.provider.sendTransaction(signedTx)
console.info(`${this.wallet.address}: Отправлено ${txResponse.hash}`)
}
}
}
}