Skip to content

Commit

Permalink
fix(v4-sdk): loosen v4 last pool check invariant (#288)
Browse files Browse the repository at this point in the history
## PR Scope

Please title your PR according to the following types and scopes following [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/):

- `fix(SDK name):` will trigger a patch version
- `chore(<type>):` will not trigger any release and should be used for internal repo changes
- `<type>(public):` will trigger a patch version for non-code changes (e.g. README changes)
- `feat(SDK name):` will trigger a minor version
- `feat(breaking):` will trigger a major version for a breaking change

## Description

_[Summary of the change, motivation, and context]_

## How Has This Been Tested?

_[e.g. Manually, E2E tests, unit tests, Storybook]_

## Are there any breaking changes?

_[e.g. Type definitions, API definitions]_

If there are breaking changes, please ensure you bump the major version Bump the major version (by using the title `feat(breaking): ...`), post a notice in #eng-sdks, and explicitly notify all Uniswap Labs consumers of the SDK.

## (Optional) Feedback Focus

_[Specific parts of this PR you'd like feedback on, or that reviewers should pay closer attention to]_

## (Optional) Follow Ups

_[Things that weren't addressed in this PR, ways you plan to build on this work, or other ways this work could be extended]_
  • Loading branch information
jsy1218 authored Jan 31, 2025
1 parent 1bd65ba commit 7ff3e1c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
34 changes: 33 additions & 1 deletion sdks/v4-sdk/src/entities/pool.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Token, CurrencyAmount, WETH9 } from '@uniswap/sdk-core'
import { Token, CurrencyAmount, WETH9, Ether, ChainId } from '@uniswap/sdk-core'
import { Pool, DYNAMIC_FEE_FLAG } from './pool'
import JSBI from 'jsbi'
import { nearestUsableTick, encodeSqrtRatioX96, TickMath } from '@uniswap/v3-sdk'
Expand Down Expand Up @@ -261,6 +261,38 @@ describe('Pool', () => {
expect(pool.involvesCurrency(WETH9[1])).toEqual(false)
})

describe('#v4InvolvesToken', () => {
const pool = new Pool(
Ether.onChain(ChainId.MAINNET),
DAI,
FEE_AMOUNT_LOW,
TICK_SPACING_TEN,
ADDRESS_ZERO,
encodeSqrtRatioX96(1, 1),
0,
0,
[]
)
expect(pool.v4InvolvesToken(Ether.onChain(ChainId.MAINNET))).toEqual(true)
expect(pool.v4InvolvesToken(DAI)).toEqual(true)
expect(pool.v4InvolvesToken(WETH9[1])).toEqual(true)

const pool2 = new Pool(
Ether.onChain(ChainId.MAINNET).wrapped,
DAI,
FEE_AMOUNT_LOW,
TICK_SPACING_TEN,
ADDRESS_ZERO,
encodeSqrtRatioX96(1, 1),
0,
0,
[]
)
expect(pool2.v4InvolvesToken(Ether.onChain(ChainId.MAINNET))).toEqual(true)
expect(pool2.v4InvolvesToken(DAI)).toEqual(true)
expect(pool2.v4InvolvesToken(WETH9[1])).toEqual(true)
})

describe('swaps', () => {
let pool: Pool
let poolWithSwapHook: Pool
Expand Down
14 changes: 14 additions & 0 deletions sdks/v4-sdk/src/entities/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ export class Pool {
return this.involvesCurrency(currency)
}

/**
* v4-only involvesToken convenience method, used for mixed route ETH <-> WETH connection only
* @param currency
*/
public v4InvolvesToken(currency: Currency): boolean {
return (
this.involvesCurrency(currency) ||
currency.wrapped.equals(this.currency0) ||
currency.wrapped.equals(this.currency1) ||
currency.wrapped.equals(this.currency0.wrapped) ||
currency.wrapped.equals(this.currency1.wrapped)
)
}

/**
* Returns the current mid price of the pool in terms of currency0, i.e. the ratio of currency1 over currency0
*/
Expand Down

0 comments on commit 7ff3e1c

Please sign in to comment.