@permissionless-technologies/upd-sdk 0.1.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.
- package/README.md +172 -0
- package/dist/chunk-4RBWWS2X.js +6616 -0
- package/dist/chunk-4RBWWS2X.js.map +1 -0
- package/dist/chunk-4VXNJTNQ.cjs +58 -0
- package/dist/chunk-4VXNJTNQ.cjs.map +1 -0
- package/dist/chunk-5NNXIJE4.js +16 -0
- package/dist/chunk-5NNXIJE4.js.map +1 -0
- package/dist/chunk-63FIKV36.js +49 -0
- package/dist/chunk-63FIKV36.js.map +1 -0
- package/dist/chunk-CZEDT3MS.cjs +62 -0
- package/dist/chunk-CZEDT3MS.cjs.map +1 -0
- package/dist/chunk-DF34ON56.cjs +18 -0
- package/dist/chunk-DF34ON56.cjs.map +1 -0
- package/dist/chunk-DJBU2OEB.js +57 -0
- package/dist/chunk-DJBU2OEB.js.map +1 -0
- package/dist/chunk-LNGWRYGY.js +3 -0
- package/dist/chunk-LNGWRYGY.js.map +1 -0
- package/dist/chunk-POBNO37G.cjs +4 -0
- package/dist/chunk-POBNO37G.cjs.map +1 -0
- package/dist/chunk-R64I3LAO.js +701 -0
- package/dist/chunk-R64I3LAO.js.map +1 -0
- package/dist/chunk-RIRT4JX6.js +1808 -0
- package/dist/chunk-RIRT4JX6.js.map +1 -0
- package/dist/chunk-WRPVPA7E.cjs +713 -0
- package/dist/chunk-WRPVPA7E.cjs.map +1 -0
- package/dist/chunk-ZDAHLZWC.cjs +1812 -0
- package/dist/chunk-ZDAHLZWC.cjs.map +1 -0
- package/dist/chunk-ZSWETUGH.cjs +6623 -0
- package/dist/chunk-ZSWETUGH.cjs.map +1 -0
- package/dist/constants-Bk2bGYfX.d.ts +64 -0
- package/dist/constants-BlOP_9dy.d.cts +64 -0
- package/dist/contracts/index.cjs +45 -0
- package/dist/contracts/index.cjs.map +1 -0
- package/dist/contracts/index.d.cts +6559 -0
- package/dist/contracts/index.d.ts +6559 -0
- package/dist/contracts/index.js +4 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/core/index.cjs +76 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +5 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +7 -0
- package/dist/core/index.js.map +1 -0
- package/dist/health-BUb4ItNt.d.ts +46 -0
- package/dist/health-DPxBqH7b.d.cts +46 -0
- package/dist/index-XNClksom.d.ts +415 -0
- package/dist/index-yRBqVOHV.d.cts +415 -0
- package/dist/index.cjs +138 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/oracle/index.cjs +30 -0
- package/dist/oracle/index.cjs.map +1 -0
- package/dist/oracle/index.d.cts +41 -0
- package/dist/oracle/index.d.ts +41 -0
- package/dist/oracle/index.js +5 -0
- package/dist/oracle/index.js.map +1 -0
- package/dist/react/index.cjs +383 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +339 -0
- package/dist/react/index.d.ts +339 -0
- package/dist/react/index.js +370 -0
- package/dist/react/index.js.map +1 -0
- package/dist/types-DySv82My.d.cts +70 -0
- package/dist/types-DySv82My.d.ts +70 -0
- package/package.json +93 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { Address, Hash } from 'viem';
|
|
2
|
+
import { P as PriceAttestationQuery } from '../types-DySv82My.cjs';
|
|
3
|
+
import { S as SystemHealth } from '../health-DPxBqH7b.cjs';
|
|
4
|
+
|
|
5
|
+
interface UseUPDConfig {
|
|
6
|
+
tokenAddress: Address;
|
|
7
|
+
userAddress?: Address;
|
|
8
|
+
}
|
|
9
|
+
interface UseUPDReturn {
|
|
10
|
+
balance: bigint | undefined;
|
|
11
|
+
totalSupply: bigint | undefined;
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
}
|
|
14
|
+
declare function useUPD(config: UseUPDConfig): UseUPDReturn;
|
|
15
|
+
|
|
16
|
+
interface UseCollateralConfig {
|
|
17
|
+
reporterAddress: Address;
|
|
18
|
+
tokenAddress: Address;
|
|
19
|
+
}
|
|
20
|
+
interface UseCollateralReturn {
|
|
21
|
+
totalStEthCollateral: bigint | undefined;
|
|
22
|
+
totalUPDSupply: bigint | undefined;
|
|
23
|
+
isLoading: boolean;
|
|
24
|
+
}
|
|
25
|
+
declare function useCollateral(config: UseCollateralConfig): UseCollateralReturn;
|
|
26
|
+
|
|
27
|
+
interface UseStabilizerConfig {
|
|
28
|
+
stabilizerNFTAddress: Address;
|
|
29
|
+
tokenId?: bigint;
|
|
30
|
+
}
|
|
31
|
+
interface UseStabilizerReturn {
|
|
32
|
+
positionEscrowAddress: Address | undefined;
|
|
33
|
+
stabilizerEscrowAddress: Address | undefined;
|
|
34
|
+
isLoading: boolean;
|
|
35
|
+
}
|
|
36
|
+
declare function useStabilizer(config: UseStabilizerConfig): UseStabilizerReturn;
|
|
37
|
+
|
|
38
|
+
interface UseEthUsdPriceConfig {
|
|
39
|
+
/** Oracle service URL. Defaults to oracle.upd.io. */
|
|
40
|
+
oracleUrl?: string;
|
|
41
|
+
/** Refetch interval in milliseconds. Defaults to 10000 (10s). */
|
|
42
|
+
refetchInterval?: number;
|
|
43
|
+
/** Whether to enable the query. Defaults to true. */
|
|
44
|
+
enabled?: boolean;
|
|
45
|
+
}
|
|
46
|
+
interface UseEthUsdPriceReturn {
|
|
47
|
+
/** Raw price in 18 decimals (e.g. 2000e18 = $2000). */
|
|
48
|
+
price: bigint | undefined;
|
|
49
|
+
/** Human-readable formatted price string (e.g. "$2,000.00"). */
|
|
50
|
+
priceFormatted: string;
|
|
51
|
+
/** Full signed attestation, ready to pass to mint/burn. */
|
|
52
|
+
attestation: PriceAttestationQuery | undefined;
|
|
53
|
+
/** Whether the initial fetch is loading. */
|
|
54
|
+
isLoading: boolean;
|
|
55
|
+
/** Error from the most recent fetch, if any. */
|
|
56
|
+
error: Error | null;
|
|
57
|
+
/** Manually trigger a refetch. */
|
|
58
|
+
refetch: () => void;
|
|
59
|
+
}
|
|
60
|
+
declare function useEthUsdPrice(config?: UseEthUsdPriceConfig): UseEthUsdPriceReturn;
|
|
61
|
+
|
|
62
|
+
interface UseMintQuoteConfig extends UseEthUsdPriceConfig {
|
|
63
|
+
}
|
|
64
|
+
interface UseMintQuoteReturn {
|
|
65
|
+
/** Expected UPD amount for the given ETH input (18 decimals). */
|
|
66
|
+
updAmount: bigint | undefined;
|
|
67
|
+
/** Current ETH/USD price used for the quote (18 decimals). */
|
|
68
|
+
ethUsdPrice: bigint | undefined;
|
|
69
|
+
/** Whether the price is still loading. */
|
|
70
|
+
isLoading: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Real-time mint quote hook — composes oracle price + pure math.
|
|
74
|
+
*
|
|
75
|
+
* @param ethAmount - ETH amount to quote (in wei). Pass 0n to disable.
|
|
76
|
+
* @param config - Optional oracle configuration.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```tsx
|
|
80
|
+
* const { updAmount, isLoading } = useMintQuote(parseEther('1'))
|
|
81
|
+
* // updAmount ≈ 2000e18 (at $2000/ETH)
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
declare function useMintQuote(ethAmount: bigint, config?: UseMintQuoteConfig): UseMintQuoteReturn;
|
|
85
|
+
|
|
86
|
+
interface UseBurnQuoteConfig extends UseEthUsdPriceConfig {
|
|
87
|
+
}
|
|
88
|
+
interface UseBurnQuoteReturn {
|
|
89
|
+
/** Expected stETH amount for the given UPD input (in wei). */
|
|
90
|
+
stEthAmount: bigint | undefined;
|
|
91
|
+
/** Current ETH/USD price used for the quote (18 decimals). */
|
|
92
|
+
ethUsdPrice: bigint | undefined;
|
|
93
|
+
/** Whether the price is still loading. */
|
|
94
|
+
isLoading: boolean;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Real-time burn quote hook — composes oracle price + pure math.
|
|
98
|
+
*
|
|
99
|
+
* @param updAmount - UPD amount to quote (18 decimals). Pass 0n to disable.
|
|
100
|
+
* @param config - Optional oracle configuration.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```tsx
|
|
104
|
+
* const { stEthAmount, isLoading } = useBurnQuote(parseUnits('2000', 18))
|
|
105
|
+
* // stEthAmount ≈ 1e18 (at $2000/ETH)
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
declare function useBurnQuote(updAmount: bigint, config?: UseBurnQuoteConfig): UseBurnQuoteReturn;
|
|
109
|
+
|
|
110
|
+
interface UseMintUPDConfig {
|
|
111
|
+
/** Address of the StabilizerNFT contract. */
|
|
112
|
+
stabilizerNFTAddress: Address;
|
|
113
|
+
}
|
|
114
|
+
interface UseMintUPDReturn {
|
|
115
|
+
/** Execute the mint transaction. */
|
|
116
|
+
mint: (params: {
|
|
117
|
+
to: Address;
|
|
118
|
+
ethAmount: bigint;
|
|
119
|
+
attestation: PriceAttestationQuery;
|
|
120
|
+
}) => void;
|
|
121
|
+
/** Whether the transaction is being sent. */
|
|
122
|
+
isPending: boolean;
|
|
123
|
+
/** Transaction hash once submitted. */
|
|
124
|
+
txHash: Hash | undefined;
|
|
125
|
+
/** Whether we're waiting for confirmation. */
|
|
126
|
+
isConfirming: boolean;
|
|
127
|
+
/** Whether the transaction is confirmed. */
|
|
128
|
+
isConfirmed: boolean;
|
|
129
|
+
/** Error from the transaction, if any. */
|
|
130
|
+
error: Error | null;
|
|
131
|
+
/** Reset the mutation state. */
|
|
132
|
+
reset: () => void;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Write hook for minting UPD by depositing ETH.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```tsx
|
|
139
|
+
* const { mint, isPending, isConfirmed, error } = useMintUPD({
|
|
140
|
+
* stabilizerNFTAddress: deployment.contracts.StabilizerNFT,
|
|
141
|
+
* })
|
|
142
|
+
*
|
|
143
|
+
* // Use with useEthUsdPrice to get attestation
|
|
144
|
+
* const { attestation } = useEthUsdPrice()
|
|
145
|
+
*
|
|
146
|
+
* <button onClick={() => mint({ to: userAddress, ethAmount: parseEther('1'), attestation })}>
|
|
147
|
+
* Mint UPD
|
|
148
|
+
* </button>
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
declare function useMintUPD(config: UseMintUPDConfig): UseMintUPDReturn;
|
|
152
|
+
|
|
153
|
+
interface UseBurnUPDConfig {
|
|
154
|
+
/** Address of the StabilizerNFT contract. */
|
|
155
|
+
stabilizerNFTAddress: Address;
|
|
156
|
+
}
|
|
157
|
+
interface UseBurnUPDReturn {
|
|
158
|
+
/** Execute the burn transaction. */
|
|
159
|
+
burn: (params: {
|
|
160
|
+
updAmount: bigint;
|
|
161
|
+
attestation: PriceAttestationQuery;
|
|
162
|
+
}) => void;
|
|
163
|
+
/** Whether the transaction is being sent. */
|
|
164
|
+
isPending: boolean;
|
|
165
|
+
/** Transaction hash once submitted. */
|
|
166
|
+
txHash: Hash | undefined;
|
|
167
|
+
/** Whether we're waiting for confirmation. */
|
|
168
|
+
isConfirming: boolean;
|
|
169
|
+
/** Whether the transaction is confirmed. */
|
|
170
|
+
isConfirmed: boolean;
|
|
171
|
+
/** Error from the transaction, if any. */
|
|
172
|
+
error: Error | null;
|
|
173
|
+
/** Reset the mutation state. */
|
|
174
|
+
reset: () => void;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Write hook for burning UPD to receive stETH.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```tsx
|
|
181
|
+
* const { burn, isPending, isConfirmed } = useBurnUPD({
|
|
182
|
+
* stabilizerNFTAddress: deployment.contracts.StabilizerNFT,
|
|
183
|
+
* })
|
|
184
|
+
*
|
|
185
|
+
* const { attestation } = useEthUsdPrice()
|
|
186
|
+
*
|
|
187
|
+
* <button onClick={() => burn({ updAmount: parseUnits('1000', 18), attestation })}>
|
|
188
|
+
* Burn 1000 UPD
|
|
189
|
+
* </button>
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
declare function useBurnUPD(config: UseBurnUPDConfig): UseBurnUPDReturn;
|
|
193
|
+
|
|
194
|
+
interface UseSystemHealthConfig {
|
|
195
|
+
/** Address of the OvercollateralizationReporter contract. */
|
|
196
|
+
reporterAddress: Address;
|
|
197
|
+
/** Address of the UPD token. */
|
|
198
|
+
tokenAddress: Address;
|
|
199
|
+
/** Oracle service URL. */
|
|
200
|
+
oracleUrl?: string;
|
|
201
|
+
/** Minimum collateral ratio in basis points (default: 12500 = 125%). */
|
|
202
|
+
minRatioBps?: bigint;
|
|
203
|
+
}
|
|
204
|
+
interface UseSystemHealthReturn {
|
|
205
|
+
/** Computed system health metrics, or undefined if still loading. */
|
|
206
|
+
health: SystemHealth | undefined;
|
|
207
|
+
/** Whether any underlying data is still loading. */
|
|
208
|
+
isLoading: boolean;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* System health hook — composes useCollateral + useEthUsdPrice + computeSystemHealth.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```tsx
|
|
215
|
+
* const { health, isLoading } = useSystemHealth({
|
|
216
|
+
* reporterAddress: deployment.contracts.OvercollateralizationReporter,
|
|
217
|
+
* tokenAddress: deployment.contracts.UPDToken,
|
|
218
|
+
* })
|
|
219
|
+
*
|
|
220
|
+
* if (health && !health.isHealthy) {
|
|
221
|
+
* return <Alert>System undercollateralized: {health.systemCollateralRatioBps} bps</Alert>
|
|
222
|
+
* }
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
declare function useSystemHealth(config: UseSystemHealthConfig): UseSystemHealthReturn;
|
|
226
|
+
|
|
227
|
+
interface UseSUPDConfig {
|
|
228
|
+
/** Address of the sUPD contract. */
|
|
229
|
+
supdAddress: Address;
|
|
230
|
+
/** User address to read balance for (optional). */
|
|
231
|
+
userAddress?: Address;
|
|
232
|
+
}
|
|
233
|
+
interface UseSUPDReturn {
|
|
234
|
+
/** User's sUPD balance (18 decimals). */
|
|
235
|
+
balance: bigint | undefined;
|
|
236
|
+
/** Total sUPD shares outstanding. */
|
|
237
|
+
totalSupply: bigint | undefined;
|
|
238
|
+
/** Current share value with accrued yield (18 decimals). */
|
|
239
|
+
shareValue: bigint | undefined;
|
|
240
|
+
/** Annual yield in basis points (e.g. 800 = 8%). */
|
|
241
|
+
annualYieldBps: bigint | undefined;
|
|
242
|
+
/** Total USD liability of all outstanding sUPD. */
|
|
243
|
+
totalLiabilityUSD: bigint | undefined;
|
|
244
|
+
/** Whether any read is still loading. */
|
|
245
|
+
isLoading: boolean;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Read hook for sUPD — share value, APY, balances, and total liability.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```tsx
|
|
252
|
+
* const { balance, shareValue, annualYieldBps, isLoading } = useSUPD({
|
|
253
|
+
* supdAddress: deployment.contracts.sUPD,
|
|
254
|
+
* userAddress: account.address,
|
|
255
|
+
* })
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
declare function useSUPD(config: UseSUPDConfig): UseSUPDReturn;
|
|
259
|
+
|
|
260
|
+
interface UseStakeUPDConfig {
|
|
261
|
+
/** Address of the sUPD contract. */
|
|
262
|
+
supdAddress: Address;
|
|
263
|
+
}
|
|
264
|
+
interface UseStakeUPDReturn {
|
|
265
|
+
/** Execute the stake transaction. User must approve UPD transfer to sUPD first. */
|
|
266
|
+
stake: (params: {
|
|
267
|
+
updAmount: bigint;
|
|
268
|
+
attestation: PriceAttestationQuery;
|
|
269
|
+
}) => void;
|
|
270
|
+
isPending: boolean;
|
|
271
|
+
txHash: Hash | undefined;
|
|
272
|
+
isConfirming: boolean;
|
|
273
|
+
isConfirmed: boolean;
|
|
274
|
+
error: Error | null;
|
|
275
|
+
reset: () => void;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Write hook for staking UPD → sUPD.
|
|
279
|
+
*
|
|
280
|
+
* Note: The user must first approve the sUPD contract to spend their UPD tokens
|
|
281
|
+
* (via UPDToken.approve or EIP-3009 transferWithAuthorization).
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```tsx
|
|
285
|
+
* const { stake, isPending } = useStakeUPD({
|
|
286
|
+
* supdAddress: deployment.contracts.sUPD,
|
|
287
|
+
* })
|
|
288
|
+
*
|
|
289
|
+
* const { attestation } = useEthUsdPrice()
|
|
290
|
+
*
|
|
291
|
+
* <button onClick={() => stake({ updAmount: parseUnits('1000', 18), attestation })}>
|
|
292
|
+
* Stake 1000 UPD
|
|
293
|
+
* </button>
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
declare function useStakeUPD(config: UseStakeUPDConfig): UseStakeUPDReturn;
|
|
297
|
+
|
|
298
|
+
interface UseUnstakeUPDConfig {
|
|
299
|
+
/** Address of the sUPD contract. */
|
|
300
|
+
supdAddress: Address;
|
|
301
|
+
}
|
|
302
|
+
interface UseUnstakeUPDReturn {
|
|
303
|
+
/** Execute the unstake transaction (unstakeToUPD — full redemption). */
|
|
304
|
+
unstake: (params: {
|
|
305
|
+
shares: bigint;
|
|
306
|
+
attestation: PriceAttestationQuery;
|
|
307
|
+
}) => void;
|
|
308
|
+
isPending: boolean;
|
|
309
|
+
txHash: Hash | undefined;
|
|
310
|
+
isConfirming: boolean;
|
|
311
|
+
isConfirmed: boolean;
|
|
312
|
+
error: Error | null;
|
|
313
|
+
reset: () => void;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Write hook for unstaking sUPD → UPD.
|
|
317
|
+
*
|
|
318
|
+
* Calls `unstakeToUPD(shares, priceQuery)` which gathers stETH from sUPD's
|
|
319
|
+
* stabilizer escrows and mints fresh UPD to the caller.
|
|
320
|
+
*
|
|
321
|
+
* For advanced unstake variants (pro-rata, queued, with-extra-UPD), use the
|
|
322
|
+
* contract ABI directly.
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```tsx
|
|
326
|
+
* const { unstake, isPending } = useUnstakeUPD({
|
|
327
|
+
* supdAddress: deployment.contracts.sUPD,
|
|
328
|
+
* })
|
|
329
|
+
*
|
|
330
|
+
* const { attestation } = useEthUsdPrice()
|
|
331
|
+
*
|
|
332
|
+
* <button onClick={() => unstake({ shares: myShares, attestation })}>
|
|
333
|
+
* Unstake
|
|
334
|
+
* </button>
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
declare function useUnstakeUPD(config: UseUnstakeUPDConfig): UseUnstakeUPDReturn;
|
|
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 };
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { Address, Hash } from 'viem';
|
|
2
|
+
import { P as PriceAttestationQuery } from '../types-DySv82My.js';
|
|
3
|
+
import { S as SystemHealth } from '../health-BUb4ItNt.js';
|
|
4
|
+
|
|
5
|
+
interface UseUPDConfig {
|
|
6
|
+
tokenAddress: Address;
|
|
7
|
+
userAddress?: Address;
|
|
8
|
+
}
|
|
9
|
+
interface UseUPDReturn {
|
|
10
|
+
balance: bigint | undefined;
|
|
11
|
+
totalSupply: bigint | undefined;
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
}
|
|
14
|
+
declare function useUPD(config: UseUPDConfig): UseUPDReturn;
|
|
15
|
+
|
|
16
|
+
interface UseCollateralConfig {
|
|
17
|
+
reporterAddress: Address;
|
|
18
|
+
tokenAddress: Address;
|
|
19
|
+
}
|
|
20
|
+
interface UseCollateralReturn {
|
|
21
|
+
totalStEthCollateral: bigint | undefined;
|
|
22
|
+
totalUPDSupply: bigint | undefined;
|
|
23
|
+
isLoading: boolean;
|
|
24
|
+
}
|
|
25
|
+
declare function useCollateral(config: UseCollateralConfig): UseCollateralReturn;
|
|
26
|
+
|
|
27
|
+
interface UseStabilizerConfig {
|
|
28
|
+
stabilizerNFTAddress: Address;
|
|
29
|
+
tokenId?: bigint;
|
|
30
|
+
}
|
|
31
|
+
interface UseStabilizerReturn {
|
|
32
|
+
positionEscrowAddress: Address | undefined;
|
|
33
|
+
stabilizerEscrowAddress: Address | undefined;
|
|
34
|
+
isLoading: boolean;
|
|
35
|
+
}
|
|
36
|
+
declare function useStabilizer(config: UseStabilizerConfig): UseStabilizerReturn;
|
|
37
|
+
|
|
38
|
+
interface UseEthUsdPriceConfig {
|
|
39
|
+
/** Oracle service URL. Defaults to oracle.upd.io. */
|
|
40
|
+
oracleUrl?: string;
|
|
41
|
+
/** Refetch interval in milliseconds. Defaults to 10000 (10s). */
|
|
42
|
+
refetchInterval?: number;
|
|
43
|
+
/** Whether to enable the query. Defaults to true. */
|
|
44
|
+
enabled?: boolean;
|
|
45
|
+
}
|
|
46
|
+
interface UseEthUsdPriceReturn {
|
|
47
|
+
/** Raw price in 18 decimals (e.g. 2000e18 = $2000). */
|
|
48
|
+
price: bigint | undefined;
|
|
49
|
+
/** Human-readable formatted price string (e.g. "$2,000.00"). */
|
|
50
|
+
priceFormatted: string;
|
|
51
|
+
/** Full signed attestation, ready to pass to mint/burn. */
|
|
52
|
+
attestation: PriceAttestationQuery | undefined;
|
|
53
|
+
/** Whether the initial fetch is loading. */
|
|
54
|
+
isLoading: boolean;
|
|
55
|
+
/** Error from the most recent fetch, if any. */
|
|
56
|
+
error: Error | null;
|
|
57
|
+
/** Manually trigger a refetch. */
|
|
58
|
+
refetch: () => void;
|
|
59
|
+
}
|
|
60
|
+
declare function useEthUsdPrice(config?: UseEthUsdPriceConfig): UseEthUsdPriceReturn;
|
|
61
|
+
|
|
62
|
+
interface UseMintQuoteConfig extends UseEthUsdPriceConfig {
|
|
63
|
+
}
|
|
64
|
+
interface UseMintQuoteReturn {
|
|
65
|
+
/** Expected UPD amount for the given ETH input (18 decimals). */
|
|
66
|
+
updAmount: bigint | undefined;
|
|
67
|
+
/** Current ETH/USD price used for the quote (18 decimals). */
|
|
68
|
+
ethUsdPrice: bigint | undefined;
|
|
69
|
+
/** Whether the price is still loading. */
|
|
70
|
+
isLoading: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Real-time mint quote hook — composes oracle price + pure math.
|
|
74
|
+
*
|
|
75
|
+
* @param ethAmount - ETH amount to quote (in wei). Pass 0n to disable.
|
|
76
|
+
* @param config - Optional oracle configuration.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```tsx
|
|
80
|
+
* const { updAmount, isLoading } = useMintQuote(parseEther('1'))
|
|
81
|
+
* // updAmount ≈ 2000e18 (at $2000/ETH)
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
declare function useMintQuote(ethAmount: bigint, config?: UseMintQuoteConfig): UseMintQuoteReturn;
|
|
85
|
+
|
|
86
|
+
interface UseBurnQuoteConfig extends UseEthUsdPriceConfig {
|
|
87
|
+
}
|
|
88
|
+
interface UseBurnQuoteReturn {
|
|
89
|
+
/** Expected stETH amount for the given UPD input (in wei). */
|
|
90
|
+
stEthAmount: bigint | undefined;
|
|
91
|
+
/** Current ETH/USD price used for the quote (18 decimals). */
|
|
92
|
+
ethUsdPrice: bigint | undefined;
|
|
93
|
+
/** Whether the price is still loading. */
|
|
94
|
+
isLoading: boolean;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Real-time burn quote hook — composes oracle price + pure math.
|
|
98
|
+
*
|
|
99
|
+
* @param updAmount - UPD amount to quote (18 decimals). Pass 0n to disable.
|
|
100
|
+
* @param config - Optional oracle configuration.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```tsx
|
|
104
|
+
* const { stEthAmount, isLoading } = useBurnQuote(parseUnits('2000', 18))
|
|
105
|
+
* // stEthAmount ≈ 1e18 (at $2000/ETH)
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
declare function useBurnQuote(updAmount: bigint, config?: UseBurnQuoteConfig): UseBurnQuoteReturn;
|
|
109
|
+
|
|
110
|
+
interface UseMintUPDConfig {
|
|
111
|
+
/** Address of the StabilizerNFT contract. */
|
|
112
|
+
stabilizerNFTAddress: Address;
|
|
113
|
+
}
|
|
114
|
+
interface UseMintUPDReturn {
|
|
115
|
+
/** Execute the mint transaction. */
|
|
116
|
+
mint: (params: {
|
|
117
|
+
to: Address;
|
|
118
|
+
ethAmount: bigint;
|
|
119
|
+
attestation: PriceAttestationQuery;
|
|
120
|
+
}) => void;
|
|
121
|
+
/** Whether the transaction is being sent. */
|
|
122
|
+
isPending: boolean;
|
|
123
|
+
/** Transaction hash once submitted. */
|
|
124
|
+
txHash: Hash | undefined;
|
|
125
|
+
/** Whether we're waiting for confirmation. */
|
|
126
|
+
isConfirming: boolean;
|
|
127
|
+
/** Whether the transaction is confirmed. */
|
|
128
|
+
isConfirmed: boolean;
|
|
129
|
+
/** Error from the transaction, if any. */
|
|
130
|
+
error: Error | null;
|
|
131
|
+
/** Reset the mutation state. */
|
|
132
|
+
reset: () => void;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Write hook for minting UPD by depositing ETH.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```tsx
|
|
139
|
+
* const { mint, isPending, isConfirmed, error } = useMintUPD({
|
|
140
|
+
* stabilizerNFTAddress: deployment.contracts.StabilizerNFT,
|
|
141
|
+
* })
|
|
142
|
+
*
|
|
143
|
+
* // Use with useEthUsdPrice to get attestation
|
|
144
|
+
* const { attestation } = useEthUsdPrice()
|
|
145
|
+
*
|
|
146
|
+
* <button onClick={() => mint({ to: userAddress, ethAmount: parseEther('1'), attestation })}>
|
|
147
|
+
* Mint UPD
|
|
148
|
+
* </button>
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
declare function useMintUPD(config: UseMintUPDConfig): UseMintUPDReturn;
|
|
152
|
+
|
|
153
|
+
interface UseBurnUPDConfig {
|
|
154
|
+
/** Address of the StabilizerNFT contract. */
|
|
155
|
+
stabilizerNFTAddress: Address;
|
|
156
|
+
}
|
|
157
|
+
interface UseBurnUPDReturn {
|
|
158
|
+
/** Execute the burn transaction. */
|
|
159
|
+
burn: (params: {
|
|
160
|
+
updAmount: bigint;
|
|
161
|
+
attestation: PriceAttestationQuery;
|
|
162
|
+
}) => void;
|
|
163
|
+
/** Whether the transaction is being sent. */
|
|
164
|
+
isPending: boolean;
|
|
165
|
+
/** Transaction hash once submitted. */
|
|
166
|
+
txHash: Hash | undefined;
|
|
167
|
+
/** Whether we're waiting for confirmation. */
|
|
168
|
+
isConfirming: boolean;
|
|
169
|
+
/** Whether the transaction is confirmed. */
|
|
170
|
+
isConfirmed: boolean;
|
|
171
|
+
/** Error from the transaction, if any. */
|
|
172
|
+
error: Error | null;
|
|
173
|
+
/** Reset the mutation state. */
|
|
174
|
+
reset: () => void;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Write hook for burning UPD to receive stETH.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```tsx
|
|
181
|
+
* const { burn, isPending, isConfirmed } = useBurnUPD({
|
|
182
|
+
* stabilizerNFTAddress: deployment.contracts.StabilizerNFT,
|
|
183
|
+
* })
|
|
184
|
+
*
|
|
185
|
+
* const { attestation } = useEthUsdPrice()
|
|
186
|
+
*
|
|
187
|
+
* <button onClick={() => burn({ updAmount: parseUnits('1000', 18), attestation })}>
|
|
188
|
+
* Burn 1000 UPD
|
|
189
|
+
* </button>
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
declare function useBurnUPD(config: UseBurnUPDConfig): UseBurnUPDReturn;
|
|
193
|
+
|
|
194
|
+
interface UseSystemHealthConfig {
|
|
195
|
+
/** Address of the OvercollateralizationReporter contract. */
|
|
196
|
+
reporterAddress: Address;
|
|
197
|
+
/** Address of the UPD token. */
|
|
198
|
+
tokenAddress: Address;
|
|
199
|
+
/** Oracle service URL. */
|
|
200
|
+
oracleUrl?: string;
|
|
201
|
+
/** Minimum collateral ratio in basis points (default: 12500 = 125%). */
|
|
202
|
+
minRatioBps?: bigint;
|
|
203
|
+
}
|
|
204
|
+
interface UseSystemHealthReturn {
|
|
205
|
+
/** Computed system health metrics, or undefined if still loading. */
|
|
206
|
+
health: SystemHealth | undefined;
|
|
207
|
+
/** Whether any underlying data is still loading. */
|
|
208
|
+
isLoading: boolean;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* System health hook — composes useCollateral + useEthUsdPrice + computeSystemHealth.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```tsx
|
|
215
|
+
* const { health, isLoading } = useSystemHealth({
|
|
216
|
+
* reporterAddress: deployment.contracts.OvercollateralizationReporter,
|
|
217
|
+
* tokenAddress: deployment.contracts.UPDToken,
|
|
218
|
+
* })
|
|
219
|
+
*
|
|
220
|
+
* if (health && !health.isHealthy) {
|
|
221
|
+
* return <Alert>System undercollateralized: {health.systemCollateralRatioBps} bps</Alert>
|
|
222
|
+
* }
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
declare function useSystemHealth(config: UseSystemHealthConfig): UseSystemHealthReturn;
|
|
226
|
+
|
|
227
|
+
interface UseSUPDConfig {
|
|
228
|
+
/** Address of the sUPD contract. */
|
|
229
|
+
supdAddress: Address;
|
|
230
|
+
/** User address to read balance for (optional). */
|
|
231
|
+
userAddress?: Address;
|
|
232
|
+
}
|
|
233
|
+
interface UseSUPDReturn {
|
|
234
|
+
/** User's sUPD balance (18 decimals). */
|
|
235
|
+
balance: bigint | undefined;
|
|
236
|
+
/** Total sUPD shares outstanding. */
|
|
237
|
+
totalSupply: bigint | undefined;
|
|
238
|
+
/** Current share value with accrued yield (18 decimals). */
|
|
239
|
+
shareValue: bigint | undefined;
|
|
240
|
+
/** Annual yield in basis points (e.g. 800 = 8%). */
|
|
241
|
+
annualYieldBps: bigint | undefined;
|
|
242
|
+
/** Total USD liability of all outstanding sUPD. */
|
|
243
|
+
totalLiabilityUSD: bigint | undefined;
|
|
244
|
+
/** Whether any read is still loading. */
|
|
245
|
+
isLoading: boolean;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Read hook for sUPD — share value, APY, balances, and total liability.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```tsx
|
|
252
|
+
* const { balance, shareValue, annualYieldBps, isLoading } = useSUPD({
|
|
253
|
+
* supdAddress: deployment.contracts.sUPD,
|
|
254
|
+
* userAddress: account.address,
|
|
255
|
+
* })
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
declare function useSUPD(config: UseSUPDConfig): UseSUPDReturn;
|
|
259
|
+
|
|
260
|
+
interface UseStakeUPDConfig {
|
|
261
|
+
/** Address of the sUPD contract. */
|
|
262
|
+
supdAddress: Address;
|
|
263
|
+
}
|
|
264
|
+
interface UseStakeUPDReturn {
|
|
265
|
+
/** Execute the stake transaction. User must approve UPD transfer to sUPD first. */
|
|
266
|
+
stake: (params: {
|
|
267
|
+
updAmount: bigint;
|
|
268
|
+
attestation: PriceAttestationQuery;
|
|
269
|
+
}) => void;
|
|
270
|
+
isPending: boolean;
|
|
271
|
+
txHash: Hash | undefined;
|
|
272
|
+
isConfirming: boolean;
|
|
273
|
+
isConfirmed: boolean;
|
|
274
|
+
error: Error | null;
|
|
275
|
+
reset: () => void;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Write hook for staking UPD → sUPD.
|
|
279
|
+
*
|
|
280
|
+
* Note: The user must first approve the sUPD contract to spend their UPD tokens
|
|
281
|
+
* (via UPDToken.approve or EIP-3009 transferWithAuthorization).
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```tsx
|
|
285
|
+
* const { stake, isPending } = useStakeUPD({
|
|
286
|
+
* supdAddress: deployment.contracts.sUPD,
|
|
287
|
+
* })
|
|
288
|
+
*
|
|
289
|
+
* const { attestation } = useEthUsdPrice()
|
|
290
|
+
*
|
|
291
|
+
* <button onClick={() => stake({ updAmount: parseUnits('1000', 18), attestation })}>
|
|
292
|
+
* Stake 1000 UPD
|
|
293
|
+
* </button>
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
declare function useStakeUPD(config: UseStakeUPDConfig): UseStakeUPDReturn;
|
|
297
|
+
|
|
298
|
+
interface UseUnstakeUPDConfig {
|
|
299
|
+
/** Address of the sUPD contract. */
|
|
300
|
+
supdAddress: Address;
|
|
301
|
+
}
|
|
302
|
+
interface UseUnstakeUPDReturn {
|
|
303
|
+
/** Execute the unstake transaction (unstakeToUPD — full redemption). */
|
|
304
|
+
unstake: (params: {
|
|
305
|
+
shares: bigint;
|
|
306
|
+
attestation: PriceAttestationQuery;
|
|
307
|
+
}) => void;
|
|
308
|
+
isPending: boolean;
|
|
309
|
+
txHash: Hash | undefined;
|
|
310
|
+
isConfirming: boolean;
|
|
311
|
+
isConfirmed: boolean;
|
|
312
|
+
error: Error | null;
|
|
313
|
+
reset: () => void;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Write hook for unstaking sUPD → UPD.
|
|
317
|
+
*
|
|
318
|
+
* Calls `unstakeToUPD(shares, priceQuery)` which gathers stETH from sUPD's
|
|
319
|
+
* stabilizer escrows and mints fresh UPD to the caller.
|
|
320
|
+
*
|
|
321
|
+
* For advanced unstake variants (pro-rata, queued, with-extra-UPD), use the
|
|
322
|
+
* contract ABI directly.
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```tsx
|
|
326
|
+
* const { unstake, isPending } = useUnstakeUPD({
|
|
327
|
+
* supdAddress: deployment.contracts.sUPD,
|
|
328
|
+
* })
|
|
329
|
+
*
|
|
330
|
+
* const { attestation } = useEthUsdPrice()
|
|
331
|
+
*
|
|
332
|
+
* <button onClick={() => unstake({ shares: myShares, attestation })}>
|
|
333
|
+
* Unstake
|
|
334
|
+
* </button>
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
declare function useUnstakeUPD(config: UseUnstakeUPDConfig): UseUnstakeUPDReturn;
|
|
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 };
|