@panoptic-eng/sdk 1.0.27 → 1.0.29
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/cow/index.d.ts +5 -5
- package/dist/cow/index.js +3 -3
- package/dist/cow/types.d.ts +2 -2
- package/dist/{cow-CbyBBJa8.js → cow-CSt61vNU.js} +2 -2
- package/dist/{cow-CbyBBJa8.js.map → cow-CSt61vNU.js.map} +1 -1
- package/dist/index-B3JZRUNo.d.ts +9084 -0
- package/dist/index-B3JZRUNo.d.ts.map +1 -0
- package/dist/{index-Bs35Gs9h.d.ts → index-CDCAju5o.d.ts} +2 -2
- package/dist/{index-Bs35Gs9h.d.ts.map → index-CDCAju5o.d.ts.map} +1 -1
- package/dist/{index-cqnrR3RH.d.ts → index-DQS8Luef.d.ts} +4 -4
- package/dist/{index-cqnrR3RH.d.ts.map → index-DQS8Luef.d.ts.map} +1 -1
- package/dist/index.d.ts +14 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/{irm-DsuOZAXj.d.ts → irm-BNtE1Dmg.d.ts} +2 -2
- package/dist/{irm-DsuOZAXj.d.ts.map → irm-BNtE1Dmg.d.ts.map} +1 -1
- package/dist/{irm-CUQhUGHI.js → irm-IcePQm1r.js} +3 -3
- package/dist/{irm-CUQhUGHI.js.map → irm-IcePQm1r.js.map} +1 -1
- package/dist/{types-CnfCBl2B.d.ts → oracle-BnpPVG8V.d.ts} +4 -244
- package/dist/oracle-BnpPVG8V.d.ts.map +1 -0
- package/dist/panoptic/v2/greeks/index.d.ts +2 -2
- package/dist/panoptic/v2/index.d.ts +8 -9956
- package/dist/panoptic/v2/index.js +5 -11281
- package/dist/panoptic/v2/react-public.d.ts +886 -0
- package/dist/panoptic/v2/react-public.d.ts.map +1 -0
- package/dist/panoptic/v2/react-public.js +3854 -0
- package/dist/panoptic/v2/react-public.js.map +1 -0
- package/dist/{position-C8du80mE.d.ts → position-Bmd_3nzI.d.ts} +1 -1
- package/dist/{position-C8du80mE.d.ts.map → position-Bmd_3nzI.d.ts.map} +1 -1
- package/dist/{position-B7cJsaOz.js → position-UL1gOvqZ.js} +2 -2
- package/dist/{position-B7cJsaOz.js.map → position-UL1gOvqZ.js.map} +1 -1
- package/dist/{router-CFs84CaF.js → router-Del9H6e0.js} +2 -2
- package/dist/{router-CFs84CaF.js.map → router-Del9H6e0.js.map} +1 -1
- package/dist/{simulation-DMPUACvp.d.ts → simulation-CUqERC5Y.d.ts} +2 -2
- package/dist/{simulation-DMPUACvp.d.ts.map → simulation-CUqERC5Y.d.ts.map} +1 -1
- package/dist/test/index.d.ts +2 -2
- package/dist/test/index.d.ts.map +1 -1
- package/dist/{tx-D4uNr1_K.d.ts → tx-BXXqhBHn.d.ts} +1 -1
- package/dist/{tx-D4uNr1_K.d.ts.map → tx-BXXqhBHn.d.ts.map} +1 -1
- package/dist/{types-CRev1pDq.d.ts → types-DgWfno7q.d.ts} +2 -2
- package/dist/{types-CRev1pDq.d.ts.map → types-DgWfno7q.d.ts.map} +1 -1
- package/dist/types-VeWdNN0j.d.ts +247 -0
- package/dist/types-VeWdNN0j.d.ts.map +1 -0
- package/dist/uniswap/index.d.ts +75 -5
- package/dist/uniswap/index.d.ts.map +1 -1
- package/dist/uniswap/index.js +64 -5
- package/dist/uniswap/index.js.map +1 -1
- package/dist/v2-BSV35bpu.js +7438 -0
- package/dist/v2-BSV35bpu.js.map +1 -0
- package/dist/{writes-GvVYh9PQ.js → writes-RyS0kHpB.js} +3 -3
- package/dist/{writes-GvVYh9PQ.js.map → writes-RyS0kHpB.js.map} +1 -1
- package/package.json +5 -1
- package/dist/panoptic/v2/index.d.ts.map +0 -1
- package/dist/panoptic/v2/index.js.map +0 -1
- package/dist/types-CnfCBl2B.d.ts.map +0 -1
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { PoolKey } from "./oracle-BnpPVG8V.js";
|
|
2
|
+
import { TxOverrides } from "./tx-BXXqhBHn.js";
|
|
3
|
+
import { Address, PublicClient, WalletClient } from "viem";
|
|
4
|
+
|
|
5
|
+
//#region src/uniswap/v4/addresses.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Uniswap v4 contract addresses required for a Universal Router spot swap.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Uniswap v4 contract addresses required for a Universal Router spot swap.
|
|
12
|
+
*/
|
|
13
|
+
interface UniswapV4Addresses {
|
|
14
|
+
/** Universal Router (v4-capable build) — entrypoint for `execute(...)`. */
|
|
15
|
+
universalRouter: Address;
|
|
16
|
+
/** V4Quoter — `quoteExactInputSingle` (revert/staticcall-based). */
|
|
17
|
+
v4Quoter: Address;
|
|
18
|
+
/** Uniswap v4 PoolManager (singleton). */
|
|
19
|
+
poolManager: Address;
|
|
20
|
+
/** Canonical Permit2 (same address on every chain). */
|
|
21
|
+
permit2: Address;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Canonical Permit2, identical across all chains.
|
|
25
|
+
*/
|
|
26
|
+
declare const PERMIT2_ADDRESS: Address;
|
|
27
|
+
/**
|
|
28
|
+
* Verified Uniswap v4 deployment addresses keyed by chainId.
|
|
29
|
+
*
|
|
30
|
+
* Sourced from the official Uniswap v4 deployments. Add a chain here only after
|
|
31
|
+
* verifying each address against the canonical Uniswap deployment listing —
|
|
32
|
+
* Universal Router in particular is NOT the same address across chains.
|
|
33
|
+
*/
|
|
34
|
+
declare const UNISWAP_V4_ADDRESSES: Record<number, UniswapV4Addresses>;
|
|
35
|
+
/**
|
|
36
|
+
* Resolve the Uniswap v4 addresses for a chain, applying optional overrides.
|
|
37
|
+
*
|
|
38
|
+
* @param chainId - Target chain ID.
|
|
39
|
+
* @param overrides - Partial override of any address (e.g. for fork tests).
|
|
40
|
+
* @returns Fully-resolved {@link UniswapV4Addresses}.
|
|
41
|
+
* @throws {UnsupportedChainError} when the chain is not listed and the
|
|
42
|
+
* overrides do not supply every required address.
|
|
43
|
+
*/
|
|
44
|
+
declare function getUniswapV4Addresses(chainId: bigint, overrides?: Partial<UniswapV4Addresses>): UniswapV4Addresses;
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/uniswap/v4/router/types.d.ts
|
|
48
|
+
/**
|
|
49
|
+
* Parameters for {@link swapExactInViaRouter}.
|
|
50
|
+
*/
|
|
51
|
+
interface SwapExactInViaRouterParams {
|
|
52
|
+
/** Public client for reads + receipts. */
|
|
53
|
+
client: PublicClient;
|
|
54
|
+
/** Wallet client for signing. */
|
|
55
|
+
walletClient: WalletClient;
|
|
56
|
+
/** Account address. */
|
|
57
|
+
account: Address;
|
|
58
|
+
/** PanopticPool address — used to resolve the underlying v4 PoolKey. */
|
|
59
|
+
poolAddress: Address;
|
|
60
|
+
/** Chain ID (selects per-chain Uniswap v4 addresses). */
|
|
61
|
+
chainId: bigint;
|
|
62
|
+
/** Token to sell. `address(0)` (zero address) for native ETH. */
|
|
63
|
+
tokenIn: Address;
|
|
64
|
+
/** Exact amount of `tokenIn` to spend (must fit uint128). */
|
|
65
|
+
amountIn: bigint;
|
|
66
|
+
/** Slippage tolerance in bps (e.g. 500n = 5%). */
|
|
67
|
+
slippageBps: bigint;
|
|
68
|
+
/** Absolute deadline (unix seconds). If omitted, derived from block timestamp. */
|
|
69
|
+
deadline?: bigint;
|
|
70
|
+
/** Recipient of the output. Defaults to `account`. */
|
|
71
|
+
recipient?: Address;
|
|
72
|
+
/** Gas and transaction overrides. */
|
|
73
|
+
txOverrides?: TxOverrides;
|
|
74
|
+
/** Override per-chain Uniswap v4 addresses (e.g. fork tests). */
|
|
75
|
+
addresses?: Partial<UniswapV4Addresses>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Parameters for {@link quoteSwapExactInViaRouter}.
|
|
79
|
+
*/
|
|
80
|
+
interface QuoteSwapExactInViaRouterParams {
|
|
81
|
+
/** Public client. */
|
|
82
|
+
client: PublicClient;
|
|
83
|
+
/** PanopticPool address — used to resolve the underlying v4 PoolKey. */
|
|
84
|
+
poolAddress: Address;
|
|
85
|
+
/** Chain ID. */
|
|
86
|
+
chainId: bigint;
|
|
87
|
+
/** Token to sell. `address(0)` for native ETH. */
|
|
88
|
+
tokenIn: Address;
|
|
89
|
+
/** Exact amount of `tokenIn` to spend (must fit uint128). */
|
|
90
|
+
amountIn: bigint;
|
|
91
|
+
/** Slippage tolerance in bps (used to compute `amountOutMinimum`). */
|
|
92
|
+
slippageBps: bigint;
|
|
93
|
+
/** Optional block number for the quote. */
|
|
94
|
+
blockNumber?: bigint;
|
|
95
|
+
/** Override per-chain Uniswap v4 addresses (e.g. fork tests). */
|
|
96
|
+
addresses?: Partial<UniswapV4Addresses>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Quote result data (carried inside a `SimulationResult`).
|
|
100
|
+
*/
|
|
101
|
+
interface SwapExactInQuote {
|
|
102
|
+
/** Quoted output amount of `tokenOut`. */
|
|
103
|
+
amountOut: bigint;
|
|
104
|
+
/** Minimum acceptable output after applying slippage. */
|
|
105
|
+
amountOutMinimum: bigint;
|
|
106
|
+
/** Whether the swap goes currency0 → currency1. */
|
|
107
|
+
zeroForOne: boolean;
|
|
108
|
+
/** Output token address (`address(0)` for native ETH). */
|
|
109
|
+
tokenOut: Address;
|
|
110
|
+
/** Resolved v4 PoolKey (reused by the swap calldata builder). */
|
|
111
|
+
poolKey: PoolKey;
|
|
112
|
+
/** Quoter's gas estimate. */
|
|
113
|
+
gasEstimate: bigint;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Parameters for {@link swapExactOutViaRouter}.
|
|
117
|
+
*/
|
|
118
|
+
interface SwapExactOutViaRouterParams {
|
|
119
|
+
/** Public client for reads + receipts. */
|
|
120
|
+
client: PublicClient;
|
|
121
|
+
/** Wallet client for signing. */
|
|
122
|
+
walletClient: WalletClient;
|
|
123
|
+
/** Account address. */
|
|
124
|
+
account: Address;
|
|
125
|
+
/** PanopticPool address — used to resolve the underlying v4 PoolKey. */
|
|
126
|
+
poolAddress: Address;
|
|
127
|
+
/** Chain ID (selects per-chain Uniswap v4 addresses). */
|
|
128
|
+
chainId: bigint;
|
|
129
|
+
/** Token to sell (the pay token). `address(0)` (zero address) for native ETH. */
|
|
130
|
+
tokenIn: Address;
|
|
131
|
+
/** Exact amount of the output token to receive (must fit uint128). */
|
|
132
|
+
amountOut: bigint;
|
|
133
|
+
/** Slippage tolerance in bps (e.g. 500n = 5%); caps the input. */
|
|
134
|
+
slippageBps: bigint;
|
|
135
|
+
/** Absolute deadline (unix seconds). If omitted, derived from block timestamp. */
|
|
136
|
+
deadline?: bigint;
|
|
137
|
+
/** Recipient of the output. Defaults to `account`. */
|
|
138
|
+
recipient?: Address;
|
|
139
|
+
/** Gas and transaction overrides. */
|
|
140
|
+
txOverrides?: TxOverrides;
|
|
141
|
+
/** Override per-chain Uniswap v4 addresses (e.g. fork tests). */
|
|
142
|
+
addresses?: Partial<UniswapV4Addresses>;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Parameters for {@link quoteSwapExactOutViaRouter}.
|
|
146
|
+
*/
|
|
147
|
+
interface QuoteSwapExactOutViaRouterParams {
|
|
148
|
+
/** Public client. */
|
|
149
|
+
client: PublicClient;
|
|
150
|
+
/** PanopticPool address — used to resolve the underlying v4 PoolKey. */
|
|
151
|
+
poolAddress: Address;
|
|
152
|
+
/** Chain ID. */
|
|
153
|
+
chainId: bigint;
|
|
154
|
+
/** Token to sell (the pay token). `address(0)` for native ETH. */
|
|
155
|
+
tokenIn: Address;
|
|
156
|
+
/** Exact amount of the output token to receive (must fit uint128). */
|
|
157
|
+
amountOut: bigint;
|
|
158
|
+
/** Slippage tolerance in bps (used to compute `amountInMaximum`). */
|
|
159
|
+
slippageBps: bigint;
|
|
160
|
+
/** Optional block number for the quote. */
|
|
161
|
+
blockNumber?: bigint;
|
|
162
|
+
/** Override per-chain Uniswap v4 addresses (e.g. fork tests). */
|
|
163
|
+
addresses?: Partial<UniswapV4Addresses>;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Quote result data for an exact-out swap (carried inside a `SimulationResult`).
|
|
167
|
+
*/
|
|
168
|
+
interface SwapExactOutQuote {
|
|
169
|
+
/** Quoted input amount of `tokenIn` required for the exact output. */
|
|
170
|
+
amountIn: bigint;
|
|
171
|
+
/** Maximum acceptable input after applying slippage. */
|
|
172
|
+
amountInMaximum: bigint;
|
|
173
|
+
/** Whether the swap goes currency0 → currency1. */
|
|
174
|
+
zeroForOne: boolean;
|
|
175
|
+
/** Output token address (`address(0)` for native ETH). */
|
|
176
|
+
tokenOut: Address;
|
|
177
|
+
/** Resolved v4 PoolKey (reused by the swap calldata builder). */
|
|
178
|
+
poolKey: PoolKey;
|
|
179
|
+
/** Quoter's gas estimate. */
|
|
180
|
+
gasEstimate: bigint;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Parameters for {@link checkRouterApproval}.
|
|
184
|
+
*/
|
|
185
|
+
interface CheckRouterApprovalParams {
|
|
186
|
+
/** Public client. */
|
|
187
|
+
client: PublicClient;
|
|
188
|
+
/** Chain ID. */
|
|
189
|
+
chainId: bigint;
|
|
190
|
+
/** ERC20 token being spent (must not be native ETH). */
|
|
191
|
+
tokenIn: Address;
|
|
192
|
+
/** Token owner. */
|
|
193
|
+
owner: Address;
|
|
194
|
+
/** Amount that must be spendable. */
|
|
195
|
+
amount: bigint;
|
|
196
|
+
/** Override per-chain Uniswap v4 addresses (e.g. fork tests). */
|
|
197
|
+
addresses?: Partial<UniswapV4Addresses>;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Result of {@link checkRouterApproval}.
|
|
201
|
+
*/
|
|
202
|
+
interface RouterApprovalStatus {
|
|
203
|
+
/** ERC20 → Permit2 allowance is insufficient. */
|
|
204
|
+
needsErc20Approval: boolean;
|
|
205
|
+
/** Permit2 → Universal Router allowance is insufficient or expired. */
|
|
206
|
+
needsPermit2Approval: boolean;
|
|
207
|
+
/** Current ERC20 → Permit2 allowance. */
|
|
208
|
+
erc20Allowance: bigint;
|
|
209
|
+
/** Current Permit2 → router allowance amount. */
|
|
210
|
+
permit2Amount: bigint;
|
|
211
|
+
/** Current Permit2 → router allowance expiration (unix seconds). */
|
|
212
|
+
permit2Expiration: bigint;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Parameters for {@link approveErc20ForPermit2}.
|
|
216
|
+
*/
|
|
217
|
+
interface ApproveErc20ForPermit2Params {
|
|
218
|
+
client: PublicClient;
|
|
219
|
+
walletClient: WalletClient;
|
|
220
|
+
account: Address;
|
|
221
|
+
chainId: bigint;
|
|
222
|
+
/** ERC20 token to approve to Permit2. */
|
|
223
|
+
tokenIn: Address;
|
|
224
|
+
/** Amount to approve. Defaults to uint256 max. */
|
|
225
|
+
amount?: bigint;
|
|
226
|
+
txOverrides?: TxOverrides;
|
|
227
|
+
addresses?: Partial<UniswapV4Addresses>;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Parameters for {@link approveRouterViaPermit2}.
|
|
231
|
+
*/
|
|
232
|
+
interface ApproveRouterViaPermit2Params {
|
|
233
|
+
client: PublicClient;
|
|
234
|
+
walletClient: WalletClient;
|
|
235
|
+
account: Address;
|
|
236
|
+
chainId: bigint;
|
|
237
|
+
/** ERC20 token the router is allowed to spend via Permit2. */
|
|
238
|
+
tokenIn: Address;
|
|
239
|
+
/** Amount to approve (must fit uint160). Defaults to uint160 max. */
|
|
240
|
+
amount?: bigint;
|
|
241
|
+
/** Allowance expiration (unix seconds, uint48). If omitted, block timestamp + 30 days. */
|
|
242
|
+
expiration?: bigint;
|
|
243
|
+
txOverrides?: TxOverrides;
|
|
244
|
+
addresses?: Partial<UniswapV4Addresses>;
|
|
245
|
+
} //#endregion
|
|
246
|
+
export { ApproveErc20ForPermit2Params, ApproveRouterViaPermit2Params, CheckRouterApprovalParams, PERMIT2_ADDRESS as PERMIT2_ADDRESS$1, QuoteSwapExactInViaRouterParams, QuoteSwapExactOutViaRouterParams, RouterApprovalStatus, SwapExactInQuote, SwapExactInViaRouterParams, SwapExactOutQuote, SwapExactOutViaRouterParams, UNISWAP_V4_ADDRESSES as UNISWAP_V4_ADDRESSES$1, UniswapV4Addresses, getUniswapV4Addresses as getUniswapV4Addresses$1 };
|
|
247
|
+
//# sourceMappingURL=types-VeWdNN0j.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-VeWdNN0j.d.ts","names":["Address","UniswapV4Addresses","PERMIT2_ADDRESS","UNISWAP_V4_ADDRESSES","Record","getUniswapV4Addresses","Partial","Address","PublicClient","WalletClient","PoolKey","TxOverrides","UniswapV4Addresses","SwapExactInViaRouterParams","Partial","QuoteSwapExactInViaRouterParams","SwapExactInQuote","SwapExactOutViaRouterParams","QuoteSwapExactOutViaRouterParams","SwapExactOutQuote","CheckRouterApprovalParams","RouterApprovalStatus","ApproveErc20ForPermit2Params","ApproveRouterViaPermit2Params"],"sources":["../src/uniswap/v4/addresses.d.ts","../src/uniswap/v4/router/types.d.ts"],"sourcesContent":null,"mappings":";;;;;;;;;;;;AAsBoB,UARHY,kBAAAA,CAQG;;mBANCL;;EAWAL,QAAAA,EATPK,OASOL;;eAPJK;;WAEJA;;;;AAab;AAA6E,cARxDL,eAQwD,EARvCK,OAQuC;;;AAA5B;;;;;cAA5BJ,sBAAsBC,eAAeQ;;;;;AAU1D;;;;;AAA2H,iBAAnGP,qBAAAA,CAAmG,OAAA,EAAA,MAAA,EAAA,SAAA,CAAA,EAAhDS,OAAgD,CAAxCF,kBAAwC,CAAA,CAAA,EAAlBA,kBAAkB;;;;;AA/B3H;;AAEqBL,UCNJM,0BAAAA,CDMIN;EAAO;EAEP,MAEJA,ECRLC,YDQKD;EAAO;EAEJ,YAAA,ECRFE,YDQE;;WCNPF;;EDWQL,WAAAA,ECTJK,ODS4B;;;;WCLhCA;;;;EDaQJ,WAAAA,EAAAA,MAAAA;EAAwD;EAAA,QAA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AAUW,UA7BNW,iBAAAA,CA6BM;;;;EAKNE,eAAAA,EAAAA,MAAoB;;;;EAepBC,QAAAA,EAzCHf,OAyCGe;EAA4B;EAAA,OACjCd,EAxCCE,OAwCDF;EAAY;EACM,WACjBD,EAAAA,MAAAA;;;;;AAOU,UA1CNa,yBAAAA,CA0CM;;UAxCXZ;;EA6CKe,OAAAA,EAAAA,MAAAA;EAA6B;EAAA,OAClCf,EA1CCD,OA0CDC;EAAY;EACM,KACjBD,EA1CFA,OA0CEA;EAAO;EAGA,MAKFI,EAAAA,MAAAA;EAAW;EACa,SAA1BG,CAAAA,EA/CAA,OA+CAA,CA/CQF,kBA+CRE,CAAAA;AAAO;;;;UA1CNO,oBAAAA;;;;;;;;;;;;;;;UAeAC,4BAAAA;UACLd;gBACMC;WACLF;;;WAGAA;;;gBAGKI;cACFG,QAAQF;;;;;UAKPW,6BAAAA;UACLf;gBACMC;WACLF;;;WAGAA;;;;;gBAKKI;cACFG,QAAQF"}
|
package/dist/uniswap/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import "../position-
|
|
2
|
-
import {
|
|
3
|
-
import { TxReceipt, TxResult } from "../tx-
|
|
4
|
-
import { PanopticError$1 as PanopticError, SimulationResult } from "../simulation-
|
|
1
|
+
import "../position-Bmd_3nzI.js";
|
|
2
|
+
import { PoolKey } from "../oracle-BnpPVG8V.js";
|
|
3
|
+
import { TxReceipt, TxResult } from "../tx-BXXqhBHn.js";
|
|
4
|
+
import { PanopticError$1 as PanopticError, SimulationResult } from "../simulation-CUqERC5Y.js";
|
|
5
|
+
import { ApproveErc20ForPermit2Params, ApproveRouterViaPermit2Params, CheckRouterApprovalParams, PERMIT2_ADDRESS$1 as PERMIT2_ADDRESS, QuoteSwapExactInViaRouterParams, QuoteSwapExactOutViaRouterParams, RouterApprovalStatus, SwapExactInQuote, SwapExactInViaRouterParams, SwapExactOutQuote, SwapExactOutViaRouterParams, UNISWAP_V4_ADDRESSES$1 as UNISWAP_V4_ADDRESSES, UniswapV4Addresses, getUniswapV4Addresses$1 as getUniswapV4Addresses } from "../types-VeWdNN0j.js";
|
|
5
6
|
import { Address, Hex, PublicClient } from "viem";
|
|
6
7
|
|
|
7
8
|
//#region src/uniswap/v4/router/encodeSwap.d.ts
|
|
@@ -311,6 +312,75 @@ declare function swapExactOutViaRouter(params: SwapExactOutViaRouterParams): Pro
|
|
|
311
312
|
*/
|
|
312
313
|
declare function swapExactOutViaRouterAndWait(params: SwapExactOutViaRouterParams): Promise<TxReceipt>;
|
|
313
314
|
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/uniswap/lpGreeks.d.ts
|
|
317
|
+
/**
|
|
318
|
+
* Greeks for plain (non-Panoptic) Uniswap v3/v4 concentrated-liquidity LP
|
|
319
|
+
* positions. Pure math over on-chain position fields (liquidity + tick range)
|
|
320
|
+
* and the pool's current price — no RPC, no protocol dependency.
|
|
321
|
+
*
|
|
322
|
+
* Units follow the Panoptic v2 greeks convention (see
|
|
323
|
+
* `packages/sdk/src/panoptic/v2/greeks/index.ts`) so a caller can present LP
|
|
324
|
+
* and Panoptic greeks side by side:
|
|
325
|
+
* - `value` → numeraire-token smallest units
|
|
326
|
+
* - `delta` → asset-token smallest units (the asset held by the LP)
|
|
327
|
+
* - `gamma` → numeraire-token smallest units (dollar-gamma `P²·d²V/dP²`;
|
|
328
|
+
* always ≤ 0 because an LP is short gamma)
|
|
329
|
+
*
|
|
330
|
+
* `assetIndex` selects which token is the "asset" (the volatile leg being
|
|
331
|
+
* hedged): `0` → token0 is the asset / token1 the numeraire; `1` → the reverse.
|
|
332
|
+
*
|
|
333
|
+
* @module uniswap/lpGreeks
|
|
334
|
+
*/
|
|
335
|
+
/** Token amounts currently backing a concentrated-liquidity position. */
|
|
336
|
+
interface LpAmounts {
|
|
337
|
+
/** token0 amount in its smallest units. */
|
|
338
|
+
amount0: bigint;
|
|
339
|
+
/** token1 amount in its smallest units. */
|
|
340
|
+
amount1: bigint;
|
|
341
|
+
}
|
|
342
|
+
/** Greeks of a Uniswap LP position in one asset frame (see module docs for units). */
|
|
343
|
+
interface LpGreeks {
|
|
344
|
+
/** Position value in numeraire-token smallest units. */
|
|
345
|
+
value: bigint;
|
|
346
|
+
/** Delta in asset-token smallest units (the asset amount the LP is long). */
|
|
347
|
+
delta: bigint;
|
|
348
|
+
/** Dollar-gamma in numeraire-token smallest units; ≤ 0 (LP is short gamma). */
|
|
349
|
+
gamma: bigint;
|
|
350
|
+
}
|
|
351
|
+
/** Inputs describing a single LP position + the pool's current price. */
|
|
352
|
+
interface LpGreeksInput {
|
|
353
|
+
/** Position liquidity `L`. */
|
|
354
|
+
liquidity: bigint;
|
|
355
|
+
/** Lower tick of the range. */
|
|
356
|
+
tickLower: bigint;
|
|
357
|
+
/** Upper tick of the range. */
|
|
358
|
+
tickUpper: bigint;
|
|
359
|
+
/** Pool's current tick. */
|
|
360
|
+
currentTick: bigint;
|
|
361
|
+
/** Which token is the asset: `0` (token0) or `1` (token1). */
|
|
362
|
+
assetIndex: 0 | 1;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Compute the token0/token1 amounts backing `liquidity` over `[sqrtA, sqrtB]`
|
|
366
|
+
* at the current price `sqrtP`, mirroring Uniswap's `LiquidityAmounts`
|
|
367
|
+
* (`getAmountsForLiquidity`). All sqrt prices are X96. The current price is
|
|
368
|
+
* clamped into the range, so out-of-range positions collapse to a single token.
|
|
369
|
+
*/
|
|
370
|
+
declare function getAmountsForLiquidity(sqrtPriceX96: bigint, sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, liquidity: bigint): LpAmounts;
|
|
371
|
+
/**
|
|
372
|
+
* Greeks (value, delta, gamma) for a Uniswap LP position in the chosen asset
|
|
373
|
+
* frame. See the module docs for the unit conventions.
|
|
374
|
+
*
|
|
375
|
+
* Closed forms (in-range, numeraire = token1 / asset = token0):
|
|
376
|
+
* value = amount1 + amount0·P (P = sqrtP² / 2^192)
|
|
377
|
+
* delta = amount0 (= dV/dP)
|
|
378
|
+
* gamma = P²·d²V/dP² = -L·sqrt(P)/2 (short gamma)
|
|
379
|
+
* The `assetIndex = 1` frame is the symmetric inverse (numeraire = token0).
|
|
380
|
+
* Gamma is zero when the price is outside the range (no curvature there).
|
|
381
|
+
*/
|
|
382
|
+
declare function getLpGreeks(input: LpGreeksInput): LpGreeks;
|
|
383
|
+
|
|
314
384
|
//#endregion
|
|
315
385
|
//#region src/uniswap/v3/addresses.d.ts
|
|
316
386
|
interface UniswapV3Addresses {
|
|
@@ -405,5 +475,5 @@ interface V3ExactInQuote {
|
|
|
405
475
|
declare function quoteV3ExactIn(params: QuoteV3ExactInParams): Promise<V3ExactInQuote | null>;
|
|
406
476
|
|
|
407
477
|
//#endregion
|
|
408
|
-
export { AmountExceedsUint128Error, ApproveErc20ForPermit2Params, ApproveRouterViaPermit2Params, BuildV3SwapCalldataArgs, BuildV4ExactOutSwapCalldataArgs, BuildV4SwapCalldataArgs, CheckRouterApprovalParams, InvalidSwapTokenError, MSG_SENDER, MissingSweepRecipientError, PERMIT2_ADDRESS, QuoteSwapExactInViaRouterParams, QuoteSwapExactOutViaRouterParams, QuoteV3ExactInParams, QuoteV4ExactInByPoolKeyParams, QuoterUnavailableError, ResolveSwapRouteParams, ResolvedSwapRoute, RouterApprovalStatus, SETTLE_ALL, SWAP_EXACT_IN_SINGLE, SWAP_EXACT_OUT_SINGLE, SWEEP, SwapExactInQuote, SwapExactInViaRouterParams, SwapExactOutQuote, SwapExactOutViaRouterParams, TAKE_ALL, UNISWAP_V3_ADDRESSES, UNISWAP_V4_ADDRESSES, UniswapV3Addresses, UniswapV4Addresses, UnsupportedChainError, V3ExactInQuote, V3_SWAP_EXACT_IN, V4ExactInQuote, V4_SWAP, approveErc20ForPermit2, approveErc20ForPermit2AndWait, approveRouterViaPermit2, approveRouterViaPermit2AndWait, buildV3SwapExecuteArgs, buildV3SwapExecuteCalldata, buildV4ExactOutSwapExecuteArgs, buildV4ExactOutSwapExecuteCalldata, buildV4SwapExecuteArgs, buildV4SwapExecuteCalldata, checkRouterApproval, encodeV3Path, getUniswapV3Addresses, getUniswapV4Addresses, quoteSwapExactInViaRouter, quoteSwapExactOutViaRouter, quoteV3ExactIn, quoteV4ExactInByPoolKey, resolveSwapRoute, swapExactInViaRouter, swapExactInViaRouterAndWait, swapExactOutViaRouter, swapExactOutViaRouterAndWait };
|
|
478
|
+
export { AmountExceedsUint128Error, ApproveErc20ForPermit2Params, ApproveRouterViaPermit2Params, BuildV3SwapCalldataArgs, BuildV4ExactOutSwapCalldataArgs, BuildV4SwapCalldataArgs, CheckRouterApprovalParams, InvalidSwapTokenError, LpAmounts, LpGreeks, LpGreeksInput, MSG_SENDER, MissingSweepRecipientError, PERMIT2_ADDRESS, QuoteSwapExactInViaRouterParams, QuoteSwapExactOutViaRouterParams, QuoteV3ExactInParams, QuoteV4ExactInByPoolKeyParams, QuoterUnavailableError, ResolveSwapRouteParams, ResolvedSwapRoute, RouterApprovalStatus, SETTLE_ALL, SWAP_EXACT_IN_SINGLE, SWAP_EXACT_OUT_SINGLE, SWEEP, SwapExactInQuote, SwapExactInViaRouterParams, SwapExactOutQuote, SwapExactOutViaRouterParams, TAKE_ALL, UNISWAP_V3_ADDRESSES, UNISWAP_V4_ADDRESSES, UniswapV3Addresses, UniswapV4Addresses, UnsupportedChainError, V3ExactInQuote, V3_SWAP_EXACT_IN, V4ExactInQuote, V4_SWAP, approveErc20ForPermit2, approveErc20ForPermit2AndWait, approveRouterViaPermit2, approveRouterViaPermit2AndWait, buildV3SwapExecuteArgs, buildV3SwapExecuteCalldata, buildV4ExactOutSwapExecuteArgs, buildV4ExactOutSwapExecuteCalldata, buildV4SwapExecuteArgs, buildV4SwapExecuteCalldata, checkRouterApproval, encodeV3Path, getAmountsForLiquidity, getLpGreeks, getUniswapV3Addresses, getUniswapV4Addresses, quoteSwapExactInViaRouter, quoteSwapExactOutViaRouter, quoteV3ExactIn, quoteV4ExactInByPoolKey, resolveSwapRoute, swapExactInViaRouter, swapExactInViaRouterAndWait, swapExactOutViaRouter, swapExactOutViaRouterAndWait };
|
|
409
479
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["Address","Hex","PoolKey","V4_SWAP","SWAP_EXACT_IN_SINGLE","SETTLE_ALL","TAKE_ALL","TAKE","SWAP_EXACT_OUT_SINGLE","SWEEP","BuildV4SwapCalldataArgs","buildV4SwapExecuteArgs","buildV4SwapExecuteCalldata","BuildV4ExactOutSwapCalldataArgs","buildV4ExactOutSwapExecuteArgs","buildV4ExactOutSwapExecuteCalldata","Address","PanopticError","UnsupportedChainError","Error","InvalidSwapTokenError","AmountExceedsUint128Error","MissingSweepRecipientError","QuoterUnavailableError","TxReceipt","TxResult","ApproveErc20ForPermit2Params","ApproveRouterViaPermit2Params","CheckRouterApprovalParams","RouterApprovalStatus","checkRouterApproval","Promise","approveErc20ForPermit2","approveErc20ForPermit2AndWait","approveRouterViaPermit2","approveRouterViaPermit2AndWait","SimulationResult","QuoteSwapExactInViaRouterParams","QuoteSwapExactOutViaRouterParams","SwapExactInQuote","SwapExactOutQuote","quoteSwapExactInViaRouter","Promise","quoteSwapExactOutViaRouter","PublicClient","PoolKey","UniswapV4Addresses","QuoteV4ExactInByPoolKeyParams","Partial","V4ExactInQuote","quoteV4ExactInByPoolKey","Promise","Address","PublicClient","PoolKey","ResolvedSwapRoute","ResolveSwapRouteParams","resolveSwapRoute","Promise","TxReceipt","TxResult","SwapExactInViaRouterParams","SwapExactOutViaRouterParams","swapExactInViaRouter","Promise","swapExactInViaRouterAndWait","swapExactOutViaRouter","swapExactOutViaRouterAndWait","Address","UniswapV3Addresses","UNISWAP_V3_ADDRESSES","Record","getUniswapV3Addresses","Partial","Address","Hex","V3_SWAP_EXACT_IN","MSG_SENDER","BuildV3SwapCalldataArgs","encodeV3Path","buildV3SwapExecuteArgs","buildV3SwapExecuteCalldata","Address","PublicClient","UniswapV3Addresses","QuoteV3ExactInParams","Partial","V3ExactInQuote","quoteV3ExactIn","Promise"],"sources":["../../src/uniswap/v4/router/encodeSwap.d.ts","../../src/uniswap/v4/router/errors.d.ts","../../src/uniswap/v4/router/permit2.d.ts","../../src/uniswap/v4/router/quote.d.ts","../../src/uniswap/v4/router/quoteByPoolKey.d.ts","../../src/uniswap/v4/router/resolvePoolKey.d.ts","../../src/uniswap/v4/router/swap.d.ts","../../src/uniswap/v3/addresses.d.ts","../../src/uniswap/v3/router/encodeSwap.d.ts","../../src/uniswap/v3/router/quote.d.ts"],"sourcesContent":null,"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["Address","Hex","PoolKey","V4_SWAP","SWAP_EXACT_IN_SINGLE","SETTLE_ALL","TAKE_ALL","TAKE","SWAP_EXACT_OUT_SINGLE","SWEEP","BuildV4SwapCalldataArgs","buildV4SwapExecuteArgs","buildV4SwapExecuteCalldata","BuildV4ExactOutSwapCalldataArgs","buildV4ExactOutSwapExecuteArgs","buildV4ExactOutSwapExecuteCalldata","Address","PanopticError","UnsupportedChainError","Error","InvalidSwapTokenError","AmountExceedsUint128Error","MissingSweepRecipientError","QuoterUnavailableError","TxReceipt","TxResult","ApproveErc20ForPermit2Params","ApproveRouterViaPermit2Params","CheckRouterApprovalParams","RouterApprovalStatus","checkRouterApproval","Promise","approveErc20ForPermit2","approveErc20ForPermit2AndWait","approveRouterViaPermit2","approveRouterViaPermit2AndWait","SimulationResult","QuoteSwapExactInViaRouterParams","QuoteSwapExactOutViaRouterParams","SwapExactInQuote","SwapExactOutQuote","quoteSwapExactInViaRouter","Promise","quoteSwapExactOutViaRouter","PublicClient","PoolKey","UniswapV4Addresses","QuoteV4ExactInByPoolKeyParams","Partial","V4ExactInQuote","quoteV4ExactInByPoolKey","Promise","Address","PublicClient","PoolKey","ResolvedSwapRoute","ResolveSwapRouteParams","resolveSwapRoute","Promise","TxReceipt","TxResult","SwapExactInViaRouterParams","SwapExactOutViaRouterParams","swapExactInViaRouter","Promise","swapExactInViaRouterAndWait","swapExactOutViaRouter","swapExactOutViaRouterAndWait","LpAmounts","LpGreeks","LpGreeksInput","getAmountsForLiquidity","getLpGreeks","Address","UniswapV3Addresses","UNISWAP_V3_ADDRESSES","Record","getUniswapV3Addresses","Partial","Address","Hex","V3_SWAP_EXACT_IN","MSG_SENDER","BuildV3SwapCalldataArgs","encodeV3Path","buildV3SwapExecuteArgs","buildV3SwapExecuteCalldata","Address","PublicClient","UniswapV3Addresses","QuoteV3ExactInParams","Partial","V3ExactInQuote","quoteV3ExactIn","Promise"],"sources":["../../src/uniswap/v4/router/encodeSwap.d.ts","../../src/uniswap/v4/router/errors.d.ts","../../src/uniswap/v4/router/permit2.d.ts","../../src/uniswap/v4/router/quote.d.ts","../../src/uniswap/v4/router/quoteByPoolKey.d.ts","../../src/uniswap/v4/router/resolvePoolKey.d.ts","../../src/uniswap/v4/router/swap.d.ts","../../src/uniswap/lpGreeks.d.ts","../../src/uniswap/v3/addresses.d.ts","../../src/uniswap/v3/router/encodeSwap.d.ts","../../src/uniswap/v3/router/quote.d.ts"],"sourcesContent":null,"mappings":";;;;;;;;;;;AAuDcuF,cA5BOpF,OAAAA,GA4BPoF,EAAAA;;AAUCP,cApCM5E,oBAAAA,GAoCN4E,CAAAA;AAAG;cAlCG3E,UAAAA;;cAEAC,QAAAA;;;;cAIAE,qBAAAA;;cAEAC,KAAAA;;AAsCrB;;AAAqDC,UAlCpCA,uBAAAA,CAkCoCA;EAAuB;EACrD,OAAWsE,EAjCrB1B,OAiCqB0B;EAAG;;;;;;;EASbpE,OAAAA,EAlCX2E,OAkCW3E;EAA0B;EAAA,QAAOF,EAhC3C6E,OAgC2C7E;EAAuB;EACnE,QAAA,EAAA,MAAA;;;;AAMb;;EAAgD,SAEnC4C,CAAAA,EAjCGiC,OAiCHjC;EAAO;EAQA,QAENiC,CAAAA,EAzCCP,GAyCDO;;;AAUI;;;;;;;;;iBAvCM5E,sBAAAA,OAA6BD;kBACjCsE,cA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Be;YUjBdA;EVmBOnF,GAAAA,EAAAA,MAAAA;;EAEAC;;EAEAC,WAAQ,CAAA,EAAA,MAAA;cUjBbqF,QAAQF;AVqBxB;UUnBiBG,cAAAA;EVqBInF,SAAK,EAAA,MAAA;;;;AAI1B;;;;;AAoBgB8E,iBUnCQM,cAAAA,CVmCRN,MAAAA,EUnC+BG,oBVmC/BH,CAAAA,EUnCsDO,OVmCtDP,CUnC8DK,cVmC9DL,GAAAA,IAAAA,CAAAA"}
|
package/dist/uniswap/index.js
CHANGED
|
@@ -1,9 +1,68 @@
|
|
|
1
|
-
import { PanopticError } from "../position-
|
|
2
|
-
import "../greeks-GysWXct-.js";
|
|
3
|
-
import "../writes-
|
|
4
|
-
import { AmountExceedsUint128Error, InvalidSwapTokenError, MissingSweepRecipientError, PERMIT2_ADDRESS, QuoterUnavailableError, SETTLE_ALL, SWAP_EXACT_IN_SINGLE, SWAP_EXACT_OUT_SINGLE, SWEEP, TAKE_ALL, UNISWAP_V4_ADDRESSES, UnsupportedChainError, V4_SWAP, approveErc20ForPermit2, approveErc20ForPermit2AndWait, approveRouterViaPermit2, approveRouterViaPermit2AndWait, buildV4ExactOutSwapExecuteArgs, buildV4ExactOutSwapExecuteCalldata, buildV4SwapExecuteArgs, buildV4SwapExecuteCalldata, checkRouterApproval, getUniswapV4Addresses, quoteSwapExactInViaRouter, quoteSwapExactOutViaRouter, quoteV4ExactInByPoolKey, resolveSwapRoute, swapExactInViaRouter, swapExactInViaRouterAndWait, swapExactOutViaRouter, swapExactOutViaRouterAndWait, universalRouterAbi } from "../router-
|
|
1
|
+
import { PanopticError } from "../position-UL1gOvqZ.js";
|
|
2
|
+
import { tickToSqrtPriceX96 } from "../greeks-GysWXct-.js";
|
|
3
|
+
import "../writes-RyS0kHpB.js";
|
|
4
|
+
import { AmountExceedsUint128Error, InvalidSwapTokenError, MissingSweepRecipientError, PERMIT2_ADDRESS, QuoterUnavailableError, SETTLE_ALL, SWAP_EXACT_IN_SINGLE, SWAP_EXACT_OUT_SINGLE, SWEEP, TAKE_ALL, UNISWAP_V4_ADDRESSES, UnsupportedChainError, V4_SWAP, approveErc20ForPermit2, approveErc20ForPermit2AndWait, approveRouterViaPermit2, approveRouterViaPermit2AndWait, buildV4ExactOutSwapExecuteArgs, buildV4ExactOutSwapExecuteCalldata, buildV4SwapExecuteArgs, buildV4SwapExecuteCalldata, checkRouterApproval, getUniswapV4Addresses, quoteSwapExactInViaRouter, quoteSwapExactOutViaRouter, quoteV4ExactInByPoolKey, resolveSwapRoute, swapExactInViaRouter, swapExactInViaRouterAndWait, swapExactOutViaRouter, swapExactOutViaRouterAndWait, universalRouterAbi } from "../router-Del9H6e0.js";
|
|
5
5
|
import { BaseError, ContractFunctionRevertedError, encodeAbiParameters, encodeFunctionData, encodePacked, zeroAddress } from "viem";
|
|
6
6
|
|
|
7
|
+
//#region src/uniswap/lpGreeks.ts
|
|
8
|
+
const Q96 = 1n << 96n;
|
|
9
|
+
const Q192 = 1n << 192n;
|
|
10
|
+
/**
|
|
11
|
+
* Compute the token0/token1 amounts backing `liquidity` over `[sqrtA, sqrtB]`
|
|
12
|
+
* at the current price `sqrtP`, mirroring Uniswap's `LiquidityAmounts`
|
|
13
|
+
* (`getAmountsForLiquidity`). All sqrt prices are X96. The current price is
|
|
14
|
+
* clamped into the range, so out-of-range positions collapse to a single token.
|
|
15
|
+
*/
|
|
16
|
+
function getAmountsForLiquidity(sqrtPriceX96, sqrtRatioAX96, sqrtRatioBX96, liquidity) {
|
|
17
|
+
const [sqrtA, sqrtB] = sqrtRatioAX96 <= sqrtRatioBX96 ? [sqrtRatioAX96, sqrtRatioBX96] : [sqrtRatioBX96, sqrtRatioAX96];
|
|
18
|
+
const sqrtC = sqrtPriceX96 < sqrtA ? sqrtA : sqrtPriceX96 > sqrtB ? sqrtB : sqrtPriceX96;
|
|
19
|
+
const amount0 = sqrtC < sqrtB ? liquidity * (sqrtB - sqrtC) * Q96 / (sqrtC * sqrtB) : 0n;
|
|
20
|
+
const amount1 = sqrtC > sqrtA ? liquidity * (sqrtC - sqrtA) / Q96 : 0n;
|
|
21
|
+
return {
|
|
22
|
+
amount0,
|
|
23
|
+
amount1
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Greeks (value, delta, gamma) for a Uniswap LP position in the chosen asset
|
|
28
|
+
* frame. See the module docs for the unit conventions.
|
|
29
|
+
*
|
|
30
|
+
* Closed forms (in-range, numeraire = token1 / asset = token0):
|
|
31
|
+
* value = amount1 + amount0·P (P = sqrtP² / 2^192)
|
|
32
|
+
* delta = amount0 (= dV/dP)
|
|
33
|
+
* gamma = P²·d²V/dP² = -L·sqrt(P)/2 (short gamma)
|
|
34
|
+
* The `assetIndex = 1` frame is the symmetric inverse (numeraire = token0).
|
|
35
|
+
* Gamma is zero when the price is outside the range (no curvature there).
|
|
36
|
+
*/
|
|
37
|
+
function getLpGreeks(input) {
|
|
38
|
+
const { liquidity, tickLower, tickUpper, currentTick, assetIndex } = input;
|
|
39
|
+
const sqrtP = tickToSqrtPriceX96(currentTick);
|
|
40
|
+
const sqrtA = tickToSqrtPriceX96(tickLower);
|
|
41
|
+
const sqrtB = tickToSqrtPriceX96(tickUpper);
|
|
42
|
+
const { amount0, amount1 } = getAmountsForLiquidity(sqrtP, sqrtA, sqrtB, liquidity);
|
|
43
|
+
const sqrtP2 = sqrtP * sqrtP;
|
|
44
|
+
const inRange = sqrtP > sqrtA && sqrtP < sqrtB;
|
|
45
|
+
if (assetIndex === 0) {
|
|
46
|
+
const value$1 = amount1 + amount0 * sqrtP2 / Q192;
|
|
47
|
+
const delta$1 = amount0;
|
|
48
|
+
const gamma$1 = inRange ? -(liquidity * sqrtP) / (2n * Q96) : 0n;
|
|
49
|
+
return {
|
|
50
|
+
value: value$1,
|
|
51
|
+
delta: delta$1,
|
|
52
|
+
gamma: gamma$1
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const value = amount0 + amount1 * Q192 / sqrtP2;
|
|
56
|
+
const delta = amount1;
|
|
57
|
+
const gamma = inRange ? -(liquidity * Q96) / (2n * sqrtP) : 0n;
|
|
58
|
+
return {
|
|
59
|
+
value,
|
|
60
|
+
delta,
|
|
61
|
+
gamma
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
7
66
|
//#region src/uniswap/v3/addresses.ts
|
|
8
67
|
/**
|
|
9
68
|
* Verified Uniswap v3 QuoterV2 addresses keyed by chainId. Add a chain only
|
|
@@ -226,5 +285,5 @@ function isRevert(err) {
|
|
|
226
285
|
}
|
|
227
286
|
|
|
228
287
|
//#endregion
|
|
229
|
-
export { AmountExceedsUint128Error, InvalidSwapTokenError, MSG_SENDER, MissingSweepRecipientError, PERMIT2_ADDRESS, QuoterUnavailableError, SETTLE_ALL, SWAP_EXACT_IN_SINGLE, SWAP_EXACT_OUT_SINGLE, SWEEP, TAKE_ALL, UNISWAP_V3_ADDRESSES, UNISWAP_V4_ADDRESSES, UnsupportedChainError, V3_SWAP_EXACT_IN, V4_SWAP, approveErc20ForPermit2, approveErc20ForPermit2AndWait, approveRouterViaPermit2, approveRouterViaPermit2AndWait, buildV3SwapExecuteArgs, buildV3SwapExecuteCalldata, buildV4ExactOutSwapExecuteArgs, buildV4ExactOutSwapExecuteCalldata, buildV4SwapExecuteArgs, buildV4SwapExecuteCalldata, checkRouterApproval, encodeV3Path, getUniswapV3Addresses, getUniswapV4Addresses, quoteSwapExactInViaRouter, quoteSwapExactOutViaRouter, quoteV3ExactIn, quoteV4ExactInByPoolKey, resolveSwapRoute, swapExactInViaRouter, swapExactInViaRouterAndWait, swapExactOutViaRouter, swapExactOutViaRouterAndWait };
|
|
288
|
+
export { AmountExceedsUint128Error, InvalidSwapTokenError, MSG_SENDER, MissingSweepRecipientError, PERMIT2_ADDRESS, QuoterUnavailableError, SETTLE_ALL, SWAP_EXACT_IN_SINGLE, SWAP_EXACT_OUT_SINGLE, SWEEP, TAKE_ALL, UNISWAP_V3_ADDRESSES, UNISWAP_V4_ADDRESSES, UnsupportedChainError, V3_SWAP_EXACT_IN, V4_SWAP, approveErc20ForPermit2, approveErc20ForPermit2AndWait, approveRouterViaPermit2, approveRouterViaPermit2AndWait, buildV3SwapExecuteArgs, buildV3SwapExecuteCalldata, buildV4ExactOutSwapExecuteArgs, buildV4ExactOutSwapExecuteCalldata, buildV4SwapExecuteArgs, buildV4SwapExecuteCalldata, checkRouterApproval, encodeV3Path, getAmountsForLiquidity, getLpGreeks, getUniswapV3Addresses, getUniswapV4Addresses, quoteSwapExactInViaRouter, quoteSwapExactOutViaRouter, quoteV3ExactIn, quoteV4ExactInByPoolKey, resolveSwapRoute, swapExactInViaRouter, swapExactInViaRouterAndWait, swapExactOutViaRouter, swapExactOutViaRouterAndWait };
|
|
230
289
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["UNISWAP_V3_ADDRESSES: Record<number, UniswapV3Addresses>","chainId: number | bigint","overrides?: Partial<UniswapV3Addresses>","MSG_SENDER: Address","UINT128_MAX","amount: bigint","tokenIn: Address","fee: bigint","tokenOut: Address","args: BuildV3SwapCalldataArgs","params: QuoteV3ExactInParams","err: unknown"],"sources":["../../src/uniswap/v3/addresses.ts","../../src/uniswap/v3/router/encodeSwap.ts","../../src/uniswap/v3/abis/quoterV2.ts","../../src/uniswap/v3/router/quote.ts"],"sourcesContent":["/**\n * Per-chain Uniswap v3 addresses needed for spot quoting via the Universal\n * Router. The Universal Router itself is shared with v4 (see\n * `uniswap/v4/addresses`); only the v3 QuoterV2 is specific to v3.\n *\n * v1 supports mainnet only; other chains throw {@link UnsupportedChainError}\n * unless the address is supplied via overrides (fork tests / new chains).\n *\n * @module uniswap/v3/addresses\n */\n\nimport type { Address } from 'viem'\n\nimport { UnsupportedChainError } from '../v4/router/errors'\n\nexport interface UniswapV3Addresses {\n /** Uniswap v3 QuoterV2 — `quoteExactInputSingle` (revert/staticcall-based). */\n quoterV2: Address\n}\n\n/**\n * Verified Uniswap v3 QuoterV2 addresses keyed by chainId. Add a chain only\n * after verifying against the canonical Uniswap v3 deployment listing.\n */\nexport const UNISWAP_V3_ADDRESSES: Record<number, UniswapV3Addresses> = {\n // Ethereum mainnet\n 1: { quoterV2: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e' },\n}\n\n/**\n * Resolve Uniswap v3 addresses for a chain, applying optional overrides.\n *\n * @throws {UnsupportedChainError} when the chain is not listed and overrides do\n * not supply every required address.\n */\nexport function getUniswapV3Addresses(\n chainId: number | bigint,\n overrides?: Partial<UniswapV3Addresses>,\n): UniswapV3Addresses {\n const id = Number(chainId)\n const base = UNISWAP_V3_ADDRESSES[id]\n const merged = { ...base, ...overrides }\n if (!merged.quoterV2) {\n throw new UnsupportedChainError(BigInt(id))\n }\n return merged as UniswapV3Addresses\n}\n","/**\n * Pure calldata builder for an exact-in single-hop swap through a Uniswap **v3**\n * pool via the Universal Router.\n *\n * Opcodes verified against `@uniswap/universal-router` `Commands.sol`:\n * - Universal Router command `V3_SWAP_EXACT_IN = 0x00`.\n *\n * The v3 command input is (unlike the v4 action list) a single flat tuple:\n * `(address recipient, uint256 amountIn, uint256 amountOutMinimum,\n * bytes path, bool payerIsUser)`\n * where:\n * - `recipient` is an EXPLICIT field. We encode the Universal Router sentinel\n * `MSG_SENDER = address(1)`, which the router maps to the `execute` caller —\n * so the output is delivered to the caller (e.g. a Safe) with no literal\n * address in the calldata to redirect.\n * - `path` is `abi.encodePacked(tokenIn, fee (uint24), tokenOut)` for a single\n * hop (43 bytes). The direction lives in the path ordering, not a bool.\n * - `payerIsUser = true`: the router pulls `tokenIn` from the caller via Permit2.\n *\n * ERC20-only: native ETH is intentionally unsupported here (the native paths\n * need WRAP/UNWRAP/SWEEP commands with explicit recipients).\n *\n * @module uniswap/v3/router/encodeSwap\n */\n\nimport type { Address, Hex } from 'viem'\nimport { encodeAbiParameters, encodeFunctionData, encodePacked, zeroAddress } from 'viem'\n\nimport { PanopticError } from '../../../panoptic/v2/errors'\nimport { universalRouterAbi } from '../../v4/abis/universalRouter'\nimport { AmountExceedsUint128Error } from '../../v4/router/errors'\n\n/** Universal Router command byte for a v3 exact-in swap. */\nexport const V3_SWAP_EXACT_IN = 0x00\n\n/**\n * Universal Router recipient sentinel: the router maps `address(1)` to\n * `msg.sender` (the `execute` caller). Uniswap `Constants.MSG_SENDER`.\n */\nexport const MSG_SENDER: Address = '0x0000000000000000000000000000000000000001'\n\nconst UINT128_MAX = (1n << 128n) - 1n\n\nconst v3ExactInInputAbi = [\n { name: 'recipient', type: 'address' },\n { name: 'amountIn', type: 'uint256' },\n { name: 'amountOutMinimum', type: 'uint256' },\n { name: 'path', type: 'bytes' },\n { name: 'payerIsUser', type: 'bool' },\n] as const\n\nfunction assertUint128(amount: bigint): void {\n if (amount < 0n || amount > UINT128_MAX) {\n throw new AmountExceedsUint128Error(amount)\n }\n}\n\n/** Arguments for {@link buildV3SwapExecuteCalldata}. */\nexport interface BuildV3SwapCalldataArgs {\n /** Input token (funds pulled from the caller via Permit2). */\n tokenIn: Address\n /** Output token. */\n tokenOut: Address\n /** v3 pool fee tier (e.g. 500, 3000). */\n fee: bigint\n /** Exact input amount (uint128). */\n amountIn: bigint\n /** Minimum acceptable output (uint128). */\n amountOutMinimum: bigint\n /**\n * Absolute deadline (unix seconds) — the `execute(commands, inputs, deadline)`\n * argument, enforced by the Universal Router.\n */\n deadline: bigint\n}\n\n/**\n * Encode the packed v3 single-hop path `tokenIn ++ fee(uint24) ++ tokenOut`.\n */\nexport function encodeV3Path(tokenIn: Address, fee: bigint, tokenOut: Address): Hex {\n if (fee < 0n || fee > 0xffffffn) {\n throw new PanopticError(`v3 fee ${fee} exceeds uint24`)\n }\n return encodePacked(['address', 'uint24', 'address'], [tokenIn, Number(fee), tokenOut])\n}\n\n/**\n * Build the typed `execute(...)` args for an exact-in single-hop v3 swap whose\n * output is delivered to the `execute` caller (recipient = MSG_SENDER).\n */\nexport function buildV3SwapExecuteArgs(args: BuildV3SwapCalldataArgs): {\n args: readonly [Hex, readonly Hex[], bigint]\n value: bigint\n} {\n const { tokenIn, tokenOut, fee, amountIn, amountOutMinimum, deadline } = args\n\n if (tokenIn === zeroAddress || tokenOut === zeroAddress) {\n throw new PanopticError('native ETH is not supported by the v3 exact-in router builder')\n }\n assertUint128(amountIn)\n assertUint128(amountOutMinimum)\n\n const path = encodeV3Path(tokenIn, fee, tokenOut)\n const input = encodeAbiParameters(v3ExactInInputAbi, [\n MSG_SENDER,\n amountIn,\n amountOutMinimum,\n path,\n true, // payerIsUser: pull tokenIn from the caller via Permit2\n ])\n\n const commands = encodePacked(['uint8'], [V3_SWAP_EXACT_IN])\n return { args: [commands, [input], deadline] as const, value: 0n }\n}\n\n/**\n * Build the `execute(commands, inputs, deadline)` calldata for an exact-in\n * single-hop v3 swap.\n */\nexport function buildV3SwapExecuteCalldata(args: BuildV3SwapCalldataArgs): {\n data: Hex\n value: bigint\n} {\n const { args: executeArgs, value } = buildV3SwapExecuteArgs(args)\n const data = encodeFunctionData({\n abi: universalRouterAbi,\n functionName: 'execute',\n args: executeArgs,\n })\n return { data, value }\n}\n","/**\n * Minimal Uniswap v3 QuoterV2 ABI (`quoteExactInputSingle`).\n *\n * QuoterV2 is revert/staticcall-based (nonpayable but intended for `eth_call` /\n * `simulateContract`), so it must be simulated, not read.\n * @module uniswap/v3/abis/quoterV2\n */\n\nexport const quoterV2Abi = [\n {\n type: 'function',\n name: 'quoteExactInputSingle',\n stateMutability: 'nonpayable',\n inputs: [\n {\n name: 'params',\n type: 'tuple',\n components: [\n { name: 'tokenIn', type: 'address' },\n { name: 'tokenOut', type: 'address' },\n { name: 'amountIn', type: 'uint256' },\n { name: 'fee', type: 'uint24' },\n { name: 'sqrtPriceLimitX96', type: 'uint160' },\n ],\n },\n ],\n outputs: [\n { name: 'amountOut', type: 'uint256' },\n { name: 'sqrtPriceX96After', type: 'uint160' },\n { name: 'initializedTicksCrossed', type: 'uint32' },\n { name: 'gasEstimate', type: 'uint256' },\n ],\n },\n] as const\n","/**\n * Quote an exact-in single-hop swap against a Uniswap v3 pool via QuoterV2.\n * @module uniswap/v3/router/quote\n */\n\nimport type { Address, PublicClient } from 'viem'\nimport { BaseError, ContractFunctionRevertedError } from 'viem'\n\nimport { PanopticError } from '../../../panoptic/v2/errors'\nimport { quoterV2Abi } from '../abis/quoterV2'\nimport { type UniswapV3Addresses, getUniswapV3Addresses } from '../addresses'\n\nconst BPS_DENOMINATOR = 10_000n\nconst UINT128_MAX = (1n << 128n) - 1n\n\nexport interface QuoteV3ExactInParams {\n client: PublicClient\n chainId: bigint\n tokenIn: Address\n tokenOut: Address\n fee: bigint\n amountIn: bigint\n /** Slippage tolerance in bps, used to compute `amountOutMinimum`. */\n slippageBps: bigint\n blockNumber?: bigint\n addresses?: Partial<UniswapV3Addresses>\n}\n\nexport interface V3ExactInQuote {\n amountOut: bigint\n amountOutMinimum: bigint\n gasEstimate: bigint\n}\n\n/**\n * Quote an exact-in v3 swap. Returns `null` when the quote reverts (e.g. the\n * pool does not exist / has no liquidity) so callers can skip that pool when\n * ranking venues, rather than aborting the whole cycle.\n */\nexport async function quoteV3ExactIn(params: QuoteV3ExactInParams): Promise<V3ExactInQuote | null> {\n const { client, chainId, tokenIn, tokenOut, fee, amountIn, slippageBps, blockNumber } = params\n if (amountIn < 0n || amountIn > UINT128_MAX) {\n throw new PanopticError(`amountIn ${amountIn} exceeds uint128 maximum`)\n }\n if (slippageBps < 0n || slippageBps > BPS_DENOMINATOR) {\n throw new PanopticError(`invalid slippageBps ${slippageBps}, must be 0..10000`)\n }\n\n const { quoterV2 } = getUniswapV3Addresses(chainId, params.addresses)\n\n try {\n const { result } = await client.simulateContract({\n address: quoterV2,\n abi: quoterV2Abi,\n functionName: 'quoteExactInputSingle',\n blockNumber,\n args: [{ tokenIn, tokenOut, amountIn, fee: Number(fee), sqrtPriceLimitX96: 0n }],\n })\n const [amountOut, , , gasEstimate] = result\n const amountOutMinimum = (amountOut * (BPS_DENOMINATOR - slippageBps)) / BPS_DENOMINATOR\n return { amountOut, amountOutMinimum, gasEstimate }\n } catch (err) {\n if (isRevert(err)) return null\n // Transport/RPC/timeout errors are NOT \"no liquidity\" — rethrow so routing\n // doesn't silently treat an unreachable node as an empty pool.\n throw err\n }\n}\n\n/** True only for genuine contract reverts (missing pool / no liquidity). */\nfunction isRevert(err: unknown): boolean {\n return (\n err instanceof BaseError &&\n err.walk((e) => e instanceof ContractFunctionRevertedError) instanceof\n ContractFunctionRevertedError\n )\n}\n"],"mappings":";;;;;;;;;;;AAwBA,MAAaA,uBAA2D,EAEtE,GAAG,EAAE,UAAU,6CAA8C,EAC9D;;;;;;;AAQD,SAAgB,sBACdC,SACAC,WACoB;CACpB,MAAM,KAAK,OAAO,QAAQ;CAC1B,MAAM,OAAO,qBAAqB;CAClC,MAAM,SAAS;EAAE,GAAG;EAAM,GAAG;CAAW;AACxC,MAAK,OAAO,SACV,OAAM,IAAI,sBAAsB,OAAO,GAAG;AAE5C,QAAO;AACR;;;;;ACbD,MAAa,mBAAmB;;;;;AAMhC,MAAaC,aAAsB;AAEnC,MAAMC,iBAAe,MAAM,QAAQ;AAEnC,MAAM,oBAAoB;CACxB;EAAE,MAAM;EAAa,MAAM;CAAW;CACtC;EAAE,MAAM;EAAY,MAAM;CAAW;CACrC;EAAE,MAAM;EAAoB,MAAM;CAAW;CAC7C;EAAE,MAAM;EAAQ,MAAM;CAAS;CAC/B;EAAE,MAAM;EAAe,MAAM;CAAQ;AACtC;AAED,SAAS,cAAcC,QAAsB;AAC3C,KAAI,SAAS,MAAM,SAASD,cAC1B,OAAM,IAAI,0BAA0B;AAEvC;;;;AAwBD,SAAgB,aAAaE,SAAkBC,KAAaC,UAAwB;AAClF,KAAI,MAAM,MAAM,MAAM,UACpB,OAAM,IAAI,eAAe,SAAS,IAAI;AAExC,QAAO,aAAa;EAAC;EAAW;EAAU;CAAU,GAAE;EAAC;EAAS,OAAO,IAAI;EAAE;CAA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C,eAAsB,eAAeC,QAA8D;CACjG,MAAM,EAAE,QAAQ,SAAS,SAAS,UAAU,KAAK,UAAU,aAAa,aAAa,GAAG;AACxF,KAAI,WAAW,MAAM,WAAW,YAC9B,OAAM,IAAI,eAAe,WAAW,SAAS;AAE/C,KAAI,cAAc,MAAM,cAAc,gBACpC,OAAM,IAAI,eAAe,sBAAsB,YAAY;CAG7D,MAAM,EAAE,UAAU,GAAG,sBAAsB,SAAS,OAAO,UAAU;AAErE,KAAI;EACF,MAAM,EAAE,QAAQ,GAAG,MAAM,OAAO,iBAAiB;GAC/C,SAAS;GACT,KAAK;GACL,cAAc;GACd;GACA,MAAM,CAAC;IAAE;IAAS;IAAU;IAAU,KAAK,OAAO,IAAI;IAAE,mBAAmB;GAAI,CAAC;EACjF,EAAC;EACF,MAAM,CAAC,eAAe,YAAY,GAAG;EACrC,MAAM,mBAAoB,aAAa,kBAAkB,eAAgB;AACzE,SAAO;GAAE;GAAW;GAAkB;EAAa;CACpD,SAAQ,KAAK;AACZ,MAAI,SAAS,IAAI,CAAE,QAAO;AAG1B,QAAM;CACP;AACF;;AAGD,SAAS,SAASC,KAAuB;AACvC,QACE,eAAe,aACf,IAAI,KAAK,CAAC,MAAM,aAAa,8BAA8B,YACzD;AAEL"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["sqrtPriceX96: bigint","sqrtRatioAX96: bigint","sqrtRatioBX96: bigint","liquidity: bigint","input: LpGreeksInput","value","delta","gamma","UNISWAP_V3_ADDRESSES: Record<number, UniswapV3Addresses>","chainId: number | bigint","overrides?: Partial<UniswapV3Addresses>","MSG_SENDER: Address","UINT128_MAX","amount: bigint","tokenIn: Address","fee: bigint","tokenOut: Address","args: BuildV3SwapCalldataArgs","params: QuoteV3ExactInParams","err: unknown"],"sources":["../../src/uniswap/lpGreeks.ts","../../src/uniswap/v3/addresses.ts","../../src/uniswap/v3/router/encodeSwap.ts","../../src/uniswap/v3/abis/quoterV2.ts","../../src/uniswap/v3/router/quote.ts"],"sourcesContent":["/**\n * Greeks for plain (non-Panoptic) Uniswap v3/v4 concentrated-liquidity LP\n * positions. Pure math over on-chain position fields (liquidity + tick range)\n * and the pool's current price — no RPC, no protocol dependency.\n *\n * Units follow the Panoptic v2 greeks convention (see\n * `packages/sdk/src/panoptic/v2/greeks/index.ts`) so a caller can present LP\n * and Panoptic greeks side by side:\n * - `value` → numeraire-token smallest units\n * - `delta` → asset-token smallest units (the asset held by the LP)\n * - `gamma` → numeraire-token smallest units (dollar-gamma `P²·d²V/dP²`;\n * always ≤ 0 because an LP is short gamma)\n *\n * `assetIndex` selects which token is the \"asset\" (the volatile leg being\n * hedged): `0` → token0 is the asset / token1 the numeraire; `1` → the reverse.\n *\n * @module uniswap/lpGreeks\n */\n\nimport { tickToSqrtPriceX96 } from '../panoptic/v2/formatters/tick'\n\nconst Q96 = 1n << 96n\nconst Q192 = 1n << 192n\n\n/** Token amounts currently backing a concentrated-liquidity position. */\nexport interface LpAmounts {\n /** token0 amount in its smallest units. */\n amount0: bigint\n /** token1 amount in its smallest units. */\n amount1: bigint\n}\n\n/** Greeks of a Uniswap LP position in one asset frame (see module docs for units). */\nexport interface LpGreeks {\n /** Position value in numeraire-token smallest units. */\n value: bigint\n /** Delta in asset-token smallest units (the asset amount the LP is long). */\n delta: bigint\n /** Dollar-gamma in numeraire-token smallest units; ≤ 0 (LP is short gamma). */\n gamma: bigint\n}\n\n/** Inputs describing a single LP position + the pool's current price. */\nexport interface LpGreeksInput {\n /** Position liquidity `L`. */\n liquidity: bigint\n /** Lower tick of the range. */\n tickLower: bigint\n /** Upper tick of the range. */\n tickUpper: bigint\n /** Pool's current tick. */\n currentTick: bigint\n /** Which token is the asset: `0` (token0) or `1` (token1). */\n assetIndex: 0 | 1\n}\n\n/**\n * Compute the token0/token1 amounts backing `liquidity` over `[sqrtA, sqrtB]`\n * at the current price `sqrtP`, mirroring Uniswap's `LiquidityAmounts`\n * (`getAmountsForLiquidity`). All sqrt prices are X96. The current price is\n * clamped into the range, so out-of-range positions collapse to a single token.\n */\nexport function getAmountsForLiquidity(\n sqrtPriceX96: bigint,\n sqrtRatioAX96: bigint,\n sqrtRatioBX96: bigint,\n liquidity: bigint,\n): LpAmounts {\n // Normalize so A <= B.\n const [sqrtA, sqrtB] =\n sqrtRatioAX96 <= sqrtRatioBX96 ? [sqrtRatioAX96, sqrtRatioBX96] : [sqrtRatioBX96, sqrtRatioAX96]\n\n // Clamp the current price into [A, B].\n const sqrtC = sqrtPriceX96 < sqrtA ? sqrtA : sqrtPriceX96 > sqrtB ? sqrtB : sqrtPriceX96\n\n // amount0 = L * (sqrtB - sqrtC) * 2^96 / (sqrtC * sqrtB)\n const amount0 = sqrtC < sqrtB ? (liquidity * (sqrtB - sqrtC) * Q96) / (sqrtC * sqrtB) : 0n\n\n // amount1 = L * (sqrtC - sqrtA) / 2^96\n const amount1 = sqrtC > sqrtA ? (liquidity * (sqrtC - sqrtA)) / Q96 : 0n\n\n return { amount0, amount1 }\n}\n\n/**\n * Greeks (value, delta, gamma) for a Uniswap LP position in the chosen asset\n * frame. See the module docs for the unit conventions.\n *\n * Closed forms (in-range, numeraire = token1 / asset = token0):\n * value = amount1 + amount0·P (P = sqrtP² / 2^192)\n * delta = amount0 (= dV/dP)\n * gamma = P²·d²V/dP² = -L·sqrt(P)/2 (short gamma)\n * The `assetIndex = 1` frame is the symmetric inverse (numeraire = token0).\n * Gamma is zero when the price is outside the range (no curvature there).\n */\nexport function getLpGreeks(input: LpGreeksInput): LpGreeks {\n const { liquidity, tickLower, tickUpper, currentTick, assetIndex } = input\n\n const sqrtP = tickToSqrtPriceX96(currentTick)\n const sqrtA = tickToSqrtPriceX96(tickLower)\n const sqrtB = tickToSqrtPriceX96(tickUpper)\n\n const { amount0, amount1 } = getAmountsForLiquidity(sqrtP, sqrtA, sqrtB, liquidity)\n\n const sqrtP2 = sqrtP * sqrtP // P in X192\n const inRange = sqrtP > sqrtA && sqrtP < sqrtB\n\n if (assetIndex === 0) {\n // numeraire = token1, asset = token0\n const value = amount1 + (amount0 * sqrtP2) / Q192\n const delta = amount0\n // gamma = -L·sqrt(P)/2, sqrt(P) = sqrtP / 2^96 → in token1 units\n const gamma = inRange ? -(liquidity * sqrtP) / (2n * Q96) : 0n\n return { value, delta, gamma }\n }\n\n // numeraire = token0, asset = token1\n const value = amount0 + (amount1 * Q192) / sqrtP2\n const delta = amount1\n // gamma = -L·sqrt(1/P)/2, sqrt(1/P) = 2^96 / sqrtP → in token0 units\n const gamma = inRange ? -(liquidity * Q96) / (2n * sqrtP) : 0n\n return { value, delta, gamma }\n}\n","/**\n * Per-chain Uniswap v3 addresses needed for spot quoting via the Universal\n * Router. The Universal Router itself is shared with v4 (see\n * `uniswap/v4/addresses`); only the v3 QuoterV2 is specific to v3.\n *\n * v1 supports mainnet only; other chains throw {@link UnsupportedChainError}\n * unless the address is supplied via overrides (fork tests / new chains).\n *\n * @module uniswap/v3/addresses\n */\n\nimport type { Address } from 'viem'\n\nimport { UnsupportedChainError } from '../v4/router/errors'\n\nexport interface UniswapV3Addresses {\n /** Uniswap v3 QuoterV2 — `quoteExactInputSingle` (revert/staticcall-based). */\n quoterV2: Address\n}\n\n/**\n * Verified Uniswap v3 QuoterV2 addresses keyed by chainId. Add a chain only\n * after verifying against the canonical Uniswap v3 deployment listing.\n */\nexport const UNISWAP_V3_ADDRESSES: Record<number, UniswapV3Addresses> = {\n // Ethereum mainnet\n 1: { quoterV2: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e' },\n}\n\n/**\n * Resolve Uniswap v3 addresses for a chain, applying optional overrides.\n *\n * @throws {UnsupportedChainError} when the chain is not listed and overrides do\n * not supply every required address.\n */\nexport function getUniswapV3Addresses(\n chainId: number | bigint,\n overrides?: Partial<UniswapV3Addresses>,\n): UniswapV3Addresses {\n const id = Number(chainId)\n const base = UNISWAP_V3_ADDRESSES[id]\n const merged = { ...base, ...overrides }\n if (!merged.quoterV2) {\n throw new UnsupportedChainError(BigInt(id))\n }\n return merged as UniswapV3Addresses\n}\n","/**\n * Pure calldata builder for an exact-in single-hop swap through a Uniswap **v3**\n * pool via the Universal Router.\n *\n * Opcodes verified against `@uniswap/universal-router` `Commands.sol`:\n * - Universal Router command `V3_SWAP_EXACT_IN = 0x00`.\n *\n * The v3 command input is (unlike the v4 action list) a single flat tuple:\n * `(address recipient, uint256 amountIn, uint256 amountOutMinimum,\n * bytes path, bool payerIsUser)`\n * where:\n * - `recipient` is an EXPLICIT field. We encode the Universal Router sentinel\n * `MSG_SENDER = address(1)`, which the router maps to the `execute` caller —\n * so the output is delivered to the caller (e.g. a Safe) with no literal\n * address in the calldata to redirect.\n * - `path` is `abi.encodePacked(tokenIn, fee (uint24), tokenOut)` for a single\n * hop (43 bytes). The direction lives in the path ordering, not a bool.\n * - `payerIsUser = true`: the router pulls `tokenIn` from the caller via Permit2.\n *\n * ERC20-only: native ETH is intentionally unsupported here (the native paths\n * need WRAP/UNWRAP/SWEEP commands with explicit recipients).\n *\n * @module uniswap/v3/router/encodeSwap\n */\n\nimport type { Address, Hex } from 'viem'\nimport { encodeAbiParameters, encodeFunctionData, encodePacked, zeroAddress } from 'viem'\n\nimport { PanopticError } from '../../../panoptic/v2/errors'\nimport { universalRouterAbi } from '../../v4/abis/universalRouter'\nimport { AmountExceedsUint128Error } from '../../v4/router/errors'\n\n/** Universal Router command byte for a v3 exact-in swap. */\nexport const V3_SWAP_EXACT_IN = 0x00\n\n/**\n * Universal Router recipient sentinel: the router maps `address(1)` to\n * `msg.sender` (the `execute` caller). Uniswap `Constants.MSG_SENDER`.\n */\nexport const MSG_SENDER: Address = '0x0000000000000000000000000000000000000001'\n\nconst UINT128_MAX = (1n << 128n) - 1n\n\nconst v3ExactInInputAbi = [\n { name: 'recipient', type: 'address' },\n { name: 'amountIn', type: 'uint256' },\n { name: 'amountOutMinimum', type: 'uint256' },\n { name: 'path', type: 'bytes' },\n { name: 'payerIsUser', type: 'bool' },\n] as const\n\nfunction assertUint128(amount: bigint): void {\n if (amount < 0n || amount > UINT128_MAX) {\n throw new AmountExceedsUint128Error(amount)\n }\n}\n\n/** Arguments for {@link buildV3SwapExecuteCalldata}. */\nexport interface BuildV3SwapCalldataArgs {\n /** Input token (funds pulled from the caller via Permit2). */\n tokenIn: Address\n /** Output token. */\n tokenOut: Address\n /** v3 pool fee tier (e.g. 500, 3000). */\n fee: bigint\n /** Exact input amount (uint128). */\n amountIn: bigint\n /** Minimum acceptable output (uint128). */\n amountOutMinimum: bigint\n /**\n * Absolute deadline (unix seconds) — the `execute(commands, inputs, deadline)`\n * argument, enforced by the Universal Router.\n */\n deadline: bigint\n}\n\n/**\n * Encode the packed v3 single-hop path `tokenIn ++ fee(uint24) ++ tokenOut`.\n */\nexport function encodeV3Path(tokenIn: Address, fee: bigint, tokenOut: Address): Hex {\n if (fee < 0n || fee > 0xffffffn) {\n throw new PanopticError(`v3 fee ${fee} exceeds uint24`)\n }\n return encodePacked(['address', 'uint24', 'address'], [tokenIn, Number(fee), tokenOut])\n}\n\n/**\n * Build the typed `execute(...)` args for an exact-in single-hop v3 swap whose\n * output is delivered to the `execute` caller (recipient = MSG_SENDER).\n */\nexport function buildV3SwapExecuteArgs(args: BuildV3SwapCalldataArgs): {\n args: readonly [Hex, readonly Hex[], bigint]\n value: bigint\n} {\n const { tokenIn, tokenOut, fee, amountIn, amountOutMinimum, deadline } = args\n\n if (tokenIn === zeroAddress || tokenOut === zeroAddress) {\n throw new PanopticError('native ETH is not supported by the v3 exact-in router builder')\n }\n assertUint128(amountIn)\n assertUint128(amountOutMinimum)\n\n const path = encodeV3Path(tokenIn, fee, tokenOut)\n const input = encodeAbiParameters(v3ExactInInputAbi, [\n MSG_SENDER,\n amountIn,\n amountOutMinimum,\n path,\n true, // payerIsUser: pull tokenIn from the caller via Permit2\n ])\n\n const commands = encodePacked(['uint8'], [V3_SWAP_EXACT_IN])\n return { args: [commands, [input], deadline] as const, value: 0n }\n}\n\n/**\n * Build the `execute(commands, inputs, deadline)` calldata for an exact-in\n * single-hop v3 swap.\n */\nexport function buildV3SwapExecuteCalldata(args: BuildV3SwapCalldataArgs): {\n data: Hex\n value: bigint\n} {\n const { args: executeArgs, value } = buildV3SwapExecuteArgs(args)\n const data = encodeFunctionData({\n abi: universalRouterAbi,\n functionName: 'execute',\n args: executeArgs,\n })\n return { data, value }\n}\n","/**\n * Minimal Uniswap v3 QuoterV2 ABI (`quoteExactInputSingle`).\n *\n * QuoterV2 is revert/staticcall-based (nonpayable but intended for `eth_call` /\n * `simulateContract`), so it must be simulated, not read.\n * @module uniswap/v3/abis/quoterV2\n */\n\nexport const quoterV2Abi = [\n {\n type: 'function',\n name: 'quoteExactInputSingle',\n stateMutability: 'nonpayable',\n inputs: [\n {\n name: 'params',\n type: 'tuple',\n components: [\n { name: 'tokenIn', type: 'address' },\n { name: 'tokenOut', type: 'address' },\n { name: 'amountIn', type: 'uint256' },\n { name: 'fee', type: 'uint24' },\n { name: 'sqrtPriceLimitX96', type: 'uint160' },\n ],\n },\n ],\n outputs: [\n { name: 'amountOut', type: 'uint256' },\n { name: 'sqrtPriceX96After', type: 'uint160' },\n { name: 'initializedTicksCrossed', type: 'uint32' },\n { name: 'gasEstimate', type: 'uint256' },\n ],\n },\n] as const\n","/**\n * Quote an exact-in single-hop swap against a Uniswap v3 pool via QuoterV2.\n * @module uniswap/v3/router/quote\n */\n\nimport type { Address, PublicClient } from 'viem'\nimport { BaseError, ContractFunctionRevertedError } from 'viem'\n\nimport { PanopticError } from '../../../panoptic/v2/errors'\nimport { quoterV2Abi } from '../abis/quoterV2'\nimport { type UniswapV3Addresses, getUniswapV3Addresses } from '../addresses'\n\nconst BPS_DENOMINATOR = 10_000n\nconst UINT128_MAX = (1n << 128n) - 1n\n\nexport interface QuoteV3ExactInParams {\n client: PublicClient\n chainId: bigint\n tokenIn: Address\n tokenOut: Address\n fee: bigint\n amountIn: bigint\n /** Slippage tolerance in bps, used to compute `amountOutMinimum`. */\n slippageBps: bigint\n blockNumber?: bigint\n addresses?: Partial<UniswapV3Addresses>\n}\n\nexport interface V3ExactInQuote {\n amountOut: bigint\n amountOutMinimum: bigint\n gasEstimate: bigint\n}\n\n/**\n * Quote an exact-in v3 swap. Returns `null` when the quote reverts (e.g. the\n * pool does not exist / has no liquidity) so callers can skip that pool when\n * ranking venues, rather than aborting the whole cycle.\n */\nexport async function quoteV3ExactIn(params: QuoteV3ExactInParams): Promise<V3ExactInQuote | null> {\n const { client, chainId, tokenIn, tokenOut, fee, amountIn, slippageBps, blockNumber } = params\n if (amountIn < 0n || amountIn > UINT128_MAX) {\n throw new PanopticError(`amountIn ${amountIn} exceeds uint128 maximum`)\n }\n if (slippageBps < 0n || slippageBps > BPS_DENOMINATOR) {\n throw new PanopticError(`invalid slippageBps ${slippageBps}, must be 0..10000`)\n }\n\n const { quoterV2 } = getUniswapV3Addresses(chainId, params.addresses)\n\n try {\n const { result } = await client.simulateContract({\n address: quoterV2,\n abi: quoterV2Abi,\n functionName: 'quoteExactInputSingle',\n blockNumber,\n args: [{ tokenIn, tokenOut, amountIn, fee: Number(fee), sqrtPriceLimitX96: 0n }],\n })\n const [amountOut, , , gasEstimate] = result\n const amountOutMinimum = (amountOut * (BPS_DENOMINATOR - slippageBps)) / BPS_DENOMINATOR\n return { amountOut, amountOutMinimum, gasEstimate }\n } catch (err) {\n if (isRevert(err)) return null\n // Transport/RPC/timeout errors are NOT \"no liquidity\" — rethrow so routing\n // doesn't silently treat an unreachable node as an empty pool.\n throw err\n }\n}\n\n/** True only for genuine contract reverts (missing pool / no liquidity). */\nfunction isRevert(err: unknown): boolean {\n return (\n err instanceof BaseError &&\n err.walk((e) => e instanceof ContractFunctionRevertedError) instanceof\n ContractFunctionRevertedError\n )\n}\n"],"mappings":";;;;;;;AAqBA,MAAM,MAAM,MAAM;AAClB,MAAM,OAAO,MAAM;;;;;;;AAwCnB,SAAgB,uBACdA,cACAC,eACAC,eACAC,WACW;CAEX,MAAM,CAAC,OAAO,MAAM,GAClB,iBAAiB,gBAAgB,CAAC,eAAe,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