Skip to content

glin-ai/glin-contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

GLIN Smart Contracts

Reference smart contract implementations for the GLIN AI-powered dApp platform. These contracts enable developers to build decentralized applications across legal, healthcare, real estate, and other industries.

πŸ“¦ Contracts

1. GenericEscrow

Purpose: Milestone-based payment escrow with AI oracle integration

Features:

  • βœ… Multi-party agreements (client & provider)
  • βœ… Milestone-based payment releases
  • βœ… Dispute resolution mechanism
  • βœ… AI oracle verification support
  • βœ… Platform fee collection (configurable)
  • βœ… Deadline tracking per milestone

Use Cases:

  • Freelance contracts
  • Service agreements
  • Real estate transactions
  • Legal retainers
  • Construction projects

Key Functions:

create_agreement()      // Create escrow with milestones
complete_milestone()    // Provider marks work done
approve_and_release()   // Client/oracle approves payment
raise_dispute()         // Either party disputes milestone
resolve_dispute()       // Oracle resolves dispute

2. ProfessionalRegistry

Purpose: Staking-based professional registry with reputation system

Features:

  • βœ… Role-based registration (Lawyer, Doctor, Arbitrator, etc.)
  • βœ… Stake requirements per role
  • βœ… Reputation scoring (0-100+)
  • βœ… Review/rating system
  • βœ… Slashing for misbehavior
  • βœ… Profile metadata (IPFS URI)

Use Cases:

  • Professional verification
  • Service provider discovery
  • Reputation-based matching
  • Quality assurance
  • Credential validation

Key Functions:

register()              // Register as professional with stake
increase_stake()        // Add more stake to profile
submit_review()         // Rate a professional (1-5 stars)
slash()                 // Penalize misbehavior (owner only)
withdraw_stake()        // Exit registry

3. ArbitrationDAO

Purpose: Decentralized arbitration with weighted voting

Features:

  • βœ… Stake-weighted voting
  • βœ… Configurable voting periods
  • βœ… Quorum requirements
  • βœ… Appeal mechanism (one appeal per dispute)
  • βœ… Evidence submission (IPFS)
  • βœ… Arbitrator reputation tracking

Use Cases:

  • Contract dispute resolution
  • Community governance
  • Decentralized justice
  • Peer-to-peer conflict resolution
  • DAO decision making

Key Functions:

register_arbitrator()   // Stake to become arbitrator
create_dispute()        // Open new dispute
start_voting()          // Begin arbitration process
vote()                  // Cast weighted vote
finalize_dispute()      // Execute final decision
appeal_dispute()        // Request re-vote (one-time)

πŸš€ Quick Start

Prerequisites

  1. Install Rust & Cargo
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  1. Install cargo-contract
cargo install cargo-contract --force
  1. Add wasm32 target
rustup target add wasm32-unknown-unknown

Build All Contracts

cd glin-contracts/scripts
./build-all.sh

This will:

  • Build all 3 contracts in release mode
  • Generate .contract and .wasm files
  • Copy artifacts to target/ink/

Build Individual Contract

cd glin-contracts/escrow
cargo contract build --release

Run Tests

# Test all contracts
cargo test --workspace

# Test specific contract
cd escrow && cargo test

πŸ“€ Deployment

Local Development Node

  1. Start GLIN node
cd ../glin-chain
./target/release/glin-node --dev
  1. Deploy contracts
cd ../glin-contracts/scripts
./deploy-testnet.sh

Testnet Deployment

export TESTNET_URL="wss://testnet.glin.network"
export SURI="//YourSeedPhrase"  # NEVER commit this!
./deploy-testnet.sh

πŸ’‘ Usage Examples

Example 1: Create Escrow Agreement

// Client creates escrow for 2 milestones
escrow.create_agreement(
    provider_address,
    vec!["Design mockups", "Final implementation"],
    vec![500 * GLIN, 1500 * GLIN],
    vec![timestamp_week_1, timestamp_week_4],
    dispute_timeout,
    Some(oracle_address)
)

Example 2: Register as Professional

// Lawyer registers with 100 GLIN stake
registry.register(
    ProfessionalRole::Lawyer,
    "ipfs://QmYourMetadata" // JSON with credentials
)

Example 3: Create Dispute

// Claimant creates dispute
arbitration.create_dispute(
    defendant_address,
    "Contract breach - undelivered services",
    "ipfs://QmEvidenceBundle"
)

πŸ—οΈ Architecture

Contract Interactions

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  GenericEscrow  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ calls
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ ArbitrationDAO  │◄────►│ ProfessionalReg  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β–²                        β–²
         β”‚                        β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         Check arbitrator status

Integration with GLIN Backend

AI Backend (Rust/Axum)
  β”‚
  β”œβ”€β–Ί Listens to contract events
  β”œβ”€β–Ί Submits AI analysis as oracle
  β”œβ”€β–Ί Caches data for fast queries
  └─► Provides REST API for dApps

πŸ“ Development Guide

Adding a New Contract

  1. Create directory
mkdir glin-contracts/my_contract
  1. Add to workspace (Cargo.toml)
members = [
    "escrow",
    "registry",
    "arbitration",
    "my_contract",  # Add here
]
  1. Create contract (my_contract/lib.rs)
#![cfg_attr(not(feature = "std"), no_std, no_main)]

#[ink::contract]
mod my_contract {
    #[ink(storage)]
    pub struct MyContract {
        // Your storage
    }

    impl MyContract {
        #[ink(constructor)]
        pub fn new() -> Self {
            Self {}
        }

        #[ink(message)]
        pub fn my_function(&self) {}
    }
}
  1. Update build script Add contract to scripts/build-all.sh

πŸ§ͺ Testing

Unit Tests

Each contract includes built-in tests:

cd escrow
cargo test

# With verbose output
cargo test -- --nocapture

Integration Testing

# Start local node
./glin-chain/target/release/glin-node --dev

# Run integration tests (coming soon)
cd glin-contracts/integration-tests
cargo test

πŸ”’ Security Considerations

Storage Deposits

All contracts require deposits for storage:

  • Per item: 1 GLIN
  • Per byte: 0.001 GLIN

Gas Limits

  • Max code size: 256 KB
  • Max storage key: 128 bytes
  • Transient storage: 1 MB

Best Practices

  1. βœ… Always validate inputs
  2. βœ… Use Checks-Effects-Interactions pattern
  3. βœ… Emit events for important state changes
  4. βœ… Implement access control for sensitive functions
  5. βœ… Handle overflows/underflows
  6. βœ… Test edge cases thoroughly

πŸ“Š Gas Cost Estimates

Operation Estimated Cost (GLIN)
Deploy Escrow ~0.5
Create Agreement ~0.1
Complete Milestone ~0.05
Register Professional ~0.2
Submit Review ~0.05
Create Dispute ~0.1
Cast Vote ~0.05

Actual costs may vary based on network congestion


🌐 Frontend Integration

Using Polkadot.js

import { ContractPromise } from '@polkadot/api-contract';

// Connect to contract
const contract = new ContractPromise(
  api,
  escrowMetadata,
  'CONTRACT_ADDRESS'
);

// Call contract method
await contract.tx
  .completeM ilestone({ value: 0, gasLimit: -1 }, agreementId, 0)
  .signAndSend(account);

// Query contract state
const { output } = await contract.query
  .getAgreement(account.address, { gasLimit: -1 }, agreementId);

Using GLIN SDK (Coming Soon)

import { GlinContracts } from '@glin/sdk';

const contracts = new GlinContracts(api);
await contracts.escrow.createAgreement(...);

πŸ”— Resources


πŸ“„ License

Apache 2.0 - see LICENSE file


🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/my-contract)
  3. Write tests
  4. Ensure cargo test passes
  5. Submit pull request

πŸ“ž Support


πŸ—ΊοΈ Roadmap

Phase 1 (Current): βœ… Core contracts

  • GenericEscrow
  • ProfessionalRegistry
  • ArbitrationDAO

Phase 2 (Q2 2025): DeFi & NFT Contracts

  • Lending pools
  • NFT marketplace
  • Staking derivatives

Phase 3 (Q3 2025): Cross-Chain

  • XCM integration
  • Bridge contracts
  • Multi-chain deployment

Phase 4 (Q4 2025): Advanced Features

  • Privacy contracts (zk-SNARKs)
  • Automated market makers
  • Prediction markets

Built with ❀️ by the GLIN Team

Releases

No releases published

Packages

No packages published