@parchment-trade/sdk 0.0.0-stage → 1.0.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.
Files changed (95) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +193 -2
  3. package/REFERENCE.md +338 -0
  4. package/SECURITY.md +25 -0
  5. package/dist/general/providers/index.d.ts +2 -0
  6. package/dist/general/providers/index.js +2 -0
  7. package/dist/general/providers/parchment.d.ts +1 -0
  8. package/dist/general/providers/parchment.js +1 -0
  9. package/dist/general/providers/parchmentSdk.d.ts +23 -0
  10. package/dist/general/providers/parchmentSdk.js +11 -0
  11. package/dist/general/types/configTypes.d.ts +62 -0
  12. package/dist/general/types/configTypes.js +1 -0
  13. package/dist/general/types/index.d.ts +1 -0
  14. package/dist/general/types/index.js +1 -0
  15. package/dist/general/utils/address.d.ts +49 -0
  16. package/dist/general/utils/address.js +110 -0
  17. package/dist/general/utils/caller.d.ts +58 -0
  18. package/dist/general/utils/caller.js +182 -0
  19. package/dist/general/utils/errors.d.ts +16 -0
  20. package/dist/general/utils/errors.js +26 -0
  21. package/dist/general/utils/index.d.ts +4 -0
  22. package/dist/general/utils/index.js +4 -0
  23. package/dist/general/utils/jsBigInt.d.ts +26 -0
  24. package/dist/general/utils/jsBigInt.js +74 -0
  25. package/dist/general/utils/txShape.d.ts +8 -0
  26. package/dist/general/utils/txShape.js +39 -0
  27. package/dist/index.d.ts +4 -0
  28. package/dist/index.js +4 -0
  29. package/dist/packages/index.d.ts +11 -0
  30. package/dist/packages/index.js +5 -0
  31. package/dist/packages/parchment/abortCodes.d.ts +196 -0
  32. package/dist/packages/parchment/abortCodes.js +522 -0
  33. package/dist/packages/parchment/batchClose.d.ts +268 -0
  34. package/dist/packages/parchment/batchClose.js +524 -0
  35. package/dist/packages/parchment/eventGuard.d.ts +106 -0
  36. package/dist/packages/parchment/eventGuard.js +119 -0
  37. package/dist/packages/parchment/gameCounterEvents.d.ts +59 -0
  38. package/dist/packages/parchment/gameCounterEvents.js +56 -0
  39. package/dist/packages/parchment/index.d.ts +52 -0
  40. package/dist/packages/parchment/index.js +30 -0
  41. package/dist/packages/parchment/liquidationCredit.d.ts +28 -0
  42. package/dist/packages/parchment/liquidationCredit.js +25 -0
  43. package/dist/packages/parchment/lockedMintEvents.d.ts +42 -0
  44. package/dist/packages/parchment/lockedMintEvents.js +46 -0
  45. package/dist/packages/parchment/monitoring.d.ts +369 -0
  46. package/dist/packages/parchment/monitoring.js +259 -0
  47. package/dist/packages/parchment/notes.d.ts +6 -0
  48. package/dist/packages/parchment/notes.js +1 -0
  49. package/dist/packages/parchment/onboarding.d.ts +50 -0
  50. package/dist/packages/parchment/onboarding.js +48 -0
  51. package/dist/packages/parchment/orderEffects.d.ts +207 -0
  52. package/dist/packages/parchment/orderEffects.js +268 -0
  53. package/dist/packages/parchment/orderParams.d.ts +72 -0
  54. package/dist/packages/parchment/orderParams.js +71 -0
  55. package/dist/packages/parchment/packageIds.d.ts +53 -0
  56. package/dist/packages/parchment/packageIds.js +149 -0
  57. package/dist/packages/parchment/parchment.d.ts +442 -0
  58. package/dist/packages/parchment/parchment.js +975 -0
  59. package/dist/packages/parchment/parchmentAccount.d.ts +189 -0
  60. package/dist/packages/parchment/parchmentAccount.js +273 -0
  61. package/dist/packages/parchment/parchmentMarket.d.ts +58 -0
  62. package/dist/packages/parchment/parchmentMarket.js +86 -0
  63. package/dist/packages/parchment/parchmentTypes.d.ts +2031 -0
  64. package/dist/packages/parchment/parchmentTypes.js +65 -0
  65. package/dist/packages/parchment/publicInts.d.ts +45 -0
  66. package/dist/packages/parchment/publicInts.js +383 -0
  67. package/dist/packages/parchment/reconcileEvents.d.ts +24 -0
  68. package/dist/packages/parchment/reconcileEvents.js +30 -0
  69. package/dist/packages/parchment/retainedFee.d.ts +43 -0
  70. package/dist/packages/parchment/retainedFee.js +68 -0
  71. package/dist/packages/parchment/sessionClose.d.ts +68 -0
  72. package/dist/packages/parchment/sessionClose.js +50 -0
  73. package/dist/packages/parchment/sessionKey.d.ts +78 -0
  74. package/dist/packages/parchment/sessionKey.js +154 -0
  75. package/dist/packages/parchment/slippage.d.ts +23 -0
  76. package/dist/packages/parchment/slippage.js +27 -0
  77. package/dist/packages/parchment/sponsor.d.ts +39 -0
  78. package/dist/packages/parchment/sponsor.js +48 -0
  79. package/dist/packages/parchment/stakingCalls.d.ts +33 -0
  80. package/dist/packages/parchment/stakingCalls.js +21 -0
  81. package/dist/packages/parchment/stakingEvents.d.ts +53 -0
  82. package/dist/packages/parchment/stakingEvents.js +71 -0
  83. package/dist/packages/parchment/triggerCalls.d.ts +46 -0
  84. package/dist/packages/parchment/triggerCalls.js +36 -0
  85. package/dist/packages/parchment/triggerEvents.d.ts +22 -0
  86. package/dist/packages/parchment/triggerEvents.js +33 -0
  87. package/dist/packages/parchment/triggers.d.ts +113 -0
  88. package/dist/packages/parchment/triggers.js +183 -0
  89. package/dist/packages/parchment/txBodies.d.ts +111 -0
  90. package/dist/packages/parchment/txBodies.js +683 -0
  91. package/dist/packages/parchment/txIntent.d.ts +99 -0
  92. package/dist/packages/parchment/txIntent.js +611 -0
  93. package/dist/types.d.ts +2 -0
  94. package/dist/types.js +1 -0
  95. package/package.json +58 -4
@@ -0,0 +1,522 @@
1
+ export const TRADE_RESERVED_ABORT_CODES = [26, 30];
2
+ export const ORDER_RESERVED_ABORT_CODES = [18, 23];
3
+ export const ORACLE_RESERVED_ABORT_CODES = [3, 18];
4
+ export const DECLARED_NOT_RAISED_ABORT_CODES = {
5
+ trade: [0, 10, 16],
6
+ order: [1],
7
+ oracle: [0],
8
+ };
9
+ export const TRADE_ABORT_MESSAGES = {
10
+ 20: "This market's price feed (oracle) is off: nothing can open, close or be liquidated until it is back",
11
+ 22: "Close pause: the current contracts do not raise this; closes and liquidation run under every pause",
12
+ 31: "Price moved beyond your slippage limit",
13
+ 32: "Price moved beyond your slippage limit",
14
+ 35: "Session closed: positions are being closed, try again when it reopens",
15
+ };
16
+ export const TRADE_ABORT_NAMES = {
17
+ 0: "EBadVersion",
18
+ 1: "ETradingPaused",
19
+ 2: "EMarketNotActive",
20
+ 3: "EOracleNotNewer",
21
+ 4: "ELeverage",
22
+ 5: "ENotionalBounds",
23
+ 6: "ETxNotionalCap",
24
+ 7: "EBlockNotionalCap",
25
+ 8: "EAccountNotional",
26
+ 9: "EOiCap",
27
+ 10: "ELpInsolvent",
28
+ 11: "EInsufficientMargin",
29
+ 12: "ESameCheckpoint",
30
+ 13: "EMinHold",
31
+ 14: "EPositionLiquidatable",
32
+ 15: "ENotLiquidatable",
33
+ 16: "ENotAuthorized",
34
+ 17: "EMarketMismatch",
35
+ 18: "EUseDebtDeferred",
36
+ 19: "ENotRetired",
37
+ 20: "EOracleKilled",
38
+ 21: "EMarketDisabled",
39
+ 22: "EClosesPaused",
40
+ 23: "EFactorWorse",
41
+ 24: "EMinLeverage",
42
+ 25: "EMarketClosed",
43
+ 27: "EBustAtOpen",
44
+ 28: "ENotInBook",
45
+ 29: "EOiNotionalCap",
46
+ 31: "EEntryPriceWorse",
47
+ 32: "EExitPriceWorse",
48
+ 33: "ESessionNotArmed",
49
+ 34: "EBatchTooLarge",
50
+ 35: "ESessionClosePending",
51
+ 36: "EKeeperOnlyLiquidation",
52
+ 37: "EWrongAccount",
53
+ };
54
+ export function tradeAbortMessage(code) {
55
+ const n = decodeAbortCode(code);
56
+ return n !== undefined && Object.hasOwn(TRADE_ABORT_MESSAGES, n) ? TRADE_ABORT_MESSAGES[n] : undefined;
57
+ }
58
+ export const ORDER_ABORT_NAMES = {
59
+ 0: "ENotKeeper",
60
+ 1: "ENotAuthorized",
61
+ 2: "EAccountMismatch",
62
+ 3: "EMarketMismatch",
63
+ 4: "EWrongKind",
64
+ 5: "EPriceBeforeRequest",
65
+ 6: "EPriceAfterWindow",
66
+ 7: "EFillDeadline",
67
+ 8: "ECancelTooEarly",
68
+ 9: "ENotExpired",
69
+ 10: "EEmergencyTooEarly",
70
+ 11: "ETooManyOrders",
71
+ 12: "EDuplicateClose",
72
+ 14: "EInsufficientFree",
73
+ 15: "ERequestsPaused",
74
+ 16: "EPositionNotFound",
75
+ 17: "EMinHold",
76
+ 19: "EBelowMinMargin",
77
+ 20: "ESessionDrainPending",
78
+ 21: "ENoSessionSnapshot",
79
+ 22: "ENotSessionPending",
80
+ 24: "ECleanupNotBlocked",
81
+ 25: "EPriceFromFuture",
82
+ 26: "EBadMinFactor",
83
+ 27: "ETopUpExceedsFee",
84
+ 28: "EDelegateExpiresBeforeDeadline",
85
+ 29: "EExecFeeAboveMax",
86
+ 30: "ENeedsSignedEvidence",
87
+ 31: "ECloseStale",
88
+ };
89
+ export const ORDER_ABORT_MESSAGES = {
90
+ ENotKeeper: "Only an authorized keeper can fill this order",
91
+ ENotAuthorized: "You are not authorized to act on this account's orders",
92
+ EAccountMismatch: "This order belongs to a different account",
93
+ EMarketMismatch: "This order belongs to a different market",
94
+ EWrongKind: "This action does not match the order type (open vs close)",
95
+ EPriceBeforeRequest: "The oracle price was published at or before the order request; a later price is needed",
96
+ EPriceAfterWindow: "The signed oracle price is outside the order's signed fill window",
97
+ EFillDeadline: "The order's fill deadline has passed; it can only be expired",
98
+ ECancelTooEarly: "This order cannot be cancelled yet; wait for the cancel delay",
99
+ ENotExpired: "This order cannot be expired yet; a close also waits out its emergency window",
100
+ EEmergencyTooEarly: "Emergency close is not available yet; wait for the emergency window, then use a price published after it",
101
+ ETooManyOrders: "Too many pending orders; wait for one to fill or cancel it",
102
+ EDuplicateClose: "A close request is already pending for this position",
103
+ EBelowMinMargin: "Margin after fees is below the market minimum; add margin",
104
+ ECleanupNotBlocked: "No halted cleanup is pending for this account on that market",
105
+ ESessionDrainPending: "Positions are closing at session end; open again shortly",
106
+ ENoSessionSnapshot: "No session snapshot on this market",
107
+ ENotSessionPending: "Order is not pending across a session close",
108
+ EPriceFromFuture: "The oracle price is timestamped after the chain clock; a keeper will retry with a current price",
109
+ EBadMinFactor: "The minimum payout factor cannot exceed 10,000 bps (100%)",
110
+ ETopUpExceedsFee: "Deposits are paused: the top-up can only cover the missing execution fee",
111
+ EDelegateExpiresBeforeDeadline: "This trading session expires before the order could fill; renew the session and try again",
112
+ EExecFeeAboveMax: "The execution fee changed since you reviewed this order; review it again",
113
+ ENeedsSignedEvidence: "This order needs a signed oracle update to expire; try again shortly",
114
+ ECloseStale: "The automatic close arrived after its deadline and did not run; it is retried with a fresh price",
115
+ EInsufficientFree: "Not enough free balance for margin plus the execution fee",
116
+ ERequestsPaused: "This market is not taking new orders (paused, reduce-only, retired or oracle off); on a retired market use close-retired",
117
+ EPositionNotFound: "This position is not open in this account and market (it may have been closed or liquidated)",
118
+ EMinHold: "This position cannot be closed yet; the minimum hold has not elapsed",
119
+ };
120
+ const CLEVER_TAG = 1n << 63n;
121
+ const CLEVER_HAS_CODE = 1n << 62n;
122
+ const CLEVER_NO_CODE = 0xffn;
123
+ export function decodeAbortCode(raw) {
124
+ if (typeof raw === "string" && !/^\d+$/.test(raw))
125
+ return undefined;
126
+ let v;
127
+ try {
128
+ v = BigInt(raw);
129
+ }
130
+ catch {
131
+ return undefined;
132
+ }
133
+ if (v < 0n || v >= 1n << 64n)
134
+ return undefined;
135
+ if ((v & CLEVER_TAG) !== 0n && (v & CLEVER_HAS_CODE) !== 0n) {
136
+ const code = (v >> 48n) & 0xffn;
137
+ return code === CLEVER_NO_CODE ? undefined : Number(code);
138
+ }
139
+ return v <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(v) : undefined;
140
+ }
141
+ export function orderAbortName(code) {
142
+ const n = decodeAbortCode(code);
143
+ return n === undefined ? undefined : ORDER_ABORT_NAMES[n];
144
+ }
145
+ export function orderAbortMessage(nameOrCode) {
146
+ if (typeof nameOrCode === "string" && !/^\d+$/.test(nameOrCode)) {
147
+ return Object.prototype.hasOwnProperty.call(ORDER_ABORT_MESSAGES, nameOrCode)
148
+ ? ORDER_ABORT_MESSAGES[nameOrCode]
149
+ : undefined;
150
+ }
151
+ const name = orderAbortName(nameOrCode);
152
+ return name === undefined ? undefined : ORDER_ABORT_MESSAGES[name];
153
+ }
154
+ export const MARKET_ABORT_NAMES = {
155
+ 0: "EBadVersion",
156
+ 1: "EBadPin",
157
+ 2: "EBadParam",
158
+ 3: "EAlreadyShared",
159
+ 4: "ENotConfigured",
160
+ 5: "EKeeperRaise",
161
+ 6: "EOracleRetargetWithOi",
162
+ 7: "EWrongExchange",
163
+ 8: "ETxBelowMinNotional",
164
+ 9: "EBucketMissing",
165
+ 10: "EBadEmergencyAfter",
166
+ };
167
+ export const FEE_MINT_ABORT_NAMES = {
168
+ 0: "EAccountMismatch",
169
+ 1: "EMintOverflow",
170
+ 2: "EWrongMintWitness",
171
+ };
172
+ export const EXCHANGE_ABORT_NAMES = {
173
+ 0: "EBadVersion",
174
+ 1: "EVault",
175
+ 2: "ENotUsdc",
176
+ 3: "EZero",
177
+ 4: "ENoTreasury",
178
+ 5: "ETreasurySet",
179
+ 6: "ESweepTooSoon",
180
+ 7: "ENoSurplus",
181
+ 8: "ECheckIncomplete",
182
+ 9: "ECheckExchange",
183
+ 11: "ECheckStale",
184
+ 12: "EReceiptMismatch",
185
+ 13: "ETreasuryMinted",
186
+ 14: "EHarvestAuth",
187
+ 15: "ETreasuryUsed",
188
+ 16: "EWrongCoinWitness",
189
+ };
190
+ export const ACCESS_ABORT_NAMES = {
191
+ 0: "EUnregisteredWitness",
192
+ 1: "EExtensionsSealed",
193
+ 2: "ENoExtensionProposal",
194
+ 3: "EExtensionNotReady",
195
+ 4: "ENotOnConfig",
196
+ 5: "EAlreadyRegistered",
197
+ 6: "EAuthNotBound",
198
+ 7: "ENotPrimaryWitness",
199
+ 8: "ERetiredImplementation",
200
+ 9: "EVersionNotNewer",
201
+ };
202
+ export const BUILDER_BOOK_ABORT_NAMES = {
203
+ 0: "EBadBuilderFee",
204
+ 1: "EBadBuilderStatus",
205
+ 2: "EZeroBuilderAddress",
206
+ 3: "EBadBuilderCode",
207
+ 4: "ETombstoneLocked",
208
+ };
209
+ export const REFERRAL_BOOK_ABORT_NAMES = {
210
+ 0: "EBadBind",
211
+ 1: "EBindCycle",
212
+ };
213
+ export const ACCOUNT_ABORT_NAMES = {
214
+ 0: "EBadVersion",
215
+ 1: "EAccountExists",
216
+ 2: "ENotAuthorized",
217
+ 3: "EDelegateTooLong",
218
+ 4: "EPositionMissing",
219
+ 5: "EWrongExchange",
220
+ 6: "ECapMismatch",
221
+ 7: "EPermitMismatch",
222
+ 8: "EPendingOrders",
223
+ };
224
+ export const HOLDER_BOOK_ABORT_NAMES = {
225
+ 0: "ERecipientHasAccount",
226
+ };
227
+ export const ACCOUNT_TRANSFER_ABORT_NAMES = {
228
+ 0: "EZeroRecipient",
229
+ };
230
+ export const GAME_BOOK_ABORT_NAMES = {
231
+ 0: "EAlreadyAttached",
232
+ 1: "EBadParam",
233
+ 2: "ERegistryFull",
234
+ 3: "EUnknownId",
235
+ };
236
+ export const CONFIG_ABORT_NAMES = {
237
+ 0: "EBadVersion",
238
+ 1: "EBadFee",
239
+ 2: "EFeeUnset",
240
+ 3: "EBadBatch",
241
+ 4: "EBadReferralFee",
242
+ 5: "EBadSecondLevel",
243
+ 6: "EBadRefereeDiscount",
244
+ 8: "EBadEconParam",
245
+ 9: "EBadExecFeeRecipient",
246
+ 10: "EBadPauseCategory",
247
+ 11: "EDepositsPaused",
248
+ 12: "EWithdrawalsPaused",
249
+ 13: "ELiquidationsPaused",
250
+ 14: "EForceClosePaused",
251
+ 15: "EHarvestPaused",
252
+ 16: "EStakePaused",
253
+ 17: "EUnstakePaused",
254
+ 18: "EStakingClaimsPaused",
255
+ 19: "ELpPaused",
256
+ 20: "EGamePaused",
257
+ 21: "EFeeMintPaused",
258
+ 22: "EReferralsPaused",
259
+ 23: "EAccountsPaused",
260
+ 25: "EOpensPaused",
261
+ 26: "EClosesPaused",
262
+ 27: "EBadBuilderFee",
263
+ 28: "EBadBuilderCreateFee",
264
+ 100: "EBadOrderParam",
265
+ 101: "EGuardianCannotUnpause",
266
+ };
267
+ export const REFERRAL_ABORT_NAMES = {
268
+ 0: "ESelfReferral",
269
+ 1: "EReferrerBound",
270
+ 2: "EReferralCycle",
271
+ 3: "EReferralDepth",
272
+ 4: "EReferralInsolvent",
273
+ 5: "EZeroReferrer",
274
+ };
275
+ export const BUILDER_ABORT_NAMES = {
276
+ 0: "EUnknownBuilder",
277
+ 2: "EBadCode",
278
+ 4: "ENotBuilderOwner",
279
+ 5: "EZeroPayout",
280
+ 6: "EZeroOwner",
281
+ 8: "EBadCharset",
282
+ 9: "ECodeReserved",
283
+ 10: "ETooManyCodes",
284
+ 11: "EBadFee",
285
+ 12: "ENotApproved",
286
+ 13: "EAdminSuspended",
287
+ 14: "ECreateFeeMismatch",
288
+ 15: "ESelfServeDisabled",
289
+ 16: "ETombstoned",
290
+ };
291
+ export const STAKING_ABORT_NAMES = {
292
+ 0: "EBadVersion",
293
+ 1: "ESinkUnset",
294
+ 2: "ESinkBound",
295
+ 3: "EZero",
296
+ 4: "EInsufficientStake",
297
+ 5: "ENotUsdc",
298
+ 6: "ESelfReferral",
299
+ 7: "EReferrerBound",
300
+ 8: "EReferralClosed",
301
+ 9: "EBadStreamDuration",
302
+ 10: "EBadStakeLock",
303
+ 11: "EStakeLocked",
304
+ 12: "EWrongConfig",
305
+ 13: "EZeroReferrer",
306
+ 14: "EBadLockedWeight",
307
+ 15: "EExchangeUnbound",
308
+ 16: "EWrongExchange",
309
+ 17: "EExchangeBound",
310
+ };
311
+ export const ORACLE_ABORT_NAMES = {
312
+ 0: "EBadVersion",
313
+ 1: "EPriceStale",
314
+ 2: "EPriceFuture",
315
+ 4: "EPriceNotPositive",
316
+ 5: "EBadFeed",
317
+ 6: "EBadSpread",
318
+ 8: "EConfStale",
319
+ 9: "EConfFuture",
320
+ 10: "ESessionNotClosed",
321
+ 11: "EMarketMismatch",
322
+ 12: "EOracleRegression",
323
+ 13: "EGapTooShort",
324
+ 14: "ESessionArmed",
325
+ 15: "EOracleKilled",
326
+ 16: "ENotKeeper",
327
+ 17: "EMarketClosesPaused",
328
+ 19: "ETimestampWindow",
329
+ 20: "ENoSignedSession",
330
+ };
331
+ export const GAME_ABORT_NAMES = {
332
+ 0: "EGameDisabled",
333
+ 1: "EAlreadyClaimed",
334
+ 2: "ENoTreasury",
335
+ 3: "EBadParam",
336
+ 4: "EUnknownId",
337
+ 5: "EAlreadyDone",
338
+ 6: "ECooldown",
339
+ 7: "ENoCrate",
340
+ 8: "ENoAccount",
341
+ 9: "ENotReady",
342
+ 10: "ESeasonRewarded",
343
+ 11: "EInactive",
344
+ 12: "ERegistryFull",
345
+ 13: "EBadBatch",
346
+ };
347
+ export const KEEPER_ABORT_NAMES = {
348
+ 0: "EKeeperPriority",
349
+ };
350
+ export const EVENT_GUARD_ABORT_NAMES = {
351
+ 0: "EBadReason",
352
+ 1: "EBadWindow",
353
+ 2: "EBadLeverageCap",
354
+ 3: "EEventPaused",
355
+ 4: "EEventLeverage",
356
+ 5: "ENoEventPause",
357
+ 6: "EMarketMismatch",
358
+ 7: "EMarketClosed",
359
+ 8: "ESessionArmed",
360
+ 9: "EOracleRegression",
361
+ };
362
+ export const FEES_ABORT_NAMES = {
363
+ 0: "ENonZeroLoss",
364
+ 1: "ESinkExists",
365
+ };
366
+ export const TIMELOCK_ABORT_NAMES = {
367
+ 0: "EBadVersion",
368
+ 2: "ENoPending",
369
+ 4: "EDigestMismatch",
370
+ 5: "ECapMissing",
371
+ 6: "ECapDeposited",
372
+ 7: "EWrongCap",
373
+ };
374
+ export const POSITION_ABORT_NAMES = {
375
+ 0: "EBufferAboveCap",
376
+ 1: "EBadLeverage",
377
+ 2: "EBadPrice",
378
+ 3: "EBadWinFee",
379
+ 4: "EBadExposure",
380
+ };
381
+ export const LIQ_BOOK_ABORT_NAMES = {
382
+ 0: "EMissing",
383
+ 1: "EExists",
384
+ };
385
+ export const LP_ABORT_NAMES = {
386
+ 0: "EZeroClaim",
387
+ };
388
+ export const AUTHORITY_ABORT_NAMES = {
389
+ 0: "ENotAuthorized",
390
+ };
391
+ export const ORACLE_ADAPTER_ABORT_NAMES = {
392
+ 1: "EBadState",
393
+ 2: "EBadFeed",
394
+ 3: "EBadSpread",
395
+ 4: "EBadExponent",
396
+ 5: "EBadSource",
397
+ 6: "ENoSignedPrice",
398
+ 7: "ENoFeedTimestamp",
399
+ 8: "EStorageBehind",
400
+ 9: "ESignedPriceMismatch",
401
+ 10: "ESignedTimestampMismatch",
402
+ };
403
+ export const LOCKED_MINT_ABORT_NAMES = {
404
+ 0: "ENoEntry",
405
+ 1: "EUnlocked",
406
+ 2: "EBadAmount",
407
+ 4: "ETooManyBuckets",
408
+ 5: "EPenaltyAboveMax",
409
+ 6: "EBadSchedule",
410
+ 7: "ENoRoom",
411
+ };
412
+ export const MINT_CAP_ABORT_NAMES = {
413
+ 0: "EBadParams",
414
+ 1: "EFloorAboveKTenth",
415
+ };
416
+ export const MARKET_ABORT_MESSAGES = {
417
+ ETxBelowMinNotional: "The per-transaction notional cap is below the market's minimum notional",
418
+ };
419
+ export const GAME_ABORT_MESSAGES = {
420
+ EBadBatch: "Batch size must be at least 1",
421
+ };
422
+ export const FEE_MINT_ABORT_MESSAGES = {
423
+ EWrongMintWitness: "The mint witness is not from the reward coin's package",
424
+ };
425
+ export const ABORT_NAME_MAPS = {
426
+ trade: TRADE_ABORT_NAMES,
427
+ order: ORDER_ABORT_NAMES,
428
+ oracle: ORACLE_ABORT_NAMES,
429
+ game: GAME_ABORT_NAMES,
430
+ game_book: GAME_BOOK_ABORT_NAMES,
431
+ keeper: KEEPER_ABORT_NAMES,
432
+ event_guard: EVENT_GUARD_ABORT_NAMES,
433
+ fees: FEES_ABORT_NAMES,
434
+ market: MARKET_ABORT_NAMES,
435
+ fee_mint: FEE_MINT_ABORT_NAMES,
436
+ exchange: EXCHANGE_ABORT_NAMES,
437
+ access: ACCESS_ABORT_NAMES,
438
+ account: ACCOUNT_ABORT_NAMES,
439
+ holder_book: HOLDER_BOOK_ABORT_NAMES,
440
+ account_transfer: ACCOUNT_TRANSFER_ABORT_NAMES,
441
+ config: CONFIG_ABORT_NAMES,
442
+ timelock: TIMELOCK_ABORT_NAMES,
443
+ position: POSITION_ABORT_NAMES,
444
+ liq_book: LIQ_BOOK_ABORT_NAMES,
445
+ lp: LP_ABORT_NAMES,
446
+ authority: AUTHORITY_ABORT_NAMES,
447
+ adapter: ORACLE_ADAPTER_ABORT_NAMES,
448
+ referral: REFERRAL_ABORT_NAMES,
449
+ builder: BUILDER_ABORT_NAMES,
450
+ builder_book: BUILDER_BOOK_ABORT_NAMES,
451
+ referral_book: REFERRAL_BOOK_ABORT_NAMES,
452
+ staking: STAKING_ABORT_NAMES,
453
+ locked_mint: LOCKED_MINT_ABORT_NAMES,
454
+ mint_cap: MINT_CAP_ABORT_NAMES,
455
+ game_facade: GAME_ABORT_NAMES,
456
+ };
457
+ export const ABORT_MODULE_PATHS = {
458
+ trade: "parchment_trade::trade",
459
+ order: "parchment_trade::order",
460
+ oracle: "parchment_trade::oracle",
461
+ game: "parchment_game::game",
462
+ game_book: "parchment_game::game_book",
463
+ keeper: "parchment_trade::keeper",
464
+ event_guard: "parchment_trade::event_guard",
465
+ fees: "parchment_trade::fees",
466
+ market: "parchment::market",
467
+ fee_mint: "parchment_trade::fee_mint",
468
+ exchange: "parchment::exchange",
469
+ access: "parchment::access",
470
+ account: "parchment::account",
471
+ holder_book: "parchment_base::holder_book",
472
+ account_transfer: "parchment_trade::account_transfer",
473
+ config: "parchment::config",
474
+ timelock: "parchment::timelock",
475
+ position: "parchment_base::position",
476
+ liq_book: "parchment_base::liq_book",
477
+ lp: "parchment_base::lp",
478
+ authority: "parchment::authority",
479
+ adapter: "parchment_oracle::adapter",
480
+ referral: "parchment_trade::referral",
481
+ builder: "parchment_trade::builder",
482
+ builder_book: "parchment_base::builder_book",
483
+ referral_book: "parchment::referral_book",
484
+ staking: "parchment_token::staking",
485
+ locked_mint: "parchment_mint::locked_mint",
486
+ mint_cap: "parchment_mint::mint_cap",
487
+ game_facade: "parchment_trade::game",
488
+ };
489
+ export const UNCOVERED_MODULES = {
490
+ "oracle_aggregator::authority": "vendored aggregator (admin setup only); short name collides with parchment::authority",
491
+ "oracle_aggregator::config": "vendored aggregator (admin setup only); short name collides with parchment::config",
492
+ "oracle_aggregator::price": "vendored aggregator internals; Parchment reads prices through parchment_oracle::adapter",
493
+ "oracle_aggregator::price_feed": "vendored aggregator feed admin; not called by Parchment users",
494
+ "oracle_aggregator::price_feed_storage": "vendored aggregator storage auth; not called by Parchment users",
495
+ "oracle_aggregator::source": "vendored aggregator version check; not called by Parchment users",
496
+ };
497
+ const MODULE_KEY_BY_PATH = new Map(Object.entries(ABORT_MODULE_PATHS).map(([key, path]) => [path, key]));
498
+ const MODULE_ABORT_MESSAGES = {
499
+ order: ORDER_ABORT_MESSAGES,
500
+ market: MARKET_ABORT_MESSAGES,
501
+ fee_mint: FEE_MINT_ABORT_MESSAGES,
502
+ game: GAME_ABORT_MESSAGES,
503
+ };
504
+ export function abortName(module, code) {
505
+ const key = MODULE_KEY_BY_PATH.get(module) ?? module;
506
+ const names = Object.hasOwn(ABORT_NAME_MAPS, key) ? ABORT_NAME_MAPS[key] : undefined;
507
+ const n = decodeAbortCode(code);
508
+ return names !== undefined && n !== undefined && Object.hasOwn(names, n) ? names[n] : undefined;
509
+ }
510
+ export function abortMessage(module, nameOrCode) {
511
+ if (module === "trade") {
512
+ if (typeof nameOrCode !== "string" || /^\d+$/.test(nameOrCode))
513
+ return tradeAbortMessage(nameOrCode);
514
+ const code = Object.keys(TRADE_ABORT_NAMES).find((n) => TRADE_ABORT_NAMES[Number(n)] === nameOrCode);
515
+ return code === undefined ? undefined : tradeAbortMessage(Number(code));
516
+ }
517
+ const messages = Object.hasOwn(MODULE_ABORT_MESSAGES, module) ? MODULE_ABORT_MESSAGES[module] : undefined;
518
+ if (messages === undefined)
519
+ return undefined;
520
+ const name = typeof nameOrCode === "string" && !/^\d+$/.test(nameOrCode) ? nameOrCode : abortName(module, nameOrCode);
521
+ return name !== undefined && Object.hasOwn(messages, name) ? messages[name] : undefined;
522
+ }