TypeScript SDK
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 walletOPTIFI_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)
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
Deposit fund (OptiFi USDC) to user's margin account (3000 usdc by default)
Find all available markets and select an OptiFi market to trade
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)
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
Place ask/bid orders
Check the user's open account again after new order placed
Check the orderbook again after new order placed
How to run OMM (AMM was rebranded to OMM in Nov 2022)
Create an AMM
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:
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 ammTo deposit USDC into an AMM, set the
amm address
andamount to deposit
, and run:
Add the optifi markets to an AMM so that it can trade on that market
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:
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
Last updated