@splitmarkets/sdk 0.2.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 +171 -0
- package/SKILL.md +73 -0
- package/dist/chunk-MZEPXYHI.js +758 -0
- package/dist/index.d.ts +527 -0
- package/dist/index.js +1 -0
- package/dist/widget.d.ts +43 -0
- package/dist/widget.js +272 -0
- package/package.json +38 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
import { WalletClient, Address, Hex, PublicClient } from 'viem';
|
|
2
|
+
|
|
3
|
+
declare const BASE_CHAIN_ID = 8453;
|
|
4
|
+
declare const ARB_CHAIN_ID = 42161;
|
|
5
|
+
declare const FACILITATOR_URL_BASE = "https://bundlerfix---b402-facilitator-base-posmj54s5q-uc.a.run.app";
|
|
6
|
+
declare const FACILITATOR_URL_ARB = "https://b402-facilitator-arb-62092339396.us-central1.run.app";
|
|
7
|
+
/** Facilitator base URL for a chain. */
|
|
8
|
+
declare function facilitatorUrlForChain(chain: ChainName): string;
|
|
9
|
+
declare const NEXUS_FACTORY: Address;
|
|
10
|
+
declare const NEXUS_BOOTSTRAP: Address;
|
|
11
|
+
interface UserOp {
|
|
12
|
+
sender: string;
|
|
13
|
+
nonce: string;
|
|
14
|
+
factory?: string;
|
|
15
|
+
factoryData?: string;
|
|
16
|
+
callData: string;
|
|
17
|
+
callGasLimit: string;
|
|
18
|
+
verificationGasLimit: string;
|
|
19
|
+
preVerificationGas: string;
|
|
20
|
+
maxFeePerGas: string;
|
|
21
|
+
maxPriorityFeePerGas: string;
|
|
22
|
+
paymaster?: string;
|
|
23
|
+
paymasterVerificationGasLimit?: string;
|
|
24
|
+
paymasterPostOpGasLimit?: string;
|
|
25
|
+
paymasterData?: string;
|
|
26
|
+
signature: string;
|
|
27
|
+
}
|
|
28
|
+
interface ExecuteCall {
|
|
29
|
+
to: Address;
|
|
30
|
+
data: Hex;
|
|
31
|
+
value: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Derive the deterministic Nexus smart-wallet address for an owner EOA on a chain.
|
|
35
|
+
* salt = keccak256("b402-"+reversed(owner)); computeAccountAddress(initData, salt).
|
|
36
|
+
* Counterfactual — works before the account is deployed (the first UserOp deploys it).
|
|
37
|
+
*/
|
|
38
|
+
declare function deriveSmartWallet(owner: Address, chain: ChainName, rpcUrl?: string): Promise<{
|
|
39
|
+
smartWallet: Address;
|
|
40
|
+
salt: string;
|
|
41
|
+
}>;
|
|
42
|
+
interface TradingAccount {
|
|
43
|
+
/** The user's connected EOA (funds source). */
|
|
44
|
+
eoa: Address;
|
|
45
|
+
/** The in-memory incognito EOA — owner of the smart wallet (never prompts to sign). */
|
|
46
|
+
incognitoEOA: Address;
|
|
47
|
+
/** The trading account: the b402 master Nexus smart wallet of the incognito EOA. */
|
|
48
|
+
smartWallet: Address;
|
|
49
|
+
/** Master salt of the incognito EOA (for the counterfactual first-UserOp deploy). */
|
|
50
|
+
salt: string;
|
|
51
|
+
/** SILENT UserOp-hash signer (the in-memory incognito key). */
|
|
52
|
+
signUserOpHash: (userOpHash: Hex) => Promise<Hex>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Derive the user's trading account from ONE fixed-message signature (cached).
|
|
56
|
+
*
|
|
57
|
+
* The returned `smartWallet` is byte-identical to split.markets for the same EOA.
|
|
58
|
+
* Subsequent calls cost zero popups (the signature is cached in memory, and in
|
|
59
|
+
* sessionStorage in the browser under the same key split.markets uses).
|
|
60
|
+
*/
|
|
61
|
+
declare function deriveTradingAccount(walletClient: WalletClient, account: Address, chain?: ChainName, rpcUrl?: string): Promise<TradingAccount>;
|
|
62
|
+
interface GaslessResult {
|
|
63
|
+
txHash: Hex;
|
|
64
|
+
userOpHash: Hex;
|
|
65
|
+
}
|
|
66
|
+
interface BuyGaslessArgs {
|
|
67
|
+
chain: ChainName;
|
|
68
|
+
side: Side;
|
|
69
|
+
seriesId: number;
|
|
70
|
+
/** Contracts to buy (human, e.g. 0.5). */
|
|
71
|
+
qN: number;
|
|
72
|
+
/** The user's connected wallet (signs the EIP-3009 pull, if any). */
|
|
73
|
+
walletClient: WalletClient;
|
|
74
|
+
/** The user's connected EOA (funds source). */
|
|
75
|
+
account: Address;
|
|
76
|
+
/** Pre-derived trading account (else derived from ONE cached signature). */
|
|
77
|
+
trading?: TradingAccount;
|
|
78
|
+
/** Pre-fetched quote (else fetched fresh right before the trade). */
|
|
79
|
+
quote?: SplitQuote;
|
|
80
|
+
/** Extra slippage over cost+fee, in bps (default 100 = 1%). */
|
|
81
|
+
slippageBps?: number;
|
|
82
|
+
facilitatorUrl?: string;
|
|
83
|
+
rpcUrl?: string;
|
|
84
|
+
/** Quote API base URL override. */
|
|
85
|
+
apiUrl?: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Open a position gaslessly. ZERO approval popups; gas sponsored. N mints to the
|
|
89
|
+
* TRADING ACCOUNT (smart wallet).
|
|
90
|
+
*
|
|
91
|
+
* Spends the trading account's USDC first and pulls ONLY the shortfall from the
|
|
92
|
+
* user's wallet via a single EIP-3009 signature — so it's 0 popups when the trading
|
|
93
|
+
* account is funded, at most 1 when short. The incognito key signs the UserOp silently.
|
|
94
|
+
*/
|
|
95
|
+
declare function buyGasless(args: BuyGaslessArgs): Promise<GaslessResult>;
|
|
96
|
+
interface CloseGaslessArgs {
|
|
97
|
+
chain: ChainName;
|
|
98
|
+
side: Side;
|
|
99
|
+
seriesId: number;
|
|
100
|
+
/** Contracts to close (human). Defaults to the trading account's full N balance. */
|
|
101
|
+
qN?: number;
|
|
102
|
+
walletClient: WalletClient;
|
|
103
|
+
account: Address;
|
|
104
|
+
trading?: TradingAccount;
|
|
105
|
+
quote?: SplitQuote;
|
|
106
|
+
/** Min-proceeds slippage below the quoted bid, in bps (default 100 = 1%). */
|
|
107
|
+
slippageBps?: number;
|
|
108
|
+
facilitatorUrl?: string;
|
|
109
|
+
rpcUrl?: string;
|
|
110
|
+
apiUrl?: string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Close a position gaslessly (sell N back to the pool). ZERO wallet popups — the N
|
|
114
|
+
* lives in the trading account, so the incognito key signs the UserOp silently and
|
|
115
|
+
* the user signs nothing. USDC proceeds settle in the trading account.
|
|
116
|
+
*/
|
|
117
|
+
declare function closeGasless(args: CloseGaslessArgs): Promise<GaslessResult>;
|
|
118
|
+
interface PositionGaslessArgs {
|
|
119
|
+
chain: ChainName;
|
|
120
|
+
side: Side;
|
|
121
|
+
seriesId: number;
|
|
122
|
+
walletClient: WalletClient;
|
|
123
|
+
account: Address;
|
|
124
|
+
trading?: TradingAccount;
|
|
125
|
+
rpcUrl?: string;
|
|
126
|
+
apiUrl?: string;
|
|
127
|
+
}
|
|
128
|
+
interface GaslessPosition {
|
|
129
|
+
/** The trading account (smart wallet) the N is held in. */
|
|
130
|
+
smartWallet: Address;
|
|
131
|
+
qN: number;
|
|
132
|
+
markUsd: number;
|
|
133
|
+
intrinsicUsd: number;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Read the account's gasless position — the N held by the TRADING ACCOUNT (smart
|
|
137
|
+
* wallet) for one series. Mark is at MID = (ask+bid)/2; intrinsicUsd is the
|
|
138
|
+
* settlement floor (call: max(0, spot−strike)·N; put: max(0, strike−spot)·N).
|
|
139
|
+
*/
|
|
140
|
+
declare function getPositionGasless(args: PositionGaslessArgs): Promise<GaslessPosition>;
|
|
141
|
+
|
|
142
|
+
declare const QUOTE_API = "https://quote-api-production-b5b9.up.railway.app";
|
|
143
|
+
type ChainId = 8453 | 42161;
|
|
144
|
+
type ChainName = "base" | "arbitrum";
|
|
145
|
+
type Side = "long" | "short";
|
|
146
|
+
interface ChainConfig {
|
|
147
|
+
id: ChainId;
|
|
148
|
+
name: ChainName;
|
|
149
|
+
/** SplitPool — long calls. */
|
|
150
|
+
splitPool: Address;
|
|
151
|
+
/** SplitPoolPut — short puts. "" when not deployed on this chain. */
|
|
152
|
+
splitPoolPut: Address | "";
|
|
153
|
+
weth: Address;
|
|
154
|
+
usdc: Address;
|
|
155
|
+
/** A public RPC; override per call via getPublic(chain, rpcUrl) if you have your own. */
|
|
156
|
+
rpc: string;
|
|
157
|
+
}
|
|
158
|
+
declare const CHAINS: Record<ChainName, ChainConfig>;
|
|
159
|
+
/** The pool address for a chain + side. Throws if that side isn't deployed there. */
|
|
160
|
+
declare function poolAddress(chain: ChainName, side: Side): Address;
|
|
161
|
+
declare const SPLIT_POOL_ABI: readonly [{
|
|
162
|
+
readonly name: "epoch";
|
|
163
|
+
readonly type: "function";
|
|
164
|
+
readonly stateMutability: "view";
|
|
165
|
+
readonly inputs: readonly [];
|
|
166
|
+
readonly outputs: readonly [{
|
|
167
|
+
readonly type: "uint256";
|
|
168
|
+
}];
|
|
169
|
+
}, {
|
|
170
|
+
readonly name: "phase";
|
|
171
|
+
readonly type: "function";
|
|
172
|
+
readonly stateMutability: "view";
|
|
173
|
+
readonly inputs: readonly [];
|
|
174
|
+
readonly outputs: readonly [{
|
|
175
|
+
readonly type: "uint8";
|
|
176
|
+
}];
|
|
177
|
+
}, {
|
|
178
|
+
readonly name: "seriesCount";
|
|
179
|
+
readonly type: "function";
|
|
180
|
+
readonly stateMutability: "view";
|
|
181
|
+
readonly inputs: readonly [{
|
|
182
|
+
readonly type: "uint256";
|
|
183
|
+
readonly name: "epoch";
|
|
184
|
+
}];
|
|
185
|
+
readonly outputs: readonly [{
|
|
186
|
+
readonly type: "uint256";
|
|
187
|
+
}];
|
|
188
|
+
}, {
|
|
189
|
+
readonly name: "seriesAt";
|
|
190
|
+
readonly type: "function";
|
|
191
|
+
readonly stateMutability: "view";
|
|
192
|
+
readonly inputs: readonly [{
|
|
193
|
+
readonly type: "uint256";
|
|
194
|
+
readonly name: "epoch";
|
|
195
|
+
}, {
|
|
196
|
+
readonly type: "uint256";
|
|
197
|
+
readonly name: "id";
|
|
198
|
+
}];
|
|
199
|
+
readonly outputs: readonly [{
|
|
200
|
+
readonly type: "address";
|
|
201
|
+
readonly name: "vault";
|
|
202
|
+
}, {
|
|
203
|
+
readonly type: "uint256";
|
|
204
|
+
readonly name: "strike";
|
|
205
|
+
}];
|
|
206
|
+
}, {
|
|
207
|
+
readonly name: "freeWeth";
|
|
208
|
+
readonly type: "function";
|
|
209
|
+
readonly stateMutability: "view";
|
|
210
|
+
readonly inputs: readonly [];
|
|
211
|
+
readonly outputs: readonly [{
|
|
212
|
+
readonly type: "uint256";
|
|
213
|
+
}];
|
|
214
|
+
}, {
|
|
215
|
+
readonly name: "freeUsdc";
|
|
216
|
+
readonly type: "function";
|
|
217
|
+
readonly stateMutability: "view";
|
|
218
|
+
readonly inputs: readonly [];
|
|
219
|
+
readonly outputs: readonly [{
|
|
220
|
+
readonly type: "uint256";
|
|
221
|
+
}];
|
|
222
|
+
}, {
|
|
223
|
+
readonly name: "spot6";
|
|
224
|
+
readonly type: "function";
|
|
225
|
+
readonly stateMutability: "view";
|
|
226
|
+
readonly inputs: readonly [];
|
|
227
|
+
readonly outputs: readonly [{
|
|
228
|
+
readonly type: "uint256";
|
|
229
|
+
}];
|
|
230
|
+
}, {
|
|
231
|
+
readonly name: "feeBps";
|
|
232
|
+
readonly type: "function";
|
|
233
|
+
readonly stateMutability: "view";
|
|
234
|
+
readonly inputs: readonly [];
|
|
235
|
+
readonly outputs: readonly [{
|
|
236
|
+
readonly type: "uint16";
|
|
237
|
+
}];
|
|
238
|
+
}, {
|
|
239
|
+
readonly name: "costWithFee";
|
|
240
|
+
readonly type: "function";
|
|
241
|
+
readonly stateMutability: "view";
|
|
242
|
+
readonly inputs: readonly [{
|
|
243
|
+
readonly type: "uint256";
|
|
244
|
+
readonly name: "qN";
|
|
245
|
+
}, {
|
|
246
|
+
readonly type: "uint256";
|
|
247
|
+
readonly name: "askPerN";
|
|
248
|
+
}];
|
|
249
|
+
readonly outputs: readonly [{
|
|
250
|
+
readonly type: "uint256";
|
|
251
|
+
}];
|
|
252
|
+
}, {
|
|
253
|
+
readonly name: "buyN";
|
|
254
|
+
readonly type: "function";
|
|
255
|
+
readonly stateMutability: "nonpayable";
|
|
256
|
+
readonly inputs: readonly [{
|
|
257
|
+
readonly type: "uint256";
|
|
258
|
+
readonly name: "seriesId";
|
|
259
|
+
}, {
|
|
260
|
+
readonly type: "uint256";
|
|
261
|
+
readonly name: "qN";
|
|
262
|
+
}, {
|
|
263
|
+
readonly type: "uint256";
|
|
264
|
+
readonly name: "maxCost";
|
|
265
|
+
}, {
|
|
266
|
+
readonly type: "tuple";
|
|
267
|
+
readonly components: readonly [{
|
|
268
|
+
readonly type: "address";
|
|
269
|
+
}, {
|
|
270
|
+
readonly type: "uint256";
|
|
271
|
+
}, {
|
|
272
|
+
readonly type: "uint256";
|
|
273
|
+
}, {
|
|
274
|
+
readonly type: "uint256";
|
|
275
|
+
}, {
|
|
276
|
+
readonly type: "uint256";
|
|
277
|
+
}];
|
|
278
|
+
readonly name: "q";
|
|
279
|
+
}, {
|
|
280
|
+
readonly type: "bytes";
|
|
281
|
+
readonly name: "sig";
|
|
282
|
+
}];
|
|
283
|
+
readonly outputs: readonly [{
|
|
284
|
+
readonly type: "uint256";
|
|
285
|
+
}];
|
|
286
|
+
}, {
|
|
287
|
+
readonly name: "sellN";
|
|
288
|
+
readonly type: "function";
|
|
289
|
+
readonly stateMutability: "nonpayable";
|
|
290
|
+
readonly inputs: readonly [{
|
|
291
|
+
readonly type: "uint256";
|
|
292
|
+
readonly name: "seriesId";
|
|
293
|
+
}, {
|
|
294
|
+
readonly type: "uint256";
|
|
295
|
+
readonly name: "qN";
|
|
296
|
+
}, {
|
|
297
|
+
readonly type: "uint256";
|
|
298
|
+
readonly name: "minProceeds";
|
|
299
|
+
}, {
|
|
300
|
+
readonly type: "tuple";
|
|
301
|
+
readonly components: readonly [{
|
|
302
|
+
readonly type: "address";
|
|
303
|
+
}, {
|
|
304
|
+
readonly type: "uint256";
|
|
305
|
+
}, {
|
|
306
|
+
readonly type: "uint256";
|
|
307
|
+
}, {
|
|
308
|
+
readonly type: "uint256";
|
|
309
|
+
}, {
|
|
310
|
+
readonly type: "uint256";
|
|
311
|
+
}];
|
|
312
|
+
readonly name: "q";
|
|
313
|
+
}, {
|
|
314
|
+
readonly type: "bytes";
|
|
315
|
+
readonly name: "sig";
|
|
316
|
+
}];
|
|
317
|
+
readonly outputs: readonly [{
|
|
318
|
+
readonly type: "uint256";
|
|
319
|
+
}];
|
|
320
|
+
}];
|
|
321
|
+
declare const SPLIT_VAULT_ABI: readonly [{
|
|
322
|
+
readonly name: "strike";
|
|
323
|
+
readonly type: "function";
|
|
324
|
+
readonly stateMutability: "view";
|
|
325
|
+
readonly inputs: readonly [];
|
|
326
|
+
readonly outputs: readonly [{
|
|
327
|
+
readonly type: "uint256";
|
|
328
|
+
}];
|
|
329
|
+
}, {
|
|
330
|
+
readonly name: "maturity";
|
|
331
|
+
readonly type: "function";
|
|
332
|
+
readonly stateMutability: "view";
|
|
333
|
+
readonly inputs: readonly [];
|
|
334
|
+
readonly outputs: readonly [{
|
|
335
|
+
readonly type: "uint256";
|
|
336
|
+
}];
|
|
337
|
+
}, {
|
|
338
|
+
readonly name: "exerciseEnd";
|
|
339
|
+
readonly type: "function";
|
|
340
|
+
readonly stateMutability: "view";
|
|
341
|
+
readonly inputs: readonly [];
|
|
342
|
+
readonly outputs: readonly [{
|
|
343
|
+
readonly type: "uint256";
|
|
344
|
+
}];
|
|
345
|
+
}, {
|
|
346
|
+
readonly name: "settled";
|
|
347
|
+
readonly type: "function";
|
|
348
|
+
readonly stateMutability: "view";
|
|
349
|
+
readonly inputs: readonly [];
|
|
350
|
+
readonly outputs: readonly [{
|
|
351
|
+
readonly type: "bool";
|
|
352
|
+
}];
|
|
353
|
+
}, {
|
|
354
|
+
readonly name: "N";
|
|
355
|
+
readonly type: "function";
|
|
356
|
+
readonly stateMutability: "view";
|
|
357
|
+
readonly inputs: readonly [];
|
|
358
|
+
readonly outputs: readonly [{
|
|
359
|
+
readonly type: "address";
|
|
360
|
+
}];
|
|
361
|
+
}];
|
|
362
|
+
declare const ERC20_ABI: readonly [{
|
|
363
|
+
readonly name: "balanceOf";
|
|
364
|
+
readonly type: "function";
|
|
365
|
+
readonly stateMutability: "view";
|
|
366
|
+
readonly inputs: readonly [{
|
|
367
|
+
readonly type: "address";
|
|
368
|
+
}];
|
|
369
|
+
readonly outputs: readonly [{
|
|
370
|
+
readonly type: "uint256";
|
|
371
|
+
}];
|
|
372
|
+
}, {
|
|
373
|
+
readonly name: "approve";
|
|
374
|
+
readonly type: "function";
|
|
375
|
+
readonly stateMutability: "nonpayable";
|
|
376
|
+
readonly inputs: readonly [{
|
|
377
|
+
readonly type: "address";
|
|
378
|
+
readonly name: "spender";
|
|
379
|
+
}, {
|
|
380
|
+
readonly type: "uint256";
|
|
381
|
+
readonly name: "amount";
|
|
382
|
+
}];
|
|
383
|
+
readonly outputs: readonly [{
|
|
384
|
+
readonly type: "bool";
|
|
385
|
+
}];
|
|
386
|
+
}, {
|
|
387
|
+
readonly name: "allowance";
|
|
388
|
+
readonly type: "function";
|
|
389
|
+
readonly stateMutability: "view";
|
|
390
|
+
readonly inputs: readonly [{
|
|
391
|
+
readonly type: "address";
|
|
392
|
+
readonly name: "owner";
|
|
393
|
+
}, {
|
|
394
|
+
readonly type: "address";
|
|
395
|
+
readonly name: "spender";
|
|
396
|
+
}];
|
|
397
|
+
readonly outputs: readonly [{
|
|
398
|
+
readonly type: "uint256";
|
|
399
|
+
}];
|
|
400
|
+
}];
|
|
401
|
+
interface Greeks {
|
|
402
|
+
delta: number;
|
|
403
|
+
gamma: number;
|
|
404
|
+
theta_per_day: number;
|
|
405
|
+
vega: number;
|
|
406
|
+
iv: number;
|
|
407
|
+
spreadBps: number;
|
|
408
|
+
}
|
|
409
|
+
/** The pricer-signed quote, exactly as the quote API returns it. The 5-field tuple
|
|
410
|
+
* [vault, askPerN, bidPerN, validUntil, nonce] + `signature` ride into buyN/sellN. */
|
|
411
|
+
interface SplitQuote {
|
|
412
|
+
desk: Address;
|
|
413
|
+
vault: Address;
|
|
414
|
+
seriesId: number;
|
|
415
|
+
epoch?: number;
|
|
416
|
+
kind?: "call" | "put";
|
|
417
|
+
domainName?: string;
|
|
418
|
+
askPerN: string;
|
|
419
|
+
bidPerN: string;
|
|
420
|
+
validUntil: number;
|
|
421
|
+
nonce: string;
|
|
422
|
+
signature: Hex;
|
|
423
|
+
spot6?: string;
|
|
424
|
+
strike6?: string;
|
|
425
|
+
greeks?: Greeks;
|
|
426
|
+
}
|
|
427
|
+
interface Market {
|
|
428
|
+
seriesId: number;
|
|
429
|
+
vault: Address;
|
|
430
|
+
strike: number;
|
|
431
|
+
leverage: number;
|
|
432
|
+
spot: number;
|
|
433
|
+
premium: number;
|
|
434
|
+
label: string;
|
|
435
|
+
side: Side;
|
|
436
|
+
}
|
|
437
|
+
interface Position {
|
|
438
|
+
qN: number;
|
|
439
|
+
markUsd: number;
|
|
440
|
+
intrinsicUsd: number;
|
|
441
|
+
}
|
|
442
|
+
interface TradeResult {
|
|
443
|
+
txHash: Hex;
|
|
444
|
+
/** N minted (buy) or sold (close), in human contracts. */
|
|
445
|
+
qN: number;
|
|
446
|
+
}
|
|
447
|
+
/** A cached viem public client for a chain. Pass `rpcUrl` to use your own RPC. */
|
|
448
|
+
declare function getPublic(chain: ChainName, rpcUrl?: string): PublicClient;
|
|
449
|
+
/**
|
|
450
|
+
* Read the live grid: current epoch -> every series (seriesAt) -> strike + a quote.
|
|
451
|
+
* Leverage = spot / premium (the ask from the quote API). Returns [] if the pool
|
|
452
|
+
* isn't Trading or has no series. Never throws on a single bad series — it's skipped.
|
|
453
|
+
*/
|
|
454
|
+
declare function getMarkets(chain: ChainName, side: Side, rpcUrl?: string): Promise<Market[]>;
|
|
455
|
+
/**
|
|
456
|
+
* GET /pool-quote?pool=&series=&put=0|1 from the hosted API. The signed quote is
|
|
457
|
+
* valid for ~3 min — fetch it RIGHT BEFORE a trade. The returned tuple + signature
|
|
458
|
+
* are carried verbatim into buyN/sellN; nothing here re-signs.
|
|
459
|
+
*/
|
|
460
|
+
declare function getQuote(chain: ChainName, side: Side, seriesId: number, apiUrl?: string): Promise<SplitQuote>;
|
|
461
|
+
/** The 5-field, vault-first on-chain Quote tuple from a SplitQuote. */
|
|
462
|
+
declare function quoteTuple(q: SplitQuote): readonly [Address, bigint, bigint, bigint, bigint];
|
|
463
|
+
interface BuyArgs {
|
|
464
|
+
chain: ChainName;
|
|
465
|
+
side: Side;
|
|
466
|
+
seriesId: number;
|
|
467
|
+
/** Contracts to buy (human, e.g. 0.5). */
|
|
468
|
+
qN: number;
|
|
469
|
+
walletClient: WalletClient;
|
|
470
|
+
account: Address;
|
|
471
|
+
/** Override the RPC used for reads. */
|
|
472
|
+
rpcUrl?: string;
|
|
473
|
+
/** Pre-fetched quote (else one is fetched fresh). */
|
|
474
|
+
quote?: SplitQuote;
|
|
475
|
+
/** Extra slippage allowance over cost+fee, in bps (default 100 = 1%). */
|
|
476
|
+
slippageBps?: number;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Open a position with the connected wallet (two txs: approve USDC, then buyN).
|
|
480
|
+
*
|
|
481
|
+
* 1. fetch a fresh signed ask quote
|
|
482
|
+
* 2. compute maxCost = cost + fee + slippage (mirrors costWithFee, ceil-rounded)
|
|
483
|
+
* 3. approve USDC -> pool (exact maxCost, if allowance short)
|
|
484
|
+
* 4. pool.buyN(seriesId, qN, maxCost, quoteTuple, sig) -> N mints to the wallet
|
|
485
|
+
*
|
|
486
|
+
* Returns the buyN tx hash + the N minted. Max loss is the premium; no liquidation.
|
|
487
|
+
*/
|
|
488
|
+
declare function buy(args: BuyArgs): Promise<TradeResult>;
|
|
489
|
+
interface CloseArgs {
|
|
490
|
+
chain: ChainName;
|
|
491
|
+
side: Side;
|
|
492
|
+
seriesId: number;
|
|
493
|
+
/** Contracts to close (human). Defaults to the full balance if omitted. */
|
|
494
|
+
qN?: number;
|
|
495
|
+
walletClient: WalletClient;
|
|
496
|
+
account: Address;
|
|
497
|
+
rpcUrl?: string;
|
|
498
|
+
quote?: SplitQuote;
|
|
499
|
+
/** Min-proceeds slippage tolerance below the quoted bid, in bps (default 100 = 1%). */
|
|
500
|
+
slippageBps?: number;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Close (sell N back to the pool) with the connected wallet (approve N, then sellN).
|
|
504
|
+
*
|
|
505
|
+
* 1. fetch a fresh signed bid quote
|
|
506
|
+
* 2. resolve the N token + your balance (close the full balance if qN omitted)
|
|
507
|
+
* 3. minProceeds = (proceeds - fee) - slippage
|
|
508
|
+
* 4. approve N -> pool (if allowance short)
|
|
509
|
+
* 5. pool.sellN(seriesId, qN, minProceeds, quoteTuple, sig) -> USDC to the wallet
|
|
510
|
+
*/
|
|
511
|
+
declare function close(args: CloseArgs): Promise<TradeResult>;
|
|
512
|
+
interface PositionArgs {
|
|
513
|
+
chain: ChainName;
|
|
514
|
+
side: Side;
|
|
515
|
+
seriesId: number;
|
|
516
|
+
account: Address;
|
|
517
|
+
rpcUrl?: string;
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Read the account's position in one series. Mark is at MID = (ask+bid)/2 — a fresh
|
|
521
|
+
* buy reads ≈ −(half-spread), not red by the full spread (this is the honest mark).
|
|
522
|
+
* intrinsicUsd is the settlement floor: a call is worth max(0, spot−strike)·N, a put
|
|
523
|
+
* max(0, strike−spot)·N. After expiry the pool stops bidding -> mark falls back to it.
|
|
524
|
+
*/
|
|
525
|
+
declare function getPosition(args: PositionArgs): Promise<Position>;
|
|
526
|
+
|
|
527
|
+
export { ARB_CHAIN_ID, BASE_CHAIN_ID, type BuyArgs, type BuyGaslessArgs, CHAINS, type ChainConfig, type ChainId, type ChainName, type CloseArgs, type CloseGaslessArgs, ERC20_ABI, type ExecuteCall, FACILITATOR_URL_ARB, FACILITATOR_URL_BASE, type GaslessPosition, type GaslessResult, type Greeks, type Market, NEXUS_BOOTSTRAP, NEXUS_FACTORY, type Position, type PositionArgs, type PositionGaslessArgs, QUOTE_API, SPLIT_POOL_ABI, SPLIT_VAULT_ABI, type Side, type SplitQuote, type TradeResult, type TradingAccount, type UserOp, buy, buyGasless, close, closeGasless, deriveSmartWallet, deriveTradingAccount, facilitatorUrlForChain, getMarkets, getPosition, getPositionGasless, getPublic, getQuote, poolAddress, quoteTuple };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ARB_CHAIN_ID, BASE_CHAIN_ID, CHAINS, ERC20_ABI, FACILITATOR_URL_ARB, FACILITATOR_URL_BASE, NEXUS_BOOTSTRAP, NEXUS_FACTORY, QUOTE_API, SPLIT_POOL_ABI, SPLIT_VAULT_ABI, buy, buyGasless, close, closeGasless, deriveSmartWallet, deriveTradingAccount, facilitatorUrlForChain, getMarkets, getPosition, getPositionGasless, getPublic, getQuote, poolAddress, quoteTuple } from './chunk-MZEPXYHI.js';
|
package/dist/widget.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { WalletClient, Address } from 'viem';
|
|
3
|
+
import { ChainName } from './index.js';
|
|
4
|
+
|
|
5
|
+
/** Brand overrides. Any omitted field falls back to the active theme preset. */
|
|
6
|
+
interface SplitTradeWidgetAppearance {
|
|
7
|
+
/** Primary action / selection accent (buttons, focused tiles). */
|
|
8
|
+
accent?: string;
|
|
9
|
+
/** Widget background. */
|
|
10
|
+
background?: string;
|
|
11
|
+
/** Raised surfaces (inputs, position panel). */
|
|
12
|
+
surface?: string;
|
|
13
|
+
/** Primary text. */
|
|
14
|
+
text?: string;
|
|
15
|
+
/** Secondary / label text. */
|
|
16
|
+
muted?: string;
|
|
17
|
+
/** Corner radius for the card (inner controls scale from it). CSS length or number (px). */
|
|
18
|
+
radius?: string | number;
|
|
19
|
+
/** Font stack. */
|
|
20
|
+
fontFamily?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Execution path. 'gasless' is reserved for the upcoming gasless-core; until it
|
|
23
|
+
* lands the widget transparently runs 'connected'. */
|
|
24
|
+
type SplitTradeWidgetMode = "gasless" | "connected";
|
|
25
|
+
interface SplitTradeWidgetProps {
|
|
26
|
+
/** A connected viem WalletClient (e.g. from wagmi's useWalletClient). */
|
|
27
|
+
walletClient: WalletClient | null | undefined;
|
|
28
|
+
/** The connected account address. */
|
|
29
|
+
account: Address | null | undefined;
|
|
30
|
+
/** Which chain the wallet is on. Default "base". */
|
|
31
|
+
chain?: ChainName;
|
|
32
|
+
/** Base look. Defaults to "dark" (the original styling). */
|
|
33
|
+
theme?: "dark" | "light";
|
|
34
|
+
/** Per-token brand overrides layered on top of `theme`. */
|
|
35
|
+
appearance?: SplitTradeWidgetAppearance;
|
|
36
|
+
/** Extra class on the scoped root (for integrator CSS / utility classes). */
|
|
37
|
+
className?: string;
|
|
38
|
+
/** Execution path. Default "connected" (gasless arrives with gasless-core). */
|
|
39
|
+
mode?: SplitTradeWidgetMode;
|
|
40
|
+
}
|
|
41
|
+
declare function SplitTradeWidget({ walletClient, account, chain, theme, appearance, className, mode, }: SplitTradeWidgetProps): react.JSX.Element;
|
|
42
|
+
|
|
43
|
+
export { SplitTradeWidget, type SplitTradeWidgetAppearance, type SplitTradeWidgetMode, type SplitTradeWidgetProps, SplitTradeWidget as default };
|