Address Contract Verified
Address
0x1B803165B3808C8a3f8BeF759cb25bD5169Ca458
Balance
0 ETH
Nonce
1
Code Size
596 bytes
Creator
0x9faf97D1...17CC at tx 0x4474d876...eacac6
Indexed Transactions
0
Contract Bytecode
596 bytes
0x60806040526004361015610015575b366101e957005b5f3560e01c80630900f0101461003457638ccbd6da0361000e57610146565b346101425760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101425760043573ffffffffffffffffffffffffffffffffffffffff8116810361014257335f52600b6020527f400000000000000000000000000000000000000000000000000000000000000060405f205416158015610132575b610105576101039073ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffff00000000000000000000000000000000000000006006541617600655565b005b7fd1b51911000000000000000000000000000000000000000000000000000000005f52600160045260245ffd5b5060ff60065460a01c16156100ba565b5f80fd5b34610142575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261014257335f52600b6020527f200000000000000000000000000000000000000000000000000000000000000060405f2054161580156101d9575b61010557600680547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055005b5060ff60065460a01c16156101ab565b5f8073ffffffffffffffffffffffffffffffffffffffff60065416368280378136915af43d5f803e1561021a573d5ff35b3d5ffdfea2646970667358221220d25ce77994d2d6c122fa1298ba92bd13737cf5f53b948da9fe6ce2b4e343fa5864736f6c634300081d0033
Verified Source Code Full Match
Compiler: v0.8.29+commit.ab55807c
EVM: cancun
Optimization: Yes (10000 runs)
TTSwap_Token_Proxy.sol 85 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.29;
import {I_TTSwap_Token} from "./interfaces/I_TTSwap_Token.sol";
import {TTSwapError} from "./libraries/L_Error.sol";
import {L_UserConfigLibrary} from "./libraries/L_UserConfig.sol";
import {
toTTSwapUINT256
} from "./libraries/L_TTSwapUINT256.sol";
/**
* @title TTSwap_Market
* @dev Core market contract for TTSwap protocol that manages goods trading, investing, and staking operations
* @notice This contract implements a decentralized market system with the following key features:
* - Meta good, value goods, and normal goods management
* - Automated market making (AMM) with configurable fees
* - Investment and disinvestment mechanisms
* - Flash loan functionality
* - Commission distribution system
* - ETH or WETH staking integration
*/
contract TTSwap_Token_Proxy {
using L_UserConfigLibrary for uint256;
string internal name ;
string internal symbol ;
string internal totalSupply;
mapping(address => uint256) internal balanceOf;
mapping(address => mapping(address => uint256)) internal allowance;
mapping(address => uint256) internal nonces;
address internal implementation;
bool internal upgradeable;
address internal usdt;
uint256 internal ttstokenconfig;
uint256 internal stakestate;
uint128 internal left_share = 45_000_000_000_000;
uint128 internal publicsell ;
mapping(address => uint256) internal userConfig;
event e_updateUserConfig(address user, uint256 config);
constructor(
address _usdt, address _dao_admin, uint256 _ttsconfig,string memory _name,string memory _symbol,address _implementation
) {
usdt = _usdt;
stakestate = toTTSwapUINT256(uint128(block.timestamp), 0);
ttstokenconfig = _ttsconfig;
userConfig[_dao_admin]=userConfig[_dao_admin].setDAOAdmin(true);
name =_name;
symbol=_symbol;
implementation=_implementation;
upgradeable=true;
emit e_updateUserConfig(_dao_admin,userConfig[_dao_admin]);
}
fallback() external payable{
address impl = implementation;
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), impl, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
if iszero(result) { revert(0, returndatasize()) }
return(0, returndatasize())
}
}
/// onlydao admin can execute
modifier onlyTokenAdminProxy() {
if (!userConfig[msg.sender].isTokenAdmin()||!upgradeable) revert TTSwapError(1);
_;
}
/// onlydao admin can execute
modifier onlyTokenOperatorProxy() {
if (!userConfig[msg.sender].isTokenManager()||!upgradeable) revert TTSwapError(1);
_;
}
function upgrade(address _implementation) external onlyTokenAdminProxy{
implementation=_implementation;
}
function freezeToken() external onlyTokenOperatorProxy{
implementation=address(0);
}
receive() external payable {}
}
I_TTSwap_Token.sol 303 lines
// 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
}
L_Error.sol 4 lines
// SPDX-License-Identifier: MIT pragma solidity 0.8.29; error TTSwapError(uint256 seq);
L_TTSwapUINT256.sol 166 lines
// 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;
assembly ("memory-safe") {
let a0 := sar(128, a)
let a1 := and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, a)
let b0 := sar(128, b)
let b1 := and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, b)
res0 := add(a0, b0)
res1 := add(a1, b1)
}
return toTTSwapUINT256(toUint128(res0), toUint128(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;
assembly ("memory-safe") {
let a0 := sar(128, a)
let a1 := and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, a)
let b0 := sar(128, b)
let b1 := and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, b)
res0 := sub(a0, b0)
res1 := sub(a1, b1)
}
return toTTSwapUINT256(toUint128(res0), toUint128(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;
assembly ("memory-safe") {
let a0 := sar(128, a)
let a1 := and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, a)
let b0 := sar(128, b)
let b1 := and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, b)
res0 := add(a0, b0)
res1 := sub(a1, b1)
}
return toTTSwapUINT256(toUint128(res0), toUint128(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;
assembly ("memory-safe") {
let a0 := sar(128, a)
let a1 := and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, a)
let b0 := sar(128, b)
let b1 := and(0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff, b)
res0 := sub(a0, b0)
res1 := add(a1, b1)
}
return toTTSwapUINT256(toUint128(res0), toUint128(res1));
}
/// @notice Safely converts a uint256 to a uint128
/// @param a The uint256 value to convert
/// @return The converted uint128 value, or 0 if overflow
function toUint128(uint256 a) pure returns (uint128) {
return a <= type(uint128).max ? uint128(a) : 0;
}
/// @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 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());
}
}
L_UserConfig.sol 86 lines
// 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));
}
}
Write Contract 2 functions
These functions modify contract state and require a wallet transaction to execute.
freezeToken 0x8ccbd6da
No parameters
upgrade 0x0900f010
address _implementation
Recent Transactions
No transactions found for this address