This document outlines tasks to resolve all parameter gaps detected by the automated gap detection system. The detector found 38 total issues across multiple categories:
- Critical: 1 issue (hardcoded slippage in buyAndBorrow)
- High: 8 issues (security-sensitive parameters, validation gaps)
- Medium: 23 issues (address validation, user-configurable params, file complexity)
- Low: 6 issues (file complexity, fee consistency)
- Issue:
ZERO_VALUE_buyAndBorrow_pos3- minAmountOut_ hardcoded to BigInt(0) - Location:
src/market.ts:570 - Impact: Critical - users get no slippage protection
- Steps:
- Update
TMarketBuyAndBorrowParamsinterface to includeminAmountOut?: bigint - Modify
buyAndBorrowfunction to accept and use the parameter - Set default value to
BigInt(0)but allow override - Add proper validation for the parameter
- Update
- Issue:
SUMMARY_ADMIN_VALIDATION- 71 functions need input validation - Impact: High - protocol security risk
- Steps:
- Create validation utility functions
- Add validation to all admin functions
- Implement range checks for numeric values
- Add address validation for address parameters
- Issue:
SECURITY_SENSITIVE_setMaxLoops_pos0- newMaxLoops_ hardcoded - Location:
src/credit-facility-admin.ts:308 - Impact: High - affects protocol leverage limits
- Steps:
- Update interface to accept configurable max loops parameter
- Add validation (e.g., max 100 loops)
- Implement proper parameter passing
- Issue:
SUMMARY_ADDRESS_VALIDATION- 76 calls need zero address validation - Impact: High - prevents sending to zero address
- Steps:
- Create address validation utility function
- Apply to all functions with receiver/to/from parameters
- Validate against zero address (0x0000...)
- Issues: Multiple USER_CONFIGURABLE issues (setBuyFee, setSellFee, etc.)
- Impact: Medium - reduces flexibility
- Steps:
- Review each hardcoded parameter
- Determine if it should be user-configurable
- Update interfaces and functions accordingly
- Add appropriate defaults
- Issue:
FILE_COMPLEX_presale.tsand others (5 files >20 calls) - Impact: Medium - maintainability
- Steps:
- Split presale.ts into buy.ts, sell.ts, admin.ts
- Split launch.ts by functionality
- Organize market-admin.ts by feature
- Issue:
SUMMARY_LOOP_COMPLEXITY- 7 loop-related calls - Impact: Medium - prevents excessive leverage
- Steps:
- Add max loop constants
- Validate loop counts in all functions
- Prevent potential exploits
- Issues: Individual ADDRESS_VALIDATION issues
- Functions: buyFor, sellTo, borrowFor, buyAndBorrowFor, harvestYield, withdrawFunds
- Impact: Medium - security improvement
- Steps:
- Add validation to each specific function
- Check for zero address before contract calls
- Issue:
SUMMARY_FEE_CONSISTENCY- 10 fee-related calls - Impact: Low - consistency improvement
- Steps:
- Standardize basis points constants
- Ensure consistent fee representation
- Add validation for fee ranges
- Issues: SUMMARY_PRESALE_SECURITY, SUMMARY_CREDIT_RISK, SUMMARY_MARKET_SLIPPAGE
- Impact: Various - risk mitigation
- Steps:
- Review presale functions for security
- Assess credit facility borrowing risk
- Review market slippage calculations
// Current (problematic):
args: [amount, loops, consolidate, BigInt(0)], // minAmountOut_ hardcoded!
// Fixed:
export interface TMarketBuyAndBorrowParams {
amount: bigint
loops: bigint
consolidate: boolean
minAmountOut?: bigint // Add this parameter
}
async buyAndBorrow(params: TMarketBuyAndBorrowParams): Promise<void> {
const { amount, loops, consolidate, minAmountOut = BigInt(0) } = params
await this.writeContract({
abi: ICreditFacility_v1,
address: this.address,
functionName: 'buyAndBorrow',
args: [amount, loops, consolidate, minAmountOut], // Pass the parameter
})
}async setSomeParam(params: TSetSomeParamParams): Promise<void> {
const { someValue } = params
// Add validation for all admin functions
if (someValue === undefined || someValue === null) {
throw new Error('Parameter cannot be null/undefined')
}
// Type-specific validation
if (typeof someValue === 'bigint' && someValue < BigInt(0)) {
throw new Error('Value cannot be negative')
}
if (typeof someValue === 'string' && !isAddress(someValue)) {
throw new Error('Invalid address format')
}
await this.writeContract({ ... })
}function validateAddress(address: string, paramName: string): void {
if (!address || address === '0x0000000000000000000000000000000000000000') {
throw new Error(`${paramName} cannot be zero address`)
}
if (!isAddress(address)) {
throw new Error(`Invalid ${paramName} address format`)
}
}- Run
bun test test/params/param-gaps.test.ts- all tests should pass - Verify no critical or high severity issues remain
- Ensure no regressions in existing functionality
- Confirm all fixes follow SDK patterns and conventions
- Total issues reduced from 38 to 0-5 low-priority items
- No critical or high severity issues
- Improved parameter flexibility
- Enhanced security validation
- Better code organization
export const BASIS_POINTS = {
ONE_PERCENT: BigInt(100),
FIVE_PERCENT: BigInt(500),
TEN_PERCENT: BigInt(1000),
MAX: BigInt(10000), // 100%
}
export const PROTOCOL_LIMITS = {
MAX_LOOPS: BigInt(10),
MAX_LEVERAGE_INDEX: BigInt(5),
DEFAULT_SLIPPAGE_BPS: BigInt(100), // 1.0% - safer for volatile markets
MAX_SLIPPAGE_BPS: BigInt(500), // 5.0% - absolute maximum
}- Run specific test for the fixed function
- Run full parameter gap detection test
- Run full SDK test suite to ensure no regressions
- Verify contract interaction still works correctly
- Phase 1: 2-3 days (critical security issues)
- Phase 2: 3-5 days (medium priority improvements)
- Phase 3: 2-3 days (low priority enhancements)
Total estimated: 1 week to resolve all critical and high priority issues.