Skip to content

payroute-protocol/x402-contracts

Repository files navigation

Payroute Smart Contracts

This directory contains the smart contracts for the Payroute project, a payment routing and escrow system. It currently features an Escrow contract for secure transactions and a mock stablecoin (MUSD) for testing purposes.

Contract Addresses

Mantle Sepolia Testnet

Contract Address Explorer
Mock MUSD 0x4dABf45C8cF333Ef1e874c3FDFC3C86799af80c8 View on Mantle Sepolia Explorer
Escrow Contract 0x3EF7d600DB474F1a544602Bd7dA33c53d98B7B1b View on Mantle Sepolia Explorer

Contracts

1. Escrow.sol

The Escrow contract facilitates secure payments between a User and a Creator, managed by an Executor.

  • Flow:

    1. Creation: A User creates a transaction (createTx) by providing a unique txId, the Creator's address, and the amount. Funds are transferred from the User to the Contract.
    2. Pending: The transaction enters a PENDING state.
    3. Finalization:
      • Success: The Executor verifies the off-chain condition (e.g., AI response generated) and calls finalizeSuccess. Funds are transferred to the Creator.
      • Failure: If the condition fails, the Executor calls finalizeFailure. Funds are refunded to the User.
    4. Timeout: If the transaction remains PENDING for more than 1 day, the User can call userCancel to reclaim their funds.
  • Roles:

    • Executor: The entity authorized to finalize transactions (defaults to deployer).
    • User: The sender of funds.
    • Creator: The receiver of funds.
  • Key Functions:

    • createTx(bytes32 txId, address creator, uint256 amount): Lock funds and start a transaction.
    • finalizeSuccess(bytes32 txId): Release funds to creator. (Executor only)
    • finalizeFailure(bytes32 txId): Refund funds to user. (Executor only)
    • userCancel(bytes32 txId): Refund funds to user after timeout.

2. MUSD.sol (Mantle USD)

A mock ERC20 stablecoin used for testing and development on testnets.

  • Decimals: 6 (Similar to USDT/USDC).
  • Faucet: Contains a public faucet(address to, uint amount) function that allows anyone to mint tokens for testing.

Prerequisites

  • Node.js (v20+ recommended)
  • npm or pnpm

Setup

  1. Current directory:

    cd payroute/smartcontract
  2. Install dependencies:

    npm install

Development Commands

Compile

Compile the smart contracts:

npx hardhat compile

Test Run the test suite:

npx hardhat test

To check gas usage:

REPORT_GAS=true npx hardhat test

Local Node

Start a local Hardhat node:

npx hardhat node

Deploy Deploy contracts (example using Ignition):

# Deploy to local network
npx hardhat ignition deploy ./ignition/modules/Escrow.ts --network localhost

Deploy to Mantle Testnet (requires .env configuration)

npx hardhat ignition deploy ./ignition/modules/Escrow.ts --network mantleTest

Alternative Deployment (Script) You can also use the legacy deployment script, which allows for more customization (e.g. using existing token addresses):

npx hardhat run scripts/deploy.ts --network <network_name>

Configuration Duplicate .env.example (if available) to .env and fill in your private key and RPC URLs.

License UNLICENSED

About

Payroute x402 Smart Contracts

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors