Chuyển đến nội dung
MZGrid

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

Solidity
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;
StatusMeaning
NoneNever registered.
ActiveRegistered; can be selected for jobs.
ExitingExit requested; no new jobs; lock still slashable; withdrawal after 10 days.
ExitedLock withdrawn. May register again.

Provider functions

Solidity
function register(string calldata metadataURI) external;

Moves the caller from None or Exited to Active. Emits Registered.

Solidity
function updateMetadata(string calldata metadataURI) external;

Updates the caller's metadata URI.

Solidity
function requestExit() external;

Moves the caller from Active to Exiting and records exitRequestedAt. Emits ExitRequested with unlockAt = exitRequestedAt + EXIT_DELAY.

Solidity
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

Solidity
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)

Solidity
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 -= 1

Slashing (SLASHER_ROLE)

Solidity
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.

ReasonCodeAmount computed by the verifier
Abandoned1min(locked, 2 × job deposit)
OfflineDuringJob2min(locked, 1 × job deposit)
VerificationFailed3100% of locked

Slashing is possible in both Active and Exiting status. See Slashing for examples.

Events

Solidity
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

TypeScript
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) });