Coder Social home page Coder Social logo

balancer-sor's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

balancer-sor's Issues

SOR cannot find pool ID

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:

Use bignumber.js

Move all calculations to use bignumbers to prevent javascript math craziness

Handle unknown pool types gracefully

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.

getSwaps() returnAmount mismatch with on-chain result

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!

Question: when will this be done on-chain

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?

Pushing to NPM

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.

Swap Limit Error

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)

gas inputs as params

gasPrice, gasPerTrade, outTokenEthPrice are currently hardcoded

these should be passed into linearizedSolution as parameters

Supporting Uniswap V3

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.

fetchPools() issue with Polygon Mainnet

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)

command line test

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.