synor/docs/PLAN/PHASE4-SmartContracts/01-Milestone-01-ContractSDK.md
Gulshan Yadav 48949ebb3f Initial commit: Synor blockchain monorepo
A complete blockchain implementation featuring:
- synord: Full node with GHOSTDAG consensus
- explorer-web: Modern React blockchain explorer with 3D DAG visualization
- CLI wallet and tools
- Smart contract SDK and example contracts (DEX, NFT, token)
- WASM crypto library for browser/mobile
2026-01-08 05:22:17 +05:30

3.9 KiB

Phase 4, Milestone 1: Contract Development Kit

SDK and tooling for smart contract development

Status: Complete Priority: Medium Crates: synor-sdk, contracts/*


Overview

Create a comprehensive development kit for building smart contracts on Synor, including SDK, templates, and example contracts.


Tasks

Task 1.1: Contract Template

  • Create boilerplate project structure
  • Cargo.toml template with WASM target
  • Basic contract skeleton
  • README with instructions
  • Generator script

Files:

  • contracts/template/
  • scripts/new-contract.sh

Template Structure:

contracts/template/
├── Cargo.toml
├── src/
│   └── lib.rs
├── tests/
│   └── integration.rs
└── README.md

Task 1.2: Host Function Documentation

  • Document all host functions
  • Parameter types and return values
  • Gas costs per function
  • Usage examples
  • Security considerations

Files:

  • contracts/HOST_FUNCTIONS.md

Host Functions:

Function Description Gas
env::caller() Get caller address 100
env::block_height() Current height 50
env::timestamp() Block timestamp 50
env::value() SYNOR sent 50
storage::get(key) Read storage 500
storage::set(key, value) Write storage 5000
storage::delete(key) Delete storage 500
env::emit_event(name, data) Emit event 1000
crypto::hash(data) Blake3 hash 200
crypto::verify(pk, msg, sig) Verify signature 3000

Task 1.3: Rust SDK

  • Procedural macros for contracts
  • Storage abstractions
  • Event emission helpers
  • Crypto utilities
  • ABI generation

Files:

  • crates/synor-sdk/

SDK Features:

#[synor_contract]
mod my_contract {
    #[init]
    pub fn init() { ... }

    #[call]
    pub fn transfer(to: Address, amount: u64) { ... }

    #[view]
    pub fn balance_of(addr: Address) -> u64 { ... }
}

Task 1.4: Example Contracts

  • Fungible token (ERC-20 style)
  • Non-fungible token (ERC-721 style)
  • Decentralized exchange (AMM)
  • Staking contract

Files:

  • contracts/token/ - Fungible token
  • contracts/nft/ - NFT contract
  • contracts/dex/ - AMM exchange
  • contracts/staking/ - Staking rewards

Validation

Validation Commands

# Build all contracts
for dir in contracts/*/; do
  (cd "$dir" && cargo build --target wasm32-unknown-unknown --release)
done

# Run contract tests
for dir in contracts/*/; do
  (cd "$dir" && cargo test)
done

# Verify WASM output
wasm-objdump -h contracts/token/target/wasm32-unknown-unknown/release/token.wasm

Validation Agents

Agent Purpose
code-reviewer Review SDK and contracts
type-design-analyzer Validate SDK types

Contract Test Matrix

Contract Unit Tests Integration Tests Gas Tests
Token 15 5 3
NFT 12 4 2
DEX 20 8 5
Staking 18 6 4

Security Checks

  • Re-entrancy protection in SDK
  • Integer overflow checks
  • Access control patterns
  • Storage key collision prevention
  • Gas limit enforcement

Contract Verification

// Token contract tests
#[test]
fn test_transfer() {
    let mut env = TestEnv::new();
    let alice = env.create_account(1000);
    let bob = env.create_account(0);
    let contract = env.deploy("token", &alice, &[1000u64]);

    env.call(&contract, &alice, "transfer", &[&bob, &100u64]);

    assert_eq!(env.view::<u64>(&contract, "balance_of", &[&alice]), 900);
    assert_eq!(env.view::<u64>(&contract, "balance_of", &[&bob]), 100);
}

Acceptance Criteria

  1. SDK compiles and tests pass
  2. All example contracts deploy successfully
  3. Host functions documented
  4. Template script generates valid projects
  5. Gas costs are reasonable

Completed: January 2025