@paraswap/dex-lib 2.42.4-baseswap.2 → 2.42.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 (194) hide show
  1. package/.vscode/launch.json +16 -0
  2. package/build/dex/uniswap-v3/config.js +0 -14
  3. package/build/dex/uniswap-v3/config.js.map +1 -1
  4. package/build/test.js +26 -0
  5. package/package.json +1 -1
  6. package/src/dex/uniswap-v3/config.ts +0 -14
  7. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +0 -24
  8. package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +0 -375
  9. package/build/abi/kyberswap-elastic/IAntiSnipAttackPositionManager.json +0 -1276
  10. package/build/abi/kyberswap-elastic/IFactory.json +0 -550
  11. package/build/abi/kyberswap-elastic/IPool.json +0 -1042
  12. package/build/abi/kyberswap-elastic/IQuoterV2.json +0 -226
  13. package/build/abi/kyberswap-elastic/IRouter.json +0 -239
  14. package/build/abi/kyberswap-elastic/TicksFeesReader.json +0 -142
  15. package/build/abi/wombat/asset.json +0 -769
  16. package/build/abi/wombat/bmw.json +0 -1247
  17. package/build/abi/wombat/pool.json +0 -1364
  18. package/build/dex/baseswap-v3/baseswap-v3-factory.d.ts +0 -26
  19. package/build/dex/baseswap-v3/baseswap-v3-factory.js +0 -44
  20. package/build/dex/baseswap-v3/baseswap-v3-factory.js.map +0 -1
  21. package/build/dex/baseswap-v3/baseswap-v3-pool.d.ts +0 -46
  22. package/build/dex/baseswap-v3/baseswap-v3-pool.js +0 -312
  23. package/build/dex/baseswap-v3/baseswap-v3-pool.js.map +0 -1
  24. package/build/dex/baseswap-v3/baseswap-v3.d.ts +0 -71
  25. package/build/dex/baseswap-v3/baseswap-v3.js +0 -752
  26. package/build/dex/baseswap-v3/baseswap-v3.js.map +0 -1
  27. package/build/dex/baseswap-v3/config.d.ts +0 -9
  28. package/build/dex/baseswap-v3/config.js +0 -48
  29. package/build/dex/baseswap-v3/config.js.map +0 -1
  30. package/build/dex/baseswap-v3/constants.d.ts +0 -28
  31. package/build/dex/baseswap-v3/constants.js +0 -35
  32. package/build/dex/baseswap-v3/constants.js.map +0 -1
  33. package/build/dex/baseswap-v3/contract-math/BitMath.d.ts +0 -4
  34. package/build/dex/baseswap-v3/contract-math/BitMath.js +0 -93
  35. package/build/dex/baseswap-v3/contract-math/BitMath.js.map +0 -1
  36. package/build/dex/baseswap-v3/contract-math/FixedPoint128.d.ts +0 -3
  37. package/build/dex/baseswap-v3/contract-math/FixedPoint128.js +0 -8
  38. package/build/dex/baseswap-v3/contract-math/FixedPoint128.js.map +0 -1
  39. package/build/dex/baseswap-v3/contract-math/FixedPoint96.d.ts +0 -4
  40. package/build/dex/baseswap-v3/contract-math/FixedPoint96.js +0 -9
  41. package/build/dex/baseswap-v3/contract-math/FixedPoint96.js.map +0 -1
  42. package/build/dex/baseswap-v3/contract-math/FullMath.d.ts +0 -4
  43. package/build/dex/baseswap-v3/contract-math/FullMath.js +0 -19
  44. package/build/dex/baseswap-v3/contract-math/FullMath.js.map +0 -1
  45. package/build/dex/baseswap-v3/contract-math/LiquidityMath.d.ts +0 -3
  46. package/build/dex/baseswap-v3/contract-math/LiquidityMath.js +0 -22
  47. package/build/dex/baseswap-v3/contract-math/LiquidityMath.js.map +0 -1
  48. package/build/dex/baseswap-v3/contract-math/Oracle.d.ts +0 -10
  49. package/build/dex/baseswap-v3/contract-math/Oracle.js +0 -133
  50. package/build/dex/baseswap-v3/contract-math/Oracle.js.map +0 -1
  51. package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.d.ts +0 -10
  52. package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.js +0 -91
  53. package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.js.map +0 -1
  54. package/build/dex/baseswap-v3/contract-math/SwapMath.d.ts +0 -8
  55. package/build/dex/baseswap-v3/contract-math/SwapMath.js +0 -70
  56. package/build/dex/baseswap-v3/contract-math/SwapMath.js.map +0 -1
  57. package/build/dex/baseswap-v3/contract-math/Tick.d.ts +0 -7
  58. package/build/dex/baseswap-v3/contract-math/Tick.js +0 -45
  59. package/build/dex/baseswap-v3/contract-math/Tick.js.map +0 -1
  60. package/build/dex/baseswap-v3/contract-math/TickBitMap.d.ts +0 -7
  61. package/build/dex/baseswap-v3/contract-math/TickBitMap.js +0 -84
  62. package/build/dex/baseswap-v3/contract-math/TickBitMap.js.map +0 -1
  63. package/build/dex/baseswap-v3/contract-math/TickMath.d.ts +0 -8
  64. package/build/dex/baseswap-v3/contract-math/TickMath.js +0 -162
  65. package/build/dex/baseswap-v3/contract-math/TickMath.js.map +0 -1
  66. package/build/dex/baseswap-v3/contract-math/UnsafeMath.d.ts +0 -3
  67. package/build/dex/baseswap-v3/contract-math/UnsafeMath.js +0 -10
  68. package/build/dex/baseswap-v3/contract-math/UnsafeMath.js.map +0 -1
  69. package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.d.ts +0 -37
  70. package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.js +0 -393
  71. package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.js.map +0 -1
  72. package/build/dex/baseswap-v3/contract-math/utils.d.ts +0 -7
  73. package/build/dex/baseswap-v3/contract-math/utils.js +0 -42
  74. package/build/dex/baseswap-v3/contract-math/utils.js.map +0 -1
  75. package/build/dex/baseswap-v3/types.d.ts +0 -164
  76. package/build/dex/baseswap-v3/types.js +0 -9
  77. package/build/dex/baseswap-v3/types.js.map +0 -1
  78. package/build/dex/baseswap-v3/utils.d.ts +0 -6
  79. package/build/dex/baseswap-v3/utils.js +0 -65
  80. package/build/dex/baseswap-v3/utils.js.map +0 -1
  81. package/build/dex/hello/config.d.ts +0 -4
  82. package/build/dex/hello/config.js +0 -15
  83. package/build/dex/hello/config.js.map +0 -1
  84. package/build/dex/hello/hello-pool.d.ts +0 -39
  85. package/build/dex/hello/hello-pool.js +0 -64
  86. package/build/dex/hello/hello-pool.js.map +0 -1
  87. package/build/dex/hello/hello.d.ts +0 -37
  88. package/build/dex/hello/hello.js +0 -126
  89. package/build/dex/hello/hello.js.map +0 -1
  90. package/build/dex/hello/types.d.ts +0 -6
  91. package/build/dex/hello/types.js +0 -3
  92. package/build/dex/hello/types.js.map +0 -1
  93. package/build/dex/kyberswap-elastic/config.d.ts +0 -4
  94. package/build/dex/kyberswap-elastic/config.js +0 -80
  95. package/build/dex/kyberswap-elastic/config.js.map +0 -1
  96. package/build/dex/kyberswap-elastic/constants.d.ts +0 -17
  97. package/build/dex/kyberswap-elastic/constants.js +0 -42
  98. package/build/dex/kyberswap-elastic/constants.js.map +0 -1
  99. package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.d.ts +0 -4
  100. package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.js +0 -9
  101. package/build/dex/kyberswap-elastic/contract-math/FixedPoint96.js.map +0 -1
  102. package/build/dex/kyberswap-elastic/contract-math/FullMath.d.ts +0 -5
  103. package/build/dex/kyberswap-elastic/contract-math/FullMath.js +0 -22
  104. package/build/dex/kyberswap-elastic/contract-math/FullMath.js.map +0 -1
  105. package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.d.ts +0 -3
  106. package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.js +0 -12
  107. package/build/dex/kyberswap-elastic/contract-math/LiqDeltaMath.js.map +0 -1
  108. package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.d.ts +0 -3
  109. package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.js +0 -22
  110. package/build/dex/kyberswap-elastic/contract-math/LiquidityMath.js.map +0 -1
  111. package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.d.ts +0 -5
  112. package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.js +0 -25
  113. package/build/dex/kyberswap-elastic/contract-math/QtyDeltaMath.js.map +0 -1
  114. package/build/dex/kyberswap-elastic/contract-math/QuadMath.d.ts +0 -4
  115. package/build/dex/kyberswap-elastic/contract-math/QuadMath.js +0 -27
  116. package/build/dex/kyberswap-elastic/contract-math/QuadMath.js.map +0 -1
  117. package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.d.ts +0 -3
  118. package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.js +0 -14
  119. package/build/dex/kyberswap-elastic/contract-math/ReinvestmentMath.js.map +0 -1
  120. package/build/dex/kyberswap-elastic/contract-math/SafeCast.d.ts +0 -8
  121. package/build/dex/kyberswap-elastic/contract-math/SafeCast.js +0 -30
  122. package/build/dex/kyberswap-elastic/contract-math/SafeCast.js.map +0 -1
  123. package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.d.ts +0 -10
  124. package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.js +0 -91
  125. package/build/dex/kyberswap-elastic/contract-math/SqrtPriceMath.js.map +0 -1
  126. package/build/dex/kyberswap-elastic/contract-math/SwapMath.d.ts +0 -13
  127. package/build/dex/kyberswap-elastic/contract-math/SwapMath.js +0 -188
  128. package/build/dex/kyberswap-elastic/contract-math/SwapMath.js.map +0 -1
  129. package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.d.ts +0 -6
  130. package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.js +0 -41
  131. package/build/dex/kyberswap-elastic/contract-math/TickLinkedList.js.map +0 -1
  132. package/build/dex/kyberswap-elastic/contract-math/TickMath.d.ts +0 -9
  133. package/build/dex/kyberswap-elastic/contract-math/TickMath.js +0 -165
  134. package/build/dex/kyberswap-elastic/contract-math/TickMath.js.map +0 -1
  135. package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.d.ts +0 -3
  136. package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.js +0 -10
  137. package/build/dex/kyberswap-elastic/contract-math/UnsafeMath.js.map +0 -1
  138. package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.d.ts +0 -28
  139. package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.js +0 -502
  140. package/build/dex/kyberswap-elastic/contract-math/kyberswap-elastic-math.js.map +0 -1
  141. package/build/dex/kyberswap-elastic/contract-math/utils.d.ts +0 -3
  142. package/build/dex/kyberswap-elastic/contract-math/utils.js +0 -16
  143. package/build/dex/kyberswap-elastic/contract-math/utils.js.map +0 -1
  144. package/build/dex/kyberswap-elastic/errors.d.ts +0 -2
  145. package/build/dex/kyberswap-elastic/errors.js +0 -6
  146. package/build/dex/kyberswap-elastic/errors.js.map +0 -1
  147. package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.d.ts +0 -80
  148. package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.js +0 -458
  149. package/build/dex/kyberswap-elastic/kyberswap-elastic-pool.js.map +0 -1
  150. package/build/dex/kyberswap-elastic/kyberswap-elastic.d.ts +0 -53
  151. package/build/dex/kyberswap-elastic/kyberswap-elastic.js +0 -610
  152. package/build/dex/kyberswap-elastic/kyberswap-elastic.js.map +0 -1
  153. package/build/dex/kyberswap-elastic/types.d.ts +0 -134
  154. package/build/dex/kyberswap-elastic/types.js +0 -9
  155. package/build/dex/kyberswap-elastic/types.js.map +0 -1
  156. package/build/dex/kyberswap-elastic/utils/decoders.d.ts +0 -9
  157. package/build/dex/kyberswap-elastic/utils/decoders.js +0 -78
  158. package/build/dex/kyberswap-elastic/utils/decoders.js.map +0 -1
  159. package/build/dex/my-test-dex/config.d.ts +0 -4
  160. package/build/dex/my-test-dex/config.js +0 -15
  161. package/build/dex/my-test-dex/config.js.map +0 -1
  162. package/build/dex/my-test-dex/my-test-dex-pool.d.ts +0 -39
  163. package/build/dex/my-test-dex/my-test-dex-pool.js +0 -64
  164. package/build/dex/my-test-dex/my-test-dex-pool.js.map +0 -1
  165. package/build/dex/my-test-dex/my-test-dex.d.ts +0 -37
  166. package/build/dex/my-test-dex/my-test-dex.js +0 -126
  167. package/build/dex/my-test-dex/my-test-dex.js.map +0 -1
  168. package/build/dex/my-test-dex/types.d.ts +0 -6
  169. package/build/dex/my-test-dex/types.js +0 -3
  170. package/build/dex/my-test-dex/types.js.map +0 -1
  171. package/build/dex/solidly/forks-override/fvm.d.ts +0 -20
  172. package/build/dex/solidly/forks-override/fvm.js +0 -42
  173. package/build/dex/solidly/forks-override/fvm.js.map +0 -1
  174. package/build/dex/wombat/config.d.ts +0 -5
  175. package/build/dex/wombat/config.js +0 -36
  176. package/build/dex/wombat/config.js.map +0 -1
  177. package/build/dex/wombat/types.d.ts +0 -33
  178. package/build/dex/wombat/types.js +0 -3
  179. package/build/dex/wombat/types.js.map +0 -1
  180. package/build/dex/wombat/utils.d.ts +0 -9
  181. package/build/dex/wombat/utils.js +0 -66
  182. package/build/dex/wombat/utils.js.map +0 -1
  183. package/build/dex/wombat/wombat-bmw.d.ts +0 -40
  184. package/build/dex/wombat/wombat-bmw.js +0 -145
  185. package/build/dex/wombat/wombat-bmw.js.map +0 -1
  186. package/build/dex/wombat/wombat-pool.d.ts +0 -22
  187. package/build/dex/wombat/wombat-pool.js +0 -161
  188. package/build/dex/wombat/wombat-pool.js.map +0 -1
  189. package/build/dex/wombat/wombat-quoter.d.ts +0 -16
  190. package/build/dex/wombat/wombat-quoter.js +0 -176
  191. package/build/dex/wombat/wombat-quoter.js.map +0 -1
  192. package/build/dex/wombat/wombat.d.ts +0 -55
  193. package/build/dex/wombat/wombat.js +0 -292
  194. package/build/dex/wombat/wombat.js.map +0 -1
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LiquidityMath = void 0;
4
- const utils_1 = require("../../../utils");
5
- class LiquidityMath {
6
- static addDelta(x, y) {
7
- let z;
8
- if (y < 0) {
9
- const _y = BigInt.asUintN(128, -y);
10
- z = x - _y;
11
- (0, utils_1._require)(z < x, 'LS', { z, x, y, _y }, 'z < x');
12
- }
13
- else {
14
- const _y = BigInt.asUintN(128, y);
15
- z = x + _y;
16
- (0, utils_1._require)(z >= x, 'LA', { z, x, y, _y }, 'z >= x');
17
- }
18
- return z;
19
- }
20
- }
21
- exports.LiquidityMath = LiquidityMath;
22
- //# sourceMappingURL=LiquidityMath.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LiquidityMath.js","sourceRoot":"","sources":["../../../../src/dex/kyberswap-elastic/contract-math/LiquidityMath.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAE1C,MAAa,aAAa;IACxB,MAAM,CAAC,QAAQ,CAAC,CAAS,EAAE,CAAS;QAClC,IAAI,CAAC,CAAC;QACN,IAAI,CAAC,GAAG,CAAC,EAAE;YACT,MAAM,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;YACnC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;YACX,IAAA,gBAAQ,EAAC,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;SACjD;aAAM;YACL,MAAM,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAClC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;YACX,IAAA,gBAAQ,EAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC;SACnD;QACD,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AAdD,sCAcC"}
@@ -1,5 +0,0 @@
1
- export declare class QtyDeltaMath {
2
- static calcRequiredQty0(lowerSqrtP: bigint, upperSqrtP: bigint, liquidity: bigint, isAdd: boolean): bigint;
3
- static calcRequiredQty1(lowerSqrtP: bigint, upperSqrtP: bigint, liquidity: bigint, isAdd: boolean): bigint;
4
- static divCeil(a: bigint, b: bigint): bigint;
5
- }
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QtyDeltaMath = void 0;
4
- const constants_1 = require("../constants");
5
- const FullMath_1 = require("./FullMath");
6
- const SafeCast_1 = require("./SafeCast");
7
- class QtyDeltaMath {
8
- static calcRequiredQty0(lowerSqrtP, upperSqrtP, liquidity, isAdd) {
9
- let numerator1 = liquidity << 96n;
10
- let numerator2 = upperSqrtP - lowerSqrtP;
11
- return isAdd
12
- ? SafeCast_1.SafeCast.toInt256(this.divCeil(FullMath_1.FullMath.mulDivCeil(numerator1, numerator2, upperSqrtP), lowerSqrtP))
13
- : SafeCast_1.SafeCast.revToInt256(FullMath_1.FullMath.mulDivFloor(numerator1, numerator2, upperSqrtP) / lowerSqrtP);
14
- }
15
- static calcRequiredQty1(lowerSqrtP, upperSqrtP, liquidity, isAdd) {
16
- return isAdd
17
- ? SafeCast_1.SafeCast.toInt256(FullMath_1.FullMath.mulDivCeil(liquidity, upperSqrtP - lowerSqrtP, constants_1.TWO_POW_96))
18
- : SafeCast_1.SafeCast.revToInt256(FullMath_1.FullMath.mulDivFloor(liquidity, upperSqrtP - lowerSqrtP, constants_1.TWO_POW_96));
19
- }
20
- static divCeil(a, b) {
21
- return (a + b - 1n) / b;
22
- }
23
- }
24
- exports.QtyDeltaMath = QtyDeltaMath;
25
- //# sourceMappingURL=QtyDeltaMath.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"QtyDeltaMath.js","sourceRoot":"","sources":["../../../../src/dex/kyberswap-elastic/contract-math/QtyDeltaMath.ts"],"names":[],"mappings":";;;AAAA,4CAA0C;AAC1C,yCAAsC;AACtC,yCAAsC;AAEtC,MAAa,YAAY;IACvB,MAAM,CAAC,gBAAgB,CACrB,UAAkB,EAClB,UAAkB,EAClB,SAAiB,EACjB,KAAc;QAEd,IAAI,UAAU,GAAG,SAAS,IAAI,GAAG,CAAC;QAClC,IAAI,UAAU,GAAG,UAAU,GAAG,UAAU,CAAC;QAEzC,OAAO,KAAK;YACV,CAAC,CAAC,mBAAQ,CAAC,QAAQ,CACf,IAAI,CAAC,OAAO,CACV,mBAAQ,CAAC,UAAU,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,EACvD,UAAU,CACX,CACF;YACH,CAAC,CAAC,mBAAQ,CAAC,WAAW,CAClB,mBAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,GAAG,UAAU,CACtE,CAAC;IACR,CAAC;IAED,MAAM,CAAC,gBAAgB,CACrB,UAAkB,EAClB,UAAkB,EAClB,SAAiB,EACjB,KAAc;QAEd,OAAO,KAAK;YACV,CAAC,CAAC,mBAAQ,CAAC,QAAQ,CACf,mBAAQ,CAAC,UAAU,CAAC,SAAS,EAAE,UAAU,GAAG,UAAU,EAAE,sBAAU,CAAC,CACpE;YACH,CAAC,CAAC,mBAAQ,CAAC,WAAW,CAClB,mBAAQ,CAAC,WAAW,CAAC,SAAS,EAAE,UAAU,GAAG,UAAU,EAAE,sBAAU,CAAC,CACrE,CAAC;IACR,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,CAAS,EAAE,CAAS;QACjC,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;CACF;AAxCD,oCAwCC"}
@@ -1,4 +0,0 @@
1
- export declare class QuadMath {
2
- static getSmallerRootOfQuadEqn(a: bigint, b: bigint, c: bigint): bigint;
3
- static sqrt(y: bigint): bigint;
4
- }
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QuadMath = void 0;
4
- class QuadMath {
5
- static getSmallerRootOfQuadEqn(a, b, c) {
6
- let smallerRoot = 0n;
7
- smallerRoot = (b - this.sqrt(b * b - a * c)) / a;
8
- return smallerRoot;
9
- }
10
- static sqrt(y) {
11
- let z = 0n;
12
- if (y > 3) {
13
- z = y;
14
- let x = y / 2n + 1n;
15
- while (x < z) {
16
- z = x;
17
- x = (y / x + x) / 2n;
18
- }
19
- }
20
- else if (y != 0n) {
21
- z = 1n;
22
- }
23
- return z;
24
- }
25
- }
26
- exports.QuadMath = QuadMath;
27
- //# sourceMappingURL=QuadMath.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"QuadMath.js","sourceRoot":"","sources":["../../../../src/dex/kyberswap-elastic/contract-math/QuadMath.ts"],"names":[],"mappings":";;;AAAA,MAAa,QAAQ;IACnB,MAAM,CAAC,uBAAuB,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS;QAC5D,IAAI,WAAW,GAAW,EAAE,CAAC;QAE7B,WAAW,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACjD,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,CAAS;QACnB,IAAI,CAAC,GAAG,EAAE,CAAC;QAEX,IAAI,CAAC,GAAG,CAAC,EAAE;YACT,CAAC,GAAG,CAAC,CAAC;YACN,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,EAAE;gBACZ,CAAC,GAAG,CAAC,CAAC;gBACN,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;aACtB;SACF;aAAM,IAAI,CAAC,IAAI,EAAE,EAAE;YAClB,CAAC,GAAG,EAAE,CAAC;SACR;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AAxBD,4BAwBC"}
@@ -1,3 +0,0 @@
1
- export declare class ReinvestmentMath {
2
- static calcrMintQty(reinvestL: bigint, reinvestLLast: bigint, baseL: bigint, rTokenSupply: bigint): bigint;
3
- }
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReinvestmentMath = void 0;
4
- const FullMath_1 = require("./FullMath");
5
- class ReinvestmentMath {
6
- static calcrMintQty(reinvestL, reinvestLLast, baseL, rTokenSupply) {
7
- let rMintQty = 0n;
8
- let lpContribution = FullMath_1.FullMath.mulDivFloor(baseL, reinvestL - reinvestLLast, baseL + reinvestL);
9
- rMintQty = FullMath_1.FullMath.mulDivFloor(rTokenSupply, lpContribution, reinvestLLast);
10
- return rMintQty;
11
- }
12
- }
13
- exports.ReinvestmentMath = ReinvestmentMath;
14
- //# sourceMappingURL=ReinvestmentMath.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ReinvestmentMath.js","sourceRoot":"","sources":["../../../../src/dex/kyberswap-elastic/contract-math/ReinvestmentMath.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AACtC,MAAa,gBAAgB;IAC3B,MAAM,CAAC,YAAY,CACjB,SAAiB,EACjB,aAAqB,EACrB,KAAa,EACb,YAAoB;QAEpB,IAAI,QAAQ,GAAW,EAAE,CAAC;QAE1B,IAAI,cAAc,GAAG,mBAAQ,CAAC,WAAW,CACvC,KAAK,EACL,SAAS,GAAG,aAAa,EACzB,KAAK,GAAG,SAAS,CAClB,CAAC;QACF,QAAQ,GAAG,mBAAQ,CAAC,WAAW,CAC7B,YAAY,EACZ,cAAc,EACd,aAAa,CACd,CAAC;QACF,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AArBD,4CAqBC"}
@@ -1,8 +0,0 @@
1
- export declare class SafeCast {
2
- static toInt256(a: bigint): bigint;
3
- static revToInt256(a: bigint): bigint;
4
- static revToInt128(a: bigint): bigint;
5
- static revToUint256(a: bigint): bigint;
6
- static revToUint128(a: bigint): bigint;
7
- static toUint160(y: bigint): bigint;
8
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SafeCast = void 0;
4
- const utils_1 = require("../../../utils");
5
- class SafeCast {
6
- static toInt256(a) {
7
- (0, utils_1._require)(a < 2n ** 255n, 'toInt256: a < 2n ** 255n');
8
- return BigInt.asIntN(256, a);
9
- }
10
- static revToInt256(a) {
11
- (0, utils_1._require)(a < 2n ** 255n, 'toInt256: a < 2n ** 255n');
12
- return BigInt.asIntN(256, -a);
13
- }
14
- static revToInt128(a) {
15
- (0, utils_1._require)(a < 2n ** 127n, 'toInt256: a < 2n ** 255n');
16
- return BigInt.asIntN(128, -a);
17
- }
18
- static revToUint256(a) {
19
- return BigInt.asUintN(256, -a);
20
- }
21
- static revToUint128(a) {
22
- return BigInt.asUintN(128, -a);
23
- }
24
- static toUint160(y) {
25
- (0, utils_1._require)(BigInt.asUintN(160, y) == y, 'toUint160 overflow');
26
- return BigInt.asUintN(160, y);
27
- }
28
- }
29
- exports.SafeCast = SafeCast;
30
- //# sourceMappingURL=SafeCast.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SafeCast.js","sourceRoot":"","sources":["../../../../src/dex/kyberswap-elastic/contract-math/SafeCast.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAE1C,MAAa,QAAQ;IACnB,MAAM,CAAC,QAAQ,CAAC,CAAS;QACvB,IAAA,gBAAQ,EAAC,CAAC,GAAG,EAAE,IAAI,IAAI,EAAE,0BAA0B,CAAC,CAAC;QACrD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,CAAS;QAC1B,IAAA,gBAAQ,EAAC,CAAC,GAAG,EAAE,IAAI,IAAI,EAAE,0BAA0B,CAAC,CAAC;QACrD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,CAAS;QAC1B,IAAA,gBAAQ,EAAC,CAAC,GAAG,EAAE,IAAI,IAAI,EAAE,0BAA0B,CAAC,CAAC;QACrD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,CAAS;QAC3B,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,CAAS;QAC3B,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,CAAS;QACxB,IAAA,gBAAQ,EAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,oBAAoB,CAAC,CAAC;QAC5D,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAChC,CAAC;CACF;AA5BD,4BA4BC"}
@@ -1,10 +0,0 @@
1
- export declare class SqrtPriceMath {
2
- static getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96: bigint, liquidity: bigint, amount: bigint, add: boolean): bigint;
3
- static getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96: bigint, liquidity: bigint, amount: bigint, add: boolean): bigint;
4
- static getNextSqrtPriceFromInput(sqrtPX96: bigint, liquidity: bigint, amountIn: bigint, zeroForOne: boolean): bigint;
5
- static getNextSqrtPriceFromOutput(sqrtPX96: bigint, liquidity: bigint, amountOut: bigint, zeroForOne: boolean): bigint;
6
- static getAmount0Delta(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, liquidity: bigint, roundUp: boolean): bigint;
7
- static getAmount1Delta(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, liquidity: bigint, roundUp: boolean): bigint;
8
- static _getAmount0DeltaO(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, liquidity: bigint): bigint;
9
- static _getAmount1DeltaO(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, liquidity: bigint): bigint;
10
- }
@@ -1,91 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SqrtPriceMath = void 0;
4
- const bigint_constants_1 = require("../../../bigint-constants");
5
- const FixedPoint96_1 = require("./FixedPoint96");
6
- const FullMath_1 = require("./FullMath");
7
- const UnsafeMath_1 = require("./UnsafeMath");
8
- const utils_1 = require("../../../utils");
9
- class SqrtPriceMath {
10
- static getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amount, add) {
11
- if (amount === 0n)
12
- return sqrtPX96;
13
- const numerator1 = BigInt.asUintN(256, liquidity) << FixedPoint96_1.FixedPoint96.RESOLUTION;
14
- const product = amount * sqrtPX96;
15
- if (add) {
16
- if (product / amount === sqrtPX96) {
17
- const denominator = numerator1 + product;
18
- if (denominator >= numerator1) {
19
- return BigInt.asUintN(160, FullMath_1.FullMath.mulDivCeil(numerator1, sqrtPX96, denominator));
20
- }
21
- }
22
- return BigInt.asUintN(160, UnsafeMath_1.UnsafeMath.divRoundingUp(numerator1, numerator1 / sqrtPX96 + amount));
23
- }
24
- else {
25
- (0, utils_1._require)(product / amount === sqrtPX96 && numerator1 > product, '', { product, amount, sqrtPX96, numerator1 }, 'product / amount === sqrtPX96 && numerator1 > product');
26
- const denominator = numerator1 - product;
27
- return BigInt.asUintN(160, FullMath_1.FullMath.mulDivCeil(numerator1, sqrtPX96, denominator));
28
- }
29
- }
30
- static getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amount, add) {
31
- if (add) {
32
- const quotient = amount <= bigint_constants_1.BI_MAX_UINT160
33
- ? (amount << FixedPoint96_1.FixedPoint96.RESOLUTION) / liquidity
34
- : FullMath_1.FullMath.mulDiv(amount, FixedPoint96_1.FixedPoint96.Q96, liquidity);
35
- return BigInt.asUintN(160, BigInt.asUintN(256, sqrtPX96) + quotient);
36
- }
37
- else {
38
- const quotient = amount <= bigint_constants_1.BI_MAX_UINT160
39
- ? UnsafeMath_1.UnsafeMath.divRoundingUp(amount << FixedPoint96_1.FixedPoint96.RESOLUTION, liquidity)
40
- : FullMath_1.FullMath.mulDivCeil(amount, FixedPoint96_1.FixedPoint96.Q96, liquidity);
41
- (0, utils_1._require)(sqrtPX96 > quotient, '', { sqrtPX96, quotient }, 'sqrtPX96 > quotient');
42
- return BigInt.asUintN(160, sqrtPX96 - quotient);
43
- }
44
- }
45
- static getNextSqrtPriceFromInput(sqrtPX96, liquidity, amountIn, zeroForOne) {
46
- (0, utils_1._require)(sqrtPX96 > 0n, '', { sqrtPX96 }, 'sqrtPX96 > 0n');
47
- (0, utils_1._require)(liquidity > 0n, '', { liquidity }, 'liquidity > 0n');
48
- return zeroForOne
49
- ? SqrtPriceMath.getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountIn, true)
50
- : SqrtPriceMath.getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountIn, true);
51
- }
52
- static getNextSqrtPriceFromOutput(sqrtPX96, liquidity, amountOut, zeroForOne) {
53
- (0, utils_1._require)(sqrtPX96 > 0n, '', { sqrtPX96 }, 'sqrtPX96 > 0n');
54
- (0, utils_1._require)(liquidity > 0n, '', { liquidity }, 'liquidity > 0n');
55
- return zeroForOne
56
- ? SqrtPriceMath.getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountOut, false)
57
- : SqrtPriceMath.getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountOut, false);
58
- }
59
- static getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp) {
60
- if (sqrtRatioAX96 > sqrtRatioBX96) {
61
- [sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
62
- }
63
- const numerator1 = BigInt.asUintN(256, liquidity) << FixedPoint96_1.FixedPoint96.RESOLUTION;
64
- const numerator2 = sqrtRatioBX96 - sqrtRatioAX96;
65
- (0, utils_1._require)(sqrtRatioAX96 > 0, '', { sqrtRatioAX96 }, 'sqrtRatioAX96 > 0');
66
- return roundUp
67
- ? UnsafeMath_1.UnsafeMath.divRoundingUp(FullMath_1.FullMath.mulDivCeil(numerator1, numerator2, sqrtRatioBX96), sqrtRatioAX96)
68
- : FullMath_1.FullMath.mulDiv(numerator1, numerator2, sqrtRatioBX96) / sqrtRatioAX96;
69
- }
70
- static getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp) {
71
- if (sqrtRatioAX96 > sqrtRatioBX96)
72
- [sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
73
- return roundUp
74
- ? FullMath_1.FullMath.mulDivCeil(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96_1.FixedPoint96.Q96)
75
- : FullMath_1.FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96_1.FixedPoint96.Q96);
76
- }
77
- // Overloaded with different argument numbers
78
- static _getAmount0DeltaO(sqrtRatioAX96, sqrtRatioBX96, liquidity) {
79
- return liquidity < 0
80
- ? -BigInt.asIntN(256, SqrtPriceMath.getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, BigInt.asUintN(128, -liquidity), false))
81
- : BigInt.asIntN(256, SqrtPriceMath.getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, BigInt.asUintN(128, liquidity), true));
82
- }
83
- // Overloaded with different argument numbers
84
- static _getAmount1DeltaO(sqrtRatioAX96, sqrtRatioBX96, liquidity) {
85
- return liquidity < 0
86
- ? -BigInt.asIntN(256, SqrtPriceMath.getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, BigInt.asUintN(128, -liquidity), false))
87
- : BigInt.asIntN(256, SqrtPriceMath.getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, BigInt.asUintN(128, liquidity), true));
88
- }
89
- }
90
- exports.SqrtPriceMath = SqrtPriceMath;
91
- //# sourceMappingURL=SqrtPriceMath.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SqrtPriceMath.js","sourceRoot":"","sources":["../../../../src/dex/kyberswap-elastic/contract-math/SqrtPriceMath.ts"],"names":[],"mappings":";;;AAAA,gEAA2D;AAC3D,iDAA8C;AAC9C,yCAAsC;AACtC,6CAA0C;AAC1C,0CAA0C;AAE1C,MA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K,CACN,CACF;YACH,CAAC,CAAC,MAAM,CAAC,MAAM,CACX,GAAG,EACH,aAAa,CAAC,eAAe,CAC3B,aAAa,EACb,aAAa,EACb,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,EAC9B,IAAI,CACL,CACF,CAAC;IACR,CAAC;CACF;AA3ND,sCA2NC"}
@@ -1,13 +0,0 @@
1
- export declare class SwapMath {
2
- static computeSwapStep(liquidity: bigint, currentSqrtP: bigint, targetSqrtP: bigint, feeInFeeUnits: bigint, specifiedAmount: bigint, isExactInput: boolean, isToken0: boolean): {
3
- usedAmount: bigint;
4
- returnedAmount: bigint;
5
- deltaL: bigint;
6
- nextSqrtP: bigint;
7
- };
8
- static calcReachAmount(liquidity: bigint, currentSqrtP: bigint, targetSqrtP: bigint, feeInFeeUnits: bigint, isExactInput: boolean, isToken0: boolean): bigint;
9
- static estimateIncrementalLiquidity(absDelta: bigint, liquidity: bigint, currentSqrtP: bigint, feeInFeeUnits: bigint, isExactInput: boolean, isToken0: boolean): bigint;
10
- static calcIncrementalLiquidity(absDelta: bigint, liquidity: bigint, currentSqrtP: bigint, nextSqrtP: bigint, isExactInput: boolean, isToken0: boolean): bigint;
11
- static calcFinalPrice(absDelta: bigint, liquidity: bigint, deltaL: bigint, currentSqrtP: bigint, isExactInput: boolean, isToken0: boolean): bigint;
12
- static calcReturnedAmount(liquidity: bigint, currentSqrtP: bigint, nextSqrtP: bigint, deltaL: bigint, isExactInput: boolean, isToken0: boolean): bigint;
13
- }
@@ -1,188 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SwapMath = void 0;
4
- const constants_1 = require("../constants");
5
- const FullMath_1 = require("./FullMath");
6
- const QuadMath_1 = require("./QuadMath");
7
- const SafeCast_1 = require("./SafeCast");
8
- class SwapMath {
9
- static computeSwapStep(liquidity, currentSqrtP, targetSqrtP, feeInFeeUnits, specifiedAmount, isExactInput, isToken0) {
10
- let nextSqrtP = 0n;
11
- let deltaL = 0n;
12
- let returnedAmount = 0n;
13
- let usedAmount = 0n;
14
- if (currentSqrtP === targetSqrtP)
15
- return {
16
- usedAmount,
17
- returnedAmount,
18
- deltaL,
19
- nextSqrtP: currentSqrtP,
20
- };
21
- usedAmount = this.calcReachAmount(liquidity, currentSqrtP, targetSqrtP, feeInFeeUnits, isExactInput, isToken0);
22
- if ((isExactInput && usedAmount > specifiedAmount) ||
23
- (!isExactInput && usedAmount <= specifiedAmount)) {
24
- usedAmount = specifiedAmount;
25
- }
26
- else {
27
- nextSqrtP = targetSqrtP;
28
- }
29
- let absDelta = usedAmount >= 0 ? usedAmount : SafeCast_1.SafeCast.revToUint256(usedAmount);
30
- if (nextSqrtP == 0n) {
31
- deltaL = this.estimateIncrementalLiquidity(absDelta, liquidity, currentSqrtP, feeInFeeUnits, isExactInput, isToken0);
32
- nextSqrtP = SafeCast_1.SafeCast.toUint160(this.calcFinalPrice(absDelta, liquidity, deltaL, currentSqrtP, isExactInput, isToken0));
33
- }
34
- else {
35
- deltaL = this.calcIncrementalLiquidity(absDelta, liquidity, currentSqrtP, nextSqrtP, isExactInput, isToken0);
36
- }
37
- returnedAmount = this.calcReturnedAmount(liquidity, currentSqrtP, nextSqrtP, deltaL, isExactInput, isToken0);
38
- return {
39
- usedAmount,
40
- returnedAmount,
41
- deltaL,
42
- nextSqrtP: BigInt.asUintN(160, nextSqrtP),
43
- };
44
- }
45
- static calcReachAmount(liquidity, currentSqrtP, targetSqrtP, feeInFeeUnits, isExactInput, isToken0) {
46
- let reachAmount = 0n;
47
- let absPriceDiff;
48
- absPriceDiff =
49
- currentSqrtP >= targetSqrtP
50
- ? currentSqrtP - targetSqrtP
51
- : targetSqrtP - currentSqrtP;
52
- if (isExactInput) {
53
- if (isToken0) {
54
- let denominator = constants_1.TWO_FEE_UNITS * targetSqrtP - feeInFeeUnits * currentSqrtP;
55
- let numerator = FullMath_1.FullMath.mulDivFloor(liquidity, constants_1.TWO_FEE_UNITS * absPriceDiff, denominator);
56
- reachAmount = SafeCast_1.SafeCast.toInt256(FullMath_1.FullMath.mulDivFloor(numerator, constants_1.TWO_POW_96, currentSqrtP));
57
- }
58
- else {
59
- let denominator = constants_1.TWO_FEE_UNITS * currentSqrtP - feeInFeeUnits * targetSqrtP;
60
- let numerator = FullMath_1.FullMath.mulDivFloor(liquidity, constants_1.TWO_FEE_UNITS * absPriceDiff, denominator);
61
- reachAmount = SafeCast_1.SafeCast.toInt256(FullMath_1.FullMath.mulDivFloor(numerator, currentSqrtP, constants_1.TWO_POW_96));
62
- }
63
- }
64
- else {
65
- if (isToken0) {
66
- // numerator: (liquidity)(absPriceDiff)(2 * currentSqrtP - deltaL * (currentSqrtP + targetSqrtP))
67
- // denominator: (currentSqrtP * targetSqrtP) * (2 * currentSqrtP - deltaL * targetSqrtP)
68
- // overflow should not happen because the absPriceDiff is capped to ~5%
69
- let denominator = constants_1.TWO_FEE_UNITS * currentSqrtP - feeInFeeUnits * targetSqrtP;
70
- let numerator = denominator - feeInFeeUnits * currentSqrtP;
71
- numerator = FullMath_1.FullMath.mulDivFloor(liquidity << 96n, numerator, denominator);
72
- reachAmount = SafeCast_1.SafeCast.revToInt256(FullMath_1.FullMath.mulDivFloor(numerator, absPriceDiff, currentSqrtP) /
73
- targetSqrtP);
74
- }
75
- else {
76
- // numerator: liquidity * absPriceDiff * (TWO_FEE_UNITS * targetSqrtP - feeInFeeUnits * (targetSqrtP + currentSqrtP))
77
- // denominator: (TWO_FEE_UNITS * targetSqrtP - feeInFeeUnits * currentSqrtP)
78
- // overflow should not happen because the absPriceDiff is capped to ~5%
79
- let denominator = constants_1.TWO_FEE_UNITS * targetSqrtP - feeInFeeUnits * currentSqrtP;
80
- let numerator = denominator - feeInFeeUnits * targetSqrtP;
81
- numerator = FullMath_1.FullMath.mulDivFloor(liquidity, numerator, denominator);
82
- reachAmount = SafeCast_1.SafeCast.revToInt256(FullMath_1.FullMath.mulDivFloor(numerator, absPriceDiff, constants_1.TWO_POW_96));
83
- }
84
- }
85
- return reachAmount;
86
- }
87
- static estimateIncrementalLiquidity(absDelta, liquidity, currentSqrtP, feeInFeeUnits, isExactInput, isToken0) {
88
- let deltaL = 0n;
89
- if (isExactInput) {
90
- if (isToken0) {
91
- // deltaL = feeInFeeUnits * absDelta * currentSqrtP / 2
92
- deltaL = FullMath_1.FullMath.mulDivFloor(currentSqrtP, absDelta * feeInFeeUnits, constants_1.TWO_FEE_UNITS << 96n);
93
- }
94
- else {
95
- // deltaL = feeInFeeUnits * absDelta * / (currentSqrtP * 2)
96
- // Because nextSqrtP = (liquidity + absDelta / currentSqrtP) * currentSqrtP / (liquidity + deltaL)
97
- // so we round up deltaL, to round down nextSqrtP
98
- deltaL = FullMath_1.FullMath.mulDivFloor(constants_1.TWO_POW_96, absDelta * feeInFeeUnits, constants_1.TWO_FEE_UNITS * currentSqrtP);
99
- }
100
- }
101
- else {
102
- // obtain the smaller root of the quadratic equation
103
- // ax^2 - 2bx + c = 0 such that b > 0, and x denotes deltaL
104
- let a = feeInFeeUnits;
105
- let b = (constants_1.FEE_UNITS - feeInFeeUnits) * liquidity;
106
- let c = feeInFeeUnits * liquidity * absDelta;
107
- if (isToken0) {
108
- // a = feeInFeeUnits
109
- // b = (FEE_UNITS - feeInFeeUnits) * liquidity - FEE_UNITS * absDelta * currentSqrtP
110
- // c = feeInFeeUnits * liquidity * absDelta * currentSqrtP
111
- b -= FullMath_1.FullMath.mulDivFloor(constants_1.FEE_UNITS * absDelta, currentSqrtP, constants_1.TWO_POW_96);
112
- c = FullMath_1.FullMath.mulDivFloor(c, currentSqrtP, constants_1.TWO_POW_96);
113
- }
114
- else {
115
- // a = feeInFeeUnits
116
- // b = (FEE_UNITS - feeInFeeUnits) * liquidity - FEE_UNITS * absDelta / currentSqrtP
117
- // c = liquidity * feeInFeeUnits * absDelta / currentSqrtP
118
- b -= FullMath_1.FullMath.mulDivFloor(constants_1.FEE_UNITS * absDelta, constants_1.TWO_POW_96, currentSqrtP);
119
- c = FullMath_1.FullMath.mulDivFloor(c, constants_1.TWO_POW_96, currentSqrtP);
120
- }
121
- deltaL = QuadMath_1.QuadMath.getSmallerRootOfQuadEqn(a, b, c);
122
- }
123
- return deltaL;
124
- }
125
- static calcIncrementalLiquidity(absDelta, liquidity, currentSqrtP, nextSqrtP, isExactInput, isToken0) {
126
- let deltaL = 0n;
127
- if (isToken0) {
128
- let tmp1 = FullMath_1.FullMath.mulDivFloor(liquidity, constants_1.TWO_POW_96, currentSqrtP);
129
- let tmp2 = isExactInput ? tmp1 + absDelta : tmp1 - absDelta;
130
- let tmp3 = FullMath_1.FullMath.mulDivFloor(nextSqrtP, tmp2, constants_1.TWO_POW_96);
131
- deltaL = tmp3 > liquidity ? tmp3 - liquidity : 0n;
132
- }
133
- else {
134
- let tmp1 = FullMath_1.FullMath.mulDivFloor(liquidity, currentSqrtP, constants_1.TWO_POW_96);
135
- let tmp2 = isExactInput ? tmp1 + absDelta : tmp1 - absDelta;
136
- let tmp3 = FullMath_1.FullMath.mulDivFloor(tmp2, constants_1.TWO_POW_96, nextSqrtP);
137
- deltaL = tmp3 > liquidity ? tmp3 - liquidity : 0n;
138
- }
139
- return deltaL;
140
- }
141
- static calcFinalPrice(absDelta, liquidity, deltaL, currentSqrtP, isExactInput, isToken0) {
142
- if (isToken0) {
143
- let tmp = FullMath_1.FullMath.mulDivFloor(absDelta, currentSqrtP, constants_1.TWO_POW_96);
144
- if (isExactInput) {
145
- return FullMath_1.FullMath.mulDivCeil(liquidity + deltaL, currentSqrtP, liquidity + tmp);
146
- }
147
- else {
148
- return FullMath_1.FullMath.mulDivFloor(liquidity + deltaL, currentSqrtP, liquidity - tmp);
149
- }
150
- }
151
- else {
152
- let tmp = FullMath_1.FullMath.mulDivFloor(absDelta, constants_1.TWO_POW_96, currentSqrtP);
153
- if (isExactInput) {
154
- return FullMath_1.FullMath.mulDivFloor(liquidity + tmp, currentSqrtP, liquidity + deltaL);
155
- }
156
- else {
157
- return FullMath_1.FullMath.mulDivCeil(liquidity - tmp, currentSqrtP, liquidity + deltaL);
158
- }
159
- }
160
- }
161
- static calcReturnedAmount(liquidity, currentSqrtP, nextSqrtP, deltaL, isExactInput, isToken0) {
162
- let returnedAmount = 0n;
163
- if (isToken0) {
164
- if (isExactInput) {
165
- returnedAmount =
166
- SafeCast_1.SafeCast.toInt256(FullMath_1.FullMath.mulDivCeil(deltaL, nextSqrtP, constants_1.TWO_POW_96)) +
167
- SafeCast_1.SafeCast.revToInt256(FullMath_1.FullMath.mulDivFloor(liquidity, currentSqrtP - nextSqrtP, constants_1.TWO_POW_96));
168
- }
169
- else {
170
- returnedAmount =
171
- SafeCast_1.SafeCast.toInt256(FullMath_1.FullMath.mulDivCeil(deltaL, nextSqrtP, constants_1.TWO_POW_96)) +
172
- SafeCast_1.SafeCast.toInt256(FullMath_1.FullMath.mulDivCeil(liquidity, nextSqrtP - currentSqrtP, constants_1.TWO_POW_96));
173
- }
174
- }
175
- else {
176
- returnedAmount =
177
- SafeCast_1.SafeCast.toInt256(FullMath_1.FullMath.mulDivCeil(liquidity + deltaL, constants_1.TWO_POW_96, nextSqrtP)) +
178
- SafeCast_1.SafeCast.revToInt256(FullMath_1.FullMath.mulDivFloor(liquidity, constants_1.TWO_POW_96, currentSqrtP));
179
- }
180
- if (isExactInput && returnedAmount == 1n) {
181
- // rounding make returnedAmount == 1
182
- returnedAmount = 0n;
183
- }
184
- return returnedAmount;
185
- }
186
- }
187
- exports.SwapMath = SwapMath;
188
- //# sourceMappingURL=SwapMath.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SwapMath.js","sourceRoot":"","sources":["../../../../src/dex/kyberswap-elastic/contract-math/SwapMath.ts"],"names":[],"mappings":";;;AAAA,4CAAoE;AACpE,yCAAsC;AACtC,yCAAsC;AACtC,yCAAsC;AAEtC,MAAa,QAAQ;IACnB,MAAM,CAAC,eAAe,CACpB,SAAiB,EACjB,YAAoB,EACpB,WAAmB,EACnB,aAAqB,EACrB,eAAuB,EACvB,Y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EAAE,YAAY,CAAC,CAC1D,CAAC;SACL;QAED,IAAI,YAAY,IAAI,cAAc,IAAI,EAAE,EAAE;YACxC,oCAAoC;YACpC,cAAc,GAAG,EAAE,CAAC;SACrB;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF;AA1VD,4BA0VC"}
@@ -1,6 +0,0 @@
1
- import { NumberAsString } from '@paraswap/core';
2
- import { LinkedlistData } from '../types';
3
- export declare class LinkedList {
4
- static remove(data: Record<NumberAsString, LinkedlistData>, removedValue: bigint): bigint;
5
- static insert(data: Record<NumberAsString, LinkedlistData>, newValue: bigint, lowerValue: bigint, nextValue: bigint): void;
6
- }
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LinkedList = void 0;
4
- const utils_1 = require("../../../utils");
5
- class LinkedList {
6
- static remove(data, removedValue) {
7
- (0, utils_1._require)(Number(removedValue) in data, 'non exist value');
8
- let node = data[Number(removedValue)];
9
- if (node.previous == removedValue)
10
- return removedValue;
11
- let ret = node.previous;
12
- if (node.next == removedValue)
13
- return ret;
14
- data[Number(node.previous)].next = node.next;
15
- data[Number(node.next)].previous = node.previous;
16
- delete data[Number(removedValue)];
17
- return ret;
18
- }
19
- static insert(data, newValue, lowerValue, nextValue) {
20
- data[Number(newValue)] = {
21
- previous: lowerValue,
22
- next: nextValue,
23
- };
24
- if (!data[Number(nextValue)]) {
25
- data[Number(nextValue)] = {
26
- next: 0n,
27
- previous: 0n,
28
- };
29
- }
30
- if (!data[Number(lowerValue)]) {
31
- data[Number(lowerValue)] = {
32
- next: 0n,
33
- previous: 0n,
34
- };
35
- }
36
- data[Number(nextValue)].previous = newValue;
37
- data[Number(lowerValue)].next = newValue;
38
- }
39
- }
40
- exports.LinkedList = LinkedList;
41
- //# sourceMappingURL=TickLinkedList.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TickLinkedList.js","sourceRoot":"","sources":["../../../../src/dex/kyberswap-elastic/contract-math/TickLink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,CAAC,UAAU,CAAC,CAAC,GAAG;gBACzB,IAAI,EAAE,EAAE;gBACR,QAAQ,EAAE,EAAE;aACb,CAAC;SACH;QAED,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAC5C,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,GAAG,QAAQ,CAAC;IAC3C,CAAC;CACF;AA7CD,gCA6CC"}
@@ -1,9 +0,0 @@
1
- export declare class TickMath {
2
- static readonly MIN_TICK = -887272n;
3
- static readonly MAX_TICK: bigint;
4
- static readonly MIN_SQRT_RATIO = 4295128739n;
5
- static readonly MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342n;
6
- static getSqrtRatioAtTick(tick: bigint): bigint;
7
- static getTickAtSqrtRatio(sqrtPriceX96: bigint): bigint;
8
- static getMaxNumberTicks(_tickDistance: bigint): bigint;
9
- }