@zkp2p/sdk 0.10.0 → 0.11.0-rc.0

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.
@@ -168,42 +168,6 @@ var IntentGuardianOperations = class {
168
168
  }
169
169
  };
170
170
 
171
- // src/takerTiers.ts
172
- var TAKER_TIER_SCHEDULE = [
173
- { tier: "PLATINUM", perIntentCapUsd: 5e3, minVolumeUsd: 1e5, maxVolumeUsd: Infinity },
174
- { tier: "PRO", perIntentCapUsd: 2500, minVolumeUsd: 5e4, maxVolumeUsd: 99999 },
175
- { tier: "PLUS", perIntentCapUsd: 1e3, minVolumeUsd: 1e4, maxVolumeUsd: 49999 },
176
- { tier: "PEER", perIntentCapUsd: 250, minVolumeUsd: 1e3, maxVolumeUsd: 9999 },
177
- { tier: "PEASANT", perIntentCapUsd: 100, minVolumeUsd: 0, maxVolumeUsd: 999 }
178
- ];
179
- var TAKER_TIER_ORDER = [
180
- "PEASANT",
181
- "PEER",
182
- "PLUS",
183
- "PRO",
184
- "PLATINUM"
185
- ];
186
- var TAKER_TIER_CAPS = Object.fromEntries(
187
- TAKER_TIER_SCHEDULE.map((entry) => [entry.tier, entry.perIntentCapUsd])
188
- );
189
- var TAKER_TIER_FEE_DISCOUNT_BPS = {
190
- PEASANT: 0,
191
- PEER: 5,
192
- PLUS: 10,
193
- PRO: 20,
194
- PLATINUM: 30
195
- };
196
- function getTakerTierFeeDiscountBps(tier) {
197
- if (!tier) return 0;
198
- return TAKER_TIER_FEE_DISCOUNT_BPS[tier] ?? 0;
199
- }
200
- function getNextTakerTier(currentTier) {
201
- if (!currentTier) return null;
202
- const index = TAKER_TIER_ORDER.indexOf(currentTier);
203
- if (index === -1 || index >= TAKER_TIER_ORDER.length - 1) return null;
204
- return TAKER_TIER_ORDER[index + 1];
205
- }
206
-
207
171
  // src/react/hooks/vaultUtils.ts
208
172
  var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
209
173
  var ZERO_RATE_MANAGER_ID = "0x0000000000000000000000000000000000000000000000000000000000000000";
@@ -276,6 +240,6 @@ var prepareSetDelegationTx = async (client, params, referrer) => {
276
240
  });
277
241
  };
278
242
 
279
- export { IntentGuardianOperations, TAKER_TIER_CAPS, TAKER_TIER_FEE_DISCOUNT_BPS, TAKER_TIER_ORDER, TAKER_TIER_SCHEDULE, ZERO_ADDRESS, ZERO_RATE_MANAGER_ID, asErrorMessage, assertAtomicDelegationSwitchSupport, assertDelegationMethodSupport, classifyDelegationState, classifyIntentGuardianError, getDelegationRoute, getNextTakerTier, getTakerTierFeeDiscountBps, isZeroRateManagerId, normalizeRateManagerId, normalizeRegistry, prepareClearDelegationTx, prepareSetDelegationTx };
280
- //# sourceMappingURL=chunk-WXEP544Y.mjs.map
281
- //# sourceMappingURL=chunk-WXEP544Y.mjs.map
243
+ export { IntentGuardianOperations, ZERO_ADDRESS, ZERO_RATE_MANAGER_ID, asErrorMessage, assertAtomicDelegationSwitchSupport, assertDelegationMethodSupport, classifyDelegationState, classifyIntentGuardianError, getDelegationRoute, isZeroRateManagerId, normalizeRateManagerId, normalizeRegistry, prepareClearDelegationTx, prepareSetDelegationTx };
244
+ //# sourceMappingURL=chunk-FCOH36IX.mjs.map
245
+ //# sourceMappingURL=chunk-FCOH36IX.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client/IntentGuardianOperations.ts","../src/react/hooks/vaultUtils.ts"],"names":[],"mappings":";AAqEA,IAAM,oBAAA,GAAgE;AAAA,EACpE,kBAAA,EAAoB,qBAAA;AAAA,EACpB,uBAAA,EAAyB,kBAAA;AAAA,EACzB,+BAAA,EAAiC,2BAAA;AAAA,EACjC,oBAAA,EAAsB,wBAAA;AAAA,EACtB,oBAAA,EAAsB,wBAAA;AAAA,EACtB,WAAA,EAAa;AACf,CAAA;AAOO,SAAS,4BAA4B,KAAA,EAAyC;AACnF,EAAA,MAAM,QAAA,GACJ,KAAA,YAAiB,KAAA,GACb,CAAA,EAAG,KAA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AA,CAAO,iBAAiB,OAAA,CAAQ;AAAA,IACrC,eAAe,MAAA,CAAO,MAAA;AAAA,IACtB,WAAW,MAAA,CAAO,SAAA;AAAA,IAClB,GAAI,WAAW,EAAE,WAAA,EAAa,EAAE,QAAA,EAAS,KAAM;AAAC,GACjD,CAAA;AACH;AAEO,IAAM,sBAAA,GAAyB,OAEpC,MAAA,EACA,MAAA,EAMA,QAAA,KACiC;AACjC,EAAA,MAAM,KAAA,GAAQ,kBAAA,CAAmB,MAAA,EAAQ,MAAA,CAAO,MAAM,CAAA;AACtD,EAAA,6BAAA,CAA8B,MAAA,EAAQ,OAAO,KAAK,CAAA;AAClD,EAAA,OAAO,MAAA,CAAO,eAAe,OAAA,CAAQ;AAAA,IACnC,eAAe,MAAA,CAAO,MAAA;AAAA,IACtB,WAAW,MAAA,CAAO,SAAA;AAAA,IAClB,oBAAoB,MAAA,CAAO,QAAA;AAAA,IAC3B,eAAe,MAAA,CAAO,aAAA;AAAA,IACtB,GAAI,WAAW,EAAE,WAAA,EAAa,EAAE,QAAA,EAAS,KAAM;AAAC,GACjD,CAAA;AACH","file":"chunk-FCOH36IX.mjs","sourcesContent":["import type { Abi } from 'abitype';\nimport type { Address, Hex, PublicClient } from 'viem';\n\nimport type { TxOverrides } from '../types';\n\nexport type IntentGuardianWriteFunction = 'extendIntent';\n\ntype GuardianWriteBase = {\n txOverrides?: TxOverrides;\n};\n\nexport type IntentGuardianWriteParams = {\n extendIntent: GuardianWriteBase & {\n escrow: Address;\n depositId: bigint;\n intentHash: Hex;\n /** Additional lifetime in seconds. */\n additionalTime: bigint;\n /**\n * Payer-confirmed ceiling on cost. The contract reverts with\n * ExtensionCostExceedsMax rather than overcharging, which is what makes a\n * governance fee change between quote and execution safe.\n */\n maxCost: bigint;\n };\n};\n\n/**\n * Live guardian policy. Read immediately before quoting or signing — the fee is\n * owner-governed and may change at any time, so a cached value is only ever a\n * display hint, never a commitment.\n */\nexport type IntentGuardianPolicy = {\n guardian: Address;\n /** Zero means governance has disabled extensions entirely. */\n extensionFeeBpsPerHour: bigint;\n extensionsEnabled: boolean;\n maxExtensionFeeBpsPerHour: bigint;\n /** Escrow-enforced ceiling on total intent lifetime, in seconds. */\n maxTotalIntentLifetime: bigint;\n owner: Address;\n pendingOwner: Address;\n};\n\n/**\n * A quote is a point-in-time read. It is not a reservation: governance can move\n * the fee before the transaction lands, which is why `maxCost` is required.\n */\nexport type IntentGuardianQuote = {\n intentAmount: bigint;\n additionalTime: bigint;\n extensionFeeBpsPerHour: bigint;\n cost: bigint;\n quotedAt: number;\n};\n\n/**\n * Classified guardian failure. The raw contract error name is preserved in\n * `code` so diagnostics stay precise while the UI can branch on the class.\n */\nexport type IntentGuardianErrorCode =\n | 'EXTENSIONS_DISABLED'\n | 'COST_EXCEEDS_MAX'\n | 'FEE_EXCEEDS_INTENT_AMOUNT'\n | 'INTENT_ALREADY_EXPIRED'\n | 'ESCROW_NOT_WHITELISTED'\n | 'ZERO_ADDRESS'\n | 'UNKNOWN';\n\nconst GUARDIAN_ERROR_CODES: Record<string, IntentGuardianErrorCode> = {\n ExtensionsDisabled: 'EXTENSIONS_DISABLED',\n ExtensionCostExceedsMax: 'COST_EXCEEDS_MAX',\n ExtensionFeeExceedsIntentAmount: 'FEE_EXCEEDS_INTENT_AMOUNT',\n IntentAlreadyExpired: 'INTENT_ALREADY_EXPIRED',\n EscrowNotWhitelisted: 'ESCROW_NOT_WHITELISTED',\n ZeroAddress: 'ZERO_ADDRESS',\n};\n\n/**\n * Map a thrown guardian error onto a stable code. Falls back to UNKNOWN rather\n * than guessing, so an unmapped revert is never silently presented as a known\n * condition.\n */\nexport function classifyIntentGuardianError(error: unknown): IntentGuardianErrorCode {\n const haystack =\n error instanceof Error\n ? `${error.name} ${error.message}`\n : typeof error === 'string'\n ? error\n : '';\n for (const [name, code] of Object.entries(GUARDIAN_ERROR_CODES)) {\n if (haystack.includes(name)) return code;\n }\n return 'UNKNOWN';\n}\n\ntype IntentGuardianOperationsConfig = {\n getPublicClient: () => PublicClient;\n getGuardianAddress: () => Address | undefined;\n getGuardianAbi: () => Abi | undefined;\n};\n\nconst ERC20_ALLOWANCE_ABI = [\n {\n type: 'function',\n name: 'allowance',\n stateMutability: 'view',\n inputs: [\n { name: 'owner', type: 'address' },\n { name: 'spender', type: 'address' },\n ],\n outputs: [{ name: '', type: 'uint256' }],\n },\n {\n type: 'function',\n name: 'balanceOf',\n stateMutability: 'view',\n inputs: [{ name: 'account', type: 'address' }],\n outputs: [{ name: '', type: 'uint256' }],\n },\n] as const satisfies Abi;\n\n/**\n * Client surface for the standalone prepaid IntentGuardian.\n *\n * Extension payment is prepaid and non-refundable, and it transfers to the\n * deposit owner rather than the protocol. Any account may pay to extend any\n * live intent — the payer does not have to be the taker.\n */\nexport class IntentGuardianOperations {\n constructor(private readonly config: IntentGuardianOperationsConfig) {}\n\n /** Throws where no guardian is deployed, so unsupported environments fail closed. */\n getContract(): { address: Address; abi: Abi } {\n const address = this.config.getGuardianAddress();\n const abi = this.config.getGuardianAbi();\n if (!address || !abi) {\n throw new Error('IntentGuardian not available for this chain/environment');\n }\n return { address, abi };\n }\n\n /** Non-throwing availability check, for gating UI affordances. */\n isAvailable(): boolean {\n try {\n this.getContract();\n return true;\n } catch {\n return false;\n }\n }\n\n private read<T>(\n functionName: string,\n args: readonly unknown[] = [],\n blockNumber?: bigint,\n ): Promise<T> {\n const { address, abi } = this.getContract();\n return this.config.getPublicClient().readContract({\n address,\n abi,\n functionName,\n args,\n ...(blockNumber !== undefined ? { blockNumber } : {}),\n }) as Promise<T>;\n }\n\n /** Live fee. Never cache this as durable policy — governance can change it. */\n async getExtensionFeeBpsPerHour(): Promise<bigint> {\n return this.read<bigint>('extensionFeeBpsPerHour');\n }\n\n async getOwner(): Promise<Address> {\n return this.read<Address>('owner');\n }\n\n async getPendingOwner(): Promise<Address> {\n return this.read<Address>('pendingOwner');\n }\n\n /** Full live policy in one batch, including whether extensions are enabled at all. */\n async getPolicy(): Promise<IntentGuardianPolicy> {\n const { address } = this.getContract();\n const blockNumber = await this.config.getPublicClient().getBlockNumber();\n const [\n extensionFeeBpsPerHour,\n maxExtensionFeeBpsPerHour,\n maxTotalIntentLifetime,\n owner,\n pendingOwner,\n ] = await Promise.all([\n this.read<bigint>('extensionFeeBpsPerHour', [], blockNumber),\n this.read<bigint>('MAX_EXTENSION_FEE_BPS_PER_HOUR', [], blockNumber),\n this.read<bigint>('MAX_TOTAL_INTENT_LIFETIME', [], blockNumber),\n this.read<Address>('owner', [], blockNumber),\n this.read<Address>('pendingOwner', [], blockNumber),\n ]);\n return {\n guardian: address,\n extensionFeeBpsPerHour,\n extensionsEnabled: extensionFeeBpsPerHour > 0n,\n maxExtensionFeeBpsPerHour,\n maxTotalIntentLifetime,\n owner,\n pendingOwner,\n };\n }\n\n /**\n * Authoritative on-chain quote against fresh state. Prefer this over the\n * package's local pricing helper immediately before signing; the helper is\n * for responsive display only.\n */\n async quoteExtensionCost(params: {\n intentAmount: bigint;\n additionalTime: bigint;\n }): Promise<IntentGuardianQuote> {\n const blockNumber = await this.config.getPublicClient().getBlockNumber();\n const [cost, extensionFeeBpsPerHour] = await Promise.all([\n this.read<bigint>(\n 'quoteExtensionCost',\n [params.intentAmount, params.additionalTime],\n blockNumber,\n ),\n this.read<bigint>('extensionFeeBpsPerHour', [], blockNumber),\n ]);\n return {\n intentAmount: params.intentAmount,\n additionalTime: params.additionalTime,\n extensionFeeBpsPerHour,\n cost,\n quotedAt: Date.now(),\n };\n }\n\n /**\n * Payer's current allowance to the guardian and balance for the deposit\n * token. The guardian transfers the token configured on the target deposit,\n * so callers must not substitute an environment-wide default token.\n */\n async getPayerFunding(params: {\n payer: Address;\n token: Address;\n }): Promise<{ allowance: bigint; balance: bigint }> {\n const { address } = this.getContract();\n const publicClient = this.config.getPublicClient();\n const [allowance, balance] = await Promise.all([\n publicClient.readContract({\n address: params.token,\n abi: ERC20_ALLOWANCE_ABI,\n functionName: 'allowance',\n args: [params.payer, address],\n }) as Promise<bigint>,\n publicClient.readContract({\n address: params.token,\n abi: ERC20_ALLOWANCE_ABI,\n functionName: 'balanceOf',\n args: [params.payer],\n }) as Promise<bigint>,\n ]);\n return { allowance, balance };\n }\n\n /**\n * Whether the payer can fund an extension at `cost`, and what is missing.\n * Callers should re-check against a fresh quote rather than a displayed one.\n */\n async checkPayerReadiness(params: {\n payer: Address;\n token: Address;\n cost: bigint;\n }): Promise<{ ready: boolean; needsApproval: boolean; insufficientBalance: boolean }> {\n const { allowance, balance } = await this.getPayerFunding({\n payer: params.payer,\n token: params.token,\n });\n const needsApproval = allowance < params.cost;\n const insufficientBalance = balance < params.cost;\n return {\n ready: !needsApproval && !insufficientBalance,\n needsApproval,\n insufficientBalance,\n };\n }\n}\n","import type { Address, Hex } from 'viem';\nimport type { PreparedTransaction } from '../../types/prepared';\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\nexport const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' as const;\nexport const ZERO_RATE_MANAGER_ID =\n '0x0000000000000000000000000000000000000000000000000000000000000000' as const;\n\n// ---------------------------------------------------------------------------\n// Normalizers\n// ---------------------------------------------------------------------------\n\nexport const normalizeRateManagerId = (value?: string | null): string =>\n (value ?? ZERO_RATE_MANAGER_ID).toLowerCase();\n\nexport const normalizeRegistry = (value?: string | null): string =>\n (value ?? ZERO_ADDRESS).toLowerCase();\n\nexport const isZeroRateManagerId = (value?: string | null): boolean => {\n if (!value) return true;\n const normalized = value.toLowerCase();\n return normalized === ZERO_ADDRESS || normalized === ZERO_RATE_MANAGER_ID;\n};\n\n// ---------------------------------------------------------------------------\n// Error helper\n// ---------------------------------------------------------------------------\n\nexport const asErrorMessage = (error: unknown): string => {\n if (!error) return 'Unknown error';\n if (error instanceof Error) return error.message;\n if (typeof error === 'string') return error;\n\n const anyErr = error as Record<string, unknown>;\n if (typeof anyErr.shortMessage === 'string') return anyErr.shortMessage;\n if (typeof anyErr.details === 'string') return anyErr.details;\n if (typeof anyErr.message === 'string') return anyErr.message;\n\n try {\n return JSON.stringify(error);\n } catch {\n return String(error);\n }\n};\n\n// ---------------------------------------------------------------------------\n// Delegation state classification\n// ---------------------------------------------------------------------------\n\nexport type DelegationState = 'delegated_here' | 'delegated_elsewhere' | 'not_delegated';\n\n/**\n * Classify whether a deposit is delegated to the target vault, delegated\n * elsewhere, or not delegated at all.\n *\n * @param currentRateManagerId The deposit's current rateManagerId (from indexer)\n * @param currentRegistry The deposit's current rateManagerAddress / registry (from indexer)\n * @param targetRateManagerId The vault's rateManagerId we're comparing against\n * @param targetRegistry The vault's registry address we're comparing against\n */\nexport const classifyDelegationState = (\n currentRateManagerId: string | null | undefined,\n currentRegistry: string | null | undefined,\n targetRateManagerId: string,\n targetRegistry: string | null | undefined,\n): DelegationState => {\n if (isZeroRateManagerId(currentRateManagerId)) {\n return 'not_delegated';\n }\n\n const normalizedCurrent = normalizeRateManagerId(currentRateManagerId);\n const normalizedTarget = targetRateManagerId.toLowerCase();\n const normalizedCurrentRegistry = normalizeRegistry(currentRegistry);\n const normalizedTargetRegistry = targetRegistry ? targetRegistry.toLowerCase() : '';\n\n const idsMatch = normalizedCurrent === normalizedTarget;\n const registryMatches = normalizedTargetRegistry\n ? normalizedCurrentRegistry === normalizedTargetRegistry\n : true;\n\n if (idsMatch && registryMatches) {\n return 'delegated_here';\n }\n\n return 'delegated_elsewhere';\n};\n\nexport const assertAtomicDelegationSwitchSupport = (\n requiresSwitch: boolean,\n canBatch: boolean,\n): void => {\n if (!requiresSwitch || canBatch) return;\n throw new Error(\n 'Switching delegation targets requires smart-account batching. Clear the existing delegation first.',\n );\n};\n\n// ---------------------------------------------------------------------------\n// Contract routing\n// ---------------------------------------------------------------------------\n\nexport type DelegationRoute = 'v2';\n\nexport const getDelegationRoute = (_client: unknown, _escrow: Address): DelegationRoute => 'v2';\n\ntype DelegationMethodSupportClient = Partial<\n Record<'setRateManager' | 'clearRateManager', { prepare?: unknown }>\n>;\n\nexport const assertDelegationMethodSupport = (\n client: DelegationMethodSupportClient,\n _route: DelegationRoute,\n action: 'set' | 'clear',\n): void => {\n const method = action === 'set' ? 'setRateManager' : 'clearRateManager';\n if (client?.[method]?.prepare) return;\n throw new Error(`Delegation requires SDK ${method} support`);\n};\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface DelegationDepositTarget {\n compositeDepositId: string;\n escrow: Address;\n depositId: bigint;\n currentRateManagerId?: string | null;\n currentRateManagerRegistry?: string | null;\n}\n\nexport interface BatchResult {\n hashes: string[];\n failed: Array<{ compositeDepositId: string; error: string }>;\n}\n\n/**\n * Callback the consumer provides for sending a single prepared transaction.\n * Returns the transaction hash.\n */\nexport type SendTransactionFn = (tx: { to: Address; data: Hex; value?: bigint }) => Promise<string>;\n\n/**\n * Optional callback for batching multiple calls in a single user operation\n * (e.g. via a smart account). If not provided, transactions are sent\n * sequentially via sendTransaction.\n */\nexport type SendBatchFn = (\n txs: Array<{ to: Address; data: Hex; value?: bigint }>,\n) => Promise<string>;\n\n// ---------------------------------------------------------------------------\n// Prepare helpers (used internally by hooks)\n// ---------------------------------------------------------------------------\n\nexport const prepareClearDelegationTx = async (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n client: any,\n params: { escrow: Address; depositId: bigint },\n referrer?: string | string[],\n): Promise<PreparedTransaction> => {\n const route = getDelegationRoute(client, params.escrow);\n assertDelegationMethodSupport(client, route, 'clear');\n return client.clearRateManager.prepare({\n escrowAddress: params.escrow,\n depositId: params.depositId,\n ...(referrer ? { txOverrides: { referrer } } : {}),\n });\n};\n\nexport const prepareSetDelegationTx = async (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n client: any,\n params: {\n escrow: Address;\n depositId: bigint;\n registry: Address;\n rateManagerId: Hex;\n },\n referrer?: string | string[],\n): Promise<PreparedTransaction> => {\n const route = getDelegationRoute(client, params.escrow);\n assertDelegationMethodSupport(client, route, 'set');\n return client.setRateManager.prepare({\n escrowAddress: params.escrow,\n depositId: params.depositId,\n rateManagerAddress: params.registry,\n rateManagerId: params.rateManagerId,\n ...(referrer ? { txOverrides: { referrer } } : {}),\n });\n};\n"]}