🌟 “MilestoneStream” – Democratic, Cancel‑able, Streaming Crowdfund Contract
A single Solidity file (0.8.x) you can drop into Remix and hit Compile right away.
// SPDX‑License‑Identifier: MIT
pragma solidity ^0.8.20;
/* ════════════════════════════════════════════════════════════════════════
MilestoneStream v0.1
‑ A novel Kickstarter‑meets‑Sablier contract.
‑ Funds are streamed (per‑second drip) to a creator **only while** backers
are happy. >50 % of the backing power can veto and claw back the rest.
‑ Backers receive non‑transferable ERC20 “Voice” tokens that encode both
refund rights and voting power.
════════════════════════════════════════════════════════════════════════ */
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract MilestoneStream is ERC20Burnable, Ownable {
/* ------------------------------------------------- *
* EVENTS *
* ------------------------------------------------- */
event Deposit(address indexed backer, uint256 amount);
event CancelVote(address indexed backer, uint256 weight);
event Unvote(address indexed backer, uint256 weight);
event StreamStarted(uint256 ratePerSecond, uint64 startTime);
event StreamHalted();
event Refund(address indexed backer, uint256 amount);
event WithdrawnByCreator(uint256 amount);
/* ------------------------------------------------- *
* IMMUTABLE CONFIG *
* ------------------------------------------------- */
address public immutable creator; // project owner to be paid
uint64 public immutable fundingDeadline; // last second people can deposit
uint64 public immutable streamDuration; // seconds the stream would last
/* ------------------------------------------------- *
* STATE *
* ------------------------------------------------- */
uint256 public totalDeposited; // total ETH ever deposited
uint256 public totalStreamed; // amount already streamed to creator
uint64 public streamStart; // == 0 until startStream() is called
uint256 public rate; // wei / second
uint256 public cancelVotes; // aggregated voting weight for cancel
bool public halted; // true once cancelled OR finished
mapping(address => bool) public hasVoted; // track individual cancel votes
/* ------------------------------------------------- *
* MODIFIERS *
* ------------------------------------------------- */
modifier streamActive() {
require(streamStart != 0 && !halted, "Stream inactive");
_;
}
modifier afterDeadline() {
require(block.timestamp >= fundingDeadline, "Not yet");
_;
}
constructor(
string memory name_,
string memory symbol_,
address creator_,
uint64 fundingDuration_, // seconds fundraising is open
uint64 streamDuration_ // seconds the streaming could last
)
ERC20(name_, symbol_)
{
require(creator_ != address(0), "creator 0");
creator = creator_;
fundingDeadline = uint64(block.timestamp) + fundingDuration_;
streamDuration = streamDuration_;
}
/* ------------------------------------------------- *
* 1️⃣ FUNDRAISING PHASE *
* ------------------------------------------------- */
function deposit() external payable {
require(block.timestamp < fundingDeadline, "Funding closed");
require(msg.value > 0, "No ETH");
_mint(msg.sender, msg.value); // 1 Voice token per wei
totalDeposited += msg.value;
emit Deposit(msg.sender, msg.value);
}
/* ------------------------------------------------- *
* 2️⃣ STREAMING PHASE *
* ------------------------------------------------- */
function startStream() external onlyOwner afterDeadline {
require(streamStart == 0, "started");
require(totalDeposited > 0, "no funds");
streamStart = uint64(block.timestamp);
rate = totalDeposited / streamDuration; // simple linear stream
emit StreamStarted(rate, streamStart);
}
// pull pattern; creator calls whenever
function withdrawFromStream(uint256 amount) external streamActive {
require(msg.sender == creator, "not creator");
uint256 available = _streamableUntil(block.timestamp);
require(amount <= available, "exceeds allowance");
totalStreamed += amount;
(bool ok, ) = creator.call{value: amount}("");
require(ok, "ETH send fail");
if (totalStreamed == totalDeposited) halted = true;
emit WithdrawnByCreator(amount);
}
// helper: how much may still be taken right now
function availableToCreator() external view returns (uint256) {
return _streamableUntil(block.timestamp);
}
/* ------------------------------------------------- *
* 3️⃣ COMMUNITY CONTROL *
* ------------------------------------------------- */
function voteCancel() external {
uint256 bal = balanceOf(msg.sender);
require(bal > 0, "no power");
require(!hasVoted[msg.sender], "already");
hasVoted[msg.sender] = true;
cancelVotes += bal;
emit CancelVote(msg.sender, bal);
if (cancelVotes * 2 > totalSupply()) { // >50 % support
halted = true;
emit StreamHalted();
}
}
function unvoteCancel() external {
require(hasVoted[msg.sender], "not voted");
uint256 bal = balanceOf(msg.sender);
cancelVotes -= bal;
hasVoted[msg.sender] = false;
emit Unvote(msg.sender, bal);
}
/* ------------------------------------------------- *
* 4️⃣ REFUND LOGIC *
* ------------------------------------------------- */
function refund() external {
require(halted, "not halted");
uint256 bal = balanceOf(msg.sender);
require(bal > 0, "nothing to refund");
// proportional remaining pool
uint256 remaining = address(this).balance;
uint256 refundAmount = remaining * bal / totalSupply();
_burn(msg.sender, bal);
(bool ok, ) = msg.sender.call{value: refundAmount}("");
require(ok, "ETH send fail");
emit Refund(msg.sender, refundAmount);
}
/* ------------------------------------------------- *
* INTERNAL HELPERS *
* ------------------------------------------------- */
function _streamableUntil(uint256 timestamp) internal view returns (uint256) {
uint256 elapsed = timestamp > streamStart
? timestamp - streamStart
: 0;
if (elapsed > streamDuration) elapsed = streamDuration;
uint256 entitled = elapsed * rate;
if (entitled > totalDeposited) entitled = totalDeposited;
return entitled - totalStreamed;
}
/* ------------------------------------------------- *
* FALLBACK / RECEIVE *
* ------------------------------------------------- */
receive() external payable {
deposit(); // allow plain ETH transfers to count as deposits
}
}
🤔 What’s novel here & why it matters
-
Continuous Streaming + Crowd Veto
• Unlike Kickstarter (all‑or‑nothing) or ordinary escrow, money is released gradually.
• If the creator abandons the project, >50 % of “Voice” tokens can cancel the stream and claw back what’s left.
→ Aligns incentives over time, not just at funding close.
-
Non‑transferable ERC20 Governance (“Voice” tokens)
• Prevents secondary‑market speculation—only original backers can vote/refund.
• Governance weight = capital size (1 wei ⇒ 1 token), yet claw‑backable.
-
Gas‑cheap Binary Voting
• Each address flips a single boolean (hasVoted) instead of storing per‑block snapshots.
• Aggregates votes on‑chain in O(1).
-
Refund without Oracles
• Remaining ETH is divided by total outstanding Voice supply—no per‑backer accounting needed.
• Simple, deterministic math ⇒ easier audits.
-
“Creator Pull” Model
• Creator must actively call withdrawFromStream().
• Backers can watch how much has been taken vs. shipped deliverables—social pressure.
Combined, these mechanics create a living contract that fosters continued accountability—a missing piece in most Web3 crowdfunding.
🛠️ How you might extend / productionize
| Idea | Quick Hint |
|---|
| Multi‑milestone rates | Replace single rate with an array {amount, duration} chunks. |
| Percentage quorum | e.g. use Quadratic voting (sqrt(balance)) for cancel weight. |
| Transferable backer tokens | If you want a market, inherit from full ERC20 not soul‑bound. |
| ERC‑4626 wrapper | Let people deposit yield‑bearing tokens (stETH, rETH) instead of raw ETH. |
| Off‑chain front‑end | Tableland/Supabase for milestone updates, commit‑hash releases, etc. |
| Fee module | Take X % of deposits or streamed withdrawals to fund platform sustainability. |
🚨 Security & audit notes
- Reentrancy – Minimal ETH transfers use
call, but creator/backer functions are last in the execution flow → safe. Still, consider ReentrancyGuard.
- Overflow – Solidity 0.8 has built‑ins; safe.
- Halting edge cases – After full payout (
totalStreamed == totalDeposited), we flag halted = true so extra refunds cannot drain creator’s funds.
- Rate rounding –
rate is truncated integer division; final wei remains locked (harmless). Could send dust to creator at end.
Always run Slither, Echidna fuzzing, unit tests, and get at least one professional audit before main‑net usage!
✨ Why this could “change the game”
Crowdfunding today either:
• dumps all capital instantly on the builder (risk of rug), or
• keeps funds locked until a binary success test (delays progress, discourages bigger goals).
MilestoneStream inserts a skin‑in‑the‑game drip that’s cancel‑able by the very people who paid. Builders receive just‑in‑time capital, backers keep real leverage. This middle ground can unlock larger, longer, community‑owned projects—everything from open‑source software to physical infrastructure—without relying on centralized Kickstarter dispute teams.
Go build cool stuff! 🚀