generated from scaffold-eth/scaffold-eth-2
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor vrf deployment script and add useful tasks
- Loading branch information
1 parent
c87a5b4
commit 5556349
Showing
8 changed files
with
109 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// import chalk from "chalk"; | ||
import { task } from "hardhat/config"; | ||
import ERC20_ABI from "@chainlink/contracts/abi/v0.8/ERC20.json"; | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
|
||
/** Get token balance for a given address | ||
* @param accountAddress the address to check | ||
* @param tokenAddress the token address | ||
* | ||
* @returns the token balance in human readable format | ||
*/ | ||
|
||
export async function getTokenBalance(hre: HardhatRuntimeEnvironment, accountAddress: string, tokenAddress: string) { | ||
const { ethers } = hre; | ||
const { provider } = ethers; | ||
|
||
const tokenContract = new ethers.Contract(tokenAddress, ERC20_ABI, provider); | ||
const decimals = await tokenContract.decimals(); | ||
const symbol = await tokenContract.symbol(); | ||
const rawBalance = await tokenContract.balanceOf(accountAddress); | ||
const formattedBalance = ethers.utils.formatUnits(rawBalance, decimals); | ||
|
||
// prettier-ignore | ||
console.log((`Address: ${accountAddress} has ${formattedBalance} ${symbol}`)); | ||
|
||
return formattedBalance; | ||
} | ||
|
||
task("get-token-balance", "Gets the token balance for a given address") | ||
.addParam("account", "The account's address") | ||
.addParam("token", "The token's contract address") | ||
.setAction(async (taskArgs, hre) => { | ||
await getTokenBalance(hre, taskArgs.account, taskArgs.token); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./send-link"; | ||
export * from "./get-token-balance"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { task } from "hardhat/config"; | ||
import ERC20_ABI from "@chainlink/contracts/abi/v0.8/ERC20.json"; | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { networkConfig } from "../helper-hardhat-config"; | ||
|
||
/** Fund a specified address with specified amount of LINK | ||
* | ||
* @param recipientAddress who receives the LINK | ||
* @param amount human readable amount of LINK to send | ||
* | ||
*/ | ||
|
||
export async function sendLink(hre: HardhatRuntimeEnvironment, recipientAddress: string, amount: number) { | ||
if (hre.network.name !== "sepolia") { | ||
throw new Error("This script is only configured for sepolia network"); | ||
} | ||
|
||
const chainId = await hre.ethers.provider.getNetwork().then(network => network.chainId); | ||
const linkTokenAddress = networkConfig[chainId].tokenAddress.LINK; | ||
const [signer] = await hre.ethers.getSigners(); | ||
|
||
console.log("Fetching LINK token contract data..."); | ||
const linkTokenContract = new hre.ethers.Contract(linkTokenAddress, ERC20_ABI, signer); | ||
const decimals = await linkTokenContract.decimals(); | ||
const parsedAmount = hre.ethers.utils.parseUnits(amount.toString(), decimals); | ||
|
||
console.log("Sending transfer transaction..."); | ||
// transfer(address to, uint256 amount) | ||
const transferTx = await linkTokenContract.transfer(recipientAddress, parsedAmount); | ||
console.log("txHash", transferTx.hash); | ||
const transferTxReceipt = await transferTx.wait(); | ||
|
||
if (transferTxReceipt.status !== 1) { | ||
throw new Error("Transfer transaction failed"); | ||
} | ||
|
||
console.log(`Sent ${amount} LINK to ${recipientAddress}`); | ||
} | ||
|
||
task("send-link", "Send a specified amount of link to a specified address") | ||
.addParam("recipient", "The address to send LINK token to") | ||
.addParam("amount", "The human readable amount of LINK to send") | ||
.setAction(async (taskArgs, hre) => { | ||
await sendLink(hre, taskArgs.recipient, taskArgs.amount); | ||
}); |