Created
June 16, 2019 03:28
-
-
Save cmditch/f025ae17e7c28540ce18475e2dc51dbb to your computer and use it in GitHub Desktop.
K. Done.
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
contract DominantAssuranceContract { | |
address owner; | |
uint256 deadline; | |
uint256 goal; | |
uint8 percentagePayoff; | |
mapping(address => uint256) public balanceOf; | |
uint256 totalPledges; | |
constructor(uint256 numberOfDays, uint256 _goal, uint8 _percentagePayoff) public payable { | |
owner = msg.sender; | |
deadline = now + (numberOfDays * 1 days); | |
goal = _goal; | |
percentagePayoff = _percentagePayoff; | |
balanceOf[msg.sender] = msg.value; | |
} | |
function pledge(uint256 amount) public payable { | |
require(now < deadline, "The campaign is over."); | |
require(msg.value == amount, "The amount is incorrect."); | |
require(msg.sender != owner, "The owner cannot pledge."); | |
uint256 payoff = amount * percentagePayoff / 100; | |
if (payoff > balanceOf[owner]) { | |
payoff = balanceOf[owner]; | |
} | |
balanceOf[owner] -= payoff; | |
balanceOf[msg.sender] += amount+payoff; | |
totalPledges += amount; | |
} | |
function claimFunds() public { | |
require(now >= deadline, "The campaign is not over."); | |
require(totalPledges >= goal, "The funding goal was not met."); | |
require(msg.sender == owner, "Only the owner may claim funds."); | |
msg.sender.transfer(address(this).balance); | |
} | |
function getRefund() public { | |
require(now >= deadline, "The campaign is still active."); | |
require(totalPledges < goal, "Funding goal was met."); | |
uint256 amount = balanceOf[msg.sender]; | |
balanceOf[msg.sender] = 0; | |
msg.sender.transfer(amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pwt!
definition of dominance assurance contract from wikipedia:
comments:
0. omg this was quick work. howd you do it so quick?
beneficiaryAddress
that is seperate from the owner address.getRefund()
scenario, what happens to the "entrepeneur"s stake? i dont think thats baked in yet.claimFunds()
scenario, the entrepeneur needs to be rewarded ( " if the quorum succeeds, the entrepreneur is compensated for taking the risk of the quorum failing" )We should share this with the bike ride frands group! Esp Dan T, who I think wants to build this into grant io.