balancer / balancer-sor Goto Github PK
View Code? Open in Web Editor NEWSmart order router: off-chain linear optimization of routing orders across pools for best price execution
Smart order router: off-chain linear optimization of routing orders across pools for best price execution
When trying to use sor.smartOrderRouter
, it mis-computes the pool ID and fails.
Error log:
TypeError: Cannot read property 'spotPrice' of undefined
at /Users/xianny/src/balancer/node_modules/@balancer-labs/sor/dist/sor.js:250:58
at Array.forEach (<anonymous>)
at getInputAmountsForEp (/Users/xianny/src/balancer/node_modules/@balancer-labs/sor/dist/sor.js:246:10)
at /Users/xianny/src/balancer/node_modules/@balancer-labs/sor/dist/sor.js:22:21
at Array.forEach (<anonymous>)
at Object.exports.smartOrderRouter (/Users/xianny/src/balancer/node_modules/@balancer-labs/sor/dist/sor.js:19:19)
at sor.getPoolsWithTokens.then.data (/Users/xianny/src/balancer/test.js:14:26)
at process._tickCallback (internal/process/next_tick.js:68:7)
Code lifted from https://docs.balancer.finance/sor/development#example
// test.js
// dependencies": {
// "@balancer-labs/sor": "^0.2.7",
// "bignumber.js": "^9.0.0",
// "ethers": "^4.0.47"
// }
const sor = require('@balancer-labs/sor');
const BigNumber = require('bignumber.js');
const ethers = require('ethers');
const MAX_UINT = ethers.constants.MaxUint256;
// MAINNET
const tokenIn = '0x6B175474E89094C44Da98b954EedeAC495271d0F' // DAI
const tokenOut = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' // WETH
sor.getPoolsWithTokens(tokenIn, tokenOut).then(data => {
const poolData = sor.parsePoolData(data.pools, tokenIn, tokenOut);
const sorSwaps = sor.smartOrderRouter(
poolData,
'swapExactIn',
new BigNumber('10000000000000000000'),
new BigNumber('10'),
0
);
});
Error is being thrown when this line returns balancer = undefined
:
Move all calculations to use bignumbers to prevent javascript math craziness
SOR pool fetching has started throwing errors the last few days since the pool type HighAmpComposableStable
was added to the graph. Some errors from the API fetching pools from our main subgraph:
ERROR Unknown pool type: HighAmpComposableStable 0xea912e1afa137c15f1638142e32f978e92fbce390000000000000000000003b4
ERROR Unknown pool type: HighAmpComposableStable 0x1d1b44a4c5a047bdc9b3f06842566e5ea9c1966d0000000000000000000003b3
This is also currently happening on the Balancer App Frontend.
https://github.com/balancer-labs/balancer-sor/pull/304/ has been done to fix this error. But the bigger issue is that SOR should be able to gracefully handle new pool types and just ignore them instead of crashing, so that older versions of SOR don't break whenever we add a new pool type.
This issue is to create a test to reproduce error'ing with a pool with an unknown type and a fix for that test so it ignores the pool instead of crashing.
I recently updated from balancer-sor 2.0.0-beta.0 to 4.0.1-beta.13 to get off-chain quote. It used to work properly(matched on/off chain quote) before the update, and no logic has been changed apart from the upgrade. Followings are the code that I am using to call getSwap() function and error examples.
const swapInfo = await sor.getSwaps(token0Address, token1Address, SwapTypes.SwapExactIn, swapAmount, { gasPrice: BigNumber.from('40000000000'), maxPools: 4, poolTypeFilter: PoolFilter.All, forceRefresh: false, });
{ "poolId": "0x2f4eb100552ef93840d5adc30560e5513dfffacb000000000000000000000334", "failMessage": "should swap 1.0 USDT for bb-a-USDT", "errorMessage": "[BalancerV2-bb-a-USDT-USDT-0x2f4eb100552ef93840d5adc30560e5513dfffacb000000000000000000000334] expected: 0.996741477812543832 bb-a-USDT - actual: 0.996741471157526565 bb-a-USDT - error: -0.000000006655017267 bb-a-USDT: Expected \"996741471157526565\" to be equal 996741477812543832" }, { "poolId": "0x25accb7943fd73dda5e23ba6329085a3c24bfb6a000200000000000000000387", "failMessage": "should swap 1.0 wstETH for bb-a-USD", "errorMessage": "[BalancerV2-wstETH-bb-a-USD-0x25accb7943fd73dda5e23ba6329085a3c24bfb6a000200000000000000000387] expected: 1258.805945837242429336 bb-a-USD - actual: 1258.805945977795458677 bb-a-USD - error: 0.000000140553029341 bb-a-USD: Expected \"1258805945977795458677\" to be equal 1258805945837242429336" },
Would be much appreciative if the team can provide some suspicious point that I can take a look.
Thank you in advance!
Hey I am a bit confused about how smart order routing currently works. This repo seems to suggest this is done off chain. Do you guys know when Balancer v2 will do this order routing on chain?
Is there a reason this isn't pushed to npm? Or if it is, it isn't published under @balancer-labs. I'd like to use the latest version that follows the example code but unless I'm building it inside my project, seems to be unavailable.
Instead of throwing an error "Swap amount exceeds the pool limit" - exclude the pool from the pool from the path building. (and maybe log an error, so we know about it with a poolId)
According to what I understand for swapExactOut
in the function getCostOutputToken
we need to pass tokenIn
. If so there is a typo in the below code. It should be USDC
instead of DAI
Use a variety of sample pool data and compare to python SOR results
gasPrice, gasPerTrade, outTokenEthPrice are currently hardcoded
these should be passed into linearizedSolution as parameters
I've figured out how to represent Uniswap V2 and Curve pools as Balancer pools. How would I got about implementing a Uniswap V3 pool within SOR? Let's assume I can perform the swap estimations synchronously/offchain.
Hi,
Ethereum works great, but Polygon gives the following error when calling fetchPools().
Does anyone know how to make it work with Polygon as well?
2023-07-10 02:16:21 calling swaps.fetchPools()
2023-07-10 02:16:21 137 fetching pools...
Error: fetchPools(): Error: Issue with pool onchain data: Error: invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.7.0)
SOR needs to account for MIN_BALANCE
, MAX_BALANCE
, MAX_IN_RATIO
, MAX_OUT_RATIO
In this repository, I am getting whole code execution regardless What I command I am typing
What if I want to run specific file or function ...
whatever command I run it is running this line..
@balancer-labs/[email protected] test
TS_NODE_PROJECT='tsconfig.testing.json' nyc mocha -r ts-node/register test/*.spec.ts --timeout 20000
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.