### Install SPL Account Compression SDK Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/account-compression/usage.md Demonstrates how to install the necessary Solana Program Library (SPL) account compression SDK and web3.js library using either npm or yarn. ```shell npm install --save @solana/spl-account-compression @solana/web3.js@1 ``` ```shell yarn add @solana/spl-account-compression @solana/web3.js@1 ``` -------------------------------- ### Setup Local Test Validator Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/stake-pool/quickstart.md Initializes a local Solana test validator with a specified number of validator vote accounts. Outputs a file containing the base58-encoded public keys of these accounts. ```bash ./setup-test-validator.sh 10 local_validators.txt ``` -------------------------------- ### Client Setup and Testing Source: https://github.com/solana-labs/solana-program-library/blob/master/binary-option/README.md Instructions for setting up the Python client for the Binary Option program, including virtual environment creation, dependency installation, and running tests against a devnet deployment. ```bash python3 -m virtualenv venv source venv/bin/activate pip install -r client/requirements.txt python -m client.test ``` -------------------------------- ### Loading Token-2022 Program for Testing Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/token-2022/onchain.md Provides console commands to dump the Token-2022 program binary and to start a local Solana test validator with the Token-2022 program loaded. ```console $ solana program dump TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb spl_token_2022.so ``` ```console $ solana-test-validator -c TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb ``` -------------------------------- ### Initialize Transfer Fee Configuration Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/token-2022/onchain.md Provides an example of initializing the transfer fee configuration for a Token-2022 mint, specifying rate and withdraw authorities, and fee amounts. ```rust let rate_authority = Keypair::new(); let withdraw_authority = Keypair::new(); let instruction = spl_token_2022::extension::transfer_fee::instruction::initialize_transfer_fee_config( program_id, &mint_key, rate_authority.pubkey(), withdraw_authority.pubkey(), 0, 0 ).unwrap(); ``` -------------------------------- ### Build Solana Program Examples Source: https://github.com/solana-labs/solana-program-library/blob/master/examples/c/README.md Builds the Solana program examples using the make utility. This command compiles and prepares the C-based Solana programs for testing. ```bash $ make ``` -------------------------------- ### Create Solana Stake Pool Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/stake-pool/quickstart.md This command creates a new Solana stake pool with specified parameters such as epoch, withdrawal, and deposit fees, referral fee, and maximum validators. It also generates necessary keypair files for the pool, validator list, mint, and reserve. ```bash $ ./setup-stake-pool.sh 15 Creating pool + spl-stake-pool create-pool --epoch-fee-numerator 3 --epoch-fee-denominator 1000 --withdrawal-fee-numerator 3 --withdrawal-fee-denominator 1000 --deposit-fee-numerator 3 --deposit-fee-denominator 1000 --referral-fee 50 --max-validators 2350 --pool-keypair keys/stake-pool.json --validator-list-keypair keys/validator-list.json --mint-keypair keys/mint.json --reserve-keypair keys/reserve.json Creating reserve stake 4tvTkLB4X7ahUYZ2NaTohkG3mud4UBBvu9ZEGD4Wk9mt Creating mint BoNneHKDrX9BHjjvSpPfnQyRjsnc9WFH71v8wrgCd7LB Creating associated token account DgyZrAq88bnG1TNRxpgDQzWXpzEurCvfY2ukKFWBvADQ to receive stake pool tokens of mint BoNneHKDrX9BHjjvSpPfnQyRjsnc9WFH71v8wrgCd7LB, owned by 4SnSuUtJGKvk2GYpBwmEsWG53zTurVM8yXGsoiZQyMJn Creating pool fee collection account DgyZrAq88bnG1TNRxpgDQzWXpzEurCvfY2ukKFWBvADQ Signature: 51yf2J6dSGAx42KPs2oTMTV4ufEm1ncAHyLPQ6PNf4sbeMHGqno7BGn2tHkUnrd7PRXiWBbGzCWpJNevYjmoLgn2 Creating stake pool Zg5YBPAk8RqBR9kaLLSoN5C8Uv7nErBz1WC63HTsCPR with validator list 86VZZCuqiz7sDJpFKjQy9c9dZQN9vwDKbYgY8pcwHuaF Signature: 47QHcWMEa5Syg13C3SQRA4n88Y8iLx1f39wJXQAStRUxpt2VD5t6pYgAdruNRHUQt1ZBY8QwbvEC1LX9j3nPrAzn Depositing SOL into stake pool Update not required Using existing associated token account DgyZrAq88bnG1TNRxpgDQzWXpzEurCvfY2ukKFWBvADQ to receive stake pool tokens of mint BoNneHKDrX9BHjjvSpPfnQyRjsnc9WFH71v8wrgCd7LB, owned by 4SnSuUtJGKvk2GYpBwmEsWG53zTurVM8yXGsoiZQyMJn Signature: 4jnS368HcofZ1rUpsGZtmSK9kVxFzJRndSX5VS7eMV3kVgzyg9efA4mcgd2C6BoSNksTmTonRGXTVM1WMywFpiKq ``` -------------------------------- ### Create Account with Required Memo Transfers (JS) Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx Provides a JavaScript example using the Solana SDK to create a new token, initialize an account with memo transfer extensions, and enable required memo transfers. ```jsx import { clusterApiUrl, sendAndConfirmTransaction, Connection, Keypair, SystemProgram, Transaction, LAMPORTS_PER_SOL, } from '@solana/web3.js'; import { createMemoInstruction } from '@solana/spl-memo'; import { createAssociatedTokenAccount, createMint, createEnableRequiredMemoTransfersInstruction, createInitializeAccountInstruction, createTransferInstruction, disableRequiredMemoTransfers, enableRequiredMemoTransfers, getAccountLen, mintTo, ExtensionType, TOKEN_2022_PROGRAM_ID, } from '@solana/spl-token'; (async () => { const connection = new Connection(clusterApiUrl('devnet'), 'confirmed'); const payer = Keypair.generate(); const airdropSignature = await connection.requestAirdrop(payer.publicKey, 2 * LAMPORTS_PER_SOL); await connection.confirmTransaction({ signature: airdropSignature, ...(await connection.getLatestBlockhash()) }); const mintAuthority = Keypair.generate(); const decimals = 9; const mint = await createMint( connection, payer, mintAuthority.publicKey, mintAuthority.publicKey, decimals, undefined, undefined, TOKEN_2022_PROGRAM_ID ); const accountLen = getAccountLen([ExtensionType.MemoTransfer]); const lamports = await connection.getMinimumBalanceForRentExemption(accountLen); const owner = Keypair.generate(); const destinationKeypair = Keypair.generate(); const destination = destinationKeypair.publicKey; const transaction = new Transaction().add( SystemProgram.createAccount({ fromPubkey: payer.publicKey, newAccountPubkey: destination, space: accountLen, lamports, programId: TOKEN_2022_PROGRAM_ID, }), createInitializeAccountInstruction(destination, mint, owner.publicKey, TOKEN_2022_PROGRAM_ID), createEnableRequiredMemoTransfersInstruction(destination, owner.publicKey, [], TOKEN_2022_PROGRAM_ID) ); await sendAndConfirmTransaction(connection, transaction, [payer, owner, destinationKeypair], undefined); })(); ``` -------------------------------- ### Start Local Development Server Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/README.md Starts a local development server for the documentation. Changes are reflected live without requiring a server restart. ```bash $ npm run start ``` -------------------------------- ### Install @solana/spl-account-compression Source: https://github.com/solana-labs/solana-program-library/blob/master/account-compression/sdk/README.md Installs the `@solana/spl-account-compression` and `@solana/web3.js` libraries using either npm or yarn. ```shell npm install --save @solana/spl-account-compression @solana/web3.js@1 ``` ```shell yarn add @solana/spl-account-compression @solana/web3.js@1 ``` -------------------------------- ### Install spl-feature-proposal CLI Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/feature-proposal.md Installs the command-line utility for managing feature proposals. Requires Rust to be installed. ```sh cargo install spl-feature-proposal-cli ``` -------------------------------- ### Install honggfuzz Source: https://github.com/solana-labs/solana-program-library/blob/master/token-swap/README.md Installs the Rust version of honggfuzz, used for fuzz testing the Token Swap program. ```sh cargo install honggfuzz ``` -------------------------------- ### Install Dependencies (NPM) Source: https://github.com/solana-labs/solana-program-library/blob/master/token-lending/js/README.md Installs the SPL Token Lending client library and its peer dependencies using NPM. ```shell npm install @solana/spl-token-lending @solana/spl-token @solana/web3.js@1 ``` -------------------------------- ### Create Lending Market CLI Example Source: https://github.com/solana-labs/solana-program-library/blob/master/token-lending/cli/README.md An example of creating a lending market with specific program ID, fee payer, and market owner. It shows the expected output including the newly created market's public key and transaction signatures. ```shell spl-token-lending \ --program 6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH \ --fee-payer owner.json \ create-market \ --market-owner JAgN4SZLNeCo9KTnr8EWt4FzEV1UDgHkcZwkVtWtfp6P # Creating lending market 7uX9ywsk1X2j6wLoywMDVQLNWAqhDpVqZzL4qm4CuMMT # Signature: 51mi4Ve42h4PQ1RXjfz141T6KCdqnB3UDyhEejviVHrX4SnQCMx86TZa9CWUT3efFYkkmfmseG5ZQr2TZTHJ8S95 ``` -------------------------------- ### Install spl-token CLI Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/token.mdx Installs the spl-token command-line utility for experimenting with SPL tokens. Requires Rust to be installed. ```console $ cargo install spl-token-cli ``` -------------------------------- ### Install JavaScript Dependencies Source: https://github.com/solana-labs/solana-program-library/blob/master/token-swap/README.md Installs the necessary Node.js modules for the JavaScript bindings of the Token Swap program. ```sh npm i ``` -------------------------------- ### Install Docusaurus Dependencies Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/README.md Installs the necessary Node.js dependencies for Docusaurus to build and serve the documentation. ```bash $ npm install ``` -------------------------------- ### Install SPL Token and Token Lending CLIs Source: https://github.com/solana-labs/solana-program-library/blob/master/token-lending/README.md Installs the necessary command-line interface tools for interacting with the Token and Token Lending programs on Solana. These tools are essential for managing lending markets and reserves. ```shell cargo install spl-token-cli cargo install spl-token-lending-cli ``` -------------------------------- ### Install spl-token-lending-cli Source: https://github.com/solana-labs/solana-program-library/blob/master/token-lending/cli/README.md Installs the SPL Token Lending CLI using Cargo, the Rust package manager. This command fetches and compiles the latest version of the CLI. ```shell cargo install spl-token-lending-cli ``` -------------------------------- ### Install Dependencies Source: https://github.com/solana-labs/solana-program-library/blob/master/token-swap/js/README.md Installs the necessary npm dependencies for the Token-swap JavaScript library, including @solana/web3.js. ```sh $ npm install ``` -------------------------------- ### Install spl-stake-pool CLI Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/stake-pool/cli.md Installs the stake pool command-line utility using Cargo. Requires Rust to be installed. ```console cargo install spl-stake-pool-cli ``` -------------------------------- ### Install Dependencies (Yarn) Source: https://github.com/solana-labs/solana-program-library/blob/master/token-lending/js/README.md Installs the SPL Token Lending client library and its peer dependencies using Yarn. ```shell yarn add @solana/spl-token-lending @solana/spl-token @solana/web3.js@1 ``` -------------------------------- ### Install @solana/spl-name-service using npm Source: https://github.com/solana-labs/solana-program-library/blob/master/name-service/js/README.md Installs the Solana Name Service JavaScript bindings using the npm package manager. ```bash npm install @solana/spl-name-service ``` -------------------------------- ### Install @solana/spl-name-service using yarn Source: https://github.com/solana-labs/solana-program-library/blob/master/name-service/js/README.md Installs the Solana Name Service JavaScript bindings using the yarn package manager. ```bash yarn add @solana/spl-name-service ``` -------------------------------- ### Install @solana/spl-single-pool Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/single-pool.mdx Instructions for installing the @solana/spl-single-pool package using different package managers. ```console $ pnpm install @solana/spl-single-pool ``` ```console $ yarn add @solana/spl-single-pool ``` ```console $ npm install @solana/spl-single-pool ``` -------------------------------- ### Run Test Client Source: https://github.com/solana-labs/solana-program-library/blob/master/token-swap/js/README.md Starts the test client along with a test validator to exercise the Token-swap program. ```sh $ npm run start-with-test-validator ``` -------------------------------- ### Add Reserve to Market CLI Example Source: https://github.com/solana-labs/solana-program-library/blob/master/token-lending/cli/README.md An example of adding a reserve to a lending market, specifying all necessary parameters including token amounts and oracle accounts. The output includes the new reserve's public key and transaction signatures. ```shell spl-token-lending \ --program 6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH \ --fee-payer owner.json \ add-reserve \ --market-owner owner.json \ --source-owner owner.json \ --market 7uX9ywsk1X2j6wLoywMDVQLNWAqhDpVqZzL4qm4CuMMT \ --source AJ2sgpgj6ZeQazPPiDyTYqN9vbj58QMaZQykB9Sr6XY \ --amount 5.0 \ --pyth-product 8yrQMUyJRnCJ72NWwMiPV9dNGw465Z8bKUvnUC8P5L6F \ --pyth-price BdgHsXrH1mXqhdosXavYxZgX6bGqTdj5mh2sxDhF8bJy # Adding reserve 69BwFhpQBzZfcp9MCj9V8TLvdv9zGfQQPQbb8dUHsaEa # Signature: 2yKHnmBSqBpbGdsxW75nnmZMys1bZMbHiczdZitMeQHYdpis4eVhuMWGE29hhgtHpNDjdPj5YVbqkWoAEBw1WaU # Signature: 33x8gbn2RkiA5844eCZq151DuVrYTvUoF1bQ5xA3mqkibJZaJja2hj8RoyjKZpZqg2ckcSKMAeqWbMeWC6vAySQS # Signature: 3dk79hSgzFhxPrmctYnS5dxRhojfKkDwwLxEda9bTXqVELHSL4ux8au4jwvL8xuraVhaZAmugCn4TA1YCfLM4sVL ``` -------------------------------- ### Transferring Tokens with Memo (CLI) Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx Demonstrates how to transfer tokens using the spl-token CLI, including a required memo. ```console $ spl-token transfer EbPBt3XkCb9trcV4c8fidhrvoeURbDbW87Acustzyi8N 10 4Uzz67txwYbfYpF8r5UGEMYJwhPAYQ5eFUY89KTYc2bL --with-memo "memo text" Signature: 5a9X8JrWzwZqb3iMonfUfSZbisQ57aEmW5cFntWGYRv2UZx8ACkMineBEQRHwLMzYHeyFDEHMXu8zqAMv5tm4u1g ``` -------------------------------- ### Initialize Mint with MintCloseAuthority Extension Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/token-2022/onchain.md Demonstrates how to create a mint account with the MintCloseAuthority extension in Token-2022. It includes calculating space, rent, and the correct instruction order for initialization. ```rust use spl_token_2022::{extension::ExtensionType, instruction::*, state::Mint}; use solana_sdk::{system_instruction, transaction::Transaction}; // Calculate the space required using the `ExtensionType` let space = ExtensionType::try_calculate_account_len::(&[ExtensionType::MintCloseAuthority]).unwrap(); // get the Rent object and calculate the rent required let rent_required = rent.minimum_balance(space); // and then create the account using those parameters let create_instruction = system_instruction::create_account(&payer.pubkey(), mint_pubkey, rent_required, space, token_program_id); // Important: you must initialize the mint close authority *BEFORE* initializing the mint, // and only when working with Token-2022, since the instruction is unsupported by Token. let initialize_close_authority_instruction = initialize_mint_close_authority(token_program_id, mint_pubkey, Some(close_authority)).unwrap(); let initialize_mint_instruction = initialize_mint(token_program_id, mint_pubkey, mint_authority_pubkey, freeze_authority, 9).unwrap(); // Make the transaction with all of these instructions let create_mint_transaction = Transaction::new(&[create_instruction, initialize_close_authority_instruction, initialize_mint_instruction], Some(&payer.pubkey)); ``` -------------------------------- ### Withdraw from Stake Pool Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/stake-pool/quickstart.md Withdraws stakes and SOL from each of the stake accounts in the pool. Users can choose to withdraw SOL from the reserve or from specific stake accounts. ```bash $ ./withdraw.sh keys/stake-pool.json local_validators.txt 1 ``` -------------------------------- ### Finding Accounts with Withheld Tokens (JavaScript) Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx This JavaScript example shows how to identify accounts that have accumulated withheld tokens. It iterates through all accounts associated with a specific mint and checks for any withheld amounts, which can then be withdrawn. ```jsx const allAccounts = await connection.getProgramAccounts(TOKEN_2022_PROGRAM_ID, { commitment: 'confirmed', filters: [ { memcmp: { offset: 0, bytes: mint.toString(), }, }, ], }); const accountsToWithdrawFrom = []; for (const accountInfo of allAccounts) { const account = unpackAccount(accountInfo.account, accountInfo.pubkey, TOKEN_2022_PROGRAM_ID); const transferFeeAmount = getTransferFeeAmount(account); if (transferFeeAmount !== null && transferFeeAmount.withheldAmount > BigInt(0)) { accountsToWithdrawFrom.push(accountInfo.pubkey); } } ``` -------------------------------- ### Delegate Stake on Local Network Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/stake-pool/quickstart.md Delegates stake to a validator on a local Solana network. The `--force` flag is required due to the lack of voting activity on test validators. ```bash solana delegate-stake --force stake.json CzDy6uxLTko5Jjcdm46AozMmrARY6R2aDBagdemiBuiT ``` -------------------------------- ### Testing Local SDK Source: https://github.com/solana-labs/solana-program-library/blob/master/account-compression/README.md Instructions for linking and testing the local Solana Program Library SDK, specifically for the account compression package. ```bash pnpm link @solana/spl-account-compression pnpm i pnpm test ``` -------------------------------- ### Deposit SOL into Stake Pool Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/stake-pool/quickstart.md This command deposits additional SOL into an existing Solana stake pool in exchange for pool tokens. It requires the stake pool's address and the amount of SOL to deposit. ```bash $ spl-stake-pool deposit-sol Zg5YBPAk8RqBR9kaLLSoN5C8Uv7nErBz1WC63HTsCPR 10 Using existing associated token account DgyZrAq88bnG1TNRxpgDQzWXpzEurCvfY2ukKFWBvADQ to receive stake pool tokens of mint BoNneHKDrX9BHjjvSpPfnQyRjsnc9WFH71v8wrgCd7LB, owned by 4SnSuUtJGKvk2GYpBwmEsWG53zTurVM8yXGsoiZQyMJn Signature: 4AJv6hSznYoMGnaQvjWXSBjKqtjYpjBx2MLezmRRjWRDa8vUaBLQfPNGd3kamZNs1JeWSvnzczwtzsMD5WkgKamA ``` -------------------------------- ### Update Instruction Processor Accounts Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/token-2022/onchain.md Modifies the account iteration in an instruction processor to include new token program accounts. This example shows the transition from expecting a fixed set of accounts to accommodating additional token program identifiers. ```rust let account_info_iter = &mut accounts.iter(); let swap_info = next_account_info(account_info_iter)?; let authority_info = next_account_info(account_info_iter)?; let user_transfer_authority_info = next_account_info(account_info_iter)?; let source_info = next_account_info(account_info_iter)?; let swap_source_info = next_account_info(account_info_iter)?; let swap_destination_info = next_account_info(account_info_iter)?; let destination_info = next_account_info(account_info_iter)?; let pool_mint_info = next_account_info(account_info_iter)?; let pool_fee_account_info = next_account_info(account_info_iter)?; let token_program_info = next_account_info(account_info_iter)?; ``` ```rust let account_info_iter = &mut accounts.iter(); let swap_info = next_account_info(account_info_iter)?; let authority_info = next_account_info(account_info_iter)?; let user_transfer_authority_info = next_account_info(account_info_iter)?; let source_info = next_account_info(account_info_iter)?; let swap_source_info = next_account_info(account_info_iter)?; let swap_destination_info = next_account_info(account_info_iter)?; let destination_info = next_account_info(account_info_iter)?; let pool_mint_info = next_account_info(account_info_iter)?; let pool_fee_account_info = next_account_info(account_info_iter)?; let source_token_program_info = next_account_info(account_info_iter)?; // added let destination_token_program_info = next_account_info(account_info_iter)?; // added let pool_token_program_info = next_account_info(account_info_iter)?; // renamed ``` -------------------------------- ### Build and Deploy Solana Program Source: https://github.com/solana-labs/solana-program-library/blob/master/token-lending/README.md Builds the Solana program binaries and deploys the program to the Solana devnet. This involves compiling the Rust code into an executable format and then uploading it to the blockchain. ```shell cargo build cargo build-sbf solana config set --url https://api.devnet.solana.com solana program deploy \ -k owner.json \ --program-id lending.json \ target/deploy/spl_token_lending.so ``` -------------------------------- ### Build Documentation Locally Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/README.md Generates static documentation files into the 'build' directory, which can then be hosted on any static hosting service. ```shell $ docs/build.sh ``` -------------------------------- ### Create Non-Transferable Mint (JavaScript) Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx Provides a JavaScript example using the `@solana/web3.js` and `@solana/spl-token` libraries to create a new token mint with the non-transferable extension enabled on the Solana devnet. It includes setting up the connection, generating keypairs, and constructing the transaction. ```javascript import { clusterApiUrl, sendAndConfirmTransaction, Connection, Keypair, SystemProgram, Transaction, LAMPORTS_PER_SOL, } from '@solana/web3.js'; import { createInitializeNonTransferableMintInstruction, createInitializeMintInstruction, getMintLen, ExtensionType, TOKEN_2022_PROGRAM_ID, } from '@solana/spl-token'; (async () => { const connection = new Connection(clusterApiUrl('devnet'), 'confirmed'); const payer = Keypair.generate(); const airdropSignature = await connection.requestAirdrop(payer.publicKey, 2 * LAMPORTS_PER_SOL); await connection.confirmTransaction({ signature: airdropSignature, ...(await connection.getLatestBlockhash()) }); const mintAuthority = Keypair.generate(); const decimals = 9; const mintKeypair = Keypair.generate(); const mint = mintKeypair.publicKey; const mintLen = getMintLen([ExtensionType.NonTransferable]); const lamports = await connection.getMinimumBalanceForRentExemption(mintLen); const transaction = new Transaction().add( SystemProgram.createAccount({ fromPubkey: payer.publicKey, newAccountPubkey: mint, space: mintLen, lamports, programId: TOKEN_2022_PROGRAM_ID, }), createInitializeNonTransferableMintInstruction(mint, TOKEN_2022_PROGRAM_ID), createInitializeMintInstruction(mint, decimals, mintAuthority.publicKey, null, TOKEN_2022_PROGRAM_ID) ); await sendAndConfirmTransaction(connection, transaction, [payer, mintKeypair], undefined); })(); ``` -------------------------------- ### Initiate Feature Proposal Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/feature-proposal.md Initiates a feature proposal by submitting a JSON configuration file. It outputs key details like Feature ID, Token Mint Address, and distribution information. The `--confirm` flag is required for actual initiation after review. ```bash $ spl-feature-proposal propose feature-proposal.json Feature Id: HQ3baDfNU7WKCyWvtMYZmi51YPs7vhSiLn1ESYp3jhiA Token Mint Address: ALvA7Lv9jbo8JFhxqnRpjWWuR3aD12uCb5KBJst4uc3d Distributor Token Address: GK55hNft4TGc3Hg4KzbjEmju8VfaNuXK8jQNDTZKcsNF Acceptance Token Address: AdqKm3mSJf8AtTWjfpA5ZbJszWQPcwyLA2XkRyLbf3Di Number of validators: 376 Tokens to be minted: 134575791.53064314 Tokens required for acceptance: 90165780.3255309 (67%) Token distribution file: feature-proposal.csv JSON RPC URL: http://api.mainnet-beta.solana.com Add --confirm flag to initiate the feature proposal ``` -------------------------------- ### Transferring Tokens with Fee Checked (JavaScript) Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx This JavaScript example demonstrates the programmatic approach to transferring tokens with a checked fee using the Solana Program Library. It includes creating accounts, minting tokens, and executing the transfer with fee validation. ```jsx const mintAmount = BigInt(1_000_000_000); const owner = Keypair.generate(); const sourceAccount = await createAccount( connection, payer, mint, owner.publicKey, undefined, undefined, TOKEN_2022_PROGRAM_ID ); await mintTo( connection, payer, mint, sourceAccount, mintAuthority, mintAmount, [], undefined, TOKEN_2022_PROGRAM_ID ); const accountKeypair = Keypair.generate(); const destinationAccount = await createAccount( connection, payer, mint, owner.publicKey, accountKeypair, undefined, TOKEN_2022_PROGRAM_ID ); const transferAmount = BigInt(1_000_000); const fee = (transferAmount * BigInt(feeBasisPoints)) / BigInt(10_000); await transferCheckedWithFee( connection, payer, sourceAccount, mint, destinationAccount, owner, transferAmount, decimals, fee, [], undefined, TOKEN_2022_PROGRAM_ID ); ``` -------------------------------- ### Add Validators to Stake Pool Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/stake-pool/quickstart.md Adds validator stake accounts to the stake pool. This operation moves SOL from the reserve to a stake account delegated to a specific validator. Ensure you have over 1 SOL per validator to add. ```bash $ ./add-validators.sh keys/stake-pool.json local_validators.txt Adding validator stake accounts to the pool Adding stake account 3k7Nwu9jUSc6SNG11wzufKYoZXRFgxWamheGLYWp5Rvx, delegated to EhRbKi4Vhm1oUCGWHiLEMYZqDrHwEd7Jgzgi26QJKvfQ Signature: 5Vm2n3umPXFzQgDiaib1B42k7GqsNYHZWrauoe4DUyFszczB7Hjv9r1DKWKrypc8KDiUccdWmJhHBqM1fdP6WiCm Signature: 3XtmYu9msqnMeKJs9BopYjn5QTc5hENMXXiBwvEw6HYzU5w6z1HUkGwNW24io4Vu9WRKFFN6SAtrfkZBLK4fYjv4 ... (something similar repeated 9 more times) ``` -------------------------------- ### Create Account with Required Memo Transfers (CLI) Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx Demonstrates the CLI commands to create a new token, create an associated account, and enable required memo transfers for that account. ```console $ spl-token --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb create-token Creating token EbPBt3XkCb9trcV4c8fidhrvoeURbDbW87Acustzyi8N under program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb Address: EbPBt3XkCb9trcV4c8fidhrvoeURbDbW87Acustzyi8N Decimals: 9 Signature: 2mCoV3ujSUArgZMyayiYtLZp2QzpqKx3NXnv9W8DpinY39rBU2yGmYLfp2tZ9uZqVbfJ6Mf3SqDHexdCcFcDAEvc $ spl-token create-account EbPBt3XkCb9trcV4c8fidhrvoeURbDbW87Acustzyi8N Creating account 4Uzz67txwYbfYpF8r5UGEMYJwhPAYQ5eFUY89KTYc2bL Signature: 57wZHDaQtSzszDkusrnozZNj5PemQhpqHMEFLWFKpqASCErcDuBuYuEky5g3evHtkjMrKgh1s3aEap1L8y5UhW5W $ spl-token enable-required-transfer-memos 4Uzz67txwYbfYpF8r5UGEMYJwhPAYQ5eFUY89KTYc2bL Signature: 5MnWtrhMK32zkbacDMwBNft48VAUpr4EoRM87hkT9AFYvPgPEU7V7ERV6gdfb3kASri4wnUnr13hNKuYJ66pD8Fs ``` -------------------------------- ### Create Token with Metadata Pointer and Embedded Metadata (JS) Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx Provides a JavaScript example using the `@solana/web3.js` and `@solana/spl-token` libraries to create a new SPL token with both a metadata pointer and embedded metadata. It demonstrates the programmatic approach to token creation and metadata initialization. ```javascript import { clusterApiUrl, Connection, Keypair, LAMPORTS_PER_SOL, sendAndConfirmTransaction, SystemProgram, Transaction, } from '@solana/web3.js'; import { createInitializeMetadataPointerInstruction, createInitializeMintInstruction, ExtensionType, getMintLen, LENGTH_SIZE, TOKEN_2022_PROGRAM_ID, TYPE_SIZE, } from '@solana/spl-token'; import { createInitializeInstruction, pack, TokenMetadata } from '@solana/spl-token-metadata'; (async () => { const payer = Keypair.generate(); const mint = Keypair.generate(); const decimals = 9; const metadata: TokenMetadata = { mint: mint.publicKey, name: 'TOKEN_NAME', symbol: 'SMBL', uri: 'URI', additionalMetadata: [['new-field', 'new-value']], }; const mintLen = getMintLen([ExtensionType.MetadataPointer]); const metadataLen = TYPE_SIZE + LENGTH_SIZE + pack(metadata).length; const connection = new Connection(clusterApiUrl('devnet'), 'confirmed'); const airdropSignature = await connection.requestAirdrop(payer.publicKey, 2 * LAMPORTS_PER_SOL); await connection.confirmTransaction({ signature: airdropSignature, ...(await connection.getLatestBlockhash()), }); const mintLamports = await connection.getMinimumBalanceForRentExemption(mintLen + metadataLen); const mintTransaction = new Transaction().add( SystemProgram.createAccount({ fromPubkey: payer.publicKey, newAccountPubkey: mint.publicKey, space: mintLen, lamports: mintLamports, programId: TOKEN_2022_PROGRAM_ID, }), createInitializeMetadataPointerInstruction(mint.publicKey, payer.publicKey, mint.publicKey, TOKEN_2022_PROGRAM_ID), createInitializeMintInstruction(mint.publicKey, decimals, payer.publicKey, null, TOKEN_2022_PROGRAM_ID), createInitializeInstruction({ programId: TOKEN_2022_PROGRAM_ID, mint: mint.publicKey, metadata: mint.publicKey, name: metadata.name, symbol: metadata.symbol, uri: metadata.uri, mintAuthority: payer.publicKey, updateAuthority: payer.publicKey, }), ); await sendAndConfirmTransaction(connection, mintTransaction, [payer, mint]); })(); ``` -------------------------------- ### Create Token with Transfer Fee (JavaScript) Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/token-2022/extensions.mdx Provides a JavaScript example using the @solana/web3.js and @solana/spl-token libraries to create an SPL token with transfer fee configurations. It sets up mint authorities, transfer fee authorities, and initializes the mint with the transfer fee configuration. ```jsx import { clusterApiUrl, sendAndConfirmTransaction, Connection, Keypair, SystemProgram, Transaction, LAMPORTS_PER_SOL, } from '@solana/web3.js'; import { ExtensionType, createInitializeMintInstruction, mintTo, createAccount, getMintLen, TOKEN_2022_PROGRAM_ID, } from '@solana/spl-token'; import { createInitializeTransferFeeConfigInstruction, harvestWithheldTokensToMint, transferCheckedWithFee, withdrawWithheldTokensFromAccounts, withdrawWithheldTokensFromMint, } from '@solana/spl-token'; (async () => { const payer = Keypair.generate(); const mintAuthority = Keypair.generate(); const mintKeypair = Keypair.generate(); const mint = mintKeypair.publicKey; const transferFeeConfigAuthority = Keypair.generate(); const withdrawWithheldAuthority = Keypair.generate(); const extensions = [ExtensionType.TransferFeeConfig]; const mintLen = getMintLen(extensions); const decimals = 9; const feeBasisPoints = 50; const maxFee = BigInt(5_000); const connection = new Connection(clusterApiUrl('devnet'), 'confirmed'); const airdropSignature = await connection.requestAirdrop(payer.publicKey, 2 * LAMPORTS_PER_SOL); await connection.confirmTransaction({ signature: airdropSignature, ...(await connection.getLatestBlockhash()) }); const mintLamports = await connection.getMinimumBalanceForRentExemption(mintLen); const mintTransaction = new Transaction().add( SystemProgram.createAccount({ fromPubkey: payer.publicKey, newAccountPubkey: mint, space: mintLen, lamports: mintLamports, programId: TOKEN_2022_PROGRAM_ID, }), createInitializeTransferFeeConfigInstruction( mint, transferFeeConfigAuthority.publicKey, withdrawWithheldAuthority.publicKey, feeBasisPoints, maxFee, TOKEN_2022_PROGRAM_ID ), createInitializeMintInstruction(mint, decimals, mintAuthority.publicKey, null, TOKEN_2022_PROGRAM_ID) ); await sendAndConfirmTransaction(connection, mintTransaction, [payer, mintKeypair], undefined); })(); ``` -------------------------------- ### Rebalance Stake in Stake Pool Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/stake-pool/quickstart.md Rebalances the stake within the pool by increasing the stake on each validator in the list by a given amount. This is a simple rebalancer; more sophisticated logic may be needed for production environments. Consider using the stake-o-matic bot for automated rebalancing. ```bash $ ./rebalance.sh keys/stake-pool.json local_validators.txt 1 ``` -------------------------------- ### Deposit Stakes into Stake Pool Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/stake-pool/quickstart.md Deposits stake accounts into the stake pool. This script creates new stakes to deposit a given amount into each of the stake accounts in the pool. This is useful for users who already have stake accounts and want to diversify or receive stake pool tokens. ```bash $ ./deposit.sh keys/stake-pool.json local_validators.txt 10 Note: This is a bit more finicky on a local network because of the short epochs, and may fail. No problem, you simply need to retry. ``` -------------------------------- ### Swap Instruction with Mint Accounts Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/token-2022/onchain.md Demonstrates how to modify a swap instruction to include source and destination mint accounts, which is a requirement when using the `transfer` instruction. ```rust /// Swap the tokens in the pool. /// /// 0. `[]` Token-swap /// 1. `[]` swap authority /// 2. `[]` user transfer authority /// 3. `[writable]` token_(A|B) SOURCE Account, amount is transferable by user transfer authority, /// 4. `[writable]` token_(A|B) Base Account to swap INTO. Must be the SOURCE token. /// 5. `[writable]` token_(A|B) Base Account to swap FROM. Must be the DESTINATION token. /// 6. `[writable]` token_(A|B) DESTINATION Account assigned to USER as the owner. /// 7. `[writable]` Pool token mint, to generate trading fees /// 8. `[writable]` Fee account, to receive trading fees /// 9. `[]` Token (A|B) SOURCE mint /// 10. `[]` Token (A|B) DESTINATION mint /// 11. `[]` Token (A|B) SOURCE program id /// 12. `[]` Token (A|B) DESTINATION program id /// 13. `[]` Pool Token program id /// 14. `[optional, writable]` Host fee account to receive additional trading fees Swap(...), ``` -------------------------------- ### Build Development Version Source: https://github.com/solana-labs/solana-program-library/blob/master/token-swap/README.md Builds a development version of the Token Swap program using the standard Solana build command. ```sh cargo build-sbf ``` -------------------------------- ### Build Clients Source: https://github.com/solana-labs/solana-program-library/blob/master/README.md Commands to build all client applications or a specific client using cargo. Navigate to the client directory for building a specific client. ```bash # To build all clients $ cargo build # To build a specific client $ cd /cli $ cargo build ``` -------------------------------- ### Initialize Token Account with ImmutableOwner Extension Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/token-2022/onchain.md Shows how to create a token account with the ImmutableOwner extension in Token-2022. This involves calculating space, rent, and the correct order of initialization instructions. ```rust use spl_token_2022::{extension::ExtensionType, instruction::*, state::Account}; use solana_sdk::{system_instruction, transaction::Transaction}; // Calculate the space required using the `ExtensionType` let space = ExtensionType::try_calculate_account_len::(&[ExtensionType::ImmutableOwner]).unwrap(); // get the Rent object and calculate the rent required let rent_required = rent.minimum_balance(space); // and then create the account using those parameters let create_instruction = system_instruction::create_account(&payer.pubkey(), account_pubkey, rent_required, space, token_program_id); // Important: you must initialize immutable owner *BEFORE* initializing the account let initialize_immutable_owner_instruction = initialize_immutable_owner(token_program_id, account_pubkey).unwrap(); let initialize_account_instruction = initialize_account(token_program_id, account_pubkey, mint_pubkey, owner_pubkey).unwrap(); // Make the transaction with all of these instructions let create_account_transaction = Transaction::new(&[create_instruction, initialize_immutable_owner_instruction, initialize_account_instruction], Some(&payer.pubkey)); ``` -------------------------------- ### Install spl-single-pool-cli Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/single-pool.mdx Installs the single-validator stake pool command-line interface using Cargo. Requires Rust to be installed. ```console $ cargo install spl-single-pool-cli ``` -------------------------------- ### Run Unit Tests Source: https://github.com/solana-labs/solana-program-library/blob/master/token-swap/README.md Executes unit tests for the Token Swap program from the ./program/ directory. ```sh cargo test ``` -------------------------------- ### Install spl-token JavaScript Package Source: https://github.com/solana-labs/solana-program-library/blob/master/docs/src/token.mdx Installs the @solana/spl-token JavaScript library using either Yarn or npm. ```bash yarn add @solana/spl-token ``` ```bash npm install @solana/spl-token ``` -------------------------------- ### Run Fuzz Tests Source: https://github.com/solana-labs/solana-program-library/blob/master/token-swap/README.md Runs fuzz tests on the Token Swap program using honggfuzz from the ./program/fuzz directory. ```sh cargo hfuzz run token-swap-instructions ```