-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
AUTO-9179: settle NOPs LINK payment offchain #12469
Conversation
I see that you haven't updated any README files. Would it make sense to do so? |
Go solidity wrappers are out-of-date, regenerate them via the |
uint256[] memory balances = new uint256[](length); | ||
for (uint256 i = 0; i < length; i++) { | ||
address transmitterAddr = s_transmittersList[i]; | ||
uint96 balance = _updateTransmitterBalanceFromPool(transmitterAddr, s_hotVars.totalPremium, uint96(length)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RyanRHall do we need to update the reserve account like
s_reserveAmounts[address(i_link)] = s_reserveAmounts[address(i_link)] - balance;
?
i assume no bc using offchain settlement means there is no LINK liquidity in service chain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow I had to think about this for a long time. I think it depends on whether LINK payments are enabled or not.
If LINK payments are disabled (most likely scenario) then we expect s_reserveAmounts[LINK] == 0
, and so if we try to subtract balance
, it will underflow and revert (not good!) In this scenario, we don't want to touch reserve amounts, it should just stay at 0.
But there is technically nothing stopping us from configuring a registry with LINK payments enabled and settlement mode set to offchain. In this scenario we would want to decrease the s_reserveAmounts
, but only by the amount of LINK spent by upkeeps with LINK configured as the payment method, and we don't currently track this value. This is a super awkward configuration, and I would be in inclined to disable it all-together.
I think we should do the following:
- don't touch
reserveAmounts[LINK]
insettleNOPsOffchain()
- add a check in
setConfig()
that if abillinkToken == LINK
, thenrequire(s_payoutMode == PayoutMode.ON_CHAIN)
. This should prevent the awkward configuration I mentioned above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great @FelixFan1992
@@ -428,6 +436,7 @@ abstract contract AutomationRegistryBase2_3 is ConfirmedOwner { | |||
event FundsAdded(uint256 indexed id, address indexed from, uint96 amount); | |||
event FundsWithdrawn(uint256 indexed id, uint256 amount, address to); | |||
event InsufficientFundsUpkeepReport(uint256 indexed id, bytes trigger); | |||
event NOPsSettledOffchain(address[] transmitters, uint256[] balances); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please confirm with @wentzeld that this event has all the information we need. I believe a request was made to separate balances
into premium
and gasFees
etc.
contracts/src/v0.8/automation/dev/v2_3/AutomationRegistryLogicB2_3.sol
Outdated
Show resolved
Hide resolved
s_transmitters[transmitterAddr].balance = 0; | ||
} | ||
|
||
emit NOPsSettledOffchain(s_transmittersList, balances); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably want to emit payees
here instead of transmitters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this bc a transmitter can use a payee which is different than transmitter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
payee is an address which has the privilege to call withdrawPayment
for a transmitter. so yes they are different.
uint256[] memory balances = new uint256[](length); | ||
for (uint256 i = 0; i < length; i++) { | ||
address transmitterAddr = s_transmittersList[i]; | ||
uint96 balance = _updateTransmitterBalanceFromPool(transmitterAddr, s_hotVars.totalPremium, uint96(length)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow I had to think about this for a long time. I think it depends on whether LINK payments are enabled or not.
If LINK payments are disabled (most likely scenario) then we expect s_reserveAmounts[LINK] == 0
, and so if we try to subtract balance
, it will underflow and revert (not good!) In this scenario, we don't want to touch reserve amounts, it should just stay at 0.
But there is technically nothing stopping us from configuring a registry with LINK payments enabled and settlement mode set to offchain. In this scenario we would want to decrease the s_reserveAmounts
, but only by the amount of LINK spent by upkeeps with LINK configured as the payment method, and we don't currently track this value. This is a super awkward configuration, and I would be in inclined to disable it all-together.
I think we should do the following:
- don't touch
reserveAmounts[LINK]
insettleNOPsOffchain()
- add a check in
setConfig()
that if abillinkToken == LINK
, thenrequire(s_payoutMode == PayoutMode.ON_CHAIN)
. This should prevent the awkward configuration I mentioned above.
contracts/src/v0.8/automation/dev/v2_3/AutomationRegistryLogicB2_3.sol
Outdated
Show resolved
Hide resolved
contracts/src/v0.8/automation/dev/test/AutomationRegistry2_3.t.sol
Outdated
Show resolved
Hide resolved
contracts/src/v0.8/automation/dev/test/AutomationRegistry2_3.t.sol
Outdated
Show resolved
Hide resolved
contracts/src/v0.8/automation/dev/test/AutomationRegistry2_3.t.sol
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
contracts/src/v0.8/automation/dev/test/AutomationRegistry2_3.t.sol
Outdated
Show resolved
Hide resolved
@@ -473,6 +474,37 @@ contract AutomationRegistry2_3_SetConfig is AutomationRegistry2_3_SetUp { | |||
); | |||
} | |||
|
|||
function testSetConfigRevertDueToInvalidBillingToken() public { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, setConfig reverts bc the payout mode is offchain, and LINK is not allowed to use. It took me a bit to understand the definition of invalid here.
contracts/src/v0.8/automation/dev/test/AutomationRegistry2_3.t.sol
Outdated
Show resolved
Hide resolved
contracts/src/v0.8/automation/dev/test/AutomationRegistry2_3.t.sol
Outdated
Show resolved
Hide resolved
s_transmitters[transmitterAddr].balance = 0; | ||
} | ||
|
||
emit NOPsSettledOffchain(s_transmittersList, balances); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this bc a transmitter can use a payee which is different than transmitter?
I see you updated files related to |
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks 🔥🔥 🔥 I only have nitpicks
uint256 a = 1234; | ||
address b = ZERO_ADDRESS; | ||
bytes memory offchainConfigBytes = abi.encode(a, b); | ||
bytes memory offchainConfigBytes = abi.encode(1234, ZERO_ADDRESS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick, but all these offchainConfigBytes
don't really do anything yeah? Maybe we could clean up a step further just leave them blank as ""
in setConfigTypeSafe()
uint256[] internal upkeepIds; | ||
uint256[] internal gasLimits; | ||
bytes[] internal performDatas; | ||
uint256[] internal balances; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick, but it looks like these are only used within the NOPsSettlement
test - I think we can move them to that contract instead of making them global across all tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, it looks like they're only used in one test yeah? Can we just move them to that one test?
if (address(token) == address(i_link) && s_payoutMode == PayoutMode.OFF_CHAIN) { | ||
revert InvalidBillingToken(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, we started reading the state vars in the loop partly to avoid stack to deep errors, right? Could we add a @dev
comment explaining that so that people don't think we're lazy lolol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have some nitpicks, but we can address later
No description provided.