-
Notifications
You must be signed in to change notification settings - Fork 586
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
Fix event emission of AToken and DebtToken events #682
Conversation
Closes #681 |
contracts/protocol/tokenization/base/ScaledBalanceTokenBase.sol
Outdated
Show resolved
Hide resolved
* @param newRate The rate of the debt after the minting | ||
* @param avgStableRate The next average stable rate after the minting | ||
* @param newTotalSupply The next total supply of the stable debt token after the action | ||
**/ | ||
event Mint( | ||
address indexed user, | ||
address indexed onBehalfOf, | ||
uint256 amount, | ||
uint256 value, |
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.
Changing this parameter name will likely break the subgraph
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.
The subgraph will need to differentiate pre and post patch versions
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.
This doesn't seem reasonable only due to a name change. Unless the subgraph breaks anyway or there is some major reason
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.
The subgraph will need to differentiate either way. However, this change will affect the subgraph logic so It may be interesting to revert it back. Thoughts @defispartan ?
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.
Last month we implemented a fix for the current V3 subgraphs, so now these subgraphs correctly handle mint and burn events. With this change we would need to add versioning throughout each V3 subgraph to say:
if(blockNumber > ...){
// use updated mint/burn logic
// use updated naming: event.params.value
} else {
// use current mint/burn logic
// use current naming: event.params.amount
}
Since we have a working version already and handling this would be quite ugly, I would be in favor of reverting the event change
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.
Makes sense to me. Reverting the change in order to make the subgraph's logic less painful
) internal { | ||
uint256 senderScaledBalance = super.balanceOf(sender); | ||
uint256 senderBalanceIncrease = senderScaledBalance.rayMul(index) - | ||
senderScaledBalance.rayMul(_userState[sender].additionalData); |
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.
@miguelmtzinf Given that this code operates on _userState[sender]
(or recipient) after and being 1 slot packed with additionalData
, is not more gas-efficient to do a
UserState memory senderState = _userState[sender];
and then just operate with the fields in memory?
Unless the compiler takes this into account already
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.
Not worth to do what you suggest because we need to update storage sender/recipient 's state later on
uint256 index | ||
) internal { | ||
uint256 senderScaledBalance = super.balanceOf(sender); | ||
uint256 senderBalanceIncrease = senderScaledBalance.rayMul(index) - |
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.
Probably better to simplify the operation to only do 1 rayMul
, no?
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.
Agree, but we are using this approach on other parts throughout the code
How is the gas impact of this @miguelmtzinf ? |
There is a slight increase up to 5k gas units. Here you can see the diff: |
|
||
if (validate) { | ||
POOL.finalizeTransfer(underlyingAsset, from, to, amount, fromBalanceBefore, toBalanceBefore); | ||
} | ||
|
||
emit BalanceTransfer(from, to, amount, index); | ||
emit BalanceTransfer(from, to, amount.rayDiv(index), index); |
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.
Would it be possible to add amount
as another field to this event? It won't be used for anything, but this way the subgraph can differentiate which logic to use based on a different event signature.
The alternative is that we'd need to store the exact block that each market was updated to 3.0.1, and decide which logic to use based on the market and blockNumber.
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.
It does not make much sense to add another param if its not needed tbh.
Are not we using blockNumber already to differentiate? I think there is no other way
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.
No, there's nowhere else in the subgraphs where events need to be differentiated between contract versions using block number. It's extremely ugly, and prone to errors if tokens have events in this same block as the update, or if not all tokens are updated in the exact same block
BalanceTransfer
eventTransfer
eventMint
events in thetransfer
function to reflect interest accrualsnatspec
docs of events and functionsAToken
andDebtToken
events