Verified contractExactMIT
LOCOTokenOFT
Address0x47288934f8d3fcdd22bde7d3b68239e48f400c21
- Balance
0 ETH
- Transactions
784
- Compiler
solc 0.8.24
- Same code
Only this contract
Details
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,902,096
- Creation transaction
- 0x19e8082b12…6de4f24c57
16 files
- src/LOCOTokenOFT.solmain7.63 KB
- lib/openzeppelin-contracts/contracts/access/Ownable.sol3.1 KB
- lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol6.54 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol10.8 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/ERC20Burnable.sol1.12 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol684 B
- lib/openzeppelin-contracts/contracts/utils/Context.sol963 B
- src/LOCOToken.sol11.43 KB
- src/LPDividendTracker.sol7.6 KB
- src/interfaces/ILayerZeroEndpointV2.sol1.12 KB
- src/interfaces/IOFT.sol1.04 KB
- src/libraries/IterableMapping.sol1.53 KB
- src/uniswapv2/interfaces/IUniswapV2ERC20.sol1.15 KB
- src/uniswapv2/interfaces/IUniswapV2Pair.sol1.42 KB
- src/uniswapv2/interfaces/IWETH.sol196 B
src/LOCOTokenOFT.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "./LOCOToken.sol";
import "./interfaces/IOFT.sol";
import "./interfaces/ILayerZeroEndpointV2.sol";
contract LOCOTokenOFT is LOCOToken, IOFT, ILayerZeroReceiver {
ILayerZeroEndpointV2 public lzEndpoint;
// LayerZero V2 Peer Mappings (dstEid => peerAddressBytes32)
mapping(uint32 => bytes32) public peers;
// Configurable Bridge Protocol Fee in wei (default 0, set by owner)
uint256 public bridgeProtocolFee;
address public feeTreasury;
event PeerSet(uint32 indexed eid, bytes32 peer);
event BridgeProtocolFeeUpdated(uint256 newFeeWei);
event FeeTreasuryUpdated(address indexed newTreasury);
event LzEndpointUpdated(address indexed newEndpoint);
constructor(
address _initialPair,
uint256 _minDividendThreshold,
address _lzEndpoint,
address _feeTreasury,
uint256 _initialBridgeFeeWei,
uint256 _initialSupply
) LOCOToken(_initialPair, _minDividendThreshold, _initialSupply) {
require(_feeTreasury != address(0), "Invalid fee treasury");
lzEndpoint = ILayerZeroEndpointV2(_lzEndpoint);
feeTreasury = _feeTreasury;
bridgeProtocolFee = _initialBridgeFeeWei;
// Exclude LayerZero endpoint and fee treasury from fees
isExcludedFromFees[_lzEndpoint] = true;
isExcludedFromFees[_feeTreasury] = true;
}
function setPeer(uint32 _eid, bytes32 _peer) external onlyOwner {
peers[_eid] = _peer;
emit PeerSet(_eid, _peer);
}
function setBridgeProtocolFee(uint256 _feeWei) external onlyOwner {
bridgeProtocolFee = _feeWei;
emit BridgeProtocolFeeUpdated(_feeWei);
}
function setFeeTreasury(address _treasury) external onlyOwner {
require(_treasury != address(0), "Invalid fee treasury");
feeTreasury = _treasury;
isExcludedFromFees[_treasury] = true;
emit FeeTreasuryUpdated(_treasury);
}
function setLzEndpoint(address _endpoint) external onlyOwner {
require(_endpoint != address(0), "Invalid LZ endpoint");
lzEndpoint = ILayerZeroEndpointV2(_endpoint);
isExcludedFromFees[_endpoint] = true;
emit LzEndpointUpdated(_endpoint);
}
/**
* @notice LayerZero V2 authorization check for initializing channel / pathway.
* @dev Resolves "Blocked - Not Initializable" / "WAITING FOR ULN CONFIG" on LayerZero Scan.
*/
function allowInitializePath(
Origin calldata _origin
) external view override returns (bool) {
return peers[_origin.srcEid] == _origin.sender;
}
/**
* @notice LayerZero V2 nextNonce check.
*/
function nextNonce(
uint32,
bytes32
) external pure override returns (uint64) {
return 0;
}
/**
* @notice Quotes total cross-chain native fee (LayerZero native fee + bridgeProtocolFee * amountLD / 1e18).
*/
function quoteSend(
SendParam calldata _sendParam,
bool _payInLzToken
) public view override returns (MessagingFee memory fee) {
bytes memory message = abi.encode(_sendParam.to, _sendParam.amountLD);
MessagingParams memory params = MessagingParams({
dstEid: _sendParam.dstEid,
receiver: _sendParam.to,
message: message,
options: _sendParam.extraOptions,
payInLzToken: _payInLzToken
});
MessagingFee memory lzFee = lzEndpoint.quote(params, address(this));
uint256 protocolFee = (_sendParam.amountLD * bridgeProtocolFee) / 1e18;
fee.nativeFee = lzFee.nativeFee + protocolFee;
fee.lzTokenFee = lzFee.lzTokenFee;
}
/**
* @notice Standard IOFT send implementation with integrated bridgeProtocolFee coefficient.
*/
function send(
SendParam calldata _sendParam,
MessagingFee calldata _fee,
address _refundAddress
)
public
payable
override
returns (
MessagingReceipt memory msgReceipt,
OFTReceipt memory oftReceipt
)
{
uint256 protocolFee = (_sendParam.amountLD * bridgeProtocolFee) / 1e18;
require(
msg.value >= _fee.nativeFee,
"LOCOTokenOFT: Insufficient msg.value for total native fee"
);
require(
_fee.nativeFee >= protocolFee,
"LOCOTokenOFT: Fee lower than bridgeProtocolFee"
);
uint256 lzNativeFee = _fee.nativeFee - protocolFee;
// 1. Forward bridgeProtocolFee to feeTreasury if > 0
if (protocolFee > 0) {
(bool success, ) = payable(feeTreasury).call{
value: protocolFee
}("");
require(
success,
"LOCOTokenOFT: Bridge protocol fee transfer failed"
);
}
// 2. Lock or Burn source chain tokens (100% token quantity preservation, 0 DEX tax)
_burn(msg.sender, _sendParam.amountLD);
// 3. Dispatch message to LayerZero Endpoint with net lzNativeFee
bytes memory message = abi.encode(_sendParam.to, _sendParam.amountLD);
MessagingParams memory params = MessagingParams({
dstEid: _sendParam.dstEid,
receiver: peers[_sendParam.dstEid] != bytes32(0)
? peers[_sendParam.dstEid]
: _sendParam.to,
message: message,
options: _sendParam.extraOptions,
payInLzToken: false
});
msgReceipt = lzEndpoint.send{value: lzNativeFee}(
params,
_refundAddress
);
oftReceipt = OFTReceipt({
amountSentLD: _sendParam.amountLD,
amountReceivedLD: _sendParam.amountLD
});
emit OFTSent(
msgReceipt.guid,
_sendParam.dstEid,
msg.sender,
_sendParam.amountLD,
_sendParam.amountLD
);
}
/**
* @notice Receives and mints tokens on destination chain from LayerZero Endpoint (V2 standard).
*/
function lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata _message,
address /*_executor*/,
bytes calldata /*_extraData*/
) external payable override {
require(
msg.sender == address(lzEndpoint),
"LOCOTokenOFT: Only LZ Endpoint can call lzReceive"
);
require(
peers[_origin.srcEid] == _origin.sender,
"LOCOTokenOFT: Only peer can send message"
);
(bytes32 toBytes32, uint256 amountLD) = abi.decode(
_message,
(bytes32, uint256)
);
address toAddress = address(uint160(uint256(toBytes32)));
_mint(toAddress, amountLD);
emit OFTReceived(_guid, _origin.srcEid, toAddress, amountLD);
}
/**
* @notice Backward compatible lzReceive overload
*/
function lzReceive(
uint32 _srcEid,
bytes32 _guid,
bytes calldata _message,
address _toAddress
) external {
require(
msg.sender == address(lzEndpoint),
"LOCOTokenOFT: Only LZ Endpoint can call lzReceive"
);
(bytes32 toBytes32, uint256 amountLD) = abi.decode(
_message,
(bytes32, uint256)
);
address toAddress = _toAddress != address(0)
? _toAddress
: address(uint160(uint256(toBytes32)));
_mint(toAddress, amountLD);
emit OFTReceived(_guid, _srcEid, toAddress, amountLD);
}
}
lib/openzeppelin-contracts/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (interfaces/draft-IERC6093.sol)
pragma solidity >=0.8.4;
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC-721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-721.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC-1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}
lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*/
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* Both values are immutable: they can only be set once during construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/// @inheritdoc IERC20
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
/// @inheritdoc IERC20
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/// @inheritdoc IERC20
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Skips emitting an {Approval} event indicating an allowance update. This is not
* required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation sets the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the `transferFrom` operation can force the flag to
* true using the following override:
*
* ```solidity
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner`'s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance < type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}
lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
lib/openzeppelin-contracts/contracts/token/ERC20/extensions/ERC20Burnable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.7.0) (token/ERC20/extensions/ERC20Burnable.sol)
pragma solidity ^0.8.20;
import {ERC20} from "../ERC20.sol";
/**
* @dev Extension of {ERC20} that allows token holders to destroy both their own
* tokens and those that they have an allowance for, in a way that can be
* recognized off-chain (via event analysis).
*/
abstract contract ERC20Burnable is ERC20 {
/**
* @dev Destroys a `value` amount of tokens from the caller.
*
* See {ERC20-_burn}.
*/
function burn(uint256 value) public virtual {
_burn(_msgSender(), value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, deducting from
* the caller's allowance.
*
* See {ERC20-_burn} and {ERC20-allowance}.
*
* Requirements:
*
* - the caller must have allowance for `account`'s tokens of at least
* `value`.
*/
function burnFrom(address account, uint256 value) public virtual {
_spendAllowance(account, _msgSender(), value);
_burn(account, value);
}
}
lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity >=0.6.2;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
lib/openzeppelin-contracts/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
src/LOCOToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./uniswapv2/interfaces/IUniswapV2Pair.sol";
import "./uniswapv2/interfaces/IWETH.sol";
import "./LPDividendTracker.sol";
abstract contract LOCOToken is ERC20, ERC20Burnable, Ownable {
// Total Tax: 4% (0.5% LP, 0.5% sent to dead address, 3.0% Dividends)
uint256 public constant TOTAL_TAX_FEE = 400; // 4.00% (basis points)
uint256 public constant LP_FEE = 50; // 0.50%
uint256 public constant BURN_FEE = 50; // 0.50%
uint256 public constant DIVIDEND_FEE = 300; // 3.00%
uint256 public constant FEE_DENOMINATOR = 10000;
// Active DEX Liquidity Pair (Uniswap V2 / PancakeSwap V2)
address public uniswapV2Pair;
LPDividendTracker public dividendTracker;
// Address where LP tokens are locked forever (Dead address by default)
address public lockedLpHolder;
address public constant DEAD_ADDRESS =
0x000000000000000000000000000000000000dEaD;
// Exemptions
mapping(address => bool) public isExcludedFromFees;
// Swap threshold (default 500,000 LOCO tokens)
uint256 public swapThreshold;
bool private inSwap;
modifier lockTheSwap() {
inSwap = true;
_;
inSwap = false;
}
event ExcludeFromFees(address indexed account, bool isExcluded);
event SwapThresholdUpdated(uint256 newThreshold);
event LockedLpHolderUpdated(address indexed newHolder);
event UniswapV2PairUpdated(address indexed newPair);
event SwapAndLiquify(
uint256 tokensSwapped,
uint256 ethReceived,
uint256 tokensIntoLiquidity
);
event FeeBurned(uint256 tokensBurned);
event SendDividends(uint256 ethAmount);
constructor(
address _initialPair,
uint256 _minDividendThreshold,
uint256 _initialSupply
) ERC20("locoliquid", "LOCO") Ownable(msg.sender) {
if (_initialSupply > 0) {
_mint(msg.sender, _initialSupply);
}
// Default swap threshold: 500,000 LOCO tokens
swapThreshold = 500_000 * 10 ** 18;
lockedLpHolder = DEAD_ADDRESS;
// Deploy LP Dividend Tracker
dividendTracker = new LPDividendTracker(_minDividendThreshold);
dividendTracker.setTokenAddress(address(this));
dividendTracker.setLockedLpHolder(lockedLpHolder);
// Exclude contract, owner, and dead address from fees & dividends
isExcludedFromFees[owner()] = true;
isExcludedFromFees[address(this)] = true;
isExcludedFromFees[DEAD_ADDRESS] = true;
dividendTracker.excludeFromDividends(address(dividendTracker), true);
dividendTracker.excludeFromDividends(address(this), true);
dividendTracker.excludeFromDividends(owner(), true);
dividendTracker.excludeFromDividends(DEAD_ADDRESS, true);
// Set initial pair if provided
if (_initialPair != address(0)) {
_setUniswapV2PairInternal(_initialPair);
}
// Transfer ownership of dividendTracker to deployer
dividendTracker.transferOwnership(msg.sender);
}
receive() external payable {}
function setSwapThreshold(uint256 _swapThreshold) external onlyOwner {
require(_swapThreshold > 0, "Threshold must be greater than zero");
swapThreshold = _swapThreshold;
emit SwapThresholdUpdated(_swapThreshold);
}
function setLockedLpHolder(address _lockedLpHolder) external onlyOwner {
require(_lockedLpHolder != address(0), "Invalid locked LP address");
lockedLpHolder = _lockedLpHolder;
dividendTracker.setLockedLpHolder(_lockedLpHolder);
emit LockedLpHolderUpdated(_lockedLpHolder);
}
function setExcludeFromFees(
address account,
bool excluded
) external onlyOwner {
isExcludedFromFees[account] = excluded;
emit ExcludeFromFees(account, excluded);
}
/**
* @notice Sets or updates the active DEX Pair (supports dynamic migration without router dependency).
*/
function setUniswapV2Pair(address _newPair) external onlyOwner {
require(_newPair != address(0), "Invalid pair address");
_setUniswapV2PairInternal(_newPair);
}
function _setUniswapV2PairInternal(address _newPair) internal {
uniswapV2Pair = _newPair;
dividendTracker.setUniswapV2Pair(_newPair);
dividendTracker.excludeFromDividends(_newPair, true);
emit UniswapV2PairUpdated(_newPair);
}
/**
* @notice Manual trigger for tax realization (swaps accumulated tax directly with pair, adds LP, sends tokens to the dead address, deposits dividends).
*/
function triggerTaxSwapAddLp() external {
uint256 contractBalance = balanceOf(address(this));
require(contractBalance > 0, "No tax tokens to swap");
require(!inSwap, "Already in swap");
_swapAndLiquify(contractBalance);
}
/**
* @dev Overrides ERC20 `_update` for tax engine & LP balance sync.
*/
function _update(
address sender,
address recipient,
uint256 amount
) internal override {
if (amount == 0) {
super._update(sender, recipient, 0);
return;
}
// Check if tax realization should be executed
uint256 contractTokenBalance = balanceOf(address(this));
bool canSwap = contractTokenBalance >= swapThreshold;
// Two-Stage Tax Model: Only execute swap when not inSwap, and sender is NOT the DEX pair (i.e. not during BUY)
if (
canSwap &&
!inSwap &&
uniswapV2Pair != address(0) &&
sender != uniswapV2Pair &&
sender != owner() &&
recipient != owner()
) {
_swapAndLiquify(contractTokenBalance);
}
bool takeFee = !inSwap;
// Remove fees if sender or recipient is excluded
if (isExcludedFromFees[sender] || isExcludedFromFees[recipient]) {
takeFee = false;
}
// Fees ONLY apply on default LOCO/WETH pair (uniswapV2Pair) Buy and Sell operations
bool isBuy = (uniswapV2Pair != address(0) && sender == uniswapV2Pair);
bool isSell = (uniswapV2Pair != address(0) &&
recipient == uniswapV2Pair);
if (takeFee && (isBuy || isSell)) {
uint256 fees = (amount * TOTAL_TAX_FEE) / FEE_DENOMINATOR;
uint256 transferAmount = amount - fees;
// Transfer tax to token contract address
super._update(sender, address(this), fees);
// Transfer remaining amount to recipient
super._update(sender, recipient, transferAmount);
} else {
super._update(sender, recipient, amount);
}
// Sync LP holder balances in Dividend Tracker
_syncLPHolderBalance(sender);
_syncLPHolderBalance(recipient);
}
/**
* @notice Syncs LP token balance of `account` into `LPDividendTracker`.
*/
function _syncLPHolderBalance(address account) private {
if (
account != address(0) &&
account != address(this) &&
account != uniswapV2Pair &&
account != DEAD_ADDRESS &&
account != owner()
) {
dividendTracker.updateLpBalance(account);
}
}
function _getWethAddress() internal view returns (address) {
address token0 = IUniswapV2Pair(uniswapV2Pair).token0();
address token1 = IUniswapV2Pair(uniswapV2Pair).token1();
return token0 == address(this) ? token1 : token0;
}
function _getAmountOut(
uint256 amountIn,
uint256 reserveIn,
uint256 reserveOut
) internal pure returns (uint256 amountOut) {
require(amountIn > 0, "INSUFFICIENT_INPUT_AMOUNT");
require(reserveIn > 0 && reserveOut > 0, "INSUFFICIENT_LIQUIDITY");
uint256 amountInWithFee = amountIn * 997; // 0.3% Uniswap fee
uint256 numerator = amountInWithFee * reserveOut;
uint256 denominator = (reserveIn * 1000) + amountInWithFee;
amountOut = numerator / denominator;
}
/**
* @notice Directly swaps accumulated tax tokens with the DEX Pair, adds locked LP, sends tokens to the dead address, deposits dividends.
* @dev High-gas-efficiency: Bypasses Uniswap Router entirely.
*/
function _swapAndLiquify(uint256 tokensToSwap) private lockTheSwap {
require(uniswapV2Pair != address(0), "Pair not set");
// Breakdown: LP = 0.5% (50/400), Dead address = 0.5% (50/400), Dividend = 3.0% (300/400)
uint256 lpTokens = (tokensToSwap * LP_FEE) / TOTAL_TAX_FEE;
uint256 burnTokens = (tokensToSwap * BURN_FEE) / TOTAL_TAX_FEE;
uint256 dividendTokens = tokensToSwap - lpTokens - burnTokens;
// 1. Add Liquidity (0.5% portion): Half to ETH, half token
uint256 halfLpTokens = lpTokens / 2;
uint256 otherHalfLpTokens = lpTokens - halfLpTokens;
// Send this portion to the dead address without reducing totalSupply.
if (burnTokens > 0) {
super._update(address(this), DEAD_ADDRESS, burnTokens);
emit FeeBurned(burnTokens);
}
// Total tokens to swap for WETH (halfLpTokens + dividendTokens)
uint256 totalTokensToWeth = halfLpTokens + dividendTokens;
address weth = _getWethAddress();
bool isToken0 = address(this) == IUniswapV2Pair(uniswapV2Pair).token0();
// 1. Read reserves before token transfer
(uint112 reserve0, uint112 reserve1, ) = IUniswapV2Pair(uniswapV2Pair)
.getReserves();
(uint256 reserveIn, uint256 reserveOut) = isToken0
? (reserve0, reserve1)
: (reserve1, reserve0);
uint256 totalWethOut = _getAmountOut(
totalTokensToWeth,
reserveIn,
reserveOut
);
// 2. Transfer LOCO tokens directly to Pair
super._update(address(this), uniswapV2Pair, totalTokensToWeth);
// 3. Direct swap to dividendTracker address (which is NOT token0 or token1)
(uint256 amount0Out, uint256 amount1Out) = isToken0
? (uint256(0), totalWethOut)
: (totalWethOut, uint256(0));
IUniswapV2Pair(uniswapV2Pair).swap(
amount0Out,
amount1Out,
address(dividendTracker),
""
);
// 4. Calculate WETH splits
uint256 wethForLP = (totalWethOut * halfLpTokens) / totalTokensToWeth;
uint256 wethForDividends = totalWethOut - wethForLP;
// 5. Unwrap & distribute dividends via dividendTracker
if (wethForDividends > 0) {
dividendTracker.handleTaxWETH(weth, 0, 0, wethForDividends);
}
// 6. Execute Auto-LP: Transfer wethForLP & otherHalfLpTokens to pair and mint to lockedLpHolder
if (otherHalfLpTokens > 0 && wethForLP > 0) {
dividendTracker.handleTaxWETH(weth, wethForLP, 0, 0);
super._update(address(this), uniswapV2Pair, otherHalfLpTokens);
IUniswapV2Pair(uniswapV2Pair).mint(lockedLpHolder);
emit SwapAndLiquify(halfLpTokens, wethForLP, otherHalfLpTokens);
}
}
}
src/LPDividendTracker.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "@openzeppelin/contracts/access/Ownable.sol";
import "./uniswapv2/interfaces/IUniswapV2Pair.sol";
import "./uniswapv2/interfaces/IWETH.sol";
import "./libraries/IterableMapping.sol";
contract LPDividendTracker is Ownable {
using IterableMapping for IterableMapping.Map;
IterableMapping.Map private tokenHoldersMap;
address public tokenAddress;
address public uniswapV2Pair;
address public lockedLpHolder;
mapping(address => bool) public isExcludedFromDividends;
// mapping(address => uint256) public totalClaimedDividends;
uint256 public minLpBalanceForDividends;
uint256 public minDistributionThreshold;
uint256 public totalDividendsDistributed;
event ExcludeFromDividends(address indexed account, bool isExcluded);
event Claimed(address indexed account, uint256 amount);
event DividendsDistributed(uint256 totalAmount, uint256 countProcessed);
event SetBalance(address indexed account, uint256 balance);
event UniswapV2PairUpdated(address indexed newPair);
modifier onlyTokenOrOwner() {
require(
msg.sender == owner() || msg.sender == tokenAddress,
"LPDividendTracker: Caller is not token or owner"
);
_;
}
constructor(uint256 _minDistributionThreshold) Ownable(msg.sender) {
minLpBalanceForDividends = 100 wei;
minDistributionThreshold = _minDistributionThreshold;
}
function setTokenAddress(address _tokenAddress) external onlyOwner {
require(_tokenAddress != address(0), "Invalid token address");
tokenAddress = _tokenAddress;
}
function setUniswapV2Pair(
address _uniswapV2Pair
) external onlyTokenOrOwner {
require(_uniswapV2Pair != address(0), "Invalid UniswapV2 pair");
uniswapV2Pair = _uniswapV2Pair;
isExcludedFromDividends[_uniswapV2Pair] = true;
tokenHoldersMap.remove(_uniswapV2Pair);
emit UniswapV2PairUpdated(_uniswapV2Pair);
}
function setLockedLpHolder(
address _lockedLpHolder
) external onlyTokenOrOwner {
require(_lockedLpHolder != address(0), "Invalid locked LP holder");
lockedLpHolder = _lockedLpHolder;
isExcludedFromDividends[_lockedLpHolder] = true;
tokenHoldersMap.remove(_lockedLpHolder);
}
function setMinLpBalanceForDividends(
uint256 _minBalance
) external onlyOwner {
minLpBalanceForDividends = _minBalance;
}
function setMinDistributionThreshold(
uint256 _threshold
) external onlyOwner {
minDistributionThreshold = _threshold;
}
function excludeFromDividends(
address account,
bool excluded
) external onlyTokenOrOwner {
isExcludedFromDividends[account] = excluded;
if (excluded) {
tokenHoldersMap.remove(account);
} else {
uint256 balance = getLPBalance(account);
if (balance >= minLpBalanceForDividends) {
tokenHoldersMap.set(account, balance);
}
}
emit ExcludeFromDividends(account, excluded);
}
function updateLpBalance(address account) external onlyTokenOrOwner {
if (uniswapV2Pair == address(0)) {
return;
}
if (
isExcludedFromDividends[account] ||
account == lockedLpHolder ||
account == uniswapV2Pair
) {
tokenHoldersMap.remove(account);
return;
}
uint256 currentBalance = getLPBalance(account);
if (currentBalance >= minLpBalanceForDividends) {
tokenHoldersMap.set(account, currentBalance);
} else {
tokenHoldersMap.remove(account);
}
emit SetBalance(account, currentBalance);
}
function getLPBalance(address account) public view returns (uint256) {
if (uniswapV2Pair == address(0) || account == address(0)) {
return 0;
}
return IUniswapV2Pair(uniswapV2Pair).balanceOf(account);
}
function getNumberOfTokenHolders() external view returns (uint256) {
return tokenHoldersMap.size();
}
function getAccountAtIndex(
uint256 index
) external view returns (address, uint256) {
address key = tokenHoldersMap.getKeyAtIndex(index);
return (key, tokenHoldersMap.get(key));
}
function setBalance(
address account,
uint256 newBalance
) external onlyTokenOrOwner {
if (isExcludedFromDividends[account]) {
return;
}
if (newBalance >= minLpBalanceForDividends) {
tokenHoldersMap.set(account, newBalance);
} else {
tokenHoldersMap.remove(account);
}
emit SetBalance(account, newBalance);
}
function getTotalEligibleLPSupply() public view returns (uint256 total) {
uint256 size = tokenHoldersMap.size();
for (uint256 i = 0; i < size; i++) {
address key = tokenHoldersMap.getKeyAtIndex(i);
total += tokenHoldersMap.get(key);
}
}
/**
* @notice Handles tax realization WETH distribution for auto-LP, buyback & burn, and dividends.
*/
function handleTaxWETH(
address _weth,
uint256 _wethForLp,
uint256 _wethForBurn,
uint256 _wethForDividends
) external onlyTokenOrOwner {
if (_wethForLp > 0) {
IWETH(_weth).transfer(uniswapV2Pair, _wethForLp);
}
if (_wethForBurn > 0) {
IWETH(_weth).transfer(uniswapV2Pair, _wethForBurn);
}
if (_wethForDividends > 0) {
IWETH(_weth).withdraw(_wethForDividends);
distributeDividends();
}
}
/**
* @notice Distributes accumulated native currency (BNB/ETH) to all eligible LP holders in a single transaction.
* @return processed Number of accounts processed.
*/
function distributeDividends() public returns (uint256 processed) {
if (address(this).balance < minDistributionThreshold) {
return 0;
}
uint256 numberOfHolders = tokenHoldersMap.size();
if (numberOfHolders == 0) {
return 0;
}
uint256 balanceToDistribute = address(this).balance;
if (balanceToDistribute == 0) {
return 0;
}
uint256 totalEligibleSupply = getTotalEligibleLPSupply();
if (totalEligibleSupply == 0) {
return 0;
}
for (uint256 i = 0; i < numberOfHolders; i++) {
address holder = tokenHoldersMap.getKeyAtIndex(i);
uint256 holderBalance = tokenHoldersMap.get(holder);
if (
holderBalance >= minLpBalanceForDividends &&
!isExcludedFromDividends[holder]
) {
uint256 amount = (balanceToDistribute * holderBalance) /
totalEligibleSupply;
if (amount > 0 && address(this).balance >= amount) {
(bool success, ) = payable(holder).call{value: amount}("");
if (success) {
// totalClaimedDividends[holder] += amount;
emit Claimed(holder, amount);
processed++;
}
}
}
}
totalDividendsDistributed += balanceToDistribute;
emit DividendsDistributed(balanceToDistribute, processed);
return processed;
}
receive() external payable {}
}
src/interfaces/ILayerZeroEndpointV2.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
struct MessagingParams {
uint32 dstEid;
bytes32 receiver;
bytes message;
bytes options;
bool payInLzToken;
}
struct MessagingFee {
uint256 nativeFee;
uint256 lzTokenFee;
}
struct MessagingReceipt {
bytes32 guid;
uint64 nonce;
MessagingFee fee;
}
struct Origin {
uint32 srcEid;
bytes32 sender;
uint64 nonce;
}
interface ILayerZeroEndpointV2 {
function quote(MessagingParams calldata _params, address _sender) external view returns (MessagingFee memory fee);
function send(MessagingParams calldata _params, address _refundAddress) external payable returns (MessagingReceipt memory receipt);
}
interface ILayerZeroReceiver {
function allowInitializePath(Origin calldata _origin) external view returns (bool);
function nextNonce(uint32 _srcEid, bytes32 _sender) external view returns (uint64);
function lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata _message,
address _executor,
bytes calldata _extraData
) external payable;
}
src/interfaces/IOFT.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "./ILayerZeroEndpointV2.sol";
struct SendParam {
uint32 dstEid;
bytes32 to;
uint256 amountLD;
uint256 minAmountLD;
bytes extraOptions;
bytes composeMsg;
bytes oftCmd;
}
struct OFTReceipt {
uint256 amountSentLD;
uint256 amountReceivedLD;
}
interface IOFT {
event OFTSent(
bytes32 indexed guid,
uint32 dstEid,
address indexed fromAddress,
uint256 amountSentLD,
uint256 amountReceivedLD
);
event OFTReceived(
bytes32 indexed guid,
uint32 srcEid,
address indexed toAddress,
uint256 amountReceivedLD
);
function quoteSend(SendParam calldata _sendParam, bool _payInLzToken) external view returns (MessagingFee memory fee);
function send(
SendParam calldata _sendParam,
MessagingFee calldata _fee,
address _refundAddress
) external payable returns (MessagingReceipt memory msgReceipt, OFTReceipt memory oftReceipt);
}
src/libraries/IterableMapping.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
library IterableMapping {
struct Map {
address[] keys;
mapping(address => uint256) values;
mapping(address => int256) indexOf;
mapping(address => bool) inserted;
}
function get(Map storage map, address key) internal view returns (uint256) {
return map.values[key];
}
function getKeyAtIndex(Map storage map, uint256 index) internal view returns (address) {
return map.keys[index];
}
function size(Map storage map) internal view returns (uint256) {
return map.keys.length;
}
function set(Map storage map, address key, uint256 val) internal {
if (map.inserted[key]) {
map.values[key] = val;
} else {
map.inserted[key] = true;
map.values[key] = val;
map.indexOf[key] = int256(map.keys.length);
map.keys.push(key);
}
}
function remove(Map storage map, address key) internal {
if (!map.inserted[key]) {
return;
}
delete map.inserted[key];
delete map.values[key];
int256 index = map.indexOf[key];
uint256 uindex = uint256(index);
uint256 lastIndex = map.keys.length - 1;
if (uindex != lastIndex) {
address lastKey = map.keys[lastIndex];
map.keys[uindex] = lastKey;
map.indexOf[lastKey] = index;
}
map.keys.pop();
delete map.indexOf[key];
}
}
src/uniswapv2/interfaces/IUniswapV2ERC20.sol
pragma solidity ^0.8.24;
interface IUniswapV2ERC20 {
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);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external view returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
}
src/uniswapv2/interfaces/IUniswapV2Pair.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import './IUniswapV2ERC20.sol';
interface IUniswapV2Pair is IUniswapV2ERC20 {
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external view returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
src/uniswapv2/interfaces/IWETH.sol
pragma solidity ^0.8.24;
interface IWETH {
function deposit() external payable;
function transfer(address to, uint value) external returns (bool);
function withdraw(uint) external;
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"forge-std/=lib/forge-std/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.