Contract Source Code:
pragma solidity 0.8.6;
// SPDX-License-Identifier: Unlicensed
contract DappToken {
string public name = "Sonic Test Token";
string public symbol = "STT";
string public standard = "Sonic Test Token v1.0";
uint256 public totalSupply = 1000000000000000;
uint256 public decimals = 18;
address public owner;
address public liquidityPool;
// Distribution tracking
uint256 public taxPool;
uint256 public lastDistribution;
uint256 public distributionInterval = 5 minutes;
uint256 public reflectionFee = 5; // Default 5% fee
// Reflection system
uint256 private constant pointMultiplier = 10 ** 18;
uint256 private totalDividendPoints;
uint256 private unclaimedDividends;
uint256 private blackListAmount;
struct Account {
uint256 balance;
uint256 lastDividendPoints;
}
mapping(address => Account) public accounts;
mapping(address => mapping(address => uint256)) public allowance;
mapping(address => bool) private _isExcluded;
mapping(address => bool) private isBlackListed;
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
event RewardsDistributed(uint256 amount);
modifier onlyOwner() {
require(msg.sender == owner, "Only owner can call");
_;
}
modifier updateAccount(address account) {
uint256 owing = dividendsOwing(account);
if (owing > 0) {
unclaimedDividends -= owing;
accounts[account].balance += owing;
}
accounts[account].lastDividendPoints = totalDividendPoints;
_;
}
constructor() {
owner = msg.sender;
accounts[msg.sender].balance = totalSupply;
_isExcluded[msg.sender] = true;
lastDistribution = block.timestamp;
emit Transfer(address(0), msg.sender, totalSupply);
}
function _transfer(address _from, address _to, uint256 _value)
internal
updateAccount(_from)
updateAccount(_to)
{
// Determine transaction type
bool isBuy = _from == liquidityPool;
bool isSell = _to == liquidityPool;
uint256 currentFee;
// Apply 5% tax only on buy/sell transactions
if (_isExcluded[_from]) {
currentFee = 0;
} else {
currentFee = (isBuy || isSell) ? reflectionFee : 0;
}
uint256 rAmount = (_value * currentFee) / 100;
uint256 amount = _value - rAmount;
// Update balances
accounts[_from].balance -= _value;
accounts[_to].balance += amount;
// Accumulate taxes for time-based distribution
if (rAmount > 0) {
taxPool += rAmount;
}
// Update blacklist tracking
if (isBlackListed[_from]) {
blackListAmount -= _value;
}
if (isBlackListed[_to]) {
blackListAmount += amount;
}
emit Transfer(_from, _to, amount);
}
// Add this new function to set liquidity pool address
function setLiquidityPool(address _pool) external onlyOwner {
liquidityPool = _pool;
_isExcluded[_pool] = true; // Optional: exclude LP from rewards
}
// Modified distribution function with time-based triggering
function distributeRewards() external {
require(
block.timestamp >= lastDistribution + distributionInterval,
"Must wait 5 minutes between distributions"
);
require(taxPool > 0, "No taxes to distribute");
disburse(taxPool);
taxPool = 0;
lastDistribution = block.timestamp;
emit RewardsDistributed(taxPool);
}
function disburse(uint256 amount) private {
uint256 totalCirculating = totalSupply - blackListAmount;
require(totalCirculating > 0, "No eligible holders");
totalDividendPoints += (amount * pointMultiplier) / totalCirculating;
unclaimedDividends += amount;
}
// Keep existing functions below (unchanged from original except for context) */
function transfer(address _to, uint256 _value) public returns (bool) {
require(accounts[msg.sender].balance >= _value);
_transfer(msg.sender, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool) {
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_value <= accounts[_from].balance);
require(_value <= allowance[_from][msg.sender]);
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
function dividendsOwing(address account) internal view returns (uint256) {
if (isBlackListed[account]) return 0;
uint256 newDividendPoints = totalDividendPoints - accounts[account].lastDividendPoints;
return (accounts[account].balance * newDividendPoints) / pointMultiplier;
}
function balanceOf(address account) public view returns (uint256) {
uint256 owing = dividendsOwing(account);
return accounts[account].balance + owing;
}
function mint(address recipient, uint256 amount) public onlyOwner updateAccount(recipient) {
accounts[recipient].balance += amount;
totalSupply += amount;
}
function blackList(address user) public onlyOwner updateAccount(user) {
if (!isBlackListed[user]) {
isBlackListed[user] = true;
blackListAmount += accounts[user].balance;
}
}
function unBlackList(address user) public onlyOwner updateAccount(user) {
if (isBlackListed[user]) {
isBlackListed[user] = false;
blackListAmount -= accounts[user].balance;
}
}
// Add function to update reflection fee
function setReflectionFee(uint256 _fee) external onlyOwner {
require(_fee <= 10, "Fee cannot exceed 10%");
reflectionFee = _fee;
}
}