Verified contractPartialMIT
PrintrTelecoin
Address0x4a1fe7b29424768fa48113c6e46dcda34a4cd0d7
- Balance
0 ETH
- Transactions
30
- Compiler
solc 0.8.27
- Same code
34 more contracts
Details
- Compiler
- solc 0.8.27+commit.40a35a09
- Language
- solidity
- Optimization
- Yes, 2,000 runs
- EVM version
- prague
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,771,200
- Creation transaction
- 0x8d6fbcacd2…1175cc3fdf
- Main copy (most transactions)
- 0xa8dfbebe…61b77777
24 files
- src/telecoin/PrintrMainTelecoin.solmain2.27 KB
- lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol6.53 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol683 B
- lib/openzeppelin-contracts/contracts/utils/Strings.sol3.1 KB
- lib/openzeppelin-contracts/contracts/utils/math/Math.sol15.12 KB
- lib/openzeppelin-contracts/contracts/utils/math/SignedMath.sol1.26 KB
- src/interfaces/ITreasury.sol3.19 KB
- src/interfaces/layerzero/ILayerZeroEndpointV2.sol4.8 KB
- src/interfaces/layerzero/IOFT.sol4.24 KB
- src/interfaces/printr/IPrintrStorage.sol10.26 KB
- src/interfaces/printr/IPrintrTeleport.sol14.08 KB
- src/interfaces/telecoin/IERC20Permit.sol3.79 KB
- src/interfaces/telecoin/IERC20Witness.sol7.27 KB
- src/interfaces/telecoin/IPrinted.sol2.77 KB
- src/interfaces/telecoin/IPrintrMainTelecoin.sol430 B
- src/interfaces/telecoin/ITelecoin.sol4.98 KB
- src/interfaces/telecoin/ITeleporting.sol915 B
- src/telecoin/ERC20.sol10.59 KB
- src/telecoin/ERC20Witness.sol14.21 KB
- src/telecoin/OftStandard.sol9.69 KB
- src/telecoin/Printed.sol5.6 KB
- src/telecoin/Telecoin.sol7.62 KB
- src/telecoin/Teleporting.sol1.95 KB
src/telecoin/PrintrMainTelecoin.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import { IPrinted } from "../interfaces/telecoin/IPrinted.sol";
import { IPrintrMainTelecoin } from "../interfaces/telecoin/IPrintrMainTelecoin.sol";
import { ERC20 } from "./ERC20.sol";
import { Printed } from "./Printed.sol";
import { Telecoin } from "./Telecoin.sol";
/**
* @title PrintrMainTelecoin
* @notice Implementation of a Main Telecoin with teleport interface and interchain functionality
* @dev Extends Telecoin to provide cross-chain functionality via LayerZero
* @dev Bridging is only possible with lock/unlock/transferFrom, there are no mint/burn mechanisms
*/
contract PrintrTelecoin is IPrintrMainTelecoin, Printed, Telecoin {
/**
* @notice Initializes the token with its basic parameters
* @param params The deployment parameters for the telecoin
* @param treasury Address to receive the initial token supply
* @param initialSupply The initial supply to mint
*/
constructor(
TelecoinDeployParams memory params,
address treasury,
uint256 initialSupply
) Printed(params.printr, treasury, initialSupply, IPrinted.TeleportType.Main) Telecoin(params) { }
/**
* @notice Internal function to handle token transfers with additional restrictions
* @dev Override of ERC20._update that includes Printed contract restrictions.
* First checks if the transfer violates bonding curve completion rules,
* then performs the actual balance update. This ensures tokens cannot be
* added to liquidity pools before the bonding curve is completed.
* @param from The address tokens are being transferred from (address(0) for minting)
* @param to The address tokens are being transferred to (address(0) for burning)
* @param amount The amount of tokens being transferred
* @custom:throws CurveIsNotComplete if attempting to add tokens to restricted pool before completion
*/
function _update(
address from,
address to,
uint256 amount
) internal override(Printed, ERC20) {
// Check Liquidity position opening restrictions
Printed._update(from, to, amount);
// Update balances
ERC20._update(from, to, amount);
}
}
lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 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 ERC721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
* 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 ERC1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 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/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
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/IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 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/Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
* representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
}
lib/openzeppelin-contracts/contracts/utils/math/Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
return a / b;
}
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}
lib/openzeppelin-contracts/contracts/utils/math/SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}
src/interfaces/ITreasury.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
/**
* @title ITreasury
* @notice Interface for managing protocol fee collection and token withdrawals
* @dev Handles LP fee collection and controlled withdrawals of tokens/native currency
*/
interface ITreasury {
/**
* @notice Thrown when an unauthorized address attempts to access treasury functions
*/
error WrongAccess();
/**
* @notice Thrown when a withdrawal of native currency fails
*/
error FailedWithdrawal();
/**
* @notice Thrown when a zero address is provided where a valid address is required
*/
error ZeroAddress();
/**
* @notice Emitted when fees are collected from a liquidity position
* @param token0 Address of the first token in the pair
* @param token1 Address of the second token in the pair
* @param recipient Address receiving the collected fees
* @param amount0 Amount of token0 collected
* @param amount1 Amount of token1 collected
* @param lockId ID of the locked liquidity position
*/
event CollectedLiquidityFees(
address indexed token0,
address indexed token1,
address indexed recipient,
uint256 amount0,
uint256 amount1,
uint256 lockId
);
/**
* @notice Collects accumulated fees from a locked liquidity position by delegating to the liquidity module
* @dev Only callable by authorized addresses. Delegates to the appropriate liquidity module
* which handles locker-specific logic (GoPlus, generic, etc.) and token ordering.
* @param liquidityModule Address of the liquidity module that manages this position's DEX
* @param lockId ID of the locked liquidity position
* @param token Address of the first token in the pair
* @param basePair Address of the second token in the pair (base currency)
* @param recipient Address to receive the collected fees
* @custom:throws WrongAccess if caller is not authorized
*/
function collectLiquidityFees(
address liquidityModule,
uint256 lockId,
address token,
address basePair,
address recipient
) external;
/**
* @notice Withdraws tokens or native currency from the treasury
* @dev Only callable by authorized addresses
* @param token Address of token to withdraw (address(0) for native currency)
* @param recipient Address to receive the withdrawal
* @param amount Amount to withdraw
* @custom:throws WrongAccess if caller is not authorized
* @custom:throws FailedWithdrawal if native currency transfer fails
*/
function withdraw(
address token,
address recipient,
uint256 amount
) external;
/**
* @notice Handles receipt of ERC721 tokens (LP position NFTs)
* @dev Required for compatibility with ERC721 token transfers
* @return bytes4 Function selector to indicate successful receipt
*/
function onERC721Received(
address, /* operator */
address, /* from */
uint256, /* tokenId */
bytes calldata /* data */
) external pure returns (bytes4);
}
src/interfaces/layerzero/ILayerZeroEndpointV2.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
/**
* @title ILayerZeroEndpointV2
* @notice Interface for LayerZero V2 endpoint contract
* @dev Defines the core messaging functions for cross-chain communication
*/
interface ILayerZeroEndpointV2 {
/**
* @notice Struct containing messaging fee information
* @param nativeFee Native fee amount to send
* @param lzTokenFee LayerZero token fee amount
*/
struct MessagingFee {
uint256 nativeFee;
uint256 lzTokenFee;
}
/**
* @notice Struct containing messaging parameters
* @param dstEid Destination endpoint ID
* @param receiver Receiver address on destination chain (as bytes32)
* @param message Message payload to send
* @param options Execution options for the message
* @param payInLzToken Whether to pay fees in LZ token
*/
struct MessagingParams {
uint32 dstEid;
bytes32 receiver;
bytes message;
bytes options;
bool payInLzToken;
}
/**
* @notice Struct containing messaging receipt information
* @param guid Globally unique identifier for the message
* @param nonce Message nonce
* @param fee Messaging fee paid
*/
struct MessagingReceipt {
bytes32 guid;
uint64 nonce;
MessagingFee fee;
}
/**
* @notice Send a message to another chain
* @param params Messaging parameters
* @param refundAddress Address to refund excess fees
* @return receipt Message receipt containing guid and fee info
*/
function send(
MessagingParams calldata params,
address refundAddress
) external payable returns (MessagingReceipt memory receipt);
/**
* @notice Quote the fee for sending a message
* @param params Messaging parameters
* @param sender The sender address
* @return fee The messaging fee quote
*/
function quote(
MessagingParams calldata params,
address sender
) external view returns (MessagingFee memory fee);
/**
* @notice Struct for setting configuration parameters
* @param eid Endpoint ID
* @param configType Configuration type (1=Executor, 2=ULN)
* @param config Encoded configuration data
*/
struct SetConfigParam {
uint32 eid;
uint32 configType;
bytes config;
}
/**
* @notice Set configuration for an OApp
* @param oapp The OApp address to configure
* @param lib The library address (SendLib or ReceiveLib)
* @param params Array of configuration parameters
*/
function setConfig(
address oapp,
address lib,
SetConfigParam[] calldata params
) external;
/**
* @notice Set send library for an OApp
* @param _oapp The OApp address
* @param _eid Destination endpoint ID
* @param _newLib Send library address
*/
function setSendLibrary(
address _oapp,
uint32 _eid,
address _newLib
) external;
/**
* @notice Set receive library for an OApp
* @param _oapp The OApp address
* @param _eid Source endpoint ID
* @param _newLib Receive library address
* @param _gracePeriod Grace period for library switch
*/
function setReceiveLibrary(
address _oapp,
uint32 _eid,
address _newLib,
uint256 _gracePeriod
) external;
/**
* @notice Set delegate for message handling
* @param delegate Address of the delegate
*/
function setDelegate(
address delegate
) external;
/**
* @notice Get the send library for an OApp and destination
* @param _sender The sender address
* @param _eid Destination endpoint ID
* @return lib The send library address
*/
function getSendLibrary(
address _sender,
uint32 _eid
) external view returns (address lib);
/**
* @notice Get the receive library for an OApp and source
* @param _receiver The receiver address
* @param _eid Source endpoint ID
* @return lib The receive library address
*/
function getReceiveLibrary(
address _receiver,
uint32 _eid
) external view returns (address lib, bool);
/**
* @notice Get the default send library for an endpoint
* @param _eid Destination endpoint ID
* @return The default send library address
*/
function defaultSendLibrary(
uint32 _eid
) external view returns (address);
/**
* @notice Get the default receive library for an endpoint
* @param _eid Source endpoint ID
* @return The default receive library address
*/
function defaultReceiveLibrary(
uint32 _eid
) external view returns (address);
}
src/interfaces/layerzero/IOFT.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import { ILayerZeroEndpointV2 } from "./ILayerZeroEndpointV2.sol";
/**
* @dev Struct representing token parameters for the OFT send() operation.
*/
struct SendParam {
uint32 dstEid; // Destination endpoint ID
bytes32 to; // Recipient address
uint256 amountLD; // Amount to send in local decimals
uint256 minAmountLD; // Minimum amount to send in local decimals
bytes extraOptions; // Additional options for LayerZero message
bytes composeMsg; // Composed message for send() operation
bytes oftCmd; // OFT command (unused in default implementations)
}
/**
* @dev Struct representing OFT limit information.
*/
struct OFTLimit {
uint256 minAmountLD; // Minimum amount in local decimals
uint256 maxAmountLD; // Maximum amount in local decimals
}
/**
* @dev Struct representing OFT receipt information.
*/
struct OFTReceipt {
uint256 amountSentLD; // Amount debited from sender
uint256 amountReceivedLD; // Amount to be received on remote side
}
/**
* @dev Struct representing OFT fee details.
*/
struct OFTFeeDetail {
int256 feeAmountLD; // Amount of fee in local decimals
string description; // Description of the fee
}
/**
* @title IOFT
* @dev Interface for the Omnichain Fungible Token (OFT) standard.
* @dev Interface ID: 0x02e49c2c
*/
interface IOFT {
// Custom errors
error InvalidLocalDecimals();
error SlippageExceeded(uint256 amountLD, uint256 minAmountLD);
// Events
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);
/**
* @notice Retrieves interfaceID and version of the OFT.
* @return interfaceId The interface ID (0x02e49c2c).
* @return version The version.
*/
function oftVersion() external view returns (bytes4 interfaceId, uint64 version);
/**
* @notice Retrieves the address of the token associated with the OFT.
* @return token The address of the ERC20 token implementation.
*/
function token() external view returns (address);
/**
* @notice Indicates whether the OFT contract requires approval of the 'token()' to send.
* @return requiresApproval Whether approval is required.
*/
function approvalRequired() external view returns (bool);
/**
* @notice Retrieves the shared decimals of the OFT.
* @return sharedDecimals The shared decimals (typically 6).
*/
function sharedDecimals() external view returns (uint8);
/**
* @notice Provides a quote for OFT-related operations.
* @param _sendParam The parameters for the send operation.
* @return limit The OFT limit information.
* @return oftFeeDetails The details of OFT fees.
* @return receipt The OFT receipt information.
*/
function quoteOFT(
SendParam calldata _sendParam
) external returns (OFTLimit memory limit, OFTFeeDetail[] memory oftFeeDetails, OFTReceipt memory receipt);
/**
* @notice Provides a quote for the send() operation.
* @param _sendParam The parameters for the send() operation.
* @param _payInLzToken Flag indicating whether the caller is paying in the LZ token.
* @return fee The calculated LayerZero messaging fee.
*/
function quoteSend(
SendParam calldata _sendParam,
bool _payInLzToken
) external returns (ILayerZeroEndpointV2.MessagingFee memory fee);
/**
* @notice Executes the send() operation.
* @param _sendParam The parameters for the send operation.
* @param _fee The fee information supplied by the caller.
* @param _refundAddress The address to receive any excess funds.
* @return receipt The LayerZero messaging receipt.
* @return oftReceipt The OFT receipt information.
*/
function send(
SendParam calldata _sendParam,
ILayerZeroEndpointV2.MessagingFee calldata _fee,
address _refundAddress
) external payable returns (ILayerZeroEndpointV2.MessagingReceipt memory receipt, OFTReceipt memory oftReceipt);
}
src/interfaces/printr/IPrintrStorage.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import { ITreasury } from "../ITreasury.sol";
/**
* @title Printr Storage Interface
* @notice Interface for the Printr contract, which manages tokens with linear bonding curves
* @dev All price calculations use PRECISION_SCALAR (1e18) for accurate floating point math
* Implements cross-chain token deployment through ITelecoinFactory integration
* This interface defines the core storage and view functions for the Printr system
*/
interface IPrintrStorage {
/// @notice Custom errors for the Printr contract
error FeeIsTooHigh(uint256 fee);
error InvalidProtocolTelecoinShare();
error WrongChainName();
error InsufficientPayment();
error InsufficientInitialBuy();
error InvalidBasePairDecimals();
error InvalidBasePrices();
error InvalidBasePairs();
error InvalidCreatorAddress();
error InvalidInitialPrice();
error InvalidLength();
error TooHighThreshold();
error ZeroAmount();
error PoolCreationFailed();
error TokenNotFound();
error SwapFailed();
error LiquidityAlreadyDeployed();
error LiquidityDeploymentFailed();
error InvalidQuoteResult();
error PriceExceedsLimit();
error RefundFailed();
error RenounceOwnershipDisabled();
error InvalidImplementation();
error FeePercentagesMustSum();
error UnauthorizedCaller();
error Create3AddressMismatch();
/**
* @notice Parameters structure for telecoin deployment
* @dev Uses bytes32 for efficient storage and cross-chain compatibility
* @param salt Unique identifier for deployment
* @param creatorAddresses Creator addresses for different chains encoded as bytes
* @param name Telecoin name encoded as bytes32, 31 characters max
* @param symbol Telecoin symbol encoded as bytes32, 31 characters max
* @param packedParams Packed parameters bit layout:
* [0-7] uint8 maxTokenSupplyE (power of 10)
* [8-23] uint16 completionThreshold (basis points, max 10000)
* [24-135] uint112 initialPrice, assuming 18 decimal places for both tokens
* [136-255] uint120 initialBuySpending, assuming 18 decimal places
* @param chains Chain names encoded as bytes32, first chain is the home chain
* @param basePairs Base currency token addresses encoded as bytes32
* @param basePrices Initial prices in base currency per chain as uint128 packed in bytes, 18 decimals for both
*/
struct TelecoinParams {
bytes32 salt;
bytes creatorAddresses;
bytes32 name;
bytes32 symbol;
bytes32 packedParams;
bytes32[] chains;
bytes32[] basePairs;
bytes basePrices;
}
/**
* @notice Unpacked version of the packedParams for easier handling
* @dev Packed bytes32 converted into individual parameters
* @param maxTokenSupplyE Maximum token supply as power of 10
* @param completionThreshold Completion threshold in basis points (max 10000) of max supply
* @param initialPrice Initial token price, assuming 18 decimal places for both tokens
* @param initialBuySpending Initial buy amount, assuming 18 decimal places
*/
struct UnpackedParams {
uint8 maxTokenSupplyE;
uint256 completionThreshold;
uint256 initialPrice;
uint256 initialBuySpending;
}
/**
* @notice Comprehensive information about a token's configuration and state
* @dev Whole struct is packed into 2 storage slots for efficiency
* @param basePair Address of the base currency token (160 bits)
* @param totalCurves Number of curves across all chains (16 bits)
* @param maxTokenSupplyE Maximum token supply as pow of 10 (8 bits)
* @param virtualReserveE Precision scalar for virtualReserve (8 bits)
* @param virtualReserve Compressed virtual reserve balance for bonding curve (64 bits)
* @param reserve Current reserve balance of the base currency token (192 bits)
* @param completionThreshold Threshold for curve completion as percentage of total supply (64 bits)
*/
struct Curve {
/// @dev Slot 1: immutable (160 + 16 + 8 + 8 + 64 = 256 bits, fits in 1 slot)
address basePair;
uint16 totalCurves;
uint8 maxTokenSupplyE;
uint8 virtualReserveE;
uint64 virtualReserve;
/// @dev Slot 2: mutable (192 + 64 = 256 bits)
uint192 reserve;
uint64 completionThreshold;
}
/**
* @notice Readable format of curve information
* @param basePair Base currency token address
* @param totalCurves Total number of curves across chains
* @param maxTokenSupply Maximum token supply
* @param virtualReserve Virtual reserve for curve calculations (already scaled with virtualReserveE)
* @param reserve Current base currency reserve
* @param completionThreshold Completion threshold value
*/
struct CurveInfo {
address basePair;
uint16 totalCurves;
uint256 maxTokenSupply;
uint256 virtualReserve;
uint256 reserve;
uint256 completionThreshold;
}
/**
* @notice Parameters for deploying Printr contracts
* @dev Used to avoid stack too deep errors in constructor
* @param chainName Name of the blockchain network
* @param treasury Address of the treasury contract
* @param legacyTreasury Address of the legacy treasury contract (for migration)
* @param mainTelecoinFactory Address of the main token factory contract
* @param teleportingTelecoinFactory Address of the teleporting token factory contract
* @param wrappedNativeToken Address of wrapped native token (e.g., WETH)
* @param locker Address of the locker contract
* @param liquidityModule Address of the liquidity module
* @param create3Deployer Address of the CREATE3 deployer for deterministic LZChannel deployments
* @param growthFundFund Address of the growth fund
* @param buybackFund Address of the buyback
* @param teamTreasuryFund Address of the team treasury
* @param stakingFund Address of the staking
* @param printrDev Address of the dev NFT contract
* @param legacyPrintrDev Address of the first legacy dev NFT contract (for migration from V1 - oldest original)
* @param legacyPrintrDev2 Address of the second legacy dev NFT contract (for migration from V2 - without base64
* fix)
* @param feePercentGrowth Fee percentage for growth fund in basis points
* @param feePercentBuyback Fee percentage for buyback in basis points
* @param feePercentTeam Fee percentage for team treasury in basis points
* @param feePercentCreator Fee percentage for creator in basis points
* @param protocolTelecoinShareBps Protocol share of V2 telecoin trading fees in basis points (0-10000)
* @param tradingFee Trading fee percentage in basis points
*/
struct DeploymentParams {
string chainName;
address treasury;
address legacyTreasury;
address mainTelecoinFactory;
address teleportingTelecoinFactory;
address wrappedNativeToken;
address locker;
address liquidityModule;
address create3Deployer;
address growthFund;
address buybackFund;
address teamTreasuryFund;
address stakingFund;
address stakingContract;
address printrDev;
address legacyPrintrDev;
address legacyPrintrDev2;
uint256 feePercentGrowth;
uint256 feePercentBuyback;
uint256 feePercentTeam;
uint256 feePercentCreator;
uint256 protocolTelecoinShareBps;
uint16 tradingFee;
}
/// @notice Returns the current chain's hash identifier
function currentChainHash() external view returns (bytes32);
/// @notice Returns the treasury contract address
function treasury() external view returns (ITreasury);
/// @notice Returns the main token factory contract address
function mainTelecoinFactory() external view returns (address);
/// @notice Returns the teleporting token factory contract address
function teleportingTelecoinFactory() external view returns (address);
/// @notice Returns the wrapped native token address
function wrappedNativeToken() external view returns (address);
/// @notice Returns the liquidity module contract address
function liquidityModule() external view returns (address);
/// @notice Returns the locker contract address
function locker() external view returns (address);
/// @notice Returns the CREATE3 deployer address
function create3Deployer() external view returns (address);
/// @notice Returns the growth fund address
function growthFund() external view returns (address);
/// @notice Returns the buyback address
function buybackFund() external view returns (address);
/// @notice Returns the team treasury address
function teamTreasuryFund() external view returns (address);
/// @notice Returns the staking address
function stakingFund() external view returns (address);
/// @notice Returns the staking contract address
function stakingContract() external view returns (address);
/// @notice Returns the creator NFT contract address
function printrDev() external view returns (address);
/// @notice Returns the fee percentage for growth fund
function feePercentGrowth() external view returns (uint256);
/// @notice Returns the fee percentage for buyback
function feePercentBuyback() external view returns (uint256);
/// @notice Returns the fee percentage for team treasury
function feePercentTeam() external view returns (uint256);
/// @notice Returns the fee percentage for creator
function feePercentCreator() external view returns (uint256);
/// @notice Returns the protocol share of V2 telecoin trading fees in basis points
function protocolTelecoinShareBps() external view returns (uint256);
/// @notice Returns the trading fee percentage in basis points
function tradingFee() external view returns (uint16);
}
src/interfaces/printr/IPrintrTeleport.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import { IPrintrStorage } from "../printr/IPrintrStorage.sol";
/**
* @title IPrintrTeleport
* @notice Interface for PrintrTeleport contract that handles cross-chain messaging with Solana
* @dev This interface defines the functionality for sending and receiving messages between EVM and Solana
* using the Teleport message protocol for token transfers
*/
interface IPrintrTeleport is IPrintrStorage {
/**
* @notice Error thrown when payload has invalid length
*/
error InvalidPayloadLength();
/**
* @notice Error thrown when message kind is unexpected
*/
error UnexpectedMessageKind();
/**
* @notice Error thrown when endpoint address is invalid
*/
error InvalidEndpoint();
/**
* @notice Error thrown when solana program address is invalid
*/
error InvalidSolanaProgram();
/**
* @notice Error thrown when sender is not authorized
*/
error UnauthorizedSender();
/**
* @notice Error thrown when contract has insufficient fee balance
*/
error InsufficientFee();
/**
* @notice Error thrown when fee transfer fails
*/
error FeeTransferFailed();
/**
* @notice Error thrown when an invalid protocol is specified
*/
error InvalidProtocol();
/**
* @notice Error thrown when the chain ID length is invalid
*/
error InvalidChainIdLength();
/**
* @notice Error thrown when a non-numeric character is found in chain ID
*/
error InvalidNumericCharacter();
/**
* @notice Error thrown when the endpoint ID is invalid
*/
error InvalidEndpointId();
/**
* @notice Error thrown when calldata is invalid
*/
error InvalidCalldata();
/**
* @notice Error thrown when security level is invalid
*/
error InvalidSecurityLevel();
/**
* @notice Error thrown when protocol is not in global whitelist
*/
error ProtocolNotWhitelisted();
/**
* @notice Error thrown when protocol is in token blacklist
*/
error ProtocolBlacklisted();
/**
* @notice Error thrown when invalid protocol bit position used
*/
error InvalidProtocolBitPosition();
/**
* @notice Error thrown when teleport amount exceeds maximum supported value
* @dev Maximum supported amount is type(uint64).max * 1e9 (in 18 decimals)
* @param requestedAmount The amount that was requested to teleport
* @param maxAmount The maximum amount that can be teleported
*/
error TeleportAmountOverflow(uint256 requestedAmount, uint256 maxAmount);
/**
* @notice Error thrown when ITS protocol is used (deprecated)
*/
error ITSDeprecated();
/**
* @notice Protocol enum for teleportation methods
* @dev Must match the Protocol enum in ITelecoin for compatibility
*/
enum TeleportProtocol {
UNSPECIFIED, // 0 - Used to catch malformed transactions
ITS, // 1 - DEPRECATED
LZ_FAST, // 2 - Fast LayerZero channel with minimal confirmations
LZ_SECURE, // 3 - Secure LayerZero channel with balanced confirmations
LZ_SLOW // 4 - Slow LayerZero channel with maximum confirmations
}
/**
* @notice Struct containing constructor parameters for teleport deployment
* @param lzFlatFee Flat fee for LayerZero transfers
* @param lzBipsFee Basis points fee for LayerZero transfers
* @param lzEndpoint LayerZero endpoint address for this chain
* @param fastSolanaLzPeer Solana LayerZero peer address for fast/low security channel
* @param secureSolanaLzPeer Solana LayerZero peer address for secure/medium security channel
* @param slowSolanaLzPeer Solana LayerZero peer address for slow/high security channel
* @param lzReceiveGasLimit Gas limit for LayerZero receive operations
* @param lzReceiveNativeDrop Native drop amount for LayerZero receive operations
*/
struct TeleportDeployParams {
uint256 lzFlatFee;
uint16 lzBipsFee;
address lzEndpoint;
bytes32 fastSolanaLzPeer;
bytes32 secureSolanaLzPeer;
bytes32 slowSolanaLzPeer;
uint128 lzReceiveGasLimit;
uint128 lzReceiveNativeDrop;
}
/**
* @notice Struct containing teleport parameters
* @param destChain The destination chain identifier
* @param destAddress The bytes representation of the address of the recipient
* @param amount The amount of tokens to be transferred
* @param metadata Additional data for the cross-chain transfer
* @param protocol The teleportation protocol to use (ITS, LZ_FAST, LZ_SECURE, LZ_SLOW)
*/
struct TeleportParams {
string destChain;
bytes destAddress;
uint256 amount;
bytes metadata;
TeleportProtocol protocol;
}
/**
* @notice Event emitted when a new LayerZero delegate is set for a channel
* @param protocol The teleport protocol (LZ_FAST, LZ_SECURE, LZ_SLOW)
* @param delegate Address of the new LayerZero delegate
*/
event LzDelegateUpdated(TeleportProtocol indexed protocol, address indexed delegate);
/**
* @notice Event emitted when global protocol whitelist is updated
* @param newWhitelist The new whitelist bitmap
*/
event TeleportProtocolWhitelistUpdated(bytes32 indexed newWhitelist);
/**
* @notice Event emitted when a token's protocol blacklist is updated
* @param telecoinId The telecoin ID
* @param newBlacklist The new blacklist bitmap
*/
event TelecoinProtocolBlacklistUpdated(bytes32 indexed telecoinId, bytes32 indexed newBlacklist);
/**
* @notice Event emitted when tokens are teleported to another chain
* @param telecoinId The ID of the token being transferred
* @param tokenAddress The address of the token contract
* @param sourceAddress The address initiating the transfer
* @param destChain The target chain for the transfer
* @param destAddress The address on the destination chain
* @param amount The amount of tokens being transferred
*/
event Teleporting(
bytes32 indexed telecoinId,
address indexed tokenAddress,
address indexed sourceAddress,
string destChain,
bytes destAddress,
uint256 amount
);
// ============================================
// EXTERNAL FUNCTIONS
// ============================================
/**
* @notice Calculates the universal token ID based on token parameters
* @dev Returns the telecoinId as a universal token ID that's vendor-agnostic
* @param tokenParams Parameters for the token deployment
* @return telecoinId The universal token ID
*/
function getTelecoinId(
TelecoinParams calldata tokenParams
) external pure returns (bytes32 telecoinId);
/**
* @notice Sets the LayerZero delegate address for a specific channel
* @dev Only callable by the contract owner or authorized account
* @param protocol The teleport protocol to configure (LZ_FAST, LZ_SECURE, LZ_SLOW)
* @param delegate Address of the new LayerZero delegate
*/
function setLzDelegate(
TeleportProtocol protocol,
address delegate
) external;
/**
* @notice Gets the LZChannel address for a specific protocol
* @param protocol The teleport protocol (LZ_FAST, LZ_SECURE, LZ_SLOW)
* @return channel Address of the LZChannel contract for this protocol
*/
function getLzChannel(
TeleportProtocol protocol
) external view returns (address channel);
/**
* @notice Updates the global protocol whitelist by enabling and/or disabling protocols
* @dev Only callable by the contract owner. Processes disable array first, then enable array.
* @param enable Array of protocols to enable globally
* @param disable Array of protocols to disable globally
*/
function updateGlobalProtocols(
TeleportProtocol[] calldata enable,
TeleportProtocol[] calldata disable
) external;
/**
* @notice Gets the global protocol whitelist bitmap
* @return whitelist Bitmap of enabled protocols
*/
function getTeleportProtocolWhitelist() external view returns (bytes32 whitelist);
/**
* @notice Updates the protocol blacklist for a specific telecoin
* @dev Only callable by the contract owner. Processes enable array first (removes from blacklist), then disable
* array (adds to blacklist).
* @param telecoinId The ID of the telecoin
* @param enable Array of protocols to enable for this telecoin (remove from blacklist)
* @param disable Array of protocols to disable for this telecoin (add to blacklist)
*/
function updateTelecoinProtocols(
bytes32 telecoinId,
TeleportProtocol[] calldata enable,
TeleportProtocol[] calldata disable
) external;
/**
* @notice Gets a token's protocol blacklist bitmap
* @param telecoinId The telecoin ID
* @return blacklist Bitmap of disabled protocols for this token
*/
function getTelecoinProtocolBlacklist(
bytes32 telecoinId
) external view returns (bytes32 blacklist);
/**
* @notice Checks if a protocol is allowed for a specific token
* @dev Returns true if protocol is in global whitelist AND NOT in token blacklist
* @param telecoinId The telecoin ID
* @param protocol The protocol to check
* @return allowed True if protocol is allowed for this token
*/
function isProtocolAllowed(
bytes32 telecoinId,
TeleportProtocol protocol
) external view returns (bool allowed);
/**
* @notice Quotes the total teleport fee for any protocol
* @dev Consolidates fee calculation for LayerZero protocols. ITS is deprecated and reverts.
* @param token Token address to transfer
* @param params The teleport parameters struct (includes protocol)
* @return totalNativeFee The total fee in native currency (protocol fee + bridge fee)
* @return basePairFee The fee in base pair tokens (0 if base pair is native)
* @return basePair The base pair address (address(0) if native)
* @return bridgeFee The bridge-specific gas fee (ITS gas fee or LZ messaging fee)
*/
function quoteTeleportFee(
address token,
TeleportParams calldata params
) external returns (uint256 totalNativeFee, uint256 basePairFee, address basePair, uint256 bridgeFee);
/**
* @notice Universal teleport function that routes to ITS or LayerZero
* @dev Routes tokens to the appropriate cross-chain protocol based on params.protocol
* @param token The token address to teleport
* @param params The teleport parameters struct (includes protocol)
*/
function teleport(
address token,
TeleportParams calldata params
) external payable;
/**
* @notice Universal teleport function with witness signature support
* @dev Called via permitWitnessCall to enable signature-based teleportation
* @dev Signer must be the first param to protect from permitWitnessCall attacks
* @param signer Address initiating the teleport, must be first parameter
* @param telecoinId The telecoin ID instead of token address
* @param params The teleport parameters struct (includes protocol)
*/
function witnessTeleport(
address signer,
bytes32 telecoinId,
TeleportParams calldata params
) external payable;
/**
* @notice Transmits a LayerZero cross-chain token transfer
* @dev Called by token contracts to initiate LayerZero transfers
* @dev telecoinId first param, to protect from permitWitnessCall calls
* @param telecoinId Universal token ID (32 bytes)
* @param sender Address initiating the transfer
* @param params The teleport parameters struct
*/
function transmitLzSend(
bytes32 telecoinId,
address sender,
TeleportParams calldata params
) external payable returns (bytes memory receipt);
/**
* @notice ITS deprecated - kept for ABI compatibility with old deployed tokens. Always reverts.
*/
function broadcastInterchainTransfer(
bytes32 telecoinId,
address sourceAddress,
string calldata destChain,
bytes calldata destAddress,
uint256 amount
) external;
/**
* @notice ITS deprecated - kept for ABI compatibility with old deployed tokens. Always reverts.
*/
function processInterchainTransfer(
bytes32 telecoinId,
address sender,
uint256 amount
) external;
// ============================================
// EXTERNAL VIEW FUNCTIONS
// ============================================
/**
* @notice Gets the LayerZero endpoint address
* @return The LayerZero endpoint address
*/
function lzEndpoint() external view returns (address);
/**
* @notice Gets the current gas limit for LayerZero receive operations
* @return gasLimit Current gas limit
*/
function lzReceiveGasLimit() external view returns (uint128 gasLimit);
/**
* @notice Gets the current native drop amount for LayerZero receive operations
* @return nativeDrop Current native drop amount
*/
function lzReceiveNativeDrop() external view returns (uint128 nativeDrop);
/**
* @notice Receives teleport messages from authorized channels
* @dev Called by LZChannel contracts to forward processed messages
* @param protocol The teleport protocol of the calling channel (LZ_FAST, LZ_SECURE, LZ_SLOW)
* @param originSender The LayerZero origin sender address (Solana peer or self)
* @param message The processed teleport payload
*/
function receiveFromChannel(
TeleportProtocol protocol,
bytes32 originSender,
bytes calldata message
) external payable;
}
src/interfaces/telecoin/IERC20Permit.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
/// @title IERC20Permit Interface with Errors
/// @notice Interface for ERC20 Permit extension with proper error definitions
/// @dev Extends the standard EIP-2612 permit functionality with error definitions
interface IERC20Permit {
/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
/**
* @notice Thrown when a permit signature has expired
* @param deadline The timestamp at which the signature expired
*/
error ERC2612ExpiredSignature(uint256 deadline);
/**
* @notice Thrown when the recovered signer does not match the expected owner
* @param signer The address recovered from the signature
* @param owner The expected owner address
*/
error ERC2612InvalidSigner(address signer, address owner);
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
/**
* @notice Emitted when an owner manually invalidates their nonce
* @param owner The address that invalidated their nonce
* @param newNonce The new nonce value after invalidation
*/
event NonceInvalidated(address indexed owner, uint256 newNonce);
/*//////////////////////////////////////////////////////////////
PERMIT LOGIC
//////////////////////////////////////////////////////////////*/
/**
* @notice Returns the current nonce for the given owner
* @dev This value must be included whenever a signature is generated for permit
* @param owner The address to get the nonce for
* @return The current nonce value for the owner
*/
function nonces(
address owner
) external view returns (uint256);
/**
* @notice Returns the domain separator used in the encoding of signatures
* @dev Used to prevent signature replay attacks across different domains
* @return The EIP-712 domain separator hash
*/
function DOMAIN_SEPARATOR() external view returns (bytes32);
/**
* @notice Returns the permit typehash used in EIP-712 signature encoding
* @dev Constant value defining the structure of permit messages
* @return The keccak256 hash of the permit type string
*/
function PERMIT_TYPEHASH() external view returns (bytes32);
/**
* @notice Sets allowance using EIP-2612 signature-based authorization
* @dev Allows setting allowance without requiring a separate transaction from the token owner
* @param owner The owner of the tokens
* @param spender The address authorized to spend the tokens
* @param value The amount of tokens to authorize for spending
* @param deadline The timestamp at which the permit expires
* @param v The recovery parameter of the signature (27 or 28)
* @param r The first 32 bytes of the signature
* @param s The second 32 bytes of the signature
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @notice Invalidates the current nonce for msg.sender
* @dev Increments the nonce, making all outstanding permit signatures invalid
* This provides users with an emergency mechanism to cancel pending permits in case of:
* - Key compromise or suspected phishing
* - Changed mind about a signed but not executed permit
* - Need to invalidate multiple permits at once
* Emits a NonceInvalidated event
*/
function invalidateNonce() external;
}
src/interfaces/telecoin/IERC20Witness.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import { IERC20Errors } from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { IERC20Permit } from "./IERC20Permit.sol";
/// @title IERC20Witness Interface
/// @notice Interface for ERC20 tokens with witness-based permit functionality
/// @dev Extends standard ERC20 with permitWitness functions that include additional validation data
interface IERC20Witness is IERC20Permit, IERC20Metadata, IERC20Errors {
/*//////////////////////////////////////////////////////////////
WITNESS-SPECIFIC ERRORS
//////////////////////////////////////////////////////////////*/
/**
* @notice Thrown when an invalid witness value is provided
* @dev The witness data failed validation checks
*/
error ERC20InvalidWitness();
/**
* @notice Thrown when attempting to call the contract itself
* @dev Self-calls are not permitted for security reasons
*/
error ERC20InvalidCallTarget();
/**
* @notice Thrown when invalid call data is provided
* @dev The call data format or content is malformed
*/
error ERC20InvalidCallData();
/**
* @notice Thrown when an external call fails during witness operations
* @dev The target contract call returned failure or reverted
*/
error ERC20CallFailed();
struct ContractCall {
address target;
string method;
uint256 nativeValue;
bytes params;
}
/*//////////////////////////////////////////////////////////////
PERMIT WITNESS LOGIC
//////////////////////////////////////////////////////////////*/
/**
* @notice Returns the permit witness typehash for EIP-712 signature encoding
* @dev Used for permitWitness function signature validation
* @return The keccak256 hash of the permit witness type string
*/
function PERMIT_WITNESS_TYPEHASH() external view returns (bytes32);
/**
* @notice Returns the base permit witness type string for EIP-712 structured data
* @dev Used as a prefix to construct full type strings with witness data
* @return The base permit witness type string stub
*/
function PERMIT_WITNESS_TYPESTRING_STAB() external view returns (string memory);
/**
* @notice Returns the contract call witness type string completion
* @dev Appended to PERMIT_WITNESS_TYPESTRING_STAB to form complete EIP-712 type string
* @return The contract call type string completion
*/
function WITNESS_CALL_TYPESTRING() external view returns (string memory);
/**
* @notice Returns the contract call typehash for EIP-712 signature encoding
* @dev Used for ContractCall struct hashing in witness validation
* @return The keccak256 hash of the ContractCall type string
*/
function WITNESS_CALL_TYPEHASH() external view returns (bytes32);
/**
* @notice Returns the witness type identifier for transfer operations
* @dev Used to validate witness data in transfer contexts
* @return The bytes32 identifier for transfer witness operations
*/
function TRANSFER_WITNESS() external view returns (bytes32);
/**
* @notice Sets allowance using signature with additional witness validation
* @dev Extends standard permit functionality with witness data for enhanced security
* @param owner The owner of the tokens
* @param spender The address authorized to spend the tokens
* @param value The amount of tokens to authorize for spending
* @param deadline The timestamp at which the permit expires
* @param witness Additional validation data to prevent certain attack vectors
* @param v The recovery parameter of the signature (27 or 28)
* @param r The first 32 bytes of the signature
* @param s The second 32 bytes of the signature
*/
function permitWitness(
address owner,
address spender,
uint256 value,
uint256 deadline,
bytes32 witness,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @notice Sets allowance using signature with custom witness type string for free-form witness data
* @dev Extends permitWitness with witnessTypeString parameter to support various witness structures
* @param owner The owner of the tokens
* @param spender The address authorized to spend the tokens
* @param value The amount of tokens to authorize for spending
* @param deadline The timestamp at which the permit expires
* @param witness Additional validation data hash to prevent certain attack vectors
* @param witnessTypeString The EIP-712 type string for the witness data structure
* @param v The recovery parameter of the signature (27 or 28)
* @param r The first 32 bytes of the signature
* @param s The second 32 bytes of the signature
*/
function permitWitness(
address owner,
address spender,
uint256 value,
uint256 deadline,
bytes32 witness,
string calldata witnessTypeString,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @notice Permits and executes a direct transfer using signature authorization
* @dev Combines permit and transferFrom into a single operation with witness validation
* @param owner The owner of the tokens to transfer
* @param spender The recipient address for the transfer
* @param value The amount of tokens to transfer
* @param deadline The timestamp at which the permit expires
* @param v The recovery parameter of the signature (27 or 28)
* @param r The first 32 bytes of the signature
* @param s The second 32 bytes of the signature
* @return success Whether the transfer operation was successful
*/
function permitTransferFrom(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external returns (bool success);
/**
* @notice Permits token allowance and executes an external call in one transaction
* @dev Combines permit functionality with external contract interaction using witness validation
* @param owner The owner of the tokens
* @param spender The address authorized to spend the tokens
* @param value The amount of tokens to authorize for spending
* @param deadline The timestamp at which the permit expires
* @param call ContractCall struct containing target address, method signature, and parameters
* @param v The recovery parameter of the signature (27 or 28)
* @param r The first 32 bytes of the signature
* @param s The second 32 bytes of the signature
* @return returnData The return data from the executed external call
*/
function permitWitnessCall(
address owner,
address spender,
uint256 value,
uint256 deadline,
ContractCall calldata call,
uint8 v,
bytes32 r,
bytes32 s
) external payable returns (bytes memory returnData);
}
src/interfaces/telecoin/IPrinted.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
/**
* @title IPrintrTeleportingTelecoin
* @notice Interface for the PrintrTelecoin contract with teleport and curve completion functionality
* @dev Extends ITelecoin interface with additional token management functions
*/
interface IPrinted {
/**
* @notice Enum representing the teleport type of a Telecoin
* @dev Values 0-1 are legacy types for backward compatibility with deployed contracts
* Values 2-3 are new types that support teleporting by calling methods on a Telecoin
* - LegacyMain (0): Legacy Main Telecoin (bool false, uses lock/unlock)
* - LegacyTeleporting (1): Legacy Teleporting Telecoin (bool true, uses mint/burn)
* - Main (2): New Main Telecoin with Telecoin.teleport() support
* - Teleporting (3): New Teleporting Telecoin with Telecoin.teleport() support
*/
enum TeleportType {
LegacyMain, // 0 - backward compatible with bool false
LegacyTeleporting, // 1 - backward compatible with bool true
Main, // 2 - new Main Telecoin type
Teleporting // 3 - new Teleporting Telecoin type
}
/**
* @notice Error thrown when attempting to interact with an incomplete curve
* @dev This error is typically thrown when trying to add liquidity before curve completion
*/
error CurveIsNotComplete();
/**
* @notice Returns the teleport type of this Telecoin
* @dev Values 0-1 are legacy (backward compatible), values 2-3 support transmitLzSend
* @return teleportType The TeleportType enum value:
* - LegacyMain (0): Legacy Main Telecoin (lock/unlock)
* - LegacyTeleporting (1): Legacy Teleporting Telecoin (mint/burn)
* - Main (2): New Main Telecoin with transmitLzSend support
* - Teleporting (3): New Teleporting Telecoin with transmitLzSend support
*/
function isTeleporting() external view returns (TeleportType teleportType);
/**
* @notice Sets the restricted pool address during curve initialization
* @dev Can only be called by Printr before completion
* @param poolAddress The pool address to restrict transfers to
* @custom:throws UnauthorizedAccount if caller is not Printr or curve is already complete
* @custom:throws ZeroAddress if pool address is zero
*/
function setRestrictedPool(
address poolAddress
) external;
/**
* @notice Marks the curve as completed, removing transfer restrictions
* @dev Can only be called by Printr when curve is not already completed
* @custom:throws UnauthorizedAccount if caller is not Printr or curve is already completed
*/
function markCurveComplete() external;
}
src/interfaces/telecoin/IPrintrMainTelecoin.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import { IPrinted } from "./IPrinted.sol";
import { ITelecoin } from "./ITelecoin.sol";
/**
* @title IPrintrTeleportingTelecoin
* @notice Interface for the PrintrTelecoin contract with teleport and curve completion functionality
* @dev Extends ITelecoin interface with additional token management functions
*/
interface IPrintrMainTelecoin is IPrinted, ITelecoin { }
src/interfaces/telecoin/ITelecoin.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import { IOFT } from "../layerzero/IOFT.sol";
import { IPrintrTeleport } from "../printr/IPrintrTeleport.sol";
import { IERC20Witness } from "./IERC20Witness.sol";
/**
* @title ITelecoin
* @notice Interface for the Telecoin base contract
* @dev Extends IERC20 for base teleport functionality
*/
interface ITelecoin is IERC20Witness, IOFT {
/**
* @notice Struct containing deployment parameters for telecoin contracts
* @param telecoinId Universal telecoin ID
* @param name Token name
* @param symbol Token symbol
* @param maxSupply Maximum supply of the token
* @param printr Address of the Printr contract
*/
struct TelecoinDeployParams {
bytes32 telecoinId;
string name;
string symbol;
uint256 maxSupply;
address printr;
}
/**
* @notice Error thrown when a zero address is provided where not allowed
*/
error ZeroAddress();
/**
* @notice Error thrown when an unauthorized account attempts a restricted operation
* @param account The address that attempted the unauthorized operation
*/
error UnauthorizedAccount(address account);
/**
* @notice Error thrown when ITS protocol is used (deprecated)
*/
error ITSDeprecated();
/**
* @notice Error thrown when an invalid protocol is specified
*/
error InvalidProtocol();
/**
* @notice Error thrown when a native token transfer fails
*/
error TransferFailed();
/**
* @notice Emitted when tokens are teleported in from another chain
* @param telecoinId The universal token ID
* @param to The address receiving the tokens
* @param value The amount of tokens teleported in
*/
event TeleportIn(bytes32 indexed telecoinId, address indexed to, uint256 value);
/**
* @notice Emitted when tokens are teleported out to another chain
* @param telecoinId The universal token ID
* @param from The address from which tokens are teleported
* @param value The amount of tokens teleported out
*/
event TeleportOut(bytes32 indexed telecoinId, address indexed from, uint256 value);
/**
* @notice Returns the universal token ID (deploySalt)
* @dev This value is immutable and set during contract construction
* @return The universal token ID based on deployment salt
*/
function telecoinId() external view returns (bytes32);
/**
* @notice Returns the address of the Printr contract that created this token
* @dev This value is immutable and set during contract construction
* @return The address of the Printr contract
*/
function printr() external view returns (address);
/**
* @notice Returns the URL of the off-chain metadata JSON for this telecoin
* @dev Indexer-friendly getter following the OpenSea contractURI convention. The URL
* is derived from the immutable telecoinId so it remains stable across chains.
* @return URL of the metadata JSON (e.g. name, description, image, socials)
*/
function contractURI() external view returns (string memory);
/**
* @notice Returns the URL of the off-chain metadata JSON for this telecoin
* @dev Alias of contractURI(). Mirrors the Solana/Metaplex naming so the same
* lookup works whether the consumer expects EVM or Solana conventions.
* @return URL of the metadata JSON (identical to contractURI())
*/
function metadataURI() external view returns (string memory);
/**
* @notice Quotes the total teleport fee for any protocol
* @dev Delegates to PrintrTeleport's quoteTeleportFee for fee calculation
* @param params The teleport parameters struct (includes protocol)
* @return totalNativeFee The total fee in native currency (protocol fee + bridge fee)
* @return basePairFee The fee in base pair tokens (0 if base pair is native)
* @return basePair The base pair address (address(0) if native)
* @return bridgeFee The bridge-specific gas fee (ITS gas fee or LZ messaging fee)
*/
function quoteTeleportFee(
IPrintrTeleport.TeleportParams memory params
) external returns (uint256 totalNativeFee, uint256 basePairFee, address basePair, uint256 bridgeFee);
/**
* @notice Teleports tokens from sender to a destination chain
* @param params The teleport parameters struct (includes protocol)
*/
function teleport(
IPrintrTeleport.TeleportParams calldata params
) external payable;
/**
* @notice Teleports tokens from a specified sender to a destination chain
* @param sender The sender of the tokens (must have approved msg.sender)
* @param params The teleport parameters struct (includes protocol)
*/
function teleportFrom(
address sender,
IPrintrTeleport.TeleportParams calldata params
) external payable;
}
src/interfaces/telecoin/ITeleporting.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import { ITelecoin } from "./ITelecoin.sol";
/**
* @title ITeleportingTelecoin
* @notice Interface for the TeleportingTelecoin contract with teleporting capabilities
* @dev Extends ITelecoin for teleport functionality via LayerZero
*/
interface ITeleportingTelecoin is ITelecoin {
/**
* @notice Teleports tokens into existence for cross-chain transfers
* @param to Address to receive the tokens
* @param value Amount of tokens to teleport in
*/
function teleportIn(
address to,
uint256 value
) external;
/**
* @notice Teleports tokens out of existence for cross-chain transfers
* @param from Address whose tokens are being teleported out
* @param value Amount of tokens to teleport out
*/
function teleportOut(
address from,
uint256 value
) external;
}
src/telecoin/ERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import { IERC20Permit } from "../interfaces/telecoin/IERC20Permit.sol";
import { IERC20Errors } from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
/**
* @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
* @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
* @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
*/
contract ERC20 is IERC20Permit, IERC20Metadata, IERC20Errors {
/*//////////////////////////////////////////////////////////////
METADATA STORAGE
//////////////////////////////////////////////////////////////*/
string public name;
string public symbol;
uint8 public immutable decimals;
/*//////////////////////////////////////////////////////////////
ERC20 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
/*//////////////////////////////////////////////////////////////
EIP-2612 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 internal immutable INITIAL_CHAIN_ID;
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
mapping(address => uint256) public nonces;
/*//////////////////////////////////////////////////////////////
EIP-2612 CONSTANTS
//////////////////////////////////////////////////////////////*/
bytes32 public constant PERMIT_TYPEHASH =
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
/**
* @notice Initializes the ERC20 token with metadata and EIP-2612 permit functionality
* @dev Sets up the token name, symbol, decimals and initializes EIP-712 domain separator for permit signatures
* @param _name The human-readable name of the token (e.g. "My Token")
* @param _symbol The token symbol used on exchanges (e.g. "MTK")
* @param _decimals Number of decimal places for token amounts (typically 18 for most ERC20 tokens)
*/
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
INITIAL_CHAIN_ID = block.chainid;
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
}
/*//////////////////////////////////////////////////////////////
ERC20 LOGIC
//////////////////////////////////////////////////////////////*/
/**
* @notice Approves another account to spend tokens on behalf of the caller
* @dev Implements the standard ERC20 approve function with unlimited allowance support
* @param spender The address that will be allowed to spend the tokens
* @param value The amount of tokens to approve for spending (in token's decimal units)
* @return Always returns true to indicate successful approval
*/
function approve(
address spender,
uint256 value
) public virtual returns (bool) {
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
/**
* @notice Transfers tokens from the caller to another address
* @dev Uses internal _update function to handle balance changes and emit Transfer event
* @param to The recipient address to transfer tokens to
* @param value The amount of tokens to transfer (in token's decimal units)
* @return Always returns true to indicate successful transfer
*/
function transfer(
address to,
uint256 value
) public virtual returns (bool) {
_update(msg.sender, to, value);
return true;
}
/**
* @notice Transfers tokens from one address to another using allowance mechanism
* @dev Checks and updates allowance before transferring. Unlimited allowance (type(uint256).max) is not
* decremented
* @param from The address to transfer tokens from (must have sufficient balance)
* @param to The recipient address to transfer tokens to
* @param value The amount of tokens to transfer (in token's decimal units)
* @return Always returns true to indicate successful transfer
*/
function transferFrom(
address from,
address to,
uint256 value
) public virtual returns (bool) {
address spender = msg.sender;
uint256 allowed = allowance[from][spender];
if (allowed != type(uint256).max) {
if (allowed < value) {
revert ERC20InsufficientAllowance(spender, allowed, value);
}
allowance[from][spender] = allowed - value;
}
_update(from, to, value);
return true;
}
/*//////////////////////////////////////////////////////////////
EIP-2612 LOGIC
//////////////////////////////////////////////////////////////*/
/**
* @notice Permits an allowance to be set via signature, implementing EIP-2612
* @dev Validates the signature against EIP-712 typed data and sets allowance without requiring a transaction from
* owner
* @param owner The address that owns the tokens and is granting the allowance
* @param spender The address that will be allowed to spend the tokens
* @param value The amount of tokens to approve for spending (in token's decimal units)
* @param deadline The timestamp after which the permit signature is no longer valid
* @param v The recovery identifier of the signature (27 or 28)
* @param r The first 32 bytes of the signature
* @param s The second 32 bytes of the signature
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
if (deadline < block.timestamp) {
revert ERC2612ExpiredSignature(deadline);
}
// Unchecked because the only math done is incrementing
// the owner's nonce which cannot realistically overflow.
unchecked {
bytes32 structHash =
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline));
bytes32 hash = keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR(), structHash));
address recoveredAddress = ecrecover(hash, v, r, s);
if (recoveredAddress == address(0) || recoveredAddress != owner) {
revert ERC2612InvalidSigner(recoveredAddress, owner);
}
allowance[recoveredAddress][spender] = value;
}
emit Approval(owner, spender, value);
}
/**
* @notice Invalidates the current nonce for msg.sender
* @dev Increments the nonce, making all outstanding permit signatures invalid
* This provides users with an emergency mechanism to cancel pending permits in case of:
* - Key compromise or suspected phishing
* - Changed mind about a signed but not executed permit
* - Need to invalidate multiple permits at once
* Emits a NonceInvalidated event
*/
function invalidateNonce() external {
unchecked {
emit NonceInvalidated(msg.sender, ++nonces[msg.sender]);
}
}
/**
* @notice Returns the domain separator for EIP-712 signature validation
* @dev Returns cached separator if chain ID hasn't changed, otherwise recomputes it
* @return The EIP-712 domain separator hash for this contract and chain
*/
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
}
/**
* @notice Computes the EIP-712 domain separator for the current chain and contract
* @dev Used for EIP-712 signature validation in permit functions
* @return The computed domain separator hash including contract name, version, chain ID, and address
*/
function computeDomainSeparator() internal view virtual returns (bytes32) {
return keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}
/*//////////////////////////////////////////////////////////////
INTERNAL UPDATE LOGIC
//////////////////////////////////////////////////////////////*/
/**
* @notice Internal function to handle token transfers, mints, and burns
* @dev Handles balance updates and total supply changes. Emits Transfer event for all operations
* @param from The address to transfer from (address(0) for minting)
* @param to The address to transfer to (address(0) for burning)
* @param value The amount of tokens to transfer/mint/burn (in token's decimal units)
*/
function _update(
address from,
address to,
uint256 value
) internal virtual {
if (from == address(0)) {
// Increase total supply
totalSupply += value;
} else {
// Transfer - decrease from balance
uint256 fromBalance = balanceOf[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
balanceOf[from] = fromBalance - value;
}
}
if (to == address(0)) {
// Decrease total supply
unchecked {
totalSupply -= value;
}
} else {
// Transfer or mint - increase to balance
unchecked {
balanceOf[to] += value;
}
}
emit Transfer(from, to, value);
}
}
src/telecoin/ERC20Witness.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import "../interfaces/telecoin/IERC20Witness.sol";
import "./ERC20.sol";
/**
* @notice ERC20 extension with witness-based permit functionality for enhanced security
* @dev Extends ERC20 with permitWitness functions that include additional validation data
*/
contract ERC20Witness is IERC20Witness, ERC20 {
/*//////////////////////////////////////////////////////////////
EIP-2612 CONSTANTS
//////////////////////////////////////////////////////////////*/
bytes32 public constant PERMIT_WITNESS_TYPEHASH = keccak256(
"PermitWitness(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline,bytes32 witness)"
);
string public constant PERMIT_WITNESS_TYPESTRING_STAB =
"PermitWitness(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline,";
string public constant WITNESS_CALL_TYPESTRING =
"ContractCall call)ContractCall(address target,string method,uint256 nativeValue,bytes params)";
bytes32 public constant WITNESS_CALL_TYPEHASH =
keccak256("ContractCall(address target,string method,uint256 nativeValue,bytes params)");
// Witness type prefixes to prevent signature collision between different witness functions
bytes32 public constant TRANSFER_WITNESS = bytes32(0);
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
/**
* @notice Initializes the ERC20Witness token with metadata and witness-based permit functionality
* @dev Calls parent ERC20 constructor to set up basic token functionality with added witness capabilities
* @param _name The human-readable name of the token (e.g. "My Token")
* @param _symbol The token symbol used on exchanges (e.g. "MTK")
* @param _decimals Number of decimal places for token amounts (typically 18 for most ERC20 tokens)
*/
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) ERC20(_name, _symbol, _decimals) { }
/*//////////////////////////////////////////////////////////////
PERMIT WITNESS LOGIC
//////////////////////////////////////////////////////////////*/
/**
* @notice Sets allowance via signature with additional witness data for enhanced security
* @dev Extends EIP-2612 permit with witness parameter to prevent signature replay across different contexts
* @param owner The address that owns the tokens and is granting the allowance
* @param spender The address that will be allowed to spend the tokens
* @param value The amount of tokens to approve for spending (in token's decimal units)
* @param deadline The timestamp after which the permit signature is no longer valid
* @param witness Additional context data hash to prevent cross-context signature replay
* @param v The recovery identifier of the signature (27 or 28)
* @param r The first 32 bytes of the signature
* @param s The second 32 bytes of the signature
*/
function permitWitness(
address owner,
address spender,
uint256 value,
uint256 deadline,
bytes32 witness,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
if (witness == TRANSFER_WITNESS) {
revert ERC20InvalidWitness();
}
_validatePermitWitness(owner, spender, value, deadline, witness, v, r, s);
allowance[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @notice Sets allowance via signature with additional witness data for enhanced security
* @dev Extends EIP-2612 permit with witness parameter to prevent signature replay across different contexts
* @param owner The address that owns the tokens and is granting the allowance
* @param spender The address that will be allowed to spend the tokens
* @param value The amount of tokens to approve for spending (in token's decimal units)
* @param deadline The timestamp after which the permit signature is no longer valid
* @param witness Additional context data hash to prevent cross-context signature replay
* @param v The recovery identifier of the signature (27 or 28)
* @param r The first 32 bytes of the signature
* @param s The second 32 bytes of the signature
*/
function permitWitness(
address owner,
address spender,
uint256 value,
uint256 deadline,
bytes32 witness,
string memory witnessTypeString,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
if (witness == TRANSFER_WITNESS) {
revert ERC20InvalidWitness();
}
_validatePermitWitness(owner, spender, value, deadline, witness, witnessTypeString, v, r, s);
allowance[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @notice Executes a direct transfer via signature without setting persistent allowance
* @dev Uses witness-based permit with TRANSFER_WITNESS to authorize a one-time transfer
* @param owner The address that owns the tokens and is authorizing the transfer
* @param spender The address that will receive the tokens (typically msg.sender)
* @param value The amount of tokens to transfer (in token's decimal units)
* @param deadline The timestamp after which the permit signature is no longer valid
* @param v The recovery identifier of the signature (27 or 28)
* @param r The first 32 bytes of the signature
* @param s The second 32 bytes of the signature
* @return Always returns true to indicate successful transfer
*/
function permitTransferFrom(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual returns (bool) {
// Use permitWitness to set the allowance
_validatePermitWitness(owner, spender, value, deadline, TRANSFER_WITNESS, v, r, s);
// Execute the transfer
_update(owner, spender, value);
return true;
}
/**
* @notice Executes an external contract call with permit-based authorization
* @dev Sets allowance via witness permit then executes arbitrary call. Witness is derived from call data to
* prevent replay
* @param owner The address that owns the tokens and is authorizing the call
* @param spender The address that will be allowed to spend the tokens (typically the target contract)
* @param value The amount of tokens to approve for spending (in token's decimal units)
* @param deadline The timestamp after which the permit signature is no longer valid
* @param call ContractCall struct containing target, method, and encoded params with owner as first param
* @param v The recovery identifier of the signature (27 or 28)
* @param r The first 32 bytes of the signature
* @param s The second 32 bytes of the signature
* @return The return data from the external contract call
*/
function permitWitnessCall(
address owner,
address spender,
uint256 value,
uint256 deadline,
ContractCall calldata call,
uint8 v,
bytes32 r,
bytes32 s
) public payable returns (bytes memory) {
// Validate inputs before expensive signature operations
if (call.target == address(0) || call.target == address(this)) {
revert ERC20InvalidCallTarget();
}
// Validate method is non-empty
if (bytes(call.method).length == 0) {
revert ERC20InvalidCallData();
}
// CRITICAL: Validate owner is first parameter (32 bytes) in call.params
if (call.params.length < 32 || bytes32(call.params[0:32]) != bytes32(uint256(uint160(owner)))) {
revert ERC20InvalidCallData();
}
// Validate msg.value is sufficient for the native value transfer
if (msg.value < call.nativeValue) {
revert ERC20InvalidCallData();
}
bytes32 witness = keccak256(
abi.encode(
WITNESS_CALL_TYPEHASH,
call.target,
keccak256(bytes(call.method)),
call.nativeValue,
keccak256(call.params)
)
);
// Use permitWitness to set the allowance
permitWitness(owner, spender, value, deadline, witness, WITNESS_CALL_TYPESTRING, v, r, s);
// Building the call data
bytes memory callData = abi.encodePacked(bytes4(keccak256(bytes(call.method))), call.params);
// Execute the external call
(bool success, bytes memory returnData) = call.target.call{ value: msg.value }(callData);
if (!success) {
// Forward the revert reason if available
if (returnData.length > 0) {
assembly {
let returnDataSize := mload(returnData)
revert(add(32, returnData), returnDataSize)
}
} else {
revert ERC20CallFailed();
}
}
return returnData;
}
/*//////////////////////////////////////////////////////////////
PERMIT WITNESS INTERNAL VALIDATION
//////////////////////////////////////////////////////////////*/
/**
* @notice Internal function to validate witness-based permit signatures using default typeHash
* @dev Validates EIP-712 signature for witness permit with PERMIT_WITNESS_TYPEHASH
* @param owner The expected owner address that should have signed the permit
* @param spender The spender address included in the signed message
* @param value The token amount included in the signed message (in token's decimal units)
* @param deadline The deadline timestamp included in the signed message
* @param witness The witness data hash included in the signed message
* @param v The recovery identifier of the signature (27 or 28)
* @param r The first 32 bytes of the signature
* @param s The second 32 bytes of the signature
*/
function _validatePermitWitness(
address owner,
address spender,
uint256 value,
uint256 deadline,
bytes32 witness,
uint8 v,
bytes32 r,
bytes32 s
) internal {
_validatePermitWitnessSignature(owner, spender, value, deadline, witness, PERMIT_WITNESS_TYPEHASH, v, r, s);
}
/**
* @notice Internal function to validate witness-based permit signatures with custom witness type
* @dev Validates EIP-712 signature for witness permit with custom witnessTypeString
* @param owner The expected owner address that should have signed the permit
* @param spender The spender address included in the signed message
* @param value The token amount included in the signed message (in token's decimal units)
* @param deadline The deadline timestamp included in the signed message
* @param witness The witness data hash included in the signed message
* @param witnessTypeString Custom witness type string for EIP-712 type construction
* @param v The recovery identifier of the signature (27 or 28)
* @param r The first 32 bytes of the signature
* @param s The second 32 bytes of the signature
*/
function _validatePermitWitness(
address owner,
address spender,
uint256 value,
uint256 deadline,
bytes32 witness,
string memory witnessTypeString,
uint8 v,
bytes32 r,
bytes32 s
) internal {
// Validate witnessTypeString is not empty and reasonable length
if (bytes(witnessTypeString).length == 0 || bytes(witnessTypeString).length > 1024) {
revert ERC20InvalidWitness();
}
bytes32 typeHash = keccak256(abi.encodePacked(PERMIT_WITNESS_TYPESTRING_STAB, witnessTypeString));
_validatePermitWitnessSignature(owner, spender, value, deadline, witness, typeHash, v, r, s);
}
/**
* @notice Core internal function to validate witness-based permit signatures with a given typeHash
* @dev Validates EIP-712 signature, checking deadline, incrementing nonce, and recovering signer
* @param owner The expected owner address that should have signed the permit
* @param spender The spender address included in the signed message
* @param value The token amount included in the signed message (in token's decimal units)
* @param deadline The deadline timestamp included in the signed message
* @param witness The witness data hash included in the signed message
* @param typeHash The EIP-712 typeHash for the permit structure
* @param v The recovery identifier of the signature (27 or 28)
* @param r The first 32 bytes of the signature
* @param s The second 32 bytes of the signature
*/
function _validatePermitWitnessSignature(
address owner,
address spender,
uint256 value,
uint256 deadline,
bytes32 witness,
bytes32 typeHash,
uint8 v,
bytes32 r,
bytes32 s
) internal {
if (deadline < block.timestamp) {
revert ERC2612ExpiredSignature(deadline);
}
bytes32 hash;
// Unchecked because the only math done is incrementing
// the owner's nonce which cannot realistically overflow.
unchecked {
uint256 nonce = nonces[owner]++;
bytes32 structHash = keccak256(abi.encode(typeHash, owner, spender, value, nonce, deadline, witness));
hash = keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR(), structHash));
}
address recoveredAddress = ecrecover(hash, v, r, s);
if (recoveredAddress == address(0) || recoveredAddress != owner) {
revert ERC2612InvalidSigner(recoveredAddress, owner);
}
}
}
src/telecoin/OftStandard.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import { ILayerZeroEndpointV2 } from "../interfaces/layerzero/ILayerZeroEndpointV2.sol";
import { IOFT, OFTFeeDetail, OFTLimit, OFTReceipt, SendParam } from "../interfaces/layerzero/IOFT.sol";
import { IPrintrTeleport } from "../interfaces/printr/IPrintrTeleport.sol";
/**
* @title OftStandard
* @notice Abstract contract implementing LayerZero OFT standard for Telecoins
* @dev Delegates to existing teleport infrastructure under the hood
* @dev Expects inheriting contracts to provide _lzTeleport and quoteTeleportFee implementations from Telecoin
*/
abstract contract OftStandard is IOFT {
/**
* @notice Retrieves interfaceID and version of the OFT
* @return interfaceId The interface ID (0x02e49c2c)
* @return version The version (1)
*/
function oftVersion() external pure returns (bytes4 interfaceId, uint64 version) {
return (0x02e49c2c, 1);
}
/**
* @notice Retrieves the address of the token associated with the OFT
* @return token The address of the ERC20 token implementation (this contract)
*/
function token() external view returns (address) {
return address(this);
}
/**
* @notice Indicates whether the OFT contract requires approval of the 'token()' to send
* @return requiresApproval False, as the token itself implements the OFT interface
*/
function approvalRequired() external pure returns (bool) {
return false;
}
/**
* @notice Retrieves the shared decimals of the OFT
* @return sharedDecimals The shared decimals (9)
*/
function sharedDecimals() external pure returns (uint8) {
return 9;
}
/**
* @notice Provides a quote for OFT-related operations
* @param _sendParam The parameters for the send operation
* @return limit The OFT limit information
* @return oftFeeDetails The details of OFT fees
* @return receipt The OFT receipt information
*/
function quoteOFT(
SendParam calldata _sendParam
) external returns (OFTLimit memory limit, OFTFeeDetail[] memory oftFeeDetails, OFTReceipt memory receipt) {
// Convert SendParam to TeleportParams
IPrintrTeleport.TeleportParams memory params = _sendParamToTeleportParams(_sendParam);
// Get fee from PrintrTeleport
(uint256 totalNativeFee,,, uint256 bridgeFee) = _quoteTeleportFee(params);
// Calculate protocol fee
uint256 protocolFee = totalNativeFee - bridgeFee;
// Return limits (no hard limits on telecoin transfers)
limit = OFTLimit({ minAmountLD: 0, maxAmountLD: type(uint256).max });
// Return fee details array with protocol fee and bridge fee
oftFeeDetails = new OFTFeeDetail[](2);
oftFeeDetails[0] = OFTFeeDetail({ feeAmountLD: int256(protocolFee), description: "Protocol Fee" });
oftFeeDetails[1] = OFTFeeDetail({ feeAmountLD: int256(bridgeFee), description: "Bridge Fee" });
// Return receipt (1:1 transfer, no conversion)
receipt = OFTReceipt({ amountSentLD: _sendParam.amountLD, amountReceivedLD: _sendParam.amountLD });
}
/**
* @notice Provides a quote for the send() operation
* @param _sendParam The parameters for the send() operation
* @return fee The calculated LayerZero messaging fee
*/
function quoteSend(
SendParam calldata _sendParam,
bool /* _payInLzToken */
) external returns (ILayerZeroEndpointV2.MessagingFee memory fee) {
// Convert SendParam to TeleportParams
IPrintrTeleport.TeleportParams memory params = _sendParamToTeleportParams(_sendParam);
// Get fee from PrintrTeleport
(uint256 totalNativeFee,,,) = _quoteTeleportFee(params);
// Return MessagingFee (we don't support LZ token payments)
fee = ILayerZeroEndpointV2.MessagingFee({ nativeFee: totalNativeFee, lzTokenFee: 0 });
}
/**
* @notice Executes the send() operation
* @param _sendParam The parameters for the send operation
* @param _fee The fee information supplied by the caller
* @return receipt The LayerZero messaging receipt
* @return oftReceipt The OFT receipt information
*/
function send(
SendParam calldata _sendParam,
ILayerZeroEndpointV2.MessagingFee calldata _fee,
address /* _refundAddress */
) external payable returns (ILayerZeroEndpointV2.MessagingReceipt memory receipt, OFTReceipt memory oftReceipt) {
// Check slippage
if (_sendParam.amountLD < _sendParam.minAmountLD) {
revert SlippageExceeded(_sendParam.amountLD, _sendParam.minAmountLD);
}
// Convert SendParam to TeleportParams
IPrintrTeleport.TeleportParams memory params = _sendParamToTeleportParams(_sendParam);
// Call the LayerZero teleport function
bytes memory data = _lzTeleport(msg.sender, params);
// Check if we received actual LayerZero receipt data
if (data.length > 0) {
// Decode the actual LayerZero MessagingReceipt
receipt = abi.decode(data, (ILayerZeroEndpointV2.MessagingReceipt));
} else {
// Create synthetic receipt until LZ channels return receipt
// Create a pseudo-GUID from sender and params
bytes32 guid = keccak256(abi.encodePacked(msg.sender, _sendParam.dstEid, _sendParam.amountLD));
// Return synthetic receipt
receipt = ILayerZeroEndpointV2.MessagingReceipt({
guid: guid, nonce: uint64(block.timestamp), fee: ILayerZeroEndpointV2.MessagingFee(_fee.nativeFee, 0)
});
}
// Emit OFTSent event
emit OFTSent(receipt.guid, _sendParam.dstEid, msg.sender, _sendParam.amountLD, _sendParam.amountLD);
// Return OFT receipt
oftReceipt = OFTReceipt({ amountSentLD: _sendParam.amountLD, amountReceivedLD: _sendParam.amountLD });
}
function _quoteTeleportFee(
IPrintrTeleport.TeleportParams memory params
) internal virtual returns (uint256 totalNativeFee, uint256 basePairFee, address basePair, uint256 bridgeFee);
/**
* @notice Internal abstract function for teleporting tokens
* @dev Must be implemented by Telecoin to call its teleport() function
* @param params The teleport parameters
*/
function _lzTeleport(
address from,
IPrintrTeleport.TeleportParams memory params
) internal virtual returns (bytes memory receipt);
/**
* @notice Converts SendParam to TeleportParams
* @param _sendParam The OFT SendParam struct
* @return params The equivalent TeleportParams struct
*/
function _sendParamToTeleportParams(
SendParam calldata _sendParam
) internal pure returns (IPrintrTeleport.TeleportParams memory params) {
// Map endpoint ID to chain name
string memory destChain = _eidToString(_sendParam.dstEid);
// Determine protocol based on extraOptions (default to LZ_FAST)
IPrintrTeleport.TeleportProtocol protocol = _parseProtocolFromOptions(_sendParam.extraOptions);
// Convert recipient from bytes32 to bytes
bytes memory destAddress = abi.encodePacked(_sendParam.to);
// Combine composeMsg and oftCmd into metadata if present
bytes memory metadata;
if (_sendParam.composeMsg.length > 0 || _sendParam.oftCmd.length > 0) {
metadata = abi.encode(_sendParam.composeMsg, _sendParam.oftCmd);
}
params = IPrintrTeleport.TeleportParams({
destChain: destChain,
destAddress: destAddress,
amount: _sendParam.amountLD,
metadata: metadata,
protocol: protocol
});
}
/**
* @notice Converts LayerZero endpoint ID to string representation
* @param eid Endpoint ID
* @return eidString The endpoint ID as a string (e.g., "30101")
*/
function _eidToString(
uint32 eid
) internal pure returns (string memory eidString) {
// Convert uint32 to string
if (eid == 0) {
return "0";
}
uint32 temp = eid;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (eid != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint32(eid % 10)));
eid /= 10;
}
return string(buffer);
}
/**
* @notice Parses LayerZero extraOptions to determine protocol
* @param extraOptions The extra options bytes (can encode security level)
* @return protocol The teleport protocol to use
*/
function _parseProtocolFromOptions(
bytes calldata extraOptions
) internal pure returns (IPrintrTeleport.TeleportProtocol protocol) {
// Default to LZ_FAST if no options provided
if (extraOptions.length == 0) {
return IPrintrTeleport.TeleportProtocol.LZ_FAST;
}
// Parse first byte as security level indicator if present
// 1 = LZ_FAST, 2 = LZ_SECURE, 3 = LZ_SLOW
uint8 securityLevel = uint8(extraOptions[0]);
if (securityLevel == 1) {
return IPrintrTeleport.TeleportProtocol.LZ_FAST;
} else if (securityLevel == 2) {
return IPrintrTeleport.TeleportProtocol.LZ_SECURE;
} else if (securityLevel == 3) {
return IPrintrTeleport.TeleportProtocol.LZ_SLOW;
}
// Default to LZ_FAST for any other value
return IPrintrTeleport.TeleportProtocol.LZ_FAST;
}
}
src/telecoin/Printed.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import { IPrinted } from "../interfaces/telecoin/IPrinted.sol";
import { ITelecoin } from "../interfaces/telecoin/ITelecoin.sol";
import { TeleportingTelecoin } from "./Teleporting.sol";
/**
* @title PrintrTelecoin
* @notice Implementation of a Telecoin with teleport capabilities and interchain functionality
* @dev Extends Telecoin to provide cross-chain functionality via LayerZero
*/
abstract contract Printed is IPrinted {
/// @notice The teleport type of this Telecoin (Main uses lock/unlock, Teleporting uses mint/burn)
TeleportType public immutable isTeleporting;
/// @notice Address of the Printr contract that created this token
address private immutable printr;
/**
* @notice Enum representing the different states of curve completion
* @dev Used to track the progression of the bonding curve
* @custom:value NotInitialized - Initial state before any completion actions
* @custom:value Restricted - State where transfers are restricted to a specific pool
* @custom:value Completed - Final state where curve is completed and unrestricted
*/
enum CompletionState {
NotInitialized, // Not yet initialized
Restricted, // Restricted to specific pool
Completed // Curve completed
}
/**
* @notice Struct to pack pool address and state in single storage slot
* @dev Packs address (160 bits) and state (8 bits) into 256 bits for gas optimization
* @param pool The address of the liquidity pool (160 bits)
* @param state The current completion state of the curve (8 bits)
*/
struct CompletionStatus {
address pool; // Pool address (160 bits)
CompletionState state; // Completion state (8 bits)
}
/// @notice Tracks the completion status and restricted pool address
CompletionStatus public completionStatus;
/**
* @notice Initializes the token with its basic parameters
* @param _printr Address of the Printr contract that created this token
* @param _treasury Address to receive the initial token supply
* @param _initialSupply The initial supply to mint to treasury
* @param _teleportType The teleport type of this telecoin (Main, Teleporting, or Legacy variants)
*/
constructor(
address _printr,
address _treasury,
uint256 _initialSupply,
TeleportType _teleportType
) {
printr = _printr;
isTeleporting = _teleportType;
// Mint the chain total supply directly to the treasury
_update(address(0), _treasury, _initialSupply);
}
/**
* @notice Sets the restricted pool address during curve initialization
* @dev Can only be called by Printr before completion. Updates the completion status
* to restrict transfers to the specified pool address until curve is marked complete.
* Uses atomic storage writes for gas efficiency.
* @param poolAddress The pool address to restrict transfers to during curve completion phase
* @custom:throws UnauthorizedAccount if caller is not Printr or curve is already complete
* @custom:throws ZeroAddress if pool address is zero
*/
function setRestrictedPool(
address poolAddress
) external {
if (poolAddress == address(0)) {
revert ITelecoin.ZeroAddress();
}
if (msg.sender != printr || completionStatus.state == CompletionState.Completed) {
revert ITelecoin.UnauthorizedAccount(msg.sender);
}
// Write the entire struct atomically in a single SSTORE
completionStatus = CompletionStatus({ pool: poolAddress, state: CompletionState.Restricted });
}
/**
* @notice Marks the bonding curve as completed, removing transfer restrictions
* @dev Can only be called by Printr when curve is not already completed.
* Clears the restricted pool address and sets state to Completed, allowing
* unrestricted token transfers. Uses atomic storage writes for gas efficiency.
* @custom:throws UnauthorizedAccount if caller is not Printr or curve is already completed
*/
function markCurveComplete() external {
if (msg.sender != printr || completionStatus.state == CompletionState.Completed) {
revert ITelecoin.UnauthorizedAccount(msg.sender);
}
// Write the entire struct atomically in a single SSTORE
// Clear pool address when marking complete
completionStatus = CompletionStatus({ pool: address(0), state: CompletionState.Completed });
}
/**
* @notice Internal hook to handle token transfers
* @dev Prevents adding tokens to liquidity pool before curve completion
* param from Address tokens are transferred from
* @param to Address tokens are transferred to
* param value Amount of tokens being transferred
* @custom:dev Inheriting contract must call super._update()
* @custom:throws CurveIsNotComplete if attempting to add to pool before completion
*/
function _update(
address,
/*from*/
address to,
uint256 /*value*/
) internal virtual {
// Read entire struct from storage once
CompletionStatus memory status = completionStatus;
// Disable adding token to liquidity pool before completion
if (status.state == CompletionState.Restricted && to == status.pool) {
revert CurveIsNotComplete();
}
// NOTE: Inheriting contract must call ERC20._update()
}
}
src/telecoin/Telecoin.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { IPrintrTeleport } from "../interfaces/printr/IPrintrTeleport.sol";
import { ITelecoin } from "../interfaces/telecoin/ITelecoin.sol";
import { ERC20 } from "./ERC20.sol";
import { ERC20Witness } from "./ERC20Witness.sol";
import { OftStandard } from "./OftStandard.sol";
/**
* @title Telecoin
* @notice Base ERC20 token with teleport capabilities and witness permit functionality
* @dev Extends ERC20Witness and OftStandard to provide cross-chain teleport functionality via LayerZero
*/
contract Telecoin is ITelecoin, ERC20Witness, OftStandard {
/// @notice Base URL for the off-chain metadata JSON, keyed by telecoinId
string private constant METADATA_BASE_URL = "https://cdn.printr.money/t/";
/// @notice Trailing path appended after the telecoinId in the metadata URL
string private constant METADATA_SUFFIX = "/media/icon";
/// @notice Printr Telecoin ID
bytes32 public immutable telecoinId;
/// @notice Maximum total supply of the token
uint256 public immutable maxSupply;
/// @notice Address of the Printr contract that created this token
address public immutable printr;
/**
* @notice Constructor for Telecoin
* @param params Deployment parameters struct containing token configuration
*/
constructor(
TelecoinDeployParams memory params
) ERC20Witness(params.name, params.symbol, 18) {
if (params.printr == address(0)) {
revert ZeroAddress();
}
telecoinId = params.telecoinId;
maxSupply = params.maxSupply;
printr = params.printr;
}
/**
* @notice Quotes the total teleport fee for any protocol (external interface)
* @param params The teleport parameters struct (includes protocol)
* @return totalNativeFee The total fee in native currency (protocol fee + bridge fee)
* @return basePairFee The fee in base pair tokens (0 if base pair is native)
* @return basePair The base pair address (address(0) if native)
* @return bridgeFee The bridge-specific gas fee (LZ messaging fee)
*/
function quoteTeleportFee(
IPrintrTeleport.TeleportParams memory params
)
public
override(ITelecoin)
returns (uint256 totalNativeFee, uint256 basePairFee, address basePair, uint256 bridgeFee)
{
return _quoteTeleportFee(params);
}
/**
* @notice Teleports tokens from sender to a destination chain
* @dev Routes to LayerZero based on params.protocol. ITS is deprecated.
* @param params The teleport parameters struct (includes protocol)
*/
function teleport(
IPrintrTeleport.TeleportParams calldata params
) public payable virtual {
if (params.protocol == IPrintrTeleport.TeleportProtocol.UNSPECIFIED) {
revert InvalidProtocol();
}
if (params.protocol == IPrintrTeleport.TeleportProtocol.ITS) {
revert ITSDeprecated();
}
_lzTeleport(msg.sender, params);
}
/**
* @notice Teleports tokens from a specified address to a destination chain
* @dev Routes to LayerZero based on params.protocol. ITS is deprecated.
* @param from The sender of the tokens (must have approved msg.sender)
* @param params The teleport parameters struct (includes protocol)
*/
function teleportFrom(
address from,
IPrintrTeleport.TeleportParams calldata params
) public payable virtual {
if (params.protocol == IPrintrTeleport.TeleportProtocol.UNSPECIFIED) {
revert InvalidProtocol();
}
if (params.protocol == IPrintrTeleport.TeleportProtocol.ITS) {
revert ITSDeprecated();
}
_lzTeleport(from, params);
}
/**
* @notice Returns the URL of the off-chain metadata JSON for this telecoin
* @dev Built from telecoinId so the URL is stable across chains and free of storage cost.
* Format: https://cdn.printr.money/t/<telecoinId>/media/icon
* @return URL of the metadata JSON
*/
function contractURI() public view virtual returns (string memory) {
return string.concat(METADATA_BASE_URL, Strings.toHexString(uint256(telecoinId), 32), METADATA_SUFFIX);
}
/**
* @notice Returns the URL of the off-chain metadata JSON for this telecoin
* @dev Alias of contractURI() that mirrors Solana/Metaplex naming.
* @return URL of the metadata JSON (identical to contractURI())
*/
function metadataURI() external view virtual returns (string memory) {
return contractURI();
}
/**
* @notice Internal function to decrease allowance
* @dev Preserves infinite allowance when value is max uint256
* @param sender Address owning the tokens
* @param spender Address spending the tokens
* @param value Amount to decrease allowance by
*/
function _decreaseAllowance(
address sender,
address spender,
uint256 value
) internal virtual {
uint256 _allowance = allowance[sender][spender];
if (_allowance < value) {
revert ERC20InsufficientAllowance(spender, _allowance, value);
}
if (_allowance != type(uint256).max) {
allowance[sender][spender] = _allowance - value;
}
}
/**
* @notice Internal fee quote implementation for OftStandard
* @dev Overrides OftStandard's virtual function, delegates to PrintrTeleport
* @param params The teleport parameters struct (includes protocol)
* @return totalNativeFee The total fee in native currency (protocol fee + bridge fee)
* @return basePairFee The fee in base pair tokens (0 if base pair is native)
* @return basePair The base pair address (address(0) if native)
* @return bridgeFee The bridge-specific gas fee (LZ messaging fee)
*/
function _quoteTeleportFee(
IPrintrTeleport.TeleportParams memory params
) internal override returns (uint256 totalNativeFee, uint256 basePairFee, address basePair, uint256 bridgeFee) {
return IPrintrTeleport(printr).quoteTeleportFee(address(this), params);
}
/**
* @notice Internal LayerZero teleport execution logic
* @dev Handles protocol routing for teleport(), teleportFrom(), and OftStandard's send()
* @param from The address sending the tokens
* @param params The teleport parameters (memory to support both calldata and memory callers)
*/
function _lzTeleport(
address from,
IPrintrTeleport.TeleportParams memory params
) internal override returns (bytes memory receipt) {
// For LayerZero protocols, consume allowance if sender is not msg.sender
// This prevents unauthorized teleportFrom calls from consuming other users' approvals
if (from != msg.sender) {
_decreaseAllowance(from, msg.sender, params.amount);
}
// For LZ protocols
if (
params.protocol == IPrintrTeleport.TeleportProtocol.LZ_FAST
|| params.protocol == IPrintrTeleport.TeleportProtocol.LZ_SECURE
|| params.protocol == IPrintrTeleport.TeleportProtocol.LZ_SLOW
) {
// Use LayerZero for teleportation via PrintrTeleport
return IPrintrTeleport(printr).transmitLzSend{ value: msg.value }(telecoinId, from, params);
}
revert InvalidProtocol();
}
}
src/telecoin/Teleporting.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import { ITeleportingTelecoin } from "../interfaces/telecoin/ITeleporting.sol";
import { Telecoin } from "./Telecoin.sol";
/**
* @title Teleporting
* @notice Base ERC20 token with teleport capabilities (mint/burn)
* @dev Extends Telecoin to provide cross-chain teleport functionality via LayerZero
*/
contract TeleportingTelecoin is ITeleportingTelecoin, Telecoin {
/**
* @notice Constructor for TeleportingTelecoin
* @param params Deployment parameters struct containing token configuration
*/
constructor(
TelecoinDeployParams memory params
) Telecoin(params) { }
/**
* @notice Teleports tokens into existence for cross-chain transfers
* @dev Can only be called by Printr
* @param to Address to receive the teleported tokens
* @param value Amount of tokens to teleport in
*/
function teleportIn(
address to,
uint256 value
) public {
if (msg.sender != printr) {
revert UnauthorizedAccount(msg.sender);
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
emit TeleportIn(telecoinId, to, value);
_update(address(0), to, value);
}
/**
* @notice Teleports tokens out of existence for cross-chain transfers
* @dev Can only be called by Printr
* @param from Address to teleport tokens from
* @param value Amount of tokens to teleport out
*/
function teleportOut(
address from,
uint256 value
) public {
if (msg.sender != printr) {
revert UnauthorizedAccount(msg.sender);
}
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
emit TeleportOut(telecoinId, from, value);
_decreaseAllowance(from, msg.sender, value);
_update(from, address(0), value);
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 2000,
"enabled": true
},
"evmVersion": "prague",
"remappings": [
"forge-std/=lib/forge-std/src/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"ds-test/=lib/openzeppelin-contracts-upgradeable/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.