Source Code

;; Title: Energize
;; Version: 1.0.0
;; Description: A vault for harvesting hold-to-earn energy rewards

(impl-trait .dexterity-traits-v0.liquidity-pool-trait)

;; Constants
(define-constant DEPLOYER tx-sender)
(define-constant CONTRACT (as-contract tx-sender))
(define-constant ERR_INVALID_OPERATION (err u4002))

;; Opcodes
(define-constant OP_HARVEST_ENERGY 0x07)

;; Metadata
(define-data-var metadata-uri (optional (string-utf8 256)) none)
(define-read-only (get-token-uri) (ok (var-get metadata-uri)))

;; --- Helper Functions ---

(define-private (get-byte (opcode (optional (buff 16))) (position uint))
    (default-to 0x00 (element-at? (default-to 0x00 opcode) position)))

;; --- Core Functions ---

(define-public (execute (amount uint) (opcode (optional (buff 16))))
    (let ((operation (get-byte opcode u0)))
        (if (is-eq operation OP_HARVEST_ENERGY) (harvest-energy)
        ERR_INVALID_OPERATION)))

(define-read-only (quote (amount uint) (opcode (optional (buff 16))))
    (let ((operation (get-byte opcode u0)))
        (if (is-eq operation OP_HARVEST_ENERGY) (ok {dx: u0, dy: u0, dk: (- stacks-block-height (get-last-tap-block))})
        ERR_INVALID_OPERATION)))

(define-public (harvest-energy)
    (contract-call? 'SP2D5BGGJ956A635JG7CJQ59FTRFRB0893514EZPJ.dexterity-hold-to-earn tap))

(define-private (get-last-tap-block)
    (contract-call? 'SP2D5BGGJ956A635JG7CJQ59FTRFRB0893514EZPJ.dexterity-hold-to-earn get-last-tap-block tx-sender))

;; --- Initialization ---

(begin
    (var-set metadata-uri (some u"data:application/json;base64,ewogICJuYW1lIjogIkVuZXJnaXplIiwKICAiaW1hZ2UiOiAiZGF0YTppbWFnZS9wbmc7YmFzZTY0LGlWQk9SdzBLR2dvQUFBQU5TVWhFVWdBQUFBRUFBQUFCQ0FJQUFBQ1FkMVBlQUFBQUVFbEVRVlI0bkdJeVB4c0hDQUFBLy84Q3FRRmxKMi9tN1FBQUFBQkpSVTVFcmtKZ2dnPT0iCn0="))
)

Functions (6)

FunctionAccessArgs
get-token-uriread-only
get-byteprivateopcode: (optional (buff 16
executepublicamount: uint, opcode: (optional (buff 16
quoteread-onlyamount: uint, opcode: (optional (buff 16
harvest-energypublic
get-last-tap-blockprivate