@kittycorn-labs/v4-sdk 1.1.30 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/README.md +9 -0
  2. package/dist/{PositionManager.d.ts → cjs/src/PositionManager.d.ts} +169 -169
  3. package/dist/cjs/src/PositionManager.js +242 -0
  4. package/dist/cjs/src/PositionManager.js.map +1 -0
  5. package/dist/cjs/src/abis/IMulticall.json +23 -0
  6. package/dist/{actionConstants.d.ts → cjs/src/actionConstants.d.ts} +1 -1
  7. package/dist/cjs/src/actionConstants.js +6 -0
  8. package/dist/cjs/src/actionConstants.js.map +1 -0
  9. package/dist/{entities → cjs/src/entities}/index.d.ts +4 -4
  10. package/dist/cjs/src/entities/index.js +8 -0
  11. package/dist/cjs/src/entities/index.js.map +1 -0
  12. package/dist/{entities → cjs/src/entities}/pool.d.ts +103 -103
  13. package/dist/cjs/src/entities/pool.js +196 -0
  14. package/dist/cjs/src/entities/pool.js.map +1 -0
  15. package/dist/{entities → cjs/src/entities}/position.d.ts +144 -144
  16. package/dist/cjs/src/entities/position.js +273 -0
  17. package/dist/cjs/src/entities/position.js.map +1 -0
  18. package/dist/{entities → cjs/src/entities}/route.d.ts +28 -28
  19. package/dist/cjs/src/entities/route.js +89 -0
  20. package/dist/cjs/src/entities/route.js.map +1 -0
  21. package/dist/{entities → cjs/src/entities}/trade.d.ts +220 -220
  22. package/dist/cjs/src/entities/trade.js +441 -0
  23. package/dist/cjs/src/entities/trade.js.map +1 -0
  24. package/dist/{index.d.ts → cjs/src/index.d.ts} +4 -4
  25. package/dist/cjs/src/index.js +8 -0
  26. package/dist/cjs/src/index.js.map +1 -0
  27. package/dist/{internalConstants.d.ts → cjs/src/internalConstants.d.ts} +46 -46
  28. package/dist/cjs/src/internalConstants.js +69 -0
  29. package/dist/cjs/src/internalConstants.js.map +1 -0
  30. package/dist/{multicall.d.ts → cjs/src/multicall.d.ts} +10 -10
  31. package/dist/cjs/src/multicall.js +26 -0
  32. package/dist/cjs/src/multicall.js.map +1 -0
  33. package/dist/cjs/src/tokenize.d.ts +17 -0
  34. package/dist/cjs/src/tokenize.js +42 -0
  35. package/dist/cjs/src/tokenize.js.map +1 -0
  36. package/dist/{utils → cjs/src/utils}/calldata.d.ts +20 -20
  37. package/dist/cjs/src/utils/calldata.js +20 -0
  38. package/dist/cjs/src/utils/calldata.js.map +1 -0
  39. package/dist/{utils → cjs/src/utils}/currencyMap.d.ts +2 -2
  40. package/dist/cjs/src/utils/currencyMap.js +15 -0
  41. package/dist/cjs/src/utils/currencyMap.js.map +1 -0
  42. package/dist/{utils → cjs/src/utils}/encodeRouteToPath.d.ts +10 -10
  43. package/dist/cjs/src/utils/encodeRouteToPath.js +26 -0
  44. package/dist/cjs/src/utils/encodeRouteToPath.js.map +1 -0
  45. package/dist/{utils → cjs/src/utils}/hook.d.ts +45 -45
  46. package/dist/cjs/src/utils/hook.js +97 -0
  47. package/dist/cjs/src/utils/hook.js.map +1 -0
  48. package/dist/{utils → cjs/src/utils}/index.d.ts +11 -11
  49. package/dist/cjs/src/utils/index.js +15 -0
  50. package/dist/cjs/src/utils/index.js.map +1 -0
  51. package/dist/{utils → cjs/src/utils}/pathCurrency.d.ts +4 -4
  52. package/dist/cjs/src/utils/pathCurrency.js +27 -0
  53. package/dist/cjs/src/utils/pathCurrency.js.map +1 -0
  54. package/dist/{utils → cjs/src/utils}/positionManagerAbi.d.ts +102 -102
  55. package/dist/cjs/src/utils/positionManagerAbi.js +1318 -0
  56. package/dist/cjs/src/utils/positionManagerAbi.js.map +1 -0
  57. package/dist/{utils → cjs/src/utils}/priceTickConversions.d.ts +20 -20
  58. package/dist/cjs/src/utils/priceTickConversions.js +55 -0
  59. package/dist/cjs/src/utils/priceTickConversions.js.map +1 -0
  60. package/dist/{utils → cjs/src/utils}/sortsBefore.d.ts +2 -2
  61. package/dist/cjs/src/utils/sortsBefore.js +12 -0
  62. package/dist/cjs/src/utils/sortsBefore.js.map +1 -0
  63. package/dist/{utils → cjs/src/utils}/v4BaseActionsParser.d.ts +49 -45
  64. package/dist/cjs/src/utils/v4BaseActionsParser.js +193 -0
  65. package/dist/cjs/src/utils/v4BaseActionsParser.js.map +1 -0
  66. package/dist/{utils → cjs/src/utils}/v4Planner.d.ts +71 -55
  67. package/dist/cjs/src/utils/v4Planner.js +267 -0
  68. package/dist/cjs/src/utils/v4Planner.js.map +1 -0
  69. package/dist/{utils → cjs/src/utils}/v4PositionPlanner.d.ts +13 -12
  70. package/dist/cjs/src/utils/v4PositionPlanner.js +61 -0
  71. package/dist/cjs/src/utils/v4PositionPlanner.js.map +1 -0
  72. package/dist/esm/package.json +1 -0
  73. package/dist/esm/src/PositionManager.d.ts +169 -0
  74. package/dist/esm/src/PositionManager.js +237 -0
  75. package/dist/esm/src/PositionManager.js.map +1 -0
  76. package/dist/esm/src/abis/IMulticall.json +23 -0
  77. package/dist/esm/src/actionConstants.d.ts +1 -0
  78. package/dist/esm/src/actionConstants.js +3 -0
  79. package/dist/esm/src/actionConstants.js.map +1 -0
  80. package/dist/esm/src/entities/index.d.ts +4 -0
  81. package/dist/esm/src/entities/index.js +5 -0
  82. package/dist/esm/src/entities/index.js.map +1 -0
  83. package/dist/esm/src/entities/pool.d.ts +103 -0
  84. package/dist/esm/src/entities/pool.js +191 -0
  85. package/dist/esm/src/entities/pool.js.map +1 -0
  86. package/dist/esm/src/entities/position.d.ts +144 -0
  87. package/dist/esm/src/entities/position.js +268 -0
  88. package/dist/esm/src/entities/position.js.map +1 -0
  89. package/dist/esm/src/entities/route.d.ts +28 -0
  90. package/dist/esm/src/entities/route.js +84 -0
  91. package/dist/esm/src/entities/route.js.map +1 -0
  92. package/dist/esm/src/entities/trade.d.ts +220 -0
  93. package/dist/esm/src/entities/trade.js +435 -0
  94. package/dist/esm/src/entities/trade.js.map +1 -0
  95. package/dist/esm/src/index.d.ts +4 -0
  96. package/dist/esm/src/index.js +5 -0
  97. package/dist/esm/src/index.js.map +1 -0
  98. package/dist/esm/src/internalConstants.d.ts +46 -0
  99. package/dist/esm/src/internalConstants.js +65 -0
  100. package/dist/esm/src/internalConstants.js.map +1 -0
  101. package/dist/esm/src/multicall.d.ts +10 -0
  102. package/dist/esm/src/multicall.js +21 -0
  103. package/dist/esm/src/multicall.js.map +1 -0
  104. package/dist/esm/src/tokenize.d.ts +17 -0
  105. package/dist/esm/src/tokenize.js +37 -0
  106. package/dist/esm/src/tokenize.js.map +1 -0
  107. package/dist/esm/src/utils/calldata.d.ts +20 -0
  108. package/dist/esm/src/utils/calldata.js +15 -0
  109. package/dist/esm/src/utils/calldata.js.map +1 -0
  110. package/dist/esm/src/utils/currencyMap.d.ts +2 -0
  111. package/dist/esm/src/utils/currencyMap.js +11 -0
  112. package/dist/esm/src/utils/currencyMap.js.map +1 -0
  113. package/dist/esm/src/utils/encodeRouteToPath.d.ts +10 -0
  114. package/dist/esm/src/utils/encodeRouteToPath.js +22 -0
  115. package/dist/esm/src/utils/encodeRouteToPath.js.map +1 -0
  116. package/dist/esm/src/utils/hook.d.ts +45 -0
  117. package/dist/esm/src/utils/hook.js +92 -0
  118. package/dist/esm/src/utils/hook.js.map +1 -0
  119. package/dist/esm/src/utils/index.d.ts +11 -0
  120. package/dist/esm/src/utils/index.js +12 -0
  121. package/dist/esm/src/utils/index.js.map +1 -0
  122. package/dist/esm/src/utils/pathCurrency.d.ts +4 -0
  123. package/dist/esm/src/utils/pathCurrency.js +22 -0
  124. package/dist/esm/src/utils/pathCurrency.js.map +1 -0
  125. package/dist/esm/src/utils/positionManagerAbi.d.ts +102 -0
  126. package/dist/esm/src/utils/positionManagerAbi.js +1315 -0
  127. package/dist/esm/src/utils/positionManagerAbi.js.map +1 -0
  128. package/dist/esm/src/utils/priceTickConversions.d.ts +20 -0
  129. package/dist/esm/src/utils/priceTickConversions.js +49 -0
  130. package/dist/esm/src/utils/priceTickConversions.js.map +1 -0
  131. package/dist/esm/src/utils/sortsBefore.d.ts +2 -0
  132. package/dist/esm/src/utils/sortsBefore.js +8 -0
  133. package/dist/esm/src/utils/sortsBefore.js.map +1 -0
  134. package/dist/esm/src/utils/v4BaseActionsParser.d.ts +49 -0
  135. package/dist/esm/src/utils/v4BaseActionsParser.js +189 -0
  136. package/dist/esm/src/utils/v4BaseActionsParser.js.map +1 -0
  137. package/dist/esm/src/utils/v4Planner.d.ts +71 -0
  138. package/dist/esm/src/utils/v4Planner.js +261 -0
  139. package/dist/esm/src/utils/v4Planner.js.map +1 -0
  140. package/dist/esm/src/utils/v4PositionPlanner.d.ts +13 -0
  141. package/dist/esm/src/utils/v4PositionPlanner.js +57 -0
  142. package/dist/esm/src/utils/v4PositionPlanner.js.map +1 -0
  143. package/dist/types/src/PositionManager.d.ts +170 -0
  144. package/dist/types/src/PositionManager.d.ts.map +1 -0
  145. package/dist/types/src/actionConstants.d.ts +2 -0
  146. package/dist/types/src/actionConstants.d.ts.map +1 -0
  147. package/dist/types/src/entities/index.d.ts +5 -0
  148. package/dist/types/src/entities/index.d.ts.map +1 -0
  149. package/dist/types/src/entities/pool.d.ts +104 -0
  150. package/dist/types/src/entities/pool.d.ts.map +1 -0
  151. package/dist/types/src/entities/position.d.ts +145 -0
  152. package/dist/types/src/entities/position.d.ts.map +1 -0
  153. package/dist/types/src/entities/route.d.ts +29 -0
  154. package/dist/types/src/entities/route.d.ts.map +1 -0
  155. package/dist/types/src/entities/trade.d.ts +221 -0
  156. package/dist/types/src/entities/trade.d.ts.map +1 -0
  157. package/dist/types/src/index.d.ts +5 -0
  158. package/dist/types/src/index.d.ts.map +1 -0
  159. package/dist/types/src/internalConstants.d.ts +47 -0
  160. package/dist/types/src/internalConstants.d.ts.map +1 -0
  161. package/dist/types/src/multicall.d.ts +11 -0
  162. package/dist/types/src/multicall.d.ts.map +1 -0
  163. package/dist/types/src/tokenize.d.ts +18 -0
  164. package/dist/types/src/tokenize.d.ts.map +1 -0
  165. package/dist/types/src/utils/calldata.d.ts +21 -0
  166. package/dist/types/src/utils/calldata.d.ts.map +1 -0
  167. package/dist/types/src/utils/currencyMap.d.ts +3 -0
  168. package/dist/types/src/utils/currencyMap.d.ts.map +1 -0
  169. package/dist/types/src/utils/encodeRouteToPath.d.ts +11 -0
  170. package/dist/types/src/utils/encodeRouteToPath.d.ts.map +1 -0
  171. package/dist/types/src/utils/hook.d.ts +46 -0
  172. package/dist/types/src/utils/hook.d.ts.map +1 -0
  173. package/dist/types/src/utils/index.d.ts +12 -0
  174. package/dist/types/src/utils/index.d.ts.map +1 -0
  175. package/dist/types/src/utils/pathCurrency.d.ts +5 -0
  176. package/dist/types/src/utils/pathCurrency.d.ts.map +1 -0
  177. package/dist/types/src/utils/positionManagerAbi.d.ts +103 -0
  178. package/dist/types/src/utils/positionManagerAbi.d.ts.map +1 -0
  179. package/dist/types/src/utils/priceTickConversions.d.ts +21 -0
  180. package/dist/types/src/utils/priceTickConversions.d.ts.map +1 -0
  181. package/dist/types/src/utils/sortsBefore.d.ts +3 -0
  182. package/dist/types/src/utils/sortsBefore.d.ts.map +1 -0
  183. package/dist/types/src/utils/v4BaseActionsParser.d.ts +50 -0
  184. package/dist/types/src/utils/v4BaseActionsParser.d.ts.map +1 -0
  185. package/dist/types/src/utils/v4Planner.d.ts +72 -0
  186. package/dist/types/src/utils/v4Planner.d.ts.map +1 -0
  187. package/dist/types/src/utils/v4PositionPlanner.d.ts +14 -0
  188. package/dist/types/src/utils/v4PositionPlanner.d.ts.map +1 -0
  189. package/package.json +28 -46
  190. package/dist/index.js +0 -8
  191. package/dist/tokenizeAddresses.d.ts +0 -25
  192. package/dist/v4-sdk.cjs.development.js +0 -3633
  193. package/dist/v4-sdk.cjs.development.js.map +0 -1
  194. package/dist/v4-sdk.cjs.production.min.js +0 -2
  195. package/dist/v4-sdk.cjs.production.min.js.map +0 -1
  196. package/dist/v4-sdk.esm.js +0 -3597
  197. package/dist/v4-sdk.esm.js.map +0 -1
@@ -1,3597 +0,0 @@
1
- import invariant from 'tiny-invariant';
2
- import { keccak256 } from '@ethersproject/solidity';
3
- import { Price, CurrencyAmount, Token, ChainId, TradeType, Fraction, Percent, sortedInsert, MaxUint256, validateAndParseAddress } from '@kittycorn-labs/sdk-core';
4
- import { TickMath, TickListDataProvider, v3Swap, NoTickDataProvider, encodeSqrtRatioX96, maxLiquidityForAmounts, SqrtPriceMath } from '@kittycorn-labs/v3-sdk';
5
- import { isAddress, defaultAbiCoder } from 'ethers/lib/utils';
6
- import JSBI from 'jsbi';
7
- import { constants, ethers } from 'ethers';
8
- import { Interface } from '@ethersproject/abi';
9
- import IMulticall from '@uniswap/v3-periphery/artifacts/contracts/interfaces/IMulticall.sol/IMulticall.json';
10
-
11
- function _arrayLikeToArray(r, a) {
12
- (null == a || a > r.length) && (a = r.length);
13
- for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
14
- return n;
15
- }
16
- function asyncGeneratorStep(n, t, e, r, o, a, c) {
17
- try {
18
- var i = n[a](c),
19
- u = i.value;
20
- } catch (n) {
21
- return void e(n);
22
- }
23
- i.done ? t(u) : Promise.resolve(u).then(r, o);
24
- }
25
- function _asyncToGenerator(n) {
26
- return function () {
27
- var t = this,
28
- e = arguments;
29
- return new Promise(function (r, o) {
30
- var a = n.apply(t, e);
31
- function _next(n) {
32
- asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
33
- }
34
- function _throw(n) {
35
- asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
36
- }
37
- _next(void 0);
38
- });
39
- };
40
- }
41
- function _defineProperties(e, r) {
42
- for (var t = 0; t < r.length; t++) {
43
- var o = r[t];
44
- o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
45
- }
46
- }
47
- function _createClass(e, r, t) {
48
- return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
49
- writable: !1
50
- }), e;
51
- }
52
- function _createForOfIteratorHelperLoose(r, e) {
53
- var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
54
- if (t) return (t = t.call(r)).next.bind(t);
55
- if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
56
- t && (r = t);
57
- var o = 0;
58
- return function () {
59
- return o >= r.length ? {
60
- done: !0
61
- } : {
62
- done: !1,
63
- value: r[o++]
64
- };
65
- };
66
- }
67
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
68
- }
69
- function _extends() {
70
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
71
- for (var e = 1; e < arguments.length; e++) {
72
- var t = arguments[e];
73
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
74
- }
75
- return n;
76
- }, _extends.apply(null, arguments);
77
- }
78
- function _inheritsLoose(t, o) {
79
- t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
80
- }
81
- function _regenerator() {
82
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
83
- var e,
84
- t,
85
- r = "function" == typeof Symbol ? Symbol : {},
86
- n = r.iterator || "@@iterator",
87
- o = r.toStringTag || "@@toStringTag";
88
- function i(r, n, o, i) {
89
- var c = n && n.prototype instanceof Generator ? n : Generator,
90
- u = Object.create(c.prototype);
91
- return _regeneratorDefine(u, "_invoke", function (r, n, o) {
92
- var i,
93
- c,
94
- u,
95
- f = 0,
96
- p = o || [],
97
- y = !1,
98
- G = {
99
- p: 0,
100
- n: 0,
101
- v: e,
102
- a: d,
103
- f: d.bind(e, 4),
104
- d: function (t, r) {
105
- return i = t, c = 0, u = e, G.n = r, a;
106
- }
107
- };
108
- function d(r, n) {
109
- for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
110
- var o,
111
- i = p[t],
112
- d = G.p,
113
- l = i[2];
114
- r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
115
- }
116
- if (o || r > 1) return a;
117
- throw y = !0, n;
118
- }
119
- return function (o, p, l) {
120
- if (f > 1) throw TypeError("Generator is already running");
121
- for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
122
- i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
123
- try {
124
- if (f = 2, i) {
125
- if (c || (o = "next"), t = i[o]) {
126
- if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
127
- if (!t.done) return t;
128
- u = t.value, c < 2 && (c = 0);
129
- } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
130
- i = e;
131
- } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
132
- } catch (t) {
133
- i = e, c = 1, u = t;
134
- } finally {
135
- f = 1;
136
- }
137
- }
138
- return {
139
- value: t,
140
- done: y
141
- };
142
- };
143
- }(r, o, i), !0), u;
144
- }
145
- var a = {};
146
- function Generator() {}
147
- function GeneratorFunction() {}
148
- function GeneratorFunctionPrototype() {}
149
- t = Object.getPrototypeOf;
150
- var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
151
- return this;
152
- }), t),
153
- u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
154
- function f(e) {
155
- return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
156
- }
157
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
158
- return this;
159
- }), _regeneratorDefine(u, "toString", function () {
160
- return "[object Generator]";
161
- }), (_regenerator = function () {
162
- return {
163
- w: i,
164
- m: f
165
- };
166
- })();
167
- }
168
- function _regeneratorDefine(e, r, n, t) {
169
- var i = Object.defineProperty;
170
- try {
171
- i({}, "", {});
172
- } catch (e) {
173
- i = 0;
174
- }
175
- _regeneratorDefine = function (e, r, n, t) {
176
- if (r) i ? i(e, r, {
177
- value: n,
178
- enumerable: !t,
179
- configurable: !t,
180
- writable: !t
181
- }) : e[r] = n;else {
182
- function o(r, n) {
183
- _regeneratorDefine(e, r, function (e) {
184
- return this._invoke(r, n, e);
185
- });
186
- }
187
- o("next", 0), o("throw", 1), o("return", 2);
188
- }
189
- }, _regeneratorDefine(e, r, n, t);
190
- }
191
- function _setPrototypeOf(t, e) {
192
- return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
193
- return t.__proto__ = e, t;
194
- }, _setPrototypeOf(t, e);
195
- }
196
- function _toPrimitive(t, r) {
197
- if ("object" != typeof t || !t) return t;
198
- var e = t[Symbol.toPrimitive];
199
- if (void 0 !== e) {
200
- var i = e.call(t, r || "default");
201
- if ("object" != typeof i) return i;
202
- throw new TypeError("@@toPrimitive must return a primitive value.");
203
- }
204
- return ("string" === r ? String : Number)(t);
205
- }
206
- function _toPropertyKey(t) {
207
- var i = _toPrimitive(t, "string");
208
- return "symbol" == typeof i ? i : i + "";
209
- }
210
- function _unsupportedIterableToArray(r, a) {
211
- if (r) {
212
- if ("string" == typeof r) return _arrayLikeToArray(r, a);
213
- var t = {}.toString.call(r).slice(8, -1);
214
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
215
- }
216
- }
217
-
218
- function sortsBefore(currencyA, currencyB) {
219
- if (currencyA.isNative) return true;
220
- if (currencyB.isNative) return false;
221
- return currencyA.wrapped.sortsBefore(currencyB.wrapped);
222
- }
223
-
224
- var _hookFlagIndex;
225
- var HookOptions;
226
- (function (HookOptions) {
227
- HookOptions["AfterRemoveLiquidityReturnsDelta"] = "afterRemoveLiquidityReturnsDelta";
228
- HookOptions["AfterAddLiquidityReturnsDelta"] = "afterAddLiquidityReturnsDelta";
229
- HookOptions["AfterSwapReturnsDelta"] = "afterSwapReturnsDelta";
230
- HookOptions["BeforeSwapReturnsDelta"] = "beforeSwapReturnsDelta";
231
- HookOptions["AfterDonate"] = "afterDonate";
232
- HookOptions["BeforeDonate"] = "beforeDonate";
233
- HookOptions["AfterSwap"] = "afterSwap";
234
- HookOptions["BeforeSwap"] = "beforeSwap";
235
- HookOptions["AfterRemoveLiquidity"] = "afterRemoveLiquidity";
236
- HookOptions["BeforeRemoveLiquidity"] = "beforeRemoveLiquidity";
237
- HookOptions["AfterAddLiquidity"] = "afterAddLiquidity";
238
- HookOptions["BeforeAddLiquidity"] = "beforeAddLiquidity";
239
- HookOptions["AfterInitialize"] = "afterInitialize";
240
- HookOptions["BeforeInitialize"] = "beforeInitialize";
241
- })(HookOptions || (HookOptions = {}));
242
- var hookFlagIndex = (_hookFlagIndex = {}, _hookFlagIndex[HookOptions.AfterRemoveLiquidityReturnsDelta] = 0, _hookFlagIndex[HookOptions.AfterAddLiquidityReturnsDelta] = 1, _hookFlagIndex[HookOptions.AfterSwapReturnsDelta] = 2, _hookFlagIndex[HookOptions.BeforeSwapReturnsDelta] = 3, _hookFlagIndex[HookOptions.AfterDonate] = 4, _hookFlagIndex[HookOptions.BeforeDonate] = 5, _hookFlagIndex[HookOptions.AfterSwap] = 6, _hookFlagIndex[HookOptions.BeforeSwap] = 7, _hookFlagIndex[HookOptions.AfterRemoveLiquidity] = 8, _hookFlagIndex[HookOptions.BeforeRemoveLiquidity] = 9, _hookFlagIndex[HookOptions.AfterAddLiquidity] = 10, _hookFlagIndex[HookOptions.BeforeAddLiquidity] = 11, _hookFlagIndex[HookOptions.AfterInitialize] = 12, _hookFlagIndex[HookOptions.BeforeInitialize] = 13, _hookFlagIndex);
243
- var Hook = /*#__PURE__*/function () {
244
- function Hook() {}
245
- Hook.permissions = function permissions(address) {
246
- this._checkAddress(address);
247
- return {
248
- beforeInitialize: this._hasPermission(address, HookOptions.BeforeInitialize),
249
- afterInitialize: this._hasPermission(address, HookOptions.AfterInitialize),
250
- beforeAddLiquidity: this._hasPermission(address, HookOptions.BeforeAddLiquidity),
251
- afterAddLiquidity: this._hasPermission(address, HookOptions.AfterAddLiquidity),
252
- beforeRemoveLiquidity: this._hasPermission(address, HookOptions.BeforeRemoveLiquidity),
253
- afterRemoveLiquidity: this._hasPermission(address, HookOptions.AfterRemoveLiquidity),
254
- beforeSwap: this._hasPermission(address, HookOptions.BeforeSwap),
255
- afterSwap: this._hasPermission(address, HookOptions.AfterSwap),
256
- beforeDonate: this._hasPermission(address, HookOptions.BeforeDonate),
257
- afterDonate: this._hasPermission(address, HookOptions.AfterDonate),
258
- beforeSwapReturnsDelta: this._hasPermission(address, HookOptions.BeforeSwapReturnsDelta),
259
- afterSwapReturnsDelta: this._hasPermission(address, HookOptions.AfterSwapReturnsDelta),
260
- afterAddLiquidityReturnsDelta: this._hasPermission(address, HookOptions.AfterAddLiquidityReturnsDelta),
261
- afterRemoveLiquidityReturnsDelta: this._hasPermission(address, HookOptions.AfterRemoveLiquidityReturnsDelta)
262
- };
263
- };
264
- Hook.hasPermission = function hasPermission(address, hookOption) {
265
- this._checkAddress(address);
266
- return this._hasPermission(address, hookOption);
267
- };
268
- Hook.hasInitializePermissions = function hasInitializePermissions(address) {
269
- this._checkAddress(address);
270
- return this._hasPermission(address, HookOptions.BeforeInitialize) || Hook._hasPermission(address, HookOptions.AfterInitialize);
271
- };
272
- Hook.hasLiquidityPermissions = function hasLiquidityPermissions(address) {
273
- this._checkAddress(address);
274
- // this implicitly encapsulates liquidity delta permissions
275
- return this._hasPermission(address, HookOptions.BeforeAddLiquidity) || Hook._hasPermission(address, HookOptions.AfterAddLiquidity) || Hook._hasPermission(address, HookOptions.BeforeRemoveLiquidity) || Hook._hasPermission(address, HookOptions.AfterRemoveLiquidity);
276
- };
277
- Hook.hasSwapPermissions = function hasSwapPermissions(address) {
278
- this._checkAddress(address);
279
- // this implicitly encapsulates swap delta permissions
280
- return this._hasPermission(address, HookOptions.BeforeSwap) || Hook._hasPermission(address, HookOptions.AfterSwap);
281
- };
282
- Hook.hasDonatePermissions = function hasDonatePermissions(address) {
283
- this._checkAddress(address);
284
- return this._hasPermission(address, HookOptions.BeforeDonate) || Hook._hasPermission(address, HookOptions.AfterDonate);
285
- };
286
- Hook._hasPermission = function _hasPermission(address, hookOption) {
287
- return !!(parseInt(address, 16) & 1 << hookFlagIndex[hookOption]);
288
- };
289
- Hook._checkAddress = function _checkAddress(address) {
290
- !isAddress(address) ? process.env.NODE_ENV !== "production" ? invariant(false, 'invalid address') : invariant(false) : void 0;
291
- };
292
- return Hook;
293
- }();
294
-
295
- var _TICK_SPACINGS;
296
- // constants used internally but not expected to be used externally
297
- var ADDRESS_ZERO = constants.AddressZero;
298
- var NEGATIVE_ONE = /*#__PURE__*/JSBI.BigInt(-1);
299
- var ZERO = /*#__PURE__*/JSBI.BigInt(0);
300
- var ONE = /*#__PURE__*/JSBI.BigInt(1);
301
- var EMPTY_BYTES = '0x';
302
- // used in liquidity amount math
303
- var Q96 = /*#__PURE__*/JSBI.exponentiate(/*#__PURE__*/JSBI.BigInt(2), /*#__PURE__*/JSBI.BigInt(96));
304
- var Q192 = /*#__PURE__*/JSBI.exponentiate(Q96, /*#__PURE__*/JSBI.BigInt(2));
305
- // used when unwrapping weth in positon manager
306
- var OPEN_DELTA = constants.Zero;
307
- // error constants
308
- var NATIVE_NOT_SET = 'NATIVE_NOT_SET';
309
- var ZERO_LIQUIDITY = 'ZERO_LIQUIDITY';
310
- var NO_SQRT_PRICE = 'NO_SQRT_PRICE';
311
- var CANNOT_BURN = 'CANNOT_BURN';
312
- /**
313
- * Function fragments that exist on the PositionManager contract.
314
- */
315
- var PositionFunctions;
316
- (function (PositionFunctions) {
317
- PositionFunctions["INITIALIZE_POOL"] = "initializePool";
318
- PositionFunctions["MODIFY_LIQUIDITIES"] = "modifyLiquidities";
319
- // Inherited from PermitForwarder
320
- PositionFunctions["PERMIT_BATCH"] = "0x002a3e3a";
321
- // Inherited from ERC721Permit
322
- PositionFunctions["ERC721PERMIT_PERMIT"] = "0x0f5730f1";
323
- })(PositionFunctions || (PositionFunctions = {}));
324
- /**
325
- * The default factory enabled fee amounts, denominated in hundredths of bips.
326
- */
327
- var FeeAmount;
328
- (function (FeeAmount) {
329
- FeeAmount[FeeAmount["LOWEST"] = 100] = "LOWEST";
330
- FeeAmount[FeeAmount["LOW"] = 500] = "LOW";
331
- FeeAmount[FeeAmount["MEDIUM"] = 3000] = "MEDIUM";
332
- FeeAmount[FeeAmount["HIGH"] = 10000] = "HIGH";
333
- })(FeeAmount || (FeeAmount = {}));
334
- /**
335
- * The default factory tick spacings by fee amount.
336
- */
337
- var TICK_SPACINGS = (_TICK_SPACINGS = {}, _TICK_SPACINGS[FeeAmount.LOWEST] = 1, _TICK_SPACINGS[FeeAmount.LOW] = 10, _TICK_SPACINGS[FeeAmount.MEDIUM] = 60, _TICK_SPACINGS[FeeAmount.HIGH] = 200, _TICK_SPACINGS);
338
-
339
- var DYNAMIC_FEE_FLAG = 0x800000;
340
- var NO_TICK_DATA_PROVIDER_DEFAULT = /*#__PURE__*/new NoTickDataProvider();
341
- /**
342
- * Represents a V4 pool
343
- */
344
- var Pool = /*#__PURE__*/function () {
345
- /**
346
- * Construct a pool
347
- * @param currencyA One of the currencys in the pool
348
- * @param currencyB The other currency in the pool
349
- * @param fee The fee in hundredths of a bips of the input amount of every swap that is collected by the pool
350
- * @param tickSpacing The tickSpacing of the pool
351
- * @param hooks The address of the hook contract
352
- * @param sqrtRatioX96 The sqrt of the current ratio of amounts of currency1 to currency0
353
- * @param liquidity The current value of in range liquidity
354
- * @param tickCurrent The current tick of the pool
355
- */
356
- function Pool(currencyA, currencyB, fee, tickSpacing, hooks, sqrtRatioX96, liquidity, tickCurrent, ticks) {
357
- if (ticks === void 0) {
358
- ticks = NO_TICK_DATA_PROVIDER_DEFAULT;
359
- }
360
- !isAddress(hooks) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Invalid hook address') : invariant(false) : void 0;
361
- !(Number.isInteger(fee) && (fee === DYNAMIC_FEE_FLAG || fee < 1000000)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'FEE') : invariant(false) : void 0;
362
- if (fee === DYNAMIC_FEE_FLAG) {
363
- !(Number(hooks) > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Dynamic fee pool requires a hook') : invariant(false) : void 0;
364
- }
365
- var tickCurrentSqrtRatioX96 = TickMath.getSqrtRatioAtTick(tickCurrent);
366
- var nextTickSqrtRatioX96 = TickMath.getSqrtRatioAtTick(tickCurrent + 1);
367
- !(JSBI.greaterThanOrEqual(JSBI.BigInt(sqrtRatioX96), tickCurrentSqrtRatioX96) && JSBI.lessThanOrEqual(JSBI.BigInt(sqrtRatioX96), nextTickSqrtRatioX96)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'PRICE_BOUNDS') : invariant(false) : void 0;
368
- var _ref = sortsBefore(currencyA, currencyB) ? [currencyA, currencyB] : [currencyB, currencyA];
369
- this.currency0 = _ref[0];
370
- this.currency1 = _ref[1];
371
- this.fee = fee;
372
- this.sqrtRatioX96 = JSBI.BigInt(sqrtRatioX96);
373
- this.tickSpacing = tickSpacing;
374
- this.hooks = hooks;
375
- this.liquidity = JSBI.BigInt(liquidity);
376
- this.tickCurrent = tickCurrent;
377
- this.tickDataProvider = Array.isArray(ticks) ? new TickListDataProvider(ticks, tickSpacing) : ticks;
378
- this.poolKey = Pool.getPoolKey(this.currency0, this.currency1, this.fee, this.tickSpacing, this.hooks);
379
- this.poolId = Pool.getPoolId(this.currency0, this.currency1, this.fee, this.tickSpacing, this.hooks);
380
- }
381
- Pool.getPoolKey = function getPoolKey(currencyA, currencyB, fee, tickSpacing, hooks) {
382
- !isAddress(hooks) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Invalid hook address') : invariant(false) : void 0;
383
- var _ref2 = sortsBefore(currencyA, currencyB) ? [currencyA, currencyB] : [currencyB, currencyA],
384
- currency0 = _ref2[0],
385
- currency1 = _ref2[1];
386
- var currency0Addr = currency0.isNative ? ADDRESS_ZERO : currency0.wrapped.address;
387
- var currency1Addr = currency1.isNative ? ADDRESS_ZERO : currency1.wrapped.address;
388
- return {
389
- currency0: currency0Addr,
390
- currency1: currency1Addr,
391
- fee: fee,
392
- tickSpacing: tickSpacing,
393
- hooks: hooks
394
- };
395
- };
396
- Pool.getPoolId = function getPoolId(currencyA, currencyB, fee, tickSpacing, hooks) {
397
- var _ref3 = sortsBefore(currencyA, currencyB) ? [currencyA, currencyB] : [currencyB, currencyA],
398
- currency0 = _ref3[0],
399
- currency1 = _ref3[1];
400
- var currency0Addr = currency0.isNative ? ADDRESS_ZERO : currency0.wrapped.address;
401
- var currency1Addr = currency1.isNative ? ADDRESS_ZERO : currency1.wrapped.address;
402
- return keccak256(['bytes'], [defaultAbiCoder.encode(['address', 'address', 'uint24', 'int24', 'address'], [currency0Addr, currency1Addr, fee, tickSpacing, hooks])]);
403
- }
404
- /** backwards compatibility with v2/3 sdks */;
405
- var _proto = Pool.prototype;
406
- /**
407
- * Returns true if the currency is either currency0 or currency1
408
- * @param currency The currency to check
409
- * @returns True if currency is either currency0 or currency1
410
- */
411
- _proto.involvesCurrency = function involvesCurrency(currency) {
412
- return currency.equals(this.currency0) || currency.equals(this.currency1);
413
- }
414
- /** backwards compatibility with v2/3 sdks */;
415
- _proto.involvesToken = function involvesToken(currency) {
416
- return this.involvesCurrency(currency);
417
- }
418
- /**
419
- * v4-only involvesToken convenience method, used for mixed route ETH <-> WETH connection only
420
- * @param currency
421
- */;
422
- _proto.v4InvolvesToken = function v4InvolvesToken(currency) {
423
- return this.involvesCurrency(currency) || currency.wrapped.equals(this.currency0) || currency.wrapped.equals(this.currency1) || currency.wrapped.equals(this.currency0.wrapped) || currency.wrapped.equals(this.currency1.wrapped);
424
- }
425
- /**
426
- * Returns the current mid price of the pool in terms of currency0, i.e. the ratio of currency1 over currency0
427
- */;
428
- /**
429
- * Return the price of the given currency in terms of the other currency in the pool.
430
- * @param currency The currency to return price of
431
- * @returns The price of the given currency, in terms of the other.
432
- */
433
- _proto.priceOf = function priceOf(currency) {
434
- !this.involvesCurrency(currency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'CURRENCY') : invariant(false) : void 0;
435
- return currency.equals(this.currency0) ? this.currency0Price : this.currency1Price;
436
- }
437
- /**
438
- * Returns the chain ID of the currencies in the pool.
439
- */;
440
- /** Works only for vanilla hookless v3 pools, otherwise throws an error */
441
- _proto.getOutputAmount =
442
- /*#__PURE__*/
443
- function () {
444
- var _getOutputAmount = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(inputAmount, sqrtPriceLimitX96) {
445
- var zeroForOne, _yield$this$swap, outputAmount, sqrtRatioX96, liquidity, tickCurrent, outputCurrency;
446
- return _regenerator().w(function (_context) {
447
- while (1) switch (_context.n) {
448
- case 0:
449
- !this.involvesCurrency(inputAmount.currency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'CURRENCY') : invariant(false) : void 0;
450
- zeroForOne = inputAmount.currency.equals(this.currency0);
451
- _context.n = 1;
452
- return this.swap(zeroForOne, inputAmount.quotient, sqrtPriceLimitX96);
453
- case 1:
454
- _yield$this$swap = _context.v;
455
- outputAmount = _yield$this$swap.amountCalculated;
456
- sqrtRatioX96 = _yield$this$swap.sqrtRatioX96;
457
- liquidity = _yield$this$swap.liquidity;
458
- tickCurrent = _yield$this$swap.tickCurrent;
459
- outputCurrency = zeroForOne ? this.currency1 : this.currency0;
460
- return _context.a(2, [CurrencyAmount.fromRawAmount(outputCurrency, JSBI.multiply(outputAmount, NEGATIVE_ONE)), new Pool(this.currency0, this.currency1, this.fee, this.tickSpacing, this.hooks, sqrtRatioX96, liquidity, tickCurrent, this.tickDataProvider)]);
461
- }
462
- }, _callee, this);
463
- }));
464
- function getOutputAmount(_x, _x2) {
465
- return _getOutputAmount.apply(this, arguments);
466
- }
467
- return getOutputAmount;
468
- }()
469
- /**
470
- * Given a desired output amount of a currency, return the computed input amount and a pool with state updated after the trade
471
- * Works only for vanilla hookless v3 pools, otherwise throws an error
472
- * @param outputAmount the output amount for which to quote the input amount
473
- * @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
474
- * @returns The input amount and the pool with updated state
475
- */
476
- ;
477
- _proto.getInputAmount =
478
- /*#__PURE__*/
479
- function () {
480
- var _getInputAmount = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(outputAmount, sqrtPriceLimitX96) {
481
- var zeroForOne, _yield$this$swap2, inputAmount, sqrtRatioX96, liquidity, tickCurrent, inputCurrency;
482
- return _regenerator().w(function (_context2) {
483
- while (1) switch (_context2.n) {
484
- case 0:
485
- !this.involvesCurrency(outputAmount.currency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'CURRENCY') : invariant(false) : void 0;
486
- zeroForOne = outputAmount.currency.equals(this.currency1);
487
- _context2.n = 1;
488
- return this.swap(zeroForOne, JSBI.multiply(outputAmount.quotient, NEGATIVE_ONE), sqrtPriceLimitX96);
489
- case 1:
490
- _yield$this$swap2 = _context2.v;
491
- inputAmount = _yield$this$swap2.amountCalculated;
492
- sqrtRatioX96 = _yield$this$swap2.sqrtRatioX96;
493
- liquidity = _yield$this$swap2.liquidity;
494
- tickCurrent = _yield$this$swap2.tickCurrent;
495
- inputCurrency = zeroForOne ? this.currency0 : this.currency1;
496
- return _context2.a(2, [CurrencyAmount.fromRawAmount(inputCurrency, inputAmount), new Pool(this.currency0, this.currency1, this.fee, this.tickSpacing, this.hooks, sqrtRatioX96, liquidity, tickCurrent, this.tickDataProvider)]);
497
- }
498
- }, _callee2, this);
499
- }));
500
- function getInputAmount(_x3, _x4) {
501
- return _getInputAmount.apply(this, arguments);
502
- }
503
- return getInputAmount;
504
- }()
505
- /**
506
- * Executes a swap
507
- * @param zeroForOne Whether the amount in is token0 or token1
508
- * @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
509
- * @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
510
- * @returns amountCalculated
511
- * @returns sqrtRatioX96
512
- * @returns liquidity
513
- * @returns tickCurrent
514
- */
515
- ;
516
- _proto.swap =
517
- /*#__PURE__*/
518
- function () {
519
- var _swap = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(zeroForOne, amountSpecified, sqrtPriceLimitX96) {
520
- return _regenerator().w(function (_context3) {
521
- while (1) switch (_context3.n) {
522
- case 0:
523
- if (this.hookImpactsSwap()) {
524
- _context3.n = 1;
525
- break;
526
- }
527
- return _context3.a(2, v3Swap(JSBI.BigInt(this.fee), this.sqrtRatioX96, this.tickCurrent, this.liquidity, this.tickSpacing, this.tickDataProvider, zeroForOne, amountSpecified, sqrtPriceLimitX96));
528
- case 1:
529
- throw new Error('Unsupported hook');
530
- case 2:
531
- return _context3.a(2);
532
- }
533
- }, _callee3, this);
534
- }));
535
- function swap(_x5, _x6, _x7) {
536
- return _swap.apply(this, arguments);
537
- }
538
- return swap;
539
- }();
540
- _proto.hookImpactsSwap = function hookImpactsSwap() {
541
- // could use this function to clear certain hooks that may have swap Permissions, but we know they don't interfere
542
- // in the swap outcome
543
- return Hook.hasSwapPermissions(this.hooks);
544
- };
545
- return _createClass(Pool, [{
546
- key: "token0",
547
- get: function get() {
548
- return this.currency0;
549
- }
550
- }, {
551
- key: "token1",
552
- get: function get() {
553
- return this.currency1;
554
- }
555
- }, {
556
- key: "currency0Price",
557
- get: function get() {
558
- var _this$_currency0Price;
559
- return (_this$_currency0Price = this._currency0Price) != null ? _this$_currency0Price : this._currency0Price = new Price(this.currency0, this.currency1, Q192, JSBI.multiply(this.sqrtRatioX96, this.sqrtRatioX96));
560
- }
561
- /** backwards compatibility with v2/3 sdks */
562
- }, {
563
- key: "token0Price",
564
- get: function get() {
565
- return this.currency0Price;
566
- }
567
- /**
568
- * Returns the current mid price of the pool in terms of currency1, i.e. the ratio of currency0 over currency1
569
- */
570
- }, {
571
- key: "currency1Price",
572
- get: function get() {
573
- var _this$_currency1Price;
574
- return (_this$_currency1Price = this._currency1Price) != null ? _this$_currency1Price : this._currency1Price = new Price(this.currency1, this.currency0, JSBI.multiply(this.sqrtRatioX96, this.sqrtRatioX96), Q192);
575
- }
576
- /** backwards compatibility with v2/3 sdks */
577
- }, {
578
- key: "token1Price",
579
- get: function get() {
580
- return this.currency1Price;
581
- }
582
- }, {
583
- key: "chainId",
584
- get: function get() {
585
- return this.currency0.chainId;
586
- }
587
- }]);
588
- }();
589
-
590
- var _BASE_TOKENIZE_UNDERL;
591
- // Kittycorn: Tokenize Token
592
- // This file contains the addresses of the Tokenize tokens on different networks.
593
- // Mainnet
594
- var TUSDC_MAINNET = /*#__PURE__*/new Token(ChainId.MAINNET, '0xcc331eC1d6CF4542F9eB988B49249cfa163081dc', 6, 'Kittycorn Tokenize USDC', 'tUSDC');
595
- var TUSDT_MAINNET = /*#__PURE__*/new Token(ChainId.MAINNET, '0x561A87303005D9C83FbD94dDEb80D63528fCD448', 6, 'Kittycorn Tokenize USDT', 'tUSDT');
596
- var TWETH_MAINNET = /*#__PURE__*/new Token(ChainId.MAINNET, '0x8a2D75bAadcd2C71b2aCF715fc3Da68964CEA48e', 18, 'Kittycorn Tokenize WETH', 'tWETH');
597
- var TWBTC_MAINNET = /*#__PURE__*/new Token(ChainId.MAINNET, '0x137a906E06EC20808c8F156F9024196427429220', 8, 'Kittycorn Tokenize WBTC', 'tWBTC');
598
- // Arbitrum
599
- var TUSDC_ARBITRUM_ONE = /*#__PURE__*/new Token(ChainId.ARBITRUM_ONE, '0x43297FBD1306f9fcDf96EE3A27e0113E4295D738', 6, 'Kittycorn Tokenize USDC', 'tUSDC');
600
- var TUSDT_ARBITRUM_ONE = /*#__PURE__*/new Token(ChainId.ARBITRUM_ONE, '0x93Ee5B16F4dDE4566b94488B8d929F39df112f60', 6, 'Kittycorn Tokenize USDT', 'tUSDT');
601
- var TWETH_ARBITRUM_ONE = /*#__PURE__*/new Token(ChainId.ARBITRUM_ONE, '0xCfdAb139Da7252EC3D8Df14F03659A46d1d1848C', 18, 'Kittycorn Tokenize WETH', 'tWETH');
602
- var TWBTC_ARBITRUM_ONE = /*#__PURE__*/new Token(ChainId.ARBITRUM_ONE, '0x8fecD0452BBF493C4915834E75310a5e8fe1FdDe', 8, 'Kittycorn Tokenize WBTC', 'tWBTC');
603
- var TLINK_ARBITRUM_ONE = /*#__PURE__*/new Token(ChainId.ARBITRUM_ONE, '0xDd816723CF1B310d1755156c4f37b4c8ed54ED5C', 18, 'Kittycorn Tokenize LINK', 'tLINK');
604
- var TAAVE_ARBITRUM_ONE = /*#__PURE__*/new Token(ChainId.ARBITRUM_ONE, '0x3eD9D2e07d314f2DcA05f920Ed5cbF2DFF60bC9a', 18, 'Kittycorn Tokenize AAVE', 'tAAVE');
605
- // Sepolia
606
- var TUSDC_SEPOLIA = /*#__PURE__*/new Token(ChainId.SEPOLIA, '0x1E271DB8D8B446A0DEe8e9D774f4213e9Bc1C6ba', 6, 'Kittycorn Tokenize USDC', 'tUSDC');
607
- var TUSDT_SEPOLIA = /*#__PURE__*/new Token(ChainId.SEPOLIA, '0x137a906E06EC20808c8F156F9024196427429220', 6, 'Kittycorn Tokenize USDT', 'tUSDT');
608
- var TWETH_SEPOLIA = /*#__PURE__*/new Token(ChainId.SEPOLIA, '0x54f4d76DaB01190A32FB0a5da441Be85e3Cef937', 18, 'Kittycorn Tokenize WETH', 'tWETH');
609
- var TWBTC_SEPOLIA = /*#__PURE__*/new Token(ChainId.SEPOLIA, '0x67332E6e2fbB793B822f3c2d7ff8BE9F07F1eAd9', 8, 'Kittycorn Tokenize WBTC', 'tWBTC');
610
- var TLINK_SEPOLIA = /*#__PURE__*/new Token(ChainId.SEPOLIA, '0x7ddE6BD33B4E6eB1d6F0519f4CF65deEB162dd86', 18, 'Kittycorn Tokenize LINK', 'tLINK');
611
- var TAAVE_SEPOLIA = /*#__PURE__*/new Token(ChainId.SEPOLIA, '0x1289c2dC45a0eA5E67F6ffa2B601D23d66547d3E', 18, 'Kittycorn Tokenize AAVE', 'tAAVE');
612
- var BASE_TOKENIZE_UNDERLYING = (_BASE_TOKENIZE_UNDERL = {}, _BASE_TOKENIZE_UNDERL[ChainId.MAINNET] = [{
613
- tokenize: TUSDC_MAINNET,
614
- underlying: /*#__PURE__*/new Token(ChainId.MAINNET, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 6, 'USDC', 'USD//C')
615
- }, {
616
- tokenize: TUSDT_MAINNET,
617
- underlying: /*#__PURE__*/new Token(ChainId.MAINNET, '0xdAC17F958D2ee523a2206206994597C13D831ec7', 6, 'USDT', 'Tether USD')
618
- }, {
619
- tokenize: TWETH_MAINNET,
620
- underlying: /*#__PURE__*/new Token(ChainId.MAINNET, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 18, 'WETH', 'Wrapped Ether')
621
- }, {
622
- tokenize: TWBTC_MAINNET,
623
- underlying: /*#__PURE__*/new Token(ChainId.MAINNET, '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 8, 'WBTC', 'Wrapped BTC')
624
- }], _BASE_TOKENIZE_UNDERL[ChainId.ARBITRUM_ONE] = [{
625
- tokenize: TUSDC_ARBITRUM_ONE,
626
- underlying: /*#__PURE__*/new Token(ChainId.ARBITRUM_ONE, '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', 6, 'USDC', 'USDC Token')
627
- }, {
628
- tokenize: TUSDT_ARBITRUM_ONE,
629
- underlying: /*#__PURE__*/new Token(ChainId.ARBITRUM_ONE, '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9', 6, 'USDT', 'USDT Token')
630
- }, {
631
- tokenize: TWETH_ARBITRUM_ONE,
632
- underlying: /*#__PURE__*/new Token(ChainId.ARBITRUM_ONE, '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', 18, 'WETH', 'Wrapped Ether')
633
- }, {
634
- tokenize: TWBTC_ARBITRUM_ONE,
635
- underlying: /*#__PURE__*/new Token(ChainId.ARBITRUM_ONE, '0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f', 8, 'WBTC', 'WBTC Token')
636
- }, {
637
- tokenize: TLINK_ARBITRUM_ONE,
638
- underlying: /*#__PURE__*/new Token(ChainId.ARBITRUM_ONE, '0xf97f4df75117a78c1A5a0DBb814Af92458539FB4', 18, 'LINK', 'LINK Token')
639
- }, {
640
- tokenize: TAAVE_ARBITRUM_ONE,
641
- underlying: /*#__PURE__*/new Token(ChainId.ARBITRUM_ONE, '0xba5DdD1f9d7F570dc94a51479a000E3BCE967196', 18, 'AAVE', 'AAVE Token')
642
- }], _BASE_TOKENIZE_UNDERL[ChainId.SEPOLIA] = [{
643
- tokenize: TUSDC_SEPOLIA,
644
- underlying: /*#__PURE__*/new Token(ChainId.SEPOLIA, '0x94a9D9AC8a22534E3FaCa9F4e7F2E2cf85d5E4C8', 6, 'USDC', 'USDC Token')
645
- }, {
646
- tokenize: TUSDT_SEPOLIA,
647
- underlying: /*#__PURE__*/new Token(ChainId.SEPOLIA, '0xaA8E23Fb1079EA71e0a56F48a2aA51851D8433D0', 6, 'USDT', 'USDT Token')
648
- }, {
649
- tokenize: TWETH_SEPOLIA,
650
- underlying: /*#__PURE__*/new Token(ChainId.SEPOLIA, '0xC558DBdd856501FCd9aaF1E62eae57A9F0629a3c', 18, 'WETH', 'Wrapped Ether')
651
- }, {
652
- tokenize: TWBTC_SEPOLIA,
653
- underlying: /*#__PURE__*/new Token(ChainId.SEPOLIA, '0x29f2D40B0605204364af54EC677bD022dA425d03', 8, 'WBTC', 'WBTC Token')
654
- }, {
655
- tokenize: TLINK_SEPOLIA,
656
- underlying: /*#__PURE__*/new Token(ChainId.SEPOLIA, '0xf8Fb3713D459D7C1018BD0A49D19b4C44290EBE5', 18, 'LINK', 'LINK Token')
657
- }, {
658
- tokenize: TAAVE_SEPOLIA,
659
- underlying: /*#__PURE__*/new Token(ChainId.SEPOLIA, '0x88541670E55cC00bEEFD87eB59EDd1b7C511AC9a', 18, 'AAVE', 'AAVE Token')
660
- }], _BASE_TOKENIZE_UNDERL);
661
- function getSupportUnderlyingByTokenize(chainId, tokenize) {
662
- var _BASE_TOKENIZE_UNDERL2;
663
- var token = (_BASE_TOKENIZE_UNDERL2 = BASE_TOKENIZE_UNDERLYING[chainId]) == null ? void 0 : _BASE_TOKENIZE_UNDERL2.find(function (token) {
664
- return tokenize.address &&
665
- // Check skip for Ether type is not have address
666
- token.tokenize.address.toLocaleLowerCase() === tokenize.address.toLocaleLowerCase();
667
- });
668
- return token ? token.underlying : undefined;
669
- }
670
- function getSupportTokenizeByUnderlying(chainId, underlying) {
671
- var _BASE_TOKENIZE_UNDERL3;
672
- var token = (_BASE_TOKENIZE_UNDERL3 = BASE_TOKENIZE_UNDERLYING[chainId]) == null ? void 0 : _BASE_TOKENIZE_UNDERL3.find(function (token) {
673
- return underlying.address &&
674
- // Check skip for Ether type is not have address
675
- token.underlying.address.toLocaleLowerCase() === underlying.address.toLocaleLowerCase();
676
- });
677
- return token ? token.tokenize : undefined;
678
- }
679
-
680
- function amountWithPathCurrency(amount, pool) {
681
- return CurrencyAmount.fromFractionalAmount(getPathCurrency(amount.currency, pool), amount.numerator, amount.denominator);
682
- }
683
- function getPathCurrency(currency, pool) {
684
- if (pool.involvesCurrency(currency)) {
685
- return currency;
686
- } else if (pool.involvesCurrency(currency.wrapped)) {
687
- return currency.wrapped;
688
- } else if (pool.currency0.wrapped.equals(currency)) {
689
- return pool.currency0;
690
- } else if (pool.currency1.wrapped.equals(currency)) {
691
- return pool.currency1;
692
- } else {
693
- var tokenize = getSupportTokenizeByUnderlying(pool.chainId, currency);
694
- if (tokenize !== undefined) {
695
- // Recursively try to find the path currency for the tokenize token
696
- return getPathCurrency(tokenize, pool);
697
- }
698
- throw new Error("Expected currency " + currency.symbol + " to be either " + pool.currency0.symbol + " or " + pool.currency1.symbol);
699
- }
700
- }
701
-
702
- /**
703
- * Represents a list of pools through which a swap can occur
704
- * @template TInput The input currency
705
- * @template TOutput The output currency
706
- */
707
- var Route = /*#__PURE__*/function () {
708
- /**
709
- * Creates an instance of route.
710
- * @param pools An array of `Pool` objects, ordered by the route the swap will take
711
- * @param input The input currency
712
- * @param output The output currency
713
- */
714
- function Route(pools, input, output) {
715
- this._midPrice = null;
716
- !(pools.length > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'POOLS') : invariant(false) : void 0;
717
- var chainId = pools[0].chainId;
718
- var allOnSameChain = pools.every(function (pool) {
719
- return pool.chainId === chainId;
720
- });
721
- !allOnSameChain ? process.env.NODE_ENV !== "production" ? invariant(false, 'CHAIN_IDS') : invariant(false) : void 0;
722
- /**
723
- * function throws if pools do not involve the input and output currency or the native/wrapped equivalent
724
- **/
725
- this.pathInput = getPathCurrency(input, pools[0]);
726
- this.pathOutput = getPathCurrency(output, pools[pools.length - 1]);
727
- /**
728
- * Normalizes currency0-currency1 order and selects the next currency/fee step to add to the path
729
- * */
730
- var currencyPath = [this.pathInput];
731
- for (var _iterator = _createForOfIteratorHelperLoose(pools.entries()), _step; !(_step = _iterator()).done;) {
732
- var _step$value = _step.value,
733
- i = _step$value[0],
734
- pool = _step$value[1];
735
- var currentInputCurrency = currencyPath[i];
736
- !(currentInputCurrency.equals(pool.currency0) || currentInputCurrency.equals(pool.currency1)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'PATH') : invariant(false) : void 0;
737
- var nextCurrency = currentInputCurrency.equals(pool.currency0) ? pool.currency1 : pool.currency0;
738
- currencyPath.push(nextCurrency);
739
- }
740
- this.pools = pools;
741
- this.currencyPath = currencyPath;
742
- this.input = input;
743
- this.output = output != null ? output : currencyPath[currencyPath.length - 1];
744
- }
745
- return _createClass(Route, [{
746
- key: "chainId",
747
- get: function get() {
748
- return this.pools[0].chainId;
749
- }
750
- /**
751
- * Returns the mid price of the route
752
- */
753
- }, {
754
- key: "midPrice",
755
- get: function get() {
756
- if (this._midPrice !== null) return this._midPrice;
757
- var price = this.pools.slice(1).reduce(function (_ref, pool) {
758
- var nextInput = _ref.nextInput,
759
- price = _ref.price;
760
- return nextInput.equals(pool.currency0) ? {
761
- nextInput: pool.currency1,
762
- price: price.multiply(pool.currency0Price)
763
- } : {
764
- nextInput: pool.currency0,
765
- price: price.multiply(pool.currency1Price)
766
- };
767
- }, this.pools[0].currency0.equals(this.input) ? {
768
- nextInput: this.pools[0].currency1,
769
- price: this.pools[0].currency0Price
770
- } : {
771
- nextInput: this.pools[0].currency0,
772
- price: this.pools[0].currency1Price
773
- }).price;
774
- return this._midPrice = new Price(this.input, this.output, price.denominator, price.numerator);
775
- }
776
- }]);
777
- }();
778
-
779
- /**
780
- * Trades comparator, an extension of the input output comparator that also considers other dimensions of the trade in ranking them
781
- * @template TInput The input currency, either Ether or an ERC-20
782
- * @template TOutput The output currency, either Ether or an ERC-20
783
- * @template TTradeType The trade type, either exact input or exact output
784
- * @param a The first trade to compare
785
- * @param b The second trade to compare
786
- * @returns A sorted ordering for two neighboring elements in a trade array
787
- */
788
- function tradeComparator(a, b) {
789
- // must have same input and output currency for comparison
790
- !a.inputAmount.currency.equals(b.inputAmount.currency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INPUT_CURRENCY') : invariant(false) : void 0;
791
- !a.outputAmount.currency.equals(b.outputAmount.currency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OUTPUT_CURRENCY') : invariant(false) : void 0;
792
- if (a.outputAmount.equalTo(b.outputAmount)) {
793
- if (a.inputAmount.equalTo(b.inputAmount)) {
794
- // consider the number of hops since each hop costs gas
795
- var aHops = a.swaps.reduce(function (total, cur) {
796
- return total + cur.route.currencyPath.length;
797
- }, 0);
798
- var bHops = b.swaps.reduce(function (total, cur) {
799
- return total + cur.route.currencyPath.length;
800
- }, 0);
801
- return aHops - bHops;
802
- }
803
- // trade A requires less input than trade B, so A should come first
804
- if (a.inputAmount.lessThan(b.inputAmount)) {
805
- return -1;
806
- } else {
807
- return 1;
808
- }
809
- } else {
810
- // tradeA has less output than trade B, so should come second
811
- if (a.outputAmount.lessThan(b.outputAmount)) {
812
- return 1;
813
- } else {
814
- return -1;
815
- }
816
- }
817
- }
818
- /**
819
- * Represents a trade executed against a set of routes where some percentage of the input is
820
- * split across each route.
821
- *
822
- * Each route has its own set of pools. Pools can not be re-used across routes.
823
- *
824
- * Does not account for slippage, i.e., changes in price environment that can occur between
825
- * the time the trade is submitted and when it is executed.
826
- * @template TInput The input currency, either Ether or an ERC-20
827
- * @template TOutput The output currency, either Ether or an ERC-20
828
- * @template TTradeType The trade type, either exact input or exact output
829
- */
830
- var Trade = /*#__PURE__*/function () {
831
- /**
832
- * Construct a trade by passing in the pre-computed property values
833
- * @param routes The routes through which the trade occurs
834
- * @param tradeType The type of trade, exact input or exact output
835
- */
836
- function Trade(_ref) {
837
- var routes = _ref.routes,
838
- tradeType = _ref.tradeType;
839
- var inputCurrency = routes[0].inputAmount.currency;
840
- var outputCurrency = routes[0].outputAmount.currency;
841
- !routes.every(function (_ref2) {
842
- var route = _ref2.route;
843
- return inputCurrency.equals(route.input);
844
- }) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INPUT_CURRENCY_MATCH') : invariant(false) : void 0;
845
- !routes.every(function (_ref3) {
846
- var route = _ref3.route;
847
- return outputCurrency.equals(route.output);
848
- }) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OUTPUT_CURRENCY_MATCH') : invariant(false) : void 0;
849
- var numPools = routes.map(function (_ref4) {
850
- var route = _ref4.route;
851
- return route.pools.length;
852
- }).reduce(function (total, cur) {
853
- return total + cur;
854
- }, 0);
855
- var poolIDSet = new Set();
856
- for (var _iterator = _createForOfIteratorHelperLoose(routes), _step; !(_step = _iterator()).done;) {
857
- var route = _step.value.route;
858
- for (var _iterator2 = _createForOfIteratorHelperLoose(route.pools), _step2; !(_step2 = _iterator2()).done;) {
859
- var pool = _step2.value;
860
- poolIDSet.add(Pool.getPoolId(pool.currency0, pool.currency1, pool.fee, pool.tickSpacing, pool.hooks));
861
- }
862
- }
863
- !(numPools === poolIDSet.size) ? process.env.NODE_ENV !== "production" ? invariant(false, 'POOLS_DUPLICATED') : invariant(false) : void 0;
864
- this.swaps = routes;
865
- this.tradeType = tradeType;
866
- }
867
- /**
868
- * @deprecated Deprecated in favor of 'swaps' property. If the trade consists of multiple routes
869
- * this will return an error.
870
- *
871
- * When the trade consists of just a single route, this returns the route of the trade,
872
- * i.e. which pools the trade goes through.
873
- */
874
- /**
875
- * Constructs an exact in trade with the given amount in and route
876
- * @template TInput The input currency, either Ether or an ERC-20
877
- * @template TOutput The output currency, either Ether or an ERC-20
878
- * @param route The route of the exact in trade
879
- * @param amountIn The amount being passed in
880
- * @returns The exact in trade
881
- */
882
- Trade.exactIn =
883
- /*#__PURE__*/
884
- function () {
885
- var _exactIn = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(route, amountIn) {
886
- return _regenerator().w(function (_context) {
887
- while (1) switch (_context.n) {
888
- case 0:
889
- return _context.a(2, Trade.fromRoute(route, amountIn, TradeType.EXACT_INPUT));
890
- }
891
- }, _callee);
892
- }));
893
- function exactIn(_x, _x2) {
894
- return _exactIn.apply(this, arguments);
895
- }
896
- return exactIn;
897
- }()
898
- /**
899
- * Constructs an exact out trade with the given amount out and route
900
- * @template TInput The input currency, either Ether or an ERC-20
901
- * @template TOutput The output currency, either Ether or an ERC-20
902
- * @param route The route of the exact out trade
903
- * @param amountOut The amount returned by the trade
904
- * @returns The exact out trade
905
- */
906
- ;
907
- Trade.exactOut =
908
- /*#__PURE__*/
909
- function () {
910
- var _exactOut = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(route, amountOut) {
911
- return _regenerator().w(function (_context2) {
912
- while (1) switch (_context2.n) {
913
- case 0:
914
- return _context2.a(2, Trade.fromRoute(route, amountOut, TradeType.EXACT_OUTPUT));
915
- }
916
- }, _callee2);
917
- }));
918
- function exactOut(_x3, _x4) {
919
- return _exactOut.apply(this, arguments);
920
- }
921
- return exactOut;
922
- }()
923
- /**
924
- * Constructs a trade by simulating swaps through the given route
925
- * @template TInput The input currency, either Ether or an ERC-20.
926
- * @template TOutput The output currency, either Ether or an ERC-20.
927
- * @template TTradeType The type of the trade, either exact in or exact out.
928
- * @param route route to swap through
929
- * @param amount the amount specified, either input or output, depending on tradeType
930
- * @param tradeType whether the trade is an exact input or exact output swap
931
- * @returns The route
932
- */
933
- ;
934
- Trade.fromRoute =
935
- /*#__PURE__*/
936
- function () {
937
- var _fromRoute = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(route, amount, tradeType) {
938
- var inputAmount, outputAmount, tokenAmount, i, pool, _yield$pool$getOutput, _tokenAmount, _i, _pool, _yield$_pool$getInput;
939
- return _regenerator().w(function (_context3) {
940
- while (1) switch (_context3.n) {
941
- case 0:
942
- if (!(tradeType === TradeType.EXACT_INPUT)) {
943
- _context3.n = 5;
944
- break;
945
- }
946
- !amount.currency.equals(route.input) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INPUT') : invariant(false) : void 0;
947
- // Account for trades that wrap/unwrap as a first step
948
- tokenAmount = amountWithPathCurrency(amount, route.pools[0]);
949
- i = 0;
950
- case 1:
951
- if (!(i < route.pools.length)) {
952
- _context3.n = 4;
953
- break;
954
- }
955
- pool = route.pools[i];
956
- _context3.n = 2;
957
- return pool.getOutputAmount(tokenAmount);
958
- case 2:
959
- _yield$pool$getOutput = _context3.v;
960
- tokenAmount = _yield$pool$getOutput[0];
961
- case 3:
962
- i++;
963
- _context3.n = 1;
964
- break;
965
- case 4:
966
- inputAmount = CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator);
967
- outputAmount = CurrencyAmount.fromFractionalAmount(route.output, tokenAmount.numerator, tokenAmount.denominator);
968
- _context3.n = 10;
969
- break;
970
- case 5:
971
- !amount.currency.equals(route.output) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OUTPUT') : invariant(false) : void 0;
972
- // Account for trades that wrap/unwrap as a last step
973
- _tokenAmount = amountWithPathCurrency(amount, route.pools[route.pools.length - 1]);
974
- _i = route.pools.length - 1;
975
- case 6:
976
- if (!(_i >= 0)) {
977
- _context3.n = 9;
978
- break;
979
- }
980
- _pool = route.pools[_i];
981
- _context3.n = 7;
982
- return _pool.getInputAmount(_tokenAmount);
983
- case 7:
984
- _yield$_pool$getInput = _context3.v;
985
- _tokenAmount = _yield$_pool$getInput[0];
986
- case 8:
987
- _i--;
988
- _context3.n = 6;
989
- break;
990
- case 9:
991
- inputAmount = CurrencyAmount.fromFractionalAmount(route.input, _tokenAmount.numerator, _tokenAmount.denominator);
992
- outputAmount = CurrencyAmount.fromFractionalAmount(route.output, amount.numerator, amount.denominator);
993
- case 10:
994
- return _context3.a(2, new Trade({
995
- routes: [{
996
- inputAmount: inputAmount,
997
- outputAmount: outputAmount,
998
- route: route
999
- }],
1000
- tradeType: tradeType
1001
- }));
1002
- }
1003
- }, _callee3);
1004
- }));
1005
- function fromRoute(_x5, _x6, _x7) {
1006
- return _fromRoute.apply(this, arguments);
1007
- }
1008
- return fromRoute;
1009
- }()
1010
- /**
1011
- * Constructs a trade from routes by simulating swaps
1012
- *
1013
- * @template TInput The input currency, either Ether or an ERC-20.
1014
- * @template TOutput The output currency, either Ether or an ERC-20.
1015
- * @template TTradeType The type of the trade, either exact in or exact out.
1016
- * @param routes the routes to swap through and how much of the amount should be routed through each
1017
- * @param tradeType whether the trade is an exact input or exact output swap
1018
- * @returns The trade
1019
- */
1020
- ;
1021
- Trade.fromRoutes =
1022
- /*#__PURE__*/
1023
- function () {
1024
- var _fromRoutes = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(routes, tradeType) {
1025
- var swaps;
1026
- return _regenerator().w(function (_context5) {
1027
- while (1) switch (_context5.n) {
1028
- case 0:
1029
- _context5.n = 1;
1030
- return Promise.all(routes.map(/*#__PURE__*/function () {
1031
- var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(_ref5) {
1032
- var amount, route, trade;
1033
- return _regenerator().w(function (_context4) {
1034
- while (1) switch (_context4.n) {
1035
- case 0:
1036
- amount = _ref5.amount, route = _ref5.route;
1037
- _context4.n = 1;
1038
- return Trade.fromRoute(route, amount, tradeType);
1039
- case 1:
1040
- trade = _context4.v;
1041
- return _context4.a(2, trade.swaps[0]);
1042
- }
1043
- }, _callee4);
1044
- }));
1045
- return function (_x0) {
1046
- return _ref6.apply(this, arguments);
1047
- };
1048
- }()));
1049
- case 1:
1050
- swaps = _context5.v;
1051
- return _context5.a(2, new Trade({
1052
- routes: swaps,
1053
- tradeType: tradeType
1054
- }));
1055
- }
1056
- }, _callee5);
1057
- }));
1058
- function fromRoutes(_x8, _x9) {
1059
- return _fromRoutes.apply(this, arguments);
1060
- }
1061
- return fromRoutes;
1062
- }()
1063
- /**
1064
- * Creates a trade without computing the result of swapping through the route. Useful when you have simulated the trade
1065
- * elsewhere and do not have any tick data
1066
- * @template TInput The input currency, either Ether or an ERC-20
1067
- * @template TOutput The output currency, either Ether or an ERC-20
1068
- * @template TTradeType The type of the trade, either exact in or exact out
1069
- * @param constructorArguments The arguments passed to the trade constructor
1070
- * @returns The unchecked trade
1071
- */
1072
- ;
1073
- Trade.createUncheckedTrade = function createUncheckedTrade(constructorArguments) {
1074
- return new Trade(_extends({}, constructorArguments, {
1075
- routes: [{
1076
- inputAmount: constructorArguments.inputAmount,
1077
- outputAmount: constructorArguments.outputAmount,
1078
- route: constructorArguments.route
1079
- }]
1080
- }));
1081
- }
1082
- /**
1083
- * Creates a trade without computing the result of swapping through the routes. Useful when you have simulated the trade
1084
- * elsewhere and do not have any tick data
1085
- * @template TInput The input currency, either Ether or an ERC-20
1086
- * @template TOutput The output currency, either Ether or an ERC-20
1087
- * @template TTradeType The type of the trade, either exact in or exact out
1088
- * @param constructorArguments The arguments passed to the trade constructor
1089
- * @returns The unchecked trade
1090
- */;
1091
- Trade.createUncheckedTradeWithMultipleRoutes = function createUncheckedTradeWithMultipleRoutes(constructorArguments) {
1092
- return new Trade(constructorArguments);
1093
- }
1094
- /**
1095
- * Get the minimum amount that must be received from this trade for the given slippage tolerance
1096
- * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
1097
- * @returns The amount out
1098
- */;
1099
- var _proto = Trade.prototype;
1100
- _proto.minimumAmountOut = function minimumAmountOut(slippageTolerance, amountOut) {
1101
- if (amountOut === void 0) {
1102
- amountOut = this.outputAmount;
1103
- }
1104
- !!slippageTolerance.lessThan(ZERO) ? process.env.NODE_ENV !== "production" ? invariant(false, 'SLIPPAGE_TOLERANCE') : invariant(false) : void 0;
1105
- if (this.tradeType === TradeType.EXACT_OUTPUT) {
1106
- return amountOut;
1107
- } else {
1108
- var slippageAdjustedAmountOut = new Fraction(ONE).add(slippageTolerance).invert().multiply(amountOut.quotient).quotient;
1109
- return CurrencyAmount.fromRawAmount(amountOut.currency, slippageAdjustedAmountOut);
1110
- }
1111
- }
1112
- /**
1113
- * Get the maximum amount in that can be spent via this trade for the given slippage tolerance
1114
- * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
1115
- * @returns The amount in
1116
- */;
1117
- _proto.maximumAmountIn = function maximumAmountIn(slippageTolerance, amountIn) {
1118
- if (amountIn === void 0) {
1119
- amountIn = this.inputAmount;
1120
- }
1121
- !!slippageTolerance.lessThan(ZERO) ? process.env.NODE_ENV !== "production" ? invariant(false, 'SLIPPAGE_TOLERANCE') : invariant(false) : void 0;
1122
- if (this.tradeType === TradeType.EXACT_INPUT) {
1123
- return amountIn;
1124
- } else {
1125
- var slippageAdjustedAmountIn = new Fraction(ONE).add(slippageTolerance).multiply(amountIn.quotient).quotient;
1126
- return CurrencyAmount.fromRawAmount(amountIn.currency, slippageAdjustedAmountIn);
1127
- }
1128
- }
1129
- /**
1130
- * Return the execution price after accounting for slippage tolerance
1131
- * @param slippageTolerance the allowed tolerated slippage
1132
- * @returns The execution price
1133
- */;
1134
- _proto.worstExecutionPrice = function worstExecutionPrice(slippageTolerance) {
1135
- return new Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).quotient, this.minimumAmountOut(slippageTolerance).quotient);
1136
- }
1137
- /**
1138
- * Given a list of pools, and a fixed amount in, returns the top `maxNumResults` trades that go from an input currency
1139
- * amount to an output currency, making at most `maxHops` hops.
1140
- * Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting
1141
- * the amount in among multiple routes.
1142
- * @param pools the pools to consider in finding the best trade
1143
- * @param nextAmountIn exact amount of input currency to spend
1144
- * @param currencyOut the desired currency out
1145
- * @param maxNumResults maximum number of results to return
1146
- * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool
1147
- * @param currentPools used in recursion; the current list of pools
1148
- * @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter
1149
- * @param bestTrades used in recursion; the current list of best trades
1150
- * @returns The exact in trade
1151
- */;
1152
- Trade.bestTradeExactIn =
1153
- /*#__PURE__*/
1154
- function () {
1155
- var _bestTradeExactIn = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(pools, currencyAmountIn, currencyOut, _temp,
1156
- // used in recursion.
1157
- currentPools, nextAmountIn, bestTrades) {
1158
- var _ref7, _ref7$maxNumResults, maxNumResults, _ref7$maxHops, maxHops, amountIn, i, pool, amountOut, _yield$pool$getOutput2, poolsExcludingThisPool, _t, _t2, _t3, _t4, _t5, _t6;
1159
- return _regenerator().w(function (_context6) {
1160
- while (1) switch (_context6.n) {
1161
- case 0:
1162
- _ref7 = _temp === void 0 ? {} : _temp, _ref7$maxNumResults = _ref7.maxNumResults, maxNumResults = _ref7$maxNumResults === void 0 ? 3 : _ref7$maxNumResults, _ref7$maxHops = _ref7.maxHops, maxHops = _ref7$maxHops === void 0 ? 3 : _ref7$maxHops;
1163
- if (currentPools === void 0) {
1164
- currentPools = [];
1165
- }
1166
- if (nextAmountIn === void 0) {
1167
- nextAmountIn = currencyAmountIn;
1168
- }
1169
- if (bestTrades === void 0) {
1170
- bestTrades = [];
1171
- }
1172
- !(pools.length > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'POOLS') : invariant(false) : void 0;
1173
- !(maxHops > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'MAX_HOPS') : invariant(false) : void 0;
1174
- !(currencyAmountIn === nextAmountIn || currentPools.length > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INVALID_RECURSION') : invariant(false) : void 0;
1175
- amountIn = nextAmountIn;
1176
- i = 0;
1177
- case 1:
1178
- if (!(i < pools.length)) {
1179
- _context6.n = 11;
1180
- break;
1181
- }
1182
- pool = pools[i]; // pool irrelevant
1183
- if (!(!pool.currency0.equals(amountIn.currency) && !pool.currency1.equals(amountIn.currency))) {
1184
- _context6.n = 2;
1185
- break;
1186
- }
1187
- return _context6.a(3, 10);
1188
- case 2:
1189
- amountOut = void 0;
1190
- _context6.p = 3;
1191
- _context6.n = 4;
1192
- return pool.getOutputAmount(amountIn);
1193
- case 4:
1194
- _yield$pool$getOutput2 = _context6.v;
1195
- amountOut = _yield$pool$getOutput2[0];
1196
- _context6.n = 7;
1197
- break;
1198
- case 5:
1199
- _context6.p = 5;
1200
- _t = _context6.v;
1201
- if (!_t.isInsufficientInputAmountError) {
1202
- _context6.n = 6;
1203
- break;
1204
- }
1205
- return _context6.a(3, 10);
1206
- case 6:
1207
- throw _t;
1208
- case 7:
1209
- if (!amountOut.currency.equals(currencyOut)) {
1210
- _context6.n = 9;
1211
- break;
1212
- }
1213
- _t2 = sortedInsert;
1214
- _t3 = bestTrades;
1215
- _context6.n = 8;
1216
- return Trade.fromRoute(new Route([].concat(currentPools, [pool]), currencyAmountIn.currency, currencyOut), currencyAmountIn, TradeType.EXACT_INPUT);
1217
- case 8:
1218
- _t4 = _context6.v;
1219
- _t5 = maxNumResults;
1220
- _t6 = tradeComparator;
1221
- _t2(_t3, _t4, _t5, _t6);
1222
- _context6.n = 10;
1223
- break;
1224
- case 9:
1225
- if (!(maxHops > 1 && pools.length > 1)) {
1226
- _context6.n = 10;
1227
- break;
1228
- }
1229
- poolsExcludingThisPool = pools.slice(0, i).concat(pools.slice(i + 1, pools.length)); // otherwise, consider all the other paths that lead from this currency as long as we have not exceeded maxHops
1230
- _context6.n = 10;
1231
- return Trade.bestTradeExactIn(poolsExcludingThisPool, currencyAmountIn, currencyOut, {
1232
- maxNumResults: maxNumResults,
1233
- maxHops: maxHops - 1
1234
- }, [].concat(currentPools, [pool]), amountOut, bestTrades);
1235
- case 10:
1236
- i++;
1237
- _context6.n = 1;
1238
- break;
1239
- case 11:
1240
- return _context6.a(2, bestTrades);
1241
- }
1242
- }, _callee6, null, [[3, 5]]);
1243
- }));
1244
- function bestTradeExactIn(_x1, _x10, _x11, _x12, _x13, _x14, _x15) {
1245
- return _bestTradeExactIn.apply(this, arguments);
1246
- }
1247
- return bestTradeExactIn;
1248
- }()
1249
- /**
1250
- * similar to the above method but instead targets a fixed output amount
1251
- * given a list of pools, and a fixed amount out, returns the top `maxNumResults` trades that go from an input currency
1252
- * to an output currency amount, making at most `maxHops` hops
1253
- * note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting
1254
- * the amount in among multiple routes.
1255
- * @param pools the pools to consider in finding the best trade
1256
- * @param currencyIn the currency to spend
1257
- * @param currencyAmountOut the desired currency amount out
1258
- * @param nextAmountOut the exact amount of currency out
1259
- * @param maxNumResults maximum number of results to return
1260
- * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool
1261
- * @param currentPools used in recursion; the current list of pools
1262
- * @param bestTrades used in recursion; the current list of best trades
1263
- * @returns The exact out trade
1264
- */
1265
- ;
1266
- Trade.bestTradeExactOut =
1267
- /*#__PURE__*/
1268
- function () {
1269
- var _bestTradeExactOut = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(pools, currencyIn, currencyAmountOut, _temp2,
1270
- // used in recursion.
1271
- currentPools, nextAmountOut, bestTrades) {
1272
- var _ref8, _ref8$maxNumResults, maxNumResults, _ref8$maxHops, maxHops, amountOut, i, pool, amountIn, _yield$pool$getInputA, poolsExcludingThisPool, _t7, _t8, _t9, _t0, _t1, _t10;
1273
- return _regenerator().w(function (_context7) {
1274
- while (1) switch (_context7.n) {
1275
- case 0:
1276
- _ref8 = _temp2 === void 0 ? {} : _temp2, _ref8$maxNumResults = _ref8.maxNumResults, maxNumResults = _ref8$maxNumResults === void 0 ? 3 : _ref8$maxNumResults, _ref8$maxHops = _ref8.maxHops, maxHops = _ref8$maxHops === void 0 ? 3 : _ref8$maxHops;
1277
- if (currentPools === void 0) {
1278
- currentPools = [];
1279
- }
1280
- if (nextAmountOut === void 0) {
1281
- nextAmountOut = currencyAmountOut;
1282
- }
1283
- if (bestTrades === void 0) {
1284
- bestTrades = [];
1285
- }
1286
- !(pools.length > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'POOLS') : invariant(false) : void 0;
1287
- !(maxHops > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'MAX_HOPS') : invariant(false) : void 0;
1288
- !(currencyAmountOut === nextAmountOut || currentPools.length > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INVALID_RECURSION') : invariant(false) : void 0;
1289
- amountOut = nextAmountOut;
1290
- i = 0;
1291
- case 1:
1292
- if (!(i < pools.length)) {
1293
- _context7.n = 11;
1294
- break;
1295
- }
1296
- pool = pools[i]; // pool irrelevant
1297
- if (!(!pool.currency0.equals(amountOut.currency) && !pool.currency1.equals(amountOut.currency))) {
1298
- _context7.n = 2;
1299
- break;
1300
- }
1301
- return _context7.a(3, 10);
1302
- case 2:
1303
- amountIn = void 0;
1304
- _context7.p = 3;
1305
- _context7.n = 4;
1306
- return pool.getInputAmount(amountOut);
1307
- case 4:
1308
- _yield$pool$getInputA = _context7.v;
1309
- amountIn = _yield$pool$getInputA[0];
1310
- _context7.n = 7;
1311
- break;
1312
- case 5:
1313
- _context7.p = 5;
1314
- _t7 = _context7.v;
1315
- if (!_t7.isInsufficientReservesError) {
1316
- _context7.n = 6;
1317
- break;
1318
- }
1319
- return _context7.a(3, 10);
1320
- case 6:
1321
- throw _t7;
1322
- case 7:
1323
- if (!amountIn.currency.equals(currencyIn)) {
1324
- _context7.n = 9;
1325
- break;
1326
- }
1327
- _t8 = sortedInsert;
1328
- _t9 = bestTrades;
1329
- _context7.n = 8;
1330
- return Trade.fromRoute(new Route([pool].concat(currentPools), currencyIn, currencyAmountOut.currency), currencyAmountOut, TradeType.EXACT_OUTPUT);
1331
- case 8:
1332
- _t0 = _context7.v;
1333
- _t1 = maxNumResults;
1334
- _t10 = tradeComparator;
1335
- _t8(_t9, _t0, _t1, _t10);
1336
- _context7.n = 10;
1337
- break;
1338
- case 9:
1339
- if (!(maxHops > 1 && pools.length > 1)) {
1340
- _context7.n = 10;
1341
- break;
1342
- }
1343
- poolsExcludingThisPool = pools.slice(0, i).concat(pools.slice(i + 1, pools.length)); // otherwise, consider all the other paths that arrive at this currency as long as we have not exceeded maxHops
1344
- _context7.n = 10;
1345
- return Trade.bestTradeExactOut(poolsExcludingThisPool, currencyIn, currencyAmountOut, {
1346
- maxNumResults: maxNumResults,
1347
- maxHops: maxHops - 1
1348
- }, [pool].concat(currentPools), amountIn, bestTrades);
1349
- case 10:
1350
- i++;
1351
- _context7.n = 1;
1352
- break;
1353
- case 11:
1354
- return _context7.a(2, bestTrades);
1355
- }
1356
- }, _callee7, null, [[3, 5]]);
1357
- }));
1358
- function bestTradeExactOut(_x16, _x17, _x18, _x19, _x20, _x21, _x22) {
1359
- return _bestTradeExactOut.apply(this, arguments);
1360
- }
1361
- return bestTradeExactOut;
1362
- }();
1363
- return _createClass(Trade, [{
1364
- key: "route",
1365
- get: function get() {
1366
- !(this.swaps.length === 1) ? process.env.NODE_ENV !== "production" ? invariant(false, 'MULTIPLE_ROUTES') : invariant(false) : void 0;
1367
- return this.swaps[0].route;
1368
- }
1369
- /**
1370
- * The input amount for the trade assuming no slippage.
1371
- */
1372
- }, {
1373
- key: "inputAmount",
1374
- get: function get() {
1375
- if (this._inputAmount) {
1376
- return this._inputAmount;
1377
- }
1378
- var inputCurrency = this.swaps[0].inputAmount.currency;
1379
- var totalInputFromRoutes = this.swaps.map(function (_ref9) {
1380
- var inputAmount = _ref9.inputAmount;
1381
- return inputAmount;
1382
- }).reduce(function (total, cur) {
1383
- return total.add(cur);
1384
- }, CurrencyAmount.fromRawAmount(inputCurrency, 0));
1385
- this._inputAmount = totalInputFromRoutes;
1386
- return this._inputAmount;
1387
- }
1388
- /**
1389
- * The output amount for the trade assuming no slippage.
1390
- */
1391
- }, {
1392
- key: "outputAmount",
1393
- get: function get() {
1394
- if (this._outputAmount) {
1395
- return this._outputAmount;
1396
- }
1397
- var outputCurrency = this.swaps[0].outputAmount.currency;
1398
- var totalOutputFromRoutes = this.swaps.map(function (_ref0) {
1399
- var outputAmount = _ref0.outputAmount;
1400
- return outputAmount;
1401
- }).reduce(function (total, cur) {
1402
- return total.add(cur);
1403
- }, CurrencyAmount.fromRawAmount(outputCurrency, 0));
1404
- this._outputAmount = totalOutputFromRoutes;
1405
- return this._outputAmount;
1406
- }
1407
- /**
1408
- * The price expressed in terms of output amount/input amount.
1409
- */
1410
- }, {
1411
- key: "executionPrice",
1412
- get: function get() {
1413
- var _this$_executionPrice;
1414
- return (_this$_executionPrice = this._executionPrice) != null ? _this$_executionPrice : this._executionPrice = new Price(this.inputAmount.currency, this.outputAmount.currency, this.inputAmount.quotient, this.outputAmount.quotient);
1415
- }
1416
- /**
1417
- * Returns the percent difference between the route's mid price and the price impact
1418
- */
1419
- }, {
1420
- key: "priceImpact",
1421
- get: function get() {
1422
- if (this._priceImpact) {
1423
- return this._priceImpact;
1424
- }
1425
- var spotOutputAmount = CurrencyAmount.fromRawAmount(this.outputAmount.currency, 0);
1426
- for (var _iterator3 = _createForOfIteratorHelperLoose(this.swaps), _step3; !(_step3 = _iterator3()).done;) {
1427
- var _step3$value = _step3.value,
1428
- route = _step3$value.route,
1429
- inputAmount = _step3$value.inputAmount;
1430
- var midPrice = route.midPrice;
1431
- spotOutputAmount = spotOutputAmount.add(midPrice.quote(inputAmount));
1432
- }
1433
- var priceImpact = spotOutputAmount.subtract(this.outputAmount).divide(spotOutputAmount);
1434
- this._priceImpact = new Percent(priceImpact.numerator, priceImpact.denominator);
1435
- return this._priceImpact;
1436
- }
1437
- }]);
1438
- }();
1439
-
1440
- /**
1441
- * This library is the almost the same as v3-sdk priceTickConversion except
1442
- * that it accepts a Currency type instead of a Token type,
1443
- * and thus uses some helper functions defined for the Currency type over the Token type.
1444
- */
1445
- /**
1446
- * Returns a price object corresponding to the input tick and the base/quote token
1447
- * Inputs must be tokens because the address order is used to interpret the price represented by the tick
1448
- * @param baseToken the base token of the price
1449
- * @param quoteToken the quote token of the price
1450
- * @param tick the tick for which to return the price
1451
- */
1452
- function tickToPrice(baseCurrency, quoteCurrency, tick) {
1453
- var sqrtRatioX96 = TickMath.getSqrtRatioAtTick(tick);
1454
- var ratioX192 = JSBI.multiply(sqrtRatioX96, sqrtRatioX96);
1455
- return sortsBefore(baseCurrency, quoteCurrency) ? new Price(baseCurrency, quoteCurrency, Q192, ratioX192) : new Price(baseCurrency, quoteCurrency, ratioX192, Q192);
1456
- }
1457
- /**
1458
- * Returns the first tick for which the given price is greater than or equal to the tick price
1459
- * @param price for which to return the closest tick that represents a price less than or equal to the input price,
1460
- * i.e. the price of the returned tick is less than or equal to the input price
1461
- */
1462
- function priceToClosestTick(price) {
1463
- var sorted = sortsBefore(price.baseCurrency, price.quoteCurrency);
1464
- var sqrtRatioX96 = sorted ? encodeSqrtRatioX96(price.numerator, price.denominator) : encodeSqrtRatioX96(price.denominator, price.numerator);
1465
- var tick = TickMath.getTickAtSqrtRatio(sqrtRatioX96);
1466
- var nextTickPrice = tickToPrice(price.baseCurrency, price.quoteCurrency, tick + 1);
1467
- if (sorted) {
1468
- if (!price.lessThan(nextTickPrice)) {
1469
- tick++;
1470
- }
1471
- } else {
1472
- if (!price.greaterThan(nextTickPrice)) {
1473
- tick++;
1474
- }
1475
- }
1476
- return tick;
1477
- }
1478
-
1479
- /**
1480
- * Represents a position on a Uniswap V4 Pool
1481
- * @dev Similar to the V3 implementation
1482
- * - using Currency instead of Token
1483
- * - keep in mind that Pool and liquidity must be fetched from the pool manager
1484
- */
1485
- var Position = /*#__PURE__*/function () {
1486
- /**
1487
- * Constructs a position for a given pool with the given liquidity
1488
- * @param pool For which pool the liquidity is assigned
1489
- * @param liquidity The amount of liquidity that is in the position
1490
- * @param tickLower The lower tick of the position
1491
- * @param tickUpper The upper tick of the position
1492
- */
1493
- function Position(_ref) {
1494
- var pool = _ref.pool,
1495
- liquidity = _ref.liquidity,
1496
- tickLower = _ref.tickLower,
1497
- tickUpper = _ref.tickUpper;
1498
- // cached resuts for the getters
1499
- this._token0Amount = null;
1500
- this._token1Amount = null;
1501
- this._mintAmounts = null;
1502
- !(tickLower < tickUpper) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TICK_ORDER') : invariant(false) : void 0;
1503
- !(tickLower >= TickMath.MIN_TICK && tickLower % pool.tickSpacing === 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TICK_LOWER') : invariant(false) : void 0;
1504
- !(tickUpper <= TickMath.MAX_TICK && tickUpper % pool.tickSpacing === 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TICK_UPPER') : invariant(false) : void 0;
1505
- this.pool = pool;
1506
- this.tickLower = tickLower;
1507
- this.tickUpper = tickUpper;
1508
- this.liquidity = JSBI.BigInt(liquidity);
1509
- }
1510
- /**
1511
- * Returns the price of token0 at the lower tick
1512
- */
1513
- var _proto = Position.prototype;
1514
- /**
1515
- * Returns the lower and upper sqrt ratios if the price 'slips' up to slippage tolerance percentage
1516
- * @param slippageTolerance The amount by which the price can 'slip' before the transaction will revert
1517
- * @returns The sqrt ratios after slippage
1518
- */
1519
- _proto.ratiosAfterSlippage = function ratiosAfterSlippage(slippageTolerance) {
1520
- var priceLower = this.pool.token0Price.asFraction.multiply(new Percent(1).subtract(slippageTolerance));
1521
- var priceUpper = this.pool.token0Price.asFraction.multiply(slippageTolerance.add(1));
1522
- var sqrtRatioX96Lower = encodeSqrtRatioX96(priceLower.numerator, priceLower.denominator);
1523
- if (JSBI.lessThanOrEqual(sqrtRatioX96Lower, TickMath.MIN_SQRT_RATIO)) {
1524
- sqrtRatioX96Lower = JSBI.add(TickMath.MIN_SQRT_RATIO, JSBI.BigInt(1));
1525
- }
1526
- var sqrtRatioX96Upper = encodeSqrtRatioX96(priceUpper.numerator, priceUpper.denominator);
1527
- if (JSBI.greaterThanOrEqual(sqrtRatioX96Upper, TickMath.MAX_SQRT_RATIO)) {
1528
- sqrtRatioX96Upper = JSBI.subtract(TickMath.MAX_SQRT_RATIO, JSBI.BigInt(1));
1529
- }
1530
- return {
1531
- sqrtRatioX96Lower: sqrtRatioX96Lower,
1532
- sqrtRatioX96Upper: sqrtRatioX96Upper
1533
- };
1534
- }
1535
- /**
1536
- * Returns the maximum amount of token0 and token1 that must be sent in order to safely mint the amount of liquidity held by the position
1537
- * with the given slippage tolerance
1538
- * @param slippageTolerance Tolerance of unfavorable slippage from the current price
1539
- * @returns The amounts, with slippage
1540
- * @dev In v4, minting and increasing is protected by maximum amounts of token0 and token1.
1541
- */;
1542
- _proto.mintAmountsWithSlippage = function mintAmountsWithSlippage(slippageTolerance) {
1543
- // get lower/upper prices
1544
- // these represent the lowest and highest prices that the pool is allowed to "slip" to
1545
- var _this$ratiosAfterSlip = this.ratiosAfterSlippage(slippageTolerance),
1546
- sqrtRatioX96Upper = _this$ratiosAfterSlip.sqrtRatioX96Upper,
1547
- sqrtRatioX96Lower = _this$ratiosAfterSlip.sqrtRatioX96Lower;
1548
- // construct counterfactual pools from the lower bounded price and the upper bounded price
1549
- var poolLower = new Pool(this.pool.token0, this.pool.token1, this.pool.fee, this.pool.tickSpacing, this.pool.hooks, sqrtRatioX96Lower, 0 /* liquidity doesn't matter */, TickMath.getTickAtSqrtRatio(sqrtRatioX96Lower));
1550
- var poolUpper = new Pool(this.pool.token0, this.pool.token1, this.pool.fee, this.pool.tickSpacing, this.pool.hooks, sqrtRatioX96Upper, 0 /* liquidity doesn't matter */, TickMath.getTickAtSqrtRatio(sqrtRatioX96Upper));
1551
- // Note: Slippage derivation in v4 is different from v3.
1552
- // When creating a position (minting) or adding to a position (increasing) slippage is bounded by the MAXIMUM amount in in token0 and token1.
1553
- // The largest amount of token1 will happen when the price slips up, so we use the poolUpper to get amount1.
1554
- // The largest amount of token0 will happen when the price slips down, so we use the poolLower to get amount0.
1555
- // Ie...We want the larger amounts, which occurs at the upper price for amount1...
1556
- var amount1 = new Position({
1557
- pool: poolUpper,
1558
- liquidity: this.liquidity,
1559
- tickLower: this.tickLower,
1560
- tickUpper: this.tickUpper
1561
- }).mintAmounts.amount1;
1562
- // ...and the lower for amount0
1563
- var amount0 = new Position({
1564
- pool: poolLower,
1565
- liquidity: this.liquidity,
1566
- tickLower: this.tickLower,
1567
- tickUpper: this.tickUpper
1568
- }).mintAmounts.amount0;
1569
- return {
1570
- amount0: amount0,
1571
- amount1: amount1
1572
- };
1573
- }
1574
- /**
1575
- * Returns the minimum amounts that should be requested in order to safely burn the amount of liquidity held by the
1576
- * position with the given slippage tolerance
1577
- * @param slippageTolerance tolerance of unfavorable slippage from the current price
1578
- * @returns The amounts, with slippage
1579
- */;
1580
- _proto.burnAmountsWithSlippage = function burnAmountsWithSlippage(slippageTolerance) {
1581
- // get lower/upper prices
1582
- var _this$ratiosAfterSlip2 = this.ratiosAfterSlippage(slippageTolerance),
1583
- sqrtRatioX96Upper = _this$ratiosAfterSlip2.sqrtRatioX96Upper,
1584
- sqrtRatioX96Lower = _this$ratiosAfterSlip2.sqrtRatioX96Lower;
1585
- // construct counterfactual pools
1586
- var poolLower = new Pool(this.pool.currency0, this.pool.currency1, this.pool.fee, this.pool.tickSpacing, this.pool.hooks, sqrtRatioX96Lower, 0 /* liquidity doesn't matter */, TickMath.getTickAtSqrtRatio(sqrtRatioX96Lower));
1587
- var poolUpper = new Pool(this.pool.currency0, this.pool.currency1, this.pool.fee, this.pool.tickSpacing, this.pool.hooks, sqrtRatioX96Upper, 0 /* liquidity doesn't matter */, TickMath.getTickAtSqrtRatio(sqrtRatioX96Upper));
1588
- // we want the smaller amounts...
1589
- // ...which occurs at the upper price for amount0...
1590
- var amount0 = new Position({
1591
- pool: poolUpper,
1592
- liquidity: this.liquidity,
1593
- tickLower: this.tickLower,
1594
- tickUpper: this.tickUpper
1595
- }).amount0;
1596
- // ...and the lower for amount1
1597
- var amount1 = new Position({
1598
- pool: poolLower,
1599
- liquidity: this.liquidity,
1600
- tickLower: this.tickLower,
1601
- tickUpper: this.tickUpper
1602
- }).amount1;
1603
- return {
1604
- amount0: amount0.quotient,
1605
- amount1: amount1.quotient
1606
- };
1607
- }
1608
- /**
1609
- * Returns the minimum amounts that must be sent in order to mint the amount of liquidity held by the position at
1610
- * the current price for the pool
1611
- */;
1612
- /**
1613
- * Returns the AllowanceTransferPermitBatch for adding liquidity to a position
1614
- * @param slippageTolerance The amount by which the price can 'slip' before the transaction will revert
1615
- * @param spender The spender of the permit (should usually be the PositionManager)
1616
- * @param nonce A valid permit2 nonce
1617
- * @param deadline The deadline for the permit
1618
- */
1619
- _proto.permitBatchData = function permitBatchData(slippageTolerance, spender, nonce, deadline) {
1620
- var _this$mintAmountsWith = this.mintAmountsWithSlippage(slippageTolerance),
1621
- amount0 = _this$mintAmountsWith.amount0,
1622
- amount1 = _this$mintAmountsWith.amount1;
1623
- return {
1624
- details: [{
1625
- token: this.pool.currency0.wrapped.address,
1626
- amount: amount0,
1627
- expiration: deadline,
1628
- nonce: nonce
1629
- }, {
1630
- token: this.pool.currency1.wrapped.address,
1631
- amount: amount1,
1632
- expiration: deadline,
1633
- nonce: nonce
1634
- }],
1635
- spender: spender,
1636
- sigDeadline: deadline
1637
- };
1638
- }
1639
- /**
1640
- * Computes the maximum amount of liquidity received for a given amount of token0, token1,
1641
- * and the prices at the tick boundaries.
1642
- * @param pool The pool for which the position should be created
1643
- * @param tickLower The lower tick of the position
1644
- * @param tickUpper The upper tick of the position
1645
- * @param amount0 token0 amountzw
1646
- * @param amount1 token1 amount
1647
- * @param useFullPrecision If false, liquidity will be maximized according to what the router can calculate,
1648
- * not what core can theoretically support
1649
- * @returns The amount of liquidity for the position
1650
- */;
1651
- Position.fromAmounts = function fromAmounts(_ref2) {
1652
- var pool = _ref2.pool,
1653
- tickLower = _ref2.tickLower,
1654
- tickUpper = _ref2.tickUpper,
1655
- amount0 = _ref2.amount0,
1656
- amount1 = _ref2.amount1,
1657
- useFullPrecision = _ref2.useFullPrecision;
1658
- var sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(tickLower);
1659
- var sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(tickUpper);
1660
- return new Position({
1661
- pool: pool,
1662
- tickLower: tickLower,
1663
- tickUpper: tickUpper,
1664
- liquidity: maxLiquidityForAmounts(pool.sqrtRatioX96, sqrtRatioAX96, sqrtRatioBX96, amount0, amount1, useFullPrecision)
1665
- });
1666
- }
1667
- /**
1668
- * Computes a position with the maximum amount of liquidity received for a given amount of token0, assuming an unlimited amount of token1
1669
- * @param pool The pool for which the position is created
1670
- * @param tickLower The lower tick
1671
- * @param tickUpper The upper tick
1672
- * @param amount0 The desired amount of token0
1673
- * @param useFullPrecision If true, liquidity will be maximized according to what the router can calculate,
1674
- * not what core can theoretically support
1675
- * @returns The position
1676
- */;
1677
- Position.fromAmount0 = function fromAmount0(_ref3) {
1678
- var pool = _ref3.pool,
1679
- tickLower = _ref3.tickLower,
1680
- tickUpper = _ref3.tickUpper,
1681
- amount0 = _ref3.amount0,
1682
- useFullPrecision = _ref3.useFullPrecision;
1683
- return Position.fromAmounts({
1684
- pool: pool,
1685
- tickLower: tickLower,
1686
- tickUpper: tickUpper,
1687
- amount0: amount0,
1688
- amount1: MaxUint256,
1689
- useFullPrecision: useFullPrecision
1690
- });
1691
- }
1692
- /**
1693
- * Computes a position with the maximum amount of liquidity received for a given amount of token1, assuming an unlimited amount of token0
1694
- * @param pool The pool for which the position is created
1695
- * @param tickLower The lower tick
1696
- * @param tickUpper The upper tick
1697
- * @param amount1 The desired amount of token1
1698
- * @returns The position
1699
- */;
1700
- Position.fromAmount1 = function fromAmount1(_ref4) {
1701
- var pool = _ref4.pool,
1702
- tickLower = _ref4.tickLower,
1703
- tickUpper = _ref4.tickUpper,
1704
- amount1 = _ref4.amount1;
1705
- // this function always uses full precision,
1706
- return Position.fromAmounts({
1707
- pool: pool,
1708
- tickLower: tickLower,
1709
- tickUpper: tickUpper,
1710
- amount0: MaxUint256,
1711
- amount1: amount1,
1712
- useFullPrecision: true
1713
- });
1714
- };
1715
- return _createClass(Position, [{
1716
- key: "token0PriceLower",
1717
- get: function get() {
1718
- return tickToPrice(this.pool.currency0, this.pool.currency1, this.tickLower);
1719
- }
1720
- /**
1721
- * Returns the price of token0 at the upper tick
1722
- */
1723
- }, {
1724
- key: "token0PriceUpper",
1725
- get: function get() {
1726
- return tickToPrice(this.pool.currency0, this.pool.currency1, this.tickUpper);
1727
- }
1728
- /**
1729
- * Returns the amount of token0 that this position's liquidity could be burned for at the current pool price
1730
- */
1731
- }, {
1732
- key: "amount0",
1733
- get: function get() {
1734
- if (!this._token0Amount) {
1735
- if (this.pool.tickCurrent < this.tickLower) {
1736
- this._token0Amount = CurrencyAmount.fromRawAmount(this.pool.currency0, SqrtPriceMath.getAmount0Delta(TickMath.getSqrtRatioAtTick(this.tickLower), TickMath.getSqrtRatioAtTick(this.tickUpper), this.liquidity, false));
1737
- } else if (this.pool.tickCurrent < this.tickUpper) {
1738
- this._token0Amount = CurrencyAmount.fromRawAmount(this.pool.currency0, SqrtPriceMath.getAmount0Delta(this.pool.sqrtRatioX96, TickMath.getSqrtRatioAtTick(this.tickUpper), this.liquidity, false));
1739
- } else {
1740
- this._token0Amount = CurrencyAmount.fromRawAmount(this.pool.currency0, ZERO);
1741
- }
1742
- }
1743
- return this._token0Amount;
1744
- }
1745
- /**
1746
- * Returns the amount of token1 that this position's liquidity could be burned for at the current pool price
1747
- */
1748
- }, {
1749
- key: "amount1",
1750
- get: function get() {
1751
- if (!this._token1Amount) {
1752
- if (this.pool.tickCurrent < this.tickLower) {
1753
- this._token1Amount = CurrencyAmount.fromRawAmount(this.pool.currency1, ZERO);
1754
- } else if (this.pool.tickCurrent < this.tickUpper) {
1755
- this._token1Amount = CurrencyAmount.fromRawAmount(this.pool.currency1, SqrtPriceMath.getAmount1Delta(TickMath.getSqrtRatioAtTick(this.tickLower), this.pool.sqrtRatioX96, this.liquidity, false));
1756
- } else {
1757
- this._token1Amount = CurrencyAmount.fromRawAmount(this.pool.currency1, SqrtPriceMath.getAmount1Delta(TickMath.getSqrtRatioAtTick(this.tickLower), TickMath.getSqrtRatioAtTick(this.tickUpper), this.liquidity, false));
1758
- }
1759
- }
1760
- return this._token1Amount;
1761
- }
1762
- }, {
1763
- key: "mintAmounts",
1764
- get: function get() {
1765
- if (this._mintAmounts === null) {
1766
- if (this.pool.tickCurrent < this.tickLower) {
1767
- return {
1768
- amount0: SqrtPriceMath.getAmount0Delta(TickMath.getSqrtRatioAtTick(this.tickLower), TickMath.getSqrtRatioAtTick(this.tickUpper), this.liquidity, true),
1769
- amount1: ZERO
1770
- };
1771
- } else if (this.pool.tickCurrent < this.tickUpper) {
1772
- return {
1773
- amount0: SqrtPriceMath.getAmount0Delta(this.pool.sqrtRatioX96, TickMath.getSqrtRatioAtTick(this.tickUpper), this.liquidity, true),
1774
- amount1: SqrtPriceMath.getAmount1Delta(TickMath.getSqrtRatioAtTick(this.tickLower), this.pool.sqrtRatioX96, this.liquidity, true)
1775
- };
1776
- } else {
1777
- return {
1778
- amount0: ZERO,
1779
- amount1: SqrtPriceMath.getAmount1Delta(TickMath.getSqrtRatioAtTick(this.tickLower), TickMath.getSqrtRatioAtTick(this.tickUpper), this.liquidity, true)
1780
- };
1781
- }
1782
- }
1783
- return this._mintAmounts;
1784
- }
1785
- }]);
1786
- }();
1787
-
1788
- var encodeRouteToPath = function encodeRouteToPath(route, exactOutput) {
1789
- // create a deep copy of pools so that we don't tamper with pool array on route
1790
- var pools = route.pools.map(function (p) {
1791
- return p;
1792
- });
1793
- if (exactOutput) pools = pools.reverse();
1794
- var startingCurrency = exactOutput ? route.pathOutput : route.pathInput;
1795
- var pathKeys = [];
1796
- for (var _iterator = _createForOfIteratorHelperLoose(pools), _step; !(_step = _iterator()).done;) {
1797
- var pool = _step.value;
1798
- var nextCurrency = startingCurrency.equals(pool.currency0) ? pool.currency1 : pool.currency0;
1799
- pathKeys.push({
1800
- intermediateCurrency: nextCurrency.isNative ? ADDRESS_ZERO : nextCurrency.address,
1801
- fee: pool.fee,
1802
- tickSpacing: pool.tickSpacing,
1803
- hooks: pool.hooks,
1804
- hookData: '0x'
1805
- });
1806
- startingCurrency = nextCurrency;
1807
- }
1808
- return exactOutput ? pathKeys.reverse() : pathKeys;
1809
- };
1810
-
1811
- var _V4_BASE_ACTIONS_ABI_;
1812
- /**
1813
- * Actions
1814
- * @description Constants that define what action to perform
1815
- * Not all actions are supported yet.
1816
- * @enum {number}
1817
- */
1818
- var Actions;
1819
- (function (Actions) {
1820
- // pool actions
1821
- // liquidity actions
1822
- Actions[Actions["INCREASE_LIQUIDITY"] = 0] = "INCREASE_LIQUIDITY";
1823
- Actions[Actions["DECREASE_LIQUIDITY"] = 1] = "DECREASE_LIQUIDITY";
1824
- Actions[Actions["MINT_POSITION"] = 2] = "MINT_POSITION";
1825
- Actions[Actions["BURN_POSITION"] = 3] = "BURN_POSITION";
1826
- // for fee on transfer tokens
1827
- // INCREASE_LIQUIDITY_FROM_DELTAS = 0x04,
1828
- // MINT_POSITION_FROM_DELTAS = 0x05,
1829
- // swapping
1830
- Actions[Actions["SWAP_EXACT_IN_SINGLE"] = 6] = "SWAP_EXACT_IN_SINGLE";
1831
- Actions[Actions["SWAP_EXACT_IN"] = 7] = "SWAP_EXACT_IN";
1832
- Actions[Actions["SWAP_EXACT_OUT_SINGLE"] = 8] = "SWAP_EXACT_OUT_SINGLE";
1833
- Actions[Actions["SWAP_EXACT_OUT"] = 9] = "SWAP_EXACT_OUT";
1834
- // closing deltas on the pool manager
1835
- // settling
1836
- Actions[Actions["SETTLE"] = 11] = "SETTLE";
1837
- Actions[Actions["SETTLE_ALL"] = 12] = "SETTLE_ALL";
1838
- Actions[Actions["SETTLE_PAIR"] = 13] = "SETTLE_PAIR";
1839
- // taking
1840
- Actions[Actions["TAKE"] = 14] = "TAKE";
1841
- Actions[Actions["TAKE_ALL"] = 15] = "TAKE_ALL";
1842
- Actions[Actions["TAKE_PORTION"] = 16] = "TAKE_PORTION";
1843
- Actions[Actions["TAKE_PAIR"] = 17] = "TAKE_PAIR";
1844
- Actions[Actions["CLOSE_CURRENCY"] = 18] = "CLOSE_CURRENCY";
1845
- // CLEAR_OR_TAKE = 0x13,
1846
- Actions[Actions["SWEEP"] = 20] = "SWEEP";
1847
- // for wrapping/unwrapping native
1848
- // WRAP = 0x15,
1849
- Actions[Actions["UNWRAP"] = 22] = "UNWRAP";
1850
- })(Actions || (Actions = {}));
1851
- var Subparser;
1852
- (function (Subparser) {
1853
- Subparser[Subparser["V4SwapExactInSingle"] = 0] = "V4SwapExactInSingle";
1854
- Subparser[Subparser["V4SwapExactIn"] = 1] = "V4SwapExactIn";
1855
- Subparser[Subparser["V4SwapExactOutSingle"] = 2] = "V4SwapExactOutSingle";
1856
- Subparser[Subparser["V4SwapExactOut"] = 3] = "V4SwapExactOut";
1857
- Subparser[Subparser["PoolKey"] = 4] = "PoolKey";
1858
- })(Subparser || (Subparser = {}));
1859
- var POOL_KEY_STRUCT = '(address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks)';
1860
- var PATH_KEY_STRUCT = '(address intermediateCurrency,uint256 fee,int24 tickSpacing,address hooks,bytes hookData)';
1861
- var SWAP_EXACT_IN_SINGLE_STRUCT = '(' + POOL_KEY_STRUCT + ' poolKey,bool zeroForOne,uint128 amountIn,uint128 amountOutMinimum,bytes hookData)';
1862
- var SWAP_EXACT_IN_STRUCT = '(address currencyIn,' + PATH_KEY_STRUCT + '[] path,uint128 amountIn,uint128 amountOutMinimum)';
1863
- var SWAP_EXACT_OUT_SINGLE_STRUCT = '(' + POOL_KEY_STRUCT + ' poolKey,bool zeroForOne,uint128 amountOut,uint128 amountInMaximum,bytes hookData)';
1864
- var SWAP_EXACT_OUT_STRUCT = '(address currencyOut,' + PATH_KEY_STRUCT + '[] path,uint128 amountOut,uint128 amountInMaximum)';
1865
- var V4_BASE_ACTIONS_ABI_DEFINITION = (_V4_BASE_ACTIONS_ABI_ = {}, _V4_BASE_ACTIONS_ABI_[Actions.INCREASE_LIQUIDITY] = [{
1866
- name: 'tokenId',
1867
- type: 'uint256'
1868
- }, {
1869
- name: 'liquidity',
1870
- type: 'uint256'
1871
- }, {
1872
- name: 'amount0Max',
1873
- type: 'uint128'
1874
- }, {
1875
- name: 'amount1Max',
1876
- type: 'uint128'
1877
- }, {
1878
- name: 'hookData',
1879
- type: 'bytes'
1880
- }], _V4_BASE_ACTIONS_ABI_[Actions.DECREASE_LIQUIDITY] = [{
1881
- name: 'tokenId',
1882
- type: 'uint256'
1883
- }, {
1884
- name: 'liquidity',
1885
- type: 'uint256'
1886
- }, {
1887
- name: 'amount0Min',
1888
- type: 'uint128'
1889
- }, {
1890
- name: 'amount1Min',
1891
- type: 'uint128'
1892
- }, {
1893
- name: 'hookData',
1894
- type: 'bytes'
1895
- }], _V4_BASE_ACTIONS_ABI_[Actions.MINT_POSITION] = [{
1896
- name: 'poolKey',
1897
- type: POOL_KEY_STRUCT,
1898
- subparser: Subparser.PoolKey
1899
- }, {
1900
- name: 'tickLower',
1901
- type: 'int24'
1902
- }, {
1903
- name: 'tickUpper',
1904
- type: 'int24'
1905
- }, {
1906
- name: 'liquidity',
1907
- type: 'uint256'
1908
- }, {
1909
- name: 'amount0Max',
1910
- type: 'uint128'
1911
- }, {
1912
- name: 'amount1Max',
1913
- type: 'uint128'
1914
- }, {
1915
- name: 'owner',
1916
- type: 'address'
1917
- }, {
1918
- name: 'hookData',
1919
- type: 'bytes'
1920
- }], _V4_BASE_ACTIONS_ABI_[Actions.BURN_POSITION] = [{
1921
- name: 'tokenId',
1922
- type: 'uint256'
1923
- }, {
1924
- name: 'amount0Min',
1925
- type: 'uint128'
1926
- }, {
1927
- name: 'amount1Min',
1928
- type: 'uint128'
1929
- }, {
1930
- name: 'hookData',
1931
- type: 'bytes'
1932
- }], _V4_BASE_ACTIONS_ABI_[Actions.SWAP_EXACT_IN_SINGLE] = [{
1933
- name: 'swap',
1934
- type: SWAP_EXACT_IN_SINGLE_STRUCT,
1935
- subparser: Subparser.V4SwapExactInSingle
1936
- }], _V4_BASE_ACTIONS_ABI_[Actions.SWAP_EXACT_IN] = [{
1937
- name: 'swap',
1938
- type: SWAP_EXACT_IN_STRUCT,
1939
- subparser: Subparser.V4SwapExactIn
1940
- }], _V4_BASE_ACTIONS_ABI_[Actions.SWAP_EXACT_OUT_SINGLE] = [{
1941
- name: 'swap',
1942
- type: SWAP_EXACT_OUT_SINGLE_STRUCT,
1943
- subparser: Subparser.V4SwapExactOutSingle
1944
- }], _V4_BASE_ACTIONS_ABI_[Actions.SWAP_EXACT_OUT] = [{
1945
- name: 'swap',
1946
- type: SWAP_EXACT_OUT_STRUCT,
1947
- subparser: Subparser.V4SwapExactOut
1948
- }], _V4_BASE_ACTIONS_ABI_[Actions.SETTLE] = [{
1949
- name: 'currency',
1950
- type: 'address'
1951
- }, {
1952
- name: 'amount',
1953
- type: 'uint256'
1954
- }, {
1955
- name: 'payerIsUser',
1956
- type: 'bool'
1957
- }], _V4_BASE_ACTIONS_ABI_[Actions.SETTLE_ALL] = [{
1958
- name: 'currency',
1959
- type: 'address'
1960
- }, {
1961
- name: 'maxAmount',
1962
- type: 'uint256'
1963
- }], _V4_BASE_ACTIONS_ABI_[Actions.SETTLE_PAIR] = [{
1964
- name: 'currency0',
1965
- type: 'address'
1966
- }, {
1967
- name: 'currency1',
1968
- type: 'address'
1969
- }], _V4_BASE_ACTIONS_ABI_[Actions.TAKE] = [{
1970
- name: 'currency',
1971
- type: 'address'
1972
- }, {
1973
- name: 'recipient',
1974
- type: 'address'
1975
- }, {
1976
- name: 'amount',
1977
- type: 'uint256'
1978
- }], _V4_BASE_ACTIONS_ABI_[Actions.TAKE_ALL] = [{
1979
- name: 'currency',
1980
- type: 'address'
1981
- }, {
1982
- name: 'minAmount',
1983
- type: 'uint256'
1984
- }], _V4_BASE_ACTIONS_ABI_[Actions.TAKE_PORTION] = [{
1985
- name: 'currency',
1986
- type: 'address'
1987
- }, {
1988
- name: 'recipient',
1989
- type: 'address'
1990
- }, {
1991
- name: 'bips',
1992
- type: 'uint256'
1993
- }], _V4_BASE_ACTIONS_ABI_[Actions.TAKE_PAIR] = [{
1994
- name: 'currency0',
1995
- type: 'address'
1996
- }, {
1997
- name: 'currency1',
1998
- type: 'address'
1999
- }, {
2000
- name: 'recipient',
2001
- type: 'address'
2002
- }], _V4_BASE_ACTIONS_ABI_[Actions.CLOSE_CURRENCY] = [{
2003
- name: 'currency',
2004
- type: 'address'
2005
- }], _V4_BASE_ACTIONS_ABI_[Actions.SWEEP] = [{
2006
- name: 'currency',
2007
- type: 'address'
2008
- }, {
2009
- name: 'recipient',
2010
- type: 'address'
2011
- }], _V4_BASE_ACTIONS_ABI_[Actions.UNWRAP] = [{
2012
- name: 'amount',
2013
- type: 'uint256'
2014
- }], _V4_BASE_ACTIONS_ABI_);
2015
- var FULL_DELTA_AMOUNT = 0;
2016
- var V4Planner = /*#__PURE__*/function () {
2017
- function V4Planner() {
2018
- this.actions = EMPTY_BYTES;
2019
- this.params = [];
2020
- }
2021
- var _proto = V4Planner.prototype;
2022
- _proto.addAction = function addAction(type, parameters) {
2023
- var command = createAction(type, parameters);
2024
- this.params.push(command.encodedInput);
2025
- this.actions = this.actions.concat(command.action.toString(16).padStart(2, '0'));
2026
- return this;
2027
- };
2028
- _proto.addTrade = function addTrade(trade, slippageTolerance) {
2029
- var exactOutput = trade.tradeType === TradeType.EXACT_OUTPUT;
2030
- // exactInput we sometimes perform aggregated slippage checks, but not with exactOutput
2031
- if (exactOutput) !!!slippageTolerance ? process.env.NODE_ENV !== "production" ? invariant(false, 'ExactOut requires slippageTolerance') : invariant(false) : void 0;
2032
- !(trade.swaps.length === 1) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Only accepts Trades with 1 swap (must break swaps into individual trades)') : invariant(false) : void 0;
2033
- var actionType = exactOutput ? Actions.SWAP_EXACT_OUT : Actions.SWAP_EXACT_IN;
2034
- var currencyIn = currencyAddress(trade.route.pathInput);
2035
- var currencyOut = currencyAddress(trade.route.pathOutput);
2036
- this.addAction(actionType, [exactOutput ? {
2037
- currencyOut: currencyOut,
2038
- path: encodeRouteToPath(trade.route, exactOutput),
2039
- amountInMaximum: trade.maximumAmountIn(slippageTolerance != null ? slippageTolerance : new Percent(0)).quotient.toString(),
2040
- amountOut: trade.outputAmount.quotient.toString()
2041
- } : {
2042
- currencyIn: currencyIn,
2043
- path: encodeRouteToPath(trade.route, exactOutput),
2044
- amountIn: trade.inputAmount.quotient.toString(),
2045
- amountOutMinimum: slippageTolerance ? trade.minimumAmountOut(slippageTolerance).quotient.toString() : 0
2046
- }]);
2047
- return this;
2048
- };
2049
- _proto.addSettle = function addSettle(currency, payerIsUser, amount) {
2050
- this.addAction(Actions.SETTLE, [currencyAddress(currency), amount != null ? amount : FULL_DELTA_AMOUNT, payerIsUser]);
2051
- return this;
2052
- };
2053
- _proto.addTake = function addTake(currency, recipient, amount) {
2054
- var takeAmount = amount != null ? amount : FULL_DELTA_AMOUNT;
2055
- this.addAction(Actions.TAKE, [currencyAddress(currency), recipient, takeAmount]);
2056
- return this;
2057
- };
2058
- _proto.addUnwrap = function addUnwrap(amount) {
2059
- this.addAction(Actions.UNWRAP, [amount]);
2060
- return this;
2061
- };
2062
- _proto.finalize = function finalize() {
2063
- return defaultAbiCoder.encode(['bytes', 'bytes[]'], [this.actions, this.params]);
2064
- };
2065
- return V4Planner;
2066
- }();
2067
- function currencyAddress(currency) {
2068
- return currency.isNative ? ADDRESS_ZERO : currency.wrapped.address;
2069
- }
2070
- function createAction(action, parameters) {
2071
- var encodedInput = defaultAbiCoder.encode(V4_BASE_ACTIONS_ABI_DEFINITION[action].map(function (v) {
2072
- return v.type;
2073
- }), parameters);
2074
- return {
2075
- action: action,
2076
- encodedInput: encodedInput
2077
- };
2078
- }
2079
-
2080
- // Uniswap v4 supports native pools. Those currencies are represented by the zero address.
2081
- // TODO: Figure out if this is how we should be handling weird edge case tokens like CELO/Polygon/etc..
2082
- // Does interface treat those like ERC20 tokens or NATIVE tokens?
2083
- function toAddress(currency) {
2084
- if (currency.isNative) return ADDRESS_ZERO;else return currency.wrapped.address;
2085
- }
2086
-
2087
- // A wrapper around V4Planner to help handle PositionManager actions
2088
- var V4PositionPlanner = /*#__PURE__*/function (_V4Planner) {
2089
- function V4PositionPlanner() {
2090
- return _V4Planner.apply(this, arguments) || this;
2091
- }
2092
- _inheritsLoose(V4PositionPlanner, _V4Planner);
2093
- var _proto = V4PositionPlanner.prototype;
2094
- // MINT_POSITION
2095
- _proto.addMint = function addMint(pool, tickLower, tickUpper, liquidity, amount0Max, amount1Max, owner, hookData) {
2096
- if (hookData === void 0) {
2097
- hookData = EMPTY_BYTES;
2098
- }
2099
- var inputs = [Pool.getPoolKey(pool.currency0, pool.currency1, pool.fee, pool.tickSpacing, pool.hooks), tickLower, tickUpper, liquidity.toString(), amount0Max.toString(), amount1Max.toString(), owner, hookData];
2100
- this.addAction(Actions.MINT_POSITION, inputs);
2101
- }
2102
- // INCREASE_LIQUIDITY
2103
- ;
2104
- _proto.addIncrease = function addIncrease(tokenId, liquidity, amount0Max, amount1Max, hookData) {
2105
- if (hookData === void 0) {
2106
- hookData = EMPTY_BYTES;
2107
- }
2108
- var inputs = [tokenId.toString(), liquidity.toString(), amount0Max.toString(), amount1Max.toString(), hookData];
2109
- this.addAction(Actions.INCREASE_LIQUIDITY, inputs);
2110
- }
2111
- // DECREASE_LIQUIDITY
2112
- ;
2113
- _proto.addDecrease = function addDecrease(tokenId, liquidity, amount0Min, amount1Min, hookData) {
2114
- if (hookData === void 0) {
2115
- hookData = EMPTY_BYTES;
2116
- }
2117
- var inputs = [tokenId.toString(), liquidity.toString(), amount0Min.toString(), amount1Min.toString(), hookData];
2118
- this.addAction(Actions.DECREASE_LIQUIDITY, inputs);
2119
- }
2120
- // BURN_POSITION
2121
- ;
2122
- _proto.addBurn = function addBurn(tokenId, amount0Min, amount1Min, hookData) {
2123
- if (hookData === void 0) {
2124
- hookData = EMPTY_BYTES;
2125
- }
2126
- var inputs = [tokenId.toString(), amount0Min.toString(), amount1Min.toString(), hookData];
2127
- this.addAction(Actions.BURN_POSITION, inputs);
2128
- }
2129
- // SETTLE_PAIR
2130
- ;
2131
- _proto.addSettlePair = function addSettlePair(currency0, currency1) {
2132
- var inputs = [toAddress(currency0), toAddress(currency1)];
2133
- this.addAction(Actions.SETTLE_PAIR, inputs);
2134
- }
2135
- // TAKE_PAIR
2136
- ;
2137
- _proto.addTakePair = function addTakePair(currency0, currency1, recipient) {
2138
- var inputs = [toAddress(currency0), toAddress(currency1), recipient];
2139
- this.addAction(Actions.TAKE_PAIR, inputs);
2140
- }
2141
- // SWEEP
2142
- ;
2143
- _proto.addSweep = function addSweep(currency, to) {
2144
- var inputs = [toAddress(currency), to];
2145
- this.addAction(Actions.SWEEP, inputs);
2146
- };
2147
- return V4PositionPlanner;
2148
- }(V4Planner);
2149
-
2150
- /**
2151
- * Converts a big int to a hex string
2152
- * @param bigintIsh
2153
- * @returns The hex encoded calldata
2154
- */
2155
- function toHex(bigintIsh) {
2156
- var bigInt = JSBI.BigInt(bigintIsh);
2157
- var hex = bigInt.toString(16);
2158
- if (hex.length % 2 !== 0) {
2159
- hex = "0" + hex;
2160
- }
2161
- return "0x" + hex;
2162
- }
2163
-
2164
- // Parses V4Router actions
2165
- var V4BaseActionsParser = /*#__PURE__*/function () {
2166
- function V4BaseActionsParser() {}
2167
- V4BaseActionsParser.parseCalldata = function parseCalldata(calldata) {
2168
- var _ethers$utils$default = ethers.utils.defaultAbiCoder.decode(['bytes', 'bytes[]'], calldata),
2169
- actions = _ethers$utils$default[0],
2170
- inputs = _ethers$utils$default[1];
2171
- var actionTypes = V4BaseActionsParser.getActions(actions);
2172
- return {
2173
- actions: actionTypes.map(function (actionType, i) {
2174
- var abiDef = V4_BASE_ACTIONS_ABI_DEFINITION[actionType];
2175
- var rawParams = ethers.utils.defaultAbiCoder.decode(abiDef.map(function (command) {
2176
- return command.type;
2177
- }), inputs[i]);
2178
- var params = rawParams.map(function (param, j) {
2179
- switch (abiDef[j].subparser) {
2180
- case Subparser.V4SwapExactInSingle:
2181
- return {
2182
- name: abiDef[j].name,
2183
- value: parseV4ExactInSingle(param)
2184
- };
2185
- case Subparser.V4SwapExactIn:
2186
- return {
2187
- name: abiDef[j].name,
2188
- value: parseV4ExactIn(param)
2189
- };
2190
- case Subparser.V4SwapExactOutSingle:
2191
- return {
2192
- name: abiDef[j].name,
2193
- value: parseV4ExactOutSingle(param)
2194
- };
2195
- case Subparser.V4SwapExactOut:
2196
- return {
2197
- name: abiDef[j].name,
2198
- value: parseV4ExactOut(param)
2199
- };
2200
- case Subparser.PoolKey:
2201
- return {
2202
- name: abiDef[j].name,
2203
- value: parsePoolKey(param)
2204
- };
2205
- default:
2206
- return {
2207
- name: abiDef[j].name,
2208
- value: param
2209
- };
2210
- }
2211
- });
2212
- return {
2213
- actionName: Actions[actionType],
2214
- actionType: actionType,
2215
- params: params
2216
- };
2217
- })
2218
- };
2219
- }
2220
- // parse command types from bytes string
2221
- ;
2222
- V4BaseActionsParser.getActions = function getActions(actions) {
2223
- var actionTypes = [];
2224
- for (var i = 2; i < actions.length; i += 2) {
2225
- var _byte = actions.substring(i, i + 2);
2226
- actionTypes.push(parseInt(_byte, 16));
2227
- }
2228
- return actionTypes;
2229
- };
2230
- return V4BaseActionsParser;
2231
- }();
2232
- function parsePoolKey(data) {
2233
- var currency0 = data[0],
2234
- currency1 = data[1],
2235
- fee = data[2],
2236
- tickSpacing = data[3],
2237
- hooks = data[4];
2238
- return {
2239
- currency0: currency0,
2240
- currency1: currency1,
2241
- fee: parseInt(fee),
2242
- tickSpacing: parseInt(tickSpacing),
2243
- hooks: hooks
2244
- };
2245
- }
2246
- function parsePathKey(data) {
2247
- var intermediateCurrency = data[0],
2248
- fee = data[1],
2249
- tickSpacing = data[2],
2250
- hooks = data[3],
2251
- hookData = data[4];
2252
- return {
2253
- intermediateCurrency: intermediateCurrency,
2254
- fee: parseInt(fee),
2255
- tickSpacing: parseInt(tickSpacing),
2256
- hooks: hooks,
2257
- hookData: hookData
2258
- };
2259
- }
2260
- function parseV4ExactInSingle(data) {
2261
- var poolKey = data[0],
2262
- zeroForOne = data[1],
2263
- amountIn = data[2],
2264
- amountOutMinimum = data[3],
2265
- hookData = data[4];
2266
- var currency0 = poolKey[0],
2267
- currency1 = poolKey[1],
2268
- fee = poolKey[2],
2269
- tickSpacing = poolKey[3],
2270
- hooks = poolKey[4];
2271
- return {
2272
- poolKey: {
2273
- currency0: currency0,
2274
- currency1: currency1,
2275
- fee: fee,
2276
- tickSpacing: tickSpacing,
2277
- hooks: hooks
2278
- },
2279
- zeroForOne: zeroForOne,
2280
- amountIn: amountIn,
2281
- amountOutMinimum: amountOutMinimum,
2282
- hookData: hookData
2283
- };
2284
- }
2285
- function parseV4ExactIn(data) {
2286
- var currencyIn = data[0],
2287
- path = data[1],
2288
- amountIn = data[2],
2289
- amountOutMinimum = data[3];
2290
- var paths = path.map(function (pathKey) {
2291
- return parsePathKey(pathKey);
2292
- });
2293
- return {
2294
- path: paths,
2295
- currencyIn: currencyIn,
2296
- amountIn: amountIn,
2297
- amountOutMinimum: amountOutMinimum
2298
- };
2299
- }
2300
- function parseV4ExactOutSingle(data) {
2301
- var poolKey = data[0],
2302
- zeroForOne = data[1],
2303
- amountOut = data[2],
2304
- amountInMaximum = data[3],
2305
- hookData = data[4];
2306
- var currency0 = poolKey.currency0,
2307
- currency1 = poolKey.currency1,
2308
- fee = poolKey.fee,
2309
- tickSpacing = poolKey.tickSpacing,
2310
- hooks = poolKey.hooks;
2311
- return {
2312
- poolKey: {
2313
- currency0: currency0,
2314
- currency1: currency1,
2315
- fee: fee,
2316
- tickSpacing: tickSpacing,
2317
- hooks: hooks
2318
- },
2319
- zeroForOne: zeroForOne,
2320
- amountOut: amountOut,
2321
- amountInMaximum: amountInMaximum,
2322
- hookData: hookData
2323
- };
2324
- }
2325
- function parseV4ExactOut(data) {
2326
- var currencyOut = data[0],
2327
- path = data[1],
2328
- amountOut = data[2],
2329
- amountInMaximum = data[3];
2330
- var paths = path.map(function (pathKey) {
2331
- return parsePathKey(pathKey);
2332
- });
2333
- return {
2334
- path: paths,
2335
- currencyOut: currencyOut,
2336
- amountOut: amountOut,
2337
- amountInMaximum: amountInMaximum
2338
- };
2339
- }
2340
-
2341
- // Shared Action Constants used in the v4 Router and v4 position manager
2342
- var MSG_SENDER = '0x0000000000000000000000000000000000000001';
2343
-
2344
- var Multicall = /*#__PURE__*/function () {
2345
- /**
2346
- * Cannot be constructed.
2347
- */
2348
- function Multicall() {}
2349
- Multicall.encodeMulticall = function encodeMulticall(calldataList) {
2350
- if (!Array.isArray(calldataList)) {
2351
- calldataList = [calldataList];
2352
- }
2353
- return calldataList.length === 1 ? calldataList[0] : Multicall.INTERFACE.encodeFunctionData('multicall', [calldataList]);
2354
- };
2355
- Multicall.decodeMulticall = function decodeMulticall(encodedCalldata) {
2356
- return Multicall.INTERFACE.decodeFunctionData('multicall', encodedCalldata)[0];
2357
- };
2358
- return Multicall;
2359
- }();
2360
- Multicall.INTERFACE = /*#__PURE__*/new Interface(IMulticall.abi);
2361
-
2362
- // TODO: import this from npm
2363
- var positionManagerAbi = [{
2364
- type: 'constructor',
2365
- inputs: [{
2366
- name: '_poolManager',
2367
- type: 'address',
2368
- internalType: 'contract IPoolManager'
2369
- }, {
2370
- name: '_permit2',
2371
- type: 'address',
2372
- internalType: 'contract IAllowanceTransfer'
2373
- }, {
2374
- name: '_unsubscribeGasLimit',
2375
- type: 'uint256',
2376
- internalType: 'uint256'
2377
- }, {
2378
- name: '_tokenDescriptor',
2379
- type: 'address',
2380
- internalType: 'contract IPositionDescriptor'
2381
- }, {
2382
- name: '_weth9',
2383
- type: 'address',
2384
- internalType: 'contract IWETH9'
2385
- }],
2386
- stateMutability: 'nonpayable'
2387
- }, {
2388
- type: 'receive',
2389
- stateMutability: 'payable'
2390
- }, {
2391
- type: 'function',
2392
- name: 'DOMAIN_SEPARATOR',
2393
- inputs: [],
2394
- outputs: [{
2395
- name: '',
2396
- type: 'bytes32',
2397
- internalType: 'bytes32'
2398
- }],
2399
- stateMutability: 'view'
2400
- }, {
2401
- type: 'function',
2402
- name: 'WETH9',
2403
- inputs: [],
2404
- outputs: [{
2405
- name: '',
2406
- type: 'address',
2407
- internalType: 'contract IWETH9'
2408
- }],
2409
- stateMutability: 'view'
2410
- }, {
2411
- type: 'function',
2412
- name: 'approve',
2413
- inputs: [{
2414
- name: 'spender',
2415
- type: 'address',
2416
- internalType: 'address'
2417
- }, {
2418
- name: 'id',
2419
- type: 'uint256',
2420
- internalType: 'uint256'
2421
- }],
2422
- outputs: [],
2423
- stateMutability: 'nonpayable'
2424
- }, {
2425
- type: 'function',
2426
- name: 'balanceOf',
2427
- inputs: [{
2428
- name: 'owner',
2429
- type: 'address',
2430
- internalType: 'address'
2431
- }],
2432
- outputs: [{
2433
- name: '',
2434
- type: 'uint256',
2435
- internalType: 'uint256'
2436
- }],
2437
- stateMutability: 'view'
2438
- }, {
2439
- type: 'function',
2440
- name: 'getApproved',
2441
- inputs: [{
2442
- name: '',
2443
- type: 'uint256',
2444
- internalType: 'uint256'
2445
- }],
2446
- outputs: [{
2447
- name: '',
2448
- type: 'address',
2449
- internalType: 'address'
2450
- }],
2451
- stateMutability: 'view'
2452
- }, {
2453
- type: 'function',
2454
- name: 'getPoolAndPositionInfo',
2455
- inputs: [{
2456
- name: 'tokenId',
2457
- type: 'uint256',
2458
- internalType: 'uint256'
2459
- }],
2460
- outputs: [{
2461
- name: 'poolKey',
2462
- type: 'tuple',
2463
- internalType: 'struct PoolKey',
2464
- components: [{
2465
- name: 'currency0',
2466
- type: 'address',
2467
- internalType: 'Currency'
2468
- }, {
2469
- name: 'currency1',
2470
- type: 'address',
2471
- internalType: 'Currency'
2472
- }, {
2473
- name: 'fee',
2474
- type: 'uint24',
2475
- internalType: 'uint24'
2476
- }, {
2477
- name: 'tickSpacing',
2478
- type: 'int24',
2479
- internalType: 'int24'
2480
- }, {
2481
- name: 'hooks',
2482
- type: 'address',
2483
- internalType: 'contract IHooks'
2484
- }]
2485
- }, {
2486
- name: 'info',
2487
- type: 'uint256',
2488
- internalType: 'PositionInfo'
2489
- }],
2490
- stateMutability: 'view'
2491
- }, {
2492
- type: 'function',
2493
- name: 'getPositionLiquidity',
2494
- inputs: [{
2495
- name: 'tokenId',
2496
- type: 'uint256',
2497
- internalType: 'uint256'
2498
- }],
2499
- outputs: [{
2500
- name: 'liquidity',
2501
- type: 'uint128',
2502
- internalType: 'uint128'
2503
- }],
2504
- stateMutability: 'view'
2505
- }, {
2506
- type: 'function',
2507
- name: 'initializePool',
2508
- inputs: [{
2509
- name: 'key',
2510
- type: 'tuple',
2511
- internalType: 'struct PoolKey',
2512
- components: [{
2513
- name: 'currency0',
2514
- type: 'address',
2515
- internalType: 'Currency'
2516
- }, {
2517
- name: 'currency1',
2518
- type: 'address',
2519
- internalType: 'Currency'
2520
- }, {
2521
- name: 'fee',
2522
- type: 'uint24',
2523
- internalType: 'uint24'
2524
- }, {
2525
- name: 'tickSpacing',
2526
- type: 'int24',
2527
- internalType: 'int24'
2528
- }, {
2529
- name: 'hooks',
2530
- type: 'address',
2531
- internalType: 'contract IHooks'
2532
- }]
2533
- }, {
2534
- name: 'sqrtPriceX96',
2535
- type: 'uint160',
2536
- internalType: 'uint160'
2537
- }],
2538
- outputs: [{
2539
- name: '',
2540
- type: 'int24',
2541
- internalType: 'int24'
2542
- }],
2543
- stateMutability: 'payable'
2544
- }, {
2545
- type: 'function',
2546
- name: 'isApprovedForAll',
2547
- inputs: [{
2548
- name: '',
2549
- type: 'address',
2550
- internalType: 'address'
2551
- }, {
2552
- name: '',
2553
- type: 'address',
2554
- internalType: 'address'
2555
- }],
2556
- outputs: [{
2557
- name: '',
2558
- type: 'bool',
2559
- internalType: 'bool'
2560
- }],
2561
- stateMutability: 'view'
2562
- }, {
2563
- type: 'function',
2564
- name: 'modifyLiquidities',
2565
- inputs: [{
2566
- name: 'unlockData',
2567
- type: 'bytes',
2568
- internalType: 'bytes'
2569
- }, {
2570
- name: 'deadline',
2571
- type: 'uint256',
2572
- internalType: 'uint256'
2573
- }],
2574
- outputs: [],
2575
- stateMutability: 'payable'
2576
- }, {
2577
- type: 'function',
2578
- name: 'modifyLiquiditiesWithoutUnlock',
2579
- inputs: [{
2580
- name: 'actions',
2581
- type: 'bytes',
2582
- internalType: 'bytes'
2583
- }, {
2584
- name: 'params',
2585
- type: 'bytes[]',
2586
- internalType: 'bytes[]'
2587
- }],
2588
- outputs: [],
2589
- stateMutability: 'payable'
2590
- }, {
2591
- type: 'function',
2592
- name: 'msgSender',
2593
- inputs: [],
2594
- outputs: [{
2595
- name: '',
2596
- type: 'address',
2597
- internalType: 'address'
2598
- }],
2599
- stateMutability: 'view'
2600
- }, {
2601
- type: 'function',
2602
- name: 'multicall',
2603
- inputs: [{
2604
- name: 'data',
2605
- type: 'bytes[]',
2606
- internalType: 'bytes[]'
2607
- }],
2608
- outputs: [{
2609
- name: 'results',
2610
- type: 'bytes[]',
2611
- internalType: 'bytes[]'
2612
- }],
2613
- stateMutability: 'payable'
2614
- }, {
2615
- type: 'function',
2616
- name: 'name',
2617
- inputs: [],
2618
- outputs: [{
2619
- name: '',
2620
- type: 'string',
2621
- internalType: 'string'
2622
- }],
2623
- stateMutability: 'view'
2624
- }, {
2625
- type: 'function',
2626
- name: 'nextTokenId',
2627
- inputs: [],
2628
- outputs: [{
2629
- name: '',
2630
- type: 'uint256',
2631
- internalType: 'uint256'
2632
- }],
2633
- stateMutability: 'view'
2634
- }, {
2635
- type: 'function',
2636
- name: 'nonces',
2637
- inputs: [{
2638
- name: 'owner',
2639
- type: 'address',
2640
- internalType: 'address'
2641
- }, {
2642
- name: 'word',
2643
- type: 'uint256',
2644
- internalType: 'uint256'
2645
- }],
2646
- outputs: [{
2647
- name: 'bitmap',
2648
- type: 'uint256',
2649
- internalType: 'uint256'
2650
- }],
2651
- stateMutability: 'view'
2652
- }, {
2653
- type: 'function',
2654
- name: 'ownerOf',
2655
- inputs: [{
2656
- name: 'id',
2657
- type: 'uint256',
2658
- internalType: 'uint256'
2659
- }],
2660
- outputs: [{
2661
- name: 'owner',
2662
- type: 'address',
2663
- internalType: 'address'
2664
- }],
2665
- stateMutability: 'view'
2666
- }, {
2667
- type: 'function',
2668
- name: 'permit',
2669
- inputs: [{
2670
- name: 'spender',
2671
- type: 'address',
2672
- internalType: 'address'
2673
- }, {
2674
- name: 'tokenId',
2675
- type: 'uint256',
2676
- internalType: 'uint256'
2677
- }, {
2678
- name: 'deadline',
2679
- type: 'uint256',
2680
- internalType: 'uint256'
2681
- }, {
2682
- name: 'nonce',
2683
- type: 'uint256',
2684
- internalType: 'uint256'
2685
- }, {
2686
- name: 'signature',
2687
- type: 'bytes',
2688
- internalType: 'bytes'
2689
- }],
2690
- outputs: [],
2691
- stateMutability: 'payable'
2692
- }, {
2693
- type: 'function',
2694
- name: 'permit',
2695
- inputs: [{
2696
- name: 'owner',
2697
- type: 'address',
2698
- internalType: 'address'
2699
- }, {
2700
- name: 'permitSingle',
2701
- type: 'tuple',
2702
- internalType: 'struct IAllowanceTransfer.PermitSingle',
2703
- components: [{
2704
- name: 'details',
2705
- type: 'tuple',
2706
- internalType: 'struct IAllowanceTransfer.PermitDetails',
2707
- components: [{
2708
- name: 'token',
2709
- type: 'address',
2710
- internalType: 'address'
2711
- }, {
2712
- name: 'amount',
2713
- type: 'uint160',
2714
- internalType: 'uint160'
2715
- }, {
2716
- name: 'expiration',
2717
- type: 'uint48',
2718
- internalType: 'uint48'
2719
- }, {
2720
- name: 'nonce',
2721
- type: 'uint48',
2722
- internalType: 'uint48'
2723
- }]
2724
- }, {
2725
- name: 'spender',
2726
- type: 'address',
2727
- internalType: 'address'
2728
- }, {
2729
- name: 'sigDeadline',
2730
- type: 'uint256',
2731
- internalType: 'uint256'
2732
- }]
2733
- }, {
2734
- name: 'signature',
2735
- type: 'bytes',
2736
- internalType: 'bytes'
2737
- }],
2738
- outputs: [{
2739
- name: 'err',
2740
- type: 'bytes',
2741
- internalType: 'bytes'
2742
- }],
2743
- stateMutability: 'payable'
2744
- }, {
2745
- type: 'function',
2746
- name: 'permit2',
2747
- inputs: [],
2748
- outputs: [{
2749
- name: '',
2750
- type: 'address',
2751
- internalType: 'contract IAllowanceTransfer'
2752
- }],
2753
- stateMutability: 'view'
2754
- }, {
2755
- type: 'function',
2756
- name: 'permitBatch',
2757
- inputs: [{
2758
- name: 'owner',
2759
- type: 'address',
2760
- internalType: 'address'
2761
- }, {
2762
- name: '_permitBatch',
2763
- type: 'tuple',
2764
- internalType: 'struct IAllowanceTransfer.PermitBatch',
2765
- components: [{
2766
- name: 'details',
2767
- type: 'tuple[]',
2768
- internalType: 'struct IAllowanceTransfer.PermitDetails[]',
2769
- components: [{
2770
- name: 'token',
2771
- type: 'address',
2772
- internalType: 'address'
2773
- }, {
2774
- name: 'amount',
2775
- type: 'uint160',
2776
- internalType: 'uint160'
2777
- }, {
2778
- name: 'expiration',
2779
- type: 'uint48',
2780
- internalType: 'uint48'
2781
- }, {
2782
- name: 'nonce',
2783
- type: 'uint48',
2784
- internalType: 'uint48'
2785
- }]
2786
- }, {
2787
- name: 'spender',
2788
- type: 'address',
2789
- internalType: 'address'
2790
- }, {
2791
- name: 'sigDeadline',
2792
- type: 'uint256',
2793
- internalType: 'uint256'
2794
- }]
2795
- }, {
2796
- name: 'signature',
2797
- type: 'bytes',
2798
- internalType: 'bytes'
2799
- }],
2800
- outputs: [{
2801
- name: 'err',
2802
- type: 'bytes',
2803
- internalType: 'bytes'
2804
- }],
2805
- stateMutability: 'payable'
2806
- }, {
2807
- type: 'function',
2808
- name: 'permitForAll',
2809
- inputs: [{
2810
- name: 'owner',
2811
- type: 'address',
2812
- internalType: 'address'
2813
- }, {
2814
- name: 'operator',
2815
- type: 'address',
2816
- internalType: 'address'
2817
- }, {
2818
- name: 'approved',
2819
- type: 'bool',
2820
- internalType: 'bool'
2821
- }, {
2822
- name: 'deadline',
2823
- type: 'uint256',
2824
- internalType: 'uint256'
2825
- }, {
2826
- name: 'nonce',
2827
- type: 'uint256',
2828
- internalType: 'uint256'
2829
- }, {
2830
- name: 'signature',
2831
- type: 'bytes',
2832
- internalType: 'bytes'
2833
- }],
2834
- outputs: [],
2835
- stateMutability: 'payable'
2836
- }, {
2837
- type: 'function',
2838
- name: 'poolKeys',
2839
- inputs: [{
2840
- name: 'poolId',
2841
- type: 'bytes25',
2842
- internalType: 'bytes25'
2843
- }],
2844
- outputs: [{
2845
- name: 'currency0',
2846
- type: 'address',
2847
- internalType: 'Currency'
2848
- }, {
2849
- name: 'currency1',
2850
- type: 'address',
2851
- internalType: 'Currency'
2852
- }, {
2853
- name: 'fee',
2854
- type: 'uint24',
2855
- internalType: 'uint24'
2856
- }, {
2857
- name: 'tickSpacing',
2858
- type: 'int24',
2859
- internalType: 'int24'
2860
- }, {
2861
- name: 'hooks',
2862
- type: 'address',
2863
- internalType: 'contract IHooks'
2864
- }],
2865
- stateMutability: 'view'
2866
- }, {
2867
- type: 'function',
2868
- name: 'poolManager',
2869
- inputs: [],
2870
- outputs: [{
2871
- name: '',
2872
- type: 'address',
2873
- internalType: 'contract IPoolManager'
2874
- }],
2875
- stateMutability: 'view'
2876
- }, {
2877
- type: 'function',
2878
- name: 'positionInfo',
2879
- inputs: [{
2880
- name: 'tokenId',
2881
- type: 'uint256',
2882
- internalType: 'uint256'
2883
- }],
2884
- outputs: [{
2885
- name: 'info',
2886
- type: 'uint256',
2887
- internalType: 'PositionInfo'
2888
- }],
2889
- stateMutability: 'view'
2890
- }, {
2891
- type: 'function',
2892
- name: 'revokeNonce',
2893
- inputs: [{
2894
- name: 'nonce',
2895
- type: 'uint256',
2896
- internalType: 'uint256'
2897
- }],
2898
- outputs: [],
2899
- stateMutability: 'payable'
2900
- }, {
2901
- type: 'function',
2902
- name: 'safeTransferFrom',
2903
- inputs: [{
2904
- name: 'from',
2905
- type: 'address',
2906
- internalType: 'address'
2907
- }, {
2908
- name: 'to',
2909
- type: 'address',
2910
- internalType: 'address'
2911
- }, {
2912
- name: 'id',
2913
- type: 'uint256',
2914
- internalType: 'uint256'
2915
- }],
2916
- outputs: [],
2917
- stateMutability: 'nonpayable'
2918
- }, {
2919
- type: 'function',
2920
- name: 'safeTransferFrom',
2921
- inputs: [{
2922
- name: 'from',
2923
- type: 'address',
2924
- internalType: 'address'
2925
- }, {
2926
- name: 'to',
2927
- type: 'address',
2928
- internalType: 'address'
2929
- }, {
2930
- name: 'id',
2931
- type: 'uint256',
2932
- internalType: 'uint256'
2933
- }, {
2934
- name: 'data',
2935
- type: 'bytes',
2936
- internalType: 'bytes'
2937
- }],
2938
- outputs: [],
2939
- stateMutability: 'nonpayable'
2940
- }, {
2941
- type: 'function',
2942
- name: 'setApprovalForAll',
2943
- inputs: [{
2944
- name: 'operator',
2945
- type: 'address',
2946
- internalType: 'address'
2947
- }, {
2948
- name: 'approved',
2949
- type: 'bool',
2950
- internalType: 'bool'
2951
- }],
2952
- outputs: [],
2953
- stateMutability: 'nonpayable'
2954
- }, {
2955
- type: 'function',
2956
- name: 'subscribe',
2957
- inputs: [{
2958
- name: 'tokenId',
2959
- type: 'uint256',
2960
- internalType: 'uint256'
2961
- }, {
2962
- name: 'newSubscriber',
2963
- type: 'address',
2964
- internalType: 'address'
2965
- }, {
2966
- name: 'data',
2967
- type: 'bytes',
2968
- internalType: 'bytes'
2969
- }],
2970
- outputs: [],
2971
- stateMutability: 'payable'
2972
- }, {
2973
- type: 'function',
2974
- name: 'subscriber',
2975
- inputs: [{
2976
- name: 'tokenId',
2977
- type: 'uint256',
2978
- internalType: 'uint256'
2979
- }],
2980
- outputs: [{
2981
- name: 'subscriber',
2982
- type: 'address',
2983
- internalType: 'contract ISubscriber'
2984
- }],
2985
- stateMutability: 'view'
2986
- }, {
2987
- type: 'function',
2988
- name: 'supportsInterface',
2989
- inputs: [{
2990
- name: 'interfaceId',
2991
- type: 'bytes4',
2992
- internalType: 'bytes4'
2993
- }],
2994
- outputs: [{
2995
- name: '',
2996
- type: 'bool',
2997
- internalType: 'bool'
2998
- }],
2999
- stateMutability: 'view'
3000
- }, {
3001
- type: 'function',
3002
- name: 'symbol',
3003
- inputs: [],
3004
- outputs: [{
3005
- name: '',
3006
- type: 'string',
3007
- internalType: 'string'
3008
- }],
3009
- stateMutability: 'view'
3010
- }, {
3011
- type: 'function',
3012
- name: 'tokenDescriptor',
3013
- inputs: [],
3014
- outputs: [{
3015
- name: '',
3016
- type: 'address',
3017
- internalType: 'contract IPositionDescriptor'
3018
- }],
3019
- stateMutability: 'view'
3020
- }, {
3021
- type: 'function',
3022
- name: 'tokenURI',
3023
- inputs: [{
3024
- name: 'tokenId',
3025
- type: 'uint256',
3026
- internalType: 'uint256'
3027
- }],
3028
- outputs: [{
3029
- name: '',
3030
- type: 'string',
3031
- internalType: 'string'
3032
- }],
3033
- stateMutability: 'view'
3034
- }, {
3035
- type: 'function',
3036
- name: 'transferFrom',
3037
- inputs: [{
3038
- name: 'from',
3039
- type: 'address',
3040
- internalType: 'address'
3041
- }, {
3042
- name: 'to',
3043
- type: 'address',
3044
- internalType: 'address'
3045
- }, {
3046
- name: 'id',
3047
- type: 'uint256',
3048
- internalType: 'uint256'
3049
- }],
3050
- outputs: [],
3051
- stateMutability: 'nonpayable'
3052
- }, {
3053
- type: 'function',
3054
- name: 'unlockCallback',
3055
- inputs: [{
3056
- name: 'data',
3057
- type: 'bytes',
3058
- internalType: 'bytes'
3059
- }],
3060
- outputs: [{
3061
- name: '',
3062
- type: 'bytes',
3063
- internalType: 'bytes'
3064
- }],
3065
- stateMutability: 'nonpayable'
3066
- }, {
3067
- type: 'function',
3068
- name: 'unsubscribe',
3069
- inputs: [{
3070
- name: 'tokenId',
3071
- type: 'uint256',
3072
- internalType: 'uint256'
3073
- }],
3074
- outputs: [],
3075
- stateMutability: 'payable'
3076
- }, {
3077
- type: 'function',
3078
- name: 'unsubscribeGasLimit',
3079
- inputs: [],
3080
- outputs: [{
3081
- name: '',
3082
- type: 'uint256',
3083
- internalType: 'uint256'
3084
- }],
3085
- stateMutability: 'view'
3086
- }, {
3087
- type: 'event',
3088
- name: 'Approval',
3089
- inputs: [{
3090
- name: 'owner',
3091
- type: 'address',
3092
- indexed: true,
3093
- internalType: 'address'
3094
- }, {
3095
- name: 'spender',
3096
- type: 'address',
3097
- indexed: true,
3098
- internalType: 'address'
3099
- }, {
3100
- name: 'id',
3101
- type: 'uint256',
3102
- indexed: true,
3103
- internalType: 'uint256'
3104
- }],
3105
- anonymous: false
3106
- }, {
3107
- type: 'event',
3108
- name: 'ApprovalForAll',
3109
- inputs: [{
3110
- name: 'owner',
3111
- type: 'address',
3112
- indexed: true,
3113
- internalType: 'address'
3114
- }, {
3115
- name: 'operator',
3116
- type: 'address',
3117
- indexed: true,
3118
- internalType: 'address'
3119
- }, {
3120
- name: 'approved',
3121
- type: 'bool',
3122
- indexed: false,
3123
- internalType: 'bool'
3124
- }],
3125
- anonymous: false
3126
- }, {
3127
- type: 'event',
3128
- name: 'Subscription',
3129
- inputs: [{
3130
- name: 'tokenId',
3131
- type: 'uint256',
3132
- indexed: true,
3133
- internalType: 'uint256'
3134
- }, {
3135
- name: 'subscriber',
3136
- type: 'address',
3137
- indexed: true,
3138
- internalType: 'address'
3139
- }],
3140
- anonymous: false
3141
- }, {
3142
- type: 'event',
3143
- name: 'Transfer',
3144
- inputs: [{
3145
- name: 'from',
3146
- type: 'address',
3147
- indexed: true,
3148
- internalType: 'address'
3149
- }, {
3150
- name: 'to',
3151
- type: 'address',
3152
- indexed: true,
3153
- internalType: 'address'
3154
- }, {
3155
- name: 'id',
3156
- type: 'uint256',
3157
- indexed: true,
3158
- internalType: 'uint256'
3159
- }],
3160
- anonymous: false
3161
- }, {
3162
- type: 'event',
3163
- name: 'Unsubscription',
3164
- inputs: [{
3165
- name: 'tokenId',
3166
- type: 'uint256',
3167
- indexed: true,
3168
- internalType: 'uint256'
3169
- }, {
3170
- name: 'subscriber',
3171
- type: 'address',
3172
- indexed: true,
3173
- internalType: 'address'
3174
- }],
3175
- anonymous: false
3176
- }, {
3177
- type: 'error',
3178
- name: 'AlreadySubscribed',
3179
- inputs: [{
3180
- name: 'tokenId',
3181
- type: 'uint256',
3182
- internalType: 'uint256'
3183
- }, {
3184
- name: 'subscriber',
3185
- type: 'address',
3186
- internalType: 'address'
3187
- }]
3188
- }, {
3189
- type: 'error',
3190
- name: 'BurnNotificationReverted',
3191
- inputs: [{
3192
- name: 'subscriber',
3193
- type: 'address',
3194
- internalType: 'address'
3195
- }, {
3196
- name: 'reason',
3197
- type: 'bytes',
3198
- internalType: 'bytes'
3199
- }]
3200
- }, {
3201
- type: 'error',
3202
- name: 'ContractLocked',
3203
- inputs: []
3204
- }, {
3205
- type: 'error',
3206
- name: 'DeadlinePassed',
3207
- inputs: [{
3208
- name: 'deadline',
3209
- type: 'uint256',
3210
- internalType: 'uint256'
3211
- }]
3212
- }, {
3213
- type: 'error',
3214
- name: 'DeltaNotNegative',
3215
- inputs: [{
3216
- name: 'currency',
3217
- type: 'address',
3218
- internalType: 'Currency'
3219
- }]
3220
- }, {
3221
- type: 'error',
3222
- name: 'DeltaNotPositive',
3223
- inputs: [{
3224
- name: 'currency',
3225
- type: 'address',
3226
- internalType: 'Currency'
3227
- }]
3228
- }, {
3229
- type: 'error',
3230
- name: 'GasLimitTooLow',
3231
- inputs: []
3232
- }, {
3233
- type: 'error',
3234
- name: 'InputLengthMismatch',
3235
- inputs: []
3236
- }, {
3237
- type: 'error',
3238
- name: 'InsufficientBalance',
3239
- inputs: []
3240
- }, {
3241
- type: 'error',
3242
- name: 'InvalidContractSignature',
3243
- inputs: []
3244
- }, {
3245
- type: 'error',
3246
- name: 'InvalidEthSender',
3247
- inputs: []
3248
- }, {
3249
- type: 'error',
3250
- name: 'InvalidSignature',
3251
- inputs: []
3252
- }, {
3253
- type: 'error',
3254
- name: 'InvalidSignatureLength',
3255
- inputs: []
3256
- }, {
3257
- type: 'error',
3258
- name: 'InvalidSigner',
3259
- inputs: []
3260
- }, {
3261
- type: 'error',
3262
- name: 'MaximumAmountExceeded',
3263
- inputs: [{
3264
- name: 'maximumAmount',
3265
- type: 'uint128',
3266
- internalType: 'uint128'
3267
- }, {
3268
- name: 'amountRequested',
3269
- type: 'uint128',
3270
- internalType: 'uint128'
3271
- }]
3272
- }, {
3273
- type: 'error',
3274
- name: 'MinimumAmountInsufficient',
3275
- inputs: [{
3276
- name: 'minimumAmount',
3277
- type: 'uint128',
3278
- internalType: 'uint128'
3279
- }, {
3280
- name: 'amountReceived',
3281
- type: 'uint128',
3282
- internalType: 'uint128'
3283
- }]
3284
- }, {
3285
- type: 'error',
3286
- name: 'ModifyLiquidityNotificationReverted',
3287
- inputs: [{
3288
- name: 'subscriber',
3289
- type: 'address',
3290
- internalType: 'address'
3291
- }, {
3292
- name: 'reason',
3293
- type: 'bytes',
3294
- internalType: 'bytes'
3295
- }]
3296
- }, {
3297
- type: 'error',
3298
- name: 'NoCodeSubscriber',
3299
- inputs: []
3300
- }, {
3301
- type: 'error',
3302
- name: 'NoSelfPermit',
3303
- inputs: []
3304
- }, {
3305
- type: 'error',
3306
- name: 'NonceAlreadyUsed',
3307
- inputs: []
3308
- }, {
3309
- type: 'error',
3310
- name: 'NotApproved',
3311
- inputs: [{
3312
- name: 'caller',
3313
- type: 'address',
3314
- internalType: 'address'
3315
- }]
3316
- }, {
3317
- type: 'error',
3318
- name: 'NotPoolManager',
3319
- inputs: []
3320
- }, {
3321
- type: 'error',
3322
- name: 'NotSubscribed',
3323
- inputs: []
3324
- }, {
3325
- type: 'error',
3326
- name: 'PoolManagerMustBeLocked',
3327
- inputs: []
3328
- }, {
3329
- type: 'error',
3330
- name: 'SignatureDeadlineExpired',
3331
- inputs: []
3332
- }, {
3333
- type: 'error',
3334
- name: 'SubscriptionReverted',
3335
- inputs: [{
3336
- name: 'subscriber',
3337
- type: 'address',
3338
- internalType: 'address'
3339
- }, {
3340
- name: 'reason',
3341
- type: 'bytes',
3342
- internalType: 'bytes'
3343
- }]
3344
- }, {
3345
- type: 'error',
3346
- name: 'TransferNotificationReverted',
3347
- inputs: [{
3348
- name: 'subscriber',
3349
- type: 'address',
3350
- internalType: 'address'
3351
- }, {
3352
- name: 'reason',
3353
- type: 'bytes',
3354
- internalType: 'bytes'
3355
- }]
3356
- }, {
3357
- type: 'error',
3358
- name: 'Unauthorized',
3359
- inputs: []
3360
- }, {
3361
- type: 'error',
3362
- name: 'UnsupportedAction',
3363
- inputs: [{
3364
- name: 'action',
3365
- type: 'uint256',
3366
- internalType: 'uint256'
3367
- }]
3368
- }];
3369
-
3370
- var NFT_PERMIT_TYPES = {
3371
- Permit: [{
3372
- name: 'spender',
3373
- type: 'address'
3374
- }, {
3375
- name: 'tokenId',
3376
- type: 'uint256'
3377
- }, {
3378
- name: 'nonce',
3379
- type: 'uint256'
3380
- }, {
3381
- name: 'deadline',
3382
- type: 'uint256'
3383
- }]
3384
- };
3385
- // type guard
3386
- function isMint(options) {
3387
- return Object.keys(options).some(function (k) {
3388
- return k === 'recipient';
3389
- });
3390
- }
3391
- function shouldCreatePool(options) {
3392
- if (options.createPool) {
3393
- !(options.sqrtPriceX96 !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, NO_SQRT_PRICE) : invariant(false) : void 0;
3394
- return true;
3395
- }
3396
- return false;
3397
- }
3398
- var V4PositionManager = /*#__PURE__*/function () {
3399
- /**
3400
- * Cannot be constructed.
3401
- */
3402
- function V4PositionManager() {}
3403
- /**
3404
- * Public methods to encode method parameters for different actions on the PositionManager contract
3405
- */
3406
- V4PositionManager.createCallParameters = function createCallParameters(poolKey, sqrtPriceX96) {
3407
- return {
3408
- calldata: this.encodeInitializePool(poolKey, sqrtPriceX96),
3409
- value: toHex(0)
3410
- };
3411
- };
3412
- V4PositionManager.addCallParameters = function addCallParameters(position, options) {
3413
- /**
3414
- * Cases:
3415
- * - if pool does not exist yet, encode initializePool
3416
- * then,
3417
- * - if is mint, encode MINT_POSITION. If migrating, encode a SETTLE and SWEEP for both currencies. Else, encode a SETTLE_PAIR. If on a NATIVE pool, encode a SWEEP.
3418
- * - else, encode INCREASE_LIQUIDITY and SETTLE_PAIR. If it is on a NATIVE pool, encode a SWEEP.
3419
- */
3420
- !JSBI.greaterThan(position.liquidity, ZERO) ? process.env.NODE_ENV !== "production" ? invariant(false, ZERO_LIQUIDITY) : invariant(false) : void 0;
3421
- var calldataList = [];
3422
- var planner = new V4PositionPlanner();
3423
- // Encode initialize pool.
3424
- if (isMint(options) && shouldCreatePool(options)) {
3425
- // No planner used here because initializePool is not supported as an Action
3426
- calldataList.push(V4PositionManager.encodeInitializePool(position.pool.poolKey, options.sqrtPriceX96));
3427
- }
3428
- // position.pool.currency0 is native if and only if options.useNative is set
3429
- !(position.pool.currency0 === options.useNative || !position.pool.currency0.isNative && options.useNative === undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, NATIVE_NOT_SET) : invariant(false) : void 0;
3430
- // adjust for slippage
3431
- var maximumAmounts = position.mintAmountsWithSlippage(options.slippageTolerance);
3432
- var amount0Max = toHex(maximumAmounts.amount0);
3433
- var amount1Max = toHex(maximumAmounts.amount1);
3434
- // We use permit2 to approve tokens to the position manager
3435
- if (options.batchPermit) {
3436
- calldataList.push(V4PositionManager.encodePermitBatch(options.batchPermit.owner, options.batchPermit.permitBatch, options.batchPermit.signature));
3437
- }
3438
- // mint
3439
- if (isMint(options)) {
3440
- var recipient = validateAndParseAddress(options.recipient);
3441
- planner.addMint(position.pool, position.tickLower, position.tickUpper, position.liquidity, amount0Max, amount1Max, recipient, options.hookData);
3442
- } else {
3443
- // increase
3444
- planner.addIncrease(options.tokenId, position.liquidity, amount0Max, amount1Max, options.hookData);
3445
- }
3446
- var value = toHex(0);
3447
- // If migrating, we need to settle and sweep both currencies individually
3448
- if (isMint(options) && options.migrate) {
3449
- if (options.useNative) {
3450
- // unwrap the exact amount needed to send to the pool manager
3451
- planner.addUnwrap(OPEN_DELTA);
3452
- // payer is v4 position manager
3453
- planner.addSettle(position.pool.currency0, false);
3454
- planner.addSettle(position.pool.currency1, false);
3455
- // sweep any leftover wrapped native that was not unwrapped
3456
- // recipient will be same as the v4 lp token recipient
3457
- planner.addSweep(position.pool.currency0.wrapped, options.recipient);
3458
- planner.addSweep(position.pool.currency1, options.recipient);
3459
- } else {
3460
- // payer is v4 position manager
3461
- planner.addSettle(position.pool.currency0, false);
3462
- planner.addSettle(position.pool.currency1, false);
3463
- // recipient will be same as the v4 lp token recipient
3464
- planner.addSweep(position.pool.currency0, options.recipient);
3465
- planner.addSweep(position.pool.currency1, options.recipient);
3466
- }
3467
- } else {
3468
- // need to settle both currencies when minting / adding liquidity (user is the payer)
3469
- planner.addSettlePair(position.pool.currency0, position.pool.currency1);
3470
- // When not migrating and adding native currency, add a final sweep
3471
- if (options.useNative) {
3472
- // Any sweeping must happen after the settling.
3473
- // native currency will always be currency0 in v4
3474
- value = toHex(amount0Max);
3475
- planner.addSweep(position.pool.currency0, MSG_SENDER);
3476
- }
3477
- }
3478
- calldataList.push(V4PositionManager.encodeModifyLiquidities(planner.finalize(), options.deadline));
3479
- return {
3480
- calldata: Multicall.encodeMulticall(calldataList),
3481
- value: value
3482
- };
3483
- }
3484
- /**
3485
- * Produces the calldata for completely or partially exiting a position
3486
- * @param position The position to exit
3487
- * @param options Additional information necessary for generating the calldata
3488
- * @returns The call parameters
3489
- */;
3490
- V4PositionManager.removeCallParameters = function removeCallParameters(position, options) {
3491
- /**
3492
- * cases:
3493
- * - if liquidityPercentage is 100%, encode BURN_POSITION and then TAKE_PAIR
3494
- * - else, encode DECREASE_LIQUIDITY and then TAKE_PAIR
3495
- */
3496
- var calldataList = [];
3497
- var planner = new V4PositionPlanner();
3498
- var tokenId = toHex(options.tokenId);
3499
- if (options.burnToken) {
3500
- // if burnToken is true, the specified liquidity percentage must be 100%
3501
- !options.liquidityPercentage.equalTo(ONE) ? process.env.NODE_ENV !== "production" ? invariant(false, CANNOT_BURN) : invariant(false) : void 0;
3502
- // if there is a permit, encode the ERC721Permit permit call
3503
- if (options.permit) {
3504
- calldataList.push(V4PositionManager.encodeERC721Permit(options.permit.spender, options.permit.tokenId, options.permit.deadline, options.permit.nonce, options.permit.signature));
3505
- }
3506
- // slippage-adjusted amounts derived from current position liquidity
3507
- var _position$burnAmounts = position.burnAmountsWithSlippage(options.slippageTolerance),
3508
- amount0Min = _position$burnAmounts.amount0,
3509
- amount1Min = _position$burnAmounts.amount1;
3510
- planner.addBurn(tokenId, amount0Min, amount1Min, options.hookData);
3511
- } else {
3512
- var _options$hookData;
3513
- // construct a partial position with a percentage of liquidity
3514
- var partialPosition = new Position({
3515
- pool: position.pool,
3516
- liquidity: options.liquidityPercentage.multiply(position.liquidity).quotient,
3517
- tickLower: position.tickLower,
3518
- tickUpper: position.tickUpper
3519
- });
3520
- // If the partial position has liquidity=0, this is a collect call and collectCallParameters should be used
3521
- !JSBI.greaterThan(partialPosition.liquidity, ZERO) ? process.env.NODE_ENV !== "production" ? invariant(false, ZERO_LIQUIDITY) : invariant(false) : void 0;
3522
- // slippage-adjusted underlying amounts
3523
- var _partialPosition$burn = partialPosition.burnAmountsWithSlippage(options.slippageTolerance),
3524
- _amount0Min = _partialPosition$burn.amount0,
3525
- _amount1Min = _partialPosition$burn.amount1;
3526
- planner.addDecrease(tokenId, partialPosition.liquidity.toString(), _amount0Min.toString(), _amount1Min.toString(), (_options$hookData = options.hookData) != null ? _options$hookData : EMPTY_BYTES);
3527
- }
3528
- planner.addTakePair(position.pool.currency0, position.pool.currency1, MSG_SENDER);
3529
- calldataList.push(V4PositionManager.encodeModifyLiquidities(planner.finalize(), options.deadline));
3530
- return {
3531
- calldata: Multicall.encodeMulticall(calldataList),
3532
- value: toHex(0)
3533
- };
3534
- }
3535
- /**
3536
- * Produces the calldata for collecting fees from a position
3537
- * @param position The position to collect fees from
3538
- * @param options Additional information necessary for generating the calldata
3539
- * @returns The call parameters
3540
- */;
3541
- V4PositionManager.collectCallParameters = function collectCallParameters(position, options) {
3542
- var calldataList = [];
3543
- var planner = new V4PositionPlanner();
3544
- var tokenId = toHex(options.tokenId);
3545
- var recipient = validateAndParseAddress(options.recipient);
3546
- /**
3547
- * To collect fees in V4, we need to:
3548
- * - encode a decrease liquidity by 0
3549
- * - and encode a TAKE_PAIR
3550
- */
3551
- planner.addDecrease(tokenId, '0', '0', '0', options.hookData);
3552
- planner.addTakePair(position.pool.currency0, position.pool.currency1, recipient);
3553
- calldataList.push(V4PositionManager.encodeModifyLiquidities(planner.finalize(), options.deadline));
3554
- return {
3555
- calldata: Multicall.encodeMulticall(calldataList),
3556
- value: toHex(0)
3557
- };
3558
- }
3559
- // Initialize a pool
3560
- ;
3561
- V4PositionManager.encodeInitializePool = function encodeInitializePool(poolKey, sqrtPriceX96) {
3562
- return V4PositionManager.INTERFACE.encodeFunctionData(PositionFunctions.INITIALIZE_POOL, [poolKey, sqrtPriceX96.toString()]);
3563
- }
3564
- // Encode a modify liquidities call
3565
- ;
3566
- V4PositionManager.encodeModifyLiquidities = function encodeModifyLiquidities(unlockData, deadline) {
3567
- return V4PositionManager.INTERFACE.encodeFunctionData(PositionFunctions.MODIFY_LIQUIDITIES, [unlockData, deadline]);
3568
- }
3569
- // Encode a permit batch call
3570
- ;
3571
- V4PositionManager.encodePermitBatch = function encodePermitBatch(owner, permitBatch, signature) {
3572
- return V4PositionManager.INTERFACE.encodeFunctionData(PositionFunctions.PERMIT_BATCH, [owner, permitBatch, signature]);
3573
- }
3574
- // Encode a ERC721Permit permit call
3575
- ;
3576
- V4PositionManager.encodeERC721Permit = function encodeERC721Permit(spender, tokenId, deadline, nonce, signature) {
3577
- return V4PositionManager.INTERFACE.encodeFunctionData(PositionFunctions.ERC721PERMIT_PERMIT, [spender, tokenId, deadline, nonce, signature]);
3578
- }
3579
- // Prepare the params for an EIP712 signTypedData request
3580
- ;
3581
- V4PositionManager.getPermitData = function getPermitData(permit, positionManagerAddress, chainId) {
3582
- return {
3583
- domain: {
3584
- name: 'Uniswap V4 Positions NFT',
3585
- chainId: chainId,
3586
- verifyingContract: positionManagerAddress
3587
- },
3588
- types: NFT_PERMIT_TYPES,
3589
- values: permit
3590
- };
3591
- };
3592
- return V4PositionManager;
3593
- }();
3594
- V4PositionManager.INTERFACE = /*#__PURE__*/new Interface(positionManagerAbi);
3595
-
3596
- export { Actions, BASE_TOKENIZE_UNDERLYING, DYNAMIC_FEE_FLAG, Hook, HookOptions, Pool, Position, Route, Subparser, TAAVE_ARBITRUM_ONE, TAAVE_SEPOLIA, TLINK_ARBITRUM_ONE, TLINK_SEPOLIA, TUSDC_ARBITRUM_ONE, TUSDC_MAINNET, TUSDC_SEPOLIA, TUSDT_ARBITRUM_ONE, TUSDT_MAINNET, TUSDT_SEPOLIA, TWBTC_ARBITRUM_ONE, TWBTC_MAINNET, TWBTC_SEPOLIA, TWETH_ARBITRUM_ONE, TWETH_MAINNET, TWETH_SEPOLIA, Trade, V4BaseActionsParser, V4Planner, V4PositionManager, V4PositionPlanner, V4_BASE_ACTIONS_ABI_DEFINITION, amountWithPathCurrency, encodeRouteToPath, getPathCurrency, getSupportTokenizeByUnderlying, getSupportUnderlyingByTokenize, hookFlagIndex, priceToClosestTick, sortsBefore, tickToPrice, toAddress, toHex, tradeComparator };
3597
- //# sourceMappingURL=v4-sdk.esm.js.map