Inside StackingDAO

Ryan Waits,stacksclarity

Note: This article is a work in progress and will be updated with more details on the StackingDAO contract operations and functionalities.

Deposit Function in StackingDAO Contract

The deposit function allows users to deposit STX in exchange for stSTX tokens. Here's a detailed look at its operations:


(define-public (deposit (reserve-contract <reserve-trait>) (stx-amount uint) (referrer (optional principal)))
(let
(
(cycle-id (get-pox-cycle))
(current-cycle-info (get-cycle-info cycle-id))
(stx-ststx (try! (get-stx-per-ststx reserve-contract)))
(ststx-to-receive (/ (* stx-amount u1000000) stx-ststx))
)
(try! (contract-call? .dao check-is-enabled))
(asserts! (not (get-shutdown-deposits)) (err ERR_SHUTDOWN))
(map-set cycle-info { cycle-id: cycle-id } (merge current-cycle-info { deposited: (+ (get deposited current-cycle-info) stx-amount) }))
(print { action: "deposit", data: { stacker: tx-sender, referrer: referrer, amount: ststx-to-receive, block-height: block-height } })
(try! (stx-transfer? stx-amount tx-sender (contract-of reserve-contract)))
(try! (contract-call? .ststx-token mint-for-protocol ststx-to-receive tx-sender))
(ok ststx-to-receive)
)
)

Determine Current Cycle

Fetches the current PoX cycle and retrieves its information.

© By Ryan Waits 2024