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