kelpieinu / kelpie

0 stars 2 forks source link

Add in 20 seconds cooldown to sell after buy #1

Open kelpieinu opened 3 years ago

kelpieinu commented 3 years ago

To add in 20 seconds cooldown under _transfer function after function is perform with uniswap as a cooldown constructor, i don't need all the fees and setting, i just need a cooldown to block "bot" .

so i need a 20 seconds "lock" period where buyer cannot sell the token immediately if they transact with Uniswapv2 , reference code as below.

To make modification to :

https://github.com/kelpieinu/kelpie/blob/main/kelpie_contract

Such that it can have a 20 seconds lock to prevent sniping bot. Buy from UniswapV2 will be locked from selling for 20 seconds.

` function _transfer(address from, address to, uint256 amount) private { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(amount > 0, "Transfer amount must be greater than zero");

    if(from != owner() && to != owner()) {
        if(_cooldownEnabled) {
            if(!cooldown[msg.sender].exists) {
                cooldown[msg.sender] = User(0,0,true);
            }
        }

        // buy
        if(from == uniswapV2Pair && to != address(uniswapV2Router) && !_isExcludedFromFee[to]) {
            require(tradingOpen, "Trading not yet enabled.");
            _taxFee = 6;
            _teamFee = 4;
            if(_cooldownEnabled) {
                if(buyLimitEnd > block.timestamp) {
                    require(amount <= _maxBuyAmount);
                    require(cooldown[to].buy < block.timestamp, "Your buy cooldown has not expired.");
                    cooldown[to].buy = block.timestamp + (45 seconds);
                }
            }
            if(_cooldownEnabled) {
                cooldown[to].sell = block.timestamp + (15 seconds);
            }
        }
        uint256 contractTokenBalance = balanceOf(address(this));

        // sell
        if(!inSwap && from != uniswapV2Pair && tradingOpen) {

            if(_cooldownEnabled) {
                require(cooldown[from].sell < block.timestamp, "Your sell cooldown has not expired.");
            }

            if(_useImpactFeeSetter) {
                uint256 feeBasis = amount.mul(_feeMultiplier);
                feeBasis = feeBasis.div(balanceOf(uniswapV2Pair).add(amount));
                setFee(feeBasis);
            }

            if(contractTokenBalance > 0) {
                if(contractTokenBalance > balanceOf(uniswapV2Pair).mul(_feeRate).div(100)) {
                    contractTokenBalance = balanceOf(uniswapV2Pair).mul(_feeRate).div(100);
                }
                swapTokensForEth(contractTokenBalance);
            }
            uint256 contractETHBalance = address(this).balance;
            if(contractETHBalance > 0) {
                sendETHToFee(address(this).balance);
            }
        }
    }
    bool takeFee = true;

    if(_isExcludedFromFee[from] || _isExcludedFromFee[to]){
        takeFee = false;
    }

    _tokenTransfer(from,to,amount,takeFee);
}

function setCooldownEnabled(bool onoff) external onlyOwner() {
    _cooldownEnabled = onoff;
    emit CooldownEnabledUpdated(_cooldownEnabled);
}

function thisBalance() public view returns (uint) {
    return balanceOf(address(this));
}

function cooldownEnabled() public view returns (bool) {
    return _cooldownEnabled;
}

function timeToBuy(address buyer) public view returns (uint) {
    return block.timestamp - cooldown[buyer].buy;
}

function timeToSell(address buyer) public view returns (uint) {
    return block.timestamp - cooldown[buyer].sell;
}`

I need add in this code into my own kelpie_contract but its a bit messy to me
gitcoinbot commented 3 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 0.1 ETH (182.88 USD @ $1828.77/ETH) attached to it.

gitcoinbot commented 3 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work has been started.

These users each claimed they can complete the work by 265 years, 5 months from now. Please review their action plans below:

1) awas666 has been approved to start work.

I already implemented something similar once in a contract, but for all transfers 2) adi44 has applied to start work _(Funders only: approve worker | reject worker)_.

Basically it needs a temporary lock implementation. I will implement a lock for 20 seconds

Learn more on the Gitcoin Issue Details page.

gitcoinbot commented 3 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work for 0.1 ETH (182.88 USD @ $1828.77/ETH) has been submitted by: