diff --git a/hardhat.config.js b/hardhat.config.js index a7e4df7f..40d8f612 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -13,7 +13,7 @@ module.exports = { chainId: 1, forking: { url: process.env.MAINNET_ALCHEMY_API, - blockNumber: 21582195, + // blockNumber: 21582195, }, chains: { 1: { diff --git a/src/tests/arbitrum/btc2x.test.ts b/src/tests/arbitrum/btc2x.test.ts index e83da433..abc2c430 100644 --- a/src/tests/arbitrum/btc2x.test.ts +++ b/src/tests/arbitrum/btc2x.test.ts @@ -3,9 +3,7 @@ import { ChainId } from 'constants/chains' import { QuoteTokens, type TestFactory, - getArbitrumTestFactory, - getSignerAccount, - getTestRpcProvider, + getTestFactoryZeroEx, wei, } from 'tests/utils' @@ -16,8 +14,7 @@ const { eth } = QuoteTokens describe('BTC2X (Arbitrum)', () => { let factory: TestFactory beforeEach(async () => { - const signer = getSignerAccount(3, getTestRpcProvider(chainId)) - factory = getArbitrumTestFactory(signer) + factory = getTestFactoryZeroEx(3, chainId) }) test('can mint with ETH', async () => { diff --git a/src/tests/arbitrum/btc2xeth.test.ts b/src/tests/arbitrum/btc2xeth.test.ts index 155ab354..df7b8d92 100644 --- a/src/tests/arbitrum/btc2xeth.test.ts +++ b/src/tests/arbitrum/btc2xeth.test.ts @@ -3,19 +3,17 @@ import { ChainId } from 'constants/chains' import { QuoteTokens, type TestFactory, - getArbitrumTestFactory, - getSignerAccount, - getTestRpcProvider, + getTestFactoryZeroEx, wei, } from 'tests/utils' describe('BTC2xETH (Arbitrum)', () => { + const chainId = ChainId.Arbitrum const { eth } = QuoteTokens - const btc2xEth = getTokenByChainAndSymbol(ChainId.Arbitrum, 'BTC2xETH') + const btc2xEth = getTokenByChainAndSymbol(chainId, 'BTC2xETH') let factory: TestFactory beforeEach(async () => { - const signer = getSignerAccount(3, getTestRpcProvider(ChainId.Arbitrum)) - factory = getArbitrumTestFactory(signer) + factory = getTestFactoryZeroEx(3, chainId) }) test('can mint with ETH', async () => { diff --git a/src/tests/arbitrum/btc3x.test.ts b/src/tests/arbitrum/btc3x.test.ts index 97e8f708..6b50ec6d 100644 --- a/src/tests/arbitrum/btc3x.test.ts +++ b/src/tests/arbitrum/btc3x.test.ts @@ -1,11 +1,9 @@ import { getTokenByChainAndSymbol } from '@indexcoop/tokenlists' import { ChainId } from 'constants/chains' import { + getTestFactoryZeroEx, QuoteTokens, type TestFactory, - getArbitrumTestFactory, - getSignerAccount, - getTestRpcProvider, wei, } from 'tests/utils' @@ -16,8 +14,7 @@ const { eth } = QuoteTokens describe.skip('BTC3X (Arbitrum)', () => { let factory: TestFactory beforeEach(async () => { - const signer = getSignerAccount(5, getTestRpcProvider(chainId)) - factory = getArbitrumTestFactory(signer) + factory = getTestFactoryZeroEx(5, chainId) }) test('can mint with ETH', async () => { diff --git a/src/tests/arbitrum/eth2x.test.ts b/src/tests/arbitrum/eth2x.test.ts index e718fb31..bd96b736 100644 --- a/src/tests/arbitrum/eth2x.test.ts +++ b/src/tests/arbitrum/eth2x.test.ts @@ -3,9 +3,7 @@ import { ChainId } from 'constants/chains' import { QuoteTokens, type TestFactory, - getArbitrumTestFactory, - getSignerAccount, - getTestRpcProvider, + getTestFactoryZeroEx, wei, } from 'tests/utils' @@ -16,8 +14,7 @@ const { eth } = QuoteTokens describe('ETH2X (Arbitrum)', () => { let factory: TestFactory beforeEach(async () => { - const signer = getSignerAccount(0, getTestRpcProvider(chainId)) - factory = getArbitrumTestFactory(signer) + factory = getTestFactoryZeroEx(0, chainId) }) test('can mint with ETH', async () => { diff --git a/src/tests/arbitrum/eth2xbtc.test.ts b/src/tests/arbitrum/eth2xbtc.test.ts index 7c7f6935..aebd4c12 100644 --- a/src/tests/arbitrum/eth2xbtc.test.ts +++ b/src/tests/arbitrum/eth2xbtc.test.ts @@ -3,19 +3,17 @@ import { ChainId } from 'constants/chains' import { QuoteTokens, type TestFactory, - getArbitrumTestFactory, - getSignerAccount, - getTestRpcProvider, + getTestFactoryZeroEx, wei, } from 'tests/utils' describe('ETH2xBTC (Arbitrum)', () => { + const chainId = ChainId.Arbitrum const { eth } = QuoteTokens - const eth2xBtc = getTokenByChainAndSymbol(ChainId.Arbitrum, 'ETH2xBTC') + const eth2xBtc = getTokenByChainAndSymbol(chainId, 'ETH2xBTC') let factory: TestFactory beforeEach(async () => { - const signer = getSignerAccount(3, getTestRpcProvider(ChainId.Arbitrum)) - factory = getArbitrumTestFactory(signer) + factory = getTestFactoryZeroEx(3, chainId) }) test('can mint with ETH', async () => { diff --git a/src/tests/arbitrum/eth3x.test.ts b/src/tests/arbitrum/eth3x.test.ts index ba06c10c..5152bcb4 100644 --- a/src/tests/arbitrum/eth3x.test.ts +++ b/src/tests/arbitrum/eth3x.test.ts @@ -3,9 +3,7 @@ import { ChainId } from 'constants/chains' import { QuoteTokens, type TestFactory, - getArbitrumTestFactory, - getSignerAccount, - getTestRpcProvider, + getTestFactoryZeroEx, wei, } from 'tests/utils' @@ -16,8 +14,7 @@ const { eth } = QuoteTokens describe('ETH3X (Arbitrum)', () => { let factory: TestFactory beforeEach(async () => { - const signer = getSignerAccount(2, getTestRpcProvider(chainId)) - factory = getArbitrumTestFactory(signer) + factory = getTestFactoryZeroEx(2, chainId) }) test.only('can mint with ETH', async () => { diff --git a/src/tests/arbitrum/ibtc1x.test.ts b/src/tests/arbitrum/ibtc1x.test.ts index a22722df..6116a93f 100644 --- a/src/tests/arbitrum/ibtc1x.test.ts +++ b/src/tests/arbitrum/ibtc1x.test.ts @@ -1,11 +1,9 @@ import { getTokenByChainAndSymbol } from '@indexcoop/tokenlists' import { ChainId } from 'constants/chains' import { + getTestFactoryZeroEx, QuoteTokens, type TestFactory, - getArbitrumTestFactory, - getSignerAccount, - getTestRpcProvider, wei, } from 'tests/utils' @@ -16,8 +14,7 @@ const { eth } = QuoteTokens describe('iBTC1X (Arbitrum)', () => { let factory: TestFactory beforeEach(async () => { - const signer = getSignerAccount(4, getTestRpcProvider(chainId)) - factory = getArbitrumTestFactory(signer) + factory = getTestFactoryZeroEx(4, chainId) }) test('can mint with ETH', async () => { diff --git a/src/tests/arbitrum/ieth1x.test.ts b/src/tests/arbitrum/ieth1x.test.ts index 70aa4ac2..100fbc31 100644 --- a/src/tests/arbitrum/ieth1x.test.ts +++ b/src/tests/arbitrum/ieth1x.test.ts @@ -1,11 +1,9 @@ import { getTokenByChainAndSymbol } from '@indexcoop/tokenlists' import { ChainId } from 'constants/chains' import { + getTestFactoryZeroEx, QuoteTokens, type TestFactory, - getArbitrumTestFactory, - getSignerAccount, - getTestRpcProvider, wei, } from 'tests/utils' @@ -16,8 +14,7 @@ const { eth } = QuoteTokens describe('iETH1X (Arbitrum)', () => { let factory: TestFactory beforeEach(async () => { - const signer = getSignerAccount(1, getTestRpcProvider(chainId)) - factory = getArbitrumTestFactory(signer) + factory = getTestFactoryZeroEx(1, chainId) }) test('can mint with ETH', async () => { diff --git a/src/tests/base/eth2x.test.ts b/src/tests/base/eth2x.test.ts index b0e31d92..53f131ae 100644 --- a/src/tests/base/eth2x.test.ts +++ b/src/tests/base/eth2x.test.ts @@ -3,9 +3,7 @@ import { ChainId } from 'constants/chains' import { QuoteTokens, type TestFactory, - getBaseTestFactory, - getSignerAccount, - getTestRpcProvider, + getTestFactoryZeroEx, wei, } from 'tests/utils' @@ -15,8 +13,7 @@ describe('ETH2X (Base)', () => { const eth2x = getTokenByChainAndSymbol(chainId, 'ETH2X') let factory: TestFactory beforeEach(async () => { - const signer = getSignerAccount(0, getTestRpcProvider(chainId)) - factory = getBaseTestFactory(signer) + factory = getTestFactoryZeroEx(0, chainId) }) test('can mint with ETH', async () => { diff --git a/src/tests/base/eth3x.test.ts b/src/tests/base/eth3x.test.ts index 91f2261c..207e1449 100644 --- a/src/tests/base/eth3x.test.ts +++ b/src/tests/base/eth3x.test.ts @@ -3,9 +3,7 @@ import { ChainId } from 'constants/chains' import { QuoteTokens, type TestFactory, - getBaseTestFactory, - getSignerAccount, - getTestRpcProvider, + getTestFactoryZeroEx, wei, } from 'tests/utils' @@ -15,8 +13,7 @@ describe('ETH3X (Base)', () => { const eth3x = getTokenByChainAndSymbol(chainId, 'ETH3X') let factory: TestFactory beforeEach(async () => { - const signer = getSignerAccount(2, getTestRpcProvider(chainId)) - factory = getBaseTestFactory(signer) + factory = getTestFactoryZeroEx(2, chainId) }) test('can mint with ETH', async () => { diff --git a/src/tests/btc2x.test.ts b/src/tests/btc2x.test.ts index 9631a657..95a1416d 100644 --- a/src/tests/btc2x.test.ts +++ b/src/tests/btc2x.test.ts @@ -1,10 +1,8 @@ import { getTokenByChainAndSymbol } from '@indexcoop/tokenlists' import { QuoteTokens, - getMainnetTestFactory, getMainnetTestFactoryUniswap, - getSignerAccount, - getTestRpcProvider, + getTestFactoryZeroEx, wei, } from './utils' @@ -15,10 +13,8 @@ describe('BTC2X (mainnet)', () => { const btc2x = getTokenByChainAndSymbol(chainId, 'BTC2X') const { eth } = QuoteTokens let factory: TestFactory - const provider = getTestRpcProvider(chainId) - const signer = getSignerAccount(4, provider) beforeEach(async () => { - factory = getMainnetTestFactory(signer) + factory = getTestFactoryZeroEx(4) }) test('can mint with ETH', async () => { @@ -33,15 +29,15 @@ describe('BTC2X (mainnet)', () => { }) test.skip('can mint with ETH (IndexSwapQuoteProvider)', async () => { - const factory = getMainnetTestFactoryUniswap(signer) - await factory.fetchQuote({ + const uniFactory = getMainnetTestFactoryUniswap(factory.getSigner()) + await uniFactory.fetchQuote({ isMinting: true, inputToken: eth, outputToken: btc2x, indexTokenAmount: wei('1').toString(), slippage: 0.5, }) - await factory.executeTx() + await uniFactory.executeTx() }) test.skip('can redeem with ETH', async () => { diff --git a/src/tests/dseth/index.test.ts b/src/tests/dseth/index.test.ts index 7fd899ca..21c31e4b 100644 --- a/src/tests/dseth/index.test.ts +++ b/src/tests/dseth/index.test.ts @@ -4,9 +4,7 @@ import { QuoteTokens, type TestFactory, addLiquidityToLido, - getMainnetTestFactory, - getSignerAccount, - getTestRpcProvider, + getTestFactoryZeroEx, swapExactInput, transferFromWhale, wei, @@ -19,8 +17,7 @@ describe('dsETH (mainnet)', () => { const { eth, steth, usdc, weth } = QuoteTokens let factory: TestFactory beforeEach(async () => { - const signer = getSignerAccount(3, getTestRpcProvider(1)) - factory = getMainnetTestFactory(signer) + factory = getTestFactoryZeroEx(3) }) test.only('minting with ETH', async () => { diff --git a/src/tests/eth2x.test.ts b/src/tests/eth2x.test.ts index e00bfb4f..fab77ccf 100644 --- a/src/tests/eth2x.test.ts +++ b/src/tests/eth2x.test.ts @@ -2,10 +2,8 @@ import { getTokenByChainAndSymbol } from '@indexcoop/tokenlists' import { QuoteTokens, type TestFactory, - getMainnetTestFactory, + getTestFactoryZeroEx, getMainnetTestFactoryUniswap, - getSignerAccount, - getTestRpcProvider, wei, } from './utils' @@ -13,10 +11,9 @@ describe('ETH2X (mainnet)', () => { const chainId = 1 const { eth } = QuoteTokens const eth2x = getTokenByChainAndSymbol(chainId, 'ETH2X') - const signer = getSignerAccount(4, getTestRpcProvider(chainId)) let factory: TestFactory beforeEach(async () => { - factory = getMainnetTestFactory(signer) + factory = getTestFactoryZeroEx(4) }) test.only('can mint with ETH', async () => { @@ -31,15 +28,15 @@ describe('ETH2X (mainnet)', () => { }) test.skip('can mint with ETH (IndexSwapQuoteProvider)', async () => { - const factory = getMainnetTestFactoryUniswap(signer) - await factory.fetchQuote({ + const uniFactory = getMainnetTestFactoryUniswap(factory.getSigner()) + await uniFactory.fetchQuote({ isMinting: true, inputToken: eth, outputToken: eth2x, indexTokenAmount: wei('1').toString(), slippage: 0.5, }) - await factory.executeTx() + await uniFactory.executeTx() }) test('can redeem with ETH', async () => { @@ -54,14 +51,14 @@ describe('ETH2X (mainnet)', () => { }) test.skip('can redeem with ETH (IndexSwapQuoteProvider)', async () => { - const factory = getMainnetTestFactoryUniswap(signer) - await factory.fetchQuote({ + const uniFactory = getMainnetTestFactoryUniswap(factory.getSigner()) + await uniFactory.fetchQuote({ isMinting: false, inputToken: eth2x, outputToken: eth, indexTokenAmount: wei('1').toString(), slippage: 0.5, }) - await factory.executeTx() + await uniFactory.executeTx() }) }) diff --git a/src/tests/hyeth.test.ts b/src/tests/hyeth.test.ts index 7e673af1..78f5138d 100644 --- a/src/tests/hyeth.test.ts +++ b/src/tests/hyeth.test.ts @@ -3,9 +3,7 @@ import { QuoteTokens, type TestFactory, balanceOf, - getMainnetTestFactory, - getSignerAccount, - getTestRpcProvider, + getTestFactoryZeroEx, transferFromWhale, wei, wrapETH, @@ -18,8 +16,7 @@ describe('hyETH', () => { const usdc = getTokenByChainAndSymbol(chainId, 'USDC') let factory: TestFactory beforeEach(async () => { - const signer = getSignerAccount(4, getTestRpcProvider(chainId)) - factory = getMainnetTestFactory(signer) + factory = getTestFactoryZeroEx(4) }) test('can mint with ETH', async () => { diff --git a/src/tests/iceth.test.ts b/src/tests/iceth.test.ts index 0e5f52d7..afdb4805 100644 --- a/src/tests/iceth.test.ts +++ b/src/tests/iceth.test.ts @@ -4,10 +4,8 @@ import { getTokenByChainAndSymbol } from '@indexcoop/tokenlists' import { QuoteTokens, type TestFactory, - getMainnetTestFactory, + getTestFactoryZeroEx, getMainnetTestFactoryUniswap, - getSignerAccount, - getTestRpcProvider, wei, wrapETH, } from './utils' @@ -17,10 +15,9 @@ describe('icETH (mainnet)', () => { const { eth } = QuoteTokens const iceth = getTokenByChainAndSymbol(chainId, 'icETH') const weth = getTokenByChainAndSymbol(chainId, 'WETH') - const signer = getSignerAccount(4, getTestRpcProvider(chainId)) let factory: TestFactory beforeEach(async () => { - factory = getMainnetTestFactory(signer) + factory = getTestFactoryZeroEx(4) }) test('can mint icETH-ETH', async () => { @@ -35,15 +32,15 @@ describe('icETH (mainnet)', () => { }) test.skip('can mint icETH-ETH (IndexSwapQuoteProvider)', async () => { - const factory = getMainnetTestFactoryUniswap(signer) - await factory.fetchQuote({ + const uniFactory = getMainnetTestFactoryUniswap(factory.getSigner()) + await uniFactory.fetchQuote({ isMinting: true, inputToken: eth, outputToken: iceth, indexTokenAmount: wei('1').toString(), slippage: 0.5, }) - await factory.executeTx() + await uniFactory.executeTx() }) test('can redeem for ETH', async () => { @@ -70,7 +67,7 @@ describe('icETH (mainnet)', () => { }) test.skip('can mint with WETH (IndexSwapQuoteProvider)', async () => { - const factory = getMainnetTestFactoryUniswap(signer) + const uniFactory = getMainnetTestFactoryUniswap(factory.getSigner()) const quote = await factory.fetchQuote({ isMinting: true, inputToken: weth, @@ -78,8 +75,8 @@ describe('icETH (mainnet)', () => { indexTokenAmount: wei('0.1').toString(), slippage: 1, }) - await wrapETH(quote.inputOutputAmount, factory.getSigner()) - await factory.executeTx() + await wrapETH(quote.inputOutputAmount, uniFactory.getSigner()) + await uniFactory.executeTx() }) test('can redeem for WETH', async () => { diff --git a/src/tests/icusd.test.ts b/src/tests/icusd.test.ts index 68e01870..e7194924 100644 --- a/src/tests/icusd.test.ts +++ b/src/tests/icusd.test.ts @@ -4,9 +4,7 @@ import { getTokenByChainAndSymbol } from '@indexcoop/tokenlists' import { ChainId } from 'constants/chains' import { type TestFactory, - getBaseTestFactory, - getSignerAccount, - getTestRpcProvider, + getTestFactoryZeroEx, transferFromWhale, wei, wrapETH, @@ -18,10 +16,9 @@ describe('icUSD (Base)', () => { const usdc = getTokenByChainAndSymbol(chainId, 'USDC') const weth = getTokenByChainAndSymbol(chainId, 'WETH') const usdcWhale = '0x8dB0f952B8B6A462445C732C41Ec2937bCae9c35' - const signer = getSignerAccount(4, getTestRpcProvider(chainId)) let factory: TestFactory beforeEach(async () => { - factory = getBaseTestFactory(signer) + factory = getTestFactoryZeroEx(4, chainId) }) test('can mint with USDC', async () => { diff --git a/src/tests/utils/factories.ts b/src/tests/utils/factories.ts index 606b04cf..72bbb353 100644 --- a/src/tests/utils/factories.ts +++ b/src/tests/utils/factories.ts @@ -1,38 +1,26 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ import { ChainId } from 'constants/chains' import { IndexSwapQuoteProvider } from 'quote' import { getLocalHostProviderUrl, + getSignerAccount, + getTestRpcProvider, getZeroExSwapQuoteProvider, } from 'tests/utils' import { TestFactory } from 'tests/utils/factory' -// Pre-configured TestFactories -export function getArbitrumTestFactory( - signer: any, - rpcUrl: string = getLocalHostProviderUrl(ChainId.Arbitrum), -) { - const swapQuoteProvider = getZeroExSwapQuoteProvider(ChainId.Arbitrum) - return new TestFactory(rpcUrl, signer, swapQuoteProvider) -} - -export function getBaseTestFactory( - signer: any, - rpcUrl: string = getLocalHostProviderUrl(ChainId.Base), -) { - const swapQuoteProvider = getZeroExSwapQuoteProvider(ChainId.Base) - return new TestFactory(rpcUrl, signer, swapQuoteProvider) -} - -export function getMainnetTestFactory( - signer: any, - rpcUrl: string = getLocalHostProviderUrl(ChainId.Mainnet), +export function getTestFactoryZeroEx( + signerAccountNo: number, + chainId = ChainId.Mainnet, ) { - const swapQuoteProvider = getZeroExSwapQuoteProvider(ChainId.Mainnet) + const provider = getTestRpcProvider(chainId) + const signer = getSignerAccount(signerAccountNo, provider) + const swapQuoteProvider = getZeroExSwapQuoteProvider(chainId) + const rpcUrl = getLocalHostProviderUrl(chainId) return new TestFactory(rpcUrl, signer, swapQuoteProvider) } export function getMainnetTestFactoryUniswap( + // eslint-disable-next-line @typescript-eslint/no-explicit-any signer: any, rpcUrl: string = getLocalHostProviderUrl(ChainId.Mainnet), ) {