@1inch/swap-vm-sdk 0.1.2-rc.6 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/index.js +454 -135
  2. package/dist/index.mjs +455 -136
  3. package/dist/swap-vm/instructions/concentrate/concentrate-liquidity-calculator/types.d.mts +9 -21
  4. package/dist/swap-vm/instructions/concentrate/concentrate-liquidity-calculator/types.d.ts +9 -21
  5. package/dist/swap-vm/instructions/concentrate/index.d.mts +8 -3
  6. package/dist/swap-vm/instructions/concentrate/index.d.ts +8 -3
  7. package/dist/swap-vm/instructions/concentrate/price/index.d.mts +3 -0
  8. package/dist/swap-vm/instructions/concentrate/price/index.d.ts +3 -0
  9. package/dist/swap-vm/instructions/concentrate/price/price.d.mts +45 -0
  10. package/dist/swap-vm/instructions/concentrate/price/price.d.ts +45 -0
  11. package/dist/swap-vm/instructions/concentrate/price/types.d.mts +21 -0
  12. package/dist/swap-vm/instructions/concentrate/price/types.d.ts +21 -0
  13. package/dist/swap-vm/instructions/concentrate/price-range/index.d.mts +2 -0
  14. package/dist/swap-vm/instructions/concentrate/price-range/index.d.ts +2 -0
  15. package/dist/swap-vm/instructions/concentrate/price-range/price-range.d.mts +18 -0
  16. package/dist/swap-vm/instructions/concentrate/price-range/price-range.d.ts +18 -0
  17. package/dist/swap-vm/instructions/concentrate/price-range/types.d.mts +26 -0
  18. package/dist/swap-vm/instructions/concentrate/price-range/types.d.ts +26 -0
  19. package/dist/swap-vm/instructions/concentrate/token-reserve/index.d.mts +2 -0
  20. package/dist/swap-vm/instructions/concentrate/token-reserve/index.d.ts +2 -0
  21. package/dist/swap-vm/instructions/concentrate/token-reserve/token-reserve.d.mts +10 -0
  22. package/dist/swap-vm/instructions/concentrate/token-reserve/token-reserve.d.ts +10 -0
  23. package/dist/swap-vm/instructions/concentrate/token-reserve/types.d.mts +10 -0
  24. package/dist/swap-vm/instructions/concentrate/token-reserve/types.d.ts +10 -0
  25. package/dist/swap-vm/instructions/index.d.mts +1 -0
  26. package/dist/swap-vm/instructions/index.d.ts +1 -0
  27. package/dist/swap-vm/instructions/pegged-swap/index.d.mts +4 -0
  28. package/dist/swap-vm/instructions/pegged-swap/index.d.ts +4 -0
  29. package/dist/swap-vm/instructions/pegged-swap/pegged-swap-calculator/index.d.mts +2 -0
  30. package/dist/swap-vm/instructions/pegged-swap/pegged-swap-calculator/index.d.ts +2 -0
  31. package/dist/swap-vm/instructions/pegged-swap/pegged-swap-calculator/pegged-swap-calculator.d.mts +16 -0
  32. package/dist/swap-vm/instructions/pegged-swap/pegged-swap-calculator/pegged-swap-calculator.d.ts +16 -0
  33. package/dist/swap-vm/instructions/pegged-swap/pegged-swap-calculator/types.d.mts +9 -0
  34. package/dist/swap-vm/instructions/pegged-swap/pegged-swap-calculator/types.d.ts +9 -0
  35. package/dist/swap-vm/instructions/pegged-swap/pegged-swap-math/pegged-swap-math.d.mts +18 -0
  36. package/dist/swap-vm/instructions/pegged-swap/pegged-swap-math/pegged-swap-math.d.ts +18 -0
  37. package/dist/swap-vm/instructions/pegged-swap/price/index.d.mts +2 -0
  38. package/dist/swap-vm/instructions/pegged-swap/price/index.d.ts +2 -0
  39. package/dist/swap-vm/instructions/pegged-swap/price/pegged-price.d.mts +28 -0
  40. package/dist/swap-vm/instructions/pegged-swap/price/pegged-price.d.ts +28 -0
  41. package/dist/swap-vm/instructions/pegged-swap/price/types.d.mts +30 -0
  42. package/dist/swap-vm/instructions/pegged-swap/price/types.d.ts +30 -0
  43. package/dist/swap-vm/instructions/utils/index.d.mts +2 -0
  44. package/dist/swap-vm/instructions/utils/index.d.ts +2 -0
  45. package/dist/swap-vm/instructions/utils/truncate-human-decimal-string.d.mts +9 -0
  46. package/dist/swap-vm/instructions/utils/truncate-human-decimal-string.d.ts +9 -0
  47. package/package.json +4 -4
  48. package/dist/swap-vm/instructions/concentrate/concentrate-liquidity-calculator/concentrate-liquidity-calculator.d.mts +0 -61
  49. package/dist/swap-vm/instructions/concentrate/concentrate-liquidity-calculator/concentrate-liquidity-calculator.d.ts +0 -61
  50. /package/dist/swap-vm/instructions/{concentrate → utils}/bigint-sqrt.d.mts +0 -0
  51. /package/dist/swap-vm/instructions/{concentrate → utils}/bigint-sqrt.d.ts +0 -0
@@ -0,0 +1,30 @@
1
+ import type { Address } from '@1inch/sdk-core';
2
+ export type PeggedTokenRef = {
3
+ address: Address;
4
+ decimals: number;
5
+ };
6
+ export type PeggedPricePair = {
7
+ quoteToken: PeggedTokenRef;
8
+ baseToken: PeggedTokenRef;
9
+ };
10
+ export type PeggedTokenReserve = PeggedTokenRef & {
11
+ initialReserve: bigint;
12
+ currentReserve: bigint;
13
+ };
14
+ export type PeggedReservesInput = {
15
+ reserveA: PeggedTokenReserve;
16
+ reserveB: PeggedTokenReserve;
17
+ linearWidth: bigint;
18
+ };
19
+ /** Snapshot from `PeggedPrice.prototype.toJSON` (bigints as decimal strings). */
20
+ export type PeggedPriceJSON = {
21
+ gtPerLtRaw: string;
22
+ tokenLt: {
23
+ address: string;
24
+ decimals: string;
25
+ };
26
+ tokenGt: {
27
+ address: string;
28
+ decimals: string;
29
+ };
30
+ };
@@ -0,0 +1,30 @@
1
+ import type { Address } from '@1inch/sdk-core';
2
+ export type PeggedTokenRef = {
3
+ address: Address;
4
+ decimals: number;
5
+ };
6
+ export type PeggedPricePair = {
7
+ quoteToken: PeggedTokenRef;
8
+ baseToken: PeggedTokenRef;
9
+ };
10
+ export type PeggedTokenReserve = PeggedTokenRef & {
11
+ initialReserve: bigint;
12
+ currentReserve: bigint;
13
+ };
14
+ export type PeggedReservesInput = {
15
+ reserveA: PeggedTokenReserve;
16
+ reserveB: PeggedTokenReserve;
17
+ linearWidth: bigint;
18
+ };
19
+ /** Snapshot from `PeggedPrice.prototype.toJSON` (bigints as decimal strings). */
20
+ export type PeggedPriceJSON = {
21
+ gtPerLtRaw: string;
22
+ tokenLt: {
23
+ address: string;
24
+ decimals: string;
25
+ };
26
+ tokenGt: {
27
+ address: string;
28
+ decimals: string;
29
+ };
30
+ };
@@ -0,0 +1,2 @@
1
+ export { bigintSqrt } from './bigint-sqrt';
2
+ export { truncateHumanDecimalString } from './truncate-human-decimal-string';
@@ -0,0 +1,2 @@
1
+ export { bigintSqrt } from './bigint-sqrt';
2
+ export { truncateHumanDecimalString } from './truncate-human-decimal-string';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Round a decimal string to `maxFrac` fractional digits (half-up: if the first dropped digit
3
+ * is `5`–`9`, round the last kept digit up), then strip trailing zeros after the dot.
4
+ *
5
+ * @param s Decimal string as produced by e.g. `formatUnits` (no scientific notation).
6
+ * @param maxFrac Maximum number of digits after `.`; `0` means integer only (round using the
7
+ * first fractional digit).
8
+ */
9
+ export declare function truncateHumanDecimalString(s: string, maxFrac: number): string;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Round a decimal string to `maxFrac` fractional digits (half-up: if the first dropped digit
3
+ * is `5`–`9`, round the last kept digit up), then strip trailing zeros after the dot.
4
+ *
5
+ * @param s Decimal string as produced by e.g. `formatUnits` (no scientific notation).
6
+ * @param maxFrac Maximum number of digits after `.`; `0` means integer only (round using the
7
+ * first fractional digit).
8
+ */
9
+ export declare function truncateHumanDecimalString(s: string, maxFrac: number): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1inch/swap-vm-sdk",
3
- "version": "0.1.2-rc.6",
3
+ "version": "0.1.2",
4
4
  "description": "1inch Swap VM SDK",
5
5
  "author": "@1inch",
6
6
  "license": "LicenseRef-Degensoft-SwapVM-1.1",
@@ -42,11 +42,11 @@
42
42
  "@1inch/sdk-core": "0.1.2"
43
43
  },
44
44
  "devDependencies": {
45
- "@types/node": "^22.13.0",
45
+ "@types/node": "^22.19.17",
46
46
  "dotenv": "17.2.3",
47
- "eslint-plugin-license-header": "0.8.0",
47
+ "eslint-plugin-license-header": "0.9.0",
48
48
  "tsdown": "^0.2.17",
49
- "typescript": "^5.7.3",
49
+ "typescript": "^5.9.3",
50
50
  "vitest": "^3.2.4"
51
51
  },
52
52
  "volta": {
@@ -1,61 +0,0 @@
1
- import type { Address } from '@1inch/sdk-core';
2
- import type { ConcentratedLiquidityInfo, ConcentrateLiquidityCalculatorArgs, ConcentrateTokenInfo, ScaledPriceBounds, ScaledPrices } from './types';
3
- /**
4
- * Calculator for concentrated liquidity: given two tokens and a price range (min, spot, max),
5
- * computes sqrt prices and token reserves for "max allocation" (use all available balances)
6
- * or "fixed allocation" (fix one token amount and solve for the other).
7
- *
8
- * Token ordering follows the pool convention: token0 = lower address, token1 = higher address.
9
- * Prices are supplied as ScaledPrices with scale 10^(token0Decimals + token1Decimals); they are
10
- * converted internally to P = token1/token0 in 1e18 and then to sqrt(P * 1e18) for the math.
11
- */
12
- export declare class ConcentrateLiquidityCalculator {
13
- private readonly tokenA;
14
- private readonly tokenB;
15
- static readonly ONE_E18: bigint;
16
- constructor(tokenA: ConcentrateTokenInfo, tokenB: ConcentrateTokenInfo);
17
- /**
18
- * Token with the smaller address (token0 in pool convention; "Lt" in the math).
19
- */
20
- get token0(): ConcentrateTokenInfo;
21
- /**
22
- * Token with the larger address (token1 in pool convention; "Gt" in the math).
23
- */
24
- get token1(): ConcentrateTokenInfo;
25
- static new(data: ConcentrateLiquidityCalculatorArgs): ConcentrateLiquidityCalculator;
26
- /**
27
- * Compute reserves when one token amount is fixed: the position uses exactly
28
- * `fixedReserve` of `fixedReserveForToken` and the other token amount is derived
29
- * to keep the same liquidity L. Returns sqrt prices and token0/token1
30
- * reserves (raw amounts).
31
- * Due to integer math (floor division, sqrt), the fixed asset amount in the result
32
- * may be less than requested by a few wei.
33
- */
34
- computeFixedAllocation(scaledPrices: ScaledPrices, fixedReserveForToken: Address, fixedReserve: bigint): ConcentratedLiquidityInfo;
35
- /**
36
- * Compute reserves when both token amounts are taken from token info: uses
37
- * token0.maxAvailableLiquidity and token1.maxAvailableLiquidity to maximize
38
- * L. Returns sqrt prices and the token0/token1 reserves that achieve
39
- * that maximum.
40
- */
41
- computeMaxAllocation(scaledPrices: ScaledPrices): ConcentratedLiquidityInfo;
42
- /**
43
- * Implied spot sqrt price from token0/token1 balances and a scaled price range
44
- * (same convention as {@link computeMaxAllocation}). Inverse of the allocation math; wraps
45
- * {@link computeLiquidityAndPrice} from concentrate-liquidity-math.
46
- *
47
- * @returns sqrt(P_spot) in 1e18 fixed-point (same as {@link ConcentratedLiquidityInfo.sqrtPriceSpot}).
48
- */
49
- computeSpotPrice(token0Balance: bigint, token1Balance: bigint, scaledPriceBounds: ScaledPriceBounds): bigint;
50
- /**
51
- * Convert user-facing ScaledPrices (scale 10^(token0Decimals+token1Decimals)) into internal
52
- * raw prices P = token1/token0 (before sqrt), so that sqrt(P * 1e18) can be
53
- * passed to the liquidity math. Handles both quote = token0 and quote = token1.
54
- */
55
- private computeRawPrices;
56
- private computeSqrtPriceBounds;
57
- /**
58
- * Internal P = token1/token0 (1e18) from scaled min/max only (same mapping as {@link computeRawPrices}).
59
- */
60
- private computeRawPriceBounds;
61
- }
@@ -1,61 +0,0 @@
1
- import type { Address } from '@1inch/sdk-core';
2
- import type { ConcentratedLiquidityInfo, ConcentrateLiquidityCalculatorArgs, ConcentrateTokenInfo, ScaledPriceBounds, ScaledPrices } from './types';
3
- /**
4
- * Calculator for concentrated liquidity: given two tokens and a price range (min, spot, max),
5
- * computes sqrt prices and token reserves for "max allocation" (use all available balances)
6
- * or "fixed allocation" (fix one token amount and solve for the other).
7
- *
8
- * Token ordering follows the pool convention: token0 = lower address, token1 = higher address.
9
- * Prices are supplied as ScaledPrices with scale 10^(token0Decimals + token1Decimals); they are
10
- * converted internally to P = token1/token0 in 1e18 and then to sqrt(P * 1e18) for the math.
11
- */
12
- export declare class ConcentrateLiquidityCalculator {
13
- private readonly tokenA;
14
- private readonly tokenB;
15
- static readonly ONE_E18: bigint;
16
- constructor(tokenA: ConcentrateTokenInfo, tokenB: ConcentrateTokenInfo);
17
- /**
18
- * Token with the smaller address (token0 in pool convention; "Lt" in the math).
19
- */
20
- get token0(): ConcentrateTokenInfo;
21
- /**
22
- * Token with the larger address (token1 in pool convention; "Gt" in the math).
23
- */
24
- get token1(): ConcentrateTokenInfo;
25
- static new(data: ConcentrateLiquidityCalculatorArgs): ConcentrateLiquidityCalculator;
26
- /**
27
- * Compute reserves when one token amount is fixed: the position uses exactly
28
- * `fixedReserve` of `fixedReserveForToken` and the other token amount is derived
29
- * to keep the same liquidity L. Returns sqrt prices and token0/token1
30
- * reserves (raw amounts).
31
- * Due to integer math (floor division, sqrt), the fixed asset amount in the result
32
- * may be less than requested by a few wei.
33
- */
34
- computeFixedAllocation(scaledPrices: ScaledPrices, fixedReserveForToken: Address, fixedReserve: bigint): ConcentratedLiquidityInfo;
35
- /**
36
- * Compute reserves when both token amounts are taken from token info: uses
37
- * token0.maxAvailableLiquidity and token1.maxAvailableLiquidity to maximize
38
- * L. Returns sqrt prices and the token0/token1 reserves that achieve
39
- * that maximum.
40
- */
41
- computeMaxAllocation(scaledPrices: ScaledPrices): ConcentratedLiquidityInfo;
42
- /**
43
- * Implied spot sqrt price from token0/token1 balances and a scaled price range
44
- * (same convention as {@link computeMaxAllocation}). Inverse of the allocation math; wraps
45
- * {@link computeLiquidityAndPrice} from concentrate-liquidity-math.
46
- *
47
- * @returns sqrt(P_spot) in 1e18 fixed-point (same as {@link ConcentratedLiquidityInfo.sqrtPriceSpot}).
48
- */
49
- computeSpotPrice(token0Balance: bigint, token1Balance: bigint, scaledPriceBounds: ScaledPriceBounds): bigint;
50
- /**
51
- * Convert user-facing ScaledPrices (scale 10^(token0Decimals+token1Decimals)) into internal
52
- * raw prices P = token1/token0 (before sqrt), so that sqrt(P * 1e18) can be
53
- * passed to the liquidity math. Handles both quote = token0 and quote = token1.
54
- */
55
- private computeRawPrices;
56
- private computeSqrtPriceBounds;
57
- /**
58
- * Internal P = token1/token0 (1e18) from scaled min/max only (same mapping as {@link computeRawPrices}).
59
- */
60
- private computeRawPriceBounds;
61
- }