Skip to main content
The AllOrNothing treasury contract implements an “all-or-nothing” crowdfunding model where campaign creators only receive funds if the campaign reaches its goal. If the goal is not met, all backers can claim refunds. This contract also manages a reward system where backers receive NFTs representing their pledges.

Overview

Key Features

  • All-or-Nothing Model: Funds only released if goal is met
  • Reward System: Backers receive rewards based on pledge amount
  • NFT Receipts: ERC721 tokens track backer pledges
  • Refund Mechanism: Backers can claim refunds if campaign fails
  • Fee Distribution: Protocol and platform fees automatically distributed
  • Shipping Support: Separate tracking for pledge amount and shipping fees

State Variables

Pledge Tracking

Reward Management

Token Metadata

Functions

Initialization

Constructor

Effects:
  • Initializes ERC721 base contract
  • Empty name/symbol set in constructor (set during initialization)

Initialize

Parameters:
  • _platformHash: Platform identifier
  • _infoAddress: CampaignInfo contract address
  • _name: Treasury contract name
  • _symbol: Treasury contract symbol
Effects:
  • Initializes base treasury contract
  • Sets name and symbol for ERC721
  • Initializes campaign connection
Requirements:
  • Can only be called once (initializer modifier)
  • Name and symbol must be non-empty strings

Reward Management

Get Reward

Parameters:
  • rewardName: Reward identifier
Returns:
  • Complete reward structure with value, items, quantities
Usage:
  • Query reward details before pledging
  • Check available reward tiers
  • Display reward information to users

Add Rewards

Parameters:
  • rewardNames: Array of reward identifiers
  • rewards: Array of reward structures
Effects:
  • Adds rewards to campaign
  • Emits RewardsAdded event
Requirements:
  • Only callable by campaign owner
  • Must be called before campaign launch
  • Reward names must be unique
  • Arrays must have matching lengths

Remove Reward

Parameters:
  • rewardName: Reward identifier to remove
Effects:
  • Removes reward from campaign
  • Emits RewardRemoved event
Requirements:
  • Only callable by campaign owner
  • Must be before launch
  • Reward must exist

Contribution Functions

Pledge For A Reward

Parameters:
  • rewardName: Reward tier identifier
  • amount: Pledge amount (must meet reward minimum)
  • shippingFee: Shipping fee (can be zero)
Returns:
  • tokenId: ERC721 token ID representing pledge
Effects:
  • Transfers tokens from backer
  • Mints ERC721 receipt NFT
  • Records pledge and shipping amounts
  • Emits Receipt event
Requirements:
  • Campaign must be active (not paused/cancelled)
  • Campaign must be between launch and deadline
  • Amount must meet minimum for reward tier
  • Reward must exist
  • Backer must approve token transfer

Check Success Condition

Returns:
  • True if total raised >= campaign goal
Logic:
  • Compares total pledged amount to goal from CampaignInfo
  • Used to determine if fees should be disbursed
  • All funds remain if condition not met

Withdrawal Functions

Withdraw Funds

Effects:
  • Transfers all collected funds to campaign owner
  • Can only be called if campaign successful
Requirements:
  • Only callable by campaign owner
  • Campaign must have reached goal
  • Funds must be successfully disbursed (fees paid)

Claim Refund

Parameters:
  • tokenId: ERC721 token ID of pledge
Effects:
  • Burns the NFT receipt
  • Transfers pledged amount back to backer
  • Emits RefundClaimed event
Requirements:
  • Campaign must not have reached goal
  • Token must not already be claimed
  • Token must be owned by caller or approved
  • Campaign must be past deadline

Fee Distribution

Disburse Fees

Effects:
  • Distributes protocol and platform fees
  • Transfers remaining funds to campaign owner
  • Marks fees as disbursed
Requirements:
  • Campaign must have reached goal
  • Fees must not already be disbursed
Distribution:
  1. Protocol fee → Protocol treasury
  2. Platform fee → Platform treasury
  3. Remaining funds → Campaign owner

Query Functions

Get Pledge Amount

Parameters:
  • tokenId: ERC721 token ID
Returns:
  • Pledged amount for the token

Get Total Collected Amount

Parameters:
  • tokenId: ERC721 token ID
Returns:
  • Total amount (pledge + shipping) for the token

Get All Rewards

Returns:
  • Array of reward names and corresponding reward structures
Usage:
  • Display all available rewards
  • Show complete reward catalog

Name & Symbol

Returns:
  • ERC721 name and symbol

Data Structures

Reward

Fields:
  • rewardValue: Minimum pledge amount to receive this reward
  • isRewardTier: Whether this tier offers physical/digital rewards
  • itemId: Identifiers of items included in reward
  • itemValue: Individual item values
  • itemQuantity: Number of each item included

Events

Receipt

Emitted when: Backer makes a pledge Includes: Backer address, reward tier, amounts, token ID, all rewards earned

RewardsAdded

Emitted when: New rewards added to campaign

RewardRemoved

Emitted when: Reward removed from campaign

RefundClaimed

Emitted when: Backer claims refund for failed campaign

Errors

AllOrNothingUnAuthorized

Emitted when: Unauthorized action attempted

AllOrNothingInvalidInput

Emitted when: Invalid input provided

AllOrNothingNotSuccessful

Emitted when: Withdrawal attempted on unsuccessful campaign

AllOrNothingNotClaimable

Emitted when: Refund cannot be claimed for token

AllOrNothingRewardExists

Emitted when: Attempting to add duplicate reward

Usage Examples

Adding Rewards

Making a Pledge

Checking Campaign Status

Claiming Refunds

Withdrawing Funds (Owner)

Querying Rewards

Funding Model Behavior

Successful Campaign

Failed Campaign

Security Considerations

Token Safety

  • Uses SafeERC20 for safe token transfers
  • No reentrancy vulnerabilities
  • Checks-Effects-Interactions pattern

Access Control

  • Campaign owner has limited access (rewards, withdrawal)
  • Only valid rewards can be added
  • Only before launch can rewards be modified

Pledge Protection

  • Cannot pledge after deadline
  • Cannot pledge less than reward minimum
  • Total amount (pledge + shipping) recorded separately

Refund Safety

  • Can only claim refund once
  • Token must be owned by claimer
  • Refunds only available if goal not met

Integration Notes

With CampaignInfo

With GlobalParams

Event Monitoring

Best Practices

Reward Design

  • Clear, achievable reward tiers
  • Reasonable minimum pledge amounts
  • Include physical items, digital goods, or experiences
  • Consider shipping costs in reward pricing

Campaign Management

  • Set realistic funding goals
  • Add rewards before launch
  • Cannot modify rewards after launch
  • Monitor campaign progress

User Experience

  • Display all rewards clearly
  • Show funding progress
  • Make refund process easy
  • Provide clear deadlines

Next Steps