2.4.0 • Published 22 days ago

@indexcoop/flash-mint-sdk v2.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
22 days ago

Flash Mint SDK v2

The Flash Mint SDK provides easy to use functions to integrate flashminting for Index's products.

The Contracts

To find out more about the contracts, go to Index's smart contracts repo.

This SDK currently supports the contracts listed here. Check out the utility functions for easily obtaining the correct addresses and contracts.

Install

$ npm install @indexcoop/flash-mint-sdk

Limitations

A limitation to be aware of (especially for getting quotes) is that the contracts can only mint or redeem an exact amount of Index token.

Additionally, make sure that the (Index/Set) tokens have been approved on the specific FlashMint contracts.

Usage

Quotes

In v2 we made it way easier to fetch a quote. Meet the FlashMintQuoteProvider. This provider will now return the appropriate quotes for any Index token, automatically selecting the correct FlashMint contract for you.

import { FlashMintQuoteProvider } from '@indexcoop/flash-mint-sdk'

// Input/output token should be of type QuoteToken with the following properties
const inputToken = {
  symbol: 'ETH',
  decimals: 18,
  address: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
}
const outputToken = {
  symbol: 'icETH',
  decimals: 18,
  address: '0x7C07F7aBe10CE8e33DC6C5aD68FE033085256A84',
}

const rpcProvider = new JsonRpcProvider('')
const quoteProvider = new FlashMintQuoteProvider(rpcProvider)
const quote = await quoteProvider.getQuote({
  isMinting: true,
  inputToken,
  outputToken,
  indexTokenAmount: wei(1),
  slippage: 0.1,
})

The returned quote is an object with meta data but most importantly the inputOutputAmount which is the quote for the given request and a tx object which is a tx object basically ready to be send.

interface FlashMintQuote {
  chainId: number
  contractType: FlashMintContractType
  contract: string
  isMinting: boolean
  inputToken: QuoteToken
  outputToken: QuoteToken
  indexTokenAmount: BigNumber
  inputOutputAmount: BigNumber
  slippage: number
  tx: TransactionRequest
}

You can still fetch quotes for individual FlashMint contracts e.g. using the ZeroExQuoteProvider.

import { QuoteToken, ZeroExQuoteProvider } from '@indexcoop/flash-mint-sdk'

// Input/output token should be of type QuoteToken with the following properties
const inputToken: QuoteToken = {
  symbol: 'ETH',
  decimals: 18,
  address: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
}
const outputToken: QuoteToken = {
  symbol: 'dsETH',
  decimals: 18,
  address: '0x341c05c0E9b33C0E38d64de76516b2Ce970bB3BE',
}
const rpcProvider = new JsonRpcProvider('')
const quoteProvider = new ZeroExQuoteProvider(rpcProvider, zeroExApiV1)
const quote = await quoteProvider.getQuote({
  isMinting: true,
  inputToken,
  outputToken,
  indexTokenAmount,
  slippage: 0.1,
})

The quote providers for the individual FlashMint contracts will return not just the inputOutputAmount but also the swap data/component quotes.

interface FlashMintZeroExQuote {
  componentQuotes: string[]
  indexTokenAmount: BigNumber
  inputOutputTokenAmount: BigNumber
}

Flashmint

To execute the flashminting of an Index for convenience use the tx object returned by the FlashMintQuoteProvider.

...
const quoteProvider = new FlashMintQuoteProvider(rpcProvider)
const quote = await quoteProvider.getQuote({...})
let tx = quote.tx
const gasEstimate = await provider.estimateGas(tx)
tx.gasLimit = gasEstimate
const res = await signer.sendTransaction(tx)
console.log(res.hash)

Alternatively, you can use the swap data returned by the individual providers to construct the tx yourself which then has to be executed on the correct FlashMint contract for that specific Index token. Use the utility functions for easily obtaining the correct addresses and contracts.

Develoment

.env vars

When adding new .env vars do not forget to update the publish.yml

Adding a new Index token

  1. add a test for determining the correct issuance module here
  2. add a test for determining the correct contract here
  3. if there is a new FlashMint contract, add it as described below
  4. additionally, add a test in tests
  5. add symbol to function getContractType(token: string) in FlashMintQuoteProvider

Adding a new contract

  1. add the contract address in constants
  2. add appropriate getters and tests in utils/contracts
  3. add a new builder and quote provider
  4. The new quote provider has to be integrated into the FlashMintQuoteProvider

Contributing

We will encourage contributing and open dialog how to improve the SDK. How though is still TBD. 🚧 In the meantime just open an issue.

License

Copyright © 2023 Index Coop.

MIT License

2.4.0

22 days ago

2.3.1

2 months ago

2.3.0

7 months ago

2.2.1

9 months ago

2.2.0

9 months ago

2.1.1

10 months ago

2.2.2

7 months ago

2.1.0

10 months ago

2.0.0

11 months ago

1.10.0

1 year ago

1.9.0

1 year ago

1.8.0

1 year ago

1.7.0

1 year ago

1.5.3

1 year ago

1.5.2

1 year ago

1.6.0

1 year ago

1.5.1

1 year ago

1.2.0

1 year ago

1.1.1

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.2.1

1 year ago

1.1.0

2 years ago

1.0.0

2 years ago