{"_id":"@bluedex/smart-order-router","name":"@bluedex/smart-order-router","dist-tags":{"latest":"3.6.1-alpha.1"},"versions":{"3.6.1-alpha.1":{"name":"@bluedex/smart-order-router","publishConfig":{"access":"public"},"version":"3.6.1-alpha.1","description":"Bluedex Smart Order Router","main":"build/main/index.js","typings":"build/main/index.d.ts","module":"build/module/index.js","repository":{"type":"git","url":"git+https://github.com/Bluecore-Dex/smart-order-router.git"},"license":"GPL","keywords":[],"scripts":{"compile-v3-core-types":"npx typechain --target ethers-v5 --out-dir src/types/v3 './node_modules/@bluedex/v3-core/artifacts/contracts/**/*.json'","compile-v3-periphery-types":"npx typechain --target ethers-v5 --out-dir src/types/v3 './node_modules/@bluedex/v3-periphery/artifacts/contracts/**/*.json'","compile-v2-core-types":"npx typechain --target ethers-v5 --out-dir src/types/v2 './node_modules/@bluedex/v2-protocol/artifacts/contracts/v2-contracts/v2-core/**/*.json'","compile-v2-periphery-types":"npx typechain --target ethers-v5 --out-dir src/types/v2 './node_modules/@bluedex/v2-protocol/artifacts/contracts/v2-contracts/v2-periphery/**/*.json'","compile-router":"npx typechain --target ethers-v5 --out-dir src/types/other './node_modules/@bluedex/swap-router-contracts/artifacts/contracts/**/*.json'","compile-external-types":"npx typechain --target ethers-v5 --out-dir src/types/other 'src/abis/**/*.json'","build":"run-p compile-v3-core-types compile-v3-periphery-types compile-v2-core-types compile-v2-periphery-types compile-router compile-external-types && run-p build:*","build:main":"tsc -p tsconfig.json","build:module":"tsc -p tsconfig.module.json","fix":"run-s fix:*","fix:prettier":"prettier \"src/**/*.ts\" --write","fix:lint":"eslint src --ext .ts --fix","prepare-release":"run-s cov:check doc:html version doc:publish","test":"jest test/unit","integ-test":"TS_NODE=true jest test/integ"},"engines":{"node":">=10"},"dependencies":{"@bluedex/default-token-list":"^11.17.0","@bluedex/permit2-sdk":"^1.2.0","@bluedex/router-sdk":"^1.4.0-alpha.1","@bluedex/swap-router-contracts":"^1.3.9","@bluedex/token-lists":"^1.0.0-beta.31","@bluedex/universal-router":"^1.1.0","@bluedex/universal-router-sdk":"^1.3.9-alpha.1","@bluedex/v2-sdk":"^3.0.1-alpha.2","@bluedex/v3-sdk":"^3.9.0-alpha.1","async-retry":"^1.3.1","await-timeout":"^1.1.1","axios":"^0.21.1","bunyan":"^1.8.15","bunyan-blackhole":"^1.1.1","ethers":"^5.7.2","graphql":"^15.5.0","graphql-request":"^3.4.0","lodash":"^4.17.21","mnemonist":"^0.38.3","node-cache":"^5.1.2","stats-lite":"^2.2.0"},"devDependencies":{"@bluedex/v2-protocol":"^1.0.4","@bluedex/v3-core":"^1.0.4","@bluedex/v3-periphery":"^1.5.4","@ethersproject/providers":"^5.4.0","@istanbuljs/nyc-config-typescript":"^1.0.1","@nomiclabs/hardhat-ethers":"^2.0.6","@oclif/command":"^1.8.0","@oclif/errors":"^1.3.5","@typechain/ethers-v5":"^7.0.1","@types/async-retry":"^1.4.4","@types/await-timeout":"^0.3.1","@types/bunyan":"^1.8.6","@types/bunyan-blackhole":"^0.2.2","@types/jest":"^27.0.0","@types/jest-sinon":"^1.0.2","@types/lodash":"^4.14.168","@types/node":"^15.0.2","@types/sinon":"^10.0.2","@types/stats-lite":"^2.2.0","@typescript-eslint/eslint-plugin":"^4.0.1","@typescript-eslint/parser":"^4.0.1","bunyan-debug-stream":"^2.0.0","dotenv":"^10.0.0","eslint":"^7.8.0","eslint-config-prettier":"^6.11.0","eslint-plugin-eslint-comments":"^3.2.0","eslint-plugin-import":"^2.22.0","hardhat":"^2.12.2","jest":"^27.0.6","jest-environment-hardhat":"^1.1.8","jest-expect-message":"^1.0.2","jest-mock":"^27.0.6","jest-sinon":"^1.0.4","npm-run-all":"^4.1.5","open-cli":"^6.0.1","prettier":"^2.1.1","prettier-plugin-organize-imports":"^2.1.0","sinon":"^11.1.2","ts-jest":"^27.0.4","ts-node":"^10.8.1","typechain":"^5.0.0","typescript":"^4.2.2"},"peerDependencies":{"jsbi":"^3.2.0"},"prettier":{"singleQuote":true},"oclif":{"commands":"./cli/commands"},"_id":"@bluedex/smart-order-router@3.6.1-alpha.1","gitHead":"fbfea025a6f8c297f8684a895ba26ef0d7f55f50","bugs":{"url":"https://github.com/Bluecore-Dex/smart-order-router/issues"},"homepage":"https://github.com/Bluecore-Dex/smart-order-router#readme","_nodeVersion":"18.19.0","_npmVersion":"10.8.1","dist":{"integrity":"sha512-kG/vDLYXThbnD5BtsVdhD6yVt2KfZieqM4FNcandulgbvsZ+KFtdp/6XBRfR5F16jGagy0dBUy/4Jxc5gLsDlA==","shasum":"10e4dea6c6f4235cea7f0f27b5aea54350769212","tarball":"https://registry.npmjs.org/@bluedex/smart-order-router/-/smart-order-router-3.6.1-alpha.1.tgz","fileCount":378,"unpackedSize":2985450,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD7xezetf48ZPZ40MJhAwf9oqVCkCuGA9tEP/0QDha+sAIgf9TbDgTox4+jxWW4XbRWUvlYdywkMqsFnrAT2A4QQ3E="}]},"_npmUser":{"name":"afzalkhan","email":"afjal.khan@speqto.com"},"directories":{},"maintainers":[{"name":"afzalkhan","email":"afjal.khan@speqto.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/smart-order-router_3.6.1-alpha.1_1718803830020_0.7703627569170937"},"_hasShrinkwrap":false}},"time":{"created":"2024-06-19T13:30:29.939Z","3.6.1-alpha.1":"2024-06-19T13:30:30.325Z","modified":"2024-06-19T13:30:30.663Z"},"maintainers":[{"name":"afzalkhan","email":"afjal.khan@speqto.com"}],"description":"Bluedex Smart Order Router","homepage":"https://github.com/Bluecore-Dex/smart-order-router#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/Bluecore-Dex/smart-order-router.git"},"bugs":{"url":"https://github.com/Bluecore-Dex/smart-order-router/issues"},"license":"GPL","readme":"# Uniswap Smart Order Router\r\n\r\nThis repository contains routing logic for the Uniswap V3 protocol.\r\n\r\nIt searches for the most efficient way to swap token A for token B, considering splitting swaps across multiple routes and gas costs.\r\n\r\n## Testing\r\n\r\n### Unit Tests\r\n\r\nFirst make sure you have run `npm install` and `npm run build`.\r\n\r\n```\r\nnpm run test\r\n```\r\n\r\n### Integration Tests\r\n\r\nMake sure the `.env` file is configured to connect to mainnet and other chains. See the [CLI](#cli) section below for more details.\r\n\r\n```\r\nnpm run integ-test\r\n```\r\n\r\n### Tenderly Simulations\r\n\r\nQuotes can be simulated on Tenderly\r\n\r\nEnsure you set the following environment variables:\r\n\r\n```\r\nprocess.env.TENDERLY_BASE_URL!,\r\nprocess.env.TENDERLY_USER!,\r\nprocess.env.TENDERLY_PROJECT!,\r\nprocess.env.TENDERLY_ACCESS_KEY!,\r\n```\r\n\r\n### CLI\r\n\r\nThe package can be run as a CLI for testing purposes.\r\n\r\nFirst create a `.env` file in the root of the project and configure:\r\n\r\n```\r\nJSON_RPC_PROVIDER = '<JSON_RPC_PROVIDER>'\r\n```\r\n\r\nTo run on chains other than mainnet set up a connection by specifying the environment variable\r\n\r\n```\r\nJSON_RPC_PROVIDER_ROPSTEN = '<JSON_RPC_PROVIDER>'\r\nJSON_RPC_PROVIDER_RINKEBY = '<JSON_RPC_PROVIDER>'\r\nJSON_RPC_PROVIDER_GORLI = '<JSON_RPC_PROVIDER>'\r\nJSON_RPC_PROVIDER_KOVAN = '<JSON_RPC_PROVIDER>'\r\nJSON_RPC_PROVIDER_OPTIMISM = '<JSON_RPC_PROVIDER>'\r\nJSON_RPC_PROVIDER_OPTIMISM_GOERLI = '<JSON_RPC_PROVIDER>'\r\nJSON_RPC_PROVIDER_OPTIMISTIC_KOVAN = '<JSON_RPC_PROVIDER>'\r\nJSON_RPC_PROVIDER_ARBITRUM_ONE = '<JSON_RPC_PROVIDER>'\r\nJSON_RPC_PROVIDER_ARBITRUM_RINKEBY = '<JSON_RPC_PROVIDER>'\r\nJSON_RPC_PROVIDER_ARBITRUM_GOERLI = '<JSON_RPC_PROVIDER>'\r\nJSON_RPC_PROVIDER_POLYGON = '<JSON_RPC_PROVIDER>'\r\nJSON_RPC_PROVIDER_POLYGON_MUMBAI = '<JSON_RPC_PROVIDER>'\r\nJSON_RPC_PROVIDER_CELO = '<JSON_RPC_PROVIDER>'\r\nJSON_RPC_PROVIDER_CELO_ALFAJORES = '<JSON_RPC_PROVIDER>'\r\nJSON_RPC_PROVIDER_BSC = '<JSON_RPC_PROVIDER>'\r\n```\r\n\r\nThen from the root directory you can execute the CLI.\r\n\r\n## Examples\r\n\r\nSome examples to use for manual CLI testing.\r\n\r\n### Mainnet\r\n\r\n```\r\n./bin/cli quote --tokenIn 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 --tokenOut 0x1f9840a85d5af5bf1d1762f925bdaddc4201f984 --amount 1000 --exactIn --recipient 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B --protocols v2,v3\r\n\r\nBest Route:\r\n100.00% = USDC -- 0.3% --> UNI\r\n\tRaw Quote Out:\r\n\t\t35.72\r\n\tGas Adjusted Quote Out:\r\n\t\t34.03\r\n\r\nGas Used Quote Token: 1.691772\r\nGas Used USD: 47.592951\r\nCalldata: 0x414bf389000000000000...\r\nValue: 0x00\r\n\r\n  blockNumber: \"13088815\"\r\n  estimatedGasUsed: \"113000\"\r\n  gasPriceWei: \"130000000000\"\r\n\r\n\r\n./bin/cli quote-to-ratio --token0 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 --token1 0xdac17f958d2ee523a2206206994597c13d831ec7 --feeAmount 3000 --recipient 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B  --token0Balance 1000 --token1Balance 2000 --tickLower -120 --tickUpper 120\r\n\r\nBest Route:\r\n100.00% = USDT -- 0.05% --> USDC\r\nRaw Quote Exact In:\r\n\t392.68\r\nGas Adjusted Quote In}:\r\n\t346.13\r\n\r\nGas Used Quote Token: 46.550010\r\nGas Used USD: 46.342899\r\nCalldata: 0x414bf389000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000ab5801a7d398351b8be11c439e05c5b3259aec9b000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000176a736c000000000000000000000000000000000000000000000000000000001764f8650000000000000000000000000000000000000000000000000000000000000000\r\n\tValue: 0x00\r\n\r\n\tblockNumber: \"13239188\"\r\n\testimatedGasUsed: \"113000\"\r\n\tgasPriceWei: \"116690684398\"\r\n\r\n./bin/cli quote --tokenIn 0x0391D2021f89DC339F60Fff84546EA23E337750f --tokenOut 0x4d224452801ACEd8B2F0aebE155379bb5D594381 --amount 10000 --exactIn --recipient 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B --protocols v2,v3,mixed\r\nBest Route:\r\n[V2 + V3] 100.00% = BOND -- [0x6591c4BcD6D7A1eb4E537DA8B78676C1576Ba244] --> USDC -- 0.3% [0xB07Fe2F407F971125D4EB1977f8aCEe8846C7324] --> APE\r\n\tRaw Quote Exact In:\r\n\t\t10437.85\r\n\tGas Adjusted Quote In:\r\n\t\t10433.83\r\n\r\nGas Used Quote Token: 4.018625\r\nGas Used USD: 29.669402\r\nCalldata: 0x5ae401dc0000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e4472b43f300000000000000000000000000000000000000000000021e19e0c9bab240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000391d2021f89dc339f60fff84546ea23e337750f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000104b858183f00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000080000000000000000000000000ab5801a7d398351b8be11c439e05c5b3259aec9b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002358df5b3b4459a3f5b000000000000000000000000000000000000000000000000000000000000002ba0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000bb84d224452801aced8b2f0aebe155379bb5d59438100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\nValue: 0x00\r\n\r\n  blockNumber: \"15303839\"\r\n  estimatedGasUsed: \"434000\"\r\n  gasPriceWei: \"38218865879\"\r\nTotal ticks crossed: 7\r\n```\r\n\r\n## Rinkeby\r\n\r\n```\r\n./bin/cli quote --tokenIn 0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea --tokenOut 0x4DBCdF9B62e891a7cec5A2568C3F4FAF9E8Abe2b --amount 200000 --exactIn --minSplits 1 --router alpha --chainId 4\r\n```\r\n\r\n## Kovan\r\n\r\n```\r\n./bin/cli quote --tokenIn 0x4f96fe3b7a6cf9725f59d353f723c1bdb64ca6aa --tokenOut 0xd0a1e359811322d97991e03f863a0c30c2cf029c --amount 10 --exactIn --minSplits 1 --router alpha --chainId 42\r\n```\r\n\r\n## Ropsten\r\n\r\n```\r\n./bin/cli quote --tokenIn 0x07865c6e87b9f70255377e024ace6630c1eaa37f --tokenOut 0xc778417e063141139fce010982780140aa0cd5ab --amount 200000 --exactIn --minSplits 1 --router alpha --chainId 3\r\n```\r\n\r\n## Optimism\r\n\r\n```\r\n./bin/cli quote --tokenIn 0x7F5c764cBc14f9669B88837ca1490cCa17c31607 --tokenOut 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1 --amount 200000 --exactIn --minSplits 1 --router alpha --chainId 10\r\n\r\n```\r\n\r\n## Optimism-Goerli\r\n\r\n```\r\n./bin/cli quote --tokenIn 0x7E07E15D2a87A24492740D16f5bdF58c16db0c4E --tokenOut 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1 --amount 200000 --exactIn --minSplits 1 --router alpha --chainId 420\r\n```\r\n\r\n## Optimistic-Kovan\r\n\r\n```\r\n./bin/cli quote --tokenIn 0x7F5c764cBc14f9669B88837ca1490cCa17c31607 --tokenOut 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1 --amount 200 --exactIn --minSplits 1 --router alpha --chainId 69\r\n```\r\n\r\n## Arbitrum\r\n\r\n```\r\n./bin/cli quote --tokenIn 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9 --tokenOut 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 --amount 20000 --exactIn --minSplits 1 --router alpha --chainId 42161 --debug\r\n```\r\n\r\n## Arbitrum-Rinkeby\r\n\r\n```\r\n./bin/cli quote --tokenIn 0x09b98f8b2395d076514037ff7d39a091a536206c --tokenOut 0xb47e6a5f8b33b3f17603c83a0535a9dcd7e32681 --amount 200 --exactIn --minSplits 1 --router alpha --chainId 421611\r\n```\r\n\r\n## Arbitrum-Goerli\r\n\r\n```\r\n./bin/cli quote --tokenIn 0xe39ab88f8a4777030a534146a9ca3b52bd5d43a3 --tokenOut 0x8FB1E3fC51F3b789dED7557E680551d93Ea9d892 --amount 200 --exactIn --minSplits 1 --router alpha --chainId 421613\r\n```\r\n\r\n## Polygon Mumbai\r\n\r\n```\r\n./bin/cli quote --tokenIn 0x001b3b4d0f3714ca98ba10f6042daebf0b1b7b6f --tokenOut 0x9c3c9283d3e44854697cd22d3faa240cfb032889 --amount 1 --exactIn --protocols v3 --recipient 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B --minSplits 1 --router alpha --chainId 80001\r\n```\r\n\r\n## Polygon Mainnet\r\n\r\n```\r\n./bin/cli quote --tokenIn 0x2791bca1f2de4661ed88a30c99a7a9449aa84174 --tokenOut 0x7ceb23fd6bc0add59e62ac25578270cff1b9f619 --amount 5 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 137\r\n```\r\n\r\n## Celo Mainnet\r\n\r\n```\r\n./bin/cli quote --tokenIn CELO --tokenOut 0x765DE816845861e75A25fCA122bb6898B8B1282a --amount 5 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 42220\r\n```\r\n\r\n## BSC Mainnet\r\n\r\n```\r\n./bin/cli quote --tokenIn 0x55d398326f99059fF775485246999027B3197955 --tokenOut 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d --amount 1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 56\r\n```\r\n\r\n## Adding a new Chain\r\n\r\nThe main components to complete are:\r\n\r\n- Deploy contracts on chain, add the pools to subgraph\r\n- Populate v3 providers in `src/providers/v3/subgraph-provider` and `src/providers/v3/static-subgraph-provider`\r\n- Populate chainId and addresses in `src/util/chains.ts` and `src/util/addresses.ts`\r\n- Populate token providers in `src/providers/caching-token-provider` and `src/providers/token-provider.ts`\r\n- Populate gas constants in `src/routers/alpha-router/gas-models/*`\r\n- Populate bases in `src/routers/legacy-router/bases.ts`\r\n- Populate `test/integ/routers/alpha-router/alpha-router.integration.test.ts` and `src/providers/v2/static-subgraph-provider.ts`\r\n- Populate `src/routers/alpha-router/*`\r\n- Add a log to `/CHANGELOG.md`\r\n- Run `npm run integ-test` successfully\r\n\r\n# Troubleshooting\r\n\r\n## ProviderGasLimit errors\r\n\r\nThe package sends many large multicall requests to nodes. You must ensure that your node provider's `eth_call` gas limit is high enough to succesfully process the RPC calls.\r\n\r\nBy default each `eth_call` will consume up to:\r\n\r\n- 132,000,000 gas on Optimism\r\n- 120,000,000 gas on Arbitrum\r\n- 50,000,000 gas on Celo\r\n- 150,000,000 gas on every other network (Mainnet, Goerli, etc.)\r\n\r\nThese parameters should work on Infura and Alchemy by default.\r\n\r\nThis total amount of gas each `eth_call` can consume is equal to the `multicallChunk` config value multiplied by the `gasLimitPerCall` config value. If you are using a node provider with a lower gas limit per `eth_call` you will need to override the default `V3QuoteProvider` with an instance that lowers the `multicallChunk` and `gasLimitPerCall` parameters such that the multiplication is below your node providers limit. Lowering these values will cause each multicall to consume less gas. See [here](https://github.com/Uniswap/smart-order-router/blob/98c58bdee9981fd9ffac9e7d7a97b18302d5f77a/src/routers/alpha-router/alpha-router.ts#L415-L416) for examples of how to set these values. Note some providers have different limits per chain.\r\n\r\nIf you are running your own node, we recommend you configure start your node with a higher gas limit per call. For example, on Geth you can use the command line argument `--rpc.gascap 150000000` to raise the limit to 150m, which is enough to run the default configuration of this package.\r\n\r\nIf you are using Hardhat mainnet forking, you should add `blockGasLimit: 150_000_000` to your Hardhat config to use the default package configuration.\r\n","readmeFilename":"README.md"}