Git Product home page Git Product logo

set-protocol-contracts's Introduction

{Set} Protocol: A Specification for Token Abstraction

Author: Felix Feng <[email protected]>

Welcome to {Set}

{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.

Install and run the unit tests

  1. Run npm install
npm install
  1. Install truffle and test-rpc globally
npm i -g ethereumjs-testrpc
npm install -g truffle
  1. Run unit tests
truffle compile
truffle 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:

Figure 1: {Set} Issuance Process

Set Issuance

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:

Figure 2: {Set} Redemption Process

Set Redemption

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

set-protocol-contracts's People

Contributors

felix2feng avatar justinkchen avatar

Watchers

aaron liu avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.