Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add deactivateJob job method #31

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = getJobBalance(jobKey_);

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
Loading