Skip to content

Commit

Permalink
chore: v1
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoujia6139 committed Dec 29, 2023
1 parent 11a94c1 commit f9b85ee
Show file tree
Hide file tree
Showing 16 changed files with 574 additions and 121 deletions.
13 changes: 13 additions & 0 deletions contracts/cross-chain/L1/IParaxL1MessageHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,17 @@ pragma solidity ^0.8.0;

interface IParaxL1MessageHandler {
function migration(address asset) external;

function updateTokenDelegation(
address delegateTo,
address underlyingAsset,
uint256[] calldata tokenIds,
bool value
) external;

function updateApeStakingBeneficiary(
address nft,
uint32[] calldata tokenIds,
address newBenificiary
) external;
}
6 changes: 4 additions & 2 deletions contracts/cross-chain/L1/IVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
pragma solidity ^0.8.0;

import "./IVaultApeStaking.sol";
import "./IVaultTemplate.sol";
import "./IVaultEarlyAccess.sol";
import "./IVaultCommon.sol";
import "./IVaultParaX.sol";
import "../../interfaces/IParaProxyInterfaces.sol";

interface IVault is
IVaultApeStaking,
IVaultTemplate,
IVaultEarlyAccess,
IVaultCommon,
IVaultParaX,
IParaProxyInterfaces
{}
10 changes: 0 additions & 10 deletions contracts/cross-chain/L1/IVaultApeStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,6 @@ interface IVaultApeStaking {
address newBenificiary
) external;

/**
* @notice Pauses the contract. Only pool admin or emergency admin can call this function
**/
function pause() external;

/**
* @notice Unpause the contract. Only pool admin can call this function
**/
function unpause() external;

/**
* @notice initialization operation for the vault
**/
Expand Down
13 changes: 13 additions & 0 deletions contracts/cross-chain/L1/IVaultCommon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
pragma solidity ^0.8.0;

interface IVaultCommon {
/**
* @notice Pauses the contract. Only pool admin or emergency admin can call this function
**/
function pause() external;

/**
* @notice Unpause the contract. Only pool admin can call this function
**/
function unpause() external;

/**
* @dev Receives and executes a batch of function calls on this contract.
*/
function multicall(
bytes[] calldata data
) external returns (bytes[] memory results);
Expand Down
10 changes: 10 additions & 0 deletions contracts/cross-chain/L1/IVaultEarlyAccess.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IVaultEarlyAccess {
function depositERC721(address nft, uint32[] calldata tokenIds) external;

// function offboardNFTs(address nft, uint32[] calldata tokenIds) external;
//
// function offboardNFT(address nft, uint32 tokenId) external;
}
12 changes: 0 additions & 12 deletions contracts/cross-chain/L1/IVaultTemplate.sol

This file was deleted.

35 changes: 21 additions & 14 deletions contracts/cross-chain/L1/ParaxL1MessageHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma abicoder v2;

import {MessageType, BridgeMessage, ERC721DelegationMessage} from "../BridgeDefine.sol";
import {Errors} from "../../protocol/libraries/helpers/Errors.sol";
import "./IVaultParaX.sol";
import "./IVault.sol";

contract ParaxL1MessageHandler {
address internal immutable vault;
Expand All @@ -22,18 +22,25 @@ contract ParaxL1MessageHandler {

function migration(address asset) external {}

function bridgeReceive(BridgeMessage calldata message) external onlyBridge {
if (message.msgType == MessageType.ERC721DELEGATION) {
ERC721DelegationMessage memory delegationMsg = abi.decode(
message.data,
(ERC721DelegationMessage)
);
IVaultParaX(vault).updateTokenDelegation(
delegationMsg.delegateTo,
delegationMsg.asset,
delegationMsg.tokenIds,
delegationMsg.value
);
}
function updateTokenDelegation(
address delegateTo,
address underlyingAsset,
uint256[] calldata tokenIds,
bool value
) external onlyBridge {
IVault(vault).updateTokenDelegation(
delegateTo,
underlyingAsset,
tokenIds,
value
);
}

function updateApeStakingBeneficiary(
address nft,
uint32[] calldata tokenIds,
address newBenificiary
) external onlyBridge {
IVault(vault).updateBeneficiary(nft, tokenIds, newBenificiary);
}
}
26 changes: 0 additions & 26 deletions contracts/cross-chain/L1/VaultApeStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -759,16 +759,6 @@ contract VaultApeStaking is ReentrancyGuard, Pausable, IVaultApeStaking {
}
}

/// @inheritdoc IVaultApeStaking
function pause() external onlyEmergencyOrPoolAdmin {
_pause();
}

/// @inheritdoc IVaultApeStaking
function unpause() external onlyPoolAdmin {
_unpause();
}

modifier onlyMsgHandler() {
require(msg.sender == address(l1MsgHander), Errors.ONLY_MSG_HANDLER);
_;
Expand All @@ -782,29 +772,13 @@ contract VaultApeStaking is ReentrancyGuard, Pausable, IVaultApeStaking {
_;
}

/**
* @dev Only emergency or pool admin can call functions marked by this modifier.
**/
modifier onlyEmergencyOrPoolAdmin() {
_onlyPoolOrEmergencyAdmin();
_;
}

function _onlyPoolAdmin() internal view {
require(
aclManager.isPoolAdmin(msg.sender),
Errors.CALLER_NOT_POOL_ADMIN
);
}

function _onlyPoolOrEmergencyAdmin() internal view {
require(
aclManager.isPoolAdmin(msg.sender) ||
aclManager.isEmergencyAdmin(msg.sender),
Errors.CALLER_NOT_POOL_OR_EMERGENCY_ADMIN
);
}

function apeStakingStorage()
internal
pure
Expand Down
53 changes: 50 additions & 3 deletions contracts/cross-chain/L1/VaultCommon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,28 @@ pragma solidity ^0.8.0;
import "../../dependencies/openzeppelin/contracts/ReentrancyGuard.sol";
import "../../dependencies/openzeppelin/contracts//Pausable.sol";
import "../../dependencies/openzeppelin/contracts/Address.sol";
import "../../interfaces/IACLManager.sol";
import {Errors} from "../../protocol/libraries/helpers/Errors.sol";
import "./IVaultCommon.sol";

contract VaultCommon is ReentrancyGuard, Pausable, IVaultCommon {
/**
* @dev Receives and executes a batch of function calls on this contract.
*/
IACLManager private immutable aclManager;

constructor(address _aclManager) {
aclManager = IACLManager(_aclManager);
}

/// @inheritdoc IVaultCommon
function pause() external onlyEmergencyOrPoolAdmin {
_pause();
}

/// @inheritdoc IVaultCommon
function unpause() external onlyPoolAdmin {
_unpause();
}

/// @inheritdoc IVaultCommon
function multicall(
bytes[] calldata data
) external virtual returns (bytes[] memory results) {
Expand All @@ -28,4 +44,35 @@ contract VaultCommon is ReentrancyGuard, Pausable, IVaultCommon {
) external pure returns (bytes4) {
return this.onERC721Received.selector;
}

/**
* @dev Only pool admin can call functions marked by this modifier.
**/
modifier onlyPoolAdmin() {
_onlyPoolAdmin();
_;
}

/**
* @dev Only emergency or pool admin can call functions marked by this modifier.
**/
modifier onlyEmergencyOrPoolAdmin() {
_onlyPoolOrEmergencyAdmin();
_;
}

function _onlyPoolAdmin() internal view {
require(
aclManager.isPoolAdmin(msg.sender),
Errors.CALLER_NOT_POOL_ADMIN
);
}

function _onlyPoolOrEmergencyAdmin() internal view {
require(
aclManager.isPoolAdmin(msg.sender) ||
aclManager.isEmergencyAdmin(msg.sender),
Errors.CALLER_NOT_POOL_OR_EMERGENCY_ADMIN
);
}
}
Loading

0 comments on commit f9b85ee

Please sign in to comment.