From eb90305cbf50688477754feda9e0d9ae8a8cb912 Mon Sep 17 00:00:00 2001 From: nikhilbajaj31 Date: Tue, 6 Aug 2024 00:43:59 +0530 Subject: [PATCH 01/13] add proposal to upgrade incentives controller --- foundry.toml | 12 +++++- lib/core-contracts | 2 +- lib/forge-std | 2 +- src/p002/P002_UpgradeIncentivesController.sol | 40 +++++++++++++++++++ src/p002/README.md | 3 ++ 5 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/p002/P002_UpgradeIncentivesController.sol create mode 100644 src/p002/README.md diff --git a/foundry.toml b/foundry.toml index 25b918f..81944cf 100644 --- a/foundry.toml +++ b/foundry.toml @@ -1,6 +1,16 @@ [profile.default] src = "src" out = "out" -libs = ["lib"] +libs = [ + "lib/core-contracts", + "lib/forge-std", + "lib/periphery-contracts", + "lib/core-v3" +] +remappings = [ + "forge-std/=lib/forge-std/src/", + "periphery-contracts/=lib/periphery-contracts/", + "@zerolendxyz/core-v3/=lib/core-contracts/" +] # See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options diff --git a/lib/core-contracts b/lib/core-contracts index 2d518fa..cd75dfe 160000 --- a/lib/core-contracts +++ b/lib/core-contracts @@ -1 +1 @@ -Subproject commit 2d518faa63833595979adb1786a63575a94264d4 +Subproject commit cd75dfe01530fdbc5dbb5f47304b8c3658256fe8 diff --git a/lib/forge-std b/lib/forge-std index 07263d1..1714bee 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 07263d193d621c4b2b0ce8b4d54af58f6957d97d +Subproject commit 1714bee72e286e73f76e320d110e0eaf5c4e649d diff --git a/src/p002/P002_UpgradeIncentivesController.sol b/src/p002/P002_UpgradeIncentivesController.sol new file mode 100644 index 0000000..2e0b19b --- /dev/null +++ b/src/p002/P002_UpgradeIncentivesController.sol @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.8.12; + +// ███████╗███████╗██████╗ ██████╗ +// ╚══███╔╝██╔════╝██╔══██╗██╔═══██╗ +// ███╔╝ █████╗ ██████╔╝██║ ██║ +// ███╔╝ ██╔══╝ ██╔══██╗██║ ██║ +// ███████╗███████╗██║ ██║╚██████╔╝ +// ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ + +// Website: https://zerolend.xyz +// Discord: https://discord.gg/zerolend +// Twitter: https://twitter.com/zerolendxyz +// Telegram: https://t.me/zerolendxyz + +// visit https://github.com/zerolend/proposals for information about tests and deployment scripts + +import {RewardsController} from "lib/periphery-contracts/contracts/rewards/RewardsController.sol"; + + +interface IRewardsController { + function upgradeTo(address newImplementation) external; +} +contract P002_UpgradeIncentiveController { + address private constant EMISSIONS_MANAGER = 0x749dF84Fd6DE7c0A67db3827e5118259ed3aBBa5; + address private constant STAKING = 0x2666951A62d82860E8e1385581E2FB7669097647; + address private constant REWARDS_CONTROLLER_PROXY = 0x28F6899fF643261Ca9766ddc251b359A2d00b945; + + IRewardsController rewardsControllerProxy; + RewardsController rewardsControllerImpl; + + constructor() { + rewardsControllerProxy = IRewardsController(REWARDS_CONTROLLER_PROXY); + rewardsControllerImpl = new RewardsController(EMISSIONS_MANAGER, STAKING); + } + + function execute() public { + rewardsControllerProxy.upgradeTo(address(rewardsControllerImpl)); + } +} \ No newline at end of file diff --git a/src/p002/README.md b/src/p002/README.md new file mode 100644 index 0000000..34c46c6 --- /dev/null +++ b/src/p002/README.md @@ -0,0 +1,3 @@ +# Proposal 002 + +Proposal 002 helps in upgrading the IncentivesController proxy with the fixed boosted-rewards code, and some getters. From 21f061549047cf4d7a5c33ad05ba1f5c8b7468d2 Mon Sep 17 00:00:00 2001 From: nikhilbajaj31 Date: Tue, 6 Aug 2024 00:50:10 +0530 Subject: [PATCH 02/13] forge fmt --- .gitmodules | 3 +++ foundry.toml | 2 +- lib/governance | 1 + src/p002/P002_UpgradeIncentivesController.sol | 8 ++++---- 4 files changed, 9 insertions(+), 5 deletions(-) create mode 160000 lib/governance diff --git a/.gitmodules b/.gitmodules index c943a4c..394d259 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "lib/periphery-contracts"] path = lib/periphery-contracts url = https://github.com/zerolend/periphery-contracts +[submodule "lib/governance"] + path = lib/governance + url = https://github.com/zerolend/governance diff --git a/foundry.toml b/foundry.toml index 81944cf..ee993bf 100644 --- a/foundry.toml +++ b/foundry.toml @@ -5,7 +5,7 @@ libs = [ "lib/core-contracts", "lib/forge-std", "lib/periphery-contracts", - "lib/core-v3" + "lib/governance" ] remappings = [ "forge-std/=lib/forge-std/src/", diff --git a/lib/governance b/lib/governance new file mode 160000 index 0000000..a20868f --- /dev/null +++ b/lib/governance @@ -0,0 +1 @@ +Subproject commit a20868f7ec8163760c8b67a11d2ca0d083ed7827 diff --git a/src/p002/P002_UpgradeIncentivesController.sol b/src/p002/P002_UpgradeIncentivesController.sol index 2e0b19b..cb26671 100644 --- a/src/p002/P002_UpgradeIncentivesController.sol +++ b/src/p002/P002_UpgradeIncentivesController.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.12; +pragma solidity 0.8.19; // ███████╗███████╗██████╗ ██████╗ // ╚══███╔╝██╔════╝██╔══██╗██╔═══██╗ @@ -17,14 +17,14 @@ pragma solidity 0.8.12; import {RewardsController} from "lib/periphery-contracts/contracts/rewards/RewardsController.sol"; - interface IRewardsController { function upgradeTo(address newImplementation) external; } + contract P002_UpgradeIncentiveController { address private constant EMISSIONS_MANAGER = 0x749dF84Fd6DE7c0A67db3827e5118259ed3aBBa5; address private constant STAKING = 0x2666951A62d82860E8e1385581E2FB7669097647; - address private constant REWARDS_CONTROLLER_PROXY = 0x28F6899fF643261Ca9766ddc251b359A2d00b945; + address private constant REWARDS_CONTROLLER_PROXY = 0x28F6899fF643261Ca9766ddc251b359A2d00b945; IRewardsController rewardsControllerProxy; RewardsController rewardsControllerImpl; @@ -37,4 +37,4 @@ contract P002_UpgradeIncentiveController { function execute() public { rewardsControllerProxy.upgradeTo(address(rewardsControllerImpl)); } -} \ No newline at end of file +} From e80e73a0238bc7954320f1978273f6d5229444e5 Mon Sep 17 00:00:00 2001 From: nikhilbajaj31 Date: Tue, 6 Aug 2024 00:58:47 +0530 Subject: [PATCH 03/13] add proposal to update cliff for airdrop vests --- src/p003/P003_UpdateCliffForAirdrops.sol | 59 ++++++++++++++++++++++++ src/p003/README.md | 3 ++ 2 files changed, 62 insertions(+) create mode 100644 src/p003/P003_UpdateCliffForAirdrops.sol create mode 100644 src/p003/README.md diff --git a/src/p003/P003_UpdateCliffForAirdrops.sol b/src/p003/P003_UpdateCliffForAirdrops.sol new file mode 100644 index 0000000..9230dc6 --- /dev/null +++ b/src/p003/P003_UpdateCliffForAirdrops.sol @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.8.19; + +// ███████╗███████╗██████╗ ██████╗ +// ╚══███╔╝██╔════╝██╔══██╗██╔═══██╗ +// ███╔╝ █████╗ ██████╔╝██║ ██║ +// ███╔╝ ██╔══╝ ██╔══██╗██║ ██║ +// ███████╗███████╗██║ ██║╚██████╔╝ +// ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ + +// Website: https://zerolend.xyz +// Discord: https://discord.gg/zerolend +// Twitter: https://twitter.com/zerolendxyz +// Telegram: https://t.me/zerolendxyz + +// visit https://github.com/zerolend/proposals for information about tests and deployment scripts + +import { IVestedZeroNFT } from "lib/governance/contracts/interfaces/IVestedZeroNFT.sol"; +import { VestedZeroNFT } from "lib/governance/contracts/vesting/VestedZeroNFT.sol"; + +contract P003_UpdateCliffForAirdrops { + uint256 public constant LINEAR_DURATION = 86400 * 91; + uint256 public constant CLIFF_DURATION = 86400 * 90; + address public constant VESTED_ZERO_NFT_PROXY_ADDRESS = 0x9FA72ea96591e486FF065E7C8A89282dEDfA6C12; + uint256[] public tokenIds; + VestedZeroNFT public vestedZeroNFT; + + constructor() { + vestedZeroNFT = IVestedZeroNFT(VESTED_ZERO_NFT_PROXY_ADDRESS); + } + + function execute() public { + + uint256 lastTokenId = vestedZeroNFT.lastTokenId(); + + for (uint256 i = 0; i < lastTokenId; i++) { + getAirdropTokenId(i); + } + + uint256[] memory linearDuration = new uint256[](tokenIds.length); + uint256[] memory cliffDuration = new uint256[](tokenIds.length); + + for (uint256 i = 0; i < tokenIds.length; i++) { + linearDuration[i] = LINEAR_DURATION; + cliffDuration[i] = CLIFF_DURATION; + } + + vestedZeroNFT.updateCliffDuration(tokenIds, linearDuration, cliffDuration); + } + + function getAirdropTokenId(uint256 i) internal { + (uint256 category,, uint256 cliffDuration) = vestedZeroNFT.tokenIdToLockDetails(i); + if (category == IVestedZeroNFT.Category.AIRDROP) { + if (cliffDuration > 86400 * 90) { + tokenIds.push(i); + } + } + } +} diff --git a/src/p003/README.md b/src/p003/README.md new file mode 100644 index 0000000..9ed45ff --- /dev/null +++ b/src/p003/README.md @@ -0,0 +1,3 @@ +# Proposal 003 + +Proposal 003 helps in updating the cliff duration from 6 months to 3 months for all airdrop vests. \ No newline at end of file From 34dc397b50266574469f06a49cf909a9dd791d24 Mon Sep 17 00:00:00 2001 From: nikhilbajaj31 Date: Tue, 6 Aug 2024 14:35:30 +0530 Subject: [PATCH 04/13] fix: refactor update logic for incentive controller --- src/p002/P002_UpgradeIncentivesController.sol | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/p002/P002_UpgradeIncentivesController.sol b/src/p002/P002_UpgradeIncentivesController.sol index cb26671..8d3dec0 100644 --- a/src/p002/P002_UpgradeIncentivesController.sol +++ b/src/p002/P002_UpgradeIncentivesController.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.19; +pragma solidity 0.8.12; // ███████╗███████╗██████╗ ██████╗ // ╚══███╔╝██╔════╝██╔══██╗██╔═══██╗ @@ -17,24 +17,25 @@ pragma solidity 0.8.19; import {RewardsController} from "lib/periphery-contracts/contracts/rewards/RewardsController.sol"; -interface IRewardsController { - function upgradeTo(address newImplementation) external; +interface IZeroAddressProvider { + function setAddressAsProxy(bytes32 id, address newImplementationAddress) external; } contract P002_UpgradeIncentiveController { address private constant EMISSIONS_MANAGER = 0x749dF84Fd6DE7c0A67db3827e5118259ed3aBBa5; address private constant STAKING = 0x2666951A62d82860E8e1385581E2FB7669097647; - address private constant REWARDS_CONTROLLER_PROXY = 0x28F6899fF643261Ca9766ddc251b359A2d00b945; + address private constant ZERO_ADDRESS_PROVIDER = 0xC44827C51d00381ed4C52646aeAB45b455d200eB; + bytes32 private constant INCENTIVE_CONTROLLER_ID = 0x703c2c8634bed68d98c029c18f310e7f7ec0e5d6342c590190b3cb8b3ba54532; - IRewardsController rewardsControllerProxy; + IZeroAddressProvider zeroAddressProvider; RewardsController rewardsControllerImpl; constructor() { - rewardsControllerProxy = IRewardsController(REWARDS_CONTROLLER_PROXY); + zeroAddressProvider = IZeroAddressProvider(ZERO_ADDRESS_PROVIDER); rewardsControllerImpl = new RewardsController(EMISSIONS_MANAGER, STAKING); } function execute() public { - rewardsControllerProxy.upgradeTo(address(rewardsControllerImpl)); + zeroAddressProvider.setAddressAsProxy(INCENTIVE_CONTROLLER_ID, address(rewardsControllerImpl)); } } From 989dc139b780b813f31c94fc59ac11a09ebc4164 Mon Sep 17 00:00:00 2001 From: nikhilbajaj31 Date: Tue, 6 Aug 2024 23:20:22 +0530 Subject: [PATCH 05/13] add deploy script and tests for P002 --- script/Deploy_P002.sol | 28 +++++ src/p002/P002_UpgradeIncentivesController.sol | 10 +- test/Test_P002.sol | 111 ++++++++++++++++++ 3 files changed, 144 insertions(+), 5 deletions(-) create mode 100644 script/Deploy_P002.sol create mode 100644 test/Test_P002.sol diff --git a/script/Deploy_P002.sol b/script/Deploy_P002.sol new file mode 100644 index 0000000..fc3678e --- /dev/null +++ b/script/Deploy_P002.sol @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.8.12; + +// ███████╗███████╗██████╗ ██████╗ +// ╚══███╔╝██╔════╝██╔══██╗██╔═══██╗ +// ███╔╝ █████╗ ██████╔╝██║ ██║ +// ███╔╝ ██╔══╝ ██╔══██╗██║ ██║ +// ███████╗███████╗██║ ██║╚██████╔╝ +// ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ + +// Website: https://zerolend.xyz +// Discord: https://discord.gg/zerolend +// Twitter: https://twitter.com/zerolendxyz +// Telegram: https://t.me/zerolendxyz + +import { P002_UpgradeIncentiveController } from "src/p002/P002_UpgradeIncentivesController.sol"; +import {Script} from "../lib/forge-std/src/Script.sol"; + +contract Deploy_P002 is Script { + function run() external { + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + vm.startBroadcast(deployerPrivateKey); + + new P002_UpgradeIncentiveController(); + + vm.stopBroadcast(); + } +} diff --git a/src/p002/P002_UpgradeIncentivesController.sol b/src/p002/P002_UpgradeIncentivesController.sol index 8d3dec0..a545013 100644 --- a/src/p002/P002_UpgradeIncentivesController.sol +++ b/src/p002/P002_UpgradeIncentivesController.sol @@ -17,25 +17,25 @@ pragma solidity 0.8.12; import {RewardsController} from "lib/periphery-contracts/contracts/rewards/RewardsController.sol"; -interface IZeroAddressProvider { +interface IPoolAddressProvider { function setAddressAsProxy(bytes32 id, address newImplementationAddress) external; } contract P002_UpgradeIncentiveController { address private constant EMISSIONS_MANAGER = 0x749dF84Fd6DE7c0A67db3827e5118259ed3aBBa5; address private constant STAKING = 0x2666951A62d82860E8e1385581E2FB7669097647; - address private constant ZERO_ADDRESS_PROVIDER = 0xC44827C51d00381ed4C52646aeAB45b455d200eB; + address private constant POOL_ADDRESS_PROVIDER = 0xC44827C51d00381ed4C52646aeAB45b455d200eB; bytes32 private constant INCENTIVE_CONTROLLER_ID = 0x703c2c8634bed68d98c029c18f310e7f7ec0e5d6342c590190b3cb8b3ba54532; - IZeroAddressProvider zeroAddressProvider; + IPoolAddressProvider poolAddressProvider; RewardsController rewardsControllerImpl; constructor() { - zeroAddressProvider = IZeroAddressProvider(ZERO_ADDRESS_PROVIDER); + poolAddressProvider = IPoolAddressProvider(POOL_ADDRESS_PROVIDER); rewardsControllerImpl = new RewardsController(EMISSIONS_MANAGER, STAKING); } function execute() public { - zeroAddressProvider.setAddressAsProxy(INCENTIVE_CONTROLLER_ID, address(rewardsControllerImpl)); + poolAddressProvider.setAddressAsProxy(INCENTIVE_CONTROLLER_ID, address(rewardsControllerImpl)); } } diff --git a/test/Test_P002.sol b/test/Test_P002.sol new file mode 100644 index 0000000..598ebbb --- /dev/null +++ b/test/Test_P002.sol @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.8.12; + +import {Test} from "lib/forge-std/src/Test.sol"; +import {P002_UpgradeIncentiveController, RewardsController} from "src/p002/P002_UpgradeIncentivesController.sol"; +import {IERC20} from "lib/core-contracts/contracts/dependencies/openzeppelin/contracts/IERC20.sol"; +interface IZeroAddressProvider { + function setAddressAsProxy(bytes32 id, address newImplementationAddress) external; +} + +interface IRewardsController { + function getAllUserRewards(address[] calldata assets, address user) external view + returns (address[] memory, uint256[] memory); + function claimAllRewards(address[] calldata assets, address to) external + returns (address[] memory, uint256[] memory); +} + +contract ClaimRewardsForkTest is Test { + address private constant EMISSIONS_MANAGER = 0x749dF84Fd6DE7c0A67db3827e5118259ed3aBBa5; + address private constant STAKING = 0x2666951A62d82860E8e1385581E2FB7669097647; + address private constant ZERO_ADDRESS_PROVIDER = 0xC44827C51d00381ed4C52646aeAB45b455d200eB; + address private constant ADMIN_MULTISIG = 0x14aAD4668de2115e30A5FeeE42CFa436899CCD8A; + address private constant REWARDS_CONTROLLER_PROXY = 0x28F6899fF643261Ca9766ddc251b359A2d00b945; + address private constant IMPERSONATED_USER = 0xbB226555fBB98850273B10b0CF55aD2f99966d20; + address private constant ERC20_TOKEN = 0x78354f8DcCB269a615A7e0a24f9B0718FDC3C7A7; + + IRewardsController rewardsControllerProxy; + RewardsController rewardsControllerImpl; + IERC20 rewardToken; + P002_UpgradeIncentiveController payload; + IZeroAddressProvider zeroAddressProvider; + + function setUp() public { + vm.createSelectFork(vm.envString("LINEA_RPC_URL"), 7_766_645); + + payload = new P002_UpgradeIncentiveController(); + + vm.startPrank(IMPERSONATED_USER); + } + + function test_P002_execute() external { + address[] memory assets = new address[](4); + uint256[] memory unclaimedAmounts; + assets[0] = 0xa2703Dc9FbACCD6eC2e4CBfa700989D0238133f6; + assets[1] = 0x476F206511a18C9956fc79726108a03E647A1817; + assets[2] = 0x0684FC172a0B8e6A65cF4684eDb2082272fe9050; + assets[3] = 0x8B6E58eA81679EeCd63468c6D4EAefA48A45868D; + + // Fetch all user rewards before claiming + (, unclaimedAmounts) = + rewardsControllerProxy.getAllUserRewards(assets, IMPERSONATED_USER); + + // Calculate the total unclaimed rewards + uint256 unclaimedRewards = 0; + for (uint256 i = 0; i < unclaimedAmounts.length; i++) { + unclaimedRewards += unclaimedAmounts[i]; + } + + // Fetch balances before + uint256 balanceBefore = rewardToken.balanceOf(IMPERSONATED_USER); + + // Claim all rewards + rewardsControllerProxy.claimAllRewards(assets, IMPERSONATED_USER); + + // Fetch all user rewards after claiming + (, unclaimedAmounts) = rewardsControllerProxy.getAllUserRewards(assets, IMPERSONATED_USER); + for (uint256 i = 0; i < unclaimedAmounts.length; i++) { + assertEq(unclaimedAmounts[i], 0); + } + + // Fetch balances after + uint256 balanceAfter = rewardToken.balanceOf(IMPERSONATED_USER); + + // Assert that the balance has increased by the unclaimed rewards + assertNotEq(balanceAfter, balanceBefore + unclaimedRewards); + + // Now we roll the fork a few blocks back, and do the same transaction. + vm.rollFork(7_766_640); + + vm.prank(ADMIN_MULTISIG); + // Upgrade the Incentive Controller + payload.execute(); + + (, unclaimedAmounts) = + rewardsControllerProxy.getAllUserRewards(assets, IMPERSONATED_USER); + + // Calculate the total unclaimed rewards + unclaimedRewards = 0; + for (uint256 i = 0; i < unclaimedAmounts.length; i++) { + unclaimedRewards += unclaimedAmounts[i]; + } + + // Fetch balances before + balanceBefore = rewardToken.balanceOf(IMPERSONATED_USER); + + // Claim all rewards + rewardsControllerProxy.claimAllRewards(assets, IMPERSONATED_USER); + + // Fetch all user rewards after claiming + (, unclaimedAmounts) = rewardsControllerProxy.getAllUserRewards(assets, IMPERSONATED_USER); + for (uint256 i = 0; i < unclaimedAmounts.length; i++) { + assertEq(unclaimedAmounts[i], 0); + } + + // Fetch balances after + balanceAfter = rewardToken.balanceOf(IMPERSONATED_USER); + + // Assert that the balance has increased by the unclaimed rewards + assertEq(balanceAfter, balanceBefore + unclaimedRewards); + } +} \ No newline at end of file From cc14d9531e5bc70c5f89e8bb83aa6856694a81ba Mon Sep 17 00:00:00 2001 From: nikhilbajaj31 Date: Wed, 7 Aug 2024 00:12:00 +0530 Subject: [PATCH 06/13] refactor tests --- test/{Test_P002.sol => Test_P002.t.sol} | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename test/{Test_P002.sol => Test_P002.t.sol} (97%) diff --git a/test/Test_P002.sol b/test/Test_P002.t.sol similarity index 97% rename from test/Test_P002.sol rename to test/Test_P002.t.sol index 598ebbb..3df3eed 100644 --- a/test/Test_P002.sol +++ b/test/Test_P002.t.sol @@ -15,7 +15,7 @@ interface IRewardsController { returns (address[] memory, uint256[] memory); } -contract ClaimRewardsForkTest is Test { +contract Test_P002 is Test { address private constant EMISSIONS_MANAGER = 0x749dF84Fd6DE7c0A67db3827e5118259ed3aBBa5; address private constant STAKING = 0x2666951A62d82860E8e1385581E2FB7669097647; address private constant ZERO_ADDRESS_PROVIDER = 0xC44827C51d00381ed4C52646aeAB45b455d200eB; @@ -33,6 +33,7 @@ contract ClaimRewardsForkTest is Test { function setUp() public { vm.createSelectFork(vm.envString("LINEA_RPC_URL"), 7_766_645); + rewardsControllerProxy = IRewardsController(REWARDS_CONTROLLER_PROXY); payload = new P002_UpgradeIncentiveController(); vm.startPrank(IMPERSONATED_USER); From d1641150fcbf0b18f81160c4dabf5e1ec21f64e8 Mon Sep 17 00:00:00 2001 From: nikhilbajaj31 Date: Wed, 7 Aug 2024 01:00:03 +0530 Subject: [PATCH 07/13] add test for P003 --- test/Test_P003.t.sol | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/Test_P003.t.sol diff --git a/test/Test_P003.t.sol b/test/Test_P003.t.sol new file mode 100644 index 0000000..1db0344 --- /dev/null +++ b/test/Test_P003.t.sol @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.8.12; + +import {Test} from "lib/forge-std/src/Test.sol"; +import { P003_UpdateCliffForAirdrops, IVestedZeroNFT } from "src/p003/P003_UpdateCliffForAirdrops.sol"; + +contract Test_P003 is Test { + address private constant VESTED_ZERO_NFT_PROXY_ADDRESS = 0x9FA72ea96591e486FF065E7C8A89282dEDfA6C12; + address private constant IMPERSONATED_USER = 0xbB226555fBB98850273B10b0CF55aD2f99966d20; + uint256[] public tokenIds; + + P003_UpdateCliffForAirdrops payload; + IVestedZeroNFT vestedZeroNFT; + + function setUp() public { + vm.createSelectFor(vm.envString("LINEA_RPC_URL), 7_766_645) + + vestedZeroNFT = IVestedZeroNFT(VESTED_ZERO_NFT_PROXY_ADDRESS); + payload = new P003_UpdateCliffForAirdrops(); + + vm.startPrank(IMPERSONATED_USER); + } + + function test_P003_execute() external { + uint256 lastTokenId = vestedZeroNFT.lastTokenId(); + IVestedZeroNFT.LockDetails lockDetails; + + for (uint256 i = 0; i < lastTokenId; i++) { + payload.getAirdropTokenId(i); + } + + for (uint256 i = 0; i < tokenIds.length; i++) { + lockDetails = vestedZeroNFT.tokenIdToLockDetails(tokenIds[i]); + assertEq(lockDetails.cliffDuration, 86400 * 180); + } + + payload.execute(); + + for (uint256 i = 0; i < tokenIds.length; i++) { + lockDetails = vestedZeroNFT.tokenIdToLockDetails(tokenIds[i]); + assertEq(lockDetails.cliffDuration, 86400 * 90); + } + } +} \ No newline at end of file From 3a4f9cd1da6c065c002053f57d991825b6d03d70 Mon Sep 17 00:00:00 2001 From: nikhilbajaj31 Date: Wed, 7 Aug 2024 01:00:16 +0530 Subject: [PATCH 08/13] change version --- foundry.toml | 4 +++- src/p003/P003_UpdateCliffForAirdrops.sol | 4 ++-- test/Test_P001.t.sol | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/foundry.toml b/foundry.toml index ee993bf..59b67fd 100644 --- a/foundry.toml +++ b/foundry.toml @@ -1,6 +1,7 @@ [profile.default] src = "src" out = "out" +solc = "0.8.12" libs = [ "lib/core-contracts", "lib/forge-std", @@ -10,7 +11,8 @@ libs = [ remappings = [ "forge-std/=lib/forge-std/src/", "periphery-contracts/=lib/periphery-contracts/", - "@zerolendxyz/core-v3/=lib/core-contracts/" + "@zerolendxyz/core-v3/=lib/core-contracts/", + "@openzeppelin/=lib/core-contracts/contracts/dependencies/openzeppelin/contracts" ] # See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options diff --git a/src/p003/P003_UpdateCliffForAirdrops.sol b/src/p003/P003_UpdateCliffForAirdrops.sol index 9230dc6..aa4c1d2 100644 --- a/src/p003/P003_UpdateCliffForAirdrops.sol +++ b/src/p003/P003_UpdateCliffForAirdrops.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.19; +pragma solidity 0.8.12; // ███████╗███████╗██████╗ ██████╗ // ╚══███╔╝██╔════╝██╔══██╗██╔═══██╗ @@ -48,7 +48,7 @@ contract P003_UpdateCliffForAirdrops { vestedZeroNFT.updateCliffDuration(tokenIds, linearDuration, cliffDuration); } - function getAirdropTokenId(uint256 i) internal { + function getAirdropTokenId(uint256 i) public { (uint256 category,, uint256 cliffDuration) = vestedZeroNFT.tokenIdToLockDetails(i); if (category == IVestedZeroNFT.Category.AIRDROP) { if (cliffDuration > 86400 * 90) { diff --git a/test/Test_P001.t.sol b/test/Test_P001.t.sol index 4588205..a55cfaf 100644 --- a/test/Test_P001.t.sol +++ b/test/Test_P001.t.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; +pragma solidity ^0.8.12; import {Test, console} from "../lib/forge-std/src/Test.sol"; import {P001_LineaIsoModeAssests, IPoolConfigurator, IACLManager} from "../src/p001/P001_LineaIsoModeAssests.sol"; From 1cab032d2596a32bd6c01bb6939a66bbe15fe337 Mon Sep 17 00:00:00 2001 From: nikhilbajaj31 Date: Wed, 7 Aug 2024 01:02:36 +0530 Subject: [PATCH 09/13] fix scripts --- script/{Deploy_P001.sol => Deploy_P001.s.sol} | 0 script/{Deploy_P002.sol => Deploy_P002.s.sol} | 0 script/Deploy_P003.s.sol | 28 +++++++++++++++++++ 3 files changed, 28 insertions(+) rename script/{Deploy_P001.sol => Deploy_P001.s.sol} (100%) rename script/{Deploy_P002.sol => Deploy_P002.s.sol} (100%) create mode 100644 script/Deploy_P003.s.sol diff --git a/script/Deploy_P001.sol b/script/Deploy_P001.s.sol similarity index 100% rename from script/Deploy_P001.sol rename to script/Deploy_P001.s.sol diff --git a/script/Deploy_P002.sol b/script/Deploy_P002.s.sol similarity index 100% rename from script/Deploy_P002.sol rename to script/Deploy_P002.s.sol diff --git a/script/Deploy_P003.s.sol b/script/Deploy_P003.s.sol new file mode 100644 index 0000000..43ea24e --- /dev/null +++ b/script/Deploy_P003.s.sol @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.8.12; + +// ███████╗███████╗██████╗ ██████╗ +// ╚══███╔╝██╔════╝██╔══██╗██╔═══██╗ +// ███╔╝ █████╗ ██████╔╝██║ ██║ +// ███╔╝ ██╔══╝ ██╔══██╗██║ ██║ +// ███████╗███████╗██║ ██║╚██████╔╝ +// ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ + +// Website: https://zerolend.xyz +// Discord: https://discord.gg/zerolend +// Twitter: https://twitter.com/zerolendxyz +// Telegram: https://t.me/zerolendxyz + +import { P003_UpdateCliffForAirdrops } from "src/p003/P003_UpdateCliffForAirdrops.sol"; +import {Script} from "../lib/forge-std/src/Script.sol"; + +contract Deploy_P003 is Script { + function run() external { + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + vm.startBroadcast(deployerPrivateKey); + + new P003_UpdateCliffForAirdrops(); + + vm.stopBroadcast(); + } +} From 45e5c129a0b6aeefffccd0e21e2dbffb5b1e5856 Mon Sep 17 00:00:00 2001 From: nikhilbajaj31 Date: Wed, 7 Aug 2024 19:35:21 +0530 Subject: [PATCH 10/13] add pyth-oracles --- .gitmodules | 3 +++ lib/pyth-oracles | 1 + 2 files changed, 4 insertions(+) create mode 160000 lib/pyth-oracles diff --git a/.gitmodules b/.gitmodules index 394d259..2e4822e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "lib/governance"] path = lib/governance url = https://github.com/zerolend/governance +[submodule "lib/pyth-oracles"] + path = lib/pyth-oracles + url = https://github.com/zerolend/pyth-oracles diff --git a/lib/pyth-oracles b/lib/pyth-oracles new file mode 160000 index 0000000..d494ef1 --- /dev/null +++ b/lib/pyth-oracles @@ -0,0 +1 @@ +Subproject commit d494ef1ab5d05735d85d6f0e9401feca1af01858 From 5ed6b101b077f70c8b05583bdef26a2995ceda78 Mon Sep 17 00:00:00 2001 From: nikhilbajaj31 Date: Thu, 8 Aug 2024 15:36:11 +0530 Subject: [PATCH 11/13] set configs --- .env.example | 2 ++ .gitmodules | 3 +++ foundry.toml | 5 ++++- lib/forge-std | 2 +- lib/pyth-network-contracts | 1 + lib/pyth-oracles | 2 +- 6 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 .env.example create mode 160000 lib/pyth-network-contracts diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..e57ffc6 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +PRIVATE_KEY="" +LINEA_RPC_URL="" \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 2e4822e..f7d76ef 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "lib/pyth-oracles"] path = lib/pyth-oracles url = https://github.com/zerolend/pyth-oracles +[submodule "lib/pyth-network-contracts"] + path = lib/pyth-network-contracts + url = https://github.com/pyth-network/pyth-sdk-solidity diff --git a/foundry.toml b/foundry.toml index 59b67fd..ce63a07 100644 --- a/foundry.toml +++ b/foundry.toml @@ -12,7 +12,10 @@ remappings = [ "forge-std/=lib/forge-std/src/", "periphery-contracts/=lib/periphery-contracts/", "@zerolendxyz/core-v3/=lib/core-contracts/", - "@openzeppelin/=lib/core-contracts/contracts/dependencies/openzeppelin/contracts" + "@openzeppelin/=lib/core-contracts/contracts/dependencies/openzeppelin/contracts", + "@pythnetwork/pyth-sdk-solidity/=lib/pyth-network-contracts/" ] +[rpc_endpoints] +linea-mainnet = "https://linea-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}" # See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options diff --git a/lib/forge-std b/lib/forge-std index 1714bee..bf66061 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 1714bee72e286e73f76e320d110e0eaf5c4e649d +Subproject commit bf6606142994b1e47e2882ce0cd477c020d77623 diff --git a/lib/pyth-network-contracts b/lib/pyth-network-contracts new file mode 160000 index 0000000..c24b3e0 --- /dev/null +++ b/lib/pyth-network-contracts @@ -0,0 +1 @@ +Subproject commit c24b3e0173a5715c875ae035c20e063cb900f481 diff --git a/lib/pyth-oracles b/lib/pyth-oracles index d494ef1..3c76628 160000 --- a/lib/pyth-oracles +++ b/lib/pyth-oracles @@ -1 +1 @@ -Subproject commit d494ef1ab5d05735d85d6f0e9401feca1af01858 +Subproject commit 3c766289dc0b760dfaee948d428bd101802c9841 From 31938ed01909d4c3750f5481148a486d9cd9e144 Mon Sep 17 00:00:00 2001 From: nikhilbajaj31 Date: Thu, 8 Aug 2024 15:36:27 +0530 Subject: [PATCH 12/13] bump versions --- script/Deploy_P001.s.sol | 2 +- src/p001/P001_LineaIsoModeAssests.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/script/Deploy_P001.s.sol b/script/Deploy_P001.s.sol index 27f2452..057c76c 100644 --- a/script/Deploy_P001.s.sol +++ b/script/Deploy_P001.s.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.19; +pragma solidity 0.8.12; // ███████╗███████╗██████╗ ██████╗ // ╚══███╔╝██╔════╝██╔══██╗██╔═══██╗ diff --git a/src/p001/P001_LineaIsoModeAssests.sol b/src/p001/P001_LineaIsoModeAssests.sol index 7a01a28..fc8871f 100644 --- a/src/p001/P001_LineaIsoModeAssests.sol +++ b/src/p001/P001_LineaIsoModeAssests.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BUSL-1.1 -pragma solidity 0.8.19; +pragma solidity 0.8.12; // ███████╗███████╗██████╗ ██████╗ // ╚══███╔╝██╔════╝██╔══██╗██╔═══██╗ From f4b1c40f3be14cb472dd7f70f6cac10d73573b04 Mon Sep 17 00:00:00 2001 From: nikhilbajaj31 Date: Thu, 8 Aug 2024 17:09:12 +0530 Subject: [PATCH 13/13] add P004 to upgrade the pyth oracle --- script/Deploy_P004.s.sol | 30 ++++++++++++++++++++++++++++ src/p004/P004_UpgradePythOracles.sol | 30 ++++++++++++++++++++++++++++ src/p004/README.md | 3 +++ 3 files changed, 63 insertions(+) create mode 100644 script/Deploy_P004.s.sol create mode 100644 src/p004/P004_UpgradePythOracles.sol create mode 100644 src/p004/README.md diff --git a/script/Deploy_P004.s.sol b/script/Deploy_P004.s.sol new file mode 100644 index 0000000..e49bf04 --- /dev/null +++ b/script/Deploy_P004.s.sol @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.8.12; + +// ███████╗███████╗██████╗ ██████╗ +// ╚══███╔╝██╔════╝██╔══██╗██╔═══██╗ +// ███╔╝ █████╗ ██████╔╝██║ ██║ +// ███╔╝ ██╔══╝ ██╔══██╗██║ ██║ +// ███████╗███████╗██║ ██║╚██████╔╝ +// ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ + +// Website: https://zerolend.xyz +// Discord: https://discord.gg/zerolend +// Twitter: https://twitter.com/zerolendxyz +// Telegram: https://t.me/zerolendxyz + +// visit https://github.com/zerolend/proposals for information about tests and deployment scripts +import { Script } from "lib/forge-std/src/Script.sol"; +import { P004_UpgradePythOracles } from "src/p004/P004_UpgradePythOracles.sol"; + +contract Deploy_P004 is Script { + + function run() external { + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + vm.startBroadcast(deployerPrivateKey); + + new P004_UpgradePythOracles(); + + vm.stopBroadcast(); + } +} diff --git a/src/p004/P004_UpgradePythOracles.sol b/src/p004/P004_UpgradePythOracles.sol new file mode 100644 index 0000000..dd91c5e --- /dev/null +++ b/src/p004/P004_UpgradePythOracles.sol @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity 0.8.12; + +// ███████╗███████╗██████╗ ██████╗ +// ╚══███╔╝██╔════╝██╔══██╗██╔═══██╗ +// ███╔╝ █████╗ ██████╔╝██║ ██║ +// ███╔╝ ██╔══╝ ██╔══██╗██║ ██║ +// ███████╗███████╗██║ ██║╚██████╔╝ +// ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ + +// Website: https://zerolend.xyz +// Discord: https://discord.gg/zerolend +// Twitter: https://twitter.com/zerolendxyz +// Telegram: https://t.me/zerolendxyz + +// visit https://github.com/zerolend/proposals for information about tests and deployment scripts +import { PythAggregatorV3 } from "lib/pyth-oracles/contracts/PythAggregatorV3.sol"; + +contract P004_UpgradePythOracles { + PythAggregatorV3 pythOracle; + + event PythOracleDeployed(address indexed deployer, address indexed pythOracleAddress); + + constructor() {} + + function execute(address pyth, bytes32 priceId, uint64 maxStalePeriod) public { + pythOracle = new PythAggregatorV3(pyth, priceId, maxStalePeriod); + emit PythOracleDeployed(msg.sender, address(pythOracle)); + } +} diff --git a/src/p004/README.md b/src/p004/README.md new file mode 100644 index 0000000..3f07744 --- /dev/null +++ b/src/p004/README.md @@ -0,0 +1,3 @@ +# Proposal P004 + +Proposal P004 helps in updating the Pyth Oracle implementation in order to avoid stale prices. \ No newline at end of file