1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| function ShortStart(address coin,address addr,uint terrace)payable public { address bnbOrUsdt=mkt.getPair(coin); require(terraces[terrace]!=address(0) && tokenPrice[addr][coin] > 0); require(coin != address(0)); require(bnbOrUsdt == _WBNB || bnbOrUsdt==_USDT); require(!getNewTokenPrice(addr,coin,bnbOrUsdt) && block.timestamp > tokenPriceTime[addr][coin]); uint bnb=msg.value; uint tos=getToken2Price(coin,bnbOrUsdt,mkt.balanceOf(coin))/10; require(Short[addr][coin].bnb+bnb <= tos); Short[addr][coin].token=bnbOrUsdt; Short[addr][coin].coin=coin; Short[addr][coin].bnb+=bnb*98/100; tokenPrice[addr][coin]=0; uint newTokenValue=getTokenPrice(coin,bnbOrUsdt,bnb*98/100); Short[addr][coin].tokenPrice+=newTokenValue; Short[addr][coin].time=block.timestamp; address[] memory add=mySells[addr].coin; bool isCoin; for(uint i=0;i<add.length;i++){ if(add[i]==coin){ isCoin=true; } } if(!isCoin){ mySells[addr].mnu++; mySells[addr].coin.push(coin); } sum+=bnb; payable(mkt).transfer(bnb*97/100); if(bnbOrUsdt ==_USDT){ uint usdts=IERC20(_USDT).balanceOf(address(mkt)); mkt.buy(_WBNB,_USDT,bnb*97/100); if(IERC20(_USDT).balanceOf(address(mkt))>usdts){ uint ut=IERC20(_USDT).balanceOf(address(mkt))-usdts; mkt.buy(_USDT,coin,ut); } }else{ mkt.buy(bnbOrUsdt,coin,bnb*97/100); } payable (owner()).transfer(bnb*2/100); payable (terraces[terrace]).transfer(bnb/100); } //通过getToken2Price()和getTokenPrice()函数获得对应代币的价格,后面细看
|