编译器
0.8.13+commit.abaa5c0e
文件 1 的 6:Address.sol
pragma solidity ^0.8.0;
library Address {
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 2 的 6:FeeCollector.sol
pragma solidity 0.8.13;
import { LibAsset } from "../Libraries/LibAsset.sol";
contract FeeCollector {
mapping(address => mapping(address => uint256)) private _balances;
mapping(address => uint256) private _lifiBalances;
address public owner;
address public pendingOwner;
error Unauthorized(address);
error NoNullOwner();
error NewOwnerMustNotBeSelf();
error NoPendingOwnershipTransfer();
error NotPendingOwner();
error TransferFailure();
event FeesCollected(address indexed _token, address indexed _integrator, uint256 _integratorFee, uint256 _lifiFee);
event FeesWithdrawn(address indexed _token, address indexed _to, uint256 _amount);
event LiFiFeesWithdrawn(address indexed _token, address indexed _to, uint256 _amount);
event OwnershipTransferRequested(address indexed _from, address indexed _to);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor(address _owner) {
owner = _owner;
}
function collectTokenFees(
address tokenAddress,
uint256 integratorFee,
uint256 lifiFee,
address integratorAddress
) external {
LibAsset.depositAsset(tokenAddress, integratorFee + lifiFee);
_balances[integratorAddress][tokenAddress] += integratorFee;
_lifiBalances[tokenAddress] += lifiFee;
emit FeesCollected(tokenAddress, integratorAddress, integratorFee, lifiFee);
}
function collectNativeFees(
uint256 integratorFee,
uint256 lifiFee,
address integratorAddress
) external payable {
_balances[integratorAddress][LibAsset.NULL_ADDRESS] += integratorFee;
_lifiBalances[LibAsset.NULL_ADDRESS] += lifiFee;
uint256 remaining = msg.value - (integratorFee + lifiFee);
if (remaining > 0) {
(bool success, ) = msg.sender.call{ value: remaining }("");
if (!success) {
revert TransferFailure();
}
}
emit FeesCollected(LibAsset.NULL_ADDRESS, integratorAddress, integratorFee, lifiFee);
}
function withdrawIntegratorFees(address tokenAddress) external {
uint256 balance = _balances[msg.sender][tokenAddress];
if (balance == 0) {
return;
}
_balances[msg.sender][tokenAddress] = 0;
LibAsset.transferAsset(tokenAddress, payable(msg.sender), balance);
emit FeesWithdrawn(tokenAddress, msg.sender, balance);
}
function batchWithdrawIntegratorFees(address[] memory tokenAddresses) external {
uint256 length = tokenAddresses.length;
uint256 balance;
for (uint256 i = 0; i < length; i++) {
balance = _balances[msg.sender][tokenAddresses[i]];
if (balance == 0) {
continue;
}
_balances[msg.sender][tokenAddresses[i]] = 0;
LibAsset.transferAsset(tokenAddresses[i], payable(msg.sender), balance);
emit FeesWithdrawn(tokenAddresses[i], msg.sender, balance);
}
}
function withdrawLifiFees(address tokenAddress) external {
_enforceIsContractOwner();
uint256 balance = _lifiBalances[tokenAddress];
if (balance == 0) {
return;
}
_lifiBalances[tokenAddress] = 0;
LibAsset.transferAsset(tokenAddress, payable(owner), balance);
emit LiFiFeesWithdrawn(tokenAddress, msg.sender, balance);
}
function batchWithdrawLifiFees(address[] memory tokenAddresses) external {
_enforceIsContractOwner();
uint256 length = tokenAddresses.length;
uint256 balance;
for (uint256 i = 0; i < length; i++) {
balance = _lifiBalances[tokenAddresses[i]];
if (balance == 0) {
continue;
}
_lifiBalances[tokenAddresses[i]] = 0;
LibAsset.transferAsset(tokenAddresses[i], payable(owner), balance);
emit LiFiFeesWithdrawn(tokenAddresses[i], msg.sender, balance);
}
}
function getTokenBalance(address integratorAddress, address tokenAddress) external view returns (uint256) {
return _balances[integratorAddress][tokenAddress];
}
function getLifiTokenBalance(address tokenAddress) external view returns (uint256) {
return _lifiBalances[tokenAddress];
}
function transferOwnership(address _newOwner) external {
_enforceIsContractOwner();
if (_newOwner == LibAsset.NULL_ADDRESS) revert NoNullOwner();
if (_newOwner == owner) revert NewOwnerMustNotBeSelf();
pendingOwner = _newOwner;
emit OwnershipTransferRequested(msg.sender, pendingOwner);
}
function cancelOnwershipTransfer() external {
_enforceIsContractOwner();
if (pendingOwner == LibAsset.NULL_ADDRESS) revert NoPendingOwnershipTransfer();
pendingOwner = LibAsset.NULL_ADDRESS;
}
function confirmOwnershipTransfer() external {
if (msg.sender != pendingOwner) revert NotPendingOwner();
owner = pendingOwner;
pendingOwner = LibAsset.NULL_ADDRESS;
emit OwnershipTransferred(owner, pendingOwner);
}
function _enforceIsContractOwner() private view {
if (msg.sender != owner) {
revert Unauthorized(msg.sender);
}
}
}
文件 3 的 6:GenericErrors.sol
pragma solidity 0.8.13;
error InvalidAmount();
error TokenAddressIsZero();
error CannotBridgeToSameNetwork();
error ZeroPostSwapBalance();
error InvalidBridgeConfigLength();
error NoSwapDataProvided();
error NativeValueWithERC();
error ContractCallNotAllowed();
error NullAddrIsNotAValidSpender();
error NullAddrIsNotAnERC20Token();
error NoTransferToNullAddress();
error NativeAssetTransferFailed();
error InvalidContract();
error InvalidConfig();
文件 4 的 6:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 5 的 6:LibAsset.sol
pragma solidity 0.8.13;
import { NullAddrIsNotAnERC20Token, NullAddrIsNotAValidSpender, NoTransferToNullAddress, InvalidAmount, NativeValueWithERC, NativeAssetTransferFailed } from "../Errors/GenericErrors.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
library LibAsset {
uint256 private constant MAX_INT = type(uint256).max;
address internal constant NULL_ADDRESS = 0x0000000000000000000000000000000000000000;
address internal constant NATIVE_ASSETID = NULL_ADDRESS;
function getOwnBalance(address assetId) internal view returns (uint256) {
return assetId == NATIVE_ASSETID ? address(this).balance : IERC20(assetId).balanceOf(address(this));
}
function transferNativeAsset(address payable recipient, uint256 amount) private {
if (recipient == NULL_ADDRESS) revert NoTransferToNullAddress();
(bool success, ) = recipient.call{ value: amount }("");
if (!success) revert NativeAssetTransferFailed();
}
function maxApproveERC20(
IERC20 assetId,
address spender,
uint256 amount
) internal {
if (address(assetId) == NATIVE_ASSETID) return;
if (spender == NULL_ADDRESS) revert NullAddrIsNotAValidSpender();
uint256 allowance = assetId.allowance(address(this), spender);
if (allowance < amount) SafeERC20.safeApprove(IERC20(assetId), spender, MAX_INT);
}
function transferERC20(
address assetId,
address recipient,
uint256 amount
) private {
if (isNativeAsset(assetId)) revert NullAddrIsNotAnERC20Token();
SafeERC20.safeTransfer(IERC20(assetId), recipient, amount);
}
function transferFromERC20(
address assetId,
address from,
address to,
uint256 amount
) internal {
if (assetId == NATIVE_ASSETID) revert NullAddrIsNotAnERC20Token();
if (to == NULL_ADDRESS) revert NoTransferToNullAddress();
SafeERC20.safeTransferFrom(IERC20(assetId), from, to, amount);
}
function depositAsset(
address tokenId,
uint256 amount,
bool isNative
) internal {
if (amount == 0) revert InvalidAmount();
if (isNative) {
if (msg.value != amount) revert InvalidAmount();
} else {
if (msg.value != 0) revert NativeValueWithERC();
uint256 _fromTokenBalance = LibAsset.getOwnBalance(tokenId);
LibAsset.transferFromERC20(tokenId, msg.sender, address(this), amount);
if (LibAsset.getOwnBalance(tokenId) - _fromTokenBalance != amount) revert InvalidAmount();
}
}
function depositAsset(address tokenId, uint256 amount) internal {
return depositAsset(tokenId, amount, tokenId == NATIVE_ASSETID);
}
function isNativeAsset(address assetId) internal pure returns (bool) {
return assetId == NATIVE_ASSETID;
}
function transferAsset(
address assetId,
address payable recipient,
uint256 amount
) internal {
(assetId == NATIVE_ASSETID)
? transferNativeAsset(recipient, amount)
: transferERC20(assetId, recipient, amount);
}
function isContract(address _contractAddr) internal view returns (bool) {
uint256 size;
assembly {
size := extcodesize(_contractAddr)
}
return size > 0;
}
}
文件 6 的 6:SafeERC20.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../../../utils/Address.sol";
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
{
"compilationTarget": {
"src/Periphery/FeeCollector.sol": "FeeCollector"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 10000
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidAmount","type":"error"},{"inputs":[],"name":"NativeAssetTransferFailed","type":"error"},{"inputs":[],"name":"NativeValueWithERC","type":"error"},{"inputs":[],"name":"NewOwnerMustNotBeSelf","type":"error"},{"inputs":[],"name":"NoNullOwner","type":"error"},{"inputs":[],"name":"NoPendingOwnershipTransfer","type":"error"},{"inputs":[],"name":"NoTransferToNullAddress","type":"error"},{"inputs":[],"name":"NotPendingOwner","type":"error"},{"inputs":[],"name":"NullAddrIsNotAnERC20Token","type":"error"},{"inputs":[],"name":"TransferFailure","type":"error"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"Unauthorized","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_token","type":"address"},{"indexed":true,"internalType":"address","name":"_integrator","type":"address"},{"indexed":false,"internalType":"uint256","name":"_integratorFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_lifiFee","type":"uint256"}],"name":"FeesCollected","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_token","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"FeesWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_token","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"LiFiFeesWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"}],"name":"OwnershipTransferRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"address[]","name":"tokenAddresses","type":"address[]"}],"name":"batchWithdrawIntegratorFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokenAddresses","type":"address[]"}],"name":"batchWithdrawLifiFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cancelOnwershipTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"integratorFee","type":"uint256"},{"internalType":"uint256","name":"lifiFee","type":"uint256"},{"internalType":"address","name":"integratorAddress","type":"address"}],"name":"collectNativeFees","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"integratorFee","type":"uint256"},{"internalType":"uint256","name":"lifiFee","type":"uint256"},{"internalType":"address","name":"integratorAddress","type":"address"}],"name":"collectTokenFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"confirmOwnershipTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"}],"name":"getLifiTokenBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"integratorAddress","type":"address"},{"internalType":"address","name":"tokenAddress","type":"address"}],"name":"getTokenBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"}],"name":"withdrawIntegratorFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"}],"name":"withdrawLifiFees","outputs":[],"stateMutability":"nonpayable","type":"function"}]