-
Notifications
You must be signed in to change notification settings - Fork 1
/
hardhat.config.ts
151 lines (128 loc) · 6.79 KB
/
hardhat.config.ts
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import { HardhatUserConfig, task } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import 'hardhat-deploy';
import 'hardhat-deploy-ethers';
import dotenv from 'dotenv';
import {ethers} from "ethers";
dotenv.config();
const config: HardhatUserConfig = {
solidity: "0.8.17",
networks: {
"zk-astar": {
url: `https://rpc.startale.com/astar-zkevm`,
chainId: 3776,
accounts: [process.env.ACCOUNT_PRIVATE_KEY as string],
},
"astar": {
url: "https://evm.astar.network",
chainId: 592,
gas: 10000000, // tx gas limit
accounts: [process.env.ACCOUNT_PRIVATE_KEY as string],
}
},
};
export default config;
const ENDPOINT_ID: { [key: string]: number } = {
"zk-astar": 257,
"astar": 210
}
task("bridge", "Bridge ASTR")
.addParam('quantity', ``)
.addParam('targetNetwork', ``)
.setAction(async (taskArgs, hre) => {
let signers = await hre.ethers.getSigners()
let owner = signers[0]
let nonce = await hre.ethers.provider.getTransactionCount(owner.address)
let toAddress = owner.address;
let qty = BigInt(taskArgs.quantity)
let localContractInstance;
if (taskArgs.targetNetwork === "astar") {
localContractInstance = await hre.ethers.getContractAt("contracts/OFTWithFee.sol:OFTWithFee", "0xdf41220C7e322bFEF933D85D01821ad277f90172", owner)
} else if (taskArgs.targetNetwork === "zk-astar") {
localContractInstance = await hre.ethers.getContractAt("contracts/OFTNativeWithFee.sol:NativeOFTWithFee", "0xdf41220C7e322bFEF933D85D01821ad277f90172", owner)
}
else {
console.log("Invalid targetNetwork")
return
}
// get remote chain id
const remoteChainId = ENDPOINT_ID[taskArgs.targetNetwork]
// quote fee with default adapterParams
let adapterParams = hre.ethers.solidityPacked(["uint16", "uint256"], [1, 100000])
// convert to address to bytes32
let toAddressBytes32 = hre.ethers.AbiCoder.defaultAbiCoder().encode(['address'], [toAddress])
// quote send function
let fees = await localContractInstance.estimateSendFee(remoteChainId, toAddressBytes32, qty, false, adapterParams)
let newFee
// need to add extra value if sending from astar
if (hre.network.name === "astar") {
newFee = fees[0] + qty
}
// define min qty to receive on the destination
let minQty = qty/BigInt(2);
const tx = await localContractInstance.sendFrom(
owner.address, // 'from' address to send tokens
remoteChainId, // remote LayerZero chainId
toAddressBytes32, // 'to' address to send tokens
qty, // amount of tokens to send (in wei)
minQty, // min amount of tokens to send (in wei)
{
refundAddress: owner.address, // refund address (if too much message fee is sent, it gets refunded)
zroPaymentAddress: hre.ethers.ZeroAddress, // address(0x0) if not paying in ZRO (LayerZero Token)
adapterParams: adapterParams // flexible bytes array to indicate messaging adapter services
},
{ value: hre.network.name === "astar" ? newFee : fees[0], gasLimit: 1000000, nonce: nonce++ }
)
console.log(`✅ Message Sent [${hre.network.name}] sendTokens() to OFT @ LZ chainId[${remoteChainId}]`)
console.log(`* check your address [${owner.address}] on the destination chain, in the ERC20 transaction tab !"`)
});
task("BridgeDOT", "Bridge XC20 DOT")
.addParam('quantity', ``)
.addParam('targetNetwork', ``)
.setAction(async (taskArgs, hre) => {
let signers = await hre.ethers.getSigners()
let owner = signers[0]
let nonce = await hre.ethers.provider.getTransactionCount(owner.address)
let toAddress = owner.address;
let qty = BigInt(taskArgs.quantity)
let oftAddress;
let localContractInstance;
if (taskArgs.targetNetwork === "astar") {
oftAddress = "0x7Cb5d4D178d93D59ea0592abF139459957898a59"
localContractInstance = await hre.ethers.getContractAt("contracts/OFTWithFee.sol:OFTWithFee", "0x7Cb5d4D178d93D59ea0592abF139459957898a59", owner)
} else if (taskArgs.targetNetwork === "zk-astar") {
oftAddress = "0x105C0F4a5Eae3bcb4c9Edbb3FD5f6b60FAcc3b36"
localContractInstance = await hre.ethers.getContractAt("contracts/ProxyOFTWithFee.sol:ProxyOFTWithFee", "0x105C0F4a5Eae3bcb4c9Edbb3FD5f6b60FAcc3b36", owner)
}
else {
console.log("Invalid targetNetwork")
return
}
// get remote chain id
const remoteChainId = ENDPOINT_ID[taskArgs.targetNetwork]
// quote fee with default adapterParams
let adapterParams = hre.ethers.solidityPacked(["uint16", "uint256"], [1, 225000 + 300000]) // min gas of OFT + gas for call
// convert to address to bytes32
let toAddressBytes32 = hre.ethers.AbiCoder.defaultAbiCoder().encode(['address'], [toAddress])
// quote send function
let fees = await localContractInstance.estimateSendFee(remoteChainId, toAddressBytes32, qty, false, adapterParams)
if (taskArgs.targetNetwork === "zk-astar") {
let erc20 = await hre.ethers.getContractAt("contracts/OFTWithFee.sol:IERC20", "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF", owner)
await erc20.approve(oftAddress, qty, { gasLimit: 10000000, nonce: nonce++ })
}
const tx = await localContractInstance.sendFrom(
owner.address, // 'from' address to send tokens
remoteChainId, // remote LayerZero chainId
toAddressBytes32, // 'to' address to send tokens
qty, // amount of tokens to send (in wei)
qty, // min amount of tokens to send (in wei)
{
refundAddress: owner.address, // refund address (if too much message fee is sent, it gets refunded)
zroPaymentAddress: hre.ethers.ZeroAddress, // address(0x0) if not paying in ZRO (LayerZero Token)
adapterParams: adapterParams // flexible bytes array to indicate messaging adapter services
},
{ value: fees[0], gasLimit: 10000000, nonce: nonce++ }
)
console.log(`✅ Message Sent [${hre.network.name}] sendTokens() to OFT @ LZ chainId[${remoteChainId}] token:[${toAddress}]`)
console.log(`* check your address [${owner.address}] on the destination chain, in the ERC20 transaction tab !"`)
});