This repository has been archived by the owner on Mar 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Agreement.sol
173 lines (150 loc) · 5.89 KB
/
Agreement.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
pragma solidity 0.4.15;
import './Standards/IEthereumForkArbiter.sol';
import './AccessControl/AccessControlled.sol';
import './AccessRoles.sol';
/**
* @title legally binding smart contract
* @dev General approach to paring legal and smart contracts:
* 1. All terms and agreement are between two parties: here between legal representation of platform operator representative and platform investor.
* 2. Parties are represented by public Ethereum addresses. Platform investor is and address that holds and controls funds and receives and controls Neumark token
* 3. Legal agreement has immutable part that corresponds to smart contract code and mutable part that may change for example due to changing regulations or other externalities that smart contract does not control.
* 4. There should be a provision in legal document that future changes in mutable part cannot change terms of immutable part.
* 5. Immutable part links to corresponding smart contract via its address.
* 6. Additional provision should be added if smart contract supports it
* a. Fork provision
* b. Bugfixing provision (unilateral code update mechanism)
* c. Migration provision (bilateral code update mechanism)
*
* Details on Agreement base class:
* 1. We bind smart contract to legal contract by storing uri (preferably ipfs or hash) of the legal contract in the smart contract. It is however crucial that such binding is done by platform operator representation so transaction establishing the link must be signed by respective wallet ('amendAgreement')
* 2. Mutable part of agreement may change. We should be able to amend the uri later. Previous amendments should not be lost and should be retrievable (`amendAgreement` and 'pastAgreement' functions).
* 3. It is up to deriving contract to decide where to put 'acceptAgreement' modifier. However situation where there is no cryptographic proof that given address was really acting in the transaction should be avoided, simplest example being 'to' address in `transfer` function of ERC20.
*
**/
contract Agreement is
AccessControlled,
AccessRoles
{
////////////////////////
// Type declarations
////////////////////////
/// @notice agreement with signature of the platform operator representative
struct SignedAgreement {
address platformOperatorRepresentative;
uint256 signedBlockTimestamp;
string agreementUri;
}
////////////////////////
// Immutable state
////////////////////////
IEthereumForkArbiter private ETHEREUM_FORK_ARBITER;
////////////////////////
// Mutable state
////////////////////////
// stores all amendments to the agreement, first amendment is the original
SignedAgreement[] private _amendments;
// stores block numbers of all addresses that signed the agreement (signatory => block number)
mapping(address => uint256) private _signatories;
////////////////////////
// Events
////////////////////////
event LogAgreementAccepted(
address indexed accepter
);
event LogAgreementAmended(
address platformOperatorRepresentative,
string agreementUri
);
////////////////////////
// Modifiers
////////////////////////
/// @notice logs that agreement was accepted by platform user
/// @dev intended to be added to functions that if used make 'accepter' origin to enter legally binding agreement
modifier acceptAgreement(address accepter) {
if(_signatories[accepter] == 0) {
require(_amendments.length > 0);
_signatories[accepter] = block.number;
LogAgreementAccepted(accepter);
}
_;
}
////////////////////////
// Constructor
////////////////////////
function Agreement(IAccessPolicy accessPolicy, IEthereumForkArbiter forkArbiter)
AccessControlled(accessPolicy)
internal
{
require(forkArbiter != IEthereumForkArbiter(0x0));
ETHEREUM_FORK_ARBITER = forkArbiter;
}
////////////////////////
// Public functions
////////////////////////
function amendAgreement(string agreementUri)
public
only(ROLE_PLATFORM_OPERATOR_REPRESENTATIVE)
{
SignedAgreement memory amendment = SignedAgreement({
platformOperatorRepresentative: msg.sender,
signedBlockTimestamp: block.timestamp,
agreementUri: agreementUri
});
_amendments.push(amendment);
LogAgreementAmended(msg.sender, agreementUri);
}
function ethereumForkArbiter()
public
constant
returns (IEthereumForkArbiter)
{
return ETHEREUM_FORK_ARBITER;
}
function currentAgreement()
public
constant
returns
(
address platformOperatorRepresentative,
uint256 signedBlockTimestamp,
string agreementUri,
uint256 index
)
{
require(_amendments.length > 0);
uint256 last = _amendments.length - 1;
SignedAgreement storage amendment = _amendments[last];
return (
amendment.platformOperatorRepresentative,
amendment.signedBlockTimestamp,
amendment.agreementUri,
last
);
}
function pastAgreement(uint256 amendmentIndex)
public
constant
returns
(
address platformOperatorRepresentative,
uint256 signedBlockTimestamp,
string agreementUri,
uint256 index
)
{
SignedAgreement storage amendment = _amendments[amendmentIndex];
return (
amendment.platformOperatorRepresentative,
amendment.signedBlockTimestamp,
amendment.agreementUri,
amendmentIndex
);
}
function agreementSignedAtBlock(address signatory)
public
constant
returns (uint256)
{
return _signatories[signatory];
}
}