Skip to content

Commit

Permalink
feat: update quote request amounts to strings (#95)
Browse files Browse the repository at this point in the history
* feat: update quote request amounts to strings

* fix provider utils test
  • Loading branch information
janndriessen authored Nov 29, 2024
1 parent ab42751 commit 0205215
Show file tree
Hide file tree
Showing 22 changed files with 103 additions and 93 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const quote = await quoteProvider.getQuote({
isMinting: true,
inputToken,
outputToken,
indexTokenAmount: wei(1),
indexTokenAmount: wei(1).toString(),
slippage: 0.1,
})
```
Expand Down
9 changes: 5 additions & 4 deletions src/quote/provider/icusd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export interface IcUsdQuoteRequest extends FlashMintQuoteRequest {
isMinting: boolean
inputToken: QuoteToken
outputToken: QuoteToken
indexTokenAmount: BigNumber
indexTokenAmount: string
// FlashMintNav always needs the input amount
inputTokenAmount: BigNumber
inputTokenAmount: string
slippage: number
}

Expand Down Expand Up @@ -98,8 +98,8 @@ export class IcUsdQuoteRouter
// }

private async getFlashMintWrappedQuote(request: IcUsdQuoteRequest) {
const { chainId, indexTokenAmount, inputToken, isMinting, outputToken } =
request
const { chainId, inputToken, isMinting, outputToken } = request
const indexTokenAmount = BigNumber.from(request.indexTokenAmount)
const indexToken = isMinting ? outputToken : inputToken
const inputOutputToken = isMinting ? inputToken : outputToken
const wrappedQuoteProvider = new WrappedQuoteProvider(
Expand All @@ -109,6 +109,7 @@ export class IcUsdQuoteRouter
const wrappedQuote = await wrappedQuoteProvider.getQuote({
...request,
chainId,
indexTokenAmount,
})
if (!wrappedQuote) return null
const builder = new WrappedTransactionBuilder(this.rpcUrl)
Expand Down
31 changes: 18 additions & 13 deletions src/quote/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export interface FlashMintQuoteRequest {
isMinting: boolean
inputToken: QuoteToken
outputToken: QuoteToken
indexTokenAmount: BigNumber
inputTokenAmount?: BigNumber
indexTokenAmount: string
inputTokenAmount?: string
slippage: number
}

Expand Down Expand Up @@ -73,14 +73,9 @@ export class FlashMintQuoteProvider
): Promise<FlashMintQuote | null> {
const { rpcUrl, swapQuoteProvider } = this
const provider = getRpcProvider(rpcUrl)
const {
indexTokenAmount,
inputTokenAmount,
inputToken,
isMinting,
outputToken,
slippage,
} = request
const { inputToken, inputTokenAmount, isMinting, outputToken, slippage } =
request
const indexTokenAmount = BigNumber.from(request.indexTokenAmount)
const indexToken = isMinting ? outputToken : inputToken
const inputOutputToken = isMinting ? inputToken : outputToken
const network = await provider.getNetwork()
Expand Down Expand Up @@ -151,7 +146,10 @@ export class FlashMintQuoteProvider
rpcUrl,
swapQuoteProvider
)
const leveragedQuote = await leveragedQuoteProvider.getQuote(request)
const leveragedQuote = await leveragedQuoteProvider.getQuote({
...request,
indexTokenAmount,
})
if (!leveragedQuote) return null
const builder = new LeveragedTransactionBuilder(rpcUrl)
const txRequest: FlashMintLeveragedBuildRequest = {
Expand Down Expand Up @@ -179,7 +177,10 @@ export class FlashMintQuoteProvider
const leverageExtendedQuoteProvider =
new LeveragedExtendedQuoteProvider(rpcUrl, swapQuoteProvider)
const leveragedExtendedQuote =
await leverageExtendedQuoteProvider.getQuote(request)
await leverageExtendedQuoteProvider.getQuote({
...request,
indexTokenAmount,
})
if (!leveragedExtendedQuote) return null
const builder = new LeveragedExtendedTransactionBuilder(rpcUrl)
const txRequest: FlashMintLeveragedExtendedBuildRequest = {
Expand Down Expand Up @@ -216,6 +217,7 @@ export class FlashMintQuoteProvider
const wrappedQuote = await wrappedQuoteProvider.getQuote({
...request,
chainId,
indexTokenAmount,
})
if (!wrappedQuote) return null
const builder = new WrappedTransactionBuilder(rpcUrl)
Expand Down Expand Up @@ -245,7 +247,10 @@ export class FlashMintQuoteProvider
rpcUrl,
swapQuoteProvider
)
const zeroExQuote = await zeroExQuoteProvider.getQuote(request)
const zeroExQuote = await zeroExQuoteProvider.getQuote({
...request,
indexTokenAmount,
})
if (!zeroExQuote) return null
const builder = new ZeroExTransactionBuilder(rpcUrl)
const txRequest: FlashMintZeroExBuildRequest = {
Expand Down
12 changes: 8 additions & 4 deletions src/quote/provider/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { BigNumber } from '@ethersproject/bignumber'
import { getTokenByChainAndSymbol } from '@indexcoop/tokenlists'

import { ChainId } from 'constants/chains'
import { Contracts } from 'constants/contracts'
import {
Expand All @@ -23,15 +26,16 @@ import { wei } from 'utils'
import { FlashMintContractType, FlashMintQuoteRequest } from './'
import { buildQuoteResponse, getContractType } from './utils'

const { icusd, usdc } = QuoteTokens
const { usdc } = QuoteTokens
const icusd = getTokenByChainAndSymbol(ChainId.Base, 'icUSD')

describe('buildQuoteResponse()', () => {
test('returns correct quote response object', async () => {
const request: FlashMintQuoteRequest = {
isMinting: true,
inputToken: usdc,
outputToken: icusd,
indexTokenAmount: wei(1),
indexTokenAmount: wei(1).toString(),
slippage: 0.1,
}
const quoteAmount = wei(100, 6)
Expand All @@ -54,8 +58,8 @@ describe('buildQuoteResponse()', () => {
inputToken: usdc,
outputToken: icusd,
inputAmount: quoteAmount,
outputAmount: request.indexTokenAmount,
indexTokenAmount: request.indexTokenAmount,
outputAmount: BigNumber.from(request.indexTokenAmount),
indexTokenAmount: BigNumber.from(request.indexTokenAmount),
inputOutputAmount: quoteAmount,
slippage: 0.1,
tx,
Expand Down
4 changes: 2 additions & 2 deletions src/quote/provider/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export function buildQuoteResponse(
inputOutputTokenAmount: BigNumber, // quote amount
tx: TransactionRequest
): FlashMintQuote {
const { isMinting, indexTokenAmount, inputToken, outputToken, slippage } =
request
const { isMinting, inputToken, outputToken, slippage } = request
const indexTokenAmount = BigNumber.from(request.indexTokenAmount)
return {
chainId,
contractType,
Expand Down
4 changes: 2 additions & 2 deletions src/tests/arbitrum/btc2x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('BTC2X (Arbitrum)', () => {
isMinting: true,
inputToken: eth,
outputToken: btc2x,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 0.5,
})
await factory.executeTx()
Expand All @@ -40,7 +40,7 @@ describe('BTC2X (Arbitrum)', () => {
isMinting: false,
inputToken: btc2x,
outputToken: eth,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 0.5,
})
await factory.executeTx()
Expand Down
4 changes: 2 additions & 2 deletions src/tests/arbitrum/btc3x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe.skip('BTC3X (Arbitrum)', () => {
isMinting: true,
inputToken: eth,
outputToken: eth3x,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 1,
})
await factory.executeTx()
Expand All @@ -40,7 +40,7 @@ describe.skip('BTC3X (Arbitrum)', () => {
isMinting: false,
inputToken: eth3x,
outputToken: eth,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 1,
})
await factory.executeTx()
Expand Down
4 changes: 2 additions & 2 deletions src/tests/arbitrum/eth2x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('ETH2X (Arbitrum)', () => {
isMinting: true,
inputToken: eth,
outputToken: eth2x,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 0.5,
})
await factory.executeTx()
Expand All @@ -40,7 +40,7 @@ describe('ETH2X (Arbitrum)', () => {
isMinting: false,
inputToken: eth2x,
outputToken: eth,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 0.5,
})
await factory.executeTx()
Expand Down
4 changes: 2 additions & 2 deletions src/tests/arbitrum/eth3x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('ETH3X (Arbitrum)', () => {
isMinting: true,
inputToken: eth,
outputToken: eth3x,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 0.5,
})
await factory.executeTx()
Expand All @@ -40,7 +40,7 @@ describe('ETH3X (Arbitrum)', () => {
isMinting: false,
inputToken: eth3x,
outputToken: eth,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 0.5,
})
await factory.executeTx()
Expand Down
4 changes: 2 additions & 2 deletions src/tests/arbitrum/ibtc1x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('iBTC1X (Arbitrum)', () => {
isMinting: true,
inputToken: eth,
outputToken: ibtc1x,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 0.5,
})
await factory.executeTx()
Expand All @@ -40,7 +40,7 @@ describe('iBTC1X (Arbitrum)', () => {
isMinting: false,
inputToken: ibtc1x,
outputToken: eth,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 0.5,
})
await factory.executeTx()
Expand Down
4 changes: 2 additions & 2 deletions src/tests/arbitrum/ieth1x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('iETH1X (Arbitrum)', () => {
isMinting: true,
inputToken: eth,
outputToken: ieth1x,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 0.5,
})
await factory.executeTx()
Expand All @@ -40,7 +40,7 @@ describe('iETH1X (Arbitrum)', () => {
isMinting: false,
inputToken: ieth1x,
outputToken: eth,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 0.5,
})
await factory.executeTx()
Expand Down
4 changes: 2 additions & 2 deletions src/tests/base/eth2x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('ETH2X (Base)', () => {
isMinting: true,
inputToken: eth,
outputToken: eth2x,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 0.5,
})
await factory.executeTx()
Expand All @@ -42,7 +42,7 @@ describe('ETH2X (Base)', () => {
isMinting: false,
inputToken: eth2x,
outputToken: eth,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 0.5,
})
await factory.executeTx()
Expand Down
4 changes: 2 additions & 2 deletions src/tests/base/eth3x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe.skip('ETH3X (Base)', () => {
isMinting: true,
inputToken: eth,
outputToken: eth3x,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 0.5,
})
await factory.executeTx()
Expand All @@ -42,7 +42,7 @@ describe.skip('ETH3X (Base)', () => {
isMinting: false,
inputToken: eth3x,
outputToken: eth,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 0.5,
})
await factory.executeTx()
Expand Down
6 changes: 3 additions & 3 deletions src/tests/btc2x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('BTC2X (mainnet)', () => {
isMinting: true,
inputToken: eth,
outputToken: btc2x,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 0.5,
})
await factory.executeTx()
Expand All @@ -33,7 +33,7 @@ describe('BTC2X (mainnet)', () => {
isMinting: true,
inputToken: eth,
outputToken: btc2x,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 0.5,
})
await factory.executeTx()
Expand All @@ -44,7 +44,7 @@ describe('BTC2X (mainnet)', () => {
isMinting: false,
inputToken: btc2x,
outputToken: eth,
indexTokenAmount: wei('1'),
indexTokenAmount: wei('1').toString(),
slippage: 0.5,
})
await factory.executeTx()
Expand Down
Loading

0 comments on commit 0205215

Please sign in to comment.