Author: Felix Feng <[email protected]>
{Set} is a specification for abstract or higher order tokens on the ethereum blockchain - written in the Solidity programming language. This repo has the SetToken
smart contract with a suite of unit tests for the {Set} token specification. The contracts are held inside the contracts
directory.
See the {Set} whitepaper for more about {Set}.
PLEASE NOTE that these contracts have not been extensively audited yet and are not deployed to mainnet. Until contracts have been thoroughly vetted and fully productionized, we do not recommend using for valuable transactions yet.
- Run npm install
npm install
npm i -g ethereumjs-testrpc
npm install -g truffle
- Run unit tests
truffle compile
truffle test
The {Set} contract has three functions, which are the constructor, issue, and redeem.
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 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:
Figure 1: {Set} Issuance Process
Figure 1 steps explained
- Issuer decides the quantity of {Set} tokens to issue
- Issuer calls Token A's
approve
function for the specified unit of Token A required multiplied by the quantity desired to issue - Issuer calls Token B's
approve
function for the specified unit of Token B required multiplied by the quantity desired to issue - Issue continues to call
approve
for the correct amount to all remaining tokens - Issuer calls the {Set} Contract's
issue
function with the desired quantity of Index Tokens to issue - The contract transfers the required quantities of tokens to the contracts. If any transfer is unsuccessful, the whole transaction is reverted.
- If the previous step was sucessful, the contract increments the corresponding quantity of tokens to the issuer
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:
Figure 2: {Set} Redemption Process
Figure steps explained
- Issuer decides the quantity of {Set} tokens to redeem
- Issuer calls the
redeem
function with the quantity to redeem - The contract checks to ensure that the user has enough Index tokens. The function reverts if not.
- The contract transfers the underlying tokens to the sender and then decrements the sender's index token balance