ETH Price: $3,382.17 (-1.89%)
Gas: 3 Gwei

Contract

0xf5D65d370141f1fff0Db646c9406Ce051354A8a5
 

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Value
Deposit Swap Wit...201247942024-06-19 9:08:4713 days ago1718788127IN
0xf5D65d37...51354A8a5
0 ETH0.000656895.33466196
Deposit Swap Wit...201234222024-06-19 4:31:1113 days ago1718771471IN
0xf5D65d37...51354A8a5
0 ETH0.000563714.39920272
Deposit Swap Wit...201178442024-06-18 9:46:1114 days ago1718703971IN
0xf5D65d37...51354A8a5
0 ETH0.000587115.22777437
Deposit Double S...201172362024-06-18 7:43:1114 days ago1718696591IN
0xf5D65d37...51354A8a5
0 ETH0.000924166.51456455
Deposit Double S...201101542024-06-17 7:55:4715 days ago1718610947IN
0xf5D65d37...51354A8a5
0 ETH0.00041793.34962838
Deposit Double S...201101172024-06-17 7:48:2315 days ago1718610503IN
0xf5D65d37...51354A8a5
0 ETH0.000505573.04791828
Deposit Swap Wit...201100172024-06-17 7:27:5915 days ago1718609279IN
0xf5D65d37...51354A8a5
0 ETH0.000414743.24242283
Deposit Swap Wit...201093752024-06-17 5:18:4715 days ago1718601527IN
0xf5D65d37...51354A8a5
0 ETH0.00025362.63123361
Deposit Swap Wit...201078262024-06-17 0:07:2316 days ago1718582843IN
0xf5D65d37...51354A8a5
0 ETH0.000377623.72525022
Deposit Swap Wit...201075782024-06-16 23:17:3516 days ago1718579855IN
0xf5D65d37...51354A8a5
0 ETH0.000259472.6921649
Deposit Swap Wit...201071972024-06-16 22:00:3516 days ago1718575235IN
0xf5D65d37...51354A8a5
0 ETH0.000452373.67405205
Deposit Swap Wit...201063732024-06-16 19:14:3516 days ago1718565275IN
0xf5D65d37...51354A8a5
0 ETH0.000475573.5435584
Deposit Double S...201052292024-06-16 15:24:1116 days ago1718551451IN
0xf5D65d37...51354A8a5
0 ETH0.000878585.17026492
Deposit Double S...201034572024-06-16 9:28:2316 days ago1718530103IN
0xf5D65d37...51354A8a5
0 ETH0.000595874.19199628
Deposit Double S...201013702024-06-16 2:29:3516 days ago1718504975IN
0xf5D65d37...51354A8a5
0 ETH0.000410412.79503133
Deposit Swap Wit...200999852024-06-15 21:50:3517 days ago1718488235IN
0xf5D65d37...51354A8a5
0 ETH0.000390933.17441829
Deposit Double S...200967082024-06-15 10:50:4717 days ago1718448647IN
0xf5D65d37...51354A8a5
0 ETH0.00064034.01451008
Deposit Double S...200965972024-06-15 10:28:3517 days ago1718447315IN
0xf5D65d37...51354A8a5
0 ETH0.000601593.70834856
Deposit Swap Wit...200950212024-06-15 5:09:3517 days ago1718428175IN
0xf5D65d37...51354A8a5
0 ETH0.000547025.67566306
Deposit Swap Wit...200945382024-06-15 3:31:2317 days ago1718422283IN
0xf5D65d37...51354A8a5
0 ETH0.000452013.97652927
Deposit Double S...200941252024-06-15 2:08:2318 days ago1718417303IN
0xf5D65d37...51354A8a5
0 ETH0.000568173.68367564
Deposit Double S...200937862024-06-15 1:00:1118 days ago1718413211IN
0xf5D65d37...51354A8a5
0 ETH0.000616324.06474503
Deposit Swap Wit...200882642024-06-14 6:30:2318 days ago1718346623IN
0xf5D65d37...51354A8a5
0 ETH0.000823127.41285093
Deposit Swap Wit...200862932024-06-13 23:53:1119 days ago1718322791IN
0xf5D65d37...51354A8a5
0 ETH0.000881537.15895492
Deposit Double S...200740552024-06-12 6:48:2320 days ago1718174903IN
0xf5D65d37...51354A8a5
0 ETH0.000832245.66032719
View all transactions

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0xF3B07e39...bDbC32077
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
Pools

Compiler Version
v0.8.22+commit.4fc1097e

Optimization Enabled:
Yes with 10000 runs

Other Settings:
paris EvmVersion
File 1 of 29 : Pools.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;

import "openzeppelin-contracts/contracts/security/ReentrancyGuard.sol";
import "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import "openzeppelin-contracts/contracts/access/Ownable.sol";
import "../interfaces/IExchangeConfig.sol";
import "../arbitrage/ArbitrageSearch.sol";
import "./interfaces/IPoolsConfig.sol";
import "./interfaces/IPools.sol";
import "./PoolStats.sol";
import "./PoolUtils.sol";


// The Pools contract stores the reserves that are used for swaps within the DEX.
// It handles deposits, arbitrage, and keeps stats for proportional rewards distribution to the liquidity providers.
//
// Only the Liquidity contract can actually call addLiquidity and removeLiquidity.
// User liquidity accounting is done by Liquidity (via its derivation of StakingRewards).

contract Pools is IPools, ReentrancyGuard, PoolStats, ArbitrageSearch, Ownable
	{
	event LiquidityAdded(IERC20 indexed tokenA, IERC20 indexed tokenB, uint256 addedAmountA, uint256 addedAmountB, uint256 addedLiquidity);
	event LiquidityRemoved(IERC20 indexed tokenA, IERC20 indexed tokenB, uint256 reclaimedA, uint256 reclaimedB, uint256 removedLiquidity);
	event TokenDeposit(address indexed user, IERC20 indexed token, uint256 amount);
	event TokenWithdrawal(address indexed user, IERC20 indexed token, uint256 amount);
	event SwapAndArbitrage(address indexed user, IERC20 indexed swapTokenIn, IERC20 indexed swapTokenOut, uint256 swapAmountIn, uint256 swapAmountOut, uint256 arbitrageProfit);

	using SafeERC20 for IERC20;

	struct PoolReserves
		{
		uint128 reserve0;						// The token reserves such that address(token0) < address(token1)
		uint128 reserve1;
		}


	IDAO public dao;
	ILiquidity public liquidity;
	ISalt public salt;

	// Set to true when starting the exchange is approved by the bootstrapBallot
	bool public exchangeIsLive;

	// Keeps track of the pool reserves by poolID
	mapping(bytes32=>PoolReserves) private _poolReserves;

	// User token balances for deposited tokens
	mapping(address=>mapping(IERC20=>uint256)) private _userDeposits;

	// 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.
	mapping(address => uint) private lastSwappedBlocks;


	constructor( IExchangeConfig _exchangeConfig, IPoolsConfig _poolsConfig )
	ArbitrageSearch(_exchangeConfig)
	PoolStats(_exchangeConfig, _poolsConfig)
		{
		salt = _exchangeConfig.salt();
		}


	// Allow users to make only one swap per block
	modifier oneUserSwapPerBlock()
		{
		require(lastSwappedBlocks[msg.sender] != block.number, "User already swapped in this block");
        _;
        lastSwappedBlocks[msg.sender] = block.number;
        }


	modifier ensureNotExpired(uint256 deadline)
		{
		require(block.timestamp <= deadline, "TX EXPIRED");
		_;
		}


	// This will be called only once - at deployment time
	function setContracts( IDAO _dao, ILiquidity _liquidity ) external onlyOwner
		{
		dao = _dao;
		liquidity = _liquidity;

		// setContracts can only be called once
		renounceOwnership();
		}


	function startExchangeApproved() external nonReentrant
		{
    	require( msg.sender == address(exchangeConfig.initialDistribution().bootstrapBallot()), "Pools.startExchangeApproved can only be called from the BootstrapBallot contract" );

		// Make sure that the arbitrage indicies for the whitelisted pools are updated before starting the exchange
		updateArbitrageIndicies();

		exchangeIsLive = true;
		}


	// Add the given amount of two tokens to the specified liquidity pool.
	// The maximum amount of tokens is added while having the added amount have the same ratio as the current reserves.
	function _addLiquidity( bytes32 poolID, uint256 maxAmount0, uint256 maxAmount1, uint256 totalLiquidity ) internal returns(uint256 addedAmount0, uint256 addedAmount1, uint256 addedLiquidity)
		{
		PoolReserves storage reserves = _poolReserves[poolID];
		uint256 reserve0 = reserves.reserve0;
		uint256 reserve1 = reserves.reserve1;

		// If either reserve is zero then consider the pool to be empty and that the added liquidity will become the initial token ratio
		if ( ( reserve0 == 0 ) || ( reserve1 == 0 ) )
			{
			// Update the reserves
			reserves.reserve0 += uint128(maxAmount0);
			reserves.reserve1 += uint128(maxAmount1);

			// Default liquidity will be the addition of both maxAmounts in case one of them is much smaller (has smaller decimals)
			return ( maxAmount0, maxAmount1, (maxAmount0 + maxAmount1) );
			}

		// Add liquidity to the pool proportional to the current existing token reserves in the pool.
		// First, try the proportional amount of tokenB for the given maxAmountA
		uint256 proportionalB = ( maxAmount0 * reserve1 ) / reserve0;

		// proportionalB too large for the specified maxAmountB?
		if ( proportionalB > maxAmount1 )
			{
			// Use maxAmountB and a proportional amount for tokenA instead
			addedAmount0 = ( maxAmount1 * reserve0 ) / reserve1;
			addedAmount1 = maxAmount1;
			}
		else
			{
			addedAmount0 = maxAmount0;
			addedAmount1 = proportionalB;
			}

		// Ensure that the added amounts are at least DUST
		require( addedAmount0 > PoolUtils.DUST, "Added liquidity for token 0 less than DUST" );
		require( addedAmount1 > PoolUtils.DUST, "Added liquidity for token 1 less than DUST" );

		// Update the reserves
		reserves.reserve0 += uint128(addedAmount0);
		reserves.reserve1 += uint128(addedAmount1);

		// Determine the amount of liquidity that will be given to the user to reflect their share of the total liquidity.
		addedLiquidity = (totalLiquidity * (addedAmount0+addedAmount1) ) / (reserve0+reserve1);
		}


	// Add liquidity to the specified pool (must be a whitelisted pool)
	// Only callable from the Liquidity contract - so it can specify totalLiquidity with authority
	function addLiquidity( IERC20 tokenA, IERC20 tokenB, uint256 maxAmountA, uint256 maxAmountB, uint256 minAddedAmountA, uint256 minAddedAmountB, uint256 totalLiquidity ) external nonReentrant returns (uint256 addedAmountA, uint256 addedAmountB, uint256 addedLiquidity)
		{
		require( msg.sender == address(liquidity), "Pools.addLiquidity is only callable from the Liquidity contract" );
		require( exchangeIsLive, "The exchange is not yet live" );
		require( address(tokenA) != address(tokenB), "Cannot add liquidity for duplicate tokens" );

		require( maxAmountA > PoolUtils.DUST, "The amount of tokenA to add is too small" );
		require( maxAmountB > PoolUtils.DUST, "The amount of tokenB to add is too small" );

		(bytes32 poolID, bool flipped) = PoolUtils._poolIDAndFlipped(tokenA, tokenB);

		// Flip the users arguments if they are not in reserve token order with address(tokenA) < address(tokenB)
		if ( flipped )
			(addedAmountB, addedAmountA, addedLiquidity) = _addLiquidity( poolID, maxAmountB, maxAmountA, totalLiquidity );
		else
			(addedAmountA, addedAmountB, addedLiquidity) = _addLiquidity( poolID, maxAmountA, maxAmountB, totalLiquidity );

		// Make sure the minimum liquidity has been added
		require( addedAmountA >= minAddedAmountA, "Insufficient tokenA added to liquidity" );
		require( addedAmountB >= minAddedAmountB, "Insufficient tokenB added to liquidity" );

		// Transfer the tokens from the sender - only tokens without fees should be whitelisted on the DEX
		tokenA.safeTransferFrom(msg.sender, address(this), addedAmountA );
		tokenB.safeTransferFrom(msg.sender, address(this), addedAmountB );

		emit LiquidityAdded(tokenA, tokenB, addedAmountA, addedAmountB, addedLiquidity);
		}


	// Remove liquidity for the user and reclaim the underlying tokens
	// Only callable from the Liquidity contract - so it can specify totalLiquidity with authority
	function removeLiquidity( IERC20 tokenA, IERC20 tokenB, uint256 liquidityToRemove, uint256 minReclaimedA, uint256 minReclaimedB, uint256 totalLiquidity ) external nonReentrant returns (uint256 reclaimedA, uint256 reclaimedB)
		{
		require( msg.sender == address(liquidity), "Pools.removeLiquidity is only callable from the Liquidity contract" );
		require( liquidityToRemove > 0, "The amount of liquidityToRemove cannot be zero" );

		(bytes32 poolID, bool flipped) = PoolUtils._poolIDAndFlipped(tokenA, tokenB);

		// Determine how much liquidity is being withdrawn and round down in favor of the protocol
		PoolReserves storage reserves = _poolReserves[poolID];

		if (reserves.reserve0 <= reserves.reserve1 )
			{
			reclaimedA = ( reserves.reserve0 * liquidityToRemove ) / totalLiquidity;
			reclaimedB = ( reserves.reserve1 * reclaimedA ) / reserves.reserve0;
			}
		else
			{
			reclaimedB = ( reserves.reserve1 * liquidityToRemove ) / totalLiquidity;
			reclaimedA = ( reserves.reserve0 * reclaimedB ) / reserves.reserve1;
			}

		reserves.reserve0 -= uint128(reclaimedA);
		reserves.reserve1 -= uint128(reclaimedB);

		// Make sure that removing liquidity doesn't drive either of the reserves below DUST.
		// This is to ensure that ratios remain relatively constant even after a maximum withdrawal.
        require((reserves.reserve0 >= PoolUtils.DUST) && (reserves.reserve1 >= PoolUtils.DUST), "Insufficient reserves after liquidity removal");

		// Switch reclaimed amounts back to the order that was specified in the call arguments so they make sense to the caller
		if (flipped)
			(reclaimedA,reclaimedB) = (reclaimedB,reclaimedA);

		require( (reclaimedA >= minReclaimedA) && (reclaimedB >= minReclaimedB), "Insufficient underlying tokens returned" );

		// Send the reclaimed tokens to the user
		tokenA.safeTransfer( msg.sender, reclaimedA );
		tokenB.safeTransfer( msg.sender, reclaimedB );

		emit LiquidityRemoved(tokenA, tokenB, reclaimedA, reclaimedB, liquidityToRemove);
		}


	// Allow users to deposit tokens into the contract.
	// 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.
	function deposit( IERC20 token, uint256 amount ) external nonReentrant
		{
        require( amount > PoolUtils.DUST, "Deposit amount too small");

		_userDeposits[msg.sender][token] += amount;

		// Transfer the tokens from the sender - only tokens without fees should be whitelisted on the DEX
		token.safeTransferFrom(msg.sender, address(this), amount );

		emit TokenDeposit(msg.sender, token, amount);
		}


	// Withdraw tokens that were previously deposited
    function withdraw( IERC20 token, uint256 amount ) external nonReentrant
    	{
    	require( _userDeposits[msg.sender][token] >= amount, "Insufficient balance to withdraw specified amount" );
        require( amount > PoolUtils.DUST, "Withdraw amount too small");

		_userDeposits[msg.sender][token] -= amount;

    	// Send the token to the user
    	token.safeTransfer( msg.sender, amount );

    	emit TokenWithdrawal(msg.sender, token, amount);
    	}


	// Swap amountIn tokens for amountOut tokens in the direction specified by flipped and update the reserves.
	// Only the reserves are updated - the function does not adjust deposited user balances or do ERC20 transfers.
	// Assumes that the reserves have already been checked for minimal necessary liquidity.
    function _adjustReservesForSwap( PoolReserves storage reserves, bool flipped, uint256 amountIn ) internal returns (uint256 amountOut)
    	{
		// Constant Product AMM Math
		// k=r0*r1																	• product of reserves is constant k
		// k=(r0+amountIn)*(r1-amountOut)							• add some token0 to r0 and swap it for some token1 which is removed from r1
		// r1-amountOut=k/(r0+amountIn)								• divide by (r0+amountIn) and flip
		// amountOut=r1-k/(r0+amountIn)								• multiply by -1 and isolate amountOut
		// amountOut(r0+amountIn)=r1(r0+amountIn)-k		• multiply by (r0+amountIn)
		// amountOut(r0+amountIn)=r1*r0+r1*amountIn-k	• multiply r1 by (r0+amountIn)
		// amountOut(r0+amountIn)=k+r1*amountIn-k			• r0*r1=k (from above)
		// amountOut(r0+amountIn)=r1*amountIn					• cancel k
		// amountOut=r1*amountIn/(r0+amountIn)				• isolate amountOut

        uint256 reserve0 = reserves.reserve0;
        uint256 reserve1 = reserves.reserve1;

		// See if the reserves should be flipped
        if (flipped)
        	{
			reserve1 += amountIn;
			amountOut = reserve0 * amountIn / reserve1;
			reserve0 -= amountOut;
        	}
        else
        	{
			reserve0 += amountIn;
			amountOut = reserve1 * amountIn / reserve0;
			reserve1 -= amountOut;
        	}

		// Make sure that the reserves after swap are greater than DUST
        require( (reserve0 > PoolUtils.DUST) && (reserve1 > PoolUtils.DUST), "Insufficient reserves after swap");

		// Update the reserves with an overflow check
		require( (reserve0 <= type(uint128).max) && (reserve1 <= type(uint128).max), "Reserves overflow after swap" );

		reserves.reserve0 = uint128(reserve0);
		reserves.reserve1 = uint128(reserve1);
    	}


    // Arbitrage a token to itself along a specified circular path (starting and ending with WETH), taking advantage of imbalances in the exchange pools.
    // Does not require any deposited tokens to make the call, but requires that the resulting amountOut is greater than the specified arbitrageAmountIn.
    // 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.
    // The extra amountOut (compared to arbitrageAmountIn) is the arbitrageProfit.
	function _arbitrage(uint256 arbitrageAmountIn, PoolReserves storage reservesA, PoolReserves storage reservesB, PoolReserves storage reservesC, bool flippedA, bool flippedB, bool flippedC ) internal returns (uint256 arbitrageProfit)
		{
		uint256 amountOut = _adjustReservesForSwap( reservesA, flippedA, arbitrageAmountIn );
		amountOut = _adjustReservesForSwap( reservesB, flippedB, amountOut );
		amountOut = _adjustReservesForSwap( reservesC, flippedC, amountOut );

		// Will revert if amountOut < arbitrageAmountIn
		arbitrageProfit = amountOut - arbitrageAmountIn;

		// Immediately swap the generated WETH arbitrage profits to SALT
		(bytes32 poolID, bool flipped) = PoolUtils._poolIDAndFlipped(weth, salt);
        PoolReserves storage reserves = _poolReserves[poolID];

        // Only swap for SALT with sufficient reserves
		if ( ( reserves.reserve0 > PoolUtils.DUST ) && ( reserves.reserve1 > PoolUtils.DUST ) )
			{
			uint256 saltOut = _adjustReservesForSwap(reserves, flipped, arbitrageProfit);

			// Deposit the swapped SALT for the DAO - to be used later within DAO.performUpkeep
			_userDeposits[address(dao)][salt] += saltOut;
			}
		}


	// Check to see if profitable arbitrage is possible after the user swap that was just made
	// Check the arbitrage path: WETH->arbToken2->arbToken3->WETH
	function _attemptArbitrage( IERC20 arbToken2, IERC20 arbToken3 ) internal returns (uint256 arbitrageProfit)
		{
		bytes32 poolID;
		bool flippedA;
		bool flippedB;
		bool flippedC;

		PoolReserves storage reservesA;
		PoolReserves storage reservesB;
		PoolReserves storage reservesC;

		// Given the specified arbitrage path, determine the best arbitrageAmountIn to use
		uint256 arbitrageAmountIn;
			{
			(poolID, flippedA) = PoolUtils._poolIDAndFlipped(weth, arbToken2);
			reservesA = _poolReserves[poolID];
			(uint256 a0, uint256 a1) = (reservesA.reserve0, reservesA.reserve1 );
			if (flippedA)
				(a0, a1) = (a1, a0);


			(poolID, flippedB) = PoolUtils._poolIDAndFlipped(arbToken2, arbToken3);
			reservesB = _poolReserves[poolID];
			(uint256 b0, uint256 b1) = (reservesB.reserve0, reservesB.reserve1 );
			if (flippedB)
				(b0, b1) = (b1, b0);


			(poolID, flippedC) = PoolUtils._poolIDAndFlipped(arbToken3, weth);
			reservesC = _poolReserves[poolID];
			(uint256 c0, uint256 c1) = (reservesC.reserve0, reservesC.reserve1 );
			if (flippedC)
				(c0, c1) = (c1, c0);

			// Determine the best amount of WETH to start the arbitrage with
			if ( a0 > PoolUtils.DUST && a1 > PoolUtils.DUST && b0 > PoolUtils.DUST && b1 > PoolUtils.DUST && c0 > PoolUtils.DUST && c1 > PoolUtils.DUST )
				arbitrageAmountIn = _bestArbitrageIn(a0, a1, b0, b1, c0, c1 );
			}

		// If arbitrage is viable, then perform it
		if (arbitrageAmountIn > 0)
			{
			 arbitrageProfit = _arbitrage(arbitrageAmountIn, reservesA, reservesB, reservesC, flippedA, flippedB, flippedC);

			// Update the stats related to the pools that contributed to the arbitrage so they can be rewarded proportionally later.
			// The arbitrage path can be identified by the middle tokens arbToken2 and arbToken3 (with WETH always on both ends)
			_updateProfitsFromArbitrage( arbToken2, arbToken3, arbitrageProfit );
			 }
		}


	// Adjust the reserves for swapping between the two specified tokens and then immediately attempt arbitrage.
	// Does not require exchange access for the sending wallet.
	function _adjustReservesForSwapAndAttemptArbitrage( IERC20 swapTokenIn, IERC20 swapTokenOut, uint256 swapAmountIn, uint256 minAmountOut ) internal returns (uint256 swapAmountOut)
		{
		// Place the user swap first
		(bytes32 poolID, bool flipped) = PoolUtils._poolIDAndFlipped(swapTokenIn, swapTokenOut);
        PoolReserves storage reserves = _poolReserves[poolID];

        // Revert if reserves are insufficient
        require((reserves.reserve0 > PoolUtils.DUST) && (reserves.reserve1 > PoolUtils.DUST), "Insufficient reserves before swap");
		swapAmountOut = _adjustReservesForSwap( reserves, flipped, swapAmountIn );

		// Make sure the swap meets the minimums specified by the user
		require( swapAmountOut >= minAmountOut, "Insufficient resulting token amount" );

		// The user's swap has just been made - attempt atomic arbitrage to rebalance the pool and yield arbitrage profit.

		// Determine the arbitrage path for the given user swap.
		// Arbitrage path returned as: weth->arbToken2->arbToken3->weth
		(IERC20 arbToken2, IERC20 arbToken3) = _arbitragePath( swapTokenIn, swapTokenOut );
		uint256 arbitrageProfit = _attemptArbitrage( arbToken2, arbToken3 );

		emit SwapAndArbitrage(msg.sender, swapTokenIn, swapTokenOut, swapAmountIn, swapAmountOut, arbitrageProfit);
		}


    // Swap one token for another via a direct whitelisted pool.
    // Having simpler swaps without multiple tokens in the swap chain makes it simpler (and less expensive gas wise) to find suitable arbitrage opportunities.
    // Cheap arbitrage gas-wise is important as arbitrage will be atomically attempted with every user swap transaction.
    // Requires that the first token in the chain has already been deposited for the caller.
	function swap( IERC20 swapTokenIn, IERC20 swapTokenOut, uint256 swapAmountIn, uint256 minAmountOut, uint256 deadline ) external oneUserSwapPerBlock nonReentrant ensureNotExpired(deadline) returns (uint256 swapAmountOut)
		{
		// Confirm and adjust user deposits
		mapping(IERC20=>uint256) storage userDeposits = _userDeposits[msg.sender];

    	require( userDeposits[swapTokenIn] >= swapAmountIn, "Insufficient deposited token balance of initial token" );
		userDeposits[swapTokenIn] -= swapAmountIn;

		swapAmountOut = _adjustReservesForSwapAndAttemptArbitrage(swapTokenIn, swapTokenOut, swapAmountIn, minAmountOut );

		// Deposit the final tokenOut for the caller
		userDeposits[swapTokenOut] += swapAmountOut;
		}


	// Deposit tokenIn, swap to tokenOut and then have tokenOut sent to the sender
	function depositSwapWithdraw(IERC20 swapTokenIn, IERC20 swapTokenOut, uint256 swapAmountIn, uint256 minAmountOut, uint256 deadline ) external oneUserSwapPerBlock nonReentrant ensureNotExpired(deadline) returns (uint256 swapAmountOut)
		{
		// Transfer the tokens from the sender - only tokens without fees should be whitelisted on the DEX
		swapTokenIn.safeTransferFrom(msg.sender, address(this), swapAmountIn );

		swapAmountOut = _adjustReservesForSwapAndAttemptArbitrage(swapTokenIn, swapTokenOut, swapAmountIn, minAmountOut );

    	// Send tokenOut to the user
    	swapTokenOut.safeTransfer( msg.sender, swapAmountOut );
		}


	// Deposit tokenIn, swap to tokenOut without arbitrage and then have tokenOut sent to the sender.
	// Only callable by the Liquidity contract
	function depositZapSwapWithdraw(IERC20 zapSwapTokenIn, IERC20 zapSwapTokenOut, uint256 zapSwapAmountIn ) external returns (uint256 zapSwapAmountOut)
		{
		require( msg.sender == address(liquidity), "Pools.depositZapSwapWithdraw is only callable from the Liquidity contract" );

		// Transfer the tokens from the sender - only tokens without fees should be whitelisted on the DEX
		zapSwapTokenIn.safeTransferFrom(msg.sender, address(this), zapSwapAmountIn );

		// Perform the zap swap without arbitrage or minimum checks (as the users final swap will be checked for relevant minimums).
		// PoolMath.determineZapSwapAmount already checked for reservers > DUST as well.
		(bytes32 poolID, bool flipped) = PoolUtils._poolIDAndFlipped(zapSwapTokenIn, zapSwapTokenOut);
        PoolReserves storage reserves = _poolReserves[poolID];

		// Prevent users from zapping too much at once as they may encounter unexpected slippage
		if ( flipped )
			require( zapSwapAmountIn < reserves.reserve1 / 100, "Cannot zap more than 1% of the reserves" );
		else
			require( zapSwapAmountIn < reserves.reserve0 / 100, "Cannot zap more than 1% of the reserves" );

		zapSwapAmountOut = _adjustReservesForSwap( reserves, flipped, zapSwapAmountIn );

    	// Send tokenOut to the user
    	zapSwapTokenOut.safeTransfer( msg.sender, zapSwapAmountOut );
		}


	// A convenience method to perform two swaps in one transaction
	function depositDoubleSwapWithdraw( IERC20 swapTokenIn, IERC20 swapTokenMiddle, IERC20 swapTokenOut, uint256 swapAmountIn, uint256 minAmountOut, uint256 deadline ) external oneUserSwapPerBlock nonReentrant ensureNotExpired(deadline) returns (uint256 swapAmountOut)
		{
		swapTokenIn.safeTransferFrom(msg.sender, address(this), swapAmountIn );

		uint256 middleAmountOut = _adjustReservesForSwapAndAttemptArbitrage(swapTokenIn, swapTokenMiddle, swapAmountIn, 0 );
		swapAmountOut = _adjustReservesForSwapAndAttemptArbitrage(swapTokenMiddle, swapTokenOut, middleAmountOut, minAmountOut );

    	swapTokenOut.safeTransfer( msg.sender, swapAmountOut );
		}


	// === VIEWS ===

	// The pool reserves for two specified tokens - returned in the order specified by the caller
	function getPoolReserves(IERC20 tokenA, IERC20 tokenB) public view returns (uint256 reserveA, uint256 reserveB)
		{
		(bytes32 poolID, bool flipped) = PoolUtils._poolIDAndFlipped(tokenA, tokenB);
		PoolReserves memory reserves = _poolReserves[poolID];
		reserveA = reserves.reserve0;
		reserveB = reserves.reserve1;

		// Return the reserves in the order that they were requested
		if (flipped)
			(reserveA, reserveB) = (reserveB, reserveA);
		}


	// A user's deposited balance for a token
	function depositedUserBalance(address user, IERC20 token) public view returns (uint256)
		{
		return _userDeposits[user][token];
		}
	}

File 2 of 29 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == _ENTERED;
    }
}

File 3 of 29 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
    }
}

File 4 of 29 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}

File 5 of 29 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 6 of 29 : IExchangeConfig.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;

import "openzeppelin-contracts/contracts/finance/VestingWallet.sol";
import "../staking/interfaces/ILiquidity.sol";
import "../launch/interfaces/IInitialDistribution.sol";
import "../rewards/interfaces/IRewardsEmitter.sol";
import "../rewards/interfaces/ISaltRewards.sol";
import "../rewards/interfaces/IEmissions.sol";
import "../interfaces/IAccessManager.sol";
import "../launch/interfaces/IAirdrop.sol";
import "../dao/interfaces/IDAO.sol";
import "../interfaces/ISalt.sol";
import "./IUpkeep.sol";


interface IExchangeConfig
	{
	function setContracts( IDAO _dao, IUpkeep _upkeep, IInitialDistribution _initialDistribution, VestingWallet _teamVestingWallet, VestingWallet _daoVestingWallet ) external; // onlyOwner
	function setAccessManager( IAccessManager _accessManager ) external; // onlyOwner

	// Views
	function salt() external view returns (ISalt);
	function wbtc() external view returns (IERC20);
	function weth() external view returns (IERC20);
	function usdc() external view returns (IERC20);
	function usdt() external view returns (IERC20);

	function daoVestingWallet() external view returns (VestingWallet);
    function teamVestingWallet() external view returns (VestingWallet);
    function initialDistribution() external view returns (IInitialDistribution);

	function accessManager() external view returns (IAccessManager);
	function dao() external view returns (IDAO);
	function upkeep() external view returns (IUpkeep);
	function teamWallet() external view returns (address);

	function walletHasAccess( address wallet ) external view returns (bool);
	}

File 7 of 29 : ArbitrageSearch.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;

import "openzeppelin-contracts/contracts/utils/math/Math.sol";
import "../interfaces/IExchangeConfig.sol";
import "../pools/PoolUtils.sol";

// Finds a circular path after a user's swap has occurred (from WETH to WETH in this case) that results in an arbitrage profit.
abstract contract ArbitrageSearch
    {
	IERC20 immutable public weth;
	IERC20 immutable public usdc;
	IERC20 immutable public usdt;


    constructor( IExchangeConfig _exchangeConfig )
    	{
		// Cached for efficiency
		weth = _exchangeConfig.weth();
		usdc = _exchangeConfig.usdc();
		usdt = _exchangeConfig.usdt();
    	}


	// Returns the middle two tokens in an arbitrage path that starts and ends with WETH.
	// The WETH tokens at the beginning and end of the path are not returned as they are always the same.
	// Full arbitrage cycle is: WETH->arbToken2->arbToken3->WETH
	function _arbitragePath( IERC20 swapTokenIn, IERC20 swapTokenOut ) internal view returns (IERC20 arbToken2, IERC20 arbToken3)
		{
		// swap: USDC->WETH
        // arb: WETH->USDC->USDT->WETH
		if ( address(swapTokenIn) == address(usdc))
		if ( address(swapTokenOut) == address(weth))
			return (usdc, usdt);

		// swap: WETH->USDC
        // arb: WETH->USDT->USDC->WETH
		if ( address(swapTokenIn) == address(weth))
		if ( address(swapTokenOut) == address(usdc))
			return (usdt, usdc);

		// swap: WETH->swapTokenOut
        // arb: WETH->USDC->swapTokenOut->WETH
		if ( address(swapTokenIn) == address(weth))
			return (usdc, swapTokenOut);

		// swap: swapTokenIn->WETH
        // arb: WETH->swapTokenIn->USDC->WETH
		if ( address(swapTokenOut) == address(weth))
			return (swapTokenIn, usdc);

		// swap: swapTokenIn->swapTokenOut
        // arb: WETH->swapTokenOut->swapTokenIn->WETH
		return (swapTokenOut, swapTokenIn);
		}


	// Determine the most significant bit of a non-zero number
    function _mostSignificantBit(uint256 x) internal pure returns (uint256 msb)
    	{
    	unchecked
    		{
			if (x >= 2**128) { x >>= 128; msb += 128; }
			if (x >= 2**64) { x >>= 64; msb += 64; }
			if (x >= 2**32) { x >>= 32; msb += 32; }
			if (x >= 2**16) { x >>= 16; msb += 16; }
			if (x >= 2**8) { x >>= 8; msb += 8; }
			if (x >= 2**4) { x >>= 4; msb += 4; }
			if (x >= 2**2) { x >>= 2; msb += 2; }
			if (x >= 2**1) { x >>= 1; msb += 1; }
			}
	    }


	// Given that x, y and z will be multiplied: determine the bit shift necessary to keep the product contained in 240 bits
	function _shiftRequired( uint256 x, uint256 y, uint256 z ) internal pure returns (uint256)
		{
		unchecked
			{
			// Determine the maximum number of bits required without shifting
			uint256 requiredBits0 = _mostSignificantBit(x) + _mostSignificantBit(y) + _mostSignificantBit(z);

			// Already fits in 240?
			if ( requiredBits0 < 240 )
				return 0;

			// Each number will be shifted so we can divide the required difference by 3
			return Math.ceilDiv( requiredBits0 - 240, 3 );
			}
		}


	// Determine the shift required to keep a0 * b0 * c0 and a1 * b1 * c1 within 240 bits
	function _determineShift( uint256 a0, uint256 b0, uint256 c0, uint256 a1, uint256 b1, uint256 c1 ) internal pure returns (uint256)
		{
		uint256 shift0 = _shiftRequired(a0, b0, c0);
		uint256 shift1 = _shiftRequired(a1, b1, c1);

		return shift0 > shift1 ? shift0 : shift1;
		}


	function _bestArbitrageIn( uint256 a0, uint256 a1, uint256 b0, uint256 b1, uint256 c0, uint256 c1 ) internal pure returns (uint256 bestArbAmountIn)
		{
		// This can be unchecked as the actual arbitrage that is performed when this is non-zero is checked and duplicates the check for profitability.
		// testArbitrageMethodsLarge() checks for proper behavior with extremely large reserves as well.
		unchecked
			{
			// Original derivation: https://github.com/code-423n4/2024-01-salty-findings/issues/419
			// uint256 n0 = A0 * B0 * C0;
			//	uint256 n1 = A1 * B1 * C1;
			//	if (n1 <= n0) return 0;
			//
			//	uint256 m = A1 * B1 + C0 * B0 + C0 * A1;
			//	uint256 z = Math.sqrt(A0 * C1);
			//	z *= Math.sqrt(A1 * B0);
			//	z *= Math.sqrt(B1 * C0);
			//	bestArbAmountIn = (z - n0) / m;

			// Determine the shift required to keep a0 * b0 * c0 and a1 * b1 * c1 each within 240 bits
			uint256 shift = _determineShift( a0, b0, c0, a1, b1, c1 );

			if ( shift > 0 )
				{
				a0 = a0 >> shift;
				a1 = a1 >> shift;
				b0 = b0 >> shift;
				b1 = b1 >> shift;
				c0 = c0 >> shift;
				c1 = c1 >> shift;
				}

			// Each variable will use less than 80 bits
			uint256 n0 = a0 * b0 * c0;
			uint256 n1 = a1 * b1 * c1;

			if (n1 <= n0)
				return 0;

			uint256 m = a1 *  b1 + c0 * ( b0 + a1 );

			// Calculating n0 * n1 directly would overflow under some situations.
			// Multiply the sqrt's instead - effectively keeping the max size the same
			uint256 z = Math.sqrt(n0) * Math.sqrt(n1);

			bestArbAmountIn = ( z - n0 ) / m;
			if ( bestArbAmountIn == 0 )
				return 0;

			// Needed for the below arbitrage profit testing
			if ( shift > 0 )
				{
				// Convert back to normal scaling
				bestArbAmountIn = bestArbAmountIn << shift;

				a0 = a0 << shift;
				a1 = a1 << shift;
				b0 = b0 << shift;
				b1 = b1 << shift;
				c0 = c0 << shift;
				c1 = c1 << shift;
				}

			// Make sure bestArbAmountIn arbitrage is actually profitable (or else it will revert when actually performed in Pools.sol)
			uint256 amountOut = (a1 * bestArbAmountIn) / (a0 + bestArbAmountIn);
			amountOut = (b1 * amountOut) / (b0 + amountOut);
			amountOut = (c1 * amountOut) / (c0 + amountOut);

			if ( amountOut < bestArbAmountIn )
				return 0;
			}
		}
	}

File 8 of 29 : IPoolsConfig.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;

import "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import "./IPools.sol";


interface IPoolsConfig
	{
	function whitelistPool( IERC20 tokenA, IERC20 tokenB ) external; // onlyOwner
	function unwhitelistPool( IERC20 tokenA, IERC20 tokenB ) external; // onlyOwner
	function changeMaximumWhitelistedPools(bool increase) external; // onlyOwner

	// Views
    function maximumWhitelistedPools() external view returns (uint256);

	function numberOfWhitelistedPools() external view returns (uint256);
	function isWhitelisted( bytes32 poolID ) external view returns (bool);
	function whitelistedPools() external view returns (bytes32[] calldata);
	function underlyingTokenPair( bytes32 poolID ) external view returns (IERC20 tokenA, IERC20 tokenB);

	// Returns true if the token has been whitelisted (meaning it has been pooled with either WETH and USDC)
	function tokenHasBeenWhitelisted( IERC20 token, IERC20 weth, IERC20 usdc ) external view returns (bool);
	}

File 9 of 29 : IPools.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;

import "../../staking/interfaces/ILiquidity.sol";
import "../../dao/interfaces/IDAO.sol";
import "./IPoolStats.sol";


interface IPools is IPoolStats
	{
	function startExchangeApproved() external;
	function setContracts( IDAO _dao, ILiquidity _liquidity ) external; // onlyOwner

	function addLiquidity( IERC20 tokenA, IERC20 tokenB, uint256 maxAmountA, uint256 maxAmountB, uint256 minAddedAmountA, uint256 minAddedAmountB, uint256 totalLiquidity ) external returns (uint256 addedAmountA, uint256 addedAmountB, uint256 addedLiquidity);
	function removeLiquidity( IERC20 tokenA, IERC20 tokenB, uint256 liquidityToRemove, uint256 minReclaimedA, uint256 minReclaimedB, uint256 totalLiquidity ) external returns (uint256 reclaimedA, uint256 reclaimedB);

	function deposit( IERC20 token, uint256 amount ) external;
	function withdraw( IERC20 token, uint256 amount ) external;
	function swap( IERC20 swapTokenIn, IERC20 swapTokenOut, uint256 swapAmountIn, uint256 minAmountOut, uint256 deadline ) external returns (uint256 swapAmountOut);
	function depositSwapWithdraw(IERC20 swapTokenIn, IERC20 swapTokenOut, uint256 swapAmountIn, uint256 minAmountOut, uint256 deadline ) external returns (uint256 swapAmountOut);
	function depositDoubleSwapWithdraw( IERC20 swapTokenIn, IERC20 swapTokenMiddle, IERC20 swapTokenOut, uint256 swapAmountIn, uint256 minAmountOut, uint256 deadline ) external returns (uint256 swapAmountOut);
	function depositZapSwapWithdraw(IERC20 swapTokenIn, IERC20 swapTokenOut, uint256 swapAmountIn ) external returns (uint256 swapAmountOut);

	// Views
	function exchangeIsLive() external view returns (bool);
	function getPoolReserves(IERC20 tokenA, IERC20 tokenB) external view returns (uint256 reserveA, uint256 reserveB);
	function depositedUserBalance(address user, IERC20 token) external view returns (uint256);
	}

File 10 of 29 : PoolStats.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;

import "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import "../interfaces/IExchangeConfig.sol";
import "./interfaces/IPoolsConfig.sol";
import "./interfaces/IPoolStats.sol";
import "./PoolUtils.sol";


// Keeps track of the arbitrage profits generated by pools (for rewards distribution proportional to the profits generated per pool).
abstract contract PoolStats is IPoolStats
	{
	uint64 constant INVALID_POOL_ID = type(uint64).max;

	IExchangeConfig immutable public exchangeConfig;
	IPoolsConfig immutable public poolsConfig;
	IERC20 immutable public _weth;

	// poolID(arbToken2, arbToken3) => arbitrage profits contributed since the last performUpkeep
	mapping(bytes32=>uint256) public _arbitrageProfits;

	// Maps poolID(arbToken2, arbToken3) => the indicies (within the whitelistedPools array) of the pools involved in WETH->arbToken2->arbToken3->WETH
	mapping(bytes32=>ArbitrageIndicies) public _arbitrageIndicies;


    constructor( IExchangeConfig _exchangeConfig, IPoolsConfig _poolsConfig )
    	{
		exchangeConfig = _exchangeConfig;
		poolsConfig = _poolsConfig;

		_weth = exchangeConfig.weth();
    	}


	// 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)
	function _updateProfitsFromArbitrage( IERC20 arbToken2, IERC20 arbToken3, uint256 arbitrageProfit ) internal
		{
		// 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
		bytes32 poolID = PoolUtils._poolID( arbToken2, arbToken3 );

		_arbitrageProfits[poolID] += arbitrageProfit;
		}


	// Called at the end of Upkeep.performUpkeep to reset the arbitrage stats for the pools
	function clearProfitsForPools() external
		{
		require(msg.sender == address(exchangeConfig.upkeep()), "PoolStats.clearProfitsForPools is only callable from the Upkeep contract" );

		bytes32[] memory poolIDs = poolsConfig.whitelistedPools();

		// Don't fully set profits to zero to avoid the increased gas cost of overwriting zero
		for( uint256 i = 0; i < poolIDs.length; i++ )
			_arbitrageProfits[ poolIDs[i] ] = 1;
		}


	// The index of pool tokenA/tokenB within the whitelistedPools array.
	// Should always find a value as only whitelisted pools are used in the arbitrage path.
	// Returns uint64.max in the event of failed lookup
	function _poolIndex( IERC20 tokenA, IERC20 tokenB, bytes32[] memory poolIDs ) internal pure returns (uint64 index)
		{
		bytes32 poolID = PoolUtils._poolID( tokenA, tokenB );

		for( uint256 i = 0; i < poolIDs.length; i++ )
			{
			if (poolID == poolIDs[i])
				return uint64(i);
			}

		return INVALID_POOL_ID;
		}


	// Traverse the current whitelisted poolIDs and update the indicies of each pool that would contribute to arbitrage for it.
	// Maps poolID(arbToken2, arbToken3) => the indicies (within the whitelistedPools array) of the pools involved in WETH->arbToken2->arbToken3->WETH arbitrage.
	function updateArbitrageIndicies() public
		{
		bytes32[] memory poolIDs = poolsConfig.whitelistedPools();

		for( uint256 i = 0; i < poolIDs.length; i++ )
			{
			bytes32 poolID = poolIDs[i];
			(IERC20 arbToken2, IERC20 arbToken3) = poolsConfig.underlyingTokenPair(poolID);

			// The middle two tokens can never be WETH in a valid arbitrage path as the path is WETH->arbToken2->arbToken3->WETH.
			if ( (arbToken2 != _weth) && (arbToken3 != _weth) )
				{
				uint64 poolIndex1 = _poolIndex( _weth, arbToken2, poolIDs );
				uint64 poolIndex2 = _poolIndex( arbToken2, arbToken3, poolIDs );
				uint64 poolIndex3 = _poolIndex( arbToken3, _weth, poolIDs );

				// Check if the indicies in storage have the correct values - and if not then update them
				ArbitrageIndicies memory indicies = _arbitrageIndicies[poolID];
				if ( ( poolIndex1 != indicies.index1 ) || ( poolIndex2 != indicies.index2 ) || ( poolIndex3 != indicies.index3 ) )
					_arbitrageIndicies[poolID] = ArbitrageIndicies(poolIndex1, poolIndex2, poolIndex3);
				}
			}
		}


	// Examine the arbitrage that has been generated since the last Upkeep.performUpkeep call and credit the pools that have contributed towards it.
	// The calculated sums for each pool will then be used to proportionally distribute SALT rewards to each of the contributing pools.
	function _calculateArbitrageProfits( bytes32[] memory poolIDs, uint256[] memory _calculatedProfits ) internal view
		{
		for( uint256 i = 0; i < poolIDs.length; i++ )
			{
			// references poolID(arbToken2, arbToken3) which defines the arbitage path of WETH->arbToken2->arbToken3->WETH
			bytes32 poolID = poolIDs[i];

			// Split the arbitrage profit between all the pools that contributed to generating the arbitrage for the referenced pool.
			uint256 arbitrageProfit = _arbitrageProfits[poolID] / 3;
			if ( arbitrageProfit > 0 )
				{
				ArbitrageIndicies memory indicies = _arbitrageIndicies[poolID];

				if ( indicies.index1 != INVALID_POOL_ID )
					_calculatedProfits[indicies.index1] += arbitrageProfit;

				if ( indicies.index2 != INVALID_POOL_ID )
					_calculatedProfits[indicies.index2] += arbitrageProfit;

				if ( indicies.index3 != INVALID_POOL_ID )
					_calculatedProfits[indicies.index3] += arbitrageProfit;
				}
			}
		}


	// === VIEWS ===

	// 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.
	// Returns the profits for all of the current whitelisted pools
	function profitsForWhitelistedPools() external view returns (uint256[] memory _calculatedProfits)
		{
		bytes32[] memory poolIDs = poolsConfig.whitelistedPools();

		_calculatedProfits = new uint256[](poolIDs.length);
		_calculateArbitrageProfits( poolIDs, _calculatedProfits );
		}


	function arbitrageIndicies(bytes32 poolID) external view returns (ArbitrageIndicies memory)
		{
		return _arbitrageIndicies[poolID];
		}
	}

File 11 of 29 : PoolUtils.sol
pragma solidity =0.8.22;

import "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";


library PoolUtils
	{
	// Token reserves less than dust are treated as if they don't exist at all.
	// With the 18 decimals that are used for most tokens, DUST has a value of 0.0000000000000001
	uint256 constant public DUST = 100;

	// A special pool that represents staked SALT that is not associated with any actual liquidity pool.
    bytes32 constant public STAKED_SALT = bytes32(0);


    // Return the unique poolID for the given two tokens.
    // Tokens are sorted before being hashed to make reversed pairs equivalent.
    function _poolID( IERC20 tokenA, IERC20 tokenB ) internal pure returns (bytes32 poolID)
    	{
        // See if the token orders are flipped
        if ( uint160(address(tokenB)) < uint160(address(tokenA)) )
            return keccak256(abi.encodePacked(address(tokenB), address(tokenA)));

        return keccak256(abi.encodePacked(address(tokenA), address(tokenB)));
    	}


    // Return the unique poolID and whether or not it is flipped
    function _poolIDAndFlipped( IERC20 tokenA, IERC20 tokenB ) internal pure returns (bytes32 poolID, bool flipped)
    	{
        // See if the token orders are flipped
        if ( uint160(address(tokenB)) < uint160(address(tokenA)) )
            return (keccak256(abi.encodePacked(address(tokenB), address(tokenA))), true);

        return (keccak256(abi.encodePacked(address(tokenA), address(tokenB))), false);
    	}
	}

File 12 of 29 : IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 13 of 29 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

File 14 of 29 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

File 15 of 29 : VestingWallet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (finance/VestingWallet.sol)
pragma solidity ^0.8.0;

import "../token/ERC20/utils/SafeERC20.sol";
import "../utils/Address.sol";
import "../utils/Context.sol";

/**
 * @title VestingWallet
 * @dev This contract handles the vesting of Eth and ERC20 tokens for a given beneficiary. Custody of multiple tokens
 * can be given to this contract, which will release the token to the beneficiary following a given vesting schedule.
 * The vesting schedule is customizable through the {vestedAmount} function.
 *
 * Any token transferred to this contract will follow the vesting schedule as if they were locked from the beginning.
 * Consequently, if the vesting has already started, any amount of tokens sent to this contract will (at least partly)
 * be immediately releasable.
 */
contract VestingWallet is Context {
    event EtherReleased(uint256 amount);
    event ERC20Released(address indexed token, uint256 amount);

    uint256 private _released;
    mapping(address => uint256) private _erc20Released;
    address private immutable _beneficiary;
    uint64 private immutable _start;
    uint64 private immutable _duration;

    /**
     * @dev Set the beneficiary, start timestamp and vesting duration of the vesting wallet.
     */
    constructor(address beneficiaryAddress, uint64 startTimestamp, uint64 durationSeconds) payable {
        require(beneficiaryAddress != address(0), "VestingWallet: beneficiary is zero address");
        _beneficiary = beneficiaryAddress;
        _start = startTimestamp;
        _duration = durationSeconds;
    }

    /**
     * @dev The contract should be able to receive Eth.
     */
    receive() external payable virtual {}

    /**
     * @dev Getter for the beneficiary address.
     */
    function beneficiary() public view virtual returns (address) {
        return _beneficiary;
    }

    /**
     * @dev Getter for the start timestamp.
     */
    function start() public view virtual returns (uint256) {
        return _start;
    }

    /**
     * @dev Getter for the vesting duration.
     */
    function duration() public view virtual returns (uint256) {
        return _duration;
    }

    /**
     * @dev Amount of eth already released
     */
    function released() public view virtual returns (uint256) {
        return _released;
    }

    /**
     * @dev Amount of token already released
     */
    function released(address token) public view virtual returns (uint256) {
        return _erc20Released[token];
    }

    /**
     * @dev Getter for the amount of releasable eth.
     */
    function releasable() public view virtual returns (uint256) {
        return vestedAmount(uint64(block.timestamp)) - released();
    }

    /**
     * @dev Getter for the amount of releasable `token` tokens. `token` should be the address of an
     * IERC20 contract.
     */
    function releasable(address token) public view virtual returns (uint256) {
        return vestedAmount(token, uint64(block.timestamp)) - released(token);
    }

    /**
     * @dev Release the native token (ether) that have already vested.
     *
     * Emits a {EtherReleased} event.
     */
    function release() public virtual {
        uint256 amount = releasable();
        _released += amount;
        emit EtherReleased(amount);
        Address.sendValue(payable(beneficiary()), amount);
    }

    /**
     * @dev Release the tokens that have already vested.
     *
     * Emits a {ERC20Released} event.
     */
    function release(address token) public virtual {
        uint256 amount = releasable(token);
        _erc20Released[token] += amount;
        emit ERC20Released(token, amount);
        SafeERC20.safeTransfer(IERC20(token), beneficiary(), amount);
    }

    /**
     * @dev Calculates the amount of ether that has already vested. Default implementation is a linear vesting curve.
     */
    function vestedAmount(uint64 timestamp) public view virtual returns (uint256) {
        return _vestingSchedule(address(this).balance + released(), timestamp);
    }

    /**
     * @dev Calculates the amount of tokens that has already vested. Default implementation is a linear vesting curve.
     */
    function vestedAmount(address token, uint64 timestamp) public view virtual returns (uint256) {
        return _vestingSchedule(IERC20(token).balanceOf(address(this)) + released(token), timestamp);
    }

    /**
     * @dev Virtual implementation of the vesting formula. This returns the amount vested, as a function of time, for
     * an asset given its total historical allocation.
     */
    function _vestingSchedule(uint256 totalAllocation, uint64 timestamp) internal view virtual returns (uint256) {
        if (timestamp < start()) {
            return 0;
        } else if (timestamp > start() + duration()) {
            return totalAllocation;
        } else {
            return (totalAllocation * (timestamp - start())) / duration();
        }
    }
}

File 16 of 29 : ILiquidity.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;

import "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import "./IStakingRewards.sol";


interface ILiquidity is IStakingRewards
	{
	function depositLiquidityAndIncreaseShare( IERC20 tokenA, IERC20 tokenB, uint256 maxAmountA, uint256 maxAmountB, uint256 minAddedAmountA, uint256 minAddedAmountB, uint256 minAddedLiquidity, uint256 deadline, bool useZapping ) external returns (uint256 addedLiquidity);
	function withdrawLiquidityAndClaim( IERC20 tokenA, IERC20 tokenB, uint256 liquidityToWithdraw, uint256 minReclaimedA, uint256 minReclaimedB, uint256 deadline ) external returns (uint256 reclaimedA, uint256 reclaimedB);
	}

File 17 of 29 : IInitialDistribution.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;

import "./IBootstrapBallot.sol";
import "./IAirdrop.sol";


interface IInitialDistribution
	{
	function distributionApproved( IAirdrop airdrop1, IAirdrop airdrop2 ) external;

	// Views
	function bootstrapBallot() external view returns (IBootstrapBallot);
	}

File 18 of 29 : IRewardsEmitter.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;

import "../../staking/interfaces/IStakingRewards.sol";


interface IRewardsEmitter
	{
	function addSALTRewards( AddedReward[] calldata addedRewards ) external;
	function performUpkeep( uint256 timeSinceLastUpkeep ) external;

	// Views
	function pendingRewardsForPools( bytes32[] calldata pools ) external view returns (uint256[] calldata);
	}

File 19 of 29 : ISaltRewards.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;

import "./IRewardsEmitter.sol";


interface ISaltRewards
	{
	function sendInitialSaltRewards( uint256 liquidityBootstrapAmount, bytes32[] calldata poolIDs ) external;
    function performUpkeep( bytes32[] calldata poolIDs, uint256[] calldata profitsForPools ) external;

    // Views
    function stakingRewardsEmitter() external view returns (IRewardsEmitter);
    function liquidityRewardsEmitter() external view returns (IRewardsEmitter);
    }

File 20 of 29 : IEmissions.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;


interface IEmissions
	{
	function performUpkeep( uint256 timeSinceLastUpkeep ) external;
    }

File 21 of 29 : IAccessManager.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;


interface IAccessManager
	{
	function excludedCountriesUpdated() external;
	function grantAccess(bytes calldata signature) external;

	// Views
	function geoVersion() external view returns (uint256);
	function walletHasAccess(address wallet) external view returns (bool);
	}

File 22 of 29 : IAirdrop.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;


interface IAirdrop
	{
	function authorizeWallet( address wallet, uint256 saltAmount ) external;
	function allowClaiming() external;
	function claim() external;

	// Views
	function claimedByUser( address wallet) external view returns (uint256);
	function claimingAllowed() external view returns (bool);
	function claimingStartTimestamp() external view returns (uint256);
	function claimableAmount(address wallet) external view returns (uint256);
    function airdropForUser( address wallet ) external view returns (uint256);
	}

File 23 of 29 : IDAO.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;

import "../../rewards/interfaces/ISaltRewards.sol";
import "../../pools/interfaces/IPools.sol";
import "../../interfaces/ISalt.sol";

interface IDAO
	{
	function finalizeBallot( uint256 ballotID ) external;
	function manuallyRemoveBallot( uint256 ballotID ) external;

	function withdrawFromDAO( IERC20 token ) external returns (uint256 withdrawnAmount);

	// Views
	function pools() external view returns (IPools);
	function websiteURL() external view returns (string memory);
	function countryIsExcluded( string calldata country ) external view returns (bool);
	}

File 24 of 29 : ISalt.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;

import "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";


interface ISalt is IERC20
	{
	function burnTokensInContract() external;

	// Views
	function totalBurned() external view returns (uint256);
	}

File 25 of 29 : IUpkeep.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;


interface IUpkeep
	{
	function performUpkeep() external;

	// Views
	function currentRewardsForCallingPerformUpkeep() external view returns (uint256);
	function lastUpkeepTimeEmissions() external view returns (uint256);
	function lastUpkeepTimeRewardsEmitters() external view returns (uint256);
	}

File 26 of 29 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1, "Math: mulDiv overflow");

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
        }
    }
}

File 27 of 29 : IPoolStats.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;


interface IPoolStats
	{
	// These are the indicies (in terms of a poolIDs location in the current whitelistedPoolIDs array) of pools involved in an arbitrage path
	struct ArbitrageIndicies
		{
		uint64 index1;
		uint64 index2;
		uint64 index3;
		}

	function clearProfitsForPools() external;
	function updateArbitrageIndicies() external;

	// Views
	function profitsForWhitelistedPools() external view returns (uint256[] memory _calculatedProfits);
	function arbitrageIndicies(bytes32 poolID) external view returns (ArbitrageIndicies memory);
	}

File 28 of 29 : IStakingRewards.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;


struct AddedReward
	{
	bytes32 poolID;							// The pool to add rewards to
	uint256 amountToAdd;				// The amount of rewards (as SALT) to add
	}

struct UserShareInfo
	{
	uint256 userShare;					// A user's share for a given poolID
	uint256 virtualRewards;				// The amount of rewards that were added to maintain proper rewards/share ratio - and will be deducted from a user's pending rewards.
	uint256 cooldownExpiration;		// The timestamp when the user can modify their share
	}


interface IStakingRewards
	{
	function claimAllRewards( bytes32[] calldata poolIDs ) external returns (uint256 rewardsAmount);
	function addSALTRewards( AddedReward[] calldata addedRewards ) external;

	// Views
	function totalShares(bytes32 poolID) external view returns (uint256);
	function totalSharesForPools( bytes32[] calldata poolIDs ) external view returns (uint256[] calldata shares);
	function totalRewardsForPools( bytes32[] calldata poolIDs ) external view returns (uint256[] calldata rewards);

	function userRewardForPool( address wallet, bytes32 poolID ) external view returns (uint256);
	function userShareForPool( address wallet, bytes32 poolID ) external view returns (uint256);
	function userVirtualRewardsForPool( address wallet, bytes32 poolID ) external view returns (uint256);

	function userRewardsForPools( address wallet, bytes32[] calldata poolIDs ) external view returns (uint256[] calldata rewards);
	function userShareForPools( address wallet, bytes32[] calldata poolIDs ) external view returns (uint256[] calldata shares);
	function userCooldowns( address wallet, bytes32[] calldata poolIDs ) external view returns (uint256[] calldata cooldowns);
	}

File 29 of 29 : IBootstrapBallot.sol
// SPDX-License-Identifier: BUSL 1.1
pragma solidity =0.8.22;


interface IBootstrapBallot
	{
	function vote( bool voteStartExchangeYes, uint256 saltAmount, bytes calldata signature ) external;
	function finalizeBallot() external;

	function authorizeAirdrop2( uint256 saltAmount, bytes calldata signature ) external;
	function finalizeAirdrop2() external;

	// Views
	function claimableTimestamp1() external view returns (uint256);
	function claimableTimestamp2() external view returns (uint256);

	function hasVoted(address user) external view returns (bool);
	function ballotFinalized() external view returns (bool);

	function startExchangeYes() external view returns (uint256);
	function startExchangeNo() external view returns (uint256);
	}

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": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract IExchangeConfig","name":"_exchangeConfig","type":"address"},{"internalType":"contract IPoolsConfig","name":"_poolsConfig","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20","name":"tokenA","type":"address"},{"indexed":true,"internalType":"contract IERC20","name":"tokenB","type":"address"},{"indexed":false,"internalType":"uint256","name":"addedAmountA","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"addedAmountB","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"addedLiquidity","type":"uint256"}],"name":"LiquidityAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20","name":"tokenA","type":"address"},{"indexed":true,"internalType":"contract IERC20","name":"tokenB","type":"address"},{"indexed":false,"internalType":"uint256","name":"reclaimedA","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"reclaimedB","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"removedLiquidity","type":"uint256"}],"name":"LiquidityRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"contract IERC20","name":"swapTokenIn","type":"address"},{"indexed":true,"internalType":"contract IERC20","name":"swapTokenOut","type":"address"},{"indexed":false,"internalType":"uint256","name":"swapAmountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"swapAmountOut","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"arbitrageProfit","type":"uint256"}],"name":"SwapAndArbitrage","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"TokenDeposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"TokenWithdrawal","type":"event"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"_arbitrageIndicies","outputs":[{"internalType":"uint64","name":"index1","type":"uint64"},{"internalType":"uint64","name":"index2","type":"uint64"},{"internalType":"uint64","name":"index3","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"_arbitrageProfits","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_weth","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"tokenA","type":"address"},{"internalType":"contract IERC20","name":"tokenB","type":"address"},{"internalType":"uint256","name":"maxAmountA","type":"uint256"},{"internalType":"uint256","name":"maxAmountB","type":"uint256"},{"internalType":"uint256","name":"minAddedAmountA","type":"uint256"},{"internalType":"uint256","name":"minAddedAmountB","type":"uint256"},{"internalType":"uint256","name":"totalLiquidity","type":"uint256"}],"name":"addLiquidity","outputs":[{"internalType":"uint256","name":"addedAmountA","type":"uint256"},{"internalType":"uint256","name":"addedAmountB","type":"uint256"},{"internalType":"uint256","name":"addedLiquidity","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"poolID","type":"bytes32"}],"name":"arbitrageIndicies","outputs":[{"components":[{"internalType":"uint64","name":"index1","type":"uint64"},{"internalType":"uint64","name":"index2","type":"uint64"},{"internalType":"uint64","name":"index3","type":"uint64"}],"internalType":"struct IPoolStats.ArbitrageIndicies","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"clearProfitsForPools","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"dao","outputs":[{"internalType":"contract IDAO","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"swapTokenIn","type":"address"},{"internalType":"contract IERC20","name":"swapTokenMiddle","type":"address"},{"internalType":"contract IERC20","name":"swapTokenOut","type":"address"},{"internalType":"uint256","name":"swapAmountIn","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"depositDoubleSwapWithdraw","outputs":[{"internalType":"uint256","name":"swapAmountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"swapTokenIn","type":"address"},{"internalType":"contract IERC20","name":"swapTokenOut","type":"address"},{"internalType":"uint256","name":"swapAmountIn","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"depositSwapWithdraw","outputs":[{"internalType":"uint256","name":"swapAmountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"zapSwapTokenIn","type":"address"},{"internalType":"contract IERC20","name":"zapSwapTokenOut","type":"address"},{"internalType":"uint256","name":"zapSwapAmountIn","type":"uint256"}],"name":"depositZapSwapWithdraw","outputs":[{"internalType":"uint256","name":"zapSwapAmountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"depositedUserBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"exchangeConfig","outputs":[{"internalType":"contract IExchangeConfig","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"exchangeIsLive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"tokenA","type":"address"},{"internalType":"contract IERC20","name":"tokenB","type":"address"}],"name":"getPoolReserves","outputs":[{"internalType":"uint256","name":"reserveA","type":"uint256"},{"internalType":"uint256","name":"reserveB","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liquidity","outputs":[{"internalType":"contract ILiquidity","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolsConfig","outputs":[{"internalType":"contract IPoolsConfig","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"profitsForWhitelistedPools","outputs":[{"internalType":"uint256[]","name":"_calculatedProfits","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"tokenA","type":"address"},{"internalType":"contract IERC20","name":"tokenB","type":"address"},{"internalType":"uint256","name":"liquidityToRemove","type":"uint256"},{"internalType":"uint256","name":"minReclaimedA","type":"uint256"},{"internalType":"uint256","name":"minReclaimedB","type":"uint256"},{"internalType":"uint256","name":"totalLiquidity","type":"uint256"}],"name":"removeLiquidity","outputs":[{"internalType":"uint256","name":"reclaimedA","type":"uint256"},{"internalType":"uint256","name":"reclaimedB","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"salt","outputs":[{"internalType":"contract ISalt","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IDAO","name":"_dao","type":"address"},{"internalType":"contract ILiquidity","name":"_liquidity","type":"address"}],"name":"setContracts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"startExchangeApproved","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"swapTokenIn","type":"address"},{"internalType":"contract IERC20","name":"swapTokenOut","type":"address"},{"internalType":"uint256","name":"swapAmountIn","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swap","outputs":[{"internalType":"uint256","name":"swapAmountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updateArbitrageIndicies","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"usdc","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"usdt","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106101e55760003560e01c8063715018a61161010f578063c4de1782116100a2578063d8952a4911610071578063d8952a49146105cb578063e2f7c480146105de578063f2fde38b146105f1578063f3fef3a31461060457600080fd5b8063c4de178214610595578063c74e31c81461059d578063cb936cc1146105b0578063d4469c3e146105b857600080fd5b80638da5cb5b116100de5780638da5cb5b1461052a578063a17645951461053b578063af42bb1a14610562578063bfa0b1331461058257600080fd5b8063715018a6146104d95780637a950f99146104e15780637ae06e58146104f457806385876e951461052257600080fd5b80633fc8cef311610187578063516a5c2511610156578063516a5c251461034f57806352c19b5a146103cc578063634040b3146103f3578063647e77d01461042857600080fd5b80633fc8cef3146102d85780634162169f146102ff57806344483d531461031257806347e7ef241461033a57600080fd5b80632458a800116101c35780632458a800146102565780632c662857146102775780632f48ab7d1461028a5780633e413bee146102b157600080fd5b80630e2789bb146101ea5780631959df061461022e5780631a68650214610243575b600080fd5b6102117f00000000000000000000000066db65306c2ddb7aa9730e010033ee624ddd7f6181565b6040516001600160a01b0390911681526020015b60405180910390f35b610236610617565b6040516102259190613bb4565b600554610211906001600160a01b031681565b610269610264366004613c0d565b6106f7565b604051908152602001610225565b610269610285366004613c4e565b610970565b6102117f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec781565b6102117f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b6102117f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b600454610211906001600160a01b031681565b610325610320366004613c87565b61099d565b60408051928352602083019190915201610225565b61034d610348366004613ce0565b610e92565b005b6103a161035d366004613d0c565b60026020526000908152604090205467ffffffffffffffff808216916801000000000000000081048216917001000000000000000000000000000000009091041683565b6040805167ffffffffffffffff94851681529284166020840152921691810191909152606001610225565b6102117f000000000000000000000000a6ba8dece812f4663a19960735c0f66560a1d89481565b6006546104189074010000000000000000000000000000000000000000900460ff1681565b6040519015158152602001610225565b6104a6610436366004613d0c565b6040805160608082018352600080835260208084018290529284018190529384526002825292829020825193840183525467ffffffffffffffff80821685526801000000000000000082048116928501929092527001000000000000000000000000000000009004169082015290565b60408051825167ffffffffffffffff90811682526020808501518216908301529282015190921690820152606001610225565b61034d610f87565b6102696104ef366004613d25565b610f9b565b610507610502366004613d76565b6111b1565b60408051938452602084019290925290820152606001610225565b61034d6115df565b6003546001600160a01b0316610211565b6102117f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b610269610570366004613d0c565b60016020526000908152604090205481565b600654610211906001600160a01b031681565b61034d611987565b6102696105ab366004613dd8565b611b85565b61034d611cd3565b6103256105c6366004613c4e565b611ebb565b61034d6105d9366004613c4e565b611f36565b6102696105ec366004613d25565b611f8e565b61034d6105ff366004613e3d565b6120ae565b61034d610612366004613ce0565b61213e565b606060007f000000000000000000000000a6ba8dece812f4663a19960735c0f66560a1d8946001600160a01b031663434798856040518163ffffffff1660e01b8152600401600060405180830381865afa158015610679573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526106a19190810190613e89565b9050805167ffffffffffffffff8111156106bd576106bd613e5a565b6040519080825280602002602001820160405280156106e6578160200160208202803683370190505b5091506106f381836122b9565b5090565b6005546000906001600160a01b031633146107a55760405162461bcd60e51b815260206004820152604960248201527f506f6f6c732e6465706f7369745a61705377617057697468647261772069732060448201527f6f6e6c792063616c6c61626c652066726f6d20746865204c697175696469747960648201527f20636f6e74726163740000000000000000000000000000000000000000000000608482015260a4015b60405180910390fd5b6107ba6001600160a01b038516333085612459565b6000806107c78686612510565b60008281526007602052604090209193509150811561089f5780546108149060649070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff16613fa5565b6fffffffffffffffffffffffffffffffff16851061089a5760405162461bcd60e51b815260206004820152602760248201527f43616e6e6f74207a6170206d6f7265207468616e203125206f6620746865207260448201527f6573657276657300000000000000000000000000000000000000000000000000606482015260840161079c565b610945565b80546108bf906064906fffffffffffffffffffffffffffffffff16613fa5565b6fffffffffffffffffffffffffffffffff1685106109455760405162461bcd60e51b815260206004820152602760248201527f43616e6e6f74207a6170206d6f7265207468616e203125206f6620746865207260448201527f6573657276657300000000000000000000000000000000000000000000000000606482015260840161079c565b6109508183876125ea565b93506109666001600160a01b038716338661278f565b5050509392505050565b6001600160a01b038083166000908152600860209081526040808320938516835292905220545b92915050565b6000806109a86127d8565b6005546001600160a01b03163314610a4e5760405162461bcd60e51b815260206004820152604260248201527f506f6f6c732e72656d6f76654c6971756964697479206973206f6e6c7920636160448201527f6c6c61626c652066726f6d20746865204c697175696469747920636f6e74726160648201527f6374000000000000000000000000000000000000000000000000000000000000608482015260a40161079c565b60008611610ac45760405162461bcd60e51b815260206004820152602e60248201527f54686520616d6f756e74206f66206c6971756964697479546f52656d6f76652060448201527f63616e6e6f74206265207a65726f000000000000000000000000000000000000606482015260840161079c565b600080610ad18a8a612510565b60008281526007602052604090208054929450909250906fffffffffffffffffffffffffffffffff70010000000000000000000000000000000082048116911611610b8c5780548690610b37908b906fffffffffffffffffffffffffffffffff16613fd4565b610b419190613feb565b81549095506fffffffffffffffffffffffffffffffff80821691610b7b918891700100000000000000000000000000000000900416613fd4565b610b859190613feb565b9350610c11565b80548690610bc1908b9070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff16613fd4565b610bcb9190613feb565b81549094506fffffffffffffffffffffffffffffffff7001000000000000000000000000000000008204811691610c0491879116613fd4565b610c0e9190613feb565b94505b805485908290600090610c379084906fffffffffffffffffffffffffffffffff16613fff565b92506101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff160217905550838160000160108282829054906101000a90046fffffffffffffffffffffffffffffffff16610c9c9190613fff565b82546101009290920a6fffffffffffffffffffffffffffffffff8181021990931691831602179091558254606491161080159150610d035750805460647001000000000000000000000000000000009091046fffffffffffffffffffffffffffffffff1610155b610d755760405162461bcd60e51b815260206004820152602d60248201527f496e73756666696369656e74207265736572766573206166746572206c69717560448201527f69646974792072656d6f76616c00000000000000000000000000000000000000606482015260840161079c565b8115610d7f579293925b878510158015610d8f5750868410155b610e015760405162461bcd60e51b815260206004820152602760248201527f496e73756666696369656e7420756e6465726c79696e6720746f6b656e73207260448201527f657475726e656400000000000000000000000000000000000000000000000000606482015260840161079c565b610e156001600160a01b038c16338761278f565b610e296001600160a01b038b16338661278f565b60408051868152602081018690529081018a90526001600160a01b03808c1691908d16907fbc7d19d505c7ec4db83f3b51f19fb98c4c8a99922e7839d1ee608dfbee29501b9060600160405180910390a3505050610e876001600055565b965096945050505050565b610e9a6127d8565b60648111610eea5760405162461bcd60e51b815260206004820152601860248201527f4465706f73697420616d6f756e7420746f6f20736d616c6c0000000000000000604482015260640161079c565b3360009081526008602090815260408083206001600160a01b038616845290915281208054839290610f1d90849061402f565b90915550610f3890506001600160a01b038316333084612459565b6040518181526001600160a01b0383169033907f98c09d9949722bae4bd0d988d4050091c3ae7ec6d51d3c6bbfe4233593944e9e906020015b60405180910390a3610f836001600055565b5050565b610f8f612831565b610f99600061288b565b565b336000908152600960205260408120544390036110205760405162461bcd60e51b815260206004820152602260248201527f5573657220616c7265616479207377617070656420696e207468697320626c6f60448201527f636b000000000000000000000000000000000000000000000000000000000000606482015260840161079c565b6110286127d8565b81804211156110795760405162461bcd60e51b815260206004820152600a60248201527f5458204558504952454400000000000000000000000000000000000000000000604482015260640161079c565b3360009081526008602090815260408083206001600160a01b038b16845291829052909120548611156111145760405162461bcd60e51b815260206004820152603560248201527f496e73756666696369656e74206465706f736974656420746f6b656e2062616c60448201527f616e6365206f6620696e697469616c20746f6b656e0000000000000000000000606482015260840161079c565b6001600160a01b0388166000908152602082905260408120805488929061113c908490614042565b9091555061114e9050888888886128f5565b925082816000896001600160a01b03166001600160a01b031681526020019081526020016000206000828254611184919061402f565b90915550506001600055506111969050565b33600090815260096020526040902043905595945050505050565b60008060006111be6127d8565b6005546001600160a01b0316331461123e5760405162461bcd60e51b815260206004820152603f60248201527f506f6f6c732e6164644c6971756964697479206973206f6e6c792063616c6c6160448201527f626c652066726f6d20746865204c697175696469747920636f6e747261637400606482015260840161079c565b60065474010000000000000000000000000000000000000000900460ff166112a85760405162461bcd60e51b815260206004820152601c60248201527f5468652065786368616e6765206973206e6f7420796574206c69766500000000604482015260640161079c565b886001600160a01b03168a6001600160a01b03160361132f5760405162461bcd60e51b815260206004820152602960248201527f43616e6e6f7420616464206c697175696469747920666f72206475706c69636160448201527f746520746f6b656e730000000000000000000000000000000000000000000000606482015260840161079c565b606488116113a55760405162461bcd60e51b815260206004820152602860248201527f54686520616d6f756e74206f6620746f6b656e4120746f20616464206973207460448201527f6f6f20736d616c6c000000000000000000000000000000000000000000000000606482015260840161079c565b6064871161141b5760405162461bcd60e51b815260206004820152602860248201527f54686520616d6f756e74206f6620746f6b656e4220746f20616464206973207460448201527f6f6f20736d616c6c000000000000000000000000000000000000000000000000606482015260840161079c565b6000806114288c8c612510565b91509150801561144b5761143e828a8c89612adc565b909650909450925061145f565b611457828b8b89612adc565b919650945092505b878510156114d55760405162461bcd60e51b815260206004820152602660248201527f496e73756666696369656e7420746f6b656e4120616464656420746f206c697160448201527f7569646974790000000000000000000000000000000000000000000000000000606482015260840161079c565b8684101561154b5760405162461bcd60e51b815260206004820152602660248201527f496e73756666696369656e7420746f6b656e4220616464656420746f206c697160448201527f7569646974790000000000000000000000000000000000000000000000000000606482015260840161079c565b6115606001600160a01b038d16333088612459565b6115756001600160a01b038c16333087612459565b60408051868152602081018690529081018490526001600160a01b03808d1691908e16907f4a1a2a6176e9646d9e3157f7c2ab3c499f18337c0b0828cfb28e0a61de4a11f79060600160405180910390a350506115d26001600055565b9750975097945050505050565b60007f000000000000000000000000a6ba8dece812f4663a19960735c0f66560a1d8946001600160a01b031663434798856040518163ffffffff1660e01b8152600401600060405180830381865afa15801561163f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526116679190810190613e89565b905060005b8151811015610f8357600082828151811061168957611689614055565b602002602001015190506000807f000000000000000000000000a6ba8dece812f4663a19960735c0f66560a1d8946001600160a01b031663c2fb9aac846040518263ffffffff1660e01b81526004016116e491815260200190565b6040805180830381865afa158015611700573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117249190614084565b915091507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316826001600160a01b03161415801561179c57507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316816001600160a01b031614155b1561197c5760006117ce7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28488612e36565b905060006117dd848489612e36565b9050600061180c847f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28a612e36565b6000878152600260209081526040918290208251606081018452905467ffffffffffffffff8082168084526801000000000000000083048216948401949094527001000000000000000000000000000000009091048116938201939093529293509085161415806118955750806020015167ffffffffffffffff168367ffffffffffffffff1614155b806118b85750806040015167ffffffffffffffff168267ffffffffffffffff1614155b15611977576040805160608101825267ffffffffffffffff8087168252858116602080840191825286831684860190815260008d8152600290925294902092518354915194518316700100000000000000000000000000000000027fffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffff95841668010000000000000000027fffffffffffffffffffffffffffffffff00000000000000000000000000000000909316919093161717929092169190911790555b505050505b50505060010161166c565b7f00000000000000000000000066db65306c2ddb7aa9730e010033ee624ddd7f616001600160a01b0316632cf4704a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119e5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a0991906140b3565b6001600160a01b0316336001600160a01b031614611ab55760405162461bcd60e51b815260206004820152604860248201527f506f6f6c53746174732e636c65617250726f66697473466f72506f6f6c73206960448201527f73206f6e6c792063616c6c61626c652066726f6d207468652055706b6565702060648201527f636f6e7472616374000000000000000000000000000000000000000000000000608482015260a40161079c565b60007f000000000000000000000000a6ba8dece812f4663a19960735c0f66560a1d8946001600160a01b031663434798856040518163ffffffff1660e01b8152600401600060405180830381865afa158015611b15573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611b3d9190810190613e89565b905060005b8151811015610f83576001806000848481518110611b6257611b62614055565b602090810291909101810151825281019190915260400160002055600101611b42565b33600090815260096020526040812054439003611c0a5760405162461bcd60e51b815260206004820152602260248201527f5573657220616c7265616479207377617070656420696e207468697320626c6f60448201527f636b000000000000000000000000000000000000000000000000000000000000606482015260840161079c565b611c126127d8565b8180421115611c635760405162461bcd60e51b815260206004820152600a60248201527f5458204558504952454400000000000000000000000000000000000000000000604482015260640161079c565b611c786001600160a01b038916333088612459565b6000611c8789898860006128f5565b9050611c95888883886128f5565b9250611cab6001600160a01b038816338561278f565b5050611cb76001600055565b3360009081526009602052604090204390559695505050505050565b611cdb6127d8565b7f00000000000000000000000066db65306c2ddb7aa9730e010033ee624ddd7f616001600160a01b03166395645e346040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d39573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d5d91906140b3565b6001600160a01b031663bd1d4b286040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d9a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dbe91906140b3565b6001600160a01b0316336001600160a01b031614611e6a5760405162461bcd60e51b815260206004820152605060248201527f506f6f6c732e737461727445786368616e6765417070726f7665642063616e2060448201527f6f6e6c792062652063616c6c65642066726f6d2074686520426f6f747374726160648201527f7042616c6c6f7420636f6e747261637400000000000000000000000000000000608482015260a40161079c565b611e726115df565b600680547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff1674010000000000000000000000000000000000000000179055610f996001600055565b600080600080611ecb8686612510565b6000828152600760209081526040918290208251808401909352546fffffffffffffffffffffffffffffffff808216808552700100000000000000000000000000000000909204169183018290529750955091935091508115611f2c579293925b5050509250929050565b611f3e612831565b600480546001600160a01b038085167fffffffffffffffffffffffff0000000000000000000000000000000000000000928316179092556005805492841692909116919091179055610f83610f87565b336000908152600960205260408120544390036120135760405162461bcd60e51b815260206004820152602260248201527f5573657220616c7265616479207377617070656420696e207468697320626c6f60448201527f636b000000000000000000000000000000000000000000000000000000000000606482015260840161079c565b61201b6127d8565b818042111561206c5760405162461bcd60e51b815260206004820152600a60248201527f5458204558504952454400000000000000000000000000000000000000000000604482015260640161079c565b6120816001600160a01b038816333088612459565b61208d878787876128f5565b91506120a36001600160a01b038716338461278f565b506111966001600055565b6120b6612831565b6001600160a01b0381166121325760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f6464726573730000000000000000000000000000000000000000000000000000606482015260840161079c565b61213b8161288b565b50565b6121466127d8565b3360009081526008602090815260408083206001600160a01b03861684529091529020548111156121df5760405162461bcd60e51b815260206004820152603160248201527f496e73756666696369656e742062616c616e636520746f20776974686472617760448201527f2073706563696669656420616d6f756e74000000000000000000000000000000606482015260840161079c565b6064811161222f5760405162461bcd60e51b815260206004820152601960248201527f576974686472617720616d6f756e7420746f6f20736d616c6c00000000000000604482015260640161079c565b3360009081526008602090815260408083206001600160a01b038616845290915281208054839290612262908490614042565b9091555061227c90506001600160a01b038316338361278f565b6040518181526001600160a01b0383169033907f42856d0378dde02337bb59ae41747abc77ded8ebdbbc5cbdd1e53693b755493890602001610f71565b60005b82518110156124545760008382815181106122d9576122d9614055565b602002602001015190506000600360016000848152602001908152602001600020546123059190613feb565b9050801561244a576000828152600260209081526040918290208251606081018452905467ffffffffffffffff80821680845268010000000000000000830482169484019490945270010000000000000000000000000000000090910481169382019390935291146123aa578185826000015167ffffffffffffffff168151811061239257612392614055565b602002602001018181516123a6919061402f565b9052505b602081015167ffffffffffffffff908116146123f9578185826020015167ffffffffffffffff16815181106123e1576123e1614055565b602002602001018181516123f5919061402f565b9052505b604081015167ffffffffffffffff90811614612448578185826040015167ffffffffffffffff168151811061243057612430614055565b60200260200101818151612444919061402f565b9052505b505b50506001016122bc565b505050565b6040516001600160a01b038085166024830152831660448201526064810182905261250a9085907f23b872dd00000000000000000000000000000000000000000000000000000000906084015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152612e97565b50505050565b600080836001600160a01b0316836001600160a01b0316101561258a576040517fffffffffffffffffffffffffffffffffffffffff000000000000000000000000606085811b8216602084015286901b166034820152604801604051602081830303815290604052805190602001206001915091506125e3565b6040517fffffffffffffffffffffffffffffffffffffffff000000000000000000000000606086811b8216602084015285901b166034820152604801604051602081830303815290604052805190602001206000915091505b9250929050565b82546000906fffffffffffffffffffffffffffffffff80821691700100000000000000000000000000000000900416841561265357612629848261402f565b9050806126368584613fd4565b6126409190613feb565b925061264c8383614042565b9150612683565b61265d848361402f565b91508161266a8583613fd4565b6126749190613feb565b92506126808382614042565b90505b6064821180156126935750606481115b6126df5760405162461bcd60e51b815260206004820181905260248201527f496e73756666696369656e742072657365727665732061667465722073776170604482015260640161079c565b6fffffffffffffffffffffffffffffffff821180159061270f57506fffffffffffffffffffffffffffffffff8111155b61275b5760405162461bcd60e51b815260206004820152601c60248201527f5265736572766573206f766572666c6f77206166746572207377617000000000604482015260640161079c565b6fffffffffffffffffffffffffffffffff908116700100000000000000000000000000000000029116179093555090919050565b6040516001600160a01b0383166024820152604481018290526124549084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064016124a6565b60026000540361282a5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161079c565b6002600055565b6003546001600160a01b03163314610f995760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161079c565b600380546001600160a01b038381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60008060006129048787612510565b600082815260076020526040902080549294509092509060646fffffffffffffffffffffffffffffffff9091161180156129665750805460647001000000000000000000000000000000009091046fffffffffffffffffffffffffffffffff16115b6129d85760405162461bcd60e51b815260206004820152602160248201527f496e73756666696369656e74207265736572766573206265666f72652073776160448201527f7000000000000000000000000000000000000000000000000000000000000000606482015260840161079c565b6129e38183886125ea565b935084841015612a5b5760405162461bcd60e51b815260206004820152602360248201527f496e73756666696369656e7420726573756c74696e6720746f6b656e20616d6f60448201527f756e740000000000000000000000000000000000000000000000000000000000606482015260840161079c565b600080612a688a8a612f7f565b915091506000612a7883836131c7565b604080518b8152602081018a90529081018290529091506001600160a01b03808c1691908d169033907f1195a8db0f3ef828b684c3193db62af33dae2817d69fa75433df4c896c00be189060600160405180910390a4505050505050949350505050565b60008481526007602052604081208054829182916fffffffffffffffffffffffffffffffff80821691700100000000000000000000000000000000900416811580612b25575080155b15612c0757825489908490600090612b509084906fffffffffffffffffffffffffffffffff166140d0565b92506101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff160217905550878360000160108282829054906101000a90046fffffffffffffffffffffffffffffffff16612bb591906140d0565b92506101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff1602179055508888898b612bf9919061402f565b955095509550505050612e2c565b600082612c14838c613fd4565b612c1e9190613feb565b905088811115612c475781612c33848b613fd4565b612c3d9190613feb565b9650889550612c4e565b8996508095505b60648711612cc45760405162461bcd60e51b815260206004820152602a60248201527f4164646564206c697175696469747920666f7220746f6b656e2030206c65737360448201527f207468616e204455535400000000000000000000000000000000000000000000606482015260840161079c565b60648611612d3a5760405162461bcd60e51b815260206004820152602a60248201527f4164646564206c697175696469747920666f7220746f6b656e2031206c65737360448201527f207468616e204455535400000000000000000000000000000000000000000000606482015260840161079c565b835487908590600090612d609084906fffffffffffffffffffffffffffffffff166140d0565b92506101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff160217905550858460000160108282829054906101000a90046fffffffffffffffffffffffffffffffff16612dc591906140d0565b92506101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff1602179055508183612e07919061402f565b612e11878961402f565b612e1b908a613fd4565b612e259190613feb565b9450505050505b9450945094915050565b600080612e4385856133a0565b905060005b8351811015612e8257838181518110612e6357612e63614055565b60200260200101518203612e7a579150612e909050565b600101612e48565b5067ffffffffffffffff9150505b9392505050565b6000612eec826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661346f9092919063ffffffff16565b9050805160001480612f0d575080806020019051810190612f0d91906140f9565b6124545760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f74207375636365656400000000000000000000000000000000000000000000606482015260840161079c565b6000807f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b0316846001600160a01b03160361303e577f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316836001600160a01b03160361303e57507f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4890507f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec76125e3565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316846001600160a01b0316036130fa577f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b0316836001600160a01b0316036130fa57507f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec790507f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486125e3565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316846001600160a01b03160361315d57507f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb489050816125e3565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316836001600160a01b0316036131c057508290507f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486125e3565b5090929050565b60008060008060008060008060006131ff7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28c612510565b60008281526007602052604090208054929a5090985094506fffffffffffffffffffffffffffffffff80821691700100000000000000000000000000000000900416881561324957905b6132538d8d612510565b60008281526007602052604090208054929c5090995095506fffffffffffffffffffffffffffffffff80821691700100000000000000000000000000000000900416891561329d57905b6132c78e7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2612510565b60008281526007602052604090208054929e50909a5096506fffffffffffffffffffffffffffffffff808216917001000000000000000000000000000000009004168a1561331157905b6064861180156133215750606485115b801561332d5750606484115b80156133395750606483115b80156133455750606482115b80156133515750606481115b1561336757613364868686868686613486565b96505b505050505050600081111561339257613385818585858b8b8b6135ae565b98506133928b8b8b6136ed565b505050505050505092915050565b6000826001600160a01b0316826001600160a01b03161015613415576040517fffffffffffffffffffffffffffffffffffffffff000000000000000000000000606084811b8216602084015285901b166034820152604801604051602081830303815290604052805190602001209050610997565b6040517fffffffffffffffffffffffffffffffffffffffff000000000000000000000000606085811b8216602084015284901b16603482015260480160405160208183030381529060405280519060200120905092915050565b606061347e8484600085613729565b949350505050565b6000806134978887868a898861381b565b905080156134b85796871c9695861c9594851c9493841c9392831c9291821c915b878602840287860284028181116134d557600093505050506135a4565b868902888a0187020160006134e983613856565b6134f285613856565b029050818482038161350657613506613f47565b0495508560000361351f576000955050505050506135a4565b8415613542579a841b9a99841b9998841b9897841b9796841b9695841b9594841b945b6000868d01878d028161355757613557613f47565b049050808b01818b028161356d5761356d613f47565b0490508089018189028161358357613583613f47565b0490508681101561359d57600096505050505050506135a4565b5050505050505b9695505050505050565b6000806135bc88868b6125ea565b90506135c98785836125ea565b90506135d68684836125ea565b90506135e28982614042565b6006549092506000908190613621907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2906001600160a01b0316612510565b600082815260076020526040902080549294509092509060646fffffffffffffffffffffffffffffffff9091161180156136835750805460647001000000000000000000000000000000009091046fffffffffffffffffffffffffffffffff16115b156136de5760006136958284886125ea565b6004546001600160a01b0390811660009081526008602090815260408083206006549094168352929052908120805492935083929091906136d790849061402f565b9091555050505b50505050979650505050505050565b60006136f984846133a0565b90508160016000838152602001908152602001600020600082825461371e919061402f565b909155505050505050565b6060824710156137a15760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c0000000000000000000000000000000000000000000000000000606482015260840161079c565b600080866001600160a01b031685876040516137bd919061413f565b60006040518083038185875af1925050503d80600081146137fa576040519150601f19603f3d011682016040523d82523d6000602084013e6137ff565b606091505b50915091506138108783838761393e565b979650505050505050565b6000806138298888886139b7565b905060006138388686866139b7565b90508082116138475780613849565b815b9998505050505050505050565b60008160000361386857506000919050565b6000600161387584613a03565b901c6001901b9050600181848161388e5761388e613f47565b048201901c905060018184816138a6576138a6613f47565b048201901c905060018184816138be576138be613f47565b048201901c905060018184816138d6576138d6613f47565b048201901c905060018184816138ee576138ee613f47565b048201901c9050600181848161390657613906613f47565b048201901c9050600181848161391e5761391e613f47565b048201901c9050612e908182858161393857613938613f47565b04613a97565b606083156139ad5782516000036139a6576001600160a01b0385163b6139a65760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161079c565b508161347e565b61347e8383613aad565b6000806139c383613ad7565b6139cc85613ad7565b6139d587613ad7565b0101905060f08110156139ec576000915050612e90565b6139fa60f082036003613b7d565b95945050505050565b600080608083901c15613a1857608092831c92015b604083901c15613a2a57604092831c92015b602083901c15613a3c57602092831c92015b601083901c15613a4e57601092831c92015b600883901c15613a6057600892831c92015b600483901c15613a7257600492831c92015b600283901c15613a8457600292831c92015b600183901c156109975760010192915050565b6000818310613aa65781612e90565b5090919050565b815115613abd5781518083602001fd5b8060405162461bcd60e51b815260040161079c919061415b565b60007001000000000000000000000000000000008210613af957608091821c91015b680100000000000000008210613b1157604091821c91015b6401000000008210613b2557602091821c91015b620100008210613b3757601091821c91015b6101008210613b4857600891821c91015b60108210613b5857600491821c91015b60048210613b6857600291821c91015b60028210613b7857600191821c91015b919050565b60008215613bab5781613b91600185614042565b613b9b9190613feb565b613ba690600161402f565b612e90565b50600092915050565b6020808252825182820181905260009190848201906040850190845b81811015613bec57835183529284019291840191600101613bd0565b50909695505050505050565b6001600160a01b038116811461213b57600080fd5b600080600060608486031215613c2257600080fd5b8335613c2d81613bf8565b92506020840135613c3d81613bf8565b929592945050506040919091013590565b60008060408385031215613c6157600080fd5b8235613c6c81613bf8565b91506020830135613c7c81613bf8565b809150509250929050565b60008060008060008060c08789031215613ca057600080fd5b8635613cab81613bf8565b95506020870135613cbb81613bf8565b95989597505050506040840135936060810135936080820135935060a0909101359150565b60008060408385031215613cf357600080fd5b8235613cfe81613bf8565b946020939093013593505050565b600060208284031215613d1e57600080fd5b5035919050565b600080600080600060a08688031215613d3d57600080fd5b8535613d4881613bf8565b94506020860135613d5881613bf8565b94979496505050506040830135926060810135926080909101359150565b600080600080600080600060e0888a031215613d9157600080fd5b8735613d9c81613bf8565b96506020880135613dac81613bf8565b96999698505050506040850135946060810135946080820135945060a0820135935060c0909101359150565b60008060008060008060c08789031215613df157600080fd5b8635613dfc81613bf8565b95506020870135613e0c81613bf8565b94506040870135613e1c81613bf8565b959894975094956060810135955060808101359460a0909101359350915050565b600060208284031215613e4f57600080fd5b8135612e9081613bf8565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60006020808385031215613e9c57600080fd5b825167ffffffffffffffff80821115613eb457600080fd5b818501915085601f830112613ec857600080fd5b815181811115613eda57613eda613e5a565b8060051b604051601f19603f83011681018181108582111715613eff57613eff613e5a565b604052918252848201925083810185019188831115613f1d57600080fd5b938501935b82851015613f3b57845184529385019392850192613f22565b98975050505050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006fffffffffffffffffffffffffffffffff80841680613fc857613fc8613f47565b92169190910492915050565b808202811582820484141761099757610997613f76565b600082613ffa57613ffa613f47565b500490565b6fffffffffffffffffffffffffffffffff82811682821603908082111561402857614028613f76565b5092915050565b8082018082111561099757610997613f76565b8181038181111561099757610997613f76565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000806040838503121561409757600080fd5b82516140a281613bf8565b6020840151909250613c7c81613bf8565b6000602082840312156140c557600080fd5b8151612e9081613bf8565b6fffffffffffffffffffffffffffffffff81811683821601908082111561402857614028613f76565b60006020828403121561410b57600080fd5b81518015158114612e9057600080fd5b60005b8381101561413657818101518382015260200161411e565b50506000910152565b6000825161415181846020870161411b565b9190910192915050565b602081526000825180602084015261417a81604085016020870161411b565b601f01601f1916919091016040019291505056fea2646970667358221220f76d3eb015685bf5f5b1aa8c67c8241773bb7bd77924670f6e2b5137485480c564736f6c63430008160033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.