Nomnom Pumpernickle Muffins

    @friktion-labs/friktion-sdk
    TypeScript icon, indicating that this package has built-in type declarations

    2.1.18 • Public • Published

    Friktion SDK

    Installation

    npm i @friktion-labs/friktion-sdk@1.1.127

    Architecture

    General

    The Friktion "volt" program is a solana program written using Anchor. Friktion's primary goal is to provide investment strategies and portfolio legos to prospective users. It accepts user deposits of SPL tokens, invests the tokens in a variety of auto-compounding strategies, and returns yield to the users upon withdrawal. Each volt offers a unique trading product and risk/reward payoff, but they are intended to all be usable within the same base UI. To facilitate this, the program consists of a set of generic "template" instructions that operate over any volt type and strategy. These include deposit/withdraw functionality, administrative controls, alternative strategies any volt can fallback on (such as lending on mango), or swapping assets. Additionally, each distinct "investment strategy" has a unique set of instructions - investment strategies are kept as generic as possible while still retaining a distinct identity in order to preserve variations and usage of the implementation within future volts (e.g. volt 1 & 2, volt 3 & 4 on Entropy)

    for instruction sets referred to above, see program/volt/ixs/* or read the docs.

    For more information on how Inertia, Soloptions, and other Supported Protocols factor into Friktion's infrastructure, check out the docs

    Volt #1 & #2

    Technical Docs Here

    State machine diagram for volt 1 & 2

    Volt #3 & #4

    Technical Docs Here

    Rebalancing & Cranking

    The volts must be cranked through their rebalancing process. Read more about how this is done here

    Environment Setup

    • Install Solana

    • Install Anchor. This should install a compatible rust version as well. It should be >= 1.61.0

    • Add the ssh key to your local GitHub configuration: instructions here

    • In order to enable ssh dependencies for cargo (rust) projects, add the following to ~/.cargo/config as well.

    [net]
    
    git-fetch-with-cli = true
    
    • Now, install typescript dependencies [^1] and build the solana programs in the programs/ directory [^2]
    npm install -g yarn
    
    yarn && cd volt-manager && yarn && cd ..
    
    anchor build --skip-lint

    Recommended IDE Setup: VSCode, install rust-analyzer, crates, prettier, beautify, gitlens, typescript importer, typescript hero

    Program Deployment Instructions

    The most important deliverables of the volt repo are the *.so binaries generated by anchor build or cargo build-bpf. Below is an example of deploying to devnet.

    First, check that the binaries exist. If they don't, run anchor build. The output should look something like this:

    ~/Friktion/volt ╱ main *1 !1 ?1  ls target/deploy 
    
    anchor_comp-keypair.json fee_utils-keypair.json oracle_utils-keypair.json soloptions-keypair.json volt-keypair.json
    
    anchor_comp.so fee_utils.so oracle_utils.so soloptions.so volt.so
    
    daoexamples-keypair.json inertia-keypair.json simple_swap-keypair.json spreads-keypair.json volt_abi-keypair.json
    
    daoexamples.so inertia.so simple_swap.so spreads.so volt_abi.so```

    Second, confirm your solana config is targeting mainnet. To see the current network, run solana config get. It should look something like

     ~/Friktion/volt ╱ main *2  solana config get
    Config File: /Users/alexwlezien/.config/solana/cli/config.yml
    RPC URL: https://api.devnet.solana.com
    WebSocket URL: wss://api.devnet.solana.com/ (computed)
    Keypair Path: /Users/alexwlezien/.config/solana/id.json
    Commitment: confirmed

    In any case, set your RPC URL to devnet now. To do this, run solana config set --URL devnet.

    Time to deploy! use the standard Solana CLI tool. If this is the first time deploying, you'll have to generate a program id keypair file and pass it as an argument

    solana program deploy target/deploy/volt.so --program-id ~/.secure-directory/volt-program-id.json --keypair ~/.config/solana/id.json

    Be patient now. It may take up to 30 minutes or so, but your program is currently deployed! To see more specific CLI docs and read about how the deployment process works under the hood click here.

    Usage Instructions

    Now that the program is deployed, you undoubtedly wish to interact with it. We do this via the SDK (friktion-sdk/) & volt manager (volt-manager) , which respectively provide a typescript interface to instructions exposed by the program and a CLI tool to specify instruction arguments and handle transaction sending logic. They are closely intertwined.

    A simple and commonly desired action is to view the details of the current state. This is possible via the printVoltDetails command in volt manager, as illustrated below in a (truncated) example.

    ~/Friktion/volt/volt-manager ╱ main *1 !1 ?1  ts-node volt.ts -i printVoltDetails --volt CMVV4kfSdJRufiTNrrhr6PsvYY8SFhNs3TVjsWS3rJvP
    
    
    
    -------------------------
    
    ID: CMVV4kfSdJRufiTNrrhr6PsvYY8SFhNs3TVjsWS3rJvP
    
    -------------------------
    
    Volt #01: Covered Call
    
    Short (Fri, 24 Jun 2022 02:00:00 GMT $133.33333333333333333 PUT)
    
    
    
    -------------------------
    
    HIGH-LEVEL STATS
    
    -------------------------
    
    Total Value (minus pending deposits) (SAMO): 14775278.49369057 , ($): 14775278.49369057
    
    deposit pool: 78.49369057
    
    premium pool: 0.000012 permissioned premium pool: 996.92707
    
    
    
    -------------------------
    
    EPOCH INFO
    
    -------------------------
    
    Round #: 3
    
    pending deposits SAMO: 224721.50630943 , ($): 224721.50630943
    
    pending withdrawals (SAMO): 5 , ($): 5
    
    
    
    -------------------------
    
    POSITION STATS
    
    -------------------------
    
    
    
    Short ( Fri, 24 Jun 2022 02:00:00 GMT $133.33333333333333333 PUT ):
    
    option key: Fpav5Y41VV2rbsugcxtZAyid2BF6gxkFsNFgpbDpZY97
    
    minted options: (#) 147752 (SAMO) 14775200
    
    serum market = CW7CwwgNwcdA5j6cX4XqxRYe9F7GYn2vRbHBjy1NdbHg
    
    option market: Fpav5Y41VV2rbsugcxtZAyid2BF6gxkFsNFgpbDpZY97

    For detailed usage, see:

    Testing

    There are a few different test suites.

    1. Typescript Integration tests. They are located inside the tests/integration directory and cover both Solana program functionality (programs/) and the Friktion SDK (friktion-sdk/). They are our best attempt at simulating real-world usage of the volts. Configuration is in Anchor.toml[^3]

    To run,

    yarn test:volt

    or for custom configuration,

    anchor test --skip-build ...
    1. Typescript unit tests. They are located inside the tests/unit directory and cover singular points of the functionality provided by the SDK. Typically, the logic being tested here is used by other dapps composing on Friktion (e.g. displaying rewards, getting user balances). Note that at least one of these tests currently depend on a private "volt testing" keypair, thus may not be possible for every developer to run.

    To run,

    yarn test:unit

    or for custom configuration,

    ANCHOR_WALLET=~/.config/solana/volt-testing.json yarn run ts-mocha -p ./tests/tsconfig.json -t 100000 tests/unit/**/*test*.ts
    1. Rust integration tests. They are inside the test/ directory of any subdirectory of programs/. The only current suite of rust integration testing is in programs/volt/test. While these tests don't capture the real-world use case as fully as the typescript integration tests (since these don't use the SDK), they run much faster and thus speed up the iterative development process. This is because they use a simulated client within rust rather than making inter-process and network calls to a local validator.

    To run,

    yarn test:volt

    or for custom configuration,

    cargo test-bpf or cargo test-bpf --manifest-path programs/volt/Cargo.toml

    1. Rust unit tests. They are located at multiple points in the rust portion of this repository, notably in rust-packages/fee-utils/lib.rs and programs/volt/src/helpers.rs

    These are run using the same commands as the rust integration tests.

    However, if you wish to run unit tests in isolation, specify the names in the command. For example,

    cargo test-bpf --manifest-path programs/volt/Cargo.toml --test calculates_zero_fees

    Development Resources

    Test Volts:

    • SOL Call volt (#1): 51q765gctu6VDSeiwKyvnzfMzmZita8uJjb5SNngpP2J

    • SOL Put volt (#2): 2LCnDj16YxVDpFGNEJWcQM6YKvbzCyzvkZQNpKN94ycL

    Glossary

    For Solana-specific definitions (e.g account, transaction, instruction), click (here)[https://docs.solana.com/terminology]. Anchor-specific terminology (here)[https://book.anchor-lang.com/anchor_references/anchor_references.html]

    Volt

    : A Friktion neologism for "vault" - a single entity that accepts user deposits and invests them in yield-earning products.

    DOV

    : short for "Defi Options Vaults," a common term describing protocols offering automated options selling strategies. Friktion offers these products via Volt #1 & #2.

    Entropy:

    : Exotic perpetuals exchange operated by the Friktion team to support volt #3

    Mango:

    : Spot & perpetuals order book exchange on Solana

    Volt #1:

    : Automated covered call strategy, the first volt Friktion launched. Profits relative to holding underlying during low volatility, moderately bearish scenarios.

    Volt #2:

    : Automated protected put strategy, the second volt Friktion launched. Profits relative to holding underlying during low volatility, moderately bullish scenarios.

    Volt #3:

    : Automated "crab" strategy using power perpetuals on entropy, the third volt Friktion launched. Profits in any relatively low volatility regime. As compared to volt 1 & 2, has the advantage of continuous liquidity and no directional bias.

    Volt #4:

    : Automated basis strategy on Mango Markets. The difference between the funding rate on linear perpetual and the interest rate on borrowing the corresponding spot asset profits.

    Volt #5:

    : Protected moonshot, soon...

    Volt #6:

    : 6th volt in Friktion portfolio. Writes undercollateralized loans to reputable, KYCed parties in return for a risk premium relative to collateralized lending.

    Collateral:

    : assets an entity controls. For example, the "volt's collateral" refers to all assets the volt controls, typically deposits from users' wallets.

    Rebalancing:

    : The process of accepting new deposits, processing further withdrawals and entering/exiting an investment position depending on net inflows/outflows.

    Rebalancing Period

    : The period between each rebalancing of a volt.

    Epoch (Round):

    : a single rebalancing period. Single-word synonym for time users must wait for a deposit/withdrawal between each opportunity. Also demarcates when fees are taken by the volt.

    Share Token

    : SPL token that represents one share of the volt's total collateral. The $ value of a single share token can be calculated in the following way. `$ = 1 / (share token supply) *

    Volt Token

    : synonym for Share Token

    Pending Deposit

    : A user sends some deposit tokens (e.g., SOL, BTC, USDC) to the volt to receive newly minted share tokens once the current epoch ends.

    Pending Withdrawal

    : A user burns some share tokens to have a claim on their share of the volt's collateral once the current epoch ends.

    User Facing Instruction

    : a Friktion volt program instruction that can be called permissionlessly from the app.friktion.fi or any other Solana cluster client.

    Claim Pending Deposit

    : A user-facing instruction to claim share tokens after the epoch attached to a pending deposit ended.

    Claim Pending Withdrawal

    : A user-facing instruction to claim deposit tokens after the epoch attached to a pending withdrawal ended.

    License

    The code in this repository is original. Some parts may have been derived from other codebases, but they have only been derived from permissively open-sourced software:

    Code in this repository only contains code derived from permissively licensed open source software (such as those licensed under MIT or Apache-2.0).

    Note

    • Friktion is in active development, so all APIs are subject to change.

    • Parts of this code may be unaudited, depending on when the last official audit was conducted

    Footnotes

    1. If you plan on using common typescript-related CLI tools, you may want to have your global versions match those specified in package.json (unless you wish to use yarn run ts-node). Specifically, consider installing matching versions for node, typescript, ts-node, mocha, and ts-mocha.

    2. cargo build-bpf may be substituted for anchor build in the code block above

    3. Under the hood, yarn test: volt calls anchor test, which spins up a Solana test validator using Solana-test-validator (packaged with Solana installation). It then deploys the programs included in Anchor.toml.

    Keywords

    none

    Install

    npm i @friktion-labs/friktion-sdk

    DownloadsWeekly Downloads

    2,337

    Version

    2.1.18

    License

    proprietary

    Unpacked Size

    3.66 MB

    Total Files

    218

    Last publish

    Collaborators

    • friktion-labs