|
@@ -7,156 +7,152 @@ This repo contains Solana onchain programs (referred to as 'Smart Contracts' in
|
|
|
> [!NOTE]
|
|
|
> If you're new to Solana, you don't need to create your own programs to perform basic things like making accounts, creating tokens, sending tokens, or minting NFTs. These common tasks are handled with existing programs, for example the System Program (for making account or transferring SOL) or the token program (for creating tokens and NFTs). See the [Solana Developer site](https://solana.com/developers) to learn more.
|
|
|
|
|
|
-## Using this repo
|
|
|
-
|
|
|
Each folder includes examples for one or more of the following
|
|
|
|
|
|
- `anchor` - Written using [Anchor](https://www.anchor-lang.com/), the most popular framework for Solana Development, which uses Rust. Use `anchor build && anchor deploy` to build & deploy the program. Run `anchor run test` to test it.
|
|
|
- `native` - Written using Solana's native Rust crates and vanilla Rust. Use `cicd.sh` to build & deploy the program. Run `yarn run test` to test it.
|
|
|
- `seahorse` - Written using the [Seahorse framework](https://seahorse-lang.org/), which converts your Python code to Anchor Rust. Use `seahorse build && anchor deploy` to build & deploy the program. Run `anchor run test` to test it.
|
|
|
|
|
|
-If a given example is missing, please add it!
|
|
|
-
|
|
|
-## The example projects
|
|
|
+**If a given example is missing, please send us a PR to add it!** Our aim is to have every examples available in every option. We'd also love to see more programs involving staking, wrapped tokens, oracles, compression and VRF. Follow the [contributing guidelines](./CONTRIBUTING.md) to keep things consistent.
|
|
|
|
|
|
<details>
|
|
|
<summary>Basics</summary>
|
|
|
|
|
|
-#### account-data
|
|
|
+### Hello world
|
|
|
|
|
|
-Store and retrieve data using Solana accounts.
|
|
|
+[Hello World on Solana! A minimal program that logs a greeting.](./basics/hello-solana/README.md)
|
|
|
|
|
|
-[anchor](./basics/account-data/anchor), [native](./basics/account-data/native)
|
|
|
+[anchor](./basics/hello-solana/anchor) [native](./basics/hello-solana/native) [seahorse](./basics/hello-solana/seahorse)
|
|
|
|
|
|
-#### checking-accounts
|
|
|
+### Account-data
|
|
|
|
|
|
-[Check that the accounts provided in incoming instructions meet particular criteria.](./basics/checking-accounts/README.md)
|
|
|
+Store and retrieve data using Solana accounts.
|
|
|
|
|
|
-[anchor](./basics/checking-accounts/anchor), [native](./basics/checking-accounts/native)
|
|
|
+[anchor](./basics/account-data/anchor) [native](./basics/account-data/native)
|
|
|
|
|
|
-#### close-account
|
|
|
+### Storing global state - Counter
|
|
|
|
|
|
-Close an account and get the Lamports back.
|
|
|
+[Use a PDA to store global state, making a counter that increments when called.](./basics/counter/README.md)
|
|
|
|
|
|
-[anchor](./basics/close-account/anchor), [native](./basics/close-account/native)
|
|
|
+[anchor](./basics/counter/anchor) [native](./basics/counter/native) [seahorse](./basics/counter/seahorse)
|
|
|
|
|
|
-#### counter
|
|
|
+### Saving per-user state - Favorites
|
|
|
|
|
|
-[Use a PDA to store global state, making a counter that increments when called.](./basics/counter/README.md)
|
|
|
+Save and update per-user state on the blockchain, ensuring users can only update their own information.
|
|
|
|
|
|
-[anchor](./basics/counter/anchor), [native](./basics/counter/native), [seahorse](./basics/counter/seahorse)
|
|
|
+[anchor](./basics/favorites/anchor)
|
|
|
|
|
|
-#### create-account
|
|
|
+### Checking Instruction Accounts
|
|
|
|
|
|
-[Make new accounts on the blockchain.](./basics/create-account/README.md)
|
|
|
+[Check that the accounts provided in incoming instructions meet particular criteria.](./basics/checking-accounts/README.md)
|
|
|
|
|
|
-[anchor](./basics/create-account/anchor), [native](./basics/create-account/native)
|
|
|
+[anchor](./basics/checking-accounts/anchor) [native](./basics/checking-accounts/native)
|
|
|
|
|
|
-#### cross-program-invocation
|
|
|
+### Closing Accounts
|
|
|
|
|
|
-[Invoke an instruction handler from one onchain program in another onchain program.](./basics/cross-program-invocation/README.md)
|
|
|
+Close an account and get the Lamports back.
|
|
|
|
|
|
-[anchor](./basics/cross-program-invocation/anchor), [native](./basics/cross-program-invocation/native)
|
|
|
+[anchor](./basics/close-account/anchor) [native](./basics/close-account/native)
|
|
|
|
|
|
-#### favorites
|
|
|
+### Creating Accounts
|
|
|
|
|
|
-Save and update per-user state on the blockchain, ensuring users can only update their own information.
|
|
|
+[Make new accounts on the blockchain.](./basics/create-account/README.md)
|
|
|
|
|
|
-[anchor](./basics/favorites/anchor)
|
|
|
+[anchor](./basics/create-account/anchor) [native](./basics/create-account/native)
|
|
|
|
|
|
-#### hello-solana
|
|
|
+### Cross program invocations
|
|
|
|
|
|
-[Hello World on Solana! A minimal program that logs a greeting.](./basics/hello-solana/README.md)
|
|
|
+[Invoke an instruction handler from one onchain program in another onchain program.](./basics/cross-program-invocation/README.md)
|
|
|
|
|
|
-[anchor](./basics/hello-solana/anchor), [native](./basics/hello-solana/native), [seahorse](./basics/hello-solana/seahorse)
|
|
|
+[anchor](./basics/cross-program-invocation/anchor) [native](./basics/cross-program-invocation/native)
|
|
|
|
|
|
-#### pda-rent-payer
|
|
|
+### PDA pda-rent-payer
|
|
|
|
|
|
[Use a PDA to pay the rent for the creation of a new account.](./basics/pda-rent-payer/README.md)
|
|
|
|
|
|
-[anchor](./basics/pda-rent-payer/anchor), [native](./basics/pda-rent-payer/native)
|
|
|
+[anchor](./basics/pda-rent-payer/anchor) [native](./basics/pda-rent-payer/native)
|
|
|
|
|
|
-#### processing-instructions
|
|
|
+### Processing instructions
|
|
|
|
|
|
[Add parameters to an instruction handler and use them.](./basics/processing-instructions/README.md)
|
|
|
|
|
|
-[anchor](./basics/processing-instructions/anchor), [native](./basics/processing-instructions/native)
|
|
|
+[anchor](./basics/processing-instructions/anchor) [native](./basics/processing-instructions/native)
|
|
|
|
|
|
-#### program-derived-addresses
|
|
|
+### Storing date in program derived addresses
|
|
|
|
|
|
Store and retrieve state in Solana.
|
|
|
|
|
|
-[anchor](./basics/program-derived-addresses/anchor), [native](./basics/program-derived-addresses/native)
|
|
|
+[anchor](./basics/program-derived-addresses/anchor) [native](./basics/program-derived-addresses/native)
|
|
|
|
|
|
-#### realloc
|
|
|
+### Handling accounts that expland in size
|
|
|
|
|
|
How to store state that changes size in Solana.
|
|
|
|
|
|
-[anchor](./basics/realloc/anchor), [native](./basics/realloc/native)
|
|
|
+[anchor](./basics/realloc/anchor) [native](./basics/realloc/native)
|
|
|
|
|
|
-#### rent
|
|
|
+### Calculating account size to determine rent
|
|
|
|
|
|
[Determine the necessary minimum rent by calculating an account's size.](./basics/rent/README.md)
|
|
|
|
|
|
-[anchor](./basics/rent/anchor), [native](./basics/rent/native)
|
|
|
+[anchor](./basics/rent/anchor) [native](./basics/rent/native)
|
|
|
|
|
|
-#### repository-layout
|
|
|
+### Laying out larger programs
|
|
|
|
|
|
[Layout larger Solana onchain programs.](./basics/repository-layout/README.md)
|
|
|
|
|
|
-[anchor](./basics/repository-layout/anchor), [native](./basics/repository-layout/native)
|
|
|
+[anchor](./basics/repository-layout/anchor) [native](./basics/repository-layout/native)
|
|
|
|
|
|
-#### transfer-sol
|
|
|
+### Transferring SOL
|
|
|
|
|
|
[Send SOL between two accounts.](./basics/transfer-sol/README.md)
|
|
|
|
|
|
-[anchor](./basics/transfer-sol/anchor), [native](./basics/transfer-sol/native), [seahorse](./basics/transfer-sol/seahorse)
|
|
|
+[anchor](./basics/transfer-sol/anchor) [native](./basics/transfer-sol/native) [seahorse](./basics/transfer-sol/seahorse)
|
|
|
|
|
|
</details>
|
|
|
<details>
|
|
|
<summary>Tokens</summary>
|
|
|
|
|
|
-#### create-token
|
|
|
+### Creating tokens
|
|
|
|
|
|
[Create a token on Solana with a token symbol and icon.](./tokens/create-token/README.md)
|
|
|
|
|
|
-[anchor](./tokens/create-token/anchor), [native](./tokens/create-token/native)
|
|
|
+[anchor](./tokens/create-token/anchor) [native](./tokens/create-token/native)
|
|
|
|
|
|
-#### escrow
|
|
|
+### Minting NFTS
|
|
|
|
|
|
-Allow two users to swap digital assets with each other, each getting 100% of what the other has offered due to the power of decentralization!
|
|
|
+[Mint an NFT from inside your own onchain program using the Token and Metaplex Token Metadata programs.](./tokens/nft-minter/README.md) Reminder: you don't need your own program just to mint an NFT, see the note at the top of this README.
|
|
|
|
|
|
-[anchor](./tokens/escrow/anchor)
|
|
|
+[anchor](./tokens/nft-minter/anchor) [native](./tokens/nft-minter/native)
|
|
|
|
|
|
-#### nft-minter
|
|
|
+### Minting a token from inside a program
|
|
|
|
|
|
-[Mint an NFT from inside your own onchain program using the Token and Metaplex Token Metadata programs.](./tokens/nft-minter/README.md) Reminder: you don't need your own program just to mint an NFT, see the note at the top of this README.
|
|
|
+[Mint a Token from inside your own onchain program using the Token program.](./tokens/spl-token-minter/README.md) Reminder: you don't need your own program just to mint an NFT, see the note at the top of this README.
|
|
|
|
|
|
-[anchor](./tokens/nft-minter/anchor), [native](./tokens/nft-minter/native)
|
|
|
+[anchor](./tokens/spl-token-minter/anchor) [native](./tokens/spl-token-minter/native)
|
|
|
|
|
|
-#### pda-mint-authority
|
|
|
+### Transferring Tokens
|
|
|
|
|
|
-[Mint a Token from inside your own onchain program using the Token program.](./tokens/pda-mint-authority/README.md) Reminder: you don't need your own program just to mint an NFT, see the note at the top of this README.
|
|
|
+[Transfer tokens between accounts](./tokens/transfer-tokens/README.md)
|
|
|
|
|
|
-[anchor](./tokens/pda-mint-authority/anchor), [native](./tokens/pda-mint-authority/native)
|
|
|
+[anchor](./tokens/transfer-tokens/anchor) [native](./tokens/transfer-tokens/native) [seahorse](./tokens/transfer-tokens/seahorse)
|
|
|
|
|
|
-#### spl-token-minter
|
|
|
+### Allowing users to swap digital assets - Escrow
|
|
|
|
|
|
-[Mint a Token from inside your own onchain program using the Token program.](./tokens/spl-token-minter/README.md) Reminder: you don't need your own program just to mint an NFT, see the note at the top of this README.
|
|
|
+Allow two users to swap digital assets with each other, each getting 100% of what the other has offered due to the power of decentralization!
|
|
|
|
|
|
-[anchor](./tokens/spl-token-minter/anchor), [native](./tokens/spl-token-minter/native)
|
|
|
+[anchor](./tokens/escrow/anchor)
|
|
|
|
|
|
-#### token-swap
|
|
|
+### Minting a token from inside a program with a PDA as the mint authority
|
|
|
|
|
|
-[Create liquidity pools to allow trading of new digital assets and allows users that provide liquidity to be rewarded by creating an Automated Market Maker.](./tokens/token-swap/README.md)
|
|
|
+[Mint a Token from inside your own onchain program using the Token program.](./tokens/pda-mint-authority/README.md) Reminder: you don't need your own program just to mint an NFT, see the note at the top of this README.
|
|
|
|
|
|
-[anchor](./tokens/token-swap/anchor)
|
|
|
+[anchor](./tokens/pda-mint-authority/anchor) [native](./tokens/pda-mint-authority/native)
|
|
|
|
|
|
-#### transfer-tokens
|
|
|
+### Creating an Automated Market Maker
|
|
|
|
|
|
-[Transfer tokens between accounts](./tokens/transfer-tokens/README.md)
|
|
|
+[Create liquidity pools to allow trading of new digital assets and allows users that provide liquidity to be rewarded by creating an Automated Market Maker.](./tokens/token-swap/README.md)
|
|
|
|
|
|
-[anchor](./tokens/transfer-tokens/anchor), [native](./tokens/transfer-tokens/native), [seahorse](./tokens/transfer-tokens/seahorse)
|
|
|
+[anchor](./tokens/token-swap/anchor)
|
|
|
|
|
|
</details>
|
|
|
|
|
@@ -164,102 +160,102 @@ Allow two users to swap digital assets with each other, each getting 100% of wha
|
|
|
|
|
|
<summary>Token Extensions</summary>
|
|
|
|
|
|
-#### basics
|
|
|
+### Basics - create token mints, mint tokens, and transfer tokens with Token Extensions
|
|
|
|
|
|
Create token mints, mint tokens, and transferr tokens using Token Extensions.
|
|
|
|
|
|
[anchor](./tokens/token-2022/basics/anchor)
|
|
|
|
|
|
-#### cpi-guard
|
|
|
+### Preventing CPIs with CPI guard
|
|
|
|
|
|
Enable CPI guard to prevents certain token action from occurring within CPI (Cross-Program Invocation).
|
|
|
|
|
|
[anchor](./tokens/token-2022/cpi-guard/anchor)
|
|
|
|
|
|
-#### default-account-state
|
|
|
+### Using default account state
|
|
|
|
|
|
Create new token accounts that are frozen by default.
|
|
|
|
|
|
-[anchor](./tokens/token-2022/default-account-state/anchor), [native](./tokens/token-2022/default-account-state/native)
|
|
|
+[anchor](./tokens/token-2022/default-account-state/anchor) [native](./tokens/token-2022/default-account-state/native)
|
|
|
|
|
|
-#### group
|
|
|
+### Grouping tokens
|
|
|
|
|
|
Create tokens that belong to larger groups of tokens using the Group Pointer extension.
|
|
|
|
|
|
[anchor](./tokens/token-2022/group/anchor)
|
|
|
|
|
|
-#### immutable-owner
|
|
|
+### Creating token accounts whose owner cannot be changed
|
|
|
|
|
|
Create tokens whose owning program cannot be changed.
|
|
|
|
|
|
[anchor](./tokens/token-2022/immutable-owner/anchor)
|
|
|
|
|
|
-#### interest-bearing
|
|
|
+### Interest bearing tokens
|
|
|
|
|
|
Create tokens that show an 'interest' calculation.
|
|
|
|
|
|
[anchor](./tokens/token-2022/interest-bearing/anchor)
|
|
|
|
|
|
-#### memo-transfer
|
|
|
+### Requiring transactions to include descriptive memos
|
|
|
|
|
|
Create tokens where transfers must have a memo describing the transaction attached.
|
|
|
|
|
|
[anchor](./tokens/token-2022/memo-transfer/anchor)
|
|
|
|
|
|
-#### metadata
|
|
|
+### Adding on-chain metadata to the token mint
|
|
|
|
|
|
Create tokens that store their onchain metadata inside the token mint, without needing to use or pay for additional programs.
|
|
|
|
|
|
[anchor](./tokens/token-2022/metadata/anchor)
|
|
|
|
|
|
-#### mint-close-authority
|
|
|
+### Allow a designedated account to close a mint
|
|
|
|
|
|
Allow a designated account to close a Mint.
|
|
|
|
|
|
-[anchor](./tokens/token-2022/mint-close-authority/anchor), [native](./tokens/token-2022/mint-close-authority/native)
|
|
|
+[anchor](./tokens/token-2022/mint-close-authority/anchor) [native](./tokens/token-2022/mint-close-authority/native)
|
|
|
|
|
|
-#### multiple-extensions
|
|
|
+### Usng multiple token extensions
|
|
|
|
|
|
Use multiple Token Extensions at once.
|
|
|
|
|
|
[native](./tokens/token-2022/multiple-extensions/native)
|
|
|
|
|
|
-#### non-transferable
|
|
|
+### Non-transferrable - create tokens that can't be transferred.
|
|
|
|
|
|
Create tokens that cannot be transferred.
|
|
|
|
|
|
-[anchor](./tokens/token-2022/non-transferable/anchor), [native](./tokens/token-2022/non-transferable/native)
|
|
|
+[anchor](./tokens/token-2022/non-transferable/anchor) [native](./tokens/token-2022/non-transferable/native)
|
|
|
|
|
|
-#### permanent-delegate
|
|
|
+### Permanent Delegate - Create tokens permanently under the control of a particular account
|
|
|
|
|
|
Create tokens that remain under the control of an account, even when transferred elsewhere.
|
|
|
|
|
|
[anchor](./tokens/token-2022/permanent-delegate/anchor)
|
|
|
|
|
|
-#### transfer-fee
|
|
|
+### Create tokens with a transfer-fee.
|
|
|
|
|
|
-Create tokens
|
|
|
+Create tokens with an inbuilt transfer fee.
|
|
|
|
|
|
-[anchor](./tokens/token-2022/transfer-fee/anchor), [native](./tokens/token-2022/transfer-fee/native)
|
|
|
+[anchor](./tokens/token-2022/transfer-fee/anchor) [native](./tokens/token-2022/transfer-fee/native)
|
|
|
|
|
|
</details>
|
|
|
<details>
|
|
|
|
|
|
<summary>Compression</summary>
|
|
|
|
|
|
-#### cnft-burn
|
|
|
+### Cnft-burn
|
|
|
|
|
|
Burn compressed NFTs.
|
|
|
|
|
|
[anchor](./compression/cnft-burn/anchor)
|
|
|
|
|
|
-#### cnft-vault
|
|
|
+### Cnft-vault
|
|
|
|
|
|
Store Metaplex compressed NFTs inside a PDA.
|
|
|
|
|
|
[anchor](./compression/cnft-vault/anchor)
|
|
|
|
|
|
-#### cutils
|
|
|
+### Cutils
|
|
|
|
|
|
Work with Metaplex compressed NFTs.
|
|
|
|
|
@@ -271,32 +267,12 @@ Work with Metaplex compressed NFTs.
|
|
|
|
|
|
<summary>Oracles</summary>
|
|
|
|
|
|
-#### pyth
|
|
|
+### pyth
|
|
|
|
|
|
Use a data source for offchain data (called an Oracle) to perform activities onchain.
|
|
|
|
|
|
-[anchor](./oracles/pyth/anchor), [seahorse](./oracles/pyth/seahorse)
|
|
|
+[anchor](./oracles/pyth/anchor) [seahorse](./oracles/pyth/seahorse)
|
|
|
|
|
|
</details>
|
|
|
|
|
|
-## Examples We'd Love to See!
|
|
|
-
|
|
|
-- Examples needed for Native:
|
|
|
- - Token Extensions
|
|
|
-- Examples needed for Anchor:
|
|
|
- - Additional Accounts & Resolving Accounts
|
|
|
-- Examples needed for Seahorse
|
|
|
- - Any existing example missing a `seahorse` folder
|
|
|
-- New examples needed for Anchor, Native, Solidity & Seahorse:
|
|
|
- - Token lending
|
|
|
- - Token swapping
|
|
|
- - Escrow
|
|
|
- - Staking
|
|
|
- - Wrapped tokens
|
|
|
- - Pyth
|
|
|
- - Clockwork
|
|
|
- - VRF
|
|
|
- - Any oracle
|
|
|
- - Merkle trees (compression)
|
|
|
-
|
|
|
---
|