@latchprotocol/widgets 0.1.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 +649 -0
- package/dist/adapters/binDistribution.d.ts +19 -0
- package/dist/adapters/binDistribution.d.ts.map +1 -0
- package/dist/adapters/protocol.d.ts +409 -0
- package/dist/adapters/protocol.d.ts.map +1 -0
- package/dist/adapters/sale.d.ts +142 -0
- package/dist/adapters/sale.d.ts.map +1 -0
- package/dist/adapters/viem.d.ts +89 -0
- package/dist/adapters/viem.d.ts.map +1 -0
- package/dist/callpath/constants.d.ts +218 -0
- package/dist/callpath/constants.d.ts.map +1 -0
- package/dist/callpath/launch.d.ts +1979 -0
- package/dist/callpath/launch.d.ts.map +1 -0
- package/dist/callpath/liquidity.d.ts +103 -0
- package/dist/callpath/liquidity.d.ts.map +1 -0
- package/dist/callpath/plan.d.ts +34 -0
- package/dist/callpath/plan.d.ts.map +1 -0
- package/dist/callpath/swap.d.ts +129 -0
- package/dist/callpath/swap.d.ts.map +1 -0
- package/dist/chunks/SwapWidget-DgyHAVc8.js +2404 -0
- package/dist/chunks/SwapWidget-DgyHAVc8.js.map +1 -0
- package/dist/chunks/scan-Dhu7f4Nl.js +2497 -0
- package/dist/chunks/scan-Dhu7f4Nl.js.map +1 -0
- package/dist/chunks/useLocker-D1c_NTk-.js +1613 -0
- package/dist/chunks/useLocker-D1c_NTk-.js.map +1 -0
- package/dist/components/LaunchWidget.d.ts +117 -0
- package/dist/components/LaunchWidget.d.ts.map +1 -0
- package/dist/components/LiquidityWidget.d.ts +33 -0
- package/dist/components/LiquidityWidget.d.ts.map +1 -0
- package/dist/components/LockerWidget.d.ts +51 -0
- package/dist/components/LockerWidget.d.ts.map +1 -0
- package/dist/components/LocksWidgets.d.ts +61 -0
- package/dist/components/LocksWidgets.d.ts.map +1 -0
- package/dist/components/SwapWidget.d.ts +165 -0
- package/dist/components/SwapWidget.d.ts.map +1 -0
- package/dist/components/TokenTrustPanel.d.ts +32 -0
- package/dist/components/TokenTrustPanel.d.ts.map +1 -0
- package/dist/components/lockCharts.d.ts +29 -0
- package/dist/components/lockCharts.d.ts.map +1 -0
- package/dist/components/portal.d.ts +10 -0
- package/dist/components/portal.d.ts.map +1 -0
- package/dist/components/primitives.d.ts +139 -0
- package/dist/components/primitives.d.ts.map +1 -0
- package/dist/components/swap/SwapSettings.d.ts +12 -0
- package/dist/components/swap/SwapSettings.d.ts.map +1 -0
- package/dist/components/swap/TokenSelect.d.ts +61 -0
- package/dist/components/swap/TokenSelect.d.ts.map +1 -0
- package/dist/components/swap/state.d.ts +208 -0
- package/dist/components/swap/state.d.ts.map +1 -0
- package/dist/config/chain.d.ts +163 -0
- package/dist/config/chain.d.ts.map +1 -0
- package/dist/config/integrator.d.ts +121 -0
- package/dist/config/integrator.d.ts.map +1 -0
- package/dist/context/WidgetProvider.d.ts +78 -0
- package/dist/context/WidgetProvider.d.ts.map +1 -0
- package/dist/core/clMath.d.ts +98 -0
- package/dist/core/clMath.d.ts.map +1 -0
- package/dist/core/errors.d.ts +18 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/format.d.ts +47 -0
- package/dist/core/format.d.ts.map +1 -0
- package/dist/core/liquidityGuards.d.ts +53 -0
- package/dist/core/liquidityGuards.d.ts.map +1 -0
- package/dist/core/liquidityRefresh.d.ts +35 -0
- package/dist/core/liquidityRefresh.d.ts.map +1 -0
- package/dist/core/math.d.ts +129 -0
- package/dist/core/math.d.ts.map +1 -0
- package/dist/core/pool.d.ts +33 -0
- package/dist/core/pool.d.ts.map +1 -0
- package/dist/core/tokenLists.d.ts +46 -0
- package/dist/core/tokenLists.d.ts.map +1 -0
- package/dist/embed/iframe.d.ts +185 -0
- package/dist/embed/iframe.d.ts.map +1 -0
- package/dist/embed/lockBadge.d.ts +55 -0
- package/dist/embed/lockBadge.d.ts.map +1 -0
- package/dist/embed/webComponent.d.ts +83 -0
- package/dist/embed/webComponent.d.ts.map +1 -0
- package/dist/embed.d.ts +25 -0
- package/dist/embed.d.ts.map +1 -0
- package/dist/embed.js +543 -0
- package/dist/embed.js.map +1 -0
- package/dist/headless.d.ts +60 -0
- package/dist/headless.d.ts.map +1 -0
- package/dist/headless.js +223 -0
- package/dist/headless.js.map +1 -0
- package/dist/hooks/useAsyncResource.d.ts +38 -0
- package/dist/hooks/useAsyncResource.d.ts.map +1 -0
- package/dist/hooks/useLaunch.d.ts +140 -0
- package/dist/hooks/useLaunch.d.ts.map +1 -0
- package/dist/hooks/useLiquidity.d.ts +91 -0
- package/dist/hooks/useLiquidity.d.ts.map +1 -0
- package/dist/hooks/useLocker.d.ts +77 -0
- package/dist/hooks/useLocker.d.ts.map +1 -0
- package/dist/hooks/useLocks.d.ts +33 -0
- package/dist/hooks/useLocks.d.ts.map +1 -0
- package/dist/hooks/useSwapExecute.d.ts +46 -0
- package/dist/hooks/useSwapExecute.d.ts.map +1 -0
- package/dist/hooks/useSwapQuote.d.ts +51 -0
- package/dist/hooks/useSwapQuote.d.ts.map +1 -0
- package/dist/hooks/useTokenLists.d.ts +26 -0
- package/dist/hooks/useTokenLists.d.ts.map +1 -0
- package/dist/hooks/useTokenTrust.d.ts +40 -0
- package/dist/hooks/useTokenTrust.d.ts.map +1 -0
- package/dist/hooks/useTokens.d.ts +15 -0
- package/dist/hooks/useTokens.d.ts.map +1 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1052 -0
- package/dist/index.js.map +1 -0
- package/dist/latch-embed.d.ts +19 -0
- package/dist/latch-embed.d.ts.map +1 -0
- package/dist/latch-embed.js +950 -0
- package/dist/latch-embed.js.map +1 -0
- package/dist/latch-embed.mjs +13162 -0
- package/dist/latch-embed.mjs.map +1 -0
- package/dist/locker/model.d.ts +73 -0
- package/dist/locker/model.d.ts.map +1 -0
- package/dist/locks/embedModel.d.ts +22 -0
- package/dist/locks/embedModel.d.ts.map +1 -0
- package/dist/locks/fetch.d.ts +60 -0
- package/dist/locks/fetch.d.ts.map +1 -0
- package/dist/locks/model.d.ts +143 -0
- package/dist/locks/model.d.ts.map +1 -0
- package/dist/locks/scan.d.ts +25 -0
- package/dist/locks/scan.d.ts.map +1 -0
- package/dist/styles/css.d.ts +32 -0
- package/dist/styles/css.d.ts.map +1 -0
- package/dist/styles.css +895 -0
- package/dist/trust/model.d.ts +48 -0
- package/dist/trust/model.d.ts.map +1 -0
- package/package.json +102 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Concentrated-liquidity arithmetic, transcribed from the pool's own formulas.
|
|
3
|
+
*
|
|
4
|
+
* The live adapter uses this to turn desired amounts into a liquidity figure
|
|
5
|
+
* (`quoteAddLiquidity`), a position's liquidity back into the amounts a
|
|
6
|
+
* withdrawal returns (`quoteRemoveLiquidity`, `listPositions`) and its
|
|
7
|
+
* uncollected fees. Nothing here estimates: a wrong constant would render a
|
|
8
|
+
* number that LOOKS real and is not, so the constants are copied verbatim from
|
|
9
|
+
* `TickMath.sol` and {@link assertTickMathSelfConsistent} checks the
|
|
10
|
+
* transcription against values the chain publishes.
|
|
11
|
+
*
|
|
12
|
+
* Rounding directions match the contracts: an add rounds **up** (the pool takes
|
|
13
|
+
* one wei more), a remove rounds **down** (it returns one wei less).
|
|
14
|
+
*
|
|
15
|
+
* - `TickMath.getSqrtRatioAtTick`
|
|
16
|
+
* - `SqrtPriceMath.getAmount{0,1}Delta`
|
|
17
|
+
* - `LiquidityAmounts.getLiquidityForAmounts`
|
|
18
|
+
* - `Tick.getFeeGrowthInside` + `CLPosition.update` (fees owed)
|
|
19
|
+
*/
|
|
20
|
+
/** 2^96. */
|
|
21
|
+
export declare const Q96: bigint;
|
|
22
|
+
/** Lowest tick a pool can quote. */
|
|
23
|
+
export declare const MIN_TICK = -887272;
|
|
24
|
+
/** Highest tick a pool can quote. */
|
|
25
|
+
export declare const MAX_TICK = 887272;
|
|
26
|
+
/** `TickMath.getSqrtRatioAtTick`. */
|
|
27
|
+
export declare function getSqrtRatioAtTick(tick: number): bigint;
|
|
28
|
+
/** `SqrtPriceMath.getAmount0Delta`. */
|
|
29
|
+
export declare function getAmount0Delta(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, liquidity: bigint, roundUp: boolean): bigint;
|
|
30
|
+
/** `SqrtPriceMath.getAmount1Delta`. */
|
|
31
|
+
export declare function getAmount1Delta(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, liquidity: bigint, roundUp: boolean): bigint;
|
|
32
|
+
/** `LiquidityAmounts.getLiquidityForAmount0`. */
|
|
33
|
+
export declare function getLiquidityForAmount0(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, amount0: bigint): bigint;
|
|
34
|
+
/** `LiquidityAmounts.getLiquidityForAmount1`. */
|
|
35
|
+
export declare function getLiquidityForAmount1(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, amount1: bigint): bigint;
|
|
36
|
+
/** `LiquidityAmounts.getLiquidityForAmounts`. */
|
|
37
|
+
export declare function getLiquidityForAmounts(sqrtRatioX96: bigint, sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, amount0: bigint, amount1: bigint): bigint;
|
|
38
|
+
/**
|
|
39
|
+
* Amounts the pool will move for a liquidity change spanning `sqrtRatioX96`.
|
|
40
|
+
*
|
|
41
|
+
* `adding` selects the rounding direction: the contracts round **towards the
|
|
42
|
+
* pool** either way, so an add costs one wei more and a remove returns one wei
|
|
43
|
+
* less than the unrounded figure.
|
|
44
|
+
*/
|
|
45
|
+
export declare function amountsForLiquidity(sqrtRatioX96: bigint, tickLower: number, tickUpper: number, liquidity: bigint, adding: boolean): {
|
|
46
|
+
amount0: bigint;
|
|
47
|
+
amount1: bigint;
|
|
48
|
+
};
|
|
49
|
+
/** Which tokens a CL range takes at the pool's current price. */
|
|
50
|
+
export type ClRangeSide = "both" | "token0-only" | "token1-only";
|
|
51
|
+
/**
|
|
52
|
+
* Which tokens a deposit into `[tickLower, tickUpper)` takes at `sqrtRatioX96`:
|
|
53
|
+
* a range entirely above the price holds only token0, one entirely below only
|
|
54
|
+
* token1, and a range spanning the price holds both in a ratio the price fixes.
|
|
55
|
+
*/
|
|
56
|
+
export declare function clRangeSide(sqrtRatioX96: bigint, tickLower: number, tickUpper: number): ClRangeSide;
|
|
57
|
+
/**
|
|
58
|
+
* The other token's amount for a one-sided entry into an in-range CL
|
|
59
|
+
* position: the liquidity the entered amount buys, and what that liquidity
|
|
60
|
+
* costs of the other token (rounded up, as the position manager settles an
|
|
61
|
+
* add). `null` when the range takes only one token - the other side is then
|
|
62
|
+
* zero by construction, and no amount of it can be deposited.
|
|
63
|
+
*/
|
|
64
|
+
export declare function pairedAmountForRange(sqrtRatioX96: bigint, tickLower: number, tickUpper: number, entered: "token0" | "token1", amount: bigint): bigint | null;
|
|
65
|
+
/** Fee growth recorded on one initialised tick (`Tick.Info`). */
|
|
66
|
+
export interface TickFeeGrowth {
|
|
67
|
+
readonly feeGrowthOutside0X128: bigint;
|
|
68
|
+
readonly feeGrowthOutside1X128: bigint;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Fees a position has earned since it was last touched, exactly as
|
|
72
|
+
* `CLPosition.update` credits them on the next `modifyLiquidity`.
|
|
73
|
+
*
|
|
74
|
+
* All subtractions wrap at 2^256 on purpose: the pool's own arithmetic is
|
|
75
|
+
* `unchecked`, and fee-growth values are only meaningful modulo 2^256.
|
|
76
|
+
*/
|
|
77
|
+
export declare function uncollectedFees(args: {
|
|
78
|
+
readonly liquidity: bigint;
|
|
79
|
+
readonly tickLower: number;
|
|
80
|
+
readonly tickUpper: number;
|
|
81
|
+
readonly currentTick: number;
|
|
82
|
+
readonly feeGrowthGlobal0X128: bigint;
|
|
83
|
+
readonly feeGrowthGlobal1X128: bigint;
|
|
84
|
+
readonly lower: TickFeeGrowth;
|
|
85
|
+
readonly upper: TickFeeGrowth;
|
|
86
|
+
readonly feeGrowthInside0LastX128: bigint;
|
|
87
|
+
readonly feeGrowthInside1LastX128: bigint;
|
|
88
|
+
}): {
|
|
89
|
+
fees0: bigint;
|
|
90
|
+
fees1: bigint;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Checks this transcription against values the chain publishes.
|
|
94
|
+
*
|
|
95
|
+
* @throws when the bit-magic constants have been corrupted.
|
|
96
|
+
*/
|
|
97
|
+
export declare function assertTickMathSelfConsistent(): void;
|
|
98
|
+
//# sourceMappingURL=clMath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clMath.d.ts","sourceRoot":"","sources":["../../src/core/clMath.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,YAAY;AACZ,eAAO,MAAM,GAAG,QAAY,CAAC;AAK7B,oCAAoC;AACpC,eAAO,MAAM,QAAQ,UAAU,CAAC;AAChC,qCAAqC;AACrC,eAAO,MAAM,QAAQ,SAAS,CAAC;AAwB/B,qCAAqC;AACrC,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAYvD;AAeD,uCAAuC;AACvC,wBAAgB,eAAe,CAC7B,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,OAAO,GACf,MAAM,CAOR;AAED,uCAAuC;AACvC,wBAAgB,eAAe,CAC7B,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,OAAO,GACf,MAAM,CAKR;AAED,iDAAiD;AACjD,wBAAgB,sBAAsB,CACpC,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,GACd,MAAM,CAIR;AAED,iDAAiD;AACjD,wBAAgB,sBAAsB,CACpC,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,GACd,MAAM,CAGR;AAED,iDAAiD;AACjD,wBAA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oB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,wBAAwB,EAAE,MAAM,CAAC;IAC1C,QAAQ,CAAC,wBAAwB,EAAE,MAAM,CAAC;CAC3C,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAcnC;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,IAAI,IAAI,CAiBnD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns whatever a quote, a wallet or a transaction threw into one sentence a
|
|
3
|
+
* trader can read.
|
|
4
|
+
*
|
|
5
|
+
* The raw error stays on the hook results (`error`) for hosts and logs; this is
|
|
6
|
+
* only what the styled widgets PRINT. Nothing here invents a cause: a revert is
|
|
7
|
+
* decoded against the ABIs of the contracts the widgets actually call (router,
|
|
8
|
+
* quoters, position managers, launch guards, core), wrappers are unwrapped
|
|
9
|
+
* (core's `WrappedError`, the quoter's `UnexpectedRevertBytes`), and a known
|
|
10
|
+
* error name gets a plain explanation. An unknown selector is reported as what
|
|
11
|
+
* it is - an unrecognised refusal - never guessed at.
|
|
12
|
+
*/
|
|
13
|
+
import { type Hex } from "viem";
|
|
14
|
+
/** Decodes revert data to an error name, following wrappers. `null` when unknown. */
|
|
15
|
+
export declare function decodeRevertName(data: Hex, depth?: number): string | null;
|
|
16
|
+
/** What went wrong, in one plain sentence. `context` names the action for the fallbacks. */
|
|
17
|
+
export declare function describeError(error: unknown, context?: "quote" | "swap" | "liquidity" | "transaction"): string;
|
|
18
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAoD,KAAK,GAAG,EAAE,MAAM,MAAM,CAAC;AAoJlF,qFAAqF;AACrF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,SAAI,GAAG,MAAM,GAAG,IAAI,CAoBpE;AA8BD,4FAA4F;AAC5F,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAE,OAAO,GAAG,MAAM,GAAG,WAAW,GAAG,aAA6B,GAAG,MAAM,CAoC7H"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Display formatting and user-input parsing.
|
|
3
|
+
*
|
|
4
|
+
* Parsing is the security-relevant half: a mis-parsed decimal string becomes a
|
|
5
|
+
* wrong `amountIn`, and `parseUnits` will happily truncate extra decimal places.
|
|
6
|
+
* {@link parseAmount} refuses ambiguous input instead of guessing.
|
|
7
|
+
*/
|
|
8
|
+
/** A rejected amount string, with a reason suitable for showing to a user. */
|
|
9
|
+
export interface AmountParseFailure {
|
|
10
|
+
readonly ok: false;
|
|
11
|
+
readonly reason: "empty" | "not-a-number" | "negative" | "too-many-decimals" | "zero";
|
|
12
|
+
readonly message: string;
|
|
13
|
+
}
|
|
14
|
+
/** A successfully parsed amount. */
|
|
15
|
+
export interface AmountParseSuccess {
|
|
16
|
+
readonly ok: true;
|
|
17
|
+
readonly value: bigint;
|
|
18
|
+
}
|
|
19
|
+
export type AmountParseResult = AmountParseSuccess | AmountParseFailure;
|
|
20
|
+
/**
|
|
21
|
+
* Parses a user-entered decimal string into the token's smallest unit.
|
|
22
|
+
*
|
|
23
|
+
* @param allowZero when `false` (default) a zero amount is rejected, since a
|
|
24
|
+
* zero-amount swap is never what the user meant.
|
|
25
|
+
*/
|
|
26
|
+
export declare function parseAmount(input: string, decimals: number, allowZero?: boolean): AmountParseResult;
|
|
27
|
+
/**
|
|
28
|
+
* Formats a smallest-unit amount for display.
|
|
29
|
+
*
|
|
30
|
+
* Trims trailing zeros and caps the visible fraction, but never rounds a value
|
|
31
|
+
* up to a non-zero display when it is zero, and never shows `0` for a non-zero
|
|
32
|
+
* dust amount - it shows `<0.0001` instead.
|
|
33
|
+
*/
|
|
34
|
+
export declare function formatAmount(value: bigint, decimals: number, maxFractionDigits?: number): string;
|
|
35
|
+
/** Formats a rate for display, e.g. `1 A = 1,234.5678 B`. */
|
|
36
|
+
export declare function formatRate(rate: number | null, symbolIn: string, symbolOut: string): string;
|
|
37
|
+
/** Formats a bps value as a percentage string. */
|
|
38
|
+
export declare function formatPercentFromBps(bps: number | null): string;
|
|
39
|
+
/** Formats a pips value (1e6 = 100%) as a percentage string. */
|
|
40
|
+
export declare function formatPercentFromPips(pips: number): string;
|
|
41
|
+
/** Shortens an address for display: `0x1234...cdef`. */
|
|
42
|
+
export declare function shortAddress(address: string): string;
|
|
43
|
+
/** Formats a remaining duration in seconds as a compact `1d 4h 3m` string. */
|
|
44
|
+
export declare function formatDuration(totalSeconds: number): string;
|
|
45
|
+
/** Formats a unix timestamp for display in the viewer's locale. */
|
|
46
|
+
export declare function formatTimestamp(unixSeconds: bigint | number): string;
|
|
47
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/core/format.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AAIH,8EAA8E;AAC9E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,MAAM,EACX,OAAO,GACP,cAAc,GACd,UAAU,GACV,mBAAmB,GACnB,MAAM,CAAC;IACX,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,oCAAoC;AACpC,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,GAAG,kBAAkB,CAAC;AAIxE;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,SAAS,UAAQ,GAChB,iBAAiB,CAwBnB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,iBAAiB,SAAI,GACpB,MAAM,CAmBR;AAMD,6DAA6D;AAC7D,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,MAAM,CAMR;AAED,kDAAkD;AAClD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAK/D;AAED,gEAAgE;AAChE,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI1D;AAMD,wDAAwD;AACxD,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGpD;AAED,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAa3D;AAED,mEAAmE;AACnE,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAIpE"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure guards for the liquidity flow: what a deposit will take from the wallet,
|
|
3
|
+
* and whether the wallet holds it.
|
|
4
|
+
*
|
|
5
|
+
* WHY THIS EXISTS. Without it an add that the wallet cannot pay reaches gas
|
|
6
|
+
* estimation and comes back as `TRANSFER_FROM_FAILED` (or an out-of-funds
|
|
7
|
+
* error for native), after the visitor may already have signed an approval
|
|
8
|
+
* for tokens they do not hold. The widget checks the balances first and says
|
|
9
|
+
* "Insufficient <SYMBOL>" before anything is signed.
|
|
10
|
+
*
|
|
11
|
+
* WHAT IS COMPARED, exactly:
|
|
12
|
+
* - native: the transaction's `value`, which is the side's slippage-bounded
|
|
13
|
+
* MAXIMUM (the adapter sends the whole cap and the position manager refunds
|
|
14
|
+
* the rest). No gas reserve is invented on top: the wallet refuses a
|
|
15
|
+
* transaction it cannot pay gas for, and a made-up margin would refuse
|
|
16
|
+
* deposits that fit.
|
|
17
|
+
* - ERC-20: the QUOTED amount, which is what the position manager pulls at
|
|
18
|
+
* the current price. The slippage cap is only an allowance ceiling; a wallet
|
|
19
|
+
* holding the quoted amount but not the cap can still deposit.
|
|
20
|
+
*/
|
|
21
|
+
import type { TokenInfo } from "../adapters/protocol.js";
|
|
22
|
+
/** True for the chain's native asset. */
|
|
23
|
+
export declare function isNativeToken(token: TokenInfo): boolean;
|
|
24
|
+
/** One side of a deposit: the token and what the wallet must hold of it. */
|
|
25
|
+
export interface DepositRequirement {
|
|
26
|
+
readonly token: TokenInfo;
|
|
27
|
+
readonly required: bigint;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* What an add-liquidity takes from the wallet, per token, in pool order. A side
|
|
31
|
+
* that deposits nothing is left out.
|
|
32
|
+
*/
|
|
33
|
+
export declare function depositRequirements(quote: {
|
|
34
|
+
readonly pool: {
|
|
35
|
+
readonly token0: TokenInfo;
|
|
36
|
+
readonly token1: TokenInfo;
|
|
37
|
+
};
|
|
38
|
+
readonly amount0: bigint;
|
|
39
|
+
readonly amount1: bigint;
|
|
40
|
+
}, amount0Max: bigint, amount1Max: bigint): readonly DepositRequirement[];
|
|
41
|
+
/**
|
|
42
|
+
* The first token the wallet holds too little of, or `null` when every balance
|
|
43
|
+
* covers its requirement. `balances[i]` is the wallet's balance of
|
|
44
|
+
* `requirements[i].token`; a `null` balance (not read) is never reported as a
|
|
45
|
+
* shortfall - the widget does not claim what it has not read.
|
|
46
|
+
*/
|
|
47
|
+
export declare function findShortfall(requirements: readonly DepositRequirement[], balances: readonly (bigint | null)[]): TokenInfo | null;
|
|
48
|
+
/** Refusal raised before an approval or a deposit the wallet cannot pay. Nothing was signed. */
|
|
49
|
+
export declare class InsufficientBalanceError extends Error {
|
|
50
|
+
readonly token: TokenInfo;
|
|
51
|
+
constructor(token: TokenInfo);
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=liquidityGuards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquidityGuards.d.ts","sourceRoot":"","sources":["../../src/core/liquidityGuards.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,yCAAyC;AACzC,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAEvD;AAED,4EAA4E;AAC5E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE;IACL,QAAQ,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;KAAE,CAAC;IAC1E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,EACD,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GACjB,SAAS,kBAAkB,EAAE,CAS/B;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,YAAY,EAAE,SAAS,kBAAkB,EAAE,EAC3C,QAAQ,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,GACnC,SAAS,GAAG,IAAI,CAMlB;AAED,gGAAgG;AAChG,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;gBAEd,KAAK,EAAE,SAAS;CAK7B"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeping the liquidity widget's own lists true after a confirmed add or
|
|
3
|
+
* removal, without a reload.
|
|
4
|
+
*
|
|
5
|
+
* The widget counts confirmed changes (`bumpOnConfirmed`); the positions list,
|
|
6
|
+
* the pool state and the wallet balances take that count as a dependency, so a
|
|
7
|
+
* confirmation re-reads them. The picker then re-selects from the FRESH list
|
|
8
|
+
* (`reconcileSelection`), so a partial removal shows the new amounts and a
|
|
9
|
+
* position emptied to zero disappears (`withdrawablePositions`).
|
|
10
|
+
*/
|
|
11
|
+
import type { PositionInfo } from "../adapters/protocol.js";
|
|
12
|
+
/**
|
|
13
|
+
* Wraps the host's `onLiquidityChanged` so a confirmation also advances the
|
|
14
|
+
* widget's refresh counter. The counter moves first: the host's callback can
|
|
15
|
+
* throw without leaving the widget's lists stale.
|
|
16
|
+
*/
|
|
17
|
+
export declare function bumpOnConfirmed<H>(bump: () => void, host: ((hash: H) => void) | undefined): (hash: H) => void;
|
|
18
|
+
/**
|
|
19
|
+
* The positions there is something to withdraw from. A CL position removed to
|
|
20
|
+
* zero keeps its NFT (the widget decreases liquidity and takes the tokens; it
|
|
21
|
+
* does not burn), so the adapter still lists it with zero liquidity and zero
|
|
22
|
+
* owed fees - offering it in the Remove picker would quote a withdrawal of
|
|
23
|
+
* nothing.
|
|
24
|
+
*/
|
|
25
|
+
export declare function withdrawablePositions(list: readonly PositionInfo[]): readonly PositionInfo[];
|
|
26
|
+
/**
|
|
27
|
+
* The selection after the list was re-read: the SAME position as its fresh
|
|
28
|
+
* record (new amounts, new liquidity), else the first position, else `null`.
|
|
29
|
+
* Returning the fresh object matters - a stale one keeps quoting the
|
|
30
|
+
* withdrawal against the liquidity it had before the last removal.
|
|
31
|
+
*/
|
|
32
|
+
export declare function reconcileSelection<T extends {
|
|
33
|
+
readonly id: string;
|
|
34
|
+
}>(current: T | null, list: readonly T[]): T | null;
|
|
35
|
+
//# sourceMappingURL=liquidityRefresh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquidityRefresh.d.ts","sourceRoot":"","sources":["../../src/core/liquidityRefresh.ts"],"names":[],"mappings":"AACA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE5D;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,IAAI,EAAE,MAAM,IAAI,EAChB,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC,GAAG,SAAS,GACpC,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAKnB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,SAAS,YAAY,EAAE,GAAG,SAAS,YAAY,EAAE,CAE5F;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI,CAMrH"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quote arithmetic.
|
|
3
|
+
*
|
|
4
|
+
* Everything here is pure, integer-only and independent of any chain, adapter
|
|
5
|
+
* or component, so it can be tested exhaustively. The rounding directions match
|
|
6
|
+
* the contracts: fees and minimum-received amounts round **down**, maximum-spend
|
|
7
|
+
* amounts round **up**. Every rounding error is therefore in the user's favour
|
|
8
|
+
* or, at worst, causes a revert instead of a silent loss.
|
|
9
|
+
*/
|
|
10
|
+
import { type ResolvedIntegratorConfig } from "../config/integrator.js";
|
|
11
|
+
/** Basis-point denominator as a bigint. */
|
|
12
|
+
export declare const BPS = 10000n;
|
|
13
|
+
/** Pips denominator, matching `ProtocolFeeLibrary.PIPS_DENOMINATOR`. */
|
|
14
|
+
export declare const PIPS = 1000000n;
|
|
15
|
+
/**
|
|
16
|
+
* Highest slippage tolerance the widgets accept, in bps (50%).
|
|
17
|
+
*
|
|
18
|
+
* Above this a "swap" is indistinguishable from a donation to whoever is
|
|
19
|
+
* watching the mempool.
|
|
20
|
+
*/
|
|
21
|
+
export declare const MAX_SLIPPAGE_BPS = 5000;
|
|
22
|
+
/** Slippage used when the embedder sets none. */
|
|
23
|
+
export declare const DEFAULT_SLIPPAGE_BPS = 50;
|
|
24
|
+
/** Price impact at or above which the UI demands explicit confirmation. */
|
|
25
|
+
export declare const HIGH_PRICE_IMPACT_BPS = 300;
|
|
26
|
+
/** Price impact treated as certainly-a-mistake. */
|
|
27
|
+
export declare const SEVERE_PRICE_IMPACT_BPS = 1000;
|
|
28
|
+
/** `floor(amount * bps / 10_000)`. */
|
|
29
|
+
export declare function portionOf(amount: bigint, bps: number): bigint;
|
|
30
|
+
/** `floor(amount * pips / 1_000_000)`. */
|
|
31
|
+
export declare function pipsOf(amount: bigint, pips: number): bigint;
|
|
32
|
+
/**
|
|
33
|
+
* Minimum amount that must be received for the transaction to be acceptable.
|
|
34
|
+
*
|
|
35
|
+
* Rounds down, so the on-chain check is never tighter than the user's stated
|
|
36
|
+
* tolerance.
|
|
37
|
+
*/
|
|
38
|
+
export declare function minimumReceived(expected: bigint, slippageBps: number): bigint;
|
|
39
|
+
/**
|
|
40
|
+
* Maximum amount the user is willing to spend.
|
|
41
|
+
*
|
|
42
|
+
* Rounds up, so a one-wei rounding difference on-chain does not revert an
|
|
43
|
+
* otherwise valid exact-output swap.
|
|
44
|
+
*/
|
|
45
|
+
export declare function maximumSpent(expected: bigint, slippageBps: number): bigint;
|
|
46
|
+
/**
|
|
47
|
+
* Price impact in basis points: how much worse the realised rate is than the
|
|
48
|
+
* pool's rate for an infinitesimal trade.
|
|
49
|
+
*
|
|
50
|
+
* `spotAmountOut` is what the same input would return at the current price with
|
|
51
|
+
* no impact and no LP fee. Returns `null` when that reference is unavailable or
|
|
52
|
+
* zero, because a fabricated zero would read as "no impact" - the most
|
|
53
|
+
* dangerous possible default.
|
|
54
|
+
*/
|
|
55
|
+
export declare function priceImpactBps(grossAmountOut: bigint, spotAmountOut: bigint | null | undefined): number | null;
|
|
56
|
+
/** Severity buckets for a price impact, used for presentation and gating. */
|
|
57
|
+
export type PriceImpactSeverity = "unknown" | "low" | "elevated" | "high" | "severe";
|
|
58
|
+
/** Classifies a price impact in bps. */
|
|
59
|
+
export declare function priceImpactSeverity(bps: number | null): PriceImpactSeverity;
|
|
60
|
+
/** Inputs to {@link buildQuoteBreakdown}. */
|
|
61
|
+
export interface QuoteBreakdownInput {
|
|
62
|
+
/** Input amount, in the input currency's smallest unit. */
|
|
63
|
+
readonly amountIn: bigint;
|
|
64
|
+
/** Output before any integrator fee, as returned by the adapter. */
|
|
65
|
+
readonly grossAmountOut: bigint;
|
|
66
|
+
/** Output at the current price with no impact, if the adapter can supply it. */
|
|
67
|
+
readonly spotAmountOut?: bigint | null;
|
|
68
|
+
/** LP fee already deducted by the pool, in the output currency. */
|
|
69
|
+
readonly lpFeeAmount?: bigint;
|
|
70
|
+
/** Pool's LP fee rate in pips. */
|
|
71
|
+
readonly lpFeePips?: number;
|
|
72
|
+
/** The rate is hook-set and was not readable; `lpFeePips` is a placeholder zero. */
|
|
73
|
+
readonly lpFeeUnknown?: boolean;
|
|
74
|
+
/** User's slippage tolerance. */
|
|
75
|
+
readonly slippageBps: number;
|
|
76
|
+
/** Validated integrator config. */
|
|
77
|
+
readonly integrator: ResolvedIntegratorConfig;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Everything a swap UI and a swap call path need, derived once.
|
|
81
|
+
*
|
|
82
|
+
* The two minimums matter and are not interchangeable:
|
|
83
|
+
*
|
|
84
|
+
* - `minAmountOutGross` is checked by the swap action, before the fee is split.
|
|
85
|
+
* - `minAmountOutNet` is what the user is guaranteed to actually receive, and is
|
|
86
|
+
* the value the final take/sweep enforces.
|
|
87
|
+
*/
|
|
88
|
+
export interface QuoteBreakdown {
|
|
89
|
+
readonly amountIn: bigint;
|
|
90
|
+
readonly grossAmountOut: bigint;
|
|
91
|
+
readonly integratorFee: bigint;
|
|
92
|
+
readonly integratorFeeBps: number;
|
|
93
|
+
readonly netAmountOut: bigint;
|
|
94
|
+
readonly minAmountOutGross: bigint;
|
|
95
|
+
readonly minAmountOutNet: bigint;
|
|
96
|
+
readonly lpFeeAmount: bigint;
|
|
97
|
+
readonly lpFeePips: number;
|
|
98
|
+
/** See {@link QuoteBreakdownInput.lpFeeUnknown}. Render as "dynamic", never as a percentage. */
|
|
99
|
+
readonly lpFeeUnknown: boolean;
|
|
100
|
+
readonly slippageBps: number;
|
|
101
|
+
readonly priceImpactBps: number | null;
|
|
102
|
+
readonly priceImpactSeverity: PriceImpactSeverity;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Derives the full quote breakdown.
|
|
106
|
+
*
|
|
107
|
+
* `minAmountOutNet` is computed as `minGross - portion(minGross)` rather than
|
|
108
|
+
* `portion(netAmountOut)`. That matters: the fee is taken on-chain from the
|
|
109
|
+
* *realised* output, not the quoted one, and `x - floor(x * bps / 10_000)` is
|
|
110
|
+
* monotonically non-decreasing in `x`. So this is a genuine floor on what the
|
|
111
|
+
* user receives whenever the swap itself clears `minAmountOutGross`.
|
|
112
|
+
*/
|
|
113
|
+
export declare function buildQuoteBreakdown(input: QuoteBreakdownInput): QuoteBreakdown;
|
|
114
|
+
/**
|
|
115
|
+
* Exchange rate as a floating-point number of output units per input unit.
|
|
116
|
+
*
|
|
117
|
+
* Display only. Never feed this back into a call path - it loses precision by
|
|
118
|
+
* construction.
|
|
119
|
+
*/
|
|
120
|
+
export declare function exchangeRate(amountIn: bigint, decimalsIn: number, amountOut: bigint, decimalsOut: number): number | null;
|
|
121
|
+
/** Progress of a sale as a percentage in `[0, 100]`. */
|
|
122
|
+
export declare function progressPercent(sold: bigint, total: bigint): number;
|
|
123
|
+
/** Clamps `value` to `[min, max]`. */
|
|
124
|
+
export declare function clampBigInt(value: bigint, min: bigint, max: bigint): bigint;
|
|
125
|
+
/** Rounds a tick down to the nearest usable multiple of `tickSpacing`. */
|
|
126
|
+
export declare function floorTickToSpacing(tick: number, tickSpacing: number): number;
|
|
127
|
+
/** Rounds a tick up to the nearest usable multiple of `tickSpacing`. */
|
|
128
|
+
export declare function ceilTickToSpacing(tick: number, tickSpacing: number): number;
|
|
129
|
+
//# sourceMappingURL=math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../src/core/math.ts"],"names":[],"mappings":"AACA;;;;;;;;GAQG;AAEH,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,yBAAyB,CAAC;AAEjC,2CAA2C;AAC3C,eAAO,MAAM,GAAG,SAAU,CAAC;AAE3B,wEAAwE;AACxE,eAAO,MAAM,IAAI,WAAa,CAAC;AAE/B;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,OAAQ,CAAC;AAEtC,iDAAiD;AACjD,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC,2EAA2E;AAC3E,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAEzC,mDAAmD;AACnD,eAAO,MAAM,uBAAuB,OAAQ,CAAC;AAY7C,sCAAsC;AACtC,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAI7D;AAED,0CAA0C;AAC1C,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI3D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAI7E;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAK1E;AAED;;;;;;;;GAQG;AACH,wBAAgB,cA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Q,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,gGAAgG;IAChG,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,CAAC;CACnD;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,mBAAmB,GAAG,cAAc,CA6B9E;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,GAClB,MAAM,GAAG,IAAI,CAMf;AAED,wDAAwD;AACxD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAInE;AAED,sCAAsC;AACtC,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAK3E;AAED,0EAA0E;AAC1E,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAK5E;AAED,wEAAwE;AACxE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAK3E"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a pool key already says about a pool.
|
|
3
|
+
*
|
|
4
|
+
* `PoolInfo.tickSpacing` and `PoolInfo.binStep` are optional because a host
|
|
5
|
+
* that lists pools from an indexer may not fill them in - but both live in the
|
|
6
|
+
* key's `parameters` word, so nothing needs to guess. These read the key when
|
|
7
|
+
* the field is absent, and every range editor and quote goes through them.
|
|
8
|
+
*/
|
|
9
|
+
import { type PoolId } from "@latchprotocol/sdk";
|
|
10
|
+
import type { PoolInfo } from "../adapters/protocol.js";
|
|
11
|
+
/** The tick spacing of a concentrated-liquidity pool, from the info or its key. */
|
|
12
|
+
export declare function tickSpacingOf(pool: PoolInfo): number;
|
|
13
|
+
/** The bin step of a liquidity-book pool, from the info or its key. */
|
|
14
|
+
export declare function binStepOf(pool: PoolInfo): number;
|
|
15
|
+
/**
|
|
16
|
+
* `BinTokenLibrary.toTokenId`: the fungible token id `BinPositionManager`
|
|
17
|
+
* mints for one bin of one pool, `keccak256(abi.encode(poolId, binId))`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function binTokenId(poolId: PoolId, binId: number): bigint;
|
|
20
|
+
/**
|
|
21
|
+
* The reserves a holder's shares of one bin are worth right now, rounded
|
|
22
|
+
* DOWN exactly as `BinPool.burn` computes them (`amount * shares / totalShares`).
|
|
23
|
+
*/
|
|
24
|
+
export declare function binShareAmounts(args: {
|
|
25
|
+
readonly shares: bigint;
|
|
26
|
+
readonly totalShares: bigint;
|
|
27
|
+
readonly reserveX: bigint;
|
|
28
|
+
readonly reserveY: bigint;
|
|
29
|
+
}): {
|
|
30
|
+
amount0: bigint;
|
|
31
|
+
amount1: bigint;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/core/pool.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAOH,OAAO,EAAqD,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACpG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAExD,mFAAmF;AACnF,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAGpD;AAED,uEAAuE;AACvE,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAGhD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAShE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAMvC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token lists as the picker consumes them: pure functions from the SDK's
|
|
3
|
+
* `TokenList` documents to the widgets' `TokenInfo`, with the provenance kept
|
|
4
|
+
* on each entry. The React hook (`hooks/useTokenLists.ts`) fetches and calls
|
|
5
|
+
* these; nothing here touches the network or the DOM, so it is testable on its
|
|
6
|
+
* own and reusable by a headless integrator.
|
|
7
|
+
*/
|
|
8
|
+
import { type MergedTokenList, type TokenList } from "@latchprotocol/sdk";
|
|
9
|
+
import type { TokenInfo } from "../adapters/protocol.js";
|
|
10
|
+
/** One entry of `SwapWidget`'s `tokenLists`: a list already in hand, or a URL to fetch. */
|
|
11
|
+
export type TokenListInput = TokenList | {
|
|
12
|
+
readonly url: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function isTokenListUrl(input: TokenListInput): input is {
|
|
15
|
+
readonly url: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The picker entries a merge yields, for `chainId`. Tokens whose address is not
|
|
19
|
+
* a 20-byte hex address (the schema also admits a Solana form) are skipped:
|
|
20
|
+
* they cannot be a Latch pool currency.
|
|
21
|
+
*/
|
|
22
|
+
export declare function tokensFromMergedList(merged: MergedTokenList): readonly TokenInfo[];
|
|
23
|
+
/**
|
|
24
|
+
* The picker's final order: the adapter's own tokens first (the tokens of the
|
|
25
|
+
* pools this site routes through, read on chain), then every list's tokens in
|
|
26
|
+
* list order, deduped by lowercase address. A token the adapter already knows
|
|
27
|
+
* keeps the adapter's fields — its decimals were read off the contract — and
|
|
28
|
+
* gains the list's provenance, logo, stock badge and tags where the adapter had
|
|
29
|
+
* none.
|
|
30
|
+
*/
|
|
31
|
+
export declare function combineTokens(adapterTokens: readonly TokenInfo[], listTokens: readonly TokenInfo[]): readonly TokenInfo[];
|
|
32
|
+
/** `mergeTokenLists` then `tokensFromMergedList`, for callers with every list in hand. */
|
|
33
|
+
export declare function tokensFromLists(lists: readonly TokenList[], chainId: number): readonly TokenInfo[];
|
|
34
|
+
/**
|
|
35
|
+
* The URL an `<img>` can load for a token's logo: `https://` as given,
|
|
36
|
+
* `ipfs://` through the SDK's first allow-listed gateway, anything else
|
|
37
|
+
* `null` (the caller draws a monogram). `http://` is refused: a mixed-content
|
|
38
|
+
* image on an https site is blocked by the browser and reads as a broken logo.
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveLogoUrl(logoUrl: string | undefined, gateways?: readonly string[]): string | null;
|
|
41
|
+
/** Group entries by their list source, in first-seen order; adapter tokens (no source) come first under `null`. */
|
|
42
|
+
export declare function groupBySource(tokens: readonly TokenInfo[]): readonly {
|
|
43
|
+
readonly source: string | null;
|
|
44
|
+
readonly tokens: readonly TokenInfo[];
|
|
45
|
+
}[];
|
|
46
|
+
//# sourceMappingURL=tokenLists.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenLists.d.ts","sourceRoot":"","sources":["../../src/core/tokenLists.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AAEH,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,SAAS,EACf,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,2FAA2F;AAC3F,MAAM,MAAM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