Delegation (ERC-7710)
Trustless vault deposits via the MetaMask Delegation Framework. Users grant limited, purpose-specific permissions so the 7N7D agent can deposit into the trading vault on their behalf — without exposing full wallet control.
The delegation module is currently scaffolded. Caveat enforcer addresses and EIP-712 domain are placeholders. Full signing integration with @metamask/delegation-toolkit ships in Phase 2.
Quick Start
import { DelegationClient } from '@7n7d/sdk';
const delegation = new DelegationClient({
agentAddress: '0x992264E591fC70a467b6a5B3763DE94384989Dd7',
chainId: 421614, // Arbitrum Sepolia (default)
});
// Build an unsigned delegation for vault deposit
const unsigned = delegation.buildVaultDepositDelegation(
'0xYourWalletAddress',
{
vaultAddress: '0xVaultAddress',
usdcAddress: '0xUsdcAddress',
maxAmount: 1000_000000n, // 1000 USDC (6 decimals)
expiry: 0n, // No expiry
},
);
// Get a human-readable summary
const result = delegation.summarize(unsigned, {
vaultAddress: '0xVaultAddress',
usdcAddress: '0xUsdcAddress',
maxAmount: 1000_000000n,
expiry: 0n,
});
console.log(result.summary);
// "Delegate 0x9922... may deposit up to 1000.00 USDC into vault 0xVault... (no expiry)"
DelegationClient
Constructor
new DelegationClient(config: DelegationClientConfig)
| Property | Type | Required | Description |
|---|---|---|---|
agentAddress | Address | Yes | The 7N7D agent address that acts as delegate |
chainId | number | No | Chain ID (default: 421614 — Arbitrum Sepolia) |
Throws if agentAddress is not provided.
Methods
buildVaultDepositDelegation(delegator, config)
Build an unsigned delegation for a vault deposit. The caller must sign it with their wallet (Phase 2).
| Parameter | Type | Description |
|---|---|---|
delegator | Address | Address granting the delegation |
config | VaultDepositDelegationConfig | Deposit constraints |
Returns: Delegation — unsigned (signature is 0x).
Throws:
maxAmountmust be positiveexpirymust be non-negative
getDelegationStatus(delegation)
Check the status of a delegation.
| Parameter | Type | Description |
|---|---|---|
delegation | Delegation | The delegation to check |
Returns: DelegationStatus — "active" | "expired" | "revoked" | "redeemed"
Currently returns "active" (stub). Phase 2 will query the on-chain DelegationManager.
summarize(delegation, config)
Create a human-readable summary of a delegation.
Returns: DelegationResult — { delegation, summary }
Types
All types are importable from @7n7d/sdk:
import type {
Caveat,
Delegation,
DelegationResult,
DelegationStatus,
VaultDepositDelegationConfig,
DelegationClientConfig,
} from '@7n7d/sdk';
Caveat
interface Caveat {
enforcer: Address; // Caveat enforcer contract address
terms: Hex; // ABI-encoded terms the enforcer validates
}
Delegation
interface Delegation {
delegator: Address; // Address granting the delegation
delegate: Address; // Address receiving the delegation (7N7D agent)
authority: Hex; // Smart account implementation authority
caveats: Caveat[]; // Restrictions on the delegation scope
salt: bigint; // Random salt for uniqueness
signature: Hex; // EIP-712 signature from delegator
}
VaultDepositDelegationConfig
interface VaultDepositDelegationConfig {
vaultAddress: Address; // Vault contract to deposit into
usdcAddress: Address; // USDC token address
maxAmount: bigint; // Max deposit amount in USDC base units (6 decimals)
expiry: bigint; // Unix timestamp expiry (0 = no expiry)
}
DelegationResult
interface DelegationResult {
delegation: Delegation; // The signed delegation object
summary: string; // Human-readable description
}
DelegationStatus
type DelegationStatus = "active" | "expired" | "revoked" | "redeemed";
Constants
import {
CAVEAT_ENFORCERS,
DELEGATION_EIP712_DOMAIN,
ROOT_AUTHORITY,
} from '@7n7d/sdk';
CAVEAT_ENFORCERS
MetaMask Delegation Framework caveat enforcer addresses (placeholder — updated once deployed to Arbitrum Sepolia).
| Key | Description |
|---|---|
allowedAmount | Limits total value that can be transferred |
allowedMethods | Restricts which contract methods can be called |
allowedTargets | Restricts which contract addresses can be called |
timestamp | Enforces time-based expiry |
DELEGATION_EIP712_DOMAIN
EIP-712 signing domain for delegations.
{
name: "DelegationManager",
version: "1",
chainId: 421614,
verifyingContract: "0x0000..." // Updated once deployed
}
ROOT_AUTHORITY
Zero hash used as root authority for top-level delegations.
const ROOT_AUTHORITY = "0x0000...0000"; // 32-byte zero hash
CLI Integration
The SDK delegation module powers the CLI delegate-deposit command:
npx @7n7d/cli delegate-deposit \
--vault 0xVaultAddress \
--usdc 0xUsdcAddress \
--max-amount 1000 \
--expiry 0
See CLI Commands for details.