¡El código fuente de este contrato está verificado!
Metadatos del Contrato
Compilador
0.8.19+commit.7dd6d404
Idioma
Solidity
Código Fuente del Contrato
Archivo 1 de 8: ERC20.sol
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity >=0.8.0;/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation./// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.abstractcontractERC20{
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/eventTransfer(addressindexedfrom, addressindexed to, uint256 amount);
eventApproval(addressindexed owner, addressindexed spender, uint256 amount);
/*//////////////////////////////////////////////////////////////
METADATA STORAGE
//////////////////////////////////////////////////////////////*/stringpublic name;
stringpublic symbol;
uint8publicimmutable decimals;
/*//////////////////////////////////////////////////////////////
ERC20 STORAGE
//////////////////////////////////////////////////////////////*/uint256public totalSupply;
mapping(address=>uint256) public balanceOf;
mapping(address=>mapping(address=>uint256)) public allowance;
/*//////////////////////////////////////////////////////////////
EIP-2612 STORAGE
//////////////////////////////////////////////////////////////*/uint256internalimmutable INITIAL_CHAIN_ID;
bytes32internalimmutable INITIAL_DOMAIN_SEPARATOR;
mapping(address=>uint256) public nonces;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/constructor(stringmemory _name,
stringmemory _symbol,
uint8 _decimals
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
INITIAL_CHAIN_ID =block.chainid;
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
}
/*//////////////////////////////////////////////////////////////
ERC20 LOGIC
//////////////////////////////////////////////////////////////*/functionapprove(address spender, uint256 amount) publicvirtualreturns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
returntrue;
}
functiontransfer(address to, uint256 amount) publicvirtualreturns (bool) {
balanceOf[msg.sender] -= amount;
// Cannot overflow because the sum of all user// balances can't exceed the max uint256 value.unchecked {
balanceOf[to] += amount;
}
emit Transfer(msg.sender, to, amount);
returntrue;
}
functiontransferFrom(addressfrom,
address to,
uint256 amount
) publicvirtualreturns (bool) {
uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.if (allowed !=type(uint256).max) allowance[from][msg.sender] = allowed - amount;
balanceOf[from] -= amount;
// Cannot overflow because the sum of all user// balances can't exceed the max uint256 value.unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
returntrue;
}
/*//////////////////////////////////////////////////////////////
EIP-2612 LOGIC
//////////////////////////////////////////////////////////////*/functionpermit(address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) publicvirtual{
require(deadline >=block.timestamp, "PERMIT_DEADLINE_EXPIRED");
// Unchecked because the only math done is incrementing// the owner's nonce which cannot realistically overflow.unchecked {
address recoveredAddress =ecrecover(
keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
),
owner,
spender,
value,
nonces[owner]++,
deadline
)
)
)
),
v,
r,
s
);
require(recoveredAddress !=address(0) && recoveredAddress == owner, "INVALID_SIGNER");
allowance[recoveredAddress][spender] = value;
}
emit Approval(owner, spender, value);
}
functionDOMAIN_SEPARATOR() publicviewvirtualreturns (bytes32) {
returnblock.chainid== INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
}
functioncomputeDomainSeparator() internalviewvirtualreturns (bytes32) {
returnkeccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}
/*//////////////////////////////////////////////////////////////
INTERNAL MINT/BURN LOGIC
//////////////////////////////////////////////////////////////*/function_mint(address to, uint256 amount) internalvirtual{
totalSupply += amount;
// Cannot overflow because the sum of all user// balances can't exceed the max uint256 value.unchecked {
balanceOf[to] += amount;
}
emit Transfer(address(0), to, amount);
}
function_burn(addressfrom, uint256 amount) internalvirtual{
balanceOf[from] -= amount;
// Cannot underflow because a user's balance// will never be larger than the total supply.unchecked {
totalSupply -= amount;
}
emit Transfer(from, address(0), amount);
}
}
Código Fuente del Contrato
Archivo 2 de 8: FeeCollector.sol
// SPDX-License-Identifier: GPL-2.0-or-laterpragmasolidity ^0.8.0;import {Owned} from"solmate/auth/Owned.sol";
import {ERC20} from"solmate/tokens/ERC20.sol";
import {SafeTransferLib} from"solmate/utils/SafeTransferLib.sol";
import {IFeeCollector} from"./interfaces/IFeeCollector.sol";
import {IPermit2} from"./external/IPermit2.sol";
/// @notice The collector of protocol fees that will be used to swap and send to a fee recipient address.contractFeeCollectorisOwned, IFeeCollector{
usingSafeTransferLibforERC20;
addresspublic universalRouter;
ERC20 publicimmutable feeToken;
IPermit2 publicimmutable permit2;
uint256publicconstant MAX_APPROVAL_AMOUNT =type(uint256).max;
uint160publicconstant MAX_PERMIT2_APPROVAL_AMOUNT =type(uint160).max;
uint48publicconstant MAX_PERMIT2_DEADLINE =type(uint48).max;
constructor(address _owner, address _universalRouter, address _permit2, address _feeToken) Owned(_owner) {
universalRouter = _universalRouter;
feeToken = ERC20(_feeToken);
permit2 = IPermit2(_permit2);
}
/// @inheritdoc IFeeCollectorfunctionswapBalance(bytescalldata swapData, uint256 nativeValue) externalonlyOwner{
_execute(swapData, nativeValue);
}
/// @inheritdoc IFeeCollectorfunctionswapBalance(bytescalldata swapData, uint256 nativeValue, ERC20[] calldata tokensToApprove)
externalonlyOwner{
unchecked {
for (uint256 i =0; i < tokensToApprove.length; i++) {
tokensToApprove[i].safeApprove(address(permit2), MAX_APPROVAL_AMOUNT);
permit2.approve(
address(tokensToApprove[i]), universalRouter, MAX_PERMIT2_APPROVAL_AMOUNT, MAX_PERMIT2_DEADLINE
);
}
}
_execute(swapData, nativeValue);
}
/// @notice Helper function to call UniversalRouter./// @param swapData The bytes call data to be forwarded to UniversalRouter./// @param nativeValue The amount of native currency to send to UniversalRouter.function_execute(bytescalldata swapData, uint256 nativeValue) internal{
(bool success,) = universalRouter.call{value: nativeValue}(swapData);
if (!success) revert UniversalRouterCallFailed();
}
/// @inheritdoc IFeeCollectorfunctionrevokeTokenApprovals(ERC20[] calldata tokensToRevoke) externalonlyOwner{
unchecked {
for (uint256 i =0; i < tokensToRevoke.length; i++) {
tokensToRevoke[i].safeApprove(address(permit2), 0);
}
}
}
/// @inheritdoc IFeeCollectorfunctionrevokePermit2Approvals(IPermit2.TokenSpenderPair[] calldata approvals) externalonlyOwner{
permit2.lockdown(approvals);
}
/// @inheritdoc IFeeCollectorfunctionwithdrawFeeToken(address feeRecipient, uint256 amount) externalonlyOwner{
feeToken.safeTransfer(feeRecipient, amount);
}
/// @inheritdoc IFeeCollectorfunctionsetUniversalRouter(address _universalRouter) externalonlyOwner{
emit UniversalRouterChanged(universalRouter, _universalRouter);
universalRouter = _universalRouter;
}
receive() externalpayable{}
}
Código Fuente del Contrato
Archivo 3 de 8: IAllowanceTransfer.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;import {IEIP712} from"./IEIP712.sol";
/// @title AllowanceTransfer/// @notice Handles ERC20 token permissions through signature based allowance setting and ERC20 token transfers by checking allowed amounts/// @dev Requires user's token approval on the Permit2 contractinterfaceIAllowanceTransferisIEIP712{
/// @notice A token spender pair.structTokenSpenderPair {
// the token the spender is approvedaddress token;
// the spender addressaddress spender;
}
/// @notice A mapping from owner address to token address to spender address to PackedAllowance struct, which contains details and conditions of the approval./// @notice The mapping is indexed in the above order see: allowance[ownerAddress][tokenAddress][spenderAddress]/// @dev The packed slot holds the allowed amount, expiration at which the allowed amount is no longer valid, and current nonce thats updated on any signature based approvals.functionallowance(address user, address token, address spender)
externalviewreturns (uint160 amount, uint48 expiration, uint48 nonce);
/// @notice Approves the spender to use up to amount of the specified token up until the expiration/// @param token The token to approve/// @param spender The spender address to approve/// @param amount The approved amount of the token/// @param expiration The timestamp at which the approval is no longer valid/// @dev The packed allowance also holds a nonce, which will stay unchanged in approve/// @dev Setting amount to type(uint160).max sets an unlimited approvalfunctionapprove(address token, address spender, uint160 amount, uint48 expiration) external;
/// @notice Enables performing a "lockdown" of the sender's Permit2 identity/// by batch revoking approvals/// @param approvals Array of approvals to revoke.functionlockdown(TokenSpenderPair[] calldata approvals) external;
}
// SPDX-License-Identifier: GPL-2.0-or-laterpragmasolidity ^0.8.13;import {ERC20} from"solmate/tokens/ERC20.sol";
import {IPermit2} from"../external/IPermit2.sol";
/// @notice The collector of protocol fees that will be used to swap and send to a fee recipient address.interfaceIFeeCollector{
/// @notice Error thrown when the call to UniversalRouter fails.errorUniversalRouterCallFailed();
/// @notice Emitted when the UniversalRouter address is changed./// @param oldUniversalRouter The old router address./// @param newUniversalRouter The new router address.eventUniversalRouterChanged(address oldUniversalRouter, address newUniversalRouter);
/// @notice Swaps the contract balance./// @param swapData The bytes call data to be forwarded to UniversalRouter./// @param nativeValue The amount of native currency to send to UniversalRouter.functionswapBalance(bytescalldata swapData, uint256 nativeValue) external;
/// @notice Approves tokens for swapping and then swaps the contract balance./// @param swapData The bytes call data to be forwarded to UniversalRouter./// @param nativeValue The amount of native currency to send to UniversalRouter./// @param tokensToApprove An array of ERC20 tokens to approve for spending.functionswapBalance(bytescalldata swapData, uint256 nativeValue, ERC20[] calldata tokensToApprove) external;
/// @notice Revokes approvals on tokens by setting their allowance to 0./// @param tokensToRevoke The token to revoke the approval for.functionrevokeTokenApprovals(ERC20[] calldata tokensToRevoke) external;
/// @notice Revokes the permit2 allowance of a spender by setting token allowances to 0./// @param approvals The approvals to revoke.functionrevokePermit2Approvals(IPermit2.TokenSpenderPair[] calldata approvals) external;
/// @notice Transfers the fee token balance from this contract to the fee recipient./// @param feeRecipient The address to send the fee token balance to./// @param amount The amount to withdraw.functionwithdrawFeeToken(address feeRecipient, uint256 amount) external;
/// @notice Sets the address of the UniversalRouter contract./// @param _universalRouter The address of the UniversalRouter contract.functionsetUniversalRouter(address _universalRouter) external;
}
Código Fuente del Contrato
Archivo 6 de 8: IPermit2.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;import {IAllowanceTransfer} from"./IAllowanceTransfer.sol";
/// @notice Permit2 handles signature-based transfers in SignatureTransfer and allowance-based transfers in AllowanceTransfer./// @dev Users must approve Permit2 before calling any of the transfer functions.interfaceIPermit2isIAllowanceTransfer{
// IPermit2 unifies the two interfaces so users have maximal flexibility with their approval.
}
// SPDX-License-Identifier: AGPL-3.0-onlypragmasolidity >=0.8.0;import {ERC20} from"../tokens/ERC20.sol";
/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values./// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer./// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.librarySafeTransferLib{
/*//////////////////////////////////////////////////////////////
ETH OPERATIONS
//////////////////////////////////////////////////////////////*/functionsafeTransferETH(address to, uint256 amount) internal{
bool success;
/// @solidity memory-safe-assemblyassembly {
// Transfer the ETH and store if it succeeded or not.
success :=call(gas(), to, amount, 0, 0, 0, 0)
}
require(success, "ETH_TRANSFER_FAILED");
}
/*//////////////////////////////////////////////////////////////
ERC20 OPERATIONS
//////////////////////////////////////////////////////////////*/functionsafeTransferFrom(
ERC20 token,
addressfrom,
address to,
uint256 amount
) internal{
bool success;
/// @solidity memory-safe-assemblyassembly {
// Get a pointer to some free memory.let freeMemoryPointer :=mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(from, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "from" argument.mstore(add(freeMemoryPointer, 36), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success :=and(
// Set success to whether the call reverted, if not we check it either// returned exactly 1 (can't just be non-zero data), or had no return data.or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.// Counterintuitively, this call must be positioned second to the or() call in the// surrounding and() call or else returndatasize() will be zero during the computation.call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)
)
}
require(success, "TRANSFER_FROM_FAILED");
}
functionsafeTransfer(
ERC20 token,
address to,
uint256 amount
) internal{
bool success;
/// @solidity memory-safe-assemblyassembly {
// Get a pointer to some free memory.let freeMemoryPointer :=mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success :=and(
// Set success to whether the call reverted, if not we check it either// returned exactly 1 (can't just be non-zero data), or had no return data.or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.// Counterintuitively, this call must be positioned second to the or() call in the// surrounding and() call or else returndatasize() will be zero during the computation.call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "TRANSFER_FAILED");
}
functionsafeApprove(
ERC20 token,
address to,
uint256 amount
) internal{
bool success;
/// @solidity memory-safe-assemblyassembly {
// Get a pointer to some free memory.let freeMemoryPointer :=mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success :=and(
// Set success to whether the call reverted, if not we check it either// returned exactly 1 (can't just be non-zero data), or had no return data.or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.// Counterintuitively, this call must be positioned second to the or() call in the// surrounding and() call or else returndatasize() will be zero during the computation.call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "APPROVE_FAILED");
}
}