From 12d9f3b88ff8666a044bd44f7ce146a1090ae5dd Mon Sep 17 00:00:00 2001 From: defi-dev Date: Thu, 8 Aug 2024 22:18:04 +0800 Subject: [PATCH 1/2] add deactivateJob job method --- contracts/VRFAgentManager.sol | 26 +++++++++++++++++--------- test/mocks/MockVRFCoordinator.sol | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/contracts/VRFAgentManager.sol b/contracts/VRFAgentManager.sol index 9bab48f..f8ad754 100644 --- a/contracts/VRFAgentManager.sol +++ b/contracts/VRFAgentManager.sol @@ -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); @@ -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; } diff --git a/test/mocks/MockVRFCoordinator.sol b/test/mocks/MockVRFCoordinator.sol index 365abad..bf4abdd 100644 --- a/test/mocks/MockVRFCoordinator.sol +++ b/test/mocks/MockVRFCoordinator.sol @@ -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]; } From c4cb76a73d86c55f2d1ac6fd16ede82778b3fc04 Mon Sep 17 00:00:00 2001 From: defi-dev Date: Mon, 12 Aug 2024 13:46:04 +0800 Subject: [PATCH 2/2] fix deactivateJob job method --- contracts/VRFAgentManager.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/VRFAgentManager.sol b/contracts/VRFAgentManager.sol index f8ad754..615374a 100644 --- a/contracts/VRFAgentManager.sol +++ b/contracts/VRFAgentManager.sol @@ -323,7 +323,7 @@ contract VRFAgentManager is Ownable { } function deactivateJob(bytes32 jobKey_) public onlyOwner returns(uint256 jobBalance) { - jobBalance = getAutoDepositJobBalance(); + jobBalance = getJobBalance(jobKey_); setJobConfig(jobKey_, false, false, false, false); agent.withdrawJobCredits(jobKey_, payable(address(this)), jobBalance);