Skip to content

Instantly share code, notes, and snippets.

@shazow
Created February 12, 2025 17:29
Show Gist options
  • Save shazow/cc39439712ee10d10b3c6b9c3cacb5f5 to your computer and use it in GitHub Desktop.
Save shazow/cc39439712ee10d10b3c6b9c3cacb5f5 to your computer and use it in GitHub Desktop.

Revisions

  1. shazow created this gist Feb 12, 2025.
    47 changes: 47 additions & 0 deletions TheDAO_Withdraw.t.sol
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    // 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);
    }