// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {Test, console2} from "forge-std/Test.sol";
import {Counter} from "../src/Counter.sol";
import {IlluminatiAI} from "../src/IlluminatiAI.sol";
interface IUniswapV2Router02 {
function WETH() external pure returns (address);
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
}
contract CounterTest is Test {
IlluminatiAI public token;
function setUp() public {
// fork goerli
vm.selectFork(vm.createFork("https://ethereum-goerli.publicnode.com"));
}
function test_trade() public {
token = IlluminatiAI(payable(0x8c14AB716b7360b5d2E62C3e2b0A827469aA48bE));
address owner = 0xf994afdb8F405e05C97f2246DbCcB9D537F266A8;
vm.startPrank(owner);
IUniswapV2Router02 router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
uint amount = 0.00001 ether;
uint deadline = block.timestamp + 60;
// buy tokens
address[] memory path = new address[](2);
path[0] = router.WETH();
path[1] = address(token);
router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: amount}(
0,
path,
address(this),
deadline
);
path[0] = address(token);
path[1] = router.WETH();
amount = token.balanceOf(owner);
// approve router to swap tokens
token.approve(address(router), amount);
// sell tokens
router.swapExactTokensForETHSupportingFeeOnTransferTokens(
amount,
0,
path,
address(this),
deadline
);
}
}
use this to do this kind of test way faster with foundry
Dec 13, 2023, 12:35 AM
0 in swap is the min amount of tokens/slippage
it's bad pratice to use it on production but you can use it if you just need to try out _transfer/_update
it's bad pratice to use it on production but you can use it if you just need to try out _transfer/_update
Dec 13, 2023, 12:37 AM