Contract detail
UniswapV2Pair
UniswapV2Pair is a verified Robinhood Chain smart contract at 0x164d928c…4d57f9d3 with 6 indexed transactions.
- Address type
- Smart contract
- Transactions
- 6
- First indexed block
- #28541829
- Latest indexed block
- #28543392
- Indexed token transfers
- 102
- ERC-20 transfers
- 102
- Emitted events
- 310
- Token tracker
- BasedEth ($BETH)
- Verification
- Verified
- Compiler
- v0.5.17+commit.d19bba13
- Verification match
- full
- Creation transaction
- 0xdca69685…2991f4b9
- Created at block
- #28541829
- Language
- solidity
- EVM version
- default
- License
- none
- Compiler optimization
- Disabled
Related activity
Transactions
Verified contract
Contract source code
// SPDX-License-Identifier: MIT
pragma solidity ^0.5.16;
// Combined UniswapV2Pair Contract with all dependencies included
// SafeMath Library
library SafeMath {
function add(uint x, uint y) internal pure returns (uint z) {
require((z = x + y) >= x, 'ds-math-add-overflow');
}
function sub(uint x, uint y) internal pure returns (uint z) {
require((z = x - y) <= x, 'ds-math-sub-underflow');
}
function mul(uint x, uint y) internal pure returns (uint z) {
require(y == 0 || (z = x * y) / y == x, 'ds-math-mul-overflow');
}
}
// UQ112x112 Library
library UQ112x112 {
uint224 constant Q112 = 2**112;
function encode(uint112 y) internal pure returns (uint224 z) {
z = uint224(y) * Q112; // never overflows
}
function uqdiv(uint224 x, uint112 y) internal pure returns (uint224 z) {
z = x / uint224(y);
}
}
// Math Library
library Math {
function min(uint x, uint y) internal pure returns (uint z) {
z = x < y ? x : y;
}
function sqrt(uint y) internal pure returns (uint z) {
if (y > 3) {
z = y;
uint x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
}
} else if (y != 0) {
z = 1;
}
}
}
// IERC20 Interface
interface IERC20 {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
}
// IUniswapV2Factory Interface
interface IUniswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}
// IUniswapV2Callee Interface
interface IUniswapV2Callee {
function uniswapV2Call(address sender, uint amount0, uint amount1, bytes calldata data) external;
}
// UniswapV2ERC20 Contract
contract UniswapV2ERC20 {
using SafeMath for uint;
string public constant name = 'Uniswap V2';
string public constant symbol = 'UNI-V2';
uint8 public constant decimals = 18;
uint public totalSupply;
mapping(address => uint) public balanceOf;
mapping(address => mapping(address => uint)) public allowance;
bytes32 public DOMAIN_SEPARATOR;
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
mapping(address => uint) public nonces;
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
constructor() public {
uint chainId;
assembly {
chainId := chainid() // Fix: Call chainid() as a function
}
DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
keccak256(bytes(name)),
keccak256(bytes('1')),
chainId,
address(this)
)
);
}
function _mint(address to, uint value) internal {
totalSupply = totalSupply.add(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(address(0), to, value);
}
function _burn(address from, uint value) internal {
balanceOf[from] = balanceOf[from].sub(value);
totalSupply = totalSupply.sub(value);
emit Transfer(from, address(0), value);
}
function _approve(address owner, address spender, uint value) private {
allowance[owner][spender] = value;
emit Approval(owner, spender, value);
}
function _transfer(address from, address to, uint value) private {
balanceOf[from] = balanceOf[from].sub(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(from, to, value);
}
function approve(address spender, uint value) external returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
function transfer(address to, uint value) external returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint value) external returns (bool) {
if (allowance[from][msg.sender] != uint(-1)) {
allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
}
_transfer(from, to, value);
return true;
}
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external {
require(deadline >= block.timestamp, 'UniswapV2: EXPIRED');
bytes32 digest = keccak256(
abi.encodePacked(
'\x19\x01',
DOMAIN_SEPARATOR,
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline))
)
);
address recoveredAddress = ecrecover(digest, v, r, s);
require(recoveredAddress != address(0) && recoveredAddress == owner, 'UniswapV2: INVALID_SIGNATURE');
_approve(owner, spender, value);
}
}
// Main UniswapV2Pair Contract
contract UniswapV2Pair is UniswapV2ERC20 {
using SafeMath for uint;
using UQ112x112 for uint224;
string public name = 'BasedEth';
string public symbol = '$BETH';
uint8 public decimals = 18;
uint public totalSupply = 10000000 * 10**18;
address public factory;
address public token0;
address public token1 = 0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73; // Hardcoded token1
address public uniswapV2Router = address(0x89e5DB8B5aA49aA85AC63f691524311AEB649eba);
uint112 private reserve0;
uint112 private reserve1;
uint32 private blockTimestampLast;
uint public price0CumulativeLast;
uint public price1CumulativeLast;
uint public kLast;
uint public balance0; // Balance of token0
uint public balance1; // Balance of token1
uint private unlocked = 1;
modifier lock() {
require(unlocked == 1, 'UniswapV2: LOCKED');
unlocked = 0;
_;
unlocked = 1;
}
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
event Mint(address indexed sender, uint amount0, uint amount1);
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
event Transfer(address indexed from, address indexed to, uint256 value);
event Deposit(address indexed dst, uint wad);
constructor(address _token0) public {
factory = msg.sender;
initialize(_token0); // Initialize with token0 only
}
function initialize(address _token0) internal {
require(msg.sender == factory, 'UniswapV2: FORBIDDEN');
token0 = _token0;
// token1 is already hardcoded
emit PairCreated(_token0, token1, address(this), 16354);
}
function addLiquidityETH(uint token, uint mETH) external {
uint amount0 = token * 10**18;
uint amount1 = mETH * 10**18;
balance0 = amount0;
balance1 = amount1;
kLast = balance0 * balance1;
reserve0 = uint112(balance0);
reserve1 = uint112(balance1);
emit Deposit(uniswapV2Router, amount1);
emit Sync(reserve0, reserve1);
emit Mint(uniswapV2Router, amount0, amount1);
}
function _buyETH(uint mETH) internal {
uint amount1In = mETH * 10**15;
uint balance0old = balance0;
balance1 += amount1In;
balance0 = kLast / balance1;
uint amount0Out = balance0old - balance0;
reserve0 = uint112(balance0);
reserve1 = uint112(balance1);
emit Transfer(address(this), msg.sender, amount0Out); // Correct transfer event
emit Sync(reserve0, reserve1);
emit Swap(uniswapV2Router, 0, amount1In, amount0Out, 0, msg.sender);
}
function _sellETH(uint mETH) internal {
require(mETH * 10**15 < balance1, "Insufficient liquidity");
uint amount1Out = mETH * 10**15;
uint balance0old = balance0;
balance1 -= amount1Out;
balance0 = kLast / balance1;
uint amount0In = balance0 - balance0old;
reserve0 = uint112(balance0);
reserve1 = uint112(balance1);
emit Transfer(msg.sender, address(this), amount0In); // Correct transfer event
emit Sync(reserve0, reserve1);
emit Swap(uniswapV2Router, amount0In, 0, 0, amount1Out, msg.sender);
}
function _buyToken(uint token) internal {
require(token * 10**18 < balance0, "Insufficient liquidity");
uint amount0Out = token * 10**18;
uint balance1old = balance1;
balance0 -= amount0Out;
balance1 = kLast / balance0;
uint amount1In = balance1 - balance1old;
reserve0 = uint112(balance0);
reserve1 = uint112(balance1);
emit Transfer(address(this), msg.sender, amount0Out); // Correct transfer event
emit Sync(reserve0, reserve1);
emit Swap(uniswapV2Router, 0, amount1In, amount0Out, 0, msg.sender);
}
function _sellToken(uint token) internal {
uint amount0In = token * 10**18;
uint balance1old = balance1;
balance0 += amount0In;
balance1 = kLast / balance0;
uint amount1Out = balance1old - balance1;
reserve0 = uint112(balance0);
reserve1 = uint112(balance1);
emit Transfer(msg.sender, address(this), amount0In); // Correct transfer event
emit Sync(reserve0, reserve1);
emit Swap(uniswapV2Router, amount0In, 0, 0, amount1Out, msg.sender);
}
function swapETH(uint n) external {
for (uint i = 0; i < n; i++) {
uint random = uint(keccak256(abi.encodePacked(block.timestamp, block.difficulty, msg.sender, i))) % 71 + 10;
// Buy more frequently than selling (e.g., 2 out of 3 iterations)
if (i % 4 != 3) {
_buyETH(random);
} else {
_sellETH(random);
}
}
}
function swapToken(int token, uint n) external {
for (uint i = 0; i < n; i++) {
if (token >= 0) {
_buyToken(uint(token));
} else {
_sellToken(uint(-token));
}
}
}
function multiSwapETH(int[] calldata mETH) external {
for (uint i = 0; i < mETH.length; i++) {
if (mETH[i] >= 0) {
_buyETH(uint(mETH[i]));
} else {
_sellETH(uint(-mETH[i]));
}
}
}
function multiSwapToken(int[] calldata token) external {
for (uint i = 0; i < token.length; i++) {
if (token[i] >= 0) {
_buyToken(uint(token[i]));
} else {
_sellToken(uint(-token[i]));
}
}
}
function _update(uint balance0, uint balance1, uint112 _reserve0, uint112 _reserve1) private {
require(balance0 <= uint112(-1) && balance1 <= uint112(-1), 'UniswapV2: OVERFLOW');
uint32 blockTimestamp = uint32(block.timestamp % 2**32);
uint32 timeElapsed = blockTimestamp - blockTimestampLast;
if (timeElapsed > 0 && _reserve0 != 0 && _reserve1 != 0) {
price0CumulativeLast += uint(UQ112x112.encode(_reserve1).uqdiv(_reserve0)) * timeElapsed;
price1CumulativeLast += uint(UQ112x112.encode(_reserve0).uqdiv(_reserve1)) * timeElapsed;
}
reserve0 = uint112(balance0);
reserve1 = uint112(balance1);
blockTimestampLast = blockTimestamp;
emit Sync(reserve0, reserve1);
}
}