@paulstinchcombe/gasless-nft-tx 0.4.3 → 0.4.5
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 +15 -0
- package/package.json +2 -1
- package/src/KAMI-NFTs/README.md +361 -0
- package/src/KAMI-NFTs/artifacts/contracts/KAMI1155C.sol/KAMI1155C.dbg.json +4 -0
- package/src/KAMI-NFTs/artifacts/contracts/KAMI1155C.sol/KAMI1155C.json +1671 -0
- package/src/KAMI-NFTs/artifacts/contracts/KAMI721AC.sol/KAMI721AC.dbg.json +4 -0
- package/src/KAMI-NFTs/artifacts/contracts/KAMI721AC.sol/KAMI721AC.json +1632 -0
- package/src/KAMI-NFTs/artifacts/contracts/KAMI721C.sol/KAMI721C.dbg.json +4 -0
- package/src/KAMI-NFTs/artifacts/contracts/KAMI721C.sol/KAMI721C.json +1592 -0
- package/src/KAMI-NFTs/artifacts/contracts/libraries/KamiNFTCore.sol/IExists.dbg.json +4 -0
- package/src/KAMI-NFTs/artifacts/contracts/libraries/KamiNFTCore.sol/IExists.json +30 -0
- package/src/KAMI-NFTs/artifacts/contracts/libraries/KamiNFTCore.sol/KamiNFTCore.dbg.json +4 -0
- package/src/KAMI-NFTs/artifacts/contracts/libraries/KamiNFTCore.sol/KamiNFTCore.json +50 -0
- package/src/KAMI-NFTs/artifacts/contracts/libraries/KamiPlatform.sol/KamiPlatform.dbg.json +4 -0
- package/src/KAMI-NFTs/artifacts/contracts/libraries/KamiPlatform.sol/KamiPlatform.json +10 -0
- package/src/KAMI-NFTs/artifacts/contracts/libraries/KamiRental.sol/KamiRental.dbg.json +4 -0
- package/src/KAMI-NFTs/artifacts/contracts/libraries/KamiRental.sol/KamiRental.json +10 -0
- package/src/KAMI-NFTs/artifacts/contracts/libraries/KamiRoyalty.sol/KamiRoyalty.dbg.json +4 -0
- package/src/KAMI-NFTs/artifacts/contracts/libraries/KamiRoyalty.sol/KamiRoyalty.json +26 -0
- package/src/KAMI-NFTs/artifacts/contracts/libraries/KamiTransfer.sol/KamiTransfer.dbg.json +4 -0
- package/src/KAMI-NFTs/artifacts/contracts/libraries/KamiTransfer.sol/KamiTransfer.json +10 -0
package/README.md
CHANGED
|
@@ -20,6 +20,20 @@ A robust, production-ready TypeScript library that enables **gasless NFT transac
|
|
|
20
20
|
- **🛡️ Robust Error Handling**: Automatic retry and recovery mechanisms
|
|
21
21
|
- **🔮 Deterministic Addresses**: Predictable SimpleAccount addresses using CREATE2
|
|
22
22
|
|
|
23
|
+
## ⚠️ Important: Update to v0.4.4+
|
|
24
|
+
|
|
25
|
+
If you're deploying KAMI libraries and got "Contract artifact not found" errors, update immediately:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @paulstinchcombe/gasless-nft-tx@^0.4.4
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Fixed:** KAMI artifacts now properly included in npm package. See [Migration Guide](./docs/MIGRATION_v0.4.4.md).
|
|
32
|
+
|
|
33
|
+
### Next.js Users: Additional Step Required
|
|
34
|
+
|
|
35
|
+
If using Next.js and still getting artifact errors after updating, see **[Next.js Artifacts Fix](./docs/NEXTJS_ARTIFACTS_FIX.md)** - you need to configure Next.js to copy artifacts to the build output.
|
|
36
|
+
|
|
23
37
|
## 🎊 What's New in v0.4.0 - Per-Token Pricing & Enhanced APIs!
|
|
24
38
|
|
|
25
39
|
### 🔥 Major API Improvements
|
|
@@ -342,6 +356,7 @@ pnpm run dev
|
|
|
342
356
|
### KAMI NFT Documentation
|
|
343
357
|
|
|
344
358
|
- 🔴 **[API Migration Guide v0.4.0](./docs/KAMI_API_CHANGES_v0.4.0.md)** - **BREAKING CHANGES: Required for v0.3.x users!**
|
|
359
|
+
- ⚠️ **[Next.js Artifacts Fix](./docs/NEXTJS_ARTIFACTS_FIX.md)** - **REQUIRED for Next.js users!**
|
|
345
360
|
- 🆕 **[Enhanced Mint Results Guide](./docs/MINT_RESULTS_GUIDE.md)** - **NEW: Get tokenId from mint operations!**
|
|
346
361
|
- 🆕 **[Royalty System Guide](./docs/KAMI_ROYALTY_GUIDE.md)** - **NEW: Dual royalty system (mint vs transfer)**
|
|
347
362
|
- 🎯 **[Custodial Zero-Gas](./docs/KAMI_CUSTODIAL_ZERO_GAS.md)** - **BEST: ZERO user gas for custodial wallets!**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paulstinchcombe/gasless-nft-tx",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"description": "Library for gasless NFT transactions using SimpleAccount operations",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"files": [
|
|
38
38
|
"dist/**/*",
|
|
39
|
+
"src/KAMI-NFTs/artifacts/**/*",
|
|
39
40
|
"README.md"
|
|
40
41
|
],
|
|
41
42
|
"engines": {
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
# KAMI NFT Contracts
|
|
2
|
+
|
|
3
|
+
This folder contains the Solidity contracts for the KAMI NFT system, along with their compiled artifacts.
|
|
4
|
+
|
|
5
|
+
## Contracts
|
|
6
|
+
|
|
7
|
+
### Main Contracts
|
|
8
|
+
|
|
9
|
+
#### KAMI721C.sol
|
|
10
|
+
|
|
11
|
+
Standard ERC721 contract with advanced features:
|
|
12
|
+
|
|
13
|
+
- Traditional one-at-a-time minting
|
|
14
|
+
- ERC20 payment token integration
|
|
15
|
+
- Platform commission system
|
|
16
|
+
- Programmable royalties (mint & transfer)
|
|
17
|
+
- Time-based rental system
|
|
18
|
+
- Transfer validation
|
|
19
|
+
- Pausable functionality
|
|
20
|
+
- Role-based access control
|
|
21
|
+
|
|
22
|
+
**Standard**: ERC721, ERC721Enumerable, ERC2981, AccessControl, Pausable
|
|
23
|
+
|
|
24
|
+
#### KAMI721AC.sol
|
|
25
|
+
|
|
26
|
+
ERC721A-style contract with claiming features:
|
|
27
|
+
|
|
28
|
+
- One claim per address restriction
|
|
29
|
+
- Batch claiming (owner pays for all)
|
|
30
|
+
- Batch claiming (each recipient pays)
|
|
31
|
+
- All KAMI721C features included
|
|
32
|
+
- Optimized for airdrops and allowlists
|
|
33
|
+
|
|
34
|
+
**Standard**: ERC721, ERC721Enumerable, ERC2981, AccessControl, Pausable
|
|
35
|
+
|
|
36
|
+
#### KAMI1155C.sol
|
|
37
|
+
|
|
38
|
+
Multi-token ERC1155 contract:
|
|
39
|
+
|
|
40
|
+
- Multiple token types in one contract
|
|
41
|
+
- Fungible and non-fungible tokens
|
|
42
|
+
- Batch minting and burning
|
|
43
|
+
- Per-token-type tracking
|
|
44
|
+
- All rental and royalty features
|
|
45
|
+
- Ideal for gaming and utility tokens
|
|
46
|
+
|
|
47
|
+
**Standard**: ERC1155, ERC1155Supply, ERC2981, AccessControl, Pausable
|
|
48
|
+
|
|
49
|
+
### Shared Libraries
|
|
50
|
+
|
|
51
|
+
All three main contracts use these libraries to reduce code duplication and gas costs:
|
|
52
|
+
|
|
53
|
+
#### libraries/KamiNFTCore.sol
|
|
54
|
+
|
|
55
|
+
Core library providing:
|
|
56
|
+
|
|
57
|
+
- Data structure definitions (RoyaltyData, Rental, PlatformConfig, etc.)
|
|
58
|
+
- Storage slot management for proxy compatibility
|
|
59
|
+
- Role constants (OWNER_ROLE, PLATFORM_ROLE, RENTER_ROLE)
|
|
60
|
+
- Storage access functions
|
|
61
|
+
- Basic validation helpers
|
|
62
|
+
|
|
63
|
+
#### libraries/KamiPlatform.sol
|
|
64
|
+
|
|
65
|
+
Platform commission management:
|
|
66
|
+
|
|
67
|
+
- Initialize platform configuration
|
|
68
|
+
- Update commission percentage and address
|
|
69
|
+
- Distribute platform commission
|
|
70
|
+
- Validation (max 20% commission)
|
|
71
|
+
|
|
72
|
+
#### libraries/KamiRoyalty.sol
|
|
73
|
+
|
|
74
|
+
Royalty system management:
|
|
75
|
+
|
|
76
|
+
- Initialize royalty configuration
|
|
77
|
+
- Set global royalty percentage
|
|
78
|
+
- Set mint and transfer royalties
|
|
79
|
+
- Set token-specific royalties
|
|
80
|
+
- Distribute royalties automatically
|
|
81
|
+
- Get royalty receivers
|
|
82
|
+
|
|
83
|
+
#### libraries/KamiRental.sol
|
|
84
|
+
|
|
85
|
+
Token rental system:
|
|
86
|
+
|
|
87
|
+
- Rent tokens for specific durations
|
|
88
|
+
- End rentals early
|
|
89
|
+
- Extend rental periods
|
|
90
|
+
- Track rental status
|
|
91
|
+
- Validate rental operations
|
|
92
|
+
- Platform commission on rentals
|
|
93
|
+
|
|
94
|
+
#### libraries/KamiTransfer.sol
|
|
95
|
+
|
|
96
|
+
Transfer validation and sales:
|
|
97
|
+
|
|
98
|
+
- Validate transfers (rental protection)
|
|
99
|
+
- Process token sales
|
|
100
|
+
- Calculate transfer payments
|
|
101
|
+
- Distribute royalties on sales
|
|
102
|
+
- Track pending transfers
|
|
103
|
+
- Burn validation
|
|
104
|
+
|
|
105
|
+
## Key Features
|
|
106
|
+
|
|
107
|
+
### 🎨 Flexible Minting
|
|
108
|
+
|
|
109
|
+
- **KAMI721C**: Traditional minting
|
|
110
|
+
- **KAMI721AC**: Claiming mechanism
|
|
111
|
+
- **KAMI1155C**: Batch multi-token minting
|
|
112
|
+
|
|
113
|
+
### 💰 Payment Integration
|
|
114
|
+
|
|
115
|
+
- All contracts accept ERC20 payment tokens (e.g., USDC)
|
|
116
|
+
- Configurable mint/claim prices
|
|
117
|
+
- Automatic payment distribution
|
|
118
|
+
|
|
119
|
+
### 🏢 Platform Commission
|
|
120
|
+
|
|
121
|
+
- Configurable commission percentage (max 20%)
|
|
122
|
+
- Automatic commission on all paid operations
|
|
123
|
+
- Platform address can be updated
|
|
124
|
+
|
|
125
|
+
### 👑 Programmable Royalties
|
|
126
|
+
|
|
127
|
+
- Global royalty percentage
|
|
128
|
+
- Mint royalties (distributed on minting)
|
|
129
|
+
- Transfer royalties (distributed on sales)
|
|
130
|
+
- Token-specific royalty overrides
|
|
131
|
+
- Multiple royalty receivers per token
|
|
132
|
+
- Automatic distribution
|
|
133
|
+
|
|
134
|
+
### 🏠 Rental System
|
|
135
|
+
|
|
136
|
+
- Time-based token rentals
|
|
137
|
+
- Rental price configuration
|
|
138
|
+
- Extend rentals
|
|
139
|
+
- End rentals early
|
|
140
|
+
- Automatic role management (RENTER_ROLE)
|
|
141
|
+
- Transfer protection for rented tokens
|
|
142
|
+
|
|
143
|
+
### 🛡️ Access Control
|
|
144
|
+
|
|
145
|
+
- **OWNER_ROLE**: Manage contract settings
|
|
146
|
+
- **PLATFORM_ROLE**: Receive commission payments
|
|
147
|
+
- **RENTER_ROLE**: Assigned to active renters
|
|
148
|
+
|
|
149
|
+
### 🔐 Security Features
|
|
150
|
+
|
|
151
|
+
- Pausable in emergencies
|
|
152
|
+
- Transfer validation
|
|
153
|
+
- Rental protection (tokens can't be transferred while rented)
|
|
154
|
+
- Royalty enforcement
|
|
155
|
+
- Role-based permissions
|
|
156
|
+
|
|
157
|
+
## Contract Interactions
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
User → KAMI721C/KAMI721AC/KAMI1155C
|
|
161
|
+
↓
|
|
162
|
+
Libraries:
|
|
163
|
+
- KamiNFTCore (storage)
|
|
164
|
+
- KamiPlatform (commission)
|
|
165
|
+
- KamiRoyalty (royalties)
|
|
166
|
+
- KamiRental (rentals)
|
|
167
|
+
- KamiTransfer (sales)
|
|
168
|
+
↓
|
|
169
|
+
Payment Token (USDC)
|
|
170
|
+
↓
|
|
171
|
+
Distribution:
|
|
172
|
+
- Platform (commission)
|
|
173
|
+
- Royalty Receivers
|
|
174
|
+
- Token Owner
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Constructor Parameters
|
|
178
|
+
|
|
179
|
+
### KAMI721C & KAMI721AC
|
|
180
|
+
|
|
181
|
+
```solidity
|
|
182
|
+
constructor(
|
|
183
|
+
address paymentToken_, // ERC20 payment token
|
|
184
|
+
string memory name_, // NFT collection name
|
|
185
|
+
string memory symbol_, // NFT collection symbol
|
|
186
|
+
string memory baseTokenURI_, // Base URI for metadata
|
|
187
|
+
uint256 initialMintPrice_, // Initial mint/claim price
|
|
188
|
+
address platformAddress_, // Platform commission receiver
|
|
189
|
+
uint96 platformCommissionPercentage_ // Commission % in basis points
|
|
190
|
+
)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### KAMI1155C
|
|
194
|
+
|
|
195
|
+
```solidity
|
|
196
|
+
constructor(
|
|
197
|
+
address paymentToken_, // ERC20 payment token
|
|
198
|
+
string memory baseTokenURI_, // Base URI for metadata
|
|
199
|
+
uint256 initialMintPrice_, // Initial mint price
|
|
200
|
+
address platformAddress_, // Platform commission receiver
|
|
201
|
+
uint96 platformCommissionPercentage_ // Commission % in basis points
|
|
202
|
+
)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Royalty Configuration
|
|
206
|
+
|
|
207
|
+
Royalties use basis points (1/100th of a percent):
|
|
208
|
+
|
|
209
|
+
- 100 = 1%
|
|
210
|
+
- 1000 = 10%
|
|
211
|
+
- 10000 = 100%
|
|
212
|
+
|
|
213
|
+
When setting royalty receivers, the feeNumerator values must sum to exactly 10000:
|
|
214
|
+
|
|
215
|
+
```solidity
|
|
216
|
+
RoyaltyData[] memory royalties = [
|
|
217
|
+
RoyaltyData({ receiver: address1, feeNumerator: 5000 }), // 50%
|
|
218
|
+
RoyaltyData({ receiver: address2, feeNumerator: 3000 }), // 30%
|
|
219
|
+
RoyaltyData({ receiver: address3, feeNumerator: 2000 }) // 20%
|
|
220
|
+
];
|
|
221
|
+
// Total: 10000 (100%) ✓
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Platform Commission Limits
|
|
225
|
+
|
|
226
|
+
- Minimum: 0 basis points (0%)
|
|
227
|
+
- Maximum: 2000 basis points (20%)
|
|
228
|
+
- Applied to: mints, claims, rentals, and sales
|
|
229
|
+
|
|
230
|
+
## Rental Flow
|
|
231
|
+
|
|
232
|
+
1. User calls `rentToken(tokenId, duration, rentalPrice)`
|
|
233
|
+
2. Contract transfers payment from user to:
|
|
234
|
+
- Platform (commission)
|
|
235
|
+
- Token owner (remainder)
|
|
236
|
+
3. Rental is created with start and end times
|
|
237
|
+
4. User is granted RENTER_ROLE
|
|
238
|
+
5. Token cannot be transferred while rented
|
|
239
|
+
6. Rental can be extended or ended early
|
|
240
|
+
7. RENTER_ROLE revoked when no active rentals
|
|
241
|
+
|
|
242
|
+
## Sales Flow
|
|
243
|
+
|
|
244
|
+
1. User calls `sellToken(to, tokenId, salePrice)`
|
|
245
|
+
2. Token is transferred to buyer
|
|
246
|
+
3. Contract processes payment:
|
|
247
|
+
- Platform commission
|
|
248
|
+
- Transfer royalties
|
|
249
|
+
- Seller receives remainder
|
|
250
|
+
4. All payments handled automatically
|
|
251
|
+
|
|
252
|
+
## Library Benefits
|
|
253
|
+
|
|
254
|
+
Using shared libraries provides:
|
|
255
|
+
|
|
256
|
+
- **Reduced Gas**: No duplicate code in each contract
|
|
257
|
+
- **Consistency**: Same logic across all contracts
|
|
258
|
+
- **Maintainability**: Update logic in one place
|
|
259
|
+
- **Reusability**: Deploy once, use in many contracts
|
|
260
|
+
|
|
261
|
+
## Deployment
|
|
262
|
+
|
|
263
|
+
Libraries must be deployed before main contracts and linked during deployment. The TypeScript library handles this automatically.
|
|
264
|
+
|
|
265
|
+
### Using TypeScript Library
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
import { deployKAMI721C } from '../index';
|
|
269
|
+
|
|
270
|
+
// Automatically handles library deployment and linking
|
|
271
|
+
const deployment = await deployKAMI721C(signer, params);
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Manual Deployment (Advanced)
|
|
275
|
+
|
|
276
|
+
1. Deploy all 5 libraries
|
|
277
|
+
2. Link libraries in main contract bytecode
|
|
278
|
+
3. Deploy main contract with linked bytecode
|
|
279
|
+
|
|
280
|
+
## Artifacts
|
|
281
|
+
|
|
282
|
+
The `artifacts/` folder contains compiled contract artifacts:
|
|
283
|
+
|
|
284
|
+
- ABI (Application Binary Interface)
|
|
285
|
+
- Bytecode
|
|
286
|
+
- Debug information
|
|
287
|
+
- Metadata
|
|
288
|
+
|
|
289
|
+
These are generated by Hardhat/Foundry during compilation.
|
|
290
|
+
|
|
291
|
+
## Dependencies
|
|
292
|
+
|
|
293
|
+
### OpenZeppelin Contracts
|
|
294
|
+
|
|
295
|
+
- ERC721, ERC721Enumerable
|
|
296
|
+
- ERC1155, ERC1155Supply
|
|
297
|
+
- ERC2981 (Royalty Standard)
|
|
298
|
+
- ERC20, SafeERC20
|
|
299
|
+
- AccessControl
|
|
300
|
+
- Pausable
|
|
301
|
+
- Counters
|
|
302
|
+
|
|
303
|
+
### Solidity Version
|
|
304
|
+
|
|
305
|
+
- `^0.8.24` (KAMI721C, KAMI721AC, KAMI1155C)
|
|
306
|
+
- `^0.8.20` (Libraries)
|
|
307
|
+
|
|
308
|
+
## Testing
|
|
309
|
+
|
|
310
|
+
Tests should cover:
|
|
311
|
+
|
|
312
|
+
- Deployment and initialization
|
|
313
|
+
- Minting/claiming
|
|
314
|
+
- Rentals (create, extend, end)
|
|
315
|
+
- Sales with royalty distribution
|
|
316
|
+
- Platform commission
|
|
317
|
+
- Role management
|
|
318
|
+
- Pause functionality
|
|
319
|
+
- Edge cases (rental protection, royalty sum validation, etc.)
|
|
320
|
+
|
|
321
|
+
## Gas Optimization
|
|
322
|
+
|
|
323
|
+
The contracts use several gas optimization techniques:
|
|
324
|
+
|
|
325
|
+
- Library usage (code reuse)
|
|
326
|
+
- Immutable variables where possible
|
|
327
|
+
- Efficient storage patterns
|
|
328
|
+
- Batch operations (KAMI1155C, KAMI721AC)
|
|
329
|
+
- Counter optimization
|
|
330
|
+
|
|
331
|
+
## Security Considerations
|
|
332
|
+
|
|
333
|
+
1. **Reentrancy**: Uses SafeERC20 for token transfers
|
|
334
|
+
2. **Access Control**: Role-based permissions
|
|
335
|
+
3. **Rental Protection**: Prevents transfer of rented tokens
|
|
336
|
+
4. **Input Validation**: Extensive require statements
|
|
337
|
+
5. **Pausable**: Emergency stop mechanism
|
|
338
|
+
6. **Royalty Validation**: Ensures royalties sum to 100%
|
|
339
|
+
7. **Commission Limits**: Platform commission capped at 20%
|
|
340
|
+
|
|
341
|
+
## Future Enhancements
|
|
342
|
+
|
|
343
|
+
Possible future additions:
|
|
344
|
+
|
|
345
|
+
- Rental marketplace
|
|
346
|
+
- Auction functionality
|
|
347
|
+
- Staking mechanisms
|
|
348
|
+
- Cross-chain bridging
|
|
349
|
+
- Upgradeable versions
|
|
350
|
+
|
|
351
|
+
## Support
|
|
352
|
+
|
|
353
|
+
For integration help, see:
|
|
354
|
+
|
|
355
|
+
- [TypeScript API Documentation](../../docs/KAMI_NFT_INTEGRATION.md)
|
|
356
|
+
- [Quick Start Guide](../../docs/KAMI_QUICK_START.md)
|
|
357
|
+
- [Complete Example](../../examples/kami-nft-complete-example.ts)
|
|
358
|
+
|
|
359
|
+
## License
|
|
360
|
+
|
|
361
|
+
MIT License
|