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

@optifi/optifi-sdk

v1.4.27

Published

TypeScript interfaces for working with the on-chain Optifi system

Downloads

339

Readme

OptiFi SDK

TypeScript interfaces for working with the on-chain OptiFi system

Configuration

Configuration variables can be specified either through environment variables, or provided to initializeContext at runtime

Optional Environment Variables:

  • OPTIFI_WALLET: the filepath of a Solana wallet
  • OPTIFI_PROGRAM_ID: The ID of the on chain OptiFi program to interact with. If you don't want to deploy the OptiFi program by yourself, try using the program id deployed on devnet: DeVoPfWrDn2UTA1MbSfagvpQxA91MpNFQnhHRw19dK34

How to initialize a new OptiFi Exchange

  • bootstrap a new exchange(do only once)
npx ts-node scripts/bootstrap.ts

it will create a new exchange with the OPTIFI_EXCHANGE_ID set in ./constants.ts, (if the exchange id is already bootstrapped, just try using another id), also create OptiFi markets that users can trade on. Each OptiFi market will list one tradable instrument and using a seperate Serum orderbook for placing orders.

  • load the exchange info npx ts-node scripts/loadExchange.ts

How to trade

  • create user account on the exchange
npx ts-node scripts/user/createUserAccountIfNotExists.ts
  • deposit fund (OptiFi USDC) to user's margin account (3000 usdc by default)
npx ts-node scripts/user/deposit.ts
  • find all available markets and select an OptiFi market to trade
npx ts-node scripts/findOptifiMarkets.ts

it will print all the market info, find the address of any OptiFi market.

Copy the OptiFi market address you want to trade and paste it to variable market in scripts/constants.ts. It will be imported and used in the scripts of later steps

  • init the user on the OptiFi market (only for first time)
npx ts-node scripts/user/initUserOnMarket.ts

It basically creates an open orders accounts for the Serum orderbook which is used the OptiFi market. Each user will have one open orders accounts for one OptiFi market.

  • check the current orderbook data
npx ts-node scripts/loadMarketOrderbook.ts
  • place ask/bid orders
npx ts-node scripts/order/placeOrder.ts
  • check the user's open account again after new order placed
npx ts-node scripts/loadOpenOdersAccount.ts
  • check the orderbook again after new order placed
npx ts-node scripts/loadMarketOrderbook.ts

How to run AMMs

  • create an AMM
npx ts-node scripts/amm/initializeAMMs.ts

It will create two AMMs, one for trading BTC options, another for trading ETH options

  • to get the info of created BTC/ETH AMMs, run:
npx ts-node scripts/amm/findAMMs.ts
  • change the variable ammIndx in scripts/amm/constants.ts, it will be imported and used in later steps. 1 is for BTC amm, 2 for ETH amm

  • to deposit USDC into an AMM, set the amm address and amount to deposit, and run:

npx ts-node scripts/amm/ammDeposit.ts
  • add the optifi markets to an AMM so that it can trade on that market
npx ts-node scripts/amm/addInstrumentToAmm.ts
  • make sure you have done the last two steps for BOTH BTC and ETH AMMs

  • now the amm is ready to work, run the following command to crank the AMM and let the AMM update orders on OptiFi markets contineously:

npx ts-node scripts/amm/crankAMM.ts

After the BTC or ETH AMM starts to run, orders should be placed on all BTC or ETH related OptiFi markets and updated contineously.

Debug

Error: failed to get info about account : FetchError: request to https://api.devnet.solana.com/ failed, reason: read ECONNRESET

Solution: It's because of the busy Solana network. just wait for a while and try again