Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 4.1.0-beta.0 #351

Merged
merged 22 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
29bdb88
update boosted tokens
sergioyuhjtman Dec 20, 2022
259c241
add connecting tokens logic
sergioyuhjtman Dec 22, 2022
f7d6d91
add a connecting token to test cases
sergioyuhjtman Dec 23, 2022
3abb551
test: add reverse case
sergioyuhjtman Dec 23, 2022
47d4108
Add connecting BBRZ2 on Polygon.
johngrantuk Jan 24, 2023
dc523b6
Merge develop
johngrantuk Jan 24, 2023
7c9a22d
Updating test address.
johngrantuk Jan 24, 2023
15d61a9
Only add the pools if there is a complete path tokenIn -> connectingT…
danielmkm Jan 25, 2023
bdf30c0
move the connectingTokens.map call to the top of the function, no nee…
danielmkm Jan 25, 2023
c3e0f98
Merge pull request #349 from beethovenxfi/daniel/configurable-connect…
Jan 25, 2023
1ca22fa
Reintroduce separate pool additions. Small refactor.
johngrantuk Jan 25, 2023
70b21f7
Add wstEth as connecting token for mainnet.
johngrantuk Jan 25, 2023
401c384
Remove old circleci.
johngrantuk Jan 25, 2023
7a1dd34
Add Github workflow.
johngrantuk Jan 25, 2023
63443f8
Remove coveralls.
johngrantuk Jan 25, 2023
39b3734
Add env config.
johngrantuk Jan 25, 2023
e40d163
Merge pull request #350 from balancer-labs/github-workflow
Jan 25, 2023
978fb9f
Make connecting tokens optional in config.
johngrantuk Jan 25, 2023
a07e95f
Remove Coveralls.
johngrantuk Jan 25, 2023
7db1287
Update version to 4.1.0-beta.0.
johngrantuk Jan 25, 2023
2367db2
Merge branch 'develop' into configurable-connecting-tokens
johngrantuk Jan 25, 2023
c6b4050
Merge pull request #348 from balancer-labs/configurable-connecting-to…
Jan 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions .circleci/config.yml

This file was deleted.

70 changes: 70 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Checks

on:
- pull_request

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install node
uses: actions/setup-node@v3
with:
node-version: 14.16.1
- name: Cache
uses: actions/cache@v2
id: cache
with:
path: '**/node_modules'
key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn --immutable
if: steps.cache.outputs.cache-hit != 'true'
- name: Lint
run: yarn lint

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install node
uses: actions/setup-node@v3
with:
node-version: 14.16.1
- name: Cache
uses: actions/cache@v2
id: cache
with:
path: '**/node_modules'
key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn --immutable
if: steps.cache.outputs.cache-hit != 'true'
- name: Build
run: yarn build

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install node
uses: actions/setup-node@v3
with:
node-version: 14.16.1
- name: Cache
uses: actions/cache@v2
id: cache
with:
path: '**/node_modules'
key: yarn-v1-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn --immutable
if: steps.cache.outputs.cache-hit != 'true'
- name: Compile
run: yarn build
- name: Test
run: yarn test
env:
CI: true
INFURA: ${{ secrets.INFURA }}
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<p align="center">
<a href="https://circleci.com/gh/balancer-labs/balancer-sor">
<img src="https://circleci.com/gh/balancer-labs/balancer-sor.svg?style=svg&circle-token=33636208d3161f79ff283b29c8dba9841bda8931" />
</a>
<a href="https://coveralls.io/github/balancer-labs/balancer-sor">
<img src="https://coveralls.io/repos/github/balancer-labs/balancer-sor/badge.svg?t=7avwwt" />
</a>
<a href="https://www.gnu.org/licenses/gpl-3.0">
<img src="https://img.shields.io/badge/License-GPLv3-green.svg" />
</a>
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@balancer-labs/sor",
"version": "4.0.1-beta.18",
"version": "4.1.0-beta.0",
"license": "GPL-3.0-only",
"main": "dist/index.js",
"module": "dist/index.esm.js",
Expand All @@ -9,7 +9,6 @@
"build": "rollup -c",
"prepack": "yarn build",
"test": "TS_NODE_PROJECT='tsconfig.testing.json' nyc mocha -r ts-node/register test/*.spec.ts --timeout 20000",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"lint": "eslint ./src ./test --ext .ts --max-warnings 0",
"node": "npx hardhat node --tsconfig tsconfig.testing.json --fork $(grep ALCHEMY_URL .env | cut -d '=' -f2) --fork-block-number 14828550"
},
Expand Down Expand Up @@ -48,7 +47,6 @@
"@typescript-eslint/parser": "^4.29.2",
"bignumber.js": "^9.0.1",
"chai": "^4.2.0",
"coveralls": "^3.0.9",
"dotenv": "^8.2.0",
"eslint": "^7.32.0",
"eslint-plugin-mocha-no-only": "^1.1.1",
Expand Down
179 changes: 104 additions & 75 deletions src/routeProposal/filtering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ import { Zero } from '@ethersproject/constants';

const BOOSTED_PATHS_MAX_LENGTH = 7;

interface edgeDict {
[node: string]: [string, string, string][];
}

interface treeEdge {
edge: [string, string, string];
parentIndices: [number, number];
visitedNodes: string[];
}

export const filterPoolsByType = (
pools: SubgraphPoolBase[],
poolTypeFilter: PoolFilter
Expand Down Expand Up @@ -166,17 +176,20 @@ export function producePaths(
// We build this tree by adding at each step all the possible continuations for
// each branch. When a branch reaches tokenOut, we write down the corresponding path.
// We only allow paths up to length BOOSTED_PATHS_MAX_LENGTH = 7

export function getBoostedGraph(
tokenIn: string,
tokenOut: string,
poolsAllDict: PoolDictionary,
config: SorConfig
): edgeDict {
const wethAddress: string = config.weth.toLowerCase();
const graphPoolsSet: Set<PoolBase> = new Set();
const linearPools: PoolBase[] = [];
const phantomPools: PoolBase[] = [];
const connectingTokens = config.connectingTokens
? config.connectingTokens.map(
(connectingToken) => connectingToken.address
)
: [];
// Here we add all linear pools, take note of phantom pools,
// add LBP pools with tokenIn or tokenOut and their corresponding
// highest liquidity WETH connections
Expand All @@ -194,73 +207,34 @@ export function getBoostedGraph(
if (tokensList.includes(pool.address)) {
phantomPools.push(pool);
}
if (config.lbpRaisingTokens) {
const raisingTokens = config.lbpRaisingTokens.map((address) =>
address.toLowerCase()
if (config.lbpRaisingTokens && pool.isLBP) {
handleLBPCase(
graphPoolsSet,
config.lbpRaisingTokens,
pool,
tokenIn,
tokenOut,
connectingTokens,
poolsAllDict
);
if (pool.isLBP) {
const raisingTokenIn: string | undefined = getRaisingToken(
pool,
raisingTokens,
tokenIn
);
if (raisingTokenIn) {
graphPoolsSet.add(pool);
if (raisingTokenIn !== wethAddress) {
const bestRaisingTokenInToWeth =
getHighestLiquidityPool(
raisingTokenIn,
wethAddress,
poolsAllDict
);
if (bestRaisingTokenInToWeth) {
graphPoolsSet.add(
poolsAllDict[bestRaisingTokenInToWeth]
);
}
}
}
const raisingTokenOut: string | undefined = getRaisingToken(
pool,
raisingTokens,
tokenOut
);
if (raisingTokenOut) {
graphPoolsSet.add(pool);
if (raisingTokenOut !== wethAddress) {
const bestWethToRaisingTokenOut =
getHighestLiquidityPool(
wethAddress,
raisingTokenOut,
poolsAllDict
);
if (bestWethToRaisingTokenOut) {
graphPoolsSet.add(
poolsAllDict[bestWethToRaisingTokenOut]
);
}
}
}
}
}
}
}
// add highest liquidity pools with tokenIn and weth or tokenOut and weth
const bestTokenInToWeth = getHighestLiquidityPool(
tokenIn,
wethAddress,
poolsAllDict
);
if (bestTokenInToWeth) {
graphPoolsSet.add(poolsAllDict[bestTokenInToWeth]);
}
const bestWethToTokenOut = getHighestLiquidityPool(
wethAddress,
tokenOut,
poolsAllDict
);
if (bestWethToTokenOut) {
graphPoolsSet.add(poolsAllDict[bestWethToTokenOut]);
// add best pools tokenIn -> connectingToken and connectingToken -> tokenOut
// these can be part of a longer path so do not rely on being directly connected
for (const connectingToken of connectingTokens) {
addMostLiquidPoolToSet(
tokenIn,
connectingToken,
poolsAllDict,
graphPoolsSet
);
addMostLiquidPoolToSet(
connectingToken,
tokenOut,
poolsAllDict,
graphPoolsSet
);
}
if (linearPools.length == 0) return {};
const linearPoolsAddresses = linearPools.map((pool) => pool.address);
Expand Down Expand Up @@ -294,10 +268,6 @@ export function getBoostedGraph(
return edgeDict;
}

interface edgeDict {
[node: string]: [string, string, string][];
}

function getNodesAndEdges(pools: PoolBase[]): edgeDict {
const edgesFromNode: edgeDict = {};
for (const pool of pools) {
Expand All @@ -319,12 +289,6 @@ function getNodesAndEdges(pools: PoolBase[]): edgeDict {
return edgesFromNode;
}

interface treeEdge {
edge: [string, string, string];
parentIndices: [number, number];
visitedNodes: string[];
}

export function getBoostedPaths(
tokenIn: string,
tokenOut: string,
Expand Down Expand Up @@ -645,3 +609,68 @@ function getRaisingToken(
}
return theOtherToken;
}

function handleLBPCase(
graphPoolsSet: Set<PoolBase>,
lbpRaisingTokens: string[],
poolLbp: PoolBase,
tokenIn: string,
tokenOut: string,
connectingTokens: string[],
poolsAllDict: PoolDictionary
) {
// Tokens that will be used as LBP Base Token, e.g. USDC/DAI/WETH
const raisingTokens = lbpRaisingTokens.map((address) =>
address.toLowerCase()
);

if (raisingTokens.length === 0) return;

// Assuming tokenIn is the lbpToken find the corresponding base token if it exists
const raisingTokenIn: string | undefined = getRaisingToken(
poolLbp,
raisingTokens,
tokenIn
);
const raisingTokenOut: string | undefined = getRaisingToken(
poolLbp,
raisingTokens,
tokenOut
);
if (!raisingTokenIn && !raisingTokenOut) return;

// Add the LBP pool to the graph
graphPoolsSet.add(poolLbp);

// For each connecting token add most liquid pools with raisingToken and raisingTokenOut
for (const connectingToken of connectingTokens) {
if (raisingTokenIn && raisingTokenIn !== connectingToken) {
// raisingToken>[Pool]>connectingToken
addMostLiquidPoolToSet(
raisingTokenIn,
connectingToken,
poolsAllDict,
graphPoolsSet
);
}
if (raisingTokenOut && raisingTokenOut !== connectingToken) {
// connectingToken>[Pool]>raisingToken
addMostLiquidPoolToSet(
connectingToken,
raisingTokenOut,
poolsAllDict,
graphPoolsSet
);
}
}
}

function addMostLiquidPoolToSet(
tokenIn: string,
tokenOut: string,
pools: PoolDictionary,
graphPools: Set<PoolBase>
): void {
const pool = getHighestLiquidityPool(tokenIn, tokenOut, pools);
if (pool) graphPools.add(pools[pool]);
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface SorConfig {
chainId: number;
vault: string;
weth: string;
connectingTokens?: { symbol: string; address: string }[];
staBal3Pool?: { id: string; address: string };
usdcConnectingPool?: { id: string; usdc: string };
wETHwstETH?: { id: string; address: string };
Expand Down
Loading