Verified contractPartialMIT
ManageFee
Address0x12a908e073b6738747952fb483f2d657e2fa3a94
- Balance
0 ETH
- Transactions
2
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,437,225
- Creation transaction
- 0xa0010837f0…3f95c511bb
ManageFee.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.16 >=0.6.2 ^0.8.20 ^0.8.24 ^0.8.28;
// lib/openzeppelin-contracts/contracts/utils/Context.sol
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
/**
* @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;
}
}
// src/interfaces/IConfig.sol
/// @notice SPHToken 外部配置源(参数唯一权威)
interface IConfig {
struct TradeParams {
address keeper;
address stakingContractAddress;
address referralContract;
address lpRewardAddress;
address contributionRewardAddress;
address autoLpManagerAddress;
address fundWallet;
uint256 buyFeeBps;
uint256 sellFeeBps;
uint256 extraSellTaxBps;
uint16 buyTaxLpBps;
uint16 buyTaxLpRewardBps;
uint16 buyTaxContributionBps;
uint16 buyTaxFundBps;
uint16 buyTaxBurnBps;
uint16 sellTaxLpRewardBps;
uint16 sellTaxFundBps;
uint16 sellTaxBurnBps;
bool purchaseOpen;
/// @notice 历史字段;当前 Staking.claim 不读取
bool claimOpen;
bool burnEnabled;
uint16 maxTxBpsOfPool;
uint32 minBlocksBeforeSell;
bool stopAll;
bool enablePerBlockTradeLimit;
uint256 perBlockMaxTradeCount;
uint256 perBlockMaxTradeAmount;
bool enableTxPoolTradeLimit;
uint256 txPoolTradeLockSize;
uint256 txPoolTradeAmountSize;
bool enableMinBlocksBeforeSell;
address sphToken;
bool sellOpen;
bool enableBuyTax;
bool enableSellTax;
bool enableAddLiquidityTax;
bool enableRemoveLiquidityTax;
}
function tradeParams() external view returns (TradeParams memory);
/// @notice Ethereum mainnet USDT
function usdt() external view returns (address);
/// @notice Uniswap V2 Router02(Ethereum mainnet)
function uniswapV2RouterAddress() external view returns (address);
function keeper() external view returns (address);
function stakingContractAddress() external view returns (address);
function referralContract() external view returns (address);
function buyFeeBps() external view returns (uint256);
function sellFeeBps() external view returns (uint256);
function extraSellTaxBps() external view returns (uint256);
/// @notice UTC 自然日基准价(sphToUsdt(1e18) 口径);keeper 写入,跨日未写则沿用
function utcDayBaselinePrice() external view returns (uint256);
/// @notice 历史字段:线性免跌宽度;阶梯卖税模式下不参与同步
function extraTaxFreeBps() external view returns (uint256);
/// @notice 仅 Security:按跌幅覆盖写入 extraSellTaxBps
function syncExtraSellTaxBps(uint256 bps) external;
function lpRewardAddress() external view returns (address);
function contributionRewardAddress() external view returns (address);
function autoLpManagerAddress() external view returns (address);
function fundWallet() external view returns (address);
function purchaseOpen() external view returns (bool);
function claimOpen() external view returns (bool);
function burnEnabled() external view returns (bool);
function maxTxBpsOfPool() external view returns (uint16);
/// @notice 买入 U 限额:本笔付出 U ≤ 底池 USDT reserve × bps/10000;0=关闭(Security 钩子)
function maxTxBpsOfPoolBuy() external view returns (uint16);
/// @notice 卖出 U 限额:本笔 SPH 税后估值 U ≤ 底池 USDT reserve × bps/10000;0=关闭(Security 钩子)
function maxTxBpsOfPoolSell() external view returns (uint16);
function minBlocksBeforeSell() external view returns (uint32);
function isExcludedFromFees(address account) external view returns (bool);
function isBlacklisted(address account) external view returns (bool);
function isRecycleToAddressPermission(
address to
) external view returns (bool);
function securityContractAddress() external view returns (address);
/// @notice 卖税沉淀合约;非 0 时 SPHToken 卖税整笔打入该地址
function taxContractAddress() external view returns (address);
/// @notice 静态/动态出局倍数(默认 1)
function exitMultiple() external view returns (uint256);
/// @notice 出局计量模式:0=币数 1=U(默认 0=币本位)
function exitMetricMode() external view returns (uint256);
/// @notice 静态阶段累计产出阈值(index 0..2)
function phaseThresholds(uint256 index) external view returns (uint256);
/// @notice 静态阶段小时利率 bps(index 0..2;20 => 0.02%/h)
function hourlyBps(uint256 index) external view returns (uint256);
/// @notice 建单最低 USDT(18 位)
function minOrderUsdt() external view returns (uint256);
/// @notice 有效账户最低持币价值 USDT(18 位)
function minHoldingUsdt() external view returns (uint256);
/// @notice 单次 claim 实发上限(SPH,18 位)
function maxClaimSph() external view returns (uint256);
/// @notice 两次 claim 最小间隔(秒);0=不限制
function minClaimInterval() external view returns (uint256);
/// @notice 静态产出总开关(false 则 Staking 不计息)
function productionEnabled() external view returns (bool);
function enablePerBlockTradeLimit() external view returns (bool);
function perBlockMaxTradeCount() external view returns (uint256);
function perBlockMaxTradeAmount() external view returns (uint256);
function enableTxPoolTradeLimit() external view returns (bool);
function txPoolTradeLockSize() external view returns (uint256);
function txPoolTradeAmountSize() external view returns (uint256);
function enableMinBlocksBeforeSell() external view returns (bool);
function sphToken() external view returns (address);
function sellOpen() external view returns (bool);
function enableBuyTax() external view returns (bool);
function enableSellTax() external view returns (bool);
function enableAddLiquidityTax() external view returns (bool);
function enableRemoveLiquidityTax() external view returns (bool);
/// @notice 系统日长度(秒)。上线一般为 86400,测试可压缩
function dayLength() external view returns (uint256);
/// @notice 系统起始时间戳,用于计算日期 index
function systemStartTimestamp() external view returns (uint256);
/// @notice 指定时间戳对应的系统日 index
function getDayIndex(uint256 timestamp) external view returns (uint256);
/// @notice 排队通道硬闸:false 时 join 与 pull / join 尾带匹配均不可执行(默认 false,首期启动时置 true)
function enableQueue() external view returns (bool);
/// @notice 暂停标志:true 时禁止一切匹配与自动开下一期;仍允许入队与判定
function queuePaused() external view returns (bool);
/// @notice 是否在 managePermission 名单内(owner 不必在名单内)
function hasManagePermission(address account) external view returns (bool);
/// @notice owner / managePermission / Queue 合约可调
function setEnableQueue(bool enabled) external;
/// @notice owner / managePermission / Queue 合约可调
function setQueuePaused(bool paused) external;
/// @notice 配置基准目标;owner / managePermission / Queue 合约可调
function setQueueTargetAmount(uint256 amount) external;
/// @notice 递增倍数;owner / managePermission / Queue 合约可调
function setQueueTargetIncreaseRatio(uint256 ratio) external;
/// @notice 排单周期,单位是 dayLength 的个数
function queuePeriod() external view returns (uint256);
/// @notice 配置基准目标(整枚 USDT);每次正式开期把该期实际目标写回,下一期 = 基准 × 倍数
function queueTargetAmount() external view returns (uint256);
/// @notice 排单额度乘数,分母 10000。13000 表示每期目标 × 1.3
function queueTargetIncreaseRatio() external view returns (uint256);
/// @notice 单地址最低入金,单位是整枚 USDT
function queueMinEntryAmount() external view returns (uint256);
/// @notice 单地址每个排单周期最高入金,单位是整枚 USDT
function queueMaxEntryAmount() external view returns (uint256);
/// @notice 排单静态收益比例,分母 10000
function queueStaticRewardRatio() external view returns (uint256);
/// @notice 排单静态收益提现手续费比例,分母 10000
function queueFeeRatio() external view returns (uint256);
/// @notice 排单收益分配:回购,分母 10000
function specifiedAddress() external view returns (uint256);
/// @notice 排单收益分配:保险池,分母 10000
function insurancePoolAddress() external view returns (uint256);
/// @notice 排单收益分配:生态,分母 10000
function ecosystemAddress() external view returns (uint256);
/// @notice 排单收益分配:风险池,分母 10000
function riskPoolAddress() external view returns (uint256);
/// @notice 强制复投时间,单位是 dayLength 的个数
function queueForceRecycleTime() external view returns (uint256);
/// @notice 排队合约地址(鉴权 pull→staking / machine sync)
function queueContract() external view returns (address);
/// @notice 提现手续费分配钱包
function queueFeeBuybackWallet() external view returns (address);
function queueFeeInsuranceWallet() external view returns (address);
function queueFeeEcosystemWallet() external view returns (address);
function queueFeeRiskWallet() external view returns (address);
/// @notice 每满多少 USDT 一台矿机
function machineSlotUsdt() external view returns (uint256);
/// @notice 矿机管理费周期,单位 dayLength 个数
function machineFeeDays() external view returns (uint256);
/// @notice 默认单台算力(1e18=1.0)
function machineDefaultPower() external view returns (uint256);
/// @notice 全网未销毁矿机数(owner 维护,用于管理费档位)
function machineAliveCount() external view returns (uint256);
/// @notice 管理费档位数量(固定)
function machineFeeTierCount() external pure returns (uint256);
/// @notice 第 index 档上限(含):aliveCount <= 该值则命中此档;最后一档为 type(uint256).max
function machineFeeTierMaxAlive(uint256 index) external view returns (uint256);
/// @notice 第 index 档每台管理费(整枚 USDT)
function machineFeeTierPrice(uint256 index) external view returns (uint256);
/// @notice 按全网 alive 数量取当前档位单价(整枚 USDT)
function machineFeePriceByAlive(uint256 alive) external view returns (uint256);
/// @notice 日产上限(SPH wei),默认 5000e18
function machineDailyOutputCap() external view returns (uint256);
/// @notice 减产周期,单位 dayLength 个数,默认 90
function machineReduceDays() external view returns (uint256);
/// @notice 每次减产比例,分母 10000,默认 1000=10%
function machineReduceRatio() external view returns (uint256);
/// @notice 单地址名下矿机软上限(热列表),默认 50;超额不新建
function machinePerUserSoftCap() external view returns (uint256);
/// @notice true=结算/sync 不扫已销毁(归档)机,默认 true
function machineSkipDestroyedInSettle() external view returns (bool);
/// @notice claim 单次最多处理机台数,默认 50
function machineClaimBatchSize() external view returns (uint256);
/// @notice claim/pending 单次最多回溯系统日,默认 30;0=不限制
function machinePendingLookbackDays() external view returns (uint256);
/// @notice 结算全网算力地板:peak × 该 bps / 10000;默认 9000=90%;0=关闭
function machinePowerFloorBps() external view returns (uint256);
/// @notice 单次 pull 最多处理订单数,默认 10
function queuePullMaxOrders() external view returns (uint256);
/// @notice 单次从游标起最多扫描订单数,默认 32
function queuePullScanLimit() external view returns (uint256);
/// @notice true=匹配后延后 sync 矿机,默认 false(当场 sync)
function queueDeferMachineSync() external view returns (bool);
function enableCredentialPurchase() external view returns (bool);
function onlyAllowWhiteListPurchase() external view returns (bool);
/// @notice 凭证单价,单位是整枚 USDT
function credentialPrice() external view returns (uint256);
/// @notice 入队扣凭证百分比:扣量 = amount * 本值 / 100(整枚);取值 1–100,默认 100
function queueCredentialBurnPercent() external view returns (uint256);
/// @notice 白名单折扣比例,分母 10000
function whiteListDiscountRatio() external view returns (uint256);
function addsCouldCallCredentialBurn(
address account
) external view returns (bool);
/// @notice 购买凭证的 USDT 收款地址
function credentialDepositAddress() external view returns (address);
/// @notice 团队/级差奖励无法发放时的沉淀地址
function teamRewardSinkAddress() external view returns (address);
/// @notice 直推奖无法发放时的沉淀地址
function directRewardSinkAddress() external view returns (address);
/// @notice 平级奖无法发放时的沉淀地址
function peerRewardSinkAddress() external view returns (address);
/// @notice 级差/团队业绩/升级刷新向上层数(默认 30)
function dynamicRewardDepth() external view returns (uint256);
/// @notice 清算合约
function liquidationContract() external view returns (address);
/// @notice 矿机合约(可 bump alive)
function machineContract() external view returns (address);
/// @notice 管理费分账合约
function manageFeeContract() external view returns (address);
/// @notice 矿机产出线性释放合约
function sphLinearRelease() external view returns (address);
/// @notice true=claimMining 按价档拆锁仓入 SphLinearRelease
function enableMiningLinearRelease() external view returns (bool);
/// @notice 线性释放天数 N(入账重置),默认 100
function linearReleaseDays() external view returns (uint256);
/// @notice 价档 i 的最低价(USDT raw / 1e18 SPH),升序
function miningLockMinPrice(uint256 index) external view returns (uint256);
/// @notice 价档 i 的锁仓 bps
function miningLockBps(uint256 index) external view returns (uint256);
/// @notice 按瞬时价(USDT raw / 1e18 SPH)取锁仓 bps
function miningLockBpsForPrice(uint256 priceUsdtPerSph) external view returns (uint256);
/// @notice SPH 凭证合约
function sphCredential() external view returns (address);
/// @notice 损失额换台除数,默认 200
function liquidationLossDivisor() external view returns (uint256);
/// @notice 余数令牌:每枚凭证对应多少整枚 USDT,默认 1
function liquidationTokenUsdt() external view returns (uint256);
/// @notice 上两期本金返还比例,分母 10000,默认 5000=50%
function liquidationRefundBps() external view returns (uint256);
/// @notice 用户领取爆仓矿机时单笔最多铸造台数
function liquidationBatchMachines() external view returns (uint256);
/// @notice 是否可从凭证库存发放(爆仓余数令牌)
function addsCouldCallCredentialGrant(address account) external view returns (bool);
/// @notice 矿机合约调整活机数
function bumpMachineAliveCount(int256 delta) external;
}
// lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)
/**
* @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);
}
// lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
/**
* @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);
}
// src/interfaces/IManageFee.sol
/// @notice 管理费分账:Machine 缴费后调用
interface IManageFee {
/// @param amountRaw 本次实转 USDT raw(1e6 = 1U)
/// @param machineCount 台数(固定 3/10/1 × 台)
/// @param payer 缴费人
/// @param machineId 单台真实 ID;batch 可为 0
/// @param feeDays 本次覆盖配置天数(如 28;架子可忽略)
/// @param priceWhole 档位单价整枚 USDT/台(架子可忽略)
/// @param periodId 管理费定价期号(架子可忽略)
function sendManageFee(
uint256 amountRaw,
uint256 machineCount,
address payer,
uint256 machineId,
uint256 feeDays,
uint256 priceWhole,
uint256 periodId
) external;
}
// lib/openzeppelin-contracts/contracts/interfaces/IERC165.sol
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)
// lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)
// lib/openzeppelin-contracts/contracts/access/Ownable.sol
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.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);
}
}
// lib/openzeppelin-contracts/contracts/interfaces/IERC1363.sol
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.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);
}
// lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol
// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/utils/SafeERC20.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 {
if (!_safeTransfer(token, to, value, true)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @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 {
if (!_safeTransferFrom(token, from, to, value, true)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @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 _safeTransfer(token, to, value, false);
}
/**
* @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 _safeTransferFrom(token, from, to, value, false);
}
/**
* @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 {
if (!_safeApprove(token, spender, value, false)) {
if (!_safeApprove(token, spender, 0, true)) revert SafeERC20FailedOperation(address(token));
if (!_safeApprove(token, spender, value, true)) revert SafeERC20FailedOperation(address(token));
}
}
/**
* @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 relies 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 relies 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}.
* Oppositely, 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 `token.transfer(to, value)` call, 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 to The recipient of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeTransfer(IERC20 token, address to, uint256 value, bool bubble) private returns (bool success) {
bytes4 selector = IERC20.transfer.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(to, shr(96, not(0))))
mstore(0x24, value)
success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
}
}
/**
* @dev Imitates a Solidity `token.transferFrom(from, to, value)` call, 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 from The sender of the tokens
* @param to The recipient of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value,
bool bubble
) private returns (bool success) {
bytes4 selector = IERC20.transferFrom.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(from, shr(96, not(0))))
mstore(0x24, and(to, shr(96, not(0))))
mstore(0x44, value)
success := call(gas(), token, 0, 0x00, 0x64, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
mstore(0x60, 0)
}
}
/**
* @dev Imitates a Solidity `token.approve(spender, value)` call, 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 spender The spender of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeApprove(IERC20 token, address spender, uint256 value, bool bubble) private returns (bool success) {
bytes4 selector = IERC20.approve.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(spender, shr(96, not(0))))
mstore(0x24, value)
success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
}
}
}
// src/ManageFee.sol
/// @title 管理费分账路由(架子)。先按台扣固定额进前三池,剩余按 bps 进后四池。
/// @dev 分红资格 / 白名单不在本合约;仅 owner 可 rescueToken
contract ManageFee is IManageFee, Ownable {
using SafeERC20 for IERC20;
uint256 private constant USDT_UNIT = 1e6;
uint256 private constant BPS = 10_000;
address public config;
/// @notice 私募分红池(release_values)
address public privatePlacementPool =
0xA0ee015D060b3B375135eDa0eEAEeAF614975582;
/// @notice 级别分红池
address public levelSharePool =
0x30d0514E043958DE950b681e1F544bA4953A26FC;
/// @notice 社区白名单分红池
address public communityWhitelistPool =
0x62B9DF7712CF1479e87a9f01b91C6C7354cCe63C;
/// @notice 管理费-回购池
address public buybackPool =
0x1CBb2173fBbdd24174a9290Af5698D88d1285d93;
/// @notice 管理费保险池
address public insurancePool =
0xEd81110e9d6444BC0a5Fa70b32C6AD83C7271B67;
/// @notice 管理费风险池
address public riskPool =
0xcD65b5d55d9f6573E853fDcC64CCd798c24Df5eB;
/// @notice 管理费生态建设
address public ecosystemPool =
0xE156769f3887087f02F9E2aE74e5F4fF5e1c4085;
/// @notice 每台固定扣除(整枚 USDT):私募 / 级别 / 社区
uint256 public privatePlacementPerMachine = 3;
uint256 public levelSharePerMachine = 10;
uint256 public communityWhitelistPerMachine = 1;
/// @notice 剩余拆分 bps(须合计 10000):回购 / 保险 / 风险 / 生态
uint16 public buybackBps = 5000;
uint16 public insuranceBps = 2000;
uint16 public riskBps = 300;
uint16 public ecosystemBps = 2700;
error ZeroAddress();
error ConfigNotSet();
error NotMachine();
error ZeroAmount();
error BadCount();
error PoolsUnset();
error BadBpsSum();
error FeeTooLow();
error InsufficientBalance();
event ConfigSet(address indexed config);
event PoolsSet(
address privatePlacementPool,
address levelSharePool,
address communityWhitelistPool,
address buybackPool,
address insurancePool,
address riskPool,
address ecosystemPool
);
event FixedPerMachineSet(uint256 privatePlacement, uint256 levelShare, uint256 communityWhitelist);
event RemainBpsSet(uint16 buyback, uint16 insurance, uint16 risk, uint16 ecosystem);
event ManageFeeDistributed(
address indexed payer,
uint256 machineId,
uint256 machineCount,
uint256 amountRaw,
uint256 fixedRaw,
uint256 remainRaw
);
constructor() Ownable(msg.sender) {}
function setConfig(address config_) external onlyOwner {
if (config_ == address(0)) revert ZeroAddress();
config = config_;
emit ConfigSet(config_);
}
function setPools(
address privatePlacementPool_,
address levelSharePool_,
address communityWhitelistPool_,
address buybackPool_,
address insurancePool_,
address riskPool_,
address ecosystemPool_
) external onlyOwner {
if (
privatePlacementPool_ == address(0) ||
levelSharePool_ == address(0) ||
communityWhitelistPool_ == address(0) ||
buybackPool_ == address(0) ||
insurancePool_ == address(0) ||
riskPool_ == address(0) ||
ecosystemPool_ == address(0)
) revert ZeroAddress();
privatePlacementPool = privatePlacementPool_;
levelSharePool = levelSharePool_;
communityWhitelistPool = communityWhitelistPool_;
buybackPool = buybackPool_;
insurancePool = insurancePool_;
riskPool = riskPool_;
ecosystemPool = ecosystemPool_;
emit PoolsSet(
privatePlacementPool_,
levelSharePool_,
communityWhitelistPool_,
buybackPool_,
insurancePool_,
riskPool_,
ecosystemPool_
);
}
function setFixedPerMachine(
uint256 privatePlacement,
uint256 levelShare,
uint256 communityWhitelist
) external onlyOwner {
privatePlacementPerMachine = privatePlacement;
levelSharePerMachine = levelShare;
communityWhitelistPerMachine = communityWhitelist;
emit FixedPerMachineSet(privatePlacement, levelShare, communityWhitelist);
}
function setRemainBps(
uint16 buyback,
uint16 insurance,
uint16 risk,
uint16 ecosystem
) external onlyOwner {
if (uint256(buyback) + insurance + risk + ecosystem != BPS) revert BadBpsSum();
buybackBps = buyback;
insuranceBps = insurance;
riskBps = risk;
ecosystemBps = ecosystem;
emit RemainBpsSet(buyback, insurance, risk, ecosystem);
}
/// @inheritdoc IManageFee
function sendManageFee(
uint256 amountRaw,
uint256 machineCount,
address payer,
uint256 machineId,
uint256 /* feeDays */,
uint256 /* priceWhole */,
uint256 /* periodId */
) external override {
if (msg.sender != _cfg().machineContract()) revert NotMachine();
if (amountRaw == 0) revert ZeroAmount();
if (machineCount == 0) revert BadCount();
_requirePools();
IERC20 usdt = IERC20(_cfg().usdt());
if (usdt.balanceOf(address(this)) < amountRaw) revert InsufficientBalance();
uint256 fixedRaw = (privatePlacementPerMachine +
levelSharePerMachine +
communityWhitelistPerMachine) * machineCount * USDT_UNIT;
if (fixedRaw > amountRaw) revert FeeTooLow();
if (privatePlacementPerMachine > 0) {
usdt.safeTransfer(privatePlacementPool, privatePlacementPerMachine * machineCount * USDT_UNIT);
}
if (levelSharePerMachine > 0) {
usdt.safeTransfer(levelSharePool, levelSharePerMachine * machineCount * USDT_UNIT);
}
if (communityWhitelistPerMachine > 0) {
usdt.safeTransfer(communityWhitelistPool, communityWhitelistPerMachine * machineCount * USDT_UNIT);
}
uint256 remain = amountRaw - fixedRaw;
if (remain > 0) {
uint256 toBuyback = (remain * buybackBps) / BPS;
uint256 toInsurance = (remain * insuranceBps) / BPS;
uint256 toRisk = (remain * riskBps) / BPS;
uint256 toEco = remain - toBuyback - toInsurance - toRisk;
if (toBuyback > 0) usdt.safeTransfer(buybackPool, toBuyback);
if (toInsurance > 0) usdt.safeTransfer(insurancePool, toInsurance);
if (toRisk > 0) usdt.safeTransfer(riskPool, toRisk);
if (toEco > 0) usdt.safeTransfer(ecosystemPool, toEco);
}
emit ManageFeeDistributed(payer, machineId, machineCount, amountRaw, fixedRaw, remain);
}
function rescueToken(address token, address to, uint256 amount) external onlyOwner {
if (token == address(0) || to == address(0)) revert ZeroAddress();
IERC20(token).safeTransfer(to, amount);
}
function _requirePools() internal view {
if (
privatePlacementPool == address(0) ||
levelSharePool == address(0) ||
communityWhitelistPool == address(0) ||
buybackPool == address(0) ||
insurancePool == address(0) ||
riskPool == address(0) ||
ecosystemPool == address(0)
) revert PoolsUnset();
}
function _cfg() internal view returns (IConfig) {
address c = config;
if (c == address(0)) revert ConfigNotSet();
return IConfig(c);
}
}Compiler settingsShow
{
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.