LogoLogo
AppBlogGovSocials
  • What is Premia?
    • Premia Origins
      • History
      • Principles
      • Mission, Vision, & Values
  • Quick Start
  • The Premia Protocol
    • Options on Premia
      • Options Primer
      • Order-book vs. AMM
    • Key Protocol Features
      • Base Layer (Exchange)
      • Depot Layer (Vaults)
      • Messaging Layer (RFQ & OB)
      • Fee Schedule
      • Differentiators
    • Concepts
      • LP Range Orders
      • Trading
      • Orderbook & Request-for-Quote (RFQ)
      • Fees
      • Exercise & Settlement
      • Margin
      • Oracles
      • Liquidity Mining
      • Referral Programs
      • Advanced Exchange Concepts
        • Token Integration Requirements
        • Flash Swaps and Loans
      • Vault Depot
        • What is a Depot?
        • APY Calculation
        • Underwriter Depot
    • Governance
      • Premian Civitas
        • Parliament
        • Blue Descent
        • Premian Assembly
        • "Influence" Politics
      • Voting (vxPremia)
        • vxPremia Manifold
        • vxPremia Rewards
          • Options Liquidity Mining
          • Protocol Commissions
          • AirDrip Initiative
      • Operator & Facilitator Role
        • Operational Expenditure and Maintenance Costs
        • Insurance Fund
      • Meta Economics
  • Developer Center
    • APIs
      • Orderbook API
        • REST API
        • WEBSOCKET
      • Subgraph API
      • Containerized API
        • API Reference
          • Orderbook
            • Quotes
            • Orders
          • Pool
            • Settle
            • Exercise
            • Annihilate
          • Account
            • Collateral Approval
            • Orders
            • Collateral Balances
            • Native Balance
            • Option Balances
          • Pools
            • Find Pools
            • Create Pools
            • Valid Maturities
            • Valid Strikes
          • Oracles
            • IV
            • Spot
          • Vaults
            • Quote
            • Trade
        • WebSockets Reference
          • Authorization
          • Connection
          • Quotes Channel
          • RFQ Channel
    • SDK
      • Guides
      • SDK Technical Docs
    • Contracts
      • Multi-Signature Wallets
      • V3 Protocol
        • Overview
        • Guides
        • Smart Contract Technical Documentation
      • Margin
      • Orderbook
      • vxPremia
      • Universal Router
      • Vaults
    • Integrations
      • Use Cases
      • Code Snippets
    • Subgraph
    • V3 Change log
  • Bots
    • Range Order Bot
  • Resources
    • VIP & Institutional Services
    • Media Kit
    • Bug Bounty
    • Audits
    • Community Groups
    • Research
      • SSVI
    • Legal, Terms, & Disclaimers
      • Terms of Service
      • Privacy Policy
      • Cookie Policy
      • Prohibited Use
      • Affiliate & Advocate Program
      • Self-Service Affiliate Agreement
      • Bug Bounty Terms
      • Academy/Newsletter Disclaimer
      • Trading Competition Terms and Disclaimers
      • Blue Descent
      • Legal Disclaimer
      • Media Disclaimer
      • AML/KYC Policies
      • Intellectual Property
      • Amendments & Updates
      • Contact Us
      • FAQs (WIP)
    • 📰Newsletter
    • 🌊Crypto News Blotter
    • 🎓Academy
    • 🔵Premia Blue (V3)
    • 💎Premia V2 Docs
Powered by GitBook

Terms and Disclaimers

  • Privacy Policy
On this page
  • Quick Start
  • Walkthrough
  • API Reference

Was this helpful?

  1. Developer Center
  2. SDK

Guides

PreviousSDKNextSDK Technical Docs

Last updated 1 year ago

Was this helpful?

Quick Start

The full SDK is free to use and open-source, currently available in the following languages:

  • Typescript / Javascript

💡 The full SDK can be used trustlessly to execute any action or query any data from the protocol.

To get started just install the latest stable version of the package with,

yarn install "@premia/v3-sdk-public"

Then use the following code to get started with the minimal setup,

API_KEY = '<infura-api-key>'
PRIVATE_KEY = '<private-key>'

premia = await Premia.initialize({
    provider: `https://arbitrum-mainnet.infura.io/v3/${API_KEY}`,
    chainId: SupportedChainId.ARBITRUM,
    privateKey: PRIVATE_KEY
})

The Premia v3 SDK is meant to be an all-in-one solution, just instantiate the Premia object and you will have access to the following:

  • , query analytics information from the subgraph

  • , find access to the Contract types for each of Premia's main contracts.

  • , an aggregator for different sources of liquidity.

  • , provide and fill quotes through the orderbook (requires an API key).

  • , interact with all functionalities related to the option pools.

  • , compare prices of different quotes

  • , query information about tokens in relation to the pools from the subgraph

  • , query information about token pairs in relation to the pools from the subgraph

  • , query information about generic/vault transactions made on the protocol via the subgraph

  • , query user information via the subgraph

  • , interact with all functionalities related to the vaults.

  • , interact with all functionalities related to the vxPremia such as vault votes, user stakes, stake histories, and voting histories.

Walkthrough

Making Trades

First, we want to initialize the SDK with the proper configuration

API_KEY = '<infura-api-key>'
PREMIA_API_KEY = '<premia-api-key' // Needed for utilizing the orderbook
PRIVATE_KEY = '<private-key>'

premia = await Premia.initialize({
    provider: `https://arbitrum-mainnet.infura.io/v3/${API_KEY}`,
    chainId: SupportedChainId.ARBITRUM,
    privateKey: PRIVATE_KEY,
    apiKey: PREMIA_API_KEY
})

Then we need to query the subgraph to see what pools are deployed because this will dictate which listings we end up selecting to get a quote for.

const WETH = Addresses[SupportedChainId.ARBITRUM].WETH

const pools = await premia.pools.getPools(WETH)

Now that we have a list of available pools, we can filter and sort through them to find out in particular which pools are closest to the strike, maturity, and option type we are aiming for. For the sake of the example, however, we are just going to pick the first pool to demonstrate how to obtain a quote.

// Get token contract
const tokenAddress = pools[0].isCall ? pools[0].base.address : pools[0].quote.address
const token = await premia.contracts.getTokenContract(tokenAddress)

// Get quote
const poolAddress = pools[0].address
const quote = await premia.pools.quote(poolAddress, parseEther('1'), true)

Now that we have our quote and it seems like it fits our target price range, let's send the transaction and make the trade.

// Approve ERC20 token for the premium
await token.approve(quote.approvalTarget, quote.approvalAmount)

// Perform trade on the pool
const tx_response = await premia.pools.trade(poolAddress, {
    size: quote.size,
    isBuy: quote.isBuy,
    premiumLimit: quote.approvalAmount,
    referrer: ZeroAddress
})

There you have it, we've made our first trade on Premia!

API Reference

Detailed API documentation is available .

analytics
contracts
options
orders
pools
pricing
tokens
pairs
transactions
users
vaults
vxPremia
here