OlympusGovDelegation.sol
OlympusGovDelegation implements DLGTE, handling the actual mechanics of delegation. It creates and manages escrow contracts for delegates through the DelegateEscrowFactory, and tracks how much gOHM each policy has deposited for each user.
Core State
struct AccountState {
EnumerableSet.AddressSet delegateAddresses; // Set of current delegates
uint112 totalGOhm; // Total gOHM across all policies
uint112 delegatedGOhm; // Amount currently delegated
uint32 maxDelegateAddresses; // Max delegates allowed (default 10)
}
// Track gOHM deposited per policy per account
mapping(address policy => mapping(address account => uint256 amount)) _policyAccountBalances;
// Track each account's delegate info
mapping(address account => AccountState) _accountState;
Functions
Deposits and Withdrawals
depositUndelegatedGohm()
Pulls gOHM from policy and tracks for user
Updates total in AccountState and policy balance
gOHM stays in module until delegated
withdrawUndelegatedGohm()
Returns gOHM to policy if enough undelegated balance
Checks both policy's deposited amount and user's undelegated amount
Updates both AccountState and policy balance
Delegation Management
applyDelegations()
Processes array of delegation requests
For each request:
If amount positive: creates/updates escrow and delegates
If amount negative: pulls from escrow and undelegates
Requires amount <= undelegated balance for delegations
Tracks delegate addresses in AccountState
Enforces max delegate limit
setMaxDelegateAddresses()
Updates max delegate limit for an account
If set to 0, defaults to DEFAULT_MAX_DELEGATE_ADDRESSES
Internal Functions
_applyDelegation()
Handles single delegation request
Creates escrow through factory if needed
Moves gOHM to/from escrow
Updates delegate address tracking
_applyDelegations()
Batch processes multiple requests
Tracks running totals of amounts delegated/undelegated
_getOrCreateDelegateEscrow()
Gets existing escrow or creates new through factory
Updates delegate address set
Checks against max delegate limit
Last updated