-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Routing sdk add support for native token pools (#10882)
<!-- Before opening a pull request, please read the [contributing guidelines](https://github.com/pancakeswap/pancake-frontend/blob/develop/CONTRIBUTING.md) first --> <!-- start pr-codex --> --- ## PR-Codex overview This PR introduces support for native token pools in the `@pancakeswap/routing-sdk`. It includes updates to types, functions, and data handling to accommodate the new native token structure in the routing logic. ### Detailed summary - Added support for native token pools. - Updated `Vertice` type to use `Token` instead of `Currency`. - Introduced `getWrappedCurrencyKey` and `getVerticeKey` functions. - Modified `getEdgeKey` to utilize the new key functions. - Adjusted various functions to handle `Token` instead of `Currency`. - Updated price calculations to work with wrapped tokens. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
- Loading branch information
1 parent
176eb10
commit ffa96b3
Showing
9 changed files
with
56 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@pancakeswap/routing-sdk': patch | ||
--- | ||
|
||
Add support for native token pools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import type { Edge, Pool, Vertice } from '../types' | ||
import { getVerticeKey } from './vertice' | ||
|
||
export function getNeighbour(e: Edge, v: Vertice): Vertice { | ||
return e.vertice0.currency.equals(v.currency) ? e.vertice1 : e.vertice0 | ||
} | ||
|
||
export function getEdgeKey(p: Pool, vertA: Vertice, vertB: Vertice): string { | ||
const [vert0, vert1] = vertA.currency.wrapped.sortsBefore(vertB.currency.wrapped) ? [vertA, vertB] : [vertB, vertA] | ||
return `${vert0.currency.chainId}-${vert0.currency.wrapped.address}-${vert1.currency.wrapped.address}-${p.getId()}` | ||
const [vert0, vert1] = vertA.currency.sortsBefore(vertB.currency) ? [vertA, vertB] : [vertB, vertA] | ||
return `${getVerticeKey(vert0)}-${getVerticeKey(vert1)}-${p.getId()}` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './edge' | ||
export * from './graph' | ||
export * from './priceCalculator' | ||
export * from './vertice' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Currency, getCurrencyAddress } from '@pancakeswap/swap-sdk-core' | ||
|
||
import { Vertice } from '../types' | ||
|
||
export function getWrappedCurrencyKey(c: Currency) { | ||
return `${c.chainId}-${getCurrencyAddress(c.wrapped)}` | ||
} | ||
|
||
export function getVerticeKey(vertice: Vertice) { | ||
return getWrappedCurrencyKey(vertice.currency) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters