Skip to content

feat: add forwardTipsImmediately config flag to KeepWhatsRaised#87

Open
Suvadra-Barua wants to merge 8 commits intomainfrom
feat/proposal-p4
Open

feat: add forwardTipsImmediately config flag to KeepWhatsRaised#87
Suvadra-Barua wants to merge 8 commits intomainfrom
feat/proposal-p4

Conversation

@Suvadra-Barua
Copy link
Copy Markdown
Collaborator

Introduces a new forwardTipsImmediately boolean flag to the treasury Config struct. When enabled (currently set for Colombian creator campaigns), tips are forwarded directly to the platform admin at pledge time instead of accumulating in the contract for a later claimTip() call.

Changes

src/treasuries/KeepWhatsRaised.sol

  • Added forwardTipsImmediately field to the Config struct.
  • Added s_tipClaimedPerToken mapping to track cumulative tips received by the platform admin per token (regardless of whether they were forwarded at pledge time or claimed later via claimTip()).
  • Added getTipClaimedPerToken(address token) and getTotalTipClaimed() view functions to expose cumulative tip data.
  • Added TipForwarded event emitted when a tip is forwarded immediately during a pledge.
  • Added KeepWhatsRaisedTipsAlreadyForwarded error — claimTip() reverts with this error when forwardTipsImmediately is enabled.
  • Updated the internal pledge processing logic:
    • For the admin path (setFeeAndPledge): the tip already resides in the admin's wallet, so only the pledge amount is transferred to the treasury.
    • For the user path (Permit2): the full amount (pledge + tip) is pulled from the backer, then the tip is immediately transferred to the platform admin.
    • When forwardTipsImmediately is disabled, behavior is unchanged — tips accumulate in s_tipPerToken for later claiming.
  • Fixed a double-tip-forwarding bug where the tip amount was being counted or transferred twice under the admin path.
  • test/foundry/utils/Defaults.sol
    • Added forwardTipsImmediately: false to the default CONFIG struct.
    • Added forwardTipsImmediately: true to the CONFIG_COLOMBIAN struct.

test/foundry/unit/KeepWhatsRaised.t.sol

Added 14 new unit tests covering:

  • claimTip() reverts when forwarding is enabled
  • Tip transferred to platform admin at pledge time (Permit2 path)
  • Admin path (setFeeAndPledge) only transfers pledge amount, not tip
  • TipForwarded event emission
  • TipReceipt event still carries the original tip amount
  • Cumulative tip tracking across multiple pledges
  • Zero-tip pledges skip forwarding logic
  • Large tips exceeding pledge amount
  • forwardTipsImmediately: false preserves the original claimTip() flow

Suvadra-Barua and others added 8 commits April 2, 2026 21:24
Cover the three key behaviors when Config.forwardTipsImmediately is true:
- claimTip() reverts with KeepWhatsRaisedTipsAlreadyForwarded
- Permit2 pledge forwards tip to platform admin at pledge time
- Admin setFeeAndPledge splits pledge vs tip accounting correctly

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
test(foundry): add forwardTipsImmediately unit tests
@Suvadra-Barua
Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants