zeta-chain / protocol-contracts

Protocol contracts implementing the core logic of the protocol, deployed on ZetaChain and on connected chains
MIT License
68 stars 55 forks source link

Use try catch #205

Open skosito opened 3 months ago

skosito commented 3 months ago
          In cases where we want to invoke an interface (there are a few of them across all the contracts), we can call them in a controlled way, such as in:
        IZRC20 zrc20token = IZRC20(zrc20);

        try zrc20token.withdrawGasFee() returns (address gasZRC20, uint256 gasFee) {
            if (gasZRC20 == address(0)) revert InvalidZRC20;
            if (!zrc20token.transferFrom(msg.sender, FUNGIBLE_MODULE_ADDRESS, gasFee)) {
                revert GasFeeTransferFailed();
            }
        } catch {
            revert SomeErrorEvent();
        }

_Originally posted by @fbac in https://github.com/zeta-chain/protocol-contracts/pull/162#discussion_r1663924981_