Trang này chỉ có bằng tiếng Anh. Phiên bản tiếng Anh là bản có giá trị chính thức.
ProviderRegistry
Provider status, locked balances, job caps, exit and withdrawal, slashing reasons, functions and events.
ProviderRegistry tracks providers, holds their locked MZG and enforces job caps, the exit delay and slashing. It inherits OpenZeppelin AccessControl.
Types and constants
enum Status { None, Active, Exiting, Exited }
struct Provider {
Status status;
uint128 locked;
uint64 exitRequestedAt;
uint32 activeJobs;
string metadataURI;
}
uint256 public constant EXIT_DELAY = 10 days;
uint256 public constant BASE_JOB_CAP = 25e18; // 25 MZG
uint256 public constant CAP_MULTIPLIER = 4;| Status | Meaning |
|---|---|
None | Never registered. |
Active | Registered; can be selected for jobs. |
Exiting | Exit requested; no new jobs; lock still slashable; withdrawal after 10 days. |
Exited | Lock withdrawn. May register again. |
Provider functions
function register(string calldata metadataURI) external;Moves the caller from None or Exited to Active. Emits Registered.
function updateMetadata(string calldata metadataURI) external;Updates the caller's metadata URI.
function requestExit() external;Moves the caller from Active to Exiting and records exitRequestedAt. Emits ExitRequested with unlockAt = exitRequestedAt + EXIT_DELAY.
function withdrawLocked() external;Requires status Exiting, block.timestamp >= exitRequestedAt + EXIT_DELAY and activeJobs == 0. Transfers the full locked balance to the provider and sets status Exited. Emits LockWithdrawn.
Views
function jobCap(address provider) external view returns (uint256); // BASE_JOB_CAP + CAP_MULTIPLIER * locked
function isActive(address provider) external view returns (bool);The escrow calls both when a job is funded: the provider must be active and the deposit must not exceed jobCap.
Escrow-only functions (ESCROW_ROLE)
function addLock(address provider, uint256 amount) external; // tokens already transferred in by the escrow
function jobStarted(address provider) external; // activeJobs += 1
function jobEnded(address provider) external; // activeJobs -= 1Slashing (SLASHER_ROLE)
function slash(address provider, uint256 amount, bytes32 jobId, uint8 reason, address client) external;The amount is capped at the provider's locked balance. Half goes to client and half to the treasury; if client is the zero address, everything goes to the treasury. Emits Slashed.
| Reason | Code | Amount computed by the verifier |
|---|---|---|
Abandoned | 1 | min(locked, 2 × job deposit) |
OfflineDuringJob | 2 | min(locked, 1 × job deposit) |
VerificationFailed | 3 | 100% of locked |
Slashing is possible in both Active and Exiting status. See Slashing for examples.
Events
event Registered(address indexed provider, string metadataURI);
event LockAdded(address indexed provider, uint256 amount, uint256 newLocked);
event ExitRequested(address indexed provider, uint256 unlockAt);
event LockWithdrawn(address indexed provider, uint256 amount);
event Slashed(address indexed provider, bytes32 indexed jobId, uint8 reason, uint256 amount, uint256 toClient, uint256 toTreasury);Reading a provider with viem
import { providerRegistryAbi, addresses } from "@mzgrid/sdk";
import { createPublicClient, http, formatUnits } from "viem";
import { base } from "viem/chains";
const client = createPublicClient({ chain: base, transport: http() });
const registry = addresses[base.id].registry;
const provider = "0x..." as const;
const [active, cap] = await Promise.all([
client.readContract({ address: registry, abi: providerRegistryAbi, functionName: "isActive", args: [provider] }),
client.readContract({ address: registry, abi: providerRegistryAbi, functionName: "jobCap", args: [provider] }),
]);
console.log({ active, jobCap: formatUnits(cap, 18) });