0

I found a very useful idea compared to the traditional deposit method on exchanges.

Using this method, not only does it not need to manage secret keys, any account can perform token collection, but it also costs less gas. But selfdestruct must be used, otherwise the gas fee will increase 3-4 times. (Of course, if contracts are reused, it will be cheaper.)

contract Imputation {
    address immutable public owner=msg.sender;
    function getwalletadd(uint256 path)public view returns(address walletadd){
        unchecked{
            bytes32 salt = keccak256(abi.encodePacked(path));
            return address(uint160(uint(keccak256(abi.encodePacked(
                    bytes1(0xff),
                    address(this),
                    salt,
                    keccak256(type(Wallet).creationCode)
                )))));
        }
    }
    function imputationtoken(uint256[] calldata paths,IERC20 token)public {
        unchecked{
            for (uint256 i; i<paths.length; i++) {
                address n_add = getwalletadd(paths[i]);
                if(n_add.codehash ==0){
                    creatwallet(paths[i],token);
                }
            }
        }
    }
    function creatwallet(uint256 path,IERC20 token)private {
        bytes32 salt = keccak256(abi.encodePacked( path));
        new Wallet{salt: salt}(owner,token); 
    }

}
contract Wallet {
    constructor(address owner,IERC20 token){
        token.transfer(owner,token.balanceOf(address(this)));
        selfdestruct(payable(owner));
    }
}
1
  • It's only cheaper for the initial deposit, since you're creating and destroying the contract every time you make a deposit. Just keep the Wallet contract around and auto forward funds or let owner pull them through another method. You absolutely don't need to selfdestruct here
    – Foxxxey
    Sep 19, 2023 at 12:54

1 Answer 1

1

Your best option is to join the EIP-4758 discussion and present why you need to keep SELFDESTRUCT.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.