@centurion_project/v3-sdk 3.30.0-ctn.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/LICENSE +21 -0
- package/README.md +13 -0
- package/dist/cjs/src/constants.d.ts +23 -0
- package/dist/cjs/src/constants.js +44 -0
- package/dist/cjs/src/constants.js.map +1 -0
- package/dist/cjs/src/entities/index.d.ts +7 -0
- package/dist/cjs/src/entities/index.js +11 -0
- package/dist/cjs/src/entities/index.js.map +1 -0
- package/dist/cjs/src/entities/pool.d.ts +81 -0
- package/dist/cjs/src/entities/pool.js +142 -0
- package/dist/cjs/src/entities/pool.js.map +1 -0
- package/dist/cjs/src/entities/position.d.ts +131 -0
- package/dist/cjs/src/entities/position.js +248 -0
- package/dist/cjs/src/entities/position.js.map +1 -0
- package/dist/cjs/src/entities/route.d.ts +26 -0
- package/dist/cjs/src/entities/route.js +75 -0
- package/dist/cjs/src/entities/route.js.map +1 -0
- package/dist/cjs/src/entities/tick.d.ts +13 -0
- package/dist/cjs/src/entities/tick.js +17 -0
- package/dist/cjs/src/entities/tick.js.map +1 -0
- package/dist/cjs/src/entities/tickDataProvider.d.ts +31 -0
- package/dist/cjs/src/entities/tickDataProvider.js +18 -0
- package/dist/cjs/src/entities/tickDataProvider.js.map +1 -0
- package/dist/cjs/src/entities/tickListDataProvider.d.ts +15 -0
- package/dist/cjs/src/entities/tickListDataProvider.js +23 -0
- package/dist/cjs/src/entities/tickListDataProvider.js.map +1 -0
- package/dist/cjs/src/entities/trade.d.ts +220 -0
- package/dist/cjs/src/entities/trade.js +440 -0
- package/dist/cjs/src/entities/trade.js.map +1 -0
- package/dist/cjs/src/index.d.ts +10 -0
- package/dist/cjs/src/index.js +14 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/cjs/src/internalConstants.d.ts +6 -0
- package/dist/cjs/src/internalConstants.js +13 -0
- package/dist/cjs/src/internalConstants.js.map +1 -0
- package/dist/cjs/src/multicall.d.ts +10 -0
- package/dist/cjs/src/multicall.js +24 -0
- package/dist/cjs/src/multicall.js.map +1 -0
- package/dist/cjs/src/nonfungiblePositionManager.d.ts +159 -0
- package/dist/cjs/src/nonfungiblePositionManager.js +250 -0
- package/dist/cjs/src/nonfungiblePositionManager.js.map +1 -0
- package/dist/cjs/src/payments.d.ts +24 -0
- package/dist/cjs/src/payments.js +56 -0
- package/dist/cjs/src/payments.js.map +1 -0
- package/dist/cjs/src/quoter.d.ts +37 -0
- package/dist/cjs/src/quoter.js +69 -0
- package/dist/cjs/src/quoter.js.map +1 -0
- package/dist/cjs/src/selfPermit.d.ts +25 -0
- package/dist/cjs/src/selfPermit.js +38 -0
- package/dist/cjs/src/selfPermit.js.map +1 -0
- package/dist/cjs/src/staker.d.ts +101 -0
- package/dist/cjs/src/staker.js +129 -0
- package/dist/cjs/src/staker.js.map +1 -0
- package/dist/cjs/src/swapRouter.d.ts +51 -0
- package/dist/cjs/src/swapRouter.js +145 -0
- package/dist/cjs/src/swapRouter.js.map +1 -0
- package/dist/cjs/src/utils/calldata.d.ts +20 -0
- package/dist/cjs/src/utils/calldata.js +20 -0
- package/dist/cjs/src/utils/calldata.js.map +1 -0
- package/dist/cjs/src/utils/computePoolAddress.d.ts +20 -0
- package/dist/cjs/src/utils/computePoolAddress.js +33 -0
- package/dist/cjs/src/utils/computePoolAddress.js.map +1 -0
- package/dist/cjs/src/utils/encodeRouteToPath.d.ts +8 -0
- package/dist/cjs/src/utils/encodeRouteToPath.js +32 -0
- package/dist/cjs/src/utils/encodeRouteToPath.js.map +1 -0
- package/dist/cjs/src/utils/encodeSqrtRatioX96.d.ts +9 -0
- package/dist/cjs/src/utils/encodeSqrtRatioX96.js +20 -0
- package/dist/cjs/src/utils/encodeSqrtRatioX96.js.map +1 -0
- package/dist/cjs/src/utils/fullMath.d.ts +8 -0
- package/dist/cjs/src/utils/fullMath.js +21 -0
- package/dist/cjs/src/utils/fullMath.js.map +1 -0
- package/dist/cjs/src/utils/index.d.ts +18 -0
- package/dist/cjs/src/utils/index.js +22 -0
- package/dist/cjs/src/utils/index.js.map +1 -0
- package/dist/cjs/src/utils/isSorted.d.ts +7 -0
- package/dist/cjs/src/utils/isSorted.js +19 -0
- package/dist/cjs/src/utils/isSorted.js.map +1 -0
- package/dist/cjs/src/utils/liquidityMath.d.ts +8 -0
- package/dist/cjs/src/utils/liquidityMath.js +22 -0
- package/dist/cjs/src/utils/liquidityMath.js.map +1 -0
- package/dist/cjs/src/utils/maxLiquidityForAmounts.d.ts +14 -0
- package/dist/cjs/src/utils/maxLiquidityForAmounts.js +87 -0
- package/dist/cjs/src/utils/maxLiquidityForAmounts.js.map +1 -0
- package/dist/cjs/src/utils/mostSignificantBit.d.ts +2 -0
- package/dist/cjs/src/utils/mostSignificantBit.js +27 -0
- package/dist/cjs/src/utils/mostSignificantBit.js.map +1 -0
- package/dist/cjs/src/utils/nearestUsableTick.d.ts +6 -0
- package/dist/cjs/src/utils/nearestUsableTick.js +25 -0
- package/dist/cjs/src/utils/nearestUsableTick.js.map +1 -0
- package/dist/cjs/src/utils/position.d.ts +8 -0
- package/dist/cjs/src/utils/position.js +21 -0
- package/dist/cjs/src/utils/position.js.map +1 -0
- package/dist/cjs/src/utils/priceTickConversions.d.ts +15 -0
- package/dist/cjs/src/utils/priceTickConversions.js +50 -0
- package/dist/cjs/src/utils/priceTickConversions.js.map +1 -0
- package/dist/cjs/src/utils/sqrtPriceMath.d.ts +13 -0
- package/dist/cjs/src/utils/sqrtPriceMath.js +95 -0
- package/dist/cjs/src/utils/sqrtPriceMath.js.map +1 -0
- package/dist/cjs/src/utils/swapMath.d.ts +9 -0
- package/dist/cjs/src/utils/swapMath.js +78 -0
- package/dist/cjs/src/utils/swapMath.js.map +1 -0
- package/dist/cjs/src/utils/tickLibrary.d.ts +14 -0
- package/dist/cjs/src/utils/tickLibrary.js +51 -0
- package/dist/cjs/src/utils/tickLibrary.js.map +1 -0
- package/dist/cjs/src/utils/tickList.d.ts +23 -0
- package/dist/cjs/src/utils/tickList.js +108 -0
- package/dist/cjs/src/utils/tickList.js.map +1 -0
- package/dist/cjs/src/utils/tickMath.d.ts +34 -0
- package/dist/cjs/src/utils/tickMath.js +125 -0
- package/dist/cjs/src/utils/tickMath.js.map +1 -0
- package/dist/cjs/src/utils/v3swap.d.ts +8 -0
- package/dist/cjs/src/utils/v3swap.js +85 -0
- package/dist/cjs/src/utils/v3swap.js.map +1 -0
- package/dist/esm/src/constants.d.ts +23 -0
- package/dist/esm/src/constants.js +40 -0
- package/dist/esm/src/constants.js.map +1 -0
- package/dist/esm/src/entities/index.d.ts +7 -0
- package/dist/esm/src/entities/index.js +8 -0
- package/dist/esm/src/entities/index.js.map +1 -0
- package/dist/esm/src/entities/pool.d.ts +81 -0
- package/dist/esm/src/entities/pool.js +137 -0
- package/dist/esm/src/entities/pool.js.map +1 -0
- package/dist/esm/src/entities/position.d.ts +131 -0
- package/dist/esm/src/entities/position.js +243 -0
- package/dist/esm/src/entities/position.js.map +1 -0
- package/dist/esm/src/entities/route.d.ts +26 -0
- package/dist/esm/src/entities/route.js +70 -0
- package/dist/esm/src/entities/route.js.map +1 -0
- package/dist/esm/src/entities/tick.d.ts +13 -0
- package/dist/esm/src/entities/tick.js +12 -0
- package/dist/esm/src/entities/tick.js.map +1 -0
- package/dist/esm/src/entities/tickDataProvider.d.ts +31 -0
- package/dist/esm/src/entities/tickDataProvider.js +14 -0
- package/dist/esm/src/entities/tickDataProvider.js.map +1 -0
- package/dist/esm/src/entities/tickListDataProvider.d.ts +15 -0
- package/dist/esm/src/entities/tickListDataProvider.js +19 -0
- package/dist/esm/src/entities/tickListDataProvider.js.map +1 -0
- package/dist/esm/src/entities/trade.d.ts +220 -0
- package/dist/esm/src/entities/trade.js +434 -0
- package/dist/esm/src/entities/trade.js.map +1 -0
- package/dist/esm/src/index.d.ts +10 -0
- package/dist/esm/src/index.js +11 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/src/internalConstants.d.ts +6 -0
- package/dist/esm/src/internalConstants.js +9 -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 +19 -0
- package/dist/esm/src/multicall.js.map +1 -0
- package/dist/esm/src/nonfungiblePositionManager.d.ts +159 -0
- package/dist/esm/src/nonfungiblePositionManager.js +245 -0
- package/dist/esm/src/nonfungiblePositionManager.js.map +1 -0
- package/dist/esm/src/payments.d.ts +24 -0
- package/dist/esm/src/payments.js +51 -0
- package/dist/esm/src/payments.js.map +1 -0
- package/dist/esm/src/quoter.d.ts +37 -0
- package/dist/esm/src/quoter.js +64 -0
- package/dist/esm/src/quoter.js.map +1 -0
- package/dist/esm/src/selfPermit.d.ts +25 -0
- package/dist/esm/src/selfPermit.js +33 -0
- package/dist/esm/src/selfPermit.js.map +1 -0
- package/dist/esm/src/staker.d.ts +101 -0
- package/dist/esm/src/staker.js +124 -0
- package/dist/esm/src/staker.js.map +1 -0
- package/dist/esm/src/swapRouter.d.ts +51 -0
- package/dist/esm/src/swapRouter.js +140 -0
- package/dist/esm/src/swapRouter.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/computePoolAddress.d.ts +20 -0
- package/dist/esm/src/utils/computePoolAddress.js +29 -0
- package/dist/esm/src/utils/computePoolAddress.js.map +1 -0
- package/dist/esm/src/utils/encodeRouteToPath.d.ts +8 -0
- package/dist/esm/src/utils/encodeRouteToPath.js +28 -0
- package/dist/esm/src/utils/encodeRouteToPath.js.map +1 -0
- package/dist/esm/src/utils/encodeSqrtRatioX96.d.ts +9 -0
- package/dist/esm/src/utils/encodeSqrtRatioX96.js +15 -0
- package/dist/esm/src/utils/encodeSqrtRatioX96.js.map +1 -0
- package/dist/esm/src/utils/fullMath.d.ts +8 -0
- package/dist/esm/src/utils/fullMath.js +16 -0
- package/dist/esm/src/utils/fullMath.js.map +1 -0
- package/dist/esm/src/utils/index.d.ts +18 -0
- package/dist/esm/src/utils/index.js +19 -0
- package/dist/esm/src/utils/index.js.map +1 -0
- package/dist/esm/src/utils/isSorted.d.ts +7 -0
- package/dist/esm/src/utils/isSorted.js +15 -0
- package/dist/esm/src/utils/isSorted.js.map +1 -0
- package/dist/esm/src/utils/liquidityMath.d.ts +8 -0
- package/dist/esm/src/utils/liquidityMath.js +17 -0
- package/dist/esm/src/utils/liquidityMath.js.map +1 -0
- package/dist/esm/src/utils/maxLiquidityForAmounts.d.ts +14 -0
- package/dist/esm/src/utils/maxLiquidityForAmounts.js +82 -0
- package/dist/esm/src/utils/maxLiquidityForAmounts.js.map +1 -0
- package/dist/esm/src/utils/mostSignificantBit.d.ts +2 -0
- package/dist/esm/src/utils/mostSignificantBit.js +22 -0
- package/dist/esm/src/utils/mostSignificantBit.js.map +1 -0
- package/dist/esm/src/utils/nearestUsableTick.d.ts +6 -0
- package/dist/esm/src/utils/nearestUsableTick.js +20 -0
- package/dist/esm/src/utils/nearestUsableTick.js.map +1 -0
- package/dist/esm/src/utils/position.d.ts +8 -0
- package/dist/esm/src/utils/position.js +16 -0
- package/dist/esm/src/utils/position.js.map +1 -0
- package/dist/esm/src/utils/priceTickConversions.d.ts +15 -0
- package/dist/esm/src/utils/priceTickConversions.js +44 -0
- package/dist/esm/src/utils/priceTickConversions.js.map +1 -0
- package/dist/esm/src/utils/sqrtPriceMath.d.ts +13 -0
- package/dist/esm/src/utils/sqrtPriceMath.js +90 -0
- package/dist/esm/src/utils/sqrtPriceMath.js.map +1 -0
- package/dist/esm/src/utils/swapMath.d.ts +9 -0
- package/dist/esm/src/utils/swapMath.js +73 -0
- package/dist/esm/src/utils/swapMath.js.map +1 -0
- package/dist/esm/src/utils/tickLibrary.d.ts +14 -0
- package/dist/esm/src/utils/tickLibrary.js +45 -0
- package/dist/esm/src/utils/tickLibrary.js.map +1 -0
- package/dist/esm/src/utils/tickList.d.ts +23 -0
- package/dist/esm/src/utils/tickList.js +103 -0
- package/dist/esm/src/utils/tickList.js.map +1 -0
- package/dist/esm/src/utils/tickMath.d.ts +34 -0
- package/dist/esm/src/utils/tickMath.js +120 -0
- package/dist/esm/src/utils/tickMath.js.map +1 -0
- package/dist/esm/src/utils/v3swap.d.ts +8 -0
- package/dist/esm/src/utils/v3swap.js +80 -0
- package/dist/esm/src/utils/v3swap.js.map +1 -0
- package/dist/types/src/constants.d.ts +23 -0
- package/dist/types/src/entities/index.d.ts +7 -0
- package/dist/types/src/entities/pool.d.ts +81 -0
- package/dist/types/src/entities/position.d.ts +131 -0
- package/dist/types/src/entities/route.d.ts +26 -0
- package/dist/types/src/entities/tick.d.ts +13 -0
- package/dist/types/src/entities/tickDataProvider.d.ts +31 -0
- package/dist/types/src/entities/tickListDataProvider.d.ts +15 -0
- package/dist/types/src/entities/trade.d.ts +220 -0
- package/dist/types/src/index.d.ts +10 -0
- package/dist/types/src/internalConstants.d.ts +6 -0
- package/dist/types/src/multicall.d.ts +10 -0
- package/dist/types/src/nonfungiblePositionManager.d.ts +159 -0
- package/dist/types/src/payments.d.ts +24 -0
- package/dist/types/src/quoter.d.ts +37 -0
- package/dist/types/src/selfPermit.d.ts +25 -0
- package/dist/types/src/staker.d.ts +101 -0
- package/dist/types/src/swapRouter.d.ts +51 -0
- package/dist/types/src/utils/calldata.d.ts +20 -0
- package/dist/types/src/utils/computePoolAddress.d.ts +20 -0
- package/dist/types/src/utils/encodeRouteToPath.d.ts +8 -0
- package/dist/types/src/utils/encodeSqrtRatioX96.d.ts +9 -0
- package/dist/types/src/utils/fullMath.d.ts +8 -0
- package/dist/types/src/utils/index.d.ts +18 -0
- package/dist/types/src/utils/isSorted.d.ts +7 -0
- package/dist/types/src/utils/liquidityMath.d.ts +8 -0
- package/dist/types/src/utils/maxLiquidityForAmounts.d.ts +14 -0
- package/dist/types/src/utils/mostSignificantBit.d.ts +2 -0
- package/dist/types/src/utils/nearestUsableTick.d.ts +6 -0
- package/dist/types/src/utils/position.d.ts +8 -0
- package/dist/types/src/utils/priceTickConversions.d.ts +15 -0
- package/dist/types/src/utils/sqrtPriceMath.d.ts +13 -0
- package/dist/types/src/utils/swapMath.d.ts +9 -0
- package/dist/types/src/utils/tickLibrary.d.ts +14 -0
- package/dist/types/src/utils/tickList.d.ts +23 -0
- package/dist/types/src/utils/tickMath.d.ts +34 -0
- package/dist/types/src/utils/v3swap.d.ts +8 -0
- package/package.json +72 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toHex = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsbi_1 = tslib_1.__importDefault(require("jsbi"));
|
|
6
|
+
/**
|
|
7
|
+
* Converts a big int to a hex string
|
|
8
|
+
* @param bigintIsh
|
|
9
|
+
* @returns The hex encoded calldata
|
|
10
|
+
*/
|
|
11
|
+
function toHex(bigintIsh) {
|
|
12
|
+
const bigInt = jsbi_1.default.BigInt(bigintIsh);
|
|
13
|
+
let hex = bigInt.toString(16);
|
|
14
|
+
if (hex.length % 2 !== 0) {
|
|
15
|
+
hex = `0${hex}`;
|
|
16
|
+
}
|
|
17
|
+
return `0x${hex}`;
|
|
18
|
+
}
|
|
19
|
+
exports.toHex = toHex;
|
|
20
|
+
//# sourceMappingURL=calldata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calldata.js","sourceRoot":"","sources":["../../../../src/utils/calldata.ts"],"names":[],"mappings":";;;;AACA,wDAAuB;AAgBvB;;;;GAIG;AACH,SAAgB,KAAK,CAAC,SAAoB;IACxC,MAAM,MAAM,GAAG,cAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;IACrC,IAAI,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IAC7B,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE;QACxB,GAAG,GAAG,IAAI,GAAG,EAAE,CAAA;KAChB;IACD,OAAO,KAAK,GAAG,EAAE,CAAA;AACnB,CAAC;AAPD,sBAOC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ChainId, Token } from '@centurion_project/sdk-core';
|
|
2
|
+
import { FeeAmount } from '../constants';
|
|
3
|
+
/**
|
|
4
|
+
* Computes a pool address
|
|
5
|
+
* @param factoryAddress The Uniswap V3 factory address
|
|
6
|
+
* @param tokenA The first token of the pair, irrespective of sort order
|
|
7
|
+
* @param tokenB The second token of the pair, irrespective of sort order
|
|
8
|
+
* @param fee The fee tier of the pool
|
|
9
|
+
* @param initCodeHashManualOverride Override the init code hash used to compute the pool address if necessary
|
|
10
|
+
* @param chainId
|
|
11
|
+
* @returns The pool address
|
|
12
|
+
*/
|
|
13
|
+
export declare function computePoolAddress({ factoryAddress, tokenA, tokenB, fee, initCodeHashManualOverride, chainId, }: {
|
|
14
|
+
factoryAddress: string;
|
|
15
|
+
tokenA: Token;
|
|
16
|
+
tokenB: Token;
|
|
17
|
+
fee: FeeAmount;
|
|
18
|
+
initCodeHashManualOverride?: string;
|
|
19
|
+
chainId?: ChainId;
|
|
20
|
+
}): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computePoolAddress = void 0;
|
|
4
|
+
const abi_1 = require("@ethersproject/abi");
|
|
5
|
+
const address_1 = require("@ethersproject/address");
|
|
6
|
+
const solidity_1 = require("@ethersproject/solidity");
|
|
7
|
+
const sdk_core_1 = require("@centurion_project/sdk-core");
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
/**
|
|
10
|
+
* Computes a pool address
|
|
11
|
+
* @param factoryAddress The Uniswap V3 factory address
|
|
12
|
+
* @param tokenA The first token of the pair, irrespective of sort order
|
|
13
|
+
* @param tokenB The second token of the pair, irrespective of sort order
|
|
14
|
+
* @param fee The fee tier of the pool
|
|
15
|
+
* @param initCodeHashManualOverride Override the init code hash used to compute the pool address if necessary
|
|
16
|
+
* @param chainId
|
|
17
|
+
* @returns The pool address
|
|
18
|
+
*/
|
|
19
|
+
function computePoolAddress({ factoryAddress, tokenA, tokenB, fee, initCodeHashManualOverride, chainId, }) {
|
|
20
|
+
const [token0, token1] = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA]; // does safety checks
|
|
21
|
+
const salt = (0, solidity_1.keccak256)(['bytes'], [abi_1.defaultAbiCoder.encode(['address', 'address', 'uint24'], [token0.address, token1.address, fee])]);
|
|
22
|
+
const initCodeHash = initCodeHashManualOverride !== null && initCodeHashManualOverride !== void 0 ? initCodeHashManualOverride : (0, constants_1.poolInitCodeHash)(chainId);
|
|
23
|
+
// ZKSync uses a different create2 address computation
|
|
24
|
+
// Most likely all ZKEVM chains will use the different computation from standard create2
|
|
25
|
+
switch (chainId) {
|
|
26
|
+
case sdk_core_1.ChainId.ZKSYNC:
|
|
27
|
+
return (0, sdk_core_1.computeZksyncCreate2Address)(factoryAddress, initCodeHash, salt);
|
|
28
|
+
default:
|
|
29
|
+
return (0, address_1.getCreate2Address)(factoryAddress, salt, initCodeHash);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.computePoolAddress = computePoolAddress;
|
|
33
|
+
//# sourceMappingURL=computePoolAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computePoolAddress.js","sourceRoot":"","sources":["../../../../src/utils/computePoolAddress.ts"],"names":[],"mappings":";;;AAAA,4CAAoD;AACpD,oDAA0D;AAC1D,sDAAmD;AACnD,0DAAyF;AACzF,4CAA0D;AAE1D;;;;;;;;;GASG;AACH,SAAgB,kBAAkB,CAAC,EACjC,cAAc,EACd,MAAM,EACN,MAAM,EACN,GAAG,EACH,0BAA0B,EAC1B,OAAO,GAQR;IACC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA,CAAC,qBAAqB;IAC/G,MAAM,IAAI,GAAG,IAAA,oBAAS,EACpB,CAAC,OAAO,CAAC,EACT,CAAC,qBAAe,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAClG,CAAA;IACD,MAAM,YAAY,GAAG,0BAA0B,aAA1B,0BAA0B,cAA1B,0BAA0B,GAAI,IAAA,4BAAgB,EAAC,OAAO,CAAC,CAAA;IAE5E,sDAAsD;IACtD,wFAAwF;IACxF,QAAQ,OAAO,EAAE;QACf,KAAK,kBAAO,CAAC,MAAM;YACjB,OAAO,IAAA,sCAA2B,EAAC,cAAc,EAAE,YAAY,EAAE,IAAI,CAAC,CAAA;QACxE;YACE,OAAO,IAAA,2BAAiB,EAAC,cAAc,EAAE,IAAI,EAAE,YAAY,CAAC,CAAA;KAC/D;AACH,CAAC;AA9BD,gDA8BC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Currency } from '@centurion_project/sdk-core';
|
|
2
|
+
import { Route } from '../entities/route';
|
|
3
|
+
/**
|
|
4
|
+
* Converts a route to a hex encoded path
|
|
5
|
+
* @param route the v3 path to convert to an encoded path
|
|
6
|
+
* @param exactOutput whether the route should be encoded in reverse, for making exact output swaps
|
|
7
|
+
*/
|
|
8
|
+
export declare function encodeRouteToPath(route: Route<Currency, Currency>, exactOutput: boolean): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeRouteToPath = void 0;
|
|
4
|
+
const solidity_1 = require("@ethersproject/solidity");
|
|
5
|
+
/**
|
|
6
|
+
* Converts a route to a hex encoded path
|
|
7
|
+
* @param route the v3 path to convert to an encoded path
|
|
8
|
+
* @param exactOutput whether the route should be encoded in reverse, for making exact output swaps
|
|
9
|
+
*/
|
|
10
|
+
function encodeRouteToPath(route, exactOutput) {
|
|
11
|
+
const firstInputToken = route.input.wrapped;
|
|
12
|
+
const { path, types } = route.pools.reduce(({ inputToken, path, types }, pool, index) => {
|
|
13
|
+
const outputToken = pool.token0.equals(inputToken) ? pool.token1 : pool.token0;
|
|
14
|
+
if (index === 0) {
|
|
15
|
+
return {
|
|
16
|
+
inputToken: outputToken,
|
|
17
|
+
types: ['address', 'uint24', 'address'],
|
|
18
|
+
path: [inputToken.address, pool.fee, outputToken.address],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return {
|
|
23
|
+
inputToken: outputToken,
|
|
24
|
+
types: [...types, 'uint24', 'address'],
|
|
25
|
+
path: [...path, pool.fee, outputToken.address],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}, { inputToken: firstInputToken, path: [], types: [] });
|
|
29
|
+
return exactOutput ? (0, solidity_1.pack)(types.reverse(), path.reverse()) : (0, solidity_1.pack)(types, path);
|
|
30
|
+
}
|
|
31
|
+
exports.encodeRouteToPath = encodeRouteToPath;
|
|
32
|
+
//# sourceMappingURL=encodeRouteToPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encodeRouteToPath.js","sourceRoot":"","sources":["../../../../src/utils/encodeRouteToPath.ts"],"names":[],"mappings":";;;AAAA,sDAA8C;AAK9C;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,KAAgC,EAAE,WAAoB;IACtF,MAAM,eAAe,GAAU,KAAK,CAAC,KAAK,CAAC,OAAO,CAAA;IAElD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CACxC,CACE,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAqE,EAC9F,IAAU,EACV,KAAK,EAC8D,EAAE;QACrE,MAAM,WAAW,GAAU,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAA;QACrF,IAAI,KAAK,KAAK,CAAC,EAAE;YACf,OAAO;gBACL,UAAU,EAAE,WAAW;gBACvB,KAAK,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,CAAC;gBACvC,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,OAAO,CAAC;aAC1D,CAAA;SACF;aAAM;YACL,OAAO;gBACL,UAAU,EAAE,WAAW;gBACvB,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC;gBACtC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,OAAO,CAAC;aAC/C,CAAA;SACF;IACH,CAAC,EACD,EAAE,UAAU,EAAE,eAAe,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CACrD,CAAA;IAED,OAAO,WAAW,CAAC,CAAC,CAAC,IAAA,eAAI,EAAC,KAAK,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,IAAA,eAAI,EAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AAChF,CAAC;AA5BD,8CA4BC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import JSBI from 'jsbi';
|
|
2
|
+
import { BigintIsh } from '@centurion_project/sdk-core';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the sqrt ratio as a Q64.96 corresponding to a given ratio of amount1 and amount0
|
|
5
|
+
* @param amount1 The numerator amount i.e., the amount of token1
|
|
6
|
+
* @param amount0 The denominator amount i.e., the amount of token0
|
|
7
|
+
* @returns The sqrt ratio
|
|
8
|
+
*/
|
|
9
|
+
export declare function encodeSqrtRatioX96(amount1: BigintIsh, amount0: BigintIsh): JSBI;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeSqrtRatioX96 = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsbi_1 = tslib_1.__importDefault(require("jsbi"));
|
|
6
|
+
const sdk_core_1 = require("@centurion_project/sdk-core");
|
|
7
|
+
/**
|
|
8
|
+
* Returns the sqrt ratio as a Q64.96 corresponding to a given ratio of amount1 and amount0
|
|
9
|
+
* @param amount1 The numerator amount i.e., the amount of token1
|
|
10
|
+
* @param amount0 The denominator amount i.e., the amount of token0
|
|
11
|
+
* @returns The sqrt ratio
|
|
12
|
+
*/
|
|
13
|
+
function encodeSqrtRatioX96(amount1, amount0) {
|
|
14
|
+
const numerator = jsbi_1.default.leftShift(jsbi_1.default.BigInt(amount1), jsbi_1.default.BigInt(192));
|
|
15
|
+
const denominator = jsbi_1.default.BigInt(amount0);
|
|
16
|
+
const ratioX192 = jsbi_1.default.divide(numerator, denominator);
|
|
17
|
+
return (0, sdk_core_1.sqrt)(ratioX192);
|
|
18
|
+
}
|
|
19
|
+
exports.encodeSqrtRatioX96 = encodeSqrtRatioX96;
|
|
20
|
+
//# sourceMappingURL=encodeSqrtRatioX96.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encodeSqrtRatioX96.js","sourceRoot":"","sources":["../../../../src/utils/encodeSqrtRatioX96.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AACvB,0DAA6D;AAE7D;;;;;GAKG;AAEH,SAAgB,kBAAkB,CAAC,OAAkB,EAAE,OAAkB;IACvE,MAAM,SAAS,GAAG,cAAI,CAAC,SAAS,CAAC,cAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,cAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;IACxE,MAAM,WAAW,GAAG,cAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACxC,MAAM,SAAS,GAAG,cAAI,CAAC,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;IACrD,OAAO,IAAA,eAAI,EAAC,SAAS,CAAC,CAAA;AACxB,CAAC;AALD,gDAKC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FullMath = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsbi_1 = tslib_1.__importDefault(require("jsbi"));
|
|
6
|
+
const internalConstants_1 = require("../internalConstants");
|
|
7
|
+
class FullMath {
|
|
8
|
+
/**
|
|
9
|
+
* Cannot be constructed.
|
|
10
|
+
*/
|
|
11
|
+
constructor() { }
|
|
12
|
+
static mulDivRoundingUp(a, b, denominator) {
|
|
13
|
+
const product = jsbi_1.default.multiply(a, b);
|
|
14
|
+
let result = jsbi_1.default.divide(product, denominator);
|
|
15
|
+
if (jsbi_1.default.notEqual(jsbi_1.default.remainder(product, denominator), internalConstants_1.ZERO))
|
|
16
|
+
result = jsbi_1.default.add(result, internalConstants_1.ONE);
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.FullMath = FullMath;
|
|
21
|
+
//# sourceMappingURL=fullMath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fullMath.js","sourceRoot":"","sources":["../../../../src/utils/fullMath.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AACvB,4DAAgD;AAEhD,MAAsB,QAAQ;IAC5B;;OAEG;IACH,gBAAuB,CAAC;IAEjB,MAAM,CAAC,gBAAgB,CAAC,CAAO,EAAE,CAAO,EAAE,WAAiB;QAChE,MAAM,OAAO,GAAG,cAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QACnC,IAAI,MAAM,GAAG,cAAI,CAAC,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;QAC9C,IAAI,cAAI,CAAC,QAAQ,CAAC,cAAI,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE,wBAAI,CAAC;YAAE,MAAM,GAAG,cAAI,CAAC,GAAG,CAAC,MAAM,EAAE,uBAAG,CAAC,CAAA;QAC7F,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAZD,4BAYC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './calldata';
|
|
2
|
+
export * from './computePoolAddress';
|
|
3
|
+
export * from './encodeRouteToPath';
|
|
4
|
+
export * from './encodeSqrtRatioX96';
|
|
5
|
+
export * from './fullMath';
|
|
6
|
+
export * from './isSorted';
|
|
7
|
+
export * from './liquidityMath';
|
|
8
|
+
export * from './maxLiquidityForAmounts';
|
|
9
|
+
export * from './mostSignificantBit';
|
|
10
|
+
export * from './nearestUsableTick';
|
|
11
|
+
export * from './position';
|
|
12
|
+
export * from './priceTickConversions';
|
|
13
|
+
export * from './sqrtPriceMath';
|
|
14
|
+
export * from './v3swap';
|
|
15
|
+
export * from './swapMath';
|
|
16
|
+
export * from './tickLibrary';
|
|
17
|
+
export * from './tickList';
|
|
18
|
+
export * from './tickMath';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./calldata"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./computePoolAddress"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./encodeRouteToPath"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./encodeSqrtRatioX96"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./fullMath"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./isSorted"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./liquidityMath"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./maxLiquidityForAmounts"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./mostSignificantBit"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./nearestUsableTick"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./position"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./priceTickConversions"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./sqrtPriceMath"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./v3swap"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./swapMath"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./tickLibrary"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./tickList"), exports);
|
|
21
|
+
tslib_1.__exportStar(require("./tickMath"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,qDAA0B;AAC1B,+DAAoC;AACpC,8DAAmC;AACnC,+DAAoC;AACpC,qDAA0B;AAC1B,qDAA0B;AAC1B,0DAA+B;AAC/B,mEAAwC;AACxC,+DAAoC;AACpC,8DAAmC;AACnC,qDAA0B;AAC1B,iEAAsC;AACtC,0DAA+B;AAC/B,mDAAwB;AACxB,qDAA0B;AAC1B,wDAA6B;AAC7B,qDAA0B;AAC1B,qDAA0B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSorted = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Determines if a tick list is sorted
|
|
6
|
+
* @param list The tick list
|
|
7
|
+
* @param comparator The comparator
|
|
8
|
+
* @returns true if sorted
|
|
9
|
+
*/
|
|
10
|
+
function isSorted(list, comparator) {
|
|
11
|
+
for (let i = 0; i < list.length - 1; i++) {
|
|
12
|
+
if (comparator(list[i], list[i + 1]) > 0) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
exports.isSorted = isSorted;
|
|
19
|
+
//# sourceMappingURL=isSorted.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isSorted.js","sourceRoot":"","sources":["../../../../src/utils/isSorted.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,SAAgB,QAAQ,CAAI,IAAc,EAAE,UAAkC;IAC5E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;QACxC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE;YACxC,OAAO,KAAK,CAAA;SACb;KACF;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAPD,4BAOC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LiquidityMath = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsbi_1 = tslib_1.__importDefault(require("jsbi"));
|
|
6
|
+
const internalConstants_1 = require("../internalConstants");
|
|
7
|
+
class LiquidityMath {
|
|
8
|
+
/**
|
|
9
|
+
* Cannot be constructed.
|
|
10
|
+
*/
|
|
11
|
+
constructor() { }
|
|
12
|
+
static addDelta(x, y) {
|
|
13
|
+
if (jsbi_1.default.lessThan(y, internalConstants_1.ZERO)) {
|
|
14
|
+
return jsbi_1.default.subtract(x, jsbi_1.default.multiply(y, internalConstants_1.NEGATIVE_ONE));
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return jsbi_1.default.add(x, y);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.LiquidityMath = LiquidityMath;
|
|
22
|
+
//# sourceMappingURL=liquidityMath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquidityMath.js","sourceRoot":"","sources":["../../../../src/utils/liquidityMath.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AACvB,4DAAyD;AAEzD,MAAsB,aAAa;IACjC;;OAEG;IACH,gBAAuB,CAAC;IAEjB,MAAM,CAAC,QAAQ,CAAC,CAAO,EAAE,CAAO;QACrC,IAAI,cAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,wBAAI,CAAC,EAAE;YAC1B,OAAO,cAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,cAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,gCAAY,CAAC,CAAC,CAAA;SACxD;aAAM;YACL,OAAO,cAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;SACtB;IACH,CAAC;CACF;AAbD,sCAaC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BigintIsh } from '@centurion_project/sdk-core';
|
|
2
|
+
import JSBI from 'jsbi';
|
|
3
|
+
/**
|
|
4
|
+
* Computes the maximum amount of liquidity received for a given amount of token0, token1,
|
|
5
|
+
* and the prices at the tick boundaries.
|
|
6
|
+
* @param sqrtRatioCurrentX96 the current price
|
|
7
|
+
* @param sqrtRatioAX96 price at lower boundary
|
|
8
|
+
* @param sqrtRatioBX96 price at upper boundary
|
|
9
|
+
* @param amount0 token0 amount
|
|
10
|
+
* @param amount1 token1 amount
|
|
11
|
+
* @param useFullPrecision if false, liquidity will be maximized according to what the router can calculate,
|
|
12
|
+
* not what core can theoretically support
|
|
13
|
+
*/
|
|
14
|
+
export declare function maxLiquidityForAmounts(sqrtRatioCurrentX96: JSBI, sqrtRatioAX96: JSBI, sqrtRatioBX96: JSBI, amount0: BigintIsh, amount1: BigintIsh, useFullPrecision: boolean): JSBI;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.maxLiquidityForAmounts = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsbi_1 = tslib_1.__importDefault(require("jsbi"));
|
|
6
|
+
const internalConstants_1 = require("../internalConstants");
|
|
7
|
+
/**
|
|
8
|
+
* Returns an imprecise maximum amount of liquidity received for a given amount of token 0.
|
|
9
|
+
* This function is available to accommodate LiquidityAmounts#getLiquidityForAmount0 in the v3 periphery,
|
|
10
|
+
* which could be more precise by at least 32 bits by dividing by Q64 instead of Q96 in the intermediate step,
|
|
11
|
+
* and shifting the subtracted ratio left by 32 bits. This imprecise calculation will likely be replaced in a future
|
|
12
|
+
* v3 router contract.
|
|
13
|
+
* @param sqrtRatioAX96 The price at the lower boundary
|
|
14
|
+
* @param sqrtRatioBX96 The price at the upper boundary
|
|
15
|
+
* @param amount0 The token0 amount
|
|
16
|
+
* @returns liquidity for amount0, imprecise
|
|
17
|
+
*/
|
|
18
|
+
function maxLiquidityForAmount0Imprecise(sqrtRatioAX96, sqrtRatioBX96, amount0) {
|
|
19
|
+
if (jsbi_1.default.greaterThan(sqrtRatioAX96, sqrtRatioBX96)) {
|
|
20
|
+
;
|
|
21
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
22
|
+
}
|
|
23
|
+
const intermediate = jsbi_1.default.divide(jsbi_1.default.multiply(sqrtRatioAX96, sqrtRatioBX96), internalConstants_1.Q96);
|
|
24
|
+
return jsbi_1.default.divide(jsbi_1.default.multiply(jsbi_1.default.BigInt(amount0), intermediate), jsbi_1.default.subtract(sqrtRatioBX96, sqrtRatioAX96));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Returns a precise maximum amount of liquidity received for a given amount of token 0 by dividing by Q64 instead of Q96 in the intermediate step,
|
|
28
|
+
* and shifting the subtracted ratio left by 32 bits.
|
|
29
|
+
* @param sqrtRatioAX96 The price at the lower boundary
|
|
30
|
+
* @param sqrtRatioBX96 The price at the upper boundary
|
|
31
|
+
* @param amount0 The token0 amount
|
|
32
|
+
* @returns liquidity for amount0, precise
|
|
33
|
+
*/
|
|
34
|
+
function maxLiquidityForAmount0Precise(sqrtRatioAX96, sqrtRatioBX96, amount0) {
|
|
35
|
+
if (jsbi_1.default.greaterThan(sqrtRatioAX96, sqrtRatioBX96)) {
|
|
36
|
+
;
|
|
37
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
38
|
+
}
|
|
39
|
+
const numerator = jsbi_1.default.multiply(jsbi_1.default.multiply(jsbi_1.default.BigInt(amount0), sqrtRatioAX96), sqrtRatioBX96);
|
|
40
|
+
const denominator = jsbi_1.default.multiply(internalConstants_1.Q96, jsbi_1.default.subtract(sqrtRatioBX96, sqrtRatioAX96));
|
|
41
|
+
return jsbi_1.default.divide(numerator, denominator);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Computes the maximum amount of liquidity received for a given amount of token1
|
|
45
|
+
* @param sqrtRatioAX96 The price at the lower tick boundary
|
|
46
|
+
* @param sqrtRatioBX96 The price at the upper tick boundary
|
|
47
|
+
* @param amount1 The token1 amount
|
|
48
|
+
* @returns liquidity for amount1
|
|
49
|
+
*/
|
|
50
|
+
function maxLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1) {
|
|
51
|
+
if (jsbi_1.default.greaterThan(sqrtRatioAX96, sqrtRatioBX96)) {
|
|
52
|
+
;
|
|
53
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
54
|
+
}
|
|
55
|
+
return jsbi_1.default.divide(jsbi_1.default.multiply(jsbi_1.default.BigInt(amount1), internalConstants_1.Q96), jsbi_1.default.subtract(sqrtRatioBX96, sqrtRatioAX96));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Computes the maximum amount of liquidity received for a given amount of token0, token1,
|
|
59
|
+
* and the prices at the tick boundaries.
|
|
60
|
+
* @param sqrtRatioCurrentX96 the current price
|
|
61
|
+
* @param sqrtRatioAX96 price at lower boundary
|
|
62
|
+
* @param sqrtRatioBX96 price at upper boundary
|
|
63
|
+
* @param amount0 token0 amount
|
|
64
|
+
* @param amount1 token1 amount
|
|
65
|
+
* @param useFullPrecision if false, liquidity will be maximized according to what the router can calculate,
|
|
66
|
+
* not what core can theoretically support
|
|
67
|
+
*/
|
|
68
|
+
function maxLiquidityForAmounts(sqrtRatioCurrentX96, sqrtRatioAX96, sqrtRatioBX96, amount0, amount1, useFullPrecision) {
|
|
69
|
+
if (jsbi_1.default.greaterThan(sqrtRatioAX96, sqrtRatioBX96)) {
|
|
70
|
+
;
|
|
71
|
+
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
72
|
+
}
|
|
73
|
+
const maxLiquidityForAmount0 = useFullPrecision ? maxLiquidityForAmount0Precise : maxLiquidityForAmount0Imprecise;
|
|
74
|
+
if (jsbi_1.default.lessThanOrEqual(sqrtRatioCurrentX96, sqrtRatioAX96)) {
|
|
75
|
+
return maxLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0);
|
|
76
|
+
}
|
|
77
|
+
else if (jsbi_1.default.lessThan(sqrtRatioCurrentX96, sqrtRatioBX96)) {
|
|
78
|
+
const liquidity0 = maxLiquidityForAmount0(sqrtRatioCurrentX96, sqrtRatioBX96, amount0);
|
|
79
|
+
const liquidity1 = maxLiquidityForAmount1(sqrtRatioAX96, sqrtRatioCurrentX96, amount1);
|
|
80
|
+
return jsbi_1.default.lessThan(liquidity0, liquidity1) ? liquidity0 : liquidity1;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return maxLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.maxLiquidityForAmounts = maxLiquidityForAmounts;
|
|
87
|
+
//# sourceMappingURL=maxLiquidityForAmounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maxLiquidityForAmounts.js","sourceRoot":"","sources":["../../../../src/utils/maxLiquidityForAmounts.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mostSignificantBit = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const sdk_core_1 = require("@centurion_project/sdk-core");
|
|
6
|
+
const jsbi_1 = tslib_1.__importDefault(require("jsbi"));
|
|
7
|
+
const tiny_invariant_1 = tslib_1.__importDefault(require("tiny-invariant"));
|
|
8
|
+
const internalConstants_1 = require("../internalConstants");
|
|
9
|
+
const TWO = jsbi_1.default.BigInt(2);
|
|
10
|
+
const POWERS_OF_2 = [128, 64, 32, 16, 8, 4, 2, 1].map((pow) => [
|
|
11
|
+
pow,
|
|
12
|
+
jsbi_1.default.exponentiate(TWO, jsbi_1.default.BigInt(pow)),
|
|
13
|
+
]);
|
|
14
|
+
function mostSignificantBit(x) {
|
|
15
|
+
(0, tiny_invariant_1.default)(jsbi_1.default.greaterThan(x, internalConstants_1.ZERO), 'ZERO');
|
|
16
|
+
(0, tiny_invariant_1.default)(jsbi_1.default.lessThanOrEqual(x, sdk_core_1.MaxUint256), 'MAX');
|
|
17
|
+
let msb = 0;
|
|
18
|
+
for (const [power, min] of POWERS_OF_2) {
|
|
19
|
+
if (jsbi_1.default.greaterThanOrEqual(x, min)) {
|
|
20
|
+
x = jsbi_1.default.signedRightShift(x, jsbi_1.default.BigInt(power));
|
|
21
|
+
msb += power;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return msb;
|
|
25
|
+
}
|
|
26
|
+
exports.mostSignificantBit = mostSignificantBit;
|
|
27
|
+
//# sourceMappingURL=mostSignificantBit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mostSignificantBit.js","sourceRoot":"","sources":["../../../../src/utils/mostSignificantBit.ts"],"names":[],"mappings":";;;;AAAA,0DAAwD;AACxD,wDAAuB;AACvB,4EAAsC;AACtC,4DAA2C;AAE3C,MAAM,GAAG,GAAG,cAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AAC1B,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAW,EAAkB,EAAE,CAAC;IACrF,GAAG;IACH,cAAI,CAAC,YAAY,CAAC,GAAG,EAAE,cAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;CACzC,CAAC,CAAA;AAEF,SAAgB,kBAAkB,CAAC,CAAO;IACxC,IAAA,wBAAS,EAAC,cAAI,CAAC,WAAW,CAAC,CAAC,EAAE,wBAAI,CAAC,EAAE,MAAM,CAAC,CAAA;IAC5C,IAAA,wBAAS,EAAC,cAAI,CAAC,eAAe,CAAC,CAAC,EAAE,qBAAU,CAAC,EAAE,KAAK,CAAC,CAAA;IAErD,IAAI,GAAG,GAAW,CAAC,CAAA;IACnB,KAAK,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,WAAW,EAAE;QACtC,IAAI,cAAI,CAAC,kBAAkB,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;YACnC,CAAC,GAAG,cAAI,CAAC,gBAAgB,CAAC,CAAC,EAAE,cAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;YAChD,GAAG,IAAI,KAAK,CAAA;SACb;KACF;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAZD,gDAYC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the closest tick that is nearest a given tick and usable for the given tick spacing
|
|
3
|
+
* @param tick the target tick
|
|
4
|
+
* @param tickSpacing the spacing of the pool
|
|
5
|
+
*/
|
|
6
|
+
export declare function nearestUsableTick(tick: number, tickSpacing: number): number;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nearestUsableTick = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tiny_invariant_1 = tslib_1.__importDefault(require("tiny-invariant"));
|
|
6
|
+
const tickMath_1 = require("./tickMath");
|
|
7
|
+
/**
|
|
8
|
+
* Returns the closest tick that is nearest a given tick and usable for the given tick spacing
|
|
9
|
+
* @param tick the target tick
|
|
10
|
+
* @param tickSpacing the spacing of the pool
|
|
11
|
+
*/
|
|
12
|
+
function nearestUsableTick(tick, tickSpacing) {
|
|
13
|
+
(0, tiny_invariant_1.default)(Number.isInteger(tick) && Number.isInteger(tickSpacing), 'INTEGERS');
|
|
14
|
+
(0, tiny_invariant_1.default)(tickSpacing > 0, 'TICK_SPACING');
|
|
15
|
+
(0, tiny_invariant_1.default)(tick >= tickMath_1.TickMath.MIN_TICK && tick <= tickMath_1.TickMath.MAX_TICK, 'TICK_BOUND');
|
|
16
|
+
const rounded = Math.round(tick / tickSpacing) * tickSpacing;
|
|
17
|
+
if (rounded < tickMath_1.TickMath.MIN_TICK)
|
|
18
|
+
return rounded + tickSpacing;
|
|
19
|
+
else if (rounded > tickMath_1.TickMath.MAX_TICK)
|
|
20
|
+
return rounded - tickSpacing;
|
|
21
|
+
else
|
|
22
|
+
return rounded;
|
|
23
|
+
}
|
|
24
|
+
exports.nearestUsableTick = nearestUsableTick;
|
|
25
|
+
//# sourceMappingURL=nearestUsableTick.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nearestUsableTick.js","sourceRoot":"","sources":["../../../../src/utils/nearestUsableTick.ts"],"names":[],"mappings":";;;;AAAA,4EAAsC;AACtC,yCAAqC;AAErC;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,IAAY,EAAE,WAAmB;IACjE,IAAA,wBAAS,EAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,UAAU,CAAC,CAAA;IAC9E,IAAA,wBAAS,EAAC,WAAW,GAAG,CAAC,EAAE,cAAc,CAAC,CAAA;IAC1C,IAAA,wBAAS,EAAC,IAAI,IAAI,mBAAQ,CAAC,QAAQ,IAAI,IAAI,IAAI,mBAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;IAC/E,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,WAAW,CAAC,GAAG,WAAW,CAAA;IAC5D,IAAI,OAAO,GAAG,mBAAQ,CAAC,QAAQ;QAAE,OAAO,OAAO,GAAG,WAAW,CAAA;SACxD,IAAI,OAAO,GAAG,mBAAQ,CAAC,QAAQ;QAAE,OAAO,OAAO,GAAG,WAAW,CAAA;;QAC7D,OAAO,OAAO,CAAA;AACrB,CAAC;AARD,8CAQC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import JSBI from 'jsbi';
|
|
2
|
+
export declare abstract class PositionLibrary {
|
|
3
|
+
/**
|
|
4
|
+
* Cannot be constructed.
|
|
5
|
+
*/
|
|
6
|
+
private constructor();
|
|
7
|
+
static getTokensOwed(feeGrowthInside0LastX128: JSBI, feeGrowthInside1LastX128: JSBI, liquidity: JSBI, feeGrowthInside0X128: JSBI, feeGrowthInside1X128: JSBI): JSBI[];
|
|
8
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PositionLibrary = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsbi_1 = tslib_1.__importDefault(require("jsbi"));
|
|
6
|
+
const _1 = require(".");
|
|
7
|
+
const Q128 = jsbi_1.default.exponentiate(jsbi_1.default.BigInt(2), jsbi_1.default.BigInt(128));
|
|
8
|
+
class PositionLibrary {
|
|
9
|
+
/**
|
|
10
|
+
* Cannot be constructed.
|
|
11
|
+
*/
|
|
12
|
+
constructor() { }
|
|
13
|
+
// replicates the portions of Position#update required to compute unaccounted fees
|
|
14
|
+
static getTokensOwed(feeGrowthInside0LastX128, feeGrowthInside1LastX128, liquidity, feeGrowthInside0X128, feeGrowthInside1X128) {
|
|
15
|
+
const tokensOwed0 = jsbi_1.default.divide(jsbi_1.default.multiply((0, _1.subIn256)(feeGrowthInside0X128, feeGrowthInside0LastX128), liquidity), Q128);
|
|
16
|
+
const tokensOwed1 = jsbi_1.default.divide(jsbi_1.default.multiply((0, _1.subIn256)(feeGrowthInside1X128, feeGrowthInside1LastX128), liquidity), Q128);
|
|
17
|
+
return [tokensOwed0, tokensOwed1];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.PositionLibrary = PositionLibrary;
|
|
21
|
+
//# sourceMappingURL=position.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"position.js","sourceRoot":"","sources":["../../../../src/utils/position.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AACvB,wBAA4B;AAE5B,MAAM,IAAI,GAAG,cAAI,CAAC,YAAY,CAAC,cAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,cAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;AAEhE,MAAsB,eAAe;IACnC;;OAEG;IACH,gBAAuB,CAAC;IAExB,kFAAkF;IAC3E,MAAM,CAAC,aAAa,CACzB,wBAA8B,EAC9B,wBAA8B,EAC9B,SAAe,EACf,oBAA0B,EAC1B,oBAA0B;QAE1B,MAAM,WAAW,GAAG,cAAI,CAAC,MAAM,CAC7B,cAAI,CAAC,QAAQ,CAAC,IAAA,WAAQ,EAAC,oBAAoB,EAAE,wBAAwB,CAAC,EAAE,SAAS,CAAC,EAClF,IAAI,CACL,CAAA;QAED,MAAM,WAAW,GAAG,cAAI,CAAC,MAAM,CAC7B,cAAI,CAAC,QAAQ,CAAC,IAAA,WAAQ,EAAC,oBAAoB,EAAE,wBAAwB,CAAC,EAAE,SAAS,CAAC,EAClF,IAAI,CACL,CAAA;QAED,OAAO,CAAC,WAAW,EAAE,WAAW,CAAC,CAAA;IACnC,CAAC;CACF;AA1BD,0CA0BC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Price, Token } from '@centurion_project/sdk-core';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a price object corresponding to the input tick and the base/quote token
|
|
4
|
+
* Inputs must be tokens because the address order is used to interpret the price represented by the tick
|
|
5
|
+
* @param baseToken the base token of the price
|
|
6
|
+
* @param quoteToken the quote token of the price
|
|
7
|
+
* @param tick the tick for which to return the price
|
|
8
|
+
*/
|
|
9
|
+
export declare function tickToPrice(baseToken: Token, quoteToken: Token, tick: number): Price<Token, Token>;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the first tick for which the given price is greater than or equal to the tick price
|
|
12
|
+
* @param price for which to return the closest tick that represents a price less than or equal to the input price,
|
|
13
|
+
* i.e. the price of the returned tick is less than or equal to the input price
|
|
14
|
+
*/
|
|
15
|
+
export declare function priceToClosestTick(price: Price<Token, Token>): number;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.priceToClosestTick = exports.tickToPrice = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const sdk_core_1 = require("@centurion_project/sdk-core");
|
|
6
|
+
const jsbi_1 = tslib_1.__importDefault(require("jsbi"));
|
|
7
|
+
const internalConstants_1 = require("../internalConstants");
|
|
8
|
+
const encodeSqrtRatioX96_1 = require("./encodeSqrtRatioX96");
|
|
9
|
+
const tickMath_1 = require("./tickMath");
|
|
10
|
+
/**
|
|
11
|
+
* Returns a price object corresponding to the input tick and the base/quote token
|
|
12
|
+
* Inputs must be tokens because the address order is used to interpret the price represented by the tick
|
|
13
|
+
* @param baseToken the base token of the price
|
|
14
|
+
* @param quoteToken the quote token of the price
|
|
15
|
+
* @param tick the tick for which to return the price
|
|
16
|
+
*/
|
|
17
|
+
function tickToPrice(baseToken, quoteToken, tick) {
|
|
18
|
+
const sqrtRatioX96 = tickMath_1.TickMath.getSqrtRatioAtTick(tick);
|
|
19
|
+
const ratioX192 = jsbi_1.default.multiply(sqrtRatioX96, sqrtRatioX96);
|
|
20
|
+
return baseToken.sortsBefore(quoteToken)
|
|
21
|
+
? new sdk_core_1.Price(baseToken, quoteToken, internalConstants_1.Q192, ratioX192)
|
|
22
|
+
: new sdk_core_1.Price(baseToken, quoteToken, ratioX192, internalConstants_1.Q192);
|
|
23
|
+
}
|
|
24
|
+
exports.tickToPrice = tickToPrice;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the first tick for which the given price is greater than or equal to the tick price
|
|
27
|
+
* @param price for which to return the closest tick that represents a price less than or equal to the input price,
|
|
28
|
+
* i.e. the price of the returned tick is less than or equal to the input price
|
|
29
|
+
*/
|
|
30
|
+
function priceToClosestTick(price) {
|
|
31
|
+
const sorted = price.baseCurrency.sortsBefore(price.quoteCurrency);
|
|
32
|
+
const sqrtRatioX96 = sorted
|
|
33
|
+
? (0, encodeSqrtRatioX96_1.encodeSqrtRatioX96)(price.numerator, price.denominator)
|
|
34
|
+
: (0, encodeSqrtRatioX96_1.encodeSqrtRatioX96)(price.denominator, price.numerator);
|
|
35
|
+
let tick = tickMath_1.TickMath.getTickAtSqrtRatio(sqrtRatioX96);
|
|
36
|
+
const nextTickPrice = tickToPrice(price.baseCurrency, price.quoteCurrency, tick + 1);
|
|
37
|
+
if (sorted) {
|
|
38
|
+
if (!price.lessThan(nextTickPrice)) {
|
|
39
|
+
tick++;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
if (!price.greaterThan(nextTickPrice)) {
|
|
44
|
+
tick++;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return tick;
|
|
48
|
+
}
|
|
49
|
+
exports.priceToClosestTick = priceToClosestTick;
|
|
50
|
+
//# sourceMappingURL=priceTickConversions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"priceTickConversions.js","sourceRoot":"","sources":["../../../../src/utils/priceTickConversions.ts"],"names":[],"mappings":";;;;AAAA,0DAA0D;AAC1D,wDAAuB;AACvB,4DAA2C;AAC3C,6DAAyD;AACzD,yCAAqC;AAErC;;;;;;GAMG;AACH,SAAgB,WAAW,CAAC,SAAgB,EAAE,UAAiB,EAAE,IAAY;IAC3E,MAAM,YAAY,GAAG,mBAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAA;IAEtD,MAAM,SAAS,GAAG,cAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA;IAE3D,OAAO,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC;QACtC,CAAC,CAAC,IAAI,gBAAK,CAAC,SAAS,EAAE,UAAU,EAAE,wBAAI,EAAE,SAAS,CAAC;QACnD,CAAC,CAAC,IAAI,gBAAK,CAAC,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,wBAAI,CAAC,CAAA;AACvD,CAAC;AARD,kCAQC;AAED;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,KAA0B;IAC3D,MAAM,MAAM,GAAG,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;IAElE,MAAM,YAAY,GAAG,MAAM;QACzB,CAAC,CAAC,IAAA,uCAAkB,EAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,WAAW,CAAC;QACxD,CAAC,CAAC,IAAA,uCAAkB,EAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;IAE1D,IAAI,IAAI,GAAG,mBAAQ,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAA;IACpD,MAAM,aAAa,GAAG,WAAW,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,aAAa,EAAE,IAAI,GAAG,CAAC,CAAC,CAAA;IACpF,IAAI,MAAM,EAAE;QACV,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE;YAClC,IAAI,EAAE,CAAA;SACP;KACF;SAAM;QACL,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE;YACrC,IAAI,EAAE,CAAA;SACP;KACF;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAnBD,gDAmBC"}
|