Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
rest of PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilz committed Sep 20, 2023
1 parent dcdd229 commit 46a02ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
10 changes: 5 additions & 5 deletions test/uniswapTrades.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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),
Expand Down
17 changes: 10 additions & 7 deletions test/utils/uniswapData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -122,10 +122,10 @@ export async function getUniswapPools(forkBlock?: number): Promise<UniswapPools>
}
}

export async function getUniswapStethPool(forkBlock?: number): Promise<Pool> {
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<Pool> {
return await getPool(WSTETH, WETH, FeeAmount.LOWEST, forkBlock)
}

function getProvider(): ethers.providers.BaseProvider {
Expand Down Expand Up @@ -163,12 +163,15 @@ export async function getPool(tokenA: Token, tokenB: Token, feeAmount: FeeAmount
])
}

export async function getWStethPerSteth(stethAmount: BigNumber, blockNumber: number): Promise<BigNumber> {
export async function getWStethPerSteth(stethAmount: BigNumber, blockNumber: number = STETH_BLOCK): Promise<BigNumber> {
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<BigNumber> {
export async function getStethPerWsteth(
wstethAmount: BigNumber,
blockNumber: number = STETH_BLOCK
): Promise<BigNumber> {
const contract = new ethers.Contract(STETH.address, STETH_ABI, getProvider())
return await contract.getPooledEthByShares(wstethAmount, { blockTag: blockNumber })
}
Expand Down

0 comments on commit 46a02ee

Please sign in to comment.