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

Fix event emission of AToken and DebtToken events #682

Merged
merged 19 commits into from
Nov 15, 2022

Conversation

miguelmtzinf
Copy link
Contributor

@miguelmtzinf miguelmtzinf commented Jun 2, 2022

  • Fix emission of scaled balance in BalanceTransfer event
  • Fix emission of whole amounts in Transfer event
  • Add emission of Mint events in the transfer function to reflect interest accruals
  • Clarify natspec docs of events and functions
  • Add multiple test cases for AToken and DebtToken events

@miguelmtzinf
Copy link
Contributor Author

Closes #681

* @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,
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Collaborator

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

Copy link
Contributor Author

@miguelmtzinf miguelmtzinf Nov 2, 2022

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 ?

Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Collaborator

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

Copy link
Contributor Author

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) -
Copy link
Collaborator

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?

Copy link
Contributor Author

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

@eboadom
Copy link
Collaborator

eboadom commented Nov 15, 2022

How is the gas impact of this @miguelmtzinf ?

@miguelmtzinf
Copy link
Contributor Author

miguelmtzinf commented Nov 15, 2022

How is the gas impact of this @miguelmtzinf ?

There is a slight increase up to 5k gas units. Here you can see the diff:
https://editor.mergely.com/i0TdBTPn/

@miguelmtzinf miguelmtzinf merged commit ab07a4e into feat/3.0.1 Nov 15, 2022
@miguelmtzinf miguelmtzinf deleted the fix/681-atoken-events branch November 15, 2022 16:36
@eboadom eboadom mentioned this pull request Nov 16, 2022

if (validate) {
POOL.finalizeTransfer(underlyingAsset, from, to, amount, fromBalanceBefore, toBalanceBefore);
}

emit BalanceTransfer(from, to, amount, index);
emit BalanceTransfer(from, to, amount.rayDiv(index), index);
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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

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