Authorized Token
Overview
This project implements an authorized token system on Solana. The access-control program is based on the solana-security-token implementation from CoMakery/solana-security-token.
Features
- Secured token transfers
- Role-based access control
- Customizable transfer restrictions
- Merchant payment processing
- Transfer hook validation
Architecture
The system consists of three main Solana programs that work together:
- Access Control Program (
access_control) - Manages roles and permissions - Authorized Token Program (
authorized_token) - Handles token transfer validation via SPL Token 2022 transfer hooks - Payment System Program (
payment_system) - Processes merchant payments
How It Works
Authorized Token Flow
The Authorized Token system uses the SPL Token 2022 transfer hook feature to validate and control token transfers. Here's how it works:
-
Account Initialization:
- Merchants are initialized with
initialize_merchantinstruction - Authorized accounts are initialized with
initialize_authorized_accountinstruction - Both include status flags, spending limits, and permissions
- Merchants are initialized with
-
Transfer Hook Registration:
- Extra account meta lists are initialized for the token mint
- When transfers occur, these accounts are automatically included in the transaction
-
Transfer Validation:
- When a token transfer is attempted, the
execute_transfer_hookfunction is called - The hook validates that both source and destination accounts meet requirements:
- Checks the authorized account is active
- Verifies the merchant account status
- Enforces any spending limits or restrictions
- When a token transfer is attempted, the
Payment Processing
The Payment System program handles merchant transactions:
-
Purchase Flow:
- Client calls
purchasewith the amount to be transferred - Transaction includes merchant and authorized account details
- Uses
invoke_transfer_checkedto execute the token transfer - The transfer hook validates the transaction before it completes
- Client calls
-
Validation Process:
- Transaction must be signed by both merchant and authorized account
- Transfer hook validates account status and permissions
- Transfer only succeeds if all validations pass
Program Interaction Example
Based on the test flow, here's how the programs interact:
- Initialize merchant and authorized accounts with the Authorized Token program
- Fund the authorized account with tokens
- Create a purchase instruction from the Payment System program
- Add extra account metas for the token transfer hook
- Execute the transaction with signatures from both merchant and authorized account
- Token transfer succeeds if all validations pass in the transfer hook
Program Details
Access Control Program
The Access Control Program manages user roles and permissions within the token ecosystem:
-
Key Features:
- Role-based access control system
- Wallet freezing/thawing capabilities
- Administrative forced transfers between accounts
- Security token minting and burning
-
Main Functions:
initialize_access_control: Sets up the access control systeminitialize_wallet_role: Assigns roles to wallets (0-255)update_wallet_role: Changes a wallet's rolefreeze_wallet/thaw_wallet: Controls account usageforce_transfer_between: Administrative transfer between accountsmint_securities/burn_securities: Manages token supply
-
Security Model:
- Hierarchical permission structure
- Only authorized admins can modify roles
- Transaction approval based on role permissions
Authorized Token Program
The Authorized Token Program implements transfer validation logic using SPL Token 2022 transfer hooks:
-
Key Components:
AuthorizedAccount: Tracks user permissions, spending limits, and transaction historyMerchantAccount: Manages merchant permissions and transaction limits- Transfer hook validation logic
-
Account Statuses:
Active: Account can participate in transactionsPaused: Temporary suspensionSanctioned: Permanently blocked
-
Spending Controls:
- Daily and monthly purchase limits
- Maximum transaction amounts
- Tracked spending history with timestamp verification
-
Validation Checks:
- Account status verification
- Transaction amount validation
- Spending limit enforcement
- Merchant authorization
Payment System Program
The Payment System Program facilitates transactions between merchants and authorized accounts:
-
Main Operations:
purchase: Transfers tokens from customer to merchantrefund: Returns tokens from merchant to customer
-
Transaction Flow:
- Client initiates transaction with merchant
- Both parties sign the transaction
- Payment amount is validated against limits
- Token transfer executed with transfer hook validation
- Transaction succeeds only if all validations pass
-
Security Features:
- Multi-signature requirement
- Integration with Authorized Token validation
- Automated spending limit enforcement