설계
상위 수준에서, DeepBook Margin design은 leveraged trading을 가능하게 하기 위해 함께 동작하는 네 가지 주요 shared object를 중심으로 한다:
MarginPool: 특정 asset에 대한 liquidity를 관리하는 shared object로, interest accrual을 포함한 supply 및 borrow 작업을 처리한다. 자세한 내용은 MarginPool shared object 섹션을 참조한다.MarginManager:BalanceManager를 감싸고 borrowing, repaying, 그리고 risk management를 포함한 leveraged trading을 위한 capability를 제공하는 shared object이다. 자세한 내용은 MarginManager shared object 섹션을 참조한다.MarginRegistry: 모든 margin pool과 margin manager를 관리하고, 시스템 전반의 구성을 강제하며, 활성화된 pool을 추적하는 중앙 registry이다. 자세한 내용은 MarginRegistry 섹션을 참조한다.BalanceManager: DeepBookV3에서 상속되며, trading을 위한 fund를 소싱하는 데 사용된다. 자세한 내용은 BalanceManager를 참조한다.
MarginPool shared object
MarginPool은 단일 asset 타입에 대한 liquidity를 관리하는 역할을 한다. 이는 여러 핵심 구성 요소로 이뤄져 있다:
State
State 구성 요소는 총 supply 및 borrow amount와, 이에 해당하는 share를 추적한다. 이는 다음과 같은 shares 기반 accounting 시스템을 사용한다:
- Supply shares: lender가 총 공급된 asset에 대해 갖는 비례 소유권을 나타낸다.
- Borrow shares: borrower의 비례 debt 의무를 나타낸다.
interest는 utilization rate(borrowed asset 대비 supplied asset의 비율)에 따라 연속적으로 누적된다. state는 모든 supply, borrow, repay, 그리고 withdraw 작업에서 업데이트되어 interest가 항상 최신 상태가 되도록 보장한다.
interest rate는 InterestConfig에 정의된 piecewise linear model을 따라 pool의 utilization rate에 기반해 동적으로 계산된다. utilization이 높을수록 interest rate가 높아져 더 많은 supply와 더 적은 borrowing을 유도한다.
Protocol config
ProtocolConfig는 margin pool의 동작을 제어하는 핵심 parameter를 저장한다:
- Interest rate parameters: interest rate curve를 정의하는 base rate, multiplier, 그리고 kink point이다.
- Supply cap: pool에 공급할 수 있는 최대 amount이다.
- Max utilization rate: pool에서 어느 정도까지 차입할 수 있는지에 대한 상한이다(ex., 80%).
- Min borrow amount: spam을 방지하기 위한 최소 loan size이다.
- Protocol spread: protocol fee로 전달되는 interest의 비율이다.
이 parameter는 pool operator가 MarginPoolCap을 사용하여 업데이트할 수 있다.
Protocol fees
ProtocolFees 구성 요소는 획득한 interest의 분배를 관리한다. borrower가 interest를 지급하면, protocol spread(ex., 10%)가 fee로 취해지고, 남은 부분(ex., 90%)은 supplier에게 share에 비례해 분배된다.
protocol spread는 다음과 같이 분배된다:
- Referral fees: protocol spread의 50%가 liquidity를 유치하는 supply referral로 전달된다.
- Protocol fees: protocol spread의 25%가 protocol treasury로 전달된다.
- Maintainer fees: protocol spread의 25%가 pool maintainer로 전달된다.
예를 들어 100 USDC의 interest가 지급되면, 10 USDC가 protocol fee로 전달되고(10% spread 기준) 90 USDC가 supplier에게 전달된다. 그 다음 10 USDC는 다음과 같이 분배된다: referral에 5 USDC, protocol에 2.5 USDC, 그리고 maintainer에 2.5 USDC이다.
protocol은 각 referral이 소유한 share를 추적하고, referral이 유치한 liquidity에 기반해 비례 fee를 계산한다.
Position Manager
PositionManager는 다음을 포함하여 개별 supplier position을 추적한다:
- 각
SupplierCap이 소유한 supply share. - fee 분배를 위한 referral 연관 관계.
- 과거 position 데이터.
MarginManager shared object
MarginManager는 BalanceManager를 감싸고 margin trading capability를 추가한다. 각 MarginManager는 특정 DeepBook pool과 연관되며 다음을 추적한다:
- Borrowed shares: base 및 quote asset margin pool에서 차입한 amount.
- Margin pool ID: 현재 loan이 어느 margin pool에서 왔는지(있는 경우).
- DeepBook pool: 이 manager가 trading하도록 권한이 부여된 trading pool.
Borrowing and risk management
MarginManager는 한 번에 하나의 margin pool에서만 차입할 수 있다(base asset 또는 quote asset 중 하나). 이는 risk 계산을 단순화하고 복잡한 cross-collateral 시나리오를 방지한다.
risk는 다음과 같이 계산되는 risk ratio로 측정된다:
서로 다른 risk ratio threshold가 허용되는 action을 결정한다:
- Withdraw threshold (ex., 2.0): 담보를 인출하기 위한 최소 ratio이다.
- Borrow threshold (ex., 1.25): 새 loan을 받기 위한 최소 ratio이다.
- Target liquidation ratio (ex., 1.25): 부분 liquidation 후 목표 ratio이다.
- Liquidation threshold (ex., 1.15): 이 값 아래로 떨어지면 position이 liquidation될 수 있다.
Liquidation process
MarginManager risk ratio가 liquidation threshold 아래로 떨어지면, 누구나 position을 liquidation할 수 있다:
- liquidator가 debt에 대한 상환을 제공한다.
- liquidator는 담보와 liquidation reward(ex., 5%)를 받는다.
- margin pool도 보상(ex., 3%)을 받을 수 있다.
- asset이 부족하면, pool에 bad debt가 기록된다.
liquidation은 position 상태와 liquidator의 입력에 따라 partial 또는 full일 수 있다.
MarginRegistry
MarginRegistry는 margin 시스템의 중앙 coordination point 역할을 한다:
- Pool registration: asset 타입별로 모든 margin pool을 추적한다.
- Pool enablement: margin trading이 활성화된 DeepBook pool을 결정한다.
- Risk parameters: pool별 risk ratio 및 liquidation parameter를 저장한다.
- Manager tracking: 모든 margin manager 목록을 유지한다.
registry는 asset 타입당 하나의 margin pool만 존재할 수 있음을 강제하고, margin manager가 활성화된 DeepBook pool에서만 trading할 수 있도록 보장한다.
Liquidation flow
다음은 전형적인 liquidation 시나리오를 설명한다:
- Risk calculation:
MarginManager는 가격 움직임 또는 interest accrual로 인해 liquidation threshold 아래로 떨어진다. - Liquidator action: liquidator는 상환 코인을 제공하며
liquidate()를 호출한다. - Order cancellation: manager에 대한 모든 open order가 취소된다.
- Debt calculation: 시스템은 상환할 수 있는 최대 debt를 계산한다.
- Asset transfer: 담보 asset이 reward와 함께 liquidator에게 전송된다.
- Pool update: margin pool은 상환과 잠재적 bad debt를 처리한다.
- Position update: manager의 borrowed share는 감소하거나 정리된다.
Interest accrual
DeepBook Margin에서 interest는 utilization rate에 기반해 연속적으로 누적된다:
interest rate는 kinked model을 따른다:
- kink 아래(ex., 80% utilization): 완만한 rate로 선형 증가한다.
- kink 위: 과도한 borrowing을 억제하기 위해 가파르게 선형 증가한다.
interest는 state가 업데이트될 때마다(어떤 supply, borrow, repay, 또는 withdraw 작업이든) 복리로 누적된다. protocol spread는 interest 중 어느 부분이 fee로 전달되고 어느 부분이 supplier에게 전달되는지를 결정한다.