-
-
Save FOFIE2002/c234a570292f3784e3c4099d00a27548 to your computer and use it in GitHub Desktop.
Mainnet Forking
This file contains hidden or 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
| import { ethers } from "hardhat"; | |
| const helpers = require("@nomicfoundation/hardhat-network-helpers"); | |
| async function main() { | |
| const AssetHolder = "0xf584f8728b874a6a5c7a8d4d387c9aae9172d621"; | |
| await helpers.impersonateAccount(AssetHolder); | |
| const impersonatedSigner = await ethers.getSigner(AssetHolder); | |
| //USDC contract Address | |
| const USDCAddress = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; | |
| //DAI contract Address | |
| const DAIAddress = "0x6B175474E89094C44Da98b954EedeAC495271d0F"; | |
| const UNIRouter = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"; | |
| const USDC = await ethers.getContractAt("IERC20", USDCAddress); | |
| const DAI = await ethers.getContractAt("IERC20", DAIAddress); | |
| const usdcBal = await USDC.balanceOf(AssetHolder); | |
| const daiBal = await DAI.balanceOf(AssetHolder); | |
| console.log( | |
| "################### Initial Balance Info ###########################" | |
| ); | |
| console.log( | |
| "User Initial USDC Balance:", | |
| ethers.formatUnits(usdcBal.toString(), 6) | |
| ); | |
| console.log( | |
| "User Initial DAI Balance:", | |
| ethers.formatUnits(daiBal.toString(), 18) | |
| ); | |
| const Router = await ethers.getContractAt("IUniSwap", UNIRouter); | |
| // defining args | |
| const USDCAmount = ethers.parseUnits("471000", 6); | |
| const DAIAmount = ethers.parseUnits("471000", 18); | |
| const approvalUSDC = await USDC.connect(impersonatedSigner).approve( | |
| UNIRouter, | |
| USDCAmount | |
| ); | |
| const tx = await approvalUSDC.wait(); | |
| console.log("USDC approval receipt:", tx); | |
| const approvalDAI = await DAI.connect(impersonatedSigner).approve( | |
| UNIRouter, | |
| DAIAmount | |
| ); | |
| const tx2 = await approvalDAI.wait(); | |
| console.log("DAI approval receipt:", tx2); | |
| const deadline = Math.floor(Date.now() / 1000) + 60 * 10; | |
| const provideLiquidity = await Router.connect( | |
| impersonatedSigner | |
| ).addLiquidity( | |
| USDCAddress, | |
| DAIAddress, | |
| USDCAmount, | |
| DAIAmount, | |
| 1, | |
| 1, | |
| impersonatedSigner.address, | |
| deadline | |
| ); | |
| const tx3 = await provideLiquidity.wait(); | |
| console.log("Liquidity receipt:", tx3); | |
| const usdcBalAfter = await USDC.balanceOf(AssetHolder); | |
| const daiBalAfter = await DAI.balanceOf(AssetHolder); | |
| console.log( | |
| "################### Final Balance Info ###########################" | |
| ); | |
| console.log( | |
| "User final USDC Balance:", | |
| ethers.formatUnits(usdcBalAfter.toString(), 6) | |
| ); | |
| console.log( | |
| "User final DAI Balance:", | |
| ethers.formatUnits(daiBalAfter.toString(), 18) | |
| ); | |
| } | |
| main().catch((error) => { | |
| console.error(error); | |
| process.exitCode = 1; | |
| }); |
This file contains hidden or 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
| npx hardhat run scripts/Lock.ts | |
| npx hardhat run scripts/addLiquidity.ts |
This file contains hidden or 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
| import { HardhatUserConfig } from "hardhat/config"; | |
| import "@nomicfoundation/hardhat-toolbox"; | |
| const config: HardhatUserConfig = { | |
| solidity: "0.8.28", | |
| networks: { | |
| hardhat: { | |
| forking: { | |
| url: `https://eth-mainnet.g.alchemy.com/v2/${Key}`, | |
| }, | |
| }, | |
| }, | |
| }; | |
| export default config; |
This file contains hidden or 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
| // SPDX-License-Identifier: UNLICENSED | |
| pragma solidity ^0.8.9; | |
| interface IERC20 { | |
| function approve(address _spender, uint256 _value) external; | |
| function balanceOf(address who) external view returns (uint256 balance); | |
| } |
This file contains hidden or 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
| // SPDX-License-Identifier: UNLICENSED | |
| pragma solidity ^0.8.9; | |
| interface IUniSwap { | |
| function swapExactTokensForTokens( | |
| uint256 amountIn, | |
| uint256 amountOutMin, | |
| address[] calldata path, | |
| address to, | |
| uint256 deadline | |
| ) external returns (uint256[] memory amounts); | |
| function swapTokensForExactTokens( | |
| uint256 amountOut, | |
| uint256 amountInMax, | |
| address[] calldata path, | |
| address to, | |
| uint256 deadline | |
| ) external returns (uint256[] memory amounts); | |
| function swapTokensForExactETH( | |
| uint256 amountOut, | |
| uint256 amountInMax, | |
| address[] calldata path, | |
| address to, | |
| uint256 deadline | |
| ) external returns (uint256[] memory amounts); | |
| function addLiquidity( | |
| address tokenA, | |
| address tokenB, | |
| uint256 amountADesired, | |
| uint256 amountBDesired, | |
| uint256 amountAMin, | |
| uint256 amountBMin, | |
| address to, | |
| uint256 deadline | |
| ) external returns (uint256 amountA, uint256 amountB, uint256 liquidity); | |
| function swapETHForExactTokens(uint256 amountOut, address[] calldata path, address to, uint256 deadline) | |
| external | |
| payable | |
| returns (uint256[] memory amounts); | |
| function swapExactETHForTokens(uint256 amountOutMin, address[] calldata path, address to, uint256 deadline) | |
| external | |
| payable | |
| returns (uint256[] memory amounts); | |
| function swapExactTokensForTokensSupportingFeeOnTransferTokens( | |
| uint256 amountIn, | |
| uint256 amountOutMin, | |
| address[] calldata path, | |
| address to, | |
| uint256 deadline | |
| ) external; | |
| } |
This file contains hidden or 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
| import { ethers } from "hardhat"; | |
| const helpers = require("@nomicfoundation/hardhat-network-helpers"); | |
| async function main() { | |
| const AssetHolder = "0xf584f8728b874a6a5c7a8d4d387c9aae9172d621"; | |
| await helpers.impersonateAccount(AssetHolder); | |
| const impersonatedSigner = await ethers.getSigner(AssetHolder); | |
| const JAN_1ST_2030 = 1893456000; | |
| const ONE_GWEI: bigint = 1_000_000_000n; | |
| const Lock = await ethers.getContractFactory("Lock"); | |
| const lock = await Lock.connect(impersonatedSigner).deploy(JAN_1ST_2030, { | |
| value: ONE_GWEI, | |
| }); | |
| await lock.waitForDeployment(); | |
| console.log("Lock deployed to:", lock.target); | |
| const tx_time = await lock.unlockTime(); | |
| const owner = await lock.owner(); | |
| console.log("Unlock time:", tx_time); | |
| console.log("Owner:", owner); | |
| } | |
| main().catch((error) => { | |
| console.error(error); | |
| process.exitCode = 1; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment