GM Vaults
Last updated
Last updated
Each asset configured in the GM Lending/Looping Pool contract is associated with an ERC-4626 Vault. The GM Vault contracts inherit from OpenZeppelin's Pausable and Ownable2Step standards. The Tokenized Vault standard assigns shares to depositors, which represent a claim to ownership on a fraction of the Vault's underlying assets. Shares can be converted to deposited asset tokens at any time. The following list of functions only include those that differ from the :
At deployment, the constructor takes in token variables and passes them to the ERC-4626 and ERC20 constructors. It makes msg.sender
the owner of the contract (hereafter referred to as Admin). It stores the _token
and _lendingPool
addresses in state variables. Lastly, the contract approves the Lending Pool contract to be able to spend the maximum allowed tokens (type(uint256).max
) on its behalf.
_token
ERC20
The asset associated with the vault
_name
string memory
The name of the asset
_symbol
string memory
The ticker symbol of the asset
_lendingPool
address
The address of the Lending Pool contract
Pauses functions with the whenNotPaused
modifier. Only the Vault Admin can call.
Unpauses functions with the whenNotPaused
modifier. Only the Vault Admin can call. After unpausing, all vault interactions will be restored except for liquidations. To help prevent liquidation bots front-running users who want to heal their positions, a short window can be added. During this time, lendingPool.liquidateUser()
will remain disabled.
liquidationsResumeTimestamp = block.timestamp + _liquidationDelay
Transfers tokens from the existing Vault contract to a new Vault contract. This function can only be called by the Admin while the contract is paused. If amount
is greater than the Vault balance, then the call with revert. The amount
argument allows for a migration "test" transfer before transferring the entire balance.
newVault
address
The address of the new Vault contract that all tokens will be transferred to
amount
uint256
The amount of tokens to migrate to the new Vault
Reads the existing vault's balance and mints an equal number of shares and assigns to the Lending Pool, effectively finishing the migration from the old vault to the new vault.
oldVault
address
The address of the old Vault contract that shares will be reflected from
In case of airdrops or tokens accidentally sent directly to the vault, the Admin can withdraw tokens to distribute later. If the asset argument is the vaultAsset
, the call will revert. If the asset is not the active vault asset, then the tokens are withdrawn to the to
address.
asset
ERC20
The unsupported asset
amount
uint256
The amount of asset tokens to withdraw
to
address
The address to send the unsupported tokens to.
Wraps the input address with the IGMIncentives
interface and stores the instance in the gmIncentives
state variable. Callable only by the Admin.
_gmIncentivesContract
address
The address of the GM Incentives contract
If a GM Incentives contract is stored in the Vault contract, this relays user
, existingBalance
, amount
, and isDeposit
to the Incentives contract via gmIncentives.relayVaultAction()
. This function can only be called by the Lending Pool via the deposit and withdraw functions and only during USDC transfers.
For now, only supplying USDC earns incentives, so borrowing USDC directly calls withdraw()
and repaying USDC directly calls deposit()
. This function is needed to pass the original pool depositor's address and a boolean to the Incentives contract, since direct ERC4626 deposit/withdraw calls must keep the exact function signature in the implementation.
user
address
The address of the user who initiated the Pool/Vault action
existingBalance
address
The user's existing pool balance.
amount
uint256
The amount of tokens involved in the pool transfer
isDeposit
boolean
If true, the action is a deposit. If false, it is a withdrawal.
The above functions are all overridden so that only the lendingPool
address can call these functions. This is to ensure that the depositing and withdrawing of assets only happens via the Lending Pool contract, so that internal variables (balances, debt, and exchange rates) are properly tracked and collateral is properly enabled.