-
Notifications
You must be signed in to change notification settings - Fork 16
/
dappVolumeAd.sol
153 lines (133 loc) · 4.11 KB
/
dappVolumeAd.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
pragma solidity ^0.4.24;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
}
// Create Ad on DappVolume
// Advertiser can choose 1 hour, 12 hours, 24 hours, or 1 week
// half of the money gets sent back to last advertiser
//
// An investor can earn 10% of the ad revenue
// Investors can get bought out by new investors
// when an invester is bought out, they get 120% of their investment back
contract dappVolumeAd {
// import safemath
using SafeMath for uint256;
// set variables
uint256 public dappId;
uint256 public purchaseTimestamp;
uint256 public purchaseSeconds;
uint256 public investmentMin;
uint256 public adPriceHour;
uint256 public adPriceHalfDay;
uint256 public adPriceDay;
uint256 public adPriceWeek;
uint256 public adPriceMultiple;
address public contractOwner;
address public lastOwner;
address public theInvestor;
// only contract owner
modifier onlyContractOwner {
require(msg.sender == contractOwner);
_;
}
// set constructor
constructor() public {
investmentMin = 1000000000000000;
adPriceHour = 5000000000000000;
adPriceHalfDay = 50000000000000000;
adPriceDay = 100000000000000000;
adPriceWeek = 500000000000000000;
adPriceMultiple = 1;
contractOwner = msg.sender;
theInvestor = contractOwner;
lastOwner = contractOwner;
}
// withdraw funds to contract creator
function withdraw() public onlyContractOwner {
contractOwner.transfer(address(this).balance);
}
// set ad price multiple incase we want to up the price in the future
function setAdPriceMultiple(uint256 amount) public onlyContractOwner {
adPriceMultiple = amount;
}
// update and set ad
function updateAd(uint256 id) public payable {
// set minimum amount and make sure ad hasnt expired
require(msg.value >= adPriceMultiple.mul(adPriceHour));
require(block.timestamp > purchaseTimestamp + purchaseSeconds);
require(id > 0);
// set ad time limit in seconds
if (msg.value >= adPriceMultiple.mul(adPriceWeek)) {
purchaseSeconds = 604800; // 1 week
} else if (msg.value >= adPriceMultiple.mul(adPriceDay)) {
purchaseSeconds = 86400; // 1 day
} else if (msg.value >= adPriceMultiple.mul(adPriceHalfDay)) {
purchaseSeconds = 43200; // 12 hours
} else {
purchaseSeconds = 3600; // 1 hour
}
// set new timestamp
purchaseTimestamp = block.timestamp;
// send 50% of the money to the last person
lastOwner.transfer(msg.value.div(2));
// send 10% to the investor
theInvestor.transfer(msg.value.div(10));
// set last owner
lastOwner = msg.sender;
// set dapp id
dappId = id;
}
// update the investor
function updateInvestor() public payable {
require(msg.value >= investmentMin);
theInvestor.transfer(msg.value.div(100).mul(60)); // send 60% to last investor (120% of original purchase)
theInvestor = msg.sender; // set new investor
investmentMin = investmentMin.mul(2); // double the price to become the investor
}
// get timestamp when ad ends
function getPurchaseTimestampEnds() public view returns (uint _getPurchaseTimestampAdEnds) {
return purchaseTimestamp.add(purchaseSeconds);
}
// get contract balance
function getBalance() public view returns(uint256){
return address(this).balance;
}
}