Skip to content

feat(contracts): add get_depositor_yield() view function to LendingPool#601

Merged
ogazboiz merged 4 commits intoLabsCrypt:mainfrom
Sundriveauto:feat/depositor-yield-query
Apr 2, 2026
Merged

feat(contracts): add get_depositor_yield() view function to LendingPool#601
ogazboiz merged 4 commits intoLabsCrypt:mainfrom
Sundriveauto:feat/depositor-yield-query

Conversation

@Sundriveauto
Copy link
Copy Markdown
Contributor

@Sundriveauto Sundriveauto commented Mar 29, 2026

Closes #458

Problem

The LendingPool contract had no on-chain way for depositors to query their current yield. They had to fetch share price externally and do manual math.

Solution

Added get_depositor_yield(env, provider, token) -> (i128, i128) which returns:

  • shares — LP shares held by the provider
  • asset_value — current redemption value of those shares (principal + accrued yield)

Net yield = asset_value - original_deposit. Since original deposit amounts are not stored per-depositor, callers compare asset_value against their own recorded cost basis.

The implementation reuses existing private helpers (read_shares, total_shares, read_pool_balance, calc_assets_to_redeem) with no new storage.

Tests

Added 2 tests to test.rs:

  • test_get_depositor_yield_no_deposit — returns (0, 0) for a provider with no position
  • test_get_depositor_yield_reflects_accrued_interest — verifies asset_value increases when interest is repaid into the pool without new shares being minted

@ogazboiz Pls review Conflict

Copy link
Copy Markdown
Contributor

@ogazboiz ogazboiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get_depositor_yield function looks correct and the tests cover the key cases.

Two things before this can merge:

1. Remove .kiro/settings/lsp.json
This is an IDE settings file from the Kiro editor and should not be in the repo. Add .kiro/ to your .gitignore and remove the file:

git rm -r .kiro/
echo '.kiro/' >> .gitignore
git commit -m 'chore: remove Kiro IDE settings, add to gitignore'

2. CI needs approval
The CI run is showing action_required which means it hasn't started yet. A maintainer will approve the CI run after you push the fix.

@ogazboiz
Copy link
Copy Markdown
Contributor

The codebase issues on main have been resolved and all CI checks are passing now. Please rebase your branch to pull in the latest changes before continuing. Thanks for your patience.

@Sundriveauto
Copy link
Copy Markdown
Contributor Author

@ogazboiz i have done that

Copy link
Copy Markdown
Contributor

@ogazboiz ogazboiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR includes the entire diff of PR #600 (timeout changes, .kiro file, lockfile noise). The contract code for get_depositor_yield is correct and well tested. Please rebase onto a clean branch without the #600 backend changes. Run cargo fmt.

@Sundriveauto Sundriveauto force-pushed the feat/depositor-yield-query branch from 737ba5b to ec569d1 Compare March 31, 2026 03:06
@Sundriveauto
Copy link
Copy Markdown
Contributor Author

@ogazboiz review

@ogazboiz
Copy link
Copy Markdown
Contributor

All three feedback items addressed. The branch is clean now with just the contract changes. Same as #600 though, CI hasn't run on this branch. Push an empty commit to trigger it: git commit --allow-empty -m 'trigger CI' && git push

@Sundriveauto
Copy link
Copy Markdown
Contributor Author

@ogazboiz review

@ogazboiz
Copy link
Copy Markdown
Contributor

heads up, a few important changes just landed on main that affect your PR:

  1. axios pinned to 1.13.5 - there's an active supply chain attack on axios 1.14.1 (pulls in confirmed malware). we added overrides in all package.json files to block it.

  2. CI now runs a supply chain audit before backend/frontend jobs. if your lockfile has a compromised package, CI will fail with a clear error.

  3. backend test fixes - loanEndpoints tests now use valid Stellar addresses and base64 strings. if your PR was failing backend CI but you didn't touch backend code, this should fix it after rebase.

please rebase on latest main:

git fetch upstream
git rebase upstream/main
git push --force-with-lease

Returns (shares, current_asset_value) for a provider so depositors can
see their on-chain returns without external share-price math.

Closes LabsCrypt#473
@Sundriveauto Sundriveauto force-pushed the feat/depositor-yield-query branch from b0bc47e to 56a56fe Compare March 31, 2026 14:11
@Sundriveauto
Copy link
Copy Markdown
Contributor Author

@ogazboiz rebase done

Copy link
Copy Markdown
Contributor

@ogazboiz ogazboiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @Sundriveauto, code looks good. the get_depositor_yield view function is clean and the tests cover both the zero-deposit and accrued-interest cases. merging!

if you want to keep contributing or follow up on open issues, join us on Telegram: https://t.me/+DOylgFv1jyJlNzM0

@ogazboiz ogazboiz merged commit daa140f into LabsCrypt:main Apr 2, 2026
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.

feat(contracts): add get_depositor_yield() view function to LendingPool

2 participants