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

Flex voting Atoken using scaled balance caching #21

Merged
merged 39 commits into from
Jan 4, 2023

Conversation

davidlaprade
Copy link
Contributor

@davidlaprade davidlaprade commented Dec 13, 2022

Fixes #8

More details about this approach and why I think it works can be found here #8 (comment)

@davidlaprade davidlaprade marked this pull request as draft December 13, 2022 21:54
@davidlaprade davidlaprade force-pushed the atoken-caching-approach-fixes-#8 branch from 1f8122d to aca43e4 Compare December 13, 2022 21:57
@davidlaprade davidlaprade force-pushed the atoken-caching-approach-fixes-#8 branch from 4cd8077 to 7efdd7b Compare December 15, 2022 17:23
@davidlaprade davidlaprade marked this pull request as ready for review December 15, 2022 19:46
Comment on lines 254 to 263
/// Note: this has been modified from Aave v3's AToken to call our custom
/// mintScaledWithCheckpoint function.
///
/// @inheritdoc IAToken
function mintToTreasury(uint256 amount, uint256 index) external override onlyPool {
if (amount == 0) {
return;
}
_mintScaledWithCheckpoint(address(POOL), _treasury, amount, index);
}
Copy link
Contributor Author

@davidlaprade davidlaprade Dec 15, 2022

Choose a reason for hiding this comment

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

As I'm reviewing this, I actually think we should not be checkpointing this function. It's called by the pool when someone calls mintToTreasury.

But mintToTreasury does not involve depositing any underlying tokens into Aave (even though it results in minting aTokens). So there should be no need to checkpoint anything. Adding checkpoints here would actually mess up our internal accounting.

Furthermore, the treasury (which is the address that we would be checkpointing for) is not an entity that can vote

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get what this mintToTreasury function is for? It's basically just AToken inflation by minting ATokens with no underlying assets involved? But it seems anyone can call Pool.mintToTreasury, so I must be missing something

Copy link
Member

Choose a reason for hiding this comment

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

Don't fully understand here either, but this code seems to indicate the treasury is earning some income, so perhaps minting to the treasury is just giving the treasury aTokens for the income it has already earned in the pool (fees?). If that's the case, checkpointing would be warranted, I believe.

https://github.com/aave/aave-v3-core/blob/f3e037b3638e3b7c98f0c09c56c5efde54f7c5d2/contracts/protocol/libraries/logic/PoolLogic.sol#L107

Copy link
Contributor Author

Choose a reason for hiding this comment

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

minting to the treasury is just giving the treasury aTokens for the income it has already earned in the pool (fees?). If that's the case, checkpointing would be warranted, I believe

I think that's right: it's minting aTokens to represent the treasury income, which are fees collected at various points, e.g. here and here.

Now that I think more about it, it probably does make sense to include this. We're snapshotting aToken balances now, not deposits. And, while the treasury won't have made any deposits, it will have an aToken balance because of this. If at some point Aave decides it wants to participate in governance with the aTokens it has earned as fees, it should be able to. Thanks for correcting me 👍

I should probably add a test for this functionality though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tested in ba4a946

Copy link
Contributor

Choose a reason for hiding this comment

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

@davidlaprade for posterity can you leave a comment here summarizing what mintToTreasury is for, when/who calls it, and whether we need to care about it? The commit linked above was rebased away and the most recent comments in this thread are "I think" style comments, e.g. from reading it I'm not certain if that's correct or outdated

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!

mintToTreasury captures/realizes protocol fees by issuing aTokens to the Aave treasury address.

The function is public, so it can be called by anyone. Ernesto from Aave told us in Telegram that it's called by "somebody in the community I think".

We do need to care about it, for the reason @apbendi stated. ATokens are being issued and the underlying asset could potentially be withdrawn (and used for voting). For consistency, therefore, we should checkpoint when it happens and accord the appropriate voting weight to the Treasury -- even if we think it will never express a voting preference.

We do support this function now, and are checkpointing when it is called, as seen by the test added in ba4a946

src/ATokenCheckpointed.sol Outdated Show resolved Hide resolved
src/ATokenCheckpointed.sol Outdated Show resolved Hide resolved
test/MockATokenCheckpointed.sol Outdated Show resolved Hide resolved
test/ATokenCheckpointed.t.sol Outdated Show resolved Hide resolved
test/ATokenCheckpointed.t.sol Outdated Show resolved Hide resolved
test/ATokenCheckpointed.t.sol Outdated Show resolved Hide resolved
test/ATokenCheckpointed.t.sol Outdated Show resolved Hide resolved
test/ATokenCheckpointed.t.sol Outdated Show resolved Hide resolved
test/ATokenCheckpointed.t.sol Outdated Show resolved Hide resolved
test/ATokenCheckpointed.t.sol Outdated Show resolved Hide resolved
Copy link
Contributor

@wildmolasses wildmolasses left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @davidlaprade !

src/ATokenCheckpointed.sol Outdated Show resolved Hide resolved
src/ATokenCheckpointed.sol Outdated Show resolved Hide resolved
src/ATokenCheckpointed.sol Outdated Show resolved Hide resolved
Comment on lines 296 to 299
// Begin modifications.
_checkpointRawBalanceOf(_msgSender());
_checkpointRawBalanceOf(recipient);
// End modifications.
Copy link
Contributor

Choose a reason for hiding this comment

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

^^ the internal _transfer instead

agreed

it seems like there are quite a few internal _transfers! We should be sure to override the right one (aka should checkpoint on both AToken:_transfer fns, the one with a validate bool and the one without)

src/ATokenCheckpointed.sol Outdated Show resolved Hide resolved
Copy link
Member

@apbendi apbendi left a comment

Choose a reason for hiding this comment

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

Looks great @davidlaprade, left some additional comments. Mostly minor!

Comment on lines 254 to 263
/// Note: this has been modified from Aave v3's AToken to call our custom
/// mintScaledWithCheckpoint function.
///
/// @inheritdoc IAToken
function mintToTreasury(uint256 amount, uint256 index) external override onlyPool {
if (amount == 0) {
return;
}
_mintScaledWithCheckpoint(address(POOL), _treasury, amount, index);
}
Copy link
Member

Choose a reason for hiding this comment

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

Don't fully understand here either, but this code seems to indicate the treasury is earning some income, so perhaps minting to the treasury is just giving the treasury aTokens for the income it has already earned in the pool (fees?). If that's the case, checkpointing would be warranted, I believe.

https://github.com/aave/aave-v3-core/blob/f3e037b3638e3b7c98f0c09c56c5efde54f7c5d2/contracts/protocol/libraries/logic/PoolLogic.sol#L107

src/ATokenCheckpointed.sol Outdated Show resolved Hide resolved
src/ATokenCheckpointed.sol Outdated Show resolved Hide resolved
src/ATokenCheckpointed.sol Outdated Show resolved Hide resolved
src/ATokenCheckpointed.sol Outdated Show resolved Hide resolved
src/ATokenCheckpointed.sol Outdated Show resolved Hide resolved
src/ATokenCheckpointed.sol Outdated Show resolved Hide resolved
@davidlaprade davidlaprade force-pushed the atoken-caching-approach-fixes-#8 branch from edb5661 to d092fb7 Compare December 23, 2022 19:02
@davidlaprade davidlaprade force-pushed the atoken-caching-approach-fixes-#8 branch from b7f9625 to f92e600 Compare December 23, 2022 19:09
@davidlaprade davidlaprade force-pushed the atoken-caching-approach-fixes-#8 branch from ba4a946 to f353412 Compare December 23, 2022 20:42
src/ATokenFlexVoting.sol Show resolved Hide resolved
test/MockATokenFlexVoting.sol Show resolved Hide resolved
test/MockATokenFlexVoting.sol Outdated Show resolved Hide resolved
Copy link
Contributor

@wildmolasses wildmolasses left a comment

Choose a reason for hiding this comment

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

a couple questions.

side note, i have not yet audited the tests thoroughly. happy to do so, but didn't want to block this review.

src/ATokenFlexVoting.sol Show resolved Hide resolved
test/ATokenFlexVotingFork.t.sol Show resolved Hide resolved
test/ATokenFlexVotingFork.t.sol Show resolved Hide resolved
test/ATokenFlexVotingFork.t.sol Show resolved Hide resolved
Copy link
Member

@apbendi apbendi left a comment

Choose a reason for hiding this comment

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

Looks good to me @davidlaprade. Nice work on this 💪

Copy link
Contributor

@wildmolasses wildmolasses left a comment

Choose a reason for hiding this comment

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

lgtm!

@davidlaprade davidlaprade requested a review from mds1 January 4, 2023 16:44
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.

Caching Approach for AToken Snapshotting
4 participants