마진 매니저
MarginManager는 BalanceManager를 감싸며 예치, 출금, trade, 그리고 leveraged 포지션을 관리하는 데 필요한 capability를 제공하는 공유 객체이다. 이는 사용자가 마진 풀에서 자산을 차입하여 trading 포지션을 확대할 수 있게 하면서, collateralization을 통해 risk를 관리하도록 한다.
각 MarginManager는 특정 DeepBook 풀과 연관되며, 해당 풀에서 trading을 허용하는 마진 풀로부터 차입할 수 있다. margin manager는 차입 포지션을 추적하고 시스템 건전성을 유지하기 위해 risk ratio limit을 강제한다.
API
다음은 MarginManager가 노출하는 서로 다른 public 함수가다.
MarginManager 생성
new() 함수는 하나의 트랜잭션에서 MarginManager를 생성하고 공유한다. 지정된 풀에 대해 margin trading이 활성화되어 있는지 검증한다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.initializer로 MarginManager 생성
new_with_initializer() 함수는 MarginManager를 생성하고 initializer hot potato와 함께 반환한다. initializer는 share() 함수를 사용해 생성 후 margin manager가 올바르게 공유되도록 보장한다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.Set or unset referral
MarginManager의 소유자는 거래 수수료 혜택을 위해 풀별 referral을 설정하거나 해제할 수 있다. referral은 margin manager와 연관된 풀에 대해 민트된 DeepBookPoolReferral이어야 한다. 각 margin manager는 서로 다른 풀에 대해 서로 다른 referral을 가질 수 있다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.Deposit 자금
소유자만 MarginManager에 fund를 예치할 수 있다. 예치하는 자산은 베이스 자산, 견적 자산, 또는 DEEP 토큰이어야 한다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.Withdraw 자금
소유자만 MarginManager에서 fund를 인출할 수 있다. manager에 활성 loan이 있을 때 인출은 risk ratio limit의 적용을 받는다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.Borrow 자산
포지션 크기를 늘리기 위해 마진 풀에서 베이스 자산 또는 견적 자산을 차입한다. 차입에는 risk ratio limit이 적용되며 마진 풀은 manager의 DeepBook 풀에서 trading을 허용해야 한다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.Repay loans
debt를 줄이기 위해 차입한 자산을 상환한다. 정확한 amount를 지정하거나, 총 debt까지 사용 가능한 잔액 전체를 상환할 수 있다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.Liquidate 포지션
담보가 부족한 margin manager를 liquidation한다. liquidator는 상환을 제공하고 담보 자산과 liquidation reward를 받는다. 마진 풀은 포지션 상태에 따라 보상을 받거나 bad debt가 발생할 수 있다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.Calculate risk ratio
margin manager의 risk ratio를 반환하며, 이는 자산 대비 debt의 비율을 나타낸다. ratio가 높을수록 더 건강한 포지션을 의미한다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.Read endpoints
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.이벤트
MarginManagerCreatedEvent
새 margin manager가 생성될 때 발생한다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.DepositCollateralEvent
담보가 margin manager에 예치될 때 발생한다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.WithdrawCollateralEvent
담보가 margin manager에서 인출될 때 발생한다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.LoanBorrowedEvent
자산이 마진 풀에서 차입될 때 발생한다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.LoanRepaidEvent
차입한 자산이 상환될 때 발생한다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.LiquidationEvent
margin manager가 liquidation될 때 발생한다.
packages/deepbook_margin/sources/margin_manager.move. You probably need to run `pnpm prebuild` and restart the site.