@panoptic-eng/sdk 1.0.20 → 1.0.22
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 +3 -3
- package/dist/{cow-Cqw3sako.js → cow-C_SGXoWr.js} +2 -2
- package/dist/{cow-Cqw3sako.js.map → cow-C_SGXoWr.js.map} +1 -1
- package/dist/index.d.ts +696 -5907
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1393 -579
- package/dist/index.js.map +1 -1
- package/dist/irm-C7OUVANR.d.ts +5641 -0
- package/dist/irm-C7OUVANR.d.ts.map +1 -0
- package/dist/{irm-DF4NwYIY.js → irm-DNK3N7qk.js} +301 -3
- package/dist/irm-DNK3N7qk.js.map +1 -0
- package/dist/panoptic/v2/index.d.ts +12 -4
- package/dist/panoptic/v2/index.d.ts.map +1 -1
- package/dist/panoptic/v2/index.js +25 -10
- package/dist/panoptic/v2/index.js.map +1 -1
- package/dist/{position-zqvENVuf.js → position-BK4a-Yyu.js} +2 -2
- package/dist/{position-zqvENVuf.js.map → position-BK4a-Yyu.js.map} +1 -1
- package/dist/{router-d09dxd-F.js → router-BZvOeloX.js} +90 -40
- package/dist/router-BZvOeloX.js.map +1 -0
- package/dist/test/index.d.ts +2 -2
- package/dist/test/index.d.ts.map +1 -1
- package/dist/uniswap/index.d.ts +118 -1
- package/dist/uniswap/index.d.ts.map +1 -1
- package/dist/uniswap/index.js +228 -4
- package/dist/uniswap/index.js.map +1 -0
- package/dist/{writes-CRjVFjMt.js → writes-DymnVbiE.js} +2 -2
- package/dist/{writes-CRjVFjMt.js.map → writes-DymnVbiE.js.map} +1 -1
- package/dist/zodiac/index.d.ts +444 -0
- package/dist/zodiac/index.d.ts.map +1 -0
- package/dist/zodiac/index.js +949 -0
- package/dist/zodiac/index.js.map +1 -0
- package/package.json +6 -1
- package/dist/irm-DF4NwYIY.js.map +0 -1
- package/dist/irm-zWjtffWA.d.ts +0 -85
- package/dist/irm-zWjtffWA.d.ts.map +0 -1
- package/dist/router-d09dxd-F.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["params: {\n publicClient: ScopeStepsPublicClient\n walletClient: ScopeStepsWalletClient\n rolesModifier: `0x${string}`\n steps: ScopeStep[]\n log?: (line: string) => void\n /**\n * EIP-1559 fee overrides applied to every tx. Pass a NON-ZERO\n * `maxPriorityFeePerGas` — some RPC estimators return a zero tip, which leaves\n * txs un-prioritised and slow to include.\n */\n fees?: { maxFeePerGas?: bigint; maxPriorityFeePerGas?: bigint }\n /** Receipt-wait timeout (ms). */\n timeoutMs?: number\n}","v: string","addr: `0x${string}`","adapter: `0x${string}`","extra: Hex","cap: bigint","name: string","adapter: `0x${string}`","extra: Hex","params: {\n roleName: string\n roleKey: Hex\n member: `0x${string}`\n pool: `0x${string}`\n adapter: `0x${string}`\n extra?: Hex\n}","params: {\n member: `0x${string}`\n pool: `0x${string}`\n roleKey?: Hex\n}","fieldOffset: bigint","bits: bigint","tokenId: bigint","v: bigint","shiftBytes: number","safe: `0x${string}`","safe: `0x${string}`","params: {\n member: `0x${string}`\n pool: `0x${string}`\n safe: `0x${string}`\n roleKey?: Hex\n}","params: {\n member: `0x${string}`\n pool: `0x${string}`\n adapter: `0x${string}` // deployed RollerCondition (stateless, shared per chain)\n sizeCap?: bigint\n roleKey?: Hex\n}","params: {\n member: `0x${string}`\n pool: `0x${string}`\n adapter: `0x${string}` // deployed SizeAdjusterCondition (stateless, shared per chain)\n sizeCap?: bigint\n roleKey?: Hex\n}"],"sources":["../../src/zodiac/rolesAbi.ts","../../src/zodiac/applySteps.ts","../../src/zodiac/conditions.ts","../../src/zodiac/constants.ts","../../src/zodiac/roles/dispatchCustomRole.ts","../../src/zodiac/roles/deleverager.ts","../../src/zodiac/tokenIdMask.ts","../../src/zodiac/roles/loanHedger.ts","../../src/zodiac/roles/maintenance.ts","../../src/zodiac/roles/roller.ts","../../src/zodiac/roles/sizeAdjuster.ts"],"sourcesContent":["/** Minimal Zodiac Roles v2 modifier ABI used by the scoping/apply flows. */\nexport const rolesV2Abi = [\n {\n type: 'function',\n name: 'assignRoles',\n stateMutability: 'nonpayable',\n inputs: [\n { name: 'module', type: 'address' },\n { name: 'roleKeys', type: 'bytes32[]' },\n { name: 'memberOf', type: 'bool[]' },\n ],\n outputs: [],\n },\n {\n type: 'function',\n name: 'scopeTarget',\n stateMutability: 'nonpayable',\n inputs: [\n { name: 'roleKey', type: 'bytes32' },\n { name: 'targetAddress', type: 'address' },\n ],\n outputs: [],\n },\n {\n type: 'function',\n name: 'scopeFunction',\n stateMutability: 'nonpayable',\n inputs: [\n { name: 'roleKey', type: 'bytes32' },\n { name: 'targetAddress', type: 'address' },\n { name: 'selector', type: 'bytes4' },\n {\n name: 'conditions',\n type: 'tuple[]',\n components: [\n { name: 'parent', type: 'uint8' },\n { name: 'paramType', type: 'uint8' },\n { name: 'operator', type: 'uint8' },\n { name: 'compValue', type: 'bytes' },\n ],\n },\n { name: 'options', type: 'uint8' },\n ],\n outputs: [],\n },\n {\n type: 'function',\n name: 'allowFunction',\n stateMutability: 'nonpayable',\n inputs: [\n { name: 'roleKey', type: 'bytes32' },\n { name: 'targetAddress', type: 'address' },\n { name: 'selector', type: 'bytes4' },\n { name: 'options', type: 'uint8' },\n ],\n outputs: [],\n },\n {\n type: 'function',\n name: 'setTransactionUnwrapper',\n stateMutability: 'nonpayable',\n inputs: [\n { name: 'to', type: 'address' },\n { name: 'selector', type: 'bytes4' },\n { name: 'adapter', type: 'address' },\n ],\n outputs: [],\n },\n] as const\n","import { rolesV2Abi } from './rolesAbi'\n\n/** One idempotent Roles-modifier configuration call. */\nexport interface ScopeStep {\n name: string\n functionName:\n | 'assignRoles'\n | 'scopeTarget'\n | 'scopeFunction'\n | 'allowFunction'\n | 'setTransactionUnwrapper'\n args: unknown[]\n}\n\n/**\n * Minimal structural client shapes (instead of viem's `PublicClient` /\n * `WalletClient`) so any viem 2.x instance is accepted — pnpm peer-keying can\n * produce multiple viem type-instances across a workspace, and the deeply\n * generic client types are not assignable across instances (TS2719).\n */\nexport interface ScopeStepsPublicClient {\n waitForTransactionReceipt(args: {\n hash: `0x${string}`\n timeout?: number\n }): Promise<{ status: string }>\n}\n\nexport interface ScopeStepsWalletClient {\n writeContract(args: {\n address: `0x${string}`\n abi: typeof rolesV2Abi\n functionName: ScopeStep['functionName']\n args: never\n maxFeePerGas?: bigint\n maxPriorityFeePerGas?: bigint\n }): Promise<`0x${string}`>\n}\n\n/**\n * Apply scope steps to a Roles v2 modifier sequentially, aborting on the\n * first revert so a partially-applied role is never silently left behind.\n * The wallet must be the modifier's owner.\n */\nexport async function applyScopeSteps(params: {\n publicClient: ScopeStepsPublicClient\n walletClient: ScopeStepsWalletClient\n rolesModifier: `0x${string}`\n steps: ScopeStep[]\n log?: (line: string) => void\n /**\n * EIP-1559 fee overrides applied to every tx. Pass a NON-ZERO\n * `maxPriorityFeePerGas` — some RPC estimators return a zero tip, which leaves\n * txs un-prioritised and slow to include.\n */\n fees?: { maxFeePerGas?: bigint; maxPriorityFeePerGas?: bigint }\n /** Receipt-wait timeout (ms). */\n timeoutMs?: number\n}): Promise<void> {\n // eslint-disable-next-line no-console\n const { publicClient, walletClient, rolesModifier, steps, log = console.log } = params\n for (const step of steps) {\n log(`→ ${step.name}`)\n const hash = await walletClient.writeContract({\n address: rolesModifier,\n abi: rolesV2Abi,\n functionName: step.functionName,\n args: step.args as never,\n ...(params.fees ?? {}),\n })\n const receipt = await publicClient.waitForTransactionReceipt({\n hash,\n ...(params.timeoutMs ? { timeout: params.timeoutMs } : {}),\n })\n log(` ${receipt.status} ${hash}`)\n if (receipt.status !== 'success') {\n throw new Error(`step \"${step.name}\" reverted (tx ${hash}); aborting before later steps`)\n }\n }\n}\n","import type { Hex } from 'viem'\n\n/** Roles v2 flat condition node (BFS-ordered tree). */\nexport interface ConditionFlat {\n parent: number\n paramType: number\n operator: number\n compValue: Hex\n}\n\n/** True for a 0x-prefixed, 20-byte (40 hex char) address. */\nfunction isHexAddress(v: string): boolean {\n return /^0x[0-9a-fA-F]{40}$/.test(v)\n}\n\n/** 32-byte left-padded address as an EqualTo Static compValue. */\nexport function addressEqualCompValue(addr: `0x${string}`): Hex {\n if (!isHexAddress(addr)) {\n throw new Error(`addressEqualCompValue: expected a 20-byte hex address, got \"${addr}\"`)\n }\n return `0x${addr.slice(2).toLowerCase().padStart(64, '0')}` as Hex\n}\n\n/**\n * Operator.Custom compValue: adapter address in the leading 20 bytes, the\n * trailing 12 bytes are passed to the adapter verbatim as `extra`.\n */\nexport function customCompValue(adapter: `0x${string}`, extra: Hex = '0x'): Hex {\n if (!isHexAddress(adapter)) {\n throw new Error(`customCompValue: adapter must be a 20-byte hex address, got \"${adapter}\"`)\n }\n if (!/^0x([0-9a-fA-F]{2})*$/.test(extra)) {\n throw new Error(`customCompValue: extra must be 0x-prefixed, even-length hex, got \"${extra}\"`)\n }\n if (extra.length - 2 > 24) throw new Error('customCompValue: extra must be at most 12 bytes')\n const extraHex = extra.slice(2).padEnd(24, '0')\n return `0x${adapter.slice(2).toLowerCase()}${extraHex}` as Hex\n}\n\n/**\n * Encode a uint96 mint-size cap as the `bytes12 extra` of a pair-condition\n * compValue (0n = uncapped). The adapters read it as `uint96(extra)`, i.e.\n * big-endian right-aligned in the 12 bytes.\n */\nexport function sizeCapExtra(cap: bigint): Hex {\n if (cap < 0n || cap >= 1n << 96n) throw new Error('size cap must fit in uint96')\n return `0x${cap.toString(16).padStart(24, '0')}` as Hex\n}\n","/**\n * Zodiac Roles Modifier v2 enum ordinals.\n *\n * Verified against gnosisguild/zodiac-modifier-roles `contracts/Types.sol`\n * (commit c343958ab7317b31d8c4aec790606d950ea21eed) and the deployed v2.1\n * mastercopy 0x9646fDAD06d3e24444381f44362a3B0eB343D337. Keep in sync with the\n * modifier version the Safe actually runs.\n */\n\nexport const ParameterType = {\n None: 0,\n Static: 1,\n Dynamic: 2,\n Tuple: 3,\n Array: 4,\n Calldata: 5,\n AbiEncoded: 6,\n} as const\n\nexport const Operator = {\n Pass: 0,\n And: 1,\n Or: 2,\n Nor: 3,\n Matches: 5,\n ArraySome: 6,\n ArrayEvery: 7,\n ArraySubset: 8,\n EqualToAvatar: 15,\n EqualTo: 16,\n GreaterThan: 17,\n LessThan: 18,\n SignedIntGreaterThan: 19,\n SignedIntLessThan: 20,\n Bitmask: 21,\n Custom: 22,\n WithinAllowance: 28,\n EtherWithinAllowance: 29,\n CallWithinAllowance: 30,\n} as const\n\n/**\n * Canonical adapter addresses — deterministic CREATE2 (factory\n * 0x4e59b44847b379578588920cA78FbF26c0B4956C, salt\n * keccak256(\"panoptic.zodiac-modules.v1\")), so they depend only on the\n * bytecode: same on every chain, deployer-independent, verifiable with\n * `cast code` against a local `forge build`. The adapters are stateless and\n * immutable (no owner/storage/upgradability). Recompute via\n * `forge script scripts/DeployAdapters.s.sol` after any source change.\n */\nexport const CANONICAL_ADAPTERS = {\n RollerCondition: '0x7b2402F7Ff7fFe0970D383dE1C6AF8892B87523a',\n SizeAdjusterCondition: '0x72494B2A0C5a69Dd0154386c2F4Af0b38a24C400',\n} as const\n\nexport const ExecutionOptions = {\n None: 0,\n Send: 1,\n DelegateCall: 2,\n Both: 3,\n} as const\n","import { type Hex, keccak256, toBytes, toFunctionSelector } from 'viem'\n\nimport type { ScopeStep } from '../applySteps'\nimport { type ConditionFlat, customCompValue } from '../conditions'\nimport { ExecutionOptions, Operator, ParameterType } from '../constants'\n\n/** PanopticPool.dispatch — TokenId is a uint256 value type. */\nexport const DISPATCH_SELECTOR = toFunctionSelector(\n 'dispatch(uint256[],uint256[],uint128[],int24[3][],bool,uint256)',\n)\n\n/** Deterministic per-role keys; override via env/config if a Safe needs several instances. */\nexport function roleKey(name: string): Hex {\n return keccak256(toBytes(`panoptic.role.${name}.v1`))\n}\n\n/**\n * ConditionFlat tree for a dispatch-scoped role whose whole authorization\n * logic lives in an on-chain `ICustomCondition` adapter (Operator.Custom).\n *\n * The Custom node is attached to arg0 (`positionIdList`): Roles hands the\n * adapter the FULL calldata regardless of attachment point, and the adapter\n * decodes `positionIdList`/`positionSizes` itself. The remaining nodes are the\n * structural template `Integrity.sol` requires (Calldata and Array nodes must\n * describe their children; see buildLoanOnlyDispatchConditions for the shape).\n */\nexport function buildDispatchCustomConditions(\n adapter: `0x${string}`,\n extra: Hex = '0x',\n): ConditionFlat[] {\n const compValue = customCompValue(adapter, extra)\n return [\n // 0: root over calldata\n { parent: 0, paramType: ParameterType.Calldata, operator: Operator.Matches, compValue: '0x' },\n // 1: arg0 positionIdList — carries the Custom adapter check\n { parent: 0, paramType: ParameterType.Array, operator: Operator.Custom, compValue },\n // 2: arg1 finalPositionIdList\n { parent: 0, paramType: ParameterType.Array, operator: Operator.Pass, compValue: '0x' },\n // 3: arg2 positionSizes\n { parent: 0, paramType: ParameterType.Array, operator: Operator.Pass, compValue: '0x' },\n // 4: arg3 tickAndSpreadLimits (int24[3][])\n { parent: 0, paramType: ParameterType.Array, operator: Operator.Pass, compValue: '0x' },\n // 5: arg4 usePremiaAsCollateral\n { parent: 0, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n // 6: arg5 builderCode\n { parent: 0, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n // 7-9: array element types\n { parent: 1, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n { parent: 2, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n { parent: 3, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n // 10: tickAndSpreadLimits element (int24[3] — statically encoded, 3 words)\n { parent: 4, paramType: ParameterType.Tuple, operator: Operator.Pass, compValue: '0x' },\n // 11-13: int24[3] members\n { parent: 10, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n { parent: 10, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n { parent: 10, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n ]\n}\n\n/** assignRoles → scopeTarget → scopeFunction steps for an adapter-gated dispatch role. */\nexport function buildDispatchCustomRoleSteps(params: {\n roleName: string\n roleKey: Hex\n member: `0x${string}`\n pool: `0x${string}`\n adapter: `0x${string}`\n extra?: Hex\n}): ScopeStep[] {\n const { roleName, member, pool, adapter, extra } = params\n return [\n {\n name: `assignRoles(${roleName} member)`,\n functionName: 'assignRoles',\n args: [member, [params.roleKey], [true]],\n },\n { name: 'scopeTarget(pool)', functionName: 'scopeTarget', args: [params.roleKey, pool] },\n {\n name: `scopeFunction(dispatch, ${roleName} custom adapter)`,\n functionName: 'scopeFunction',\n args: [\n params.roleKey,\n pool,\n DISPATCH_SELECTOR,\n buildDispatchCustomConditions(adapter, extra),\n ExecutionOptions.None,\n ],\n },\n ]\n}\n","import type { Hex } from 'viem'\n\nimport type { ScopeStep } from '../applySteps'\nimport type { ConditionFlat } from '../conditions'\nimport { ExecutionOptions, Operator, ParameterType } from '../constants'\nimport { DISPATCH_SELECTOR, roleKey } from './dispatchCustomRole'\n\n/**\n * Deleverager role: burn the Safe's existing positions only — never mint.\n *\n * Enforced with plain static conditions, no adapter and no state oracle:\n * every `positionSizes` entry must be 0. A size-0 entry either burns a held\n * position or reverts the whole dispatch — a size-0 mint is impossible\n * (option legs trip `ChunkHasZeroLiquidity` in the SFPM; pure-loan tokenIds\n * die in the end-of-dispatch solvency pass / positions-hash validation).\n *\n * Trade-off vs an oracle-based check: the key cannot settle premium (settle\n * requires `sizes[i] == storedSize`, unknowable pre-execution). Strictly a\n * risk-reduction key: safe for a watchdog keeper or dead-man's-switch.\n */\nexport const DELEVERAGER_ROLE_KEY = roleKey('deleverager')\n\nconst ZERO_WORD = `0x${'0'.repeat(64)}` as Hex\n\nexport function buildDeleveragerDispatchConditions(): ConditionFlat[] {\n return [\n // 0: root over calldata\n { parent: 0, paramType: ParameterType.Calldata, operator: Operator.Matches, compValue: '0x' },\n // 1: arg0 positionIdList — unconstrained (any held tokenId may be burnt)\n { parent: 0, paramType: ParameterType.Array, operator: Operator.Pass, compValue: '0x' },\n // 2: arg1 finalPositionIdList\n { parent: 0, paramType: ParameterType.Array, operator: Operator.Pass, compValue: '0x' },\n // 3: arg2 positionSizes — EVERY entry must be 0 (burn-or-revert)\n { parent: 0, paramType: ParameterType.Array, operator: Operator.ArrayEvery, compValue: '0x' },\n // 4: arg3 tickAndSpreadLimits (int24[3][])\n { parent: 0, paramType: ParameterType.Array, operator: Operator.Pass, compValue: '0x' },\n // 5: arg4 usePremiaAsCollateral\n { parent: 0, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n // 6: arg5 builderCode\n { parent: 0, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n // 7-9: array element types\n { parent: 1, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n { parent: 2, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n {\n parent: 3,\n paramType: ParameterType.Static,\n operator: Operator.EqualTo,\n compValue: ZERO_WORD,\n },\n // 10: tickAndSpreadLimits element (int24[3] — statically encoded, 3 words)\n { parent: 4, paramType: ParameterType.Tuple, operator: Operator.Pass, compValue: '0x' },\n // 11-13: int24[3] members\n { parent: 10, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n { parent: 10, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n { parent: 10, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n ]\n}\n\nexport function buildDeleveragerRoleSteps(params: {\n member: `0x${string}`\n pool: `0x${string}`\n roleKey?: Hex\n}): ScopeStep[] {\n const key = params.roleKey ?? DELEVERAGER_ROLE_KEY\n return [\n {\n name: 'assignRoles(deleverager member)',\n functionName: 'assignRoles',\n args: [params.member, [key], [true]],\n },\n { name: 'scopeTarget(pool)', functionName: 'scopeTarget', args: [key, params.pool] },\n {\n name: 'scopeFunction(dispatch, burn-only: all sizes == 0)',\n functionName: 'scopeFunction',\n args: [\n key,\n params.pool,\n DISPATCH_SELECTOR,\n buildDeleveragerDispatchConditions(),\n ExecutionOptions.None,\n ],\n },\n ]\n}\n","/**\n * Bit-field masks over the Panoptic v2 tokenId layout, mirroring\n * `contracts/lib/TokenIdMasks.sol` (kept in lockstep by golden unit tests).\n *\n * Layout (packages/panoptic-v2-core/contracts/types/TokenId.sol):\n * - bits [0, 64) poolId\n * - each leg is 48 bits, starting at 64 + legIndex*48, packing\n * asset(+0,1b) | optionRatio(+1,7b) | isLong(+8) | tokenType(+9)\n * | riskPartner(+10,2b) | strike(+12,24b) | width(+36,12b)\n */\n\nconst POOL_ID_SIZE = 64n\nconst LEG_SIZE = 48n\nconst MAX_LEGS = 4n\n\n/** Mask with 1-bits over a `bits`-wide field at `fieldOffset` in every leg. */\nexport function legFieldMask(fieldOffset: bigint, bits: bigint): bigint {\n const field = (1n << bits) - 1n\n let mask = 0n\n for (let leg = 0n; leg < MAX_LEGS; leg++) {\n mask |= field << (POOL_ID_SIZE + leg * LEG_SIZE + fieldOffset)\n }\n return mask\n}\n\n/** Mask with 1-bits over every leg's 12-bit width field. */\nexport function loanWidthFieldsMask(): bigint {\n return legFieldMask(36n, 12n)\n}\n\n/** Mask with 1-bits over every leg's 24-bit strike field. */\nexport function strikeFieldsMask(): bigint {\n return legFieldMask(12n, 24n)\n}\n\n/** Mask with 1-bits over every leg's 7-bit optionRatio field. */\nexport function optionRatioFieldsMask(): bigint {\n return legFieldMask(1n, 7n)\n}\n\n/** True iff every leg of the tokenId has width == 0 (a pure loan/credit). */\nexport function isPureLoanTokenId(tokenId: bigint): boolean {\n return (tokenId & loanWidthFieldsMask()) === 0n\n}\n\n/** The 32-byte mask + expected value for a Zodiac Roles v2 Bitmask condition. */\nexport function loanBitmaskCondition(): { mask: `0x${string}`; expected: `0x${string}` } {\n const mask = loanWidthFieldsMask()\n const toBytes32 = (v: bigint) => `0x${v.toString(16).padStart(64, '0')}` as `0x${string}`\n return { mask: toBytes32(mask), expected: toBytes32(0n) }\n}\n","import type { Hex } from 'viem'\n\nimport { type ConditionFlat, addressEqualCompValue } from '../conditions'\nimport { Operator, ParameterType } from '../constants'\nimport { loanBitmaskCondition } from '../tokenIdMask'\n\n/**\n * Loan-only hedger role scope (migrated from apps/hedger-bot scripts/lib).\n *\n * ⚠️ VALIDATE ON A FORK BEFORE MAINNET. The ConditionFlat encoding below is\n * security-critical. Dry-run `scopeFunction` on an anvil/Tenderly fork and\n * assert that the role CAN mint/burn a pure width=0 loan via dispatch and\n * CANNOT dispatch a tokenId with any width>0 leg.\n *\n * The scope constrains PanopticPool.dispatch(positionIdList, finalPositionIdList,\n * positionSizes, tickAndSpreadLimits, usePremiaAsCollateral, builderCode) so that\n * EVERY element of `positionIdList` (arg 0 — the tokenIds actually minted/burned)\n * is a pure loan: `tokenId & widthFieldsMask == 0`. All other args pass freely;\n * `finalPositionIdList` is intentionally NOT constrained (it legitimately contains\n * the user's option positions that remain open).\n */\n\n/**\n * Bitmask compValue layout (Roles v2 `PermissionChecker._bitmask`): a 32-byte\n * word packing `uint16 shift | bytes15 mask | bytes15 expected`, where `shift`\n * is a BYTE offset from the start (left / most-significant end) of the value\n * and the 15-byte mask is applied LEFT-aligned to `bytes32(value[shift:])`.\n *\n * The four 12-bit width fields span tokenId bits 100–255 (leg 3's width sits in\n * the top two bytes), which is wider than one 15-byte window. So the loan\n * constraint is expressed as TWO windows AND-ed together:\n * - shift 0: tokenId bytes 0..14 (bits 136–255) — covers legs 1, 2, 3\n * - shift 17: tokenId bytes 17..31 (bits 0–119) — covers leg 0\n * Bytes 15–16 (bits 120–135) contain no width bits.\n */\nexport const LOAN_BITMASK_WINDOW_SHIFTS = [0, 17] as const\n\nexport function loanBitmaskCompValueAt(shiftBytes: number): Hex {\n const { mask } = loanBitmaskCondition()\n const maskBytes = mask.slice(2) // 64 hex chars, byte 0 first\n const window = maskBytes.slice(shiftBytes * 2, shiftBytes * 2 + 30).padEnd(30, '0')\n const shift = shiftBytes.toString(16).padStart(4, '0')\n return `0x${shift}${window}${'0'.repeat(30)}` as Hex // expected = all zeros\n}\n\n/**\n * Build the ConditionFlat[] tree scoping dispatch to loan-only positionIdList.\n *\n * Roles v2 `Integrity.sol` requirements honored here:\n * - BFS order: parent indices must be non-decreasing (NotBFS).\n * - Every Array-typed node needs >=1 child describing the element type\n * (UnsuitableChildCount); ArrayEvery needs exactly 1.\n * - And nodes use ParameterType.None and an empty compValue.\n */\nexport function buildLoanOnlyDispatchConditions(): ConditionFlat[] {\n return [\n // 0: root over calldata\n { parent: 0, paramType: ParameterType.Calldata, operator: Operator.Matches, compValue: '0x' },\n // 1: arg0 positionIdList — every element must satisfy subtree [7]\n { parent: 0, paramType: ParameterType.Array, operator: Operator.ArrayEvery, compValue: '0x' },\n // 2: arg1 finalPositionIdList — unconstrained (holds user option positions)\n { parent: 0, paramType: ParameterType.Array, operator: Operator.Pass, compValue: '0x' },\n // 3: arg2 positionSizes\n { parent: 0, paramType: ParameterType.Array, operator: Operator.Pass, compValue: '0x' },\n // 4: arg3 tickAndSpreadLimits (int24[3][])\n { parent: 0, paramType: ParameterType.Array, operator: Operator.Pass, compValue: '0x' },\n // 5: arg4 usePremiaAsCollateral\n { parent: 0, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n // 6: arg5 builderCode\n { parent: 0, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n // 7: positionIdList element (uint256 tokenId) — both width windows must be zero\n { parent: 1, paramType: ParameterType.None, operator: Operator.And, compValue: '0x' },\n // 8: finalPositionIdList element\n { parent: 2, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n // 9: positionSizes element\n { parent: 3, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n // 10: tickAndSpreadLimits element (int24[3] — statically encoded, 3 words)\n { parent: 4, paramType: ParameterType.Tuple, operator: Operator.Pass, compValue: '0x' },\n // 11-12: the two AND-ed bitmask windows over the tokenId\n {\n parent: 7,\n paramType: ParameterType.Static,\n operator: Operator.Bitmask,\n compValue: loanBitmaskCompValueAt(LOAN_BITMASK_WINDOW_SHIFTS[0]),\n },\n {\n parent: 7,\n paramType: ParameterType.Static,\n operator: Operator.Bitmask,\n compValue: loanBitmaskCompValueAt(LOAN_BITMASK_WINDOW_SHIFTS[1]),\n },\n // 13-15: int24[3] members\n { parent: 10, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n { parent: 10, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n { parent: 10, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n ]\n}\n\n// ---------------------------------------------------------------------------\n// Cross-pool scope: MultiSend unwrap + per-inner-call scopes.\n//\n// The bot batches [CT.withdraw, router.execute, CT.deposit] via Safe MultiSend,\n// routed through Roles with a MultiSend unwrapper registered so each inner call\n// is re-checked against these scopes. Selectors below are the inner targets.\n// ---------------------------------------------------------------------------\n\n/** ERC4626 CollateralTracker withdraw(uint256 assets, address receiver, address owner). */\nexport const WITHDRAW_SELECTOR = '0xb460af94' as const\n/** ERC4626 CollateralTracker deposit(uint256 assets, address receiver). */\nexport const DEPOSIT_SELECTOR = '0x6e553f65' as const\n/** Uniswap UniversalRouter execute(bytes,bytes[],uint256). */\nexport const EXECUTE_SELECTOR = '0x3593564c' as const\n\n/**\n * Scope CT.withdraw so tokens can only be pulled to the Safe: receiver == owner\n * == Safe. Without this, a compromised bot key could withdraw the Safe's\n * collateral to an arbitrary address — this is the critical cross-pool scope.\n */\nexport function buildWithdrawConditions(safe: `0x${string}`): ConditionFlat[] {\n const safeEq = addressEqualCompValue(safe)\n return [\n { parent: 0, paramType: ParameterType.Calldata, operator: Operator.Matches, compValue: '0x' },\n { parent: 0, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' }, // assets\n { parent: 0, paramType: ParameterType.Static, operator: Operator.EqualTo, compValue: safeEq }, // receiver\n { parent: 0, paramType: ParameterType.Static, operator: Operator.EqualTo, compValue: safeEq }, // owner\n ]\n}\n\n/** Scope CT.deposit so the shares are credited to the Safe: receiver == Safe. */\nexport function buildDepositConditions(safe: `0x${string}`): ConditionFlat[] {\n return [\n { parent: 0, paramType: ParameterType.Calldata, operator: Operator.Matches, compValue: '0x' },\n { parent: 0, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' }, // assets\n {\n parent: 0,\n paramType: ParameterType.Static,\n operator: Operator.EqualTo,\n compValue: addressEqualCompValue(safe),\n }, // receiver\n ]\n}\n\n/**\n * Router `execute` is scoped with a calldata template — see\n * apps/hedger-bot/scripts/lib/routerScope.ts (hedging-specific, not migrated).\n */\nexport const ROUTER_EXECUTE_SELECTOR_ONLY = EXECUTE_SELECTOR\n","import { type Hex, toFunctionSelector } from 'viem'\n\nimport type { ScopeStep } from '../applySteps'\nimport { type ConditionFlat, addressEqualCompValue } from '../conditions'\nimport { ExecutionOptions, Operator, ParameterType } from '../constants'\nimport { roleKey } from './dispatchCustomRole'\n\n/**\n * Maintenance role: full `dispatchFrom` access — settle premium on, force-\n * exercise, and liquidate third-party accounts using the Safe's capital.\n * No adapter needed; the pool itself hash-validates the position lists.\n *\n * The only pin is `account != Safe` (Nor(EqualTo(safe))) so the maintenance\n * key can never force-exercise or liquidate the Safe's own book.\n * `positionIdListFrom` (the caller's solvency list) is intentionally\n * unconstrained — the Safe may legitimately hold option positions.\n *\n * dispatchFrom is payable ⇒ ExecutionOptions.Send.\n */\nexport const MAINTENANCE_ROLE_KEY = roleKey('maintenance')\n\n/** LeftRightUnsigned is a uint256 value type. */\nexport const DISPATCH_FROM_SELECTOR = toFunctionSelector(\n 'dispatchFrom(uint256[],address,uint256[],uint256[],uint256)',\n)\n\nexport function buildDispatchFromConditions(safe: `0x${string}`): ConditionFlat[] {\n return [\n // 0: root over calldata\n { parent: 0, paramType: ParameterType.Calldata, operator: Operator.Matches, compValue: '0x' },\n // 1: arg0 positionIdListFrom (caller solvency list)\n { parent: 0, paramType: ParameterType.Array, operator: Operator.Pass, compValue: '0x' },\n // 2: arg1 account — anything but the Safe itself\n { parent: 0, paramType: ParameterType.None, operator: Operator.Nor, compValue: '0x' },\n // 3: arg2 positionIdListTo\n { parent: 0, paramType: ParameterType.Array, operator: Operator.Pass, compValue: '0x' },\n // 4: arg3 positionIdListToFinal\n { parent: 0, paramType: ParameterType.Array, operator: Operator.Pass, compValue: '0x' },\n // 5: arg4 usePremiaAsCollateral (LeftRightUnsigned)\n { parent: 0, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n // 6: arg0 element\n { parent: 1, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n // 7: Nor child — account == Safe (negated by the parent)\n {\n parent: 2,\n paramType: ParameterType.Static,\n operator: Operator.EqualTo,\n compValue: addressEqualCompValue(safe),\n },\n // 8: arg2 element\n { parent: 3, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n // 9: arg3 element\n { parent: 4, paramType: ParameterType.Static, operator: Operator.Pass, compValue: '0x' },\n ]\n}\n\nexport function buildMaintenanceRoleSteps(params: {\n member: `0x${string}`\n pool: `0x${string}`\n safe: `0x${string}`\n roleKey?: Hex\n}): ScopeStep[] {\n const key = params.roleKey ?? MAINTENANCE_ROLE_KEY\n return [\n {\n name: 'assignRoles(maintenance member)',\n functionName: 'assignRoles',\n args: [params.member, [key], [true]],\n },\n { name: 'scopeTarget(pool)', functionName: 'scopeTarget', args: [key, params.pool] },\n {\n name: 'scopeFunction(dispatchFrom, account != safe, Send)',\n functionName: 'scopeFunction',\n args: [\n key,\n params.pool,\n DISPATCH_FROM_SELECTOR,\n buildDispatchFromConditions(params.safe),\n ExecutionOptions.Send,\n ],\n },\n ]\n}\n","import type { Hex } from 'viem'\n\nimport type { ScopeStep } from '../applySteps'\nimport { sizeCapExtra } from '../conditions'\nimport { buildDispatchCustomRoleSteps, roleKey } from './dispatchCustomRole'\n\n/**\n * Roller role: close one position and reopen it identical-except-strike (roll\n * out-of-range positions back into range). Enforced on-chain by the stateless\n * `RollerCondition` adapter (strike-mask equality + one-burn-one-mint shape).\n *\n * The reopened size is bounded by `sizeCap` (0n = uncapped, leaving only\n * dispatch's solvency check as the ceiling) — there is no pre-state oracle,\n * so \"same size as before\" cannot be enforced.\n */\nexport const ROLLER_ROLE_KEY = roleKey('roller')\n\nexport function buildRollerRoleSteps(params: {\n member: `0x${string}`\n pool: `0x${string}`\n adapter: `0x${string}` // deployed RollerCondition (stateless, shared per chain)\n sizeCap?: bigint\n roleKey?: Hex\n}): ScopeStep[] {\n return buildDispatchCustomRoleSteps({\n roleName: 'roller',\n roleKey: params.roleKey ?? ROLLER_ROLE_KEY,\n member: params.member,\n pool: params.pool,\n adapter: params.adapter,\n extra: sizeCapExtra(params.sizeCap ?? 0n),\n })\n}\n","import type { Hex } from 'viem'\n\nimport type { ScopeStep } from '../applySteps'\nimport { sizeCapExtra } from '../conditions'\nimport { buildDispatchCustomRoleSteps, roleKey } from './dispatchCustomRole'\n\n/**\n * Size-adjuster role: replace one position with an identical-except-optionRatio\n * one — reduce a short whose long side was purchased, or grow a long as more\n * options are sold. Enforced on-chain by the stateless `SizeAdjusterCondition`\n * adapter (ratio-mask equality + one-burn-one-mint shape).\n *\n * Without a pre-state oracle the relative notional cap is not enforceable;\n * set `sizeCap` (uint96, 0n = uncapped) to bound the mint size absolutely.\n */\nexport const SIZE_ADJUSTER_ROLE_KEY = roleKey('size-adjuster')\n\nexport function buildSizeAdjusterRoleSteps(params: {\n member: `0x${string}`\n pool: `0x${string}`\n adapter: `0x${string}` // deployed SizeAdjusterCondition (stateless, shared per chain)\n sizeCap?: bigint\n roleKey?: Hex\n}): ScopeStep[] {\n return buildDispatchCustomRoleSteps({\n roleName: 'size-adjuster',\n roleKey: params.roleKey ?? SIZE_ADJUSTER_ROLE_KEY,\n member: params.member,\n pool: params.pool,\n adapter: params.adapter,\n extra: sizeCapExtra(params.sizeCap ?? 0n),\n })\n}\n"],"mappings":";;;;AACA,MAAa,aAAa;CACxB;EACE,MAAM;EACN,MAAM;EACN,iBAAiB;EACjB,QAAQ;GACN;IAAE,MAAM;I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AO;EACb,SAAS,OAAO;EAChB,OAAO,aAAa,OAAO,WAAW,GAAG;CAC1C,EAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panoptic-eng/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/panoptic-labs/panoptic-sdk.git"
|
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
"types": "./dist/cow/index.d.ts",
|
|
28
28
|
"import": "./dist/cow/index.js"
|
|
29
29
|
},
|
|
30
|
+
"./zodiac": {
|
|
31
|
+
"types": "./dist/zodiac/index.d.ts",
|
|
32
|
+
"import": "./dist/zodiac/index.js"
|
|
33
|
+
},
|
|
30
34
|
"./test": {
|
|
31
35
|
"types": "./dist/test/index.d.ts",
|
|
32
36
|
"import": "./dist/test/index.js"
|
|
@@ -59,6 +63,7 @@
|
|
|
59
63
|
"prepublishOnly": "pnpm build"
|
|
60
64
|
},
|
|
61
65
|
"dependencies": {
|
|
66
|
+
"decimal.js": "^10.6.0",
|
|
62
67
|
"graphql": "^16.12.0",
|
|
63
68
|
"graphql-request": "^7.3.1",
|
|
64
69
|
"graphql-tag": "^2.12.6",
|
package/dist/irm-DF4NwYIY.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"irm-DF4NwYIY.js","names":["client: Client","results: readonly MulticallBlockResult[]","index: number","label: string","amount: bigint","sqrtPriceX96: bigint","params: IsLiquidatableParams","collateralToken0: Address","collateralToken1: Address","calls: MulticallBlockCall[]","denominatedInToken: bigint","pool: {\n collateralTracker0: { address: Address }\n collateralTracker1: { address: Address }\n}","params: GetAccountCollateralParams","collateralToken0: Address","collateralToken1: Address","token0: TokenCollateral","token1: TokenCollateral","params: GetAccountSummaryBasicParams","params: GetAccountSummaryRiskParams","params: GetNetLiquidationValueParams","params: GetNetLiquidationValuesParams","params: GetLiquidationPricesParams","SECONDS_PER_YEAR","erc20Abi","params: GetCollateralDataParams","_meta","poolData","totalShares","interestRate","depositedAssets","insideAMM","creditedShares","utilization","totalAssets","borrowRate","supplyRate","params: GetCurrentRatesParams","collateralToken0: Address","collateralToken1: Address","params: GetInterestStateParams","amount: bigint","decimals: bigint","precision: bigint","amount: string","flow: TokenFlow","decimals0: bigint","decimals1: bigint","precision0: bigint","precision1: bigint","wad: bigint","precision: bigint","rateWad: bigint","value: string","SECONDS_PER_YEAR","ratePerSecondWad: bigint","precision: bigint","utilizationBps: bigint","bits: bigint","value: bigint","fieldName: string","inputs: IrmMarketStateInputs","utilizationPct: number","ratePerSecWad: bigint","borrowRatePerSecWad: bigint","utilizationWad: bigint","params: {\n client: PublicClient\n collateralTrackerAddress: Address\n blockNumber?: bigint\n}","params: {\n client: PublicClient\n collateralTrackerAddress: Address\n points?: number\n blockNumber?: bigint\n}","curvePoints: IrmPoint[]"],"sources":["../src/abis/multicall3.ts","../src/panoptic/v2/abis/panopticQuery.ts","../src/panoptic/v2/reads/multicallBlock.ts","../src/panoptic/v2/reads/checks.ts","../src/panoptic/v2/reads/account.ts","../src/panoptic/v2/reads/collateral.ts","../src/panoptic/v2/formatters/amount.ts","../src/panoptic/v2/formatters/wad.ts","../src/panoptic/v2/formatters/rates.ts","../src/panoptic/v2/reads/irm.ts"],"sourcesContent":["export const Multicall3Abi = [\n {\n inputs: [\n {\n components: [\n {\n internalType: 'address',\n name: 'target',\n type: 'address',\n },\n {\n internalType: 'bytes',\n name: 'callData',\n type: 'bytes',\n },\n ],\n internalType: 'struct Multicall3.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'aggregate',\n outputs: [\n {\n internalType: 'uint256',\n name: 'blockNumber',\n type: 'uint256',\n },\n {\n internalType: 'bytes[]',\n name: 'returnData',\n type: 'bytes[]',\n },\n ],\n stateMutability: 'payable',\n type: 'function',\n },\n {\n inputs: [\n {\n components: [\n {\n internalType: 'address',\n name: 'target',\n type: 'address',\n },\n {\n internalType: 'bool',\n name: 'allowFailure',\n type: 'bool',\n },\n {\n internalType: 'bytes',\n name: 'callData',\n type: 'bytes',\n },\n ],\n internalType: 'struct Multicall3.Call3[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'aggregate3',\n outputs: [\n {\n components: [\n {\n internalType: 'bool',\n name: 'success',\n type: 'bool',\n },\n {\n internalType: 'bytes',\n name: 'returnData',\n type: 'bytes',\n },\n ],\n internalType: 'struct Multicall3.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n ],\n stateMutability: 'payable',\n type: 'function',\n },\n {\n inputs: [\n {\n components: [\n {\n internalType: 'address',\n name: 'target',\n type: 'address',\n },\n {\n internalType: 'bool',\n name: 'allowFailure',\n type: 'bool',\n },\n {\n internalType: 'uint256',\n name: 'value',\n type: 'uint256',\n },\n {\n internalType: 'bytes',\n name: 'callData',\n type: 'bytes',\n },\n ],\n internalType: 'struct Multicall3.Call3Value[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'aggregate3Value',\n outputs: [\n {\n components: [\n {\n internalType: 'bool',\n name: 'success',\n type: 'bool',\n },\n {\n internalType: 'bytes',\n name: 'returnData',\n type: 'bytes',\n },\n ],\n internalType: 'struct Multicall3.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n ],\n stateMutability: 'payable',\n type: 'function',\n },\n {\n inputs: [\n {\n components: [\n {\n internalType: 'address',\n name: 'target',\n type: 'address',\n },\n {\n internalType: 'bytes',\n name: 'callData',\n type: 'bytes',\n },\n ],\n internalType: 'struct Multicall3.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'blockAndAggregate',\n outputs: [\n {\n internalType: 'uint256',\n name: 'blockNumber',\n type: 'uint256',\n },\n {\n internalType: 'bytes32',\n name: 'blockHash',\n type: 'bytes32',\n },\n {\n components: [\n {\n internalType: 'bool',\n name: 'success',\n type: 'bool',\n },\n {\n internalType: 'bytes',\n name: 'returnData',\n type: 'bytes',\n },\n ],\n internalType: 'struct Multicall3.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n ],\n stateMutability: 'payable',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getBasefee',\n outputs: [\n {\n internalType: 'uint256',\n name: 'basefee',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [\n {\n internalType: 'uint256',\n name: 'blockNumber',\n type: 'uint256',\n },\n ],\n name: 'getBlockHash',\n outputs: [\n {\n internalType: 'bytes32',\n name: 'blockHash',\n type: 'bytes32',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getBlockNumber',\n outputs: [\n {\n internalType: 'uint256',\n name: 'blockNumber',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getChainId',\n outputs: [\n {\n internalType: 'uint256',\n name: 'chainid',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getCurrentBlockCoinbase',\n outputs: [\n {\n internalType: 'address',\n name: 'coinbase',\n type: 'address',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getCurrentBlockDifficulty',\n outputs: [\n {\n internalType: 'uint256',\n name: 'difficulty',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getCurrentBlockGasLimit',\n outputs: [\n {\n internalType: 'uint256',\n name: 'gaslimit',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getCurrentBlockTimestamp',\n outputs: [\n {\n internalType: 'uint256',\n name: 'timestamp',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [\n {\n internalType: 'address',\n name: 'addr',\n type: 'address',\n },\n ],\n name: 'getEthBalance',\n outputs: [\n {\n internalType: 'uint256',\n name: 'balance',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'getLastBlockHash',\n outputs: [\n {\n internalType: 'bytes32',\n name: 'blockHash',\n type: 'bytes32',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [\n {\n internalType: 'bool',\n name: 'requireSuccess',\n type: 'bool',\n },\n {\n components: [\n {\n internalType: 'address',\n name: 'target',\n type: 'address',\n },\n {\n internalType: 'bytes',\n name: 'callData',\n type: 'bytes',\n },\n ],\n internalType: 'struct Multicall3.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'tryAggregate',\n outputs: [\n {\n components: [\n {\n internalType: 'bool',\n name: 'success',\n type: 'bool',\n },\n {\n internalType: 'bytes',\n name: 'returnData',\n type: 'bytes',\n },\n ],\n internalType: 'struct Multicall3.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n ],\n stateMutability: 'payable',\n type: 'function',\n },\n {\n inputs: [\n {\n internalType: 'bool',\n name: 'requireSuccess',\n type: 'bool',\n },\n {\n components: [\n {\n internalType: 'address',\n name: 'target',\n type: 'address',\n },\n {\n internalType: 'bytes',\n name: 'callData',\n type: 'bytes',\n },\n ],\n internalType: 'struct Multicall3.Call[]',\n name: 'calls',\n type: 'tuple[]',\n },\n ],\n name: 'tryBlockAndAggregate',\n outputs: [\n {\n internalType: 'uint256',\n name: 'blockNumber',\n type: 'uint256',\n },\n {\n internalType: 'bytes32',\n name: 'blockHash',\n type: 'bytes32',\n },\n {\n components: [\n {\n internalType: 'bool',\n name: 'success',\n type: 'bool',\n },\n {\n internalType: 'bytes',\n name: 'returnData',\n type: 'bytes',\n },\n ],\n internalType: 'struct Multicall3.Result[]',\n name: 'returnData',\n type: 'tuple[]',\n },\n ],\n stateMutability: 'payable',\n type: 'function',\n },\n] as const\n","/**\n * PanopticQuery contract ABI\n * Auto-generated from PanopticQuery.json\n * @module abis/panopticQuery\n */\n\nexport const panopticQueryAbi = [\n {\n type: 'constructor',\n inputs: [\n {\n name: 'SFPM_',\n type: 'address',\n internalType: 'contract ISemiFungiblePositionManager',\n },\n ],\n stateMutability: 'payable',\n },\n {\n type: 'function',\n name: 'checkCollateral',\n inputs: [\n { name: 'pool', type: 'address', internalType: 'contract PanopticPool' },\n { name: 'account', type: 'address', internalType: 'address' },\n { name: 'positionIdList', type: 'uint256[]', internalType: 'TokenId[]' },\n ],\n outputs: [\n { name: 'collateralBalances0', type: 'uint256[4]', internalType: 'uint256[4]' },\n { name: 'requiredCollaterals0', type: 'uint256[4]', internalType: 'uint256[4]' },\n { name: 'collateralBalances1', type: 'uint256[4]', internalType: 'uint256[4]' },\n { name: 'requiredCollaterals1', type: 'uint256[4]', internalType: 'uint256[4]' },\n ],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'checkCollateral',\n inputs: [\n { name: 'pool', type: 'address', internalType: 'contract PanopticPool' },\n { name: 'account', type: 'address', internalType: 'address' },\n { name: 'positionIdList', type: 'uint256[]', internalType: 'TokenId[]' },\n { name: 'atTick', type: 'int24', internalType: 'int24' },\n ],\n outputs: [{ name: 'balancesAndRequired', type: 'uint256[4]', internalType: 'uint256[4]' }],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'checkCollateralListOutput',\n inputs: [\n { name: 'pool', type: 'address', internalType: 'contract PanopticPool' },\n { name: 'account', type: 'address', internalType: 'address' },\n { name: 'positionIdList', type: 'uint256[]', internalType: 'TokenId[]' },\n ],\n outputs: [\n { name: '', type: 'uint256[2][]', internalType: 'uint256[2][]' },\n { name: '', type: 'int256[]', internalType: 'int256[]' },\n { name: '', type: 'int24[]', internalType: 'int24[]' },\n ],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'computeMedianObservedPrice',\n inputs: [\n { name: 'univ3pool', type: 'address', internalType: 'contract IUniswapV3Pool' },\n { name: 'cardinality', type: 'uint256', internalType: 'uint256' },\n { name: 'period', type: 'uint256', internalType: 'uint256' },\n ],\n outputs: [{ name: 'medianTick', type: 'int24', internalType: 'int24' }],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'getChunkData',\n inputs: [\n { name: 'pool', type: 'address', internalType: 'contract PanopticPool' },\n { name: 'positionIdList', type: 'uint256[]', internalType: 'TokenId[]' },\n ],\n outputs: [{ name: '', type: 'uint256[2][4][]', internalType: 'uint256[2][4][]' }],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'scanChunks',\n inputs: [\n { name: 'pool', type: 'address', internalType: 'contract PanopticPool' },\n { name: 'tickLower', type: 'int24', internalType: 'int24' },\n { name: 'tickUpper', type: 'int24', internalType: 'int24' },\n { name: 'width', type: 'int24', internalType: 'int24' },\n ],\n outputs: [\n { name: 'strikes', type: 'int24[]', internalType: 'int24[]' },\n { name: 'netLiquidities', type: 'uint128[2][]', internalType: 'uint128[2][]' },\n { name: 'removedLiquidities', type: 'uint128[2][]', internalType: 'uint128[2][]' },\n { name: 'settledTokens', type: 'uint256[2][]', internalType: 'LeftRightUnsigned[2][]' },\n ],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'getLiquidationPrices',\n inputs: [\n { name: 'pool', type: 'address', internalType: 'contract PanopticPool' },\n { name: 'account', type: 'address', internalType: 'address' },\n { name: 'positionIdList', type: 'uint256[]', internalType: 'TokenId[]' },\n ],\n outputs: [\n { name: 'liquidationPriceDown', type: 'int24', internalType: 'int24' },\n { name: 'liquidationPriceUp', type: 'int24', internalType: 'int24' },\n ],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'getMaxPositionSizeBounds',\n inputs: [\n { name: 'pool', type: 'address', internalType: 'contract PanopticPool' },\n { name: 'existingPositionIds', type: 'uint256[]', internalType: 'TokenId[]' },\n { name: 'account', type: 'address', internalType: 'address' },\n { name: 'tokenId', type: 'uint256', internalType: 'TokenId' },\n ],\n outputs: [\n { name: 'maxSizeAtMinUtil', type: 'uint128', internalType: 'uint128' },\n { name: 'maxSizeAtMaxUtil', type: 'uint128', internalType: 'uint128' },\n ],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'getNetLiquidationValue',\n inputs: [\n { name: 'pool', type: 'address', internalType: 'contract PanopticPool' },\n { name: 'account', type: 'address', internalType: 'address' },\n { name: 'includePendingPremium', type: 'bool', internalType: 'bool' },\n { name: 'positionIdList', type: 'uint256[]', internalType: 'TokenId[]' },\n { name: 'atTicks', type: 'int24[]', internalType: 'int24[]' },\n ],\n outputs: [\n { name: 'value0', type: 'int256[]', internalType: 'int256[]' },\n { name: 'value1', type: 'int256[]', internalType: 'int256[]' },\n ],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'getPortfolioValue',\n inputs: [\n { name: 'pool', type: 'address', internalType: 'contract PanopticPool' },\n { name: 'account', type: 'address', internalType: 'address' },\n { name: 'atTick', type: 'int24', internalType: 'int24' },\n { name: 'positionIdList', type: 'uint256[]', internalType: 'TokenId[]' },\n ],\n outputs: [\n { name: 'value0', type: 'int256', internalType: 'int256' },\n { name: 'value1', type: 'int256', internalType: 'int256' },\n ],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'getRequiredBase',\n inputs: [\n { name: 'pool', type: 'address', internalType: 'contract PanopticPool' },\n { name: 'tokenId', type: 'uint256', internalType: 'TokenId' },\n { name: 'atTick', type: 'int24', internalType: 'int24' },\n ],\n outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'getTickNets',\n inputs: [\n { name: 'pool', type: 'address', internalType: 'contract PanopticPool' },\n { name: 'startTick', type: 'int24', internalType: 'int24' },\n { name: 'nTicks', type: 'uint256', internalType: 'uint256' },\n ],\n outputs: [\n { name: 'tickData', type: 'int256[]', internalType: 'int256[]' },\n { name: 'liquidityNets', type: 'int256[]', internalType: 'int256[]' },\n ],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'getTickNetsV3',\n inputs: [\n { name: 'univ3pool', type: 'address', internalType: 'contract IUniswapV3Pool' },\n { name: 'startTick', type: 'int24', internalType: 'int24' },\n { name: 'nTicks', type: 'uint256', internalType: 'uint256' },\n ],\n outputs: [\n { name: 'tickData', type: 'int256[]', internalType: 'int256[]' },\n { name: 'liquidityNets', type: 'int256[]', internalType: 'int256[]' },\n ],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'getTickNetsV4',\n inputs: [\n { name: 'manager', type: 'address', internalType: 'contract IPoolManager' },\n { name: 'poolId', type: 'bytes32', internalType: 'PoolId' },\n { name: 'tickSpacing', type: 'int24', internalType: 'int24' },\n { name: 'startTick', type: 'int24', internalType: 'int24' },\n { name: 'nTicks', type: 'uint256', internalType: 'uint256' },\n ],\n outputs: [\n { name: 'tickData', type: 'int256[]', internalType: 'int256[]' },\n { name: 'liquidityNets', type: 'int256[]', internalType: 'int256[]' },\n ],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'isAccountSolvent',\n inputs: [\n { name: 'pool', type: 'address', internalType: 'contract PanopticPool' },\n { name: 'account', type: 'address', internalType: 'address' },\n { name: 'positionIdList', type: 'uint256[]', internalType: 'TokenId[]' },\n { name: 'atTick', type: 'int24', internalType: 'int24' },\n ],\n outputs: [{ name: '', type: 'bool', internalType: 'bool' }],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'optimizeRiskPartners',\n inputs: [\n { name: 'pool', type: 'address', internalType: 'contract PanopticPool' },\n { name: 'atTick', type: 'int24', internalType: 'int24' },\n { name: 'tokenId', type: 'uint256', internalType: 'TokenId' },\n ],\n outputs: [{ name: '', type: 'uint256', internalType: 'TokenId' }],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'twapFilter',\n inputs: [\n { name: 'univ3pool', type: 'address', internalType: 'contract IUniswapV3Pool' },\n { name: 'twapWindow', type: 'uint32', internalType: 'uint32' },\n ],\n outputs: [{ name: '', type: 'int24', internalType: 'int24' }],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'validateTokenId',\n inputs: [{ name: 'self', type: 'uint256', internalType: 'TokenId' }],\n outputs: [],\n stateMutability: 'pure',\n },\n {\n type: 'error',\n name: 'CastingError',\n inputs: [],\n },\n {\n type: 'error',\n name: 'InvalidTick',\n inputs: [],\n },\n {\n type: 'error',\n name: 'InvalidTokenIdParameter',\n inputs: [{ name: 'parameterType', type: 'uint256', internalType: 'uint256' }],\n },\n {\n type: 'error',\n name: 'LiquidityTooHigh',\n inputs: [],\n },\n {\n type: 'error',\n name: 'UnderOverFlow',\n inputs: [],\n },\n] as const\n","import type { Address, Client, Hex } from 'viem'\nimport { decodeFunctionResult, encodeFunctionData } from 'viem'\nimport { call } from 'viem/actions'\n\nimport { Multicall3Abi } from '../../../abis/multicall3'\nimport {\n MulticallNoDataError,\n MulticallResultFailedError,\n MulticallResultMissingError,\n} from '../errors'\nimport type { BlockMeta } from '../types'\n\nexport const MULTICALL3_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11' as const\n\nexport interface MulticallBlockCall {\n target: Address\n callData: Hex\n}\n\nexport interface MulticallBlockResult {\n success: boolean\n returnData: Hex\n}\n\ninterface ClientWithCall extends Client {\n call: (parameters: { to: Address; data: Hex; blockNumber?: bigint }) => Promise<{ data?: Hex }>\n}\n\nfunction hasCall(client: Client): client is ClientWithCall {\n return 'call' in client && typeof (client as Record<'call', unknown>).call === 'function'\n}\n\nfunction requireResult(\n results: readonly MulticallBlockResult[],\n index: number,\n label: string,\n): MulticallBlockResult {\n const result = results[index]\n if (result === undefined) {\n throw new MulticallResultMissingError(label, index)\n }\n if (!result.success) {\n throw new MulticallResultFailedError(label, index)\n }\n return result\n}\n\nexport function requireReturnData(\n results: readonly MulticallBlockResult[],\n index: number,\n label: string,\n): Hex {\n return requireResult(results, index, label).returnData\n}\n\nexport async function readBlockAndAggregate({\n client,\n calls,\n blockNumber,\n}: {\n client: Client\n calls: readonly MulticallBlockCall[]\n blockNumber?: bigint\n}): Promise<{ _meta: BlockMeta; results: readonly MulticallBlockResult[] }> {\n const aggregateCalls = [\n ...calls,\n {\n target: MULTICALL3_ADDRESS,\n callData: encodeFunctionData({\n abi: Multicall3Abi,\n functionName: 'getCurrentBlockTimestamp',\n }),\n },\n ]\n\n const data = encodeFunctionData({\n abi: Multicall3Abi,\n functionName: 'blockAndAggregate',\n args: [aggregateCalls],\n })\n const parameters = { to: MULTICALL3_ADDRESS, data, blockNumber }\n const response = hasCall(client) ? await client.call(parameters) : await call(client, parameters)\n\n if (response.data === undefined) {\n throw new MulticallNoDataError('blockAndAggregate')\n }\n const aggregateResult = decodeFunctionResult({\n abi: Multicall3Abi,\n functionName: 'blockAndAggregate',\n data: response.data,\n })\n const [aggregateBlockNumber, blockHash, rawResults] = aggregateResult as readonly [\n bigint,\n Hex,\n readonly MulticallBlockResult[],\n ]\n const timestampResult = requireReturnData(\n rawResults,\n calls.length,\n 'Multicall3.getCurrentBlockTimestamp',\n )\n const blockTimestamp = decodeFunctionResult({\n abi: Multicall3Abi,\n functionName: 'getCurrentBlockTimestamp',\n data: timestampResult,\n })\n\n return {\n _meta: {\n blockNumber: aggregateBlockNumber,\n blockHash,\n blockTimestamp,\n },\n results: rawResults.slice(0, calls.length),\n }\n}\n","/**\n * Position and account check functions for the Panoptic v2 SDK.\n *\n * These functions check account liquidatability.\n *\n * @module v2/reads/checks\n */\n\nimport type { Address, PublicClient } from 'viem'\nimport { decodeFunctionResult, encodeFunctionData } from 'viem'\n\nimport { collateralTrackerV2Abi, panopticPoolV2Abi } from '../../../generated'\nimport { tickToSqrtPriceX96 } from '../formatters/tick'\nimport type { BlockMeta } from '../types'\nimport { decodeLeftRightUnsigned } from '../writes/utils'\nimport { type MulticallBlockCall, readBlockAndAggregate, requireReturnData } from './multicallBlock'\n\nconst FP96 = 1n << 96n\nconst Q128 = 1n << 128n\n\nfunction convert0to1(amount: bigint, sqrtPriceX96: bigint): bigint {\n if (sqrtPriceX96 < Q128) {\n return (amount * sqrtPriceX96 * sqrtPriceX96) >> 192n\n }\n const sp2Hi = (sqrtPriceX96 * sqrtPriceX96) >> 64n\n return (amount * sp2Hi) >> 128n\n}\n\nfunction convert1to0(amount: bigint, sqrtPriceX96: bigint): bigint {\n if (sqrtPriceX96 < Q128) {\n const denom = sqrtPriceX96 * sqrtPriceX96\n return (amount * (1n << 192n)) / denom\n }\n const sp2Hi = (sqrtPriceX96 * sqrtPriceX96) >> 64n\n return (amount * (1n << 128n)) / sp2Hi\n}\n\n/**\n * Liquidation check result with detailed margin breakdown.\n *\n * **Denomination**: both per-token pairs hold the gross account total\n * cross-converted to that single token denomination at `atTick`.\n * - `currentMargin0` / `requiredMargin0` are in token0 units\n * - `currentMargin1` / `requiredMargin1` are in token1 units\n *\n * `denominatedInToken` indicates which pair is \"preferred\": 0n when\n * `atTick < 0` (token0), 1n otherwise.\n */\nexport interface LiquidationCheck {\n /** Whether the account is liquidatable */\n isLiquidatable: boolean\n /** Margin shortfall for slot 0 (positive = shortfall, negative = excess) */\n marginShortfall0: bigint\n /** Margin shortfall for slot 1 (positive = shortfall, negative = excess) */\n marginShortfall1: bigint\n /** Current (gross) margin (collateral balance), denominated in token0 */\n currentMargin0: bigint\n /** Current (gross) margin, denominated in token1 */\n currentMargin1: bigint\n /** Required margin (sum of per-position requirements), denominated in token0 */\n requiredMargin0: bigint\n /** Required margin, denominated in token1 */\n requiredMargin1: bigint\n /**\n * Which token the \"preferred\" margin pair is denominated in.\n * 0n = token0 (when atTick < 0), 1n = token1 (when atTick >= 0).\n */\n denominatedInToken: bigint\n /** Tick at which liquidation was checked */\n atTick: bigint\n /** Block metadata */\n _meta: BlockMeta\n}\n\n/**\n * Parameters for isLiquidatable.\n */\nexport interface IsLiquidatableParams {\n /** viem PublicClient */\n client: PublicClient\n /** PanopticPool address */\n poolAddress: Address\n /** Account to check */\n account: Address\n /** TokenIds of open positions */\n tokenIds: bigint[]\n /**\n * Optional: Tick to check liquidation at (defaults to current tick).\n * Note: collateral requirements are evaluated by the contract at the\n * pool's current tick — `atTick` here governs only the cross-token\n * sqrtPrice used to express the totals in a single denomination.\n */\n atTick?: bigint\n /** PanopticQuery address (kept for backwards compatibility; unused). */\n queryAddress?: Address\n /**\n * Optional pre-fetched collateral tracker addresses (saves an RPC).\n * If omitted, they are fetched from the pool.\n */\n collateralAddresses?: { collateralToken0: Address; collateralToken1: Address }\n /** Optional block number for historical queries */\n blockNumber?: bigint\n /** Optional pre-fetched block metadata (skips getBlockMeta RPC call) */\n _meta?: BlockMeta\n}\n\n/**\n * Check if an account is liquidatable with detailed margin breakdown.\n *\n * Sources gross collateral from `CollateralTracker.assetsOf` and per-position\n * required margin from `PanopticPool.getFullPositionsData.collateralRequirements[]`,\n * cross-converted to each token denomination at `atTick`. Loan tokenIds\n * (width=0 shorts) contribute correctly to required margin.\n *\n * @param params - The parameters\n * @returns Liquidation check result with detailed margin breakdown\n *\n * @example\n * ```typescript\n * const result = await isLiquidatable({\n * client,\n * poolAddress,\n * account,\n * tokenIds: [position1, position2],\n * })\n *\n * if (result.isLiquidatable) {\n * console.log('Account is liquidatable!')\n * }\n * ```\n */\nexport async function isLiquidatable(params: IsLiquidatableParams): Promise<LiquidationCheck> {\n const { client, poolAddress, account, tokenIds, atTick, blockNumber } = params\n\n const targetBlockNumber =\n blockNumber ?? params._meta?.blockNumber ?? (await client.getBlockNumber())\n\n // Resolve collateral tracker addresses (immutable; cache-friendly).\n let collateralToken0: Address\n let collateralToken1: Address\n if (params.collateralAddresses) {\n collateralToken0 = params.collateralAddresses.collateralToken0\n collateralToken1 = params.collateralAddresses.collateralToken1\n } else {\n const addrs = await client.multicall({\n contracts: [\n { address: poolAddress, abi: panopticPoolV2Abi, functionName: 'collateralToken0' },\n { address: poolAddress, abi: panopticPoolV2Abi, functionName: 'collateralToken1' },\n ],\n blockNumber: targetBlockNumber,\n allowFailure: false,\n })\n collateralToken0 = addrs[0]\n collateralToken1 = addrs[1]\n }\n\n const calls: MulticallBlockCall[] = []\n const currentTickIndex = atTick === undefined ? calls.length : null\n if (currentTickIndex !== null) {\n calls.push({\n target: poolAddress,\n callData: encodeFunctionData({\n abi: panopticPoolV2Abi,\n functionName: 'getCurrentTick',\n }),\n })\n }\n\n const assets0Index = calls.length\n calls.push({\n target: collateralToken0,\n callData: encodeFunctionData({\n abi: collateralTrackerV2Abi,\n functionName: 'assetsOf',\n args: [account],\n }),\n })\n\n const assets1Index = calls.length\n calls.push({\n target: collateralToken1,\n callData: encodeFunctionData({\n abi: collateralTrackerV2Abi,\n functionName: 'assetsOf',\n args: [account],\n }),\n })\n\n const positionDataIndex = tokenIds.length > 0 ? calls.length : null\n if (positionDataIndex !== null) {\n calls.push({\n target: poolAddress,\n callData: encodeFunctionData({\n abi: panopticPoolV2Abi,\n functionName: 'getFullPositionsData',\n args: [account, true, tokenIds],\n }),\n })\n }\n\n const { _meta, results } = await readBlockAndAggregate({\n client,\n calls,\n blockNumber: targetBlockNumber,\n })\n\n let effectiveTick = atTick\n if (effectiveTick === undefined) {\n if (currentTickIndex === null) {\n throw new Error('Missing current tick Multicall3 result index')\n }\n effectiveTick = BigInt(\n decodeFunctionResult({\n abi: panopticPoolV2Abi,\n functionName: 'getCurrentTick',\n data: requireReturnData(results, currentTickIndex, 'PanopticPool.getCurrentTick'),\n }),\n )\n }\n const assets0 = decodeFunctionResult({\n abi: collateralTrackerV2Abi,\n functionName: 'assetsOf',\n data: requireReturnData(results, assets0Index, 'CollateralTracker.assetsOf token0'),\n })\n const assets1 = decodeFunctionResult({\n abi: collateralTrackerV2Abi,\n functionName: 'assetsOf',\n data: requireReturnData(results, assets1Index, 'CollateralTracker.assetsOf token1'),\n })\n const positionDataResult =\n positionDataIndex === null\n ? null\n : (decodeFunctionResult({\n abi: panopticPoolV2Abi,\n functionName: 'getFullPositionsData',\n data: requireReturnData(results, positionDataIndex, 'PanopticPool.getFullPositionsData'),\n }) as readonly [bigint, bigint, readonly bigint[], readonly bigint[], readonly bigint[]])\n\n let required0Native = 0n\n let required1Native = 0n\n if (positionDataResult) {\n const collateralRequirements = positionDataResult[3]\n for (const packed of collateralRequirements) {\n const decoded = decodeLeftRightUnsigned(packed)\n required0Native += decoded.right\n required1Native += decoded.left\n }\n }\n\n const sqrtPriceX96 = tickToSqrtPriceX96(effectiveTick)\n const currentMargin0 = assets0 + convert1to0(assets1, sqrtPriceX96)\n const requiredMargin0 = required0Native + convert1to0(required1Native, sqrtPriceX96)\n const currentMargin1 = assets1 + convert0to1(assets0, sqrtPriceX96)\n const requiredMargin1 = required1Native + convert0to1(required0Native, sqrtPriceX96)\n\n const marginShortfall0 = requiredMargin0 - currentMargin0\n const marginShortfall1 = requiredMargin1 - currentMargin1\n const denominatedInToken: bigint = sqrtPriceX96 < FP96 ? 0n : 1n\n const isLiquidatableResult =\n denominatedInToken === 0n ? marginShortfall0 > 0n : marginShortfall1 > 0n\n\n return {\n isLiquidatable: isLiquidatableResult,\n marginShortfall0,\n marginShortfall1,\n currentMargin0,\n currentMargin1,\n requiredMargin0,\n requiredMargin1,\n denominatedInToken,\n atTick: effectiveTick,\n _meta,\n }\n}\n","/**\n * Account read functions for the Panoptic v2 SDK.\n *\n * ## Same-Block Guarantee\n *\n * All dynamic data is fetched in a SINGLE multicall to ensure block consistency.\n * Per PLAN.md §6, immutable \"static prefetch\" data (addresses) can be fetched\n * separately and cached - it's not subject to same-block consistency.\n *\n * @module v2/reads/account\n */\n\nimport type { Address, PublicClient } from 'viem'\n\nimport { collateralTrackerV2Abi, panopticPoolV2Abi } from '../../../generated'\nimport { panopticQueryAbi } from '../abis/panopticQuery'\nimport { getBlockMeta } from '../clients/blockMeta'\nimport type {\n AccountCollateral,\n AccountSummaryBasic,\n AccountSummaryRisk,\n BlockMeta,\n LiquidationPrices,\n NetLiquidationValue,\n NetLiquidationValues,\n TokenCollateral,\n} from '../types'\nimport { isLiquidatable } from './checks'\nimport { type PoolMetadata, getPool } from './pool'\nimport { getPositions } from './position'\n\n/**\n * Collateral tracker addresses (immutable, can be cached).\n */\nexport interface CollateralAddresses {\n /** Collateral tracker 0 address */\n collateralToken0: Address\n /** Collateral tracker 1 address */\n collateralToken1: Address\n}\n\n/**\n * Extract collateral tracker addresses from a Pool object.\n *\n * Convenience helper that avoids re-fetching immutable addresses\n * when you already have a Pool from a prior `getPool()` call.\n *\n * @param pool - Pool object from getPool()\n * @returns Collateral tracker addresses\n */\nexport function getCollateralAddresses(pool: {\n collateralTracker0: { address: Address }\n collateralTracker1: { address: Address }\n}): CollateralAddresses {\n return {\n collateralToken0: pool.collateralTracker0.address,\n collateralToken1: pool.collateralTracker1.address,\n }\n}\n\n/**\n * Parameters for getAccountCollateral.\n */\nexport interface GetAccountCollateralParams {\n /** viem PublicClient */\n client: PublicClient\n /** PanopticPool address */\n poolAddress: Address\n /** Account address */\n account: Address\n /** Optional block number for historical queries */\n blockNumber?: bigint\n /** Optional pre-fetched collateral addresses (for caching/optimization) */\n collateralAddresses?: CollateralAddresses\n /** Optional pre-fetched block metadata (skips getBlockMeta RPC call) */\n _meta?: BlockMeta\n}\n\n/**\n * Get collateral data for an account.\n *\n * ## Same-Block Guarantee\n * All dynamic data is fetched in ONE multicall at the target block.\n * Collateral tracker addresses are either provided or fetched separately (static prefetch).\n *\n * @param params - The parameters\n * @returns Account collateral data with block metadata\n */\nexport async function getAccountCollateral(\n params: GetAccountCollateralParams,\n): Promise<AccountCollateral> {\n const { client, poolAddress, account, blockNumber, collateralAddresses } = params\n\n const targetBlockNumber =\n blockNumber ?? params._meta?.blockNumber ?? (await client.getBlockNumber())\n\n // Get collateral tracker addresses (static prefetch if not provided)\n let collateralToken0: Address\n let collateralToken1: Address\n\n if (collateralAddresses) {\n collateralToken0 = collateralAddresses.collateralToken0\n collateralToken1 = collateralAddresses.collateralToken1\n } else {\n // Static prefetch - addresses are immutable\n const addressResults = await client.multicall({\n contracts: [\n {\n address: poolAddress,\n abi: panopticPoolV2Abi,\n functionName: 'collateralToken0',\n },\n {\n address: poolAddress,\n abi: panopticPoolV2Abi,\n functionName: 'collateralToken1',\n },\n ],\n allowFailure: false,\n })\n collateralToken0 = addressResults[0]\n collateralToken1 = addressResults[1]\n }\n\n // SINGLE multicall for ALL dynamic data - ensures same-block consistency\n const [dynamicResults, _meta] = await Promise.all([\n client.multicall({\n contracts: [\n // Token 0 collateral data\n {\n address: collateralToken0,\n abi: collateralTrackerV2Abi,\n functionName: 'balanceOf',\n args: [account],\n },\n {\n address: collateralToken0,\n abi: collateralTrackerV2Abi,\n functionName: 'assetsOf',\n args: [account],\n },\n {\n address: collateralToken0,\n abi: collateralTrackerV2Abi,\n functionName: 'maxWithdraw',\n args: [account],\n },\n // Token 1 collateral data\n {\n address: collateralToken1,\n abi: collateralTrackerV2Abi,\n functionName: 'balanceOf',\n args: [account],\n },\n {\n address: collateralToken1,\n abi: collateralTrackerV2Abi,\n functionName: 'assetsOf',\n args: [account],\n },\n {\n address: collateralToken1,\n abi: collateralTrackerV2Abi,\n functionName: 'maxWithdraw',\n args: [account],\n },\n // Leg count from pool\n {\n address: poolAddress,\n abi: panopticPoolV2Abi,\n functionName: 'numberOfLegs',\n args: [account],\n },\n ],\n blockNumber: targetBlockNumber,\n allowFailure: false,\n }),\n params._meta ?? getBlockMeta({ client, blockNumber: targetBlockNumber }),\n ])\n\n const [shares0, assets0, maxWithdraw0, shares1, assets1, maxWithdraw1, legCount] = dynamicResults\n\n // Calculate locked assets as total - available (maxWithdraw)\n const locked0 = assets0 > maxWithdraw0 ? assets0 - maxWithdraw0 : 0n\n const locked1 = assets1 > maxWithdraw1 ? assets1 - maxWithdraw1 : 0n\n\n const token0: TokenCollateral = {\n assets: assets0,\n shares: shares0,\n availableAssets: maxWithdraw0,\n lockedAssets: locked0,\n }\n\n const token1: TokenCollateral = {\n assets: assets1,\n shares: shares1,\n availableAssets: maxWithdraw1,\n lockedAssets: locked1,\n }\n\n return {\n account,\n poolAddress,\n token0,\n token1,\n legCount,\n _meta,\n }\n}\n\n/**\n * Parameters for getAccountSummaryBasic.\n */\nexport interface GetAccountSummaryBasicParams {\n /** viem PublicClient */\n client: PublicClient\n /** PanopticPool address */\n poolAddress: Address\n /** Account address */\n account: Address\n /** Chain ID */\n chainId: bigint\n /** TokenIds of open positions */\n tokenIds: bigint[]\n /** Optional block number for historical queries */\n blockNumber?: bigint\n /** Optional pre-fetched pool metadata (for caching/optimization) */\n poolMetadata?: PoolMetadata\n /** Optional pre-fetched block metadata (skips getBlockMeta RPC call) */\n _meta?: BlockMeta\n}\n\n/**\n * Parameters for getAccountSummaryRisk.\n */\nexport interface GetAccountSummaryRiskParams extends GetAccountSummaryBasicParams {\n /** PanopticQuery address (required for risk fields) */\n queryAddress: Address\n /** Optional: Tick to calculate risk metrics at (defaults to current tick) */\n atTick?: bigint\n /** Optional: Whether to include pending premium in NLV */\n includePendingPremium?: boolean\n}\n\ninterface AccountSummaryCoreData {\n pool: Awaited<ReturnType<typeof getPool>>\n collateral: AccountCollateral\n positions: Awaited<ReturnType<typeof getPositions>>['positions']\n _meta: BlockMeta\n}\n\nasync function getAccountSummaryCore(\n params: GetAccountSummaryBasicParams,\n): Promise<AccountSummaryCoreData> {\n const { client, poolAddress, account, chainId, tokenIds, blockNumber, poolMetadata } = params\n\n const targetBlockNumber =\n blockNumber ?? params._meta?.blockNumber ?? (await client.getBlockNumber())\n const sharedMeta =\n params._meta ?? (await getBlockMeta({ client, blockNumber: targetBlockNumber }))\n\n const collateralAddresses = poolMetadata\n ? {\n collateralToken0: poolMetadata.collateralToken0Address,\n collateralToken1: poolMetadata.collateralToken1Address,\n }\n : undefined\n\n const [pool, collateral, { positions }] = await Promise.all([\n getPool({\n client,\n poolAddress,\n chainId,\n blockNumber: targetBlockNumber,\n poolMetadata,\n _meta: sharedMeta,\n }),\n getAccountCollateral({\n client,\n poolAddress,\n account,\n blockNumber: targetBlockNumber,\n collateralAddresses,\n _meta: sharedMeta,\n }),\n getPositions({\n client,\n poolAddress,\n owner: account,\n tokenIds,\n blockNumber: targetBlockNumber,\n _meta: sharedMeta,\n }),\n ])\n\n return {\n pool,\n collateral,\n positions,\n _meta: sharedMeta,\n }\n}\n\n/**\n * Get base account summary data for UI dashboards.\n *\n * ## Same-Block Guarantee\n * Uses the same blockNumber for pool, collateral, and position reads.\n *\n * @param params - The parameters\n * @returns Base account summary with block metadata\n */\nexport async function getAccountSummaryBasic(\n params: GetAccountSummaryBasicParams,\n): Promise<AccountSummaryBasic> {\n const { account } = params\n const { pool, collateral, positions, _meta } = await getAccountSummaryCore(params)\n\n return {\n account,\n pool,\n collateral,\n positions,\n healthStatus: pool.healthStatus,\n networkMismatch: false, // Requires wallet context, not available in read functions\n _meta,\n }\n}\n\n/**\n * Get risk-focused account summary including helper-dependent fields.\n *\n * ## Same-Block Guarantee\n * Uses one block target for all pool/collateral/position/risk reads.\n *\n * @param params - The parameters\n * @returns Risk-focused account summary with block metadata\n */\nexport async function getAccountSummaryRisk(\n params: GetAccountSummaryRiskParams,\n): Promise<AccountSummaryRisk> {\n const {\n client,\n poolAddress,\n account,\n tokenIds,\n queryAddress,\n atTick,\n includePendingPremium = true,\n blockNumber,\n } = params\n\n const targetBlockNumber =\n blockNumber ?? params._meta?.blockNumber ?? (await client.getBlockNumber())\n const sharedMeta =\n params._meta ?? (await getBlockMeta({ client, blockNumber: targetBlockNumber }))\n\n const [{ pool, collateral, positions }, nlv, liquidationCheck, liquidationPrices] =\n await Promise.all([\n getAccountSummaryCore({\n ...params,\n blockNumber: targetBlockNumber,\n _meta: sharedMeta,\n }),\n getNetLiquidationValue({\n client,\n poolAddress,\n account,\n tokenIds,\n atTick,\n includePendingPremium,\n queryAddress,\n blockNumber: targetBlockNumber,\n _meta: sharedMeta,\n }),\n isLiquidatable({\n client,\n poolAddress,\n account,\n tokenIds,\n atTick,\n queryAddress,\n blockNumber: targetBlockNumber,\n _meta: sharedMeta,\n }),\n getLiquidationPrices({\n client,\n poolAddress,\n account,\n tokenIds,\n queryAddress,\n blockNumber: targetBlockNumber,\n _meta: sharedMeta,\n }),\n ])\n\n const totalGreeks = {\n value: 0n,\n delta: 0n,\n gamma: 0n,\n }\n\n const maintenanceMargin0 = liquidationCheck.requiredMargin0\n const maintenanceMargin1 = liquidationCheck.requiredMargin1\n const marginExcess0 = liquidationCheck.currentMargin0 - liquidationCheck.requiredMargin0\n const marginExcess1 = liquidationCheck.currentMargin1 - liquidationCheck.requiredMargin1\n\n return {\n account,\n pool,\n collateral,\n positions,\n totalGreeks,\n netLiquidationValue0: nlv.value0,\n netLiquidationValue1: nlv.value1,\n maintenanceMargin0,\n maintenanceMargin1,\n marginExcess0,\n marginExcess1,\n marginShortfall0: liquidationCheck.marginShortfall0,\n marginShortfall1: liquidationCheck.marginShortfall1,\n currentMargin0: liquidationCheck.currentMargin0,\n currentMargin1: liquidationCheck.currentMargin1,\n isLiquidatable: liquidationCheck.isLiquidatable,\n liquidationPrices,\n healthStatus: pool.healthStatus,\n networkMismatch: false, // Requires wallet context, not available in read functions\n _meta: sharedMeta,\n }\n}\n\n/**\n * Parameters for getNetLiquidationValue.\n */\nexport interface GetNetLiquidationValueParams {\n /** viem PublicClient */\n client: PublicClient\n /** PanopticPool address */\n poolAddress: Address\n /** Account address */\n account: Address\n /** TokenIds of open positions */\n tokenIds: bigint[]\n /** Optional: Tick to calculate NLV at (defaults to current tick) */\n atTick?: bigint\n /** Optional: Whether to include pending premium */\n includePendingPremium?: boolean\n /** PanopticQuery address (required) */\n queryAddress: Address\n /** Optional block number for historical queries */\n blockNumber?: bigint\n /** Optional pre-fetched block metadata (skips getBlockMeta RPC call) */\n _meta?: BlockMeta\n}\n\n/**\n * Get net liquidation value for an account.\n *\n * ## Same-Block Guarantee\n * Tick and NLV are queried at the same target block.\n *\n * Requires PanopticQuery for accurate value and premium accounting.\n *\n * @param params - The parameters\n * @returns Net liquidation value with block metadata\n */\nexport async function getNetLiquidationValue(\n params: GetNetLiquidationValueParams,\n): Promise<NetLiquidationValue> {\n const {\n client,\n poolAddress,\n account,\n tokenIds,\n atTick,\n includePendingPremium = true,\n queryAddress,\n blockNumber,\n } = params\n\n const targetBlockNumber =\n blockNumber ?? params._meta?.blockNumber ?? (await client.getBlockNumber())\n\n // Skip getCurrentTick RPC call when atTick is provided\n const [currentTickResult, _meta] = await Promise.all([\n atTick != null\n ? Promise.resolve(atTick)\n : client\n .readContract({\n address: poolAddress,\n abi: panopticPoolV2Abi,\n functionName: 'getCurrentTick',\n blockNumber: targetBlockNumber,\n })\n .then((r) => BigInt(r)),\n params._meta ?? getBlockMeta({ client, blockNumber: targetBlockNumber }),\n ])\n\n const effectiveTick = currentTickResult\n\n // PanopticQuery only exposes the int24[] overload; query a single tick and unwrap.\n const result = await client.readContract({\n address: queryAddress,\n abi: panopticQueryAbi,\n functionName: 'getNetLiquidationValue',\n args: [poolAddress, account, includePendingPremium, tokenIds, [Number(effectiveTick)]],\n blockNumber: targetBlockNumber,\n })\n\n const [values0, values1] = result\n const value0 = values0[0]\n const value1 = values1[0]\n\n return {\n value0,\n value1,\n atTick: effectiveTick,\n includedPendingPremium: includePendingPremium,\n _meta,\n }\n}\n\n/**\n * Parameters for getNetLiquidationValues (batch/multi-tick).\n */\nexport interface GetNetLiquidationValuesParams {\n /** viem PublicClient */\n client: PublicClient\n /** PanopticPool address */\n poolAddress: Address\n /** Account address */\n account: Address\n /** TokenIds of open positions */\n tokenIds: bigint[]\n /** Ticks to calculate NLV at */\n atTicks: bigint[]\n /** Optional: Whether to include pending premium */\n includePendingPremium?: boolean\n /** PanopticQuery address (required) */\n queryAddress: Address\n /** Optional block number for historical queries */\n blockNumber?: bigint\n /** Optional pre-fetched block metadata (skips getBlockMeta RPC call) */\n _meta?: BlockMeta\n}\n\n/**\n * Get net liquidation values at multiple ticks in a single contract call.\n *\n * Uses the `int24[]` overload of `getNetLiquidationValue` on PanopticQuery.\n *\n * @param params - The parameters\n * @returns Net liquidation values with block metadata\n */\nexport async function getNetLiquidationValues(\n params: GetNetLiquidationValuesParams,\n): Promise<NetLiquidationValues> {\n const {\n client,\n poolAddress,\n account,\n tokenIds,\n atTicks,\n includePendingPremium = true,\n queryAddress,\n blockNumber,\n } = params\n\n const targetBlockNumber =\n blockNumber ?? params._meta?.blockNumber ?? (await client.getBlockNumber())\n\n // Use an isolated ABI with only the int24[] overload to avoid viem overload ambiguity\n const batchNlvAbi = [\n {\n type: 'function' as const,\n name: 'getNetLiquidationValue' as const,\n inputs: [\n { name: 'pool', type: 'address' as const },\n { name: 'account', type: 'address' as const },\n { name: 'includePendingPremium', type: 'bool' as const },\n { name: 'positionIdList', type: 'uint256[]' as const },\n { name: 'atTicks', type: 'int24[]' as const },\n ],\n outputs: [\n { name: 'value0', type: 'int256[]' as const },\n { name: 'value1', type: 'int256[]' as const },\n ],\n stateMutability: 'view' as const,\n },\n ] as const\n\n const [result, _meta] = await Promise.all([\n client.readContract({\n address: queryAddress,\n abi: batchNlvAbi,\n functionName: 'getNetLiquidationValue',\n args: [poolAddress, account, includePendingPremium, tokenIds, atTicks.map((t) => Number(t))],\n blockNumber: targetBlockNumber,\n }),\n params._meta ?? getBlockMeta({ client, blockNumber: targetBlockNumber }),\n ])\n\n const [values0, values1] = result\n\n return {\n values0: [...values0],\n values1: [...values1],\n atTicks,\n _meta,\n }\n}\n\n/**\n * Parameters for getLiquidationPrices.\n */\nexport interface GetLiquidationPricesParams {\n /** viem PublicClient */\n client: PublicClient\n /** PanopticPool address */\n poolAddress: Address\n /** Account address */\n account: Address\n /** TokenIds of open positions */\n tokenIds: bigint[]\n /** PanopticQuery address (required) */\n queryAddress: Address\n /** Optional block number for historical queries */\n blockNumber?: bigint\n /** Optional pre-fetched block metadata (skips getBlockMeta RPC call) */\n _meta?: BlockMeta\n}\n\n/**\n * Get liquidation prices for an account.\n *\n * ## Same-Block Guarantee\n * Liquidation price query is made at a single block.\n *\n * @param params - The parameters\n * @returns Liquidation prices with block metadata\n */\nexport async function getLiquidationPrices(\n params: GetLiquidationPricesParams,\n): Promise<LiquidationPrices> {\n const { client, poolAddress, account, tokenIds, queryAddress, blockNumber } = params\n\n const targetBlockNumber =\n blockNumber ?? params._meta?.blockNumber ?? (await client.getBlockNumber())\n\n // MIN_TICK and MAX_TICK indicate no liquidation at that boundary\n const MIN_TICK = -887272n\n const MAX_TICK = 887272n\n\n const [result, _meta] = await Promise.all([\n client.readContract({\n address: queryAddress,\n abi: panopticQueryAbi,\n functionName: 'getLiquidationPrices',\n args: [poolAddress, account, tokenIds],\n blockNumber: targetBlockNumber,\n }),\n params._meta ?? getBlockMeta({ client, blockNumber: targetBlockNumber }),\n ])\n\n // Convert from number (abitype default for int24) to bigint (viem runtime type)\n const liqPriceDown = BigInt(result[0])\n const liqPriceUp = BigInt(result[1])\n\n return {\n lowerTick: liqPriceDown === MIN_TICK ? null : liqPriceDown,\n upperTick: liqPriceUp === MAX_TICK ? null : liqPriceUp,\n isLiquidatable: liqPriceDown !== MIN_TICK || liqPriceUp !== MAX_TICK,\n _meta,\n }\n}\n","/**\n * Collateral read functions for the Panoptic v2 SDK.\n *\n * ## Same-Block Guarantee\n *\n * All dynamic data is fetched in a SINGLE multicall to ensure block consistency.\n * Per PLAN.md §6, immutable \"static prefetch\" data (addresses, symbols, decimals)\n * can be fetched separately and cached - it's not subject to same-block consistency.\n *\n * @module v2/reads/collateral\n */\n\nimport type { Address, PublicClient } from 'viem'\n\nimport { collateralTrackerV2Abi, panopticPoolV2Abi } from '../../../generated'\nimport { getBlockMeta } from '../clients/blockMeta'\nimport type { BlockMeta, CollateralTracker, CurrentRates } from '../types'\n\nconst SECONDS_PER_YEAR = 31_536_000n\n\n// ERC20 minimal ABI for token metadata\nconst erc20Abi = [\n {\n type: 'function',\n name: 'symbol',\n inputs: [],\n outputs: [{ type: 'string' }],\n stateMutability: 'view',\n },\n {\n type: 'function',\n name: 'decimals',\n inputs: [],\n outputs: [{ type: 'uint8' }],\n stateMutability: 'view',\n },\n] as const\n\n/**\n * Pre-fetched collateral tracker metadata (immutable, can be cached).\n */\nexport interface CollateralTrackerMetadata {\n /** Collateral tracker address */\n address: Address\n /** Underlying asset address */\n assetAddress: Address\n /** Token symbol */\n symbol: string\n /** Token decimals */\n decimals: bigint\n}\n\n/**\n * Parameters for getCollateralData.\n */\nexport interface GetCollateralDataParams {\n /** viem PublicClient */\n client: PublicClient\n /** PanopticPool address */\n poolAddress: Address\n /** Which token's collateral tracker to query (0 or 1) */\n tokenIndex: 0 | 1\n /** Optional block number for historical queries */\n blockNumber?: bigint\n /** Optional pre-fetched collateral tracker metadata (for caching/optimization) */\n trackerMetadata?: CollateralTrackerMetadata\n /** Optional pre-fetched block metadata (skips getBlockMeta RPC call) */\n _meta?: BlockMeta\n}\n\n/**\n * Get collateral tracker data for a specific token.\n *\n * ## Same-Block Guarantee\n * All dynamic data is fetched in ONE multicall at the target block.\n * Static metadata (address, symbol, decimals) is either provided or fetched separately.\n *\n * @param params - The parameters\n * @returns Collateral tracker data with block metadata\n */\nexport async function getCollateralData(\n params: GetCollateralDataParams,\n): Promise<CollateralTracker & { _meta: BlockMeta }> {\n const { client, poolAddress, tokenIndex, blockNumber, trackerMetadata } = params\n\n const targetBlockNumber =\n blockNumber ?? params._meta?.blockNumber ?? (await client.getBlockNumber())\n\n // If metadata is provided, we only need ONE multicall for dynamic data\n if (trackerMetadata) {\n const [dynamicResults, _meta] = await Promise.all([\n client.multicall({\n contracts: [\n {\n address: trackerMetadata.address,\n abi: collateralTrackerV2Abi,\n functionName: 'getPoolData',\n },\n {\n address: trackerMetadata.address,\n abi: collateralTrackerV2Abi,\n functionName: 'totalSupply',\n },\n {\n address: trackerMetadata.address,\n abi: collateralTrackerV2Abi,\n functionName: 'interestRate',\n },\n ],\n blockNumber: targetBlockNumber,\n allowFailure: false,\n }),\n params._meta ?? getBlockMeta({ client, blockNumber: targetBlockNumber }),\n ])\n\n const [poolData, totalShares, interestRate] = dynamicResults\n const [depositedAssets, insideAMM, creditedShares, utilization] = poolData\n const totalAssets = depositedAssets + insideAMM\n\n const borrowRate = BigInt(interestRate) * SECONDS_PER_YEAR\n const supplyRate = (borrowRate * utilization) / 10000n\n\n return {\n address: trackerMetadata.address,\n token: trackerMetadata.assetAddress,\n symbol: trackerMetadata.symbol,\n decimals: trackerMetadata.decimals,\n totalAssets,\n insideAMM,\n creditedShares,\n totalShares,\n utilization,\n borrowRate,\n supplyRate,\n _meta,\n }\n }\n\n // Without metadata, fetch everything (original structure for backwards compatibility)\n // 1. Get tracker address (static)\n const collateralTrackerAddress = await client.readContract({\n address: poolAddress,\n abi: panopticPoolV2Abi,\n functionName: tokenIndex === 0 ? 'collateralToken0' : 'collateralToken1',\n })\n\n // 2. Get asset + dynamic data in one multicall (same-block guarantee for dynamic data)\n const [trackerData, _meta] = await Promise.all([\n client.multicall({\n contracts: [\n {\n address: collateralTrackerAddress,\n abi: collateralTrackerV2Abi,\n functionName: 'asset',\n },\n {\n address: collateralTrackerAddress,\n abi: collateralTrackerV2Abi,\n functionName: 'getPoolData',\n },\n {\n address: collateralTrackerAddress,\n abi: collateralTrackerV2Abi,\n functionName: 'totalSupply',\n },\n {\n address: collateralTrackerAddress,\n abi: collateralTrackerV2Abi,\n functionName: 'interestRate',\n },\n ],\n blockNumber: targetBlockNumber,\n allowFailure: false,\n }),\n params._meta ?? getBlockMeta({ client, blockNumber: targetBlockNumber }),\n ])\n\n const [assetAddress, poolData, totalShares, interestRate] = trackerData\n\n // 3. Get token metadata (static - can be cached)\n const [symbol, decimals] = await client.multicall({\n contracts: [\n {\n address: assetAddress,\n abi: erc20Abi,\n functionName: 'symbol',\n },\n {\n address: assetAddress,\n abi: erc20Abi,\n functionName: 'decimals',\n },\n ],\n allowFailure: false,\n })\n\n // poolData returns: (depositedAssets, insideAMM, creditedShares, currentPoolUtilization)\n const [depositedAssets, insideAMM, creditedShares, utilization] = poolData\n const totalAssets = depositedAssets + insideAMM\n\n // Annualize rates: interestRate() returns WAD/s\n const borrowRate = BigInt(interestRate) * SECONDS_PER_YEAR\n const supplyRate = (borrowRate * utilization) / 10000n\n\n return {\n address: collateralTrackerAddress,\n token: assetAddress,\n symbol,\n decimals: BigInt(decimals),\n totalAssets,\n insideAMM,\n creditedShares,\n totalShares,\n utilization,\n borrowRate,\n supplyRate,\n _meta,\n }\n}\n\n/**\n * Collateral tracker addresses (immutable, can be cached).\n */\nexport interface CollateralAddresses {\n /** Collateral tracker 0 address */\n collateralToken0: Address\n /** Collateral tracker 1 address */\n collateralToken1: Address\n}\n\n/**\n * Parameters for getCurrentRates.\n */\nexport interface GetCurrentRatesParams {\n /** viem PublicClient */\n client: PublicClient\n /** PanopticPool address */\n poolAddress: Address\n /** Optional block number for historical queries */\n blockNumber?: bigint\n /** Optional pre-fetched collateral tracker addresses (for caching/optimization) */\n collateralAddresses?: CollateralAddresses\n /** Optional pre-fetched block metadata (skips getBlockMeta RPC call) */\n _meta?: BlockMeta\n}\n\n/**\n * Get current interest rates for both tokens.\n *\n * ## Same-Block Guarantee\n * All dynamic data is fetched in ONE multicall at the target block.\n * Collateral tracker addresses are either provided or fetched separately (static prefetch).\n *\n * @param params - The parameters\n * @returns Current rates with block metadata\n */\nexport async function getCurrentRates(params: GetCurrentRatesParams): Promise<CurrentRates> {\n const { client, poolAddress, blockNumber, collateralAddresses } = params\n\n const targetBlockNumber =\n blockNumber ?? params._meta?.blockNumber ?? (await client.getBlockNumber())\n\n // Get collateral tracker addresses (static prefetch if not provided)\n let collateralToken0: Address\n let collateralToken1: Address\n\n if (collateralAddresses) {\n collateralToken0 = collateralAddresses.collateralToken0\n collateralToken1 = collateralAddresses.collateralToken1\n } else {\n // Static prefetch - addresses are immutable\n const addressResults = await client.multicall({\n contracts: [\n {\n address: poolAddress,\n abi: panopticPoolV2Abi,\n functionName: 'collateralToken0',\n },\n {\n address: poolAddress,\n abi: panopticPoolV2Abi,\n functionName: 'collateralToken1',\n },\n ],\n allowFailure: false,\n })\n collateralToken0 = addressResults[0]\n collateralToken1 = addressResults[1]\n }\n\n // SINGLE multicall for ALL dynamic data - ensures same-block consistency\n const [rateData, _meta] = await Promise.all([\n client.multicall({\n contracts: [\n {\n address: collateralToken0,\n abi: collateralTrackerV2Abi,\n functionName: 'interestRate',\n },\n {\n address: collateralToken0,\n abi: collateralTrackerV2Abi,\n functionName: 'getPoolData',\n },\n {\n address: collateralToken1,\n abi: collateralTrackerV2Abi,\n functionName: 'interestRate',\n },\n {\n address: collateralToken1,\n abi: collateralTrackerV2Abi,\n functionName: 'getPoolData',\n },\n ],\n blockNumber: targetBlockNumber,\n allowFailure: false,\n }),\n params._meta ?? getBlockMeta({ client, blockNumber: targetBlockNumber }),\n ])\n\n const [interestRate0, poolData0, interestRate1, poolData1] = rateData\n\n // Extract utilization from pool data\n const utilization0 = poolData0[3]\n const utilization1 = poolData1[3]\n\n // Annualize rates: interestRate() returns WAD/s\n const borrowRate0 = BigInt(interestRate0) * SECONDS_PER_YEAR\n const borrowRate1 = BigInt(interestRate1) * SECONDS_PER_YEAR\n\n // Supply rate = borrow rate * utilization (utilization is in bps, so /10000)\n const supplyRate0 = (borrowRate0 * utilization0) / 10000n\n const supplyRate1 = (borrowRate1 * utilization1) / 10000n\n\n return {\n borrowRate0,\n supplyRate0,\n borrowRate1,\n supplyRate1,\n _meta,\n }\n}\n\n// ─── Interest State (per-user borrows) ───────────────────────────────────────\n\n/**\n * Per-user interest state for a single collateral tracker.\n */\nexport interface TokenInterestState {\n /** User's borrow index snapshot (int128) */\n userBorrowIndex: bigint\n /** User's net borrows: positive = borrowing, negative = net supplying (int128) */\n netBorrows: bigint\n}\n\n/**\n * Interest state for both tokens in a Panoptic pool.\n */\nexport interface InterestState {\n /** Token 0 interest state */\n token0: TokenInterestState\n /** Token 1 interest state */\n token1: TokenInterestState\n /** Block metadata */\n _meta: BlockMeta\n}\n\n/**\n * Parameters for getInterestState.\n */\nexport interface GetInterestStateParams {\n /** viem PublicClient */\n client: PublicClient\n /** PanopticPool address */\n poolAddress: Address\n /** Account address to query */\n account: Address\n /** Optional block number for historical queries */\n blockNumber?: bigint\n /** Optional pre-fetched collateral tracker addresses */\n collateralAddresses?: CollateralAddresses\n /** Optional pre-fetched block metadata */\n _meta?: BlockMeta\n}\n\n/**\n * Get per-user interest state (borrow index + net borrows) for both tokens.\n *\n * Calls `collateralTracker.interestState(user)` on both trackers in a single multicall.\n *\n * @param params - The parameters\n * @returns Interest state for both tokens with block metadata\n */\nexport async function getInterestState(params: GetInterestStateParams): Promise<InterestState> {\n const { client, poolAddress, account, blockNumber, collateralAddresses } = params\n\n const targetBlockNumber =\n blockNumber ?? params._meta?.blockNumber ?? (await client.getBlockNumber())\n\n let collateralToken0: Address\n let collateralToken1: Address\n\n if (collateralAddresses) {\n collateralToken0 = collateralAddresses.collateralToken0\n collateralToken1 = collateralAddresses.collateralToken1\n } else {\n const addressResults = await client.multicall({\n contracts: [\n {\n address: poolAddress,\n abi: panopticPoolV2Abi,\n functionName: 'collateralToken0',\n },\n {\n address: poolAddress,\n abi: panopticPoolV2Abi,\n functionName: 'collateralToken1',\n },\n ],\n allowFailure: false,\n })\n collateralToken0 = addressResults[0]\n collateralToken1 = addressResults[1]\n }\n\n const [results, _meta] = await Promise.all([\n client.multicall({\n contracts: [\n {\n address: collateralToken0,\n abi: collateralTrackerV2Abi,\n functionName: 'interestState',\n args: [account],\n },\n {\n address: collateralToken1,\n abi: collateralTrackerV2Abi,\n functionName: 'interestState',\n args: [account],\n },\n ],\n blockNumber: targetBlockNumber,\n allowFailure: false,\n }),\n params._meta ?? getBlockMeta({ client, blockNumber: targetBlockNumber }),\n ])\n\n const [state0, state1] = results\n\n return {\n token0: { userBorrowIndex: state0[0], netBorrows: state0[1] },\n token1: { userBorrowIndex: state1[0], netBorrows: state1[1] },\n _meta,\n }\n}\n","/**\n * Token amount formatters and parsers.\n *\n * All formatters require explicit precision - no hidden defaults.\n *\n * @module v2/formatters/amount\n */\n\nimport type { TokenFlow } from '../types'\n\n/**\n * Format a raw token amount to a human-readable string.\n *\n * @param amount - The amount in smallest units (e.g., wei)\n * @param decimals - Token decimals (e.g., 18n for WETH, 6n for USDC)\n * @param precision - Number of decimal places to display\n * @returns Formatted string\n *\n * @example\n * ```typescript\n * formatTokenAmount(1500000000000000000n, 18n, 4n) // \"1.5000\"\n * formatTokenAmount(1500000000000000000n, 18n, 2n) // \"1.50\"\n * formatTokenAmount(1500000n, 6n, 2n) // \"1.50\" (USDC)\n * formatTokenAmount(-500000000000000000n, 18n, 4n) // \"-0.5000\"\n * ```\n */\nexport function formatTokenAmount(amount: bigint, decimals: bigint, precision: bigint): string {\n const isNegative = amount < 0n\n const absAmount = isNegative ? -amount : amount\n const divisor = 10n ** decimals\n const integerPart = absAmount / divisor\n const fractionalPart = absAmount % divisor\n\n // Build fractional string with proper padding\n const fullFractionalStr = fractionalPart.toString().padStart(Number(decimals), '0')\n const truncatedFractionalStr = fullFractionalStr.slice(0, Number(precision))\n const paddedFractionalStr = truncatedFractionalStr.padEnd(Number(precision), '0')\n\n const sign = isNegative ? '-' : ''\n return precision > 0n ? `${sign}${integerPart}.${paddedFractionalStr}` : `${sign}${integerPart}`\n}\n\n/**\n * Format a token amount with a sign prefix (+/-) for non-zero values.\n * Useful for displaying PnL, deltas, or changes.\n *\n * @param amount - The amount in smallest units\n * @param decimals - Token decimals\n * @param precision - Number of decimal places to display\n * @returns Formatted string with sign prefix\n *\n * @example\n * ```typescript\n * formatTokenAmountSigned(1500000000000000000n, 18n, 4n) // \"+1.5000\"\n * formatTokenAmountSigned(-500000000000000000n, 18n, 4n) // \"-0.5000\"\n * formatTokenAmountSigned(0n, 18n, 4n) // \"0.0000\"\n * ```\n */\nexport function formatTokenAmountSigned(\n amount: bigint,\n decimals: bigint,\n precision: bigint,\n): string {\n const formatted = formatTokenAmount(amount, decimals, precision)\n if (amount > 0n) {\n return `+${formatted}`\n }\n return formatted\n}\n\n/**\n * Parse a human-readable token amount string to raw units.\n *\n * @param amount - Human-readable amount string (e.g., \"1.5\")\n * @param decimals - Token decimals\n * @returns Amount in smallest units\n *\n * @example\n * ```typescript\n * parseTokenAmount(\"1.5\", 18n) // 1500000000000000000n\n * parseTokenAmount(\"1.5\", 6n) // 1500000n (USDC)\n * parseTokenAmount(\"100\", 18n) // 100000000000000000000n\n * parseTokenAmount(\"-0.5\", 18n) // -500000000000000000n\n * ```\n */\nexport function parseTokenAmount(amount: string, decimals: bigint): bigint {\n const trimmed = amount.trim()\n const isNegative = trimmed.startsWith('-')\n const cleanAmount = isNegative ? trimmed.slice(1) : trimmed\n\n const [integerStr, fractionalStr = ''] = cleanAmount.split('.')\n const paddedFractional = fractionalStr.padEnd(Number(decimals), '0').slice(0, Number(decimals))\n\n const integerPart = BigInt(integerStr || '0') * 10n ** decimals\n const fractionalPart = BigInt(paddedFractional || '0')\n\n const result = integerPart + fractionalPart\n return isNegative ? -result : result\n}\n\n/**\n * Format a token delta amount with a sign prefix (+/-) for non-zero values.\n * Alias for formatTokenAmountSigned, useful for clarity at call sites.\n *\n * @param amount - The delta amount in smallest units\n * @param decimals - Token decimals\n * @param precision - Number of decimal places to display\n * @returns Formatted string with sign prefix\n */\nexport function formatTokenDelta(amount: bigint, decimals: bigint, precision: bigint): string {\n return formatTokenAmountSigned(amount, decimals, precision)\n}\n\n/**\n * Format token flow deltas and balances from simulation results.\n *\n * @param flow - Token flow data\n * @param decimals0 - Token0 decimals\n * @param decimals1 - Token1 decimals\n * @param precision0 - Precision for token0 formatting\n * @param precision1 - Precision for token1 formatting\n * @returns Formatted token flow strings\n */\nexport function formatTokenFlow(\n flow: TokenFlow,\n decimals0: bigint,\n decimals1: bigint,\n precision0: bigint,\n precision1: bigint,\n): {\n delta0: string\n delta1: string\n balanceBefore0: string\n balanceBefore1: string\n balanceAfter0: string\n balanceAfter1: string\n} {\n return {\n delta0: formatTokenAmountSigned(flow.delta0, decimals0, precision0),\n delta1: formatTokenAmountSigned(flow.delta1, decimals1, precision1),\n balanceBefore0: formatTokenAmount(flow.balanceBefore0, decimals0, precision0),\n balanceBefore1: formatTokenAmount(flow.balanceBefore1, decimals1, precision1),\n balanceAfter0: formatTokenAmount(flow.balanceAfter0, decimals0, precision0),\n balanceAfter1: formatTokenAmount(flow.balanceAfter1, decimals1, precision1),\n }\n}\n","/**\n * WAD-scaled value formatters.\n *\n * WAD is a fixed-point representation where 1e18 = 1.0.\n * Used extensively in DeFi for representing ratios, prices, and multipliers.\n *\n * @module v2/formatters/wad\n */\n\nimport { formatTokenAmount } from './amount'\n\n/**\n * Format a WAD-scaled value (1e18 = 1.0).\n *\n * @param wad - WAD-scaled value\n * @param precision - Number of decimal places to display\n * @returns Formatted string\n *\n * @example\n * ```typescript\n * formatWad(1220000000000000000n, 2n) // \"1.22\"\n * formatWad(1220000000000000000n, 4n) // \"1.2200\"\n * formatWad(1000000000000000000n, 2n) // \"1.00\"\n * formatWad(500000000000000000n, 2n) // \"0.50\"\n * ```\n */\nexport function formatWad(wad: bigint, precision: bigint): string {\n return formatTokenAmount(wad, 18n, precision)\n}\n\n/**\n * Format a WAD-scaled value with sign prefix (+/-) for non-zero values.\n *\n * @param wad - WAD-scaled value\n * @param precision - Number of decimal places to display\n * @returns Formatted string with sign prefix\n *\n * @example\n * ```typescript\n * formatWadSigned(1220000000000000000n, 2n) // \"+1.22\"\n * formatWadSigned(-500000000000000000n, 2n) // \"-0.50\"\n * formatWadSigned(0n, 2n) // \"0.00\"\n * ```\n */\nexport function formatWadSigned(wad: bigint, precision: bigint): string {\n const formatted = formatWad(wad, precision)\n if (wad > 0n) {\n return `+${formatted}`\n }\n return formatted\n}\n\n/**\n * Format a WAD-scaled value as a percentage string.\n *\n * @param wad - WAD-scaled value\n * @param precision - Number of decimal places to display\n * @returns Formatted percentage string\n *\n * @example\n * ```typescript\n * formatWadPercent(50000000000000000n, 2n) // \"5.00%\"\n * formatWadPercent(1000000000000000000n, 1n) // \"100.0%\"\n * ```\n */\nexport function formatWadPercent(wad: bigint, precision: bigint): string {\n return `${formatTokenAmount(wad * 100n, 18n, precision)}%`\n}\n\n/**\n * Format an annualized rate stored as a WAD-scaled value.\n * Alias for formatWadPercent.\n *\n * @param rateWad - Rate in WAD (1e18 = 1.0)\n * @param precision - Number of decimal places to display\n * @returns Formatted percentage string\n */\nexport function formatRateWad(rateWad: bigint, precision: bigint): string {\n return formatWadPercent(rateWad, precision)\n}\n\n/**\n * Parse a decimal string to a WAD-scaled value.\n *\n * @param value - Decimal string (e.g., \"1.5\")\n * @returns WAD-scaled bigint\n *\n * @example\n * ```typescript\n * parseWad(\"1.5\") // 1500000000000000000n\n * parseWad(\"0.5\") // 500000000000000000n\n * parseWad(\"100\") // 100000000000000000000n\n * parseWad(\"-1.22\") // -1220000000000000000n\n * ```\n */\nexport function parseWad(value: string): bigint {\n const trimmed = value.trim()\n const isNegative = trimmed.startsWith('-')\n const cleanValue = isNegative ? trimmed.slice(1) : trimmed\n\n const [integerStr, fractionalStr = ''] = cleanValue.split('.')\n const paddedFractional = fractionalStr.padEnd(18, '0').slice(0, 18)\n\n const integerPart = BigInt(integerStr || '0') * 10n ** 18n\n const fractionalPart = BigInt(paddedFractional || '0')\n\n const result = integerPart + fractionalPart\n return isNegative ? -result : result\n}\n","/**\n * Per-second rate helpers.\n *\n * Collateral tracker rates are returned as WAD-scaled per-second rates.\n * These helpers annualize them for display.\n *\n * @module v2/formatters/rates\n */\n\nimport { formatWadPercent } from './wad'\n\nconst SECONDS_PER_DAY = 86_400n\nconst DAYS_PER_YEAR = 365n\nconst SECONDS_PER_YEAR = SECONDS_PER_DAY * DAYS_PER_YEAR\n\n/**\n * Annualize a per-second WAD-scaled rate to annual WAD.\n *\n * @param ratePerSecondWad - Rate in WAD per second\n * @returns Annualized rate in WAD\n */\nexport function annualizePerSecondRateWad(ratePerSecondWad: bigint): bigint {\n return ratePerSecondWad * SECONDS_PER_YEAR\n}\n\n/**\n * Format a per-second WAD rate as APY percentage text.\n * Uses linear annualization, then formats as WAD percent.\n *\n * @param ratePerSecondWad - Rate in WAD per second\n * @param precision - Decimal places\n * @returns Percentage string, e.g. \"2.41%\"\n */\nexport function formatPerSecondRateWadAsApyPct(\n ratePerSecondWad: bigint,\n precision: bigint,\n): string {\n return formatWadPercent(annualizePerSecondRateWad(ratePerSecondWad), precision)\n}\n\n/**\n * Format a per-second WAD rate as APR percentage text.\n * For this rate model, APR presentation uses the same annualized output.\n *\n * @param ratePerSecondWad - Rate in WAD per second\n * @param precision - Decimal places\n * @returns Percentage string, e.g. \"2.41%\"\n */\nexport function formatPerSecondRateWadAsAprPct(\n ratePerSecondWad: bigint,\n precision: bigint,\n): string {\n return formatWadPercent(annualizePerSecondRateWad(ratePerSecondWad), precision)\n}\n","/**\n * Interest rate model (IRM) reads for Panoptic v2.\n * @module v2/reads/irm\n */\n\nimport type { Address, PublicClient } from 'viem'\n\nimport { collateralTrackerV2Abi, riskEngineAbi } from '../../../generated'\nimport { PanopticValidationError } from '../errors/sdk'\nimport type { IrmCurrent, IrmMarketStateInputs, IrmPoint } from '../types/irm'\nexport type { IrmCurrent, IrmMarketStateInputs, IrmPoint } from '../types/irm'\n\nexport const WAD = 10n ** 18n\nexport const BPS_SCALE = 10_000n\nexport const SECONDS_PER_YEAR = 31_536_000n\nexport const MARKET_EPOCH_SHIFT = 2n\nexport const BORROW_INDEX_BITS = 80n\nexport const MARKET_EPOCH_BITS = 32n\nexport const RATE_AT_TARGET_BITS = 38n\nexport const UNREALIZED_INTEREST_BITS = 106n\n\nconst BORROW_INDEX_SHIFT = 0n\nconst MARKET_EPOCH_FIELD_SHIFT = BORROW_INDEX_BITS\nconst RATE_AT_TARGET_FIELD_SHIFT = BORROW_INDEX_BITS + MARKET_EPOCH_BITS\nconst UNREALIZED_INTEREST_FIELD_SHIFT = RATE_AT_TARGET_FIELD_SHIFT + RATE_AT_TARGET_BITS\nconst MAX_IRM_CURVE_POINTS = 500\n\nconst clampUtilizationBps = (utilizationBps: bigint): bigint => {\n if (utilizationBps < 0n) {\n return 0n\n }\n if (utilizationBps > BPS_SCALE) {\n return BPS_SCALE\n }\n return utilizationBps\n}\n\nconst getMaxValue = (bits: bigint): bigint => (1n << bits) - 1n\n\nconst assertFitsBits = (value: bigint, bits: bigint, fieldName: string): void => {\n if (value < 0n) {\n throw new PanopticValidationError(`${fieldName} must be >= 0`)\n }\n if (value > getMaxValue(bits)) {\n throw new PanopticValidationError(`${fieldName} exceeds ${bits.toString()} bits`)\n }\n}\n\nexport function packMarketState(inputs: IrmMarketStateInputs): bigint {\n const { borrowIndex, lastInteractionTimestamp, rateAtTarget, unrealizedGlobalInterest } = inputs\n const marketEpoch = lastInteractionTimestamp >> MARKET_EPOCH_SHIFT\n\n assertFitsBits(borrowIndex, BORROW_INDEX_BITS, 'borrowIndex')\n assertFitsBits(marketEpoch, MARKET_EPOCH_BITS, 'marketEpoch')\n assertFitsBits(rateAtTarget, RATE_AT_TARGET_BITS, 'rateAtTarget')\n assertFitsBits(unrealizedGlobalInterest, UNREALIZED_INTEREST_BITS, 'unrealizedGlobalInterest')\n\n return (\n (borrowIndex << BORROW_INDEX_SHIFT) +\n (marketEpoch << MARKET_EPOCH_FIELD_SHIFT) +\n (rateAtTarget << RATE_AT_TARGET_FIELD_SHIFT) +\n (unrealizedGlobalInterest << UNREALIZED_INTEREST_FIELD_SHIFT)\n )\n}\n\nexport function utilizationPctToWad(utilizationPct: number): bigint {\n if (!Number.isFinite(utilizationPct)) {\n throw new PanopticValidationError('utilizationPct must be finite')\n }\n if (utilizationPct < 0 || utilizationPct > 100) {\n throw new PanopticValidationError('utilizationPct must be between 0 and 100')\n }\n\n const scaledPct = Math.round(utilizationPct * 1_000_000)\n return (BigInt(scaledPct) * WAD) / 100_000_000n\n}\n\nexport function utilizationBpsToWad(utilizationBps: bigint): bigint {\n return (clampUtilizationBps(utilizationBps) * WAD) / BPS_SCALE\n}\n\nexport function ratePerSecWadToAprPct(ratePerSecWad: bigint): number {\n return (Number(ratePerSecWad) * Number(SECONDS_PER_YEAR) * 100) / Number(WAD)\n}\n\nexport function deriveSupplyRatePerSecWad(\n borrowRatePerSecWad: bigint,\n utilizationWad: bigint,\n): bigint {\n return (borrowRatePerSecWad * utilizationWad) / WAD\n}\n\nexport async function getIrmCurrent(params: {\n client: PublicClient\n collateralTrackerAddress: Address\n blockNumber?: bigint\n}): Promise<IrmCurrent> {\n const { client, collateralTrackerAddress, blockNumber } = params\n const [\n borrowIndex,\n lastInteractionTimestamp,\n rateAtTarget,\n unrealizedGlobalInterest,\n poolData,\n riskEngineAddress,\n ] = await client.multicall({\n contracts: [\n {\n address: collateralTrackerAddress,\n abi: collateralTrackerV2Abi,\n functionName: 'borrowIndex',\n },\n {\n address: collateralTrackerAddress,\n abi: collateralTrackerV2Abi,\n functionName: 'lastInteractionTimestamp',\n },\n {\n address: collateralTrackerAddress,\n abi: collateralTrackerV2Abi,\n functionName: 'rateAtTarget',\n },\n {\n address: collateralTrackerAddress,\n abi: collateralTrackerV2Abi,\n functionName: 'unrealizedGlobalInterest',\n },\n {\n address: collateralTrackerAddress,\n abi: collateralTrackerV2Abi,\n functionName: 'getPoolData',\n },\n {\n address: collateralTrackerAddress,\n abi: collateralTrackerV2Abi,\n functionName: 'riskEngine',\n },\n ],\n blockNumber,\n allowFailure: false,\n })\n\n const currentUtilizationBps = clampUtilizationBps(poolData[3])\n const currentUtilizationWad = utilizationBpsToWad(currentUtilizationBps)\n const currentUtilizationPct = Number(currentUtilizationBps) / 100\n\n const marketStatePacked = packMarketState({\n borrowIndex,\n lastInteractionTimestamp,\n rateAtTarget,\n unrealizedGlobalInterest,\n })\n\n const borrowRatePerSecWad = await client.readContract({\n address: riskEngineAddress,\n abi: riskEngineAbi,\n functionName: 'interestRate',\n args: [currentUtilizationWad, marketStatePacked],\n blockNumber,\n })\n\n const supplyRatePerSecWad = deriveSupplyRatePerSecWad(borrowRatePerSecWad, currentUtilizationWad)\n\n return {\n collateralTrackerAddress,\n riskEngineAddress,\n currentUtilizationBps,\n currentUtilizationWad,\n currentUtilizationPct,\n borrowRatePerSecWad,\n supplyRatePerSecWad,\n borrowAprPct: ratePerSecWadToAprPct(borrowRatePerSecWad),\n supplyAprPct: ratePerSecWadToAprPct(supplyRatePerSecWad),\n marketStatePacked,\n }\n}\n\nexport async function getIrmCurve(params: {\n client: PublicClient\n collateralTrackerAddress: Address\n points?: number\n blockNumber?: bigint\n}): Promise<{\n current: IrmCurrent\n points: IrmPoint[]\n}> {\n const { client, collateralTrackerAddress, points = 201, blockNumber } = params\n\n if (!Number.isInteger(points) || points < 2) {\n throw new PanopticValidationError('points must be an integer >= 2')\n }\n if (points > MAX_IRM_CURVE_POINTS) {\n throw new PanopticValidationError(`points must be <= ${MAX_IRM_CURVE_POINTS}`)\n }\n\n const current = await getIrmCurrent({\n client,\n collateralTrackerAddress,\n blockNumber,\n })\n\n const denominator = BigInt(points - 1)\n const contracts = Array.from({ length: points }, (_, idx) => {\n const i = BigInt(idx)\n const utilizationWad = (i * WAD) / denominator\n\n return {\n address: current.riskEngineAddress,\n abi: riskEngineAbi,\n functionName: 'interestRate' as const,\n args: [utilizationWad, current.marketStatePacked] as const,\n }\n })\n\n const borrowRatesPerSecWad = await client.multicall({\n contracts,\n blockNumber,\n allowFailure: false,\n })\n\n const curvePoints: IrmPoint[] = borrowRatesPerSecWad.map((borrowRatePerSecWad, idx) => {\n const i = BigInt(idx)\n const utilizationWad = (i * WAD) / denominator\n const supplyRatePerSecWad = deriveSupplyRatePerSecWad(borrowRatePerSecWad, utilizationWad)\n\n return {\n utilizationWad,\n utilizationPct: (idx * 100) / (points - 1),\n borrowRatePerSecWad,\n supplyRatePerSecWad,\n borrowAprPct: ratePerSecWadToAprPct(borrowRatePerSecWad),\n supplyAprPct: ratePerSecWadToAprPct(supplyRatePerSecWad),\n }\n })\n\n return {\n current,\n points: curvePoints,\n }\n}\n"],"mappings":";;;;;AAAA,MAAa,gBAAgB;CAC3B;EACE,QAAQ,CACN;GACE,YAAY,CACV;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP,GACD;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP,CACF;GACD,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,MAAM;EACN,SAAS,CACP;GACE,cAAc;GACd,MAAM;GACN,MAAM;EACP,GACD;GACE,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,iBAAiB;EACjB,MAAM;CACP;CACD;EACE,QAAQ,CACN;GACE,YAAY;IACV;KACE,cAAc;KACd,MAAM;KACN,MAAM;IACP;IACD;KACE,cAAc;KACd,MAAM;KACN,MAAM;IACP;IACD;KACE,cAAc;KACd,MAAM;KACN,MAAM;IACP;GACF;GACD,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,MAAM;EACN,SAAS,CACP;GACE,YAAY,CACV;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP,GACD;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP,CACF;GACD,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,iBAAiB;EACjB,MAAM;CACP;CACD;EACE,QAAQ,CACN;GACE,YAAY;IACV;KACE,cAAc;KACd,MAAM;KACN,MAAM;IACP;IACD;KACE,cAAc;KACd,MAAM;KACN,MAAM;IACP;IACD;KACE,cAAc;KACd,MAAM;KACN,MAAM;IACP;IACD;KACE,cAAc;KACd,MAAM;KACN,MAAM;IACP;GACF;GACD,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,MAAM;EACN,SAAS,CACP;GACE,YAAY,CACV;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP,GACD;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP,CACF;GACD,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,iBAAiB;EACjB,MAAM;CACP;CACD;EACE,QAAQ,CACN;GACE,YAAY,CACV;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP,GACD;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP,CACF;GACD,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,MAAM;EACN,SAAS;GACP;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP;GACD;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP;GACD;IACE,YAAY,CACV;KACE,cAAc;KACd,MAAM;KACN,MAAM;IACP,GACD;KACE,cAAc;KACd,MAAM;KACN,MAAM;IACP,CACF;IACD,cAAc;IACd,MAAM;IACN,MAAM;GACP;EACF;EACD,iBAAiB;EACjB,MAAM;CACP;CACD;EACE,QAAQ,CAAE;EACV,MAAM;EACN,SAAS,CACP;GACE,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,iBAAiB;EACjB,MAAM;CACP;CACD;EACE,QAAQ,CACN;GACE,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,MAAM;EACN,SAAS,CACP;GACE,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,iBAAiB;EACjB,MAAM;CACP;CACD;EACE,QAAQ,CAAE;EACV,MAAM;EACN,SAAS,CACP;GACE,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,iBAAiB;EACjB,MAAM;CACP;CACD;EACE,QAAQ,CAAE;EACV,MAAM;EACN,SAAS,CACP;GACE,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,iBAAiB;EACjB,MAAM;CACP;CACD;EACE,QAAQ,CAAE;EACV,MAAM;EACN,SAAS,CACP;GACE,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,iBAAiB;EACjB,MAAM;CACP;CACD;EACE,QAAQ,CAAE;EACV,MAAM;EACN,SAAS,CACP;GACE,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,iBAAiB;EACjB,MAAM;CACP;CACD;EACE,QAAQ,CAAE;EACV,MAAM;EACN,SAAS,CACP;GACE,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,iBAAiB;EACjB,MAAM;CACP;CACD;EACE,QAAQ,CAAE;EACV,MAAM;EACN,SAAS,CACP;GACE,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,iBAAiB;EACjB,MAAM;CACP;CACD;EACE,QAAQ,CACN;GACE,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,MAAM;EACN,SAAS,CACP;GACE,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,iBAAiB;EACjB,MAAM;CACP;CACD;EACE,QAAQ,CAAE;EACV,MAAM;EACN,SAAS,CACP;GACE,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,iBAAiB;EACjB,MAAM;CACP;CACD;EACE,QAAQ,CACN;GACE,cAAc;GACd,MAAM;GACN,MAAM;EACP,GACD;GACE,YAAY,CACV;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP,GACD;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP,CACF;GACD,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,MAAM;EACN,SAAS,CACP;GACE,YAAY,CACV;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP,GACD;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP,CACF;GACD,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,iBAAiB;EACjB,MAAM;CACP;CACD;EACE,QAAQ,CACN;GACE,cAAc;GACd,MAAM;GACN,MAAM;EACP,GACD;GACE,YAAY,CACV;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP,GACD;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP,CACF;GACD,cAAc;GACd,MAAM;GACN,MAAM;EACP,CACF;EACD,MAAM;EACN,SAAS;GACP;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP;GACD;IACE,cAAc;IACd,MAAM;IACN,MAAM;GACP;GACD;IACE,YAAY,CACV;KACE,cAAc;KACd,MAAM;KACN,MAAM;IACP,GACD;KACE,cAAc;KACd,MAAM;KACN,MAAM;IACP,CACF;IACD,cAAc;IACd,MAAM;IACN,MAAM;GACP;EACF;EACD,iBAAiB;EACjB,MAAM;CACP;AACF;;;;;;;;;ACjbD,MAAa,mBAAmB;CAC9B;EACE,MAAM;EACN,QAAQ,CACN;GACE,MAAM;GACN,MAAM;GACN,cAAc;EACf,CACF;EACD,iBAAiB;CAClB;CACD;EACE,MAAM;EACN,MAAM;EACN,QAAQ;GACN;IAAE,M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AO,UAAU,OAAO,IAAI,SAAS,EACxC,OAAM,IAAI,wBAAwB;AAEpC,KAAI,SAAS,qBACX,OAAM,IAAI,yBAAyB,oBAAoB,qBAAqB;CAG9E,MAAM,UAAU,MAAM,cAAc;EAClC;EACA;EACA;CACD,EAAC;CAEF,MAAM,cAAc,OAAO,SAAS,EAAE;CACtC,MAAM,YAAY,MAAM,KAAK,EAAE,QAAQ,OAAQ,GAAE,CAAC,GAAG,QAAQ;EAC3D,MAAM,IAAI,OAAO,IAAI;EACrB,MAAM,iBAAkB,IAAI,MAAO;AAEnC,SAAO;GACL,SAAS,QAAQ;GACjB,KAAK;GACL,cAAc;GACd,MAAM,CAAC,gBAAgB,QAAQ,iBAAkB;EAClD;CACF,EAAC;CAEF,MAAM,uBAAuB,MAAM,OAAO,UAAU;EAClD;EACA;EACA,cAAc;CACf,EAAC;CAEF,MAAMC,cAA0B,qBAAqB,IAAI,CAAC,qBAAqB,QAAQ;EACrF,MAAM,IAAI,OAAO,IAAI;EACrB,MAAM,iBAAkB,IAAI,MAAO;EACnC,MAAM,sBAAsB,0BAA0B,qBAAqB,eAAe;AAE1F,SAAO;GACL;GACA,gBAAiB,MAAM,OAAQ,SAAS;GACxC;GACA;GACA,cAAc,sBAAsB,oBAAoB;GACxD,cAAc,sBAAsB,oBAAoB;EACzD;CACF,EAAC;AAEF,QAAO;EACL;EACA,QAAQ;CACT;AACF"}
|
package/dist/irm-zWjtffWA.d.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { IrmCurrent, IrmMarketStateInputs, IrmPoint } from "./irm-CGykVo3q.js";
|
|
2
|
-
import { Address, PublicClient } from "viem";
|
|
3
|
-
|
|
4
|
-
//#region src/panoptic/v2/formatters/rates.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Per-second rate helpers.
|
|
7
|
-
*
|
|
8
|
-
* Collateral tracker rates are returned as WAD-scaled per-second rates.
|
|
9
|
-
* These helpers annualize them for display.
|
|
10
|
-
*
|
|
11
|
-
* @module v2/formatters/rates
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Annualize a per-second WAD-scaled rate to annual WAD.
|
|
15
|
-
*
|
|
16
|
-
* @param ratePerSecondWad - Rate in WAD per second
|
|
17
|
-
* @returns Annualized rate in WAD
|
|
18
|
-
*/
|
|
19
|
-
/**
|
|
20
|
-
* Per-second rate helpers.
|
|
21
|
-
*
|
|
22
|
-
* Collateral tracker rates are returned as WAD-scaled per-second rates.
|
|
23
|
-
* These helpers annualize them for display.
|
|
24
|
-
*
|
|
25
|
-
* @module v2/formatters/rates
|
|
26
|
-
*/
|
|
27
|
-
/**
|
|
28
|
-
* Annualize a per-second WAD-scaled rate to annual WAD.
|
|
29
|
-
*
|
|
30
|
-
* @param ratePerSecondWad - Rate in WAD per second
|
|
31
|
-
* @returns Annualized rate in WAD
|
|
32
|
-
*/
|
|
33
|
-
declare function annualizePerSecondRateWad(ratePerSecondWad: bigint): bigint;
|
|
34
|
-
/**
|
|
35
|
-
* Format a per-second WAD rate as APY percentage text.
|
|
36
|
-
* Uses linear annualization, then formats as WAD percent.
|
|
37
|
-
*
|
|
38
|
-
* @param ratePerSecondWad - Rate in WAD per second
|
|
39
|
-
* @param precision - Decimal places
|
|
40
|
-
* @returns Percentage string, e.g. "2.41%"
|
|
41
|
-
*/
|
|
42
|
-
declare function formatPerSecondRateWadAsApyPct(ratePerSecondWad: bigint, precision: bigint): string;
|
|
43
|
-
/**
|
|
44
|
-
* Format a per-second WAD rate as APR percentage text.
|
|
45
|
-
* For this rate model, APR presentation uses the same annualized output.
|
|
46
|
-
*
|
|
47
|
-
* @param ratePerSecondWad - Rate in WAD per second
|
|
48
|
-
* @param precision - Decimal places
|
|
49
|
-
* @returns Percentage string, e.g. "2.41%"
|
|
50
|
-
*/
|
|
51
|
-
declare function formatPerSecondRateWadAsAprPct(ratePerSecondWad: bigint, precision: bigint): string;
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/panoptic/v2/reads/irm.d.ts
|
|
55
|
-
declare const WAD: bigint;
|
|
56
|
-
declare const BPS_SCALE = 10000n;
|
|
57
|
-
declare const SECONDS_PER_YEAR = 31536000n;
|
|
58
|
-
declare const MARKET_EPOCH_SHIFT = 2n;
|
|
59
|
-
declare const BORROW_INDEX_BITS = 80n;
|
|
60
|
-
declare const MARKET_EPOCH_BITS = 32n;
|
|
61
|
-
declare const RATE_AT_TARGET_BITS = 38n;
|
|
62
|
-
declare const UNREALIZED_INTEREST_BITS = 106n;
|
|
63
|
-
declare function packMarketState(inputs: IrmMarketStateInputs): bigint;
|
|
64
|
-
declare function utilizationPctToWad(utilizationPct: number): bigint;
|
|
65
|
-
declare function utilizationBpsToWad(utilizationBps: bigint): bigint;
|
|
66
|
-
declare function ratePerSecWadToAprPct(ratePerSecWad: bigint): number;
|
|
67
|
-
declare function deriveSupplyRatePerSecWad(borrowRatePerSecWad: bigint, utilizationWad: bigint): bigint;
|
|
68
|
-
declare function getIrmCurrent(params: {
|
|
69
|
-
client: PublicClient;
|
|
70
|
-
collateralTrackerAddress: Address;
|
|
71
|
-
blockNumber?: bigint;
|
|
72
|
-
}): Promise<IrmCurrent>;
|
|
73
|
-
declare function getIrmCurve(params: {
|
|
74
|
-
client: PublicClient;
|
|
75
|
-
collateralTrackerAddress: Address;
|
|
76
|
-
points?: number;
|
|
77
|
-
blockNumber?: bigint;
|
|
78
|
-
}): Promise<{
|
|
79
|
-
current: IrmCurrent;
|
|
80
|
-
points: IrmPoint[];
|
|
81
|
-
}>;
|
|
82
|
-
|
|
83
|
-
//#endregion
|
|
84
|
-
export { BORROW_INDEX_BITS as BORROW_INDEX_BITS$1, BPS_SCALE as BPS_SCALE$1, MARKET_EPOCH_BITS as MARKET_EPOCH_BITS$1, MARKET_EPOCH_SHIFT as MARKET_EPOCH_SHIFT$1, RATE_AT_TARGET_BITS as RATE_AT_TARGET_BITS$1, SECONDS_PER_YEAR as SECONDS_PER_YEAR$1, UNREALIZED_INTEREST_BITS as UNREALIZED_INTEREST_BITS$1, WAD as WAD$2, annualizePerSecondRateWad as annualizePerSecondRateWad$1, deriveSupplyRatePerSecWad as deriveSupplyRatePerSecWad$1, formatPerSecondRateWadAsAprPct as formatPerSecondRateWadAsAprPct$1, formatPerSecondRateWadAsApyPct as formatPerSecondRateWadAsApyPct$1, getIrmCurrent as getIrmCurrent$1, getIrmCurve as getIrmCurve$1, packMarketState as packMarketState$1, ratePerSecWadToAprPct as ratePerSecWadToAprPct$1, utilizationBpsToWad as utilizationBpsToWad$1, utilizationPctToWad as utilizationPctToWad$1 };
|
|
85
|
-
//# sourceMappingURL=irm-zWjtffWA.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"irm-zWjtffWA.d.ts","names":["annualizePerSecondRateWad","formatPerSecondRateWadAsApyPct","formatPerSecondRateWadAsAprPct","Address","PublicClient","IrmCurrent","IrmMarketStateInputs","IrmPoint","WAD","BPS_SCALE","SECONDS_PER_YEAR","MARKET_EPOCH_SHIFT","BORROW_INDEX_BITS","MARKET_EPOCH_BITS","RATE_AT_TARGET_BITS","UNREALIZED_INTEREST_BITS","packMarketState","utilizationPctToWad","utilizationBpsToWad","ratePerSecWadToAprPct","deriveSupplyRatePerSecWad","getIrmCurrent","Promise","getIrmCurve"],"sources":["../src/panoptic/v2/formatters/rates.d.ts","../src/panoptic/v2/reads/irm.d.ts"],"sourcesContent":null,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAcwBA,yBAAAA;;;;AAAxB;;;;;iBASwBC,8BAAAA;;;;AAAxB;;;;;iBASwBC,8BAAAA;;;;cCzBHM;cACAC,SAAAA;cACAC,gBAAAA;cACAC,kBAAAA;cACAC,iBAAAA;cACAC,iBAAAA;cACAC,mBAAAA;cACAC,wBAAAA;iBACGC,eAAAA,SAAwBV;iBACxBW,mBAAAA;iBACAC,mBAAAA;ADHAlB,iBCIAmB,qBAAAA,CDJyB,aAAA,EAAA,MAAA,CAAA,EAAA,MAAA;iBCKzBC,yBAAAA;iBACAC,aAAAA;UACZjB;4BACkBD;;IAE1BmB,QAAQjB;iBACYkB,WAAAA;UACZnB;EDHYH,wBAAAA,ECIME,ODJwB;;;ICOlDmB;WACSjB;UACDE"}
|