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

support billing config #12310

Merged
merged 2 commits into from
Mar 8, 2024
Merged

support billing config #12310

merged 2 commits into from
Mar 8, 2024

Conversation

shileiwill
Copy link
Contributor

AUTO-9111

This is a copy of this PR. Some great comments from Ryan are from the old PR, but unfortunately I messed up that PR when rebasing.

All comments should have been addressed except this one pending confirmation: #12295 (comment)

Copy link
Contributor

github-actions bot commented Mar 6, 2024

I see that you haven't updated any README files. Would it make sense to do so?

Copy link
Contributor

github-actions bot commented Mar 6, 2024

Go solidity wrappers are out-of-date, regenerate them via the make wrappers-all command

uint96 oldLength = uint96(s_transmittersList.length);
for (uint256 i = 0; i < oldLength; i++) {
_updateTransmitterBalanceFromPool(s_transmittersList[i], totalPremium, oldLength);
for (uint256 i = 0; i < s_transmittersList.length; i++) {
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 access .length so many times?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good Q, removed the oldLength variable to avoid stack too deep. confirmed with Ryan, a bit more gas is not a concern in this non-transmit path.

Copy link
Contributor

github-actions bot commented Mar 6, 2024

Go solidity wrappers are out-of-date, regenerate them via the make wrappers-all command

1 similar comment
Copy link
Contributor

github-actions bot commented Mar 6, 2024

Go solidity wrappers are out-of-date, regenerate them via the make wrappers-all command

@@ -155,6 +158,7 @@ abstract contract AutomationRegistryBase2_3 is ConfirmedOwner {
error UpkeepNotCanceled();
error UpkeepNotNeeded();
error ValueNotChanged();
error ZeroAddressNotAllowed();
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 for generic / reusable errors

@@ -677,7 +693,7 @@ abstract contract AutomationRegistryBase2_3 is ConfirmedOwner {
function _updateTransmitterBalanceFromPool(
address transmitterAddress,
uint96 totalPremium,
uint96 payeeCount
uint96 payeeCount // TODO: why payeeCount is of type uint96?
Copy link
Contributor

Choose a reason for hiding this comment

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

meh I don't love it but let's not fix what's not broken eh? I think remove the comment and we can save this for a future version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

created https://smartcontract-it.atlassian.net/browse/AUTO-9235 and added to Misc Contract 2.2+.

Comment on lines 994 to 995
if (s_billingConfigs[token].priceFeed == address(0)) {
s_billingTokens.push(token);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can we have an else { revert DuplicateEntry() } here?

Copy link
Contributor

Choose a reason for hiding this comment

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

or maybe simpler...

if (s_billingConfigs[token].priceFeed != address(0)) {
  revert DuplicateEntry();
}
s_billingTokens.push(token);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, we will not swallow the duplicate entries, we will revert!

* @notice the billing config of a token
*/
struct BillingConfig {
bool active;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can get rid of this field! I don't forsee it being necessary.

Comment on lines 107 to 108
mapping(address billingToken => BillingConfig billingConfig) internal s_billingConfigs; // billing configurations for different tokens
address[] internal s_billingTokens; // list of billing tokens
Copy link
Contributor

Choose a reason for hiding this comment

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

one more comment - can we make these IERC20s instead of addresss? you can get that from vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, that makes more sense. I guess we should use IERC20 for both the mapping and the list

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah pretty much everywhere - including in the functions like getBillingConfig() and setConfig(), etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the underlying data structures and associated APIs. I didnt touch the setConfigTypeSafe signature tho, let me know if you think that need to use IERC20 as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I think make that IERC20 also!

Copy link
Contributor

github-actions bot commented Mar 7, 2024

Go solidity wrappers are out-of-date, regenerate them via the make wrappers-all command

@@ -483,6 +497,8 @@ abstract contract AutomationRegistryBase2_3 is ConfirmedOwner {
event UpkeepTriggerConfigSet(uint256 indexed id, bytes triggerConfig);
event UpkeepUnpaused(uint256 indexed id);
event Unpaused(address account);
// Event to emit when a billing configuration is set
event BillingConfigSet(IERC20 indexed token, BillingConfig config);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

* @param billingTokens the addresses of tokens
* @param billingConfigs the configs for tokens
*/
function _setBillingConfig(address[] memory billingTokens, BillingConfig[] memory billingConfigs) internal {
Copy link
Contributor

Choose a reason for hiding this comment

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

change to IERC20[]

delete s_billingTokens;

for (uint256 i = 0; i < billingTokens.length; i++) {
IERC20 token = IERC20(billingTokens[i]);
Copy link
Contributor

Choose a reason for hiding this comment

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

then we can delete this line :)

@@ -266,23 +273,30 @@ contract AutomationRegistry2_3 is AutomationRegistryBase2_3, OCR2Abstract, Chain
uint8 f,
OnchainConfig memory onchainConfig,
uint64 offchainConfigVersion,
bytes memory offchainConfig
bytes memory offchainConfig,
address[] memory billingTokens,
Copy link
Contributor

Choose a reason for hiding this comment

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

IERC20[]

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.

unit tests are 🔥 very thorough!

@cl-sonarqube-production
Copy link

@shileiwill shileiwill requested a review from RyanRHall March 7, 2024 20:38
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.

LGTM!

@RyanRHall RyanRHall added this pull request to the merge queue Mar 8, 2024
Merged via the queue into develop with commit f42894a Mar 8, 2024
109 checks passed
@RyanRHall RyanRHall deleted the AUTO-9111-new2 branch March 8, 2024 14:55
ogtownsend pushed a commit that referenced this pull request Mar 14, 2024
* support billing config

* use IERC20
kidambisrinivas pushed a commit that referenced this pull request Mar 27, 2024
* support billing config

* use IERC20
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.

3 participants