npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@indexcoop/flash-mint-sdk

v3.11.0

Published

The FlashMintSDK of the Index Coop.

Downloads

704

Readme

Flash Mint SDK v3

The Flash Mint SDK provides easy to use functions to integrate flash minting 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 on Mainnet, Arbitrum and Base.

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

With v3, while you could still use other quote providers individually, we recommend solely using the FlashMintQuoteProvider which will do most of the guess work for you. This provider will return the appropriate quotes for any Index token, automatically selecting the correct FlashMint contract for you - as well as preparing the call data.

import { FlashMintQuoteProvider, QuoteToken } 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: 'icETH',
  decimals: 18,
  address: '0x7C07F7aBe10CE8e33DC6C5aD68FE033085256A84',
}

// Add a RPC URL e.g. from Alchemy
const rpcUrl = ''
// Use the 0x swap quote provider configured to your needs e.g. custom base url -
// or provide your own adapter implementing the `SwapQuoteProvider` interface
const zeroexSwapQuoteProvider = new ZeroExSwapQuoteProvider()
const quoteProvider = new FlashMintQuoteProvider(
  rpcUrl,
  zeroexSwapQuoteProvider
)
const quote = await quoteProvider.getQuote({
  isMinting: true,
  inputToken,
  outputToken,
  indexTokenAmount: wei(1),
  slippage: 0.1,
})

The returned quote is an object including 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
  inputAmount: BigNumber
  outputAmount: BigNumber
  indexTokenAmount: BigNumber
  inputOutputAmount: BigNumber
  slippage: number
  tx: TransactionRequest
}

* for minting this will be the input amount, for redeeming the output amount

Flashmint

To execute the flash minting of an Index token for convenience use the tx object returned by the FlashMintQuoteProvider.

...
const quoteProvider = new FlashMintQuoteProvider(
      rpcUrl,
      zeroexSwapQuoteProvider
    )
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. add symbol to function getContractType(token: string) in src/quote/provider/utils.ts and add a test
  5. additionally, add a test in tests

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 © 2024 Index Coop.

MIT License