Verified contractExactMIT
SmithiiPoolLauncher
Address0xcd6db2c240ccedb953abd87e02629f1452540517
- Balance
0 ETH
- Transactions
3
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 10,000 runs
- EVM version
- paris
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,861,624
- Creation transaction
- 0xc60c8fb728…4c378b80b5
12 files
- contracts/bundler/SmithiiPoolLauncher.solmain19.14 KB
- @openzeppelin/contracts/access/Ownable.sol3.1 KB
- @openzeppelin/contracts/access/Ownable2Step.sol2.48 KB
- @openzeppelin/contracts/interfaces/IERC1363.sol4.45 KB
- @openzeppelin/contracts/interfaces/IERC165.sol192 B
- @openzeppelin/contracts/interfaces/IERC20.sol181 B
- @openzeppelin/contracts/token/ERC20/IERC20.sol2.78 KB
- @openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol10.08 KB
- @openzeppelin/contracts/utils/Context.sol963 B
- @openzeppelin/contracts/utils/Pausable.sol2.71 KB
- @openzeppelin/contracts/utils/ReentrancyGuard.sol3.38 KB
- @openzeppelin/contracts/utils/introspection/IERC165.sol870 B
contracts/bundler/SmithiiPoolLauncher.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
interface ISmithiiRouterPools {
function getServicePrice(bytes32 _serviceId) external view returns (uint256);
function PoolFactory() external view returns (address);
function createPoolWithNativeToken(
address _token,
uint256 _amountTokenDesired,
uint256 _amountTokenMin,
uint256 _amountETH,
uint256 _amountETHMin,
address _to,
uint256 _deadline
) external payable;
}
interface IUniswapV2RouterMinimal {
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable;
function WETH() external view returns (address);
function factory() external view returns (address);
}
interface IPoolFactoryMinimal {
function router() external view returns (address);
}
interface IUniswapV2FactoryMinimal {
function getPair(address, address) external view returns (address);
}
interface IUniswapV2PairMinimal {
function getReserves() external view returns (uint112, uint112, uint32);
function token0() external view returns (address);
}
/**
* Everything a launch needs, as typed values.
*
* A struct rather than ten parameters because this contract compiles without
* `viaIR` and ten would not fit the stack. It is NOT a relaxation of the rule
* that this contract never accepts calldata from its caller — that rule is
* about `bytes`, and it does not move.
*/
struct LaunchParams {
address token;
uint256 amountToken;
uint256 amountTokenMin;
uint256 amountETH;
uint256 amountETHMin;
uint256 buyETH;
uint256 minTokensOut;
uint256 maxFeeWei;
address buyRecipient;
uint256 deadline;
}
/**
* SmithiiPoolLauncher — create a pool through this suite's Router and buy into it
* in the SAME transaction, so the pool is never open with liquidity and no buyer.
*
* Only the seven V2 chains need this. Robinhood's own `ERC20PoolFactory` already
* buys inside `createMintAndBuy`; the Router these chains use has no dev-buy at
* all, so creating and buying are two transactions with a gap between them.
*
* Design note, and the reason this contract stays small on purpose. It has to sit
* in `TradeGuardian.exempt[]` or the anti-whale rejects the very transfer that
* seeds the pool: a wallet cap of 10,000 blocks moving 100,000 tokens in, and
* that check runs before the Router is ever reached. Being in that map bypasses
* the anti-bot AND the anti-whale of every token on the platform. So the two
* targets are pinned in the constructor and every call is encoded here from
* typed arguments. It must never forward bytes it was handed — an allowlist
* constrains WHO is called, never WHAT is called, which is the lesson
* `SmithiiLauncherBase` already carries.
*/
contract SmithiiPoolLauncher is Ownable2Step, Pausable, ReentrancyGuard {
using SafeERC20 for IERC20;
/// Hard ceiling on the fee, so no owner can price a launch out of reach.
uint256 public constant MAX_LAUNCH_FEE_WEI = 1 ether;
/// The Router's own charge for creating a pool. Priced from the admin
/// panel, in the clear, which is why it is read at call time rather than
/// pinned here.
bytes32 private constant POOL_SERVICE_ID =
keccak256(abi.encodePacked("ERC20PoolFactoryFee"));
/// This suite's Router. Immutable — see the note above.
address public immutable router;
/// The chain's Uniswap-V2-style router, the same one `PoolFactory` was given.
address public immutable dexRouter;
address public feeWallet;
uint256 public launchFeeWei;
/**
* What the launch actually did, not what it was asked to do.
*
* The first version of this event repeated its own arguments, so a launch
* that deposited a hundredth of the native it was given still emitted the
* full figure — the fork rehearsal read it and reported success (audit H-1).
* `amountTokenIn` and `amountETHIn` are read off the pair afterwards, and
* `tokensBought` off the recipient's balance.
*/
event PoolLaunched(
address indexed token,
address indexed creator,
address indexed buyRecipient,
uint256 amountTokenIn,
uint256 amountETHIn,
uint256 buyETH,
uint256 tokensBought
);
/// A contract living in the guardian's global exemption deserves more
/// observability than its peers, not less: without these, the owner moving
/// the fee or the wallet that collects it leaves no trace an indexer can
/// see (audit L-5).
event FeeWalletUpdated(address indexed feeWallet);
event LaunchFeeUpdated(uint256 launchFeeWei);
event EthRescued(address indexed to, uint256 amount);
error ZeroAddress();
error TargetNotContract();
error FeeAboveMax();
error DeadlinePassed();
error FeeTransferFailed();
error RefundFailed();
error OwnershipCannotBeRenounced();
error PairAlreadyExists(address pair);
error FeeAboveCallerMax();
error ValueMismatch(uint256 expected, uint256 got);
error TargetMismatch();
error ZeroAmount();
error FeeWalletCannotBeSelf();
constructor(
address router_,
address dexRouter_,
address feeWallet_,
uint256 launchFeeWei_,
address owner_
) Ownable(owner_) {
if (router_ == address(0) || dexRouter_ == address(0)) revert ZeroAddress();
if (feeWallet_ == address(0) || owner_ == address(0)) revert ZeroAddress();
// A call to an address with no code succeeds silently, so a target left
// unset or taken from the wrong chain would swallow every launch while
// reporting success.
if (router_.code.length == 0 || dexRouter_.code.length == 0) {
revert TargetNotContract();
}
if (launchFeeWei_ > MAX_LAUNCH_FEE_WEI) revert FeeAboveMax();
// Probe the DEX first: it is the cheap check, and it names the common
// mistake. A V2 fork that exposes `WAVAX()` or `WBNB()` instead of
// `WETH()` passes the code check above and is not caught until the
// first launch.
if (IUniswapV2RouterMinimal(dexRouter_).WETH() == address(0)) {
revert TargetNotContract();
}
// Then prove the two targets belong together: a DEX router from another
// exchange or another chain would create the pool through one router
// and buy through another (audit L-3). Both sides of this comparison
// derive from `router_`, so it does not depend on the deployer typing
// the second address consistently.
address poolFactory = ISmithiiRouterPools(router_).PoolFactory();
if (IPoolFactoryMinimal(poolFactory).router() != dexRouter_) {
revert TargetMismatch();
}
router = router_;
dexRouter = dexRouter_;
feeWallet = feeWallet_;
launchFeeWei = launchFeeWei_;
}
/**
* Create the pool and buy into it, in one transaction.
*
* `msg.value` covers, in this order: this contract's fee, the dev-buy, the
* native side of the liquidity, and the Router's own `ERC20PoolFactoryFee`.
* The Router takes that last one out of what it is sent, so it is passed
* through rather than charged again here.
*
* The LP tokens go to the caller. The bought tokens go to `buyRecipient`,
* which is deliberately not forced to be the caller: the creator already
* holds the rest of the supply, so crediting the dev-buy to them adds
* nothing. It belongs in a wallet that holds none of it yet.
*
* This used to claim the anti-whale forced the split, and that is not true
* (audit M-3). On a buy the caller into the token is the pair, and the
* Router exempts the pair while creating the pool, so `isWhaleDetected`
* short-circuits and the cap is never evaluated. The recommendation stands;
* the reason was wrong, and a wrong reason falls over the first time
* somebody checks it.
*
* Every bound the launch runs under comes from the caller: the two
* liquidity minimums, the floor on the dev-buy, and the ceiling on this
* contract's own fee. The first version passed zeroes for all of them, and
* a pre-seeded pair turned that into a launch priced by somebody else
* (audit H-1, L-1).
*/
function createPoolAndBuy(
LaunchParams calldata p
) external payable nonReentrant whenNotPaused {
if (block.timestamp > p.deadline) revert DeadlinePassed();
if (p.token == address(0) || p.buyRecipient == address(0)) {
revert ZeroAddress();
}
// Without these the DEX cuts in with `INSUFFICIENT_INPUT_AMOUNT` three
// contracts down, and a launch with no buy is not what this is for
// (audit I-2).
if (p.amountToken == 0 || p.amountETH == 0 || p.buyETH == 0) {
revert ZeroAmount();
}
uint256 fee = launchFeeWei;
// The owner can move the fee between the moment this is signed and the
// moment it is mined. `SmithiiLauncherBase` takes the same bound.
if (fee > p.maxFeeWei) revert FeeAboveCallerMax();
uint256 expected = launchCost(p.amountETH, p.buyETH);
if (msg.value != expected) revert ValueMismatch(expected, msg.value);
address weth = IUniswapV2RouterMinimal(dexRouter).WETH();
// Before any value moves. This contract's premise is that the pool does
// not exist yet; if it does, Uniswap reprices the deposit to the ratio
// already there and the minimums cannot catch it, because they are
// compared against the repriced amounts (audit H-1).
_requireNoPricedPair(p.token, weth);
// Balance owned before this call's value: anything above it afterwards
// belongs to this caller and is refunded, while funds stranded by an
// earlier transaction stay put for `rescueETH`.
uint256 balBefore = address(this).balance - msg.value;
uint256 received = _pullAndApprove(p.token, p.amountToken);
ISmithiiRouterPools(router).createPoolWithNativeToken{
value: msg.value - fee - p.buyETH
}(
p.token,
received,
p.amountTokenMin,
p.amountETH,
p.amountETHMin,
msg.sender,
p.deadline
);
_buyAndReport(p, weth);
// Paid last. `feeWallet` is mutable by the owner, so a contract sitting
// at that address gets control from this `.call`; there is no reason to
// hand it that control before the pool exists (audit L-6).
if (fee > 0) {
(bool feeOk, ) = feeWallet.call{value: fee}("");
if (!feeOk) revert FeeTransferFailed();
}
// Not the safety net for over-payment — that reverts above. This is for
// native that arrives mid-call: `receive()` is open, and a token hook
// could push some in while the launch runs.
uint256 leftover = address(this).balance - balBefore;
if (leftover > 0) {
(bool refundOk, ) = msg.sender.call{value: leftover}("");
if (!refundOk) revert RefundFailed();
}
}
/**
* Pull the seed tokens in and approve the Router for what actually arrived.
*
* Less than what was asked for whenever the caller is not the whitelisted
* creator of a taxed token — the distributor case, and the platform's own
* default token carries 4% (audit M-2). Approving the asked-for amount made
* the Router's pull run out of balance and the token revert
* `ERC20InsufficientBalance`, an error that says nothing about the cause.
*
* The `before` matters: without it a residue left by an earlier launch
* would be swallowed into this one.
*/
function _pullAndApprove(
address token,
uint256 amountToken
) private returns (uint256 received) {
uint256 balanceBefore = IERC20(token).balanceOf(address(this));
IERC20(token).safeTransferFrom(msg.sender, address(this), amountToken);
received = IERC20(token).balanceOf(address(this)) - balanceBefore;
IERC20(token).forceApprove(router, received);
}
/// The dev-buy and the event, in their own frame so the launch fits the
/// stack without `viaIR`.
function _buyAndReport(LaunchParams calldata p, address weth) private {
// Read before the buy moves them: with the pair proven empty above,
// these reserves are the deposit itself.
(uint256 amountTokenIn, uint256 amountETHIn) = _poolAmounts(p.token, weth);
emit PoolLaunched(
p.token,
msg.sender,
p.buyRecipient,
amountTokenIn,
amountETHIn,
p.buyETH,
_buy(p, weth)
);
}
/// Where the pair for this launch would be, or `address(0)`.
function _pairFor(address token, address weth) private view returns (address) {
return
IUniswapV2FactoryMinimal(
IUniswapV2RouterMinimal(dexRouter).factory()
).getPair(token, weth);
}
function _requireNoPricedPair(address token, address weth) private view {
address pair = _pairFor(token, weth);
if (pair == address(0)) return;
(uint112 r0, uint112 r1, ) = IUniswapV2PairMinimal(pair).getReserves();
// An empty pair is not evidence of anything — `createPair` is
// permissionless, so anybody can bring one into existence for the cost
// of gas. Reserves are what let somebody else set the price.
if (r0 != 0 || r1 != 0) revert PairAlreadyExists(pair);
}
function _poolAmounts(
address token,
address weth
) private view returns (uint256 amountTokenIn, uint256 amountETHIn) {
address pair = _pairFor(token, weth);
if (pair == address(0)) return (0, 0);
(uint112 r0, uint112 r1, ) = IUniswapV2PairMinimal(pair).getReserves();
return
IUniswapV2PairMinimal(pair).token0() == token
? (uint256(r0), uint256(r1))
: (uint256(r1), uint256(r0));
}
/// The dev-buy. Returns what the recipient actually received, which is less
/// than the pair paid out whenever the token taxes the transfer.
function _buy(
LaunchParams calldata p,
address weth
) private returns (uint256) {
address[] memory path = new address[](2);
path[0] = weth;
path[1] = p.token;
uint256 balanceBefore = IERC20(p.token).balanceOf(p.buyRecipient);
IUniswapV2RouterMinimal(dexRouter)
.swapExactETHForTokensSupportingFeeOnTransferTokens{value: p.buyETH}(
p.minTokensOut,
path,
p.buyRecipient,
p.deadline
);
return IERC20(p.token).balanceOf(p.buyRecipient) - balanceBefore;
}
/**
* What a launch costs, to the wei.
*
* `Payments.payService` rejects anything but the exact service price, so
* `msg.value` here is an equality and not a floor. The first version stated
* a `<` and carried a refund branch, which read like the surplus came back;
* it never did — a single wei over reverted three contracts down, with an
* error naming neither this contract nor its fee (audit M-1).
*/
function launchCost(
uint256 amountETH,
uint256 buyETH
) public view returns (uint256) {
return
amountETH +
buyETH +
launchFeeWei +
ISmithiiRouterPools(router).getServicePrice(POOL_SERVICE_ID);
}
function setFeeWallet(address feeWallet_) external onlyOwner {
if (feeWallet_ == address(0)) revert ZeroAddress();
// A fee wallet pointing at the launcher pays the fee to itself and
// hands it straight back to the caller as `leftover`: every launch goes
// free, with nothing on chain to show it (audit I-4).
if (feeWallet_ == address(this)) revert FeeWalletCannotBeSelf();
feeWallet = feeWallet_;
emit FeeWalletUpdated(feeWallet_);
}
function setLaunchFee(uint256 launchFeeWei_) external onlyOwner {
if (launchFeeWei_ > MAX_LAUNCH_FEE_WEI) revert FeeAboveMax();
launchFeeWei = launchFeeWei_;
emit LaunchFeeUpdated(launchFeeWei_);
}
function pause() external onlyOwner {
_pause();
}
function unpause() external onlyOwner {
_unpause();
}
/**
* Ownership is never given up.
*
* Pausing is the only way to stop a contract that sits in the guardian's
* global exemption, and only the owner can pause. An ownerless launcher
* with that reach could not be switched off by anyone.
*/
function renounceOwnership() public view override onlyOwner {
revert OwnershipCannotBeRenounced();
}
/// Native stranded by an earlier transaction. A launch refunds its own.
function rescueETH(
address to,
uint256 amount
) external onlyOwner nonReentrant {
if (to == address(0)) revert ZeroAddress();
(bool ok, ) = to.call{value: amount}("");
if (!ok) revert RefundFailed();
emit EthRescued(to, amount);
}
/**
* Tokens that reached the launcher and would otherwise stay here forever.
*
* The launcher handles tokens on every launch and sits in the guardian's
* global exemption, so nothing stops a transfer landing on it — a mistaken
* send, or a residue from a token that rounds oddly. `rescueETH` existed for
* exactly this and had no ERC20 half (audit L-4). It custodies nothing
* between transactions, so this takes nothing from anyone.
*/
function rescueERC20(
address token,
address to,
uint256 amount
) external onlyOwner nonReentrant {
if (to == address(0)) revert ZeroAddress();
IERC20(token).safeTransfer(to, amount);
}
/**
* Not the DEX refunding a swap — it refunds nothing, it deposits the whole
* `msg.value` into WETH — and not `addLiquidityETH`'s surplus either, which
* goes to the PoolFactory and from there to the caller (audit I-1).
*
* It is here so `rescueETH` has something to rescue: native can still reach
* this contract by selfdestruct, by a coinbase payout, or by a plain send.
*/
receive() external payable {}
}
@openzeppelin/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
@openzeppelin/contracts/access/Ownable2Step.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This extension of the {Ownable} contract includes a two-step mechanism to transfer
* ownership, where the new owner must call {acceptOwnership} in order to replace the
* old one. This can help prevent common mistakes, such as transfers of ownership to
* incorrect accounts, or to contracts that are unable to interact with the
* permission system.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*
* Setting `newOwner` to the zero address is allowed; this can be used to cancel an initiated ownership transfer.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}
@openzeppelin/contracts/interfaces/IERC1363.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
@openzeppelin/contracts/interfaces/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";
@openzeppelin/contracts/interfaces/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
@openzeppelin/contracts/utils/Pausable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Pausable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
bool private _paused;
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
/**
* @dev The operation failed because the contract is paused.
*/
error EnforcedPause();
/**
* @dev The operation failed because the contract is not paused.
*/
error ExpectedPause();
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
if (paused()) {
revert EnforcedPause();
}
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
if (!paused()) {
revert ExpectedPause();
}
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
@openzeppelin/contracts/utils/ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
@openzeppelin/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 10000,
"enabled": true
},
"evmVersion": "paris",
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.