Skip to content

hack-money/primitive-contracts

 
 

Repository files navigation

Primitive Protocol

Twitter Follow Discord

Primitive is a permissionless options protocol.

Overvie

We overview the contracts and their functions as well as how to test them.

Environment

Our development environment consists of the following:

  • Buidler - Framework
  • Solidity Visual Auditor - VS Code
  • Slither - static analyzer
  • Solium - linter
  • Web3/Truffle plugins for Buidler
  • Mocha - testing framework
  • Chai, chai-bn, and bn.js - unit testing
  • Truffle assertions - unit testing
  • Open Zeppelin Contracts - contract dependency

Contracts

Mainnet

Status Contract Address Link
Active Prime Option 0xced83f96AA38bFe34617ea1F699F9f0022548f61 Etherscan
Active Prime Redeem 0xB0A4d596939715f203Fa9E907935938FEdEa715F Etherscan
Active Prime Trader 0xff5C103d76586BB55bb33CE01f3dEc9cEe55617f Etherscan
Paused Prime Pool 0xf7a7126C6eB9c2cC0dB9F936bA4d0D5685662830 Etherscan

Documentation

Documentation

Testing

Use Docker

docker build -t primitive-contracts
docker run -it --name primitive primitive

npm run test
npm run coverage

Or...

Steps to testing using the buidler EVM

Step 1 - Install Dependencies

npm run clean-install

Step 2 - Compile Contracts

npm run compile

Step 3 - Start Buidler EVM Node

npm run bevm

Step 4 - Run the tests

npm run test

Steps to testing using the ganache-cli on forked mainnet

Step 1

npm i

Step 2

npm compile

Step 3 - A forked mainnet node with network ID 999 is required.

npm start:f-mainnet

Step 4

npm test:f-mainnet

Coverage

For coverage, we use buidler's plugin for solidity-coverage.

npm run coverage

Linting

For linting you can run this command which uses the solium linter:

npm run lint

Solium can also fix some linting errors which can be checked with this command:

npm run lint:fix

Static analysis

For static analysis you can run the contracts through slither with this command:

npm slither

Etherscan Addresses

PrimeOption - Primitive

PrimeRedeem - Primitive

PrimeTrader - Extension

PrimePool - Extension

Primitives

Prime Option

The Prime is a smart token with vanilla option attributes and functionality embedded into the token. It inherits the ERC-20 token standard and adds functionality which matches the specification of a vanilla option.

The vanilla option specification:

- Underlying asset.
- Strike Price denominated in $USD.
- Expiration date.

The Prime specification:

- Address of underlying token.
- Address of stike token.
- "Base" value (Amount of underlying tokens).
- "Price" value (Amount of strike tokens).
- Expiration Date, a UNIX timestamp.

The Base and Price attributes make up the strike ratio.

- Base / Price = Strike Ratio

Prime Redeem

The Redeem token is a helper token for the Prime which manages the accounting for the underwriters. When underwriters deposit underlying tokens they receive Primes and also a 'receipt' token, the Redeem. This Redeem token is used to withdraw strike tokens from the Prime when the Prime's underlying tokens are exercised, or its used to withdraw underlying tokens when the Primes expire.

Extensions

Prime Trader

This is an extension contract to support easier interaction with the Prime Option contract. The Prime Option contract operates with optimistic swap technology. It assumes that tokens are sent into it before its functions are called. The Prime Option contract does not use any transferFrom calls.

The trader does the transferFrom call to the user, then it transfers the tokens to the Prime Option contract, and finally it calls one of the functions in the Prime Option contract like mint.

The trader contract does this all in a single transaction and it can call any function in the Prime Option contract.

Prime Pool

This is a liquidity pool contract that has the logic to (1) Accept underlying token deposits. (2) Mint Primes with the underlying tokens. (3) Sell the Primes for premium to buyers.

Prime Oracle

Feeds a price, the premium, to the Prime Pool. The Primes are sold from the pool to buyers at this price given by the oracle.

Contributing and Discussion

Join our community and protocol developers in the Primitive Discord.

If you have security concerns, email us at primitive@primitive.finance.

About

Alpha Primitive Solidity Contracts ⚠️

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 55.6%
  • Solidity 44.3%
  • Dockerfile 0.1%