Skip to content

Commit

Permalink
add new contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
friedger authored and github-actions[bot] committed Oct 3, 2023
1 parent 9c20667 commit ed5450f
Show file tree
Hide file tree
Showing 4 changed files with 540 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
;; sir-winston-of-sourek-club
;; contractType: continuous

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

(define-non-fungible-token sir-winston-of-sourek-club 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 'SP1C93AD4JFXD5V7H2DNTR60JR3P5ZTDFWEPSHPJ4)
(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? sir-winston-of-sourek-club 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? sir-winston-of-sourek-club 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? sir-winston-of-sourek-club 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? sir-winston-of-sourek-club 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? sir-winston-of-sourek-club 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? sir-winston-of-sourek-club 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? sir-winston-of-sourek-club 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? sir-winston-of-sourek-club u1 'SP1C93AD4JFXD5V7H2DNTR60JR3P5ZTDFWEPSHPJ4))
(map-set token-count 'SP1C93AD4JFXD5V7H2DNTR60JR3P5ZTDFWEPSHPJ4 (+ (get-balance 'SP1C93AD4JFXD5V7H2DNTR60JR3P5ZTDFWEPSHPJ4) u1))
(map-set cids u1 "QmSaUiKrmgXpBMc44RPRm3CVpYrEqdtZbtRMtzfzG8MfzL/json/1.json")
(var-set last-id u1)

(define-data-var license-uri (string-ascii 80) "https://arweave.net/zmc1WTspIhFyVY82bwfAIcIExLFH5lUcHHUN0wXg4W8/3")
(define-data-var license-name (string-ascii 40) "COMMERCIAL-NO-HATE")

(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))))
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@

;; version: 1
;; name: fuckb
;; namespace: btc

(use-trait commission-trait 'SP3D6PV2ACBPEKYJTCMH7HEN02KP87QSP8KTEH335.commission-trait.commission)

(define-constant DEPLOYER_CONTRACT_PRINCIPAL (as-contract tx-sender))
(define-constant COMM-ADDR 'SP7NDX6YRAH6C99WCZJWKF2SYR1GQRF7X6894QSJ)

(define-constant ERR-ALREADY-LISTED (err u401))
(define-constant ERR-WRONG-COMMISSION (err u402))
(define-constant ERR-NOT-AUTHORIZED (err u403))
(define-constant ERR-NOT-FOUND (err u404))
(define-constant ERR-WRONG-PRICE (err u405))
(define-constant ERR-TRANSFER-FAILED (err u500))

(define-data-var current-namespace (buff 20) 0x00)
(define-data-var current-name (buff 48) 0x00)

(define-map listings { namespace: (buff 20), name: (buff 48) } { price: uint, lister: principal, commission: principal })

(define-read-only (is-admin)
(is-eq tx-sender COMM-ADDR)
)

(define-read-only (get-listing)
(map-get? listings { namespace: (var-get current-namespace), name: (var-get current-name) })
)

(define-read-only (get-current-name)
{ namespace: (var-get current-namespace), name: (var-get current-name) }
)

(define-private (list-name (namespace (buff 20)) (name (buff 48)) (price uint) (commission <commission-trait>))
(begin
(asserts! (is-none (get-listing)) ERR-ALREADY-LISTED)
(try! (to-bool-response (contract-call?
'SP000000000000000000002Q6VF78.bns
name-transfer
namespace
name
DEPLOYER_CONTRACT_PRINCIPAL
none
)))
(var-set current-namespace namespace)
(var-set current-name name)
(ok (map-set listings {name: name, namespace: namespace}
{price: price, lister: tx-sender, commission: (contract-of commission)}))
)
)

(define-public (change-price (namespace (buff 20)) (name (buff 48)) (new-price uint) (commission <commission-trait>))
(let (
(listing (unwrap! (map-get? listings {namespace: namespace, name: name}) ERR-NOT-FOUND))
(price (get price listing))
(lister (get lister listing)))
(asserts! (is-eq tx-sender lister) ERR-NOT-AUTHORIZED)
(ok (map-set listings { namespace: namespace, name: name } { price: new-price, lister: lister, commission: (contract-of commission) }))
)
)

(define-public (unlist-name (namespace (buff 20)) (name (buff 48)))
(let (
(listing (unwrap! (map-get? listings {namespace: namespace, name: name}) ERR-NOT-FOUND))
(price (get price listing))
(lister (get lister listing)))
(asserts! (or (is-eq tx-sender lister) (is-admin)) ERR-NOT-AUTHORIZED)
(map-delete listings {namespace: namespace, name: name})
(as-contract
(to-bool-response (contract-call?
'SP000000000000000000002Q6VF78.bns
name-transfer
namespace
name
lister
none
))
)
)
)

(define-public (purchase-name (namespace (buff 20)) (name (buff 48)) (expected-price uint) (commission <commission-trait>) (recipient (optional principal)))
(let (
(new-owner (if (is-some recipient) (unwrap-panic recipient) tx-sender))
(listing (unwrap! (map-get? listings {namespace: namespace, name: name}) ERR-NOT-FOUND))
(price (get price listing))
(lister (get lister listing))
(list-commission (get commission listing))
)
(asserts! (is-eq (contract-of commission) list-commission) ERR-WRONG-COMMISSION)
(asserts! (is-eq price expected-price) ERR-WRONG-PRICE)
(try! (contract-call? commission pay u0 price))
(try! (stx-transfer? price tx-sender lister))
(map-delete listings {namespace: namespace, name: name})
(to-bool-response (as-contract
(contract-call?
'SP000000000000000000002Q6VF78.bns
name-transfer
namespace
name
new-owner
none
)
))
)
)

(define-public (withdraw-stx (amount uint))
(let (
(listing (unwrap! (get-listing) ERR-NOT-FOUND))
(lister (get lister listing))
)
(asserts! (or (is-eq tx-sender lister) (is-admin)) ERR-NOT-AUTHORIZED)
(try! (as-contract (stx-transfer? amount tx-sender lister)))
(ok amount)
)
)

(define-private (to-bool-response (value (response bool int)))
(match value
success (ok success)
error (err (to-uint error))))

(list-name 0x627463 0x6675636b62 u96618358 'SPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S.gamma-commission-3-5)

Loading

0 comments on commit ed5450f

Please sign in to comment.