API Reference
Complete contract interface documentation for the Lux Standard Library
Complete contract interface documentation for the Lux Standard Library.
| Contract | Description | Import |
|---|
| LUX | Native platform token | @luxfi/contracts/tokens/LUX.sol |
| LUXD | Dollar stablecoin | @luxfi/contracts/tokens/LUXD.sol |
| AI | AI compute mining token | @luxfi/contracts/tokens/AI.sol |
| LRC20 | Base ERC20 implementation | @luxfi/contracts/tokens/LRC20.sol |
| LRC20B | Bridgeable ERC20 | @luxfi/contracts/tokens/LRC20B.sol |
| LRC721B | Bridgeable ERC721 | @luxfi/contracts/tokens/LRC721B.sol |
| Contract | Description | Import |
|---|
| AlchemistV2 | Self-repaying loans vault | @luxfi/contracts/synths/AlchemistV2.sol |
| TransmuterV2 | 1:1 synth redemption | @luxfi/contracts/synths/TransmuterV2.sol |
| Vault | Perps liquidity vault | @luxfi/contracts/perps/core/Vault.sol |
| Router | Position management | @luxfi/contracts/perps/core/Router.sol |
| LLP | Liquidity provider token | @luxfi/contracts/perps/tokens/LLP.sol |
| Contract | Description | Import |
|---|
| AMMV2Factory | Uniswap V2 factory | @luxfi/contracts/amm/AMMV2Factory.sol |
| AMMV2Pair | V2 liquidity pair | @luxfi/contracts/amm/AMMV2Pair.sol |
| AMMV3Factory | Uniswap V3 factory | @luxfi/contracts/amm/AMMV3Factory.sol |
| AMMV3Pool | V3 concentrated liquidity | @luxfi/contracts/amm/AMMV3Pool.sol |
| SwapRouter | Optimized swap routing | @luxfi/contracts/amm/SwapRouter.sol |
| WLUX | Wrapped LUX | @luxfi/contracts/tokens/WLUX.sol |
| Contract | Description | Import |
|---|
| Governor | OpenZeppelin Governor | @luxfi/contracts/governance/Governor.sol |
| Timelock | TimelockController | @luxfi/contracts/governance/Timelock.sol |
| vLUX | Vote-escrowed LUX | @luxfi/contracts/governance/vLUX.sol |
| DAO | Complete DAO contract | @luxfi/contracts/governance/DAO.sol |
| Contract | Description | Import |
|---|
| Teleport | Token teleportation | @luxfi/contracts/bridge/Teleport.sol |
| Bridge | Core bridge logic | @luxfi/contracts/bridge/Bridge.sol |
| Warp | BLS messaging | @luxfi/contracts/bridge/interfaces/IWarpMessenger.sol |
| Contract | Description | Import |
|---|
| Safe | Multi-sig wallet | @luxfi/contracts/safe/Safe.sol |
| SafeFactory | Safe deployment | @luxfi/contracts/safe/SafeFactory.sol |
| LamportBase | Post-quantum signatures | @luxfi/contracts/crypto/lamport/LamportBase.sol |
Standard ERC20 token interface used throughout the library.
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
Extended interface for bridge-compatible tokens.
interface IERC20B is IERC20 {
function mint(address to, uint256 amount) external;
function burn(address from, uint256 amount) external;
function hasRole(bytes32 role, address account) external view returns (bool);
function grantRole(bytes32 role, address account) external;
function revokeRole(bytes32 role, address account) external;
// Role constants
function ADMIN_ROLE() external view returns (bytes32);
}
Self-repaying loans interface (synths protocol).
interface IAlchemistV2 {
// Deposits
function deposit(address yieldToken, uint256 amount, address recipient) external returns (uint256);
function depositUnderlying(address yieldToken, uint256 amount, address recipient, uint256 minOut) external returns (uint256);
// Minting & Burning
function mint(uint256 amount, address recipient) external;
function burn(uint256 amount, address recipient) external returns (uint256);
// Withdrawals
function withdraw(address yieldToken, uint256 shares, address recipient) external returns (uint256);
function withdrawUnderlying(address yieldToken, uint256 shares, address recipient, uint256 minOut) external returns (uint256);
// Liquidation
function liquidate(address owner, uint256 shares, uint256 minOut) external returns (uint256);
// Views
function accounts(address owner) external view returns (int256 debt, address[] memory depositedTokens);
function mintAllowance(address owner, address spender) external view returns (uint256);
function getMintLimitPerBlock() external view returns (uint256);
function getYieldTokensPerShare(address yieldToken) external view returns (uint256);
}
Central vault interface for perpetual trading.
interface IVault {
// Positions
function increasePosition(address account, address collateralToken, address indexToken, uint256 sizeDelta, bool isLong) external;
function decreasePosition(address account, address collateralToken, address indexToken, uint256 collateralDelta, uint256 sizeDelta, bool isLong, address receiver) external returns (uint256);
function liquidatePosition(address account, address collateralToken, address indexToken, bool isLong, address feeReceiver) external;
// Swaps
function swap(address tokenIn, address tokenOut, address receiver) external returns (uint256);
// Views
function getMaxPrice(address token) external view returns (uint256);
function getMinPrice(address token) external view returns (uint256);
function getPosition(address account, address collateralToken, address indexToken, bool isLong) external view returns (uint256, uint256, uint256, uint256, uint256, int256, uint256);
function getPositionLeverage(address account, address collateralToken, address indexToken, bool isLong) external view returns (uint256);
function poolAmounts(address token) external view returns (uint256);
function reservedAmounts(address token) external view returns (uint256);
}
npm install @luxfi/contracts
import { LuxClient, Tokens, DeFi } from '@luxfi/contracts';
import { ethers } from 'ethers';
// Initialize client
const client = new LuxClient({
chainId: 96369,
provider: new ethers.JsonRpcProvider('https://api.lux.network/rpc'),
});
// Token operations
const lux = client.tokens.lux();
const balance = await lux.balanceOf(address);
// DeFi operations
const alchemist = client.defi.alchemist();
await alchemist.deposit(yieldToken, amount, recipient);
// Perps trading
const perps = client.defi.perps();
await perps.openPosition({
indexToken: 'ETH',
collateral: parseEther('1'),
leverage: 10,
isLong: true,
});
| Module | Description |
|---|
client.tokens | Token interactions (LUX, LUXD, AI, LRC20) |
client.defi.alchemist() | Self-repaying loans |
client.defi.perps() | Perpetual trading |
client.defi.lending() | Lending pools |
client.amm | AMM pool interactions |
client.bridge | Cross-chain operations |
client.governance | DAO and voting |
client.safe | Multi-sig wallets |
| Contract | Address |
|---|
| LUX | 0x... |
| LUXD | 0x... |
| AI | 0x... |
| WLUX | 0x... |
| SwapRouter | 0x... |
| AlchemistV2 | 0x... |
| Vault | 0x... |
| Contract | Address |
|---|
| LUX | 0x... |
| LUXD | 0x... |
| AI | 0x... |
| WLUX | 0x... |
| SwapRouter | 0x... |
| AlchemistV2 | 0x... |
| Vault | 0x... |
Contract addresses will be published after mainnet launch. Check GitHub for the latest deployment addresses.
| Error | Code | Description |
|---|
InsufficientBalance | 0x01 | Balance too low for operation |
InsufficientAllowance | 0x02 | Approval needed |
Unauthorized | 0x03 | Caller lacks permission |
InvalidAmount | 0x04 | Amount is zero or invalid |
Paused | 0x05 | Contract is paused |
Blacklisted | 0x06 | Address is blacklisted |
| Error | Code | Description |
|---|
Undercollateralized | 0x10 | Below minimum collateral ratio |
ExceedsDebtCeiling | 0x11 | Global debt limit reached |
SlippageExceeded | 0x12 | Output below minimum |
PositionNotFound | 0x13 | Position doesn't exist |
MaxLeverageExceeded | 0x14 | Leverage too high |
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
event BridgeMint(address indexed to, uint256 value);
event BridgeBurn(address indexed from, uint256 value);
// Synths
event Deposit(address indexed sender, address indexed yieldToken, uint256 amount, address recipient);
event Withdraw(address indexed sender, address indexed yieldToken, uint256 shares, address recipient);
event Mint(address indexed sender, uint256 amount, address recipient);
event Burn(address indexed sender, uint256 amount, address recipient);
event Liquidate(address indexed sender, address indexed owner, uint256 shares);
// Perps
event IncreasePosition(bytes32 key, address account, address collateralToken, address indexToken, uint256 collateralDelta, uint256 sizeDelta, bool isLong, uint256 price, uint256 fee);
event DecreasePosition(bytes32 key, address account, address collateralToken, address indexToken, uint256 collateralDelta, uint256 sizeDelta, bool isLong, uint256 price, uint256 fee);
event LiquidatePosition(bytes32 key, address account, address collateralToken, address indexToken, bool isLong, uint256 size, uint256 collateral, uint256 reserveAmount, int256 realisedPnl, uint256 markPrice);