This is an Anchor project implementing a simple vault manager on the Solana blockchain. The contract allows users to deposit and withdraw tokens from a vault.
2eH4VtkkB5X5592hmuQqFQvQ9QKaTEmRZyvQgf9EWyxp
This is the main module of the contract, containing the program's logic.
initialize: Initializes the Vault Manager.deposit: Allows users to deposit tokens into the vault.withdraw: Allows users to withdraw tokens from the vault.
Initialize: Accounts required for initializing the vault manager.Deposit: Accounts required for depositing tokens into the vault.Withdraw: Accounts required for withdrawing tokens from the vault.
VaultError: Custom error enum for handling insufficient funds errors.
- Creates a PDA (Program Derived Address) for the token account owner.
- Initializes necessary accounts and programs.
- Checks if the sender has sufficient funds.
- Transfers tokens from the sender's account to the vault.
- Uses Cross-Program Invocation (CPI) to interact with the SPL Token program.
- Checks if the vault has sufficient funds.
- Transfers tokens from the vault to the receiver's account.
- Uses CPI with signer seeds to authorize the transfer.
To build and test this Anchor project, follow these steps:
-
Install Anchor and its dependencies:
npm install -g @project-serum/anchor-cli -
Build the project:
anchor build -
Update the program ID in
lib.rsandAnchor.tomlwith the new program ID generated during the build process. -
Test the project:
anchor test -
To deploy the program to a Solana cluster (e.g., devnet):
anchor deploy --provider.cluster devnet
Note: Make sure you have a Solana wallet set up and funded with SOL for deployment costs.
- This contract uses the
anchor_langandanchor_splcrates for Solana program development. - Proper error handling is implemented for insufficient funds scenarios.
- The contract uses PDAs for secure token management.
- Always ensure you have the latest version of Anchor and its dependencies installed.
For more information on Anchor development, visit the official Anchor documentation.