Skip to content

Commit

Permalink
update reserve amount of LINK after offchain settlement (#12916)
Browse files Browse the repository at this point in the history
  • Loading branch information
shileiwill authored Apr 24, 2024
1 parent a293dfe commit 7ec1d5b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-icons-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

offchain settlement fix #bugfix
5 changes: 5 additions & 0 deletions contracts/.changeset/poor-panthers-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chainlink/contracts": patch
---

Offchain settlement fix #bugfix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,25 +166,32 @@ 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(
transmitterAddr,
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));
}
Expand Down

0 comments on commit 7ec1d5b

Please sign in to comment.