.derupt-feed

All .derupt-profile contract message calls are logged in .derupt-feed

The following function is only callable by .derupt-core-yyyymmdd:

  • log-send-message

About Messages: log-send-message is only callable by the current .derupt-core-yyyymmdd contract. (To prove messages in a transparent order of operations, so that developers have consistent data for presentation across all potential user interfaces)

About Replies: log-send-message include Reply Messages as inferred by the inclusion of a reply-to transaction id argument. (The log-send-message function logs send-message calls received from core) (The core wraps replies functions as send-message function calls)

Work in Progress

;; title: derupt-feed
;; version: 1.3.1
;; summary: Feed Contract
;; description: used to log Feed

(use-trait sip-010-trait 'ST1ZK4MRVTQQJMVAAJQWBV2WPQ87QV2851YCTHD7X.sip-010-trait-ft-standard.sip-010-trait)
;; (use-trait sip-010-trait 'MAINNETADDRESS.sip-010-trait-ft-standard.sip-010-trait)

(use-trait derupt-ext-trait 'ST1ZK4MRVTQQJMVAAJQWBV2WPQ87QV2851YCTHD7X.derupt-ext-trait.derupt-ext)
;; (use-trait derupt-ext-trait 'MAINNETADDRESS.derupt-ext-trait.derupt-ext)

(use-trait cryptocash-token-trait 'ST1ZK4MRVTQQJMVAAJQWBV2WPQ87QV2851YCTHD7X.cryptocash-token-trait.cryptocash-token)

(use-trait cryptocash-core-trait 'ST1ZK4MRVTQQJMVAAJQWBV2WPQ87QV2851YCTHD7X.cryptocash-core-trait.cryptocash-core)

(define-constant DAPP tx-sender)

;; Error constants
(define-constant ERR-UNAUTHORIZED (err u100))
(define-constant ERR-NOTFOUND (err u101))
(define-constant ERR-MISSINGARG (err u103))
(define-constant ERR-INSUFFICIENT-BALANCE (err u104))
(define-constant ERR-INSUFFICIENT-ARG (err u106))
(define-constant ERR-NEW-BRO-REQUIRED (err u107))
(define-constant ERR-NEW-PARTNER-REQUIRED (err u108))
(define-constant ERR-WRONG-CC-TOKEN-VERSION (err u109))
(define-constant ERR-WRONG-CC-CORE-VERSION (err u110))

;; Contract references
(define-data-var derupt-core-contract principal (as-contract tx-sender))
(define-data-var cc-token-contract principal (as-contract tx-sender))
(define-data-var cc-core-contract principal (as-contract tx-sender))

;; Cost map
(define-map cost principal { chime-stx-cost: (optional uint), chime-ft-cost: (optional uint), like-ft-cost: (optional uint), dislike-ft-cost: (optional uint) })
(define-map crypto-bros (string-ascii 11) principal)
(define-map crypto-partners (string-ascii 11) principal)

;; Setter for costs
(define-public (set-cost (chime-stx-cost (optional uint)) (chime-ft-cost (optional uint)) (like-ft-cost (optional uint)) (dislike-ft-cost (optional uint))) 
  (begin 
    (asserts! (is-eq tx-sender (unwrap! (map-get? crypto-bros "cryptodude") ERR-UNAUTHORIZED)) ERR-UNAUTHORIZED)
      (match chime-stx-cost value (map-set cost DAPP 
        { 
            chime-stx-cost:   (some value), 
            chime-ft-cost:   (unwrap! (get chime-ft-cost (map-get? cost DAPP)) ERR-NOTFOUND),
            like-ft-cost:   (unwrap! (get like-ft-cost (map-get? cost DAPP)) ERR-NOTFOUND),
            dislike-ft-cost:  (unwrap! (get dislike-ft-cost (map-get? cost DAPP)) ERR-NOTFOUND) 
        }) false)
      (match chime-ft-cost value (map-set cost DAPP 
        { 
            chime-stx-cost:   (unwrap! (get chime-stx-cost (map-get? cost DAPP)) ERR-NOTFOUND),
            chime-ft-cost:  (some value), 
            like-ft-cost:   (unwrap! (get like-ft-cost (map-get? cost DAPP)) ERR-NOTFOUND),
            dislike-ft-cost:   (unwrap! (get dislike-ft-cost (map-get? cost DAPP)) ERR-NOTFOUND),
        }) false)
      (match like-ft-cost value (map-set cost DAPP
        { 
            chime-stx-cost:   (unwrap! (get chime-stx-cost (map-get? cost DAPP)) ERR-NOTFOUND),
            chime-ft-cost:   (unwrap! (get chime-ft-cost (map-get? cost DAPP)) ERR-NOTFOUND),  
            like-ft-cost:   (some value), 
            dislike-ft-cost:   (unwrap! (get dislike-ft-cost (map-get? cost DAPP)) ERR-NOTFOUND) 
        }) false)
      (match dislike-ft-cost value (map-set cost DAPP
        {
            chime-stx-cost:   (unwrap! (get chime-stx-cost (map-get? cost DAPP)) ERR-NOTFOUND), 
            chime-ft-cost:   (unwrap! (get chime-ft-cost (map-get? cost DAPP)) ERR-NOTFOUND), 
            like-ft-cost:   (unwrap! (get like-ft-cost (map-get? cost DAPP)) ERR-NOTFOUND), 
            dislike-ft-cost:   (some value) 
        }) false)
      (ok true)
  )
)

;; Get All Costs
(define-read-only (view-cost)
  (ok (map-get? cost DAPP))
)

;; Get Costs Individually
(define-read-only (get-chime-stx-amount)
  (ok (unwrap! (unwrap! (get chime-stx-cost (map-get? cost DAPP)) ERR-NOTFOUND) ERR-NOTFOUND))
)

(define-read-only (get-chime-ft-amount)
  (ok (unwrap! (unwrap! (get chime-ft-cost (map-get? cost DAPP)) ERR-NOTFOUND) ERR-NOTFOUND))
)

(define-read-only (get-like-ft-amount)
  (ok (unwrap! (unwrap! (get like-ft-cost (map-get? cost DAPP)) ERR-NOTFOUND) ERR-NOTFOUND))
)

(define-read-only (get-dislike-ft-amount)
  (ok (unwrap! (unwrap! (get dislike-ft-cost (map-get? cost DAPP)) ERR-NOTFOUND) ERR-NOTFOUND))
)

;; Validates core-contract (Derupt Core)
(define-read-only (validate-core-contract (input-core-contract principal)) 
  (if (is-eq input-core-contract (var-get derupt-core-contract)) 
    (ok true)
    (ok false)
  )
)

;; Setter for Derupt Core contract address (callable by DAPP, eg when a new .derupt-core-yyyymmdd is deployed by DAPP)
(define-public (set-derupt-core-contract (new-core-contract principal))
  (begin
    (asserts! (is-eq tx-sender DAPP) ERR-UNAUTHORIZED) 
    (asserts! (is-eq new-core-contract tx-sender) ERR-UNAUTHORIZED)
    (ok (var-set derupt-core-contract new-core-contract))
  )
)

;; Get .derupt-core-yyyymmdd contract address
(define-read-only (get-derupt-core-contract) 
    (ok (var-get derupt-core-contract))
)

;; Validates cc-token-contract (CryptoCash Token Contract)
(define-read-only (validate-cc-token-contract (input-contract <cryptocash-token-trait>)) 
  (if (is-eq (contract-of input-contract) (var-get cc-token-contract)) 
    (ok true)
    (ok false)
  )
)

;; Setter for CC Token contract address (callable by DAPP, eg if a new .cryptocash-token is ever required to be deployed by DAPP) 
;; To be used only in the event that CryptoCash requires a hard fork
(define-public (set-cc-token-contract (new-cc-token-contract principal))
  (begin
    (asserts! (is-eq tx-sender DAPP) ERR-UNAUTHORIZED) 
    (asserts! (is-eq new-cc-token-contract tx-sender) ERR-UNAUTHORIZED)
    (ok (var-set cc-token-contract new-cc-token-contract))
  )
)

;; Get .cryptocash-token contract address
(define-read-only (get-cc-token-contract) 
    (ok (var-get cc-token-contract))
)

;; Validates cc-core-contract (CryptoCash Core Contract)
(define-read-only (validate-cc-core-contract (input-contract <cryptocash-core-trait>)) 
  (if (is-eq (contract-of input-contract) (var-get cc-core-contract)) 
    (ok true)
    (ok false)
  )
)

;; Setter for CC Core contract address (callable by DAPP, eg if a new .cryptocash-core is ever required to be deployed by DAPP) 
;; To be used only in the event that CryptoCash requires a hard fork
(define-public (set-cc-core-contract (new-cc-core-contract principal))
  (begin
    (asserts! (is-eq tx-sender DAPP) ERR-UNAUTHORIZED) 
    (asserts! (is-eq new-cc-core-contract tx-sender) ERR-UNAUTHORIZED)
    (ok (var-set cc-core-contract new-cc-core-contract))
  )
)

;; Get .cryptocash-core contract address
(define-read-only (get-cc-core-contract) 
    (ok (var-get cc-core-contract))
)

;; Setter for updating crypto-bros
(define-public (update-crypto-bros (bro (string-ascii 11)) (new-bro principal))        
    (begin 
      (asserts! (is-eq (unwrap! (map-get? crypto-bros bro) ERR-UNAUTHORIZED) tx-sender) ERR-UNAUTHORIZED)
      (asserts! (not (is-eq new-bro tx-sender)) ERR-NEW-BRO-REQUIRED)
      (ok (map-set crypto-bros bro new-bro))
    )
)

(define-read-only (view-crypto-bros (bro (string-ascii 11))) 
  (ok (unwrap! (map-get? crypto-bros bro) ERR-NOTFOUND))
)

;; Setter for updating crypto-partners
(define-public (update-crypto-partners (new-partner principal))        
    (begin 
      (asserts! (is-eq tx-sender (unwrap! (map-get? crypto-bros "cryptodude") ERR-UNAUTHORIZED)) ERR-UNAUTHORIZED)
      
      (asserts! (not (is-eq new-partner tx-sender)) ERR-NEW-PARTNER-REQUIRED)
      (ok (map-set crypto-partners "charity" new-partner))
    )
)

(define-read-only (view-crypto-partners (partner (string-ascii 9))) 
  (ok (unwrap! (map-get? crypto-partners partner) ERR-NOTFOUND))
)

;; Log Send Messages
(define-public (log-send-message 
    (content (string-utf8 256)) (attachment-uri (optional (string-utf8 256))) 
    (thumbnail-uri (optional (string-utf8 256))) (reply-to (optional (string-utf8 256))) 
    (mine-amounts (list 200 uint)) (alt-origin (string-utf8 256))
    (ext (optional <derupt-ext-trait>))
    (pay-dev bool) 
    (pay-gaia bool) 
    (dev-stx-total uint) 
    (gaia-stx-total uint)
    (dev-address (optional principal)) 
    (gaia-address (optional principal)) 
  )
    (let 
      (        
        (chime-stx-total (unwrap! (unwrap! (get chime-stx-cost (map-get? cost DAPP)) ERR-MISSINGARG) ERR-MISSINGARG)) 
        (mine-total (fold + mine-amounts u0))
      ) 
      (asserts! (is-eq contract-caller (var-get derupt-core-contract)) ERR-UNAUTHORIZED)
      (print 
        { 
          event: "send-message", content: content, publisher: tx-sender, attachment-uri: attachment-uri, 
          thumbnail-uri: thumbnail-uri, reply-to: reply-to, alt-origin: alt-origin, ext: ext,
          pay-dev: pay-dev, pay-gaia: pay-gaia, dev-address: dev-address, gaia-address: gaia-address,
          dev-stx-total: dev-stx-total, gaia-stx-total: gaia-stx-total, chime-stx-total: chime-stx-total, mine-total: mine-total, mine-amounts: mine-amounts
        }
      )
      (ok true)
    )
)

(define-public (pay-stx 
  (mine-amounts (list 200 uint)) 
  (pay-dev bool) 
  (pay-gaia bool) 
  (dev-stx-amount uint) 
  (gaia-stx-amount uint)
  (dev-address (optional principal)) 
  (gaia-address (optional principal)) 
  (cryptocash-core-contract <cryptocash-core-trait>)
  )
  (let 
    (
      (dev-stx-total dev-stx-amount) 
      (gaia-stx-total gaia-stx-amount) 
      (chime-stx-total (unwrap! (unwrap! (get chime-stx-cost (map-get? cost DAPP)) ERR-MISSINGARG) ERR-MISSINGARG)) 
      (mine-stx-total (fold + mine-amounts u0)) 
      (user-stx-balance (stx-get-balance tx-sender))
    )     
    ;; CryptoCash core version check
    (asserts! (unwrap! (validate-cc-core-contract cryptocash-core-contract) ERR-NOTFOUND) ERR-WRONG-CC-CORE-VERSION)
    
    (if (and pay-dev pay-gaia) 
    ;; Case 1: pay-dev and pay-gaia are both true hence pay all
      (begin 
        (asserts! (> user-stx-balance (+ chime-stx-total dev-stx-total gaia-stx-total mine-stx-total)) ERR-INSUFFICIENT-BALANCE)
        (try! (contract-call? cryptocash-core-contract mine mine-amounts))
        (try! (stx-transfer? (/ chime-stx-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptodude") ERR-UNAUTHORIZED)))
        (try! (stx-transfer? (/ chime-stx-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptosmith") ERR-UNAUTHORIZED)))
        (try! (stx-transfer? (/ chime-stx-total u3) tx-sender (unwrap! (map-get? crypto-partners "charity") ERR-UNAUTHORIZED)))
        (try! (stx-transfer? dev-stx-total tx-sender (unwrap! dev-address ERR-MISSINGARG)))
        (try! (stx-transfer? gaia-stx-total tx-sender (unwrap! gaia-address ERR-MISSINGARG)))
        (ok true)
      )
      (if (or pay-dev pay-gaia)
      ;; Here we use 'or' to switch either if pay-dev or pay-gaia is true
        (if pay-dev 
        ;; Case 2: pay-dev is true while pay-gaia is false hence pay dev + normal
          (begin 
            (asserts! (> user-stx-balance (+ chime-stx-total dev-stx-total mine-stx-total)) ERR-INSUFFICIENT-BALANCE)
            (try! (contract-call? cryptocash-core-contract mine mine-amounts))
            (try! (stx-transfer? (/ chime-stx-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptodude") ERR-UNAUTHORIZED)))
            (try! (stx-transfer? (/ chime-stx-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptosmith") ERR-UNAUTHORIZED)))
            (try! (stx-transfer? (/ chime-stx-total u3) tx-sender (unwrap! (map-get? crypto-partners "charity") ERR-UNAUTHORIZED)))
            (try! (stx-transfer? dev-stx-total tx-sender (unwrap! dev-address ERR-MISSINGARG)))
            (ok true)
          )
          ;; Case 3: pay-gaia is true while pay-dev is false hence pay-gaia + normal
          (begin 
            (asserts! (> user-stx-balance (+ chime-stx-total gaia-stx-total mine-stx-total)) ERR-INSUFFICIENT-BALANCE)
            (try! (contract-call? cryptocash-core-contract mine mine-amounts))
            (try! (stx-transfer? (/ chime-stx-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptodude") ERR-UNAUTHORIZED)))
            (try! (stx-transfer? (/ chime-stx-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptosmith") ERR-UNAUTHORIZED)))
            (try! (stx-transfer? (/ chime-stx-total u3) tx-sender (unwrap! (map-get? crypto-partners "charity") ERR-UNAUTHORIZED)))
            (try! (stx-transfer? gaia-stx-total tx-sender (unwrap! gaia-address ERR-MISSINGARG)))
            (ok true)
          )
        )
        ;; Case 4: pay-dev and pay-gaia are both false hence pay only normal
        (begin 
          (asserts! (> user-stx-balance (+ chime-stx-total mine-stx-total)) ERR-INSUFFICIENT-BALANCE)
          (try! (contract-call? cryptocash-core-contract mine mine-amounts))
          (try! (stx-transfer? (/ chime-stx-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptodude") ERR-UNAUTHORIZED)))
          (try! (stx-transfer? (/ chime-stx-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptosmith") ERR-UNAUTHORIZED)))
          (try! (stx-transfer? (/ chime-stx-total u3) tx-sender (unwrap! (map-get? crypto-partners "charity") ERR-UNAUTHORIZED)))
          (ok true)
        )
      )     
    )
  )
)

(define-public (pay-ft-like
  (author-principal principal)
  (like-ft-amount uint)
  (pay-dev bool) 
  (pay-gaia bool) 
  (dev-ft-amount uint) 
  (gaia-ft-amount uint)
  (dev-address (optional principal)) 
  (gaia-address (optional principal)) 
  (cryptocash-token-contract <cryptocash-token-trait>)
  )
  (let 
    (
      (dev-ft-total dev-ft-amount) 
      (gaia-ft-total gaia-ft-amount) 
      (chime-ft-total (unwrap! (unwrap! (get chime-ft-cost (map-get? cost DAPP)) ERR-MISSINGARG) ERR-MISSINGARG)) 
      (like-ft-total like-ft-amount) 
      (like-ft-minimum (unwrap! (unwrap! (get like-ft-cost (map-get? cost DAPP)) ERR-MISSINGARG) ERR-MISSINGARG)) 
      (user-ft-balance (unwrap! (contract-call? cryptocash-token-contract get-balance tx-sender) ERR-MISSINGARG))
    ) 
    (begin
      ;; CryptoCash token version check
      (asserts! (unwrap! (validate-cc-token-contract cryptocash-token-contract) ERR-NOTFOUND) ERR-WRONG-CC-TOKEN-VERSION)
      (asserts! (>= like-ft-total like-ft-minimum) ERR-INSUFFICIENT-BALANCE)

      (if (and pay-dev pay-gaia) 
      ;; Case 1: pay-dev and pay-gaia are both true hence pay all
        (begin 
          (asserts! (> user-ft-balance (+ chime-ft-total dev-ft-total gaia-ft-total like-ft-total)) ERR-INSUFFICIENT-BALANCE)
          (try! (contract-call? cryptocash-token-contract transfer like-ft-total tx-sender author-principal none ))
          (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptodude") ERR-UNAUTHORIZED) none))
          (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptosmith") ERR-UNAUTHORIZED) none))
          (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-partners "charity") ERR-UNAUTHORIZED) none))
          (try! (contract-call? cryptocash-token-contract transfer dev-ft-total tx-sender (unwrap! dev-address ERR-MISSINGARG) none))
          (try! (contract-call? cryptocash-token-contract transfer gaia-ft-total tx-sender (unwrap! gaia-address ERR-MISSINGARG) none))
          (ok true)
        )
        (if (or pay-dev pay-gaia)
        ;; Here we use 'or' to switch either if pay-dev or pay-gaia is true
          (if pay-dev 
          ;; Case 2: pay-dev is true while pay-gaia is false hence pay dev + normal
            (begin
              (asserts! (> user-ft-balance (+ chime-ft-total dev-ft-total like-ft-total)) ERR-INSUFFICIENT-BALANCE)
              (try! (contract-call? cryptocash-token-contract transfer like-ft-total tx-sender author-principal none))
              (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptodude") ERR-UNAUTHORIZED) none))
              (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptosmith") ERR-UNAUTHORIZED) none))
              (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-partners "charity") ERR-UNAUTHORIZED) none))
              (try! (contract-call? cryptocash-token-contract transfer dev-ft-total tx-sender (unwrap! dev-address ERR-MISSINGARG) none))
              (ok true)
            )
            ;; Case 3: pay-gaia is true while pay-dev is false hence pay-gaia + normal
            (begin 
              (asserts! (> user-ft-balance (+ chime-ft-total gaia-ft-total like-ft-total)) ERR-INSUFFICIENT-BALANCE)
              (try! (contract-call? cryptocash-token-contract transfer like-ft-total tx-sender author-principal none))
              (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptodude") ERR-UNAUTHORIZED) none))
              (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptosmith") ERR-UNAUTHORIZED) none))
              (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-partners "charity") ERR-UNAUTHORIZED) none))
              (try! (contract-call? cryptocash-token-contract transfer gaia-ft-total tx-sender (unwrap! gaia-address ERR-MISSINGARG) none))
              (ok true)
            )
          )
          ;; Case 4: pay-dev and pay-gaia are both false hence pay only normal
          (begin 
            (asserts! (> user-ft-balance (+ chime-ft-total like-ft-total)) ERR-INSUFFICIENT-BALANCE)
            (try! (contract-call? cryptocash-token-contract transfer like-ft-total tx-sender author-principal none))
            (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptodude") ERR-UNAUTHORIZED) none))
            (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptosmith") ERR-UNAUTHORIZED) none))
            (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-partners "charity") ERR-UNAUTHORIZED) none))
            (ok true)
          )
        )     
      )    
    )    
  )
)

(define-public (pay-ft-dislike
  (dislike-ft-amount uint)
  (lockPeriod uint)
  (pay-dev bool) 
  (pay-gaia bool) 
  (dev-ft-amount uint) 
  (gaia-ft-amount uint)
  (dev-address (optional principal)) 
  (gaia-address (optional principal)) 
  (cryptocash-token-contract <cryptocash-token-trait>)
  (cryptocash-core-contract <cryptocash-core-trait>)
  )
  (let 
    (
      (dev-ft-total dev-ft-amount) 
      (gaia-ft-total gaia-ft-amount) 
      (chime-ft-total (unwrap! (unwrap! (get chime-ft-cost (map-get? cost DAPP)) ERR-MISSINGARG) ERR-MISSINGARG)) 
      (dislike-ft-total dislike-ft-amount) 
      (dislike-ft-minimum (unwrap! (unwrap! (get dislike-ft-cost (map-get? cost DAPP)) ERR-MISSINGARG) ERR-MISSINGARG)) 
      (user-ft-balance (unwrap! (contract-call? cryptocash-token-contract get-balance tx-sender) ERR-MISSINGARG))
    ) 
    (begin
      ;; CryptoCash Token and Core version checks
      (asserts! (unwrap! (validate-cc-token-contract cryptocash-token-contract) ERR-NOTFOUND) ERR-WRONG-CC-TOKEN-VERSION)
      (asserts! (unwrap! (validate-cc-core-contract cryptocash-core-contract) ERR-NOTFOUND) ERR-WRONG-CC-CORE-VERSION)

      (asserts! (> lockPeriod u0) ERR-INSUFFICIENT-ARG)
      (asserts! (>= dislike-ft-total dislike-ft-minimum) ERR-INSUFFICIENT-ARG) 
      (if (and pay-dev pay-gaia) 
      ;; Case 1: pay-dev and pay-gaia are both true hence pay all
        (begin          
          (asserts! (> user-ft-balance (+ chime-ft-total dev-ft-total gaia-ft-total dislike-ft-total)) ERR-INSUFFICIENT-BALANCE)
          (try! (contract-call? cryptocash-core-contract stack dislike-ft-total lockPeriod))
          (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptodude") ERR-UNAUTHORIZED) none))
          (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptosmith") ERR-UNAUTHORIZED) none))
          (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-partners "charity") ERR-UNAUTHORIZED) none))
          (try! (contract-call? cryptocash-token-contract transfer dev-ft-total tx-sender (unwrap! dev-address ERR-MISSINGARG) none))
          (try! (contract-call? cryptocash-token-contract transfer gaia-ft-total tx-sender (unwrap! gaia-address ERR-MISSINGARG) none))
          (ok true)
        )
        (if (or pay-dev pay-gaia)
        ;; Here we use 'or' to switch either if pay-dev or pay-gaia is true
          (if pay-dev 
          ;; Case 2: pay-dev is true while pay-gaia is false hence pay dev + normal
            (begin 
              (asserts! (> user-ft-balance (+ chime-ft-total dev-ft-total dislike-ft-total)) ERR-INSUFFICIENT-BALANCE)
              (try! (contract-call? cryptocash-core-contract stack dislike-ft-total lockPeriod))
              (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptodude") ERR-UNAUTHORIZED) none))
              (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptosmith") ERR-UNAUTHORIZED) none))
              (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-partners "charity") ERR-UNAUTHORIZED) none))
              (try! (contract-call? cryptocash-token-contract transfer dev-ft-total tx-sender (unwrap! dev-address ERR-MISSINGARG) none))
              (ok true)
            )
            ;; Case 3: pay-gaia is true while pay-dev is false hence pay-gaia + normal
            (begin
              (asserts! (> user-ft-balance (+ chime-ft-total gaia-ft-total dislike-ft-total)) ERR-INSUFFICIENT-BALANCE)
              (try! (contract-call? cryptocash-core-contract stack dislike-ft-total lockPeriod))
              (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptodude") ERR-UNAUTHORIZED) none))
              (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptosmith") ERR-UNAUTHORIZED) none))
              (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-partners "charity") ERR-UNAUTHORIZED) none))
              (try! (contract-call? cryptocash-token-contract transfer gaia-ft-total tx-sender (unwrap! gaia-address ERR-MISSINGARG) none))
              (ok true)
            )
          )
          ;; Case 4: pay-dev and pay-gaia are both false hence pay only normal
          (begin
            (asserts! (> user-ft-balance (+ chime-ft-total dislike-ft-total)) ERR-INSUFFICIENT-BALANCE)
            (try! (contract-call? cryptocash-core-contract stack dislike-ft-total lockPeriod))
            (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptodude") ERR-UNAUTHORIZED) none))
            (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-bros "cryptosmith") ERR-UNAUTHORIZED) none))
            (try! (contract-call? cryptocash-token-contract transfer (/ chime-ft-total u3) tx-sender (unwrap! (map-get? crypto-partners "charity") ERR-UNAUTHORIZED) none))
            (ok true)
          )
        )     
      )
    )
    
  )
)

;; Default cost map insertion
(map-insert cost DAPP { chime-stx-cost:  (some u100000), chime-ft-cost:  (some u10), like-ft-cost:  (some u100), dislike-ft-cost:  (some u100) })

;; Mapp insertion for crypto-bros principals
;; (map-insert crypto-bros "cryptodude" 'SP3ABD2FW64Y75W22R4G9TVKF6EA79RZHRC5BG4HD)
;; (map-insert crypto-bros "cryptosmith" 'SP2E9NTWSFGEN393GHT0CC4K7QCEX2CGYK0G2TY2F)
(map-insert crypto-bros "cryptodude" 'ST3WAR3N1XRR139DXCGPR1ATPK2VN63PGRYJTFK5N)
(map-insert crypto-bros "cryptosmith" 'ST30RNTQNY63F6XR66J2Q3WP1THZT3VHZGYEXA9XX)


;; Map insertion for crypto partners
;; replace periodically with a variable charity principal that we partner with for a temparory period of time. Rotating in new charities
;; (map-insert crypto-partners "charity" 'SP16DCVM40B7DDPZQ6R9XZ8FXSH52246GP1C4FJPP)
(map-insert crypto-partners "charity" 'STSM74KAMAH949MDDYAAZZ8V2W9YAS07F8WCD7K6)

Last updated