Developers
Root user operations
The root acts through ERC-4337 user operations for EntryPoint v0.7. Each one carries a batch of calls, a module to install or a module to remove, and is valid only with enough signatures from the root's keys.
What a root operation can do
| Kind | Use it for |
|---|---|
| execute | A batch of calls: Gate settings, transfers out, sub-vault calls, root and guardian changes. |
| installModule | Plugging in a module: the sub-vault module, the timelock hook, the signer. |
| uninstallModule | Pulling a module out. |
The root validator accepts only these three Safe7579 calls, so a root signature can never be used for anything else.
Keys and thresholds
A root has one to ten keys and a threshold. A key is an ECDSA address or a WebAuthn passkey, checked on the P-256 curve through the RIP-7212 precompile. ECDSA keys sign the EIP-191 hash of the user operation hash; encodeRootSignature orders the signatures as the validator expects.
import { buildRootOp, ecdsaRootSigner, gate } from "@mortiseagentvault/sdk";
const root = {
members: [
{ type: "ecdsa", signer: KEY_A },
{ type: "ecdsa", signer: KEY_B },
{ type: "passkey", x: PASSKEY_X, y: PASSKEY_Y },
],
threshold: 2,
};
// Keys A and B sign; each passes its index in the root.
const op = await buildRootOp(client, vault, { kind: "execute", calls: [gate.setAgent(AGENT, 0n)] }, {
root,
signers: [ecdsaRootSigner(0, accountA), ecdsaRootSigner(1, accountB)],
bundlerUrl: BUNDLER_URL,
});Sending
sendUserOpToBundler sends through an ERC-4337 bundler; Alchemy's serves Robinhood Chain. sendUserOpDirect calls the EntryPoint from an ordinary account, which pays the gas up front and is repaid by the vault. Either way the vault pays for its own operations, from its ETH or through a paymaster.
With root.setPaymasterOnly(true), every root operation must name a paymaster, so the vault's own ETH never pays gas. The timelock requires it, because gas is paid before any hook runs.
Sub-vaults
The parent installs the sub-vault module once with subVaults.install(). After that, one operation can create a sub-vault, accept it into the family, fund it and give it its own agent. subVaults.sweep moves every listed token back to the parent.
import { mortise, subVaults, subVaultsAbi, gate, buildRootOp } from "@mortiseagentvault/sdk";
// The address is fixed by the parent and a number.
const child = await client.readContract({
address: mortise.subVaults, abi: subVaultsAbi, functionName: "predictSubVault", args: [vault, 1n],
});
const op = await buildRootOp(client, vault, {
kind: "execute",
calls: [
subVaults.create(vault, 1n),
gate.acceptChild(child),
subVaults.exec(child, [gate.setAgent(AGENT, until), gate.setCap(AGENT, USDG, limit, day)]),
gate.setAgent(AGENT, 0n), // take the agent off the parent
],
}, { root, signers, bundlerUrl: BUNDLER_URL });Guardian recovery
root.setGuardians(guardians, threshold, delay) names who can replace a lost root. Each guardian calls approveRecovery for one exact new root from its own key; once the threshold approves and the delay of 7 to 90 days has passed, anyone calls executeRecovery. The root can cancel with root.cancelRecovery() until then.
Timelock
timelock.install(delay, destinations) puts a delay of 1 to 30 days on every change that widens what the vault allows. Tightening, withdrawals to the registered destinations, sweeps and funds coming back from sub-vaults run at once. Anything else is scheduled with timelock.schedule and runs once, after the delay and before the schedule expires.