编译器
0.8.22+commit.4fc1097e
文件 1 的 12: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 的 12:ERC20.sol
pragma solidity >=0.8.0;
abstract contract ERC20 {
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
string public name;
string public symbol;
uint8 public immutable decimals;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
uint256 internal immutable INITIAL_CHAIN_ID;
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
mapping(address => uint256) public nonces;
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
INITIAL_CHAIN_ID = block.chainid;
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
}
function approve(address spender, uint256 amount) public virtual returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transfer(address to, uint256 amount) public virtual returns (bool) {
balanceOf[msg.sender] -= amount;
unchecked {
balanceOf[to] += amount;
}
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual returns (bool) {
uint256 allowed = allowance[from][msg.sender];
if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
balanceOf[from] -= amount;
unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");
unchecked {
address recoveredAddress = ecrecover(
keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
),
owner,
spender,
value,
nonces[owner]++,
deadline
)
)
)
),
v,
r,
s
);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");
allowance[recoveredAddress][spender] = value;
}
emit Approval(owner, spender, value);
}
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
}
function computeDomainSeparator() internal view virtual returns (bytes32) {
return
keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}
function _mint(address to, uint256 amount) internal virtual {
totalSupply += amount;
unchecked {
balanceOf[to] += amount;
}
emit Transfer(address(0), to, amount);
}
function _burn(address from, uint256 amount) internal virtual {
balanceOf[from] -= amount;
unchecked {
totalSupply -= amount;
}
emit Transfer(from, address(0), amount);
}
}
文件 3 的 12:ERC721.sol
pragma solidity >=0.8.0;
abstract contract ERC721 {
event Transfer(address indexed from, address indexed to, uint256 indexed id);
event Approval(address indexed owner, address indexed spender, uint256 indexed id);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
string public name;
string public symbol;
function tokenURI(uint256 id) public view virtual returns (string memory);
mapping(uint256 => address) internal _ownerOf;
mapping(address => uint256) internal _balanceOf;
function ownerOf(uint256 id) public view virtual returns (address owner) {
require((owner = _ownerOf[id]) != address(0), "NOT_MINTED");
}
function balanceOf(address owner) public view virtual returns (uint256) {
require(owner != address(0), "ZERO_ADDRESS");
return _balanceOf[owner];
}
mapping(uint256 => address) public getApproved;
mapping(address => mapping(address => bool)) public isApprovedForAll;
constructor(string memory _name, string memory _symbol) {
name = _name;
symbol = _symbol;
}
function approve(address spender, uint256 id) public virtual {
address owner = _ownerOf[id];
require(msg.sender == owner || isApprovedForAll[owner][msg.sender], "NOT_AUTHORIZED");
getApproved[id] = spender;
emit Approval(owner, spender, id);
}
function setApprovalForAll(address operator, bool approved) public virtual {
isApprovedForAll[msg.sender][operator] = approved;
emit ApprovalForAll(msg.sender, operator, approved);
}
function transferFrom(
address from,
address to,
uint256 id
) public virtual {
require(from == _ownerOf[id], "WRONG_FROM");
require(to != address(0), "INVALID_RECIPIENT");
require(
msg.sender == from || isApprovedForAll[from][msg.sender] || msg.sender == getApproved[id],
"NOT_AUTHORIZED"
);
unchecked {
_balanceOf[from]--;
_balanceOf[to]++;
}
_ownerOf[id] = to;
delete getApproved[id];
emit Transfer(from, to, id);
}
function safeTransferFrom(
address from,
address to,
uint256 id
) public virtual {
transferFrom(from, to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, "") ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
function safeTransferFrom(
address from,
address to,
uint256 id,
bytes calldata data
) public virtual {
transferFrom(from, to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, data) ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return
interfaceId == 0x01ffc9a7 ||
interfaceId == 0x80ac58cd ||
interfaceId == 0x5b5e139f;
}
function _mint(address to, uint256 id) internal virtual {
require(to != address(0), "INVALID_RECIPIENT");
require(_ownerOf[id] == address(0), "ALREADY_MINTED");
unchecked {
_balanceOf[to]++;
}
_ownerOf[id] = to;
emit Transfer(address(0), to, id);
}
function _burn(uint256 id) internal virtual {
address owner = _ownerOf[id];
require(owner != address(0), "NOT_MINTED");
unchecked {
_balanceOf[owner]--;
}
delete _ownerOf[id];
delete getApproved[id];
emit Transfer(owner, address(0), id);
}
function _safeMint(address to, uint256 id) internal virtual {
_mint(to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(msg.sender, address(0), id, "") ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
function _safeMint(
address to,
uint256 id,
bytes memory data
) internal virtual {
_mint(to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(msg.sender, address(0), id, data) ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
}
abstract contract ERC721TokenReceiver {
function onERC721Received(
address,
address,
uint256,
bytes calldata
) external virtual returns (bytes4) {
return ERC721TokenReceiver.onERC721Received.selector;
}
}
文件 4 的 12:KomodosRoost.sol
pragma solidity >=0.8.0;
import "@openzeppelin/contracts@4.8.0/utils/Strings.sol";
import "@openzeppelin/contracts@4.8.0/access/Ownable.sol";
import {ERC721} from "solmate/src/tokens/ERC721.sol";
contract KomodosRoost is ERC721, Ownable {
using Strings for uint256;
uint256 public constant HONOR_ALLOCATION = 33;
uint256 public constant CLAIM_ALLOCATION = 165;
uint256 public nextToClaim = HONOR_ALLOCATION;
uint256 public nextToMint = CLAIM_ALLOCATION;
address public minter = address(0);
address public courtAddress = address(0);
uint256 private claimsEnabledBlock;
mapping(address => uint256) private claimsRemaining;
string public tokenBaseURI;
event MinterUpdated(address minter);
event ClaimsEnabledBlockUpdated(uint256 claimsEnabledBlock);
event TokenBaseURIUpdated(string uri);
event EggMinted(uint256 indexed eggId, address indexed mintedTo);
event MetadataUpdate(uint256 _tokenId);
modifier onlyMinter() {
require(msg.sender == minter, "MINTER_ONLY");
_;
}
constructor(
address _courtAddress,
string memory _tokenBaseURI,
uint256 _claimsEnabledBlock
) ERC721("Komodo's Roost", "KOMODO") {
require(_courtAddress != address(0), "INVALID_COURT");
courtAddress = _courtAddress;
tokenBaseURI = _tokenBaseURI;
claimsEnabledBlock = _claimsEnabledBlock;
_transferOwnership(_courtAddress);
}
function emitMetadataUpdate(uint256 tokenId) public {
require(msg.sender == minter || msg.sender == courtAddress, "NOT_ALLOWED");
emit MetadataUpdate(tokenId);
}
function exists(uint256 id) public view returns (bool) {
return _ownerOf[id] != address(0);
}
function tokenURI(uint256 id) public view override returns (string memory) {
require(ownerOf(id) != address(0), "NOT_YET_MINTED");
return
bytes(tokenBaseURI).length > 0
? string(abi.encodePacked(tokenBaseURI, id.toString()))
: "";
}
function setMinter(address _minter) external onlyOwner {
minter = _minter;
emit MinterUpdated(_minter);
}
function setClaimsEnabledBlock(uint256 _newClaimsEnabledBlock)
external
onlyOwner
{
claimsEnabledBlock = _newClaimsEnabledBlock;
emit ClaimsEnabledBlockUpdated(_newClaimsEnabledBlock);
}
function setBaseTokenURI(string memory _tokenBaseURI) external onlyOwner {
tokenBaseURI = _tokenBaseURI;
emit TokenBaseURIUpdated(_tokenBaseURI);
}
function assignClaims(
address[] calldata addresses,
uint256[] calldata claimQuantities
) external onlyOwner {
require(
addresses.length == claimQuantities.length,
"MISMATCHING_LENGTHS"
);
for (uint256 i = 0; i < addresses.length; i++) {
claimsRemaining[addresses[i]] += claimQuantities[i];
}
}
function removeClaims(
address[] calldata addresses,
uint256[] calldata claimQuantities
) external onlyOwner {
require(
addresses.length == claimQuantities.length,
"MISMATCHING_LENGTHS"
);
for (uint256 i = 0; i < addresses.length; i++) {
require(
claimsRemaining[addresses[i]] >= claimQuantities[i],
"INVALID_CLAIMS_QUANTITY"
);
claimsRemaining[addresses[i]] -= claimQuantities[i];
}
}
function mint(address to) public onlyMinter {
_mint(to, nextToMint++);
emit EggMinted(nextToMint - 1, to);
}
function claimHonor() public onlyOwner {
for (uint256 i = 0; i < HONOR_ALLOCATION; i++) {
_mint(courtAddress, i);
emit EggMinted(i, courtAddress);
}
}
function claim(uint256 quantity) public {
require((block.number >= claimsEnabledBlock), "CLAIM_WINDOW_INACTIVE");
require(quantity > 0, "CLAIM_QTY_ZERO");
require(quantity <= claimsRemaining[msg.sender], "NO_CLAIMS_REMAINING");
require(
nextToClaim + quantity <= CLAIM_ALLOCATION,
"ALLOCATION_EXHAUSTED"
);
claimsRemaining[msg.sender] -= quantity;
for (uint256 i = 0; i < quantity; i++) {
_mint(msg.sender, nextToClaim++);
emit EggMinted(nextToClaim - 1, msg.sender);
}
}
function claimsAvailable(address claimer) public view returns (uint256) {
return
nextToClaim + claimsRemaining[claimer] <= CLAIM_ALLOCATION
? claimsRemaining[claimer]
: CLAIM_ALLOCATION - nextToClaim;
}
function claimAll() public {
claim(claimsAvailable(msg.sender));
}
function transferFrom(
address from,
address to,
uint256 id
) public override {
require(from == _ownerOf[id], "WRONG_FROM");
require(to != address(0), "INVALID_RECIPIENT");
require(
msg.sender == from ||
msg.sender == minter ||
isApprovedForAll[from][msg.sender] ||
msg.sender == getApproved[id],
"NOT_AUTHORIZED"
);
unchecked {
_balanceOf[from]--;
_balanceOf[to]++;
}
_ownerOf[id] = to;
delete getApproved[id];
emit Transfer(from, to, id);
}
}
文件 5 的 12:KomodosRoostNest.sol
pragma solidity >=0.8.0;
import "@openzeppelin/contracts@4.8.0/access/Ownable.sol";
import {LinearVRGDA} from "./VRGDAs/LinearVRGDA.sol";
import {ERC721TokenReceiver} from "solmate/src/tokens/ERC721.sol";
import {SafeTransferLib} from "solmate/src/utils/SafeTransferLib.sol";
import {toDaysWadUnsafe} from "solmate/src/utils/SignedWadMath.sol";
import {KomodosRoost} from "./KomodosRoost.sol";
contract KomodosRoostNest is LinearVRGDA, Ownable, ERC721TokenReceiver {
KomodosRoost public roost;
uint256 private soldQty = 0;
uint256 private startTime = 0;
uint256 private randNonce;
uint256 private constant MAX_ORDER_QTY = 50;
uint256 private constant MAX_SALE_ALLOCATION = 1069;
uint256 private constant MIN_KOMODO_RANK = 4;
uint256 private constant MAX_KOMODO_RANK = 10;
uint256 private constant GILA_KOMODO_RANK = 150;
mapping(uint256 => NestState) private nestStates;
mapping(address => uint256[]) private allNestedEggs;
uint256[] private komodoIdsRankWeighted;
bool public nestingActive = false;
struct NestState {
uint256 nestedTill;
uint256 nestedFor;
address nestedBy;
uint256 rank;
}
event FundsAssigned(uint256 timestamp);
event EggMinted(uint256 indexed eggId, address indexed mintedTo);
event EggNested(
uint256 indexed eggId,
address indexed nestedBy,
uint256 nestedFor
);
event EggStolen(
uint256 indexed eggId,
address indexed stolenFrom,
address indexed stolenBy,
uint256 stolenByKomodo
);
event EggHatched(
uint256 indexed eggId,
address indexed hatchedBy,
uint256 rank
);
modifier onlyGilaKomodo() {
require(
msg.sender == roost.ownerOf(0),
"Only the Legion of Gila may enter"
);
_;
}
constructor(
address _roostAddress,
int256 _targetPrice,
int256 _priceDecayPercent,
int256 _perTimeUnit,
uint256 _entropy
) LinearVRGDA(_targetPrice, _priceDecayPercent, _perTimeUnit) {
roost = KomodosRoost(_roostAddress);
randNonce = uint256(
keccak256(
abi.encodePacked(
blockhash(block.number - 1),
block.number,
block.coinbase,
block.prevrandao,
block.timestamp,
_entropy
)
)
);
_transferOwnership(roost.courtAddress());
}
function awaken() external onlyOwner {
require(startTime == 0, "ALREADY_AWAKE");
address courtAddress = roost.courtAddress();
nestStates[0] = NestState(0, 0, courtAddress, GILA_KOMODO_RANK);
emit EggHatched(0, courtAddress, GILA_KOMODO_RANK);
nestStates[1] = NestState(0, 0, courtAddress, MAX_KOMODO_RANK);
emit EggHatched(1, courtAddress, MAX_KOMODO_RANK);
for (uint256 i = 0; i < GILA_KOMODO_RANK; i++) {
komodoIdsRankWeighted.push(0);
}
for (uint256 i = 0; i < MAX_KOMODO_RANK; i++) {
komodoIdsRankWeighted.push(1);
}
nestingActive = true;
startTime = block.timestamp;
}
function disableNesting() external onlyOwner {
nestingActive = false;
}
function getPrice() public view returns (uint256) {
return
getVRGDAPrice(
toDaysWadUnsafe(block.timestamp - startTime),
soldQty
);
}
function mint(
uint256 quantity
) external payable returns (uint256 unitPrice) {
require(nestingActive, "NESTING_INACTIVE");
require(block.timestamp >= startTime, "SALE_INACTIVE");
require(soldQty + quantity <= MAX_SALE_ALLOCATION, "SUPPLY_EXHAUSTED");
require(quantity > 0 && quantity <= MAX_ORDER_QTY, "ORDER_QTY_INVALID");
unchecked {
unitPrice = getPrice();
uint256 totalPrice = quantity * unitPrice;
require(msg.value >= totalPrice, "UNDERPAID");
soldQty += quantity;
for (uint256 i = 0; i < quantity; i++) {
roost.mint(msg.sender);
emit EggMinted(roost.nextToMint() - 1, msg.sender);
}
SafeTransferLib.safeTransferETH(msg.sender, msg.value - totalPrice);
}
}
function withdraw() external onlyOwner {
payable(owner()).transfer(address(this).balance);
emit FundsAssigned(block.timestamp);
}
function isNestable(uint256 eggId) public view returns (bool) {
return
(nestStates[eggId].rank == 0) &&
(nestStates[eggId].nestedTill == 0) &&
roost.exists(eggId);
}
function nest(uint256 eggId, uint256 rank) public {
require(nestingActive, "NESTING_INACTIVE");
require(roost.ownerOf(eggId) == msg.sender, "NOT_THE_EGG_OWNER");
require(nestStates[eggId].rank == 0, "EGG_ALREADY_HATCHED");
require(nestStates[eggId].nestedTill == 0, "EGG_ALREADY_NESTED");
require(
rank >= MIN_KOMODO_RANK && rank <= MAX_KOMODO_RANK,
"INVALID_RANK"
);
uint256 nestingBlocks = calculateNestingBlocks(rank);
nestStates[eggId] = NestState(
block.number + nestingBlocks,
nestingBlocks,
msg.sender,
0
);
allNestedEggs[msg.sender].push(eggId);
emit EggNested(eggId, msg.sender, nestingBlocks);
roost.safeTransferFrom(msg.sender, address(this), eggId);
}
function nestAll(uint256[] calldata eggIds, uint256 rank) public {
for (uint256 i = 0; i < eggIds.length; ++i) {
nest(eggIds[i], rank);
}
}
function getPendingEggs(
address nester
) public view returns (uint256[] memory) {
uint256 count = 0;
for (uint256 i = 0; i < allNestedEggs[nester].length; i++) {
uint256 eggId = allNestedEggs[nester][i];
NestState storage nestState = nestStates[eggId];
if (
nestState.nestedTill != 0 && block.number < nestState.nestedTill
) {
++count;
}
}
uint256 idx = 0;
uint256[] memory eggIds = new uint256[](count);
for (uint256 i = 0; i < allNestedEggs[nester].length; i++) {
uint256 eggId = allNestedEggs[nester][i];
NestState storage nestState = nestStates[eggId];
if (
nestState.nestedTill != 0 && block.number < nestState.nestedTill
) {
eggIds[idx++] = eggId;
}
}
return eggIds;
}
function getHatchableEggs(
address nester
) public view returns (uint256[] memory) {
uint256 count = 0;
for (uint256 i = 0; i < allNestedEggs[nester].length; i++) {
uint256 eggId = allNestedEggs[nester][i];
NestState storage nestState = nestStates[eggId];
if (
nestState.nestedTill != 0 &&
block.number >= nestState.nestedTill
) {
++count;
}
}
uint256 idx = 0;
uint256[] memory eggIds = new uint256[](count);
for (uint256 i = 0; i < allNestedEggs[nester].length; i++) {
uint256 eggId = allNestedEggs[nester][i];
NestState storage nestState = nestStates[eggId];
if (
nestState.nestedTill != 0 &&
block.number >= nestState.nestedTill
) {
eggIds[idx++] = eggId;
}
}
return eggIds;
}
function hatch(uint256 eggId) public {
NestState storage nestState = nestStates[eggId];
require(nestState.rank == 0, "EGG_ALREADY_HATCHED");
require(nestState.nestedTill != 0, "EGG_NOT_YET_NESTED");
require(block.number >= nestState.nestedTill, "NESTING_INCOMPLETE");
require(
nestState.nestedBy == msg.sender || msg.sender == owner(),
"NOT_THE_NESTER_OR_CONTRACT_OWNER"
);
uint256 randomNumber = uint256(
keccak256(
abi.encodePacked(
blockhash(block.number - 1),
randNonce,
block.coinbase,
block.prevrandao,
block.timestamp
)
)
);
randNonce += 1;
uint256 hatchingRank = hatchingKomodoRank(nestState.nestedFor);
bool stolen = randomNumber % 10000 <
hatchingStealProbabilityBps(hatchingRank);
address owner;
if (stolen) {
uint256 ownerId = komodoIdsRankWeighted[
randomNumber % komodoIdsRankWeighted.length
];
owner = roost.ownerOf(ownerId);
nestStates[eggId] = NestState(0, 0, address(0), 0);
emit EggStolen(eggId, nestState.nestedBy, owner, ownerId);
} else {
owner = msg.sender;
nestState.rank = hatchingRank;
nestState.nestedTill = 0;
nestState.nestedFor = 0;
for (uint256 i = 0; i < nestState.rank; i++) {
komodoIdsRankWeighted.push(eggId);
}
emit EggHatched(eggId, nestState.nestedBy, nestState.rank);
roost.emitMetadataUpdate(eggId);
}
roost.safeTransferFrom(address(this), owner, eggId);
}
function hatchAll(uint256[] calldata eggIds) public {
for (uint256 i = 0; i < eggIds.length; i++) {
hatch(eggIds[i]);
}
}
function hatchingStealProbabilityBps(
uint256 rank
) public pure returns (uint256) {
require(
rank >= MIN_KOMODO_RANK && rank <= MAX_KOMODO_RANK,
"INVALID_RANK"
);
return 2667 - (167 * rank);
}
function hatchingKomodoRank(
uint256 nestedBlocks
) public pure returns (uint256) {
return (nestedBlocks + 132000) / 34800;
}
function calculateNestingBlocks(
uint256 rank
) public pure returns (uint256) {
require(
rank >= MIN_KOMODO_RANK && rank <= MAX_KOMODO_RANK,
"INVALID_RANK"
);
return (34800 * rank) - 132000;
}
}
文件 6 的 12:LinearVRGDA.sol
pragma solidity >=0.8.0;
import {unsafeWadDiv} from "solmate/src/utils/SignedWadMath.sol";
import {VRGDA} from "./VRGDA.sol";
abstract contract LinearVRGDA is VRGDA {
int256 internal immutable perTimeUnit;
constructor(
int256 _targetPrice,
int256 _priceDecayPercent,
int256 _perTimeUnit
) VRGDA(_targetPrice, _priceDecayPercent) {
perTimeUnit = _perTimeUnit;
}
function getTargetSaleTime(int256 sold)
public
view
virtual
override
returns (int256)
{
return unsafeWadDiv(sold, perTimeUnit);
}
}
文件 7 的 12:Math.sol
pragma solidity ^0.8.0;
library Math {
enum Rounding {
Down,
Up,
Zero
}
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return (a & b) + (a ^ b) / 2;
}
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
return a == 0 ? 0 : (a - 1) / b + 1;
}
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
uint256 prod0;
uint256 prod1;
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
return prod0 / denominator;
}
require(denominator > prod1);
uint256 remainder;
assembly {
remainder := mulmod(x, y, denominator)
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
uint256 twos = denominator & (~denominator + 1);
assembly {
denominator := div(denominator, twos)
prod0 := div(prod0, twos)
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;
uint256 inverse = (3 * denominator) ^ 2;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
result = prod0 * inverse;
return result;
}
}
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 result = 1 << (log2(a) >> 1);
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}
文件 8 的 12: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);
}
}
文件 9 的 12:SafeTransferLib.sol
pragma solidity >=0.8.0;
import {ERC20} from "../tokens/ERC20.sol";
library SafeTransferLib {
function safeTransferETH(address to, uint256 amount) internal {
bool success;
assembly {
success := call(gas(), to, amount, 0, 0, 0, 0)
}
require(success, "ETH_TRANSFER_FAILED");
}
function safeTransferFrom(
ERC20 token,
address from,
address to,
uint256 amount
) internal {
bool success;
assembly {
let freeMemoryPointer := mload(0x40)
mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(from, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(add(freeMemoryPointer, 36), and(to, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(add(freeMemoryPointer, 68), amount)
success := and(
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)
)
}
require(success, "TRANSFER_FROM_FAILED");
}
function safeTransfer(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
assembly {
let freeMemoryPointer := mload(0x40)
mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(add(freeMemoryPointer, 36), amount)
success := and(
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "TRANSFER_FAILED");
}
function safeApprove(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
assembly {
let freeMemoryPointer := mload(0x40)
mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(add(freeMemoryPointer, 36), amount)
success := and(
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "APPROVE_FAILED");
}
}
文件 10 的 12:SignedWadMath.sol
pragma solidity >=0.8.0;
function toWadUnsafe(uint256 x) pure returns (int256 r) {
assembly {
r := mul(x, 1000000000000000000)
}
}
function toDaysWadUnsafe(uint256 x) pure returns (int256 r) {
assembly {
r := div(mul(x, 1000000000000000000), 86400)
}
}
function fromDaysWadUnsafe(int256 x) pure returns (uint256 r) {
assembly {
r := div(mul(x, 86400), 1000000000000000000)
}
}
function unsafeWadMul(int256 x, int256 y) pure returns (int256 r) {
assembly {
r := sdiv(mul(x, y), 1000000000000000000)
}
}
function unsafeWadDiv(int256 x, int256 y) pure returns (int256 r) {
assembly {
r := sdiv(mul(x, 1000000000000000000), y)
}
}
function wadMul(int256 x, int256 y) pure returns (int256 r) {
assembly {
if and(eq(x, not(0)), eq(y, 0x8000000000000000000000000000000000000000000000000000000000000000)) {
revert(0, 0)
}
r := mul(x, y)
if iszero(or(iszero(x), eq(sdiv(r, x), y))) {
revert(0, 0)
}
r := sdiv(r, 1000000000000000000)
}
}
function wadDiv(int256 x, int256 y) pure returns (int256 r) {
assembly {
r := mul(x, 1000000000000000000)
if iszero(and(iszero(iszero(y)), eq(sdiv(r, 1000000000000000000), x))) {
revert(0, 0)
}
r := sdiv(r, y)
}
}
function wadPow(int256 x, int256 y) pure returns (int256) {
return wadExp((wadLn(x) * y) / 1e18);
}
function wadExp(int256 x) pure returns (int256 r) {
unchecked {
if (x <= -42139678854452767551) return 0;
if (x >= 135305999368893231589) revert("EXP_OVERFLOW");
x = (x << 78) / 5**18;
int256 k = ((x << 96) / 54916777467707473351141471128 + 2**95) >> 96;
x = x - k * 54916777467707473351141471128;
int256 y = x + 1346386616545796478920950773328;
y = ((y * x) >> 96) + 57155421227552351082224309758442;
int256 p = y + x - 94201549194550492254356042504812;
p = ((p * y) >> 96) + 28719021644029726153956944680412240;
p = p * x + (4385272521454847904659076985693276 << 96);
int256 q = x - 2855989394907223263936484059900;
q = ((q * x) >> 96) + 50020603652535783019961831881945;
q = ((q * x) >> 96) - 533845033583426703283633433725380;
q = ((q * x) >> 96) + 3604857256930695427073651918091429;
q = ((q * x) >> 96) - 14423608567350463180887372962807573;
q = ((q * x) >> 96) + 26449188498355588339934803723976023;
assembly {
r := sdiv(p, q)
}
r = int256((uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k));
}
}
function wadLn(int256 x) pure returns (int256 r) {
unchecked {
require(x > 0, "UNDEFINED");
assembly {
r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(r, shl(3, lt(0xff, shr(r, x))))
r := or(r, shl(2, lt(0xf, shr(r, x))))
r := or(r, shl(1, lt(0x3, shr(r, x))))
r := or(r, lt(0x1, shr(r, x)))
}
int256 k = r - 96;
x <<= uint256(159 - k);
x = int256(uint256(x) >> 159);
int256 p = x + 3273285459638523848632254066296;
p = ((p * x) >> 96) + 24828157081833163892658089445524;
p = ((p * x) >> 96) + 43456485725739037958740375743393;
p = ((p * x) >> 96) - 11111509109440967052023855526967;
p = ((p * x) >> 96) - 45023709667254063763336534515857;
p = ((p * x) >> 96) - 14706773417378608786704636184526;
p = p * x - (795164235651350426258249787498 << 96);
int256 q = x + 5573035233440673466300451813936;
q = ((q * x) >> 96) + 71694874799317883764090561454958;
q = ((q * x) >> 96) + 283447036172924575727196451306956;
q = ((q * x) >> 96) + 401686690394027663651624208769553;
q = ((q * x) >> 96) + 204048457590392012362485061816622;
q = ((q * x) >> 96) + 31853899698501571402653359427138;
q = ((q * x) >> 96) + 909429971244387300277376558375;
assembly {
r := sdiv(p, q)
}
r *= 1677202110996718588342820967067443963516166;
r += 16597577552685614221487285958193947469193820559219878177908093499208371 * k;
r += 600920179829731861736702779321621459595472258049074101567377883020018308;
r >>= 174;
}
}
function unsafeDiv(int256 x, int256 y) pure returns (int256 r) {
assembly {
r := sdiv(x, y)
}
}
文件 11 的 12:Strings.sol
pragma solidity ^0.8.0;
import "./math/Math.sol";
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}
文件 12 的 12:VRGDA.sol
pragma solidity >=0.8.0;
import {wadExp, wadLn, wadMul, unsafeWadMul, toWadUnsafe} from "solmate/src/utils/SignedWadMath.sol";
abstract contract VRGDA {
int256 public immutable targetPrice;
int256 internal immutable decayConstant;
constructor(int256 _targetPrice, int256 _priceDecayPercent) {
targetPrice = _targetPrice;
decayConstant = wadLn(1e18 - _priceDecayPercent);
require(decayConstant < 0, "NON_NEGATIVE_DECAY_CONSTANT");
}
function getVRGDAPrice(int256 timeSinceStart, uint256 sold)
public
view
virtual
returns (uint256)
{
unchecked {
return uint256(wadMul(targetPrice, wadExp(unsafeWadMul(decayConstant,
timeSinceStart - getTargetSaleTime(toWadUnsafe(sold + 1))
))));
}
}
function getTargetSaleTime(int256 sold)
public
view
virtual
returns (int256);
}
{
"compilationTarget": {
"KomodosRoostNest.sol": "KomodosRoostNest"
},
"evmVersion": "shanghai",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_roostAddress","type":"address"},{"internalType":"int256","name":"_targetPrice","type":"int256"},{"internalType":"int256","name":"_priceDecayPercent","type":"int256"},{"internalType":"int256","name":"_perTimeUnit","type":"int256"},{"internalType":"uint256","name":"_entropy","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"eggId","type":"uint256"},{"indexed":true,"internalType":"address","name":"hatchedBy","type":"address"},{"indexed":false,"internalType":"uint256","name":"rank","type":"uint256"}],"name":"EggHatched","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"eggId","type":"uint256"},{"indexed":true,"internalType":"address","name":"mintedTo","type":"address"}],"name":"EggMinted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"eggId","type":"uint256"},{"indexed":true,"internalType":"address","name":"nestedBy","type":"address"},{"indexed":false,"internalType":"uint256","name":"nestedFor","type":"uint256"}],"name":"EggNested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"eggId","type":"uint256"},{"indexed":true,"internalType":"address","name":"stolenFrom","type":"address"},{"indexed":true,"internalType":"address","name":"stolenBy","type":"address"},{"indexed":false,"internalType":"uint256","name":"stolenByKomodo","type":"uint256"}],"name":"EggStolen","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"FundsAssigned","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"},{"inputs":[],"name":"awaken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"rank","type":"uint256"}],"name":"calculateNestingBlocks","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"disableNesting","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"nester","type":"address"}],"name":"getHatchableEggs","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"nester","type":"address"}],"name":"getPendingEggs","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int256","name":"sold","type":"int256"}],"name":"getTargetSaleTime","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int256","name":"timeSinceStart","type":"int256"},{"internalType":"uint256","name":"sold","type":"uint256"}],"name":"getVRGDAPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"eggId","type":"uint256"}],"name":"hatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"eggIds","type":"uint256[]"}],"name":"hatchAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"nestedBlocks","type":"uint256"}],"name":"hatchingKomodoRank","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"rank","type":"uint256"}],"name":"hatchingStealProbabilityBps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"eggId","type":"uint256"}],"name":"isNestable","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"quantity","type":"uint256"}],"name":"mint","outputs":[{"internalType":"uint256","name":"unitPrice","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"eggId","type":"uint256"},{"internalType":"uint256","name":"rank","type":"uint256"}],"name":"nest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"eggIds","type":"uint256[]"},{"internalType":"uint256","name":"rank","type":"uint256"}],"name":"nestAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nestingActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"roost","outputs":[{"internalType":"contract KomodosRoost","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"targetPrice","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]