TTSwap_Token

Description:

Multi-signature wallet contract requiring multiple confirmations for transaction execution.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "settings": {
    "viaIR": true,
    "evmVersion": "cancun",
    "optimizer": {
      "enabled": true,
      "runs": 100
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "remappings": [
      "ds-test/=lib/forge-std/lib/ds-test/src/",
      "forge-std/=lib/forge-std/src/",
      "@openzeppelin-upgradeable/contracts/=lib/openzeppelin-contracts-upgradeable/contracts/",
      "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
      "forge-gas-snapshot/=lib/forge-gas-snapshot/",
      "forge-std-1.10.0/=dependencies/forge-std-1.10.0/",
      "forge-std/=lib/forge-std/",
      "permit2/=lib/permit2/",
      "solmate/=lib/solmate/",
      "@openzeppelin-upgradeable/contracts/=lib/openzeppelin-contracts-upgradeable/contracts/",
      "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
      "forge-gas-snapshot/=lib/forge-gas-snapshot/",
      "forge-std-1.10.0/=dependencies/forge-std-1.10.0/",
      "forge-std/=lib/forge-std/",
      "permit2/=lib/permit2/",
      "solmate/=lib/solmate/",
      "@openzeppelin-upgradeable/contracts/=lib/openzeppelin-contracts-upgradeable/contracts/",
      "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
      "forge-gas-snapshot/=lib/forge-gas-snapshot/",
      "forge-std-1.10.0/=dependencies/forge-std-1.10.0/",
      "forge-std/=lib/forge-std/",
      "permit2/=lib/permit2/",
      "solmate/=lib/solmate/"
    ]
  },
  "sources": {
    "src/TTSwap_Token.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.29;

import {ERC20} from "./base/ERC20.sol";
import {I_TTSwap_Market} from "./interfaces/I_TTSwap_Market.sol";
import {I_TTSwap_Token, s_share, s_proof} from "./interfaces/I_TTSwap_Token.sol";
import {L_TTSTokenConfigLibrary} from "./libraries/L_TTSTokenConfig.sol";
import {L_UserConfigLibrary} from "./libraries/L_UserConfig.sol";
import {L_CurrencyLibrary} from "./libraries/L_Currency.sol";
import {TTSwapError} from "./libraries/L_Error.sol";
import {toTTSwapUINT256, L_TTSwapUINT256Library, add, sub, mulDiv} from "./libraries/L_TTSwapUINT256.sol";
import {IEIP712} from "./interfaces/IEIP712.sol";
import {L_SignatureVerification} from "./libraries/L_SignatureVerification.sol";

/**
 * @title TTS Token Contract
 * @dev Implements ERC20 token with additional staking and cross-chain functionality
 */
contract TTSwap_Token is I_TTSwap_Token, ERC20, IEIP712 {
    using L_TTSwapUINT256Library for uint256;
    using L_TTSTokenConfigLibrary for uint256;
    using L_UserConfigLibrary for uint256;
    using L_CurrencyLibrary for address;
    using L_SignatureVerification for bytes;
    address internal implementation;
    bool internal upgradeable;
    address internal usdt;
    uint256 public override ttstokenconfig;
    uint256 public override stakestate; // first 128 bit record lasttime,last 128 bit record poolvalue
    uint128 public override left_share = 45_000_000_000_000;
    /// @inheritdoc I_TTSwap_Token
    uint128 public override publicsell;
    // uint256 1:add referral priv 2: market priv
    /// @inheritdoc I_TTSwap_Token
    mapping(address => uint256) public override userConfig;

    address internal marketcontract;
    uint256 public override poolstate; // first 128 bit record all asset(contain actual asset and constuct fee),last  128 bit record construct  fee

    mapping(address => s_share) internal shares; // all share's mapping
    mapping(uint256 => s_proof) internal stakeproof;

    bytes32 internal constant _PERMITSHARE_TYPEHASH =
        keccak256(
            "permitShare(uint128 amount,uint120 chips,uint8 metric,address owner,uint128 existamount,uint128 deadline,uint256 nonce)"
        );

    constructor() ERC20("TTSwap Token", "TTS", 6) {}

    /**
     * @dev Modifier to ensure function is only called on the main chain
     */
    modifier onlymain() {
        if (!ttstokenconfig.ismain()) revert TTSwapError(61);
        _;
    }
    //**************************privillages partition**********************************/

    /**
     * @dev Grants or revokes DAO admin privileges to a recipient address.
     * @param _recipient The address to grant or revoke DAO admin rights.
     * @param result Boolean indicating whether to grant (true) or revoke (false) the privilege.
     * @notice Only callable by an existing DAO admin.
     */
    /// @inheritdoc I_TTSwap_Token
    function setDAOAdmin(address _recipient, bool result) external override {
        if (!userConfig[msg.sender].isDAOAdmin()) revert TTSwapError(62);
        userConfig[msg.sender] = userConfig[msg.sender].setDAOAdmin(!result);
        userConfig[_recipient] = userConfig[_recipient].setDAOAdmin(result);
        emit e_updateUserConfig(_recipient, userConfig[_recipient]);
    }

    /**
     * @dev Grants or revokes Token admin privileges to a recipient address.
     * @param _recipient The address to grant or revoke Token admin rights.
     * @param result Boolean indicating whether to grant (true) or revoke (false) the privilege.
     * @notice Only callable by a DAO admin.
     */
    /// @inheritdoc I_TTSwap_Token
    function setTokenAdmin(address _recipient, bool result) external override {
        if (!userConfig[msg.sender].isDAOAdmin()) revert TTSwapError(63);
        userConfig[_recipient] = userConfig[_recipient].setTokenAdmin(result);
        emit e_updateUserConfig(_recipient, userConfig[_recipient]);
    }

    /**
     * @dev Grants or revokes Token manager privileges to a recipient address.
     * @param _recipient The address to grant or revoke Token manager rights.
     * @param result Boolean indicating whether to grant (true) or revoke (false) the privilege.
     * @notice Only callable by a Token admin.
     */
    /// @inheritdoc I_TTSwap_Token
    function setTokenManager(
        address _recipient,
        bool result
    ) external override {
        if (!userConfig[msg.sender].isTokenAdmin()) revert TTSwapError(63);
        userConfig[_recipient] = userConfig[_recipient].setTokenManager(result);
        emit e_updateUserConfig(_recipient, userConfig[_recipient]);
    }

    /**
     * @dev Grants or revokes permission to call mintTTS to a recipient address.
     * @param _recipient The address to grant or revoke permission.
     * @param result Boolean indicating whether to grant (true) or revoke (false) the privilege.
     * @notice Only callable by a Token admin.
     */
    /// @inheritdoc I_TTSwap_Token
    function setCallMintTTS(address _recipient, bool result) external override {
        if (!userConfig[msg.sender].isTokenAdmin()) revert TTSwapError(63);
        userConfig[_recipient] = userConfig[_recipient].setCallMintTTS(result);
        emit e_updateUserConfig(_recipient, userConfig[_recipient]);
    }

    /**
     * @dev Grants or revokes Market admin privileges to a recipient address.
     * @param _recipient The address to grant or revoke Market admin rights.
     * @param result Boolean indicating whether to grant (true) or revoke (false) the privilege.
     * @notice Only callable by a DAO admin.
     */
    /// @inheritdoc I_TTSwap_Token
    function setMarketAdmin(address _recipient, bool result) external override {
        if (!userConfig[msg.sender].isDAOAdmin()) revert TTSwapError(62);
        userConfig[_recipient] = userConfig[_recipient].setMarketAdmin(result);
        emit e_updateUserConfig(_recipient, userConfig[_recipient]);
    }

    /**
     * @dev Grants or revokes Market manager privileges to a recipient address.
     * @param _recipient The address to grant or revoke Market manager rights.
     * @param result Boolean indicating whether to grant (true) or revoke (false) the privilege.
     * @notice Only callable by a Market admin.
     */
    /// @inheritdoc I_TTSwap_Token
    function setMarketManager(
        address _recipient,
        bool result
    ) external override {
        if (!userConfig[msg.sender].isMarketAdmin()) revert TTSwapError(1);
        userConfig[_recipient] = userConfig[_recipient].setMarketManager(
            result
        );
        emit e_updateUserConfig(_recipient, userConfig[_recipient]);
    }

    /**
     * @dev Grants or revokes Stake admin privileges to a recipient address.
     * @param _recipient The address to grant or revoke Stake admin rights.
     * @param result Boolean indicating whether to grant (true) or revoke (false) the privilege.
     * @notice Only callable by a DAO admin.
     */
    /// @inheritdoc I_TTSwap_Token
    function setStakeAdmin(address _recipient, bool result) external override {
        if (!userConfig[msg.sender].isDAOAdmin()) revert TTSwapError(62);
        userConfig[_recipient] = userConfig[_recipient].setStakeAdmin(result);
        emit e_updateUserConfig(_recipient, userConfig[_recipient]);
    }

    /**
     * @dev Grants or revokes Stake manager privileges to a recipient address.
     * @param _recipient The address to grant or revoke Stake manager rights.
     * @param result Boolean indicating whether to grant (true) or revoke (false) the privilege.
     * @notice Only callable by a Stake admin.
     */
    /// @inheritdoc I_TTSwap_Token
    function setStakeManager(
        address _recipient,
        bool result
    ) external override {
        if (!userConfig[msg.sender].isStakeAdmin()) revert TTSwapError(64);
        userConfig[_recipient] = userConfig[_recipient].setStakeManager(result);
        emit e_updateUserConfig(_recipient, userConfig[_recipient]);
    }

    /**
     * @dev Sets or unsets a ban on a recipient address, restricting their access.
     * @param _recipient The address to ban or unban.
     * @param result Boolean indicating whether to ban (true) or unban (false) the address.
     * @notice Only callable by a Token manager.
     */
    /// @inheritdoc I_TTSwap_Token
    function setBan(address _recipient, bool result) external override {
        if (!userConfig[msg.sender].isTokenManager()) revert TTSwapError(65);
        userConfig[_recipient] = userConfig[_recipient].setBan(result);
        emit e_updateUserConfig(_recipient, userConfig[_recipient]);
    }

    /**
     * @dev Returns the share information for a given user address.
     * @param user The address to query for share information.
     * @return The s_share struct containing the user's share details.
     */
    /// @inheritdoc I_TTSwap_Token
    function usershares(
        address user
    ) external view override returns (s_share memory) {
        return shares[user];
    }

    /**
     * @dev Returns the stake proof information for a given index.
     * @param index The index to query for stake proof information.
     * @return The s_proof struct containing the stake proof details.
     */
    /// @inheritdoc I_TTSwap_Token
    function stakeproofinfo(
        uint256 index
    ) external view override returns (s_proof memory) {
        return stakeproof[index];
    }

    /**
     * @dev Adds a referral relationship between a user and a referrer
     * @param user The address of the user being referred
     * @param referral The address of the referrer
     * @notice Only callable by authorized addresses (auths[msg.sender] == 1)
     * @notice Will only set the referral if the user doesn't already have one
     */
    /// @inheritdoc I_TTSwap_Token
    function setReferral(address user, address referral) external override {
        if (
            userConfig[msg.sender].isCallMintTTS() &&
            userConfig[user].referral() == address(0) &&
            user != referral
        ) {
            userConfig[user] = userConfig[user].setReferral(referral);
        }
        emit e_addreferral(user, referral);
    }

    /**
     * @dev Retrieves both the DAO admin address and the referrer address for a given customer
     * @param _customer The address of the customer
     * @return A tuple containing the DAO admin address and the customer's referrer address
     */
    /// @inheritdoc I_TTSwap_Token
    function getreferral(
        address _customer
    ) external view override returns (address) {
        return userConfig[_customer].referral();
    }

    /**
     * @dev  this chain trade vol ratio in protocol
     */
    /// @inheritdoc I_TTSwap_Token
    function setRatio(uint256 _ratio) external override {
        if (_ratio > 10000) revert TTSwapError(66);
        if (!userConfig[msg.sender].isTokenAdmin()) revert TTSwapError(63);
        ttstokenconfig = ttstokenconfig.setratio(_ratio);
        emit e_updatettsconfig(ttstokenconfig);
    }

    /**
     * @dev Set environment variables for the contract
     * @param _marketcontract Address of the market contract
     */
    /// @inheritdoc I_TTSwap_Token
    function setEnv(address _marketcontract) external override {
        if (!userConfig[msg.sender].isDAOAdmin()) revert TTSwapError(62);
        marketcontract = _marketcontract;
        emit e_setenv(marketcontract);
    }
    /**
     * @dev Adds a new mint share to the contract
     * @param _share The share structure containing recipient, amount, metric, and chips
     * @notice Only callable on the main chain by the DAO admin
     * @notice Reduces the left_share by the amount in _share
     * @notice Increments the shares_index and adds the new share to the shares mapping
     * @notice Emits an e_addShare event with the share details
     */
    /// @inheritdoc I_TTSwap_Token
    function addShare(
        s_share memory _share,
        address owner
    ) external override onlymain {
        if (left_share < _share.leftamount) revert TTSwapError(67);
        if (!userConfig[msg.sender].isTokenAdmin()) revert TTSwapError(63);
        _addShare(_share, owner);
    }

    function _addShare(s_share memory _share, address owner) internal {
        left_share -= uint64(_share.leftamount);
        if (shares[owner].leftamount == 0) {
            shares[owner] = _share;
        } else {
            s_share memory newpart = shares[owner];
            newpart.leftamount += _share.leftamount;
            newpart.chips = newpart.chips >= _share.chips
                ? newpart.chips
                : _share.chips;
            newpart.metric = newpart.metric >= _share.metric
                ? newpart.metric
                : _share.metric;
            shares[owner] = newpart;
        }
        emit e_addShare(owner, _share.leftamount, _share.metric, _share.chips);
    }

    /**
     * @dev Burns (removes) a mint share from the contract
     * @param index The index of the share to burn
     * @notice Only callable on the main chain by the DAO admin
     * @notice Adds the leftamount of the burned share back to left_share
     * @notice Emits an e_burnShare event and deletes the share from the shares mapping
     */
    /// @inheritdoc I_TTSwap_Token
    function burnShare(address owner) external override onlymain {
        if (!userConfig[msg.sender].isTokenAdmin()) revert TTSwapError(63);
        left_share += uint64(shares[owner].leftamount);
        emit e_burnShare(owner);
        delete shares[owner];
    }

    /**
     * @dev Allows the DAO to mint tokens based on a specific share
     * @param index The index of the share to mint from
     * @notice Only callable on the main chain
     * @notice Requires the market price to be below a certain threshold
     * @notice Mints tokens to the share recipient, reduces leftamount, and increments metric
     * @notice Emits an e_daomint event with the minted amount and index
     */
    /// @inheritdoc I_TTSwap_Token
    function shareMint() external override onlymain {
        if (
            !I_TTSwap_Market(marketcontract).ishigher(
                address(this),
                usdt,
                2 ** shares[msg.sender].metric * 2 ** 128 + 20
            )
        ) revert TTSwapError(68);
        if (shares[msg.sender].leftamount == 0) revert TTSwapError(69);
        uint128 mintamount = shares[msg.sender].leftamount /
            shares[msg.sender].chips;
        shares[msg.sender].leftamount -= mintamount;
        shares[msg.sender].metric += 1;
        _mint(msg.sender, mintamount);
        emit e_shareMint(mintamount, msg.sender);
    }

    /**
     * @dev Perform public token sale
     * @param usdtamount Amount of USDT to spend on token purchase
     */
    /// @inheritdoc I_TTSwap_Token
    function publicSell(
        uint256 usdtamount,
        bytes calldata data
    ) external override onlymain {
        publicsell += uint128(usdtamount);
        if (publicsell > 500_000_000_000) revert TTSwapError(70);
        usdt.transferFrom(msg.sender, address(this), usdtamount, data);
        uint256 ttsamount;
        if (publicsell <= 87_500_000_000) {
            ttsamount = (usdtamount * 24);
            _mint(msg.sender, ttsamount);
        } else if (publicsell <= 162_500_000_000) {
            ttsamount = usdtamount * 20;
            _mint(msg.sender, ttsamount);
        } else if (publicsell <= 250_000_000_000) {
            ttsamount = (usdtamount * 16);
            _mint(msg.sender, ttsamount);
        }
        emit e_publicsell(usdtamount, ttsamount);
    }

    /**
     * @dev Withdraws funds from public token sale
     * @param amount The amount of USDT to withdraw
     * @param recipient The address to receive the withdrawn funds
     * @notice Only callable on the main chain by the DAO admin
     * @notice Transfers the specified amount of USDT to the recipient
     */
    /// @inheritdoc I_TTSwap_Token
    function withdrawPublicSell(
        uint256 amount,
        address recipient
    ) external override onlymain {
        if (!userConfig[msg.sender].isTokenAdmin()) revert TTSwapError(63);
        usdt.safeTransfer(recipient, amount);
    }

    /**
     * @dev Stake tokens
     * @param _staker Address of the staker
     * @param proofvalue Amount to stake
     * @return netconstruct Net construct value
     */
    /// @inheritdoc I_TTSwap_Token
    function stake(
        address _staker,
        uint128 proofvalue
    ) external override returns (uint128 netconstruct) {
        if (!userConfig[msg.sender].isCallMintTTS()) revert TTSwapError(71);
        _stakeFee();
        uint256 restakeid = uint256(keccak256(abi.encode(_staker, msg.sender)));
        netconstruct = poolstate.amount1() == 0
            ? 0
            : mulDiv(poolstate.amount0(), proofvalue, stakestate.amount1());
        poolstate = add(poolstate, toTTSwapUINT256(netconstruct, netconstruct));
        stakestate = add(stakestate, toTTSwapUINT256(0, proofvalue));
        stakeproof[restakeid].fromcontract = msg.sender;
        stakeproof[restakeid].proofstate = add(
            stakeproof[restakeid].proofstate,
            toTTSwapUINT256(proofvalue, netconstruct)
        );
        emit e_stakeinfo(
            _staker,
            stakeproof[restakeid].proofstate,
            toTTSwapUINT256(0, netconstruct),
            stakestate,
            poolstate
        );
    }

    /**
     * @dev Unstake tokens
     * @param _staker Address of the staker
     * @param proofvalue Amount to unstake
     */
    /// @inheritdoc I_TTSwap_Token
    function unstake(address _staker, uint128 proofvalue) external override {
        if (!userConfig[msg.sender].isCallMintTTS()) revert TTSwapError(71);
        _stakeFee();
        uint128 profit;
        uint128 construct;
        uint256 restakeid = uint256(keccak256(abi.encode(_staker, msg.sender)));
        if (proofvalue >= stakeproof[restakeid].proofstate.amount0()) {
            proofvalue = stakeproof[restakeid].proofstate.amount0();
            construct = stakeproof[restakeid].proofstate.amount1();
            delete stakeproof[restakeid];
        } else {
            construct = stakeproof[restakeid].proofstate.getamount1fromamount0(
                proofvalue
            );
            stakeproof[restakeid].proofstate = sub(
                stakeproof[restakeid].proofstate,
                toTTSwapUINT256(proofvalue, construct)
            );
        }
        profit = toTTSwapUINT256(poolstate.amount0(), stakestate.amount1())
            .getamount0fromamount1(proofvalue);
        stakestate = sub(stakestate, toTTSwapUINT256(0, proofvalue));
        poolstate = sub(poolstate, toTTSwapUINT256(profit, construct));
        profit = profit - construct;
        if (profit > 0) _mint(_staker, profit);
        emit e_stakeinfo(
            _staker,
            stakeproof[restakeid].proofstate,
            toTTSwapUINT256(construct, profit),
            stakestate,
            poolstate
        );
    }

    /**
     * @dev Internal function to handle staking fees
     */
    function _stakeFee() internal {
        if (stakestate.amount0() + 86400 < block.timestamp) {
            stakestate = add(stakestate, toTTSwapUINT256(86400, 0));
            uint128 leftamount = uint128(200_000_000_000_000 - totalSupply);
            uint128 mintamount = leftamount < 1000000
                ? 1000000
                : leftamount / 18250; //leftamount /50 /365
            poolstate = add(
                poolstate,
                toTTSwapUINT256(ttstokenconfig.getratio(mintamount), 0)
            );
            emit e_updatepool(
                toTTSwapUINT256(stakestate.amount0(), poolstate.amount0())
            );
        }
    }
    // burn
    /**
     * @dev Burn tokens from an account
     * @param account Address of the account to burn tokens from
     * @param value Amount of tokens to burn
     */
    /// @inheritdoc I_TTSwap_Token
    function burn(uint256 value) external override {
        _burn(msg.sender, value);
    }

    function _mint(address to, uint256 amount) internal override {
        totalSupply += amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(address(0), to, amount);
    }

    function _burn(address from, uint256 amount) internal override {
        balanceOf[from] -= amount;

        // Cannot underflow because a user's balance
        // will never be larger than the total supply.
        unchecked {
            totalSupply -= amount;
        }

        emit Transfer(from, address(0), amount);
    }
    /**
     * @dev Permits a share to be transferred
     * @param _share The share structure containing recipient, amount, metric, and chips
     * @param dealline The deadline for the share transfer
     * @param signature The signature of the share transfer
     * @param signer The address of the signer
     */
    /// @inheritdoc I_TTSwap_Token
    function permitShare(
        s_share memory _share,
        uint128 dealline,
        bytes calldata signature,
        address signer
    ) external override {
        if (block.timestamp > dealline) revert TTSwapError(72);
        // Verify the signer address from the signature.
        signature.verify(
            _hashTypedData(
                shareHash(
                    _share,
                    msg.sender,
                    shares[msg.sender].leftamount,
                    dealline,
                    nonces[msg.sender]++
                )
            ),
            userConfig[signer].isTokenAdmin() ? signer : address(0)
        );
        _addShare(_share, msg.sender);
    }

    /**
     * @dev Calculates the hash of a share transfer
     * @param _share The share structure containing recipient, amount, metric, and chips
     * @param owner The address of the owner
     * @param leftamount The amount of left share
     * @param deadline The deadline for the share transfer
     */
    function shareHash(
        s_share memory _share,
        address owner,
        uint128 leftamount,
        uint128 deadline,
        uint256 nonce
    ) public pure override returns (bytes32) {
        return
            keccak256(
                abi.encode(
                    _PERMITSHARE_TYPEHASH,
                    _share.leftamount,
                    _share.chips,
                    _share.metric,
                    owner,
                    leftamount,
                    deadline,
                    nonce
                )
            );
    }

    /// @notice Builds a domain separator using the current chainId and contract address.
    function _buildDomainSeparator(
        bytes32 typeHash,
        bytes32 nameHash
    ) private view returns (bytes32) {
        return
            keccak256(
                abi.encode(typeHash, nameHash, block.chainid, address(this))
            );
    }

    /// @notice Creates an EIP-712 typed data hash
    function _hashTypedData(bytes32 dataHash) internal view returns (bytes32) {
        return
            keccak256(
                abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR(), dataHash)
            );
    }

    function DOMAIN_SEPARATOR()
        public
        view
        override(ERC20, IEIP712)
        returns (bytes32)
    {
        return
            block.chainid == INITIAL_CHAIN_ID
                ? INITIAL_DOMAIN_SEPARATOR
                : computeDomainSeparator();
    }

    function computeDomainSeparator() internal view override returns (bytes32) {
        return
            _buildDomainSeparator(
                keccak256(
                    "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
                ),
                keccak256(bytes(name))
            );
    }

    function disableUpgrade() external {
        if (!userConfig[msg.sender].isDAOAdmin()) revert TTSwapError(62);
        upgradeable = false;
    }

    function mint(address to, uint256 amount) external {
        if (!userConfig[msg.sender].isDAOAdmin()) revert TTSwapError(62);
        _mint(to, amount);
    }

    function burn(address from, uint256 amount) external {
        if (!userConfig[msg.sender].isDAOAdmin()) revert TTSwapError(62);
        _burn(from, amount);
    }
}
"
    },
    "src/libraries/L_SignatureVerification.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

library L_SignatureVerification {
    /// @notice Thrown when the passed in signature is not a valid length
    error InvalidSignatureLength();

    /// @notice Thrown when the recovered signer is equal to the zero address
    error InvalidSignature();

    /// @notice Thrown when the recovered signer does not equal the claimedSigner
    error InvalidSigner();

    /// @notice Thrown when the recovered contract signature is incorrect
    error InvalidContractSignature();

    bytes32 constant UPPER_BIT_MASK = (0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);

    function verify(bytes calldata signature, bytes32 hash, address claimedSigner) internal pure {
        bytes32 r;
        bytes32 s;
        uint8 v;

        if (signature.length == 65) {
            (r, s) = abi.decode(signature, (bytes32, bytes32));
            v = uint8(signature[64]);
        } else if (signature.length == 64) {
            // EIP-2098
            bytes32 vs;
            (r, vs) = abi.decode(signature, (bytes32, bytes32));
            s = vs & UPPER_BIT_MASK;
            v = uint8(uint256(vs >> 255)) + 27;
        } else {
            revert InvalidSignatureLength();
        }
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) revert InvalidSignature();
        if (signer != claimedSigner) revert InvalidSigner();
    }
}
"
    },
    "src/interfaces/IEIP712.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IEIP712 {
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}
"
    },
    "src/libraries/L_TTSwapUINT256.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.29;

using L_TTSwapUINT256Library for uint256;
/// @notice Converts two uint128 values into a T_BalanceUINT256
/// @param _amount0 The first 128-bit amount
/// @param _amount1 The second 128-bit amount
/// @return balanceDelta The resulting T_BalanceUINT256

function toTTSwapUINT256(uint128 _amount0, uint128 _amount1) pure returns (uint256 balanceDelta) {
    assembly ("memory-safe") {
        balanceDelta :=
            or(shl(128, _amount0), and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, _amount1))
    }
}

/// @notice Adds two T_BalanceUINT256 values
/// @param a The first T_BalanceUINT256
/// @param b The second T_BalanceUINT256
/// @return The sum of a and b as a T_BalanceUINT256
function add(uint256 a, uint256 b) pure returns (uint256) {
    uint256 res0;
    uint256 res1;
    uint256 a0;
    uint256 a1;
    uint256 b0;
    uint256 b1;
    assembly ("memory-safe") {
         a0 := shr(128, a)
         a1 := and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, a)
         b0 := shr(128, b)
         b1 := and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, b)
        res0 := add(a0, b0)
        res1 := add(a1, b1)
    }
    require(res0 >= a0 && res0 >= b0 && res1 >= a1 && res1 >= b1 && res1 <type(uint128).max && res0 <type(uint128).max, "TTSwapUINT256: add overflow");
    return (res0<<128)+res1;
}


/// @notice Subtracts two T_BalanceUINT256 values
/// @param a The first T_BalanceUINT256
/// @param b The second T_BalanceUINT256
/// @return The difference of a and b as a T_BalanceUINT256
function sub(uint256 a, uint256 b) pure returns (uint256) {
    uint256 res0;
    uint256 res1;
    uint256 a0;
    uint256 a1;
    uint256 b0;
    uint256 b1;
    unchecked{
    assembly ("memory-safe") {
         a0 := shr(128, a)
         a1 := and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, a)
         b0 := shr(128, b)
         b1 := and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, b)
        res0 := sub(a0, b0)
        res1 := sub(a1, b1)
    }}
    require(res0 <=a0 && res1<=a1 &&a1>=b1 && a0>=b0, "TTSwapUINT256: sub overflow");
    return (res0<<128)+res1;
}

/// @notice Adds the first components and subtracts the second components of two T_BalanceUINT256 values
/// @param a The first T_BalanceUINT256
/// @param b The second T_BalanceUINT256
/// @return The result of (a0 + b0, a1 - b1) as a T_BalanceUINT256
function addsub(uint256 a, uint256 b) pure returns (uint256) {
    uint256 res0;
    uint256 res1;
    uint256 a0;
    uint256 a1;
    uint256 b0;
    uint256 b1;
    unchecked{
    assembly ("memory-safe") {
         a0 := shr(128, a)
         a1 := and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, a)
         b0 := shr(128, b)
         b1 := and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, b)
        res0 := add(a0, b0)
        res1 := sub(a1, b1)
    }}
    require(res0 >=a0 && res0>=b0 && res1<=a1 && a1>=b1 && res0<type(uint128).max , "TTSwapUINT256: addsub overflow");
    return (res0<<128)+res1;
}

/// @notice Subtracts the first components and adds the second components of two T_BalanceUINT256 values
/// @param a The first T_BalanceUINT256
/// @param b The second T_BalanceUINT256
/// @return The result of (a0 - b0, a1 + b1) as a T_BalanceUINT256
function subadd(uint256 a, uint256 b) pure returns (uint256) {
    uint256 res0;
    uint256 res1;
    uint256 a0;
    uint256 a1;
    uint256 b0;
    uint256 b1;
    unchecked{
    assembly ("memory-safe") {
        a0 := sar(128, a)
        a1 := and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, a)
        b0 := sar(128, b)
        b1 := and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, b)
        res0 := sub(a0, b0)
        res1 := add(a1, b1)
    }}

    require(res1 >=a1 && res1>=b1 && res0<=a0 && a0>=b0 && res1<type(uint128).max , "TTSwapUINT256: subadd overflow");
    return (res0<<128)+res1;
}

/// @notice Safely converts a uint256 to a uint128
/// @param a The uint256 value to convert
/// @return b converted uint128 value, or 0 if overflow
function toUint128(uint256 a) pure returns (uint128 b) {
    b=uint128(a);
    require(a==uint256(b) , "TTSwapUINT256: toUint128 overflow");
}

/// @notice Compares the prices of three T_BalanceUINT256 values
/// @param a The first T_BalanceUINT256
/// @param b The second T_BalanceUINT256
/// @param c The third T_BalanceUINT256
/// @return True if the price of a is lower than the prices of b and c, false otherwise
function lowerprice(uint256 a, uint256 b, uint256 c) pure returns (bool) {
    return uint256(a.amount0()) * uint256(b.amount1()) * uint256(c.amount1())
        > uint256(a.amount1()) * uint256(b.amount0()) * uint256(c.amount0()) ? true : false;
}

/// @notice Performs a multiplication followed by a division
/// @param config The multiplicand
/// @param amount The multiplier
/// @param domitor The divisor
/// @return a The result as a uint128
function mulDiv(uint256 config, uint256 amount, uint256 domitor) pure returns (uint128 a) {
    uint256 result;
    unchecked {
        assembly {
            config := mul(config, amount)
            result := div(config, domitor)
        }
    }
    return toUint128(result);
}

/// @title L_TTSwapUINT256Library
/// @notice A library for operations on T_BalanceUINT256
library L_TTSwapUINT256Library {
    /// @notice Extracts the first 128-bit amount from a T_BalanceUINT256
    /// @param balanceDelta The T_BalanceUINT256 to extract from
    /// @return _amount0 The extracted first 128-bit amount
    function amount0(uint256 balanceDelta) internal pure returns (uint128 _amount0) {
        assembly {
            _amount0 := shr(128, balanceDelta)
        }
    }

    /// @notice Extracts the second 128-bit amount from a T_BalanceUINT256
    /// @param balanceDelta The T_BalanceUINT256 to extract from
    /// @return _amount1 The extracted second 128-bit amount
    function amount1(uint256 balanceDelta) internal pure returns (uint128 _amount1) {
        assembly {
            _amount1 := balanceDelta
        }
    }

    /// @notice Extracts the first and second 128-bit amounts from a T_BalanceUINT256
    /// @param balanceDelta The T_BalanceUINT256 to extract from
    /// @return _amount0 The extracted first 128-bit amount
    /// @return _amount1 The extracted second 128-bit amount
    function amount01(uint256 balanceDelta) internal pure returns (uint128 _amount0,uint128 _amount1) {
        assembly {
            _amount0 := shr(128, balanceDelta)
            _amount1 := balanceDelta
        }
    }

    /// @notice Calculates amount0 based on a given amount1 and the ratio in balanceDelta
    /// @param balanceDelta The T_BalanceUINT256 containing the ratio
    /// @param amount1delta The amount1 to base the calculation on
    /// @return _amount0 The calculated amount0
    function getamount0fromamount1(uint256 balanceDelta, uint128 amount1delta)
        internal
        pure
        returns (uint128 _amount0)
    {
        return mulDiv(balanceDelta.amount0(), amount1delta, balanceDelta.amount1());
    }

    /// @notice Calculates amount1 based on a given amount0 and the ratio in balanceDelta
    /// @param balanceDelta The T_BalanceUINT256 containing the ratio
    /// @param amount0delta The amount0 to base the calculation on
    /// @return _amount1 The calculated amount1
    function getamount1fromamount0(uint256 balanceDelta, uint128 amount0delta)
        internal
        pure
        returns (uint128 _amount1)
    {
        return mulDiv(balanceDelta.amount1(), amount0delta, balanceDelta.amount0());
    }
}
"
    },
    "src/libraries/L_Error.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.29;

error TTSwapError(uint256 seq);
"
    },
    "src/libraries/L_Currency.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.29;

import {IAllowanceTransfer} from "../interfaces/IAllowanceTransfer.sol";
import {ISignatureTransfer} from "../interfaces/ISignatureTransfer.sol";
import {IERC20Permit} from "../interfaces/IERC20Permit.sol";
import {IERC20} from "../interfaces/IERC20.sol";
import {IDAIPermit} from "../interfaces/IDAIPermit.sol";
import {L_Transient} from "./L_Transient.sol";

address constant NATIVE = address(1);
address constant dai = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address constant _permit2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;

/// @title L_CurrencyLibrary
/// @dev This library allows for transferring and holding native tokens and ERC20 tokens
library L_CurrencyLibrary {
    using L_CurrencyLibrary for address;

    struct S_Permit {
        uint256 value;
        uint256 deadline;
        uint8 v;
        bytes32 r;
        bytes32 s;
    }

    struct S_Permit2 {
        uint256 value;
        uint256 deadline;
        uint256 nonce;
        uint8 v;
        bytes32 r;
        bytes32 s;
    }

    bytes constant defualtvalue = bytes("");

    struct S_transferData {
        uint8 transfertype;
        bytes sigdata;
    }

    /// @notice Thrown when an ERC20 transfer fails
    error NativeETHTransferFailed();
    /// @notice Thrown when an ERC20 transfer fails
    error ERC20TransferFailed();
    /// @notice Thrown when an ERC20Permit transfer fails
    error ERC20PermitFailed();

    error ApproveFailed();

    function balanceof(
        address token,
        address _sender
    ) internal view returns (uint256 amount) {
        if (token.isNative()) {
            amount = address(_sender).balance;
        } else {
            amount = IERC20(token).balanceOf(_sender);
        }
    }

    function transferFrom(
        address token,
        address from,
        address to,
        uint256 amount,
        bytes calldata detail
    ) internal {
        bool success;
        if (token.isNative()) {
            L_Transient.decreaseValue(amount);
        } else if (detail.length == 0) {
            transferFromInter(token, from, to, amount);
        } else {
            S_transferData memory _simplePermit = abi.decode(
                detail,
                (S_transferData)
            );
            if (_simplePermit.transfertype == 2) {
                S_Permit memory _permit = abi.decode(
                    _simplePermit.sigdata,
                    (S_Permit)
                );
                bytes memory inputdata = token == dai
                    ? abi.encodeCall(
                        IDAIPermit.permit,
                        (
                            from,
                            address(this),
                            IDAIPermit(token).nonces(from),
                            _permit.deadline,
                            true,
                            _permit.v,
                            _permit.r,
                            _permit.s
                        )
                    )
                    : abi.encodeCall(
                        IERC20Permit.permit,
                        (
                            from,
                            address(this),
                            _permit.value,
                            _permit.deadline,
                            _permit.v,
                            _permit.r,
                            _permit.s
                        )
                    );

                assembly {
                    success := call(
                        gas(),
                        token,
                        0,
                        add(inputdata, 32),
                        mload(inputdata),
                        0,
                        0
                    )
                }
                if (success) {
                    transferFromInter(token, from, to, amount);
                } else {
                    revert ERC20PermitFailed();
                }
            } else if (_simplePermit.transfertype == 3) {
                IAllowanceTransfer(_permit2).transferFrom(
                    from,
                    to,
                    to_uint160(amount),
                    token
                );
            } else if (_simplePermit.transfertype == 4) {
                S_Permit2 memory _permit = abi.decode(
                    _simplePermit.sigdata,
                    (S_Permit2)
                );
                IAllowanceTransfer(_permit2).permit(
                    from,
                    IAllowanceTransfer.PermitSingle({
                        details: IAllowanceTransfer.PermitDetails({
                            token: token,
                            amount: to_uint160(_permit.value),
                            // Use an unlimited expiration because it most
                            // closely mimics how a standard approval works.
                            expiration: type(uint48).max,
                            nonce: uint48(_permit.nonce)
                        }),
                        spender: address(this),
                        sigDeadline: _permit.deadline
                    }),
                    bytes.concat(_permit.r, _permit.s, bytes1(_permit.v))
                );

                IAllowanceTransfer(_permit2).transferFrom(
                    from,
                    to,
                    to_uint160(amount),
                    token
                );
            } else if (_simplePermit.transfertype == 5) {
                S_Permit2 memory _permit = abi.decode(
                    _simplePermit.sigdata,
                    (S_Permit2)
                );
                ISignatureTransfer(_permit2).permitTransferFrom(
                    ISignatureTransfer.PermitTransferFrom({
                        permitted: ISignatureTransfer.TokenPermissions({
                            token: token,
                            amount: _permit.value
                        }),
                        nonce: _permit.nonce,
                        deadline: _permit.deadline
                    }),
                    ISignatureTransfer.SignatureTransferDetails({
                        to: to,
                        requestedAmount: amount
                    }),
                    from,
                    bytes.concat(_permit.r, _permit.s, bytes1(_permit.v))
                );
            }
        }
    }

    function transferFrom(
        address token,
        address from,
        uint256 amount,
        bytes calldata trandata
    ) internal {
        address to = address(this);
        transferFrom(token, from, to, uint128(amount), trandata);
    }

    function transferFromInter(
        address currency,
        address from,
        address to,
        uint256 amount
    ) internal {
        bool success;

        /// @solidity memory-safe-assembly
        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(
                freeMemoryPointer,
                0x23b872dd00000000000000000000000000000000000000000000000000000000
            )
            mstore(
                add(freeMemoryPointer, 4),
                and(from, 0xffffffffffffffffffffffffffffffffffffffff)
            ) // Append and mask the "from" argument.
            mstore(
                add(freeMemoryPointer, 36),
                and(to, 0xffffffffffffffffffffffffffffffffffffffff)
            ) // Append and mask the "to" argument.
            mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.

            // We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
            // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
            success := call(gas(), currency, 0, freeMemoryPointer, 100, 0, 32)

            // Set success to whether the call reverted, if not we check it either
            // returned exactly 1 (can't just be non-zero data), or had no return data and token has code.
            if and(
                iszero(and(eq(mload(0), 1), gt(returndatasize(), 31))),
                success
            ) {
                success := iszero(
                    or(iszero(extcodesize(currency)), returndatasize())
                )
            }
        }

        if (!success) revert ERC20TransferFailed();
    }

    function safeTransfer(
        address currency,
        address to,
        uint256 amount
    ) internal {
        // implementation from
        // https://github.com/transmissions11/solmate/blob/e8f96f25d48fe702117ce76c79228ca4f20206cb/src/utils/SafeTransferLib.sol

        bool success;
        if (currency.isNative()) {
            assembly {
                // Transfer the ETH and store if it succeeded or not.
                success := call(gas(), to, amount, 0, 0, 0, 0)
            }
            if (!success) revert NativeETHTransferFailed();
        } else {
            /// @solidity memory-safe-assembly
            assembly {
                // Get a pointer to some free memory.
                let freeMemoryPointer := mload(0x40)

                // Write the abi-encoded calldata into memory, beginning with the function selector.
                mstore(
                    freeMemoryPointer,
                    0xa9059cbb00000000000000000000000000000000000000000000000000000000
                )
                mstore(
                    add(freeMemoryPointer, 4),
                    and(to, 0xffffffffffffffffffffffffffffffffffffffff)
                ) // Append and mask the "to" argument.
                mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.

                // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                success := call(
                    gas(),
                    currency,
                    0,
                    freeMemoryPointer,
                    68,
                    0,
                    32
                )

                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data and token has code.
                if and(
                    iszero(and(eq(mload(0), 1), gt(returndatasize(), 31))),
                    success
                ) {
                    success := iszero(
                        or(iszero(extcodesize(currency)), returndatasize())
                    )
                }
            }

            if (!success) revert ERC20TransferFailed();
        }
    }

    function isNative(address currency) internal pure returns (bool) {
        return currency == address(1);
    }

    function to_uint160(uint256 amount) internal pure returns (uint160) {
        return amount == uint160(amount) ? uint160(amount) : 0;
    }

    function to_uint256(address amount) internal pure returns (uint256 a) {
        return uint256(uint160(amount));
    }
}
"
    },
    "src/libraries/L_UserConfig.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.29;

/// @title Market Configuration Library
/// @notice Library for managing and calculating various fee configurations for a market
library L_UserConfigLibrary {
    function isDAOAdmin(uint256 config) internal pure returns(bool a){
        return (config&uint256(2**255))>0;
    }
    function setDAOAdmin(uint256 config,bool a)internal pure  returns(uint256 e){
        return (config&(~(uint256(2**255))))|(a?uint256(2**255):0);
    }

    function isTokenAdmin(uint256 config) internal pure returns(bool a){
        return (config&uint256(2**254))>0;
    }

    function setTokenAdmin(uint256 config,bool a)internal pure  returns(uint256 e){
        return config&~(uint256(2**254))|(a?uint256(2**254):0);
    }

    function isTokenManager(uint256 config) internal pure returns(bool a){
        return (config&uint256(2**253))>0;
    }

    function setTokenManager(uint256 config,bool a)internal pure  returns(uint256 e){
        return config&~(uint256(2**253))|(a?uint256(2**253):0);
    }

    function isMarketAdmin(uint256 config)internal pure returns(bool a){
        return (config&uint256(2**252))>0;
    }

    function setMarketAdmin(uint256 config,bool a)internal pure  returns(uint256 e){
        return config&~(uint256(2**252))|(a?uint256(2**252):0);
    }

    function isMarketManager(uint256 config)internal pure returns(bool a){
        return (config&uint256(2**251))>0;
    }

    function setMarketManager(uint256 config,bool a)internal pure  returns(uint256 e){
        return config&~(uint256(2**251))|(a?uint256(2**251):0);
    }

    function isCallMintTTS(uint256 config)internal pure returns(bool a){
        return (config&uint256(2**250))>0;
    }

    function setCallMintTTS(uint256 config,bool a)internal pure returns(uint256 e){
        return config&~(uint256(2**250))|(a?uint256(2**250):0);
    }

    function isStakeAdmin(uint256 config)internal pure returns(bool a){
        return (config&uint256(2**249))>0;
    }

    function setStakeAdmin(uint256 config,bool a)internal pure returns(uint256 e){
        return config&~(uint256(2**249))|(a?uint256(2**249):0);
    }

    function isStakeManager(uint256 config)internal pure returns(bool a){
        return (config&uint256(2**248))>0;
    }

    function setStakeManager(uint256 config,bool a)internal pure returns(uint256 e){
        return config&~(uint256(2**248))|(a?uint256(2**248):0);
    }

    function isBan(uint256 config)internal pure returns(bool a){
        return (config&uint256(2**160))>0;
    }

    function setBan(uint256 config,bool a)internal pure returns(uint256 e){
        return config&~(uint256(2**160))|(a?uint256(2**160):0);
    }

    function referral(uint256 config)internal pure returns(address a){
        return address(uint160(config));
    }

    function setReferral(uint256 config,address a)internal pure returns(uint256 e){
        return (config&~(uint256(2**160)-1))|uint256(uint160(a));
    }

}
"
    },
    "src/libraries/L_TTSTokenConfig.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity 0.8.29;

/// @title TTS Token Configuration Library
/// @notice A library for handling TTS token configurations
library L_TTSTokenConfigLibrary {
    /// @notice Checks if the given configuration represents a main item
    /// @dev Uses assembly to perform a bitwise right shift operation
    /// @param config The configuration value to check
    /// @return a True if the configuration represents a main item, false otherwise
    function ismain(uint256 config) internal pure returns (bool a) {
        uint256 b;
        assembly {
            b := shr(255, config)
        }
        return b == 1 ? true : false;
    }

    function getratio(uint256 config, uint128 amount) internal pure returns (uint128 b) {
        unchecked {
            assembly {
                config := and(config, 0xffff)
                config := mul(config, amount)
                b := div(config, 10000)
            }
        }
    }

    function setratio(uint256 config, uint256 ttsconfig) internal pure returns (uint256 b) {
        unchecked {
            assembly {
                ttsconfig := and(ttsconfig, 0xffff)
                config := shl(32, shr(32, config))
                b := add(ttsconfig, config)
            }
        }
    }
}
"
    },
    "src/interfaces/I_TTSwap_Token.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.29;

/// @title Investment Proof Interface
/// @notice Contains a series of interfaces for goods
interface I_TTSwap_Token {
    /// @notice Emitted when environment variables are set
    /// @param marketcontract The address of the market contract
    event e_setenv(address marketcontract);

    /// @notice Emitted when user config is updated
    /// @param user The address of the user
    /// @param config The new config value
    event e_updateUserConfig(address user, uint256 config);

    /// @notice Emitted when a referral relationship is added
    /// @param user The address of the user being referred
    event e_addreferral(address user, address referal);

    /// @notice Emitted when minting is added
    /// @param recipient The address receiving the minted tokens
    /// @param leftamount The remaining amount to be minted
    /// @param metric The metric used for minting
    /// @param chips The number of chips
    event e_addShare(
        address recipient,
        uint128 leftamount,
        uint120 metric,
        uint8 chips
    );

    /// @notice Emitted when minting is burned
    /// @param owner The index of the minting operation being burned
    event e_burnShare(address owner);

    /// @notice Emitted when DAO minting occurs
    /// @param mintamount The amount being minted
    /// @param owner The index of the minting operation
    event e_shareMint(uint128 mintamount, address owner);

    /// @notice Emitted during a public sale
    /// @param usdtamount The amount of USDT involved
    /// @param ttsamount The amount of TTS involved
    event e_publicsell(uint256 usdtamount, uint256 ttsamount);

    /// @notice Emitted when chain stake is synchronized
    /// @param chain The chain ID
    /// @param poolasset The pool asset value
    /// @param proofstate  The value of the pool
    //first 128 bit proofvalue,last 128 bit proofconstruct
    event e_syncChainStake(uint32 chain, uint128 poolasset, uint256 proofstate);

    /// @notice Emitted when unstaking occurs
    /// @param recipient The address receiving the unstaked tokens
    /// @param proofvalue first 128 bit proofvalue,last 128 bit poolcontruct
    /// @param unstakestate The state after unstaking
    /// @param stakestate The state of the stake
    /// @param poolstate The state of the pool
    event e_stakeinfo(
        address recipient,
        uint256 proofvalue,
        uint256 unstakestate,
        uint256 stakestate,
        uint256 poolstate
    );
    /// @notice Emitted when the pool state is updated
    /// @param poolstate The new state of the pool
    event e_updatepool(uint256 poolstate);
    /// @notice Emitted when the pool state is updated
    /// @param ttsconfig The new state of the pool
    event e_updatettsconfig(uint256 ttsconfig);

    /**
     * @dev Returns the share information for a given user address.
     * @param user The address to query for share information.
     * @return The s_share struct containing the user's share details.
     */
    function usershares(address user) external view returns (s_share memory);

    /**
     * @dev Returns the current staking state.
     * @return The staking state as a uint256 value.
     */
    function stakestate() external view returns (uint256);

    /**
     * @dev Returns the current pool state.
     * @return The pool state as a uint256 value.
     */
    function poolstate() external view returns (uint256);

    /**
     * @dev Returns the TTS token configuration value.
     * @return The configuration as a uint256 value.
     */
    function ttstokenconfig() external view returns (uint256);

    /**
     * @dev Returns the amount of left share available for minting.
     * @return The left share as a uint128 value.
     */
    function left_share() external view returns (uint128);

    /**
     * @dev Returns the stake proof information for a given index.
     * @param index The index to query for stake proof information.
     * @return The s_proof struct containing the stake proof details.
     */
    function stakeproofinfo(uint256 index) external view returns (s_proof memory);

    /**
     * @dev Sets the trading volume ratio for the protocol.
     * @param _ratio The new ratio value (max 10000).
     */
    function setRatio(uint256 _ratio) external;

    /**
     * @dev Grants or revokes DAO admin privileges to a recipient address.
     * @param _recipient The address to grant or revoke DAO admin rights.
     * @param result Boolean indicating whether to grant (true) or revoke (false) the privilege.
     */
    function setDAOAdmin(address _recipient, bool result) external;

    /**
     * @dev Grants or revokes Token admin privileges to a recipient address.
     * @param _recipient The address to grant or revoke Token admin rights.
     * @param result Boolean indicating whether to grant (true) or revoke (false) the privilege.
     */
    function setTokenAdmin(address _recipient, bool result) external;

    /**
     * @dev Grants or revokes Token manager privileges to a recipient address.
     * @param _recipient The address to grant or revoke Token manager rights.
     * @param result Boolean indicating whether to grant (true) or revoke (false) the privilege.
     */
    function setTokenManager(address _recipient, bool result) external;

    /**
     * @dev Grants or revokes permission to call mintTTS to a recipient address.
     * @param _recipient The address to grant or revoke permission.
     * @param result Boolean indicating whether to grant (true) or revoke (false) the privilege.
     */
    function setCallMintTTS(address _recipient, bool result) external;

    /**
     * @dev Grants or revokes Market admin privileges to a recipient address.
     * @param _recipient The address to grant or revoke Market admin rights.
     * @param result Boolean indicating whether to grant (true) or revoke (false) the privilege.
     */
    function setMarketAdmin(address _recipient, bool result) external;

    /**
     * @dev Grants or revokes Market manager privileges to a recipient address.
     * @param _recipient The address to grant or revoke Market manager rights.
     * @param result Boolean indicating whether to grant (true) or revoke (false) the privilege.
     */
    function setMarketManager(address _recipient, bool result) external;

    /**
     * @dev Grants or revokes Stake admin privileges to a recipient address.
     * @param _recipient The address to grant or revoke Stake admin rights.
     * @param result Boolean indicating whether to grant (true) or revoke (false) the privilege.
     */
    function setStakeAdmin(address _recipient, bool result) external;

    /**
     * @dev Grants or revokes Stake manager privileges to a recipient address.
     * @param _recipient The address to grant or revoke Stake manager rights.
     * @param result Boolean indicating whether to grant (true) or revoke (false) the privilege.
     */
    function setStakeManager(address _recipient, bool result) external;

    /**
     * @dev Sets or unsets a ban on a recipient address, restricting their access.
     * @param _recipient The address to ban or unban.
     * @param result Boolean indicating whether to ban (true) or unban (false) the address.
     */
    function setBan(address _recipient, bool result) external;

    /**
     * @dev  Returns the amount of TTS available for public sale
     * @return _publicsell Returns the amount of TTS available for public sale
     */
    function publicsell() external view returns (uint128 _publicsell);

    /**
     * @dev Returns the authorization level for a given address
     * @param recipent user's address
     * @return _auth Returns the authorization level
     */
    function userConfig(address recipent) external view returns (uint256 _auth);

    /**
     * @dev Sets the environment variables for normal good ID, value good ID, and market contract address
     * @param _marketcontract The address of the market contract
     */
    function setEnv(address _marketcontract) external; 
    /**
     * @dev Adds a new mint share to the contract
     * @param _share The share structure containing recipient, amount, metric, and chips
     * @notice Only callable on the main chain by the DAO admin
     * @notice Reduces the left_share by the amount in _share
     * @notice Increments the shares_index and adds the new share to the shares mapping
     * @notice Emits an e_addShare event with the share details
     */
    function addShare(s_share calldata _share, address owner) external;
    /**
     * @dev  Burns the share at the specified index
     * @param owner owner of share
     */
    function burnShare(address owner) external;
    /**
     * @dev  Mints a share at the specified
     */
    function shareMint() external;
    /**
     * @dev how much cost to buy tts
     * @param usdtamount usdt amount
     */
    function publicSell(uint256 usdtamount, bytes calldata data) external;
    /**
     * @dev  Withdraws the specified amount from the public sale to the recipient
     * @param amount admin tranfer public sell to another address
     * @param recipent user's address
     */
    function withdrawPublicSell(uint256 amount, address recipent) external;

    /**
     * @dev Burns the specified value of tokens from the given account
     * @param value the amount will be burned
     */
    function burn(uint256 value) external;

    /// @notice Add a referral relationship
    /// @param user The address of the user being referred
    /// @param referral The address of the referrer
    function setReferral(address user, address referral) external;

    /// @notice Stake tokens
    /// @param staker The address of the staker
    /// @param proofvalue The proof value for the stake
    /// @return construct The construct value after staking
    function stake(
        address staker,
        uint128 proofvalue
    ) external returns (uint128 construct);

    /// @notice Unstake tokens
    /// @param staker The address of the staker
    /// @param proofvalue The proof value for unstaking
    function unstake(address staker, uint128 proofvalue) external;

    /// @notice Get the DAO admin and referral for a customer
    /// @param _customer The address of the customer
    /// @return referral The address of the referrer
    function getreferral(
        address _customer
    ) external view returns (address referral);

    /**
     * @dev Permits a share to be transferred
     * @param _share The share structure containing recipient, amount, metric, and chips
     * @param dealline The deadline for the share transfer
     * @param signature The signature of the share transfer
     * @param signer The address of the signer
     */
    function permitShare(
        s_share memory _share,
        uint128 dealline,
        bytes calldata signature,
        address signer
    ) external;

    /**
     * @dev Calculates the hash of a share transfer
     * @param _share The share structure containing recipient, amount, metric, and chips
     * @param owner The address of the owner
     * @param leftamount The amount of left share
     * @param deadline The deadline for the share transfer
     */
    function shareHash(
        s_share memory _share,
        address owner,
        uint128 leftamount,
        uint128 deadline,
        uint256 nonce
    ) external pure returns (bytes32);
}

/// @notice Struct for share information
/// @dev Contains information about a share, including the amount of left to unlock, the metric, and the chips
struct s_share {
    uint128 leftamount; // unlock amount
    uint120 metric; //last unlock's metric
    uint8 chips; // define the share's chips, and every time unlock one chips
}

/// @notice Struct for proof information
/// @dev Contains information about a proof, including the contract address and the state
struct s_proof {
    address fromcontract; // from which contract
    uint256 proofstate; // stake's state  amount0 value 128 construct asset
}
"
    },
    "src/i

Tags:
ERC20, Multisig, Mintable, Burnable, Swap, Staking, Upgradeable, Multi-Signature, Factory|addr:0x5274edaf131503fb6f4624194818a38a3add8b04|verified:true|block:23580505|tx:0xeec48476c82ca2cd1d0a48fe29101e72b1f3ca45738d7db5a557b0953e0b0f76|first_check:1760519375

Submitted on: 2025-10-15 11:09:37

Comments

Log in to comment.

No comments yet.