Skip to content

Commit

Permalink
add calling get issue/redeem exact set
Browse files Browse the repository at this point in the history
  • Loading branch information
janndriessen committed Sep 18, 2024
1 parent 47b276f commit db6804b
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions src/quote/flashmint/wrapped/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { BigNumber } from '@ethersproject/bignumber'
import {
ComponentSwapData,
ComponentWrapData,
getFlashMintWrappedContract,
getIssuanceComponentSwapData,
getRedemptionComponentSwapData,
getWrapData,
slippageAdjustedTokenAmount,
} from 'utils'
import { getRpcProvider } from 'utils/rpc-provider'

import { QuoteProvider, QuoteToken } from '../../interfaces'
import { getRpcProvider } from 'utils/rpc-provider'

export interface FlashMintWrappedQuoteRequest {
isMinting: boolean
Expand All @@ -34,8 +36,6 @@ export class WrappedQuoteProvider
async getQuote(
request: FlashMintWrappedQuoteRequest
): Promise<FlashMintWrappedQuote | null> {
const provider = getRpcProvider(this.rpcUrl)
console.log(provider.connection.url)
const { inputToken, indexTokenAmount, isMinting, outputToken, slippage } =
request
console.log(
Expand Down Expand Up @@ -66,37 +66,40 @@ export class WrappedQuoteProvider
},
this.rpcUrl
)
console.log(componentSwapData)
const componentWrapData = getWrapData(indexToken.symbol)
// FIXME: add check
// if (componentSwapData.length !== componentWrapData.length) return null
// let estimatedInputOutputAmount: BigNumber = BigNumber.from(0)
// const contract = getFlashMintWrappedContract(provider)
// if (isMinting) {
// estimatedInputOutputAmount = await contract.callStatic.getIssueExactSet(
// indexToken.address,
// inputToken.address,
// indexTokenAmount,
// componentSwapData
// )
// } else {
// estimatedInputOutputAmount = await contract.callStatic.getRedeemExactSet(
// indexToken.address,
// outputToken.address,
// indexTokenAmount,
// componentSwapData
// )
// }
// const inputOutputTokenAmount = slippageAdjustedTokenAmount(
// estimatedInputOutputAmount,
// isMinting ? inputToken.decimals : outputToken.decimals,
// slippage,
// isMinting
// )
let estimatedInputOutputAmount: BigNumber = BigNumber.from(0)
const provider = getRpcProvider(this.rpcUrl)
const contract = getFlashMintWrappedContract(provider)
if (isMinting) {
estimatedInputOutputAmount = await contract.callStatic.getIssueExactSet(
indexToken.address,
inputToken.address,
indexTokenAmount,
componentSwapData
)
} else {
estimatedInputOutputAmount = await contract.callStatic.getRedeemExactSet(
indexToken.address,
outputToken.address,
indexTokenAmount,
componentSwapData
)
}
// FIXME: add slippage?
const inputOutputTokenAmount = slippageAdjustedTokenAmount(
estimatedInputOutputAmount,
isMinting ? inputToken.decimals : outputToken.decimals,
slippage,
isMinting
)
const quote: FlashMintWrappedQuote = {
componentSwapData,
componentWrapData,
indexTokenAmount,
inputOutputTokenAmount: BigNumber.from(0),
inputOutputTokenAmount,
}
return quote
}
Expand Down

0 comments on commit db6804b

Please sign in to comment.