feat(defi): Staking & Yield Optimization Automation (#76)#91
Merged
memplethee-lab merged 1 commit intoJun 29, 2026
Conversation
…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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 adapterunstake()— reduces/closes a staking positiongetStakingPositions()— lists all staking positions for a userclaimRewards()— claims accumulated staking rewards and persists yield recordsautoCompound()— re-stakes claimable rewards when auto-compound is enabledsetAutoCompound()— toggles auto-compound on a positiongetStakingOpportunities()— discovers staking APY across all protocol adaptersNew: StakingDTOs (
src/defi/dto/staking.dto.ts)StakeDto,UnstakeDto,AutoCompoundConfigDto,StakingPositionResponseDto,StakingOpportunityDtoNew: 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:
/defi/staking/defi/staking/defi/staking/:id/unstake/defi/staking/:id/claim/defi/staking/:id/compound/defi/staking/:id/auto-compound/defi/staking/opportunitiesFix: PortfolioConstraintService (pre-existing test failures)
warningThresholdPercentto distinguish warning vs error boundarygetCategoryConcentrationPenalty()for accurate risk scoringTesting
npx tsc --noEmit✅ zero errorsnpm run build✅ webpack compiled successfully