-
Notifications
You must be signed in to change notification settings - Fork 5
[VPD-1314] Configure PrimeV2 on BSC #712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Debugger022
wants to merge
6
commits into
main
Choose a base branch
from
feat/VPD-1314
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+867
−0
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ca3c34e
feat: add PrimeV2 and PrimeLeaderboard testnet setup
Debugger022 47310d8
fix: address PR review comments
Debugger022 ef6c7f2
chore: tighten VIP-675 testnet sim pre-checks and header comment
Debugger022 bd3c286
chore: update PrimeV2 testnet address and sim fork block
Debugger022 6bd5326
chore: scaffold VIP-675 PrimeV2 setup for bscmainnet
Debugger022 c307c3a
feat: add VIP-675 bsctestnet addendum
Debugger022 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { expect } from "chai"; | ||
| import { Contract } from "ethers"; | ||
| import { ethers } from "hardhat"; | ||
| import { NETWORK_ADDRESSES } from "src/networkAddresses"; | ||
| import { forking, testVip } from "src/vip-framework"; | ||
|
|
||
| import vip675, { PLP, PRIME_LEADERBOARD, PRIME_V2 } from "../../vips/vip-675/bscmainnet"; | ||
|
|
||
| const { bscmainnet } = NETWORK_ADDRESSES; | ||
|
|
||
| // Minimal inline ABIs — PrimeV2 / PrimeLeaderboard not deployed yet, so no | ||
| // generated ABI files exist. Copy full ABIs into ./abi once deployed and swap these out. | ||
| const OWNABLE2STEP_ABI = ["function owner() view returns (address)", "function pendingOwner() view returns (address)"]; | ||
| const PLP_ABI = ["function prime() view returns (address)"]; | ||
|
|
||
| // TODO: set to a block after PrimeV2 / PrimeLeaderboard are deployed on bscmainnet | ||
| const BLOCK_NUMBER = 0; | ||
|
|
||
| forking(BLOCK_NUMBER, async () => { | ||
| let primeV2: Contract; | ||
| let primeLeaderboard: Contract; | ||
| let plp: Contract; | ||
|
|
||
| before(async () => { | ||
| primeV2 = new ethers.Contract(PRIME_V2, OWNABLE2STEP_ABI, ethers.provider); | ||
| primeLeaderboard = new ethers.Contract(PRIME_LEADERBOARD, OWNABLE2STEP_ABI, ethers.provider); | ||
| plp = new ethers.Contract(PLP, PLP_ABI, ethers.provider); | ||
| }); | ||
|
|
||
| describe("Pre-VIP behavior", () => { | ||
| it("PrimeV2 ownership pending on NormalTimelock (not accepted)", async () => { | ||
| expect(await primeV2.pendingOwner()).to.equal(bscmainnet.NORMAL_TIMELOCK); | ||
| }); | ||
|
|
||
| it("PrimeLeaderboard ownership pending on NormalTimelock (not accepted)", async () => { | ||
| expect(await primeLeaderboard.pendingOwner()).to.equal(bscmainnet.NORMAL_TIMELOCK); | ||
| }); | ||
|
|
||
| it("PLP prime token is not yet PrimeV2", async () => { | ||
| expect(await plp.prime()).to.not.equal(PRIME_V2); | ||
| }); | ||
| }); | ||
|
|
||
| testVip("VIP-675 PrimeV2 + PrimeLeaderboard setup", await vip675(), { | ||
| callbackAfterExecution: async () => { | ||
| // TODO: assert OwnershipTransferred / PermissionGranted / MarketAdded events | ||
| // once PrimeV2 / PrimeLeaderboard ABIs are available | ||
| }, | ||
| }); | ||
|
|
||
| describe("Post-VIP behavior", () => { | ||
| it("PrimeV2 owner is the NormalTimelock", async () => { | ||
| expect(await primeV2.owner()).to.equal(bscmainnet.NORMAL_TIMELOCK); | ||
| }); | ||
|
|
||
| it("PrimeLeaderboard owner is the NormalTimelock", async () => { | ||
| expect(await primeLeaderboard.owner()).to.equal(bscmainnet.NORMAL_TIMELOCK); | ||
| }); | ||
|
|
||
| it("PLP points at PrimeV2", async () => { | ||
| expect(await plp.prime()).to.equal(PRIME_V2); | ||
| }); | ||
|
|
||
| it("Prime markets are configured on PrimeV2", async () => { | ||
| // TODO: assert each addMarket entry exists with the expected multipliers | ||
| }); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import { expect } from "chai"; | ||
| import { Contract } from "ethers"; | ||
| import { ethers } from "hardhat"; | ||
| import { NETWORK_ADDRESSES } from "src/networkAddresses"; | ||
| import { forking, testVip } from "src/vip-framework"; | ||
|
|
||
| import { PRIME_LEADERBOARD, PRIME_V2 } from "../../vips/vip-675/bsctestnet"; | ||
| import vip675Addendum, { TIER_DURATIONS, TIER_MULTIPLIERS } from "../../vips/vip-675/bsctestnet-addendum"; | ||
|
|
||
| const { bsctestnet } = NETWORK_ADDRESSES; | ||
|
|
||
| const ACM_ABI = [ | ||
| "function hasRole(bytes32 role, address account) view returns (bool)", | ||
| "event PermissionGranted(address account, address contractAddress, string functionSig)", | ||
| ]; | ||
| const LEADERBOARD_ABI = [ | ||
| "function getMultiplierTiers() view returns (uint256[] durations, uint256[] multipliers)", | ||
| "event MultiplierTiersUpdated(uint256[] durations, uint256[] multipliers)", | ||
| ]; | ||
|
|
||
| const BLOCK_NUMBER = 111353484; | ||
|
|
||
| // All ACM-gated functions on PrimeV2 / PrimeLeaderboard that the addendum grants to the Guardian. | ||
| const PRIME_V2_NEW_GUARDIAN_SIGS = [ | ||
| "setPrimeLeaderboard(address)", | ||
| "addMarket(address,uint256,uint256)", | ||
| "removeMarket(address)", | ||
| "setLimit(uint256)", | ||
| "updateAlpha(uint128,uint128)", | ||
| "updateMultipliers(address,uint256,uint256)", | ||
| "setMaxLoopsLimit(uint256)", | ||
| "pause()", | ||
| "unpause()", | ||
| ]; | ||
| const PRIME_LEADERBOARD_NEW_GUARDIAN_SIGS = [ | ||
| "setMultiplierTiers(uint256[],uint256[])", | ||
| "setPrimeV2(address)", | ||
| "setMaxLoopsLimit(uint256)", | ||
| ]; | ||
|
|
||
| forking(BLOCK_NUMBER, async () => { | ||
| let acm: Contract; | ||
| let leaderboard: Contract; | ||
|
|
||
| before(async () => { | ||
| acm = new ethers.Contract(bsctestnet.ACCESS_CONTROL_MANAGER, ACM_ABI, ethers.provider); | ||
| leaderboard = new ethers.Contract(PRIME_LEADERBOARD, LEADERBOARD_ABI, ethers.provider); | ||
| }); | ||
|
|
||
| const roleFor = (target: string, signature: string) => | ||
| ethers.utils.solidityKeccak256(["address", "string"], [target, signature]); | ||
|
|
||
| describe("Pre-VIP behavior", () => { | ||
| it("Guardian does not yet hold the addendum permissions on PrimeV2", async () => { | ||
| for (const sig of PRIME_V2_NEW_GUARDIAN_SIGS) { | ||
| expect(await acm.hasRole(roleFor(PRIME_V2, sig), bsctestnet.GUARDIAN)).to.equal(false); | ||
| } | ||
| }); | ||
|
|
||
| it("Guardian does not yet hold the addendum permissions on PrimeLeaderboard", async () => { | ||
| for (const sig of PRIME_LEADERBOARD_NEW_GUARDIAN_SIGS) { | ||
| expect(await acm.hasRole(roleFor(PRIME_LEADERBOARD, sig), bsctestnet.GUARDIAN)).to.equal(false); | ||
| } | ||
| }); | ||
|
|
||
| it("PrimeLeaderboard tiers are still the day-scale defaults", async () => { | ||
| const { durations, multipliers } = await leaderboard.getMultiplierTiers(); | ||
| expect(durations.map((d: { toString: () => string }) => d.toString())).to.deep.equal([ | ||
| (30 * 24 * 60 * 60).toString(), | ||
| (60 * 24 * 60 * 60).toString(), | ||
| (90 * 24 * 60 * 60).toString(), | ||
| ]); | ||
| expect(multipliers.map((m: { toString: () => string }) => m.toString())).to.deep.equal([ | ||
| "1300000000000000000", | ||
| "1600000000000000000", | ||
| "2000000000000000000", | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| testVip("VIP-675 addendum [Testnet]", await vip675Addendum(), { | ||
| callbackAfterExecution: async txResponse => { | ||
| await expect(txResponse) | ||
| .to.emit(leaderboard, "MultiplierTiersUpdated") | ||
| .withArgs(TIER_DURATIONS, TIER_MULTIPLIERS); | ||
| await expect(txResponse) | ||
| .to.emit(acm, "PermissionGranted") | ||
| .withArgs(bsctestnet.GUARDIAN, PRIME_LEADERBOARD, "setMultiplierTiers(uint256[],uint256[])"); | ||
| }, | ||
| }); | ||
|
|
||
| describe("Post-VIP behavior", () => { | ||
| it("Guardian holds all addendum permissions on PrimeV2", async () => { | ||
| for (const sig of PRIME_V2_NEW_GUARDIAN_SIGS) { | ||
| expect(await acm.hasRole(roleFor(PRIME_V2, sig), bsctestnet.GUARDIAN)).to.equal(true); | ||
| } | ||
| }); | ||
|
|
||
| it("Guardian holds all addendum permissions on PrimeLeaderboard", async () => { | ||
| for (const sig of PRIME_LEADERBOARD_NEW_GUARDIAN_SIGS) { | ||
| expect(await acm.hasRole(roleFor(PRIME_LEADERBOARD, sig), bsctestnet.GUARDIAN)).to.equal(true); | ||
| } | ||
| }); | ||
|
|
||
| it("PrimeLeaderboard tiers are compressed to the hour-scale schedule", async () => { | ||
| const { durations, multipliers } = await leaderboard.getMultiplierTiers(); | ||
| expect(durations.map((d: { toString: () => string }) => d.toString())).to.deep.equal( | ||
| TIER_DURATIONS.map(d => d.toString()), | ||
| ); | ||
| expect(multipliers.map((m: { toString: () => string }) => m.toString())).to.deep.equal(TIER_MULTIPLIERS); | ||
| }); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| import { expect } from "chai"; | ||
| import { Contract, constants } from "ethers"; | ||
| import { ethers } from "hardhat"; | ||
| import { NETWORK_ADDRESSES } from "src/networkAddresses"; | ||
| import { forking, testVip } from "src/vip-framework"; | ||
|
|
||
| import vip675, { | ||
| COMPTROLLER, | ||
| LEGACY_PRIME, | ||
| MINT_DEADLINE, | ||
| MINT_THRESHOLD, | ||
| PLP, | ||
| PRIME_LEADERBOARD, | ||
| PRIME_MARKETS, | ||
| PRIME_V2, | ||
| XVS_VAULT, | ||
| } from "../../vips/vip-675/bsctestnet"; | ||
|
|
||
| const { bsctestnet } = NETWORK_ADDRESSES; | ||
| const ACM_ABI = [ | ||
| "function hasRole(bytes32 role, address account) view returns (bool)", | ||
| "event PermissionGranted(address account, address contractAddress, string functionSig)", | ||
| ]; | ||
| const VAULT_ABI = ["function primeToken() view returns (address)"]; | ||
| const COMPTROLLER_ABI = ["function prime() view returns (address)"]; | ||
|
|
||
| // Minimal inline ABIs | ||
| const PRIME_V2_ABI = [ | ||
| "function owner() view returns (address)", | ||
| "function pendingOwner() view returns (address)", | ||
| "function primeLeaderboard() view returns (address)", | ||
| "function tokenLimit() view returns (uint256)", | ||
| "function mintThreshold() view returns (uint256)", | ||
| "function mintDeadline() view returns (uint256)", | ||
| "function markets(address) view returns (uint256 supplyMultiplier, uint256 borrowMultiplier, uint256 rewardIndex, uint256 sumOfMembersScore, bool exists)", | ||
| "event MarketAdded(address indexed market, uint256 supplyMultiplier, uint256 borrowMultiplier)", | ||
| "event MintThresholdUpdated(uint256 oldThreshold, uint256 newThreshold, uint256 deadline)", | ||
| "event PrimeLeaderboardSet(address indexed oldLeaderboard, address indexed newLeaderboard)", | ||
| ]; | ||
| const PRIME_LEADERBOARD_ABI = [ | ||
| "function owner() view returns (address)", | ||
| "function pendingOwner() view returns (address)", | ||
| "function primeV2() view returns (address)", | ||
| ]; | ||
| const PLP_ABI = ["function prime() view returns (address)"]; | ||
| const LEGACY_PRIME_ABI = ["function paused() view returns (bool)"]; | ||
|
|
||
| const BLOCK_NUMBER = 111010308; | ||
|
|
||
| forking(BLOCK_NUMBER, async () => { | ||
| let primeV2: Contract; | ||
| let primeLeaderboard: Contract; | ||
| let plp: Contract; | ||
| let legacyPrime: Contract; | ||
| let acm: Contract; | ||
| let xvsVault: Contract; | ||
| let comptroller: Contract; | ||
|
|
||
| before(async () => { | ||
| primeV2 = new ethers.Contract(PRIME_V2, PRIME_V2_ABI, ethers.provider); | ||
| primeLeaderboard = new ethers.Contract(PRIME_LEADERBOARD, PRIME_LEADERBOARD_ABI, ethers.provider); | ||
| plp = new ethers.Contract(PLP, PLP_ABI, ethers.provider); | ||
| legacyPrime = new ethers.Contract(LEGACY_PRIME, LEGACY_PRIME_ABI, ethers.provider); | ||
| acm = new ethers.Contract(bsctestnet.ACCESS_CONTROL_MANAGER, ACM_ABI, ethers.provider); | ||
| xvsVault = new ethers.Contract(XVS_VAULT, VAULT_ABI, ethers.provider); | ||
| comptroller = new ethers.Contract(COMPTROLLER, COMPTROLLER_ABI, ethers.provider); | ||
| }); | ||
|
|
||
| const roleFor = (target: string, signature: string) => | ||
| ethers.utils.solidityKeccak256(["address", "string"], [target, signature]); | ||
|
|
||
| describe("Pre-VIP behavior", () => { | ||
| it("PrimeV2 ownership pending on NormalTimelock (not accepted)", async () => { | ||
| expect(await primeV2.pendingOwner()).to.equal(bsctestnet.NORMAL_TIMELOCK); | ||
| }); | ||
|
|
||
| it("PrimeLeaderboard ownership pending on NormalTimelock (not accepted)", async () => { | ||
| expect(await primeLeaderboard.pendingOwner()).to.equal(bsctestnet.NORMAL_TIMELOCK); | ||
| }); | ||
|
|
||
| it("PLP prime token is still the legacy Prime", async () => { | ||
| expect(await plp.prime()).to.equal(LEGACY_PRIME); | ||
| }); | ||
|
|
||
| it("PrimeV2 <-> PrimeLeaderboard are not yet wired", async () => { | ||
| expect(await primeV2.primeLeaderboard()).to.equal(constants.AddressZero); | ||
| expect(await primeLeaderboard.primeV2()).to.equal(constants.AddressZero); | ||
| }); | ||
|
|
||
| it("PrimeV2 mint window is not yet open", async () => { | ||
| expect(await primeV2.mintThreshold()).to.equal(0); | ||
| expect(await primeV2.mintDeadline()).to.equal(0); | ||
| }); | ||
|
|
||
| it("legacy Prime is active (unpaused)", async () => { | ||
| expect(await legacyPrime.paused()).to.equal(false); | ||
| }); | ||
|
|
||
| it("XVSVault prime hook still points at legacy Prime", async () => { | ||
| expect(await xvsVault.primeToken()).to.equal(LEGACY_PRIME); | ||
| }); | ||
|
|
||
| it("Comptroller prime still points at legacy Prime", async () => { | ||
| expect(await comptroller.prime()).to.equal(LEGACY_PRIME); | ||
| }); | ||
| }); | ||
|
|
||
| testVip("VIP-675 [Testnet] PrimeV2 + PrimeLeaderboard setup", await vip675(), { | ||
| callbackAfterExecution: async txResponse => { | ||
| await expect(txResponse) | ||
| .to.emit(primeV2, "PrimeLeaderboardSet") | ||
| .withArgs(constants.AddressZero, PRIME_LEADERBOARD); | ||
| await expect(txResponse).to.emit(primeV2, "MintThresholdUpdated").withArgs(0, MINT_THRESHOLD, MINT_DEADLINE); | ||
| for (const market of PRIME_MARKETS) { | ||
| await expect(txResponse) | ||
| .to.emit(primeV2, "MarketAdded") | ||
| .withArgs(market.vToken, market.supplyMultiplier, market.borrowMultiplier); | ||
| } | ||
| // ACM emits PermissionGranted for every ACM-gated function granted by this VIP; | ||
| // spot-check the Guardian's issue(address) grant on PrimeV2. | ||
| await expect(txResponse) | ||
| .to.emit(acm, "PermissionGranted") | ||
| .withArgs(bsctestnet.GUARDIAN, PRIME_V2, "issue(address)"); | ||
| }, | ||
| }); | ||
|
|
||
| describe("Post-VIP behavior", () => { | ||
| it("PrimeV2 owner is the NormalTimelock", async () => { | ||
| expect(await primeV2.owner()).to.equal(bsctestnet.NORMAL_TIMELOCK); | ||
| }); | ||
|
|
||
| it("PrimeLeaderboard owner is the NormalTimelock", async () => { | ||
| expect(await primeLeaderboard.owner()).to.equal(bsctestnet.NORMAL_TIMELOCK); | ||
| }); | ||
|
|
||
| it("PLP points at PrimeV2", async () => { | ||
| expect(await plp.prime()).to.equal(PRIME_V2); | ||
| }); | ||
|
|
||
| it("PrimeV2 <-> PrimeLeaderboard are wired", async () => { | ||
| expect(await primeV2.primeLeaderboard()).to.equal(PRIME_LEADERBOARD); | ||
| expect(await primeLeaderboard.primeV2()).to.equal(PRIME_V2); | ||
| }); | ||
|
|
||
| it("PrimeV2 token limit is 500", async () => { | ||
| expect(await primeV2.tokenLimit()).to.equal(500); | ||
| }); | ||
|
|
||
| it("PrimeV2 mint window is configured", async () => { | ||
| expect(await primeV2.mintThreshold()).to.equal(MINT_THRESHOLD); | ||
| expect(await primeV2.mintDeadline()).to.equal(MINT_DEADLINE); | ||
| }); | ||
|
|
||
| it("Guardian can call epoch ops on PrimeV2 (issue / issueBatch / burn / burnBatch / setMintThreshold)", async () => { | ||
| for (const sig of [ | ||
| "issue(address)", | ||
| "issueBatch(address[])", | ||
| "burn(address)", | ||
| "burnBatch(address[])", | ||
| "setMintThreshold(uint256,uint256)", | ||
| ]) { | ||
| expect(await acm.hasRole(roleFor(PRIME_V2, sig), bsctestnet.GUARDIAN)).to.equal(true); | ||
| } | ||
| }); | ||
|
|
||
| it("Guardian can seed stakers on PrimeLeaderboard", async () => { | ||
| for (const sig of ["initializeStakers(address[],uint256[],uint64[])", "finalizeInitialization()"]) { | ||
| expect(await acm.hasRole(roleFor(PRIME_LEADERBOARD, sig), bsctestnet.GUARDIAN)).to.equal(true); | ||
| } | ||
| }); | ||
|
|
||
| it("NormalTimelock can configure PrimeLeaderboard (tiers / primeV2 / maxLoops)", async () => { | ||
| for (const sig of [ | ||
| "setMultiplierTiers(uint256[],uint256[])", | ||
| "setPrimeV2(address)", | ||
| "setMaxLoopsLimit(uint256)", | ||
| ]) { | ||
| expect(await acm.hasRole(roleFor(PRIME_LEADERBOARD, sig), bsctestnet.NORMAL_TIMELOCK)).to.equal(true); | ||
| } | ||
| }); | ||
|
|
||
| it("XVSVault prime hook points at PrimeLeaderboard", async () => { | ||
| expect(await xvsVault.primeToken()).to.equal(PRIME_LEADERBOARD); | ||
| }); | ||
|
|
||
| it("Comptroller prime points at PrimeV2", async () => { | ||
| expect(await comptroller.prime()).to.equal(PRIME_V2); | ||
| }); | ||
|
|
||
| it("legacy Prime is decommissioned (paused)", async () => { | ||
| expect(await legacyPrime.paused()).to.equal(true); | ||
| }); | ||
|
|
||
| for (const market of PRIME_MARKETS) { | ||
| it(`market ${market.vToken} is configured on PrimeV2`, async () => { | ||
| const m = await primeV2.markets(market.vToken); | ||
| expect(m.exists).to.equal(true); | ||
| expect(m.supplyMultiplier).to.equal(market.supplyMultiplier); | ||
| expect(m.borrowMultiplier).to.equal(market.borrowMultiplier); | ||
| }); | ||
| } | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.