Skip to content

Commit

Permalink
Merge pull request #83 from primitivefinance/system/20
Browse files Browse the repository at this point in the history
Alpha release v0.2.0 - Protocol Genesis
  • Loading branch information
Alexangelj authored Jun 10, 2020
2 parents f308ffe + ec6956f commit 255d901
Show file tree
Hide file tree
Showing 39 changed files with 1,350 additions and 1,935 deletions.
9 changes: 1 addition & 8 deletions .solcover.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
module.exports = {
skipFiles: [
"./Primitives.sol",
"./interfaces",
"./tokens",
"./test",
"./PrimeExchange.sol",
"./PrimePool.sol",
],
skipFiles: ["./Primitives.sol", "./interfaces", "./tokens", "./test"],
providerOptions: {
default_balance_ether: "1000",
},
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

Primitive is a permissionless options protocol. Built on Ethereum.

## Risk

The protocol and software is in an alpha stage.

## Overview

We overview the contracts and their functions as well as how to test them.
Expand Down
2 changes: 1 addition & 1 deletion buidler.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = {
useColors: true,
},
etherscan: {
url: "https://api.etherscan.io/api",
url: "https://api-rinkeby.etherscan.io/api",
apiKey: ETHERSCAN_APY_KEY,
},
gasReporter: {
Expand Down
69 changes: 0 additions & 69 deletions contracts/Factory.sol

This file was deleted.

107 changes: 55 additions & 52 deletions contracts/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# Primitives

## Documentation

Documentation is also [here](https://docs.primitive.finance).

## Overview

We design smart tokens. These are tokens that inherit the ERC-20 standard and add extra functions to fulfill a specification.
We design base unit primitives, which we call smart tokens. These are tokens that inherit the ERC-20 standard and add extra functions to fulfill a specification.

Smart tokens can be designed to fulfill the specifications of more complex financial instruments like options, synthetics, and stablecoins.

We designed the first smart token with the options market of DeFi in mind.

## Directory Structure

The folders are structured in a way to organize the three components of the protocol: primitives, extensions, and applications. We also have a registry folder which is the factory that deploys and tracks these contracts.

## The Prime

The Prime is a smart token with embedded optionality.
Expand All @@ -19,29 +24,29 @@ This token gives the holder the ability to swap two assets at a fixed exchange r

#### The vanilla option specification:

* Underlying asset.
* Strike Price denominated in $USD.
* Expiration date.
* Buy/Sell underlying asset for strike price.
- Underlying asset.
- Strike Price denominated in \$USD.
- Expiration date.
- Buy/Sell underlying asset for strike price.

#### The Prime specification:

* Address of underlying token.
* Address of strike token.
* "Base" value \(amount of underlying tokens\).
* "Price" value \(strike price\).
* Expiration Date, a UNIX timestamp.
- Address of underlying token.
- Address of strike token.
- "Base" value \(amount of underlying tokens\).
- "Price" value \(strike price\).
- Expiration Date, a UNIX timestamp.

#### Four Token Design

The Prime contract accepts certain tokens as inputs and knows what tokens to output. There are four critical tokens that are in this system:

| Name | Function | Example |
| :--- | :--- | :--- |
| Prime | Vanilla Option | Right to sell ETH for DAI \(ETH Put\) |
| Redeem | Underwriter's receipt | Redeem for ETH |
| Underlying | Token that is purchasable | DAI |
| Strike | Token that is used to purchase underlying | ETH |
| Name | Function | Example |
| :--------- | :---------------------------------------- | :------------------------------------ |
| Prime | Vanilla Option | Right to sell ETH for DAI \(ETH Put\) |
| Redeem | Underwriter's receipt | Redeem for ETH |
| Underlying | Token that is purchasable | DAI |
| Strike | Token that is used to purchase underlying | ETH |

The simplicity in the system comes from this four token design, which makes the input/output calculations simple accounting formulas.

Expand Down Expand Up @@ -116,52 +121,52 @@ This is the full constructor of the Prime contract:

The name, symbol, and marketId will be the identifiers for the option contract. There will be extension contracts which will track these identifiers in a global list of Prime options outstanding.

* `string memory name, <-----`
* `string memory symbol, <-----`
* `uint256 _marketId, <-----`
* `address tokenU,`
* `address tokenS,`
* `uint256 base,`
* `uint256 price,`
* `uint256 expiry`
- `string memory name, <-----`
- `string memory symbol, <-----`
- `uint256 _marketId, <-----`
- `address tokenU,`
- `address tokenS,`
- `uint256 base,`
- `uint256 price,`
- `uint256 expiry`

#### Choosing the Assets

We choose the underlying asset based on what the user wants to buy, WETH, and we give it a strike price based on the strike asset, which we choose to be stablecoin, like DAI.

* `address tokenU, <-----`
* `address tokenS, <-----`
* `uint256 base,`
* `uint256 price,`
* `uint256 expiry`
- `address tokenU, <-----`
- `address tokenS, <-----`
- `uint256 base,`
- `uint256 price,`
- `uint256 expiry`

#### Choosing the ratio between the assets

The user wants to buy the WETH at a rate of 1 WETH per 200 DAI. WETH is the underlying asset and the amount is 1, so that is the _Base_ value. DAI is the strike asset, with an amount of 200, which is the _Price_ value.

The rate for this Prime is:

* `1 WETH / 200 DAI`
* `Base / Price`
* `Buy 200 DAI for 1 WETH per 1 Prime you own`
- `1 WETH / 200 DAI`
- `Base / Price`
- `Buy 200 DAI for 1 WETH per 1 Prime you own`

You are changing these values:

* `address tokenU,`
* `address tokenS,`
* `uint256 base, <-----`
* `uint256 price, <-----`
* `uint256 expiry`
- `address tokenU,`
- `address tokenS,`
- `uint256 base, <-----`
- `uint256 price, <-----`
- `uint256 expiry`

#### Choosing the expiration date

Lets also make the Prime expire at some future point of time, say June of 2020. We can pass an _expiration_ date into the constructor's parameters.

* `address tokenU,`
* `address tokenS,`
* `uint256 base,`
* `uint256 price,`
* `uint256 expiry <-----`
- `address tokenU,`
- `address tokenS,`
- `uint256 base,`
- `uint256 price,`
- `uint256 expiry <-----`

Now that we have all the ingredients, we can make a Prime and then use it.

Expand All @@ -171,13 +176,13 @@ To mint Primes we need to send it the underlying assets. The contract knows how

If we send 1 WETH to this contract, the amount of outputted Primes is equal to this input which is:

* `1 WETH Input = 1 Prime Output.`
- `1 WETH Input = 1 Prime Output.`

The contract also outputs redeem tokens. The amount of Redeems to output is proportional to the input of WETH and the _rate_ of the Prime.

* `1 WETH (Input) / (1 WETH (Base) / 200 DAI (Price)) = 200 Redeems to Output.`
* `Rate = Base / Price.`
* `Input Underlying / Rate = Output Redeem.`
- `1 WETH (Input) / (1 WETH (Base) / 200 DAI (Price)) = 200 Redeems to Output.`
- `Rate = Base / Price.`
- `Input Underlying / Rate = Output Redeem.`

#### Swapping, also called Exercising

Expand All @@ -189,24 +194,24 @@ A Prime has the right to swap to the underlying asset at a 1:1 ratio. If underly

The contract knows how to handle this.

* `200 DAI * (1 WETH / 200 DAI) = 1 WETH.`
* `Input Strike Tokens (DAI) * (Base (Quantity of WETH) / Price (Quantity of DAI)) = Output Underlying Tokens.`
- `200 DAI * (1 WETH / 200 DAI) = 1 WETH.`
- `Input Strike Tokens (DAI) * (Base (Quantity of WETH) / Price (Quantity of DAI)) = Output Underlying Tokens.`

#### Redeeming

Since we just bought the 1 WETH for 200 DAI, where does the DAI go and who gets the DAI?

The DAI goes to the Prime contract and it is redeemable at a 1:1 ratio using the Redeem token.

* `Input Redeem = Output Strike (DAI).`
- `Input Redeem = Output Strike (DAI).`

#### Closing

What about the case where we want to withdraw our underlying assets that we used in order to mint the Prime. The Prime and the Redeem token can be sent to the contract in exchange for the underlying tokens. In this case, it is a lot like the reverse of the minting process!

If you minted 1 Prime and 200 Redeems in exchange for 1 WETH, you need to send the contract 1 Prime and 200 Redeems in order to withdraw 1 WETH.

* `Input Redeem Tokens * Rate & Prime Tokens = Output Underlying Tokens.`
- `Input Redeem Tokens * Rate & Prime Tokens = Output Underlying Tokens.`

### Expiration

Expand Down Expand Up @@ -257,8 +262,6 @@ $$
\frac{Strike}{Market} \times ImpliedVol \times \sqrt{T} \times \frac{1}{SecondsInDay}
$$



We use demand as a proxy for the Implied Volatility value. How do we get the demand for the option?

### Demand of the Primes
Expand Down
Loading

0 comments on commit 255d901

Please sign in to comment.