编译器
0.8.13+commit.abaa5c0e
文件 1 的 17:CrowdPool.sol
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "../../interfaces/IWETH.sol";
import "../TransferHelper.sol";
import "./SharedStructs.sol";
import "./CrowdPoolLockForwarder.sol";
import "../CrowdPoolSettings.sol";
contract CrowdPoolV1 is ReentrancyGuard {
struct CrowdPoolFeeInfo {
uint256 raised_fee;
uint256 sold_fee;
uint256 referral_fee;
address payable raise_fee_address;
address payable sole_fee_address;
address payable referral_fee_address;
}
struct CrowdPoolStatus {
bool lp_generation_complete;
bool force_failed;
uint256 raised_amount;
uint256 sold_amount;
uint256 token_withdraw;
uint256 base_withdraw;
uint256 num_buyers;
}
struct BuyerInfo {
uint256 base;
uint256 sale;
}
struct TokenInfo {
string name;
string symbol;
uint256 totalsupply;
uint256 decimal;
}
SharedStructs.CrowdPoolInfo public crowdpool_info;
CrowdPoolStatus public status;
SharedStructs.CrowdPoolLink public link;
CrowdPoolFeeInfo public crowdpool_fee_info;
TokenInfo public tokeninfo;
address manage_addr;
IWETH private WETH;
CrowdPoolSettings public crowdpool_setting;
CrowdPoolLockForwarder public crowdpool_lock_forwarder;
mapping(address => BuyerInfo) public buyers;
event UserDepsitedSuccess(address, uint256);
event UserWithdrawSuccess(uint256);
event UserWithdrawTokensSuccess(uint256);
event AddLiquidtySuccess(uint256);
constructor(
address manage,
address wethfact,
address setting,
address lockaddr
) payable {
crowdpool_setting = CrowdPoolSettings(setting);
require(
msg.value >= crowdpool_setting.getLockFee(),
"Balance is insufficent"
);
manage_addr = manage;
WETH = IWETH(wethfact);
crowdpool_lock_forwarder = CrowdPoolLockForwarder(lockaddr);
}
function init_private(SharedStructs.CrowdPoolInfo memory _crowdpool_info)
external
{
require(msg.sender == manage_addr, "Only manage address is available");
crowdpool_info = _crowdpool_info;
tokeninfo.name = IERC20Metadata(_crowdpool_info.pool_token).name();
tokeninfo.symbol = IERC20Metadata(_crowdpool_info.pool_token).symbol();
tokeninfo.decimal = IERC20Metadata(_crowdpool_info.pool_token).decimals();
tokeninfo.totalsupply = IERC20Metadata(_crowdpool_info.pool_token)
.totalSupply();
}
function init_link(SharedStructs.CrowdPoolLink memory _link) external {
require(msg.sender == manage_addr, "Only manage address is available");
link = _link;
}
function init_fee() external {
require(msg.sender == manage_addr, "Only manage address is available");
crowdpool_fee_info.raised_fee = crowdpool_setting.getRasiedFee();
crowdpool_fee_info.sold_fee = crowdpool_setting.getSoldFee();
crowdpool_fee_info.referral_fee = crowdpool_setting.getRefferralFee();
crowdpool_fee_info.raise_fee_address = crowdpool_setting
.getRaisedFeeAddress();
crowdpool_fee_info.sole_fee_address = crowdpool_setting.getSoleFeeAddress();
crowdpool_fee_info.referral_fee_address = crowdpool_setting
.getReferralFeeAddress();
}
modifier onlyCrowdPoolOwner() {
require(crowdpool_info.crowdpool_owner == msg.sender, "NOT CROWDPOOL OWNER");
_;
}
function crowdpoolStatus() public view returns (uint256) {
if (status.force_failed) {
return 3;
}
if (
(block.timestamp > crowdpool_info.crowdpool_end) &&
(status.raised_amount < crowdpool_info.softcap)
) {
return 3;
}
if (status.raised_amount >= crowdpool_info.hardcap) {
return 2;
}
if (
(block.timestamp > crowdpool_info.crowdpool_end) &&
(status.raised_amount >= crowdpool_info.softcap)
) {
return 2;
}
if (
(block.timestamp >= crowdpool_info.crowdpool_start) &&
(block.timestamp <= crowdpool_info.crowdpool_end)
) {
return 1;
}
return 0;
}
function userDeposit() public payable nonReentrant {
require(crowdpoolStatus() == 1, "NOT ACTIVE");
require(crowdpool_info.pool_min <= msg.value, "balance is insufficent");
require(crowdpool_info.pool_max >= msg.value, "balance is too much");
BuyerInfo storage buyer = buyers[msg.sender];
uint256 amount_in = msg.value;
uint256 allowance = crowdpool_info.pool_max - buyer.base;
uint256 remaining = crowdpool_info.hardcap - status.raised_amount;
allowance = allowance > remaining ? remaining : allowance;
if (amount_in > allowance) {
amount_in = allowance;
}
uint256 tokensSold = (amount_in * crowdpool_info.token_rate) / (10**18);
require(tokensSold > 0, "ZERO TOKENS");
require(
tokensSold <=
IERC20(crowdpool_info.pool_token).balanceOf(address(this)),
"Token reamin error"
);
if (buyer.base == 0) {
status.num_buyers++;
}
buyers[msg.sender].base = buyers[msg.sender].base + amount_in;
buyers[msg.sender].sale = buyers[msg.sender].sale + tokensSold;
status.raised_amount = status.raised_amount + amount_in;
status.sold_amount = status.sold_amount + tokensSold;
if (amount_in < msg.value) {
payable(msg.sender).transfer(msg.value - amount_in);
}
emit UserDepsitedSuccess(msg.sender, msg.value);
}
function userWithdrawTokens() public nonReentrant {
require(status.lp_generation_complete, "AWAITING LP GENERATION");
BuyerInfo storage buyer = buyers[msg.sender];
uint256 tokensRemainingDenominator = status.sold_amount -
status.token_withdraw;
uint256 tokensOwed = (IERC20(crowdpool_info.pool_token).balanceOf(
address(this)
) * buyer.sale) / tokensRemainingDenominator;
require(tokensOwed > 0, "NOTHING TO WITHDRAW");
status.token_withdraw = status.token_withdraw + buyer.sale;
buyers[msg.sender].sale = 0;
buyers[msg.sender].base = 0;
TransferHelper.safeTransfer(
address(crowdpool_info.pool_token),
msg.sender,
tokensOwed
);
emit UserWithdrawTokensSuccess(tokensOwed);
}
function userWithdrawBaseTokens() public nonReentrant {
require(crowdpoolStatus() == 3, "NOT FAILED");
if (msg.sender == crowdpool_info.crowdpool_owner) {
ownerWithdrawTokens();
}
BuyerInfo storage buyer = buyers[msg.sender];
uint256 baseRemainingDenominator = status.raised_amount -
status.base_withdraw;
uint256 remainingBaseBalance = address(this).balance;
uint256 tokensOwed = (remainingBaseBalance * buyer.base) /
baseRemainingDenominator;
require(tokensOwed > 0, "NOTHING TO WITHDRAW");
status.base_withdraw = status.base_withdraw + buyer.base;
buyer.base = 0;
buyer.sale = 0;
address payable reciver = payable(msg.sender);
reciver.transfer(tokensOwed);
emit UserWithdrawSuccess(tokensOwed);
}
function ownerWithdrawTokens() private onlyCrowdPoolOwner {
require(crowdpoolStatus() == 3, "Only failed status");
TransferHelper.safeTransfer(
address(crowdpool_info.pool_token),
crowdpool_info.crowdpool_owner,
IERC20(crowdpool_info.pool_token).balanceOf(address(this))
);
emit UserWithdrawSuccess(
IERC20(crowdpool_info.pool_token).balanceOf(address(this))
);
}
function forceFailIfPairExists() public {
require(!status.lp_generation_complete && !status.force_failed);
if (
crowdpool_lock_forwarder.uniswapPairIsInitialised(
address(crowdpool_info.pool_token),
address(WETH)
)
) {
status.force_failed = true;
}
}
function addLiquidity() public nonReentrant onlyCrowdPoolOwner {
require(!status.lp_generation_complete, "GENERATION COMPLETE");
require(crowdpoolStatus() == 2, "NOT SUCCESS");
if (
crowdpool_lock_forwarder.uniswapPairIsInitialised(
address(crowdpool_info.pool_token),
address(WETH)
)
) {
status.force_failed = true;
emit AddLiquidtySuccess(0);
return;
}
uint256 crowdpool_raisedfee = (status.raised_amount *
crowdpool_setting.getRasiedFee()) / 100;
uint256 baseLiquidity = ((status.raised_amount - crowdpool_raisedfee) *
(crowdpool_info.liqudity_percent)) / 100;
uint256 tokenLiquidity = (baseLiquidity * crowdpool_info.listing_rate) /
(10**18);
require(tokenLiquidity > 0, "ZERO Tokens");
TransferHelper.safeApprove(
address(crowdpool_info.pool_token),
address(crowdpool_lock_forwarder),
tokenLiquidity
);
crowdpool_lock_forwarder.lockLiquidity{
value: crowdpool_setting.getLockFee() + baseLiquidity
}(
address(crowdpool_info.pool_token),
baseLiquidity,
tokenLiquidity,
crowdpool_info.lock_end,
crowdpool_info.crowdpool_owner
);
uint256 crowdpoolSoldFee = (status.sold_amount *
crowdpool_setting.getSoldFee()) / 100;
address payable reciver = payable(
address(crowdpool_fee_info.raise_fee_address)
);
reciver.transfer(crowdpool_raisedfee);
TransferHelper.safeTransfer(
address(crowdpool_info.pool_token),
crowdpool_fee_info.sole_fee_address,
crowdpoolSoldFee
);
uint256 remainingSBalance = IERC20(crowdpool_info.pool_token).balanceOf(
address(this)
);
if (remainingSBalance > status.sold_amount) {
uint256 burnAmount = remainingSBalance - status.sold_amount;
TransferHelper.safeTransfer(
address(crowdpool_info.pool_token),
0x000000000000000000000000000000000000dEaD,
burnAmount
);
}
uint256 remainingBaseBalance = address(this).balance;
address payable crowdpool_fee_reciver = payable(
address(crowdpool_info.crowdpool_owner)
);
crowdpool_fee_reciver.transfer(remainingBaseBalance);
status.lp_generation_complete = true;
emit AddLiquidtySuccess(1);
}
function destroy() public {
require(status.lp_generation_complete, "lp generation incomplete");
selfdestruct(crowdpool_info.crowdpool_owner);
}
}
文件 2 的 17:CrowdPoolFactory.sol
pragma solidity ^0.8.0;
import "./CrowdPool.sol";
contract CrowdPoolFactory {
function deploy(
address manage,
address wethfact,
address setting,
address lockaddr
) external payable returns (CrowdPoolV1) {
return
(new CrowdPoolV1){value: msg.value}(
manage,
wethfact,
setting,
lockaddr
);
}
}
文件 3 的 17:CrowdPoolLockForwarder.sol
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./CrowdPoolManage.sol";
import "../../interfaces/IWETH.sol";
import "../../interfaces/IUniswapV2Factory.sol";
import "../../interfaces/IUniswapV2Router02.sol";
import "../../interfaces/IUniswapV2Pair.sol";
import "../../LiquidityLock/LPLock.sol";
import "../TransferHelper.sol";
contract CrowdPoolLockForwarder {
LPLocker public lplocker;
IUniswapV2Factory public uniswapfactory;
IUniswapV2Router02 public uniswaprouter;
CrowdPoolManage manage;
IWETH public WETH;
mapping(address => address) public locked_lp_tokens;
mapping(address => address) public locked_lp_owner;
constructor(
address _manage,
address lplock_addrress,
address unifactaddr,
address unirouter,
address wethaddr
) public {
lplocker = LPLocker(lplock_addrress);
uniswapfactory = IUniswapV2Factory(unifactaddr);
uniswaprouter = IUniswapV2Router02(unirouter);
WETH = IWETH(wethaddr);
manage = CrowdPoolManage(_manage);
}
function uniswapPairIsInitialised(address _token0, address _token1)
public
view
returns (bool)
{
address pairAddress = uniswapfactory.getPair(_token0, _token1);
if (pairAddress == address(0)) {
return false;
}
uint256 balance = IERC20(_token0).balanceOf(pairAddress);
if (balance > 0) {
return true;
}
return false;
}
function lockLiquidity(
address _saleToken,
uint256 _baseAmount,
uint256 _saleAmount,
uint256 _unlock_date,
address payable _withdrawer
) external payable {
require(manage.IsRegistered(msg.sender), "CROWDPOOL NOT REGISTERED");
require(
msg.value >= lplocker.price() + _baseAmount,
"Balance is insufficient"
);
TransferHelper.safeTransferFrom(
address(_saleToken),
msg.sender,
address(this),
_saleAmount
);
TransferHelper.safeApprove(
address(_saleToken),
address(uniswaprouter),
_saleAmount
);
IUniswapV2Router02(address(uniswaprouter)).addLiquidityETH{
value: _baseAmount
}(
address(_saleToken),
_saleAmount,
0,
0,
payable(address(this)),
block.timestamp + 5 minutes
);
address pair = uniswapfactory.getPair(
address(WETH),
address(_saleToken)
);
uint256 totalLPTokensMinted = IUniswapV2Pair(pair).balanceOf(
address(this)
);
require(totalLPTokensMinted != 0, "LP creation failed");
TransferHelper.safeApprove(
pair,
address(lplocker),
totalLPTokensMinted
);
uint256 unlock_date = _unlock_date > 9999999999
? 9999999999
: _unlock_date;
lplocker.lpLock{value: lplocker.price()}(
pair,
totalLPTokensMinted,
unlock_date,
_withdrawer
);
locked_lp_tokens[address(_saleToken)] = pair;
locked_lp_owner[address(_saleToken)] = _withdrawer;
payable(_withdrawer).transfer(address(this).balance);
}
}
文件 4 的 17:CrowdPoolManage.sol
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "../TransferHelper.sol";
import "../CrowdPoolSettings.sol";
import "./SharedStructs.sol";
import "./CrowdPoolLockForwarder.sol";
import "./CrowdPoolFactory.sol";
import "./CrowdPool.sol";
contract CrowdPoolManage {
using EnumerableSet for EnumerableSet.AddressSet;
EnumerableSet.AddressSet private crowdpools;
CrowdPoolFactory internal crowdpoolFactory;
address public crowdpool_lock_forward_addr;
address public crowdpool_setting_addr;
CrowdPoolLockForwarder _lock;
address private uniswap_factory_address;
address private uniswap_pair_address;
address private weth_address;
address payable owner;
SharedStructs.CrowdPoolInfo crowdpool_info;
SharedStructs.CrowdPoolLink crowdpoollink;
CrowdPoolSettings public settings;
event OwnerWithdrawSuccess(uint256 value);
event CreateCrowdpoolSucess(address, address);
constructor(
address payable _owner,
address lock_addr,
address uniswapfactory_addr,
address uniswaprouter_Addr,
address weth_addr,
CrowdPoolFactory _crowdpoolFactory
) {
owner = _owner;
uniswap_factory_address = uniswapfactory_addr;
weth_address = weth_addr;
_lock = new CrowdPoolLockForwarder(
address(this),
lock_addr,
uniswapfactory_addr,
uniswaprouter_Addr,
weth_addr
);
crowdpool_lock_forward_addr = address(_lock);
CrowdPoolSettings _setting;
_setting = new CrowdPoolSettings(address(this), _owner, lock_addr);
_setting.init(owner, 0.01 ether, owner, 10, owner, 10, owner, 10);
crowdpool_setting_addr = address(_setting);
settings = CrowdPoolSettings(crowdpool_setting_addr);
crowdpoolFactory = _crowdpoolFactory;
}
function ownerWithdraw() public {
require(
msg.sender == settings.getCreateFeeAddress(),
"Only creater can withdraw"
);
address payable reciver = payable(settings.getCreateFeeAddress());
reciver.transfer(address(this).balance);
emit OwnerWithdrawSuccess(address(this).balance);
}
function calculateAmountRequired(
uint256 _amount,
uint256 _tokenPrice,
uint256 _listingRate,
uint256 _liquidityPercent,
uint256 _tokenFee
) public pure returns (uint256) {
uint256 tokenamount = (_amount * _tokenPrice) / (10**18);
uint256 TokenFee = (((_amount * _tokenFee) / 100) / 10**18) *
_tokenPrice;
uint256 liqudityrateamount = (_amount * _listingRate) / (10**18);
uint256 liquiditytoken = (liqudityrateamount * _liquidityPercent) / 100;
uint256 tokensRequiredForCrowdPool = tokenamount +
liquiditytoken +
TokenFee;
return tokensRequiredForCrowdPool;
}
function createCrowdPool(
SharedStructs.CrowdPoolInfo memory _crowdpool_info,
SharedStructs.CrowdPoolLink memory _crowdpoollink
) public payable {
crowdpool_info = _crowdpool_info;
crowdpoollink = _crowdpoollink;
if ( (crowdpool_info.crowdpool_end - crowdpool_info.crowdpool_start) < 1 weeks) {
crowdpool_info.crowdpool_end = crowdpool_info.crowdpool_start + 1 weeks;
}
if ( (crowdpool_info.lock_end - crowdpool_info.lock_start) < 4 weeks) {
crowdpool_info.lock_end = crowdpool_info.lock_start + 4 weeks;
}
require(
msg.value >= settings.getCrowdPoolCreateFee() + settings.getLockFee(),
"Balance is insufficent"
);
require(_crowdpool_info.token_rate > 0, "token rate is invalid");
require(
_crowdpool_info.pool_min < _crowdpool_info.pool_max,
"pool min/max in invalid"
);
require(
_crowdpool_info.softcap <= _crowdpool_info.hardcap,
"softcap/hardcap is invalid"
);
require(
_crowdpool_info.liqudity_percent >= 30 &&
_crowdpool_info.liqudity_percent <= 100,
"Liqudity percent is invalid"
);
require(_crowdpool_info.listing_rate > 0, "Listing rate is invalid");
require(
(_crowdpool_info.crowdpool_end - _crowdpool_info.crowdpool_start) > 0,
"CrowdPool start/end time is invalid"
);
require(
(_crowdpool_info.lock_end - _crowdpool_info.lock_start) >= 4 weeks,
"Lock end is invalid"
);
uint256 tokensRequiredForCrowdPool = calculateAmountRequired(
_crowdpool_info.hardcap,
_crowdpool_info.token_rate,
_crowdpool_info.listing_rate,
_crowdpool_info.liqudity_percent,
settings.getSoldFee()
);
CrowdPoolV1 newCrowdPool = crowdpoolFactory.deploy{
value: settings.getLockFee()
}(
address(this),
weth_address,
crowdpool_setting_addr,
crowdpool_lock_forward_addr
);
if (address(newCrowdPool) == address(0)) {
require(false, "Create crowdpool Failed");
}
TransferHelper.safeTransferFrom(
address(_crowdpool_info.pool_token),
address(msg.sender),
address(newCrowdPool),
tokensRequiredForCrowdPool
);
newCrowdPool.init_private(_crowdpool_info);
newCrowdPool.init_link(_crowdpoollink);
newCrowdPool.init_fee();
crowdpools.add(address(newCrowdPool));
emit CreateCrowdpoolSucess(address(newCrowdPool), address(msg.sender));
}
function getCount() external view returns (uint256) {
return crowdpools.length();
}
function getBalance() external view returns (uint256) {
return address(this).balance;
}
function getCrowdPoolAt(uint256 index) external view returns (address) {
return crowdpools.at(index);
}
function IsRegistered(address crowdpool_addr) external view returns (bool) {
return crowdpools.contains(crowdpool_addr);
}
}
文件 5 的 17:CrowdPoolSettings.sol
pragma solidity ^0.8.0;
interface ILpLocker {
function price() external pure returns (uint256);
}
contract CrowdPoolSettings {
address private owner;
address private manage;
ILpLocker locker;
struct SettingsInfo {
uint256 raised_fee;
uint256 sold_fee;
uint256 referral_fee;
uint256 crowdpool_create_fee;
address payable raise_fee_address;
address payable sole_fee_address;
address payable referral_fee_address;
address payable create_fee_address;
}
SettingsInfo public info;
modifier onlyOwner() {
require(owner == msg.sender, "Ownable: caller is not the owner");
_;
}
modifier onlyManager() {
require(manage == msg.sender, "Ownable: caller is not the manager");
_;
}
event setRaiseFeeAddrSuccess(address indexed addr);
event setRaisedFeeSuccess(uint256 num);
event setSoleFeeAddrSuccess(address indexed addr);
event setSoldFeeSuccess(uint256 num);
event setReferralFeeAddrSuccess(address addr);
event setReferralFeeSuccess(uint256 num);
event setCreateFeeAddrSuccess(address addr);
event setCreateFeeSuccess(uint256 num);
event setFeeInfoSuccess(uint256);
constructor(
address _manage,
address _owner,
address lockaddr
) public {
owner = _owner;
manage = _manage;
locker = ILpLocker(lockaddr);
}
function init(
address payable _crowdpool_create_fee_addr,
uint256 _crowdpool_create_fee,
address payable _raise_fee_addr,
uint256 _raised_fee,
address payable _sole_fee_address,
uint256 _sold_fee,
address payable _referral_fee_address,
uint256 _referral_fee
) public onlyManager {
info.crowdpool_create_fee = _crowdpool_create_fee;
info.raise_fee_address = _raise_fee_addr;
info.raised_fee = _raised_fee;
info.sole_fee_address = _sole_fee_address;
info.sold_fee = _sold_fee;
info.referral_fee_address = _referral_fee_address;
info.referral_fee = _referral_fee;
info.create_fee_address = _crowdpool_create_fee_addr;
}
function getRaisedFeeAddress()
external
view
returns (address payable _raise_fee_addr)
{
return info.raise_fee_address;
}
function setRaisedFeeAddress(address payable _raised_fee_addr)
external
onlyOwner
{
info.raise_fee_address = _raised_fee_addr;
emit setRaiseFeeAddrSuccess(info.raise_fee_address);
}
function getRasiedFee() external view returns (uint256) {
return info.raised_fee;
}
function setRaisedFee(uint256 _raised_fee) external onlyOwner {
info.raised_fee = _raised_fee;
emit setRaisedFeeSuccess(info.raised_fee);
}
function getSoleFeeAddress()
external
view
returns (address payable _sole_fee_address)
{
return info.sole_fee_address;
}
function setSoleFeeAddress(address payable _sole_fee_address)
external
onlyOwner
{
info.sole_fee_address = _sole_fee_address;
emit setSoleFeeAddrSuccess(info.sole_fee_address);
}
function getSoldFee() external view returns (uint256) {
return info.sold_fee;
}
function setSoldFee(uint256 _sold_fee) external onlyOwner {
info.sold_fee = _sold_fee;
emit setSoldFeeSuccess(info.sold_fee);
}
function getReferralFeeAddress() external view returns (address payable) {
return info.referral_fee_address;
}
function setReferralFeeAddress(address payable _referral_fee_address)
external
onlyOwner
{
info.sole_fee_address = _referral_fee_address;
emit setReferralFeeAddrSuccess(info.referral_fee_address);
}
function getRefferralFee() external view returns (uint256) {
return info.referral_fee;
}
function setRefferralFee(uint256 _referral_fee) external onlyOwner {
info.referral_fee = _referral_fee;
emit setReferralFeeSuccess(info.referral_fee);
}
function getLockFee() external view returns (uint256) {
return locker.price();
}
function getCrowdPoolCreateFee() external view returns (uint256) {
return info.crowdpool_create_fee;
}
function setSetCrowdPoolCreateFee(uint256 _crowdpool_create_fee)
external
onlyOwner
{
info.crowdpool_create_fee = _crowdpool_create_fee;
emit setCreateFeeSuccess(info.crowdpool_create_fee);
}
function getCreateFeeAddress() external view returns (address payable) {
return info.create_fee_address;
}
function setCreateFeeAddress(address payable _create_fee_address)
external
onlyOwner
{
info.create_fee_address = _create_fee_address;
emit setReferralFeeAddrSuccess(info.create_fee_address);
}
function setFeeInfo(
address payable _create_address,
address payable _raise_address,
address payable _sold_address,
uint256 _create_fee,
uint256 _raise_fee,
uint256 _sold_fee
) external onlyOwner {
info.create_fee_address = _create_address;
info.raise_fee_address = _raise_address;
info.sole_fee_address = _sold_address;
info.crowdpool_create_fee = _create_fee;
info.raised_fee = _raise_fee;
info.sold_fee = _sold_fee;
emit setFeeInfoSuccess(1);
}
}
文件 6 的 17:EnumerableSet.sol
pragma solidity ^0.8.0;
library EnumerableSet {
struct Set {
bytes32[] _values;
mapping(bytes32 => uint256) _indexes;
}
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
function _remove(Set storage set, bytes32 value) private returns (bool) {
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
set._values[toDeleteIndex] = lastValue;
set._indexes[lastValue] = valueIndex;
}
set._values.pop();
delete set._indexes[value];
return true;
} else {
return false;
}
}
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
struct Bytes32Set {
Set _inner;
}
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
assembly {
result := store
}
return result;
}
struct AddressSet {
Set _inner;
}
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
assembly {
result := store
}
return result;
}
struct UintSet {
Set _inner;
}
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
assembly {
result := store
}
return result;
}
}
文件 7 的 17:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
文件 8 的 17:IERC20Metadata.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
文件 9 的 17:IUniswapV2Factory.sol
pragma solidity ^0.8.0;
interface IUniswapV2Factory {
event PairCreated(
address indexed token0,
address indexed token1,
address pair,
uint256
);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB)
external
view
returns (address pair);
function allPairs(uint256) external view returns (address pair);
function allPairsLength() external view returns (uint256);
function createPair(address tokenA, address tokenB)
external
returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}
文件 10 的 17:IUniswapV2Pair.sol
pragma solidity ^0.8.0;
interface IUniswapV2Pair {
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
event Transfer(address indexed from, address indexed to, uint256 value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address owner) external view returns (uint256);
function allowance(address owner, address spender)
external
view
returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transfer(address to, uint256 value) external returns (bool);
function transferFrom(
address from,
address to,
uint256 value
) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint256);
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
event Burn(
address indexed sender,
uint256 amount0,
uint256 amount1,
address indexed to
);
event Swap(
address indexed sender,
uint256 amount0In,
uint256 amount1In,
uint256 amount0Out,
uint256 amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint256);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves()
external
view
returns (
uint112 reserve0,
uint112 reserve1,
uint32 blockTimestampLast
);
function price0CumulativeLast() external view returns (uint256);
function price1CumulativeLast() external view returns (uint256);
function kLast() external view returns (uint256);
function burn(address to)
external
returns (uint256 amount0, uint256 amount1);
function swap(
uint256 amount0Out,
uint256 amount1Out,
address to,
bytes calldata data
) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
文件 11 的 17:IUniswapV2Router01.sol
pragma solidity ^0.8.0;
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
)
external
returns (
uint256 amountA,
uint256 amountB,
uint256 liquidity
);
function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
)
external
payable
returns (
uint256 amountToken,
uint256 amountETH,
uint256 liquidity
);
function removeLiquidity(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
) external returns (uint256 amountA, uint256 amountB);
function removeLiquidityETH(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountToken, uint256 amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountA, uint256 amountB);
function removeLiquidityETHWithPermit(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountToken, uint256 amountETH);
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapTokensForExactTokens(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactETHForTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable returns (uint256[] memory amounts);
function swapTokensForExactETH(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactTokensForETH(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapETHForExactTokens(
uint256 amountOut,
address[] calldata path,
address to,
uint256 deadline
) external payable returns (uint256[] memory amounts);
function quote(
uint256 amountA,
uint256 reserveA,
uint256 reserveB
) external pure returns (uint256 amountB);
function getAmountOut(
uint256 amountIn,
uint256 reserveIn,
uint256 reserveOut
) external pure returns (uint256 amountOut);
function getAmountIn(
uint256 amountOut,
uint256 reserveIn,
uint256 reserveOut
) external pure returns (uint256 amountIn);
function getAmountsOut(uint256 amountIn, address[] calldata path)
external
view
returns (uint256[] memory amounts);
function getAmountsIn(uint256 amountOut, address[] calldata path)
external
view
returns (uint256[] memory amounts);
}
文件 12 的 17:IUniswapV2Router02.sol
pragma solidity ^0.8.0;
import "./IUniswapV2Router01.sol";
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
}
文件 13 的 17:IWETH.sol
pragma solidity ^0.8.0;
interface IWETH {
function deposit() external payable;
function transfer(address to, uint256 value) external returns (bool);
function transferFrom(
address src,
address dst,
uint256 wad
) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function balanceOf(address owner) external view returns (uint256);
function decimals() external view returns (uint256);
}
文件 14 的 17:LPLock.sol
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract LPLocker {
address public owner;
uint256 public price;
uint256 public penaltyfee;
struct holder {
address holderAddress;
mapping(address => Token) tokens;
}
struct Token {
uint256 balance;
address tokenAddress;
uint256 unlockTime;
}
modifier onlyOwner() {
require(msg.sender == owner, "Only available to the contract owner.");
_;
}
mapping(address => holder) public holders;
constructor(address _owner, uint256 _price) {
owner = _owner;
price = _price;
penaltyfee = 10;
}
event Hold(
address indexed holder,
address token,
uint256 amount,
uint256 unlockTime
);
event PanicWithdraw(
address indexed holder,
address token,
uint256 amount,
uint256 unlockTime
);
event Withdrawal(address indexed holder, address token, uint256 amount);
event FeesClaimed();
event SetOwnerSuccess(address owner);
event SetPriceSuccess(uint256 _price);
event SetPenaltyFeeSuccess(uint256 _fee);
event OwnerWithdrawSuccess(uint256 amount);
function lpLock(
address token,
uint256 amount,
uint256 unlockTime,
address withdrawer
) public payable {
require(msg.value >= price, "Required price is low");
holder storage holder0 = holders[withdrawer];
holder0.holderAddress = withdrawer;
Token storage lockedToken = holders[withdrawer].tokens[token];
if (lockedToken.balance > 0) {
lockedToken.balance += amount;
if (lockedToken.unlockTime < unlockTime) {
lockedToken.unlockTime = unlockTime;
}
} else {
holders[withdrawer].tokens[token] = Token(
amount,
token,
unlockTime
);
}
IERC20(token).transferFrom(withdrawer, address(this), amount);
emit Hold(withdrawer, token, amount, unlockTime);
}
function withdraw(address token) public {
holder storage holder0 = holders[msg.sender];
require(
msg.sender == holder0.holderAddress,
"Only available to the token owner."
);
require(
block.timestamp > holder0.tokens[token].unlockTime,
"Unlock time not reached yet."
);
uint256 amount = holder0.tokens[token].balance;
holder0.tokens[token].balance = 0;
IERC20(token).transfer(msg.sender, amount);
emit Withdrawal(msg.sender, token, amount);
}
function panicWithdraw(address token) public {
holder storage holder0 = holders[msg.sender];
require(
msg.sender == holder0.holderAddress,
"Only available to the token owner."
);
uint256 feeAmount = (holder0.tokens[token].balance / 100) * penaltyfee;
uint256 withdrawalAmount = holder0.tokens[token].balance - feeAmount;
holder0.tokens[token].balance = 0;
IERC20(token).transfer(msg.sender, withdrawalAmount);
IERC20(token).transfer(owner, feeAmount);
emit PanicWithdraw(
msg.sender,
token,
withdrawalAmount,
holder0.tokens[token].unlockTime
);
}
function OwnerWithdraw() public onlyOwner {
uint256 amount = address(this).balance;
address payable ownerAddress = payable(owner);
ownerAddress.transfer(amount);
emit OwnerWithdrawSuccess(amount);
}
function getcurtime() public view returns (uint256) {
return block.timestamp;
}
function GetBalance(address token) public view returns (uint256) {
Token storage lockedToken = holders[msg.sender].tokens[token];
return lockedToken.balance;
}
function SetOwner(address contractowner) public onlyOwner {
owner = contractowner;
emit SetOwnerSuccess(owner);
}
function SetPrice(uint256 _price) public onlyOwner {
price = _price;
emit SetPriceSuccess(price);
}
function SetPenaltyFee(uint256 _penaltyfee) public onlyOwner {
penaltyfee = _penaltyfee;
emit SetPenaltyFeeSuccess(penaltyfee);
}
function GetUnlockTime(address token) public view returns (uint256) {
Token storage lockedToken = holders[msg.sender].tokens[token];
return lockedToken.unlockTime;
}
}
文件 15 的 17:ReentrancyGuard.sol
pragma solidity ^0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
}
function _nonReentrantAfter() private {
_status = _NOT_ENTERED;
}
}
文件 16 的 17:SharedStructs.sol
pragma solidity ^0.8.0;
library SharedStructs {
struct CrowdPoolInfo {
address payable crowdpool_owner;
address pool_token;
uint256 token_rate;
uint256 pool_min;
uint256 pool_max;
uint256 hardcap;
uint256 softcap;
uint256 liqudity_percent;
uint256 listing_rate;
uint256 lock_end;
uint256 lock_start;
uint256 crowdpool_end;
uint256 crowdpool_start;
}
struct CrowdPoolLink {
string color;
string website_link;
string twitter_link;
string key_val;
string telegram_link;
}
}
文件 17 的 17:TransferHelper.sol
pragma solidity ^0.8.0;
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(
abi.encodeWithSelector(0x095ea7b3, to, value)
);
require(
success && (data.length == 0 || abi.decode(data, (bool))),
"TransferHelper: APPROVE_FAILED"
);
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(
abi.encodeWithSelector(0xa9059cbb, to, value)
);
require(
success && (data.length == 0 || abi.decode(data, (bool))),
"TransferHelper: TRANSFER_FAILED"
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(
abi.encodeWithSelector(0x23b872dd, from, to, value)
);
require(
success && (data.length == 0 || abi.decode(data, (bool))),
"TransferHelper: TRANSFER_FROM_FAILED"
);
}
function safeTransferBaseToken(
address token,
address payable to,
uint256 value,
bool isERC20
) internal {
if (!isERC20) {
to.transfer(value);
} else {
(bool success, bytes memory data) = token.call(
abi.encodeWithSelector(0xa9059cbb, to, value)
);
require(
success && (data.length == 0 || abi.decode(data, (bool))),
"TransferHelper: TRANSFER_FAILED"
);
}
}
}
{
"compilationTarget": {
"contracts/CrowdPool/Meter/CrowdPoolManage.sol": "CrowdPoolManage"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 5000
},
"remappings": []
}
[{"inputs":[{"internalType":"address payable","name":"_owner","type":"address"},{"internalType":"address","name":"lock_addr","type":"address"},{"internalType":"address","name":"uniswapfactory_addr","type":"address"},{"internalType":"address","name":"uniswaprouter_Addr","type":"address"},{"internalType":"address","name":"weth_addr","type":"address"},{"internalType":"contract CrowdPoolFactory","name":"_crowdpoolFactory","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"","type":"address"},{"indexed":false,"internalType":"address","name":"","type":"address"}],"name":"CreateCrowdpoolSucess","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"OwnerWithdrawSuccess","type":"event"},{"inputs":[{"internalType":"address","name":"crowdpool_addr","type":"address"}],"name":"IsRegistered","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_tokenPrice","type":"uint256"},{"internalType":"uint256","name":"_listingRate","type":"uint256"},{"internalType":"uint256","name":"_liquidityPercent","type":"uint256"},{"internalType":"uint256","name":"_tokenFee","type":"uint256"}],"name":"calculateAmountRequired","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"address payable","name":"crowdpool_owner","type":"address"},{"internalType":"address","name":"pool_token","type":"address"},{"internalType":"uint256","name":"token_rate","type":"uint256"},{"internalType":"uint256","name":"pool_min","type":"uint256"},{"internalType":"uint256","name":"pool_max","type":"uint256"},{"internalType":"uint256","name":"hardcap","type":"uint256"},{"internalType":"uint256","name":"softcap","type":"uint256"},{"internalType":"uint256","name":"liqudity_percent","type":"uint256"},{"internalType":"uint256","name":"listing_rate","type":"uint256"},{"internalType":"uint256","name":"lock_end","type":"uint256"},{"internalType":"uint256","name":"lock_start","type":"uint256"},{"internalType":"uint256","name":"crowdpool_end","type":"uint256"},{"internalType":"uint256","name":"crowdpool_start","type":"uint256"}],"internalType":"struct SharedStructs.CrowdPoolInfo","name":"_crowdpool_info","type":"tuple"},{"components":[{"internalType":"string","name":"color","type":"string"},{"internalType":"string","name":"website_link","type":"string"},{"internalType":"string","name":"twitter_link","type":"string"},{"internalType":"string","name":"key_val","type":"string"},{"internalType":"string","name":"telegram_link","type":"string"}],"internalType":"struct SharedStructs.CrowdPoolLink","name":"_crowdpoollink","type":"tuple"}],"name":"createCrowdPool","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"crowdpool_lock_forward_addr","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"crowdpool_setting_addr","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getCrowdPoolAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ownerWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"settings","outputs":[{"internalType":"contract CrowdPoolSettings","name":"","type":"address"}],"stateMutability":"view","type":"function"}]