Skip to content
This repository was archived by the owner on Jan 1, 2020. It is now read-only.

Common cases #5

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
0bf91c5
Pulled validated token
expede Apr 2, 2018
7439e56
This is starting to make more sense 😅
expede Apr 3, 2018
dd2d72e
Compiles
expede Apr 3, 2018
25d063e
Tweak
expede Apr 3, 2018
f93e551
Better types
expede Apr 3, 2018
dc48a0c
Better types
expede Apr 3, 2018
3335ac0
Better types
expede Apr 3, 2018
8ae6c57
Bump sol
expede Apr 3, 2018
313e555
Notes to self
expede Apr 3, 2018
fe2d71f
Refactoring
expede Apr 4, 2018
7d14bfc
Time locking in validator
expede Apr 4, 2018
1eed981
Charts
expede Apr 4, 2018
eb48464
Speed bump
expede Apr 4, 2018
7bcf3d3
Thought
expede Apr 4, 2018
81ce89e
Tweak
expede Apr 5, 2018
e7593ae
Tweak
expede Apr 5, 2018
ef8791a
Clarify with README
expede Apr 5, 2018
6c9b947
Clean up README
expede Apr 5, 2018
eb0de61
Rearrange
expede Apr 5, 2018
4715fd2
Typo
expede Apr 5, 2018
44e5d40
Note to self
expede Apr 5, 2018
9b6e454
Remove unused code
expede Apr 5, 2018
6fccc46
Crutial flaw
expede Apr 5, 2018
7687ff8
WIP
expede Apr 10, 2018
4e96a8f
WIP
expede Apr 12, 2018
09f084e
WIP
expede Apr 12, 2018
249b6ed
Wow it compiles
expede Apr 12, 2018
44bc28c
Happily compiling
expede Apr 12, 2018
c9ac427
yey
expede Apr 12, 2018
ea80535
just tests
expede Apr 12, 2018
d902188
Starting on tests
expede Apr 12, 2018
5c01f17
muahahhaa it compiles again
expede Apr 18, 2018
75935b3
Passing
expede Apr 19, 2018
e6f16a3
Compiles again
expede Apr 19, 2018
80df5e6
Tests pass agian
expede Apr 19, 2018
26109f3
Break out portions of functionality
expede Apr 19, 2018
f4bacf0
Sure why not
expede Apr 19, 2018
8a2fc8a
Starting tests for closable
expede Apr 19, 2018
babc37b
test closable
expede Apr 19, 2018
44c979f
WIP
expede Apr 20, 2018
829372b
Truffle! YUNO return value
expede Apr 21, 2018
34d51e9
ESLint
expede Apr 21, 2018
e87bbe4
Troubleshooting Could not find artifacts for truffle/Assert.sol
expede Apr 23, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 30 additions & 37 deletions contracts/Deal.sol
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
pragma solidity ^0.4.15;


import '../node_modules/zeppelin-solidity/contracts/crowdsale/Crowdsale.sol';
import './TxOwnable.sol';
import './DealToken.sol';


contract Deal is Crowdsale, TxOwnable {

DealToken dealToken;
mapping (address => bool) authorized;
event Authorizing(address sender, address investor);

function Deal(uint256 _startTime, uint256 _endTime, uint256 _rate, address _wallet)
Crowdsale(_startTime, _endTime, _rate, _wallet) TxOwnable {
}

// creates the token to be sold.
// override this method to have crowdsale of a specific MintableToken token.
function createTokenContract() internal returns (MintableToken) {
// address dealAddress = address(this);
// DealToken(dealAddress, address(token));
dealToken = new DealToken();
return dealToken;
}

function authorize(address investor) onlyOwner public {
Authorizing(msg.sender,investor);
dealToken.authorizeAddress(investor,true);
authorized[investor] = true;
}


function buyTokens(address beneficiary) public payable {
return super.buyTokens(beneficiary);
}
pragma solidity ^0.4.19;

import '../node_modules/validated-token/contracts/ReferenceToken.sol';

contract Deal is ReferenceToken {
using SafeMath for uint256;

uint256 public startTime;
uint256 public endTime;
uint256 public holdPeriod;

function Deal(
string _name,
string _symbol,
uint256 _granularity,
uint256 _startTime,
uint256 _endTime,
uint256 _holdPeriod,
TokenValidator _validator
) ReferenceToken(_name, _symbol, _granularity, _validator) public {
require(_startTime >= now);
require(_startTime < _endTime);

startTime = _startTime;
endTime = _endTime;
}

function endNow() public onlyOwner {
endTime = now;
}
}
33 changes: 22 additions & 11 deletions contracts/DealFactory.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
pragma solidity ^0.4.15;

pragma solidity ^0.4.19;

import './Deal.sol';


contract DealFactory {
event DealCreated(address sender, address instance);
event DealCreated(address sender, Deal deal);
mapping(address => Deal[]) private registry;

function create(
string _name,
string _symbol,
uint256 _granularity,
uint256 _startTime,
uint256 _endTime,
uint256 _holdPeriod,
TokenValidator _validator
) public returns (Deal _deal) {
Deal deal =
new Deal(_name, _symbol, _granularity, _startTime, _endTime, _holdPeriod, _validator);

registry[msg.sender].push(deal);
DealCreated(msg.sender, deal);

return deal;
}

mapping(address => address[]) public instantiations;
function createDeal(uint256 _startTime, uint256 _endTime, uint256 _rate, address _wallet) public returns (address deal) {
deal = new Deal(_startTime, _endTime, _rate, _wallet);
instantiations[msg.sender].push(deal);
DealCreated(msg.sender,deal);
return deal;
}
function mine() public view returns (Deal[]) { return registry[msg.sender]; }
}
13 changes: 0 additions & 13 deletions contracts/DealToken.sol

This file was deleted.

48 changes: 0 additions & 48 deletions contracts/RegulatedToken.sol

This file was deleted.

17 changes: 0 additions & 17 deletions contracts/SimpleContract.sol

This file was deleted.

53 changes: 53 additions & 0 deletions contracts/StaggeredDeal.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
pragma solidity ^0.4.19;

import './Deal.sol';

/** Staggered close

startTime endTime dealOver
-tX t0 tZ
|============|============================|
Prehistory | Mintable | Tradeable | Inactive
|============|============================|
| | |
| | |
Alice | a ---------- a + holdPeriod |
| Mint Hold Trade |
| | |
| | |
Bob | b ---------- b + holdPeriod |
| Mint Hold Trade |
| | |
| | |
Carol | c ---------- c + holdPeriod |
| Mint | Hold Trade |
| | |

*/
contract StaggeredDeal is Deal {
struct Minting {
uint256 amount;
uint256 createdAt;
}

mapping(address => Minting[]) public mintings;

/* function StaggeredDeal( */
/* string _name, */
/* string _symbol, */
/* uint256 _granularity, */
/* uint256 _startTime, */
/* uint256 _endTime, */
/* uint256 _holdPeriod, */
/* TokenValidator _validator */
/* ) Deal(_name, _symbol, _granularity, _holdPeriod, _validator) public {} */

function mint(address _tokenHolder, uint256 _amount) public onlyOwner {
mintings[_tokenHolder].push(Minting({
amount: _amount,
createdAt: now
}));

super.mint(_tokenHolder, _amount);
}
}
42 changes: 0 additions & 42 deletions contracts/TxOwnable.sol

This file was deleted.

24 changes: 24 additions & 0 deletions contracts/heirarchy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Heirarchy

| Symbol | Meaning | Memonic |
|---------------|---------------|---------|
| `△` | Inherits from | "is a" |
| `V`, `>`, `<` | Depends on | "has a" |

```
TOKENS FACTORIES VALIDATORS

(EIP-902)
ReferenceToken
| +----- DealFactory ----> TokenValidator
| | △ △
| | | |
| |+------------------ DealValidator |
| || | |
| VV V |
Deal <-------------------- PhaseValidator
△ △
| |
StaggeredDeal <------- StaggeredPhaseValidator
```
1 change: 1 addition & 0 deletions contracts/validators/.#PhaseValidator.sol
77 changes: 77 additions & 0 deletions contracts/validators/DealValidator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
pragma solidity ^0.4.19;

import './PhaseValidator.sol';
import './TokenValidator.sol';

/* import '../Deal.sol'; */

import '../../node_modules/zeppelin-solidity/contracts/ownership/Ownable.sol';

/*
Deal DealValidator PhaseValidator
| | |
| check/4 | |
+---------------> | |
| | check/4 |
| +------------------> |
| | |
| | |
| | startTime/0 |
| <------------------------------------+
| | 12345 |
+------------------------------------> |
| | |
| | |
| | endTime/0 |
| <------------------------------------+
| | 67890 |
+------------------------------------> |
| | |
| | |
| | hex"41" |
| | <------------------+
| hex"41" | |
| <---------------+ |
| | |
| | |
*/
contract DealValidator is Ownable, TokenValidator {
using SafeMath for uint256;

PhaseValidator private phaseValidator;
mapping(address => bool) private auths;

function DealValidator(PhaseValidator _phaseValidator) Ownable public {
phaseValidator = _phaseValidator;
}

function setAuth(address _address, bool _status) public onlyOwner {
auths[_address] = _status;
}

// TOKEN VALIDATOR //

function check(Deal _deal, address _account) public returns(byte _status) {
return auths[_account] ? phaseCheck(_deal, _account) : hex"10";
}

function check(
address /* _token */,
address _from,
address _to,
uint256 _amount
) public returns (byte _validation) {
return (auths[_from] && auths[_to]) ? hex"11" : hex"10";
}

// HELPERS //

function phaseCheck(Deal _deal, address _tokenHolder) internal view returns (byte _validation) {
byte phaseState = phaseValidator.check(_deal, _tokenHolder);
return isOk(phaseState) ? hex"11" : phaseState;
}

function isOk(byte status) internal view returns (bool) {
return (status & hex"0F") == 1;
}
}
Loading