diff --git a/contracts/keeper/CrossChainMintKeeperHelper.sol b/contracts/keeper/CrossChainMintKeeperHelper.sol new file mode 100644 index 00000000..57fb286d --- /dev/null +++ b/contracts/keeper/CrossChainMintKeeperHelper.sol @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +pragma solidity >=0.6.10 <0.8.0; + +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@chainlink/contracts/src/v0.6/interfaces/KeeperCompatibleInterface.sol"; +import "../layerzero/interfaces/ILayerZeroEndpoint.sol"; +import "../utils/CoreUtility.sol"; + +interface IScheduleRelayer { + function lzEndpoint() external view returns (ILayerZeroEndpoint); + + function subLzChainID() external view returns (uint16); + + function lastWeek() external view returns (uint256); + + function crossChainMint(bytes memory adapterParams) external payable; +} + +contract CrossChainMintKeeperHelper is KeeperCompatibleInterface, Ownable, CoreUtility { + uint256 private constant DATA_LENGTH = 32; // abi.encode(uint256) + uint256 private constant MINT_GAS_LIMIT = 140000; + + IScheduleRelayer public immutable relayer; + uint16 public immutable subLzChainID; + ILayerZeroEndpoint public immutable lzEndpoint; + + constructor(address relayer_) public { + relayer = IScheduleRelayer(relayer_); + subLzChainID = IScheduleRelayer(relayer_).subLzChainID(); + lzEndpoint = IScheduleRelayer(relayer_).lzEndpoint(); + } + + receive() external payable {} + + function withdraw(uint256 value) external onlyOwner { + (bool success, ) = msg.sender.call{value: value}(""); + require(success, "ETH transfer failed"); + } + + function checkUpkeep(bytes calldata) + external + override + returns (bool upkeepNeeded, bytes memory) + { + uint256 startWeek = _endOfWeek(block.timestamp) - 1 weeks; + uint256 lastWeek = relayer.lastWeek(); + upkeepNeeded = (startWeek > lastWeek); + } + + function performUpkeep(bytes calldata) external override { + (uint256 srcFees, ) = + lzEndpoint.estimateFees( + subLzChainID, + address(relayer), + new bytes(DATA_LENGTH), + false, + abi.encodePacked(uint16(1), MINT_GAS_LIMIT) + ); + require(address(this).balance >= srcFees, "Not enough balance"); + relayer.crossChainMint{value: srcFees}(abi.encodePacked(uint16(1), MINT_GAS_LIMIT)); + } +} diff --git a/contracts/keeper/CrossChainSyncKeeperHelper.sol b/contracts/keeper/CrossChainSyncKeeperHelper.sol index 8f60e1a1..d2b30aaa 100644 --- a/contracts/keeper/CrossChainSyncKeeperHelper.sol +++ b/contracts/keeper/CrossChainSyncKeeperHelper.sol @@ -10,7 +10,7 @@ interface ISubSchedule { function mainLzChainID() external view returns (uint16); - function crossChainSync() external payable; + function crossChainSync(bytes memory adapterParams) external payable; } contract CrossChainSyncKeeperHelper is KeeperCompatibleInterface, Ownable { @@ -62,7 +62,7 @@ contract CrossChainSyncKeeperHelper is KeeperCompatibleInterface, Ownable { abi.encodePacked(uint16(1), SYNC_GAS_LIMIT) ); require(address(this).balance >= srcFees, "Not enough balance"); - subSchedule.crossChainSync{value: srcFees}(); + subSchedule.crossChainSync{value: srcFees}(abi.encodePacked(uint16(1), SYNC_GAS_LIMIT)); // Always skip to the lastest week _updateLastTimestamp(