Smart contracts

Technical reference for the SadClaw Solana program.

Program Overview

The SadClaw program handles on-chain logic for VM purchases, NFT minting, and ownership management.

Program ID: SADCLAWvmProgram111111111111111111111111111

Source: github.com/techwebc/sadclaw/programs/sadclaw-vmarrow-up-right

Instructions

Initialize

Initialize the program configuration. Called once by the admin.

pub fn initialize(
    ctx: Context<Initialize>,
    admin: Pubkey,
    treasury: Pubkey,
    usdc_mint: Pubkey,
) -> Result<()>

Accounts:

Account
Type
Description

config

PDA

Program config account

payer

Signer

Transaction payer

system_program

Program

System program

CreateTier

Create a new VM pricing tier.

Accounts:

Account
Type
Description

config

PDA

Program config

tier

PDA

New tier account

admin

Signer

Admin authority

PurchaseVm

Purchase a new VM with USDC.

Accounts:

Account
Type
Description

config

PDA

Program config

tier

PDA

Selected tier

vm_instance

PDA

New VM instance

nft_mint

Mint

New NFT mint

nft_metadata

Metaplex

NFT metadata

buyer

Signer

Purchaser

buyer_usdc

TokenAccount

Buyer's USDC account

treasury_usdc

TokenAccount

Treasury USDC account

token_program

Program

SPL Token program

metadata_program

Program

Metaplex program

Logic:

  1. Calculate cost: tier.price_per_hour * duration_hours

  2. Transfer USDC from buyer to treasury

  3. Create VM instance PDA

  4. Mint NFT to buyer

  5. Create NFT metadata

ExtendVm

Extend an existing VM's duration.

Accounts:

Account
Type
Description

vm_instance

PDA

Existing VM

tier

PDA

VM's tier

nft_mint

Mint

VM's NFT

owner

Signer

NFT owner

owner_usdc

TokenAccount

Owner's USDC

treasury_usdc

TokenAccount

Treasury USDC

DestroyVm

Destroy a VM and burn its NFT.

Accounts:

Account
Type
Description

vm_instance

PDA

VM to destroy

nft_mint

Mint

VM's NFT

nft_token_account

TokenAccount

Owner's NFT account

owner

Signer

NFT owner

token_program

Program

SPL Token program

Logic:

  1. Verify owner holds the NFT

  2. Burn the NFT

  3. Mark VM instance as destroyed

  4. Close the VM instance account

PDAs

Config

Global program configuration.

Seeds: ["config"]

Tier

VM pricing tier.

Seeds: ["tier", tier_id]

VM Instance

Individual VM state.

Seeds: ["vm", vm_id]

Events

VmPurchased

Emitted when a VM is purchased.

VmExtended

Emitted when a VM is extended.

VmDestroyed

Emitted when a VM is destroyed.

Errors

Integration

Building Transactions

Listening to Events

Security

  • All instructions verify signer authority

  • NFT ownership verified before operations

  • USDC transfers are atomic with state changes

  • PDAs prevent account spoofing

  • Duration limits prevent overflow attacks

Last updated