Source Code

;; SatGuard Fee Discount
(define-constant err-owner (err u840))
(define-constant err-amt (err u841))
(define-data-var admin principal tx-sender)
(define-map discounts {who: principal} {pct: uint,sa: uint})
(define-map tier-discounts {tier: uint} {pct: uint})
(define-read-only (get-discount (who principal)) (default-to {pct: u0,sa: u0} (map-get? discounts {who: who})))
(define-read-only (get-tier-discount (tier uint)) (default-to {pct: u0} (map-get? tier-discounts {tier: tier})))
(define-public (set-discount (who principal) (pct uint))
  (begin
    (asserts! (is-eq tx-sender (var-get admin)) err-owner)
    (asserts! (<= pct u50) err-amt) ;; max 50% discount
    (map-set discounts {who: who} {pct: pct,sa: block-height})
    (print {e: "discount-set",who: who,pct: pct})
    (ok true)))
(define-public (set-tier-discount (tier uint) (pct uint))
  (begin
    (asserts! (is-eq tx-sender (var-get admin)) err-owner)
    (asserts! (<= pct u50) err-amt)
    (map-set tier-discounts {tier: tier} {pct: pct})
    (print {e: "tier-discount-set",tier: tier,pct: pct})
    (ok true)))
(define-read-only (calc-discounted (who principal) (amt uint))
  (let ((d (get pct (get-discount who))))
    (ok (- amt (/ (* amt d) u100)))))

Functions (5)

FunctionAccessArgs
get-discountread-onlywho: principal
get-tier-discountread-onlytier: uint
set-discountpublicwho: principal, pct: uint
set-tier-discountpublictier: uint, pct: uint
calc-discountedread-onlywho: principal, amt: uint