๐Ÿ”ŒOn-Chain Integration for Flexible Term Vault (V4)

This page provides information on how to access full documentation on the flexible term vault contract, using the Flexible Term USDC Vault deployed on Ethereum as an example

Getting Started

To integrate to a loan vault contract, you can start by viewing the contract source code on Etherscan, which will provide you the contract source code, a list of functions and their descriptions, as well as all of the libraries, interfaces, factories, and controllers.

Flexible Term Vaults implement the OpenZeppelin ERC-1967 Upgradeable Beacon Proxy Pattern.

View the Proxy Contract Source Code

Read as Proxy, including all the read functions

Write as Proxy, including all the write functions

View the Implementation Contract Source Code, including the source code, interfaces, factories, controllers, and libraries

Flexible Term USD Vault Product Documentation

Using Etherscan to View Documentation

Important Functions

As a Lender, there are only a handful of functions you will ever need to call. They are to

  1. Make Investments

  2. Request Withdrawals

  3. Read contract data

These three are covered in more detail below. There are quite a number more in detailed in the full code, libraries, and interfaces on Etherscan but we present the most important below.

Flexible Term Vaults implement the ERC-1967 Beacon Proxy Pattern. The only implementation contract you will interact with as a Lender is the PoolFlex contract.

Terminology

OpenTrade implements many of the ERC-4626 and ERC-20 standards. In some cases, the terminology we use in the product is different from those in the code. They are primarily

Term in Code
Display Name

Pool

Vault

Shares

Vault Tokens

Assets

USDC, EURC

Key Data Fields and their Decimals / Formatting

Field
Decimals
Example in Code
Example in Display

assets

6

1000000

1 USDC/EURC

shares

6

1000000

1 Vault Token

exchangeRate

18

1000261149376738066

1.000261

interestRate

2

500

5.00%

1. Make Investments

The prerequisites for making an investment on mainnet are:

1) to have been onboarded to OpenTrade

2) to have had your supported digital asset wallet whitelisted and

3) to have have enough ETH in the wallet to pay for gas.

To make an investment, you must first call the function to create a spending allowance. This is the amount the the caller is authorising the pool contract to spend.

...where amount is the number of assets you'd like to approve to be deposited and address is the wallet address of the lender. It will return a boolean, true if the request succesful, false if the request failed.

Once the allowance is approved, you will then need to call the function

where assets is the number of assets you'd like to deposit and lender is the wallet address of the lender making the deposit.

To see a demo of this working in action, you can visit our product documentation here.

2. Request Withdrawals

There is only a single function for creating a withdrawal request. After calling this function successfully, the liquidity asset (USDC, EURC) will be send back to your wallet directly from the vault.

To make a withdrawal request, you must call the following function...

...where shares is the number of vault tokens you wish to be redeemed. It will return the withdrawal request amount in assets.

Demo of Making a Withdrawal Request

To view a live example of making a withdrawal request, you can view our product documentation here.

Previewing Requests

Preview Redeem Request

To simulate the result of a withdrawal request at the current block and see how many assets would be withdrawn for a given number of vault tokens (i.e. shares), you can call the following function...

It will returns the amount of assets that would be requested if this entire redeem request were to be processed at the current block. Note: This is equivalent of EIP-4626 previewRedeem.

Preview Withdrawal Request

To simulate the result of a withdrawal request at the current block and see how many vault tokens (i.e. shares) would be burned if this entire withdrawal request were to be processed at the current block, you can call the following function...

It will returns the amount of shares that would be burned if this entire withdrawRequest were to be processed at the current block. Note: This is equivalent of EIP-4626 previewWithdraw.

Convert to Assets

To see the get the value of a certain number of vault tokens as converted to liquidity assets (USDC, EURC), you can call the following function for a specified number of assets and it will return the number of shares.

Convert to Shares

To see the value of a certain number of assets (USDC, EURC) converted to vault tokens (i.e. shares), you can call the following function for a specified number of assets and it will return the number of shares.

3. Reading Contract Data

As a Lender, all of the important information regarding the vault can be called back from the contract.

When you call any read function from typescript using popular Ethereum libraries like ethers.js or web3.js, it will return a full list of fields available from the contract ABI.

Get Pool Overview State

To get the current state of the pool, you can call the function

and it will return the Pool Overview data in the following structure

Get Pool Configuration

To get the current parameters and configuration of the pool, you can call...

and it will return the following data

Get Account Overview

To get data on a specific wallet address ("account"), you can call the following function...

and it will return the following data

Typescript Reference Implementation

Below are typescript examples for making deposits and withdrawals from the vault using ethers.js

Last updated