-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
1,436 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
# 🤖💳🤖 Stacks M2M | ||
|
||
Smart contracts and tests for machine-payable transactions on Stacks. | ||
|
||
## Local Development | ||
|
||
1. Clone repository | ||
2. Install dependencies: `npm install` | ||
3. Run tests: `npm test` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
(define-constant ERR-NOT-AUTHORIZED (err u1000)) | ||
(define-fungible-token bridged-btc) | ||
(define-data-var contract-owner principal tx-sender) | ||
(define-map approved-contracts principal bool) | ||
(define-data-var token-name (string-ascii 32) "aBTC") | ||
(define-data-var token-symbol (string-ascii 10) "aBTC") | ||
(define-data-var token-uri (optional (string-utf8 256)) (some u"https://cdn.alexlab.co/metadata/token-abtc.json")) | ||
(define-data-var token-decimals uint u8) | ||
(define-read-only (get-contract-owner) | ||
(ok (var-get contract-owner))) | ||
(define-public (set-contract-owner (owner principal)) | ||
(begin | ||
(try! (check-is-owner)) | ||
(ok (var-set contract-owner owner)))) | ||
(define-private (check-is-owner) | ||
(ok (asserts! (is-eq tx-sender (var-get contract-owner)) ERR-NOT-AUTHORIZED))) | ||
(define-private (check-is-approved) | ||
(ok (asserts! (default-to false (map-get? approved-contracts tx-sender)) ERR-NOT-AUTHORIZED))) | ||
(define-public (set-name (new-name (string-ascii 32))) | ||
(begin | ||
(try! (check-is-owner)) | ||
(ok (var-set token-name new-name)))) | ||
(define-public (set-symbol (new-symbol (string-ascii 10))) | ||
(begin | ||
(try! (check-is-owner)) | ||
(ok (var-set token-symbol new-symbol)) | ||
) | ||
) | ||
(define-public (set-decimals (new-decimals uint)) | ||
(begin | ||
(try! (check-is-owner)) | ||
(ok (var-set token-decimals new-decimals)))) | ||
(define-public (set-token-uri (new-uri (optional (string-utf8 256)))) | ||
(begin | ||
(try! (check-is-owner)) | ||
(ok (var-set token-uri new-uri)))) | ||
(define-public (add-approved-contract (new-approved-contract principal)) | ||
(begin | ||
(try! (check-is-owner)) | ||
(ok (map-set approved-contracts new-approved-contract true)))) | ||
(define-public (set-approved-contract (owner principal) (approved bool)) | ||
(begin | ||
(try! (check-is-owner)) | ||
(ok (map-set approved-contracts owner approved)))) | ||
(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) | ||
(begin | ||
(asserts! (is-eq sender tx-sender) ERR-NOT-AUTHORIZED) | ||
(try! (ft-transfer? bridged-btc amount sender recipient)) | ||
(match memo to-print (print to-print) 0x) | ||
(ok true))) | ||
(define-read-only (get-name) | ||
(ok (var-get token-name))) | ||
(define-read-only (get-symbol) | ||
(ok (var-get token-symbol))) | ||
(define-read-only (get-decimals) | ||
(ok (var-get token-decimals))) | ||
(define-read-only (get-balance (who principal)) | ||
(ok (ft-get-balance bridged-btc who))) | ||
(define-read-only (get-total-supply) | ||
(ok (ft-get-supply bridged-btc))) | ||
(define-read-only (get-token-uri) | ||
(ok (var-get token-uri))) | ||
(define-constant ONE_8 u100000000) | ||
(define-public (mint (amount uint) (recipient principal)) | ||
(begin | ||
(asserts! (or (is-ok (check-is-approved)) (is-ok (check-is-owner))) ERR-NOT-AUTHORIZED) | ||
(ft-mint? bridged-btc amount recipient))) | ||
(define-public (burn (amount uint) (sender principal)) | ||
(begin | ||
(asserts! (or (is-ok (check-is-approved)) (is-ok (check-is-owner))) ERR-NOT-AUTHORIZED) | ||
(ft-burn? bridged-btc amount sender))) | ||
(define-private (pow-decimals) | ||
(pow u10 (unwrap-panic (get-decimals)))) | ||
(define-read-only (fixed-to-decimals (amount uint)) | ||
(/ (* amount (pow-decimals)) ONE_8)) | ||
(define-private (decimals-to-fixed (amount uint)) | ||
(/ (* amount ONE_8) (pow-decimals))) | ||
(define-read-only (get-total-supply-fixed) | ||
(ok (decimals-to-fixed (unwrap-panic (get-total-supply))))) | ||
(define-read-only (get-balance-fixed (account principal)) | ||
(ok (decimals-to-fixed (unwrap-panic (get-balance account))))) | ||
(define-public (transfer-fixed (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) | ||
(transfer (fixed-to-decimals amount) sender recipient memo)) | ||
(define-public (mint-fixed (amount uint) (recipient principal)) | ||
(mint (fixed-to-decimals amount) recipient)) | ||
(define-public (burn-fixed (amount uint) (sender principal)) | ||
(burn (fixed-to-decimals amount) sender)) | ||
(define-private (burn-fixed-many-iter (item {amount: uint, sender: principal})) | ||
(burn-fixed (get amount item) (get sender item))) | ||
(define-public (burn-fixed-many (senders (list 200 {amount: uint, sender: principal}))) | ||
(begin | ||
(asserts! (or (is-ok (check-is-approved)) (is-ok (check-is-owner))) ERR-NOT-AUTHORIZED) | ||
(ok (map burn-fixed-many-iter senders)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
(define-trait stacks-m2m-trait-v1 | ||
( | ||
(set-payment-address (principal principal) (response bool uint)) | ||
(add-resource ((string-utf8 50) (string-utf8 255) uint) (response bool uint)) | ||
(add-resource (uint (string-utf8 50) (string-utf8 255)) (response bool uint)) | ||
(delete-resource (uint) (response bool uint)) | ||
(delete-resource-by-name ((string-utf8 50)) (response bool uint)) | ||
(pay-invoice (uint (optional (buff 34))) (response bool uint)) | ||
(pay-invoice-by-resource-name ((string-utf8 50) (optional (buff 34))) (response bool uint)) | ||
;; (pay-invoice (uint (optional (buff 34))) (response bool uint)) | ||
;; (pay-invoice-by-resource-name ((string-utf8 50) (optional (buff 34))) (response bool uint)) | ||
) | ||
) |
Oops, something went wrong.