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 4, 2023
1 parent ed5450f commit 10d40fa
Show file tree
Hide file tree
Showing 32 changed files with 5,533 additions and 1 deletion.
1,065 changes: 1,065 additions & 0 deletions contracts/SP14VDDN583TB43F06NFV36YRAS0QWQC75QBDFBFR/cp-staking.clar

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions contracts/SP14VDDN583TB43F06NFV36YRAS0QWQC75QBDFBFR/ft-trait.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(define-trait sip-010-trait
(
;; Transfer from the caller to a new principal
(transfer (uint principal principal (optional (buff 34))) (response bool uint))

;; the human readable name of the token
(get-name () (response (string-ascii 32) uint))

;; the ticker symbol, or empty if none
(get-symbol () (response (string-ascii 32) uint))

;; the number of decimals used, e.g. 6 would mean 1_000_000 represents 1 token
(get-decimals () (response uint uint))

;; the balance of the passed principal
(get-balance (principal) (response uint uint))

;; the current total supply (which does not need to be a constant)
(get-total-supply () (response uint uint))

;; an optional URI that represents metadata of this token
(get-token-uri () (response (optional (string-utf8 256)) uint))
)
)
15 changes: 15 additions & 0 deletions contracts/SP14VDDN583TB43F06NFV36YRAS0QWQC75QBDFBFR/nft-trait.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(define-trait nft-trait
(
;; Last token ID, limited to uint range
(get-last-token-id () (response uint uint))

;; URI for metadata associated with the token
(get-token-uri (uint) (response (optional (string-ascii 256)) uint))

;; Owner of a given token identifier
(get-owner (uint) (response (optional principal) uint))

;; Transfer from the sender to a new principal
(transfer (uint principal principal) (response bool uint))
)
)
172 changes: 172 additions & 0 deletions contracts/SP14VDDN583TB43F06NFV36YRAS0QWQC75QBDFBFR/snow-token.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
;; $SNOW FT Contract
;; This contract represents the $SNOW FT - the fungible token for the CrashPunks metaverse.
;; Written by StrataLabs

;; $SNOW FT Unique Properties
;; 1. Minting is only allowed by the staking contract

(impl-trait .ft-trait.sip-010-trait)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Cons, Vars, & Maps ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define-constant contract-owner tx-sender)
(define-constant TOKEN_NAME "SNOW")
(define-constant TOKEN_SYMBOL "SNW")
(define-constant TOKEN_DECIMALS u6)
(define-constant TOKEN_MAX_SUPPLY u100000000000000)

;;;;;;;;;;;;;;;;;;;
;; FT Vars/Cons ;;
;;;;;;;;;;;;;;;;;;;

(define-fungible-token SNOW TOKEN_MAX_SUPPLY)
(define-data-var activate-transfer bool false)
(define-data-var TOKEN_URI (optional (string-utf8 256)) (some u"https://gateway.pinata.cloud/ipfs/QmerTxsPTgfdR2iz5xV6oqy7jprPoga5NNiEJRtgQ2pF2H"))
(define-data-var mint-active bool true)

;;;;;;;;;;;;;;;;
;; Error Cons ;;
;;;;;;;;;;;;;;;;

(define-constant ERR_SENDER_NOT_VALID (err u1000))
(define-constant ERR_SENDER_AND_RECIPENT_IS_EQUAL (err u1001))
(define-constant ERR_INSUFFICIENT_AMOUNT (err u1002))
(define-constant ERR_GETING_BALANCE_OF_SENDER (err u1003))
(define-constant ERR_SENDER_BALANCE_NOT_VALID (err u1004))
(define-constant ERR_NOT_ALLOWED (err u1005))
(define-constant ERR_RECIPIENT_NOT_VALID (err u1006))
(define-constant ERR_TRANSFER_NOT_ACTIVATED (err u1007))
(define-constant ERR_NOT_AUTH (err u1008))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;; SIP10 Functions ;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Regular transfer function for SIP-010 but we need to activita the transfer function before being able to actually transfer
(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34))))
(begin

;; assert sender is tx-sender
(asserts! (is-eq tx-sender sender) ERR_SENDER_NOT_VALID)

;; assert sender is not recipient
(asserts! (not (is-eq sender recipient)) ERR_SENDER_AND_RECIPENT_IS_EQUAL)

;; assert amount transferred > 0
(asserts! (> amount u0) ERR_INSUFFICIENT_AMOUNT)

;; assert amount transferred =< balance of sender
(asserts! (<= amount (unwrap! (get-balance sender) ERR_GETING_BALANCE_OF_SENDER)) ERR_SENDER_BALANCE_NOT_VALID)

;; assert the transfer function is activated
(asserts! (var-get activate-transfer) ERR_TRANSFER_NOT_ACTIVATED)

;; transfer
(try! (ft-transfer? SNOW amount sender recipient))
(match memo to-print (print to-print) 0x)
(ok true)
)
)

(define-public (change-transfer-state)
(ok (var-set activate-transfer true))
)

(define-public (update-token-uri (new-uri (optional (string-utf8 256))))
(begin
(asserts! (is-eq tx-sender contract-owner) ERR_NOT_ALLOWED)
(ok (var-set TOKEN_URI new-uri))
)
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;; Read Functions ;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define-read-only (get-name)
(ok TOKEN_NAME)
)

(define-read-only (get-symbol)
(ok TOKEN_SYMBOL)
)

(define-read-only (get-decimals)
(ok TOKEN_DECIMALS)
)

(define-read-only (get-balance (account principal))
(ok (ft-get-balance SNOW account))
)

(define-read-only (get-total-supply)
(ok (ft-get-supply SNOW))
)

(define-read-only (get-token-uri)
(ok (var-get TOKEN_URI))
)

(define-read-only (get-max-supply)
(ok TOKEN_MAX_SUPPLY)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;; Mint Functions ;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Regular SIP-010 mint function, except this is only callable by the CrashPunks staking contract or admin
(define-public (mint (amount uint) (recipient principal))
(let
(
(current-total-supply (ft-get-supply SNOW))
)

;; If mint is active, check that the tx-sender is contract-owner or staking contract, if it is not active only check that the sender is staking contract
(if (var-get mint-active)
(asserts! (or (is-eq tx-sender contract-owner) (is-eq contract-caller .cp-staking)) ERR_NOT_AUTH)
(asserts! (is-eq contract-caller .cp-staking) ERR_NOT_AUTH)
)

;; asserts that recipient is not staking contract
(asserts! (not (is-eq recipient .cp-staking)) ERR_RECIPIENT_NOT_VALID)

;; asserts that amount is greater than 0
(asserts! (> amount u0) ERR_INSUFFICIENT_AMOUNT)

;; asserts that amount is less than
(asserts! (<= amount (- TOKEN_MAX_SUPPLY current-total-supply)) ERR_NOT_ALLOWED)
(ft-mint? SNOW amount recipient)
)
)

(define-public (burn (amount uint) (sender principal))
(begin
(asserts! (is-eq tx-sender sender) ERR_SENDER_NOT_VALID)
(asserts! (> amount u0) ERR_INSUFFICIENT_AMOUNT)
(asserts! (<= amount (ft-get-balance SNOW sender)) ERR_SENDER_BALANCE_NOT_VALID)
(ft-burn? SNOW amount sender)
)
)

;; Change the mint-active so that only the staking contract can mint SNOW tokens
(define-public (turn-off-mint-by-owner)
(ok
(begin
(asserts! (is-eq tx-sender contract-owner) ERR_NOT_AUTH)
(var-set mint-active false)
)
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@

;; version: 1
;; name: ayyy
;; 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 0x61797979 u193236715 'SPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S.gamma-commission-3-5)

Loading

0 comments on commit 10d40fa

Please sign in to comment.