This repository contains the Liquidity Book contracts, as well as tests and deploy scripts.
-
The LBPair is the contract that contains all the logic of the actual pair for swaps, adds, removals of liquidity and fee claiming. This contract should never be deployed directly, and the factory should always be used for that matter.
-
The LBToken is the contract that is used to calculate the shares of a user. The LBToken is a new token standard that is similar to ERC-1155, but without any callbacks (for safety reasons) and any functions or variables relating to ERC-721.
-
The LBFactory is the contract used to deploy the different pairs and acts as a registry for all the pairs already created. There are also privileged functions such as setting the parameters of the fees, the flashloan fee, setting the pair implementation, set if a pair should be ignored by the quoter and add new presets. Unless the BipsConfig
isOpenistrue, only the owner of the factory can create pairs. -
The LBRouter is the main contract that user will interact with as it adds security checks. Most users shouldn't interact directly with the pair.
-
The LBQuoter is a contract that is used to return the best route of all those given. This should be used before a swap to get the best return on a swap.
For more information, go to the documentation and the whitepaper.
Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
Foundry consists of:
- Forge: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- Cast: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- Anvil: Local Ethereum node, akin to Ganache, Hardhat Network.
- Chisel: Fast, utilitarian, and verbose solidity REPL.
Foundry documentation can be found in the Foundry Book.
Open your terminal and type in the following command:
curl -L https://foundry.paradigm.xyz | bashThis will download foundryup. Then install Foundry by running:
foundryupTo update foundry after installation, simply run foundryup again, and it will update to the latest Foundry release.
You can also revert to a specific version of Foundry with foundryup -v $VERSION.
If you use Windows, you need to build from source to get Foundry.
Download and run rustup-init from rustup.rs. It will start the installation in a console.
After this, run the following to build Foundry from source:
cargo install --git https://github.com/foundry-rs/foundry foundry-cli anvil --bins --lockedTo update from source, run the same command again.
To install dependencies, run the following to install dependencies:
forge installforge buildTo run all tests:
forge testRun specific tests:
forge test --match-test testSwap
forge test --match-contract LBPairTestRun tests with verbose output:
forge test -vvvforge fmtforge snapshotStart local Ethereum node:
anvilforge script script/deploy-core.s.sol --rpc-url <your_rpc_url> --broadcastInteract with contracts:
cast call <address> <signature> [args] --rpc-url <rpc_url>
cast send <address> <signature> [args] --rpc-url <rpc_url> --private-key <key>forge --help
anvil --help
cast --helpCreate a .env file with:
# BSC Testnet ็ง้ฅ
PRIVATE_KEY=0xYourPrivateKeyHere
# BSCScan API Key๏ผ็จไบ้ช่ฏๅ็บฆ๏ผhttps://etherscan.io/apidashboard
ETHERSCAN_API_KEY=YourBSCScanApiKeyHere
BSC_RPC_MAINNET_URL=https://bsc-dataseed.bnbchain.org
BSC_RPC_TESTNET_URL=https://data-seed-prebsc-1-s1.bnbchain.org:8545
Latest test run: 261 tests passed, 65 tests failed
Most failures are in edge cases and fuzzing tests related to:
- Oracle helper boundary conditions
- Math library overflow/underflow edge cases
- SafeCast boundary validations
- Parameter validation edge cases
Core functionality tests are passing successfully.