Code Monkey home page Code Monkey logo

gammaprotocol's Introduction

Gamma Protocol CircleCI Coverage Status

Gamma is a decentralized capital efficient option protocol that enables sellers to create spreads. Gamma protocol enables any user to create arbitrary option tokens, that represent the right to buy or sell a certain asset in a predefined price (strike price) at or before expiry. As the option seller in Gamma, you can reduce the amount of capital locked in the system by creating spreads. (e.g Instead of putting down 100 USDC and mint 1 ETH-USDC-100 Put, you can buy a ETH-USDC-50 Put, and only deposit 50 USDC as collateral) The oTokens created by Gamma are cash settled European option, means all the options will automatically be exercised at expiry. A holder can redeem the proceeds by sending the oTokens back, the system will pay the holder the cash value based on strike price and underlying spot price at expiry, instead of actually exchanging the underlying asset and the strike asset.

Documentation

Our docs site is here. It contains tutorials, explainers, and smart contract documentation. If you'd like to view these docs on github instead, check out the docs folder in the docs repo:

Local Development Setup

For local development it is recommended to use ganache to run a local development chain. Using the ganache simulator no full Ethereum node is required.

As a pre-requisite, you need:

  • Node.js (v10.18.0)
  • NPM

Clone the project and install all dependencies:

$ git clone https://github.com/opynfinance/GammaProtocol.git
$ cd GammaProtocol

# install project dependencies
$ npm i

Compile all contracts:

$ npm run build

In a new terminal, launch an Ethereum RPC client, we use the default ganache-cli command to configure and run a local development ganache:

$ npm run ganache

Switch back to your other terminal and deploy the contracts, and make sure to:

  • Add your infura key in .infuraKey file
  • Add your wallet mnemonic in .secret file
  • Setup the deployments parameters in ./migrations/deployment-config.json file
# Local deployment
$ npm run deploy:development

# Mainnet deployment
$ npm run deploy:mainnet

Running Tests

Run all unit tests:

$ npm run test:unit

Run all integration tests:

$ npm run test:integration

Linting

Clean code is the best code, so we've provided tools to automatically lint your projects.

Lint all smart contracts:

$ npm run lint:sol

Lint all tests files:

$ npm run lint:tests

Automatically Fixing Linting Issues

We've also provided tools to make it possible to automatically fix any linting issues. It's much easier than trying to fix issues manually.

Fix all smart contracts:

$ npm run lint:sol:prettier:fix

Fix all tests files:

$ npm run lint:tests:prettier:fix

Coverage

We use the solidity-coverage package to generate our coverage reports. You can find the coverage report at coveralls. Otherwise, you can generate it locally by running:

$ npm run coverage

The full report can be viewed by opening the coverage/index.html file in a browser.

Security And Bug Bounty Program

The security of the Opyn protocol is our highest priority. Our team has created a protocol that we believe is safe and dependable, and has been audited by OpenZeppelin. All smart contract code is publicly verifiable and we have a bug bounty for undiscovered vulnerabilities. We encourage our users to be mindful of risk and only use funds they can afford to lose. Options are complex instruments that when understood correctly can be powerful hedges. Smart contracts are still new and experimental technology. We want to remind our users to be optimistic about innovation while remaining cautious about where they put their money.

Please see here for details on our security audit and bug bounty program.

gammaprotocol's People

Contributors

aleone avatar alexisgauba avatar alphaserpentis avatar antoncoding avatar aparnakr avatar chudnov avatar cruzmolina avatar demolajames avatar fqlx avatar haythemsellami avatar kenchangh avatar shellygr avatar zkoticha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gammaprotocol's Issues

Factory expiry check

The current factory will only allow creation of option that expires at 08:00AM UTC.

Should we somehow make it possible to bypass this in case we need it? (Whitelist / admin?)

MarginAccount._clearVault uses a variable after it was deleted

https://crytic.io/opynfinance/GammaProtocol/54/security_checks

Crytic is complaining about our delete syntax on the vault struct. I ignore it for now because it seems fine and we already had test coverage the delete action. But probably need a deeper review before closing this.

MarginAccount._clearVault(MarginAccount.Vault) uses a variable after it was deleted
- Delete: delete _vault.longOtokens
- Use: delete _vault.collateralAssets

Make sure variables that are deleted are not used later.

[NAMING] - Controller/_exercise()

All of our european options are autoexercised. Should we rename this action as it might be confusing? No one needs to actually exercise anything. They just have to withdraw proceeds.

Some ideas:
WithdrawLongProceeds
WithdrawProceeds
WithdrawOtokenProceeds
RedeemLongProceeds
RedeemLong
Redeem
RedeemOtoken
WithdrawTheMoneys

Create truffle script to automate tasks

Create truffle script for easier dev experience

  • Whitelist a long Otoken
  • Whitelist a collateral
  • Add a pricer
  • Farm asset from pool
  • Set terminator address
  • Set disputer address
    ...

Update names + grammar

  1. Use otoken series instead of otoken to represent a specific strike-underlying-collateral-strikePrice-expiry combination

[NAMING] - paused vs emergency shutdown

Naming:

variables:
pauser
terminator
systemPaused
systemShutdown

functions:
TerminatorUpdated
PauserUpdated
SystemPaused
EmergencyShutdown

systemShutdown or emergency shutdown is done by terminator
systemPaused is done by pauser

I think we should switch names or change them. I think we should pick emergency shutdown vs system shutdown.

To me emergency shutdown implies that users will be able to unwind positions/remove collateral (kind of like maker, but at some future point in the future).
System paused implies to me that things are temporarily frozen - which I think applies to the entire protocol.

Any thoughts?

Fix rounding issue, or have a clear doc on when will it happen

In file test/integration-tests/longCallSpreadExpireItm.test.ts.

get result of getExcessCollateral is wrong

      // Todo: Fix following rounding problem
      assert.equal(
        new BigNumber(vaultStateBeforeSettlement[0]).plus(1).toString(), // -4999999999999999999
        createScaledUint256(collateralPayout, (await weth.decimals()).toNumber()), //+5000000000000000000
      )

update MarginPool and tests for standard ERC20 transfers

In the current implementation, we ignore the returned value of transfer and transferFrom. In the ERC20 standard, a failed transfer should return false instead of revert.

May need to do some more research on if there're any tokens that won't return true, and look into other protocols on how they handle it.

getExcessCollateral function doesnt always return a properly scaled value.

[Issue] the getExcessCollateral returns a 1e18 number, instead of a scaled value for a long spread which settles ITM, without collateral deposited.
Scenario:
Long Option: $300 Strike Put
Short Option: $200 Strike Put
Collateral: USDC
Long amount: 10
Short amount: 10
Collateral amount: 0
On settle vault will fail because in margin calculator, in the get excessCollateral function, hasCollateral will be false, so it won't convert it into token amount.

Using WETH instead of ETH

In the current spec, there exist multiple checks that require having collateral address different than address zero.
We should decide wether to use WETH token or what specific address for ETH collateral.

Improve Oracle module

Currently the Oracle module store one price for each batch at a specific time, if we have multiple ETH-USDC put options with different strike prices, we will only need to push the underlying asset price once to settle them all.
In case we have ETH put options with different collateral(USDC and DAI) we will need to push the price twice at expiry time as the batch for those two options is different. Also as the Oracle store an asset price, I think it will be better to map price directly by asset rather than by batch.

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.