feat(api): add GET /api/v1/vaults/{id}/harvest/preview — dry-run harvest before commit#747
Open
ruthoreaji-123 wants to merge 2 commits into
Open
feat(api): add GET /api/v1/vaults/{id}/harvest/preview — dry-run harvest before commit#747ruthoreaji-123 wants to merge 2 commits into
ruthoreaji-123 wants to merge 2 commits into
Conversation
|
@ruthoreaji-123 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
0xDeon
requested changes
Jun 27, 2026
0xDeon
left a comment
Contributor
There was a problem hiding this comment.
Merge conflict with main. Rebase onto main and resolve conflicts before this can be merged.
- Add HarvestPreview struct and PreviewHarvest service method
- Register GET /api/v1/vaults/{id}/harvest/preview route
- Impaired vault returns gross/fee/net = 0 with impaired: true
- compound=true param returns estimated_new_shares
- Non-owner returns 403 via ErrVaultForbidden
- Add unit tests: normal, impaired, compound, forbidden cases
Fix pre-existing CI failures:
- cmd/api/main.go: remove unused notificationDispatcher using ws.Hub
(ws.Hub does not implement notifications.WebSocketHub)
- savings_goal_service_test.go: fix map key type and missing notifier args
- savings_schedule_service_test.go: add missing interface methods to stubs
- recurring_deposit_integration_test.go: break service<->postgres import
cycle; fix wrong migration filename 038_ -> 039_
Closes Suncrest-Labs#665
- stellar/reader.go: fix invalid int64 shift-by-64 in simulateI128; read i128 value correctly from hi/lo parts - user_handler_test.go: add error checks before using HTTP responses to silence 'using X before checking error' vet warnings
75eb28d to
d2f8b75
Compare
Author
|
@0xDeon All requested changes have been addressed and the branch has been rebased |
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 a dry-run harvest preview endpoint so the frontend can show users a full fee breakdown before committing an on-chain harvest.
Changes
New endpoint
GET /api/v1/vaults/{id}/harvest/preview?compound=trueReturns gross yield, performance fee, net yield, and (optionally) estimated new shares — without writing anything to the DB or chain.
Service layer (
vault_service.go)HarvestPreviewstruct (same shape asHarvestResult, noTxHash)PreviewHarvest(ctx, PreviewHarvestInput)methodharvestableYield()(clamped to 0 on impairment)impaired: truewhen balance < depositedcompound=true, estimates new shares viaestimateSharesMinted()Handler layer (
vault_handler.go)GET /api/v1/vaults/{id}/harvest/preview?compound=truequery param and delegates toPreviewHarvestCI fixes
internal/stellar/reader.go: fixed invalidint64shift-by-64 insimulateI128(go vetfailure)internal/handler/user_handler_test.go: added error checks before using HTTP responses (go vetwarnings)Test coverage
TestPreviewHarvestNormalCaseTestPreviewHarvestImpairedCaseimpaired: trueTestPreviewHarvestCompoundCaseestimated_new_sharespopulatedTestPreviewHarvestForbiddenForOtherUserTestVaultHandlerPreviewHarvestNormalCaseTestVaultHandlerPreviewHarvestImpairedCaseimpaired: trueTestVaultHandlerPreviewHarvestCompoundParamestimated_new_sharesTestVaultHandlerPreviewHarvestForbiddenForOtherUserAll 8 tests pass.
go build ./...,go vet ./..., andgo test -race -short ./...are clean.Closes #665