contractDiffusiveToken{// -----------------------------------------
// State Variables
// 状态变量
// -----------------------------------------
stringpublicname;stringpublicsymbol;uint8publicdecimals;uint256publictotalSupply;uint256publicmaxSupply;uint256publictransferFee;// Fee per token transferred in wei
// 以 wei 为单位的每个转移代币的费用
addresspublicowner;// -----------------------------------------
// Events
// 事件
// -----------------------------------------
eventTransfer(addressindexedfrom,addressindexedto,uint256amount);eventBurn(addressindexedburner,uint256amount);eventFeeUpdated(uint256newFee);eventMaxSupplyUpdated(uint256newMaxSupply);eventApproval(addressindexedowner,addressindexedspender,uint256value);// -----------------------------------------
// Modifiers
// 修饰符
// -----------------------------------------
modifieronlyOwner(){require(msg.sender==owner,"DiffusiveToken: caller is not the owner");_;}// -----------------------------------------
// Constructor
// 构造函数
// -----------------------------------------
/**
* @dev Constructor sets the initial parameters for the Diffusive Token.
* @param _name Token name
* @param _symbol Token symbol
* @param _decimals Decimal places
* @param _maxSupply The max supply of tokens that can ever exist
* @param _transferFee Initial fee per token transferred in wei
* @dev 构造函数设置 Diffusive Token 的初始参数。
* @param _name 代币名称
* @param _symbol 代币符号
* @param _decimals 小数位数
* @param _maxSupply 可以存在的代币的最大供应量
* @param _transferFee 以 wei 为单位的每个转移代币的初始费用
*/constructor(stringmemory_name,stringmemory_symbol,uint8_decimals,uint256_maxSupply,uint256_transferFee){name=_name;symbol=_symbol;decimals=_decimals;maxSupply=_maxSupply;transferFee=_transferFee;owner=msg.sender;totalSupply=0;// Initially, no tokens are minted
// 最初,没有铸造任何代币
}// -----------------------------------------
// External and Public Functions
// 外部和公共函数
// -----------------------------------------
/**
* @notice Returns the token balance of the given address.
* @param account The address to query
* @notice 返回给定地址的代币余额。
* @param account 要查询的地址
*/functionbalanceOf(addressaccount)externalviewreturns(uint256){returnbalances[account];}/**
* @notice Transfers `amount` tokens to address `to`, minting new tokens in the process.
* @dev Requires payment of native currency: transferFee * amount.
* @param to Recipient address
* @param amount Number of tokens to transfer
* @return True if successful
* @notice 将 `amount` 个代币转移到地址 `to`,在此过程中铸造新的代币。
* @dev 需要支付原生货币:transferFee * amount。
* @param to 接收者地址
* @param amount 要转移的代币数量
* @return 如果成功则为 True
*/functiontransfer(addressto,uint256amount)externalpayablereturns(bool){require(to!=address(0),"DiffusiveToken: transfer to zero address");require(amount>0,"DiffusiveToken: amount must be greater than zero");uint256requiredFee=transferFee*amount;require(msg.value>=requiredFee,"DiffusiveToken: insufficient fee");// Check max supply limit
// 检查最大供应量限制
require(totalSupply+amount<=maxSupply,"DiffusiveToken: would exceed max supply");// Mint new tokens to `to`
// 将新代币铸造到 `to`
balances[to]+=amount;totalSupply+=amount;emitTransfer(msg.sender,to,amount);returntrue;}/**
* @notice Burns `amount` tokens from the caller's balance, decreasing total supply.
* @param amount The number of tokens to burn
* @notice 从调用者的余额中销毁 `amount` 个代币,从而减少总供应量。
* @param amount 要燃烧的代币数量
*/functionburn(uint256amount)external{require(amount>0,"DiffusiveToken: burn amount must be greater than zero");require(balances[msg.sender]>=amount,"DiffusiveToken: insufficient balance");balances[msg.sender]-=amount;totalSupply-=amount;emitBurn(msg.sender,amount);}/**
* @notice Approves `spender` to transfer up to `amount` tokens on behalf of `msg.sender`.
* @param spender The address authorized to spend
* @param amount The max amount they can spend
* @notice 批准 `spender` 代表 `msg.sender` 转移最多 `amount` 个代币。
* @param spender 授权消费的地址
* @param amount 他们可以消费的最大金额
*/functionapprove(addressspender,uint256amount)externalreturns(bool){require(spender!=address(0),"DiffusiveToken: approve to zero address");allowances[msg.sender][spender]=amount;emitApproval(msg.sender,spender,amount);returntrue;}/**
* @notice Returns the current allowance of `spender` for `owner`.
* @param _owner The owner of the tokens
* @param _spender The address allowed to spend the tokens
* @notice 返回 `spender` 对 `owner` 的当前津贴。
* @param _owner 代币的所有者
* @param _spender 允许花费代币的地址
*/functionallowance(address_owner,address_spender)externalviewreturns(uint256){returnallowances[_owner][_spender];}/**
* @notice Transfers `amount` tokens from `from` to `to` using the allowance mechanism.
* @dev The `from` account does not lose tokens; this still mints to `to`.
* @param from The address from which the allowance has been given
* @param to The recipient address
* @param amount The number of tokens to transfer (mint)
* @notice 使用津贴机制将 `amount` 个代币从 `from` 转移到 `to`。
* @dev `from` 帐户不会丢失代币;这仍然会铸造到 `to`。
* @param from 已授予该津贴的地址
* @param to 收件人地址
* @param amount 要转移(铸造)的代币数量
*/functiontransferFrom(addressfrom,addressto,uint256amount)externalpayablereturns(bool){require(to!=address(0),"DiffusiveToken: transfer to zero address");require(amount>0,"DiffusiveToken: amount must be greater than zero");uint256allowed=allowances[from][msg.sender];require(allowed>=amount,"DiffusiveToken: allowance exceeded");// Deduct from allowance
// 从津贴中扣除
allowances[from][msg.sender]=allowed-amount;uint256requiredFee=transferFee*amount;require(msg.value>=requiredFee,"DiffusiveToken: insufficient fee");// Check max supply
// 检查最大供应量
require(totalSupply+amount<=maxSupply,"DiffusiveToken: would exceed max supply");// Mint tokens to `to`
// 将代币铸造到 `to`
balances[to]+=amount;totalSupply+=amount;emitTransfer(from,to,amount);returntrue;}// -----------------------------------------
// Owner Functions
// 所有者函数
// -----------------------------------------
/**
* @notice Updates the maximum supply of tokens. Must be >= current totalSupply.
* @param newMaxSupply The new maximum supply
* @notice 更新代币的最大供应量。必须 >= 当前 totalSupply。
* @param newMaxSupply 新的最大供应量
*/functionsetMaxSupply(uint256newMaxSupply)externalonlyOwner{require(newMaxSupply>=totalSupply,"DiffusiveToken: new max < current supply");maxSupply=newMaxSupply;emitMaxSupplyUpdated(newMaxSupply);}/**
* @notice Updates the per-token transfer fee.
* @param newFee The new fee in wei per token transferred
* @notice 更新每个代币的转移费用。
* @param newFee 以 wei 为单位的每个转移代币的新费用
*/functionsetTransferFee(uint256newFee)externalonlyOwner{transferFee=newFee;emitFeeUpdated(newFee);}/**
* @notice Allows the owner to withdraw accumulated native currency fees.
* @param recipient The address that will receive the withdrawn fees
* @notice 允许所有者提取累积的原生货币费用。
* @param recipient 将收到提取费用的地址
*/functionwithdrawFees(addresspayablerecipient)externalonlyOwner{require(recipient!=address(0),"DiffusiveToken: withdraw to zero address");uint256balance=address(this).balance;(boolsuccess,)=recipient.call{value:balance}("");require(success,"DiffusiveToken: withdrawal failed");}// -----------------------------------------
// Fallback and Receive
// 回退和接收
// -----------------------------------------
// Allows the contract to receive Ether.
// 允许合约接收 Ether。
receive()externalpayable{}}