@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.
- package/dist/index.js +454 -135
- package/dist/index.mjs +455 -136
- package/dist/swap-vm/instructions/concentrate/concentrate-liquidity-calculator/types.d.mts +9 -21
- package/dist/swap-vm/instructions/concentrate/concentrate-liquidity-calculator/types.d.ts +9 -21
- package/dist/swap-vm/instructions/concentrate/index.d.mts +8 -3
- package/dist/swap-vm/instructions/concentrate/index.d.ts +8 -3
- package/dist/swap-vm/instructions/concentrate/price/index.d.mts +3 -0
- package/dist/swap-vm/instructions/concentrate/price/index.d.ts +3 -0
- package/dist/swap-vm/instructions/concentrate/price/price.d.mts +45 -0
- package/dist/swap-vm/instructions/concentrate/price/price.d.ts +45 -0
- package/dist/swap-vm/instructions/concentrate/price/types.d.mts +21 -0
- package/dist/swap-vm/instructions/concentrate/price/types.d.ts +21 -0
- package/dist/swap-vm/instructions/concentrate/price-range/index.d.mts +2 -0
- package/dist/swap-vm/instructions/concentrate/price-range/index.d.ts +2 -0
- package/dist/swap-vm/instructions/concentrate/price-range/price-range.d.mts +18 -0
- package/dist/swap-vm/instructions/concentrate/price-range/price-range.d.ts +18 -0
- package/dist/swap-vm/instructions/concentrate/price-range/types.d.mts +26 -0
- package/dist/swap-vm/instructions/concentrate/price-range/types.d.ts +26 -0
- package/dist/swap-vm/instructions/concentrate/token-reserve/index.d.mts +2 -0
- package/dist/swap-vm/instructions/concentrate/token-reserve/index.d.ts +2 -0
- package/dist/swap-vm/instructions/concentrate/token-reserve/token-reserve.d.mts +10 -0
- package/dist/swap-vm/instructions/concentrate/token-reserve/token-reserve.d.ts +10 -0
- package/dist/swap-vm/instructions/concentrate/token-reserve/types.d.mts +10 -0
- package/dist/swap-vm/instructions/concentrate/token-reserve/types.d.ts +10 -0
- package/dist/swap-vm/instructions/index.d.mts +1 -0
- package/dist/swap-vm/instructions/index.d.ts +1 -0
- package/dist/swap-vm/instructions/pegged-swap/index.d.mts +4 -0
- package/dist/swap-vm/instructions/pegged-swap/index.d.ts +4 -0
- package/dist/swap-vm/instructions/pegged-swap/pegged-swap-calculator/index.d.mts +2 -0
- package/dist/swap-vm/instructions/pegged-swap/pegged-swap-calculator/index.d.ts +2 -0
- package/dist/swap-vm/instructions/pegged-swap/pegged-swap-calculator/pegged-swap-calculator.d.mts +16 -0
- package/dist/swap-vm/instructions/pegged-swap/pegged-swap-calculator/pegged-swap-calculator.d.ts +16 -0
- package/dist/swap-vm/instructions/pegged-swap/pegged-swap-calculator/types.d.mts +9 -0
- package/dist/swap-vm/instructions/pegged-swap/pegged-swap-calculator/types.d.ts +9 -0
- package/dist/swap-vm/instructions/pegged-swap/pegged-swap-math/pegged-swap-math.d.mts +18 -0
- package/dist/swap-vm/instructions/pegged-swap/pegged-swap-math/pegged-swap-math.d.ts +18 -0
- package/dist/swap-vm/instructions/pegged-swap/price/index.d.mts +2 -0
- package/dist/swap-vm/instructions/pegged-swap/price/index.d.ts +2 -0
- package/dist/swap-vm/instructions/pegged-swap/price/pegged-price.d.mts +28 -0
- package/dist/swap-vm/instructions/pegged-swap/price/pegged-price.d.ts +28 -0
- package/dist/swap-vm/instructions/pegged-swap/price/types.d.mts +30 -0
- package/dist/swap-vm/instructions/pegged-swap/price/types.d.ts +30 -0
- package/dist/swap-vm/instructions/utils/index.d.mts +2 -0
- package/dist/swap-vm/instructions/utils/index.d.ts +2 -0
- package/dist/swap-vm/instructions/utils/truncate-human-decimal-string.d.mts +9 -0
- package/dist/swap-vm/instructions/utils/truncate-human-decimal-string.d.ts +9 -0
- package/package.json +4 -4
- package/dist/swap-vm/instructions/concentrate/concentrate-liquidity-calculator/concentrate-liquidity-calculator.d.mts +0 -61
- package/dist/swap-vm/instructions/concentrate/concentrate-liquidity-calculator/concentrate-liquidity-calculator.d.ts +0 -61
- /package/dist/swap-vm/instructions/{concentrate → utils}/bigint-sqrt.d.mts +0 -0
- /package/dist/swap-vm/instructions/{concentrate → utils}/bigint-sqrt.d.ts +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Address } from '@1inch/sdk-core';
|
|
2
|
+
import type { Price } from '../price';
|
|
2
3
|
/**
|
|
3
4
|
* Per-token input for the calculator: address, decimals, and the maximum amount
|
|
4
5
|
* the user is willing to allocate (used by computeMaxAllocation).
|
|
@@ -8,29 +9,16 @@ export type ConcentrateTokenInfo = {
|
|
|
8
9
|
decimals: bigint;
|
|
9
10
|
maxAvailableLiquidity: bigint;
|
|
10
11
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
maxPriceRaw: bigint;
|
|
12
|
+
export type PriceAllocationRange = {
|
|
13
|
+
minPrice: Price;
|
|
14
|
+
spotPrice: Price;
|
|
15
|
+
maxPrice: Price;
|
|
16
|
+
};
|
|
17
|
+
export type PriceBounds = {
|
|
18
|
+
minPrice: Price;
|
|
19
|
+
maxPrice: Price;
|
|
20
20
|
};
|
|
21
|
-
/**
|
|
22
|
-
* Price range only (no spot): same scaling and quote convention as {@link ScaledPrices}.
|
|
23
|
-
* Used when deriving spot from balances and bounds.
|
|
24
|
-
*/
|
|
25
|
-
export type ScaledPriceBounds = Pick<ScaledPrices, 'quoteToken' | 'minPriceRaw' | 'maxPriceRaw'>;
|
|
26
|
-
/**
|
|
27
|
-
* Result of allocation: sqrt prices and the token0/token1 reserves
|
|
28
|
-
* (raw amounts) to use for the concentrated liquidity position.
|
|
29
|
-
*/
|
|
30
21
|
export type ConcentratedLiquidityInfo = {
|
|
31
|
-
sqrtPriceMin: bigint;
|
|
32
|
-
sqrtPriceSpot: bigint;
|
|
33
|
-
sqrtPriceMax: bigint;
|
|
34
22
|
token0Reserve: bigint;
|
|
35
23
|
token1Reserve: bigint;
|
|
36
24
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Address } from '@1inch/sdk-core';
|
|
2
|
+
import type { Price } from '../price';
|
|
2
3
|
/**
|
|
3
4
|
* Per-token input for the calculator: address, decimals, and the maximum amount
|
|
4
5
|
* the user is willing to allocate (used by computeMaxAllocation).
|
|
@@ -8,29 +9,16 @@ export type ConcentrateTokenInfo = {
|
|
|
8
9
|
decimals: bigint;
|
|
9
10
|
maxAvailableLiquidity: bigint;
|
|
10
11
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
maxPriceRaw: bigint;
|
|
12
|
+
export type PriceAllocationRange = {
|
|
13
|
+
minPrice: Price;
|
|
14
|
+
spotPrice: Price;
|
|
15
|
+
maxPrice: Price;
|
|
16
|
+
};
|
|
17
|
+
export type PriceBounds = {
|
|
18
|
+
minPrice: Price;
|
|
19
|
+
maxPrice: Price;
|
|
20
20
|
};
|
|
21
|
-
/**
|
|
22
|
-
* Price range only (no spot): same scaling and quote convention as {@link ScaledPrices}.
|
|
23
|
-
* Used when deriving spot from balances and bounds.
|
|
24
|
-
*/
|
|
25
|
-
export type ScaledPriceBounds = Pick<ScaledPrices, 'quoteToken' | 'minPriceRaw' | 'maxPriceRaw'>;
|
|
26
|
-
/**
|
|
27
|
-
* Result of allocation: sqrt prices and the token0/token1 reserves
|
|
28
|
-
* (raw amounts) to use for the concentrated liquidity position.
|
|
29
|
-
*/
|
|
30
21
|
export type ConcentratedLiquidityInfo = {
|
|
31
|
-
sqrtPriceMin: bigint;
|
|
32
|
-
sqrtPriceSpot: bigint;
|
|
33
|
-
sqrtPriceMax: bigint;
|
|
34
22
|
token0Reserve: bigint;
|
|
35
23
|
token1Reserve: bigint;
|
|
36
24
|
};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export * from './opcodes';
|
|
2
2
|
export { ConcentrateGrowLiquidity2DArgs, ONE_E18 } from './concentrate-grow-liquidity-2d-args';
|
|
3
3
|
export { computeLiquidityFromAmounts, computeBalances, computeLiquidityAndPrice, } from './concentrate-liquidity-math/concentrate-liquidity-math';
|
|
4
|
-
export {
|
|
5
|
-
export type {
|
|
6
|
-
export
|
|
4
|
+
export { Price } from './price';
|
|
5
|
+
export type { PriceJSON, PricePair, PriceToken } from './price';
|
|
6
|
+
export { PriceRange } from './price-range';
|
|
7
|
+
export type { PriceRangeJSON } from './price-range';
|
|
8
|
+
export { TokenReserve } from './token-reserve';
|
|
9
|
+
export type { TokenReserveArgs, TokenReserveJSON } from './token-reserve';
|
|
10
|
+
export type { ConcentrateTokenInfo, ConcentrateLiquidityCalculatorArgs, PriceAllocationRange, PriceBounds, ConcentratedLiquidityInfo, } from './concentrate-liquidity-calculator/types';
|
|
11
|
+
export { bigintSqrt } from '../utils/bigint-sqrt';
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export * from './opcodes';
|
|
2
2
|
export { ConcentrateGrowLiquidity2DArgs, ONE_E18 } from './concentrate-grow-liquidity-2d-args';
|
|
3
3
|
export { computeLiquidityFromAmounts, computeBalances, computeLiquidityAndPrice, } from './concentrate-liquidity-math/concentrate-liquidity-math';
|
|
4
|
-
export {
|
|
5
|
-
export type {
|
|
6
|
-
export
|
|
4
|
+
export { Price } from './price';
|
|
5
|
+
export type { PriceJSON, PricePair, PriceToken } from './price';
|
|
6
|
+
export { PriceRange } from './price-range';
|
|
7
|
+
export type { PriceRangeJSON } from './price-range';
|
|
8
|
+
export { TokenReserve } from './token-reserve';
|
|
9
|
+
export type { TokenReserveArgs, TokenReserveJSON } from './token-reserve';
|
|
10
|
+
export type { ConcentrateTokenInfo, ConcentrateLiquidityCalculatorArgs, PriceAllocationRange, PriceBounds, ConcentratedLiquidityInfo, } from './concentrate-liquidity-calculator/types';
|
|
11
|
+
export { bigintSqrt } from '../utils/bigint-sqrt';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Address } from '@1inch/sdk-core';
|
|
2
|
+
import type { PriceJSON, PricePair, PriceToken } from './types';
|
|
3
|
+
export declare class Price {
|
|
4
|
+
private readonly sqrtP;
|
|
5
|
+
readonly token0: PriceToken;
|
|
6
|
+
readonly token1: PriceToken;
|
|
7
|
+
private constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Fixed-point sqrt price as used on-chain (`sqrt(P * 1e18)`).
|
|
10
|
+
*/
|
|
11
|
+
static fromSqrt(price: bigint, pair: {
|
|
12
|
+
tokenA: PriceToken;
|
|
13
|
+
tokenB: PriceToken;
|
|
14
|
+
}): Price;
|
|
15
|
+
/**
|
|
16
|
+
* Human decimal string for **quote per 1 base**`.
|
|
17
|
+
*/
|
|
18
|
+
static fromHuman(price: string, pair: PricePair): Price;
|
|
19
|
+
static fromJSON(input: PriceJSON): Price;
|
|
20
|
+
equals(other: Price): boolean;
|
|
21
|
+
lt(other: Price): boolean;
|
|
22
|
+
lte(other: Price): boolean;
|
|
23
|
+
gt(other: Price): boolean;
|
|
24
|
+
gte(other: Price): boolean;
|
|
25
|
+
isSamePair(other: Price): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Raw price `P` with 1e18 fixed-point (`(sqrtP^2) / 1e18`), matching typical on-chain use.
|
|
28
|
+
*/
|
|
29
|
+
toRaw(): bigint;
|
|
30
|
+
toSqrt(): bigint;
|
|
31
|
+
/**
|
|
32
|
+
* Decimal string for **quote per 1 base** at scale `10^(token0Decimals + token1Decimals)`.
|
|
33
|
+
* Fractional digits after the dot are **rounded half-up** to {@link PriceToken.decimals} of
|
|
34
|
+
* the quote token (then trailing zeros are removed).
|
|
35
|
+
*
|
|
36
|
+
* @param quoteToken Which token is the quote currency; base is the other token.
|
|
37
|
+
*/
|
|
38
|
+
toHuman(quoteToken: Address): string;
|
|
39
|
+
toJSON(): PriceJSON;
|
|
40
|
+
/**
|
|
41
|
+
* Quote per 1 base scaled by `10^(token0Decimals + token1Decimals)`.
|
|
42
|
+
* Uses `sqrtP^2` in one step so we do not compound truncation from {@link toRaw}.
|
|
43
|
+
*/
|
|
44
|
+
private scaledRawAmountForQuote;
|
|
45
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Address } from '@1inch/sdk-core';
|
|
2
|
+
import type { PriceJSON, PricePair, PriceToken } from './types';
|
|
3
|
+
export declare class Price {
|
|
4
|
+
private readonly sqrtP;
|
|
5
|
+
readonly token0: PriceToken;
|
|
6
|
+
readonly token1: PriceToken;
|
|
7
|
+
private constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Fixed-point sqrt price as used on-chain (`sqrt(P * 1e18)`).
|
|
10
|
+
*/
|
|
11
|
+
static fromSqrt(price: bigint, pair: {
|
|
12
|
+
tokenA: PriceToken;
|
|
13
|
+
tokenB: PriceToken;
|
|
14
|
+
}): Price;
|
|
15
|
+
/**
|
|
16
|
+
* Human decimal string for **quote per 1 base**`.
|
|
17
|
+
*/
|
|
18
|
+
static fromHuman(price: string, pair: PricePair): Price;
|
|
19
|
+
static fromJSON(input: PriceJSON): Price;
|
|
20
|
+
equals(other: Price): boolean;
|
|
21
|
+
lt(other: Price): boolean;
|
|
22
|
+
lte(other: Price): boolean;
|
|
23
|
+
gt(other: Price): boolean;
|
|
24
|
+
gte(other: Price): boolean;
|
|
25
|
+
isSamePair(other: Price): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Raw price `P` with 1e18 fixed-point (`(sqrtP^2) / 1e18`), matching typical on-chain use.
|
|
28
|
+
*/
|
|
29
|
+
toRaw(): bigint;
|
|
30
|
+
toSqrt(): bigint;
|
|
31
|
+
/**
|
|
32
|
+
* Decimal string for **quote per 1 base** at scale `10^(token0Decimals + token1Decimals)`.
|
|
33
|
+
* Fractional digits after the dot are **rounded half-up** to {@link PriceToken.decimals} of
|
|
34
|
+
* the quote token (then trailing zeros are removed).
|
|
35
|
+
*
|
|
36
|
+
* @param quoteToken Which token is the quote currency; base is the other token.
|
|
37
|
+
*/
|
|
38
|
+
toHuman(quoteToken: Address): string;
|
|
39
|
+
toJSON(): PriceJSON;
|
|
40
|
+
/**
|
|
41
|
+
* Quote per 1 base scaled by `10^(token0Decimals + token1Decimals)`.
|
|
42
|
+
* Uses `sqrtP^2` in one step so we do not compound truncation from {@link toRaw}.
|
|
43
|
+
*/
|
|
44
|
+
private scaledRawAmountForQuote;
|
|
45
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Address } from '@1inch/sdk-core';
|
|
2
|
+
export type PriceToken = {
|
|
3
|
+
address: Address;
|
|
4
|
+
decimals: bigint;
|
|
5
|
+
};
|
|
6
|
+
export type PricePair = {
|
|
7
|
+
quoteToken: PriceToken;
|
|
8
|
+
baseToken: PriceToken;
|
|
9
|
+
};
|
|
10
|
+
/** Snapshot from `Price.prototype.toJSON` (bigints as decimal strings). */
|
|
11
|
+
export type PriceJSON = {
|
|
12
|
+
sqrtP: string;
|
|
13
|
+
token0: {
|
|
14
|
+
address: string;
|
|
15
|
+
decimals: string;
|
|
16
|
+
};
|
|
17
|
+
token1: {
|
|
18
|
+
address: string;
|
|
19
|
+
decimals: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Address } from '@1inch/sdk-core';
|
|
2
|
+
export type PriceToken = {
|
|
3
|
+
address: Address;
|
|
4
|
+
decimals: bigint;
|
|
5
|
+
};
|
|
6
|
+
export type PricePair = {
|
|
7
|
+
quoteToken: PriceToken;
|
|
8
|
+
baseToken: PriceToken;
|
|
9
|
+
};
|
|
10
|
+
/** Snapshot from `Price.prototype.toJSON` (bigints as decimal strings). */
|
|
11
|
+
export type PriceJSON = {
|
|
12
|
+
sqrtP: string;
|
|
13
|
+
token0: {
|
|
14
|
+
address: string;
|
|
15
|
+
decimals: string;
|
|
16
|
+
};
|
|
17
|
+
token1: {
|
|
18
|
+
address: string;
|
|
19
|
+
decimals: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { PriceAllocationRange, PriceBounds, PriceRangeJSON, SortedReserves, TokenReserves } from './types';
|
|
2
|
+
import type { PriceToken } from '../price';
|
|
3
|
+
import { Price } from '../price';
|
|
4
|
+
import { TokenReserve } from '../token-reserve';
|
|
5
|
+
export declare class PriceRange {
|
|
6
|
+
readonly minPrice: Price;
|
|
7
|
+
readonly spotPrice: Price;
|
|
8
|
+
readonly maxPrice: Price;
|
|
9
|
+
private constructor();
|
|
10
|
+
get token0(): PriceToken;
|
|
11
|
+
get token1(): PriceToken;
|
|
12
|
+
static new(range: PriceAllocationRange): PriceRange;
|
|
13
|
+
static fromJSON(input: PriceRangeJSON): PriceRange;
|
|
14
|
+
static fromPriceBounds(bounds: PriceBounds, reserves: TokenReserves): PriceRange;
|
|
15
|
+
computeFixedAllocation(fixedReserve: TokenReserve): SortedReserves;
|
|
16
|
+
computeMaxAllocation(maxAvailableLiquidity: TokenReserves): SortedReserves;
|
|
17
|
+
toJSON(): PriceRangeJSON;
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { PriceAllocationRange, PriceBounds, PriceRangeJSON, SortedReserves, TokenReserves } from './types';
|
|
2
|
+
import type { PriceToken } from '../price';
|
|
3
|
+
import { Price } from '../price';
|
|
4
|
+
import { TokenReserve } from '../token-reserve';
|
|
5
|
+
export declare class PriceRange {
|
|
6
|
+
readonly minPrice: Price;
|
|
7
|
+
readonly spotPrice: Price;
|
|
8
|
+
readonly maxPrice: Price;
|
|
9
|
+
private constructor();
|
|
10
|
+
get token0(): PriceToken;
|
|
11
|
+
get token1(): PriceToken;
|
|
12
|
+
static new(range: PriceAllocationRange): PriceRange;
|
|
13
|
+
static fromJSON(input: PriceRangeJSON): PriceRange;
|
|
14
|
+
static fromPriceBounds(bounds: PriceBounds, reserves: TokenReserves): PriceRange;
|
|
15
|
+
computeFixedAllocation(fixedReserve: TokenReserve): SortedReserves;
|
|
16
|
+
computeMaxAllocation(maxAvailableLiquidity: TokenReserves): SortedReserves;
|
|
17
|
+
toJSON(): PriceRangeJSON;
|
|
18
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PriceJSON } from '../price/types';
|
|
2
|
+
import type { Price } from '../price';
|
|
3
|
+
import type { TokenReserve } from '../token-reserve';
|
|
4
|
+
export type PriceAllocationRange = {
|
|
5
|
+
minPrice: Price;
|
|
6
|
+
spotPrice: Price;
|
|
7
|
+
maxPrice: Price;
|
|
8
|
+
};
|
|
9
|
+
export type PriceBounds = {
|
|
10
|
+
minPrice: Price;
|
|
11
|
+
maxPrice: Price;
|
|
12
|
+
};
|
|
13
|
+
export type TokenReserves = {
|
|
14
|
+
reserveA: TokenReserve;
|
|
15
|
+
reserveB: TokenReserve;
|
|
16
|
+
};
|
|
17
|
+
/** Snapshot from `PriceRange.prototype.toJSON`. */
|
|
18
|
+
export type PriceRangeJSON = {
|
|
19
|
+
minPrice: PriceJSON;
|
|
20
|
+
spotPrice: PriceJSON;
|
|
21
|
+
maxPrice: PriceJSON;
|
|
22
|
+
};
|
|
23
|
+
export type SortedReserves = {
|
|
24
|
+
reserve0: TokenReserve;
|
|
25
|
+
reserve1: TokenReserve;
|
|
26
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PriceJSON } from '../price/types';
|
|
2
|
+
import type { Price } from '../price';
|
|
3
|
+
import type { TokenReserve } from '../token-reserve';
|
|
4
|
+
export type PriceAllocationRange = {
|
|
5
|
+
minPrice: Price;
|
|
6
|
+
spotPrice: Price;
|
|
7
|
+
maxPrice: Price;
|
|
8
|
+
};
|
|
9
|
+
export type PriceBounds = {
|
|
10
|
+
minPrice: Price;
|
|
11
|
+
maxPrice: Price;
|
|
12
|
+
};
|
|
13
|
+
export type TokenReserves = {
|
|
14
|
+
reserveA: TokenReserve;
|
|
15
|
+
reserveB: TokenReserve;
|
|
16
|
+
};
|
|
17
|
+
/** Snapshot from `PriceRange.prototype.toJSON`. */
|
|
18
|
+
export type PriceRangeJSON = {
|
|
19
|
+
minPrice: PriceJSON;
|
|
20
|
+
spotPrice: PriceJSON;
|
|
21
|
+
maxPrice: PriceJSON;
|
|
22
|
+
};
|
|
23
|
+
export type SortedReserves = {
|
|
24
|
+
reserve0: TokenReserve;
|
|
25
|
+
reserve1: TokenReserve;
|
|
26
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Address } from '@1inch/sdk-core';
|
|
2
|
+
import type { TokenReserveArgs, TokenReserveJSON } from './types';
|
|
3
|
+
export declare class TokenReserve {
|
|
4
|
+
readonly token: Address;
|
|
5
|
+
readonly reserve: bigint;
|
|
6
|
+
constructor(token: Address, reserve: bigint);
|
|
7
|
+
static new(args: TokenReserveArgs): TokenReserve;
|
|
8
|
+
static fromJSON(input: TokenReserveJSON): TokenReserve;
|
|
9
|
+
toJSON(): TokenReserveJSON;
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Address } from '@1inch/sdk-core';
|
|
2
|
+
import type { TokenReserveArgs, TokenReserveJSON } from './types';
|
|
3
|
+
export declare class TokenReserve {
|
|
4
|
+
readonly token: Address;
|
|
5
|
+
readonly reserve: bigint;
|
|
6
|
+
constructor(token: Address, reserve: bigint);
|
|
7
|
+
static new(args: TokenReserveArgs): TokenReserve;
|
|
8
|
+
static fromJSON(input: TokenReserveJSON): TokenReserve;
|
|
9
|
+
toJSON(): TokenReserveJSON;
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Address } from '@1inch/sdk-core';
|
|
2
|
+
export type TokenReserveArgs = {
|
|
3
|
+
token: Address;
|
|
4
|
+
reserve: bigint;
|
|
5
|
+
};
|
|
6
|
+
/** Snapshot from `TokenReserve.prototype.toJSON` (reserve as decimal string). */
|
|
7
|
+
export type TokenReserveJSON = {
|
|
8
|
+
token: string;
|
|
9
|
+
reserve: string;
|
|
10
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Address } from '@1inch/sdk-core';
|
|
2
|
+
export type TokenReserveArgs = {
|
|
3
|
+
token: Address;
|
|
4
|
+
reserve: bigint;
|
|
5
|
+
};
|
|
6
|
+
/** Snapshot from `TokenReserve.prototype.toJSON` (reserve as decimal string). */
|
|
7
|
+
export type TokenReserveJSON = {
|
|
8
|
+
token: string;
|
|
9
|
+
reserve: string;
|
|
10
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Opcode } from './opcode';
|
|
2
2
|
import type { IArgsData } from './types';
|
|
3
3
|
export * from './types';
|
|
4
|
+
export { bigintSqrt, truncateHumanDecimalString } from './utils';
|
|
4
5
|
export { EMPTY_OPCODE } from './empty';
|
|
5
6
|
export * as balances from './balances';
|
|
6
7
|
export * as controls from './controls';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Opcode } from './opcode';
|
|
2
2
|
import type { IArgsData } from './types';
|
|
3
3
|
export * from './types';
|
|
4
|
+
export { bigintSqrt, truncateHumanDecimalString } from './utils';
|
|
4
5
|
export { EMPTY_OPCODE } from './empty';
|
|
5
6
|
export * as balances from './balances';
|
|
6
7
|
export * as controls from './controls';
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export * from './opcodes';
|
|
2
2
|
export { PeggedSwapArgs } from './pegged-swap-args';
|
|
3
3
|
export type { PeggedTokenInfo } from './types';
|
|
4
|
+
export { PeggedSwapCalculator } from './pegged-swap-calculator';
|
|
5
|
+
export { PeggedPrice } from './price';
|
|
6
|
+
export type { PeggedInitialBalances, PeggedSwapCalculatorArgs } from './pegged-swap-calculator';
|
|
7
|
+
export type { PeggedPriceJSON, PeggedPricePair, PeggedReservesInput, PeggedTokenRef, PeggedTokenReserve, } from './price';
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export * from './opcodes';
|
|
2
2
|
export { PeggedSwapArgs } from './pegged-swap-args';
|
|
3
3
|
export type { PeggedTokenInfo } from './types';
|
|
4
|
+
export { PeggedSwapCalculator } from './pegged-swap-calculator';
|
|
5
|
+
export { PeggedPrice } from './price';
|
|
6
|
+
export type { PeggedInitialBalances, PeggedSwapCalculatorArgs } from './pegged-swap-calculator';
|
|
7
|
+
export type { PeggedPriceJSON, PeggedPricePair, PeggedReservesInput, PeggedTokenRef, PeggedTokenReserve, } from './price';
|
package/dist/swap-vm/instructions/pegged-swap/pegged-swap-calculator/pegged-swap-calculator.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Address } from '@1inch/sdk-core';
|
|
2
|
+
import type { PeggedInitialBalances, PeggedSwapCalculatorArgs } from './types';
|
|
3
|
+
import type { PeggedPrice, PeggedTokenRef } from '../price';
|
|
4
|
+
export declare class PeggedSwapCalculator {
|
|
5
|
+
private readonly tokenA;
|
|
6
|
+
private readonly tokenB;
|
|
7
|
+
constructor(tokenA: PeggedTokenRef, tokenB: PeggedTokenRef);
|
|
8
|
+
get tokenLt(): PeggedTokenRef;
|
|
9
|
+
get tokenGt(): PeggedTokenRef;
|
|
10
|
+
static new(args: PeggedSwapCalculatorArgs): PeggedSwapCalculator;
|
|
11
|
+
/**
|
|
12
|
+
* Initial balances before deployment (`currentReserve = initialReserve`, u = v = 1).
|
|
13
|
+
* Given spot price and one raw initial reserve, returns the other.
|
|
14
|
+
*/
|
|
15
|
+
computeFixedAllocation(spotPrice: PeggedPrice, fixedReserveForToken: Address, fixedReserve: bigint): PeggedInitialBalances;
|
|
16
|
+
}
|
package/dist/swap-vm/instructions/pegged-swap/pegged-swap-calculator/pegged-swap-calculator.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Address } from '@1inch/sdk-core';
|
|
2
|
+
import type { PeggedInitialBalances, PeggedSwapCalculatorArgs } from './types';
|
|
3
|
+
import type { PeggedPrice, PeggedTokenRef } from '../price';
|
|
4
|
+
export declare class PeggedSwapCalculator {
|
|
5
|
+
private readonly tokenA;
|
|
6
|
+
private readonly tokenB;
|
|
7
|
+
constructor(tokenA: PeggedTokenRef, tokenB: PeggedTokenRef);
|
|
8
|
+
get tokenLt(): PeggedTokenRef;
|
|
9
|
+
get tokenGt(): PeggedTokenRef;
|
|
10
|
+
static new(args: PeggedSwapCalculatorArgs): PeggedSwapCalculator;
|
|
11
|
+
/**
|
|
12
|
+
* Initial balances before deployment (`currentReserve = initialReserve`, u = v = 1).
|
|
13
|
+
* Given spot price and one raw initial reserve, returns the other.
|
|
14
|
+
*/
|
|
15
|
+
computeFixedAllocation(spotPrice: PeggedPrice, fixedReserveForToken: Address, fixedReserve: bigint): PeggedInitialBalances;
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Matches `PeggedSwapMath.ONE` in swap-vm. */
|
|
2
|
+
export declare const PEGGED_SWAP_ONE: bigint;
|
|
3
|
+
/**
|
|
4
|
+
* Spot price tokenGt per tokenLt (raw) in 1e18 fixed-point.
|
|
5
|
+
*
|
|
6
|
+
* P = (Y₀/X₀) · (1/(2√u) + A) / (1/(2√v) + A) · (rateLt/rateGt)
|
|
7
|
+
*
|
|
8
|
+
* where u = x·ONE/X₀, v = y·ONE/Y₀, x/y are rate-adjusted Lt/Gt balances, A = `linearWidth`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function peggedSwapMarginalGtPerLtE18(balanceLtNorm: bigint, balanceGtNorm: bigint, x0: bigint, y0: bigint, linearWidth: bigint, rateLt: bigint, rateGt: bigint): bigint;
|
|
11
|
+
/**
|
|
12
|
+
* u = x·ONE/X₀, v = y·ONE/Y₀ (x, y are rate-adjusted reserves).
|
|
13
|
+
*/
|
|
14
|
+
export declare function normalizeReserve(currentReserve: bigint, initialReserve: bigint): bigint;
|
|
15
|
+
/**
|
|
16
|
+
* Marginal weight `1/(2√u) + A` (Lt side) or `1/(2√v) + A` (Gt side), A = `linearWidth`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function peggedSwapMarginalWeight(sqrtCoord: bigint, linearWidth: bigint): bigint;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Matches `PeggedSwapMath.ONE` in swap-vm. */
|
|
2
|
+
export declare const PEGGED_SWAP_ONE: bigint;
|
|
3
|
+
/**
|
|
4
|
+
* Spot price tokenGt per tokenLt (raw) in 1e18 fixed-point.
|
|
5
|
+
*
|
|
6
|
+
* P = (Y₀/X₀) · (1/(2√u) + A) / (1/(2√v) + A) · (rateLt/rateGt)
|
|
7
|
+
*
|
|
8
|
+
* where u = x·ONE/X₀, v = y·ONE/Y₀, x/y are rate-adjusted Lt/Gt balances, A = `linearWidth`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function peggedSwapMarginalGtPerLtE18(balanceLtNorm: bigint, balanceGtNorm: bigint, x0: bigint, y0: bigint, linearWidth: bigint, rateLt: bigint, rateGt: bigint): bigint;
|
|
11
|
+
/**
|
|
12
|
+
* u = x·ONE/X₀, v = y·ONE/Y₀ (x, y are rate-adjusted reserves).
|
|
13
|
+
*/
|
|
14
|
+
export declare function normalizeReserve(currentReserve: bigint, initialReserve: bigint): bigint;
|
|
15
|
+
/**
|
|
16
|
+
* Marginal weight `1/(2√u) + A` (Lt side) or `1/(2√v) + A` (Gt side), A = `linearWidth`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function peggedSwapMarginalWeight(sqrtCoord: bigint, linearWidth: bigint): bigint;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Address } from '@1inch/sdk-core';
|
|
2
|
+
import type { PeggedPriceJSON, PeggedPricePair, PeggedReservesInput, PeggedTokenRef } from './types';
|
|
3
|
+
export declare class PeggedPrice {
|
|
4
|
+
private readonly gtPerLtRaw;
|
|
5
|
+
readonly tokenLt: PeggedTokenRef;
|
|
6
|
+
readonly tokenGt: PeggedTokenRef;
|
|
7
|
+
private constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Spot price from per-token `initialReserve` / `currentReserve` (raw, not rate-scaled) and `linearWidth`.
|
|
10
|
+
* Use currentReserve = initialReserve to calculate the spot price before the strategy was deployed
|
|
11
|
+
*/
|
|
12
|
+
static fromReserves(input: PeggedReservesInput): PeggedPrice;
|
|
13
|
+
/**
|
|
14
|
+
* Human decimal string for **quote per 1 base**.
|
|
15
|
+
*/
|
|
16
|
+
static fromHuman(price: string, pair: PeggedPricePair): PeggedPrice;
|
|
17
|
+
static fromJSON(input: PeggedPriceJSON): PeggedPrice;
|
|
18
|
+
private static fromGtPerLtE18;
|
|
19
|
+
matchesTokens(tokenA: Address, tokenB: Address): boolean;
|
|
20
|
+
equals(other: PeggedPrice): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Decimal string for **quote per 1 base**; rounded half-up to quote token decimals.
|
|
23
|
+
*/
|
|
24
|
+
toHuman(quoteToken: Address): string;
|
|
25
|
+
/** Marginal gt-per-lt rate in 1e18 fixed-point. */
|
|
26
|
+
toGtPerLtE18(): bigint;
|
|
27
|
+
toJSON(): PeggedPriceJSON;
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Address } from '@1inch/sdk-core';
|
|
2
|
+
import type { PeggedPriceJSON, PeggedPricePair, PeggedReservesInput, PeggedTokenRef } from './types';
|
|
3
|
+
export declare class PeggedPrice {
|
|
4
|
+
private readonly gtPerLtRaw;
|
|
5
|
+
readonly tokenLt: PeggedTokenRef;
|
|
6
|
+
readonly tokenGt: PeggedTokenRef;
|
|
7
|
+
private constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Spot price from per-token `initialReserve` / `currentReserve` (raw, not rate-scaled) and `linearWidth`.
|
|
10
|
+
* Use currentReserve = initialReserve to calculate the spot price before the strategy was deployed
|
|
11
|
+
*/
|
|
12
|
+
static fromReserves(input: PeggedReservesInput): PeggedPrice;
|
|
13
|
+
/**
|
|
14
|
+
* Human decimal string for **quote per 1 base**.
|
|
15
|
+
*/
|
|
16
|
+
static fromHuman(price: string, pair: PeggedPricePair): PeggedPrice;
|
|
17
|
+
static fromJSON(input: PeggedPriceJSON): PeggedPrice;
|
|
18
|
+
private static fromGtPerLtE18;
|
|
19
|
+
matchesTokens(tokenA: Address, tokenB: Address): boolean;
|
|
20
|
+
equals(other: PeggedPrice): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Decimal string for **quote per 1 base**; rounded half-up to quote token decimals.
|
|
23
|
+
*/
|
|
24
|
+
toHuman(quoteToken: Address): string;
|
|
25
|
+
/** Marginal gt-per-lt rate in 1e18 fixed-point. */
|
|
26
|
+
toGtPerLtE18(): bigint;
|
|
27
|
+
toJSON(): PeggedPriceJSON;
|
|
28
|
+
}
|