-
Notifications
You must be signed in to change notification settings - Fork 18
restrict depositFor to initiator #233
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b32f634
fix: restrict depositFor
adhusson a92c39b
chore: fmt
adhusson abcf39a
chore: change alchemy key
MathisGD 84d9c02
fix test
adhusson 06abc62
test: add verUsdc test
adhusson 0fea847
Update src/adapters/GeneralAdapter1.sol
MathisGD 9bf084c
docs: document the change
MathisGD 3533c79
Update test/fork/ERC20PermissionedWrappersForkTest.sol
adhusson ab2cad5
Update test/fork/ERC20PermissionedWrappersForkTest.sol
adhusson 239e65f
Update src/adapters/GeneralAdapter1.sol
adhusson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import {ErrorsLib} from "../../src/libraries/ErrorsLib.sol"; | ||
|
|
||
| import {ERC20Wrapper} from "../helpers/mocks/ERC20WrapperMock.sol"; | ||
|
|
||
| import "./helpers/ForkTest.sol"; | ||
|
|
||
| /* WBIB01 INTERFACES */ | ||
|
|
||
| error NonWhitelistedToAddress(address to); | ||
|
|
||
| interface IWrappedBackedToken { | ||
| function whitelistControllerAggregator() external view returns (address); | ||
| } | ||
|
|
||
| interface IWhitelistControllerAggregator { | ||
| function isWhitelisted(address) external view returns (bool, address); | ||
| } | ||
|
|
||
| /* VER_USDC INTERFACES */ | ||
|
|
||
| error NoPermission(address account); | ||
|
|
||
| interface IPermissionedERC20Wrapper { | ||
| function memberlist() external view returns (address); | ||
| } | ||
|
|
||
| interface IMemberList { | ||
| function isMember(address) external view returns (bool); | ||
| } | ||
|
|
||
| /* TEST */ | ||
|
|
||
| contract Erc20PermissionedWrappersForkTest is ForkTest { | ||
| address internal immutable WBIB01 = getAddress("WBIB01"); | ||
| address internal immutable VER_USDC = getAddress("VER_USDC"); | ||
|
|
||
| function setUp() public override { | ||
| super.setUp(); | ||
|
|
||
| if (block.chainid == 1) { | ||
| _whitelistForWbib01(address(generalAdapter1)); | ||
| } else if (block.chainid == 8453) { | ||
| console.log("VEr", VER_USDC); | ||
| console.log("VEr", VER_USDC.code.length); | ||
adhusson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _whitelistForVerUsdc(address(generalAdapter1)); | ||
| } | ||
| } | ||
|
|
||
| function testWbib01NotUsableWithoutPermission(uint256 amount, address initiator) public onlyEthereum { | ||
| vm.assume(initiator != address(0)); | ||
| amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT); | ||
|
|
||
| deal(address(ERC20Wrapper(WBIB01).underlying()), address(generalAdapter1), amount); | ||
|
|
||
| bundle.push(_erc20WrapperDepositFor(address(WBIB01), amount)); | ||
|
|
||
| vm.expectRevert(abi.encodeWithSelector(NonWhitelistedToAddress.selector, initiator)); | ||
| vm.prank(initiator); | ||
| bundler3.multicall(bundle); | ||
| } | ||
|
|
||
| function testWbibUsableWithPermission(uint256 amount, address initiator) public onlyEthereum { | ||
| vm.assume(initiator != address(0)); | ||
| _whitelistForWbib01(initiator); | ||
|
|
||
| amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT); | ||
|
|
||
| vm.prank(initiator); | ||
| IERC20(WBIB01).approve(address(generalAdapter1), amount); | ||
|
|
||
| deal(address(ERC20Wrapper(WBIB01).underlying()), address(generalAdapter1), amount, true); | ||
|
|
||
| bundle.push(_erc20WrapperDepositFor(address(WBIB01), amount)); | ||
| bundle.push(_erc20TransferFrom(address(WBIB01), address(generalAdapter1), amount)); | ||
|
|
||
| vm.prank(initiator); | ||
| bundler3.multicall(bundle); | ||
|
|
||
| vm.assertGt(IERC20(WBIB01).balanceOf(address(generalAdapter1)), 0); | ||
| } | ||
|
|
||
| function testVerUsdcNotUsableWithoutPermission(uint256 amount, address initiator) public onlyBase { | ||
| vm.assume(initiator != address(0)); | ||
| amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT); | ||
|
|
||
| deal(address(ERC20Wrapper(VER_USDC).underlying()), address(generalAdapter1), amount); | ||
|
|
||
| bundle.push(_erc20WrapperDepositFor(address(VER_USDC), amount)); | ||
|
|
||
| // vm.expectRevert(abi.encodeWithSelector(NoPermission.selector, initiator)); | ||
adhusson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| vm.expectRevert("PermissionedERC20Wrapper/no-attestation-found"); | ||
| vm.prank(initiator); | ||
| bundler3.multicall(bundle); | ||
| } | ||
|
|
||
| function testVerUsdcUsableWithPermission(uint256 amount, address initiator) public onlyBase { | ||
| vm.assume(initiator != address(0)); | ||
| _whitelistForVerUsdc(initiator); | ||
|
|
||
| amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT); | ||
|
|
||
| vm.prank(initiator); | ||
| IERC20(VER_USDC).approve(address(generalAdapter1), amount); | ||
|
|
||
| deal(address(ERC20Wrapper(VER_USDC).underlying()), address(generalAdapter1), amount, true); | ||
|
|
||
| bundle.push(_erc20WrapperDepositFor(address(VER_USDC), amount)); | ||
| bundle.push(_erc20TransferFrom(address(VER_USDC), address(generalAdapter1), amount)); | ||
|
|
||
| vm.prank(initiator); | ||
| bundler3.multicall(bundle); | ||
|
|
||
| vm.assertGt(IERC20(VER_USDC).balanceOf(address(generalAdapter1)), 0); | ||
| } | ||
|
|
||
| /* WHITELISTING HELPERS */ | ||
|
|
||
| function _whitelistForWbib01(address account) internal { | ||
| address controller = IWrappedBackedToken(WBIB01).whitelistControllerAggregator(); | ||
| vm.mockCall( | ||
| controller, | ||
| abi.encodeCall(IWhitelistControllerAggregator.isWhitelisted, (account)), | ||
| abi.encode(true, address(0)) | ||
| ); | ||
| } | ||
|
|
||
| function _whitelistForVerUsdc(address account) internal { | ||
| address memberList = IPermissionedERC20Wrapper(VER_USDC).memberlist(); | ||
| vm.mockCall(memberList, abi.encodeCall(IMemberList.isMember, (account)), abi.encode(true)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.