Last active
June 22, 2022 15:57
-
-
Save donoso-eth/340ca96b53005dd457defab0991a735c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ============= ============= Create Simple Task with NO Prepayment Use Case Business Logic ============= ============= // | |
// #region Create Simple Task With NO Prepayment Use Case Business Logic | |
/************************************************************************** | |
* Create Simple Task With NO Prepayment Use Case Business Logic | |
* The difference with the simple create task is we will transfer the execution gas fees | |
* at the time of execution, for that we will require our contract to hold balance | |
* | |
* Step 1 : createTaskNoPrepayment() | |
* - requiere the contract to have funds or to receive funds | |
* - will create the task, we add ETH as the feetoken | |
* - will store the taskId | |
* | |
* Step 2 : checkerNoPrepayment() Function. | |
* - Check If the task can be executed , in this case if we do not have headache | |
* - returns the execPayload of startPartyNoPrepayment() | |
* | |
* Step 3 : Executable Function: startPartyNoPrepayment() | |
* - get Fee Details and transfer the requiered funds to Gelato | |
* - will Start the party setting lastPartyStart to block.timestamp | |
* - will cause a headache | |
*************************************************************************/ | |
function createTaskNoPrepayment() public payable { | |
require(taskIdByUser[msg.sender] == bytes32(0), "TASK_STILL_ACTIVE"); | |
require( | |
msg.value >= 0.1 ether || address(this).balance > 0.1 ether, | |
"NO_FUNDING" | |
); | |
bytes32 taskId = IOps(ops).createTaskNoPrepayment( | |
address(this), | |
this.startPartyNoPrepayment.selector, | |
address(this), | |
abi.encodeWithSelector(this.checkerNoPrepayment.selector), | |
ETH | |
); | |
taskIdByUser[msg.sender] = taskId; | |
} | |
function checkerNoPrepayment() | |
external | |
view | |
returns (bool canExec, bytes memory execPayload) | |
{ | |
canExec = headachePresent == false; | |
execPayload = abi.encodeWithSelector(this.startPartyNoPrepayment.selector); | |
} | |
function startPartyNoPrepayment() external onlyOps { | |
require(headachePresent == false, "NOT_READY"); | |
//// every task will be payed with a transfer of funds to gelato | |
uint256 fee; | |
address feeToken; | |
(fee, feeToken) = IOps(ops).getFeeDetails(); | |
_transfer(fee, feeToken); | |
lastPartyStart = block.timestamp; | |
headachePresent = true; | |
} | |
// #endregion Create Simple Task Without Prepayment Use Case Business Logic |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment