Skip to content

Commit

Permalink
fix: tests and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
adu-web3 committed Oct 9, 2024
1 parent 403a143 commit 6331d4c
Show file tree
Hide file tree
Showing 27 changed files with 194 additions and 77 deletions.
6 changes: 4 additions & 2 deletions script/12_RedeployClientChainGateway.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {Bootstrap} from "../src/core/Bootstrap.sol";
import {ClientChainGateway} from "../src/core/ClientChainGateway.sol";

import "../src/core/ExoCapsule.sol";
import {Vault} from "../src/core/Vault.sol";

import {RewardVault} from "../src/core/RewardVault.sol";
import {Vault} from "../src/core/Vault.sol";
import "../src/utils/BeaconProxyBytecode.sol";
import {CustomProxyAdmin} from "../src/utils/CustomProxyAdmin.sol";
import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
Expand Down Expand Up @@ -36,7 +37,8 @@ contract RedeployClientChainGateway is BaseScript {
require(address(beaconOracle) != address(0), "beacon oracle should not be empty");
vaultBeacon = UpgradeableBeacon(stdJson.readAddress(prerequisiteContracts, ".clientChain.vaultBeacon"));
require(address(vaultBeacon) != address(0), "vault beacon should not be empty");
rewardVaultBeacon = UpgradeableBeacon(stdJson.readAddress(prerequisiteContracts, ".clientChain.rewardVaultBeacon"));
rewardVaultBeacon =
UpgradeableBeacon(stdJson.readAddress(prerequisiteContracts, ".clientChain.rewardVaultBeacon"));
require(address(rewardVaultBeacon) != address(0), "reward vault beacon should not be empty");
capsuleBeacon = UpgradeableBeacon(stdJson.readAddress(prerequisiteContracts, ".clientChain.capsuleBeacon"));
require(address(capsuleBeacon) != address(0), "capsule beacon should not be empty");
Expand Down
3 changes: 2 additions & 1 deletion script/1_Prerequisities.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {ERC20PresetFixedSupply} from "@openzeppelin/contracts/token/ERC20/preset
import "forge-std/Script.sol";

import "test/mocks/AssetsMock.sol";
import "test/mocks/RewardMock.sol";

import "test/mocks/DelegationMock.sol";
import {NonShortCircuitEndpointV2Mock} from "test/mocks/NonShortCircuitEndpointV2Mock.sol";
import "test/mocks/RewardMock.sol";

contract PrerequisitiesScript is BaseScript {

Expand Down
3 changes: 2 additions & 1 deletion script/2_DeployBoth.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ pragma solidity ^0.8.19;
import "../src/core/ClientChainGateway.sol";
import "../src/core/ExoCapsule.sol";
import "../src/core/ExocoreGateway.sol";
import {Vault} from "../src/core/Vault.sol";

import {RewardVault} from "../src/core/RewardVault.sol";
import {Vault} from "../src/core/Vault.sol";
import "../src/utils/BeaconProxyBytecode.sol";
import "../src/utils/CustomProxyAdmin.sol";
import {ExocoreGatewayMock} from "../test/mocks/ExocoreGatewayMock.sol";
Expand Down
3 changes: 2 additions & 1 deletion script/7_DeployBootstrap.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {Bootstrap} from "../src/core/Bootstrap.sol";
import {ClientChainGateway} from "../src/core/ClientChainGateway.sol";

import "../src/core/ExoCapsule.sol";
import {Vault} from "../src/core/Vault.sol";

import {RewardVault} from "../src/core/RewardVault.sol";
import {Vault} from "../src/core/Vault.sol";
import "../src/utils/BeaconProxyBytecode.sol";
import {CustomProxyAdmin} from "../src/utils/CustomProxyAdmin.sol";

Expand Down
9 changes: 6 additions & 3 deletions script/BaseScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ pragma solidity ^0.8.19;
import "../src/interfaces/IClientChainGateway.sol";
import "../src/interfaces/IExoCapsule.sol";
import "../src/interfaces/IExocoreGateway.sol";
import "../src/interfaces/IVault.sol";

import "../src/interfaces/IRewardVault.sol";
import "../src/interfaces/IVault.sol";
import "../src/utils/BeaconProxyBytecode.sol";
import "../src/utils/CustomProxyAdmin.sol";

import "../src/interfaces/precompiles/IAssets.sol";
import "../src/interfaces/precompiles/IReward.sol";

import "../src/interfaces/precompiles/IDelegation.sol";
import "../src/interfaces/precompiles/IReward.sol";

import "@beacon-oracle/contracts/src/EigenLayerBeaconOracle.sol";
import "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol";
Expand All @@ -20,8 +22,9 @@ import "forge-std/Script.sol";
import {StdCheats} from "forge-std/StdCheats.sol";

import "../test/mocks/AssetsMock.sol";
import "../test/mocks/RewardMock.sol";

import "../test/mocks/DelegationMock.sol";
import "../test/mocks/RewardMock.sol";

contract BaseScript is Script, StdCheats {

Expand Down
3 changes: 2 additions & 1 deletion script/TestPrecompileErrorFixed.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import "../src/interfaces/IExocoreGateway.sol";
import "../src/interfaces/IVault.sol";

import "../src/interfaces/precompiles/IAssets.sol";
import "../src/interfaces/precompiles/IReward.sol";

import "../src/interfaces/precompiles/IDelegation.sol";
import "../src/interfaces/precompiles/IReward.sol";
import {Action, GatewayStorage} from "../src/storage/GatewayStorage.sol";

import {NonShortCircuitEndpointV2Mock} from "../test/mocks/NonShortCircuitEndpointV2Mock.sol";
Expand Down
16 changes: 10 additions & 6 deletions src/core/BaseRestakingController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,23 @@ abstract contract BaseRestakingController is
_processRequest(Action.REQUEST_UNDELEGATE_FROM, actionArgs, bytes(""));
}

function submitReward(address token, address avs, uint256 amount)
external
function submitReward(address token, address avs, uint256 amount)
external
payable
isValidAmount(amount)
whenNotPaused
nonReentrant
{
// deposit reward to reward vault
rewardVault.deposit(token, msg.sender, avs, amount);
// send request to exocore, and this would not expect a response since deposit is supposed to be must success by
// protocol
bytes memory actionArgs = abi.encodePacked(bytes32(bytes20(token)), bytes32(bytes20(avs)), amount);
_processRequest(Action.REQUEST_SUBMIT_REWARD, actionArgs, bytes(""));
}

function claimRewardFromExocore(address token, uint256 amount)
external
function claimRewardFromExocore(address token, uint256 amount)
external
payable
isValidAmount(amount)
whenNotPaused
Expand All @@ -105,8 +109,8 @@ abstract contract BaseRestakingController is
_processRequest(Action.REQUEST_CLAIM_REWARD, actionArgs, encodedRequest);
}

function withdrawReward(address token, address recipient, uint256 amount)
external
function withdrawReward(address token, address recipient, uint256 amount)
external
isValidAmount(amount)
whenNotPaused
nonReentrant
Expand Down
16 changes: 14 additions & 2 deletions src/core/Bootstrap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,13 @@ contract Bootstrap is

/// @inheritdoc IBaseRestakingController
/// @dev This is not yet supported.
function submitReward(address token, address avs, uint256 rewardAmount) external payable override beforeLocked whenNotPaused {
function submitReward(address, address, uint256)
external
payable
override
beforeLocked
whenNotPaused
{
revert Errors.NotYetSupported();
}

Expand All @@ -447,7 +453,13 @@ contract Bootstrap is

/// @inheritdoc IBaseRestakingController
/// @dev This is not yet supported.
function withdrawReward(address token, address recipient, uint256 rewardAmount) external view override beforeLocked whenNotPaused {
function withdrawReward(address, address, uint256)
external
view
override
beforeLocked
whenNotPaused
{
revert Errors.NotYetSupported();
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/ClientChainGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
pragma solidity ^0.8.19;

import {IClientChainGateway} from "../interfaces/IClientChainGateway.sol";

import {IRewardVault} from "../interfaces/IRewardVault.sol";
import {ITokenWhitelister} from "../interfaces/ITokenWhitelister.sol";
import {IVault} from "../interfaces/IVault.sol";
import {IRewardVault} from "../interfaces/IRewardVault.sol";
import {OAppCoreUpgradeable} from "../lzApp/OAppCoreUpgradeable.sol";
import {OAppReceiverUpgradeable} from "../lzApp/OAppReceiverUpgradeable.sol";
import {MessagingFee, OAppSenderUpgradeable} from "../lzApp/OAppSenderUpgradeable.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/core/ExoCapsule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract ExoCapsule is ReentrancyGuardUpgradeable, ExoCapsuleStorage, IExoCapsul
using ValidatorContainer for bytes32[];
using WithdrawalContainer for bytes32[];

/// @notice Emitted when the ETH principal balance is unlocked.
/// @notice Emitted when the ETH principal balance is unlocked.
/// @param owner The address of the capsule owner.
/// @param unlockedAmount The amount added to the withdrawable balance.
event ETHPrincipalUnlocked(address owner, uint256 unlockedAmount);
Expand Down
5 changes: 3 additions & 2 deletions src/core/ExocoreGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {IExocoreGateway} from "../interfaces/IExocoreGateway.sol";
import {Action} from "../storage/GatewayStorage.sol";

import {ASSETS_CONTRACT} from "../interfaces/precompiles/IAssets.sol";
import {REWARD_CONTRACT} from "../interfaces/precompiles/IReward.sol";

import {DELEGATION_CONTRACT} from "../interfaces/precompiles/IDelegation.sol";
import {REWARD_CONTRACT} from "../interfaces/precompiles/IReward.sol";

import {
MessagingFee,
Expand Down Expand Up @@ -413,7 +414,7 @@ contract ExocoreGateway is
} else {
(success,) = REWARD_CONTRACT.claimReward(srcChainId, token, avsOrWithdrawer, amount);
}
emit RewardOperation(success, isSubmitReward, bytes32(token), bytes32(avsOrWithdrawer), amount);
emit RewardOperation(isSubmitReward, success, bytes32(token), bytes32(avsOrWithdrawer), amount);

response = isSubmitReward ? bytes("") : abi.encodePacked(lzNonce, success);
}
Expand Down
13 changes: 6 additions & 7 deletions src/core/RewardVault.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {IRewardVault} from "../interfaces/IRewardVault.sol";
import {Errors} from "../libraries/Errors.sol";
import {RewardVaultStorage} from "../storage/RewardVaultStorage.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IRewardVault} from "../interfaces/IRewardVault.sol";

contract RewardVault is RewardVaultStorage, Initializable, IRewardVault {

Expand All @@ -27,8 +27,9 @@ contract RewardVault is RewardVaultStorage, Initializable, IRewardVault {
gateway = gateway_;
}

function deposit(address token, address avs, uint256 amount) external onlyGateway {
IERC20(token).safeTransferFrom(msg.sender, address(this), amount);
// slither-disable-next-line arbitrary-send-erc20
function deposit(address token, address depositor, address avs, uint256 amount) external onlyGateway {
IERC20(token).safeTransferFrom(depositor, address(this), amount);
totalDepositedRewards[token][avs] += amount;

emit RewardDeposited(token, avs, amount);
Expand All @@ -44,10 +45,7 @@ contract RewardVault is RewardVaultStorage, Initializable, IRewardVault {
emit RewardWithdrawn(token, withdrawer, recipient, amount);
}

function unlockReward(address token, address withdrawer, uint256 amount)
external
onlyGateway
{
function unlockReward(address token, address withdrawer, uint256 amount) external onlyGateway {
withdrawableBalances[token][withdrawer] += amount;

emit RewardUnlocked(token, withdrawer, amount);
Expand All @@ -60,4 +58,5 @@ contract RewardVault is RewardVaultStorage, Initializable, IRewardVault {
function getTotalDepositedRewards(address token, address avs) external view returns (uint256) {
return totalDepositedRewards[token][avs];
}

}
5 changes: 1 addition & 4 deletions src/core/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ contract Vault is Initializable, VaultStorage, IVault {
}

/// @inheritdoc IVault
function unlockPrincipal(address user, uint256 amount)
external
onlyGateway
{
function unlockPrincipal(address user, uint256 amount) external onlyGateway {
uint256 totalDeposited = totalDepositedPrincipalAmount[user];
if (amount > totalDeposited) {
revert Errors.VaultPrincipalExceedsTotalDeposit();
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/IBaseRestakingController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface IBaseRestakingController {

/// @notice Submits reward to the reward module on behalf of the AVS
/// @param token The address of the specific token that the user wants to submit as a reward.
/// @param rewardAmount The amount of reward tokens that the user wants to submit.
/// @param rewardAmount The amount of reward tokens that the user wants to submit.
function submitReward(address token, address avs, uint256 rewardAmount) external payable;

/// @notice Claims reward tokens from Exocore.
Expand All @@ -39,7 +39,7 @@ interface IBaseRestakingController {
/// @notice Withdraws reward tokens from vault to the recipient.
/// @param token The address of the specific token that the user wants to withdraw as a reward.
/// @param recipient The address of the recipient of the reward tokens.
/// @param rewardAmount The amount of reward tokens that the user wants to withdraw.
/// @param rewardAmount The amount of reward tokens that the user wants to withdraw.
function withdrawReward(address token, address recipient, uint256 rewardAmount) external;

}
5 changes: 3 additions & 2 deletions src/interfaces/IRewardVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface IRewardVault {
* @param avs The avs ID to which the token is deposited.
* @param amount The amount of the token to be deposited.
*/
function deposit(address token, address avs, uint256 amount) external;
function deposit(address token, address depositor, address avs, uint256 amount) external;

/**
* @notice Withdraws a token from the reward vault.
Expand Down Expand Up @@ -49,4 +49,5 @@ interface IRewardVault {
* @return The total deposited rewards of the token for the avs.
*/
function getTotalDepositedRewards(address token, address avs) external view returns (uint256);
}

}
9 changes: 3 additions & 6 deletions src/interfaces/precompiles/IReward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ interface IReward {
/// @param assetsAddress The client chain asset Address
/// @param avsId The contract address of the AVS
/// @param amount The reward amount
function submitReward(
uint32 clientChainLzId,
bytes calldata assetsAddress,
bytes calldata avsId,
uint256 amount
) external returns (bool success, uint256 latestAssetState);
function submitReward(uint32 clientChainLzId, bytes calldata assetsAddress, bytes calldata avsId, uint256 amount)
external
returns (bool success, uint256 latestAssetState);

/// TRANSACTIONS
/// @dev ClaimReward To the staker, that will change the state in reward module
Expand Down
3 changes: 2 additions & 1 deletion src/libraries/ActionAttributes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ library ActionAttributes {
} else if (action == Action.REQUEST_CLAIM_REWARD) {
attributes = REWARD | WITHDRAWAL;
messageLength = ASSET_OPERATION_LENGTH;
} else if (action == Action.REQUEST_SUBMIT_REWARD) { // New action
} else if (action == Action.REQUEST_SUBMIT_REWARD) {
// New action
attributes = REWARD;
messageLength = ASSET_OPERATION_LENGTH;
} else if (action == Action.REQUEST_DELEGATE_TO || action == Action.REQUEST_UNDELEGATE_FROM) {
Expand Down
4 changes: 1 addition & 3 deletions src/storage/RewardVaultStorage.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract RewardVaultStorage {

// Address of the gateway contract
Expand All @@ -21,4 +18,5 @@ contract RewardVaultStorage {
event RewardDeposited(address indexed token, address indexed avs, uint256 amount);
event RewardUnlocked(address indexed token, address indexed staker, uint256 amount);
event RewardWithdrawn(address indexed token, address indexed staker, address indexed recipient, uint256 amount);

}
2 changes: 1 addition & 1 deletion src/storage/VaultStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ contract VaultStorage {

/// @notice Emitted when a user's principal balance is deposited.
/// @param depositor The address of the depositor.
/// @param amount The amount of the principal balance deposited.
/// @param amount The amount of the principal balance deposited.
event PrincipalDeposited(address depositor, uint256 amount);

/// @notice Emitted when a user's principal balance is unlocked for withdrawal.
Expand Down
11 changes: 7 additions & 4 deletions test/foundry/ExocoreDeployer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@ import "../../src/core/ClientChainGateway.sol";

import "../../src/core/ExoCapsule.sol";
import "../../src/core/ExocoreGateway.sol";
import {Vault} from "../../src/core/Vault.sol";

import {RewardVault} from "../../src/core/RewardVault.sol";
import {Vault} from "../../src/core/Vault.sol";
import {Action, GatewayStorage} from "../../src/storage/GatewayStorage.sol";

import {IVault} from "../../src/interfaces/IVault.sol";
import {IRewardVault} from "../../src/interfaces/IRewardVault.sol";
import {IVault} from "../../src/interfaces/IVault.sol";

import "../../src/interfaces/precompiles/IAssets.sol";
import "../../src/interfaces/precompiles/IReward.sol";

import "../../src/interfaces/precompiles/IDelegation.sol";
import "../../src/interfaces/precompiles/IReward.sol";

import "../mocks/AssetsMock.sol";
import "../mocks/RewardMock.sol";

import "../mocks/DelegationMock.sol";
import {NonShortCircuitEndpointV2Mock} from "../mocks/NonShortCircuitEndpointV2Mock.sol";
import "../mocks/RewardMock.sol";

import "src/core/ExoCapsule.sol";
import "src/utils/BeaconProxyBytecode.sol";
Expand Down
3 changes: 2 additions & 1 deletion test/foundry/Governance.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import "src/core/ClientChainGateway.sol";
import "src/storage/ClientChainGatewayStorage.sol";

import "src/core/ExoCapsule.sol";
import {Vault} from "src/core/Vault.sol";

import {RewardVault} from "src/core/RewardVault.sol";
import {Vault} from "src/core/Vault.sol";
import {IRewardVault} from "src/interfaces/IRewardVault.sol";

import {NonShortCircuitEndpointV2Mock} from "../mocks/NonShortCircuitEndpointV2Mock.sol";
Expand Down
Loading

0 comments on commit 6331d4c

Please sign in to comment.