-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add trait import and trait implementation contracts
This commit adds the following to the example project: - `ft-transfer-many`: A contract that imports a trait and references it in a function parameter. - `rendezvous-token`: A contract that implements the referenced trait. Additionally, it includes an invariant and a property test for the ft-transfer-many contract to demonstrate the random selection of trait implementations in action.
- Loading branch information
1 parent
0868451
commit 33432a1
Showing
6 changed files
with
119 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
(use-trait ft-trait 'SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.sip-010-trait-ft-standard.sip-010-trait) | ||
|
||
(define-public (transfer-many | ||
(transfers-list | ||
(list 5 {token: <ft-trait>, recipient: principal, amount: uint}) | ||
) | ||
) | ||
(ok (map transfer transfers-list)) | ||
) | ||
|
||
(define-private (transfer | ||
(one-transfer {token: <ft-trait>, recipient: principal, amount: uint}) | ||
) | ||
(let | ||
( | ||
(ft (get token one-transfer)) | ||
(recipient (get recipient one-transfer)) | ||
(amount (get amount one-transfer)) | ||
) | ||
(contract-call? ft transfer amount tx-sender recipient none)) | ||
) |
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,47 @@ | ||
;; Invariants | ||
|
||
(define-read-only (invariant-trait (address principal)) | ||
(let | ||
( | ||
(total-supply | ||
(unwrap-panic (contract-call? .rendezvous-token get-total-supply))) | ||
(user-balance | ||
(unwrap-panic | ||
(contract-call? | ||
.rendezvous-token | ||
get-balance | ||
address | ||
) | ||
) | ||
) | ||
) | ||
(<= user-balance total-supply) | ||
) | ||
) | ||
|
||
;; Properties | ||
|
||
(define-public (test-transfer | ||
(token <ft-trait>) (recipient principal) (amount uint) | ||
) | ||
(let | ||
( | ||
(sender-balance-before | ||
(unwrap-panic (contract-call? token get-balance tx-sender))) | ||
(transfer-result | ||
(transfer {token: token, recipient: recipient, amount: amount})) | ||
(sender-balance-after | ||
(unwrap-panic (contract-call? token get-balance tx-sender))) | ||
) | ||
(match transfer-result | ||
result | ||
(ok | ||
(is-eq | ||
sender-balance-after | ||
(- sender-balance-before amount) | ||
) | ||
) | ||
error (ok false) | ||
) | ||
) | ||
) |
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,41 @@ | ||
(impl-trait 'SP4SZE494VC2YC5JYG7AYFQ44F5Q4PYV7DVMDPBG.sip-010-trait-ft-standard.sip-010-trait) | ||
|
||
(define-fungible-token rendezvous) | ||
|
||
;; SIP-010 methods. | ||
|
||
(define-read-only (get-total-supply) | ||
(ok (ft-get-supply rendezvous)) | ||
) | ||
|
||
(define-read-only (get-name) | ||
(ok "Rendezvous Token") | ||
) | ||
|
||
(define-read-only (get-symbol) | ||
(ok "rendezvous") | ||
) | ||
|
||
(define-read-only (get-decimals) | ||
(ok u6) | ||
) | ||
|
||
(define-read-only (get-balance (account principal)) | ||
(ok (ft-get-balance rendezvous account)) | ||
) | ||
|
||
(define-read-only (get-token-uri) | ||
(ok (some u"")) | ||
) | ||
|
||
(define-public (transfer | ||
(amount uint) | ||
(sender principal) | ||
(recipient principal) | ||
(memo (optional (buff 34))) | ||
) | ||
(match (ft-transfer? rendezvous amount sender recipient) | ||
response (ok response) | ||
error (err error) | ||
) | ||
) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.