编译器
0.8.17+commit.8df45f5f
文件 1 的 7:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 2 的 7:IERC1155.sol
pragma solidity ^0.8.0;
import "../../utils/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;
}
文件 3 的 7:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 4 的 7:IStarterPackPurchase.sol
import { StarterPackPurchaseLib } from "../libraries/StarterPackPurchaseLib.sol";
pragma solidity 0.8.17;
interface IStarterPackPurchase {
error Disabled();
error ParallelAlreadyReceived(address user);
error CardBackAlreadyReceived(address user);
error InvalidLength();
error InvalidPayment(uint256 amount);
error InvalidCardBack(uint256 cardBackId);
error ParallelPackSoldOut(uint256 parallelId);
event PackPriceSet(uint256 packPrice);
event PackSet(
StarterPackPurchaseLib.Parallel indexed parallelId,
uint256[] cardIds,
uint256[] cardAmounts
);
event IsDisabledSet(bool isDisabled);
event AllowlistSet(address[] allowlist, bool val);
event ParallelAlphaSet(address indexed parallelAlpha);
event PullFromAddressSet(address indexed pullFromAddress);
event PacksPurchased(
address indexed user,
StarterPackPurchaseLib.Parallel[] parallelIds
);
}
文件 5 的 7:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 6 的 7:StarterPackPurchase.sol
pragma solidity 0.8.17;
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IERC1155 } from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import { IStarterPackPurchase } from "./interfaces/IStarterPackPurchase.sol";
import { StarterPackPurchaseLib } from "./libraries/StarterPackPurchaseLib.sol";
contract StarterPackPurchase is IStarterPackPurchase, Ownable {
mapping(StarterPackPurchaseLib.Parallel => StarterPackPurchaseLib.ParallelPack)
internal parallelPacks;
mapping(StarterPackPurchaseLib.Parallel => uint256)
public parallelPacksSupply;
mapping(StarterPackPurchaseLib.Parallel => uint256)
public parallelPacksPurchased;
mapping(address => bool) public allowlist;
bool public isDisabled = true;
uint256 public packPrice = 0.01 ether;
address public pullFromAddress = 0xF61036949E2D584CCAd40Ddad45C37bdf49E9c78;
IERC1155 public parallelAlpha =
IERC1155(0x206571b68c66E1d112b74d65695043ad2b5F95D5);
function getPack(
StarterPackPurchaseLib.Parallel _parallelId
) external view returns (uint256[] memory, uint256[] memory) {
return (
parallelPacks[_parallelId].cardIds,
parallelPacks[_parallelId].cardAmounts
);
}
function purchasePack(
StarterPackPurchaseLib.Parallel[] calldata _parallelIds
) external payable {
if (msg.value != packPrice * _parallelIds.length)
revert InvalidPayment(msg.value);
if (isDisabled && !allowlist[_msgSender()]) revert Disabled();
bool[] memory parallelPackReceived = new bool[](5);
for (uint256 i = 0; i < _parallelIds.length; i++) {
StarterPackPurchaseLib.Parallel _parallelId = _parallelIds[i];
if (parallelPackReceived[uint256(_parallelId)])
revert ParallelAlreadyReceived(_msgSender());
if (
parallelPacksPurchased[_parallelId] >=
parallelPacksSupply[_parallelId]
) revert ParallelPackSoldOut(uint256(_parallelId));
parallelAlpha.safeBatchTransferFrom(
pullFromAddress,
_msgSender(),
parallelPacks[_parallelId].cardIds,
parallelPacks[_parallelId].cardAmounts,
""
);
parallelPackReceived[uint256(_parallelId)] = true;
parallelPacksPurchased[_parallelId]++;
}
emit PacksPurchased(_msgSender(), _parallelIds);
}
function setDisabled(bool _isDisabled) external onlyOwner {
isDisabled = _isDisabled;
emit IsDisabledSet(_isDisabled);
}
function setParallelAlpha(IERC1155 _parallelAlpha) external onlyOwner {
parallelAlpha = IERC1155(_parallelAlpha);
emit ParallelAlphaSet(address(_parallelAlpha));
}
function setPullFromAddress(address _pullFromAddress) external onlyOwner {
pullFromAddress = _pullFromAddress;
emit PullFromAddressSet(_pullFromAddress);
}
function setPackPrice(uint256 _packPrice) external onlyOwner {
packPrice = _packPrice;
emit PackPriceSet(_packPrice);
}
function setPack(
StarterPackPurchaseLib.Parallel _parallelId,
uint256[] calldata _cardIds,
uint256[] calldata _cardAmounts,
uint256 _maxSupply
) external onlyOwner {
if (_cardIds.length != _cardAmounts.length) revert InvalidLength();
parallelPacks[_parallelId] = StarterPackPurchaseLib.ParallelPack({
cardIds: _cardIds,
cardAmounts: _cardAmounts
});
parallelPacksSupply[_parallelId] = _maxSupply;
emit PackSet(_parallelId, _cardIds, _cardAmounts);
}
function setAllowlist(
address[] calldata _allowlist,
bool _val
) external onlyOwner {
for (uint256 i = 0; i < _allowlist.length; i++) {
allowlist[_allowlist[i]] = _val;
}
emit AllowlistSet(_allowlist, _val);
}
function sweep() public onlyOwner {
(bool sent, ) = msg.sender.call{ value: address(this).balance }("");
require(sent, "Failed to send Ether");
}
function sweepToAddress(
uint _amount,
address payable _address
) public onlyOwner {
(bool sent, ) = _address.call{ value: _amount }("");
require(sent, "Failed to send Ether");
}
}
文件 7 的 7:StarterPackPurchaseLib.sol
pragma solidity 0.8.17;
library StarterPackPurchaseLib {
enum Parallel {
AUGENCORE,
EARTHEN,
KATHARI,
MARCOLIAN,
SHROUD
}
struct ParallelPack {
uint256[] cardIds;
uint256[] cardAmounts;
}
}
{
"compilationTarget": {
"contracts/packdrop/StarterPackPurchase.sol": "StarterPackPurchase"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"CardBackAlreadyReceived","type":"error"},{"inputs":[],"name":"Disabled","type":"error"},{"inputs":[{"internalType":"uint256","name":"cardBackId","type":"uint256"}],"name":"InvalidCardBack","type":"error"},{"inputs":[],"name":"InvalidLength","type":"error"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"InvalidPayment","type":"error"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"ParallelAlreadyReceived","type":"error"},{"inputs":[{"internalType":"uint256","name":"parallelId","type":"uint256"}],"name":"ParallelPackSoldOut","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address[]","name":"allowlist","type":"address[]"},{"indexed":false,"internalType":"bool","name":"val","type":"bool"}],"name":"AllowlistSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"isDisabled","type":"bool"}],"name":"IsDisabledSet","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":false,"internalType":"uint256","name":"packPrice","type":"uint256"}],"name":"PackPriceSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"enum StarterPackPurchaseLib.Parallel","name":"parallelId","type":"uint8"},{"indexed":false,"internalType":"uint256[]","name":"cardIds","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"cardAmounts","type":"uint256[]"}],"name":"PackSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"enum StarterPackPurchaseLib.Parallel[]","name":"parallelIds","type":"uint8[]"}],"name":"PacksPurchased","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"parallelAlpha","type":"address"}],"name":"ParallelAlphaSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pullFromAddress","type":"address"}],"name":"PullFromAddressSet","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"allowlist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum StarterPackPurchaseLib.Parallel","name":"_parallelId","type":"uint8"}],"name":"getPack","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isDisabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"packPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"parallelAlpha","outputs":[{"internalType":"contract IERC1155","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum StarterPackPurchaseLib.Parallel","name":"","type":"uint8"}],"name":"parallelPacksPurchased","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum StarterPackPurchaseLib.Parallel","name":"","type":"uint8"}],"name":"parallelPacksSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pullFromAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum StarterPackPurchaseLib.Parallel[]","name":"_parallelIds","type":"uint8[]"}],"name":"purchasePack","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_allowlist","type":"address[]"},{"internalType":"bool","name":"_val","type":"bool"}],"name":"setAllowlist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_isDisabled","type":"bool"}],"name":"setDisabled","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum StarterPackPurchaseLib.Parallel","name":"_parallelId","type":"uint8"},{"internalType":"uint256[]","name":"_cardIds","type":"uint256[]"},{"internalType":"uint256[]","name":"_cardAmounts","type":"uint256[]"},{"internalType":"uint256","name":"_maxSupply","type":"uint256"}],"name":"setPack","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_packPrice","type":"uint256"}],"name":"setPackPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC1155","name":"_parallelAlpha","type":"address"}],"name":"setParallelAlpha","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_pullFromAddress","type":"address"}],"name":"setPullFromAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sweep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address payable","name":"_address","type":"address"}],"name":"sweepToAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]