@ring-protocol/smart-order-router 0.5.0 → 0.5.1

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.
Files changed (162) hide show
  1. package/build/main/index.js.map +1 -0
  2. package/build/main/providers/cache-node.js.map +1 -0
  3. package/build/main/providers/cache.js.map +1 -0
  4. package/build/main/providers/caching/route/index.js.map +1 -0
  5. package/build/main/providers/caching/route/model/cache-mode.js.map +1 -0
  6. package/build/main/providers/caching/route/model/cached-route.js.map +1 -0
  7. package/build/main/providers/caching/route/model/cached-routes.js.map +1 -0
  8. package/build/main/providers/caching/route/model/index.js.map +1 -0
  9. package/build/main/providers/caching/route/route-caching-provider.js.map +1 -0
  10. package/build/main/providers/caching-gas-provider.js.map +1 -0
  11. package/build/main/providers/caching-subgraph-provider.js.map +1 -0
  12. package/build/main/providers/caching-token-list-provider.js.map +1 -0
  13. package/build/main/providers/caching-token-provider.js.map +1 -0
  14. package/build/main/providers/eip-1559-gas-price-provider.js.map +1 -0
  15. package/build/main/providers/eth-estimate-gas-provider.js.map +1 -0
  16. package/build/main/providers/eth-gas-station-info-gas-price-provider.js.map +1 -0
  17. package/build/main/providers/fewV2/ring-caching-pool-provider.js.map +1 -0
  18. package/build/main/providers/fewV2/ring-caching-subgraph-provider.js.map +1 -0
  19. package/build/main/providers/fewV2/ring-pool-provider.js.map +1 -0
  20. package/build/main/providers/fewV2/ring-quote-provider.js.map +1 -0
  21. package/build/main/providers/fewV2/ring-static-subgraph-provider.js.map +1 -0
  22. package/build/main/providers/fewV2/ring-subgraph-provider-with-fallback.js.map +1 -0
  23. package/build/main/providers/fewV2/ring-subgraph-provider.js.map +1 -0
  24. package/build/main/providers/fewV2/ring-uri-subgraph-provider.js.map +1 -0
  25. package/build/main/providers/gas-price-provider.js.map +1 -0
  26. package/build/main/providers/index.js.map +1 -0
  27. package/build/main/providers/legacy-gas-price-provider.js.map +1 -0
  28. package/build/main/providers/multicall-provider.js.map +1 -0
  29. package/build/main/providers/multicall-ringswap-provider.js.map +1 -0
  30. package/build/main/providers/multicall-uniswap-provider.js.map +1 -0
  31. package/build/main/providers/on-chain-gas-price-provider.js.map +1 -0
  32. package/build/main/providers/on-chain-quote-provider.d.ts +4 -4
  33. package/build/main/providers/on-chain-quote-provider.js +35 -37
  34. package/build/main/providers/on-chain-quote-provider.js.map +1 -0
  35. package/build/main/providers/pool-provider.js.map +1 -0
  36. package/build/main/providers/portion-provider.js.map +1 -0
  37. package/build/main/providers/provider.js.map +1 -0
  38. package/build/main/providers/simulation-provider.js.map +1 -0
  39. package/build/main/providers/static-gas-price-provider.js.map +1 -0
  40. package/build/main/providers/subgraph-provider-with-fallback.js.map +1 -0
  41. package/build/main/providers/subgraph-provider.js.map +1 -0
  42. package/build/main/providers/swap-router-provider.js.map +1 -0
  43. package/build/main/providers/tenderly-simulation-provider.js.map +1 -0
  44. package/build/main/providers/token-fee-fetcher.js.map +1 -0
  45. package/build/main/providers/token-properties-provider.js.map +1 -0
  46. package/build/main/providers/token-provider.js.map +1 -0
  47. package/build/main/providers/token-validator-provider.js.map +1 -0
  48. package/build/main/providers/uri-subgraph-provider.js.map +1 -0
  49. package/build/main/providers/v2/caching-pool-provider.js.map +1 -0
  50. package/build/main/providers/v2/caching-subgraph-provider.js.map +1 -0
  51. package/build/main/providers/v2/pool-provider.js.map +1 -0
  52. package/build/main/providers/v2/quote-provider.js.map +1 -0
  53. package/build/main/providers/v2/static-subgraph-provider.js.map +1 -0
  54. package/build/main/providers/v2/subgraph-provider-with-fallback.js.map +1 -0
  55. package/build/main/providers/v2/subgraph-provider.js.map +1 -0
  56. package/build/main/providers/v2/uri-subgraph-provider.js.map +1 -0
  57. package/build/main/providers/v3/caching-pool-provider.js.map +1 -0
  58. package/build/main/providers/v3/caching-subgraph-provider.js.map +1 -0
  59. package/build/main/providers/v3/gas-data-provider.js.map +1 -0
  60. package/build/main/providers/v3/pool-provider.js.map +1 -0
  61. package/build/main/providers/v3/static-subgraph-provider.js.map +1 -0
  62. package/build/main/providers/v3/subgraph-provider-with-fallback.js.map +1 -0
  63. package/build/main/providers/v3/subgraph-provider.js.map +1 -0
  64. package/build/main/providers/v3/uri-subgraph-provider.js.map +1 -0
  65. package/build/main/providers/v4/caching-pool-provider.js.map +1 -0
  66. package/build/main/providers/v4/caching-subgraph-provider.js.map +1 -0
  67. package/build/main/providers/v4/pool-provider.js.map +1 -0
  68. package/build/main/providers/v4/static-subgraph-provider.js.map +1 -0
  69. package/build/main/providers/v4/subgraph-provider-with-fallback.js.map +1 -0
  70. package/build/main/providers/v4/subgraph-provider.js.map +1 -0
  71. package/build/main/providers/v4/uri-subgraph-provider.js.map +1 -0
  72. package/build/main/routers/alpha-router/alpha-router.d.ts +9 -0
  73. package/build/main/routers/alpha-router/alpha-router.js +4 -1
  74. package/build/main/routers/alpha-router/alpha-router.js.map +1 -0
  75. package/build/main/routers/alpha-router/config.js.map +1 -0
  76. package/build/main/routers/alpha-router/entities/index.js.map +1 -0
  77. package/build/main/routers/alpha-router/entities/route-with-valid-quote.js.map +1 -0
  78. package/build/main/routers/alpha-router/functions/best-swap-route.js.map +1 -0
  79. package/build/main/routers/alpha-router/functions/calculate-ratio-amount-in.js.map +1 -0
  80. package/build/main/routers/alpha-router/functions/compute-all-routes.js.map +1 -0
  81. package/build/main/routers/alpha-router/functions/get-candidate-pools.js.map +1 -0
  82. package/build/main/routers/alpha-router/gas-models/fewV2/v2-heuristic-gas-model.js.map +1 -0
  83. package/build/main/routers/alpha-router/gas-models/gas-costs.js.map +1 -0
  84. package/build/main/routers/alpha-router/gas-models/gas-model.js.map +1 -0
  85. package/build/main/routers/alpha-router/gas-models/index.js.map +1 -0
  86. package/build/main/routers/alpha-router/gas-models/mixedRoute/mixed-route-heuristic-gas-model.js.map +1 -0
  87. package/build/main/routers/alpha-router/gas-models/ring-gas-model.js.map +1 -0
  88. package/build/main/routers/alpha-router/gas-models/tick-based-heuristic-gas-model.js.map +1 -0
  89. package/build/main/routers/alpha-router/gas-models/uniswapFewV3/v3-heuristic-gas-model.js.map +1 -0
  90. package/build/main/routers/alpha-router/gas-models/uniswapFewV4/v4-heuristic-gas-model.js.map +1 -0
  91. package/build/main/routers/alpha-router/gas-models/v2/v2-heuristic-gas-model.js.map +1 -0
  92. package/build/main/routers/alpha-router/gas-models/v3/v3-heuristic-gas-model.js.map +1 -0
  93. package/build/main/routers/alpha-router/gas-models/v4/v4-heuristic-gas-model.js.map +1 -0
  94. package/build/main/routers/alpha-router/index.js.map +1 -0
  95. package/build/main/routers/alpha-router/quoters/base-quoter.js.map +1 -0
  96. package/build/main/routers/alpha-router/quoters/few-v2-quoter.js.map +1 -0
  97. package/build/main/routers/alpha-router/quoters/index.js.map +1 -0
  98. package/build/main/routers/alpha-router/quoters/mixed-quoter.js.map +1 -0
  99. package/build/main/routers/alpha-router/quoters/model/index.js.map +1 -0
  100. package/build/main/routers/alpha-router/quoters/model/results/get-quotes-result.js.map +1 -0
  101. package/build/main/routers/alpha-router/quoters/model/results/get-routes-result.js.map +1 -0
  102. package/build/main/routers/alpha-router/quoters/model/results/index.js.map +1 -0
  103. package/build/main/routers/alpha-router/quoters/uniswap-few-v3-quoter.js.map +1 -0
  104. package/build/main/routers/alpha-router/quoters/uniswap-few-v4-quoter.js.map +1 -0
  105. package/build/main/routers/alpha-router/quoters/v2-quoter.js.map +1 -0
  106. package/build/main/routers/alpha-router/quoters/v3-quoter.js.map +1 -0
  107. package/build/main/routers/alpha-router/quoters/v4-quoter.js.map +1 -0
  108. package/build/main/routers/index.js.map +1 -0
  109. package/build/main/routers/legacy-router/bases.js.map +1 -0
  110. package/build/main/routers/legacy-router/index.js.map +1 -0
  111. package/build/main/routers/legacy-router/legacy-router.js.map +1 -0
  112. package/build/main/routers/router.js.map +1 -0
  113. package/build/main/tsconfig.tsbuildinfo +1 -1
  114. package/build/main/types/other/commons.js.map +1 -0
  115. package/build/main/types/other/factories/Erc20__factory.js.map +1 -0
  116. package/build/main/types/other/factories/GasDataArbitrum__factory.js.map +1 -0
  117. package/build/main/types/other/factories/IMixedRouteQuoterV1__factory.js.map +1 -0
  118. package/build/main/types/other/factories/ITokenValidator__factory.js.map +1 -0
  119. package/build/main/types/other/factories/MixedRouteQuoterV2__factory.js.map +1 -0
  120. package/build/main/types/other/factories/Permit2__factory.js.map +1 -0
  121. package/build/main/types/other/factories/StateView__factory.js.map +1 -0
  122. package/build/main/types/other/factories/SwapRouter02__factory.js.map +1 -0
  123. package/build/main/types/other/factories/TokenFeeDetector__factory.js.map +1 -0
  124. package/build/main/types/other/factories/V4Quoter__factory.js.map +1 -0
  125. package/build/main/types/v2/commons.js.map +1 -0
  126. package/build/main/types/v2/factories/IUniswapV2Pair__factory.js.map +1 -0
  127. package/build/main/types/v3/commons.js.map +1 -0
  128. package/build/main/types/v3/factories/IERC20Metadata__factory.js.map +1 -0
  129. package/build/main/types/v3/factories/IQuoterV2__factory.js.map +1 -0
  130. package/build/main/types/v3/factories/IUniswapV3PoolState__factory.js.map +1 -0
  131. package/build/main/types/v3/factories/UniswapInterfaceMulticall__factory.js.map +1 -0
  132. package/build/main/util/addresses.js.map +1 -0
  133. package/build/main/util/amounts.js.map +1 -0
  134. package/build/main/util/callData.js.map +1 -0
  135. package/build/main/util/chains.js.map +1 -0
  136. package/build/main/util/defaultBlocksToLive.js.map +1 -0
  137. package/build/main/util/fewAddress.js.map +1 -0
  138. package/build/main/util/gas-factory-helpers.js.map +1 -0
  139. package/build/main/util/hooksOptions.js.map +1 -0
  140. package/build/main/util/index.js.map +1 -0
  141. package/build/main/util/intent.js.map +1 -0
  142. package/build/main/util/l2FeeChains.js.map +1 -0
  143. package/build/main/util/log.js.map +1 -0
  144. package/build/main/util/methodParameters.js +3 -1
  145. package/build/main/util/methodParameters.js.map +1 -0
  146. package/build/main/util/metric.js.map +1 -0
  147. package/build/main/util/mixedRouteFilterOutV4Pools.js.map +1 -0
  148. package/build/main/util/onchainQuoteProviderConfigs.js.map +1 -0
  149. package/build/main/util/pool.js.map +1 -0
  150. package/build/main/util/protocols.js.map +1 -0
  151. package/build/main/util/routes.js.map +1 -0
  152. package/build/main/util/serializeRouteIds.js.map +1 -0
  153. package/build/main/util/simple-perf-tracker.js.map +1 -0
  154. package/build/main/util/tenderlySimulationErrorBreakDown.js.map +1 -0
  155. package/build/main/util/unsupported-tokens.js.map +1 -0
  156. package/build/module/providers/on-chain-quote-provider.d.ts +4 -4
  157. package/build/module/providers/on-chain-quote-provider.js +35 -37
  158. package/build/module/routers/alpha-router/alpha-router.d.ts +9 -0
  159. package/build/module/routers/alpha-router/alpha-router.js +4 -1
  160. package/build/module/tsconfig.module.tsbuildinfo +1 -1
  161. package/build/module/util/methodParameters.js +3 -1
  162. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../src/routers/alpha-router/config.ts"],"names":[],"mappings":";;;AAAA,oDAAgD;AAEhD,iDAAyE;AAElE,MAAM,+BAA+B,GAAG,CAC7C,OAAgB,EACG,EAAE;IACrB,QAAQ,OAAO,EAAE;QACf,WAAW;QACX,KAAK,kBAAO,CAAC,QAAQ,CAAC;QACtB,KAAK,kBAAO,CAAC,eAAe,CAAC;QAC7B,KAAK,kBAAO,CAAC,gBAAgB,CAAC;QAC9B,KAAK,kBAAO,CAAC,IAAI,CAAC;QAClB,KAAK,kBAAO,CAAC,WAAW,CAAC;QACzB,KAAK,kBAAO,CAAC,YAAY,CAAC;QAC1B,KAAK,kBAAO,CAAC,KAAK,CAAC;QACnB,KAAK,kBAAO,CAAC,UAAU,CAAC;QACxB,KAAK,kBAAO,CAAC,gBAAgB,CAAC;QAC9B,KAAK,kBAAO,CAAC,aAAa,CAAC;QAC3B,KAAK,kBAAO,CAAC,QAAQ,CAAC;QACtB,KAAK,kBAAO,CAAC,OAAO;YAClB,OAAO;gBACL,eAAe,EAAE;oBACf,IAAI,EAAE,CAAC;oBACP,eAAe,EAAE,CAAC;oBAClB,cAAc,EAAE,CAAC;oBACjB,aAA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,EAAE,CAAC;oBAClB,cAAc,EAAE,CAAC;oBACjB,aAAa,EAAE,CAAC;oBAChB,qBAAqB,EAAE,CAAC;oBACxB,iBAAiB,EAAE,CAAC;iBACrB;gBACD,eAAe,EAAE,CAAC;gBAClB,SAAS,EAAE,CAAC;gBACZ,SAAS,EAAE,CAAC;gBACZ,mBAAmB,EAAE,EAAE;gBACvB,kBAAkB,EAAE,KAAK;aAC1B,CAAC;QACJ;YACE,OAAO;gBACL,eAAe,EAAE;oBACf,IAAI,EAAE,CAAC;oBACP,eAAe,EAAE,CAAC;oBAClB,cAAc,EAAE,CAAC;oBACjB,aAAa,EAAE,CAAC;oBAChB,yBAAyB,EAAE,IAAI,mCAAoB,CACjD,4CAA4C,CAAC,kBAAkB;qBAChE;oBACD,qBAAqB,EAAE,CAAC;oBACxB,iBAAiB,EAAE,CAAC;iBACrB;gBACD,eAAe,EAAE;oBACf,IAAI,EAAE,CAAC;oBACP,eAAe,EAAE,CAAC;oBAClB,cAAc,EAAE,CAAC;oBACjB,aAAa,EAAE,CAAC;oBAChB,qBAAqB,EAAE,CAAC;oBACxB,iBAAiB,EAAE,CAAC;iBACrB;gBACD,eAAe,EAAE;oBACf,IAAI,EAAE,CAAC;oBACP,eAAe,EAAE,CAAC;oBAClB,cAAc,EAAE,CAAC;oBACjB,aAAa,EAAE,CAAC;oBAChB,qBAAqB,EAAE,CAAC;oBACxB,iBAAiB,EAAE,CAAC;iBACrB;gBACD,eAAe,EAAE,CAAC;gBAClB,SAAS,EAAE,CAAC;gBACZ,SAAS,EAAE,CAAC;gBACZ,mBAAmB,EAAE,CAAC;gBACtB,kBAAkB,EAAE,KAAK;aAC1B,CAAC;KACL;AACH,CAAC,CAAC;AA3HW,QAAA,+BAA+B,mCA2H1C;AACW,QAAA,uBAAuB,GAClC,+CAA+C,CAAC","sourcesContent":["import { ChainId } from '@fewprotocol/sdk-core';\n\nimport { AlphaRouterConfig, LowerCaseStringArray } from './alpha-router';\n\nexport const DEFAULT_ROUTING_CONFIG_BY_CHAIN = (\n chainId: ChainId\n): AlphaRouterConfig => {\n switch (chainId) {\n // Optimism\n case ChainId.OPTIMISM:\n case ChainId.OPTIMISM_GOERLI:\n case ChainId.OPTIMISM_SEPOLIA:\n case ChainId.BASE:\n case ChainId.BASE_GOERLI:\n case ChainId.BASE_SEPOLIA:\n case ChainId.BLAST:\n case ChainId.WORLDCHAIN:\n case ChainId.UNICHAIN_SEPOLIA:\n case ChainId.MONAD_TESTNET:\n case ChainId.UNICHAIN:\n case ChainId.SONEIUM:\n return {\n v2PoolSelection: {\n topN: 3,\n topNDirectSwaps: 1,\n topNTokenInOut: 5,\n topNSecondHop: 2,\n topNWithEachBaseToken: 2,\n topNWithBaseToken: 6,\n },\n v3PoolSelection: {\n topN: 2,\n topNDirectSwaps: 2,\n topNTokenInOut: 2,\n topNSecondHop: 1,\n topNWithEachBaseToken: 3,\n topNWithBaseToken: 3,\n },\n v4PoolSelection: {\n topN: 2,\n topNDirectSwaps: 2,\n topNTokenInOut: 2,\n topNSecondHop: 1,\n topNWithEachBaseToken: 3,\n topNWithBaseToken: 3,\n },\n maxSwapsPerPath: 3,\n minSplits: 1,\n maxSplits: 7,\n distributionPercent: 10,\n forceCrossProtocol: false,\n };\n // Arbitrum calls have lower gas limits and tend to timeout more, which causes us to reduce the multicall\n // batch size and send more multicalls per quote. To reduce the amount of requests each quote sends, we\n // have to adjust the routing config so we explore fewer routes.\n case ChainId.ARBITRUM_ONE:\n case ChainId.ARBITRUM_GOERLI:\n case ChainId.ARBITRUM_SEPOLIA:\n case ChainId.CELO:\n case ChainId.CELO_ALFAJORES:\n return {\n v2PoolSelection: {\n topN: 3,\n topNDirectSwaps: 1,\n topNTokenInOut: 5,\n topNSecondHop: 2,\n topNWithEachBaseToken: 2,\n topNWithBaseToken: 6,\n },\n v3PoolSelection: {\n topN: 2,\n topNDirectSwaps: 2,\n topNTokenInOut: 2,\n topNSecondHop: 1,\n topNWithEachBaseToken: 3,\n topNWithBaseToken: 2,\n },\n v4PoolSelection: {\n topN: 2,\n topNDirectSwaps: 2,\n topNTokenInOut: 2,\n topNSecondHop: 1,\n topNWithEachBaseToken: 3,\n topNWithBaseToken: 2,\n },\n maxSwapsPerPath: 2,\n minSplits: 1,\n maxSplits: 7,\n distributionPercent: 25,\n forceCrossProtocol: false,\n };\n default:\n return {\n v2PoolSelection: {\n topN: 3,\n topNDirectSwaps: 1,\n topNTokenInOut: 5,\n topNSecondHop: 2,\n tokensToAvoidOnSecondHops: new LowerCaseStringArray(\n '0xd46ba6d942050d489dbd938a2c909a5d5039a161' // AMPL on Mainnet\n ),\n topNWithEachBaseToken: 2,\n topNWithBaseToken: 6,\n },\n v3PoolSelection: {\n topN: 2,\n topNDirectSwaps: 2,\n topNTokenInOut: 3,\n topNSecondHop: 1,\n topNWithEachBaseToken: 3,\n topNWithBaseToken: 5,\n },\n v4PoolSelection: {\n topN: 2,\n topNDirectSwaps: 2,\n topNTokenInOut: 3,\n topNSecondHop: 1,\n topNWithEachBaseToken: 3,\n topNWithBaseToken: 5,\n },\n maxSwapsPerPath: 3,\n minSplits: 1,\n maxSplits: 7,\n distributionPercent: 5,\n forceCrossProtocol: false,\n };\n }\n};\nexport const ETH_GAS_STATION_API_URL =\n 'https://ethgasstation.info/api/ethgasAPI.json';\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/routers/alpha-router/entities/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC","sourcesContent":["export * from './route-with-valid-quote';\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-with-valid-quote.js","sourceRoot":"","sources":["../../../../../src/routers/alpha-router/entities/route-with-valid-quote.ts"],"names":[],"mappings":";;;;;;AACA,wDAAmD;AACnD,gDAAwD;AACxD,oDAAmE;AACnE,gEAAmD;AACnD,gEAA6D;AAC7D,gEAA6D;AAC7D,oDAAuB;AAKvB,mDAAuD;AACvD,iDAAqD;AAwF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AAC;CAqEF;AAhGD,4DAgGC","sourcesContent":["import { BigNumber } from '@ethersproject/bignumber';\nimport { Protocol } from '@fewprotocol/router-sdk';\nimport { Pair as FewV2Pair } from '@fewprotocol/v2-sdk';\nimport { Currency, Token, TradeType } from '@fewprotocol/sdk-core';\nimport { Pair } from '@fewprotocol/uniswap-v2-sdk';\nimport { Pool as V3Pool } from '@fewprotocol/uniswap-v3-sdk';\nimport { Pool as V4Pool } from '@fewprotocol/uniswap-v4-sdk';\nimport _ from 'lodash';\n\nimport { IRingV2PoolProvider, IV4PoolProvider } from '../../../providers';\nimport { IV2PoolProvider } from '../../../providers/v2/pool-provider';\nimport { IV3PoolProvider } from '../../../providers/v3/pool-provider';\nimport { CurrencyAmount } from '../../../util/amounts';\nimport { routeToString } from '../../../util/routes';\nimport {\n RingFewV2Route,\n MixedRoute,\n SupportedRoutes,\n V2Route,\n V3Route,\n V4Route,\n} from '../../router';\nimport { IGasModel } from '../gas-models/gas-model';\n// import { getFeWTokenForToken, isFWToken } from '../../../util/fw-token-helper';\n\n/**\n * Represents a route, a quote for swapping some amount on it, and other\n * metadata used by the routing algorithm.\n *\n * @export\n * @interface IRouteWithValidQuote\n * @template Route\n */\nexport interface IRouteWithValidQuote<Route extends SupportedRoutes> {\n amount: CurrencyAmount;\n percent: number;\n // If exact in, this is (quote - gasCostInToken). If exact out, this is (quote + gasCostInToken).\n quoteAdjustedForGas: CurrencyAmount;\n quote: CurrencyAmount;\n route: Route;\n gasEstimate: BigNumber;\n // The gas cost in terms of the quote token.\n gasCostInToken: CurrencyAmount;\n gasCostInUSD: CurrencyAmount;\n gasCostInGasToken?: CurrencyAmount;\n tradeType: TradeType;\n poolIdentifiers: string[];\n tokenPath: Currency[];\n}\n\n// Discriminated unions on protocol field to narrow types.\nexport type IV2RouteWithValidQuote = {\n protocol: Protocol.V2;\n} & IRouteWithValidQuote<V2Route>;\n\nexport type IFewV2RouteWithValidQuote = {\n protocol: Protocol.FEWV2;\n} & IRouteWithValidQuote<RingFewV2Route>;\n\nexport type IV3RouteWithValidQuote = {\n protocol: Protocol.V3;\n} & IRouteWithValidQuote<V3Route>;\n\nexport type IV4RouteWithValidQuote = {\n protocol: Protocol.V4;\n} & IRouteWithValidQuote<V4Route>;\n\nexport type IMixedRouteWithValidQuote = {\n protocol: Protocol.MIXED;\n} & IRouteWithValidQuote<MixedRoute>;\n\nexport type RouteWithValidQuote =\n | RingFewV2RouteWithValidQuote\n | V2RouteWithValidQuote\n | V3RouteWithValidQuote\n | UniswapFewV3RouteWithValidQuote\n | V4RouteWithValidQuote\n | UniswapFewV4RouteWithValidQuote\n | MixedRouteWithValidQuote;\n\nexport type V2RouteWithValidQuoteParams = {\n amount: CurrencyAmount;\n rawQuote: BigNumber;\n percent: number;\n route: V2Route;\n gasModel: IGasModel<V2RouteWithValidQuote>;\n quoteToken: Token;\n tradeType: TradeType;\n v2PoolProvider: IV2PoolProvider;\n};\n\nexport type RingFewV2RouteWithValidQuoteParams = {\n amount: CurrencyAmount;\n rawQuote: BigNumber;\n percent: number;\n route: RingFewV2Route;\n gasModel: IGasModel<RingFewV2RouteWithValidQuote>;\n quoteToken: Token;\n tradeType: TradeType;\n fewV2PoolProvider: IRingV2PoolProvider;\n};\n/**\n * Represents a quote for swapping on a V2 only route. Contains all information\n * such as the route used, the amount specified by the user, the type of quote\n * (exact in or exact out), the quote itself, and gas estimates.\n *\n * @export\n * @class V2RouteWithValidQuote\n */\nexport class V2RouteWithValidQuote implements IV2RouteWithValidQuote {\n public readonly protocol = Protocol.V2;\n public amount: CurrencyAmount;\n // The BigNumber representing the quote.\n public rawQuote: BigNumber;\n public quote: CurrencyAmount;\n public quoteAdjustedForGas: CurrencyAmount;\n public percent: number;\n public route: V2Route;\n public quoteToken: Token;\n public gasModel: IGasModel<V2RouteWithValidQuote>;\n public gasEstimate: BigNumber;\n public gasCostInToken: CurrencyAmount;\n public gasCostInUSD: CurrencyAmount;\n public gasCostInGasToken?: CurrencyAmount;\n public tradeType: TradeType;\n public poolIdentifiers: string[];\n public tokenPath: Token[];\n\n public toString(): string {\n return `${this.percent.toFixed(\n 2\n )}% QuoteGasAdj[${this.quoteAdjustedForGas.toExact()}] Quote[${this.quote.toExact()}] Gas[${this.gasEstimate.toString()}] = ${routeToString(\n this.route\n )}`;\n }\n\n constructor({\n amount,\n rawQuote,\n percent,\n route,\n gasModel,\n quoteToken,\n tradeType,\n v2PoolProvider,\n }: V2RouteWithValidQuoteParams) {\n this.amount = amount;\n this.rawQuote = rawQuote;\n this.quote = CurrencyAmount.fromRawAmount(quoteToken, rawQuote.toString());\n this.percent = percent;\n this.route = route;\n this.gasModel = gasModel;\n this.quoteToken = quoteToken;\n this.tradeType = tradeType;\n\n const { gasEstimate, gasCostInToken, gasCostInUSD, gasCostInGasToken } =\n this.gasModel.estimateGasCost(this);\n\n this.gasCostInToken = gasCostInToken;\n this.gasCostInUSD = gasCostInUSD;\n this.gasEstimate = gasEstimate;\n this.gasCostInGasToken = gasCostInGasToken;\n\n // If its exact out, we need to request *more* of the input token to account for the gas.\n if (this.tradeType == TradeType.EXACT_INPUT) {\n const quoteGasAdjusted = this.quote.subtract(gasCostInToken);\n this.quoteAdjustedForGas = quoteGasAdjusted;\n } else {\n const quoteGasAdjusted = this.quote.add(gasCostInToken);\n this.quoteAdjustedForGas = quoteGasAdjusted;\n }\n\n this.poolIdentifiers = _.map(\n route.pairs,\n (p) => v2PoolProvider.getPoolAddress(p.token0, p.token1).poolAddress\n );\n\n this.tokenPath = this.route.path;\n }\n}\n\n/**\n * Represents a quote for swapping on a V2 only route. Contains all information\n * such as the route used, the amount specified by the user, the type of quote\n * (exact in or exact out), the quote itself, and gas estimates.\n *\n * @export\n * @class RingFewV2RouteWithValidQuote\n */\nexport class RingFewV2RouteWithValidQuote implements IFewV2RouteWithValidQuote {\n public readonly protocol = Protocol.FEWV2;\n public amount: CurrencyAmount;\n // The BigNumber representing the quote.\n public rawQuote: BigNumber;\n public quote: CurrencyAmount;\n public quoteAdjustedForGas: CurrencyAmount;\n public percent: number;\n public route: RingFewV2Route;\n public quoteToken: Token;\n public gasModel: IGasModel<RingFewV2RouteWithValidQuote>;\n public gasEstimate: BigNumber;\n public gasCostInToken: CurrencyAmount;\n public gasCostInUSD: CurrencyAmount;\n public gasCostInGasToken?: CurrencyAmount;\n public tradeType: TradeType;\n public poolIdentifiers: string[];\n public tokenPath: Token[];\n\n public toString(): string {\n return `${this.percent.toFixed(\n 2\n )}% QuoteGasAdj[${this.quoteAdjustedForGas.toExact()}] Quote[${this.quote.toExact()}] Gas[${this.gasEstimate.toString()}] = ${routeToString(\n this.route\n )}`;\n }\n\n constructor({\n amount,\n rawQuote,\n percent,\n route,\n gasModel,\n quoteToken,\n tradeType,\n fewV2PoolProvider,\n }: RingFewV2RouteWithValidQuoteParams) {\n this.amount = amount;\n this.rawQuote = rawQuote;\n this.quote = CurrencyAmount.fromRawAmount(quoteToken, rawQuote.toString());\n this.percent = percent;\n this.route = route;\n this.gasModel = gasModel;\n this.quoteToken = quoteToken;\n this.tradeType = tradeType;\n\n const { gasEstimate, gasCostInToken, gasCostInUSD, gasCostInGasToken } =\n this.gasModel.estimateGasCost(this);\n\n this.gasCostInToken = gasCostInToken;\n this.gasCostInUSD = gasCostInUSD;\n this.gasEstimate = gasEstimate;\n this.gasCostInGasToken = gasCostInGasToken;\n\n // If its exact out, we need to request *more* of the input token to account for the gas.\n if (this.tradeType == TradeType.EXACT_INPUT) {\n const quoteGasAdjusted = this.quote.subtract(gasCostInToken);\n this.quoteAdjustedForGas = quoteGasAdjusted;\n } else {\n const quoteGasAdjusted = this.quote.add(gasCostInToken);\n this.quoteAdjustedForGas = quoteGasAdjusted;\n }\n\n this.poolIdentifiers = _.map(\n route.pairs,\n (p) => fewV2PoolProvider.getPoolAddress(p.token0, p.token1).poolAddress\n );\n\n this.tokenPath = this.route.path;\n }\n}\n\nexport type V3RouteWithValidQuoteParams = {\n amount: CurrencyAmount;\n rawQuote: BigNumber;\n sqrtPriceX96AfterList: BigNumber[];\n initializedTicksCrossedList: number[];\n quoterGasEstimate: BigNumber;\n percent: number;\n route: V3Route;\n gasModel: IGasModel<V3RouteWithValidQuote>;\n quoteToken: Token;\n tradeType: TradeType;\n v3PoolProvider: IV3PoolProvider;\n};\n\n/**\n * Represents a quote for swapping on a V3 only route. Contains all information\n * such as the route used, the amount specified by the user, the type of quote\n * (exact in or exact out), the quote itself, and gas estimates.\n *\n * @export\n * @class V3RouteWithValidQuote\n */\nexport class V3RouteWithValidQuote implements IV3RouteWithValidQuote {\n public readonly protocol = Protocol.V3;\n public amount: CurrencyAmount;\n public rawQuote: BigNumber;\n public quote: CurrencyAmount;\n public quoteAdjustedForGas: CurrencyAmount;\n public sqrtPriceX96AfterList: BigNumber[];\n public initializedTicksCrossedList: number[];\n public quoterGasEstimate: BigNumber;\n public percent: number;\n public route: V3Route;\n public quoteToken: Token;\n public gasModel: IGasModel<V3RouteWithValidQuote>;\n public gasEstimate: BigNumber;\n public gasCostInToken: CurrencyAmount;\n public gasCostInUSD: CurrencyAmount;\n public gasCostInGasToken?: CurrencyAmount;\n public tradeType: TradeType;\n public poolIdentifiers: string[];\n public tokenPath: Token[];\n\n public toString(): string {\n return `${this.percent.toFixed(\n 2\n )}% QuoteGasAdj[${this.quoteAdjustedForGas.toExact()}] Quote[${this.quote.toExact()}] Gas[${this.gasEstimate.toString()}] = ${routeToString(\n this.route\n )}`;\n }\n\n constructor({\n amount,\n rawQuote,\n sqrtPriceX96AfterList,\n initializedTicksCrossedList,\n quoterGasEstimate,\n percent,\n route,\n gasModel,\n quoteToken,\n tradeType,\n v3PoolProvider,\n }: V3RouteWithValidQuoteParams) {\n this.amount = amount;\n this.rawQuote = rawQuote;\n this.sqrtPriceX96AfterList = sqrtPriceX96AfterList;\n this.initializedTicksCrossedList = initializedTicksCrossedList;\n this.quoterGasEstimate = quoterGasEstimate;\n this.quote = CurrencyAmount.fromRawAmount(quoteToken, rawQuote.toString());\n this.percent = percent;\n this.route = route;\n this.gasModel = gasModel;\n this.quoteToken = quoteToken;\n this.tradeType = tradeType;\n\n const { gasEstimate, gasCostInToken, gasCostInUSD, gasCostInGasToken } =\n this.gasModel.estimateGasCost(this);\n\n this.gasCostInToken = gasCostInToken;\n this.gasCostInUSD = gasCostInUSD;\n this.gasEstimate = gasEstimate;\n this.gasCostInGasToken = gasCostInGasToken;\n\n // If its exact out, we need to request *more* of the input token to account for the gas.\n if (this.tradeType == TradeType.EXACT_INPUT) {\n const quoteGasAdjusted = this.quote.subtract(gasCostInToken);\n this.quoteAdjustedForGas = quoteGasAdjusted;\n } else {\n const quoteGasAdjusted = this.quote.add(gasCostInToken);\n this.quoteAdjustedForGas = quoteGasAdjusted;\n }\n\n this.poolIdentifiers = _.map(\n route.pools,\n (p) =>\n v3PoolProvider.getPoolAddress(p.token0, p.token1, p.fee).poolAddress\n );\n\n this.tokenPath = this.route.tokenPath;\n }\n}\n\nexport type UniswapFewV3RouteWithValidQuoteParams = {\n amount: CurrencyAmount;\n rawQuote: BigNumber;\n sqrtPriceX96AfterList: BigNumber[];\n initializedTicksCrossedList: number[];\n quoterGasEstimate: BigNumber;\n percent: number;\n route: V3Route;\n gasModel: IGasModel<UniswapFewV3RouteWithValidQuote>;\n quoteToken: Token;\n tradeType: TradeType;\n v3PoolProvider: IV3PoolProvider;\n};\n\n/**\n * Represents a quote for swapping on a V3 only route. Contains all information\n * such as the route used, the amount specified by the user, the type of quote\n * (exact in or exact out), the quote itself, and gas estimates.\n *\n * @export\n * @class V3RouteWithValidQuote\n */\nexport class UniswapFewV3RouteWithValidQuote implements IV3RouteWithValidQuote {\n public readonly protocol = Protocol.V3;\n public amount: CurrencyAmount;\n public rawQuote: BigNumber;\n public quote: CurrencyAmount;\n public quoteAdjustedForGas: CurrencyAmount;\n public sqrtPriceX96AfterList: BigNumber[];\n public initializedTicksCrossedList: number[];\n public quoterGasEstimate: BigNumber;\n public percent: number;\n public route: V3Route;\n public quoteToken: Token;\n public gasModel: IGasModel<UniswapFewV3RouteWithValidQuote>;\n public gasEstimate: BigNumber;\n public gasCostInToken: CurrencyAmount;\n public gasCostInUSD: CurrencyAmount;\n public gasCostInGasToken?: CurrencyAmount;\n public tradeType: TradeType;\n public poolIdentifiers: string[];\n public tokenPath: Token[];\n\n public toString(): string {\n return `${this.percent.toFixed(\n 2\n )}% QuoteGasAdj[${this.quoteAdjustedForGas.toExact()}] Quote[${this.quote.toExact()}] Gas[${this.gasEstimate.toString()}] = ${routeToString(\n this.route\n )}`;\n }\n\n constructor({\n amount,\n rawQuote,\n sqrtPriceX96AfterList,\n initializedTicksCrossedList,\n quoterGasEstimate,\n percent,\n route,\n gasModel,\n quoteToken,\n tradeType,\n v3PoolProvider,\n }: UniswapFewV3RouteWithValidQuoteParams) {\n this.amount = amount;\n this.rawQuote = rawQuote;\n this.sqrtPriceX96AfterList = sqrtPriceX96AfterList;\n this.initializedTicksCrossedList = initializedTicksCrossedList;\n this.quoterGasEstimate = quoterGasEstimate;\n this.quote = CurrencyAmount.fromRawAmount(quoteToken, rawQuote.toString());\n this.percent = percent;\n this.route = route;\n this.gasModel = gasModel;\n this.quoteToken = quoteToken;\n this.tradeType = tradeType;\n\n const { gasEstimate, gasCostInToken, gasCostInUSD, gasCostInGasToken } =\n this.gasModel.estimateGasCost(this);\n\n this.gasCostInToken = gasCostInToken;\n this.gasCostInUSD = gasCostInUSD;\n this.gasEstimate = gasEstimate;\n this.gasCostInGasToken = gasCostInGasToken;\n\n // If its exact out, we need to request *more* of the input token to account for the gas.\n if (this.tradeType == TradeType.EXACT_INPUT) {\n const quoteGasAdjusted = this.quote.subtract(gasCostInToken);\n this.quoteAdjustedForGas = quoteGasAdjusted;\n } else {\n const quoteGasAdjusted = this.quote.add(gasCostInToken);\n this.quoteAdjustedForGas = quoteGasAdjusted;\n }\n\n this.poolIdentifiers = _.map(\n route.pools,\n (p) =>\n v3PoolProvider.getPoolAddress(p.token0, p.token1, p.fee).poolAddress\n );\n\n this.tokenPath = this.route.tokenPath;\n }\n}\n\nexport type V4RouteWithValidQuoteParams = {\n amount: CurrencyAmount;\n rawQuote: BigNumber;\n sqrtPriceX96AfterList: BigNumber[];\n initializedTicksCrossedList: number[];\n quoterGasEstimate: BigNumber;\n percent: number;\n route: V4Route;\n quoteToken: Token;\n gasModel: IGasModel<V4RouteWithValidQuote>;\n tradeType: TradeType;\n v4PoolProvider: IV4PoolProvider;\n};\n\nexport class V4RouteWithValidQuote implements IV4RouteWithValidQuote {\n public readonly protocol = Protocol.V4;\n public amount: CurrencyAmount;\n public rawQuote: BigNumber;\n public quote: CurrencyAmount;\n public quoteAdjustedForGas: CurrencyAmount; // TODO: Might be an array in V4 quoter v1\n public sqrtPriceX96AfterList: BigNumber[];\n public initializedTicksCrossedList: number[];\n public quoterGasEstimate: BigNumber; // TODO: not available in v4 quoter v1\n public percent: number;\n public route: V4Route;\n public quoteToken: Token;\n public gasModel: IGasModel<V4RouteWithValidQuote>;\n public gasEstimate: BigNumber;\n public gasCostInToken: CurrencyAmount;\n public gasCostInUSD: CurrencyAmount;\n public gasCostInGasToken?: CurrencyAmount;\n public tradeType: TradeType;\n public poolIdentifiers: string[];\n public tokenPath: Currency[];\n\n public toString(): string {\n return `${this.percent.toFixed(\n 2\n )}% QuoteGasAdj[${this.quoteAdjustedForGas.toExact()}] Quote[${this.quote.toExact()}] Gas[${this.gasEstimate.toString()}] = ${routeToString(\n this.route\n )}`;\n }\n\n constructor({\n amount,\n rawQuote,\n sqrtPriceX96AfterList,\n initializedTicksCrossedList,\n quoterGasEstimate,\n percent,\n route,\n gasModel,\n quoteToken,\n tradeType,\n v4PoolProvider,\n }: V4RouteWithValidQuoteParams) {\n this.amount = amount;\n this.rawQuote = rawQuote;\n this.sqrtPriceX96AfterList = sqrtPriceX96AfterList;\n this.initializedTicksCrossedList = initializedTicksCrossedList;\n this.quoterGasEstimate = quoterGasEstimate;\n this.quote = CurrencyAmount.fromRawAmount(quoteToken, rawQuote.toString());\n this.percent = percent;\n this.route = route;\n this.gasModel = gasModel;\n this.quoteToken = quoteToken;\n this.tradeType = tradeType;\n\n const { gasEstimate, gasCostInToken, gasCostInUSD, gasCostInGasToken } =\n this.gasModel.estimateGasCost(this);\n\n this.gasCostInToken = gasCostInToken;\n this.gasCostInUSD = gasCostInUSD;\n this.gasEstimate = gasEstimate;\n this.gasCostInGasToken = gasCostInGasToken;\n\n // If its exact out, we need to request *more* of the input token to account for the gas.\n if (this.tradeType == TradeType.EXACT_INPUT) {\n const quoteGasAdjusted = this.quote.subtract(gasCostInToken);\n this.quoteAdjustedForGas = quoteGasAdjusted;\n } else {\n const quoteGasAdjusted = this.quote.add(gasCostInToken);\n this.quoteAdjustedForGas = quoteGasAdjusted;\n }\n\n this.poolIdentifiers = _.map(\n route.pools,\n (p) =>\n v4PoolProvider.getPoolId(\n p.token0,\n p.token1,\n p.fee,\n p.tickSpacing,\n p.hooks\n ).poolId\n );\n\n this.tokenPath = this.route.currencyPath;\n }\n}\n\nexport type UniswapFewV4RouteWithValidQuoteParams = {\n amount: CurrencyAmount;\n rawQuote: BigNumber;\n sqrtPriceX96AfterList: BigNumber[];\n initializedTicksCrossedList: number[];\n quoterGasEstimate: BigNumber;\n percent: number;\n route: V4Route;\n quoteToken: Token;\n gasModel: IGasModel<UniswapFewV4RouteWithValidQuote>;\n tradeType: TradeType;\n v4PoolProvider: IV4PoolProvider;\n};\n\nexport class UniswapFewV4RouteWithValidQuote implements IV4RouteWithValidQuote {\n public readonly protocol = Protocol.V4;\n public amount: CurrencyAmount;\n public rawQuote: BigNumber;\n public quote: CurrencyAmount;\n public quoteAdjustedForGas: CurrencyAmount; // TODO: Might be an array in V4 quoter v1\n public sqrtPriceX96AfterList: BigNumber[];\n public initializedTicksCrossedList: number[];\n public quoterGasEstimate: BigNumber; // TODO: not available in v4 quoter v1\n public percent: number;\n public route: V4Route;\n public quoteToken: Token;\n public gasModel: IGasModel<UniswapFewV4RouteWithValidQuote>;\n public gasEstimate: BigNumber;\n public gasCostInToken: CurrencyAmount;\n public gasCostInUSD: CurrencyAmount;\n public gasCostInGasToken?: CurrencyAmount;\n public tradeType: TradeType;\n public poolIdentifiers: string[];\n public tokenPath: Currency[];\n\n public toString(): string {\n return `${this.percent.toFixed(\n 2\n )}% QuoteGasAdj[${this.quoteAdjustedForGas.toExact()}] Quote[${this.quote.toExact()}] Gas[${this.gasEstimate.toString()}] = ${routeToString(\n this.route\n )}`;\n }\n\n constructor({\n amount,\n rawQuote,\n sqrtPriceX96AfterList,\n initializedTicksCrossedList,\n quoterGasEstimate,\n percent,\n route,\n gasModel,\n quoteToken,\n tradeType,\n v4PoolProvider,\n }: UniswapFewV4RouteWithValidQuoteParams) {\n this.amount = amount;\n this.rawQuote = rawQuote;\n this.sqrtPriceX96AfterList = sqrtPriceX96AfterList;\n this.initializedTicksCrossedList = initializedTicksCrossedList;\n this.quoterGasEstimate = quoterGasEstimate;\n this.quote = CurrencyAmount.fromRawAmount(quoteToken, rawQuote.toString());\n this.percent = percent;\n this.route = route;\n this.gasModel = gasModel;\n this.quoteToken = quoteToken;\n this.tradeType = tradeType;\n\n const { gasEstimate, gasCostInToken, gasCostInUSD, gasCostInGasToken } =\n this.gasModel.estimateGasCost(this);\n \n this.gasCostInToken = gasCostInToken;\n this.gasCostInUSD = gasCostInUSD;\n this.gasEstimate = gasEstimate;\n this.gasCostInGasToken = gasCostInGasToken;\n\n // If its exact out, we need to request *more* of the input token to account for the gas.\n if (this.tradeType == TradeType.EXACT_INPUT) {\n const quoteGasAdjusted = this.quote.subtract(gasCostInToken);\n this.quoteAdjustedForGas = quoteGasAdjusted;\n } else {\n const quoteGasAdjusted = this.quote.add(gasCostInToken);\n this.quoteAdjustedForGas = quoteGasAdjusted;\n }\n\n this.poolIdentifiers = _.map(\n route.pools,\n (p) =>\n v4PoolProvider.getPoolId(\n p.token0,\n p.token1,\n p.fee,\n p.tickSpacing,\n p.hooks\n ).poolId\n );\n\n this.tokenPath = this.route.currencyPath;\n }\n}\n\nexport type MixedRouteWithValidQuoteParams = {\n amount: CurrencyAmount;\n rawQuote: BigNumber;\n sqrtPriceX96AfterList: BigNumber[];\n initializedTicksCrossedList: number[];\n quoterGasEstimate: BigNumber;\n percent: number;\n route: MixedRoute;\n mixedRouteGasModel: IGasModel<MixedRouteWithValidQuote>;\n quoteToken: Token;\n tradeType: TradeType;\n v4PoolProvider: IV4PoolProvider;\n v3PoolProvider: IV3PoolProvider;\n v2PoolProvider: IV2PoolProvider;\n};\n\n/**\n * Represents a quote for swapping on a Mixed Route. Contains all information\n * such as the route used, the amount specified by the user, the type of quote\n * (exact in or exact out), the quote itself, and gas estimates.\n *\n * @export\n * @class MixedRouteWithValidQuote\n */\nexport class MixedRouteWithValidQuote implements IMixedRouteWithValidQuote {\n public readonly protocol = Protocol.MIXED;\n public amount: CurrencyAmount;\n public rawQuote: BigNumber;\n public quote: CurrencyAmount;\n public quoteAdjustedForGas: CurrencyAmount;\n public sqrtPriceX96AfterList: BigNumber[];\n public initializedTicksCrossedList: number[];\n public quoterGasEstimate: BigNumber;\n public percent: number;\n public route: MixedRoute;\n public quoteToken: Token;\n public gasModel: IGasModel<MixedRouteWithValidQuote>;\n public gasEstimate: BigNumber;\n public gasCostInToken: CurrencyAmount;\n public gasCostInUSD: CurrencyAmount;\n public gasCostInGasToken?: CurrencyAmount;\n public tradeType: TradeType;\n public poolIdentifiers: string[];\n public tokenPath: Currency[];\n\n public toString(): string {\n return `${this.percent.toFixed(\n 2\n )}% QuoteGasAdj[${this.quoteAdjustedForGas.toExact()}] Quote[${this.quote.toExact()}] Gas[${this.gasEstimate.toString()}] = ${routeToString(\n this.route\n )}`;\n }\n\n constructor({\n amount,\n rawQuote,\n sqrtPriceX96AfterList,\n initializedTicksCrossedList,\n quoterGasEstimate,\n percent,\n route,\n mixedRouteGasModel,\n quoteToken,\n tradeType,\n v4PoolProvider,\n v3PoolProvider,\n v2PoolProvider,\n }: MixedRouteWithValidQuoteParams) {\n this.amount = amount;\n this.rawQuote = rawQuote;\n this.sqrtPriceX96AfterList = sqrtPriceX96AfterList;\n this.initializedTicksCrossedList = initializedTicksCrossedList;\n this.quoterGasEstimate = quoterGasEstimate;\n this.quote = CurrencyAmount.fromRawAmount(quoteToken, rawQuote.toString());\n this.percent = percent;\n this.route = route;\n this.gasModel = mixedRouteGasModel;\n this.quoteToken = quoteToken;\n this.tradeType = tradeType;\n\n const { gasEstimate, gasCostInToken, gasCostInUSD, gasCostInGasToken } =\n this.gasModel.estimateGasCost(this);\n\n this.gasCostInToken = gasCostInToken;\n this.gasCostInUSD = gasCostInUSD;\n this.gasEstimate = gasEstimate;\n this.gasCostInGasToken = gasCostInGasToken;\n\n // If its exact out, we need to request *more* of the input token to account for the gas.\n if (this.tradeType == TradeType.EXACT_INPUT) {\n const quoteGasAdjusted = this.quote.subtract(gasCostInToken);\n this.quoteAdjustedForGas = quoteGasAdjusted;\n } else {\n const quoteGasAdjusted = this.quote.add(gasCostInToken);\n this.quoteAdjustedForGas = quoteGasAdjusted;\n }\n\n this.poolIdentifiers = _.map(route.pools, (p) => {\n if (p instanceof V4Pool) {\n return v4PoolProvider.getPoolId(\n p.token0,\n p.token1,\n p.fee,\n p.tickSpacing,\n p.hooks\n ).poolId;\n } else if (p instanceof V3Pool) {\n return v3PoolProvider.getPoolAddress(p.token0, p.token1, p.fee)\n .poolAddress;\n } else if (p instanceof Pair) {\n return v2PoolProvider.getPoolAddress(p.token0, p.token1).poolAddress;\n } else if (p instanceof FewV2Pair) {\n return v2PoolProvider.getPoolAddress(p.token0, p.token1).poolAddress;\n } else {\n throw new Error(`Unknown pool type ${JSON.stringify(p)}`);\n }\n });\n\n this.tokenPath = this.route.path;\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"best-swap-route.js","sourceRoot":"","sources":["../../../../../src/routers/alpha-router/functions/best-swap-route.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAqD;AACrD,wDAAmD;AACnD,oDAAgF;AAChF,gDAAwB;AACxB,oDAAoC;AACpC,sFAA4D;AAC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CAAC,KAAK,CAAC,QAAQ;QACxC,mBAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAC1C,CAAC;AACJ,CAAC,CAAC;AAPW,QAAA,gCAAgC,oCAO3C;AAEK,MAAM,uCAAuC,GAAG,CACrD,mBAAwC,EAC/B,EAAE;IACX,MAAM,OAAO,GAAG,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC;IAClD,MAAM,kBAAkB,GACtB,8BAAuB,CAAC,OAA+C,CAAC,CAAC;IAC3E,IAAI,CAAC,kBAAkB,EAAE;QACvB,OAAO,KAAK,CAAC;KACd;IACD,OAAO,CACL,CAAC,mBAAmB,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO;QACtC,mBAAmB,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;QACrE,CAAC,mBAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO;YACvC,mBAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CACvE,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,uCAAuC,2CAelD","sourcesContent":["import { BigNumber } from '@ethersproject/bignumber';\nimport { Protocol } from '@fewprotocol/router-sdk';\nimport { ChainId, Fraction, /*Token,*/ TradeType } from '@fewprotocol/sdk-core';\nimport JSBI from 'jsbi';\nimport _ /*,{ sum }*/ from 'lodash';\nimport FixedReverseHeap from 'mnemonist/fixed-reverse-heap';\nimport Queue from 'mnemonist/queue';\n\nimport { IPortionProvider } from '../../../providers/portion-provider';\nimport { ProviderConfig } from '../../../providers/provider';\nimport {\n HAS_L1_FEE,\n V2_SUPPORTED,\n V4_SUPPORTED,\n WRAPPED_NATIVE_CURRENCY,\n} from '../../../util';\nimport { CurrencyAmount } from '../../../util/amounts';\nimport { log } from '../../../util/log';\nimport { metric, MetricLoggerUnit } from '../../../util/metric';\nimport { /*routeAmountsToString,*/ routeToString } from '../../../util/routes';\nimport { SwapOptions } from '../../router';\nimport { AlphaRouterConfig } from '../alpha-router';\nimport { IGasModel, L1ToL2GasCosts, usdGasTokensByChain } from '../gas-models';\n\nimport {\n RouteWithValidQuote,\n V2RouteWithValidQuote,\n V3RouteWithValidQuote,\n V4RouteWithValidQuote,\n} from './../entities/route-with-valid-quote';\n// import { isFewToken } from '../../../util/fewAddress';\n// import { getFewTokenFromOriginalToken } from '@fewprotocol/v2-sdk';\n// import { isFewCurrency } from '../../../util/fewAddress';\n\nexport type BestSwapRoute = {\n quote: CurrencyAmount;\n quoteGasAdjusted: CurrencyAmount;\n estimatedGasUsed: BigNumber;\n estimatedGasUsedUSD: CurrencyAmount;\n estimatedGasUsedQuoteToken: CurrencyAmount;\n estimatedGasUsedGasToken?: CurrencyAmount;\n routes: RouteWithValidQuote[];\n};\n\nexport async function getBestSwapRoute(\n amount: CurrencyAmount,\n percents: number[],\n routesWithValidQuotes: RouteWithValidQuote[],\n routeType: TradeType,\n chainId: ChainId,\n routingConfig: AlphaRouterConfig,\n portionProvider: IPortionProvider,\n v2GasModel?: IGasModel<V2RouteWithValidQuote>,\n v3GasModel?: IGasModel<V3RouteWithValidQuote>,\n v4GasModel?: IGasModel<V4RouteWithValidQuote>,\n swapConfig?: SwapOptions,\n providerConfig?: ProviderConfig\n): Promise<BestSwapRoute | null> {\n const now = Date.now();\n\n const { forceMixedRoutes } = routingConfig;\n\n /// Like with forceCrossProtocol, we apply that logic here when determining the bestSwapRoute\n if (forceMixedRoutes) {\n log.info(\n {\n forceMixedRoutes: forceMixedRoutes,\n },\n 'Forcing mixed routes by filtering out other route types'\n );\n routesWithValidQuotes = _.filter(routesWithValidQuotes, (quotes) => {\n return quotes.protocol === Protocol.MIXED;\n });\n if (!routesWithValidQuotes) {\n return null;\n }\n }\n\n // Build a map of percentage of the input to list of valid quotes.\n // Quotes can be null for a variety of reasons (not enough liquidity etc), so we drop them here too.\n const percentToQuotes: { [percent: number]: RouteWithValidQuote[] } = {};\n for (const routeWithValidQuote of routesWithValidQuotes) {\n if (!percentToQuotes[routeWithValidQuote.percent]) {\n percentToQuotes[routeWithValidQuote.percent] = [];\n }\n percentToQuotes[routeWithValidQuote.percent]!.push(routeWithValidQuote);\n }\n\n metric.putMetric(\n 'BuildRouteWithValidQuoteObjects',\n Date.now() - now,\n MetricLoggerUnit.Milliseconds\n );\n\n // Given all the valid quotes for each percentage find the optimal route.\n const getBestSwapRouteByStartTime = Date.now();\n const swapRoute = await getBestSwapRouteBy(\n routeType,\n percentToQuotes,\n percents,\n chainId,\n (rq: RouteWithValidQuote) => rq.quoteAdjustedForGas,\n routingConfig,\n portionProvider,\n v2GasModel,\n v3GasModel,\n v4GasModel,\n swapConfig,\n providerConfig\n );\n\n const getBestSwapRouteByLatencyMs = Date.now() - getBestSwapRouteByStartTime;\n\n // Add latency metrics.\n metric.putMetric(\n 'GetBestSwapRouteByLatency',\n getBestSwapRouteByLatencyMs,\n MetricLoggerUnit.Milliseconds\n );\n metric.putMetric(\n `GetBestSwapRouteByLatency_Chain${chainId}`,\n getBestSwapRouteByLatencyMs,\n MetricLoggerUnit.Milliseconds\n );\n\n // It is possible we were unable to find any valid route given the quotes.\n if (!swapRoute) {\n return null;\n }\n\n // Due to potential loss of precision when taking percentages of the input it is possible that the sum of the amounts of each\n // route of our optimal quote may not add up exactly to exactIn or exactOut.\n //\n // We check this here, and if there is a mismatch\n // add the missing amount to a random route. The missing amount size should be neglible so the quote should still be highly accurate.\n const { routes: routeAmounts } = swapRoute;\n\n const totalAmount = _.reduce(\n routeAmounts,\n (total, routeAmount) => addFn(total, routeAmount.amount),\n CurrencyAmount.fromRawAmount(routeAmounts[0]!.amount.currency, 0)\n );\n\n const fewAmount = CurrencyAmount.fromRawAmount(totalAmount.currency, amount.quotient);\n\n const missingAmount = fewAmount.subtract(totalAmount);\n\n // const fewMissingAmount = CurrencyAmount.fromRawAmount(totalAmount.currency, 0);\n if (missingAmount.greaterThan(0)) {\n log.info(\n {\n missingAmount: missingAmount.quotient.toString(),\n },\n `Optimal route's amounts did not equal exactIn/exactOut total. Adding missing amount to last route in array.`\n );\n\n routeAmounts[routeAmounts.length - 1]!.amount =\n routeAmounts[routeAmounts.length - 1]!.amount.add(missingAmount);\n }\n\n // log.info(\n // {\n // routes: routeAmountsToString(routeAmounts),\n // numSplits: routeAmounts.length,\n // amount: amount.toExact(),\n // quote: swapRoute.quote.toExact(),\n // quoteGasAdjusted: swapRoute.quoteGasAdjusted.toFixed(\n // Math.min(swapRoute.quoteGasAdjusted.currency.decimals, 2)\n // ),\n // estimatedGasUSD: swapRoute.estimatedGasUsedUSD.toFixed(\n // Math.min(swapRoute.estimatedGasUsedUSD.currency.decimals, 2)\n // ),\n // estimatedGasToken: swapRoute.estimatedGasUsedQuoteToken.toFixed(\n // Math.min(swapRoute.estimatedGasUsedQuoteToken.currency.decimals, 2)\n // ),\n // },\n // `Found best swap route. ${routeAmounts.length} split.`\n // );\n\n return swapRoute;\n}\n\nexport function addFn(first: CurrencyAmount, second: CurrencyAmount): CurrencyAmount {\n // invariant(first.currency.equals(second.currency), 'CURRENCY')\n // const added = first.add(second)\n // console.log(\"[addFn] -- added=\", added.toExact());\n let addedFraction: Fraction;\n const otherParsed = second.asFraction\n if (JSBI.equal(first.denominator, otherParsed.denominator)) {\n addedFraction = new Fraction(JSBI.add(first.numerator, otherParsed.numerator), first.denominator)\n } else {\n addedFraction = new Fraction(\n JSBI.add(\n JSBI.multiply(first.numerator, otherParsed.denominator),\n JSBI.multiply(otherParsed.numerator, first.denominator)\n ),\n JSBI.multiply(first.denominator, otherParsed.denominator)\n )\n }\n\n return CurrencyAmount.fromFractionalAmount(first.currency, addedFraction.numerator, addedFraction.denominator)\n}\n\nexport async function getBestSwapRouteBy(\n routeType: TradeType,\n percentToQuotes: { [percent: number]: RouteWithValidQuote[] },\n percents: number[],\n chainId: ChainId,\n by: (routeQuote: RouteWithValidQuote) => CurrencyAmount,\n routingConfig: AlphaRouterConfig,\n portionProvider: IPortionProvider,\n v2GasModel?: IGasModel<V2RouteWithValidQuote>,\n v3GasModel?: IGasModel<V3RouteWithValidQuote>,\n v4GasModel?: IGasModel<V4RouteWithValidQuote>,\n swapConfig?: SwapOptions,\n providerConfig?: ProviderConfig\n): Promise<BestSwapRoute | undefined> {\n\n // Build a map of percentage to sorted list of quotes, with the biggest quote being first in the list.\n const percentToSortedQuotes = _.mapValues(\n percentToQuotes,\n (routeQuotes: RouteWithValidQuote[]) => {\n return routeQuotes.sort((routeQuoteA, routeQuoteB) => {\n if (routeType == TradeType.EXACT_INPUT) {\n return by(routeQuoteA).greaterThan(by(routeQuoteB)) ? -1 : 1;\n } else {\n return by(routeQuoteA).lessThan(by(routeQuoteB)) ? -1 : 1;\n }\n });\n }\n );\n\n const quoteCompFn =\n routeType == TradeType.EXACT_INPUT\n ? (a: CurrencyAmount, b: CurrencyAmount) => a.greaterThan(b)\n : (a: CurrencyAmount, b: CurrencyAmount) => a.lessThan(b);\n\n const sumFn = (currencyAmounts: CurrencyAmount[]): CurrencyAmount => {\n let sum = currencyAmounts[0]!;\n for (let i = 1; i < currencyAmounts.length; i++) {\n sum = sum.add(currencyAmounts[i]!);\n }\n return sum;\n };\n\n //compatible with few\n //ts-ignore\n\n\n const _sumFnFew = (currencyAmounts: CurrencyAmount[]): CurrencyAmount => {\n let sum = currencyAmounts[0]!;\n // const theFirstIsFewToken = isFewCurrency(sum.currency);\n for (let i = 1; i < currencyAmounts.length; i++) {\n const currencyAmount = currencyAmounts[i]!;\n // const currencyAsToken = currencyAmounts[i]!.currency as Token;\n\n // if (isFewCurrency(currencyAsToken) === theFirstIsFewToken) {\n sum = addFn(sum, currencyAmount);\n // continue;\n // }\n\n // if (theFirstIsFewToken) {\n // console.log(\"[sumFnFew] -- 添加fw\", currencyAsToken.symbol);\n\n // //convert to few token\n // let temp_currencyAmount = CurrencyAmount.fromFractionalAmount(getFewTokenFromOriginalToken(currencyAsToken, chainId), currencyAmount.numerator, currencyAmount.denominator);\n // sum = sum.add(temp_currencyAmount);\n // console.log(\"[sumFnFew] --success 添加fw\");\n // }\n // else {\n // console.log(\"[sumFnFew] -- 去掉fw\", currencyAsToken.symbol);\n\n // //convert to none few token\n // const unwrap_token = new Token(chainId, currencyAsToken.address, currencyAsToken.decimals, currencyAsToken.symbol?.replace(/^fw/i, ''), undefined);\n // const temp_currencyAmount = CurrencyAmount.fromFractionalAmount(unwrap_token, currencyAmount.numerator, currencyAmount.denominator);\n // console.log(\"[sumFnFew] -- temp_currencyAmount=\", temp_currencyAmount);\n // sum = sum.add(temp_currencyAmount);\n // console.log(\"[sumFnFew] --success 去掉fw\");\n // }\n }\n return sum;\n };\n\n\n let bestQuote: CurrencyAmount | undefined;\n let bestSwap: RouteWithValidQuote[] | undefined;\n\n // Min-heap for tracking the 5 best swaps given some number of splits.\n const bestSwapsPerSplit = new FixedReverseHeap<{\n quote: CurrencyAmount;\n routes: RouteWithValidQuote[];\n }>(\n Array,\n (a, b) => {\n return quoteCompFn(a.quote, b.quote) ? -1 : 1;\n },\n 3\n );\n\n const { minSplits, maxSplits, forceCrossProtocol } = routingConfig;\n\n if (!percentToSortedQuotes[100] || minSplits > 1 || forceCrossProtocol) {\n log.info(\n {\n percentToSortedQuotes: _.mapValues(\n percentToSortedQuotes,\n (p) => p.length\n ),\n },\n 'Did not find a valid route without any splits. Continuing search anyway.'\n );\n } else {\n bestQuote = by(percentToSortedQuotes[100][0]!);\n bestSwap = [percentToSortedQuotes[100][0]!];\n\n for (const routeWithQuote of percentToSortedQuotes[100].slice(0, 5)) {\n bestSwapsPerSplit.push({\n quote: by(routeWithQuote),\n routes: [routeWithQuote],\n });\n }\n }\n\n // We do a BFS. Each additional node in a path represents us adding an additional split to the route.\n const queue = new Queue<{\n percentIndex: number;\n curRoutes: RouteWithValidQuote[];\n remainingPercent: number;\n special: boolean;\n }>();\n\n // First we seed BFS queue with the best quotes for each percentage.\n // i.e. [best quote when sending 10% of amount, best quote when sending 20% of amount, ...]\n // We will explore the various combinations from each node.\n for (let i = percents.length; i >= 0; i--) {\n const percent = percents[i]!;\n\n if (!percentToSortedQuotes[percent]) {\n continue;\n }\n\n queue.enqueue({\n curRoutes: [percentToSortedQuotes[percent]![0]!],\n percentIndex: i,\n remainingPercent: 100 - percent,\n special: false,\n });\n\n if (\n !percentToSortedQuotes[percent] ||\n !percentToSortedQuotes[percent]![1]\n ) {\n continue;\n }\n\n queue.enqueue({\n curRoutes: [percentToSortedQuotes[percent]![1]!],\n percentIndex: i,\n remainingPercent: 100 - percent,\n special: true,\n });\n }\n\n let splits = 1;\n let startedSplit = Date.now();\n\n while (queue.size > 0) {\n metric.putMetric(\n `Split${splits}Done`,\n Date.now() - startedSplit,\n MetricLoggerUnit.Milliseconds\n );\n\n metric.putMetric(\n `Split${splits}Done_Chain${chainId}`,\n Date.now() - startedSplit,\n MetricLoggerUnit.Milliseconds\n );\n\n startedSplit = Date.now();\n\n log.info(\n {\n top5: _.map(\n Array.from(bestSwapsPerSplit.consume()),\n (q) =>\n `${q.quote.toExact()} (${_(q.routes)\n .map((r) => r.toString())\n .join(', ')})`\n ),\n onQueue: queue.size,\n },\n `Top 3 with ${splits} splits`\n );\n\n bestSwapsPerSplit.clear();\n\n // Size of the queue at this point is the number of potential routes we are investigating for the given number of splits.\n let layer = queue.size;\n splits++;\n\n // If we didn't improve our quote by adding another split, very unlikely to improve it by splitting more after that.\n if (splits >= 3 && bestSwap && bestSwap.length < splits - 1) {\n break;\n }\n\n if (splits > maxSplits) {\n log.info('Max splits reached. Stopping search.');\n metric.putMetric(`MaxSplitsHitReached`, 1, MetricLoggerUnit.Count);\n break;\n }\n\n while (layer > 0) {\n layer--;\n\n const { remainingPercent, curRoutes, percentIndex, special } =\n queue.dequeue()!;\n\n // For all other percentages, add a new potential route.\n // E.g. if our current aggregated route if missing 50%, we will create new nodes and add to the queue for:\n // 50% + new 10% route, 50% + new 20% route, etc.\n for (let i = percentIndex; i >= 0; i--) {\n const percentA = percents[i]!;\n\n if (percentA > remainingPercent) {\n continue;\n }\n\n // At some point the amount * percentage is so small that the quoter is unable to get\n // a quote. In this case there could be no quotes for that percentage.\n if (!percentToSortedQuotes[percentA]) {\n continue;\n }\n\n const candidateRoutesA = percentToSortedQuotes[percentA]!;\n\n // Find the best route in the complimentary percentage that doesn't re-use a pool already\n // used in the current route. Re-using pools is not allowed as each swap through a pool changes its liquidity,\n // so it would make the quotes inaccurate.\n const routeWithQuoteA = findFirstRouteNotUsingUsedPools(\n curRoutes,\n candidateRoutesA,\n forceCrossProtocol\n );\n\n if (!routeWithQuoteA) {\n continue;\n }\n\n const remainingPercentNew = remainingPercent - percentA;\n const curRoutesNew = [...curRoutes, routeWithQuoteA];\n\n // If we've found a route combination that uses all 100%, and it has at least minSplits, update our best route.\n if (remainingPercentNew == 0 && splits >= minSplits) {\n const quotesNew = _.map(curRoutesNew, (r) => by(r));\n const quoteNew = _sumFnFew(quotesNew);\n\n let gasCostL1QuoteToken = CurrencyAmount.fromRawAmount(\n quoteNew.currency,\n 0\n );\n\n if (HAS_L1_FEE.includes(chainId)) {\n if (\n v2GasModel == undefined &&\n v3GasModel == undefined &&\n v4GasModel == undefined\n ) {\n throw new Error(\"Can't compute L1 gas fees.\");\n } else {\n\n // ROUTE-249: consoliate L1 + L2 gas fee adjustment within best-swap-route\n const v2Routes = curRoutesNew.filter(\n (routes) => routes.protocol === Protocol.V2\n );\n if (v2Routes.length > 0 && V2_SUPPORTED.includes(chainId)) {\n if (v2GasModel) {\n const v2GasCostL1 = await v2GasModel.calculateL1GasFees!(\n v2Routes as V2RouteWithValidQuote[]\n );\n gasCostL1QuoteToken = gasCostL1QuoteToken.add(\n v2GasCostL1.gasCostL1QuoteToken\n );\n }\n }\n\n const v3Routes = curRoutesNew.filter(\n (routes) => routes.protocol === Protocol.V3\n );\n if (v3Routes.length > 0) {\n if (v3GasModel) {\n const v3GasCostL1 = await v3GasModel.calculateL1GasFees!(\n v3Routes as V3RouteWithValidQuote[]\n );\n gasCostL1QuoteToken = gasCostL1QuoteToken.add(\n v3GasCostL1.gasCostL1QuoteToken\n );\n }\n }\n\n const v4Routes = curRoutesNew.filter(\n (routes) => routes.protocol === Protocol.V4\n );\n if (v4Routes.length > 0 && V4_SUPPORTED.includes(chainId)) {\n if (v4GasModel) {\n const v4GasCostL1 = await v4GasModel.calculateL1GasFees!(\n v4Routes as V4RouteWithValidQuote[]\n );\n gasCostL1QuoteToken = gasCostL1QuoteToken.add(\n v4GasCostL1.gasCostL1QuoteToken\n );\n }\n }\n }\n }\n\n const quoteAfterL1Adjust =\n routeType == TradeType.EXACT_INPUT\n ? quoteNew.subtract(gasCostL1QuoteToken)\n : quoteNew.add(gasCostL1QuoteToken);\n\n bestSwapsPerSplit.push({\n quote: quoteAfterL1Adjust,\n routes: curRoutesNew,\n });\n\n if (!bestQuote || quoteCompFn(quoteAfterL1Adjust, bestQuote)) {\n bestQuote = quoteAfterL1Adjust;\n bestSwap = curRoutesNew;\n\n // Temporary experiment.\n if (special) {\n metric.putMetric(\n `BestSwapNotPickingBestForPercent`,\n 1,\n MetricLoggerUnit.Count\n );\n }\n }\n\n } else {\n\n queue.enqueue({\n curRoutes: curRoutesNew,\n remainingPercent: remainingPercentNew,\n percentIndex: i,\n special,\n });\n }\n }\n }\n }\n\n if (!bestSwap) {\n log.info(`Could not find a valid swap`);\n return undefined;\n }\n\n const postSplitNow = Date.now();\n\n let quoteGasAdjusted = _sumFnFew(\n _.map(\n bestSwap,\n (routeWithValidQuote) => routeWithValidQuote.quoteAdjustedForGas\n )\n );\n\n // this calculates the base gas used\n // if on L1, its the estimated gas used based on hops and ticks across all the routes\n // if on L2, its the gas used on the L2 based on hops and ticks across all the routes\n const estimatedGasUsed = _(bestSwap)\n .map((routeWithValidQuote) => routeWithValidQuote.gasEstimate)\n .reduce(\n (sum, routeWithValidQuote) => sum.add(routeWithValidQuote),\n BigNumber.from(0)\n );\n\n if (!usdGasTokensByChain[chainId] || !usdGasTokensByChain[chainId]![0]) {\n // Each route can use a different stablecoin to account its gas costs.\n // They should all be pegged, and this is just an estimate, so we do a merge\n // to an arbitrary stable.\n throw new Error(\n `Could not find a USD token for computing gas costs on ${chainId}`\n );\n }\n const usdToken = usdGasTokensByChain[chainId]![0]!;\n const usdTokenDecimals = usdToken.decimals;\n\n // if on L2, calculate the L1 security fee\n const gasCostsL1ToL2: L1ToL2GasCosts = {\n gasUsedL1: BigNumber.from(0),\n gasUsedL1OnL2: BigNumber.from(0),\n gasCostL1USD: CurrencyAmount.fromRawAmount(usdToken, 0),\n gasCostL1QuoteToken: CurrencyAmount.fromRawAmount(\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n bestSwap[0]?.quoteToken!,\n 0\n ),\n };\n\n // If swapping on an L2 that includes a L1 security fee, calculate the fee and include it in the gas adjusted quotes\n if (HAS_L1_FEE.includes(chainId)) {\n // ROUTE-249: consoliate L1 + L2 gas fee adjustment within best-swap-route\n if (\n v2GasModel == undefined &&\n v3GasModel == undefined &&\n v4GasModel == undefined\n ) {\n throw new Error(\"Can't compute L1 gas fees.\");\n } else {\n // Before v2 deploy everywhere, a quote on L2 can only go through v3 protocol,\n // so a split between v2 and v3 is not possible.\n // After v2 deploy everywhere, a quote on L2 can go through v2 AND v3 protocol.\n // Since a split is possible now, the gas cost will be the summation of both v2 and v3 gas models.\n // So as long as any route contains v2/v3 protocol, we will calculate the gas cost accumulatively.\n const v2Routes = bestSwap.filter(\n (routes) => routes.protocol === Protocol.V2\n );\n if (v2Routes.length > 0 && V2_SUPPORTED.includes(chainId)) {\n if (v2GasModel) {\n const v2GasCostL1 = await v2GasModel.calculateL1GasFees!(\n v2Routes as V2RouteWithValidQuote[]\n );\n gasCostsL1ToL2.gasUsedL1 = gasCostsL1ToL2.gasUsedL1.add(\n v2GasCostL1.gasUsedL1\n );\n gasCostsL1ToL2.gasUsedL1OnL2 = gasCostsL1ToL2.gasUsedL1OnL2.add(\n v2GasCostL1.gasUsedL1OnL2\n );\n if (\n gasCostsL1ToL2.gasCostL1USD.currency.equals(\n v2GasCostL1.gasCostL1USD.currency\n )\n ) {\n gasCostsL1ToL2.gasCostL1USD = gasCostsL1ToL2.gasCostL1USD.add(\n v2GasCostL1.gasCostL1USD\n );\n } else {\n // This is to handle the case where gasCostsL1ToL2.gasCostL1USD and v2GasCostL1.gasCostL1USD have different currencies.\n //\n // gasCostsL1ToL2.gasCostL1USD was initially hardcoded to CurrencyAmount.fromRawAmount(usdGasTokensByChain[chainId]![0]!, 0)\n // (https://github.com/Uniswap/smart-order-router/blob/main/src/routers/alpha-router/functions/best-swap-route.ts#L438)\n // , where usdGasTokensByChain is coded in the descending order of decimals per chain,\n // e.g. Arbitrum_one DAI (18 decimals), USDC bridged (6 decimals), USDC native (6 decimals)\n // so gasCostsL1ToL2.gasCostL1USD will have DAI as currency.\n //\n // For v2GasCostL1.gasCostL1USD, it's calculated within getHighestLiquidityUSDPool among usdGasTokensByChain[chainId]!,\n // (https://github.com/Uniswap/smart-order-router/blob/b970aedfec8a9509f9e22f14cc5c11be54d47b35/src/routers/alpha-router/gas-models/v2/v2-heuristic-gas-model.ts#L220)\n // , so the code will actually see which USD pool has the highest liquidity, if any.\n // e.g. Arbitrum_one on v2 only has liquidity on USDC native\n // so v2GasCostL1.gasCostL1USD will have USDC native as currency.\n //\n // We will re-assign gasCostsL1ToL2.gasCostL1USD to v2GasCostL1.gasCostL1USD in this case.\n gasCostsL1ToL2.gasCostL1USD = v2GasCostL1.gasCostL1USD;\n }\n gasCostsL1ToL2.gasCostL1QuoteToken =\n gasCostsL1ToL2.gasCostL1QuoteToken.add(\n v2GasCostL1.gasCostL1QuoteToken\n );\n }\n }\n const v3Routes = bestSwap.filter(\n (routes) => routes.protocol === Protocol.V3\n );\n if (v3Routes.length > 0) {\n if (v3GasModel) {\n const v3GasCostL1 = await v3GasModel.calculateL1GasFees!(\n v3Routes as V3RouteWithValidQuote[]\n );\n gasCostsL1ToL2.gasUsedL1 = gasCostsL1ToL2.gasUsedL1.add(\n v3GasCostL1.gasUsedL1\n );\n gasCostsL1ToL2.gasUsedL1OnL2 = gasCostsL1ToL2.gasUsedL1OnL2.add(\n v3GasCostL1.gasUsedL1OnL2\n );\n if (\n gasCostsL1ToL2.gasCostL1USD.currency.equals(\n v3GasCostL1.gasCostL1USD.currency\n )\n ) {\n gasCostsL1ToL2.gasCostL1USD = gasCostsL1ToL2.gasCostL1USD.add(\n v3GasCostL1.gasCostL1USD\n );\n } else {\n // This is to handle the case where gasCostsL1ToL2.gasCostL1USD and v3GasCostL1.gasCostL1USD have different currencies.\n //\n // gasCostsL1ToL2.gasCostL1USD was initially hardcoded to CurrencyAmount.fromRawAmount(usdGasTokensByChain[chainId]![0]!, 0)\n // (https://github.com/Uniswap/smart-order-router/blob/main/src/routers/alpha-router/functions/best-swap-route.ts#L438)\n // , where usdGasTokensByChain is coded in the descending order of decimals per chain,\n // e.g. Arbitrum_one DAI (18 decimals), USDC bridged (6 decimals), USDC native (6 decimals)\n // so gasCostsL1ToL2.gasCostL1USD will have DAI as currency.\n //\n // For v3GasCostL1.gasCostL1USD, it's calculated within getHighestLiquidityV3USDPool among usdGasTokensByChain[chainId]!,\n // (https://github.com/Uniswap/smart-order-router/blob/1c93e133c46af545f8a3d8af7fca3f1f2dcf597d/src/util/gas-factory-helpers.ts#L110)\n // , so the code will actually see which USD pool has the highest liquidity, if any.\n // e.g. Arbitrum_one on v3 has highest liquidity on USDC native\n // so v3GasCostL1.gasCostL1USD will have USDC native as currency.\n //\n // We will re-assign gasCostsL1ToL2.gasCostL1USD to v3GasCostL1.gasCostL1USD in this case.\n gasCostsL1ToL2.gasCostL1USD = v3GasCostL1.gasCostL1USD;\n }\n gasCostsL1ToL2.gasCostL1QuoteToken =\n gasCostsL1ToL2.gasCostL1QuoteToken.add(\n v3GasCostL1.gasCostL1QuoteToken\n );\n }\n }\n const v4Routes = bestSwap.filter(\n (routes) => routes.protocol === Protocol.V4\n );\n if (v4Routes.length > 0 && V4_SUPPORTED.includes(chainId)) {\n if (v4GasModel) {\n const v4GasCostL1 = await v4GasModel.calculateL1GasFees!(\n v4Routes as V4RouteWithValidQuote[]\n );\n gasCostsL1ToL2.gasUsedL1 = gasCostsL1ToL2.gasUsedL1.add(\n v4GasCostL1.gasUsedL1\n );\n gasCostsL1ToL2.gasUsedL1OnL2 = gasCostsL1ToL2.gasUsedL1OnL2.add(\n v4GasCostL1.gasUsedL1OnL2\n );\n if (\n gasCostsL1ToL2.gasCostL1USD.currency.equals(\n v4GasCostL1.gasCostL1USD.currency\n )\n ) {\n gasCostsL1ToL2.gasCostL1USD = gasCostsL1ToL2.gasCostL1USD.add(\n v4GasCostL1.gasCostL1USD\n );\n } else {\n // This is to handle the case where gasCostsL1ToL2.gasCostL1USD and v4GasCostL1.gasCostL1USD have different currencies.\n //\n // gasCostsL1ToL2.gasCostL1USD was initially hardcoded to CurrencyAmount.fromRawAmount(usdGasTokensByChain[chainId]![0]!, 0)\n // (https://github.com/Uniswap/smart-order-router/blob/main/src/routers/alpha-router/functions/best-swap-route.ts#L438)\n // , where usdGasTokensByChain is coded in the descending order of decimals per chain,\n // e.g. Arbitrum_one DAI (18 decimals), USDC bridged (6 decimals), USDC native (6 decimals)\n // so gasCostsL1ToL2.gasCostL1USD will have DAI as currency.\n //\n // For v4GasCostL1.gasCostL1USD, it's calculated within getHighestLiquidityV3USDPool among usdGasTokensByChain[chainId]!,\n // (https://github.com/Uniswap/smart-order-router/blob/1c93e133c46af545f8a3d8af7fca3f1f2dcf597d/src/util/gas-factory-helpers.ts#L110)\n // , so the code will actually see which USD pool has the highest liquidity, if any.\n // e.g. Arbitrum_one on v3 has highest liquidity on USDC native\n // so v4GasCostL1.gasCostL1USD will have USDC native as currency.\n //\n // We will re-assign gasCostsL1ToL2.gasCostL1USD to v3GasCostL1.gasCostL1USD in this case.\n gasCostsL1ToL2.gasCostL1USD = v4GasCostL1.gasCostL1USD;\n }\n gasCostsL1ToL2.gasCostL1QuoteToken =\n gasCostsL1ToL2.gasCostL1QuoteToken.add(\n v4GasCostL1.gasCostL1QuoteToken\n );\n }\n }\n }\n }\n\n const { gasUsedL1OnL2, gasCostL1USD, gasCostL1QuoteToken } = gasCostsL1ToL2;\n\n // For each gas estimate, normalize decimals to that of the chosen usd token.\n const estimatedGasUsedUSDs = _(bestSwap)\n .map((routeWithValidQuote) => {\n // TODO: will error if gasToken has decimals greater than usdToken\n const decimalsDiff =\n usdTokenDecimals - routeWithValidQuote.gasCostInUSD.currency.decimals;\n\n if (decimalsDiff == 0) {\n return CurrencyAmount.fromRawAmount(\n usdToken,\n routeWithValidQuote.gasCostInUSD.quotient\n );\n }\n\n if (decimalsDiff < 0) {\n // Handle negative decimals difference by using division instead of multiplication\n log.warn(`Decimals diff is negative: ${decimalsDiff}. Using division to handle this case.\n usdTokenDecimals ${usdTokenDecimals} routeWithValidQuote.gasCostInUSD.currency.decimals\n ${routeWithValidQuote.gasCostInUSD.currency.decimals}`);\n \n return CurrencyAmount.fromRawAmount(\n usdToken,\n JSBI.divide(\n routeWithValidQuote.gasCostInUSD.quotient,\n JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(-decimalsDiff))\n )\n );\n }\n\n return CurrencyAmount.fromRawAmount(\n usdToken,\n JSBI.multiply(\n routeWithValidQuote.gasCostInUSD.quotient,\n JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(decimalsDiff))\n )\n );\n })\n .value();\n\n let estimatedGasUsedUSD = sumFn(estimatedGasUsedUSDs);\n\n // if they are different usd pools, convert to the usdToken\n if (estimatedGasUsedUSD.currency != gasCostL1USD.currency) {\n const decimalsDiff = usdTokenDecimals - gasCostL1USD.currency.decimals;\n estimatedGasUsedUSD = estimatedGasUsedUSD.add(\n CurrencyAmount.fromRawAmount(\n usdToken,\n JSBI.multiply(\n gasCostL1USD.quotient,\n JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(decimalsDiff))\n )\n )\n );\n } else {\n estimatedGasUsedUSD = estimatedGasUsedUSD.add(gasCostL1USD);\n }\n\n log.info(\n {\n estimatedGasUsedUSD: estimatedGasUsedUSD.toExact(),\n normalizedUsdToken: usdToken,\n routeUSDGasEstimates: _.map(\n bestSwap,\n (b) =>\n `${b.percent}% ${routeToString(b.route)} ${b.gasCostInUSD.toExact()}`\n ),\n flatL1GasCostUSD: gasCostL1USD.toExact(),\n },\n 'USD gas estimates of best route'\n );\n const estimatedGasUsedQuoteToken = _sumFnFew(\n _.map(bestSwap, (routeWithValidQuote) => routeWithValidQuote.gasCostInToken)\n ).add(gasCostL1QuoteToken);\n\n let estimatedGasUsedGasToken: CurrencyAmount | undefined;\n if (routingConfig.gasToken) {\n // sum the gas costs in the gas token across all routes\n // if there is a route with undefined gasCostInGasToken, throw an error\n if (\n bestSwap.some(\n (routeWithValidQuote) =>\n routeWithValidQuote.gasCostInGasToken === undefined\n )\n ) {\n log.info(\n {\n bestSwap,\n routingConfig,\n },\n 'Could not find gasCostInGasToken for a route in bestSwap'\n );\n throw new Error(\"Can't compute estimatedGasUsedGasToken\");\n }\n estimatedGasUsedGasToken = sumFn(\n _.map(\n bestSwap,\n // ok to type cast here because we throw above if any are not defined\n (routeWithValidQuote) =>\n routeWithValidQuote.gasCostInGasToken as CurrencyAmount\n )\n );\n }\n\n const quote = _sumFnFew(\n _.map(bestSwap, (routeWithValidQuote) => routeWithValidQuote.quote)\n );\n\n // Adjust the quoteGasAdjusted for the l1 fee\n if (routeType == TradeType.EXACT_INPUT) {\n const quoteGasAdjustedForL1 =\n quoteGasAdjusted.subtract(gasCostL1QuoteToken);\n quoteGasAdjusted = quoteGasAdjustedForL1;\n } else {\n const quoteGasAdjustedForL1 = quoteGasAdjusted.add(gasCostL1QuoteToken);\n quoteGasAdjusted = quoteGasAdjustedForL1;\n }\n\n const routeWithQuotes = bestSwap.sort((routeAmountA, routeAmountB) =>\n routeAmountB.amount.greaterThan(routeAmountA.amount) ? 1 : -1\n );\n\n metric.putMetric(\n 'PostSplitDone',\n Date.now() - postSplitNow,\n MetricLoggerUnit.Milliseconds\n );\n return {\n quote,\n quoteGasAdjusted,\n estimatedGasUsed: estimatedGasUsed.add(gasUsedL1OnL2),\n estimatedGasUsedUSD,\n estimatedGasUsedQuoteToken,\n estimatedGasUsedGasToken,\n routes: portionProvider.getRouteWithQuotePortionAdjusted(\n routeType,\n routeWithQuotes,\n swapConfig,\n providerConfig\n ),\n };\n}\n\n// We do not allow pools to be re-used across split routes, as swapping through a pool changes the pools state.\n// Given a list of used routes, this function finds the first route in the list of candidate routes that does not re-use an already used pool.\nconst findFirstRouteNotUsingUsedPools = (\n usedRoutes: RouteWithValidQuote[],\n candidateRouteQuotes: RouteWithValidQuote[],\n forceCrossProtocol: boolean\n): RouteWithValidQuote | null => {\n const poolAddressSet = new Set();\n const usedPoolAddresses = _(usedRoutes)\n .flatMap((r) => r.poolIdentifiers)\n .value();\n\n for (const poolAddress of usedPoolAddresses) {\n poolAddressSet.add(poolAddress);\n }\n\n const protocolsSet = new Set();\n const usedProtocols = _(usedRoutes)\n .flatMap((r) => r.protocol)\n .uniq()\n .value();\n\n for (const protocol of usedProtocols) {\n protocolsSet.add(protocol);\n }\n\n for (const routeQuote of candidateRouteQuotes) {\n const { poolIdentifiers: poolAddresses, protocol } = routeQuote;\n\n if (poolAddresses.some((poolAddress) => poolAddressSet.has(poolAddress))) {\n continue;\n }\n\n // This code is just for debugging. Allows us to force a cross-protocol split route by skipping\n // consideration of routes that come from the same protocol as a used route.\n const needToForce = forceCrossProtocol && protocolsSet.size == 1;\n if (needToForce && protocolsSet.has(protocol)) {\n continue;\n }\n\n // Note: Below is a temporary fix until we have this logic handled in the SDK level.\n // If any previous route has Native token, don't allow Wrapped Native token routes and vice versa\n const hasNativeInUsedRoutes = usedRoutes.some(\n routeHasNativeTokenInputOrOutput\n );\n const hasWrappedNativeInUsedRoutes = usedRoutes.some(\n routeHasWrappedNativeTokenInputOrOutput\n );\n\n if (\n (hasNativeInUsedRoutes &&\n routeHasWrappedNativeTokenInputOrOutput(routeQuote)) ||\n (hasWrappedNativeInUsedRoutes &&\n routeHasNativeTokenInputOrOutput(routeQuote))\n ) {\n continue;\n }\n\n return routeQuote;\n }\n\n return null;\n};\n\nexport const routeHasNativeTokenInputOrOutput = (\n routeWithValidQuote: RouteWithValidQuote\n): boolean => {\n return (\n routeWithValidQuote.route.input.isNative ||\n routeWithValidQuote.route.output.isNative\n );\n};\n\nexport const routeHasWrappedNativeTokenInputOrOutput = (\n routeWithValidQuote: RouteWithValidQuote\n): boolean => {\n const chainId = routeWithValidQuote.route.chainId;\n const wrappedNativeToken =\n WRAPPED_NATIVE_CURRENCY[chainId as keyof typeof WRAPPED_NATIVE_CURRENCY];\n if (!wrappedNativeToken) {\n return false;\n }\n return (\n (routeWithValidQuote.route.input.isToken &&\n routeWithValidQuote.route.input.wrapped.equals(wrappedNativeToken)) ||\n (routeWithValidQuote.route.output.isToken &&\n routeWithValidQuote.route.output.wrapped.equals(wrappedNativeToken))\n );\n};\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculate-ratio-amount-in.js","sourceRoot":"","sources":["../../../../../src/routers/alpha-router/functions/calculate-ratio-amount-in.ts"],"names":[],"mappings":";;;AAAA,oDAAiD;AAEjD,mDAAuD;AAEvD,SAAgB,sBAAsB,CACpC,YAAsB,EACtB,eAAyB,EACzB,YAA4B,EAC5B,aAA6B;IAE7B,oHAAoH;IACpH,MAAM,eAAe,GAAG,IAAI,mBAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC;SACxD,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;SACvD,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAEzD,IAAI,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;QAC/B,2DAA2D;QAC3D,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;KAClE;IAED,OAAO,wBAAc,CAAC,aAAa,CACjC,YAAY,CAAC,QAAQ,EACrB,eAAe,CAAC,QAAQ,CACzB,CAAC;AACJ,CAAC;AApBD,wDAoBC","sourcesContent":["import { Fraction } from '@fewprotocol/sdk-core';\n\nimport { CurrencyAmount } from '../../../util/amounts';\n\nexport function calculateRatioAmountIn(\n optimalRatio: Fraction,\n inputTokenPrice: Fraction,\n inputBalance: CurrencyAmount,\n outputBalance: CurrencyAmount\n): CurrencyAmount {\n // formula: amountToSwap = (inputBalance - (optimalRatio * outputBalance)) / ((optimalRatio * inputTokenPrice) + 1))\n const amountToSwapRaw = new Fraction(inputBalance.quotient)\n .subtract(optimalRatio.multiply(outputBalance.quotient))\n .divide(optimalRatio.multiply(inputTokenPrice).add(1));\n\n if (amountToSwapRaw.lessThan(0)) {\n // should never happen since we do checks before calling in\n throw new Error('routeToRatio: insufficient input token amount');\n }\n\n return CurrencyAmount.fromRawAmount(\n inputBalance.currency,\n amountToSwapRaw.quotient\n );\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compute-all-routes.js","sourceRoot":"","sources":["../../../../../src/routers/alpha-router/functions/compute-all-routes.ts"],"names":[],"mappings":";;;AAAA,wDAA8D;AAE9D,gEAAmD;AACnD,gEAA6D;AAC7D,gEAA6D;AAG7D,wCAIuB;AACvB,6DAA0D;AAC1D,2CAAwC;AACxC,iDAAmE;AACnE,yCAOsB;AAEtB,SAAgB,kBAAkB,CAChC,UAAoB,EACpB,WAAqB,EACrB,KAAe,EACf,OAAe,EACf,YAA2B;IAE3B,IAAI,aAAa,GAAa,KAAK,CAAC;IAEpC,IAAI,YAAY,KAAK,2BAAY,CAAC,UAAU,EAAE;QAC5C,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,yBAAY,CAAC,CAAC;KACrE;IAED,IAAI,YAAY,KAAK,2BAAY,CAAC,QAAQ,EAAE;QAC1C,aAAa,GAAG,KAAK,C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,GAAG,CAAC,sBAAa,CAAC;QACjC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,qBAAY,CAAC;KAC/B,EACD,YAAY,MAAM,CAAC,MAAM,6BAA6B,MAAA,MAAM,CAAC,CAAC,CAAC,0CAAE,QAAQ,GAAG,CAC7E,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC;AA9GD,4CA8GC","sourcesContent":["import { ADDRESS_ZERO, TPool } from '@fewprotocol/router-sdk';\nimport { ChainId, Currency, Token } from '@fewprotocol/sdk-core';\nimport { Pair } from '@fewprotocol/uniswap-v2-sdk';\nimport { Pool as V3Pool } from '@fewprotocol/uniswap-v3-sdk';\nimport { Pool as V4Pool } from '@fewprotocol/uniswap-v4-sdk';\nimport { Pair as RingFewV2Pair } from '@fewprotocol/v2-sdk';\n\nimport {\n getAddressLowerCase,\n nativeOnChain,\n V4_ETH_WETH_FAKE_POOL,\n} from '../../../util';\nimport { HooksOptions } from '../../../util/hooksOptions';\nimport { log } from '../../../util/log';\nimport { poolToString, routeToString } from '../../../util/routes';\nimport {\n MixedRoute,\n SupportedRoutes,\n RingFewV2Route,\n V2Route,\n V3Route,\n V4Route,\n} from '../../router';\n\nexport function computeAllV4Routes(\n currencyIn: Currency,\n currencyOut: Currency,\n pools: V4Pool[],\n maxHops: number,\n hooksOptions?: HooksOptions\n): V4Route[] {\n let filteredPools: V4Pool[] = pools;\n\n if (hooksOptions === HooksOptions.HOOKS_ONLY) {\n filteredPools = pools.filter((pool) => pool.hooks !== ADDRESS_ZERO);\n }\n\n if (hooksOptions === HooksOptions.NO_HOOKS) {\n filteredPools = pools.filter((pool) => pool.hooks === ADDRESS_ZERO);\n }\n\n return computeAllRoutes<V4Pool, V4Route, Currency>(\n currencyIn,\n currencyOut,\n (route: V4Pool[], currencyIn: Currency, currencyOut: Currency) => {\n return new V4Route(route, currencyIn, currencyOut);\n },\n (pool: V4Pool, currency: Currency) => pool.involvesToken(currency),\n filteredPools,\n maxHops\n );\n}\n\nexport function computeAllUniswapFewV4Routes(\n currencyIn: Currency,\n currencyOut: Currency,\n pools: V4Pool[],\n maxHops: number,\n hooksOptions?: HooksOptions\n): V4Route[] {\n let filteredPools: V4Pool[] = pools;\n\n if (hooksOptions === HooksOptions.HOOKS_ONLY) {\n filteredPools = pools.filter((pool) => pool.hooks !== ADDRESS_ZERO);\n }\n\n if (hooksOptions === HooksOptions.NO_HOOKS) {\n filteredPools = pools.filter((pool) => pool.hooks === ADDRESS_ZERO);\n }\n\n return computeAllRoutes<V4Pool, V4Route, Currency>(\n currencyIn,\n currencyOut,\n (route: V4Pool[], currencyIn: Currency, currencyOut: Currency) => {\n return new V4Route(route, currencyIn, currencyOut);\n },\n (pool: V4Pool, currency: Currency) => pool.involvesToken(currency),\n filteredPools,\n maxHops\n );\n}\n\nexport function computeAllV3Routes(\n tokenIn: Token,\n tokenOut: Token,\n pools: V3Pool[],\n maxHops: number\n): V3Route[] {\n return computeAllRoutes<V3Pool, V3Route, Token>(\n tokenIn,\n tokenOut,\n (route: V3Pool[], tokenIn: Token, tokenOut: Token) => {\n return new V3Route(route, tokenIn, tokenOut);\n },\n (pool: V3Pool, token: Token) => pool.involvesToken(token),\n pools,\n maxHops\n );\n}\n\nexport function computeAllUniswapFewV3Routes(\n tokenIn: Token,\n tokenOut: Token,\n pools: V3Pool[],\n maxHops: number\n): V3Route[] {\n return computeAllRoutes<V3Pool, V3Route, Token>(\n tokenIn,\n tokenOut,\n (route: V3Pool[], tokenIn: Token, tokenOut: Token) => {\n return new V3Route(route, tokenIn, tokenOut);\n },\n (pool: V3Pool, token: Token) => pool.involvesToken(token),\n pools,\n maxHops\n );\n}\n\nexport function computeAllV2Routes(\n tokenIn: Token,\n tokenOut: Token,\n pools: Pair[],\n maxHops: number\n): V2Route[] {\n return computeAllRoutes<Pair, V2Route, Token>(\n tokenIn,\n tokenOut,\n (route: Pair[], tokenIn: Token, tokenOut: Token) => {\n return new V2Route(route, tokenIn, tokenOut);\n },\n (pool: Pair, token: Token) => pool.involvesToken(token),\n pools,\n maxHops\n );\n}\n\nexport function computeAllRingFewV2Routes(\n tokenIn: Token,\n tokenOut: Token,\n pools: RingFewV2Pair[],\n maxHops: number\n): RingFewV2Route[] {\n return computeAllRoutes<RingFewV2Pair, RingFewV2Route, Token>(\n tokenIn,\n tokenOut,\n (route: RingFewV2Pair[], tokenIn: Token, tokenOut: Token) => {\n return new RingFewV2Route(route, tokenIn, tokenOut);\n },\n (pool: RingFewV2Pair, token: Token) => pool.involvesToken(token),\n pools,\n maxHops\n );\n}\n\nexport function computeAllMixedRoutes(\n currencyIn: Currency,\n currencyOut: Currency,\n parts: TPool[],\n maxHops: number,\n shouldEnableMixedRouteEthWeth?: boolean,\n hooksOptions?: HooksOptions\n): MixedRoute[] {\n // first we need to filter non v4-pools\n const filteredPools: TPool[] =\n !hooksOptions || hooksOptions === HooksOptions.HOOKS_INCLUSIVE\n ? parts\n : parts.filter((pool) => !(pool instanceof V4Pool));\n\n if (hooksOptions === HooksOptions.HOOKS_ONLY) {\n // we need to filter out v4-pools with hooks\n // then concat the v4-pools with hooks\n const v4HookslessPools = parts.filter(\n (pool) => pool instanceof V4Pool && pool.hooks !== ADDRESS_ZERO\n );\n parts = filteredPools.concat(v4HookslessPools);\n }\n\n if (hooksOptions === HooksOptions.NO_HOOKS) {\n // we need to filter out v4-pools without hooks\n // then concat the v4-pools without hooks\n const v4HookfulPools = parts.filter(\n (pool) => pool instanceof V4Pool && pool.hooks === ADDRESS_ZERO\n );\n parts = filteredPools.concat(v4HookfulPools);\n }\n\n // only add fake v4 pool, if we see there's a native v4 pool in the candidate pool\n const containsV4NativePools =\n parts.filter(\n (pool) =>\n pool instanceof V4Pool &&\n pool.v4InvolvesToken(nativeOnChain(currencyIn.chainId))\n ).length > 0;\n const amendedPools =\n containsV4NativePools && shouldEnableMixedRouteEthWeth\n ? parts.concat(V4_ETH_WETH_FAKE_POOL[currencyIn.chainId as ChainId])\n : parts;\n // NOTE: we added a fake v4 pool, in order for mixed route to connect the v3 weth pool with v4 eth pool\n const routesRaw = computeAllRoutes<TPool, MixedRoute, Currency>(\n currencyIn,\n currencyOut,\n (route: TPool[], currencyIn: Currency, currencyOut: Currency) => {\n // we only retake the fake v4 pool if the route contains a native v4 pool\n return new MixedRoute(\n route,\n currencyIn,\n currencyOut,\n containsV4NativePools\n );\n },\n (pool: TPool, currency: Currency) =>\n currency.isNative\n ? (pool as V4Pool).involvesToken(currency)\n : pool.involvesToken(currency),\n amendedPools,\n maxHops\n );\n /// filter out pure v4 and v3 and v2 routes\n return routesRaw.filter((route) => {\n return (\n !route.pools.every((pool) => pool instanceof V4Pool) &&\n !route.pools.every((pool) => pool instanceof V3Pool) &&\n !route.pools.every((pool) => pool instanceof Pair)\n );\n });\n}\n\nexport function computeAllRoutes<\n TypePool extends TPool,\n TRoute extends SupportedRoutes,\n TCurrency extends Currency\n>(\n tokenIn: TCurrency,\n tokenOut: TCurrency,\n buildRoute: (\n route: TypePool[],\n tokenIn: TCurrency,\n tokenOut: TCurrency\n ) => TRoute,\n involvesToken: (pool: TypePool, token: TCurrency) => boolean,\n pools: TypePool[],\n maxHops: number\n): TRoute[] {\n const poolsUsed = Array<boolean>(pools.length).fill(false);\n const routes: TRoute[] = [];\n\n const computeRoutes = (\n tokenIn: TCurrency,\n tokenOut: TCurrency,\n currentRoute: TypePool[],\n poolsUsed: boolean[],\n tokensVisited: Set<string>,\n _previousTokenOut?: TCurrency\n ) => {\n const currentRouteContainsFakeV4Pool =\n currentRoute.filter(\n (pool) =>\n pool instanceof V4Pool &&\n pool.tickSpacing ===\n V4_ETH_WETH_FAKE_POOL[tokenIn.chainId as ChainId].tickSpacing\n ).length > 0;\n const amendedMaxHops = currentRouteContainsFakeV4Pool\n ? maxHops + 1\n : maxHops;\n\n // amendedMaxHops is the maxHops + 1 if the current route contains a fake v4 pool\n // b/c we want to allow the route to go through the fake v4 pool\n // also gas wise, if a route goes through the fake v4 pool, mixed quoter will add the wrap/unwrap gas cost:\n // https://github.com/Uniswap/mixed-quoter/pull/41/files#diff-a4d1289f264d1da22aac20cc55a9d01c8ba9cccd76ce1af8f952ec9034e7e1aaR189\n // and SOR will use the gas cost from the mixed quoter:\n // https://github.com/Uniswap/smart-order-router/blob/17da523f1af050e6430afb866d96681346c8fb8b/src/routers/alpha-router/gas-models/mixedRoute/mixed-route-heuristic-gas-model.ts#L222\n if (currentRoute.length > amendedMaxHops) {\n return;\n }\n\n if (\n currentRoute.length > 0 &&\n involvesToken(currentRoute[currentRoute.length - 1]!, tokenOut)\n ) {\n routes.push(buildRoute([...currentRoute], tokenIn, tokenOut));\n return;\n }\n\n for (let i = 0; i < pools.length; i++) {\n if (poolsUsed[i]) {\n continue;\n }\n\n const curPool = pools[i]!;\n const previousTokenOut = _previousTokenOut ? _previousTokenOut : tokenIn;\n\n if (!involvesToken(curPool, previousTokenOut)) {\n continue;\n }\n\n const currentTokenOut = curPool.token0.equals(previousTokenOut)\n ? curPool.token1\n : curPool.token0;\n\n if (tokensVisited.has(getAddressLowerCase(currentTokenOut))) {\n continue;\n }\n\n tokensVisited.add(getAddressLowerCase(currentTokenOut));\n currentRoute.push(curPool);\n poolsUsed[i] = true;\n computeRoutes(\n tokenIn,\n tokenOut,\n currentRoute,\n poolsUsed,\n tokensVisited,\n currentTokenOut as TCurrency\n );\n poolsUsed[i] = false;\n currentRoute.pop();\n tokensVisited.delete(getAddressLowerCase(currentTokenOut));\n }\n };\n\n computeRoutes(\n tokenIn,\n tokenOut,\n [],\n poolsUsed,\n new Set([getAddressLowerCase(tokenIn)])\n );\n\n log.info(\n {\n routes: routes.map(routeToString),\n pools: pools.map(poolToString),\n },\n `Computed ${routes.length} possible routes for type ${routes[0]?.protocol}.`\n );\n\n return routes;\n}\n"]}