;; constants
(define-constant ERR-NOT-AUTHORIZED u401)
(define-constant ERR-ALL-MINTED u101)
(define-constant ERR-COOLDOWN u102)

(define-constant CONTRACT-OWNER tx-sender)


;;;;;;;;;;;;;;

(define-public (funct1 (amountIn uint) )
  (let (
    (b1 (unwrap-panic (unwrap-and-unstake amountIn)))
    (b2 (unwrap-panic (swap-ldn-stx b1)))
  )
    (begin
      (asserts! (> b2 amountIn) (err ERR-COOLDOWN))
      (asserts! (is-eq CONTRACT-OWNER tx-sender) (err ERR-ALL-MINTED))
    )
    (ok (list amountIn b1 b2))
  )
)


(define-public (unwrap-and-unstake (amountIn uint))
    (a1 (unwrap-panic (unwrap-wldn amountIn)))
    (a2 (unwrap-panic (unstake-sldn a1)))

    (ok (unwrap-panic (element-at a2 u0))))
)

(define-public (swap-ldn-stx (amountIn uint))
    (a1 (unwrap-panic (swap-wldn-usda amountIn)))
    (a2 (unwrap-panic (swap-wldn-usda amountIn)))

    (ok u0)
)


(define-public (unwrap-wldn (amount uint))
  (let ((r (unwrap-panic (contract-call? 'SP3MBWGMCVC9KZ5DTAYFMG1D0AEJCR7NENTM3FTK5.wrapped-lydian-creator-v1-1 unwrap amount))))
  (ok (unwrap-panic (element-at r u0))))
)

(define-public (unstake-sldn (amount uint))
  (let ((r (unwrap-panic (contract-call? 'SP3MBWGMCVC9KZ5DTAYFMG1D0AEJCR7NENTM3FTK5.staking-v1-1 unstake 'SP3MBWGMCVC9KZ5DTAYFMG1D0AEJCR7NENTM3FTK5.staking-distributor-v1-1 'SP3MBWGMCVC9KZ5DTAYFMG1D0AEJCR7NENTM3FTK5.treasury-v1-1 amount))))
  (ok (unwrap-panic (element-at r u0))))
)

(define-public (swap-wldn-usda (dx uint))
  (let ((r (unwrap-panic (contract-call? 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-swap-v2-1 swap-x-for-y 'SP3MBWGMCVC9KZ5DTAYFMG1D0AEJCR7NENTM3FTK5.lydian-token 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.usda-token dx u0))))
  (ok (unwrap-panic (element-at r u0))))
)


