Source Code

;; Dungeon Crawler Contract
;;
;; This contract serves as the primary interface for user interactions within the Charisma protocol.
;; It acts as a central hub for executing actions across various interaction contracts, enabling
;; users to engage with multiple protocol components in a single transaction.
;;
;; Key Responsibilities:
;; 1. Action Execution: Coordinates the execution of actions on interaction contracts.
;; 2. Multi-Interaction Support: Allows users to execute up to eight different interactions in one transaction.
;; 3. Error Handling: Implements a "best-effort" approach, attempting all interactions even if some fail.
;;
;; Core Components:
;; - Interaction Execution: Provides functions to execute single or multiple interactions.
;; - Error Clobbering: Continues execution of subsequent interactions even if earlier ones fail.
;;
;; Integration with Charisma Ecosystem:
;; - Interaction Contracts: Executes actions on various protocol components through standardized interfaces.
;; - Dungeon Keeper: Relies on for interaction verification and privileged operations (indirectly through interactions).
;; - Token Contracts: Interacts with Experience, Energy, DMG, and Charisma token contracts indirectly through verified interactions.
;;
;; Key Functions:
;; - interact: Executes a single interaction with the specified action.
;; - explore: Executes up to eight different interactions in a single transaction.
;;
;; Security Features:
;; - Interaction Isolation: Each interaction is executed independently, preventing cascading failures.
;; - Non-Privileged Execution: The Dungeon Crawler itself does not perform sensitive operations, relying on properly verified interaction contracts.
;;
;; Error Handling Philosophy:
;; The Dungeon Crawler implements a "best-effort" approach to interaction execution:
;; - In single interactions, errors are propagated to the caller for handling.
;; - In multi-interaction calls, the contract attempts to execute all provided interactions, regardless of individual failures.
;; - This approach ensures maximum utility from each transaction while isolating failures.
;;
;; This contract is crucial for enabling flexible and robust user engagement with the Charisma protocol.
;; It provides a streamlined interface for executing complex sequences of interactions while maintaining
;; system integrity. The architecture supports the protocol's innovative approach to multi-faceted
;; blockchain interactions, allowing for complex operations to be performed in a single transaction.

(use-trait interaction-trait .dao-traits-v7.interaction-trait)

(define-public (interact (interaction <interaction-trait>) (action (string-ascii 32)))
  (contract-call? interaction execute action))

(define-public (explore
  (interaction-1 (optional <interaction-trait>)) (action-1 (optional (string-ascii 32)))
  (interaction-2 (optional <interaction-trait>)) (action-2 (optional (string-ascii 32)))
  (interaction-3 (optional <interaction-trait>)) (action-3 (optional (string-ascii 32)))
  (interaction-4 (optional <interaction-trait>)) (action-4 (optional (string-ascii 32)))
  (interaction-5 (optional <interaction-trait>)) (action-5 (optional (string-ascii 32)))
  (interaction-6 (optional <interaction-trait>)) (action-6 (optional (string-ascii 32)))
  (interaction-7 (optional <interaction-trait>)) (action-7 (optional (string-ascii 32)))
  (interaction-8 (optional <interaction-trait>)) (action-8 (optional (string-ascii 32))))
  (let (
    (response-1 (if (is-some action-1) (match (interact (unwrap-panic interaction-1) (unwrap-panic action-1)) success success error error) ""))
    (response-2 (if (is-some action-2) (match (interact (unwrap-panic interaction-2) (unwrap-panic action-2)) success success error error) ""))
    (response-3 (if (is-some action-3) (match (interact (unwrap-panic interaction-3) (unwrap-panic action-3)) success success error error) ""))
    (response-4 (if (is-some action-4) (match (interact (unwrap-panic interaction-4) (unwrap-panic action-4)) success success error error) ""))
    (response-5 (if (is-some action-5) (match (interact (unwrap-panic interaction-5) (unwrap-panic action-5)) success success error error) ""))
    (response-6 (if (is-some action-6) (match (interact (unwrap-panic interaction-6) (unwrap-panic action-6)) success success error error) ""))
    (response-7 (if (is-some action-7) (match (interact (unwrap-panic interaction-7) (unwrap-panic action-7)) success success error error) ""))
    (response-8 (if (is-some action-8) (match (interact (unwrap-panic interaction-8) (unwrap-panic action-8)) success success error error) ""))
    (output {
      i1: {i: (unwrap-panic interaction-1), a: (unwrap-panic action-1), r: response-1},
      i2: {i: (unwrap-panic interaction-2), a: (unwrap-panic action-2), r: response-2},
      i3: {i: (unwrap-panic interaction-3), a: (unwrap-panic action-3), r: response-3},
      i4: {i: (unwrap-panic interaction-4), a: (unwrap-panic action-4), r: response-4},
      i5: {i: (unwrap-panic interaction-5), a: (unwrap-panic action-5), r: response-5},
      i6: {i: (unwrap-panic interaction-6), a: (unwrap-panic action-6), r: response-6},
      i7: {i: (unwrap-panic interaction-7), a: (unwrap-panic action-7), r: response-7},
      i8: {i: (unwrap-panic interaction-8), a: (unwrap-panic action-8), r: response-8},
    }))
    (print output)
    (ok output)))

Functions (2)

FunctionAccessArgs
interactpublicinteraction: <interaction-trait>, action: (string-ascii 32
explorepublicinteraction-1: (optional <interaction-trait>