Skip to content

Commit

Permalink
Update 1_deployer_funding.js
Browse files Browse the repository at this point in the history
  • Loading branch information
wcgcyx committed Nov 2, 2023
1 parent f73dec8 commit 9a4b1c8
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions bootstrap/1_deployer_funding.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,21 @@ async function run() {
}

// Execute
console.log("Axelar EOA now has: ", ethers.utils.formatEther(await childProvider.getBalance(axelarEOA)));
console.log("Fund deployer in...");
for (let i = 10; i >= 0; i--) {
console.log(i)
await delay(1000);
}
let feeData = await adminWallet.getFeeData();
let baseFee = feeData.lastBaseFeePerGas;
let gasPrice = feeData.gasPrice;
let priorityFee = Math.round(gasPrice * 150 / 100);
let maxFee = Math.round(1.13 * baseFee + priorityFee);
await wait();

let txn = {
let [priorityFee, maxFee] = await getFee(adminWallet);
let resp = await adminWallet.sendTransaction({
to: axelarEOA,
value: ethers.utils.parseEther(axelarFund),
maxPriorityFeePerGas: priorityFee,
maxFeePerGas: maxFee,
}
let resp = await adminWallet.sendTransaction(txn)

let receipt;
while (receipt == null) {
receipt = await childProvider.getTransactionReceipt(resp.hash)
await delay(1000);
}
console.log(receipt);
})
await waitForReceipt(resp.hash, childProvider);

// Check target balance
let balance = await childProvider.getBalance(axelarEOA)
console.log("Axelar EOA now has: ", ethers.utils.formatEther(balance));
console.log("Axelar EOA now has: ", ethers.utils.formatEther(await childProvider.getBalance(axelarEOA)));
}

run();
Expand All @@ -80,4 +66,33 @@ function hasDuplicates(array) {

function delay(time) {
return new Promise(resolve => setTimeout(resolve, time));
}

async function wait() {
for (let i = 10; i >= 0; i--) {
console.log(i)
await delay(1000);
}
}

async function getFee(adminWallet) {
let feeData = await adminWallet.getFeeData();
let baseFee = feeData.lastBaseFeePerGas;
let gasPrice = feeData.gasPrice;
let priorityFee = Math.round(gasPrice * 150 / 100);
let maxFee = Math.round(1.13 * baseFee + priorityFee);
return [priorityFee, maxFee];
}

async function waitForReceipt(txHash, provider) {
let receipt;
while (receipt == null) {
receipt = await provider.getTransactionReceipt(txHash)
await delay(1000);
}
if (receipt.status != 1) {
throw("Fail to execute");
}
console.log(receipt);
console.log("Succeed.");
}

0 comments on commit 9a4b1c8

Please sign in to comment.