Skip to content

Commit

Permalink
get available erc20 for finance payment (#13088)
Browse files Browse the repository at this point in the history
  • Loading branch information
shileiwill committed May 3, 2024
1 parent d79bdf1 commit 29b1636
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-hats-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

get available erc20 for payment #bugfix
5 changes: 5 additions & 0 deletions contracts/.changeset/proud-tables-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chainlink/contracts": patch
---

get available erc20s for payment #bugfix

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions contracts/src/v0.8/automation/dev/test/AutomationRegistry2_3.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ contract AddFunds is SetUp {
registry.addFunds(nativeUpkeepID, 1);
assertEq(registry.getBalance(nativeUpkeepID), startRegistryBalance + 1);
assertEq(weth.balanceOf(address(registry)), startTokenBalance + 1);
assertEq(registry.getAvailableERC20ForPayment(address(weth)), 0);
}

// when msg.value is not 0, it uses the native payment path
Expand All @@ -214,6 +215,7 @@ contract AddFunds is SetUp {
registry.addFunds{value: 1}(nativeUpkeepID, 1000); // parameter amount should be ignored
assertEq(registry.getBalance(nativeUpkeepID), startRegistryBalance + 1);
assertEq(weth.balanceOf(address(registry)), startTokenBalance + 1);
assertEq(registry.getAvailableERC20ForPayment(address(weth)), 0);
}

// it fails when the billing token is not native, but trying to pay with native
Expand Down Expand Up @@ -348,6 +350,10 @@ contract Withdraw is SetUp {
function test_WithdrawERC20Fees_RevertsWhen_LinkAvailableForPaymentIsNegative() public {
_transmit(usdUpkeepID18, registry); // adds USD token to finance withdrawable, and gives NOPs a LINK balance
require(registry.linkAvailableForPayment() < 0, "linkAvailableForPayment should be negative");
require(
registry.getAvailableERC20ForPayment(address(usdToken18)) > 0,
"ERC20AvailableForPayment should be positive"
);
vm.expectRevert(Registry.InsufficientLinkLiquidity.selector);
vm.prank(FINANCE_ADMIN);
registry.withdrawERC20Fees(address(usdToken18), FINANCE_ADMIN, 1); // should revert
Expand Down Expand Up @@ -1563,8 +1569,21 @@ contract Transmit is SetUp {
upkeepIDs[0] = linkUpkeepID;
upkeepIDs[1] = usdUpkeepID18;
upkeepIDs[2] = nativeUpkeepID;

// withdraw-able by finance team should be 0
require(registry.getAvailableERC20ForPayment(address(usdToken18)) == 0, "ERC20AvailableForPayment should be 0");
require(registry.getAvailableERC20ForPayment(address(weth)) == 0, "ERC20AvailableForPayment should be 0");

// do the thing
_transmit(upkeepIDs, registry);

// withdraw-able by the finance team should be positive
require(
registry.getAvailableERC20ForPayment(address(usdToken18)) > 0,
"ERC20AvailableForPayment should be positive"
);
require(registry.getAvailableERC20ForPayment(address(weth)) > 0, "ERC20AvailableForPayment should be positive");

// assert upkeep balances have decreased
require(prevUpkeepBalances[0] > registry.getBalance(linkUpkeepID), "link upkeep balance should have decreased");
require(prevUpkeepBalances[1] > registry.getBalance(usdUpkeepID18), "usd upkeep balance should have decreased");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,13 @@ contract AutomationRegistryLogicC2_3 is AutomationRegistryBase2_3 {
return s_reserveAmounts[billingToken];
}

/**
* @notice returns the amount of a particular token that is withdraw-able by finance admin
*/
function getAvailableERC20ForPayment(IERC20 billingToken) external view returns (uint256) {
return billingToken.balanceOf(address(this)) - s_reserveAmounts[IERC20(address(billingToken))];
}

/**
* @notice returns the size of the LINK liquidity pool
*/
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dummy_protocol_wrapper: ../../contracts/solc/v0.8.16/DummyProtocol/DummyProtocol
gas_wrapper: ../../contracts/solc/v0.8.6/KeeperRegistryCheckUpkeepGasUsageWrapper1_2/KeeperRegistryCheckUpkeepGasUsageWrapper1_2.abi ../../contracts/solc/v0.8.6/KeeperRegistryCheckUpkeepGasUsageWrapper1_2/KeeperRegistryCheckUpkeepGasUsageWrapper1_2.bin 4a5dcdac486d18fcd58e3488c15c1710ae76b977556a3f3191bd269a4bc75723
gas_wrapper_mock: ../../contracts/solc/v0.8.6/KeeperRegistryCheckUpkeepGasUsageWrapper1_2Mock/KeeperRegistryCheckUpkeepGasUsageWrapper1_2Mock.abi ../../contracts/solc/v0.8.6/KeeperRegistryCheckUpkeepGasUsageWrapper1_2Mock/KeeperRegistryCheckUpkeepGasUsageWrapper1_2Mock.bin a9b08f18da59125c6fc305855710241f3d35161b8b9f3e3f635a7b1d5c6da9c8
i_automation_registry_master_wrapper_2_2: ../../contracts/solc/v0.8.19/IAutomationRegistryMaster/IAutomationRegistryMaster.abi ../../contracts/solc/v0.8.19/IAutomationRegistryMaster/IAutomationRegistryMaster.bin 9ff7087179f89f9b05964ebc3e71332fce11f1b8e85058f7b16b3bc0dd6fb96b
i_automation_registry_master_wrapper_2_3: ../../contracts/solc/v0.8.19/IAutomationRegistryMaster2_3/IAutomationRegistryMaster2_3.abi ../../contracts/solc/v0.8.19/IAutomationRegistryMaster2_3/IAutomationRegistryMaster2_3.bin 19f51996d05341f1229f21be26b5d72ff58e321f0b6da69c260f768e4622ae8e
i_automation_registry_master_wrapper_2_3: ../../contracts/solc/v0.8.19/IAutomationRegistryMaster2_3/IAutomationRegistryMaster2_3.abi ../../contracts/solc/v0.8.19/IAutomationRegistryMaster2_3/IAutomationRegistryMaster2_3.bin aa65a3c4bc89fadae2f389da6643caad50e9b9948d61e2d40d8f00774f356a80
i_automation_v21_plus_common: ../../contracts/solc/v0.8.19/IAutomationV21PlusCommon/IAutomationV21PlusCommon.abi ../../contracts/solc/v0.8.19/IAutomationV21PlusCommon/IAutomationV21PlusCommon.bin e8a601ec382c0a2e83c49759de13b0622b5e04e6b95901e96a1e9504329e594c
i_chain_module: ../../contracts/solc/v0.8.19/IChainModule/IChainModule.abi ../../contracts/solc/v0.8.19/IChainModule/IChainModule.bin 383611981c86c70522f41b8750719faacc7d7933a22849d5004799ebef3371fa
i_keeper_registry_master_wrapper_2_1: ../../contracts/solc/v0.8.16/IKeeperRegistryMaster/IKeeperRegistryMaster.abi ../../contracts/solc/v0.8.16/IKeeperRegistryMaster/IKeeperRegistryMaster.bin ee0f150b3afbab2df3d24ff3f4c87851efa635da30db04cd1f70cb4e185a1781
Expand Down

0 comments on commit 29b1636

Please sign in to comment.