LCOV - code coverage report
Current view: top level - contracts/extensions - bme004-0-core-execute.clar (source / functions) Coverage Total Hit
Test: lcov.info Lines: 75.0 % 36 27
Test Date: 2025-11-05 10:54:00 Functions: 70.0 % 10 7
Branches: 41.7 % 12 5

             Branch data     Line data    Source code
       1                 :             : ;; Title: BME04 Core Execute
       2                 :             : ;; Synopsis:
       3                 :             : ;; This extension allows a small number of very trusted principals to immediately
       4                 :             : ;; execute a proposal once a super majority is reached.
       5                 :             : ;; Description:
       6                 :             : ;; An extension meant for the bootstrapping period of a DAO. It temporarily gives
       7                 :             : ;; some very trusted principals the ability to perform an "executive action";
       8                 :             : ;; meaning, they can skip the voting process to immediately executive a proposal.
       9                 :             : ;; The Core execute extension has an optional sunset period of ~1 month from deploy
      10                 :             : ;; time, set it to 0 to disable. The core executive team, parameters, and sunset period may be changed
      11                 :             : ;; by means of a future proposal.
      12                 :             : 
      13                 :             : (impl-trait 'SP3JP0N1ZXGASRJ0F7QAHWFPGTVK9T2XNXDB908Z.extension-trait.extension-trait)
      14                 :             : (use-trait proposal-trait  'SP3JP0N1ZXGASRJ0F7QAHWFPGTVK9T2XNXDB908Z.proposal-trait.proposal-trait)
      15                 :             : 
      16                 :             : (define-data-var executive-team-sunset-height uint u0) ;; does not expire by default - can be changed by proposal
      17                 :             : 
      18                 :             : (define-constant err-unauthorised (err u3400))
      19                 :             : (define-constant err-not-executive-team-member (err u3401))
      20                 :             : (define-constant err-already-executed (err u3402))
      21                 :             : (define-constant err-sunset-height-reached (err u3403))
      22                 :             : (define-constant err-sunset-height-in-past (err u3404))
      23                 :             : 
      24                 :             : (define-map executive-team principal bool)
      25                 :             : (define-map executive-action-signals {proposal: principal, team-member: principal} bool)
      26                 :             : (define-map executive-action-signal-count principal uint)
      27                 :             : 
      28                 :             : (define-data-var executive-signals-required uint u1) ;; signals required for an executive action.
      29                 :             : 
      30                 :             : ;; --- Authorisation check
      31                 :             : 
      32                 :         289 : (define-public (is-dao-or-extension)
      33    [ - ][ +  - ]:        1445 :         (ok (asserts! (or (is-eq tx-sender .bigmarket-dao) (contract-call? .bigmarket-dao is-extension contract-caller)) err-unauthorised))
      34                 :             : )
      35                 :             : 
      36                 :             : ;; --- Internal DAO functions
      37                 :             : 
      38                 :           0 : (define-public (set-executive-team-sunset-height (height uint))
      39                 :           0 :         (begin
      40                 :           0 :                 (try! (is-dao-or-extension))
      41            [ - ]:           0 :                 (asserts! (> height burn-block-height) err-sunset-height-in-past)
      42                 :           0 :                 (ok (var-set executive-team-sunset-height height))
      43                 :             :         )
      44                 :             : )
      45                 :             : 
      46                 :         289 : (define-public (set-executive-team-member (who principal) (member bool))
      47                 :        1156 :         (begin
      48                 :        1156 :                 (try! (is-dao-or-extension))
      49                 :        1156 :                 (ok (map-set executive-team who member))
      50                 :             :         )
      51                 :             : )
      52                 :             : 
      53                 :         289 : (define-public (set-signals-required (new-requirement uint))
      54                 :         289 :         (begin
      55                 :         289 :                 (try! (is-dao-or-extension))
      56                 :         289 :                 (ok (var-set executive-signals-required new-requirement))
      57                 :             :         )
      58                 :             : )
      59                 :             : 
      60                 :             : ;; --- Public functions
      61                 :             : 
      62                 :          16 : (define-read-only (is-executive-team-member (who principal))
      63                 :          44 :         (default-to false (map-get? executive-team who))
      64                 :             : )
      65                 :             : 
      66                 :          16 : (define-read-only (has-signalled (proposal principal) (who principal))
      67                 :          44 :         (default-to false (map-get? executive-action-signals {proposal: proposal, team-member: who}))
      68                 :             : )
      69                 :             : 
      70                 :           0 : (define-read-only (get-signals-required)
      71                 :           0 :         (var-get executive-signals-required)
      72                 :             : )
      73                 :             : 
      74                 :          16 : (define-read-only (get-signals (proposal principal))
      75                 :          44 :         (default-to u0 (map-get? executive-action-signal-count proposal))
      76                 :             : )
      77                 :             : 
      78                 :          16 : (define-public (executive-action (proposal <proposal-trait>))
      79                 :          44 :         (let
      80                 :             :                 (
      81                 :          44 :                         (proposal-principal (contract-of proposal))
      82         [ -  + ]:          44 :                         (signals (+ (get-signals proposal-principal) (if (has-signalled proposal-principal tx-sender) u0 u1)))
      83                 :             :                 )
      84            [ - ]:          44 :                 (asserts! (is-executive-team-member tx-sender) err-not-executive-team-member)
      85    [ - ][ +  - ]:          44 :                 (asserts! (or (is-eq (var-get executive-team-sunset-height) u0) (< burn-block-height (var-get executive-team-sunset-height))) err-sunset-height-reached)
      86            [ + ]:          44 :                 (and (>= signals (var-get executive-signals-required))
      87            [ + ]:          44 :                         (try! (contract-call? .bigmarket-dao execute proposal tx-sender))
      88                 :             :                 )
      89                 :          22 :                 (map-set executive-action-signals {proposal: proposal-principal, team-member: tx-sender} true)
      90                 :          22 :                 (map-set executive-action-signal-count proposal-principal signals)
      91                 :          22 :                 (ok signals)
      92                 :             :         )
      93                 :             : )
      94                 :             : 
      95                 :             : ;; --- Extension callback
      96                 :             : 
      97                 :           0 : (define-public (callback (sender principal) (memo (buff 34)))
      98                 :           0 :         (ok true)
      99                 :             : )
        

Generated by: LCOV version 2.3.2-1