Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c2e1ac7
add centralized contract configuration file
Mosas2000 Apr 28, 2026
157e204
fix contract name in root frontend config
Mosas2000 Apr 28, 2026
ddc1936
add contract name to environment example
Mosas2000 Apr 28, 2026
2f3eb60
create contract config loader utility
Mosas2000 Apr 28, 2026
8ae1d31
update create proposal script to use centralized config
Mosas2000 Apr 28, 2026
2f43836
update stake script to use centralized config
Mosas2000 Apr 28, 2026
2dad4e4
update call-logger script to use centralized config
Mosas2000 Apr 28, 2026
297d1c7
update withdraw-legacy script to use centralized config
Mosas2000 Apr 28, 2026
bfa0b8c
update shell script to load config from centralized json
Mosas2000 Apr 28, 2026
79ac11e
add config validation script
Mosas2000 Apr 28, 2026
669978f
add validate-config script to package.json
Mosas2000 Apr 28, 2026
e371c82
update contract versions doc to reference centralized config
Mosas2000 Apr 28, 2026
6635dfb
add typescript contract config loader for frontend
Mosas2000 Apr 28, 2026
b937075
update frontend config to use centralized config as fallback
Mosas2000 Apr 28, 2026
21f674c
add configuration management documentation
Mosas2000 Apr 28, 2026
76863a9
add typescript definitions for config loader
Mosas2000 Apr 28, 2026
52c9046
add unit tests for config loader
Mosas2000 Apr 28, 2026
4b725b7
add config exports index file
Mosas2000 Apr 28, 2026
757cfd4
add config update helper script
Mosas2000 Apr 28, 2026
7cad415
add configuration migration guide
Mosas2000 Apr 28, 2026
1ba1b20
update scripts readme with config info
Mosas2000 Apr 28, 2026
aaa5d47
add contract config readme
Mosas2000 Apr 28, 2026
bfff8d6
add validation to config loader
Mosas2000 Apr 28, 2026
e38ebc5
add legacy contract helper functions
Mosas2000 Apr 28, 2026
4f436f7
update typescript definitions for new helpers
Mosas2000 Apr 28, 2026
4785424
add legacy contract helpers to frontend config
Mosas2000 Apr 28, 2026
350fbd2
update exports to include new helper functions
Mosas2000 Apr 28, 2026
7609b18
add tests for legacy contract helpers
Mosas2000 Apr 28, 2026
14f38cd
add github workflow for config validation
Mosas2000 Apr 28, 2026
75db911
add husky hook for config validation
Mosas2000 Apr 28, 2026
1151c47
add configuration reference to main readme
Mosas2000 Apr 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ PRIVATE_KEY=
# Stacks API base URL (default: mainnet)
STACKS_API_URL=https://stacks-node-api.mainnet.stacks.co

# Contract deployer address
# Contract configuration
CONTRACT_ADDRESS=SP31PKQVQZVZCK3FM3NH67CGD6G1FMR17VQVS2W5T
CONTRACT_NAME=sprintfund-core-v3
48 changes: 48 additions & 0 deletions .github/workflows/validate-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Validate Configuration

on:
pull_request:
paths:
- 'contract-config.json'
- 'frontend/src/config.ts'
- 'frontend/config.ts'
- '.env.example'
- 'scripts/**/*.js'
push:
branches:
- main
paths:
- 'contract-config.json'
- 'frontend/src/config.ts'
- 'frontend/config.ts'
- '.env.example'

jobs:
validate:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install dependencies
run: |
cd scripts
npm install

- name: Validate configuration
run: |
cd scripts
npm run validate-config

- name: Check for config drift
if: failure()
run: |
echo "Configuration validation failed!"
echo "Please ensure all config files reference the centralized contract-config.json"
exit 1
12 changes: 12 additions & 0 deletions .husky/validate-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# Check if contract-config.json or related files were modified
if git diff --cached --name-only | grep -qE '(contract-config\.json|frontend/(src/)?config\.ts|\.env\.example)'; then
echo "Config files modified, running validation..."
cd scripts && npm run validate-config
if [ $? -ne 0 ]; then
echo "Config validation failed! Please fix the issues before committing."
exit 1
fi
fi
85 changes: 85 additions & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Configuration Management

## Centralized Contract Configuration

This project uses a centralized configuration system to prevent drift between contract settings across different files.

### Single Source of Truth

The `contract-config.json` file at the project root is the single source of truth for all contract configuration:

```json
{
"version": "3",
"contract": {
"address": "SP31PKQVQZVZCK3FM3NH67CGD6G1FMR17VQVS2W5T",
"name": "sprintfund-core-v3",
"principal": "SP31PKQVQZVZCK3FM3NH67CGD6G1FMR17VQVS2W5T.sprintfund-core-v3"
},
"network": {
"default": "mainnet",
"mainnet": { "apiUrl": "...", "explorerUrl": "..." },
"testnet": { "apiUrl": "...", "explorerUrl": "..." }
}
}
```

### How It Works

1. **Root config file**: `contract-config.json` contains all contract settings
2. **Frontend**: `frontend/src/config.ts` loads from centralized config with env override support
3. **Scripts**: `scripts/lib/contract-config.js` loads centralized config directly
4. **Validation**: `scripts/validate-config.js` verifies all files are in sync

### Environment Variables

Environment variables can override centralized config values:

- `NEXT_PUBLIC_CONTRACT_ADDRESS` - Override contract address
- `NEXT_PUBLIC_CONTRACT_NAME` - Override contract name
- `NEXT_PUBLIC_NETWORK` - Override network (mainnet/testnet)
- `NEXT_PUBLIC_STACKS_API_URL` - Override API URL

### Validation

Run the validation script to check for config drift:

```bash
cd scripts
npm run validate-config
```

This will:
- Load the centralized config
- Check all config files for consistency
- Report any mismatches
- Exit with error code if issues found

### Adding New Config Values

1. Add the value to `contract-config.json`
2. Update the TypeScript loader (`frontend/src/lib/contract-config.ts`)
3. Update the JavaScript loader (`scripts/lib/contract-config.js`)
4. Update any files that use the new value
5. Run validation to verify

### Migration from Hardcoded Values

All hardcoded contract addresses and names have been replaced with references to the centralized config:

- ✅ `frontend/src/config.ts` - Uses centralized config
- ✅ `frontend/config.ts` - Uses centralized config
- ✅ `scripts/create-proposal.js` - Uses centralized config
- ✅ `scripts/stake.js` - Uses centralized config
- ✅ `scripts/call-logger.js` - Uses centralized config
- ✅ `scripts/withdraw-legacy.js` - Uses centralized config
- ✅ `create-test-proposal.sh` - Loads from centralized config
- ✅ `.env.example` - Includes contract name

### Benefits

- **No more drift**: Single source of truth prevents inconsistencies
- **Easy updates**: Change once in `contract-config.json`
- **Validation**: Automated checks catch mismatches
- **Documentation**: Clear structure for all config values
- **Type safety**: TypeScript definitions for config structure
27 changes: 18 additions & 9 deletions CONTRACT_VERSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,24 @@ When deploying a new contract version:

All contract references use centralized configuration:

**Single source of truth**: `frontend/src/config.ts`

```typescript
export const CONTRACT_ADDRESS = 'SP31PKQVQZVZCK3FM3NH67CGD6G1FMR17VQVS2W5T';
export const CONTRACT_NAME = 'sprintfund-core-v3';
export const CONTRACT_PRINCIPAL = `${CONTRACT_ADDRESS}.${CONTRACT_NAME}`;
**Single source of truth**: `contract-config.json` (root level)

```json
{
"version": "3",
"contract": {
"address": "SP31PKQVQZVZCK3FM3NH67CGD6G1FMR17VQVS2W5T",
"name": "sprintfund-core-v3",
"principal": "SP31PKQVQZVZCK3FM3NH67CGD6G1FMR17VQVS2W5T.sprintfund-core-v3"
}
}
```

All components import from this file instead of hardcoding values.
All components and scripts import from this file via:
- Frontend: `frontend/src/config.ts` (reads from env with fallback to centralized config)
- Scripts: `scripts/lib/contract-config.js` (loads centralized config directly)

Run `npm run validate-config` to verify all config files are in sync.

### 4. Backward Compatibility

Expand All @@ -86,8 +95,8 @@ Before switching to a new contract version:

When ready to switch to a new version:

- [ ] Update `CONTRACT_NAME` in `frontend/src/config.ts`
- [ ] Update `CONTRACT_NAME` in all script files under `scripts/`
- [ ] Update `contract-config.json` with new contract details
- [ ] Run `npm run validate-config` to verify consistency
- [ ] Update documentation (README.md, frontend/README.md)
- [ ] Update deployment configs (`Clarinet.toml`, deployment plans)
- [ ] Update kubernetes configs if applicable
Expand Down
70 changes: 70 additions & 0 deletions MIGRATION_CONFIG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Configuration Migration Guide

This guide helps you understand and work with the new centralized configuration system.

## What Changed

Previously, contract configuration was scattered across multiple files:
- `frontend/src/config.ts` - Hardcoded values
- `frontend/config.ts` - Different hardcoded values
- `.env.example` - Only had address
- Scripts - Hardcoded values in each file

Now, all configuration is centralized in `contract-config.json`.

## Migration Steps

### For Developers

1. **Update your environment**:
```bash
cp .env.example .env
# Edit .env with your values
```

2. **Run validation**:
```bash
cd scripts
npm run validate-config
```

3. **Update scripts**:
- All scripts now import from `scripts/lib/contract-config.js`
- No manual updates needed unless adding new scripts

### For Maintainers

When updating contract configuration:

1. Edit `contract-config.json` with new values
2. Run `npm run validate-config` to check consistency
3. Update any documentation that references the old values
4. Commit the changes

## Files Updated

The following files were updated to use the centralized config:

- `frontend/src/config.ts` - Now imports from centralized config
- `frontend/config.ts` - Fixed to use correct contract name
- `scripts/create-proposal.js` - Uses centralized config
- `scripts/stake.js` - Uses centralized config
- `scripts/call-logger.js` - Uses centralized config
- `scripts/withdraw-legacy.js` - Uses centralized config
- `create-test-proposal.sh` - Loads from centralized config
- `.env.example` - Now includes contract name

## Rollback Plan

If you need to rollback:

1. The old hardcoded values are preserved in git history
2. You can revert the config files individually
3. Environment variables still work as overrides

## Support

For questions about the configuration system:
- Check `CONFIGURATION.md` for detailed documentation
- Run `npm run validate-config` to check for issues
- Open an issue on GitHub if you encounter problems
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ SprintFund is a decentralized autonomous organization (DAO) designed to fund sma

**Explorer**: [View on Stacks Explorer](https://explorer.hiro.so/txid/SP31PKQVQZVZCK3FM3NH67CGD6G1FMR17VQVS2W5T.sprintfund-core-v3?chain=mainnet)

**Configuration**: See [CONFIGURATION.md](CONFIGURATION.md) for centralized config management

## Key Features

- **⚡ Micro-Grants** - Fast funding for small projects ($50-200 STX range)
Expand Down
76 changes: 76 additions & 0 deletions contract-config.README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contract Configuration File

This file (`contract-config.json`) is the single source of truth for all contract configuration in the SprintFund project.

## Structure

```json
{
"version": "3", // Contract version number
"contract": {
"address": "SP...", // Stacks contract address
"name": "sprintfund-core-v3", // Contract name
"principal": "SP....contract" // Full principal (address.name)
},
"network": {
"default": "mainnet", // Default network
"mainnet": { ... }, // Mainnet API endpoints
"testnet": { ... } // Testnet API endpoints
},
"legacy": { // Legacy contract versions
"v1": { ... },
"v2": { ... }
}
}
```

## Usage

### Frontend (TypeScript)
```typescript
import { config } from './lib/contract-config';
const address = config.contract.address;
```

### Scripts (JavaScript)
```javascript
import { getContractAddress } from './lib/contract-config.js';
const address = getContractAddress();
```

### Shell Scripts
```bash
CONTRACT_ADDRESS=$(jq -r '.contract.address' contract-config.json)
```

## Updating

When updating contract configuration:

1. Edit `contract-config.json`
2. Run `npm run validate-config` to verify
3. Commit the changes
4. All scripts and frontend will automatically use new values

## Validation

Run validation to check for config drift:
```bash
cd scripts
npm run validate-config
```

This checks that all files reference the correct contract values.

## Environment Overrides

Environment variables can override config values:
- `NEXT_PUBLIC_CONTRACT_ADDRESS`
- `NEXT_PUBLIC_CONTRACT_NAME`
- `NEXT_PUBLIC_NETWORK`

## See Also

- `CONFIGURATION.md` - Detailed configuration documentation
- `MIGRATION_CONFIG.md` - Migration guide for the config system
- `CONTRACT_VERSIONS.md` - Contract versioning strategy
29 changes: 29 additions & 0 deletions contract-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "3",
"contract": {
"address": "SP31PKQVQZVZCK3FM3NH67CGD6G1FMR17VQVS2W5T",
"name": "sprintfund-core-v3",
"principal": "SP31PKQVQZVZCK3FM3NH67CGD6G1FMR17VQVS2W5T.sprintfund-core-v3"
},
"network": {
"default": "mainnet",
"mainnet": {
"apiUrl": "https://api.mainnet.hiro.so",
"explorerUrl": "https://explorer.hiro.so"
},
"testnet": {
"apiUrl": "https://api.testnet.hiro.so",
"explorerUrl": "https://explorer.hiro.so"
}
},
"legacy": {
"v1": {
"name": "sprintfund-core",
"status": "deprecated"
},
"v2": {
"name": "sprintfund-core-v2",
"status": "deprecated"
}
}
}
Loading
Loading