Full lesson
D2D
A decentralized infrastructure helping developers deploy on Solana affordably. With D2D, devs can borrow small amounts of SOL from the community to deploy their programs — and lenders earn yield while supporting innovation.
What it does
From the project README:
D2D is a comprehensive deployment service that automates the process of deploying Solana programs from devnet to mainnet. The system handles program dumping, wallet generation, and mainnet deployment, making it easy for developers to transition their programs to production.
- Original
- SaitamaCoderVN/D2D
- SuperStack fork
- Blockchains/D2D @
03387fe - Stars
- 0
- Last push (original)
- 2025-11-09
- Languages
- TypeScript, Rust, PLpgSQL, CSS, JavaScript
- Detected stack
- AnchorNext.jsweb3.js
- Categories
- DeFiGaming
- Licence
- MIT
Architecture
81 source files. By extension: .ts ×43, .rs ×26, .tsx ×10, .js ×2.
| Top-level directory | Source files |
|---|---|
backend | 34 |
programs | 28 |
frontend | 19 |
On-chain programs: programs/d2d-program-sol/programs/d2d-program-sol
Dapp: devnet deploy pending
⏳ Devnet deploy pending — goes live when the devnet wallet is topped up. This fork's own dapp is not deployed yet, so there is no program address or transaction to show. It is queued in dapp-queue.txt; once devnet SOL is available it is deployed, exercised with real devnet transactions, and this section switches to the live dapp at /dapps/d2d/. Until then, the lesson and step-by-step guide below are complete, and you can run it locally with the commands below.
Key code, explained
Excerpts chosen automatically where the code uses the most Solana concepts, pinned to the fork's commit.
programs/d2d-program-sol/programs/d2d-program-sol/src/instructions/lender/claim_rewards.rs L37–60 @ 03387fe · MIT · original // Check if treasury has enough funds require!( rewards <= treasury_pool.calculate_total_rewards()?, ErrorCode::InsufficientTreasuryFunds ); // Update lender stake lender_stake.total_claimed += rewards; lender_stake.last_claim_time = Clock::get()?.unix_timestamp; // Update treasury pool treasury_pool.total_rewards_distributed += rewards; // Transfer rewards to lender from Treasury Pool PDA let treasury_pool_seeds = &[ TreasuryPool::PREFIX_SEED, &[ctx.accounts.treasury_pool.bump], ]; let signer_seeds = &[&treasury_pool_seeds[..]]; let cpi_context = CpiContext::new_with_signer( ctx.accounts.system_program.to_account_info(), system_program::Transfer { from: ctx.accounts.treasury_pool.to_account_info(),- Line 38
require!(: An explicit validation that aborts the instruction with an error. - Line 43
// Update lender stake: Touches staking state: the amount locked and when it was locked. - Line 45
lender_stake.last_claim_time = Clock::get()?.unix_timestamp;: Reads on-chain time from the Clock sysvar. - Line 51
let treasury_pool_seeds = &[: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 53
&[ctx.accounts.treasury_pool.bump],: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 57
let cpi_context = CpiContext::new_with_signer(: Makes a CPI signed by a PDA. The signer seeds prove the program controls that address.
programs/d2d-program-sol/programs/d2d-program-sol/src/instructions/deploy_program.rs L13–36 @ 03387fe · MIT · original )] pub treasury_pool: Account<'info, TreasuryPool>, #[account( init, payer = developer, space = 8 + DeployRequest::INIT_SPACE, seeds = [DeployRequest::PREFIX_SEED, program_hash.as_ref()], bump )] pub deploy_request: Account<'info, DeployRequest>, #[account( init_if_needed, payer = developer, space = 8 + UserDeployStats::INIT_SPACE, seeds = [UserDeployStats::PREFIX_SEED, developer.key().as_ref()], bump )] pub user_stats: Account<'info, UserDeployStats>, #[account(mut)] pub developer: Signer<'info>, #[account( mut, constraint = admin.key() == treasury_pool.admin @ ErrorCode::Unauthorized )]- Line 16
init,: Creates and pays for a new account. Space and payer must be specified. - Line 19
seeds = [DeployRequest::PREFIX_SEED, program_hash.as_ref()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 20
bump: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 24
init_if_needed,: Creates the account only if it doesn't exist. Watch for re-initialisation bugs. - Line 32
pub developer: Signer<'info>,: Requires this account to have signed the transaction.
programs/d2d-program-sol/programs/d2d-program-sol/src/instructions/admin/suspend_expired_programs.rs L1–24 @ 03387fe · MIT · originaluse crate::errors::ErrorCode;use crate::events::ProgramsSuspended;use crate::states::TreasuryPool;use anchor_lang::prelude::*; #[derive(Accounts)]pub struct SuspendExpiredPrograms<'info> { #[account( seeds = [TreasuryPool::PREFIX_SEED], bump = treasury_pool.bump )] pub treasury_pool: Account<'info, TreasuryPool>, #[account(mut)] pub admin: Signer<'info>,} pub fn suspend_expired_programs(ctx: Context<SuspendExpiredPrograms>) -> Result<()> { let treasury_pool = &ctx.accounts.treasury_pool; let current_time = Clock::get()?.unix_timestamp; require!(!treasury_pool.emergency_pause, ErrorCode::ProgramPaused); require!( ctx.accounts.admin.key() == treasury_pool.admin, ErrorCode::Unauthorized- Line 9
seeds = [TreasuryPool::PREFIX_SEED],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 10
bump = treasury_pool.bump: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 14
pub admin: Signer<'info>,: Requires this account to have signed the transaction. - Line 19
let current_time = Clock::get()?.unix_timestamp;: Reads on-chain time from the Clock sysvar. - Line 21
require!(!treasury_pool.emergency_pause, ErrorCode::ProgramPaused);: An explicit validation that aborts the instruction with an error.
programs/d2d-program-sol/programs/d2d-program-sol/src/instructions/lender/stake_sol.rs L13–36 @ 03387fe · MIT · original mut, seeds = [TreasuryPool::PREFIX_SEED], bump = treasury_pool.bump )] pub treasury_pool: Account<'info, TreasuryPool>, #[account( init_if_needed, payer = lender, space = 8 + BackerDeposit::INIT_SPACE, seeds = [BackerDeposit::PREFIX_SEED, lender.key().as_ref()], bump )] pub lender_stake: Account<'info, BackerDeposit>, #[account(mut)] pub lender: Signer<'info>, pub system_program: Program<'info, System>,} /// Stake SOL into treasury pool (create deposit)/// Returns a deposit receipt tracked in BackerDeposit accountpub fn stake_sol(ctx: Context<StakeSol>, amount: u64, lock_period: i64) -> Result<()> { let treasury_pool = &mut ctx.accounts.treasury_pool; let lender_stake = &mut ctx.accounts.lender_stake; let current_time = Clock::get()?.unix_timestamp;- Line 14
seeds = [TreasuryPool::PREFIX_SEED],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 15
bump = treasury_pool.bump: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 19
init_if_needed,: Creates the account only if it doesn't exist. Watch for re-initialisation bugs. - Line 27
pub lender: Signer<'info>,: Requires this account to have signed the transaction. - Line 36
let current_time = Clock::get()?.unix_timestamp;: Reads on-chain time from the Clock sysvar.
How to run, build and test
These commands come from the repo's own manifests (package.json scripts, Anchor.toml, Cargo, go.mod, Makefile). Check the README for prerequisites and environment variables.
| Directory | Command | Runs |
|---|---|---|
frontend | npm run dev | next dev |
frontend | npm run start | next start |
frontend | npm run build | next build |
frontend | npm run lint | next lint |
programs/d2d-program-sol | npm run test | mocha -r ts-node/register tests/*.test.ts |
programs/d2d-program-sol | npm run lint | prettier */*.js "*/**/*{.js,.ts}" --check |
backend | npm run start | nest start |
backend | npm run build | nest build |
backend | npm run test | jest |
backend | npm run lint | eslint "{src,apps,libs,test}/**/*.ts" --fix |
programs/d2d-program-sol | anchor build | compile programs and generate IDLs |
programs/d2d-program-sol | anchor test | local validator + test suite |
programs/d2d-program-sol | anchor run test | yarn run mocha -r ts-node/register tests/**/d2d-program-sol.ts |
What you could build from it
- Fork the SuperStack copy and extend it within the DeFi gaps listed on the idea page.
- Learn the pattern first: Program Derived Addresses (PDAs)
- Learn the pattern first: Cross-Program Invocations (CPIs)
- Learn the pattern first: SPL Tokens: mints, accounts and transfers