-
Notifications
You must be signed in to change notification settings - Fork 0
/
gemini.sol
214 lines (161 loc) · 6.98 KB
/
gemini.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
pragma solidity ^0.8.0;
contract Agreement {
enum State { draft, active, terminated, violated }
State public currentState;
struct Party {
string name;
address payable wallet;
bool signed;
}
Party public partyA;
Party public partyB;
uint256 public executionDate;
uint256 public endDate;
uint256 public effectivePeriod;
bool public isRenewed;
uint256 public renewPeriod;
uint256 public terminationNoticePeriod;
uint256 public terminationNoticeDate;
uint256 public terminationDate;
uint256 public nextPriceIncreaseDate;
uint256 public adCompensateNoticeDate;
uint256 public adCompensateFinishDate;
string public violationDetails;
bool public isTerminated;
uint256 public adCompensatePeriod;
uint256[] public prices;
uint256 public priceIncreaseLimit;
string public IPRights;
bool public infringementStatus;
bool public adImpressionStatus;
bool public transferStatus;
address public currentActor; // Track the current actor
modifier inState(State _state) {
require(currentState == _state, "Invalid state transition");
_;
}
modifier onlyParty() {
require(msg.sender == partyA.wallet || msg.sender == partyB.wallet, "Unauthorized party.");
_;
}
constructor(address payable _partyA, address payable _partyB) {
partyA.name = "Women.com";
partyB.name = "eDiets";
partyA.wallet = _partyA;
partyB.wallet = _partyB;
effectivePeriod = 2 * 365 days;
renewPeriod = 12 * 30 days;
terminationNoticePeriod = 60 days;
prices.push(10000);
priceIncreaseLimit = 20 * 100; // percentage to actual value
IPRights = partyA.name;
currentState = State.draft; // Initial state
}
event StateTransition(State from, State to);
event sign_agreement();
event contract_renewal_check();
event notify_termination();
event terminate_agreement();
event breach_advertisement();
event transfer_contract();
event adjust_payment();
event guarantee_impressions();
event compensate_period();
event compensate_impressions();
event use_intellectual_property();
event brand_infringement();
function signAgreement() public onlyParty inState(State.draft) {
if (msg.sender == partyA.wallet) {
partyA.signed = true;
} else {
partyB.signed = true;
}
if (partyA.signed && partyB.signed) {
executionDate = block.timestamp;
endDate = executionDate + effectivePeriod;
nextPriceIncreaseDate = executionDate + 60 days;
currentState = State.active;
emit StateTransition(State.draft, State.active);
}
emit sign_agreement();
}
function contractRenewalCheck() public inState(State.active) {
require(block.timestamp > endDate && !isTerminated, "Renewal conditions not met.");
isRenewed = true;
endDate = endDate + renewPeriod;
emit contract_renewal_check();
}
function notifyTermination() public onlyParty inState(State.active) {
require(block.timestamp < endDate - terminationNoticePeriod, "Too late to notify termination.");
terminationNoticeDate = block.timestamp;
emit notify_termination();
}
function terminateAgreement() public inState(State.active) {
require(block.timestamp < endDate && terminationNoticeDate != 0, "Termination conditions not met.");
terminationDate = block.timestamp;
isTerminated = true;
currentState = State.terminated;
emit terminate_agreement();
emit StateTransition(State.active, State.terminated);
}
function breachAdvertisement(bool competitorAdvertisement) public onlyParty inState(State.active) {
require(competitorAdvertisement, "No competitor advertisement detected.");
currentState = State.violated;
violationDetails = "Advertising on competing platform";
emit StateTransition(State.active, State.violated);
emit breach_advertisement();
}
function transferContract(bool controlChange, bool isCompetitor, address _transferParty) public onlyParty inState(State.active){
require(controlChange && !isCompetitor, "Transfer conditions not met.");
transferStatus = true;
currentActor = _transferParty;
emit transfer_contract();
}
function adjustPayment(uint256 price) public inState(State.active) {
require(msg.sender == partyA.wallet, "Unauthorized party.");
require(block.timestamp > nextPriceIncreaseDate, "Not eligible for price adjustment yet.");
// Get last year's price
uint256 lastYearPrice = 0;
if(prices.length > 0 && block.timestamp > nextPriceIncreaseDate){
lastYearPrice = prices[prices.length - 1];
}
require(price * 100 <= lastYearPrice * (100 + priceIncreaseLimit), "Price increase exceeds limit.");
prices.push(price);
nextPriceIncreaseDate = nextPriceIncreaseDate + 365 days;
emit adjust_payment();
}
function guaranteeImpressions(uint256 adImpressions) public inState(State.active) {
require(msg.sender == partyA.wallet, "Unauthorized party.");
require(adImpressions < 13000000, "Ad impressions requirement met.");
adImpressionStatus = false;
emit guarantee_impressions();
}
function compensatePeriod(uint256 _adCompensatePeriod) public inState(State.active) {
require(msg.sender == partyB.wallet, "Unauthorized party.");
require(!adImpressionStatus, "Ad impression status is true.");
adCompensateNoticeDate = block.timestamp;
adCompensatePeriod = _adCompensatePeriod;
emit compensate_period();
}
function compensateImpressions() public inState(State.active) {
require(msg.sender == partyA.wallet, "Unauthorized party.");
require(block.timestamp <= adCompensateNoticeDate + adCompensatePeriod, "Compensation period expired.");
adImpressionStatus = true;
adCompensateFinishDate = block.timestamp;
emit compensate_impressions();
}
function useIntellectualProperty(bool IPUsageCheck) public onlyParty inState(State.active) {
require(!IPUsageCheck, "IP usage within contract scope.");
currentState = State.violated;
violationDetails = "IP usage is out of contract scope.";
emit StateTransition(State.active, State.violated);
emit use_intellectual_property();
}
function brandInfringement(bool _brandInfringement) public onlyParty inState(State.active) {
require((block.timestamp > endDate || (terminationDate != 0 && block.timestamp > terminationDate)) && _brandInfringement, "Brand infringement conditions not met.");
currentState = State.violated;
infringementStatus = true;
emit StateTransition(State.active, State.violated);
emit brand_infringement();
}
}