Skip to content

Commit

Permalink
adds set claimer functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
WalidOfNow committed Jul 17, 2024
1 parent e5c7227 commit 0b41927
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 24 deletions.
3 changes: 0 additions & 3 deletions mainnet-contracts/script/UpgradePufETH.s.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0;

import "forge-std/Script.sol";
import { stdJson } from "forge-std/StdJson.sol";
import { BaseScript } from ".//BaseScript.s.sol";
import { PufferVault } from "../src/PufferVault.sol";
Expand Down Expand Up @@ -70,8 +69,6 @@ contract UpgradePufETH is BaseScript {
l2RewardManager: address(0)
});

console.log("LOCKBOX", bridgingDeployment.xPufETHLockBox);

PufferVaultV3 newImplementation = new PufferVaultV3Tests(
IStETH(deployment.stETH),
IWETH(deployment.weth),
Expand Down
34 changes: 32 additions & 2 deletions mainnet-contracts/src/PufferVaultV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ contract PufferVaultV3 is PufferVaultV2, IPufferVaultV3 {
* @notice Mints and bridges rewards according to the provided parameters.
* @param params The parameters for bridging rewards.
*/
function mintAndBridgeRewards(BridgingParams calldata params) external payable restricted {
function mintAndBridgeRewards(MintAndBridgeParams calldata params) external payable restricted {
VaultStorage storage $ = _getPufferVaultStorage();

if (params.rewardsAmount > $.allowedRewardMintAmount) {
Expand All @@ -137,8 +137,11 @@ contract PufferVaultV3 is PufferVaultV2, IPufferVaultV3 {
// This contract approves transfer to Connext
XTOKEN.approve(address(_CONNEXT), params.rewardsAmount);

BridgingParams memory bridgingParams =
BridgingParams({ bridgingType: BridgingType.MintAndBridge, data: abi.encode(params) });

// Encode calldata for the target contract call
bytes memory callData = abi.encode(params);
bytes memory callData = abi.encode(bridgingParams);

_CONNEXT.xcall{ value: msg.value }(
_DESTINATION_DOMAIN, // _destination: Domain ID of the destination chain
Expand All @@ -155,6 +158,33 @@ contract PufferVaultV3 is PufferVaultV2, IPufferVaultV3 {
);
}

/**
* @notice Sets the L2 reward claimer.
* @param claimer The address of the new claimer.
* @dev Restricted in this context is like `whenNotPaused` modifier from Pausable.sol
*/
function setL2RewardClaimer(address claimer) external payable restricted {
SetClaimerParams memory params = SetClaimerParams({ account: msg.sender, claimer: claimer });

BridgingParams memory bridgingParams =
BridgingParams({ bridgingType: BridgingType.SetClaimer, data: abi.encode(params) });

// Encode calldata for the target contract call
bytes memory callData = abi.encode(bridgingParams);

_CONNEXT.xcall{ value: msg.value }(
_DESTINATION_DOMAIN, // _destination: Domain ID of the destination chain
L2_REWARD_MANAGER, // _to: address of the target contract
address(0), // _asset: address of the token contract
msg.sender, // _delegate: address that can revert or forceLocal on destination
0, // _amount: amount of tokens to transfer
_SLIPPAGE, // _slippage: max slippage the user will accept in BPS (e.g. 300 = 3%)
callData // _callData: the encoded calldata to send
);

emit L2RewardClaimerUpdated(msg.sender, claimer);
}

/**
* @notice Sets the allowed reward mint amount.
* @param newAmount The new allowed reward mint amount.
Expand Down
47 changes: 42 additions & 5 deletions mainnet-contracts/src/interface/IPufferVaultV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,44 @@ import { IPufferVaultV2 } from "./IPufferVaultV2.sol";

/**
* @title IPufferVaultV3
* @author Puffer Finance
* @custom:security-contact security@puffer.fi
* @notice Interface for the PufferVault version 3 contract.
* @custom:security-contact security@puffer.fi
*/
interface IPufferVaultV3 is IPufferVaultV2 {
enum BridgingType {
MintAndBridge,
SetClaimer
}

/**
* @notice Parameters for bridging actions.
* @param bridgingType The type of bridging action.
* @param data The data associated with the bridging action.
*/
struct BridgingParams {
BridgingType bridgingType;
bytes data;
}

/**
* @notice Parameters for setting a claimer.
* @param account The account setting the claimer.
* @param claimer The address of the new claimer.
*/
struct SetClaimerParams {
address account;
address claimer;
}

/**
* @notice Parameters for bridging rewards.
* @notice Parameters for minting and bridging rewards.
* @param rewardsAmount The amount of rewards to be bridged.
* @param startEpoch The starting epoch for the rewards.
* @param endEpoch The ending epoch for the rewards.
* @param rewardsRoot The merkle root of the rewards.
* @param rewardsURI The URI for the rewards metadata.
*/
struct BridgingParams {
struct MintAndBridgeParams {
uint88 rewardsAmount;
uint64 startEpoch;
uint64 endEpoch;
Expand Down Expand Up @@ -78,9 +102,22 @@ interface IPufferVaultV3 is IPufferVaultV2 {
*/
event AllowedRewardMintFrequencyUpdated(uint24 oldFrequency, uint24 newFrequency);

/**
* @notice Event emitted when the L2 reward claimer is updated.
* @param account The account setting the claimer.
* @param claimer The address of the new claimer.
*/
event L2RewardClaimerUpdated(address account, address claimer);

/**
* @notice Mints and bridges rewards according to the provided parameters.
* @param params The parameters for bridging rewards.
*/
function mintAndBridgeRewards(BridgingParams calldata params) external payable;
function mintAndBridgeRewards(MintAndBridgeParams calldata params) external payable;

/**
* @notice Sets the L2 reward claimer.
* @param claimer The address of the new claimer.
*/
function setL2RewardClaimer(address claimer) external payable;
}
2 changes: 0 additions & 2 deletions mainnet-contracts/test/helpers/UnitTestHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import {
ROLE_ID_LOCKBOX
} from "../../script/Roles.sol";

import "forge-std/console.sol";

contract UnitTestHelper is Test, BaseScript {
bytes32 private constant _PERMIT_TYPEHASH =
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
Expand Down
35 changes: 23 additions & 12 deletions mainnet-contracts/test/unit/PufferVaultV3.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { UnitTestHelper } from "../helpers/UnitTestHelper.sol";
import { xPufETH } from "src/l2/xPufETH.sol";
import { IPufferVaultV3 } from "../../src/interface/IPufferVaultV3.sol";
import { IAccessManaged } from "@openzeppelin/contracts/access/manager/IAccessManaged.sol";
import { ROLE_ID_DAO, ROLE_ID_LOCKBOX } from "../../script/Roles.sol";
import { ROLE_ID_DAO, PUBLIC_ROLE } from "../../script/Roles.sol";

contract PufferVaultV3Test is UnitTestHelper {
function setUp() public override {
Expand All @@ -19,12 +19,15 @@ contract PufferVaultV3Test is UnitTestHelper {
xpufETHDAOselectors[0] = xPufETH.setLimits.selector;
xpufETHDAOselectors[1] = xPufETH.setLockbox.selector;

bytes4[] memory pufferVaultSelectors = new bytes4[](1);
pufferVaultSelectors[0] = IPufferVaultV3.setL2RewardClaimer.selector;

vm.startPrank(_broadcaster);
accessManager.setTargetFunctionRole(address(xpufETH), xpufETHDAOselectors, ROLE_ID_DAO);
accessManager.setTargetFunctionRole(address(xpufETH), xpufETHselectors, ROLE_ID_LOCKBOX);
accessManager.setTargetFunctionRole(address(xpufETH), xpufETHselectors, PUBLIC_ROLE);
accessManager.setTargetFunctionRole(address(pufferVault), pufferVaultSelectors, PUBLIC_ROLE);

accessManager.grantRole(ROLE_ID_DAO, DAO, 0);
accessManager.grantRole(ROLE_ID_LOCKBOX, address(lockBox), 0);

vm.stopPrank();

Expand All @@ -40,8 +43,8 @@ contract PufferVaultV3Test is UnitTestHelper {
vm.warp(365 days);
}

function testMintAndBridgeRewardsSuccess() public {
IPufferVaultV3.BridgingParams memory params = IPufferVaultV3.BridgingParams({
function test_MintAndBridgeRewardsSuccess() public {
IPufferVaultV3.MintAndBridgeParams memory params = IPufferVaultV3.MintAndBridgeParams({
rewardsAmount: 100 ether,
startEpoch: 1,
endEpoch: 2,
Expand All @@ -60,8 +63,8 @@ contract PufferVaultV3Test is UnitTestHelper {
vm.stopPrank();
}

function testMintAndBridgeRewardsInvalidMintAmount() public {
IPufferVaultV3.BridgingParams memory params = IPufferVaultV3.BridgingParams({
function testRevert_MintAndBridgeRewardsInvalidMintAmount() public {
IPufferVaultV3.MintAndBridgeParams memory params = IPufferVaultV3.MintAndBridgeParams({
rewardsAmount: 200 ether, // assuming this is more than allowed
startEpoch: 1,
endEpoch: 2,
Expand All @@ -76,8 +79,8 @@ contract PufferVaultV3Test is UnitTestHelper {
vm.stopPrank();
}

function testMintAndBridgeRewardsNotAllowedMintFrequency() public {
IPufferVaultV3.BridgingParams memory params = IPufferVaultV3.BridgingParams({
function test_MintAndBridgeRewardsNotAllowedMintFrequency() public {
IPufferVaultV3.MintAndBridgeParams memory params = IPufferVaultV3.MintAndBridgeParams({
rewardsAmount: 1 ether,
startEpoch: 1,
endEpoch: 2,
Expand All @@ -95,7 +98,7 @@ contract PufferVaultV3Test is UnitTestHelper {
vm.stopPrank();
}

function testSetAllowedRewardMintAmountSuccess() public {
function test_SetAllowedRewardMintAmountSuccess() public {
uint88 newAmount = 200 ether;
vm.startPrank(DAO);

Expand All @@ -106,7 +109,7 @@ contract PufferVaultV3Test is UnitTestHelper {
vm.stopPrank();
}

function testSetAllowedRewardMintAmountRevert() public {
function testRevert_SetAllowedRewardMintAmount() public {
uint88 newAmount = 200 ether;
vm.expectRevert(abi.encodeWithSelector(IAccessManaged.AccessManagedUnauthorized.selector, address(this)));
pufferVault.setAllowedRewardMintAmount(newAmount);
Expand All @@ -124,10 +127,18 @@ contract PufferVaultV3Test is UnitTestHelper {
vm.stopPrank();
}

function testSetAllowedRewardMintFrequencyRevert() public {
function testRevert_SetAllowedRewardMintFrequency() public {
uint24 newFrequency = 86400; // 24 hours

vm.expectRevert(abi.encodeWithSelector(IAccessManaged.AccessManagedUnauthorized.selector, address(this)));
pufferVault.setAllowedRewardMintFrequency(newFrequency);
}

function testSetClaimerRevert() public {
address newClaimer = address(0x123);

vm.expectEmit(true, true, true, true);
emit IPufferVaultV3.L2RewardClaimerUpdated(address(this), newClaimer);
pufferVault.setL2RewardClaimer(newClaimer);
}
}

0 comments on commit 0b41927

Please sign in to comment.