Skip to content

[VPD-1313] PrimeV2 deployments for BSC#677

Open
Debugger022 wants to merge 14 commits into
feat/prime-v2from
feat/VPD-1313
Open

[VPD-1313] PrimeV2 deployments for BSC#677
Debugger022 wants to merge 14 commits into
feat/prime-v2from
feat/VPD-1313

Conversation

@Debugger022

@Debugger022 Debugger022 commented May 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Introduce PrimeLens — a standalone view-only contract that reads PrimeV2's public mappings and reconstructs the V1 APR helpers (calculateAPR, estimateAPR, incomeDistributionYearly) for off-chain consumers. Lives in a separate deployment so PrimeV2 stays under the 24,576-byte EVM contract-size limit.
  • Restore impl-only / lens-only / leaderboard-only deploy scripts so the three contracts can be redeployed independently across upgrades and chains.
  • Land deployment artifacts for bsctestnet + bscmainnet (PrimeV2, PrimeLeaderboard, PrimeLens) plus a fresh testnet WBNB reward-distribution fork test.

Changes

Contracts

  • PrimeLens.sol — new stateless view contract. Reads PrimeV2's public getters via IPrimeV2WithStorage; computes per-(market, user) APR figures off-chain. PrimeV2 itself unchanged → no link-time dependency, no contract-size pressure.
  • IPrimeV2.sol — added APRInfo and Capital structs consumed by the lens.

Deploy scripts

  • deploy/014-deploy-prime-leaderboard.ts — split out from the original combined script.
  • deploy/014-deploy-prime-v2.ts — focused on PrimeV2 proxy + initialize, with ACM-permission grants for the local hardhat network and ownership transfer to the network's NormalTimelock on live chains.
  • deploy/015-deploy-prime-v2-impl.ts — impl-only redeploy path (no proxy / initialize); used when shipping a new PrimeV2 implementation for upgrade.
  • deploy/016-deploy-prime-lens.ts — deploys the lens with the existing PrimeV2 proxy address as constructor arg.
  • Removed deploy/015-configure-prime-v2.ts — wiring now lives inside the per-contract scripts; on live networks the cross-contract setters run via VIP, not deploy.

Deployments

  • bsctestnet: PrimeV2 (0xeC22366d2572e52BCB29B50C905b945BA421B9b2), PrimeLeaderboard, PrimeLens, with implementations + proxies.
  • bscmainnet: PrimeV2 (0x4f5fd115Df31CC48De880a988D74aaD931851628), PrimeLeaderboard, PrimeLens (0x43e768EFa1bC365bfd0965A490a41d87c6Dea526), with implementations + proxies + solcInputs.

Tests

  • tests/hardhat/PrimeV2/PrimeLens.ts — unit suite for the lens. Constructor edge cases; exact-equality assertions against PrimeV2 stored state; APR formula identity check; zero-distribution and no-totalScore branches; estimate's "subtract user score then re-add" invariant.
  • tests/hardhat/Fork/PrimeLensForkTest.ts — bsctestnet fork test. Deploys fresh PrimeV2 + Leaderboard + Lens against real Comptroller/Oracle/XVSVault/PLP/ACM; verifies all three view helpers behave correctly against on-chain state.
  • tests/hardhat/Fork/PrimeV2TestnetWbnbRewardForkTest.ts — fork test covering the native-market (WBNB) reward path on bsctestnet.

Config

  • hardhat.config.ts — added chain 97 (bsctestnet) hardfork history to isFork() so testnet fork tests can execute historical blocks.

Wiring gated to hardhat (live wires via VIP), add impl verification,
and drop the 'Prime' dependency to avoid re-triggering 012's proxy
upgrade that reverts under Timelock ownership.
Deployment artifacts from deploying PrimeLeaderboard and PrimeV2 to
bsctestnet. Contracts are unwired; setPrimeV2/setPrimeLeaderboard
wiring lands via VIP.
@Debugger022 Debugger022 self-assigned this May 29, 2026
…scripts

Fold the Timelock ownership transfer into each deploy script so it runs
with the deploy tag (the standalone PrimeLeaderboard deploy had no
configure step). Removes the now-redundant 015-configure-prime-v2.
@Debugger022 Debugger022 marked this pull request as ready for review June 1, 2026 04:04

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

Standalone tagged hardhat-deploy script for deploying a new PrimeV2
implementation against a Timelock-owned proxy; the impl is left
unwired so a governance VIP can call ProxyAdmin.upgrade to point the
proxy at it. Includes the resulting bsctestnet implementation artifact.
@Debugger022 Debugger022 changed the base branch from feat/VPD-1292 to feat/prime-v2 June 10, 2026 15:19
Standalone view-only contract that reads PrimeV2 state via its public
mappings. Replaces V1's removed 'calculateAPR' / 'estimateAPR' /
'incomeDistributionYearly' helpers without growing PrimeV2 past the 24KB
EVM size limit. Adds 'APRInfo' and 'Capital' structs to 'IPrimeV2'.
borrowAPR = totalBorrow == 0 ? 0 : ((userBorrowIncomeYearly * MAXIMUM_BPS) / totalBorrow);
}

function _getUnderlying(address vToken) internal view returns (address) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

we need handle the native token case, same with prime v2

function _getUnderlying(address vToken) internal view returns (address) {
if (vToken == primeV2.NATIVE_MARKET()) {
return primeV2.WRAPPED_NATIVE_TOKEN();
}
return IVToken(vToken).underlying();
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

address market,
address user
) external view returns (uint256 accrued, uint256 score, uint256 rewardIndex, uint256 lifetimeAccrued);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

function NATIVE_MARKET() external view returns (address);
function WRAPPED_NATIVE_TOKEN() external view returns (address);

add this two to read from Prime v2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolve vBNB→WBNB in PrimeLens._getUnderlying so APR queries on the
native market hit PLP correctly. Add hardhat-deploy script for
PrimeLens, fork test, and a bsctestnet chain hardhat hardfork-history
entry so the lens fork suite can run.
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.

2 participants