Bunni v2 is a next-gen decentralized exchange with shapeshifting liquidity, the next breakthrough in AMM design after Uniswap v3's concentrated liquidity.
To learn more, see:
To install with Foundry:
forge install timeless-fi/bunni-v2
This project uses Foundry as the development framework.
Note: This project only compiles using Solidity 0.8.25
(and not 0.8.26
), but Uniswap's v4-core repo only compiles using Solidity 0.8.26. To develop locally, change the Solidity version of lib/v4-core/src/PoolManager.sol
to 0.8.25
.
forge install
forge build
forge test
Bunni uses Medusa and fuzz-utils for fuzzing.
Before fuzzing, BunniSwapMath
should be temporarily modified to use internal
instead of external
and to use memory
instead of calldata
for the computeSwap
function. This is because Medusa doesn't support external libraries.
To start fuzzing, run:
medusa fuzz
To generate Foundry tests from the failed fuzzing runs, run:
fuzz-utils generate ./fuzz/FuzzEntry.sol -c FuzzEntry -cd medusa
To use Foundry to run the failed fuzzing runs, run:
forge test --mc FuzzEntry_Medusa_Test
Please create a .env
file before deployment. An example can be found in .env.example
.
The Create3 salts for the following contracts are required in the .env
file:
BunniSwapMath
RebalanceLogic
BunniHub
BunniHook
BunniZone
BunniQuoter
GeometricDistribution
DoubleGeometricDistribution
CarpetedGeometricDistribution
CarpetedDoubleGeometricDistribution
UniformDistribution
BuyTheDipGeometricDistribution
FOUNDRY_PROFILE=gas forge script script/DeployLibraries.s.sol -f [network]
FOUNDRY_PROFILE=gas forge script script/DeployLDFs.s.sol -f [network]
forge script script/DeployCore.s.sol -f [network] --libraries src/lib/BunniSwapMath.sol:BunniSwapMath:[swapMathLibAddress] --libraries src/lib/RebalanceLogic.sol:RebalanceLogic:[rebalanceLibAddress]
forge script script/DeployBunniQuoter.s.sol -f [network] --libraries src/lib/BunniSwapMath.sol:BunniSwapMath:[swapMathLibAddress] --libraries src/lib/RebalanceLogic.sol:RebalanceLogic:[rebalanceLibAddress] --libraries src/lib/BunniHookLogic.sol:BunniHookLogic:[hookLogicLibAddress]
FOUNDRY_PROFILE=gas forge script script/DeployLibraries.s.sol -f [network] --verify --broadcast --slow
FOUNDRY_PROFILE=gas forge script script/DeployLDFs.s.sol -f [network] --verify --broadcast --slow
forge script script/DeployCore.s.sol -f [network] --verify --broadcast --slow --libraries src/lib/BunniSwapMath.sol:BunniSwapMath:[swapMathLibAddress] --libraries src/lib/RebalanceLogic.sol:RebalanceLogic:[rebalanceLibAddress]
forge script script/DeployBunniQuoter.s.sol -f [network] --verify --broadcast --slow --libraries src/lib/BunniSwapMath.sol:BunniSwapMath:[swapMathLibAddress] --libraries src/lib/RebalanceLogic.sol:RebalanceLogic:[rebalanceLibAddress] --libraries src/lib/BunniHookLogic.sol:BunniHookLogic:[hookLogicLibAddress]