Created
March 21, 2014 01:10
-
-
Save wemeetagain/9677553 to your computer and use it in GitHub Desktop.
Sample Crowdfunded Employment Contract
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [AMT] - Withdraw AMT from contract | |
// tracks 'employee' withdrawal time, amount, and contract balance starting at storage[500] | |
if tx.value < 100 * block.basefee: | |
stop | |
if tx.sender == CONTRACT_CREATOR: | |
// if a withdrawal amount is set, attempt withdrawl | |
if tx.data[0] > 0: | |
WITHDRAWAL_LOG_INDEX = contract.storage[499] + 500 | |
LAST_WITHDRAWAL_TIME = contract.storage[WITHDRAWAL_LOG_INDEX] | |
if block.timestamp - LAST_WITHDRAWAL_TIME >= 2_WEEKS: | |
LAST_WITHDRAWAL_AMT = 0 | |
else: | |
LAST_WITHDRAWAL_AMT = contract.storage[WITHDRAWAL_LOG_INDEX + 1] | |
// 'employee' withdrawal rule, true == valid withdrawal | |
if tx.data[0] + LAST_WITHDRAWAL_AMT <= WITHDRAWAL_CAP_1 && tx.data[0] >= contract.balance: | |
contract.storage[WITHDRAWAL_LOG_INDEX + 3] = block.timestamp | |
contract.storage[WITHDRAWAL_LOG_INDEX + 4] = tx.data[0] + LAST_WITHDRAWAL_AMT | |
contract.storage[WITHDRAWAL_LOG_INDEX + 5] = contract.balance - tx.data[0] | |
contract.storage[499] = WITHDRAWAL_LOG_INDEX - 500 + 3 | |
mktx(CONTRACT_CREATOR,tx.data[0],0,array()) | |
// return all unused fees (do not allow creator to store funds in this contract) | |
mktx(CONTRACT_CREATOR, tx.value - block.basefee * 100, 0, array()) | |
else: | |
WITHDRAWAL_LOG_INDEX = contract.storage[499] + 500 | |
LAST_LOG_INDEX = contract.storage[tx.sender+3] + 500 | |
// subtract 'funder' balance for all previous 'employee' withdrawals | |
while LAST_LOG_INDEX < WITHDRAWAL_LOG_INDEX: | |
contract.storage[tx.sender] = contract.storage[tx.sender] - (contract.storage[tx.sender] * contract.storage[LAST_LOG_INDEX + 1] / contract.storage[LAST_LOG_INDEX + 2]) | |
LAST_LOG_INDEX = LAST_LOG_INDEX + 3 | |
contract.storage[tx.sender+3] = LAST_LOG_INDEX - 500 | |
// if a withdrawal amount is set, attempt withdrawl | |
if tx.data[0] > 0: | |
LAST_WITHDRAWAL_TIME = contract.storage[tx.sender+1] | |
if block.timestamp - LAST_WITHDRAWAL_TIME >= 2_WEEKS: | |
LAST_WITHDRAWAL_AMT = 0 | |
else: | |
LAST_WITHDRAWAL_AMT = contract.storage[tx.sender+2] | |
// 'funder' withdrawal rule, true == valid withdrawal | |
if tx.data[0] + LAST_WITHDRAWAL_AMT <= WITHDRAWAL_CAP_2 && tx.data[0] >= contract.storage[tx.sender]: | |
contract.storage[tx.sender+1] = block.timestamp | |
contract.storage[tx.sender+2] = tx.data[0] + LAST_WITHDRAWAL_AMT | |
contract.storage[tx.sender] = contract.storage[tx.sender] - tx.data[0] | |
mktx(tx.sender,tx.data[0],0,array()) | |
// deposit funder money | |
contract.storage[tx.sender] = contract.storage[tx.sender] + tx.value - block.basefee * 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment