# Contract Reference

Solidity interfaces for the LiquidCore Router and pool contracts.

Use the **Router** for execution. Direct pool calls are optional when you already know the pool address.

## Router

**LiquidCore Router:** `0x625aC1D165c776121A52ff158e76e3544B4a0b8B`

### Discovery functions

```solidity
function getPools() external pure returns (address[] memory pools)
function getPoolForPair(address tokenA, address tokenB) public view returns (address)
```

### Execution functions

```solidity
function swap(
    address tokenIn,
    address tokenOut,
    uint256 amountIn,
    uint256 minAmountOut
) external returns (uint256 amountOut)
```

```solidity
function swap(
    address tokenIn,
    address tokenOut,
    uint256 amountIn,
    uint256 minAmountOut,
    bytes32 refCode
) external returns (uint256 amountOut)
```

`refCode` is checked against an on-chain allowlist (`RefCodeRegistry`). Invalid codes do not accrue referral allocation and do not block the swap.

### Quote functions

```solidity
function estimateSwap(
    address tokenIn,
    address tokenOut,
    uint256 amountIn
) external view returns (uint256 amountOut)

function estimateSwapBatch(
    address tokenIn,
    address tokenOut,
    uint256[] calldata amountsIn
) external view returns (uint256[] memory amountsOut)

function getReserves(address tokenA, address tokenB)
    external view returns (uint256 reserve0, uint256 reserve1)
```

`estimateSwapBatch` is used by the [REST API quote endpoint](https://docs.liqd.ag/api-endpoints#get-quote) for CSV `amountIn` inputs. `getReserves` reverts with `NoPoolForPair` if no pool exists.

### Referral functions

```solidity
function getRefCodeOwner(address tokenA, address tokenB, bytes32 refCode)
    external view returns (address)

function getRefClaimable(address tokenA, address tokenB, bytes32 refCode)
    external view returns (uint256 amount0, uint256 amount1)

function getRefCodes(address tokenA, address tokenB)
    external view returns (bytes32[] memory refCodes, address[] memory owners)

function claimRefFees(address tokenA, address tokenB, bytes32 refCode)
    external returns (uint256 amount0, uint256 amount1)

function distributeRefFees() external
```

See [Referrals](https://docs.liqd.ag/liquidcore-integration/referrals) for usage details.

### Router errors

```solidity
error NoPoolForPair();
error TransferFailed();
```

***

## Direct pool interface

Pool addresses:

* `0xA7478A5ff7cB27A8008D6D90785db10223bc6087` (USDT0/WHYPE)
* `0xD3994A6CF46cA91536376f89aCDadf92eD289a9F` (USDC/WHYPE)
* `0x305e5B1a81879Aa0538338306Cb9430A547E1eEa` (USDH/WHYPE)

```solidity
function getTokens() external view returns (address token0, address token1)
function getReserves() external view returns (uint256 reserve0, uint256 reserve1)
function swap(address tokenIn, address tokenOut, uint256 amountIn, uint256 minAmountOut) external returns (uint256 amountOut)
function swap(address tokenIn, address tokenOut, uint256 amountIn, uint256 minAmountOut, bytes32 refCode) external returns (uint256 amountOut)
function estimateSwap(address tokenIn, address tokenOut, uint256 amountIn) external view returns (uint256 amountOut)
function estimateSwapBatch(address tokenIn, address tokenOut, uint256[] calldata amountsIn) external view returns (uint256[] memory amountsOut)
function getRefCodeOwner(bytes32 refCode) external view returns (address)
function getRefClaimable(bytes32 refCode) external view returns (uint256 amount0, uint256 amount1)
function getRefCodes() external view returns (bytes32[] memory refCodes, address[] memory owners)
function claimRefFeesFor(bytes32 refCode, address recipient) external returns (uint256 amount0, uint256 amount1)
function distributeRefFees() external
```

### Common direct-pool errors

```solidity
error InvalidToken();
error ZeroAmount();
error SlippageExceeded();
error InsufficientReserve();
error TransferFailed();
error PriceDeviationTooLarge();
```

Referral usage details are documented in [Referrals](https://docs.liqd.ag/liquidcore-integration/referrals).
