1.众筹 ERC20
- 用户创建活动;
- 用户可以承诺,将他们的 ERC20 转移到活动中;
- 活动结束后,如果承诺的总金额超过活动目标,活动创建者可以申请提取 ERC20;
- 否则,活动并没有达到目标,用户可以撤回承诺。
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
interface IERC20 {
function transfer(address, uint) external returns (bool);
function transferFrom(address, address, uint) external returns (bool);
}
contract CrowdFund {
event Launch(uint id, address indexed creator, uint goal, uint32 startAt, uint32 endAt);
event Cancel(uint id);
event Pledge(uint indexed id, address indexed caller, uint amount);
event Unpledge(uint indexed id, address indexed caller, uint amount);
event Claim(uint id);
event Refund(uint id, address indexed caller, uint amount);
struct Campaign {
// Creator of campaign
address creator;
// Amount of tokens to raise
uint goal;
// Total amount pledged
ui