📖
KLAYLibrary
  • Welcome to KLAYLibrary
    • 수수료
    • 용어 설명
  • Features
    • Fully Decentralized
    • 자동화된 유동성 공급자
    • Referral Program
    • Flash Settlement
  • Tokenomics
    • Rationale
    • Overview
    • Rules
      • FAQ
    • Initial Launch Plan
  • Use Guides
    • 주문 하기
      • 지정가 주문
      • 시장가 주문
      • 지정가 주문의 옵션
    • 수동 Claim
    • 인센티브 수령
  • Trading Pairs
    • Tick Size
  • Contracts
    • Library
    • OrderBookViewer
    • TradeRecorder
  • Disclaimer
    • 위험 및 보안
    • 이용 약관
  • Contact Us
  • Link
    • KLAYLibrary
Powered by GitBook
On this page
  • Overview
  • 주문 제출 시 설정 옵션
  • Address on Cypress
  • Functions
  1. Contracts

Library

주문을 체출하고 거래를 체결하는 컨트랙트 입니다

PreviousContractsNextOrderBookViewer

Last updated 1 year ago

Overview

Library 컨트랙트는 사용자의 주문을 블록체인 네트워크에 제출하고, 해당 주문이 오더북에서 거래 상대방을 찾아 체결되면 스마트 컨트랙트가 자동으로 거래를 실행합니다. 이러한 방식으로 주문과 거래 과정이 효율적으로 이루어질 수 있습니다.

Library에 등록된 각각의 트레이딩 페어는 고유한 식별자인 ID로 구분됩니다. 각 트레이딩 페어는 매도 오더북(Sell Order Book, SOB)과 매수 오더북(Buy Order Book, BOB)으로 구성되어뉘있습니다. 이 오더북은 주문이 제출되고 체결될 때 사용되는 중요한 구성 요소입니다.

주문 제출 시 설정 옵션

수수료 옵션

수수료 지급 자산 선택

Taker 는 feePayment 변수를 설정하여 수수료로 지급하는 자산을 선택할 수 있습니다. 만약 feePayment 가 true이면 거래 후에 수령한 자산으로 수수료 지급하며, 매도 주문의 경우 quote 자산, 매수 주문의 경우 base 자산이 됩니다. 반면에 feePayment 가 false이면 거래 시에 지불하는 자산으로 수수료를 지불하며, 매도 주문의 경우 base 자산, 매수 주문의 경우 quote 자산이 됩니다.

지정가 주문의 옵션

Address on Cypress

0x151C663c338a633B27817337bc7884cA9cE0EA55

Functions

PriceFilter

struct PriceFilter {
    uint256 tickSize;
}

Parameters
    uint256 tickSize: the step to increase/reduce order price

LotSizeFilter

struct LotSizeFilter {
    uint256 minOrderQty;
    uint256 maxOrderQty;
    uint256 stepSize;
}

Parameters
    uint256 minOrderQty: maximum order quantity
    uint256 maxOrderQty: minimum order quantity
    uint256 stepSize: The step to increase/reduce order quantity

InstrumentInfo

struct InstrumentInfo {
    string symbol;
    address baseAsset;
    uint8 baseAssetDecimals;
    address quoteAsset;
    uint8 quoteAssetDecimals;
    bool status;
    PriceFilter priceFilter;
    LotSizeFilter lotSizeFilter;
}

Parameters
    string symbol: symbol name
    address baseAsset: the address of the base asset
    uint8 baseAssetDecimals: the decimals of the base asset
    address quoteAsset: the address of the quote asset
    uint8 quoteAssetDecimals: the decimals of the quote asset
    bool status: [false:non-operational, true:operational]
    PriceFilter priceFilter: price attributes
    LotSizeFilter lotSizeFilter: size attributes

TradeOrder

struct TradeOrder {
    uint256 pid;
    uint256 price;
    uint256 orderQty;
    uint256 quoteOrderQty;
    bool side;
    bool feePayment;
    uint8 orderType;
    uint8 timeInForce;
}

Parameters
    uint256 pid: trading pair id
    uint256 price: order price
    uint256 orderQty: order quantity
    uint256 quoteOrderQty: quote order quantity
    bool side: [false:buy, true:sell]
    bool feePayment: [false:fee paid in the asset before conversion, true:fee paid in the asset after conversion]
    uint8 orderType: [0:market, 1:limit]    
    uint8 timeInForce: [0:GTC, 1:IOC, 2:FOK, 3:PlaceOnly]

getPairCount

function getPairCount() public view returns (uint256)

Description
    라이브러리에 등록된 트레이딩 페어의 수를 조회한다

Parameters

Return
    uint256 : 트레이딩 페어의 수

getOrderBooks

function getOrderBooks(uint256 sId) external view returns (address sob, address bob)

Description
    라이브러리에 등록된 오더북의 컨트랙트 주소를 조회한다

Parameters
    uint256 id : 트레이딩 페어의 id

Return
    address sob : 매도 오더북의 주소
    address bob : 매수 오더북의 주소

getPair

function getPair(uint256 id) external view returns(address base, uint8 dBase, address quote, uint8 dQuote)

Description
    트레이딩 페어의 기본정보를 조회한다

Parameters
    uint256 id : 트레이딩 페어의 id

Return
    address base : base asset 의 주소
    uint8 dBase : base asset 의 소수점 자릿수
    address quote : quote asset 의 주소
    uint8 dQuote : quote asset 의 소수점 자릿수

getInstrumentInfo

function getInstrumentInfo(uint256 pid) external view returns (InstrumentInfo memory);

Description
    트레이딩 페어의 설정값을 조회한다

Parameters
    uint256 pid : 트레이딩 페어의 id

Return
    InstrumentInfo: 해당 트레이딩 페어의 설정 값

getInstrumentsInfo

function getInstrumentsInfo() external view returns (InstrumentInfo[] memory)

Description
    모든 트레이딩 페어의 설정 값을 조회한다

Parameters

Return
    InstrumentInfo[]: 모든 트레이딩 페어의 설정 값

getMakerIncentive

function getMakerIncentive(address user) external view returns (address[] memory tokens, uint256[] memory amounts, uint256[] memory claimed)

Description
    사용자가 수령할 수 있는 메이커 인센티브를 조회한다

Parameters
    address user : 사용자의 주소

Return
    address[] memory tokens : 토큰의 주소
    uint256[] memory amounts : 수령할 수 있는 메이커 인센티브의 수량
    uint256[] memory claimed : 기 수령한 메이커 인센티브의 누적 수량    

getReferralIncentive

function getReferralIncentive(address user) external view returns (address[] memory tokens, uint256[] memory amounts, uint256[] memory claimed)

Description
    사용자가 수령할 수 있는 레퍼럴 인센티브를 조회한다

Parameters
    address user : 사용자의 주소

Return
    address[] memory tokens : 토큰의 주소
    uint256[] memory amounts : 수령할 수 있는 레퍼럴 인센티브의 수량
    uint256[] memory claimed : 기 수령한 레퍼럴 인센티브의 누적 수량

estimateFSProfit

function estimateFSProfit(uint256 id) external view returns (address token, uint256 amount)


Description
    Flash settlement 실행 시 예상 수익을 조회한다

Parameters
    uint256 id : 트레이딩 페어의 id

Return
    address token : 토큰의 주소 (손실일 경우 address(0)를 반환)
    uint256 amount : 토큰의 수량

placeOrder

function placeOrder(TradeOrder memory order) external payable

Description
    Create the order

Parameters
    TradeOrder memory order: the trading order

Return

claimN

function claimN(uint256 id, uint256 n) external

Description
    해당 trading pair 의 주문 n개의 잔량을 수령한다

Parameters
    uint256 id : 트레이딩 페어의 id
    uint256 n : 주문의 수 (n=0 인 경우, 전부 다 수령)

Return

cancelN

function cancelN(uint256 id, uint256 n) external


Description
    해당 trading pair 의 주문 n개를 취소한다

Parameters
    uint256 id : 트레이딩 페어의 id
    uint256 n : 주문의 수 (n=0 인 경우, 전부 다 취소)

Return

claimAllMakerIncentive

function claimAllMakerIncentive() external

Description
    메이커 인센티브를 모두 수령한다

Parameters

Return

claimAllReferralIncentive

function claimAllReferralIncentive() external

Description
    레퍼럴 인센티브를 모두 수령한다

Parameters

Return

claimMakerIncentive

function claimMakerIncentive(uint256 i) external

Description
    getMakerIncentive 로 조회한 메이커 인센티브 중 i번 째 토큰을 수령한다

Parameters
    uint256 i : i번 토큰

Return

claimReferralIncentive

function claimReferralIncentive(uint256 i) external

Description
    getReferralIncentive 로 조회한 레퍼럴 인센티브 중 i번 째 토큰을 수령한다

Parameters
    uint256 i : i번 토큰

Return

claimSell

function claimSell(uint256 sId, uint256 oId) external

Description
    지정가 매도 주문이 체결된 이후 체결된자산을 수령한다
    
Parameters
    uint256 id : 트레이딩 페어의 id
    uint256 oId : 주문의 id

Return

cancelSell

function cancelSell(uint256 id, uint256 oId) external

Description
    지정가 매도 주문을 취소한다
    
Parameters
    uint256 id : 트레이딩 페어의 id
    uint256 oId : 주문의 id

Return

claimBuy

function claimBuy(uint256 id, uint256 oId) external

Description
    지정가 매수 주문이 체결된 이후 체결된 자산을 수령한다
    
Parameters
    uint256 id : 트레이딩 페어의 id
    uint256 oId : 주문의 id

Return

cancelBuy

function cancelBuy(uint256 id, uint256 oId) external

Description
    지정가 매수 주문을 취소한다
    
Parameters
    uint256 id : 트레이딩 페어의 id
    uint256 oId : 주문의 id

Return

follow

function follow(address friend) external

Description
    friend 를 follow 한다

Parameters
    address friend : 친구의 주소

Return

unfollow

function unfollow() external

Description
    follow 를 해제한다

Parameters

Return

flashSettlement

function flashSettlement(uint256 sId, uint256 allowanceRatio6) external

Description
    flash settlement 를 실행한다

Parameters
    uint256 id : 트레이딩 페어의 id
    uint256 allowanceRatio6 : 팀 인센티브 비율 (범위 제한 0~1e6)

Return

을 참고 바랍니다.

지정가 주문의 옵션