# donation-vault — result ## Changed - `src/DonationVault.sol` (new): the DonationVault contract plus a local `IDonationToken` ERC-20 interface (`balanceOf`, `transfer`, `transferFrom`). It has no imports. - `test/DonationVault.t.sol` (new): a local `MockToken` ERC-20 fixture (name `test`, symbol `testAdam`, 18 decimals, with switches to make it return false or revert) and the `DonationVaultTest` suite. It uses a minimal inline `Vm` cheatcode interface, so it needs no forge-std, no `lib/` and no remappings. No other files were touched: no foundry.toml, remappings, lib/ or submodules. ## Interface - `constructor(address token_)`: `token` is immutable. It reverts with `ZeroAddress()` if passed address 0. The deployer supplies the testAdam token address. - `donate(uint256 amount) returns (uint256 giftId)` - Pulls `amount` from `msg.sender` through `transferFrom`, so the sender must approve the vault first. - Gift IDs are sequential and start at **1**. - The gift amount and the points are the **base units actually received**, measured as the change in the vault's balance. - Reverts: `ZeroAmount()` if amount is 0, `TransferFailed()` if the pull reverts or returns false (missing or too-small allowance), `NothingReceived()` if the vault's balance did not go up. - `claim(uint256 giftId) returns (uint256 amount)` - Pays the whole gift to the first caller who is not its donor. - Sets `claimed = true` and lowers `totalOutstanding` before calling `transfer`. - Reverts: `UnknownGift(id)`, `AlreadyClaimed(id)`, `SelfClaim(id)`, or `TransferFailed()` if the transfer reverts or returns false. That revert rolls the whole claim back. - Views: - `giftCount()`, `giftDonor(id)`, `giftAmount(id)`, `isClaimed(id)` - `getGift(id) returns (address donor, uint256 amount, bool claimed)`; an unknown ID returns zeros - `totalOutstanding()`, `points(address)`, `token()` - Events: - `Donated(uint256 indexed giftId, address indexed donor, uint256 amount)` - `Claimed(uint256 indexed giftId, address indexed claimer, uint256 amount)` - Units: points are counted in token base units, so 1e18 = 1 point = 1 whole testAdam (18 decimals). Fractions are credited exactly. - Point rules: - Points cannot be transferred; there is no transfer function. - Claims never change points, either the donor's or the claimer's. - Tokens sent straight to the vault earn no points and create no gift. - Safety: - A `nonReentrant` guard covers `donate` and `claim`. - The token call wrapper accepts tokens that return true or return nothing, and refuses calls to an address that has no code. ## Checks run (forge 1.8.3, solc 0.8.30 auto-selected from the local svm cache, no network) - `forge build --offline` (and `--force`): compiles 2 files with no errors. - The linter gives 3 notes: two `reentrancy-events` (events emitted after the token call) and one `reentrancy-no-eth`. - I accepted these. Both functions have the reentrancy guard, and the claim's state is written before the call. - `forge test --offline -vv`: **16 passed, 0 failed, 0 skipped**. - The fuzz test ran 256 times. - The first run had 3 tests named `testFail*`, which forge 1.8 now refuses to run. I renamed them to `test_RevertWhen_*` and the next run passed them all. Tests and what each covers: - constructor rejects address 0 - donating records the gift, the points and the `Donated` event - several gifts from several donors, with sequential IDs and points totalled per donor - fractional amounts (1 wei and 0.5 token) - donating 0 reverts - donating with no allowance, or too little, reverts - a direct transfer to the vault earns no points - a claim pays the claimer, emits `Claimed` and leaves the donor's points unchanged; the claimer gets none - a donor claiming their own gift reverts - unknown IDs 0 and N+1 revert - a second claim, by a new caller or by the first claimer, reverts - a claim reverts when the payout returns false; the gift stays unclaimed and can still be claimed later - a claim reverts when the payout reverts - vault balance ≥ `totalOutstanding` after every step of a mixed sequence - a fuzz test of donating then claiming any amount ## Left open - The deployed testAdam token address goes into the constructor at deploy time. This item does not supply it. - `forge build` leaves `out/` and `cache/` in the checkout. They are build output and are not committed.