;; This contract implements the SIP-010 community-standard Fungible Token trait.
(impl-trait 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.sip-010-trait)
;; Define the FT, with no maximum supply
(define-fungible-token count-token)
;; Define errors
(define-constant ERR_OWNER_ONLY (err u100))
(define-constant ERR_NOT_TOKEN_OWNER (err u101))
;; Define constants for contract
(define-constant CONTRACT_OWNER tx-sender)
(define-data-var TOKEN-URI (optional (string-utf8 256)) (some u"https://ustnpmyvsbtbyjiqiwge.supabase.co/storage/v1/object/public/Count%20Token%20Metadata/count-token-metadata.json"))
(define-constant TOKEN_NAME "Count Token")
(define-constant TOKEN_SYMBOL "COUNT")
(define-constant TOKEN_DECIMALS u6) ;; 6 units displayed past decimal, e.g. 1.000_000 = 1 token
;; SIP-010 function: Get the token balance of a specified principal
(define-read-only (get-balance (who principal))
(ok (ft-get-balance count-token who))
)
;; SIP-010 function: Returns the total supply of fungible token
(define-read-only (get-total-supply)
(ok (ft-get-supply count-token))
)
;; SIP-010 function: Returns the human-readable token name
(define-read-only (get-name)
(ok TOKEN_NAME)
)
;; SIP-010 function: Returns the symbol or "ticker" for this token
(define-read-only (get-symbol)
(ok TOKEN_SYMBOL)
)
;; SIP-010 function: Returns number of decimals to display
(define-read-only (get-decimals)
(ok TOKEN_DECIMALS)
)
;; SIP-010 function: Returns the URI containing token metadata
(define-read-only (get-token-uri)
(ok (var-get TOKEN-URI))
)
(define-public (set-token-uri (value (string-utf8 256)))
(begin
(asserts! (is-eq tx-sender CONTRACT_OWNER) (err ERR_OWNER_ONLY))
(var-set TOKEN-URI (some value))
(ok (print {
notification: "token-metadata-update",
payload: {
contract-id: (as-contract tx-sender),
token-class: "ft"
}
})
)
)
)
;; Mint new tokens and send them to a recipient.
;; Only the contract deployer can perform this operation.
(define-public (mint)
(begin
(asserts! (is-eq contract-caller .counter) ERR_OWNER_ONLY)
(ft-mint? count-token u1000000 tx-sender)
)
)
(define-public (burn)
(begin
(asserts! (is-eq contract-caller .counter) ERR_OWNER_ONLY)
(if (> (unwrap-panic (get-balance tx-sender)) u0)
(ft-burn? count-token u1000000 tx-sender)
(stx-burn? u1000000 tx-sender)
)
)
)
;; SIP-010 function: Transfers tokens to a recipient
;; Sender must be the same as the caller to prevent principals from transferring tokens they do not own.
(define-public (transfer
(amount uint)
(sender principal)
(recipient principal)
(memo (optional (buff 34)))
)
(begin
;; #[filter(amount, recipient)]
(asserts! (or (is-eq tx-sender sender) (is-eq contract-caller sender)) ERR_NOT_TOKEN_OWNER)
(try! (ft-transfer? count-token amount sender recipient))
(match memo to-print (print to-print) 0x)
(ok true)
)
)