creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "src/pools/Pools.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\nimport \"openzeppelin-contracts/contracts/security/ReentrancyGuard.sol\";\nimport \"openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport \"openzeppelin-contracts/contracts/token/ERC20/IERC20.sol\";\nimport \"openzeppelin-contracts/contracts/access/Ownable.sol\";\nimport \"../interfaces/IExchangeConfig.sol\";\nimport \"../arbitrage/ArbitrageSearch.sol\";\nimport \"./interfaces/IPoolsConfig.sol\";\nimport \"./interfaces/IPools.sol\";\nimport \"./PoolStats.sol\";\nimport \"./PoolUtils.sol\";\n\n\n// The Pools contract stores the reserves that are used for swaps within the DEX.\n// It handles deposits, arbitrage, and keeps stats for proportional rewards distribution to the liquidity providers.\n//\n// Only the Liquidity contract can actually call addLiquidity and removeLiquidity.\n// User liquidity accounting is done by Liquidity (via its derivation of StakingRewards).\n\ncontract Pools is IPools, ReentrancyGuard, PoolStats, ArbitrageSearch, Ownable\n\t{\n\tevent LiquidityAdded(IERC20 indexed tokenA, IERC20 indexed tokenB, uint256 addedAmountA, uint256 addedAmountB, uint256 addedLiquidity);\n\tevent LiquidityRemoved(IERC20 indexed tokenA, IERC20 indexed tokenB, uint256 reclaimedA, uint256 reclaimedB, uint256 removedLiquidity);\n\tevent TokenDeposit(address indexed user, IERC20 indexed token, uint256 amount);\n\tevent TokenWithdrawal(address indexed user, IERC20 indexed token, uint256 amount);\n\tevent SwapAndArbitrage(address indexed user, IERC20 indexed swapTokenIn, IERC20 indexed swapTokenOut, uint256 swapAmountIn, uint256 swapAmountOut, uint256 arbitrageProfit);\n\n\tusing SafeERC20 for IERC20;\n\n\tstruct PoolReserves\n\t\t{\n\t\tuint128 reserve0;\t\t\t\t\t\t// The token reserves such that address(token0) < address(token1)\n\t\tuint128 reserve1;\n\t\t}\n\n\n\tIDAO public dao;\n\tILiquidity public liquidity;\n\tISalt public salt;\n\n\t// Set to true when starting the exchange is approved by the bootstrapBallot\n\tbool public exchangeIsLive;\n\n\t// Keeps track of the pool reserves by poolID\n\tmapping(bytes32=>PoolReserves) private _poolReserves;\n\n\t// User token balances for deposited tokens\n\tmapping(address=>mapping(IERC20=>uint256)) private _userDeposits;\n\n\t// Used to prevent splitting large swaps within a single block into smaller ones as doing so allows for greater price manipulation without consequence from the arbitrage rebalancing.\n\tmapping(address => uint) private lastSwappedBlocks;\n\n\n\tconstructor( IExchangeConfig _exchangeConfig, IPoolsConfig _poolsConfig )\n\tArbitrageSearch(_exchangeConfig)\n\tPoolStats(_exchangeConfig, _poolsConfig)\n\t\t{\n\t\tsalt = _exchangeConfig.salt();\n\t\t}\n\n\n\t// Allow users to make only one swap per block\n\tmodifier oneUserSwapPerBlock()\n\t\t{\n\t\trequire(lastSwappedBlocks[msg.sender] != block.number, \"User already swapped in this block\");\n        _;\n        lastSwappedBlocks[msg.sender] = block.number;\n        }\n\n\n\tmodifier ensureNotExpired(uint256 deadline)\n\t\t{\n\t\trequire(block.timestamp <= deadline, \"TX EXPIRED\");\n\t\t_;\n\t\t}\n\n\n\t// This will be called only once - at deployment time\n\tfunction setContracts( IDAO _dao, ILiquidity _liquidity ) external onlyOwner\n\t\t{\n\t\tdao = _dao;\n\t\tliquidity = _liquidity;\n\n\t\t// setContracts can only be called once\n\t\trenounceOwnership();\n\t\t}\n\n\n\tfunction startExchangeApproved() external nonReentrant\n\t\t{\n    \trequire( msg.sender == address(exchangeConfig.initialDistribution().bootstrapBallot()), \"Pools.startExchangeApproved can only be called from the BootstrapBallot contract\" );\n\n\t\t// Make sure that the arbitrage indicies for the whitelisted pools are updated before starting the exchange\n\t\tupdateArbitrageIndicies();\n\n\t\texchangeIsLive = true;\n\t\t}\n\n\n\t// Add the given amount of two tokens to the specified liquidity pool.\n\t// The maximum amount of tokens is added while having the added amount have the same ratio as the current reserves.\n\tfunction _addLiquidity( bytes32 poolID, uint256 maxAmount0, uint256 maxAmount1, uint256 totalLiquidity ) internal returns(uint256 addedAmount0, uint256 addedAmount1, uint256 addedLiquidity)\n\t\t{\n\t\tPoolReserves storage reserves = _poolReserves[poolID];\n\t\tuint256 reserve0 = reserves.reserve0;\n\t\tuint256 reserve1 = reserves.reserve1;\n\n\t\t// If either reserve is zero then consider the pool to be empty and that the added liquidity will become the initial token ratio\n\t\tif ( ( reserve0 == 0 ) || ( reserve1 == 0 ) )\n\t\t\t{\n\t\t\t// Update the reserves\n\t\t\treserves.reserve0 += uint128(maxAmount0);\n\t\t\treserves.reserve1 += uint128(maxAmount1);\n\n\t\t\t// Default liquidity will be the addition of both maxAmounts in case one of them is much smaller (has smaller decimals)\n\t\t\treturn ( maxAmount0, maxAmount1, (maxAmount0 + maxAmount1) );\n\t\t\t}\n\n\t\t// Add liquidity to the pool proportional to the current existing token reserves in the pool.\n\t\t// First, try the proportional amount of tokenB for the given maxAmountA\n\t\tuint256 proportionalB = ( maxAmount0 * reserve1 ) / reserve0;\n\n\t\t// proportionalB too large for the specified maxAmountB?\n\t\tif ( proportionalB > maxAmount1 )\n\t\t\t{\n\t\t\t// Use maxAmountB and a proportional amount for tokenA instead\n\t\t\taddedAmount0 = ( maxAmount1 * reserve0 ) / reserve1;\n\t\t\taddedAmount1 = maxAmount1;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\taddedAmount0 = maxAmount0;\n\t\t\taddedAmount1 = proportionalB;\n\t\t\t}\n\n\t\t// Ensure that the added amounts are at least DUST\n\t\trequire( addedAmount0 > PoolUtils.DUST, \"Added liquidity for token 0 less than DUST\" );\n\t\trequire( addedAmount1 > PoolUtils.DUST, \"Added liquidity for token 1 less than DUST\" );\n\n\t\t// Update the reserves\n\t\treserves.reserve0 += uint128(addedAmount0);\n\t\treserves.reserve1 += uint128(addedAmount1);\n\n\t\t// Determine the amount of liquidity that will be given to the user to reflect their share of the total liquidity.\n\t\taddedLiquidity = (totalLiquidity * (addedAmount0+addedAmount1) ) / (reserve0+reserve1);\n\t\t}\n\n\n\t// Add liquidity to the specified pool (must be a whitelisted pool)\n\t// Only callable from the Liquidity contract - so it can specify totalLiquidity with authority\n\tfunction addLiquidity( IERC20 tokenA, IERC20 tokenB, uint256 maxAmountA, uint256 maxAmountB, uint256 minAddedAmountA, uint256 minAddedAmountB, uint256 totalLiquidity ) external nonReentrant returns (uint256 addedAmountA, uint256 addedAmountB, uint256 addedLiquidity)\n\t\t{\n\t\trequire( msg.sender == address(liquidity), \"Pools.addLiquidity is only callable from the Liquidity contract\" );\n\t\trequire( exchangeIsLive, \"The exchange is not yet live\" );\n\t\trequire( address(tokenA) != address(tokenB), \"Cannot add liquidity for duplicate tokens\" );\n\n\t\trequire( maxAmountA > PoolUtils.DUST, \"The amount of tokenA to add is too small\" );\n\t\trequire( maxAmountB > PoolUtils.DUST, \"The amount of tokenB to add is too small\" );\n\n\t\t(bytes32 poolID, bool flipped) = PoolUtils._poolIDAndFlipped(tokenA, tokenB);\n\n\t\t// Flip the users arguments if they are not in reserve token order with address(tokenA) < address(tokenB)\n\t\tif ( flipped )\n\t\t\t(addedAmountB, addedAmountA, addedLiquidity) = _addLiquidity( poolID, maxAmountB, maxAmountA, totalLiquidity );\n\t\telse\n\t\t\t(addedAmountA, addedAmountB, addedLiquidity) = _addLiquidity( poolID, maxAmountA, maxAmountB, totalLiquidity );\n\n\t\t// Make sure the minimum liquidity has been added\n\t\trequire( addedAmountA >= minAddedAmountA, \"Insufficient tokenA added to liquidity\" );\n\t\trequire( addedAmountB >= minAddedAmountB, \"Insufficient tokenB added to liquidity\" );\n\n\t\t// Transfer the tokens from the sender - only tokens without fees should be whitelisted on the DEX\n\t\ttokenA.safeTransferFrom(msg.sender, address(this), addedAmountA );\n\t\ttokenB.safeTransferFrom(msg.sender, address(this), addedAmountB );\n\n\t\temit LiquidityAdded(tokenA, tokenB, addedAmountA, addedAmountB, addedLiquidity);\n\t\t}\n\n\n\t// Remove liquidity for the user and reclaim the underlying tokens\n\t// Only callable from the Liquidity contract - so it can specify totalLiquidity with authority\n\tfunction removeLiquidity( IERC20 tokenA, IERC20 tokenB, uint256 liquidityToRemove, uint256 minReclaimedA, uint256 minReclaimedB, uint256 totalLiquidity ) external nonReentrant returns (uint256 reclaimedA, uint256 reclaimedB)\n\t\t{\n\t\trequire( msg.sender == address(liquidity), \"Pools.removeLiquidity is only callable from the Liquidity contract\" );\n\t\trequire( liquidityToRemove > 0, \"The amount of liquidityToRemove cannot be zero\" );\n\n\t\t(bytes32 poolID, bool flipped) = PoolUtils._poolIDAndFlipped(tokenA, tokenB);\n\n\t\t// Determine how much liquidity is being withdrawn and round down in favor of the protocol\n\t\tPoolReserves storage reserves = _poolReserves[poolID];\n\n\t\tif (reserves.reserve0 <= reserves.reserve1 )\n\t\t\t{\n\t\t\treclaimedA = ( reserves.reserve0 * liquidityToRemove ) / totalLiquidity;\n\t\t\treclaimedB = ( reserves.reserve1 * reclaimedA ) / reserves.reserve0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\treclaimedB = ( reserves.reserve1 * liquidityToRemove ) / totalLiquidity;\n\t\t\treclaimedA = ( reserves.reserve0 * reclaimedB ) / reserves.reserve1;\n\t\t\t}\n\n\t\treserves.reserve0 -= uint128(reclaimedA);\n\t\treserves.reserve1 -= uint128(reclaimedB);\n\n\t\t// Make sure that removing liquidity doesn't drive either of the reserves below DUST.\n\t\t// This is to ensure that ratios remain relatively constant even after a maximum withdrawal.\n        require((reserves.reserve0 >= PoolUtils.DUST) && (reserves.reserve1 >= PoolUtils.DUST), \"Insufficient reserves after liquidity removal\");\n\n\t\t// Switch reclaimed amounts back to the order that was specified in the call arguments so they make sense to the caller\n\t\tif (flipped)\n\t\t\t(reclaimedA,reclaimedB) = (reclaimedB,reclaimedA);\n\n\t\trequire( (reclaimedA >= minReclaimedA) && (reclaimedB >= minReclaimedB), \"Insufficient underlying tokens returned\" );\n\n\t\t// Send the reclaimed tokens to the user\n\t\ttokenA.safeTransfer( msg.sender, reclaimedA );\n\t\ttokenB.safeTransfer( msg.sender, reclaimedB );\n\n\t\temit LiquidityRemoved(tokenA, tokenB, reclaimedA, reclaimedB, liquidityToRemove);\n\t\t}\n\n\n\t// Allow users to deposit tokens into the contract.\n\t// This is not rewarded or considered staking in any way.  It's simply a way to reduce gas costs by preventing transfers at swap time.\n\tfunction deposit( IERC20 token, uint256 amount ) external nonReentrant\n\t\t{\n        require( amount > PoolUtils.DUST, \"Deposit amount too small\");\n\n\t\t_userDeposits[msg.sender][token] += amount;\n\n\t\t// Transfer the tokens from the sender - only tokens without fees should be whitelisted on the DEX\n\t\ttoken.safeTransferFrom(msg.sender, address(this), amount );\n\n\t\temit TokenDeposit(msg.sender, token, amount);\n\t\t}\n\n\n\t// Withdraw tokens that were previously deposited\n    function withdraw( IERC20 token, uint256 amount ) external nonReentrant\n    \t{\n    \trequire( _userDeposits[msg.sender][token] >= amount, \"Insufficient balance to withdraw specified amount\" );\n        require( amount > PoolUtils.DUST, \"Withdraw amount too small\");\n\n\t\t_userDeposits[msg.sender][token] -= amount;\n\n    \t// Send the token to the user\n    \ttoken.safeTransfer( msg.sender, amount );\n\n    \temit TokenWithdrawal(msg.sender, token, amount);\n    \t}\n\n\n\t// Swap amountIn tokens for amountOut tokens in the direction specified by flipped and update the reserves.\n\t// Only the reserves are updated - the function does not adjust deposited user balances or do ERC20 transfers.\n\t// Assumes that the reserves have already been checked for minimal necessary liquidity.\n    function _adjustReservesForSwap( PoolReserves storage reserves, bool flipped, uint256 amountIn ) internal returns (uint256 amountOut)\n    \t{\n\t\t// Constant Product AMM Math\n\t\t// k=r0*r1\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t• product of reserves is constant k\n\t\t// k=(r0+amountIn)*(r1-amountOut)\t\t\t\t\t\t\t• add some token0 to r0 and swap it for some token1 which is removed from r1\n\t\t// r1-amountOut=k/(r0+amountIn)\t\t\t\t\t\t\t\t• divide by (r0+amountIn) and flip\n\t\t// amountOut=r1-k/(r0+amountIn)\t\t\t\t\t\t\t\t• multiply by -1 and isolate amountOut\n\t\t// amountOut(r0+amountIn)=r1(r0+amountIn)-k\t\t• multiply by (r0+amountIn)\n\t\t// amountOut(r0+amountIn)=r1*r0+r1*amountIn-k\t• multiply r1 by (r0+amountIn)\n\t\t// amountOut(r0+amountIn)=k+r1*amountIn-k\t\t\t• r0*r1=k (from above)\n\t\t// amountOut(r0+amountIn)=r1*amountIn\t\t\t\t\t• cancel k\n\t\t// amountOut=r1*amountIn/(r0+amountIn)\t\t\t\t• isolate amountOut\n\n        uint256 reserve0 = reserves.reserve0;\n        uint256 reserve1 = reserves.reserve1;\n\n\t\t// See if the reserves should be flipped\n        if (flipped)\n        \t{\n\t\t\treserve1 += amountIn;\n\t\t\tamountOut = reserve0 * amountIn / reserve1;\n\t\t\treserve0 -= amountOut;\n        \t}\n        else\n        \t{\n\t\t\treserve0 += amountIn;\n\t\t\tamountOut = reserve1 * amountIn / reserve0;\n\t\t\treserve1 -= amountOut;\n        \t}\n\n\t\t// Make sure that the reserves after swap are greater than DUST\n        require( (reserve0 > PoolUtils.DUST) && (reserve1 > PoolUtils.DUST), \"Insufficient reserves after swap\");\n\n\t\t// Update the reserves with an overflow check\n\t\trequire( (reserve0 <= type(uint128).max) && (reserve1 <= type(uint128).max), \"Reserves overflow after swap\" );\n\n\t\treserves.reserve0 = uint128(reserve0);\n\t\treserves.reserve1 = uint128(reserve1);\n    \t}\n\n\n    // Arbitrage a token to itself along a specified circular path (starting and ending with WETH), taking advantage of imbalances in the exchange pools.\n    // Does not require any deposited tokens to make the call, but requires that the resulting amountOut is greater than the specified arbitrageAmountIn.\n    // Essentially the caller virtually \"borrows\" arbitrageAmountIn of the starting token and virtually \"repays\" it from their received amountOut at the end of the swap chain.\n    // The extra amountOut (compared to arbitrageAmountIn) is the arbitrageProfit.\n\tfunction _arbitrage(uint256 arbitrageAmountIn, PoolReserves storage reservesA, PoolReserves storage reservesB, PoolReserves storage reservesC, bool flippedA, bool flippedB, bool flippedC ) internal returns (uint256 arbitrageProfit)\n\t\t{\n\t\tuint256 amountOut = _adjustReservesForSwap( reservesA, flippedA, arbitrageAmountIn );\n\t\tamountOut = _adjustReservesForSwap( reservesB, flippedB, amountOut );\n\t\tamountOut = _adjustReservesForSwap( reservesC, flippedC, amountOut );\n\n\t\t// Will revert if amountOut < arbitrageAmountIn\n\t\tarbitrageProfit = amountOut - arbitrageAmountIn;\n\n\t\t// Immediately swap the generated WETH arbitrage profits to SALT\n\t\t(bytes32 poolID, bool flipped) = PoolUtils._poolIDAndFlipped(weth, salt);\n        PoolReserves storage reserves = _poolReserves[poolID];\n\n        // Only swap for SALT with sufficient reserves\n\t\tif ( ( reserves.reserve0 > PoolUtils.DUST ) && ( reserves.reserve1 > PoolUtils.DUST ) )\n\t\t\t{\n\t\t\tuint256 saltOut = _adjustReservesForSwap(reserves, flipped, arbitrageProfit);\n\n\t\t\t// Deposit the swapped SALT for the DAO - to be used later within DAO.performUpkeep\n\t\t\t_userDeposits[address(dao)][salt] += saltOut;\n\t\t\t}\n\t\t}\n\n\n\t// Check to see if profitable arbitrage is possible after the user swap that was just made\n\t// Check the arbitrage path: WETH->arbToken2->arbToken3->WETH\n\tfunction _attemptArbitrage( IERC20 arbToken2, IERC20 arbToken3 ) internal returns (uint256 arbitrageProfit)\n\t\t{\n\t\tbytes32 poolID;\n\t\tbool flippedA;\n\t\tbool flippedB;\n\t\tbool flippedC;\n\n\t\tPoolReserves storage reservesA;\n\t\tPoolReserves storage reservesB;\n\t\tPoolReserves storage reservesC;\n\n\t\t// Given the specified arbitrage path, determine the best arbitrageAmountIn to use\n\t\tuint256 arbitrageAmountIn;\n\t\t\t{\n\t\t\t(poolID, flippedA) = PoolUtils._poolIDAndFlipped(weth, arbToken2);\n\t\t\treservesA = _poolReserves[poolID];\n\t\t\t(uint256 a0, uint256 a1) = (reservesA.reserve0, reservesA.reserve1 );\n\t\t\tif (flippedA)\n\t\t\t\t(a0, a1) = (a1, a0);\n\n\n\t\t\t(poolID, flippedB) = PoolUtils._poolIDAndFlipped(arbToken2, arbToken3);\n\t\t\treservesB = _poolReserves[poolID];\n\t\t\t(uint256 b0, uint256 b1) = (reservesB.reserve0, reservesB.reserve1 );\n\t\t\tif (flippedB)\n\t\t\t\t(b0, b1) = (b1, b0);\n\n\n\t\t\t(poolID, flippedC) = PoolUtils._poolIDAndFlipped(arbToken3, weth);\n\t\t\treservesC = _poolReserves[poolID];\n\t\t\t(uint256 c0, uint256 c1) = (reservesC.reserve0, reservesC.reserve1 );\n\t\t\tif (flippedC)\n\t\t\t\t(c0, c1) = (c1, c0);\n\n\t\t\t// Determine the best amount of WETH to start the arbitrage with\n\t\t\tif ( a0 > PoolUtils.DUST && a1 > PoolUtils.DUST && b0 > PoolUtils.DUST && b1 > PoolUtils.DUST && c0 > PoolUtils.DUST && c1 > PoolUtils.DUST )\n\t\t\t\tarbitrageAmountIn = _bestArbitrageIn(a0, a1, b0, b1, c0, c1 );\n\t\t\t}\n\n\t\t// If arbitrage is viable, then perform it\n\t\tif (arbitrageAmountIn > 0)\n\t\t\t{\n\t\t\t arbitrageProfit = _arbitrage(arbitrageAmountIn, reservesA, reservesB, reservesC, flippedA, flippedB, flippedC);\n\n\t\t\t// Update the stats related to the pools that contributed to the arbitrage so they can be rewarded proportionally later.\n\t\t\t// The arbitrage path can be identified by the middle tokens arbToken2 and arbToken3 (with WETH always on both ends)\n\t\t\t_updateProfitsFromArbitrage( arbToken2, arbToken3, arbitrageProfit );\n\t\t\t }\n\t\t}\n\n\n\t// Adjust the reserves for swapping between the two specified tokens and then immediately attempt arbitrage.\n\t// Does not require exchange access for the sending wallet.\n\tfunction _adjustReservesForSwapAndAttemptArbitrage( IERC20 swapTokenIn, IERC20 swapTokenOut, uint256 swapAmountIn, uint256 minAmountOut ) internal returns (uint256 swapAmountOut)\n\t\t{\n\t\t// Place the user swap first\n\t\t(bytes32 poolID, bool flipped) = PoolUtils._poolIDAndFlipped(swapTokenIn, swapTokenOut);\n        PoolReserves storage reserves = _poolReserves[poolID];\n\n        // Revert if reserves are insufficient\n        require((reserves.reserve0 > PoolUtils.DUST) && (reserves.reserve1 > PoolUtils.DUST), \"Insufficient reserves before swap\");\n\t\tswapAmountOut = _adjustReservesForSwap( reserves, flipped, swapAmountIn );\n\n\t\t// Make sure the swap meets the minimums specified by the user\n\t\trequire( swapAmountOut >= minAmountOut, \"Insufficient resulting token amount\" );\n\n\t\t// The user's swap has just been made - attempt atomic arbitrage to rebalance the pool and yield arbitrage profit.\n\n\t\t// Determine the arbitrage path for the given user swap.\n\t\t// Arbitrage path returned as: weth->arbToken2->arbToken3->weth\n\t\t(IERC20 arbToken2, IERC20 arbToken3) = _arbitragePath( swapTokenIn, swapTokenOut );\n\t\tuint256 arbitrageProfit = _attemptArbitrage( arbToken2, arbToken3 );\n\n\t\temit SwapAndArbitrage(msg.sender, swapTokenIn, swapTokenOut, swapAmountIn, swapAmountOut, arbitrageProfit);\n\t\t}\n\n\n    // Swap one token for another via a direct whitelisted pool.\n    // Having simpler swaps without multiple tokens in the swap chain makes it simpler (and less expensive gas wise) to find suitable arbitrage opportunities.\n    // Cheap arbitrage gas-wise is important as arbitrage will be atomically attempted with every user swap transaction.\n    // Requires that the first token in the chain has already been deposited for the caller.\n\tfunction swap( IERC20 swapTokenIn, IERC20 swapTokenOut, uint256 swapAmountIn, uint256 minAmountOut, uint256 deadline ) external oneUserSwapPerBlock nonReentrant ensureNotExpired(deadline) returns (uint256 swapAmountOut)\n\t\t{\n\t\t// Confirm and adjust user deposits\n\t\tmapping(IERC20=>uint256) storage userDeposits = _userDeposits[msg.sender];\n\n    \trequire( userDeposits[swapTokenIn] >= swapAmountIn, \"Insufficient deposited token balance of initial token\" );\n\t\tuserDeposits[swapTokenIn] -= swapAmountIn;\n\n\t\tswapAmountOut = _adjustReservesForSwapAndAttemptArbitrage(swapTokenIn, swapTokenOut, swapAmountIn, minAmountOut );\n\n\t\t// Deposit the final tokenOut for the caller\n\t\tuserDeposits[swapTokenOut] += swapAmountOut;\n\t\t}\n\n\n\t// Deposit tokenIn, swap to tokenOut and then have tokenOut sent to the sender\n\tfunction depositSwapWithdraw(IERC20 swapTokenIn, IERC20 swapTokenOut, uint256 swapAmountIn, uint256 minAmountOut, uint256 deadline ) external oneUserSwapPerBlock nonReentrant ensureNotExpired(deadline) returns (uint256 swapAmountOut)\n\t\t{\n\t\t// Transfer the tokens from the sender - only tokens without fees should be whitelisted on the DEX\n\t\tswapTokenIn.safeTransferFrom(msg.sender, address(this), swapAmountIn );\n\n\t\tswapAmountOut = _adjustReservesForSwapAndAttemptArbitrage(swapTokenIn, swapTokenOut, swapAmountIn, minAmountOut );\n\n    \t// Send tokenOut to the user\n    \tswapTokenOut.safeTransfer( msg.sender, swapAmountOut );\n\t\t}\n\n\n\t// Deposit tokenIn, swap to tokenOut without arbitrage and then have tokenOut sent to the sender.\n\t// Only callable by the Liquidity contract\n\tfunction depositZapSwapWithdraw(IERC20 zapSwapTokenIn, IERC20 zapSwapTokenOut, uint256 zapSwapAmountIn ) external returns (uint256 zapSwapAmountOut)\n\t\t{\n\t\trequire( msg.sender == address(liquidity), \"Pools.depositZapSwapWithdraw is only callable from the Liquidity contract\" );\n\n\t\t// Transfer the tokens from the sender - only tokens without fees should be whitelisted on the DEX\n\t\tzapSwapTokenIn.safeTransferFrom(msg.sender, address(this), zapSwapAmountIn );\n\n\t\t// Perform the zap swap without arbitrage or minimum checks (as the users final swap will be checked for relevant minimums).\n\t\t// PoolMath.determineZapSwapAmount already checked for reservers > DUST as well.\n\t\t(bytes32 poolID, bool flipped) = PoolUtils._poolIDAndFlipped(zapSwapTokenIn, zapSwapTokenOut);\n        PoolReserves storage reserves = _poolReserves[poolID];\n\n\t\t// Prevent users from zapping too much at once as they may encounter unexpected slippage\n\t\tif ( flipped )\n\t\t\trequire( zapSwapAmountIn < reserves.reserve1 / 100, \"Cannot zap more than 1% of the reserves\" );\n\t\telse\n\t\t\trequire( zapSwapAmountIn < reserves.reserve0 / 100, \"Cannot zap more than 1% of the reserves\" );\n\n\t\tzapSwapAmountOut = _adjustReservesForSwap( reserves, flipped, zapSwapAmountIn );\n\n    \t// Send tokenOut to the user\n    \tzapSwapTokenOut.safeTransfer( msg.sender, zapSwapAmountOut );\n\t\t}\n\n\n\t// A convenience method to perform two swaps in one transaction\n\tfunction depositDoubleSwapWithdraw( IERC20 swapTokenIn, IERC20 swapTokenMiddle, IERC20 swapTokenOut, uint256 swapAmountIn, uint256 minAmountOut, uint256 deadline ) external oneUserSwapPerBlock nonReentrant ensureNotExpired(deadline) returns (uint256 swapAmountOut)\n\t\t{\n\t\tswapTokenIn.safeTransferFrom(msg.sender, address(this), swapAmountIn );\n\n\t\tuint256 middleAmountOut = _adjustReservesForSwapAndAttemptArbitrage(swapTokenIn, swapTokenMiddle, swapAmountIn, 0 );\n\t\tswapAmountOut = _adjustReservesForSwapAndAttemptArbitrage(swapTokenMiddle, swapTokenOut, middleAmountOut, minAmountOut );\n\n    \tswapTokenOut.safeTransfer( msg.sender, swapAmountOut );\n\t\t}\n\n\n\t// === VIEWS ===\n\n\t// The pool reserves for two specified tokens - returned in the order specified by the caller\n\tfunction getPoolReserves(IERC20 tokenA, IERC20 tokenB) public view returns (uint256 reserveA, uint256 reserveB)\n\t\t{\n\t\t(bytes32 poolID, bool flipped) = PoolUtils._poolIDAndFlipped(tokenA, tokenB);\n\t\tPoolReserves memory reserves = _poolReserves[poolID];\n\t\treserveA = reserves.reserve0;\n\t\treserveB = reserves.reserve1;\n\n\t\t// Return the reserves in the order that they were requested\n\t\tif (flipped)\n\t\t\t(reserveA, reserveB) = (reserveB, reserveA);\n\t\t}\n\n\n\t// A user's deposited balance for a token\n\tfunction depositedUserBalance(address user, IERC20 token) public view returns (uint256)\n\t\t{\n\t\treturn _userDeposits[user][token];\n\t\t}\n\t}"
      },
      "lib/openzeppelin-contracts/contracts/security/ReentrancyGuard.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n    // Booleans are more expensive than uint256 or any type that takes up a full\n    // word because each write operation emits an extra SLOAD to first read the\n    // slot's contents, replace the bits taken up by the boolean, and then write\n    // back. This is the compiler's defense against contract upgrades and\n    // pointer aliasing, and it cannot be disabled.\n\n    // The values being non-zero value makes deployment a bit more expensive,\n    // but in exchange the refund on every call to nonReentrant will be lower in\n    // amount. Since refunds are capped to a percentage of the total\n    // transaction's gas, it is best to keep them low in cases like this one, to\n    // increase the likelihood of the full refund coming into effect.\n    uint256 private constant _NOT_ENTERED = 1;\n    uint256 private constant _ENTERED = 2;\n\n    uint256 private _status;\n\n    constructor() {\n        _status = _NOT_ENTERED;\n    }\n\n    /**\n     * @dev Prevents a contract from calling itself, directly or indirectly.\n     * Calling a `nonReentrant` function from another `nonReentrant`\n     * function is not supported. It is possible to prevent this from happening\n     * by making the `nonReentrant` function external, and making it call a\n     * `private` function that does the actual work.\n     */\n    modifier nonReentrant() {\n        _nonReentrantBefore();\n        _;\n        _nonReentrantAfter();\n    }\n\n    function _nonReentrantBefore() private {\n        // On the first call to nonReentrant, _status will be _NOT_ENTERED\n        require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n        // Any calls to nonReentrant after this point will fail\n        _status = _ENTERED;\n    }\n\n    function _nonReentrantAfter() private {\n        // By storing the original value once again, a refund is triggered (see\n        // https://eips.ethereum.org/EIPS/eip-2200)\n        _status = _NOT_ENTERED;\n    }\n\n    /**\n     * @dev Returns true if the reentrancy guard is currently set to \"entered\", which indicates there is a\n     * `nonReentrant` function in the call stack.\n     */\n    function _reentrancyGuardEntered() internal view returns (bool) {\n        return _status == _ENTERED;\n    }\n}\n"
      },
      "lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\nimport \"../extensions/IERC20Permit.sol\";\nimport \"../../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n    using Address for address;\n\n    /**\n     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful.\n     */\n    function safeTransfer(IERC20 token, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n    }\n\n    /**\n     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the\n     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.\n     */\n    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n    }\n\n    /**\n     * @dev Deprecated. This function has issues similar to the ones found in\n     * {IERC20-approve}, and its usage is discouraged.\n     *\n     * Whenever possible, use {safeIncreaseAllowance} and\n     * {safeDecreaseAllowance} instead.\n     */\n    function safeApprove(IERC20 token, address spender, uint256 value) internal {\n        // safeApprove should only be called when setting an initial allowance,\n        // or when resetting it to zero. To increase and decrease it, use\n        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n        require(\n            (value == 0) || (token.allowance(address(this), spender) == 0),\n            \"SafeERC20: approve from non-zero to non-zero allowance\"\n        );\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n    }\n\n    /**\n     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful.\n     */\n    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n        uint256 oldAllowance = token.allowance(address(this), spender);\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));\n    }\n\n    /**\n     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful.\n     */\n    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n        unchecked {\n            uint256 oldAllowance = token.allowance(address(this), spender);\n            require(oldAllowance >= value, \"SafeERC20: decreased allowance below zero\");\n            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));\n        }\n    }\n\n    /**\n     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval\n     * to be set to zero before setting it to a non-zero value, such as USDT.\n     */\n    function forceApprove(IERC20 token, address spender, uint256 value) internal {\n        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);\n\n        if (!_callOptionalReturnBool(token, approvalCall)) {\n            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));\n            _callOptionalReturn(token, approvalCall);\n        }\n    }\n\n    /**\n     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.\n     * Revert on invalid signature.\n     */\n    function safePermit(\n        IERC20Permit token,\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal {\n        uint256 nonceBefore = token.nonces(owner);\n        token.permit(owner, spender, value, deadline, v, r, s);\n        uint256 nonceAfter = token.nonces(owner);\n        require(nonceAfter == nonceBefore + 1, \"SafeERC20: permit did not succeed\");\n    }\n\n    /**\n     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n     * on the return value: the return value is optional (but if data is returned, it must not be false).\n     * @param token The token targeted by the call.\n     * @param data The call data (encoded using abi.encode or one of its variants).\n     */\n    function _callOptionalReturn(IERC20 token, bytes memory data) private {\n        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that\n        // the target address contains contract code and also asserts for success in the low-level call.\n\n        bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n        require(returndata.length == 0 || abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n    }\n\n    /**\n     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n     * on the return value: the return value is optional (but if data is returned, it must not be false).\n     * @param token The token targeted by the call.\n     * @param data The call data (encoded using abi.encode or one of its variants).\n     *\n     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.\n     */\n    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {\n        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false\n        // and not revert is the subcall reverts.\n\n        (bool success, bytes memory returndata) = address(token).call(data);\n        return\n            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));\n    }\n}\n"
      },
      "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `from` to `to` using the\n     * allowance mechanism. `amount` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 amount) external returns (bool);\n}\n"
      },
      "lib/openzeppelin-contracts/contracts/access/Ownable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    constructor() {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n}\n"
      },
      "src/interfaces/IExchangeConfig.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\nimport \"openzeppelin-contracts/contracts/finance/VestingWallet.sol\";\nimport \"../staking/interfaces/ILiquidity.sol\";\nimport \"../launch/interfaces/IInitialDistribution.sol\";\nimport \"../rewards/interfaces/IRewardsEmitter.sol\";\nimport \"../rewards/interfaces/ISaltRewards.sol\";\nimport \"../rewards/interfaces/IEmissions.sol\";\nimport \"../interfaces/IAccessManager.sol\";\nimport \"../launch/interfaces/IAirdrop.sol\";\nimport \"../dao/interfaces/IDAO.sol\";\nimport \"../interfaces/ISalt.sol\";\nimport \"./IUpkeep.sol\";\n\n\ninterface IExchangeConfig\n\t{\n\tfunction setContracts( IDAO _dao, IUpkeep _upkeep, IInitialDistribution _initialDistribution, VestingWallet _teamVestingWallet, VestingWallet _daoVestingWallet ) external; // onlyOwner\n\tfunction setAccessManager( IAccessManager _accessManager ) external; // onlyOwner\n\n\t// Views\n\tfunction salt() external view returns (ISalt);\n\tfunction wbtc() external view returns (IERC20);\n\tfunction weth() external view returns (IERC20);\n\tfunction usdc() external view returns (IERC20);\n\tfunction usdt() external view returns (IERC20);\n\n\tfunction daoVestingWallet() external view returns (VestingWallet);\n    function teamVestingWallet() external view returns (VestingWallet);\n    function initialDistribution() external view returns (IInitialDistribution);\n\n\tfunction accessManager() external view returns (IAccessManager);\n\tfunction dao() external view returns (IDAO);\n\tfunction upkeep() external view returns (IUpkeep);\n\tfunction teamWallet() external view returns (address);\n\n\tfunction walletHasAccess( address wallet ) external view returns (bool);\n\t}\n"
      },
      "src/arbitrage/ArbitrageSearch.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\nimport \"openzeppelin-contracts/contracts/utils/math/Math.sol\";\nimport \"../interfaces/IExchangeConfig.sol\";\nimport \"../pools/PoolUtils.sol\";\n\n// Finds a circular path after a user's swap has occurred (from WETH to WETH in this case) that results in an arbitrage profit.\nabstract contract ArbitrageSearch\n    {\n\tIERC20 immutable public weth;\n\tIERC20 immutable public usdc;\n\tIERC20 immutable public usdt;\n\n\n    constructor( IExchangeConfig _exchangeConfig )\n    \t{\n\t\t// Cached for efficiency\n\t\tweth = _exchangeConfig.weth();\n\t\tusdc = _exchangeConfig.usdc();\n\t\tusdt = _exchangeConfig.usdt();\n    \t}\n\n\n\t// Returns the middle two tokens in an arbitrage path that starts and ends with WETH.\n\t// The WETH tokens at the beginning and end of the path are not returned as they are always the same.\n\t// Full arbitrage cycle is: WETH->arbToken2->arbToken3->WETH\n\tfunction _arbitragePath( IERC20 swapTokenIn, IERC20 swapTokenOut ) internal view returns (IERC20 arbToken2, IERC20 arbToken3)\n\t\t{\n\t\t// swap: USDC->WETH\n        // arb: WETH->USDC->USDT->WETH\n\t\tif ( address(swapTokenIn) == address(usdc))\n\t\tif ( address(swapTokenOut) == address(weth))\n\t\t\treturn (usdc, usdt);\n\n\t\t// swap: WETH->USDC\n        // arb: WETH->USDT->USDC->WETH\n\t\tif ( address(swapTokenIn) == address(weth))\n\t\tif ( address(swapTokenOut) == address(usdc))\n\t\t\treturn (usdt, usdc);\n\n\t\t// swap: WETH->swapTokenOut\n        // arb: WETH->USDC->swapTokenOut->WETH\n\t\tif ( address(swapTokenIn) == address(weth))\n\t\t\treturn (usdc, swapTokenOut);\n\n\t\t// swap: swapTokenIn->WETH\n        // arb: WETH->swapTokenIn->USDC->WETH\n\t\tif ( address(swapTokenOut) == address(weth))\n\t\t\treturn (swapTokenIn, usdc);\n\n\t\t// swap: swapTokenIn->swapTokenOut\n        // arb: WETH->swapTokenOut->swapTokenIn->WETH\n\t\treturn (swapTokenOut, swapTokenIn);\n\t\t}\n\n\n\t// Determine the most significant bit of a non-zero number\n    function _mostSignificantBit(uint256 x) internal pure returns (uint256 msb)\n    \t{\n    \tunchecked\n    \t\t{\n\t\t\tif (x >= 2**128) { x >>= 128; msb += 128; }\n\t\t\tif (x >= 2**64) { x >>= 64; msb += 64; }\n\t\t\tif (x >= 2**32) { x >>= 32; msb += 32; }\n\t\t\tif (x >= 2**16) { x >>= 16; msb += 16; }\n\t\t\tif (x >= 2**8) { x >>= 8; msb += 8; }\n\t\t\tif (x >= 2**4) { x >>= 4; msb += 4; }\n\t\t\tif (x >= 2**2) { x >>= 2; msb += 2; }\n\t\t\tif (x >= 2**1) { x >>= 1; msb += 1; }\n\t\t\t}\n\t    }\n\n\n\t// Given that x, y and z will be multiplied: determine the bit shift necessary to keep the product contained in 240 bits\n\tfunction _shiftRequired( uint256 x, uint256 y, uint256 z ) internal pure returns (uint256)\n\t\t{\n\t\tunchecked\n\t\t\t{\n\t\t\t// Determine the maximum number of bits required without shifting\n\t\t\tuint256 requiredBits0 = _mostSignificantBit(x) + _mostSignificantBit(y) + _mostSignificantBit(z);\n\n\t\t\t// Already fits in 240?\n\t\t\tif ( requiredBits0 < 240 )\n\t\t\t\treturn 0;\n\n\t\t\t// Each number will be shifted so we can divide the required difference by 3\n\t\t\treturn Math.ceilDiv( requiredBits0 - 240, 3 );\n\t\t\t}\n\t\t}\n\n\n\t// Determine the shift required to keep a0 * b0 * c0 and a1 * b1 * c1 within 240 bits\n\tfunction _determineShift( uint256 a0, uint256 b0, uint256 c0, uint256 a1, uint256 b1, uint256 c1 ) internal pure returns (uint256)\n\t\t{\n\t\tuint256 shift0 = _shiftRequired(a0, b0, c0);\n\t\tuint256 shift1 = _shiftRequired(a1, b1, c1);\n\n\t\treturn shift0 > shift1 ? shift0 : shift1;\n\t\t}\n\n\n\tfunction _bestArbitrageIn( uint256 a0, uint256 a1, uint256 b0, uint256 b1, uint256 c0, uint256 c1 ) internal pure returns (uint256 bestArbAmountIn)\n\t\t{\n\t\t// This can be unchecked as the actual arbitrage that is performed when this is non-zero is checked and duplicates the check for profitability.\n\t\t// testArbitrageMethodsLarge() checks for proper behavior with extremely large reserves as well.\n\t\tunchecked\n\t\t\t{\n\t\t\t// Original derivation: https://github.com/code-423n4/2024-01-salty-findings/issues/419\n\t\t\t// uint256 n0 = A0 * B0 * C0;\n\t\t\t//\tuint256 n1 = A1 * B1 * C1;\n\t\t\t//\tif (n1 <= n0) return 0;\n\t\t\t//\n\t\t\t//\tuint256 m = A1 * B1 + C0 * B0 + C0 * A1;\n\t\t\t//\tuint256 z = Math.sqrt(A0 * C1);\n\t\t\t//\tz *= Math.sqrt(A1 * B0);\n\t\t\t//\tz *= Math.sqrt(B1 * C0);\n\t\t\t//\tbestArbAmountIn = (z - n0) / m;\n\n\t\t\t// Determine the shift required to keep a0 * b0 * c0 and a1 * b1 * c1 each within 240 bits\n\t\t\tuint256 shift = _determineShift( a0, b0, c0, a1, b1, c1 );\n\n\t\t\tif ( shift > 0 )\n\t\t\t\t{\n\t\t\t\ta0 = a0 >> shift;\n\t\t\t\ta1 = a1 >> shift;\n\t\t\t\tb0 = b0 >> shift;\n\t\t\t\tb1 = b1 >> shift;\n\t\t\t\tc0 = c0 >> shift;\n\t\t\t\tc1 = c1 >> shift;\n\t\t\t\t}\n\n\t\t\t// Each variable will use less than 80 bits\n\t\t\tuint256 n0 = a0 * b0 * c0;\n\t\t\tuint256 n1 = a1 * b1 * c1;\n\n\t\t\tif (n1 <= n0)\n\t\t\t\treturn 0;\n\n\t\t\tuint256 m = a1 *  b1 + c0 * ( b0 + a1 );\n\n\t\t\t// Calculating n0 * n1 directly would overflow under some situations.\n\t\t\t// Multiply the sqrt's instead - effectively keeping the max size the same\n\t\t\tuint256 z = Math.sqrt(n0) * Math.sqrt(n1);\n\n\t\t\tbestArbAmountIn = ( z - n0 ) / m;\n\t\t\tif ( bestArbAmountIn == 0 )\n\t\t\t\treturn 0;\n\n\t\t\t// Needed for the below arbitrage profit testing\n\t\t\tif ( shift > 0 )\n\t\t\t\t{\n\t\t\t\t// Convert back to normal scaling\n\t\t\t\tbestArbAmountIn = bestArbAmountIn << shift;\n\n\t\t\t\ta0 = a0 << shift;\n\t\t\t\ta1 = a1 << shift;\n\t\t\t\tb0 = b0 << shift;\n\t\t\t\tb1 = b1 << shift;\n\t\t\t\tc0 = c0 << shift;\n\t\t\t\tc1 = c1 << shift;\n\t\t\t\t}\n\n\t\t\t// Make sure bestArbAmountIn arbitrage is actually profitable (or else it will revert when actually performed in Pools.sol)\n\t\t\tuint256 amountOut = (a1 * bestArbAmountIn) / (a0 + bestArbAmountIn);\n\t\t\tamountOut = (b1 * amountOut) / (b0 + amountOut);\n\t\t\tamountOut = (c1 * amountOut) / (c0 + amountOut);\n\n\t\t\tif ( amountOut < bestArbAmountIn )\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t}"
      },
      "src/pools/interfaces/IPoolsConfig.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\nimport \"openzeppelin-contracts/contracts/token/ERC20/IERC20.sol\";\nimport \"./IPools.sol\";\n\n\ninterface IPoolsConfig\n\t{\n\tfunction whitelistPool( IERC20 tokenA, IERC20 tokenB ) external; // onlyOwner\n\tfunction unwhitelistPool( IERC20 tokenA, IERC20 tokenB ) external; // onlyOwner\n\tfunction changeMaximumWhitelistedPools(bool increase) external; // onlyOwner\n\n\t// Views\n    function maximumWhitelistedPools() external view returns (uint256);\n\n\tfunction numberOfWhitelistedPools() external view returns (uint256);\n\tfunction isWhitelisted( bytes32 poolID ) external view returns (bool);\n\tfunction whitelistedPools() external view returns (bytes32[] calldata);\n\tfunction underlyingTokenPair( bytes32 poolID ) external view returns (IERC20 tokenA, IERC20 tokenB);\n\n\t// Returns true if the token has been whitelisted (meaning it has been pooled with either WETH and USDC)\n\tfunction tokenHasBeenWhitelisted( IERC20 token, IERC20 weth, IERC20 usdc ) external view returns (bool);\n\t}"
      },
      "src/pools/interfaces/IPools.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\nimport \"../../staking/interfaces/ILiquidity.sol\";\nimport \"../../dao/interfaces/IDAO.sol\";\nimport \"./IPoolStats.sol\";\n\n\ninterface IPools is IPoolStats\n\t{\n\tfunction startExchangeApproved() external;\n\tfunction setContracts( IDAO _dao, ILiquidity _liquidity ) external; // onlyOwner\n\n\tfunction addLiquidity( IERC20 tokenA, IERC20 tokenB, uint256 maxAmountA, uint256 maxAmountB, uint256 minAddedAmountA, uint256 minAddedAmountB, uint256 totalLiquidity ) external returns (uint256 addedAmountA, uint256 addedAmountB, uint256 addedLiquidity);\n\tfunction removeLiquidity( IERC20 tokenA, IERC20 tokenB, uint256 liquidityToRemove, uint256 minReclaimedA, uint256 minReclaimedB, uint256 totalLiquidity ) external returns (uint256 reclaimedA, uint256 reclaimedB);\n\n\tfunction deposit( IERC20 token, uint256 amount ) external;\n\tfunction withdraw( IERC20 token, uint256 amount ) external;\n\tfunction swap( IERC20 swapTokenIn, IERC20 swapTokenOut, uint256 swapAmountIn, uint256 minAmountOut, uint256 deadline ) external returns (uint256 swapAmountOut);\n\tfunction depositSwapWithdraw(IERC20 swapTokenIn, IERC20 swapTokenOut, uint256 swapAmountIn, uint256 minAmountOut, uint256 deadline ) external returns (uint256 swapAmountOut);\n\tfunction depositDoubleSwapWithdraw( IERC20 swapTokenIn, IERC20 swapTokenMiddle, IERC20 swapTokenOut, uint256 swapAmountIn, uint256 minAmountOut, uint256 deadline ) external returns (uint256 swapAmountOut);\n\tfunction depositZapSwapWithdraw(IERC20 swapTokenIn, IERC20 swapTokenOut, uint256 swapAmountIn ) external returns (uint256 swapAmountOut);\n\n\t// Views\n\tfunction exchangeIsLive() external view returns (bool);\n\tfunction getPoolReserves(IERC20 tokenA, IERC20 tokenB) external view returns (uint256 reserveA, uint256 reserveB);\n\tfunction depositedUserBalance(address user, IERC20 token) external view returns (uint256);\n\t}\n\n"
      },
      "src/pools/PoolStats.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\nimport \"openzeppelin-contracts/contracts/token/ERC20/IERC20.sol\";\nimport \"../interfaces/IExchangeConfig.sol\";\nimport \"./interfaces/IPoolsConfig.sol\";\nimport \"./interfaces/IPoolStats.sol\";\nimport \"./PoolUtils.sol\";\n\n\n// Keeps track of the arbitrage profits generated by pools (for rewards distribution proportional to the profits generated per pool).\nabstract contract PoolStats is IPoolStats\n\t{\n\tuint64 constant INVALID_POOL_ID = type(uint64).max;\n\n\tIExchangeConfig immutable public exchangeConfig;\n\tIPoolsConfig immutable public poolsConfig;\n\tIERC20 immutable public _weth;\n\n\t// poolID(arbToken2, arbToken3) => arbitrage profits contributed since the last performUpkeep\n\tmapping(bytes32=>uint256) public _arbitrageProfits;\n\n\t// Maps poolID(arbToken2, arbToken3) => the indicies (within the whitelistedPools array) of the pools involved in WETH->arbToken2->arbToken3->WETH\n\tmapping(bytes32=>ArbitrageIndicies) public _arbitrageIndicies;\n\n\n    constructor( IExchangeConfig _exchangeConfig, IPoolsConfig _poolsConfig )\n    \t{\n\t\texchangeConfig = _exchangeConfig;\n\t\tpoolsConfig = _poolsConfig;\n\n\t\t_weth = exchangeConfig.weth();\n    \t}\n\n\n\t// Record that arbitrageProfit was generated and the a specific arbitrage path generated it (which is defined by the middle two tokens in WETH->arbToken2->arbToken3->WETH)\n\tfunction _updateProfitsFromArbitrage( IERC20 arbToken2, IERC20 arbToken3, uint256 arbitrageProfit ) internal\n\t\t{\n\t\t// Though three pools contributed to the arbitrage we can record just the middle one as we know the input and output token will be WETH\n\t\tbytes32 poolID = PoolUtils._poolID( arbToken2, arbToken3 );\n\n\t\t_arbitrageProfits[poolID] += arbitrageProfit;\n\t\t}\n\n\n\t// Called at the end of Upkeep.performUpkeep to reset the arbitrage stats for the pools\n\tfunction clearProfitsForPools() external\n\t\t{\n\t\trequire(msg.sender == address(exchangeConfig.upkeep()), \"PoolStats.clearProfitsForPools is only callable from the Upkeep contract\" );\n\n\t\tbytes32[] memory poolIDs = poolsConfig.whitelistedPools();\n\n\t\t// Don't fully set profits to zero to avoid the increased gas cost of overwriting zero\n\t\tfor( uint256 i = 0; i < poolIDs.length; i++ )\n\t\t\t_arbitrageProfits[ poolIDs[i] ] = 1;\n\t\t}\n\n\n\t// The index of pool tokenA/tokenB within the whitelistedPools array.\n\t// Should always find a value as only whitelisted pools are used in the arbitrage path.\n\t// Returns uint64.max in the event of failed lookup\n\tfunction _poolIndex( IERC20 tokenA, IERC20 tokenB, bytes32[] memory poolIDs ) internal pure returns (uint64 index)\n\t\t{\n\t\tbytes32 poolID = PoolUtils._poolID( tokenA, tokenB );\n\n\t\tfor( uint256 i = 0; i < poolIDs.length; i++ )\n\t\t\t{\n\t\t\tif (poolID == poolIDs[i])\n\t\t\t\treturn uint64(i);\n\t\t\t}\n\n\t\treturn INVALID_POOL_ID;\n\t\t}\n\n\n\t// Traverse the current whitelisted poolIDs and update the indicies of each pool that would contribute to arbitrage for it.\n\t// Maps poolID(arbToken2, arbToken3) => the indicies (within the whitelistedPools array) of the pools involved in WETH->arbToken2->arbToken3->WETH arbitrage.\n\tfunction updateArbitrageIndicies() public\n\t\t{\n\t\tbytes32[] memory poolIDs = poolsConfig.whitelistedPools();\n\n\t\tfor( uint256 i = 0; i < poolIDs.length; i++ )\n\t\t\t{\n\t\t\tbytes32 poolID = poolIDs[i];\n\t\t\t(IERC20 arbToken2, IERC20 arbToken3) = poolsConfig.underlyingTokenPair(poolID);\n\n\t\t\t// The middle two tokens can never be WETH in a valid arbitrage path as the path is WETH->arbToken2->arbToken3->WETH.\n\t\t\tif ( (arbToken2 != _weth) && (arbToken3 != _weth) )\n\t\t\t\t{\n\t\t\t\tuint64 poolIndex1 = _poolIndex( _weth, arbToken2, poolIDs );\n\t\t\t\tuint64 poolIndex2 = _poolIndex( arbToken2, arbToken3, poolIDs );\n\t\t\t\tuint64 poolIndex3 = _poolIndex( arbToken3, _weth, poolIDs );\n\n\t\t\t\t// Check if the indicies in storage have the correct values - and if not then update them\n\t\t\t\tArbitrageIndicies memory indicies = _arbitrageIndicies[poolID];\n\t\t\t\tif ( ( poolIndex1 != indicies.index1 ) || ( poolIndex2 != indicies.index2 ) || ( poolIndex3 != indicies.index3 ) )\n\t\t\t\t\t_arbitrageIndicies[poolID] = ArbitrageIndicies(poolIndex1, poolIndex2, poolIndex3);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\t// Examine the arbitrage that has been generated since the last Upkeep.performUpkeep call and credit the pools that have contributed towards it.\n\t// The calculated sums for each pool will then be used to proportionally distribute SALT rewards to each of the contributing pools.\n\tfunction _calculateArbitrageProfits( bytes32[] memory poolIDs, uint256[] memory _calculatedProfits ) internal view\n\t\t{\n\t\tfor( uint256 i = 0; i < poolIDs.length; i++ )\n\t\t\t{\n\t\t\t// references poolID(arbToken2, arbToken3) which defines the arbitage path of WETH->arbToken2->arbToken3->WETH\n\t\t\tbytes32 poolID = poolIDs[i];\n\n\t\t\t// Split the arbitrage profit between all the pools that contributed to generating the arbitrage for the referenced pool.\n\t\t\tuint256 arbitrageProfit = _arbitrageProfits[poolID] / 3;\n\t\t\tif ( arbitrageProfit > 0 )\n\t\t\t\t{\n\t\t\t\tArbitrageIndicies memory indicies = _arbitrageIndicies[poolID];\n\n\t\t\t\tif ( indicies.index1 != INVALID_POOL_ID )\n\t\t\t\t\t_calculatedProfits[indicies.index1] += arbitrageProfit;\n\n\t\t\t\tif ( indicies.index2 != INVALID_POOL_ID )\n\t\t\t\t\t_calculatedProfits[indicies.index2] += arbitrageProfit;\n\n\t\t\t\tif ( indicies.index3 != INVALID_POOL_ID )\n\t\t\t\t\t_calculatedProfits[indicies.index3] += arbitrageProfit;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\t// === VIEWS ===\n\n\t// Look at the arbitrage that has been generated since the last performUpkeep and determine how much each of the pools contributed to those generated profits.\n\t// Returns the profits for all of the current whitelisted pools\n\tfunction profitsForWhitelistedPools() external view returns (uint256[] memory _calculatedProfits)\n\t\t{\n\t\tbytes32[] memory poolIDs = poolsConfig.whitelistedPools();\n\n\t\t_calculatedProfits = new uint256[](poolIDs.length);\n\t\t_calculateArbitrageProfits( poolIDs, _calculatedProfits );\n\t\t}\n\n\n\tfunction arbitrageIndicies(bytes32 poolID) external view returns (ArbitrageIndicies memory)\n\t\t{\n\t\treturn _arbitrageIndicies[poolID];\n\t\t}\n\t}"
      },
      "src/pools/PoolUtils.sol": {
        "content": "pragma solidity =0.8.22;\n\nimport \"openzeppelin-contracts/contracts/token/ERC20/IERC20.sol\";\n\n\nlibrary PoolUtils\n\t{\n\t// Token reserves less than dust are treated as if they don't exist at all.\n\t// With the 18 decimals that are used for most tokens, DUST has a value of 0.0000000000000001\n\tuint256 constant public DUST = 100;\n\n\t// A special pool that represents staked SALT that is not associated with any actual liquidity pool.\n    bytes32 constant public STAKED_SALT = bytes32(0);\n\n\n    // Return the unique poolID for the given two tokens.\n    // Tokens are sorted before being hashed to make reversed pairs equivalent.\n    function _poolID( IERC20 tokenA, IERC20 tokenB ) internal pure returns (bytes32 poolID)\n    \t{\n        // See if the token orders are flipped\n        if ( uint160(address(tokenB)) < uint160(address(tokenA)) )\n            return keccak256(abi.encodePacked(address(tokenB), address(tokenA)));\n\n        return keccak256(abi.encodePacked(address(tokenA), address(tokenB)));\n    \t}\n\n\n    // Return the unique poolID and whether or not it is flipped\n    function _poolIDAndFlipped( IERC20 tokenA, IERC20 tokenB ) internal pure returns (bytes32 poolID, bool flipped)\n    \t{\n        // See if the token orders are flipped\n        if ( uint160(address(tokenB)) < uint160(address(tokenA)) )\n            return (keccak256(abi.encodePacked(address(tokenB), address(tokenA))), true);\n\n        return (keccak256(abi.encodePacked(address(tokenA), address(tokenB))), false);\n    \t}\n\t}\n"
      },
      "lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n */\ninterface IERC20Permit {\n    /**\n     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\n     * given ``owner``'s signed approval.\n     *\n     * IMPORTANT: The same issues {IERC20-approve} has related to transaction\n     * ordering also apply here.\n     *\n     * Emits an {Approval} event.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     * - `deadline` must be a timestamp in the future.\n     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\n     * over the EIP712-formatted function arguments.\n     * - the signature must use ``owner``'s current nonce (see {nonces}).\n     *\n     * For more information on the signature format, see the\n     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\n     * section].\n     */\n    function permit(\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external;\n\n    /**\n     * @dev Returns the current nonce for `owner`. This value must be\n     * included whenever a signature is generated for {permit}.\n     *\n     * Every successful call to {permit} increases ``owner``'s nonce by one. This\n     * prevents a signature from being used multiple times.\n     */\n    function nonces(address owner) external view returns (uint256);\n\n    /**\n     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\n     */\n    // solhint-disable-next-line func-name-mixedcase\n    function DOMAIN_SEPARATOR() external view returns (bytes32);\n}\n"
      },
      "lib/openzeppelin-contracts/contracts/utils/Address.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length > 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance >= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length > 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n"
      },
      "lib/openzeppelin-contracts/contracts/utils/Context.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n}\n"
      },
      "lib/openzeppelin-contracts/contracts/finance/VestingWallet.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (finance/VestingWallet.sol)\npragma solidity ^0.8.0;\n\nimport \"../token/ERC20/utils/SafeERC20.sol\";\nimport \"../utils/Address.sol\";\nimport \"../utils/Context.sol\";\n\n/**\n * @title VestingWallet\n * @dev This contract handles the vesting of Eth and ERC20 tokens for a given beneficiary. Custody of multiple tokens\n * can be given to this contract, which will release the token to the beneficiary following a given vesting schedule.\n * The vesting schedule is customizable through the {vestedAmount} function.\n *\n * Any token transferred to this contract will follow the vesting schedule as if they were locked from the beginning.\n * Consequently, if the vesting has already started, any amount of tokens sent to this contract will (at least partly)\n * be immediately releasable.\n */\ncontract VestingWallet is Context {\n    event EtherReleased(uint256 amount);\n    event ERC20Released(address indexed token, uint256 amount);\n\n    uint256 private _released;\n    mapping(address => uint256) private _erc20Released;\n    address private immutable _beneficiary;\n    uint64 private immutable _start;\n    uint64 private immutable _duration;\n\n    /**\n     * @dev Set the beneficiary, start timestamp and vesting duration of the vesting wallet.\n     */\n    constructor(address beneficiaryAddress, uint64 startTimestamp, uint64 durationSeconds) payable {\n        require(beneficiaryAddress != address(0), \"VestingWallet: beneficiary is zero address\");\n        _beneficiary = beneficiaryAddress;\n        _start = startTimestamp;\n        _duration = durationSeconds;\n    }\n\n    /**\n     * @dev The contract should be able to receive Eth.\n     */\n    receive() external payable virtual {}\n\n    /**\n     * @dev Getter for the beneficiary address.\n     */\n    function beneficiary() public view virtual returns (address) {\n        return _beneficiary;\n    }\n\n    /**\n     * @dev Getter for the start timestamp.\n     */\n    function start() public view virtual returns (uint256) {\n        return _start;\n    }\n\n    /**\n     * @dev Getter for the vesting duration.\n     */\n    function duration() public view virtual returns (uint256) {\n        return _duration;\n    }\n\n    /**\n     * @dev Amount of eth already released\n     */\n    function released() public view virtual returns (uint256) {\n        return _released;\n    }\n\n    /**\n     * @dev Amount of token already released\n     */\n    function released(address token) public view virtual returns (uint256) {\n        return _erc20Released[token];\n    }\n\n    /**\n     * @dev Getter for the amount of releasable eth.\n     */\n    function releasable() public view virtual returns (uint256) {\n        return vestedAmount(uint64(block.timestamp)) - released();\n    }\n\n    /**\n     * @dev Getter for the amount of releasable `token` tokens. `token` should be the address of an\n     * IERC20 contract.\n     */\n    function releasable(address token) public view virtual returns (uint256) {\n        return vestedAmount(token, uint64(block.timestamp)) - released(token);\n    }\n\n    /**\n     * @dev Release the native token (ether) that have already vested.\n     *\n     * Emits a {EtherReleased} event.\n     */\n    function release() public virtual {\n        uint256 amount = releasable();\n        _released += amount;\n        emit EtherReleased(amount);\n        Address.sendValue(payable(beneficiary()), amount);\n    }\n\n    /**\n     * @dev Release the tokens that have already vested.\n     *\n     * Emits a {ERC20Released} event.\n     */\n    function release(address token) public virtual {\n        uint256 amount = releasable(token);\n        _erc20Released[token] += amount;\n        emit ERC20Released(token, amount);\n        SafeERC20.safeTransfer(IERC20(token), beneficiary(), amount);\n    }\n\n    /**\n     * @dev Calculates the amount of ether that has already vested. Default implementation is a linear vesting curve.\n     */\n    function vestedAmount(uint64 timestamp) public view virtual returns (uint256) {\n        return _vestingSchedule(address(this).balance + released(), timestamp);\n    }\n\n    /**\n     * @dev Calculates the amount of tokens that has already vested. Default implementation is a linear vesting curve.\n     */\n    function vestedAmount(address token, uint64 timestamp) public view virtual returns (uint256) {\n        return _vestingSchedule(IERC20(token).balanceOf(address(this)) + released(token), timestamp);\n    }\n\n    /**\n     * @dev Virtual implementation of the vesting formula. This returns the amount vested, as a function of time, for\n     * an asset given its total historical allocation.\n     */\n    function _vestingSchedule(uint256 totalAllocation, uint64 timestamp) internal view virtual returns (uint256) {\n        if (timestamp < start()) {\n            return 0;\n        } else if (timestamp > start() + duration()) {\n            return totalAllocation;\n        } else {\n            return (totalAllocation * (timestamp - start())) / duration();\n        }\n    }\n}\n"
      },
      "src/staking/interfaces/ILiquidity.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\nimport \"openzeppelin-contracts/contracts/token/ERC20/IERC20.sol\";\nimport \"./IStakingRewards.sol\";\n\n\ninterface ILiquidity is IStakingRewards\n\t{\n\tfunction depositLiquidityAndIncreaseShare( IERC20 tokenA, IERC20 tokenB, uint256 maxAmountA, uint256 maxAmountB, uint256 minAddedAmountA, uint256 minAddedAmountB, uint256 minAddedLiquidity, uint256 deadline, bool useZapping ) external returns (uint256 addedLiquidity);\n\tfunction withdrawLiquidityAndClaim( IERC20 tokenA, IERC20 tokenB, uint256 liquidityToWithdraw, uint256 minReclaimedA, uint256 minReclaimedB, uint256 deadline ) external returns (uint256 reclaimedA, uint256 reclaimedB);\n\t}\n"
      },
      "src/launch/interfaces/IInitialDistribution.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\nimport \"./IBootstrapBallot.sol\";\nimport \"./IAirdrop.sol\";\n\n\ninterface IInitialDistribution\n\t{\n\tfunction distributionApproved( IAirdrop airdrop1, IAirdrop airdrop2 ) external;\n\n\t// Views\n\tfunction bootstrapBallot() external view returns (IBootstrapBallot);\n\t}\n"
      },
      "src/rewards/interfaces/IRewardsEmitter.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\nimport \"../../staking/interfaces/IStakingRewards.sol\";\n\n\ninterface IRewardsEmitter\n\t{\n\tfunction addSALTRewards( AddedReward[] calldata addedRewards ) external;\n\tfunction performUpkeep( uint256 timeSinceLastUpkeep ) external;\n\n\t// Views\n\tfunction pendingRewardsForPools( bytes32[] calldata pools ) external view returns (uint256[] calldata);\n\t}\n"
      },
      "src/rewards/interfaces/ISaltRewards.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\nimport \"./IRewardsEmitter.sol\";\n\n\ninterface ISaltRewards\n\t{\n\tfunction sendInitialSaltRewards( uint256 liquidityBootstrapAmount, bytes32[] calldata poolIDs ) external;\n    function performUpkeep( bytes32[] calldata poolIDs, uint256[] calldata profitsForPools ) external;\n\n    // Views\n    function stakingRewardsEmitter() external view returns (IRewardsEmitter);\n    function liquidityRewardsEmitter() external view returns (IRewardsEmitter);\n    }"
      },
      "src/rewards/interfaces/IEmissions.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\n\ninterface IEmissions\n\t{\n\tfunction performUpkeep( uint256 timeSinceLastUpkeep ) external;\n    }"
      },
      "src/interfaces/IAccessManager.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\n\ninterface IAccessManager\n\t{\n\tfunction excludedCountriesUpdated() external;\n\tfunction grantAccess(bytes calldata signature) external;\n\n\t// Views\n\tfunction geoVersion() external view returns (uint256);\n\tfunction walletHasAccess(address wallet) external view returns (bool);\n\t}\n"
      },
      "src/launch/interfaces/IAirdrop.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\n\ninterface IAirdrop\n\t{\n\tfunction authorizeWallet( address wallet, uint256 saltAmount ) external;\n\tfunction allowClaiming() external;\n\tfunction claim() external;\n\n\t// Views\n\tfunction claimedByUser( address wallet) external view returns (uint256);\n\tfunction claimingAllowed() external view returns (bool);\n\tfunction claimingStartTimestamp() external view returns (uint256);\n\tfunction claimableAmount(address wallet) external view returns (uint256);\n    function airdropForUser( address wallet ) external view returns (uint256);\n\t}\n"
      },
      "src/dao/interfaces/IDAO.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\nimport \"../../rewards/interfaces/ISaltRewards.sol\";\nimport \"../../pools/interfaces/IPools.sol\";\nimport \"../../interfaces/ISalt.sol\";\n\ninterface IDAO\n\t{\n\tfunction finalizeBallot( uint256 ballotID ) external;\n\tfunction manuallyRemoveBallot( uint256 ballotID ) external;\n\n\tfunction withdrawFromDAO( IERC20 token ) external returns (uint256 withdrawnAmount);\n\n\t// Views\n\tfunction pools() external view returns (IPools);\n\tfunction websiteURL() external view returns (string memory);\n\tfunction countryIsExcluded( string calldata country ) external view returns (bool);\n\t}"
      },
      "src/interfaces/ISalt.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\nimport \"openzeppelin-contracts/contracts/token/ERC20/IERC20.sol\";\n\n\ninterface ISalt is IERC20\n\t{\n\tfunction burnTokensInContract() external;\n\n\t// Views\n\tfunction totalBurned() external view returns (uint256);\n\t}\n"
      },
      "src/interfaces/IUpkeep.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\n\ninterface IUpkeep\n\t{\n\tfunction performUpkeep() external;\n\n\t// Views\n\tfunction currentRewardsForCallingPerformUpkeep() external view returns (uint256);\n\tfunction lastUpkeepTimeEmissions() external view returns (uint256);\n\tfunction lastUpkeepTimeRewardsEmitters() external view returns (uint256);\n\t}\n"
      },
      "lib/openzeppelin-contracts/contracts/utils/math/Math.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n    enum Rounding {\n        Down, // Toward negative infinity\n        Up, // Toward infinity\n        Zero // Toward zero\n    }\n\n    /**\n     * @dev Returns the largest of two numbers.\n     */\n    function max(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a > b ? a : b;\n    }\n\n    /**\n     * @dev Returns the smallest of two numbers.\n     */\n    function min(uint256 a, uint256 b) internal pure returns (uint256) {\n        return a < b ? a : b;\n    }\n\n    /**\n     * @dev Returns the average of two numbers. The result is rounded towards\n     * zero.\n     */\n    function average(uint256 a, uint256 b) internal pure returns (uint256) {\n        // (a + b) / 2 can overflow.\n        return (a & b) + (a ^ b) / 2;\n    }\n\n    /**\n     * @dev Returns the ceiling of the division of two numbers.\n     *\n     * This differs from standard division with `/` in that it rounds up instead\n     * of rounding down.\n     */\n    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n        // (a + b - 1) / b can overflow on addition, so we distribute.\n        return a == 0 ? 0 : (a - 1) / b + 1;\n    }\n\n    /**\n     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)\n     * with further edits by Uniswap Labs also under MIT license.\n     */\n    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {\n        unchecked {\n            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\n            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n            // variables such that product = prod1 * 2^256 + prod0.\n            uint256 prod0; // Least significant 256 bits of the product\n            uint256 prod1; // Most significant 256 bits of the product\n            assembly {\n                let mm := mulmod(x, y, not(0))\n                prod0 := mul(x, y)\n                prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n            }\n\n            // Handle non-overflow cases, 256 by 256 division.\n            if (prod1 == 0) {\n                // Solidity will revert if denominator == 0, unlike the div opcode on its own.\n                // The surrounding unchecked block does not change this fact.\n                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.\n                return prod0 / denominator;\n            }\n\n            // Make sure the result is less than 2^256. Also prevents denominator == 0.\n            require(denominator > prod1, \"Math: mulDiv overflow\");\n\n            ///////////////////////////////////////////////\n            // 512 by 256 division.\n            ///////////////////////////////////////////////\n\n            // Make division exact by subtracting the remainder from [prod1 prod0].\n            uint256 remainder;\n            assembly {\n                // Compute remainder using mulmod.\n                remainder := mulmod(x, y, denominator)\n\n                // Subtract 256 bit number from 512 bit number.\n                prod1 := sub(prod1, gt(remainder, prod0))\n                prod0 := sub(prod0, remainder)\n            }\n\n            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.\n            // See https://cs.stackexchange.com/q/138556/92363.\n\n            // Does not overflow because the denominator cannot be zero at this stage in the function.\n            uint256 twos = denominator & (~denominator + 1);\n            assembly {\n                // Divide denominator by twos.\n                denominator := div(denominator, twos)\n\n                // Divide [prod1 prod0] by twos.\n                prod0 := div(prod0, twos)\n\n                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\n                twos := add(div(sub(0, twos), twos), 1)\n            }\n\n            // Shift in bits from prod1 into prod0.\n            prod0 |= prod1 * twos;\n\n            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n            // four bits. That is, denominator * inv = 1 mod 2^4.\n            uint256 inverse = (3 * denominator) ^ 2;\n\n            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works\n            // in modular arithmetic, doubling the correct bits in each step.\n            inverse *= 2 - denominator * inverse; // inverse mod 2^8\n            inverse *= 2 - denominator * inverse; // inverse mod 2^16\n            inverse *= 2 - denominator * inverse; // inverse mod 2^32\n            inverse *= 2 - denominator * inverse; // inverse mod 2^64\n            inverse *= 2 - denominator * inverse; // inverse mod 2^128\n            inverse *= 2 - denominator * inverse; // inverse mod 2^256\n\n            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\n            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\n            // is no longer required.\n            result = prod0 * inverse;\n            return result;\n        }\n    }\n\n    /**\n     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\n     */\n    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {\n        uint256 result = mulDiv(x, y, denominator);\n        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {\n            result += 1;\n        }\n        return result;\n    }\n\n    /**\n     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.\n     *\n     * Inspired by Henry S. Warren, Jr.'s \"Hacker's Delight\" (Chapter 11).\n     */\n    function sqrt(uint256 a) internal pure returns (uint256) {\n        if (a == 0) {\n            return 0;\n        }\n\n        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n        //\n        // We know that the \"msb\" (most significant bit) of our target number `a` is a power of 2 such that we have\n        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n        //\n        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n        //\n        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n        uint256 result = 1 << (log2(a) >> 1);\n\n        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n        // into the expected uint128 result.\n        unchecked {\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            result = (result + a / result) >> 1;\n            return min(result, a / result);\n        }\n    }\n\n    /**\n     * @notice Calculates sqrt(a), following the selected rounding direction.\n     */\n    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = sqrt(a);\n            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 2, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log2(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >> 128 > 0) {\n                value >>= 128;\n                result += 128;\n            }\n            if (value >> 64 > 0) {\n                value >>= 64;\n                result += 64;\n            }\n            if (value >> 32 > 0) {\n                value >>= 32;\n                result += 32;\n            }\n            if (value >> 16 > 0) {\n                value >>= 16;\n                result += 16;\n            }\n            if (value >> 8 > 0) {\n                value >>= 8;\n                result += 8;\n            }\n            if (value >> 4 > 0) {\n                value >>= 4;\n                result += 4;\n            }\n            if (value >> 2 > 0) {\n                value >>= 2;\n                result += 2;\n            }\n            if (value >> 1 > 0) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log2(value);\n            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 10, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log10(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >= 10 ** 64) {\n                value /= 10 ** 64;\n                result += 64;\n            }\n            if (value >= 10 ** 32) {\n                value /= 10 ** 32;\n                result += 32;\n            }\n            if (value >= 10 ** 16) {\n                value /= 10 ** 16;\n                result += 16;\n            }\n            if (value >= 10 ** 8) {\n                value /= 10 ** 8;\n                result += 8;\n            }\n            if (value >= 10 ** 4) {\n                value /= 10 ** 4;\n                result += 4;\n            }\n            if (value >= 10 ** 2) {\n                value /= 10 ** 2;\n                result += 2;\n            }\n            if (value >= 10 ** 1) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log10(value);\n            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);\n        }\n    }\n\n    /**\n     * @dev Return the log in base 256, rounded down, of a positive value.\n     * Returns 0 if given 0.\n     *\n     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n     */\n    function log256(uint256 value) internal pure returns (uint256) {\n        uint256 result = 0;\n        unchecked {\n            if (value >> 128 > 0) {\n                value >>= 128;\n                result += 16;\n            }\n            if (value >> 64 > 0) {\n                value >>= 64;\n                result += 8;\n            }\n            if (value >> 32 > 0) {\n                value >>= 32;\n                result += 4;\n            }\n            if (value >> 16 > 0) {\n                value >>= 16;\n                result += 2;\n            }\n            if (value >> 8 > 0) {\n                result += 1;\n            }\n        }\n        return result;\n    }\n\n    /**\n     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.\n     * Returns 0 if given 0.\n     */\n    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n        unchecked {\n            uint256 result = log256(value);\n            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);\n        }\n    }\n}\n"
      },
      "src/pools/interfaces/IPoolStats.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\n\ninterface IPoolStats\n\t{\n\t// These are the indicies (in terms of a poolIDs location in the current whitelistedPoolIDs array) of pools involved in an arbitrage path\n\tstruct ArbitrageIndicies\n\t\t{\n\t\tuint64 index1;\n\t\tuint64 index2;\n\t\tuint64 index3;\n\t\t}\n\n\tfunction clearProfitsForPools() external;\n\tfunction updateArbitrageIndicies() external;\n\n\t// Views\n\tfunction profitsForWhitelistedPools() external view returns (uint256[] memory _calculatedProfits);\n\tfunction arbitrageIndicies(bytes32 poolID) external view returns (ArbitrageIndicies memory);\n\t}\n\n"
      },
      "src/staking/interfaces/IStakingRewards.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\n\nstruct AddedReward\n\t{\n\tbytes32 poolID;\t\t\t\t\t\t\t// The pool to add rewards to\n\tuint256 amountToAdd;\t\t\t\t// The amount of rewards (as SALT) to add\n\t}\n\nstruct UserShareInfo\n\t{\n\tuint256 userShare;\t\t\t\t\t// A user's share for a given poolID\n\tuint256 virtualRewards;\t\t\t\t// The amount of rewards that were added to maintain proper rewards/share ratio - and will be deducted from a user's pending rewards.\n\tuint256 cooldownExpiration;\t\t// The timestamp when the user can modify their share\n\t}\n\n\ninterface IStakingRewards\n\t{\n\tfunction claimAllRewards( bytes32[] calldata poolIDs ) external returns (uint256 rewardsAmount);\n\tfunction addSALTRewards( AddedReward[] calldata addedRewards ) external;\n\n\t// Views\n\tfunction totalShares(bytes32 poolID) external view returns (uint256);\n\tfunction totalSharesForPools( bytes32[] calldata poolIDs ) external view returns (uint256[] calldata shares);\n\tfunction totalRewardsForPools( bytes32[] calldata poolIDs ) external view returns (uint256[] calldata rewards);\n\n\tfunction userRewardForPool( address wallet, bytes32 poolID ) external view returns (uint256);\n\tfunction userShareForPool( address wallet, bytes32 poolID ) external view returns (uint256);\n\tfunction userVirtualRewardsForPool( address wallet, bytes32 poolID ) external view returns (uint256);\n\n\tfunction userRewardsForPools( address wallet, bytes32[] calldata poolIDs ) external view returns (uint256[] calldata rewards);\n\tfunction userShareForPools( address wallet, bytes32[] calldata poolIDs ) external view returns (uint256[] calldata shares);\n\tfunction userCooldowns( address wallet, bytes32[] calldata poolIDs ) external view returns (uint256[] calldata cooldowns);\n\t}\n"
      },
      "src/launch/interfaces/IBootstrapBallot.sol": {
        "content": "// SPDX-License-Identifier: BUSL 1.1\npragma solidity =0.8.22;\n\n\ninterface IBootstrapBallot\n\t{\n\tfunction vote( bool voteStartExchangeYes, uint256 saltAmount, bytes calldata signature ) external;\n\tfunction finalizeBallot() external;\n\n\tfunction authorizeAirdrop2( uint256 saltAmount, bytes calldata signature ) external;\n\tfunction finalizeAirdrop2() external;\n\n\t// Views\n\tfunction claimableTimestamp1() external view returns (uint256);\n\tfunction claimableTimestamp2() external view returns (uint256);\n\n\tfunction hasVoted(address user) external view returns (bool);\n\tfunction ballotFinalized() external view returns (bool);\n\n\tfunction startExchangeYes() external view returns (uint256);\n\tfunction startExchangeNo() external view returns (uint256);\n\t}\n"
      }
    },
    "settings": {
      "remappings": [
        "chainlink/=lib/chainlink/",
        "ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
        "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
        "forge-std/=lib/openzeppelin-contracts/lib/forge-std/src/",
        "openzeppelin-contracts/=lib/openzeppelin-contracts/",
        "openzeppelin/=lib/openzeppelin-contracts/contracts/",
        "v3-core/=lib/v3-core/contracts/"
      ],
      "optimizer": {
        "enabled": true,
        "runs": 10000
      },
      "metadata": {
        "useLiteralContent": false,
        "bytecodeHash": "ipfs",
        "appendCBOR": true
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "evmVersion": "paris",
      "libraries": {}
    }
  }}