Monkle LP (MLP)

Description:

Smart contract deployed on Ethereum.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;

interface IERC20 { function balanceOf(address) external view returns (uint); }

contract MonklePair {
    address public token0;
    address public token1;

    // Minimal LP ERC20
    string public constant name = "Monkle LP";
    string public constant symbol = "MLP";
    uint8  public constant decimals = 18;
    uint   public totalSupply;
    mapping(address => uint) public balanceOf;
    event Transfer(address indexed from, address indexed to, uint value);

    uint112 private reserve0;
    uint112 private reserve1;
    event Sync(uint112 r0, uint112 r1);

    uint private constant MIN_LIQUIDITY = 1000;

    function initialize(address _token0, address _token1) external {
        require(token0 == address(0) && token1 == address(0), "inited");
        require(_token0 != _token1 && _token0 != address(0) && _token1 != address(0), "bad tokens");
        (token0, token1) = _token0 < _token1 ? (_token0, _token1) : (_token1, _token0);
    }

    function _mint(address to, uint amount) private {
        totalSupply += amount;
        balanceOf[to] += amount;
        emit Transfer(address(0), to, amount);
    }

    function _update(uint b0, uint b1) private {
        reserve0 = uint112(b0);
        reserve1 = uint112(b1);
        emit Sync(reserve0, reserve1);
    }

    function _sqrt(uint y) private 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; }
    }

    function mint(address to) external returns (uint liquidity) {
        uint b0 = IERC20(token0).balanceOf(address(this));
        uint b1 = IERC20(token1).balanceOf(address(this));
        uint a0 = b0 - reserve0;
        uint a1 = b1 - reserve1;
        require(a0 > 0 && a1 > 0, "no deposits");

        if (totalSupply == 0) {
            uint rootK = _sqrt(a0 * a1);
            require(rootK > MIN_LIQUIDITY, "liq low");
            liquidity = rootK - MIN_LIQUIDITY;
            _mint(address(0), MIN_LIQUIDITY);
        } else {
            uint l0 = (a0 * totalSupply) / reserve0;
            uint l1 = (a1 * totalSupply) / reserve1;
            liquidity = l0 < l1 ? l0 : l1;
        }
        require(liquidity > 0, "liquidity=0");
        _mint(to, liquidity);
        _update(b0, b1);
    }

    function getReserves() external view returns (uint112, uint112) { return (reserve0, reserve1); }
}

Tags:
addr:0xc8b79e1869d89565d08ddb0a5a92f519742d3ada|verified:true|block:23471723|tx:0x24eaa682a39593122ece307463b0da6f280dda194c41295eb2144343f1d256bf|first_check:1759220910

Submitted on: 2025-09-30 10:28:30

Comments

Log in to comment.

No comments yet.