;; metacine
;; contractType: public

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

(define-non-fungible-token metacine uint)

;; Constants
(define-constant DEPLOYER tx-sender)
(define-constant COMM u1000)
(define-constant COMM-ADDR 'SPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S)

(define-constant ERR-NO-MORE-NFTS u100)
(define-constant ERR-NOT-ENOUGH-PASSES u101)
(define-constant ERR-PUBLIC-SALE-DISABLED u102)
(define-constant ERR-CONTRACT-INITIALIZED u103)
(define-constant ERR-NOT-AUTHORIZED u104)
(define-constant ERR-INVALID-USER u105)
(define-constant ERR-LISTING u106)
(define-constant ERR-WRONG-COMMISSION u107)
(define-constant ERR-NOT-FOUND u108)
(define-constant ERR-PAUSED u109)
(define-constant ERR-MINT-LIMIT u110)
(define-constant ERR-METADATA-FROZEN u111)
(define-constant ERR-AIRDROP-CALLED u112)
(define-constant ERR-NO-MORE-MINTS u113)
(define-constant ERR-INVALID-PERCENTAGE u114)

;; Internal variables
(define-data-var mint-limit uint u669)
(define-data-var last-id uint u1)
(define-data-var total-price uint u0)
(define-data-var artist-address principal 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0)
(define-data-var ipfs-root (string-ascii 80) "ipfs://ipfs/QmZj3k2LmnatbNzGJ2pEGrqRuHQXVkhjLxJvTDhEFYWE11/json/")
(define-data-var mint-paused bool true)
(define-data-var premint-enabled bool false)
(define-data-var sale-enabled bool false)
(define-data-var metadata-frozen bool false)
(define-data-var airdrop-called bool false)
(define-data-var mint-cap uint u0)

(define-map mints-per-user principal uint)
(define-map mint-passes principal uint)

(define-public (claim) 
  (mint (list true)))

(define-public (claim-two) (mint (list true true)))

(define-public (claim-three) (mint (list true true true)))

;; Mintpass Minting
(define-private (mint (orders (list 25 bool)))
  (let 
    (
      (passes (get-passes tx-sender))
    )
    (if (var-get premint-enabled)
      (begin
        (asserts! (>= passes (len orders)) (err ERR-NOT-ENOUGH-PASSES))
        (map-set mint-passes tx-sender (- passes (len orders)))
        (mint-many orders)
      )
      (begin
        (asserts! (var-get sale-enabled) (err ERR-PUBLIC-SALE-DISABLED))
        (mint-many orders)
      )
    )))

(define-private (mint-many (orders (list 25 bool )))  
  (let 
    (
      (last-nft-id (var-get last-id))
      (enabled (asserts! (<= last-nft-id (var-get mint-limit)) (err ERR-NO-MORE-NFTS)))
      (art-addr (var-get artist-address))
      (id-reached (fold mint-many-iter orders last-nft-id))
      (price (* (var-get total-price) (- id-reached last-nft-id)))
      (total-commission (/ (* price COMM) u10000))
      (current-balance (get-balance tx-sender))
      (total-artist (- price total-commission))
      (capped (> (var-get mint-cap) u0))
      (user-mints (get-mints tx-sender))
    )
    (asserts! (or (is-eq false (var-get mint-paused)) (is-eq tx-sender DEPLOYER)) (err ERR-PAUSED))
    (asserts! (or (not capped) (is-eq tx-sender DEPLOYER) (is-eq tx-sender art-addr) (>= (var-get mint-cap) (+ (len orders) user-mints))) (err ERR-NO-MORE-MINTS))
    (map-set mints-per-user tx-sender (+ (len orders) user-mints))
    (if (or (is-eq tx-sender art-addr) (is-eq tx-sender DEPLOYER) (is-eq (var-get total-price) u0000000))
      (begin
        (var-set last-id id-reached)
        (map-set token-count tx-sender (+ current-balance (- id-reached last-nft-id)))
      )
      (begin
        (var-set last-id id-reached)
        (map-set token-count tx-sender (+ current-balance (- id-reached last-nft-id)))
        (try! (stx-transfer? total-artist tx-sender (var-get artist-address)))
        (try! (stx-transfer? total-commission tx-sender COMM-ADDR))
      )    
    )
    (ok id-reached)))

(define-private (mint-many-iter (ignore bool) (next-id uint))
  (if (<= next-id (var-get mint-limit))
    (begin
      (unwrap! (nft-mint? metacine next-id tx-sender) next-id)
      (+ next-id u1)    
    )
    next-id))

(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 (set-price (price uint))
  (begin
    (asserts! (or (is-eq tx-sender (var-get artist-address)) (is-eq tx-sender DEPLOYER)) (err ERR-INVALID-USER))
    (ok (var-set total-price price))))

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

(define-public (set-mint-limit (limit uint))
  (begin
    (asserts! (or (is-eq tx-sender (var-get artist-address)) (is-eq tx-sender DEPLOYER)) (err ERR-INVALID-USER))
    (asserts! (< limit (var-get mint-limit)) (err ERR-MINT-LIMIT))
    (ok (var-set mint-limit limit))))

(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? metacine token-id tx-sender)))

(define-private (is-owner (token-id uint) (user principal))
    (is-eq user (unwrap! (nft-get-owner? metacine token-id) false)))

(define-public (set-base-uri (new-base-uri (string-ascii 80)))
  (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", contract-id: (as-contract tx-sender) }})
    (var-set ipfs-root new-base-uri)
    (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)))

;; Non-custodial SIP-009 transfer function
(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)))

;; read-only functions
(define-read-only (get-owner (token-id uint))
  (ok (nft-get-owner? metacine token-id)))

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

(define-read-only (get-token-uri (token-id uint))
  (ok (some (concat (concat (var-get ipfs-root) "{id}") ".json"))))

(define-read-only (get-paused)
  (ok (var-get mint-paused)))

(define-read-only (get-price)
  (ok (var-get total-price)))

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

(define-read-only (get-mints (caller principal))
  (default-to u0 (map-get? mints-per-user caller)))

(define-read-only (get-mint-limit)
  (ok (var-get mint-limit)))

(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))))

;; Non-custodial marketplace extras
(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? metacine 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? metacine 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? metacine 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)))

;; Extra functionality required for mintpass
(define-public (toggle-sale-state)
  (let 
    (
      ;; (premint (not (var-get premint-enabled)))
      (sale (not (var-get sale-enabled)))
    )
    (asserts! (or (is-eq tx-sender (var-get artist-address)) (is-eq tx-sender DEPLOYER)) (err ERR-NOT-AUTHORIZED))
    (var-set premint-enabled false)
    (var-set sale-enabled sale)
    (print { sale: sale })
    (ok true)))

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

(define-public (disable-premint)
  (begin
    (asserts! (or (is-eq tx-sender (var-get artist-address)) (is-eq tx-sender DEPLOYER)) (err ERR-NOT-AUTHORIZED))
    (ok (var-set premint-enabled false))))

(define-read-only (get-passes (caller principal))
  (default-to u0 (map-get? mint-passes caller)))

(define-read-only (get-premint-enabled)
  (ok (var-get premint-enabled)))

(define-read-only (get-sale-enabled)
  (ok (var-get sale-enabled)))  

(map-set mint-passes 'SP14814KM6CBCJZMD15JJ58Q3E2S3NCB6SDXM8C79 u8)
(map-set mint-passes 'SP17YP1HGWK7DP5Q69GRG14W34E078S4D78YM1FA5 u1)
(map-set mint-passes 'SP18WRH4SF7F1M5QZZ2BQDZZYBCJWT9VWQMDSTFY5 u6)
(map-set mint-passes 'SP19SM08PBAVFF0ZCB3WXK753Q8KVYZHBVKS0DWJM u2)
(map-set mint-passes 'SP1C5N37KPVY75A42VKVFD10V8N04TA0YFNEGQET1 u5)
(map-set mint-passes 'SP1CE3NQXDKCJ2KEFFGCVFA5C196S9F0RRX93HY87 u1)
(map-set mint-passes 'SP1DMPD0JNAVDRCTY17S2MNHX8F6502NB0Z25RVR u1)
(map-set mint-passes 'SP1DPNP3RRD6JG1557SP6JMX68W5BV6R2Z74BQEXV u2)
(map-set mint-passes 'SP1E7DEJG95E0EBZFFGEFGE0QX6Y0CR5V79615FB2 u2)
(map-set mint-passes 'SP1FH1Z76SQ13AJ79VNCA4HKCN4TBXC015PAPDHTJ u2)
(map-set mint-passes 'SP1FJN5P7V9W2K96VN7YWGH7VP36RB5K5JW1R9HF7 u1)
(map-set mint-passes 'SP1FR2M102H4DE4DH96R4D29RC8AGQZG5D5Y4S7CH u1)
(map-set mint-passes 'SP1FTE6BCZ14AHW7025F8B7AS6GQT4ZRNG4V209WH u13)
(map-set mint-passes 'SP1HCA0BF4PX3G7064MA5JW0Q8Q8R6KYMG4DWQAZN u2)
(map-set mint-passes 'SP1JCPNPAMAQJ364AFHPTW3HY7X0HYZ3TJ0ZDGWZH u1)
(map-set mint-passes 'SP1JF9VSNJBP4YZVC7AJ9CE6CXBD2ZV0W67T0E4T0 u1)
(map-set mint-passes 'SP1KBVBP3AZP7YA968Y3G14A17P9XXFPBPEVF5EG9 u3)
(map-set mint-passes 'SP1NFRJJFQAA5AB4R8RDA3F0WEBZHK0HQSKW1PPNY u1)
(map-set mint-passes 'SP1Q6N226KFMA496MVWSB0VZC0T0R9FSKTYYYZ403 u1)
(map-set mint-passes 'SP1QZT85MFT8HBAG3XEK7K6QY4GGP3MSG5C3H9PQ1 u2)
(map-set mint-passes 'SP1SSM54SWXV65318Q2J22DG4W0DDSYYKBD74XH1W u1)
(map-set mint-passes 'SP1SX5YDFDYWW16SMD1PQ5KS1QV3XK5S27PJPJMTG u2)
(map-set mint-passes 'SP1T07GK9H4M0WP4N1DSSA7NJ7GNTQZ0GBZM0GAR2 u50)
(map-set mint-passes 'SP1TRJR66FTZZGJWDG3ZK6VCS4SNQ10CHWTTMHMHZ u1)
(map-set mint-passes 'SP1V19KW8DVQ5D8YPBVHBF9NZXWMC0Q4FGG7S9NRY u1)
(map-set mint-passes 'SP1VCG4HXMG02BMJCSAZDBS1WR4N2YG3RPHMNP9WR u4)
(map-set mint-passes 'SP1VH4R8R3ASSW377GRRB8DK71416ZC3EEEPY140R u1)
(map-set mint-passes 'SP1XGVC95Z0HPG50YPEV5XZB5YA08DC29B0XZWBWN u2)
(map-set mint-passes 'SP1XPG9QFX5M95G36SGN9R8YJ4KJ0JB7ZXNH892N6 u3)
(map-set mint-passes 'SP1Y60B0GCM1P040N7Y0QD9R93Y5EZRJ8YH2BV5NW u1)
(map-set mint-passes 'SP1ZTC41HNC5PS8A7K444GBHN4104JXJ5EWRHTDM8 u3)
(map-set mint-passes 'SP2069715QFEA9GK8Q2E7QREFABGKRP78C08NTDTK u1)
(map-set mint-passes 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 u600)
(map-set mint-passes 'SP23NXVJWQARSPF1K3TD73MHVJE4EFV9V58GXHT73 u1)
(map-set mint-passes 'SP23Z3QX3CPAF7ARD2N1YP4BR5ATZW9X2Z6J0740J u4)
(map-set mint-passes 'SP247RS63PWW7ZQZ9EYYA9CXKKPWEP71M14W8N294 u1)
(map-set mint-passes 'SP24ZBZ8ZE6F48JE9G3F3HRTG9FK7E2H6K2QZ3Q1K u1)
(map-set mint-passes 'SP25KJH4N4YNKTVXSWSHDPVCWDFAN2BA4H2VQVN0G u1)
(map-set mint-passes 'SP26C9TWJYK6DTCD4T6HKBC76DPMK2DXXRNWS3E2D u1)
(map-set mint-passes 'SP26GZCVY8FYHNZ6C73W68TCFJHS8F8C9E772XX7X u2)
(map-set mint-passes 'SP26ZSXREMGCD8M71Y4FVA17QBC42EV0VM3HPVXYQ u2)
(map-set mint-passes 'SP2791RKSYJJ39MVHC09J8NARWBMK5G9C79EJB0RV u11)
(map-set mint-passes 'SP27E3TDKYNH3C11RBDFPD5WGR6FV0VN08RKX4D2N u1)
(map-set mint-passes 'SP28RZ1QXMXJXVKRRCR3D7GR5D48XY0NNA9MZWHJB u5)
(map-set mint-passes 'SP28YEDDDBM8GT23KVS9HEEGVRD4X35H542K100SC u1)
(map-set mint-passes 'SP2B53GAM9MH4MDA8RNKPDHXGC8X2YG7HKTPRPKP8 u1)
(map-set mint-passes 'SP2DFZRT48FTXK4SDYVMYK72TETEQ7W33S9RWK168 u3)
(map-set mint-passes 'SP2EFHG2729NAJ0YAMVKXTQV22HJ5ZW5SC9BVWHJ0 u2)
(map-set mint-passes 'SP2EMZSA1CQQCGJEQ9JSDBWBV0NFDJ59EH5P9E56V u1)
(map-set mint-passes 'SP2F18PH7FP22EHS0J0X3A6EFZ9PAW0EZJRET0GXZ u4)
(map-set mint-passes 'SP2F2KH0RVX6GF1Y9FWMMSR9RHG0TW3NN72D724NX u2)
(map-set mint-passes 'SP2F40S465JTD7AMZ2X9SMN229617HZ9YB0HHY98A u1)
(map-set mint-passes 'SP2HK7J6617VBSKXQGZWMXP2R64MMDX3S54M0S1Q6 u1)
(map-set mint-passes 'SP2HV9HYWZRAPTCC10VXCK72P3W4F9NDB8E1HBEZH u60)
(map-set mint-passes 'SP2HVP68NY5BD2RDFX0JNXSYRS8AA6R7S30N08NJZ u2)
(map-set mint-passes 'SP2HX7247FTWB9FEM3J5CKJ3H3FKZ51C4D3XABFT u2)
(map-set mint-passes 'SP2KD44XNHAXEPY4WXDQDCM596DNM68N29EGWJJ52 u2)
(map-set mint-passes 'SP2KJC2WBNJPGVRB0GG30666PQW96MAKH7YWGPWB0 u4)
(map-set mint-passes 'SP2M1RTDQ80NXSTKF25357P7X9APWCZRHXQSSG59K u1)
(map-set mint-passes 'SP2MS5KKM4CFTC6C6H2QAB7BKYBSNXWZKVCCXBMQG u1)
(map-set mint-passes 'SP2NHZDAMMEEASE4DKHYYCVAG8RF8PA7YHPPW40BX u1)
(map-set mint-passes 'SP2Q1SZSETS27AZ9FE0BH6C6B7MVC25E4N6C2VE7D u3)
(map-set mint-passes 'SP2QDMH88MEZ8FFAYHW4B0BTXJRTHX8XBD54FE7HJ u3)
(map-set mint-passes 'SP2QK20FRJ6N1XZ0T6RGF180RVQ62HPR1NAFMYTVB u1)
(map-set mint-passes 'SP2R3CHRAP1HE4M64X1NZXHZT41JG3XGNHJW4HX2W u14)
(map-set mint-passes 'SP2RVCMFS8C2XZYGMQ36HKZM0PKXDWE8GE64QMQQ1 u2)
(map-set mint-passes 'SP2W7RC4ERS8XKN83MR2KJPJ97DWN68K4064Q7C2W u3)
(map-set mint-passes 'SP2WGW1GPCYM0KXEFW3EK9CEW8ZWRRDPM7GS7DS6F u2)
(map-set mint-passes 'SP2ZD78CEHCFPJ71SB8R0EK0ZMVAGB3NTHK947F06 u4)
(map-set mint-passes 'SP31C9QV5F4XE9E5WHFKD9MZZJ05EJKA0S1G3Z3WQ u1)
(map-set mint-passes 'SP31WTJ415SNJM9H6202S3WK9AFQXQZMT48PESBQE u1)
(map-set mint-passes 'SP329G766AV8Z01X9EEAHPDQ4WDJXT2A0XB383MGP u31)
(map-set mint-passes 'SP3356JJ54Q0YB2Q7EN3ZPV7DAY8E2NAS9P8E2WZ0 u1)
(map-set mint-passes 'SP33N5R751MG99QAM4CN6HQ3MDTYBR71SB4NXVGT1 u4)
(map-set mint-passes 'SP348W0HYCX8N7BWDNJKPHTYXAE6S84SAKVG5BKGS u2)
(map-set mint-passes 'SP35DJDPDNCYRPMTDW10YCQFA29HWXK2S3W5FKFA7 u4)
(map-set mint-passes 'SP35E73RP0EV411FP3Y34GX89P171VHWSF7QKC8JT u1)
(map-set mint-passes 'SP364J7EDJXRE1FPDZDABP9M58HPY4G88BFCP2HD0 u2)
(map-set mint-passes 'SP36TTA0SPPD8TBHZ01D0X7KND69ZH488C5JH57H3 u2)
(map-set mint-passes 'SP38K2HQ505BBMB3GH5HYJZ6VT8W190XVBKXDPEJB u1)
(map-set mint-passes 'SP3AFTJ38PSZQBXZGNCDGM05GR0SFY7HBPZD2ACR2 u2)
(map-set mint-passes 'SP3ANCQYYYFKD0CKX140V498DMY9W1RH0FPHX3QGN u1)
(map-set mint-passes 'SP3AQSW210PFW6K3FB1JW62ZHTH11FSVR0SH5AZ6P u3)
(map-set mint-passes 'SP3B84QWAXRAKB67Z4TB33SY5G0BGGVQC36526QN6 u4)
(map-set mint-passes 'SP3BRRCHKMPBR60V8ES9J5YF40VXWMABWXK4SEB9G u1)
(map-set mint-passes 'SP3C5JYPB8YE5H9WC2SM196RVJ0JXN2GHCWXJWSES u3)
(map-set mint-passes 'SP3C5W9RSSYG3SVP192DCQY4Z2WQWPJ9YEERKTPSY u10)
(map-set mint-passes 'SP3CRGM0QHHD36B57FXZW60EQS7NM6XJK8WC7T34S u1)
(map-set mint-passes 'SP3CXP82SP2M920C5XX42RMAJ3Y6FS0KS5ZK1N1BC u2)
(map-set mint-passes 'SP3D5EHK8SMJ3MMJWYCAKWJ2H4F1JQX85E33ZJDB9 u5)
(map-set mint-passes 'SP3DRN2BP4KM2WFG4W59Q5DPW5QQ5HHSZB76M7T33 u2)
(map-set mint-passes 'SP3E2VDGSYDBX7KSY5MS600RDDAWDWXPTA66N6331 u3)
(map-set mint-passes 'SP3FQTGMJXM9743HJZMV31QGGRGHHZ2DTWPFNRNBK u1)
(map-set mint-passes 'SP3G9BMCJ0858Y68MM35R6HA0WAZDNYXWZBN4RYK1 u1)
(map-set mint-passes 'SP3HYFVG35TW1RF47N6RKYYDNPX6T47J6ZJB3B4PE u1)
(map-set mint-passes 'SP3JPR7XNR60AMBBEZAGF1YHRSFY1JCKE14HBKGTY u1)
(map-set mint-passes 'SP3K22XKPT9WJFCE957J94J6XXVZHP7747YNPDTFD u2)
(map-set mint-passes 'SP3KXV3J6MRHAH4H89MDS390X1KS0GQN4DWQ5RFVB u71)
(map-set mint-passes 'SP3M16X85R7ED2RR70ANNB3X0HXPHGSAXBEGGZKK0 u19)
(map-set mint-passes 'SP3MMG05H6T48W5NJEEST0RR3FTPGKPM7C19X5M16 u2)
(map-set mint-passes 'SP3MQWSKAESKY7JFBS88GFQ47AZDKC3XH3ZHTWWYT u1)
(map-set mint-passes 'SP3N6EZPTSX8ZV2RGPY9NR9A8CA0QET39CY978H5E u1)
(map-set mint-passes 'SP3P8M5J25457Q73MKS8EGD5Z19Z57RKYSPNEAK85 u1)
(map-set mint-passes 'SP3PV1W0CX2F0B382FPC5C412VAB3A3TK84RCFB5N u1)
(map-set mint-passes 'SP3QBRHQF4BN8HNNGFHCJMQZDB8V20BMGF2VS3MJ2 u5)
(map-set mint-passes 'SP3R4NKXMGW6YXA44X2ESZPKJNV25X4ZN7DPW0RXR u3)
(map-set mint-passes 'SP3R7Q3QMTYC4QR0RFDR9HZBWNBNBNDA7S549CR6Y u1)
(map-set mint-passes 'SP3RE5RYJQFAHVC8XC94RHGNGBTA52SBDEGQE9Y5W u2)
(map-set mint-passes 'SP3SF0PSD7KYVJQPKKRBYJFF7NENGFHZSBVHM3B27 u4)
(map-set mint-passes 'SP3ST6K5W36V2MTSNYYXE56SCXR7DGTW9N4NMZHYV u1)
(map-set mint-passes 'SP3T7SA543GTWEPD3022B66RYN2WZ4SQW64S686AA u1)
(map-set mint-passes 'SP3T7WAB5DMJ3JSRMCQF6SC7CG50DYYJVS4C303CN u2)
(map-set mint-passes 'SP3VTWA4VHJXCC82898M21QSRQCYC730K49M5NMKF u1)
(map-set mint-passes 'SP3WBYAEWN0JER1VPBW8TRT1329BGP9RGC5S2519W u1)
(map-set mint-passes 'SP3WD2M5Q3HW5RSHKF2XAD2EAFNDZGDT2J67YDYR0 u2)
(map-set mint-passes 'SP3WK60BC1J5CPQVAFYCDME148EY0BST1Q2E6K66A u1)
(map-set mint-passes 'SP3WKZWBE7F7GR91GPFDNTT65A2J8WA8KZC9MFKQJ u1)
(map-set mint-passes 'SP3WSEATAT4VFFR6KAGX0QXS13E491TV64ZD1E4YY u4)
(map-set mint-passes 'SP3XVFQ1AB7DD5N19GS0412CG4JG7XWSBYAG98PVW u7)
(map-set mint-passes 'SP3ZMEFW7VH796ZQAH1JMAJT4WC4VPEZZFB6W5CAD u2)
(map-set mint-passes 'SP3ZTYBN9PYVVFKBEFVSZ2BEGK3HXRNVP6FDG79WV u1)
(map-set mint-passes 'SP4JRVAABXMXVNSA023C4KW3MEHND6BGRPQK51NB u4)
(map-set mint-passes 'SP4QA0NHP03T3T9GJKR5KEA7VQ2KNSXRK5JC74NG u1)
(map-set mint-passes 'SP5MJB2231XSTW82MEX7S7HRHAAM918CVJETR0K4 u1)
(map-set mint-passes 'SP6VV2AFXM7ZMT5V3ZAE8M6JXK9EA5N1GPFHJC4M u1)
(map-set mint-passes 'SP6X8X0JN8RX0Q1SFZDTPKB0QS1KWY3QMJTKH63D u1)
(map-set mint-passes 'SP71N7X6G8KYGQPHZW7TB4PD1JZ6ND9AESF9JPZ8 u2)
(map-set mint-passes 'SP779SC9CDWQVMTRXT0HZCEHSDBXCHNGG7BC1H9B u7)
(map-set mint-passes 'SP84C5YVBTBSXZ8KS39R97QDKX1YNSXXR8814ET7 u1)
(map-set mint-passes 'SPA9AS2QY0959QA46W46872ZDHJ2SWYPRVWPCP2S u1)
(map-set mint-passes 'SPACX3N484ES8NXN0V7S9BZSG67FRN50N2XC4ECJ u1)
(map-set mint-passes 'SPAFJKGDVS11C9P9DY0ZTNFQ9774R568W9XYZDJV u11)
(map-set mint-passes 'SPBFZ5MRGDMEKWNQTJ57W2PA2GC0765ZFC5BY0KP u1)
(map-set mint-passes 'SPCBX0GCHMK9GP717F23ZP7V2NM2A0EJ8D634N44 u1)
(map-set mint-passes 'SPDXC0NM3YQDHV1HN3V9P5Y4P26QWY709NB86EYB u4)
(map-set mint-passes 'SPFXQK7QMGCYWJ5DTATS96N7FAEXNRNZM3FMB1AJ u1)
(map-set mint-passes 'SPHK8A7P61C6ASWKYDX1PCDX9YA54DKVJN49EXGJ u1)
(map-set mint-passes 'SPJSCH3DDEJ8GQPGYZBHSB4F3HX5Q222CG89PSAB u29)
(map-set mint-passes 'SPK9KP81Q281Q84SPGAMK8J12X2AQQJGT0XFPPCX u1)
(map-set mint-passes 'SPKDTG14Y6G5T0678WP1Q47S5MTHNP2TD0Q0NF0W u1)
(map-set mint-passes 'SPKFSJ4T8T39ZJN455QBY7TJX4DYF47J7344HNNF u1)
(map-set mint-passes 'SPM1Q7YG18378H6W254YN8PABEVRPT38ZCY01SJD u24)
(map-set mint-passes 'SPN0DSRZGFNGE6D59S4ZRF8GP604NDTSQ9RRS2BM u2)
(map-set mint-passes 'SPPMGZTRGMBVCFW3RMEVQJEF26MW9G6EKT51EMD8 u1)
(map-set mint-passes 'SPQ2HN9TYF8ZYY9D3G45NGYA9GHA6QZHQ8AXF5QM u6)
(map-set mint-passes 'SPRGJGNR5MJF34F9V11E148M2X6VSQ4P26021QZC u1)
(map-set mint-passes 'SPRX8W53YWFKB61CAMRH4WPT3N1SD7H2KCZTH9Z3 u1)
(map-set mint-passes 'SPS2RBYAXSCXMVPYXSG724CFY4W2WA2NPG44V191 u1)
(map-set mint-passes 'SPS6543QSVCWM0B1CQYD67RV4QP3MGFPJEHG4FHS u3)
(map-set mint-passes 'SPSS7WAYA17Y8Z5Q6GJTMH4FH4MRJ7HZZ6JPGAGR u2)
(map-set mint-passes 'SPTD7KKZG68EZBNSXDHAEJT4JDNB7SZ107H35WTK u1)
(map-set mint-passes 'SPV00QHST52GD7D0SEWV3R5N04RD4Q1PMA3TE2MP u2)
(map-set mint-passes 'SPV48Q8E5WP4TCQ63E9TV6KF9R4HP01Z8WS3FBTG u9)
(map-set mint-passes 'SPXQS1T1T2BKGSHH8H75PVFEY0R1X39F0B3MQWTJ u1)
(map-set mint-passes 'SPYAX2RNZA18KQA8Y0S5G393QBE8SWPNZ6R08XNH u1)
(map-set mint-passes 'SPZD3EE1M7YMH3RCKNQE1CGPA4VDTGMDCT2QWGQN u2)
(map-set mint-passes 'SP2RKVC8PYANWJ40VSRCK2K935HSN4H0AHTVHD73D u3)
;; Airdrop
(define-public (admin-airdrop)
  (let
    (
      (last-nft-id (var-get last-id))
    )
    (begin
      (asserts! (or (is-eq tx-sender (var-get artist-address)) (is-eq tx-sender DEPLOYER)) (err ERR-NOT-AUTHORIZED))
      (asserts! (is-eq false (var-get airdrop-called)) (err ERR-AIRDROP-CALLED))
      (try! (nft-mint? metacine (+ last-nft-id u0) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u1) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u2) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u3) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u4) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u5) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u6) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u7) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u8) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u9) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u10) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u11) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u12) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u13) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u14) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u15) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u16) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u17) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u18) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u19) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u20) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u21) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u22) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u23) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u24) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u25) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u26) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u27) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u28) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u29) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u30) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u31) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))
      (try! (nft-mint? metacine (+ last-nft-id u32) 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0))
      (map-set token-count 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0 (+ (get-balance 'SP22GHCK5W3EK5VC1PEB3VVCBVFRQNTQXV9306QA0) u1))

      (var-set last-id (+ last-nft-id u33))
      (var-set airdrop-called true)
      (ok true))))