From 7ec1d5b7abb51e100f7a6a48662e33703a589ecb Mon Sep 17 00:00:00 2001 From: Lei Date: Wed, 24 Apr 2024 16:46:16 -0700 Subject: [PATCH] update reserve amount of LINK after offchain settlement (#12916) --- .changeset/witty-icons-rhyme.md | 5 +++++ contracts/.changeset/poor-panthers-build.md | 5 +++++ .../v0.8/automation/dev/test/AutomationRegistry2_3.t.sol | 6 ++++++ .../automation/dev/v2_3/AutomationRegistryLogicC2_3.sol | 7 +++++++ 4 files changed, 23 insertions(+) create mode 100644 .changeset/witty-icons-rhyme.md create mode 100644 contracts/.changeset/poor-panthers-build.md diff --git a/.changeset/witty-icons-rhyme.md b/.changeset/witty-icons-rhyme.md new file mode 100644 index 00000000000..25d9cf3b1d3 --- /dev/null +++ b/.changeset/witty-icons-rhyme.md @@ -0,0 +1,5 @@ +--- +"chainlink": patch +--- + +offchain settlement fix #bugfix diff --git a/contracts/.changeset/poor-panthers-build.md b/contracts/.changeset/poor-panthers-build.md new file mode 100644 index 00000000000..2c21cae5d7a --- /dev/null +++ b/contracts/.changeset/poor-panthers-build.md @@ -0,0 +1,5 @@ +--- +"@chainlink/contracts": patch +--- + +Offchain settlement fix #bugfix diff --git a/contracts/src/v0.8/automation/dev/test/AutomationRegistry2_3.t.sol b/contracts/src/v0.8/automation/dev/test/AutomationRegistry2_3.t.sol index 3e7e489379e..03138696436 100644 --- a/contracts/src/v0.8/automation/dev/test/AutomationRegistry2_3.t.sol +++ b/contracts/src/v0.8/automation/dev/test/AutomationRegistry2_3.t.sol @@ -940,6 +940,9 @@ contract NOPsSettlement is SetUp { assertEq(i, index); assertEq(0, balance); } + + // after the offchain settlement, the total reserve amount of LINK should be 0 + assertEq(registry.getReserveAmount(address(linkToken)), 0); } function testSettleNOPsOffchainForDeactivatedTransmittersSuccess() public { @@ -1035,6 +1038,9 @@ contract NOPsSettlement is SetUp { assertEq(i, index); assertEq(0, balance); } + + // after the offchain settlement, the total reserve amount of LINK should be 0 + assertEq(registry.getReserveAmount(address(linkToken)), 0); } function testDisableOffchainPaymentsRevertDueToUnauthorizedCaller() public { diff --git a/contracts/src/v0.8/automation/dev/v2_3/AutomationRegistryLogicC2_3.sol b/contracts/src/v0.8/automation/dev/v2_3/AutomationRegistryLogicC2_3.sol index 92a9ca1a648..4048227f111 100644 --- a/contracts/src/v0.8/automation/dev/v2_3/AutomationRegistryLogicC2_3.sol +++ b/contracts/src/v0.8/automation/dev/v2_3/AutomationRegistryLogicC2_3.sol @@ -166,6 +166,7 @@ contract AutomationRegistryLogicC2_3 is AutomationRegistryBase2_3 { uint256 length = activeTransmittersLength + deactivatedTransmittersLength; uint256[] memory payments = new uint256[](length); address[] memory payees = new address[](length); + for (uint256 i = 0; i < activeTransmittersLength; i++) { address transmitterAddr = s_transmittersList[i]; uint96 balance = _updateTransmitterBalanceFromPool( @@ -173,18 +174,24 @@ contract AutomationRegistryLogicC2_3 is AutomationRegistryBase2_3 { s_hotVars.totalPremium, uint96(activeTransmittersLength) ); + payments[i] = balance; payees[i] = s_transmitterPayees[transmitterAddr]; s_transmitters[transmitterAddr].balance = 0; } + for (uint256 i = 0; i < deactivatedTransmittersLength; i++) { address deactivatedAddr = s_deactivatedTransmitters.at(i); Transmitter memory transmitter = s_transmitters[deactivatedAddr]; + payees[i + activeTransmittersLength] = s_transmitterPayees[deactivatedAddr]; payments[i + activeTransmittersLength] = transmitter.balance; s_transmitters[deactivatedAddr].balance = 0; } + // reserve amount of LINK is reset to 0 since no user deposits of LINK are expected in offchain mode + s_reserveAmounts[IERC20(address(i_link))] = 0; + for (uint256 idx = s_deactivatedTransmitters.length(); idx > 0; idx--) { s_deactivatedTransmitters.remove(s_deactivatedTransmitters.at(idx - 1)); }