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

add erc20 and erc721 deposit function to the Vault #53

Merged
merged 2 commits into from
Mar 4, 2024

Conversation

0xb337r007
Copy link
Collaborator

@0xb337r007 0xb337r007 commented Feb 26, 2024

Description

closes #31

Added 2 functions to deposit erc20 and erc721 tokens and register erc20 balances and erc721 ids.

Checklist

Ensure you completed all of the steps below before submitting your pull request:

  • Added natspec comments?
  • Ran forge snapshot?
  • Ran pnpm lint?
  • Ran forge test?
  • Ran pnpm verify?

@0xb337r007 0xb337r007 marked this pull request as draft February 26, 2024 10:07
@0x-r4bbit
Copy link
Member

@0xb337r007 this is still marked as a WIP, do you want us to wait until the ERC721 changes land here as well?

@0xb337r007 0xb337r007 marked this pull request as ready for review March 1, 2024 11:03
Copy link
Member

@0x-r4bbit 0x-r4bbit left a comment

Choose a reason for hiding this comment

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

Great work @0xb337r007

I have some minor comments. And I believe there's 1-2 tests missing.

error CommunityVault_ERC721TokenNotDeposited();

mapping(address => uint256) public erc20TokenBalances;
mapping(address => EnumerableSet.UintSet) private erc721TokenIds;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
mapping(address => EnumerableSet.UintSet) private erc721TokenIds;
mapping(address owners => EnumerableSet.UintSet balances) private erc721TokenIds;

Just cosmetics, but I think we can use named mapping annotation here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we need to upgrade to a newer version of the compiler to do it, shall we do it in another PR?
in this case instead of owners should be tokens

Copy link
Member

Choose a reason for hiding this comment

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

Yes that can be done in a different PR. Good point.

bool added = erc721TokenIds[token].add(tokenIds[i]);
if (!added) {
revert CommunityVault_ERC721TokenAlreadyDeposited();
}
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we perform this check before we even try to transfer it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good idea, I moved it

* to indicate the contract implements `onERC721Received` as per ERC721.
*/
function onERC721Received(address, address, uint256, bytes calldata) public pure override returns (bytes4) {
return this.onERC721Received.selector;
Copy link
Member

Choose a reason for hiding this comment

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

I think here we still need to check if:

a) the received ERC721 doesn't already exist in the set and
b) do a) only if we know for sure that this onReceived event wasn't triggered from a previous depositERC721() call

Thoughts @0xb337r007 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I completely skipped the check here on purpose to support only the deposit function. otherwise we might have strange scenarios in case we call deposit with a token that doesn't call the onERC721Received

Copy link
Member

Choose a reason for hiding this comment

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

Hm.. okay maybe we can revisit this in the future.
I might be missing something here, but if such a token would not call onERC721Received it's perfectly fine no? We still track via depositERC721. I'd even consider this one of the "simpler" cases as it'd just be as if onERC721Received didn't exist.

For now we can leave it like this, but I still think we should consider supporting both unless there's good reasons not to.

vm.stopPrank();

assertEq(erc721Token.balanceOf(address(vault)), initialVaultBalance + 2);
assertEq(vault.erc721TokenBalances(address(erc721Token)), initialTokenBalanceValue + 2);
Copy link
Member

Choose a reason for hiding this comment

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

I think we need some tests for the error cases of depositERC721 here

Copy link
Member

@0x-r4bbit 0x-r4bbit left a comment

Choose a reason for hiding this comment

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

Nice work @0xb337r007 !

@0xb337r007 0xb337r007 changed the title add erc20 deposit function to the Vault add erc20 and erc721 deposit function to the Vault Mar 4, 2024
@0xb337r007 0xb337r007 mentioned this pull request Mar 4, 2024
5 tasks
@0x-r4bbit 0x-r4bbit merged commit 34219eb into main Mar 4, 2024
7 checks passed
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.

Allow for community vaults to keep track of deposited tokens
2 participants