Symmetry SDKs

Symmetry SDK is utilized in Symmetry UI (app.symmetry.fi), which is open-source. You can fork the repository and deploy it as your own asset management platform, or modify & add new features.

Baskets Sdk

Software Development Kit for interacting with Symmetry Baskets Program

To install the sdk, run:

npm install @symmetry-hq/baskets-sdk

Initialize SDK

import { BasketsSDK } from "@symmetry-hq/baskets-sdk";

let basketsSdk: BasketsSDK = await BasketsSDK.init(
    // rpc connection
    connection: Connection,
    // wallet (optional, can be provided later, using setWallet()
    wallet: Wallet,
);

// load list of supported tokens(returns TokenSettings array)
let tokens: TokenSettings[] = basketsSdk.getTokenListData();

// get tokenId(tokenId in symmetry supported tokens) from mint
let tokenId = basketsSdk.tokenIdFromMint(
  "So11111111111111111111111111111111111111112"
);

// set wallet
basketsSdk.setWallet(wallet: Wallet);

Create/Edit/Close Basket

Create Basket with specific settings and rules

Checkout Types and Full Example for more information on how settings should be provided.

Edit Basket (Only for Mutable & Permissioned baskets)

Close Basket (Basket TVL == 0 & no active BuyStates is required)

Create/Update Metadata for Baskets token mint:

Load Basket(s)

Load specific basket from public key

Load list of baskets based on filters (manager/host platform public key)

You can also load baskets' current compositions & parsed data such as basket name, symbol, current TVL - basketWorth, current price - rawPrice, etc...

Buy Basket Tokens

There are three ways to buy a basket token.

Option 1 (Simple):

Buy basket with a single token (token should be in the basket composition)

Option 2 (Simple): Contribute all tokens from baskets composition

Works for baskets with no more than 5 tokens Amounts for tokens should be provided in the same order tokens are present in baskets composition. Baskets composition can be found in Basket object of a basket, or using getCurrentCompositions()

Option 3 (Advanced):

Users also have option to contribute USDC to the basket. Symmetry Engine will use that USDC to buy underlying tokens (rebalance usdc to baskets current composition based on their target weights) After rebalancing, basket tokens will be minted for user.

Step 1: Contribute USDC to Basket and create BuyState (Temporary on-chain account) Initially BuyState will have the information about users contribution.

Step 2: Rebalance BuyState: Buy underlying assets in the basket using contributed USDC. During rebalancing process, BuyState will store the information about already purchased assets, as well as remaining amount of USDC.

Users can always force-rebalance their BuyState, but it is also done by Symmetry engine (BuyState will automatically rebalance within 3 minutes)

Step 3: Mint Basket Tokens & Close Buy State.

During this stage, all the assets acquired during rebalancing process will be added to the basket. Corresponding basket tokens will be minted for user, and circulating supply of the basket tokens will increase by same amount. After, it will safely close BuyState. Users can call force-mint function after 3 minutes, but Symmetry engine will also automatically handle this step. Rent for creating temporary account goes back to user.

Helpers:

Sell Basket

There are two ways to sell basket tokens.

Option 1 (Simple): Sell to a specific token (token should be in baskets composition)

Option 2 (Advanced):

Users can directly claim their portion of the tokens from Baskets composition. They also have an option to rebalance those tokens to USDC before claiming.

Step 1: Burn Basket Tokens and create SellState (Temporary on-chain account) SellState is an on-chain account which has exactly same structure as Basket. Initially SellState will store baskets composition with amounts corresponding to users holdings. Circulating supply will decrease by burn amount and users Basket tokens will be burned. From here, this SellState is already independent from the original Basket. User can specify if they want to rebalance their to-be-claimed tokens to USDC

Step 2: Rebalance SellState(Basket): Rebalance underlying assets to USDC This step is optional, user can skip this step and directly claim underlying tokens. SellState-s have exact structure as Baskets so rebalance function is same for them. (Optional, only when rebalance == true)

Step 3: Claim underlying tokens (or USDC) from SellState. After this step, SellState is closed and rent is collected by user.

Helpers:

Automation

Automation on all baskets (Refilter/Reweight/Rebalance), as well as monitoring active Buy/Sell states and rebalancing them is done by Symmetry Engine, based on RefilterInterval, ReweightInterval, RebalanceInterval settings provided in basket rules. Platforms and Developers can run their own automation for their baskets using examples below. Managers can Force-(Refilter/Reweight/Rebalance) anytime.

Refilter Basket

Automatically selects assets based on provided rules in basket settings.

Reweight Basket

Automatically updates target weights for assets based on provided rules.

Rebalance Basket

Swap basket tokens using DEX aggregators to bring all tokens back to target weights.

Other Helper Functions

Set priority fee:

Fetch User's Holdings:

Get Oracle Prices

Retrieve TransactionInstruction Objects that can be called on baskets.

Swap using Symmetry Baskets Liquidity

Users can swap and check available swap liquidity for a specific basket

Find out more at @symmetry-hq/liquidity-sdk

Full Example

Example shows how to create/buy/sell/rebalance/refilter/reweight a basket

Creating basket with following settings:

  • Manager fee : 0.1% - Users pay 0.1% to basket manager when buying

  • Is Mutable - Manager can edit basket settings and rules

  • Asset Pool consists of 4 tokens - [USDC, SOL, BTC, ETH]

  • Basket refilters underlying assets every week

  • Basket reweights underlying assets every day

  • Basket rebalances every 2 hours

  • Basket rebalances when target and current weights differ by at least 5%

  • Maximum allowed slippage on rebalance is 3% (compared to oracle price)

  • Basket provides swap liquidity for a token if current weight is within 5% (rebalance) 50%(lpOffset) = 2.5% of target weight

  • Basket has 1 rule:

  • Select TOP 3 assets by 1 week average MarketCap,

  • Weight chosen assets by square root of 1 day performance

  • Automation is on (Symmetry Engine will Refilter/Reweight/Rebalance based on rules)

  • Liquidity Provision is enabled.

Types

Having trouble integrating? Please reach out in our Discord, we're happy to help!

Last updated