Skip to main content
Smart contract interfaces and function documentation for TED Protocol.

Core Interfaces

IFXSwap

The main swap interface for stablecoin exchanges. The swap() function executes a token swap, taking the input token address, output token address, input amount, minimum acceptable output, and deadline timestamp. It returns the actual output amount received. The getQuote() function provides swap quotes, returning expected output amount, price impact in basis points, the DEX route, and estimated gas.
interface IFXSwap {
    function swap(
        address tokenIn,
        address tokenOut,
        uint256 amountIn,
        uint256 minAmountOut,
        uint256 deadline
    ) external returns (uint256 amountOut);

    function getQuote(
        address tokenIn,
        address tokenOut,
        uint256 amountIn
    ) external view returns (Quote memory quote);

    struct Quote {
        uint256 amountOut;
        uint256 priceImpact;
        address[] route;
        uint256 gasEstimate;
    }
}

ICrossChainSwap

Interface for cross-chain stablecoin swaps. The crossChainSwap() function executes a cross-chain swap and returns a bridge message identifier for tracking. The estimateFees() function returns the native token fee and bridge protocol fee.
interface ICrossChainSwap {
    function crossChainSwap(
        CrossChainParams calldata params
    ) external payable returns (bytes32 messageId);

    function estimateFees(
        CrossChainParams calldata params
    ) external view returns (uint256 nativeFee, uint256 bridgeFee);

    struct CrossChainParams {
        address tokenIn;
        address tokenOut;
        uint256 amountIn;
        uint256 minAmountOut;
        uint32 srcChainId;
        uint32 dstChainId;
        address recipient;
        uint256 deadline;
        bytes bridgeOptions;
    }
}

Bridge Interfaces

ICCTP

Circle CCTP integration for USDC transfers. The sendUSDC() function sends USDC to another chain via CCTP, returning a message nonce for tracking. The receiveUSDC() function receives USDC from another chain using the CCTP message and Circle attestation.
interface ICCTP {
    function sendUSDC(
        uint256 amount,
        uint32 dstChainId,
        bytes32 recipient
    ) external returns (uint64 nonce);

    function receiveUSDC(
        bytes calldata message,
        bytes calldata attestation
    ) external;
}

ILayerZeroOFT

LayerZero OFT interface for TEDP transfers. The send() function transfers tokens to another chain, requiring the destination endpoint ID, recipient address (as bytes32), amount in local decimals, and LayerZero messaging options. The quoteSend() function returns the native token fee for the transfer.
interface ILayerZeroOFT {
    function send(
        uint32 _dstEid,
        bytes32 _to,
        uint256 _amountLD,
        bytes calldata _options
    ) external payable;

    function quoteSend(
        uint32 _dstEid,
        bytes32 _to,
        uint256 _amountLD,
        bytes calldata _options
    ) external view returns (uint256 nativeFee);
}

Admin Interfaces

IDiamondCut

Interface for upgrading diamond facets. The diamondCut() function adds, replaces, or removes facet functions. Each FacetCut specifies a facet address, the action (Add, Replace, or Remove), and the function selectors affected.
interface IDiamondCut {
    enum FacetCutAction { Add, Replace, Remove }

    struct FacetCut {
        address facetAddress;
        FacetCutAction action;
        bytes4[] functionSelectors;
    }

    function diamondCut(
        FacetCut[] calldata _diamondCut,
        address _init,
        bytes calldata _calldata
    ) external;
}

IAdmin

Protocol administration interface. Functions include pause() to stop all operations, unpause() to resume, setProtocolFee() to update fees in basis points (max 100 = 1%), and addSupportedToken()/removeSupportedToken() to manage supported tokens.
interface IAdmin {
    function pause() external;
    function unpause() external;
    function setProtocolFee(uint256 _fee) external;
    function addSupportedToken(address _token) external;
    function removeSupportedToken(address _token) external;
}

Events

Swap events notify when swaps execute. The Swap event includes sender, input/output tokens, amounts, and the DEX used. The CrossChainSwapInitiated event includes the message ID, sender, chain IDs, tokens, and input amount. The CrossChainSwapCompleted event confirms completion with the message ID, recipient, output token, and amount. Admin events include Paused and Unpaused (with admin address) and FeeUpdated (with old and new fee values).

Error Codes

TED Protocol uses custom errors for gas-efficient error handling:
  • InsufficientOutput — Output amount less than minimum specified
  • DeadlineExpired — Transaction deadline has passed
  • UnsupportedToken — Token not supported by the protocol
  • UnsupportedChain — Chain ID not supported
  • ProtocolPaused — Protocol operations are paused
  • InsufficientFee — Native token fee provided is too low
  • InvalidRoute — Swap route is invalid
  • ZeroAmount — Amount cannot be zero
  • ZeroAddress — Address cannot be zero

Usage Examples

Basic swap on Ethereum:
const tedProtocol = new ethers.Contract(DIAMOND_ADDRESS, ABI, signer);

// Get quote
const quote = await tedProtocol.getQuote(
    USDT_ADDRESS,
    USDC_ADDRESS,
    ethers.parseUnits("1000", 6)
);

console.log("Expected output:", quote.amountOut);
console.log("Price impact:", quote.priceImpact, "bps");

// Execute swap with 1% slippage
const tx = await tedProtocol.swap(
    USDT_ADDRESS,
    USDC_ADDRESS,
    ethers.parseUnits("1000", 6),
    quote.amountOut * 99n / 100n,
    Math.floor(Date.now() / 1000) + 600
);

await tx.wait();
Cross-chain swap from Ethereum to Arbitrum:
const [nativeFee, bridgeFee] = await tedProtocol.estimateFees({
    tokenIn: USDT_ADDRESS,
    tokenOut: USDC_ADDRESS,
    amountIn: ethers.parseUnits("1000", 6),
    minAmountOut: ethers.parseUnits("990", 6),
    srcChainId: 1,
    dstChainId: 42161,
    recipient: userAddress,
    deadline: Math.floor(Date.now() / 1000) + 3600,
    bridgeOptions: "0x"
});

const tx = await tedProtocol.crossChainSwap(
    {
        tokenIn: USDT_ADDRESS,
        tokenOut: USDC_ADDRESS,
        amountIn: ethers.parseUnits("1000", 6),
        minAmountOut: ethers.parseUnits("990", 6),
        srcChainId: 1,
        dstChainId: 42161,
        recipient: userAddress,
        deadline: Math.floor(Date.now() / 1000) + 3600,
        bridgeOptions: "0x"
    },
    { value: nativeFee }
);

await tx.wait();
TEDP transfer using LayerZero OFT:
const tedpToken = new ethers.Contract(TEDP_ADDRESS, OFT_ABI, signer);

// Convert address to bytes32
const recipientBytes32 = ethers.zeroPadValue(recipientAddress, 32);

// Quote fee
const fee = await tedpToken.quoteSend(
    30110,  // Arbitrum endpoint ID
    recipientBytes32,
    ethers.parseUnits("1000", 18),
    "0x"
);

// Send TEDP cross-chain
const tx = await tedpToken.send(
    30110,
    recipientBytes32,
    ethers.parseUnits("1000", 18),
    "0x",
    { value: fee }
);

await tx.wait();