├── utils ├── cgen │ ├── src │ │ └── main │ └── Cargo.toml └── test-client │ ├── src │ └── main.rs │ └── Cargo.toml ├── binary-option ├── client │ ├── __init__.py │ └── requirements.txt └── program │ ├── program_id.md │ ├── src │ ├── lib.rs │ ├── entrypoint.rs │ ├── error.rs │ └── validation_utils.rs │ └── Cargo.toml ├── token-swap ├── js │ ├── .eslintignore │ ├── .gitignore │ ├── tsconfig.root.json │ ├── src │ │ └── util │ │ │ ├── sleep.ts │ │ │ ├── new-system-account-with-airdrop.ts │ │ │ ├── account.ts │ │ │ └── new-account-with-lamports.ts │ ├── .prettierrc.yaml │ ├── .mocharc.json │ ├── tsconfig.json │ ├── tsconfig.all.json │ ├── tsconfig.cjs.json │ ├── tsconfig.esm.json │ ├── tsconfig.base.json │ ├── README.md │ └── .eslintrc ├── program │ ├── program-id.md │ ├── Xargo.toml │ ├── proptest-regressions │ │ └── curve │ │ │ └── constant_price.txt │ ├── fuzz │ │ ├── src │ │ │ ├── lib.rs │ │ │ └── native_account_data.rs │ │ └── Cargo.toml │ ├── src │ │ ├── curve │ │ │ └── mod.rs │ │ ├── lib.rs │ │ └── entrypoint.rs │ ├── cbindgen.toml │ └── Cargo.toml └── proposals │ ├── StakePoolStableCurve.md │ ├── DynamicMarketMaking.md │ └── Pausable.md ├── .npmrc ├── governance ├── program │ ├── tests │ │ ├── fixtures │ │ │ ├── .gitignore │ │ │ ├── solana_bpf_rust_upgraded.so │ │ │ └── solana_bpf_rust_upgradeable.so │ │ └── process_create_token_owner_record.rs │ ├── Xargo.toml │ ├── src │ │ ├── addins │ │ │ └── mod.rs │ │ ├── tools │ │ │ ├── mod.rs │ │ │ └── pack.rs │ │ ├── state │ │ │ ├── mod.rs │ │ │ └── native_treasury.rs │ │ ├── lib.rs │ │ ├── entrypoint.rs │ │ └── processor │ │ │ └── process_set_governance_delegate.rs │ └── Cargo.toml ├── tools │ ├── src │ │ └── lib.rs │ ├── README.md │ └── Cargo.toml ├── addin-api │ ├── README.md │ ├── src │ │ └── lib.rs │ └── Cargo.toml ├── chat │ ├── program │ │ ├── Xargo.toml │ │ ├── src │ │ │ ├── lib.rs │ │ │ ├── entrypoint.rs │ │ │ └── error.rs │ │ ├── tests │ │ │ └── program_test │ │ │ │ └── cookies.rs │ │ └── Cargo.toml │ └── README.md ├── addin-mock │ ├── program │ │ ├── Xargo.toml │ │ ├── src │ │ │ ├── lib.rs │ │ │ ├── entrypoint.rs │ │ │ └── error.rs │ │ └── Cargo.toml │ └── README.md ├── resources │ ├── governance-accounts.jpg │ └── governance-workflow.jpg ├── test-sdk │ ├── README.md │ ├── src │ │ ├── cookies.rs │ │ └── addins.rs │ └── Cargo.toml └── CHANGELOG.md ├── rust-toolchain.toml ├── token-lending ├── js │ ├── .gitignore │ ├── src │ │ ├── util │ │ │ ├── index.ts │ │ │ └── layout.ts │ │ ├── index.ts │ │ ├── state │ │ │ ├── index.ts │ │ │ ├── lastUpdate.ts │ │ │ └── lendingMarket.ts │ │ ├── constants.ts │ │ └── instructions │ │ │ ├── instruction.ts │ │ │ ├── index.ts │ │ │ ├── refreshReserve.ts │ │ │ ├── setLendingMarketOwner.ts │ │ │ ├── refreshObligation.ts │ │ │ └── initObligation.ts │ ├── .eslintignore │ ├── .eslintrc.json │ ├── tsconfig.json │ ├── rollup.config.ts │ └── README.md ├── program │ ├── program-id.md │ ├── Xargo.toml │ ├── proptest-regressions │ │ └── state │ │ │ └── reserve.txt │ ├── src │ │ ├── math │ │ │ ├── mod.rs │ │ │ └── common.rs │ │ ├── lib.rs │ │ └── entrypoint.rs │ ├── tests │ │ └── fixtures │ │ │ ├── 3Mnn2fX6rQyUsyELYms1sBJyChWofzSNRoqYzvgMVz5E.bin │ │ │ ├── 6MEwdxe4g1NeAF9u6KDG14anJpFsVEa2cvr5H6iriFZ8.bin │ │ │ ├── 992moaMQKs32GKZ9dxi8keyM2bUmbrwBZpK4p2K6X5Vs.bin │ │ │ ├── J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix.bin │ │ │ ├── lending_market.json │ │ │ ├── oracle_program_id.json │ │ │ ├── usdc_mint.json │ │ │ ├── lending_market_owner.json │ │ │ ├── srm_mint.json │ │ │ └── README.md │ ├── cbindgen.toml │ └── Cargo.toml ├── flash_loan_receiver │ ├── src │ │ ├── lib.rs │ │ └── entrypoint.rs │ ├── Xargo.toml │ └── Cargo.toml ├── devnet.json └── cli │ └── Cargo.toml ├── account-compression ├── sdk │ ├── .gitignore │ ├── .npmignore │ ├── src │ │ ├── accounts │ │ │ └── index.ts │ │ ├── types │ │ │ ├── index.ts │ │ │ ├── Path.ts │ │ │ └── Canopy.ts │ │ ├── generated │ │ │ ├── instructions │ │ │ │ └── index.ts │ │ │ ├── types │ │ │ │ ├── index.ts │ │ │ │ ├── ApplicationDataEventV1.ts │ │ │ │ ├── PathNode.ts │ │ │ │ ├── CompressionAccountType.ts │ │ │ │ ├── ChangeLogEventV1.ts │ │ │ │ ├── ConcurrentMerkleTreeHeader.ts │ │ │ │ └── ConcurrentMerkleTreeHeaderDataV1.ts │ │ │ └── index.ts │ │ └── index.ts │ ├── .eslintignore │ ├── prettierrc.yaml │ ├── typedoc.json │ ├── jest.config.js │ ├── tsconfig.json │ ├── .eslintrc.js │ ├── tsconfig.base.json │ ├── .solitarc.js │ └── tests │ │ ├── events │ │ └── applicationData.test.ts │ │ └── merkleTree.test.ts ├── programs │ ├── account-compression │ │ ├── Xargo.toml │ │ ├── src │ │ │ ├── state │ │ │ │ ├── mod.rs │ │ │ │ └── path_node.rs │ │ │ ├── events │ │ │ │ ├── application_data.rs │ │ │ │ └── mod.rs │ │ │ └── zero_copy.rs │ │ ├── README.md │ │ └── Cargo.toml │ └── noop │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ └── lib.rs ├── Cargo.toml └── Anchor.toml ├── docs ├── src │ ├── confidential-token.md │ ├── confidential-token │ │ └── deep-dive │ │ │ ├── zero_proof.pdf │ │ │ ├── pubkey_proof.pdf │ │ │ ├── equality_proof.pdf │ │ │ ├── twisted_elgamal.pdf │ │ │ └── validity_proof.pdf │ ├── token-lending.md │ ├── introduction.md │ ├── theme │ │ └── SearchBar │ │ │ └── styles.css │ ├── shared-memory.md │ └── transfer-hook-interface.md ├── babel.config.js ├── static │ ├── img │ │ ├── favicon.ico │ │ ├── favicon-16x16.png │ │ ├── favicon-32x32.png │ │ ├── apple-touch-icon.png │ │ ├── android-chrome-192x192.png │ │ ├── android-chrome-512x512.png │ │ ├── logo.svg │ │ └── dark-mark-white.inline.svg │ └── css │ │ └── code-block-buttons.css ├── .gitignore ├── publish-docs.sh ├── build.sh ├── README.md └── package.json ├── name-service ├── program │ ├── program-id.md │ ├── Xargo.toml │ ├── src │ │ ├── lib.rs │ │ ├── error.rs │ │ └── entrypoint.rs │ └── Cargo.toml ├── js │ ├── .eslintignore │ ├── tsconfig.root.json │ ├── src │ │ ├── index.ts │ │ └── state.ts │ ├── tsconfig.json │ ├── jest.config.ts │ ├── tsconfig.all.json │ ├── tsconfig.cjs.json │ ├── tsconfig.esm.json │ ├── tsconfig.base.json │ ├── README.md │ └── .eslintrc.json ├── .gitignore └── README.md ├── shared-memory ├── program │ ├── program-id.md │ ├── Xargo.toml │ └── Cargo.toml └── README.md ├── token-upgrade ├── program │ ├── program-id.md │ ├── src │ │ ├── entrypoint.rs │ │ └── error.rs │ └── Cargo.toml ├── README.md └── cli │ └── Cargo.toml ├── examples ├── rust │ ├── logging │ │ ├── Xargo.toml │ │ ├── src │ │ │ ├── lib.rs │ │ │ ├── entrypoint.rs │ │ │ └── processor.rs │ │ ├── Cargo.toml │ │ └── tests │ │ │ └── functional.rs │ ├── sysvar │ │ ├── Xargo.toml │ │ ├── src │ │ │ ├── lib.rs │ │ │ └── entrypoint.rs │ │ ├── Cargo.toml │ │ └── tests │ │ │ └── functional.rs │ ├── custom-heap │ │ ├── Xargo.toml │ │ ├── src │ │ │ ├── lib.rs │ │ │ └── processor.rs │ │ ├── Cargo.toml │ │ └── tests │ │ │ └── functional.rs │ ├── transfer-lamports │ │ ├── Xargo.toml │ │ ├── src │ │ │ ├── lib.rs │ │ │ ├── entrypoint.rs │ │ │ └── processor.rs │ │ └── Cargo.toml │ ├── cross-program-invocation │ │ ├── Xargo.toml │ │ ├── src │ │ │ ├── lib.rs │ │ │ └── entrypoint.rs │ │ └── Cargo.toml │ ├── transfer-tokens │ │ ├── src │ │ │ ├── lib.rs │ │ │ └── entrypoint.rs │ │ └── Cargo.toml │ └── README.md └── c │ ├── makefile │ ├── src │ ├── logging │ │ ├── test_logging.c │ │ └── logging.c │ └── transfer-lamports │ │ └── transfer-lamports.c │ └── README.md ├── libraries ├── math-example │ ├── Xargo.toml │ ├── README.md │ ├── src │ │ ├── lib.rs │ │ ├── entrypoint.rs │ │ └── error.rs │ └── Cargo.toml ├── math │ ├── src │ │ ├── lib.rs │ │ └── uint.rs │ ├── README.md │ └── Cargo.toml ├── README.md ├── concurrent-merkle-tree │ ├── src │ │ ├── log.rs │ │ ├── path.rs │ │ ├── lib.rs │ │ └── hash.rs │ └── Cargo.toml └── merkle-tree-reference │ └── Cargo.toml ├── binary-oracle-pair ├── program │ ├── Xargo.toml │ ├── src │ │ ├── lib.rs │ │ └── entrypoint.rs │ └── Cargo.toml └── README.md ├── managed-token ├── program │ ├── build.sh │ └── Cargo.toml ├── sdk │ ├── src │ │ └── generated │ │ │ ├── instructions │ │ │ └── index.ts │ │ │ └── index.ts │ ├── package.json │ └── .solitarc.js └── README.md ├── rustfmt.toml ├── record └── README.md ├── .prettierignore ├── slashing └── README.md ├── .eslintrc.js ├── stake-pool └── README.md ├── single-pool └── README.md ├── token-group └── README.md ├── feature-proposal └── README.md ├── token-metadata └── README.md ├── instruction-padding └── README.md ├── ci ├── js-test-token-lending.sh ├── install-build-deps.sh ├── js-test-token-swap.sh ├── install-program-deps.sh ├── js-test-name-service.sh ├── js-test-account-compression.sh ├── read-cargo-variable.sh ├── affects.sh ├── anchor-build.sh ├── install-anchor.sh ├── solana-version.sh ├── warning │ └── purge-ubuntu-runner.sh ├── cargo-build-test.sh ├── cargo-test-sbf.sh └── do-audit.sh ├── .prettierrc ├── associated-token-account └── README.md ├── .gitignore ├── cargo-nightly ├── token-collection ├── program │ ├── src │ │ ├── lib.rs │ │ └── entrypoint.rs │ └── Cargo.toml └── README.md ├── .github ├── workflows │ ├── label-actions.yml │ └── spl_action.yml ├── dependabot.yml └── label-actions.yml ├── pnpm-workspace.yaml ├── stateless-asks ├── program │ ├── src │ │ ├── lib.rs │ │ ├── entrypoint.rs │ │ └── error.rs │ └── Cargo.toml └── README.md ├── cbindgen.sh ├── token └── README.md ├── Anchor.toml ├── token-wrap └── program │ ├── src │ ├── entrypoint.rs │ ├── processor.rs │ └── state.rs │ └── Cargo.toml ├── memo └── README.md ├── turbo.json ├── SECURITY.md └── package.json /utils/cgen/src/main: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /binary-option/client/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /token-swap/js/.eslintignore: -------------------------------------------------------------------------------- 1 | /lib 2 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | enable-pre-post-scripts=true 2 | -------------------------------------------------------------------------------- /governance/program/tests/fixtures/.gitignore: -------------------------------------------------------------------------------- 1 | !*.so -------------------------------------------------------------------------------- /token-swap/js/.gitignore: -------------------------------------------------------------------------------- 1 | test-ledger/ 2 | lib/ 3 | -------------------------------------------------------------------------------- /rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "1.81.0" 3 | -------------------------------------------------------------------------------- /governance/tools/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod account; 2 | pub mod error; 3 | -------------------------------------------------------------------------------- /token-lending/js/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | 3 | docs 4 | lib 5 | -------------------------------------------------------------------------------- /token-lending/js/src/util/index.ts: -------------------------------------------------------------------------------- 1 | export * from './layout'; 2 | -------------------------------------------------------------------------------- /account-compression/sdk/.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | doc/ 3 | test-ledger/ 4 | -------------------------------------------------------------------------------- /docs/src/confidential-token.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Introduction 3 | --- 4 | -------------------------------------------------------------------------------- /account-compression/sdk/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | test-ledger/ 3 | tests/ 4 | -------------------------------------------------------------------------------- /binary-option/program/program_id.md: -------------------------------------------------------------------------------- 1 | betw959P4WToez4DkuXwNsJszqbpe3HuY56AcG5yevx 2 | -------------------------------------------------------------------------------- /name-service/program/program-id.md: -------------------------------------------------------------------------------- 1 | namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX 2 | -------------------------------------------------------------------------------- /shared-memory/program/program-id.md: -------------------------------------------------------------------------------- 1 | shmem4EWT2sPdVGvTZCzXXRAURL9G5vpPxNwSeKhHUL 2 | -------------------------------------------------------------------------------- /token-lending/js/.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | 3 | docs 4 | lib 5 | types 6 | -------------------------------------------------------------------------------- /token-lending/program/program-id.md: -------------------------------------------------------------------------------- 1 | LendZqTs7gn5CTSJU1jWKhKuVpjJGom45nnwPb2AMTi 2 | -------------------------------------------------------------------------------- /token-swap/program/program-id.md: -------------------------------------------------------------------------------- 1 | SwapsVeCiPHMUAtzQWZw7RjsKjgCjhwU55QGu4U1Szw 2 | -------------------------------------------------------------------------------- /token-upgrade/program/program-id.md: -------------------------------------------------------------------------------- 1 | TkupDoNseygccBCjSsrSpMccjwHfTYwcrjpnDSrFDhC 2 | -------------------------------------------------------------------------------- /name-service/js/.eslintignore: -------------------------------------------------------------------------------- 1 | docs 2 | lib 3 | test-ledger 4 | 5 | package-lock.json 6 | -------------------------------------------------------------------------------- /token-lending/flash_loan_receiver/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod entrypoint; 2 | pub mod processor; 3 | -------------------------------------------------------------------------------- /account-compression/sdk/src/accounts/index.ts: -------------------------------------------------------------------------------- 1 | export * from './ConcurrentMerkleTreeAccount'; 2 | -------------------------------------------------------------------------------- /examples/rust/logging/Xargo.toml: -------------------------------------------------------------------------------- 1 | [target.bpfel-unknown-unknown.dependencies.std] 2 | features = [] -------------------------------------------------------------------------------- /examples/rust/sysvar/Xargo.toml: -------------------------------------------------------------------------------- 1 | [target.bpfel-unknown-unknown.dependencies.std] 2 | features = [] -------------------------------------------------------------------------------- /governance/addin-api/README.md: -------------------------------------------------------------------------------- 1 | # Governance Addin Api 2 | 3 | Governance Addin Api interface 4 | -------------------------------------------------------------------------------- /governance/program/Xargo.toml: -------------------------------------------------------------------------------- 1 | [target.bpfel-unknown-unknown.dependencies.std] 2 | features = [] -------------------------------------------------------------------------------- /libraries/math-example/Xargo.toml: -------------------------------------------------------------------------------- 1 | [target.bpfel-unknown-unknown.dependencies.std] 2 | features = [] -------------------------------------------------------------------------------- /name-service/program/Xargo.toml: -------------------------------------------------------------------------------- 1 | [target.bpfel-unknown-unknown.dependencies.std] 2 | features = [] -------------------------------------------------------------------------------- /shared-memory/program/Xargo.toml: -------------------------------------------------------------------------------- 1 | [target.bpfel-unknown-unknown.dependencies.std] 2 | features = [] -------------------------------------------------------------------------------- /token-lending/program/Xargo.toml: -------------------------------------------------------------------------------- 1 | [target.bpfel-unknown-unknown.dependencies.std] 2 | features = [] -------------------------------------------------------------------------------- /token-swap/program/Xargo.toml: -------------------------------------------------------------------------------- 1 | [target.bpfel-unknown-unknown.dependencies.std] 2 | features = [] -------------------------------------------------------------------------------- /binary-oracle-pair/program/Xargo.toml: -------------------------------------------------------------------------------- 1 | [target.bpfel-unknown-unknown.dependencies.std] 2 | features = [] -------------------------------------------------------------------------------- /examples/rust/custom-heap/Xargo.toml: -------------------------------------------------------------------------------- 1 | [target.bpfel-unknown-unknown.dependencies.std] 2 | features = [] -------------------------------------------------------------------------------- /governance/chat/program/Xargo.toml: -------------------------------------------------------------------------------- 1 | [target.bpfel-unknown-unknown.dependencies.std] 2 | features = [] -------------------------------------------------------------------------------- /managed-token/program/build.sh: -------------------------------------------------------------------------------- 1 | cargo build-bpf 2 | cd ../sdk 3 | yarn 4 | yarn solita 5 | cd - 6 | 7 | -------------------------------------------------------------------------------- /examples/rust/transfer-lamports/Xargo.toml: -------------------------------------------------------------------------------- 1 | [target.bpfel-unknown-unknown.dependencies.std] 2 | features = [] -------------------------------------------------------------------------------- /governance/addin-mock/program/Xargo.toml: -------------------------------------------------------------------------------- 1 | [target.bpfel-unknown-unknown.dependencies.std] 2 | features = [] -------------------------------------------------------------------------------- /account-compression/sdk/.eslintignore: -------------------------------------------------------------------------------- 1 | /.eslintrc.js 2 | /.solitarc.js 3 | /jest.config.js 4 | doc 5 | dist 6 | -------------------------------------------------------------------------------- /token-lending/flash_loan_receiver/Xargo.toml: -------------------------------------------------------------------------------- 1 | [target.bpfel-unknown-unknown.dependencies.std] 2 | features = [] -------------------------------------------------------------------------------- /examples/rust/cross-program-invocation/Xargo.toml: -------------------------------------------------------------------------------- 1 | [target.bpfel-unknown-unknown.dependencies.std] 2 | features = [] -------------------------------------------------------------------------------- /docs/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [require.resolve("@docusaurus/core/lib/babel/preset")], 3 | }; 4 | -------------------------------------------------------------------------------- /docs/static/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/docs/static/img/favicon.ico -------------------------------------------------------------------------------- /governance/addin-api/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Governance add-ins interfaces 2 | pub mod max_voter_weight; 3 | pub mod voter_weight; 4 | -------------------------------------------------------------------------------- /token-lending/js/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './constants'; 2 | export * from './instructions'; 3 | export * from './state'; 4 | -------------------------------------------------------------------------------- /account-compression/programs/account-compression/Xargo.toml: -------------------------------------------------------------------------------- 1 | [target.bpfel-unknown-unknown.dependencies.std] 2 | features = [] 3 | -------------------------------------------------------------------------------- /examples/c/makefile: -------------------------------------------------------------------------------- 1 | OUT_DIR := ../../target/deploy 2 | include ~/.local/share/solana/install/active_release/bin/sdk/sbf/c/sbf.mk 3 | -------------------------------------------------------------------------------- /governance/program/src/addins/mod.rs: -------------------------------------------------------------------------------- 1 | //! Governance add-ins interfaces 2 | pub mod max_voter_weight; 3 | pub mod voter_weight; 4 | -------------------------------------------------------------------------------- /token-lending/program/proptest-regressions/state/reserve.txt: -------------------------------------------------------------------------------- 1 | cc 39c6d681e691839313426bb0801cf3f46d0befb69b568a28cf6d8e752d74526b 2 | -------------------------------------------------------------------------------- /token-swap/program/proptest-regressions/curve/constant_price.txt: -------------------------------------------------------------------------------- 1 | cc 2594e0e0a7f4471f4929439462cb19c5b187294cc0ede01a155051179eb99bdd 2 | -------------------------------------------------------------------------------- /docs/static/img/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/docs/static/img/favicon-16x16.png -------------------------------------------------------------------------------- /docs/static/img/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/docs/static/img/favicon-32x32.png -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | comment_width = 80 2 | edition = "2021" 3 | group_imports = "One" 4 | imports_granularity = "One" 5 | wrap_comments = true 6 | -------------------------------------------------------------------------------- /docs/static/img/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/docs/static/img/apple-touch-icon.png -------------------------------------------------------------------------------- /name-service/js/tsconfig.root.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "compilerOptions": { 4 | "composite": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /token-swap/js/tsconfig.root.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "compilerOptions": { 4 | "composite": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /record/README.md: -------------------------------------------------------------------------------- 1 | NOTE: The record program and clients are now maintained at 2 | [solana-program/record](https://github.com/solana-program/record). 3 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | docs 2 | lib 3 | test-ledger 4 | node_modules 5 | dist 6 | generated 7 | .mypy_cache 8 | *.yml 9 | *.yaml 10 | *.md 11 | *.json 12 | -------------------------------------------------------------------------------- /account-compression/Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "programs/account-compression", 4 | "programs/noop" 5 | ] 6 | 7 | resolver = "2" 8 | -------------------------------------------------------------------------------- /docs/static/img/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/docs/static/img/android-chrome-192x192.png -------------------------------------------------------------------------------- /docs/static/img/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/docs/static/img/android-chrome-512x512.png -------------------------------------------------------------------------------- /libraries/math/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Math utilities. 2 | 3 | pub mod approximations; 4 | pub mod checked_ceil_div; 5 | pub mod precise_number; 6 | pub mod uint; 7 | -------------------------------------------------------------------------------- /slashing/README.md: -------------------------------------------------------------------------------- 1 | NOTE: The slashing program and clients are now maintained at 2 | [solana-program/slashing](https://github.com/solana-program/slashing). 3 | -------------------------------------------------------------------------------- /token-swap/js/src/util/sleep.ts: -------------------------------------------------------------------------------- 1 | export function sleep(ms: number): Promise { 2 | return new Promise(resolve => setTimeout(resolve, ms)); 3 | } 4 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['turbo', '@solana/eslint-config-solana', '@solana/eslint-config-solana/jest'], 3 | root: true, 4 | }; 5 | -------------------------------------------------------------------------------- /account-compression/sdk/prettierrc.yaml: -------------------------------------------------------------------------------- 1 | arrowParens: "avoid" 2 | bracketSpacing: false 3 | semi: true 4 | singleQuote: true 5 | tabWidth: 2 6 | trailingComma: "all" -------------------------------------------------------------------------------- /governance/resources/governance-accounts.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/governance/resources/governance-accounts.jpg -------------------------------------------------------------------------------- /governance/resources/governance-workflow.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/governance/resources/governance-workflow.jpg -------------------------------------------------------------------------------- /token-swap/js/.prettierrc.yaml: -------------------------------------------------------------------------------- 1 | arrowParens: "avoid" 2 | bracketSpacing: false 3 | semi: true 4 | singleQuote: true 5 | tabWidth: 2 6 | trailingComma: "all" 7 | -------------------------------------------------------------------------------- /governance/test-sdk/README.md: -------------------------------------------------------------------------------- 1 | # Governance Test SDK 2 | 3 | Governance test SDK is a set of test utility functions used across the governance programs ecosystem 4 | -------------------------------------------------------------------------------- /governance/tools/README.md: -------------------------------------------------------------------------------- 1 | # Governance Tool 2 | 3 | Governance tools is a set of general purpose utility functions used across the governance programs ecosystem 4 | -------------------------------------------------------------------------------- /stake-pool/README.md: -------------------------------------------------------------------------------- 1 | NOTE: The stake-pool program and clients are now maintained at 2 | [solana-program/stake-pool](https://github.com/solana-program/stake-pool). 3 | -------------------------------------------------------------------------------- /examples/rust/custom-heap/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! A program demonstrating implementing a custom heap 2 | #![deny(missing_docs)] 3 | 4 | mod entrypoint; 5 | pub mod processor; 6 | -------------------------------------------------------------------------------- /single-pool/README.md: -------------------------------------------------------------------------------- 1 | NOTE: The single-pool program and clients are now maintained at 2 | [solana-program/single-pool](https://github.com/solana-program/single-pool). 3 | -------------------------------------------------------------------------------- /token-lending/js/src/state/index.ts: -------------------------------------------------------------------------------- 1 | export * from './lastUpdate'; 2 | export * from './lendingMarket'; 3 | export * from './reserve'; 4 | export * from './obligation'; 5 | -------------------------------------------------------------------------------- /docs/src/confidential-token/deep-dive/zero_proof.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/docs/src/confidential-token/deep-dive/zero_proof.pdf -------------------------------------------------------------------------------- /examples/rust/logging/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! A program demonstrating logging 2 | #![deny(missing_docs)] 3 | #![forbid(unsafe_code)] 4 | 5 | mod entrypoint; 6 | pub mod processor; 7 | -------------------------------------------------------------------------------- /token-lending/program/src/math/mod.rs: -------------------------------------------------------------------------------- 1 | //! Math for preserving precision 2 | 3 | mod common; 4 | mod decimal; 5 | mod rate; 6 | 7 | pub use {common::*, decimal::*, rate::*}; 8 | -------------------------------------------------------------------------------- /docs/src/confidential-token/deep-dive/pubkey_proof.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/docs/src/confidential-token/deep-dive/pubkey_proof.pdf -------------------------------------------------------------------------------- /governance/chat/README.md: -------------------------------------------------------------------------------- 1 | # Governance chat 2 | 3 | Governance chat is a program which allows voters to comment on proposals. 4 | All comments are public and stored on chain. 5 | -------------------------------------------------------------------------------- /token-group/README.md: -------------------------------------------------------------------------------- 1 | NOTE: The token-group interface, program, and clients are now maintained at 2 | [solana-program/token-group](https://github.com/solana-program/token-group). 3 | -------------------------------------------------------------------------------- /docs/src/confidential-token/deep-dive/equality_proof.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/docs/src/confidential-token/deep-dive/equality_proof.pdf -------------------------------------------------------------------------------- /docs/src/confidential-token/deep-dive/twisted_elgamal.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/docs/src/confidential-token/deep-dive/twisted_elgamal.pdf -------------------------------------------------------------------------------- /docs/src/confidential-token/deep-dive/validity_proof.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/docs/src/confidential-token/deep-dive/validity_proof.pdf -------------------------------------------------------------------------------- /governance/addin-mock/README.md: -------------------------------------------------------------------------------- 1 | # Governance Addin Mock 2 | 3 | Governance Addin Mock is a skeleton program which is used as a mock to test the governance program with external addins 4 | -------------------------------------------------------------------------------- /name-service/js/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './bindings'; 2 | export * from './instructions'; 3 | export * from './state'; 4 | export * from './utils'; 5 | export * from './twitter'; 6 | -------------------------------------------------------------------------------- /examples/rust/sysvar/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! A program demonstrating the transfer of lamports 2 | #![deny(missing_docs)] 3 | #![forbid(unsafe_code)] 4 | 5 | mod entrypoint; 6 | pub mod processor; 7 | -------------------------------------------------------------------------------- /feature-proposal/README.md: -------------------------------------------------------------------------------- 1 | NOTE: The feature-proposal program and clients are now maintained at 2 | [solana-program/feature-proposal](https://github.com/solana-program/feature-proposal). 3 | -------------------------------------------------------------------------------- /governance/program/src/tools/mod.rs: -------------------------------------------------------------------------------- 1 | //! Utility functions 2 | 3 | pub mod spl_token; 4 | 5 | pub mod bpf_loader_upgradeable; 6 | 7 | pub mod pack; 8 | 9 | pub mod structs; 10 | -------------------------------------------------------------------------------- /token-metadata/README.md: -------------------------------------------------------------------------------- 1 | NOTE: The token-metadat interface, program, and clients are now maintained at 2 | [solana-program/token-metadata](https://github.com/solana-program/token-metadata). 3 | -------------------------------------------------------------------------------- /account-compression/sdk/typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "entryPoints": ["src/index.ts", "src/merkle-tree/index.ts"], 3 | "excludeInternal": true, 4 | "excludePrivate": false, 5 | "out": "doc" 6 | } 7 | -------------------------------------------------------------------------------- /governance/program/tests/fixtures/solana_bpf_rust_upgraded.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/governance/program/tests/fixtures/solana_bpf_rust_upgraded.so -------------------------------------------------------------------------------- /examples/rust/transfer-lamports/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! A program demonstrating the transfer of lamports 2 | #![deny(missing_docs)] 3 | #![forbid(unsafe_code)] 4 | 5 | mod entrypoint; 6 | pub mod processor; 7 | -------------------------------------------------------------------------------- /examples/rust/transfer-tokens/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! A program demonstrating the transfer of lamports 2 | #![deny(missing_docs)] 3 | #![forbid(unsafe_code)] 4 | 5 | mod entrypoint; 6 | pub mod processor; 7 | -------------------------------------------------------------------------------- /governance/program/tests/fixtures/solana_bpf_rust_upgradeable.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/governance/program/tests/fixtures/solana_bpf_rust_upgradeable.so -------------------------------------------------------------------------------- /instruction-padding/README.md: -------------------------------------------------------------------------------- 1 | NOTE: The instruction-padding program and clients are now maintained at 2 | [solana-program/instruction-padding](https://github.com/solana-program/instruction-padding). 3 | -------------------------------------------------------------------------------- /name-service/js/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.all.json", 3 | "include": ["src", "test"], 4 | "compilerOptions": { 5 | "noEmit": true, 6 | "skipLibCheck": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /token-swap/js/.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extension": ["ts"], 3 | "node-option": [ 4 | "experimental-specifier-resolution=node", 5 | "loader=ts-node/esm" 6 | ], 7 | "timeout": 100000 8 | } 9 | -------------------------------------------------------------------------------- /token-swap/js/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.all.json", 3 | "include": ["src", "test"], 4 | "compilerOptions": { 5 | "noEmit": true, 6 | "skipLibCheck": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /token-swap/program/fuzz/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::arithmetic_side_effects)] 2 | pub mod native_account_data; 3 | pub mod native_processor; 4 | pub mod native_token; 5 | pub mod native_token_swap; 6 | -------------------------------------------------------------------------------- /account-compression/sdk/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'ts-jest/presets/default', 3 | testEnvironment: 'node', 4 | testTimeout: 100000, 5 | resolver: 'ts-jest-resolver', 6 | }; 7 | -------------------------------------------------------------------------------- /examples/rust/cross-program-invocation/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Rust example demonstrating invoking another program 2 | #![deny(missing_docs)] 3 | #![forbid(unsafe_code)] 4 | 5 | mod entrypoint; 6 | pub mod processor; 7 | -------------------------------------------------------------------------------- /name-service/js/jest.config.ts: -------------------------------------------------------------------------------- 1 | import type { JestConfigWithTsJest } from 'ts-jest'; 2 | 3 | const jestConfig: JestConfigWithTsJest = { 4 | preset: 'ts-jest', 5 | }; 6 | 7 | export default jestConfig; 8 | -------------------------------------------------------------------------------- /ci/js-test-token-lending.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | cd "$(dirname "$0")/.." 5 | 6 | set -x 7 | pnpm install 8 | pnpm format 9 | pnpm build 10 | 11 | cd token-lending/js 12 | pnpm lint 13 | -------------------------------------------------------------------------------- /token-swap/program/src/curve/mod.rs: -------------------------------------------------------------------------------- 1 | //! Curve invariant implementations 2 | 3 | pub mod base; 4 | pub mod calculator; 5 | pub mod constant_price; 6 | pub mod constant_product; 7 | pub mod fees; 8 | pub mod offset; 9 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": true, 3 | "singleQuote": true, 4 | "trailingComma": "es5", 5 | "useTabs": false, 6 | "tabWidth": 4, 7 | "arrowParens": "always", 8 | "printWidth": 80 9 | } 10 | -------------------------------------------------------------------------------- /associated-token-account/README.md: -------------------------------------------------------------------------------- 1 | NOTE: The associated-token-account program and clients are now maintained at 2 | [solana-program/associated-token-account](https://github.com/solana-program/associated-token-account). 3 | -------------------------------------------------------------------------------- /libraries/math/README.md: -------------------------------------------------------------------------------- 1 | # Math 2 | 3 | Library with utilities for on-chain math. 4 | 5 | ## Audit 6 | 7 | The repository [README](https://github.com/solana-labs/solana-program-library#audits) 8 | contains information about program audits. 9 | -------------------------------------------------------------------------------- /token-lending/program/tests/fixtures/3Mnn2fX6rQyUsyELYms1sBJyChWofzSNRoqYzvgMVz5E.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/token-lending/program/tests/fixtures/3Mnn2fX6rQyUsyELYms1sBJyChWofzSNRoqYzvgMVz5E.bin -------------------------------------------------------------------------------- /token-lending/program/tests/fixtures/6MEwdxe4g1NeAF9u6KDG14anJpFsVEa2cvr5H6iriFZ8.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/token-lending/program/tests/fixtures/6MEwdxe4g1NeAF9u6KDG14anJpFsVEa2cvr5H6iriFZ8.bin -------------------------------------------------------------------------------- /token-lending/program/tests/fixtures/992moaMQKs32GKZ9dxi8keyM2bUmbrwBZpK4p2K6X5Vs.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/token-lending/program/tests/fixtures/992moaMQKs32GKZ9dxi8keyM2bUmbrwBZpK4p2K6X5Vs.bin -------------------------------------------------------------------------------- /token-lending/program/tests/fixtures/J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardcoding-1992/solana-program-library/HEAD/token-lending/program/tests/fixtures/J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix.bin -------------------------------------------------------------------------------- /token-swap/js/tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "./tsconfig.cjs.json" 6 | }, 7 | { 8 | "path": "./tsconfig.esm.json" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /utils/cgen/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cgen" 3 | version = "0.1.0" 4 | authors = ["Solana Labs Maintainers "] 5 | publish = false 6 | edition = "2021" 7 | 8 | [dependencies] 9 | cbindgen = "=0.16.0" 10 | -------------------------------------------------------------------------------- /ci/install-build-deps.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ex 4 | 5 | sudo apt update 6 | sudo apt install libudev-dev -y 7 | sudo apt install binutils-dev -y 8 | sudo apt install libunwind-dev -y 9 | sudo apt install protobuf-compiler -y 10 | -------------------------------------------------------------------------------- /name-service/js/tsconfig.all.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.root.json", 3 | "references": [ 4 | { 5 | "path": "./tsconfig.cjs.json" 6 | }, 7 | { 8 | "path": "./tsconfig.esm.json" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /token-lending/devnet.json: -------------------------------------------------------------------------------- 1 | [130,246,120,89,231,133,43,33,49,205,101,1,213,248,157,83,95,80,96,30,168,34,211,201,73,192,238,78,197,58,36,166,127,241,163,107,200,196,254,160,100,74,111,93,214,194,19,244,98,55,78,136,39,63,215,185,110,144,39,169,181,180,241,236] -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .env 3 | .vscode 4 | bin 5 | config.json 6 | node_modules 7 | ./package-lock.json 8 | hfuzz_target 9 | hfuzz_workspace 10 | **/*.so 11 | **/.DS_Store 12 | test-ledger 13 | docker-target 14 | .idea 15 | .coderrect 16 | .turbo 17 | -------------------------------------------------------------------------------- /account-compression/programs/account-compression/src/state/mod.rs: -------------------------------------------------------------------------------- 1 | //! State needed to manipulate SPL ConcurrentMerkleTrees 2 | mod concurrent_merkle_tree_header; 3 | mod path_node; 4 | 5 | pub use concurrent_merkle_tree_header::*; 6 | pub use path_node::PathNode; 7 | -------------------------------------------------------------------------------- /cargo-nightly: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | here=$(dirname "$0") 4 | source "${here}"/ci/rust-version.sh nightly 5 | # shellcheck disable=SC2054 # rust_nightly is sourced from rust-version.sh 6 | toolchain="$rust_nightly" 7 | set -x 8 | exec cargo "+${toolchain}" "${@}" -------------------------------------------------------------------------------- /name-service/js/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/cjs", 6 | "target": "ES2016", 7 | "module": "CommonJS", 8 | "sourceMap": true 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /token-swap/js/tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/cjs", 6 | "target": "ES2016", 7 | "module": "CommonJS", 8 | "sourceMap": true 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /ci/js-test-token-swap.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ex 4 | cd "$(dirname "$0")/.." 5 | source ./ci/solana-version.sh install 6 | 7 | pnpm install 8 | pnpm format 9 | pnpm build 10 | 11 | cd token-swap/js 12 | pnpm build:program 13 | pnpm lint 14 | pnpm test 15 | -------------------------------------------------------------------------------- /token-lending/program/tests/fixtures/lending_market.json: -------------------------------------------------------------------------------- 1 | [203,123,29,107,44,194,199,159,73,87,44,135,219,143,105,205,50,46,221,112,57,204,38,172,131,203,182,189,62,76,57,3,81,199,160,36,169,53,203,113,246,98,0,64,242,171,158,252,244,178,125,153,52,75,148,210,143,30,142,191,135,52,242,25] -------------------------------------------------------------------------------- /token-lending/program/tests/fixtures/oracle_program_id.json: -------------------------------------------------------------------------------- 1 | [34,165,56,243,236,153,203,167,72,136,131,212,217,45,33,184,51,188,81,218,245,67,252,172,250,244,94,239,138,13,166,47,132,99,44,63,242,187,236,116,168,172,11,28,66,228,151,55,166,71,44,51,64,111,49,62,187,222,61,97,138,87,87,216] -------------------------------------------------------------------------------- /token-lending/program/tests/fixtures/usdc_mint.json: -------------------------------------------------------------------------------- 1 | [54,145,24,15,126,194,110,22,253,254,251,8,199,129,146,68,215,154,174,126,138,116,37,4,117,86,129,129,89,175,244,126,148,200,124,73,201,204,74,241,165,229,204,237,90,194,169,78,162,215,149,186,235,67,211,112,2,102,233,153,22,216,200,163] -------------------------------------------------------------------------------- /ci/install-program-deps.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | source ci/rust-version.sh stable 6 | source ci/solana-version.sh install 7 | 8 | set -x 9 | 10 | cargo --version 11 | cargo install rustfilt || true 12 | 13 | cargo +"$rust_stable" build-sbf --version 14 | -------------------------------------------------------------------------------- /token-lending/program/tests/fixtures/lending_market_owner.json: -------------------------------------------------------------------------------- 1 | [237,94,30,208,149,9,211,113,89,130,186,215,210,240,152,201,225,9,164,38,6,66,245,251,44,121,38,3,210,200,217,24,114,133,232,227,86,67,182,15,253,36,214,87,201,19,105,189,111,157,211,250,12,167,115,73,3,116,254,73,245,75,104,105] -------------------------------------------------------------------------------- /token-lending/program/tests/fixtures/srm_mint.json: -------------------------------------------------------------------------------- 1 | [58,208,121,211,147,191,252,194,27,112,242,181,234,8,178,221,146,159,34,49,159,191,43,185,225,149,79,50,132,251,191,160,190,232,3,127,76,66,126,248,122,226,243,163,63,22,80,127,18,193,145,126,162,197,113,216,136,135,137,237,47,207,231,220] -------------------------------------------------------------------------------- /ci/js-test-name-service.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | cd "$(dirname "$0")/.." 5 | source ./ci/solana-version.sh install 6 | 7 | set -x 8 | pnpm install 9 | pnpm format 10 | 11 | cd name-service/js 12 | pnpm lint 13 | pnpm build:program 14 | pnpm build 15 | pnpm test 16 | -------------------------------------------------------------------------------- /libraries/math-example/README.md: -------------------------------------------------------------------------------- 1 | # Math 2 | 3 | Program wrapper around the spl-math-utils crate. The program exists for testing purposes. 4 | 5 | ## Audit 6 | 7 | The repository [README](https://github.com/solana-labs/solana-program-library#audits) 8 | contains information about program audits. 9 | -------------------------------------------------------------------------------- /token-collection/program/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Crate defining the Token Collection program implementing the 2 | //! SPL Token Group interface. 3 | 4 | #![deny(missing_docs)] 5 | #![forbid(unsafe_code)] 6 | 7 | pub mod processor; 8 | 9 | #[cfg(not(feature = "no-entrypoint"))] 10 | mod entrypoint; 11 | -------------------------------------------------------------------------------- /managed-token/sdk/src/generated/instructions/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Approve' 2 | export * from './Burn' 3 | export * from './CloseAccount' 4 | export * from './InitializeAccount' 5 | export * from './InitializeMint' 6 | export * from './MintTo' 7 | export * from './Revoke' 8 | export * from './Transfer' 9 | -------------------------------------------------------------------------------- /.github/workflows/label-actions.yml: -------------------------------------------------------------------------------- 1 | name: "Issue Label Actions" 2 | 3 | on: 4 | issues: 5 | types: [labeled, unlabeled] 6 | 7 | permissions: 8 | contents: read 9 | issues: write 10 | 11 | jobs: 12 | action: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: dessant/label-actions@v2 16 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - "account-compression/sdk" 3 | - "libraries/type-length-value/js" 4 | - "name-service/js" 5 | - "single-pool/js/packages/*" 6 | - "stake-pool/js" 7 | - "token/js" 8 | - "token-group/js" 9 | - "token-lending/js" 10 | - "token-metadata/js" 11 | - "token-swap/js" 12 | -------------------------------------------------------------------------------- /governance/test-sdk/src/cookies.rs: -------------------------------------------------------------------------------- 1 | use {solana_program::pubkey::Pubkey, solana_sdk::account::Account}; 2 | 3 | #[derive(Debug)] 4 | pub struct TokenAccountCookie { 5 | pub address: Pubkey, 6 | } 7 | 8 | #[derive(Debug)] 9 | pub struct WalletCookie { 10 | pub address: Pubkey, 11 | pub account: Account, 12 | } 13 | -------------------------------------------------------------------------------- /ci/js-test-account-compression.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | cd "$(dirname "$0")/.." 5 | export SOLANA_VERSION="v2.0.14" 6 | source ./ci/solana-version.sh install 7 | 8 | set -x 9 | pnpm install 10 | pnpm format 11 | cd account-compression/sdk 12 | pnpm build 13 | pnpm build:program 14 | pnpm lint 15 | pnpm test 16 | -------------------------------------------------------------------------------- /stateless-asks/program/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod error; 2 | pub mod instruction; 3 | pub mod processor; 4 | pub mod validation_utils; 5 | 6 | #[cfg(not(feature = "no-entrypoint"))] 7 | mod entrypoint; 8 | 9 | // Export current sdk types for downstream users building with a different sdk 10 | // version 11 | pub use solana_program; 12 | -------------------------------------------------------------------------------- /token-upgrade/README.md: -------------------------------------------------------------------------------- 1 | # Token Upgrade 2 | 3 | The Token Upgrade Program provides a stateless protocol for permanently converting 4 | tokens from one mint to another. 5 | 6 | ## Audit 7 | 8 | The repository [README](https://github.com/solana-labs/solana-program-library#audits) 9 | contains information about program audits. 10 | -------------------------------------------------------------------------------- /docs/src/token-lending.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Token-Lending Program 3 | --- 4 | 5 | A lending protocol for the Token program on the Solana blockchain inspired by 6 | Aave and Compound. 7 | 8 | ## Audit 9 | 10 | The repository [README](https://github.com/solana-labs/solana-program-library#audits) 11 | contains information about program audits. 12 | -------------------------------------------------------------------------------- /token-lending/js/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "env": { 4 | "node": true, 5 | "browser": true 6 | }, 7 | "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"], 8 | "parser": "@typescript-eslint/parser", 9 | "plugins": ["@typescript-eslint", "prettier"], 10 | "rules": {} 11 | } 12 | -------------------------------------------------------------------------------- /token-lending/js/src/util/layout.ts: -------------------------------------------------------------------------------- 1 | import { AccountInfo, PublicKey } from '@solana/web3.js'; 2 | 3 | export type Parser = ( 4 | pubkey: PublicKey, 5 | info: AccountInfo, 6 | ) => 7 | | { 8 | pubkey: PublicKey; 9 | info: AccountInfo; 10 | data: T; 11 | } 12 | | undefined; 13 | -------------------------------------------------------------------------------- /cbindgen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cd "$(dirname "$0")" 4 | set -x 5 | 6 | # Cargo.lock can cause older spl-token bindings to be generated? Move it out of 7 | # the way... 8 | mv -f Cargo.lock Cargo.lock.org 9 | 10 | cargo run --manifest-path=utils/cgen/Cargo.toml 11 | exitcode=$? 12 | 13 | mv -f Cargo.lock.org Cargo.lock 14 | 15 | exit $exitcode 16 | -------------------------------------------------------------------------------- /name-service/js/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/esm", 6 | "declarationDir": "lib/types", 7 | "target": "ES2020", 8 | "module": "ES2020", 9 | "sourceMap": true, 10 | "declaration": true, 11 | "declarationMap": true 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /token-swap/js/tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "include": ["src"], 4 | "compilerOptions": { 5 | "outDir": "lib/esm", 6 | "declarationDir": "lib/types", 7 | "target": "ES2020", 8 | "module": "ES2020", 9 | "sourceMap": true, 10 | "declaration": true, 11 | "declarationMap": true 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /managed-token/sdk/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "managed-token", 3 | "version": "1.0.0", 4 | "description": "SDK for managed-token", 5 | "main": "index.ts", 6 | "license": "MIT", 7 | "dependencies": { 8 | "@metaplex-foundation/rustbin": "^0.3.1", 9 | "@metaplex-foundation/solita": "^0.12.2", 10 | "@solana/spl-token": "0.1.8" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | /node_modules 3 | 4 | # Production 5 | /build 6 | 7 | # Generated files 8 | .docusaurus 9 | .cache-loader 10 | .vercel 11 | vercel.json 12 | 13 | # Misc 14 | .DS_Store 15 | .env.local 16 | .env.development.local 17 | .env.test.local 18 | .env.production.local 19 | 20 | npm-debug.log* 21 | yarn-debug.log* 22 | yarn-error.log* 23 | -------------------------------------------------------------------------------- /token-lending/js/src/state/lastUpdate.ts: -------------------------------------------------------------------------------- 1 | import { struct } from '@solana/buffer-layout'; 2 | import { bool, u64 } from '@solana/buffer-layout-utils'; 3 | 4 | export interface LastUpdate { 5 | slot: bigint; 6 | stale: boolean; 7 | } 8 | 9 | /** @internal */ 10 | export const LastUpdateLayout = struct([u64('slot'), bool('stale')], 'lastUpdate'); 11 | -------------------------------------------------------------------------------- /account-compression/sdk/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "include": ["src", "tests"], 4 | "compilerOptions": { 5 | "outDir": "dist/cjs/", 6 | "declarationDir": "dist/types", 7 | "sourceMap": true, 8 | "declaration": true, 9 | "declarationMap": true, 10 | "target": "ES2016", 11 | "module": "CommonJS" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /token-swap/js/tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": [], 3 | "compilerOptions": { 4 | "target": "ESNext", 5 | "module": "ESNext", 6 | "moduleResolution": "Node", 7 | "esModuleInterop": true, 8 | "isolatedModules": true, 9 | "noEmitOnError": true, 10 | "resolveJsonModule": true, 11 | "strict": true, 12 | "stripInternal": true 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /governance/addin-mock/program/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![deny(missing_docs)] 2 | //! Governance VoterWeight Addin program 3 | 4 | pub mod entrypoint; 5 | pub mod error; 6 | pub mod instruction; 7 | pub mod processor; 8 | //pub mod state; 9 | // pub mod tools; 10 | 11 | // Export current sdk types for downstream users building with a different sdk 12 | // version 13 | pub use solana_program; 14 | -------------------------------------------------------------------------------- /name-service/js/tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": [], 3 | "compilerOptions": { 4 | "target": "ESNext", 5 | "module": "ESNext", 6 | "moduleResolution": "Node", 7 | "esModuleInterop": true, 8 | "isolatedModules": true, 9 | "noEmitOnError": true, 10 | "resolveJsonModule": true, 11 | "strict": true, 12 | "stripInternal": true 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /token-swap/program/cbindgen.toml: -------------------------------------------------------------------------------- 1 | language = "C" 2 | header = "/* Autogenerated SPL Token-Swap program C Bindings */" 3 | pragma_once = true 4 | cpp_compat = true 5 | line_length = 80 6 | tab_width = 4 7 | style = "both" 8 | 9 | [export] 10 | prefix = "TokenSwap_" 11 | include = ["SwapInstruction", "State"] 12 | 13 | [parse] 14 | parse_deps = true 15 | include = ["solana-sdk"] 16 | -------------------------------------------------------------------------------- /governance/chat/program/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::arithmetic_side_effects)] 2 | #![deny(missing_docs)] 3 | //! Governance Chat program 4 | 5 | pub mod entrypoint; 6 | pub mod error; 7 | pub mod instruction; 8 | pub mod processor; 9 | pub mod state; 10 | 11 | // Export current sdk types for downstream users building with a different sdk 12 | // version 13 | pub use solana_program; 14 | -------------------------------------------------------------------------------- /token-lending/program/cbindgen.toml: -------------------------------------------------------------------------------- 1 | language = "C" 2 | header = "/* Autogenerated SPL Token-Lending program C Bindings */" 3 | pragma_once = true 4 | cpp_compat = true 5 | line_length = 80 6 | tab_width = 4 7 | style = "both" 8 | 9 | [export] 10 | prefix = "TokenLending_" 11 | include = ["LendingInstruction", "State"] 12 | 13 | [parse] 14 | parse_deps = true 15 | include = ["solana-sdk"] 16 | -------------------------------------------------------------------------------- /account-compression/programs/account-compression/src/events/application_data.rs: -------------------------------------------------------------------------------- 1 | use anchor_lang::prelude::*; 2 | 3 | #[derive(AnchorDeserialize, AnchorSerialize)] 4 | #[repr(C)] 5 | pub enum ApplicationDataEvent { 6 | V1(ApplicationDataEventV1), 7 | } 8 | 9 | #[derive(AnchorDeserialize, AnchorSerialize)] 10 | pub struct ApplicationDataEventV1 { 11 | pub application_data: Vec, 12 | } 13 | -------------------------------------------------------------------------------- /account-compression/sdk/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['turbo', '@solana/eslint-config-solana', '@solana/eslint-config-solana/jest'], 3 | overrides: [ 4 | { 5 | files: ['tests/**.ts'], 6 | rules: { 7 | 'no-empty': ['error', { allowEmptyCatch: true }], 8 | }, 9 | }, 10 | ], 11 | root: true, 12 | }; 13 | -------------------------------------------------------------------------------- /name-service/program/src/lib.rs: -------------------------------------------------------------------------------- 1 | #[cfg(not(feature = "no-entrypoint"))] 2 | pub mod entrypoint; 3 | pub mod error; 4 | pub mod instruction; 5 | pub mod processor; 6 | pub mod state; 7 | 8 | // Export current sdk types for downstream users building with a different sdk 9 | // version 10 | pub use solana_program; 11 | 12 | solana_program::declare_id!("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX"); 13 | -------------------------------------------------------------------------------- /ci/read-cargo-variable.sh: -------------------------------------------------------------------------------- 1 | # source this file 2 | 3 | readCargoVariable() { 4 | declare variable="$1" 5 | declare Cargo_toml="$2" 6 | 7 | while read -r name equals value _; do 8 | if [[ $name = "$variable" && $equals = = ]]; then 9 | echo "${value//\"/}" 10 | return 11 | fi 12 | done < <(cat "$Cargo_toml") 13 | echo "Unable to locate $variable in $Cargo_toml" 1>&2 14 | } 15 | -------------------------------------------------------------------------------- /libraries/README.md: -------------------------------------------------------------------------------- 1 | NOTE: The actively maintained libraries now live at 2 | [solana-program/libraries](https://github.com/solana-program/libraries). 3 | 4 | The other repo includes: 5 | 6 | * discriminator 7 | * pod 8 | * program-error 9 | * tlv-account-resolution 10 | * type-length-value 11 | * type-length-value-derive-test 12 | 13 | Unmaintained libraries still live here and can still be forked. 14 | -------------------------------------------------------------------------------- /libraries/math-example/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Math operations using unsigned integers 2 | 3 | #![deny(missing_docs)] 4 | #![forbid(unsafe_code)] 5 | 6 | mod entrypoint; 7 | pub mod error; 8 | pub mod instruction; 9 | pub mod processor; 10 | 11 | pub use spl_math::{approximations, checked_ceil_div, precise_number, uint}; 12 | 13 | solana_program::declare_id!("Math111111111111111111111111111111111111111"); 14 | -------------------------------------------------------------------------------- /account-compression/Anchor.toml: -------------------------------------------------------------------------------- 1 | [programs.localnet] 2 | spl_account_compression = "cmtDvXumGCrqC1Age74AVPhSRVXJMd8PJS91L8KbNCK" 3 | 4 | [[test.genesis]] 5 | address = "noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV" 6 | program = "./target/deploy/wrapper.so" 7 | 8 | [registry] 9 | url = "https://anchor.projectserum.com" 10 | 11 | [provider] 12 | cluster = "localnet" 13 | wallet = "~/.config/solana/id.json" 14 | -------------------------------------------------------------------------------- /token-lending/flash_loan_receiver/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "flash_loan_receiver" 3 | version = "1.0.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | arrayref = "0.3.9" 8 | solana-program = "2.1.0" 9 | spl-token = { version = "7.0", features=["no-entrypoint"] } 10 | 11 | [lib] 12 | crate-type = ["cdylib", "lib"] 13 | 14 | [package.metadata.docs.rs] 15 | targets = ["x86_64-unknown-linux-gnu"] 16 | -------------------------------------------------------------------------------- /account-compression/sdk/src/types/index.ts: -------------------------------------------------------------------------------- 1 | import { PublicKey } from '@solana/web3.js'; 2 | import BN from 'bn.js'; 3 | 4 | import { PathNode } from '../generated'; 5 | export * from './Path'; 6 | export * from './Canopy'; 7 | export * from './ConcurrentMerkleTree'; 8 | 9 | export type ChangeLogEventV1 = { 10 | index: number; 11 | path: PathNode[]; 12 | seq: BN; 13 | treeId: PublicKey; 14 | }; 15 | -------------------------------------------------------------------------------- /managed-token/README.md: -------------------------------------------------------------------------------- 1 | # Managed Token 2 | 3 | On-chain program for "managed tokens", SPL tokens that are perpetually frozen, 4 | and must be used through this program, which will thaw the account, perform an 5 | instruction, and re-freeze the account. 6 | 7 | ## Audit 8 | 9 | The repository [README](https://github.com/solana-labs/solana-program-library#audits) 10 | contains information about program audits. 11 | -------------------------------------------------------------------------------- /token-lending/js/src/constants.ts: -------------------------------------------------------------------------------- 1 | import { PublicKey } from '@solana/web3.js'; 2 | import BigNumber from 'bignumber.js'; 3 | 4 | export const LENDING_PROGRAM_ID = new PublicKey('6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH'); 5 | 6 | /** @internal */ 7 | export const ORACLE_PROGRAM_ID = new PublicKey('5mkqGkkWSaSk2NL9p4XptwEQu4d5jFTJiurbbzdqYexF'); 8 | 9 | /** @internal */ 10 | export const WAD = new BigNumber('1e+18'); 11 | -------------------------------------------------------------------------------- /shared-memory/README.md: -------------------------------------------------------------------------------- 1 | # Shared memory program 2 | 3 | A shared-memory program on the Solana blockchain, usable for sharing data 4 | between programs or within cross-program invocations. 5 | 6 | Full documentation is available at https://spl.solana.com/shared-memory 7 | 8 | ## Audit 9 | 10 | The repository [README](https://github.com/solana-labs/solana-program-library#audits) 11 | contains information about program audits. 12 | -------------------------------------------------------------------------------- /account-compression/sdk/tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": [], 3 | "compilerOptions": { 4 | "target": "ESNext", 5 | "module": "ESNext", 6 | "moduleResolution": "Node", 7 | "esModuleInterop": true, 8 | "isolatedModules": true, 9 | "noEmitOnError": true, 10 | "resolveJsonModule": true, 11 | "strict": true, 12 | "stripInternal": true, 13 | "typeRoots": ["node_modules/@types"] 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /governance/program/src/state/mod.rs: -------------------------------------------------------------------------------- 1 | //! Program accounts 2 | 3 | pub mod enums; 4 | pub mod governance; 5 | pub mod legacy; 6 | pub mod native_treasury; 7 | pub mod program_metadata; 8 | pub mod proposal; 9 | pub mod proposal_deposit; 10 | pub mod proposal_transaction; 11 | pub mod realm; 12 | pub mod realm_config; 13 | pub mod required_signatory; 14 | pub mod signatory_record; 15 | pub mod token_owner_record; 16 | pub mod vote_record; 17 | -------------------------------------------------------------------------------- /libraries/math/src/uint.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::arithmetic_side_effects)] 2 | //! Large uint types 3 | 4 | // required for clippy 5 | #![allow(clippy::assign_op_pattern)] 6 | #![allow(clippy::ptr_offset_with_cast)] 7 | #![allow(clippy::manual_range_contains)] 8 | #![allow(missing_docs)] 9 | 10 | use uint::construct_uint; 11 | 12 | construct_uint! { 13 | pub struct U256(4); 14 | } 15 | construct_uint! { 16 | pub struct U192(3); 17 | } 18 | -------------------------------------------------------------------------------- /token-lending/flash_loan_receiver/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}; 2 | 3 | solana_program::entrypoint!(process_instruction); 4 | fn process_instruction( 5 | program_id: &Pubkey, 6 | accounts: &[AccountInfo], 7 | instruction_data: &[u8], 8 | ) -> ProgramResult { 9 | crate::processor::process_instruction(program_id, accounts, instruction_data) 10 | } 11 | -------------------------------------------------------------------------------- /account-compression/sdk/src/generated/instructions/index.ts: -------------------------------------------------------------------------------- 1 | export * from './append'; 2 | export * from './appendCanopyNodes'; 3 | export * from './closeEmptyTree'; 4 | export * from './initEmptyMerkleTree'; 5 | export * from './initPreparedTreeWithRoot'; 6 | export * from './insertOrAppend'; 7 | export * from './prepareBatchMerkleTree'; 8 | export * from './replaceLeaf'; 9 | export * from './transferAuthority'; 10 | export * from './verifyLeaf'; 11 | -------------------------------------------------------------------------------- /ci/affects.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Check if files in the commit range match one or more prefixes 4 | # 5 | 6 | ( 7 | set -x 8 | git diff --name-only "$CI_BASE_BRANCH".."$CI_COMMIT" 9 | ) 10 | 11 | for file in $(git diff --name-only "$CI_BASE_BRANCH".."$CI_COMMIT"); do 12 | for prefix in "$@"; do 13 | if [[ $file =~ ^"$prefix" ]]; then 14 | exit 0 15 | fi 16 | done 17 | done 18 | 19 | echo "No modifications to $*" 20 | exit 1 21 | -------------------------------------------------------------------------------- /account-compression/sdk/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './generated'; 2 | export { 3 | PROGRAM_ADDRESS as SPL_ACCOUNT_COMPRESSION_ADDRESS, 4 | PROGRAM_ID as SPL_ACCOUNT_COMPRESSION_PROGRAM_ID, 5 | } from './generated'; 6 | export * from './instructions'; 7 | export * from './accounts'; 8 | export * from './events'; 9 | export * from './constants'; 10 | export * from './types'; 11 | export * from './merkle-tree'; 12 | export type { ChangeLogEventV1 } from './types'; 13 | -------------------------------------------------------------------------------- /binary-option/program/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::arithmetic_side_effects)] 2 | pub mod entrypoint; 3 | pub mod error; 4 | pub mod instruction; 5 | pub mod processor; 6 | pub mod spl_utils; 7 | pub mod state; 8 | pub mod system_utils; 9 | pub mod validation_utils; 10 | // Export current sdk types for downstream users building with a different sdk 11 | // version 12 | pub use solana_program; 13 | 14 | solana_program::declare_id!("betw959P4WToez4DkuXwNsJszqbpe3HuY56AcG5yevx"); 15 | -------------------------------------------------------------------------------- /managed-token/sdk/src/generated/index.ts: -------------------------------------------------------------------------------- 1 | import { PublicKey } from '@solana/web3.js' 2 | export * from './instructions' 3 | 4 | /** 5 | * Program address 6 | * 7 | * @category constants 8 | * @category generated 9 | */ 10 | export const PROGRAM_ADDRESS = 'mTok58Lg4YfcmwqyrDHpf7ogp599WRhzb6PxjaBqAxS' 11 | 12 | /** 13 | * Program public key 14 | * 15 | * @category constants 16 | * @category generated 17 | */ 18 | export const PROGRAM_ID = new PublicKey(PROGRAM_ADDRESS) 19 | -------------------------------------------------------------------------------- /token/README.md: -------------------------------------------------------------------------------- 1 | NOTE: The token program is now maintained at 2 | [solana-program/token](https://github.com/solana-program/token). 3 | 4 | The token-2022 program, confidential-transfers, clients, CLI, and JS library are 5 | maintained at 6 | [solana-program/token-2022](https://github.com/solana-program/token-2022). 7 | 8 | The transfer-hook interface, example program, and clients are maintained at 9 | [solana-program/transfer-hook](https://github.com/solana-program/transfer-hook). 10 | -------------------------------------------------------------------------------- /examples/rust/custom-heap/src/processor.rs: -------------------------------------------------------------------------------- 1 | //! Program instruction processor 2 | 3 | use solana_program::{ 4 | account_info::AccountInfo, entrypoint::ProgramResult, log::sol_log_slice, pubkey::Pubkey, 5 | }; 6 | 7 | /// Instruction processor 8 | pub fn process_instruction( 9 | _program_id: &Pubkey, 10 | _accounts: &[AccountInfo], 11 | _instruction_data: &[u8], 12 | ) -> ProgramResult { 13 | let vec = vec![42_u8; 5]; 14 | sol_log_slice(&vec); 15 | Ok(()) 16 | } 17 | -------------------------------------------------------------------------------- /utils/test-client/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let sdk_dep = solana_sdk::signature::Signature::default(); 3 | println!("Yes have some sdk_dep {:?}", sdk_dep); 4 | let memo_dep = spl_memo::id(); 5 | println!("Yes have some memo_dep {:?}", memo_dep); 6 | let token_dep = spl_token::id(); 7 | println!("Yes have some token_dep {:?}", token_dep); 8 | let token_swap_dep = spl_token_swap::id(); 9 | println!("Yes have some token_swap_dep {:?}", token_swap_dep); 10 | } 11 | -------------------------------------------------------------------------------- /Anchor.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | anchor_version = "0.29.0" 3 | solana_version = "2.1.0" 4 | 5 | [workspace] 6 | members = [ 7 | "governance/program", 8 | "governance/chat/program", 9 | ] 10 | exclude = [ 11 | "account-compression/" 12 | ] 13 | 14 | [provider] 15 | cluster = "mainnet" 16 | wallet = "~/.config/solana/id.json" 17 | 18 | [programs.mainnet] 19 | spl_governance = "GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw" 20 | spl_governance_chat = "gCHAtYKrUUktTVzE4hEnZdLV4LXrdBf6Hh9qMaJALET" 21 | -------------------------------------------------------------------------------- /account-compression/programs/account-compression/src/state/path_node.rs: -------------------------------------------------------------------------------- 1 | use anchor_lang::prelude::*; 2 | use spl_concurrent_merkle_tree::node::Node; 3 | 4 | #[derive(AnchorDeserialize, AnchorSerialize, Clone, Copy, Debug)] 5 | pub struct PathNode { 6 | pub node: [u8; 32], 7 | pub index: u32, 8 | } 9 | 10 | impl PathNode { 11 | pub fn new(tree_node: Node, index: u32) -> Self { 12 | Self { 13 | node: tree_node, 14 | index, 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /account-compression/sdk/src/generated/types/index.ts: -------------------------------------------------------------------------------- 1 | export * from './AccountCompressionEvent'; 2 | export * from './ApplicationDataEvent'; 3 | export * from './ApplicationDataEventV1'; 4 | export * from './ChangeLogEvent'; 5 | export * from './ChangeLogEventV1'; 6 | export * from './CompressionAccountType'; 7 | export * from './ConcurrentMerkleTreeHeader'; 8 | export * from './ConcurrentMerkleTreeHeaderData'; 9 | export * from './ConcurrentMerkleTreeHeaderDataV1'; 10 | export * from './PathNode'; 11 | -------------------------------------------------------------------------------- /binary-oracle-pair/program/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! binary oracle pair 2 | #![deny(missing_docs)] 3 | 4 | pub mod error; 5 | pub mod instruction; 6 | pub mod processor; 7 | pub mod state; 8 | 9 | #[cfg(not(feature = "no-entrypoint"))] 10 | mod entrypoint; 11 | 12 | // Export current sdk types for downstream users building with a different sdk 13 | // version 14 | pub use solana_program; 15 | 16 | // Binary Oracle Pair id 17 | solana_program::declare_id!("Fd7btgySsrjuo25CJCj7oE7VPMyezDhnx7pZkj2v69Nk"); 18 | -------------------------------------------------------------------------------- /governance/addin-api/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-governance-addin-api" 3 | version = "0.1.4" 4 | description = "Solana Program Library Governance Addin Api" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [dependencies] 11 | borsh = "1.5.3" 12 | spl-governance-tools = { version = "0.1.4", path = "../tools" } 13 | solana-program = "2.1.0" 14 | -------------------------------------------------------------------------------- /managed-token/sdk/.solitarc.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const programDir = path.join(__dirname, '..', 'program'); 3 | const idlDir = path.join(__dirname, 'idl'); 4 | const sdkDir = path.join(__dirname, 'src', 'generated'); 5 | const binaryInstallDir = path.join(__dirname, '..', '..', 'target', 'solita'); 6 | 7 | module.exports = { 8 | idlGenerator: 'shank', 9 | programName: 'spl_managed_token', 10 | idlDir, 11 | sdkDir, 12 | binaryInstallDir, 13 | programDir, 14 | }; 15 | -------------------------------------------------------------------------------- /token-upgrade/program/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | //! Program entrypoint 2 | 3 | #![cfg(not(feature = "no-entrypoint"))] 4 | 5 | use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}; 6 | 7 | solana_program::entrypoint!(process_instruction); 8 | fn process_instruction( 9 | program_id: &Pubkey, 10 | accounts: &[AccountInfo], 11 | instruction_data: &[u8], 12 | ) -> ProgramResult { 13 | crate::processor::process(program_id, accounts, instruction_data) 14 | } 15 | -------------------------------------------------------------------------------- /binary-option/program/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "binary-option" 3 | version = "0.1.0" 4 | edition = "2021" 5 | license = "WTFPL" 6 | 7 | [features] 8 | no-entrypoint = [] 9 | test-sbf = [] 10 | 11 | [dependencies] 12 | solana-program = "2.1.0" 13 | thiserror = "2.0" 14 | spl-token = { version = "7.0", features = [ 15 | "no-entrypoint", 16 | ] } 17 | arrayref = "0.3.9" 18 | borsh = "1.5.3" 19 | uint = "0.10" 20 | 21 | [lib] 22 | crate-type = ["cdylib", "lib"] 23 | 24 | [lints] 25 | workspace = true 26 | -------------------------------------------------------------------------------- /examples/rust/logging/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | //! Program entrypoint 2 | 3 | #![cfg(not(feature = "no-entrypoint"))] 4 | 5 | use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}; 6 | 7 | solana_program::entrypoint!(process_instruction); 8 | fn process_instruction( 9 | program_id: &Pubkey, 10 | accounts: &[AccountInfo], 11 | instruction_data: &[u8], 12 | ) -> ProgramResult { 13 | crate::processor::process_instruction(program_id, accounts, instruction_data) 14 | } 15 | -------------------------------------------------------------------------------- /examples/rust/sysvar/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | //! Program entrypoint 2 | 3 | #![cfg(not(feature = "no-entrypoint"))] 4 | 5 | use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}; 6 | 7 | solana_program::entrypoint!(process_instruction); 8 | fn process_instruction( 9 | program_id: &Pubkey, 10 | accounts: &[AccountInfo], 11 | instruction_data: &[u8], 12 | ) -> ProgramResult { 13 | crate::processor::process_instruction(program_id, accounts, instruction_data) 14 | } 15 | -------------------------------------------------------------------------------- /libraries/math-example/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | //! Program entrypoint 2 | 3 | #![cfg(not(feature = "no-entrypoint"))] 4 | 5 | use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}; 6 | 7 | solana_program::entrypoint!(process_instruction); 8 | fn process_instruction( 9 | program_id: &Pubkey, 10 | accounts: &[AccountInfo], 11 | instruction_data: &[u8], 12 | ) -> ProgramResult { 13 | crate::processor::process_instruction(program_id, accounts, instruction_data) 14 | } 15 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: cargo 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "09:00" 8 | timezone: UTC 9 | labels: 10 | - "automerge" 11 | open-pull-requests-limit: 6 12 | ignore: 13 | - dependency-name: "cbindgen" 14 | - package-ecosystem: npm 15 | directory: "/" 16 | schedule: 17 | interval: daily 18 | time: "10:00" 19 | timezone: UTC 20 | open-pull-requests-limit: 12 21 | labels: 22 | - "automerge" 23 | -------------------------------------------------------------------------------- /examples/rust/transfer-lamports/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | //! Program entrypoint 2 | 3 | #![cfg(not(feature = "no-entrypoint"))] 4 | 5 | use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}; 6 | 7 | solana_program::entrypoint!(process_instruction); 8 | fn process_instruction( 9 | program_id: &Pubkey, 10 | accounts: &[AccountInfo], 11 | instruction_data: &[u8], 12 | ) -> ProgramResult { 13 | crate::processor::process_instruction(program_id, accounts, instruction_data) 14 | } 15 | -------------------------------------------------------------------------------- /examples/rust/transfer-tokens/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | //! Program entrypoint 2 | 3 | #![cfg(not(feature = "no-entrypoint"))] 4 | 5 | use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}; 6 | 7 | solana_program::entrypoint!(process_instruction); 8 | fn process_instruction( 9 | program_id: &Pubkey, 10 | accounts: &[AccountInfo], 11 | instruction_data: &[u8], 12 | ) -> ProgramResult { 13 | crate::processor::process_instruction(program_id, accounts, instruction_data) 14 | } 15 | -------------------------------------------------------------------------------- /examples/rust/cross-program-invocation/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | //! Program entrypoint 2 | 3 | #![cfg(not(feature = "no-entrypoint"))] 4 | 5 | use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}; 6 | 7 | solana_program::entrypoint!(process_instruction); 8 | fn process_instruction( 9 | program_id: &Pubkey, 10 | accounts: &[AccountInfo], 11 | instruction_data: &[u8], 12 | ) -> ProgramResult { 13 | crate::processor::process_instruction(program_id, accounts, instruction_data) 14 | } 15 | -------------------------------------------------------------------------------- /token-lending/program/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::arithmetic_side_effects)] 2 | #![deny(missing_docs)] 3 | 4 | //! A lending program for the Solana blockchain. 5 | 6 | pub mod entrypoint; 7 | pub mod error; 8 | pub mod instruction; 9 | pub mod math; 10 | pub mod processor; 11 | pub mod pyth; 12 | pub mod state; 13 | 14 | // Export current sdk types for downstream users building with a different sdk 15 | // version 16 | pub use solana_program; 17 | 18 | solana_program::declare_id!("6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH"); 19 | -------------------------------------------------------------------------------- /token-swap/js/src/util/new-system-account-with-airdrop.ts: -------------------------------------------------------------------------------- 1 | import type {Connection} from '@solana/web3.js'; 2 | import {Account} from '@solana/web3.js'; 3 | 4 | /** 5 | * Create a new system account and airdrop it some lamports 6 | * 7 | * @private 8 | */ 9 | export async function newSystemAccountWithAirdrop( 10 | connection: Connection, 11 | lamports: number = 1, 12 | ): Promise { 13 | const account = new Account(); 14 | await connection.requestAirdrop(account.publicKey, lamports); 15 | return account; 16 | } 17 | -------------------------------------------------------------------------------- /libraries/math/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-math" 3 | version = "0.3.0" 4 | description = "Solana Program Library Math" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [dependencies] 11 | num-traits = "0.2" 12 | uint = "0.10" 13 | 14 | [dev-dependencies] 15 | proptest = "1.6.0" 16 | libm = "0.2.11" 17 | 18 | [package.metadata.docs.rs] 19 | targets = ["x86_64-unknown-linux-gnu"] 20 | -------------------------------------------------------------------------------- /token-wrap/program/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | //! Program entrypoint 2 | 3 | #![cfg(all(target_os = "solana", not(feature = "no-entrypoint")))] 4 | 5 | use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}; 6 | 7 | solana_program::entrypoint!(process_instruction); 8 | fn process_instruction( 9 | program_id: &Pubkey, 10 | accounts: &[AccountInfo], 11 | instruction_data: &[u8], 12 | ) -> ProgramResult { 13 | crate::processor::process_instruction(program_id, accounts, instruction_data) 14 | } 15 | -------------------------------------------------------------------------------- /binary-option/program/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | #![cfg(all(target_os = "solana", not(feature = "no-entrypoint")))] 2 | 3 | use { 4 | crate::processor::Processor, 5 | solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}, 6 | }; 7 | 8 | solana_program::entrypoint!(process_instruction); 9 | fn process_instruction( 10 | program_id: &Pubkey, 11 | accounts: &[AccountInfo], 12 | instruction_data: &[u8], 13 | ) -> ProgramResult { 14 | Processor::process(program_id, accounts, instruction_data) 15 | } 16 | -------------------------------------------------------------------------------- /stateless-asks/program/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | #![cfg(all(target_os = "solana", not(feature = "no-entrypoint")))] 2 | 3 | use { 4 | crate::processor::Processor, 5 | solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}, 6 | }; 7 | 8 | solana_program::entrypoint!(process_instruction); 9 | fn process_instruction( 10 | program_id: &Pubkey, 11 | accounts: &[AccountInfo], 12 | instruction_data: &[u8], 13 | ) -> ProgramResult { 14 | Processor::process(program_id, accounts, instruction_data) 15 | } 16 | -------------------------------------------------------------------------------- /account-compression/sdk/src/generated/index.ts: -------------------------------------------------------------------------------- 1 | import { PublicKey } from '@solana/web3.js'; 2 | export * from './errors'; 3 | export * from './instructions'; 4 | export * from './types'; 5 | 6 | /** 7 | * Program address 8 | * 9 | * @category constants 10 | * @category generated 11 | */ 12 | export const PROGRAM_ADDRESS = 'cmtDvXumGCrqC1Age74AVPhSRVXJMd8PJS91L8KbNCK'; 13 | 14 | /** 15 | * Program public key 16 | * 17 | * @category constants 18 | * @category generated 19 | */ 20 | export const PROGRAM_ID = new PublicKey(PROGRAM_ADDRESS); 21 | -------------------------------------------------------------------------------- /examples/rust/README.md: -------------------------------------------------------------------------------- 1 | # Program examples written in Rust 2 | 3 | The examples in this directory demonstrate various Solana program mechanisms. 4 | They are for code reference only and are not end-to-end examples that interact 5 | with a live cluster. 6 | 7 | ## Build and Test 8 | 9 | The root [README](../../README.md) gives instructions on how to build and test 10 | these examples. 11 | 12 | ## Audit 13 | 14 | The repository [README](https://github.com/solana-labs/solana-program-library#audits) 15 | contains information about program audits. 16 | -------------------------------------------------------------------------------- /libraries/concurrent-merkle-tree/src/log.rs: -------------------------------------------------------------------------------- 1 | macro_rules! solana_logging { 2 | ($message:literal, $($arg:tt)*) => { 3 | #[cfg(feature = "log")] 4 | ::solana_program::msg!($message, $($arg)*); 5 | }; 6 | ($message:literal) => { 7 | #[cfg(feature = "log")] 8 | ::solana_program::msg!($message); 9 | }; 10 | } 11 | 12 | macro_rules! log_compute { 13 | () => { 14 | #[cfg(all(feature = "sol-log", feature = "log"))] 15 | ::solana_program::log::sol_log_compute_units(); 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /name-service/.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | src/target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 7 | Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | 12 | target 13 | .vscode 14 | hfuzz* 15 | third_party/ 16 | 17 | */node_modules 18 | js/dist 19 | js/lib 20 | js/docs 21 | js/src/secret.ts 22 | js/src/test.ts 23 | -------------------------------------------------------------------------------- /account-compression/programs/noop/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-noop" 3 | version = "0.2.0" 4 | description = "Solana Program Library No-op Program" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [lib] 11 | crate-type = ["cdylib", "lib"] 12 | 13 | [features] 14 | no-entrypoint = [] 15 | cpi = ["no-entrypoint"] 16 | default = [] 17 | 18 | [dependencies] 19 | solana-program = ">=1.18.11,<=2" 20 | -------------------------------------------------------------------------------- /utils/test-client/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "test-client" 3 | version = "0.1.0" 4 | authors = ["Solana Labs Maintainers "] 5 | publish = false 6 | edition = "2021" 7 | 8 | # Used to ensure that SPL programs are buildable by external clients 9 | 10 | [dependencies] 11 | solana-sdk = "2.1.0" 12 | spl-memo = { version = "6.0.0", features = [ "no-entrypoint" ] } 13 | spl-token = { version = "7.0.0", features = [ "no-entrypoint" ] } 14 | spl-token-swap = { path = "../../token-swap/program", features = [ "no-entrypoint" ] } 15 | -------------------------------------------------------------------------------- /ci/anchor-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | source ci/rust-version.sh stable 6 | source ci/solana-version.sh install 7 | source ci/install-anchor.sh install 8 | 9 | set -x 10 | 11 | usage() { 12 | exitcode=0 13 | if [[ -n "$1" ]]; then 14 | exitcode=1 15 | echo "Error: $*" 16 | fi 17 | echo "Usage: $0 [program-directory]" 18 | exit $exitcode 19 | } 20 | 21 | program_directory=$1 22 | if [[ -z $program_directory ]]; then 23 | usage "No program directory provided" 24 | fi 25 | 26 | cd $program_directory 27 | anchor build -------------------------------------------------------------------------------- /docs/src/introduction.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Introduction 3 | id: introduction 4 | slug: / 5 | --- 6 | 7 | The Solana Program Library (SPL) is a collection of on-chain programs targeting 8 | the [Sealevel parallel runtime](https://medium.com/solana-labs/sealevel-parallel-processing-thousands-of-smart-contracts-d814b378192). 9 | These programs are tested against Solana's implementation 10 | of Sealevel, solana-runtime, and deployed to its mainnet. As others implement 11 | Sealevel, we will graciously accept patches to ensure the programs here are 12 | portable across all implementations. 13 | -------------------------------------------------------------------------------- /token-lending/js/src/instructions/instruction.ts: -------------------------------------------------------------------------------- 1 | /** @internal */ 2 | export enum LendingInstruction { 3 | InitLendingMarket = 0, 4 | SetLendingMarketOwner = 1, 5 | InitReserve = 2, 6 | RefreshReserve = 3, 7 | DepositReserveLiquidity = 4, 8 | RedeemReserveCollateral = 5, 9 | InitObligation = 6, 10 | RefreshObligation = 7, 11 | DepositObligationCollateral = 8, 12 | WithdrawObligationCollateral = 9, 13 | BorrowObligationLiquidity = 10, 14 | RepayObligationLiquidity = 11, 15 | LiquidateObligation = 12, 16 | FlashLoan = 13, 17 | } 18 | -------------------------------------------------------------------------------- /libraries/merkle-tree-reference/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-merkle-tree-reference" 3 | version = "0.1.0" 4 | description = "Reference implementation of a merkle tree" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [dependencies] 11 | solana-program = ">=1.18.11,<=2" 12 | thiserror = "2.0.9" 13 | 14 | [lib] 15 | crate-type = ["cdylib", "lib"] 16 | 17 | [package.metadata.docs.rs] 18 | targets = ["x86_64-unknown-linux-gnu"] 19 | -------------------------------------------------------------------------------- /token-swap/program/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::arithmetic_side_effects)] 2 | #![deny(missing_docs)] 3 | 4 | //! An Uniswap-like program for the Solana blockchain. 5 | 6 | pub mod constraints; 7 | pub mod curve; 8 | pub mod error; 9 | pub mod instruction; 10 | pub mod processor; 11 | pub mod state; 12 | 13 | #[cfg(not(feature = "no-entrypoint"))] 14 | mod entrypoint; 15 | 16 | // Export current sdk types for downstream users building with a different sdk 17 | // version 18 | pub use solana_program; 19 | 20 | solana_program::declare_id!("SwapsVeCiPHMUAtzQWZw7RjsKjgCjhwU55QGu4U1Szw"); 21 | -------------------------------------------------------------------------------- /shared-memory/program/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-shared-memory" 3 | version = "2.0.6" 4 | description = "Solana Program Library Shared-memory" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [features] 11 | test-sbf = [] 12 | 13 | [dependencies] 14 | arrayref = "0.3.9" 15 | solana-program = "2.1.0" 16 | 17 | [dev-dependencies] 18 | solana-program-test = "2.1.0" 19 | solana-sdk = "2.1.0" 20 | 21 | [lib] 22 | crate-type = ["cdylib", "lib"] 23 | -------------------------------------------------------------------------------- /token-lending/js/src/instructions/index.ts: -------------------------------------------------------------------------------- 1 | export * from './borrowObligationLiquidity'; 2 | export * from './depositObligationCollateral'; 3 | export * from './depositReserveLiquidity'; 4 | export * from './initLendingMarket'; 5 | export * from './initObligation'; 6 | export * from './initReserve'; 7 | export * from './instruction'; 8 | export * from './liquidateObligation'; 9 | export * from './redeemReserveCollateral'; 10 | export * from './refreshObligation'; 11 | export * from './refreshReserve'; 12 | export * from './repayObligationLiquidity'; 13 | export * from './withdrawObligationCollateral'; 14 | -------------------------------------------------------------------------------- /token-swap/js/README.md: -------------------------------------------------------------------------------- 1 | # Token-swap JavaScript API 2 | 3 | The Token-swap JavaScript library comprises: 4 | 5 | * A library to interact with the on-chain program 6 | * A test client that exercises the program 7 | * Scripts to facilitate building the program 8 | 9 | ## Getting Started 10 | 11 | First fetch the npm dependencies, including `@solana/web3.js`, by running: 12 | ```sh 13 | $ npm install 14 | ``` 15 | 16 | ### Build the on-chain program 17 | 18 | ```sh 19 | $ npm run build:program 20 | ``` 21 | 22 | ### Run the test client 23 | 24 | ```sh 25 | $ npm run start-with-test-validator 26 | ``` 27 | -------------------------------------------------------------------------------- /token-swap/js/src/util/account.ts: -------------------------------------------------------------------------------- 1 | import type {Connection, PublicKey} from '@solana/web3.js'; 2 | 3 | export async function loadAccount( 4 | connection: Connection, 5 | address: PublicKey, 6 | programId: PublicKey, 7 | ): Promise { 8 | const accountInfo = await connection.getAccountInfo(address); 9 | if (accountInfo === null) { 10 | throw new Error('Failed to find account'); 11 | } 12 | 13 | if (!accountInfo.owner.equals(programId)) { 14 | throw new Error(`Invalid owner: ${JSON.stringify(accountInfo.owner)}`); 15 | } 16 | 17 | return Buffer.from(accountInfo.data); 18 | } 19 | -------------------------------------------------------------------------------- /account-compression/sdk/.solitarc.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | const path = require('path'); 3 | const programDir = path.join(__dirname, '..', 'programs', 'account-compression'); 4 | const idlDir = path.join(__dirname, 'idl'); 5 | const sdkDir = path.join(__dirname, 'src', 'generated'); 6 | const binaryInstallDir = path.join(__dirname, '..', 'target', 'solita'); 7 | 8 | module.exports = { 9 | idlGenerator: 'anchor', 10 | programName: 'spl_account_compression', 11 | programId: 'cmtDvXumGCrqC1Age74AVPhSRVXJMd8PJS91L8KbNCK', 12 | idlDir, 13 | sdkDir, 14 | binaryInstallDir, 15 | programDir, 16 | }; 17 | -------------------------------------------------------------------------------- /account-compression/programs/account-compression/src/events/mod.rs: -------------------------------------------------------------------------------- 1 | //! Anchor events are used to emit information necessary to 2 | //! index changes made to a SPL ConcurrentMerkleTree 3 | 4 | use anchor_lang::prelude::*; 5 | 6 | mod application_data; 7 | mod changelog_event; 8 | 9 | pub use application_data::{ApplicationDataEvent, ApplicationDataEventV1}; 10 | pub use changelog_event::{ChangeLogEvent, ChangeLogEventV1}; 11 | 12 | #[derive(AnchorDeserialize, AnchorSerialize)] 13 | #[repr(C)] 14 | pub enum AccountCompressionEvent { 15 | ChangeLog(ChangeLogEvent), 16 | ApplicationData(ApplicationDataEvent), 17 | } 18 | -------------------------------------------------------------------------------- /docs/publish-docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ex 4 | 5 | if [[ -d .vercel ]]; then 6 | rm -r .vercel 7 | fi 8 | 9 | CONFIG_FILE=vercel.json 10 | PROJECT_NAME=spl-solana-com 11 | 12 | PRODUCTION= 13 | if [[ -n "$CI" ]]; then 14 | PRODUCTION=--prod 15 | fi 16 | 17 | cat > "$CONFIG_FILE" < Result, ProgramError> { 10 | let (tag, body) = array_refs![src, 4, 32]; 11 | match *tag { 12 | [0, 0, 0, 0] => Ok(COption::None), 13 | [1, 0, 0, 0] => Ok(COption::Some(Pubkey::new_from_array(*body))), 14 | _ => Err(ProgramError::InvalidAccountData), 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /account-compression/programs/account-compression/README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Solana 4 | 5 |

6 | 7 | # SPL Account Compression Rust SDK 8 | 9 | More information about account compression can be found in [the solana-program-library repo](https://github.com/solana-labs/solana-program-library/tree/master/account-compression). 10 | 11 | `spl-account-compression` and this crate's implementation are targeted towards supporting [Metaplex Compressed NFTs](https://github.com/metaplex-foundation/mpl-bubblegum) and may be subject to change. -------------------------------------------------------------------------------- /docs/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -ex 3 | 4 | cd "$(dirname "$0")" 5 | 6 | # shellcheck source=ci/env.sh 7 | source ../ci/env.sh 8 | 9 | # Publish only if in CI, vercel token is present, and it's not a pull request 10 | if [[ -n $CI ]] && [[ -n $VERCEL_TOKEN ]] && [[ -z $CI_PULL_REQUEST ]]; then 11 | PUBLISH_DOCS=true 12 | else 13 | PUBLISH_DOCS= 14 | fi 15 | 16 | if [[ -n $PUBLISH_DOCS ]]; then 17 | npm install --global docusaurus-init 18 | docusaurus-init 19 | npm install --global vercel 20 | fi 21 | 22 | # Build from /src into /build 23 | npm run build 24 | 25 | if [[ -n $PUBLISH_DOCS ]]; then 26 | ./publish-docs.sh 27 | fi 28 | -------------------------------------------------------------------------------- /account-compression/programs/noop/README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Solana 4 | 5 |

6 | 7 | # SPL Noop Rust SDK 8 | 9 | This crate provides a wrapper for invoking `spl-noop`, which does nothing. 10 | It's primary use is circumventing log truncation when emitting application data by `invoke`-ing `spl-noop` with event data. 11 | 12 | `spl-noop` and this crate's implementation are targeted towards supporting [account-compression](https://github.com/solana-labs/solana-program-library/tree/master/account-compression) and may be subject to change. 13 | -------------------------------------------------------------------------------- /governance/tools/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-governance-tools" 3 | version = "0.1.4" 4 | description = "Solana Program Library Governance Tools" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [dependencies] 11 | arrayref = "0.3.9" 12 | bincode = "1.3.2" 13 | borsh = "1.5.3" 14 | num-derive = "0.4" 15 | num-traits = "0.2" 16 | serde = "1.0.217" 17 | serde_derive = "1.0.103" 18 | solana-program = "2.1.0" 19 | spl-token = { version = "7.0", features = [ 20 | "no-entrypoint", 21 | ] } 22 | thiserror = "2.0" 23 | -------------------------------------------------------------------------------- /name-service/README.md: -------------------------------------------------------------------------------- 1 | # Name Service program 2 | 3 | A spl program for issuing and managing ownership of: domain names, Solana 4 | Pubkeys, URLs, twitter handles, ipfs cid's, metadata, etc.. 5 | 6 | This program provides an interface and implementation that third parties can 7 | utilize to create and use their own version of a name service of any kind. 8 | 9 | Full documentation is available at https://spl.solana.com/name-service 10 | 11 | JavaScript binding are available in the `./js` directory. 12 | 13 | ## Audit 14 | 15 | The repository [README](https://github.com/solana-labs/solana-program-library#audits) 16 | contains information about program audits. 17 | -------------------------------------------------------------------------------- /libraries/concurrent-merkle-tree/src/path.rs: -------------------------------------------------------------------------------- 1 | use crate::node::Node; 2 | 3 | /// Represents a proof to perform a Merkle tree operation on the leaf at `index` 4 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] 5 | #[repr(C)] 6 | pub struct Path { 7 | pub proof: [Node; MAX_DEPTH], 8 | pub leaf: Node, 9 | pub index: u32, 10 | pub _padding: u32, 11 | } 12 | 13 | impl Default for Path { 14 | fn default() -> Self { 15 | Self { 16 | proof: [Node::default(); MAX_DEPTH], 17 | leaf: Node::default(), 18 | index: 0, 19 | _padding: 0, 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /token-lending/js/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "emitDeclarationOnly": true, 5 | "outDir": "lib", 6 | "module": "esnext", 7 | "esModuleInterop": true, 8 | "resolveJsonModule": true, 9 | "isolatedModules": true, 10 | "declaration": true, 11 | "moduleResolution": "node", 12 | "stripInternal": true, 13 | "skipLibCheck": true 14 | }, 15 | "files": ["rollup.config.ts"], 16 | "include": ["src"], 17 | "exclude": ["lib", "node_modules"], 18 | "typedocOptions": { 19 | "entryPoints": ["src/index.ts"], 20 | "out": "docs" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/rust/sysvar/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-example-sysvar" 3 | version = "1.0.0" 4 | description = "Solana Program Library Sysvar Example" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | publish = false 10 | 11 | [features] 12 | no-entrypoint = [] 13 | test-sbf = [] 14 | 15 | [dependencies] 16 | solana-program = "2.1.0" 17 | 18 | [dev-dependencies] 19 | solana-program-test = "2.1.0" 20 | solana-sdk = "2.1.0" 21 | 22 | [lib] 23 | crate-type = ["cdylib", "lib"] 24 | 25 | [package.metadata.docs.rs] 26 | targets = ["x86_64-unknown-linux-gnu"] 27 | -------------------------------------------------------------------------------- /account-compression/programs/noop/src/lib.rs: -------------------------------------------------------------------------------- 1 | use solana_program::{ 2 | account_info::AccountInfo, declare_id, entrypoint::ProgramResult, instruction::Instruction, 3 | pubkey::Pubkey, 4 | }; 5 | 6 | declare_id!("noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV"); 7 | 8 | #[cfg(not(feature = "no-entrypoint"))] 9 | solana_program::entrypoint!(noop); 10 | 11 | pub fn noop( 12 | _program_id: &Pubkey, 13 | _accounts: &[AccountInfo], 14 | _instruction_data: &[u8], 15 | ) -> ProgramResult { 16 | Ok(()) 17 | } 18 | 19 | pub fn instruction(data: Vec) -> Instruction { 20 | Instruction { 21 | program_id: crate::id(), 22 | accounts: vec![], 23 | data, 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /binary-oracle-pair/README.md: -------------------------------------------------------------------------------- 1 | # Simple Oracle Pair Token 2 | 3 | 1. pick a deposit token 4 | 2. pick the decider's pubkey 5 | 3. pick the mint term end slot 6 | 4. pick the decide term end slot, must be after 3 7 | 8 | Each deposit token can mint one `Pass` and one `Fail` token up to 9 | the mint term end slot. After the decide term end slot the `Pass` 10 | token converts 1:1 with the deposit token if and only if the decider 11 | had set `pass` before the end of the decide term, otherwise the `Fail` 12 | token converts 1:1 with the deposit token. 13 | 14 | ## Audit 15 | 16 | The repository [README](https://github.com/solana-labs/solana-program-library#audits) 17 | contains information about program audits. 18 | -------------------------------------------------------------------------------- /examples/rust/logging/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-example-logging" 3 | version = "1.0.0" 4 | description = "Solana Program Library Logging Example" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | publish = false 10 | 11 | [features] 12 | no-entrypoint = [] 13 | test-sbf = [] 14 | 15 | [dependencies] 16 | solana-program = "2.1.0" 17 | 18 | [dev-dependencies] 19 | solana-program-test = "2.1.0" 20 | solana-sdk = "2.1.0" 21 | 22 | [lib] 23 | crate-type = ["cdylib", "lib"] 24 | 25 | [package.metadata.docs.rs] 26 | targets = ["x86_64-unknown-linux-gnu"] 27 | -------------------------------------------------------------------------------- /examples/rust/transfer-lamports/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-example-transfer-lamports" 3 | version = "1.0.0" 4 | description = "Solana Program Library Transfer Lamports Example" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [features] 11 | no-entrypoint = [] 12 | test-sbf = [] 13 | 14 | [dependencies] 15 | solana-program = "2.1.0" 16 | 17 | [dev-dependencies] 18 | solana-program-test = "2.1.0" 19 | solana-sdk = "2.1.0" 20 | 21 | [lib] 22 | crate-type = ["cdylib", "lib"] 23 | 24 | [package.metadata.docs.rs] 25 | targets = ["x86_64-unknown-linux-gnu"] 26 | -------------------------------------------------------------------------------- /account-compression/sdk/src/generated/types/ApplicationDataEventV1.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This code was GENERATED using the solita package. 3 | * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. 4 | * 5 | * See: https://github.com/metaplex-foundation/solita 6 | */ 7 | 8 | import * as beet from '@metaplex-foundation/beet'; 9 | export type ApplicationDataEventV1 = { 10 | applicationData: Uint8Array; 11 | }; 12 | 13 | /** 14 | * @category userTypes 15 | * @category generated 16 | */ 17 | export const applicationDataEventV1Beet = new beet.FixableBeetArgsStruct( 18 | [['applicationData', beet.bytes]], 19 | 'ApplicationDataEventV1', 20 | ); 21 | -------------------------------------------------------------------------------- /name-service/program/src/error.rs: -------------------------------------------------------------------------------- 1 | use { 2 | num_derive::FromPrimitive, 3 | solana_program::{decode_error::DecodeError, program_error::ProgramError}, 4 | thiserror::Error, 5 | }; 6 | 7 | #[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] 8 | pub enum NameServiceError { 9 | #[error("Out of space")] 10 | OutOfSpace, 11 | } 12 | 13 | pub type NameServiceResult = Result<(), NameServiceError>; 14 | 15 | impl From for ProgramError { 16 | fn from(e: NameServiceError) -> Self { 17 | ProgramError::Custom(e as u32) 18 | } 19 | } 20 | 21 | impl DecodeError for NameServiceError { 22 | fn type_of() -> &'static str { 23 | "NameServiceError" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /token-collection/program/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | //! Program entrypoint 2 | 3 | use { 4 | crate::processor, 5 | solana_program::{ 6 | account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, 7 | pubkey::Pubkey, 8 | }, 9 | spl_token_group_interface::error::TokenGroupError, 10 | }; 11 | 12 | solana_program::entrypoint!(process_instruction); 13 | fn process_instruction( 14 | program_id: &Pubkey, 15 | accounts: &[AccountInfo], 16 | instruction_data: &[u8], 17 | ) -> ProgramResult { 18 | if let Err(error) = processor::process(program_id, accounts, instruction_data) { 19 | error.print::(); 20 | return Err(error); 21 | } 22 | Ok(()) 23 | } 24 | -------------------------------------------------------------------------------- /account-compression/sdk/src/generated/types/PathNode.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This code was GENERATED using the solita package. 3 | * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. 4 | * 5 | * See: https://github.com/metaplex-foundation/solita 6 | */ 7 | 8 | import * as beet from '@metaplex-foundation/beet'; 9 | export type PathNode = { 10 | index: number; 11 | node: number[] /* size: 32 */; 12 | }; 13 | 14 | /** 15 | * @category userTypes 16 | * @category generated 17 | */ 18 | export const pathNodeBeet = new beet.BeetArgsStruct( 19 | [ 20 | ['node', beet.uniformFixedSizeArray(beet.u8, 32)], 21 | ['index', beet.u32], 22 | ], 23 | 'PathNode', 24 | ); 25 | -------------------------------------------------------------------------------- /examples/rust/cross-program-invocation/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-example-cross-program-invocation" 3 | version = "1.0.0" 4 | description = "Solana Program Library Cross Program Invocation Example" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | publish = false 10 | 11 | [features] 12 | no-entrypoint = [] 13 | test-sbf = [] 14 | 15 | [dependencies] 16 | solana-program = "2.1.0" 17 | 18 | [dev-dependencies] 19 | solana-program-test = "2.1.0" 20 | solana-sdk = "2.1.0" 21 | 22 | [lib] 23 | crate-type = ["cdylib", "lib"] 24 | 25 | [package.metadata.docs.rs] 26 | targets = ["x86_64-unknown-linux-gnu"] 27 | -------------------------------------------------------------------------------- /token-swap/js/src/util/new-account-with-lamports.ts: -------------------------------------------------------------------------------- 1 | import type {Connection} from '@solana/web3.js'; 2 | import {Keypair} from '@solana/web3.js'; 3 | 4 | import {sleep} from './sleep.js'; 5 | 6 | export async function newAccountWithLamports( 7 | connection: Connection, 8 | lamports: number = 1000000, 9 | ): Promise { 10 | const account = Keypair.generate(); 11 | 12 | let retries = 30; 13 | await connection.requestAirdrop(account.publicKey, lamports); 14 | for (;;) { 15 | await sleep(500); 16 | if (lamports == (await connection.getBalance(account.publicKey))) { 17 | return account; 18 | } 19 | if (--retries <= 0) { 20 | break; 21 | } 22 | } 23 | throw new Error(`Airdrop of ${lamports} failed`); 24 | } 25 | -------------------------------------------------------------------------------- /name-service/js/README.md: -------------------------------------------------------------------------------- 1 | # Name Service JavaScript bindings 2 | 3 | [![npm](https://img.shields.io/npm/v/@solana/spl-name-service)](https://unpkg.com/@solana/spl-name-service@latest/) 4 | 5 | Full documentation is available at https://spl.solana.com/name-service 6 | 7 | JavaScript binding allow to interact with a spl program for issuing and managing 8 | ownership of: domain names, Solana Pubkeys, URLs, twitter handles, arweave ids, 9 | metadata, etc.. 10 | 11 | This package provides an interface that third parties can 12 | utilize to create and use their own version of a name service of any kind. 13 | 14 | ## Installation 15 | 16 | ```bash 17 | npm install @solana/spl-name-service 18 | ``` 19 | 20 | ```bash 21 | yarn add @solana/spl-name-service 22 | ``` 23 | -------------------------------------------------------------------------------- /governance/test-sdk/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-governance-test-sdk" 3 | version = "0.1.4" 4 | description = "Solana Program Library Governance Program Test SDK" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [dependencies] 11 | arrayref = "0.3.9" 12 | bincode = "1.3.2" 13 | borsh = "1.5.3" 14 | lazy_static = "1.5.0" 15 | num-derive = "0.4" 16 | num-traits = "0.2" 17 | serde = "1.0.217" 18 | serde_derive = "1.0.103" 19 | solana-program = "2.1.0" 20 | solana-program-test = "2.1.0" 21 | solana-sdk = "2.1.0" 22 | spl-token = { version = "7.0", features = [ 23 | "no-entrypoint", 24 | ] } 25 | thiserror = "2.0" 26 | -------------------------------------------------------------------------------- /token-swap/program/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | //! Program entrypoint definitions 2 | 3 | use { 4 | crate::{error::SwapError, processor::Processor}, 5 | solana_program::{ 6 | account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, 7 | pubkey::Pubkey, 8 | }, 9 | }; 10 | 11 | solana_program::entrypoint!(process_instruction); 12 | fn process_instruction( 13 | program_id: &Pubkey, 14 | accounts: &[AccountInfo], 15 | instruction_data: &[u8], 16 | ) -> ProgramResult { 17 | if let Err(error) = Processor::process(program_id, accounts, instruction_data) { 18 | // catch the error so we can print it 19 | error.print::(); 20 | return Err(error); 21 | } 22 | Ok(()) 23 | } 24 | -------------------------------------------------------------------------------- /examples/c/src/logging/test_logging.c: -------------------------------------------------------------------------------- 1 | // #include "logging.c" 2 | // #include 3 | 4 | // Test(logging, sanity) { 5 | // uint8_t instruction_data[] = {10, 11, 12, 13, 14}; 6 | // SolPubkey program_id = {.x = { 7 | // 1, 8 | // }}; 9 | // SolPubkey key = {.x = { 10 | // 2, 11 | // }}; 12 | // uint64_t lamports = 1; 13 | // uint8_t data[] = {0, 0, 0, 0}; 14 | // SolAccountInfo accounts[] = {}; 15 | // SolParameters params = {accounts, sizeof(accounts) / 16 | // sizeof(SolAccountInfo), instruction_data, 17 | // sizeof(instruction_data), &program_id}; 18 | 19 | // cr_assert(SUCCESS == logging(¶ms)); 20 | // } 21 | -------------------------------------------------------------------------------- /examples/rust/transfer-tokens/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-example-transfer-tokens" 3 | version = "1.0.0" 4 | description = "Solana Program Library Transfer Tokens Example" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [features] 11 | no-entrypoint = [] 12 | test-sbf = [] 13 | 14 | [dependencies] 15 | solana-program = "2.1.0" 16 | spl-token = { version = "7.0", features = [ "no-entrypoint" ] } 17 | 18 | [dev-dependencies] 19 | solana-program-test = "2.1.0" 20 | solana-sdk = "2.1.0" 21 | 22 | [lib] 23 | crate-type = ["cdylib", "lib"] 24 | 25 | [package.metadata.docs.rs] 26 | targets = ["x86_64-unknown-linux-gnu"] 27 | -------------------------------------------------------------------------------- /token-lending/js/rollup.config.ts: -------------------------------------------------------------------------------- 1 | import commonjs from '@rollup/plugin-commonjs'; 2 | import nodeResolve from '@rollup/plugin-node-resolve'; 3 | import typescript from '@rollup/plugin-typescript'; 4 | import { RollupOptions } from 'rollup'; 5 | import pkg from './package.json' assert { type: 'json' }; 6 | 7 | const config: RollupOptions = { 8 | input: 'src/index.ts', 9 | output: [ 10 | { file: pkg.main, format: 'cjs', sourcemap: true }, 11 | { file: pkg.module, format: 'es', sourcemap: true }, 12 | ], 13 | external: ['@solana/spl-token', '@solana/web3.js', 'assert', 'buffer', 'fs', 'path'], 14 | watch: { 15 | include: 'src/**', 16 | }, 17 | plugins: [typescript(), commonjs(), nodeResolve()], 18 | }; 19 | export default config; 20 | -------------------------------------------------------------------------------- /examples/c/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Program examples written in C 3 | 4 | The examples in this directory demonstrate various Solana program mechanisms. 5 | They are for code reference only and are not end-to-end working examples. The 6 | current C test frameworks are very limited so not all functionality is fully 7 | tested. 8 | 9 | ## Environment Setup 10 | 11 | 1. Install `make` 12 | 2. Install gcc 13 | 3. Install Solana v1.4.6 or later from 14 | https://docs.solana.com/cli/install-solana-cli-tools 15 | 16 | ## Build and Test 17 | 18 | To build the examples and run the tests: 19 | 20 | ```bash 21 | $ make 22 | ``` 23 | 24 | ## Audit 25 | 26 | The repository [README](https://github.com/solana-labs/solana-program-library#audits) 27 | contains information about program audits. 28 | -------------------------------------------------------------------------------- /memo/README.md: -------------------------------------------------------------------------------- 1 | NOTE: The memo program and clients are now maintained at 2 | [solana-program/memo](https://github.com/solana-program/memo). 3 | 4 | # Memo Program 5 | 6 | A simple program that validates a string of UTF-8 encoded characters and logs it 7 | in the transaction log. The program also verifies that any accounts provided are 8 | signers of the transaction, and if so, logs their addresses. It can be used to 9 | record a string on-chain, stored in the instruction data of a successful 10 | transaction, and optionally verify the originator. 11 | 12 | Full documentation is available at https://spl.solana.com/memo 13 | 14 | ## Audit 15 | 16 | The repository [README](https://github.com/solana-labs/solana-program-library#audits) 17 | contains information about program audits. 18 | -------------------------------------------------------------------------------- /stateless-asks/program/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "stateless-asks" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | 9 | [features] 10 | no-entrypoint = [] 11 | test-sbf = [] 12 | 13 | [dependencies] 14 | borsh = "1.5.3" 15 | solana-program = "2.1.0" 16 | spl-token = { version = "7.0", features = [ 17 | "no-entrypoint", 18 | ] } 19 | spl-associated-token-account-client = { version = "2.0.0" } 20 | thiserror = "2.0" 21 | 22 | [dev-dependencies] 23 | solana-program-test = "2.1.0" 24 | solana-sdk = "2.1.0" 25 | 26 | [lib] 27 | crate-type = ["cdylib", "lib"] 28 | 29 | [package.metadata.docs.rs] 30 | targets = ["x86_64-unknown-linux-gnu"] 31 | 32 | [lints] 33 | workspace = true 34 | -------------------------------------------------------------------------------- /governance/program/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::arithmetic_side_effects)] 2 | #![allow(clippy::doc_lazy_continuation)] 3 | #![deny(missing_docs)] 4 | //! A Governance program for the Solana blockchain. 5 | 6 | pub mod addins; 7 | pub mod entrypoint; 8 | pub mod error; 9 | pub mod instruction; 10 | pub mod processor; 11 | pub mod state; 12 | pub mod tools; 13 | 14 | // Export current sdk types for downstream users building with a different sdk 15 | // version 16 | pub use solana_program; 17 | 18 | /// Seed prefix for Governance PDAs 19 | /// Note: This prefix is used for the initial set of PDAs and shouldn't be used 20 | /// for any new accounts All new PDAs should use a unique prefix to guarantee 21 | /// uniqueness for each account 22 | pub const PROGRAM_AUTHORITY_SEED: &[u8] = b"governance"; 23 | -------------------------------------------------------------------------------- /token-lending/program/tests/fixtures/README.md: -------------------------------------------------------------------------------- 1 | # fixtures 2 | 3 | ### SOL / SRM Aggregator Accounts 4 | 5 | ```shell 6 | solana config set --url https://api.devnet.solana.com 7 | 8 | # Pyth product: SOL/USD 9 | solana account 3Mnn2fX6rQyUsyELYms1sBJyChWofzSNRoqYzvgMVz5E --output-file 3Mnn2fX6rQyUsyELYms1sBJyChWofzSNRoqYzvgMVz5E.bin 10 | # Pyth price: SOL/USD 11 | solana account J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix --output-file J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix.bin 12 | # Pyth product: SRM/USD 13 | solana account 6MEwdxe4g1NeAF9u6KDG14anJpFsVEa2cvr5H6iriFZ8 --output-file 6MEwdxe4g1NeAF9u6KDG14anJpFsVEa2cvr5H6iriFZ8.bin 14 | # Pyth price: SRM/USD 15 | solana account 992moaMQKs32GKZ9dxi8keyM2bUmbrwBZpK4p2K6X5Vs --output-file 992moaMQKs32GKZ9dxi8keyM2bUmbrwBZpK4p2K6X5Vs.bin 16 | ``` 17 | -------------------------------------------------------------------------------- /account-compression/sdk/src/generated/types/CompressionAccountType.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This code was GENERATED using the solita package. 3 | * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. 4 | * 5 | * See: https://github.com/metaplex-foundation/solita 6 | */ 7 | 8 | import * as beet from '@metaplex-foundation/beet'; 9 | /** 10 | * @category enums 11 | * @category generated 12 | */ 13 | export enum CompressionAccountType { 14 | Uninitialized, 15 | ConcurrentMerkleTree, 16 | } 17 | 18 | /** 19 | * @category userTypes 20 | * @category generated 21 | */ 22 | export const compressionAccountTypeBeet = beet.fixedScalarEnum(CompressionAccountType) as beet.FixedSizeBeet< 23 | CompressionAccountType, 24 | CompressionAccountType 25 | >; 26 | -------------------------------------------------------------------------------- /docs/static/css/code-block-buttons.css: -------------------------------------------------------------------------------- 1 | /* "Copy" code block button */ 2 | pre { 3 | position: relative; 4 | } 5 | 6 | pre .btnIcon { 7 | position: absolute; 8 | top: 4px; 9 | z-index: 2; 10 | cursor: pointer; 11 | border: 1px solid transparent; 12 | padding: 0; 13 | color: #fff; 14 | background-color: transparent; 15 | height: 30px; 16 | transition: all .25s ease-out; 17 | } 18 | 19 | pre .btnIcon:hover { 20 | text-decoration: none; 21 | } 22 | 23 | .btnIcon__body { 24 | align-items: center; 25 | display: flex; 26 | } 27 | 28 | .btnIcon svg { 29 | fill: currentColor; 30 | margin-right: .4em; 31 | } 32 | 33 | .btnIcon__label { 34 | font-size: 11px; 35 | } 36 | 37 | .btnClipboard { 38 | right: 10px; 39 | } -------------------------------------------------------------------------------- /examples/rust/custom-heap/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-example-custom-heap" 3 | version = "1.0.0" 4 | description = "Solana Program Library Custom Heap Example" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | publish = false 10 | 11 | [features] 12 | default = ["custom-heap"] 13 | custom-heap = [] 14 | no-entrypoint = [] 15 | test-sbf = [] 16 | 17 | [dependencies] 18 | solana-program = "2.1.0" 19 | 20 | [dev-dependencies] 21 | solana-program-test = "2.1.0" 22 | solana-sdk = "2.1.0" 23 | 24 | [lib] 25 | crate-type = ["cdylib", "lib"] 26 | 27 | [package.metadata.docs.rs] 28 | targets = ["x86_64-unknown-linux-gnu"] 29 | 30 | [lints] 31 | workspace = true 32 | -------------------------------------------------------------------------------- /turbo.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://turbo.build/schema.json", 3 | "remoteCache": { 4 | "signature": true 5 | }, 6 | "tasks": { 7 | "build": { 8 | "dependsOn": ["^build"], 9 | "outputs": ["dist/**", "lib/**"] 10 | }, 11 | "build:program": { 12 | "dependsOn": ["^build:program"] 13 | }, 14 | "clean": {}, 15 | "lint:fix": { 16 | "inputs": ["tsconfig*.json", "src/**", "test/**"], 17 | "outputs": [] 18 | }, 19 | "lint": { 20 | "inputs": ["tsconfig*.json", "src/**", "test/**"], 21 | "outputs": [] 22 | }, 23 | "test": { 24 | "inputs": ["src/**", "test/**"], 25 | "outputs": [] 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /binary-oracle-pair/program/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-binary-oracle-pair" 3 | version = "0.1.0" 4 | description = "Solana Program Library Binary Oracle Pair" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [features] 11 | test-sbf = [] 12 | 13 | [dependencies] 14 | num-derive = "0.4" 15 | num-traits = "0.2" 16 | solana-program = "2.1.0" 17 | spl-token = { version = "7.0", features = [ 18 | "no-entrypoint", 19 | ] } 20 | thiserror = "2.0" 21 | uint = "0.10" 22 | borsh = "1.5.3" 23 | 24 | [dev-dependencies] 25 | solana-program-test = "2.1.0" 26 | solana-sdk = "2.1.0" 27 | 28 | [lib] 29 | crate-type = ["cdylib", "lib"] 30 | 31 | [lints] 32 | workspace = true 33 | -------------------------------------------------------------------------------- /token-wrap/program/src/processor.rs: -------------------------------------------------------------------------------- 1 | //! Program state processor 2 | 3 | use { 4 | crate::instruction::TokenWrapInstruction, 5 | solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey}, 6 | spl_token_2022::instruction::decode_instruction_type, 7 | }; 8 | 9 | /// Instruction processor 10 | pub fn process_instruction( 11 | _program_id: &Pubkey, 12 | _accounts: &[AccountInfo], 13 | input: &[u8], 14 | ) -> ProgramResult { 15 | match decode_instruction_type(input)? { 16 | TokenWrapInstruction::CreateMint => { 17 | unimplemented!(); 18 | } 19 | TokenWrapInstruction::Wrap => { 20 | unimplemented!(); 21 | } 22 | TokenWrapInstruction::Unwrap => { 23 | unimplemented!(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /libraries/math-example/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-math-example" 3 | version = "0.1.0" 4 | description = "Solana Program Library Math Example" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [features] 11 | no-entrypoint = [] 12 | test-sbf = [] 13 | 14 | [dependencies] 15 | borsh = "1.5.3" 16 | num-derive = "0.4" 17 | num-traits = "0.2" 18 | solana-program = "2.1.0" 19 | spl-math = { path = "../math", version = "0.3.0" } 20 | thiserror = "2.0" 21 | 22 | [dev-dependencies] 23 | solana-program-test = "2.1.0" 24 | solana-sdk = "2.1.0" 25 | 26 | [lib] 27 | crate-type = ["cdylib", "lib"] 28 | 29 | 30 | [package.metadata.docs.rs] 31 | targets = ["x86_64-unknown-linux-gnu"] 32 | -------------------------------------------------------------------------------- /binary-option/client/requirements.txt: -------------------------------------------------------------------------------- 1 | attrs==21.2.0 2 | base58==2.1.0 3 | certifi==2024.7.4 4 | cffi==1.14.5 5 | chardet==4.0.0 6 | cheroot==8.5.2 7 | CherryPy==18.6.0 8 | construct==2.10.67 9 | cryptography==43.0.1 10 | ed25519==1.5 11 | idna==3.7 12 | iniconfig==1.1.1 13 | jaraco.classes==3.2.1 14 | jaraco.collections==3.3.0 15 | jaraco.functools==3.3.0 16 | jaraco.text==3.5.0 17 | more-itertools==8.8.0 18 | numpy==1.22.0 19 | packaging==20.9 20 | pandas==1.3.0 21 | pluggy==0.13.1 22 | portend==2.7.1 23 | py==1.10.0 24 | pycparser==2.20 25 | PyNaCl==1.4.0 26 | pyparsing==2.4.7 27 | pytest==6.2.4 28 | python-dateutil==2.8.1 29 | pytz==2021.1 30 | requests==2.32.0 31 | six==1.16.0 32 | solana==0.10.0 33 | tempora==4.1.1 34 | toml==0.10.2 35 | typing-extensions==3.10.0.0 36 | urllib3==1.26.19 37 | websockets==9.1 38 | zc.lockfile==2.0 39 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | ## This repo will be archived soon 2 | Active development in this repo is ending 2024-03-02. Anza is continuing development 3 | in program-specific repos under the 4 | [solana-program organization](https://github.com/solana-program). Please refer to 5 | the security policy in individual repos: 6 | 7 | * [associated-token-account](https://github.com/solana-program/associated-token-account/security) 8 | * [feature-proposal](https://github.com/solana-program/feature-proposal/security) 9 | * [memo](https://github.com/solana-program/memo/security) 10 | * [single-pool](https://github.com/solana-program/single-pool/security) 11 | * [stake-pool](https://github.com/solana-program/stake-pool/security) 12 | * [token](https://github.com/solana-program/token/security) 13 | * [token-2022](https://github.com/solana-program/token-2022/security) 14 | -------------------------------------------------------------------------------- /token-lending/cli/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["Solana Labs Maintainers "] 3 | description = "SPL Token Lending CLI" 4 | edition = "2021" 5 | homepage = "https://spl.solana.com/token-lending" 6 | license = "Apache-2.0" 7 | name = "spl-token-lending-cli" 8 | repository = "https://github.com/solana-labs/solana-program-library" 9 | version = "0.2.0" 10 | 11 | [dependencies] 12 | clap = "2.33.3" 13 | solana-clap-utils = "2.1.0" 14 | solana-cli-config = "2.1.0" 15 | solana-client = "2.1.0" 16 | solana-logger = "2.1.0" 17 | solana-sdk = "2.1.0" 18 | solana-program = "2.1.0" 19 | spl-token-lending = { version = "0.2", path="../program", features = [ "no-entrypoint" ] } 20 | spl-token = { version = "7.0", features = [ "no-entrypoint" ] } 21 | 22 | [[bin]] 23 | name = "spl-token-lending" 24 | path = "src/main.rs" 25 | -------------------------------------------------------------------------------- /governance/chat/program/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | //! Program entrypoint 2 | #![cfg(all(target_os = "solana", not(feature = "no-entrypoint")))] 3 | 4 | use { 5 | crate::{error::GovernanceChatError, processor}, 6 | solana_program::{ 7 | account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, 8 | pubkey::Pubkey, 9 | }, 10 | }; 11 | 12 | solana_program::entrypoint!(process_instruction); 13 | fn process_instruction( 14 | program_id: &Pubkey, 15 | accounts: &[AccountInfo], 16 | instruction_data: &[u8], 17 | ) -> ProgramResult { 18 | if let Err(error) = processor::process_instruction(program_id, accounts, instruction_data) { 19 | // catch the error so we can print it 20 | error.print::(); 21 | return Err(error); 22 | } 23 | Ok(()) 24 | } 25 | -------------------------------------------------------------------------------- /governance/program/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | //! Program entrypoint definitions 2 | #![cfg(all(target_os = "solana", not(feature = "no-entrypoint")))] 3 | 4 | use { 5 | crate::{error::GovernanceError, processor}, 6 | solana_program::{ 7 | account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, 8 | pubkey::Pubkey, 9 | }, 10 | }; 11 | 12 | solana_program::entrypoint!(process_instruction); 13 | fn process_instruction( 14 | program_id: &Pubkey, 15 | accounts: &[AccountInfo], 16 | instruction_data: &[u8], 17 | ) -> ProgramResult { 18 | if let Err(error) = processor::process_instruction(program_id, accounts, instruction_data) { 19 | // catch the error so we can print it 20 | error.print::(); 21 | return Err(error); 22 | } 23 | Ok(()) 24 | } 25 | -------------------------------------------------------------------------------- /name-service/program/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-name-service" 3 | description = "Solana Program Library Name Service" 4 | version = "0.3.0" 5 | repository = "https://github.com/solana-labs/solana-program-library" 6 | authors = [ 7 | "lcchy ", 8 | "Solana Labs Maintainers ", 9 | ] 10 | license = "Apache-2.0" 11 | edition = "2021" 12 | 13 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 14 | 15 | [features] 16 | no-entrypoint = [] 17 | test-sbf = [] 18 | 19 | [dependencies] 20 | solana-program = "2.1.0" 21 | num-traits = "0.2" 22 | borsh = "1.5.3" 23 | num-derive = "0.4.2" 24 | thiserror = "2.0.9" 25 | 26 | [dev-dependencies] 27 | solana-program-test = "2.1.0" 28 | solana-sdk = "2.1.0" 29 | 30 | [lib] 31 | crate-type = ["cdylib", "lib"] 32 | -------------------------------------------------------------------------------- /token-swap/proposals/StakePoolStableCurve.md: -------------------------------------------------------------------------------- 1 | # Combine Stable Curve with Stake Pool for price discovery 2 | 3 | Implement a curve for token-swap that accepts stake pool account and uses stable curve to swap assets. 4 | [Stake pool account](https://github.com/solana-labs/solana-program-library/blob/master/stake-pool/program/src/state.rs#L17) will be used for initial price discovery then stable curve would be used to derive price based on the size of the order and available reserves. 5 | 6 | ## Links 7 | 1. Stake pool implementation: https://github.com/solana-labs/solana-program-library/blob/master/stake-pool/program 8 | 2. AMM implementation: https://github.com/solana-labs/solana-program-library/blob/master/token-swap/program 9 | 3. Stable curve: https://github.com/solana-labs/solana-program-library/blob/master/token-swap/program/src/curve/stable.rs 10 | -------------------------------------------------------------------------------- /token-lending/program/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | //! Program entrypoint definitions 2 | 3 | #![cfg(all(target_os = "solana", not(feature = "no-entrypoint")))] 4 | 5 | use { 6 | crate::{error::LendingError, processor}, 7 | solana_program::{ 8 | account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, 9 | pubkey::Pubkey, 10 | }, 11 | }; 12 | 13 | solana_program::entrypoint!(process_instruction); 14 | fn process_instruction( 15 | program_id: &Pubkey, 16 | accounts: &[AccountInfo], 17 | instruction_data: &[u8], 18 | ) -> ProgramResult { 19 | if let Err(error) = processor::process_instruction(program_id, accounts, instruction_data) { 20 | // catch the error so we can print it 21 | error.print::(); 22 | return Err(error); 23 | } 24 | Ok(()) 25 | } 26 | -------------------------------------------------------------------------------- /token-swap/program/fuzz/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-token-swap-fuzz" 3 | version = "0.0.1" 4 | description = "Solana Program Library Token Swap Fuzzer" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | publish = false 10 | 11 | [dependencies] 12 | honggfuzz = { version = "0.5.56" } 13 | arbitrary = { version = "1.4", features = ["derive"] } 14 | solana-program = "2.1.0" 15 | spl-math = { version = "0.3", path = "../../../libraries/math" } 16 | spl-token = { version = "7.0", features = [ "no-entrypoint" ] } 17 | spl-token-swap = { path = "..", features = ["fuzz", "no-entrypoint"] } 18 | 19 | [[bin]] 20 | name = "token-swap-instructions" 21 | path = "src/instructions.rs" 22 | test = false 23 | doc = false 24 | -------------------------------------------------------------------------------- /governance/addin-mock/program/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | //! Program entrypoint 2 | #![cfg(all(target_os = "solana", not(feature = "no-entrypoint")))] 3 | 4 | use { 5 | crate::{error::VoterWeightAddinError, processor}, 6 | solana_program::{ 7 | account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, 8 | pubkey::Pubkey, 9 | }, 10 | }; 11 | 12 | solana_program::entrypoint!(process_instruction); 13 | fn process_instruction( 14 | program_id: &Pubkey, 15 | accounts: &[AccountInfo], 16 | instruction_data: &[u8], 17 | ) -> ProgramResult { 18 | if let Err(error) = processor::process_instruction(program_id, accounts, instruction_data) { 19 | // catch the error so we can print it 20 | error.print::(); 21 | return Err(error); 22 | } 23 | Ok(()) 24 | } 25 | -------------------------------------------------------------------------------- /stateless-asks/program/src/error.rs: -------------------------------------------------------------------------------- 1 | use {solana_program::program_error::ProgramError, thiserror::Error}; 2 | 3 | #[derive(Error, Debug, Copy, Clone)] 4 | pub enum UtilError { 5 | #[error("PublicKeyMismatch")] 6 | PublicKeyMismatch, 7 | #[error("InvalidMintAuthority")] 8 | InvalidMintAuthority, 9 | #[error("UninitializedAccount")] 10 | UninitializedAccount, 11 | #[error("IncorrectOwner")] 12 | IncorrectOwner, 13 | #[error("PublicKeysShouldBeUnique")] 14 | PublicKeysShouldBeUnique, 15 | #[error("StatementFalse")] 16 | StatementFalse, 17 | #[error("NotRentExempt")] 18 | NotRentExempt, 19 | #[error("NumericalOverflow")] 20 | NumericalOverflow, 21 | } 22 | 23 | impl From for ProgramError { 24 | fn from(e: UtilError) -> Self { 25 | ProgramError::Custom(e as u32) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /governance/chat/program/tests/program_test/cookies.rs: -------------------------------------------------------------------------------- 1 | use { 2 | solana_program::pubkey::Pubkey, solana_sdk::signature::Keypair, 3 | spl_governance_chat::state::ChatMessage, 4 | }; 5 | 6 | #[derive(Debug)] 7 | pub struct ChatMessageCookie { 8 | pub address: Pubkey, 9 | pub account: ChatMessage, 10 | } 11 | 12 | #[derive(Debug)] 13 | pub struct ProposalCookie { 14 | pub address: Pubkey, 15 | pub realm_address: Pubkey, 16 | pub governance_address: Pubkey, 17 | pub token_owner_record_address: Pubkey, 18 | pub token_owner: Keypair, 19 | 20 | pub governing_token_mint: Pubkey, 21 | pub governing_token_mint_authority: Keypair, 22 | 23 | pub voter_weight_record: Option, 24 | } 25 | 26 | #[derive(Debug)] 27 | pub struct TokenOwnerRecordCookie { 28 | pub address: Pubkey, 29 | pub token_owner: Keypair, 30 | } 31 | -------------------------------------------------------------------------------- /token-swap/proposals/DynamicMarketMaking.md: -------------------------------------------------------------------------------- 1 | # Openbook DEX Dynamic market making curve for token-swap 2 | 3 | Implement a curve for token-swap that accepts CLOB dex for the same pair. 4 | Implementation should 'split'/'route' portion of order using predefined curve 5 | for the pool and the rest to the dex as IOC order. Dynamic curve should find 6 | ideal size of the order based on the curve parameters and market depth for a 7 | given DEX. 8 | 9 | Ideas: 10 | * CLOB fee discounts 11 | - If pool contains SRM use tressure account to receive `taker` discounts from dex 12 | - Curve can provide additional stake pool for LPs to store SRM to receive `taker` discounts 13 | * Fees 14 | - AMM should charge same fee structure with 30bps difference from fees in CLOB 15 | 16 | ## Links 17 | 1. CLOB implementation: https://github.com/openbook-dex/program/tree/master/dex 18 | -------------------------------------------------------------------------------- /token-wrap/program/src/state.rs: -------------------------------------------------------------------------------- 1 | //! Program state 2 | 3 | use { 4 | bytemuck::{Pod, Zeroable}, 5 | solana_program::pubkey::Pubkey, 6 | }; 7 | 8 | /// Backpointer 9 | /// 10 | /// Since the backpointer account address is derived from the wrapped mint, it 11 | /// allows clients to easily work with wrapped tokens. 12 | /// 13 | /// Try to fetch the account at `get_wrapped_mint_backpointer_address`. 14 | /// * if it doesn't exist, then the token is not wrapped 15 | /// * if it exists, read the data in the account as the unwrapped mint address 16 | /// 17 | /// With this info, clients can easily unwrap tokens, even if they don't know 18 | /// the origin. 19 | #[derive(Copy, Clone, Debug, PartialEq, Pod, Zeroable)] 20 | #[repr(transparent)] 21 | pub struct Backpointer { 22 | /// Address that the wrapped mint is wrapping 23 | pub unwrapped_mint: Pubkey, 24 | } 25 | -------------------------------------------------------------------------------- /binary-oracle-pair/program/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | //! Program entrypoint definitions 2 | 3 | #![cfg(all(target_os = "solana", not(feature = "no-entrypoint")))] 4 | 5 | use { 6 | crate::{error::PoolError, processor}, 7 | solana_program::{ 8 | account_info::AccountInfo, entrypoint::ProgramResult, program_error::PrintProgramError, 9 | pubkey::Pubkey, 10 | }, 11 | }; 12 | 13 | solana_program::entrypoint!(process_instruction); 14 | fn process_instruction( 15 | program_id: &Pubkey, 16 | accounts: &[AccountInfo], 17 | instruction_data: &[u8], 18 | ) -> ProgramResult { 19 | if let Err(error) = 20 | processor::Processor::process_instruction(program_id, accounts, instruction_data) 21 | { 22 | // catch the error so we can print it 23 | error.print::(); 24 | return Err(error); 25 | } 26 | Ok(()) 27 | } 28 | -------------------------------------------------------------------------------- /libraries/concurrent-merkle-tree/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-concurrent-merkle-tree" 3 | version = "0.4.0" 4 | description = "Solana Program Library Concurrent Merkle Tree" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [features] 11 | log = [] 12 | sol-log = ["log"] 13 | 14 | [dependencies] 15 | solana-program = ">=1.18.11,<=2" 16 | bytemuck = "1.21" 17 | thiserror = "2.0.9" 18 | 19 | [dev-dependencies] 20 | rand_distr = "0.4.3" 21 | rand = "0.8" 22 | spl-merkle-tree-reference = { version = "0.1.0", path = "../merkle-tree-reference" } 23 | tokio = { version = "1.42", features = ["full"] } 24 | 25 | [lib] 26 | crate-type = ["cdylib", "lib"] 27 | 28 | [package.metadata.docs.rs] 29 | targets = ["x86_64-unknown-linux-gnu"] 30 | -------------------------------------------------------------------------------- /token-lending/program/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-token-lending" 3 | version = "0.2.0" 4 | description = "Solana Program Library Token Lending" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [features] 11 | no-entrypoint = [] 12 | test-sbf = [] 13 | 14 | [dependencies] 15 | arrayref = "0.3.9" 16 | bytemuck = "1.21.0" 17 | num-derive = "0.4" 18 | num-traits = "0.2" 19 | solana-program = "2.1.0" 20 | spl-token = { version = "7.0", features = [ "no-entrypoint" ] } 21 | thiserror = "2.0" 22 | uint = "0.10" 23 | 24 | [dev-dependencies] 25 | assert_matches = "1.5.0" 26 | proptest = "1.6" 27 | solana-program-test = "2.1.0" 28 | solana-sdk = "2.1.0" 29 | 30 | [lib] 31 | crate-type = ["cdylib", "lib"] 32 | 33 | [lints] 34 | workspace = true 35 | -------------------------------------------------------------------------------- /token-lending/js/README.md: -------------------------------------------------------------------------------- 1 | # SPL Token Lending client library 2 | 3 | This is a JavaScript + TypeScript library for interacting with the [SPL Token Lending](https://github.com/solana-labs/solana-program-library/tree/master/token-lending) program. 4 | 5 | ## Install 6 | 7 | Install the library and its peer dependencies in your app: 8 | 9 | ### Yarn 10 | ```shell 11 | yarn add @solana/spl-token-lending @solana/spl-token @solana/web3.js@1 12 | ``` 13 | 14 | ### NPM 15 | ```shell 16 | npm install @solana/spl-token-lending @solana/spl-token @solana/web3.js@1 17 | ``` 18 | 19 | ## Documentation 20 | 21 | - [Client library docs](https://solana-labs.github.io/solana-program-library/token-lending/) 22 | - [Program docs](https://github.com/solana-labs/solana-program-library/tree/master/token-lending) 23 | - [CLI docs](https://github.com/solana-labs/solana-program-library/tree/master/token-lending/cli) 24 | -------------------------------------------------------------------------------- /ci/install-anchor.sh: -------------------------------------------------------------------------------- 1 | # 2 | # This file maintains the solana versions for use by CI. 3 | # 4 | # Obtain the environment variables without any automatic updating: 5 | # $ source ci/install-anchor.sh 6 | # 7 | # Obtain the environment variables and install update: 8 | # $ source ci/install-anchor.sh install 9 | 10 | # Then to access the anchor version: 11 | # $ echo "$anchor_cli_version" 12 | # 13 | 14 | if [[ -n $ANCHOR_CLI_VERSION ]]; then 15 | anchor_cli_version="$ANCHOR_CLI_VERSION" 16 | else 17 | anchor_cli_version=v0.29.0 18 | fi 19 | 20 | export anchor_cli_version="$anchor_cli_version" 21 | 22 | if [[ -n $1 ]]; then 23 | case $1 in 24 | install) 25 | cargo install --git https://github.com/coral-xyz/anchor --tag $anchor_cli_version anchor-cli --locked 26 | anchor --version 27 | ;; 28 | *) 29 | echo "anchor-version.sh: Note: ignoring unknown argument: $1" >&2 30 | ;; 31 | esac 32 | fi 33 | -------------------------------------------------------------------------------- /ci/solana-version.sh: -------------------------------------------------------------------------------- 1 | # 2 | # This file maintains the solana versions for use by CI. 3 | # 4 | # Obtain the environment variables without any automatic updating: 5 | # $ source ci/solana-version.sh 6 | # 7 | # Obtain the environment variables and install update: 8 | # $ source ci/solana-version.sh install 9 | 10 | # Then to access the solana version: 11 | # $ echo "$solana_version" 12 | # 13 | 14 | if [[ -n $SOLANA_VERSION ]]; then 15 | solana_version="$SOLANA_VERSION" 16 | else 17 | solana_version=v2.1.0 18 | fi 19 | 20 | export solana_version="$solana_version" 21 | export PATH="$HOME"/.local/share/solana/install/active_release/bin:"$PATH" 22 | 23 | if [[ -n $1 ]]; then 24 | case $1 in 25 | install) 26 | sh -c "$(curl -sSfL https://release.anza.xyz/$solana_version/install)" 27 | solana --version 28 | ;; 29 | *) 30 | echo "solana-version.sh: Note: ignoring unknown argument: $1" >&2 31 | ;; 32 | esac 33 | fi 34 | -------------------------------------------------------------------------------- /token-wrap/program/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-token-wrap" 3 | version = "0.1.0" 4 | description = "Solana Program Library Token Wrap" 5 | authors = ["Solana Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2018" 9 | 10 | [features] 11 | no-entrypoint = [] 12 | test-sbf = [] 13 | 14 | [dependencies] 15 | bytemuck = { version = "1.21.0", features = ["derive"] } 16 | num_enum = "0.7" 17 | solana-program = "2.1.0" 18 | spl-associated-token-account = { version = "6.0.0", features = ["no-entrypoint"] } 19 | spl-token = { version = "7.0", features = ["no-entrypoint"] } 20 | spl-token-2022 = { version = "6.0.0", features = ["no-entrypoint"] } 21 | thiserror = "2.0" 22 | 23 | [lib] 24 | crate-type = ["cdylib", "lib"] 25 | 26 | [package.metadata.docs.rs] 27 | targets = ["x86_64-unknown-linux-gnu"] 28 | 29 | [lints] 30 | workspace = true 31 | -------------------------------------------------------------------------------- /governance/test-sdk/src/addins.rs: -------------------------------------------------------------------------------- 1 | use { 2 | lazy_static::lazy_static, 3 | solana_program_test::find_file, 4 | std::{process::Command, sync::Mutex}, 5 | }; 6 | 7 | lazy_static! { 8 | pub static ref VOTER_WEIGHT_ADDIN_BUILD_GUARD: Mutex:: = Mutex::new(0); 9 | } 10 | 11 | pub fn ensure_addin_mock_is_built() { 12 | if find_file("spl_governance_voter_weight_addin_mock.so").is_none() { 13 | let _guard = VOTER_WEIGHT_ADDIN_BUILD_GUARD.lock().unwrap(); 14 | if find_file("spl_governance_addin_mock.so").is_none() { 15 | assert!(Command::new("cargo") 16 | .args([ 17 | "build-sbf", 18 | "--manifest-path", 19 | "../addin-mock/program/Cargo.toml", 20 | ]) 21 | .status() 22 | .expect("Failed to build spl-governance-addin-mock program") 23 | .success()); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ci/warning/purge-ubuntu-runner.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 4 | # WARNING: THIS IS NOT TO BE USED LOCALLY, BUT ONLY IN GITHUB ACTIONS TO CLEAR 5 | # DISK SPACE ON UBUNTU. IT IS NOT MARKED AS EXECUTABLE BY DEFAULT FOR SAFETY AND 6 | # ONLY RUNS IN CI. 7 | # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 8 | if [[ -n "$CI" ]]; then 9 | set -e 10 | 11 | sudo rm -rf /usr/share/dotnet 12 | sudo rm -rf /usr/share/swift 13 | sudo rm -rf /usr/share/mysql 14 | sudo rm -rf /usr/share/az_* 15 | sudo rm -rf /usr/share/postgresql-common 16 | 17 | sudo rm -rf /opt/ghc 18 | sudo rm -rf /opt/az 19 | sudo rm -rf /opt/pipx 20 | sudo rm -rf /opt/microsoft 21 | sudo rm -rf /opt/google 22 | sudo rm -rf /opt/hostedtoolcache 23 | 24 | sudo rm -rf /usr/local/lib/android 25 | sudo rm -rf /usr/local/lib/heroku 26 | sudo rm -rf /imagegeneration 27 | fi 28 | -------------------------------------------------------------------------------- /token-collection/README.md: -------------------------------------------------------------------------------- 1 | # SPL Token Collection 2 | 3 | This program serves as a reference implementation for using the SPL Token Group 4 | interface to create an on-chain program for managing token collections - such 5 | as NFT Collections. 6 | 7 | This program bears a lot of similarity to the example program found at 8 | `token-group/example`, but with some additional implementations centered around 9 | specifically token collections. 10 | 11 | ## How Collections Work in this Program 12 | 13 | Strictly for demonstration purposes, this program is going to require the 14 | following: 15 | 16 | - Group tokens must be NFTs (0 decimals, 1 supply) 17 | - Group tokens must have metadata 18 | - Member tokens can be any SPL token, but must have metadata 19 | - Member tokens can be part of multiple collections 20 | 21 | ## Demonstration 22 | 23 | For a particularly fleshed-out example of this program in action, check out the 24 | `token-collections.rs` test under `tests`! -------------------------------------------------------------------------------- /docs/src/theme/SearchBar/styles.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017-present, Facebook, Inc. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | .search-icon { 9 | background-image: var(--ifm-navbar-search-input-icon); 10 | height: auto; 11 | width: 24px; 12 | cursor: pointer; 13 | padding: 8px; 14 | line-height: 32px; 15 | background-repeat: no-repeat; 16 | background-position: center; 17 | display: none; 18 | } 19 | 20 | .search-icon-hidden { 21 | visibility: hidden; 22 | } 23 | 24 | @media (max-width: 360px) { 25 | .search-bar { 26 | width: 0 !important; 27 | background: none !important; 28 | padding: 0 !important; 29 | transition: none !important; 30 | } 31 | 32 | .search-bar-expanded { 33 | width: 9rem !important; 34 | } 35 | 36 | .search-icon { 37 | display: inline; 38 | vertical-align: sub; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /token-upgrade/program/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-token-upgrade" 3 | version = "0.1.1" 4 | description = "Solana Program Library Token Upgrade" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [features] 11 | no-entrypoint = [] 12 | test-sbf = [] 13 | 14 | [dependencies] 15 | num-derive = "0.4" 16 | num-traits = "0.2" 17 | num_enum = "0.7.3" 18 | solana-program = "2.1.0" 19 | spl-token-2022 = { version = "6.0.0", features = ["no-entrypoint"] } 20 | thiserror = "2.0" 21 | 22 | [dev-dependencies] 23 | solana-program-test = "2.1.0" 24 | solana-sdk = "2.1.0" 25 | spl-token = { version = "7.0", features = ["no-entrypoint"] } 26 | spl-token-client = { version = "0.13.0" } 27 | test-case = "3.3" 28 | 29 | [lib] 30 | crate-type = ["cdylib", "lib"] 31 | 32 | [package.metadata.docs.rs] 33 | targets = ["x86_64-unknown-linux-gnu"] 34 | -------------------------------------------------------------------------------- /account-compression/programs/account-compression/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-account-compression" 3 | version = "0.4.2" 4 | description = "Solana Program Library Account Compression Program" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [lib] 11 | crate-type = ["cdylib", "lib"] 12 | 13 | [features] 14 | no-entrypoint = [] 15 | no-idl = [] 16 | no-log-ix-name = [] 17 | cpi = ["no-entrypoint"] 18 | default = [] 19 | idl-build = ["anchor-lang/idl-build"] 20 | 21 | [dependencies] 22 | anchor-lang = { version = "0.29.0" } 23 | bytemuck = "1.13" 24 | solana-program = ">=1.18.11,<=2" 25 | spl-concurrent-merkle-tree = { version = "0.4.0", path = "../../../libraries/concurrent-merkle-tree" } 26 | spl-noop = { version = "0.2.0", path = "../noop", features = ["no-entrypoint"] } 27 | 28 | [profile.release] 29 | overflow-checks = true 30 | -------------------------------------------------------------------------------- /governance/addin-mock/program/src/error.rs: -------------------------------------------------------------------------------- 1 | //! Error types 2 | 3 | use { 4 | num_derive::FromPrimitive, 5 | solana_program::{ 6 | decode_error::DecodeError, 7 | msg, 8 | program_error::{PrintProgramError, ProgramError}, 9 | }, 10 | thiserror::Error, 11 | }; 12 | 13 | /// Errors that may be returned by the VoterWeightAddin program 14 | #[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] 15 | pub enum VoterWeightAddinError {} 16 | 17 | impl PrintProgramError for VoterWeightAddinError { 18 | fn print(&self) { 19 | msg!("GOVERNANCE-ADDIN-MOCK-ERROR: {}", &self.to_string()); 20 | } 21 | } 22 | 23 | impl From for ProgramError { 24 | fn from(e: VoterWeightAddinError) -> Self { 25 | ProgramError::Custom(e as u32) 26 | } 27 | } 28 | 29 | impl DecodeError for VoterWeightAddinError { 30 | fn type_of() -> &'static str { 31 | "Governance Addin Mock Error" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /libraries/concurrent-merkle-tree/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::arithmetic_side_effects)] 2 | //! # Concurrent Merkle Tree 3 | //! 4 | //! This crate is a Solana-optimized implementation of the 5 | //! concurrent merkle tree data structure introduced in [this 6 | //! whitepaper](https://drive.google.com/file/d/1BOpa5OFmara50fTvL0VIVYjtg-qzHCVc/view) 7 | //! 8 | //! The core implementation of CMT can be found in [concurrent_merkle_tree] 9 | 10 | /// Private macros to enable logging in the Solana runtime 11 | #[macro_use] 12 | mod log; 13 | /// Changelog implementation to keep track of information necessary to fast 14 | /// forward proofs 15 | pub mod changelog; 16 | /// Core implementation of the concurrent merkle tree structure 17 | pub mod concurrent_merkle_tree; 18 | /// Descriptive errors 19 | pub mod error; 20 | /// Hashing utils to support merkle tree operations 21 | pub mod hash; 22 | /// Node implementation and utils 23 | pub mod node; 24 | /// Path implementation 25 | pub mod path; 26 | -------------------------------------------------------------------------------- /.github/workflows/spl_action.yml: -------------------------------------------------------------------------------- 1 | name: Docs Publish 2 | 3 | on: 4 | push: 5 | branches: [master] 6 | paths: 7 | - 'docs/**' 8 | - '.github/workflows/spl_action.yml' 9 | 10 | concurrency: 11 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} 12 | cancel-in-progress: true 13 | 14 | jobs: 15 | build: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - uses: actions/checkout@v4 19 | name: "importing all the document" 20 | - uses: actions/setup-node@v4 21 | with: 22 | node-version: '18' 23 | name: "installing the node.js with version 18" 24 | - name: "Build Docs" 25 | if: ${{ github.event_name == ('push' || 'pull_request')}} && ${{github.ref == 'master'}} 26 | run: | 27 | cd docs/ 28 | npm ci 29 | ./build.sh 30 | env: 31 | VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} 32 | VERCEL_SCOPE: ${{ secrets.VERCEL_SCOPE }} 33 | -------------------------------------------------------------------------------- /token-upgrade/program/src/error.rs: -------------------------------------------------------------------------------- 1 | //! Error types 2 | 3 | use { 4 | num_derive::FromPrimitive, 5 | solana_program::{decode_error::DecodeError, program_error::ProgramError}, 6 | thiserror::Error, 7 | }; 8 | 9 | /// Errors that may be returned by the program. 10 | #[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] 11 | pub enum TokenUpgradeError { 12 | // 0 13 | /// Account does not match address derivation 14 | #[error("Account does not match address derivation")] 15 | InvalidOwner, 16 | /// Decimals of original and new token mint do not match 17 | #[error("Decimals of original and new token mint do not match")] 18 | DecimalsMismatch, 19 | } 20 | impl From for ProgramError { 21 | fn from(e: TokenUpgradeError) -> Self { 22 | ProgramError::Custom(e as u32) 23 | } 24 | } 25 | impl DecodeError for TokenUpgradeError { 26 | fn type_of() -> &'static str { 27 | "TokenUpgradeError" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Docs Readme 2 | 3 | SPL Docs are built using [Docusaurus 2](https://v2.docusaurus.io/) with `npm`. 4 | Static content delivery is handled using `vercel`. 5 | 6 | ### Installing Docusaurus 7 | 8 | ``` 9 | $ npm install 10 | ``` 11 | 12 | ### Local Development 13 | 14 | This command starts a local development server and opens up a browser window. 15 | Most changes are reflected live without having to restart the server. 16 | 17 | ``` 18 | $ npm run start 19 | ``` 20 | 21 | ### Build Locally 22 | 23 | This command generates static content into the `build` directory and can be 24 | served using any static contents hosting service. 25 | 26 | ``` 27 | $ docs/build.sh 28 | ``` 29 | 30 | ### CI Build Flow 31 | 32 | The docs are built and published in Travis CI with the `docs/build.sh` script. 33 | On each PR, the docs are built, but not published. 34 | 35 | In each post-commit build, docs are built and published using `vercel`. 36 | 37 | Documentation is published to spl.solana.com 38 | -------------------------------------------------------------------------------- /stateless-asks/README.md: -------------------------------------------------------------------------------- 1 | # Stateless Offer 2 | 3 | Simple program to make token offers to any bidder that can satisfy 4 | the constraints. 5 | 6 | This program is stateless. It is up to the maker to advertise. It 7 | uses the PDA as a one way hash of the offer that the maker wants 8 | to create. The maker then only needs to approve their token to the 9 | PDA address for the taker to receive the items. The maker doesn't 10 | need to be online to complete the transaction, but needs to advertise 11 | the offer off-chain. 12 | 13 | ## Maker 14 | 1. compute the offer PDA 15 | 2. approve the token delegation for the amount to the PDA 16 | 3. publish the offer off-chain 17 | 18 | ## Taker 19 | 1. Create the offer TX 20 | 2. Submit the TX to the stateless-offer program 21 | 22 | To cancel, the maker simply needs to cancel the delegation. 23 | 24 | ## Audit 25 | 26 | The repository [README](https://github.com/solana-labs/solana-program-library#audits) 27 | contains information about program audits. 28 | -------------------------------------------------------------------------------- /.github/label-actions.yml: -------------------------------------------------------------------------------- 1 | question: 2 | issues: 3 | # Post a comment, `{issue-author}` is an optional placeholder 4 | comment: > 5 | Hi @{issue-author}, 6 | 7 | 8 | Thanks for your question! 9 | 10 | 11 | We want to make sure to keep signal strong in the GitHub issue tracker – to make sure 12 | that it remains the best place to track issues that affect the development of Solana itself. 13 | 14 | 15 | Questions like yours deserve a purpose-built Q&A forum. Unless there exists evidence that 16 | this is a bug with Solana itself, please post your question to the Solana Stack Exchange 17 | using this link: https://solana.stackexchange.com/questions/ask 18 | 19 | 20 | --- 21 | 22 | _This 23 | [automated message](https://github.com/solana-labs/solana-program-library/blob/master/.github/label-actions.yml) 24 | is a result of having added the ‘question’ tag_. 25 | 26 | # Close the issue 27 | close: true 28 | -------------------------------------------------------------------------------- /docs/static/img/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /docs/static/img/dark-mark-white.inline.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /account-compression/sdk/src/types/Path.ts: -------------------------------------------------------------------------------- 1 | import * as beet from '@metaplex-foundation/beet'; 2 | import * as beetSolana from '@metaplex-foundation/beet-solana'; 3 | import { PublicKey } from '@solana/web3.js'; 4 | 5 | /** 6 | * Canopy fields necessary for deserializing an on-chain Path 7 | * used in an {@link ConcurrentMerkleTree} 8 | */ 9 | export type Path = { 10 | // u32 11 | _padding: number; 12 | index: number; 13 | leaf: PublicKey; 14 | proof: PublicKey[]; // u32 15 | }; 16 | 17 | /** 18 | * Factory function for generating a `beet` that can deserialize 19 | * an on-chain {@link Path} 20 | * 21 | * @param maxDepth 22 | * @returns 23 | */ 24 | export const pathBeetFactory = (maxDepth: number) => { 25 | return new beet.BeetArgsStruct( 26 | [ 27 | ['proof', beet.uniformFixedSizeArray(beetSolana.publicKey, maxDepth)], 28 | ['leaf', beetSolana.publicKey], 29 | ['index', beet.u32], 30 | ['_padding', beet.u32], 31 | ], 32 | 'Path', 33 | ); 34 | }; 35 | -------------------------------------------------------------------------------- /examples/rust/logging/src/processor.rs: -------------------------------------------------------------------------------- 1 | //! Program instruction processor 2 | 3 | use solana_program::{ 4 | account_info::AccountInfo, 5 | entrypoint::ProgramResult, 6 | log::{sol_log_compute_units, sol_log_params, sol_log_slice}, 7 | msg, 8 | pubkey::Pubkey, 9 | }; 10 | 11 | /// Instruction processor 12 | pub fn process_instruction( 13 | program_id: &Pubkey, 14 | accounts: &[AccountInfo], 15 | instruction_data: &[u8], 16 | ) -> ProgramResult { 17 | // Log a string 18 | msg!("static string"); 19 | 20 | // Log a slice 21 | sol_log_slice(instruction_data); 22 | 23 | // Log a formatted message, use with caution can be expensive 24 | msg!("formatted {}: {:?}", "message", instruction_data); 25 | 26 | // Log a public key 27 | program_id.log(); 28 | 29 | // Log all the program's input parameters 30 | sol_log_params(accounts, instruction_data); 31 | 32 | // Log the number of compute units remaining that the program can consume. 33 | sol_log_compute_units(); 34 | 35 | Ok(()) 36 | } 37 | -------------------------------------------------------------------------------- /account-compression/sdk/src/generated/types/ChangeLogEventV1.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This code was GENERATED using the solita package. 3 | * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. 4 | * 5 | * See: https://github.com/metaplex-foundation/solita 6 | */ 7 | 8 | import * as beet from '@metaplex-foundation/beet'; 9 | import * as beetSolana from '@metaplex-foundation/beet-solana'; 10 | import * as web3 from '@solana/web3.js'; 11 | 12 | import { PathNode, pathNodeBeet } from './PathNode'; 13 | export type ChangeLogEventV1 = { 14 | id: web3.PublicKey; 15 | index: number; 16 | path: PathNode[]; 17 | seq: beet.bignum; 18 | }; 19 | 20 | /** 21 | * @category userTypes 22 | * @category generated 23 | */ 24 | export const changeLogEventV1Beet = new beet.FixableBeetArgsStruct( 25 | [ 26 | ['id', beetSolana.publicKey], 27 | ['path', beet.array(pathNodeBeet)], 28 | ['seq', beet.u64], 29 | ['index', beet.u32], 30 | ], 31 | 'ChangeLogEventV1', 32 | ); 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "workspaces": [ 4 | "account-compression/sdk", 5 | "token-lending/js", 6 | "token-swap/js" 7 | ], 8 | "scripts": { 9 | "build": "turbo run build", 10 | "build:program": "turbo run build:program", 11 | "clean": "turbo run clean", 12 | "lint": "turbo run lint", 13 | "format": "prettier --check .", 14 | "format:fix": "prettier --write .", 15 | "test": "turbo run test" 16 | }, 17 | "devDependencies": { 18 | "@solana/eslint-config-solana": "^4.0.0", 19 | "@solana/prettier-config-solana": "^0.0.5", 20 | "eslint-config-prettier": "^9.1.0", 21 | "eslint-config-turbo": "^2.3.3", 22 | "eslint-plugin-prettier": "^5.2.1", 23 | "prettier": "^3.4.2", 24 | "turbo": "^2.3.3" 25 | }, 26 | "engines": { 27 | "node": ">=14.0.0" 28 | }, 29 | "packageManager": "pnpm@8.14.3", 30 | "prettier": "@solana/prettier-config-solana", 31 | "name": "solana-program-library" 32 | } 33 | -------------------------------------------------------------------------------- /examples/c/src/transfer-lamports/transfer-lamports.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @brief A program demonstrating the transfer of lamports 3 | */ 4 | #include 5 | 6 | extern uint64_t transfer(SolParameters *params) { 7 | // As part of the program specification the first account is the source 8 | // account and the second is the destination account 9 | if (params->ka_num != 2) { 10 | return ERROR_NOT_ENOUGH_ACCOUNT_KEYS; 11 | } 12 | SolAccountInfo *source_info = ¶ms->ka[0]; 13 | SolAccountInfo *destination_info = ¶ms->ka[1]; 14 | 15 | // Withdraw five lamports from the source 16 | *source_info->lamports -= 5; 17 | // Deposit five lamports into the destination 18 | *destination_info->lamports += 5; 19 | 20 | return SUCCESS; 21 | } 22 | 23 | extern uint64_t entrypoint(const uint8_t *input) { 24 | SolAccountInfo accounts[2]; 25 | SolParameters params = (SolParameters){.ka = accounts}; 26 | 27 | if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(accounts))) { 28 | return ERROR_INVALID_ARGUMENT; 29 | } 30 | 31 | return transfer(¶ms); 32 | } 33 | -------------------------------------------------------------------------------- /examples/rust/custom-heap/tests/functional.rs: -------------------------------------------------------------------------------- 1 | use { 2 | solana_program::{instruction::Instruction, pubkey::Pubkey}, 3 | solana_program_test::*, 4 | solana_sdk::{signature::Signer, transaction::Transaction}, 5 | spl_example_custom_heap::processor::process_instruction, 6 | std::str::FromStr, 7 | }; 8 | 9 | #[tokio::test] 10 | async fn test_custom_heap() { 11 | let program_id = Pubkey::from_str("CustomHeap111111111111111111111111111111111").unwrap(); 12 | let (banks_client, payer, recent_blockhash) = ProgramTest::new( 13 | "spl_example_custom_heap", 14 | program_id, 15 | processor!(process_instruction), 16 | ) 17 | .start() 18 | .await; 19 | let mut transaction = Transaction::new_with_payer( 20 | &[Instruction::new_with_bincode( 21 | program_id, 22 | &[10_u8, 11, 12, 13, 14], 23 | vec![], 24 | )], 25 | Some(&payer.pubkey()), 26 | ); 27 | transaction.sign(&[&payer], recent_blockhash); 28 | banks_client.process_transaction(transaction).await.unwrap(); 29 | } 30 | -------------------------------------------------------------------------------- /token-lending/js/src/instructions/refreshReserve.ts: -------------------------------------------------------------------------------- 1 | import { PublicKey, SYSVAR_CLOCK_PUBKEY, TransactionInstruction } from '@solana/web3.js'; 2 | import { struct, u8 } from '@solana/buffer-layout'; 3 | import { LENDING_PROGRAM_ID } from '../constants'; 4 | import { LendingInstruction } from './instruction'; 5 | 6 | interface Data { 7 | instruction: number; 8 | } 9 | 10 | const DataLayout = struct([u8('instruction')]); 11 | 12 | export const refreshReserveInstruction = (reserve: PublicKey, oracle: PublicKey): TransactionInstruction => { 13 | const data = Buffer.alloc(DataLayout.span); 14 | DataLayout.encode({ instruction: LendingInstruction.RefreshReserve }, data); 15 | 16 | const keys = [ 17 | { pubkey: reserve, isSigner: false, isWritable: true }, 18 | { pubkey: oracle, isSigner: false, isWritable: false }, 19 | { pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, 20 | ]; 21 | 22 | return new TransactionInstruction({ 23 | keys, 24 | programId: LENDING_PROGRAM_ID, 25 | data, 26 | }); 27 | }; 28 | -------------------------------------------------------------------------------- /name-service/js/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "parserOptions": { "project": "./tsconfig.json" }, 5 | "env": { "es6": true }, 6 | "ignorePatterns": ["node_modules", "build", "coverage"], 7 | "plugins": ["import", "eslint-comments"], 8 | "extends": [ 9 | "eslint:recommended", 10 | "plugin:eslint-comments/recommended", 11 | "plugin:@typescript-eslint/recommended", 12 | "plugin:import/typescript", 13 | "prettier" 14 | ], 15 | "globals": { "BigInt": true, "console": true, "WebAssembly": true }, 16 | "rules": { 17 | "@typescript-eslint/explicit-module-boundary-types": "off", 18 | "eslint-comments/disable-enable-pair": [ 19 | "error", 20 | { "allowWholeFile": true } 21 | ], 22 | "eslint-comments/no-unused-disable": "error", 23 | "import/order": [ 24 | "error", 25 | { "newlines-between": "always", "alphabetize": { "order": "asc" } } 26 | ], 27 | "sort-imports": [ 28 | "error", 29 | { "ignoreDeclarationSort": true, "ignoreCase": true } 30 | ] 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /governance/program/src/state/native_treasury.rs: -------------------------------------------------------------------------------- 1 | //! Native treasury account 2 | 3 | use { 4 | borsh::{BorshDeserialize, BorshSchema, BorshSerialize}, 5 | solana_program::pubkey::Pubkey, 6 | spl_governance_tools::account::AccountMaxSize, 7 | }; 8 | 9 | /// Treasury account 10 | /// The account has no data and can be used as a payer for instruction signed by 11 | /// Governance PDAs or as a native SOL treasury 12 | #[derive(Clone, Debug, PartialEq, Eq, BorshDeserialize, BorshSerialize, BorshSchema)] 13 | pub struct NativeTreasury {} 14 | 15 | impl AccountMaxSize for NativeTreasury { 16 | fn get_max_size(&self) -> Option { 17 | Some(0) 18 | } 19 | } 20 | 21 | /// Returns NativeTreasury PDA seeds 22 | pub fn get_native_treasury_address_seeds(governance: &Pubkey) -> [&[u8]; 2] { 23 | [b"native-treasury", governance.as_ref()] 24 | } 25 | 26 | /// Returns NativeTreasury PDA address 27 | pub fn get_native_treasury_address(program_id: &Pubkey, governance: &Pubkey) -> Pubkey { 28 | Pubkey::find_program_address(&get_native_treasury_address_seeds(governance), program_id).0 29 | } 30 | -------------------------------------------------------------------------------- /account-compression/sdk/src/generated/types/ConcurrentMerkleTreeHeader.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This code was GENERATED using the solita package. 3 | * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. 4 | * 5 | * See: https://github.com/metaplex-foundation/solita 6 | */ 7 | 8 | import * as beet from '@metaplex-foundation/beet'; 9 | 10 | import { CompressionAccountType, compressionAccountTypeBeet } from './CompressionAccountType'; 11 | import { ConcurrentMerkleTreeHeaderData, concurrentMerkleTreeHeaderDataBeet } from './ConcurrentMerkleTreeHeaderData'; 12 | export type ConcurrentMerkleTreeHeader = { 13 | accountType: CompressionAccountType; 14 | header: ConcurrentMerkleTreeHeaderData; 15 | }; 16 | 17 | /** 18 | * @category userTypes 19 | * @category generated 20 | */ 21 | export const concurrentMerkleTreeHeaderBeet = new beet.FixableBeetArgsStruct( 22 | [ 23 | ['accountType', compressionAccountTypeBeet], 24 | ['header', concurrentMerkleTreeHeaderDataBeet], 25 | ], 26 | 'ConcurrentMerkleTreeHeader', 27 | ); 28 | -------------------------------------------------------------------------------- /token-swap/js/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "extends": [ 4 | "eslint:recommended", 5 | "plugin:@typescript-eslint/recommended", 6 | "plugin:prettier/recommended", 7 | "plugin:require-extensions/recommended" 8 | ], 9 | "parser": "@typescript-eslint/parser", 10 | "plugins": [ 11 | "@typescript-eslint", 12 | "prettier", 13 | "require-extensions" 14 | ], 15 | "rules": { 16 | "@typescript-eslint/ban-ts-comment": "off", 17 | "@typescript-eslint/no-explicit-any": "off", 18 | "@typescript-eslint/no-unused-vars": "off", 19 | "@typescript-eslint/no-empty-interface": "off", 20 | "@typescript-eslint/consistent-type-imports": "error" 21 | }, 22 | "overrides": [ 23 | { 24 | "files": [ 25 | "examples/**/*", 26 | "test/**/*" 27 | ], 28 | "rules": { 29 | "require-extensions/require-extensions": "off", 30 | "require-extensions/require-index": "off" 31 | } 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /examples/c/src/logging/logging.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @brief A program demonstrating logging 3 | */ 4 | #include 5 | 6 | extern uint64_t logging(SolParameters *params) { 7 | // Log a string 8 | sol_log("static string"); 9 | 10 | // Log 5 numbers as u64s in hexadecimal format 11 | sol_log_64(params->data[0], params->data[1], params->data[2], params->data[3], 12 | params->data[4]); 13 | 14 | // Log a slice 15 | sol_log_array(params->data, params->data_len); 16 | 17 | // Log a public key 18 | sol_log_pubkey(params->program_id); 19 | 20 | // Log all the program's input parameters 21 | sol_log_params(params); 22 | 23 | // Log the number of compute units remaining that the program can consume. 24 | sol_log_compute_units(); 25 | 26 | return SUCCESS; 27 | } 28 | 29 | extern uint64_t entrypoint(const uint8_t *input) { 30 | SolAccountInfo accounts[1]; 31 | SolParameters params = (SolParameters){.ka = accounts}; 32 | 33 | if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(accounts))) { 34 | return ERROR_INVALID_ARGUMENT; 35 | } 36 | 37 | return logging(¶ms); 38 | } 39 | -------------------------------------------------------------------------------- /token-swap/proposals/Pausable.md: -------------------------------------------------------------------------------- 1 | # Pausable & Ownable 2 | 3 | Implement two programs for SPL that can be used to extend contracts with ability to pause, resume and check for the owner before instructions are executed. 4 | 5 | An Owner program with the instructions you've listed: 6 | 7 | - set owner 8 | - renounce ownership 9 | - check owner 10 | 11 | Additionally: 12 | * an Owner struct should contain Option 13 | * library code should generate a pda, probably given (struct_key, program_id) 14 | 15 | Given an Owner program, compose it with the Pause program. 16 | 17 | - pause 18 | - resume 19 | 20 | Note: only owner can pause/resume normal operations 21 | 22 | For both programs provide example usage from other programs via CPI and unit tests. 23 | 24 | Links: 25 | * [Pausable solidity contract](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/24a0bc23cfe3fbc76f8f2510b78af1e948ae6651/contracts/security/Pausable.sol) 26 | * [Ownable solidity contract](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/24a0bc23cfe3fbc76f8f2510b78af1e948ae6651/contracts/access/Ownable.sol) 27 | -------------------------------------------------------------------------------- /managed-token/program/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-managed-token" 3 | version = "0.1.0" 4 | description = "Solana Program Library Token Swap" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 11 | 12 | [lib] 13 | crate-type = ["cdylib", "lib"] 14 | name = "spl_managed_token" 15 | 16 | [features] 17 | no-entrypoint = [] 18 | no-idl = [] 19 | no-log-ix-name = [] 20 | cpi = ["no-entrypoint"] 21 | default = [] 22 | test = [] 23 | 24 | [dependencies] 25 | borsh = "1.5.3" 26 | shank = "^0.4.2" 27 | solana-program = "2.1.0" 28 | spl-associated-token-account = { version = "6.0.0", features = [ 29 | "no-entrypoint", 30 | ] } 31 | spl-associated-token-account-client = { version = "2.0.0" } 32 | spl-token = { version = "7.0", features = [ 33 | "no-entrypoint", 34 | ] } 35 | thiserror = "^2.0.9" 36 | 37 | [dev-dependencies] 38 | solana-program-test = "2.1.0" 39 | solana-sdk = "2.1.0" 40 | -------------------------------------------------------------------------------- /account-compression/programs/account-compression/src/zero_copy.rs: -------------------------------------------------------------------------------- 1 | //! Implements ZeroCopy over ConcurrrentMerkleTree generics 2 | use crate::error::error_msg; 3 | use anchor_lang::prelude::*; 4 | use bytemuck::Pod; 5 | use spl_concurrent_merkle_tree::concurrent_merkle_tree::ConcurrentMerkleTree; 6 | use std::mem::size_of; 7 | 8 | pub trait ZeroCopy: Pod { 9 | fn load_mut_bytes<'a>(data: &'a mut [u8]) -> Result<&'a mut Self> { 10 | let size = size_of::(); 11 | let data_len = data.len(); 12 | 13 | Ok(bytemuck::try_from_bytes_mut(&mut data[..size]) 14 | .map_err(error_msg::(data_len)) 15 | .unwrap()) 16 | } 17 | 18 | fn load_bytes<'a>(data: &'a [u8]) -> Result<&'a Self> { 19 | let size = size_of::(); 20 | let data_len = data.len(); 21 | 22 | Ok(bytemuck::try_from_bytes(&data[..size]) 23 | .map_err(error_msg::(data_len)) 24 | .unwrap()) 25 | } 26 | } 27 | 28 | impl ZeroCopy 29 | for ConcurrentMerkleTree 30 | { 31 | } 32 | -------------------------------------------------------------------------------- /examples/rust/transfer-lamports/src/processor.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::arithmetic_side_effects)] 2 | //! Program instruction processor 3 | 4 | use solana_program::{ 5 | account_info::{next_account_info, AccountInfo}, 6 | entrypoint::ProgramResult, 7 | pubkey::Pubkey, 8 | }; 9 | 10 | /// Instruction processor 11 | pub fn process_instruction( 12 | _program_id: &Pubkey, 13 | accounts: &[AccountInfo], 14 | _instruction_data: &[u8], 15 | ) -> ProgramResult { 16 | // Create an iterator to safely reference accounts in the slice 17 | let account_info_iter = &mut accounts.iter(); 18 | 19 | // As part of the program specification the first account is the source 20 | // account and the second is the destination account 21 | let source_info = next_account_info(account_info_iter)?; 22 | let destination_info = next_account_info(account_info_iter)?; 23 | 24 | // Withdraw five lamports from the source 25 | **source_info.try_borrow_mut_lamports()? -= 5; 26 | // Deposit five lamports into the destination 27 | **destination_info.try_borrow_mut_lamports()? += 5; 28 | 29 | Ok(()) 30 | } 31 | -------------------------------------------------------------------------------- /ci/cargo-build-test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | cd "$(dirname "$0")/.." 5 | 6 | source ./ci/rust-version.sh stable 7 | source ./ci/solana-version.sh 8 | 9 | export RUSTFLAGS="-D warnings" 10 | export RUSTBACKTRACE=1 11 | 12 | set -x 13 | 14 | # Build all C examples 15 | make -C examples/c 16 | 17 | # Build/test all host crates 18 | cargo +"$rust_stable" build --workspace --exclude spl-token-cli --exclude spl-token-upgrade-cli --exclude spl-single-pool-cli --exclude spl-transfer-hook-cli 19 | cargo +"$rust_stable" test --workspace --exclude spl-token-cli --exclude spl-token-upgrade-cli --exclude spl-single-pool-cli --exclude spl-transfer-hook-cli -- --nocapture 20 | 21 | # Run test-client sanity check 22 | cargo +"$rust_stable" run --manifest-path=utils/test-client/Cargo.toml 23 | 24 | # # Check generated C headers 25 | # cargo run --manifest-path=utils/cgen/Cargo.toml 26 | # 27 | # git diff --exit-code token/program/inc/token.h 28 | # cc token/program/inc/token.h -o target/token.gch 29 | # git diff --exit-code token-swap/program/inc/token-swap.h 30 | # cc token-swap/program/inc/token-swap.h -o target/token-swap.gch 31 | 32 | exit 0 33 | -------------------------------------------------------------------------------- /account-compression/sdk/tests/events/applicationData.test.ts: -------------------------------------------------------------------------------- 1 | import { strict as assert } from 'node:assert'; 2 | 3 | import { BN } from 'bn.js'; 4 | 5 | import { deserializeApplicationDataEvent } from '../../src'; 6 | 7 | describe('Serde tests', () => { 8 | describe('ApplicationDataEvent tests', () => { 9 | it('Can serialize and deserialize ApplicationDataEvent', () => { 10 | const data = Buffer.from('Hello world'); 11 | const applicationDataEvent = Buffer.concat([ 12 | Buffer.from([0x1]), // ApplicationData Event tag 13 | Buffer.from([0x0]), // version 0 tag 14 | Buffer.from(new BN.BN(data.length).toArray('le', 4)), // Size of application data (for Vec) 15 | data, // serialized application data (for Vec) 16 | ]); 17 | 18 | const deserialized = deserializeApplicationDataEvent(applicationDataEvent); 19 | const decoder = new TextDecoder(); 20 | const deserializedData = decoder.decode(deserialized.fields[0].applicationData); 21 | assert('Hello world' === deserializedData); 22 | }); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /examples/rust/logging/tests/functional.rs: -------------------------------------------------------------------------------- 1 | use { 2 | solana_program::{ 3 | instruction::{AccountMeta, Instruction}, 4 | pubkey::Pubkey, 5 | }, 6 | solana_program_test::*, 7 | solana_sdk::{signature::Signer, transaction::Transaction}, 8 | spl_example_logging::processor::process_instruction, 9 | std::str::FromStr, 10 | }; 11 | 12 | #[tokio::test] 13 | async fn test_logging() { 14 | let program_id = Pubkey::from_str("Logging111111111111111111111111111111111111").unwrap(); 15 | let (banks_client, payer, recent_blockhash) = ProgramTest::new( 16 | "spl_example_logging", 17 | program_id, 18 | processor!(process_instruction), 19 | ) 20 | .start() 21 | .await; 22 | let mut transaction = Transaction::new_with_payer( 23 | &[Instruction::new_with_bincode( 24 | program_id, 25 | &[10_u8, 11, 12, 13, 14], 26 | vec![AccountMeta::new(Pubkey::new_unique(), false)], 27 | )], 28 | Some(&payer.pubkey()), 29 | ); 30 | transaction.sign(&[&payer], recent_blockhash); 31 | banks_client.process_transaction(transaction).await.unwrap(); 32 | } 33 | -------------------------------------------------------------------------------- /token-collection/program/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-token-collection" 3 | version = "0.1.0" 4 | description = "Solana Program Library Token Collection" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [features] 11 | no-entrypoint = [] 12 | test-sbf = [] 13 | 14 | [dependencies] 15 | solana-program = "2.1.0" 16 | spl-pod = { version = "0.5.0" } 17 | spl-program-error = { version = "0.6.0" } 18 | spl-token-2022 = { version = "6.0.0", features = ["no-entrypoint"] } 19 | spl-token-group-example = { version = "0.2", features = ["no-entrypoint"] } 20 | spl-token-group-interface = { version = "0.5.0" } 21 | spl-token-metadata-interface = { version = "0.6.0" } 22 | spl-type-length-value = { version = "0.7.0" } 23 | 24 | [dev-dependencies] 25 | solana-program-test = "2.1.0" 26 | solana-sdk = "2.1.0" 27 | spl-discriminator = { version = "0.4.0" } 28 | spl-token-client = { version = "0.13.0" } 29 | 30 | [lib] 31 | crate-type = ["cdylib", "lib"] 32 | 33 | [package.metadata.docs.rs] 34 | targets = ["x86_64-unknown-linux-gnu"] 35 | -------------------------------------------------------------------------------- /account-compression/sdk/src/types/Canopy.ts: -------------------------------------------------------------------------------- 1 | import * as beet from '@metaplex-foundation/beet'; 2 | 3 | /** 4 | * Canopy fields necessary for deserializing an on-chain Canopy 5 | * for a {@link ConcurrentMerkleTreeAccount} 6 | */ 7 | export type Canopy = { 8 | canopyBytes: number[]; 9 | }; 10 | 11 | /** 12 | * Factory function for generating a `beet` that can deserialize 13 | * an on-chain {@link Canopy} 14 | * 15 | * {@link Canopy} of depth `N` is an on-chain cache of the top 16 | * `N` nodes in the {@link ConcurrentMerkleTree}. This is a total 17 | * of `2^(N+1) - 1` nodes. Each node has `32` bytes. 18 | * However, the current root of the tree is always stored in the 19 | * most recent {@link ChangeLog}, so we only need to cache the remaining `N-1` levels. 20 | * 21 | * The final formula for account size in bytes: `(2^(N) - 1 - 1) * 32`. 22 | * 23 | * @param canopyDepth 24 | * @returns 25 | */ 26 | export const canopyBeetFactory = (canopyDepth: number) => { 27 | return new beet.BeetArgsStruct( 28 | [['canopyBytes', beet.uniformFixedSizeArray(beet.u8, Math.max(((1 << (canopyDepth + 1)) - 2) * 32, 0))]], 29 | 'Canopy', 30 | ); 31 | }; 32 | -------------------------------------------------------------------------------- /docs/src/shared-memory.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Shared memory Program 3 | --- 4 | 5 | A simple program and highly optimized program that writes instruction data into 6 | the provided account's data 7 | 8 | ## Background 9 | 10 | Solana's programming model and the definitions of the Solana terms used in this 11 | document are available at: 12 | 13 | - https://docs.solana.com/apps 14 | - https://docs.solana.com/terminology 15 | 16 | ## Source 17 | 18 | The Shared memory Program's source is available on 19 | [GitHub](https://github.com/solana-labs/solana-program-library) 20 | 21 | ## Interface 22 | 23 | The Shared memory program expects one account and writes instruction data into 24 | the account's data. The first 8 bytes of the instruction data contain the 25 | little-endian offset into the account data. The rest of the instruction data is 26 | written into the account data starting at that offset. 27 | 28 | ## Operational overview 29 | 30 | This program is useful for returning data from cross-program invoked programs to 31 | the invoker. Because the account does not need to be signed it is not reliable 32 | to use this program to pass data between programs from different transactions. 33 | -------------------------------------------------------------------------------- /token-lending/program/src/math/common.rs: -------------------------------------------------------------------------------- 1 | //! Common module for Decimal and Rate 2 | 3 | use solana_program::program_error::ProgramError; 4 | 5 | /// Scale of precision 6 | pub const SCALE: usize = 18; 7 | /// Identity 8 | pub const WAD: u64 = 1_000_000_000_000_000_000; 9 | /// Half of identity 10 | pub const HALF_WAD: u64 = 500_000_000_000_000_000; 11 | /// Scale for percentages 12 | pub const PERCENT_SCALER: u64 = 10_000_000_000_000_000; 13 | 14 | /// Try to subtract, return an error on underflow 15 | pub trait TrySub: Sized { 16 | /// Subtract 17 | fn try_sub(self, rhs: Self) -> Result; 18 | } 19 | 20 | /// Try to subtract, return an error on overflow 21 | pub trait TryAdd: Sized { 22 | /// Add 23 | fn try_add(self, rhs: Self) -> Result; 24 | } 25 | 26 | /// Try to divide, return an error on overflow or divide by zero 27 | pub trait TryDiv: Sized { 28 | /// Divide 29 | fn try_div(self, rhs: RHS) -> Result; 30 | } 31 | 32 | /// Try to multiply, return an error on overflow 33 | pub trait TryMul: Sized { 34 | /// Multiply 35 | fn try_mul(self, rhs: RHS) -> Result; 36 | } 37 | -------------------------------------------------------------------------------- /binary-option/program/src/error.rs: -------------------------------------------------------------------------------- 1 | use {solana_program::program_error::ProgramError, thiserror::Error}; 2 | 3 | #[derive(Error, Debug, Copy, Clone)] 4 | pub enum BinaryOptionError { 5 | #[error("PublicKeyMismatch")] 6 | PublicKeyMismatch, 7 | #[error("InvalidMintAuthority")] 8 | InvalidMintAuthority, 9 | #[error("NotMintAuthority")] 10 | NotMintAuthority, 11 | #[error("InvalidSupply")] 12 | InvalidSupply, 13 | #[error("InvalidWinner")] 14 | InvalidWinner, 15 | #[error("UninitializedAccount")] 16 | UninitializedAccount, 17 | #[error("IncorrectOwner")] 18 | IncorrectOwner, 19 | #[error("AlreadySettled")] 20 | AlreadySettled, 21 | #[error("BetNotSettled")] 22 | BetNotSettled, 23 | #[error("TokenNotFoundInPool")] 24 | TokenNotFoundInPool, 25 | #[error("PublicKeysShouldBeUnique")] 26 | PublicKeysShouldBeUnique, 27 | #[error("TradePricesIncorrect")] 28 | TradePricesIncorrect, 29 | #[error("AmountOverflow")] 30 | AmountOverflow, 31 | } 32 | 33 | impl From for ProgramError { 34 | fn from(e: BinaryOptionError) -> Self { 35 | ProgramError::Custom(e as u32) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /token-swap/program/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-token-swap" 3 | version = "3.0.0" 4 | description = "Solana Program Library Token Swap" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [features] 11 | no-entrypoint = [] 12 | production = [] 13 | fuzz = ["arbitrary", "roots"] 14 | 15 | [dependencies] 16 | arrayref = "0.3.9" 17 | enum_dispatch = "0.3.13" 18 | num-derive = "0.4" 19 | num-traits = "0.2" 20 | solana-program = "2.1.0" 21 | spl-math = { version = "0.3", path = "../../libraries/math" } 22 | spl-token = { version = "7.0", features = [ "no-entrypoint" ] } 23 | spl-token-2022 = { version = "6.0.0", features = [ "no-entrypoint" ] } 24 | thiserror = "2.0" 25 | arbitrary = { version = "1.4", features = ["derive"], optional = true } 26 | roots = { version = "0.0.8", optional = true } 27 | 28 | [dev-dependencies] 29 | proptest = "1.6" 30 | roots = "0.0.8" 31 | solana-sdk = "2.1.0" 32 | test-case = "3.3" 33 | 34 | [lib] 35 | crate-type = ["cdylib", "lib"] 36 | 37 | [package.metadata.docs.rs] 38 | targets = ["x86_64-unknown-linux-gnu"] 39 | -------------------------------------------------------------------------------- /name-service/program/src/entrypoint.rs: -------------------------------------------------------------------------------- 1 | use { 2 | crate::{error::NameServiceError, processor::Processor}, 3 | num_traits::FromPrimitive, 4 | solana_program::{ 5 | account_info::AccountInfo, decode_error::DecodeError, entrypoint::ProgramResult, msg, 6 | program_error::PrintProgramError, pubkey::Pubkey, 7 | }, 8 | }; 9 | 10 | solana_program::entrypoint!(process_instruction); 11 | 12 | pub fn process_instruction( 13 | program_id: &Pubkey, 14 | accounts: &[AccountInfo], 15 | instruction_data: &[u8], 16 | ) -> ProgramResult { 17 | msg!("Entrypoint"); 18 | if let Err(error) = Processor::process_instruction(program_id, accounts, instruction_data) { 19 | // catch the error so we can print it 20 | error.print::(); 21 | return Err(error); 22 | } 23 | Ok(()) 24 | } 25 | 26 | impl PrintProgramError for NameServiceError { 27 | fn print(&self) 28 | where 29 | E: 'static + std::error::Error + DecodeError + PrintProgramError + FromPrimitive, 30 | { 31 | match self { 32 | NameServiceError::OutOfSpace => msg!("Error: Registry is out of space!"), 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /governance/addin-mock/program/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-governance-addin-mock" 3 | version = "0.1.4" 4 | description = "Solana Program Library Governance Voter Weight Addin Program" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [features] 11 | no-entrypoint = [] 12 | test-sbf = [] 13 | 14 | [dependencies] 15 | arrayref = "0.3.9" 16 | bincode = "1.3.2" 17 | borsh = "1.5.3" 18 | num-derive = "0.4" 19 | num-traits = "0.2" 20 | serde = "1.0.217" 21 | serde_derive = "1.0.103" 22 | solana-program = "2.1.0" 23 | spl-token = { version = "7.0", features = [ 24 | "no-entrypoint", 25 | ] } 26 | spl-governance-addin-api = { version = "0.1.4", path = "../../addin-api" } 27 | spl-governance-tools = { version = "0.1.4", path = "../../tools" } 28 | thiserror = "2.0" 29 | 30 | 31 | [dev-dependencies] 32 | assert_matches = "1.5.0" 33 | proptest = "1.6" 34 | solana-program-test = "2.1.0" 35 | solana-sdk = "2.1.0" 36 | spl-governance-test-sdk = { version = "0.1.4", path = "../../test-sdk" } 37 | 38 | 39 | [lib] 40 | crate-type = ["cdylib", "lib"] 41 | 42 | [lints] 43 | workspace = true 44 | -------------------------------------------------------------------------------- /governance/program/src/processor/process_set_governance_delegate.rs: -------------------------------------------------------------------------------- 1 | //! Program state processor 2 | 3 | use { 4 | crate::state::token_owner_record::get_token_owner_record_data, 5 | solana_program::{ 6 | account_info::{next_account_info, AccountInfo}, 7 | entrypoint::ProgramResult, 8 | pubkey::Pubkey, 9 | }, 10 | }; 11 | 12 | /// Processes SetGovernanceDelegate instruction 13 | pub fn process_set_governance_delegate( 14 | program_id: &Pubkey, 15 | accounts: &[AccountInfo], 16 | new_governance_delegate: &Option, 17 | ) -> ProgramResult { 18 | let account_info_iter = &mut accounts.iter(); 19 | 20 | let governance_authority_info = next_account_info(account_info_iter)?; // 0 21 | let token_owner_record_info = next_account_info(account_info_iter)?; // 1 22 | 23 | let mut token_owner_record_data = 24 | get_token_owner_record_data(program_id, token_owner_record_info)?; 25 | 26 | token_owner_record_data.assert_token_owner_or_delegate_is_signer(governance_authority_info)?; 27 | 28 | token_owner_record_data.governance_delegate = *new_governance_delegate; 29 | token_owner_record_data.serialize(&mut token_owner_record_info.data.borrow_mut()[..])?; 30 | 31 | Ok(()) 32 | } 33 | -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "solana-spl-docs", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "docusaurus start", 7 | "build": "docusaurus build", 8 | "serve": "docusaurus serve", 9 | "swizzle": "docusaurus swizzle", 10 | "deploy": "docusaurus deploy", 11 | "format": "prettier --check \"**/*.{js,jsx,json,md,scss}\"", 12 | "format:fix": "prettier --write \"**/*.{js,jsx,json,md,scss}\"", 13 | "lint": "set -ex; eslint .", 14 | "lint:fix": "npm run lint -- --fix" 15 | }, 16 | "dependencies": { 17 | "@babel/eslint-parser": "^7.2.0", 18 | "@docusaurus/core": "^3.0.0", 19 | "@docusaurus/preset-classic": "^3.0.0", 20 | "autocomplete.js": "^0.38.1", 21 | "clsx": "^1.1.1", 22 | "docusaurus-lunr-search": "^3.3.0", 23 | "eslint": "^7.3.1", 24 | "eslint-plugin-react": "^7.28.0", 25 | "prettier": "^2.0.5", 26 | "react": "^18.0.0", 27 | "react-dom": "^18.0.0" 28 | }, 29 | "browserslist": { 30 | "production": [ 31 | ">0.2%", 32 | "not dead", 33 | "not op_mini all" 34 | ], 35 | "development": [ 36 | "last 1 chrome version", 37 | "last 1 firefox version", 38 | "last 1 safari version" 39 | ] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /account-compression/sdk/tests/merkleTree.test.ts: -------------------------------------------------------------------------------- 1 | import { strict as assert } from 'node:assert'; 2 | 3 | import * as crypto from 'crypto'; 4 | 5 | import { emptyNode, MerkleTree } from '../src'; 6 | 7 | describe('MerkleTree tests', () => { 8 | it('Check constructor equivalence for depth 2 tree', () => { 9 | const leaves = [crypto.randomBytes(32), crypto.randomBytes(32), crypto.randomBytes(32)]; 10 | const rawLeaves = leaves.concat(emptyNode(0)); 11 | const merkleTreeRaw = new MerkleTree(rawLeaves); 12 | const merkleTreeSparse = MerkleTree.sparseMerkleTreeFromLeaves(leaves, 2); 13 | 14 | assert(merkleTreeRaw.root.equals(merkleTreeSparse.root)); 15 | }); 16 | 17 | const TEST_DEPTH = 14; 18 | it(`Check proofs for 2^${TEST_DEPTH} tree`, () => { 19 | const leaves: Buffer[] = []; 20 | for (let i = 0; i < 2 ** TEST_DEPTH; i++) { 21 | leaves.push(crypto.randomBytes(32)); 22 | } 23 | const merkleTree = new MerkleTree(leaves); 24 | 25 | // Check proofs 26 | for (let i = 0; i < leaves.length; i++) { 27 | const proof = merkleTree.getProof(i); 28 | assert(MerkleTree.verify(merkleTree.getRoot(), proof)); 29 | } 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /governance/program/tests/process_create_token_owner_record.rs: -------------------------------------------------------------------------------- 1 | #![cfg(feature = "test-sbf")] 2 | 3 | use solana_program_test::*; 4 | 5 | mod program_test; 6 | 7 | use { 8 | program_test::*, spl_governance::state::token_owner_record::TOKEN_OWNER_RECORD_LAYOUT_VERSION, 9 | }; 10 | 11 | #[tokio::test] 12 | async fn test_create_token_owner_record() { 13 | // Arrange 14 | let mut governance_test = GovernanceProgramTest::start_new().await; 15 | let realm_cookie = governance_test.with_realm().await; 16 | 17 | // Act 18 | let token_owner_record_cookie = governance_test 19 | .with_community_token_owner_record(&realm_cookie) 20 | .await; 21 | 22 | // Assert 23 | let token_owner_record_account = governance_test 24 | .get_token_owner_record_account(&token_owner_record_cookie.address) 25 | .await; 26 | 27 | assert_eq!(0, token_owner_record_account.governing_token_deposit_amount); 28 | 29 | assert_eq!( 30 | TOKEN_OWNER_RECORD_LAYOUT_VERSION, 31 | token_owner_record_account.version 32 | ); 33 | assert_eq!(0, token_owner_record_account.unrelinquished_votes_count); 34 | 35 | assert_eq!( 36 | token_owner_record_cookie.account, 37 | token_owner_record_account 38 | ); 39 | } 40 | -------------------------------------------------------------------------------- /examples/rust/sysvar/tests/functional.rs: -------------------------------------------------------------------------------- 1 | use { 2 | solana_program::{ 3 | instruction::{AccountMeta, Instruction}, 4 | pubkey::Pubkey, 5 | sysvar::{self}, 6 | }, 7 | solana_program_test::*, 8 | solana_sdk::{signature::Signer, transaction::Transaction}, 9 | spl_example_sysvar::processor::process_instruction, 10 | std::str::FromStr, 11 | }; 12 | 13 | #[tokio::test] 14 | async fn test_sysvar() { 15 | let program_id = Pubkey::from_str("Sysvar1111111111111111111111111111111111111").unwrap(); 16 | let (banks_client, payer, recent_blockhash) = ProgramTest::new( 17 | "spl_example_sysvar", 18 | program_id, 19 | processor!(process_instruction), 20 | ) 21 | .start() 22 | .await; 23 | 24 | let mut transaction = Transaction::new_with_payer( 25 | &[Instruction::new_with_bincode( 26 | program_id, 27 | &(), 28 | vec![ 29 | AccountMeta::new(sysvar::clock::id(), false), 30 | AccountMeta::new(sysvar::rent::id(), false), 31 | ], 32 | )], 33 | Some(&payer.pubkey()), 34 | ); 35 | transaction.sign(&[&payer], recent_blockhash); 36 | banks_client.process_transaction(transaction).await.unwrap(); 37 | } 38 | -------------------------------------------------------------------------------- /governance/program/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-governance" 3 | version = "4.0.0" 4 | description = "Solana Program Library Governance Program" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [features] 11 | no-entrypoint = [] 12 | test-sbf = [] 13 | 14 | [dependencies] 15 | arrayref = "0.3.9" 16 | bincode = "1.3.2" 17 | borsh = "1.5.3" 18 | num-derive = "0.4" 19 | num-traits = "0.2" 20 | serde = "1.0.217" 21 | serde_derive = "1.0.103" 22 | solana-program = "2.1.0" 23 | spl-token = { version = "7.0", features = [ 24 | "no-entrypoint", 25 | ] } 26 | spl-governance-tools = { version = "0.1.4", path = "../tools" } 27 | spl-governance-addin-api = { version = "0.1.4", path = "../addin-api" } 28 | thiserror = "2.0" 29 | 30 | [dev-dependencies] 31 | assert_matches = "1.5.0" 32 | base64 = "0.22" 33 | proptest = "1.6" 34 | solana-program-test = "2.1.0" 35 | solana-sdk = "2.1.0" 36 | spl-governance-test-sdk = { version = "0.1.4", path = "../test-sdk" } 37 | spl-governance-addin-mock = { version = "0.1.4", path = "../addin-mock/program" } 38 | 39 | 40 | [lib] 41 | crate-type = ["cdylib", "lib"] 42 | 43 | [lints] 44 | workspace = true 45 | -------------------------------------------------------------------------------- /token-lending/js/src/instructions/setLendingMarketOwner.ts: -------------------------------------------------------------------------------- 1 | import { PublicKey, TransactionInstruction } from '@solana/web3.js'; 2 | import { struct, u8 } from '@solana/buffer-layout'; 3 | import { LENDING_PROGRAM_ID } from '../constants'; 4 | import { publicKey } from '@solana/buffer-layout-utils'; 5 | import { LendingInstruction } from './instruction'; 6 | 7 | interface Data { 8 | instruction: number; 9 | newOwner: PublicKey; 10 | } 11 | 12 | const DataLayout = struct([u8('instruction'), publicKey('newOwner')]); 13 | 14 | export const setLendingMarketOwnerInstruction = ( 15 | newOwner: PublicKey, 16 | lendingMarket: PublicKey, 17 | currentOwner: PublicKey, 18 | ): TransactionInstruction => { 19 | const data = Buffer.alloc(DataLayout.span); 20 | DataLayout.encode( 21 | { 22 | instruction: LendingInstruction.SetLendingMarketOwner, 23 | newOwner, 24 | }, 25 | data, 26 | ); 27 | 28 | const keys = [ 29 | { pubkey: lendingMarket, isSigner: false, isWritable: true }, 30 | { pubkey: currentOwner, isSigner: true, isWritable: false }, 31 | ]; 32 | 33 | return new TransactionInstruction({ 34 | keys, 35 | programId: LENDING_PROGRAM_ID, 36 | data, 37 | }); 38 | }; 39 | -------------------------------------------------------------------------------- /token-upgrade/cli/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-token-upgrade-cli" 3 | version = "0.1.1" 4 | description = "SPL Token Upgrade Command-line Utility" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [build-dependencies] 11 | walkdir = "2" 12 | 13 | [dependencies] 14 | clap = { version = "3", features = ["cargo"] } 15 | futures-util = "0.3.31" 16 | solana-clap-v3-utils = "2.1.0" 17 | solana-cli-config = "2.1.0" 18 | solana-client = "2.1.0" 19 | solana-logger = "2.1.0" 20 | solana-remote-wallet = "2.1.0" 21 | solana-sdk = "2.1.0" 22 | spl-associated-token-account-client = { version = "2.0.0" } 23 | spl-token = { version = "7.0", features = ["no-entrypoint"] } 24 | spl-token-2022 = { version = "6.0.0", features = ["no-entrypoint"] } 25 | spl-token-client = { version = "0.13.0" } 26 | spl-token-upgrade = { version = "0.1", path = "../program", features = ["no-entrypoint"] } 27 | tokio = { version = "1", features = ["full"] } 28 | 29 | [dev-dependencies] 30 | solana-test-validator = "2.1.0" 31 | 32 | [[bin]] 33 | name = "spl-token-upgrade" 34 | path = "src/main.rs" 35 | 36 | [package.metadata.docs.rs] 37 | targets = ["x86_64-unknown-linux-gnu"] 38 | -------------------------------------------------------------------------------- /account-compression/sdk/src/generated/types/ConcurrentMerkleTreeHeaderDataV1.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This code was GENERATED using the solita package. 3 | * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. 4 | * 5 | * See: https://github.com/metaplex-foundation/solita 6 | */ 7 | 8 | import * as beet from '@metaplex-foundation/beet'; 9 | import * as beetSolana from '@metaplex-foundation/beet-solana'; 10 | import * as web3 from '@solana/web3.js'; 11 | export type ConcurrentMerkleTreeHeaderDataV1 = { 12 | authority: web3.PublicKey; 13 | creationSlot: beet.bignum; 14 | isBatchInitialized: boolean; 15 | maxBufferSize: number; 16 | maxDepth: number; 17 | padding: number[] /* size: 5 */; 18 | }; 19 | 20 | /** 21 | * @category userTypes 22 | * @category generated 23 | */ 24 | export const concurrentMerkleTreeHeaderDataV1Beet = new beet.BeetArgsStruct( 25 | [ 26 | ['maxBufferSize', beet.u32], 27 | ['maxDepth', beet.u32], 28 | ['authority', beetSolana.publicKey], 29 | ['creationSlot', beet.u64], 30 | ['isBatchInitialized', beet.bool], 31 | ['padding', beet.uniformFixedSizeArray(beet.u8, 5)], 32 | ], 33 | 'ConcurrentMerkleTreeHeaderDataV1', 34 | ); 35 | -------------------------------------------------------------------------------- /governance/chat/program/src/error.rs: -------------------------------------------------------------------------------- 1 | //! Error types 2 | 3 | use { 4 | num_derive::FromPrimitive, 5 | solana_program::{ 6 | decode_error::DecodeError, 7 | msg, 8 | program_error::{PrintProgramError, ProgramError}, 9 | }, 10 | thiserror::Error, 11 | }; 12 | 13 | /// Errors that may be returned by the GovernanceChat program 14 | #[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] 15 | pub enum GovernanceChatError { 16 | /// Owner doesn't have enough governing tokens to comment on Proposal 17 | #[error("Owner doesn't have enough governing tokens to comment on Proposal")] 18 | NotEnoughTokensToCommentProposal = 900, 19 | 20 | /// Account already initialized 21 | #[error("Account already initialized")] 22 | AccountAlreadyInitialized, 23 | } 24 | 25 | impl PrintProgramError for GovernanceChatError { 26 | fn print(&self) { 27 | msg!("GOVERNANCE-CHAT-ERROR: {}", &self.to_string()); 28 | } 29 | } 30 | 31 | impl From for ProgramError { 32 | fn from(e: GovernanceChatError) -> Self { 33 | ProgramError::Custom(e as u32) 34 | } 35 | } 36 | 37 | impl DecodeError for GovernanceChatError { 38 | fn type_of() -> &'static str { 39 | "Governance Chat Error" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ci/cargo-test-sbf.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | cd "$(dirname "$0")/.." 5 | 6 | source ./ci/rust-version.sh stable 7 | source ./ci/solana-version.sh 8 | 9 | export RUSTFLAGS="-D warnings" 10 | export RUSTBACKTRACE=1 11 | 12 | usage() { 13 | exitcode=0 14 | if [[ -n "$1" ]]; then 15 | exitcode=1 16 | echo "Error: $*" 17 | fi 18 | echo "Usage: $0 [program-directory]" 19 | exit $exitcode 20 | } 21 | 22 | program_directory=$1 23 | if [[ -z $program_directory ]]; then 24 | usage "No program directory provided" 25 | fi 26 | 27 | cd $program_directory 28 | run_dir=$(pwd) 29 | 30 | if [[ -r $run_dir/Cargo.toml ]]; then 31 | # Build/test just one BPF program 32 | set -x 33 | cd $run_dir 34 | cargo +"$rust_stable" test-sbf -- --nocapture 35 | exit 0 36 | fi 37 | 38 | run_all=1 39 | for program in $run_dir/program{,-*}; do 40 | # Build/test all program directories 41 | if [[ -r $program/Cargo.toml ]]; then 42 | run_all= 43 | ( 44 | set -x 45 | cd $program 46 | cargo +"$rust_stable" test-sbf -- --nocapture 47 | ) 48 | fi 49 | done 50 | 51 | if [[ -n $run_all ]]; then 52 | # Build/test all directories 53 | set -x 54 | for directory in $(ls -d $run_dir/*/); do 55 | cd $directory 56 | cargo +"$rust_stable" test-sbf -- --nocapture 57 | done 58 | fi 59 | -------------------------------------------------------------------------------- /ci/do-audit.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | cd "$(dirname "$0")/.." 5 | source ./ci/rust-version.sh stable 6 | 7 | cargo_audit_ignores=( 8 | # ed25519-dalek: Double Public Key Signing Function Oracle Attack 9 | # 10 | # Remove once SPL upgrades to ed25519-dalek v2 11 | --ignore RUSTSEC-2022-0093 12 | 13 | # curve25519-dalek 14 | # 15 | # Remove once SPL upgrades to curve25519-dalek v4 16 | --ignore RUSTSEC-2024-0344 17 | 18 | # Crate: tonic 19 | # Version: 0.9.2 20 | # Title: Remotely exploitable Denial of Service in Tonic 21 | # Date: 2024-10-01 22 | # ID: RUSTSEC-2024-0376 23 | # URL: https://rustsec.org/advisories/RUSTSEC-2024-0376 24 | # Solution: Upgrade to >=0.12.3 25 | --ignore RUSTSEC-2024-0376 26 | 27 | # Crate: idna 28 | # Version: 0.1.5 29 | # Title: `idna` accepts Punycode labels that do not produce any non-ASCII when decoded 30 | # Date: 2024-12-09 31 | # ID: RUSTSEC-2024-0421 32 | # URL: https://rustsec.org/advisories/RUSTSEC-2024-0421 33 | # Solution: Upgrade to >=1.0.0 34 | # need to solve this depentant tree: 35 | # jsonrpc-core-client v18.0.0 -> jsonrpc-client-transports v18.0.0 -> url v1.7.2 -> idna v0.1.5 36 | --ignore RUSTSEC-2024-0421 37 | ) 38 | cargo +"$rust_stable" audit "${cargo_audit_ignores[@]}" 39 | -------------------------------------------------------------------------------- /libraries/math-example/src/error.rs: -------------------------------------------------------------------------------- 1 | //! Error types 2 | 3 | use { 4 | num_derive::FromPrimitive, 5 | solana_program::{decode_error::DecodeError, program_error::ProgramError}, 6 | thiserror::Error, 7 | }; 8 | 9 | /// Errors that may be returned by the Math program. 10 | #[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] 11 | pub enum MathError { 12 | /// Calculation overflowed the destination number 13 | #[error("Calculation overflowed the destination number")] 14 | Overflow, 15 | /// Calculation underflowed the destination number 16 | #[error("Calculation underflowed the destination number")] 17 | Underflow, 18 | } 19 | impl From for ProgramError { 20 | fn from(e: MathError) -> Self { 21 | ProgramError::Custom(e as u32) 22 | } 23 | } 24 | impl DecodeError for MathError { 25 | fn type_of() -> &'static str { 26 | "Math Error" 27 | } 28 | } 29 | 30 | #[cfg(test)] 31 | mod tests { 32 | use {super::*, solana_program::program_error::ProgramError}; 33 | 34 | #[test] 35 | fn test_math_error_from() { 36 | let program_error = ProgramError::from(MathError::Overflow); 37 | assert_eq!(program_error, ProgramError::Custom(0)); 38 | 39 | let program_error = ProgramError::from(MathError::Underflow); 40 | assert_eq!(program_error, ProgramError::Custom(1)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /governance/chat/program/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "spl-governance-chat" 3 | version = "0.2.9" 4 | description = "Solana Program Library Governance Chat Program" 5 | authors = ["Solana Labs Maintainers "] 6 | repository = "https://github.com/solana-labs/solana-program-library" 7 | license = "Apache-2.0" 8 | edition = "2021" 9 | 10 | [features] 11 | no-entrypoint = [] 12 | test-sbf = [] 13 | 14 | [dependencies] 15 | arrayref = "0.3.9" 16 | bincode = "1.3.2" 17 | borsh = "1.5.3" 18 | num-derive = "0.4" 19 | num-traits = "0.2" 20 | serde = "1.0.217" 21 | serde_derive = "1.0.103" 22 | solana-program = "2.1.0" 23 | spl-token = { version = "7.0", features = [ 24 | "no-entrypoint", 25 | ] } 26 | spl-governance = { version = "4.0.0", path = "../../program", features = [ 27 | "no-entrypoint", 28 | ] } 29 | spl-governance-tools = { version = "0.1.4", path = "../../tools" } 30 | spl-governance-addin-api = { version = "0.1.4", path = "../../addin-api" } 31 | thiserror = "2.0" 32 | 33 | 34 | [dev-dependencies] 35 | assert_matches = "1.5.0" 36 | proptest = "1.6" 37 | solana-program-test = "2.1.0" 38 | solana-sdk = "2.1.0" 39 | spl-governance-test-sdk = { version = "0.1.4", path = "../../test-sdk" } 40 | spl-governance-addin-mock = { version = "0.1.4", path = "../../addin-mock/program" } 41 | 42 | 43 | [lib] 44 | crate-type = ["cdylib", "lib"] 45 | 46 | [lints] 47 | workspace = true 48 | -------------------------------------------------------------------------------- /token-swap/program/fuzz/src/native_account_data.rs: -------------------------------------------------------------------------------- 1 | use solana_program::{account_info::AccountInfo, clock::Epoch, pubkey::Pubkey}; 2 | 3 | #[derive(Clone)] 4 | pub struct NativeAccountData { 5 | pub key: Pubkey, 6 | pub lamports: u64, 7 | pub data: Vec, 8 | pub program_id: Pubkey, 9 | pub is_signer: bool, 10 | } 11 | 12 | impl NativeAccountData { 13 | pub fn new(size: usize, program_id: Pubkey) -> Self { 14 | Self { 15 | key: Pubkey::new_unique(), 16 | lamports: 0, 17 | data: vec![0; size], 18 | program_id, 19 | is_signer: false, 20 | } 21 | } 22 | 23 | pub fn new_from_account_info(account_info: &AccountInfo) -> Self { 24 | Self { 25 | key: *account_info.key, 26 | lamports: **account_info.lamports.borrow(), 27 | data: account_info.data.borrow().to_vec(), 28 | program_id: *account_info.owner, 29 | is_signer: account_info.is_signer, 30 | } 31 | } 32 | 33 | pub fn as_account_info(&mut self) -> AccountInfo { 34 | AccountInfo::new( 35 | &self.key, 36 | self.is_signer, 37 | false, 38 | &mut self.lamports, 39 | &mut self.data[..], 40 | &self.program_id, 41 | false, 42 | Epoch::default(), 43 | ) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /docs/src/transfer-hook-interface.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Transfer Hook Interface 3 | --- 4 | 5 | The Transfer Hook Interface is one of several interfaces introduced within the 6 | Solana Program Library that can be implemented by any Solana program. 7 | 8 | During transfers, Token-2022 calls a mint's configured transfer hook program 9 | using this interface, as described in the 10 | [Transfer Hook Extension Guide](../../token-2022/extensions#transfer-hook). 11 | Additionally, a 12 | [reference implementation](https://github.com/solana-program/transfer-hook/tree/main/program) 13 | can be found in the SPL GitHub repository, detailing 14 | how one might implement this interface in their own program. 15 | 16 | The Transfer Hook Interface is designed to allow token creators to "hook" 17 | additional functionality into token transfers. The token program CPIs into the 18 | transfer hook program using the interface-defined instruction. The transfer 19 | hook program can then perform any custom functionality. 20 | 21 | In the case of Token-2022, a token creator configures a transfer hook program 22 | using a mint extension, and this extension tells Token-2022 which program to 23 | invoke whenever a transfer is conducted. 24 | 25 | With this interface, programs can compose highly customizable transfer 26 | functionality that can be compatible with many other programs - particularly 27 | tokens who implement the SPL Token interface. 28 | -------------------------------------------------------------------------------- /token-lending/js/src/instructions/refreshObligation.ts: -------------------------------------------------------------------------------- 1 | import { PublicKey, SYSVAR_CLOCK_PUBKEY, TransactionInstruction } from '@solana/web3.js'; 2 | import { struct, u8 } from '@solana/buffer-layout'; 3 | import { LENDING_PROGRAM_ID } from '../constants'; 4 | import { LendingInstruction } from './instruction'; 5 | 6 | interface Data { 7 | instruction: number; 8 | } 9 | 10 | const DataLayout = struct([u8('instruction')]); 11 | 12 | export const refreshObligationInstruction = ( 13 | obligation: PublicKey, 14 | depositReserves: PublicKey[], 15 | borrowReserves: PublicKey[], 16 | ): TransactionInstruction => { 17 | const data = Buffer.alloc(DataLayout.span); 18 | DataLayout.encode({ instruction: LendingInstruction.RefreshObligation }, data); 19 | 20 | const keys = [ 21 | { pubkey: obligation, isSigner: false, isWritable: true }, 22 | { pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, 23 | ]; 24 | 25 | for (const depositReserve of depositReserves) { 26 | keys.push({ pubkey: depositReserve, isSigner: false, isWritable: false }); 27 | } 28 | 29 | for (const borrowReserve of borrowReserves) { 30 | keys.push({ pubkey: borrowReserve, isSigner: false, isWritable: false }); 31 | } 32 | 33 | return new TransactionInstruction({ 34 | keys, 35 | programId: LENDING_PROGRAM_ID, 36 | data, 37 | }); 38 | }; 39 | -------------------------------------------------------------------------------- /binary-option/program/src/validation_utils.rs: -------------------------------------------------------------------------------- 1 | use { 2 | crate::error::BinaryOptionError, 3 | solana_program::{ 4 | account_info::AccountInfo, 5 | entrypoint::ProgramResult, 6 | program_error::ProgramError, 7 | program_pack::{IsInitialized, Pack}, 8 | pubkey::Pubkey, 9 | }, 10 | }; 11 | 12 | pub fn assert_keys_equal(key1: Pubkey, key2: Pubkey) -> ProgramResult { 13 | if key1 != key2 { 14 | Err(BinaryOptionError::PublicKeyMismatch.into()) 15 | } else { 16 | Ok(()) 17 | } 18 | } 19 | 20 | pub fn assert_keys_unequal(key1: Pubkey, key2: Pubkey) -> ProgramResult { 21 | if key1 == key2 { 22 | Err(BinaryOptionError::PublicKeysShouldBeUnique.into()) 23 | } else { 24 | Ok(()) 25 | } 26 | } 27 | 28 | /// assert initialized account 29 | pub fn assert_initialized( 30 | account_info: &AccountInfo, 31 | ) -> Result { 32 | let account: T = T::unpack_unchecked(&account_info.data.borrow())?; 33 | if !account.is_initialized() { 34 | Err(BinaryOptionError::UninitializedAccount.into()) 35 | } else { 36 | Ok(account) 37 | } 38 | } 39 | 40 | /// assert owned by 41 | pub fn assert_owned_by(account: &AccountInfo, owner: &Pubkey) -> ProgramResult { 42 | if account.owner != owner { 43 | Err(BinaryOptionError::IncorrectOwner.into()) 44 | } else { 45 | Ok(()) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /token-lending/js/src/instructions/initObligation.ts: -------------------------------------------------------------------------------- 1 | import { TOKEN_PROGRAM_ID } from '@solana/spl-token'; 2 | import { PublicKey, SYSVAR_CLOCK_PUBKEY, SYSVAR_RENT_PUBKEY, TransactionInstruction } from '@solana/web3.js'; 3 | import { struct, u8 } from '@solana/buffer-layout'; 4 | import { LENDING_PROGRAM_ID } from '../constants'; 5 | import { LendingInstruction } from './instruction'; 6 | 7 | interface Data { 8 | instruction: number; 9 | } 10 | 11 | const DataLayout = struct([u8('instruction')]); 12 | 13 | export const initObligationInstruction = ( 14 | obligation: PublicKey, 15 | lendingMarket: PublicKey, 16 | obligationOwner: PublicKey, 17 | ): TransactionInstruction => { 18 | const data = Buffer.alloc(DataLayout.span); 19 | DataLayout.encode({ instruction: LendingInstruction.InitObligation }, data); 20 | 21 | const keys = [ 22 | { pubkey: obligation, isSigner: false, isWritable: true }, 23 | { pubkey: lendingMarket, isSigner: false, isWritable: false }, 24 | { pubkey: obligationOwner, isSigner: true, isWritable: false }, 25 | { pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false }, 26 | { pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, 27 | { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, 28 | ]; 29 | 30 | return new TransactionInstruction({ 31 | keys, 32 | programId: LENDING_PROGRAM_ID, 33 | data, 34 | }); 35 | }; 36 | -------------------------------------------------------------------------------- /name-service/js/src/state.ts: -------------------------------------------------------------------------------- 1 | import { Connection, PublicKey } from '@solana/web3.js'; 2 | import { deserialize, Schema } from 'borsh'; 3 | 4 | type InitArgs = { 5 | parentName: Uint8Array; 6 | owner: Uint8Array; 7 | class: Uint8Array; 8 | }; 9 | 10 | export class NameRegistryState { 11 | static HEADER_LEN = 96; 12 | parentName: PublicKey; 13 | owner: PublicKey; 14 | class: PublicKey; 15 | data: Buffer | undefined; 16 | 17 | static schema: Schema = { 18 | struct: { 19 | parentName: { array: { type: 'u8', len: 32 } }, 20 | owner: { array: { type: 'u8', len: 32 } }, 21 | class: { array: { type: 'u8', len: 32 } }, 22 | }, 23 | }; 24 | constructor(obj: InitArgs) { 25 | this.parentName = new PublicKey(obj.parentName); 26 | this.owner = new PublicKey(obj.owner); 27 | this.class = new PublicKey(obj.class); 28 | } 29 | 30 | public static async retrieve(connection: Connection, nameAccountKey: PublicKey): Promise { 31 | const nameAccount = await connection.getAccountInfo(nameAccountKey, 'processed'); 32 | if (!nameAccount) { 33 | throw new Error('Invalid name account provided'); 34 | } 35 | 36 | const deserialized = deserialize(this.schema, nameAccount.data) as InitArgs; 37 | const res = new NameRegistryState(deserialized); 38 | 39 | res.data = nameAccount.data?.slice(this.HEADER_LEN); 40 | 41 | return res; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /governance/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # SPL Governance Changelog 2 | 3 | ## v4.0.0 - WIP 4 | 5 | - Mandatory signatories 6 | 7 | ## v3.1.1 - 25 Apr 2022 8 | 9 | - Weighted multi choice voting 10 | - Revoking own membership 11 | 12 | ## v3.1.0 - 13 Dec 2022 13 | 14 | - Council governance plugins 15 | - Non transferable and revokable membership 16 | - Veto vote 17 | - Council wallet rules 18 | - approval quorum 19 | - vote tipping 20 | - veto threshold 21 | - Explicitly disabled options 22 | - community/council vote 23 | - community/council proposals 24 | - Absolute max supply 25 | - Proposal cool off time 26 | - Proposal deposit 27 | 28 | ## v2.2.4 - 24 Mar 2022 29 | 30 | - Support Anchor native account discriminators for `MaxVoterWeightRecord` and `VoterWeightRecord` 31 | 32 | ## v2.2.3 - 09 Feb 2022 33 | 34 | - Fix serialisation of multiple instructions within a single proposal transaction 35 | 36 | ## v2.2.2 - 07 Feb 2022 37 | 38 | - Native SOL Treasuries 39 | - Multi choice and survey style proposals 40 | - `voter_weight` and `max_voter_weight` addins 41 | - Multiple instructions per proposal transaction 42 | - Configurable tipping point (`Strict`, `Early`, `Disabled`) 43 | - Owner signed off proposals 44 | - `realm_authority` can create governances 45 | - Program metadata and version detection 46 | - Custom deposit amount for governance tokens 47 | 48 | ## v1.1.1 - 23 Sep 2021 49 | 50 | - Constrain number of outstanding proposals per token owner to 10 at a time 51 | 52 | ## v1.0.8 - 1 Aug 2021 53 | 54 | - First release 55 | -------------------------------------------------------------------------------- /libraries/concurrent-merkle-tree/src/hash.rs: -------------------------------------------------------------------------------- 1 | use { 2 | crate::node::{empty_node, Node}, 3 | solana_program::keccak::hashv, 4 | }; 5 | 6 | /// Recomputes root of the Merkle tree from Node & proof 7 | pub fn recompute(leaf: Node, proof: &[Node], index: u32) -> Node { 8 | let mut current_node = leaf; 9 | for (depth, sibling) in proof.iter().enumerate() { 10 | hash_to_parent(&mut current_node, sibling, index >> depth & 1 == 0); 11 | } 12 | current_node 13 | } 14 | 15 | /// Computes the parent node of `node` and `sibling` and copies the result into 16 | /// `node` 17 | #[inline(always)] 18 | pub fn hash_to_parent(node: &mut Node, sibling: &Node, is_left: bool) { 19 | let parent = if is_left { 20 | hashv(&[node, sibling]) 21 | } else { 22 | hashv(&[sibling, node]) 23 | }; 24 | node.copy_from_slice(parent.as_ref()) 25 | } 26 | 27 | /// Fills in proof to the height of the concurrent merkle tree. 28 | /// Missing nodes are inferred as empty node hashes. 29 | pub fn fill_in_proof( 30 | proof_vec: &[Node], 31 | full_proof: &mut [Node; MAX_DEPTH], 32 | ) { 33 | solana_logging!("Attempting to fill in proof"); 34 | if !proof_vec.is_empty() { 35 | full_proof[..proof_vec.len()].copy_from_slice(proof_vec); 36 | } 37 | 38 | for (i, item) in full_proof 39 | .iter_mut() 40 | .enumerate() 41 | .take(MAX_DEPTH) 42 | .skip(proof_vec.len()) 43 | { 44 | *item = empty_node(i as u32); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /token-lending/js/src/state/lendingMarket.ts: -------------------------------------------------------------------------------- 1 | import { AccountInfo, PublicKey } from '@solana/web3.js'; 2 | import { blob, struct, u8 } from '@solana/buffer-layout'; 3 | import { publicKey } from '@solana/buffer-layout-utils'; 4 | import { Parser } from '../util'; 5 | 6 | export interface LendingMarket { 7 | version: number; 8 | bumpSeed: number; 9 | owner: PublicKey; 10 | quoteCurrency: Uint8Array; 11 | tokenProgramId: PublicKey; 12 | oracleProgramId: PublicKey; 13 | } 14 | 15 | /** @internal */ 16 | export const LendingMarketLayout = struct( 17 | [ 18 | u8('version'), 19 | u8('bumpSeed'), 20 | publicKey('owner'), 21 | blob(32, 'quoteCurrency'), 22 | publicKey('tokenProgramId'), 23 | publicKey('oracleProgramId'), 24 | blob(128, 'padding'), 25 | ], 26 | 'lendingMarket', 27 | ); 28 | 29 | export const LENDING_MARKET_SIZE = LendingMarketLayout.span; 30 | 31 | export const isLendingMarket = (info: AccountInfo): boolean => { 32 | return info.data.length === LENDING_MARKET_SIZE; 33 | }; 34 | 35 | export const parseLendingMarket: Parser = (pubkey: PublicKey, info: AccountInfo) => { 36 | if (!isLendingMarket(info)) return; 37 | 38 | const buffer = Buffer.from(info.data); 39 | const lendingMarket = LendingMarketLayout.decode(buffer); 40 | 41 | if (!lendingMarket.version) return; 42 | 43 | return { 44 | pubkey, 45 | info, 46 | data: lendingMarket, 47 | }; 48 | }; 49 | --------------------------------------------------------------------------------