// SPDX-License-Identifier: MIT pragma solidity ^0.8.22; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {OFT} from "@layerzerolabs/oft-evm/contracts/OFT.sol"; contract SSG is OFT { uint256 public constant MAX_SUPPLY = 20_000_000 * 10 ** 18; error MaxSupplyExceeded(); constructor( string memory _name, string memory _symbol, address _lzEndpoint, address _delegate ) OFT(_name, _symbol, _lzEndpoint, _delegate) Ownable(_delegate) {} /** * @dev Mints new tokens to the specified address * @param _to The address to mint tokens to * @param _amount The amount of tokens to mint */ function mint(address _to, uint256 _amount) external onlyOwner { if (totalSupply() + _amount > MAX_SUPPLY) { revert MaxSupplyExceeded(); } _mint(_to, _amount); } /** * @dev Override _credit method to enforce max supply limit during cross-chain transfers */ function _credit( address _to, uint256 _amountLD, uint32 _srcEid ) internal virtual override returns (uint256 amountReceivedLD) { // Check if minting would exceed max supply if (totalSupply() + _amountLD > MAX_SUPPLY) { revert MaxSupplyExceeded(); } return super._credit(_to, _amountLD, _srcEid); } /** * @dev Override _update to enforce max supply limit for all minting operations * This is used by both _mint and cross-chain transfers */ function _update( address from, address to, uint256 amount ) internal virtual override { if (from == address(0) && totalSupply() + amount > MAX_SUPPLY) { revert MaxSupplyExceeded(); } super._update(from, to, amount); } }