Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LinkBalMonV2(minPerform) and CCIPWatchlist AutoUpdate Contract #13605

Closed
wants to merge 6 commits into from

Conversation

poke1994
Copy link
Collaborator

Adding 2 files.

  1. I added a minPerform() function to the LinkBalMonV2 contract and tested it on Sepolia. The purpose of the minPerform function is to establish a minimum batch size required for the sampleUnderfunded address array. If the array size is less than minPerform, no top-up operation will be performed. This optimization is crucial for deploying the BalanceMonitor contract on Ethereum, which consumes significant gas.

  2. Creation of a CCIPOnRampWatchlistUpdate contract to allow auto update of the watchlist on the LinkBalMonV2 when deployed to fund CCIP On-Ramps

Testing File Link - https://docs.google.com/spreadsheets/d/1zk4J4xQrhSJhIEt7l1bpsG6_jrl6qTQLNa5EZia3JzU/edit?gid=829494086#gid=829494086 Specification File - https://docs.google.com/document/d/1p4naJOlrdPmZ5xsZkZE7FDw1cEQqWcQ3hgguhI21SNQ/edit#heading=h.3t9vh460y192

Ticket

Requires Dependencies

Resolves Dependencies

Adding 2 files. 
1. I added a minPerform() function to the LinkBalMonV2 contract and tested it on Sepolia. The purpose of the minPerform function is to establish a minimum batch size required for the sampleUnderfunded address array. If the array size is less than minPerform, no top-up operation will be performed. This optimization is crucial for deploying the BalanceMonitor contract on Ethereum, which consumes significant gas. 

2. Creation of a CCIPOnRampWatchlistUpdate contract to allow auto update of the watchlist on the LinkBalMonV2 when deployed to fund CCIP On-Ramps

Testing File Link - https://docs.google.com/spreadsheets/d/1zk4J4xQrhSJhIEt7l1bpsG6_jrl6qTQLNa5EZia3JzU/edit?gid=829494086#gid=829494086
Specification File - https://docs.google.com/document/d/1p4naJOlrdPmZ5xsZkZE7FDw1cEQqWcQ3hgguhI21SNQ/edit#heading=h.3t9vh460y192
@poke1994 poke1994 requested a review from a team as a code owner June 18, 2024 13:22
Copy link
Contributor

I see you updated files related to contracts. Please run pnpm changeset in the contracts directory to add a changeset.

@poke1994 poke1994 changed the title Add files via upload LinkBalMonV2(minPerform) and CCIPWatchlist AutoUpdate Contract Jun 18, 2024
import {LinkAvailableBalanceMonitor} from "../upkeeps/LinkAvailableBalanceMonitor.sol";


struct Log {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you import this and ILogAutomation from the existing ILogAutomation.sol interface?

@@ -333,7 +337,8 @@ contract LinkAvailableBalanceMonitor is AccessControl, AutomationCompatibleInter
bytes calldata
) external view override whenNotPaused returns (bool upkeepNeeded, bytes memory performData) {
address[] memory needsFunding = sampleUnderfundedAddresses();
if (needsFunding.length == 0) {
uint16 minPerform = s_minPerform;
if (needsFunding.length <= minPerform) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it's probably more idiomatic to do <

@@ -333,7 +337,8 @@ contract LinkAvailableBalanceMonitor is AccessControl, AutomationCompatibleInter
bytes calldata
) external view override whenNotPaused returns (bool upkeepNeeded, bytes memory performData) {
address[] memory needsFunding = sampleUnderfundedAddresses();
if (needsFunding.length == 0) {
uint16 minPerform = s_minPerform;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to create a new variable unless it will be read again in this function

require(routerAddress != address(0), "Router address not set");

// Define the event signature for OnRampSet(uint64,address)
bytes32 eventSignature = keccak256(abi.encodePacked("OnRampSet(uint64,address)"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this event sig is known in advance, u can encode it and set it as a constant

function checkLog(
Log calldata log,
bytes memory checkData
) external view override returns (bool upkeepNeeded, bytes memory performData) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can try to run
pnpm prettier:write to format all the code


event setWatchlistOnMonitor(uint64 indexed _dstChainSelector,address indexed _onRamp);

LinkAvailableBalanceMonitor public LinkAvailableBalanceMonitorAddress;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: variable starts with lowercase and it should be called linkAvailableBalanceMonitor or monitor bc it's not an address anymore

@@ -389,6 +394,12 @@ contract LinkAvailableBalanceMonitor is AccessControl, AutomationCompatibleInter
s_maxPerform = maxPerform;
}

/// @notice Update s_minPerform
function setMinPerform(uint16 minPerform) public onlyRole(ADMIN_ROLE) {
emit MinPerformSet(s_minPerform, minPerform);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: emit after the variable is set

if (log.source == routerAddress && log.topics.length > 0 && log.topics[0] == eventSignature) {
// Extract the indexed parameter from the log
uint64 destChainSelector = uint64(uint256(log.topics[1])); // cast to uint64
address onRamp = address(uint160(uint256(bytes32(log.data)))); // extract from log.data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depending on the possible values of destChainSelector and onRamp, maybe add some sanity checks for these values?

@@ -389,6 +394,12 @@ contract LinkAvailableBalanceMonitor is AccessControl, AutomationCompatibleInter
s_maxPerform = maxPerform;
}

/// @notice Update s_minPerform
function setMinPerform(uint16 minPerform) public onlyRole(ADMIN_ROLE) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be external

@FelixFan1992 FelixFan1992 requested a review from RyanRHall June 19, 2024 15:01
Made changed as per Felix's comments
Copy link
Collaborator Author

@poke1994 poke1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made changes to CCIPAutoWatchlist contract and LinkAvailableBalanceMonitor contract

Copy link
Collaborator Author

@poke1994 poke1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made changes to LinkBalanceMonitorContract as suggested

@@ -6,89 +6,67 @@ import "../../shared/access/ConfirmedOwner.sol";
import {AutomationCompatibleInterface} from "../interfaces/AutomationCompatibleInterface.sol";
import {AccessControl} from "../../vendor/openzeppelin-solidity/v4.8.3/contracts/access/AccessControl.sol";
import {LinkAvailableBalanceMonitor} from "../upkeeps/LinkAvailableBalanceMonitor.sol";
import "../interfaces/ILogAutomation.sol";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's import specific struct / interface

Address comments to the updateWatchlist function of the code
Imported specific parts of ILogAutomation
@cl-sonarqube-production
Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Copy link
Contributor

@RyanRHall RyanRHall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but I can't sign off on these without unit tests! From your testing file it looks like you have a good understanding of what needs coverage, but those test cases need to manifest in code :)

@chainchad
Copy link
Collaborator

Going to close this for now as it seems to have gotten stale. Please re-open when ready.

@chainchad chainchad closed this Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants