Announcing the Euler SDK

Calling all smart contract developers — integrate Euler into your workflows now!

As Euler grows and matures, attracting lenders and borrowers, the Euler community is also looking for ways to encourage developers to build cool products and integrations on top of the platform. To reach that goal, a JavaScript SDK for Euler has been released.

With this initial release, the SDK provides:

  • Easy access to instances of all Euler smart contracts, including mining contracts, the EUL token and peripheries such as FlashLoan.
  • Built-in configurations for Ethereum mainnet and Ropsten testnet.
  • Tools for working with Euler’s batch transactions.
  • Tools for signing and applying the EIP2612 permits.

For details, please read the docs. Here are just a few quick examples of how to use the SDK to interact with the Euler platform.

The Euler class

To begin with, import the Euler class and instantiate it with a standard ethers provider or signer:

import { Euler } from "@eulerxyz/euler-sdk"

const provider = new ethers
.providers
.JsonRpcProvider("<JSON_RPC_URL>")

const signer = new ethers.Wallet("<PRV_KEY>", provider)

const e = new Euler(signer)

Contracts

By default, you will get an instance configured for the mainnet. The main Euler singleton contracts are provided on the contracts property. They are simply vanilla instances of the ethers Contract class. Helpers are also available for factory-created contracts (eTokens, dTokens, pTokens).

const eUsdcAddress = await e
.contracts
.markets
.underlyingToEToken(USDC_ADDRESS)

await e.eToken(eUsdcAddress).deposit(0, 1M_USDC)

Batch transactions

Now let’s try something more interesting. We’ll take advantage of batch transactions and deferred liquidity check, some of Euler’s coolest features. We’re going to build a leveraged position in a single transaction, in the same way the Short feature works in the Euler dapp. We’re going to mint the shorted token (WETH) and swap it on Uniswap V3 for collateral or long token (USDC). We need to defer the liquidity check because presumably the minted amount is too large to be sustained by existing collateral, and the liquidity check would fail on mint. Only when the minted deposit is swapped back to collateral is the health score restored.

const batchItems = [
{
contract: "markets",
method: "enterMarket",
args: USDC_ADDRESS,
},
{
contract: "eToken",
address: EWETH_ADDRESS,
method: "mint",
args: [0, 1M_USDC]
},
{
contract: "swap",
method: "swapUniExactInputSingle",
args: [{
subAccountIdIn: 0,
subAccountIdOut: 0,
underlyingIn: WETH_ADDRESS,
underlyingOut: USDC_ADDRESS,
amountIn: 1M_USDC,
amountOutMinimum: mySlippageTolerance,
deadline: 0,
fee: 300, // use 0.3% USDC/WETH pool
sqrtPriceLimitX96: 0
}]
}
]

const encodedBatch = e.buildBatch(batchItems)

const deferredLiquidityCheckAccount = await e
.getSigner()
.getAddress()

await e
.contracts
.exec
.batchDispatch(encodedBatch, [deferredLiquidityCheckAccount])

Permits

Finally, the SDK handles signing and applying EIP2612 permits. The list of tokens supporting permits and the data needed to construct the signatures is provided by Euler’s token list.

const agEur = eulerTokenList.find(t => t.symbol === 'agEUR')
const eagEurAddr = e
.contracts
.markets
.underlyingToEtoken(agEur.address)

const batchItems = [
await e.signPermitBatchItem(agEur),
{
contract: e.eToken(eagEurAddr),
method: "deposit",
args: [0, 1M_AGEUR]
}
]

What’s next

The current release provides a very basic set of features, and there’s obviously room for improvement. Work will be done on improving the SDK in the near future, but contributions, ideas, and requests from the community are also encouraged. Please feel free to open a pull request or reach out on Discord.

GitHub: https://github.com/euler-xyz/euler-sdk

NPM: https://www.npmjs.com/package/@eulerxyz/euler-sdk

About Euler

Euler is a capital-efficient permissionless lending protocol that helps users to earn interest on their crypto assets or hedge against volatile markets without the need for a trusted third-party. Euler features a number of innovations not seen before in DeFi, including permissionless lending markets, reactive interest rates, protected collateral, MEV-resistant liquidations, multi-collateral stability pools, sub-accounts, risk-adjusted loans, and much more. For more information, visit euler.finance.

Join the Community

Follow us on Twitter. Join our Discord. Keep in touch on Telegram (community, announcements). Check out our website.

This piece is provided by Euler Labs Ltd. for informational purposes only and should not be interpreted as investment, tax, legal, insurance, or business advice. Euler Labs Ltd. and The Euler Foundation are independent entities.

Neither Euler Labs Ltd., The Euler Foundation, nor any of their owners, members, directors, officers, employees, agents, independent contractors, or affiliates are registered as an investment advisor, broker-dealer, futures commission merchant, or commodity trading advisor or are members of any self-regulatory organization.

The information provided herein is not intended to be, and should not be construed in any manner whatsoever, as personalized advice or advice tailored to the needs of any specific person. Nothing on the Website should be construed as an offer to sell, a solicitation of an offer to buy, or a recommendation for any asset or transaction.

This post reflects the current opinions of the authors and is not made on behalf of Euler Labs, The Euler Foundation, or their affiliates and does not necessarily reflect the opinions of Euler Labs, The Euler Foundation, their affiliates, or individuals associated with Euler Labs or The Euler Foundation.

Euler Labs Ltd. and The Euler Foundation do not represent or speak for or on behalf of the users of Euler Finance. The commentary and opinions provided by Euler Labs Ltd. or The Euler Foundation are for general informational purposes only, are provided "AS IS," and without any warranty of any kind. To the best of our knowledge and belief, all information contained herein is accurate and reliable and has been obtained from public sources believed to be accurate and reliable at the time of publication.

The information provided is presented only as of the date published or indicated and may be superseded by subsequent events or for other reasons. As events and markets change continuously, previously published information and data may not be current and should not be relied upon.

The opinions reflected herein are subject to change without being updated.

2024 Euler © All Rights Reserved