500 寻找使用Vyper部署的带有交易税的ERC20代币模版

正在学习如何在ERC20代币中增加交易税,实现跟Safemoon类似的功能,添加流动性、分红。

找了好几天好像没有发现使用Vyper部署的合约,要是有见过的可以发链接让我学习下。

目前能够实现的是转账时收取交易税并且将税换成DAI,但如果我在sender==UniswapPair时在Uniswap交易的话就会失败。

下面是我的合约代码,没有在sender==UniswapPair时添加_swapTokensForETH,如果加了_swapTokensForETH功能就会失败。

@internal
def _swapTokensForETH(_amount: uint256):    

    self._approve(self, UNISWAP_ROUTE, _amount)

    raw_call(
        UNISWAP_ROUTE,
        concat(
            method_id("swapExactTokensForTokensSupportingFeeOnTransferTokens(uint256,uint256,address[],address,uint256)"),
            convert(_amount, bytes32),
            EMPTY_BYTES32,
            convert(160, bytes32),
            convert(self, bytes32),
            convert(block.timestamp, bytes32),
            convert(3, bytes32),
            convert(self, bytes32),
            convert(WETH, bytes32),
            convert(DAI, bytes32)
        )
    )

@internal
def _transfer(_from: address, _to: address, _value: uint256):

    self.balanceOf[_from] -= _value
    self.balanceOf[_to] += _value
    log Transfer(_from, _to, _value)

@external
@nonreentrant('lock')
def transfer(_to: address, _value: uint256) -> bool:
    """
    @dev Transfer token for a specified address
    @param _to The address to transfer to.
    @param _value The amount to be transferred.
    """
    # NOTE: vyper does not allow underflows
    #       so the following subtraction would revert on insufficient balance
    takeFeeAmount: uint256 = _value * self.takeFee / 100
    excludeFeeAmount: uint256 = _value - takeFeeAmount

    if msg.sender != self.UniswapPair:
        self._transfer(msg.sender, _to, excludeFeeAmount)
        self._transfer(msg.sender, self, takeFeeAmount)
        self._swapTokensForETH(takeFeeAmount)
    else:
        self._transfer(msg.sender, _to, excludeFeeAmount)
        self._transfer(msg.sender, self, takeFeeAmount)

    return True

这是转账,交易税是5%:

image.png

不是很清楚哪里出现了问题,如果有大佬能够回答或者有现成的模版学习最好了。

请先 登录 后评论

1 个回答

tengdw
请先 登录 后评论