Skip to content

Commit

Permalink
fix: account for V1 and V2 in total supply and balances
Browse files Browse the repository at this point in the history
  • Loading branch information
whoabuddy committed Apr 2, 2024
1 parent c8a06dd commit f5fbf13
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions contracts/extensions/ccd012-redemption-mia.clar
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

;; CONSTANTS

;; error codes
(define-constant ERR_UNAUTHORIZED (err u12000))
(define-constant ERR_PANIC (err u12001))
(define-constant ERR_GETTING_TOTAL_SUPPLY (err u12002))
Expand All @@ -18,6 +19,9 @@
(define-constant ERR_BALANCE_NOT_FOUND (err u12006))
(define-constant ERR_NOTHING_TO_REDEEM (err u12007))

;; helpers
(define-constant MICRO_CITYCOINS (pow u10 u6)) ;; 6 decimal places

;; DATA VARS

(define-data-var redemptionsEnabled bool false)
Expand Down Expand Up @@ -51,13 +55,15 @@
(let
(
;; MAINNET: TODO
(miaTotalSupply (unwrap! (contract-call? .miamicoin-token-v2 get-total-supply) ERR_PANIC))
(miaTotalSupplyV1 (unwrap! (contract-call? .miamicoin-token get-total-supply) ERR_PANIC))
(miaTotalSupplyV2 (unwrap! (contract-call? .miamicoin-token-v2 get-total-supply) ERR_PANIC))
(miaTotalSupply (+ (* miaTotalSupplyV1 MICRO_CITYCOINS) miaTotalSupplyV2))
(miaRedemptionBalance (as-contract (stx-get-balance tx-sender)))
)
;; check if sender is DAO or extension
(try! (is-dao-or-extension))
;; check that total supply is greater than 0
(asserts! (> miaTotalSupply u0) ERR_GETTING_TOTAL_SUPPLY)
(asserts! (and (> miaTotalSupplyV1 u0) (> miaTotalSupplyV2 u0)) ERR_GETTING_TOTAL_SUPPLY)
;; check that redemption balance is greater than 0
(asserts! (> miaRedemptionBalance u0) ERR_GETTING_REDEMPTION_BALANCE)
;; check if redemptions are already enabled
Expand All @@ -79,9 +85,10 @@
(let
(
(userAddress tx-sender)
(balanceV1 (unwrap! (contract-call? .miamicoin-token get-balance userAddress) ERR_BALANCE_NOT_FOUND))
(balanceV2 (unwrap! (contract-call? .miamicoin-token-v2 get-balance userAddress) ERR_BALANCE_NOT_FOUND))
(redemptionAmount (unwrap! (get-redemption-amount balanceV2) ERR_NOTHING_TO_REDEEM))
(redemptionClaims (default-to u0 (get-redemption-claims (some userAddress))))
(redemptionClaims (default-to u0 (get-redemption-claims userAddress)))
)
;; check if redemptions are enabled
(asserts! (var-get redemptionsEnabled) ERR_NOT_ENABLED)
Expand Down Expand Up @@ -137,11 +144,8 @@
)
)

(define-read-only (get-redemption-claims (address (optional principal)))
(if (is-some address)
(map-get? RedemptionClaims (unwrap! address none))
(define-read-only (get-redemption-claims (address principal))
(map-get? RedemptionClaims tx-sender)
)
)

;; TODO: read-only that returns all post conditions in one call
Expand Down

0 comments on commit f5fbf13

Please sign in to comment.