### Deploy Full Solidly Protocol Source: https://context7.com/velodrome-finance/solidly/llms.txt Use this script to deploy all core Solidly contracts in the correct order. Ensure all dependencies and addresses are correctly configured before execution. ```javascript const { ethers } = require("hardhat"); async function main() { // 1. Deploy core infrastructure const token = await ( await ethers.getContractFactory("BaseV1") ).deploy(); const gauges = await ( await ethers.getContractFactory("BaseV1GaugeFactory") ).deploy(); const bribes = await ( await ethers.getContractFactory("BaseV1BribeFactory") ).deploy(); const core = await ( await ethers.getContractFactory("BaseV1Factory") ).deploy(); const WFTM_ADDRESS = "0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83"; const router = await ( await ethers.getContractFactory("BaseV1Router01") ).deploy(core.address, WFTM_ADDRESS); // 2. Deploy ve + ve_dist const ve = await ( await ethers.getContractFactory("contracts/ve.sol:ve") ).deploy(token.address); const ve_dist = await ( await ethers.getContractFactory("contracts/ve_dist.sol:ve_dist") ).deploy(ve.address); // 3. Deploy voter + minter const voter = await ( await ethers.getContractFactory("BaseV1Voter") ).deploy(ve.address, core.address, gauges.address, bribes.address); const minter = await ( await ethers.getContractFactory("BaseV1Minter") ).deploy(voter.address, ve.address, ve_dist.address); // 4. Wire contracts together await token.setMinter(minter.address); await ve.setVoter(voter.address); await ve_dist.setDepositor(minter.address); // 5. Whitelist initial tokens in the voter const whitelistedTokens = [WFTM_ADDRESS /*, ... other tokens */]; await voter.initialize(whitelistedTokens, minter.address); // 6. Mint initial veNFT distribution to partner protocols const claimants = [ "0x5bDacBaE440A2F30af96147DE964CC97FE283305" /*, ...*/ ]; const amounts = [ ethers.BigNumber.from("800000000000000000000000") /*, ...*/ ]; const totalMax = ethers.utils.parseEther("100000000"); // 100M SOLID await minter.initialize(claimants, amounts, totalMax); // After this call, initializer is set to address(0) — minter is live console.log("Factory:", core.address); console.log("Router: ", router.address); console.log("veNFT: ", ve.address); console.log("Voter: ", voter.address); console.log("Minter: ", minter.address); } main().then(() => process.exit(0)).catch(console.error); ``` -------------------------------- ### Execute Token Swaps with BaseV1Router01 Source: https://context7.com/velodrome-finance/solidly/llms.txt Use `swapExactTokensForTokens` for single or multi-hop swaps. Ensure tokens are approved to the router and specify minimum output amounts to mitigate slippage. `getAmountOut` can be used to preview the best single-hop swap. ```Solidity BaseV1Router01 router = BaseV1Router01(0xa38cd27185a464914D3046f0AB9d43356B34829D); // --- Single-hop: MIM → USDC via stable pool --- BaseV1Router01.route[] memory routes1 = new BaseV1Router01.route[](1); routes1[0] = BaseV1Router01.route({ from: 0x82f0b8b456c1a451378467398982d4834b6829c1, // MIM to: 0x04068DA6C83AFCFA0e13ba15A6696662335D5b75, // USDC stable: true }); IERC20(routes1[0].from).approve(address(router), 500e18); uint[] memory amounts1 = router.swapExactTokensForTokens( 500e18, // amountIn: 500 MIM 498e6, // amountOutMin: 498 USDC (0.4% slippage) routes1, msg.sender, block.timestamp + 300 ); // amounts1[0] = 500e18 (MIM in), amounts1[1] = actual USDC out ``` ```Solidity // --- Multi-hop: USDC → MIM (stable) → SOLID (volatile) --- BaseV1Router01.route[] memory routes2 = new BaseV1Router01.route[](2); routes2[0] = BaseV1Router01.route({ from: address(USDC), to: address(MIM), stable: true }); routes2[1] = BaseV1Router01.route({ from: address(MIM), to: address(SOLID), stable: false }); uint[] memory preview = router.getAmountsOut(100e6, routes2); // 100 USDC IERC20(address(USDC)).approve(address(router), 100e6); router.swapExactTokensForTokens( 100e6, preview[2] * 99 / 100, routes2, msg.sender, block.timestamp + 300 ); ``` ```Solidity // --- Query best single-hop output --- (uint bestOut, bool isStable) = router.getAmountOut(1000e18, address(MIM), address(USDC)); // isStable = true → route through sAMM // isStable = false → route through vAMM ``` -------------------------------- ### Manage LP Positions and Fees with BaseV1Pair Source: https://context7.com/velodrome-finance/solidly/llms.txt Interact with `BaseV1Pair` for low-level liquidity provisioning and fee claiming. `mint` and `burn` are typically called via the router. `claimFees` allows LP holders to retrieve their share of trading fees. ```Solidity // Low-level mint — called by the router after transferring tokens to the pair // (Router handles token transfers; direct usage shown for illustration) BaseV1Pair pair = BaseV1Pair(pairAddress); // Transfer tokens to the pair contract directly, then call mint IERC20(pair.token0()).transfer(pairAddress, amount0); IERC20(pair.token1()).transfer(pairAddress, amount1); uint liquidity = pair.mint(recipient); // mints LP tokens to `recipient` ``` ```Solidity // Low-level burn — transfer LP tokens back, then call burn IERC20(pairAddress).transfer(pairAddress, liquidity); (uint out0, uint out1) = pair.burn(recipient); // returns underlying tokens ``` ```Solidity // Claim accumulated trading fees as an LP holder (uint claimed0, uint claimed1) = pair.claimFees(); // claimed0 = amount of token0 fees received // claimed1 = amount of token1 fees received ``` ```Solidity // View pending claimable fees before claiming uint pending0 = pair.claimable0(msg.sender); uint pending1 = pair.claimable1(msg.sender); ``` ```Solidity // Force sync reserves to current balances (e.g. after direct token transfer) pair.sync(); ``` ```Solidity // Skim excess tokens above reserves to an address pair.skim(recipient); ``` -------------------------------- ### BaseV1Router Swap Exact Tokens For Tokens Source: https://github.com/velodrome-finance/solidly/blob/master/readme.md Executes a token-to-token swap with exact input amount and minimum output amount. This function routes swaps through specified pairs. Ensure the deadline is respected. ```Solidity function swapExactTokensForTokens( uint amountIn, uint amountOutMin, route[] calldata routes, address to, uint deadline ) external ensure(deadline) returns (uint[] memory amounts) ``` -------------------------------- ### BaseV1Router01 - getAmountsOut Source: https://context7.com/velodrome-finance/solidly/llms.txt Queries the expected output amounts for a given input amount and a series of swap routes. ```APIDOC ## BaseV1Router01 - getAmountsOut ### Description Queries the expected output amounts for a given input amount and a series of swap routes. This is useful for previewing the results of a multi-hop swap before execution. ### Method `getAmountsOut` ### Parameters - `amountIn` (uint) - The amount of input tokens. - `routes` (BaseV1Router01.route[]) - An array of route structs specifying the swap path. ### Request Example ```solidity BaseV1Router01.route[] memory routes = new BaseV1Router01.route[](2); routes[0] = BaseV1Router01.route({ from: address(USDC), to: address(MIM), stable: true }); routes[1] = BaseV1Router01.route({ from: address(MIM), to: address(SOLID), stable: false }); uint[] memory preview = router.getAmountsOut(100e6, routes); // 100 USDC ``` ### Response - `amounts` (uint[]) - An array containing the input amount and the expected output amount for each hop in the route. ``` -------------------------------- ### BaseV1Factory Create Pair Source: https://github.com/velodrome-finance/solidly/blob/master/readme.md Creates a new BaseV1Pair (pool) for two specified tokens. This function is permissionless and uses an immutable pattern to reduce gas costs. ```Solidity function createPair(address tokenA, address tokenB, bool stable) external returns (address pair) ``` -------------------------------- ### Create Liquidity Pools with BaseV1Factory Source: https://context7.com/velodrome-finance/solidly/llms.txt Use BaseV1Factory to deploy new stable or volatile AMM pairs. The factory contract is already deployed on mainnet. The `createPair` function uses CREATE2 for deterministic pool addresses. ```Solidity // Deploy the factory (already deployed on mainnet at 0x3fAaB499b519fdC5819e3D7ed0C26111904cbc28) BaseV1Factory factory = BaseV1Factory(0x3fAaB499b519fdC5819e3D7ed0C26111904cbc28); address MIM = 0x82f0b8b456c1a451378467398982d4834b6829c1; address USDC = 0x04068DA6C83AFCFA0e13ba15A6696662335D5b75; // Create a stable pool for two correlated stablecoins address stablePool = factory.createPair(MIM, USDC, true); // stablePool name => "StableV1 AMM - MIM/USDC" // stablePool symbol => "sAMM-MIM/USDC" // Create a volatile pool for two uncorrelated assets address wFTM = 0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83; address SPELL = 0x468003B688943977e6130F4F68F23AAD939a1040; address volatilePool = factory.createPair(wFTM, SPELL, false); // volatilePool name => "VolatileV1 AMM - FTM/SPELL" // volatilePool symbol => "vAMM-FTM/SPELL" // Look up an existing pair address existingPair = factory.getPair(MIM, USDC, true); // returns stablePool address // Pause all swaps across the protocol (pauser role only) factory.setPause(true); // Total number of pairs deployed uint256 count = factory.allPairsLength(); ``` -------------------------------- ### BaseV1Pair swap Source: https://github.com/velodrome-finance/solidly/blob/master/readme.md Executes a swap within a BaseV1Pair. ```APIDOC ## BaseV1Pair swap ### Description Executes a swap within a BaseV1Pair. This function should not be referenced directly and should be interacted with via the BaseV1Router. ### Function Signature ```solidity function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external ``` ### Parameters #### Path Parameters - **amount0Out** (uint) - The amount of token0 to output. - **amount1Out** (uint) - The amount of token1 to output. - **to** (address) - The address to which the swapped tokens will be sent. - **data** (bytes calldata) - Additional data for the swap. ``` -------------------------------- ### Query TWAP and Pool Data with BaseV1Pair Source: https://context7.com/velodrome-finance/solidly/llms.txt Use `BaseV1Pair` contract methods to query time-weighted average prices (TWAP) and pool metadata. `current` provides the latest TWAP, `quote` averages over multiple windows, and `prices` returns raw per-window data. `getAmountOut` provides an instant spot price. ```Solidity BaseV1Pair pair = BaseV1Pair(0x...); // e.g. sAMM-MIM/USDC address MIM = pair.token0(); address USDC = pair.token1(); // Current TWAP: how much USDC does 1000 MIM fetch? uint twapOut = pair.current(MIM, 1000e18); // Returns USDC amount based on the latest 30-min TWAP window ``` ```Solidity // 4-point average (120 minutes of history) uint avgOut = pair.quote(MIM, 1000e18, 4); ``` ```Solidity // Raw array of 8 per-window prices uint[] memory history = pair.prices(MIM, 1000e18, 8); for (uint i = 0; i < history.length; i++) { // history[i] = USDC output for 1000 MIM in window i } ``` ```Solidity // Cumulative prices for external TWAP construction (uint res0Cum, uint res1Cum, uint ts) = pair.currentCumulativePrices(); ``` ```Solidity // Instant quote (spot, ignores TWAP) uint spotOut = pair.getAmountOut(1000e18, MIM); ``` ```Solidity // Pool metadata (uint dec0, uint dec1, uint r0, uint r1, bool stable, address t0, address t1) = pair.metadata(); ``` -------------------------------- ### Manage ve(3,3) Emission Schedule Source: https://context7.com/velodrome-finance/solidly/llms.txt The BaseV1Minter contract codifies the ve(3,3) emission schedule, allowing updates once per week. It distributes a portion of each mint to ve_dist for veNFT holders to compensate for inflation dilution. Ensure to check the weekly emission and circulating supply for accurate calculations. ```solidity BaseV1Minter minter = BaseV1Minter(0xC4209c19b183e72A037b2D1Fb11fbe522054A90D); // Trigger the weekly emission (callable by anyone once per 7-day period) uint activePeriod = minter.update_period(); // If a new period has started: // 1. Calculates weekly emission // 2. Mints growth tokens → ve_dist (anti-dilution for veNFT holders) // 3. Approves and notifies voter with the weekly gauge allocation // 4. Emits: Mint(sender, weekly, circulating_supply, circulating_emission) // Read current weekly emission amount uint thisWeek = minter.weekly(); // Calculate expected next emission uint nextEmission = minter.weekly_emission(); // = max(calculate_emission(), circulating_emission()) // Circulating supply = total token supply - locked ve supply uint circulating = minter.circulating_supply(); // Anti-dilution growth to distribute to veNFT holders this week uint growth = minter.calculate_growth(minter.weekly()); // Target emission based on circulating ratio uint targetEmission = minter.calculate_emission(); // Tail (minimum) emission = 0.2% of circulating supply per week uint tailEmission = minter.circulating_emission(); ``` -------------------------------- ### BaseV1Router addLiquidity Source: https://github.com/velodrome-finance/solidly/blob/master/readme.md Adds liquidity to a pair. ```APIDOC ## BaseV1Router addLiquidity ### Description Adds liquidity to a pair. This is the primary function for providing liquidity to Solidly pools. ### Function Signature ```solidity function addLiquidity( address tokenA, address tokenB, bool stable, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external ensure(deadline) returns (uint amountA, uint amountB, uint liquidity) ``` ### Parameters #### Path Parameters - **tokenA** (address) - The address of the first token. - **tokenB** (address) - The address of the second token. - **stable** (bool) - Whether the pair is a stable swap pair. - **amountADesired** (uint) - The desired amount of tokenA to deposit. - **amountBDesired** (uint) - The desired amount of tokenB to deposit. - **amountAMin** (uint) - The minimum amount of tokenA to deposit. - **amountBMin** (uint) - The minimum amount of tokenB to deposit. - **to** (address) - The address to which liquidity tokens will be sent. - **deadline** (uint) - The transaction deadline. ``` -------------------------------- ### BaseV1Factory - Create Liquidity Pool Source: https://context7.com/velodrome-finance/solidly/llms.txt The `BaseV1Factory` contract allows permissionless creation of new liquidity pools. It supports both stable and volatile pairs using different AMM curves. ```APIDOC ## BaseV1Factory - Create Liquidity Pool ### Description Deploys a new `BaseV1Pair` contract using CREATE2 for a deterministic address. Supports stable and volatile pairs. ### Method `createPair(address tokenA, address tokenB, bool stable)` ### Parameters - **tokenA** (address) - The address of the first token. - **tokenB** (address) - The address of the second token. - **stable** (bool) - `true` for a StableV1 pool, `false` for a VolatileV1 pool. ### Returns - **address** - The address of the newly deployed pair contract. ### Example ```solidity BaseV1Factory factory = BaseV1Factory(0x3fAaB499b519fdC5819e3D7ed0C26111904cbc28); address MIM = 0x82f0b8b456c1a451378467398982d4834b6829c1; address USDC = 0x04068DA6C83AFCFA0e13ba15A6696662335D5b75; // Create a stable pool address stablePool = factory.createPair(MIM, USDC, true); // Create a volatile pool address wFTM = 0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83; address SPELL = 0x468003B688943977e6130F4F68F23aad939a1040; address volatilePool = factory.createPair(wFTM, SPELL, false); ``` ## BaseV1Factory - Get Pair ### Description Looks up the address of an existing pair contract. ### Method `getPair(address tokenA, address tokenB, bool stable)` ### Parameters - **tokenA** (address) - The address of the first token. - **tokenB** (address) - The address of the second token. - **stable** (bool) - `true` if the pair is stable, `false` otherwise. ### Returns - **address** - The address of the pair contract. ### Example ```solidity address existingPair = factory.getPair(MIM, USDC, true); ``` ## BaseV1Factory - Set Pause ### Description Pauses or unpauses all swaps across the protocol. Requires pauser role. ### Method `setPause(bool _paused)` ### Parameters - **_paused** (bool) - `true` to pause, `false` to unpause. ### Example ```solidity factory.setPause(true); ``` ## BaseV1Factory - All Pairs Length ### Description Returns the total number of pairs deployed by the factory. ### Method `allPairsLength()` ### Returns - **uint256** - The total number of pairs. ### Example ```solidity uint256 count = factory.allPairsLength(); ``` ``` -------------------------------- ### BaseV1Pair - LP Mint / Burn / Fees Source: https://context7.com/velodrome-finance/solidly/llms.txt Functions for managing Liquidity Provider (LP) positions, including minting, burning, and claiming fees. ```APIDOC ## BaseV1Pair - LP Mint / Burn / Fees ### Description `mint` and `burn` are low-level functions called via the router. `claimFees` lets LP token holders collect their pro-rata share of the 0.01% trading fees that are tracked separately in `BaseV1Fees`. ### Methods #### `mint(address recipient)` - **Description**: Low-level function to mint LP tokens. Assumes tokens have already been transferred to the pair contract. - **Parameters**: - `recipient` (address): The address to which LP tokens will be minted. - **Response**: - `liquidity` (uint): The amount of LP tokens minted. - **Example**: ```solidity // Transfer tokens to the pair contract directly, then call mint IERC20(pair.token0()).transfer(pairAddress, amount0); IERC20(pair.token1()).transfer(pairAddress, amount1); uint liquidity = pair.mint(recipient); ``` #### `burn(address recipient)` - **Description**: Low-level function to burn LP tokens and return underlying assets. Assumes LP tokens have been transferred back to the pair contract. - **Parameters**: - `recipient` (address): The address to which the underlying tokens will be sent. - **Response**: - `out0` (uint): The amount of token0 returned. - `out1` (uint): The amount of token1 returned. - **Example**: ```solidity // Transfer LP tokens back, then call burn IERC20(pairAddress).transfer(pairAddress, liquidity); (uint out0, uint out1) = pair.burn(recipient); ``` #### `claimFees()` - **Description**: Allows LP token holders to claim their pro-rata share of accumulated trading fees. - **Response**: - `claimed0` (uint): Amount of token0 fees claimed. - `claimed1` (uint): Amount of token1 fees claimed. - **Example**: ```solidity (uint claimed0, uint claimed1) = pair.claimFees(); ``` #### `claimable0(address account)` - **Description**: Returns the amount of token0 fees claimable by a given account. - **Parameters**: - `account` (address): The address of the account to check. - **Response**: - `pending0` (uint): The amount of token0 fees pending. - **Example**: ```solidity uint pending0 = pair.claimable0(msg.sender); ``` #### `claimable1(address account)` - **Description**: Returns the amount of token1 fees claimable by a given account. - **Parameters**: - `account` (address): The address of the account to check. - **Response**: - `pending1` (uint): The amount of token1 fees pending. - **Example**: ```solidity uint pending1 = pair.claimable1(msg.sender); ``` #### `sync()` - **Description**: Forces a synchronization of the pair's reserves with the current token balances. Useful after direct token transfers. - **Example**: ```solidity pair.sync(); ``` #### `skim(address recipient)` - **Description**: Skims excess tokens from the pair contract (above reserves) and sends them to a specified recipient. - **Parameters**: - `recipient` (address): The address to send the excess tokens to. - **Example**: ```solidity pair.skim(recipient); ``` ``` -------------------------------- ### BaseV1Router swapExactTokensForTokens Source: https://github.com/velodrome-finance/solidly/blob/master/readme.md Swaps an exact amount of tokens for another token through a series of routes. ```APIDOC ## BaseV1Router swapExactTokensForTokens ### Description Swaps an exact amount of tokens for another token through a series of routes. This function allows for complex swaps across multiple pairs. ### Function Signature ```solidity function swapExactTokensForTokens( uint amountIn, uint amountOutMin, route[] calldata routes, address to, uint deadline ) external ensure(deadline) returns (uint[] memory amounts) ``` ### Parameters #### Path Parameters - **amountIn** (uint) - The exact amount of tokens to send. - **amountOutMin** (uint) - The minimum amount of output tokens expected. - **routes** (route[] calldata) - An array of routes to follow for the swap. Each route specifies the tokenIn, tokenOut, and the pair address. - **to** (address) - The address to which the output tokens will be sent. - **deadline** (uint) - The transaction deadline. ``` -------------------------------- ### BaseV1Factory createPair Source: https://github.com/velodrome-finance/solidly/blob/master/readme.md Creates a new pair (pool) between two tokens. ```APIDOC ## BaseV1Factory createPair ### Description Creates a new pair (pool) between two tokens. This function can be called permissionlessly. ### Function Signature ```solidity function createPair(address tokenA, address tokenB, bool stable) external returns (address pair) ``` ### Parameters #### Path Parameters - **tokenA** (address) - The address of the first token. - **tokenB** (address) - The address of the second token. - **stable** (bool) - Whether the pair should be a stable swap pair. ``` -------------------------------- ### BaseV1Router01 - Add/Remove Liquidity Source: https://context7.com/velodrome-finance/solidly/llms.txt The `BaseV1Router01` contract facilitates adding and removing liquidity from pairs. It can also auto-create pairs if they do not exist. ```APIDOC ## BaseV1Router01 - Add Liquidity ### Description Transfers tokens to a pair contract and mints LP tokens in a single atomic transaction. The router can auto-create the pair if it does not exist. ### Method `addLiquidity(address tokenA, address tokenB, bool stable, uint amountA, uint amountB, uint minAmountA, uint minAmountB, address to, uint deadline)` ### Parameters - **tokenA** (address) - The address of the first token. - **tokenB** (address) - The address of the second token. - **stable** (bool) - `true` if the pair is stable, `false` otherwise. - **amountA** (uint) - The amount of `tokenA` to deposit. - **amountB** (uint) - The amount of `tokenB` to deposit. - **minAmountA** (uint) - The minimum amount of `tokenA` to deposit (slippage tolerance). - **minAmountB** (uint) - The minimum amount of `tokenB` to deposit (slippage tolerance). - **to** (address) - The address to send the LP tokens to. - **deadline** (uint) - The transaction deadline in Unix time. ### Returns - **uint** - The actual amount of `tokenA` deposited. - **uint** - The actual amount of `tokenB` deposited. - **uint** - The amount of LP tokens minted. ### Example ```solidity BaseV1Router01 router = BaseV1Router01(0xa38cd27185a464914D3046f0AB9d43356B34829D); IERC20 mimToken = IERC20(0x82f0b8b456c1a451378467398982d4834b6829c1); IERC20 usdcToken = IERC20(0x04068DA6C83AFCFA0e13ba15A6696662335D5b75); uint amountMIM = 1000e18; uint amountUSDC = 1000e6; mimToken.approve(address(router), amountMIM); usdcToken.approve(address(router), amountUSDC); (uint actualA, uint actualB, uint lpTokens) = router.addLiquidity( address(mimToken), address(usdcToken), true, // stable pair amountMIM, amountUSDC, amountMIM * 995 / 1000, // 0.5% slippage amountUSDC * 995 / 1000, // 0.5% slippage msg.sender, block.timestamp + 300 ); ``` ## BaseV1Router01 - Remove Liquidity ### Description Burns LP tokens and returns the underlying assets to the caller. ### Method `removeLiquidity(address tokenA, address tokenB, bool stable, uint lpTokens, uint minAmountA, uint minAmountB, address to, uint deadline)` ### Parameters - **tokenA** (address) - The address of the first token. - **tokenB** (address) - The address of the second token. - **stable** (bool) - `true` if the pair is stable, `false` otherwise. - **lpTokens** (uint) - The amount of LP tokens to burn. - **minAmountA** (uint) - The minimum amount of `tokenA` to receive (slippage tolerance). - **minAmountB** (uint) - The minimum amount of `tokenB` to receive (slippage tolerance). - **to** (address) - The address to send the underlying assets to. - **deadline** (uint) - The transaction deadline in Unix time. ### Returns - **uint** - The amount of `tokenA` received. - **uint** - The amount of `tokenB` received. ### Example ```solidity address pair = router.pairFor(address(mimToken), address(usdcToken), true); IERC20(pair).approve(address(router), lpTokens); (uint outMIM, uint outUSDC) = router.removeLiquidity( address(mimToken), address(usdcToken), true, lpTokens, 0, 0, // min amounts (set appropriately in production) msg.sender, block.timestamp + 300 ); ``` ## BaseV1Router01 - Quote Add Liquidity ### Description Estimates the amount of liquidity tokens that would be minted for a given deposit of `tokenA` and `tokenB`. ### Method `quoteAddLiquidity(address tokenA, address tokenB, bool stable, uint amountA, uint amountB)` ### Parameters - **tokenA** (address) - The address of the first token. - **tokenB** (address) - The address of the second token. - **stable** (bool) - `true` if the pair is stable, `false` otherwise. - **amountA** (uint) - The amount of `tokenA` to deposit. - **amountB** (uint) - The amount of `tokenB` to deposit. ### Returns - **uint** - The expected amount of `tokenA` to be deposited. - **uint** - The expected amount of `tokenB` to be deposited. - **uint** - The expected amount of LP tokens to be minted. ### Example ```solidity (uint expectedA, uint expectedB, uint expectedLp) = router.quoteAddLiquidity( address(mimToken), address(usdcToken), true, amountMIM, amountUSDC ); ``` ``` -------------------------------- ### Add and Remove Liquidity with BaseV1Router01 Source: https://context7.com/velodrome-finance/solidly/llms.txt Use BaseV1Router01 to add or remove liquidity from AMM pairs. The router can auto-create pairs if they don't exist. Ensure tokens are approved before calling `addLiquidity` or `removeLiquidity`. ```Solidity BaseV1Router01 router = BaseV1Router01(0xa38cd27185a464914D3046f0AB9d43356B34829D); IERC20 mimToken = IERC20(0x82f0b8b456c1a451378467398982d4834b6829c1); IERC20 usdcToken = IERC20(0x04068DA6C83AFCFA0e13ba15A6696662335D5b75); uint amountMIM = 1000e18; // 1,000 MIM uint amountUSDC = 1000e6; // 1,000 USDC (6 decimals) // Approve router mimToken.approve(address(router), amountMIM); usdcToken.approve(address(router), amountUSDC); // Preview expected liquidity before transacting (uint expectedA, uint expectedB, uint expectedLp) = router.quoteAddLiquidity( address(mimToken), address(usdcToken), true, amountMIM, amountUSDC ); // Add liquidity; 0.5% slippage tolerance, 5-minute deadline (uint actualA, uint actualB, uint lpTokens) = router.addLiquidity( address(mimToken), address(usdcToken), true, // stable pair amountMIM, amountUSDC, amountMIM * 995 / 1000, amountUSDC * 995 / 1000, msg.sender, // LP tokens sent to caller block.timestamp + 300 ); // lpTokens are ERC-20, symbol = "sAMM-MIM/USDC" // ---- Remove liquidity (no permit) ---- address pair = router.pairFor(address(mimToken), address(usdcToken), true); IERC20(pair).approve(address(router), lpTokens); (uint outMIM, uint outUSDC) = router.removeLiquidity( address(mimToken), address(usdcToken), true, lpTokens, 0, 0, // min amounts (set appropriately in production) msg.sender, block.timestamp + 300 ); ``` -------------------------------- ### BaseV1Pair mint Source: https://github.com/velodrome-finance/solidly/blob/master/readme.md Mints liquidity tokens for a BaseV1Pair. ```APIDOC ## BaseV1Pair mint ### Description Mints liquidity tokens for a BaseV1Pair. This function should not be referenced directly and should be interacted with via the BaseV1Router. ### Function Signature ```solidity function mint(address to) external returns (uint liquidity) ``` ### Parameters #### Path Parameters - **to** (address) - The address to which liquidity tokens will be sent. ``` -------------------------------- ### BaseV1Router01 - swapExactTokensForTokens Source: https://context7.com/velodrome-finance/solidly/llms.txt Executes a multi-hop swap along a user-supplied route array. The router automatically routes through the best pool for single-hop swaps via getAmountOut. ```APIDOC ## BaseV1Router01 - swapExactTokensForTokens ### Description Executes a multi-hop swap along a user-supplied route array. Each `route` struct specifies the input token, output token, and whether the hop traverses the stable or volatile pool. The router automatically routes through the best pool for single-hop swaps via `getAmountOut`. ### Method `swapExactTokensForTokens` ### Parameters - `amountIn` (uint) - The exact amount of input tokens to send. - `amountOutMin` (uint) - The minimum amount of output tokens the user will receive. - `routes` (BaseV1Router01.route[]) - An array of route structs specifying the swap path. - `to` (address) - The address to send the output tokens to. - `deadline` (uint) - The maximum timestamp the transaction can be mined. ### Request Example ```solidity BaseV1Router01.route[] memory routes = new BaseV1Router01.route[](1); routes[0] = BaseV1Router01.route({ from: 0x82f0b8b456c1a451378467398982d4834b6829c1, // MIM to: 0x04068DA6C83AFCFA0e13ba15A6696662335D5b75, // USDC stable: true }); IERC20(routes[0].from).approve(address(router), 500e18); uint[] memory amounts = router.swapExactTokensForTokens( 500e18, // amountIn: 500 MIM 498e6, // amountOutMin: 498 USDC (0.4% slippage) routes, msg.sender, block.timestamp + 300 ); ``` ### Response - `amounts` (uint[]) - An array containing the input amount and the actual output amount. ``` -------------------------------- ### BaseV1Pair Swap Function Source: https://github.com/velodrome-finance/solidly/blob/master/readme.md Executes a swap within a BaseV1Pair. This function is part of the BaseV1Pair contract and should be interacted with via the BaseV1Router. ```Solidity function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external ``` -------------------------------- ### BaseV1Router01 - getAmountOut Source: https://context7.com/velodrome-finance/solidly/llms.txt Queries the expected output amount for a single-hop swap between two tokens, indicating whether to use the stable or volatile pool. ```APIDOC ## BaseV1Router01 - getAmountOut ### Description Queries the expected output amount for a single-hop swap between two tokens, indicating whether to use the stable or volatile pool. This is useful for determining the best pool for a direct swap. ### Method `getAmountOut` ### Parameters - `amountIn` (uint) - The amount of input tokens. - `tokenA` (address) - The address of the input token. - `tokenB` (address) - The address of the output token. ### Request Example ```solidity (uint bestOut, bool isStable) = router.getAmountOut(1000e18, address(MIM), address(USDC)); // isStable = true → route through sAMM // isStable = false → route through vAMM ``` ### Response - `bestOut` (uint) - The expected output amount. - `isStable` (bool) - True if the stable pool should be used, false if the volatile pool should be used. ``` -------------------------------- ### BaseV1Pair - TWAP Oracle Queries Source: https://context7.com/velodrome-finance/solidly/llms.txt Provides functions to query Time-Weighted Average Prices (TWAP) from a BaseV1Pair contract. ```APIDOC ## BaseV1Pair - TWAP Oracle Queries ### Description `BaseV1Pair` records a 30-minute TWAP observation every `periodSize` seconds without any external keeper. `current()` returns the time-weighted output for the most recent window; `quote()` averages over multiple windows for configurable granularity; `sample()` returns the raw per-window price series. ### Methods #### `current(address token, uint amountIn)` - **Description**: Returns the time-weighted output for the most recent TWAP window. - **Parameters**: - `token` (address): The address of the token for which to calculate the TWAP output. - `amountIn` (uint): The amount of the input token. - **Response**: - `twapOut` (uint): The calculated TWAP output amount. - **Example**: ```solidity uint twapOut = pair.current(MIM, 1000e18); ``` #### `quote(address token, uint amountIn, uint windows)` - **Description**: Averages over multiple TWAP windows for configurable granularity. - **Parameters**: - `token` (address): The address of the token for which to calculate the TWAP output. - `amountIn` (uint): The amount of the input token. - `windows` (uint): The number of TWAP windows to average over. - **Response**: - `avgOut` (uint): The calculated average output amount. - **Example**: ```solidity uint avgOut = pair.quote(MIM, 1000e18, 4); // 4-point average (120 minutes of history) ``` #### `prices(address token, uint amountIn, uint count)` - **Description**: Returns the raw per-window price series. - **Parameters**: - `token` (address): The address of the token for which to retrieve prices. - `amountIn` (uint): The amount of the input token. - `count` (uint): The number of historical windows to retrieve. - **Response**: - `history` (uint[]): An array of output amounts for each window. - **Example**: ```solidity uint[] memory history = pair.prices(MIM, 1000e18, 8); // Raw array of 8 per-window prices ``` #### `currentCumulativePrices()` - **Description**: Returns the cumulative prices and timestamp for external TWAP construction. - **Response**: - `res0Cum` (uint): Cumulative price for token0. - `res1Cum` (uint): Cumulative price for token1. - `ts` (uint): Timestamp of the cumulative prices. - **Example**: ```solidity (uint res0Cum, uint res1Cum, uint ts) = pair.currentCumulativePrices(); ``` #### `getAmountOut(uint amountIn, address tokenIn)` - **Description**: Provides an instant quote (spot price), ignoring TWAP. - **Parameters**: - `amountIn` (uint): The amount of input tokens. - `tokenIn` (address): The address of the input token. - **Response**: - `spotOut` (uint): The calculated spot output amount. - **Example**: ```solidity uint spotOut = pair.getAmountOut(1000e18, MIM); ``` #### `metadata()` - **Description**: Returns metadata about the pair contract. - **Response**: - `dec0` (uint): Decimals of token0. - `dec1` (uint): Decimals of token1. - `r0` (uint): Reserves of token0. - `r1` (uint): Reserves of token1. - `stable` (bool): Whether the pair is stable. - `t0` (address): Address of token0. - `t1` (address): Address of token1. - **Example**: ```solidity (uint dec0, uint dec1, uint r0, uint r1, bool stable, address t0, address t1) = pair.metadata(); ``` ``` -------------------------------- ### BaseV1Router Add Liquidity Source: https://github.com/velodrome-finance/solidly/blob/master/readme.md Adds liquidity to a BaseV1 pool. This is the primary function for LPs to deposit assets and receive liquidity tokens. Ensure the deadline is respected. ```Solidity function addLiquidity( address tokenA, address tokenB, bool stable, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external ensure(deadline) returns (uint amountA, uint amountB, uint liquidity) ``` -------------------------------- ### BaseV1Pair Mint Function Source: https://github.com/velodrome-finance/solidly/blob/master/readme.md Mints liquidity tokens for a BaseV1Pair. This function is part of the BaseV1Pair contract and should be interacted with via the BaseV1Router. ```Solidity function mint(address to) external returns (uint liquidity) ``` -------------------------------- ### BaseV1Pair burn Source: https://github.com/velodrome-finance/solidly/blob/master/readme.md Burns liquidity tokens to retrieve underlying assets from a BaseV1Pair. ```APIDOC ## BaseV1Pair burn ### Description Burns liquidity tokens to retrieve underlying assets from a BaseV1Pair. This function should not be referenced directly and should be interacted with via the BaseV1Router. ### Function Signature ```solidity function burn(address to) external returns (uint amount0, uint amount1) ``` ### Parameters #### Path Parameters - **to** (address) - The address to which the retrieved assets will be sent. ``` -------------------------------- ### BaseV1Router removeLiquidity Source: https://github.com/velodrome-finance/solidly/blob/master/readme.md Removes liquidity from a pair. ```APIDOC ## BaseV1Router removeLiquidity ### Description Removes liquidity from a pair and returns the underlying assets. ### Function Signature ```solidity function removeLiquidity( address tokenA, address tokenB, bool stable, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) public ensure(deadline) returns (uint amountA, uint amountB) ``` ### Parameters #### Path Parameters - **tokenA** (address) - The address of the first token. - **tokenB** (address) - The address of the second token. - **stable** (bool) - Whether the pair is a stable swap pair. - **liquidity** (uint) - The amount of liquidity tokens to burn. - **amountAMin** (uint) - The minimum amount of tokenA to receive. - **amountBMin** (uint) - The minimum amount of tokenB to receive. - **to** (address) - The address to which the retrieved assets will be sent. - **deadline** (uint) - The transaction deadline. ```