Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #13 from SetProtocol/v0.2.0
Browse files Browse the repository at this point in the history
@SetProtocol Alpha Release V0.2.0
  • Loading branch information
felix2feng authored Apr 17, 2018
2 parents 61d4fb9 + 5eb5987 commit 1b722a9
Show file tree
Hide file tree
Showing 65 changed files with 67,758 additions and 3,365 deletions.
14 changes: 14 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2

jobs:
build:
docker:
- image: circleci/node:9.6.1
steps:
- checkout
- run: yarn
- run:
name: testrpc
command: yarn chain
background: true
- run: yarn test
17 changes: 15 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
node_modules/
build
.DS_Store
/node_modules
/transpiled
/types/generated/*
/build
/dist

### Node ###

# Logs
*.log
/logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
types/generated/
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# .prettierrc
printWidth: 100
parser: typescript
tabWidth: 2
trailingComma: all
arrowParens: always
16 changes: 10 additions & 6 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"extends": "default",
"rules": {
"indent": ["error", 2],
"quotes": ["error", "double"],
"max-line-length": ["error", 120]
}
"extends": "default",
"rules": {
"indent": ["error", 2],
"code-complexity": false,
"function-max-lines": false,
"separate-by-one-line-in-contract": false,
"not-rely-on-time": false,
"no-unused-vars": false,
"no-empty-blocks": false
}
}
75 changes: 5 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,83 +13,18 @@ PLEASE NOTE that these contracts have not been extensively audited yet and are n

## Install and run the unit tests

1. Run npm install
1. Run yarn install
```
npm install
yarn install
```

2. Install [truffle](http://truffleframework.com/) and [test-rpc](https://github.com/ethereumjs/testrpc) globally
```
npm i -g ethereumjs-testrpc
npm install -g truffle
yarn global add ethereumjs-testrpc
yarn global add truffle
```

3. Run unit tests
```
truffle compile
truffle test
yarn run test
```



## Smart Contract
The {Set} contract has three functions, which are the constructor, issue, and redeem.

### Underwriting (constructor)
Underwriting is the process of creating a new {Set} contract. Anybody can create an Index Token by deploying a new {Set} contract that follows the {Set} specification to an Ethereum network. The constructor function is only called once during deployment. The required constructor parameters are below:

**Token Creation Parameters**

Parameter | Type | Description
------------ | ------------- | -------------
tokens | address[] | A list of ERC20 token addresses
units | uint[] | A list of quantities for each token

There are no restrictions to how many different ERC20 tokens can be included, aside from the transaction gas limit and data input limits. Since {Set}s are ERC20 tokens, {Set}s could be composed of other {Set}s. Deploying a {Set} creates a clean-slate contract with 0 tokens.


### Token Issuance (issue)
Token issuance is the process of generating new tokens from a {Set} Contract. Given the {Set} contract has been deployed, anybody can call the contract's `issue` function to convert a specified mix of ERC20 tokens into a token that represents its underlying parts. There only exists as many {Set} tokens as there are tokens issued less redemptions. The issue function parameters are:

**Issue Function Parameters**

Parameter | Type | Description
------------ | ------------- | -------------
quantity | uint | The quantity of {Set}s to issue

There are 7 steps to issuing a {Set} token:

<p align="center"><strong>Figure 1: {Set} Issuance Process</strong></p>
<p align="center"><img src="diagrams/SetIssuance.png" alt="Set Issuance" height="300"/></p>

Figure 1 steps explained

1. Issuer decides the quantity of {Set} tokens to issue
2. Issuer calls Token A's `approve` function for the specified unit of Token A required multiplied by the quantity desired to issue
3. Issuer calls Token B's `approve` function for the specified unit of Token B required multiplied by the quantity desired to issue
4. Issue continues to call `approve` for the correct amount to all remaining tokens
5. Issuer calls the {Set} Contract's `issue` function with the desired quantity of Index Tokens to issue
6. The contract transfers the required quantities of tokens to the contracts. If any transfer is unsuccessful, the whole transaction is reverted.
7. If the previous step was sucessful, the contract increments the corresponding quantity of tokens to the issuer


### Token Redemption (redeem)
Token Redemption is the process of converting an Index Token into its underlying component tokens. Redeeming tokens reduces the token supply of {Set} tokens in the contract. The issue function parameters are:

**Redeem Function Parameters**

Parameter | Type | Description
------------ | ------------- | -------------
quantity | uint | The quantity of {Set}s to redeem

There are 4 steps to issuing a {Set} token:

<p align="center"><strong>Figure 2: {Set} Redemption Process</strong></p>
<p align="center"><img src="diagrams/SetRedemption.png" alt="Set Redemption" height="200"/></p>

Figure steps explained
1. Issuer decides the quantity of {Set} tokens to redeem
2. Issuer calls the `redeem` function with the quantity to redeem
3. The contract checks to ensure that the user has enough Index tokens. The function reverts if not.
4. The contract transfers the underlying tokens to the sender and then decrements the sender's index token balance

19 changes: 19 additions & 0 deletions artifacts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { BasicToken } from "./ts/BasicToken";
import { DetailedERC20 } from "./ts/DetailedERC20";
import { ERC20 } from "./ts/ERC20";
import { ERC20Basic } from "./ts/ERC20Basic";
import { Set } from "./ts/Set";
import { SetToken } from "./ts/SetToken";
import { StandardToken } from "./ts/StandardToken";
import { StandardTokenMock } from "./ts/StandardTokenMock";

export {
BasicToken,
DetailedERC20,
ERC20,
ERC20Basic,
Set,
SetToken,
StandardToken,
StandardTokenMock,
};
Loading

0 comments on commit 1b722a9

Please sign in to comment.