@strobelabs/perpcity-sdk 0.3.11 → 0.4.1

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
@@ -95,103 +95,148 @@ var BEACON_ABI = [
95
95
  {
96
96
  inputs: [
97
97
  {
98
- internalType: "contract IVerifierWrapper",
99
- name: "verifierWrapper",
98
+ internalType: "address",
99
+ name: "owner",
100
100
  type: "address"
101
101
  },
102
102
  {
103
- internalType: "uint256",
104
- name: "initialData",
105
- type: "uint256"
103
+ internalType: "contract IVerifierAdapter",
104
+ name: "adapter",
105
+ type: "address"
106
106
  },
107
107
  {
108
- internalType: "uint32",
109
- name: "initialCardinalityNext",
110
- type: "uint32"
108
+ internalType: "contract IIndexEngine",
109
+ name: "engine",
110
+ type: "address"
111
+ },
112
+ {
113
+ internalType: "uint256",
114
+ name: "initialIndex",
115
+ type: "uint256"
111
116
  }
112
117
  ],
113
118
  stateMutability: "nonpayable",
114
119
  type: "constructor"
115
120
  },
116
121
  {
122
+ inputs: [],
123
+ name: "AlreadyInitialized",
124
+ type: "error"
125
+ },
126
+ {
127
+ inputs: [],
128
+ name: "NewOwnerIsZeroAddress",
129
+ type: "error"
130
+ },
131
+ {
132
+ inputs: [],
133
+ name: "NoHandoverRequest",
134
+ type: "error"
135
+ },
136
+ {
137
+ inputs: [],
138
+ name: "Unauthorized",
139
+ type: "error"
140
+ },
141
+ {
142
+ anonymous: false,
117
143
  inputs: [
118
144
  {
119
- internalType: "bytes",
120
- name: "proof",
121
- type: "bytes"
122
- },
123
- {
124
- internalType: "bytes",
125
- name: "publicSignals",
126
- type: "bytes"
145
+ indexed: false,
146
+ internalType: "uint256",
147
+ name: "index",
148
+ type: "uint256"
127
149
  }
128
150
  ],
129
- name: "InvalidProof",
130
- type: "error"
151
+ name: "IndexUpdated",
152
+ type: "event"
131
153
  },
132
154
  {
155
+ anonymous: false,
133
156
  inputs: [
134
157
  {
135
- internalType: "bytes",
136
- name: "proof",
137
- type: "bytes"
138
- },
158
+ indexed: true,
159
+ internalType: "address",
160
+ name: "pendingOwner",
161
+ type: "address"
162
+ }
163
+ ],
164
+ name: "OwnershipHandoverCanceled",
165
+ type: "event"
166
+ },
167
+ {
168
+ anonymous: false,
169
+ inputs: [
139
170
  {
140
- internalType: "bytes",
141
- name: "publicSignals",
142
- type: "bytes"
171
+ indexed: true,
172
+ internalType: "address",
173
+ name: "pendingOwner",
174
+ type: "address"
143
175
  }
144
176
  ],
145
- name: "ProofAlreadyUsed",
146
- type: "error"
177
+ name: "OwnershipHandoverRequested",
178
+ type: "event"
147
179
  },
148
180
  {
149
181
  anonymous: false,
150
182
  inputs: [
151
183
  {
152
- indexed: false,
153
- internalType: "uint256",
154
- name: "data",
155
- type: "uint256"
184
+ indexed: true,
185
+ internalType: "address",
186
+ name: "oldOwner",
187
+ type: "address"
188
+ },
189
+ {
190
+ indexed: true,
191
+ internalType: "address",
192
+ name: "newOwner",
193
+ type: "address"
156
194
  }
157
195
  ],
158
- name: "DataUpdated",
196
+ name: "OwnershipTransferred",
159
197
  type: "event"
160
198
  },
161
199
  {
162
200
  inputs: [],
163
- name: "MAX_DATA",
164
- outputs: [
201
+ name: "cancelOwnershipHandover",
202
+ outputs: [],
203
+ stateMutability: "payable",
204
+ type: "function"
205
+ },
206
+ {
207
+ inputs: [
165
208
  {
166
- internalType: "int256",
167
- name: "",
168
- type: "int256"
209
+ internalType: "address",
210
+ name: "pendingOwner",
211
+ type: "address"
169
212
  }
170
213
  ],
171
- stateMutability: "view",
214
+ name: "completeOwnershipHandover",
215
+ outputs: [],
216
+ stateMutability: "payable",
172
217
  type: "function"
173
218
  },
174
219
  {
175
- inputs: [],
176
- name: "MIN_DATA",
177
- outputs: [
220
+ inputs: [
178
221
  {
179
- internalType: "int256",
180
- name: "",
181
- type: "int256"
222
+ internalType: "uint16",
223
+ name: "newCap",
224
+ type: "uint16"
182
225
  }
183
226
  ],
184
- stateMutability: "view",
227
+ name: "increaseCardinalityCap",
228
+ outputs: [],
229
+ stateMutability: "nonpayable",
185
230
  type: "function"
186
231
  },
187
232
  {
188
233
  inputs: [],
189
- name: "VERIFIER_WRAPPER",
234
+ name: "index",
190
235
  outputs: [
191
236
  {
192
- internalType: "contract IVerifierWrapper",
237
+ internalType: "uint256",
193
238
  name: "",
194
- type: "address"
239
+ type: "uint256"
195
240
  }
196
241
  ],
197
242
  stateMutability: "view",
@@ -199,12 +244,12 @@ var BEACON_ABI = [
199
244
  },
200
245
  {
201
246
  inputs: [],
202
- name: "data",
247
+ name: "indexEngine",
203
248
  outputs: [
204
249
  {
205
- internalType: "uint256",
250
+ internalType: "contract IIndexEngine",
206
251
  name: "",
207
- type: "uint256"
252
+ type: "address"
208
253
  }
209
254
  ],
210
255
  stateMutability: "view",
@@ -212,17 +257,12 @@ var BEACON_ABI = [
212
257
  },
213
258
  {
214
259
  inputs: [],
215
- name: "getData",
260
+ name: "owner",
216
261
  outputs: [
217
262
  {
218
- internalType: "uint256",
219
- name: "",
220
- type: "uint256"
221
- },
222
- {
223
- internalType: "uint256",
224
- name: "",
225
- type: "uint256"
263
+ internalType: "address",
264
+ name: "result",
265
+ type: "address"
226
266
  }
227
267
  ],
228
268
  stateMutability: "view",
@@ -231,49 +271,84 @@ var BEACON_ABI = [
231
271
  {
232
272
  inputs: [
233
273
  {
234
- internalType: "uint32",
235
- name: "twapSecondsAgo",
236
- type: "uint32"
274
+ internalType: "address",
275
+ name: "pendingOwner",
276
+ type: "address"
237
277
  }
238
278
  ],
239
- name: "getTwap",
279
+ name: "ownershipHandoverExpiresAt",
240
280
  outputs: [
241
281
  {
242
282
  internalType: "uint256",
243
- name: "twapPrice",
283
+ name: "result",
244
284
  type: "uint256"
245
285
  }
246
286
  ],
247
287
  stateMutability: "view",
248
288
  type: "function"
249
289
  },
290
+ {
291
+ inputs: [],
292
+ name: "renounceOwnership",
293
+ outputs: [],
294
+ stateMutability: "payable",
295
+ type: "function"
296
+ },
297
+ {
298
+ inputs: [],
299
+ name: "requestOwnershipHandover",
300
+ outputs: [],
301
+ stateMutability: "payable",
302
+ type: "function"
303
+ },
250
304
  {
251
305
  inputs: [
252
306
  {
253
- internalType: "uint32",
254
- name: "cardinalityNext",
255
- type: "uint32"
307
+ internalType: "contract IIndexEngine",
308
+ name: "newIndexEngine",
309
+ type: "address"
256
310
  }
257
311
  ],
258
- name: "increaseCardinalityNext",
259
- outputs: [
260
- {
261
- internalType: "uint32",
262
- name: "cardinalityNextOld",
263
- type: "uint32"
264
- },
312
+ name: "setIndexEngine",
313
+ outputs: [],
314
+ stateMutability: "nonpayable",
315
+ type: "function"
316
+ },
317
+ {
318
+ inputs: [
265
319
  {
266
- internalType: "uint32",
267
- name: "cardinalityNextNew",
268
- type: "uint32"
320
+ internalType: "contract IVerifierAdapter",
321
+ name: "newVerifierAdapter",
322
+ type: "address"
269
323
  }
270
324
  ],
325
+ name: "setVerifierAdapter",
326
+ outputs: [],
271
327
  stateMutability: "nonpayable",
272
328
  type: "function"
273
329
  },
274
330
  {
275
- inputs: [],
276
- name: "timestamp",
331
+ inputs: [
332
+ {
333
+ internalType: "address",
334
+ name: "newOwner",
335
+ type: "address"
336
+ }
337
+ ],
338
+ name: "transferOwnership",
339
+ outputs: [],
340
+ stateMutability: "payable",
341
+ type: "function"
342
+ },
343
+ {
344
+ inputs: [
345
+ {
346
+ internalType: "uint32",
347
+ name: "secondsAgo",
348
+ type: "uint32"
349
+ }
350
+ ],
351
+ name: "twAvg",
277
352
  outputs: [
278
353
  {
279
354
  internalType: "uint256",
@@ -286,22 +361,22 @@ var BEACON_ABI = [
286
361
  },
287
362
  {
288
363
  inputs: [],
289
- name: "twapState",
364
+ name: "twAvgState",
290
365
  outputs: [
291
366
  {
292
- internalType: "uint32",
367
+ internalType: "uint16",
293
368
  name: "index",
294
- type: "uint32"
369
+ type: "uint16"
295
370
  },
296
371
  {
297
- internalType: "uint32",
372
+ internalType: "uint16",
298
373
  name: "cardinality",
299
- type: "uint32"
374
+ type: "uint16"
300
375
  },
301
376
  {
302
- internalType: "uint32",
303
- name: "cardinalityNext",
304
- type: "uint32"
377
+ internalType: "uint16",
378
+ name: "cardinalityCap",
379
+ type: "uint16"
305
380
  }
306
381
  ],
307
382
  stateMutability: "view",
@@ -316,29 +391,23 @@ var BEACON_ABI = [
316
391
  },
317
392
  {
318
393
  internalType: "bytes",
319
- name: "publicSignals",
394
+ name: "inputs",
320
395
  type: "bytes"
321
396
  }
322
397
  ],
323
- name: "updateData",
398
+ name: "updateIndex",
324
399
  outputs: [],
325
400
  stateMutability: "nonpayable",
326
401
  type: "function"
327
402
  },
328
403
  {
329
- inputs: [
330
- {
331
- internalType: "bytes",
332
- name: "",
333
- type: "bytes"
334
- }
335
- ],
336
- name: "usedProofs",
404
+ inputs: [],
405
+ name: "verifierAdapter",
337
406
  outputs: [
338
407
  {
339
- internalType: "bool",
408
+ internalType: "contract IVerifierAdapter",
340
409
  name: "",
341
- type: "bool"
410
+ type: "address"
342
411
  }
343
412
  ],
344
413
  stateMutability: "view",
@@ -384,6 +453,11 @@ var PERP_MANAGER_ABI = [
384
453
  name: "BeaconNotRegistered",
385
454
  type: "error"
386
455
  },
456
+ {
457
+ inputs: [],
458
+ name: "CouldNotFullyFill",
459
+ type: "error"
460
+ },
387
461
  {
388
462
  inputs: [],
389
463
  name: "FeeTooLarge",
@@ -410,36 +484,14 @@ var PERP_MANAGER_ABI = [
410
484
  name: "InvalidCaller",
411
485
  type: "error"
412
486
  },
413
- {
414
- inputs: [
415
- {
416
- internalType: "uint128",
417
- name: "liquidity",
418
- type: "uint128"
419
- }
420
- ],
421
- name: "InvalidLiquidity",
422
- type: "error"
423
- },
424
487
  {
425
488
  inputs: [],
426
489
  name: "InvalidMargin",
427
490
  type: "error"
428
491
  },
429
- {
430
- inputs: [
431
- {
432
- internalType: "uint256",
433
- name: "marginRatio",
434
- type: "uint256"
435
- }
436
- ],
437
- name: "InvalidMarginRatio",
438
- type: "error"
439
- },
440
492
  {
441
493
  inputs: [],
442
- name: "InvalidStartingSqrtPriceX96",
494
+ name: "InvalidMarginRatio",
443
495
  type: "error"
444
496
  },
445
497
  {
@@ -458,40 +510,13 @@ var PERP_MANAGER_ABI = [
458
510
  type: "error"
459
511
  },
460
512
  {
461
- inputs: [
462
- {
463
- internalType: "uint256",
464
- name: "maximumAmount",
465
- type: "uint256"
466
- },
467
- {
468
- internalType: "uint256",
469
- name: "amountRequested",
470
- type: "uint256"
471
- }
472
- ],
513
+ inputs: [],
473
514
  name: "MaximumAmountExceeded",
474
515
  type: "error"
475
516
  },
476
- {
477
- inputs: [
478
- {
479
- internalType: "uint256",
480
- name: "minimumAmount",
481
- type: "uint256"
482
- },
483
- {
484
- internalType: "uint256",
485
- name: "amountReceived",
486
- type: "uint256"
487
- }
488
- ],
489
- name: "MinimumAmountInsufficient",
490
- type: "error"
491
- },
492
517
  {
493
518
  inputs: [],
494
- name: "ModuleAlreadyRegistered",
519
+ name: "MinimumAmountInsufficient",
495
520
  type: "error"
496
521
  },
497
522
  {
@@ -531,17 +556,27 @@ var PERP_MANAGER_ABI = [
531
556
  },
532
557
  {
533
558
  inputs: [],
534
- name: "TokenAlreadyExists",
559
+ name: "StartingSqrtPriceTooHigh",
535
560
  type: "error"
536
561
  },
537
562
  {
538
563
  inputs: [],
539
- name: "TokenDoesNotExist",
564
+ name: "StartingSqrtPriceTooLow",
565
+ type: "error"
566
+ },
567
+ {
568
+ inputs: [],
569
+ name: "TicksOutOfBounds",
570
+ type: "error"
571
+ },
572
+ {
573
+ inputs: [],
574
+ name: "TokenAlreadyExists",
540
575
  type: "error"
541
576
  },
542
577
  {
543
578
  inputs: [],
544
- name: "TransferFromFailed",
579
+ name: "TokenDoesNotExist",
545
580
  type: "error"
546
581
  },
547
582
  {
@@ -569,6 +604,16 @@ var PERP_MANAGER_ABI = [
569
604
  name: "ZeroDelta",
570
605
  type: "error"
571
606
  },
607
+ {
608
+ inputs: [],
609
+ name: "ZeroLiquidity",
610
+ type: "error"
611
+ },
612
+ {
613
+ inputs: [],
614
+ name: "ZeroNotional",
615
+ type: "error"
616
+ },
572
617
  {
573
618
  anonymous: false,
574
619
  inputs: [
@@ -1150,6 +1195,25 @@ var PERP_MANAGER_ABI = [
1150
1195
  stateMutability: "payable",
1151
1196
  type: "function"
1152
1197
  },
1198
+ {
1199
+ inputs: [
1200
+ {
1201
+ internalType: "PoolId",
1202
+ name: "perpId",
1203
+ type: "bytes32"
1204
+ }
1205
+ ],
1206
+ name: "cardinalityCap",
1207
+ outputs: [
1208
+ {
1209
+ internalType: "uint16",
1210
+ name: "",
1211
+ type: "uint16"
1212
+ }
1213
+ ],
1214
+ stateMutability: "view",
1215
+ type: "function"
1216
+ },
1153
1217
  {
1154
1218
  inputs: [
1155
1219
  {
@@ -1630,9 +1694,9 @@ var PERP_MANAGER_ABI = [
1630
1694
  type: "uint128"
1631
1695
  },
1632
1696
  {
1633
- internalType: "uint256",
1634
- name: "levX96",
1635
- type: "uint256"
1697
+ internalType: "uint24",
1698
+ name: "marginRatio",
1699
+ type: "uint24"
1636
1700
  },
1637
1701
  {
1638
1702
  internalType: "uint128",
@@ -1844,9 +1908,9 @@ var PERP_MANAGER_ABI = [
1844
1908
  name: "quoteClosePosition",
1845
1909
  outputs: [
1846
1910
  {
1847
- internalType: "bool",
1848
- name: "success",
1849
- type: "bool"
1911
+ internalType: "bytes",
1912
+ name: "unexpectedReason",
1913
+ type: "bytes"
1850
1914
  },
1851
1915
  {
1852
1916
  internalType: "int256",
@@ -1925,9 +1989,9 @@ var PERP_MANAGER_ABI = [
1925
1989
  name: "quoteOpenMakerPosition",
1926
1990
  outputs: [
1927
1991
  {
1928
- internalType: "bool",
1929
- name: "success",
1930
- type: "bool"
1992
+ internalType: "bytes",
1993
+ name: "unexpectedReason",
1994
+ type: "bytes"
1931
1995
  },
1932
1996
  {
1933
1997
  internalType: "int256",
@@ -1968,9 +2032,9 @@ var PERP_MANAGER_ABI = [
1968
2032
  type: "uint128"
1969
2033
  },
1970
2034
  {
1971
- internalType: "uint256",
1972
- name: "levX96",
1973
- type: "uint256"
2035
+ internalType: "uint24",
2036
+ name: "marginRatio",
2037
+ type: "uint24"
1974
2038
  },
1975
2039
  {
1976
2040
  internalType: "uint128",
@@ -1986,9 +2050,9 @@ var PERP_MANAGER_ABI = [
1986
2050
  name: "quoteOpenTakerPosition",
1987
2051
  outputs: [
1988
2052
  {
1989
- internalType: "bool",
1990
- name: "success",
1991
- type: "bool"
2053
+ internalType: "bytes",
2054
+ name: "unexpectedReason",
2055
+ type: "bytes"
1992
2056
  },
1993
2057
  {
1994
2058
  internalType: "int256",
@@ -3298,8 +3362,8 @@ var PerpCityContext = class {
3298
3362
  functionName: "quoteClosePosition",
3299
3363
  args: [positionId]
3300
3364
  });
3301
- const [success, pnl, funding, netMargin, wasLiquidated] = result;
3302
- if (!success) {
3365
+ const [unexpectedReason, pnl, funding, netMargin, wasLiquidated] = result;
3366
+ if (unexpectedReason !== "0x") {
3303
3367
  throw new Error(
3304
3368
  `Failed to quote position ${positionId} - position may be invalid or already closed`
3305
3369
  );
@@ -3465,8 +3529,8 @@ var OpenPosition = class _OpenPosition {
3465
3529
  functionName: "quoteClosePosition",
3466
3530
  args: [this.positionId]
3467
3531
  });
3468
- const [success, pnl, funding, netMargin, wasLiquidated] = result;
3469
- if (!success) {
3532
+ const [unexpectedReason, pnl, funding, netMargin, wasLiquidated] = result;
3533
+ if (unexpectedReason !== "0x") {
3470
3534
  throw new Error(
3471
3535
  `Failed to quote position ${this.positionId} - position may be invalid or already closed`
3472
3536
  );
@@ -3556,13 +3620,13 @@ async function openTakerPosition(context, perpId, params) {
3556
3620
  }
3557
3621
  const marginScaled = scale6Decimals(params.margin);
3558
3622
  await approveUsdc(context, marginScaled);
3559
- const levX96 = scaleToX96(params.leverage);
3623
+ const marginRatio = Math.floor(NUMBER_1E6 / params.leverage);
3560
3624
  const unspecifiedAmountLimit = typeof params.unspecifiedAmountLimit === "bigint" ? params.unspecifiedAmountLimit : scale6Decimals(params.unspecifiedAmountLimit);
3561
3625
  const contractParams = {
3562
3626
  holder: context.walletClient.account.address,
3563
3627
  isLong: params.isLong,
3564
3628
  margin: marginScaled,
3565
- levX96,
3629
+ marginRatio,
3566
3630
  unspecifiedAmountLimit
3567
3631
  };
3568
3632
  const { request } = await context.publicClient.simulateContract({
@@ -3749,8 +3813,8 @@ async function getPositionLiveDetailsFromContract(context, _perpId, positionId)
3749
3813
  functionName: "quoteClosePosition",
3750
3814
  args: [positionId]
3751
3815
  });
3752
- const [success, pnl, funding, netMargin, wasLiquidated] = result;
3753
- if (!success) {
3816
+ const [unexpectedReason, pnl, funding, netMargin, wasLiquidated] = result;
3817
+ if (unexpectedReason !== "0x") {
3754
3818
  throw new Error(
3755
3819
  `Failed to quote position ${positionId} - position may be invalid or already closed`
3756
3820
  );