Description:
Proxy contract enabling upgradeable smart contract patterns. Delegates calls to an implementation contract.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
interface IMonklePairLite { function initialize(address _token0, address _token1) external; }
contract MonkleFactory {
address public immutable pairImplementation;
mapping(address => mapping(address => address)) public getPair;
address[] public allPairs;
event PairCreated(address indexed token0, address indexed token1, address pair, uint index);
constructor(address _pairImplementation) {
require(_pairImplementation != address(0), "pair impl=0");
pairImplementation = _pairImplementation;
}
function allPairsLength() external view returns (uint) { return allPairs.length; }
// matches Router signature; ignores provided bytecode and clones our implementation
function createPairWith(
address tokenA,
address tokenB,
bytes32 salt,
bytes calldata /* pairCreationBytecode */
) external returns (address pair) {
require(tokenA != tokenB, "IDENTICAL");
(address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(getPair[token0][token1] == address(0), "EXISTS");
// EIP-1167 minimal proxy via CREATE2
bytes20 target = bytes20(pairImplementation);
bytes memory code = abi.encodePacked(
hex"3d602d80600a3d3981f3",
hex"363d3d373d3d3d363d73", target,
hex"5af43d82803e903d91602b57fd5bf3"
);
address clone;
assembly { clone := create2(0, add(code, 0x20), mload(code), salt) }
require(clone != address(0), "CREATE2_FAIL");
IMonklePairLite(clone).initialize(token0, token1);
getPair[token0][token1] = clone;
getPair[token1][token0] = clone;
allPairs.push(clone);
emit PairCreated(token0, token1, clone, allPairs.length - 1);
return clone;
}
}
Submitted on: 2025-09-30 10:07:49
Comments
Log in to comment.
No comments yet.