Contract Overview
Balance:
0 ETH
EtherValue:
$0.00
My Name Tag:
Not Available, login to update
Txn Hash | Method |
Block
|
From
|
To
|
Value | ||||
---|---|---|---|---|---|---|---|---|---|
0x4c247591f9419b50fd49c822335cea1715729b6bda5c9c1f88b1ebf55b6d07c1 | 0x61012060 | 6726980 | 12 days 9 hrs ago | 0x8610f105f3d0a0479d9c9d85c13b352f6c8eefee | IN | Create: BalancerAMM | 0 ETH | 0.003694468375 |
[ Download CSV Export ]
Contract Name:
BalancerAMM
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (interfaces/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../token/ERC20/extensions/IERC20Metadata.sol";
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.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); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.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) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1); /////////////////////////////////////////////// // 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 10, 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 * 8) < value ? 1 : 0); } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.6.0; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; library TransferHelper { /// @notice Transfers tokens from the targeted address to the given destination /// @notice Errors with 'STF' if transfer fails /// @param token The contract address of the token to be transferred /// @param from The originating address from which the tokens will be transferred /// @param to The destination address of the transfer /// @param value The amount to be transferred function safeTransferFrom( address token, address from, address to, uint256 value ) internal { (bool success, bytes memory data) = token.call( abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value) ); require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF'); } /// @notice Transfers tokens from msg.sender to a recipient /// @dev Errors with ST if transfer fails /// @param token The contract address of the token which will be transferred /// @param to The recipient of the transfer /// @param value The value of the transfer function safeTransfer( address token, address to, uint256 value ) internal { (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'ST'); } /// @notice Approves the stipulated contract to spend the given allowance in the given token /// @dev Errors with 'SA' if transfer fails /// @param token The contract address of the token to be approved /// @param to The target of the approval /// @param value The amount of the given token the target will be allowed to spend function safeApprove( address token, address to, uint256 value ) internal { (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'SA'); } /// @notice Transfers ETH to the recipient address /// @dev Fails with `STE` /// @param to The destination of the transfer /// @param value The value to be transferred function safeTransferETH(address to, uint256 value) internal { (bool success, ) = to.call{value: value}(new bytes(0)); require(success, 'STE'); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.19; // ========================================================== // ====================== BalancerAMM.sol ==================== // ========================================================== /** * @title Balancer AMM * @dev Interactions with Balancer Pool */ import { ChainlinkLibrary, IPriceFeed } from "../Libraries/Chainlink.sol"; import { IERC20Metadata } from "@openzeppelin/contracts/interfaces/IERC20Metadata.sol"; import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; import { TransferHelper } from "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol"; import { ISweep } from "../Sweep/ISweep.sol"; import { IAsset, SingleSwap, FundManagement, SwapKind, IBalancerVault, IBalancerPool } from "../Assets/Balancer/IBalancer.sol"; contract BalancerAMM { using Math for uint256; IBalancerVault public vault; IBalancerPool public pool; IERC20Metadata public immutable base; ISweep public immutable sweep; IPriceFeed public immutable oracleBase; IPriceFeed public immutable sequencer; uint256 public immutable oracleBaseUpdateFrequency; uint8 private constant USD_DECIMALS = 6; uint16 private constant DEADLINE_GAP = 15 minutes; constructor( address _sweep, address _base, address _sequencer, address _oracleBase, uint256 _oracleBaseUpdateFrequency ) { sweep = ISweep(_sweep); base = IERC20Metadata(_base); oracleBase = IPriceFeed(_oracleBase); sequencer = IPriceFeed(_sequencer); oracleBaseUpdateFrequency = _oracleBaseUpdateFrequency; } // Events event Bought(uint256 usdxAmount); event Sold(uint256 sweepAmount); // Errors error OverZero(); /** * @notice Get Price * @dev Get the quote for selling 1 unit of a token. */ function getPrice() public view returns (uint256 price) { if(address(pool) == address(0)) return 2e6; uint256 rate = pool.getTokenRate(address(sweep)); uint8 rateDecimals = 18; uint256 stablePrice = ChainlinkLibrary.getPrice( oracleBase, sequencer, oracleBaseUpdateFrequency ); uint8 oracleDecimals = ChainlinkLibrary.getDecimals(oracleBase); price = rate.mulDiv(stablePrice * (10 ** base.decimals()), 10 ** (oracleDecimals + rateDecimals)); } /** * @notice Get TWA Price * @dev Get the quote for selling 1 unit of a token. */ function getTWAPrice() external view returns (uint256 amountOut) { return getPrice(); } function getRate() public view returns (uint256 rate) { rate = sweep.targetPrice() * 1e12; } function getPositions(uint256) public view returns (uint256 usdxAmount, uint256 sweepAmount, uint256 lp) { (IAsset[] memory tokens, uint256[] memory balances,) = vault.getPoolTokens(pool.getPoolId()); usdxAmount = findAssetIndex(address(base), tokens, balances); sweepAmount = findAssetIndex(address(sweep), tokens, balances); lp = findAssetIndex(address(pool), tokens, balances); } /* ========== Actions ========== */ /** * @notice Buy Sweep * @param tokenAddress Token Address to use for buying sweep. * @param tokenAmount Token Amount. * @param amountOutMin Minimum amount out. * @dev Increases the sweep balance and decrease collateral balance. */ function buySweep( address tokenAddress, uint256 tokenAmount, uint256 amountOutMin ) external returns (uint256 sweepAmount) { emit Bought(tokenAmount); sweepAmount = swapExactInput( tokenAddress, address(sweep), 0, tokenAmount, amountOutMin ); } /** * @notice Sell Sweep * @param tokenAddress Token Address to return after selling sweep. * @param sweepAmount Sweep Amount. * @param amountOutMin Minimum amount out. * @dev Decreases the sweep balance and increase collateral balance */ function sellSweep( address tokenAddress, uint256 sweepAmount, uint256 amountOutMin ) external returns (uint256 tokenAmount) { emit Sold(sweepAmount); tokenAmount = swapExactInput( address(sweep), tokenAddress, 0, sweepAmount, amountOutMin ); } /** * @notice Swap tokenIn for tokenOut using balancer exact input swap * @param tokenIn Address to in * @param tokenOut Address to out * @param amountIn Amount of _tokenA * @param amountOutMin Minimum amount out. */ function swapExactInput( address tokenIn, address tokenOut, uint24, uint256 amountIn, uint256 amountOutMin ) public returns (uint256 amountOut) { // Approval TransferHelper.safeTransferFrom( tokenIn, msg.sender, address(this), amountIn ); TransferHelper.safeApprove(tokenIn, address(vault), amountIn); bytes32 poolId = pool.getPoolId(); bytes memory userData; SingleSwap memory singleSwap = SingleSwap( poolId, SwapKind.GIVEN_IN, IAsset(tokenIn), IAsset(tokenOut), amountIn, userData ); FundManagement memory funds = FundManagement( address(this), false, payable(msg.sender), false ); uint256 deadline = block.timestamp + DEADLINE_GAP; amountOut = vault.swap(singleSwap, funds, amountOutMin, deadline); } function setPool(address poolAddress) external { require(msg.sender == sweep.owner(), "BalancerAMM: Not Governance"); pool = IBalancerPool(poolAddress); vault = IBalancerVault(pool.getVault()); } function findAssetIndex(address asset, IAsset[] memory assets, uint256[] memory balances) internal pure returns (uint256) { for (uint8 i = 0; i < assets.length; i++) { if ( address(assets[i]) == asset ) { return balances[i]; } } revert(); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.19; import "@openzeppelin/contracts/interfaces/IERC20Metadata.sol"; interface IBalancerVault { struct JoinPoolRequest { IAsset[] assets; uint256[] maxAmountsIn; bytes userData; bool fromInternalBalance; } struct ExitPoolRequest { IAsset[] assets; uint256[] minAmountsOut; bytes userData; bool toInternalBalance; } function joinPool(bytes32 poolId, address sender, address recipient, JoinPoolRequest memory request) external payable; function exitPool(bytes32 poolId, address sender, address recipient, ExitPoolRequest memory request) external payable; function getPoolTokens(bytes32 poolId) external view returns (IAsset[] memory tokens, uint256[] memory balances, uint256 lastChangeBlock); function swap(SingleSwap memory singleSwap, FundManagement memory funds, uint256 limit, uint256 deadline) external returns (uint256 amountOut); } interface IAsset { // solhint-disable-previous-line no-empty-blocks } interface IBalancerPool is IERC20Metadata { function getPoolId() external view returns (bytes32); function getVault() external view returns (address); function getRate() external view returns (uint256); function getTokenRate(address) external view returns (uint256); } struct SingleSwap { bytes32 poolId; SwapKind kind; IAsset assetIn; IAsset assetOut; uint256 amount; bytes userData; } struct FundManagement { address sender; bool fromInternalBalance; address payable recipient; bool toInternalBalance; } interface IComposableStablePoolFactory { function create( string memory name, string memory symbol, IERC20[] memory tokens, uint256 amplificationParameter, IRateProvider[] memory rateProviders, uint256[] memory tokenRateCacheDurations, bool exemptFromYieldProtocolFeeFlag, uint256 swapFeePercentage, address owner, bytes32 salt ) external returns(address poolAddress); } interface IRateProvider { function getRate() external view returns (uint256); } enum JoinKind { INIT, EXACT_TOKENS_IN_FOR_BPT_OUT, TOKEN_IN_FOR_EXACT_BPT_OUT, ALL_TOKENS_IN_FOR_EXACT_BPT_OUT } enum ExitKind { EXACT_BPT_IN_FOR_ONE_TOKEN_OUT, BPT_IN_FOR_EXACT_TOKENS_OUT, EXACT_BPT_IN_FOR_ALL_TOKENS_OUT } enum SwapKind { GIVEN_IN, GIVEN_OUT }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.19; interface IPriceFeed { function latestAnswer() external view returns (int256); function latestTimestamp() external view returns (uint256); function latestRound() external view returns (uint256); function getAnswer(uint256 roundId) external view returns (int256); function getTimestamp(uint256 roundId) external view returns (uint256); function decimals() external view returns (uint8); function description() external view returns (string memory); function version() external view returns (uint256); function getRoundData( uint80 _roundId ) external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); function latestRoundData() external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); } library ChainlinkLibrary { uint8 constant USD_DECIMALS = 6; function getDecimals(IPriceFeed oracle) internal view returns (uint8) { return oracle.decimals(); } function getPrice(IPriceFeed oracle) internal view returns (uint256) { ( uint80 roundID, int256 price, , uint256 timeStamp, uint80 answeredInRound ) = oracle.latestRoundData(); require(answeredInRound >= roundID, "Old data"); require(timeStamp > 0, "Round not complete"); return uint256(price); } function getPrice( IPriceFeed oracle, IPriceFeed sequencerOracle, uint256 frequency ) internal view returns (uint256) { if (address(sequencerOracle) != address(0)) checkUptime(sequencerOracle); (uint256 roundId, int256 price, , uint256 updatedAt, ) = oracle .latestRoundData(); require(price > 0 && roundId != 0 && updatedAt != 0, "Invalid Price"); if (frequency > 0) require(block.timestamp - updatedAt <= frequency, "Stale Price"); return uint256(price); } function checkUptime(IPriceFeed sequencerOracle) internal view { (, int256 answer, uint256 startedAt, , ) = sequencerOracle .latestRoundData(); require(answer <= 0, "Sequencer Down"); // 0: Sequencer is up, 1: Sequencer is down require(block.timestamp - startedAt > 1 hours, "Grace Period Not Over"); } function convertTokenToToken( uint256 amount0, uint8 token0Decimals, uint8 token1Decimals, IPriceFeed oracle0, IPriceFeed oracle1 ) internal view returns (uint256 amount1) { uint256 price0 = getPrice(oracle0); uint256 price1 = getPrice(oracle1); amount1 = (amount0 * price0 * (10 ** token1Decimals)) / (price1 * (10 ** token0Decimals)); } function convertTokenToUsd( uint256 amount, uint8 tokenDecimals, IPriceFeed oracle ) internal view returns (uint256 amountUsd) { uint8 decimals = getDecimals(oracle); uint256 price = getPrice(oracle); amountUsd = (amount * price * (10 ** USD_DECIMALS)) / 10 ** (decimals + tokenDecimals); } function convertUsdToToken( uint256 amountUsd, uint256 tokenDecimals, IPriceFeed oracle ) internal view returns (uint256 amount) { uint8 decimals = getDecimals(oracle); uint256 price = getPrice(oracle); amount = (amountUsd * 10 ** (decimals + tokenDecimals)) / (price * (10 ** USD_DECIMALS)); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.19; interface ISweep { struct Minter { uint256 maxAmount; uint256 mintedAmount; bool isListed; bool isEnabled; } function isMintingAllowed() external view returns (bool); function DEFAULT_ADMIN_ADDRESS() external view returns (address); function balancer() external view returns (address); function treasury() external view returns (address); function allowance( address holder, address spender ) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function balanceOf(address account) external view returns (uint256); function decimals() external view returns (uint8); function decreaseAllowance( address spender, uint256 subtractedValue ) external returns (bool); function isValidMinter(address) external view returns (bool); function amm() external view returns (address); function ammPrice() external view returns (uint256); function twaPrice() external view returns (uint256); function increaseAllowance( address spender, uint256 addedValue ) external returns (bool); function name() external view returns (string memory); function owner() external view returns (address); function fastMultisig() external view returns (address); function burn(uint256 amount) external; function mint(uint256 amount) external; function minters(address minterAaddress) external returns (Minter memory); function minterAddresses(uint256 index) external view returns (address); function getMinters() external view returns (address[] memory); function targetPrice() external view returns (uint256); function interestRate() external view returns (int256); function periodStart() external view returns (uint256); function stepValue() external view returns (int256); function arbSpread() external view returns (uint256); function refreshInterestRate(int256 newInterestRate, uint256 newPeriodStart) external; function setTargetPrice( uint256 currentTargetPrice, uint256 nextTargetPrice ) external; function setInterestRate( int256 currentInterestRate, int256 nextInterestRate ) external; function setPeriodStart( uint256 currentPeriodStart, uint256 nextPeriodStart ) external; function startNewPeriod() external; function symbol() external view returns (string memory); function totalSupply() external view returns (uint256); function convertToUSD(uint256 amount) external view returns (uint256); function convertToSWEEP(uint256 amount) external view returns (uint256); function transfer( address recipient, uint256 amount ) external returns (bool); function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); }
{ "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_sweep","type":"address"},{"internalType":"address","name":"_base","type":"address"},{"internalType":"address","name":"_sequencer","type":"address"},{"internalType":"address","name":"_oracleBase","type":"address"},{"internalType":"uint256","name":"_oracleBaseUpdateFrequency","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"OverZero","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"usdxAmount","type":"uint256"}],"name":"Bought","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"sweepAmount","type":"uint256"}],"name":"Sold","type":"event"},{"inputs":[],"name":"base","outputs":[{"internalType":"contract IERC20Metadata","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenAmount","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"}],"name":"buySweep","outputs":[{"internalType":"uint256","name":"sweepAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"getPositions","outputs":[{"internalType":"uint256","name":"usdxAmount","type":"uint256"},{"internalType":"uint256","name":"sweepAmount","type":"uint256"},{"internalType":"uint256","name":"lp","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPrice","outputs":[{"internalType":"uint256","name":"price","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRate","outputs":[{"internalType":"uint256","name":"rate","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTWAPrice","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oracleBase","outputs":[{"internalType":"contract IPriceFeed","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oracleBaseUpdateFrequency","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pool","outputs":[{"internalType":"contract IBalancerPool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"sweepAmount","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"}],"name":"sellSweep","outputs":[{"internalType":"uint256","name":"tokenAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sequencer","outputs":[{"internalType":"contract IPriceFeed","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"poolAddress","type":"address"}],"name":"setPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint24","name":"","type":"uint24"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"}],"name":"swapExactInput","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sweep","outputs":[{"internalType":"contract ISweep","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"contract IBalancerVault","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
6101206040523480156200001257600080fd5b50604051620018f7380380620018f783398101604081905262000035916200007b565b6001600160a01b0394851660a052928416608052831660c05290911660e05261010052620000e2565b80516001600160a01b03811681146200007657600080fd5b919050565b600080600080600060a086880312156200009457600080fd5b6200009f866200005e565b9450620000af602087016200005e565b9350620000bf604087016200005e565b9250620000cf606087016200005e565b9150608086015190509295509295909350565b60805160a05160c05160e0516101005161177c6200017b6000396000818161023f015261080101526000818161021001526107e00152600081816101ba015281816107bf015261082e01526000818161015d015281816103bd015281816104470152818161047a01528181610612015281816106e2015261073f0152600081816101e1015281816103900152610859015261177c6000f3fe608060405234801561001057600080fd5b50600436106100f55760003560e01c806359879099116100975780638c60c71c116100665780638c60c71c1461026157806398d5fdca14610274578063eda28b111461027c578063fbfa77cf1461028f57600080fd5b806359879099146102035780635c1bba381461020b578063679aefce1461023257806375cdf6491461023a57600080fd5b806338da412e116100d357806338da412e1461017f5780634437152a146101a05780634562aee3146101b55780635001f3b5146101dc57600080fd5b806316f0115b146100fa57806330e005961461012a57806335faa41614610158575b600080fd5b60015461010d906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b61013d6101383660046110c8565b6102a2565b60408051938452602084019290925290820152606001610121565b61010d7f000000000000000000000000000000000000000000000000000000000000000081565b61019261018d3660046110f9565b610407565b604051908152602001610121565b6101b36101ae36600461112e565b610478565b005b61010d7f000000000000000000000000000000000000000000000000000000000000000081565b61010d7f000000000000000000000000000000000000000000000000000000000000000081565b6101926105ff565b61010d7f000000000000000000000000000000000000000000000000000000000000000081565b61019261060e565b6101927f000000000000000000000000000000000000000000000000000000000000000081565b61019261026f3660046110f9565b6106a1565b61019261070a565b61019261028a36600461114b565b610914565b60005461010d906001600160a01b031681565b600080546001546040805163038fff2d60e41b8152905184938493849384936001600160a01b039384169363f94d46689316916338fff2d09160048083019260209291908290030181865afa1580156102ff573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061032391906111ae565b6040518263ffffffff1660e01b815260040161034191815260200190565b600060405180830381865afa15801561035e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610386919081019061129d565b50915091506103b67f00000000000000000000000000000000000000000000000000000000000000008383610adb565b94506103e37f00000000000000000000000000000000000000000000000000000000000000008383610adb565b6001549094506103fd906001600160a01b03168383610adb565b9496939550505050565b60007f92f64ca637d023f354075a4be751b169c1a8a9ccb6d33cdd0cb35205439957278360405161043a91815260200190565b60405180910390a16104707f00000000000000000000000000000000000000000000000000000000000000008560008686610914565b949350505050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156104d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104fa919061136b565b6001600160a01b0316336001600160a01b03161461055f5760405162461bcd60e51b815260206004820152601b60248201527f42616c616e636572414d4d3a204e6f7420476f7665726e616e6365000000000060448201526064015b60405180910390fd5b600180546001600160a01b0319166001600160a01b038316908117909155604080516311b2515f60e31b81529051638d928af8916004808201926020929091908290030181865afa1580156105b8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105dc919061136b565b600080546001600160a01b0319166001600160a01b039290921691909117905550565b600061060961070a565b905090565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663dc38679c6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561066e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061069291906111ae565b6106099064e8d4a5100061139e565b60007f4e08ba899977cf7d4c2964bce71c6b9a7ef76ee5166a4c1249a1e08016e33ef1836040516106d491815260200190565b60405180910390a1610470847f000000000000000000000000000000000000000000000000000000000000000060008686610914565b6001546000906001600160a01b03166107255750621e848090565b600154604051632a6f500560e11b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116600483015260009216906354dea00a90602401602060405180830381865afa158015610790573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107b491906111ae565b9050601260006108257f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000610b5e565b905060006108527f0000000000000000000000000000000000000000000000000000000000000000610ca0565b905061090b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156108b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108d991906113b5565b6108e490600a6114bc565b6108ee908461139e565b6108f885846114cb565b61090390600a6114bc565b869190610d0a565b94505050505090565b600061092286333086610db9565b60005461093a9087906001600160a01b031685610ec3565b6001546040805163038fff2d60e41b815290516000926001600160a01b0316916338fff2d09160048083019260209291908290030181865afa158015610984573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109a891906111ae565b9050606060006040518060c00160405280848152602001600060018111156109d2576109d26114e4565b81526020018a6001600160a01b03168152602001896001600160a01b0316815260200187815260200183815250905060006040518060800160405280306001600160a01b03168152602001600015158152602001336001600160a01b03168152602001600015158152509050600061038461ffff1642610a5291906114fa565b6000546040516352bbbe2960e01b81529192506001600160a01b0316906352bbbe2990610a8990869086908c90879060040161155d565b6020604051808303816000875af1158015610aa8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610acc91906111ae565b9b9a5050505050505050505050565b6000805b83518160ff1610156100f557846001600160a01b0316848260ff1681518110610b0a57610b0a61163b565b60200260200101516001600160a01b031603610b4557828160ff1681518110610b3557610b3561163b565b6020026020010151915050610b57565b80610b4f81611651565b915050610adf565b9392505050565b60006001600160a01b03831615610b7857610b7883610fc3565b6000806000866001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa158015610bbb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bdf919061168f565b50935050925069ffffffffffffffffffff169250600082138015610c0257508215155b8015610c0d57508015155b610c495760405162461bcd60e51b815260206004820152600d60248201526c496e76616c696420507269636560981b6044820152606401610556565b8415610c965784610c5a82426116df565b1115610c965760405162461bcd60e51b815260206004820152600b60248201526a5374616c6520507269636560a81b6044820152606401610556565b5095945050505050565b6000816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ce0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d0491906113b5565b92915050565b6000808060001985870985870292508281108382030391505080600003610d4457838281610d3a57610d3a6116f2565b0492505050610b57565b808411610d5057600080fd5b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b1790529151600092839290881691610e1d9190611708565b6000604051808303816000865af19150503d8060008114610e5a576040519150601f19603f3d011682016040523d82523d6000602084013e610e5f565b606091505b5091509150818015610e89575080511580610e89575080806020019051810190610e899190611724565b610ebb5760405162461bcd60e51b815260206004820152600360248201526229aa2360e91b6044820152606401610556565b505050505050565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663095ea7b360e01b1790529151600092839290871691610f1f9190611708565b6000604051808303816000865af19150503d8060008114610f5c576040519150601f19603f3d011682016040523d82523d6000602084013e610f61565b606091505b5091509150818015610f8b575080511580610f8b575080806020019051810190610f8b9190611724565b610fbc5760405162461bcd60e51b8152602060048201526002602482015261534160f01b6044820152606401610556565b5050505050565b600080826001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa158015611004573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611028919061168f565b5050925092505060008213156110715760405162461bcd60e51b815260206004820152600e60248201526d29b2b8bab2b731b2b9102237bbb760911b6044820152606401610556565b610e1061107e82426116df565b116110c35760405162461bcd60e51b815260206004820152601560248201527423b930b1b2902832b934b7b2102737ba1027bb32b960591b6044820152606401610556565b505050565b6000602082840312156110da57600080fd5b5035919050565b6001600160a01b03811681146110f657600080fd5b50565b60008060006060848603121561110e57600080fd5b8335611119816110e1565b95602085013595506040909401359392505050565b60006020828403121561114057600080fd5b8135610b57816110e1565b600080600080600060a0868803121561116357600080fd5b853561116e816110e1565b9450602086013561117e816110e1565b9350604086013562ffffff8116811461119657600080fd5b94979396509394606081013594506080013592915050565b6000602082840312156111c057600080fd5b5051919050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715611206576112066111c7565b604052919050565b600067ffffffffffffffff821115611228576112286111c7565b5060051b60200190565b600082601f83011261124357600080fd5b815160206112586112538361120e565b6111dd565b82815260059290921b8401810191818101908684111561127757600080fd5b8286015b84811015611292578051835291830191830161127b565b509695505050505050565b6000806000606084860312156112b257600080fd5b835167ffffffffffffffff808211156112ca57600080fd5b818601915086601f8301126112de57600080fd5b815160206112ee6112538361120e565b82815260059290921b8401810191818101908a84111561130d57600080fd5b948201945b83861015611334578551611325816110e1565b82529482019490820190611312565b9189015191975090935050508082111561134d57600080fd5b5061135a86828701611232565b925050604084015190509250925092565b60006020828403121561137d57600080fd5b8151610b57816110e1565b634e487b7160e01b600052601160045260246000fd5b8082028115828204841417610d0457610d04611388565b6000602082840312156113c757600080fd5b815160ff81168114610b5757600080fd5b600181815b808511156114135781600019048211156113f9576113f9611388565b8085161561140657918102915b93841c93908002906113dd565b509250929050565b60008261142a57506001610d04565b8161143757506000610d04565b816001811461144d576002811461145757611473565b6001915050610d04565b60ff84111561146857611468611388565b50506001821b610d04565b5060208310610133831016604e8410600b8410161715611496575081810a610d04565b6114a083836113d8565b80600019048211156114b4576114b4611388565b029392505050565b6000610b5760ff84168361141b565b60ff8181168382160190811115610d0457610d04611388565b634e487b7160e01b600052602160045260246000fd5b80820180821115610d0457610d04611388565b60005b83811015611528578181015183820152602001611510565b50506000910152565b6000815180845261154981602086016020860161150d565b601f01601f19169290920160200192915050565b60e08152845160e0820152600060208601516002811061158d57634e487b7160e01b600052602160045260246000fd5b61010083015260408601516001600160a01b031661012083015260608601516115c26101408401826001600160a01b03169052565b50608086015161016083015260a086015160c06101808401526115e96101a0840182611531565b915050611629602083018680516001600160a01b039081168352602080830151151590840152604080830151909116908301526060908101511515910152565b60a082019390935260c0015292915050565b634e487b7160e01b600052603260045260246000fd5b600060ff821660ff810361166757611667611388565b60010192915050565b805169ffffffffffffffffffff8116811461168a57600080fd5b919050565b600080600080600060a086880312156116a757600080fd5b6116b086611670565b94506020860151935060408601519250606086015191506116d360808701611670565b90509295509295909350565b81810381811115610d0457610d04611388565b634e487b7160e01b600052601260045260246000fd5b6000825161171a81846020870161150d565b9190910192915050565b60006020828403121561173657600080fd5b81518015158114610b5757600080fdfea2646970667358221220df16a45be541fe55d5f6f5734aab801106819b11fbb1ceedd8c1e43e365e6ad064736f6c63430008130033000000000000000000000000b88a5ac00917a02d82c7cd6cebd73e2852d43574000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000bcf85224fc0756b9fa45aa7892530b47e10b64330000000000000000000000007e860098f58bbfc8648a4311b374b1d669a2bc6b0000000000000000000000000000000000000000000000000000000000015180
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000b88a5ac00917a02d82c7cd6cebd73e2852d43574000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000bcf85224fc0756b9fa45aa7892530b47e10b64330000000000000000000000007e860098f58bbfc8648a4311b374b1d669a2bc6b0000000000000000000000000000000000000000000000000000000000015180
-----Decoded View---------------
Arg [0] : _sweep (address): 0xB88a5Ac00917a02d82c7cd6CEBd73E2852d43574
Arg [1] : _base (address): 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
Arg [2] : _sequencer (address): 0xBCF85224fc0756B9Fa45aA7892530B47e10b6433
Arg [3] : _oracleBase (address): 0x7e860098F58bBFC8648a4311b374B1D669a2bc6B
Arg [4] : _oracleBaseUpdateFrequency (uint256): 86400
-----Encoded View---------------
5 Constructor Arguments found :
Arg [0] : 000000000000000000000000b88a5ac00917a02d82c7cd6cebd73e2852d43574
Arg [1] : 000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913
Arg [2] : 000000000000000000000000bcf85224fc0756b9fa45aa7892530b47e10b6433
Arg [3] : 0000000000000000000000007e860098f58bbfc8648a4311b374b1d669a2bc6b
Arg [4] : 0000000000000000000000000000000000000000000000000000000000015180
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.