zeta-chain / toolkit

A library of ZetaChain helper utilities, contracts, and Hardhat tasks for smart-contract development
MIT License
43 stars 22 forks source link

OnlySystem modifier #131

Closed fadeev closed 6 months ago

fadeev commented 6 months ago

OnlySystem modifier which can be imported into contracts and used like so:

// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;

import "@zetachain/protocol-contracts/contracts/zevm/SystemContract.sol";
import "@zetachain/protocol-contracts/contracts/zevm/interfaces/zContract.sol";
import "@zetachain/toolkit/contracts/SwapHelperLib.sol";
import "@zetachain/toolkit/contracts/BytesHelperLib.sol";
import "@zetachain/toolkit/contracts/OnlySystem.sol";

contract Swap is zContract, OnlySystem {
    SystemContract public systemContract;

    constructor(address systemContractAddress) {
        systemContract = SystemContract(systemContractAddress);
    }

    function onCrossChainCall(
        zContext calldata context,
        address zrc20,
        uint256 amount,
        bytes calldata message
    ) external virtual override onlySystem(address(systemContract)) {
    //...
}
fadeev commented 6 months ago

@andresaiello please, review and lmk if this is the right way to ship a modifier. Thanks!