@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.
Files changed (68) hide show
  1. package/README.md +172 -0
  2. package/dist/chunk-4RBWWS2X.js +6616 -0
  3. package/dist/chunk-4RBWWS2X.js.map +1 -0
  4. package/dist/chunk-4VXNJTNQ.cjs +58 -0
  5. package/dist/chunk-4VXNJTNQ.cjs.map +1 -0
  6. package/dist/chunk-5NNXIJE4.js +16 -0
  7. package/dist/chunk-5NNXIJE4.js.map +1 -0
  8. package/dist/chunk-63FIKV36.js +49 -0
  9. package/dist/chunk-63FIKV36.js.map +1 -0
  10. package/dist/chunk-CZEDT3MS.cjs +62 -0
  11. package/dist/chunk-CZEDT3MS.cjs.map +1 -0
  12. package/dist/chunk-DF34ON56.cjs +18 -0
  13. package/dist/chunk-DF34ON56.cjs.map +1 -0
  14. package/dist/chunk-DJBU2OEB.js +57 -0
  15. package/dist/chunk-DJBU2OEB.js.map +1 -0
  16. package/dist/chunk-LNGWRYGY.js +3 -0
  17. package/dist/chunk-LNGWRYGY.js.map +1 -0
  18. package/dist/chunk-POBNO37G.cjs +4 -0
  19. package/dist/chunk-POBNO37G.cjs.map +1 -0
  20. package/dist/chunk-R64I3LAO.js +701 -0
  21. package/dist/chunk-R64I3LAO.js.map +1 -0
  22. package/dist/chunk-RIRT4JX6.js +1808 -0
  23. package/dist/chunk-RIRT4JX6.js.map +1 -0
  24. package/dist/chunk-WRPVPA7E.cjs +713 -0
  25. package/dist/chunk-WRPVPA7E.cjs.map +1 -0
  26. package/dist/chunk-ZDAHLZWC.cjs +1812 -0
  27. package/dist/chunk-ZDAHLZWC.cjs.map +1 -0
  28. package/dist/chunk-ZSWETUGH.cjs +6623 -0
  29. package/dist/chunk-ZSWETUGH.cjs.map +1 -0
  30. package/dist/constants-Bk2bGYfX.d.ts +64 -0
  31. package/dist/constants-BlOP_9dy.d.cts +64 -0
  32. package/dist/contracts/index.cjs +45 -0
  33. package/dist/contracts/index.cjs.map +1 -0
  34. package/dist/contracts/index.d.cts +6559 -0
  35. package/dist/contracts/index.d.ts +6559 -0
  36. package/dist/contracts/index.js +4 -0
  37. package/dist/contracts/index.js.map +1 -0
  38. package/dist/core/index.cjs +76 -0
  39. package/dist/core/index.cjs.map +1 -0
  40. package/dist/core/index.d.cts +5 -0
  41. package/dist/core/index.d.ts +5 -0
  42. package/dist/core/index.js +7 -0
  43. package/dist/core/index.js.map +1 -0
  44. package/dist/health-BUb4ItNt.d.ts +46 -0
  45. package/dist/health-DPxBqH7b.d.cts +46 -0
  46. package/dist/index-XNClksom.d.ts +415 -0
  47. package/dist/index-yRBqVOHV.d.cts +415 -0
  48. package/dist/index.cjs +138 -0
  49. package/dist/index.cjs.map +1 -0
  50. package/dist/index.d.cts +7 -0
  51. package/dist/index.d.ts +7 -0
  52. package/dist/index.js +9 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/oracle/index.cjs +30 -0
  55. package/dist/oracle/index.cjs.map +1 -0
  56. package/dist/oracle/index.d.cts +41 -0
  57. package/dist/oracle/index.d.ts +41 -0
  58. package/dist/oracle/index.js +5 -0
  59. package/dist/oracle/index.js.map +1 -0
  60. package/dist/react/index.cjs +383 -0
  61. package/dist/react/index.cjs.map +1 -0
  62. package/dist/react/index.d.cts +339 -0
  63. package/dist/react/index.d.ts +339 -0
  64. package/dist/react/index.js +370 -0
  65. package/dist/react/index.js.map +1 -0
  66. package/dist/types-DySv82My.d.cts +70 -0
  67. package/dist/types-DySv82My.d.ts +70 -0
  68. package/package.json +93 -0
package/README.md ADDED
@@ -0,0 +1,172 @@
1
+ # UPD SDK — Universal Private Dollar
2
+
3
+ Integrate UPD minting and burning into your protocol. Non-rebasing stablecoin backed by stETH.
4
+
5
+ ```bash
6
+ npm install @permissionless-technologies/upd-sdk
7
+ ```
8
+
9
+ ## Quick Start
10
+
11
+ ```typescript
12
+ import { createPublicClient, http, parseEther } from 'viem'
13
+ import { mainnet } from 'viem/chains'
14
+ import { createUPDClient, quoteMintUPD } from '@permissionless-technologies/upd-sdk'
15
+
16
+ // 1. Create a client
17
+ const publicClient = createPublicClient({ chain: mainnet, transport: http() })
18
+ const client = createUPDClient({ publicClient, chainId: 1 })
19
+
20
+ // 2. Read data (no wallet needed)
21
+ const balance = await client.getUPDBalance('0x...')
22
+ const supply = await client.getTotalSupply()
23
+ const { totalStEthCollateral, totalUPDSupply } = await client.getCollateralInfo()
24
+
25
+ // 3. Quote a mint (pure math, no blockchain call)
26
+ const expectedUPD = quoteMintUPD(parseEther('1'), 2000n * 10n**18n)
27
+ // → 2000000000000000000000n (2000 UPD for 1 ETH at $2000)
28
+ ```
29
+
30
+ ## Minting UPD
31
+
32
+ Send ETH → receive UPD (pegged to $1). The StabilizerNFT contract handles collateral allocation automatically.
33
+
34
+ ```typescript
35
+ import { createWalletClient, custom, parseEther } from 'viem'
36
+ import { createUPDClient, createMockAttestation } from '@permissionless-technologies/upd-sdk'
37
+
38
+ const walletClient = createWalletClient({ chain: mainnet, transport: custom(window.ethereum) })
39
+ const client = createUPDClient({ publicClient, walletClient, chainId: 1 })
40
+
41
+ // Get a price attestation (see Oracle section below)
42
+ const attestation = await fetchPriceFromYourOracle() // your implementation
43
+
44
+ // Mint UPD
45
+ const txHash = await client.mint({
46
+ to: userAddress,
47
+ ethAmount: parseEther('1'),
48
+ priceAttestation: attestation,
49
+ })
50
+ ```
51
+
52
+ ## Burning UPD
53
+
54
+ Send UPD → receive stETH back.
55
+
56
+ ```typescript
57
+ import { parseUnits } from 'viem'
58
+
59
+ const txHash = await client.burn({
60
+ updAmount: parseUnits('2000', 18),
61
+ priceAttestation: attestation,
62
+ })
63
+ ```
64
+
65
+ ## Quote Functions
66
+
67
+ Pure math — no blockchain calls needed. Use these to show users expected amounts before a transaction.
68
+
69
+ ```typescript
70
+ import { quoteMintUPD, quoteBurnUPD, collateralizationRatio } from '@permissionless-technologies/upd-sdk'
71
+
72
+ // How much UPD for 1 ETH at $2000?
73
+ quoteMintUPD(parseEther('1'), 2000n * 10n**18n) // → 2000 UPD
74
+
75
+ // How much stETH for 2000 UPD at $2000?
76
+ quoteBurnUPD(parseUnits('2000', 18), 2000n * 10n**18n) // → 1 stETH
77
+
78
+ // Calculate collateralization ratio
79
+ collateralizationRatio(parseEther('1.25'), 2000n * 10n**18n, parseUnits('2000', 18)) // → 12500 (125%)
80
+ ```
81
+
82
+ ## Oracle Integration
83
+
84
+ Minting and burning require a signed price attestation from an authorized oracle signer. The attestation format:
85
+
86
+ ```typescript
87
+ interface PriceAttestationQuery {
88
+ price: bigint // ETH/USD price, 18 decimals (e.g. 2000e18)
89
+ decimals: number // Always 18
90
+ dataTimestamp: bigint // Milliseconds since epoch
91
+ assetPair: `0x${string}` // keccak256("MORPHER:ETH_USD")
92
+ signature: `0x${string}` // ECDSA sig from authorized signer
93
+ }
94
+ ```
95
+
96
+ **For testing/development**, use the mock helper:
97
+
98
+ ```typescript
99
+ import { createMockAttestation } from '@permissionless-technologies/upd-sdk'
100
+
101
+ const attestation = createMockAttestation(2000n * 10n**18n)
102
+ // Works with MockPriceOracle on local Anvil — NOT for production
103
+ ```
104
+
105
+ **For production**, the oracle service signs `keccak256(abi.encodePacked(price, decimals, timestamp, assetPair))` with an authorized key. The PriceOracle contract validates this against Chainlink + Uniswap V3 (±5% deviation check on mainnet).
106
+
107
+ ## Contract Addresses
108
+
109
+ Addresses are loaded per chain ID:
110
+
111
+ ```typescript
112
+ import { getDeployment, getContractAddress } from '@permissionless-technologies/upd-sdk'
113
+
114
+ const deployment = getDeployment(1) // mainnet (when deployed)
115
+ const updToken = getContractAddress(1, 'UPDToken')
116
+ const stabNFT = getContractAddress(1, 'StabilizerNFT')
117
+ ```
118
+
119
+ To add a new chain, create `src/deployments/[chainId].json` with contract addresses.
120
+
121
+ ## React Hooks
122
+
123
+ Optional wagmi-based hooks for frontends:
124
+
125
+ ```typescript
126
+ import { useUPD, useCollateral, useStabilizer } from '@permissionless-technologies/upd-sdk/react'
127
+
128
+ function Dashboard() {
129
+ const { balance, totalSupply, isLoading } = useUPD({ tokenAddress, userAddress })
130
+ const { totalStEthCollateral, totalUPDSupply } = useCollateral({ reporterAddress, tokenAddress })
131
+ const { positionEscrowAddress } = useStabilizer({ stabilizerNFTAddress, tokenId: 1n })
132
+ }
133
+ ```
134
+
135
+ ## Contracts
136
+
137
+ | Contract | Purpose |
138
+ |---|---|
139
+ | **UPDToken** | Non-rebasing ERC20 ($1 = 1 UPD). Mint/burn via StabilizerNFT. |
140
+ | **StabilizerNFT** | Entry point for minting/burning. Manages collateral allocation. |
141
+ | **PositionEscrow** | Holds stETH per stabilizer. Yield increases collateral ratio. |
142
+ | **StabilizerEscrow** | Holds unallocated stETH per stabilizer. |
143
+ | **PriceOracle** | Validates signed ETH/USD attestations (Chainlink + Uniswap V3). |
144
+ | **OvercollateralizationReporter** | System-wide collateral ratio tracking. |
145
+
146
+ ### ABIs
147
+
148
+ ```typescript
149
+ import {
150
+ UPD_TOKEN_ABI, STABILIZER_NFT_ABI, PRICE_ORACLE_ABI,
151
+ POSITION_ESCROW_ABI, STABILIZER_ESCROW_ABI,
152
+ } from '@permissionless-technologies/upd-sdk/contracts'
153
+ ```
154
+
155
+ ## Subpath Exports
156
+
157
+ ```
158
+ @permissionless-technologies/upd-sdk # Everything
159
+ @permissionless-technologies/upd-sdk/core # Client, types, quote, oracle
160
+ @permissionless-technologies/upd-sdk/contracts # ABIs only
161
+ @permissionless-technologies/upd-sdk/react # React hooks (wagmi)
162
+ ```
163
+
164
+ ## Development
165
+
166
+ ```bash
167
+ npm install # Install deps
168
+ npm run build # Build SDK (ESM + CJS + types)
169
+ npm test # Run TypeScript tests (vitest)
170
+ npm run test:forge # Run Solidity tests (forge)
171
+ npm run generate:abis # Rebuild ABIs from contracts
172
+ ```