-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFractonSwap.clar
51 lines (45 loc) · 1.44 KB
/
FractonSwap.clar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(define-fungible-token fracton-fft)
(define-non-fungible-token fracton-nft uint)
(define-data-var swap-rate uint u1000000000000000000) ;; Example rate
(define-data-var fft-tax uint u3000000000000000000) ;; Example tax for FFT
(define-data-var nft-tax uint u3) ;; Example tax for NFT
(define-map nft-ids
{ nft-contract: principal }
{ token-ids: (list 10 uint) }
)
(define-public (update-swap-rate (new-rate uint))
(begin
(asserts! (is-eq tx-sender (get-dao-address)) "Unauthorized")
(var-set swap-rate new-rate)
(ok true)
)
)
(define-public (update-taxes (new-fft-tax uint) (new-nft-tax uint))
(begin
(asserts! (is-eq tx-sender (get-dao-address)) "Unauthorized")
(var-set fft-tax new-fft-tax)
(var-set nft-tax new-nft-tax)
(ok true)
)
)
;; Example swap function for FFT tokens
(define-public (swap-fft (amount uint))
(begin
(let ((tax (var-get fft-tax)))
(ft-transfer? fracton-fft amount tx-sender 'some-other-address)
(ft-transfer? fracton-fft tax tx-sender 'tax-receiver)
)
(ok true)
)
)
;; Accepting an NFT transfer
(define-public (receive-nft (nft-contract principal) (token-id uint))
(begin
(nft-transfer? fracton-nft token-id tx-sender (as-contract tx-sender))
(map-insert nft-ids
{ nft-contract: nft-contract }
{ token-ids: (unwrap-panic (concat (default-to (list) (get token-ids (map-get? nft-ids { nft-contract: nft-contract }))) [token-id])) }
)
(ok true)
)
)