Full lesson
OuroC
A Fully on-chain, compliance aligned subscription tool for Solana
What it does
From the project README:
๐ **Proof-of-Concept Subscription Infrastructure** - ICP Timer + Solana Smart Contract
- Original
- Legatia/OuroC
- SuperStack fork
- Blockchains/OuroC @
7f4b495 - Stars
- 2
- Last push (original)
- 2025-11-10
- Languages
- Motoko, TypeScript, Rust, Python, HTML, JavaScript
- Detected stack
- AnchorNext.jsweb3.js
- Categories
- Infrastructure & Tooling
- Licence
- MIT
Architecture
299 source files. By extension: .tsx ร107, .ts ร105, .rs ร57, .js ร22, .py ร8.
| Top-level directory | Source files |
|---|---|
Archive | 168 |
OuroC-Mesos | 104 |
solana-contract | 27 |
On-chain programs: Archive/solana-contract-mesos/ouroc_prima/programs/ouroc_prima, solana-contract/ouroc_prima/programs/ouroc_prima
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/ouroc/. 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.
Archive/solana-contract-mesos/ouroc_prima/programs/ouroc_prima/src/lib.rs L73โ95 @ 7f4b495 ยท MIT ยท original #[account( mut, has_one = authority @ ErrorCode::UnauthorizedAccess )] pub config: Account<'info, Config>, pub authority: Signer<'info>,} #[derive(Accounts)]#[instruction(subscription_id: String)]pub struct CreateSubscription<'info> { #[account( init, payer = subscriber, space = 8 + Subscription::LEN, seeds = [b"subscription", subscription_id.as_bytes()], bump )] pub subscription: Account<'info, Subscription>, #[account(seeds = [b"config"], bump)] pub config: Account<'info, Config>,- Line 75
has_one = authority @ ErrorCode::UnauthorizedAccess: Checks that a stored pubkey field matches the passed account. - Line 79
pub authority: Signer<'info>,: Requires this account to have signed the transaction. - Line 86
init,: Creates and pays for a new account. Space and payer must be specified. - Line 89
seeds = [b"subscription", subscription_id.as_bytes()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 90
bump: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve.
solana-contract/ouroc_prima/programs/ouroc_prima/src/lib.rs L73โ96 @ 7f4b495 ยท MIT ยท original #[account( mut, has_one = authority @ ErrorCode::UnauthorizedAccess )] pub config: Account<'info, Config>, pub authority: Signer<'info>,} #[derive(Accounts)]#[instruction(subscription_id: String)]pub struct CreateSubscription<'info> { #[account( init, payer = subscriber, space = 8 + Subscription::LEN, seeds = [b"subscription", subscription_id.as_bytes()], bump )] pub subscription: Account<'info, Subscription>, /// Subscription PDA (same as subscription account key, for delegation) /// CHECK: PDA derived from subscription_id #[account(- Line 75
has_one = authority @ ErrorCode::UnauthorizedAccess: Checks that a stored pubkey field matches the passed account. - Line 79
pub authority: Signer<'info>,: Requires this account to have signed the transaction. - Line 86
init,: Creates and pays for a new account. Space and payer must be specified. - Line 89
seeds = [b"subscription", subscription_id.as_bytes()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 90
bump: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve.
Archive/solana-contract-mesos/ouroc_prima/programs/ouroc_prima/src/payment_helpers.rs L121โ144 @ 7f4b495 ยท MIT ยท original let fee_config = &config.fee_config; let platform_fee = subscription.amount .checked_mul(fee_config.fee_percentage_basis_points as u64) .ok_or(ErrorCode::MathOverflow)? .checked_div(BASIS_POINTS_DIVISOR) .ok_or(ErrorCode::MathOverflow)?; let merchant_amount = subscription.amount .checked_sub(platform_fee) .ok_or(ErrorCode::InsufficientAmount)?; // Use subscription PDA as authority (subscriber must delegate to this PDA) // Derive PDA signer seeds for CPI - Clone ID to avoid borrow issues let subscription_id = subscription.id.clone(); let subscription_key = subscription.key(); // Find the bump seed for this subscription PDA let (subscription_pda, bump) = Pubkey::find_program_address( &[b"subscription", subscription_id.as_bytes()], program_id ); // Verify the subscription account matches the derived PDA require!(- Line 123
.checked_mul(fee_config.fee_percentage_basis_points as u64): Uses checked arithmetic so overflow fails instead of wrapping. - Line 137
// Find the bump seed for this subscription PDA: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 138
let (subscription_pda, bump) = Pubkey::find_program_address(: Derives a PDA from seeds and the program ID and returns the address with its canonical bump. - Line 144
require!(: An explicit validation that aborts the instruction with an error.
Archive/solana-contract-mesos/ouroc_prima/programs/ouroc_prima/src/instruction_handlers.rs L337โ360 @ 7f4b495 ยท MIT ยท original /// Pause a subscriptionpub fn pause_subscription(ctx: Context<UpdateSubscription>) -> Result<()> { let subscription = &mut ctx.accounts.subscription; require!(subscription.status == SubscriptionStatus::Active, ErrorCode::SubscriptionNotActive); let clock = Clock::get()?; let subscription_id = subscription.id.clone(); subscription.status = SubscriptionStatus::Paused; msg!("Subscription {} paused", subscription_id); emit!(SubscriptionPaused { subscription_id, paused_at: clock.unix_timestamp, }); Ok(())} /// Resume a subscriptionpub fn resume_subscription(ctx: Context<UpdateSubscription>) -> Result<()> { let subscription = &mut ctx.accounts.subscription;- Line 341
require!(subscription.status == SubscriptionStatus::Active, ErrorCode::SubscriptionNotActi: An explicit validation that aborts the instruction with an error. - Line 343
let clock = Clock::get()?;: Reads on-chain time from the Clock sysvar. - Line 348
msg!("Subscription {} paused", subscription_id);: Logs to the program log, which is visible in explorers and the test output. - Line 350
emit!(SubscriptionPaused {: Emits an Anchor event that clients can parse from the logs.
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 |
|---|---|---|
Archive/demo-dapp | npm run dev | next dev -p 3002 |
Archive/demo-dapp | npm run start | next start |
Archive/demo-dapp | npm run build | next build |
Archive/demo-dapp | npm run lint | next lint |
OuroC-Mesos/frontend | npm run dev | vite |
OuroC-Mesos/frontend | npm run build | vite build |
OuroC-Mesos/frontend | npm run lint | eslint . |
solana-contract/ouroc_prima | npm run test | anchor test |
solana-contract/ouroc_prima | npm run lint | prettier */*.js "*/**/*{.js,.ts}" --check |
Archive/solana-contract-mesos/ouroc_prima | anchor build | compile programs and generate IDLs |
Archive/solana-contract-mesos/ouroc_prima | anchor test | local validator + test suite |
Archive/solana-contract-mesos/ouroc_prima | anchor run test | yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts |
solana-contract/ouroc_prima | anchor build | compile programs and generate IDLs |
solana-contract/ouroc_prima | anchor test | local validator + test suite |
solana-contract/ouroc_prima | anchor run test | yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts |
. | cargo build | Rust workspace build |
What you could build from it
- Fork the SuperStack copy and extend it within the Infrastructure & Tooling gaps listed on the idea page.
- Learn the pattern first: Building and sending transactions from a client
- Learn the pattern first: Anchor account constraints