Repository navigation
feat(goals): multiple concurrent goals with priority-weighted allocation (#358) - #733
Open
huangji6693-max wants to merge 1 commit into
Conversation
7 tasks
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.
Closes #358
Summary
Implements multiple concurrent
SavingsGoalsupport with priority-weighted and sequential allocation across shared portfolio capital:Schema & Migration (
prisma/schema.prisma):User.goalFundingMode(SEQUENTIAL|WEIGHTED, defaultSEQUENTIAL).SavingsGoal.priority(Int @default(100)),allocationWeight(Decimal @default(1) @db.Decimal(10, 4)), andfundingMode(String @default("SEQUENTIAL")).GoalAllocationappend-only attribution ledger (goalId,amount,sourceType,sourceRef,createdAt) with forward migration androllback.sql.Pure Allocation Engine (
src/goals/allocation.ts):sortGoalsByPriority: deterministic ordering (priority ASC,targetDate ASC,createdAt ASC,id ASC).attributeContribution: supportsSEQUENTIALwaterfall andWEIGHTEDproportional water-filling cascade up to each active goal's remaining headroom, returning anyunallocatedremainder.attributeYield: attributes snapshot yield proportional to each active goal's attributed balance (currentAmount), capped by remaining headroom.attributeWithdrawal: reduces attributed capital in reverse funding order (or position-scoped goals first whenpositionIdis specified), clamping attributed balances to>= 0.reconcileUserGoalAllocations: computes per-goalcurrentAmount,portfolioShare, and portfolio-levelunallocatedcapital.selectBindingGoal: selects the under-funded active goal with the highestrequiredApyforGoalTrackingStrategyand enforces the stricter (Math.max)riskCeilingacross all active goals while preserving exact single-goal backward compatibility.Service, Agent & API Integration:
src/goals/service.ts&src/controllers/goal-controller.ts&src/routes/goals.ts(/api/v1/portfolio/goalsand/api/v1/goals):GET /: returns all goals sorted by priority withportfolioShare,bindingGoalId,effectiveRiskCeiling,totalPortfolioAmount,totalAttributedAmount, andunallocatedAmount.PATCH /:id: updatespriority,allocationWeight,fundingMode,targetAmount,targetDate,riskCeiling,name.POST /reorder: atomic bulk priority update.POST /reassign: atomic ledger-backed balance transfer (MANUAL_REASSIGN-amount/+amount) between two same-user goals without touching on-chain positions.src/agent/router.ts:loadActiveGoals/loadActiveGoalresolves the binding goal and strictest risk ceiling across all active goals.docs/GOALS_MULTI.md,ASSUMPTIONS.md,docs/openapi.yaml,docs/API_KEYS.md).Verification
npx prisma generatenpm run docs:scopesnode scripts/check-openapi-drift.jsbash scripts/check-migration-rollback.shnpm run typechecknpx jest tests/unit/goals/allocation.test.ts tests/unit/goals/externalHoldings.test.ts tests/integration/goals-multi.integration.test.ts tests/integration/agent/goal-strategy-selection.integration.test.ts tests/unit/middleware/rateLimitTierMatrix.test.ts tests/unit/auth/scopeCatalog.test.ts --runInBand