# Smart Contracts Documentation

HyDRAULIC is built on EVM that enables intellectual property (IP) owners to tokenize their assets as non-fungible tokens (NFTs) and leverage them for financing through loans or sales. This platform integrates governance, compliance, valuation, and marketplace functionalities to create a secure, transparent, and efficient ecosystem for IP financing.

#### **Purpose of the Smart Contracts**

The smart contract suite is designed to achieve the following objectives:

* **Tokenization**: Convert IPs into NFTs that represent ownership and metadata.
* **Valuation**: Facilitate a decentralized valuation process involving lawyers and external data via Chainlink oracles.
* **Financing**: Allow IP owners to use their NFTs as collateral for loans or list them for sale in a marketplace.
* **Compliance**: Enforce legal and regulatory standards through role-based access control and blacklisting mechanisms.
* **Sustainability**: Provide upgradeability and emergency controls to ensure the platform's long-term viability.

Below we provide a detailed overview of each contract, its role within the platform, and its key functionalities.

***

### **Smart Contract Suite Overview**

The IP Financing Platform comprises the following core smart contracts:

1. **Admin.sol**: Manages governance, roles, fees, compliance, and emergency controls.
2. **ValuationOracle.sol**: Handles IP valuation using lawyer submissions and external data.
3. **IPIssuer.sol**: Oversees the issuance and reissuance of IP NFTs.
4. **IPNFT.sol**: Implements the ERC721 standard for IP NFTs.
5. **IPLoans.sol**: Facilitates loans using IP NFTs as collateral.
6. **IPSales.sol**: Manages the sale of IP NFTs via fixed prices or auctions.
7. **IPEscrow\.sol**: Secures NFTs during loans or sales.
8. **AttestationRegistry.sol**: Records legal attestations for auditability.
9. **FunctionsSource.sol**: Centralizes JavaScript source code for Chainlink Functions.
10. **ComplianceOracle.sol**: Performs compliance checks using external data.
11. **MarketDataOracle.sol**: Provides market data for loans and sales.

Each contract follows the UUPS (Universal Upgradeable Proxy Standard) pattern, ensuring modularity and future-proofing.

***

### **1. Admin.sol - Governance and Compliance**

#### **Purpose**

The Admin.sol contract acts as the governance and compliance hub, controlling access, fees, and emergency operations.

#### **Key Features**

* **Role Management**: Assigns roles like ISSUANCE\_MANAGER\_ROLE, COMPLIANCE\_MANAGER\_ROLE, and LAWYER\_ROLE for access control.
* **Fee Management**: Configures fees for tokenization, valuation, and marketplace transactions.
* **Stablecoin Whitelist**: Limits transactions to approved stablecoins.
* **Blacklisting**: Prevents blacklisted users from interacting with the platform.
* **Pausing**: Enables emergency pausing of platform operations.

#### **Key Functions**

* **updateFees**: Adjusts fee structures.
* **toggleBlacklist**: Adds or removes users from the blacklist.
* **updateStablecoinWhitelist**: Manages the stablecoin whitelist.
* **pause / unpause**: Activates or deactivates the emergency pause.

***

### **2. ValuationOracle.sol - Valuation Management**

#### **Purpose**

The ValuationOracle.sol contract manages the IP valuation process by integrating lawyer evaluations with external data from Chainlink Functions.

#### **Key Features**

* **Lawyer Assignment**: Compliance managers assign lawyers to assess IPs.
* **Valuation Submission**: Lawyers submit valuations recorded on-chain.
* **External Data**: Chainlink Functions fetch supplementary valuation data.
* **Valuation Struct**: Stores spot value, max loan, risk rating, and IP type.

#### **Key Functions**

* **beginValuation**: Initiates the valuation process.
* **assignLawyers**: Assigns lawyers to an IP.
* **submitValuation**: Records a lawyer’s valuation.
* **postValuation**: Finalizes valuation with Chainlink data.

***

### **3. IPIssuer.sol - Tokenization Logic**

#### **Purpose**

The IPIssuer.sol contract handles the issuance and reissuance of IP NFTs, ensuring only valued IPs are tokenized and ownership disputes can be resolved.

#### **Key Features**

* **NFT Issuance**: Mints IP NFTs post-valuation and fee payment.
* **NFT Reissuance**: Burns and reissues NFTs to correct ownership.
* **Fee Calculation**: Determines fees based on IP value and type.

#### **Key Functions**

* **issueIPNFT**: Mints a new IP NFT.
* **reissueIPNFT**: Reissues an NFT to the rightful owner.

***

### **4. IPNFT.sol - ERC721 for IP NFTs**

#### **Purpose**

The IPNFT.sol contract implements the ERC721 standard for IP NFTs, managing their lifecycle and metadata.

#### **Key Features**

* **Minting and Burning**: Restricted to authorized roles.
* **Metadata Storage**: Uses ERC721URIStorage for metadata.
* **Blacklist Enforcement**: Blocks transfers to blacklisted addresses.

#### **Key Functions**

* **mint**: Creates an IP NFT.
* **burn**: Destroys an IP NFT.

***

### **5. IPLoans.sol - Loan Marketplace**

#### **Purpose**

The IPLoans.sol contract enables users to secure loans using IP NFTs as collateral.

#### **Key Features**

* **Loan Creation**: Borrowers lock NFTs in escrow to create loan offers.
* **Loan Funding**: Lenders fund loans with stablecoins.
* **Repayment**: Borrowers repay with interest to reclaim NFTs.
* **Liquidation**: Compliance managers liquidate defaulted loans.

#### **Key Functions**

* **createLoanOffer**: Locks NFTs and creates a loan offer.
* **fundLoan**: Transfers funds to the borrower.
* **repayLoan**: Processes repayment and releases NFTs.
* **liquidateLoan**: Liquidates collateral for defaults.

***

### **6. IPSales.sol - Sales Marketplace**

#### **Purpose**

The IPSales.sol contract facilitates NFT sales through fixed prices or auctions.

#### **Key Features**

* **Listing**: Sellers list NFTs for sale or auction.
* **Bidding**: Buyers bid on auction listings.
* **Fulfillment**: Transfers NFTs and funds upon sale completion.

#### **Key Functions**

* **listNFT**: Lists an NFT for sale or auction.
* **placeBid**: Submits an auction bid.
* **fulfillSale**: Completes the sale or auction.

***

### **7. IPEscrow\.sol - Escrow for NFTs**

#### **Purpose**

The IPEscrow\.sol contract secures NFTs during loans or sales, releasing them only upon transaction completion.

#### **Key Features**

* **Locking**: Holds NFTs in escrow during transactions.
* **Releasing**: Transfers NFTs to the owner or buyer post-transaction.

#### **Key Functions**

* **lockNFT**: Locks an NFT in escrow.
* **releaseNFT**: Releases an NFT from escrow.

***

### **8. AttestationRegistry.sol - Legal Attestations**

#### **Purpose**

The AttestationRegistry.sol contract logs legal attestations for transparency and auditability.

#### **Key Features**

* **Attestation Storage**: Records attestations on-chain.
* **Retrieval**: Enables attestation verification.

#### **Key Functions**

* **attest**: Adds a new attestation.
* **getAttestation**: Retrieves an attestation.

***

### **9. FunctionsSource.sol - Centralized Oracle Source Code**

#### **Purpose**

The FunctionsSource.sol contract centralizes JavaScript code for Chainlink Functions, simplifying updates and reuse.

#### **Key Features**

* **Source Code Storage**: Stores JavaScript for oracle queries.
* **Reusability**: Supports multiple oracle contracts.

***

### **10. ComplianceOracle.sol - Compliance Checks**

#### **Purpose**

The ComplianceOracle.sol contract conducts compliance checks (e.g., KYC, AML) using Chainlink Functions.

#### **Key Features**

* **Compliance Queries**: Triggers external compliance checks.
* **Status Storage**: Records compliance results on-chain.

#### **Key Functions**

* **checkCompliance**: Initiates a compliance check.

***

### **11. MarketDataOracle.sol - Market Data**

#### **Purpose**

The MarketDataOracle.sol contract fetches market data (e.g., interest rates) for loans and sales.

#### **Key Features**

* **Data Fetching**: Retrieves data via Chainlink Functions.
* **Data Storage**: Stores data for use in other contracts.

#### **Key Functions**

* **fetchMarketData**: Triggers a market data query.

***

This smart contract suite powers HyDRAULIC, enabling secure and compliant tokenization and financing of intellectual properties. Designed for modularity and upgradeability, it supports a robust and adaptable ecosystem. For deployment, integration, or usage details, refer to individual contract sections or the platform’s developer guides.
