Verified contractPartialMIT
HappiVirtualPairFactory
Address0xa01ddff97577986954b3a246d86ad6f826cab031
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.35
- Same code
1 more contract
Details
- Compiler
- solc 0.8.35+commit.47b9dedd
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,287,420
- Creation transaction
- 0x482ff5021d…6e266e5968
- Libraries
- src/v2/libraries/HappiGraduationPlanLib.sol:HappiGraduationPlanLib0x3f91…89798esrc/v2/libraries/HappiV2LaunchEconomics.sol:HappiV2LaunchEconomics0xd883…315ab4src/v2/libraries/HappiV2GraduationSeedLib.sol:HappiV2GraduationSeedLib0xad98…efeeb0
2 files
- src/v2/HappiVirtualPairFactory.solmain1.94 KB
- src/v2/HappiVirtualPair.sol4.89 KB
src/v2/HappiVirtualPairFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import {HappiVirtualPair, IVirtualPairCurve} from "./HappiVirtualPair.sol";
/// @notice Separate discovery registry. Registration is atomic with a new launch.
contract HappiVirtualPairFactory {
error InvalidPair();
error NotLaunchFactory();
address public immutable launchFactory;
address public immutable wrappedNative;
mapping(address => mapping(address => address)) public getPair;
mapping(address => address) public pairForCurve;
address[] public allPairs;
event PairCreated(address indexed token0, address indexed token1, address pair, uint256 count);
constructor(address launchFactory_, address wrappedNative_) {
if (launchFactory_ == address(0) || wrappedNative_ == address(0)) revert InvalidPair();
launchFactory = launchFactory_;
wrappedNative = wrappedNative_;
}
function allPairsLength() external view returns (uint256) { return allPairs.length; }
function createPair(address curve) external returns (address pair) {
if (msg.sender != launchFactory) revert NotLaunchFactory();
IVirtualPairCurve source = IVirtualPairCurve(curve);
address token = source.token();
address quote = source.pairToken();
if (quote == address(0)) quote = wrappedNative;
if (source.factory() != launchFactory || token == address(0) || token == quote ||
pairForCurve[curve] != address(0) || getPair[token][quote] != address(0)) revert InvalidPair();
HappiVirtualPair created = new HappiVirtualPair{salt: bytes32(uint256(uint160(curve)))}(curve, token, quote);
pair = address(created);
pairForCurve[curve] = pair;
getPair[token][quote] = pair;
getPair[quote][token] = pair;
allPairs.push(pair);
emit PairCreated(created.token0(), created.token1(), pair, allPairs.length);
created.initialize();
}
}
src/v2/HappiVirtualPair.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
interface IVirtualPairCurve {
function token() external view returns (address);
function pairToken() external view returns (address);
function factory() external view returns (address);
function virtualPair() external view returns (address);
function virtualTradeSequence() external view returns (uint256);
function graduated() external view returns (bool);
function getReserves() external view returns (uint256, uint256);
}
/// @notice Indexer representation of a bonding curve, not a funded AMM or LP token.
contract HappiVirtualPair {
enum Status { Active, Closed, Unrepresentable }
error NotCurve();
error NotFactory();
error AlreadyInitialized();
error InvalidSequence();
address public immutable factory;
address public immutable curve;
address public immutable token0;
address public immutable token1;
bool private immutable quoteIsToken0;
uint112 private reserve0;
uint112 private reserve1;
uint32 private blockTimestampLast;
uint256 public lastTradeSequence;
Status public status;
bool private initialized;
event Sync(uint112 reserve0, uint112 reserve1);
/// @notice Removal of displayed virtual reserves, not a transfer of assets.
event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to);
event Swap(address indexed sender, uint256 amount0In, uint256 amount1In,
uint256 amount0Out, uint256 amount1Out, address indexed to);
event MarketStatusChanged(Status status);
event Resynchronized(uint256 previousSequence, uint256 currentSequence);
event TradeRecorded(uint256 indexed sequence);
constructor(address curve_, address token_, address quote_) {
factory = msg.sender;
curve = curve_;
quoteIsToken0 = quote_ < token_;
(token0, token1) = quoteIsToken0 ? (quote_, token_) : (token_, quote_);
}
function initialize() external {
if (msg.sender != factory) revert NotFactory();
if (initialized) revert AlreadyInitialized();
initialized = true;
_readCurve();
}
function getReserves() external view returns (uint112, uint112, uint32) {
return (reserve0, reserve1, blockTimestampLast);
}
/// @dev Only the bound curve can report trades. No transfers or external calls.
function recordSwap(uint256 quoteIn, uint256 quoteOut, uint256 tokenIn, uint256 tokenOut,
address recipient, uint256 quoteReserve, uint256 tokenReserve, uint256 sequence) external {
if (msg.sender != curve) revert NotCurve();
if (sequence <= lastTradeSequence) revert InvalidSequence();
lastTradeSequence = sequence;
_update(quoteReserve, tokenReserve, false);
if (status == Status.Active) {
if (quoteIsToken0) emit Swap(msg.sender, quoteIn, tokenIn, quoteOut, tokenOut, recipient);
else emit Swap(msg.sender, tokenIn, quoteIn, tokenOut, quoteOut, recipient);
}
emit TradeRecorded(sequence);
}
function close() external {
if (msg.sender != curve) revert NotCurve();
_update(0, 0, true);
}
/// @notice Recover current reserves; never fabricate missed historical swaps.
function syncFromCurve() external {
uint256 previous = lastTradeSequence;
_readCurve();
emit Resynchronized(previous, lastTradeSequence);
}
function _readCurve() private {
IVirtualPairCurve source = IVirtualPairCurve(curve);
lastTradeSequence = source.virtualTradeSequence();
bool closed = source.graduated();
(uint256 quote, uint256 tokens) = closed ? (uint256(0), uint256(0)) : source.getReserves();
_update(quote, tokens, closed);
}
function _update(uint256 quote, uint256 tokens, bool closed) private {
// Closure is terminal, including when recovered through syncFromCurve.
bool closing = closed && status != Status.Closed;
uint112 previous0 = reserve0;
uint112 previous1 = reserve1;
closed = closed || status == Status.Closed;
Status next = closed ? Status.Closed :
quote > type(uint112).max || tokens > type(uint112).max ? Status.Unrepresentable : Status.Active;
if (next != status) { status = next; emit MarketStatusChanged(next); }
if (next != Status.Active) { quote = 0; tokens = 0; }
(reserve0, reserve1) = quoteIsToken0 ? (uint112(quote), uint112(tokens)) : (uint112(tokens), uint112(quote));
blockTimestampLast = uint32(block.timestamp);
emit Sync(reserve0, reserve1);
// V2 indexers need the standard removal event as well as zero reserves.
// Use the bound curve even when a third party performs recovery.
if (closing) emit Burn(curve, previous0, previous1, curve);
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {
"src/v2/libraries/HappiGraduationPlanLib.sol": {
"HappiGraduationPlanLib": "0x3F919750ae5F337741EF1a2F910812796b89798e"
},
"src/v2/libraries/HappiV2LaunchEconomics.sol": {
"HappiV2LaunchEconomics": "0xD883FA46945afA7e746EF8eAD0D614e79E315ab4"
},
"src/v2/libraries/HappiV2GraduationSeedLib.sol": {
"HappiV2GraduationSeedLib": "0xAd9841a010D23cd461A8a7Bb4084646b39efeEB0"
}
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@uniswap/v4-core/=lib/v4-core/",
"@uniswap/v4-periphery/=lib/v4-periphery/",
"@uniswap/v4-hooks-public/=lib/v4-hooks-public/",
"v4-core/=lib/v4-core/src/",
"v4-periphery/=lib/v4-periphery/src/",
"v4-hooks-public/=lib/v4-hooks-public/src/",
"permit2/=lib/v4-periphery/lib/permit2/",
"forge-std/=lib/forge-std/src/",
"infinity-core/=lib/infinity-core/",
"infinity-periphery/=lib/infinity-periphery/",
"solmate/=lib/solmate/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.