@usdu-finance/usdu-core 0.0.1 → 0.0.2
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 +76 -198
- package/dist/index.d.mts +1674 -2
- package/dist/index.d.ts +1674 -2
- package/dist/index.js +35 -0
- package/dist/index.mjs +30 -0
- package/exports/address.types.ts +34 -2
- package/package.json +1 -1
- package/.claude/settings.local.json +0 -12
package/README.md
CHANGED
|
@@ -1,244 +1,122 @@
|
|
|
1
|
-
# Core
|
|
1
|
+
# USDU Finance - Core Smart Contracts
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Core smart contract implementation for USDU Finance, a stablecoin protocol built on Ethereum. This repository contains the essential contracts for the USDU stablecoin, yield-generating vault adapters, and reward distribution system.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
// yarn run <command> args...
|
|
5
|
+
## Overview
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
"wallet:info": "npx ts-node helper/wallet.info.ts",
|
|
7
|
+
**Key Components:**
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
- **USDU Stablecoin**: ERC20 stablecoin with role-based governance
|
|
10
|
+
- **Vault Adapters**: TermMax, Morpho & Curve integrations for borrow & lending market and deep liquidity
|
|
11
|
+
- **Reward System**: Token distribution and staking rewards
|
|
12
|
+
- **TermMax Integration**: Advanced yield optimization strategies
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
"verify": "npx hardhat verify",
|
|
14
|
+
## Project Structure
|
|
17
15
|
|
|
18
|
-
"npm:build": "tsup",
|
|
19
|
-
"npm:publish": "npm publish --access public"
|
|
20
16
|
```
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
> See .env.example
|
|
29
|
-
|
|
30
|
-
```JSON
|
|
31
|
-
file: .env
|
|
32
|
-
|
|
33
|
-
DEPLOYER_SEED="test test test test test test test test test test test junk"
|
|
34
|
-
DEPLOYER_SEED_INDEX=1
|
|
35
|
-
ALCHEMY_RPC_KEY=...
|
|
36
|
-
ETHERSCAN_API=...
|
|
17
|
+
contracts/
|
|
18
|
+
├── stablecoin/ # USDU stablecoin core implementation
|
|
19
|
+
├── vault/ # Vault adapters for yield generation
|
|
20
|
+
├── morpho/ # Morpho protocol integration
|
|
21
|
+
├── curve/ # Curve protocol integration
|
|
22
|
+
├── reward/ # Reward distribution system
|
|
23
|
+
└── test/ # Test contracts and utilities
|
|
37
24
|
```
|
|
38
25
|
|
|
39
|
-
|
|
26
|
+
**Supported Networks:**
|
|
40
27
|
|
|
41
|
-
|
|
28
|
+
- **Mainnet** (primary): Full protocol deployment with all contracts
|
|
29
|
+
- **L2s** (in discussion): Polygon, Arbitrum, Optimism, Base, Avalanche, Gnosis, Sonic
|
|
42
30
|
|
|
43
|
-
>
|
|
31
|
+
> See `exports/address.types.ts` for complete chain configurations and `exports/address.config.ts` for deployed addresses.
|
|
44
32
|
|
|
45
|
-
|
|
46
|
-
yarn run compile # Compiles all contracts
|
|
47
|
-
```
|
|
33
|
+
## Quick Start
|
|
48
34
|
|
|
49
|
-
|
|
35
|
+
```bash
|
|
36
|
+
# Setup
|
|
37
|
+
yarn install
|
|
38
|
+
cp .env.example .env # Configure your environment
|
|
50
39
|
|
|
51
|
-
|
|
40
|
+
# Development
|
|
41
|
+
yarn compile # Compile contracts
|
|
42
|
+
yarn test # Run tests
|
|
43
|
+
yarn coverage # Test coverage
|
|
52
44
|
|
|
53
|
-
|
|
54
|
-
yarn
|
|
55
|
-
yarn run test test/Membership.ts # Run specific test file
|
|
56
|
-
yarn run coverage # Generate test coverage report
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### 5. Write Deployment Scripts (via ignition deploy and verify)
|
|
60
|
-
|
|
61
|
-
- Create new `/ignition/params/[file].ts` for type conform deployment params
|
|
62
|
-
- Create new `/ignition/module/[file].ts` for workflow of deployment
|
|
45
|
+
# Deployment
|
|
46
|
+
yarn deploy ignition/modules/StablecoinModule.ts --network mainnet --verify
|
|
63
47
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
yarn run deploy ignition/modules/MembershipFactory.ts --network polygon --verify --deployment-id Membership01
|
|
68
|
-
|
|
69
|
-
--> increase: deployment-id
|
|
48
|
+
# Package
|
|
49
|
+
yarn npm:build # Build for npm
|
|
50
|
+
yarn npm:publish # Publish package
|
|
70
51
|
```
|
|
71
52
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
- Compile and deploy contracts
|
|
75
|
-
- Verify on Etherscan and Sourcify
|
|
76
|
-
- Generate deployment artifacts in `/ignition/deployments`
|
|
77
|
-
|
|
78
|
-
Verify:
|
|
79
|
-
|
|
80
|
-
- verifies contract on etherscan
|
|
81
|
-
- verifies contract on sourcify
|
|
82
|
-
|
|
83
|
-
Key deployment files:
|
|
84
|
-
|
|
85
|
-
- deployed_addresses.json: Contains contract addresses
|
|
86
|
-
- journal.json: Detailed deployment logs
|
|
87
|
-
|
|
88
|
-
- creates deployment artifacts in /ignition`/deployments` directory
|
|
89
|
-
- creates ./ignition/deployments/[deployment]/`deployed_addresses.json`
|
|
90
|
-
- creates ./ignition/deployments/[deployment]/`journal.jsonl`
|
|
91
|
-
- creates constructor-args in /ignition`/constructor-args` directory, as JS module export
|
|
92
|
-
|
|
93
|
-
### 5.1 Example
|
|
94
|
-
|
|
95
|
-
```Bash
|
|
96
|
-
✔ Confirm deploy to network polygon (137)? … yes
|
|
97
|
-
{
|
|
98
|
-
message: 'Config Info: Deploying Module with accounts',
|
|
99
|
-
admin: '0xb687FE7E47774B22F10Ca5E747496d81827167E3',
|
|
100
|
-
executor: '0xBdae8D35EDe5bc5174E805DcBe3F7714d142DAAb',
|
|
101
|
-
member: '0x2ACf17C04F1d8BE7E9D5529894DCee86bf2fcdC3'
|
|
102
|
-
}
|
|
103
|
-
Constructor Args
|
|
104
|
-
[
|
|
105
|
-
'0xb687FE7E47774B22F10Ca5E747496d81827167E3',
|
|
106
|
-
'0xBdae8D35EDe5bc5174E805DcBe3F7714d142DAAb',
|
|
107
|
-
'0x2ACf17C04F1d8BE7E9D5529894DCee86bf2fcdC3'
|
|
108
|
-
]
|
|
109
|
-
Hardhat Ignition 🚀
|
|
110
|
-
|
|
111
|
-
Deploying [ MembershipModule ]
|
|
112
|
-
|
|
113
|
-
Batch #1
|
|
114
|
-
Executed MembershipModule#Membership
|
|
115
|
-
|
|
116
|
-
Batch #2
|
|
117
|
-
Executed MembershipModule#Storage
|
|
118
|
-
|
|
119
|
-
[ MembershipModule ] successfully deployed 🚀
|
|
120
|
-
|
|
121
|
-
Deployed Addresses
|
|
53
|
+
## Development Workflow
|
|
122
54
|
|
|
123
|
-
|
|
124
|
-
MembershipModule#Storage - 0x8A7e8091e71cCB7D1EbDd773C26AD82AAd323328
|
|
55
|
+
### Environment Setup
|
|
125
56
|
|
|
126
|
-
|
|
57
|
+
Create `.env` file (see `.env.example`):
|
|
127
58
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
Contract contracts/Storage.sol:Storage already verified on network polygon:
|
|
134
|
-
- https://polygonscan.com/address/0x8A7e8091e71cCB7D1EbDd773C26AD82AAd323328#code
|
|
135
|
-
|
|
136
|
-
✨ Done in 69.96s.
|
|
59
|
+
```bash
|
|
60
|
+
DEPLOYER_SEED="your mnemonic here"
|
|
61
|
+
DEPLOYER_SEED_INDEX=0
|
|
62
|
+
ALCHEMY_RPC_KEY=your_api_key
|
|
63
|
+
ETHERSCAN_API=your_api_key
|
|
137
64
|
```
|
|
138
65
|
|
|
139
|
-
###
|
|
140
|
-
|
|
141
|
-
`npx hardhat verify --network polygon --constructor-args ./ignition/constructor-args/$FILE.js $ADDRESS`
|
|
142
|
-
|
|
143
|
-
or manually include unrelated contracts by creating or using `/ignition/constructor-args/[file].js`
|
|
144
|
-
|
|
145
|
-
`npx hardhat ignition verify $DEPLOYMENT --include-unrelated-contracts`
|
|
146
|
-
|
|
147
|
-
### 6 Prepare NPM Package Support
|
|
66
|
+
### Testing & Building
|
|
148
67
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
### 6.1 TypeScript ABIs
|
|
154
|
-
|
|
155
|
-
Export contract ABIs for npm package usage by copying the JSON into dedicated TypeScript files:
|
|
156
|
-
|
|
157
|
-
```TS
|
|
158
|
-
file: exports/abis/...
|
|
159
|
-
|
|
160
|
-
export const StorageABI = [
|
|
161
|
-
...
|
|
162
|
-
JSON
|
|
163
|
-
...
|
|
164
|
-
] as const;
|
|
68
|
+
```bash
|
|
69
|
+
yarn test # All tests
|
|
70
|
+
yarn test test/Stablecoin.ts # Specific test
|
|
71
|
+
yarn coverage # Coverage report
|
|
165
72
|
```
|
|
166
73
|
|
|
167
|
-
###
|
|
168
|
-
|
|
169
|
-
Provides a mapping of contract addresses for the Membership and Storage contracts deployed on different blockchain networks.
|
|
170
|
-
|
|
171
|
-
The `ADDRESS` object contains the contract addresses for the `mainnet` and `polygon` networks, with the network ID as the key.
|
|
172
|
-
The `zeroAddress` is used as a placeholder for the `mainnet` network, as the contracts have not been deployed there yet.
|
|
74
|
+
### Deployment
|
|
173
75
|
|
|
174
|
-
|
|
175
|
-
file: exports/address.config.ts
|
|
76
|
+
Create deployment modules in `/ignition/modules/` and parameter files in `/ignition/params/`:
|
|
176
77
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
export interface ChainAddress {
|
|
181
|
-
membership: Address;
|
|
182
|
-
storage: Address;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export const ADDRESS: Record<number, ChainAddress> = {
|
|
186
|
-
[mainnet.id]: {
|
|
187
|
-
membership: zeroAddress,
|
|
188
|
-
storage: zeroAddress,
|
|
189
|
-
},
|
|
190
|
-
[polygon.id]: {
|
|
191
|
-
membership: '0x72950A0A9689fCA941Ddc9E1a58dcD3fb792E3D2',
|
|
192
|
-
storage: '0x8A7e8091e71cCB7D1EbDd773C26AD82AAd323328',
|
|
193
|
-
},
|
|
194
|
-
};
|
|
78
|
+
```bash
|
|
79
|
+
yarn deploy ignition/modules/StablecoinModule.ts --network mainnet --verify --deployment-id USDU01
|
|
195
80
|
```
|
|
196
81
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
### 7.1 TSUP
|
|
200
|
-
|
|
201
|
-
> Config: /tsup.config.ts
|
|
202
|
-
|
|
203
|
-
TSUP bundles TypeScript code into optimized JavaScript packages. This package uses TSUP to create production-ready builds.
|
|
82
|
+
This compiles, deploys, and verifies contracts on Etherscan/Sourcify. Artifacts are saved to `/ignition/deployments/`.
|
|
204
83
|
|
|
205
|
-
|
|
84
|
+
**Manual Verification:**
|
|
206
85
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
```
|
|
212
|
-
file: /package.json
|
|
213
|
-
|
|
214
|
-
"name": "@wrytlabs/core-template",
|
|
215
|
-
"version": "0.0.1", <-- HERE
|
|
86
|
+
```bash
|
|
87
|
+
npx hardhat verify --network mainnet --constructor-args ./ignition/constructor-args/$FILE.js $ADDRESS
|
|
88
|
+
npx hardhat ignition verify $DEPLOYMENT --include-unrelated-contracts
|
|
216
89
|
```
|
|
217
90
|
|
|
218
|
-
|
|
91
|
+
## NPM Package
|
|
219
92
|
|
|
220
|
-
|
|
93
|
+
The package exports TypeScript ABIs and address configurations:
|
|
221
94
|
|
|
222
|
-
|
|
95
|
+
**ABIs:** `exports/abis/` - Contract ABIs as TypeScript constants
|
|
96
|
+
**Addresses:** `exports/address.config.ts` - Deployed contract addresses by chain
|
|
97
|
+
**Types:** `exports/address.types.ts` - Chain configurations and type definitions
|
|
223
98
|
|
|
224
|
-
|
|
99
|
+
```typescript
|
|
100
|
+
import { ADDRESS, StablecoinABI, MorphoAdapterV1ABI } from '@usdu-finance/usdu-core';
|
|
225
101
|
|
|
226
|
-
|
|
102
|
+
// Get mainnet addresses
|
|
103
|
+
const { usduStable, usduMorphoAdapterV1_2 } = ADDRESS[1];
|
|
227
104
|
|
|
228
|
-
|
|
105
|
+
// Use ABIs with contract instances
|
|
106
|
+
const stablecoin = new Contract(usduStable, StablecoinABI, provider);
|
|
107
|
+
```
|
|
229
108
|
|
|
230
|
-
###
|
|
109
|
+
### Package Publishing
|
|
231
110
|
|
|
232
|
-
|
|
111
|
+
1. **Update version** in `package.json` (semantic versioning)
|
|
112
|
+
2. **Build package:** `yarn npm:build` (uses tsup config)
|
|
113
|
+
3. **Publish:** `yarn npm:publish` (requires `npm login`)
|
|
233
114
|
|
|
234
|
-
|
|
115
|
+
**Next.js Integration:**
|
|
235
116
|
|
|
236
117
|
```js
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
transpilePackages: ['@wrtylabs/core', '@wrytelabs/api'],
|
|
118
|
+
// next.config.js
|
|
119
|
+
module.exports = {
|
|
120
|
+
transpilePackages: ['@usdu-finance/usdu-core'],
|
|
241
121
|
};
|
|
242
|
-
|
|
243
|
-
module.exports = nextConfig;
|
|
244
122
|
```
|