Skip to content

Trustless-Work/EVM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trustless Work - Avalanche EVM Implementation

Gasless USDT Escrow Infrastructure for Avalanche C-Chain

Built for Avalanche x Tether Hackathon 🏔️💰

🚀 Live on Avalanche Fuji Testnet

Contract Address Snowtrace
MockUSDT 0x314FAf4931e6bd8dc4ae0b17cA48dFA7F88838b9 View Code
GaslessForwarder 0xe5E115786F3a5131BEDB62EB9FD02811723c757C View Code
TrustlessWorkFactory 0x3cD54445dC9812B74752B671561C7204A75b045C View Code

Network: Avalanche Fuji Testnet Chain ID: 43113 Status: ✅ All contracts deployed and verified


🎯 What is This?

Trustless Work is NOT an app - it's INFRASTRUCTURE.

ANY platform can deploy their own escrow contracts in 5 minutes using our Factory pattern.

Key Features

USDT Programmable Vaults - 4% APY on locked funds (NEW!) ✅ TES-1 Standard - First USDT escrow standard on Avalanche (NEW!) ✅ Gasless Transactions - Users NEVER need AVAX, only USDT ✅ Factory Pattern - Any platform can deploy escrows ✅ EIP-2771 Compliant - Meta-transactions support ✅ 6 Decimal USDT - Correctly handles real USDT ✅ Role-Based Access - 6 configurable roles per escrow ✅ Milestone Support - Single-release escrows with multiple checkpoints ✅ Yield Tracking - Real-time metrics across all escrows


📁 Project Structure

EVM/
├── contracts/
│   ├── core/
│   │   ├── EscrowBase.sol              # Base logic for all escrows (implements TES-1)
│   │   ├── SingleReleaseEscrow.sol     # Single-payment escrow with yield
│   │   └── TrustlessWorkFactory.sol    # Factory for deploying escrows
│   ├── gasless/
│   │   └── GaslessForwarder.sol        # EIP-2771 forwarder
│   ├── mocks/
│   │   └── MockUSDT.sol                # 6-decimal USDT for testing
│   └── interfaces/
│       ├── IUSDT.sol                   # USDT interface
│       └── ITetherEscrowStandard.sol   # TES-1 standard interface
├── scripts/
│   └── deploy.js                       # Deployment script
├── deployments/                         # Deployment info JSONs
└── IMPLEMENTATION_SUMMARY.md            # Complete feature documentation

🚀 Quick Start

1. Install Dependencies

npm install --legacy-peer-deps

2. Setup Environment

Copy .env.example to .env and fill in:

FUJI_RPC_URL=https://api.avax-test.network/ext/bc/C/rpc
PRIVATE_KEY=your_private_key_here
SNOWTRACE_API_KEY=your_snowtrace_api_key_here

3. Compile Contracts

npx hardhat compile

4. Deploy to Avalanche Fuji

npx hardhat run scripts/deploy.js --network fuji

5. Get Free Fuji AVAX

https://faucet.avax.network/

6. Verify Contracts (Optional)

npx hardhat verify --network fuji <CONTRACT_ADDRESS>

⚡ Quick Test (Using Deployed Contracts)

Want to test the live contracts? Here's how:

Option 1: Using Snowtrace UI

  1. Go to the TrustlessWorkFactory on Snowtrace: https://testnet.snowtrace.io/address/0x3cD54445dC9812B74752B671561C7204A75b045C#writeContract

  2. Connect your wallet

  3. Call createSingleReleaseEscrow with your parameters

  4. Check getTotalYieldGenerated() to see accumulated yield across all escrows

Option 2: Using Hardhat Console

npx hardhat console --network fuji

const factory = await ethers.getContractAt(
  "TrustlessWorkFactory",
  "0x3cD54445dC9812B74752B671561C7204A75b045C"
);

// Check metrics
const totalEscrows = await factory.getTotalEscrows();
const totalYield = await factory.getTotalYieldGenerated();
const totalLocked = await factory.getTotalUSDTLocked();

console.log("Total Escrows:", totalEscrows.toString());
console.log("Total Yield:", ethers.formatUnits(totalYield, 6), "USDT");
console.log("Total Locked:", ethers.formatUnits(totalLocked, 6), "USDT");

🏗️ Smart Contracts

TrustlessWorkFactory

The core infrastructure contract. ANY platform calls this to deploy their own escrow.

function createSingleReleaseEscrow(
    string memory _engagementId,
    string memory _title,
    string memory _description,
    EscrowBase.Roles memory _roles,
    uint256 _amount,
    uint256 _platformFee,
    string[] memory _milestoneDescriptions
) external returns (address escrowAddress)

SingleReleaseEscrow

Individual escrow contract with:

  • 6 Roles: Approver, ServiceProvider, ReleaseSigner, DisputeResolver, PlatformAddress, Receiver
  • Milestones: Multiple checkpoints that must all be approved
  • Gasless Support: Works with GaslessForwarder for meta-transactions
  • Dispute Resolution: Built-in arbitration mechanism

GaslessForwarder

EIP-2771 compliant forwarder:

  • Users sign transactions
  • Relayer pays gas
  • Users only need USDT, never AVAX

ITetherEscrowStandard (TES-1)

The first proposed standard for USDT escrows on Avalanche:

interface ITetherEscrowStandard {
    // Standard Events
    event USDTLocked(uint256 amount, string escrowId, address indexed platform);
    event USDTReleased(uint256 amount, address indexed recipient, uint256 yieldAmount);
    event USDTDisputed(string escrowId, address indexed initiator);

    // Core Metrics
    function totalUSDTLocked() external view returns (uint256);
    function totalYieldGenerated() external view returns (uint256);
    function averageHoldTime() external view returns (uint256);

    // Core Functions
    function depositUSDT(uint256 amount) external;
    function releaseWithYield() external;
    function getYieldRate() external view returns (uint256);
}

Why TES-1?

  • Enables ANY platform to build USDT escrows that are interoperable
  • Tether can track ALL USDT escrow activity on Avalanche via standard events
  • Creates a foundation for USDT DeFi infrastructure on Avalanche

💰 How USDT Programmable Vaults Work

Yield Generation Explained

Every escrow automatically generates 4% APY on locked USDT:

// When funds are deposited, timestamp is recorded
depositTimestamp = block.timestamp;

// Yield calculation (simple interest)
function getAccumulatedYield() public view returns (uint256) {
    uint256 timeElapsed = block.timestamp - depositTimestamp;
    uint256 principal = amount;
    return (principal * 400 * timeElapsed) / (365 days * 10000);
}

// On release, receiver gets principal + yield
uint256 yieldAmount = getAccumulatedYield();
uint256 totalPayout = amount - platformFee + yieldAmount;

Key Features

  • Automatic: No action required, yield accrues every second
  • Transparent: Anyone can query getAccumulatedYield() anytime
  • Fair: Platform fee calculated on principal only, not yield
  • Bonus: Yield goes 100% to the receiver as bonus payment
  • Trackable: YieldGenerated event emitted on every release

Example

// Freelancer escrow: 1000 USDT locked for 30 days
const principal = 1000; // USDT
const days = 30;
const apy = 0.04; // 4%

// Yield calculation
const yield = (principal * apy * days) / 365;
// = 3.29 USDT

// Total payout to freelancer
const total = principal - platformFee + yield;
// = 1000 - 25 + 3.29 = 978.29 USDT

This makes Trustless Work the FIRST escrow system where your money works for you while locked!


💡 How It Works (Gasless Flow)

1. User signs transaction (has only USDT, no AVAX)
2. Relayer receives signed message
3. Relayer submits to GaslessForwarder (pays gas)
4. Forwarder verifies signature
5. Forwarder executes on target contract
6. User's USDT is used, they paid $0 in AVAX

📊 Architecture

┌─────────────────────────────────────┐
│      Frontend (Next.js + ethers)    │
├─────────────────────────────────────┤
│      Gasless Relayer (Express)      │
├─────────────────────────────────────┤
│      GaslessForwarder Contract      │
├─────────────────────────────────────┤
│   TrustlessWorkFactory Contract     │
│   ├── SingleReleaseEscrow 1         │
│   ├── SingleReleaseEscrow 2         │
│   └── SingleReleaseEscrow ...       │
├─────────────────────────────────────┤
│       Avalanche C-Chain (Fuji)      │
└─────────────────────────────────────┘

🎬 Demo Scenarios

Scenario 1: Freelance Marketplace

// Platform deploys escrow for client-freelancer job
const escrow = await factory.createSingleReleaseEscrow({
  engagementId: "job-123",
  title: "Website Development",
  roles: {
    approver: clientAddress,
    serviceProvider: freelancerAddress,
    releaseSigner: platformAddress,
    // ...
  },
  amount: parseUnits("1000", 6), // 1000 USDT
  platformFee: 250, // 2.5%
  // ...
});

Scenario 2: DAO Bounty

// DAO deploys escrow for bounty
const escrow = await factory.createSingleReleaseEscrow({
  engagementId: "bounty-456",
  title: "Fix Critical Bug",
  roles: {
    approver: daoMultisig,
    serviceProvider: developerAddress,
    releaseSigner: daoMultisig,
    // ...
  },
  amount: parseUnits("500", 6), // 500 USDT
  // ...
});

🔥 What Makes This Special for Avalanche x Tether?

The 4 Pillars

1️⃣ USDT Programmable Vaults

  • Locked USDT generates 4% APY automatically
  • Makes idle funds productive while awaiting milestone completion
  • First escrow system where your money works for you while locked

2️⃣ Gasless USDT Payments

  • Users can use USDT without ever touching AVAX
  • EIP-2771 meta-transactions via GaslessForwarder
  • Platform pays gas, users only need USDT

3️⃣ Cross-Border Freelance Highway

  • Instant international payments with USDT
  • No banks, no delays, no high fees
  • Perfect for freelancers, DAOs, and P2P exchanges

4️⃣ TES-1: The Tether Escrow Standard

  • First proposed standard for USDT escrows on Avalanche
  • Standardized events, metrics, and functions
  • Enables interoperability between platforms
  • Makes Avalanche THE place for USDT escrow infrastructure

Why This Matters

  • Infrastructure Play: Not a single app, enables 1000s of apps
  • Real USDT Integration: Correctly handles 6 decimals and non-standard ERC20
  • Avalanche Speed: 1-2 second finality showcased in demo
  • Volume Potential: Every escrow = more USDT flowing through Avalanche

📈 Metrics We're Tracking

Real-Time Dashboard Metrics

  • Total Escrows Created - Number of escrows deployed via factory
  • Total USDT Locked - Current TVL across all active escrows
  • Total Yield Generated - 4% APY accumulated across all escrows
  • Total Volume Processed - Lifetime USDT volume through the system
  • Active Escrows - Currently funded and operational
  • Gas Saved for Users - From gasless meta-transactions
  • Average Hold Time - How long USDT stays locked (yield calculation)
  • Platforms Integrated - Number of platforms using our infrastructure

Per-Platform Metrics (via Factory)

  • Volume per platform
  • Yield generated per platform
  • Number of escrows per platform

🛠️ Development

Run Tests

npx hardhat test

Start Local Node

npx hardhat node

Deploy Locally

npx hardhat run scripts/deploy.js --network localhost

🎯 Hackathon Submission Highlights

Complete Implementation of All 4 Features

  • USDT Programmable Vaults - 4% APY on locked funds
  • Gasless USDT Payments - EIP-2771 meta-transactions
  • Cross-Border Freelance Highway - Instant international payments
  • TES-1 Standard - First USDT escrow standard on Avalanche

Technical Excellence

  • Fully Functional Contracts on Avalanche Fuji
  • Factory Pattern - Infrastructure, not just an app
  • Live Demo with real transactions
  • Open Source and composable
  • Yield Generation - Making USDT productive while locked
  • Real-Time Metrics - Dashboard-ready analytics

Innovation

  • 🏆 First-ever USDT yield-generating escrow
  • 🏆 First proposed standard (TES-1) for USDT escrows on Avalanche
  • 🏆 Infrastructure play that enables thousands of platforms
  • 🏆 Gasless UX removing barriers to USDT adoption

Live Metrics (Testnet)

Check these metrics in real-time on the deployed Factory contract:

// Via Snowtrace Read Contract:
// https://testnet.snowtrace.io/address/0x3cD54445dC9812B74752B671561C7204A75b045C#readContract

getTotalEscrows()           // Number of escrows created
getTotalVolume()            // Total USDT volume processed
getTotalYieldGenerated()    // Total yield accumulated (4% APY)
getTotalUSDTLocked()        // Current TVL across all escrows

For Judges: You can verify ALL functionality is working by:

  1. Checking the verified source code on Snowtrace ✅
  2. Reading real-time metrics from the Factory contract ✅
  3. Seeing the 3 demo escrows already created ✅
  4. Viewing all events emitted (including TES-1 standard events) ✅

🚨 IMPORTANT NOTES

  • USDT has 6 decimals, not 18! Use parseUnits(amount, 6)
  • Gasless relayer needs funding for gas
  • Platform fee is in basis points (250 = 2.5%)
  • All roles are immutable once escrow is deployed

📞 Links & Resources

Verified Contracts on Snowtrace

Documentation

  • Implementation Summary: See IMPLEMENTATION_SUMMARY.md for complete feature documentation
  • Deployment Info: Check deployments/ folder for deployment details

Network Info


🏆 Built for Avalanche x Tether Hackathon

Theme: Making USDT payments frictionless on Avalanche

Our Solution: Gasless escrow infrastructure that ANY platform can use

Impact: Enable thousands of platforms to integrate programmable USDT payments


Made with ❤️ for the Avalanche ecosystem

About

EVM build of TW. Re-started for Avax hackathon on Blockchain Jungle

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •