@permissionless-technologies/upd-sdk 0.1.0 → 0.2.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.
Files changed (47) hide show
  1. package/dist/chunk-3V62JGJY.js +192 -0
  2. package/dist/chunk-3V62JGJY.js.map +1 -0
  3. package/dist/{chunk-ZSWETUGH.cjs → chunk-7BP37BGO.cjs} +359 -31
  4. package/dist/chunk-7BP37BGO.cjs.map +1 -0
  5. package/dist/{chunk-R64I3LAO.js → chunk-AGPBQ56J.js} +81 -155
  6. package/dist/chunk-AGPBQ56J.js.map +1 -0
  7. package/dist/chunk-KSGUFTW3.cjs +206 -0
  8. package/dist/chunk-KSGUFTW3.cjs.map +1 -0
  9. package/dist/{chunk-WRPVPA7E.cjs → chunk-LECDXCSW.cjs} +105 -184
  10. package/dist/chunk-LECDXCSW.cjs.map +1 -0
  11. package/dist/{chunk-4RBWWS2X.js → chunk-PS6EIE5E.js} +359 -32
  12. package/dist/chunk-PS6EIE5E.js.map +1 -0
  13. package/dist/{chunk-RIRT4JX6.js → chunk-TYRBIJVF.js} +3 -228
  14. package/dist/chunk-TYRBIJVF.js.map +1 -0
  15. package/dist/{chunk-ZDAHLZWC.cjs → chunk-VZZN3BR3.cjs} +2 -228
  16. package/dist/chunk-VZZN3BR3.cjs.map +1 -0
  17. package/dist/contracts/index.cjs +13 -13
  18. package/dist/contracts/index.d.cts +104 -24
  19. package/dist/contracts/index.d.ts +104 -24
  20. package/dist/contracts/index.js +2 -2
  21. package/dist/core/index.cjs +17 -17
  22. package/dist/core/index.d.cts +1 -1
  23. package/dist/core/index.d.ts +1 -1
  24. package/dist/core/index.js +3 -3
  25. package/dist/{index-XNClksom.d.ts → index-BMgIlGvW.d.ts} +11 -3
  26. package/dist/{index-yRBqVOHV.d.cts → index-D6VgT_bZ.d.cts} +11 -3
  27. package/dist/index.cjs +50 -50
  28. package/dist/index.d.cts +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +4 -4
  31. package/dist/react/index.cjs +145 -22
  32. package/dist/react/index.cjs.map +1 -1
  33. package/dist/react/index.d.cts +112 -1
  34. package/dist/react/index.d.ts +112 -1
  35. package/dist/react/index.js +126 -5
  36. package/dist/react/index.js.map +1 -1
  37. package/package.json +3 -1
  38. package/dist/chunk-4RBWWS2X.js.map +0 -1
  39. package/dist/chunk-4VXNJTNQ.cjs +0 -58
  40. package/dist/chunk-4VXNJTNQ.cjs.map +0 -1
  41. package/dist/chunk-63FIKV36.js +0 -49
  42. package/dist/chunk-63FIKV36.js.map +0 -1
  43. package/dist/chunk-R64I3LAO.js.map +0 -1
  44. package/dist/chunk-RIRT4JX6.js.map +0 -1
  45. package/dist/chunk-WRPVPA7E.cjs.map +0 -1
  46. package/dist/chunk-ZDAHLZWC.cjs.map +0 -1
  47. package/dist/chunk-ZSWETUGH.cjs.map +0 -1
@@ -336,4 +336,115 @@ interface UseUnstakeUPDReturn {
336
336
  */
337
337
  declare function useUnstakeUPD(config: UseUnstakeUPDConfig): UseUnstakeUPDReturn;
338
338
 
339
- export { type UseBurnQuoteConfig, type UseBurnQuoteReturn, type UseBurnUPDConfig, type UseBurnUPDReturn, type UseCollateralConfig, type UseCollateralReturn, type UseEthUsdPriceConfig, type UseEthUsdPriceReturn, type UseMintQuoteConfig, type UseMintQuoteReturn, type UseMintUPDConfig, type UseMintUPDReturn, type UseSUPDConfig, type UseSUPDReturn, type UseStabilizerConfig, type UseStabilizerReturn, type UseStakeUPDConfig, type UseStakeUPDReturn, type UseSystemHealthConfig, type UseSystemHealthReturn, type UseUPDConfig, type UseUPDReturn, type UseUnstakeUPDConfig, type UseUnstakeUPDReturn, useBurnQuote, useBurnUPD, useCollateral, useEthUsdPrice, useMintQuote, useMintUPD, useSUPD, useStabilizer, useStakeUPD, useSystemHealth, useUPD, useUnstakeUPD };
339
+ interface UseSwapEthToUPDConfig {
340
+ /** Chain ID — contract addresses resolved automatically from deployment config. */
341
+ chainId: number;
342
+ /** Oracle configuration (optional). */
343
+ oracle?: UseEthUsdPriceConfig;
344
+ }
345
+ interface UseSwapEthToUPDReturn {
346
+ /** Compute expected UPD amount for a given ETH input. */
347
+ quote: (ethAmount: bigint) => bigint | undefined;
348
+ /** Execute the mint: sends ETH, receives UPD. Oracle attestation handled internally. */
349
+ mint: (params: {
350
+ to: Address;
351
+ ethAmount: bigint;
352
+ }) => void;
353
+ /** Current ETH/USD price (18 decimals). */
354
+ price: bigint | undefined;
355
+ /** Formatted price string (e.g. "$2,000.00"). */
356
+ priceFormatted: string;
357
+ /** Whether the oracle price is still loading. */
358
+ priceLoading: boolean;
359
+ /** Whether the mint transaction is pending. */
360
+ isPending: boolean;
361
+ /** Transaction hash once submitted. */
362
+ txHash: Hash | undefined;
363
+ /** Whether we're waiting for on-chain confirmation. */
364
+ isConfirming: boolean;
365
+ /** Whether the transaction is confirmed. */
366
+ isConfirmed: boolean;
367
+ /** Error from oracle or transaction. */
368
+ error: Error | null;
369
+ /** Reset the transaction state. */
370
+ reset: () => void;
371
+ /** Whether the hook is ready (deployment exists + oracle loaded). */
372
+ isReady: boolean;
373
+ }
374
+ /**
375
+ * One-stop hook for swapping ETH → UPD.
376
+ *
377
+ * Internally composes oracle price feed, quote computation, and StabilizerNFT.mintUPD.
378
+ * Contract addresses are resolved from the deployment config — no manual wiring needed.
379
+ *
380
+ * @example
381
+ * ```tsx
382
+ * const { quote, mint, price, priceFormatted, isPending, isConfirmed } = useSwapEthToUPD({
383
+ * chainId: 11155111,
384
+ * })
385
+ *
386
+ * const expectedUPD = quote(parseEther('1'))
387
+ *
388
+ * <button onClick={() => mint({ to: address, ethAmount: parseEther('1') })}>
389
+ * Mint {expectedUPD ? formatUnits(expectedUPD, 18) : '...'} UPD
390
+ * </button>
391
+ * ```
392
+ */
393
+ declare function useSwapEthToUPD(config: UseSwapEthToUPDConfig): UseSwapEthToUPDReturn;
394
+
395
+ interface UseSwapUPDToStETHConfig {
396
+ /** Chain ID — contract addresses resolved automatically from deployment config. */
397
+ chainId: number;
398
+ /** Oracle configuration (optional). */
399
+ oracle?: UseEthUsdPriceConfig;
400
+ }
401
+ interface UseSwapUPDToStETHReturn {
402
+ /** Compute expected stETH amount for a given UPD input. */
403
+ quote: (updAmount: bigint) => bigint | undefined;
404
+ /** Execute the burn: sends UPD, receives stETH. Oracle attestation handled internally. */
405
+ burn: (params: {
406
+ updAmount: bigint;
407
+ }) => void;
408
+ /** Current ETH/USD price (18 decimals). */
409
+ price: bigint | undefined;
410
+ /** Formatted price string (e.g. "$2,000.00"). */
411
+ priceFormatted: string;
412
+ /** Whether the oracle price is still loading. */
413
+ priceLoading: boolean;
414
+ /** Whether the burn transaction is pending. */
415
+ isPending: boolean;
416
+ /** Transaction hash once submitted. */
417
+ txHash: Hash | undefined;
418
+ /** Whether we're waiting for on-chain confirmation. */
419
+ isConfirming: boolean;
420
+ /** Whether the transaction is confirmed. */
421
+ isConfirmed: boolean;
422
+ /** Error from oracle or transaction. */
423
+ error: Error | null;
424
+ /** Reset the transaction state. */
425
+ reset: () => void;
426
+ /** Whether the hook is ready (deployment exists + oracle loaded). */
427
+ isReady: boolean;
428
+ }
429
+ /**
430
+ * One-stop hook for swapping UPD → stETH (burn).
431
+ *
432
+ * Internally composes oracle price feed, quote computation, and StabilizerNFT.burnUPD.
433
+ * Contract addresses are resolved from the deployment config — no manual wiring needed.
434
+ *
435
+ * @example
436
+ * ```tsx
437
+ * const { quote, burn, priceFormatted, isPending, isConfirmed } = useSwapUPDToStETH({
438
+ * chainId: 11155111,
439
+ * })
440
+ *
441
+ * const expectedStETH = quote(parseUnits('1000', 18))
442
+ *
443
+ * <button onClick={() => burn({ updAmount: parseUnits('1000', 18) })}>
444
+ * Burn for {expectedStETH ? formatUnits(expectedStETH, 18) : '...'} stETH
445
+ * </button>
446
+ * ```
447
+ */
448
+ declare function useSwapUPDToStETH(config: UseSwapUPDToStETHConfig): UseSwapUPDToStETHReturn;
449
+
450
+ export { type UseBurnQuoteConfig, type UseBurnQuoteReturn, type UseBurnUPDConfig, type UseBurnUPDReturn, type UseCollateralConfig, type UseCollateralReturn, type UseEthUsdPriceConfig, type UseEthUsdPriceReturn, type UseMintQuoteConfig, type UseMintQuoteReturn, type UseMintUPDConfig, type UseMintUPDReturn, type UseSUPDConfig, type UseSUPDReturn, type UseStabilizerConfig, type UseStabilizerReturn, type UseStakeUPDConfig, type UseStakeUPDReturn, type UseSwapEthToUPDConfig, type UseSwapEthToUPDReturn, type UseSwapUPDToStETHConfig, type UseSwapUPDToStETHReturn, type UseSystemHealthConfig, type UseSystemHealthReturn, type UseUPDConfig, type UseUPDReturn, type UseUnstakeUPDConfig, type UseUnstakeUPDReturn, useBurnQuote, useBurnUPD, useCollateral, useEthUsdPrice, useMintQuote, useMintUPD, useSUPD, useStabilizer, useStakeUPD, useSwapEthToUPD, useSwapUPDToStETH, useSystemHealth, useUPD, useUnstakeUPD };
@@ -1,6 +1,6 @@
1
- import '../chunk-RIRT4JX6.js';
2
- import { quoteMintUPD, quoteBurnUPD, computeSystemHealth } from '../chunk-63FIKV36.js';
3
- import { UPD_TOKEN_ABI, OVERCOLLATERALIZATION_REPORTER_ABI, STABILIZER_NFT_ABI, SUPD_ABI } from '../chunk-4RBWWS2X.js';
1
+ import '../chunk-TYRBIJVF.js';
2
+ import { quoteMintUPD, quoteBurnUPD, computeSystemHealth, getDeployment } from '../chunk-3V62JGJY.js';
3
+ import { UPD_TOKEN_ABI, OVERCOLLATERALIZATION_REPORTER_ABI, STABILIZER_NFT_ABI, SUPD_ABI } from '../chunk-PS6EIE5E.js';
4
4
  import { createOracleClient } from '../chunk-DJBU2OEB.js';
5
5
  import { useReadContract, useWriteContract, useWaitForTransactionReceipt } from 'wagmi';
6
6
  import { useQuery } from '@tanstack/react-query';
@@ -31,7 +31,7 @@ function useCollateral(config) {
31
31
  const { data: totalStEthCollateral, isLoading: collateralLoading } = useReadContract({
32
32
  address: reporterAddress,
33
33
  abi: OVERCOLLATERALIZATION_REPORTER_ABI,
34
- functionName: "totalStEthCollateral"
34
+ functionName: "getTotalStEthCollateral"
35
35
  });
36
36
  const { data: totalUPDSupply, isLoading: supplyLoading } = useReadContract({
37
37
  address: tokenAddress,
@@ -364,7 +364,128 @@ function useUnstakeUPD(config) {
364
364
  reset
365
365
  };
366
366
  }
367
+ function useSwapEthToUPD(config) {
368
+ const deployment = getDeployment(config.chainId);
369
+ const stabilizerNFTAddress = deployment?.contracts.StabilizerNFT;
370
+ const {
371
+ price,
372
+ priceFormatted,
373
+ attestation,
374
+ isLoading: priceLoading,
375
+ error: priceError
376
+ } = useEthUsdPrice(config.oracle);
377
+ const {
378
+ writeContract,
379
+ data: txHash,
380
+ isPending,
381
+ error: writeError,
382
+ reset
383
+ } = useWriteContract();
384
+ const {
385
+ isLoading: isConfirming,
386
+ isSuccess: isConfirmed
387
+ } = useWaitForTransactionReceipt({ hash: txHash });
388
+ const quote = useMemo(() => {
389
+ return (ethAmount) => {
390
+ if (price === void 0 || ethAmount === 0n) return void 0;
391
+ return quoteMintUPD(ethAmount, price);
392
+ };
393
+ }, [price]);
394
+ function mint(params) {
395
+ if (!stabilizerNFTAddress || !attestation) return;
396
+ writeContract({
397
+ address: stabilizerNFTAddress,
398
+ abi: STABILIZER_NFT_ABI,
399
+ functionName: "mintUPD",
400
+ args: [
401
+ params.to,
402
+ {
403
+ price: attestation.price,
404
+ decimals: attestation.decimals,
405
+ dataTimestamp: attestation.dataTimestamp,
406
+ assetPair: attestation.assetPair,
407
+ signature: attestation.signature
408
+ }
409
+ ],
410
+ value: params.ethAmount
411
+ });
412
+ }
413
+ return {
414
+ quote,
415
+ mint,
416
+ price,
417
+ priceFormatted,
418
+ priceLoading,
419
+ isPending,
420
+ txHash,
421
+ isConfirming,
422
+ isConfirmed,
423
+ error: writeError ?? priceError,
424
+ reset,
425
+ isReady: !!stabilizerNFTAddress && !!attestation
426
+ };
427
+ }
428
+ function useSwapUPDToStETH(config) {
429
+ const deployment = getDeployment(config.chainId);
430
+ const stabilizerNFTAddress = deployment?.contracts.StabilizerNFT;
431
+ const {
432
+ price,
433
+ priceFormatted,
434
+ attestation,
435
+ isLoading: priceLoading,
436
+ error: priceError
437
+ } = useEthUsdPrice(config.oracle);
438
+ const {
439
+ writeContract,
440
+ data: txHash,
441
+ isPending,
442
+ error: writeError,
443
+ reset
444
+ } = useWriteContract();
445
+ const {
446
+ isLoading: isConfirming,
447
+ isSuccess: isConfirmed
448
+ } = useWaitForTransactionReceipt({ hash: txHash });
449
+ const quote = useMemo(() => {
450
+ return (updAmount) => {
451
+ if (price === void 0 || updAmount === 0n) return void 0;
452
+ return quoteBurnUPD(updAmount, price);
453
+ };
454
+ }, [price]);
455
+ function burn(params) {
456
+ if (!stabilizerNFTAddress || !attestation) return;
457
+ writeContract({
458
+ address: stabilizerNFTAddress,
459
+ abi: STABILIZER_NFT_ABI,
460
+ functionName: "burnUPD",
461
+ args: [
462
+ params.updAmount,
463
+ {
464
+ price: attestation.price,
465
+ decimals: attestation.decimals,
466
+ dataTimestamp: attestation.dataTimestamp,
467
+ assetPair: attestation.assetPair,
468
+ signature: attestation.signature
469
+ }
470
+ ]
471
+ });
472
+ }
473
+ return {
474
+ quote,
475
+ burn,
476
+ price,
477
+ priceFormatted,
478
+ priceLoading,
479
+ isPending,
480
+ txHash,
481
+ isConfirming,
482
+ isConfirmed,
483
+ error: writeError ?? priceError,
484
+ reset,
485
+ isReady: !!stabilizerNFTAddress && !!attestation
486
+ };
487
+ }
367
488
 
368
- export { useBurnQuote, useBurnUPD, useCollateral, useEthUsdPrice, useMintQuote, useMintUPD, useSUPD, useStabilizer, useStakeUPD, useSystemHealth, useUPD, useUnstakeUPD };
489
+ export { useBurnQuote, useBurnUPD, useCollateral, useEthUsdPrice, useMintQuote, useMintUPD, useSUPD, useStabilizer, useStakeUPD, useSwapEthToUPD, useSwapUPDToStETH, useSystemHealth, useUPD, useUnstakeUPD };
369
490
  //# sourceMappingURL=index.js.map
370
491
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/react/use-upd.ts","../../src/react/use-collateral.ts","../../src/react/use-stabilizer.ts","../../src/react/use-eth-usd-price.ts","../../src/react/use-mint-quote.ts","../../src/react/use-burn-quote.ts","../../src/react/use-mint-upd.ts","../../src/react/use-burn-upd.ts","../../src/react/use-system-health.ts","../../src/react/use-supd.ts","../../src/react/use-stake-upd.ts","../../src/react/use-unstake-upd.ts"],"names":["useReadContract","useMemo","useWriteContract","useWaitForTransactionReceipt"],"mappings":";;;;;;;;AAeO,SAAS,OAAO,MAAA,EAAoC;AACzD,EAAA,MAAM,EAAE,YAAA,EAAc,WAAA,EAAY,GAAI,MAAA;AAEtC,EAAA,MAAM,EAAE,IAAA,EAAM,OAAA,EAAS,SAAA,EAAW,cAAA,KAAmB,eAAA,CAAgB;AAAA,IACnE,OAAA,EAAS,YAAA;AAAA,IACT,GAAA,EAAK,aAAA;AAAA,IACL,YAAA,EAAc,WAAA;AAAA,IACd,IAAA,EAAM,WAAA,GAAc,CAAC,WAAW,CAAA,GAAI,MAAA;AAAA,IACpC,KAAA,EAAO,EAAE,OAAA,EAAS,CAAC,CAAC,WAAA;AAAY,GACjC,CAAA;AAED,EAAA,MAAM,EAAE,IAAA,EAAM,WAAA,EAAa,SAAA,EAAW,aAAA,KAAkB,eAAA,CAAgB;AAAA,IACtE,OAAA,EAAS,YAAA;AAAA,IACT,GAAA,EAAK,aAAA;AAAA,IACL,YAAA,EAAc;AAAA,GACf,CAAA;AAED,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,WAAA;AAAA,IACA,WAAW,cAAA,IAAkB;AAAA,GAC/B;AACF;ACrBO,SAAS,cAAc,MAAA,EAAkD;AAC9E,EAAA,MAAM,EAAE,eAAA,EAAiB,YAAA,EAAa,GAAI,MAAA;AAE1C,EAAA,MAAM,EAAE,IAAA,EAAM,oBAAA,EAAsB,SAAA,EAAW,iBAAA,KAC7CA,eAAAA,CAAgB;AAAA,IACd,OAAA,EAAS,eAAA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Content":["import { useReadContract } from 'wagmi'\nimport type { Address } from 'viem'\nimport { UPD_TOKEN_ABI } from '../contracts/index.js'\n\nexport interface UseUPDConfig {\n tokenAddress: Address\n userAddress?: Address\n}\n\nexport interface UseUPDReturn {\n balance: bigint | undefined\n totalSupply: bigint | undefined\n isLoading: boolean\n}\n\nexport function useUPD(config: UseUPDConfig): UseUPDReturn {\n const { tokenAddress, userAddress } = config\n\n const { data: balance, isLoading: balanceLoading } = useReadContract({\n address: tokenAddress,\n abi: UPD_TOKEN_ABI,\n functionName: 'balanceOf',\n args: userAddress ? [userAddress] : undefined,\n query: { enabled: !!userAddress },\n })\n\n const { data: totalSupply, isLoading: supplyLoading } = useReadContract({\n address: tokenAddress,\n abi: UPD_TOKEN_ABI,\n functionName: 'totalSupply',\n })\n\n return {\n balance: balance as bigint | undefined,\n totalSupply: totalSupply as bigint | undefined,\n isLoading: balanceLoading || supplyLoading,\n }\n}\n","import { useReadContract } from 'wagmi'\nimport type { Address } from 'viem'\nimport { OVERCOLLATERALIZATION_REPORTER_ABI } from '../contracts/index.js'\nimport { UPD_TOKEN_ABI } from '../contracts/index.js'\n\nexport interface UseCollateralConfig {\n reporterAddress: Address\n tokenAddress: Address\n}\n\nexport interface UseCollateralReturn {\n totalStEthCollateral: bigint | undefined\n totalUPDSupply: bigint | undefined\n isLoading: boolean\n}\n\nexport function useCollateral(config: UseCollateralConfig): UseCollateralReturn {\n const { reporterAddress, tokenAddress } = config\n\n const { data: totalStEthCollateral, isLoading: collateralLoading } =\n useReadContract({\n address: reporterAddress,\n abi: OVERCOLLATERALIZATION_REPORTER_ABI,\n functionName: 'totalStEthCollateral',\n })\n\n const { data: totalUPDSupply, isLoading: supplyLoading } = useReadContract({\n address: tokenAddress,\n abi: UPD_TOKEN_ABI,\n functionName: 'totalSupply',\n })\n\n return {\n totalStEthCollateral: totalStEthCollateral as bigint | undefined,\n totalUPDSupply: totalUPDSupply as bigint | undefined,\n isLoading: collateralLoading || supplyLoading,\n }\n}\n","import { useReadContract } from 'wagmi'\nimport type { Address } from 'viem'\nimport { STABILIZER_NFT_ABI } from '../contracts/index.js'\n\nexport interface UseStabilizerConfig {\n stabilizerNFTAddress: Address\n tokenId?: bigint\n}\n\nexport interface UseStabilizerReturn {\n positionEscrowAddress: Address | undefined\n stabilizerEscrowAddress: Address | undefined\n isLoading: boolean\n}\n\nexport function useStabilizer(\n config: UseStabilizerConfig,\n): UseStabilizerReturn {\n const { stabilizerNFTAddress, tokenId } = config\n\n const { data: positionEscrow, isLoading: posLoading } = useReadContract({\n address: stabilizerNFTAddress,\n abi: STABILIZER_NFT_ABI,\n functionName: 'positionEscrows',\n args: tokenId !== undefined ? [tokenId] : undefined,\n query: { enabled: tokenId !== undefined },\n })\n\n const { data: stabilizerEscrow, isLoading: stabLoading } = useReadContract({\n address: stabilizerNFTAddress,\n abi: STABILIZER_NFT_ABI,\n functionName: 'stabilizerEscrows',\n args: tokenId !== undefined ? [tokenId] : undefined,\n query: { enabled: tokenId !== undefined },\n })\n\n return {\n positionEscrowAddress: positionEscrow as Address | undefined,\n stabilizerEscrowAddress: stabilizerEscrow as Address | undefined,\n isLoading: posLoading || stabLoading,\n }\n}\n","import { useQuery } from '@tanstack/react-query'\nimport { createOracleClient } from '../oracle/client.js'\nimport type { PriceAttestationQuery } from '../core/types.js'\n\nexport interface UseEthUsdPriceConfig {\n /** Oracle service URL. Defaults to oracle.upd.io. */\n oracleUrl?: string\n /** Refetch interval in milliseconds. Defaults to 10000 (10s). */\n refetchInterval?: number\n /** Whether to enable the query. Defaults to true. */\n enabled?: boolean\n}\n\nexport interface UseEthUsdPriceReturn {\n /** Raw price in 18 decimals (e.g. 2000e18 = $2000). */\n price: bigint | undefined\n /** Human-readable formatted price string (e.g. \"$2,000.00\"). */\n priceFormatted: string\n /** Full signed attestation, ready to pass to mint/burn. */\n attestation: PriceAttestationQuery | undefined\n /** Whether the initial fetch is loading. */\n isLoading: boolean\n /** Error from the most recent fetch, if any. */\n error: Error | null\n /** Manually trigger a refetch. */\n refetch: () => void\n}\n\nfunction formatUsdPrice(price: bigint | undefined): string {\n if (price === undefined) return '--'\n const priceFloat = Number(price) / 1e18\n return new Intl.NumberFormat('en-US', {\n style: 'currency',\n currency: 'USD',\n minimumFractionDigits: 2,\n maximumFractionDigits: 2,\n }).format(priceFloat)\n}\n\nexport function useEthUsdPrice(config?: UseEthUsdPriceConfig): UseEthUsdPriceReturn {\n const oracleUrl = config?.oracleUrl\n const refetchInterval = config?.refetchInterval ?? 10_000\n const enabled = config?.enabled ?? true\n\n const oracle = createOracleClient({ oracleUrl })\n\n const { data, isLoading, error, refetch } = useQuery({\n queryKey: ['upd-oracle-eth-usd', oracleUrl],\n queryFn: () => oracle.getEthUsdAttestation(),\n refetchInterval,\n enabled,\n staleTime: 5_000,\n })\n\n return {\n price: data?.price,\n priceFormatted: formatUsdPrice(data?.price),\n attestation: data,\n isLoading,\n error: error as Error | null,\n refetch: () => { refetch() },\n }\n}\n","import { useMemo } from 'react'\nimport { useEthUsdPrice, type UseEthUsdPriceConfig } from './use-eth-usd-price.js'\nimport { quoteMintUPD } from '../core/quote.js'\n\nexport interface UseMintQuoteConfig extends UseEthUsdPriceConfig {}\n\nexport interface UseMintQuoteReturn {\n /** Expected UPD amount for the given ETH input (18 decimals). */\n updAmount: bigint | undefined\n /** Current ETH/USD price used for the quote (18 decimals). */\n ethUsdPrice: bigint | undefined\n /** Whether the price is still loading. */\n isLoading: boolean\n}\n\n/**\n * Real-time mint quote hook — composes oracle price + pure math.\n *\n * @param ethAmount - ETH amount to quote (in wei). Pass 0n to disable.\n * @param config - Optional oracle configuration.\n *\n * @example\n * ```tsx\n * const { updAmount, isLoading } = useMintQuote(parseEther('1'))\n * // updAmount ≈ 2000e18 (at $2000/ETH)\n * ```\n */\nexport function useMintQuote(\n ethAmount: bigint,\n config?: UseMintQuoteConfig,\n): UseMintQuoteReturn {\n const { price, isLoading } = useEthUsdPrice({\n ...config,\n enabled: ethAmount > 0n && (config?.enabled ?? true),\n })\n\n const updAmount = useMemo(() => {\n if (price === undefined || ethAmount === 0n) return undefined\n return quoteMintUPD(ethAmount, price)\n }, [ethAmount, price])\n\n return {\n updAmount,\n ethUsdPrice: price,\n isLoading,\n }\n}\n","import { useMemo } from 'react'\nimport { useEthUsdPrice, type UseEthUsdPriceConfig } from './use-eth-usd-price.js'\nimport { quoteBurnUPD } from '../core/quote.js'\n\nexport interface UseBurnQuoteConfig extends UseEthUsdPriceConfig {}\n\nexport interface UseBurnQuoteReturn {\n /** Expected stETH amount for the given UPD input (in wei). */\n stEthAmount: bigint | undefined\n /** Current ETH/USD price used for the quote (18 decimals). */\n ethUsdPrice: bigint | undefined\n /** Whether the price is still loading. */\n isLoading: boolean\n}\n\n/**\n * Real-time burn quote hook — composes oracle price + pure math.\n *\n * @param updAmount - UPD amount to quote (18 decimals). Pass 0n to disable.\n * @param config - Optional oracle configuration.\n *\n * @example\n * ```tsx\n * const { stEthAmount, isLoading } = useBurnQuote(parseUnits('2000', 18))\n * // stEthAmount ≈ 1e18 (at $2000/ETH)\n * ```\n */\nexport function useBurnQuote(\n updAmount: bigint,\n config?: UseBurnQuoteConfig,\n): UseBurnQuoteReturn {\n const { price, isLoading } = useEthUsdPrice({\n ...config,\n enabled: updAmount > 0n && (config?.enabled ?? true),\n })\n\n const stEthAmount = useMemo(() => {\n if (price === undefined || updAmount === 0n) return undefined\n return quoteBurnUPD(updAmount, price)\n }, [updAmount, price])\n\n return {\n stEthAmount,\n ethUsdPrice: price,\n isLoading,\n }\n}\n","import { useWriteContract, useWaitForTransactionReceipt } from 'wagmi'\nimport type { Address, Hash } from 'viem'\nimport type { PriceAttestationQuery } from '../core/types.js'\nimport { STABILIZER_NFT_ABI } from '../contracts/index.js'\n\nexport interface UseMintUPDConfig {\n /** Address of the StabilizerNFT contract. */\n stabilizerNFTAddress: Address\n}\n\nexport interface UseMintUPDReturn {\n /** Execute the mint transaction. */\n mint: (params: {\n to: Address\n ethAmount: bigint\n attestation: PriceAttestationQuery\n }) => void\n /** Whether the transaction is being sent. */\n isPending: boolean\n /** Transaction hash once submitted. */\n txHash: Hash | undefined\n /** Whether we're waiting for confirmation. */\n isConfirming: boolean\n /** Whether the transaction is confirmed. */\n isConfirmed: boolean\n /** Error from the transaction, if any. */\n error: Error | null\n /** Reset the mutation state. */\n reset: () => void\n}\n\n/**\n * Write hook for minting UPD by depositing ETH.\n *\n * @example\n * ```tsx\n * const { mint, isPending, isConfirmed, error } = useMintUPD({\n * stabilizerNFTAddress: deployment.contracts.StabilizerNFT,\n * })\n *\n * // Use with useEthUsdPrice to get attestation\n * const { attestation } = useEthUsdPrice()\n *\n * <button onClick={() => mint({ to: userAddress, ethAmount: parseEther('1'), attestation })}>\n * Mint UPD\n * </button>\n * ```\n */\nexport function useMintUPD(config: UseMintUPDConfig): UseMintUPDReturn {\n const { stabilizerNFTAddress } = config\n\n const {\n writeContract,\n data: txHash,\n isPending,\n error: writeError,\n reset,\n } = useWriteContract()\n\n const {\n isLoading: isConfirming,\n isSuccess: isConfirmed,\n } = useWaitForTransactionReceipt({\n hash: txHash,\n })\n\n function mint(params: {\n to: Address\n ethAmount: bigint\n attestation: PriceAttestationQuery\n }) {\n writeContract({\n address: stabilizerNFTAddress,\n abi: STABILIZER_NFT_ABI,\n functionName: 'mintUPD',\n args: [\n params.to,\n {\n price: params.attestation.price,\n decimals: params.attestation.decimals,\n dataTimestamp: params.attestation.dataTimestamp,\n assetPair: params.attestation.assetPair,\n signature: params.attestation.signature,\n },\n ],\n value: params.ethAmount,\n })\n }\n\n return {\n mint,\n isPending,\n txHash,\n isConfirming,\n isConfirmed,\n error: writeError as Error | null,\n reset,\n }\n}\n","import { useWriteContract, useWaitForTransactionReceipt } from 'wagmi'\nimport type { Address, Hash } from 'viem'\nimport type { PriceAttestationQuery } from '../core/types.js'\nimport { STABILIZER_NFT_ABI } from '../contracts/index.js'\n\nexport interface UseBurnUPDConfig {\n /** Address of the StabilizerNFT contract. */\n stabilizerNFTAddress: Address\n}\n\nexport interface UseBurnUPDReturn {\n /** Execute the burn transaction. */\n burn: (params: {\n updAmount: bigint\n attestation: PriceAttestationQuery\n }) => void\n /** Whether the transaction is being sent. */\n isPending: boolean\n /** Transaction hash once submitted. */\n txHash: Hash | undefined\n /** Whether we're waiting for confirmation. */\n isConfirming: boolean\n /** Whether the transaction is confirmed. */\n isConfirmed: boolean\n /** Error from the transaction, if any. */\n error: Error | null\n /** Reset the mutation state. */\n reset: () => void\n}\n\n/**\n * Write hook for burning UPD to receive stETH.\n *\n * @example\n * ```tsx\n * const { burn, isPending, isConfirmed } = useBurnUPD({\n * stabilizerNFTAddress: deployment.contracts.StabilizerNFT,\n * })\n *\n * const { attestation } = useEthUsdPrice()\n *\n * <button onClick={() => burn({ updAmount: parseUnits('1000', 18), attestation })}>\n * Burn 1000 UPD\n * </button>\n * ```\n */\nexport function useBurnUPD(config: UseBurnUPDConfig): UseBurnUPDReturn {\n const { stabilizerNFTAddress } = config\n\n const {\n writeContract,\n data: txHash,\n isPending,\n error: writeError,\n reset,\n } = useWriteContract()\n\n const {\n isLoading: isConfirming,\n isSuccess: isConfirmed,\n } = useWaitForTransactionReceipt({\n hash: txHash,\n })\n\n function burn(params: {\n updAmount: bigint\n attestation: PriceAttestationQuery\n }) {\n writeContract({\n address: stabilizerNFTAddress,\n abi: STABILIZER_NFT_ABI,\n functionName: 'burnUPD',\n args: [\n params.updAmount,\n {\n price: params.attestation.price,\n decimals: params.attestation.decimals,\n dataTimestamp: params.attestation.dataTimestamp,\n assetPair: params.attestation.assetPair,\n signature: params.attestation.signature,\n },\n ],\n })\n }\n\n return {\n burn,\n isPending,\n txHash,\n isConfirming,\n isConfirmed,\n error: writeError as Error | null,\n reset,\n }\n}\n","import { useMemo } from 'react'\nimport type { Address } from 'viem'\nimport { useCollateral, type UseCollateralConfig } from './use-collateral.js'\nimport { useEthUsdPrice, type UseEthUsdPriceConfig } from './use-eth-usd-price.js'\nimport { computeSystemHealth, type SystemHealth } from '../core/health.js'\n\nexport interface UseSystemHealthConfig {\n /** Address of the OvercollateralizationReporter contract. */\n reporterAddress: Address\n /** Address of the UPD token. */\n tokenAddress: Address\n /** Oracle service URL. */\n oracleUrl?: string\n /** Minimum collateral ratio in basis points (default: 12500 = 125%). */\n minRatioBps?: bigint\n}\n\nexport interface UseSystemHealthReturn {\n /** Computed system health metrics, or undefined if still loading. */\n health: SystemHealth | undefined\n /** Whether any underlying data is still loading. */\n isLoading: boolean\n}\n\n/**\n * System health hook — composes useCollateral + useEthUsdPrice + computeSystemHealth.\n *\n * @example\n * ```tsx\n * const { health, isLoading } = useSystemHealth({\n * reporterAddress: deployment.contracts.OvercollateralizationReporter,\n * tokenAddress: deployment.contracts.UPDToken,\n * })\n *\n * if (health && !health.isHealthy) {\n * return <Alert>System undercollateralized: {health.systemCollateralRatioBps} bps</Alert>\n * }\n * ```\n */\nexport function useSystemHealth(config: UseSystemHealthConfig): UseSystemHealthReturn {\n const collateralConfig: UseCollateralConfig = {\n reporterAddress: config.reporterAddress,\n tokenAddress: config.tokenAddress,\n }\n\n const priceConfig: UseEthUsdPriceConfig = {\n oracleUrl: config.oracleUrl,\n }\n\n const {\n totalStEthCollateral,\n totalUPDSupply,\n isLoading: collateralLoading,\n } = useCollateral(collateralConfig)\n\n const {\n price: ethUsdPrice,\n isLoading: priceLoading,\n } = useEthUsdPrice(priceConfig)\n\n const health = useMemo(() => {\n if (\n totalStEthCollateral === undefined ||\n totalUPDSupply === undefined ||\n ethUsdPrice === undefined\n ) {\n return undefined\n }\n\n return computeSystemHealth(\n { totalStEthCollateral, totalUPDSupply },\n ethUsdPrice,\n config.minRatioBps,\n )\n }, [totalStEthCollateral, totalUPDSupply, ethUsdPrice, config.minRatioBps])\n\n return {\n health,\n isLoading: collateralLoading || priceLoading,\n }\n}\n","import { useReadContract } from 'wagmi'\nimport type { Address } from 'viem'\nimport { SUPD_ABI } from '../contracts/index.js'\n\nexport interface UseSUPDConfig {\n /** Address of the sUPD contract. */\n supdAddress: Address\n /** User address to read balance for (optional). */\n userAddress?: Address\n}\n\nexport interface UseSUPDReturn {\n /** User's sUPD balance (18 decimals). */\n balance: bigint | undefined\n /** Total sUPD shares outstanding. */\n totalSupply: bigint | undefined\n /** Current share value with accrued yield (18 decimals). */\n shareValue: bigint | undefined\n /** Annual yield in basis points (e.g. 800 = 8%). */\n annualYieldBps: bigint | undefined\n /** Total USD liability of all outstanding sUPD. */\n totalLiabilityUSD: bigint | undefined\n /** Whether any read is still loading. */\n isLoading: boolean\n}\n\n/**\n * Read hook for sUPD — share value, APY, balances, and total liability.\n *\n * @example\n * ```tsx\n * const { balance, shareValue, annualYieldBps, isLoading } = useSUPD({\n * supdAddress: deployment.contracts.sUPD,\n * userAddress: account.address,\n * })\n * ```\n */\nexport function useSUPD(config: UseSUPDConfig): UseSUPDReturn {\n const { supdAddress, userAddress } = config\n\n const { data: balance, isLoading: balLoading } = useReadContract({\n address: supdAddress,\n abi: SUPD_ABI,\n functionName: 'balanceOf',\n args: userAddress ? [userAddress] : undefined,\n query: { enabled: !!userAddress },\n })\n\n const { data: totalSupply, isLoading: supplyLoading } = useReadContract({\n address: supdAddress,\n abi: SUPD_ABI,\n functionName: 'totalSupply',\n })\n\n const { data: shareValue, isLoading: svLoading } = useReadContract({\n address: supdAddress,\n abi: SUPD_ABI,\n functionName: 'currentShareValue',\n })\n\n const { data: annualYieldBps, isLoading: apyLoading } = useReadContract({\n address: supdAddress,\n abi: SUPD_ABI,\n functionName: 'annualYieldBps',\n })\n\n const { data: totalLiabilityUSD, isLoading: liabLoading } = useReadContract({\n address: supdAddress,\n abi: SUPD_ABI,\n functionName: 'totalLiabilityUSD',\n })\n\n return {\n balance: balance as bigint | undefined,\n totalSupply: totalSupply as bigint | undefined,\n shareValue: shareValue as bigint | undefined,\n annualYieldBps: annualYieldBps as bigint | undefined,\n totalLiabilityUSD: totalLiabilityUSD as bigint | undefined,\n isLoading: balLoading || supplyLoading || svLoading || apyLoading || liabLoading,\n }\n}\n","import { useWriteContract, useWaitForTransactionReceipt } from 'wagmi'\nimport type { Address, Hash } from 'viem'\nimport type { PriceAttestationQuery } from '../core/types.js'\nimport { SUPD_ABI } from '../contracts/index.js'\n\nexport interface UseStakeUPDConfig {\n /** Address of the sUPD contract. */\n supdAddress: Address\n}\n\nexport interface UseStakeUPDReturn {\n /** Execute the stake transaction. User must approve UPD transfer to sUPD first. */\n stake: (params: {\n updAmount: bigint\n attestation: PriceAttestationQuery\n }) => void\n isPending: boolean\n txHash: Hash | undefined\n isConfirming: boolean\n isConfirmed: boolean\n error: Error | null\n reset: () => void\n}\n\n/**\n * Write hook for staking UPD → sUPD.\n *\n * Note: The user must first approve the sUPD contract to spend their UPD tokens\n * (via UPDToken.approve or EIP-3009 transferWithAuthorization).\n *\n * @example\n * ```tsx\n * const { stake, isPending } = useStakeUPD({\n * supdAddress: deployment.contracts.sUPD,\n * })\n *\n * const { attestation } = useEthUsdPrice()\n *\n * <button onClick={() => stake({ updAmount: parseUnits('1000', 18), attestation })}>\n * Stake 1000 UPD\n * </button>\n * ```\n */\nexport function useStakeUPD(config: UseStakeUPDConfig): UseStakeUPDReturn {\n const { supdAddress } = config\n\n const {\n writeContract,\n data: txHash,\n isPending,\n error: writeError,\n reset,\n } = useWriteContract()\n\n const {\n isLoading: isConfirming,\n isSuccess: isConfirmed,\n } = useWaitForTransactionReceipt({ hash: txHash })\n\n function stake(params: {\n updAmount: bigint\n attestation: PriceAttestationQuery\n }) {\n writeContract({\n address: supdAddress,\n abi: SUPD_ABI,\n functionName: 'stakeUPD',\n args: [\n params.updAmount,\n {\n price: params.attestation.price,\n decimals: params.attestation.decimals,\n dataTimestamp: params.attestation.dataTimestamp,\n assetPair: params.attestation.assetPair,\n signature: params.attestation.signature,\n },\n ],\n })\n }\n\n return {\n stake,\n isPending,\n txHash,\n isConfirming,\n isConfirmed,\n error: writeError as Error | null,\n reset,\n }\n}\n","import { useWriteContract, useWaitForTransactionReceipt } from 'wagmi'\nimport type { Address, Hash } from 'viem'\nimport type { PriceAttestationQuery } from '../core/types.js'\nimport { SUPD_ABI } from '../contracts/index.js'\n\nexport interface UseUnstakeUPDConfig {\n /** Address of the sUPD contract. */\n supdAddress: Address\n}\n\nexport interface UseUnstakeUPDReturn {\n /** Execute the unstake transaction (unstakeToUPD — full redemption). */\n unstake: (params: {\n shares: bigint\n attestation: PriceAttestationQuery\n }) => void\n isPending: boolean\n txHash: Hash | undefined\n isConfirming: boolean\n isConfirmed: boolean\n error: Error | null\n reset: () => void\n}\n\n/**\n * Write hook for unstaking sUPD → UPD.\n *\n * Calls `unstakeToUPD(shares, priceQuery)` which gathers stETH from sUPD's\n * stabilizer escrows and mints fresh UPD to the caller.\n *\n * For advanced unstake variants (pro-rata, queued, with-extra-UPD), use the\n * contract ABI directly.\n *\n * @example\n * ```tsx\n * const { unstake, isPending } = useUnstakeUPD({\n * supdAddress: deployment.contracts.sUPD,\n * })\n *\n * const { attestation } = useEthUsdPrice()\n *\n * <button onClick={() => unstake({ shares: myShares, attestation })}>\n * Unstake\n * </button>\n * ```\n */\nexport function useUnstakeUPD(config: UseUnstakeUPDConfig): UseUnstakeUPDReturn {\n const { supdAddress } = config\n\n const {\n writeContract,\n data: txHash,\n isPending,\n error: writeError,\n reset,\n } = useWriteContract()\n\n const {\n isLoading: isConfirming,\n isSuccess: isConfirmed,\n } = useWaitForTransactionReceipt({ hash: txHash })\n\n function unstake(params: {\n shares: bigint\n attestation: PriceAttestationQuery\n }) {\n writeContract({\n address: supdAddress,\n abi: SUPD_ABI,\n functionName: 'unstakeToUPD',\n args: [\n params.shares,\n {\n price: params.attestation.price,\n decimals: params.attestation.decimals,\n dataTimestamp: params.attestation.dataTimestamp,\n assetPair: params.attestation.assetPair,\n signature: params.attestation.signature,\n },\n ],\n })\n }\n\n return {\n unstake,\n isPending,\n txHash,\n isConfirming,\n isConfirmed,\n error: writeError as Error | null,\n reset,\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/react/use-upd.ts","../../src/react/use-collateral.ts","../../src/react/use-stabilizer.ts","../../src/react/use-eth-usd-price.ts","../../src/react/use-mint-quote.ts","../../src/react/use-burn-quote.ts","../../src/react/use-mint-upd.ts","../../src/react/use-burn-upd.ts","../../src/react/use-system-health.ts","../../src/react/use-supd.ts","../../src/react/use-stake-upd.ts","../../src/react/use-unstake-upd.ts","../../src/react/use-swap-eth-to-upd.ts","../../src/react/use-swap-upd-to-steth.ts"],"names":["useReadContract","useMemo","useWriteContract","useWaitForTransactionReceipt"],"mappings":";;;;;;;;AAeO,SAAS,OAAO,MAAA,EAAoC;AACzD,EAAA,MAAM,EAAE,YAAA,EAAc,WAAA,EAAY,GAAI,MAAA;AAEtC,EAAA,MAAM,EAAE,IAAA,EAAM,OAAA,EAAS,SAAA,EAAW,cAAA,KAAmB,eAAA,CAAgB;AAAA,IACnE,OAAA,EAAS,YAAA;AAAA,IACT,GAAA,EAAK,aAAA;AAAA,IACL,YAAA,EAAc,WAAA;AAAA,IACd,IAAA,EAAM,WAAA,GAAc,CAAC,WAAW,CAAA,GAAI,MAAA;AAAA,IACpC,KAAA,EAAO,EAAE,OAAA,EAAS,CAAC,CAAC,WAAA;AAAY,GACjC,CAAA;AAED,EAAA,MAAM,EAAE,IAAA,EAAM,WAAA,EAAa,SAAA,EAAW,aAAA,KAAkB,eAAA,CAAgB;AAAA,IACtE,OAAA,EAAS,YAAA;AAAA,IACT,GAAA,EAAK,aAAA;AAAA,IACL,YAAA,EAAc;AAAA,GACf,CAAA;AAED,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,WAAA;AAAA,IACA,WAAW,cAAA,IAAkB;AAAA,GAC/B;AACF;ACrBO,SAAS,cAAc,MAAA,EAAkD;AAC9E,EAAA,MAAM,EAAE,eAAA,EAAiB,YAAA,EAAa,GAAI,MAAA;AAE1C,EAAA,MAAM,EAAE,IAAA,EAAM,oBAAA,EAAsB,SAAA,EAAW,iBAAA,KAC7CA,eAAAA,CAAgB;AAAA,IACd,OAAA,EAAS,eAAA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EAAA,EAAI,OAAO,MAAA;AACpD,MAAA,OAAO,YAAA,CAAa,WAAW,KAAK,CAAA;AAAA,IACtC,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,KAAK,CAAC,CAAA;AAEV,EAAA,SAAS,KAAK,MAAA,EAA+B;AAC3C,IAAA,IAAI,CAAC,oBAAA,IAAwB,CAAC,WAAA,EAAa;AAC3C,IAAA,aAAA,CAAc;AAAA,MACZ,OAAA,EAAS,oBAAA;AAAA,MACT,GAAA,EAAK,kBAAA;AAAA,MACL,YAAA,EAAc,SAAA;AAAA,MACd,IAAA,EAAM;AAAA,QACJ,MAAA,CAAO,SAAA;AAAA,QACP;AAAA,UACE,OAAO,WAAA,CAAY,KAAA;AAAA,UACnB,UAAU,WAAA,CAAY,QAAA;AAAA,UACtB,eAAe,WAAA,CAAY,aAAA;AAAA,UAC3B,WAAW,WAAA,CAAY,SAAA;AAAA,UACvB,WAAW,WAAA,CAAY;AAAA;AACzB;AACF,KACD,CAAA;AAAA,EACH;AAEA,EAAA,OAAO;AAAA,IACL,KAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,cAAA;AAAA,IACA,YAAA;AAAA,IACA,SAAA;AAAA,IACA,MAAA;AAAA,IACA,YAAA;AAAA,IACA,WAAA;AAAA,IACA,OAAQ,UAAA,IAAc,UAAA;AAAA,IACtB,KAAA;AAAA,IACA,OAAA,EAAS,CAAC,CAAC,oBAAA,IAAwB,CAAC,CAAC;AAAA,GACvC;AACF","file":"index.js","sourcesContent":["import { useReadContract } from 'wagmi'\nimport type { Address } from 'viem'\nimport { UPD_TOKEN_ABI } from '../contracts/index.js'\n\nexport interface UseUPDConfig {\n tokenAddress: Address\n userAddress?: Address\n}\n\nexport interface UseUPDReturn {\n balance: bigint | undefined\n totalSupply: bigint | undefined\n isLoading: boolean\n}\n\nexport function useUPD(config: UseUPDConfig): UseUPDReturn {\n const { tokenAddress, userAddress } = config\n\n const { data: balance, isLoading: balanceLoading } = useReadContract({\n address: tokenAddress,\n abi: UPD_TOKEN_ABI,\n functionName: 'balanceOf',\n args: userAddress ? [userAddress] : undefined,\n query: { enabled: !!userAddress },\n })\n\n const { data: totalSupply, isLoading: supplyLoading } = useReadContract({\n address: tokenAddress,\n abi: UPD_TOKEN_ABI,\n functionName: 'totalSupply',\n })\n\n return {\n balance: balance as bigint | undefined,\n totalSupply: totalSupply as bigint | undefined,\n isLoading: balanceLoading || supplyLoading,\n }\n}\n","import { useReadContract } from 'wagmi'\nimport type { Address } from 'viem'\nimport { OVERCOLLATERALIZATION_REPORTER_ABI } from '../contracts/index.js'\nimport { UPD_TOKEN_ABI } from '../contracts/index.js'\n\nexport interface UseCollateralConfig {\n reporterAddress: Address\n tokenAddress: Address\n}\n\nexport interface UseCollateralReturn {\n totalStEthCollateral: bigint | undefined\n totalUPDSupply: bigint | undefined\n isLoading: boolean\n}\n\nexport function useCollateral(config: UseCollateralConfig): UseCollateralReturn {\n const { reporterAddress, tokenAddress } = config\n\n const { data: totalStEthCollateral, isLoading: collateralLoading } =\n useReadContract({\n address: reporterAddress,\n abi: OVERCOLLATERALIZATION_REPORTER_ABI,\n functionName: 'getTotalStEthCollateral',\n })\n\n const { data: totalUPDSupply, isLoading: supplyLoading } = useReadContract({\n address: tokenAddress,\n abi: UPD_TOKEN_ABI,\n functionName: 'totalSupply',\n })\n\n return {\n totalStEthCollateral: totalStEthCollateral as bigint | undefined,\n totalUPDSupply: totalUPDSupply as bigint | undefined,\n isLoading: collateralLoading || supplyLoading,\n }\n}\n","import { useReadContract } from 'wagmi'\nimport type { Address } from 'viem'\nimport { STABILIZER_NFT_ABI } from '../contracts/index.js'\n\nexport interface UseStabilizerConfig {\n stabilizerNFTAddress: Address\n tokenId?: bigint\n}\n\nexport interface UseStabilizerReturn {\n positionEscrowAddress: Address | undefined\n stabilizerEscrowAddress: Address | undefined\n isLoading: boolean\n}\n\nexport function useStabilizer(\n config: UseStabilizerConfig,\n): UseStabilizerReturn {\n const { stabilizerNFTAddress, tokenId } = config\n\n const { data: positionEscrow, isLoading: posLoading } = useReadContract({\n address: stabilizerNFTAddress,\n abi: STABILIZER_NFT_ABI,\n functionName: 'positionEscrows',\n args: tokenId !== undefined ? [tokenId] : undefined,\n query: { enabled: tokenId !== undefined },\n })\n\n const { data: stabilizerEscrow, isLoading: stabLoading } = useReadContract({\n address: stabilizerNFTAddress,\n abi: STABILIZER_NFT_ABI,\n functionName: 'stabilizerEscrows',\n args: tokenId !== undefined ? [tokenId] : undefined,\n query: { enabled: tokenId !== undefined },\n })\n\n return {\n positionEscrowAddress: positionEscrow as Address | undefined,\n stabilizerEscrowAddress: stabilizerEscrow as Address | undefined,\n isLoading: posLoading || stabLoading,\n }\n}\n","import { useQuery } from '@tanstack/react-query'\nimport { createOracleClient } from '../oracle/client.js'\nimport type { PriceAttestationQuery } from '../core/types.js'\n\nexport interface UseEthUsdPriceConfig {\n /** Oracle service URL. Defaults to oracle.upd.io. */\n oracleUrl?: string\n /** Refetch interval in milliseconds. Defaults to 10000 (10s). */\n refetchInterval?: number\n /** Whether to enable the query. Defaults to true. */\n enabled?: boolean\n}\n\nexport interface UseEthUsdPriceReturn {\n /** Raw price in 18 decimals (e.g. 2000e18 = $2000). */\n price: bigint | undefined\n /** Human-readable formatted price string (e.g. \"$2,000.00\"). */\n priceFormatted: string\n /** Full signed attestation, ready to pass to mint/burn. */\n attestation: PriceAttestationQuery | undefined\n /** Whether the initial fetch is loading. */\n isLoading: boolean\n /** Error from the most recent fetch, if any. */\n error: Error | null\n /** Manually trigger a refetch. */\n refetch: () => void\n}\n\nfunction formatUsdPrice(price: bigint | undefined): string {\n if (price === undefined) return '--'\n const priceFloat = Number(price) / 1e18\n return new Intl.NumberFormat('en-US', {\n style: 'currency',\n currency: 'USD',\n minimumFractionDigits: 2,\n maximumFractionDigits: 2,\n }).format(priceFloat)\n}\n\nexport function useEthUsdPrice(config?: UseEthUsdPriceConfig): UseEthUsdPriceReturn {\n const oracleUrl = config?.oracleUrl\n const refetchInterval = config?.refetchInterval ?? 10_000\n const enabled = config?.enabled ?? true\n\n const oracle = createOracleClient({ oracleUrl })\n\n const { data, isLoading, error, refetch } = useQuery({\n queryKey: ['upd-oracle-eth-usd', oracleUrl],\n queryFn: () => oracle.getEthUsdAttestation(),\n refetchInterval,\n enabled,\n staleTime: 5_000,\n })\n\n return {\n price: data?.price,\n priceFormatted: formatUsdPrice(data?.price),\n attestation: data,\n isLoading,\n error: error as Error | null,\n refetch: () => { refetch() },\n }\n}\n","import { useMemo } from 'react'\nimport { useEthUsdPrice, type UseEthUsdPriceConfig } from './use-eth-usd-price.js'\nimport { quoteMintUPD } from '../core/quote.js'\n\nexport interface UseMintQuoteConfig extends UseEthUsdPriceConfig {}\n\nexport interface UseMintQuoteReturn {\n /** Expected UPD amount for the given ETH input (18 decimals). */\n updAmount: bigint | undefined\n /** Current ETH/USD price used for the quote (18 decimals). */\n ethUsdPrice: bigint | undefined\n /** Whether the price is still loading. */\n isLoading: boolean\n}\n\n/**\n * Real-time mint quote hook — composes oracle price + pure math.\n *\n * @param ethAmount - ETH amount to quote (in wei). Pass 0n to disable.\n * @param config - Optional oracle configuration.\n *\n * @example\n * ```tsx\n * const { updAmount, isLoading } = useMintQuote(parseEther('1'))\n * // updAmount ≈ 2000e18 (at $2000/ETH)\n * ```\n */\nexport function useMintQuote(\n ethAmount: bigint,\n config?: UseMintQuoteConfig,\n): UseMintQuoteReturn {\n const { price, isLoading } = useEthUsdPrice({\n ...config,\n enabled: ethAmount > 0n && (config?.enabled ?? true),\n })\n\n const updAmount = useMemo(() => {\n if (price === undefined || ethAmount === 0n) return undefined\n return quoteMintUPD(ethAmount, price)\n }, [ethAmount, price])\n\n return {\n updAmount,\n ethUsdPrice: price,\n isLoading,\n }\n}\n","import { useMemo } from 'react'\nimport { useEthUsdPrice, type UseEthUsdPriceConfig } from './use-eth-usd-price.js'\nimport { quoteBurnUPD } from '../core/quote.js'\n\nexport interface UseBurnQuoteConfig extends UseEthUsdPriceConfig {}\n\nexport interface UseBurnQuoteReturn {\n /** Expected stETH amount for the given UPD input (in wei). */\n stEthAmount: bigint | undefined\n /** Current ETH/USD price used for the quote (18 decimals). */\n ethUsdPrice: bigint | undefined\n /** Whether the price is still loading. */\n isLoading: boolean\n}\n\n/**\n * Real-time burn quote hook — composes oracle price + pure math.\n *\n * @param updAmount - UPD amount to quote (18 decimals). Pass 0n to disable.\n * @param config - Optional oracle configuration.\n *\n * @example\n * ```tsx\n * const { stEthAmount, isLoading } = useBurnQuote(parseUnits('2000', 18))\n * // stEthAmount ≈ 1e18 (at $2000/ETH)\n * ```\n */\nexport function useBurnQuote(\n updAmount: bigint,\n config?: UseBurnQuoteConfig,\n): UseBurnQuoteReturn {\n const { price, isLoading } = useEthUsdPrice({\n ...config,\n enabled: updAmount > 0n && (config?.enabled ?? true),\n })\n\n const stEthAmount = useMemo(() => {\n if (price === undefined || updAmount === 0n) return undefined\n return quoteBurnUPD(updAmount, price)\n }, [updAmount, price])\n\n return {\n stEthAmount,\n ethUsdPrice: price,\n isLoading,\n }\n}\n","import { useWriteContract, useWaitForTransactionReceipt } from 'wagmi'\nimport type { Address, Hash } from 'viem'\nimport type { PriceAttestationQuery } from '../core/types.js'\nimport { STABILIZER_NFT_ABI } from '../contracts/index.js'\n\nexport interface UseMintUPDConfig {\n /** Address of the StabilizerNFT contract. */\n stabilizerNFTAddress: Address\n}\n\nexport interface UseMintUPDReturn {\n /** Execute the mint transaction. */\n mint: (params: {\n to: Address\n ethAmount: bigint\n attestation: PriceAttestationQuery\n }) => void\n /** Whether the transaction is being sent. */\n isPending: boolean\n /** Transaction hash once submitted. */\n txHash: Hash | undefined\n /** Whether we're waiting for confirmation. */\n isConfirming: boolean\n /** Whether the transaction is confirmed. */\n isConfirmed: boolean\n /** Error from the transaction, if any. */\n error: Error | null\n /** Reset the mutation state. */\n reset: () => void\n}\n\n/**\n * Write hook for minting UPD by depositing ETH.\n *\n * @example\n * ```tsx\n * const { mint, isPending, isConfirmed, error } = useMintUPD({\n * stabilizerNFTAddress: deployment.contracts.StabilizerNFT,\n * })\n *\n * // Use with useEthUsdPrice to get attestation\n * const { attestation } = useEthUsdPrice()\n *\n * <button onClick={() => mint({ to: userAddress, ethAmount: parseEther('1'), attestation })}>\n * Mint UPD\n * </button>\n * ```\n */\nexport function useMintUPD(config: UseMintUPDConfig): UseMintUPDReturn {\n const { stabilizerNFTAddress } = config\n\n const {\n writeContract,\n data: txHash,\n isPending,\n error: writeError,\n reset,\n } = useWriteContract()\n\n const {\n isLoading: isConfirming,\n isSuccess: isConfirmed,\n } = useWaitForTransactionReceipt({\n hash: txHash,\n })\n\n function mint(params: {\n to: Address\n ethAmount: bigint\n attestation: PriceAttestationQuery\n }) {\n writeContract({\n address: stabilizerNFTAddress,\n abi: STABILIZER_NFT_ABI,\n functionName: 'mintUPD',\n args: [\n params.to,\n {\n price: params.attestation.price,\n decimals: params.attestation.decimals,\n dataTimestamp: params.attestation.dataTimestamp,\n assetPair: params.attestation.assetPair,\n signature: params.attestation.signature,\n },\n ],\n value: params.ethAmount,\n })\n }\n\n return {\n mint,\n isPending,\n txHash,\n isConfirming,\n isConfirmed,\n error: writeError as Error | null,\n reset,\n }\n}\n","import { useWriteContract, useWaitForTransactionReceipt } from 'wagmi'\nimport type { Address, Hash } from 'viem'\nimport type { PriceAttestationQuery } from '../core/types.js'\nimport { STABILIZER_NFT_ABI } from '../contracts/index.js'\n\nexport interface UseBurnUPDConfig {\n /** Address of the StabilizerNFT contract. */\n stabilizerNFTAddress: Address\n}\n\nexport interface UseBurnUPDReturn {\n /** Execute the burn transaction. */\n burn: (params: {\n updAmount: bigint\n attestation: PriceAttestationQuery\n }) => void\n /** Whether the transaction is being sent. */\n isPending: boolean\n /** Transaction hash once submitted. */\n txHash: Hash | undefined\n /** Whether we're waiting for confirmation. */\n isConfirming: boolean\n /** Whether the transaction is confirmed. */\n isConfirmed: boolean\n /** Error from the transaction, if any. */\n error: Error | null\n /** Reset the mutation state. */\n reset: () => void\n}\n\n/**\n * Write hook for burning UPD to receive stETH.\n *\n * @example\n * ```tsx\n * const { burn, isPending, isConfirmed } = useBurnUPD({\n * stabilizerNFTAddress: deployment.contracts.StabilizerNFT,\n * })\n *\n * const { attestation } = useEthUsdPrice()\n *\n * <button onClick={() => burn({ updAmount: parseUnits('1000', 18), attestation })}>\n * Burn 1000 UPD\n * </button>\n * ```\n */\nexport function useBurnUPD(config: UseBurnUPDConfig): UseBurnUPDReturn {\n const { stabilizerNFTAddress } = config\n\n const {\n writeContract,\n data: txHash,\n isPending,\n error: writeError,\n reset,\n } = useWriteContract()\n\n const {\n isLoading: isConfirming,\n isSuccess: isConfirmed,\n } = useWaitForTransactionReceipt({\n hash: txHash,\n })\n\n function burn(params: {\n updAmount: bigint\n attestation: PriceAttestationQuery\n }) {\n writeContract({\n address: stabilizerNFTAddress,\n abi: STABILIZER_NFT_ABI,\n functionName: 'burnUPD',\n args: [\n params.updAmount,\n {\n price: params.attestation.price,\n decimals: params.attestation.decimals,\n dataTimestamp: params.attestation.dataTimestamp,\n assetPair: params.attestation.assetPair,\n signature: params.attestation.signature,\n },\n ],\n })\n }\n\n return {\n burn,\n isPending,\n txHash,\n isConfirming,\n isConfirmed,\n error: writeError as Error | null,\n reset,\n }\n}\n","import { useMemo } from 'react'\nimport type { Address } from 'viem'\nimport { useCollateral, type UseCollateralConfig } from './use-collateral.js'\nimport { useEthUsdPrice, type UseEthUsdPriceConfig } from './use-eth-usd-price.js'\nimport { computeSystemHealth, type SystemHealth } from '../core/health.js'\n\nexport interface UseSystemHealthConfig {\n /** Address of the OvercollateralizationReporter contract. */\n reporterAddress: Address\n /** Address of the UPD token. */\n tokenAddress: Address\n /** Oracle service URL. */\n oracleUrl?: string\n /** Minimum collateral ratio in basis points (default: 12500 = 125%). */\n minRatioBps?: bigint\n}\n\nexport interface UseSystemHealthReturn {\n /** Computed system health metrics, or undefined if still loading. */\n health: SystemHealth | undefined\n /** Whether any underlying data is still loading. */\n isLoading: boolean\n}\n\n/**\n * System health hook — composes useCollateral + useEthUsdPrice + computeSystemHealth.\n *\n * @example\n * ```tsx\n * const { health, isLoading } = useSystemHealth({\n * reporterAddress: deployment.contracts.OvercollateralizationReporter,\n * tokenAddress: deployment.contracts.UPDToken,\n * })\n *\n * if (health && !health.isHealthy) {\n * return <Alert>System undercollateralized: {health.systemCollateralRatioBps} bps</Alert>\n * }\n * ```\n */\nexport function useSystemHealth(config: UseSystemHealthConfig): UseSystemHealthReturn {\n const collateralConfig: UseCollateralConfig = {\n reporterAddress: config.reporterAddress,\n tokenAddress: config.tokenAddress,\n }\n\n const priceConfig: UseEthUsdPriceConfig = {\n oracleUrl: config.oracleUrl,\n }\n\n const {\n totalStEthCollateral,\n totalUPDSupply,\n isLoading: collateralLoading,\n } = useCollateral(collateralConfig)\n\n const {\n price: ethUsdPrice,\n isLoading: priceLoading,\n } = useEthUsdPrice(priceConfig)\n\n const health = useMemo(() => {\n if (\n totalStEthCollateral === undefined ||\n totalUPDSupply === undefined ||\n ethUsdPrice === undefined\n ) {\n return undefined\n }\n\n return computeSystemHealth(\n { totalStEthCollateral, totalUPDSupply },\n ethUsdPrice,\n config.minRatioBps,\n )\n }, [totalStEthCollateral, totalUPDSupply, ethUsdPrice, config.minRatioBps])\n\n return {\n health,\n isLoading: collateralLoading || priceLoading,\n }\n}\n","import { useReadContract } from 'wagmi'\nimport type { Address } from 'viem'\nimport { SUPD_ABI } from '../contracts/index.js'\n\nexport interface UseSUPDConfig {\n /** Address of the sUPD contract. */\n supdAddress: Address\n /** User address to read balance for (optional). */\n userAddress?: Address\n}\n\nexport interface UseSUPDReturn {\n /** User's sUPD balance (18 decimals). */\n balance: bigint | undefined\n /** Total sUPD shares outstanding. */\n totalSupply: bigint | undefined\n /** Current share value with accrued yield (18 decimals). */\n shareValue: bigint | undefined\n /** Annual yield in basis points (e.g. 800 = 8%). */\n annualYieldBps: bigint | undefined\n /** Total USD liability of all outstanding sUPD. */\n totalLiabilityUSD: bigint | undefined\n /** Whether any read is still loading. */\n isLoading: boolean\n}\n\n/**\n * Read hook for sUPD — share value, APY, balances, and total liability.\n *\n * @example\n * ```tsx\n * const { balance, shareValue, annualYieldBps, isLoading } = useSUPD({\n * supdAddress: deployment.contracts.sUPD,\n * userAddress: account.address,\n * })\n * ```\n */\nexport function useSUPD(config: UseSUPDConfig): UseSUPDReturn {\n const { supdAddress, userAddress } = config\n\n const { data: balance, isLoading: balLoading } = useReadContract({\n address: supdAddress,\n abi: SUPD_ABI,\n functionName: 'balanceOf',\n args: userAddress ? [userAddress] : undefined,\n query: { enabled: !!userAddress },\n })\n\n const { data: totalSupply, isLoading: supplyLoading } = useReadContract({\n address: supdAddress,\n abi: SUPD_ABI,\n functionName: 'totalSupply',\n })\n\n const { data: shareValue, isLoading: svLoading } = useReadContract({\n address: supdAddress,\n abi: SUPD_ABI,\n functionName: 'currentShareValue',\n })\n\n const { data: annualYieldBps, isLoading: apyLoading } = useReadContract({\n address: supdAddress,\n abi: SUPD_ABI,\n functionName: 'annualYieldBps',\n })\n\n const { data: totalLiabilityUSD, isLoading: liabLoading } = useReadContract({\n address: supdAddress,\n abi: SUPD_ABI,\n functionName: 'totalLiabilityUSD',\n })\n\n return {\n balance: balance as bigint | undefined,\n totalSupply: totalSupply as bigint | undefined,\n shareValue: shareValue as bigint | undefined,\n annualYieldBps: annualYieldBps as bigint | undefined,\n totalLiabilityUSD: totalLiabilityUSD as bigint | undefined,\n isLoading: balLoading || supplyLoading || svLoading || apyLoading || liabLoading,\n }\n}\n","import { useWriteContract, useWaitForTransactionReceipt } from 'wagmi'\nimport type { Address, Hash } from 'viem'\nimport type { PriceAttestationQuery } from '../core/types.js'\nimport { SUPD_ABI } from '../contracts/index.js'\n\nexport interface UseStakeUPDConfig {\n /** Address of the sUPD contract. */\n supdAddress: Address\n}\n\nexport interface UseStakeUPDReturn {\n /** Execute the stake transaction. User must approve UPD transfer to sUPD first. */\n stake: (params: {\n updAmount: bigint\n attestation: PriceAttestationQuery\n }) => void\n isPending: boolean\n txHash: Hash | undefined\n isConfirming: boolean\n isConfirmed: boolean\n error: Error | null\n reset: () => void\n}\n\n/**\n * Write hook for staking UPD → sUPD.\n *\n * Note: The user must first approve the sUPD contract to spend their UPD tokens\n * (via UPDToken.approve or EIP-3009 transferWithAuthorization).\n *\n * @example\n * ```tsx\n * const { stake, isPending } = useStakeUPD({\n * supdAddress: deployment.contracts.sUPD,\n * })\n *\n * const { attestation } = useEthUsdPrice()\n *\n * <button onClick={() => stake({ updAmount: parseUnits('1000', 18), attestation })}>\n * Stake 1000 UPD\n * </button>\n * ```\n */\nexport function useStakeUPD(config: UseStakeUPDConfig): UseStakeUPDReturn {\n const { supdAddress } = config\n\n const {\n writeContract,\n data: txHash,\n isPending,\n error: writeError,\n reset,\n } = useWriteContract()\n\n const {\n isLoading: isConfirming,\n isSuccess: isConfirmed,\n } = useWaitForTransactionReceipt({ hash: txHash })\n\n function stake(params: {\n updAmount: bigint\n attestation: PriceAttestationQuery\n }) {\n writeContract({\n address: supdAddress,\n abi: SUPD_ABI,\n functionName: 'stakeUPD',\n args: [\n params.updAmount,\n {\n price: params.attestation.price,\n decimals: params.attestation.decimals,\n dataTimestamp: params.attestation.dataTimestamp,\n assetPair: params.attestation.assetPair,\n signature: params.attestation.signature,\n },\n ],\n })\n }\n\n return {\n stake,\n isPending,\n txHash,\n isConfirming,\n isConfirmed,\n error: writeError as Error | null,\n reset,\n }\n}\n","import { useWriteContract, useWaitForTransactionReceipt } from 'wagmi'\nimport type { Address, Hash } from 'viem'\nimport type { PriceAttestationQuery } from '../core/types.js'\nimport { SUPD_ABI } from '../contracts/index.js'\n\nexport interface UseUnstakeUPDConfig {\n /** Address of the sUPD contract. */\n supdAddress: Address\n}\n\nexport interface UseUnstakeUPDReturn {\n /** Execute the unstake transaction (unstakeToUPD — full redemption). */\n unstake: (params: {\n shares: bigint\n attestation: PriceAttestationQuery\n }) => void\n isPending: boolean\n txHash: Hash | undefined\n isConfirming: boolean\n isConfirmed: boolean\n error: Error | null\n reset: () => void\n}\n\n/**\n * Write hook for unstaking sUPD → UPD.\n *\n * Calls `unstakeToUPD(shares, priceQuery)` which gathers stETH from sUPD's\n * stabilizer escrows and mints fresh UPD to the caller.\n *\n * For advanced unstake variants (pro-rata, queued, with-extra-UPD), use the\n * contract ABI directly.\n *\n * @example\n * ```tsx\n * const { unstake, isPending } = useUnstakeUPD({\n * supdAddress: deployment.contracts.sUPD,\n * })\n *\n * const { attestation } = useEthUsdPrice()\n *\n * <button onClick={() => unstake({ shares: myShares, attestation })}>\n * Unstake\n * </button>\n * ```\n */\nexport function useUnstakeUPD(config: UseUnstakeUPDConfig): UseUnstakeUPDReturn {\n const { supdAddress } = config\n\n const {\n writeContract,\n data: txHash,\n isPending,\n error: writeError,\n reset,\n } = useWriteContract()\n\n const {\n isLoading: isConfirming,\n isSuccess: isConfirmed,\n } = useWaitForTransactionReceipt({ hash: txHash })\n\n function unstake(params: {\n shares: bigint\n attestation: PriceAttestationQuery\n }) {\n writeContract({\n address: supdAddress,\n abi: SUPD_ABI,\n functionName: 'unstakeToUPD',\n args: [\n params.shares,\n {\n price: params.attestation.price,\n decimals: params.attestation.decimals,\n dataTimestamp: params.attestation.dataTimestamp,\n assetPair: params.attestation.assetPair,\n signature: params.attestation.signature,\n },\n ],\n })\n }\n\n return {\n unstake,\n isPending,\n txHash,\n isConfirming,\n isConfirmed,\n error: writeError as Error | null,\n reset,\n }\n}\n","import { useMemo } from 'react'\nimport { useWriteContract, useWaitForTransactionReceipt } from 'wagmi'\nimport type { Address, Hash } from 'viem'\nimport { getDeployment } from '../deployments/index.js'\nimport { useEthUsdPrice, type UseEthUsdPriceConfig } from './use-eth-usd-price.js'\nimport { quoteMintUPD } from '../core/quote.js'\nimport { STABILIZER_NFT_ABI } from '../contracts/index.js'\n\nexport interface UseSwapEthToUPDConfig {\n /** Chain ID — contract addresses resolved automatically from deployment config. */\n chainId: number\n /** Oracle configuration (optional). */\n oracle?: UseEthUsdPriceConfig\n}\n\nexport interface UseSwapEthToUPDReturn {\n /** Compute expected UPD amount for a given ETH input. */\n quote: (ethAmount: bigint) => bigint | undefined\n /** Execute the mint: sends ETH, receives UPD. Oracle attestation handled internally. */\n mint: (params: { to: Address; ethAmount: bigint }) => void\n /** Current ETH/USD price (18 decimals). */\n price: bigint | undefined\n /** Formatted price string (e.g. \"$2,000.00\"). */\n priceFormatted: string\n /** Whether the oracle price is still loading. */\n priceLoading: boolean\n /** Whether the mint transaction is pending. */\n isPending: boolean\n /** Transaction hash once submitted. */\n txHash: Hash | undefined\n /** Whether we're waiting for on-chain confirmation. */\n isConfirming: boolean\n /** Whether the transaction is confirmed. */\n isConfirmed: boolean\n /** Error from oracle or transaction. */\n error: Error | null\n /** Reset the transaction state. */\n reset: () => void\n /** Whether the hook is ready (deployment exists + oracle loaded). */\n isReady: boolean\n}\n\n/**\n * One-stop hook for swapping ETH → UPD.\n *\n * Internally composes oracle price feed, quote computation, and StabilizerNFT.mintUPD.\n * Contract addresses are resolved from the deployment config — no manual wiring needed.\n *\n * @example\n * ```tsx\n * const { quote, mint, price, priceFormatted, isPending, isConfirmed } = useSwapEthToUPD({\n * chainId: 11155111,\n * })\n *\n * const expectedUPD = quote(parseEther('1'))\n *\n * <button onClick={() => mint({ to: address, ethAmount: parseEther('1') })}>\n * Mint {expectedUPD ? formatUnits(expectedUPD, 18) : '...'} UPD\n * </button>\n * ```\n */\nexport function useSwapEthToUPD(config: UseSwapEthToUPDConfig): UseSwapEthToUPDReturn {\n const deployment = getDeployment(config.chainId)\n const stabilizerNFTAddress = deployment?.contracts.StabilizerNFT\n\n const {\n price,\n priceFormatted,\n attestation,\n isLoading: priceLoading,\n error: priceError,\n } = useEthUsdPrice(config.oracle)\n\n const {\n writeContract,\n data: txHash,\n isPending,\n error: writeError,\n reset,\n } = useWriteContract()\n\n const {\n isLoading: isConfirming,\n isSuccess: isConfirmed,\n } = useWaitForTransactionReceipt({ hash: txHash })\n\n const quote = useMemo(() => {\n return (ethAmount: bigint): bigint | undefined => {\n if (price === undefined || ethAmount === 0n) return undefined\n return quoteMintUPD(ethAmount, price)\n }\n }, [price])\n\n function mint(params: { to: Address; ethAmount: bigint }) {\n if (!stabilizerNFTAddress || !attestation) return\n writeContract({\n address: stabilizerNFTAddress,\n abi: STABILIZER_NFT_ABI,\n functionName: 'mintUPD',\n args: [\n params.to,\n {\n price: attestation.price,\n decimals: attestation.decimals,\n dataTimestamp: attestation.dataTimestamp,\n assetPair: attestation.assetPair,\n signature: attestation.signature,\n },\n ],\n value: params.ethAmount,\n })\n }\n\n return {\n quote,\n mint,\n price,\n priceFormatted,\n priceLoading,\n isPending,\n txHash,\n isConfirming,\n isConfirmed,\n error: (writeError ?? priceError) as Error | null,\n reset,\n isReady: !!stabilizerNFTAddress && !!attestation,\n }\n}\n","import { useMemo } from 'react'\nimport { useWriteContract, useWaitForTransactionReceipt } from 'wagmi'\nimport type { Hash } from 'viem'\nimport { getDeployment } from '../deployments/index.js'\nimport { useEthUsdPrice, type UseEthUsdPriceConfig } from './use-eth-usd-price.js'\nimport { quoteBurnUPD } from '../core/quote.js'\nimport { STABILIZER_NFT_ABI } from '../contracts/index.js'\n\nexport interface UseSwapUPDToStETHConfig {\n /** Chain ID — contract addresses resolved automatically from deployment config. */\n chainId: number\n /** Oracle configuration (optional). */\n oracle?: UseEthUsdPriceConfig\n}\n\nexport interface UseSwapUPDToStETHReturn {\n /** Compute expected stETH amount for a given UPD input. */\n quote: (updAmount: bigint) => bigint | undefined\n /** Execute the burn: sends UPD, receives stETH. Oracle attestation handled internally. */\n burn: (params: { updAmount: bigint }) => void\n /** Current ETH/USD price (18 decimals). */\n price: bigint | undefined\n /** Formatted price string (e.g. \"$2,000.00\"). */\n priceFormatted: string\n /** Whether the oracle price is still loading. */\n priceLoading: boolean\n /** Whether the burn transaction is pending. */\n isPending: boolean\n /** Transaction hash once submitted. */\n txHash: Hash | undefined\n /** Whether we're waiting for on-chain confirmation. */\n isConfirming: boolean\n /** Whether the transaction is confirmed. */\n isConfirmed: boolean\n /** Error from oracle or transaction. */\n error: Error | null\n /** Reset the transaction state. */\n reset: () => void\n /** Whether the hook is ready (deployment exists + oracle loaded). */\n isReady: boolean\n}\n\n/**\n * One-stop hook for swapping UPD → stETH (burn).\n *\n * Internally composes oracle price feed, quote computation, and StabilizerNFT.burnUPD.\n * Contract addresses are resolved from the deployment config — no manual wiring needed.\n *\n * @example\n * ```tsx\n * const { quote, burn, priceFormatted, isPending, isConfirmed } = useSwapUPDToStETH({\n * chainId: 11155111,\n * })\n *\n * const expectedStETH = quote(parseUnits('1000', 18))\n *\n * <button onClick={() => burn({ updAmount: parseUnits('1000', 18) })}>\n * Burn for {expectedStETH ? formatUnits(expectedStETH, 18) : '...'} stETH\n * </button>\n * ```\n */\nexport function useSwapUPDToStETH(config: UseSwapUPDToStETHConfig): UseSwapUPDToStETHReturn {\n const deployment = getDeployment(config.chainId)\n const stabilizerNFTAddress = deployment?.contracts.StabilizerNFT\n\n const {\n price,\n priceFormatted,\n attestation,\n isLoading: priceLoading,\n error: priceError,\n } = useEthUsdPrice(config.oracle)\n\n const {\n writeContract,\n data: txHash,\n isPending,\n error: writeError,\n reset,\n } = useWriteContract()\n\n const {\n isLoading: isConfirming,\n isSuccess: isConfirmed,\n } = useWaitForTransactionReceipt({ hash: txHash })\n\n const quote = useMemo(() => {\n return (updAmount: bigint): bigint | undefined => {\n if (price === undefined || updAmount === 0n) return undefined\n return quoteBurnUPD(updAmount, price)\n }\n }, [price])\n\n function burn(params: { updAmount: bigint }) {\n if (!stabilizerNFTAddress || !attestation) return\n writeContract({\n address: stabilizerNFTAddress,\n abi: STABILIZER_NFT_ABI,\n functionName: 'burnUPD',\n args: [\n params.updAmount,\n {\n price: attestation.price,\n decimals: attestation.decimals,\n dataTimestamp: attestation.dataTimestamp,\n assetPair: attestation.assetPair,\n signature: attestation.signature,\n },\n ],\n })\n }\n\n return {\n quote,\n burn,\n price,\n priceFormatted,\n priceLoading,\n isPending,\n txHash,\n isConfirming,\n isConfirmed,\n error: (writeError ?? priceError) as Error | null,\n reset,\n isReady: !!stabilizerNFTAddress && !!attestation,\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@permissionless-technologies/upd-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Universal Private Dollar SDK — Non-rebasing stablecoin backed by stETH with stabilizer collateral management",
5
5
  "workspaces": [
6
6
  "packages/*"
@@ -50,6 +50,8 @@
50
50
  "generate:abis": "forge build && node scripts/generate-abis.js",
51
51
  "deploy:local": "node scripts/deploy.js 31337",
52
52
  "deploy:sepolia": "node scripts/deploy.js 11155111",
53
+ "deploy:supd:local": "node scripts/deploy-supd.js 31337",
54
+ "deploy:supd:sepolia": "node scripts/deploy-supd.js 11155111",
53
55
  "prepublishOnly": "npm run build"
54
56
  },
55
57
  "keywords": [