Skip to content

ninebitcomputer/MBC_25_Contract

Repository files navigation

SolanaAid

A decentralized donation infrastructure built on Solana using Anchor. SolanaAid enables anyone to register NGOs, create donation pools, receive donations, and track on-chain giving—all with transparent, verifiable program logic and client tooling.

Features

NGO Registry

  • NGOs register on-chain via a deterministic PDA.

  • Each NGO has metadata including name, authority, and approval state.

Donation Pools

  • Pools are created with a unique u64 ID.

  • Each pool is a PDA derived as:

    seeds = [b"pool", id.to_le_bytes()]
    
  • Pool metadata includes NGO owner, name, donation stats, and bump.

Donations

  • Anyone can donate SOL to a pool.

  • Funds are sent directly to the NGO’s vault PDA or authority.

Admin Configuration

  • Global config PDA storing allowed pools, NGO approvals, and global settings.

  • Only program authority can approve/deny NGOs or modify system settings.

TypeScript Client

  • Uses the Anchor-generated IDL types (target/types/solana_aid.ts).

  • Helper scripts to derive PDAs, fetch pool data, approve NGOs, list donations, etc.

PDAs (Program Derived Accounts)

NGO PDA

const [ngoPda] = PublicKey.findProgramAddressSync(
  [Buffer.from("ngo"), ngoAuthority.toBuffer()],
  program.programId
);

Pool PDA

const [poolPda] = PublicKey.findProgramAddressSync(
  [Buffer.from("pool"), new BN(id).toArrayLike(Buffer, "le", 8)],
  program.programId
);

Config PDA

const [configPda] = PublicKey.findProgramAddressSync(
  [Buffer.from("config")],
  program.programId
);

Building & Deploying

Build Program

anchor build

Test Program

anchor test

Deploy to Devnet

anchor build anchor deploy --provider.cluster devnet

Publish IDL to Anchor Registry

anchor idl add <PROGRAM_ID>

TypeScript Client Usage

Initialize Anchor Provider

export ANCHOR_PROVIDER_URL=https://api.devnet.solana.com
export ANCHOR_WALLET=$HOME/.config/solana/id.json

Run script

npx ts-node scripts/[script]
  • All admin-only instructions require the admin PDA as signer.

  • PDA derivation prevents collisions and spoofing.

  • NGOs cannot spend funds from unauthorized pools.

  • Donations are atomic and logged on-chain.

Script descriptions

config.ts

  • Handles global program configuration.

  • Derives the Config PDA

  • Provides helpers to:

    • Fetch the global config account

    • Decode config fields with generated IDL types

    • Display admin address, allowed pools, and system metadata

ngo.ts

  • Utility functions for working with NGOs on-chain.

  • Derives the NGO PDA

  • Fetches NGO metadata accounts

  • Provides helpers for:

    • Creating NGO accounts (if handled client-side)

    • Fetching name, authority, approval status

    • Displaying NGO information in a human-readable format

modify-ngo.ts

  • Client script for modifying NGO metadata.

  • Handles updating an NGO’s fields such as:

    • Name

    • Description

    • Display data

  • Wraps Anchor RPC calls for the modifyNgo instruction

  • Ensures PDAs are derived consistently before invocation

pool.ts

  • Handles everything related to donation pools.

  • Derives Pool PDA from id: u64

  • Fetches/deserializes pool account data

  • Displays pool metadata:

    • Pool name

    • NGO owner

    • Total donations

  • Includes helper wrappers for:

    • Creating pools

    • Fetching all pools associated with a given NGO

donate.ts

  • Script for performing a donation.

  • Wraps the RPC call for the donate instruction

  • Accepts:

    • Pool ID

    • Donation amount (SOL or lamports)

  • Derives pool PDAs automatically

  • Prints transaction signature + post-donation pool stats

withdraw.ts

  • Allows NGOs to withdraw funds from their pools.

  • Wraps the RPC call for withdraw

  • Handles deriving:

    • Pool PDA

    • NGO PDA

  • Ensures only NGO authority can withdraw

  • Prints transaction receipt and updated pool balance

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors