feat: add VaultV2.depositFor() for Trial Market Program treasury seeding#7
Merged
Merged
Conversation
Adds a permissioned treasury seeding mechanism to VaultV2: - `depositFor(address recipient, uint256 amount)` — allows a designated treasury EOA/multisig to top up any address's vault balance with USDC. Used by the Trial Market Program: treasury covers the $30 seed for trial market creators so factory.pullForNewMarket() can succeed. - `setTreasury(address)` — admin-only function to configure the treasury. - `NotTreasury` error and `TreasuryUpdated` event. - `LedgerReason.PlatformSeed` added to Types.sol for audit trail clarity. The function is protected by `onlyTreasury` modifier, `nonReentrant`, and `whenNotPaused`. The global invariant is preserved (USDC transfer increases totalBalances by the same amount). Tests (13 new, 30 total in VaultV2Test): - depositFor credits recipient, invariant holds, allows subsequent pullForNewMarket (full trial market seeding flow) - reverts for non-treasury, unset treasury, zero amount, zero address, and when paused - setTreasury: admin access, event emission, clear treasury Related: flipcoin-app docs/TRIAL_MARKET_PROGRAM.md §8.1 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the treasury seeding mechanism required by the Trial Market Program (see
flipcoin-appdocs/TRIAL_MARKET_PROGRAM.md §8.1).The problem:
VaultV2.deposit()only creditsmsg.sender. The platform treasury could not top up another user's vault balance, so the factory'spullForNewMarket(creator, market, seed)would fail for free trial markets where the creator has $0.The solution:
depositFor(address recipient, uint256 amount)— a treasury-only function that deposits USDC on behalf of a recipient.Changes
contracts/v2/interfaces/Types.sol— addsLedgerReason.PlatformSeedfor audit trail claritycontracts/v2/VaultV2.sol:address public treasurystate variableNotTreasuryerror,TreasuryUpdatedevent,onlyTreasurymodifierdepositFor(address recipient, uint256 amount) external nonReentrant whenNotPaused onlyTreasurysetTreasury(address) external onlyAdmintest/VaultV2.t.sol— 13 new tests (30 total)Full trial market seeding flow (after this PR)
Security properties
onlyTreasury— only the configured treasury address can callnonReentrant— reentrancy protectionwhenNotPaused— respects global pauseUSDC.balanceOf(vault) >= totalBalances + splitReserve + feePoolsetTreasury(address(0))) to disable the mechanismTest plan
forge test --match-contract VaultV2Test— 30/30 ✅forge test— 387/387 ✅ (including fuzz invariants)