@panoptic-eng/sdk 1.0.60 → 1.0.61
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/cow/index.js +1207 -484
- package/dist/cow/index.js.map +1 -1
- package/dist/{cow-CHb343la.js → cow-BItQK2Bi.js} +1 -1
- package/dist/index.d.ts +72 -55
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -6
- package/dist/index.js.map +1 -1
- package/dist/{irm-BIaLQ-0n.js → irm-BEug2-TH.js} +2 -2
- package/dist/panoptic/v2/index.d.ts +50 -3
- package/dist/panoptic/v2/index.d.ts.map +1 -1
- package/dist/panoptic/v2/index.js +254 -83
- package/dist/panoptic/v2/index.js.map +1 -1
- package/dist/panoptic/v2/react-public.d.ts +58 -3
- package/dist/panoptic/v2/react-public.d.ts.map +1 -1
- package/dist/panoptic/v2/react-public.js +270 -89
- package/dist/panoptic/v2/react-public.js.map +1 -1
- package/dist/{rates-COAJpKRd.js → rates-CPHxWqpT.js} +498 -482
- package/dist/{router-B2fj4_X7.js → router-BZGHjEcU.js} +2 -2
- package/dist/{router-DliBF9FK.js → router-kTiatP_R.js} +2 -2
- package/dist/{transactionFees-CNbjAigT.js → transactionFees-MocbcAyR.js} +10 -5
- package/dist/uniswap/index.js +724 -1
- package/dist/uniswap/index.js.map +1 -1
- package/dist/{v2-C3n8n1_i.js → v2-odOz_0wM.js} +175 -201
- package/dist/vault-transaction-fees.d.ts +1 -0
- package/dist/vault-transaction-fees.d.ts.map +1 -1
- package/dist/vault-transaction-fees.js +10 -5
- package/dist/vault-transaction-fees.js.map +1 -1
- package/dist/{writes-BTkqc_rn.js → writes-gs0k0uoN.js} +219 -38
- package/dist/zodiac/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cow/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { decodeEventLog, encodeFunctionData, erc20Abi, getAbiItem, getAddress, keccak256, maxUint256, parseAbi, stringToHex, toFunctionSelector, zeroAddress } from "viem";
|
|
1
|
+
import { BaseError, decodeErrorResult, decodeEventLog, encodeFunctionData, erc20Abi, getAbiItem, getAddress, keccak256, maxUint256, parseAbi, stringToHex, toFunctionSelector, zeroAddress } from "viem";
|
|
2
2
|
|
|
3
3
|
//#region src/cow/addresses.ts
|
|
4
4
|
/** GPv2Settlement — EIP-712 verifying contract for signed orders. */
|
|
@@ -3099,576 +3099,790 @@ const riskEngineAbi = [
|
|
|
3099
3099
|
];
|
|
3100
3100
|
|
|
3101
3101
|
//#endregion
|
|
3102
|
-
//#region src/panoptic/v2/
|
|
3102
|
+
//#region src/panoptic/v2/errors/base.ts
|
|
3103
3103
|
/**
|
|
3104
|
-
*
|
|
3104
|
+
* Base error class for the Panoptic v2 SDK.
|
|
3105
|
+
* @module v2/errors/base
|
|
3106
|
+
*/
|
|
3107
|
+
/**
|
|
3108
|
+
* Base error class for all Panoptic SDK errors.
|
|
3109
|
+
* All errors thrown by the SDK extend this class.
|
|
3105
3110
|
*
|
|
3106
|
-
*
|
|
3107
|
-
*
|
|
3108
|
-
*
|
|
3109
|
-
*
|
|
3110
|
-
*
|
|
3111
|
-
*
|
|
3112
|
-
*
|
|
3113
|
-
*
|
|
3111
|
+
* @example
|
|
3112
|
+
* ```typescript
|
|
3113
|
+
* try {
|
|
3114
|
+
* await openPosition(config, params)
|
|
3115
|
+
* } catch (error) {
|
|
3116
|
+
* if (error instanceof PanopticError) {
|
|
3117
|
+
* console.log('Panoptic error:', error.name, error.message)
|
|
3118
|
+
* console.log('Original cause:', error.cause)
|
|
3119
|
+
* }
|
|
3120
|
+
* }
|
|
3121
|
+
* ```
|
|
3114
3122
|
*/
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3123
|
+
var PanopticError = class extends Error {
|
|
3124
|
+
name = "PanopticError";
|
|
3125
|
+
/** The Solidity error name (e.g. 'PriceBoundFail', 'InputListFail'). Set by the parser. */
|
|
3126
|
+
errorName;
|
|
3127
|
+
/**
|
|
3128
|
+
* Creates a new PanopticError.
|
|
3129
|
+
*
|
|
3130
|
+
* @param message - Human-readable error message
|
|
3131
|
+
* @param cause - Optional underlying error that caused this error
|
|
3132
|
+
*/
|
|
3133
|
+
constructor(message, cause) {
|
|
3134
|
+
super(message);
|
|
3135
|
+
this.cause = cause;
|
|
3136
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
|
|
3137
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
3138
|
+
}
|
|
3139
|
+
};
|
|
3140
|
+
|
|
3141
|
+
//#endregion
|
|
3142
|
+
//#region src/panoptic/v2/errors/contract.ts
|
|
3134
3143
|
/**
|
|
3135
|
-
*
|
|
3144
|
+
* The account is not solvent enough to perform the desired action.
|
|
3145
|
+
* @see Errors.sol:9
|
|
3136
3146
|
*/
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
};
|
|
3146
|
-
}
|
|
3147
|
+
var AccountInsolventError = class extends PanopticError {
|
|
3148
|
+
name = "AccountInsolventError";
|
|
3149
|
+
constructor(solvent, numberOfTicks, cause) {
|
|
3150
|
+
super(`Account insolvent: solvent=${solvent}, numberOfTicks=${numberOfTicks}`, cause);
|
|
3151
|
+
this.solvent = solvent;
|
|
3152
|
+
this.numberOfTicks = numberOfTicks;
|
|
3153
|
+
}
|
|
3154
|
+
};
|
|
3147
3155
|
/**
|
|
3148
|
-
*
|
|
3149
|
-
*
|
|
3150
|
-
* @param logs - The transaction logs
|
|
3151
|
-
* @returns Parsed Panoptic events
|
|
3156
|
+
* Position is still solvent and cannot be liquidated.
|
|
3157
|
+
* @see Errors.sol:84
|
|
3152
3158
|
*/
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
blockNumber: log.blockNumber ?? 0n,
|
|
3158
|
-
blockHash: log.blockHash ?? "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
3159
|
-
transactionHash: log.transactionHash ?? "0x",
|
|
3160
|
-
logIndex: BigInt(log.logIndex ?? 0)
|
|
3161
|
-
};
|
|
3162
|
-
try {
|
|
3163
|
-
const poolEvent = decodeEventLog({
|
|
3164
|
-
abi: panopticPoolV2Abi,
|
|
3165
|
-
data: log.data,
|
|
3166
|
-
topics: log.topics
|
|
3167
|
-
});
|
|
3168
|
-
if (poolEvent.eventName === "OptionMinted") {
|
|
3169
|
-
const args = poolEvent.args;
|
|
3170
|
-
const balance = decodePositionBalance(args.balanceData);
|
|
3171
|
-
events.push({
|
|
3172
|
-
type: "OptionMinted",
|
|
3173
|
-
...baseEvent,
|
|
3174
|
-
recipient: args.recipient,
|
|
3175
|
-
tokenId: args.tokenId,
|
|
3176
|
-
positionSize: balance.positionSize,
|
|
3177
|
-
poolUtilization0: balance.poolUtilization0,
|
|
3178
|
-
poolUtilization1: balance.poolUtilization1,
|
|
3179
|
-
tickAtMint: balance.tickAtMint,
|
|
3180
|
-
timestampAtMint: balance.timestampAtMint,
|
|
3181
|
-
blockAtMint: balance.blockAtMint,
|
|
3182
|
-
swapAtMint: balance.swapAtMint
|
|
3183
|
-
});
|
|
3184
|
-
} else if (poolEvent.eventName === "OptionBurnt") {
|
|
3185
|
-
const args = poolEvent.args;
|
|
3186
|
-
events.push({
|
|
3187
|
-
type: "OptionBurnt",
|
|
3188
|
-
...baseEvent,
|
|
3189
|
-
recipient: args.recipient,
|
|
3190
|
-
tokenId: args.tokenId,
|
|
3191
|
-
positionSize: args.positionSize,
|
|
3192
|
-
premiaByLeg: [
|
|
3193
|
-
args.premiaByLeg[0] ?? 0n,
|
|
3194
|
-
args.premiaByLeg[1] ?? 0n,
|
|
3195
|
-
args.premiaByLeg[2] ?? 0n,
|
|
3196
|
-
args.premiaByLeg[3] ?? 0n
|
|
3197
|
-
]
|
|
3198
|
-
});
|
|
3199
|
-
} else if (poolEvent.eventName === "AccountLiquidated") {
|
|
3200
|
-
const args = poolEvent.args;
|
|
3201
|
-
const { right, left } = decodeLeftRightSigned(args.bonusAmounts);
|
|
3202
|
-
events.push({
|
|
3203
|
-
type: "AccountLiquidated",
|
|
3204
|
-
...baseEvent,
|
|
3205
|
-
liquidator: args.liquidator,
|
|
3206
|
-
liquidatee: args.liquidatee,
|
|
3207
|
-
bonusAmount0: right,
|
|
3208
|
-
bonusAmount1: left
|
|
3209
|
-
});
|
|
3210
|
-
} else if (poolEvent.eventName === "ForcedExercised") {
|
|
3211
|
-
const args = poolEvent.args;
|
|
3212
|
-
const { right, left } = decodeLeftRightSigned(args.exerciseFee);
|
|
3213
|
-
events.push({
|
|
3214
|
-
type: "ForcedExercised",
|
|
3215
|
-
...baseEvent,
|
|
3216
|
-
exercisor: args.exercisor,
|
|
3217
|
-
user: args.user,
|
|
3218
|
-
tokenId: args.tokenId,
|
|
3219
|
-
exerciseFee0: right,
|
|
3220
|
-
exerciseFee1: left
|
|
3221
|
-
});
|
|
3222
|
-
} else if (poolEvent.eventName === "PremiumSettled") {
|
|
3223
|
-
const args = poolEvent.args;
|
|
3224
|
-
const { right, left } = decodeLeftRightSigned(args.settledAmounts);
|
|
3225
|
-
events.push({
|
|
3226
|
-
type: "PremiumSettled",
|
|
3227
|
-
...baseEvent,
|
|
3228
|
-
user: args.user,
|
|
3229
|
-
tokenId: args.tokenId,
|
|
3230
|
-
legIndex: args.legIndex,
|
|
3231
|
-
settledAmount0: right,
|
|
3232
|
-
settledAmount1: left
|
|
3233
|
-
});
|
|
3234
|
-
}
|
|
3235
|
-
} catch {
|
|
3236
|
-
try {
|
|
3237
|
-
const collateralEvent = decodeEventLog({
|
|
3238
|
-
abi: collateralTrackerV2Abi,
|
|
3239
|
-
data: log.data,
|
|
3240
|
-
topics: log.topics
|
|
3241
|
-
});
|
|
3242
|
-
if (collateralEvent.eventName === "Deposit") {
|
|
3243
|
-
const args = collateralEvent.args;
|
|
3244
|
-
events.push({
|
|
3245
|
-
type: "Deposit",
|
|
3246
|
-
...baseEvent,
|
|
3247
|
-
sender: args.sender,
|
|
3248
|
-
owner: args.owner,
|
|
3249
|
-
assets: args.assets,
|
|
3250
|
-
shares: args.shares
|
|
3251
|
-
});
|
|
3252
|
-
} else if (collateralEvent.eventName === "Withdraw") {
|
|
3253
|
-
const args = collateralEvent.args;
|
|
3254
|
-
events.push({
|
|
3255
|
-
type: "Withdraw",
|
|
3256
|
-
...baseEvent,
|
|
3257
|
-
sender: args.sender,
|
|
3258
|
-
receiver: args.receiver,
|
|
3259
|
-
owner: args.owner,
|
|
3260
|
-
assets: args.assets,
|
|
3261
|
-
shares: args.shares
|
|
3262
|
-
});
|
|
3263
|
-
}
|
|
3264
|
-
} catch {}
|
|
3265
|
-
}
|
|
3159
|
+
var NotMarginCalledError = class extends PanopticError {
|
|
3160
|
+
name = "NotMarginCalledError";
|
|
3161
|
+
constructor(cause) {
|
|
3162
|
+
super("Position is still solvent and cannot be liquidated", cause);
|
|
3266
3163
|
}
|
|
3267
|
-
|
|
3268
|
-
}
|
|
3164
|
+
};
|
|
3269
3165
|
/**
|
|
3270
|
-
*
|
|
3271
|
-
*
|
|
3272
|
-
* @param client - The public client
|
|
3273
|
-
* @param hash - The transaction hash
|
|
3274
|
-
* @returns TxResult with wait function
|
|
3166
|
+
* The user does not own enough assets to open/close a position.
|
|
3167
|
+
* @see Errors.sol:78
|
|
3275
3168
|
*/
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
return {
|
|
3286
|
-
hash: receipt.transactionHash,
|
|
3287
|
-
blockNumber: receipt.blockNumber,
|
|
3288
|
-
blockHash: receipt.blockHash,
|
|
3289
|
-
gasUsed: receipt.gasUsed,
|
|
3290
|
-
status: receipt.status === "success" ? "success" : "reverted",
|
|
3291
|
-
events
|
|
3292
|
-
};
|
|
3293
|
-
}
|
|
3294
|
-
};
|
|
3295
|
-
}
|
|
3169
|
+
var NotEnoughTokensError = class extends PanopticError {
|
|
3170
|
+
name = "NotEnoughTokensError";
|
|
3171
|
+
constructor(tokenAddress, assetsRequested, assetBalance, cause) {
|
|
3172
|
+
super(`Not enough tokens: requested=${assetsRequested}, balance=${assetBalance}, token=${tokenAddress}`, cause);
|
|
3173
|
+
this.tokenAddress = tokenAddress;
|
|
3174
|
+
this.assetsRequested = assetsRequested;
|
|
3175
|
+
this.assetBalance = assetBalance;
|
|
3176
|
+
}
|
|
3177
|
+
};
|
|
3296
3178
|
/**
|
|
3297
|
-
*
|
|
3298
|
-
*
|
|
3299
|
-
*
|
|
3300
|
-
* Normal path (no broadcaster): calls walletClient.writeContract() with gas overrides.
|
|
3301
|
-
* Broadcaster path: prepareTransactionRequest → apply overrides → signTransaction → broadcast.
|
|
3302
|
-
*
|
|
3303
|
-
* @param params - Submit write parameters
|
|
3304
|
-
* @returns TxResult
|
|
3179
|
+
* There is not enough available liquidity in the chunk for a long leg.
|
|
3180
|
+
* @see Errors.sol:75
|
|
3305
3181
|
*/
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
const data = encodeFunctionData({
|
|
3311
|
-
abi,
|
|
3312
|
-
functionName,
|
|
3313
|
-
args
|
|
3314
|
-
});
|
|
3315
|
-
const broadcastAccount = walletClient.account ?? account;
|
|
3316
|
-
const request = await walletClient.prepareTransactionRequest({
|
|
3317
|
-
account: broadcastAccount,
|
|
3318
|
-
to: address,
|
|
3319
|
-
chain: walletClient.chain,
|
|
3320
|
-
data,
|
|
3321
|
-
...value !== void 0 && { value },
|
|
3322
|
-
...txOverrides?.maxFeePerGas !== void 0 && { maxFeePerGas: txOverrides.maxFeePerGas },
|
|
3323
|
-
...txOverrides?.maxPriorityFeePerGas !== void 0 && { maxPriorityFeePerGas: txOverrides.maxPriorityFeePerGas },
|
|
3324
|
-
...txOverrides?.gas !== void 0 && { gas: txOverrides.gas },
|
|
3325
|
-
...txOverrides?.nonce !== void 0 && { nonce: Number(txOverrides.nonce) }
|
|
3326
|
-
});
|
|
3327
|
-
const signedTx = await walletClient.signTransaction({
|
|
3328
|
-
...request,
|
|
3329
|
-
account: broadcastAccount
|
|
3330
|
-
});
|
|
3331
|
-
const hash$1 = await broadcaster.broadcast(signedTx);
|
|
3332
|
-
return createTxResult(client, hash$1);
|
|
3182
|
+
var NotEnoughLiquidityInChunkError = class extends PanopticError {
|
|
3183
|
+
name = "NotEnoughLiquidityInChunkError";
|
|
3184
|
+
constructor(cause) {
|
|
3185
|
+
super("Not enough liquidity in chunk for long leg creation or short leg closure", cause);
|
|
3333
3186
|
}
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
abi,
|
|
3344
|
-
functionName,
|
|
3345
|
-
args,
|
|
3346
|
-
account: resolvedAccount,
|
|
3347
|
-
...value !== void 0 && { value }
|
|
3348
|
-
});
|
|
3349
|
-
gasOverrides.gas = estimated * 120n / 100n;
|
|
3187
|
+
};
|
|
3188
|
+
/**
|
|
3189
|
+
* There is not enough available liquidity to fulfill a credit.
|
|
3190
|
+
* @see Errors.sol:47
|
|
3191
|
+
*/
|
|
3192
|
+
var InsufficientCreditLiquidityError = class extends PanopticError {
|
|
3193
|
+
name = "InsufficientCreditLiquidityError";
|
|
3194
|
+
constructor(cause) {
|
|
3195
|
+
super("Insufficient credit liquidity available in the PanopticPool", cause);
|
|
3350
3196
|
}
|
|
3351
|
-
|
|
3352
|
-
address,
|
|
3353
|
-
abi,
|
|
3354
|
-
functionName,
|
|
3355
|
-
args,
|
|
3356
|
-
account: resolvedAccount,
|
|
3357
|
-
chain: walletClient.chain,
|
|
3358
|
-
...value !== void 0 && { value },
|
|
3359
|
-
...gasOverrides
|
|
3360
|
-
});
|
|
3361
|
-
return createTxResult(client, hash);
|
|
3362
|
-
}
|
|
3363
|
-
|
|
3364
|
-
//#endregion
|
|
3365
|
-
//#region src/panoptic/v2/errors/base.ts
|
|
3197
|
+
};
|
|
3366
3198
|
/**
|
|
3367
|
-
*
|
|
3368
|
-
* @
|
|
3199
|
+
* The amount deposited is larger than the maximum permitted.
|
|
3200
|
+
* @see Errors.sol:25
|
|
3369
3201
|
*/
|
|
3202
|
+
var DepositTooLargeError = class extends PanopticError {
|
|
3203
|
+
name = "DepositTooLargeError";
|
|
3204
|
+
constructor(cause) {
|
|
3205
|
+
super("Deposit amount exceeds maximum permitted", cause);
|
|
3206
|
+
}
|
|
3207
|
+
};
|
|
3370
3208
|
/**
|
|
3371
|
-
*
|
|
3372
|
-
*
|
|
3373
|
-
*
|
|
3374
|
-
* @example
|
|
3375
|
-
* ```typescript
|
|
3376
|
-
* try {
|
|
3377
|
-
* await openPosition(config, params)
|
|
3378
|
-
* } catch (error) {
|
|
3379
|
-
* if (error instanceof PanopticError) {
|
|
3380
|
-
* console.log('Panoptic error:', error.name, error.message)
|
|
3381
|
-
* console.log('Original cause:', error.cause)
|
|
3382
|
-
* }
|
|
3383
|
-
* }
|
|
3384
|
-
* ```
|
|
3209
|
+
* Attempted to withdraw/redeem less than a single asset.
|
|
3210
|
+
* @see Errors.sol:16
|
|
3385
3211
|
*/
|
|
3386
|
-
var
|
|
3387
|
-
name = "
|
|
3388
|
-
|
|
3389
|
-
|
|
3212
|
+
var BelowMinimumRedemptionError = class extends PanopticError {
|
|
3213
|
+
name = "BelowMinimumRedemptionError";
|
|
3214
|
+
constructor(cause) {
|
|
3215
|
+
super("Redemption amount below minimum threshold", cause);
|
|
3216
|
+
}
|
|
3217
|
+
};
|
|
3218
|
+
/**
|
|
3219
|
+
* Attempted to withdraw/redeem more than available.
|
|
3220
|
+
* @see Errors.sol:35
|
|
3221
|
+
*/
|
|
3222
|
+
var ExceedsMaximumRedemptionError = class extends PanopticError {
|
|
3223
|
+
name = "ExceedsMaximumRedemptionError";
|
|
3224
|
+
constructor(cause) {
|
|
3225
|
+
super("Redemption exceeds maximum available (liquidity, shares, or open positions)", cause);
|
|
3226
|
+
}
|
|
3227
|
+
};
|
|
3228
|
+
/**
|
|
3229
|
+
* Mints/burns of a position returns no collateral requirement.
|
|
3230
|
+
* @see Errors.sol:141
|
|
3231
|
+
*/
|
|
3232
|
+
var ZeroCollateralRequirementError = class extends PanopticError {
|
|
3233
|
+
name = "ZeroCollateralRequirementError";
|
|
3234
|
+
constructor(cause) {
|
|
3235
|
+
super("Position mint/burn returned zero collateral requirement", cause);
|
|
3236
|
+
}
|
|
3237
|
+
};
|
|
3238
|
+
/**
|
|
3239
|
+
* The TokenId provided is malformed or invalid.
|
|
3240
|
+
* @see Errors.sol:54
|
|
3241
|
+
*/
|
|
3242
|
+
var InvalidTokenIdParameterError = class extends PanopticError {
|
|
3243
|
+
name = "InvalidTokenIdParameterError";
|
|
3390
3244
|
/**
|
|
3391
|
-
*
|
|
3392
|
-
*
|
|
3393
|
-
* @param message - Human-readable error message
|
|
3394
|
-
* @param cause - Optional underlying error that caused this error
|
|
3245
|
+
* Parameter type meanings:
|
|
3246
|
+
* 0=poolId, 1=ratio, 2=tokenType, 3=riskPartner, 4=strike, 5=width, 6=duplicateChunk
|
|
3395
3247
|
*/
|
|
3396
|
-
constructor(
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3248
|
+
constructor(parameterType, cause) {
|
|
3249
|
+
const paramNames = [
|
|
3250
|
+
"poolId",
|
|
3251
|
+
"ratio",
|
|
3252
|
+
"tokenType",
|
|
3253
|
+
"riskPartner",
|
|
3254
|
+
"strike",
|
|
3255
|
+
"width",
|
|
3256
|
+
"duplicateChunk"
|
|
3257
|
+
];
|
|
3258
|
+
const paramName = paramNames[Number(parameterType)] ?? `unknown(${parameterType})`;
|
|
3259
|
+
super(`Invalid TokenId parameter: ${paramName}`, cause);
|
|
3260
|
+
this.parameterType = parameterType;
|
|
3401
3261
|
}
|
|
3402
3262
|
};
|
|
3403
|
-
|
|
3404
|
-
//#endregion
|
|
3405
|
-
//#region src/panoptic/v2/errors/errorsAbi.ts
|
|
3406
3263
|
/**
|
|
3407
|
-
*
|
|
3408
|
-
*
|
|
3409
|
-
* Contains all custom errors from Errors.sol with their signatures.
|
|
3410
|
-
* Used for decoding contract revert data.
|
|
3411
|
-
*
|
|
3412
|
-
* Selectors sourced from `forge selectors list` output.
|
|
3413
|
-
*
|
|
3414
|
-
* @module v2/errors/errorsAbi
|
|
3264
|
+
* Position is not owned by the user and has positionSize=0.
|
|
3265
|
+
* @see Errors.sol:96
|
|
3415
3266
|
*/
|
|
3267
|
+
var PositionNotOwnedError = class extends PanopticError {
|
|
3268
|
+
name = "PositionNotOwnedError";
|
|
3269
|
+
constructor(cause) {
|
|
3270
|
+
super("Position is not owned by the user", cause);
|
|
3271
|
+
}
|
|
3272
|
+
};
|
|
3416
3273
|
/**
|
|
3417
|
-
*
|
|
3418
|
-
*
|
|
3419
|
-
* Selector computation: keccak256(errorSignature)[:4]
|
|
3274
|
+
* The maximum token deltas for a position exceed limits.
|
|
3275
|
+
* @see Errors.sol:99
|
|
3420
3276
|
*/
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
{
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
{
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
{
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
{
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
{
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
{
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
{
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
{
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3277
|
+
var PositionTooLargeError = class extends PanopticError {
|
|
3278
|
+
name = "PositionTooLargeError";
|
|
3279
|
+
constructor(cause) {
|
|
3280
|
+
super("Position size exceeds maximum allowed token deltas", cause);
|
|
3281
|
+
}
|
|
3282
|
+
};
|
|
3283
|
+
/**
|
|
3284
|
+
* User has open positions, so they cannot transfer collateral shares.
|
|
3285
|
+
* @see Errors.sol:93
|
|
3286
|
+
*/
|
|
3287
|
+
var PositionCountNotZeroError = class extends PanopticError {
|
|
3288
|
+
name = "PositionCountNotZeroError";
|
|
3289
|
+
constructor(cause) {
|
|
3290
|
+
super("Cannot transfer collateral shares while positions are open", cause);
|
|
3291
|
+
}
|
|
3292
|
+
};
|
|
3293
|
+
/**
|
|
3294
|
+
* The list of provided TokenIds has a duplicate entry.
|
|
3295
|
+
* @see Errors.sol:28
|
|
3296
|
+
*/
|
|
3297
|
+
var DuplicateTokenIdError = class extends PanopticError {
|
|
3298
|
+
name = "DuplicateTokenIdError";
|
|
3299
|
+
constructor(cause) {
|
|
3300
|
+
super("Duplicate TokenId in provided list", cause);
|
|
3301
|
+
}
|
|
3302
|
+
};
|
|
3303
|
+
/**
|
|
3304
|
+
* The supplied tokenId has no valid legs.
|
|
3305
|
+
* @see Errors.sol:144
|
|
3306
|
+
*/
|
|
3307
|
+
var TokenIdHasZeroLegsError = class extends PanopticError {
|
|
3308
|
+
name = "TokenIdHasZeroLegsError";
|
|
3309
|
+
constructor(cause) {
|
|
3310
|
+
super("TokenId has no valid legs", cause);
|
|
3311
|
+
}
|
|
3312
|
+
};
|
|
3313
|
+
/**
|
|
3314
|
+
* Position would exceed maximum legs open for account.
|
|
3315
|
+
* @see Errors.sol:112
|
|
3316
|
+
*/
|
|
3317
|
+
var TooManyLegsOpenError = class extends PanopticError {
|
|
3318
|
+
name = "TooManyLegsOpenError";
|
|
3319
|
+
constructor(cause) {
|
|
3320
|
+
super("Position would exceed maximum allowed legs open", cause);
|
|
3321
|
+
}
|
|
3322
|
+
};
|
|
3323
|
+
/**
|
|
3324
|
+
* The provided list of option positions is incorrect or invalid.
|
|
3325
|
+
* @see Errors.sol:38
|
|
3326
|
+
*/
|
|
3327
|
+
var InputListFailError = class extends PanopticError {
|
|
3328
|
+
name = "InputListFailError";
|
|
3329
|
+
constructor(cause) {
|
|
3330
|
+
super("Invalid position list provided", cause);
|
|
3331
|
+
}
|
|
3332
|
+
};
|
|
3333
|
+
/**
|
|
3334
|
+
* Tick is not between MIN_TICK and MAX_TICK.
|
|
3335
|
+
* @see Errors.sol:41
|
|
3336
|
+
*/
|
|
3337
|
+
var InvalidTickError = class extends PanopticError {
|
|
3338
|
+
name = "InvalidTickError";
|
|
3339
|
+
constructor(cause) {
|
|
3340
|
+
super("Tick is outside valid range (MIN_TICK to MAX_TICK)", cause);
|
|
3341
|
+
}
|
|
3342
|
+
};
|
|
3343
|
+
/**
|
|
3344
|
+
* The tick range is invalid (not initializable or exceeds bounds).
|
|
3345
|
+
* @see Errors.sol:120
|
|
3346
|
+
*/
|
|
3347
|
+
var InvalidTickBoundError = class extends PanopticError {
|
|
3348
|
+
name = "InvalidTickBoundError";
|
|
3349
|
+
constructor(cause) {
|
|
3350
|
+
super("Tick range is invalid (not initializable multiples of tickSpacing or exceeds bounds)", cause);
|
|
3351
|
+
}
|
|
3352
|
+
};
|
|
3353
|
+
/**
|
|
3354
|
+
* The current tick has fallen outside the slippage range.
|
|
3355
|
+
* @see Errors.sol:102
|
|
3356
|
+
*/
|
|
3357
|
+
var PriceBoundFailError = class extends PanopticError {
|
|
3358
|
+
name = "PriceBoundFailError";
|
|
3359
|
+
constructor(currentTick, cause) {
|
|
3360
|
+
super(`Price moved outside slippage bounds (currentTick=${currentTick})`, cause);
|
|
3361
|
+
this.currentTick = currentTick;
|
|
3362
|
+
}
|
|
3363
|
+
};
|
|
3364
|
+
/**
|
|
3365
|
+
* The price impact of the trade is too large.
|
|
3366
|
+
* @see Errors.sol:105
|
|
3367
|
+
*/
|
|
3368
|
+
var PriceImpactTooLargeError = class extends PanopticError {
|
|
3369
|
+
name = "PriceImpactTooLargeError";
|
|
3370
|
+
constructor(cause) {
|
|
3371
|
+
super("Price impact of trade exceeds maximum allowed", cause);
|
|
3372
|
+
}
|
|
3373
|
+
};
|
|
3374
|
+
/**
|
|
3375
|
+
* Mints/burns of zero-liquidity chunks are not supported.
|
|
3376
|
+
* @see Errors.sol:19
|
|
3377
|
+
*/
|
|
3378
|
+
var ChunkHasZeroLiquidityError = class extends PanopticError {
|
|
3379
|
+
name = "ChunkHasZeroLiquidityError";
|
|
3380
|
+
constructor(cause) {
|
|
3381
|
+
super("Cannot mint/burn chunk with zero liquidity", cause);
|
|
3382
|
+
}
|
|
3383
|
+
};
|
|
3384
|
+
/**
|
|
3385
|
+
* Liquidity in a chunk is above 2^128.
|
|
3386
|
+
* @see Errors.sol:44
|
|
3387
|
+
*/
|
|
3388
|
+
var LiquidityTooHighError = class extends PanopticError {
|
|
3389
|
+
name = "LiquidityTooHighError";
|
|
3390
|
+
constructor(cause) {
|
|
3391
|
+
super("Liquidity exceeds maximum (2^128)", cause);
|
|
3392
|
+
}
|
|
3393
|
+
};
|
|
3394
|
+
/**
|
|
3395
|
+
* Net liquidity is zero due to small positions.
|
|
3396
|
+
* @see Errors.sol:63
|
|
3397
|
+
*/
|
|
3398
|
+
var NetLiquidityZeroError = class extends PanopticError {
|
|
3399
|
+
name = "NetLiquidityZeroError";
|
|
3400
|
+
constructor(cause) {
|
|
3401
|
+
super("Net liquidity is zero, cannot compute liquidity spread", cause);
|
|
3402
|
+
}
|
|
3403
|
+
};
|
|
3404
|
+
/**
|
|
3405
|
+
* Effective liquidity above threshold during long mint or short burn.
|
|
3406
|
+
* @see Errors.sol:32
|
|
3407
|
+
*/
|
|
3408
|
+
var EffectiveLiquidityAboveThresholdError = class extends PanopticError {
|
|
3409
|
+
name = "EffectiveLiquidityAboveThresholdError";
|
|
3410
|
+
constructor(cause) {
|
|
3411
|
+
super("Effective liquidity above spread threshold", cause);
|
|
3412
|
+
}
|
|
3413
|
+
};
|
|
3414
|
+
/**
|
|
3415
|
+
* An oracle price is too far from another or the current tick.
|
|
3416
|
+
* @see Errors.sol:109
|
|
3417
|
+
*/
|
|
3418
|
+
var StaleOracleError = class extends PanopticError {
|
|
3419
|
+
name = "StaleOracleError";
|
|
3420
|
+
constructor(cause) {
|
|
3421
|
+
super("Oracle price deviation too high (potential manipulation safeguard)", cause);
|
|
3422
|
+
}
|
|
3423
|
+
};
|
|
3424
|
+
/**
|
|
3425
|
+
* None of the legs in a position are force-exercisable.
|
|
3426
|
+
* @see Errors.sol:66
|
|
3427
|
+
*/
|
|
3428
|
+
var NoLegsExercisableError = class extends PanopticError {
|
|
3429
|
+
name = "NoLegsExercisableError";
|
|
3430
|
+
constructor(cause) {
|
|
3431
|
+
super("No legs are force-exercisable (all are short or ATM long)", cause);
|
|
3432
|
+
}
|
|
3433
|
+
};
|
|
3434
|
+
/**
|
|
3435
|
+
* The leg is not long, so premium cannot be settled.
|
|
3436
|
+
* @see Errors.sol:69
|
|
3437
|
+
*/
|
|
3438
|
+
var NotALongLegError = class extends PanopticError {
|
|
3439
|
+
name = "NotALongLegError";
|
|
3440
|
+
constructor(cause) {
|
|
3441
|
+
super("Cannot settle premium for non-long leg", cause);
|
|
3442
|
+
}
|
|
3443
|
+
};
|
|
3444
|
+
/**
|
|
3445
|
+
* The Uniswap Pool has not been created.
|
|
3446
|
+
* @see Errors.sol:90
|
|
3447
|
+
*/
|
|
3448
|
+
var PoolNotInitializedError = class extends PanopticError {
|
|
3449
|
+
name = "PoolNotInitializedError";
|
|
3450
|
+
constructor(cause) {
|
|
3451
|
+
super("Uniswap pool not initialized", cause);
|
|
3452
|
+
}
|
|
3453
|
+
};
|
|
3454
|
+
/**
|
|
3455
|
+
* Smart contract has already been initialized.
|
|
3456
|
+
* @see Errors.sol:22
|
|
3457
|
+
*/
|
|
3458
|
+
var AlreadyInitializedError = class extends PanopticError {
|
|
3459
|
+
name = "AlreadyInitializedError";
|
|
3460
|
+
constructor(cause) {
|
|
3461
|
+
super("Contract already initialized", cause);
|
|
3462
|
+
}
|
|
3463
|
+
};
|
|
3464
|
+
/**
|
|
3465
|
+
* The supplied poolId does not match the poolId for that Uniswap Pool.
|
|
3466
|
+
* @see Errors.sol:132
|
|
3467
|
+
*/
|
|
3468
|
+
var WrongPoolIdError = class extends PanopticError {
|
|
3469
|
+
name = "WrongPoolIdError";
|
|
3470
|
+
constructor(cause) {
|
|
3471
|
+
super("Pool ID mismatch", cause);
|
|
3472
|
+
}
|
|
3473
|
+
};
|
|
3474
|
+
/**
|
|
3475
|
+
* The poolId's don't match (SFPM).
|
|
3476
|
+
* @see Errors.sol:135
|
|
3477
|
+
*/
|
|
3478
|
+
var WrongUniswapPoolError = class extends PanopticError {
|
|
3479
|
+
name = "WrongUniswapPoolError";
|
|
3480
|
+
constructor(cause) {
|
|
3481
|
+
super("Uniswap pool mismatch", cause);
|
|
3482
|
+
}
|
|
3483
|
+
};
|
|
3484
|
+
/**
|
|
3485
|
+
* The caller is not the Panoptic Pool.
|
|
3486
|
+
* @see Errors.sol:87
|
|
3487
|
+
*/
|
|
3488
|
+
var NotPanopticPoolError = class extends PanopticError {
|
|
3489
|
+
name = "NotPanopticPoolError";
|
|
3490
|
+
constructor(cause) {
|
|
3491
|
+
super("Caller is not the Panoptic Pool", cause);
|
|
3492
|
+
}
|
|
3493
|
+
};
|
|
3494
|
+
/**
|
|
3495
|
+
* Can only be called by the guardian.
|
|
3496
|
+
* @see Errors.sol:81
|
|
3497
|
+
*/
|
|
3498
|
+
var NotGuardianError = class extends PanopticError {
|
|
3499
|
+
name = "NotGuardianError";
|
|
3500
|
+
constructor(cause) {
|
|
3501
|
+
super("Caller is not the guardian", cause);
|
|
3502
|
+
}
|
|
3503
|
+
};
|
|
3504
|
+
/**
|
|
3505
|
+
* Can only be called by the Builder.
|
|
3506
|
+
* @see Errors.sol:72
|
|
3507
|
+
*/
|
|
3508
|
+
var NotBuilderError = class extends PanopticError {
|
|
3509
|
+
name = "NotBuilderError";
|
|
3510
|
+
constructor(cause) {
|
|
3511
|
+
super("Caller is not the builder", cause);
|
|
3512
|
+
}
|
|
3513
|
+
};
|
|
3514
|
+
/**
|
|
3515
|
+
* Invalid builder code.
|
|
3516
|
+
* @see Errors.sol:50
|
|
3517
|
+
*/
|
|
3518
|
+
var InvalidBuilderCodeError = class extends PanopticError {
|
|
3519
|
+
name = "InvalidBuilderCodeError";
|
|
3520
|
+
constructor(cause) {
|
|
3521
|
+
super("Invalid builder code", cause);
|
|
3522
|
+
}
|
|
3523
|
+
};
|
|
3524
|
+
/**
|
|
3525
|
+
* Mint or swap callback from invalid address.
|
|
3526
|
+
* @see Errors.sol:57
|
|
3527
|
+
*/
|
|
3528
|
+
var InvalidUniswapCallbackError = class extends PanopticError {
|
|
3529
|
+
name = "InvalidUniswapCallbackError";
|
|
3530
|
+
constructor(cause) {
|
|
3531
|
+
super("Invalid Uniswap callback (address mismatch)", cause);
|
|
3532
|
+
}
|
|
3533
|
+
};
|
|
3534
|
+
/**
|
|
3535
|
+
* Unlock callback from non-canonical pool manager.
|
|
3536
|
+
* @see Errors.sol:123
|
|
3537
|
+
*/
|
|
3538
|
+
var UnauthorizedUniswapCallbackError = class extends PanopticError {
|
|
3539
|
+
name = "UnauthorizedUniswapCallbackError";
|
|
3540
|
+
constructor(cause) {
|
|
3541
|
+
super("Unauthorized Uniswap V4 callback", cause);
|
|
3542
|
+
}
|
|
3543
|
+
};
|
|
3544
|
+
/**
|
|
3545
|
+
* ERC20 or SFPM (ERC1155) token transfer did not complete successfully.
|
|
3546
|
+
* @see Errors.sol:115
|
|
3547
|
+
*/
|
|
3548
|
+
var TransferFailedError = class extends PanopticError {
|
|
3549
|
+
name = "TransferFailedError";
|
|
3550
|
+
constructor(token, from, amount, balance, cause) {
|
|
3551
|
+
super(`Transfer failed: token=${token}, from=${from}, amount=${amount}, balance=${balance}`, cause);
|
|
3552
|
+
this.token = token;
|
|
3553
|
+
this.from = from;
|
|
3554
|
+
this.amount = amount;
|
|
3555
|
+
this.balance = balance;
|
|
3556
|
+
}
|
|
3557
|
+
};
|
|
3558
|
+
/**
|
|
3559
|
+
* Casting error (e.g., uint128(uint256(a)) fails).
|
|
3560
|
+
* @see Errors.sol:13
|
|
3561
|
+
*/
|
|
3562
|
+
var CastingError = class extends PanopticError {
|
|
3563
|
+
name = "CastingError";
|
|
3564
|
+
constructor(cause) {
|
|
3565
|
+
super("Numeric casting overflow", cause);
|
|
3566
|
+
}
|
|
3567
|
+
};
|
|
3568
|
+
/**
|
|
3569
|
+
* Underflow or overflow in library operation.
|
|
3570
|
+
* @see Errors.sol:126
|
|
3571
|
+
*/
|
|
3572
|
+
var UnderOverFlowError = class extends PanopticError {
|
|
3573
|
+
name = "UnderOverFlowError";
|
|
3574
|
+
constructor(cause) {
|
|
3575
|
+
super("Arithmetic underflow or overflow", cause);
|
|
3576
|
+
}
|
|
3577
|
+
};
|
|
3578
|
+
/**
|
|
3579
|
+
* Reentrancy check triggered.
|
|
3580
|
+
* @see Errors.sol:129
|
|
3581
|
+
*/
|
|
3582
|
+
var ReentrancyError = class extends PanopticError {
|
|
3583
|
+
name = "ReentrancyError";
|
|
3584
|
+
constructor(cause) {
|
|
3585
|
+
super("Reentrancy detected", cause);
|
|
3586
|
+
}
|
|
3587
|
+
};
|
|
3588
|
+
/**
|
|
3589
|
+
* Pool deployment via CREATE2 failed.
|
|
3590
|
+
*/
|
|
3591
|
+
var CreateFailError = class extends PanopticError {
|
|
3592
|
+
name = "CreateFailError";
|
|
3593
|
+
constructor(cause) {
|
|
3594
|
+
super("Pool deployment failed (CREATE2)", cause);
|
|
3595
|
+
}
|
|
3596
|
+
};
|
|
3597
|
+
/**
|
|
3598
|
+
* Zero address was supplied as a parameter.
|
|
3599
|
+
* @see Errors.sol:138
|
|
3600
|
+
*/
|
|
3601
|
+
var ZeroAddressError = class extends PanopticError {
|
|
3602
|
+
name = "ZeroAddressError";
|
|
3603
|
+
constructor(cause) {
|
|
3604
|
+
super("Zero address supplied", cause);
|
|
3605
|
+
}
|
|
3606
|
+
};
|
|
3607
|
+
/**
|
|
3608
|
+
* Length mismatch between positionIdList and positionBalanceArray.
|
|
3609
|
+
* @see Errors.sol:60
|
|
3610
|
+
*/
|
|
3611
|
+
var LengthMismatchError = class extends PanopticError {
|
|
3612
|
+
name = "LengthMismatchError";
|
|
3613
|
+
constructor(cause) {
|
|
3614
|
+
super("Array length mismatch", cause);
|
|
3615
|
+
}
|
|
3616
|
+
};
|
|
3617
|
+
|
|
3618
|
+
//#endregion
|
|
3619
|
+
//#region src/panoptic/v2/errors/errorsAbi.ts
|
|
3620
|
+
/**
|
|
3621
|
+
* Custom error ABI definitions for Panoptic v2 contracts.
|
|
3622
|
+
*
|
|
3623
|
+
* Contains all custom errors from Errors.sol with their signatures.
|
|
3624
|
+
* Used for decoding contract revert data.
|
|
3625
|
+
*
|
|
3626
|
+
* Selectors sourced from `forge selectors list` output.
|
|
3627
|
+
*
|
|
3628
|
+
* @module v2/errors/errorsAbi
|
|
3629
|
+
*/
|
|
3630
|
+
/**
|
|
3631
|
+
* All custom errors from Panoptic Errors.sol
|
|
3632
|
+
*
|
|
3633
|
+
* Selector computation: keccak256(errorSignature)[:4]
|
|
3634
|
+
*/
|
|
3635
|
+
const panopticErrorsAbi = [
|
|
3636
|
+
{
|
|
3570
3637
|
type: "error",
|
|
3571
|
-
name: "
|
|
3572
|
-
inputs: [
|
|
3638
|
+
name: "AccountInsolvent",
|
|
3639
|
+
inputs: [{
|
|
3640
|
+
name: "solvent",
|
|
3641
|
+
type: "uint256"
|
|
3642
|
+
}, {
|
|
3643
|
+
name: "numberOfTicks",
|
|
3644
|
+
type: "uint256"
|
|
3645
|
+
}]
|
|
3573
3646
|
},
|
|
3574
3647
|
{
|
|
3575
3648
|
type: "error",
|
|
3576
|
-
name: "
|
|
3649
|
+
name: "AlreadyInitialized",
|
|
3577
3650
|
inputs: []
|
|
3578
3651
|
},
|
|
3579
3652
|
{
|
|
3580
3653
|
type: "error",
|
|
3581
|
-
name: "
|
|
3654
|
+
name: "BelowMinimumRedemption",
|
|
3582
3655
|
inputs: []
|
|
3583
3656
|
},
|
|
3584
3657
|
{
|
|
3585
3658
|
type: "error",
|
|
3586
|
-
name: "
|
|
3659
|
+
name: "CastingError",
|
|
3587
3660
|
inputs: []
|
|
3588
3661
|
},
|
|
3589
3662
|
{
|
|
3590
3663
|
type: "error",
|
|
3591
|
-
name: "
|
|
3664
|
+
name: "ChunkHasZeroLiquidity",
|
|
3592
3665
|
inputs: []
|
|
3593
3666
|
},
|
|
3594
3667
|
{
|
|
3595
3668
|
type: "error",
|
|
3596
|
-
name: "
|
|
3669
|
+
name: "CreateFail",
|
|
3597
3670
|
inputs: []
|
|
3598
3671
|
},
|
|
3599
3672
|
{
|
|
3600
3673
|
type: "error",
|
|
3601
|
-
name: "
|
|
3674
|
+
name: "DepositTooLarge",
|
|
3602
3675
|
inputs: []
|
|
3603
3676
|
},
|
|
3604
3677
|
{
|
|
3605
3678
|
type: "error",
|
|
3606
|
-
name: "
|
|
3607
|
-
inputs: [
|
|
3608
|
-
name: "currentTick",
|
|
3609
|
-
type: "int24"
|
|
3610
|
-
}]
|
|
3679
|
+
name: "DuplicateTokenId",
|
|
3680
|
+
inputs: []
|
|
3611
3681
|
},
|
|
3612
3682
|
{
|
|
3613
3683
|
type: "error",
|
|
3614
|
-
name: "
|
|
3684
|
+
name: "EffectiveLiquidityAboveThreshold",
|
|
3615
3685
|
inputs: []
|
|
3616
3686
|
},
|
|
3617
3687
|
{
|
|
3618
3688
|
type: "error",
|
|
3619
|
-
name: "
|
|
3689
|
+
name: "ExceedsMaximumRedemption",
|
|
3620
3690
|
inputs: []
|
|
3621
3691
|
},
|
|
3622
3692
|
{
|
|
3623
3693
|
type: "error",
|
|
3624
|
-
name: "
|
|
3694
|
+
name: "InputListFail",
|
|
3625
3695
|
inputs: []
|
|
3626
3696
|
},
|
|
3627
3697
|
{
|
|
3628
3698
|
type: "error",
|
|
3629
|
-
name: "
|
|
3699
|
+
name: "InsufficientCreditLiquidity",
|
|
3630
3700
|
inputs: []
|
|
3631
3701
|
},
|
|
3632
3702
|
{
|
|
3633
3703
|
type: "error",
|
|
3634
|
-
name: "
|
|
3704
|
+
name: "InvalidBuilderCode",
|
|
3635
3705
|
inputs: []
|
|
3636
3706
|
},
|
|
3637
3707
|
{
|
|
3638
3708
|
type: "error",
|
|
3639
|
-
name: "
|
|
3640
|
-
inputs: [
|
|
3641
|
-
{
|
|
3642
|
-
name: "token",
|
|
3643
|
-
type: "address"
|
|
3644
|
-
},
|
|
3645
|
-
{
|
|
3646
|
-
name: "from",
|
|
3647
|
-
type: "address"
|
|
3648
|
-
},
|
|
3649
|
-
{
|
|
3650
|
-
name: "amount",
|
|
3651
|
-
type: "uint256"
|
|
3652
|
-
},
|
|
3653
|
-
{
|
|
3654
|
-
name: "balance",
|
|
3655
|
-
type: "uint256"
|
|
3656
|
-
}
|
|
3657
|
-
]
|
|
3709
|
+
name: "InvalidTick",
|
|
3710
|
+
inputs: []
|
|
3658
3711
|
},
|
|
3659
3712
|
{
|
|
3660
3713
|
type: "error",
|
|
3661
|
-
name: "
|
|
3714
|
+
name: "InvalidTickBound",
|
|
3662
3715
|
inputs: []
|
|
3663
3716
|
},
|
|
3664
3717
|
{
|
|
3665
3718
|
type: "error",
|
|
3666
|
-
name: "
|
|
3667
|
-
inputs: [
|
|
3719
|
+
name: "InvalidTokenIdParameter",
|
|
3720
|
+
inputs: [{
|
|
3721
|
+
name: "parameterType",
|
|
3722
|
+
type: "uint256"
|
|
3723
|
+
}]
|
|
3668
3724
|
},
|
|
3669
3725
|
{
|
|
3670
3726
|
type: "error",
|
|
3671
|
-
name: "
|
|
3727
|
+
name: "InvalidUniswapCallback",
|
|
3728
|
+
inputs: []
|
|
3729
|
+
},
|
|
3730
|
+
{
|
|
3731
|
+
type: "error",
|
|
3732
|
+
name: "LengthMismatch",
|
|
3733
|
+
inputs: []
|
|
3734
|
+
},
|
|
3735
|
+
{
|
|
3736
|
+
type: "error",
|
|
3737
|
+
name: "LiquidityTooHigh",
|
|
3738
|
+
inputs: []
|
|
3739
|
+
},
|
|
3740
|
+
{
|
|
3741
|
+
type: "error",
|
|
3742
|
+
name: "NetLiquidityZero",
|
|
3743
|
+
inputs: []
|
|
3744
|
+
},
|
|
3745
|
+
{
|
|
3746
|
+
type: "error",
|
|
3747
|
+
name: "NoLegsExercisable",
|
|
3748
|
+
inputs: []
|
|
3749
|
+
},
|
|
3750
|
+
{
|
|
3751
|
+
type: "error",
|
|
3752
|
+
name: "NotALongLeg",
|
|
3753
|
+
inputs: []
|
|
3754
|
+
},
|
|
3755
|
+
{
|
|
3756
|
+
type: "error",
|
|
3757
|
+
name: "NotBuilder",
|
|
3758
|
+
inputs: []
|
|
3759
|
+
},
|
|
3760
|
+
{
|
|
3761
|
+
type: "error",
|
|
3762
|
+
name: "NotEnoughLiquidityInChunk",
|
|
3763
|
+
inputs: []
|
|
3764
|
+
},
|
|
3765
|
+
{
|
|
3766
|
+
type: "error",
|
|
3767
|
+
name: "NotEnoughTokens",
|
|
3768
|
+
inputs: [
|
|
3769
|
+
{
|
|
3770
|
+
name: "tokenAddress",
|
|
3771
|
+
type: "address"
|
|
3772
|
+
},
|
|
3773
|
+
{
|
|
3774
|
+
name: "assetsRequested",
|
|
3775
|
+
type: "uint256"
|
|
3776
|
+
},
|
|
3777
|
+
{
|
|
3778
|
+
name: "assetBalance",
|
|
3779
|
+
type: "uint256"
|
|
3780
|
+
}
|
|
3781
|
+
]
|
|
3782
|
+
},
|
|
3783
|
+
{
|
|
3784
|
+
type: "error",
|
|
3785
|
+
name: "NotGuardian",
|
|
3786
|
+
inputs: []
|
|
3787
|
+
},
|
|
3788
|
+
{
|
|
3789
|
+
type: "error",
|
|
3790
|
+
name: "NotMarginCalled",
|
|
3791
|
+
inputs: []
|
|
3792
|
+
},
|
|
3793
|
+
{
|
|
3794
|
+
type: "error",
|
|
3795
|
+
name: "NotPanopticPool",
|
|
3796
|
+
inputs: []
|
|
3797
|
+
},
|
|
3798
|
+
{
|
|
3799
|
+
type: "error",
|
|
3800
|
+
name: "PoolNotInitialized",
|
|
3801
|
+
inputs: []
|
|
3802
|
+
},
|
|
3803
|
+
{
|
|
3804
|
+
type: "error",
|
|
3805
|
+
name: "PositionCountNotZero",
|
|
3806
|
+
inputs: []
|
|
3807
|
+
},
|
|
3808
|
+
{
|
|
3809
|
+
type: "error",
|
|
3810
|
+
name: "PositionNotOwned",
|
|
3811
|
+
inputs: []
|
|
3812
|
+
},
|
|
3813
|
+
{
|
|
3814
|
+
type: "error",
|
|
3815
|
+
name: "PositionTooLarge",
|
|
3816
|
+
inputs: []
|
|
3817
|
+
},
|
|
3818
|
+
{
|
|
3819
|
+
type: "error",
|
|
3820
|
+
name: "PriceBoundFail",
|
|
3821
|
+
inputs: [{
|
|
3822
|
+
name: "currentTick",
|
|
3823
|
+
type: "int24"
|
|
3824
|
+
}]
|
|
3825
|
+
},
|
|
3826
|
+
{
|
|
3827
|
+
type: "error",
|
|
3828
|
+
name: "PriceImpactTooLarge",
|
|
3829
|
+
inputs: []
|
|
3830
|
+
},
|
|
3831
|
+
{
|
|
3832
|
+
type: "error",
|
|
3833
|
+
name: "Reentrancy",
|
|
3834
|
+
inputs: []
|
|
3835
|
+
},
|
|
3836
|
+
{
|
|
3837
|
+
type: "error",
|
|
3838
|
+
name: "StaleOracle",
|
|
3839
|
+
inputs: []
|
|
3840
|
+
},
|
|
3841
|
+
{
|
|
3842
|
+
type: "error",
|
|
3843
|
+
name: "TokenIdHasZeroLegs",
|
|
3844
|
+
inputs: []
|
|
3845
|
+
},
|
|
3846
|
+
{
|
|
3847
|
+
type: "error",
|
|
3848
|
+
name: "TooManyLegsOpen",
|
|
3849
|
+
inputs: []
|
|
3850
|
+
},
|
|
3851
|
+
{
|
|
3852
|
+
type: "error",
|
|
3853
|
+
name: "TransferFailed",
|
|
3854
|
+
inputs: [
|
|
3855
|
+
{
|
|
3856
|
+
name: "token",
|
|
3857
|
+
type: "address"
|
|
3858
|
+
},
|
|
3859
|
+
{
|
|
3860
|
+
name: "from",
|
|
3861
|
+
type: "address"
|
|
3862
|
+
},
|
|
3863
|
+
{
|
|
3864
|
+
name: "amount",
|
|
3865
|
+
type: "uint256"
|
|
3866
|
+
},
|
|
3867
|
+
{
|
|
3868
|
+
name: "balance",
|
|
3869
|
+
type: "uint256"
|
|
3870
|
+
}
|
|
3871
|
+
]
|
|
3872
|
+
},
|
|
3873
|
+
{
|
|
3874
|
+
type: "error",
|
|
3875
|
+
name: "UnauthorizedUniswapCallback",
|
|
3876
|
+
inputs: []
|
|
3877
|
+
},
|
|
3878
|
+
{
|
|
3879
|
+
type: "error",
|
|
3880
|
+
name: "UnderOverFlow",
|
|
3881
|
+
inputs: []
|
|
3882
|
+
},
|
|
3883
|
+
{
|
|
3884
|
+
type: "error",
|
|
3885
|
+
name: "WrongPoolId",
|
|
3672
3886
|
inputs: []
|
|
3673
3887
|
},
|
|
3674
3888
|
{
|
|
@@ -3700,6 +3914,515 @@ const combinedAbi = [
|
|
|
3700
3914
|
...riskEngineAbi,
|
|
3701
3915
|
...panopticErrorsAbi
|
|
3702
3916
|
];
|
|
3917
|
+
/**
|
|
3918
|
+
* Map of error names to error constructors.
|
|
3919
|
+
*/
|
|
3920
|
+
const errorConstructors = {
|
|
3921
|
+
AccountInsolvent: (args, cause) => new AccountInsolventError(args[0], args[1], cause),
|
|
3922
|
+
NotMarginCalled: (_args, cause) => new NotMarginCalledError(cause),
|
|
3923
|
+
CreateFail: (_args, cause) => new CreateFailError(cause),
|
|
3924
|
+
NotEnoughTokens: (args, cause) => new NotEnoughTokensError(args[0], args[1], args[2], cause),
|
|
3925
|
+
NotEnoughLiquidityInChunk: (_args, cause) => new NotEnoughLiquidityInChunkError(cause),
|
|
3926
|
+
InsufficientCreditLiquidity: (_args, cause) => new InsufficientCreditLiquidityError(cause),
|
|
3927
|
+
DepositTooLarge: (_args, cause) => new DepositTooLargeError(cause),
|
|
3928
|
+
BelowMinimumRedemption: (_args, cause) => new BelowMinimumRedemptionError(cause),
|
|
3929
|
+
ExceedsMaximumRedemption: (_args, cause) => new ExceedsMaximumRedemptionError(cause),
|
|
3930
|
+
ZeroCollateralRequirement: (_args, cause) => new ZeroCollateralRequirementError(cause),
|
|
3931
|
+
InvalidTokenIdParameter: (args, cause) => new InvalidTokenIdParameterError(args[0], cause),
|
|
3932
|
+
PositionNotOwned: (_args, cause) => new PositionNotOwnedError(cause),
|
|
3933
|
+
PositionTooLarge: (_args, cause) => new PositionTooLargeError(cause),
|
|
3934
|
+
PositionCountNotZero: (_args, cause) => new PositionCountNotZeroError(cause),
|
|
3935
|
+
DuplicateTokenId: (_args, cause) => new DuplicateTokenIdError(cause),
|
|
3936
|
+
TokenIdHasZeroLegs: (_args, cause) => new TokenIdHasZeroLegsError(cause),
|
|
3937
|
+
TooManyLegsOpen: (_args, cause) => new TooManyLegsOpenError(cause),
|
|
3938
|
+
InputListFail: (_args, cause) => new InputListFailError(cause),
|
|
3939
|
+
InvalidTick: (_args, cause) => new InvalidTickError(cause),
|
|
3940
|
+
InvalidTickBound: (_args, cause) => new InvalidTickBoundError(cause),
|
|
3941
|
+
PriceBoundFail: (args, cause) => new PriceBoundFailError(args[0], cause),
|
|
3942
|
+
PriceImpactTooLarge: (_args, cause) => new PriceImpactTooLargeError(cause),
|
|
3943
|
+
ChunkHasZeroLiquidity: (_args, cause) => new ChunkHasZeroLiquidityError(cause),
|
|
3944
|
+
LiquidityTooHigh: (_args, cause) => new LiquidityTooHighError(cause),
|
|
3945
|
+
NetLiquidityZero: (_args, cause) => new NetLiquidityZeroError(cause),
|
|
3946
|
+
EffectiveLiquidityAboveThreshold: (_args, cause) => new EffectiveLiquidityAboveThresholdError(cause),
|
|
3947
|
+
StaleOracle: (_args, cause) => new StaleOracleError(cause),
|
|
3948
|
+
NoLegsExercisable: (_args, cause) => new NoLegsExercisableError(cause),
|
|
3949
|
+
NotALongLeg: (_args, cause) => new NotALongLegError(cause),
|
|
3950
|
+
PoolNotInitialized: (_args, cause) => new PoolNotInitializedError(cause),
|
|
3951
|
+
AlreadyInitialized: (_args, cause) => new AlreadyInitializedError(cause),
|
|
3952
|
+
WrongPoolId: (_args, cause) => new WrongPoolIdError(cause),
|
|
3953
|
+
WrongUniswapPool: (_args, cause) => new WrongUniswapPoolError(cause),
|
|
3954
|
+
NotPanopticPool: (_args, cause) => new NotPanopticPoolError(cause),
|
|
3955
|
+
NotGuardian: (_args, cause) => new NotGuardianError(cause),
|
|
3956
|
+
NotBuilder: (_args, cause) => new NotBuilderError(cause),
|
|
3957
|
+
InvalidBuilderCode: (_args, cause) => new InvalidBuilderCodeError(cause),
|
|
3958
|
+
InvalidUniswapCallback: (_args, cause) => new InvalidUniswapCallbackError(cause),
|
|
3959
|
+
UnauthorizedUniswapCallback: (_args, cause) => new UnauthorizedUniswapCallbackError(cause),
|
|
3960
|
+
TransferFailed: (args, cause) => new TransferFailedError(args[0], args[1], args[2], args[3], cause),
|
|
3961
|
+
CastingError: (_args, cause) => new CastingError(cause),
|
|
3962
|
+
UnderOverFlow: (_args, cause) => new UnderOverFlowError(cause),
|
|
3963
|
+
Reentrancy: (_args, cause) => new ReentrancyError(cause),
|
|
3964
|
+
ZeroAddress: (_args, cause) => new ZeroAddressError(cause),
|
|
3965
|
+
LengthMismatch: (_args, cause) => new LengthMismatchError(cause)
|
|
3966
|
+
};
|
|
3967
|
+
/**
|
|
3968
|
+
* Parse a raw contract error into a typed SDK error.
|
|
3969
|
+
*
|
|
3970
|
+
* This function attempts to decode the error data from a failed contract call
|
|
3971
|
+
* and return a typed error instance with extracted parameters.
|
|
3972
|
+
*
|
|
3973
|
+
* @param error - The raw error from a failed contract call
|
|
3974
|
+
* @returns Parsed error with typed error instance, or null if parsing fails
|
|
3975
|
+
*
|
|
3976
|
+
* @example
|
|
3977
|
+
* ```typescript
|
|
3978
|
+
* try {
|
|
3979
|
+
* await contract.openPosition(...)
|
|
3980
|
+
* } catch (rawError) {
|
|
3981
|
+
* const parsed = parsePanopticError(rawError)
|
|
3982
|
+
* if (parsed) {
|
|
3983
|
+
* console.log('Error:', parsed.errorName)
|
|
3984
|
+
* if (parsed.error instanceof AccountInsolventError) {
|
|
3985
|
+
* console.log('Solvent value:', parsed.error.solvent)
|
|
3986
|
+
* }
|
|
3987
|
+
* }
|
|
3988
|
+
* }
|
|
3989
|
+
* ```
|
|
3990
|
+
*/
|
|
3991
|
+
function parsePanopticError(error) {
|
|
3992
|
+
const viemDecoded = extractViemDecodedError(error);
|
|
3993
|
+
if (viemDecoded) return buildParsedError(viemDecoded.errorName, viemDecoded.args, error);
|
|
3994
|
+
const errorData = extractErrorData(error);
|
|
3995
|
+
if (!errorData) return null;
|
|
3996
|
+
try {
|
|
3997
|
+
const decoded = decodeErrorResult({
|
|
3998
|
+
abi: combinedAbi,
|
|
3999
|
+
data: errorData
|
|
4000
|
+
});
|
|
4001
|
+
return buildParsedError(decoded.errorName, decoded.args ?? [], error);
|
|
4002
|
+
} catch {
|
|
4003
|
+
if (errorData.length >= 10) {
|
|
4004
|
+
const selector = errorData.slice(0, 10);
|
|
4005
|
+
const match = matchSelectorToErrorName(selector);
|
|
4006
|
+
if (match) return buildParsedError(match, [], error);
|
|
4007
|
+
}
|
|
4008
|
+
return null;
|
|
4009
|
+
}
|
|
4010
|
+
}
|
|
4011
|
+
/**
|
|
4012
|
+
* Walk the cause chain looking for a viem ContractFunctionRevertedError
|
|
4013
|
+
* that already has decoded `.data` (an object with `errorName` and `args`).
|
|
4014
|
+
* This happens when the ABI passed to simulateContract includes the error definitions.
|
|
4015
|
+
*/
|
|
4016
|
+
function extractViemDecodedError(error) {
|
|
4017
|
+
if (!error || typeof error !== "object") return null;
|
|
4018
|
+
if (error instanceof BaseError) {
|
|
4019
|
+
let found = null;
|
|
4020
|
+
error.walk((e) => {
|
|
4021
|
+
if (found) return false;
|
|
4022
|
+
const node = e;
|
|
4023
|
+
if (node.data && typeof node.data === "object" && "errorName" in node.data && typeof node.data.errorName === "string") {
|
|
4024
|
+
const data = node.data;
|
|
4025
|
+
found = {
|
|
4026
|
+
errorName: data.errorName,
|
|
4027
|
+
args: data.args ?? []
|
|
4028
|
+
};
|
|
4029
|
+
return true;
|
|
4030
|
+
}
|
|
4031
|
+
return false;
|
|
4032
|
+
});
|
|
4033
|
+
return found;
|
|
4034
|
+
}
|
|
4035
|
+
let current = error;
|
|
4036
|
+
for (let i = 0; i < 10 && current; i++) {
|
|
4037
|
+
if (current.data && typeof current.data === "object" && "errorName" in current.data && typeof current.data.errorName === "string") {
|
|
4038
|
+
const data = current.data;
|
|
4039
|
+
return {
|
|
4040
|
+
errorName: data.errorName,
|
|
4041
|
+
args: data.args ?? []
|
|
4042
|
+
};
|
|
4043
|
+
}
|
|
4044
|
+
current = current.cause && typeof current.cause === "object" ? current.cause : null;
|
|
4045
|
+
}
|
|
4046
|
+
return null;
|
|
4047
|
+
}
|
|
4048
|
+
/**
|
|
4049
|
+
* Build a ParsedError from a decoded error name and args.
|
|
4050
|
+
*/
|
|
4051
|
+
function buildParsedError(errorName, args, originalError) {
|
|
4052
|
+
const constructor = errorConstructors[errorName];
|
|
4053
|
+
const cause = originalError instanceof Error ? originalError : void 0;
|
|
4054
|
+
if (!constructor) {
|
|
4055
|
+
const unknownError = new PanopticError(`Unknown contract error: ${errorName}`);
|
|
4056
|
+
unknownError.errorName = errorName;
|
|
4057
|
+
return {
|
|
4058
|
+
error: unknownError,
|
|
4059
|
+
errorName,
|
|
4060
|
+
args
|
|
4061
|
+
};
|
|
4062
|
+
}
|
|
4063
|
+
const typedError = constructor(args, cause);
|
|
4064
|
+
typedError.errorName = errorName;
|
|
4065
|
+
return {
|
|
4066
|
+
error: typedError,
|
|
4067
|
+
errorName,
|
|
4068
|
+
args
|
|
4069
|
+
};
|
|
4070
|
+
}
|
|
4071
|
+
/**
|
|
4072
|
+
* Match a 4-byte selector against the panoptic errors ABI.
|
|
4073
|
+
* Used as fallback when we only have the selector (no encoded args).
|
|
4074
|
+
*/
|
|
4075
|
+
function matchSelectorToErrorName(selector) {
|
|
4076
|
+
for (const item of panopticErrorsAbi) {
|
|
4077
|
+
if (item.type !== "error") continue;
|
|
4078
|
+
const computed = toFunctionSelector(`${item.name}(${item.inputs.map((i) => i.type).join(",")})`);
|
|
4079
|
+
if (computed === selector) return item.name;
|
|
4080
|
+
}
|
|
4081
|
+
return null;
|
|
4082
|
+
}
|
|
4083
|
+
/**
|
|
4084
|
+
* Extract error data from various error formats.
|
|
4085
|
+
*
|
|
4086
|
+
* Strategy:
|
|
4087
|
+
* 1. Use viem's BaseError.walk() to traverse the full cause chain and find
|
|
4088
|
+
* hex data on any node (handles arbitrary nesting depth for multicall etc.)
|
|
4089
|
+
* 2. Fall back to manual cause-chain walk for non-viem errors
|
|
4090
|
+
* 3. Last resort: extract selector from error message (loses args)
|
|
4091
|
+
*/
|
|
4092
|
+
function extractErrorData(error) {
|
|
4093
|
+
if (!error) return null;
|
|
4094
|
+
if (typeof error === "string" && error.startsWith("0x")) return error;
|
|
4095
|
+
if (typeof error !== "object") return null;
|
|
4096
|
+
if (error instanceof BaseError) {
|
|
4097
|
+
let foundData = null;
|
|
4098
|
+
error.walk((e) => {
|
|
4099
|
+
if (foundData) return false;
|
|
4100
|
+
const node = e;
|
|
4101
|
+
if (typeof node.raw === "string" && node.raw.startsWith("0x") && node.raw.length > 10) {
|
|
4102
|
+
foundData = node.raw;
|
|
4103
|
+
return true;
|
|
4104
|
+
}
|
|
4105
|
+
if (node.data && typeof node.data === "string" && node.data.startsWith("0x")) {
|
|
4106
|
+
foundData = node.data;
|
|
4107
|
+
return true;
|
|
4108
|
+
}
|
|
4109
|
+
if (node.data && typeof node.data === "object") {
|
|
4110
|
+
const nested = node.data;
|
|
4111
|
+
if (nested.data && typeof nested.data === "string" && nested.data.startsWith("0x")) {
|
|
4112
|
+
foundData = nested.data;
|
|
4113
|
+
return true;
|
|
4114
|
+
}
|
|
4115
|
+
}
|
|
4116
|
+
return false;
|
|
4117
|
+
});
|
|
4118
|
+
if (foundData) return foundData;
|
|
4119
|
+
error.walk((e) => {
|
|
4120
|
+
if (foundData) return false;
|
|
4121
|
+
const node = e;
|
|
4122
|
+
if (node.signature && typeof node.signature === "string" && node.signature.startsWith("0x")) {
|
|
4123
|
+
foundData = node.signature;
|
|
4124
|
+
return true;
|
|
4125
|
+
}
|
|
4126
|
+
return false;
|
|
4127
|
+
});
|
|
4128
|
+
if (foundData) return foundData;
|
|
4129
|
+
}
|
|
4130
|
+
let current = error;
|
|
4131
|
+
const maxDepth = 10;
|
|
4132
|
+
for (let i = 0; i < maxDepth && current; i++) {
|
|
4133
|
+
if (typeof current.raw === "string" && current.raw.startsWith("0x") && current.raw.length > 10) return current.raw;
|
|
4134
|
+
if (current.data && typeof current.data === "string" && current.data.startsWith("0x")) return current.data;
|
|
4135
|
+
if (current.data && typeof current.data === "object") {
|
|
4136
|
+
const nested = current.data;
|
|
4137
|
+
if (nested.data && typeof nested.data === "string" && nested.data.startsWith("0x")) return nested.data;
|
|
4138
|
+
}
|
|
4139
|
+
if (current.error && typeof current.error === "object") {
|
|
4140
|
+
const rpcError = current.error;
|
|
4141
|
+
if (rpcError.data && typeof rpcError.data === "string" && rpcError.data.startsWith("0x")) return rpcError.data;
|
|
4142
|
+
}
|
|
4143
|
+
current = current.cause && typeof current.cause === "object" ? current.cause : null;
|
|
4144
|
+
}
|
|
4145
|
+
const obj = error;
|
|
4146
|
+
if (obj.message && typeof obj.message === "string") {
|
|
4147
|
+
const signatureMatch = obj.message.match(/signature:?\s*["']?(0x[a-fA-F0-9]{8,})/i);
|
|
4148
|
+
if (signatureMatch) return signatureMatch[1];
|
|
4149
|
+
}
|
|
4150
|
+
return null;
|
|
4151
|
+
}
|
|
4152
|
+
|
|
4153
|
+
//#endregion
|
|
4154
|
+
//#region src/panoptic/v2/writes/utils.ts
|
|
4155
|
+
/**
|
|
4156
|
+
* Decode PositionBalance packed data.
|
|
4157
|
+
*
|
|
4158
|
+
* Layout (from LSB to MSB):
|
|
4159
|
+
* - positionSize: bits 0-127 (uint128)
|
|
4160
|
+
* - poolUtilization0: bits 128-143 (uint16)
|
|
4161
|
+
* - poolUtilization1: bits 144-159 (uint16)
|
|
4162
|
+
* - tickAtMint: bits 160-183 (int24)
|
|
4163
|
+
* - timestampAtMint: bits 184-215 (uint32)
|
|
4164
|
+
* - blockAtMint: bits 216-254 (uint39)
|
|
4165
|
+
* - swapAtMint: bit 255 (bool)
|
|
4166
|
+
*/
|
|
4167
|
+
function decodePositionBalance(balanceData) {
|
|
4168
|
+
const positionSize = balanceData & (1n << 128n) - 1n;
|
|
4169
|
+
const poolUtilization0 = balanceData >> 128n & 0xffffn;
|
|
4170
|
+
const poolUtilization1 = balanceData >> 144n & 0xffffn;
|
|
4171
|
+
let tickAtMint = balanceData >> 160n & 0xffffffn;
|
|
4172
|
+
if (tickAtMint > 0x7fffffn) tickAtMint = tickAtMint - 0x1000000n;
|
|
4173
|
+
const timestampAtMint = balanceData >> 184n & 0xffffffffn;
|
|
4174
|
+
const blockAtMint = balanceData >> 216n & (1n << 39n) - 1n;
|
|
4175
|
+
const swapAtMint = balanceData >> 255n === 1n;
|
|
4176
|
+
return {
|
|
4177
|
+
positionSize,
|
|
4178
|
+
poolUtilization0,
|
|
4179
|
+
poolUtilization1,
|
|
4180
|
+
tickAtMint,
|
|
4181
|
+
timestampAtMint,
|
|
4182
|
+
blockAtMint,
|
|
4183
|
+
swapAtMint
|
|
4184
|
+
};
|
|
4185
|
+
}
|
|
4186
|
+
/**
|
|
4187
|
+
* Decode LeftRightSigned packed value.
|
|
4188
|
+
*/
|
|
4189
|
+
function decodeLeftRightSigned(value) {
|
|
4190
|
+
let right = value & (1n << 128n) - 1n;
|
|
4191
|
+
let left = value >> 128n;
|
|
4192
|
+
if (right >= 1n << 127n) right = right - (1n << 128n);
|
|
4193
|
+
if (left >= 1n << 127n) left = left - (1n << 128n);
|
|
4194
|
+
return {
|
|
4195
|
+
right,
|
|
4196
|
+
left
|
|
4197
|
+
};
|
|
4198
|
+
}
|
|
4199
|
+
/**
|
|
4200
|
+
* Parse Panoptic events from transaction logs.
|
|
4201
|
+
*
|
|
4202
|
+
* @param logs - The transaction logs
|
|
4203
|
+
* @returns Parsed Panoptic events
|
|
4204
|
+
*/
|
|
4205
|
+
function parsePanopticEvents(logs) {
|
|
4206
|
+
const events = [];
|
|
4207
|
+
for (const log of logs) {
|
|
4208
|
+
const baseEvent = {
|
|
4209
|
+
blockNumber: log.blockNumber ?? 0n,
|
|
4210
|
+
blockHash: log.blockHash ?? "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
4211
|
+
transactionHash: log.transactionHash ?? "0x",
|
|
4212
|
+
logIndex: BigInt(log.logIndex ?? 0)
|
|
4213
|
+
};
|
|
4214
|
+
try {
|
|
4215
|
+
const poolEvent = decodeEventLog({
|
|
4216
|
+
abi: panopticPoolV2Abi,
|
|
4217
|
+
data: log.data,
|
|
4218
|
+
topics: log.topics
|
|
4219
|
+
});
|
|
4220
|
+
if (poolEvent.eventName === "OptionMinted") {
|
|
4221
|
+
const args = poolEvent.args;
|
|
4222
|
+
const balance = decodePositionBalance(args.balanceData);
|
|
4223
|
+
events.push({
|
|
4224
|
+
type: "OptionMinted",
|
|
4225
|
+
...baseEvent,
|
|
4226
|
+
recipient: args.recipient,
|
|
4227
|
+
tokenId: args.tokenId,
|
|
4228
|
+
positionSize: balance.positionSize,
|
|
4229
|
+
poolUtilization0: balance.poolUtilization0,
|
|
4230
|
+
poolUtilization1: balance.poolUtilization1,
|
|
4231
|
+
tickAtMint: balance.tickAtMint,
|
|
4232
|
+
timestampAtMint: balance.timestampAtMint,
|
|
4233
|
+
blockAtMint: balance.blockAtMint,
|
|
4234
|
+
swapAtMint: balance.swapAtMint
|
|
4235
|
+
});
|
|
4236
|
+
} else if (poolEvent.eventName === "OptionBurnt") {
|
|
4237
|
+
const args = poolEvent.args;
|
|
4238
|
+
events.push({
|
|
4239
|
+
type: "OptionBurnt",
|
|
4240
|
+
...baseEvent,
|
|
4241
|
+
recipient: args.recipient,
|
|
4242
|
+
tokenId: args.tokenId,
|
|
4243
|
+
positionSize: args.positionSize,
|
|
4244
|
+
premiaByLeg: [
|
|
4245
|
+
args.premiaByLeg[0] ?? 0n,
|
|
4246
|
+
args.premiaByLeg[1] ?? 0n,
|
|
4247
|
+
args.premiaByLeg[2] ?? 0n,
|
|
4248
|
+
args.premiaByLeg[3] ?? 0n
|
|
4249
|
+
]
|
|
4250
|
+
});
|
|
4251
|
+
} else if (poolEvent.eventName === "AccountLiquidated") {
|
|
4252
|
+
const args = poolEvent.args;
|
|
4253
|
+
const { right, left } = decodeLeftRightSigned(args.bonusAmounts);
|
|
4254
|
+
events.push({
|
|
4255
|
+
type: "AccountLiquidated",
|
|
4256
|
+
...baseEvent,
|
|
4257
|
+
liquidator: args.liquidator,
|
|
4258
|
+
liquidatee: args.liquidatee,
|
|
4259
|
+
bonusAmount0: right,
|
|
4260
|
+
bonusAmount1: left
|
|
4261
|
+
});
|
|
4262
|
+
} else if (poolEvent.eventName === "ForcedExercised") {
|
|
4263
|
+
const args = poolEvent.args;
|
|
4264
|
+
const { right, left } = decodeLeftRightSigned(args.exerciseFee);
|
|
4265
|
+
events.push({
|
|
4266
|
+
type: "ForcedExercised",
|
|
4267
|
+
...baseEvent,
|
|
4268
|
+
exercisor: args.exercisor,
|
|
4269
|
+
user: args.user,
|
|
4270
|
+
tokenId: args.tokenId,
|
|
4271
|
+
exerciseFee0: right,
|
|
4272
|
+
exerciseFee1: left
|
|
4273
|
+
});
|
|
4274
|
+
} else if (poolEvent.eventName === "PremiumSettled") {
|
|
4275
|
+
const args = poolEvent.args;
|
|
4276
|
+
const { right, left } = decodeLeftRightSigned(args.settledAmounts);
|
|
4277
|
+
events.push({
|
|
4278
|
+
type: "PremiumSettled",
|
|
4279
|
+
...baseEvent,
|
|
4280
|
+
user: args.user,
|
|
4281
|
+
tokenId: args.tokenId,
|
|
4282
|
+
legIndex: args.legIndex,
|
|
4283
|
+
settledAmount0: right,
|
|
4284
|
+
settledAmount1: left
|
|
4285
|
+
});
|
|
4286
|
+
}
|
|
4287
|
+
} catch {
|
|
4288
|
+
try {
|
|
4289
|
+
const collateralEvent = decodeEventLog({
|
|
4290
|
+
abi: collateralTrackerV2Abi,
|
|
4291
|
+
data: log.data,
|
|
4292
|
+
topics: log.topics
|
|
4293
|
+
});
|
|
4294
|
+
if (collateralEvent.eventName === "Deposit") {
|
|
4295
|
+
const args = collateralEvent.args;
|
|
4296
|
+
events.push({
|
|
4297
|
+
type: "Deposit",
|
|
4298
|
+
...baseEvent,
|
|
4299
|
+
sender: args.sender,
|
|
4300
|
+
owner: args.owner,
|
|
4301
|
+
assets: args.assets,
|
|
4302
|
+
shares: args.shares
|
|
4303
|
+
});
|
|
4304
|
+
} else if (collateralEvent.eventName === "Withdraw") {
|
|
4305
|
+
const args = collateralEvent.args;
|
|
4306
|
+
events.push({
|
|
4307
|
+
type: "Withdraw",
|
|
4308
|
+
...baseEvent,
|
|
4309
|
+
sender: args.sender,
|
|
4310
|
+
receiver: args.receiver,
|
|
4311
|
+
owner: args.owner,
|
|
4312
|
+
assets: args.assets,
|
|
4313
|
+
shares: args.shares
|
|
4314
|
+
});
|
|
4315
|
+
}
|
|
4316
|
+
} catch {}
|
|
4317
|
+
}
|
|
4318
|
+
}
|
|
4319
|
+
return events;
|
|
4320
|
+
}
|
|
4321
|
+
/**
|
|
4322
|
+
* Create a TxResult from a transaction hash.
|
|
4323
|
+
*
|
|
4324
|
+
* @param client - The public client
|
|
4325
|
+
* @param hash - The transaction hash
|
|
4326
|
+
* @returns TxResult with wait function
|
|
4327
|
+
*/
|
|
4328
|
+
function createTxResult(client, hash) {
|
|
4329
|
+
return {
|
|
4330
|
+
hash,
|
|
4331
|
+
wait: async (confirmations) => {
|
|
4332
|
+
const receipt = await client.waitForTransactionReceipt({
|
|
4333
|
+
hash,
|
|
4334
|
+
confirmations: confirmations !== void 0 ? Number(confirmations) : void 0
|
|
4335
|
+
});
|
|
4336
|
+
const events = parsePanopticEvents(receipt.logs);
|
|
4337
|
+
return {
|
|
4338
|
+
hash: receipt.transactionHash,
|
|
4339
|
+
blockNumber: receipt.blockNumber,
|
|
4340
|
+
blockHash: receipt.blockHash,
|
|
4341
|
+
gasUsed: receipt.gasUsed,
|
|
4342
|
+
status: receipt.status === "success" ? "success" : "reverted",
|
|
4343
|
+
events
|
|
4344
|
+
};
|
|
4345
|
+
}
|
|
4346
|
+
};
|
|
4347
|
+
}
|
|
4348
|
+
/**
|
|
4349
|
+
* Submit a write operation, supporting both direct wallet submission
|
|
4350
|
+
* and custom broadcaster paths with gas overrides.
|
|
4351
|
+
*
|
|
4352
|
+
* Normal path (no broadcaster): calls walletClient.writeContract() with gas overrides.
|
|
4353
|
+
* Broadcaster path: prepareTransactionRequest → apply overrides → signTransaction → broadcast.
|
|
4354
|
+
*
|
|
4355
|
+
* @param params - Submit write parameters
|
|
4356
|
+
* @returns TxResult
|
|
4357
|
+
*/
|
|
4358
|
+
async function submitWrite(params) {
|
|
4359
|
+
try {
|
|
4360
|
+
return await submitWriteRequest({
|
|
4361
|
+
...params,
|
|
4362
|
+
abi: [...params.abi, ...panopticErrorsAbi]
|
|
4363
|
+
});
|
|
4364
|
+
} catch (error) {
|
|
4365
|
+
if (error instanceof PanopticError) throw error;
|
|
4366
|
+
throw parsePanopticError(error)?.error ?? error;
|
|
4367
|
+
}
|
|
4368
|
+
}
|
|
4369
|
+
async function submitWriteRequest(params) {
|
|
4370
|
+
const { client, walletClient, account, address, abi, functionName, args, value, txOverrides } = params;
|
|
4371
|
+
const broadcaster = txOverrides?.broadcaster;
|
|
4372
|
+
if (broadcaster) {
|
|
4373
|
+
const data = encodeFunctionData({
|
|
4374
|
+
abi,
|
|
4375
|
+
functionName,
|
|
4376
|
+
args
|
|
4377
|
+
});
|
|
4378
|
+
const broadcastAccount = walletClient.account ?? account;
|
|
4379
|
+
const request = await walletClient.prepareTransactionRequest({
|
|
4380
|
+
account: broadcastAccount,
|
|
4381
|
+
to: address,
|
|
4382
|
+
chain: walletClient.chain,
|
|
4383
|
+
data,
|
|
4384
|
+
...value !== void 0 && { value },
|
|
4385
|
+
...txOverrides?.maxFeePerGas !== void 0 && { maxFeePerGas: txOverrides.maxFeePerGas },
|
|
4386
|
+
...txOverrides?.maxPriorityFeePerGas !== void 0 && { maxPriorityFeePerGas: txOverrides.maxPriorityFeePerGas },
|
|
4387
|
+
...txOverrides?.gas !== void 0 && { gas: txOverrides.gas },
|
|
4388
|
+
...txOverrides?.nonce !== void 0 && { nonce: Number(txOverrides.nonce) }
|
|
4389
|
+
});
|
|
4390
|
+
const signedTx = await walletClient.signTransaction({
|
|
4391
|
+
...request,
|
|
4392
|
+
account: broadcastAccount
|
|
4393
|
+
});
|
|
4394
|
+
const hash$1 = await broadcaster.broadcast(signedTx);
|
|
4395
|
+
return createTxResult(client, hash$1);
|
|
4396
|
+
}
|
|
4397
|
+
const gasOverrides = {};
|
|
4398
|
+
if (txOverrides?.maxFeePerGas !== void 0) gasOverrides.maxFeePerGas = txOverrides.maxFeePerGas;
|
|
4399
|
+
if (txOverrides?.maxPriorityFeePerGas !== void 0) gasOverrides.maxPriorityFeePerGas = txOverrides.maxPriorityFeePerGas;
|
|
4400
|
+
if (txOverrides?.nonce !== void 0) gasOverrides.nonce = Number(txOverrides.nonce);
|
|
4401
|
+
const resolvedAccount = walletClient.account ?? account;
|
|
4402
|
+
if (txOverrides?.gas !== void 0) gasOverrides.gas = txOverrides.gas;
|
|
4403
|
+
else {
|
|
4404
|
+
const estimated = await client.estimateContractGas({
|
|
4405
|
+
address,
|
|
4406
|
+
abi,
|
|
4407
|
+
functionName,
|
|
4408
|
+
args,
|
|
4409
|
+
account: resolvedAccount,
|
|
4410
|
+
...value !== void 0 && { value }
|
|
4411
|
+
});
|
|
4412
|
+
gasOverrides.gas = estimated * 120n / 100n;
|
|
4413
|
+
}
|
|
4414
|
+
const hash = await walletClient.writeContract({
|
|
4415
|
+
address,
|
|
4416
|
+
abi,
|
|
4417
|
+
functionName,
|
|
4418
|
+
args,
|
|
4419
|
+
account: resolvedAccount,
|
|
4420
|
+
chain: walletClient.chain,
|
|
4421
|
+
...value !== void 0 && { value },
|
|
4422
|
+
...gasOverrides
|
|
4423
|
+
});
|
|
4424
|
+
return createTxResult(client, hash);
|
|
4425
|
+
}
|
|
3703
4426
|
|
|
3704
4427
|
//#endregion
|
|
3705
4428
|
//#region src/panoptic/v2/utils/constants.ts
|