Skip to content
Lattice

GovernedVaultLib

Git Source

Title: GovernedVaultLib

Author: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80)

The one piece of genuinely NEW logic the self-governed ERC-4626 vault needs on top of the audited modules it composes (ERC20VotesLib, ERC4626Lib/VaultCoreLib, VotesLib, GovernorLib, TimelockControllerLib): a DEDICATED nonce namespace for the governor's castVoteBySig.

WHY THIS EXISTS: GovernorLib.castVoteBySig and ERC20VotesLib's delegateBySig both draw from NoncesLib — fine when the token and the governor are separate contracts (the canonical OZ topology), but on ONE diamond they would share a single counter, so signing a delegation would consume the nonce a pending vote signature depends on (and vice versa), silently invalidating it. GovernedVault keeps the token's delegateBySig on NoncesLib and routes the governor's ballot nonce through this namespace, so the two are independent — the exact isolation the two-contract deployment enjoys for free. Everything else (share accounting, checkpoints, proposal lifecycle, timelock) reuses the existing libraries unmodified; only the nonce source and the vault-mint→checkpoint seam (in the facet) are new.

Functions

governedVaultStorage

function governedVaultStorage() internal pure returns (GovernedVaultStorage storage $);

Returns

NameTypeDescription
$GovernedVaultStorage

registerInterface

Registers the IGovernedVault ERC-165 id. Called inside the diamond initializing window.

function registerInterface() internal;

useBallotNonce

Returns the current governor-ballot nonce for voter and increments it (consume-once).

Mirrors NoncesLib.useNonce's return-then-increment semantics, in the vault's own namespace.

function useBallotNonce(address voter) internal returns (uint256 current);

Parameters

NameTypeDescription
voteraddress

Returns

NameTypeDescription
currentuint256

ballotNonce

The next unused governor-ballot nonce for voter.

function ballotNonce(address voter) internal view returns (uint256);

Parameters

NameTypeDescription
voteraddress

Returns

NameTypeDescription
<none>uint256