|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +import {ErrorsLib} from "../../src/libraries/ErrorsLib.sol"; |
| 5 | + |
| 6 | +import {ERC20Wrapper} from "../helpers/mocks/ERC20WrapperMock.sol"; |
| 7 | + |
| 8 | +import "./helpers/ForkTest.sol"; |
| 9 | + |
| 10 | +/* WBIB01 INTERFACES */ |
| 11 | + |
| 12 | +error NonWhitelistedToAddress(address to); |
| 13 | + |
| 14 | +interface IWrappedBackedToken { |
| 15 | + function whitelistControllerAggregator() external view returns (address); |
| 16 | +} |
| 17 | + |
| 18 | +interface IWhitelistControllerAggregator { |
| 19 | + function isWhitelisted(address) external view returns (bool, address); |
| 20 | +} |
| 21 | + |
| 22 | +/* VER_USDC INTERFACES */ |
| 23 | + |
| 24 | +error NoPermission(address account); |
| 25 | + |
| 26 | +interface IPermissionedERC20Wrapper { |
| 27 | + function memberlist() external view returns (address); |
| 28 | +} |
| 29 | + |
| 30 | +interface IMemberList { |
| 31 | + function isMember(address) external view returns (bool); |
| 32 | +} |
| 33 | + |
| 34 | +/* TEST */ |
| 35 | + |
| 36 | +contract Erc20PermissionedWrappersForkTest is ForkTest { |
| 37 | + address internal immutable WBIB01 = getAddress("WBIB01"); |
| 38 | + address internal immutable VER_USDC = getAddress("VER_USDC"); |
| 39 | + |
| 40 | + function setUp() public override { |
| 41 | + super.setUp(); |
| 42 | + |
| 43 | + if (block.chainid == 1) { |
| 44 | + _whitelistForWbib01(address(generalAdapter1)); |
| 45 | + } else if (block.chainid == 8453) { |
| 46 | + _whitelistForVerUsdc(address(generalAdapter1)); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + function testWbib01NotUsableWithoutPermission(uint256 amount, address initiator) public onlyEthereum { |
| 51 | + vm.assume(initiator != address(0)); |
| 52 | + amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT); |
| 53 | + |
| 54 | + deal(address(ERC20Wrapper(WBIB01).underlying()), address(generalAdapter1), amount); |
| 55 | + |
| 56 | + bundle.push(_erc20WrapperDepositFor(address(WBIB01), amount)); |
| 57 | + |
| 58 | + vm.expectRevert(abi.encodeWithSelector(NonWhitelistedToAddress.selector, initiator)); |
| 59 | + vm.prank(initiator); |
| 60 | + bundler3.multicall(bundle); |
| 61 | + } |
| 62 | + |
| 63 | + function testWbibUsableWithPermission(uint256 amount, address initiator) public onlyEthereum { |
| 64 | + vm.assume(initiator != address(0)); |
| 65 | + _whitelistForWbib01(initiator); |
| 66 | + |
| 67 | + amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT); |
| 68 | + |
| 69 | + vm.prank(initiator); |
| 70 | + IERC20(WBIB01).approve(address(generalAdapter1), amount); |
| 71 | + |
| 72 | + deal(address(ERC20Wrapper(WBIB01).underlying()), address(generalAdapter1), amount, true); |
| 73 | + |
| 74 | + bundle.push(_erc20WrapperDepositFor(address(WBIB01), amount)); |
| 75 | + bundle.push(_erc20TransferFrom(address(WBIB01), address(generalAdapter1), amount)); |
| 76 | + |
| 77 | + vm.prank(initiator); |
| 78 | + bundler3.multicall(bundle); |
| 79 | + |
| 80 | + vm.assertGt(IERC20(WBIB01).balanceOf(address(generalAdapter1)), 0); |
| 81 | + } |
| 82 | + |
| 83 | + function testVerUsdcNotUsableWithoutPermission(uint256 amount, address initiator) public onlyBase { |
| 84 | + vm.assume(initiator != address(0)); |
| 85 | + amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT); |
| 86 | + |
| 87 | + deal(address(ERC20Wrapper(VER_USDC).underlying()), address(generalAdapter1), amount); |
| 88 | + |
| 89 | + bundle.push(_erc20WrapperDepositFor(address(VER_USDC), amount)); |
| 90 | + |
| 91 | + vm.expectRevert("PermissionedERC20Wrapper/no-attestation-found"); |
| 92 | + vm.prank(initiator); |
| 93 | + bundler3.multicall(bundle); |
| 94 | + } |
| 95 | + |
| 96 | + function testVerUsdcUsableWithPermission(uint256 amount, address initiator) public onlyBase { |
| 97 | + vm.assume(initiator != address(0)); |
| 98 | + _whitelistForVerUsdc(initiator); |
| 99 | + |
| 100 | + amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT); |
| 101 | + |
| 102 | + vm.prank(initiator); |
| 103 | + IERC20(VER_USDC).approve(address(generalAdapter1), amount); |
| 104 | + |
| 105 | + deal(address(ERC20Wrapper(VER_USDC).underlying()), address(generalAdapter1), amount, true); |
| 106 | + |
| 107 | + bundle.push(_erc20WrapperDepositFor(address(VER_USDC), amount)); |
| 108 | + bundle.push(_erc20TransferFrom(address(VER_USDC), address(generalAdapter1), amount)); |
| 109 | + |
| 110 | + vm.prank(initiator); |
| 111 | + bundler3.multicall(bundle); |
| 112 | + |
| 113 | + vm.assertGt(IERC20(VER_USDC).balanceOf(address(generalAdapter1)), 0); |
| 114 | + } |
| 115 | + |
| 116 | + /* WHITELISTING HELPERS */ |
| 117 | + |
| 118 | + function _whitelistForWbib01(address account) internal { |
| 119 | + address controller = IWrappedBackedToken(WBIB01).whitelistControllerAggregator(); |
| 120 | + vm.mockCall( |
| 121 | + controller, |
| 122 | + abi.encodeCall(IWhitelistControllerAggregator.isWhitelisted, (account)), |
| 123 | + abi.encode(true, address(0)) |
| 124 | + ); |
| 125 | + } |
| 126 | + |
| 127 | + function _whitelistForVerUsdc(address account) internal { |
| 128 | + address memberList = IPermissionedERC20Wrapper(VER_USDC).memberlist(); |
| 129 | + vm.mockCall(memberList, abi.encodeCall(IMemberList.isMember, (account)), abi.encode(true)); |
| 130 | + } |
| 131 | +} |
0 commit comments