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 | Address | Explorer |
|---|---|---|
| Mock MUSD | 0x4dABf45C8cF333Ef1e874c3FDFC3C86799af80c8 |
View on Mantle Sepolia Explorer |
| Escrow Contract | 0x3EF7d600DB474F1a544602Bd7dA33c53d98B7B1b |
View on Mantle Sepolia Explorer |
The Escrow contract facilitates secure payments between a User and a Creator, managed by an Executor.
-
Flow:
- Creation: A User creates a transaction (
createTx) by providing a uniquetxId, the Creator's address, and the amount. Funds are transferred from the User to the Contract. - Pending: The transaction enters a
PENDINGstate. - 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.
- Success: The Executor verifies the off-chain condition (e.g., AI response generated) and calls
- Timeout: If the transaction remains
PENDINGfor more than 1 day, the User can calluserCancelto reclaim their funds.
- Creation: A User creates a transaction (
-
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.
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.
- Node.js (v20+ recommended)
- npm or pnpm
-
Current directory:
cd payroute/smartcontract -
Install dependencies:
npm install
Compile the smart contracts:
npx hardhat compileTest Run the test suite:
npx hardhat testTo check gas usage:
REPORT_GAS=true npx hardhat testLocal Node
Start a local Hardhat node:
npx hardhat nodeDeploy Deploy contracts (example using Ignition):
# Deploy to local network
npx hardhat ignition deploy ./ignition/modules/Escrow.ts --network localhostnpx hardhat ignition deploy ./ignition/modules/Escrow.ts --network mantleTestAlternative 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