Source Code
Overview
GLMR Balance
GLMR Value
$0.00Latest 22 from a total of 22 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Create Token | 8399237 | 433 days ago | IN | 20 GLMR | 0.6246705 | ||||
| Create Token | 8396916 | 434 days ago | IN | 20 GLMR | 0.6246705 | ||||
| Create Token | 8395796 | 434 days ago | IN | 20 GLMR | 0.64965732 | ||||
| Create Token | 8382720 | 435 days ago | IN | 20 GLMR | 0.77958878 | ||||
| Create Token | 8378332 | 435 days ago | IN | 20 GLMR | 0.6246705 | ||||
| Create Token | 8370390 | 435 days ago | IN | 20 GLMR | 0.6246705 | ||||
| Create Token | 8369605 | 436 days ago | IN | 20 GLMR | 0.6246705 | ||||
| Create Token | 8363363 | 436 days ago | IN | 20 GLMR | 0.6246705 | ||||
| Create Token | 8360407 | 436 days ago | IN | 20 GLMR | 0.6246705 | ||||
| Create Token | 8360051 | 436 days ago | IN | 20 GLMR | 0.6246705 | ||||
| Create Token | 8343992 | 437 days ago | IN | 20 GLMR | 0.6246705 | ||||
| Create Token | 8341904 | 438 days ago | IN | 20 GLMR | 0.6246705 | ||||
| Create Token | 8340420 | 438 days ago | IN | 20 GLMR | 0.6246705 | ||||
| Create Token | 8340056 | 438 days ago | IN | 20 GLMR | 0.6246705 | ||||
| Create Token | 8335262 | 438 days ago | IN | 20 GLMR | 0.6246705 | ||||
| Create Token | 8327432 | 439 days ago | IN | 20 GLMR | 0.6246705 | ||||
| Create Token | 8317262 | 439 days ago | IN | 20 GLMR | 0.6246705 | ||||
| Create Token | 8294904 | 441 days ago | IN | 20 GLMR | 0.74281392 | ||||
| Create Token | 8290087 | 441 days ago | IN | 20 GLMR | 0.72461778 | ||||
| Create Token | 8287530 | 441 days ago | IN | 20 GLMR | 0.6246705 | ||||
| Create Token | 8287527 | 441 days ago | IN | 20 GLMR | 0.6299775 | ||||
| Change Mcap To L... | 7995670 | 462 days ago | IN | 0 GLMR | 0.020532 |
Latest 25 internal transactions (View All)
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 8399237 | 433 days ago | 20 GLMR | ||||
| 8399237 | 433 days ago | Contract Creation | 0 GLMR | |||
| 8399237 | 433 days ago | Contract Creation | 0 GLMR | |||
| 8396916 | 434 days ago | 20 GLMR | ||||
| 8396916 | 434 days ago | Contract Creation | 0 GLMR | |||
| 8396916 | 434 days ago | Contract Creation | 0 GLMR | |||
| 8395796 | 434 days ago | 20 GLMR | ||||
| 8395796 | 434 days ago | Contract Creation | 0 GLMR | |||
| 8395796 | 434 days ago | Contract Creation | 0 GLMR | |||
| 8382720 | 435 days ago | 20 GLMR | ||||
| 8382720 | 435 days ago | Contract Creation | 0 GLMR | |||
| 8382720 | 435 days ago | Contract Creation | 0 GLMR | |||
| 8378332 | 435 days ago | 20 GLMR | ||||
| 8378332 | 435 days ago | Contract Creation | 0 GLMR | |||
| 8378332 | 435 days ago | Contract Creation | 0 GLMR | |||
| 8370390 | 435 days ago | 20 GLMR | ||||
| 8370390 | 435 days ago | Contract Creation | 0 GLMR | |||
| 8370390 | 435 days ago | Contract Creation | 0 GLMR | |||
| 8369605 | 436 days ago | 20 GLMR | ||||
| 8369605 | 436 days ago | Contract Creation | 0 GLMR | |||
| 8369605 | 436 days ago | Contract Creation | 0 GLMR | |||
| 8363363 | 436 days ago | 20 GLMR | ||||
| 8363363 | 436 days ago | Contract Creation | 0 GLMR | |||
| 8363363 | 436 days ago | Contract Creation | 0 GLMR | |||
| 8360407 | 436 days ago | 20 GLMR |
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
LOL_Factory
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
No with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity =0.8.20;
import {LOL_ICommonToken} from "./interfaces/LOL_ICommonToken.sol";
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import {LOL_Token} from "./LOL_Token.sol";
import {LOL_Bond} from "./LOL_Bond.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/**
* @title Projektlol LOL_Factory
* @dev Providing Bonding Curve/Token ERC20 contract for Projektlol.
* @notice Some function/parameter names can be confusing, because creating a bond contract == creating an erc20 token contract at the same time,
* which cannot exist without a bond contract. For example, function tokenCount() returns the number of created bonds/tokens
*/
contract LOL_Factory is Ownable {
using SafeERC20 for IERC20;
using SafeCast for uint256;
// Error messages
error LOL_Factory__InvalidConstructorParams(string reason);
error LOL_Factory__InvalidCreationTokenParams(string reason);
error LOL_Factory__InvalidCreationTokenFee();
error LOL_Factory__InvalidStepParams(string reason);
error LOL_Factory__CreationTokenFeeTransactionFailed();
error LOL_Factory__InvalidPaginationParameters();
error LOL_Factory__InvalidAddress(address adr);
error LOL_Factory__FundsTransferFailed();
uint256 private immutable MAX_SUPPLY =
21_000_000_000_000_000_000_000_000_000;
uint256 private immutable MAX_STEPS;
/**
* @dev ERC20 Token implementation/LOL_Bond implementation contract
* We use "EIP-1167: Minimal Proxy Contract" in order to save gas cost for each token deployment
* REF: https://github.com/optionality/clone-factory
*/
address private immutable TOKEN_IMPLEMENTATION;
address private immutable BOND_IMPLEMENTATION;
uint16 public tax;
uint256 public mcapToLp;
address[] public tokens;
address private _feeWallet;
uint256 public creationFee;
address public router;
// Use structs to avoid stack too deep error
struct TokenParams {
string name;
string symbol;
}
event TokenCreated(
address indexed bond,
address indexed token,
address user
);
// MARK: Constructor
/**
* @dev Initializes the factory with the provided params.
* @param tokenImplementation The address of the token implementation contract.
* @param bondImplementation The address of the bond implementation contract.
* @param owner owner address
* @param router_ Router address, needed to create lp on dex.
* @param feeWallet_ fee wallet address
* @param maxSteps The maximum number of steps allowed in a bond.
* @param creationFee_ The amount of native funds require to create bond.
* @param tax_ The tax rate
* @param mcapToLp_ The amount of native funds with which you can create an lp.
*/
constructor(
address tokenImplementation,
address bondImplementation,
address owner,
address router_,
address feeWallet_,
uint256 maxSteps,
uint256 creationFee_,
uint16 tax_,
uint256 mcapToLp_
) Ownable(owner) {
if (tokenImplementation == address(0))
revert LOL_Factory__InvalidConstructorParams("tokenImplementation");
if (bondImplementation == address(0))
revert LOL_Factory__InvalidConstructorParams("bondImplementation");
if (feeWallet_ == address(0))
revert LOL_Factory__InvalidConstructorParams("feeWallet");
TOKEN_IMPLEMENTATION = tokenImplementation;
BOND_IMPLEMENTATION = bondImplementation;
_feeWallet = feeWallet_;
MAX_STEPS = maxSteps;
creationFee = creationFee_;
tax = tax_;
mcapToLp = mcapToLp_;
router = router_;
}
receive() external payable {}
// MARK: - Factory
/**
* @dev Clones the implementation contract with a unique symbol.
* @param implementation The address of the implementation contract.
* @param symbol The symbol of the token.
* @return The address of the cloned token contract.
*/
function _clone(
address implementation,
string calldata symbol
) private returns (address payable) {
// Uniqueness of symbols on this network is guaranteed by the deterministic contract address
bytes32 salt = keccak256(
abi.encodePacked(msg.sender, symbol, block.timestamp)
);
return payable(Clones.cloneDeterministic(implementation, salt));
}
/**
* @dev Creates a new bond and token with the given parameters.
* @param tp The token parameters.
* @param bs The bond step.
* @return The address of the newly created bond and token.
*/
function createToken(
TokenParams calldata tp,
LOL_Bond.BondStep[] calldata bs
) external payable returns (address, address) {
uint256 amount = msg.value;
if (amount < creationFee) revert LOL_Factory__InvalidCreationTokenFee();
_validateTokenParams(tp);
_validateBondParams(bs);
address token = _clone(TOKEN_IMPLEMENTATION, tp.symbol);
LOL_Token newToken = LOL_Token(token);
address payable bond = _clone(BOND_IMPLEMENTATION, tp.symbol);
LOL_Bond newBond = LOL_Bond(bond);
LOL_Bond.Bond memory initialBond = _setBond(bs, tp);
newBond.init(
initialBond,
tax,
_feeWallet,
mcapToLp,
token,
router,
owner()
);
newToken.init(tp.name, tp.symbol, bond);
tokens.push(bond);
emit TokenCreated(bond, token, msg.sender);
// Transfer fee
payable(_feeWallet).transfer(creationFee);
// Refund leftover funds to the sender
uint256 leftover = amount - creationFee;
if (leftover > 0) {
payable(msg.sender).transfer(leftover);
}
return (bond, token);
}
// MARK: - Only owner functions
/**
* @dev Change tax rate.
* @param new_tax New tax .
*/
function changeTaxRate(uint16 new_tax) external onlyOwner {
tax = new_tax;
}
/**
* @dev Change owner.
* @param new_owner New owner .
*/
function changeOwner(address new_owner) external onlyOwner {
Ownable.transferOwnership(new_owner);
}
/**
* @dev Change fee wallet.
* @param new_wallet New wallet .
*/
function changeFeeWallet(address new_wallet) external onlyOwner {
if (new_wallet == address(0)) {
revert LOL_Factory__InvalidAddress(address(0));
}
_feeWallet = new_wallet;
}
/**
* @dev Change router address.
* @param new_router New router.
*/
function changeRouter(address new_router) external onlyOwner {
if (new_router == address(0)) {
revert LOL_Factory__InvalidAddress(address(0));
}
router = new_router;
}
/**
* @dev Change required native amount to created lp.
* @param amount amount native funds .
*/
function changeMcapToLp(uint256 amount) external onlyOwner {
mcapToLp = amount;
}
/**
* @dev Change required native amount to created tokens.
* @param new_fee amount native funds .
*/
function changeCreationFee(uint256 new_fee) external onlyOwner {
creationFee = new_fee;
}
// MARK: - Utility functions
/**
* @dev Returns the number of tokens in the factory.
* @return The number of tokens in the factory.
*/
function tokenCount() external view returns (uint256) {
return tokens.length;
}
/**
* @dev Get all tokens address in the range where start <= id < stop.
* @param start The starting index of the range.
* @param stop The ending index of the range.
* @return info An array of addresses.
*/
function getList(
uint256 start,
uint256 stop
) external view returns (address[] memory info) {
if (start >= stop || stop - start > 1000)
revert LOL_Factory__InvalidPaginationParameters();
uint256 tokensLength = tokens.length;
if (stop > tokensLength) {
stop = tokensLength;
}
uint256 arrayLength = stop - start;
info = new address[](arrayLength);
uint256 j;
for (uint256 i = start; i < stop; ++i) {
info[j++] = tokens[i];
}
}
/**
* @dev Validates the token creation parameters.
* @param tp The token parameters.
*/
function _validateTokenParams(TokenParams calldata tp) private pure {
if (bytes(tp.name).length == 0)
revert LOL_Factory__InvalidCreationTokenParams("name");
if (bytes(tp.symbol).length == 0)
revert LOL_Factory__InvalidCreationTokenParams("symbol");
}
/**
* @dev Validates the bond step.
* @param bs The bond step.
*/
function _validateBondParams(LOL_Bond.BondStep[] calldata bs) private view {
if (bs.length == 0 || bs.length > MAX_STEPS)
revert LOL_Factory__InvalidStepParams("INVALID_STEP_LENGTH");
// Last value or the rangeTo must be the same as the maxSupply
if (bs[bs.length - 1].rangeTo != MAX_SUPPLY)
revert LOL_Factory__InvalidStepParams("MAX_SUPPLY_MISMATCH");
}
/**
* @dev Sets the bond parameters for a token.
* @param tp Token params.
* @param bs The bond step.
*/
function _setBond(
LOL_Bond.BondStep[] calldata bs,
TokenParams calldata tp
) private view returns (LOL_Bond.Bond memory) {
uint256 multiFactor = 10 ** 18;
for (uint256 i = 0; i < bs.length; ++i) {
uint256 stepRange = bs[i].rangeTo;
uint256 stepPrice = bs[i].price;
if (stepRange == 0) {
revert LOL_Factory__InvalidStepParams("STEP_CANNOT_BE_ZERO");
} else if (stepPrice > 0 && stepRange * stepPrice < multiFactor) {
// To minimize rounding errors, the product of the range and price must be at least multiFactor (1e18 for ERC20, 1 for ERC1155).
revert LOL_Factory__InvalidStepParams(
"STEP_RANGE_OR_PRICE_TOO_SMALL"
);
}
// Ranges and prices must be strictly increasing
if (i > 0) {
if (stepRange <= bs[i - 1].rangeTo)
revert LOL_Factory__InvalidStepParams("DECREASING_RANGE");
if (stepPrice <= bs[i - 1].price)
revert LOL_Factory__InvalidStepParams("DECREASING_PRICE");
}
}
// Set token bond data
LOL_Bond.Bond memory bond = LOL_Bond.Bond({
steps: bs,
creator: msg.sender,
name: tp.name,
symbol: tp.symbol,
totalSupply: 0,
reserveBalance: 0,
decimals: 18,
lpCreated: false
});
return bond;
}
}// 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);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/Clones.sol)
pragma solidity ^0.8.20;
/**
* @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
* deploying minimal proxy contracts, also known as "clones".
*
* > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
* > a minimal bytecode implementation that delegates all calls to a known, fixed address.
*
* The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
* (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
* deterministic method.
*/
library Clones {
/**
* @dev A clone instance deployment failed.
*/
error ERC1167FailedCreateClone();
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
*
* This function uses the create opcode, which should never revert.
*/
function clone(address implementation) internal returns (address instance) {
/// @solidity memory-safe-assembly
assembly {
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
// of the `implementation` address with the bytecode before the address.
mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
instance := create(0, 0x09, 0x37)
}
if (instance == address(0)) {
revert ERC1167FailedCreateClone();
}
}
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
*
* This function uses the create2 opcode and a `salt` to deterministically deploy
* the clone. Using the same `implementation` and `salt` multiple time will revert, since
* the clones cannot be deployed twice at the same address.
*/
function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
/// @solidity memory-safe-assembly
assembly {
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
// of the `implementation` address with the bytecode before the address.
mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
instance := create2(0, 0x09, 0x37, salt)
}
if (instance == address(0)) {
revert ERC1167FailedCreateClone();
}
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(
address implementation,
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(add(ptr, 0x38), deployer)
mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff)
mstore(add(ptr, 0x14), implementation)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73)
mstore(add(ptr, 0x58), salt)
mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37))
predicted := keccak256(add(ptr, 0x43), 0x55)
}
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(
address implementation,
bytes32 salt
) internal view returns (address predicted) {
return predictDeterministicAddress(implementation, salt, address(this));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 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 {
using Address for address;
/**
* @dev An operation with an ERC20 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 Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
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.
*/
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.
*/
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 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).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
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 silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}// 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;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
return a / b;
}
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
}pragma solidity >=0.6.2;
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.20;
interface LOL_ICommonToken {
function totalSupply() external view returns (uint256);
function mintByBond(address to, uint256 amount) external;
function burnByBond(address account, uint256 amount) external;
function decimals() external pure returns (uint8);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {Context} from "@openzeppelin/contracts/utils/Context.sol";
import {IERC20Errors} from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
/**
* @notice A slightly modified version of ERC20 (from OpenZeppelin 5.0.0) for initialization pattern.
* Modifications are marekd with the MODIFIED tag.
*/
abstract contract ERC20Initializable is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply;
string internal _name; // MODIFIED
string internal _symbol; // MODIFIED
// MODIFIED: Removed for initialization pattern
// constructor(string memory name_, string memory symbol_) {
// _name = name_;
// _symbol = symbol_;
// }
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
* ```
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.20;
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {LOL_Token} from "./LOL_Token.sol";
import {LOL_ICommonToken} from "./interfaces/LOL_ICommonToken.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {IUniswapV2Router01} from "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router01.sol";
/**
* @title Projektlol LOL_Bond
* @dev Providing liquidity for Projektlol tokens with a bonding curve.
*/
contract LOL_Bond {
using SafeERC20 for IERC20;
using SafeCast for uint256;
// Error messages
error LOL_Bond__ExceedMaxSupply();
error LOL_Bond__SlippageLimitExceeded();
error LOL_Bond__InvalidTokenAmount();
error LOL_Bond__ExceedTotalSupply();
error LOL_Bond__InvalidCurrentSupply();
error LOL_Bond__InvalidReceiver();
error LOL_Bond__AlreadyInitialized();
error LOL_Bond__NotPermission();
error LOL_Bond__FailedToApprove();
error LOL_Bond__InvalidReserveAmount();
error LOL_Bond__InsufficientReserve();
error LOL_Bond__FundsTransferFailed();
error LOL_Bond__Overflow();
error LOL_Bond__InvalidAddress(address adr);
uint256 private immutable RATIO_BASE = 1000;
uint256 private immutable MAX_SUPPLY =
21_000_000_000_000_000_000_000_000_000;
uint256 private constant MAX_INT = type(uint256).max;
address private _owner;
address public token;
address public router;
uint16 private _tax;
address private _taxWallet;
Bond public bond;
uint256 private _mcapToLp;
bool private _initialized; // false by default
struct Bond {
string name;
string symbol;
uint256 totalSupply;
uint256 reserveBalance;
BondStep[] steps;
address creator;
uint8 decimals;
bool lpCreated;
}
// Use uint128 to save storage cost & prevent integer overflow when calculating range * price
struct BondStep {
uint128 rangeTo;
uint128 price;
}
event Mint(
address indexed token,
address indexed user,
address receiver,
uint256 amountMinted,
uint256 reserveAmount
);
event Burn(
address indexed token,
address indexed user,
address receiver,
uint256 amountBurned,
uint256 refundAmount
);
event PairCreated(
address indexed tokenA,
address indexed tokenB,
address pair
);
event LiquidityAdded(uint amount);
// MARK: - Initialize
/**
* @dev Initializes the bond contract with the provided params.
* @param bond_ Bond params, include name, symbol, steps, and other informations.
* @param tax The tax rate
* @param taxWallet Tax wallet address
* @param mcapToLp The amount of native funds with which you can create an lp.
* @param token_ Token address.
* @param router_ Router address, needed to create lp on dex.
*/
function init(
Bond calldata bond_,
uint16 tax,
address taxWallet,
uint256 mcapToLp,
address token_,
address router_,
address owner_
) external {
if (_initialized) revert LOL_Bond__AlreadyInitialized();
_initialized = true;
token = token_;
_tax = tax;
_taxWallet = taxWallet;
_mcapToLp = mcapToLp;
router = router_;
_owner = owner_;
bond.name = bond_.name;
bond.symbol = bond_.symbol;
bond.totalSupply = bond_.totalSupply;
bond.reserveBalance = bond_.reserveBalance;
bond.creator = bond_.creator;
bond.decimals = bond_.decimals;
bond.lpCreated = bond_.lpCreated;
// Operation necessary because data cannot be copied from calldata to contract storage.
for (uint i = 0; i < bond_.steps.length; i++) {
bond.steps.push(bond_.steps[i]);
}
}
receive() external payable {}
modifier onlyOwner() {
if (_owner != msg.sender) revert LOL_Bond__NotPermission();
_;
}
// MARK: - Mint
/**
* @dev Mint new tokens by depositing native funds.
* @param receiver The address to receive the minted tokens.
*/
function mint(
address receiver
) external payable returns (uint256, uint256) {
if (bond.lpCreated) revert LOL_Bond__NotPermission();
if (receiver == address(0)) revert LOL_Bond__InvalidReceiver();
uint256 maxAmount = msg.value;
(
uint256 tokensToMint,
uint256 reserveUsed,
uint256 tax
) = getTokensForReserve(maxAmount);
if ((reserveUsed + tax) > maxAmount)
revert LOL_Bond__SlippageLimitExceeded();
address user = msg.sender;
// Update reserve & supply
bond.reserveBalance += reserveUsed;
bond.totalSupply += tokensToMint;
// Mint reward tokens to the receiver
LOL_ICommonToken(token).mintByBond(receiver, tokensToMint);
emit Mint(token, user, receiver, tokensToMint, reserveUsed);
// Transfer tax
payable(_taxWallet).transfer(tax);
// Refund leftover funds to the sender
uint256 leftover = maxAmount - (reserveUsed + tax);
if (leftover > 0) {
payable(user).transfer(leftover);
}
uint256 totalCost = reserveUsed + tax;
return (tokensToMint, totalCost);
}
/**
* @dev Retrieves the tokens amount to mint, reserve amount and tax for a given native funds.
* @param reserveAmount The number of native funds.
* @return tokensToMint The amount of tokens to mint.
* @return reserveUsed The reserve amount required to mint the specified number of tokens.
* @return tax The tax amount to be send to the tax wallet.
*/
function getTokensForReserve(
uint256 reserveAmount
) public view returns (uint256, uint256, uint256) {
if (reserveAmount == 0) {
revert LOL_Bond__InvalidReserveAmount();
}
uint256 tax = _calculateTax(reserveAmount);
uint256 newReserveAmount = reserveAmount - tax;
uint256 currentSupply = bond.totalSupply;
uint256 tokensToMint = 0;
uint256 reserveUsed = 0;
uint256 multiFactor = 10 ** bond.decimals; // 18
if (currentSupply == MAX_SUPPLY) revert LOL_Bond__ExceedMaxSupply();
for (uint256 i = 0; i < bond.steps.length; i++) {
BondStep memory step = bond.steps[i];
if (
currentSupply >= step.rangeTo || reserveUsed >= newReserveAmount
) {
continue;
}
uint256 maxTokensInStep = step.rangeTo - currentSupply;
(bool result, uint256 reserveAvailable) = Math.trySub(
newReserveAmount,
reserveUsed
);
if (!result) revert LOL_Bond__Overflow();
(bool result_, uint256 tokens_for_step_temp) = Math.tryMul(
reserveAvailable,
multiFactor
);
if (!result_) revert LOL_Bond__Overflow();
uint256 tokensForStep = Math.min(
tokens_for_step_temp / step.price,
maxTokensInStep
);
if (tokensForStep == 0) {
break;
}
uint256 stepReserve = Math.mulDiv(
tokensForStep,
step.price,
multiFactor
);
tokensToMint = tokensToMint += tokensForStep;
currentSupply = currentSupply += tokensForStep;
reserveUsed = reserveUsed += stepReserve;
if (currentSupply >= MAX_SUPPLY) {
break;
}
}
if (tokensToMint == 0) {
revert LOL_Bond__InsufficientReserve();
}
//There is no need to check if reserveUsed < newReserveAmount, because leftover funds are sent to the sender
return (tokensToMint, reserveUsed, tax);
}
// MARK: - Burn
/**
* @dev Calculates the refund amount and royalty for a given amount of tokens to burn.
* @param tokensToBurn The amount of tokens to burn.
* @return refundAmount The amount to be refunded.
* @return tax The tax amount to be send to the tax wallet.
*/
function getRefundForTokens(
uint256 tokensToBurn
) public view returns (uint256 refundAmount, uint256 tax) {
if (tokensToBurn == 0) revert LOL_Bond__InvalidTokenAmount();
// Store bond.steps in memory to minimize sloads
BondStep[] memory steps = bond.steps;
uint256 currentSupply = bond.totalSupply;
if (tokensToBurn > currentSupply) revert LOL_Bond__ExceedTotalSupply();
uint256 multiFactor = 10 ** bond.decimals;
uint256 reserveFromBond;
uint256 tokensLeft = tokensToBurn;
uint256 i = _getCurrentStep(currentSupply);
while (tokensLeft > 0) {
uint256 supplyLeft = i == 0
? currentSupply
: currentSupply - steps[i - 1].rangeTo;
uint256 tokensToProcess = tokensLeft < supplyLeft
? tokensLeft
: supplyLeft;
reserveFromBond += Math.mulDiv(
tokensToProcess,
steps[i].price,
multiFactor
);
tokensLeft -= tokensToProcess;
currentSupply -= tokensToProcess;
if (i > 0) --i;
}
// tokensLeft > 0 -> can never happen
if (tokensLeft > 0) revert LOL_Bond__InvalidTokenAmount();
tax = _calculateTax(reserveFromBond);
uint256 contractBalance = address(this).balance;
refundAmount = reserveFromBond - tax;
// Pay special attention to the tax adjustment at the end of the function.
// This was added to contract a specific issue with rounding during full balance withdrawals.
// The problem that occurred: reserve = 974999999999999999, refund+tax = 975000000000000022
// contractBalance =/= refund amount + tax.
// We reduce the amount of tax
if ((refundAmount + tax) > contractBalance) {
uint256 excess = reserveFromBond - contractBalance;
if (tax > excess) {
tax -= excess;
} else {
tax = 0;
}
}
}
/**
* @dev Burn tokens and receive funds as refund.
* @param tokensToBurn The amount of tokens to burn.
* @param minRefund The minimum refund amount required.
* @param receiver The address to receive the refund.
*/
function burn(
uint256 tokensToBurn,
uint256 minRefund,
address receiver
) external returns (uint256) {
if (bond.lpCreated) revert LOL_Bond__NotPermission();
if (receiver == address(0)) revert LOL_Bond__InvalidReceiver();
(uint256 refundAmount, uint256 tax) = getRefundForTokens(tokensToBurn);
if (refundAmount < minRefund) revert LOL_Bond__SlippageLimitExceeded();
address user = msg.sender;
// Update reserve & supply
bond.reserveBalance -= (refundAmount + tax);
bond.totalSupply -= tokensToBurn;
// Receive tokens to burn
IERC20 t = IERC20(token);
t.safeTransferFrom(user, address(this), tokensToBurn);
// Burn tokens from the user
LOL_ICommonToken(token).burnByBond(address(this), tokensToBurn);
emit Burn(token, user, receiver, tokensToBurn, refundAmount);
// Transfer tax
payable(_taxWallet).transfer(tax);
// Refund funds to the receiver
payable(receiver).transfer(refundAmount);
return refundAmount;
}
// MARK: - Utility functions
/**
* @dev Returns the price for the next mint of a token
* @return The price at the next step of the bonding curve
*/
function _priceForNextMint() private view returns (uint128) {
uint256 currentSupply = bond.totalSupply;
if (currentSupply < MAX_SUPPLY) {
++currentSupply; // Ensure currentSupply is in the next range
}
uint256 i = _getCurrentStep(currentSupply);
return bond.steps[i].price;
}
struct BondInfo {
address creator;
address token;
uint8 decimals;
string symbol;
string name;
uint256 currentSupply;
uint128 priceForNextMint;
uint256 reserveBalance;
bool lpCreated;
}
struct BondDetail {
BondInfo info;
BondStep[] steps;
}
/**
* @dev Retrieves the details of a bond token.
* @return detail The BondDetail struct containing the bond info, and steps of the bond.
*/
function getDetail() external view returns (BondDetail memory detail) {
detail = BondDetail({info: _getBondInfo(), steps: bond.steps});
}
function _getBondInfo() private view returns (BondInfo memory info) {
info = BondInfo({
creator: bond.creator,
token: token,
decimals: bond.decimals,
symbol: bond.symbol,
name: bond.name,
currentSupply: bond.totalSupply,
priceForNextMint: _priceForNextMint(),
reserveBalance: bond.reserveBalance,
lpCreated: bond.lpCreated
});
}
/**
* @dev Calculates the tax amount.
* @return The calculated tax amount.
*/
function _calculateTax(uint256 amount) private view returns (uint256) {
return (amount * _tax) / RATIO_BASE;
}
/**
* @dev Calculates the tokens amount required to the create lp on the dex with actual price on the bonding curve contract.
* @return The calculated tokens amount.
*/
function _calculateTokensToMint() private view returns (uint256) {
uint256 i = _getCurrentStep(bond.totalSupply);
uint128 currentPrice = bond.steps[i].price;
uint256 multiFactor = 10 ** bond.decimals;
return Math.mulDiv(bond.reserveBalance, multiFactor, currentPrice);
}
/**
* @dev Check status bonding curve contract, does he have enough native funds to make an lp.
* @return result as a result of the operation.
*/
function getStatusForLp() public view returns (bool result) {
result = bond.reserveBalance >= _mcapToLp;
}
/**
* @dev Create LP and provide liquidity to the pair if there are enough funds. Any user can trigger it.
* @return amountToken used to create lp.
* @return amountNative used to create lp.
* @return liquidity amount of liquidity created.
*/
function createLiquidity() external returns (uint, uint, uint) {
if (!getStatusForLp() || bond.lpCreated || router == address(0))
revert LOL_Bond__NotPermission();
uint256 balance = address(this).balance;
uint256 tokens = _calculateTokensToMint();
bond.lpCreated = true;
bond.totalSupply += tokens;
bond.reserveBalance = 0;
LOL_ICommonToken(token).mintByBond(address(this), tokens);
if (!IERC20(token).approve(router, tokens))
revert LOL_Bond__FailedToApprove();
IUniswapV2Router01 router_ = IUniswapV2Router01(router);
(uint amountToken, uint amountNative, uint liquidity) = router_
.addLiquidityETH{value: balance}(
token,
tokens,
tokens,
balance,
address(0),
block.timestamp
);
emit LiquidityAdded(liquidity);
return (amountToken, amountNative, liquidity);
}
/**
* @dev Retrieves the current step for a given current supply.
* @param currentSupply The current supply of the token.
* @return The index of the current step.
*/
function _getCurrentStep(
uint256 currentSupply
) private view returns (uint256) {
for (uint256 i = 0; i < bond.steps.length; ++i) {
if (currentSupply <= bond.steps[i].rangeTo) {
return i;
}
}
revert LOL_Bond__InvalidCurrentSupply(); // can never happen
}
}// SPDX-License-Identifier: MIT
pragma solidity =0.8.20;
import {ERC20Initializable} from "./lib/ERC20Initializable.sol";
/**
* @title Projektlol LOL_Token
* @dev A token contract that implements a bonding curve and allows minting and burning of tokens.
*/
contract LOL_Token is ERC20Initializable {
error LOL_Token__AlreadyInitialized();
error LOL_Token__PermissionDenied();
bool private _initialized; // false by default
address public bond; // Bonding curve contract should have its minting permission
/**
* @dev Initializes the token contract with the provided name and symbol.
* @param name_ The name of the token.
* @param symbol_ The symbol of the token.
* @param bond_ The address bonding curve contract
*/
function init(string calldata name_, string calldata symbol_, address bond_) external {
if(_initialized) revert LOL_Token__AlreadyInitialized();
_initialized = true;
_name = name_;
_symbol = symbol_;
bond = bond_;
}
modifier onlyBond() {
if (bond != _msgSender()) revert LOL_Token__PermissionDenied();
_;
}
/**
* @dev Mint tokens by the bonding curve contract.
* Minting should also provide liquidity to the bonding curve contract.
* @param to The address to which the minted tokens will be transferred.
* @param amount The amount of tokens to mint.
*/
function mintByBond(address to, uint256 amount) external onlyBond {
_mint(to, amount);
}
/**
* @dev Burns tokens by the bonding curve contract.
* Burning tokens affects the bonding curve.
* Users can simply send tokens to the token contract address for the same burning effect without changing the totalSupply.
* @param account The address from which the tokens will be burned.
* @param amount The amount of tokens to burn.
*/
function burnByBond(address account, uint256 amount) external onlyBond {
_burn(account, amount);
}
}{
"evmVersion": "paris",
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"tokenImplementation","type":"address"},{"internalType":"address","name":"bondImplementation","type":"address"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"router_","type":"address"},{"internalType":"address","name":"feeWallet_","type":"address"},{"internalType":"uint256","name":"maxSteps","type":"uint256"},{"internalType":"uint256","name":"creationFee_","type":"uint256"},{"internalType":"uint16","name":"tax_","type":"uint16"},{"internalType":"uint256","name":"mcapToLp_","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ERC1167FailedCreateClone","type":"error"},{"inputs":[],"name":"LOL_Factory__CreationTokenFeeTransactionFailed","type":"error"},{"inputs":[],"name":"LOL_Factory__FundsTransferFailed","type":"error"},{"inputs":[{"internalType":"address","name":"adr","type":"address"}],"name":"LOL_Factory__InvalidAddress","type":"error"},{"inputs":[{"internalType":"string","name":"reason","type":"string"}],"name":"LOL_Factory__InvalidConstructorParams","type":"error"},{"inputs":[],"name":"LOL_Factory__InvalidCreationTokenFee","type":"error"},{"inputs":[{"internalType":"string","name":"reason","type":"string"}],"name":"LOL_Factory__InvalidCreationTokenParams","type":"error"},{"inputs":[],"name":"LOL_Factory__InvalidPaginationParameters","type":"error"},{"inputs":[{"internalType":"string","name":"reason","type":"string"}],"name":"LOL_Factory__InvalidStepParams","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"bond","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"address","name":"user","type":"address"}],"name":"TokenCreated","type":"event"},{"inputs":[{"internalType":"uint256","name":"new_fee","type":"uint256"}],"name":"changeCreationFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"new_wallet","type":"address"}],"name":"changeFeeWallet","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"changeMcapToLp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"new_owner","type":"address"}],"name":"changeOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"new_router","type":"address"}],"name":"changeRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"new_tax","type":"uint16"}],"name":"changeTaxRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"}],"internalType":"struct LOL_Factory.TokenParams","name":"tp","type":"tuple"},{"components":[{"internalType":"uint128","name":"rangeTo","type":"uint128"},{"internalType":"uint128","name":"price","type":"uint128"}],"internalType":"struct LOL_Bond.BondStep[]","name":"bs","type":"tuple[]"}],"name":"createToken","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"creationFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"start","type":"uint256"},{"internalType":"uint256","name":"stop","type":"uint256"}],"name":"getList","outputs":[{"internalType":"address[]","name":"info","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mcapToLp","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":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"router","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tax","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokens","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]Contract Creation Code
6101006040526b43dacaf91c1a84ff080000006080908152503480156200002557600080fd5b5060405162002c2a38038062002c2a83398181016040528101906200004b9190620004fd565b86600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603620000c15760006040517f1e4fbdf7000000000000000000000000000000000000000000000000000000008152600401620000b89190620005ed565b60405180910390fd5b620000d2816200035560201b60201c565b50600073ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff160362000145576040517f6c54792f0000000000000000000000000000000000000000000000000000000081526004016200013c906200066b565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168873ffffffffffffffffffffffffffffffffffffffff1603620001b7576040517f6c54792f000000000000000000000000000000000000000000000000000000008152600401620001ae90620006dd565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff160362000229576040517f6c54792f00000000000000000000000000000000000000000000000000000000815260040162000220906200074f565b60405180910390fd5b8873ffffffffffffffffffffffffffffffffffffffff1660c08173ffffffffffffffffffffffffffffffffffffffff16815250508773ffffffffffffffffffffffffffffffffffffffff1660e08173ffffffffffffffffffffffffffffffffffffffff168152505084600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508360a081815250508260048190555081600060146101000a81548161ffff021916908361ffff1602179055508060018190555085600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050505050505050505062000771565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006200044b826200041e565b9050919050565b6200045d816200043e565b81146200046957600080fd5b50565b6000815190506200047d8162000452565b92915050565b6000819050919050565b620004988162000483565b8114620004a457600080fd5b50565b600081519050620004b8816200048d565b92915050565b600061ffff82169050919050565b620004d781620004be565b8114620004e357600080fd5b50565b600081519050620004f781620004cc565b92915050565b60008060008060008060008060006101208a8c03121562000523576200052262000419565b5b6000620005338c828d016200046c565b9950506020620005468c828d016200046c565b9850506040620005598c828d016200046c565b97505060606200056c8c828d016200046c565b96505060806200057f8c828d016200046c565b95505060a0620005928c828d01620004a7565b94505060c0620005a58c828d01620004a7565b93505060e0620005b88c828d01620004e6565b925050610100620005cc8c828d01620004a7565b9150509295985092959850929598565b620005e7816200043e565b82525050565b6000602082019050620006046000830184620005dc565b92915050565b600082825260208201905092915050565b7f746f6b656e496d706c656d656e746174696f6e00000000000000000000000000600082015250565b6000620006536013836200060a565b915062000660826200061b565b602082019050919050565b60006020820190508181036000830152620006868162000644565b9050919050565b7f626f6e64496d706c656d656e746174696f6e0000000000000000000000000000600082015250565b6000620006c56012836200060a565b9150620006d2826200068d565b602082019050919050565b60006020820190508181036000830152620006f881620006b6565b9050919050565b7f66656557616c6c65740000000000000000000000000000000000000000000000600082015250565b6000620007376009836200060a565b91506200074482620006ff565b602082019050919050565b600060208201905081810360008301526200076a8162000728565b9050919050565b60805160a05160c05160e05161247f620007ab600039600061086f0152600061082d01526000610ea601526000610f0d015261247f6000f3fe6080604052600436106101025760003560e01c80639f181b5e11610095578063b538945a11610064578063b538945a14610318578063ce123ca814610349578063dce0b4e414610372578063f2fde38b1461039d578063f887ea40146103c657610109565b80639f181b5e1461025e578063a1596c4c14610289578063a6f9dae1146102b2578063a9816b08146102db57610109565b8063715018a6116100d1578063715018a6146101c657806380154b3c146101dd5780638da5cb5b1461020857806399c8d5561461023357610109565b8063340ac20f1461010e5780633e4d0310146101375780634c718f05146101605780634f64b2be1461018957610109565b3661010957005b600080fd5b34801561011a57600080fd5b5061013560048036038101906101309190611566565b6103f1565b005b34801561014357600080fd5b5061015e60048036038101906101599190611566565b6104af565b005b34801561016c57600080fd5b50610187600480360381019061018291906115c9565b61056d565b005b34801561019557600080fd5b506101b060048036038101906101ab91906115c9565b61057f565b6040516101bd9190611605565b60405180910390f35b3480156101d257600080fd5b506101db6105be565b005b3480156101e957600080fd5b506101f26105d2565b6040516101ff919061162f565b60405180910390f35b34801561021457600080fd5b5061021d6105d8565b60405161022a9190611605565b60405180910390f35b34801561023f57600080fd5b50610248610601565b6040516102559190611667565b60405180910390f35b34801561026a57600080fd5b50610273610615565b604051610280919061162f565b60405180910390f35b34801561029557600080fd5b506102b060048036038101906102ab91906115c9565b610622565b005b3480156102be57600080fd5b506102d960048036038101906102d49190611566565b610634565b005b3480156102e757600080fd5b5061030260048036038101906102fd9190611682565b610648565b60405161030f9190611780565b60405180910390f35b610332600480360381019061032d919061182b565b6107cf565b6040516103409291906118a7565b60405180910390f35b34801561035557600080fd5b50610370600480360381019061036b91906118fc565b610bc7565b005b34801561037e57600080fd5b50610387610bef565b604051610394919061162f565b60405180910390f35b3480156103a957600080fd5b506103c460048036038101906103bf9190611566565b610bf5565b005b3480156103d257600080fd5b506103db610c7b565b6040516103e89190611605565b60405180910390f35b6103f9610ca1565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff160361046b5760006040517f929a7f420000000000000000000000000000000000000000000000000000000081526004016104629190611605565b60405180910390fd5b80600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6104b7610ca1565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16036105295760006040517f929a7f420000000000000000000000000000000000000000000000000000000081526004016105209190611605565b60405180910390fd5b80600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b610575610ca1565b8060018190555050565b6002818154811061058f57600080fd5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6105c6610ca1565b6105d06000610d28565b565b60015481565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b600060149054906101000a900461ffff1681565b6000600280549050905090565b61062a610ca1565b8060048190555050565b61063c610ca1565b61064581610bf5565b50565b6060818310158061066557506103e883836106639190611958565b115b1561069c576040517f02c5bb8e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006002805490509050808311156106b2578092505b600084846106c09190611958565b90508067ffffffffffffffff8111156106dc576106db61198c565b5b60405190808252806020026020018201604052801561070a5781602001602082028036833780820191505090505b5092506000808690505b858110156107c557600281815481106107305761072f6119bb565b5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16858380610767906119ea565b94508151811061077a576107796119bb565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050806107be906119ea565b9050610714565b5050505092915050565b6000806000349050600454811015610813576040517f0216752700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61081c86610dec565b6108268585610e97565b60006108617f000000000000000000000000000000000000000000000000000000000000000088806020019061085c9190611a41565b610fbc565b9050600081905060006108a37f00000000000000000000000000000000000000000000000000000000000000008a806020019061089e9190611a41565b610fbc565b9050600081905060006108b78a8a8d611002565b90508173ffffffffffffffffffffffffffffffffffffffff1663cb53bd6182600060149054906101000a900461ffff16600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166001548a600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166109396105d8565b6040518863ffffffff1660e01b815260040161095b9796959493929190611d41565b600060405180830381600087803b15801561097557600080fd5b505af1158015610989573d6000803e3d6000fd5b505050508373ffffffffffffffffffffffffffffffffffffffff16636ee5741a8c80600001906109b99190611a41565b8e80602001906109c99190611a41565b886040518663ffffffff1660e01b81526004016109ea959493929190611e63565b600060405180830381600087803b158015610a0457600080fd5b505af1158015610a18573d6000803e3d6000fd5b505050506002839080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508473ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fb5a149b73151b44553ff737ca050c61de65038e2ae67ec044215d3261cc6fa0033604051610adc9190611605565b60405180910390a3600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc6004549081150290604051600060405180830381858888f19350505050158015610b4e573d6000803e3d6000fd5b50600060045487610b5f9190611958565b90506000811115610bb2573373ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015610bb0573d6000803e3d6000fd5b505b83869850985050505050505050935093915050565b610bcf610ca1565b80600060146101000a81548161ffff021916908361ffff16021790555050565b60045481565b610bfd610ca1565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610c6f5760006040517f1e4fbdf7000000000000000000000000000000000000000000000000000000008152600401610c669190611605565b60405180910390fd5b610c7881610d28565b50565b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b610ca96113d9565b73ffffffffffffffffffffffffffffffffffffffff16610cc76105d8565b73ffffffffffffffffffffffffffffffffffffffff1614610d2657610cea6113d9565b6040517f118cdaa7000000000000000000000000000000000000000000000000000000008152600401610d1d9190611605565b60405180910390fd5b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b6000818060000190610dfe9190611a41565b905003610e40576040517ff8f3ba12000000000000000000000000000000000000000000000000000000008152600401610e3790611ef8565b60405180910390fd5b6000818060200190610e529190611a41565b905003610e94576040517ff8f3ba12000000000000000000000000000000000000000000000000000000008152600401610e8b90611f64565b60405180910390fd5b50565b6000828290501480610ecb57507f000000000000000000000000000000000000000000000000000000000000000082829050115b15610f0b576040517f7e1f8c58000000000000000000000000000000000000000000000000000000008152600401610f0290611fd0565b60405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000008282600185859050610f3e9190611958565b818110610f4e57610f4d6119bb565b5b9050604002016000016020810190610f66919061201c565b6fffffffffffffffffffffffffffffffff1614610fb8576040517f7e1f8c58000000000000000000000000000000000000000000000000000000008152600401610faf90612095565b60405180910390fd5b5050565b60008033848442604051602001610fd6949392919061214e565b604051602081830303815290604052805190602001209050610ff885826113e1565b9150509392505050565b61100a611494565b6000670de0b6b3a7640000905060005b8585905081101561127557600086868381811061103a576110396119bb565b5b9050604002016000016020810190611052919061201c565b6fffffffffffffffffffffffffffffffff169050600087878481811061107b5761107a6119bb565b5b9050604002016020016020810190611093919061201c565b6fffffffffffffffffffffffffffffffff169050600082036110ea576040517f7e1f8c580000000000000000000000000000000000000000000000000000000081526004016110e1906121d5565b60405180910390fd5b600081118015611104575083818361110291906121f5565b105b15611144576040517f7e1f8c5800000000000000000000000000000000000000000000000000000000815260040161113b90612283565b60405180910390fd5b600083111561126257878760018561115c9190611958565b81811061116c5761116b6119bb565b5b9050604002016000016020810190611184919061201c565b6fffffffffffffffffffffffffffffffff1682116111d7576040517f7e1f8c580000000000000000000000000000000000000000000000000000000081526004016111ce906122ef565b60405180910390fd5b87876001856111e69190611958565b8181106111f6576111f56119bb565b5b905060400201602001602081019061120e919061201c565b6fffffffffffffffffffffffffffffffff168111611261576040517f7e1f8c580000000000000000000000000000000000000000000000000000000081526004016112589061235b565b60405180910390fd5b5b50508061126e906119ea565b905061101a565b5060006040518061010001604052808580600001906112949190611a41565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505081526020018580602001906112ec9190611a41565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050815260200160008152602001600081526020018787808060200260200160405190810160405280939291908181526020016000905b8282101561139457848483905060400201803603810190611385919061241c565b81526020019060010190611364565b505050505081526020013373ffffffffffffffffffffffffffffffffffffffff168152602001601260ff16815260200160001515815250905080925050509392505050565b600033905090565b6000763d602d80600a3d3981f3363d3d373d3d3d363d730000008360601b60e81c176000526e5af43d82803e903d91602b57fd5bf38360781b1760205281603760096000f59050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff160361148e576040517fc2f868f400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b92915050565b6040518061010001604052806060815260200160608152602001600081526020016000815260200160608152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600060ff1681526020016000151581525090565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061153382611508565b9050919050565b61154381611528565b811461154e57600080fd5b50565b6000813590506115608161153a565b92915050565b60006020828403121561157c5761157b6114fe565b5b600061158a84828501611551565b91505092915050565b6000819050919050565b6115a681611593565b81146115b157600080fd5b50565b6000813590506115c38161159d565b92915050565b6000602082840312156115df576115de6114fe565b5b60006115ed848285016115b4565b91505092915050565b6115ff81611528565b82525050565b600060208201905061161a60008301846115f6565b92915050565b61162981611593565b82525050565b60006020820190506116446000830184611620565b92915050565b600061ffff82169050919050565b6116618161164a565b82525050565b600060208201905061167c6000830184611658565b92915050565b60008060408385031215611699576116986114fe565b5b60006116a7858286016115b4565b92505060206116b8858286016115b4565b9150509250929050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6116f781611528565b82525050565b600061170983836116ee565b60208301905092915050565b6000602082019050919050565b600061172d826116c2565b61173781856116cd565b9350611742836116de565b8060005b8381101561177357815161175a88826116fd565b975061176583611715565b925050600181019050611746565b5085935050505092915050565b6000602082019050818103600083015261179a8184611722565b905092915050565b600080fd5b6000604082840312156117bd576117bc6117a2565b5b81905092915050565b600080fd5b600080fd5b600080fd5b60008083601f8401126117eb576117ea6117c6565b5b8235905067ffffffffffffffff811115611808576118076117cb565b5b602083019150836040820283011115611824576118236117d0565b5b9250929050565b600080600060408486031215611844576118436114fe565b5b600084013567ffffffffffffffff81111561186257611861611503565b5b61186e868287016117a7565b935050602084013567ffffffffffffffff81111561188f5761188e611503565b5b61189b868287016117d5565b92509250509250925092565b60006040820190506118bc60008301856115f6565b6118c960208301846115f6565b9392505050565b6118d98161164a565b81146118e457600080fd5b50565b6000813590506118f6816118d0565b92915050565b600060208284031215611912576119116114fe565b5b6000611920848285016118e7565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061196382611593565b915061196e83611593565b925082820390508181111561198657611985611929565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60006119f582611593565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203611a2757611a26611929565b5b600182019050919050565b600080fd5b600080fd5b600080fd5b60008083356001602003843603038112611a5e57611a5d611a32565b5b80840192508235915067ffffffffffffffff821115611a8057611a7f611a37565b5b602083019250600182023603831315611a9c57611a9b611a3c565b5b509250929050565b600081519050919050565b600082825260208201905092915050565b60005b83811015611ade578082015181840152602081019050611ac3565b60008484015250505050565b6000601f19601f8301169050919050565b6000611b0682611aa4565b611b108185611aaf565b9350611b20818560208601611ac0565b611b2981611aea565b840191505092915050565b611b3d81611593565b82525050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b60006fffffffffffffffffffffffffffffffff82169050919050565b611b9481611b6f565b82525050565b604082016000820151611bb06000850182611b8b565b506020820151611bc36020850182611b8b565b50505050565b6000611bd58383611b9a565b60408301905092915050565b6000602082019050919050565b6000611bf982611b43565b611c038185611b4e565b9350611c0e83611b5f565b8060005b83811015611c3f578151611c268882611bc9565b9750611c3183611be1565b925050600181019050611c12565b5085935050505092915050565b600060ff82169050919050565b611c6281611c4c565b82525050565b60008115159050919050565b611c7d81611c68565b82525050565b6000610100830160008301518482036000860152611ca18282611afb565b91505060208301518482036020860152611cbb8282611afb565b9150506040830151611cd06040860182611b34565b506060830151611ce36060860182611b34565b5060808301518482036080860152611cfb8282611bee565b91505060a0830151611d1060a08601826116ee565b5060c0830151611d2360c0860182611c59565b5060e0830151611d3660e0860182611c74565b508091505092915050565b600060e0820190508181036000830152611d5b818a611c83565b9050611d6a6020830189611658565b611d7760408301886115f6565b611d846060830187611620565b611d9160808301866115f6565b611d9e60a08301856115f6565b611dab60c08301846115f6565b98975050505050505050565b600082825260208201905092915050565b82818337600083830152505050565b6000611de38385611db7565b9350611df0838584611dc8565b611df983611aea565b840190509392505050565b6000819050919050565b6000611e29611e24611e1f84611508565b611e04565b611508565b9050919050565b6000611e3b82611e0e565b9050919050565b6000611e4d82611e30565b9050919050565b611e5d81611e42565b82525050565b60006060820190508181036000830152611e7e818789611dd7565b90508181036020830152611e93818587611dd7565b9050611ea26040830184611e54565b9695505050505050565b7f6e616d6500000000000000000000000000000000000000000000000000000000600082015250565b6000611ee2600483611db7565b9150611eed82611eac565b602082019050919050565b60006020820190508181036000830152611f1181611ed5565b9050919050565b7f73796d626f6c0000000000000000000000000000000000000000000000000000600082015250565b6000611f4e600683611db7565b9150611f5982611f18565b602082019050919050565b60006020820190508181036000830152611f7d81611f41565b9050919050565b7f494e56414c49445f535445505f4c454e47544800000000000000000000000000600082015250565b6000611fba601383611db7565b9150611fc582611f84565b602082019050919050565b60006020820190508181036000830152611fe981611fad565b9050919050565b611ff981611b6f565b811461200457600080fd5b50565b60008135905061201681611ff0565b92915050565b600060208284031215612032576120316114fe565b5b600061204084828501612007565b91505092915050565b7f4d41585f535550504c595f4d49534d4154434800000000000000000000000000600082015250565b600061207f601383611db7565b915061208a82612049565b602082019050919050565b600060208201905081810360008301526120ae81612072565b9050919050565b60008160601b9050919050565b60006120cd826120b5565b9050919050565b60006120df826120c2565b9050919050565b6120f76120f282611528565b6120d4565b82525050565b600081905092915050565b600061211483856120fd565b9350612121838584611dc8565b82840190509392505050565b6000819050919050565b61214861214382611593565b61212d565b82525050565b600061215a82876120e6565b60148201915061216b828587612108565b91506121778284612137565b60208201915081905095945050505050565b7f535445505f43414e4e4f545f42455f5a45524f00000000000000000000000000600082015250565b60006121bf601383611db7565b91506121ca82612189565b602082019050919050565b600060208201905081810360008301526121ee816121b2565b9050919050565b600061220082611593565b915061220b83611593565b925082820261221981611593565b915082820484148315176122305761222f611929565b5b5092915050565b7f535445505f52414e47455f4f525f50524943455f544f4f5f534d414c4c000000600082015250565b600061226d601d83611db7565b915061227882612237565b602082019050919050565b6000602082019050818103600083015261229c81612260565b9050919050565b7f44454352454153494e475f52414e474500000000000000000000000000000000600082015250565b60006122d9601083611db7565b91506122e4826122a3565b602082019050919050565b60006020820190508181036000830152612308816122cc565b9050919050565b7f44454352454153494e475f505249434500000000000000000000000000000000600082015250565b6000612345601083611db7565b91506123508261230f565b602082019050919050565b6000602082019050818103600083015261237481612338565b9050919050565b600080fd5b61238982611aea565b810181811067ffffffffffffffff821117156123a8576123a761198c565b5b80604052505050565b60006123bb6114f4565b90506123c78282612380565b919050565b6000604082840312156123e2576123e161237b565b5b6123ec60406123b1565b905060006123fc84828501612007565b600083015250602061241084828501612007565b60208301525092915050565b600060408284031215612432576124316114fe565b5b6000612440848285016123cc565b9150509291505056fea2646970667358221220963d770b9f840713514b31ac11159776637104052360db0b1698675e98d01f8564736f6c63430008140033000000000000000000000000319b3a6e65ada7f8472a789185e9bf777713ea2e000000000000000000000000b9465a3982e470a000d7f29be99de73536b6c8c2000000000000000000000000802e04873fa51e7fc72056f6b39390864c42479c00000000000000000000000070085a09d30d6f8c4ecf6ee10120d1847383bb57000000000000000000000000d370f30b3724bddb690dd98a18a20992cc394a080000000000000000000000000000000000000000000000000000000000000096000000000000000000000000000000000000000000000001158e460913d00000000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000272cdebe93fde1a00000
Deployed Bytecode
0x6080604052600436106101025760003560e01c80639f181b5e11610095578063b538945a11610064578063b538945a14610318578063ce123ca814610349578063dce0b4e414610372578063f2fde38b1461039d578063f887ea40146103c657610109565b80639f181b5e1461025e578063a1596c4c14610289578063a6f9dae1146102b2578063a9816b08146102db57610109565b8063715018a6116100d1578063715018a6146101c657806380154b3c146101dd5780638da5cb5b1461020857806399c8d5561461023357610109565b8063340ac20f1461010e5780633e4d0310146101375780634c718f05146101605780634f64b2be1461018957610109565b3661010957005b600080fd5b34801561011a57600080fd5b5061013560048036038101906101309190611566565b6103f1565b005b34801561014357600080fd5b5061015e60048036038101906101599190611566565b6104af565b005b34801561016c57600080fd5b50610187600480360381019061018291906115c9565b61056d565b005b34801561019557600080fd5b506101b060048036038101906101ab91906115c9565b61057f565b6040516101bd9190611605565b60405180910390f35b3480156101d257600080fd5b506101db6105be565b005b3480156101e957600080fd5b506101f26105d2565b6040516101ff919061162f565b60405180910390f35b34801561021457600080fd5b5061021d6105d8565b60405161022a9190611605565b60405180910390f35b34801561023f57600080fd5b50610248610601565b6040516102559190611667565b60405180910390f35b34801561026a57600080fd5b50610273610615565b604051610280919061162f565b60405180910390f35b34801561029557600080fd5b506102b060048036038101906102ab91906115c9565b610622565b005b3480156102be57600080fd5b506102d960048036038101906102d49190611566565b610634565b005b3480156102e757600080fd5b5061030260048036038101906102fd9190611682565b610648565b60405161030f9190611780565b60405180910390f35b610332600480360381019061032d919061182b565b6107cf565b6040516103409291906118a7565b60405180910390f35b34801561035557600080fd5b50610370600480360381019061036b91906118fc565b610bc7565b005b34801561037e57600080fd5b50610387610bef565b604051610394919061162f565b60405180910390f35b3480156103a957600080fd5b506103c460048036038101906103bf9190611566565b610bf5565b005b3480156103d257600080fd5b506103db610c7b565b6040516103e89190611605565b60405180910390f35b6103f9610ca1565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff160361046b5760006040517f929a7f420000000000000000000000000000000000000000000000000000000081526004016104629190611605565b60405180910390fd5b80600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b6104b7610ca1565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16036105295760006040517f929a7f420000000000000000000000000000000000000000000000000000000081526004016105209190611605565b60405180910390fd5b80600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b610575610ca1565b8060018190555050565b6002818154811061058f57600080fd5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6105c6610ca1565b6105d06000610d28565b565b60015481565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b600060149054906101000a900461ffff1681565b6000600280549050905090565b61062a610ca1565b8060048190555050565b61063c610ca1565b61064581610bf5565b50565b6060818310158061066557506103e883836106639190611958565b115b1561069c576040517f02c5bb8e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006002805490509050808311156106b2578092505b600084846106c09190611958565b90508067ffffffffffffffff8111156106dc576106db61198c565b5b60405190808252806020026020018201604052801561070a5781602001602082028036833780820191505090505b5092506000808690505b858110156107c557600281815481106107305761072f6119bb565b5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16858380610767906119ea565b94508151811061077a576107796119bb565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050806107be906119ea565b9050610714565b5050505092915050565b6000806000349050600454811015610813576040517f0216752700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61081c86610dec565b6108268585610e97565b60006108617f000000000000000000000000319b3a6e65ada7f8472a789185e9bf777713ea2e88806020019061085c9190611a41565b610fbc565b9050600081905060006108a37f000000000000000000000000b9465a3982e470a000d7f29be99de73536b6c8c28a806020019061089e9190611a41565b610fbc565b9050600081905060006108b78a8a8d611002565b90508173ffffffffffffffffffffffffffffffffffffffff1663cb53bd6182600060149054906101000a900461ffff16600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166001548a600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166109396105d8565b6040518863ffffffff1660e01b815260040161095b9796959493929190611d41565b600060405180830381600087803b15801561097557600080fd5b505af1158015610989573d6000803e3d6000fd5b505050508373ffffffffffffffffffffffffffffffffffffffff16636ee5741a8c80600001906109b99190611a41565b8e80602001906109c99190611a41565b886040518663ffffffff1660e01b81526004016109ea959493929190611e63565b600060405180830381600087803b158015610a0457600080fd5b505af1158015610a18573d6000803e3d6000fd5b505050506002839080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508473ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fb5a149b73151b44553ff737ca050c61de65038e2ae67ec044215d3261cc6fa0033604051610adc9190611605565b60405180910390a3600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc6004549081150290604051600060405180830381858888f19350505050158015610b4e573d6000803e3d6000fd5b50600060045487610b5f9190611958565b90506000811115610bb2573373ffffffffffffffffffffffffffffffffffffffff166108fc829081150290604051600060405180830381858888f19350505050158015610bb0573d6000803e3d6000fd5b505b83869850985050505050505050935093915050565b610bcf610ca1565b80600060146101000a81548161ffff021916908361ffff16021790555050565b60045481565b610bfd610ca1565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610c6f5760006040517f1e4fbdf7000000000000000000000000000000000000000000000000000000008152600401610c669190611605565b60405180910390fd5b610c7881610d28565b50565b600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b610ca96113d9565b73ffffffffffffffffffffffffffffffffffffffff16610cc76105d8565b73ffffffffffffffffffffffffffffffffffffffff1614610d2657610cea6113d9565b6040517f118cdaa7000000000000000000000000000000000000000000000000000000008152600401610d1d9190611605565b60405180910390fd5b565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b6000818060000190610dfe9190611a41565b905003610e40576040517ff8f3ba12000000000000000000000000000000000000000000000000000000008152600401610e3790611ef8565b60405180910390fd5b6000818060200190610e529190611a41565b905003610e94576040517ff8f3ba12000000000000000000000000000000000000000000000000000000008152600401610e8b90611f64565b60405180910390fd5b50565b6000828290501480610ecb57507f000000000000000000000000000000000000000000000000000000000000009682829050115b15610f0b576040517f7e1f8c58000000000000000000000000000000000000000000000000000000008152600401610f0290611fd0565b60405180910390fd5b7f000000000000000000000000000000000000000043dacaf91c1a84ff080000008282600185859050610f3e9190611958565b818110610f4e57610f4d6119bb565b5b9050604002016000016020810190610f66919061201c565b6fffffffffffffffffffffffffffffffff1614610fb8576040517f7e1f8c58000000000000000000000000000000000000000000000000000000008152600401610faf90612095565b60405180910390fd5b5050565b60008033848442604051602001610fd6949392919061214e565b604051602081830303815290604052805190602001209050610ff885826113e1565b9150509392505050565b61100a611494565b6000670de0b6b3a7640000905060005b8585905081101561127557600086868381811061103a576110396119bb565b5b9050604002016000016020810190611052919061201c565b6fffffffffffffffffffffffffffffffff169050600087878481811061107b5761107a6119bb565b5b9050604002016020016020810190611093919061201c565b6fffffffffffffffffffffffffffffffff169050600082036110ea576040517f7e1f8c580000000000000000000000000000000000000000000000000000000081526004016110e1906121d5565b60405180910390fd5b600081118015611104575083818361110291906121f5565b105b15611144576040517f7e1f8c5800000000000000000000000000000000000000000000000000000000815260040161113b90612283565b60405180910390fd5b600083111561126257878760018561115c9190611958565b81811061116c5761116b6119bb565b5b9050604002016000016020810190611184919061201c565b6fffffffffffffffffffffffffffffffff1682116111d7576040517f7e1f8c580000000000000000000000000000000000000000000000000000000081526004016111ce906122ef565b60405180910390fd5b87876001856111e69190611958565b8181106111f6576111f56119bb565b5b905060400201602001602081019061120e919061201c565b6fffffffffffffffffffffffffffffffff168111611261576040517f7e1f8c580000000000000000000000000000000000000000000000000000000081526004016112589061235b565b60405180910390fd5b5b50508061126e906119ea565b905061101a565b5060006040518061010001604052808580600001906112949190611a41565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505081526020018580602001906112ec9190611a41565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050815260200160008152602001600081526020018787808060200260200160405190810160405280939291908181526020016000905b8282101561139457848483905060400201803603810190611385919061241c565b81526020019060010190611364565b505050505081526020013373ffffffffffffffffffffffffffffffffffffffff168152602001601260ff16815260200160001515815250905080925050509392505050565b600033905090565b6000763d602d80600a3d3981f3363d3d373d3d3d363d730000008360601b60e81c176000526e5af43d82803e903d91602b57fd5bf38360781b1760205281603760096000f59050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff160361148e576040517fc2f868f400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b92915050565b6040518061010001604052806060815260200160608152602001600081526020016000815260200160608152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600060ff1681526020016000151581525090565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061153382611508565b9050919050565b61154381611528565b811461154e57600080fd5b50565b6000813590506115608161153a565b92915050565b60006020828403121561157c5761157b6114fe565b5b600061158a84828501611551565b91505092915050565b6000819050919050565b6115a681611593565b81146115b157600080fd5b50565b6000813590506115c38161159d565b92915050565b6000602082840312156115df576115de6114fe565b5b60006115ed848285016115b4565b91505092915050565b6115ff81611528565b82525050565b600060208201905061161a60008301846115f6565b92915050565b61162981611593565b82525050565b60006020820190506116446000830184611620565b92915050565b600061ffff82169050919050565b6116618161164a565b82525050565b600060208201905061167c6000830184611658565b92915050565b60008060408385031215611699576116986114fe565b5b60006116a7858286016115b4565b92505060206116b8858286016115b4565b9150509250929050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6116f781611528565b82525050565b600061170983836116ee565b60208301905092915050565b6000602082019050919050565b600061172d826116c2565b61173781856116cd565b9350611742836116de565b8060005b8381101561177357815161175a88826116fd565b975061176583611715565b925050600181019050611746565b5085935050505092915050565b6000602082019050818103600083015261179a8184611722565b905092915050565b600080fd5b6000604082840312156117bd576117bc6117a2565b5b81905092915050565b600080fd5b600080fd5b600080fd5b60008083601f8401126117eb576117ea6117c6565b5b8235905067ffffffffffffffff811115611808576118076117cb565b5b602083019150836040820283011115611824576118236117d0565b5b9250929050565b600080600060408486031215611844576118436114fe565b5b600084013567ffffffffffffffff81111561186257611861611503565b5b61186e868287016117a7565b935050602084013567ffffffffffffffff81111561188f5761188e611503565b5b61189b868287016117d5565b92509250509250925092565b60006040820190506118bc60008301856115f6565b6118c960208301846115f6565b9392505050565b6118d98161164a565b81146118e457600080fd5b50565b6000813590506118f6816118d0565b92915050565b600060208284031215611912576119116114fe565b5b6000611920848285016118e7565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061196382611593565b915061196e83611593565b925082820390508181111561198657611985611929565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60006119f582611593565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203611a2757611a26611929565b5b600182019050919050565b600080fd5b600080fd5b600080fd5b60008083356001602003843603038112611a5e57611a5d611a32565b5b80840192508235915067ffffffffffffffff821115611a8057611a7f611a37565b5b602083019250600182023603831315611a9c57611a9b611a3c565b5b509250929050565b600081519050919050565b600082825260208201905092915050565b60005b83811015611ade578082015181840152602081019050611ac3565b60008484015250505050565b6000601f19601f8301169050919050565b6000611b0682611aa4565b611b108185611aaf565b9350611b20818560208601611ac0565b611b2981611aea565b840191505092915050565b611b3d81611593565b82525050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b60006fffffffffffffffffffffffffffffffff82169050919050565b611b9481611b6f565b82525050565b604082016000820151611bb06000850182611b8b565b506020820151611bc36020850182611b8b565b50505050565b6000611bd58383611b9a565b60408301905092915050565b6000602082019050919050565b6000611bf982611b43565b611c038185611b4e565b9350611c0e83611b5f565b8060005b83811015611c3f578151611c268882611bc9565b9750611c3183611be1565b925050600181019050611c12565b5085935050505092915050565b600060ff82169050919050565b611c6281611c4c565b82525050565b60008115159050919050565b611c7d81611c68565b82525050565b6000610100830160008301518482036000860152611ca18282611afb565b91505060208301518482036020860152611cbb8282611afb565b9150506040830151611cd06040860182611b34565b506060830151611ce36060860182611b34565b5060808301518482036080860152611cfb8282611bee565b91505060a0830151611d1060a08601826116ee565b5060c0830151611d2360c0860182611c59565b5060e0830151611d3660e0860182611c74565b508091505092915050565b600060e0820190508181036000830152611d5b818a611c83565b9050611d6a6020830189611658565b611d7760408301886115f6565b611d846060830187611620565b611d9160808301866115f6565b611d9e60a08301856115f6565b611dab60c08301846115f6565b98975050505050505050565b600082825260208201905092915050565b82818337600083830152505050565b6000611de38385611db7565b9350611df0838584611dc8565b611df983611aea565b840190509392505050565b6000819050919050565b6000611e29611e24611e1f84611508565b611e04565b611508565b9050919050565b6000611e3b82611e0e565b9050919050565b6000611e4d82611e30565b9050919050565b611e5d81611e42565b82525050565b60006060820190508181036000830152611e7e818789611dd7565b90508181036020830152611e93818587611dd7565b9050611ea26040830184611e54565b9695505050505050565b7f6e616d6500000000000000000000000000000000000000000000000000000000600082015250565b6000611ee2600483611db7565b9150611eed82611eac565b602082019050919050565b60006020820190508181036000830152611f1181611ed5565b9050919050565b7f73796d626f6c0000000000000000000000000000000000000000000000000000600082015250565b6000611f4e600683611db7565b9150611f5982611f18565b602082019050919050565b60006020820190508181036000830152611f7d81611f41565b9050919050565b7f494e56414c49445f535445505f4c454e47544800000000000000000000000000600082015250565b6000611fba601383611db7565b9150611fc582611f84565b602082019050919050565b60006020820190508181036000830152611fe981611fad565b9050919050565b611ff981611b6f565b811461200457600080fd5b50565b60008135905061201681611ff0565b92915050565b600060208284031215612032576120316114fe565b5b600061204084828501612007565b91505092915050565b7f4d41585f535550504c595f4d49534d4154434800000000000000000000000000600082015250565b600061207f601383611db7565b915061208a82612049565b602082019050919050565b600060208201905081810360008301526120ae81612072565b9050919050565b60008160601b9050919050565b60006120cd826120b5565b9050919050565b60006120df826120c2565b9050919050565b6120f76120f282611528565b6120d4565b82525050565b600081905092915050565b600061211483856120fd565b9350612121838584611dc8565b82840190509392505050565b6000819050919050565b61214861214382611593565b61212d565b82525050565b600061215a82876120e6565b60148201915061216b828587612108565b91506121778284612137565b60208201915081905095945050505050565b7f535445505f43414e4e4f545f42455f5a45524f00000000000000000000000000600082015250565b60006121bf601383611db7565b91506121ca82612189565b602082019050919050565b600060208201905081810360008301526121ee816121b2565b9050919050565b600061220082611593565b915061220b83611593565b925082820261221981611593565b915082820484148315176122305761222f611929565b5b5092915050565b7f535445505f52414e47455f4f525f50524943455f544f4f5f534d414c4c000000600082015250565b600061226d601d83611db7565b915061227882612237565b602082019050919050565b6000602082019050818103600083015261229c81612260565b9050919050565b7f44454352454153494e475f52414e474500000000000000000000000000000000600082015250565b60006122d9601083611db7565b91506122e4826122a3565b602082019050919050565b60006020820190508181036000830152612308816122cc565b9050919050565b7f44454352454153494e475f505249434500000000000000000000000000000000600082015250565b6000612345601083611db7565b91506123508261230f565b602082019050919050565b6000602082019050818103600083015261237481612338565b9050919050565b600080fd5b61238982611aea565b810181811067ffffffffffffffff821117156123a8576123a761198c565b5b80604052505050565b60006123bb6114f4565b90506123c78282612380565b919050565b6000604082840312156123e2576123e161237b565b5b6123ec60406123b1565b905060006123fc84828501612007565b600083015250602061241084828501612007565b60208301525092915050565b600060408284031215612432576124316114fe565b5b6000612440848285016123cc565b9150509291505056fea2646970667358221220963d770b9f840713514b31ac11159776637104052360db0b1698675e98d01f8564736f6c63430008140033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000319b3a6e65ada7f8472a789185e9bf777713ea2e000000000000000000000000b9465a3982e470a000d7f29be99de73536b6c8c2000000000000000000000000802e04873fa51e7fc72056f6b39390864c42479c00000000000000000000000070085a09d30d6f8c4ecf6ee10120d1847383bb57000000000000000000000000d370f30b3724bddb690dd98a18a20992cc394a080000000000000000000000000000000000000000000000000000000000000096000000000000000000000000000000000000000000000001158e460913d00000000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000272cdebe93fde1a00000
-----Decoded View---------------
Arg [0] : tokenImplementation (address): 0x319b3A6e65ADa7F8472a789185e9bF777713Ea2E
Arg [1] : bondImplementation (address): 0xB9465a3982E470A000D7f29Be99De73536B6c8c2
Arg [2] : owner (address): 0x802e04873fa51E7fc72056f6b39390864C42479c
Arg [3] : router_ (address): 0x70085a09D30D6f8C4ecF6eE10120d1847383BB57
Arg [4] : feeWallet_ (address): 0xD370F30b3724BddB690Dd98A18A20992cc394A08
Arg [5] : maxSteps (uint256): 150
Arg [6] : creationFee_ (uint256): 20000000000000000000
Arg [7] : tax_ (uint16): 30
Arg [8] : mcapToLp_ (uint256): 185000000000000000000000
-----Encoded View---------------
9 Constructor Arguments found :
Arg [0] : 000000000000000000000000319b3a6e65ada7f8472a789185e9bf777713ea2e
Arg [1] : 000000000000000000000000b9465a3982e470a000d7f29be99de73536b6c8c2
Arg [2] : 000000000000000000000000802e04873fa51e7fc72056f6b39390864c42479c
Arg [3] : 00000000000000000000000070085a09d30d6f8c4ecf6ee10120d1847383bb57
Arg [4] : 000000000000000000000000d370f30b3724bddb690dd98a18a20992cc394a08
Arg [5] : 0000000000000000000000000000000000000000000000000000000000000096
Arg [6] : 000000000000000000000000000000000000000000000001158e460913d00000
Arg [7] : 000000000000000000000000000000000000000000000000000000000000001e
Arg [8] : 00000000000000000000000000000000000000000000272cdebe93fde1a00000
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in GLMR
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.