Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xD9e795DfbC7D1dCA53d181d613681f5C1Effab65
Balance 0 ETH
Nonce 2
Code Size 7570 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

7570 bytes
0x60406080815260049081361015610020575b5050361561001e57600080fd5b005b600091823560e01c9081630483f7a014610f0c578163064a59d014610ee557816306fdde0314610dee578163095ea7b314610dc45781630b94de9c14610d4c57816318160ddd14610d2d5781631f53ac0214610cbe57816323b872dd14610bc2578163244ce7db14610b8557816327a14fc214610b63578163313ce56714610b4757816333e62f1b14610b095781634122010414610ac957816342966c6814610aa857816349f16ad114610a425781634fbee19314610a045781635cce86cd146109c657816369fe0e2d146109435781636dd3d39f1461090557816370a08231146108ce578163715018a6146108705781638da5cb5b146108475781638ea5220f1461081e57816395d89b4114610719578163a771ebc7146106f2578163a9059cbb146106c1578163a9ba9fd014610626578163aa4bde2814610607578163bad3ea6a146105de578163c024666814610576578163c0a904a2146104f2578163c0d78655146104aa578163c705c5691461046c578163cca5dcb614610445578163dd62ed3e146103f7578163ddca3f43146103d8578163e156afd514610372578163e3638a6b14610350578163f2fde38b146102bb57508063f796f8191461029d578063f887ea40146102755763fe417fa50361001157346102715780600319360112610271577fe9aa550fd75d0d28e07fa9dd67d3ae705678776f6c4a75abd09534f93e7d7907906102316110bd565b61026b602435926102406111fd565b61024b8484306112f3565b516001600160a01b03909216825260208201929092529081906040820190565b0390a180f35b5080fd5b503461027157816003193601126102715760075490516001600160a01b039091168152602090f35b5034610271578160031936011261027157602090600a549051908152f35b90503461034c57602036600319011261034c576102d66110bd565b906102df6111fd565b6001600160a01b03918216928315610336575050600554826bffffffffffffffffffffffff60a01b821617600555167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a380f35b51631e4fbdf760e01b8152908101849052602490fd5b8280fd5b8390346102715760203660031901126102715761036b6111fd565b35600a5580f35b50503461027157816003193601126102715760207fbeda7dca7bc1b3e80b871f4818129ec73b771581f803d553aeb3484098e5f65a916103b06111fd565b6008805460ff60a01b1916600160a01b1790819055905160a09190911c60ff1615158152a180f35b5050346102715781600319360112610271576020906009549051908152f35b5050346102715780600319360112610271576020916104146110bd565b8261041d6110d8565b6001600160a01b03928316845260018652922091166000908152908352819020549051908152f35b50503461027157816003193601126102715760209060ff60085460a81c1690519015158152f35b5050346102715760203660031901126102715760209160ff9082906001600160a01b036104976110bd565b168152600f855220541690519015158152f35b83346104ef5760203660031901126104ef576104c46110bd565b6104cc6111fd565b60018060a01b03166bffffffffffffffffffffffff60a01b600754161760075580f35b80fd5b5050346102715761026b7f74392251b09500cc108c71712e5e7e0392be9075a74a24f1494551cfa8e0687091610527366110ee565b9290916105326111fd565b6001600160a01b0383168652600e602052808620805460ff191660ff861515161790555b516001600160a01b03909216825291151560208201529081906040820190565b5050346102715761026b7f3499bfcf9673677ba552f3fe2ea274ec7e6246da31c3c87e115b45a9b0db2efb916105ab366110ee565b9290916105b66111fd565b6001600160a01b0383168652600d602052808620805460ff191660ff86151516179055610556565b50503461027157816003193601126102715760065490516001600160a01b039091168152602090f35b505034610271578160031936011261027157602090600b549051908152f35b5050346102715761026b7f06ec5a5ab383c96a6d0cb0f7921142da03f3afd943b6bf8e410a3fc47a8738a29161065b366110ee565b9290916106666111fd565b6001600160a01b03831686526011602052808620805460ff191660ff86151516179055600f6020908152818720805460ff1916600117905590516001600160a01b039093168352921515928201929092529081906040820190565b5050346102715780600319360112610271576020906106eb6106e16110bd565b6024359033611229565b5160018152f35b50503461027157816003193601126102715760209060ff60085460b01c1690519015158152f35b83833461027157816003193601126102715780519180938054916001908360011c9260018516948515610814575b6020958686108114610801578589529081156107dd5750600114610785575b6107818787610777828c038361119b565b5191829182611128565b0390f35b81529295507f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b5b8284106107ca57505050826107819461077792820101948680610766565b80548685018801529286019281016107ac565b60ff19168887015250505050151560051b8301019250610777826107818680610766565b634e487b7160e01b845260228352602484fd5b93607f1693610747565b50503461027157816003193601126102715760085490516001600160a01b039091168152602090f35b50503461027157816003193601126102715760055490516001600160a01b039091168152602090f35b83346104ef57806003193601126104ef576108896111fd565b600580546001600160a01b031981169091556000906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b5050346102715760203660031901126102715760209181906001600160a01b036108f66110bd565b16815280845220549051908152f35b5050346102715760203660031901126102715760209160ff9082906001600160a01b036109306110bd565b1681526010855220541690519015158152f35b9190503461034c57602036600319011261034c578135916109626111fd565b60ff60085460b01c16156109b857601e83116109aa5750816020917f20461e09b8e557b77e107939f9ce6544698123aad0fc964ac5cc59b7df2e608f9360095551908152a180f35b905163cd4e616760e01b8152fd5b90516336a8541b60e01b8152fd5b5050346102715760203660031901126102715760209160ff9082906001600160a01b036109f16110bd565b168152600e855220541690519015158152f35b5050346102715760203660031901126102715760209160ff9082906001600160a01b03610a2f6110bd565b168152600d855220541690519015158152f35b50503461027157816003193601126102715760207fa410c62368e64b86d7722fd28e698d03bd00719ba95a861b50ceb65efdc6ca4491610a806111fd565b6008805460ff60a81b1916600160a81b1790819055905160a89190911c60ff1615158152a180f35b83903461027157602036600319011261027157610ac690353361127f565b80f35b50503461027157610ac690610add366110ee565b9190610ae76111fd565b60018060a01b03168452601060205283209060ff801983541691151516179055565b5050346102715760203660031901126102715760209160ff9082906001600160a01b03610b346110bd565b1681526011855220541690519015158152f35b5050346102715781600319360112610271576020905160128152f35b83903461027157602036600319011261027157610b7e6111fd565b35600b5580f35b90503461034c57602036600319011261034c57803591610ba36111fd565b620f42408311610bb5575050600c5580f35b51630b25774360e41b8152fd5b905082346104ef5760603660031901126104ef5750610bdf6110bd565b610be76110d8565b906044359260018060a01b03821680600052600160205285600020336000526020528560002054916000198310610c27575b6020876106eb888888611229565b858310610c92578115610c7b573315610c6457506000908152600160209081528682203383528152908690209185900390915582906106eb610c19565b6024906000885191634a1406b160e11b8352820152fd5b602490600088519163e602df0560e01b8352820152fd5b8651637dc7a0d960e11b8152339181019182526020820193909352604081018690528291506060010390fd5b5050346102715760203660031901126102715760207f31bb1993faff4f8409d7baad771f861e093ef4ce2c92c6e0cb10b82d1c7324cb91610cfd6110bd565b610d056111fd565b600880546001600160a01b0319166001600160a01b039290921691821790559051908152a180f35b5050346102715781600319360112610271576020906002549051908152f35b9190503461034c578060031936011261034c5782808080610d6b6110bd565b610d736111fd565b602435905af1610d816111bd565b5015610d8b578280f35b906020606492519162461bcd60e51b83528201526013602482015272115512081d1c985b9cd9995c8819985a5b1959606a1b6044820152fd5b5050346102715780600319360112610271576020906106eb610de46110bd565b6024359033611a0c565b9190503461034c578260031936011261034c5780519183600354906001908260011c92600181168015610edb575b6020958686108214610ec85750848852908115610ea65750600114610e4d575b6107818686610777828b038361119b565b929550600383527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b5b828410610e93575050508261078194610777928201019438610e3c565b8054868501880152928601928101610e76565b60ff191687860152505050151560051b83010192506107778261078138610e3c565b634e487b7160e01b845260229052602483fd5b93607f1693610e1c565b50503461027157816003193601126102715760209060ff60085460a01c1690519015158152f35b8391503461027157610f1d366110ee565b91610f266111fd565b6001600160a01b03828116808652600f602052868620805460ff191660ff8715151617905591908415610ff7579085969592916006541691823b15610fe957604484928389519586948593630a5b654b60e11b85528401528160248401525af18015610fed57610fd5575b505091516001600160a01b039092168252151560208201527f50b9be6d475eaa75d2387ce1985972767cbe50d0b6e16cffd31a82062cbfbc7590806040810161026b565b610fde90611171565b610fe9578385610f91565b8380fd5b85513d84823e3d90fd5b90915060065416846020528585205491813b156110b9578651630a5b654b60e11b81526001600160a01b03851691810191825260208201939093528591839182908490829060400103925af180156110af5761107a575b5061026b7f50b9be6d475eaa75d2387ce1985972767cbe50d0b6e16cffd31a82062cbfbc759394610556565b7f50b9be6d475eaa75d2387ce1985972767cbe50d0b6e16cffd31a82062cbfbc75936110a861026b92611171565b935061104e565b85513d86823e3d90fd5b8580fd5b600435906001600160a01b03821682036110d357565b600080fd5b602435906001600160a01b03821682036110d357565b60409060031901126110d3576004356001600160a01b03811681036110d3579060243580151581036110d35790565b60009103126110d357565b6020808252825181830181905290939260005b82811061115d57505060409293506000838284010152601f8019910116010190565b81810186015184820160400152850161113b565b67ffffffffffffffff811161118557604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff82111761118557604052565b3d156111f8573d9067ffffffffffffffff821161118557604051916111ec601f8201601f19166020018461119b565b82523d6000602084013e565b606090565b6005546001600160a01b0316330361121157565b60405163118cdaa760e01b8152336004820152602490fd5b91906001600160a01b03808416156112665781161561124d5761124b926112f3565b565b60405163ec442f0560e01b815260006004820152602490fd5b604051634b637e8f60e11b815260006004820152602490fd5b906001600160a01b0382161561126657600061124b926112f3565b919082018092116112a757565b634e487b7160e01b600052601160045260246000fd5b906021820291808304602114901517156112a757565b818102929181159184041417156112a757565b919082039182116112a757565b909161130560085460ff9060b81c1690565b611a01576001600160a01b038316600090815260116020526040902061132d905b5460ff1690565b6001600160a01b038316600090815260116020526040902061134e90611326565b6009543060009081526020819052604090209192915492600b549060085460ff8160a81c1615806119d6575b806119ab575b6119995784918515611991575b5081611982575b5080611957575b8061192c575b61191a5780611873575b5080151580611848575b8061181d575b6117a4575b5080611798575b611662575b506113d8908383611a9f565b6001600160a01b0381166000908152600f60205260409020611401906113fd90611326565b1590565b611597575b506001600160a01b0381166000908152600f6020526040902061142c906113fd90611326565b6114cc575b5060065461144f906001600160a01b03165b6001600160a01b031690565b600c5490803b156110d3576040516001624d3b8760e01b0319815260048101929092526000908290602490829084905af190816114b3575b5061124b577fbc1e4cd8fb52842c9d0533b1114281cfebd139853201caef455670236801d56b600080a1565b806114c06114c692611171565b8061111d565b38611487565b6006546114e1906001600160a01b0316611443565b6001600160a01b03821660009081526020819052604090205490803b156110d357604051630a5b654b60e11b81526001600160a01b038416600482015260248101929092526000908290604490829084905af19081611584575b5061157e576040516001600160a01b039190911681527f20ca2ab824099035a137c90affbf365085795a01f71d1d7be6ab41158093ab5690602090a15b38611431565b50611578565b806114c061159192611171565b3861153b565b6006546115ac906001600160a01b0316611443565b6001600160a01b03821660009081526020819052604090205490803b156110d357604051630a5b654b60e11b81526001600160a01b038416600482015260248101929092526000908290604490829084905af1908161164f575b50611649576040516001600160a01b039190911681527f20ca2ab824099035a137c90affbf365085795a01f71d1d7be6ab41158093ab5690602090a15b38611406565b50611643565b806114c061165c92611171565b38611606565b61167561166e826112bd565b6064900490565b90611680823061127f565b6116c9916116c4917f6ef4855b666dcc7884561072e4358b28dfe01feb1b7f4dcebc00e62d50394ac7604051806116bc85829190602083019252565b0390a16112e6565b611b9c565b6116d78160011c80926112e6565b9060009081808080846116f160085460018060a01b031690565b5af16116fb6111bd565b50611766575b50600654611717906001600160a01b0316611443565b803b1561027157906113d8939291600460405180948193630d0e30db60e41b83525af1611753575b506008805460ff60b81b19169055906113cc565b806114c061176092611171565b3861173f565b6040519081527f7656cab9d29c776a94dd095f6b04dbc2251bcd02756b085a6dfb79a86af80eb790602090a138611701565b50600a548110156113c7565b6118146117f26117e06117d87f06c5efeff5c320943d265dc4e5f1af95ad523555ce0c1957e367dda5514572df94886112d3565b6103e8900490565b80966117ed82308b611a9f565b6112e6565b604080516001600160a01b038916815260208101979097529095918291820190565b0390a1386113c0565b506001600160a01b0386166000908152600d60205260409020611843906113fd90611326565b6113bb565b506001600160a01b0385166000908152600d6020526040902061186e906113fd90611326565b6113b5565b611899856118938960018060a01b03166000526000602052604060002090565b5461129a565b11806118ef575b6118aa57386113ab565b60405162461bcd60e51b815260206004820152601a60248201527f4d61782077616c6c657420616d6f756e742065786365656465640000000000006044820152606490fd5b506001600160a01b0386166000908152601060205260409020611915906113fd90611326565b6118a0565b60405163bcb8b8fb60e01b8152600490fd5b506001600160a01b0387166000908152600e60205260409020611952906113fd90611326565b6113a1565b506001600160a01b0386166000908152600e6020526040902061197d906113fd90611326565b61139b565b60ff915060a01c161538611394565b91503861138d565b60405163a24e573d60e01b8152600490fd5b506001600160a01b0389166000908152600e602052604090206119d1906113fd90611326565b611380565b506001600160a01b0388166000908152600e602052604090206119fc906113fd90611326565b61137a565b909161124b92611a9f565b6001600160a01b03908116918215611a865716918215611a6d5760207f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925918360005260018252604060002085600052825280604060002055604051908152a3565b604051634a1406b160e11b815260006004820152602490fd5b60405163e602df0560e01b815260006004820152602490fd5b6001600160a01b0380821692909183611b1957507fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91602091611ae48660025461129a565b6002555b169384611b015780600254036002555b604051908152a3565b84600052600082526040600020818154019055611af8565b60009084825281602052604082205490868210611b6a57509181604087602095887fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef98965283875203912055611ae8565b60405163391434e360e21b81526001600160a01b03919091166004820152602481019190915260448101869052606490fd5b904760ff60b81b19600160b81b8160085416176008556040938451906060820182811067ffffffffffffffff8211176111855786526002825260208083019087368337835115611d015730825260075488516315ab88c960e31b81526001600160a01b03949092909185168184600481845afa938415611d5157600094611d17575b5086519360019460011015611d0157611c3f91878592168d8a015230611a0c565b846007541694853b156110d357918a9694939196519687956318cbafe560e01b875260a487019260048801526000602488015260a060448801525180925260c4860194936000905b838210611ce7575050505050509181600081819530606483015242608483015203925af18015611cdc57611cca949550611ccd575b5060085416600855476112e6565b90565b611cd690611171565b38611cbc565b85513d6000823e3d90fd5b855181168752899750958201959482019490840190611c87565b634e487b7160e01b600052603260045260246000fd5b8281819693963d8311611d4a575b611d2f818361119b565b8101031261027157519086821682036104ef57509238611c1e565b503d611d25565b8b513d6000823e3d90fdfea2646970667358221220771da5423be41b679d6e506b4235d95caaed210803a19122f35331f6346ffe1964736f6c63430008190033

Verified Source Code Full Match

Compiler: v0.8.25+commit.b61c2a91 EVM: paris Optimization: Yes (200 runs)
Ownable.sol 100 lines
// 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);
    }
}
IERC1363.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)

pragma solidity >=0.6.2;

import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";

/**
 * @title IERC1363
 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
 *
 * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
 * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
 */
interface IERC1363 is IERC20, IERC165 {
    /*
     * Note: the ERC-165 identifier for this interface is 0xb0202a11.
     * 0xb0202a11 ===
     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
     */

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @param data Additional data with no specified format, sent in call to `spender`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)

pragma solidity >=0.4.16;

import {IERC165} from "../utils/introspection/IERC165.sol";
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)

pragma solidity >=0.4.16;

import {IERC20} from "../token/ERC20/IERC20.sol";
draft-IERC6093.sol 161 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/draft-IERC6093.sol)
pragma solidity >=0.8.4;

/**
 * @dev Standard ERC-20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 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 ERC-721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-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 ERC-1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 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);
}
ERC20.sol 305 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC-20
 * applications.
 */
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
    mapping(address account => uint256) private _balances;

    mapping(address account => mapping(address spender => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * Both values are immutable: they can only be set once during construction.
     */
    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;
    }

    /// @inheritdoc IERC20
    function totalSupply() public view virtual returns (uint256) {
        return _totalSupply;
    }

    /// @inheritdoc IERC20
    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;
    }

    /// @inheritdoc IERC20
    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}.
     *
     * Skips emitting an {Approval} event indicating an allowance update. This is not
     * required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
     *
     * 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:
     *
     * ```solidity
     * 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);
            }
        }
    }
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}
IERC20Metadata.sol 26 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity >=0.6.2;

import {IERC20} from "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC-20 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);
}
SafeERC20.sol 212 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC-20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    /**
     * @dev An operation with an ERC-20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
        return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
        return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
     * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferFromAndCallRelaxed(
        IERC1363 token,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        if (to.code.length == 0) {
            safeTransferFrom(token, from, to, value);
        } else if (!token.transferFromAndCall(from, to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
     * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
     * once without retrying, and relies on the returned value to be true.
     *
     * Reverts if the returned value is other than `true`.
     */
    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            forceApprove(token, to, value);
        } else if (!token.approveAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            // bubble errors
            if iszero(success) {
                let ptr := mload(0x40)
                returndatacopy(ptr, 0, returndatasize())
                revert(ptr, returndatasize())
            }
            returnSize := returndatasize()
            returnValue := mload(0)
        }

        if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        bool success;
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            returnSize := returndatasize()
            returnValue := mload(0)
        }
        return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
    }
}
Context.sol 28 lines
// 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;
    }
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
SimpleDividendDistributor.sol 190 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

interface IDEXRouter {
    function WETH() external pure returns (address);

    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
}

contract SimpleDividendDistributor {

    IDEXRouter router;
    IERC20Metadata public rewardToken;
    address _token;
    address public owner;
    address[] public shareholders;
    uint256 public totalShares;
    uint256 public totalDividends;
    uint256 public totalDistributed;
    uint256 public dividendsPerShare;
    uint256 public dividendsPerShareAccuracyFactor;
    uint256 public minPeriod;
    uint256 public minDistribution;
    uint256 currentIndex;

    mapping (address => uint256) shareholderIndexes;
    mapping (address => uint256) shareholderClaims;
    mapping (address => Share) public shares;

    struct Share {
        uint256 amount;
        uint256 totalExcluded;
        uint256 totalRealised;
    }

    event RewardDistributed(address receiver, uint256 amount);

    constructor (address _owner, address _router, address _rewardToken) {
        router = IDEXRouter(_router);
        _token = msg.sender;
        owner = _owner;
        rewardToken = IERC20Metadata(_rewardToken);
        minPeriod = 5 minutes;
        minDistribution = 1 * (10 ** rewardToken.decimals());
        dividendsPerShareAccuracyFactor = 10 ** 36;
    }

    modifier onlyToken() {
        require(msg.sender == _token, "only token can call this"); _;
    }
    modifier onlyOwner() {
        require(msg.sender == owner, "only owner can call this"); _;
    }

    function transferOwnership(address newOwner) external onlyOwner {
        require(newOwner != address(0), "new owner is zero address");
        owner = newOwner;
    }

    function claimETH(address to, uint amount) external onlyOwner {
        (bool success,) = to.call{value: amount}("");
        require(success, "ETH transfer failed");
    }

    function setDistributionCriteria(uint256 newMinPeriod, uint256 newMinDistribution) external onlyOwner {
        minPeriod = newMinPeriod;
        minDistribution = newMinDistribution;
    }

    function setRewardToken(address newRewardToken) external onlyOwner {
        rewardToken = IERC20Metadata(newRewardToken);
    }

    function setShare(address shareholder, uint256 amount) external onlyToken {

        if(shares[shareholder].amount > 0){
            distributeDividend(shareholder);
        }

        if(amount > 0 && shares[shareholder].amount == 0){
            addShareholder(shareholder);
        }else if(amount == 0 && shares[shareholder].amount > 0){
            removeShareholder(shareholder);
        }

        totalShares = totalShares - shares[shareholder].amount + amount;
        shares[shareholder].amount = amount;
        shares[shareholder].totalExcluded = getCumulativeDividends(shares[shareholder].amount);
    }

    function deposit() external payable onlyToken {
        uint256 balanceBefore = rewardToken.balanceOf(address(this));

        address[] memory path = new address[](2);
        path[0] = router.WETH();
        path[1] = address(rewardToken);

        router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: msg.value}(
            0,
            path,
            address(this),
            block.timestamp
        );
        uint256 amount = rewardToken.balanceOf(address(this)) - balanceBefore;
        totalDividends = totalDividends + amount;
        dividendsPerShare = dividendsPerShare + (dividendsPerShareAccuracyFactor * amount / totalShares);
    }

    function process(uint256 gas) external {
        uint256 shareholderCount = shareholders.length;

        if(shareholderCount == 0) { return; }

        uint256 iterations = 0;
        uint256 gasUsed = 0;
        uint256 gasLeft = gasleft();

        while(gasUsed < gas && iterations < shareholderCount) {

            if(currentIndex >= shareholderCount){ currentIndex = 0; }
            if(shouldDistribute(shareholders[currentIndex])){
                distributeDividend(shareholders[currentIndex]);
            }

            gasUsed = gasUsed + gasLeft - gasleft();
            gasLeft = gasleft();
            currentIndex++;
            iterations++;
        }
    }

    function shouldDistribute(address shareholder) public view returns (bool) {
        return shareholderClaims[shareholder] + minPeriod < block.timestamp
                && getUnpaidEarnings(shareholder) > minDistribution;
    }

    function distributeDividend(address shareholder) internal {
        if(shares[shareholder].amount == 0){ return; }

        uint256 amount = getUnpaidEarnings(shareholder);
        if(amount > 0){
            totalDistributed = totalDistributed + amount;
            SafeERC20.safeTransfer(rewardToken, shareholder, amount);
            emit RewardDistributed(shareholder, amount);
            shareholderClaims[shareholder] = block.timestamp;
            shares[shareholder].totalRealised = shares[shareholder].totalRealised + amount;
            shares[shareholder].totalExcluded = getCumulativeDividends(shares[shareholder].amount);
        }
    }

    function claimDividend() external {
        require(shouldDistribute(msg.sender), "Too soon. Need to wait!");
        distributeDividend(msg.sender);
    }

    function getUnpaidEarnings(address shareholder) public view returns (uint256) {
        if(shares[shareholder].amount == 0){ return 0; }

        uint256 shareholderTotalDividends = getCumulativeDividends(shares[shareholder].amount);
        uint256 shareholderTotalExcluded = shares[shareholder].totalExcluded;

        if(shareholderTotalDividends <= shareholderTotalExcluded){ return 0; }

        return shareholderTotalDividends - shareholderTotalExcluded;
    }

    function getCumulativeDividends(uint256 share) internal view returns (uint256) {
        return share * dividendsPerShare / dividendsPerShareAccuracyFactor;
    }

    function addShareholder(address shareholder) internal {
        shareholderIndexes[shareholder] = shareholders.length;
        shareholders.push(shareholder);
    }

    function removeShareholder(address shareholder) internal {
        shareholders[shareholderIndexes[shareholder]] = shareholders[shareholders.length-1];
        shareholderIndexes[shareholders[shareholders.length-1]] = shareholderIndexes[shareholder];
        shareholders.pop();
    }

}
TaxToken.sol 318 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { SimpleDividendDistributor } from "./SimpleDividendDistributor.sol";

interface IUniswapV2Factory {
    function createPair(address tokenA, address tokenB) external returns (address pair);
}

interface IUniswapV2Router02 {
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function factory() external pure returns (address);
    function WETH() external pure returns (address);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
}

interface IERC20 {
    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    function transfer(address recipient, uint256 amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

interface Irouter {
    function WETH() external pure returns (address);
    function swapExactTokensForETH(
        uint amountIn, 
        uint amountOutMin, 
        address[] calldata path, 
        address to, 
        uint deadline
    ) external;
}

contract FENRIR is ERC20, Ownable {
    SimpleDividendDistributor public dividendDistributor;
    address public router;
    address public devWallet;
    bool public isTradingEnabled = false;
    bool public isTransferEnabled = false;
    bool public feeEnabled;
    bool isSwapping;
    uint public fee;
    uint public minAmountForSwap;
    uint public maxWalletAmount;
    uint distributorGas;

    mapping(address => bool)  public isExcludedFromFees;
    mapping(address => bool)  public isExcludedFromLimits;
    mapping (address => bool) public isExcludedFromDividends;
    mapping (address => bool) public isExcludedFromMaxWallet;
    mapping(address => bool)  public ammContracts;

    IUniswapV2Router02 private uniswapV2Router;
    address private uniswapV2Pair;
    bool private tradingOpen;
    bool private inSwap = false;
    bool private swapEnabled = false;
    bool private lpAdded = false;

    error TransferDisabled();
    error TradingDisabled();
    error FeeTooHigh();
    error NoAmountToTransfer();
    error AirdropListMismatch();
    error FeeDisabled();
    error GasTooHigh();

    event FeeIsDisabled();
    event TradingEnabled(bool state);
    event TransferEnabled(bool state);
    event FeeSet(uint newFee);
    event AmmPoolSet(address pool, bool enabled);
    event ExcludedFromFees(address account, bool excluded);
    event ExcludedFromLimits(address account, bool excluded);
    event ExcludedFromDividends(address account, bool excluded);
    event ClaimedTokens(address to, uint amount);
    event FeeCollected(address from, uint amount);
    event TokensBurned(uint amount);
    event DevShareSent(uint amount);
    event SetDividendShareFailed(address account);
    event ProcessDividendFailed();
    event DevWalletUpdated(address newDevWallet);

    constructor(address _devWallet) ERC20("FENRIR!", "FENRIR") Ownable(msg.sender) {
        devWallet = _devWallet;
        isExcludedFromFees[msg.sender]         = true;
        isExcludedFromLimits[msg.sender]       = true;
        isExcludedFromLimits[address(this)]    = true;
        isExcludedFromDividends[address(this)] = true;
        isExcludedFromMaxWallet[msg.sender]    = true;
        isExcludedFromMaxWallet[address(this)] = true;
        uint _totalSupply = 5_555_555 * 1e18;
        
        fee              = 30; // 3% = 30/1000
        feeEnabled       = true;
        distributorGas   = 300000;
        minAmountForSwap = _totalSupply / 1000; // 0.1% of total supply
        router           = address(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
        // SKOL reward token: 0xB369dACa21eE035312176Eb8Cf9d88ce97E0aA95
        dividendDistributor = new SimpleDividendDistributor(msg.sender, router, address(0xB369dACa21eE035312176Eb8Cf9d88ce97E0aA95));
        isExcludedFromDividends[address(dividendDistributor)] = true;
        _mint(msg.sender, _totalSupply);
    }

    receive() external payable {}

    function setRouter(address _router) external onlyOwner {
        router = _router;
    }

    function setDevWallet(address _devWallet) external onlyOwner {
        devWallet = _devWallet;
        emit DevWalletUpdated(_devWallet);
    }

    function setMaxWalletAmount(uint amount) external onlyOwner {
        maxWalletAmount = amount;
    }

    function setExcludedFromMaxWallet(address account, bool excluded) external onlyOwner {
        isExcludedFromMaxWallet[account] = excluded;
    }

    function setMinAmountForSwap(uint amount) external onlyOwner {
        minAmountForSwap = amount;
    }

    function setDistributorGas(uint gas) external onlyOwner {
        if (gas > 1_000_000) revert GasTooHigh();
        distributorGas = gas;
    }

    function setTradingEnabled() external onlyOwner {
        isTradingEnabled = true;
        emit TradingEnabled(isTradingEnabled);
    }
    
    function setTransferEnabled() external onlyOwner {
        isTransferEnabled = true;
        emit TransferEnabled(isTransferEnabled);
    }

    function setAmmPool(address pool, bool enabled) external onlyOwner {
        ammContracts[pool] = enabled;
        isExcludedFromDividends[pool] = true;
        emit AmmPoolSet(pool, enabled);
    }

    function setFee(uint _fee) external onlyOwner {
        if(!feeEnabled) revert FeeDisabled();
        if(_fee > 30)  revert FeeTooHigh();
        fee = _fee;
        emit FeeSet(_fee);
    }

    function claimTokens(address to, uint amount) external onlyOwner {
        _update(address(this), to, amount);
        emit ClaimedTokens(to, amount);
    }

    function claimETH(address to, uint amount) external onlyOwner {
        (bool success,) = to.call{value: amount}("");
        require(success, "ETH transfer failed");
    }

    function excludeFromFees(address account, bool excluded) external onlyOwner {
        isExcludedFromFees[account] = excluded;
        emit ExcludedFromFees(account, excluded);
    }

    function excludeFromLimits(address account, bool excluded) external onlyOwner {
        isExcludedFromLimits[account] = excluded;
        emit ExcludedFromLimits(account, excluded);
    }

    function excludeFromDividends(address account, bool excluded) external onlyOwner {
        isExcludedFromDividends[account] = excluded;
        if (excluded) {
            dividendDistributor.setShare(account, 0);
        } else {
            dividendDistributor.setShare(account, balanceOf(account));
        }
        emit ExcludedFromDividends(account, excluded);
    }

    function swapTokensForEth(uint256 tokenAmount) private returns(uint) {
        uint balanceBefore = address(this).balance;
        isSwapping = true;
        address[] memory path = new address[](2);
        path[0] = address(this);
        path[1] = Irouter(router).WETH();

        _approve(address(this), router, tokenAmount);
        Irouter(router).swapExactTokensForETH(
            tokenAmount,
            0,
            path,
            address(this),
            block.timestamp
        );
        isSwapping = false;
        return address(this).balance - balanceBefore;
    }

    function _update(address from, address to, uint256 amount) internal override {
        if(isSwapping) {
            super._update(from, to, amount);
            return;
        }
        bool isSell    = ammContracts[to];
        bool isBuy     = ammContracts[from];
        uint _fee  = fee;
        uint caBalance = balanceOf(address(this));
        uint _maxWallet = maxWalletAmount;
        if (// if transfer is disabled
                !isTransferEnabled
            // and neither from nor to is excluded from limits
                && !isExcludedFromLimits[from] && !isExcludedFromLimits[to]
            ) revert TransferDisabled();
        if (// if from or to is an AMM contract
                (isSell || isBuy) &&
            // and trading is disabled
                !isTradingEnabled &&
            // and neither from nor to is excluded from limits
                !isExcludedFromLimits[from] && !isExcludedFromLimits[to]
            ) revert TradingDisabled();

        // max wallet
        if (_maxWallet > 0) {
            if (balanceOf(to) + amount > _maxWallet && !isExcludedFromMaxWallet[to]) {
                revert("Max wallet amount exceeded");
            }
        }
        
        if (_fee > 0 && !isExcludedFromFees[from] && !isExcludedFromFees[to]) {
            _fee = amount * _fee / 1000;
            super._update(from, address(this), _fee);
            amount -= _fee;
            emit FeeCollected(from, _fee);
        }

        // swap tokens to accumulate rewards if balance is higher than minAmountForSwap
        if(isSell && caBalance >= minAmountForSwap) {
            // Burn 33% of accumulated tokens
            uint burnAmount = caBalance * 33 / 100;
            _burn(address(this), burnAmount);
            emit TokensBurned(burnAmount);
            
            // Swap remaining 66% to ETH
            uint swapAmount = caBalance - burnAmount;
            uint ethReceived = swapTokensForEth(swapAmount);
            
            // Split ETH: 50% to dev, 50% to rewards
            uint devShare = ethReceived / 2;
            uint rewardShare = ethReceived - devShare;
            
            // Send to dev wallet
            (bool sent,) = devWallet.call{value: devShare}("");
            if(sent) {
                emit DevShareSent(devShare);
            }
            
            // Send to dividend distributor
            try dividendDistributor.deposit{value: rewardShare}() {} catch {}
            isSwapping = false;
        }

        super._update(from, to, amount);
        
        // Dividend tracker
        if(!isExcludedFromDividends[from]) {
            try dividendDistributor.setShare(from, balanceOf(from)) {} catch {
                emit SetDividendShareFailed(from);
            }
        }

        if(!isExcludedFromDividends[to]) {
            try dividendDistributor.setShare(to, balanceOf(to)) {} catch {
                emit SetDividendShareFailed(to);
            } 
        }

        try dividendDistributor.process(distributorGas) {} catch {
            emit ProcessDividendFailed();
        }
    }

    function burn(uint256 amount) external {
        super._burn(msg.sender, amount);
    }

}

Read Contract

allowance 0xdd62ed3e → uint256
ammContracts 0x33e62f1b → bool
balanceOf 0x70a08231 → uint256
decimals 0x313ce567 → uint8
devWallet 0x8ea5220f → address
dividendDistributor 0xbad3ea6a → address
fee 0xddca3f43 → uint256
feeEnabled 0xa771ebc7 → bool
isExcludedFromDividends 0xc705c569 → bool
isExcludedFromFees 0x4fbee193 → bool
isExcludedFromLimits 0x5cce86cd → bool
isExcludedFromMaxWallet 0x6dd3d39f → bool
isTradingEnabled 0x064a59d0 → bool
isTransferEnabled 0xcca5dcb6 → bool
maxWalletAmount 0xaa4bde28 → uint256
minAmountForSwap 0xf796f819 → uint256
name 0x06fdde03 → string
owner 0x8da5cb5b → address
router 0xf887ea40 → address
symbol 0x95d89b41 → string
totalSupply 0x18160ddd → uint256

Write Contract 21 functions

These functions modify contract state and require a wallet transaction to execute.

approve 0x095ea7b3
address spender
uint256 value
returns: bool
burn 0x42966c68
uint256 amount
claimETH 0x0b94de9c
address to
uint256 amount
claimTokens 0xfe417fa5
address to
uint256 amount
excludeFromDividends 0x0483f7a0
address account
bool excluded
excludeFromFees 0xc0246668
address account
bool excluded
excludeFromLimits 0xc0a904a2
address account
bool excluded
renounceOwnership 0x715018a6
No parameters
setAmmPool 0xa9ba9fd0
address pool
bool enabled
setDevWallet 0x1f53ac02
address _devWallet
setDistributorGas 0x244ce7db
uint256 gas
setExcludedFromMaxWallet 0x41220104
address account
bool excluded
setFee 0x69fe0e2d
uint256 _fee
setMaxWalletAmount 0x27a14fc2
uint256 amount
setMinAmountForSwap 0xe3638a6b
uint256 amount
setRouter 0xc0d78655
address _router
setTradingEnabled 0xe156afd5
No parameters
setTransferEnabled 0x49f16ad1
No parameters
transfer 0xa9059cbb
address to
uint256 value
returns: bool
transferFrom 0x23b872dd
address from
address to
uint256 value
returns: bool
transferOwnership 0xf2fde38b
address newOwner

Recent Transactions

No transactions found for this address