Skip to content

Commit

Permalink
reserveAmounts to be a map to take ERC20s. (#12413)
Browse files Browse the repository at this point in the history
* add financeAdmin to onchainConfig

* remove ownerLinkbalance and rename expectedLinkBalance

* add withdraw functions

* add foundry test and generate wrappers

* reserveAmounts is a map for various tokens
  • Loading branch information
shileiwill authored Mar 13, 2024
1 parent d01db32 commit e6843e8
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-timers-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

make reserveAmounts to be a map
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ contract AutomationRegistry2_3 is AutomationRegistryBase2_3, OCR2Abstract, Chain
uint256 id = abi.decode(data, (uint256));
if (s_upkeep[id].maxValidBlocknumber != UINT32_MAX) revert UpkeepCancelled();
s_upkeep[id].balance = s_upkeep[id].balance + uint96(amount);
s_reserveLinkBalance = s_reserveLinkBalance + amount;
s_reserveAmounts[address(i_link)] = s_reserveAmounts[address(i_link)] + amount;
emit FundsAdded(id, sender, uint96(amount));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ abstract contract AutomationRegistryBase2_3 is ConfirmedOwner {
uint256 internal s_fallbackGasPrice;
uint256 internal s_fallbackLinkPrice;
uint256 internal s_fallbackNativePrice;
uint256 internal s_reserveLinkBalance; // Unspent user deposits + unwithdrawn NOP payments
mapping(address billingToken => uint256 reserveAmount) internal s_reserveAmounts; // unspent user deposits + unwithdrawn NOP payments
mapping(address => MigrationPermission) internal s_peerRegistryMigrationPermission; // Permissions for migration to and fro
mapping(uint256 => bytes) internal s_upkeepTriggerConfig; // upkeep triggers
mapping(uint256 => bytes) internal s_upkeepOffchainConfig; // general config set by users for each upkeep
Expand Down Expand Up @@ -593,7 +593,7 @@ abstract contract AutomationRegistryBase2_3 is ConfirmedOwner {
s_upkeep[id] = upkeep;
s_upkeepAdmin[id] = admin;
s_checkData[id] = checkData;
s_reserveLinkBalance = s_reserveLinkBalance + upkeep.balance;
s_reserveAmounts[address(i_link)] = s_reserveAmounts[address(i_link)] + upkeep.balance;
s_upkeepTriggerConfig[id] = triggerConfig;
s_upkeepOffchainConfig[id] = offchainConfig;
s_upkeepIDs.add(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ contract AutomationRegistryLogicA2_3 is AutomationRegistryBase2_3, Chainable {
}
}
s_upkeep[id].balance = upkeep.balance - cancellationFee;
s_reserveLinkBalance = s_reserveLinkBalance - cancellationFee;
s_reserveAmounts[address(i_link)] = s_reserveAmounts[address(i_link)] - cancellationFee;

emit UpkeepCanceled(id, uint64(height));
}
Expand All @@ -309,7 +309,7 @@ contract AutomationRegistryLogicA2_3 is AutomationRegistryBase2_3, Chainable {
Upkeep memory upkeep = s_upkeep[id];
if (upkeep.maxValidBlocknumber != UINT32_MAX) revert UpkeepCancelled();
s_upkeep[id].balance = upkeep.balance + amount;
s_reserveLinkBalance = s_reserveLinkBalance + amount;
s_reserveAmounts[address(i_link)] = s_reserveAmounts[address(i_link)] + amount;
i_link.transferFrom(msg.sender, address(this), amount);
emit FundsAdded(id, msg.sender, amount);
}
Expand Down Expand Up @@ -357,7 +357,7 @@ contract AutomationRegistryLogicA2_3 is AutomationRegistryBase2_3, Chainable {
s_upkeepIDs.remove(id);
emit UpkeepMigrated(id, upkeep.balance, destination);
}
s_reserveLinkBalance = s_reserveLinkBalance - totalBalanceRemaining;
s_reserveAmounts[address(i_link)] = s_reserveAmounts[address(i_link)] - totalBalanceRemaining;
bytes memory encodedUpkeeps = abi.encode(
ids,
upkeeps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ contract AutomationRegistryLogicB2_3 is AutomationRegistryBase2_3 {
if (s_upkeepAdmin[id] != msg.sender) revert OnlyCallableByAdmin();
if (upkeep.maxValidBlocknumber > s_hotVars.chainModule.blockNumber()) revert UpkeepNotCanceled();
uint96 amountToWithdraw = s_upkeep[id].balance;
s_reserveLinkBalance = s_reserveLinkBalance - amountToWithdraw;
s_reserveAmounts[address(i_link)] = s_reserveAmounts[address(i_link)] - amountToWithdraw;
s_upkeep[id].balance = 0;
i_link.transfer(to, amountToWithdraw);
emit FundsWithdrawn(id, amountToWithdraw, to);
Expand All @@ -140,7 +140,7 @@ contract AutomationRegistryLogicB2_3 is AutomationRegistryBase2_3 {
* @notice LINK available to withdraw by the finance team
*/
function linkAvailableForPayment() public view returns (uint256) {
return i_link.balanceOf(address(this)) - s_reserveLinkBalance;
return i_link.balanceOf(address(this)) - s_reserveAmounts[address(i_link)];
}

function withdrawLinkFees(address to, uint256 amount) external {
Expand Down Expand Up @@ -206,7 +206,7 @@ contract AutomationRegistryLogicB2_3 is AutomationRegistryBase2_3 {
if (s_transmitterPayees[from] != msg.sender) revert OnlyCallableByPayee();
uint96 balance = _updateTransmitterBalanceFromPool(from, s_hotVars.totalPremium, uint96(s_transmittersList.length));
s_transmitters[from].balance = 0;
s_reserveLinkBalance = s_reserveLinkBalance - balance;
s_reserveAmounts[address(i_link)] = s_reserveAmounts[address(i_link)] - balance;
i_link.transfer(to, balance);
emit PaymentWithdrawn(from, balance, to, msg.sender);
}
Expand Down Expand Up @@ -459,7 +459,7 @@ contract AutomationRegistryLogicB2_3 is AutomationRegistryBase2_3 {
state = State({
nonce: s_storage.nonce,
ownerLinkBalance: 0,
expectedLinkBalance: s_reserveLinkBalance,
expectedLinkBalance: s_reserveAmounts[address(i_link)],
totalPremium: s_hotVars.totalPremium,
numUpkeeps: s_upkeepIDs.length(),
configCount: s_storage.configCount,
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ automation_forwarder_logic: ../../contracts/solc/v0.8.16/AutomationForwarderLogi
automation_registrar_wrapper2_1: ../../contracts/solc/v0.8.16/AutomationRegistrar2_1/AutomationRegistrar2_1.abi ../../contracts/solc/v0.8.16/AutomationRegistrar2_1/AutomationRegistrar2_1.bin eb06d853aab39d3196c593b03e555851cbe8386e0fe54a74c2479f62d14b3c42
automation_registrar_wrapper2_3: ../../contracts/solc/v0.8.19/AutomationRegistrar2_3/AutomationRegistrar2_3.abi ../../contracts/solc/v0.8.19/AutomationRegistrar2_3/AutomationRegistrar2_3.bin 8e18d447009546ac8ad15d0d516ad4d663d0e1ca5f723300acb604b5571b63bf
automation_registry_logic_a_wrapper_2_2: ../../contracts/solc/v0.8.19/AutomationRegistryLogicA2_2/AutomationRegistryLogicA2_2.abi ../../contracts/solc/v0.8.19/AutomationRegistryLogicA2_2/AutomationRegistryLogicA2_2.bin 58d09c16be20a6d3f70be6d06299ed61415b7796c71f176d87ce015e1294e029
automation_registry_logic_a_wrapper_2_3: ../../contracts/solc/v0.8.19/AutomationRegistryLogicA2_3/AutomationRegistryLogicA2_3.abi ../../contracts/solc/v0.8.19/AutomationRegistryLogicA2_3/AutomationRegistryLogicA2_3.bin 64c9acd72540fadb0e8f2b641ce580a766e6542aca03f40e1e9a77b025a85185
automation_registry_logic_a_wrapper_2_3: ../../contracts/solc/v0.8.19/AutomationRegistryLogicA2_3/AutomationRegistryLogicA2_3.abi ../../contracts/solc/v0.8.19/AutomationRegistryLogicA2_3/AutomationRegistryLogicA2_3.bin 814408fe3f1c80c709c91341a303a18c5bf758060ca4fae2686194ffa5ee5ffc
automation_registry_logic_b_wrapper_2_2: ../../contracts/solc/v0.8.19/AutomationRegistryLogicB2_2/AutomationRegistryLogicB2_2.abi ../../contracts/solc/v0.8.19/AutomationRegistryLogicB2_2/AutomationRegistryLogicB2_2.bin e5669214a6b747b17331ebbf8f2d13cf7100d3313d652c6f1304ccf158441fc6
automation_registry_logic_b_wrapper_2_3: ../../contracts/solc/v0.8.19/AutomationRegistryLogicB2_3/AutomationRegistryLogicB2_3.abi ../../contracts/solc/v0.8.19/AutomationRegistryLogicB2_3/AutomationRegistryLogicB2_3.bin 19b65d0dfcb80041f3654cfc201369808623cae28018f64e45b6c06b4da4a25b
automation_registry_logic_b_wrapper_2_3: ../../contracts/solc/v0.8.19/AutomationRegistryLogicB2_3/AutomationRegistryLogicB2_3.abi ../../contracts/solc/v0.8.19/AutomationRegistryLogicB2_3/AutomationRegistryLogicB2_3.bin a6d3aa3dd5aa64887e1f73d03cc35dbb6c3e2f3e311d81ae5496ef96cfd01bda
automation_registry_wrapper_2_2: ../../contracts/solc/v0.8.19/AutomationRegistry2_2/AutomationRegistry2_2.abi ../../contracts/solc/v0.8.19/AutomationRegistry2_2/AutomationRegistry2_2.bin eca1187a878b622ef3fced041a28a4229d45dd797d95630838ff6351b6afc437
automation_registry_wrapper_2_3: ../../contracts/solc/v0.8.19/AutomationRegistry2_3/AutomationRegistry2_3.abi ../../contracts/solc/v0.8.19/AutomationRegistry2_3/AutomationRegistry2_3.bin 537d03d6fb8dac368790a1e92a9df8a15c4fe2a93a626a1d3789dcc37731354c
automation_registry_wrapper_2_3: ../../contracts/solc/v0.8.19/AutomationRegistry2_3/AutomationRegistry2_3.abi ../../contracts/solc/v0.8.19/AutomationRegistry2_3/AutomationRegistry2_3.bin 6127aa4541dbecc98e01486f43fa8bc6934f56037a376e2f9a97dac2870165fe
automation_utils_2_1: ../../contracts/solc/v0.8.16/AutomationUtils2_1/AutomationUtils2_1.abi ../../contracts/solc/v0.8.16/AutomationUtils2_1/AutomationUtils2_1.bin 331bfa79685aee6ddf63b64c0747abee556c454cae3fb8175edff425b615d8aa
automation_utils_2_2: ../../contracts/solc/v0.8.19/AutomationUtils2_2/AutomationUtils2_2.abi ../../contracts/solc/v0.8.19/AutomationUtils2_2/AutomationUtils2_2.bin 6fe2e41b1d3b74bee4013a48c10d84da25e559f28e22749aa13efabbf2cc2ee8
automation_utils_2_3: ../../contracts/solc/v0.8.19/AutomationUtils2_3/AutomationUtils2_3.abi ../../contracts/solc/v0.8.19/AutomationUtils2_3/AutomationUtils2_3.bin 6c774a1924c04f545b1dd8e7b2463293cdaeeced43e8ef7f34effc490cbe7f4a
Expand Down

0 comments on commit e6843e8

Please sign in to comment.