Skip to content

Commit

Permalink
Merge pull request #14 from levelkdev/update-readme
Browse files Browse the repository at this point in the history
Update Readme
  • Loading branch information
ewilz authored Oct 25, 2018
2 parents 76c8fd7 + 8f86ae9 commit 1e3c6d3
Showing 1 changed file with 31 additions and 90 deletions.
121 changes: 31 additions & 90 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,112 +1,46 @@
# Modular TCR Library

## About

This library aims to be a readable and modular library for TCR's. Ideally developers can use these contracts to deploy their TCR or use these contracts as an extension onto their personalized TCR contract. However, if developers must make changes to these existing contracts to fit their needs, the hope is that these contracts are organized enough that you can alter them with ease.
#### *** DISCLAIMER: Current version contracts are not thoroughly tested or audited. Use at own risk ***

## Structure (a work in progress)
** Plan to eventually incorporate a `Parameterizer.sol` for certain vars
## About

### Registry
This library aims to be a readable and modular library for registries and TCR's. Ideally developers can use these contracts to deploy their TCR or use these contracts as an extension onto their personalized registry contract.

`BasicRegistry.sol`

## Setup
Install node modules:
```
contract BasicRegistry {
mapping(bytes32 => bytes32) items;
function add(bytes32 data) public returns (bytes32 id);
function remove(bytes32 id) public;
function get(bytes32 id) public constant returns (bytes32);
function exists(bytes32 id) public view returns (bool);
}
$ npm install
```

`OwnedItemRegistry.sol`

Sets the msg.sender of the `add` transaction as the owner of the added item. Only allows the owner of the item to remove it.

Compile contracts:
```
contract OwnedItemRegistry is BasicRegistry {
modifier onlyItemOwner(bytes32 id);
mapping(bytes32 => address) public owners;
function add(bytes32 data) public returns (bytes32 id);
function remove(bytes32 id) public onlyItemOwner(id);
}
$ npm run compile
```

`StakedRegistry.sol`

Handles token stake for owned items. Requires a minimum stake. Allows the owner to increase or decrease stake, as long as it remains above the minimum stake.
Run tests:

```
contract StakedRegistry is OwnedItemRegistry {
ERC20 token;
uint minStake; // minimum required amount of tokens to add an item
mapping(bytes32 => uint) public ownerStakes;
function add(bytes32 data) public returns (bytes32 id);
function remove(bytes32 id) public onlyItemOwner(id);
function increaseStake(bytes32 id, uint stakeAmount) public onlyItemOwner(id);
function decreaseStake(bytes32 id, uint stakeAmount) public onlyItemOwner(id);
}
$ npm run test
```

`TimelockableItemRegistry.sol`

Provides a mapping of unlock times for items. Only allows item removal when the unlock time has been exceeded.

```
contract TimelockableItemRegistry is OwnedItemRegistry {
mapping(bytes32 => uint) public unlockTimes;

function remove(bytes32 id) public;
function isLocked(bytes32 id) public view returns (bool);
}
```
## Contract Structure

### Registry Interface

`TokenCuratedRegistry.sol`
`IRegistry.sol `

```
TokenCuratedRegistry is StakedRegistry {
uint applicationPeriod;
IChallengeFactory public challengeFactory;
mapping(bytes32 => IChallenge) public challenges;
// Adds an item to the `items` mapping, transfers token stake from msg.sender, and locks
// the item from removal until now + applicationPeriod.
interface IRegistry {
function add(bytes32 data) public returns (bytes32 id);
// Removes an item from the `items` mapping, and deletes challenge state. Requires that
// there is not an active or passed challenge for this item. OwnedItemRegistry.remove
// requires that this is called by the item owner. TimelockableItemRegistry.remove requires
// that the item is not locked.
function remove(bytes32 id) public;
// Creates a new challenge for an item.
// Requires that the item exists, and that there is no existing challenge for the item.
// Requires msg.sender (the challenger) to match the owner's stake by transferring to
// this contract. The challenger's and owner's stake is transferred to the newly created
// challenge contract.
function challenge(bytes32 id) public;
// Handles transfer of reward after a challenge has ended. Requires that there
// is an ended challenge for the item.
function resolveChallenge(bytes32 id) public;
// Returns true if the item exists and is not locked. We know that locked items are in
// the application phase, because the unlock time is set to now + applicationPeriod when
// items are added. Also, unlock time is set to 0 if an item is challenged and the
// challenge fails.
function inApplicationPhase(bytes32 id) public view returns (bool);
function get(bytes32 id) public view returns (bytes32 item);
function exists(bytes32 id) public view returns (bool itemExists);
}
```

### Challenge
### Challenge Interface
`IChallengeFactory.sol`

```
Expand All @@ -119,18 +53,25 @@ interface IChallengeFactory {

```
interface IChallenge {
// returns the address of the challenger
function challenger() view returns (address);
// returns true if the challenge has ended
function ended() view returns(bool);
function close() public;
// returns whether challenge has been officially closed
function isClosed() public view returns (bool);
// returns true if the challenge has passed
function passed() view returns (bool);
// reverts if challenge has not been closed
function passed() public view returns (bool);
// returns the amount of tokens to transfer back to the registry contract
// after the challenge has eneded, to be distributed as a reward for applicant/challenger
function reward() view returns (uint);
// @notice returns the amount of tokens the challenge must
// obtain to carry out functionality
function fundsRequired() public view returns (uint);
// returns the address of the challenger
function challenger() view returns (address);
// @dev returns amount to be rewarded to challenge winner
function winnerReward() public view returns (uint);
}
```

Expand Down

0 comments on commit 1e3c6d3

Please sign in to comment.