From 1afacf08e082c9f94ff542e80b5cf5d8149c540d Mon Sep 17 00:00:00 2001 From: bt3gl <1130416+bt3gl@users.noreply.github.com> Date: Tue, 4 Oct 2022 08:31:09 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=93=20add=20function=20to=20set=20USDC?= =?UTF-8?q?=20balance=20by=20jambro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hardhat/set_usdc_balance.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 hardhat/set_usdc_balance.js diff --git a/hardhat/set_usdc_balance.js b/hardhat/set_usdc_balance.js new file mode 100644 index 0000000..ccab353 --- /dev/null +++ b/hardhat/set_usdc_balance.js @@ -0,0 +1,28 @@ +// function to set USDC balance of ethereum mainnet forks by @janbro + + +const { ethers } = require("hardhat"); + +async function setUSDCBalance(account, balance) { + const balances_index = 9; + const USDC_ADDRESS = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; // ETH mainnet USDC address + + // modify usdc's storage to give rich account large amount of tokens + const index = ethers.utils.solidityKeccak256( + ["uint256", "uint256"], + [account, balances_index] // key, slot + ); + + await await ethers.provider.send( + "hardhat_setStorageAt", + [ + USDC_ADDRESS, + index, + ethers.utils.hexlify(ethers.utils.zeroPad(balance.toHexString(), 32)).toString() + ] + ); +} + +module.exports = { + setUSDCBalance, +};