Skip to content

Instantly share code, notes, and snippets.

@calvinclaus
Created March 7, 2018 00:03
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save calvinclaus/32f5b00967aca6aabb10d0d91e824e14 to your computer and use it in GitHub Desktop.
Save calvinclaus/32f5b00967aca6aabb10d0d91e824e14 to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.11;
// @calvin_claus' contract
// @neuling2k didn't do anything
contract CryptoLambo {
address public dev1;
address public dev2;
uint[3] public priceIncrementDuringPhase = [150, 120, 115];
uint[3] public maxValueDuringPhase = [0.05 ether, 0.5 ether, 2**256-1];
uint public shareOfProfitForOwner = 50;
uint public constant initialPrice = 0.005 ether;
LedgerItem[] public ownerLedger;
struct LedgerItem {
address _address;
string name;
string message;
uint customization;
uint pricePaid;
uint profit;
uint timeOfPurchase;
}
event Snatch();
function CryptoLambo(address _dev1, address _dev2) public payable {
dev1 = _dev1;
dev2 = _dev2;
ownerLedger.push(LedgerItem(dev1, "@lamborghini", "Snatch that Lambo while it's hot!", 0xffffff, initialPrice, getProfitOfOwnerWhoBoughtFor(initialPrice), now));
}
function getPhaseForPrice(uint price) public constant returns (uint) {
for (int i = int(maxValueDuringPhase.length)-1; i >= 0; i-=1) {
uint maxPhaseValue = maxValueDuringPhase[uint(i)];
if (maxPhaseValue < price) {
return uint(i)+1;
}
}
return 0;
}
function getNextPrice() public constant returns (uint) {
return getPriceAfter(ownerLedger[ownerLedger.length-1].pricePaid);
}
function getPriceAfter(uint price) public constant returns (uint) {
return (price*priceIncrementDuringPhase[getPhaseForPrice(price)])/100;
}
function getProfitOfOwnerWhoBoughtFor(uint price) public constant returns (uint) {
return ((getPriceAfter(price)-price)*shareOfProfitForOwner)/100;
}
function getProfitOfNextOwner() public constant returns (uint) {
return getProfitOfOwnerWhoBoughtFor(getNextPrice());
}
function snatch(string name, string message, uint customization) public payable {
require(bytes(name).length <= 80);
require(bytes(message).length <= 560);
uint nextPrice = getNextPrice();
require(msg.value >= nextPrice);
LedgerItem storage currentItem = ownerLedger[ownerLedger.length-1];
uint profitOfNewOwner = getProfitOfOwnerWhoBoughtFor(nextPrice);
Snatch();
ownerLedger.push(LedgerItem(msg.sender, name, message, customization, nextPrice, profitOfNewOwner, now));
currentItem._address.transfer(currentItem.pricePaid+getProfitOfOwnerWhoBoughtFor(currentItem.pricePaid));
//ether not used for purchase remains on this contract
}
function developerCachout() public {
if (msg.sender == dev1 || msg.sender == dev2) {
uint half = this.balance/2;
uint otherHalf = this.balance-half;
dev1.transfer(half);
dev2.transfer(otherHalf);
}
}
function getLedgerLength() public constant returns (uint) {
return ownerLedger.length;
}
function getBalance() public constant returns (uint) {
return this.balance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment