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