npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

opyn-v1-connector

v0.0.1

Published

A utility for interacting with the opyn smart contracts

Downloads

9

Readme

opyn-v1-connector

opyn-v1-connector is a library for helping you interact with the opyn v1 smart contracts on the ethereum blockchain. This project is still in pre-release - it still needs a bit of a cleanup.

NOTE: This package doesnt work with metamask!!! For some reason metamask doesn't allow you to use BatchRequest functionality from web3. It works fine with your own node or an infura node (which is weird since metamask is using infura by default).

Usage:

Firstly install the dependency to your project

npm i opyn-v1-connector --save

Import the dependency where you need it:

const OpynConnectorV1 = require('opyn-v1-connector');

Instantiate the fetcher and pass in a web3 instance:

const web3 = new Web3(new Web3.providers.HttpProvider(`https://localhost:8545`));

const opynConnector = new OpynConnector({ web3 });

Fetching data:

Once you have your connector instantiated, you can initialise it using the init method. You can then access options contracts:

try {
    await opynConnector.init();
    console.log(opynConnector.optionsContracts);
} catch(err) {
    console.error("Error: " + err);
}

This will return a list of active options:

[
  {
    address: '0xde34d5e3f942b4543c309a0fb0461497e72c793c',
    name: 'Opyn aUSDC insurance',
    isExerciseWindow: true,
    totalSupply: '24604000000',
    decimals: '6',
    liquidationFactor: 0.5,
    optionsExchange: '0x39246c4f3f6592c974ebc44f80ba6dc69b817c71',
    underlying: '0x9ba00d6856a4edf4665bca2c2309936572473b7e',
    COMPOUND_ORACLE: '0x7054e08461e3ecb7718b63540addb3c3a1746415',
    liquidationIncentive: 0.01,
    owner: '0x87887cf0e37d937f989ab76b99e4f4682da044c4',
    isOwner: false,
    hasExpired: false,
    symbol: 'oaUSDC',
    transactionFee: 0,
    strike: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
    underlyingExp: '-6',
    collateralExp: '-18',
    oTokenExchangeRate: 0.000001,
    minCollateralizationRatio: 1.4000000000000001,
    strikePrice: 9.800000000000001e-7,
    collateral: '0x0000000000000000000000000000000000000000',
    expiry: '1625011200'
  },
  {
    address: '0xc6b11850241c5127eab73af4b6c68bc267cbbff4',
    name: 'Opyn WETH Put $360 12/25/20',
    isExerciseWindow: true,
    totalSupply: '5975312391',
    decimals: '7',
    liquidationFactor: 0,
    optionsExchange: '0x39246c4f3f6592c974ebc44f80ba6dc69b817c71',
    underlying: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
    COMPOUND_ORACLE: '0x7054e08461e3ecb7718b63540addb3c3a1746415',
    liquidationIncentive: 0,
    owner: '0x87887cf0e37d937f989ab76b99e4f4682da044c4',
    isOwner: false,
    hasExpired: false,
    symbol: 'oWETH $360 Put 12/25/20',
    transactionFee: 0,
    strike: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
    underlyingExp: '-18',
    collateralExp: '-6',
    oTokenExchangeRate: 1e-7,
    minCollateralizationRatio: 1,
    strikePrice: 0.000036,
    collateral: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
    expiry: '1608883200'
  },
  ....
]

You can fetch the cost of oTokens using premiumToPay();

  • @param: oTokenAddress
  • @param: paymentTokenAddress
  • @param: oTokensToBuy
try {
    console.log(await opynConnector.premiumToPay("0xfc19B36158D9a004D3550B7f29ec57eC5EF2dDC9", "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", 400000000));
} catch(err) {
    console.error("Error: " + err);
}

Alternatively, a convenience method is provided so you don't have to do the oToken translation for calls - getPriceOfPurchase()

  • @param: oTokenAddress
  • @param: isCall
  • @param: amountOptionsToBuy

This is the equivalent to the above example.

try {
    const eth400call = {
        address: '0xfc19b36158d9a004d3550b7f29ec57ec5ef2ddc9',
        name: 'Opyn ETH Call $400 11/27/20',
        isExerciseWindow: true,
        totalSupply: '58045200000',
        decimals: '6',
        liquidationFactor: 0,
        optionsExchange: '0x39246c4f3f6592c974ebc44f80ba6dc69b817c71',
        underlying: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
        COMPOUND_ORACLE: '0x7054e08461e3ecb7718b63540addb3c3a1746415',
        liquidationIncentive: 0,
        owner: '0x87887cf0e37d937f989ab76b99e4f4682da044c4',
        isOwner: false,
        hasExpired: false,
        symbol: 'oETH $400 Call 11/27/20',
        transactionFee: 0,
        strike: '0x0000000000000000000000000000000000000000',
        underlyingExp: '-6',
        collateralExp: '-18',
        oTokenExchangeRate: 0.000001,
        minCollateralizationRatio: 1,
        strikePrice: 2.5e-9,
        collateral: '0x0000000000000000000000000000000000000000',
        expiry: '1606464000'
    }

    console.log(await opynConnector.getPriceOfPurchase(myOption, true, 1));
} catch(err) {
    console.error("Error: " + err);
}

It also works for puts:

try {
    const eth400put = {
            address: '0x83cbbc045bd86ca1435e9d3e2f5fe29373d532ce',
            name: 'Opyn WETH Put $400 11/06/20',
            isExerciseWindow: true,
            totalSupply: '2288930617',
            decimals: '7',
            liquidationFactor: 0,
            optionsExchange: '0x39246c4f3f6592c974ebc44f80ba6dc69b817c71',
            underlying: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
            COMPOUND_ORACLE: '0x7054e08461e3ecb7718b63540addb3c3a1746415',
            liquidationIncentive: 0,
            owner: '0x87887cf0e37d937f989ab76b99e4f4682da044c4',
            isOwner: false,
            hasExpired: false,
            symbol: 'oWETH $400 Put 11/06/20',
            transactionFee: 0,
            strike: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
            underlyingExp: '-18',
            collateralExp: '-6',
            oTokenExchangeRate: 1e-7,
            minCollateralizationRatio: 1,
            strikePrice: 0.000039999999999999996,
            collateral: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
            expiry: '1604649600'
        };

    console.log(await opynConnector.getPriceOfPurchase(eth400put, false, 1));
} catch(err) {
    console.error("Error: " + err);
}

Examples

There's example code in the examples folder. To use this you can rename the .env.example file to .env and change your infura project id in the file. If using a local node, replace the provider in the example with the RPC url of your local node before running.

node examples/examples.js