@xspswap/smart-order-router 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +255 -0
- package/LICENSE +674 -0
- package/README.md +189 -0
- package/build/main/index.d.ts +3 -0
- package/build/main/index.js +20 -0
- package/build/main/providers/cache-node.d.ts +9 -0
- package/build/main/providers/cache-node.js +19 -0
- package/build/main/providers/cache.d.ts +13 -0
- package/build/main/providers/cache.js +3 -0
- package/build/main/providers/caching/route/index.d.ts +2 -0
- package/build/main/providers/caching/route/index.js +19 -0
- package/build/main/providers/caching/route/model/cache-mode.d.ts +16 -0
- package/build/main/providers/caching/route/model/cache-mode.js +21 -0
- package/build/main/providers/caching/route/model/cached-route.d.ts +23 -0
- package/build/main/providers/caching/route/model/cached-route.js +24 -0
- package/build/main/providers/caching/route/model/cached-routes.d.ts +63 -0
- package/build/main/providers/caching/route/model/cached-routes.js +73 -0
- package/build/main/providers/caching/route/model/index.d.ts +3 -0
- package/build/main/providers/caching/route/model/index.js +20 -0
- package/build/main/providers/caching/route/route-caching-provider.d.ts +91 -0
- package/build/main/providers/caching/route/route-caching-provider.js +65 -0
- package/build/main/providers/caching-gas-provider.d.ts +23 -0
- package/build/main/providers/caching-gas-provider.js +37 -0
- package/build/main/providers/caching-token-list-provider.d.ts +40 -0
- package/build/main/providers/caching-token-list-provider.js +123 -0
- package/build/main/providers/caching-token-provider.d.ts +25 -0
- package/build/main/providers/caching-token-provider.js +113 -0
- package/build/main/providers/eip-1559-gas-price-provider.d.ts +31 -0
- package/build/main/providers/eip-1559-gas-price-provider.js +66 -0
- package/build/main/providers/eth-estimate-gas-provider.d.ts +14 -0
- package/build/main/providers/eth-estimate-gas-provider.js +72 -0
- package/build/main/providers/eth-gas-station-info-gas-price-provider.d.ts +19 -0
- package/build/main/providers/eth-gas-station-info-gas-price-provider.js +37 -0
- package/build/main/providers/gas-price-provider.d.ts +10 -0
- package/build/main/providers/gas-price-provider.js +10 -0
- package/build/main/providers/index.d.ts +37 -0
- package/build/main/providers/index.js +54 -0
- package/build/main/providers/legacy-gas-price-provider.d.ts +7 -0
- package/build/main/providers/legacy-gas-price-provider.js +20 -0
- package/build/main/providers/multicall-provider.d.ts +82 -0
- package/build/main/providers/multicall-provider.js +15 -0
- package/build/main/providers/multicall-uniswap-provider.d.ts +37 -0
- package/build/main/providers/multicall-uniswap-provider.js +163 -0
- package/build/main/providers/on-chain-gas-price-provider.d.ts +19 -0
- package/build/main/providers/on-chain-gas-price-provider.js +33 -0
- package/build/main/providers/on-chain-quote-provider.d.ts +221 -0
- package/build/main/providers/on-chain-quote-provider.js +511 -0
- package/build/main/providers/provider.d.ts +10 -0
- package/build/main/providers/provider.js +3 -0
- package/build/main/providers/simulation-provider.d.ts +42 -0
- package/build/main/providers/simulation-provider.js +130 -0
- package/build/main/providers/static-gas-price-provider.d.ts +7 -0
- package/build/main/providers/static-gas-price-provider.js +13 -0
- package/build/main/providers/swap-router-provider.d.ts +31 -0
- package/build/main/providers/swap-router-provider.js +42 -0
- package/build/main/providers/tenderly-simulation-provider.d.ts +43 -0
- package/build/main/providers/tenderly-simulation-provider.js +244 -0
- package/build/main/providers/token-provider.d.ts +45 -0
- package/build/main/providers/token-provider.js +121 -0
- package/build/main/providers/token-validator-provider.d.ts +42 -0
- package/build/main/providers/token-validator-provider.js +95 -0
- package/build/main/providers/uri-subgraph-provider.d.ts +20 -0
- package/build/main/providers/uri-subgraph-provider.js +65 -0
- package/build/main/providers/v2/caching-pool-provider.d.ts +34 -0
- package/build/main/providers/v2/caching-pool-provider.js +88 -0
- package/build/main/providers/v2/caching-subgraph-provider.d.ts +23 -0
- package/build/main/providers/v2/caching-subgraph-provider.js +34 -0
- package/build/main/providers/v2/pool-provider.d.ts +60 -0
- package/build/main/providers/v2/pool-provider.js +110 -0
- package/build/main/providers/v2/quote-provider.d.ts +33 -0
- package/build/main/providers/v2/quote-provider.js +91 -0
- package/build/main/providers/v2/static-subgraph-provider.d.ts +20 -0
- package/build/main/providers/v2/static-subgraph-provider.js +73 -0
- package/build/main/providers/v2/subgraph-provider-with-fallback.d.ts +19 -0
- package/build/main/providers/v2/subgraph-provider-with-fallback.js +35 -0
- package/build/main/providers/v2/subgraph-provider.d.ts +34 -0
- package/build/main/providers/v2/subgraph-provider.js +135 -0
- package/build/main/providers/v2/uri-subgraph-provider.d.ts +4 -0
- package/build/main/providers/v2/uri-subgraph-provider.js +8 -0
- package/build/main/providers/v3/caching-pool-provider.d.ts +33 -0
- package/build/main/providers/v3/caching-pool-provider.js +77 -0
- package/build/main/providers/v3/caching-subgraph-provider.d.ts +23 -0
- package/build/main/providers/v3/caching-subgraph-provider.js +34 -0
- package/build/main/providers/v3/gas-data-provider.d.ts +30 -0
- package/build/main/providers/v3/gas-data-provider.js +3 -0
- package/build/main/providers/v3/pool-provider.d.ts +61 -0
- package/build/main/providers/v3/pool-provider.js +125 -0
- package/build/main/providers/v3/static-subgraph-provider.d.ts +21 -0
- package/build/main/providers/v3/static-subgraph-provider.js +100 -0
- package/build/main/providers/v3/subgraph-provider-with-fallback.d.ts +15 -0
- package/build/main/providers/v3/subgraph-provider-with-fallback.js +31 -0
- package/build/main/providers/v3/subgraph-provider.d.ts +37 -0
- package/build/main/providers/v3/subgraph-provider.js +137 -0
- package/build/main/providers/v3/uri-subgraph-provider.d.ts +4 -0
- package/build/main/providers/v3/uri-subgraph-provider.js +8 -0
- package/build/main/routers/alpha-router/alpha-router.d.ts +267 -0
- package/build/main/routers/alpha-router/alpha-router.js +762 -0
- package/build/main/routers/alpha-router/config.d.ts +4 -0
- package/build/main/routers/alpha-router/config.js +61 -0
- package/build/main/routers/alpha-router/entities/index.d.ts +1 -0
- package/build/main/routers/alpha-router/entities/index.js +18 -0
- package/build/main/routers/alpha-router/entities/route-with-valid-quote.d.ts +163 -0
- package/build/main/routers/alpha-router/entities/route-with-valid-quote.js +143 -0
- package/build/main/routers/alpha-router/functions/best-swap-route.d.ts +19 -0
- package/build/main/routers/alpha-router/functions/best-swap-route.js +344 -0
- package/build/main/routers/alpha-router/functions/calculate-ratio-amount-in.d.ts +3 -0
- package/build/main/routers/alpha-router/functions/calculate-ratio-amount-in.js +18 -0
- package/build/main/routers/alpha-router/functions/compute-all-routes.d.ts +8 -0
- package/build/main/routers/alpha-router/functions/compute-all-routes.js +72 -0
- package/build/main/routers/alpha-router/functions/get-candidate-pools.d.ts +78 -0
- package/build/main/routers/alpha-router/functions/get-candidate-pools.js +704 -0
- package/build/main/routers/alpha-router/gas-models/gas-model.d.ts +83 -0
- package/build/main/routers/alpha-router/gas-models/gas-model.js +39 -0
- package/build/main/routers/alpha-router/gas-models/index.d.ts +2 -0
- package/build/main/routers/alpha-router/gas-models/index.js +19 -0
- package/build/main/routers/alpha-router/gas-models/mixedRoute/mixed-route-heuristic-gas-model.d.ts +25 -0
- package/build/main/routers/alpha-router/gas-models/mixedRoute/mixed-route-heuristic-gas-model.js +171 -0
- package/build/main/routers/alpha-router/gas-models/v2/v2-heuristic-gas-model.d.ts +29 -0
- package/build/main/routers/alpha-router/gas-models/v2/v2-heuristic-gas-model.js +167 -0
- package/build/main/routers/alpha-router/gas-models/v3/gas-costs.d.ts +6 -0
- package/build/main/routers/alpha-router/gas-models/v3/gas-costs.js +43 -0
- package/build/main/routers/alpha-router/gas-models/v3/v3-heuristic-gas-model.d.ts +25 -0
- package/build/main/routers/alpha-router/gas-models/v3/v3-heuristic-gas-model.js +223 -0
- package/build/main/routers/alpha-router/index.d.ts +4 -0
- package/build/main/routers/alpha-router/index.js +21 -0
- package/build/main/routers/alpha-router/quoters/base-quoter.d.ts +68 -0
- package/build/main/routers/alpha-router/quoters/base-quoter.js +61 -0
- package/build/main/routers/alpha-router/quoters/index.d.ts +5 -0
- package/build/main/routers/alpha-router/quoters/index.js +22 -0
- package/build/main/routers/alpha-router/quoters/mixed-quoter.d.ts +20 -0
- package/build/main/routers/alpha-router/quoters/mixed-quoter.js +130 -0
- package/build/main/routers/alpha-router/quoters/model/index.d.ts +1 -0
- package/build/main/routers/alpha-router/quoters/model/index.js +18 -0
- package/build/main/routers/alpha-router/quoters/model/results/get-quotes-result.d.ts +6 -0
- package/build/main/routers/alpha-router/quoters/model/results/get-quotes-result.js +3 -0
- package/build/main/routers/alpha-router/quoters/model/results/get-routes-result.d.ts +6 -0
- package/build/main/routers/alpha-router/quoters/model/results/get-routes-result.js +3 -0
- package/build/main/routers/alpha-router/quoters/model/results/index.d.ts +2 -0
- package/build/main/routers/alpha-router/quoters/model/results/index.js +19 -0
- package/build/main/routers/alpha-router/quoters/v2-quoter.d.ts +21 -0
- package/build/main/routers/alpha-router/quoters/v2-quoter.js +122 -0
- package/build/main/routers/alpha-router/quoters/v3-quoter.d.ts +19 -0
- package/build/main/routers/alpha-router/quoters/v3-quoter.js +125 -0
- package/build/main/routers/index.d.ts +4 -0
- package/build/main/routers/index.js +21 -0
- package/build/main/routers/legacy-router/bases.d.ts +28 -0
- package/build/main/routers/legacy-router/bases.js +58 -0
- package/build/main/routers/legacy-router/index.d.ts +1 -0
- package/build/main/routers/legacy-router/index.js +18 -0
- package/build/main/routers/legacy-router/legacy-router.d.ts +42 -0
- package/build/main/routers/legacy-router/legacy-router.js +289 -0
- package/build/main/routers/router.d.ts +165 -0
- package/build/main/routers/router.js +52 -0
- package/build/main/tsconfig.tsbuildinfo +1 -0
- package/build/main/types/other/factories/Erc20__factory.d.ts +45 -0
- package/build/main/types/other/factories/Erc20__factory.js +240 -0
- package/build/main/types/other/factories/GasDataArbitrum__factory.d.ts +18 -0
- package/build/main/types/other/factories/GasDataArbitrum__factory.js +58 -0
- package/build/main/types/other/factories/GasPriceOracle__factory.d.ts +46 -0
- package/build/main/types/other/factories/GasPriceOracle__factory.js +316 -0
- package/build/main/types/other/factories/IMixedRouteQuoterV1__factory.d.ts +41 -0
- package/build/main/types/other/factories/IMixedRouteQuoterV1__factory.js +156 -0
- package/build/main/types/other/factories/ITokenValidator__factory.d.ts +22 -0
- package/build/main/types/other/factories/ITokenValidator__factory.js +78 -0
- package/build/main/types/other/factories/Permit2__factory.d.ts +87 -0
- package/build/main/types/other/factories/Permit2__factory.js +941 -0
- package/build/main/types/other/factories/SwapRouter02__factory.d.ts +67 -0
- package/build/main/types/other/factories/SwapRouter02__factory.js +1103 -0
- package/build/main/types/v2/factories/IUniswapV2Pair__factory.d.ts +35 -0
- package/build/main/types/v2/factories/IUniswapV2Pair__factory.js +671 -0
- package/build/main/types/v3/factories/IERC20Metadata__factory.d.ts +35 -0
- package/build/main/types/v3/factories/IERC20Metadata__factory.js +242 -0
- package/build/main/types/v3/factories/IQuoterV2__factory.d.ts +41 -0
- package/build/main/types/v3/factories/IQuoterV2__factory.js +220 -0
- package/build/main/types/v3/factories/IUniswapV3PoolState__factory.d.ts +22 -0
- package/build/main/types/v3/factories/IUniswapV3PoolState__factory.js +266 -0
- package/build/main/types/v3/factories/UniswapInterfaceMulticall__factory.d.ts +61 -0
- package/build/main/types/v3/factories/UniswapInterfaceMulticall__factory.js +132 -0
- package/build/main/util/addresses.d.ts +25 -0
- package/build/main/util/addresses.js +59 -0
- package/build/main/util/amounts.d.ts +8 -0
- package/build/main/util/amounts.js +51 -0
- package/build/main/util/callData.d.ts +1 -0
- package/build/main/util/callData.js +6 -0
- package/build/main/util/chains.d.ts +34 -0
- package/build/main/util/chains.js +128 -0
- package/build/main/util/gas-factory-helpers.d.ts +24 -0
- package/build/main/util/gas-factory-helpers.js +294 -0
- package/build/main/util/index.d.ts +7 -0
- package/build/main/util/index.js +24 -0
- package/build/main/util/log.d.ts +3 -0
- package/build/main/util/log.js +97 -0
- package/build/main/util/methodParameters.d.ts +5 -0
- package/build/main/util/methodParameters.js +108 -0
- package/build/main/util/metric.d.ts +48 -0
- package/build/main/util/metric.js +59 -0
- package/build/main/util/protocols.d.ts +2 -0
- package/build/main/util/protocols.js +18 -0
- package/build/main/util/routes.d.ts +8 -0
- package/build/main/util/routes.js +60 -0
- package/build/main/util/unsupported-tokens.d.ts +37 -0
- package/build/main/util/unsupported-tokens.js +1119 -0
- package/build/module/index.d.ts +3 -0
- package/build/module/index.js +4 -0
- package/build/module/providers/cache-node.d.ts +9 -0
- package/build/module/providers/cache-node.js +15 -0
- package/build/module/providers/cache.d.ts +13 -0
- package/build/module/providers/cache.js +2 -0
- package/build/module/providers/caching/route/index.d.ts +2 -0
- package/build/module/providers/caching/route/index.js +3 -0
- package/build/module/providers/caching/route/model/cache-mode.d.ts +16 -0
- package/build/module/providers/caching/route/model/cache-mode.js +18 -0
- package/build/module/providers/caching/route/model/cached-route.d.ts +23 -0
- package/build/module/providers/caching/route/model/cached-route.js +20 -0
- package/build/module/providers/caching/route/model/cached-routes.d.ts +63 -0
- package/build/module/providers/caching/route/model/cached-routes.js +66 -0
- package/build/module/providers/caching/route/model/index.d.ts +3 -0
- package/build/module/providers/caching/route/model/index.js +4 -0
- package/build/module/providers/caching/route/route-caching-provider.d.ts +91 -0
- package/build/module/providers/caching/route/route-caching-provider.js +61 -0
- package/build/module/providers/caching-gas-provider.d.ts +23 -0
- package/build/module/providers/caching-gas-provider.js +33 -0
- package/build/module/providers/caching-token-list-provider.d.ts +40 -0
- package/build/module/providers/caching-token-list-provider.js +116 -0
- package/build/module/providers/caching-token-provider.d.ts +25 -0
- package/build/module/providers/caching-token-provider.js +106 -0
- package/build/module/providers/eip-1559-gas-price-provider.d.ts +31 -0
- package/build/module/providers/eip-1559-gas-price-provider.js +59 -0
- package/build/module/providers/eth-estimate-gas-provider.d.ts +14 -0
- package/build/module/providers/eth-estimate-gas-provider.js +80 -0
- package/build/module/providers/eth-gas-station-info-gas-price-provider.d.ts +19 -0
- package/build/module/providers/eth-gas-station-info-gas-price-provider.js +30 -0
- package/build/module/providers/gas-price-provider.d.ts +10 -0
- package/build/module/providers/gas-price-provider.js +6 -0
- package/build/module/providers/index.d.ts +37 -0
- package/build/module/providers/index.js +38 -0
- package/build/module/providers/legacy-gas-price-provider.d.ts +7 -0
- package/build/module/providers/legacy-gas-price-provider.js +16 -0
- package/build/module/providers/multicall-provider.d.ts +82 -0
- package/build/module/providers/multicall-provider.js +11 -0
- package/build/module/providers/multicall-uniswap-provider.d.ts +37 -0
- package/build/module/providers/multicall-uniswap-provider.js +156 -0
- package/build/module/providers/on-chain-gas-price-provider.d.ts +19 -0
- package/build/module/providers/on-chain-gas-price-provider.js +29 -0
- package/build/module/providers/on-chain-quote-provider.d.ts +221 -0
- package/build/module/providers/on-chain-quote-provider.js +505 -0
- package/build/module/providers/provider.d.ts +10 -0
- package/build/module/providers/provider.js +2 -0
- package/build/module/providers/simulation-provider.d.ts +42 -0
- package/build/module/providers/simulation-provider.js +132 -0
- package/build/module/providers/static-gas-price-provider.d.ts +7 -0
- package/build/module/providers/static-gas-price-provider.js +9 -0
- package/build/module/providers/swap-router-provider.d.ts +31 -0
- package/build/module/providers/swap-router-provider.js +38 -0
- package/build/module/providers/tenderly-simulation-provider.d.ts +43 -0
- package/build/module/providers/tenderly-simulation-provider.js +239 -0
- package/build/module/providers/token-provider.d.ts +45 -0
- package/build/module/providers/token-provider.js +110 -0
- package/build/module/providers/token-validator-provider.d.ts +42 -0
- package/build/module/providers/token-validator-provider.js +88 -0
- package/build/module/providers/uri-subgraph-provider.d.ts +20 -0
- package/build/module/providers/uri-subgraph-provider.js +58 -0
- package/build/module/providers/v2/caching-pool-provider.d.ts +34 -0
- package/build/module/providers/v2/caching-pool-provider.js +81 -0
- package/build/module/providers/v2/caching-subgraph-provider.d.ts +23 -0
- package/build/module/providers/v2/caching-subgraph-provider.js +30 -0
- package/build/module/providers/v2/pool-provider.d.ts +60 -0
- package/build/module/providers/v2/pool-provider.js +103 -0
- package/build/module/providers/v2/quote-provider.d.ts +33 -0
- package/build/module/providers/v2/quote-provider.js +87 -0
- package/build/module/providers/v2/static-subgraph-provider.d.ts +20 -0
- package/build/module/providers/v2/static-subgraph-provider.js +66 -0
- package/build/module/providers/v2/subgraph-provider-with-fallback.d.ts +19 -0
- package/build/module/providers/v2/subgraph-provider-with-fallback.js +31 -0
- package/build/module/providers/v2/subgraph-provider.d.ts +34 -0
- package/build/module/providers/v2/subgraph-provider.js +136 -0
- package/build/module/providers/v2/uri-subgraph-provider.d.ts +4 -0
- package/build/module/providers/v2/uri-subgraph-provider.js +4 -0
- package/build/module/providers/v3/caching-pool-provider.d.ts +33 -0
- package/build/module/providers/v3/caching-pool-provider.js +70 -0
- package/build/module/providers/v3/caching-subgraph-provider.d.ts +23 -0
- package/build/module/providers/v3/caching-subgraph-provider.js +30 -0
- package/build/module/providers/v3/gas-data-provider.d.ts +30 -0
- package/build/module/providers/v3/gas-data-provider.js +2 -0
- package/build/module/providers/v3/pool-provider.d.ts +61 -0
- package/build/module/providers/v3/pool-provider.js +118 -0
- package/build/module/providers/v3/static-subgraph-provider.d.ts +21 -0
- package/build/module/providers/v3/static-subgraph-provider.js +93 -0
- package/build/module/providers/v3/subgraph-provider-with-fallback.d.ts +15 -0
- package/build/module/providers/v3/subgraph-provider-with-fallback.js +27 -0
- package/build/module/providers/v3/subgraph-provider.d.ts +37 -0
- package/build/module/providers/v3/subgraph-provider.js +124 -0
- package/build/module/providers/v3/uri-subgraph-provider.d.ts +4 -0
- package/build/module/providers/v3/uri-subgraph-provider.js +4 -0
- package/build/module/routers/alpha-router/alpha-router.d.ts +267 -0
- package/build/module/routers/alpha-router/alpha-router.js +760 -0
- package/build/module/routers/alpha-router/config.d.ts +4 -0
- package/build/module/routers/alpha-router/config.js +57 -0
- package/build/module/routers/alpha-router/entities/index.d.ts +1 -0
- package/build/module/routers/alpha-router/entities/index.js +2 -0
- package/build/module/routers/alpha-router/entities/route-with-valid-quote.d.ts +163 -0
- package/build/module/routers/alpha-router/entities/route-with-valid-quote.js +134 -0
- package/build/module/routers/alpha-router/functions/best-swap-route.d.ts +19 -0
- package/build/module/routers/alpha-router/functions/best-swap-route.js +336 -0
- package/build/module/routers/alpha-router/functions/calculate-ratio-amount-in.d.ts +3 -0
- package/build/module/routers/alpha-router/functions/calculate-ratio-amount-in.js +14 -0
- package/build/module/routers/alpha-router/functions/compute-all-routes.d.ts +8 -0
- package/build/module/routers/alpha-router/functions/compute-all-routes.js +65 -0
- package/build/module/routers/alpha-router/functions/get-candidate-pools.d.ts +78 -0
- package/build/module/routers/alpha-router/functions/get-candidate-pools.js +715 -0
- package/build/module/routers/alpha-router/gas-models/gas-model.d.ts +83 -0
- package/build/module/routers/alpha-router/gas-models/gas-model.js +34 -0
- package/build/module/routers/alpha-router/gas-models/index.d.ts +2 -0
- package/build/module/routers/alpha-router/gas-models/index.js +3 -0
- package/build/module/routers/alpha-router/gas-models/mixedRoute/mixed-route-heuristic-gas-model.d.ts +25 -0
- package/build/module/routers/alpha-router/gas-models/mixedRoute/mixed-route-heuristic-gas-model.js +164 -0
- package/build/module/routers/alpha-router/gas-models/v2/v2-heuristic-gas-model.d.ts +29 -0
- package/build/module/routers/alpha-router/gas-models/v2/v2-heuristic-gas-model.js +160 -0
- package/build/module/routers/alpha-router/gas-models/v3/gas-costs.d.ts +6 -0
- package/build/module/routers/alpha-router/gas-models/v3/gas-costs.js +37 -0
- package/build/module/routers/alpha-router/gas-models/v3/v3-heuristic-gas-model.d.ts +25 -0
- package/build/module/routers/alpha-router/gas-models/v3/v3-heuristic-gas-model.js +216 -0
- package/build/module/routers/alpha-router/index.d.ts +4 -0
- package/build/module/routers/alpha-router/index.js +5 -0
- package/build/module/routers/alpha-router/quoters/base-quoter.d.ts +68 -0
- package/build/module/routers/alpha-router/quoters/base-quoter.js +54 -0
- package/build/module/routers/alpha-router/quoters/index.d.ts +5 -0
- package/build/module/routers/alpha-router/quoters/index.js +6 -0
- package/build/module/routers/alpha-router/quoters/mixed-quoter.d.ts +20 -0
- package/build/module/routers/alpha-router/quoters/mixed-quoter.js +123 -0
- package/build/module/routers/alpha-router/quoters/model/index.d.ts +1 -0
- package/build/module/routers/alpha-router/quoters/model/index.js +2 -0
- package/build/module/routers/alpha-router/quoters/model/results/get-quotes-result.d.ts +6 -0
- package/build/module/routers/alpha-router/quoters/model/results/get-quotes-result.js +2 -0
- package/build/module/routers/alpha-router/quoters/model/results/get-routes-result.d.ts +6 -0
- package/build/module/routers/alpha-router/quoters/model/results/get-routes-result.js +2 -0
- package/build/module/routers/alpha-router/quoters/model/results/index.d.ts +2 -0
- package/build/module/routers/alpha-router/quoters/model/results/index.js +3 -0
- package/build/module/routers/alpha-router/quoters/v2-quoter.d.ts +21 -0
- package/build/module/routers/alpha-router/quoters/v2-quoter.js +115 -0
- package/build/module/routers/alpha-router/quoters/v3-quoter.d.ts +19 -0
- package/build/module/routers/alpha-router/quoters/v3-quoter.js +118 -0
- package/build/module/routers/index.d.ts +4 -0
- package/build/module/routers/index.js +5 -0
- package/build/module/routers/legacy-router/bases.d.ts +28 -0
- package/build/module/routers/legacy-router/bases.js +54 -0
- package/build/module/routers/legacy-router/index.d.ts +1 -0
- package/build/module/routers/legacy-router/index.js +2 -0
- package/build/module/routers/legacy-router/legacy-router.d.ts +42 -0
- package/build/module/routers/legacy-router/legacy-router.js +290 -0
- package/build/module/routers/router.d.ts +165 -0
- package/build/module/routers/router.js +44 -0
- package/build/module/tsconfig.module.tsbuildinfo +1 -0
- package/build/module/types/other/factories/Erc20__factory.d.ts +45 -0
- package/build/module/types/other/factories/Erc20__factory.js +236 -0
- package/build/module/types/other/factories/GasDataArbitrum__factory.d.ts +18 -0
- package/build/module/types/other/factories/GasDataArbitrum__factory.js +54 -0
- package/build/module/types/other/factories/GasPriceOracle__factory.d.ts +46 -0
- package/build/module/types/other/factories/GasPriceOracle__factory.js +312 -0
- package/build/module/types/other/factories/IMixedRouteQuoterV1__factory.d.ts +41 -0
- package/build/module/types/other/factories/IMixedRouteQuoterV1__factory.js +152 -0
- package/build/module/types/other/factories/ITokenValidator__factory.d.ts +22 -0
- package/build/module/types/other/factories/ITokenValidator__factory.js +74 -0
- package/build/module/types/other/factories/Permit2__factory.d.ts +87 -0
- package/build/module/types/other/factories/Permit2__factory.js +937 -0
- package/build/module/types/other/factories/SwapRouter02__factory.d.ts +67 -0
- package/build/module/types/other/factories/SwapRouter02__factory.js +1099 -0
- package/build/module/types/v2/factories/IUniswapV2Pair__factory.d.ts +35 -0
- package/build/module/types/v2/factories/IUniswapV2Pair__factory.js +667 -0
- package/build/module/types/v3/factories/IERC20Metadata__factory.d.ts +35 -0
- package/build/module/types/v3/factories/IERC20Metadata__factory.js +238 -0
- package/build/module/types/v3/factories/IQuoterV2__factory.d.ts +41 -0
- package/build/module/types/v3/factories/IQuoterV2__factory.js +216 -0
- package/build/module/types/v3/factories/IUniswapV3PoolState__factory.d.ts +22 -0
- package/build/module/types/v3/factories/IUniswapV3PoolState__factory.js +262 -0
- package/build/module/types/v3/factories/UniswapInterfaceMulticall__factory.d.ts +61 -0
- package/build/module/types/v3/factories/UniswapInterfaceMulticall__factory.js +128 -0
- package/build/module/util/addresses.d.ts +25 -0
- package/build/module/util/addresses.js +70 -0
- package/build/module/util/amounts.d.ts +8 -0
- package/build/module/util/amounts.js +41 -0
- package/build/module/util/callData.d.ts +1 -0
- package/build/module/util/callData.js +3 -0
- package/build/module/util/chains.d.ts +34 -0
- package/build/module/util/chains.js +120 -0
- package/build/module/util/gas-factory-helpers.d.ts +24 -0
- package/build/module/util/gas-factory-helpers.js +277 -0
- package/build/module/util/index.d.ts +7 -0
- package/build/module/util/index.js +8 -0
- package/build/module/util/log.d.ts +3 -0
- package/build/module/util/log.js +93 -0
- package/build/module/util/methodParameters.d.ts +5 -0
- package/build/module/util/methodParameters.js +106 -0
- package/build/module/util/metric.d.ts +48 -0
- package/build/module/util/metric.js +53 -0
- package/build/module/util/protocols.d.ts +2 -0
- package/build/module/util/protocols.js +14 -0
- package/build/module/util/routes.d.ts +8 -0
- package/build/module/util/routes.js +50 -0
- package/build/module/util/unsupported-tokens.d.ts +37 -0
- package/build/module/util/unsupported-tokens.js +1116 -0
- package/package.json +133 -0
package/README.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# Xswap Smart Order Router
|
|
2
|
+
|
|
3
|
+
This repository contains routing logic for the Xswap V3 protocol.
|
|
4
|
+
|
|
5
|
+
It searches for the most efficient way to swap token A for token B, considering splitting swaps across multiple routes and gas costs.
|
|
6
|
+
|
|
7
|
+
## Testing
|
|
8
|
+
|
|
9
|
+
### Unit Tests
|
|
10
|
+
|
|
11
|
+
First make sure you have run `npm install` and `npm run build`.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
npm run test
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Integration Tests
|
|
18
|
+
|
|
19
|
+
Make sure the `.env` file is configured to connect to mainnet and other chains. See the [CLI](#cli) section below for more details.
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
npm run integ-test
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Tenderly Simulations
|
|
26
|
+
|
|
27
|
+
Quotes can be simulated on Tenderly
|
|
28
|
+
|
|
29
|
+
Ensure you set the following environment variables:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
process.env.TENDERLY_BASE_URL!,
|
|
33
|
+
process.env.TENDERLY_USER!,
|
|
34
|
+
process.env.TENDERLY_PROJECT!,
|
|
35
|
+
process.env.TENDERLY_ACCESS_KEY!,
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### CLI
|
|
39
|
+
|
|
40
|
+
The package can be run as a CLI for testing purposes.
|
|
41
|
+
|
|
42
|
+
First create a `.env` file in the root of the project and configure:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
JSON_RPC_PROVIDER = '<JSON_RPC_PROVIDER>'
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
To run on chains other than mainnet set up a connection by specifying the environment variable
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
JSON_RPC_PROVIDER_ROPSTEN = '<JSON_RPC_PROVIDER>'
|
|
52
|
+
JSON_RPC_PROVIDER_RINKEBY = '<JSON_RPC_PROVIDER>'
|
|
53
|
+
JSON_RPC_PROVIDER_GORLI = '<JSON_RPC_PROVIDER>'
|
|
54
|
+
JSON_RPC_PROVIDER_KOVAN = '<JSON_RPC_PROVIDER>'
|
|
55
|
+
JSON_RPC_PROVIDER_OPTIMISM = '<JSON_RPC_PROVIDER>'
|
|
56
|
+
JSON_RPC_PROVIDER_OPTIMISM_GOERLI = '<JSON_RPC_PROVIDER>'
|
|
57
|
+
JSON_RPC_PROVIDER_OPTIMISTIC_KOVAN = '<JSON_RPC_PROVIDER>'
|
|
58
|
+
JSON_RPC_PROVIDER_ARBITRUM_ONE = '<JSON_RPC_PROVIDER>'
|
|
59
|
+
JSON_RPC_PROVIDER_ARBITRUM_RINKEBY = '<JSON_RPC_PROVIDER>'
|
|
60
|
+
JSON_RPC_PROVIDER_ARBITRUM_GOERLI = '<JSON_RPC_PROVIDER>'
|
|
61
|
+
JSON_RPC_PROVIDER_POLYGON = '<JSON_RPC_PROVIDER>'
|
|
62
|
+
JSON_RPC_PROVIDER_POLYGON_MUMBAI = '<JSON_RPC_PROVIDER>'
|
|
63
|
+
JSON_RPC_PROVIDER_CELO = '<JSON_RPC_PROVIDER>'
|
|
64
|
+
JSON_RPC_PROVIDER_CELO_ALFAJORES = '<JSON_RPC_PROVIDER>'
|
|
65
|
+
JSON_RPC_PROVIDER_BSC = '<JSON_RPC_PROVIDER>'
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Then from the root directory you can execute the CLI.
|
|
69
|
+
|
|
70
|
+
## Examples
|
|
71
|
+
|
|
72
|
+
Some examples to use for manual CLI testing.
|
|
73
|
+
|
|
74
|
+
### Mainnet
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
./bin/cli quote --tokenIn 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 --tokenOut 0x1f9840a85d5af5bf1d1762f925bdaddc4201f984 --amount 1000 --exactIn --recipient 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B --protocols v2,v3
|
|
78
|
+
|
|
79
|
+
Best Route:
|
|
80
|
+
100.00% = USDC -- 0.3% --> UNI
|
|
81
|
+
Raw Quote Out:
|
|
82
|
+
35.72
|
|
83
|
+
Gas Adjusted Quote Out:
|
|
84
|
+
34.03
|
|
85
|
+
|
|
86
|
+
Gas Used Quote Token: 1.691772
|
|
87
|
+
Gas Used USD: 47.592951
|
|
88
|
+
Calldata: 0x414bf389000000000000...
|
|
89
|
+
Value: 0x00
|
|
90
|
+
|
|
91
|
+
blockNumber: "13088815"
|
|
92
|
+
estimatedGasUsed: "113000"
|
|
93
|
+
gasPriceWei: "130000000000"
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
./bin/cli quote-to-ratio --token0 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 --token1 0xdac17f958d2ee523a2206206994597c13d831ec7 --feeAmount 3000 --recipient 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B --token0Balance 1000 --token1Balance 2000 --tickLower -120 --tickUpper 120
|
|
97
|
+
|
|
98
|
+
Best Route:
|
|
99
|
+
100.00% = USDT -- 0.05% --> USDC
|
|
100
|
+
Raw Quote Exact In:
|
|
101
|
+
392.68
|
|
102
|
+
Gas Adjusted Quote In}:
|
|
103
|
+
346.13
|
|
104
|
+
|
|
105
|
+
Gas Used Quote Token: 46.550010
|
|
106
|
+
Gas Used USD: 46.342899
|
|
107
|
+
Calldata: 0x414bf389000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000ab5801a7d398351b8be11c439e05c5b3259aec9b000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000176a736c000000000000000000000000000000000000000000000000000000001764f8650000000000000000000000000000000000000000000000000000000000000000
|
|
108
|
+
Value: 0x00
|
|
109
|
+
|
|
110
|
+
blockNumber: "13239188"
|
|
111
|
+
estimatedGasUsed: "113000"
|
|
112
|
+
gasPriceWei: "116690684398"
|
|
113
|
+
|
|
114
|
+
./bin/cli quote --tokenIn 0x0391D2021f89DC339F60Fff84546EA23E337750f --tokenOut 0x4d224452801ACEd8B2F0aebE155379bb5D594381 --amount 10000 --exactIn --recipient 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B --protocols v2,v3,mixed
|
|
115
|
+
Best Route:
|
|
116
|
+
[V2 + V3] 100.00% = BOND -- [0x6591c4BcD6D7A1eb4E537DA8B78676C1576Ba244] --> USDC -- 0.3% [0xB07Fe2F407F971125D4EB1977f8aCEe8846C7324] --> APE
|
|
117
|
+
Raw Quote Exact In:
|
|
118
|
+
10437.85
|
|
119
|
+
Gas Adjusted Quote In:
|
|
120
|
+
10433.83
|
|
121
|
+
|
|
122
|
+
Gas Used Quote Token: 4.018625
|
|
123
|
+
Gas Used USD: 29.669402
|
|
124
|
+
Calldata: 0x5ae401dc0000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e4472b43f300000000000000000000000000000000000000000000021e19e0c9bab240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000391d2021f89dc339f60fff84546ea23e337750f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000104b858183f00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000080000000000000000000000000ab5801a7d398351b8be11c439e05c5b3259aec9b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002358df5b3b4459a3f5b000000000000000000000000000000000000000000000000000000000000002ba0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000bb84d224452801aced8b2f0aebe155379bb5d59438100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
125
|
+
Value: 0x00
|
|
126
|
+
|
|
127
|
+
blockNumber: "15303839"
|
|
128
|
+
estimatedGasUsed: "434000"
|
|
129
|
+
gasPriceWei: "38218865879"
|
|
130
|
+
Total ticks crossed: 7
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## XDC Mainnet
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
XSP
|
|
137
|
+
./bin/cli quote --tokenIn 0x36726235dAdbdb4658D33E62a249dCA7c4B2bC68 --tokenOut 0xD4B5f10D61916Bd6E0860144a91Ac658dE8a1437 --amount 1000 --exactIn --minSplits 1 --protocols v2,v3,mixed --router alpha --chainId 50
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
SRX - USDT
|
|
141
|
+
./bin/cli quote --tokenIn 0x5d5f074837f5d4618b3916ba74de1bf9662a3fed --tokenOut 0xD4B5f10D61916Bd6E0860144a91Ac658dE8a1437 --amount 1000 --exactIn --minSplits 1 --protocols v2 --router alpha --chainId 50
|
|
142
|
+
|
|
143
|
+
SRX - WXDC
|
|
144
|
+
./bin/cli quote --tokenIn 0x5d5f074837f5d4618b3916ba74de1bf9662a3fed --tokenOut 0x951857744785e80e2de051c32ee7b25f9c458c42 --amount 1000 --exactIn --minSplits 1 --protocols v2,v3,mixed --router alpha --chainId 50
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Adding a new Chain
|
|
149
|
+
|
|
150
|
+
The main components to complete are:
|
|
151
|
+
|
|
152
|
+
- Deploy contracts on chain, add the pools to subgraph
|
|
153
|
+
- Populate v3 providers in `src/providers/v3/subgraph-provider` and `src/providers/v3/static-subgraph-provider`
|
|
154
|
+
- Populate chainId and addresses in `src/util/chains.ts` and `src/util/addresses.ts`
|
|
155
|
+
- Populate token providers in `src/providers/caching-token-provider` and `src/providers/token-provider.ts`
|
|
156
|
+
- Populate gas constants in `src/routers/alpha-router/gas-models/*`
|
|
157
|
+
- Populate bases in `src/routers/legacy-router/bases.ts`
|
|
158
|
+
- Populate `test/integ/routers/alpha-router/alpha-router.integration.test.ts` and `src/providers/v2/static-subgraph-provider.ts`
|
|
159
|
+
- Populate `src/routers/alpha-router/*`
|
|
160
|
+
- Add a log to `/CHANGELOG.md`
|
|
161
|
+
- Run `npm run integ-test` successfully
|
|
162
|
+
|
|
163
|
+
# Troubleshooting
|
|
164
|
+
|
|
165
|
+
## ProviderGasLimit errors
|
|
166
|
+
|
|
167
|
+
The 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.
|
|
168
|
+
|
|
169
|
+
By default each `eth_call` will consume up to:
|
|
170
|
+
|
|
171
|
+
- 132,000,000 gas on Optimism
|
|
172
|
+
- 120,000,000 gas on Arbitrum
|
|
173
|
+
- 50,000,000 gas on Celo
|
|
174
|
+
- 150,000,000 gas on every other network (Mainnet, Goerli, etc.)
|
|
175
|
+
|
|
176
|
+
These parameters should work on Infura and Alchemy by default.
|
|
177
|
+
|
|
178
|
+
This 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/Xs/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.
|
|
179
|
+
|
|
180
|
+
If 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.
|
|
181
|
+
|
|
182
|
+
If you are using Hardhat mainnet forking, you should add `blockGasLimit: 150_000_000` to your Hardhat config to use the default package configuration.
|
|
183
|
+
|
|
184
|
+
# TODO
|
|
185
|
+
1) Check default gas limit for XDC
|
|
186
|
+
2) add v2 against
|
|
187
|
+
|
|
188
|
+
___
|
|
189
|
+
node version 15
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./providers"), exports);
|
|
18
|
+
__exportStar(require("./routers"), exports);
|
|
19
|
+
__exportStar(require("./util"), exports);
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLDhDQUE0QjtBQUM1Qiw0Q0FBMEI7QUFDMUIseUNBQXVCIn0=
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import NodeCache from 'node-cache';
|
|
2
|
+
import { ICache } from './cache';
|
|
3
|
+
export declare class NodeJSCache<T> implements ICache<T> {
|
|
4
|
+
private nodeCache;
|
|
5
|
+
constructor(nodeCache: NodeCache);
|
|
6
|
+
get(key: string): Promise<T | undefined>;
|
|
7
|
+
set(key: string, value: T): Promise<boolean>;
|
|
8
|
+
has(key: string): Promise<boolean>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeJSCache = void 0;
|
|
4
|
+
class NodeJSCache {
|
|
5
|
+
constructor(nodeCache) {
|
|
6
|
+
this.nodeCache = nodeCache;
|
|
7
|
+
}
|
|
8
|
+
async get(key) {
|
|
9
|
+
return this.nodeCache.get(key);
|
|
10
|
+
}
|
|
11
|
+
async set(key, value) {
|
|
12
|
+
return this.nodeCache.set(key, value);
|
|
13
|
+
}
|
|
14
|
+
async has(key) {
|
|
15
|
+
return this.nodeCache.has(key);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.NodeJSCache = NodeJSCache;
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2FjaGUtbm9kZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9wcm92aWRlcnMvY2FjaGUtbm9kZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFJQSxNQUFhLFdBQVc7SUFDdEIsWUFBb0IsU0FBb0I7UUFBcEIsY0FBUyxHQUFULFNBQVMsQ0FBVztJQUFHLENBQUM7SUFFNUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxHQUFXO1FBQ25CLE9BQU8sSUFBSSxDQUFDLFNBQVMsQ0FBQyxHQUFHLENBQUksR0FBRyxDQUFDLENBQUM7SUFDcEMsQ0FBQztJQUVELEtBQUssQ0FBQyxHQUFHLENBQUMsR0FBVyxFQUFFLEtBQVE7UUFDN0IsT0FBTyxJQUFJLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxHQUFHLEVBQUUsS0FBSyxDQUFDLENBQUM7SUFDeEMsQ0FBQztJQUVELEtBQUssQ0FBQyxHQUFHLENBQUMsR0FBVztRQUNuQixPQUFPLElBQUksQ0FBQyxTQUFTLENBQUMsR0FBRyxDQUFDLEdBQUcsQ0FBQyxDQUFDO0lBQ2pDLENBQUM7Q0FDRjtBQWRELGtDQWNDIn0=
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic cache used by providers. Allows caching of results to minimize
|
|
3
|
+
* round trips to external data sources.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @interface ICache
|
|
7
|
+
* @template T
|
|
8
|
+
*/
|
|
9
|
+
export interface ICache<T> {
|
|
10
|
+
get(key: string): Promise<T | undefined>;
|
|
11
|
+
set(key: string, value: T): Promise<boolean>;
|
|
12
|
+
has(key: string): Promise<boolean>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2FjaGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvcHJvdmlkZXJzL2NhY2hlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIifQ==
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./route-caching-provider"), exports);
|
|
18
|
+
__exportStar(require("./model/"), exports);
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvcHJvdmlkZXJzL2NhY2hpbmcvcm91dGUvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLDJEQUF5QztBQUN6QywyQ0FBeUIifQ==
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CacheMode enum that controls the way that the RouteCachingProvider works.
|
|
3
|
+
* - *Livemode*: This mode will set materialized routes into cache and fetch routes from cache.
|
|
4
|
+
* If the route exists in cache, it will be quoted and returned, otherwise it will materialized.
|
|
5
|
+
* - *Darkmode*: This mode indicates that the cache will not be used, it will not be inserted nor fetched.
|
|
6
|
+
* Routes will always be materialized.
|
|
7
|
+
* - *Tapcompare*: In this mode we will insert and fetch routes to/from cache, and we will also materialize the route.
|
|
8
|
+
* Ultimately the materialized route will be returned, but we will log some metrics comparing both.
|
|
9
|
+
*
|
|
10
|
+
* @enum {string}
|
|
11
|
+
*/
|
|
12
|
+
export declare enum CacheMode {
|
|
13
|
+
Livemode = "livemode",
|
|
14
|
+
Darkmode = "darkmode",
|
|
15
|
+
Tapcompare = "tapcompare"
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CacheMode = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* CacheMode enum that controls the way that the RouteCachingProvider works.
|
|
6
|
+
* - *Livemode*: This mode will set materialized routes into cache and fetch routes from cache.
|
|
7
|
+
* If the route exists in cache, it will be quoted and returned, otherwise it will materialized.
|
|
8
|
+
* - *Darkmode*: This mode indicates that the cache will not be used, it will not be inserted nor fetched.
|
|
9
|
+
* Routes will always be materialized.
|
|
10
|
+
* - *Tapcompare*: In this mode we will insert and fetch routes to/from cache, and we will also materialize the route.
|
|
11
|
+
* Ultimately the materialized route will be returned, but we will log some metrics comparing both.
|
|
12
|
+
*
|
|
13
|
+
* @enum {string}
|
|
14
|
+
*/
|
|
15
|
+
var CacheMode;
|
|
16
|
+
(function (CacheMode) {
|
|
17
|
+
CacheMode["Livemode"] = "livemode";
|
|
18
|
+
CacheMode["Darkmode"] = "darkmode";
|
|
19
|
+
CacheMode["Tapcompare"] = "tapcompare";
|
|
20
|
+
})(CacheMode = exports.CacheMode || (exports.CacheMode = {}));
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2FjaGUtbW9kZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy9wcm92aWRlcnMvY2FjaGluZy9yb3V0ZS9tb2RlbC9jYWNoZS1tb2RlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBOzs7Ozs7Ozs7O0dBVUc7QUFDSCxJQUFZLFNBSVg7QUFKRCxXQUFZLFNBQVM7SUFDbkIsa0NBQXFCLENBQUE7SUFDckIsa0NBQXFCLENBQUE7SUFDckIsc0NBQXlCLENBQUE7QUFDM0IsQ0FBQyxFQUpXLFNBQVMsR0FBVCxpQkFBUyxLQUFULGlCQUFTLFFBSXBCIn0=
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Protocol } from '@xswap-v3/router-sdk';
|
|
2
|
+
import { MixedRoute, V2Route, V3Route } from '../../../../routers';
|
|
3
|
+
interface CachedRouteParams<Route extends V3Route | V2Route | MixedRoute> {
|
|
4
|
+
route: Route;
|
|
5
|
+
percent: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Class defining the route to cache
|
|
9
|
+
*
|
|
10
|
+
* @export
|
|
11
|
+
* @class CachedRoute
|
|
12
|
+
*/
|
|
13
|
+
export declare class CachedRoute<Route extends V3Route | V2Route | MixedRoute> {
|
|
14
|
+
readonly route: Route;
|
|
15
|
+
readonly percent: number;
|
|
16
|
+
/**
|
|
17
|
+
* @param route
|
|
18
|
+
* @param percent
|
|
19
|
+
*/
|
|
20
|
+
constructor({ route, percent }: CachedRouteParams<Route>);
|
|
21
|
+
get protocol(): Protocol;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CachedRoute = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Class defining the route to cache
|
|
6
|
+
*
|
|
7
|
+
* @export
|
|
8
|
+
* @class CachedRoute
|
|
9
|
+
*/
|
|
10
|
+
class CachedRoute {
|
|
11
|
+
/**
|
|
12
|
+
* @param route
|
|
13
|
+
* @param percent
|
|
14
|
+
*/
|
|
15
|
+
constructor({ route, percent }) {
|
|
16
|
+
this.route = route;
|
|
17
|
+
this.percent = percent;
|
|
18
|
+
}
|
|
19
|
+
get protocol() {
|
|
20
|
+
return this.route.protocol;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.CachedRoute = CachedRoute;
|
|
24
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2FjaGVkLXJvdXRlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vc3JjL3Byb3ZpZGVycy9jYWNoaW5nL3JvdXRlL21vZGVsL2NhY2hlZC1yb3V0ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFTQTs7Ozs7R0FLRztBQUNILE1BQWEsV0FBVztJQUl0Qjs7O09BR0c7SUFDSCxZQUFZLEVBQUUsS0FBSyxFQUFFLE9BQU8sRUFBNEI7UUFDdEQsSUFBSSxDQUFDLEtBQUssR0FBRyxLQUFLLENBQUM7UUFDbkIsSUFBSSxDQUFDLE9BQU8sR0FBRyxPQUFPLENBQUM7SUFDekIsQ0FBQztJQUVELElBQVcsUUFBUTtRQUNqQixPQUFPLElBQUksQ0FBQyxLQUFLLENBQUMsUUFBUSxDQUFDO0lBQzdCLENBQUM7Q0FDRjtBQWhCRCxrQ0FnQkMifQ==
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Protocol } from '@xswap-v3/router-sdk';
|
|
2
|
+
import { Token, TradeType } from '@uniswap/sdk-core';
|
|
3
|
+
import { MixedRoute, RouteWithValidQuote, V2Route, V3Route } from '../../../../routers';
|
|
4
|
+
import { ChainId } from '../../../../util';
|
|
5
|
+
import { CachedRoute } from './cached-route';
|
|
6
|
+
interface CachedRoutesParams {
|
|
7
|
+
routes: CachedRoute<V3Route | V2Route | MixedRoute>[];
|
|
8
|
+
chainId: ChainId;
|
|
9
|
+
tokenIn: Token;
|
|
10
|
+
tokenOut: Token;
|
|
11
|
+
protocolsCovered: Protocol[];
|
|
12
|
+
blockNumber: number;
|
|
13
|
+
tradeType: TradeType;
|
|
14
|
+
blocksToLive?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Class defining the route to cache
|
|
18
|
+
*
|
|
19
|
+
* @export
|
|
20
|
+
* @class CachedRoute
|
|
21
|
+
*/
|
|
22
|
+
export declare class CachedRoutes {
|
|
23
|
+
readonly routes: CachedRoute<V3Route | V2Route | MixedRoute>[];
|
|
24
|
+
readonly chainId: ChainId;
|
|
25
|
+
readonly tokenIn: Token;
|
|
26
|
+
readonly tokenOut: Token;
|
|
27
|
+
readonly protocolsCovered: Protocol[];
|
|
28
|
+
readonly blockNumber: number;
|
|
29
|
+
readonly tradeType: TradeType;
|
|
30
|
+
blocksToLive: number;
|
|
31
|
+
/**
|
|
32
|
+
* @param routes
|
|
33
|
+
* @param chainId
|
|
34
|
+
* @param tokenIn
|
|
35
|
+
* @param tokenOut
|
|
36
|
+
* @param protocolsCovered
|
|
37
|
+
* @param blockNumber
|
|
38
|
+
* @param tradeType
|
|
39
|
+
* @param blocksToLive
|
|
40
|
+
*/
|
|
41
|
+
constructor({ routes, chainId, tokenIn, tokenOut, protocolsCovered, blockNumber, tradeType, blocksToLive }: CachedRoutesParams);
|
|
42
|
+
/**
|
|
43
|
+
* Factory method that creates a `CachedRoutes` object from an array of RouteWithValidQuote.
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
* @static
|
|
47
|
+
* @param routes
|
|
48
|
+
* @param chainId
|
|
49
|
+
* @param tokenIn
|
|
50
|
+
* @param tokenOut
|
|
51
|
+
* @param protocolsCovered
|
|
52
|
+
* @param blockNumber
|
|
53
|
+
* @param tradeType
|
|
54
|
+
*/
|
|
55
|
+
static fromRoutesWithValidQuotes(routes: RouteWithValidQuote[], chainId: ChainId, tokenIn: Token, tokenOut: Token, protocolsCovered: Protocol[], blockNumber: number, tradeType: TradeType): CachedRoutes | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Function to determine if, given a block number, the CachedRoute is expired or not.
|
|
58
|
+
*
|
|
59
|
+
* @param currentBlockNumber
|
|
60
|
+
*/
|
|
61
|
+
notExpired(currentBlockNumber: number): boolean;
|
|
62
|
+
}
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CachedRoutes = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const cached_route_1 = require("./cached-route");
|
|
9
|
+
/**
|
|
10
|
+
* Class defining the route to cache
|
|
11
|
+
*
|
|
12
|
+
* @export
|
|
13
|
+
* @class CachedRoute
|
|
14
|
+
*/
|
|
15
|
+
class CachedRoutes {
|
|
16
|
+
/**
|
|
17
|
+
* @param routes
|
|
18
|
+
* @param chainId
|
|
19
|
+
* @param tokenIn
|
|
20
|
+
* @param tokenOut
|
|
21
|
+
* @param protocolsCovered
|
|
22
|
+
* @param blockNumber
|
|
23
|
+
* @param tradeType
|
|
24
|
+
* @param blocksToLive
|
|
25
|
+
*/
|
|
26
|
+
constructor({ routes, chainId, tokenIn, tokenOut, protocolsCovered, blockNumber, tradeType, blocksToLive = 0 }) {
|
|
27
|
+
this.routes = routes;
|
|
28
|
+
this.chainId = chainId;
|
|
29
|
+
this.tokenIn = tokenIn;
|
|
30
|
+
this.tokenOut = tokenOut;
|
|
31
|
+
this.protocolsCovered = protocolsCovered;
|
|
32
|
+
this.blockNumber = blockNumber;
|
|
33
|
+
this.tradeType = tradeType;
|
|
34
|
+
this.blocksToLive = blocksToLive;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Factory method that creates a `CachedRoutes` object from an array of RouteWithValidQuote.
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
* @static
|
|
41
|
+
* @param routes
|
|
42
|
+
* @param chainId
|
|
43
|
+
* @param tokenIn
|
|
44
|
+
* @param tokenOut
|
|
45
|
+
* @param protocolsCovered
|
|
46
|
+
* @param blockNumber
|
|
47
|
+
* @param tradeType
|
|
48
|
+
*/
|
|
49
|
+
static fromRoutesWithValidQuotes(routes, chainId, tokenIn, tokenOut, protocolsCovered, blockNumber, tradeType) {
|
|
50
|
+
if (routes.length == 0)
|
|
51
|
+
return undefined;
|
|
52
|
+
const cachedRoutes = lodash_1.default.map(routes, (route) => new cached_route_1.CachedRoute({ route: route.route, percent: route.percent }));
|
|
53
|
+
return new CachedRoutes({
|
|
54
|
+
routes: cachedRoutes,
|
|
55
|
+
chainId: chainId,
|
|
56
|
+
tokenIn: tokenIn,
|
|
57
|
+
tokenOut: tokenOut,
|
|
58
|
+
protocolsCovered: protocolsCovered,
|
|
59
|
+
blockNumber: blockNumber,
|
|
60
|
+
tradeType: tradeType
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Function to determine if, given a block number, the CachedRoute is expired or not.
|
|
65
|
+
*
|
|
66
|
+
* @param currentBlockNumber
|
|
67
|
+
*/
|
|
68
|
+
notExpired(currentBlockNumber) {
|
|
69
|
+
return (currentBlockNumber - this.blockNumber) <= this.blocksToLive;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.CachedRoutes = CachedRoutes;
|
|
73
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2FjaGVkLXJvdXRlcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy9wcm92aWRlcnMvY2FjaGluZy9yb3V0ZS9tb2RlbC9jYWNoZWQtcm91dGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7OztBQUVBLG9EQUF1QjtBQUt2QixpREFBNkM7QUFhN0M7Ozs7O0dBS0c7QUFDSCxNQUFhLFlBQVk7SUFXdkI7Ozs7Ozs7OztPQVNHO0lBQ0gsWUFDRSxFQUNFLE1BQU0sRUFDTixPQUFPLEVBQ1AsT0FBTyxFQUNQLFFBQVEsRUFDUixnQkFBZ0IsRUFDaEIsV0FBVyxFQUNYLFNBQVMsRUFDVCxZQUFZLEdBQUcsQ0FBQyxFQUNHO1FBRXJCLElBQUksQ0FBQyxNQUFNLEdBQUcsTUFBTSxDQUFDO1FBQ3JCLElBQUksQ0FBQyxPQUFPLEdBQUcsT0FBTyxDQUFDO1FBQ3ZCLElBQUksQ0FBQyxPQUFPLEdBQUcsT0FBTyxDQUFDO1FBQ3ZCLElBQUksQ0FBQyxRQUFRLEdBQUcsUUFBUSxDQUFDO1FBQ3pCLElBQUksQ0FBQyxnQkFBZ0IsR0FBRyxnQkFBZ0IsQ0FBQztRQUN6QyxJQUFJLENBQUMsV0FBVyxHQUFHLFdBQVcsQ0FBQztRQUMvQixJQUFJLENBQUMsU0FBUyxHQUFHLFNBQVMsQ0FBQztRQUMzQixJQUFJLENBQUMsWUFBWSxHQUFHLFlBQVksQ0FBQztJQUNuQyxDQUFDO0lBRUQ7Ozs7Ozs7Ozs7OztPQVlHO0lBQ0ksTUFBTSxDQUFDLHlCQUF5QixDQUNyQyxNQUE2QixFQUM3QixPQUFnQixFQUNoQixPQUFjLEVBQ2QsUUFBZSxFQUNmLGdCQUE0QixFQUM1QixXQUFtQixFQUNuQixTQUFvQjtRQUVwQixJQUFJLE1BQU0sQ0FBQyxNQUFNLElBQUksQ0FBQztZQUFFLE9BQU8sU0FBUyxDQUFDO1FBRXpDLE1BQU0sWUFBWSxHQUFHLGdCQUFDLENBQUMsR0FBRyxDQUFDLE1BQU0sRUFBRSxDQUFDLEtBQTBCLEVBQUUsRUFBRSxDQUNoRSxJQUFJLDBCQUFXLENBQUMsRUFBRSxLQUFLLEVBQUUsS0FBSyxDQUFDLEtBQUssRUFBRSxPQUFPLEVBQUUsS0FBSyxDQUFDLE9BQU8sRUFBRSxDQUFDLENBQ2hFLENBQUM7UUFFRixPQUFPLElBQUksWUFBWSxDQUFDO1lBQ3RCLE1BQU0sRUFBRSxZQUFZO1lBQ3BCLE9BQU8sRUFBRSxPQUFPO1lBQ2hCLE9BQU8sRUFBRSxPQUFPO1lBQ2hCLFFBQVEsRUFBRSxRQUFRO1lBQ2xCLGdCQUFnQixFQUFFLGdCQUFnQjtZQUNsQyxXQUFXLEVBQUUsV0FBVztZQUN4QixTQUFTLEVBQUUsU0FBUztTQUNyQixDQUFDLENBQUM7SUFDTCxDQUFDO0lBRUQ7Ozs7T0FJRztJQUNJLFVBQVUsQ0FBQyxrQkFBMEI7UUFDMUMsT0FBTyxDQUFDLGtCQUFrQixHQUFHLElBQUksQ0FBQyxXQUFXLENBQUMsSUFBSSxJQUFJLENBQUMsWUFBWSxDQUFDO0lBQ3RFLENBQUM7Q0FDRjtBQTFGRCxvQ0EwRkMifQ==
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./cached-route"), exports);
|
|
18
|
+
__exportStar(require("./cached-routes"), exports);
|
|
19
|
+
__exportStar(require("./cache-mode"), exports);
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvcHJvdmlkZXJzL2NhY2hpbmcvcm91dGUvbW9kZWwvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLGlEQUErQjtBQUMvQixrREFBZ0M7QUFDaEMsK0NBQTZCIn0=
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider for getting token data from a Token List.
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @interface IRouteCachingProvider
|
|
6
|
+
*/
|
|
7
|
+
import { Protocol } from '@xswap-v3/router-sdk';
|
|
8
|
+
import { Currency, CurrencyAmount, Token, TradeType } from '@uniswap/sdk-core';
|
|
9
|
+
import { ChainId } from '../../../util';
|
|
10
|
+
import { CacheMode } from './model';
|
|
11
|
+
import { CachedRoutes } from './model/cached-routes';
|
|
12
|
+
/**
|
|
13
|
+
* Abstract class for a RouteCachingProvider.
|
|
14
|
+
* Defines the base methods of how to interact with this interface, but not the implementation of how to cache.
|
|
15
|
+
*/
|
|
16
|
+
export declare abstract class IRouteCachingProvider {
|
|
17
|
+
/**
|
|
18
|
+
* Final implementation of the public `getCachedRoute` method, this is how code will interact with the implementation
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
* @readonly
|
|
22
|
+
* @param chainId
|
|
23
|
+
* @param amount
|
|
24
|
+
* @param quoteToken
|
|
25
|
+
* @param tradeType
|
|
26
|
+
* @param protocols
|
|
27
|
+
* @param blockNumber
|
|
28
|
+
*/
|
|
29
|
+
readonly getCachedRoute: (chainId: number, amount: CurrencyAmount<Currency>, quoteToken: Token, tradeType: TradeType, protocols: Protocol[], blockNumber: number) => Promise<CachedRoutes | undefined>;
|
|
30
|
+
/**
|
|
31
|
+
* Final implementation of the public `setCachedRoute` method.
|
|
32
|
+
* This method will set the blockToLive in the CachedRoutes object before calling the internal method to insert in cache.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
* @readonly
|
|
36
|
+
* @param cachedRoutes The route to cache.
|
|
37
|
+
* @returns Promise<boolean> Indicates if the route was inserted into cache.
|
|
38
|
+
*/
|
|
39
|
+
readonly setCachedRoute: (cachedRoutes: CachedRoutes, amount: CurrencyAmount<Currency>) => Promise<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the CacheMode for the given cachedRoutes and amount
|
|
42
|
+
*
|
|
43
|
+
* @param cachedRoutes
|
|
44
|
+
* @param amount
|
|
45
|
+
*/
|
|
46
|
+
getCacheModeFromCachedRoutes(cachedRoutes: CachedRoutes, amount: CurrencyAmount<Currency>): Promise<CacheMode>;
|
|
47
|
+
/**
|
|
48
|
+
* Returns the CacheMode for the given combination of chainId, tokenIn, tokenOut and tradetype
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
* @abstract
|
|
52
|
+
* @param chainId
|
|
53
|
+
* @param tokenIn
|
|
54
|
+
* @param tokenOut
|
|
55
|
+
* @param tradeType
|
|
56
|
+
* @param amount
|
|
57
|
+
*/
|
|
58
|
+
abstract getCacheMode(chainId: ChainId, amount: CurrencyAmount<Currency>, quoteToken: Token, tradeType: TradeType, protocols: Protocol[]): Promise<CacheMode>;
|
|
59
|
+
private filterExpiredCachedRoutes;
|
|
60
|
+
/**
|
|
61
|
+
* Internal function to fetch the CachedRoute from the cache.
|
|
62
|
+
* Must be implemented.
|
|
63
|
+
*
|
|
64
|
+
* @param chainId
|
|
65
|
+
* @param amount
|
|
66
|
+
* @param quoteToken
|
|
67
|
+
* @param tradeType
|
|
68
|
+
* @param protocols
|
|
69
|
+
* @protected
|
|
70
|
+
*/
|
|
71
|
+
protected abstract _getCachedRoute(chainId: ChainId, amount: CurrencyAmount<Currency>, quoteToken: Token, tradeType: TradeType, protocols: Protocol[]): Promise<CachedRoutes | undefined>;
|
|
72
|
+
/**
|
|
73
|
+
* Internal function to insert the CachedRoute into cache.
|
|
74
|
+
* Must be implemented.
|
|
75
|
+
*
|
|
76
|
+
* @param cachedRoutes
|
|
77
|
+
* @param amount
|
|
78
|
+
* @protected
|
|
79
|
+
*/
|
|
80
|
+
protected abstract _setCachedRoute(cachedRoutes: CachedRoutes, amount: CurrencyAmount<Currency>): Promise<boolean>;
|
|
81
|
+
/**
|
|
82
|
+
* Internal function to getBlocksToLive for a given cachedRoute.
|
|
83
|
+
* This function is called before attempting to insert the route into cache.
|
|
84
|
+
* Must be implemented.
|
|
85
|
+
*
|
|
86
|
+
* @param cachedRoutes
|
|
87
|
+
* @param amount
|
|
88
|
+
* @protected
|
|
89
|
+
*/
|
|
90
|
+
protected abstract _getBlocksToLive(cachedRoutes: CachedRoutes, amount: CurrencyAmount<Currency>): Promise<number>;
|
|
91
|
+
}
|