@pawtom/sdk 0.0.0-stage → 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/README.md +90 -2
- package/dist/abis.d.ts +649 -0
- package/dist/abis.js +47 -0
- package/dist/abis.js.map +1 -0
- package/dist/client.d.ts +228 -0
- package/dist/client.js +474 -0
- package/dist/client.js.map +1 -0
- package/dist/deployments.d.ts +53 -0
- package/dist/deployments.js +52 -0
- package/dist/deployments.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/liquidity.d.ts +65 -0
- package/dist/liquidity.js +135 -0
- package/dist/liquidity.js.map +1 -0
- package/dist/math.d.ts +41 -0
- package/dist/math.js +88 -0
- package/dist/math.js.map +1 -0
- package/package.json +57 -4
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { type Address, type Hex, type PublicClient } from "viem";
|
|
2
|
+
import { type Deployment, type PawtomPool, type Token } from "./deployments.js";
|
|
3
|
+
import { BPS } from "./math.js";
|
|
4
|
+
export type PawtomClientOptions = {
|
|
5
|
+
/** Where Pawtom lives. Defaults to Unichain Sepolia. */
|
|
6
|
+
deployment?: Deployment;
|
|
7
|
+
/** Bring your own viem client, or give an RPC URL (default: the chain's public RPC). */
|
|
8
|
+
publicClient?: PublicClient;
|
|
9
|
+
rpcUrl?: string;
|
|
10
|
+
};
|
|
11
|
+
/** The hook's parameters for a pool, exact (as stored on chain). */
|
|
12
|
+
export type PoolParams = {
|
|
13
|
+
capPips: number;
|
|
14
|
+
priorityCapPips: number;
|
|
15
|
+
kW: bigint;
|
|
16
|
+
kZ: bigint;
|
|
17
|
+
alpha: bigint;
|
|
18
|
+
gap: number;
|
|
19
|
+
sigma0: bigint;
|
|
20
|
+
sigmaMin: bigint;
|
|
21
|
+
sigmaMax: bigint;
|
|
22
|
+
priorityFloor: bigint;
|
|
23
|
+
/** v8: charge per wei of priority fee above the floor, 1e18 = 100%. (v7 priced the charge in ETH: see priorityK.) */
|
|
24
|
+
priorityRate: bigint;
|
|
25
|
+
priorityK?: bigint;
|
|
26
|
+
};
|
|
27
|
+
export type PoolState = {
|
|
28
|
+
pool: PawtomPool;
|
|
29
|
+
poolId: Hex;
|
|
30
|
+
block: bigint;
|
|
31
|
+
blockTime: number;
|
|
32
|
+
baseFee: bigint;
|
|
33
|
+
sqrtPriceX96: bigint;
|
|
34
|
+
tick: number;
|
|
35
|
+
liquidity: bigint;
|
|
36
|
+
/** ln(raw token1 / raw token0), and the price as people read it (quote per base, e.g. USDC per WETH). */
|
|
37
|
+
u: number;
|
|
38
|
+
price: number;
|
|
39
|
+
params: PoolParams;
|
|
40
|
+
/** The measurement a swap now faces: the last active block's move (log-price; 0 = none), its age, whether it
|
|
41
|
+
* still counts (younger than `gap` seconds), and the same move in bps of the displayed price. */
|
|
42
|
+
measurement: {
|
|
43
|
+
delta: number;
|
|
44
|
+
moveBps: number;
|
|
45
|
+
measuredAt: number;
|
|
46
|
+
ageSeconds: number;
|
|
47
|
+
fresh: boolean;
|
|
48
|
+
};
|
|
49
|
+
sigmaPerSecond: number;
|
|
50
|
+
/** Momentum rates now (1e18 = 100%), for a swap raising the raw price (oneForZero) and lowering it (zeroForOne). */
|
|
51
|
+
momentumRateWad: {
|
|
52
|
+
up: bigint;
|
|
53
|
+
down: bigint;
|
|
54
|
+
};
|
|
55
|
+
momentumOn: boolean;
|
|
56
|
+
priorityOn: boolean;
|
|
57
|
+
};
|
|
58
|
+
export type QuoteParams = {
|
|
59
|
+
pool?: PawtomPool;
|
|
60
|
+
tokenIn: Address;
|
|
61
|
+
/** Exact input (exactIn, default) or exact output, in the token's raw units. */
|
|
62
|
+
amount: bigint;
|
|
63
|
+
exactIn?: boolean;
|
|
64
|
+
/** The priority fee per gas the swap will be sent with. Default: 0.001 gwei, below every floor. The priority charge
|
|
65
|
+
* depends only on this, so the quote is exact for it. */
|
|
66
|
+
priorityFeePerGas?: bigint;
|
|
67
|
+
/** Slippage for amountOutMin / amountInMax, in bps (default 50). */
|
|
68
|
+
slippageBps?: number;
|
|
69
|
+
};
|
|
70
|
+
export type ChargePart = {
|
|
71
|
+
rateWad: bigint;
|
|
72
|
+
bps: number;
|
|
73
|
+
amount: bigint;
|
|
74
|
+
};
|
|
75
|
+
export type Quote = {
|
|
76
|
+
pool: PawtomPool;
|
|
77
|
+
block: bigint;
|
|
78
|
+
tokenIn: Token;
|
|
79
|
+
tokenOut: Token;
|
|
80
|
+
exactIn: boolean;
|
|
81
|
+
amountIn: bigint;
|
|
82
|
+
amountOut: bigint;
|
|
83
|
+
/** Bound to send with the swap: amountOutMin (exact in) or amountInMax (exact out), after slippage. */
|
|
84
|
+
limit: bigint;
|
|
85
|
+
zeroForOne: boolean;
|
|
86
|
+
priorityFeePerGas: bigint;
|
|
87
|
+
/** The token both charges are taken in: the output of an exact-input swap, the input of an exact-output swap. */
|
|
88
|
+
chargedToken: Token;
|
|
89
|
+
lpFee: {
|
|
90
|
+
pips: number;
|
|
91
|
+
bps: number;
|
|
92
|
+
};
|
|
93
|
+
momentum: ChargePart & {
|
|
94
|
+
continuesMove: boolean;
|
|
95
|
+
};
|
|
96
|
+
priority: ChargePart;
|
|
97
|
+
/** Charge amounts are derived from the quoted totals and the hook's rates; each can differ from settlement by 1 wei. */
|
|
98
|
+
amountsExact: false;
|
|
99
|
+
explanation: string[];
|
|
100
|
+
warnings: string[];
|
|
101
|
+
};
|
|
102
|
+
export type UnsignedTx = {
|
|
103
|
+
to: Address;
|
|
104
|
+
data: Hex;
|
|
105
|
+
value: bigint;
|
|
106
|
+
chainId: number;
|
|
107
|
+
description: string;
|
|
108
|
+
maxPriorityFeePerGas?: bigint;
|
|
109
|
+
};
|
|
110
|
+
export type SwapExplanation = {
|
|
111
|
+
txHash: Hex;
|
|
112
|
+
block: bigint;
|
|
113
|
+
pool: PawtomPool | null;
|
|
114
|
+
zeroForOne: boolean;
|
|
115
|
+
amount0: bigint;
|
|
116
|
+
amount1: bigint;
|
|
117
|
+
priorityFeePerGas: bigint;
|
|
118
|
+
chargedToken: Token | null;
|
|
119
|
+
momentum: bigint;
|
|
120
|
+
priority: bigint;
|
|
121
|
+
/** The measurement in force for this swap's block: the move it measured, or null if the block measured nothing. */
|
|
122
|
+
measuredMoveBps: number | null;
|
|
123
|
+
direction: "with" | "against" | "none";
|
|
124
|
+
explanation: string[];
|
|
125
|
+
};
|
|
126
|
+
export declare class PawtomClient {
|
|
127
|
+
readonly deployment: Deployment;
|
|
128
|
+
readonly publicClient: PublicClient;
|
|
129
|
+
constructor(o?: PawtomClientOptions);
|
|
130
|
+
/** The default pool, or one by name ("USDC/WETH (v8)"), pool id or hook address. */
|
|
131
|
+
pool(which?: string): PawtomPool;
|
|
132
|
+
token(address: Address, pool?: PawtomPool): Token;
|
|
133
|
+
getPool(pool?: PawtomPool): Promise<PoolState>;
|
|
134
|
+
/** The priority charge rate (1e18 = 100%) a swap in `pool` pays at a priority fee per gas. Exact (hook view). */
|
|
135
|
+
priorityRate(priorityFeePerGas: bigint, pool?: PawtomPool): Promise<bigint>;
|
|
136
|
+
/**
|
|
137
|
+
* An exact quote through the canonical V4Quoter, simulated at the priority fee the swap will be sent with, so it
|
|
138
|
+
* includes both charges as settlement will (in the same block). Plus the breakdown: LP fee, momentum charge and
|
|
139
|
+
* priority charge, with plain-language reasons.
|
|
140
|
+
*/
|
|
141
|
+
quote(q: QuoteParams): Promise<Quote>;
|
|
142
|
+
/**
|
|
143
|
+
* Unsigned transactions for a swap: an ERC-20 approval of the router if `owner`'s allowance is short, then the swap,
|
|
144
|
+
* bounded by the quote's slippage limit and sent with the quoted priority fee. Nothing is signed or sent here.
|
|
145
|
+
*/
|
|
146
|
+
buildSwap(o: QuoteParams & {
|
|
147
|
+
recipient: Address;
|
|
148
|
+
owner?: Address;
|
|
149
|
+
deadlineSeconds?: number;
|
|
150
|
+
}): Promise<{
|
|
151
|
+
quote: Quote;
|
|
152
|
+
transactions: UnsignedTx[];
|
|
153
|
+
}>;
|
|
154
|
+
/** What each Pawtom swap in a transaction paid, and why: its charges, the measurement it faced and its tip. */
|
|
155
|
+
explainTx(hash: Hex): Promise<SwapExplanation[]>;
|
|
156
|
+
/** Recent swaps of a pool from the chain, newest first, with each swap's charges. Reads `blocks` back (default
|
|
157
|
+
* 3,000, about 50 minutes on Unichain) in 1,000-block pages, the public RPC's limit. */
|
|
158
|
+
recentSwaps(o?: {
|
|
159
|
+
pool?: PawtomPool;
|
|
160
|
+
blocks?: number;
|
|
161
|
+
limit?: number;
|
|
162
|
+
}): Promise<{
|
|
163
|
+
txHash: `0x${string}`;
|
|
164
|
+
block: bigint;
|
|
165
|
+
amount0: bigint;
|
|
166
|
+
amount1: bigint;
|
|
167
|
+
price: number;
|
|
168
|
+
momentum: bigint;
|
|
169
|
+
priority: bigint;
|
|
170
|
+
chargedToken: Token | null;
|
|
171
|
+
}[]>;
|
|
172
|
+
/** A position: its pool, range, liquidity, whether it is in range now and what it holds. */
|
|
173
|
+
position(tokenId: bigint): Promise<{
|
|
174
|
+
tokenId: bigint;
|
|
175
|
+
owner: `0x${string}`;
|
|
176
|
+
pool: PawtomPool | null;
|
|
177
|
+
poolKey: {
|
|
178
|
+
currency0: `0x${string}`;
|
|
179
|
+
currency1: `0x${string}`;
|
|
180
|
+
fee: number;
|
|
181
|
+
tickSpacing: number;
|
|
182
|
+
hooks: `0x${string}`;
|
|
183
|
+
};
|
|
184
|
+
tickLower: number;
|
|
185
|
+
tickUpper: number;
|
|
186
|
+
liquidity: bigint;
|
|
187
|
+
inRange: boolean | null;
|
|
188
|
+
holds: {
|
|
189
|
+
amount0: bigint;
|
|
190
|
+
amount1: bigint;
|
|
191
|
+
} | null;
|
|
192
|
+
}>;
|
|
193
|
+
/**
|
|
194
|
+
* Unsigned transactions to open a position: Permit2 approvals for both tokens, then the mint. Give a tick range, or
|
|
195
|
+
* a range in percent around the current price (default +-5%). Amounts are the most you are willing to deposit; the
|
|
196
|
+
* liquidity is the largest both amounts allow, minus slippage, and the unused rest is swept back.
|
|
197
|
+
*/
|
|
198
|
+
buildAddLiquidity(o: {
|
|
199
|
+
pool?: PawtomPool;
|
|
200
|
+
owner: Address;
|
|
201
|
+
amount0Max: bigint;
|
|
202
|
+
amount1Max: bigint;
|
|
203
|
+
tickLower?: number;
|
|
204
|
+
tickUpper?: number;
|
|
205
|
+
rangePct?: number;
|
|
206
|
+
slippageBps?: number;
|
|
207
|
+
}): Promise<{
|
|
208
|
+
liquidity: bigint;
|
|
209
|
+
tickLower: number;
|
|
210
|
+
tickUpper: number;
|
|
211
|
+
transactions: UnsignedTx[];
|
|
212
|
+
}>;
|
|
213
|
+
/** Unsigned transaction to remove `percent` (1-100) of a position's liquidity and collect its fees. 100 closes it. */
|
|
214
|
+
buildRemoveLiquidity(o: {
|
|
215
|
+
tokenId: bigint;
|
|
216
|
+
owner: Address;
|
|
217
|
+
percent?: number;
|
|
218
|
+
slippageBps?: number;
|
|
219
|
+
}): Promise<UnsignedTx>;
|
|
220
|
+
/** Unsigned transaction to collect a position's fees, including Pawtom's donated charges, without removing liquidity. */
|
|
221
|
+
buildCollectFees(o: {
|
|
222
|
+
tokenId: bigint;
|
|
223
|
+
owner: Address;
|
|
224
|
+
}): Promise<UnsignedTx>;
|
|
225
|
+
}
|
|
226
|
+
/** Unlimited approval, for callers that want it explicitly (the SDK itself approves exact amounts). */
|
|
227
|
+
export declare const UNLIMITED: bigint;
|
|
228
|
+
export { BPS };
|