synor/contracts
Gulshan Yadav 7c7137c4f6 fix: resolve clippy warnings for Rust 1.93
- Replace manual modulo checks with .is_multiple_of()
- Use enumerate() instead of manual loop counters
- Use iterator .take() instead of index-based loops
- Use slice literals instead of unnecessary vec![]
- Allow too_many_arguments in IBC and bridge crates (protocol requirements)
- Allow assertions on constants in integration tests
2026-02-02 06:18:16 +05:30
..
aggregator feat(dex): add Phase 15 - DEX Ecosystem with Perpetuals Trading 2026-01-19 19:22:02 +05:30
confidential-token feat(privacy): add Phase 14 Milestone 2 - Privacy Layer 2026-01-19 17:58:11 +05:30
dex Initial commit: Synor blockchain monorepo 2026-01-08 05:22:17 +05:30
ibc-bridge feat(ibc): add Phase 14 Milestone 1 - Cross-Chain IBC Interoperability 2026-01-19 16:51:59 +05:30
multi-sig feat(tooling): add Phase 14 M4 - Developer Tooling 2026-01-19 20:55:56 +05:30
nft Initial commit: Synor blockchain monorepo 2026-01-08 05:22:17 +05:30
oracle fix: resolve clippy warnings for Rust 1.93 2026-02-02 06:18:16 +05:30
perps feat(dex): add Phase 15 - DEX Ecosystem with Perpetuals Trading 2026-01-19 19:22:02 +05:30
staking Initial commit: Synor blockchain monorepo 2026-01-08 05:22:17 +05:30
template Initial commit: Synor blockchain monorepo 2026-01-08 05:22:17 +05:30
token Initial commit: Synor blockchain monorepo 2026-01-08 05:22:17 +05:30
HOST_FUNCTIONS.md Initial commit: Synor blockchain monorepo 2026-01-08 05:22:17 +05:30
README.md Initial commit: Synor blockchain monorepo 2026-01-08 05:22:17 +05:30

Synor Smart Contracts

This directory contains example smart contracts for the Synor blockchain.

Building Contracts

Contracts are compiled to WebAssembly using the wasm32-unknown-unknown target:

# Install the wasm target
rustup target add wasm32-unknown-unknown

# Build the token contract
cargo build --manifest-path contracts/token/Cargo.toml --target wasm32-unknown-unknown --release

# Build the NFT contract
cargo build --manifest-path contracts/nft/Cargo.toml --target wasm32-unknown-unknown --release

The compiled WASM files will be in target/wasm32-unknown-unknown/release/.

Optimizing Contract Size

For production, use wasm-opt to further reduce contract size:

# Install wasm-opt (part of binaryen)
brew install binaryen  # macOS
apt install binaryen   # Ubuntu

# Optimize the contract
wasm-opt -Oz -o optimized.wasm target/wasm32-unknown-unknown/release/synor_token.wasm

Example Contracts

SYN-20 Token (token/)

A fungible token contract similar to ERC-20:

  • Minting (owner only)
  • Burning
  • Transfers
  • Allowances (approve/transferFrom)
  • Ownership management

SYN-721 NFT (nft/)

A non-fungible token contract similar to ERC-721:

  • Minting NFTs with metadata URI
  • Burning
  • Transfers
  • Approvals (per-token and operator)
  • Ownership management

AMM DEX (dex/)

A Uniswap V2-style automated market maker:

  • Liquidity pools for token pairs
  • Constant product formula (x * y = k)
  • LP tokens for liquidity providers
  • Swap with 0.3% fee
  • Quote/preview swaps

Staking (staking/)

A token staking contract with rewards:

  • Stake tokens for rewards
  • Lock periods with bonus multipliers (1x to 3x)
  • Claim rewards anytime
  • Emergency unstake with 10% penalty
  • Pausable by owner

Creating Your Own Contract

Using the Template Generator

The fastest way to create a new contract:

./scripts/new-contract.sh my-contract --description "My custom contract"

This creates a new contract in contracts/my-contract/ with boilerplate code.

Manual Setup

  1. Create a new contract directory:

    mkdir -p contracts/my_contract/src
    
  2. Create Cargo.toml:

    [package]
    name = "my-contract"
    version = "0.1.0"
    edition = "2021"
    
    [lib]
    crate-type = ["cdylib"]
    
    [dependencies]
    synor-sdk = { path = "../../crates/synor-sdk", default-features = false }
    borsh = { version = "1.3", default-features = false, features = ["derive"] }
    
    [profile.release]
    opt-level = "z"
    lto = true
    panic = "abort"
    strip = true
    
  3. Create src/lib.rs:

    #![no_std]
    extern crate alloc;
    
    use synor_sdk::prelude::*;
    
    synor_sdk::entry_point!(init, call);
    
    fn init(_params: &[u8]) -> Result<()> {
        Ok(())
    }
    
    fn call(selector: &[u8], params: &[u8]) -> Result<Vec<u8>> {
        // Handle method calls
        Err(Error::InvalidMethod)
    }
    
  4. Build:

    cargo build --manifest-path contracts/my_contract/Cargo.toml \
        --target wasm32-unknown-unknown --release
    

Host Function ABI

See HOST_FUNCTIONS.md for the complete list of host functions available to contracts.