@synthra-swap/sdk 0.1.4

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 (235) hide show
  1. package/README.md +12 -0
  2. package/chains.d.ts +1 -0
  3. package/chains.js +1 -0
  4. package/core.d.ts +1 -0
  5. package/core.js +1 -0
  6. package/dist/chain-registry.d.ts +22 -0
  7. package/dist/chain-registry.js +315 -0
  8. package/dist/chain-registry.js.map +1 -0
  9. package/dist/chains.d.ts +5 -0
  10. package/dist/chains.js +29 -0
  11. package/dist/chains.js.map +1 -0
  12. package/dist/core/addresses.d.ts +21 -0
  13. package/dist/core/addresses.js +76 -0
  14. package/dist/core/addresses.js.map +1 -0
  15. package/dist/core/chains.d.ts +51 -0
  16. package/dist/core/chains.js +82 -0
  17. package/dist/core/chains.js.map +1 -0
  18. package/dist/core/constants.d.ts +12 -0
  19. package/dist/core/constants.js +20 -0
  20. package/dist/core/constants.js.map +1 -0
  21. package/dist/core/entities/baseCurrency.d.ts +48 -0
  22. package/dist/core/entities/baseCurrency.js +29 -0
  23. package/dist/core/entities/baseCurrency.js.map +1 -0
  24. package/dist/core/entities/currency.d.ts +3 -0
  25. package/dist/core/entities/currency.js +3 -0
  26. package/dist/core/entities/currency.js.map +1 -0
  27. package/dist/core/entities/ether.d.ts +13 -0
  28. package/dist/core/entities/ether.js +32 -0
  29. package/dist/core/entities/ether.js.map +1 -0
  30. package/dist/core/entities/fractions/currencyAmount.d.ts +31 -0
  31. package/dist/core/entities/fractions/currencyAmount.js +74 -0
  32. package/dist/core/entities/fractions/currencyAmount.js.map +1 -0
  33. package/dist/core/entities/fractions/fraction.d.ts +24 -0
  34. package/dist/core/entities/fractions/fraction.js +106 -0
  35. package/dist/core/entities/fractions/fraction.js.map +1 -0
  36. package/dist/core/entities/fractions/index.d.ts +4 -0
  37. package/dist/core/entities/fractions/index.js +12 -0
  38. package/dist/core/entities/fractions/index.js.map +1 -0
  39. package/dist/core/entities/fractions/percent.d.ts +14 -0
  40. package/dist/core/entities/fractions/percent.js +45 -0
  41. package/dist/core/entities/fractions/percent.js.map +1 -0
  42. package/dist/core/entities/fractions/price.d.ts +38 -0
  43. package/dist/core/entities/fractions/price.js +75 -0
  44. package/dist/core/entities/fractions/price.js.map +1 -0
  45. package/dist/core/entities/index.d.ts +7 -0
  46. package/dist/core/entities/index.js +24 -0
  47. package/dist/core/entities/index.js.map +1 -0
  48. package/dist/core/entities/nativeCurrency.d.ts +8 -0
  49. package/dist/core/entities/nativeCurrency.js +16 -0
  50. package/dist/core/entities/nativeCurrency.js.map +1 -0
  51. package/dist/core/entities/nativeOnChain.d.ts +19 -0
  52. package/dist/core/entities/nativeOnChain.js +141 -0
  53. package/dist/core/entities/nativeOnChain.js.map +1 -0
  54. package/dist/core/entities/token.d.ts +48 -0
  55. package/dist/core/entities/token.js +71 -0
  56. package/dist/core/entities/token.js.map +1 -0
  57. package/dist/core/entities/weth9.d.ts +7 -0
  58. package/dist/core/entities/weth9.js +28 -0
  59. package/dist/core/entities/weth9.js.map +1 -0
  60. package/dist/core/index.d.ts +5 -0
  61. package/dist/core/index.js +22 -0
  62. package/dist/core/index.js.map +1 -0
  63. package/dist/core/utils/computePriceImpact.d.ts +8 -0
  64. package/dist/core/utils/computePriceImpact.js +18 -0
  65. package/dist/core/utils/computePriceImpact.js.map +1 -0
  66. package/dist/core/utils/index.d.ts +4 -0
  67. package/dist/core/utils/index.js +12 -0
  68. package/dist/core/utils/index.js.map +1 -0
  69. package/dist/core/utils/sortedInsert.d.ts +1 -0
  70. package/dist/core/utils/sortedInsert.js +40 -0
  71. package/dist/core/utils/sortedInsert.js.map +1 -0
  72. package/dist/core/utils/sqrt.d.ts +7 -0
  73. package/dist/core/utils/sqrt.js +34 -0
  74. package/dist/core/utils/sqrt.js.map +1 -0
  75. package/dist/core/utils/validateAndParseAddress.d.ts +10 -0
  76. package/dist/core/utils/validateAndParseAddress.js +31 -0
  77. package/dist/core/utils/validateAndParseAddress.js.map +1 -0
  78. package/dist/index.d.ts +4 -0
  79. package/dist/index.js +34 -0
  80. package/dist/index.js.map +1 -0
  81. package/dist/universal-router/entities/Command.d.ts +12 -0
  82. package/dist/universal-router/entities/Command.js +9 -0
  83. package/dist/universal-router/entities/Command.js.map +1 -0
  84. package/dist/universal-router/entities/index.d.ts +3 -0
  85. package/dist/universal-router/entities/index.js +20 -0
  86. package/dist/universal-router/entities/index.js.map +1 -0
  87. package/dist/universal-router/entities/protocols/index.d.ts +2 -0
  88. package/dist/universal-router/entities/protocols/index.js +19 -0
  89. package/dist/universal-router/entities/protocols/index.js.map +1 -0
  90. package/dist/universal-router/entities/protocols/uniswap.d.ts +32 -0
  91. package/dist/universal-router/entities/protocols/uniswap.js +143 -0
  92. package/dist/universal-router/entities/protocols/uniswap.js.map +1 -0
  93. package/dist/universal-router/entities/protocols/unwrapWETH.d.ts +12 -0
  94. package/dist/universal-router/entities/protocols/unwrapWETH.js +35 -0
  95. package/dist/universal-router/entities/protocols/unwrapWETH.js.map +1 -0
  96. package/dist/universal-router/entities/trade.d.ts +41 -0
  97. package/dist/universal-router/entities/trade.js +114 -0
  98. package/dist/universal-router/entities/trade.js.map +1 -0
  99. package/dist/universal-router/index.d.ts +5 -0
  100. package/dist/universal-router/index.js +31 -0
  101. package/dist/universal-router/index.js.map +1 -0
  102. package/dist/universal-router/swapRouter.d.ts +29 -0
  103. package/dist/universal-router/swapRouter.js +102 -0
  104. package/dist/universal-router/swapRouter.js.map +1 -0
  105. package/dist/universal-router/utils/constants.d.ts +8 -0
  106. package/dist/universal-router/utils/constants.js +21 -0
  107. package/dist/universal-router/utils/constants.js.map +1 -0
  108. package/dist/universal-router/utils/getNativeCurrencyValue.d.ts +2 -0
  109. package/dist/universal-router/utils/getNativeCurrencyValue.js +19 -0
  110. package/dist/universal-router/utils/getNativeCurrencyValue.js.map +1 -0
  111. package/dist/universal-router/utils/inputTokens.d.ts +16 -0
  112. package/dist/universal-router/utils/inputTokens.js +44 -0
  113. package/dist/universal-router/utils/inputTokens.js.map +1 -0
  114. package/dist/universal-router/utils/numbers.d.ts +6 -0
  115. package/dist/universal-router/utils/numbers.js +24 -0
  116. package/dist/universal-router/utils/numbers.js.map +1 -0
  117. package/dist/universal-router/utils/routerCommands.d.ts +29 -0
  118. package/dist/universal-router/utils/routerCommands.js +64 -0
  119. package/dist/universal-router/utils/routerCommands.js.map +1 -0
  120. package/dist/universal-router/utils/routerTradeAdapter.d.ts +40 -0
  121. package/dist/universal-router/utils/routerTradeAdapter.js +82 -0
  122. package/dist/universal-router/utils/routerTradeAdapter.js.map +1 -0
  123. package/dist/v3/abis.d.ts +6 -0
  124. package/dist/v3/abis.js +39 -0
  125. package/dist/v3/abis.js.map +1 -0
  126. package/dist/v3/constants.d.ts +18 -0
  127. package/dist/v3/constants.js +26 -0
  128. package/dist/v3/constants.js.map +1 -0
  129. package/dist/v3/entities/index.d.ts +7 -0
  130. package/dist/v3/entities/index.js +24 -0
  131. package/dist/v3/entities/index.js.map +1 -0
  132. package/dist/v3/entities/pool.d.ts +81 -0
  133. package/dist/v3/entities/pool.js +215 -0
  134. package/dist/v3/entities/pool.js.map +1 -0
  135. package/dist/v3/entities/position.d.ts +131 -0
  136. package/dist/v3/entities/position.js +250 -0
  137. package/dist/v3/entities/position.js.map +1 -0
  138. package/dist/v3/entities/route.d.ts +26 -0
  139. package/dist/v3/entities/route.js +77 -0
  140. package/dist/v3/entities/route.js.map +1 -0
  141. package/dist/v3/entities/tick.d.ts +13 -0
  142. package/dist/v3/entities/tick.js +19 -0
  143. package/dist/v3/entities/tick.js.map +1 -0
  144. package/dist/v3/entities/tickDataProvider.d.ts +31 -0
  145. package/dist/v3/entities/tickDataProvider.js +18 -0
  146. package/dist/v3/entities/tickDataProvider.js.map +1 -0
  147. package/dist/v3/entities/tickListDataProvider.d.ts +15 -0
  148. package/dist/v3/entities/tickListDataProvider.js +23 -0
  149. package/dist/v3/entities/tickListDataProvider.js.map +1 -0
  150. package/dist/v3/entities/trade.d.ts +220 -0
  151. package/dist/v3/entities/trade.js +442 -0
  152. package/dist/v3/entities/trade.js.map +1 -0
  153. package/dist/v3/index.d.ts +9 -0
  154. package/dist/v3/index.js +26 -0
  155. package/dist/v3/index.js.map +1 -0
  156. package/dist/v3/internalConstants.d.ts +6 -0
  157. package/dist/v3/internalConstants.js +15 -0
  158. package/dist/v3/internalConstants.js.map +1 -0
  159. package/dist/v3/multicall.d.ts +9 -0
  160. package/dist/v3/multicall.js +20 -0
  161. package/dist/v3/multicall.js.map +1 -0
  162. package/dist/v3/nonfungiblePositionManager.d.ts +146 -0
  163. package/dist/v3/nonfungiblePositionManager.js +231 -0
  164. package/dist/v3/nonfungiblePositionManager.js.map +1 -0
  165. package/dist/v3/payments.d.ts +24 -0
  166. package/dist/v3/payments.js +55 -0
  167. package/dist/v3/payments.js.map +1 -0
  168. package/dist/v3/quoter.d.ts +37 -0
  169. package/dist/v3/quoter.js +76 -0
  170. package/dist/v3/quoter.js.map +1 -0
  171. package/dist/v3/selfPermit.d.ts +25 -0
  172. package/dist/v3/selfPermit.js +37 -0
  173. package/dist/v3/selfPermit.js.map +1 -0
  174. package/dist/v3/swapRouter.d.ts +51 -0
  175. package/dist/v3/swapRouter.js +147 -0
  176. package/dist/v3/swapRouter.js.map +1 -0
  177. package/dist/v3/utils/calldata.d.ts +20 -0
  178. package/dist/v3/utils/calldata.js +22 -0
  179. package/dist/v3/utils/calldata.js.map +1 -0
  180. package/dist/v3/utils/computePoolAddress.d.ts +18 -0
  181. package/dist/v3/utils/computePoolAddress.js +22 -0
  182. package/dist/v3/utils/computePoolAddress.js.map +1 -0
  183. package/dist/v3/utils/encodeRouteToPath.d.ts +8 -0
  184. package/dist/v3/utils/encodeRouteToPath.js +32 -0
  185. package/dist/v3/utils/encodeRouteToPath.js.map +1 -0
  186. package/dist/v3/utils/encodeSqrtRatioX96.d.ts +9 -0
  187. package/dist/v3/utils/encodeSqrtRatioX96.js +22 -0
  188. package/dist/v3/utils/encodeSqrtRatioX96.js.map +1 -0
  189. package/dist/v3/utils/fullMath.d.ts +8 -0
  190. package/dist/v3/utils/fullMath.js +23 -0
  191. package/dist/v3/utils/fullMath.js.map +1 -0
  192. package/dist/v3/utils/index.d.ts +17 -0
  193. package/dist/v3/utils/index.js +34 -0
  194. package/dist/v3/utils/index.js.map +1 -0
  195. package/dist/v3/utils/isSorted.d.ts +7 -0
  196. package/dist/v3/utils/isSorted.js +19 -0
  197. package/dist/v3/utils/isSorted.js.map +1 -0
  198. package/dist/v3/utils/liquidityMath.d.ts +8 -0
  199. package/dist/v3/utils/liquidityMath.js +24 -0
  200. package/dist/v3/utils/liquidityMath.js.map +1 -0
  201. package/dist/v3/utils/maxLiquidityForAmounts.d.ts +14 -0
  202. package/dist/v3/utils/maxLiquidityForAmounts.js +89 -0
  203. package/dist/v3/utils/maxLiquidityForAmounts.js.map +1 -0
  204. package/dist/v3/utils/mostSignificantBit.d.ts +2 -0
  205. package/dist/v3/utils/mostSignificantBit.js +29 -0
  206. package/dist/v3/utils/mostSignificantBit.js.map +1 -0
  207. package/dist/v3/utils/nearestUsableTick.d.ts +6 -0
  208. package/dist/v3/utils/nearestUsableTick.js +27 -0
  209. package/dist/v3/utils/nearestUsableTick.js.map +1 -0
  210. package/dist/v3/utils/position.d.ts +8 -0
  211. package/dist/v3/utils/position.js +23 -0
  212. package/dist/v3/utils/position.js.map +1 -0
  213. package/dist/v3/utils/priceTickConversions.d.ts +15 -0
  214. package/dist/v3/utils/priceTickConversions.js +52 -0
  215. package/dist/v3/utils/priceTickConversions.js.map +1 -0
  216. package/dist/v3/utils/sqrtPriceMath.d.ts +13 -0
  217. package/dist/v3/utils/sqrtPriceMath.js +97 -0
  218. package/dist/v3/utils/sqrtPriceMath.js.map +1 -0
  219. package/dist/v3/utils/swapMath.d.ts +9 -0
  220. package/dist/v3/utils/swapMath.js +79 -0
  221. package/dist/v3/utils/swapMath.js.map +1 -0
  222. package/dist/v3/utils/tickLibrary.d.ts +14 -0
  223. package/dist/v3/utils/tickLibrary.js +53 -0
  224. package/dist/v3/utils/tickLibrary.js.map +1 -0
  225. package/dist/v3/utils/tickList.d.ts +23 -0
  226. package/dist/v3/utils/tickList.js +110 -0
  227. package/dist/v3/utils/tickList.js.map +1 -0
  228. package/dist/v3/utils/tickMath.d.ts +34 -0
  229. package/dist/v3/utils/tickMath.js +127 -0
  230. package/dist/v3/utils/tickMath.js.map +1 -0
  231. package/package.json +80 -0
  232. package/universal-router.d.ts +1 -0
  233. package/universal-router.js +1 -0
  234. package/v3.d.ts +1 -0
  235. package/v3.js +1 -0
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RouterTradeAdapter = exports.isNativeCurrency = exports.PoolType = void 0;
4
+ const core_1 = require("../../core");
5
+ const v3_1 = require("../../v3");
6
+ const ethers_1 = require("ethers");
7
+ const trade_1 = require("../entities/trade");
8
+ const constants_1 = require("./constants");
9
+ var PoolType;
10
+ (function (PoolType) {
11
+ PoolType["V3Pool"] = "v3-pool";
12
+ })(PoolType = exports.PoolType || (exports.PoolType = {}));
13
+ const isNativeCurrency = (address) => address.toLowerCase() === constants_1.ETH_ADDRESS.toLowerCase() || address.toLowerCase() === constants_1.E_ETH_ADDRESS.toLowerCase();
14
+ exports.isNativeCurrency = isNativeCurrency;
15
+ // Helper class to convert routing-specific quote entities to Synthra V3-only trade entities.
16
+ class RouterTradeAdapter {
17
+ // Generate a SynthraTrade using fields from a classic quote response.
18
+ static fromClassicQuote(quote) {
19
+ const { route, tokenIn, tokenOut } = quote;
20
+ if (!route)
21
+ throw new Error('Expected route to be present');
22
+ if (!route.length)
23
+ throw new Error('Expected there to be at least one route');
24
+ if (route.some((r) => !r.length))
25
+ throw new Error('Expected all routes to have at least one pool');
26
+ const firstRoute = route[0];
27
+ const tokenInData = firstRoute[0].tokenIn;
28
+ const tokenOutData = firstRoute[firstRoute.length - 1].tokenOut;
29
+ if (!tokenInData || !tokenOutData)
30
+ throw new Error('Expected both tokenIn and tokenOut to be present');
31
+ if (tokenInData.chainId !== tokenOutData.chainId)
32
+ throw new Error('Expected tokenIn and tokenOut to be have same chainId');
33
+ const parsedCurrencyIn = RouterTradeAdapter.toCurrency((0, exports.isNativeCurrency)(tokenIn), tokenInData);
34
+ const parsedCurrencyOut = RouterTradeAdapter.toCurrency((0, exports.isNativeCurrency)(tokenOut), tokenOutData);
35
+ const typedRoutes = route.map((subRoute) => {
36
+ const rawAmountIn = subRoute[0].amountIn;
37
+ const rawAmountOut = subRoute[subRoute.length - 1].amountOut;
38
+ if (!rawAmountIn || !rawAmountOut) {
39
+ throw new Error('Expected both raw amountIn and raw amountOut to be present');
40
+ }
41
+ const inputAmount = core_1.CurrencyAmount.fromRawAmount(parsedCurrencyIn, rawAmountIn);
42
+ const outputAmount = core_1.CurrencyAmount.fromRawAmount(parsedCurrencyOut, rawAmountOut);
43
+ const isOnlyV3 = RouterTradeAdapter.isVersionedRoute(PoolType.V3Pool, subRoute);
44
+ if (!isOnlyV3)
45
+ throw new Error('Only V3 routes are supported');
46
+ return {
47
+ routev3: new v3_1.Route(subRoute.map(RouterTradeAdapter.toPool), parsedCurrencyIn, parsedCurrencyOut),
48
+ inputAmount,
49
+ outputAmount,
50
+ };
51
+ });
52
+ return new trade_1.SynthraTrade({
53
+ v3Routes: typedRoutes
54
+ .filter((route) => route.routev3 !== null)
55
+ .map((route) => ({
56
+ routev3: route.routev3,
57
+ inputAmount: route.inputAmount,
58
+ outputAmount: route.outputAmount,
59
+ })),
60
+ tradeType: quote.tradeType,
61
+ });
62
+ }
63
+ static toCurrency(isNative, token) {
64
+ if (isNative) {
65
+ return core_1.Ether.onChain(token.chainId);
66
+ }
67
+ return this.toToken(token);
68
+ }
69
+ static toToken(token) {
70
+ const { chainId, address, decimals, symbol, buyFeeBps, sellFeeBps } = token;
71
+ return new core_1.Token(chainId, address, parseInt(decimals.toString()), symbol,
72
+ /* name */ undefined, false, buyFeeBps ? ethers_1.BigNumber.from(buyFeeBps) : undefined, sellFeeBps ? ethers_1.BigNumber.from(sellFeeBps) : undefined);
73
+ }
74
+ static toPool({ fee, sqrtRatioX96, liquidity, tickCurrent, tokenIn, tokenOut }) {
75
+ return new v3_1.Pool(RouterTradeAdapter.toToken(tokenIn), RouterTradeAdapter.toToken(tokenOut), parseInt(fee), sqrtRatioX96, liquidity, parseInt(tickCurrent));
76
+ }
77
+ static isVersionedRoute(type, route) {
78
+ return route.every((pool) => pool.type === type);
79
+ }
80
+ }
81
+ exports.RouterTradeAdapter = RouterTradeAdapter;
82
+ //# sourceMappingURL=routerTradeAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routerTradeAdapter.js","sourceRoot":"","sources":["../../../src/universal-router/utils/routerTradeAdapter.ts"],"names":[],"mappings":";;;AAAA,qCAA8E;AAC9E,iCAA4D;AAC5D,mCAAkC;AAClC,6CAAgD;AAChD,2CAAwD;AAYxD,IAAY,QAEX;AAFD,WAAY,QAAQ;IAClB,8BAAkB,CAAA;AACpB,CAAC,EAFW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAEnB;AA6BM,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,EAAE,CAClD,OAAO,CAAC,WAAW,EAAE,KAAK,uBAAW,CAAC,WAAW,EAAE,IAAI,OAAO,CAAC,WAAW,EAAE,KAAK,yBAAa,CAAC,WAAW,EAAE,CAAA;AADjG,QAAA,gBAAgB,oBACiF;AAE9G,6FAA6F;AAC7F,MAAa,kBAAkB;IAC7B,sEAAsE;IACtE,MAAM,CAAC,gBAAgB,CAAC,KAA0B;QAChD,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAA;QAE1C,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;QAC3D,IAAI,CAAC,KAAK,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;QAC7E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EACP,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,EAC7B,MAAM;QACN,UAAU,CAAC,SAAS,EACpB,KAAK,EACL,SAAS,CAAC,CAAC,CAAC,kBAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,EACjD,UAAU,CAAC,CAAC,CAAC,kBAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CACpD,CAAA;IACH,CAAC;IAEO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAiB;QACnG,OAAO,IAAI,SAAI,CACb,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,EACnC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,EACpC,QAAQ,CAAC,GAAG,CAAc,EAC1B,YAAY,EACZ,SAAS,EACT,QAAQ,CAAC,WAAW,CAAC,CACtB,CAAA;IACH,CAAC;IAEO,MAAM,CAAC,gBAAgB,CAC7B,IAAc,EACd,KAAsB;QAEtB,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,CAAA;IAClD,CAAC;CACF;AA3FD,gDA2FC"}
@@ -0,0 +1,6 @@
1
+ export declare const MULTICALL_ABI: string[];
2
+ export declare const NONFUNGIBLE_POSITION_MANAGER_ABI: string[];
3
+ export declare const PAYMENTS_WITH_FEE_ABI: string[];
4
+ export declare const QUOTER_ABI: string[];
5
+ export declare const SELF_PERMIT_ABI: string[];
6
+ export declare const SWAP_ROUTER_ABI: string[];
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SWAP_ROUTER_ABI = exports.SELF_PERMIT_ABI = exports.QUOTER_ABI = exports.PAYMENTS_WITH_FEE_ABI = exports.NONFUNGIBLE_POSITION_MANAGER_ABI = exports.MULTICALL_ABI = void 0;
4
+ exports.MULTICALL_ABI = ['function multicall(bytes[] data) payable returns (bytes[] results)'];
5
+ exports.NONFUNGIBLE_POSITION_MANAGER_ABI = [
6
+ 'function createAndInitializePoolIfNecessary(address token0, address token1, uint24 fee, uint160 sqrtPriceX96) payable returns (address pool)',
7
+ 'function mint((address token0, address token1, uint24 fee, int24 tickLower, int24 tickUpper, uint256 amount0Desired, uint256 amount1Desired, uint256 amount0Min, uint256 amount1Min, address recipient, uint256 deadline) params) payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1)',
8
+ 'function increaseLiquidity((uint256 tokenId, uint256 amount0Desired, uint256 amount1Desired, uint256 amount0Min, uint256 amount1Min, uint256 deadline) params) payable returns (uint128 liquidity, uint256 amount0, uint256 amount1)',
9
+ 'function collect((uint256 tokenId, address recipient, uint128 amount0Max, uint128 amount1Max) params) payable returns (uint256 amount0, uint256 amount1)',
10
+ 'function permit(address spender, uint256 tokenId, uint256 deadline, uint8 v, bytes32 r, bytes32 s)',
11
+ 'function decreaseLiquidity((uint256 tokenId, uint128 liquidity, uint256 amount0Min, uint256 amount1Min, uint256 deadline) params) payable returns (uint256 amount0, uint256 amount1)',
12
+ 'function burn(uint256 tokenId) payable',
13
+ 'function safeTransferFrom(address from, address to, uint256 tokenId)',
14
+ 'function safeTransferFrom(address from, address to, uint256 tokenId, bytes data)'
15
+ ];
16
+ exports.PAYMENTS_WITH_FEE_ABI = [
17
+ 'function unwrapWETH9(uint256 amountMinimum, address recipient) payable',
18
+ 'function unwrapWETH9WithFee(uint256 amountMinimum, address recipient, uint256 feeBips, address feeRecipient) payable',
19
+ 'function sweepToken(address token, uint256 amountMinimum, address recipient) payable',
20
+ 'function sweepTokenWithFee(address token, uint256 amountMinimum, address recipient, uint256 feeBips, address feeRecipient) payable',
21
+ 'function refundETH() payable'
22
+ ];
23
+ exports.QUOTER_ABI = [
24
+ 'function quoteExactInput(bytes path, uint256 amountIn) returns (uint256 amountOut)',
25
+ 'function quoteExactInputSingle(address tokenIn, address tokenOut, uint24 fee, uint256 amountIn, uint160 sqrtPriceLimitX96) returns (uint256 amountOut)',
26
+ 'function quoteExactOutput(bytes path, uint256 amountOut) returns (uint256 amountIn)',
27
+ 'function quoteExactOutputSingle(address tokenIn, address tokenOut, uint24 fee, uint256 amountOut, uint160 sqrtPriceLimitX96) returns (uint256 amountIn)'
28
+ ];
29
+ exports.SELF_PERMIT_ABI = [
30
+ 'function selfPermit(address token, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)',
31
+ 'function selfPermitAllowed(address token, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s)'
32
+ ];
33
+ exports.SWAP_ROUTER_ABI = [
34
+ 'function exactInputSingle((address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 deadline, uint256 amountIn, uint256 amountOutMinimum, uint160 sqrtPriceLimitX96) params) payable returns (uint256 amountOut)',
35
+ 'function exactInput((bytes path, address recipient, uint256 deadline, uint256 amountIn, uint256 amountOutMinimum) params) payable returns (uint256 amountOut)',
36
+ 'function exactOutputSingle((address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 deadline, uint256 amountOut, uint256 amountInMaximum, uint160 sqrtPriceLimitX96) params) payable returns (uint256 amountIn)',
37
+ 'function exactOutput((bytes path, address recipient, uint256 deadline, uint256 amountOut, uint256 amountInMaximum) params) payable returns (uint256 amountIn)'
38
+ ];
39
+ //# sourceMappingURL=abis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abis.js","sourceRoot":"","sources":["../../src/v3/abis.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG,CAAC,oEAAoE,CAAC,CAAA;AAEtF,QAAA,gCAAgC,GAAG;IAC9C,8IAA8I;IAC9I,0TAA0T;IAC1T,sOAAsO;IACtO,0JAA0J;IAC1J,oGAAoG;IACpG,sLAAsL;IACtL,wCAAwC;IACxC,sEAAsE;IACtE,kFAAkF;CACnF,CAAA;AAEY,QAAA,qBAAqB,GAAG;IACnC,wEAAwE;IACxE,sHAAsH;IACtH,sFAAsF;IACtF,oIAAoI;IACpI,8BAA8B;CAC/B,CAAA;AAEY,QAAA,UAAU,GAAG;IACxB,oFAAoF;IACpF,wJAAwJ;IACxJ,qFAAqF;IACrF,yJAAyJ;CAC1J,CAAA;AAEY,QAAA,eAAe,GAAG;IAC7B,oGAAoG;IACpG,yGAAyG;CAC1G,CAAA;AAEY,QAAA,eAAe,GAAG;IAC7B,mOAAmO;IACnO,+JAA+J;IAC/J,mOAAmO;IACnO,+JAA+J;CAChK,CAAA"}
@@ -0,0 +1,18 @@
1
+ export declare const FACTORY_ADDRESS = "0xd57aAf751E8fdD6Ae330cd45087B579580416243";
2
+ export declare const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000";
3
+ export declare const POOL_INIT_CODE_HASH = "0x499aba1e2f07d97749c4eabd822eca2efa521b1d6e34a67285e4a3cb773905dd";
4
+ /**
5
+ * The default factory enabled fee amounts, denominated in hundredths of bips.
6
+ */
7
+ export declare enum FeeAmount {
8
+ LOWEST = 100,
9
+ LOW = 500,
10
+ MEDIUM = 3000,
11
+ HIGH = 10000
12
+ }
13
+ /**
14
+ * The default factory tick spacings by fee amount.
15
+ */
16
+ export declare const TICK_SPACINGS: {
17
+ [amount in FeeAmount]: number;
18
+ };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TICK_SPACINGS = exports.FeeAmount = exports.POOL_INIT_CODE_HASH = exports.ADDRESS_ZERO = exports.FACTORY_ADDRESS = void 0;
4
+ exports.FACTORY_ADDRESS = '0xd57aAf751E8fdD6Ae330cd45087B579580416243';
5
+ exports.ADDRESS_ZERO = '0x0000000000000000000000000000000000000000';
6
+ exports.POOL_INIT_CODE_HASH = '0x499aba1e2f07d97749c4eabd822eca2efa521b1d6e34a67285e4a3cb773905dd';
7
+ /**
8
+ * The default factory enabled fee amounts, denominated in hundredths of bips.
9
+ */
10
+ var FeeAmount;
11
+ (function (FeeAmount) {
12
+ FeeAmount[FeeAmount["LOWEST"] = 100] = "LOWEST";
13
+ FeeAmount[FeeAmount["LOW"] = 500] = "LOW";
14
+ FeeAmount[FeeAmount["MEDIUM"] = 3000] = "MEDIUM";
15
+ FeeAmount[FeeAmount["HIGH"] = 10000] = "HIGH";
16
+ })(FeeAmount = exports.FeeAmount || (exports.FeeAmount = {}));
17
+ /**
18
+ * The default factory tick spacings by fee amount.
19
+ */
20
+ exports.TICK_SPACINGS = {
21
+ [FeeAmount.LOWEST]: 1,
22
+ [FeeAmount.LOW]: 10,
23
+ [FeeAmount.MEDIUM]: 60,
24
+ [FeeAmount.HIGH]: 200
25
+ };
26
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/v3/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG,4CAA4C,CAAA;AAE9D,QAAA,YAAY,GAAG,4CAA4C,CAAA;AAE3D,QAAA,mBAAmB,GAAG,oEAAoE,CAAA;AAEvG;;GAEG;AACH,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,+CAAY,CAAA;IACZ,yCAAS,CAAA;IACT,gDAAa,CAAA;IACb,6CAAY,CAAA;AACd,CAAC,EALW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAKpB;AAED;;GAEG;AACU,QAAA,aAAa,GAAsC;IAC9D,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;IACrB,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE;IACnB,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,EAAE;IACtB,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,GAAG;CACtB,CAAA"}
@@ -0,0 +1,7 @@
1
+ export * from './pool';
2
+ export * from './position';
3
+ export * from './route';
4
+ export * from './tick';
5
+ export * from './trade';
6
+ export * from './tickDataProvider';
7
+ export * from './tickListDataProvider';
@@ -0,0 +1,24 @@
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("./pool"), exports);
18
+ __exportStar(require("./position"), exports);
19
+ __exportStar(require("./route"), exports);
20
+ __exportStar(require("./tick"), exports);
21
+ __exportStar(require("./trade"), exports);
22
+ __exportStar(require("./tickDataProvider"), exports);
23
+ __exportStar(require("./tickListDataProvider"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/entities/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAsB;AACtB,6CAA0B;AAC1B,0CAAuB;AACvB,yCAAsB;AACtB,0CAAuB;AACvB,qDAAkC;AAClC,yDAAsC"}
@@ -0,0 +1,81 @@
1
+ import { BigintIsh, CurrencyAmount, Price, Token } from '../../core';
2
+ import JSBI from 'jsbi';
3
+ import { FeeAmount } from '../constants';
4
+ import { Tick, TickConstructorArgs } from './tick';
5
+ import { TickDataProvider } from './tickDataProvider';
6
+ /**
7
+ * Represents a V3 pool
8
+ */
9
+ export declare class Pool {
10
+ readonly token0: Token;
11
+ readonly token1: Token;
12
+ readonly fee: FeeAmount;
13
+ readonly sqrtRatioX96: JSBI;
14
+ readonly liquidity: JSBI;
15
+ readonly tickCurrent: number;
16
+ readonly tickDataProvider: TickDataProvider;
17
+ private _token0Price?;
18
+ private _token1Price?;
19
+ static getAddress(tokenA: Token, tokenB: Token, fee: FeeAmount, initCodeHashManualOverride?: string, factoryAddressOverride?: string): string;
20
+ /**
21
+ * Construct a pool
22
+ * @param tokenA One of the tokens in the pool
23
+ * @param tokenB The other token in the pool
24
+ * @param fee The fee in hundredths of a bips of the input amount of every swap that is collected by the pool
25
+ * @param sqrtRatioX96 The sqrt of the current ratio of amounts of token1 to token0
26
+ * @param liquidity The current value of in range liquidity
27
+ * @param tickCurrent The current tick of the pool
28
+ * @param ticks The current state of the pool ticks or a data provider that can return tick data
29
+ */
30
+ constructor(tokenA: Token, tokenB: Token, fee: FeeAmount, sqrtRatioX96: BigintIsh, liquidity: BigintIsh, tickCurrent: number, ticks?: TickDataProvider | (Tick | TickConstructorArgs)[]);
31
+ /**
32
+ * Returns true if the token is either token0 or token1
33
+ * @param token The token to check
34
+ * @returns True if token is either token0 or token
35
+ */
36
+ involvesToken(token: Token): boolean;
37
+ /**
38
+ * Returns the current mid price of the pool in terms of token0, i.e. the ratio of token1 over token0
39
+ */
40
+ get token0Price(): Price<Token, Token>;
41
+ /**
42
+ * Returns the current mid price of the pool in terms of token1, i.e. the ratio of token0 over token1
43
+ */
44
+ get token1Price(): Price<Token, Token>;
45
+ /**
46
+ * Return the price of the given token in terms of the other token in the pool.
47
+ * @param token The token to return price of
48
+ * @returns The price of the given token, in terms of the other.
49
+ */
50
+ priceOf(token: Token): Price<Token, Token>;
51
+ /**
52
+ * Returns the chain ID of the tokens in the pool.
53
+ */
54
+ get chainId(): number;
55
+ /**
56
+ * Given an input amount of a token, return the computed output amount, and a pool with state updated after the trade
57
+ * @param inputAmount The input amount for which to quote the output amount
58
+ * @param sqrtPriceLimitX96 The Q64.96 sqrt price limit
59
+ * @returns The output amount and the pool with updated state
60
+ */
61
+ getOutputAmount(inputAmount: CurrencyAmount<Token>, sqrtPriceLimitX96?: JSBI): Promise<[CurrencyAmount<Token>, Pool]>;
62
+ /**
63
+ * Given a desired output amount of a token, return the computed input amount and a pool with state updated after the trade
64
+ * @param outputAmount the output amount for which to quote the input amount
65
+ * @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swap
66
+ * @returns The input amount and the pool with updated state
67
+ */
68
+ getInputAmount(outputAmount: CurrencyAmount<Token>, sqrtPriceLimitX96?: JSBI): Promise<[CurrencyAmount<Token>, Pool]>;
69
+ /**
70
+ * Executes a swap
71
+ * @param zeroForOne Whether the amount in is token0 or token1
72
+ * @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
73
+ * @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swap
74
+ * @returns amountCalculated
75
+ * @returns sqrtRatioX96
76
+ * @returns liquidity
77
+ * @returns tickCurrent
78
+ */
79
+ private swap;
80
+ get tickSpacing(): number;
81
+ }
@@ -0,0 +1,215 @@
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.Pool = void 0;
7
+ const core_1 = require("../../core");
8
+ const jsbi_1 = __importDefault(require("jsbi"));
9
+ const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
10
+ const constants_1 = require("../constants");
11
+ const internalConstants_1 = require("../internalConstants");
12
+ const computePoolAddress_1 = require("../utils/computePoolAddress");
13
+ const liquidityMath_1 = require("../utils/liquidityMath");
14
+ const swapMath_1 = require("../utils/swapMath");
15
+ const tickMath_1 = require("../utils/tickMath");
16
+ const tickDataProvider_1 = require("./tickDataProvider");
17
+ const tickListDataProvider_1 = require("./tickListDataProvider");
18
+ /**
19
+ * By default, pools will not allow operations that require ticks.
20
+ */
21
+ const NO_TICK_DATA_PROVIDER_DEFAULT = new tickDataProvider_1.NoTickDataProvider();
22
+ /**
23
+ * Represents a V3 pool
24
+ */
25
+ class Pool {
26
+ static getAddress(tokenA, tokenB, fee, initCodeHashManualOverride, factoryAddressOverride) {
27
+ return (0, computePoolAddress_1.computePoolAddress)({
28
+ factoryAddress: factoryAddressOverride !== null && factoryAddressOverride !== void 0 ? factoryAddressOverride : constants_1.FACTORY_ADDRESS,
29
+ fee,
30
+ tokenA,
31
+ tokenB,
32
+ initCodeHashManualOverride
33
+ });
34
+ }
35
+ /**
36
+ * Construct a pool
37
+ * @param tokenA One of the tokens in the pool
38
+ * @param tokenB The other token in the pool
39
+ * @param fee The fee in hundredths of a bips of the input amount of every swap that is collected by the pool
40
+ * @param sqrtRatioX96 The sqrt of the current ratio of amounts of token1 to token0
41
+ * @param liquidity The current value of in range liquidity
42
+ * @param tickCurrent The current tick of the pool
43
+ * @param ticks The current state of the pool ticks or a data provider that can return tick data
44
+ */
45
+ constructor(tokenA, tokenB, fee, sqrtRatioX96, liquidity, tickCurrent, ticks = NO_TICK_DATA_PROVIDER_DEFAULT) {
46
+ (0, tiny_invariant_1.default)(Number.isInteger(fee) && fee < 1000000, 'FEE');
47
+ const tickCurrentSqrtRatioX96 = tickMath_1.TickMath.getSqrtRatioAtTick(tickCurrent);
48
+ const nextTickSqrtRatioX96 = tickMath_1.TickMath.getSqrtRatioAtTick(tickCurrent + 1);
49
+ (0, tiny_invariant_1.default)(jsbi_1.default.greaterThanOrEqual(jsbi_1.default.BigInt(sqrtRatioX96), tickCurrentSqrtRatioX96) &&
50
+ jsbi_1.default.lessThanOrEqual(jsbi_1.default.BigInt(sqrtRatioX96), nextTickSqrtRatioX96), 'PRICE_BOUNDS');
51
+ [this.token0, this.token1] = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA];
52
+ this.fee = fee;
53
+ this.sqrtRatioX96 = jsbi_1.default.BigInt(sqrtRatioX96);
54
+ this.liquidity = jsbi_1.default.BigInt(liquidity);
55
+ this.tickCurrent = tickCurrent;
56
+ this.tickDataProvider = Array.isArray(ticks) ? new tickListDataProvider_1.TickListDataProvider(ticks, constants_1.TICK_SPACINGS[fee]) : ticks;
57
+ }
58
+ /**
59
+ * Returns true if the token is either token0 or token1
60
+ * @param token The token to check
61
+ * @returns True if token is either token0 or token
62
+ */
63
+ involvesToken(token) {
64
+ return token.equals(this.token0) || token.equals(this.token1);
65
+ }
66
+ /**
67
+ * Returns the current mid price of the pool in terms of token0, i.e. the ratio of token1 over token0
68
+ */
69
+ get token0Price() {
70
+ var _a;
71
+ return ((_a = this._token0Price) !== null && _a !== void 0 ? _a : (this._token0Price = new core_1.Price(this.token0, this.token1, internalConstants_1.Q192, jsbi_1.default.multiply(this.sqrtRatioX96, this.sqrtRatioX96))));
72
+ }
73
+ /**
74
+ * Returns the current mid price of the pool in terms of token1, i.e. the ratio of token0 over token1
75
+ */
76
+ get token1Price() {
77
+ var _a;
78
+ return ((_a = this._token1Price) !== null && _a !== void 0 ? _a : (this._token1Price = new core_1.Price(this.token1, this.token0, jsbi_1.default.multiply(this.sqrtRatioX96, this.sqrtRatioX96), internalConstants_1.Q192)));
79
+ }
80
+ /**
81
+ * Return the price of the given token in terms of the other token in the pool.
82
+ * @param token The token to return price of
83
+ * @returns The price of the given token, in terms of the other.
84
+ */
85
+ priceOf(token) {
86
+ (0, tiny_invariant_1.default)(this.involvesToken(token), 'TOKEN');
87
+ return token.equals(this.token0) ? this.token0Price : this.token1Price;
88
+ }
89
+ /**
90
+ * Returns the chain ID of the tokens in the pool.
91
+ */
92
+ get chainId() {
93
+ return this.token0.chainId;
94
+ }
95
+ /**
96
+ * Given an input amount of a token, return the computed output amount, and a pool with state updated after the trade
97
+ * @param inputAmount The input amount for which to quote the output amount
98
+ * @param sqrtPriceLimitX96 The Q64.96 sqrt price limit
99
+ * @returns The output amount and the pool with updated state
100
+ */
101
+ async getOutputAmount(inputAmount, sqrtPriceLimitX96) {
102
+ (0, tiny_invariant_1.default)(this.involvesToken(inputAmount.currency), 'TOKEN');
103
+ const zeroForOne = inputAmount.currency.equals(this.token0);
104
+ const { amountCalculated: outputAmount, sqrtRatioX96, liquidity, tickCurrent } = await this.swap(zeroForOne, inputAmount.quotient, sqrtPriceLimitX96);
105
+ const outputToken = zeroForOne ? this.token1 : this.token0;
106
+ return [
107
+ core_1.CurrencyAmount.fromRawAmount(outputToken, jsbi_1.default.multiply(outputAmount, internalConstants_1.NEGATIVE_ONE)),
108
+ new Pool(this.token0, this.token1, this.fee, sqrtRatioX96, liquidity, tickCurrent, this.tickDataProvider)
109
+ ];
110
+ }
111
+ /**
112
+ * Given a desired output amount of a token, return the computed input amount and a pool with state updated after the trade
113
+ * @param outputAmount the output amount for which to quote the input amount
114
+ * @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swap
115
+ * @returns The input amount and the pool with updated state
116
+ */
117
+ async getInputAmount(outputAmount, sqrtPriceLimitX96) {
118
+ (0, tiny_invariant_1.default)(outputAmount.currency.isToken && this.involvesToken(outputAmount.currency), 'TOKEN');
119
+ const zeroForOne = outputAmount.currency.equals(this.token1);
120
+ const { amountCalculated: inputAmount, sqrtRatioX96, liquidity, tickCurrent } = await this.swap(zeroForOne, jsbi_1.default.multiply(outputAmount.quotient, internalConstants_1.NEGATIVE_ONE), sqrtPriceLimitX96);
121
+ const inputToken = zeroForOne ? this.token0 : this.token1;
122
+ return [
123
+ core_1.CurrencyAmount.fromRawAmount(inputToken, inputAmount),
124
+ new Pool(this.token0, this.token1, this.fee, sqrtRatioX96, liquidity, tickCurrent, this.tickDataProvider)
125
+ ];
126
+ }
127
+ /**
128
+ * Executes a swap
129
+ * @param zeroForOne Whether the amount in is token0 or token1
130
+ * @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
131
+ * @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swap
132
+ * @returns amountCalculated
133
+ * @returns sqrtRatioX96
134
+ * @returns liquidity
135
+ * @returns tickCurrent
136
+ */
137
+ async swap(zeroForOne, amountSpecified, sqrtPriceLimitX96) {
138
+ if (!sqrtPriceLimitX96)
139
+ sqrtPriceLimitX96 = zeroForOne
140
+ ? jsbi_1.default.add(tickMath_1.TickMath.MIN_SQRT_RATIO, internalConstants_1.ONE)
141
+ : jsbi_1.default.subtract(tickMath_1.TickMath.MAX_SQRT_RATIO, internalConstants_1.ONE);
142
+ if (zeroForOne) {
143
+ (0, tiny_invariant_1.default)(jsbi_1.default.greaterThan(sqrtPriceLimitX96, tickMath_1.TickMath.MIN_SQRT_RATIO), 'RATIO_MIN');
144
+ (0, tiny_invariant_1.default)(jsbi_1.default.lessThan(sqrtPriceLimitX96, this.sqrtRatioX96), 'RATIO_CURRENT');
145
+ }
146
+ else {
147
+ (0, tiny_invariant_1.default)(jsbi_1.default.lessThan(sqrtPriceLimitX96, tickMath_1.TickMath.MAX_SQRT_RATIO), 'RATIO_MAX');
148
+ (0, tiny_invariant_1.default)(jsbi_1.default.greaterThan(sqrtPriceLimitX96, this.sqrtRatioX96), 'RATIO_CURRENT');
149
+ }
150
+ const exactInput = jsbi_1.default.greaterThanOrEqual(amountSpecified, internalConstants_1.ZERO);
151
+ // keep track of swap state
152
+ const state = {
153
+ amountSpecifiedRemaining: amountSpecified,
154
+ amountCalculated: internalConstants_1.ZERO,
155
+ sqrtPriceX96: this.sqrtRatioX96,
156
+ tick: this.tickCurrent,
157
+ liquidity: this.liquidity
158
+ };
159
+ // start swap while loop
160
+ while (jsbi_1.default.notEqual(state.amountSpecifiedRemaining, internalConstants_1.ZERO) && state.sqrtPriceX96 != sqrtPriceLimitX96) {
161
+ let step = {};
162
+ step.sqrtPriceStartX96 = state.sqrtPriceX96;
163
+ [step.tickNext, step.initialized] = await this.tickDataProvider.nextInitializedTickWithinOneWord(state.tick, zeroForOne, this.tickSpacing);
164
+ if (step.tickNext < tickMath_1.TickMath.MIN_TICK) {
165
+ step.tickNext = tickMath_1.TickMath.MIN_TICK;
166
+ }
167
+ else if (step.tickNext > tickMath_1.TickMath.MAX_TICK) {
168
+ step.tickNext = tickMath_1.TickMath.MAX_TICK;
169
+ }
170
+ step.sqrtPriceNextX96 = tickMath_1.TickMath.getSqrtRatioAtTick(step.tickNext);
171
+ [state.sqrtPriceX96, step.amountIn, step.amountOut, step.feeAmount] = swapMath_1.SwapMath.computeSwapStep(state.sqrtPriceX96, (zeroForOne
172
+ ? jsbi_1.default.lessThan(step.sqrtPriceNextX96, sqrtPriceLimitX96)
173
+ : jsbi_1.default.greaterThan(step.sqrtPriceNextX96, sqrtPriceLimitX96))
174
+ ? sqrtPriceLimitX96
175
+ : step.sqrtPriceNextX96, state.liquidity, state.amountSpecifiedRemaining, this.fee);
176
+ if (exactInput) {
177
+ state.amountSpecifiedRemaining = jsbi_1.default.subtract(state.amountSpecifiedRemaining, jsbi_1.default.add(step.amountIn, step.feeAmount));
178
+ state.amountCalculated = jsbi_1.default.subtract(state.amountCalculated, step.amountOut);
179
+ }
180
+ else {
181
+ state.amountSpecifiedRemaining = jsbi_1.default.add(state.amountSpecifiedRemaining, step.amountOut);
182
+ state.amountCalculated = jsbi_1.default.add(state.amountCalculated, jsbi_1.default.add(step.amountIn, step.feeAmount));
183
+ }
184
+ // TODO
185
+ if (jsbi_1.default.equal(state.sqrtPriceX96, step.sqrtPriceNextX96)) {
186
+ // if the tick is initialized, run the tick transition
187
+ if (step.initialized) {
188
+ let liquidityNet = jsbi_1.default.BigInt((await this.tickDataProvider.getTick(step.tickNext)).liquidityNet);
189
+ // if we're moving leftward, we interpret liquidityNet as the opposite sign
190
+ // safe because liquidityNet cannot be type(int128).min
191
+ if (zeroForOne)
192
+ liquidityNet = jsbi_1.default.multiply(liquidityNet, internalConstants_1.NEGATIVE_ONE);
193
+ state.liquidity = liquidityMath_1.LiquidityMath.addDelta(state.liquidity, liquidityNet);
194
+ }
195
+ state.tick = zeroForOne ? step.tickNext - 1 : step.tickNext;
196
+ }
197
+ else if (jsbi_1.default.notEqual(state.sqrtPriceX96, step.sqrtPriceStartX96)) {
198
+ // updated comparison function
199
+ // recompute unless we're on a lower tick boundary (i.e. already transitioned ticks), and haven't moved
200
+ state.tick = tickMath_1.TickMath.getTickAtSqrtRatio(state.sqrtPriceX96);
201
+ }
202
+ }
203
+ return {
204
+ amountCalculated: state.amountCalculated,
205
+ sqrtRatioX96: state.sqrtPriceX96,
206
+ liquidity: state.liquidity,
207
+ tickCurrent: state.tick
208
+ };
209
+ }
210
+ get tickSpacing() {
211
+ return constants_1.TICK_SPACINGS[this.fee];
212
+ }
213
+ }
214
+ exports.Pool = Pool;
215
+ //# sourceMappingURL=pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../src/v3/entities/pool.ts"],"names":[],"mappings":";;;;;;AAAA,qCAAoE;AACpE,gDAAuB;AACvB,oEAAsC;AACtC,4CAAwE;AACxE,4DAAoE;AACpE,oEAAgE;AAChE,0DAAsD;AACtD,gDAA4C;AAC5C,gDAA4C;AAE5C,yDAAyE;AACzE,iEAA6D;AAY7D;;GAEG;AACH,MAAM,6BAA6B,GAAG,IAAI,qCAAkB,EAAE,CAAA;AAE9D;;GAEG;AACH,MAAa,IAAI;IAYR,MAAM,CAAC,UAAU,CACtB,MAAa,EACb,MAAa,EACb,GAAc,EACd,0BAAmC,EACnC,sBAA+B;QAE/B,OAAO,IAAA,uCAAkB,EAAC;YACxB,cAAc,EAAE,sBAAsB,aAAtB,sBAAsB,cAAtB,sBAAsB,GAAI,2BAAe;YACzD,GAAG;YACH,MAAM;YACN,MAAM;YACN,0BAA0B;SAC3B,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;;;;OASG;IACH,YACE,MAAa,EACb,MAAa,EACb,GAAc,EACd,YAAuB,EACvB,SAAoB,EACpB,WAAmB,EACnB,QAA2D,6B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