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

feat: public-pools-strategy-manager Dead Man's Switch #55

Open
wants to merge 2 commits into
base: mainnet
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ requirements = [
{ contract_id = "SM3KNVZS30WM7F89SXKVVFY4SN9RMPZZ9FX929N0V.li-stx-mint-nft" },
{ contract_id = "SM3KNVZS30WM7F89SXKVVFY4SN9RMPZZ9FX929N0V.li-stx-burn-nft" },
{ contract_id = "SM3KNVZS30WM7F89SXKVVFY4SN9RMPZZ9FX929N0V.lqstx-mint-endpoint-v2-01" },
{ contract_id = "SM3KNVZS30WM7F89SXKVVFY4SN9RMPZZ9FX929N0V.public-pools-strategy-v2" },
{ contract_id = "SPGAB1P3YV109E22KXFJYM63GK0G21BYX50CQ80B.lip005" },
{ contract_id = "SP3BQ65DRM8DMTYDD5HWMN60EYC0JFS5NC2V5CWW7.lip006" },
{ contract_id = "SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.executor-dao" },
Expand All @@ -27,3 +28,7 @@ requirements = [
[contracts.lip007]
path = "contracts/proposals/lip007.clar"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be a requirement.

epoch = 2.5

[contracts.public-pools-strategy-manager-v3]
path = "contracts/extensions/public-pools-strategy-manager.clar"
epoch = 2.5
39 changes: 36 additions & 3 deletions contracts/extensions/public-pools-strategy-manager.clar
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
;; SPDX-License-Identifier: BUSL-1.1

(define-constant err-unauthorised (err u3000))
(define-constant err-still-alive (err u3001))

(define-constant dms-activation-period u12960) ;; ~90 days
Copy link
Collaborator

Choose a reason for hiding this comment

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

one cycle is already bad. So 2100 bitcoin blocks?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure we can do that, but then a manager must be sure to send a keep-alive each cycle if there are no changes. The theory of the DMS was so that people can always get the underlying STX of their LiSTX back into the vault in case the managers go missing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Pool manager has to extend if nobody else does it for us


(define-map authorised-managers principal bool)
(map-set authorised-managers tx-sender true)

(define-data-var last-manager-action-height uint burn-block-height)

(define-read-only (is-dao-or-extension)
(ok (asserts! (or (is-eq tx-sender 'SM26NBC8SFHNW4P1Y4DFH27974P56WN86C92HPEHH.lisa-dao) (contract-call? 'SM26NBC8SFHNW4P1Y4DFH27974P56WN86C92HPEHH.lisa-dao is-extension contract-caller)) err-unauthorised))
Expand All @@ -17,14 +21,23 @@
(define-public (fund-strategy (amounts (list 20 uint)))
(begin
(asserts! (is-authorised-manager tx-sender) err-unauthorised)
(contract-call? 'SM26NBC8SFHNW4P1Y4DFH27974P56WN86C92HPEHH.lqstx-vault fund-strategy .public-pools-strategy-v2 (unwrap-panic (to-consensus-buff? amounts)))
(var-set last-manager-action-height burn-block-height)
(contract-call? 'SM26NBC8SFHNW4P1Y4DFH27974P56WN86C92HPEHH.lqstx-vault fund-strategy 'SM3KNVZS30WM7F89SXKVVFY4SN9RMPZZ9FX929N0V.public-pools-strategy-v2 (unwrap-panic (to-consensus-buff? amounts)))
)
)

(define-public (refund-strategy (selection (list 20 bool)))
(begin
(asserts! (is-authorised-manager tx-sender) err-unauthorised)
(contract-call? 'SM26NBC8SFHNW4P1Y4DFH27974P56WN86C92HPEHH.lqstx-vault refund-strategy .public-pools-strategy-v2 (unwrap-panic (to-consensus-buff? selection)))
(var-set last-manager-action-height burn-block-height)
(contract-call? 'SM26NBC8SFHNW4P1Y4DFH27974P56WN86C92HPEHH.lqstx-vault refund-strategy 'SM3KNVZS30WM7F89SXKVVFY4SN9RMPZZ9FX929N0V.public-pools-strategy-v2 (unwrap-panic (to-consensus-buff? selection)))
)
)

(define-public (keep-alive)
(begin
(asserts! (is-authorised-manager tx-sender) err-unauthorised)
(ok (var-set last-manager-action-height burn-block-height))
)
)

Expand All @@ -34,3 +47,23 @@
(ok (map-set authorised-managers who enabled))
)
)

;; Dead Man's switch

(define-read-only (dms-active)
Copy link
Collaborator

Choose a reason for hiding this comment

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

dms-active sounds like the dms was pressed. Better "dms-inactive"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps dms-available? I called it "active" because it indicates the DMS "can be pressed".

Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably, I don't understandthe term DMS not properly. It indicates that the manager was not active, correct?
Go with whatever you like.

(ok (asserts! (< (+ (var-get last-manager-action-height) dms-activation-period) burn-block-height) err-still-alive))
)

(define-public (dms-revoke-strategy)
(begin
(try! (dms-active))
(contract-call? 'SM26NBC8SFHNW4P1Y4DFH27974P56WN86C92HPEHH.lqstx-vault fund-strategy 'SM3KNVZS30WM7F89SXKVVFY4SN9RMPZZ9FX929N0V.public-pools-strategy-v2 (unwrap-panic (to-consensus-buff? (list u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0 u0))))
)
)

(define-public (dms-refund-strategy)
(begin
(try! (dms-active))
(contract-call? 'SM26NBC8SFHNW4P1Y4DFH27974P56WN86C92HPEHH.lqstx-vault refund-strategy 'SM3KNVZS30WM7F89SXKVVFY4SN9RMPZZ9FX929N0V.public-pools-strategy-v2 (unwrap-panic (to-consensus-buff? (list true true true true true true true true true true true true true true true true true true true true))))
)
)