文件 1 的 13:Address.sol
pragma solidity >=0.6.2 <0.8.0;
library Address {
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly { size := extcodesize(account) }
return size > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{ value: value }(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 2 的 13:BondlyLaunchpad.sol
pragma solidity ^0.7.3;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155MetadataURI.sol";
import "@openzeppelin/contracts/cryptography/MerkleProof.sol";
contract BondlyLaunchPad is Ownable {
using Strings for string;
using SafeMath for uint256;
using Address for address;
using SafeERC20 for ERC20;
using MerkleProof for bytes32[];
uint256 public _currentCardId = 0;
address payable public _salesperson;
bool public _saleStarted = false;
uint256[] times;
uint256[] limitsPerWallet;
uint256[] tiers;
struct Card {
uint256 cardId;
uint256 tokenId;
uint256 totalAmount;
uint256 currentAmount;
uint256 basePrice;
address contractAddress;
address paymentToken;
bool isFinished;
}
struct History {
mapping(uint256 => mapping(address => uint256)) purchasedHistories;
}
event CreateCard(
address indexed _from,
uint256 _cardId,
address indexed _contractAddress,
uint256 _tokenId,
uint256 _totalAmount,
uint256 _basePrice
);
event PurchaseCard(address indexed _from, uint256 _cardId, uint256 _amount);
event CardChanged(uint256 _cardId);
mapping(uint256 => Card) public _cards;
mapping(address => bool) public _blacklist;
bytes32 public _whitelistRoot;
mapping(address => History) private _history;
constructor() {
_salesperson = msg.sender;
}
function setSalesPerson(address payable newSalesPerson) external onlyOwner {
_salesperson = newSalesPerson;
}
function startSale() external onlyOwner {
_saleStarted = true;
}
function stopSale() external onlyOwner {
_saleStarted = false;
}
function createCard(
address _contractAddress,
uint256 _tokenId,
uint256 _totalAmount,
address _paymentTokenAddress,
uint256 _basePrice
) external onlyOwner {
IERC1155 _contract = IERC1155(_contractAddress);
require(
_contract.balanceOf(_salesperson, _tokenId) >= _totalAmount,
"Initial supply cannot be more than available supply"
);
require(
_contract.isApprovedForAll(_salesperson, address(this)) == true,
"Contract must be whitelisted by owner"
);
uint256 _id = _getNextCardID();
_incrementCardId();
Card memory _newCard;
_newCard.cardId = _id;
_newCard.contractAddress = _contractAddress;
_newCard.tokenId = _tokenId;
_newCard.totalAmount = _totalAmount;
_newCard.currentAmount = _totalAmount;
_newCard.basePrice = _basePrice;
_newCard.paymentToken = _paymentTokenAddress;
_newCard.isFinished = false;
_cards[_id] = _newCard;
emit CreateCard(
msg.sender,
_id,
_contractAddress,
_tokenId,
_totalAmount,
_basePrice
);
}
function isEligbleToBuy(uint256 _cardId, uint256 tier, bytes32[] calldata whitelistProof) public view returns (uint256) {
if (_blacklist[msg.sender] == true) return 0;
if (_saleStarted == false) return 0;
if(tier != 0){
if(! verifyWhitelist(msg.sender,tier,whitelistProof)){
return 0;
}
}
Card memory _currentCard = _cards[_cardId];
if (times.length == 0) return 0;
for (uint256 i = 0; i < times.length; i++) {
if (
block.timestamp >= times[i] &&
tier == tiers[i]
) {
History storage _currentHistory =
_history[_currentCard.contractAddress];
uint256 _currentBoughtAmount =
_currentHistory.purchasedHistories[_currentCard.tokenId][
msg.sender
];
uint256 _limitPerWallet = limitsPerWallet[i];
if (_currentBoughtAmount >= _limitPerWallet) return 0;
if (
_currentCard.currentAmount <=
_limitPerWallet.sub(_currentBoughtAmount)
) return _currentCard.currentAmount;
return _limitPerWallet.sub(_currentBoughtAmount);
}
}
return 0;
}
function purchaseNFT(uint256 _cardId, uint256 _amount, uint256 tier, bytes32[] calldata whitelistProof) external payable {
require(_blacklist[msg.sender] == false, "you are blocked");
require(_saleStarted == true, "Sale stopped");
Card memory _currentCard = _cards[_cardId];
require(_currentCard.isFinished == false, "Card is finished");
if(tier != 0){
require(verifyWhitelist(msg.sender,tier,whitelistProof),"Invalid proof for whitelist");
}
uint256 startTime;
uint256 _limitPerWallet;
for (uint256 i = 0; i < tiers.length; i++) {
if (tiers[i] == tier) {
startTime = times[i];
_limitPerWallet = limitsPerWallet[i];
}
}
require(
startTime != 0 && startTime <= block.timestamp,
"wait for sale start"
);
require(
_currentCard.currentAmount >= _amount,
"Order exceeds the max number of available NFTs"
);
History storage _currentHistory =
_history[_currentCard.contractAddress];
uint256 _currentBoughtAmount =
_currentHistory.purchasedHistories[_currentCard.tokenId][
msg.sender
];
require(
_currentBoughtAmount < _limitPerWallet,
"Order exceeds the max limit of NFTs per wallet"
);
uint256 availableAmount = _limitPerWallet.sub(_currentBoughtAmount);
if (availableAmount > _amount) {
availableAmount = _amount;
}
uint256 _price = _currentCard.basePrice.mul(availableAmount);
require(
_currentCard.paymentToken == address(0) ||
ERC20(_currentCard.paymentToken).allowance(
msg.sender,
address(this)
) >=
_price,
"Need to Approve payment"
);
if (_currentCard.paymentToken == address(0)) {
require(msg.value >= _price, "Not enough funds to purchase");
uint256 overPrice = msg.value - _price;
_salesperson.transfer(_price);
if (overPrice > 0) msg.sender.transfer(overPrice);
} else {
ERC20(_currentCard.paymentToken).transferFrom(
msg.sender,
_salesperson,
_price
);
}
IERC1155(_currentCard.contractAddress).safeTransferFrom(
_salesperson,
msg.sender,
_currentCard.tokenId,
availableAmount,
""
);
_cards[_cardId].currentAmount = _cards[_cardId].currentAmount.sub(
availableAmount
);
_currentHistory.purchasedHistories[_currentCard.tokenId][
msg.sender
] = _currentBoughtAmount.add(availableAmount);
emit PurchaseCard(msg.sender, _cardId, availableAmount);
}
function _getNextCardID() private view returns (uint256) {
return _currentCardId.add(1);
}
function _incrementCardId() private {
_currentCardId++;
}
function cancelCard(uint256 _cardId) external onlyOwner {
_cards[_cardId].isFinished = true;
emit CardChanged(_cardId);
}
function _setTier(
uint256 _tier,
uint256 _startTime,
uint256 _limitPerWallet
) private {
for (uint256 i = 0; i < tiers.length; i++) {
if (tiers[i] == _tier) {
times[i] = _startTime;
limitsPerWallet[i] = _limitPerWallet;
return;
}
}
tiers.push(_tier);
times.push(_startTime);
limitsPerWallet.push(_limitPerWallet);
}
function setTier(
uint256 _tier,
uint256 _startTime,
uint256 _limitPerWallet
) external onlyOwner {
_setTier(_tier, _startTime, _limitPerWallet);
}
function setTiers(
uint256[] calldata _tiers,
uint256[] calldata _startTimes,
uint256[] calldata _limitsPerWallet
) external onlyOwner{
require(_tiers.length == _startTimes.length &&
_tiers.length == _limitsPerWallet.length,
"Input array lengths mismatch");
for(uint256 i = 0; i < _tiers.length; i++){
_setTier(_tiers[i], _startTimes[i], _limitsPerWallet[i]);
}
}
function resumeCard(uint256 _cardId) external onlyOwner {
_cards[_cardId].isFinished = false;
emit CardChanged(_cardId);
}
function setCardPrice(uint256 _cardId, uint256 _newPrice)
external
onlyOwner
returns (bool)
{
_cards[_cardId].basePrice = _newPrice;
emit CardChanged(_cardId);
}
function setCardPaymentToken(uint256 _cardId, address _newAddr)
external
onlyOwner
returns (bool)
{
_cards[_cardId].paymentToken = _newAddr;
emit CardChanged(_cardId);
}
function addBlackListAddress(address addr) external onlyOwner {
_blacklist[addr] = true;
}
function batchAddBlackListAddress(address[] calldata addr)
external
onlyOwner
{
for (uint256 i = 0; i < addr.length; i++) {
_blacklist[addr[i]] = true;
}
}
function removeBlackListAddress(address addr) external onlyOwner {
_blacklist[addr] = false;
}
function batchRemoveBlackListAddress(address[] calldata addr)
external
onlyOwner
{
for (uint256 i = 0; i < addr.length; i++) {
_blacklist[addr[i]] = false;
}
}
function setWhitelistRoot(bytes32 merkleRoot) external onlyOwner{
_whitelistRoot = merkleRoot;
}
function isCardCompleted(uint256 _cardId) public view returns (bool) {
return _cards[_cardId].isFinished;
}
function isCardFree(uint256 _cardId) public view returns (bool) {
return _cards[_cardId].basePrice == 0;
}
function getCardContract(uint256 _cardId) public view returns (address) {
return _cards[_cardId].contractAddress;
}
function getCardPaymentContract(uint256 _cardId)
public
view
returns (address)
{
return _cards[_cardId].paymentToken;
}
function getCardTokenId(uint256 _cardId) public view returns (uint256) {
return _cards[_cardId].tokenId;
}
function getTierTimes()
public
view
returns (uint256[] memory, uint256[] memory)
{
return (tiers, times);
}
function getTierTime(uint256 _tier)
public
view
returns (uint256)
{
for(uint256 i = 0; i < tiers.length; i++){
if(tiers[i] == _tier){
return times[i];
}
}
return 0;
}
function getTierLimitsPerWallet()
public
view
returns (uint256[] memory, uint256[] memory)
{
return (tiers, times);
}
function getTierLimitPerWallet(uint256 _tier)
public
view
returns (uint256)
{
for(uint256 i = 0; i < tiers.length; i++)
{
if(tiers[i] == _tier){
return limitsPerWallet[i];
}
}
return 0;
}
function getCardTotalAmount(uint256 _cardId) public view returns (uint256) {
return _cards[_cardId].totalAmount;
}
function getCardCurrentAmount(uint256 _cardId)
public
view
returns (uint256)
{
return _cards[_cardId].currentAmount;
}
function getAllCardsPerContract(address _contractAddr)
public
view
returns (uint256[] memory, uint256[] memory)
{
uint256 count;
for (uint256 i = 1; i <= _currentCardId; i++) {
if (_cards[i].contractAddress == _contractAddr) {
count++;
}
}
uint256[] memory cardIds = new uint256[](count);
uint256[] memory tokenIds = new uint256[](count);
count = 0;
for (uint256 i = 1; i <= _currentCardId; i++) {
if (_cards[i].contractAddress == _contractAddr) {
cardIds[count] = i;
tokenIds[count] = _cards[i].tokenId;
count++;
}
}
return (cardIds, tokenIds);
}
function getActiveCardsPerContract(address _contractAddr)
public
view
returns (uint256[] memory, uint256[] memory)
{
uint256 count;
for (uint256 i = 1; i <= _currentCardId; i++) {
if (
_cards[i].contractAddress == _contractAddr &&
_cards[i].isFinished == false
) {
count++;
}
}
uint256[] memory cardIds = new uint256[](count);
uint256[] memory tokenIds = new uint256[](count);
count = 0;
for (uint256 i = 1; i <= _currentCardId; i++) {
if (
_cards[i].contractAddress == _contractAddr &&
_cards[i].isFinished == false
) {
cardIds[count] = i;
tokenIds[count] = _cards[i].tokenId;
count++;
}
}
return (cardIds, tokenIds);
}
function getClosedCardsPerContract(address _contractAddr)
public
view
returns (uint256[] memory, uint256[] memory)
{
uint256 count;
for (uint256 i = 1; i <= _currentCardId; i++) {
if (
_cards[i].contractAddress == _contractAddr &&
_cards[i].isFinished
) {
count++;
}
}
uint256[] memory cardIds = new uint256[](count);
uint256[] memory tokenIds = new uint256[](count);
count = 0;
for (uint256 i = 1; i <= _currentCardId; i++) {
if (
_cards[i].contractAddress == _contractAddr &&
_cards[i].isFinished
) {
cardIds[count] = i;
tokenIds[count] = _cards[i].tokenId;
count++;
}
}
return (cardIds, tokenIds);
}
function getCardBasePrice(uint256 _cardId) public view returns (uint256) {
return _cards[_cardId].basePrice;
}
function getCardURL(uint256 _cardId) public view returns (string memory) {
return
IERC1155MetadataURI(_cards[_cardId].contractAddress).uri(
_cards[_cardId].tokenId
);
}
function collect(address _token) external onlyOwner {
if (_token == address(0)) {
msg.sender.transfer(address(this).balance);
} else {
uint256 amount = ERC20(_token).balanceOf(address(this));
ERC20(_token).transfer(msg.sender, amount);
}
}
function verifyWhitelist(address user, uint256 tier, bytes32[] calldata whitelistProof) public view returns (bool){
bytes32 leaf = keccak256(abi.encodePacked(user,tier));
return whitelistProof.verify(_whitelistRoot, leaf);
}
}
文件 3 的 13:Context.sol
pragma solidity >=0.6.0 <0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
文件 4 的 13:ERC20.sol
pragma solidity >=0.6.0 <0.8.0;
import "../../utils/Context.sol";
import "./IERC20.sol";
import "../../math/SafeMath.sol";
contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
uint8 private _decimals;
constructor (string memory name_, string memory symbol_) public {
_name = name_;
_symbol = symbol_;
_decimals = 18;
}
function name() public view virtual returns (string memory) {
return _name;
}
function symbol() public view virtual returns (string memory) {
return _symbol;
}
function decimals() public view virtual returns (uint8) {
return _decimals;
}
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _setupDecimals(uint8 decimals_) internal virtual {
_decimals = decimals_;
}
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
文件 5 的 13:IERC1155.sol
pragma solidity >=0.6.2 <0.8.0;
import "../../introspection/IERC165.sol";
interface IERC1155 is IERC165 {
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
event TransferBatch(address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values);
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
event URI(string value, uint256 indexed id);
function balanceOf(address account, uint256 id) external view returns (uint256);
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory);
function setApprovalForAll(address operator, bool approved) external;
function isApprovedForAll(address account, address operator) external view returns (bool);
function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external;
function safeBatchTransferFrom(address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) external;
}
文件 6 的 13:IERC1155MetadataURI.sol
pragma solidity >=0.6.2 <0.8.0;
import "./IERC1155.sol";
interface IERC1155MetadataURI is IERC1155 {
function uri(uint256 id) external view returns (string memory);
}
文件 7 的 13:IERC165.sol
pragma solidity >=0.6.0 <0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 8 的 13:IERC20.sol
pragma solidity >=0.6.0 <0.8.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, 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 sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 9 的 13:MerkleProof.sol
pragma solidity >=0.6.0 <0.8.0;
library MerkleProof {
function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
bytes32 proofElement = proof[i];
if (computedHash <= proofElement) {
computedHash = keccak256(abi.encodePacked(computedHash, proofElement));
} else {
computedHash = keccak256(abi.encodePacked(proofElement, computedHash));
}
}
return computedHash == root;
}
}
文件 10 的 13:Ownable.sol
pragma solidity >=0.6.0 <0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
文件 11 的 13:SafeERC20.sol
pragma solidity >=0.6.0 <0.8.0;
import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(IERC20 token, address spender, uint256 value) internal {
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
文件 12 的 13:SafeMath.sol
pragma solidity >=0.6.0 <0.8.0;
library SafeMath {
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
}
文件 13 的 13:Strings.sol
pragma solidity >=0.6.0 <0.8.0;
library Strings {
function toString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
uint256 index = digits - 1;
temp = value;
while (temp != 0) {
buffer[index--] = bytes1(uint8(48 + temp % 10));
temp /= 10;
}
return string(buffer);
}
}
{
"compilationTarget": {
"contracts/BondlyLaunchpad.sol": "BondlyLaunchPad"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_cardId","type":"uint256"}],"name":"CardChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":false,"internalType":"uint256","name":"_cardId","type":"uint256"},{"indexed":true,"internalType":"address","name":"_contractAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"_tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_totalAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_basePrice","type":"uint256"}],"name":"CreateCard","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":false,"internalType":"uint256","name":"_cardId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"PurchaseCard","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"_blacklist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"_cards","outputs":[{"internalType":"uint256","name":"cardId","type":"uint256"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"totalAmount","type":"uint256"},{"internalType":"uint256","name":"currentAmount","type":"uint256"},{"internalType":"uint256","name":"basePrice","type":"uint256"},{"internalType":"address","name":"contractAddress","type":"address"},{"internalType":"address","name":"paymentToken","type":"address"},{"internalType":"bool","name":"isFinished","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_currentCardId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_saleStarted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_salesperson","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_whitelistRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"addBlackListAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"addr","type":"address[]"}],"name":"batchAddBlackListAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"addr","type":"address[]"}],"name":"batchRemoveBlackListAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cardId","type":"uint256"}],"name":"cancelCard","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"collect","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_contractAddress","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_totalAmount","type":"uint256"},{"internalType":"address","name":"_paymentTokenAddress","type":"address"},{"internalType":"uint256","name":"_basePrice","type":"uint256"}],"name":"createCard","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_contractAddr","type":"address"}],"name":"getActiveCardsPerContract","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_contractAddr","type":"address"}],"name":"getAllCardsPerContract","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cardId","type":"uint256"}],"name":"getCardBasePrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cardId","type":"uint256"}],"name":"getCardContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cardId","type":"uint256"}],"name":"getCardCurrentAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cardId","type":"uint256"}],"name":"getCardPaymentContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cardId","type":"uint256"}],"name":"getCardTokenId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cardId","type":"uint256"}],"name":"getCardTotalAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cardId","type":"uint256"}],"name":"getCardURL","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_contractAddr","type":"address"}],"name":"getClosedCardsPerContract","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tier","type":"uint256"}],"name":"getTierLimitPerWallet","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTierLimitsPerWallet","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tier","type":"uint256"}],"name":"getTierTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTierTimes","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cardId","type":"uint256"}],"name":"isCardCompleted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cardId","type":"uint256"}],"name":"isCardFree","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cardId","type":"uint256"},{"internalType":"uint256","name":"tier","type":"uint256"},{"internalType":"bytes32[]","name":"whitelistProof","type":"bytes32[]"}],"name":"isEligbleToBuy","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cardId","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"tier","type":"uint256"},{"internalType":"bytes32[]","name":"whitelistProof","type":"bytes32[]"}],"name":"purchaseNFT","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"removeBlackListAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cardId","type":"uint256"}],"name":"resumeCard","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cardId","type":"uint256"},{"internalType":"address","name":"_newAddr","type":"address"}],"name":"setCardPaymentToken","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_cardId","type":"uint256"},{"internalType":"uint256","name":"_newPrice","type":"uint256"}],"name":"setCardPrice","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"newSalesPerson","type":"address"}],"name":"setSalesPerson","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tier","type":"uint256"},{"internalType":"uint256","name":"_startTime","type":"uint256"},{"internalType":"uint256","name":"_limitPerWallet","type":"uint256"}],"name":"setTier","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_tiers","type":"uint256[]"},{"internalType":"uint256[]","name":"_startTimes","type":"uint256[]"},{"internalType":"uint256[]","name":"_limitsPerWallet","type":"uint256[]"}],"name":"setTiers","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"}],"name":"setWhitelistRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"startSale","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stopSale","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"tier","type":"uint256"},{"internalType":"bytes32[]","name":"whitelistProof","type":"bytes32[]"}],"name":"verifyWhitelist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]