Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

[main][feat] Add new-vault to user-entry.clar #5

Open
wants to merge 5 commits into
base: main
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
39 changes: 37 additions & 2 deletions Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,33 @@ path = 'contracts/traits/oracle-trait.clar'
clarity_version = 2
epoch = 2.4

[contracts.vault-storage-trait]
path = 'contracts/traits/vault-storage-trait.clar'
clarity_version = 2
epoch = 2.4

[contracts.stablecoin-trait]
path = 'contracts/traits/stablecoin-trait.clar'
clarity_version = 2
epoch = 2.4

[contracts.simple-oracle]
path = 'contracts/oracles/simple-oracle.clar'
clarity_version = 2
epoch = 2.4

[contracts.position-storage]
path = 'contracts/storages/position-storage.clar'
[contracts.vault-storage]
path = 'contracts/storages/vault-storage.clar'
clarity_version = 2
epoch = 2.4

[contracts.config-storage]
path = 'contracts/storages/config-storage.clar'
clarity_version = 2
epoch = 2.4

[contracts.stablecoin]
path = 'contracts/stablecoin.clar'
clarity_version = 2
epoch = 2.4

Expand All @@ -43,6 +63,21 @@ path = 'contracts/mocks/sbtc.clar'
clarity_version = 2
epoch = 2.4

[contracts.fake-simple-oracle]
path = 'contracts/mocks/fake-simple-oracle.clar'
clarity_version = 2
epoch = 2.4

[contracts.fake-vault-storage]
path = 'contracts/mocks/fake-vault-storage.clar'
clarity_version = 2
epoch = 2.4

[contracts.fake-sbtc]
path = 'contracts/mocks/fake-sbtc.clar'
clarity_version = 2
epoch = 2.4

[repl.analysis.check_checker]
strict = false
trusted_sender = false
Expand Down
84 changes: 84 additions & 0 deletions contracts/mocks/fake-sbtc.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

;; title: sbtc
;; version:
;; summary:
;; description:

;; traits
;;
(impl-trait .ft-trait.ft-trait)

;; token definitions
;;
(define-fungible-token sbtc)

;; constants
;;
(define-constant ERR_FORBIDDEN (err u403))

;; data vars
;;
(define-data-var token-name (string-ascii 32) "sbtc")
(define-data-var token-symbol (string-ascii 8) "sBTC")
(define-data-var token-uri (optional (string-utf8 256)) none)
(define-data-var token-decimals uint u8)

;; data maps
;;

;; public functions
;;
(define-public (transfer
(amount uint)
(sender principal)
(recipient principal)
(memo (optional (buff 34)))
)
(begin
(asserts! (or (is-eq tx-sender sender) (is-eq contract-caller sender)) ERR_FORBIDDEN)
;; #[allow(unchecked_data)]
(ft-transfer? sbtc amount sender recipient)
)
)

(define-public (mint
(amount uint)
(recipient principal)
)
(begin
;; #[allow(unchecked_data)]
(ft-mint? sbtc amount recipient)
)
)

;; read only functions
;;
(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
(account principal)
)
(ok (ft-get-balance sbtc account))
)

(define-read-only (get-total-supply)
(ok (ft-get-supply sbtc))
)

(define-read-only (get-token-uri)
(ok (var-get token-uri))
)

;; private functions
;;

87 changes: 87 additions & 0 deletions contracts/mocks/fake-simple-oracle.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
;; title: simple_oracle
;; version: 0.0.1
;; summary: Simple oracle contract
;; description: A plain simple oracle contract that
;; allows whitelisted accounts to set asset prices and return asset prices

;; traits
;;
(impl-trait .oracle-trait.oracle-trait)
(impl-trait .ownable-trait.ownable-trait)
(use-trait ft .ft-trait.ft-trait)

;; token definitions
;;

;; constants
;;
(define-constant ERR_FORBIDDEN (err u403))
(define-constant ERR_NOT_FOUND (err u404))

;; data vars
;;
(define-data-var feeder principal tx-sender)
(define-data-var owner principal tx-sender)

;; data maps
;;
(define-map assets principal uint)

;; public functions
;;
(define-public (set-price
(asset <ft>)
(price uint)
)
(begin
(asserts! (is-eq (var-get feeder) tx-sender) ERR_FORBIDDEN)
;; #[allow(unchecked_data)]
(ok (map-set assets (contract-of asset) price))
)
)

;; read only functions
;;
(define-read-only (fetch-price
(asset <ft>)
)
(match (map-get? assets (contract-of asset))
ret (ok ret)
ERR_NOT_FOUND
)
)

(define-read-only (get-owner
)
(ok (var-get owner))
)

;; admin only functions
;;
(define-public (set-feeder
(new-feeder principal)
)
(begin
(try! (assert-is-owner))
;; #[allow(unchecked_data)]
(var-set feeder new-feeder)
(ok true)
)
)

(define-public (transfer-ownership
(new-owner principal)
)
(begin
(try! (assert-is-owner))
;; #[allow(unchecked_data)]
(var-set owner new-owner)
(ok true)
)
)

;; private functions
;;
(define-private (assert-is-owner)
(ok (asserts! (is-eq (var-get owner) tx-sender) ERR_FORBIDDEN))
)
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@

;; title: position-storge.clar
;; title: vault-storge.clar
;; version:
;; summary: position storage contract
;; summary: vault storage contract
;; description:

;; traits
;;
(impl-trait .ownable-trait.ownable-trait)
(impl-trait .vault-storage-trait.vault-storage-trait)

;; token definitions
;;

;; constants
;;
(define-constant ERR_INVALID_POSITION (err u401))
(define-constant ERR_INVALID_VAULT (err u401))
(define-constant ERR_FORBIDDEN (err u403))

;; data vars
Expand All @@ -29,7 +30,7 @@
;; 2: Closed by owner
;; 3: Closed by liquidation
;; 4: Closed by redemption
(define-map positions principal
(define-map vaults principal
{
debt: uint,
collateral: uint,
Expand All @@ -40,18 +41,18 @@

;; public functions
;;
(define-public (set-position-status
(define-public (set-vault-status
(borrower principal)
(status uint)
)
(let
(
(pos (unwrap! (get-position borrower) ERR_INVALID_POSITION))
(pos (unwrap! (get-vault borrower) ERR_INVALID_VAULT))
(data { debt: (get debt pos), collateral: (get collateral pos), status: status, arrayIndex: (get arrayIndex pos) })
)
(try! (assert-is-allowed-caller contract-caller))
;; #[allow(unchecked_data)]
(map-set positions borrower data)
(map-set vaults borrower data)
(ok true)
)
)
Expand All @@ -62,12 +63,12 @@
)
(let
(
(pos (unwrap! (get-position who) ERR_INVALID_POSITION))
(pos (unwrap! (get-vault who) ERR_INVALID_VAULT))
(data { debt: (get debt pos), collateral: (+ (get collateral pos) amount), status: (get status pos), arrayIndex: (get arrayIndex pos) })
)
(try! (assert-is-allowed-caller contract-caller))
;; #[allow(unchecked_data)]
(map-set positions who data)
(map-set vaults who data)
(ok true)
)
)
Expand All @@ -78,12 +79,12 @@
)
(let
(
(pos (unwrap! (get-position who) ERR_INVALID_POSITION))
(pos (unwrap! (get-vault who) ERR_INVALID_VAULT))
(data { debt: (+ (get debt pos) amount), collateral: (get collateral pos), status: (get status pos), arrayIndex: (get arrayIndex pos) })
)
(try! (assert-is-allowed-caller contract-caller))
;; #[allow(unchecked_data)]
(map-set positions who data)
(map-set vaults who data)
(ok true)
)
)
Expand All @@ -95,10 +96,10 @@
(ok (var-get owner))
)

(define-read-only (get-position
(define-read-only (get-vault
(borrower principal)
)
(ok (default-to { debt: u0, collateral: u0, status: u0, arrayIndex: u0 } (map-get? positions borrower))
(ok (default-to { debt: u0, collateral: u0, status: u0, arrayIndex: u0 } (map-get? vaults borrower))
)
)

Expand Down
Loading