@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 |