Skip to content

Commit

Permalink
fix: hyeth quotes (#103)
Browse files Browse the repository at this point in the history
* feat: make component swap data for hyeth dynamic

* fix tests

* fix hyeth builder test

* temp skip tests

* update block number

* fix test

* remove whale for redeem

* update block number. clean up tests

* fix hyeth provider tests
  • Loading branch information
janndriessen authored Dec 20, 2024
1 parent f24052d commit 56db38b
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 194 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ jobs:
- run: npm run test:utils
- run: npm run test:builders
- run: npm run test:quotes
- run: npm run test:btc2xeth
- run: npm run test:eth2xbtc
- run: npm run test:base
- run: npm run test:icusd
# - run: npm run test:btc2xeth
# - run: npm run test:eth2xbtc
# - run: npm run test:base
# - run: npm run test:icusd
- run: npm run test:hyeth
# - run: npm run test:btc2x
# - run: npm run test:eth2x
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
chainId: 1,
forking: {
url: process.env.MAINNET_ALCHEMY_API,
blockNumber: 21037088,
blockNumber: 21442190,
},
chains: {
1: {
Expand Down
11 changes: 10 additions & 1 deletion src/flashmint/builders/hyeth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,16 @@ function createBuildRequest(
poolIds: [],
pool: '0xDC24316b9AE028F1497c275EB9192a3Ea0f67022',
}
const componentsSwapData = getComponentsSwapData().map((swapData) => {
const componentsSwapData = getComponentsSwapData([
'',
'',
'',
'',
'',
'',
'',
'',
]).map((swapData) => {
return { ...swapData, poolIds: [] }
})
return {
Expand Down
113 changes: 20 additions & 93 deletions src/quote/flashmint/hyeth/provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getTokenByChainAndSymbol } from '@indexcoop/tokenlists'

/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { AddressZero, EthAddress } from 'constants/addresses'
import { ChainId } from 'constants/chains'
Expand All @@ -14,22 +16,21 @@ import {

import { FlashMintHyEthQuoteProvider } from './provider'

const rpcUrl = getLocalHostProviderUrl(ChainId.Mainnet)
const swapQuoteProvider = getZeroExSwapQuoteProvider(ChainId.Mainnet)

const { eth, hyeth, usdc, weth } = QuoteTokens
const indexToken = hyeth
const chainId = ChainId.Mainnet
const rpcUrl = getLocalHostProviderUrl(chainId)
const swapQuoteProvider = getZeroExSwapQuoteProvider(chainId)

describe('FlashMintHyEthQuoteProvider()', () => {
const { eth } = QuoteTokens
const hyeth = getTokenByChainAndSymbol(chainId, 'hyETH')
const indexToken = hyeth
const usdc = getTokenByChainAndSymbol(chainId, 'USDC')
const weth = getTokenByChainAndSymbol(chainId, 'WETH')
test('returns a quote for minting w/ ETH', async () => {
const request = {
isMinting: true,
inputToken: eth,
outputToken: {
symbol: indexToken.symbol,
decimals: 18,
address: indexToken.address!,
},
outputToken: indexToken,
indexTokenAmount: wei(1).toBigInt(),
slippage: 0.5,
}
Expand All @@ -41,13 +42,7 @@ describe('FlashMintHyEthQuoteProvider()', () => {
if (!quote) fail()
expect(quote.indexTokenAmount).toEqual(request.indexTokenAmount)
expect(quote.inputOutputTokenAmount > 0).toBe(true)
const componentSwapDataIssue = [
noopSwapData,
noopSwapData,
noopSwapData,
noopSwapData,
noopSwapData,
]
const componentSwapDataIssue = [noopSwapData, noopSwapData]
expect(quote.componentsSwapData).toStrictEqual(componentSwapDataIssue)
expect(quote.swapDataEthToInputOutputToken).toBeNull()
expect(quote.swapDataInputTokenToEth).toBeNull()
Expand All @@ -57,11 +52,7 @@ describe('FlashMintHyEthQuoteProvider()', () => {
const request = {
isMinting: true,
inputToken: weth,
outputToken: {
symbol: indexToken.symbol,
decimals: 18,
address: indexToken.address!,
},
outputToken: indexToken,
indexTokenAmount: wei(1).toBigInt(),
slippage: 0.5,
}
Expand All @@ -73,20 +64,7 @@ describe('FlashMintHyEthQuoteProvider()', () => {
if (!quote) fail()
expect(quote.indexTokenAmount).toEqual(request.indexTokenAmount)
expect(quote.inputOutputTokenAmount > 0).toBe(true)
const componentSwapDataIssue = [
noopSwapData,
noopSwapData,
noopSwapData,
noopSwapData,
noopSwapData,
// {
// exchange: Exchange.UniV3,
// fees: [500],
// path: [WETH.address, USDC.address],
// pool: AddressZero,
// },
]
expect(quote.componentsSwapData).toStrictEqual(componentSwapDataIssue)
expect(quote.componentsSwapData.length).toBe(2)
const swapDataInputTokenToEth = {
path: [weth.address, EthAddress],
fees: [],
Expand All @@ -109,11 +87,7 @@ describe('FlashMintHyEthQuoteProvider()', () => {
const request = {
isMinting: true,
inputToken: usdc,
outputToken: {
symbol: indexToken.symbol,
decimals: 18,
address: indexToken.address!,
},
outputToken: indexToken,
indexTokenAmount: wei(1).toBigInt(),
slippage: 0.5,
}
Expand All @@ -125,20 +99,7 @@ describe('FlashMintHyEthQuoteProvider()', () => {
if (!quote) fail()
expect(quote.indexTokenAmount).toEqual(request.indexTokenAmount)
expect(quote.inputOutputTokenAmount > 0).toBe(true)
const componentSwapDataIssue = [
noopSwapData,
noopSwapData,
noopSwapData,
noopSwapData,
noopSwapData,
// {
// exchange: Exchange.UniV3,
// fees: [500],
// path: [WETH.address, USDC.address],
// pool: AddressZero,
// },
]
expect(quote.componentsSwapData).toStrictEqual(componentSwapDataIssue)
expect(quote.componentsSwapData.length).toBe(2)
const swapDataInputTokenToEth = {
path: [USDC.address, WETH.address],
fees: [500],
Expand All @@ -160,11 +121,7 @@ describe('FlashMintHyEthQuoteProvider()', () => {
test('returns a quote for redeeming to ETH', async () => {
const request = {
isMinting: false,
inputToken: {
symbol: indexToken.symbol,
decimals: 18,
address: indexToken.address!,
},
inputToken: indexToken,
outputToken: eth,
indexTokenAmount: wei(1).toBigInt(),
slippage: 0.5,
Expand All @@ -177,32 +134,15 @@ describe('FlashMintHyEthQuoteProvider()', () => {
if (!quote) fail()
expect(quote.indexTokenAmount).toEqual(request.indexTokenAmount)
expect(quote.inputOutputTokenAmount > 0).toBe(true)
const componentSwapDataRedeem = [
noopSwapData,
noopSwapData,
noopSwapData,
noopSwapData,
noopSwapData,
// {
// exchange: Exchange.UniV3,
// fees: [500],
// path: [USDC.address, WETH.address],
// pool: AddressZero,
// },
]
expect(quote.componentsSwapData).toStrictEqual(componentSwapDataRedeem)
expect(quote.componentsSwapData.length).toBe(2)
expect(quote.swapDataEthToInputOutputToken).toBeNull()
expect(quote.swapDataInputTokenToEth).toBeNull()
})

test('returns a quote for redeeming to ERC-20', async () => {
const request = {
isMinting: false,
inputToken: {
symbol: indexToken.symbol,
decimals: 18,
address: indexToken.address!,
},
inputToken: indexToken,
outputToken: usdc,
indexTokenAmount: wei(1).toBigInt(),
slippage: 0.5,
Expand All @@ -215,20 +155,7 @@ describe('FlashMintHyEthQuoteProvider()', () => {
if (!quote) fail()
expect(quote.indexTokenAmount).toEqual(request.indexTokenAmount)
expect(quote.inputOutputTokenAmount > 0).toBe(true)
const componentSwapDataRedeem = [
noopSwapData,
noopSwapData,
noopSwapData,
noopSwapData,
noopSwapData,
// {
// exchange: Exchange.UniV3,
// fees: [500],
// path: [USDC.address, WETH.address],
// pool: AddressZero,
// },
]
expect(quote.componentsSwapData).toStrictEqual(componentSwapDataRedeem)
expect(quote.componentsSwapData.length).toBe(2)
expect(quote.swapDataInputTokenToEth).toBeNull()
const swapDataEthToInputToken = {
path: [WETH.address, USDC.address],
Expand Down
3 changes: 2 additions & 1 deletion src/quote/flashmint/hyeth/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export class FlashMintHyEthQuoteProvider
): Promise<FlashMintHyEthQuote | null> {
const { indexTokenAmount, inputToken, isMinting, outputToken, slippage } =
request
const componentsSwapData = getComponentsSwapData()
// Only relevant for minting ERC-20's
const swapDataInputTokenToEth = isMinting
? getInputTokenToEthSwapData(inputToken)
Expand All @@ -61,6 +60,8 @@ export class FlashMintHyEthQuoteProvider
this.rpcUrl
)

const componentsSwapData = getComponentsSwapData(components)

if (componentsSwapData.length !== components.length) return null

// Mainnet only for now
Expand Down
4 changes: 2 additions & 2 deletions src/quote/flashmint/hyeth/swap-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { ETH, WETH } from 'constants/tokens'
import { QuoteToken } from 'quote/interfaces'
import { Exchange, SwapData } from 'utils'

export function getComponentsSwapData(): SwapData[] {
return [noopSwapData, noopSwapData, noopSwapData, noopSwapData, noopSwapData]
export function getComponentsSwapData(components: string[]): SwapData[] {
return components.map(() => noopSwapData)
}

export function getEthToInputOutputTokenSwapData(
Expand Down
Loading

0 comments on commit 56db38b

Please sign in to comment.