import {// sdk WITHOUT a user wallet attached VoltSDK,// sdk WITH a user wallet attached toConnectedSDK, FriktionSDK,} from"@friktion-labs/friktion-sdk";// SOL Covered Call Volt pubkeyconstvoltVaultId=newPublicKey("CbPemKEEe7Y7YgBmYtFaZiECrVTP5sGrYzrrrviSewKY");constfriktionSDK:FriktionSDK=newFriktionSDK({ provider: provider,// e.g AnchorProvider network:CLUSTER,// e.g mainnet-beta});// loads a volt SDK based on the VoltVault account pubkey// friktionSDK.loadShortOptionsVoltSDKByKey to load a ShortOptionsVoltSDK// friktionSDK.loadEntropyVoltSDKByKey to load an EntropyVoltSDKconstvoltSdk=awaitfriktionSDK.loadVoltAndExtraDataByKey(voltVaultId),// friktionSdk.loadVolt(...) is a lightweight version of sdk with reduced functionality// creates a ConnectedSDK instance// toConnectedEntropySDK for getting a ConnectedEntropyVoltSDK (const cVoltSdk =toConnectedVoltSDK( voltSdk, connection,// solana cluster connection user,// generally, provider.wallet pubkeyundefined,// only used if depositing from a PDA or other program-owned account);
3. Use this reference package.json for example dependencies:
In the below examples, SOL is used as a default placeholder for the deposit token of a volt. The deposit token can be easily found by calling voltSdk.depositMint()
The SDK provides a method for each instruction, returning a TransactionInstruction object later to be included in a transaction.
//// DEPOSIT EXAMPLE ////// depositing 0.00001 SOLconstdepositAmount:Decimal=newDecimal(0.00001);awaitcVoltSdk.doFullDeposit(depositAmount);
Withdraw
See a Full Withdraw Example for implementation details. Keep in mind that it is impossible to 100% accurately know the value of a volt before the epoch ends, and thus any withdrawal done mid-epoch is based on a (fairly accurate) estimate.
//// WITHDRAW EXAMPLE ////// withdrawing 0.00001 SOLconstwithdrawAmount:Decimal=newDecimal(0.00001);awaitcVoltSdk.doFullWithdraw(withdrawAmount); // creates and send transactions
// NOTE: in below definitions, 'SOL' would be replaced by the deposit token for that volt.const {totalBalance,// total # SOL user has in Friktion (e.g 0.001 SOL)normalBalance,// SOL value of volt tokens in user's walletpendingDeposits,// SOL value of users's unclaimed and pending depositspendingWithdrawals,// SOL value of user's unclaimed and pending withdrawalsmintableShares,// # of volt tokens user could mint immediatelyclaimableUnderlying,// SOL value of user's *mintableShares*normFactor,// 10^(number of decimals in SOL mint) = 10^9 for SOL, varies depending on deposit tokenvaultNormFactor,// generally equivalent to normFactor, but may differ if deposit token was migrated (e.g sollet deprecation)} =awaitvoltSdk.getBalancesForUser(user // wallet pubkey or PDA);
This retrieves the pnl denominated in the deposit token of the volt. This can be accessed via voltSdk.voltVault.depositMint. This feature is only supported after a certain epoch on each volt. For full historicals or user-specific PnL (like this), please ask in the #developers channel in discord
// denominated in deposit token.// e.g if the volt made $1000 in premium, SOL is worth $100, constepochPnl=awaitvoltSdk.getPnlForEpoch(roundNumber)// for SOL Call round 25, outputs 325.872 SOL.
Calculate TVL
This gets the TVL (total value locked) of a volt (all collateral under control of the volt's on-chain authorities).
consttvl=awaitvoltSdk.getTvlInDepositToken()
To convert to USD-demoninated TVL, simply multiply by the deposit token price (scraped from coingecko). Or, call the built-in function.
constusdTvl=awaitvoltSdk.getTvl();// or:// const usdTvl = tvl.mul(await voltSdk.depositTokenPrice());VoltSDK vs. ConnectedVoltSDK
For more detailed statistics about TVL, call getTvlStats()
const {tvlusdTvlstrategyDeposits,pendingDeposits,pendingWithdrawals,// SOL } =awaitvoltSdk.getTvlStats();
Print Volt Details
To see the loaded volt's type, strategy, and name.
It's often useful to print more details of volt in order to visually interpret the current state (e.g stage of rebalancing, total TVL,
awaitvoltSdk.printState();
Truncated output below. To see full output check out the example
-------------------------
ID: CbPemKEEe7Y7YgBmYtFaZiECrVTP5sGrYzrrrviSewKY
-------------------------
Volt #01: Covered Call
volt 1 or 2
returning...
Short (Fri, 01 Jul 2022 02:00:00 GMT $0.019230769230769230769 PUT)
-------------------------
HIGH LEVEL STATS
-------------------------
Total Value (minus pending deposits) (SOL): 159155.947477497 , ($): 6124320.85893408456
deposit pool: 0.947477497
premium pool: 0.535425 permissioned premium pool: 35795.55105
...
...
Epoch-specific Information
Each Volt epoch contains valuable information about deposits/withdrawals, fees collected, PnL, and the rebalancing process.
constcurrentRound=awaitvoltSdk.getRoundByNumber(voltSdk.voltVault.roundNumber) // Round accountconstcurrentRound2=awaitvoltSdk.getCurrentRound() // equivalent to currentRoundconstcurrentEpochInfo=awaitvoltSdk.getEpochInfoByNumber(voltSdk.voltVault.roundNumber) // FriktionEpochInfo accountconstcurrentEpochInfo2=awaitvoltSdk.getCurrentEpochInfo() // equivalent to currentEpochInfo
To understand the fields on these account better, read the Global Accounts section
Estimate Fees
Performance fees can be easily calculated given an expected reward (denominated in deposit token).
consttotalReward=100*voltSdk.getDepositTokenNormalizationFactor() // 100 SOL in lamportsconstperformanceFee=voltSdk.performanceFeeAmount(totalReward) // 1000 bps = 10% * 100 SOL = 10 SOL = 10000000000 lamports
while withdrawal fees require an estimation of the underlying received.
constexpectedWithdrawnUnderlying=100*voltSdk.getDepositTokenNormalizationFactor() // 100 SOL in lamportsconstwithdrawalFee=voltSdk.withdrawalFeeAmount(expectedWithdrawnUnderlying) // 10 bps = 0.1% * 100 SOL = 0.1 SOL = 100000000 lamports
Alternative Strategy Tracking
If there are operational difficulties with public volts, or if a Circuits volt requests to pause the current strategy, all Friktion volts can utilize a simple, low risk lending aggregator.
Entropy describes the set of exchanges + lending platforms that are based off the original Mango Markets codebase. To view the lower-level objects used to calculate volt TVL in this set of lending platforms, see below.
const { entropyGroup,entropyAccount,entropyCache} =awaitthis.getEntropyLendingObjects(); // may fail if lending has not been initialized
Load All Volts on Friktion UI
let friktionSdk =newFriktionSDK({ provider:newAnchorProvider(newConnection("https://api.mainnet-beta.solana.com"),Wallet.local(), {} ),// with mainnet RPC network:'mainnet-beta',});constallMainnetVolts:VoltSDK[] =awaitfriktionSdk.getAllVoltsInSnapshot();friktionSdk =newFriktionSDK({ provider:newAnchorProvider(newConnection("https://api.devnet.solana.com"),Wallet.local(), {} ),// with devnet RPC network:'devnet',});constallDevnetVolts:VoltSDK[] =awaitfriktionSdk.getAllVoltsInSnapshot();
VoltSDK vs. ShortOptions/Entropy-VoltSDK vs. ConnectedVoltSDK
VoltSDK is a generic wrapper around a single Friktion volt. Useful for retrieving accounts (e.g VoltVault, ExtraVoltData) and calculating statistics. It is implemented as an abstract class. Each specific volt type extends VoltSDK to form their own SDK. ShortOptionsVoltSDK provides helper methods for interacting with volt 1 & 2, while EntropyVoltSDK does the same for volt 3 & 4.
ConnectedVoltSDK is an extension of VoltSDK tied to a specific user, and provides an API for creating any Friktion volt instruction using the provided wallet as an authority. It's also an abstract class, so requires a specific implementation given by ConnectedShortOptionsVoltSDK or ConnectedEntropyVoltSDK. Examples below:
// load ShortOptionsVoltSDK extends VoltSDKconstsolPutLowKey=newPublicKey("2evPXRLaTZj92DM93sdryeszwqoC9C6DoWa1TKHn1AzU");constsolPutLowShortOptionsSdk=awaitfriktionSDK.loadShortOptionsVoltSDKByKey(solPutLowKey);// convert to ConnectedShortOptionsVoltSDK extends (ConnectedVoltSDK & ShortOptionsVoltSDK)// this inherits all methods from both parent classesconstsolPutLowConnectedSDK:ConnectedSDK=toConnectedSDK( solPutLowShortOptionsSdk,provider.connection,provider.wallet);// use short options specific helper to get the specific class typeconstsolPutLowConnectedSDK:ConnectedShortOptionsVoltSDK=toConnectedShortOptionsSDK( solPutLowShortOptionsSdk,provider.connection,provider.wallet);constsolBasisKey=newPublicKey("2yPs4YTdMzuKmYeubfNqH2xxgdEkXMxVcFWnAFbsojS2");constsolBasisEntropySdk=awaitfriktionSDK.loadEntropyVoltSDKByKey(solBasisKey);// mirror methods toConnectedSDK and toConnectedEntropySDK