{"id":22399896,"url":"https://github.com/laugharne/ssf_s3_exo","last_synced_at":"2026-05-03T16:32:31.096Z","repository":{"id":252422286,"uuid":"838690560","full_name":"Laugharne/ssf_s3_exo","owner":"Laugharne","description":"Build an asset manager’s vault, where customers can deposit SPL tokens of their choice. The vault manager should not be able to withdraw the vault’s funds.","archived":false,"fork":false,"pushed_at":"2024-08-10T05:58:37.000Z","size":563,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T00:16:58.867Z","etag":null,"topics":["anchor","cpi","fellowship","pda","rust","rust-lang","solana","summer","test","test-unit","token","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Laugharne.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-06T06:42:29.000Z","updated_at":"2024-08-10T05:58:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"e38fd531-4a14-4dbf-abf8-628bcf0e1888","html_url":"https://github.com/Laugharne/ssf_s3_exo","commit_stats":null,"previous_names":["laugharne/ssf_s3_exo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Laugharne/ssf_s3_exo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Laugharne%2Fssf_s3_exo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Laugharne%2Fssf_s3_exo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Laugharne%2Fssf_s3_exo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Laugharne%2Fssf_s3_exo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Laugharne","download_url":"https://codeload.github.com/Laugharne/ssf_s3_exo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Laugharne%2Fssf_s3_exo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32577121,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T06:36:36.687Z","status":"ssl_error","status_checked_at":"2026-05-03T06:36:09.306Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["anchor","cpi","fellowship","pda","rust","rust-lang","solana","summer","test","test-unit","token","typescript"],"created_at":"2024-12-05T08:10:26.080Z","updated_at":"2026-05-03T16:32:31.073Z","avatar_url":"https://github.com/Laugharne.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Asset manager's vault\n\n## Deployed program\n\n**Program Id:** `8uot8k7km7RtdkxFfXGG2nrRd8CxAG4p2SNJ5sSpmQaz`\n\n**On devnet : [Solana Explorer Link](https://solana.fm/address/8uot8k7km7RtdkxFfXGG2nrRd8CxAG4p2SNJ5sSpmQaz/transactions?cluster=devnet-solana)**\n\n--------\n\n\n## Overview\n\n![](2024-08-06-08-27-27.png)\n\n**Exercise:** Build an **asset manager’s vault**, where customers can deposit SPL tokens of their choice. The vault manager should not be able to withdraw the vault’s funds\n\nTopics in this exercice :\n- Rust\n- Anchor\n- PDA\n- init_if_needed\n- CPI\n- ATA creation\n- Token transfer\n- Build \u0026 deploy on devnet\n\n### Components\n\n- This Anchor program defines a vault that allows users to deposit SPL tokens into a secure account managed by a PDA.\n- The PDA acts as the authority over the vault, ensuring that only authorized actions can be performed.\n- The program is designed with error handling and careful account validation to prevent unauthorized access or insufficient funds errors.\n\n1. Program \u0026 instructions\n    - **Initialization**: `initialize()`, a function to set up initial state or accounts required by the program. In this case, it just logs \"INITIALIZE\" and does nothing else.\n    - **Depose tokens**: `deposit()`, the function to deposit SPL tokens into the vault. It performs checks and transfers tokens.\n\n2. Accounts\n\n    **Initialize Struct**\n    ```rust\n    #[derive(Accounts)]\n    pub struct Initialize\u003c'info\u003e {\n        ...\n    }\n    ```\n    - **`#[derive(Accounts)]`**: This macro implements necessary traits for the struct to be used in a context (e.g., in `Context\u003cInitialize\u003e`).\n    - **`token_account_owner_pda: AccountInfo\u003c'info\u003e`**: An unchecked account that represents the PDA (Program Derived Address) which will own the token vault. It's marked as `CHECK`, meaning it requires extra care as it's not automatically validated by Anchor.\n    - **`signer: Signer\u003c'info\u003e`**: The account that signs the transaction and pays for the transaction fees.\n    - **`system_program: Program\u003c'info, System\u003e`**: The Solana System Program, which is necessary for account initialization.\n    - **`token_program: Program\u003c'info, Token\u003e`**: The SPL Token program, used for handling tokens.\n    - **`rent: Sysvar\u003c'info, Rent\u003e`**: A system variable that provides the current rent exemption status.\n\n    **Deposit Struct**\n    ```rust\n    #[derive(Accounts)]\n    pub struct Deposit\u003c'info\u003e {\n        ...\n    }\n    ```\n    - **`token_account_owner_pda: AccountInfo\u003c'info\u003e`**: Similar to the Initialize struct, this is the PDA that will own the vault.\n    - **`vault: Account\u003c'info, TokenAccount\u003e`**: The vault account where tokens will be stored. It is created if needed (`init_if_needed`), associated with the mint and owned by the PDA.\n    - **`signer: Signer\u003c'info\u003e`**: The user who is depositing tokens.\n    - **`mint_account: Account\u003c'info, Mint\u003e`**: The mint account for the tokens being deposited.\n    - **`sender_token_account: Account\u003c'info, TokenAccount\u003e`**: The token account from which tokens will be transferred.\n    - **`token_program: Program\u003c'info, Token\u003e`**: The SPL Token program.\n    - **`system_program: Program\u003c'info, System\u003e`**: The system program, required for account initialization.\n\n3. **Error Handling**\n    ```rust\n    #[error_code]\n    pub enum VaultError {\n        #[msg(\"Insufficient Funds.\")]\n        InsufficientFunds,\n    }\n    ```\n\n    - **`#[error_code]`**: This macro defines custom error codes for the program. It allows the program to return specific errors that can be handled by the client.\n    - **`VaultError`**: This enum defines possible errors, such as \"Insufficient Funds\", which is used when a user tries to deposit more tokens than they have.\n\n\n4. **CPI Context and Token Transfer**\n    ```rust\n    let transfer_instruction: anchor_spl::token::Transfer = Transfer {\n        from:      ctx.accounts.sender_token_account.to_account_info(),\n        to:        ctx.accounts.vault.to_account_info(),\n        authority: ctx.accounts.signer.to_account_info(),\n    };\n\n    let cpi_ctx: CpiContext\u003canchor_spl::token::Transfer\u003e = CpiContext::new(\n        ctx.accounts.token_program.to_account_info(),\n        transfer_instruction,\n    );\n\n    anchor_spl::token::transfer(cpi_ctx, amount)?;\n    ```\n\n    - **Transfer**: A struct defining the details of the token transfer, specifying the source account, destination account, and authority.\n    - **CpiContext**: Context for a cross-program invocation (CPI). This wraps the transfer instruction and provides the necessary program information.\n    - **anchor_spl::token::transfer**: This function performs the token transfer.\n\n\n## Tree repository\n\n```bash\n.\n├── app\n├── migrations\n│   └── deploy.ts\n├── programs\n│   └── vault\n│       ├── src\n│       │   └── lib.rs\n│       ├── Cargo.toml\n│       └── Xargo.toml\n├── tests\n│   └── vault.ts\n├── 2024-08-06-08-27-27.png\n├── Anchor.toml\n├── Cargo.lock\n├── Cargo.toml\n├── package.json\n├── package-lock.json\n├── README.md\n├── tsconfig.json\n└── yarn.lock\n\n6 directories, 14 files\n```\n\n## Deployment\n\n**Changing the cluster environnement**\n\n```bash\nsolana config set --url devnet\n```\n\n**Create and set wallet if needed**\n\n```bash\nsolana-keygen new --outfile ~/.config/solana/devnet.json\nsolana config set --keypair ~/.config/solana/devnet.json\nsolana airdrop 2\n```\n\n**Update : Anchor.toml**\n\n```toml\n[programs.devnet]\nmy_program = \"8uot8k7km7RtdkxFfXGG2nrRd8CxAG4p2SNJ5sSpmQaz\"\n\n[provider]\ncluster = \"devnet\"\nwallet = \"~/.config/solana/devnet.json\"\n# cluster = \"Localnet\"\n# wallet = \"~/.config/solana/id.json\"\n```\n\n**Build and deploy**\n\n```bash\nanchor build\nanchor deploy\n```\n\n\u003e**Program Id:** 8uot8k7km7RtdkxFfXGG2nrRd8CxAG4p2SNJ5sSpmQaz\n\u003e\n\u003e Deploy success\n\n\n## Local tests\n\n### Local validator\n\n`solana-test-validator --reset`\n\n⚠️ Beware it creates local files and directories at the current working directory.\n\n\n### Real-time logs display\n\n`solana logs`\n\n\n### Local deploy and launch tests\n\n`anchor test --skip-local-validator`\n\n## Versions\n\n```\nrustc 1.79.0 (129f3b996 2024-06-10)\ncargo 1.79.0 (ffa9cf99a 2024-06-03)\nsolana-cli 1.18.17 (src:b685182a; feat:4215500110, client:SolanaLabs)\nanchor-cli 0.29.0\nyarn 1.22.22\nnode v18.17.0\nnpm 9.6.7\n```\n\n`cargo build-sbf -V`\n```\nsolana-cargo-build-sbf 1.18.17\nplatform-tools v1.41\nrustc 1.75.0\n```\n\n## Resources\n- [Cross Program Invocation (CPI) | Solana](https://solana.com/docs/core/cpi)\n- [Anchor : High-level Overview - Docs](https://www.anchor-lang.com/docs/high-level-overview)\n- [Program Derived Addresses (PDAs) | Solana Cookbook](https://solanacookbook.com/core-concepts/pdas.html#facts)\n- [Slides : Anchor](https://pitch.com/v/anchor-dudz4a)\n- [CPI code for transferring tokens](https://github.com/solana-developers/program-examples/blob/main/tokens/transfer-tokens/anchor/programs/transfer-tokens/src/instructions/transfer.rs)\n- [Transferring SOL and building a payment splitter: \u0026quot;msg.value\u0026quot; in Solana](https://www.rareskills.io/post/anchor-transfer-sol)\n- [Cross Program Invocation in Anchor](https://www.rareskills.io/post/cross-program-invocation)\n- [PDA (Program Derived Address) vs Keypair Account in Solana](https://www.rareskills.io/post/solana-pda)\n- [Solana Playground| Spl Token Vault](https://beta.solpg.io/tutorials/spl-token-vault)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaugharne%2Fssf_s3_exo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaugharne%2Fssf_s3_exo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaugharne%2Fssf_s3_exo/lists"}