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 Jan 3, 2024
1 parent 0162ef6 commit 54de85d
Show file tree
Hide file tree
Showing 7 changed files with 1,179 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@

;; version: 1
;; name: realfarming
;; 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 0x7265616c6661726d696e67 u9661836 'SPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S.gamma-commission-3-5)

Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@

;; version: 1
;; name: 5852
;; 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 0x35383532 u54589372 'SPNWZ5V2TPWGQGVDR6T7B6RQ4XMGZ4PXTEE0VQ0S.gamma-commission-3-5)

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
;; NOT A PRODUCTION DEPLOYMENT
;; This contract should be used for test purposes only

(define-constant ERR-MINIMUM-OUTPUT (err u1000))

(define-public (route-a (input uint) (min-output uint))
(let (
(a (unwrap-panic (bitflow-a input)))
(b (unwrap-panic (alex-a a)))
)
(begin
(asserts! (>= input min-output) ERR-MINIMUM-OUTPUT)
(ok (list input a b min-output))
)
)
)

(define-public (bitflow-a (input uint))
(let (
(call (try! (contract-call?
'SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.stableswap-abtc-xbtc-v-1-1 swap-x-for-y
'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-abtc
'SP3DX3H4FEYZJZ586MFBS25ZW3HZDMEW92260R2PR.Wrapped-Bitcoin
'SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.abtc-xbtc-lp-token-v-1-1
input u0)))
)
(ok call)
)
)

(define-public (alex-a (input uint))
(let (
(call (try! (contract-call?
'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.amm-swap-pool-v1-1 swap-helper
'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wbtc
'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx
u100000000 input (some u0))))
)
(ok call)
)
)
Loading

0 comments on commit 54de85d

Please sign in to comment.