Created
February 12, 2025 17:29
-
-
Save shazow/cc39439712ee10d10b3c6b9c3cacb5f5 to your computer and use it in GitHub Desktop.
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
// SPDX-License-Identifier: MIT | |
// Run with: | |
// $ nix develop github:shazow/foundry.nix/monthly | |
// $ forge init | |
// Add test/TheDAO_Withdraw.t.sol | |
// $ forge test -vvv ./test/TheDAO_Withdraw.t.sol --fork-url https://ethereum-rpc.publicnode.com | |
pragma solidity ^0.8.13; | |
import {Test, console} from "forge-std/Test.sol"; | |
interface Token { | |
function approve(address, uint256) external; | |
function balanceOf(address addr) external returns (uint); | |
function transferFrom(address from, address to, uint balance) external returns (bool); | |
} | |
interface TheDAOExtraBalance { | |
function refund() external; | |
} | |
interface DAOWithdraw { | |
function withdraw() external; | |
} | |
contract TheDAOWithdraw is Test { | |
address public sender = address(...); // XXX: Fill this in | |
DAOWithdraw public withdrawContract = DAOWithdraw(0xBf4eD7b27F1d666546E30D74d50d173d20bca754); | |
Token public daoToken = Token(0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413); | |
Token public extraBalanceToken = Token(0x5c40eF6f527f4FbA68368774E6130cE6515123f2); | |
DAOWithdraw public withdrawExtraBalance = DAOWithdraw(0x755cdba6AE4F479f7164792B318b2a06c759833B); | |
function test_DAOWithdraw() public { | |
// Reproduce https://ethereum.stackexchange.com/questions/7204/how-do-i-convert-my-the-dao-tokens-into-ethers-using-the-withdrawal-contract-aft | |
// call dao.approve("0xbf4ed7b27f1d666546e30d74d50d173d20bca754", dao.balanceOf(youraccount)) | |
// call withdrawContract.withdraw() | |
console.log("Balance before: %s", sender.balance / 1 ether); | |
vm.startPrank(sender); | |
daoToken.approve(address(withdrawContract), daoToken.balanceOf(sender)); | |
withdrawContract.withdraw(); | |
extraBalanceToken.approve(address(withdrawExtraBalance), extraBalanceToken.balanceOf(sender)); | |
withdrawExtraBalance.withdraw(); | |
console.log("Balance after: %s", sender.balance / 1 ether); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment