If a sponsor accidentally sends the wrong tokens to the proxy, they can be recovered using distributeByOwner after the expiration time. However, in this process, a 5% commission fee is also paid to the stadium address.
function testCommissionFeeIsPayedUponRecovery() public {
vm.startPrank(tokenMinter);
MockERC20(jpycv1Address).mint(user2, 100_000 ether);
vm.stopPrank();
vm.startPrank(factoryAdmin);
bytes32 randomId = keccak256(abi.encode("Jason", "001"));
proxyFactory.setContest(organizer, randomId, block.timestamp + 8 days, address(distributor));
vm.stopPrank();
bytes32 salt = keccak256(abi.encode(organizer, randomId, address(distributor)));
address proxyAddress = proxyFactory.getProxyAddress(salt, address(distributor));
vm.startPrank(sponsor);
MockERC20(jpycv2Address).transfer(proxyAddress, 10000 ether);
vm.stopPrank();
vm.startPrank(user2);
MockERC20(jpycv1Address).transfer(proxyAddress, 10000 ether);
vm.stopPrank();
assertEq(MockERC20(jpycv2Address).balanceOf(user1), 0);
bytes memory data = createData();
vm.warp(9 days);
vm.startPrank(organizer);
address proxy = proxyFactory.deployProxyAndDistribute(randomId, address(distributor), data);
vm.stopPrank();
address[] memory tokens_ = new address[](1);
tokens_[0] = jpycv1Address;
address[] memory winners = new address[](1);
winners[0] = user2;
uint256[] memory percentages_ = new uint256[](1);
percentages_[0] = 9500;
bytes memory dataRecover = abi.encodeWithSelector(Distributor.distribute.selector, jpycv1Address, winners, percentages_, "");
vm.warp(16 days);
vm.startPrank(factoryAdmin);
proxyFactory.distributeByOwner(
proxy, organizer, randomId, address(distributor), dataRecover
);
vm.stopPrank();
assertEq(MockERC20(jpycv2Address).balanceOf(user1), 9500 ether);
}
function recover(address token, address receiver, uint256 amount) external {
if (msg.sender != FACTORY_ADDRESS) {
revert Distributor__OnlyFactoryAddressIsAllowed();
}
if (token == address(0)) revert Distributor__NoZeroAddress();
if (!_isWhiteListed(token)) {
revert Distributor__InvalidTokenAddress();
}
if(IERC20(token).balanceOf(address(this)) < amount) revert Distributor__TooFewTokens();
IERC20(token).safeTransfer(receiver, amount);
}
Make sure that the organizer cannot call this function.