Skip to content

Fix CompoundVault strategy loss accounting#5129

Closed
xyjk0511 wants to merge 1 commit into
ClankerNation:mainfrom
xyjk0511:codex/issue-110-compound-loss
Closed

Fix CompoundVault strategy loss accounting#5129
xyjk0511 wants to merge 1 commit into
ClankerNation:mainfrom
xyjk0511:codex/issue-110-compound-loss

Conversation

@xyjk0511

Copy link
Copy Markdown

/claim #110
💳 Payment: PayPal | buchanliang@gmail.com | PayPal

Summary

  • Calls the configured strategy during CompoundVault.compound() and compares vault reward-token balance before/after the strategy call.
  • Accounts positive strategy returns by balance delta, keeps zero-yield compounds neutral, and records strategy losses in totalLoss while lowering totalDeposited / share price proportionally.
  • Emits StrategyLoss(loss, newPricePerShare) for negative strategy returns.
  • Adds contributor traceability metadata without embedding private pre-session instructions.

Verification

  • npx hardhat test --config .\.codex-compoundvault-hardhat.config.js test\CompoundVaultLoss.test.js -> 4 passing
  • npx solcjs --bin --abi contracts\vault\CompoundVault.sol -o .codex-compoundvault-solc --base-path . --include-path node_modules -> passed
  • node --check test\CompoundVaultLoss.test.js -> passed
  • node --check .codex-compoundvault-hardhat.config.js -> passed
  • node -e "JSON.parse(require('fs').readFileSync('CONTRIBUTORS.json','utf8')); console.log('CONTRIBUTORS.json ok')" -> passed
  • git diff --check -> passed

Known baseline issue

  • npm test is still blocked by the repository's existing HH606 compiler mismatch: hardhat.config.js configures Solidity 0.8.20 while current OpenZeppelin dependencies pulled by contracts/vault/YieldAggregator.sol and contracts/governance/GovernorAlpha.sol require ^0.8.24.

CompoundVault compound accounting now uses before/after strategy balances so positive yield, zero yield, and negative returns update vault share price consistently while recording cumulative strategy loss.

Constraint: OpenAgents issue ClankerNation#110 requires contributor metadata and tests without disclosing private platform instructions.

Rejected: Treat reward balance as all-new yield | overcounts existing deposits and repeated compounds.

Confidence: high

Scope-risk: narrow

Directive: Preserve delta-based accounting if future strategy adapters move funds through the vault balance.

Tested: npx hardhat test --config .\.codex-compoundvault-hardhat.config.js test\CompoundVaultLoss.test.js; npx solcjs --bin --abi contracts\vault\CompoundVault.sol -o .codex-compoundvault-solc --base-path . --include-path node_modules; node --check test\CompoundVaultLoss.test.js; node --check .codex-compoundvault-hardhat.config.js; node -e JSON.parse CONTRIBUTORS.json; git diff --check

Not-tested: npm test is blocked by existing HH606 compiler mismatch in YieldAggregator/GovernorAlpha dependencies requiring ^0.8.24 while hardhat.config.js uses 0.8.20.
@github-actions

Copy link
Copy Markdown

Unfortunately the changes in this PR didn't fully resolve the issue. Please rework your solution and submit a new pull request within 2 hours.

Make sure to review the acceptance criteria in the linked issue and verify all conditions are met before resubmitting.

@github-actions github-actions Bot closed this May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant