Skip to content

Instantly share code, notes, and snippets.

@xx444812313
Created May 17, 2022 16:39
Show Gist options
  • Save xx444812313/93b3ad1f22afd0eb528f54229e09d300 to your computer and use it in GitHub Desktop.
Save xx444812313/93b3ad1f22afd0eb528f54229e09d300 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=true&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.7.0;
contract delegate_demo {
Erc20Util util;
constructor(address _util){
util = Erc20Util(_util);
}
function SetUtil(address _util) public {
util = Erc20Util(_util);
}
event DelegateBatchTransfer20(address indexed erc20, address to, uint256 amount);
event DelegateCall(bool success, bytes result);
function delegate_BatchTransfer20(address util, address erc20, address to, uint256 amount) public {
(bool success,bytes memory result) = util.delegatecall(abi.encodeWithSignature("BatchTransfer20(address,address,uint256)", erc20, to, amount));
emit DelegateBatchTransfer20(erc20, to, amount);
}
function delegate_BatchTransfer202(address erc20, address to, uint256 amount) public {
util.BatchTransfer20(erc20, to, amount);
emit DelegateBatchTransfer20(erc20, to, amount);
}
function delegate_call(address util, string calldata data) public {
(bool success, bytes memory result) = util.delegatecall(abi.encodeWithSignature(data));
emit DelegateCall(success, result);
}
}
contract Erc20Util {
function BatchTransfer20(address erc20, address to, uint256 amount) public {
IERC20 _erc20 = IERC20(erc20);
_erc20.transferFrom(msg.sender, to, amount);
_erc20.transferFrom(msg.sender, to, amount);
}
}
interface IERC20 {
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment