Skip to content

Commit d73fb31

Browse files
committed
added natspec to a fair bit of code, changed extern state token to be destructible
1 parent 6d2054b commit d73fb31

19 files changed

+449
-155
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ come at the expense of clarity or simplicity.
6464
* `contracts/` contains smart contract code to be deployed.
6565
* `contracts/Owned.sol` a contract with an owner.
6666
* `contracts/SafeDecimalMath.sol` a math library for unsigned fixed point decimal arithmetic, with built-in safety checking.
67-
* `contracts/TokenState.sol` The balances of the ExternStateToken contract.
68-
* `contracts/ExternStateToken.sol` a foundation for generic ERC20 tokens with external state.
67+
* `contracts/TokenState.sol` The balances of the DestructibleExternStateToken contract.
68+
* `contracts/DestructibleExternStateToken.sol` a foundation for generic ERC20 tokens with external state.
6969
* `contracts/ExternStateFeeToken.sol` a foundation for generic ERC20 tokens which also charge fees on transfers, with external state.
7070
* `contracts/Nomin.sol` ether-backed nomin contract, with liquidation and confiscation logic.
7171
* `contracts/Havven.sol` havven collateral token, including calculations involving entitlements to fees being generated by nomins.

contracts/Court.sol

+73-43
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
FILE INFORMATION
44
-----------------------------------------------------------------
55
file: Court.sol
6-
version: 1.0
6+
version: 1.1
77
author: Anton Jurisevic
88
Mike Spain
9+
Dominic Romanowski
910
10-
date: 2018-2-6
11+
date: 2018-05-02
1112
1213
checked: Mike Spain
1314
approved: Samuel Brooks
@@ -96,13 +97,13 @@ Confirmation:
9697
9798
9899
User votes are not automatically cancelled upon the conclusion of a motion.
99-
Therefore, after a motion comes to a conclusion, if a user wishes to vote
100+
Therefore, after a motion comes to a conclusion, if a user wishes to vote
100101
in another motion, they must manually cancel their vote in order to do so.
101102
102103
This procedure is designed to be relatively simple.
103104
There are some things that can be added to enhance the functionality
104105
at the expense of simplicity and efficiency:
105-
106+
106107
- Democratic unfreezing of nomin accounts (induces multiple categories of vote)
107108
- Configurable per-vote durations;
108109
- Vote standing denominated in a fiat quantity rather than a quantity of havvens;
@@ -208,7 +209,7 @@ contract Court is SafeDecimalMath, Owned {
208209
/* ========== CONSTRUCTOR ========== */
209210

210211
/**
211-
* @dev Constructor.
212+
* @dev Court Constructor.
212213
*/
213214
constructor(Havven _havven, Nomin _nomin, address _owner)
214215
Owned(_owner)
@@ -238,7 +239,7 @@ contract Court is SafeDecimalMath, Owned {
238239
/**
239240
* @notice Set the length of time a vote runs for.
240241
* @dev Only the contract owner may call this. The proposed duration must fall
241-
* within sensible bounds (1 to 4 weeks), and must be no longer than a single fee period.
242+
* within sensible bounds (3 days to 4 weeks), and must be no longer than a single fee period.
242243
*/
243244
function setVotingPeriod(uint duration)
244245
external
@@ -252,6 +253,11 @@ contract Court is SafeDecimalMath, Owned {
252253
votingPeriod = duration;
253254
}
254255

256+
/**
257+
* @notice Set the confirmation period after a vote has concluded.
258+
* @dev Only the contract owner may call this. The proposed duration must fall
259+
* within sensible bounds (1 day to 2 weeks).
260+
*/
255261
function setConfirmationPeriod(uint duration)
256262
external
257263
onlyOwner
@@ -261,6 +267,10 @@ contract Court is SafeDecimalMath, Owned {
261267
confirmationPeriod = duration;
262268
}
263269

270+
/**
271+
* @notice Set the required fraction of all Havvens that need to be part of
272+
* a vote for it to pass.
273+
*/
264274
function setRequiredParticipation(uint fraction)
265275
external
266276
onlyOwner
@@ -269,6 +279,10 @@ contract Court is SafeDecimalMath, Owned {
269279
requiredParticipation = fraction;
270280
}
271281

282+
/**
283+
* @notice Set what portion of voting havvens need to be in the affirmative
284+
* to allow it to pass.
285+
*/
272286
function setRequiredMajority(uint fraction)
273287
external
274288
onlyOwner
@@ -280,35 +294,37 @@ contract Court is SafeDecimalMath, Owned {
280294

281295
/* ========== VIEW FUNCTIONS ========== */
282296

283-
/* There is a motion in progress on the specified
284-
* account, and votes are being accepted in that motion. */
297+
/**
298+
* @notice There is a motion in progress on the specified
299+
* account, and votes are being accepted in that motion.
300+
*/
285301
function motionVoting(uint motionID)
286302
public
287303
view
288304
returns (bool)
289305
{
290-
/* No need to check (startTime < now) as there is no way
291-
* to set future start times for votes.
292-
* These values are timestamps, they will not overflow
293-
* as they can only ever be initialised to relatively small values. */
294306
return motionStartTime[motionID] < now && now < motionStartTime[motionID] + votingPeriod;
295307
}
296308

297-
/* A vote on the target account has concluded, but the motion
309+
/**
310+
* @notice A vote on the target account has concluded, but the motion
298311
* has not yet been approved, vetoed, or closed. */
299312
function motionConfirming(uint motionID)
300313
public
301314
view
302315
returns (bool)
303316
{
304317
/* These values are timestamps, they will not overflow
305-
* as they can only ever be initialised to relatively small values. */
318+
* as they can only ever be initialised to relatively small values.
319+
*/
306320
uint startTime = motionStartTime[motionID];
307321
return startTime + votingPeriod <= now &&
308322
now < startTime + votingPeriod + confirmationPeriod;
309323
}
310324

311-
/* A vote motion either not begun, or it has completely terminated. */
325+
/**
326+
* @notice A vote motion either not begun, or it has completely terminated.
327+
*/
312328
function motionWaiting(uint motionID)
313329
public
314330
view
@@ -319,8 +335,10 @@ contract Court is SafeDecimalMath, Owned {
319335
return motionStartTime[motionID] + votingPeriod + confirmationPeriod <= now;
320336
}
321337

322-
/* If the motion was to terminate at this instant, it would pass.
323-
* That is: there was sufficient participation and a sizeable enough majority. */
338+
/**
339+
* @notice If the motion was to terminate at this instant, it would pass.
340+
* That is: there was sufficient participation and a sizeable enough majority.
341+
*/
324342
function motionPasses(uint motionID)
325343
public
326344
view
@@ -343,6 +361,9 @@ contract Court is SafeDecimalMath, Owned {
343361
fractionInFavour > requiredMajority;
344362
}
345363

364+
/**
365+
* @notice Return if the specified account has voted on the specified motion
366+
*/
346367
function hasVoted(address account, uint motionID)
347368
public
348369
view
@@ -354,10 +375,12 @@ contract Court is SafeDecimalMath, Owned {
354375

355376
/* ========== MUTATIVE FUNCTIONS ========== */
356377

357-
/* Begin a motion to confiscate the funds in a given nomin account.
358-
* Only the foundation, or accounts with sufficient havven balances
378+
/**
379+
* @notice Begin a motion to confiscate the funds in a given nomin account.
380+
* @dev Only the foundation, or accounts with sufficient havven balances
359381
* may elect to start such a motion.
360-
* Returns the ID of the motion that was begun. */
382+
* @return Returns the ID of the motion that was begun.
383+
*/
361384
function beginMotion(address target)
362385
external
363386
returns (uint)
@@ -376,22 +399,21 @@ contract Court is SafeDecimalMath, Owned {
376399
/* Disallow votes on accounts that have previously been frozen. */
377400
require(!nomin.frozen(target));
378401

379-
/* Rollover the fee period in case it hasn't happened yet */
380-
havven.rolloverFeePeriod();
381-
382402
uint motionID = nextMotionID++;
383403
motionTarget[motionID] = target;
384404
targetMotionID[target] = motionID;
385405

386406
/* Start the vote at the start of the next fee period */
387-
motionStartTime[motionID] = havven.feePeriodStartTime() + havven.targetFeePeriodDurationSeconds();
388-
emit MotionBegun(msg.sender, msg.sender, target, target, motionID, motionID, motionStartTime[motionID]);
407+
uint startTime = havven.feePeriodStartTime() + havven.targetFeePeriodDurationSeconds();
408+
motionStartTime[motionID] = startTime;
409+
emit MotionBegun(msg.sender, msg.sender, target, target, motionID, motionID, startTime);
389410

390411
return motionID;
391412
}
392413

393-
/* Shared vote setup function between voteFor and voteAgainst.
394-
* Returns the voter's vote weight. */
414+
/**
415+
* @notice Shared vote setup function between voteFor and voteAgainst.
416+
* @return Returns the voter's vote weight. */
395417
function setupVote(uint motionID)
396418
internal
397419
returns (uint)
@@ -406,11 +428,6 @@ contract Court is SafeDecimalMath, Owned {
406428
/* The voter may not cast votes on themselves. */
407429
require(msg.sender != motionTarget[motionID]);
408430

409-
/* Ensure the voter's vote weight is current. */
410-
/* We use a fee period guaranteed to have terminated before
411-
* the start of the vote. Select the right period if
412-
* a fee period rolls over in the middle of the vote. */
413-
414431
uint weight = havven.recomputeAccountLastHavvenAverageBalance(msg.sender);
415432

416433
/* Users must have a nonzero voting weight to vote. */
@@ -421,8 +438,10 @@ contract Court is SafeDecimalMath, Owned {
421438
return weight;
422439
}
423440

424-
/* The sender casts a vote in favour of confiscation of the
425-
* target account's nomin balance. */
441+
/**
442+
* @notice The sender casts a vote in favour of confiscation of the
443+
* target account's nomin balance.
444+
*/
426445
function voteFor(uint motionID)
427446
external
428447
{
@@ -432,8 +451,10 @@ contract Court is SafeDecimalMath, Owned {
432451
emit VotedFor(msg.sender, msg.sender, motionID, motionID, weight);
433452
}
434453

435-
/* The sender casts a vote against confiscation of the
436-
* target account's nomin balance. */
454+
/**
455+
* @notice The sender casts a vote against confiscation of the
456+
* target account's nomin balance.
457+
*/
437458
function voteAgainst(uint motionID)
438459
external
439460
{
@@ -443,8 +464,10 @@ contract Court is SafeDecimalMath, Owned {
443464
emit VotedAgainst(msg.sender, msg.sender, motionID, motionID, weight);
444465
}
445466

446-
/* Cancel an existing vote by the sender on a motion
447-
* to confiscate the target balance. */
467+
/**
468+
* @notice Cancel an existing vote by the sender on a motion
469+
* to confiscate the target balance.
470+
*/
448471
function cancelVote(uint motionID)
449472
external
450473
{
@@ -476,6 +499,9 @@ contract Court is SafeDecimalMath, Owned {
476499
delete vote[msg.sender][motionID];
477500
}
478501

502+
/**
503+
* @notice clear all data associated with a motionID for hygiene purposes.
504+
*/
479505
function _closeMotion(uint motionID)
480506
internal
481507
{
@@ -487,17 +513,21 @@ contract Court is SafeDecimalMath, Owned {
487513
emit MotionClosed(motionID, motionID);
488514
}
489515

490-
/* If a motion has concluded, or if it lasted its full duration but not passed,
491-
* then anyone may close it. */
516+
/**
517+
* @notice If a motion has concluded, or if it lasted its full duration but not passed,
518+
* then anyone may close it.
519+
*/
492520
function closeMotion(uint motionID)
493521
external
494522
{
495523
require((motionConfirming(motionID) && !motionPasses(motionID)) || motionWaiting(motionID));
496524
_closeMotion(motionID);
497525
}
498526

499-
/* The foundation may only confiscate a balance during the confirmation
500-
* period after a motion has passed. */
527+
/**
528+
* @notice The foundation may only confiscate a balance during the confirmation
529+
* period after a motion has passed.
530+
*/
501531
function approveMotion(uint motionID)
502532
external
503533
onlyOwner
@@ -509,7 +539,7 @@ contract Court is SafeDecimalMath, Owned {
509539
emit MotionApproved(motionID, motionID);
510540
}
511541

512-
/* The foundation may veto a motion at any time. */
542+
/* @notice The foundation may veto a motion at any time. */
513543
function vetoMotion(uint motionID)
514544
external
515545
onlyOwner

contracts/ExternStateToken.sol renamed to contracts/DestructibleExternStateToken.sol

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
-----------------------------------------------------------------
33
FILE INFORMATION
44
-----------------------------------------------------------------
5-
file: ExternStateToken.sol
6-
version: 1.0
5+
file: DestructibleExternStateToken.sol
6+
version: 1.1
77
author: Anton Jurisevic
88
Dominic Romanowski
99
10-
date: 2018-2-28
10+
date: 2018-05-02
1111
1212
checked: Mike Spain
1313
approved: Samuel Brooks
@@ -28,14 +28,14 @@ pragma solidity 0.4.23;
2828

2929

3030
import "contracts/SafeDecimalMath.sol";
31-
import "contracts/Owned.sol";
31+
import "contracts/SelfDestructible.sol";
3232
import "contracts/TokenState.sol";
3333

3434

3535
/**
3636
* @title ERC20 Token contract, with detached state and designed to operate behind a proxy.
3737
*/
38-
contract ExternStateToken is SafeDecimalMath, Owned {
38+
contract DestructibleExternStateToken is SafeDecimalMath, SelfDestructible {
3939

4040
/* ========== STATE VARIABLES ========== */
4141

@@ -62,7 +62,7 @@ contract ExternStateToken is SafeDecimalMath, Owned {
6262
constructor(string _name, string _symbol,
6363
uint _initialSupply, address _initialBeneficiary,
6464
TokenState _state, address _owner)
65-
Owned(_owner)
65+
SelfDestructible(_owner, _owner)
6666
public
6767
{
6868
name = _name;

0 commit comments

Comments
 (0)