Skip to content

Commit b72dbce

Browse files
committed
feat: Complete 1DEV burn contract with Phase 2 transition logic
- Add execute_phase_transition() function for Phase 1 → Phase 2 transition - Fix genesis_timestamp to use network genesis block (parameter in initialize) - Fix burn_percentage updates in record_burn function - Remove unused structures (PhaseTransitionRecord, QNCRewardClaimRecord) - Add proper constraint checks for phase_transitioned state - Implement correct dynamic pricing: 1500 → 150 1DEV based on burn % - Add TransitionNotReady error for premature transition attempts - Contract blocks 1DEV activation after 90% burned OR 5 years from genesis - All comments and code in English as required - Ready for immutable deployment on Solana devnet Functions: ✅ initialize() - with network_genesis_timestamp parameter ✅ burn_1dev_for_node_activation() - Phase 1 activation (blocked after transition) ✅ record_burn() - burn transaction recording with burn_percentage updates ✅ get_burn_stats() - comprehensive statistics with transition status ✅ execute_phase_transition() - triggers Phase 2 transition when conditions met Economic Model: ✅ Phase 1: Dynamic 1DEV pricing (1500 → 150 based on burn %) ✅ Phase 2: QNC Pool #3 system (separate contract) ✅ Transition: 90% burned OR 5 years since network genesis block ✅ All node types cost same amount in Phase 1 (universal pricing) Contract compiles successfully and ready for production deployment.
1 parent 69eaf1e commit b72dbce

13 files changed

Lines changed: 466 additions & 83 deletions

File tree

ARCHIVE/development/IMPLEMENTATION_LOG_2025.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Good progress on micro/macro block architecture. Foundation is solid, but needs
101101

102102
## Session: Production Security & RPC Integration Completion
103103

104-
### Date: January 7, 2025
104+
### Date: July 22, 2025
105105

106106
### Work Completed
107107

check_and_deploy_new.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/bash
2+
3+
export PATH="/root/.cargo/bin:/usr/local/bin:$PATH"
4+
5+
echo "🔍 Checking current program and deploying new upgradeable version..."
6+
7+
# Set up main wallet
8+
echo '[98,54,150,232,151,114,95,85,54,178,29,20,13,43,209,232,68,64,73,82,48,149,22,59,253,195,246,33,65,247,32,168,84,114,232,9,201,117,109,12,111,218,239,66,214,123,83,48,43,27,78,236,7,237,231,68,120,247,80,1,162,166,118,181]' > /root/deploy_wallet.json
9+
10+
/root/.cargo/bin/solana config set --keypair /root/deploy_wallet.json --url devnet
11+
12+
echo "📋 Wallet address:"
13+
/root/.cargo/bin/solana address
14+
15+
echo "💰 Current balance:"
16+
/root/.cargo/bin/solana balance
17+
18+
echo ""
19+
echo "🔍 Checking existing program vLYG5buWMnRCdxykgRQks84dPYJ2D5dareoNoq9mMEg..."
20+
PROGRAM_INFO=$(/root/.cargo/bin/solana program show vLYG5buWMnRCdxykgRQks84dPYJ2D5dareoNoq9mMEg --url devnet 2>&1)
21+
echo "$PROGRAM_INFO"
22+
23+
echo ""
24+
echo "🔍 Checking if it's deployed with BPF Loader 2 or BPF Loader Upgradeable..."
25+
26+
# Navigate to contract directory
27+
cd /root/QNet-Blockchain/development/qnet-contracts/1dev-burn-contract
28+
29+
echo "📂 Current directory: $(pwd)"
30+
31+
echo ""
32+
echo "🚀 Deploying NEW UPGRADEABLE program..."
33+
echo "⏳ This will create a new Program ID with upgrade authority..."
34+
35+
# Deploy as new upgradeable program
36+
DEPLOY_OUTPUT=$(/root/.cargo/bin/solana program deploy target/deploy/onedev_burn_contract.so --keypair /root/deploy_wallet.json --url devnet --program-id /root/deploy_wallet.json --upgrade-authority /root/deploy_wallet.json 2>&1)
37+
echo "$DEPLOY_OUTPUT"
38+
39+
# Extract new program ID
40+
NEW_PROGRAM_ID=$(echo "$DEPLOY_OUTPUT" | grep -o 'Program Id: [A-Za-z0-9]*' | sed 's/Program Id: //')
41+
42+
if [ -n "$NEW_PROGRAM_ID" ] && [ ${#NEW_PROGRAM_ID} -eq 44 ]; then
43+
echo ""
44+
echo "🎉🎉🎉 NEW UPGRADEABLE CONTRACT DEPLOYED! 🎉🎉🎉"
45+
echo "✅ New Program ID: $NEW_PROGRAM_ID"
46+
echo "✅ Upgrade Authority: $(solana address)"
47+
echo "✅ Contract is now upgradeable!"
48+
49+
echo ""
50+
echo "💰 Final balance:"
51+
/root/.cargo/bin/solana balance
52+
53+
echo ""
54+
echo "🔍 Verify new program on Solscan:"
55+
echo "https://solscan.io/address/$NEW_PROGRAM_ID?cluster=devnet"
56+
57+
echo ""
58+
echo "📋 NEXT STEPS:"
59+
echo "1. Update all config files with new Program ID: $NEW_PROGRAM_ID"
60+
echo "2. Update documentation"
61+
echo "3. Test the new contract"
62+
63+
echo ""
64+
echo "🎯 NEW PROGRAM DEPLOYED - READY FOR FUTURE UPGRADES!"
65+
66+
else
67+
echo ""
68+
echo "❌ Deployment failed or couldn't extract Program ID!"
69+
echo "Full deploy output: $DEPLOY_OUTPUT"
70+
71+
echo ""
72+
echo "🔄 Trying alternative deployment method..."
73+
74+
# Alternative: generate new keypair for program
75+
/root/.cargo/bin/solana-keygen new --outfile /root/new_program_keypair.json --no-bip39-passphrase
76+
77+
ALT_DEPLOY_OUTPUT=$(/root/.cargo/bin/solana program deploy target/deploy/onedev_burn_contract.so --keypair /root/deploy_wallet.json --url devnet --program-id /root/new_program_keypair.json --upgrade-authority /root/deploy_wallet.json 2>&1)
78+
echo "$ALT_DEPLOY_OUTPUT"
79+
80+
ALT_PROGRAM_ID=$(echo "$ALT_DEPLOY_OUTPUT" | grep -o 'Program Id: [A-Za-z0-9]*' | sed 's/Program Id: //')
81+
82+
if [ -n "$ALT_PROGRAM_ID" ]; then
83+
echo "✅ Alternative deployment successful!"
84+
echo "✅ New Program ID: $ALT_PROGRAM_ID"
85+
else
86+
echo "❌ Both deployment methods failed"
87+
fi
88+
89+
rm -f /root/new_program_keypair.json
90+
fi
91+
92+
# Cleanup
93+
rm -f /root/deploy_wallet.json
94+
95+
echo ""
96+
echo "✅ Deployment process completed"

deploy_immutable.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
3+
export PATH="/root/.cargo/bin:/usr/local/bin:$PATH"
4+
5+
echo "🚀 Deploying NEW IMMUTABLE contract..."
6+
7+
# Set up main wallet
8+
echo '[98,54,150,232,151,114,95,85,54,178,29,20,13,43,209,232,68,64,73,82,48,149,22,59,253,195,246,33,65,247,32,168,84,114,232,9,201,117,109,12,111,218,239,66,214,123,83,48,43,27,78,236,7,237,231,68,120,247,80,1,162,166,118,181]' > /root/deploy_wallet.json
9+
10+
/root/.cargo/bin/solana config set --keypair /root/deploy_wallet.json --url devnet
11+
12+
echo "📋 Wallet address:"
13+
/root/.cargo/bin/solana address
14+
15+
echo "💰 Current balance:"
16+
BALANCE=$(/root/.cargo/bin/solana balance)
17+
echo $BALANCE
18+
19+
# Navigate to contract directory
20+
cd /root/QNet-Blockchain/development/qnet-contracts/1dev-burn-contract
21+
22+
echo "📂 Current directory: $(pwd)"
23+
echo "📋 Contract file:"
24+
ls -la target/deploy/onedev_burn_contract.so
25+
26+
echo ""
27+
echo "🚀 Deploying as IMMUTABLE program (no upgrade authority)..."
28+
echo "⏳ This will create a new Program ID that cannot be changed..."
29+
30+
# Deploy as immutable program (no --upgrade-authority parameter)
31+
DEPLOY_OUTPUT=$(/root/.cargo/bin/solana program deploy target/deploy/onedev_burn_contract.so --keypair /root/deploy_wallet.json --url devnet 2>&1)
32+
echo "$DEPLOY_OUTPUT"
33+
34+
# Extract new program ID
35+
NEW_PROGRAM_ID=$(echo "$DEPLOY_OUTPUT" | grep -E "Program Id: [A-Za-z0-9]{32,}" | sed 's/.*Program Id: \([A-Za-z0-9]*\).*/\1/')
36+
37+
if [ -n "$NEW_PROGRAM_ID" ] && [ ${#NEW_PROGRAM_ID} -eq 44 ]; then
38+
echo ""
39+
echo "🎉🎉🎉 IMMUTABLE CONTRACT DEPLOYED SUCCESSFULLY! 🎉🎉🎉"
40+
echo "✅ New Program ID: $NEW_PROGRAM_ID"
41+
echo "✅ Contract is IMMUTABLE (cannot be upgraded)"
42+
echo "✅ Lower deployment cost than upgradeable programs"
43+
44+
echo ""
45+
echo "💰 Final balance:"
46+
/root/.cargo/bin/solana balance
47+
48+
echo ""
49+
echo "🔍 Verify new program on Solscan:"
50+
echo "https://solscan.io/address/$NEW_PROGRAM_ID?cluster=devnet"
51+
52+
echo ""
53+
echo "📋 IMPORTANT - UPDATE THESE FILES WITH NEW PROGRAM ID:"
54+
echo "- README.md"
55+
echo "- documentation/technical/ECONOMIC_MODEL.md"
56+
echo "- documentation/technical/NODE_ACTIVATION_ARCHITECTURE.md"
57+
echo "- infrastructure/config/config.ini"
58+
echo "- development/qnet-contracts/1dev-burn-contract/src/lib.rs"
59+
echo "- development/qnet-contracts/simple-burn-tracker/src/lib.rs"
60+
echo "- development/qnet-integration/src/bin/qnet-node.rs"
61+
echo "- development/qnet-contracts/production-deploy.bat"
62+
63+
echo ""
64+
echo "🎯 DEPLOYMENT COMPLETE - IMMUTABLE CONTRACT READY!"
65+
66+
# Show program info
67+
echo ""
68+
echo "📋 Program information:"
69+
/root/.cargo/bin/solana program show $NEW_PROGRAM_ID --url devnet
70+
71+
else
72+
echo ""
73+
echo "❌ Deployment failed or couldn't extract Program ID!"
74+
echo "Full deploy output: $DEPLOY_OUTPUT"
75+
76+
echo ""
77+
echo "🔍 Current balance for troubleshooting:"
78+
/root/.cargo/bin/solana balance
79+
80+
echo ""
81+
echo "💡 Possible issues:"
82+
echo "- Insufficient SOL balance"
83+
echo "- Network connectivity"
84+
echo "- Contract compilation issues"
85+
fi
86+
87+
# Cleanup
88+
rm -f /root/deploy_wallet.json
89+
90+
echo ""
91+
echo "✅ Deployment process completed"

development/qnet-contracts/1dev-burn-contract/src/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ pub enum BurnError {
3030
DuplicateBurnTransaction,
3131
#[msg("Invalid burner address")]
3232
InvalidBurner,
33+
#[msg("Phase transition conditions not met")]
34+
TransitionNotReady,
3335
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use anchor_lang::prelude::*;
2+
use crate::state::*;
3+
use crate::errors::BurnError;
4+
5+
#[derive(Accounts)]
6+
pub struct ExecutePhaseTransition<'info> {
7+
#[account(
8+
mut,
9+
seeds = [BURN_TRACKER_SEED],
10+
bump = burn_tracker.bump,
11+
constraint = !burn_tracker.phase_transitioned @ BurnError::PhaseTransitioned
12+
)]
13+
pub burn_tracker: Account<'info, BurnTracker>,
14+
15+
/// Anyone can call this function when transition conditions are met
16+
pub caller: Signer<'info>,
17+
}
18+
19+
pub fn handler(ctx: Context<ExecutePhaseTransition>) -> Result<()> {
20+
let burn_tracker = &mut ctx.accounts.burn_tracker;
21+
let clock = Clock::get()?;
22+
23+
// Check transition conditions: 90% burned OR 5 years elapsed since genesis
24+
require!(
25+
burn_tracker.should_transition(),
26+
BurnError::TransitionNotReady
27+
);
28+
29+
// Execute Phase 2 transition
30+
burn_tracker.phase_transitioned = true;
31+
burn_tracker.last_update = clock.unix_timestamp;
32+
33+
msg!("🚀 PHASE 2 TRANSITION EXECUTED!");
34+
msg!("✅ 1DEV burn activation is now PERMANENTLY DISABLED");
35+
msg!("✅ QNC Pool #3 activation system is now ACTIVE");
36+
msg!("📊 Final burn percentage: {:.2}%", burn_tracker.burn_percentage);
37+
msg!("📊 Total 1DEV burned: {} tokens", burn_tracker.total_1dev_burned);
38+
msg!("📊 Total nodes activated in Phase 1: {}", burn_tracker.total_nodes_activated);
39+
40+
// Calculate days elapsed for logging
41+
let days_elapsed = (clock.unix_timestamp - burn_tracker.genesis_timestamp) / 86400;
42+
msg!("⏱️ Days since genesis: {}", days_elapsed);
43+
44+
if burn_tracker.burn_percentage >= 90.0 {
45+
msg!("🔥 Transition triggered by: 90% burn threshold reached");
46+
} else {
47+
msg!("⏰ Transition triggered by: 5-year time limit reached");
48+
}
49+
50+
Ok(())
51+
}

development/qnet-contracts/1dev-burn-contract/src/instructions/initialize.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub fn handler(
2424
admin: Pubkey,
2525
burn_address: Pubkey,
2626
one_dev_mint: Pubkey,
27+
network_genesis_timestamp: i64,
2728
) -> Result<()> {
2829
let burn_tracker = &mut ctx.accounts.burn_tracker;
2930
let clock = Clock::get()?;
@@ -32,7 +33,11 @@ pub fn handler(
3233
burn_tracker.admin = admin;
3334
burn_tracker.burn_address = burn_address;
3435
burn_tracker.one_dev_mint = one_dev_mint;
35-
burn_tracker.genesis_timestamp = clock.unix_timestamp;
36+
37+
// Set genesis_timestamp as QNet network genesis block time (passed as parameter)
38+
// This is the REAL genesis block timestamp for 5-year Phase 2 limit calculation
39+
burn_tracker.genesis_timestamp = network_genesis_timestamp;
40+
3641
burn_tracker.total_1dev_burned = 0;
3742
burn_tracker.total_burn_transactions = 0;
3843
burn_tracker.total_nodes_activated = 0;
@@ -48,6 +53,7 @@ pub fn handler(
4853
msg!("Burn tracker initialized");
4954
msg!("Authority: {}", burn_tracker.authority);
5055
msg!("Burn address: {}", burn_tracker.burn_address);
56+
msg!("Genesis timestamp: {}", burn_tracker.genesis_timestamp);
5157

5258
Ok(())
5359
}

development/qnet-contracts/1dev-burn-contract/src/instructions/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ pub mod initialize;
22
pub mod record_burn;
33
pub mod get_burn_stats;
44
pub mod burn_1dev_for_node_activation;
5+
pub mod execute_phase_transition;
56

67
pub use initialize::*;
78
pub use record_burn::*;
89
pub use get_burn_stats::*;
9-
pub use burn_1dev_for_node_activation::*;
10+
pub use burn_1dev_for_node_activation::*;
11+
pub use execute_phase_transition::*;

development/qnet-contracts/1dev-burn-contract/src/instructions/record_burn.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ pub fn handler(
4444
.checked_add(amount)
4545
.ok_or(BurnError::Overflow)?;
4646
burn_tracker.total_burn_transactions += 1;
47+
48+
// Update burn_percentage in burn_tracker
49+
burn_tracker.update_burn_percentage();
4750
burn_tracker.last_update = clock.unix_timestamp;
4851

4952
// Create burn record
@@ -56,13 +59,10 @@ pub fn handler(
5659
burn_record.verified = true;
5760
burn_record.bump = ctx.bumps.burn_record;
5861

59-
// Calculate burn percentage
60-
let burn_percentage = (burn_tracker.total_1dev_burned as f64 / ONE_DEV_TOTAL_SUPPLY as f64) * 100.0;
61-
6262
msg!("Burn recorded successfully");
6363
msg!("Amount: {} 1DEV", amount);
6464
msg!("Total burned: {} 1DEV", burn_tracker.total_1dev_burned);
65-
msg!("Burn percentage: {:.2}%", burn_percentage);
65+
msg!("Burn percentage: {:.2}%", burn_tracker.burn_percentage);
6666

6767
Ok(())
6868
}

development/qnet-contracts/1dev-burn-contract/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ pub mod onedev_burn_contract {
2020
admin: Pubkey,
2121
burn_address: Pubkey,
2222
one_dev_mint: Pubkey,
23+
network_genesis_timestamp: i64,
2324
) -> Result<()> {
24-
initialize::handler(ctx, authority, admin, burn_address, one_dev_mint)
25+
initialize::handler(ctx, authority, admin, burn_address, one_dev_mint, network_genesis_timestamp)
2526
}
2627

2728
/// Record a 1DEV burn transaction for node activation
@@ -48,4 +49,9 @@ pub mod onedev_burn_contract {
4849
pub fn get_burn_stats(ctx: Context<GetBurnStats>) -> Result<BurnStatistics> {
4950
get_burn_stats::handler(ctx)
5051
}
52+
53+
/// Execute Phase 2 transition (disable 1DEV activation, enable QNC Pool #3)
54+
pub fn execute_phase_transition(ctx: Context<ExecutePhaseTransition>) -> Result<()> {
55+
execute_phase_transition::handler(ctx)
56+
}
5157
}

0 commit comments

Comments
 (0)