;; ordinal-8-bit-heroes-and-villains
;; contractType: continuous

(impl-trait 'SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait.nft-trait)
;;(impl-trait .nft-trait.nft-trait)

(define-non-fungible-token ordinal-8-bit-heroes-and-villains uint)

(define-constant DEPLOYER tx-sender)

(define-constant ERR-NOT-AUTHORIZED u101)
(define-constant ERR-INVALID-USER u102)
(define-constant ERR-LISTING u103)
(define-constant ERR-WRONG-COMMISSION u104)
(define-constant ERR-NOT-FOUND u105)
(define-constant ERR-NFT-MINT u106)
(define-constant ERR-CONTRACT-LOCKED u107)
(define-constant ERR-METADATA-FROZEN u111)
(define-constant ERR-INVALID-PERCENTAGE u114)

(define-data-var last-id uint u0)
(define-data-var artist-address principal 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1)
(define-data-var locked bool false)
(define-data-var metadata-frozen bool false)

(define-map cids uint (string-ascii 64))

(define-public (lock-contract)
  (begin
    (asserts! (or (is-eq tx-sender (var-get artist-address)) (is-eq tx-sender DEPLOYER)) (err ERR-NOT-AUTHORIZED))
    (var-set locked true)
    (ok true)))

(define-public (set-artist-address (address principal))
  (begin
    (asserts! (or (is-eq tx-sender (var-get artist-address)) (is-eq tx-sender DEPLOYER)) (err ERR-INVALID-USER))
    (ok (var-set artist-address address))))

(define-public (burn (token-id uint))
  (begin 
    (asserts! (is-owner token-id tx-sender) (err ERR-NOT-AUTHORIZED))
    (asserts! (is-none (map-get? market token-id)) (err ERR-LISTING))
    (nft-burn? ordinal-8-bit-heroes-and-villains token-id tx-sender)))

(define-public (set-token-uri (hash (string-ascii 64)) (token-id uint))
  (begin
    (asserts! (or (is-eq tx-sender (var-get artist-address)) (is-eq tx-sender DEPLOYER)) (err ERR-NOT-AUTHORIZED))
    (asserts! (not (var-get metadata-frozen)) (err ERR-METADATA-FROZEN))
    (print { notification: "token-metadata-update", payload: { token-class: "nft", token-ids: (list token-id), contract-id: (as-contract tx-sender) }})
    (map-set cids token-id hash)
    (ok true)))

(define-public (freeze-metadata)
  (begin
    (asserts! (or (is-eq tx-sender (var-get artist-address)) (is-eq tx-sender DEPLOYER)) (err ERR-NOT-AUTHORIZED))
    (var-set metadata-frozen true)
    (ok true)))

(define-private (is-owner (token-id uint) (user principal))
    (is-eq user (unwrap! (nft-get-owner? ordinal-8-bit-heroes-and-villains token-id) false)))

(define-public (transfer (id uint) (sender principal) (recipient principal))
  (begin
    (asserts! (is-eq tx-sender sender) (err ERR-NOT-AUTHORIZED))
    (asserts! (is-none (map-get? market id)) (err ERR-LISTING))
    (trnsfr id sender recipient)))

(define-read-only (get-owner (token-id uint))
  (ok (nft-get-owner? ordinal-8-bit-heroes-and-villains token-id)))

(define-read-only (get-last-token-id)
  (ok (var-get last-id)))

(define-read-only (get-token-uri (token-id uint))
  (ok (some (concat "ipfs://" (unwrap-panic (map-get? cids token-id))))))

(define-read-only (get-artist-address)
  (ok (var-get artist-address)))

(define-public (claim (uris (list 25 (string-ascii 64))))
  (mint-many uris))

(define-private (mint-many (uris (list 25 (string-ascii 64))))
  (let 
    (
      (token-id (+ (var-get last-id) u1))
      (art-addr (var-get artist-address))
      (id-reached (fold mint-many-iter uris token-id))
      (current-balance (get-balance tx-sender))
    )
    (asserts! (or (is-eq tx-sender DEPLOYER) (is-eq tx-sender art-addr)) (err ERR-NOT-AUTHORIZED))
    (asserts! (is-eq (var-get locked) false) (err ERR-CONTRACT-LOCKED))
    (var-set last-id (- id-reached u1))
    (map-set token-count tx-sender (+ current-balance (- id-reached token-id)))    
    (ok id-reached)))

(define-private (mint-many-iter (hash (string-ascii 64)) (next-id uint))
  (begin
    (unwrap! (nft-mint? ordinal-8-bit-heroes-and-villains next-id tx-sender) next-id)
    (map-set cids next-id hash)      
    (+ next-id u1)))

;; NON-CUSTODIAL FUNCTIONS START
(use-trait commission-trait 'SP3D6PV2ACBPEKYJTCMH7HEN02KP87QSP8KTEH335.commission-trait.commission)

(define-map token-count principal uint)
(define-map market uint {price: uint, commission: principal, royalty: uint})

(define-read-only (get-balance (account principal))
  (default-to u0
    (map-get? token-count account)))

(define-private (trnsfr (id uint) (sender principal) (recipient principal))
  (match (nft-transfer? ordinal-8-bit-heroes-and-villains id sender recipient)
    success
      (let
        ((sender-balance (get-balance sender))
        (recipient-balance (get-balance recipient)))
          (map-set token-count
            sender
            (- sender-balance u1))
          (map-set token-count
            recipient
            (+ recipient-balance u1))
          (ok success))
    error (err error)))

(define-private (is-sender-owner (id uint))
  (let ((owner (unwrap! (nft-get-owner? ordinal-8-bit-heroes-and-villains id) false)))
    (or (is-eq tx-sender owner) (is-eq contract-caller owner))))

(define-read-only (get-listing-in-ustx (id uint))
  (map-get? market id))

(define-public (list-in-ustx (id uint) (price uint) (comm-trait <commission-trait>))
  (let ((listing  {price: price, commission: (contract-of comm-trait), royalty: (var-get royalty-percent)}))
    (asserts! (is-sender-owner id) (err ERR-NOT-AUTHORIZED))
    (map-set market id listing)
    (print (merge listing {a: "list-in-ustx", id: id}))
    (ok true)))

(define-public (unlist-in-ustx (id uint))
  (begin
    (asserts! (is-sender-owner id) (err ERR-NOT-AUTHORIZED))
    (map-delete market id)
    (print {a: "unlist-in-ustx", id: id})
    (ok true)))

(define-public (buy-in-ustx (id uint) (comm-trait <commission-trait>))
  (let ((owner (unwrap! (nft-get-owner? ordinal-8-bit-heroes-and-villains id) (err ERR-NOT-FOUND)))
      (listing (unwrap! (map-get? market id) (err ERR-LISTING)))
      (price (get price listing))
      (royalty (get royalty listing)))
    (asserts! (is-eq (contract-of comm-trait) (get commission listing)) (err ERR-WRONG-COMMISSION))
    (try! (stx-transfer? price tx-sender owner))
    (try! (pay-royalty price royalty))
    (try! (contract-call? comm-trait pay id price))
    (try! (trnsfr id owner tx-sender))
    (map-delete market id)
    (print {a: "buy-in-ustx", id: id})
    (ok true)))
    
(define-data-var royalty-percent uint u500)

(define-read-only (get-royalty-percent)
  (ok (var-get royalty-percent)))

(define-public (set-royalty-percent (royalty uint))
  (begin
    (asserts! (or (is-eq tx-sender (var-get artist-address)) (is-eq tx-sender DEPLOYER)) (err ERR-INVALID-USER))
    (asserts! (and (>= royalty u0) (<= royalty u1000)) (err ERR-INVALID-PERCENTAGE))
    (ok (var-set royalty-percent royalty))))

(define-private (pay-royalty (price uint) (royalty uint))
  (let (
    (royalty-amount (/ (* price royalty) u10000))
  )
  (if (and (> royalty-amount u0) (not (is-eq tx-sender (var-get artist-address))))
    (try! (stx-transfer? royalty-amount tx-sender (var-get artist-address)))
    (print false)
  )
  (ok true)))

;; NON-CUSTODIAL FUNCTIONS END

(try! (nft-mint? ordinal-8-bit-heroes-and-villains u1 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u1 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/1.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u2 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u2 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/2.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u3 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u3 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/3.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u4 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u4 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/4.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u5 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u5 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/5.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u6 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u6 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/6.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u7 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u7 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/7.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u8 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u8 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/8.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u9 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u9 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/9.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u10 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u10 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/10.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u11 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u11 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/11.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u12 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u12 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/12.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u13 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u13 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/13.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u14 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u14 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/14.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u15 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u15 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/15.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u16 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u16 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/16.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u17 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u17 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/17.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u18 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u18 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/18.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u19 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u19 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/19.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u20 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u20 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/20.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u21 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u21 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/21.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u22 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u22 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/22.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u23 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u23 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/23.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u24 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u24 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/24.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u25 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u25 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/25.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u26 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u26 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/26.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u27 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u27 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/27.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u28 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u28 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/28.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u29 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u29 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/29.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u30 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u30 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/30.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u31 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u31 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/31.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u32 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u32 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/32.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u33 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u33 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/33.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u34 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u34 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/34.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u35 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u35 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/35.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u36 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u36 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/36.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u37 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u37 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/37.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u38 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u38 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/38.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u39 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u39 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/39.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u40 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u40 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/40.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u41 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u41 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/41.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u42 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u42 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/42.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u43 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u43 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/43.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u44 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u44 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/44.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u45 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u45 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/45.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u46 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u46 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/46.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u47 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u47 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/47.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u48 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u48 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/48.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u49 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u49 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/49.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u50 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u50 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/50.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u51 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u51 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/51.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u52 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u52 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/52.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u53 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u53 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/53.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u54 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u54 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/54.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u55 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u55 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/55.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u56 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u56 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/56.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u57 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u57 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/57.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u58 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u58 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/58.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u59 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u59 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/59.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u60 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u60 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/60.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u61 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u61 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/61.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u62 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u62 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/62.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u63 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u63 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/63.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u64 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u64 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/64.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u65 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u65 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/65.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u66 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u66 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/66.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u67 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u67 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/67.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u68 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u68 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/68.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u69 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u69 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/69.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u70 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u70 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/70.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u71 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u71 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/71.json")
(try! (nft-mint? ordinal-8-bit-heroes-and-villains u72 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1))
(map-set token-count 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1 (+ (get-balance 'SP297RVXNK1YRTXGQY49WBCAKGP5MNDR50RVZCNQ1) u1))
(map-set cids u72 "Qme5tcM82Lt9A2pTLJk4KukZGhu6nepVeiTM2obeF9UskS/json/72.json")
(var-set last-id u72)

(define-data-var license-uri (string-ascii 80) "")
(define-data-var license-name (string-ascii 40) "")

(define-read-only (get-license-uri)
  (ok (var-get license-uri)))
  
(define-read-only (get-license-name)
  (ok (var-get license-name)))
  
(define-public (set-license-uri (uri (string-ascii 80)))
  (begin
    (asserts! (or (is-eq tx-sender (var-get artist-address)) (is-eq tx-sender DEPLOYER)) (err ERR-NOT-AUTHORIZED))
    (ok (var-set license-uri uri))))
    
(define-public (set-license-name (name (string-ascii 40)))
  (begin
    (asserts! (or (is-eq tx-sender (var-get artist-address)) (is-eq tx-sender DEPLOYER)) (err ERR-NOT-AUTHORIZED))
    (ok (var-set license-name name))))