Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
57 changes: 57 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store
Thumbs.db

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# Environment variables
.env
.env.test
.env.production
.env.local

# Build outputs
*.tsbuildinfo
compile_output.txt

# Temporary files
*.tmp
*.temp
fix.js
fix2.js

# Tool directories
.kiro/

# Root backend partial copy (actual code is in harvest-finance/backend/)
/backend/
115 changes: 115 additions & 0 deletions PR_DESCRIPTION_SCORING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Pull Request: Vault Strategy Scoring Model Implementation

## Direct PR Creation Link

**Click this link to create your Pull Request:**

### https://github.com/daveedAJ/Harvest-Finance/pull/new/feat/strategy-apy-clean

---

## PR Title

```
feat: implement vault strategy scoring model with hourly recalculation
```

## PR Description

```markdown
## Summary

This PR implements a comprehensive vault strategy scoring system (GitHub issues #504 and #977) that provides risk-adjusted scores for vaults based on multiple factors.

## Features

- ✅ Strategy score (0-100) for each vault based on weighted components
- ✅ Risk-adjusted APY scoring (40% weight)
- ✅ TVL stability scoring (25% weight)
- ✅ Historical drawdown scoring (20% weight)
- ✅ Operator reputation scoring (15% weight)
- ✅ Hourly score recalculation via cron job
- ✅ Score history persistence in database
- ✅ GET /vaults/:id/score-breakdown API endpoint
- ✅ Comprehensive unit tests

## Changes

### New Files
- `src/analytics/scoring.service.ts` - Scoring service with all calculation logic
- `src/analytics/scoring.service.spec.ts` - Unit tests for scoring service
- `src/vaults/dto/score-breakdown.dto.ts` - DTO for score breakdown response
- `src/database/entities/vault-score-history.entity.ts` - Entity for score history
- `src/database/migrations/1700000000018-CreateVaultScoreHistory.ts` - Migration for score history table
- `docs/scoring-model.md` - Documentation for the scoring model

### Modified Files
- `src/database/entities/vault.entity.ts` - Added strategyScore column
- `src/database/entities/index.ts` - Export VaultScoreHistory entity
- `src/analytics/analytics.module.ts` - Added ScoringService
- `src/vaults/vaults.controller.ts` - Added score-breakdown endpoint
- `src/vaults/vaults.module.ts` - Added AnalyticsModule and VaultScoreHistory
- `src/app.module.ts` - Added VaultScoreHistory entity and migration

## Score Calculation

The overall strategy score is calculated as:

```
strategyScore = round(
apyScore * 0.4 +
tvlStabilityScore * 0.25 +
drawdownScore * 0.2 +
operatorScore * 0.15
)
```

## How to Test

```bash
# Run tests
npm test -- harvest-finance/backend/src/analytics/scoring.service.spec.ts

# Build to verify no compilation errors
npm run build -- harvest-finance/backend
```

## API Endpoint

### GET /vaults/:vaultId/score-breakdown

Returns the detailed score breakdown for a specific vault:

```json
{
"strategyScore": 75,
"apyScore": 75,
"tvlStabilityScore": 100,
"drawdownScore": 100,
"operatorScore": 25
}
```

## Checklist

- [x] Code follows project style guidelines
- [x] No new dependencies added
- [x] New tests included and passing
- [x] Documentation updated
- [x] All acceptance criteria met
```

---

## Quick Steps

1. **Click the link above** - Takes you to GitHub comparison page
2. **Review the changes** - All Strategy Scoring implementation
3. **Click "Create pull request"** - Green button on the right
4. **Add PR description** - Use the template above

## Branch Information

- **Branch**: `feat/strategy-apy-clean`
- **Target**: `main`
- **Repository**: https://github.com/daveedAJ/Harvest-Finance
108 changes: 108 additions & 0 deletions PR_DESCRIPTION_STRATEGY_APY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Pull Request: Strategy and Vault APY History Implementation

## Direct PR Creation Link

**Click this link to create your Pull Request:**

### https://github.com/daveedAJ/Harvest-Finance/pull/new/feat/strategy-apy-clean

---

## PR Title

```
feat: add Strategy and VaultApyHistory entities with migration
```

## PR Description

```markdown
## Summary

This PR implements Strategy and Vault APY History entities to support compounding frequency configuration and APY tracking for vaults in the Harvest Finance platform.

## Features

- ✅ Strategy entity with compounding frequency support (daily, weekly, monthly)
- ✅ VaultApyHistory entity for tracking APY snapshots over time
- ✅ Database migration for schema changes
- ✅ APY calculation based on compounding frequency
- ✅ Updated VaultResponseDto to include APY field
- ✅ Comprehensive test coverage for APY calculations

## Changes

### New Entities
- `Strategy` - Defines compounding strategies with frequency options
- `VaultApyHistory` - Tracks historical APY data for vaults

### Database
- Migration `1700000000017-CreateStrategyAndApyHistory` creates:
- `strategies` table with compounding_frequency enum
- `vault_apy_history` table for APY snapshots
- Foreign key relationship from vaults to strategies

### Service Updates
- `VaultsService.calculateApy()` - Computes APY from APR using compound interest formula
- `VaultsService.getVaultCompoundingFrequency()` - Gets effective compounding frequency

### DTO Updates
- `VaultResponseDto` - Added `apr` and `apy` fields for API responses

## APY Calculation Formula

```
APY = (1 + APR / n)^n - 1

Where:
- APR = Annual Percentage Rate (as percentage)
- n = Compounding frequency (365 for daily, 52 for weekly, 12 for monthly)
```

## How to Test

```bash
# Run tests
npm test -- harvest-finance/backend/src/vaults/vaults.service.spec.ts

# Build to verify no compilation errors
npm run build -- harvest-finance/backend
```

## Files Changed

- `src/database/entities/strategy.entity.ts` (41 lines) - New Strategy entity
- `src/database/entities/vault-apy-history.entity.ts` (35 lines) - New VaultApyHistory entity
- `src/database/migrations/1700000000017-CreateStrategyAndApyHistory.ts` (173 lines) - New migration
- `src/database/entities/vault.entity.ts` (21 lines) - Added strategy relationship and APY getter
- `src/database/entities/index.ts` (2 lines) - Export new entities
- `src/database/data-source.ts` (4 lines) - Register new entities
- `src/app.module.ts` (6 lines) - Import Strategy and VaultApyHistory modules
- `src/vaults/vaults.module.ts` (11 lines) - Add Strategy and VaultApyHistory repositories
- `src/vaults/vaults.service.ts` (104 lines) - Add APY calculation methods
- `src/vaults/vaults.service.spec.ts` (207 lines) - Add APY tests
- `src/vaults/dto/vault-response.dto.ts` (14 lines) - Add APR and APY fields

## Checklist

- [x] Code follows project style guidelines
- [x] No new dependencies added
- [x] New tests included and passing
- [x] Documentation updated
- [x] All acceptance criteria met
```

---

## Quick Steps

1. **Click the link above** - Takes you to GitHub comparison page
2. **Review the changes** - All Strategy and APY History implementation
3. **Click "Create pull request"** - Green button on the right
4. **Add PR description** - Use the template above

## Branch Information

- **Branch**: `feat/strategy-apy-clean`
- **Target**: `main`
- **Repository**: https://github.com/daveedAJ/Harvest-Finance
Loading
Loading