This guide covers the deployment and testing of the new threshold management system for Paramify flood insurance protocol. The system now uses a dynamic 12-foot flood threshold (adjustable by admin) instead of hardcoded values.
- Added
uint256 public floodThreshold = 1200000000000;(12 feet default) - Added
setThreshold()function with owner-only access control - Added
ThresholdChangedevent for audit trail - Updated payout logic to use dynamic threshold
- Added
GET /api/threshold- returns current threshold in feet and units - Added
POST /api/threshold- updates threshold (admin only) - Integrated threshold data in
/api/statusresponse - Added proper error handling and validation
- Admin Dashboard: Added threshold management UI, removed manual flood input
- Customer Dashboard: Displays current threshold, uses it for payout conditions
- Both dashboards show live USGS data with proper unit conversions
# Create backup directory
mkdir backup-$(date +%Y%m%d)
# Copy current contract addresses and configurations
cp backend/.env backup-$(date +%Y%m%d)/
cp frontend/src/lib/contract.ts backup-$(date +%Y%m%d)/# Make sure Hardhat node is running
npx hardhat node
# In a new terminal, deploy the contract
npx hardhat run scripts/deploy.js --network localhostIMPORTANT: Note the new Paramify contract address from the deployment output.
PARAMIFY_ADDRESS=<NEW_CONTRACT_ADDRESS>
MOCK_ORACLE_ADDRESS=<EXISTING_ORACLE_ADDRESS>
PRIVATE_KEY=<EXISTING_PRIVATE_KEY>export const PARAMIFY_ADDRESS = '<NEW_CONTRACT_ADDRESS>';
// Keep existing MOCK_ORACLE_ADDRESS unchanged# Terminal 1: Backend
cd backend
npm start
# Terminal 2: Frontend (if not already running)
cd frontend
npm run devAccess the admin dashboard and fund the contract with ETH for insurance payouts.
- Open Admin Dashboard (http://localhost:8080)
- Check "Threshold Management" section shows 12.0 feet (1200000000000 units)
- Open Customer Dashboard in another browser
- Verify same threshold is displayed
- In Admin Dashboard, set threshold to 5 feet
- Click "Update Threshold"
- Verify success message
- Check both dashboards show updated threshold (5.0 feet = 500000000000 units)
- Current USGS reading should be ~4.26 feet
- Set threshold to 4 feet (below current level)
- Verify "THRESHOLD EXCEEDED" warning appears
- Buy insurance policy on customer dashboard
- Verify "Claim Insurance Payout" button appears
- Click to trigger payout
- Verify payout is processed successfully
- Set threshold back to 12 feet
- Verify payout conditions no longer met
- System ready for production use
Contract Units = Feet × 100,000,000,000
Examples:
- 4.26 ft = 426,000,000,000 units
- 12 ft = 1,200,000,000,000 units
// Feet to units
const thresholdUnits = Math.floor(thresholdFeet * 100000000000);
// USGS data scaling
const scaledValue = Math.floor(waterLevel * 100000000000);- Ensure you updated both backend/.env and frontend contract.ts with new address
- Restart both backend and frontend services
- Check wallet is connected as admin (0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266)
- Ensure backend is running and connected to blockchain
- Verify backend is running:
cd backend && npm start - Check console for any API errors
- Manual update available in admin dashboard
- Verify flood level exceeds threshold
- Ensure user has active insurance policy
- Check contract has sufficient balance
- Access Control: Only contract owner can modify threshold
- Input Validation:
- Threshold must be positive
- Maximum threshold: 100 feet (10000000000000 units)
- Event Logging: All threshold changes emit events for audit trail
- No Breaking Changes: Existing policies remain unaffected
{
"thresholdFeet": 12,
"thresholdUnits": "1200000000000"
}Request:
{
"thresholdFeet": 8.5
}Response:
{
"success": true,
"thresholdFeet": 8.5,
"thresholdUnits": "850000000000",
"transactionHash": "0x..."
}If issues occur:
- Stop all services
- Restore original contract addresses from backup
- Redeploy previous contract version if needed
- Restart services
- Verify system functionality
- Smart contract deployed successfully
- Contract addresses updated in all config files
- Backend API endpoints responding correctly
- Admin can view and update threshold
- Customer dashboard shows current threshold
- Threshold changes immediately affect payout conditions
- USGS data continues updating every 5 minutes
- Manual flood input completely removed from UI
- Events emitted for all threshold changes
- Only admin can modify threshold
- Existing insurance policies work correctly
- Payouts trigger automatically when threshold exceeded
Once all tests pass and checklist items are verified, the system is ready for production use with dynamic threshold management fully operational.