Last active
December 29, 2018 01:14
-
-
Save noman-land/0389e11cb41f76a5ed0fc0b8758fc28f to your computer and use it in GitHub Desktop.
Work agreement and taxes smart contracts
This file contains 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
pragma solidity ^0.4.11; | |
contract TaxAuthority { | |
address public owner; | |
mapping (address => uint) public taxesCollected; | |
modifier onlyOwner() { | |
require(msg.sender == owner); | |
_; | |
} | |
function TaxAuthority() { | |
owner = msg.sender; | |
} | |
function getBalance() constant returns (uint balance) { | |
return this.balance; | |
} | |
function pay() payable { | |
taxesCollected[msg.sender] += msg.value; | |
} | |
function withdraw(uint amount) onlyOwner { | |
if (amount == 0 || amount > this.balance) { | |
revert(); | |
} | |
msg.sender.transfer(amount); | |
} | |
} | |
contract WorkAgreement { | |
address public employer; | |
address public employee; | |
uint public salaryPerPayPeriod; | |
uint public payPeriodLengthInBlocks; | |
uint public numPayPeriods; | |
uint public numBufferPayPeriods; | |
uint public startBlock; | |
uint public endBlock; | |
uint public lastWithdrawlBlock; | |
uint public taxPercentage; | |
modifier onlyEmployer() { | |
require(msg.sender == employer); | |
_; | |
} | |
modifier onlyEmployee() { | |
require(msg.sender == employee); | |
_; | |
} | |
function WorkAgreement( | |
address _employee, | |
uint _salaryPerPayPeriod, | |
uint _payPeriodLengthInBlocks, | |
uint _numPayPeriods, | |
uint _numBufferPayPeriods, | |
uint _startBlock | |
) | |
payable | |
{ | |
if ( | |
msg.value == 0 || | |
_salaryPerPayPeriod == 0 || | |
_payPeriodLengthInBlocks == 0 || | |
_numPayPeriods == 0 || | |
_startBlock == 0 || | |
msg.value < _salaryPerPayPeriod * _numBufferPayPeriods || | |
msg.value > _salaryPerPayPeriod * _numPayPeriods || | |
_numBufferPayPeriods > _numPayPeriods | |
) { | |
revert(); | |
} | |
employer = msg.sender; | |
employee = _employee; | |
salaryPerPayPeriod = _salaryPerPayPeriod; | |
payPeriodLengthInBlocks = _payPeriodLengthInBlocks; | |
numPayPeriods = _numPayPeriods; | |
numBufferPayPeriods = _numBufferPayPeriods; | |
startBlock = _startBlock; | |
lastWithdrawlBlock = _startBlock; | |
} | |
function deposit() payable onlyEmployer returns(uint newBalance) { | |
if ( | |
this.balance > numPayPeriods * salaryPerPayPeriod || | |
(block.number > endBlock && endBlock > 0) | |
) { | |
revert(); | |
} | |
return this.balance; | |
} | |
function getBalance() constant returns(uint) { | |
return this.balance; | |
} | |
function setEndBlock(uint blockNumber) onlyEmployer { | |
if (endBlock < block.number) { | |
revert(); | |
} | |
endBlock = blockNumber; | |
} | |
function setTaxPercentage(uint percentage) onlyEmployee { | |
if (percentage == taxPercentage || percentage > 100) { | |
revert(); | |
} | |
taxPercentage = percentage; | |
} | |
function triggerSeverance() onlyEmployee { | |
if (this.balance >= numBufferPayPeriods * salaryPerPayPeriod) { | |
revert(); | |
} | |
employee.transfer(this.balance); | |
} | |
function withdraw() onlyEmployee { | |
uint blocksSinceWithdrawl = block.number - lastWithdrawlBlock; | |
uint payPeriodsSinceWithdrawl = blocksSinceWithdrawl / payPeriodLengthInBlocks; | |
if (payPeriodsSinceWithdrawl < 1) { | |
revert(); | |
} | |
lastWithdrawlBlock = block.number; | |
uint paymentAmount = payPeriodsSinceWithdrawl * salaryPerPayPeriod; | |
uint taxedAmount = paymentAmount * taxPercentage / 100; | |
uint paymentAmountAfterTaxes = paymentAmount - taxedAmount; | |
employee.transfer(paymentAmountAfterTaxes); | |
// taxAuthority.pay(taxedAmount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment