Taxr Smart Contract Architecture

This document provides a comprehensive overview of the Taxr smart contract architecture, detailing the design principles, contract relationships, and implementation details of the blockchain components that power the Taxr platform.

Architecture Overview

The Taxr smart contract architecture follows a modular design pattern with a central orchestration contract and specialized manager modules:

                                                      ┌──────────────────┐
                                                      │   External Apps  │
                                                      └────────┬─────────┘
                                                               │
                                 ┌─────────────────────────────┼─────────────────────────────┐
                                 │                             │                             │
                         ┌───────▼───────┐             ┌───────▼───────┐             ┌───────▼───────┐
                         │  Web3 Client   │             │  Payment Router │             │  Other Services │
                         └───────┬───────┘             └───────┬───────┘             └───────┬───────┘
                                 │                             │                             │
                                 └─────────────────────────────┼─────────────────────────────┘
                                                               │
                                                      ┌────────▼─────────┐
                                                      │                  │
                                                      │   TaxrMastr      │
                                                      │   (Core)         │
                                                      │                  │
                                                      └───┬───────┬──────┘
                                                          │       │
                    ┌──────────────────────┬──────────────┘       └───────────┬─────────────────────────┐
                    │                      │                                   │                         │
            ┌───────▼─────────┐    ┌───────▼─────────┐                 ┌──────▼──────────┐      ┌───────▼─────────┐
            │                 │    │                 │                 │                 │      │                 │
            │ JurisdictionMgr │    │   ClaimManager  │                 │ CommissionMgr   │      │  SheriffToken   │
            │                 │    │                 │                 │                 │      │                 │
            └─────────────────┘    └─────────────────┘                 └─────────────────┘      └─────────────────┘
                     │                     │                                   │                         │
                     │                     │                                   │                         │
            ┌────────▼─────────┐  ┌────────▼─────────┐                ┌────────▼─────────┐     ┌────────▼─────────┐
            │ Jurisdiction     │  │ TaxrBill &       │                │ Commission        │     │ ERC721 Sheriff   │
            │ Token (ERC1155)  │  │ Receipt NFTs     │                │ Calculations      │     │ Badges           │
            └──────────────────┘  └──────────────────┘                └──────────────────┘     └──────────────────┘
                

Core Contracts

TaxrMastr (Proxy Implementation)

The central orchestration contract that coordinates all system functionality, now implemented as a proxy pattern:

TaxrMastrStorage

The storage layout contract for the proxy implementation:

TaxrMastrBase

The foundation contract that TaxrMastr inherits from:

SheriffToken

ERC-721 implementation for Sheriff identity badges:

TaxrToken

ERC-20 implementation with dual-layer design and burn-to-govern mechanism:

PaymentRouter

Multi-currency payment processor:

Manager Modules

JurisdictionManager

Manages tax jurisdictions as ERC-1155 tokens:

ClaimManager

Handles tax bill claims and receipts:

CommissionManager

Manages commission structures and calculations:

Tax Bill Contracts

TaxrBill Base

Base contract for all tax bill types:

PropertyTaxrBill

Specialized implementation for property tax bills:

UpstartBill

Implementation for other types of government fees:

Type Libraries

Specialized libraries for type-safe identifier handling:

Library Purpose Location
BillID Unique tax bill identifiers /taxr-persistence/contracts/libraries/BillID.sol
ClaimID Tax claim identifiers /taxr-persistence/contracts/libraries/ClaimID.sol
JurisdictionID Tax jurisdiction identifiers /taxr-persistence/contracts/libraries/JurisdictionID.sol
SheriffTokenID Sheriff badge identifiers /taxr-persistence/contracts/libraries/SheriffTokenID.sol
DomainID System domain identifiers /taxr-persistence/contracts/libraries/DomainID.sol
TaxrType Type definitions and enums /taxr-persistence/contracts/libraries/TaxrType.sol
TypeComparisons Type-safe comparison utilities /taxr-persistence/contracts/libraries/TypeComparisons.sol

Interface Contracts

Interface definitions for contract interactions:

Interface Purpose Location
ITaxrMastr Core contract interface /taxr-persistence/contracts/interfaces/ITaxrMastr.sol
ISheriffToken Sheriff token interface /taxr-persistence/contracts/interfaces/ISheriffToken.sol
ITaxrMastrToken TAXR token interface /taxr-persistence/contracts/interfaces/ITaxrMastrToken.sol
IPaymentRouter Payment router interface /taxr-persistence/contracts/interfaces/IPaymentRouter.sol
IPriceSource Price feed interface /taxr-persistence/contracts/interfaces/IPriceSource.sol
ITaxMasterEventEmitter Event emission interface /taxr-persistence/contracts/interfaces/ITaxMasterEventEmitter.sol
ITaxMasterErrorEmitter Error handling interface /taxr-persistence/contracts/interfaces/ITaxMasterErrorEmitter.sol

Proxy Architecture

The TaxrMastr contract implements an ERC1967 proxy pattern to overcome Ethereum's 24KB contract size limitation while providing upgradeability:

                    ┌───────────────────┐
                    │                   │
                    │   TaxrMastrProxy  │◄───── User Interactions
                    │   (ERC1967)       │
                    │                   │
                    └─────────┬─────────┘
                              │
                              │ delegatecall
                              ▼
                    ┌───────────────────┐
                    │                   │
                    │ TaxrMastrConcrete │
                    │ (Implementation)  │
                    │                   │
                    └─────────┬─────────┘
                              │
                              │ inheritance
                              ▼
                    ┌───────────────────┐
                    │                   │
                    │   TaxrMastrFull   │
                    │                   │
                    └─────────┬─────────┘
                              │
                              │ inheritance
                              ▼
                    ┌───────────────────┐
                    │                   │
                    │ TaxrMastrModules  │
                    │                   │
                    └─────────┬─────────┘
                              │
                              │ inheritance
                              ▼
                    ┌───────────────────┐
                    │                   │
                    │   TaxrMastrImpl   │
                    │                   │
                    └─────────┬─────────┘
                              │
                              │ inheritance
                              ▼
                    ┌───────────────────┐
                    │                   │
                    │ TaxrMastrStorage  │
                    │                   │
                    └───────────────────┘
                

Proxy Components

Key Proxy Features

Business Flow Support

Commission-Based Authorization

Design Patterns

Modular Architecture

The Taxr smart contract system uses a modular architecture with the following benefits:

Type-Safe Identifiers

Custom type wrappers with the TypeComparisons library provide:

Interface Segregation

Interfaces are segregated by functionality:

Role-Based Access Control

The system implements comprehensive role-based access control:

Integration Points

Frontend Integration

The smart contracts integrate with the frontend through:

External Services

The system integrates with external services through:

Proxy Upgrade System

The proxy upgrade mechanism provides critical integration functionality:

Testing Framework

The smart contracts are thoroughly tested using:

Test files can be found in /taxr-persistence/test/ directory.

Development & Deployment

Development Tools

Deployment Scripts

The contracts can be deployed using:

Development Commands

Further Resources