Contract Integration Guide
Find out how to start working with the Euler smart contracts
Modules
The Euler protocol is a collection of smart contracts connected together with a module system. Each module handles specific areas of the protocol, so depending on what you want to do, you will interact with several different contract addresses.
Some modules are global, for example:
markets: Activating markets, enter/exiting markets, and querying various market-related information.
exec: Batch requests, liquidity deferrals (ie, flash loans)
liquidation: Seizure of assets for users in violation
Other modules are asset-specific:
eTokens: ERC20-compatible tokens that represent assets
dTokens: ERC20-compatible tokens that represent liabilities
Deposit and withdraw
In order to invest an asset to earn interest, you need to deposit
into an eToken.
Borrow and repay
If you would like to borrow an asset, you must have sufficient collateral, and be "entered" into the collateral's market.
Flash loans
Euler has flash loans built-in as an integral component of the protocol. There are three ways to take a flash loan, a low-level Euler-specific way, a way that uses an EIP-3156 compatible flash-loan adaptor, and a gas-efficient direct interface.
Low-level Flash Loans
The low-level way to take a flash loan is to defer the liquidity check for your account. The Euler contract will call back into your contract, where you can perform operations like borrow()
without worrying about liquidity violations. As long as your callback leaves the account in a non-violating state, the transaction will complete successfully.
Since Euler only charges interest for a loan when it is held for a non-zero amount of time, this results in fee-less flash loans.
Here is an example contract that demonstrates this:
encodedData
is a pass-through parameter that lets you transfer data to your callback without requiring storage writes.
EIP-3156 Flash Loans
There is also an adaptor smart contract that exposes Euler's flash loan functionality as an EIP-3156 compatible API.
The smart contract addresses are: mainnet, goerli.
Examples of how to use the adaptor can be found in the EIP documentation, as well as the Euler test suite. The fee value is always 0.
Gas-Efficient Direct Flash Loans
As of eIP-14, DTokens also support a flashLoan
method. In most cases, this is now the recommended way to perform a pure flash loan. It is simpler and consumes less gas than either of the above methods.
To use this, your contract should implement the IFlashLoan
interface:
When you wish to perform a flash loan, your contract should invoke the flashLoan
function on the DToken that corresponds to the asset you wish to borrow:
The DToken contract will transfer the requested amount
of tokens to your contract address (decimals are the same as in the external token contract -- no normalisation needed), and then invoke your contract's onFlashLoan
function. The data
parameter you specify is passed to the callback unchanged, which allows you to pass extra data to your contract without requiring expensive storage writes.
Note that any address could call onFlashLoan
on your contract at any time. You may want to ensure that msg.sender
is the Euler contract's address, or use some other kind of authentication scheme.
Your contract is expected to repay amount
back to the Euler contract (which will be msg.sender
) within the onFlashLoan
function.
Here is an example:
Last updated