Skip to content

feat(defi): Staking & Yield Optimization Automation (#76)#91

Merged
memplethee-lab merged 1 commit into
SourceXXL:mainfrom
Ebenezer199914:feat/issue-76-staking-yield-optimization-automation
Jun 29, 2026
Merged

feat(defi): Staking & Yield Optimization Automation (#76)#91
memplethee-lab merged 1 commit into
SourceXXL:mainfrom
Ebenezer199914:feat/issue-76-staking-yield-optimization-automation

Conversation

@Ebenezer199914

Copy link
Copy Markdown
Contributor

Summary

Implements staking and yield optimization automation as described in issue #76.

Changes

New: StakingService (src/defi/services/staking.service.ts)

  • stake() — opens a new staking position against a DeFi protocol adapter
  • unstake() — reduces/closes a staking position
  • getStakingPositions() — lists all staking positions for a user
  • claimRewards() — claims accumulated staking rewards and persists yield records
  • autoCompound() — re-stakes claimable rewards when auto-compound is enabled
  • setAutoCompound() — toggles auto-compound on a position
  • getStakingOpportunities() — discovers staking APY across all protocol adapters

New: StakingDTOs (src/defi/dto/staking.dto.ts)

StakeDto, UnstakeDto, AutoCompoundConfigDto, StakingPositionResponseDto, StakingOpportunityDto

New: Unit tests (src/defi/services/staking.service.spec.ts)

8 tests covering: stake, unstake (partial + full close + 404), getStakingPositions, claimRewards, autoCompound (disabled + enabled), setAutoCompound, getStakingOpportunities (capability filter)

Updated: DeFiModule + DeFiController

REST endpoints added:

Method Path
GET /defi/staking
POST /defi/staking
POST /defi/staking/:id/unstake
POST /defi/staking/:id/claim
POST /defi/staking/:id/compound
PUT /defi/staking/:id/auto-compound
GET /defi/staking/opportunities

Fix: PortfolioConstraintService (pre-existing test failures)

  1. Category allocation check now applies warningThresholdPercent to distinguish warning vs error boundary
  2. Added getCategoryConcentrationPenalty() for accurate risk scoring

Testing

  • npx tsc --noEmit ✅ zero errors
  • npm run build ✅ webpack compiled successfully
  • 196 tests across 13 suites ✅ all passing

…XXL#76)

- Add StakingService with stake, unstake, claimRewards, autoCompound,
  setAutoCompound, and getStakingOpportunities
- Add StakingDTOs (StakeDto, UnstakeDto, AutoCompoundConfigDto, etc.)
- Wire StakingService into DeFiModule and expose REST endpoints:
    GET    /defi/staking
    POST   /defi/staking
    POST   /defi/staking/:id/unstake
    POST   /defi/staking/:id/claim
    POST   /defi/staking/:id/compound
    PUT    /defi/staking/:id/auto-compound
    GET    /defi/staking/opportunities
- Add 8 unit tests for StakingService covering all core methods
- Fix pre-existing PortfolioConstraintService bugs:
    * Category allocation check now uses warningThresholdPercent to
      distinguish error vs warning boundary
    * Add getCategoryConcentrationPenalty() for asset-type concentration
      risk scoring (fixes risk-score-near-limit warning threshold test)
@memplethee-lab memplethee-lab merged commit 8e13c51 into SourceXXL:main Jun 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants