Skip to content

Commit

Permalink
add deactivateJob job method
Browse files Browse the repository at this point in the history
  • Loading branch information
defi-dev committed Aug 8, 2024
1 parent d833b1d commit 12d9f3b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 17 additions & 9 deletions contracts/VRFAgentManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,22 @@ contract VRFAgentManager is Ownable {

acceptAllJobsTransfer();

uint256 autoDepositJobBalance = getAutoDepositJobBalance();
setJobConfig(autoDepositJobKey, false, false, false, false);
agent.withdrawJobCredits(autoDepositJobKey, payable(address(this)), autoDepositJobBalance);
(, , uint256 jobMinKeeperCvp, PPAgentV2VRFBased.Job memory details, , ) = agent.getJob(autoDepositJobKey);

uint256 autoDepositJobBalance = deactivateJob(autoDepositJobKey);
_registerAutoDepositJob(details.maxBaseFeeGwei, details.rewardPct, details.fixedReward, jobMinKeeperCvp, true, autoDepositJobBalance);

setVrfConfig(oldVrfAgentManager_.vrfJobMinBalance(), oldVrfAgentManager_.vrfJobMaxDeposit());
setAutoDepositConfig(oldVrfAgentManager_.autoDepositJobMinBalance(), oldVrfAgentManager_.autoDepositJobMaxDeposit());
}

function deactivateJob(bytes32 jobKey_) public onlyOwner returns(uint256 jobBalance) {
jobBalance = getAutoDepositJobBalance();

setJobConfig(jobKey_, false, false, false, false);
agent.withdrawJobCredits(jobKey_, payable(address(this)), jobBalance);
}

function acceptAllJobsTransfer() public onlyOwner {
if (getJobPendingOwner(vrfJobKey) == address(this)) {
agent.acceptJobTransfer(vrfJobKey);
Expand All @@ -335,18 +340,21 @@ contract VRFAgentManager is Ownable {

/*** GETTER ***/

function getVrfFullfillJobBalance() public view returns(uint256) {
(, , , PPAgentV2VRFBased.Job memory details, , ) = agent.getJob(vrfJobKey);
return details.credits;
}

function getVrfFullfillJobResolver() public view returns(IPPAgentV2Viewer.Resolver memory) {
(, , , , , IPPAgentV2Viewer.Resolver memory resolver) = agent.getJob(vrfJobKey);
return resolver;
}

function getVrfFullfillJobBalance() public view returns(uint256) {
return getJobBalance(vrfJobKey);
}

function getAutoDepositJobBalance() public view returns(uint256) {
(, , , PPAgentV2VRFBased.Job memory details, , ) = agent.getJob(autoDepositJobKey);
return getJobBalance(autoDepositJobKey);
}

function getJobBalance(bytes32 jobKey_) public view returns(uint256) {
(, , , PPAgentV2VRFBased.Job memory details, , ) = agent.getJob(jobKey_);
return details.credits;
}

Expand Down
2 changes: 1 addition & 1 deletion test/mocks/MockVRFCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract MockVRFCoordinator is VRFAgentCoordinator {
randomWords = new uint256[](requestedNumWords);
requestId = lastRequestIdByConsumer[requestedByConsumer];
for (uint256 i = 0; i < randomWords.length; i++) {
randomWords[i] = i + requestId + 95;
randomWords[i] = i + requestId + 100;
}
delete s_requestCommitments[requestId];
}
Expand Down

0 comments on commit 12d9f3b

Please sign in to comment.