Skip to content

Satyam-10124/Growwwstreams

Repository files navigation

πŸš€ Hyper Vara Streams - Quick Start Guide

πŸ“¦ Your Deployed Contracts

βœ… All contracts are already deployed on Vara Testnet!

Contract Program ID Status
USDC Token 0x4d0e258ccc3962cddae2c1d3fc45dbd398cdba55cf19e82c103b9ee6424f6ebe βœ… Live
Escrow Manager 0x62dcf755afbf95e27f163c0687dd24d9950a2b7dfdefedf63a03d17111399fb1 βœ… Live
Verification Bridge 0x073865f712b3760e2a5ffbdfc91c44bf9ade6227230dd3239faa6accead5442a βœ… Live

View contracts: Vara Idea Explorer


πŸƒ How to Run HVS

Step 1: Install Dependencies

cd hyper_vara_streams_deployment
npm install

This installs:

  • @gear-js/api - Vara Network SDK
  • express - REST API framework

Step 2: Choose Your Method

Option A: Run Complete Workflow (Recommended for Testing)

Execute the full project lifecycle automatically:

npm run workflow

What it does:

  1. βœ… Mints USDC tokens
  2. βœ… Creates a project with 3 milestones (30%, 30%, 40%)
  3. βœ… Funds the escrow (60% progress, 35% final, 5% fee)
  4. βœ… Selects a developer
  5. βœ… Submits milestone progress via verification bridge
  6. βœ… Releases payments progressively
  7. βœ… Approves final delivery and releases final 35%

Expected Output:

╔════════════════════════════════════════════════════════════════╗
β•‘     HYPER VARA STREAMS - COMPLETE WORKFLOW                     β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

πŸ”Œ Connecting to Vara Network...
βœ… Connected to Vara Network
   USDC Token: 0x4d0e258ccc...
   Escrow Manager: 0x62dcf755af...
   Verification Bridge: 0x073865f712...

πŸ‘₯ Participants:
   Project Owner: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
   Developer: 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty
   Relayer: 5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y

======================================================================
STEP 1: Setup - Mint USDC Tokens
======================================================================
πŸ’° Minting 100000 USDC tokens...
βœ… Tokens minted successfully!
πŸ’° Owner balance: 100000 USDC
...

Option B: Run REST API Server (For Integration)

Start the HTTP API server:

npm run server

Server starts on http://localhost:3000

Available Endpoints:

# System
GET  /health
GET  /contracts
POST /connect

# Keyring Management
POST /keyring/register
GET  /keyring/list

# USDC Token
POST /usdc/mint
POST /usdc/transfer
GET  /usdc/balance/:address

# Escrow Manager
POST /escrow/create-project
POST /escrow/fund-project
POST /escrow/select-developer
POST /escrow/apply-progress
POST /escrow/mark-final-approved
POST /escrow/set-verifier

# Verification Bridge
POST /bridge/set-relayer
POST /bridge/submit-attestation
GET  /bridge/last-percent/:milestoneIndex
POST /bridge/set-escrow-manager

Step 3: Test the API (curl examples)

1. Initialize Connection

curl -X POST http://localhost:3000/connect

2. Register Keyrings

# Register project owner
curl -X POST http://localhost:3000/keyring/register \
  -H "Content-Type: application/json" \
  -d '{"id": "owner", "seed": "//Alice"}'

# Register developer
curl -X POST http://localhost:3000/keyring/register \
  -H "Content-Type: application/json" \
  -d '{"id": "developer", "seed": "//Bob"}'

# Register relayer
curl -X POST http://localhost:3000/keyring/register \
  -H "Content-Type: application/json" \
  -d '{"id": "relayer", "seed": "//Charlie"}'

3. Mint USDC Tokens

curl -X POST http://localhost:3000/usdc/mint \
  -H "Content-Type: application/json" \
  -d '{
    "toAddress": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
    "amount": "100000",
    "adminKeyringId": "owner"
  }'

4. Check Balance

curl http://localhost:3000/usdc/balance/5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY

5. Create Project

curl -X POST http://localhost:3000/escrow/create-project \
  -H "Content-Type: application/json" \
  -d '{
    "budget": "100000",
    "milestones": [3000, 3000, 4000],
    "ownerKeyringId": "owner"
  }'

6. Submit Milestone Progress

curl -X POST http://localhost:3000/bridge/submit-attestation \
  -H "Content-Type: application/json" \
  -d '{
    "milestoneIndex": 1,
    "percentComplete": 10000,
    "relayerKeyringId": "relayer"
  }'

πŸ“š Using the JavaScript SDK

Basic Usage

const { HyperVaraStreamsAPI } = require('./hyper_vara_streams_api');

async function main() {
  // Initialize API
  const api = new HyperVaraStreamsAPI();
  
  await api.connect('wss://testnet.vara.network', {
    usdcToken: '0x4d0e258ccc3962cddae2c1d3fc45dbd398cdba55cf19e82c103b9ee6424f6ebe',
    escrowManager: '0x62dcf755afbf95e27f163c0687dd24d9950a2b7dfdefedf63a03d17111399fb1',
    verificationBridge: '0x073865f712b3760e2a5ffbdfc91c44bf9ade6227230dd3239faa6accead5442a'
  });

  // Create keyring
  const keyring = api.createKeyring('//Alice');
  
  // Mint tokens
  await api.usdc.mint(keyring.address, 100000n, keyring);
  
  // Check balance
  const balance = await api.usdc.balanceOf(keyring.address);
  console.log(`Balance: ${balance}`);
  
  // Disconnect
  await api.disconnect();
}

main().catch(console.error);

USDC Token Operations

// Mint tokens
await api.usdc.mint(recipientAddress, 50000n, adminKeyring);

// Transfer tokens
await api.usdc.transfer(toAddress, 25000n, senderKeyring);

// Check balance
const balance = await api.usdc.balanceOf(address);

Escrow Manager Operations

// Create project
await api.escrow.createProject(
  100000n,              // Budget
  [3000, 3000, 4000],   // Milestones: 30%, 30%, 40%
  ownerKeyring
);

// Fund project
await api.usdc.transfer(escrowAddress, 100000n, ownerKeyring);
await api.escrow.fundProject(ownerKeyring);

// Select developer
await api.escrow.selectDeveloper(developerAddress, ownerKeyring);

// Set verifier (verification bridge)
await api.escrow.setVerifier(bridgeAddress, ownerKeyring);

// Mark final approved
await api.escrow.markFinalApproved(ownerKeyring);

Verification Bridge Operations

// Set relayer
await api.bridge.setRelayer(1, relayerAddress, adminKeyring);

// Set escrow manager
await api.bridge.setEscrowManager(escrowAddress, adminKeyring);

// Submit attestation (triggers payment)
await api.bridge.submitAttestation(
  1,      // Milestone index
  10000,  // 100% complete (in basis points)
  relayerKeyring
);

// Get last verified percent
const percent = await api.bridge.getLastPercent(1);
console.log(`Milestone 1: ${percent / 100}% complete`);

🎯 Complete Project Flow

1. Setup Phase

# Owner mints USDC tokens
api.usdc.mint(ownerAddress, budget, ownerKeyring)

# Owner creates project
api.escrow.createProject(budget, [3000, 3000, 4000], ownerKeyring)

# Owner sets verification bridge as verifier
api.escrow.setVerifier(bridgeAddress, ownerKeyring)

# Admin configures bridge
api.bridge.setRelayer(1, relayerAddress, adminKeyring)
api.bridge.setEscrowManager(escrowAddress, adminKeyring)

2. Funding Phase

# Owner transfers USDC to escrow
api.usdc.transfer(escrowAddress, budget, ownerKeyring)

# Owner calls fund_project (splits into pools)
api.escrow.fundProject(ownerKeyring)
# Result: 60% β†’ Progress Pool, 35% β†’ Final Pool, 5% β†’ Treasury

3. Development Phase

# Owner selects developer
api.escrow.selectDeveloper(developerAddress, ownerKeyring)

# Developer works on milestones...

4. Progress & Payment Phase

# Relayer submits milestone 1 completion (30%)
api.bridge.submitAttestation(1, 10000, relayerKeyring)
# β†’ Developer receives 30% from progress pool

# Relayer submits milestone 2 completion (30%)
api.bridge.submitAttestation(2, 10000, relayerKeyring)
# β†’ Developer receives another 30% from progress pool

# Relayer submits milestone 3 progress (20% of 40%)
api.bridge.submitAttestation(3, 5000, relayerKeyring)
# β†’ Developer receives 20% from progress pool

# Relayer submits milestone 3 completion (remaining 20%)
api.bridge.submitAttestation(3, 10000, relayerKeyring)
# β†’ Developer receives final 20% from progress pool
# β†’ Total from progress pool: 100% (of 60% budget = 60% of total)

5. Final Delivery Phase

# Owner approves final delivery
api.escrow.markFinalApproved(ownerKeyring)
# β†’ Developer receives final 35% pool

# Final distribution:
# Developer: 95% (60% progressive + 35% final)
# Treasury: 5% (platform fee)

πŸ”§ Troubleshooting

Issue: "API not initialized"

Solution: Call /connect endpoint first or ensure api.connect() is called

Issue: "Keyring not found"

Solution: Register keyring first using /keyring/register

Issue: "Insufficient balance"

Solution: Mint tokens first using api.usdc.mint()

Issue: "Transaction failed"

Solution: Check gas limits, ensure correct permissions (admin/owner/verifier)


πŸ“Š Payment Distribution Example

Project Budget: 100,000 USDC

Initial Split (after funding):
β”œβ”€ Progress Pool (60%): 60,000 USDC
β”œβ”€ Final Pool (35%):    35,000 USDC
└─ Treasury Fee (5%):    5,000 USDC

Milestone Releases:
β”œβ”€ Milestone 1 (30%): 30,000 USDC β†’ Developer
β”œβ”€ Milestone 2 (30%): 30,000 USDC β†’ Developer
└─ Milestone 3 (40%): 40,000 USDC β†’ Developer (split: 20k + 20k)

Final Approval:
└─ Final Pool (35%):  35,000 USDC β†’ Developer

Total Developer Earnings: 95,000 USDC (95%)
Total Treasury Fee:        5,000 USDC (5%)

πŸ“ File Structure

hyper_vara_streams_deployment/
β”œβ”€β”€ DEPLOYMENT_MANIFEST.json          # Contract addresses
β”œβ”€β”€ package.json                      # NPM scripts
β”œβ”€β”€ hyper_vara_streams_api.js         # JavaScript SDK
β”œβ”€β”€ hyper_vara_streams_server.js      # REST API server
β”œβ”€β”€ complete_workflow.js              # Full workflow example
β”œβ”€β”€ usdc_token/
β”‚   β”œβ”€β”€ usdc_token.rs                 # Source code
β”‚   └── usdc_token.wasm               # Compiled WASM
β”œβ”€β”€ escrow_manager/
β”‚   β”œβ”€β”€ escrow_manager.rs             # Source code
β”‚   └── escrow_manager.wasm           # Compiled WASM
└── verification_bridge/
    β”œβ”€β”€ verification_bridge.rs        # Source code
    └── verification_bridge.wasm      # Compiled WASM

🌐 Explorer Links


πŸŽ‰ Next Steps

  1. βœ… Test the workflow: npm run workflow
  2. βœ… Start API server: npm run server
  3. βœ… Integrate with frontend: Use the JavaScript SDK
  4. βœ… Connect Hyperliquid: Configure relayers to submit attestations
  5. βœ… Production deployment: Use secure keyring management (hardware wallets, KMS)

πŸ’‘ Tips

  • Basis Points: Percentages are in basis points (10000 = 100%, 5000 = 50%)
  • Monotonic Progress: Milestones can only move forward, never backward
  • Multi-relayer: Support up to 3 relayers for decentralization
  • Gas Estimation: SDK automatically calculates gas limits
  • Security: Never hardcode seeds in production, use environment variables

πŸ“ž Support

For issues or questions:

  • Check the Vara Documentation
  • View contract source code in respective directories
  • Test with small amounts first

Happy Building! πŸš€

About

Contracts deployed for the GrowStreams

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors