From 46a02ee661530a0e27bf1b16ec922fe567e8c68f Mon Sep 17 00:00:00 2001 From: Emily Williams Date: Wed, 20 Sep 2023 17:39:50 -0400 Subject: [PATCH] rest of PR comments --- test/uniswapTrades.test.ts | 10 +++++----- test/utils/uniswapData.ts | 17 ++++++++++------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/test/uniswapTrades.test.ts b/test/uniswapTrades.test.ts index 00238d03..57f7f1bb 100644 --- a/test/uniswapTrades.test.ts +++ b/test/uniswapTrades.test.ts @@ -625,7 +625,7 @@ describe('Uniswap', () => { it('encodes a single exactInput STETH -> WSTETH -> WETH swap with Permit', async () => { const inputSTETH = expandTo18DecimalsBN('0.001') - const inputWSTETH = await getWStethPerSteth(inputSTETH.sub(1), 18135610) + const inputWSTETH = await getWStethPerSteth(inputSTETH.sub(1)) const permit2Data = makePermit(STETH_ADDRESS(1), inputSTETH.toString(), undefined, FORGE_ROUTER_ADDRESS) const signature = await generatePermitSignature(permit2Data, wallet, 1, FORGE_PERMIT2_ADDRESS) @@ -653,7 +653,7 @@ describe('Uniswap', () => { it('encodes a single exactInput STETH -> WSTETH -> ETH swap with Permit', async () => { const inputSTETH = expandTo18DecimalsBN('0.001') - const inputWSTETH = await getWStethPerSteth(inputSTETH.sub(1), 18135610) + const inputWSTETH = await getWStethPerSteth(inputSTETH.sub(1)) const permit2Data = makePermit(STETH_ADDRESS(1), inputSTETH.toString(), undefined, FORGE_ROUTER_ADDRESS) const signature = await generatePermitSignature(permit2Data, wallet, 1, FORGE_PERMIT2_ADDRESS) @@ -691,8 +691,8 @@ describe('Uniswap', () => { ) // Wrap Configurations - const maximumWstethIn = BigNumber.from(trade.maximumAmountIn((swapOpts.slippageTolerance)).quotient.toString()) - const inputSTETH = await getStethPerWsteth(maximumWstethIn.add('1'), 18135610) + const maximumWstethIn = BigNumber.from(trade.maximumAmountIn(swapOpts.slippageTolerance).quotient.toString()) + const inputSTETH = await getStethPerWsteth(maximumWstethIn.add('1')) const permit2Data = makePermit(STETH_ADDRESS(1), inputSTETH.toString(), undefined, FORGE_ROUTER_ADDRESS) const signature = await generatePermitSignature(permit2Data, wallet, 1, FORGE_PERMIT2_ADDRESS) const WrapSTETHPermitData = { @@ -750,7 +750,7 @@ describe('Uniswap', () => { it('encodes a single exactInput WETH -> WSTETH -> STETH exactOutput swap', async () => { const outputSTETH = expandTo18DecimalsBN('0.001') - const outputWSTETH = await getWStethPerSteth(outputSTETH.add('2'), 18135610) + const outputWSTETH = await getWStethPerSteth(outputSTETH.add('2')) const trade = await V3Trade.fromRoute( new RouteV3([WETH_WSTETH_V3], WETH, WSTETH), diff --git a/test/utils/uniswapData.ts b/test/utils/uniswapData.ts index cf0d403b..c4b27fb3 100644 --- a/test/utils/uniswapData.ts +++ b/test/utils/uniswapData.ts @@ -93,7 +93,7 @@ export const WETH = new Token(1, '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', 1 export const DAI = new Token(1, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 18, 'DAI', 'dai') export const USDC = new Token(1, '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', 6, 'USDC', 'USD Coin') export const STETH = new Token(1, '0xae7ab96520de3a18e5e111b5eaab095312d7fe84', 18, 'STETH', 'Liquid staked Ether') -export const WSTETH = new Token(1, '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0', 18, 'WSTETH', 'Liquid staked Ether') +export const WSTETH = new Token(1, '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0', 18, 'WSTETH', 'Wrapped liquid staked Ether') export const FEE_AMOUNT = FeeAmount.MEDIUM type UniswapPools = { @@ -122,10 +122,10 @@ export async function getUniswapPools(forkBlock?: number): Promise } } -export async function getUniswapStethPool(forkBlock?: number): Promise { - const stethDefaultFork = 18135610 - const fork = forkBlock ?? stethDefaultFork - return await getPool(WSTETH, WETH, FeeAmount.LOWEST, fork) +const STETH_BLOCK = 18135610 + +export async function getUniswapStethPool(forkBlock: number = STETH_BLOCK): Promise { + return await getPool(WSTETH, WETH, FeeAmount.LOWEST, forkBlock) } function getProvider(): ethers.providers.BaseProvider { @@ -163,12 +163,15 @@ export async function getPool(tokenA: Token, tokenB: Token, feeAmount: FeeAmount ]) } -export async function getWStethPerSteth(stethAmount: BigNumber, blockNumber: number): Promise { +export async function getWStethPerSteth(stethAmount: BigNumber, blockNumber: number = STETH_BLOCK): Promise { const contract = new ethers.Contract(STETH.address, STETH_ABI, getProvider()) return await contract.getSharesByPooledEth(stethAmount, { blockTag: blockNumber }) } -export async function getStethPerWsteth(wstethAmount: BigNumber, blockNumber: number): Promise { +export async function getStethPerWsteth( + wstethAmount: BigNumber, + blockNumber: number = STETH_BLOCK +): Promise { const contract = new ethers.Contract(STETH.address, STETH_ABI, getProvider()) return await contract.getPooledEthByShares(wstethAmount, { blockTag: blockNumber }) }