@skate-org/amm-core-v2 1.0.0 → 2.0.0-alpha.3
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/CHANGELOG.md +41 -0
- package/README.md +7 -2
- package/dist/deployment/aggregated/_type_.d.ts +39 -5
- package/dist/deployment/aggregated/_type_.d.ts.map +1 -1
- package/dist/deployment/aggregated/retrieval.d.ts +4 -8
- package/dist/deployment/aggregated/retrieval.d.ts.map +1 -1
- package/dist/index.cjs +384 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +365 -0
- package/dist/index.js.map +1 -1
- package/dist/math/fullMath.d.ts +28 -0
- package/dist/math/fullMath.d.ts.map +1 -0
- package/dist/math/index.d.ts +5 -0
- package/dist/math/index.d.ts.map +1 -0
- package/dist/math/liquidityMath.d.ts +18 -0
- package/dist/math/liquidityMath.d.ts.map +1 -0
- package/dist/math/sqrtPriceMath.d.ts +62 -0
- package/dist/math/sqrtPriceMath.d.ts.map +1 -0
- package/dist/math/tickMath.d.ts +42 -0
- package/dist/math/tickMath.d.ts.map +1 -0
- package/dist/types/chain-vm.d.ts +9 -0
- package/dist/types/chain-vm.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure-BigInt port of Uniswap v3-core `FullMath.sol`.
|
|
3
|
+
*
|
|
4
|
+
* Canonical source:
|
|
5
|
+
* https://github.com/Uniswap/v3-core/blob/6562c52e8f75f0c10f9deaf44861847585fc8129/contracts/libraries/FullMath.sol
|
|
6
|
+
*
|
|
7
|
+
* Solidity's FullMath.sol computes `floor(a*b/denom)` and `ceil(a*b/denom)`
|
|
8
|
+
* for 256-bit unsigned values with full 512-bit intermediate precision, and
|
|
9
|
+
* reverts if the 256-bit result overflows or if `denom == 0`.
|
|
10
|
+
*
|
|
11
|
+
* In JS BigInt we have arbitrary precision, so the implementation is far
|
|
12
|
+
* simpler: compute the full product, divide, and explicitly check that the
|
|
13
|
+
* final result fits in 256 bits.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Returns `floor(a * b / denom)` under Solidity uint256 semantics.
|
|
17
|
+
*
|
|
18
|
+
* Throws if `denom == 0` or if the quotient would not fit in 256 bits.
|
|
19
|
+
*/
|
|
20
|
+
export declare function mulDiv(a: bigint, b: bigint, denom: bigint): bigint;
|
|
21
|
+
/**
|
|
22
|
+
* Returns `ceil(a * b / denom)` under Solidity uint256 semantics.
|
|
23
|
+
*
|
|
24
|
+
* Throws if `denom == 0`, if the intermediate `mulDiv` would overflow, or if
|
|
25
|
+
* rounding up pushes the result past `uint256` range.
|
|
26
|
+
*/
|
|
27
|
+
export declare function mulDivRoundingUp(a: bigint, b: bigint, denom: bigint): bigint;
|
|
28
|
+
//# sourceMappingURL=fullMath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fullMath.d.ts","sourceRoot":"","sources":["../../src/math/fullMath.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAclE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,MAAM,GACZ,MAAM,CAmBR"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/math/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure-BigInt port of Uniswap v3-core `LiquidityMath.sol`.
|
|
3
|
+
*
|
|
4
|
+
* Canonical source:
|
|
5
|
+
* https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/LiquidityMath.sol
|
|
6
|
+
*
|
|
7
|
+
* Exposes `addDelta(x, y)` with Solidity's revert semantics: subtracting
|
|
8
|
+
* past zero reverts with `LS`, adding past `uint128.max` reverts with `LA`.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Add a signed `int128` liquidity delta to a `uint128` liquidity value,
|
|
12
|
+
* reverting on overflow / underflow.
|
|
13
|
+
*
|
|
14
|
+
* @throws `LA` if `x + y > uint128.max`
|
|
15
|
+
* @throws `LS` if `x + y < 0`
|
|
16
|
+
*/
|
|
17
|
+
export declare function addDelta(x: bigint, y: bigint): bigint;
|
|
18
|
+
//# sourceMappingURL=liquidityMath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquidityMath.d.ts","sourceRoot":"","sources":["../../src/math/liquidityMath.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAiBrD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure-BigInt port of Uniswap v3-core `SqrtPriceMath.sol`.
|
|
3
|
+
*
|
|
4
|
+
* Canonical source:
|
|
5
|
+
* https://github.com/Uniswap/v3-core/blob/6562c52e8f75f0c10f9deaf44861847585fc8129/contracts/libraries/SqrtPriceMath.sol
|
|
6
|
+
*
|
|
7
|
+
* Functions based on Q64.96 sqrt price and liquidity. Contains the math
|
|
8
|
+
* that uses square root of price as a Q64.96 and liquidity to compute
|
|
9
|
+
* deltas. Rounding modes match the canonical source exactly — change only
|
|
10
|
+
* if the canonical Solidity changes.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Gets the next sqrt price given a delta of token0.
|
|
14
|
+
*
|
|
15
|
+
* Always rounds up. See canonical source for the two-branch formula and
|
|
16
|
+
* overflow-fallback rationale.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96: bigint, liquidity: bigint, amount: bigint, add: boolean): bigint;
|
|
19
|
+
/**
|
|
20
|
+
* Gets the next sqrt price given a delta of token1.
|
|
21
|
+
*
|
|
22
|
+
* Always rounds down. See canonical source for the branch selection based
|
|
23
|
+
* on `amount <= type(uint160).max`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96: bigint, liquidity: bigint, amount: bigint, add: boolean): bigint;
|
|
26
|
+
/**
|
|
27
|
+
* Gets the next sqrt price given an input amount of token0 or token1.
|
|
28
|
+
*
|
|
29
|
+
* @throws if `sqrtPX96 <= 0`, `liquidity <= 0`, or the next price is out of bounds.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getNextSqrtPriceFromInput(sqrtPX96: bigint, liquidity: bigint, amountIn: bigint, zeroForOne: boolean): bigint;
|
|
32
|
+
/**
|
|
33
|
+
* Gets the next sqrt price given an output amount of token0 or token1.
|
|
34
|
+
*
|
|
35
|
+
* @throws if `sqrtPX96 <= 0`, `liquidity <= 0`, or the next price is out of bounds.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getNextSqrtPriceFromOutput(sqrtPX96: bigint, liquidity: bigint, amountOut: bigint, zeroForOne: boolean): bigint;
|
|
38
|
+
/**
|
|
39
|
+
* Amount0 delta between two sqrt prices for a given liquidity.
|
|
40
|
+
*
|
|
41
|
+
* `liquidity * (sqrt(upper) - sqrt(lower)) / (sqrt(upper) * sqrt(lower))`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getAmount0Delta(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, liquidity: bigint, roundUp: boolean): bigint;
|
|
44
|
+
/**
|
|
45
|
+
* Amount1 delta between two sqrt prices for a given liquidity.
|
|
46
|
+
*
|
|
47
|
+
* `liquidity * (sqrt(upper) - sqrt(lower))`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function getAmount1Delta(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, liquidity: bigint, roundUp: boolean): bigint;
|
|
50
|
+
/**
|
|
51
|
+
* Signed amount0 delta: positive liquidity -> rounds up, negative -> rounds
|
|
52
|
+
* down and negates. Matches the `int128 liquidity` overload of the
|
|
53
|
+
* canonical library.
|
|
54
|
+
*/
|
|
55
|
+
export declare function getAmount0DeltaSigned(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, liquidity: bigint): bigint;
|
|
56
|
+
/**
|
|
57
|
+
* Signed amount1 delta: positive liquidity -> rounds up, negative -> rounds
|
|
58
|
+
* down and negates. Matches the `int128 liquidity` overload of the
|
|
59
|
+
* canonical library.
|
|
60
|
+
*/
|
|
61
|
+
export declare function getAmount1DeltaSigned(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, liquidity: bigint): bigint;
|
|
62
|
+
//# sourceMappingURL=sqrtPriceMath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqrtPriceMath.d.ts","sourceRoot":"","sources":["../../src/math/sqrtPriceMath.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAwCH;;;;;GAKG;AACH,wBAAgB,qCAAqC,CACnD,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,OAAO,GACX,MAAM,CAqCR;AAED;;;;;GAKG;AACH,wBAAgB,uCAAuC,CACrD,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,OAAO,GACX,MAAM,CAsBR;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,OAAO,GAClB,MAAM,CAaR;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,OAAO,GAClB,MAAM,CAkBR;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,OAAO,GACf,MAAM,CAoBR;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,OAAO,GACf,MAAM,CAcR;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,GAChB,MAAM,CAWR;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,GAChB,MAAM,CAUR"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure-BigInt port of Uniswap v3-core `TickMath.sol`.
|
|
3
|
+
*
|
|
4
|
+
* Canonical source:
|
|
5
|
+
* https://github.com/Uniswap/v3-core/blob/6562c52e8f75f0c10f9deaf44861847585fc8129/contracts/libraries/TickMath.sol
|
|
6
|
+
*
|
|
7
|
+
* Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as
|
|
8
|
+
* fixed point Q64.96 numbers, and the inverse.
|
|
9
|
+
*
|
|
10
|
+
* Solidity uses `uint256` / `uint160` / `int24` with wrap-on-overflow inside
|
|
11
|
+
* `unchecked` blocks. We emulate that by doing arithmetic as BigInt and then
|
|
12
|
+
* ANDing with `MAX_UINT256` / `MAX_UINT128` as needed. All multipliers and
|
|
13
|
+
* hex constants are copied verbatim from the canonical source — do not
|
|
14
|
+
* simplify.
|
|
15
|
+
*/
|
|
16
|
+
/** Minimum tick passable to `getSqrtRatioAtTick`, `log_{1.0001}(2^-128)`. */
|
|
17
|
+
export declare const MIN_TICK = -887272;
|
|
18
|
+
/** Maximum tick passable to `getSqrtRatioAtTick`, `log_{1.0001}(2^128)`. */
|
|
19
|
+
export declare const MAX_TICK = 887272;
|
|
20
|
+
/** Minimum value returnable from `getSqrtRatioAtTick`. Equals `getSqrtRatioAtTick(MIN_TICK)`. */
|
|
21
|
+
export declare const MIN_SQRT_RATIO = 4295128739n;
|
|
22
|
+
/** Maximum value returnable from `getSqrtRatioAtTick`. Equals `getSqrtRatioAtTick(MAX_TICK)`. */
|
|
23
|
+
export declare const MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342n;
|
|
24
|
+
/** Strict-inclusive lower bound for a user-supplied `sqrtPriceLimitX96`.
|
|
25
|
+
* The periphery contract checks `sqrtPriceLimit > MIN_SQRT_RATIO`, so the
|
|
26
|
+
* smallest valid value is `MIN_SQRT_RATIO + 1`. SVM/Sui validators use this. */
|
|
27
|
+
export declare const MIN_SQRT_PRICE_LIMIT: bigint;
|
|
28
|
+
/** Strict-inclusive upper bound for a user-supplied `sqrtPriceLimitX96`. */
|
|
29
|
+
export declare const MAX_SQRT_PRICE_LIMIT: bigint;
|
|
30
|
+
/**
|
|
31
|
+
* Calculates `sqrt(1.0001^tick) * 2^96` as a Q64.96 `uint160`.
|
|
32
|
+
*
|
|
33
|
+
* @throws if `|tick| > MAX_TICK`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function getSqrtRatioAtTick(tick: number): bigint;
|
|
36
|
+
/**
|
|
37
|
+
* Calculates the greatest tick value such that `getSqrtRatioAtTick(tick) <= sqrtPriceX96`.
|
|
38
|
+
*
|
|
39
|
+
* @throws if `sqrtPriceX96 < MIN_SQRT_RATIO` or `sqrtPriceX96 >= MAX_SQRT_RATIO`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function getTickAtSqrtRatio(sqrtPriceX96: bigint): number;
|
|
42
|
+
//# sourceMappingURL=tickMath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tickMath.d.ts","sourceRoot":"","sources":["../../src/math/tickMath.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,6EAA6E;AAC7E,eAAO,MAAM,QAAQ,UAAU,CAAC;AAEhC,4EAA4E;AAC5E,eAAO,MAAM,QAAQ,SAAS,CAAC;AAE/B,iGAAiG;AACjG,eAAO,MAAM,cAAc,cAAc,CAAC;AAE1C,iGAAiG;AACjG,eAAO,MAAM,cAAc,qDACyB,CAAC;AAErD;;iFAEiF;AACjF,eAAO,MAAM,oBAAoB,QAAsB,CAAC;AAExD,4EAA4E;AAC5E,eAAO,MAAM,oBAAoB,QAAsB,CAAC;AAExD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAiEvD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAwF/D"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CHAIN } from "./chain";
|
|
2
|
+
/** EVM-family chains. The kernel chain (MEGAETH) and every periphery chain
|
|
3
|
+
* whose contracts are EVM-compatible. */
|
|
4
|
+
export type EvmChain = CHAIN.ETHEREUM | CHAIN.BASE | CHAIN.ARBITRUM | CHAIN.OPTIMISM | CHAIN.BSC | CHAIN.MANTLE | CHAIN.HYPERLIQUID | CHAIN.PLUME | CHAIN.ZG | CHAIN.MONAD | CHAIN.MEGAETH | CHAIN.TEMPO | CHAIN.SKATE;
|
|
5
|
+
/** SVM-family chains (Solana program model). */
|
|
6
|
+
export type SvmChain = CHAIN.SOLANA | CHAIN.ECLIPSE;
|
|
7
|
+
/** Sui-family chains. Only one chain today. */
|
|
8
|
+
export type SuiChain = CHAIN.SUI;
|
|
9
|
+
//# sourceMappingURL=chain-vm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain-vm.d.ts","sourceRoot":"","sources":["../../src/types/chain-vm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;0CAC0C;AAC1C,MAAM,MAAM,QAAQ,GAChB,KAAK,CAAC,QAAQ,GACd,KAAK,CAAC,IAAI,GACV,KAAK,CAAC,QAAQ,GACd,KAAK,CAAC,QAAQ,GACd,KAAK,CAAC,GAAG,GACT,KAAK,CAAC,MAAM,GACZ,KAAK,CAAC,WAAW,GACjB,KAAK,CAAC,KAAK,GACX,KAAK,CAAC,EAAE,GACR,KAAK,CAAC,KAAK,GACX,KAAK,CAAC,OAAO,GACb,KAAK,CAAC,KAAK,GACX,KAAK,CAAC,KAAK,CAAC;AAEhB,gDAAgD;AAChD,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC;AAEpD,+CAA+C;AAC/C,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,MAAM,CAAC;AACrB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,MAAM,CAAC;AACrB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
|