@kittycorn-labs/v4-sdk 1.1.30 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/{PositionManager.d.ts → cjs/src/PositionManager.d.ts} +169 -169
- package/dist/cjs/src/PositionManager.js +242 -0
- package/dist/cjs/src/PositionManager.js.map +1 -0
- package/dist/cjs/src/abis/IMulticall.json +23 -0
- package/dist/{actionConstants.d.ts → cjs/src/actionConstants.d.ts} +1 -1
- package/dist/cjs/src/actionConstants.js +6 -0
- package/dist/cjs/src/actionConstants.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/index.d.ts +4 -4
- package/dist/cjs/src/entities/index.js +8 -0
- package/dist/cjs/src/entities/index.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/pool.d.ts +103 -103
- package/dist/cjs/src/entities/pool.js +196 -0
- package/dist/cjs/src/entities/pool.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/position.d.ts +144 -144
- package/dist/cjs/src/entities/position.js +273 -0
- package/dist/cjs/src/entities/position.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/route.d.ts +28 -28
- package/dist/cjs/src/entities/route.js +89 -0
- package/dist/cjs/src/entities/route.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/trade.d.ts +220 -220
- package/dist/cjs/src/entities/trade.js +441 -0
- package/dist/cjs/src/entities/trade.js.map +1 -0
- package/dist/{index.d.ts → cjs/src/index.d.ts} +4 -4
- package/dist/cjs/src/index.js +8 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/{internalConstants.d.ts → cjs/src/internalConstants.d.ts} +46 -46
- package/dist/cjs/src/internalConstants.js +69 -0
- package/dist/cjs/src/internalConstants.js.map +1 -0
- package/dist/{multicall.d.ts → cjs/src/multicall.d.ts} +10 -10
- package/dist/cjs/src/multicall.js +26 -0
- package/dist/cjs/src/multicall.js.map +1 -0
- package/dist/cjs/src/tokenize.d.ts +17 -0
- package/dist/cjs/src/tokenize.js +42 -0
- package/dist/cjs/src/tokenize.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/calldata.d.ts +20 -20
- package/dist/cjs/src/utils/calldata.js +20 -0
- package/dist/cjs/src/utils/calldata.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/currencyMap.d.ts +2 -2
- package/dist/cjs/src/utils/currencyMap.js +15 -0
- package/dist/cjs/src/utils/currencyMap.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/encodeRouteToPath.d.ts +10 -10
- package/dist/cjs/src/utils/encodeRouteToPath.js +26 -0
- package/dist/cjs/src/utils/encodeRouteToPath.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/hook.d.ts +45 -45
- package/dist/cjs/src/utils/hook.js +97 -0
- package/dist/cjs/src/utils/hook.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/index.d.ts +11 -11
- package/dist/cjs/src/utils/index.js +15 -0
- package/dist/cjs/src/utils/index.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/pathCurrency.d.ts +4 -4
- package/dist/cjs/src/utils/pathCurrency.js +27 -0
- package/dist/cjs/src/utils/pathCurrency.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/positionManagerAbi.d.ts +102 -102
- package/dist/cjs/src/utils/positionManagerAbi.js +1318 -0
- package/dist/cjs/src/utils/positionManagerAbi.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/priceTickConversions.d.ts +20 -20
- package/dist/cjs/src/utils/priceTickConversions.js +55 -0
- package/dist/cjs/src/utils/priceTickConversions.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/sortsBefore.d.ts +2 -2
- package/dist/cjs/src/utils/sortsBefore.js +12 -0
- package/dist/cjs/src/utils/sortsBefore.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/v4BaseActionsParser.d.ts +49 -45
- package/dist/cjs/src/utils/v4BaseActionsParser.js +193 -0
- package/dist/cjs/src/utils/v4BaseActionsParser.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/v4Planner.d.ts +71 -55
- package/dist/cjs/src/utils/v4Planner.js +267 -0
- package/dist/cjs/src/utils/v4Planner.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/v4PositionPlanner.d.ts +13 -12
- package/dist/cjs/src/utils/v4PositionPlanner.js +61 -0
- package/dist/cjs/src/utils/v4PositionPlanner.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/src/PositionManager.d.ts +169 -0
- package/dist/esm/src/PositionManager.js +237 -0
- package/dist/esm/src/PositionManager.js.map +1 -0
- package/dist/esm/src/abis/IMulticall.json +23 -0
- package/dist/esm/src/actionConstants.d.ts +1 -0
- package/dist/esm/src/actionConstants.js +3 -0
- package/dist/esm/src/actionConstants.js.map +1 -0
- package/dist/esm/src/entities/index.d.ts +4 -0
- package/dist/esm/src/entities/index.js +5 -0
- package/dist/esm/src/entities/index.js.map +1 -0
- package/dist/esm/src/entities/pool.d.ts +103 -0
- package/dist/esm/src/entities/pool.js +191 -0
- package/dist/esm/src/entities/pool.js.map +1 -0
- package/dist/esm/src/entities/position.d.ts +144 -0
- package/dist/esm/src/entities/position.js +268 -0
- package/dist/esm/src/entities/position.js.map +1 -0
- package/dist/esm/src/entities/route.d.ts +28 -0
- package/dist/esm/src/entities/route.js +84 -0
- package/dist/esm/src/entities/route.js.map +1 -0
- package/dist/esm/src/entities/trade.d.ts +220 -0
- package/dist/esm/src/entities/trade.js +435 -0
- package/dist/esm/src/entities/trade.js.map +1 -0
- package/dist/esm/src/index.d.ts +4 -0
- package/dist/esm/src/index.js +5 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/src/internalConstants.d.ts +46 -0
- package/dist/esm/src/internalConstants.js +65 -0
- package/dist/esm/src/internalConstants.js.map +1 -0
- package/dist/esm/src/multicall.d.ts +10 -0
- package/dist/esm/src/multicall.js +21 -0
- package/dist/esm/src/multicall.js.map +1 -0
- package/dist/esm/src/tokenize.d.ts +17 -0
- package/dist/esm/src/tokenize.js +37 -0
- package/dist/esm/src/tokenize.js.map +1 -0
- package/dist/esm/src/utils/calldata.d.ts +20 -0
- package/dist/esm/src/utils/calldata.js +15 -0
- package/dist/esm/src/utils/calldata.js.map +1 -0
- package/dist/esm/src/utils/currencyMap.d.ts +2 -0
- package/dist/esm/src/utils/currencyMap.js +11 -0
- package/dist/esm/src/utils/currencyMap.js.map +1 -0
- package/dist/esm/src/utils/encodeRouteToPath.d.ts +10 -0
- package/dist/esm/src/utils/encodeRouteToPath.js +22 -0
- package/dist/esm/src/utils/encodeRouteToPath.js.map +1 -0
- package/dist/esm/src/utils/hook.d.ts +45 -0
- package/dist/esm/src/utils/hook.js +92 -0
- package/dist/esm/src/utils/hook.js.map +1 -0
- package/dist/esm/src/utils/index.d.ts +11 -0
- package/dist/esm/src/utils/index.js +12 -0
- package/dist/esm/src/utils/index.js.map +1 -0
- package/dist/esm/src/utils/pathCurrency.d.ts +4 -0
- package/dist/esm/src/utils/pathCurrency.js +22 -0
- package/dist/esm/src/utils/pathCurrency.js.map +1 -0
- package/dist/esm/src/utils/positionManagerAbi.d.ts +102 -0
- package/dist/esm/src/utils/positionManagerAbi.js +1315 -0
- package/dist/esm/src/utils/positionManagerAbi.js.map +1 -0
- package/dist/esm/src/utils/priceTickConversions.d.ts +20 -0
- package/dist/esm/src/utils/priceTickConversions.js +49 -0
- package/dist/esm/src/utils/priceTickConversions.js.map +1 -0
- package/dist/esm/src/utils/sortsBefore.d.ts +2 -0
- package/dist/esm/src/utils/sortsBefore.js +8 -0
- package/dist/esm/src/utils/sortsBefore.js.map +1 -0
- package/dist/esm/src/utils/v4BaseActionsParser.d.ts +49 -0
- package/dist/esm/src/utils/v4BaseActionsParser.js +189 -0
- package/dist/esm/src/utils/v4BaseActionsParser.js.map +1 -0
- package/dist/esm/src/utils/v4Planner.d.ts +71 -0
- package/dist/esm/src/utils/v4Planner.js +261 -0
- package/dist/esm/src/utils/v4Planner.js.map +1 -0
- package/dist/esm/src/utils/v4PositionPlanner.d.ts +13 -0
- package/dist/esm/src/utils/v4PositionPlanner.js +57 -0
- package/dist/esm/src/utils/v4PositionPlanner.js.map +1 -0
- package/dist/types/src/PositionManager.d.ts +170 -0
- package/dist/types/src/PositionManager.d.ts.map +1 -0
- package/dist/types/src/actionConstants.d.ts +2 -0
- package/dist/types/src/actionConstants.d.ts.map +1 -0
- package/dist/types/src/entities/index.d.ts +5 -0
- package/dist/types/src/entities/index.d.ts.map +1 -0
- package/dist/types/src/entities/pool.d.ts +104 -0
- package/dist/types/src/entities/pool.d.ts.map +1 -0
- package/dist/types/src/entities/position.d.ts +145 -0
- package/dist/types/src/entities/position.d.ts.map +1 -0
- package/dist/types/src/entities/route.d.ts +29 -0
- package/dist/types/src/entities/route.d.ts.map +1 -0
- package/dist/types/src/entities/trade.d.ts +221 -0
- package/dist/types/src/entities/trade.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +5 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/internalConstants.d.ts +47 -0
- package/dist/types/src/internalConstants.d.ts.map +1 -0
- package/dist/types/src/multicall.d.ts +11 -0
- package/dist/types/src/multicall.d.ts.map +1 -0
- package/dist/types/src/tokenize.d.ts +18 -0
- package/dist/types/src/tokenize.d.ts.map +1 -0
- package/dist/types/src/utils/calldata.d.ts +21 -0
- package/dist/types/src/utils/calldata.d.ts.map +1 -0
- package/dist/types/src/utils/currencyMap.d.ts +3 -0
- package/dist/types/src/utils/currencyMap.d.ts.map +1 -0
- package/dist/types/src/utils/encodeRouteToPath.d.ts +11 -0
- package/dist/types/src/utils/encodeRouteToPath.d.ts.map +1 -0
- package/dist/types/src/utils/hook.d.ts +46 -0
- package/dist/types/src/utils/hook.d.ts.map +1 -0
- package/dist/types/src/utils/index.d.ts +12 -0
- package/dist/types/src/utils/index.d.ts.map +1 -0
- package/dist/types/src/utils/pathCurrency.d.ts +5 -0
- package/dist/types/src/utils/pathCurrency.d.ts.map +1 -0
- package/dist/types/src/utils/positionManagerAbi.d.ts +103 -0
- package/dist/types/src/utils/positionManagerAbi.d.ts.map +1 -0
- package/dist/types/src/utils/priceTickConversions.d.ts +21 -0
- package/dist/types/src/utils/priceTickConversions.d.ts.map +1 -0
- package/dist/types/src/utils/sortsBefore.d.ts +3 -0
- package/dist/types/src/utils/sortsBefore.d.ts.map +1 -0
- package/dist/types/src/utils/v4BaseActionsParser.d.ts +50 -0
- package/dist/types/src/utils/v4BaseActionsParser.d.ts.map +1 -0
- package/dist/types/src/utils/v4Planner.d.ts +72 -0
- package/dist/types/src/utils/v4Planner.d.ts.map +1 -0
- package/dist/types/src/utils/v4PositionPlanner.d.ts +14 -0
- package/dist/types/src/utils/v4PositionPlanner.d.ts.map +1 -0
- package/package.json +28 -46
- package/dist/index.js +0 -8
- package/dist/tokenizeAddresses.d.ts +0 -25
- package/dist/v4-sdk.cjs.development.js +0 -3633
- 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 -3597
- package/dist/v4-sdk.esm.js.map +0 -1
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Trade = exports.tradeComparator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tokenize_1 = require("../tokenize");
|
|
6
|
+
const sdk_core_1 = require("@kittycorn-labs/sdk-core");
|
|
7
|
+
const jsbi_1 = tslib_1.__importDefault(require("jsbi"));
|
|
8
|
+
const tiny_invariant_1 = tslib_1.__importDefault(require("tiny-invariant"));
|
|
9
|
+
const internalConstants_1 = require("../internalConstants");
|
|
10
|
+
const pool_1 = require("./pool");
|
|
11
|
+
const route_1 = require("./route");
|
|
12
|
+
const pathCurrency_1 = require("../utils/pathCurrency");
|
|
13
|
+
/**
|
|
14
|
+
* Trades comparator, an extension of the input output comparator that also considers other dimensions of the trade in ranking them
|
|
15
|
+
* @template TInput The input currency, either Ether or an ERC-20
|
|
16
|
+
* @template TOutput The output currency, either Ether or an ERC-20
|
|
17
|
+
* @template TTradeType The trade type, either exact input or exact output
|
|
18
|
+
* @param a The first trade to compare
|
|
19
|
+
* @param b The second trade to compare
|
|
20
|
+
* @returns A sorted ordering for two neighboring elements in a trade array
|
|
21
|
+
*/
|
|
22
|
+
function tradeComparator(a, b) {
|
|
23
|
+
// must have same input and output currency for comparison
|
|
24
|
+
(0, tiny_invariant_1.default)(a.inputAmount.currency.equals(b.inputAmount.currency), 'INPUT_CURRENCY');
|
|
25
|
+
(0, tiny_invariant_1.default)(a.outputAmount.currency.equals(b.outputAmount.currency), 'OUTPUT_CURRENCY');
|
|
26
|
+
if (a.outputAmount.equalTo(b.outputAmount)) {
|
|
27
|
+
if (a.inputAmount.equalTo(b.inputAmount)) {
|
|
28
|
+
// consider the number of hops since each hop costs gas
|
|
29
|
+
const aHops = a.swaps.reduce((total, cur) => total + cur.route.currencyPath.length, 0);
|
|
30
|
+
const bHops = b.swaps.reduce((total, cur) => total + cur.route.currencyPath.length, 0);
|
|
31
|
+
return aHops - bHops;
|
|
32
|
+
}
|
|
33
|
+
// trade A requires less input than trade B, so A should come first
|
|
34
|
+
if (a.inputAmount.lessThan(b.inputAmount)) {
|
|
35
|
+
return -1;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return 1;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// tradeA has less output than trade B, so should come second
|
|
43
|
+
if (a.outputAmount.lessThan(b.outputAmount)) {
|
|
44
|
+
return 1;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return -1;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.tradeComparator = tradeComparator;
|
|
52
|
+
/**
|
|
53
|
+
* Represents a trade executed against a set of routes where some percentage of the input is
|
|
54
|
+
* split across each route.
|
|
55
|
+
*
|
|
56
|
+
* Each route has its own set of pools. Pools can not be re-used across routes.
|
|
57
|
+
*
|
|
58
|
+
* Does not account for slippage, i.e., changes in price environment that can occur between
|
|
59
|
+
* the time the trade is submitted and when it is executed.
|
|
60
|
+
* @template TInput The input currency, either Ether or an ERC-20
|
|
61
|
+
* @template TOutput The output currency, either Ether or an ERC-20
|
|
62
|
+
* @template TTradeType The trade type, either exact input or exact output
|
|
63
|
+
*/
|
|
64
|
+
class Trade {
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated Deprecated in favor of 'swaps' property. If the trade consists of multiple routes
|
|
67
|
+
* this will return an error.
|
|
68
|
+
*
|
|
69
|
+
* When the trade consists of just a single route, this returns the route of the trade,
|
|
70
|
+
* i.e. which pools the trade goes through.
|
|
71
|
+
*/
|
|
72
|
+
get route() {
|
|
73
|
+
(0, tiny_invariant_1.default)(this.swaps.length === 1, 'MULTIPLE_ROUTES');
|
|
74
|
+
return this.swaps[0].route;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The input amount for the trade assuming no slippage.
|
|
78
|
+
*/
|
|
79
|
+
get inputAmount() {
|
|
80
|
+
if (this._inputAmount) {
|
|
81
|
+
return this._inputAmount;
|
|
82
|
+
}
|
|
83
|
+
const inputCurrency = this.swaps[0].inputAmount.currency;
|
|
84
|
+
const totalInputFromRoutes = this.swaps
|
|
85
|
+
.map(({ inputAmount }) => inputAmount)
|
|
86
|
+
.reduce((total, cur) => total.add(cur), sdk_core_1.CurrencyAmount.fromRawAmount(inputCurrency, 0));
|
|
87
|
+
this._inputAmount = totalInputFromRoutes;
|
|
88
|
+
return this._inputAmount;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The output amount for the trade assuming no slippage.
|
|
92
|
+
*/
|
|
93
|
+
get outputAmount() {
|
|
94
|
+
if (this._outputAmount) {
|
|
95
|
+
return this._outputAmount;
|
|
96
|
+
}
|
|
97
|
+
const outputCurrency = this.swaps[0].outputAmount.currency;
|
|
98
|
+
const totalOutputFromRoutes = this.swaps
|
|
99
|
+
.map(({ outputAmount }) => outputAmount)
|
|
100
|
+
.reduce((total, cur) => total.add(cur), sdk_core_1.CurrencyAmount.fromRawAmount(outputCurrency, 0));
|
|
101
|
+
this._outputAmount = totalOutputFromRoutes;
|
|
102
|
+
return this._outputAmount;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The price expressed in terms of output amount/input amount.
|
|
106
|
+
*/
|
|
107
|
+
get executionPrice() {
|
|
108
|
+
var _a;
|
|
109
|
+
return ((_a = this._executionPrice) !== null && _a !== void 0 ? _a : (this._executionPrice = new sdk_core_1.Price(this.inputAmount.currency, this.outputAmount.currency, this.inputAmount.quotient, this.outputAmount.quotient)));
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Returns the percent difference between the route's mid price and the price impact
|
|
113
|
+
*/
|
|
114
|
+
get priceImpact() {
|
|
115
|
+
if (this._priceImpact) {
|
|
116
|
+
return this._priceImpact;
|
|
117
|
+
}
|
|
118
|
+
let spotOutputAmount = sdk_core_1.CurrencyAmount.fromRawAmount(this.outputAmount.currency, 0);
|
|
119
|
+
for (const { route, inputAmount } of this.swaps) {
|
|
120
|
+
const midPrice = route.midPrice;
|
|
121
|
+
spotOutputAmount = spotOutputAmount.add(midPrice.quote(inputAmount));
|
|
122
|
+
}
|
|
123
|
+
const priceImpact = spotOutputAmount.subtract(this.outputAmount).divide(spotOutputAmount);
|
|
124
|
+
this._priceImpact = new sdk_core_1.Percent(priceImpact.numerator, priceImpact.denominator);
|
|
125
|
+
return this._priceImpact;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Constructs an exact in trade with the given amount in and route
|
|
129
|
+
* @template TInput The input currency, either Ether or an ERC-20
|
|
130
|
+
* @template TOutput The output currency, either Ether or an ERC-20
|
|
131
|
+
* @param route The route of the exact in trade
|
|
132
|
+
* @param amountIn The amount being passed in
|
|
133
|
+
* @returns The exact in trade
|
|
134
|
+
*/
|
|
135
|
+
static async exactIn(route, amountIn) {
|
|
136
|
+
return Trade.fromRoute(route, amountIn, sdk_core_1.TradeType.EXACT_INPUT);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Constructs an exact out trade with the given amount out and route
|
|
140
|
+
* @template TInput The input currency, either Ether or an ERC-20
|
|
141
|
+
* @template TOutput The output currency, either Ether or an ERC-20
|
|
142
|
+
* @param route The route of the exact out trade
|
|
143
|
+
* @param amountOut The amount returned by the trade
|
|
144
|
+
* @returns The exact out trade
|
|
145
|
+
*/
|
|
146
|
+
static async exactOut(route, amountOut) {
|
|
147
|
+
return Trade.fromRoute(route, amountOut, sdk_core_1.TradeType.EXACT_OUTPUT);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Constructs a trade by simulating swaps through the given route
|
|
151
|
+
* @template TInput The input currency, either Ether or an ERC-20.
|
|
152
|
+
* @template TOutput The output currency, either Ether or an ERC-20.
|
|
153
|
+
* @template TTradeType The type of the trade, either exact in or exact out.
|
|
154
|
+
* @param route route to swap through
|
|
155
|
+
* @param amount the amount specified, either input or output, depending on tradeType
|
|
156
|
+
* @param tradeType whether the trade is an exact input or exact output swap
|
|
157
|
+
* @returns The route
|
|
158
|
+
*/
|
|
159
|
+
static async fromRoute(route, amount, tradeType) {
|
|
160
|
+
var _a;
|
|
161
|
+
let inputAmount;
|
|
162
|
+
let outputAmount;
|
|
163
|
+
if (tradeType === sdk_core_1.TradeType.EXACT_INPUT) {
|
|
164
|
+
(0, tiny_invariant_1.default)(amount.currency.equals(route.input), 'INPUT');
|
|
165
|
+
// Account for trades that wrap/unwrap as a first step
|
|
166
|
+
let tokenAmount = (0, pathCurrency_1.amountWithPathCurrency)(amount, route.pools[0]);
|
|
167
|
+
for (let i = 0; i < route.pools.length; i++) {
|
|
168
|
+
const pool = route.pools[i];
|
|
169
|
+
[tokenAmount] = await pool.getOutputAmount(tokenAmount);
|
|
170
|
+
}
|
|
171
|
+
inputAmount = sdk_core_1.CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator);
|
|
172
|
+
outputAmount = sdk_core_1.CurrencyAmount.fromFractionalAmount(route.output, tokenAmount.numerator, tokenAmount.denominator);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
(0, tiny_invariant_1.default)(amount.currency.equals(route.output), 'OUTPUT');
|
|
176
|
+
// Account for trades that wrap/unwrap as a last step
|
|
177
|
+
let tokenAmount = (0, pathCurrency_1.amountWithPathCurrency)(amount, route.pools[route.pools.length - 1]);
|
|
178
|
+
for (let i = route.pools.length - 1; i >= 0; i--) {
|
|
179
|
+
const pool = route.pools[i];
|
|
180
|
+
[tokenAmount] = await pool.getInputAmount(tokenAmount);
|
|
181
|
+
// Special case: if this is the last pool (first in backward iteration) and it's an ETH-WETH pool
|
|
182
|
+
// with ETH as the route output, we need to convert the WETH amount back to ETH
|
|
183
|
+
// so the next pool in the iteration can work with ETH
|
|
184
|
+
// and vice versa if the route output is WETH
|
|
185
|
+
if (i === route.pools.length - 1) {
|
|
186
|
+
// Check if this is an ETH-WETH pool
|
|
187
|
+
const isEthWethPool = pool.currency1.equals(pool.currency0.wrapped);
|
|
188
|
+
if (isEthWethPool) {
|
|
189
|
+
if (route.output.isNative && ((_a = route.pools[i - 1]) === null || _a === void 0 ? void 0 : _a.currency0.isNative)) {
|
|
190
|
+
// Convert WETH amount to ETH for the next pool
|
|
191
|
+
tokenAmount = sdk_core_1.CurrencyAmount.fromFractionalAmount(pool.currency0, // native currency
|
|
192
|
+
tokenAmount.numerator, tokenAmount.denominator);
|
|
193
|
+
}
|
|
194
|
+
else if (route.output.equals(pool.currency1) &&
|
|
195
|
+
route.pools[i - 1] &&
|
|
196
|
+
!route.pools[i - 1].currency0.isNative) {
|
|
197
|
+
// Convert ETH amount to WETH for the next pool
|
|
198
|
+
tokenAmount = sdk_core_1.CurrencyAmount.fromFractionalAmount(pool.currency1, // wrapped currency
|
|
199
|
+
tokenAmount.numerator, tokenAmount.denominator);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
inputAmount = sdk_core_1.CurrencyAmount.fromFractionalAmount(route.input, tokenAmount.numerator, tokenAmount.denominator);
|
|
205
|
+
outputAmount = sdk_core_1.CurrencyAmount.fromFractionalAmount(route.output, amount.numerator, amount.denominator);
|
|
206
|
+
}
|
|
207
|
+
return new Trade({
|
|
208
|
+
routes: [{ inputAmount, outputAmount, route }],
|
|
209
|
+
tradeType,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Constructs a trade from routes by simulating swaps
|
|
214
|
+
*
|
|
215
|
+
* @template TInput The input currency, either Ether or an ERC-20.
|
|
216
|
+
* @template TOutput The output currency, either Ether or an ERC-20.
|
|
217
|
+
* @template TTradeType The type of the trade, either exact in or exact out.
|
|
218
|
+
* @param routes the routes to swap through and how much of the amount should be routed through each
|
|
219
|
+
* @param tradeType whether the trade is an exact input or exact output swap
|
|
220
|
+
* @returns The trade
|
|
221
|
+
*/
|
|
222
|
+
static async fromRoutes(routes, tradeType) {
|
|
223
|
+
const swaps = await Promise.all(routes.map(async ({ amount, route }) => {
|
|
224
|
+
const trade = await Trade.fromRoute(route, amount, tradeType);
|
|
225
|
+
return trade.swaps[0];
|
|
226
|
+
}));
|
|
227
|
+
return new Trade({
|
|
228
|
+
routes: swaps,
|
|
229
|
+
tradeType,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Creates a trade without computing the result of swapping through the route. Useful when you have simulated the trade
|
|
234
|
+
* elsewhere and do not have any tick data
|
|
235
|
+
* @template TInput The input currency, either Ether or an ERC-20
|
|
236
|
+
* @template TOutput The output currency, either Ether or an ERC-20
|
|
237
|
+
* @template TTradeType The type of the trade, either exact in or exact out
|
|
238
|
+
* @param constructorArguments The arguments passed to the trade constructor
|
|
239
|
+
* @returns The unchecked trade
|
|
240
|
+
*/
|
|
241
|
+
static createUncheckedTrade(constructorArguments) {
|
|
242
|
+
return new Trade({
|
|
243
|
+
...constructorArguments,
|
|
244
|
+
routes: [
|
|
245
|
+
{
|
|
246
|
+
inputAmount: constructorArguments.inputAmount,
|
|
247
|
+
outputAmount: constructorArguments.outputAmount,
|
|
248
|
+
route: constructorArguments.route,
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Creates a trade without computing the result of swapping through the routes. Useful when you have simulated the trade
|
|
255
|
+
* elsewhere and do not have any tick data
|
|
256
|
+
* @template TInput The input currency, either Ether or an ERC-20
|
|
257
|
+
* @template TOutput The output currency, either Ether or an ERC-20
|
|
258
|
+
* @template TTradeType The type of the trade, either exact in or exact out
|
|
259
|
+
* @param constructorArguments The arguments passed to the trade constructor
|
|
260
|
+
* @returns The unchecked trade
|
|
261
|
+
*/
|
|
262
|
+
static createUncheckedTradeWithMultipleRoutes(constructorArguments) {
|
|
263
|
+
return new Trade(constructorArguments);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Construct a trade by passing in the pre-computed property values
|
|
267
|
+
* @param routes The routes through which the trade occurs
|
|
268
|
+
* @param tradeType The type of trade, exact input or exact output
|
|
269
|
+
*/
|
|
270
|
+
constructor({ routes, tradeType, }) {
|
|
271
|
+
const inputCurrency = routes[0].inputAmount.currency;
|
|
272
|
+
const outputCurrency = routes[0].outputAmount.currency;
|
|
273
|
+
(0, tiny_invariant_1.default)(routes.every(({ route }) => inputCurrency.equals(route.input)), 'INPUT_CURRENCY_MATCH');
|
|
274
|
+
(0, tiny_invariant_1.default)(routes.every(({ route }) => outputCurrency.equals(route.output)), 'OUTPUT_CURRENCY_MATCH');
|
|
275
|
+
const numPools = routes.map(({ route }) => route.pools.filter(pool => !(0, tokenize_1.isTokenizeConversion)(pool)).length).reduce((total, cur) => total + cur, 0);
|
|
276
|
+
const poolIDSet = new Set();
|
|
277
|
+
for (const { route } of routes) {
|
|
278
|
+
for (const pool of route.pools) {
|
|
279
|
+
if (!(0, tokenize_1.isTokenizeConversion)(pool))
|
|
280
|
+
poolIDSet.add(pool_1.Pool.getPoolId(pool.currency0, pool.currency1, pool.fee, pool.tickSpacing, pool.hooks));
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
(0, tiny_invariant_1.default)(numPools === poolIDSet.size, 'POOLS_DUPLICATED');
|
|
284
|
+
this.swaps = routes;
|
|
285
|
+
this.tradeType = tradeType;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Get the minimum amount that must be received from this trade for the given slippage tolerance
|
|
289
|
+
* @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
|
|
290
|
+
* @returns The amount out
|
|
291
|
+
*/
|
|
292
|
+
minimumAmountOut(slippageTolerance, amountOut = this.outputAmount) {
|
|
293
|
+
(0, tiny_invariant_1.default)(!slippageTolerance.lessThan(internalConstants_1.ZERO), 'SLIPPAGE_TOLERANCE');
|
|
294
|
+
if (this.tradeType === sdk_core_1.TradeType.EXACT_OUTPUT) {
|
|
295
|
+
return amountOut;
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
const slippageAdjustedAmountOut = new sdk_core_1.Fraction(internalConstants_1.ONE)
|
|
299
|
+
.subtract(slippageTolerance)
|
|
300
|
+
.multiply(amountOut.quotient).quotient;
|
|
301
|
+
const clampedAmount = jsbi_1.default.greaterThan(slippageAdjustedAmountOut, jsbi_1.default.BigInt(0))
|
|
302
|
+
? slippageAdjustedAmountOut
|
|
303
|
+
: jsbi_1.default.BigInt(0);
|
|
304
|
+
return sdk_core_1.CurrencyAmount.fromRawAmount(amountOut.currency, clampedAmount);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Get the maximum amount in that can be spent via this trade for the given slippage tolerance
|
|
309
|
+
* @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
|
|
310
|
+
* @returns The amount in
|
|
311
|
+
*/
|
|
312
|
+
maximumAmountIn(slippageTolerance, amountIn = this.inputAmount) {
|
|
313
|
+
(0, tiny_invariant_1.default)(!slippageTolerance.lessThan(internalConstants_1.ZERO), 'SLIPPAGE_TOLERANCE');
|
|
314
|
+
if (this.tradeType === sdk_core_1.TradeType.EXACT_INPUT) {
|
|
315
|
+
return amountIn;
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
const slippageAdjustedAmountIn = new sdk_core_1.Fraction(internalConstants_1.ONE).add(slippageTolerance).multiply(amountIn.quotient).quotient;
|
|
319
|
+
return sdk_core_1.CurrencyAmount.fromRawAmount(amountIn.currency, slippageAdjustedAmountIn);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Return the execution price after accounting for slippage tolerance
|
|
324
|
+
* @param slippageTolerance the allowed tolerated slippage
|
|
325
|
+
* @returns The execution price
|
|
326
|
+
*/
|
|
327
|
+
worstExecutionPrice(slippageTolerance) {
|
|
328
|
+
return new sdk_core_1.Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).quotient, this.minimumAmountOut(slippageTolerance).quotient);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Given a list of pools, and a fixed amount in, returns the top `maxNumResults` trades that go from an input currency
|
|
332
|
+
* amount to an output currency, making at most `maxHops` hops.
|
|
333
|
+
* Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting
|
|
334
|
+
* the amount in among multiple routes.
|
|
335
|
+
* @param pools the pools to consider in finding the best trade
|
|
336
|
+
* @param nextAmountIn exact amount of input currency to spend
|
|
337
|
+
* @param currencyOut the desired currency out
|
|
338
|
+
* @param maxNumResults maximum number of results to return
|
|
339
|
+
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool
|
|
340
|
+
* @param currentPools used in recursion; the current list of pools
|
|
341
|
+
* @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter
|
|
342
|
+
* @param bestTrades used in recursion; the current list of best trades
|
|
343
|
+
* @returns The exact in trade
|
|
344
|
+
*/
|
|
345
|
+
static async bestTradeExactIn(pools, currencyAmountIn, currencyOut, { maxNumResults = 3, maxHops = 3 } = {},
|
|
346
|
+
// used in recursion.
|
|
347
|
+
currentPools = [], nextAmountIn = currencyAmountIn, bestTrades = []) {
|
|
348
|
+
(0, tiny_invariant_1.default)(pools.length > 0, 'POOLS');
|
|
349
|
+
(0, tiny_invariant_1.default)(maxHops > 0, 'MAX_HOPS');
|
|
350
|
+
(0, tiny_invariant_1.default)(currencyAmountIn === nextAmountIn || currentPools.length > 0, 'INVALID_RECURSION');
|
|
351
|
+
const amountIn = nextAmountIn;
|
|
352
|
+
for (let i = 0; i < pools.length; i++) {
|
|
353
|
+
const pool = pools[i];
|
|
354
|
+
// pool irrelevant
|
|
355
|
+
if (!pool.currency0.equals(amountIn.currency) && !pool.currency1.equals(amountIn.currency))
|
|
356
|
+
continue;
|
|
357
|
+
let amountOut;
|
|
358
|
+
try {
|
|
359
|
+
;
|
|
360
|
+
[amountOut] = await pool.getOutputAmount(amountIn);
|
|
361
|
+
}
|
|
362
|
+
catch (error) {
|
|
363
|
+
// input too low
|
|
364
|
+
if (error.isInsufficientInputAmountError) {
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
throw error;
|
|
368
|
+
}
|
|
369
|
+
// we have arrived at the output currency, so this is the final trade of one of the paths
|
|
370
|
+
if (amountOut.currency.equals(currencyOut)) {
|
|
371
|
+
(0, sdk_core_1.sortedInsert)(bestTrades, await Trade.fromRoute(new route_1.Route([...currentPools, pool], currencyAmountIn.currency, currencyOut), currencyAmountIn, sdk_core_1.TradeType.EXACT_INPUT), maxNumResults, tradeComparator);
|
|
372
|
+
}
|
|
373
|
+
else if (maxHops > 1 && pools.length > 1) {
|
|
374
|
+
const poolsExcludingThisPool = pools.slice(0, i).concat(pools.slice(i + 1, pools.length));
|
|
375
|
+
// otherwise, consider all the other paths that lead from this currency as long as we have not exceeded maxHops
|
|
376
|
+
await Trade.bestTradeExactIn(poolsExcludingThisPool, currencyAmountIn, currencyOut, {
|
|
377
|
+
maxNumResults,
|
|
378
|
+
maxHops: maxHops - 1,
|
|
379
|
+
}, [...currentPools, pool], amountOut, bestTrades);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return bestTrades;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* similar to the above method but instead targets a fixed output amount
|
|
386
|
+
* given a list of pools, and a fixed amount out, returns the top `maxNumResults` trades that go from an input currency
|
|
387
|
+
* to an output currency amount, making at most `maxHops` hops
|
|
388
|
+
* note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting
|
|
389
|
+
* the amount in among multiple routes.
|
|
390
|
+
* @param pools the pools to consider in finding the best trade
|
|
391
|
+
* @param currencyIn the currency to spend
|
|
392
|
+
* @param currencyAmountOut the desired currency amount out
|
|
393
|
+
* @param nextAmountOut the exact amount of currency out
|
|
394
|
+
* @param maxNumResults maximum number of results to return
|
|
395
|
+
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool
|
|
396
|
+
* @param currentPools used in recursion; the current list of pools
|
|
397
|
+
* @param bestTrades used in recursion; the current list of best trades
|
|
398
|
+
* @returns The exact out trade
|
|
399
|
+
*/
|
|
400
|
+
static async bestTradeExactOut(pools, currencyIn, currencyAmountOut, { maxNumResults = 3, maxHops = 3 } = {},
|
|
401
|
+
// used in recursion.
|
|
402
|
+
currentPools = [], nextAmountOut = currencyAmountOut, bestTrades = []) {
|
|
403
|
+
(0, tiny_invariant_1.default)(pools.length > 0, 'POOLS');
|
|
404
|
+
(0, tiny_invariant_1.default)(maxHops > 0, 'MAX_HOPS');
|
|
405
|
+
(0, tiny_invariant_1.default)(currencyAmountOut === nextAmountOut || currentPools.length > 0, 'INVALID_RECURSION');
|
|
406
|
+
const amountOut = nextAmountOut;
|
|
407
|
+
for (let i = 0; i < pools.length; i++) {
|
|
408
|
+
const pool = pools[i];
|
|
409
|
+
// pool irrelevant
|
|
410
|
+
if (!pool.currency0.equals(amountOut.currency) && !pool.currency1.equals(amountOut.currency))
|
|
411
|
+
continue;
|
|
412
|
+
let amountIn;
|
|
413
|
+
try {
|
|
414
|
+
;
|
|
415
|
+
[amountIn] = await pool.getInputAmount(amountOut);
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
// not enough liquidity in this pool
|
|
419
|
+
if (error.isInsufficientReservesError) {
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
throw error;
|
|
423
|
+
}
|
|
424
|
+
// we have arrived at the input currency, so this is the first trade of one of the paths
|
|
425
|
+
if (amountIn.currency.equals(currencyIn)) {
|
|
426
|
+
(0, sdk_core_1.sortedInsert)(bestTrades, await Trade.fromRoute(new route_1.Route([pool, ...currentPools], currencyIn, currencyAmountOut.currency), currencyAmountOut, sdk_core_1.TradeType.EXACT_OUTPUT), maxNumResults, tradeComparator);
|
|
427
|
+
}
|
|
428
|
+
else if (maxHops > 1 && pools.length > 1) {
|
|
429
|
+
const poolsExcludingThisPool = pools.slice(0, i).concat(pools.slice(i + 1, pools.length));
|
|
430
|
+
// otherwise, consider all the other paths that arrive at this currency as long as we have not exceeded maxHops
|
|
431
|
+
await Trade.bestTradeExactOut(poolsExcludingThisPool, currencyIn, currencyAmountOut, {
|
|
432
|
+
maxNumResults,
|
|
433
|
+
maxHops: maxHops - 1,
|
|
434
|
+
}, [pool, ...currentPools], amountIn, bestTrades);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return bestTrades;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
exports.Trade = Trade;
|
|
441
|
+
//# sourceMappingURL=trade.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trade.js","sourceRoot":"","sources":["../../../../src/entities/trade.ts"],"names":[],"mappings":";;;;AAAA,0CAAkD;AAClD,uDAA6H;AAC7H,wDAAuB;AACvB,4EAAsC;AACtC,4DAAgD;AAChD,iCAA6B;AAC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C;iBACrB,EACD,CAAC,IAAI,EAAE,GAAG,YAAY,CAAC,EACvB,QAAQ,EACR,UAAU,CACX,CAAA;aACF;SACF;QAED,OAAO,UAAU,CAAA;IACnB,CAAC;CACF;AAnjBD,sBAmjBC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './entities';
|
|
2
|
-
export * from './utils';
|
|
3
|
-
export * from './PositionManager';
|
|
4
|
-
export * from './
|
|
1
|
+
export * from './entities';
|
|
2
|
+
export * from './utils';
|
|
3
|
+
export * from './PositionManager';
|
|
4
|
+
export * from './tokenize';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./entities"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./utils"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./PositionManager"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./tokenize"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAA0B;AAC1B,kDAAuB;AACvB,4DAAiC;AAEjC,qDAA0B"}
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import JSBI from 'jsbi';
|
|
2
|
-
export declare const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000";
|
|
3
|
-
export declare const NEGATIVE_ONE: JSBI;
|
|
4
|
-
export declare const ZERO: JSBI;
|
|
5
|
-
export declare const ONE: JSBI;
|
|
6
|
-
export declare const ONE_ETHER: JSBI;
|
|
7
|
-
export declare const EMPTY_BYTES = "0x";
|
|
8
|
-
export declare const Q96: JSBI;
|
|
9
|
-
export declare const Q192: JSBI;
|
|
10
|
-
export declare const FEE_AMOUNT_LOW = 100;
|
|
11
|
-
export declare const FEE_AMOUNT_MEDIUM = 3000;
|
|
12
|
-
export declare const FEE_AMOUNT_HIGHEST = 10000;
|
|
13
|
-
export declare const TICK_SPACING_TEN = 10;
|
|
14
|
-
export declare const TICK_SPACING_SIXTY = 60;
|
|
15
|
-
export declare const MIN_SLIPPAGE_DECREASE = 0;
|
|
16
|
-
export declare const OPEN_DELTA: import("
|
|
17
|
-
export declare const SQRT_PRICE_1_1: JSBI;
|
|
18
|
-
export declare const EMPTY_HOOK = "0x0000000000000000000000000000000000000000";
|
|
19
|
-
export declare const NATIVE_NOT_SET = "NATIVE_NOT_SET";
|
|
20
|
-
export declare const ZERO_LIQUIDITY = "ZERO_LIQUIDITY";
|
|
21
|
-
export declare const NO_SQRT_PRICE = "NO_SQRT_PRICE";
|
|
22
|
-
export declare const CANNOT_BURN = "CANNOT_BURN";
|
|
23
|
-
/**
|
|
24
|
-
* Function fragments that exist on the PositionManager contract.
|
|
25
|
-
*/
|
|
26
|
-
export declare enum PositionFunctions {
|
|
27
|
-
INITIALIZE_POOL = "initializePool",
|
|
28
|
-
MODIFY_LIQUIDITIES = "modifyLiquidities",
|
|
29
|
-
PERMIT_BATCH = "0x002a3e3a",
|
|
30
|
-
ERC721PERMIT_PERMIT = "0x0f5730f1"
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* The default factory enabled fee amounts, denominated in hundredths of bips.
|
|
34
|
-
*/
|
|
35
|
-
export declare enum FeeAmount {
|
|
36
|
-
LOWEST = 100,
|
|
37
|
-
LOW = 500,
|
|
38
|
-
MEDIUM = 3000,
|
|
39
|
-
HIGH = 10000
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* The default factory tick spacings by fee amount.
|
|
43
|
-
*/
|
|
44
|
-
export declare const TICK_SPACINGS: {
|
|
45
|
-
[amount in FeeAmount]: number;
|
|
46
|
-
};
|
|
1
|
+
import JSBI from 'jsbi';
|
|
2
|
+
export declare const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000";
|
|
3
|
+
export declare const NEGATIVE_ONE: JSBI;
|
|
4
|
+
export declare const ZERO: JSBI;
|
|
5
|
+
export declare const ONE: JSBI;
|
|
6
|
+
export declare const ONE_ETHER: JSBI;
|
|
7
|
+
export declare const EMPTY_BYTES = "0x";
|
|
8
|
+
export declare const Q96: JSBI;
|
|
9
|
+
export declare const Q192: JSBI;
|
|
10
|
+
export declare const FEE_AMOUNT_LOW = 100;
|
|
11
|
+
export declare const FEE_AMOUNT_MEDIUM = 3000;
|
|
12
|
+
export declare const FEE_AMOUNT_HIGHEST = 10000;
|
|
13
|
+
export declare const TICK_SPACING_TEN = 10;
|
|
14
|
+
export declare const TICK_SPACING_SIXTY = 60;
|
|
15
|
+
export declare const MIN_SLIPPAGE_DECREASE = 0;
|
|
16
|
+
export declare const OPEN_DELTA: import("@ethersproject/bignumber").BigNumber;
|
|
17
|
+
export declare const SQRT_PRICE_1_1: JSBI;
|
|
18
|
+
export declare const EMPTY_HOOK = "0x0000000000000000000000000000000000000000";
|
|
19
|
+
export declare const NATIVE_NOT_SET = "NATIVE_NOT_SET";
|
|
20
|
+
export declare const ZERO_LIQUIDITY = "ZERO_LIQUIDITY";
|
|
21
|
+
export declare const NO_SQRT_PRICE = "NO_SQRT_PRICE";
|
|
22
|
+
export declare const CANNOT_BURN = "CANNOT_BURN";
|
|
23
|
+
/**
|
|
24
|
+
* Function fragments that exist on the PositionManager contract.
|
|
25
|
+
*/
|
|
26
|
+
export declare enum PositionFunctions {
|
|
27
|
+
INITIALIZE_POOL = "initializePool",
|
|
28
|
+
MODIFY_LIQUIDITIES = "modifyLiquidities",
|
|
29
|
+
PERMIT_BATCH = "0x002a3e3a",
|
|
30
|
+
ERC721PERMIT_PERMIT = "0x0f5730f1"
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The default factory enabled fee amounts, denominated in hundredths of bips.
|
|
34
|
+
*/
|
|
35
|
+
export declare enum FeeAmount {
|
|
36
|
+
LOWEST = 100,
|
|
37
|
+
LOW = 500,
|
|
38
|
+
MEDIUM = 3000,
|
|
39
|
+
HIGH = 10000
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The default factory tick spacings by fee amount.
|
|
43
|
+
*/
|
|
44
|
+
export declare const TICK_SPACINGS: {
|
|
45
|
+
[amount in FeeAmount]: number;
|
|
46
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TICK_SPACINGS = exports.FeeAmount = exports.PositionFunctions = exports.CANNOT_BURN = exports.NO_SQRT_PRICE = exports.ZERO_LIQUIDITY = exports.NATIVE_NOT_SET = exports.EMPTY_HOOK = exports.SQRT_PRICE_1_1 = exports.OPEN_DELTA = exports.MIN_SLIPPAGE_DECREASE = exports.TICK_SPACING_SIXTY = exports.TICK_SPACING_TEN = exports.FEE_AMOUNT_HIGHEST = exports.FEE_AMOUNT_MEDIUM = exports.FEE_AMOUNT_LOW = exports.Q192 = exports.Q96 = exports.EMPTY_BYTES = exports.ONE_ETHER = exports.ONE = exports.ZERO = exports.NEGATIVE_ONE = exports.ADDRESS_ZERO = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsbi_1 = tslib_1.__importDefault(require("jsbi"));
|
|
6
|
+
const constants_1 = require("@ethersproject/constants");
|
|
7
|
+
const v3_sdk_1 = require("@kittycorn-labs/v3-sdk");
|
|
8
|
+
// constants used internally but not expected to be used externally
|
|
9
|
+
exports.ADDRESS_ZERO = constants_1.AddressZero;
|
|
10
|
+
exports.NEGATIVE_ONE = jsbi_1.default.BigInt(-1);
|
|
11
|
+
exports.ZERO = jsbi_1.default.BigInt(0);
|
|
12
|
+
exports.ONE = jsbi_1.default.BigInt(1);
|
|
13
|
+
exports.ONE_ETHER = jsbi_1.default.exponentiate(jsbi_1.default.BigInt(10), jsbi_1.default.BigInt(18));
|
|
14
|
+
exports.EMPTY_BYTES = '0x';
|
|
15
|
+
// used in liquidity amount math
|
|
16
|
+
exports.Q96 = jsbi_1.default.exponentiate(jsbi_1.default.BigInt(2), jsbi_1.default.BigInt(96));
|
|
17
|
+
exports.Q192 = jsbi_1.default.exponentiate(exports.Q96, jsbi_1.default.BigInt(2));
|
|
18
|
+
// pool setup
|
|
19
|
+
exports.FEE_AMOUNT_LOW = 100;
|
|
20
|
+
exports.FEE_AMOUNT_MEDIUM = 3000;
|
|
21
|
+
exports.FEE_AMOUNT_HIGHEST = 10000;
|
|
22
|
+
exports.TICK_SPACING_TEN = 10;
|
|
23
|
+
exports.TICK_SPACING_SIXTY = 60;
|
|
24
|
+
// used in position manager math
|
|
25
|
+
exports.MIN_SLIPPAGE_DECREASE = 0;
|
|
26
|
+
// used when unwrapping weth in positon manager
|
|
27
|
+
exports.OPEN_DELTA = constants_1.Zero;
|
|
28
|
+
// default prices
|
|
29
|
+
exports.SQRT_PRICE_1_1 = (0, v3_sdk_1.encodeSqrtRatioX96)(1, 1);
|
|
30
|
+
// default hook addresses
|
|
31
|
+
exports.EMPTY_HOOK = '0x0000000000000000000000000000000000000000';
|
|
32
|
+
// error constants
|
|
33
|
+
exports.NATIVE_NOT_SET = 'NATIVE_NOT_SET';
|
|
34
|
+
exports.ZERO_LIQUIDITY = 'ZERO_LIQUIDITY';
|
|
35
|
+
exports.NO_SQRT_PRICE = 'NO_SQRT_PRICE';
|
|
36
|
+
exports.CANNOT_BURN = 'CANNOT_BURN';
|
|
37
|
+
/**
|
|
38
|
+
* Function fragments that exist on the PositionManager contract.
|
|
39
|
+
*/
|
|
40
|
+
var PositionFunctions;
|
|
41
|
+
(function (PositionFunctions) {
|
|
42
|
+
PositionFunctions["INITIALIZE_POOL"] = "initializePool";
|
|
43
|
+
PositionFunctions["MODIFY_LIQUIDITIES"] = "modifyLiquidities";
|
|
44
|
+
// Inherited from PermitForwarder
|
|
45
|
+
PositionFunctions["PERMIT_BATCH"] = "0x002a3e3a";
|
|
46
|
+
// Inherited from ERC721Permit
|
|
47
|
+
PositionFunctions["ERC721PERMIT_PERMIT"] = "0x0f5730f1";
|
|
48
|
+
})(PositionFunctions = exports.PositionFunctions || (exports.PositionFunctions = {}));
|
|
49
|
+
/**
|
|
50
|
+
* The default factory enabled fee amounts, denominated in hundredths of bips.
|
|
51
|
+
*/
|
|
52
|
+
var FeeAmount;
|
|
53
|
+
(function (FeeAmount) {
|
|
54
|
+
FeeAmount[FeeAmount["LOWEST"] = 100] = "LOWEST";
|
|
55
|
+
FeeAmount[FeeAmount["LOW"] = 500] = "LOW";
|
|
56
|
+
FeeAmount[FeeAmount["MEDIUM"] = 3000] = "MEDIUM";
|
|
57
|
+
FeeAmount[FeeAmount["HIGH"] = 10000] = "HIGH";
|
|
58
|
+
})(FeeAmount = exports.FeeAmount || (exports.FeeAmount = {}));
|
|
59
|
+
/**
|
|
60
|
+
* The default factory tick spacings by fee amount.
|
|
61
|
+
*/
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
63
|
+
exports.TICK_SPACINGS = {
|
|
64
|
+
[FeeAmount.LOWEST]: 1,
|
|
65
|
+
[FeeAmount.LOW]: 10,
|
|
66
|
+
[FeeAmount.MEDIUM]: 60,
|
|
67
|
+
[FeeAmount.HIGH]: 200,
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=internalConstants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internalConstants.js","sourceRoot":"","sources":["../../../src/internalConstants.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AACvB,wDAA4D;AAC5D,mDAA2D;AAE3D,mEAAmE;AACtD,QAAA,YAAY,GAAG,uBAAW,CAAA;AAC1B,QAAA,YAAY,GAAG,cAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AAC9B,QAAA,IAAI,GAAG,cAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AACrB,QAAA,GAAG,GAAG,cAAI,CAAC,MAAM,CAAC,CAAC,CAAC,C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