Skip to content

Commit b0b9a8c

Browse files
committed
Enhance staking module with Move integration and improved data structures
- Refactor staking constants to align with Move specifications. - Introduce EnhancedStakedNode and StakingPoolManager for better state management. - Implement enhanced staking and unstaking functions with Move-aligned validation. - Update reward distribution logic to support Move-based calculations. - Enhance storage functions for improved state persistence. - Add new utility functions for penalty calculation and validator management. - Ensure thread-safe access to staking data with updated locking mechanisms.
1 parent 15eb942 commit b0b9a8c

10 files changed

Lines changed: 1800 additions & 532 deletions

File tree

crates/rpc/rpc-api/1.Blockchain.md

Lines changed: 107 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ curl -X POST -H "Content-Type: application/json" -d '{
122122
}' http://192.168.1.103:30030
123123
```
124124

125-
## 10. Staking Operations
125+
## 10. Enhanced Staking Operations
126126

127-
### 10.1 Stake Tokens
128-
Stake KARI tokens to run a node or become a validator:
127+
### 10.1 Stake Tokens (Enhanced with Move Integration)
128+
Stake KARI tokens to run a node or become a validator with Move smart contract integration:
129129
```bash
130130
curl -X POST -H "Content-Type: application/json" -d '{
131131
"jsonrpc": "2.0",
@@ -134,36 +134,56 @@ curl -X POST -H "Content-Type: application/json" -d '{
134134
"address": "YOUR_ACCOUNT_ADDRESS",
135135
"amount": 200.0,
136136
"password": "WALLET_PASSWORD",
137-
"validator": true
137+
"validator": true,
138+
"use_move_integration": true
138139
},
139140
"id": 1
140141
}' http://192.168.1.103:30030
141142
```
142143

143-
- Minimum amount for running a node: 200 KARI
144-
- Minimum amount for becoming a validator: 32 KARI
145-
- Setting `validator` to `true` will make the node eligible for staking rewards (0.01%)
146-
- All staked tokens have a 24-hour lock period
147-
148-
### 10.2 Unstake Tokens
149-
Withdraw your staked KARI tokens (plus rewards if a validator):
144+
**Enhanced Staking Requirements:**
145+
- Minimum amount for running a node: **200 KARI** (200,000,000,000 KA)
146+
- Minimum amount for becoming a validator: **32 KARI** (32,000,000,000 KA)
147+
- Setting `validator` to `true` enables validator rewards with 5% default commission
148+
- All staked tokens have a **24-hour lock period**
149+
- Move integration provides enhanced security and smart contract functionality
150+
- Validators earn **0.01% annual rewards** distributed proportionally based on stake
151+
152+
**Response includes:**
153+
- `commission_rate`: Validator commission rate (500 basis points = 5%)
154+
- `move_object_id`: Move smart contract object ID (if Move integration enabled)
155+
- `security_hash`: Cryptographic security hash for the staking position
156+
- `delegated_stake`: Amount delegated to this validator
157+
- `penalty_rate`: Early unstaking penalty rate (10%)
158+
159+
### 10.2 Enhanced Unstake Tokens
160+
Withdraw your staked KARI tokens with enhanced penalty calculation:
150161
```bash
151162
curl -X POST -H "Content-Type: application/json" -d '{
152163
"jsonrpc": "2.0",
153164
"method": "unstake_tokens",
154165
"params": {
155166
"address": "YOUR_ACCOUNT_ADDRESS",
156-
"password": "WALLET_PASSWORD"
167+
"password": "WALLET_PASSWORD",
168+
"force": false
157169
},
158170
"id": 1
159171
}' http://192.168.1.103:30030
160172
```
161173

162-
- Early unstaking (before lock period ends) will incur a 10% penalty
163-
- Validators will receive accumulated rewards when unstaking
174+
**Enhanced Unstaking Features:**
175+
- `force` parameter allows early unstaking with 10% penalty (1000 basis points)
176+
- Normal unstaking after 24-hour lock period has no penalty
177+
- Validators receive accumulated rewards when unstaking
178+
- Early unstaking penalty is calculated using Move-aligned formula: `(amount * 1000) / 10000`
164179

165-
### 10.3 Get Staking Info
166-
Check your staking status and rewards:
180+
**Response includes:**
181+
- `penalty`: Penalty amount if unstaking early (0 if after lock period)
182+
- `force_unstake`: Whether force unstaking was used
183+
- Detailed breakdown of withdrawn amount, rewards, and penalties
184+
185+
### 10.3 Enhanced Staking Info
186+
Check your staking status with comprehensive details:
167187
```bash
168188
curl -X POST -H "Content-Type: application/json" -d '{
169189
"jsonrpc": "2.0",
@@ -173,8 +193,17 @@ curl -X POST -H "Content-Type: application/json" -d '{
173193
}' http://192.168.1.103:30030
174194
```
175195

176-
### 10.4 Get Staking Statistics
177-
Get network-wide staking information:
196+
**Enhanced Response includes:**
197+
- `commission_rate`: Current validator commission rate
198+
- `delegated_stake`: Amount delegated to this validator
199+
- `move_object_id`: Move smart contract object ID
200+
- `security_hash`: Position security hash
201+
- `estimated_daily_reward`: Estimated daily rewards for validators
202+
- `lock_period_remaining_hours`: Hours remaining in lock period
203+
- `early_unstake_penalty`: Calculated penalty for early unstaking
204+
205+
### 10.4 Enhanced Staking Statistics
206+
Get comprehensive network-wide staking information:
178207
```bash
179208
curl -X POST -H "Content-Type: application/json" -d '{
180209
"jsonrpc": "2.0",
@@ -184,6 +213,29 @@ curl -X POST -H "Content-Type: application/json" -d '{
184213
}' http://192.168.1.103:30030
185214
```
186215

216+
**Enhanced Statistics include:**
217+
- **Pool State**: Total staked, validator/node counts, reward rate, last reward epoch
218+
- **Validator Details**: Complete validator list with stake amounts, commission rates, active status
219+
- **Requirements**: Move-aligned minimum stake requirements
220+
- **Parameters**: Lock period (24 hours), penalty rate (10%), reward rate (0.01% annual)
221+
- **Move Integration**: Current Move integration status
222+
223+
### 10.5 Claim Rewards (New)
224+
Check claimable rewards for your staking position:
225+
```bash
226+
curl -X POST -H "Content-Type: application/json" -d '{
227+
"jsonrpc": "2.0",
228+
"method": "claim_rewards",
229+
"params": ["YOUR_ACCOUNT_ADDRESS"],
230+
"id": 1
231+
}' http://192.168.1.103:30030
232+
```
233+
234+
**Features:**
235+
- Check accumulated rewards without claiming
236+
- Indicates if rewards are available for claiming
237+
- Provides formatted reward amounts in both KA and KARI units
238+
187239
## Placeholders
188240
Replace these placeholders with actual values when making requests:
189241
- `YOUR_ACCOUNT_ADDRESS`: Your wallet address
@@ -237,16 +289,43 @@ Gas fees range from a minimum of 0.000000002 KARI to a maximum of 0.000000050 KA
237289

238290
To prioritize your transaction, you can add the optional `priority_boost` parameter when making transfers.
239291

240-
## Staking System
241-
242-
The Kanari network uses a Proof of Stake (PoS) consensus mechanism where:
243-
244-
- Users must stake at least 200 KARI to run a node
245-
- Validators must stake at least 32 KARI and opt in to validation
246-
- Validators receive a 0.01% annual reward on their staked amount
247-
- Rewards are drawn from the token pool at address: `0x47621776628ba3a5b9baaab38e61f4c98e893e124204bc4dad52e702e2b24ea1`
248-
- All staked tokens have a 24-hour lock period
249-
- Early unstaking incurs a 10% penalty
292+
## Enhanced Staking System
293+
294+
The Kanari network uses an enhanced Proof of Stake (PoS) consensus mechanism with Move smart contract integration:
295+
296+
### Core Features:
297+
- **Move Integration**: Enhanced security through Move smart contract validation
298+
- **Dual Staking Tiers**: Node operators (200 KARI minimum) and Validators (32 KARI minimum)
299+
- **Proportional Rewards**: Validators earn 0.01% annual rewards based on their stake
300+
- **Commission System**: Validators earn 5% commission on delegated stakes
301+
- **Security**: Each staking position has a unique cryptographic security hash
302+
303+
### Economic Parameters:
304+
- **Minimum Node Stake**: 200 KARI (200,000,000,000 KA)
305+
- **Minimum Validator Stake**: 32 KARI (32,000,000,000 KA)
306+
- **Lock Period**: 24 hours (86,400,000 milliseconds)
307+
- **Early Unstake Penalty**: 10% (1000 basis points)
308+
- **Validator Commission**: 5% (500 basis points)
309+
- **Annual Reward Rate**: 0.01% (1 basis point)
310+
311+
### Reward Distribution:
312+
- Rewards are distributed daily (epoch-based)
313+
- Validators receive rewards proportional to their stake
314+
- Commission is deducted for delegated stakes
315+
- Rewards are drawn from the pool at: `0x47621776628ba3a5b9baaab38e61f4c98e893e124204bc4dad52e702e2b24ea1`
316+
317+
### Move Smart Contract Benefits:
318+
- Enhanced transaction validation
319+
- Immutable staking rules
320+
- Automated penalty calculation
321+
- Transparent reward distribution
322+
- Cross-chain compatibility
323+
324+
### Validator Requirements:
325+
- Minimum 32 KARI stake
326+
- 24-hour commitment period
327+
- Network participation requirements
328+
- Commission rate disclosure (default 5%)
250329

251330
## Security Note
252331

crates/rpc/rpc-api/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod get_block;
1010
mod accounts;
1111
mod move_api; // Add the new module
1212

13-
use stake::{get_staking_info, get_staking_stats, stake_tokens, unstake_tokens};
13+
use stake::{get_staking_info, get_staking_stats, stake_tokens, unstake_tokens, claim_rewards};
1414
use get_block::{
1515
get_all_blocks,
1616
get_account_details,
@@ -134,6 +134,11 @@ pub async fn start_rpc_server(network_config: NetworkConfig) -> Result<(), tokio
134134
futures::future::ready(get_staking_stats(params)).boxed()
135135
});
136136

137+
// Add enhanced staking operations
138+
io.add_method("claim_rewards", |params| {
139+
futures::future::ready(claim_rewards(params)).boxed()
140+
});
141+
137142
// Add Move VM operations
138143
io.add_method("list_modules", |params| {
139144
futures::future::ready(list_modules(params)).boxed()

0 commit comments

Comments
 (0)