@juicedollar/jusd 1.0.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 (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +356 -0
  3. package/contracts/Equity.sol +457 -0
  4. package/contracts/JuiceDollar.sol +363 -0
  5. package/contracts/Leadrate.sol +79 -0
  6. package/contracts/MintingHubV2/MintingHub.sol +445 -0
  7. package/contracts/MintingHubV2/Position.sol +810 -0
  8. package/contracts/MintingHubV2/PositionFactory.sol +69 -0
  9. package/contracts/MintingHubV2/PositionRoller.sol +159 -0
  10. package/contracts/MintingHubV2/interface/IMintingHub.sol +26 -0
  11. package/contracts/MintingHubV2/interface/IPosition.sol +90 -0
  12. package/contracts/MintingHubV2/interface/IPositionFactory.sol +20 -0
  13. package/contracts/Savings.sol +141 -0
  14. package/contracts/SavingsVaultJUSD.sol +140 -0
  15. package/contracts/StablecoinBridge.sol +109 -0
  16. package/contracts/StartUSD.sol +16 -0
  17. package/contracts/gateway/CoinLendingGateway.sol +223 -0
  18. package/contracts/gateway/FrontendGateway.sol +224 -0
  19. package/contracts/gateway/MintingHubGateway.sol +87 -0
  20. package/contracts/gateway/SavingsGateway.sol +51 -0
  21. package/contracts/gateway/interface/ICoinLendingGateway.sol +73 -0
  22. package/contracts/gateway/interface/IFrontendGateway.sol +49 -0
  23. package/contracts/gateway/interface/IMintingHubGateway.sol +12 -0
  24. package/contracts/impl/ERC3009.sol +171 -0
  25. package/contracts/interface/IJuiceDollar.sol +54 -0
  26. package/contracts/interface/ILeadrate.sol +7 -0
  27. package/contracts/interface/IReserve.sol +9 -0
  28. package/contracts/interface/ISavingsJUSD.sol +49 -0
  29. package/contracts/test/FreakToken.sol +25 -0
  30. package/contracts/test/Math.sol +339 -0
  31. package/contracts/test/MockEquity.sol +15 -0
  32. package/contracts/test/PositionExpirationTest.sol +75 -0
  33. package/contracts/test/PositionRollingTest.sol +65 -0
  34. package/contracts/test/TestFlashLoan.sol +84 -0
  35. package/contracts/test/TestFlashLoanGateway.sol +49 -0
  36. package/contracts/test/TestMathUtil.sol +40 -0
  37. package/contracts/test/TestToken.sol +45 -0
  38. package/contracts/test/TestWcBTC.sol +35 -0
  39. package/contracts/utils/MathUtil.sol +61 -0
  40. package/dist/index.d.mts +8761 -0
  41. package/dist/index.d.ts +8761 -0
  42. package/dist/index.js +11119 -0
  43. package/dist/index.mjs +11073 -0
  44. package/exports/abis/MintingHubV2/PositionFactoryV2.ts +90 -0
  45. package/exports/abis/MintingHubV2/PositionRoller.ts +183 -0
  46. package/exports/abis/MintingHubV2/PositionV2.ts +999 -0
  47. package/exports/abis/core/CoinLendingGateway.ts +427 -0
  48. package/exports/abis/core/Equity.ts +1286 -0
  49. package/exports/abis/core/FrontendGateway.ts +906 -0
  50. package/exports/abis/core/JuiceDollar.ts +1366 -0
  51. package/exports/abis/core/MintingHubGateway.ts +865 -0
  52. package/exports/abis/core/SavingsGateway.ts +559 -0
  53. package/exports/abis/core/SavingsVaultJUSD.ts +920 -0
  54. package/exports/abis/utils/ERC20.ts +310 -0
  55. package/exports/abis/utils/ERC20PermitLight.ts +520 -0
  56. package/exports/abis/utils/Leadrate.ts +175 -0
  57. package/exports/abis/utils/MintingHubV2.ts +682 -0
  58. package/exports/abis/utils/Ownable.ts +76 -0
  59. package/exports/abis/utils/Savings.ts +453 -0
  60. package/exports/abis/utils/StablecoinBridge.ts +209 -0
  61. package/exports/abis/utils/StartUSD.ts +315 -0
  62. package/exports/abis/utils/UniswapV3Pool.ts +638 -0
  63. package/exports/address.config.ts +48 -0
  64. package/exports/index.ts +28 -0
  65. package/package.json +87 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 DistributedCollective
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,356 @@
1
+ # JuiceDollar (JUSD)
2
+
3
+ > An oracle-free, collateralized stablecoin forked from dEURO
4
+
5
+ This repository contains the smart contracts for JuiceDollar (JUSD), a decentralized stablecoin system with native protocol shares (JUICE).
6
+
7
+ **Links:**
8
+ - [Public Frontend](https://app.juicedollar.com)
9
+ - [Documentation](https://docs.juicedollar.com)
10
+ - [Upstream Repository](https://github.com/d-EURO/smartContracts) (d-EURO)
11
+ - [Original Frankencoin](https://github.com/Frankencoin-ZCHF/FrankenCoin) (dEURO was forked from Frankencoin commit [a2ce625](https://github.com/Frankencoin-ZCHF/FrankenCoin/commit/a2ce625c554bbd3465a31e7d8b7360a054339dd2), December 2, 2024)
12
+
13
+ ---
14
+
15
+ ## Table of Contents
16
+
17
+ - [Smart Contracts Overview](#smart-contracts-overview)
18
+ - [Fork History](#fork-history)
19
+ - [Key Differences](#key-differences)
20
+ - [Audit Reports](#audit-reports)
21
+ - [Development Setup](#development-setup)
22
+ - [Testing](#testing)
23
+ - [Deployment](#deployment)
24
+ - [NPM Package](#npm-package)
25
+ - [Foundry Fuzzing Tests](#foundry-fuzzing-tests)
26
+
27
+ ---
28
+
29
+ ## Smart Contracts Overview
30
+
31
+ All source code is located in the [contracts](contracts) folder.
32
+
33
+ ### Core Contracts
34
+
35
+ | Contract | Description |
36
+ |----------|-------------|
37
+ | **JuiceDollar.sol** | The JUSD ERC20 stablecoin token |
38
+ | **Equity.sol** | The JUICE ERC20 token (Juice Protocol) |
39
+ | **Leadrate.sol** | Leading interest rate module for the system |
40
+
41
+ ### Minting Hub V2
42
+
43
+ | Contract | Description |
44
+ |----------|-------------|
45
+ | **MintingHub.sol** | Oracle-free collateralized minting system |
46
+ | **Position.sol** | Individual collateralized loan position |
47
+ | **PositionFactory.sol** | Factory to create new positions |
48
+ | **PositionRoller.sol** | Roll positions into new ones |
49
+
50
+ ### Savings & Bridges
51
+
52
+ | Contract | Description |
53
+ |----------|-------------|
54
+ | **Savings.sol** | Interest distribution to JUSD holders |
55
+ | **SavingsVaultJUSD.sol** | ERC4626 vault for JUSD savings |
56
+ | **StablecoinBridge.sol** | 1:1 swaps with external stablecoins (StartUSD for bootstrap) |
57
+
58
+ ### Gateway Contracts (Frontend Rewards)
59
+
60
+ | Contract | Description |
61
+ |----------|-------------|
62
+ | **FrontendGateway.sol** | Rewards frontend providers for referrals |
63
+ | **MintingHubGateway.sol** | Minting with frontend provider rewards |
64
+ | **SavingsGateway.sol** | Savings with frontend provider rewards |
65
+ | **CoinLendingGateway.sol** | Native coin (cBTC) lending with custom liquidation |
66
+
67
+ ---
68
+
69
+ ## Fork History
70
+
71
+ JuiceDollar is part of a three-generation fork chain:
72
+
73
+ ```
74
+ Frankencoin-ZCHF (Original)
75
+
76
+ d-EURO (December 2024 fork)
77
+
78
+ JuiceDollar (Current repository)
79
+ ```
80
+
81
+ **Upstream**: [`d-EURO/smartContracts`](https://github.com/d-EURO/smartContracts)
82
+ **Origin**: [`Frankencoin-ZCHF/FrankenCoin`](https://github.com/Frankencoin-ZCHF/FrankenCoin)
83
+
84
+ **Deployment Networks:**
85
+ - **Frankencoin-ZCHF**: Ethereum Mainnet (native currency: ETH)
86
+ - **dEURO**: Ethereum Mainnet (native currency: ETH) | Testnet: Sepolia
87
+ - **JuiceDollar**: Citrea Mainnet (native currency: cBTC) | Testnet: Citrea Testnet
88
+
89
+ d-EURO forked from Frankencoin at commit [a2ce625](https://github.com/Frankencoin-ZCHF/FrankenCoin/commit/a2ce625c554bbd3465a31e7d8b7360a054339dd2) (December 2, 2024), introducing significant protocol improvements. JuiceDollar continues this evolution with deployment on Citrea, using cBTC as the native currency.
90
+
91
+ ---
92
+
93
+ ## Audit Reports
94
+
95
+ JuiceDollar inherits security audits from its upstream repositories:
96
+
97
+ ### Frankencoin Audits
98
+
99
+ | Date | Auditor | Report |
100
+ |------|---------|--------|
101
+ | 2023-02-10 | Blockbite | [Report](https://github.com/Frankencoin-ZCHF/FrankenCoin/blob/main/audits/blockbite-audit.pdf) |
102
+ | 2023-06-09 | Code4rena | [Report](https://code4rena.com/reports/2023-04-frankencoin) |
103
+ | 2023-10-30 | ChainSecurity | [Report](https://github.com/Frankencoin-ZCHF/FrankenCoin/blob/main/audits/V1/blockbite-audit.pdf) |
104
+ | 2024-09-25 | Decurity | [Report](https://github.com/Decurity/audits/blob/master/Frankencoin/frankencoin-audit-report-2024-1.1.pdf) |
105
+ | 2024-11-28 | ChainSecurity | [Report](https://cdn.prod.website-files.com/65d35b01a4034b72499019e8/674873bff5163fea0b1d9faa_ChainSecurity_Frankencoin_Frankencoin_v2024_audit.pdf) |
106
+
107
+ ### dEURO-Specific Audits
108
+
109
+ | Auditor | Scope | Report |
110
+ |---------|-------|--------|
111
+ | ChainSecurity | dEURO fork changes (Interest Accrual, Auction, Accounting) | [Audit](https://www.chainsecurity.com/security-audit/deuro-smart-contracts) |
112
+ | Audit Boutique | dEURO smart contracts | [Report PDF](https://github.com/d-EURO/landingPage/blob/develop/audits/deuro_audit_report.pdf) |
113
+
114
+ ### Bug Bounty
115
+
116
+ - **JuiceDollar Bug Bounty**: Program details will be announced soon
117
+ - **Upstream Bug Bounty Programs**:
118
+ - [Frankencoin Bug Bounty](https://bugbounty.compass-security.com/service-details.html?id=18)
119
+ - [dEURO Bug Bounty](https://bugbounty.compass-security.com/service-details.html?id=23)
120
+
121
+ ---
122
+
123
+ ## Development Setup
124
+
125
+ ### Prerequisites
126
+
127
+ - Node.js & Yarn
128
+ - Hardhat
129
+ - (Optional) Foundry for fuzzing tests
130
+
131
+ ### 1. Install Dependencies
132
+
133
+ ```bash
134
+ yarn install
135
+ ```
136
+
137
+ ### 2. Environment Configuration
138
+
139
+ Create a `.env` file (see `.env.example`):
140
+
141
+ ```bash
142
+ # Required: Use EITHER private key OR seed phrase
143
+ DEPLOYER_PRIVATE_KEY=your_private_key_here
144
+ # DEPLOYER_ACCOUNT_SEED="twelve word seed phrase goes here"
145
+
146
+ # Optional: For contract verification on Citrea explorer
147
+ # CITREA_EXPLORER_API_KEY=your_api_key_here
148
+ ```
149
+
150
+ ### 3. Compile Contracts
151
+
152
+ ```bash
153
+ yarn run compile
154
+ ```
155
+
156
+ ---
157
+
158
+ ## Testing
159
+
160
+ ### Run Tests
161
+
162
+ ```bash
163
+ yarn run test # Run all tests
164
+ yarn run test test/TESTSCRIPT.ts # Run specific test
165
+ yarn run coverage # Generate coverage report
166
+ ```
167
+
168
+ ### Auto-refresh Testing
169
+
170
+ ```bash
171
+ npx tsc-watch --onCompilationComplete "npx hardhat test ./test/RollerTests.ts"
172
+ ```
173
+
174
+ ---
175
+
176
+ ## Deployment
177
+
178
+ ### Target Networks
179
+
180
+ - **Mainnet**: Citrea (native currency: cBTC)
181
+ - **Testnet**: Citrea Testnet
182
+
183
+ ### Manual Deployment (Hardhat Deploy)
184
+
185
+ Deploy to Citrea Testnet:
186
+
187
+ ```bash
188
+ hh deploy --network citreaTestnet --tags MockTokens
189
+ hh deploy --network citreaTestnet --tags JuiceDollar
190
+ hh deploy --network citreaTestnet --tags PositionFactory
191
+ hh deploy --network citreaTestnet --tags MintingHub
192
+ hh deploy --network citreaTestnet --tags positions
193
+ ```
194
+
195
+ **Testing on local fork:**
196
+ ```bash
197
+ # Set USE_FORK=true in .env, then:
198
+ npx hardhat node
199
+ ```
200
+
201
+ ### Deploy Stablecoin Bridges
202
+
203
+ **NOTE:** The bootstrap bridge (StartUSD → JUSD) is deployed automatically via `deployProtocol.ts`
204
+
205
+ For additional bridges:
206
+ ```bash
207
+ # 1. Add bridge config to scripts/deployment/config/stablecoinBridgeConfig.ts
208
+ # 2. Deploy using BRIDGE_KEY environment variable:
209
+ BRIDGE_KEY=<KEY> npx hardhat run scripts/deployment/deploy/deployBridge.ts --network citrea
210
+
211
+ # Test on forked network
212
+ USE_FORK=true BRIDGE_KEY=<KEY> npx hardhat run scripts/deployment/deploy/deployBridge.ts --network hardhat
213
+ ```
214
+
215
+ Bridge configurations: `scripts/deployment/config/stablecoinBridgeConfig.ts`
216
+
217
+ ### Hardhat Ignition Deployment
218
+
219
+ ```bash
220
+ # Deploy single module with verification
221
+ npm run deploy ignition/modules/MODULE --network citrea --verify --deployment-id MODULE_ID_01
222
+
223
+ # Deploy all modules
224
+ npm run deploy -- --network citrea --verify
225
+ ```
226
+
227
+ **Output:**
228
+ - `ignition/deployments/[deployment]/deployed_addresses.json`
229
+ - `ignition/deployments/[deployment]/journal.jsonl`
230
+ - `ignition/constructor-args/*.js`
231
+
232
+ ### Manual Verification
233
+
234
+ ```bash
235
+ npx hardhat verify --network citrea \
236
+ --constructor-args ./ignition/constructor-args/$FILE.js \
237
+ $ADDRESS
238
+
239
+ # Verify unrelated contracts
240
+ npx hardhat ignition verify $DEPLOYMENT --include-unrelated-contracts
241
+ ```
242
+
243
+ ---
244
+
245
+ ## NPM Package
246
+
247
+ ### Package Info
248
+
249
+ - **Name**: `@juicedollar/jusd`
250
+ - **Version**: `1.0.16` (see `package.json`)
251
+ - **Registry**: https://registry.npmjs.org
252
+
253
+ ### Build & Publish
254
+
255
+ ```bash
256
+ # 1. Update version in package.json
257
+ # "version": "1.0.17"
258
+
259
+ # 2. Build TypeScript package
260
+ yarn run build
261
+
262
+ # 3. Login to NPM
263
+ npm login
264
+
265
+ # 4. Publish package
266
+ yarn run publish
267
+ ```
268
+
269
+ **Note:** The publish command may execute twice; the second will fail with a version conflict (expected behavior).
270
+
271
+ ### Package Exports
272
+
273
+ **TypeScript ABIs** (`exports/abis/`):
274
+ ```typescript
275
+ export const JuiceDollarABI = [...] as const;
276
+ ```
277
+
278
+ **Address Config** (`exports/address.config.ts`):
279
+ ```typescript
280
+ export const ADDRESS: Record<number, ChainAddress> = {
281
+ [citrea.id]: { juiceDollar: '0x...', equity: '0x...' }
282
+ };
283
+ ```
284
+
285
+ ---
286
+
287
+ ## Foundry Fuzzing Tests
288
+
289
+ ### Overview
290
+
291
+ Invariant/stateful fuzzing tests verify system integrity under random operations.
292
+
293
+ **Location:** `foundry-test/invariant/`
294
+ - `Invariants.t.sol` - Defines system invariants
295
+ - `Handler.t.sol` - Defines random actions
296
+
297
+ **Configuration:** `foundry.toml`
298
+ **Remappings:** `remappings.txt`
299
+
300
+ ### Setup
301
+
302
+ ```bash
303
+ # Install Foundry: https://book.getfoundry.sh/
304
+ curl -L https://foundry.paradigm.xyz | bash
305
+ foundryup
306
+
307
+ # Install dependencies
308
+ forge install
309
+ ```
310
+
311
+ ### Run Fuzzing Tests
312
+
313
+ ```bash
314
+ # Clean artifacts
315
+ forge clean
316
+
317
+ # Run tests
318
+ forge test
319
+
320
+ # Verbose output (filter noise)
321
+ forge test -vvv | grep -v "Bound result"
322
+
323
+ # Show progress
324
+ forge test --show-progress
325
+
326
+ # Re-run failed test (enable snapshots in foundry.toml)
327
+ forge test --rerun
328
+ ```
329
+
330
+ ### Debug Handler Reverts
331
+
332
+ Set in `foundry.toml`:
333
+ ```toml
334
+ [invariant]
335
+ fail_on_revert = true
336
+ ```
337
+
338
+ ---
339
+
340
+ ## License
341
+
342
+ MIT License - See [LICENSE](LICENSE) file
343
+
344
+ Copyright (c) 2024 DistributedCollective
345
+
346
+ ---
347
+
348
+ ## Contributing
349
+
350
+ This project is a fork of [d-EURO](https://github.com/d-EURO/smartContracts), which itself is a fork of [Frankencoin-ZCHF](https://github.com/Frankencoin-ZCHF/FrankenCoin).
351
+
352
+ For contribution guidelines, please open an issue in this repository or refer to the upstream dEURO repository.
353
+
354
+ ---
355
+
356
+ **Built with ❤️ by the JuiceDollar team**