Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Select contracts implementing the correct trait from the Clarinet project for argument generation #88

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
26 changes: 26 additions & 0 deletions citizen.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@ describe("Simnet deployment plan operations", () => {

// Verify
const expected = {
"2.4": [
{
dao: {
clarity_version: 2,
path: "./.cache/requirements/SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.dao.clar",
},
},
{
"sip-010-trait-ft-standard": {
clarity_version: 2,
path: "./.cache/requirements/SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.sip-010-trait-ft-standard.clar",
},
},
{
"ststx-token": {
clarity_version: 2,
path: "./.cache/requirements/SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.ststx-token.clar",
},
},
],
"3.0": [
{
cargo: {
Expand All @@ -106,6 +126,12 @@ describe("Simnet deployment plan operations", () => {
clarity_version: 3,
},
},
{
trait: {
path: "contracts/trait.clar",
clarity_version: 3,
},
},
],
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
;; @contract DAO
;; @version 1

;;-------------------------------------
;; Constants
;;-------------------------------------

(define-constant ERR_NOT_ADMIN u20001)
(define-constant ERR_CONTRACTS_DISABLED u20002)
(define-constant ERR_INACTIVE_CONTRACT u20003)

;;-------------------------------------
;; Variables
;;-------------------------------------

(define-data-var contracts-enabled bool true)

;;-------------------------------------
;; Maps
;;-------------------------------------

(define-map contracts
{
address: principal
}
{
active: bool,
}
)

(define-map admins
{
address: principal
}
{
active: bool,
}
)

;;-------------------------------------
;; Getters
;;-------------------------------------

(define-read-only (get-contracts-enabled)
(var-get contracts-enabled)
)

(define-read-only (get-contract-active (address principal))
(get active
(default-to
{ active: false }
(map-get? contracts { address: address })
)
)
)

(define-read-only (get-admin (address principal))
(get active
(default-to
{ active: false }
(map-get? admins { address: address })
)
)
)

;;-------------------------------------
;; Checks
;;-------------------------------------

(define-public (check-is-enabled)
(begin
(asserts! (var-get contracts-enabled) (err ERR_CONTRACTS_DISABLED))
(ok true)
)
)

(define-public (check-is-protocol (contract principal))
(begin
(asserts! (get-contract-active contract) (err ERR_INACTIVE_CONTRACT))
(ok true)
)
)

(define-public (check-is-admin (contract principal))
(begin
(asserts! (get-admin contract) (err ERR_NOT_ADMIN))
(ok true)
)
)

;;-------------------------------------
;; Set
;;-------------------------------------

(define-public (set-contracts-enabled (enabled bool))
(begin
(try! (check-is-admin tx-sender))
(var-set contracts-enabled enabled)
(ok true)
)
)

(define-public (set-contract-active (address principal) (active bool))
(begin
(try! (check-is-admin tx-sender))
(map-set contracts { address: address } { active: active }
)
(ok true)
)
)

(define-public (set-admin (address principal) (active bool))
(begin
(try! (check-is-admin tx-sender))
(map-set admins { address: address } { active: active }
)
(ok true)
)
)

;;-------------------------------------
;; Init
;;-------------------------------------

(begin
(map-set admins { address: tx-sender } { active: true })

(map-set contracts { address: tx-sender } { active: true })

(map-set contracts { address: .stacking-dao-core-v1 } { active: true })
(map-set contracts { address: .reserve-v1 } { active: true })
(map-set contracts { address: .commission-v1 } { active: true })

(map-set contracts { address: .stacker-1 } { active: true })
(map-set contracts { address: .stacker-2 } { active: true })
(map-set contracts { address: .stacker-3 } { active: true })
(map-set contracts { address: .stacker-4 } { active: true })
(map-set contracts { address: .stacker-5 } { active: true })
(map-set contracts { address: .stacker-6 } { active: true })
(map-set contracts { address: .stacker-7 } { active: true })
(map-set contracts { address: .stacker-8 } { active: true })
(map-set contracts { address: .stacker-9 } { active: true })
(map-set contracts { address: .stacker-10 } { active: true })
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"epoch": "Epoch24",
"clarity_version": "Clarity2"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(define-trait sip-010-trait
(
;; Transfer from the caller to a new principal
(transfer (uint principal principal (optional (buff 34))) (response bool uint))

;; the human readable name of the token
(get-name () (response (string-ascii 32) uint))

;; the ticker symbol, or empty if none
(get-symbol () (response (string-ascii 32) uint))

;; the number of decimals used, e.g. 6 would mean 1_000_000 represents 1 token
(get-decimals () (response uint uint))

;; the balance of the passed principal
(get-balance (principal) (response uint uint))

;; the current total supply (which does not need to be a constant)
(get-total-supply () (response uint uint))

;; an optional URI that represents metadata of this token
(get-token-uri () (response (optional (string-utf8 256)) uint))
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"epoch": "Epoch24",
"clarity_version": "Clarity2"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
(impl-trait .sip-010-trait-ft-standard.sip-010-trait)

;; Defines the Stacked STX according to the SIP010 Standard
(define-fungible-token ststx)

(define-constant ERR_NOT_AUTHORIZED u1401)

;;-------------------------------------
;; Variables
;;-------------------------------------

(define-data-var token-uri (string-utf8 256) u"")

;;-------------------------------------
;; SIP-010
;;-------------------------------------

(define-read-only (get-total-supply)
(ok (ft-get-supply ststx))
)

(define-read-only (get-name)
(ok "Stacked STX Token")
)

(define-read-only (get-symbol)
(ok "stSTX")
)

(define-read-only (get-decimals)
(ok u6)
)

(define-read-only (get-balance (account principal))
(ok (ft-get-balance ststx account))
)

(define-read-only (get-token-uri)
(ok (some (var-get token-uri)))
)

(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34))))
(begin
(asserts! (is-eq tx-sender sender) (err ERR_NOT_AUTHORIZED))

(match (ft-transfer? ststx amount sender recipient)
response (begin
(print memo)
(print { action: "transfer", data: { sender: tx-sender, recipient: recipient, amount: amount, block-height: block-height } })
(ok response)
)
error (err error)
)
)
)

;;-------------------------------------
;; Admin
;;-------------------------------------

(define-public (set-token-uri (value (string-utf8 256)))
(begin
(try! (contract-call? .dao check-is-protocol tx-sender))
(ok (var-set token-uri value))
)
)

;;-------------------------------------
;; Mint / Burn
;;-------------------------------------

;; Mint method
(define-public (mint-for-protocol (amount uint) (recipient principal))
(begin
(try! (contract-call? .dao check-is-protocol contract-caller))
(ft-mint? ststx amount recipient)
)
)

;; Burn method
(define-public (burn-for-protocol (amount uint) (sender principal))
(begin
(try! (contract-call? .dao check-is-protocol contract-caller))
(ft-burn? ststx amount sender)
)
)

;; Burn external
(define-public (burn (amount uint))
(begin
(ft-burn? ststx amount tx-sender)
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"epoch": "Epoch24",
"clarity_version": "Clarity2"
}
8 changes: 8 additions & 0 deletions example/Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name = "example"
telemetry = false
cache_dir = "./.cache"

[[project.requirements]]
contract_id = 'SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.ststx-token'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it that adding this as requirement adds also dao and sip-010-trait-ft-standard, right?


[contracts.cargo]
path = "contracts/cargo.clar"
clarity_version = 3
Expand All @@ -23,6 +26,11 @@ path = "contracts/slice.clar"
clarity_version = 3
epoch = 3.0

[contracts.trait]
path = 'contracts/trait.clar'
clarity_version = 3
epoch = 3.0

[repl.analysis]
passes = ["check_checker"]
check_checker = { trusted_sender = false, trusted_caller = false, callee_filter = false }
3 changes: 3 additions & 0 deletions example/contracts/trait.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(define-public (function)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This contract is named trait but has just a function in it?

(ok true)
)
9 changes: 9 additions & 0 deletions example/contracts/trait.tests.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(use-trait ft-trait 'SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.sip-010-trait-ft-standard.sip-010-trait)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use this trait in the examples, why do we require ststx-token after all?


(define-public (test-no-trait)
(ok true)
)

(define-public (test-trait (token <ft-trait>))
(ok true)
)
Loading
Loading