Technical Reference
Shibaswap v1 consists of several core smart contracts that work together to enable decentralized token swapping:- Factory Contract: Creates and manages trading pairs
- Pair Contract: Handles the actual trading logic and liquidity provision
- Pair ERC-20 Contract: Represents liquidity provider tokens
- Library Contract: Provides utility functions for calculations and price queries
- Router02 Contract: Offers user-friendly interface for all trading and liquidity operations
Shibaswap v1 is based on the Uniswap v2 protocol architecture, adapted specifically for the Shiba Inu ecosystem and Shibarium network.
Factory Contract
The Factory contract is responsible for creating and managing all trading pairs on Shibaswap v1. It serves as the central registry for all pair contracts.Key Functions
Creating a New Pair
When you want to create a new trading pair, the Factory contract:- Validates that the token addresses are different
- Sorts the token addresses to ensure consistent pair addresses
- Checks if the pair already exists
- Deploys a new Pair contract with the specified tokens
- Registers the new pair in its internal mapping
Pair Address Calculation
The Factory uses a deterministic address calculation to ensure the same pair address is generated for the same token combination:Pair Contract
The Pair contract handles the core trading logic, including:- Token swaps
- Liquidity provision and removal
- Price calculations
- Fee collection
Core State Variables
Swap Function
The main swap function handles token exchanges:Liquidity Functions
The Pair contract provides functions for adding and removing liquidity:Pair ERC-20 Contract
Each trading pair has an associated ERC-20 token that represents liquidity provider (LP) positions. These tokens are minted when liquidity is added and burned when liquidity is removed.Token Properties
Minting and Burning
LP tokens are minted when liquidity is added and burned when liquidity is removed:ERC-20 Functions
The Pair contract implements standard ERC-20 functions:LP tokens represent your share of the liquidity pool. The number of LP tokens you receive when adding liquidity is proportional to your contribution relative to the existing liquidity.
Library Contract
The Library contract provides utility functions for calculating amounts, reserves, and pair addresses. It’s used by the Router and other periphery contracts to perform calculations without making external calls.Key Functions
Usage Examples
The Library is primarily used for:- Price calculations before executing swaps
- Multi-hop routing to find optimal swap paths
- Liquidity calculations for adding/removing liquidity
- Reserve queries without direct pair contract calls
The Library contract contains pure and view functions only, making it gas-efficient for calculations and safe to use without state changes.
Router02 Contract
The Router02 contract is the main interface for users to interact with Shibaswap v1. It provides user-friendly functions for all trading and liquidity operations, handling the complexity of direct contract interactions.Key Properties
Liquidity Functions
Adding Liquidity
Removing Liquidity
Swap Functions
Exact Input Swaps
Exact Output Swaps
Fee-On-Transfer Support
Router02 includes special functions for tokens with transfer fees:Calculation Functions
The Router02 also provides the same calculation functions as the Library:Contract Interactions
The smart contracts work together in the following flow:- Factory creates new Pair contracts for token combinations
- Pair contracts handle swaps and liquidity operations
- Pair ERC-20 tokens represent LP positions and can be traded or staked
- Library provides calculation utilities for amounts and reserves
- Router02 provides user-friendly interface for all operations
- All contracts interact through the Router for user-friendly operations

Security Considerations
When interacting with Shibaswap v1 smart contracts:- Always verify contract addresses from official sources
- Use the Router contract for swaps and liquidity operations
- Be aware of slippage and set appropriate limits
- Consider gas costs when performing multiple operations
- Verify token approvals before transactions