;; DMToken - SIP-010 Fungible Token
;; Generated by Charisma Launchpad
(impl-trait 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.sip-010-trait)
;; Error codes
(define-constant ERR-OWNER-ONLY (err u100))
(define-constant ERR-NOT-AUTHORIZED (err u403))
;; Constants
(define-constant DEPLOYER tx-sender)
(define-constant TOTAL-SUPPLY u21000000000000)
;; Token definition
(define-fungible-token DMT TOTAL-SUPPLY)
(define-data-var token-uri (optional (string-utf8 256)) (some u"data:application/json;base64,eyJzaXAiOjE2LCJuYW1lIjoiRE1Ub2tlbiIsImltYWdlIjoiZGF0YTppbWFnZS9wbmc7YmFzZTY0LGlWQk9SdzBLR2dvQUFBQU5TVWhFVWdBQUFBRUFBQUFCQ0FJQUFBQ1FkMVBlQUFBQUVFbEVRVlI0bkdKNjBTZ0lDQUFBLy84RDF3RjkxSG00SkFBQUFBQkpSVTVFcmtKZ2dnPT0ifQ=="))
;; SIP-010 Standard Functions
(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34))))
(begin
(asserts! (or (is-eq tx-sender sender) (is-eq contract-caller sender)) ERR-NOT-AUTHORIZED)
(if (is-some memo)
(print memo)
none)
(ft-transfer? DMT amount sender recipient)
)
)
(define-read-only (get-name)
(ok "DMToken")
)
(define-read-only (get-symbol)
(ok "DMT")
)
(define-read-only (get-decimals)
(ok u6)
)
(define-read-only (get-balance (who principal))
(ok (ft-get-balance DMT who))
)
(define-read-only (get-total-supply)
(ok (ft-get-supply DMT))
)
(define-read-only (get-token-uri)
(ok (var-get token-uri))
)
;; Additional Functions
;; DMT: set-token-uri function is intentionally omitted as token-uri is fixed on-chain.
;; Batch Transfer Function
(define-public (send-many (recipients (list 200 { to: principal, amount: uint, memo: (optional (buff 34)) })))
(fold check-err (map send-token recipients) (ok true))
)
(define-private (check-err (result (response bool uint)) (prior (response bool uint)))
(match prior ok-value result err-value (err err-value))
)
(define-private (send-token (recipient { to: principal, amount: uint, memo: (optional (buff 34)) }))
(send-token-with-memo (get amount recipient) (get to recipient) (get memo recipient))
)
(define-private (send-token-with-memo (amount uint) (to principal) (memo (optional (buff 34))))
(let ((transferOk (try! (transfer amount tx-sender to memo))))
(ok transferOk)
)
)
;; The token-uri is now initialized directly in its define-data-var statement.
;; The following line is no longer needed:
;; (var-set token-uri (some u"..."))
;; Initial mint to deployer
(ft-mint? DMT TOTAL-SUPPLY DEPLOYER)