메인 콘텐츠로 건너뛰기

코어 인터페이스

IFXSwap

스테이블코인 교환을 위한 메인 스왑 인터페이스입니다.
  • swap() — 토큰 스왑 실행, 실제 수령 금액 반환
  • getQuote() — 예상 출력, 가격 영향, 라우트, 가스 추정 반환
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

크로스체인 스테이블코인 스왑 인터페이스입니다.
  • crossChainSwap() — 크로스체인 스왑 실행, 브릿지 메시지 ID 반환
  • estimateFees() — 네이티브 토큰 수수료와 브릿지 수수료 반환
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;
    }
}

브릿지 인터페이스

ICCTP

USDC 전송을 위한 Circle CCTP 통합입니다.
  • sendUSDC() — CCTP를 통해 USDC 전송, 메시지 논스 반환
  • receiveUSDC() — CCTP 메시지와 Circle 인증으로 USDC 수신
interface ICCTP {
    function sendUSDC(
        uint256 amount,
        uint32 dstChainId,
        bytes32 recipient
    ) external returns (uint64 nonce);

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

ILayerZeroOFT

TEDP 전송을 위한 LayerZero OFT 인터페이스입니다.
  • send() — 다른 체인으로 토큰 전송
  • quoteSend() — 전송에 필요한 네이티브 토큰 수수료 반환
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 인터페이스

IDiamondCut

Diamond facet 업그레이드 인터페이스입니다.
  • diamondCut() — facet 함수 추가, 교체 또는 제거
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

프로토콜 관리 인터페이스입니다.
  • pause() — 모든 작업 중지
  • unpause() — 작업 재개
  • setProtocolFee() — 수수료 업데이트 (최대 100 = 1%)
  • addSupportedToken() / removeSupportedToken() — 지원 토큰 관리
interface IAdmin {
    function pause() external;
    function unpause() external;
    function setProtocolFee(uint256 _fee) external;
    function addSupportedToken(address _token) external;
    function removeSupportedToken(address _token) external;
}

이벤트

스왑 이벤트

이벤트설명
Swap발신자, 입력/출력 토큰, 금액, 사용된 DEX
CrossChainSwapInitiated메시지 ID, 발신자, 체인 ID, 토큰, 입력 금액
CrossChainSwapCompleted메시지 ID, 수신자, 출력 토큰, 금액

Admin 이벤트

이벤트설명
Paused관리자 주소
Unpaused관리자 주소
FeeUpdated이전 및 새 수수료 값

에러 코드

TED Protocol은 가스 효율적인 에러 처리를 위해 커스텀 에러를 사용합니다.
에러설명
InsufficientOutput출력 금액이 지정된 최소값 미만
DeadlineExpired트랜잭션 유효 기간 경과
UnsupportedToken프로토콜에서 지원하지 않는 토큰
UnsupportedChain지원하지 않는 체인 ID
ProtocolPaused프로토콜 작업이 일시정지됨
InsufficientFee제공된 네이티브 토큰 수수료가 너무 낮음
InvalidRoute스왑 라우트가 유효하지 않음
ZeroAmount금액이 0일 수 없음
ZeroAddress주소가 0일 수 없음

사용 예시

기본 스왑

const tedProtocol = new ethers.Contract(DIAMOND_ADDRESS, ABI, signer);

// 견적 조회
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");

// 1% 슬리피지로 스왑 실행
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();

크로스체인 스왑

Ethereum에서 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 전송

LayerZero OFT 사용:
const tedpToken = new ethers.Contract(TEDP_ADDRESS, OFT_ABI, signer);

// 주소를 bytes32로 변환
const recipientBytes32 = ethers.zeroPadValue(recipientAddress, 32);

// 수수료 견적
const fee = await tedpToken.quoteSend(
    30110,  // Arbitrum 엔드포인트 ID
    recipientBytes32,
    ethers.parseUnits("1000", 18),
    "0x"
);

// TEDP 크로스체인 전송
const tx = await tedpToken.send(
    30110,
    recipientBytes32,
    ethers.parseUnits("1000", 18),
    "0x",
    { value: fee }
);

await tx.wait();