You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

自定义ERC20合约向自建流动性池交易的异常问题

问题描述
  • 开发带有转账手续费机制和反狙击系统(限制特定时间段内地址转账)的ERC20代币,基于IUniswapV2Router02实现,当前系统仅部分可用
  • 在Goerli测试网部署合约并创建流动性池后,第二个钱包可完成一次买卖交易,但首次交易后所有钱包均无法再进行买卖操作
  • 首次交易正常执行,手续费已成功转入指定钱包,因此认为transferFrom函数逻辑无问题;猜测可能是流动性池储备未在首次转账后更新导致后续交易失败,但未收到任何错误提示
  • transfer函数逻辑与transferFrom一致,仅将from替换为msg.sender
transferFrom函数代码
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
    require(!AntiSnipeDenyList[from] && !AntiSnipeDenyList[to], "AntiSnipe: address is on denylist");
    address spender = _msgSender();
    _spendAllowance(from, spender, amount);

    uint256 lp_tax_amount = 0;
    uint256 dev_tax_amount = 0;
    uint256 marketing_tax_amount = 0;
    uint256 transfer_amount;

    if(
         msg.sender != _contractDeployer
        && msg.sender != owner()
        && msg.sender != _uniswapV2RouterAddress
        && to != address(this)
        && from != address(this)
    )
    {   
        
        // Calculate Taxes
        lp_tax_amount = (amount * _lpTax)/100;
        dev_tax_amount = (amount * _devTax)/100;
        marketing_tax_amount = (amount * _marketingTax)/100;

        // Calculate final transfer amount
        transfer_amount = amount - lp_tax_amount - dev_tax_amount - marketing_tax_amount;

        // Begin Max Wallet Check
        uint256 wallet_size = balanceOf(to);
        require((wallet_size + transfer_amount) <= _maxWallet, "IBIT: maximum wallet cannot be exceeded");

        // InfinityBit Token official contract address will be announced only after
        //   _ASB blocks have passed since contract deployment. Any transfers before
        //   such time are considered to be bot snipers, and will be locked.

        if(block.timestamp < deploy + 60){
           AntiSnipeDenyList[to] = true;
        }
       
    }
    else
    {
        transfer_amount = amount;
    }

    if(marketing_tax_amount > 0)
    {
        _transfer(from, _marketingWallet, marketing_tax_amount);
    }

    if(dev_tax_amount > 0)
    {
       _transfer(from, _devWallet, dev_tax_amount);
    }

    if(lp_tax_amount > 0)
    {
        _transfer(from, _lpWallet, lp_tax_amount);
    }

    _transfer(from, to, transfer_amount);
    return true;
}

内容的提问来源于stack exchange,提问作者user18541404

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 20:46:34