Skip to content

Instantly share code, notes, and snippets.

View ilamanov's full-sized avatar

Nazar Ilamanov ilamanov

View GitHub Profile
@ilamanov
ilamanov / SaleClockAuction.sol
Created March 7, 2022 15:57
Shortened version of SaleClockAuction
contract SaleClockAuction is ClockAuction {
bool public isSaleClockAuction = true;
// Tracks last 5 sale price of gen0 kitty sales
uint256 public gen0SaleCount;
uint256[5] public lastGen0SalePrices;
// Updates lastSalePrice if seller is the nft contract
// Otherwise, works the same as default bid method.
function bid(uint256 _tokenId) external payable {
@ilamanov
ilamanov / KittyAuction.sol
Created March 7, 2022 15:48
Shortened version of KittyAuction
contract KittyAuction is KittyBreeding {
SaleClockAuction public saleAuction;
SiringClockAuction public siringAuction;
function setSaleAuctionAddress(address _address) external onlyCEO {
SaleClockAuction candidateContract = SaleClockAuction(_address);
require(candidateContract.isSaleClockAuction());
saleAuction = candidateContract;
}
@ilamanov
ilamanov / ClockAuction.sol
Last active March 7, 2022 15:48
Shortened version of ClockAuction
contract ClockAuction is Pausable, ClockAuctionBase {
// Remove all Ether from the contract, which is the owner's cuts
// as well as any Ether sent directly to the contract address.
// Always transfers to the NFT contract
function withdrawBalance() external {
address nftAddress = address(nonFungibleContract);
require(msg.sender == owner || msg.sender == nftAddress);
bool res = nftAddress.send(this.balance);
}
@ilamanov
ilamanov / ClockAuctionBase.sol
Last active March 7, 2022 15:05
Shortened version of ClockAuctionBase
contract ClockAuctionBase {
struct Auction {
address seller;
uint128 startingPrice;
uint128 endingPrice;
uint64 duration;
uint64 startedAt; // 0 if this auction has been concluded
}
uint256 public ownerCut; // measured in basis points (1/100 of a percent)
@ilamanov
ilamanov / KittyBreeding.sol
Created March 7, 2022 09:05
KittyBreeding address reference to GeneScience
contract KittyBreeding is KittyOwnership {
// The address of the sibling contract that is used to implement the sooper-sekret
// genetic combination algorithm.
GeneScienceInterface public geneScience;
function setGeneScienceAddress(address _address) external onlyCEO {
GeneScienceInterface candidateContract = GeneScienceInterface(_address);
require(candidateContract.isGeneScience());
geneScience = candidateContract;
}
@ilamanov
ilamanov / KittyBreeding.sol
Last active March 7, 2022 09:25
Shortened version of KittyBreeding
contract KittyBreeding is KittyOwnership {
uint256 public autoBirthFee = 2 finney; // autoBirth is explained in the article
uint256 public pregnantKitties; // number of pregnant kitties
function _isReadyToBreed(Kitty _kit) internal view returns (bool) {
return (_kit.siringWithId == 0) && (_kit.cooldownEndBlock <= uint64(block.number));
}
function _isReadyToGiveBirth(Kitty _matron) private view returns (bool) {
return (_matron.siringWithId != 0) && (_matron.cooldownEndBlock <= uint64(block.number));
}
@ilamanov
ilamanov / KittyCore.sol
Created March 7, 2022 08:13
Shortened version of KittyCore
contract KittyCore is KittyMinting {
function KittyCore() public {
paused = true;
// the creator of the contract is the initial CEO and COO
ceoAddress = msg.sender;
cooAddress = msg.sender;
// start with the mythical kitten 0 - so we don't have generation-0 parent issues
_createKitty(0, 0, 0, uint256(-1), address(0));
@ilamanov
ilamanov / KittyMinting.sol
Created March 7, 2022 07:58
Shortened version of KittyMinting
contract KittyMinting is KittyAuction {
uint256 public constant PROMO_CREATION_LIMIT = 5000;
uint256 public constant GEN0_CREATION_LIMIT = 45000;
uint256 public constant GEN0_STARTING_PRICE = 10 finney;
uint256 public constant GEN0_AUCTION_DURATION = 1 days;
// Counts the number of cats the contract owner has created.
uint256 public promoCreatedCount;
uint256 public gen0CreatedCount;
@ilamanov
ilamanov / KittyBase.sol
Last active March 7, 2022 20:10
Shortened version of KittyBase
contract KittyBase is KittyAccessControl {
struct Kitty {
uint256 genes; // genetic code packed into 256 bits
uint64 birthTime;
uint64 cooldownEndBlock; // cooldown after breeding
uint32 matronId; // mom's ID
uint32 sireId; // dad's ID
uint32 siringWithId; // if set then pregnant
uint16 cooldownIndex; // like age. bigger it is, longer is the cooldown
uint16 generation;
@ilamanov
ilamanov / KittyAccessControl.sol
Created March 7, 2022 07:05
Shortened version of KittyAccessControl
contract KittyAccessControl {
address public ceoAddress;
address public cfoAddress;
address public cooAddress;
modifier onlyCEO() {
require(msg.sender == ceoAddress);
_;
}
// ...same functions for CFO and COO