Skip to content

Commit

Permalink
Merge pull request #313 from tranchess/dev-bc-keeperhelper
Browse files Browse the repository at this point in the history
Add CrossChainMint Keeper helper
  • Loading branch information
tpawn authored Jul 25, 2023
2 parents 5dc6f06 + 4682171 commit 7286c54
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
62 changes: 62 additions & 0 deletions contracts/keeper/CrossChainMintKeeperHelper.sol
Original file line number Diff line number Diff line change
@@ -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));
}
}
4 changes: 2 additions & 2 deletions contracts/keeper/CrossChainSyncKeeperHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 7286c54

Please sign in to comment.