Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. contract Rubixi {
  2.  
  3. //Declare variables for storage critical to contract
  4. uint private balance = 0;
  5. uint private collectedFees = 0;
  6. uint private feePercent = 10;
  7. uint private pyramidMultiplier = 300;
  8. uint private payoutOrder = 0;
  9.  
  10. address private creator;
  11.  
  12. //Sets creator
  13. function DynamicPyramid() {
  14. creator = msg.sender;
  15. }
  16.  
  17. modifier onlyowner {
  18. if (msg.sender == creator) _;
  19. }
  20.  
  21. struct Participant {
  22. address etherAddress;
  23. uint payout;
  24. }
  25.  
  26. Participant[] private participants;
  27.  
  28. //Fallback function
  29. function() payable {
  30. init();
  31. }
  32.  
  33. //init function run on fallback
  34. function init() private {
  35. //Ensures only tx with value of 1 ether or greater are processed and added to pyramid
  36. if (msg.value < 1 ether) {
  37. collectedFees += msg.value;
  38. return;
  39. }
  40.  
  41. uint _fee = feePercent;
  42. //50% fee rebate on any ether value of 50 or greater
  43. if (msg.value >= 50 ether) _fee /= 2;
  44.  
  45. addPayout(_fee);
  46. }
  47.  
  48. //Function called for valid tx to the contract
  49. function addPayout(uint _fee) private {
  50. //Adds new address to participant array
  51. participants.push(Participant(msg.sender, (msg.value * pyramidMultiplier) / 100));
  52.  
  53. //These statements ensure a quicker payout system to later pyramid entrants, so the pyramid has a longer lifespan
  54. if (participants.length == 10) pyramidMultiplier = 200;
  55. else if (participants.length == 25) pyramidMultiplier = 150;
  56.  
  57. // collect fees and update contract balance
  58. balance += (msg.value * (100 - _fee)) / 100;
  59. collectedFees += (msg.value * _fee) / 100;
  60.  
  61. //Pays earlier participiants if balance sufficient
  62. while (balance > participants[payoutOrder].payout) {
  63. uint payoutToSend = participants[payoutOrder].payout;
  64. address(participants[payoutOrder].etherAddress).transfer(payoutToSend);
  65.  
  66. balance -= participants[payoutOrder].payout;
  67. payoutOrder += 1;
  68. }
  69. }
  70.  
  71. //Fee functions for creator
  72. function collectAllFees() onlyowner {
  73. if (collectedFees == 0) throw;
  74.  
  75. creator.send(collectedFees);
  76. collectedFees = 0;
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement