forked from LayerZero-Labs/mainnet-testnet-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswapAndBridge.js
21 lines (17 loc) · 1.03 KB
/
swapAndBridge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const CHAIN_IDS = require("../constants/chainIds.json")
const OFT_ARGS = require("../constants/oftArgs.json")
module.exports = async function (taskArgs, hre) {
const signers = await ethers.getSigners()
const owner = signers[0]
const dstChainId = CHAIN_IDS[taskArgs.targetNetwork]
const amount = ethers.utils.parseEther(taskArgs.amount)
const oft = await ethers.getContract(OFT_ARGS[hre.network.name].contractName)
const bridge = await ethers.getContract("SwappableBridge")
const nativeFee = (await oft.estimateSendFee(dstChainId, owner.address, amount, false, "0x")).nativeFee
const increasedNativeFee = nativeFee.mul(5).div(4) // 20% increase
const gasPrice = await hre.ethers.provider.getGasPrice()
const finalGasPrice = gasPrice.mul(5).div(4)
let tx = await bridge.swapAndBridge(amount, "0", dstChainId, owner.address, owner.address, ethers.constants.AddressZero, "0x", { value: amount.add(increasedNativeFee), gasPrice: finalGasPrice })
console.log(`swapAndBridge tx ${tx.hash}`)
await tx.wait()
}