Lux Standard

API Reference

Complete contract interface documentation for the Lux Standard Library

API Reference

Complete contract interface documentation for the Lux Standard Library.

Core Contract Interfaces

Tokens

ContractDescriptionImport
LUXNative platform token@luxfi/contracts/tokens/LUX.sol
LUXDDollar stablecoin@luxfi/contracts/tokens/LUXD.sol
AIAI compute mining token@luxfi/contracts/tokens/AI.sol
LRC20Base ERC20 implementation@luxfi/contracts/tokens/LRC20.sol
LRC20BBridgeable ERC20@luxfi/contracts/tokens/LRC20B.sol
LRC721BBridgeable ERC721@luxfi/contracts/tokens/LRC721B.sol

DeFi Protocols

ContractDescriptionImport
AlchemistV2Self-repaying loans vault@luxfi/contracts/synths/AlchemistV2.sol
TransmuterV21:1 synth redemption@luxfi/contracts/synths/TransmuterV2.sol
VaultPerps liquidity vault@luxfi/contracts/perps/core/Vault.sol
RouterPosition management@luxfi/contracts/perps/core/Router.sol
LLPLiquidity provider token@luxfi/contracts/perps/tokens/LLP.sol

AMM & DEX

ContractDescriptionImport
AMMV2FactoryUniswap V2 factory@luxfi/contracts/amm/AMMV2Factory.sol
AMMV2PairV2 liquidity pair@luxfi/contracts/amm/AMMV2Pair.sol
AMMV3FactoryUniswap V3 factory@luxfi/contracts/amm/AMMV3Factory.sol
AMMV3PoolV3 concentrated liquidity@luxfi/contracts/amm/AMMV3Pool.sol
SwapRouterOptimized swap routing@luxfi/contracts/amm/SwapRouter.sol
WLUXWrapped LUX@luxfi/contracts/tokens/WLUX.sol

Governance

ContractDescriptionImport
GovernorOpenZeppelin Governor@luxfi/contracts/governance/Governor.sol
TimelockTimelockController@luxfi/contracts/governance/Timelock.sol
vLUXVote-escrowed LUX@luxfi/contracts/governance/vLUX.sol
DAOComplete DAO contract@luxfi/contracts/governance/DAO.sol

Bridge & Cross-Chain

ContractDescriptionImport
TeleportToken teleportation@luxfi/contracts/bridge/Teleport.sol
BridgeCore bridge logic@luxfi/contracts/bridge/Bridge.sol
WarpBLS messaging@luxfi/contracts/bridge/interfaces/IWarpMessenger.sol

Security & Multi-Sig

ContractDescriptionImport
SafeMulti-sig wallet@luxfi/contracts/safe/Safe.sol
SafeFactorySafe deployment@luxfi/contracts/safe/SafeFactory.sol
LamportBasePost-quantum signatures@luxfi/contracts/crypto/lamport/LamportBase.sol

Common Interfaces

IERC20

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);
}

IERC20B (Bridgeable)

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);
}

IAlchemistV2

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);
}

IVault (Perps)

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);
}

TypeScript SDK

Installation

npm install @luxfi/contracts

Quick Start

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,
});

Available Modules

ModuleDescription
client.tokensToken interactions (LUX, LUXD, AI, LRC20)
client.defi.alchemist()Self-repaying loans
client.defi.perps()Perpetual trading
client.defi.lending()Lending pools
client.ammAMM pool interactions
client.bridgeCross-chain operations
client.governanceDAO and voting
client.safeMulti-sig wallets

Contract Addresses

Mainnet (Chain ID: 96369)

ContractAddress
LUX0x...
LUXD0x...
AI0x...
WLUX0x...
SwapRouter0x...
AlchemistV20x...
Vault0x...

Testnet (Chain ID: 96368)

ContractAddress
LUX0x...
LUXD0x...
AI0x...
WLUX0x...
SwapRouter0x...
AlchemistV20x...
Vault0x...

Contract addresses will be published after mainnet launch. Check GitHub for the latest deployment addresses.


Error Codes

Common Errors

ErrorCodeDescription
InsufficientBalance0x01Balance too low for operation
InsufficientAllowance0x02Approval needed
Unauthorized0x03Caller lacks permission
InvalidAmount0x04Amount is zero or invalid
Paused0x05Contract is paused
Blacklisted0x06Address is blacklisted

DeFi Errors

ErrorCodeDescription
Undercollateralized0x10Below minimum collateral ratio
ExceedsDebtCeiling0x11Global debt limit reached
SlippageExceeded0x12Output below minimum
PositionNotFound0x13Position doesn't exist
MaxLeverageExceeded0x14Leverage too high

Events

Token Events

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);

DeFi Events

// 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);

On this page