Smart Contracts
The Oyl AMM protocol consists of several smart contracts built on the Alkanes runtime for Bitcoin. These contracts work together to provide automated market making functionality.
Contract Architecture
Factory Contract
The Factory contract is the central registry for all trading pairs. It:
- Creates new pool contracts for token pairs
- Maintains a registry of all existing pools
- Handles protocol-wide settings and fees
- Provides routing functionality for multi-hop swaps and additional safety checks
Pool Contracts
Each trading pair has its own Pool contract that:
- Holds reserves of both tokens in the pair
- Executes swaps using the constant product formula
- Mints and burns liquidity provider (LP) tokens
- Collects and distributes trading fees
Contract Addresses & Proxies
The Oyl AMM contracts are deployed on the Alkanes metaprotocol. Contract addresses are determined by the Alkanes runtime based on deployment parameters.
It is important to note that the contracts are deployed using a proxy pattern to allow for future upgrades. All transactions should be sent to the proxy addresses, not the underlying logic contract addresses.
Factory Proxy
The factory contract is deployed behind a standard upgradeable proxy. This means that the factory's logic can be upgraded without changing the contract address that users interact with.
Pool Beacon Proxy
The pool contracts are deployed using a beacon proxy pattern. This is a more gas-efficient way to deploy multiple contracts that share the same logic. A single "beacon" contract holds the address of the current pool logic contract. Each pool proxy contract simply asks the beacon for the address of the logic contract to delegate its calls to. This means that all pools can be upgraded simultaneously by simply updating the logic contract address in the beacon.
Security Features
Access Control
- Factory operations are protected by authentication mechanisms
- Pool operations validate caller permissions
- Critical functions include deadline checks
Mathematical Safety
- All calculations use safe arithmetic to prevent overflow
- Minimum liquidity requirements prevent division by zero
- Price impact limits protect against manipulation
Reentrancy Protection
- State changes occur before external calls
- Critical sections are protected against reentrancy attacks
- Token transfers are validated
Integration
Developers can integrate with Oyl AMM by:
- Calling Factory functions to find or create pools
- Interacting directly with Pool contracts for swaps
- Using Library functions for price calculations
- Building custom routing logic for complex trades
For detailed information about each contract, see the individual contract documentation pages.