Skip to content

oyin-moh/Institutional-Custody-Integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Institutional Custody Integration Smart Contract

A robust Clarity smart contract designed for managing institutional asset custody with multi-signature approval workflows, role-based access control, and comprehensive asset tracking.

Overview

This smart contract provides institutional-grade custody services on the Stacks blockchain, enabling secure management of digital assets with approval mechanisms, manager hierarchies, and detailed audit trails.

Features

  • Custody Account Management: Create and manage institutional custody accounts with three tiers (standard, premium, enterprise)
  • Asset Deposit/Withdrawal: Secure deposit and withdrawal mechanisms with balance validation
  • Multi-Approval Workflow: Pending withdrawal system requiring administrative approval
  • Manager Role Management: Support for up to 5 approved managers per institution
  • Asset Ledger Tracking: Complete transaction history with timestamps
  • Owner Authorization: Contract owner controls critical operations
  • Real-time Balance Tracking: Total custodied assets monitoring

Contract Architecture

Constants

``` CONTRACT-OWNER: Initial deployer of the contract ERR-UNAUTHORIZED (u401): Access denied ERR-INVALID-AMOUNT (u400): Amount must be > 0 ERR-INSUFFICIENT-BALANCE (u402): Insufficient funds ERR-ACCOUNT-EXISTS (u403): Account already initialized ERR-ACCOUNT-NOT-FOUND (u404): Institution account not found ERR-INVALID-CUSTODY-TYPE (u405): Invalid custody tier ```

Data Variables

  • total-custodied-assets: Sum of all assets under custody
  • active-institutions: Count of active custody accounts
  • withdrawal-counter: Incremental withdrawal ID tracker

Data Maps

custody-accounts ``` Key: { institution: principal } Value: { balance: uint, approved-managers: list of up to 5 principals, created-at: block height, custody-type: "standard" | "premium" | "enterprise", is-active: bool } ```

asset-ledger ``` Key: { institution: principal, asset-id: uint } Value: { amount: uint, timestamp: uint } ```

pending-withdrawals ``` Key: { id: uint } Value: { institution: principal, amount: uint, requester: principal, created-at: block height, approved-count: uint, is-executed: bool } ```

Public Functions

open-custody-account(institution, custody-type)

Initializes a new custody account for an institution.

Parameters:

  • institution: Principal address of the institution
  • custody-type: Type of custody ("standard", "premium", or "enterprise")

Authorization: Contract owner only

Returns: ok true or error code


deposit-assets(institution, amount)

Deposits STX or assets into an institutional custody account.

Parameters:

  • institution: Target institution principal
  • amount: Amount to deposit (must be > 0)

Authorization: Public (any caller)

Returns: ok true or error code


request-withdrawal(institution, amount)

Requests withdrawal of assets from custody with multi-approval workflow.

Parameters:

  • institution: Institution to withdraw from
  • amount: Amount to withdraw (must be > 0 and ≤ balance)

Authorization: Institution or contract owner

Returns: ok withdrawal-id or error code


approve-withdrawal(withdrawal-id)

Approves a pending withdrawal request.

Parameters:

  • withdrawal-id: ID of the withdrawal to approve

Authorization: Contract owner only

Returns: ok true or error code


add-manager(institution, manager)

Adds an approved manager to an institution's custody account.

Parameters:

  • institution: Target institution
  • manager: Principal of new manager

Authorization: Institution or contract owner

Returns: ok true or error code

Read-Only Functions

get-custody-account(institution)

Retrieves complete custody account details.

Returns: Optional custody account data structure


get-withdrawal-status(withdrawal-id)

Retrieves pending withdrawal status.

Returns: Optional withdrawal data structure


get-total-custody-balance()

Retrieves total assets under custody across all institutions.

Returns: uint (total balance)


get-active-institutions-count()

Retrieves number of active institutional accounts.

Returns: uint (count of institutions)

Usage Example

;; Deploy contract
;; ...

;; Initialize custody for institution
(contract-call? .institutional-custody open-custody-account 'SP2X1Y8RFEJB6KPV0DY2CX3M5N4K6J9L1A2B3C4D5 "premium")

;; Deposit assets
(contract-call? .institutional-custody deposit-assets 'SP2X1Y8RFEJB6KPV0DY2CX3M5N4K6J9L1A2B3C4D5 u1000000)

;; Request withdrawal
(contract-call? .institutional-custody request-withdrawal 'SP2X1Y8RFEJB6KPV0DY2CX3M5N4K6J9L1A2B3C4D5 u500000)

;; Approve withdrawal
(contract-call? .institutional-custody approve-withdrawal u0)

;; Add manager
(contract-call? .institutional-custody add-manager 'SP2X1Y8RFEJB6KPV0DY2CX3M5N4K6J9L1A2B3C4D5 'SP3A1B2C3D4E5F6G7H8I9J0K1L2M3N4O5P6Q7R8S9)

;; Query balance
(contract-call? .institutional-custody get-custody-account 'SP2X1Y8RFEJB6KPV0DY2CX3M5N4K6J9L1A2B3C4D5)

About

The Institutional Custody Integration smart contract is a role-based asset management system designed for financial institutions to securely hold, manage, and control digital assets on behalf of clients. It implements a robust multi-level approval workflow with institutional-grade security controls and comprehensive audit trails.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors