Skip to content

Commit 4919f97

Browse files
committed
fix: update bank account contract
Removes update terms in favor of individual functions, clearer on proposals, updates read-only functions to link to each other, uses burn block height, and an extra check withdrawal gt deployed height.
1 parent c8f42a2 commit 4919f97

File tree

2 files changed

+32
-78
lines changed

2 files changed

+32
-78
lines changed

contracts/dao/extensions/aibtcdev-bank-account.clar

Lines changed: 21 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
;; traits
66
;;
77
(impl-trait .aibtcdev-dao-traits-v1.extension)
8-
(impl-trait .aibtcdev-dao-traits-v1.bank-acccount)
8+
(impl-trait .aibtcdev-dao-traits-v1.bank-account)
99

1010
;; constants
1111
;;
1212
(define-constant SELF (as-contract tx-sender))
13+
(define-constant DEPLOYED_AT burn-block-height)
1314
(define-constant ERR_INVALID (err u1000))
1415
(define-constant ERR_UNAUTHORIZED (err u1001))
1516
(define-constant ERR_TOO_SOON (err u1002))
@@ -58,76 +59,11 @@
5859
(define-public (override-last-withdrawal-block (block uint))
5960
(begin
6061
(try! (is-dao-or-extension))
61-
(asserts! (> block u0) ERR_INVALID)
62+
(asserts! (> block DEPLOYED_AT) ERR_INVALID)
6263
(ok (var-set lastWithdrawalBlock block))
6364
)
6465
)
6566

66-
(define-public (update-terms
67-
(accountHolder (optional principal))
68-
(withdrawalPeriod (optional uint))
69-
(withdrawalAmount (optional uint))
70-
(lastWithdrawalBlock (optional uint))
71-
(opcode (optional (buff 16))))
72-
73-
(begin
74-
;; Check authorization
75-
(try! (is-dao-or-extension))
76-
77-
;; Update account holder if provided
78-
(match accountHolder holder
79-
(begin
80-
(asserts! (not (is-eq (var-get accountHolder) holder)) ERR_INVALID)
81-
(var-set accountHolder holder)
82-
)
83-
true
84-
)
85-
86-
;; Update withdrawal period if provided
87-
(match withdrawalPeriod period
88-
(begin
89-
(asserts! (> period u0) ERR_INVALID)
90-
(var-set withdrawalPeriod period)
91-
)
92-
true
93-
)
94-
95-
;; Update withdrawal amount if provided
96-
(match withdrawalAmount amount
97-
(begin
98-
(asserts! (> amount u0) ERR_INVALID)
99-
(var-set withdrawalAmount amount)
100-
)
101-
true
102-
)
103-
104-
;; Update last withdrawal block if provided
105-
(match lastWithdrawalBlock block
106-
(begin
107-
(asserts! (> block u0) ERR_INVALID)
108-
(var-set lastWithdrawalBlock block)
109-
)
110-
true
111-
)
112-
113-
;; Print settings update event
114-
(print {
115-
notification: "terms-updated",
116-
payload: {
117-
accountHolder: (var-get accountHolder),
118-
withdrawalPeriod: (var-get withdrawalPeriod),
119-
withdrawalAmount: (var-get withdrawalAmount),
120-
lastWithdrawalBlock: (var-get lastWithdrawalBlock),
121-
opcode: opcode,
122-
caller: contract-caller,
123-
sender: tx-sender
124-
}
125-
})
126-
127-
(ok true)
128-
)
129-
)
130-
13167
(define-public (deposit-stx (amount uint))
13268
(begin
13369
(asserts! (> amount u0) ERR_INVALID_AMOUNT)
@@ -148,9 +84,9 @@
14884
;; verify user is enabled in the map
14985
(try! (is-account-holder))
15086
;; verify user is not withdrawing too soon
151-
(asserts! (>= block-height (+ (var-get lastWithdrawalBlock) (var-get withdrawalPeriod))) ERR_TOO_SOON)
87+
(asserts! (>= burn-block-height (+ (var-get lastWithdrawalBlock) (var-get withdrawalPeriod))) ERR_TOO_SOON)
15288
;; update last withdrawal block
153-
(var-set lastWithdrawalBlock block-height)
89+
(var-set lastWithdrawalBlock burn-block-height)
15490
;; print notification and transfer STX
15591
(print {
15692
notification: "withdraw-stx",
@@ -166,6 +102,10 @@
166102

167103
;; read only functions
168104
;;
105+
(define-read-only (get-deployed-block)
106+
DEPLOYED_AT
107+
)
108+
169109
(define-read-only (get-account-balance)
170110
(stx-get-balance SELF)
171111
)
@@ -174,6 +114,10 @@
174114
(var-get accountHolder)
175115
)
176116

117+
(define-read-only (get-last-withdrawal-block)
118+
(var-get lastWithdrawalBlock)
119+
)
120+
177121
(define-read-only (get-withdrawal-period)
178122
(var-get withdrawalPeriod)
179123
)
@@ -182,16 +126,15 @@
182126
(var-get withdrawalAmount)
183127
)
184128

185-
(define-read-only (get-last-withdrawal-block)
186-
(var-get lastWithdrawalBlock)
187-
)
188-
189-
(define-read-only (get-terms)
129+
(define-read-only (get-account-terms)
190130
{
191-
accountHolder: (var-get accountHolder),
192-
lastWithdrawalBlock: (var-get lastWithdrawalBlock),
193-
withdrawalAmount: (var-get withdrawalAmount),
194-
withdrawalPeriod: (var-get withdrawalPeriod),
131+
accountBalance: (get-account-balance),
132+
accountHolder: (get-account-holder),
133+
contractName: SELF,
134+
deployedAt: (get-deployed-block),
135+
lastWithdrawalBlock: (get-last-withdrawal-block),
136+
withdrawalAmount: (get-withdrawal-amount),
137+
withdrawalPeriod: (get-withdrawal-period),
195138
}
196139
)
197140

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(use-trait proposal-trait .aibtcdev-dao-traits-v1.proposal)
2+
(use-trait extension-trait .aibtcdev-dao-traits-v1.extension)
3+
4+
(define-trait aibtc-base-dao (
5+
;; Execute a governance proposal
6+
(execute (<proposal-trait> principal) (response bool uint))
7+
;; Enable or disable an extension contract
8+
(set-extension (principal bool) (response bool uint))
9+
;; Request extension callback
10+
(request-extension-callback (<extension-trait> (buff 34)) (response bool uint))
11+
))

0 commit comments

Comments
 (0)