CPI examples for deposits/withdrawals with Friktion Volts

Related tags

Utilities lightning
Overview

Lightning

Overview

CPI Examples for interacting with Friktion's volt program

Devnet Faucets

Can be found here: https://app.friktion.fi/faucet

Docs

Full docs can be found at https://docs.friktion.fi/integration/rust-abi

Examples

The following is an example of a CPI call into the Friktion program calling the deposit instruction. Anchor provides docs on the syntax used.

use anchor_lang::declare_id;
use anchor_lang::prelude::*;
mod contexts;
pub use crate::contexts::*;

declare_id!("DAo2pDtpiBFDu4TTiv2WggP6PfQ6FnKqwSRYxpMjyuV2");

fn get_authority() -> (Pubkey, u8) {
    return Pubkey::find_program_address(&[b"daoProgramAuthority" as &[u8]], &crate::id());
}

#[program]
pub mod cpi_examples {

    use super::*;
    pub fn deposit_example<'a, 'b, 'c, 'info>(
        ctx: Context<'a, 'b, 'c, 'info, DepositExample<'info>>,
        deposit_amount: u64,
    ) -> Result<()> {
        let (_, bump) = get_authority();
        let base_seeds = &[b"daoProgramAuthority" as &[u8], &[bump]];
        let seeds = [&base_seeds[..]];
        let cpi_ctx = CpiContext::new_with_signer(
            ctx.accounts.volt_program_id.clone(),
            volt_abi::cpi::accounts::Deposit {
                authority: ctx.accounts.authority.to_account_info(),
                dao_authority: ctx.accounts.dao_authority.to_account_info(),
                authority_check: ctx.accounts.dao_authority.to_account_info(),
                vault_mint: ctx.accounts.vault_mint.to_account_info(),
                volt_vault: ctx.accounts.volt_vault.to_account_info(),
                vault_authority: ctx.accounts.vault_authority.to_account_info(),
                extra_volt_data: ctx.accounts.extra_volt_data.to_account_info(),
                whitelist: ctx.accounts.whitelist.to_account_info(),
                deposit_pool: ctx.accounts.deposit_pool.to_account_info(),
                writer_token_pool: ctx.accounts.writer_token_pool.to_account_info(),
                vault_token_destination: ctx.accounts.vault_token_destination.to_account_info(),
                underlying_token_source: ctx.accounts.underlying_token_source.to_account_info(),
                round_info: ctx.accounts.round_info.to_account_info(),
                round_volt_tokens: ctx.accounts.round_volt_tokens.to_account_info(),
                round_underlying_tokens: ctx.accounts.round_underlying_tokens.to_account_info(),
                pending_deposit_info: ctx.accounts.pending_deposit_info.to_account_info(),
                entropy_program: ctx.accounts.entropy_program.to_account_info(),
                entropy_group: ctx.accounts.entropy_group.to_account_info(),
                entropy_cache: ctx.accounts.entropy_cache.to_account_info(),
                entropy_account: ctx.accounts.entropy_account.to_account_info(),
                epoch_info: ctx.accounts.epoch_info.to_account_info(),
                system_program: ctx.accounts.system_program.to_account_info(),
                token_program: ctx.accounts.token_program.to_account_info(),
            },
            &seeds,
        );

        volt_abi::cpi::deposit(cpi_ctx, deposit_amount).unwrap();
        Ok(())
    }
}

using the following context:

#[derive(Accounts)]
#[instruction(
    deposit_amount: u64,
)]
pub struct DepositExample<'info> {
    #[account(mut, signer)]
    /// CHECK: skip, checked by the volt program
    pub authority: AccountInfo<'info>,

    /// CHECK: skip, checked by the volt program
    pub dao_authority: AccountInfo<'info>,

    #[account(address=volt_abi::id())]
    /// CHECK: skip, checked by the volt program, will check program id in instruction
    pub volt_program_id: AccountInfo<'info>,

    #[account(mut)]
    /// CHECK: skip, checked by the volt program
    pub vault_mint: AccountInfo<'info>,

    #[account(mut)]
    /// CHECK: skip, checked by the volt program
    pub volt_vault: AccountInfo<'info>,
    /// CHECK: skip, checked by the volt program
    pub vault_authority: AccountInfo<'info>,

    #[account()]
    /// CHECK: skip, checked by the volt program
    pub extra_volt_data: AccountInfo<'info>,

    /// CHECK: skip, checked by the volt program
    pub whitelist: AccountInfo<'info>,

    #[account(mut)]
    /// CHECK: skip, checked by the volt program
    pub deposit_pool: AccountInfo<'info>,

    /// CHECK: skip, checked by the volt program
    pub writer_token_pool: AccountInfo<'info>,

    #[account(mut, token::authority=dao_authority.key())]
    // user controlled token account w/ mint == vault mint
    /// CHECK: skip, checked by the volt program
    pub vault_token_destination: Box<Account<'info, TokenAccount>>,

    #[account(mut, token::authority=dao_authority.key())]
    // user controlled token account w/ mint == underlying mint
    /// CHECK: skip, checked by the volt program
    pub underlying_token_source: Box<Account<'info, TokenAccount>>,

    #[account(mut)]
    /// CHECK: skip, checked by the volt program
    pub round_info: AccountInfo<'info>,

    #[account(mut)]
    /// CHECK: skip, checked by the volt program
    pub round_volt_tokens: AccountInfo<'info>,

    #[account(mut)]
    /// CHECK: skip, checked by the volt program
    pub round_underlying_tokens: AccountInfo<'info>,

    #[account(mut)]
    /// CHECK: skip, checked by the volt program
    pub epoch_info: AccountInfo<'info>,
    /// CHECK: skip, checked by the volt program
    #[account(mut)]
    pub pending_deposit_info: AccountInfo<'info>,

    /// CHECK: skip, checked by the volt program
    pub entropy_program: AccountInfo<'info>,
    /// CHECK: skip, checked by the volt program
    pub entropy_group: AccountInfo<'info>,

    /// CHECK: skip, checked by the volt program
    pub entropy_account: AccountInfo<'info>,

    /// CHECK: skip, checked by the volt program
    pub entropy_cache: AccountInfo<'info>,

    /// CHECK: skip, checked by the volt program
    pub system_program: AccountInfo<'info>,
    /// CHECK: skip, checked by the volt program
    pub token_program: AccountInfo<'info>,
}

Keep in mind, the CPI feature must be enabled on "volt-abi" as the following demonstrates:

volt-abi = { version = "0.2.0", features = ["cpi"]}
You might also like...
Examples of interacting with a Polkadot node using Rust

Examples of interacting with a Polkadot node Some examples of using JSON RPC to interact with a Polkadot node, working up to manually building and sub

Game examples implemented in rust console applications primarily for educational purposes.

rust-console-games A collection of game examples implemented as rust console applications primarily for providing education and inspiration. :) Game *

Examples on how to write Windows kernel drivers in Rust

windows-kernel-rs Note: this is still work in progress! This is a Windows kernel framework in Rust that consists of windows-kernel-sys, a crate that p

Examples and helpers to build NFT contracts on CosmWasm

CosmWasm NFTS This repo is the official repository to work on all NFT standard and examples in the CosmWasm ecosystem. cw721 and cw721-base were moved

Code examples for https://www.poor.dev/blog/terminal-anatomy/

This repository contains examples from the Anatomy of a Terminal Emulator blog post. Each folder contains a separate example and can be run separately

Examples of Solana on-chain programs

spl-examples List of Solana on-chain programs which demonstrate different aspects of Solana architecture. 01__state It's a counter program. Each user

 PyO3 examples
PyO3 examples

PyO3 examples This repo accompanies this blog post. The Rust examples, found here, include: calculate the n-th Fibonacci in Python as well as in Rust

zine/book about bitmap drawing algorithms and math with code examples in Rust
zine/book about bitmap drawing algorithms and math with code examples in Rust

A Bitmapper's Companion - zine/book about bitmap drawing algorithms and math with code examples in Rust A small zine/book written in LaTeX. In progres

Simple examples to demonstrate full-stack Rust audio plugin dev with baseplug and iced_audio
Simple examples to demonstrate full-stack Rust audio plugin dev with baseplug and iced_audio

iced baseplug examples Simple examples to demonstrate full-stack Rust audio plugin dev with baseplug and iced_audio WIP (The GUI knobs do nothing curr

Examples to demonstrate how to use PipeCD

examples A repository contains some examples for PipeCD. NOTE: This repository is automatically synced from the examples directory of pipe-cd/pipe rep

Examples for Deno Deploy

Deno Deploy Examples This repository contains a list of examples for Deno Deploy. fetch - Make outbound requests using the fetch() API. json_html - Re

Community showcase and examples of Actix ecosystem usage.

Actix Examples Curated examples using the Actix ecosystem. Community Showcase Merino: Web service for Firefox Suggest lemmy: A federated alternative t

Examples of cw20 usage, extracted from cw-plus, maintained by the community

CosmWasm Tokens This is a collection of cw20-related contracts extracted from cw-plus. These serve as examples of what is possible to build and as sta

Examples from the talk Why you should learn Rust

Why you should learn Rust: Examples This repository contains the examples from the talk "Why you should learn Rust". All examples demonstrate that the

A pretty, sensible logger for Rust - ideal for running examples and tests on a crate of choice
A pretty, sensible logger for Rust - ideal for running examples and tests on a crate of choice

sensible-env-logger A pretty, sensible logger for Rust - ideal for running examples and tests on a crate of choice. This is a thin wrapper around pret

A simple, modern fuzzy finder tool to run examples in a Cargo project.

cargo-rx cargo-rx is a simple, modern Runner for Examples in a Cargo project. This crate provides a single executable: rx. Basically anywhere you woul

A collection (eventually) of examples that use some non-beginner things.

nannou examples A collection (eventually) of examples that use some non-beginner things. Right now the only example combines nannou's standard draw AP

tulipv2 vaults and v1 lending program sdk & examples

tulipv2-sdk Warning Unaudited, possibly untested sdk Tulip Protocol takes no responsibility for any (financial, physical, emotional, etc..) damage tha

Cargo subcommand to easily run targets/examples

cargo-select Cargo subcommand to easily run targets/examples/tests Fuzzy match against targets, examples or tests in current rust project. cargo-selec

Owner
Friktion Labs
Friktion Labs
Examples of how to use Rust with Serverless Framework, Lambda, API Gateway v1 and v2, SQS, GraphQL, etc

Rust Serverless Examples All examples live in their own directories: project: there is nothing here, just a simple cargo new project_name with a custo

Fernando Daciuk 9 Dec 17, 2022
Code examples, data structures, and links from my book, Rust Atomics and Locks.

This repository contains the code examples, data structures, and links from Rust Atomics and Locks. The examples from chapters 1, 2, 3, and 8 can be f

Mara Bos 338 Jan 6, 2023
Rust examples for stm32-cam

esp32cam-rs Rust esp32-cam examples Usage populate the required .txt files, then run the examples ./examples/telegram_bot/bot_token.txt ./examples/tel

Kezi 4 Feb 17, 2024
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
rust mappings for Friktion's volt program

Friktion (volt) ABI Overview Provides contexts and instruction functions to interact with Friktion Program via CPI calls Friktion program ID: VoLT1mJz

Friktion Labs 3 Jul 22, 2022
Winsafe-examples - Examples of native Windows applications written in Rust with WinSafe.

WinSafe examples This repo contains several examples of native Win32 applications written in Rust with WinSafe. All examples follow the same program s

Rodrigo 40 Dec 14, 2022
An anchor CPI client for the SPL token lending program

anchor-lending anchor-lending is an anchor CPI client for any program that implements or extends the instruction interface found in the spl token lend

Rohan Kapur 11 Oct 24, 2022
Making composability with the Zeta DEX a breeze, FuZe provides CPI interfaces and sample implementations for on-chain program integration.

Zeta FuZe ?? Zeta FuZe FuZe is Zeta's cross-program integration ecosystem. This repository contains the Zeta Cross Program Invocation (CPI) interface

Zeta 39 Aug 27, 2022
Generates an Anchor CPI crate from a JSON IDL.

anchor-gen Generates a crate for cross-program invocations to an Anchor program from a JSON IDL. Usage In a new crate, write: anchor_gen::generate_cpi

Saber 44 Jul 3, 2023
Rust library for program synthesis of string transformations from input-output examples 🔮

Synox implements program synthesis of string transformations from input-output examples. Perhaps the most well-known use of string program synthesis in end-user programs is the Flash Fill feature in Excel. These string transformations are learned from input-output examples.

Anish Athalye 21 Apr 27, 2022