Full lesson
AutoShieldFI
What it does
From the project README:
AutoShieldFI é um dApp (aplicativo descentralizado) focado em proteção veicular para o mercado brasileiro. Nosso objetivo é oferecer uma alternativa acessível, eficiente e transparente ao seguro veicular tradicional por meio de infraestrutura Web3, proporcionando uma melhor experiência ao usuário e a possibilidade de retorno financeiro quando a cobertura não é utilizada.
- Original
- bl4cks1d3/AutoShieldFI
- SuperStack fork
- Blockchains/AutoShieldFI @
e207f10 - Stars
- 0
- Last push (original)
- 2026-10-01
- Languages
- TypeScript, Rust, CSS, JavaScript, HTML
- Detected stack
- @solana/kitAnchorNext.jsweb3.js
- Categories
- Other
- Licence
- Apache-2.0
- Homepage
- https://autoshieldfi.vercel.app
Architecture
69 source files. By extension: .ts ×34, .tsx ×21, .rs ×13, .js ×1.
| Top-level directory | Source files |
|---|---|
app | 52 |
programs | 13 |
scripts | 3 |
tests | 1 |
On-chain programs: programs/autoshield
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/autoshieldfi/. 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/autoshield/src/instructions/admin.rs L97–120 @ e207f10 · Apache-2.0 · original/// Qualquer pessoa pode aplicar uma mudanca cujo timelock ja expirou.#[derive(Accounts)]pub struct ApplyGovernance<'info> { pub caller: Signer<'info>, #[account(mut, seeds = [POOL_SEED], bump = pool.bump)] pub pool: Account<'info, Pool>,} pub fn propose_params(ctx: Context<AdminAction>, params: PoolParams) -> Result<()> { require!(params.validate(), AutoShieldError::InvalidParameter); let now = Clock::get()?.unix_timestamp; let pool = &mut ctx.accounts.pool; let eta = now .checked_add(pool.params.governance_delay_secs) .ok_or(AutoShieldError::MathOverflow)?; pool.pending_params = Some(params); pool.pending_params_eta = eta; emit!(GovernanceChangeProposed { kind: 0, eta }); Ok(())} pub fn apply_params(ctx: Context<ApplyGovernance>) -> Result<()> { let now = Clock::get()?.unix_timestamp;- Line 100
pub caller: Signer<'info>,: Requires this account to have signed the transaction. - Line 102
#[account(mut, seeds = [POOL_SEED], bump = pool.bump)]: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 102
#[account(mut, seeds = [POOL_SEED], bump = pool.bump)]: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 107
require!(params.validate(), AutoShieldError::InvalidParameter);: An explicit validation that aborts the instruction with an error. - Line 108
let now = Clock::get()?.unix_timestamp;: Reads on-chain time from the Clock sysvar. - Line 111
.checked_add(pool.params.governance_delay_secs): Uses checked arithmetic so overflow fails instead of wrapping. - Line 115
emit!(GovernanceChangeProposed { kind: 0, eta });: Emits an Anchor event that clients can parse from the logs.
programs/autoshield/src/instructions/bond.rs L25–48 @ e207f10 · Apache-2.0 · original #[account( init_if_needed, payer = assessor, space = 8 + AssessorRecord::INIT_SPACE, seeds = [ASSESSOR_SEED, assessor.key().as_ref()], bump )] pub assessor_record: Box<Account<'info, AssessorRecord>>, pub token_program: Program<'info, Token>, pub system_program: Program<'info, System>,} pub fn post_bond(ctx: Context<AssessorBond>, amount: u64) -> Result<()> { require!(amount > 0, AutoShieldError::ZeroAmount); token::transfer_checked( CpiContext::new( ctx.accounts.token_program.to_account_info(), TransferChecked { from: ctx.accounts.assessor_token.to_account_info(), mint: ctx.accounts.stable_mint.to_account_info(), to: ctx.accounts.vault.to_account_info(), authority: ctx.accounts.assessor.to_account_info(),- Line 27
init_if_needed,: Creates the account only if it doesn't exist. Watch for re-initialisation bugs. - Line 30
seeds = [ASSESSOR_SEED, assessor.key().as_ref()],: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 31
bump: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 40
require!(amount > 0, AutoShieldError::ZeroAmount);: An explicit validation that aborts the instruction with an error. - Line 41
token::transfer_checked(: A checked token transfer, which also verifies the mint and decimals. - Line 41
token::transfer_checked(: An SPL token transfer through the Token Program. - Line 42
CpiContext::new(: Makes a cross-program invocation into another program.
programs/autoshield/src/instructions/claims.rs L361–384 @ e207f10 · Apache-2.0 · originalpub struct ExpireClaim<'info> { pub caller: Signer<'info>, #[account(mut, seeds = [POOL_SEED], bump = pool.bump)] pub pool: Account<'info, Pool>, #[account(mut, has_one = pool, address = claim.policy)] pub policy: Box<Account<'info, Policy>>, #[account(mut, has_one = pool, has_one = policy)] pub claim: Box<Account<'info, Claim>>,} pub fn expire_claim(ctx: Context<ExpireClaim>) -> Result<()> { let now = Clock::get()?.unix_timestamp; let claim = &mut ctx.accounts.claim; require!( matches!(claim.status, ClaimStatus::Pending | ClaimStatus::Appealed), AutoShieldError::ClaimNotPending ); require!(now > claim.voting_deadline, AutoShieldError::VotingStillOpen); claim.status = ClaimStatus::Rejected; claim.resolved_ts = now; let pool = &mut ctx.accounts.pool;- Line 362
pub caller: Signer<'info>,: Requires this account to have signed the transaction. - Line 364
#[account(mut, seeds = [POOL_SEED], bump = pool.bump)]: Declares the PDA seeds. Anchor re-derives the address and rejects the account if it doesn't match. - Line 364
#[account(mut, seeds = [POOL_SEED], bump = pool.bump)]: Uses the bump seed, the extra byte that pushes the derived address off the ed25519 curve. - Line 367
#[account(mut, has_one = pool, address = claim.policy)]: Checks that a stored pubkey field matches the passed account. - Line 375
let now = Clock::get()?.unix_timestamp;: Reads on-chain time from the Clock sysvar. - Line 377
require!(: An explicit validation that aborts the instruction with an error.
programs/autoshield/src/instructions/policy.rs L325–348 @ e207f10 · Apache-2.0 · original #[account(mut, has_one = pool, has_one = owner @ AutoShieldError::Unauthorized)] pub policy: Box<Account<'info, Policy>>, pub token_program: Program<'info, Token>,} /// Paga a proxima parcela. So e aceita ate o fim da tolerancia: depois disso a/// apolice caducou (evita pagar so depois do acidente).pub fn pay_installment(ctx: Context<PayInstallment>) -> Result<()> { let now = Clock::get()?.unix_timestamp; let grace = ctx.accounts.pool.params.installment_grace_secs; let policy = &ctx.accounts.policy; require!( policy.status == PolicyStatus::Active, AutoShieldError::PolicyNotActive ); require!(!policy.fully_paid(), AutoShieldError::AlreadyFullyPaid); require!(!policy.is_lapsed(now, grace), AutoShieldError::PolicyLapsed); let amount = policy.next_installment_amount(); token::transfer_checked( CpiContext::new( ctx.accounts.token_program.to_account_info(),- Line 326
#[account(mut, has_one = pool, has_one = owner @ AutoShieldError::Unauthorized)]: Checks that a stored pubkey field matches the passed account. - Line 335
let now = Clock::get()?.unix_timestamp;: Reads on-chain time from the Clock sysvar. - Line 338
require!(: An explicit validation that aborts the instruction with an error. - Line 346
token::transfer_checked(: A checked token transfer, which also verifies the mint and decimals. - Line 346
token::transfer_checked(: An SPL token transfer through the Token Program. - Line 347
CpiContext::new(: Makes a cross-program invocation into another program.
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 |
|---|---|---|
. | npm run lint | prettier */*.js "*/**/*{.js,.ts}" --check |
app | npm run dev | next dev |
app | npm run start | next start |
app | npm run build | next build |
app | npm run lint | tsc --noEmit |
. | anchor build | compile programs and generate IDLs |
. | anchor test | local validator + test suite |
. | anchor run bootstrap | yarn run ts-node scripts/bootstrap.ts |
. | anchor run oracle | yarn run ts-node scripts/oracle-fipe.ts |
. | anchor run shop | yarn run ts-node scripts/register-shop.ts |
. | anchor run test | yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts |
. | cargo build | Rust workspace build |
. | cargo test | Rust tests |
What you could build from it
- Fork the SuperStack copy and extend it within the Other gaps listed on the idea page.
- Learn the pattern first: Program Derived Addresses (PDAs)
- Learn the pattern first: Cross-Program Invocations (CPIs)