Repository navigation
Conversation
Bug fixes: - Refunds return each donor's own assets (ETH and token tracked and refunded separately); previously ETH balances were paid out as tokens - Token value now comes from an IPriceOracle instead of the Uniswap v4 spot price: ChainlinkTwapOracle uses Chainlink (TOKEN/ETH or TOKEN/USD via ETH/USD) with a Uniswap v3 TWAP fallback, both flash-loan resistant - Price math rewritten with FullMath (correct direction, no truncation to 0 for low-decimal tokens, no overflow) - Price sources are validated when configured (fresh feed, pool pairs token with WETH, enough TWAP history, minimum 30 min window) Design changes: - CampaignBase shared by all campaign types: Active/Settled/Refunding state, deadline (max 365 days), owner can settle early once the goal is reached, anyone can settle after the deadline, refunds open automatically if the goal is missed; first outcome is final - Oracle outages can't lock donors in: refunds still open after deadline - SafeERC20, fee-on-transfer accounting, call instead of transfer, ReentrancyGuard, custom errors, indexed events with asset field - BlockFund uses Ownable, holds the oracle, emits CampaignType.MIXED Tests: unit tests for every fix plus optional mainnet fork tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0178pC5ovfwig5P4H2dMDwWQ
Campaigns: - settleCampaign() now only records the outcome; the owner collects with claimFunds(to) at any address they choose - withdrawDonation(to) refunds a donor's assets to any address - A recipient that can't receive ETH (contract without receive) or a token-blacklisted address can no longer lock funds in a settled campaign: it claims or withdraws elsewhere - New FundsClaimed event; DonationRefunded includes the recipient Admin: - BlockFund and ChainlinkTwapOracle use Ownable2Step, so ownership only moves once the new owner (e.g. a Safe) accepts it - Deploy script requires OWNER to be a contract (multisig) on any chain except local anvil - README: creating the admin Safe, configuring the oracle through the Safe Transaction Builder, changing the admin Tests cover claiming/withdrawing to other addresses, ETH-rejecting and blacklisted recipients, and two-step transfer to a multisig contract. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0178pC5ovfwig5P4H2dMDwWQ
The admin could previously change price feeds/pools on the shared oracle, which also changed how running campaigns were valued (e.g. pushing one over its goal). Now: - ChainlinkTwapOracle prices a single token and is immutable: every setting is fixed and validated in the constructor, with no owner and no setters - New PriceSourceRegistry (Ownable2Step, owned by the admin multisig) deploys these oracles via setSource(token, chainlink, twap) and records which one new campaigns use; removeSource stops new campaigns - BlockFund reads the token's oracle from the registry when creating a mixed campaign; the campaign stores it immutably. The registry address is fixed in BlockFund, which no longer has an owner or admin functions - A retired feed counts as stale (TWAP fallback); with no working source a campaign can't settle and refunds open after the deadline Tests include changing and removing a token's source after a campaign exists and checking its valuation is unchanged. Deploy script and README updated for the registry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0178pC5ovfwig5P4H2dMDwWQ
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
Fixes the
MixedCampaignbugs from the status review, adds deadlines and safer payouts to every campaign type, and replaces the Uniswap v4 spot price with a Chainlink / Uniswap v3 TWAP oracle whose price sources are locked per campaign: nobody, including the admin, can change how an existing campaign is valued.maincurrently has the Foundry setup but the original contracts, so this PR contains three commits:Bugs fixed
FullMath; decimals handledslot0) movable by a flash loan to force settlementIPriceOraclebacked by Chainlink (TOKEN/ETH, or TOKEN/USD via ETH/USD, with staleness checks) and a Uniswap v3 TWAP fallback (≥ 30 min window)PoolId(non-existent or wrong pair priced at 0)Price sources locked per campaign (this change)
ChainlinkTwapOraclenow prices one token, and every setting is fixed in its constructor. It has no owner and no setters.PriceSourceRegistry(Ownable2Step, owned by the admin Safe) deploys these oracles withsetSource(token, chainlink, twap)and records which one new campaigns use.removeSource(token)stops new mixed campaigns for that token.BlockFundreads the token's oracle from the registry when it creates a mixed campaign, and the campaign stores it immutably. Changing or removing a registry entry only affects campaigns created afterwards.BlockFund's registry address is fixed at deployment, and the factory no longer has an owner or any admin functions. The registry is the only admin surface.Campaign lifecycle (all campaign types)
CampaignBasewith anActive/Settled/Refundingstate and a deadline (at most 365 days).settleCampaign()only records the outcome; the owner collects withclaimFunds(to)and donors refund withwithdrawDonation(to), both to any address. An owner contract withoutreceive(), or an address blacklisted by a token like USDC, can no longer lock funds.SafeERC20(USDT-style tokens), fee-on-transfer accounting,callinstead oftransfer,ReentrancyGuard, custom errors, indexed events with an asset field,CampaignType.MIXED.Interface changes
deadline(Unix timestamp).withdrawDonation(address to)replaces the old per-contract variants. NewclaimFunds(address to)for owners.donateEth()/donateToken(amount).BlockFund(registry)constructor;createMixedCampaigntakes the token, and the oracle comes from the registry.PriceSourceRegistry(owned byOWNER, which must be a contract such as a Safe except on local anvil) andBlockFund.Testing
forge buildwith no warnings; 93 tests pass, 2 fork tests skipped (no RPC in CI).test/fork/(real Chainlink feeds and the USDC/WETH v3 pool, including a same-block 20,000 WETH swap that must not move the TWAP). Run withMAINNET_RPC_URL=… forge test --match-path "test/fork/*" -vvv.Known limitations / follow-ups
Generated by Claude Code