zeta-chain / protocol-contracts

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

feat: Write a zetatokenconsumer for zevm #146

Closed andresaiello closed 5 months ago

andresaiello commented 6 months ago

Summary

fadeev commented 6 months ago

Would we be able to use the consumer on ZetaChain the same way as on Ethereum, for example?

Would this work on ZetaChain?


import "@zetachain/protocol-contracts/contracts/evm/interfaces/ZetaInterfaces.sol";

contract CrossChainMessage is ZetaInteractor, ZetaReceiver {
    ZetaTokenConsumer private immutable _zetaConsumer;

    constructor(address connectorAddress, address zetaTokenAddress, address zetaConsumerAddress) ZetaInteractor(connectorAddress) {
        _zetaToken = IERC20(zetaTokenAddress);
        _zetaConsumer = ZetaTokenConsumer(zetaConsumerAddress);
    }

    function sendMessage(uint256 destinationChainId, string memory message) external payable {
        uint256 crossChainGas = 2 * (10 ** 18);
        uint256 zetaValueAndGas = _zetaConsumer.getZetaFromEth{
            value: msg.value
        }(address(this), crossChainGas);
        _zetaToken.approve(address(connector), zetaValueAndGas);

        connector.send(...)
    }
    //...
}
socket-security[bot] commented 6 months ago

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/buffer-from@1.1.2 None 0 5.05 kB linusu
npm/deep-is@0.1.4 None 0 8.11 kB thlorenz
npm/fast-levenshtein@2.0.6 None 0 9.44 kB hiddentao
npm/get-caller-file@2.0.5 None 0 4.72 kB stefanpenner
npm/has-bigints@1.0.2 None 0 12.8 kB ljharb
npm/util-deprecate@1.0.2 None 0 5.48 kB tootallnate

🚮 Removed packages: npm/abstract-leveldown@6.3.0, npm/diff@3.5.0, npm/level-concat-iterator@2.0.1, npm/level-errors@2.0.1, npm/string-width@2.1.1, npm/yargs@13.3.2

View full report↗︎

andresaiello commented 6 months ago

Would we be able to use the consumer on ZetaChain the same way as on Ethereum, for example?

Would this work on ZetaChain?

import "@zetachain/protocol-contracts/contracts/evm/interfaces/ZetaInterfaces.sol";

contract CrossChainMessage is ZetaInteractor, ZetaReceiver {
    ZetaTokenConsumer private immutable _zetaConsumer;

    constructor(address connectorAddress, address zetaTokenAddress, address zetaConsumerAddress) ZetaInteractor(connectorAddress) {
        _zetaToken = IERC20(zetaTokenAddress);
        _zetaConsumer = ZetaTokenConsumer(zetaConsumerAddress);
    }

    function sendMessage(uint256 destinationChainId, string memory message) external payable {
        uint256 crossChainGas = 2 * (10 ** 18);
        uint256 zetaValueAndGas = _zetaConsumer.getZetaFromEth{
            value: msg.value
        }(address(this), crossChainGas);
        _zetaToken.approve(address(connector), zetaValueAndGas);

        connector.send(...)
    }
    //...
}

it should