@strobelabs/perpcity-sdk 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -20,21 +20,32 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ BEACON_ABI: () => BEACON_ABI,
24
+ DECIMAL_PRECISION_6: () => DECIMAL_PRECISION_6,
25
+ GOLDSKY_BASE_SEPOLIA_URL: () => GOLDSKY_BASE_SEPOLIA_URL,
26
+ PERP_MANAGER_ABI: () => PERP_MANAGER_ABI,
27
+ PERP_MANAGER_BASE_SEPOLIA_ADDRESS: () => PERP_MANAGER_BASE_SEPOLIA_ADDRESS,
23
28
  Perp: () => Perp,
24
29
  PerpCityContext: () => PerpCityContext,
25
30
  PerpManager: () => PerpManager,
31
+ Position: () => Position,
32
+ Q96: () => Q96,
33
+ approveUsdc: () => approveUsdc,
34
+ estimateLiquidity: () => estimateLiquidity,
35
+ getUsdcAddress: () => getUsdcAddress,
26
36
  priceToSqrtPriceX96: () => priceToSqrtPriceX96,
37
+ priceToTick: () => priceToTick,
27
38
  scale6Decimals: () => scale6Decimals,
28
39
  scaleX96: () => scaleX96
29
40
  });
30
41
  module.exports = __toCommonJS(index_exports);
31
42
 
32
43
  // src/context.ts
44
+ var import_viem = require("viem");
33
45
  var import_graphql_request = require("graphql-request");
34
46
  var PerpCityContext = class {
35
47
  constructor(config) {
36
- this.publicClient = config.publicClient;
37
- this.walletClient = config.walletClient;
48
+ this.walletClient = config.walletClient.extend(import_viem.publicActions);
38
49
  this.goldskyClient = new import_graphql_request.GraphQLClient(config.goldskyEndpoint);
39
50
  this.perpManagerAddress = config.perpManagerAddress;
40
51
  this.perpManagerAbi = config.perpManagerAbi;
@@ -42,6 +53,39 @@ var PerpCityContext = class {
42
53
  }
43
54
  };
44
55
 
56
+ // src/entities/perp.ts
57
+ var import_viem4 = require("viem");
58
+
59
+ // src/entities/position.ts
60
+ var Position = class {
61
+ constructor(context, perpId, positionId) {
62
+ this.context = context;
63
+ this.perpId = perpId;
64
+ this.positionId = positionId;
65
+ }
66
+ // async closePosition(params: ClosePositionParams): Promise<Position | null> {
67
+ // const contractParams = {
68
+ // positionId: this.positionId,
69
+ // minAmt0Out: scale6Decimals(params.minAmt0Out),
70
+ // minAmt1Out: scale6Decimals(params.minAmt1Out),
71
+ // maxAmt1In: scale6Decimals(params.maxAmt1In),
72
+ // };
73
+ // const { result, request } = await this.context.walletClient.extend(publicActions).simulateContract({
74
+ // address: this.context.perpManagerAddress,
75
+ // abi: this.context.perpManagerAbi,
76
+ // functionName: 'closePosition',
77
+ // args: [this.perpId, contractParams],
78
+ // account: this.context.walletClient.account,
79
+ // });
80
+ // await this.context.walletClient.writeContract(request);
81
+ // const takerPositionId = result[0];
82
+ // if (takerPositionId === 0n) {
83
+ // return null;
84
+ // }
85
+ // return new Position(this.context, this.perpId, takerPositionId);
86
+ // }
87
+ };
88
+
45
89
  // src/utils/constants.ts
46
90
  var DECIMAL_PRECISION_6 = 1e6;
47
91
  var Q96 = 79228162514264337593543950336n;
@@ -63,56 +107,87 @@ function scale6Decimals(amount) {
63
107
  function scaleX96(amount) {
64
108
  return BigInt(scale6Decimals(amount)) * Q96 / BigInt(DECIMAL_PRECISION_6);
65
109
  }
110
+ function priceToTick(price, roundDown) {
111
+ const logSqrtPrice = Math.log(Math.sqrt(price)) / Math.log(1.0001);
112
+ return roundDown ? Math.floor(logSqrtPrice) : Math.ceil(logSqrtPrice);
113
+ }
66
114
 
67
- // src/entities/position.ts
68
- var Position = class _Position {
69
- constructor(context, perpId, positionId) {
70
- this.context = context;
71
- this.perpId = perpId;
72
- this.positionId = positionId;
73
- }
74
- async closePosition(params) {
75
- const contractParams = {
76
- positionId: this.positionId,
77
- minAmt0Out: scale6Decimals(params.minAmt0Out),
78
- minAmt1Out: scale6Decimals(params.minAmt1Out),
79
- maxAmt1In: scale6Decimals(params.maxAmt1In)
80
- };
81
- const { result, request } = await this.context.publicClient.simulateContract({
82
- address: this.context.perpManagerAddress,
83
- abi: this.context.perpManagerAbi,
84
- functionName: "closePosition",
85
- args: [this.perpId, contractParams],
86
- account: this.context.walletClient.account
87
- });
88
- await this.context.walletClient.writeContract(request);
89
- const takerPositionId = result[0];
90
- if (takerPositionId === 0n) {
91
- return null;
92
- }
93
- return new _Position(this.context, this.perpId, takerPositionId);
94
- }
95
- };
115
+ // src/utils/approve.ts
116
+ var import_viem2 = require("viem");
117
+ async function approveUsdc(context, amount) {
118
+ const usdcAddress = await getUsdcAddress(context);
119
+ const { request } = await context.walletClient.extend(import_viem2.publicActions).simulateContract({
120
+ address: usdcAddress,
121
+ abi: import_viem2.erc20Abi,
122
+ functionName: "approve",
123
+ args: [context.perpManagerAddress, amount],
124
+ account: context.walletClient.account
125
+ });
126
+ const hash = await context.walletClient.writeContract(request);
127
+ await context.walletClient.extend(import_viem2.publicActions).waitForTransactionReceipt({
128
+ confirmations: 2,
129
+ hash
130
+ });
131
+ }
132
+ async function getUsdcAddress(context) {
133
+ return await context.walletClient.extend(import_viem2.publicActions).readContract({
134
+ address: context.perpManagerAddress,
135
+ abi: context.perpManagerAbi,
136
+ functionName: "USDC"
137
+ });
138
+ }
139
+
140
+ // src/utils/liquidity.ts
141
+ var import_viem3 = require("viem");
142
+ async function estimateLiquidity(context, tickLower, tickUpper, usdScaled) {
143
+ return await context.walletClient.extend(import_viem3.publicActions).readContract({
144
+ address: context.perpManagerAddress,
145
+ abi: context.perpManagerAbi,
146
+ functionName: "estimateLiquidityForAount1",
147
+ args: [tickLower, tickUpper, usdScaled]
148
+ });
149
+ }
96
150
 
97
151
  // src/entities/perp.ts
152
+ var import_v3_sdk = require("@uniswap/v3-sdk");
98
153
  var Perp = class {
99
154
  constructor(context, id) {
100
155
  this.context = context;
101
156
  this.id = id;
102
157
  }
103
158
  // READS
159
+ async getTickSpacing() {
160
+ const tickSpacing = await this.context.walletClient.extend(import_viem4.publicActions).readContract({
161
+ address: this.context.perpManagerAddress,
162
+ abi: this.context.perpManagerAbi,
163
+ functionName: "tickSpacing",
164
+ args: [this.id]
165
+ });
166
+ return Number(tickSpacing);
167
+ }
104
168
  // WRITES
105
- // TODO: read tickspacing from perp to adjust tickLower and tickUpper
169
+ async approveAndOpenMakerPosition(params) {
170
+ await approveUsdc(this.context, scale6Decimals(params.margin));
171
+ return await this.openMakerPosition(params);
172
+ }
173
+ async approveAndOpenTakerPosition(params) {
174
+ await approveUsdc(this.context, scale6Decimals(params.margin));
175
+ return await this.openTakerPosition(params);
176
+ }
106
177
  async openMakerPosition(params) {
178
+ const tickSpacing = await this.getTickSpacing();
179
+ const scaledUsd = scale6Decimals(params.margin);
180
+ const tickLower = BigInt((0, import_v3_sdk.nearestUsableTick)(priceToTick(params.priceLower, true), tickSpacing));
181
+ const tickUpper = BigInt((0, import_v3_sdk.nearestUsableTick)(priceToTick(params.priceUpper, false), tickSpacing));
107
182
  const contractParams = {
108
- margin: scale6Decimals(params.margin),
109
- liquidity: BigInt(params.liquidity),
110
- tickLower: BigInt(params.tickLower),
111
- tickUpper: BigInt(params.tickUpper),
183
+ margin: scaledUsd,
184
+ liquidity: await estimateLiquidity(this.context, tickLower, tickUpper, scaledUsd),
185
+ tickLower,
186
+ tickUpper,
112
187
  maxAmt0In: scale6Decimals(params.maxAmt0In),
113
188
  maxAmt1In: scale6Decimals(params.maxAmt1In)
114
189
  };
115
- const { result, request } = await this.context.publicClient.simulateContract({
190
+ const { result, request } = await this.context.walletClient.extend(import_viem4.publicActions).simulateContract({
116
191
  address: this.context.perpManagerAddress,
117
192
  abi: this.context.perpManagerAbi,
118
193
  functionName: "openMakerPosition",
@@ -120,16 +195,16 @@ var Perp = class {
120
195
  account: this.context.walletClient.account
121
196
  });
122
197
  await this.context.walletClient.writeContract(request);
123
- return new Position(this.context, this.id, result[0]);
198
+ return new Position(this.context, this.id, result);
124
199
  }
125
200
  async openTakerPosition(params) {
126
201
  const contractParams = {
127
202
  isLong: params.isLong,
128
203
  margin: scale6Decimals(params.margin),
129
- leverage: scaleX96(params.leverage),
204
+ levX96: scaleX96(params.leverage),
130
205
  unspecifiedAmountLimit: scale6Decimals(params.unspecifiedAmountLimit)
131
206
  };
132
- const { result, request } = await this.context.publicClient.simulateContract({
207
+ const { result, request } = await this.context.walletClient.extend(import_viem4.publicActions).simulateContract({
133
208
  address: this.context.perpManagerAddress,
134
209
  abi: this.context.perpManagerAbi,
135
210
  functionName: "openTakerPosition",
@@ -137,7 +212,7 @@ var Perp = class {
137
212
  account: this.context.walletClient.account
138
213
  });
139
214
  await this.context.walletClient.writeContract(request);
140
- return new Position(this.context, this.id, result[0]);
215
+ return new Position(this.context, this.id, result);
141
216
  }
142
217
  };
143
218
 
@@ -150,6 +225,7 @@ var PerpCollection = class {
150
225
  };
151
226
 
152
227
  // src/entities/perp-manager.ts
228
+ var import_viem5 = require("viem");
153
229
  var import_graphql_request2 = require("graphql-request");
154
230
  var import_graphql = require("graphql");
155
231
  var PerpManager = class {
@@ -174,23 +250,1301 @@ var PerpManager = class {
174
250
  // WRITES
175
251
  async createPerp(params) {
176
252
  const sqrtPriceX96 = priceToSqrtPriceX96(params.startingPrice);
177
- const { result, request } = await this.context.publicClient.simulateContract({
253
+ const contractParams = {
254
+ startingSqrtPriceX96: sqrtPriceX96,
255
+ beacon: params.beacon
256
+ };
257
+ const { result, request } = await this.context.walletClient.extend(import_viem5.publicActions).simulateContract({
178
258
  address: this.context.perpManagerAddress,
179
259
  abi: this.context.perpManagerAbi,
180
260
  functionName: "createPerp",
181
- args: [sqrtPriceX96, params.beacon],
182
- account: this.context.walletClient.account
261
+ args: [contractParams],
262
+ account: this.context.walletClient.account,
263
+ chain: this.context.walletClient.chain
183
264
  });
184
265
  await this.context.walletClient.writeContract(request);
185
- return new Perp(this.context, result[0]);
266
+ return new Perp(this.context, result);
186
267
  }
187
268
  };
269
+
270
+ // src/addresses.ts
271
+ var PERP_MANAGER_BASE_SEPOLIA_ADDRESS = "0xA25aF834AA93Fe5Dca241955AF2383F04374c000";
272
+
273
+ // src/endpoints.ts
274
+ var GOLDSKY_BASE_SEPOLIA_URL = "https://api.goldsky.com/api/public/project_cmbawn40q70fj01ws4jmsfj7f/subgraphs/perp-city/3fe61683-20250915_170731/gn";
275
+
276
+ // src/abis/perp-manager.ts
277
+ var PERP_MANAGER_ABI = [
278
+ {
279
+ "inputs": [
280
+ {
281
+ "internalType": "contract IPoolManager",
282
+ "name": "poolManager",
283
+ "type": "address"
284
+ },
285
+ {
286
+ "internalType": "address",
287
+ "name": "usdc",
288
+ "type": "address"
289
+ }
290
+ ],
291
+ "stateMutability": "nonpayable",
292
+ "type": "constructor"
293
+ },
294
+ {
295
+ "inputs": [
296
+ {
297
+ "internalType": "uint8",
298
+ "name": "action",
299
+ "type": "uint8"
300
+ }
301
+ ],
302
+ "name": "InvalidAction",
303
+ "type": "error"
304
+ },
305
+ {
306
+ "inputs": [
307
+ {
308
+ "internalType": "address",
309
+ "name": "caller",
310
+ "type": "address"
311
+ },
312
+ {
313
+ "internalType": "address",
314
+ "name": "expectedCaller",
315
+ "type": "address"
316
+ }
317
+ ],
318
+ "name": "InvalidCaller",
319
+ "type": "error"
320
+ },
321
+ {
322
+ "inputs": [
323
+ {
324
+ "internalType": "address",
325
+ "name": "caller",
326
+ "type": "address"
327
+ },
328
+ {
329
+ "internalType": "address",
330
+ "name": "holder",
331
+ "type": "address"
332
+ },
333
+ {
334
+ "internalType": "bool",
335
+ "name": "isLiquidated",
336
+ "type": "bool"
337
+ }
338
+ ],
339
+ "name": "InvalidClose",
340
+ "type": "error"
341
+ },
342
+ {
343
+ "inputs": [
344
+ {
345
+ "internalType": "uint128",
346
+ "name": "liquidity",
347
+ "type": "uint128"
348
+ }
349
+ ],
350
+ "name": "InvalidLiquidity",
351
+ "type": "error"
352
+ },
353
+ {
354
+ "inputs": [
355
+ {
356
+ "internalType": "uint256",
357
+ "name": "margin",
358
+ "type": "uint256"
359
+ }
360
+ ],
361
+ "name": "InvalidMargin",
362
+ "type": "error"
363
+ },
364
+ {
365
+ "inputs": [
366
+ {
367
+ "internalType": "uint256",
368
+ "name": "currentTimestamp",
369
+ "type": "uint256"
370
+ },
371
+ {
372
+ "internalType": "uint256",
373
+ "name": "lockupPeriodEnd",
374
+ "type": "uint256"
375
+ }
376
+ ],
377
+ "name": "MakerPositionLocked",
378
+ "type": "error"
379
+ },
380
+ {
381
+ "inputs": [
382
+ {
383
+ "internalType": "uint256",
384
+ "name": "maximumAmount",
385
+ "type": "uint256"
386
+ },
387
+ {
388
+ "internalType": "uint256",
389
+ "name": "amountRequested",
390
+ "type": "uint256"
391
+ }
392
+ ],
393
+ "name": "MaximumAmountExceeded",
394
+ "type": "error"
395
+ },
396
+ {
397
+ "inputs": [
398
+ {
399
+ "internalType": "uint256",
400
+ "name": "minimumAmount",
401
+ "type": "uint256"
402
+ },
403
+ {
404
+ "internalType": "uint256",
405
+ "name": "amountReceived",
406
+ "type": "uint256"
407
+ }
408
+ ],
409
+ "name": "MinimumAmountInsufficient",
410
+ "type": "error"
411
+ },
412
+ {
413
+ "inputs": [],
414
+ "name": "NotPoolManager",
415
+ "type": "error"
416
+ },
417
+ {
418
+ "inputs": [
419
+ {
420
+ "internalType": "bytes",
421
+ "name": "reason",
422
+ "type": "bytes"
423
+ }
424
+ ],
425
+ "name": "UnexpectedRevertBytes",
426
+ "type": "error"
427
+ },
428
+ {
429
+ "anonymous": false,
430
+ "inputs": [
431
+ {
432
+ "indexed": false,
433
+ "internalType": "PoolId",
434
+ "name": "perpId",
435
+ "type": "bytes32"
436
+ },
437
+ {
438
+ "indexed": false,
439
+ "internalType": "uint256",
440
+ "name": "posId",
441
+ "type": "uint256"
442
+ },
443
+ {
444
+ "indexed": false,
445
+ "internalType": "uint256",
446
+ "name": "newMargin",
447
+ "type": "uint256"
448
+ }
449
+ ],
450
+ "name": "MarginAdded",
451
+ "type": "event"
452
+ },
453
+ {
454
+ "anonymous": false,
455
+ "inputs": [
456
+ {
457
+ "indexed": false,
458
+ "internalType": "PoolId",
459
+ "name": "perpId",
460
+ "type": "bytes32"
461
+ },
462
+ {
463
+ "indexed": false,
464
+ "internalType": "address",
465
+ "name": "beacon",
466
+ "type": "address"
467
+ },
468
+ {
469
+ "indexed": false,
470
+ "internalType": "uint256",
471
+ "name": "startingSqrtPriceX96",
472
+ "type": "uint256"
473
+ }
474
+ ],
475
+ "name": "PerpCreated",
476
+ "type": "event"
477
+ },
478
+ {
479
+ "anonymous": false,
480
+ "inputs": [
481
+ {
482
+ "indexed": false,
483
+ "internalType": "PoolId",
484
+ "name": "perpId",
485
+ "type": "bytes32"
486
+ },
487
+ {
488
+ "indexed": false,
489
+ "internalType": "uint256",
490
+ "name": "posId",
491
+ "type": "uint256"
492
+ },
493
+ {
494
+ "indexed": false,
495
+ "internalType": "bool",
496
+ "name": "wasLiquidated",
497
+ "type": "bool"
498
+ },
499
+ {
500
+ "indexed": false,
501
+ "internalType": "uint256",
502
+ "name": "sqrtPriceX96",
503
+ "type": "uint256"
504
+ }
505
+ ],
506
+ "name": "PositionClosed",
507
+ "type": "event"
508
+ },
509
+ {
510
+ "anonymous": false,
511
+ "inputs": [
512
+ {
513
+ "indexed": false,
514
+ "internalType": "PoolId",
515
+ "name": "perpId",
516
+ "type": "bytes32"
517
+ },
518
+ {
519
+ "indexed": false,
520
+ "internalType": "uint256",
521
+ "name": "posId",
522
+ "type": "uint256"
523
+ },
524
+ {
525
+ "indexed": false,
526
+ "internalType": "bool",
527
+ "name": "isMaker",
528
+ "type": "bool"
529
+ },
530
+ {
531
+ "indexed": false,
532
+ "internalType": "uint256",
533
+ "name": "margin",
534
+ "type": "uint256"
535
+ },
536
+ {
537
+ "indexed": false,
538
+ "internalType": "uint256",
539
+ "name": "sqrtPriceX96",
540
+ "type": "uint256"
541
+ }
542
+ ],
543
+ "name": "PositionOpened",
544
+ "type": "event"
545
+ },
546
+ {
547
+ "inputs": [],
548
+ "name": "POOL_MANAGER",
549
+ "outputs": [
550
+ {
551
+ "internalType": "contract IPoolManager",
552
+ "name": "",
553
+ "type": "address"
554
+ }
555
+ ],
556
+ "stateMutability": "view",
557
+ "type": "function"
558
+ },
559
+ {
560
+ "inputs": [],
561
+ "name": "USDC",
562
+ "outputs": [
563
+ {
564
+ "internalType": "address",
565
+ "name": "",
566
+ "type": "address"
567
+ }
568
+ ],
569
+ "stateMutability": "view",
570
+ "type": "function"
571
+ },
572
+ {
573
+ "inputs": [
574
+ {
575
+ "internalType": "PoolId",
576
+ "name": "perpId",
577
+ "type": "bytes32"
578
+ },
579
+ {
580
+ "components": [
581
+ {
582
+ "internalType": "uint128",
583
+ "name": "posId",
584
+ "type": "uint128"
585
+ },
586
+ {
587
+ "internalType": "uint256",
588
+ "name": "margin",
589
+ "type": "uint256"
590
+ }
591
+ ],
592
+ "internalType": "struct IPerpManager.AddMarginParams",
593
+ "name": "params",
594
+ "type": "tuple"
595
+ }
596
+ ],
597
+ "name": "addMargin",
598
+ "outputs": [],
599
+ "stateMutability": "nonpayable",
600
+ "type": "function"
601
+ },
602
+ {
603
+ "inputs": [
604
+ {
605
+ "internalType": "PoolId",
606
+ "name": "perpId",
607
+ "type": "bytes32"
608
+ },
609
+ {
610
+ "components": [
611
+ {
612
+ "internalType": "uint128",
613
+ "name": "posId",
614
+ "type": "uint128"
615
+ },
616
+ {
617
+ "internalType": "uint128",
618
+ "name": "minAmt0Out",
619
+ "type": "uint128"
620
+ },
621
+ {
622
+ "internalType": "uint128",
623
+ "name": "minAmt1Out",
624
+ "type": "uint128"
625
+ },
626
+ {
627
+ "internalType": "uint128",
628
+ "name": "maxAmt1In",
629
+ "type": "uint128"
630
+ }
631
+ ],
632
+ "internalType": "struct IPerpManager.ClosePositionParams",
633
+ "name": "params",
634
+ "type": "tuple"
635
+ }
636
+ ],
637
+ "name": "closePosition",
638
+ "outputs": [
639
+ {
640
+ "internalType": "uint128",
641
+ "name": "posId",
642
+ "type": "uint128"
643
+ }
644
+ ],
645
+ "stateMutability": "nonpayable",
646
+ "type": "function"
647
+ },
648
+ {
649
+ "inputs": [
650
+ {
651
+ "components": [
652
+ {
653
+ "internalType": "uint160",
654
+ "name": "startingSqrtPriceX96",
655
+ "type": "uint160"
656
+ },
657
+ {
658
+ "internalType": "address",
659
+ "name": "beacon",
660
+ "type": "address"
661
+ }
662
+ ],
663
+ "internalType": "struct IPerpManager.CreatePerpParams",
664
+ "name": "params",
665
+ "type": "tuple"
666
+ }
667
+ ],
668
+ "name": "createPerp",
669
+ "outputs": [
670
+ {
671
+ "internalType": "PoolId",
672
+ "name": "perpId",
673
+ "type": "bytes32"
674
+ }
675
+ ],
676
+ "stateMutability": "nonpayable",
677
+ "type": "function"
678
+ },
679
+ {
680
+ "inputs": [
681
+ {
682
+ "internalType": "int24",
683
+ "name": "tickA",
684
+ "type": "int24"
685
+ },
686
+ {
687
+ "internalType": "int24",
688
+ "name": "tickB",
689
+ "type": "int24"
690
+ },
691
+ {
692
+ "internalType": "uint256",
693
+ "name": "amount1",
694
+ "type": "uint256"
695
+ }
696
+ ],
697
+ "name": "estimateLiquidityForAount1",
698
+ "outputs": [
699
+ {
700
+ "internalType": "uint128",
701
+ "name": "liquidity",
702
+ "type": "uint128"
703
+ }
704
+ ],
705
+ "stateMutability": "pure",
706
+ "type": "function"
707
+ },
708
+ {
709
+ "inputs": [
710
+ {
711
+ "internalType": "PoolId",
712
+ "name": "perpId",
713
+ "type": "bytes32"
714
+ },
715
+ {
716
+ "internalType": "uint128",
717
+ "name": "posId",
718
+ "type": "uint128"
719
+ }
720
+ ],
721
+ "name": "getPosition",
722
+ "outputs": [
723
+ {
724
+ "components": [
725
+ {
726
+ "internalType": "address",
727
+ "name": "holder",
728
+ "type": "address"
729
+ },
730
+ {
731
+ "internalType": "uint256",
732
+ "name": "margin",
733
+ "type": "uint256"
734
+ },
735
+ {
736
+ "internalType": "int256",
737
+ "name": "perpDelta",
738
+ "type": "int256"
739
+ },
740
+ {
741
+ "internalType": "int256",
742
+ "name": "usdDelta",
743
+ "type": "int256"
744
+ },
745
+ {
746
+ "internalType": "int256",
747
+ "name": "entryTwPremiumX96",
748
+ "type": "int256"
749
+ },
750
+ {
751
+ "components": [
752
+ {
753
+ "internalType": "uint32",
754
+ "name": "entryTimestamp",
755
+ "type": "uint32"
756
+ },
757
+ {
758
+ "internalType": "int24",
759
+ "name": "tickLower",
760
+ "type": "int24"
761
+ },
762
+ {
763
+ "internalType": "int24",
764
+ "name": "tickUpper",
765
+ "type": "int24"
766
+ },
767
+ {
768
+ "internalType": "uint128",
769
+ "name": "liquidity",
770
+ "type": "uint128"
771
+ },
772
+ {
773
+ "internalType": "int256",
774
+ "name": "entryTwPremiumGrowthInsideX96",
775
+ "type": "int256"
776
+ },
777
+ {
778
+ "internalType": "int256",
779
+ "name": "entryTwPremiumDivBySqrtPriceGrowthInsideX96",
780
+ "type": "int256"
781
+ },
782
+ {
783
+ "internalType": "int256",
784
+ "name": "entryTwPremiumGrowthBelowX96",
785
+ "type": "int256"
786
+ }
787
+ ],
788
+ "internalType": "struct IPerpManager.MakerDetails",
789
+ "name": "makerDetails",
790
+ "type": "tuple"
791
+ }
792
+ ],
793
+ "internalType": "struct IPerpManager.Position",
794
+ "name": "",
795
+ "type": "tuple"
796
+ }
797
+ ],
798
+ "stateMutability": "view",
799
+ "type": "function"
800
+ },
801
+ {
802
+ "inputs": [
803
+ {
804
+ "internalType": "PoolId",
805
+ "name": "perpId",
806
+ "type": "bytes32"
807
+ },
808
+ {
809
+ "internalType": "uint32",
810
+ "name": "secondsAgo",
811
+ "type": "uint32"
812
+ }
813
+ ],
814
+ "name": "getTimeWeightedAvg",
815
+ "outputs": [
816
+ {
817
+ "internalType": "uint256",
818
+ "name": "",
819
+ "type": "uint256"
820
+ }
821
+ ],
822
+ "stateMutability": "view",
823
+ "type": "function"
824
+ },
825
+ {
826
+ "inputs": [
827
+ {
828
+ "internalType": "PoolId",
829
+ "name": "perpId",
830
+ "type": "bytes32"
831
+ },
832
+ {
833
+ "internalType": "uint32",
834
+ "name": "cardinalityNext",
835
+ "type": "uint32"
836
+ }
837
+ ],
838
+ "name": "increaseCardinalityNext",
839
+ "outputs": [],
840
+ "stateMutability": "nonpayable",
841
+ "type": "function"
842
+ },
843
+ {
844
+ "inputs": [
845
+ {
846
+ "internalType": "PoolId",
847
+ "name": "perpId",
848
+ "type": "bytes32"
849
+ },
850
+ {
851
+ "internalType": "uint128",
852
+ "name": "posId",
853
+ "type": "uint128"
854
+ }
855
+ ],
856
+ "name": "livePositionDetails",
857
+ "outputs": [
858
+ {
859
+ "internalType": "int256",
860
+ "name": "pnl",
861
+ "type": "int256"
862
+ },
863
+ {
864
+ "internalType": "int256",
865
+ "name": "fundingPayment",
866
+ "type": "int256"
867
+ },
868
+ {
869
+ "internalType": "int256",
870
+ "name": "effectiveMargin",
871
+ "type": "int256"
872
+ },
873
+ {
874
+ "internalType": "bool",
875
+ "name": "isLiquidatable",
876
+ "type": "bool"
877
+ },
878
+ {
879
+ "internalType": "uint256",
880
+ "name": "newPriceX96",
881
+ "type": "uint256"
882
+ }
883
+ ],
884
+ "stateMutability": "nonpayable",
885
+ "type": "function"
886
+ },
887
+ {
888
+ "inputs": [
889
+ {
890
+ "internalType": "PoolId",
891
+ "name": "perpId",
892
+ "type": "bytes32"
893
+ },
894
+ {
895
+ "components": [
896
+ {
897
+ "internalType": "uint256",
898
+ "name": "margin",
899
+ "type": "uint256"
900
+ },
901
+ {
902
+ "internalType": "uint128",
903
+ "name": "liquidity",
904
+ "type": "uint128"
905
+ },
906
+ {
907
+ "internalType": "int24",
908
+ "name": "tickLower",
909
+ "type": "int24"
910
+ },
911
+ {
912
+ "internalType": "int24",
913
+ "name": "tickUpper",
914
+ "type": "int24"
915
+ },
916
+ {
917
+ "internalType": "uint128",
918
+ "name": "maxAmt0In",
919
+ "type": "uint128"
920
+ },
921
+ {
922
+ "internalType": "uint128",
923
+ "name": "maxAmt1In",
924
+ "type": "uint128"
925
+ }
926
+ ],
927
+ "internalType": "struct IPerpManager.OpenMakerPositionParams",
928
+ "name": "params",
929
+ "type": "tuple"
930
+ }
931
+ ],
932
+ "name": "openMakerPosition",
933
+ "outputs": [
934
+ {
935
+ "internalType": "uint128",
936
+ "name": "makerPosId",
937
+ "type": "uint128"
938
+ }
939
+ ],
940
+ "stateMutability": "nonpayable",
941
+ "type": "function"
942
+ },
943
+ {
944
+ "inputs": [
945
+ {
946
+ "internalType": "PoolId",
947
+ "name": "perpId",
948
+ "type": "bytes32"
949
+ },
950
+ {
951
+ "components": [
952
+ {
953
+ "internalType": "bool",
954
+ "name": "isLong",
955
+ "type": "bool"
956
+ },
957
+ {
958
+ "internalType": "uint256",
959
+ "name": "margin",
960
+ "type": "uint256"
961
+ },
962
+ {
963
+ "internalType": "uint256",
964
+ "name": "levX96",
965
+ "type": "uint256"
966
+ },
967
+ {
968
+ "internalType": "uint128",
969
+ "name": "unspecifiedAmountLimit",
970
+ "type": "uint128"
971
+ }
972
+ ],
973
+ "internalType": "struct IPerpManager.OpenTakerPositionParams",
974
+ "name": "params",
975
+ "type": "tuple"
976
+ }
977
+ ],
978
+ "name": "openTakerPosition",
979
+ "outputs": [
980
+ {
981
+ "internalType": "uint128",
982
+ "name": "takerPosId",
983
+ "type": "uint128"
984
+ }
985
+ ],
986
+ "stateMutability": "nonpayable",
987
+ "type": "function"
988
+ },
989
+ {
990
+ "inputs": [
991
+ {
992
+ "internalType": "PoolId",
993
+ "name": "",
994
+ "type": "bytes32"
995
+ }
996
+ ],
997
+ "name": "perps",
998
+ "outputs": [
999
+ {
1000
+ "internalType": "address",
1001
+ "name": "vault",
1002
+ "type": "address"
1003
+ },
1004
+ {
1005
+ "internalType": "address",
1006
+ "name": "beacon",
1007
+ "type": "address"
1008
+ },
1009
+ {
1010
+ "internalType": "address",
1011
+ "name": "creator",
1012
+ "type": "address"
1013
+ },
1014
+ {
1015
+ "internalType": "uint32",
1016
+ "name": "creationTimestamp",
1017
+ "type": "uint32"
1018
+ },
1019
+ {
1020
+ "internalType": "uint32",
1021
+ "name": "makerLockupPeriod",
1022
+ "type": "uint32"
1023
+ },
1024
+ {
1025
+ "internalType": "uint32",
1026
+ "name": "twapWindow",
1027
+ "type": "uint32"
1028
+ },
1029
+ {
1030
+ "internalType": "uint32",
1031
+ "name": "lastTwPremiumsUpdate",
1032
+ "type": "uint32"
1033
+ },
1034
+ {
1035
+ "internalType": "uint24",
1036
+ "name": "creatorFee",
1037
+ "type": "uint24"
1038
+ },
1039
+ {
1040
+ "internalType": "uint24",
1041
+ "name": "insuranceFee",
1042
+ "type": "uint24"
1043
+ },
1044
+ {
1045
+ "internalType": "uint24",
1046
+ "name": "liquidationFee",
1047
+ "type": "uint24"
1048
+ },
1049
+ {
1050
+ "internalType": "uint24",
1051
+ "name": "liquidatorFeeSplit",
1052
+ "type": "uint24"
1053
+ },
1054
+ {
1055
+ "internalType": "uint128",
1056
+ "name": "nextPosId",
1057
+ "type": "uint128"
1058
+ },
1059
+ {
1060
+ "internalType": "uint256",
1061
+ "name": "sqrtPriceLowerMultiX96",
1062
+ "type": "uint256"
1063
+ },
1064
+ {
1065
+ "internalType": "uint256",
1066
+ "name": "sqrtPriceUpperMultiX96",
1067
+ "type": "uint256"
1068
+ },
1069
+ {
1070
+ "internalType": "uint24",
1071
+ "name": "minOpeningMargin",
1072
+ "type": "uint24"
1073
+ },
1074
+ {
1075
+ "internalType": "uint24",
1076
+ "name": "minMakerOpeningMarginRatio",
1077
+ "type": "uint24"
1078
+ },
1079
+ {
1080
+ "internalType": "uint24",
1081
+ "name": "maxMakerOpeningMarginRatio",
1082
+ "type": "uint24"
1083
+ },
1084
+ {
1085
+ "internalType": "uint24",
1086
+ "name": "makerLiquidationMarginRatio",
1087
+ "type": "uint24"
1088
+ },
1089
+ {
1090
+ "internalType": "uint24",
1091
+ "name": "minTakerOpeningMarginRatio",
1092
+ "type": "uint24"
1093
+ },
1094
+ {
1095
+ "internalType": "uint24",
1096
+ "name": "maxTakerOpeningMarginRatio",
1097
+ "type": "uint24"
1098
+ },
1099
+ {
1100
+ "internalType": "uint24",
1101
+ "name": "takerLiquidationMarginRatio",
1102
+ "type": "uint24"
1103
+ },
1104
+ {
1105
+ "internalType": "int256",
1106
+ "name": "twPremiumX96",
1107
+ "type": "int256"
1108
+ },
1109
+ {
1110
+ "internalType": "int256",
1111
+ "name": "twPremiumDivBySqrtPriceX96",
1112
+ "type": "int256"
1113
+ },
1114
+ {
1115
+ "internalType": "int256",
1116
+ "name": "premiumPerSecondX96",
1117
+ "type": "int256"
1118
+ },
1119
+ {
1120
+ "components": [
1121
+ {
1122
+ "internalType": "Currency",
1123
+ "name": "currency0",
1124
+ "type": "address"
1125
+ },
1126
+ {
1127
+ "internalType": "Currency",
1128
+ "name": "currency1",
1129
+ "type": "address"
1130
+ },
1131
+ {
1132
+ "internalType": "uint24",
1133
+ "name": "fee",
1134
+ "type": "uint24"
1135
+ },
1136
+ {
1137
+ "internalType": "int24",
1138
+ "name": "tickSpacing",
1139
+ "type": "int24"
1140
+ },
1141
+ {
1142
+ "internalType": "contract IHooks",
1143
+ "name": "hooks",
1144
+ "type": "address"
1145
+ }
1146
+ ],
1147
+ "internalType": "struct PoolKey",
1148
+ "name": "key",
1149
+ "type": "tuple"
1150
+ },
1151
+ {
1152
+ "components": [
1153
+ {
1154
+ "internalType": "uint128",
1155
+ "name": "baseFeeX96",
1156
+ "type": "uint128"
1157
+ },
1158
+ {
1159
+ "internalType": "uint128",
1160
+ "name": "startFeeX96",
1161
+ "type": "uint128"
1162
+ },
1163
+ {
1164
+ "internalType": "uint128",
1165
+ "name": "targetFeeX96",
1166
+ "type": "uint128"
1167
+ },
1168
+ {
1169
+ "internalType": "uint128",
1170
+ "name": "decay",
1171
+ "type": "uint128"
1172
+ },
1173
+ {
1174
+ "internalType": "uint128",
1175
+ "name": "volatilityScalerX96",
1176
+ "type": "uint128"
1177
+ },
1178
+ {
1179
+ "internalType": "uint128",
1180
+ "name": "maxFeeMultiplierX96",
1181
+ "type": "uint128"
1182
+ }
1183
+ ],
1184
+ "internalType": "struct TradingFee.Config",
1185
+ "name": "tradingFeeConfig",
1186
+ "type": "tuple"
1187
+ },
1188
+ {
1189
+ "components": [
1190
+ {
1191
+ "internalType": "uint32",
1192
+ "name": "index",
1193
+ "type": "uint32"
1194
+ },
1195
+ {
1196
+ "internalType": "uint32",
1197
+ "name": "cardinality",
1198
+ "type": "uint32"
1199
+ },
1200
+ {
1201
+ "internalType": "uint32",
1202
+ "name": "cardinalityNext",
1203
+ "type": "uint32"
1204
+ },
1205
+ {
1206
+ "components": [
1207
+ {
1208
+ "internalType": "uint32",
1209
+ "name": "blockTimestamp",
1210
+ "type": "uint32"
1211
+ },
1212
+ {
1213
+ "internalType": "uint216",
1214
+ "name": "cumulativeValue",
1215
+ "type": "uint216"
1216
+ },
1217
+ {
1218
+ "internalType": "bool",
1219
+ "name": "initialized",
1220
+ "type": "bool"
1221
+ }
1222
+ ],
1223
+ "internalType": "struct TimeWeightedAvg.Observation[65535]",
1224
+ "name": "observations",
1225
+ "type": "tuple[65535]"
1226
+ }
1227
+ ],
1228
+ "internalType": "struct TimeWeightedAvg.State",
1229
+ "name": "twapState",
1230
+ "type": "tuple"
1231
+ }
1232
+ ],
1233
+ "stateMutability": "view",
1234
+ "type": "function"
1235
+ },
1236
+ {
1237
+ "inputs": [
1238
+ {
1239
+ "internalType": "PoolId",
1240
+ "name": "perpId",
1241
+ "type": "bytes32"
1242
+ }
1243
+ ],
1244
+ "name": "tickSpacing",
1245
+ "outputs": [
1246
+ {
1247
+ "internalType": "int24",
1248
+ "name": "",
1249
+ "type": "int24"
1250
+ }
1251
+ ],
1252
+ "stateMutability": "view",
1253
+ "type": "function"
1254
+ },
1255
+ {
1256
+ "inputs": [
1257
+ {
1258
+ "internalType": "bytes",
1259
+ "name": "data",
1260
+ "type": "bytes"
1261
+ }
1262
+ ],
1263
+ "name": "unlockCallback",
1264
+ "outputs": [
1265
+ {
1266
+ "internalType": "bytes",
1267
+ "name": "encodedDelta",
1268
+ "type": "bytes"
1269
+ }
1270
+ ],
1271
+ "stateMutability": "nonpayable",
1272
+ "type": "function"
1273
+ }
1274
+ ];
1275
+
1276
+ // src/abis/beacon.ts
1277
+ var BEACON_ABI = [
1278
+ {
1279
+ "inputs": [
1280
+ {
1281
+ "internalType": "contract IVerifierWrapper",
1282
+ "name": "verifierWrapper",
1283
+ "type": "address"
1284
+ },
1285
+ {
1286
+ "internalType": "uint256",
1287
+ "name": "initialData",
1288
+ "type": "uint256"
1289
+ },
1290
+ {
1291
+ "internalType": "uint32",
1292
+ "name": "initialCardinalityNext",
1293
+ "type": "uint32"
1294
+ }
1295
+ ],
1296
+ "stateMutability": "nonpayable",
1297
+ "type": "constructor"
1298
+ },
1299
+ {
1300
+ "inputs": [
1301
+ {
1302
+ "internalType": "bytes",
1303
+ "name": "proof",
1304
+ "type": "bytes"
1305
+ },
1306
+ {
1307
+ "internalType": "bytes",
1308
+ "name": "publicSignals",
1309
+ "type": "bytes"
1310
+ }
1311
+ ],
1312
+ "name": "InvalidProof",
1313
+ "type": "error"
1314
+ },
1315
+ {
1316
+ "inputs": [
1317
+ {
1318
+ "internalType": "bytes",
1319
+ "name": "proof",
1320
+ "type": "bytes"
1321
+ },
1322
+ {
1323
+ "internalType": "bytes",
1324
+ "name": "publicSignals",
1325
+ "type": "bytes"
1326
+ }
1327
+ ],
1328
+ "name": "ProofAlreadyUsed",
1329
+ "type": "error"
1330
+ },
1331
+ {
1332
+ "anonymous": false,
1333
+ "inputs": [
1334
+ {
1335
+ "indexed": false,
1336
+ "internalType": "uint256",
1337
+ "name": "data",
1338
+ "type": "uint256"
1339
+ }
1340
+ ],
1341
+ "name": "DataUpdated",
1342
+ "type": "event"
1343
+ },
1344
+ {
1345
+ "inputs": [],
1346
+ "name": "MAX_DATA",
1347
+ "outputs": [
1348
+ {
1349
+ "internalType": "int256",
1350
+ "name": "",
1351
+ "type": "int256"
1352
+ }
1353
+ ],
1354
+ "stateMutability": "view",
1355
+ "type": "function"
1356
+ },
1357
+ {
1358
+ "inputs": [],
1359
+ "name": "MIN_DATA",
1360
+ "outputs": [
1361
+ {
1362
+ "internalType": "int256",
1363
+ "name": "",
1364
+ "type": "int256"
1365
+ }
1366
+ ],
1367
+ "stateMutability": "view",
1368
+ "type": "function"
1369
+ },
1370
+ {
1371
+ "inputs": [],
1372
+ "name": "VERIFIER_WRAPPER",
1373
+ "outputs": [
1374
+ {
1375
+ "internalType": "contract IVerifierWrapper",
1376
+ "name": "",
1377
+ "type": "address"
1378
+ }
1379
+ ],
1380
+ "stateMutability": "view",
1381
+ "type": "function"
1382
+ },
1383
+ {
1384
+ "inputs": [],
1385
+ "name": "data",
1386
+ "outputs": [
1387
+ {
1388
+ "internalType": "uint256",
1389
+ "name": "",
1390
+ "type": "uint256"
1391
+ }
1392
+ ],
1393
+ "stateMutability": "view",
1394
+ "type": "function"
1395
+ },
1396
+ {
1397
+ "inputs": [],
1398
+ "name": "getData",
1399
+ "outputs": [
1400
+ {
1401
+ "internalType": "uint256",
1402
+ "name": "",
1403
+ "type": "uint256"
1404
+ },
1405
+ {
1406
+ "internalType": "uint256",
1407
+ "name": "",
1408
+ "type": "uint256"
1409
+ }
1410
+ ],
1411
+ "stateMutability": "view",
1412
+ "type": "function"
1413
+ },
1414
+ {
1415
+ "inputs": [
1416
+ {
1417
+ "internalType": "uint32",
1418
+ "name": "twapSecondsAgo",
1419
+ "type": "uint32"
1420
+ }
1421
+ ],
1422
+ "name": "getTwap",
1423
+ "outputs": [
1424
+ {
1425
+ "internalType": "uint256",
1426
+ "name": "twapPrice",
1427
+ "type": "uint256"
1428
+ }
1429
+ ],
1430
+ "stateMutability": "view",
1431
+ "type": "function"
1432
+ },
1433
+ {
1434
+ "inputs": [
1435
+ {
1436
+ "internalType": "uint32",
1437
+ "name": "cardinalityNext",
1438
+ "type": "uint32"
1439
+ }
1440
+ ],
1441
+ "name": "increaseCardinalityNext",
1442
+ "outputs": [
1443
+ {
1444
+ "internalType": "uint32",
1445
+ "name": "cardinalityNextOld",
1446
+ "type": "uint32"
1447
+ },
1448
+ {
1449
+ "internalType": "uint32",
1450
+ "name": "cardinalityNextNew",
1451
+ "type": "uint32"
1452
+ }
1453
+ ],
1454
+ "stateMutability": "nonpayable",
1455
+ "type": "function"
1456
+ },
1457
+ {
1458
+ "inputs": [],
1459
+ "name": "timestamp",
1460
+ "outputs": [
1461
+ {
1462
+ "internalType": "uint256",
1463
+ "name": "",
1464
+ "type": "uint256"
1465
+ }
1466
+ ],
1467
+ "stateMutability": "view",
1468
+ "type": "function"
1469
+ },
1470
+ {
1471
+ "inputs": [],
1472
+ "name": "twapState",
1473
+ "outputs": [
1474
+ {
1475
+ "internalType": "uint32",
1476
+ "name": "index",
1477
+ "type": "uint32"
1478
+ },
1479
+ {
1480
+ "internalType": "uint32",
1481
+ "name": "cardinality",
1482
+ "type": "uint32"
1483
+ },
1484
+ {
1485
+ "internalType": "uint32",
1486
+ "name": "cardinalityNext",
1487
+ "type": "uint32"
1488
+ }
1489
+ ],
1490
+ "stateMutability": "view",
1491
+ "type": "function"
1492
+ },
1493
+ {
1494
+ "inputs": [
1495
+ {
1496
+ "internalType": "bytes",
1497
+ "name": "proof",
1498
+ "type": "bytes"
1499
+ },
1500
+ {
1501
+ "internalType": "bytes",
1502
+ "name": "publicSignals",
1503
+ "type": "bytes"
1504
+ }
1505
+ ],
1506
+ "name": "updateData",
1507
+ "outputs": [],
1508
+ "stateMutability": "nonpayable",
1509
+ "type": "function"
1510
+ },
1511
+ {
1512
+ "inputs": [
1513
+ {
1514
+ "internalType": "bytes",
1515
+ "name": "",
1516
+ "type": "bytes"
1517
+ }
1518
+ ],
1519
+ "name": "usedProofs",
1520
+ "outputs": [
1521
+ {
1522
+ "internalType": "bool",
1523
+ "name": "",
1524
+ "type": "bool"
1525
+ }
1526
+ ],
1527
+ "stateMutability": "view",
1528
+ "type": "function"
1529
+ }
1530
+ ];
188
1531
  // Annotate the CommonJS export names for ESM import in node:
189
1532
  0 && (module.exports = {
1533
+ BEACON_ABI,
1534
+ DECIMAL_PRECISION_6,
1535
+ GOLDSKY_BASE_SEPOLIA_URL,
1536
+ PERP_MANAGER_ABI,
1537
+ PERP_MANAGER_BASE_SEPOLIA_ADDRESS,
190
1538
  Perp,
191
1539
  PerpCityContext,
192
1540
  PerpManager,
1541
+ Position,
1542
+ Q96,
1543
+ approveUsdc,
1544
+ estimateLiquidity,
1545
+ getUsdcAddress,
193
1546
  priceToSqrtPriceX96,
1547
+ priceToTick,
194
1548
  scale6Decimals,
195
1549
  scaleX96
196
1550
  });