From 777a5f312fd154ad86fe679b2fbfc52da6785c84 Mon Sep 17 00:00:00 2001 From: friedger Date: Fri, 20 Oct 2023 01:09:52 +0000 Subject: [PATCH] add new contracts --- .../bns-1697707327549-v1.clar | 126 +++++ .../nonnish-greebles.clar | 504 ++++++++++++++++++ .../bns-1697751232638-v1.clar | 126 +++++ .../bns-1697708319671-v1.clar | 126 +++++ .../bns-1697735159110-v1.clar | 126 +++++ .../bns-1697702107649-v1.clar | 126 +++++ .../brc20-bridge-endpoint-dev-preview-6.clar | 188 +++++++ .../indexer-dev-preview-7.clar | 144 +++++ .../indexer-registry-dev-preview-2.clar | 70 +++ .../bns-1697710634765-v1.clar | 126 +++++ .../bns-1697698898462-v1.clar | 126 +++++ last-block.txt | 2 +- 12 files changed, 1789 insertions(+), 1 deletion(-) create mode 100644 contracts/SP14B8X5N1JD3WZEY55CR4VBEN7XGS22NEK12BCDN/bns-1697707327549-v1.clar create mode 100644 contracts/SP1D3Y8A2VVD2W98VFXCG5AXRYX5PJBBEMV1YPKF1/nonnish-greebles.clar create mode 100644 contracts/SP2D7DHG09B4E0AY4X8YRA6B8R5XFA8R14BWM3ZE0/bns-1697751232638-v1.clar create mode 100644 contracts/SP2NGYP1BPT8T4JFZJ23SAWCGXWSMMKBM8JJ3QW0F/bns-1697708319671-v1.clar create mode 100644 contracts/SP34YCV5E1QDAZH6S1JYZWPFSJ06BTZQ93D8DJ5M0/bns-1697735159110-v1.clar create mode 100644 contracts/SP3J80WHJXPZ1QG42PWKS3PHMNBMSKJ8BAZKMR41W/bns-1697702107649-v1.clar create mode 100644 contracts/SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9/brc20-bridge-endpoint-dev-preview-6.clar create mode 100644 contracts/SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9/indexer-dev-preview-7.clar create mode 100644 contracts/SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9/indexer-registry-dev-preview-2.clar create mode 100644 contracts/SP5EZFA3N8PBTSG24AB60SH71ZSWG96CEF6KTSTB/bns-1697710634765-v1.clar create mode 100644 contracts/SPYXBZDP6SQ1WPNAAB0MXEY8ETJ58SHDRNNFSMNG/bns-1697698898462-v1.clar diff --git a/contracts/SP14B8X5N1JD3WZEY55CR4VBEN7XGS22NEK12BCDN/bns-1697707327549-v1.clar b/contracts/SP14B8X5N1JD3WZEY55CR4VBEN7XGS22NEK12BCDN/bns-1697707327549-v1.clar new file mode 100644 index 0000000000..568c4dd283 --- /dev/null +++ b/contracts/SP14B8X5N1JD3WZEY55CR4VBEN7XGS22NEK12BCDN/bns-1697707327549-v1.clar @@ -0,0 +1,126 @@ + + ;; version: 1 + ;; name: russiabitcoin + ;; 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 )) + (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 )) + (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 ) (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 0x727573736961626974636f696e u96618357488 'SPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S.gamma-commission-3-5) + \ No newline at end of file diff --git a/contracts/SP1D3Y8A2VVD2W98VFXCG5AXRYX5PJBBEMV1YPKF1/nonnish-greebles.clar b/contracts/SP1D3Y8A2VVD2W98VFXCG5AXRYX5PJBBEMV1YPKF1/nonnish-greebles.clar new file mode 100644 index 0000000000..1690120c26 --- /dev/null +++ b/contracts/SP1D3Y8A2VVD2W98VFXCG5AXRYX5PJBBEMV1YPKF1/nonnish-greebles.clar @@ -0,0 +1,504 @@ +;; nonnish-greebles +;; contractType: public + +(impl-trait 'SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait.nft-trait) + +(define-non-fungible-token nonnish-greebles 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 u1000) +(define-data-var last-id uint u1) +(define-data-var total-price uint u0) +(define-data-var artist-address principal 'SP1D3Y8A2VVD2W98VFXCG5AXRYX5PJBBEMV1YPKF1) +(define-data-var ipfs-root (string-ascii 80) "ipfs://ipfs/Qme9CJE36oWcm4qGgde1WDF9nbqwS2bkjcdDVL55BzV7Fj/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))) + +(define-public (claim-four) (mint (list true true true true))) + +(define-public (claim-five) (mint (list true true true true true))) + +(define-public (claim-six) (mint (list true true true true true true))) + +(define-public (claim-seven) (mint (list true true true true true true true))) + +(define-public (claim-eight) (mint (list true true true true true true true true))) + +(define-public (claim-nine) (mint (list true true true true true true true true true))) + +(define-public (claim-ten) (mint (list true true true true true true true true true true))) + +(define-public (claim-fifteen) (mint (list true true true true true true true true true true true true true true true))) + +(define-public (claim-twenty) (mint (list true true true true true true true true true true true true true true true true true true true true))) + +(define-public (claim-twentyfive) (mint (list true true true true true true true true true true true true true true true true true true true true true true 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? nonnish-greebles 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? nonnish-greebles token-id tx-sender))) + +(define-private (is-owner (token-id uint) (user principal)) + (is-eq user (unwrap! (nft-get-owner? nonnish-greebles 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? nonnish-greebles 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? nonnish-greebles 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? nonnish-greebles 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 )) + (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 )) + (let ((owner (unwrap! (nft-get-owner? nonnish-greebles 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 'SPVCMKZTGYMKYJEHFN4FABNFBBYMM02HNF66A6N6 u105) +(map-set mint-passes 'SP329G766AV8Z01X9EEAHPDQ4WDJXT2A0XB383MGP u62) +(map-set mint-passes 'SP31WTJ415SNJM9H6202S3WK9AFQXQZMT48PESBQE u51) +(map-set mint-passes 'SP12391ZGS5YJXHXVJPQ0DVTB3M8AQNAQGYEH72ZR u50) +(map-set mint-passes 'SPM1Q7YG18378H6W254YN8PABEVRPT38ZCY01SJD u49) +(map-set mint-passes 'SP32CF0E78JNPK0HYDTH3CCZ8FN76PFX5W0FYBN20 u30) +(map-set mint-passes 'SP3QBRHQF4BN8HNNGFHCJMQZDB8V20BMGF2VS3MJ2 u29) +(map-set mint-passes 'SP1FR2M102H4DE4DH96R4D29RC8AGQZG5D5Y4S7CH u25) +(map-set mint-passes 'SP18WRH4SF7F1M5QZZ2BQDZZYBCJWT9VWQMDSTFY5 u23) +(map-set mint-passes 'SP3AQSW210PFW6K3FB1JW62ZHTH11FSVR0SH5AZ6P u22) +(map-set mint-passes 'SP1TQZS5G1Y47KXWQE8WG2Q606664A7MFMPVCKHRZ u21) +(map-set mint-passes 'SP1XGVC95Z0HPG50YPEV5XZB5YA08DC29B0XZWBWN u20) +(map-set mint-passes 'SP1F9156MENFJTEWE6WJPMVWFAHNGKGC7YJX6HK72 u19) +(map-set mint-passes 'SPS2FZ3K6N2CZPBM4BSQCEQV23V2334E7MJ4CHZT u19) +(map-set mint-passes 'SPQ2HN9TYF8ZYY9D3G45NGYA9GHA6QZHQ8AXF5QM u19) +(map-set mint-passes 'SP2DFZRT48FTXK4SDYVMYK72TETEQ7W33S9RWK168 u18) +(map-set mint-passes 'SPQY88E87FNMP1NTY2YQ7X5DPTVY810PS8T6D2Y3 u17) +(map-set mint-passes 'SP197GMEG6WGBRDTCTGGWMRA1G77E65TRXWYKGCT7 u16) +(map-set mint-passes 'SP3EPS563XJNK170J902C78ZPDPNXVZFWWCN7DGWH u15) +(map-set mint-passes 'SP2791RKSYJJ39MVHC09J8NARWBMK5G9C79EJB0RV u15) +(map-set mint-passes 'SP3C5W9RSSYG3SVP192DCQY4Z2WQWPJ9YEERKTPSY u14) +(map-set mint-passes 'SPSS7WAYA17Y8Z5Q6GJTMH4FH4MRJ7HZZ6JPGAGR u14) +(map-set mint-passes 'SP71N7X6G8KYGQPHZW7TB4PD1JZ6ND9AESF9JPZ8 u13) +(map-set mint-passes 'SP12BEEDG31J0AH68DFDJJYZ36D002PKDZCP1DZQE u12) +(map-set mint-passes 'SP2KSK3WJ1TJWMBWWEAA5043ARA21ZNFCARTHT8EZ u12) +(map-set mint-passes 'SP364J7EDJXRE1FPDZDABP9M58HPY4G88BFCP2HD0 u12) +(map-set mint-passes 'SP3Z7511VWR5WG9J3MAKER3NRZYKWT83K2XTP36EV u11) +(map-set mint-passes 'SP3KXV3J6MRHAH4H89MDS390X1KS0GQN4DWQ5RFVB u10) +(map-set mint-passes 'SP3SC5PSKQM9ABTYPNYDV1J7SBGHA08VRW1DKTJK6 u10) +(map-set mint-passes 'SP4QA0NHP03T3T9GJKR5KEA7VQ2KNSXRK5JC74NG u9) +(map-set mint-passes 'SP2F18PH7FP22EHS0J0X3A6EFZ9PAW0EZJRET0GXZ u9) +(map-set mint-passes 'SP1T07GK9H4M0WP4N1DSSA7NJ7GNTQZ0GBZM0GAR2 u8) +(map-set mint-passes 'SP2TW1D8YF5CE0NDP5VCR5NMTPHQ4PQR1KBB4NQ5Q u8) +(map-set mint-passes 'SP342MMZRDFSC556F193N76D87SCTYX7SSHD8H3XD u8) +(map-set mint-passes 'SP3GG2XRSX2APJ1JFWV2A3KFEJPAJ5X8JGDXTSF1N u6) +(map-set mint-passes 'SPV48Q8E5WP4TCQ63E9TV6KF9R4HP01Z8WS3FBTG u6) +(map-set mint-passes 'SP247RS63PWW7ZQZ9EYYA9CXKKPWEP71M14W8N294 u6) +(map-set mint-passes 'SP1XZ7KEMJT5V8ATRYZB0XWJ20KMGM37JXJZG9D6S u6) +(map-set mint-passes 'SP3GNAE8V8KZ24T31JC10TT184F6NQ4YDYHGVFZ10 u5) +(map-set mint-passes 'SP16PPSNDG265N42ZG7GPDADAAAMQCDY9MT6TN4XY u5) +(map-set mint-passes 'SP28RZ1QXMXJXVKRRCR3D7GR5D48XY0NNA9MZWHJB u5) +(map-set mint-passes 'SP1A9NAK7RCXN0E47D95X5E0VY0HPAAA0VVC2M322 u5) +(map-set mint-passes 'SPJSCH3DDEJ8GQPGYZBHSB4F3HX5Q222CG89PSAB u5) +(map-set mint-passes 'SP1QZT85MFT8HBAG3XEK7K6QY4GGP3MSG5C3H9PQ1 u4) +(map-set mint-passes 'SP1XAR0A0J2AFWXQXCJ07SPV3TSZV2BCQQAQ6H5B5 u4) +(map-set mint-passes 'SP3ST6K5W36V2MTSNYYXE56SCXR7DGTW9N4NMZHYV u4) +(map-set mint-passes 'SP32QTYYGG6SWTP198FST4SPM85J0A3JPNB9S2BEA u4) +(map-set mint-passes 'SPHWCHVHRY2Q4884XNNSV8B3J1T41PBN0GQE16A9 u4) +(map-set mint-passes 'SP3JPR7XNR60AMBBEZAGF1YHRSFY1JCKE14HBKGTY u4) +(map-set mint-passes 'SP3ZY51K23M753B7S2CG823Y47EE80RC3ZMYJ78X u4) +(map-set mint-passes 'SP33N5R751MG99QAM4CN6HQ3MDTYBR71SB4NXVGT1 u4) +(map-set mint-passes 'SP3Q1VW36FD1HF4J0EFRF2E486QGYNYJASB9PKDKF u3) +(map-set mint-passes 'SP19WSDJWTH4CW3YG554XS5CAXJJGAN83P8CFZ4K1 u3) +(map-set mint-passes 'SPN9JGFGXFJZD7AM5VF2S7BRATNCQYVHVWG3087B u3) +(map-set mint-passes 'SP3G9BMCJ0858Y68MM35R6HA0WAZDNYXWZBN4RYK1 u3) +(map-set mint-passes 'SPXZ0GWQTMGQ860MGG86PNMFJNHJ2NWJSWJWGM0K u3) +(map-set mint-passes 'SPDXC0NM3YQDHV1HN3V9P5Y4P26QWY709NB86EYB u3) +(map-set mint-passes 'SP2W0KJMJB2601KK53Y7F8W9FV5YJ1QVCT0GBJHTA u3) +(map-set mint-passes 'SP2HK9TYP0662DZMM6FSC2T18BG18YXE0N037JT08 u3) +(map-set mint-passes 'SP1MHYF45ZRE9QCG4SRHB72W65K89Q48FSQR4PDNK u3) +(map-set mint-passes 'SP1HHSDYJ0SGAM6K2W01ZF5K7AJFKWMJNH365ZWS9 u3) +(map-set mint-passes 'SP1DPNP3RRD6JG1557SP6JMX68W5BV6R2Z74BQEXV u3) +(map-set mint-passes 'SPFK6E20DN1PFBY02956QN23TCWSPHMY76KYWGEZ u3) +(map-set mint-passes 'SP2MMK0WPM6Y5VMKZ87RBSDC0J66FTTYM7GVWCN0Z u3) +(map-set mint-passes 'SPV00QHST52GD7D0SEWV3R5N04RD4Q1PMA3TE2MP u3) +(map-set mint-passes 'SP3WXWMD8NC947EASJCMCVT11YDDMBHPXT8WE9WMF u3) +(map-set mint-passes 'SP265DNHNK1NHX7FE9MZKCCA4G1VS7TT3BMES5TR u3) +(map-set mint-passes 'SP3BRAY8T6S1K7WDCPM9CEEA00XMZD33PE9V4JT8C u3) +(map-set mint-passes 'SP26SB34D9THJ8BMSPT6EJHW9JDGBHWMX74PVDFEN u3) +(map-set mint-passes 'SP1JCPNPAMAQJ364AFHPTW3HY7X0HYZ3TJ0ZDGWZH u3) +(map-set mint-passes 'SP3JJC9CVH2251JC0B4QTPS661H6JNTA2P9E6HA6N u3) +(map-set mint-passes 'SP32DFA3HXYZ2BV3P8H6XQM8EN94D2212QM71BRYG u3) +(map-set mint-passes 'SP3BWAHYMTHQZHSB8N49AXQNTYWBACQBAN8Z4QFRD u2) +(map-set mint-passes 'SP3T7WAB5DMJ3JSRMCQF6SC7CG50DYYJVS4C303CN u2) +(map-set mint-passes 'SP1GNB1KSWAB2SK9GWZ9A1R8HSYKWKBBQ40QP240F u2) +(map-set mint-passes 'SP2RQXNR5Z9W4TW0TH9Y0FJEY19F61G1SD726AV9H u2) +(map-set mint-passes 'SP1XPG9QFX5M95G36SGN9R8YJ4KJ0JB7ZXNH892N6 u2) +(map-set mint-passes 'SPE6KAAKXSC0QSGG17SWYPX5R2KP3Q56V9KD88TP u2) +(map-set mint-passes 'SPJCSG2ZJD95JR4QG9Z0EP786WN7T3CAF7GKBD01 u2) +(map-set mint-passes 'SP3356JJ54Q0YB2Q7EN3ZPV7DAY8E2NAS9P8E2WZ0 u2) +(map-set mint-passes 'SP3K22XKPT9WJFCE957J94J6XXVZHP7747YNPDTFD u2) +(map-set mint-passes 'SPV5GYRXDQRYQKZW7FFAZDNRRNVFS41P3YZWXFGD u2) +(map-set mint-passes 'SP2SFZX1WJSKT1GA2STDT6E5NWDX44GW4BB8DW4DJ u2) +(map-set mint-passes 'SP2QDMH88MEZ8FFAYHW4B0BTXJRTHX8XBD54FE7HJ u2) +(map-set mint-passes 'SPTETNN57BDV0X796ZVW41B5VVN99JQRDH68Z5W6 u2) +(map-set mint-passes 'SP25KJH4N4YNKTVXSWSHDPVCWDFAN2BA4H2VQVN0G u2) +(map-set mint-passes 'SPRXRB7J5SF0N0XQJF1FK332H5VZ67ZA5Y9Q036S u2) +(map-set mint-passes 'SP2MC6PBPNPSEHA6G87DDMN6WX3HGMTANXZBYKCNF u2) +(map-set mint-passes 'SP2NBCT6WVMD8PX46VTNRT4ENTQBZZ8ZYYYZY65RB u2) +(map-set mint-passes 'SP3XVFQ1AB7DD5N19GS0412CG4JG7XWSBYAG98PVW u2) +(map-set mint-passes 'SP2C8P3MM137K1A48D1SRENG67KHEVPZV4K36G3JY u2) +(map-set mint-passes 'SP3PZGB6ZXH1G9K158H56A6TF26X7K1GGMAGMW0M3 u2) +(map-set mint-passes 'SPYF9PC72BSWS0DGA33FR24GCG81MG1Z96463H68 u2) +(map-set mint-passes 'SP3CXP82SP2M920C5XX42RMAJ3Y6FS0KS5ZK1N1BC u2) +(map-set mint-passes 'SPFERFF3QKF0Q6WBC4Y2Y6RQWEGN3DTDD5Y7S0NY u2) +(map-set mint-passes 'SP1PCEAP62X5BZSMH257ZHAPGAPSX3BDT3TDVCN4M u2) +(map-set mint-passes 'SP3R5TCK97NMBS1V1MARCK0YTDFWG1FKJ94EFQTF4 u2) +(map-set mint-passes 'SP2KD44XNHAXEPY4WXDQDCM596DNM68N29EGWJJ52 u2) +(map-set mint-passes 'SP216YJTD76S81ZXKVHEBTJT77PSVR33AZ57548V3 u2) +(map-set mint-passes 'SP2RN25RGDZPZQAHGFRPQ31P6QAW82H9H9HVCKDGR u2) +(map-set mint-passes 'SP3GKD03CY339NVCVG0PKKRRC4CAGCECYXNXGQ69 u2) +(map-set mint-passes 'SPP28QCMZ51GVN9933VFH9TXKQ3XCT4WE5A07533 u2) +(map-set mint-passes 'SP26GZCVY8FYHNZ6C73W68TCFJHS8F8C9E772XX7X u2) +(map-set mint-passes 'SP3P8M5J25457Q73MKS8EGD5Z19Z57RKYSPNEAK85 u2) +(map-set mint-passes 'SP23FMJXH1MBKW7H4GTZZTPWHZR21NZACYQE5DEN1 u2) +(map-set mint-passes 'SPS2RBYAXSCXMVPYXSG724CFY4W2WA2NPG44V191 u2) +(map-set mint-passes 'SPXQS1T1T2BKGSHH8H75PVFEY0R1X39F0B3MQWTJ u2) +(map-set mint-passes 'SP1FXY0FASRSJ00BC71YS569RG9JFFG0J51EW42GD u1) +(map-set mint-passes 'SP21M4GV6XA7MKK9Q06GPN6TWVMR27C604AB81FFE u1) +(map-set mint-passes 'SPPMGZTRGMBVCFW3RMEVQJEF26MW9G6EKT51EMD8 u1) +(map-set mint-passes 'SP1CSHTKVHMMQJ7PRQRFYW6SB4QAW6SR3XY2F81PA u1) +(map-set mint-passes 'SP249AVXAABB31ZKDEDSF4S22DD6X2208PXYC6GPP u1) +(map-set mint-passes 'SP2NHZDAMMEEASE4DKHYYCVAG8RF8PA7YHPPW40BX u1) +(map-set mint-passes 'SP2BEFSB43KR4M6C9117SA2A6T4SA6H0X1XDZF716 u1) +(map-set mint-passes 'SP32V5EAKRWZ66VVA67XGDK18VYMZM5NT7NP98M9 u1) +(map-set mint-passes 'SP3VCX5NFQ8VCHFS9M6N40ZJNVTRT4HZ62WFH5C4Q u1) +(map-set mint-passes 'SP1QJDCZ0J9NRPPPZ9186GGBFQZEZM86VKCE19D4T u1) +(map-set mint-passes 'SP1NBCK2JP3KNCHGGM8FGWPT7VFWSCBAXGMJ1WMZB u1) +(map-set mint-passes 'SP3JP1QHR31X0HRX1VM0SEMRAMCEAHC5BR626QX16 u1) +(map-set mint-passes 'SP3TTE9TNNDK1DFP2CHGSQ21P3TQVQNCVWEMSWN21 u1) +(map-set mint-passes 'SPFZJAWND9GDB2QC54524J73DGBQ07XJ6JM1E3GN u1) +(map-set mint-passes 'SP1FZKAJ5V0QSV19RB5T2DG1PJQ6R6MKSB5ZJF5A5 u1) +(map-set mint-passes 'SP17XZQC08H8ASTGNYJ651YGCM5497G9TX8V061SX u1) +(map-set mint-passes 'SP12YGGACNA4R43DB1HAQ3AE03PKPJGXZ1BX96CYB u1) +(map-set mint-passes 'SP4TH5RH19FSBNC54JA8S1V5N9G1GRNPCX39HK5P u1) +(map-set mint-passes 'SP18V7NZHXPQKRNBYAF5WGBV79PDY6XMDNHMZSW4R u1) +(map-set mint-passes 'SP2HV9HYWZRAPTCC10VXCK72P3W4F9NDB8E1HBEZH u1) +(map-set mint-passes 'SP2H94BXVGSH92VD407JX18VZ7S2ZFW2CFT5TJKKZ u1) +(map-set mint-passes 'SP2QAG09GBM8Y9HK05MSC30X0A09VW11T23ES27GX u1) +(map-set mint-passes 'SP3F2QCGP5QZFM19VWXNA1T32T9XCGCMXMMSMT5VH u1) +(map-set mint-passes 'SP30HDQ1WGZRD1YTBRPPPYZHKQJ7E8CVYZCTHXKVX u1) +(map-set mint-passes 'SP35K3WCA9GCJV2XC7X021MR2D9D2PKF855CVCKB0 u1) +(map-set mint-passes 'SP2F40S465JTD7AMZ2X9SMN229617HZ9YB0HHY98A u1) +(map-set mint-passes 'SP1NFRJJFQAA5AB4R8RDA3F0WEBZHK0HQSKW1PPNY u1) +(map-set mint-passes 'SP3WSEATAT4VFFR6KAGX0QXS13E491TV64ZD1E4YY u1) +(map-set mint-passes 'SPJFHQVQNGRWNX90FA49QQ5RGPR31YVVFB3EJ71D u1) +(map-set mint-passes 'SP1ZQSWQ9QNNW388VFG45HYX1H592147V2FZZJY8V u1) +(map-set mint-passes 'SP84C5YVBTBSXZ8KS39R97QDKX1YNSXXR8814ET7 u1) +(map-set mint-passes 'SP14814KM6CBCJZMD15JJ58Q3E2S3NCB6SDXM8C79 u1) +(map-set mint-passes 'SP268V0BZFF2B4VNRGVFM934QR9TKT76M6G6FCKJ u1) +(map-set mint-passes 'SPJSCH3DDEJ8GQPGYZBHSB4F3HX5Q222CG89PSAB u1) +(map-set mint-passes 'SP33SCE1F3J9N6D4ZFY9AA3GR05GS3112GS1VZDFC u1) +(map-set mint-passes 'SP3TZ3BCB16A0W0PPFYMGTTWTT3DVWTQEP8DFRAG1 u1) +(map-set mint-passes 'SPK70AN512VN2VRD52D0928MA05JVJ7DY2H5F3CF u1) +(map-set mint-passes 'SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF u1) +(map-set mint-passes 'SP7PSDAPGQ2A36G1EPX363AZFWS017Q6FXFFF2BX u1) +(map-set mint-passes 'SP3M16X85R7ED2RR70ANNB3X0HXPHGSAXBEGGZKK0 u1) +(map-set mint-passes 'SP3JCJYVVZVY7Y64JYJ57JFS6FM7ASHX6QDTKFXGY u1) +(map-set mint-passes 'SP1KBVBP3AZP7YA968Y3G14A17P9XXFPBPEVF5EG9 u1) +(map-set mint-passes 'SP349J1ZTEE71M1J5D4YS0BPQCCFJ3YSNM1P8BJY4 u1) +(map-set mint-passes 'SP7MAP8XJCMRZ9901ETFA3EKVVPJ4X51AWQ2VG4F u1) +(map-set mint-passes 'SP28NCDY6V4T7NJBMYGTJ55NHMXMC0GG806JW1ZTB u1) +(map-set mint-passes 'SP3R7Q3QMTYC4QR0RFDR9HZBWNBNBNDA7S549CR6Y u1) +(map-set mint-passes 'SP1VCG4HXMG02BMJCSAZDBS1WR4N2YG3RPHMNP9WR u1) +(map-set mint-passes 'SP2NDK60R7JKQ3SJ98CEHV2CMNDVTFBR541C4KV5Y u1) +(map-set mint-passes 'SPMDGP7AP5JQTDYY83V0Q7JD3CM7YQRXQYWW3E54 u1) +(map-set mint-passes 'SP1ATHZCMZA4CDJY3ZVNFRFNZZ4R2VEJ0PHYYX3YF u1) +(map-set mint-passes 'SP2TZE09GHARKG0B8NTT9X77QXBTQPQ2J1579T0D8 u1) +(map-set mint-passes 'SP23X8JVMHN2A9N1PWSGNW83Q0VV5T7NF2N6PJW9J u1) +(map-set mint-passes 'SPN0DSRZGFNGE6D59S4ZRF8GP604NDTSQ9RRS2BM u1) +(map-set mint-passes 'SP2SH0QW45QY23H6G9YVDJMRXT55SX67CXAAM61NT u1) +(map-set mint-passes 'SP1CMFJW9J8WN7R2XJ26AC90AARGW68R1CWNYDANC u1) +(map-set mint-passes 'SP39VDGM02VMDTAAXC0DC1HB7GX1QQJBEGMMMZA8Z u1) +(map-set mint-passes 'SP9J6BTSPCXGQ5HC066NRYQPK43S48V7K299PTQX u1) +(map-set mint-passes 'SP136AXDAQ41R31GJWJX8KX14E2T4K8PA08NCE6Q5 u1) +(map-set mint-passes 'SP2ZY7ETKYAN1M7R4HWQ77Q4CVDVH8PVQ41XS0N0S u1) +(map-set mint-passes 'SP3BJ4GDXYMBRS42NJNVE271YPAPYTF28T9722GHJ u1) +(map-set mint-passes 'SPHK8A7P61C6ASWKYDX1PCDX9YA54DKVJN49EXGJ u1) diff --git a/contracts/SP2D7DHG09B4E0AY4X8YRA6B8R5XFA8R14BWM3ZE0/bns-1697751232638-v1.clar b/contracts/SP2D7DHG09B4E0AY4X8YRA6B8R5XFA8R14BWM3ZE0/bns-1697751232638-v1.clar new file mode 100644 index 0000000000..a977be100d --- /dev/null +++ b/contracts/SP2D7DHG09B4E0AY4X8YRA6B8R5XFA8R14BWM3ZE0/bns-1697751232638-v1.clar @@ -0,0 +1,126 @@ + + ;; version: 1 + ;; name: americabtc + ;; 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 )) + (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 )) + (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 ) (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 0x616d6572696361627463 u96618357488 'SPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S.gamma-commission-3-5) + \ No newline at end of file diff --git a/contracts/SP2NGYP1BPT8T4JFZJ23SAWCGXWSMMKBM8JJ3QW0F/bns-1697708319671-v1.clar b/contracts/SP2NGYP1BPT8T4JFZJ23SAWCGXWSMMKBM8JJ3QW0F/bns-1697708319671-v1.clar new file mode 100644 index 0000000000..1db2c85836 --- /dev/null +++ b/contracts/SP2NGYP1BPT8T4JFZJ23SAWCGXWSMMKBM8JJ3QW0F/bns-1697708319671-v1.clar @@ -0,0 +1,126 @@ + + ;; version: 1 + ;; name: russiabtc + ;; 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 )) + (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 )) + (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 ) (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 0x727573736961627463 u96618357488 'SPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S.gamma-commission-3-5) + \ No newline at end of file diff --git a/contracts/SP34YCV5E1QDAZH6S1JYZWPFSJ06BTZQ93D8DJ5M0/bns-1697735159110-v1.clar b/contracts/SP34YCV5E1QDAZH6S1JYZWPFSJ06BTZQ93D8DJ5M0/bns-1697735159110-v1.clar new file mode 100644 index 0000000000..d477e4285e --- /dev/null +++ b/contracts/SP34YCV5E1QDAZH6S1JYZWPFSJ06BTZQ93D8DJ5M0/bns-1697735159110-v1.clar @@ -0,0 +1,126 @@ + + ;; version: 1 + ;; name: 49 + ;; namespace: helloworld + + (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 )) + (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 )) + (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 ) (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 0x68656c6c6f776f726c64 0x3439 u966184 'SPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S.gamma-commission-3-5) + \ No newline at end of file diff --git a/contracts/SP3J80WHJXPZ1QG42PWKS3PHMNBMSKJ8BAZKMR41W/bns-1697702107649-v1.clar b/contracts/SP3J80WHJXPZ1QG42PWKS3PHMNBMSKJ8BAZKMR41W/bns-1697702107649-v1.clar new file mode 100644 index 0000000000..f21793fca3 --- /dev/null +++ b/contracts/SP3J80WHJXPZ1QG42PWKS3PHMNBMSKJ8BAZKMR41W/bns-1697702107649-v1.clar @@ -0,0 +1,126 @@ + + ;; version: 1 + ;; name: germanybitcoin + ;; 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 )) + (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 )) + (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 ) (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 0x6765726d616e79626974636f696e u96618357488 'SPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S.gamma-commission-3-5) + \ No newline at end of file diff --git a/contracts/SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9/brc20-bridge-endpoint-dev-preview-6.clar b/contracts/SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9/brc20-bridge-endpoint-dev-preview-6.clar new file mode 100644 index 0000000000..42def94fb9 --- /dev/null +++ b/contracts/SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9/brc20-bridge-endpoint-dev-preview-6.clar @@ -0,0 +1,188 @@ +(use-trait sip010-trait .trait-sip-010.sip-010-trait) +(define-constant err-unauthorised (err u1000)) +(define-constant err-paused (err u1001)) +(define-constant err-peg-in-address-not-found (err u1002)) +(define-constant err-invalid-amount (err u1003)) +(define-constant err-token-mismatch (err u1004)) +(define-constant err-invalid-tx (err u1005)) +(define-constant err-already-sent (err u1006)) +(define-constant err-address-mismatch (err u1007)) +(define-constant err-request-already-revoked (err u1008)) +(define-constant err-request-already-finalized (err u1009)) +(define-constant err-revoke-grace-period (err u1010)) +(define-constant err-request-already-claimed (err u1011)) +(define-constant MAX_UINT u340282366920938463463374607431768211455) +(define-constant ONE_8 u100000000) +(define-constant gas-fee-token .token-susdt) +(define-data-var contract-owner principal tx-sender) +(define-data-var fee-address principal tx-sender) +(define-public (set-contract-owner (new-contract-owner principal)) + (begin + (try! (is-contract-owner)) + (ok (var-set contract-owner new-contract-owner)))) +(define-public (set-fee-address (new-fee-address principal)) + (begin + (try! (is-contract-owner)) + (ok (var-set fee-address new-fee-address)))) +(define-read-only (get-request-revoke-grace-period) + (contract-call? .brc20-bridge-registry-dev-preview-2 get-request-revoke-grace-period) +) +(define-read-only (get-request-claim-grace-period) + (contract-call? .brc20-bridge-registry-dev-preview-2 get-request-claim-grace-period) +) +(define-read-only (is-peg-in-address-approved (address (buff 128))) + (contract-call? .brc20-bridge-registry-dev-preview-2 is-peg-in-address-approved address)) +(define-read-only (get-token-to-tick-or-fail (token principal)) + (contract-call? .brc20-bridge-registry-dev-preview-2 get-token-to-tick-or-fail token)) +(define-read-only (get-token-details-or-fail (tick (string-utf8 4))) + (contract-call? .brc20-bridge-registry-dev-preview-2 get-token-details-or-fail tick)) +(define-read-only (get-token-details-or-fail-by-address (token principal)) + (contract-call? .brc20-bridge-registry-dev-preview-2 get-token-details-or-fail-by-address token)) +(define-read-only (is-approved-token (tick (string-utf8 4))) + (contract-call? .brc20-bridge-registry-dev-preview-2 is-approved-token tick)) +(define-read-only (get-request-or-fail (request-id uint)) + (contract-call? .brc20-bridge-registry-dev-preview-2 get-request-or-fail request-id)) +(define-read-only (create-order-or-fail (order principal)) + (contract-call? .brc20-bridge-registry-dev-preview-2 create-order-or-fail order)) +(define-read-only (decode-order-or-fail (order-script (buff 128))) + (from-consensus-buff? principal (unwrap-panic (slice? order-script u2 (len order-script)))) +) +(define-read-only (get-peg-in-sent-or-default (bitcoin-tx (buff 4096)) (output uint) (offset uint)) + (contract-call? .brc20-bridge-registry-dev-preview-2 get-peg-in-sent-or-default bitcoin-tx output offset)) +(define-read-only (get-fee-address) + (var-get fee-address)) +(define-read-only (extract-tx-ins-outs (tx (buff 4096))) + (if (try! (contract-call? .clarity-bitcoin-dev-preview-3 is-segwit-tx tx)) + (let + ( + (parsed-tx (unwrap! (contract-call? .clarity-bitcoin-dev-preview-3 parse-wtx tx) err-invalid-tx)) + ) + (ok { ins: (get ins parsed-tx), outs: (get outs parsed-tx) }) + ) + (let + ( + (parsed-tx (unwrap! (contract-call? .clarity-bitcoin-dev-preview-3 parse-tx tx) err-invalid-tx)) + ) + (ok { ins: (get ins parsed-tx), outs: (get outs parsed-tx) }) + ) + ) +) +(define-read-only (validate-tx (tx (buff 4096)) (output-idx uint) (offset-idx uint) (order-idx uint) (token principal)) + (let ( + (tx-idxed (try! (contract-call? .indexer-dev-preview-7 get-bitcoin-tx-indexed-or-fail tx output-idx offset-idx))) + (parsed-tx (try! (extract-tx-ins-outs tx))) + (order-script (get scriptPubKey (unwrap-panic (element-at? (get outs parsed-tx) order-idx)))) + (order-address (unwrap-panic (from-consensus-buff? principal (unwrap-panic (slice? order-script u2 (len order-script)))))) + (token-details (try! (get-token-details-or-fail (get tick tx-idxed)))) + (amt-in-fixed (decimals-to-fixed (get amt tx-idxed) (contract-call? .indexer-dev-preview-7 get-tick-decimals-or-default (get tick tx-idxed)))) + (fee (mul-down amt-in-fixed (get peg-in-fee token-details))) + (amt-net (- amt-in-fixed fee))) + (asserts! (is-eq token (get token token-details)) err-token-mismatch) + (asserts! (not (get-peg-in-sent-or-default tx output-idx offset-idx)) err-already-sent) + (asserts! (is-peg-in-address-approved (get to tx-idxed)) err-peg-in-address-not-found) + (ok { order-address: order-address, fee: fee, amt-net: amt-net, tx-idxed: tx-idxed, token-details: token-details }) + ) +) +(define-public (finalize-peg-in (tx (buff 4096)) (output-idx uint) (offset-idx uint) (order-idx uint) (token-trait )) + (let ( + (token (contract-of token-trait)) + (validation-data (try! (validate-tx tx output-idx offset-idx order-idx token))) + (tx-idxed (get tx-idxed validation-data)) + (order-address (get order-address validation-data)) + (token-details (get token-details validation-data)) + (fee (get fee validation-data)) + (amt-net (get amt-net validation-data))) + (asserts! (not (get peg-in-paused token-details)) err-paused) + (as-contract (try! (contract-call? .brc20-bridge-registry-dev-preview-2 set-peg-in-sent { tx: tx, output: output-idx, offset: offset-idx } true))) + (and (> fee u0) (as-contract (try! (contract-call? token-trait mint-fixed fee (var-get fee-address))))) + (and (> amt-net u0) (as-contract (try! (contract-call? token-trait mint-fixed amt-net order-address)))) + (print (merge tx-idxed { type: "peg-in", order-address: order-address, fee: fee, amt-net: amt-net })) + (ok true))) +(define-public (request-peg-out (tick (string-utf8 4)) (amount uint) (peg-out-address (buff 128)) (token-trait )) + (let ( + (token (contract-of token-trait)) + (token-details (try! (get-token-details-or-fail tick))) + (fee (mul-down amount (get peg-out-fee token-details))) + (amount-net (- amount fee)) + (gas-fee (get peg-out-gas-fee token-details)) + (request-details { requested-by: tx-sender, peg-out-address: peg-out-address, tick: tick, amount-net: amount-net, fee: fee, gas-fee: gas-fee, claimed: u0, claimed-by: tx-sender, fulfilled-by: 0x, revoked: false, finalized: false, requested-at: block-height }) + (request-id (as-contract (try! (contract-call? .brc20-bridge-registry-dev-preview-2 set-request u0 request-details))))) + (asserts! (not (get peg-out-paused token-details)) err-paused) + (asserts! (is-eq token (get token token-details)) err-token-mismatch) + (asserts! (> amount u0) err-invalid-amount) + (try! (contract-call? token-trait transfer-fixed amount tx-sender (as-contract tx-sender) none)) + (and (> gas-fee u0) (try! (contract-call? gas-fee-token transfer-fixed gas-fee tx-sender (as-contract tx-sender) none))) + (print (merge request-details { type: "request-peg-out", request-id: request-id })) + (ok true))) +(define-public (claim-peg-out (request-id uint) (fulfilled-by (buff 128))) + (let ( + (claimer tx-sender) + (request-details (try! (get-request-or-fail request-id))) + (token-details (try! (get-token-details-or-fail (get tick request-details))))) + (asserts! (not (get peg-out-paused token-details)) err-paused) + (asserts! (< (get claimed request-details) block-height) err-request-already-claimed) + (asserts! (not (get revoked request-details)) err-request-already-revoked) + (asserts! (not (get finalized request-details)) err-request-already-finalized) + + (as-contract (try! (contract-call? .brc20-bridge-registry-dev-preview-2 set-request request-id (merge request-details { claimed: (+ block-height (get-request-claim-grace-period)), claimed-by: claimer, fulfilled-by: fulfilled-by })))) + (print (merge request-details { type: "claim-peg-out", request-id: request-id, claimed: (+ block-height (get-request-claim-grace-period)), claimed-by: claimer, fulfilled-by: fulfilled-by })) + (ok true) + ) +) +(define-public (finalize-peg-out (request-id uint) (tx (buff 4096)) (output-idx uint) (offset-idx uint) (token-trait )) + (let ( + (token (contract-of token-trait)) + (request-details (try! (get-request-or-fail request-id))) + (token-details (try! (get-token-details-or-fail (get tick request-details)))) + (tx-idxed (try! (contract-call? .indexer-dev-preview-7 get-bitcoin-tx-indexed-or-fail tx output-idx offset-idx))) + (amount-in-fixed (decimals-to-fixed (get amt tx-idxed) (contract-call? .indexer-dev-preview-7 get-tick-decimals-or-default (get tick tx-idxed)))) + (fulfilled-by (get from tx-idxed)) + (is-fulfilled-by-peg-in (is-peg-in-address-approved fulfilled-by)) + ) + (asserts! (not (get peg-out-paused token-details)) err-paused) + (asserts! (is-eq token (get token token-details)) err-token-mismatch) + (asserts! (is-eq (get tick request-details) (get tick tx-idxed)) err-token-mismatch) + (asserts! (is-eq (get amount-net request-details) amount-in-fixed) err-invalid-amount) + (asserts! (is-eq (get peg-out-address request-details) (get to tx-idxed)) err-address-mismatch) + (asserts! (is-eq (get fulfilled-by request-details) fulfilled-by) err-address-mismatch) + (asserts! (not (get-peg-in-sent-or-default tx output-idx offset-idx)) err-already-sent) + (asserts! (not (get revoked request-details)) err-request-already-revoked) + (asserts! (not (get finalized request-details)) err-request-already-finalized) + (as-contract (try! (contract-call? .brc20-bridge-registry-dev-preview-2 set-peg-in-sent { tx: tx, output: output-idx, offset: offset-idx } true))) + (as-contract (try! (contract-call? .brc20-bridge-registry-dev-preview-2 set-request request-id (merge request-details { finalized: true })))) + (and (> (get fee request-details) u0) (as-contract (try! (contract-call? token-trait transfer-fixed (get fee request-details) tx-sender (var-get fee-address) none)))) + (and (> (get gas-fee request-details) u0) (as-contract (try! (contract-call? gas-fee-token transfer-fixed (get gas-fee request-details) tx-sender (if is-fulfilled-by-peg-in (var-get fee-address) (get claimed-by request-details)) none)))) + (if is-fulfilled-by-peg-in + (as-contract (try! (contract-call? token-trait burn-fixed (get amount-net request-details) tx-sender))) + (as-contract (try! (contract-call? token-trait transfer-fixed (get amount-net request-details) tx-sender (get claimed-by request-details) none))) + ) + (print { type: "finalize-peg-out", request-id: request-id, tx: tx }) + (ok true))) +(define-public (revoke-peg-out (request-id uint) (token-trait )) + (let ( + (token (contract-of token-trait)) + (request-details (try! (get-request-or-fail request-id))) + (token-details (try! (get-token-details-or-fail (get tick request-details))))) + (asserts! (not (get peg-out-paused token-details)) err-paused) + (asserts! (is-eq token (get token token-details)) err-token-mismatch) + (asserts! (> block-height (+ (get requested-at request-details) (get-request-revoke-grace-period))) err-revoke-grace-period) + (asserts! (not (get revoked request-details)) err-request-already-revoked) + (asserts! (not (get finalized request-details)) err-request-already-finalized) + (as-contract (try! (contract-call? .brc20-bridge-registry-dev-preview-2 set-request request-id (merge request-details { revoked: true })))) + (and (> (get fee request-details) u0) (as-contract (try! (contract-call? token-trait transfer-fixed (get fee request-details) tx-sender (get requested-by request-details) none)))) + (and (> (get gas-fee request-details) u0) (as-contract (try! (contract-call? gas-fee-token transfer-fixed (get gas-fee request-details) tx-sender (get requested-by request-details) none)))) + (as-contract (try! (contract-call? token-trait transfer-fixed (get amount-net request-details) tx-sender (get requested-by request-details) none))) + (print { type: "revoke-peg-out", request-id: request-id }) + (ok true))) +(define-private (is-contract-owner) + (ok (asserts! (is-eq (var-get contract-owner) tx-sender) err-unauthorised))) +(define-private (min (a uint) (b uint)) + (if (< a b) a b)) +(define-private (mul-down (a uint) (b uint)) + (/ (* a b) ONE_8)) +(define-private (div-down (a uint) (b uint)) + (if (is-eq a u0) + u0 + (/ (* a ONE_8) b))) +(define-private (decimals-to-fixed (amount uint) (decimals uint)) + (/ (* amount ONE_8) (pow u10 decimals))) \ No newline at end of file diff --git a/contracts/SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9/indexer-dev-preview-7.clar b/contracts/SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9/indexer-dev-preview-7.clar new file mode 100644 index 0000000000..b297fb508b --- /dev/null +++ b/contracts/SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9/indexer-dev-preview-7.clar @@ -0,0 +1,144 @@ +(define-constant ERR-NOT-AUTHORIZED (err u1000)) +(define-constant ERR-UNKNOWN-VALIDATOR (err u1001)) +(define-constant ERR-PAUSED (err u1002)) +(define-constant ERR-UKNOWN-RELAYER (err u1003)) +(define-constant ERR-REQUIRED-VALIDATORS (err u1004)) +(define-constant ERR-VALIDATOR-ALREADY-REGISTERED (err u1005)) +(define-constant ERR-DUPLICATE-SIGNATURE (err u1006)) +(define-constant ERR-ORDER-HASH-MISMATCH (err u1007)) +(define-constant ERR-INVALID-SIGNATURE (err u1008)) +(define-constant MAX_UINT u340282366920938463463374607431768211455) +(define-constant ONE_8 u100000000) +(define-constant MAX_REQUIRED_VALIDATORS u10) +(define-constant structured-data-prefix 0x534950303138) +(define-constant message-domain 0x6d11cd301d11961e7cfeabd61e3f4da17f42f3d627362c8878aa9cbb5c532be2) ;;mainnet +(define-data-var contract-owner principal tx-sender) +(define-map approved-relayers principal bool) +(define-data-var is-paused bool true) +(define-map validators principal (buff 33)) +(define-data-var validator-count uint u0) +(define-data-var required-validators uint MAX_UINT) +(define-map tx-validated-by { tx-hash: (buff 32), validator: principal } bool) +(define-data-var tx-hash-to-iter (buff 32) 0x) +(define-public (set-paused (paused bool)) + (begin + (try! (check-is-owner)) + (ok (var-set is-paused paused)))) +(define-public (add-validator (validator-pubkey (buff 33)) (validator principal)) + (begin + (try! (check-is-owner)) + (asserts! (is-none (map-get? validators validator)) ERR-VALIDATOR-ALREADY-REGISTERED) + (map-set validators validator validator-pubkey) + (var-set validator-count (+ u1 (var-get validator-count))) + (ok (var-get validator-count)))) +(define-public (remove-validator (validator principal)) + (begin + (try! (check-is-owner)) + (asserts! (is-some (map-get? validators validator)) ERR-UNKNOWN-VALIDATOR) + (map-delete validators validator) + (var-set validator-count (- (var-get validator-count) u1)) + (ok (var-get validator-count)))) +(define-public (approve-relayer (relayer principal) (approved bool)) + (begin + (try! (check-is-owner)) + (ok (map-set approved-relayers relayer approved)))) +(define-public (set-required-validators (new-required-validators uint)) + (begin + (try! (check-is-owner)) + (asserts! (< new-required-validators MAX_REQUIRED_VALIDATORS) ERR-REQUIRED-VALIDATORS) + (ok (var-set required-validators new-required-validators)))) +(define-public (set-contract-owner (owner principal)) + (begin + (try! (check-is-owner)) + (ok (var-set contract-owner owner)))) +(define-read-only (get-contract-owner) + (var-get contract-owner)) +(define-read-only (get-validator-or-fail (validator principal)) + (ok (unwrap! (map-get? validators validator) ERR-UNKNOWN-VALIDATOR))) +(define-read-only (get-required-validators) + (var-get required-validators)) +(define-read-only (hash-tx (tx { bitcoin-tx: (buff 4096), output: uint, offset: uint, tick: (string-utf8 4), amt: uint, from: (buff 128), to: (buff 128), from-bal: uint, to-bal: uint, decimals: uint } )) + (sha256 (default-to 0x (to-consensus-buff? tx)))) +(define-read-only (get-paused) + (var-get is-paused)) +(define-read-only (get-user-balance-or-default (user (buff 128)) (tick (string-utf8 4))) + (contract-call? .indexer-registry-dev-preview-2 get-user-balance-or-default user tick)) +(define-read-only (get-tick-decimals-or-default (tick (string-utf8 4))) + (contract-call? .indexer-registry-dev-preview-2 get-tick-decimals-or-default tick) +) +(define-read-only (validate-tx (tx-hash (buff 32)) (signature-pack { signer: principal, tx-hash: (buff 32), signature: (buff 65)})) + (let ( + (validator-pubkey (try! (get-validator-or-fail (get signer signature-pack))))) + (asserts! (is-none (map-get? tx-validated-by { tx-hash: tx-hash, validator: (get signer signature-pack) })) ERR-DUPLICATE-SIGNATURE) + (asserts! (is-eq tx-hash (get tx-hash signature-pack)) ERR-ORDER-HASH-MISMATCH) + (ok (asserts! (is-eq (secp256k1-recover? (sha256 (concat structured-data-prefix (concat message-domain tx-hash))) (get signature signature-pack)) (ok validator-pubkey)) ERR-INVALID-SIGNATURE)))) +(define-read-only (verify-mined (tx (buff 4096)) (block { header: (buff 80), height: uint }) (proof { tx-index: uint, hashes: (list 14 (buff 32)), tree-depth: uint })) + (if (is-eq chain-id u1) + (if (try! (contract-call? .clarity-bitcoin-dev-preview-3 is-segwit-tx tx)) + (contract-call? .clarity-bitcoin-dev-preview-3 was-segwit-tx-mined? block tx proof) + (contract-call? .clarity-bitcoin-dev-preview-3 was-tx-mined? block tx proof) + ) + (ok true) ;; if not mainnet, assume verified + ) +) +(define-read-only (get-bitcoin-tx-mined-or-default (tx (buff 4096))) + (contract-call? .indexer-registry-dev-preview-2 get-bitcoin-tx-mined-or-default tx) +) +(define-read-only (get-bitcoin-tx-indexed-or-fail (bitcoin-tx (buff 4096)) (output uint) (offset uint)) + (contract-call? .indexer-registry-dev-preview-2 get-bitcoin-tx-indexed-or-fail bitcoin-tx output offset) +) +(define-public (index-tx-many + (tx-many (list 25 { + tx: { bitcoin-tx: (buff 4096), output: uint, offset: uint, tick: (string-utf8 4), amt: uint, from: (buff 128), to: (buff 128), from-bal: uint, to-bal: uint, decimals: uint }, + block: { header: (buff 80), height: uint }, + proof: { tx-index: uint, hashes: (list 14 (buff 32)), tree-depth: uint }, + signature-packs: (list 10 { signer: principal, tx-hash: (buff 32), signature: (buff 65) })}))) + (begin + (asserts! (not (var-get is-paused)) ERR-PAUSED) + (asserts! (is-some (map-get? approved-relayers tx-sender)) ERR-UKNOWN-RELAYER) + (fold index-tx-iter tx-many (ok true)))) +(define-private (validate-signature-iter + (signature-pack { signer: principal, tx-hash: (buff 32), signature: (buff 65)}) + (previous-response (response bool uint))) + (match previous-response + prev-ok + (begin + (try! (validate-tx (var-get tx-hash-to-iter) signature-pack)) + (ok (map-set tx-validated-by { tx-hash: (var-get tx-hash-to-iter), validator: (get signer signature-pack) } true))) + prev-err + previous-response)) +(define-private (index-tx-iter + (signed-tx { + tx: { bitcoin-tx: (buff 4096), output: uint, offset: uint, tick: (string-utf8 4), amt: uint, from: (buff 128), to: (buff 128), from-bal: uint, to-bal: uint, decimals: uint }, + block: { header: (buff 80), height: uint }, + proof: { tx-index: uint, hashes: (list 14 (buff 32)), tree-depth: uint }, + signature-packs: (list 10 { signer: principal, tx-hash: (buff 32), signature: (buff 65)}) }) + (previous-response (response bool uint))) + (match previous-response + prev-ok + (let ( + (tx (get tx signed-tx)) + (signature-packs (get signature-packs signed-tx)) + (tx-hash (hash-tx tx)) + (from-bal (get-user-balance-or-default (get from tx) (get tick tx))) + (to-bal (get-user-balance-or-default (get to tx) (get tick tx))) + (height (get height (get block signed-tx))) + ) + (asserts! (>= (len signature-packs) (var-get required-validators)) ERR-REQUIRED-VALIDATORS) + (and (not (get-bitcoin-tx-mined-or-default (get bitcoin-tx tx))) + (begin + (try! (verify-mined (get bitcoin-tx tx) (get block signed-tx) (get proof signed-tx))) + (as-contract (try! (contract-call? .indexer-registry-dev-preview-2 set-tx-mined (get bitcoin-tx tx) true))) + ) + ) + (var-set tx-hash-to-iter tx-hash) + (try! (fold validate-signature-iter signature-packs (ok true))) + (as-contract (try! (contract-call? .indexer-registry-dev-preview-2 set-tx-indexed { tx-hash: (get bitcoin-tx tx), output: (get output tx), offset: (get offset tx) } { tick: (get tick tx), amt: (get amt tx), from: (get from tx), to: (get to tx) }))) + (and (> height (get up-to-block from-bal)) (as-contract (try! (contract-call? .indexer-registry-dev-preview-2 set-user-balance { user: (get from tx), tick: (get tick tx) } { balance: (get from-bal tx), up-to-block: height })))) + (and (> height (get up-to-block to-bal)) (as-contract (try! (contract-call? .indexer-registry-dev-preview-2 set-user-balance { user: (get to tx), tick: (get tick tx) } { balance: (get to-bal tx), up-to-block: height })))) + (as-contract (try! (contract-call? .indexer-registry-dev-preview-2 set-tick-decimals (get tick tx) (get decimals tx)))) + (ok true)) + prev-err + previous-response)) +(define-private (check-is-owner) + (ok (asserts! (is-eq (var-get contract-owner) tx-sender) ERR-NOT-AUTHORIZED))) \ No newline at end of file diff --git a/contracts/SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9/indexer-registry-dev-preview-2.clar b/contracts/SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9/indexer-registry-dev-preview-2.clar new file mode 100644 index 0000000000..fb4092cd63 --- /dev/null +++ b/contracts/SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9/indexer-registry-dev-preview-2.clar @@ -0,0 +1,70 @@ +(define-constant ERR-NOT-AUTHORIZED (err u1000)) +(define-constant ERR-PAUSED (err u1001)) +(define-constant ERR-TX-NOT-INDEXED (err u1002)) +(define-data-var contract-owner principal tx-sender) +(define-map approved-operators principal bool) +(define-data-var is-paused bool true) +(define-map bitcoin-tx-mined (buff 4096) bool) +(define-map bitcoin-tx-indexed { tx-hash: (buff 4096), output: uint, offset: uint } { tick: (string-utf8 4), amt: uint, from: (buff 128), to: (buff 128) }) +(define-map user-balance { user: (buff 128), tick: (string-utf8 4) } { balance: uint, up-to-block: uint }) +(define-map tick-decimals (string-utf8 4) uint) +(define-public (set-paused (paused bool)) + (begin + (try! (check-is-owner)) + (ok (var-set is-paused paused)))) +(define-public (approve-operator (operator principal) (approved bool)) + (begin + (try! (check-is-owner)) + (ok (map-set approved-operators operator approved)))) +(define-public (set-contract-owner (owner principal)) + (begin + (try! (check-is-owner)) + (ok (var-set contract-owner owner)))) +(define-read-only (get-contract-owner) + (var-get contract-owner)) +(define-read-only (get-paused) + (var-get is-paused)) +(define-read-only (get-approved-operator-or-default (operator principal)) + (default-to false (map-get? approved-operators operator)) +) +(define-read-only (get-user-balance-or-default (user (buff 128)) (tick (string-utf8 4))) + (default-to { balance: u0, up-to-block: u0 } (map-get? user-balance { user: user, tick: tick }))) +(define-read-only (get-bitcoin-tx-mined-or-default (tx (buff 4096))) + (default-to false (map-get? bitcoin-tx-mined tx)) +) +(define-read-only (get-tick-decimals-or-default (tick (string-utf8 4))) + (default-to u18 (map-get? tick-decimals tick)) +) +(define-read-only (get-bitcoin-tx-indexed-or-fail (bitcoin-tx (buff 4096)) (output uint) (offset uint)) + (ok (unwrap! (map-get? bitcoin-tx-indexed { tx-hash: bitcoin-tx, output: output, offset: offset }) ERR-TX-NOT-INDEXED))) +(define-public (set-tick-decimals (tick (string-utf8 4)) (decimals uint)) + (begin + (try! (check-is-approved)) + (print { type: "tick-decimals-updated", tick: tick, decimals: decimals}) + (ok (map-set tick-decimals tick decimals)) + ) +) +(define-public (set-user-balance (key { user: (buff 128), tick: (string-utf8 4) }) (value { balance: uint, up-to-block: uint })) + (begin + (try! (check-is-approved)) + (print { type: "user-balance-updated", user: (get user key), tick: (get tick key), balance: (get balance value), up-to-block: (get up-to-block value) }) + (ok (map-set user-balance key value)))) +(define-public (set-tx-mined (key (buff 4096)) (value bool)) + (begin + (try! (check-is-approved)) + (print { type: "tx-mined", tx-hash: key }) + (ok (map-set bitcoin-tx-mined key value)) + ) +) +(define-public (set-tx-indexed (key { tx-hash: (buff 4096), output: uint, offset: uint }) (value { tick: (string-utf8 4), amt: uint, from: (buff 128), to: (buff 128) })) + (begin + (try! (check-is-approved)) + (print { type: "tx-indexed", tx-hash: (get tx-hash key), output: (get output key), offset: (get offset key), tick: (get tick value), amt: (get amt value), from: (get from value), to: (get to value) }) + (ok (map-set bitcoin-tx-indexed key value)) + ) +) +(define-private (check-is-approved) + (ok (asserts! (or (get-approved-operator-or-default tx-sender) (is-ok (check-is-owner))) ERR-NOT-AUTHORIZED)) +) +(define-private (check-is-owner) + (ok (asserts! (is-eq (var-get contract-owner) tx-sender) ERR-NOT-AUTHORIZED))) \ No newline at end of file diff --git a/contracts/SP5EZFA3N8PBTSG24AB60SH71ZSWG96CEF6KTSTB/bns-1697710634765-v1.clar b/contracts/SP5EZFA3N8PBTSG24AB60SH71ZSWG96CEF6KTSTB/bns-1697710634765-v1.clar new file mode 100644 index 0000000000..7636f68631 --- /dev/null +++ b/contracts/SP5EZFA3N8PBTSG24AB60SH71ZSWG96CEF6KTSTB/bns-1697710634765-v1.clar @@ -0,0 +1,126 @@ + + ;; version: 1 + ;; name: americabitcoin + ;; 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 )) + (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 )) + (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 ) (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 0x616d6572696361626974636f696e u96618357488 'SPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S.gamma-commission-3-5) + \ No newline at end of file diff --git a/contracts/SPYXBZDP6SQ1WPNAAB0MXEY8ETJ58SHDRNNFSMNG/bns-1697698898462-v1.clar b/contracts/SPYXBZDP6SQ1WPNAAB0MXEY8ETJ58SHDRNNFSMNG/bns-1697698898462-v1.clar new file mode 100644 index 0000000000..7374feee5e --- /dev/null +++ b/contracts/SPYXBZDP6SQ1WPNAAB0MXEY8ETJ58SHDRNNFSMNG/bns-1697698898462-v1.clar @@ -0,0 +1,126 @@ + + ;; version: 1 + ;; name: germanybtc + ;; 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 )) + (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 )) + (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 ) (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 0x6765726d616e79627463 u96618357488 'SPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S.gamma-commission-3-5) + \ No newline at end of file diff --git a/last-block.txt b/last-block.txt index c0e2b782d2..1796f0fb0b 100644 --- a/last-block.txt +++ b/last-block.txt @@ -1 +1 @@ -125334 \ No newline at end of file +125455 \ No newline at end of file