npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mirrorworld/library.bankdecentralized.new

v1.0.0-alpha.4

Published

bank decentralized SDK

Downloads

68

Readme

This SDK contains the client side methods for the Bank Decentralized Solana Program

Installation

🚨 Please make sure to add this NPM token in your .npmrc file: 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

yarn add @mirrorworld/library.bankdecentralized

Usage

Import the BankDecentralizedLib instance into your client. It expects a connection and wallet instance. You can get these by using one of the Solana Wallet Adapters your application will use to connect to a Solana RPC.

These transactions require you to sign the transaction using your wallet. That means you need to have SOL. You can request SOL from the SolFaucet

import {
    BankDecentralizedLib,
    BANK_DECENTRALIZED_PROGRAM_ID
} from '@mirrorworld/library.bankdecentralized';

const connection = useConnection()

/** Make sure your wallet is initialized and connected to the browser before providing to GameWalletLib */
const wallet = useWallet()

/** GameWalletLib instance */
const bankDecentralizedLib = new BankDecentralizedLib(
    BANK_DECENTRALIZED_PROGRAM_ID,
    connection,
    wallet
);

Demo

Example: You can see example project in this repo here:

Initialize Main Config

Main Config Account pda is the top level config for the program.

let tx = await bankDecentralizedLib.createInitializeMainConfigTransaction(mainSigningAuthorityWalletKeypair.publicKey, feePayerWalletKeypair.publicKey,
    SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, mainSigningAuthorityWalletSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Create Bank Config

This transaction create bank config account pda from the bank name seed.

let tx = await bankDecentralizedLib.createBankConfigTransaction(bankName, bankSigningAuthorityWalletKeypair.publicKey,
    feePayerWalletKeypair.publicKey, SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, bankSigningAuthorityWalletSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Create Sol Config

Create Sol Config transaction make the sol payment config for the bank.

const isSigningAuthorityRequired = false;
const isMaxWithdrawEnable = false;
const isMinWithdrawEnable = false;
const maxWithdraw = 0.1 * LAMPORTS_PER_SOL;
const minWithdraw = 0.3 * LAMPORTS_PER_SOL;

let tx = await bankDecentralizedLib.createSolConfigTransaction(bankName, isSigningAuthorityRequired, isMaxWithdrawEnable, isMinWithdrawEnable,
    maxWithdraw, minWithdraw, incomeAccount, solSigningAuthorityWalletKeypair.publicKey, bankSigningAuthorityWalletKeypair.publicKey,
    feePayerWalletKeypair.publicKey, SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, bankSigningAuthorityWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, solSigningAuthorityWalletSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Update Sol Config

Update Sol Config transaction update the sol payment config for the bank, but sol signing authority can call this transaction.

const isSigningAuthorityRequired = false;
const isMaxWithdrawEnable = false;
const isMinWithdrawEnable = false;
const maxWithdraw = 0.1 * LAMPORTS_PER_SOL;
const minWithdraw = 0.3 * LAMPORTS_PER_SOL;

let tx = await bankDecentralizedLib.createUpdateSolConfigTransaction(bankName, isSigningAuthorityRequired, isMaxWithdrawEnable, isMinWithdrawEnable,
    maxWithdraw, minWithdraw, incomeAccount, solSigningAuthorityWalletKeypair.publicKey, feePayerWalletKeypair.publicKey,
    SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, solSigningAuthorityWalletSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Add Sol Distribution Supply

This transaction add the sol in the distribution supply

let tx = await bankDecentralizedLib.createAddSolDistributionSupplyTransaction(bankName, amount, solSigningAuthorityWalletKeypair.publicKey, solSigningAuthorityWalletKeypair.publicKey,
    feePayerWalletKeypair.publicKey, SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, solSigningAuthorityWalletSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Deposit Sol

This transaction create user sol config pda if it is not created and add the sol in the deposit pool

let tx = await bankDecentralizedLib.createDepositSolTransaction(bankName, amount, userKeypair.publicKey, userKeypair.publicKey,
    feePayerWalletKeypair.publicKey, SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, userSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Deposit Sol With Authority

This transaction create user sol config pda if it is not created and add the sol in the deposit pool, for this transaction sol signing authority is needed.

let tx = await bankDecentralizedLib.createDepositSolWithAuthorityTransaction(bankName, amount, userKeypair.publicKey, solSigningAuthorityWalletKeypair.publicKey,
    userKeypair.publicKey, feePayerWalletKeypair.publicKey, SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, userSecretKey);
bankDecentralizedLib.signTransaction(tx, solSigningAuthorityWalletSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Withdraw Sol

This transaction withdraw the sol from the deposit pool for the user

let tx = await bankDecentralizedLib.createWithdrawSolTransaction(bankName, amount, userKeypair.publicKey,
    userKeypair.publicKey, feePayerWalletKeypair.publicKey, SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, userSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Withdraw Sol With Authority

This transaction withdraw the sol from the deposit pool for the user and for this transaction sol signing authority is needed

let tx = await bankDecentralizedLib.createWithdrawSolWithAuthorityTransaction(bankName, amount, userKeypair.publicKey, solSigningAuthorityWalletKeypair.publicKey,
    userKeypair.publicKey, feePayerWalletKeypair.publicKey, SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, userSecretKey);
bankDecentralizedLib.signTransaction(tx, solSigningAuthorityWalletSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Spend Sol

This Transaction Spend the sol from user deposit pool and add the in the income account

let tx = await bankDecentralizedLib.createSpendSolTransaction(bankName, amount, incomeAccount, solSigningAuthorityWalletKeypair.publicKey,
    userKeypair.publicKey, feePayerWalletKeypair.publicKey, SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, userSecretKey);
bankDecentralizedLib.signTransaction(tx, solSigningAuthorityWalletSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Distribute Sol

This transaction add the sol in the user deposit pool from the distribution pool

let tx = await bankDecentralizedLib.createDistributeSolTransaction(bankName, amount, solSigningAuthorityWalletKeypair.publicKey,
    userKeypair.publicKey, feePayerWalletKeypair.publicKey, SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, userSecretKey);
bankDecentralizedLib.signTransaction(tx, solSigningAuthorityWalletSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Create Token Config

This transaction the creates the token config for the bank for a token mint account

const isSigningAuthorityRequired = false;
const isMaxWithdrawEnable = false;
const isMinWithdrawEnable = false;
const maxWithdraw = 0.1 * LAMPORTS_PER_SOL;
const minWithdraw = 3 * LAMPORTS_PER_SOL;

let tx = await bankDecentralizedLib.createTokenConfigTransaction(tokenMintAccount, bankName, isSigningAuthorityRequired, isMaxWithdrawEnable, isMinWithdrawEnable,
    maxWithdraw, minWithdraw, incomeAccount, tokenSigningAuthorityWalletKeypair.publicKey, bankSigningAuthorityWalletKeypair.publicKey,
    feePayerWalletKeypair.publicKey,
    TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, SystemProgram.programId, SYSVAR_RENT_PUBKEY);
bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, bankSigningAuthorityWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, tokenSigningAuthorityWalletSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Update Token Config

this transaction update the token config, only token signing authority can call this transaction

const isSigningAuthorityRequired = false;
const isMaxWithdrawEnable = false;
const isMinWithdrawEnable = false;
const maxWithdraw = 0.1 * LAMPORTS_PER_SOL;
const minWithdraw = 3 * LAMPORTS_PER_SOL;

let tx = await bankDecentralizedLib.createUpdateTokenConfigTransaction(tokenMintAccount, bankName, isSigningAuthorityRequired, isMaxWithdrawEnable, isMinWithdrawEnable,
    maxWithdraw, minWithdraw, incomeAccount, tokenSigningAuthorityWalletKeypair.publicKey,
    feePayerWalletKeypair.publicKey,
    TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, tokenSigningAuthorityWalletSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Add Token Distribution Supply

This transaction add the token in the distribution pool.

let tx = await bankDecentralizedLib.createAddTokenDistributionSupplyTransaction(tokenMintAccount, bankName, amount,
    bankSigningAuthorityWalletKeypair.publicKey, tokenSigningAuthorityWalletKeypair.publicKey, feePayerWalletKeypair.publicKey,
    TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, tokenSigningAuthorityWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, bankSigningAuthorityWalletSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Deposit Token

This transaction create user token config if it is not created and add token in the deposit pool.

let tx = await bankDecentralizedLib.createDepositTokenTransaction(tokenMintAccount, bankName, amount,
    userKeypair.publicKey, userKeypair.publicKey, feePayerWalletKeypair.publicKey,
    TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, userSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Deposit Token With Authority

This transaction create user token config if it is not created and add token in the deposit pool. For this transaction token signing authority is needed.

let tx = await bankDecentralizedLib.createDepositTokenWithAuthorityTransaction(tokenMintAccount, bankName, amount,
    userKeypair.publicKey, tokenSigningAuthorityWalletKeypair.publicKey, userKeypair.publicKey, feePayerWalletKeypair.publicKey,
    TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, userSecretKey);
bankDecentralizedLib.signTransaction(tx, tokenSigningAuthorityWalletSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Withdraw Token

This transaction withdraw token from the deposit pool for the user.

let tx = await bankDecentralizedLib.createWithdrawTokenTransaction(tokenMintAccount, bankName, amount,
    userKeypair.publicKey, userKeypair.publicKey, feePayerWalletKeypair.publicKey,
    TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, userSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Withdraw Token With Authority

This transaction withdraw token from the deposit pool for the user. For the transaction token signing authority is needed

let tx = await bankDecentralizedLib.createWithdrawTokenWithAuthorityTransaction(tokenMintAccount, bankName, amount,
    userKeypair.publicKey, tokenSigningAuthorityWalletKeypair.publicKey, userKeypair.publicKey, feePayerWalletKeypair.publicKey,
    TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, userSecretKey);
bankDecentralizedLib.signTransaction(tx, tokenSigningAuthorityWalletSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Spend Token

This transaction spend token from the user deposit pool and added in the income account.

let tx = await bankDecentralizedLib.createSpendTokenTransaction(tokenMintAccount, bankName, amount,
    incomeAccount, tokenSigningAuthorityWalletKeypair.publicKey, userKeypair.publicKey, feePayerWalletKeypair.publicKey,
    TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, userSecretKey);
bankDecentralizedLib.signTransaction(tx, tokenSigningAuthorityWalletSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

Distribute Token

This transaction add the token in the user deposit pool from the distribution pool

let tx = await bankDecentralizedLib.createDistributeTokenTransaction(tokenMintAccount, bankName, amount,
    tokenSigningAuthorityWalletKeypair.publicKey, userKeypair.publicKey, feePayerWalletKeypair.publicKey,
    TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, SystemProgram.programId, SYSVAR_RENT_PUBKEY);

bankDecentralizedLib.signTransaction(tx, feePayerWalletSecretKey);
bankDecentralizedLib.signTransaction(tx, userSecretKey);
bankDecentralizedLib.signTransaction(tx, tokenSigningAuthorityWalletSecretKey);

let txHash = await connection.sendRawTransaction(tx.serialize(), {skipPreflight: false});
console.log("Tx Hash: ", txHash);

See example here

| Name | Description | |:-------------------------------:|:--------------------------------------------:| | Main Config | Program config for the main pda account | | Bank Config | Program config for the bank pda account | | Sol Config | Program config for the sol pda account | | Token Config | Program config for the token pda account | | User Token Config | User config related to the token pda account | | User Sol Config | User config related to the sol pda account | | Deposit Pool | Deposit Pool pda account | | Deposit Pool Token Account | Deposit Pool pda token account | | Distribution Pool | Distribution Pool pda account | | Distribution Pool Token Account | Distribution Pool pda token account |