Index Cooperative Launch App
Index Coop News

Introducing the Flash Mint SDK

Flash Mint is an innovative integration that enables dApps and DEXs to pass along significant cost savings and provide deep liquidity for large cryptocurrency trades.

8/8/2022

Index Coop

Index Coop

Flash Mint is an innovative integration that enables dApps and DEXs to pass along significant cost savings and provide deep liquidity for large cryptocurrency trades.

The Index Coop is pleased to introduce the Flash Mint SDK, which provides support for dApps and exchanges looking to easily integrate mint and redeem capabilities for crypto structured products, such as DeFi Pulse Index (DPI) and Interest Compounding Ethereum (icETH). Integrating Flash Mint provides many benefits not only for developers but also for crypto users. The ability to Flash Mint tokens reduces slippage and unlocks cost savings on large trades. The Flash Mint SDK is written in TypeScript, and is available now on GitHub.

Disclaimer: the Flash Mint SDK should be treated as **beta** for now. ⚠️

TL;DR

“I’m a DeFi app and/or DEX aggregator. What’s in it for me?”

The Flash Mint SDK:

1. Provides the code and documentation so the ability to Flash Mint can be simply integrated into your dApp or DEX

2. Sources better trade execution for your users (especially for large trades)

What is Flash Mint?

A simple decentralized exchange (DEX) trade is usually cost-effective for smaller trades where you are likely to encounter low slippage. However, at some threshold on larger trades, you are likely to encounter significant slippage (> 1%). That’s where Flash Mint can offer cost savings.

Compared to typical DEX trades, Flash Mint can facilitate more cost-effective large trades by minting new units from the underlying product components. This is especially helpful where the cost of slippage would exceed the cost of gas for buying each token and minting a new product unit.

Flash Mint allows you to indirectly buy components of an index and then mint a new unit. As an example, here’s how that works for DPI:

  • You send your currency of choice (ETH, USDC, or DAI, for example) to the contract

  • Your currency is then exchanged into the correct amount of underlying DPI assets necessary to mint new units

  • New DPI units are minted and sent back to your wallet

The Contracts

To find out more about the code of Flash Mint contracts, go to Index Coop’s smart contract repository on GitHub.

The SDK includes:

Check out the utility functions for easily obtaining the correct addresses and contracts when integrating into your project.

Limitations

There are a few limitations to be aware of when first getting started.

  • A Flash Mint contract can only mint or redeem an exact amount of Set token. The SDK currently does not support finding these amounts e.g., compared to other quotes. You're welcome to contact us and we can walk you through how we do it in our frontend.

  • (Set) tokens must be approved on the contracts before they can be used with any of the contract's functions. Use `approveSetToken`, `approveToken` or `approveTokens`. This functionality is currently not available through the SDK but can be easily executed via a block explorer like Etherscan.

Quick Install

The library is hosted on npm. Installing is as easy as:

$ npm i @indexcoop/flash-mint-sdkor$ yarn add @indexcoop/flash-mint-sdk

Using Flash Mint SDK

Flash Mint SDK currently supports two use cases - fetching quotes and issuing/redeeming a Set token. This is available for both the FlashMintLeveraged and FlashMintZeroEx.

Quotes

To fetch a quote for `FlashMintLeveraged` use the following code.

import {  getFlashMintLeveragedQuote,  ZeroExApi,} from '@indexcoop/flash-mint-sdk'// Input/output token should be of type QuoteToken with the following propertiesconst inputToken = {      symbol: "ETH",      decimals: 18,      address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",    }const outputToken = { ... }// Slippage should be defined in % e.g. 0.1 or 3%const slippage = 0.5// For quotes the provider can be read-onlyconst provider: JsonRpcProvider = ...// Define no base url to use the free default (watch rate limits!)const zeroExApi = new ZeroExApi()const quote = await getFlashMintLeveragedQuote(  inputToken,  outputToken,  setTokenAmount,   // How much of the Set token should be minted/redeemed  isMinting,        // Set here whether the Set token should be minted/redeemed  slippage,  zeroExApi,  provider,  chainId ?? 1)

Fetching quotes for the `FlashMintZeroEx` works similar to the example above.

const quote = await getFlashMintZeroExQuote(  inputToken,  outputToken,  setTokenAmount,  isMinting,  slippage,  zeroExApi,  provider,  chainId)

The quote functions will return objects of the following types (or null on error). Depending on minting/redeeming the `inputOutputTokenAmount` will be the quote for the input or output token amount that is needed to mint/redeem the exact set amount `setTokenAmount`. The other properties are data that will be used as input for the trade functions (when minting/redeeming).

export interface FlashMintLeveragedQuote {  swapDataDebtCollateral: SwapData  swapDataPaymentToken: SwapData  inputOutputTokenAmount: BigNumber  setTokenAmount: BigNumber}export interface FlashMintZeroExQuote {  componentQuotes: string[]  inputOutputTokenAmount: BigNumber  setTokenAmount: BigNumber}

Mint/Redeem Tokens

Multiple functions for minting and redeeming Set tokens are included in the Flash Mint SDK. The functions will execute and return an object of type `TransactionResponse` (ethers.js). Only one mint and redeem function are shown here as examples. Check out the repository on GitHub to see how to call all functions. The functions always differentiate between the native chain token (e.g., ETH or MATIC) and other tokens.

FlashMintLeveraged

import {  FlashMintLeveraged,  getFlashMintLeveragedContract,  SwapData,} from '@indexcoop/flash-mint-sdk'// For these functions you'll need a provider with a signerconst contract = getFlashMintLeveragedContract(provider?.getSigner(), chainId)// Pass the contract to the flash mint classconst flashMint = new FlashMintLeveraged(contract)// To redeem a Set token for ETHconst redeemTx = await flashMint.redeemExactSetForETH(  setTokenAddress,  setTokenAmount,  inputOutputLimit,  debtCollateralSwapData,  inputOutputSwapData,  { gasLimit: ... })

FlashMintZeroEx

import {  FlashMintZeroEx,  getFlashMintZeroExContract,  getIssuanceModule,} from '@indexcoop/flash-mint-sdk'// For these functions you'll need a provider with a signerconst contract = getFlashMintZeroExContract(provider.getSigner(), chainId)// Pass the contract to the flash mint classconst flashMint = new FlashMintZeroEx(contract)// Determine the correct issuance module (helper function)const issuanceModule = getIssuanceModule(setTokenSymbol, chainId)// To mint a Set token from ETHconst mintTx = await flashMint.mintExactSetFromETH(  setTokenAddress,  setTokenAmount,  quote.componentQuotes,  // the component quotes that were fetched via the quote function earlier  issuanceModule.address,  issuanceModule.isDebtIssuance,  quoteData.inputTokenAmount,  { gasLimit: ... })

Integrate Flash Mint Today

We’ve introduced this SDK to help development teams more easily integrate Flash Mint into their apps and enable more cost-efficient trades. We look forward to your feedback and hearing how you integrate Flash Mint to benefit your protocol and users.

To discuss partnership opportunities, email Funkmaster Flex: institutions@indexcoop.com. For any technical questions, feel free to reach out to JD, jann@indexcoop.com, or our engineering team via our channel #product-nest on Discord.

The SDK is licensed under MIT. Copyright © 2022 Index Coop.

Find out more under: https://github.com/IndexCoop/flash-mint-sdk

https://www.npmjs.com/package/@indexcoop/flash-mint-sdk

Dive deeper

Watch, read, and learn everything you need to master our leverage tokens.

Subscribe to our newsletter

Join over 6,000 subscribers in receiving weekly updates about our products, DeFi, and the onchain structured products space.

FAQs