Euler SDK来啦!(Announcing the Euler SDK)

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

召集所有智能合约开发人员——现在将 Euler 集成到您的工作流中吧!


As Euler grows and matures, attracting lenders and borrowers, we are also looking for ways to encourage the developer community to build cool products and integrations on top of the platform. To reach that goal, we are excited to announce the release of a JavaScript SDK for Euler.

随着 Euler 的成长和成熟,以及吸引了贷款人和出借人,我们也在寻找方法来鼓励开发者社区在平台之上构建很酷的产品和集成。为了实现这一目标,我们很高兴地宣布发布 JavaScript SDK for Euler

With this initial release, the SDK provides:
在此初始版本中,SDK 提供:

  • Easy access to instances of all Euler smart contracts, including mining contracts, the EUL token and peripheries such as FlashLoan.
    轻松访问所有 Euler 智能合约的实例,包括挖矿合约、EUL 代币和 FlashLoan 等外围合约。

  • Built-in configurations for Ethereum mainnet and Ropsten testnet.
    以太坊主网和 Ropsten 测试网的内置配置。

  • Tools for working with Euler’s batch transactions.
    用于处理 Euler 批量事务的工具。

  • Tools for signing and applying the EIP2612 permits.
    用于签署和应用 EIP2612 许可的工具。

For details, please read the docs. Here we’d like to give you just a few quick examples of how to use the SDK to interact with the Euler platform.

有关详细信息,请阅读 文档。在这里,我们想为您提供几个快速示例,说明如何使用 SDK 与 Euler 平台进行交互。

Euler类 (The Euler class)

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

首先,导入 Euler 类并使用标准的 ethers 提供者或签名者对其进行实例化:

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).

您将默认获得一个为主网配置的实例。 contracts 属性提供了主要的 Euler 单例合约。它们只是 ethers合约 类的普通实例。助手(Helpers)也可用于工厂创建的合约(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.

现在让我们尝试一些更有趣的东西。我们将利用 批量交易展期流动性检查,Euler的一些最酷的功能。我们将在单个交易中建立一个杠杆头寸,就像Euler dapp 中的 Short 功能一样。我们将铸造做空的代币 (WETH) 并在 Uniswap V3 上将其换成抵押品或做多的代币 (USDC)。我们需要推迟流动性检查,因为可能铸造的数量太大而无法由现有抵押品维持,并且流动性检查将在“铸造”时失败。只有当铸造的存款被换回抵押品时,健康评分才会恢复。

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.

最后,SDK 处理签署和申请 EIP2612 许可。支持许可的代币列表和构建签名所需的数据由 Euler 的代币列表 提供。

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. We will be working on improving the SDK in the near future, but we also welcome contributions, ideas, and requests from the community. Please feel free to open a pull request or reach out to us on Discord.

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

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

当前版本提供了一组非常基本的功能,显然还有改进的余地。我们将在不久的将来努力改进 SDK,但我们也欢迎社区的贡献、想法和请求。请随时打开提出请求或通过以下方式与我们联系。

Discord: https://discord.gg/rMk7wSSxaG

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

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

关于Euler (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.

Euler 是一种资本效率高的无许可借贷协议,可帮助用户从其加密资产中赚取利息或对冲波动的市场,而无需受信第三方。 Euler 具有许多在 DeFi 中前所未有的创新,包括无许可的借贷市场、回应性利率、受保护的抵押品、抗 MEV 清算、多抵押品稳定池、子账户、风险调整贷款等等。有关更多信息,请访问 euler.finance

加入社区 (Join the Community)

Follow us Twitter. Join our Discord. Keep in touch on Telegram (communityannouncements). Check out our website. Connect with us on LinkedIn.

关注我们 Twitter。加入我们的 Discord。在 Telegram 上保持联系(communityannouncements)。查看我们的网站。在 LinkedIn 上与我们联系。

赞赏