Gloop
WebsiteTwitterDiscord
  • gLoop Litepaper v2
    • Introduction
    • The Two Tokens
    • Roadmap
  • PRODUCTS
    • GM Index
      • Providing/Removing Liquidity
      • Fees and Reflection
      • Deposit/Withdrawal Examples
    • GM Lend/Borrow
      • Lending USDC
      • Depositing Collateral Assets
      • Withdrawing Assets
      • Borrowing USDC
      • Repaying Debt
      • gLooping GM Assets
      • Position Management
        • Withdrawing Assets
        • Health Factor and Liquidations
      • Lending/Borrowing GMI (Coming Soon)
      • Frequently Asked Questions (FAQs)
    • GLOOP Staking (Coming Soon)
  • GM Points (COMING SOON)
  • Technical
    • Gloop Protocol Parameters
    • Gloop Parameters
    • Contracts
      • GM Lending and Looping
        • GM Lending Pool
        • GM Price Oracle
        • GM Vaults
        • GM Interest Rate Model
        • GM Incentives
      • GMI
        • GM Index
        • GMI USDC Zap
        • Token Banks
        • Token Oracles
        • Fees
  • FREQUENTLY ASKED QUESTIONS (FAQs)
    • GM Index (GMI)
    • GM Lending/Looping
    • GLOOP Staking (Coming Soon)
  • GLoop Ecosystem
    • Tokenomics
  • Security and Risk
    • Risks
    • Audits
  • Social
    • Socials
Powered by GitBook
On this page
  • constructor
  • pause
  • unpause
  • migrate
  • reflectPoolShares
  • recoverUnsupported
  • USDC Vault Only Functions
  • setIncentives
  • handleTransfer
  • Other Functions
  1. Technical
  2. Contracts
  3. GM Lending and Looping

GM Vaults

PreviousGM Price OracleNextGM Interest Rate Model

Last updated 24 days ago

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 :

constructor

constructor(
        ERC20 _token,
        string memory _name,
        string memory _symbol,
        address _lendingPool
    ) ERC4626(_token) ERC20(_name, _symbol) Ownable(msg.sender)

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.

Parameters:

Name
Type
Description

_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

pause

function pause() external onlyOwner

Pauses functions with the whenNotPaused modifier. Only the Vault Admin can call.

unpause

function unpause(uint256 _liquidationDely) external onlyOwner

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

migrate

function migrate(address newVault, uint256 amount) external whenPaused onlyOwner

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.

Parameters:

Name
Type
Description

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

reflectPoolShares

function reflectPoolShares(address oldVault) external onlyOwner

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.

Parameters:

Name
Type
Description

oldVault

address

The address of the old Vault contract that shares will be reflected from

recoverUnsupported

function recoverUnsupported(ERC20 asset, uint256 amount, address to) external onlyOwner

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.

Parameters:

Name
Type
Description

asset

ERC20

The unsupported asset

amount

uint256

The amount of asset tokens to withdraw

to

address

The address to send the unsupported tokens to.

USDC Vault Only Functions

setIncentives

function setIncentives(address _gmIncentivesContract) external onlyOwner

Wraps the input address with the IGMIncentives interface and stores the instance in the gmIncentives state variable. Callable only by the Admin.

Parameters:

Name
Type
Description

_gmIncentivesContract

address

The address of the GM Incentives contract

handleTransfer

function handleTransfer(address user, uint256 existingBalance, uint256 amount, bool isDeposit) external whenNotPaused onlyPool

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.

Parameters:

Name
Type
Description

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.

Other Functions

function deposit(uint256 assets, address receiver) public override whenNotPaused onlyPool returns (uint256);
function mint(uint256 shares, address receiver) public override whenNotPaused onlyPool returns (uint256);
function withdraw(uint256 assets, address receiver, address owner) public override whenNotPaused onlyPool returns (uint256);
function redeem(uint256 sares, address receiver, address owner) public override whenNotPaused onlyPool returns (uint256);

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.

base ERC-4626 specification