Overview
ETH Balance
ETH Value
$0.00Latest 1 from a total of 1 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Set Discount | 20850122 | 6 days ago | IN | 0 ETH | 0.00000135 |
Latest 25 internal transactions (View All)
| Parent Transaction Hash | Block | From | To | ||||
|---|---|---|---|---|---|---|---|
| 21343177 | 23 hrs ago | 0 ETH | |||||
| 21343177 | 23 hrs ago | 0 ETH | |||||
| 21343177 | 23 hrs ago | 0 ETH | |||||
| 21343177 | 23 hrs ago | 0 ETH | |||||
| 21343177 | 23 hrs ago | 0 ETH | |||||
| 21028935 | 4 days ago | 0 ETH | |||||
| 21028935 | 4 days ago | 0 ETH | |||||
| 21028935 | 4 days ago | 0 ETH | |||||
| 21028935 | 4 days ago | 0 ETH | |||||
| 21028935 | 4 days ago | 0 ETH | |||||
| 20931911 | 5 days ago | 0 ETH | |||||
| 20931911 | 5 days ago | 0 ETH | |||||
| 20931911 | 5 days ago | 0 ETH | |||||
| 20931911 | 5 days ago | 0 ETH | |||||
| 20931911 | 5 days ago | 0 ETH | |||||
| 20929346 | 5 days ago | 0 ETH | |||||
| 20929346 | 5 days ago | 0 ETH | |||||
| 20929346 | 5 days ago | 0 ETH | |||||
| 20929346 | 5 days ago | 0 ETH | |||||
| 20929346 | 5 days ago | 0 ETH | |||||
| 20882559 | 6 days ago | 0 ETH | |||||
| 20882559 | 6 days ago | 0 ETH | |||||
| 20882559 | 6 days ago | 0 ETH | |||||
| 20882559 | 6 days ago | 0 ETH | |||||
| 20882559 | 6 days ago | 0 ETH |
Cross-Chain Transactions
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.21;
import {FixedPointMathLib} from "@solmate/utils/FixedPointMathLib.sol";
import {SafeTransferLib} from "@solmate/utils/SafeTransferLib.sol";
import {ERC20} from "@solmate/tokens/ERC20.sol";
import {ReentrancyGuard} from "@solmate/utils/ReentrancyGuard.sol";
import {IAtomicSolver} from "./IAtomicSolver.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {Auth, Authority} from "@solmate/auth/Auth.sol";
import {TellerWithMultiAssetSupport} from "src/base/Roles/TellerWithMultiAssetSupport.sol";
import {BoringVault} from "src/base/BoringVault.sol";
import {AccountantWithRateProviders} from "src/base/Roles/AccountantWithRateProviders.sol";
/**
* @notice Stores request information needed to fulfill a users atomic request.
* @param deadline unix timestamp for when request is no longer valid
* @param creationTime timestamp when request was created
* @param offerAmount the amount of `offer` asset the user wants converted to `want` asset
* @param user The address of the user making the request
* @param offer The address of the offer token
* @param want The address of the want token
*/
struct AtomicRequest {
uint64 deadline; // deadline to fulfill request
uint64 creationTime; // timestamp when request was created
uint96 offerAmount; // The amount of offer asset the user wants to sell.
address user; // The address of the user making the request
address offer; // The address of the offer token
address want; // The address of the want token
}
contract AtomicQueue is ReentrancyGuard, Auth {
using EnumerableSet for EnumerableSet.Bytes32Set;
using SafeTransferLib for ERC20;
using FixedPointMathLib for uint256;
// ========================================= GLOBAL STATE =========================================
/**
* @notice The set of request Ids currently in the queue.
* @dev Requests are removed when solve or cancel is called.
*/
EnumerableSet.Bytes32Set internal _existingWithdrawRequests;
/**
* @notice The maturity time of the atomic request.
*/
uint256 public maturityTime = 1 days;
/**
* @notice Mapping of request Ids to AtomicRequests.
* @dev Requests won't be removed when solve or cancel is called.
*/
mapping(bytes32 => AtomicRequest) internal onChainWithdraws;
/**
* @notice This mapping tracks the total amount of 'offer' tokens in progress for withdrawal requests per want token.
* @dev It is incremented when a new request is submitted and decremented when the request is fulfilled or cancelled.
*/
mapping(address => mapping(address => uint256)) public withdrawInProgressAmount;
/**
* @notice Mapping to track whitelisted addresses, which can be solved quickly.
*/
mapping(address => bool) public whitelist;
/**
* @notice The accountant contract to use for withdrawal
*/
AccountantWithRateProviders public immutable accountant;
/**
* @notice The divisor used to reduce maturity time for whitelisted users.
*/
uint256 public whitelistMaturityDivisor = 10;
/**
* @notice The discount(redemption fee) in parts-per-million (0.05% => 500)
*/
uint256 public discount = 500; // 0.05% (ppm)
/**
* @notice Denominator for discount calculations (parts-per-million)
*/
uint256 private constant DISCOUNT_DENOMINATOR = 1e6;
//============================== ERRORS ===============================
error AtomicQueue__BadWhitelistDivisor();
error AtomicQueue__BadDiscount();
error AtomicQueue__RemovedRequest();
error AtomicQueue__DuplicateRequest();
error AtomicQueue__OfferAmountIsZero();
error AtomicQueue__UserAddressIsZero();
error AtomicQueue__OfferAddressIsZero();
error AtomicQueue__WantAddressIsZero();
error AtomicQueue__InsufficientBalance();
error AtomicQueue__DeadlineExpired();
error AtomicQueue__RequestAccountantOfferMismatch(address offer, address vault);
error AtomicQueue__BadUser();
error AtomicQueue__BoringVaultTellerMismatch(address vault, address teller);
error AtomicQueue__ZeroOfferAmount(address user);
error AtomicQueue__InsufficientVaultLiquidity(uint256 required, uint256 available);
error AtomicQueue__RequestNotMature(address user);
error AtomicQueue__MinimumAssetsNotMet();
error AtomicQueue__InstantWithdrawShortfall(uint256 expected, uint256 actual);
error AtomicQueue__InsufficientBalanceInUserWallet(address user, uint256 required, uint256 available);
error AtomicQueue__UnauthorizedSolver(address caller);
//============================== EVENTS ===============================
/**
* @notice Emitted when `setMaturityTime` is called.
*/
event MaturityTimeUpdated(uint256 oldMaturityTime, uint256 newMaturityTime);
/**
* @notice Emitted when `updateAtomicRequest` is called.
*/
event AtomicRequestUpdated(
bytes32 indexed requestId,
address indexed user,
address offerToken,
address indexed wantToken,
uint256 amount,
uint256 deadline,
uint256 timestamp
);
/**
* @notice Emitted when `solve` exchanges a users offer asset for their want asset.
*/
event AtomicRequestFulfilled(
bytes32 indexed requestId,
address indexed user,
address offerToken,
address indexed wantToken,
uint256 offerAmountSpent,
uint256 wantAmountReceived,
uint256 timestamp
);
/**
* @notice Emitted when `cancelAtomicRequest` is called.
*/
event AtomicRequestCancelled(
bytes32 indexed requestId,
address indexed user,
address offerToken,
address indexed wantToken,
uint256 amount,
uint256 deadline,
uint256 timestamp
);
/**
* @notice Emitted when `instantWithdraw` is called.
*/
event InstantWithdraw(
address indexed user,
address indexed offerToken,
address indexed wantToken,
uint256 offerAmount,
uint256 wantAmount,
uint256 timestamp
);
/**
* @notice Emitted when `addToWhitelist` is called.
*/
event WhitelistAdded(address indexed user);
/**
* @notice Emitted when `removeFromWhitelist` is called.
*/
event WhitelistRemoved(address indexed user);
/**
* @notice Emitted when `updateWhitelistMaturityDivisor` is called.
*/
event WhitelistMaturityDivisorUpdated(uint256 newDivisor);
/**
* @notice Emitted when `setDiscount` is called.
*/
event DiscountUpdated(uint256 newDiscount);
/**
* @notice Emitted when `setSolver` is called.
*/
event SolverUpdated(address newSolver);
//============================== VARIABLES ===============================
/**
* @notice The solver contract to use for solving
*/
IAtomicSolver public solver;
/**
* @notice Constructor
* @param _owner The owner of the contract
* @param _authority The authority of the contract
* @param _accountant The accountant contract to use for withdrawal
* @param _solver The solver contract to use for solving
*/
constructor(address _owner, Authority _authority, address _accountant, address _solver) Auth(_owner, _authority) {
accountant = AccountantWithRateProviders(_accountant);
solver = IAtomicSolver(_solver);
}
//============================== ADMIN FUNCTIONS ===============================
/**
* @notice Allows the owner to update the maturity time
* @param newMaturityTime The new maturity time in seconds
*/
function setMaturityTime(uint256 newMaturityTime) external requiresAuth {
uint256 oldMaturityTime = maturityTime;
maturityTime = newMaturityTime;
emit MaturityTimeUpdated(oldMaturityTime, newMaturityTime);
}
/**
* @notice Allows the owner to update the discount
* @param newDiscount The new discount in parts-per-million (500 = 0.05%)
*/
function setDiscount(uint256 newDiscount) external requiresAuth {
if (newDiscount >= DISCOUNT_DENOMINATOR) revert AtomicQueue__BadDiscount();
discount = newDiscount;
emit DiscountUpdated(newDiscount);
}
/**
* @notice Add an address to the whitelist.
* @dev Callable by MULTISIG_ROLE.
* @param user The address to add to the whitelist.
*/
function addToWhitelist(address user) external requiresAuth {
if (user == address(0)) revert AtomicQueue__UserAddressIsZero();
whitelist[user] = true;
emit WhitelistAdded(user);
}
/**
* @notice Remove an address from the whitelist.
* @dev Callable by MULTISIG_ROLE.
* @param user The address to remove from the whitelist.
*/
function removeFromWhitelist(address user) external requiresAuth {
if (user == address(0)) revert AtomicQueue__UserAddressIsZero();
whitelist[user] = false;
emit WhitelistRemoved(user);
}
/**
* @notice Update the whitelist maturity divisor.
* @dev Callable by MULTISIG_ROLE.
* @param newDivisor The new divisor value.
*/
function updateWhitelistMaturityDivisor(uint256 newDivisor) external requiresAuth {
if (newDivisor == 0) revert AtomicQueue__BadWhitelistDivisor();
whitelistMaturityDivisor = newDivisor;
emit WhitelistMaturityDivisorUpdated(newDivisor);
}
/**
* @notice Allows the owner to update the solver contract
* @dev Callable by MULTISIG_ROLE.
* @param newSolver The new solver contract address.
*/
function setSolver(address newSolver) external requiresAuth {
solver = IAtomicSolver(newSolver);
emit SolverUpdated(newSolver);
}
/**
* @notice Allows the admin to cancel multiple withdraw requests.
* @dev Callable by MULTISIG_ROLE.
* @param userRequests The array of user requests to cancel.
*/
function cancelAtomicRequestByAdmin(AtomicRequest[] calldata userRequests) external requiresAuth {
for (uint256 i = 0; i < userRequests.length; ++i) {
AtomicRequest calldata userRequest = userRequests[i];
bytes32 requestId = keccak256(abi.encode(userRequest));
if (!_existingWithdrawRequests.contains(requestId)) revert AtomicQueue__RemovedRequest();
withdrawInProgressAmount[userRequest.offer][userRequest.want] -= userRequest.offerAmount;
_existingWithdrawRequests.remove(requestId);
// Transfer offer shares from solver contract to user
IAtomicSolver(solver).approveOfferForQueue(address(this), userRequest);
ERC20(userRequest.offer).safeTransferFrom(address(solver), userRequest.user, userRequest.offerAmount);
emit AtomicRequestCancelled(
requestId,
userRequest.user,
userRequest.offer,
userRequest.want,
userRequest.offerAmount,
userRequest.deadline,
block.timestamp
);
}
}
//============================== VIEW FUNCTIONS ===============================
/**
* @notice Get the total amount of 'offer' tokens in progress for withdrawal requests for a specific want token.
* @param offer The address of the offer token.
* @param want The address of the want token.
* @return The total amount of 'offer' tokens in progress for withdrawal requests for the specified want token.
*/
function getTotalWithdrawInProgressAmount(address offer, address want) external view returns (uint256) {
return withdrawInProgressAmount[offer][want];
}
/**
* @notice Get all existing withdraw request Ids currently in the queue.
* @dev Includes requests that are not mature, matured, and expired. But does not include requests that have been solved.
* @return requestIds The request Ids.
*/
function getExistingWithdrawRequestIds() public view returns (bytes32[] memory) {
return _existingWithdrawRequests.values();
}
/**
* @notice Get all existing withdraw requests.
* @dev Includes requests that are not mature, matured, and expired. But does not include requests that have been solved.
*/
function getExistingWithdrawRequests()
external
view
returns (bytes32[] memory requestIds, AtomicRequest[] memory requests)
{
requestIds = getExistingWithdrawRequestIds();
uint256 requestsLength = requestIds.length;
requests = new AtomicRequest[](requestsLength);
for (uint256 i = 0; i < requestsLength; ) {
requests[i] = onChainWithdraws[requestIds[i]];
unchecked { ++i; }
}
}
/**
* @notice Get all existing withdraw requests by user.
* @dev Includes requests that are not mature, matured, and expired. But does not include requests that have been solved.
* @param user The address of the user.
* @return requestIds The request Ids.
* @return requests The requests.
*/
function getExistingWithdrawRequestsByUser(address user)
external
view
returns (bytes32[] memory requestIds, AtomicRequest[] memory requests)
{
bytes32[] memory allExistingWithdrawRequestIds = getExistingWithdrawRequestIds();
uint256 allExistingWithdrawRequestsLength = allExistingWithdrawRequestIds.length;
// First pass: count how many requests belong to this user
uint256 userRequestCount = 0;
for (uint256 i = 0; i < allExistingWithdrawRequestsLength; ) {
if (onChainWithdraws[allExistingWithdrawRequestIds[i]].user == user) {
userRequestCount++;
}
unchecked { ++i; }
}
// Initialize arrays with the correct size
requestIds = new bytes32[](userRequestCount);
requests = new AtomicRequest[](userRequestCount);
// Second pass: populate the arrays with user's requests
uint256 index = 0;
for (uint256 i = 0; i < allExistingWithdrawRequestsLength; ) {
bytes32 requestId = allExistingWithdrawRequestIds[i];
AtomicRequest memory request = onChainWithdraws[requestId];
if (request.user == user) {
requestIds[index] = requestId;
requests[index] = request;
unchecked { ++index; }
}
unchecked { ++i; }
}
}
/**
* @notice Get a withdraw request by request Id.
* @dev Does verify nonce is non-zero.
* @param requestId The request Id.
* @return request The request.
*/
function getAtomicRequestById(bytes32 requestId) public view returns (AtomicRequest memory) {
return onChainWithdraws[requestId];
}
/**
* @notice Preview the amount of want assets that would be received for an atomic request.
* @dev This is a view function that calculates the expected output without executing the transaction.
* @param request The atomic request to preview.
* @return wantAmountReceived The expected amount of want assets to be received.
*/
function previewReceivedAmount(AtomicRequest calldata request) external view returns (uint256 wantAmountReceived) {
// Basic validation (similar to checkAtomicRequestValid but without queue existence check)
if (request.offerAmount == 0) revert AtomicQueue__OfferAmountIsZero();
if (request.user == address(0)) revert AtomicQueue__UserAddressIsZero();
if (request.offer == address(0)) revert AtomicQueue__OfferAddressIsZero();
if (request.want == address(0)) revert AtomicQueue__WantAddressIsZero();
if (block.timestamp > request.deadline) revert AtomicQueue__DeadlineExpired();
// Get the offer token decimals
ERC20 offer = ERC20(request.offer);
uint8 offerDecimals = offer.decimals();
// Get the rate and apply discount (same logic as in solve function)
uint256 safeRate = accountant.getRateInQuoteSafe(ERC20(request.want));
uint256 safeAtomicPriceWithDiscount = safeRate.mulDivDown(DISCOUNT_DENOMINATOR - discount, DISCOUNT_DENOMINATOR);
// Calculate the want amount
wantAmountReceived = _calculateAssetAmount(request.offerAmount, safeAtomicPriceWithDiscount, offerDecimals);
}
//============================== HELPER FUNCTIONS ===============================
/**
* @notice Helper function that validates a withdraw request.
* @dev Reverts with specific error if the request is invalid.
* It is possible for a withdraw request to pass validation here, but solvers
* may not be able to include the user in `solve` unless some other state is changed.
* @param userRequest the full request struct to validate (should have correct .offer, .want, .user fields)
*/
function checkAtomicRequestValid(AtomicRequest calldata userRequest)
public
view
{
bytes32 requestId = keccak256(abi.encode(userRequest));
if (!_existingWithdrawRequests.contains(requestId)) revert AtomicQueue__RemovedRequest();
address requestUser = userRequest.user;
ERC20 offer = ERC20(userRequest.offer);
// Validate offerAmount is nonzero.
if (userRequest.offerAmount == 0) revert AtomicQueue__OfferAmountIsZero();
// Validate user address is not zero.
if (requestUser == address(0)) revert AtomicQueue__UserAddressIsZero();
// Validate offer address is not zero.
if (address(offer) == address(0)) revert AtomicQueue__OfferAddressIsZero();
// Validate want address is not zero.
if (userRequest.want == address(0)) revert AtomicQueue__WantAddressIsZero();
// Validate deadline.
if (block.timestamp > userRequest.deadline) revert AtomicQueue__DeadlineExpired();
}
//============================== USER FUNCTIONS ===============================
/**
* @notice Allows user to add their withdraw request.
* @dev This function will completely ignore the provided atomic price and calculate a new one based off the
* the accountant rate in quote.
* @param userRequest the users request
*/
function updateAtomicRequest(AtomicRequest memory userRequest) external nonReentrant returns (bytes32) {
if (userRequest.offer != address(accountant.vault())) revert AtomicQueue__RequestAccountantOfferMismatch(address(userRequest.offer), address(accountant.vault()));
if (userRequest.user != msg.sender) revert AtomicQueue__BadUser();
// try to gate rate from the accountant, should revert if the want token is not supported
accountant.getRateInQuoteSafe(ERC20(userRequest.want));
// Normalize creation time to prevent bypassing maturity
userRequest.creationTime = uint64(block.timestamp);
// Validate basic fields at submission time
if (userRequest.offerAmount == 0) revert AtomicQueue__OfferAmountIsZero();
if (userRequest.offer == address(0)) revert AtomicQueue__OfferAddressIsZero();
if (userRequest.want == address(0)) revert AtomicQueue__WantAddressIsZero();
if (userRequest.offerAmount > ERC20(userRequest.offer).balanceOf(userRequest.user)) revert AtomicQueue__InsufficientBalance();
if (block.timestamp > userRequest.deadline) revert AtomicQueue__DeadlineExpired();
bytes32 requestId = keccak256(abi.encode(userRequest));
if (!_existingWithdrawRequests.add(requestId)) revert AtomicQueue__DuplicateRequest();
onChainWithdraws[requestId] = userRequest;
withdrawInProgressAmount[userRequest.offer][userRequest.want] += userRequest.offerAmount;
// Transfer offer shares from user to solver contract
ERC20(userRequest.offer).safeTransferFrom(userRequest.user, address(solver), userRequest.offerAmount);
emit AtomicRequestUpdated(
requestId,
msg.sender,
userRequest.offer,
userRequest.want,
userRequest.offerAmount,
userRequest.deadline,
block.timestamp
);
return requestId;
}
/**
* @notice Allows user to cancel their withdraw request.
* @param userRequest the user's request
*/
function cancelAtomicRequest(AtomicRequest calldata userRequest) external {
if (userRequest.user != msg.sender) revert AtomicQueue__BadUser();
bytes32 requestId = keccak256(abi.encode(userRequest));
if (!_existingWithdrawRequests.contains(requestId)) revert AtomicQueue__RemovedRequest();
withdrawInProgressAmount[userRequest.offer][userRequest.want] -= userRequest.offerAmount;
_existingWithdrawRequests.remove(requestId);
// Transfer offer shares from solver contract to user
IAtomicSolver(solver).approveOfferForQueue(address(this), userRequest);
ERC20(userRequest.offer).safeTransferFrom(address(solver), userRequest.user, userRequest.offerAmount);
emit AtomicRequestCancelled(
requestId,
userRequest.user,
userRequest.offer,
userRequest.want,
userRequest.offerAmount,
userRequest.deadline,
block.timestamp
);
}
/**
* @notice Allows role granted users to instantly withdraw without going through the request queue.
* @dev Callable by role granted users only.
* @dev Ensures that the withdrawal amount plus pending queue withdrawals don't exceed vault liquidity.
* @param offer The vault share token to burn
* @param want The underlying asset to receive
* @param offerAmount Amount of shares to withdraw
* @param minimumAssetsOut Minimum amount of assets expected
* @param teller The teller contract to use for withdrawal
*/
function instantWithdraw(
ERC20 offer,
ERC20 want,
uint256 offerAmount,
uint256 minimumAssetsOut,
TellerWithMultiAssetSupport teller
) external nonReentrant requiresAuth returns (uint256 assetsOut) {
// Validate inputs
if (offerAmount == 0) revert AtomicQueue__ZeroOfferAmount(msg.sender);
// Get vault from accountant
BoringVault vault = accountant.vault();
if (address(offer) != address(vault)) revert AtomicQueue__RequestAccountantOfferMismatch(address(offer), address(vault));
if (address(offer) != address(teller.vault())) revert AtomicQueue__BoringVaultTellerMismatch(address(offer), address(teller));
uint256 ONE_SHARE = 10 ** offer.decimals();
// Calculate assets that will be withdrawn
assetsOut = offerAmount.mulDivDown(
accountant.getRateInQuoteSafe(want),
ONE_SHARE
);
uint256 assetOutWithDiscount = assetsOut.mulDivDown(DISCOUNT_DENOMINATOR - discount, DISCOUNT_DENOMINATOR);
// Calculate assets needed for pending withdrawal requests for this want token
uint256 pendingWithdrawAssets = withdrawInProgressAmount[address(offer)][address(want)].mulDivDown(
accountant.getRateInQuoteSafe(want),
ONE_SHARE
);
// Check vault has enough liquidity
uint256 vaultBalance = want.balanceOf(address(vault));
uint256 totalRequired = assetOutWithDiscount + pendingWithdrawAssets;
if (totalRequired > vaultBalance) {
revert AtomicQueue__InsufficientVaultLiquidity(totalRequired, vaultBalance);
}
// Ensure minimum output is met
if (assetOutWithDiscount < minimumAssetsOut) {
revert AtomicQueue__MinimumAssetsNotMet();
}
// Transfer shares from user to this contract
offer.safeTransferFrom(msg.sender, address(this), offerAmount);
// Execute withdrawal through teller
assetsOut = teller.bulkWithdraw(want, offerAmount, minimumAssetsOut, address(this));
if (assetsOut < assetOutWithDiscount) {
revert AtomicQueue__InstantWithdrawShortfall(assetOutWithDiscount, assetsOut);
}
uint256 excessAssets = assetsOut - assetOutWithDiscount;
if (excessAssets > 0) {
want.safeTransfer(address(vault), excessAssets);
}
want.safeTransfer(msg.sender, assetOutWithDiscount);
assetsOut = assetOutWithDiscount;
emit InstantWithdraw(
msg.sender,
address(offer),
address(want),
offerAmount,
assetOutWithDiscount,
block.timestamp
);
}
//============================== SOLVER FUNCTIONS ===============================
/**
* @notice Called by solvers in order to exchange offer asset for want asset.
* @notice Solvers are optimistically transferred the offer asset, then are required to
* approve this contract to spend enough of want assets to cover the request.
* @dev It is very likely `solve` TXs will be front run if broadcasted to public mem pools,
* so solvers should use private mem pools.
* @param runData extra data that is passed back to solver when `finishSolve` is called
* @param request the atomic request to solve
*/
function solve(
bytes calldata runData,
AtomicRequest calldata request
) external nonReentrant {
ERC20 offer = ERC20(request.offer);
ERC20 want = ERC20(request.want);
address user = request.user;
// Save offer asset decimals.
uint8 offerDecimals = offer.decimals();
checkAtomicRequestValid(request);
// Check maturity time
if (
block.timestamp
< request.creationTime
+ (whitelist[user] ? maturityTime / whitelistMaturityDivisor : maturityTime)
) {
revert AtomicQueue__RequestNotMature(user);
}
// Check if the caller is the solver
if (msg.sender != address(solver)) revert AtomicQueue__UnauthorizedSolver(msg.sender);
uint256 safeRate = accountant.getRateInQuoteSafe(ERC20(request.want));
uint256 safeAtomicPriceWithDiscount = safeRate.mulDivDown(DISCOUNT_DENOMINATOR - discount, DISCOUNT_DENOMINATOR);
// Calculate want assets needed
uint256 assetsForWant = _calculateAssetAmount(request.offerAmount, safeAtomicPriceWithDiscount, offerDecimals);
// // Transfer offer shares from user to solver contract
// offer.safeTransferFrom(user, solver, request.offerAmount);
// Call solver contract to finish the solve
IAtomicSolver(solver).finishSolve(runData, msg.sender, offer, want, request.offerAmount, assetsForWant, address(accountant.vault()));
// Transfer want assets from solver contract to user
want.safeTransferFrom(address(solver), user, assetsForWant);
// Decrease the withdraw in progress amount
withdrawInProgressAmount[address(offer)][address(want)] -= request.offerAmount;
bytes32 requestId = keccak256(abi.encode(request));
// Emit event
emit AtomicRequestFulfilled(
requestId, user, address(offer), address(want), request.offerAmount, assetsForWant, block.timestamp
);
// Remove request from queue
_existingWithdrawRequests.remove(requestId);
}
//============================== INTERNAL FUNCTIONS ===============================
/**
* @notice Helper function to calculate the amount of want assets a users wants in exchange for
* `offerAmount` of offer asset.
*/
function _calculateAssetAmount(uint256 offerAmount, uint256 atomicPrice, uint8 offerDecimals)
internal
pure
returns (uint256)
{
return atomicPrice.mulDivDown(offerAmount, 10 ** offerDecimals);
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Arithmetic library with operations for fixed-point numbers.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol)
/// @author Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol)
library FixedPointMathLib {
/*//////////////////////////////////////////////////////////////
SIMPLIFIED FIXED POINT OPERATIONS
//////////////////////////////////////////////////////////////*/
uint256 internal constant MAX_UINT256 = 2**256 - 1;
uint256 internal constant WAD = 1e18; // The scalar of ETH and most ERC20s.
function mulWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivDown(x, y, WAD); // Equivalent to (x * y) / WAD rounded down.
}
function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivUp(x, y, WAD); // Equivalent to (x * y) / WAD rounded up.
}
function divWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivDown(x, WAD, y); // Equivalent to (x * WAD) / y rounded down.
}
function divWadUp(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivUp(x, WAD, y); // Equivalent to (x * WAD) / y rounded up.
}
/*//////////////////////////////////////////////////////////////
LOW LEVEL FIXED POINT OPERATIONS
//////////////////////////////////////////////////////////////*/
function mulDivDown(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to require(denominator != 0 && (y == 0 || x <= type(uint256).max / y))
if iszero(mul(denominator, iszero(mul(y, gt(x, div(MAX_UINT256, y)))))) {
revert(0, 0)
}
// Divide x * y by the denominator.
z := div(mul(x, y), denominator)
}
}
function mulDivUp(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to require(denominator != 0 && (y == 0 || x <= type(uint256).max / y))
if iszero(mul(denominator, iszero(mul(y, gt(x, div(MAX_UINT256, y)))))) {
revert(0, 0)
}
// If x * y modulo the denominator is strictly greater than 0,
// 1 is added to round up the division of x * y by the denominator.
z := add(gt(mod(mul(x, y), denominator), 0), div(mul(x, y), denominator))
}
}
function rpow(
uint256 x,
uint256 n,
uint256 scalar
) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
switch x
case 0 {
switch n
case 0 {
// 0 ** 0 = 1
z := scalar
}
default {
// 0 ** n = 0
z := 0
}
}
default {
switch mod(n, 2)
case 0 {
// If n is even, store scalar in z for now.
z := scalar
}
default {
// If n is odd, store x in z for now.
z := x
}
// Shifting right by 1 is like dividing by 2.
let half := shr(1, scalar)
for {
// Shift n right by 1 before looping to halve it.
n := shr(1, n)
} n {
// Shift n right by 1 each iteration to halve it.
n := shr(1, n)
} {
// Revert immediately if x ** 2 would overflow.
// Equivalent to iszero(eq(div(xx, x), x)) here.
if shr(128, x) {
revert(0, 0)
}
// Store x squared.
let xx := mul(x, x)
// Round to the nearest number.
let xxRound := add(xx, half)
// Revert if xx + half overflowed.
if lt(xxRound, xx) {
revert(0, 0)
}
// Set x to scaled xxRound.
x := div(xxRound, scalar)
// If n is even:
if mod(n, 2) {
// Compute z * x.
let zx := mul(z, x)
// If z * x overflowed:
if iszero(eq(div(zx, x), z)) {
// Revert if x is non-zero.
if iszero(iszero(x)) {
revert(0, 0)
}
}
// Round to the nearest number.
let zxRound := add(zx, half)
// Revert if zx + half overflowed.
if lt(zxRound, zx) {
revert(0, 0)
}
// Return properly scaled zxRound.
z := div(zxRound, scalar)
}
}
}
}
}
/*//////////////////////////////////////////////////////////////
GENERAL NUMBER UTILITIES
//////////////////////////////////////////////////////////////*/
function sqrt(uint256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
let y := x // We start y at x, which will help us make our initial estimate.
z := 181 // The "correct" value is 1, but this saves a multiplication later.
// This segment is to get a reasonable initial estimate for the Babylonian method. With a bad
// start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.
// We check y >= 2^(k + 8) but shift right by k bits
// each branch to ensure that if x >= 256, then y >= 256.
if iszero(lt(y, 0x10000000000000000000000000000000000)) {
y := shr(128, y)
z := shl(64, z)
}
if iszero(lt(y, 0x1000000000000000000)) {
y := shr(64, y)
z := shl(32, z)
}
if iszero(lt(y, 0x10000000000)) {
y := shr(32, y)
z := shl(16, z)
}
if iszero(lt(y, 0x1000000)) {
y := shr(16, y)
z := shl(8, z)
}
// Goal was to get z*z*y within a small factor of x. More iterations could
// get y in a tighter range. Currently, we will have y in [256, 256*2^16).
// We ensured y >= 256 so that the relative difference between y and y+1 is small.
// That's not possible if x < 256 but we can just verify those cases exhaustively.
// Now, z*z*y <= x < z*z*(y+1), and y <= 2^(16+8), and either y >= 256, or x < 256.
// Correctness can be checked exhaustively for x < 256, so we assume y >= 256.
// Then z*sqrt(y) is within sqrt(257)/sqrt(256) of sqrt(x), or about 20bps.
// For s in the range [1/256, 256], the estimate f(s) = (181/1024) * (s+1) is in the range
// (1/2.84 * sqrt(s), 2.84 * sqrt(s)), with largest error when s = 1 and when s = 256 or 1/256.
// Since y is in [256, 256*2^16), let a = y/65536, so that a is in [1/256, 256). Then we can estimate
// sqrt(y) using sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2^18.
// There is no overflow risk here since y < 2^136 after the first branch above.
z := shr(18, mul(z, add(y, 65536))) // A mul() is saved from starting z at 181.
// Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough.
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
// If x+1 is a perfect square, the Babylonian method cycles between
// floor(sqrt(x)) and ceil(sqrt(x)). This statement ensures we return floor.
// See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division
// Since the ceil is rare, we save gas on the assignment and repeat division in the rare case.
// If you don't care whether the floor or ceil square root is returned, you can remove this statement.
z := sub(z, lt(div(x, z), z))
}
}
function unsafeMod(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Mod x by y. Note this will return
// 0 instead of reverting if y is zero.
z := mod(x, y)
}
}
function unsafeDiv(uint256 x, uint256 y) internal pure returns (uint256 r) {
/// @solidity memory-safe-assembly
assembly {
// Divide x by y. Note this will return
// 0 instead of reverting if y is zero.
r := div(x, y)
}
}
function unsafeDivUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Add 1 to x * y if x % y > 0. Note this will
// return 0 instead of reverting if y is zero.
z := add(gt(mod(x, y), 0), div(x, y))
}
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
import {ERC20} from "../tokens/ERC20.sol";
/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
/// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.
library SafeTransferLib {
/*//////////////////////////////////////////////////////////////
ETH OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferETH(address to, uint256 amount) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Transfer the ETH and store if it succeeded or not.
success := call(gas(), to, amount, 0, 0, 0, 0)
}
require(success, "ETH_TRANSFER_FAILED");
}
/*//////////////////////////////////////////////////////////////
ERC20 OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferFrom(
ERC20 token,
address from,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(from, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "from" argument.
mstore(add(freeMemoryPointer, 36), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)
)
}
require(success, "TRANSFER_FROM_FAILED");
}
function safeTransfer(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "TRANSFER_FAILED");
}
function safeApprove(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "APPROVE_FAILED");
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
/*//////////////////////////////////////////////////////////////
METADATA STORAGE
//////////////////////////////////////////////////////////////*/
string public name;
string public symbol;
uint8 public immutable decimals;
/*//////////////////////////////////////////////////////////////
ERC20 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
/*//////////////////////////////////////////////////////////////
EIP-2612 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 internal immutable INITIAL_CHAIN_ID;
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
mapping(address => uint256) public nonces;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
INITIAL_CHAIN_ID = block.chainid;
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
}
/*//////////////////////////////////////////////////////////////
ERC20 LOGIC
//////////////////////////////////////////////////////////////*/
function approve(address spender, uint256 amount) public virtual returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transfer(address to, uint256 amount) public virtual returns (bool) {
balanceOf[msg.sender] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual returns (bool) {
uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.
if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
balanceOf[from] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
/*//////////////////////////////////////////////////////////////
EIP-2612 LOGIC
//////////////////////////////////////////////////////////////*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");
// Unchecked because the only math done is incrementing
// the owner's nonce which cannot realistically overflow.
unchecked {
address recoveredAddress = ecrecover(
keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
),
owner,
spender,
value,
nonces[owner]++,
deadline
)
)
)
),
v,
r,
s
);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");
allowance[recoveredAddress][spender] = value;
}
emit Approval(owner, spender, value);
}
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
}
function computeDomainSeparator() internal view virtual returns (bytes32) {
return
keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}
/*//////////////////////////////////////////////////////////////
INTERNAL MINT/BURN LOGIC
//////////////////////////////////////////////////////////////*/
function _mint(address to, uint256 amount) internal virtual {
totalSupply += amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(address(0), to, amount);
}
function _burn(address from, uint256 amount) internal virtual {
balanceOf[from] -= amount;
// Cannot underflow because a user's balance
// will never be larger than the total supply.
unchecked {
totalSupply -= amount;
}
emit Transfer(from, address(0), amount);
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Gas optimized reentrancy protection for smart contracts.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/ReentrancyGuard.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/ReentrancyGuard.sol)
abstract contract ReentrancyGuard {
uint256 private locked = 1;
modifier nonReentrant() virtual {
require(locked == 1, "REENTRANCY");
locked = 2;
_;
locked = 1;
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;
import { ERC20 } from "@solmate/tokens/ERC20.sol";
import { AtomicRequest, AtomicQueue } from "./AtomicQueue.sol";
interface IAtomicSolver {
/**
* @notice This function must be implemented in order for an address to be a `solver`
* for the AtomicQueue
* @param runData arbitrary bytes data that is dependent on how each solver is setup
* it could contain swap data, or flash loan data, etc..
* @param initiator the address that initiated a solve
* @param offer the ERC20 asset sent to the solver
* @param want the ERC20 asset the solver must approve the queue for
* @param assetsToOffer the amount of `offer` sent to the solver
* @param assetsForWant the amount of `want` the solver must approve the queue for
* @param vault the address of the vault
*/
function finishSolve(
bytes calldata runData,
address initiator,
ERC20 offer,
ERC20 want,
uint256 assetsToOffer,
uint256 assetsForWant,
address vault
) external;
/**
* @notice Approve the offer for the queue to spend
* @param queue the address of the queue
* @param request the atomic request to approve
*/
function approveOfferForQueue(
address queue,
AtomicRequest calldata request
) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.20;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position is the index of the value in the `values` array plus 1.
// Position 0 is used to mean a value is not in the set.
mapping(bytes32 value => uint256) _positions;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._positions[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We cache the value's position to prevent multiple reads from the same storage slot
uint256 position = set._positions[value];
if (position != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 valueIndex = position - 1;
uint256 lastIndex = set._values.length - 1;
if (valueIndex != lastIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the lastValue to the index where the value to delete is
set._values[valueIndex] = lastValue;
// Update the tracked position of the lastValue (that was just moved)
set._positions[lastValue] = position;
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the tracked position for the deleted slot
delete set._positions[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._positions[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Provides a flexible and updatable auth pattern which is completely separate from application logic.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
abstract contract Auth {
event OwnershipTransferred(address indexed user, address indexed newOwner);
event AuthorityUpdated(address indexed user, Authority indexed newAuthority);
address public owner;
Authority public authority;
constructor(address _owner, Authority _authority) {
owner = _owner;
authority = _authority;
emit OwnershipTransferred(msg.sender, _owner);
emit AuthorityUpdated(msg.sender, _authority);
}
modifier requiresAuth() virtual {
require(isAuthorized(msg.sender, msg.sig), "UNAUTHORIZED");
_;
}
function isAuthorized(address user, bytes4 functionSig) internal view virtual returns (bool) {
Authority auth = authority; // Memoizing authority saves us a warm SLOAD, around 100 gas.
// Checking if the caller is the owner only after calling the authority saves gas in most cases, but be
// aware that this makes protected functions uncallable even to the owner if the authority is out of order.
return (address(auth) != address(0) && auth.canCall(user, address(this), functionSig)) || user == owner;
}
function setAuthority(Authority newAuthority) public virtual {
// We check if the caller is the owner first because we want to ensure they can
// always swap out the authority even if it's reverting or using up a lot of gas.
require(msg.sender == owner || authority.canCall(msg.sender, address(this), msg.sig));
authority = newAuthority;
emit AuthorityUpdated(msg.sender, newAuthority);
}
function transferOwnership(address newOwner) public virtual requiresAuth {
owner = newOwner;
emit OwnershipTransferred(msg.sender, newOwner);
}
}
/// @notice A generic interface for a contract which provides authorization data to an Auth instance.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
interface Authority {
function canCall(
address user,
address target,
bytes4 functionSig
) external view returns (bool);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
import {ERC20} from "@solmate/tokens/ERC20.sol";
import {WETH} from "@solmate/tokens/WETH.sol";
import {BoringVault} from "src/base/BoringVault.sol";
import {AccountantWithRateProviders} from "src/base/Roles/AccountantWithRateProviders.sol";
import {FixedPointMathLib} from "@solmate/utils/FixedPointMathLib.sol";
import {SafeTransferLib} from "@solmate/utils/SafeTransferLib.sol";
import {BeforeTransferHook} from "src/interfaces/BeforeTransferHook.sol";
import {Auth, Authority} from "@solmate/auth/Auth.sol";
import {ReentrancyGuard} from "@solmate/utils/ReentrancyGuard.sol";
contract TellerWithMultiAssetSupport is Auth, BeforeTransferHook, ReentrancyGuard {
using FixedPointMathLib for uint256;
using SafeTransferLib for ERC20;
using SafeTransferLib for WETH;
// ========================================= CONSTANTS =========================================
/**
* @notice Native address used to tell the contract to handle native asset deposits.
*/
address internal constant NATIVE = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
/**
* @notice The maximum possible share lock period.
*/
uint256 internal constant MAX_SHARE_LOCK_PERIOD = 3 days;
// ========================================= STATE =========================================
/**
* @notice Mapping ERC20s to an isSupported bool.
*/
mapping(ERC20 => bool) public isSupported;
/**
* @notice The deposit nonce used to map to a deposit hash.
*/
uint96 public depositNonce = 1;
/**
* @notice After deposits, shares are locked to the msg.sender's address
* for `shareLockPeriod`.
* @dev During this time all trasnfers from msg.sender will revert, and
* deposits are refundable.
*/
uint64 public shareLockPeriod;
/**
* @notice Used to pause calls to `deposit` and `depositWithPermit`.
*/
bool public isPaused;
/**
* @dev Maps deposit nonce to keccak256(address receiver, address depositAsset, uint256 depositAmount, uint256 shareAmount, uint256 timestamp, uint256 shareLockPeriod).
*/
mapping(uint256 => bytes32) public publicDepositHistory;
/**
* @notice Maps user address to the time their shares will be unlocked.
*/
mapping(address => uint256) public shareUnlockTime;
//============================== ERRORS ===============================
error TellerWithMultiAssetSupport__ShareLockPeriodTooLong();
error TellerWithMultiAssetSupport__SharesAreLocked();
error TellerWithMultiAssetSupport__SharesAreUnLocked();
error TellerWithMultiAssetSupport__BadDepositHash();
error TellerWithMultiAssetSupport__AssetNotSupported();
error TellerWithMultiAssetSupport__ZeroAssets();
error TellerWithMultiAssetSupport__MinimumMintNotMet();
error TellerWithMultiAssetSupport__MinimumAssetsNotMet();
error TellerWithMultiAssetSupport__PermitFailedAndAllowanceTooLow();
error TellerWithMultiAssetSupport__ZeroShares();
error TellerWithMultiAssetSupport__DualDeposit();
error TellerWithMultiAssetSupport__Paused();
//============================== EVENTS ===============================
event Paused();
event Unpaused();
event AssetAdded(address indexed asset);
event AssetRemoved(address indexed asset);
event Deposit(
uint256 indexed nonce,
address indexed receiver,
address indexed depositAsset,
uint256 depositAmount,
uint256 shareAmount,
uint256 depositTimestamp,
uint256 shareLockPeriodAtTimeOfDeposit
);
event BulkDeposit(address indexed asset, uint256 depositAmount);
event BulkWithdraw(address indexed asset, uint256 shareAmount);
event DepositRefunded(uint256 indexed nonce, bytes32 depositHash, address indexed user);
//============================== IMMUTABLES ===============================
/**
* @notice The BoringVault this contract is working with.
*/
BoringVault public immutable vault;
/**
* @notice The AccountantWithRateProviders this contract is working with.
*/
AccountantWithRateProviders public immutable accountant;
/**
* @notice One share of the BoringVault.
*/
uint256 internal immutable ONE_SHARE;
/**
* @notice The native wrapper contract.
*/
WETH public immutable nativeWrapper;
constructor(address _owner, address _vault, address _accountant, address _weth)
Auth(_owner, Authority(address(0)))
{
vault = BoringVault(payable(_vault));
ONE_SHARE = 10 ** vault.decimals();
accountant = AccountantWithRateProviders(_accountant);
nativeWrapper = WETH(payable(_weth));
}
// ========================================= ADMIN FUNCTIONS =========================================
/**
* @notice Pause this contract, which prevents future calls to `deposit` and `depositWithPermit`.
* @dev Callable by MULTISIG_ROLE.
*/
function pause() external requiresAuth {
isPaused = true;
emit Paused();
}
/**
* @notice Unpause this contract, which allows future calls to `deposit` and `depositWithPermit`.
* @dev Callable by MULTISIG_ROLE.
*/
function unpause() external requiresAuth {
isPaused = false;
emit Unpaused();
}
/**
* @notice Adds this asset as a deposit asset.
* @dev The accountant must also support pricing this asset, else the `deposit` call will revert.
* @dev Callable by OWNER_ROLE.
*/
function addAsset(ERC20 asset) external requiresAuth {
isSupported[asset] = true;
emit AssetAdded(address(asset));
}
/**
* @notice Removes this asset as a deposit asset.
* @dev Callable by OWNER_ROLE.
*/
function removeAsset(ERC20 asset) external requiresAuth {
isSupported[asset] = false;
emit AssetRemoved(address(asset));
}
/**
* @notice Sets the share lock period.
* @dev This not only locks shares to the user address, but also serves as the pending deposit period, where deposits can be reverted.
* @dev If a new shorter share lock period is set, users with pending share locks could make a new deposit to receive 1 wei shares,
* and have their shares unlock sooner than their original deposit allows. This state would allow for the user deposit to be refunded,
* but only if they have not transferred their shares out of there wallet. This is an accepted limitation, and should be known when decreasing
* the share lock period.
* @dev Callable by OWNER_ROLE.
*/
function setShareLockPeriod(uint64 _shareLockPeriod) external requiresAuth {
if (_shareLockPeriod > MAX_SHARE_LOCK_PERIOD) revert TellerWithMultiAssetSupport__ShareLockPeriodTooLong();
shareLockPeriod = _shareLockPeriod;
}
// ========================================= BeforeTransferHook FUNCTIONS =========================================
/**
* @notice Implement beforeTransfer hook to check if shares are locked.
*/
function beforeTransfer(address from, address, address) public view virtual {
if (shareUnlockTime[from] > block.timestamp) revert TellerWithMultiAssetSupport__SharesAreLocked();
}
// ========================================= REVERT DEPOSIT FUNCTIONS =========================================
/**
* @notice Allows DEPOSIT_REFUNDER_ROLE to revert a pending deposit.
* @dev Once a deposit share lock period has passed, it can no longer be reverted.
* @dev It is possible the admin does not setup the BoringVault to call the transfer hook,
* but this contract can still be saving share lock state. In the event this happens
* deposits are still refundable if the user has not transferred their shares.
* But there is no guarantee that the user has not transferred their shares.
* @dev Callable by STRATEGIST_MULTISIG_ROLE.
*/
function refundDeposit(
uint256 nonce,
address receiver,
address depositAsset,
uint256 depositAmount,
uint256 shareAmount,
uint256 depositTimestamp,
uint256 shareLockUpPeriodAtTimeOfDeposit
) external requiresAuth {
if ((block.timestamp - depositTimestamp) > shareLockUpPeriodAtTimeOfDeposit) {
// Shares are already unlocked, so we can not revert deposit.
revert TellerWithMultiAssetSupport__SharesAreUnLocked();
}
bytes32 depositHash = keccak256(
abi.encode(
receiver, depositAsset, depositAmount, shareAmount, depositTimestamp, shareLockUpPeriodAtTimeOfDeposit
)
);
if (publicDepositHistory[nonce] != depositHash) revert TellerWithMultiAssetSupport__BadDepositHash();
// Delete hash to prevent refund gas.
delete publicDepositHistory[nonce];
// If deposit used native asset, send user back wrapped native asset.
depositAsset = depositAsset == NATIVE ? address(nativeWrapper) : depositAsset;
// Burn shares and refund assets to receiver.
vault.exit(receiver, ERC20(depositAsset), depositAmount, receiver, shareAmount);
emit DepositRefunded(nonce, depositHash, receiver);
}
// ========================================= USER FUNCTIONS =========================================
/**
* @notice Allows users to deposit into the BoringVault, if this contract is not paused.
* @dev Publicly callable.
*/
function deposit(ERC20 depositAsset, uint256 depositAmount, uint256 minimumMint)
external
payable
requiresAuth
nonReentrant
returns (uint256 shares)
{
if (isPaused) revert TellerWithMultiAssetSupport__Paused();
if (!isSupported[depositAsset]) revert TellerWithMultiAssetSupport__AssetNotSupported();
if (address(depositAsset) == NATIVE) {
if (msg.value == 0) revert TellerWithMultiAssetSupport__ZeroAssets();
nativeWrapper.deposit{value: msg.value}();
depositAmount = msg.value;
shares = depositAmount.mulDivDown(ONE_SHARE, accountant.getRateInQuoteSafe(nativeWrapper));
if (shares < minimumMint) revert TellerWithMultiAssetSupport__MinimumMintNotMet();
// `from` is address(this) since user already sent value.
nativeWrapper.safeApprove(address(vault), depositAmount);
vault.enter(address(this), nativeWrapper, depositAmount, msg.sender, shares);
} else {
if (msg.value > 0) revert TellerWithMultiAssetSupport__DualDeposit();
shares = _erc20Deposit(depositAsset, depositAmount, minimumMint, msg.sender);
}
_afterPublicDeposit(msg.sender, depositAsset, depositAmount, shares, shareLockPeriod);
}
/**
* @notice Allows users to deposit into BoringVault using permit.
* @dev Publicly callable.
*/
function depositWithPermit(
ERC20 depositAsset,
uint256 depositAmount,
uint256 minimumMint,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external requiresAuth nonReentrant returns (uint256 shares) {
if (isPaused) revert TellerWithMultiAssetSupport__Paused();
if (!isSupported[depositAsset]) revert TellerWithMultiAssetSupport__AssetNotSupported();
try depositAsset.permit(msg.sender, address(vault), depositAmount, deadline, v, r, s) {}
catch {
if (depositAsset.allowance(msg.sender, address(vault)) < depositAmount) {
revert TellerWithMultiAssetSupport__PermitFailedAndAllowanceTooLow();
}
}
shares = _erc20Deposit(depositAsset, depositAmount, minimumMint, msg.sender);
_afterPublicDeposit(msg.sender, depositAsset, depositAmount, shares, shareLockPeriod);
}
/**
* @notice Allows on ramp role to deposit into this contract.
* @dev Does NOT support native deposits.
* @dev Callable by SOLVER_ROLE.
*/
function bulkDeposit(ERC20 depositAsset, uint256 depositAmount, uint256 minimumMint, address to)
external
requiresAuth
nonReentrant
returns (uint256 shares)
{
if (!isSupported[depositAsset]) revert TellerWithMultiAssetSupport__AssetNotSupported();
shares = _erc20Deposit(depositAsset, depositAmount, minimumMint, to);
emit BulkDeposit(address(depositAsset), depositAmount);
}
/**
* @notice Allows off ramp role to withdraw from this contract.
* @dev Callable by SOLVER_ROLE.
*/
function bulkWithdraw(ERC20 withdrawAsset, uint256 shareAmount, uint256 minimumAssets, address to)
external
requiresAuth
returns (uint256 assetsOut)
{
if (!isSupported[withdrawAsset]) revert TellerWithMultiAssetSupport__AssetNotSupported();
if (shareAmount == 0) revert TellerWithMultiAssetSupport__ZeroShares();
assetsOut = shareAmount.mulDivDown(accountant.getRateInQuoteSafe(withdrawAsset), ONE_SHARE);
if (assetsOut < minimumAssets) revert TellerWithMultiAssetSupport__MinimumAssetsNotMet();
vault.exit(to, withdrawAsset, assetsOut, msg.sender, shareAmount);
emit BulkWithdraw(address(withdrawAsset), shareAmount);
}
// ========================================= INTERNAL HELPER FUNCTIONS =========================================
/**
* @notice Implements a common ERC20 deposit into BoringVault.
*/
function _erc20Deposit(ERC20 depositAsset, uint256 depositAmount, uint256 minimumMint, address to)
internal
returns (uint256 shares)
{
if (depositAmount == 0) revert TellerWithMultiAssetSupport__ZeroAssets();
shares = depositAmount.mulDivDown(ONE_SHARE, accountant.getRateInQuoteSafe(depositAsset));
if (shares < minimumMint) revert TellerWithMultiAssetSupport__MinimumMintNotMet();
vault.enter(msg.sender, depositAsset, depositAmount, to, shares);
}
/**
* @notice Handle share lock logic, and event.
*/
function _afterPublicDeposit(
address user,
ERC20 depositAsset,
uint256 depositAmount,
uint256 shares,
uint256 currentShareLockPeriod
) internal {
shareUnlockTime[user] = block.timestamp + currentShareLockPeriod;
uint256 nonce = depositNonce;
publicDepositHistory[nonce] =
keccak256(abi.encode(user, depositAsset, depositAmount, shares, block.timestamp, currentShareLockPeriod));
depositNonce++;
emit Deposit(nonce, user, address(depositAsset), depositAmount, shares, block.timestamp, currentShareLockPeriod);
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {ERC721Holder} from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import {ERC1155Holder} from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
import {FixedPointMathLib} from "@solmate/utils/FixedPointMathLib.sol";
import {SafeTransferLib} from "@solmate/utils/SafeTransferLib.sol";
import {ERC20} from "@solmate/tokens/ERC20.sol";
import {BeforeTransferHook} from "src/interfaces/BeforeTransferHook.sol";
import {Auth, Authority} from "@solmate/auth/Auth.sol";
import {ERC20Upgradeable} from "@openzeppelin-contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {Initializable} from "@openzeppelin-contracts-upgradeable/proxy/utils/Initializable.sol";
import {UUPSUpgradeable} from "@openzeppelin-contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";
contract BoringVault is Auth, Initializable, ERC20Upgradeable, UUPSUpgradeable, ERC721Holder, ERC1155Holder {
using Address for address;
using SafeTransferLib for ERC20;
using FixedPointMathLib for uint256;
// ========================================= STATE =========================================
/**
* @notice Contract responsbile for implementing `beforeTransfer`.
*/
BeforeTransferHook public hook;
uint8 private _decimals;
uint256 public maxTotalSupply = 10_000_000 * 1e6;
//============================== EVENTS ===============================
event Enter(address indexed from, address indexed asset, uint256 amount, address indexed to, uint256 shares);
event Exit(address indexed to, address indexed asset, uint256 amount, address indexed from, uint256 shares);
//============================== ERRORS ===============================
error NotSuperchainERC20Bridge();
//============================== CONSTRUCTOR ===============================
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() Auth(address(0), Authority(address(0))) {
_disableInitializers();
}
function initialize(
address _owner,
Authority _authority,
string memory _name,
string memory _symbol,
uint8 decimals_
) public initializer {
__ERC20_init(_name, _symbol);
__UUPSUpgradeable_init();
owner = _owner;
authority = _authority;
_decimals = decimals_;
maxTotalSupply = 10_000_000 * 1e6;
}
function _authorizeUpgrade(address newImplementation)
internal
override
requiresAuth
{}
//============================== MANAGE ===============================
/**
* @notice Allows manager to make an arbitrary function call from this contract.
* @dev Callable by MANAGER_ROLE.
*/
function manage(address target, bytes calldata data, uint256 value)
external
requiresAuth
returns (bytes memory result)
{
result = target.functionCallWithValue(data, value);
}
/**
* @notice Allows manager to make arbitrary function calls from this contract.
* @dev Callable by MANAGER_ROLE.
*/
function manage(address[] calldata targets, bytes[] calldata data, uint256[] calldata values)
external
requiresAuth
returns (bytes[] memory results)
{
uint256 targetsLength = targets.length;
results = new bytes[](targetsLength);
for (uint256 i; i < targetsLength; ++i) {
results[i] = targets[i].functionCallWithValue(data[i], values[i]);
}
}
//============================== ENTER ===============================
/**
* @notice Allows minter to mint shares, in exchange for assets.
* @dev If assetAmount is zero, no assets are transferred in.
* @dev Callable by MINTER_ROLE.
*/
function enter(address from, ERC20 asset, uint256 assetAmount, address to, uint256 shareAmount)
external
requiresAuth
{
// Check if total supply would exceed max
require(totalSupply() + shareAmount <= maxTotalSupply, "Exceeds max total supply");
// Transfer assets in
if (assetAmount > 0) asset.safeTransferFrom(from, address(this), assetAmount);
// Mint shares.
_mint(to, shareAmount);
emit Enter(from, address(asset), assetAmount, to, shareAmount);
}
//============================== EXIT ===============================
/**
* @notice Allows burner to burn shares, in exchange for assets.
* @dev If assetAmount is zero, no assets are transferred out.
* @dev Callable by BURNER_ROLE.
*/
function exit(address to, ERC20 asset, uint256 assetAmount, address from, uint256 shareAmount)
external
requiresAuth
{
// Burn shares.
_burn(from, shareAmount);
// Transfer assets out.
if (assetAmount > 0) asset.safeTransfer(to, assetAmount);
emit Exit(to, address(asset), assetAmount, from, shareAmount);
}
//============================== BEFORE TRANSFER HOOK ===============================
/**
* @notice Sets the share locker.
* @notice If set to zero address, the share locker logic is disabled.
* @dev Callable by OWNER_ROLE.
*/
function setBeforeTransferHook(address _hook) external requiresAuth {
hook = BeforeTransferHook(_hook);
}
/**
* @notice Call `beforeTransferHook` passing in `from` `to`, and `msg.sender`.
*/
function _callBeforeTransfer(address from, address to) internal view {
if (address(hook) != address(0)) hook.beforeTransfer(from, to, msg.sender);
}
function transfer(address to, uint256 amount) public override returns (bool) {
_callBeforeTransfer(msg.sender, to);
return super.transfer(to, amount);
}
function transferFrom(address from, address to, uint256 amount) public override returns (bool) {
_callBeforeTransfer(from, to);
return super.transferFrom(from, to, amount);
}
/// @inheritdoc IERC165
function supportsInterface(bytes4 _interfaceId) public view virtual override (ERC1155Holder) returns (bool) {
return _interfaceId == type(IERC20).interfaceId
|| _interfaceId == type(IERC165).interfaceId || super.supportsInterface(_interfaceId);
}
//============================== RECEIVE ===============================
receive() external payable {}
function decimals() public view override returns (uint8) {
return _decimals;
}
/**
* @notice Sets the maximum total supply of shares.
* @dev Callable by authorized roles.
*/
function setMaxTotalSupply(uint256 _maxTotalSupply) external requiresAuth {
maxTotalSupply = _maxTotalSupply;
}
/// @notice Sets the name and symbol of the token.
/// @dev Callable by authorized roles.
/// @param name_ The name of the token.
/// @param symbol_ The symbol of the token.
function setNameAndSymbol(string calldata name_, string calldata symbol_) external requiresAuth {
// get storage
bytes32 ERC20StorageLocation = 0x52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00;
ERC20Upgradeable.ERC20Storage storage $;
assembly {
$.slot := ERC20StorageLocation
}
// set name and symbol in storage
$._name = name_;
$._symbol = symbol_;
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
import {FixedPointMathLib} from "@solmate/utils/FixedPointMathLib.sol";
import {IRateProvider} from "src/interfaces/IRateProvider.sol";
import {ERC20} from "@solmate/tokens/ERC20.sol";
import {SafeTransferLib} from "@solmate/utils/SafeTransferLib.sol";
import {BoringVault} from "src/base/BoringVault.sol";
import {Auth, Authority} from "@solmate/auth/Auth.sol";
import {IPausable} from "src/interfaces/IPausable.sol";
contract AccountantWithRateProviders is Auth, IRateProvider, IPausable {
using FixedPointMathLib for uint256;
using SafeTransferLib for ERC20;
// ========================================= STRUCTS =========================================
/**
* @param payoutAddress the address `claimFees` sends fees to
* @param highwaterMark the highest value of the BoringVault's share price
* @param feesOwedInBase total pending fees owed in terms of base
* @param totalSharesLastUpdate total amount of shares the last exchange rate update
* @param exchangeRate the current exchange rate in terms of base
* @param allowedExchangeRateChangeUpper the max allowed change to exchange rate from an update
* @param allowedExchangeRateChangeLower the min allowed change to exchange rate from an update
* @param lastUpdateTimestamp the block timestamp of the last exchange rate update
* @param isPaused whether or not this contract is paused
* @param minimumUpdateDelayInSeconds the minimum amount of time that must pass between
* exchange rate updates, such that the update won't trigger the contract to be paused
* @param managementFee the management fee
* @param performanceFee the performance fee
*/
struct AccountantState {
address payoutAddress;
uint96 highwaterMark;
uint128 feesOwedInBase;
uint128 totalSharesLastUpdate;
uint96 exchangeRate;
uint16 allowedExchangeRateChangeUpper;
uint16 allowedExchangeRateChangeLower;
uint64 lastUpdateTimestamp;
bool isPaused;
uint24 minimumUpdateDelayInSeconds;
uint16 managementFee;
uint16 performanceFee;
}
/**
* @param isPeggedToBase whether or not the asset is 1:1 with the base asset
* @param rateProvider the rate provider for this asset if `isPeggedToBase` is false
*/
struct RateProviderData {
bool isPeggedToBase;
IRateProvider rateProvider;
}
// ========================================= STATE =========================================
/**
* @notice Store the accountant state in 3 packed slots.
*/
AccountantState public accountantState;
/**
* @notice Maps ERC20s to their RateProviderData.
*/
mapping(ERC20 => RateProviderData) public rateProviderData;
//============================== ERRORS ===============================
error AccountantWithRateProviders__UpperBoundTooSmall();
error AccountantWithRateProviders__LowerBoundTooLarge();
error AccountantWithRateProviders__ManagementFeeTooLarge();
error AccountantWithRateProviders__PerformanceFeeTooLarge();
error AccountantWithRateProviders__Paused();
error AccountantWithRateProviders__ZeroFeesOwed();
error AccountantWithRateProviders__OnlyCallableByBoringVault();
error AccountantWithRateProviders__UpdateDelayTooLarge();
error AccountantWithRateProviders__ExchangeRateAboveHighwaterMark();
//============================== EVENTS ===============================
event Paused();
event Unpaused();
event DelayInSecondsUpdated(uint24 oldDelay, uint24 newDelay);
event UpperBoundUpdated(uint16 oldBound, uint16 newBound);
event LowerBoundUpdated(uint16 oldBound, uint16 newBound);
event ManagementFeeUpdated(uint16 oldFee, uint16 newFee);
event PerformanceFeeUpdated(uint16 oldFee, uint16 newFee);
event PayoutAddressUpdated(address oldPayout, address newPayout);
event RateProviderUpdated(address asset, bool isPegged, address rateProvider);
event ExchangeRateUpdated(uint96 oldRate, uint96 newRate, uint64 currentTime);
event FeesClaimed(address indexed feeAsset, uint256 amount);
event HighwaterMarkReset();
//============================== IMMUTABLES ===============================
/**
* @notice The base asset rates are provided in.
*/
ERC20 public immutable base;
/**
* @notice The decimals rates are provided in.
*/
uint8 public immutable decimals;
/**
* @notice The BoringVault this accountant is working with.
* Used to determine share supply for fee calculation.
*/
BoringVault public immutable vault;
/**
* @notice One share of the BoringVault.
*/
uint256 internal immutable ONE_SHARE;
constructor(
address _owner,
address _vault,
address payoutAddress,
uint96 startingExchangeRate,
address _base,
uint16 allowedExchangeRateChangeUpper,
uint16 allowedExchangeRateChangeLower,
uint24 minimumUpdateDelayInSeconds,
uint16 managementFee,
uint16 performanceFee
) Auth(_owner, Authority(address(0))) {
base = ERC20(_base);
decimals = ERC20(_base).decimals();
vault = BoringVault(payable(_vault));
ONE_SHARE = 10 ** vault.decimals();
accountantState = AccountantState({
payoutAddress: payoutAddress,
highwaterMark: startingExchangeRate,
feesOwedInBase: 0,
totalSharesLastUpdate: uint128(vault.totalSupply()),
exchangeRate: startingExchangeRate,
allowedExchangeRateChangeUpper: allowedExchangeRateChangeUpper,
allowedExchangeRateChangeLower: allowedExchangeRateChangeLower,
lastUpdateTimestamp: uint64(block.timestamp),
isPaused: false,
minimumUpdateDelayInSeconds: minimumUpdateDelayInSeconds,
managementFee: managementFee,
performanceFee: performanceFee
});
}
// ========================================= ADMIN FUNCTIONS =========================================
/**
* @notice Pause this contract, which prevents future calls to `updateExchangeRate`, and any safe rate
* calls will revert.
* @dev Callable by MULTISIG_ROLE.
*/
function pause() external requiresAuth {
accountantState.isPaused = true;
emit Paused();
}
/**
* @notice Unpause this contract, which allows future calls to `updateExchangeRate`, and any safe rate
* calls will stop reverting.
* @dev Callable by MULTISIG_ROLE.
*/
function unpause() external requiresAuth {
accountantState.isPaused = false;
emit Unpaused();
}
/**
* @notice Update the minimum time delay between `updateExchangeRate` calls.
* @dev There are no input requirements, as it is possible the admin would want
* the exchange rate updated as frequently as needed.
* @dev Callable by OWNER_ROLE.
*/
function updateDelay(uint24 minimumUpdateDelayInSeconds) external requiresAuth {
if (minimumUpdateDelayInSeconds > 14 days) revert AccountantWithRateProviders__UpdateDelayTooLarge();
uint24 oldDelay = accountantState.minimumUpdateDelayInSeconds;
accountantState.minimumUpdateDelayInSeconds = minimumUpdateDelayInSeconds;
emit DelayInSecondsUpdated(oldDelay, minimumUpdateDelayInSeconds);
}
/**
* @notice Update the allowed upper bound change of exchange rate between `updateExchangeRateCalls`.
* @dev Callable by OWNER_ROLE.
*/
function updateUpper(uint16 allowedExchangeRateChangeUpper) external requiresAuth {
if (allowedExchangeRateChangeUpper < 1e4) revert AccountantWithRateProviders__UpperBoundTooSmall();
uint16 oldBound = accountantState.allowedExchangeRateChangeUpper;
accountantState.allowedExchangeRateChangeUpper = allowedExchangeRateChangeUpper;
emit UpperBoundUpdated(oldBound, allowedExchangeRateChangeUpper);
}
/**
* @notice Update the allowed lower bound change of exchange rate between `updateExchangeRateCalls`.
* @dev Callable by OWNER_ROLE.
*/
function updateLower(uint16 allowedExchangeRateChangeLower) external requiresAuth {
if (allowedExchangeRateChangeLower > 1e4) revert AccountantWithRateProviders__LowerBoundTooLarge();
uint16 oldBound = accountantState.allowedExchangeRateChangeLower;
accountantState.allowedExchangeRateChangeLower = allowedExchangeRateChangeLower;
emit LowerBoundUpdated(oldBound, allowedExchangeRateChangeLower);
}
/**
* @notice Update the management fee to a new value.
* @dev Callable by OWNER_ROLE.
*/
function updateManagementFee(uint16 managementFee) external requiresAuth {
if (managementFee > 0.2e4) revert AccountantWithRateProviders__ManagementFeeTooLarge();
uint16 oldFee = accountantState.managementFee;
accountantState.managementFee = managementFee;
emit ManagementFeeUpdated(oldFee, managementFee);
}
/**
* @notice Update the performance fee to a new value.
* @dev Callable by OWNER_ROLE.
*/
function updatePerformanceFee(uint16 performanceFee) external requiresAuth {
if (performanceFee > 0.5e4) revert AccountantWithRateProviders__PerformanceFeeTooLarge();
uint16 oldFee = accountantState.performanceFee;
accountantState.performanceFee = performanceFee;
emit PerformanceFeeUpdated(oldFee, performanceFee);
}
/**
* @notice Update the payout address fees are sent to.
* @dev Callable by OWNER_ROLE.
*/
function updatePayoutAddress(address payoutAddress) external requiresAuth {
address oldPayout = accountantState.payoutAddress;
accountantState.payoutAddress = payoutAddress;
emit PayoutAddressUpdated(oldPayout, payoutAddress);
}
/**
* @notice Update the rate provider data for a specific `asset`.
* @dev Rate providers must return rates in terms of `base` or
* an asset pegged to base and they must use the same decimals
* as `asset`.
* @dev Callable by OWNER_ROLE.
*/
function setRateProviderData(ERC20 asset, bool isPeggedToBase, address rateProvider) external requiresAuth {
rateProviderData[asset] =
RateProviderData({isPeggedToBase: isPeggedToBase, rateProvider: IRateProvider(rateProvider)});
emit RateProviderUpdated(address(asset), isPeggedToBase, rateProvider);
}
/**
* @notice Reset the highwater mark to the current exchange rate.
* @dev Callable by OWNER_ROLE.
*/
function resetHighwaterMark() external virtual requiresAuth {
AccountantState storage state = accountantState;
if (state.exchangeRate > state.highwaterMark) {
revert AccountantWithRateProviders__ExchangeRateAboveHighwaterMark();
}
uint64 currentTime = uint64(block.timestamp);
uint256 currentTotalShares = vault.totalSupply();
_calculateFeesOwed(state, state.exchangeRate, state.exchangeRate, currentTotalShares, currentTime);
state.totalSharesLastUpdate = uint128(currentTotalShares);
state.highwaterMark = accountantState.exchangeRate;
state.lastUpdateTimestamp = currentTime;
emit HighwaterMarkReset();
}
// ========================================= UPDATE EXCHANGE RATE/FEES FUNCTIONS =========================================
/**
* @notice Updates this contract exchangeRate.
* @dev If new exchange rate is outside of accepted bounds, or if not enough time has passed, this
* will pause the contract, and this function will NOT calculate fees owed.
* @dev Callable by UPDATE_EXCHANGE_RATE_ROLE.
*/
function updateExchangeRate(uint96 newExchangeRate) external requiresAuth {
AccountantState storage state = accountantState;
if (state.isPaused) revert AccountantWithRateProviders__Paused();
uint64 currentTime = uint64(block.timestamp);
uint256 currentExchangeRate = state.exchangeRate;
uint256 currentTotalShares = vault.totalSupply();
if (
currentTime < state.lastUpdateTimestamp + state.minimumUpdateDelayInSeconds
|| newExchangeRate > currentExchangeRate.mulDivDown(state.allowedExchangeRateChangeUpper, 1e4)
|| newExchangeRate < currentExchangeRate.mulDivDown(state.allowedExchangeRateChangeLower, 1e4)
) {
// Instead of reverting, pause the contract. This way the exchange rate updater is able to update the exchange rate
// to a better value, and pause it.
state.isPaused = true;
} else {
_calculateFeesOwed(state, newExchangeRate, currentExchangeRate, currentTotalShares, currentTime);
}
newExchangeRate = _setExchangeRate(newExchangeRate, state);
state.totalSharesLastUpdate = uint128(currentTotalShares);
state.lastUpdateTimestamp = currentTime;
emit ExchangeRateUpdated(uint96(currentExchangeRate), newExchangeRate, currentTime);
}
/**
* @notice Claim pending fees.
* @dev This function must be called by the BoringVault.
* @dev This function will lose precision if the exchange rate
* decimals is greater than the feeAsset's decimals.
*/
function claimFees(ERC20 feeAsset) external {
if (msg.sender != address(vault)) revert AccountantWithRateProviders__OnlyCallableByBoringVault();
AccountantState storage state = accountantState;
if (state.isPaused) revert AccountantWithRateProviders__Paused();
if (state.feesOwedInBase == 0) revert AccountantWithRateProviders__ZeroFeesOwed();
// Determine amount of fees owed in feeAsset.
uint256 feesOwedInFeeAsset;
RateProviderData memory data = rateProviderData[feeAsset];
if (address(feeAsset) == address(base)) {
feesOwedInFeeAsset = state.feesOwedInBase;
} else {
uint8 feeAssetDecimals = ERC20(feeAsset).decimals();
uint256 feesOwedInBaseUsingFeeAssetDecimals =
changeDecimals(state.feesOwedInBase, decimals, feeAssetDecimals);
if (data.isPeggedToBase) {
feesOwedInFeeAsset = feesOwedInBaseUsingFeeAssetDecimals;
} else {
uint256 rate = data.rateProvider.getRate();
feesOwedInFeeAsset = feesOwedInBaseUsingFeeAssetDecimals.mulDivDown(10 ** feeAssetDecimals, rate);
}
}
// Zero out fees owed.
state.feesOwedInBase = 0;
// Transfer fee asset to payout address.
feeAsset.safeTransferFrom(msg.sender, state.payoutAddress, feesOwedInFeeAsset);
emit FeesClaimed(address(feeAsset), feesOwedInFeeAsset);
}
// ========================================= RATE FUNCTIONS =========================================
/**
* @notice Get this BoringVault's current rate in the base.
*/
function getRate() public view returns (uint256 rate) {
rate = accountantState.exchangeRate;
}
/**
* @notice Get this BoringVault's current rate in the base.
* @dev Revert if paused.
*/
function getRateSafe() external view returns (uint256 rate) {
if (accountantState.isPaused) revert AccountantWithRateProviders__Paused();
rate = getRate();
}
/**
* @notice Get this BoringVault's current rate in the provided quote.
* @dev `quote` must have its RateProviderData set, else this will revert.
* @dev This function will lose precision if the exchange rate
* decimals is greater than the quote's decimals.
*/
function getRateInQuote(ERC20 quote) public view returns (uint256 rateInQuote) {
if (address(quote) == address(base)) {
rateInQuote = accountantState.exchangeRate;
} else {
RateProviderData memory data = rateProviderData[quote];
uint8 quoteDecimals = ERC20(quote).decimals();
uint256 exchangeRateInQuoteDecimals = changeDecimals(accountantState.exchangeRate, decimals, quoteDecimals);
if (data.isPeggedToBase) {
rateInQuote = exchangeRateInQuoteDecimals;
} else {
uint256 quoteRate = data.rateProvider.getRate();
uint256 oneQuote = 10 ** quoteDecimals;
rateInQuote = oneQuote.mulDivDown(exchangeRateInQuoteDecimals, quoteRate);
}
}
}
/**
* @notice Get this BoringVault's current rate in the provided quote.
* @dev `quote` must have its RateProviderData set, else this will revert.
* @dev Revert if paused.
*/
function getRateInQuoteSafe(ERC20 quote) external view returns (uint256 rateInQuote) {
if (accountantState.isPaused) revert AccountantWithRateProviders__Paused();
rateInQuote = getRateInQuote(quote);
}
// ========================================= INTERNAL HELPER FUNCTIONS =========================================
/**
* @notice Used to change the decimals of precision used for an amount.
*/
function changeDecimals(uint256 amount, uint8 fromDecimals, uint8 toDecimals) internal pure returns (uint256) {
if (fromDecimals == toDecimals) {
return amount;
} else if (fromDecimals < toDecimals) {
return amount * 10 ** (toDecimals - fromDecimals);
} else {
return amount / 10 ** (fromDecimals - toDecimals);
}
}
/**
* @notice Set the exchange rate.
*/
function _setExchangeRate(uint96 newExchangeRate, AccountantState storage state)
internal
virtual
returns (uint96)
{
state.exchangeRate = newExchangeRate;
return newExchangeRate;
}
/**
* @notice Calculate management fees.
*/
function _calculateManagementFee(
uint128 totalSharesLastUpdate,
uint64 lastUpdateTimestamp,
uint16 managementFee,
uint96 newExchangeRate,
uint256 currentExchangeRate,
uint256 currentTotalShares,
uint64 currentTime
) internal view returns (uint256 managementFeesOwedInBase, uint256 shareSupplyToUse) {
shareSupplyToUse = currentTotalShares;
// Use the minimum between current total supply and total supply for last update.
if (totalSharesLastUpdate < shareSupplyToUse) {
shareSupplyToUse = totalSharesLastUpdate;
}
// Determine management fees owned.
if (managementFee > 0) {
uint256 timeDelta = currentTime - lastUpdateTimestamp;
uint256 minimumAssets = newExchangeRate > currentExchangeRate
? shareSupplyToUse.mulDivDown(currentExchangeRate, ONE_SHARE)
: shareSupplyToUse.mulDivDown(newExchangeRate, ONE_SHARE);
uint256 managementFeesAnnual = minimumAssets.mulDivDown(managementFee, 1e4);
managementFeesOwedInBase = managementFeesAnnual.mulDivDown(timeDelta, 365 days);
}
}
/**
* @notice Calculate performance fees.
*/
function _calculatePerformanceFee(
uint96 newExchangeRate,
uint256 shareSupplyToUse,
uint96 datum,
uint16 performanceFee
) internal view returns (uint256 performanceFeesOwedInBase, uint256 yieldEarned) {
uint256 changeInExchangeRate = newExchangeRate - datum;
yieldEarned = changeInExchangeRate.mulDivDown(shareSupplyToUse, ONE_SHARE);
if (performanceFee > 0) {
performanceFeesOwedInBase = yieldEarned.mulDivDown(performanceFee, 1e4);
}
}
/**
* @notice Calculate fees owed in base.
* @dev This function will update the highwater mark if the new exchange rate is higher.
*/
function _calculateFeesOwed(
AccountantState storage state,
uint96 newExchangeRate,
uint256 currentExchangeRate,
uint256 currentTotalShares,
uint64 currentTime
) internal virtual {
// Only update fees if we are not paused.
// Update fee accounting.
(uint256 newFeesOwedInBase, uint256 shareSupplyToUse) = _calculateManagementFee(
state.totalSharesLastUpdate,
state.lastUpdateTimestamp,
state.managementFee,
newExchangeRate,
currentExchangeRate,
currentTotalShares,
currentTime
);
// Account for performance fees.
if (newExchangeRate > state.highwaterMark) {
(uint256 performanceFeesOwedInBase,) =
_calculatePerformanceFee(newExchangeRate, shareSupplyToUse, state.highwaterMark, state.performanceFee);
// Add performance fees to fees owed.
newFeesOwedInBase += performanceFeesOwedInBase;
// Always update the highwater mark if the new exchange rate is higher.
// This way if we are not iniitiall taking performance fees, we can start taking them
// without back charging them on past performance.
state.highwaterMark = newExchangeRate;
}
state.feesOwedInBase += uint128(newFeesOwedInBase);
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
import {ERC20} from "./ERC20.sol";
import {SafeTransferLib} from "../utils/SafeTransferLib.sol";
/// @notice Minimalist and modern Wrapped Ether implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/WETH.sol)
/// @author Inspired by WETH9 (https://github.com/dapphub/ds-weth/blob/master/src/weth9.sol)
contract WETH is ERC20("Wrapped Ether", "WETH", 18) {
using SafeTransferLib for address;
event Deposit(address indexed from, uint256 amount);
event Withdrawal(address indexed to, uint256 amount);
function deposit() public payable virtual {
_mint(msg.sender, msg.value);
emit Deposit(msg.sender, msg.value);
}
function withdraw(uint256 amount) public virtual {
_burn(msg.sender, amount);
emit Withdrawal(msg.sender, amount);
msg.sender.safeTransferETH(amount);
}
receive() external payable virtual {
deposit();
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
interface BeforeTransferHook {
function beforeTransfer(address from, address to, address operator) external view;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @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.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @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 or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* 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.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @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`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) 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 FailedInnerCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/utils/ERC721Holder.sol)
pragma solidity ^0.8.20;
import {IERC721Receiver} from "../IERC721Receiver.sol";
/**
* @dev Implementation of the {IERC721Receiver} interface.
*
* Accepts all token transfers.
* Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or
* {IERC721-setApprovalForAll}.
*/
abstract contract ERC721Holder is IERC721Receiver {
/**
* @dev See {IERC721Receiver-onERC721Received}.
*
* Always returns `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(address, address, uint256, bytes memory) public virtual returns (bytes4) {
return this.onERC721Received.selector;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/utils/ERC1155Holder.sol)
pragma solidity ^0.8.20;
import {IERC165, ERC165} from "../../../utils/introspection/ERC165.sol";
import {IERC1155Receiver} from "../IERC1155Receiver.sol";
/**
* @dev Simple implementation of `IERC1155Receiver` that will allow a contract to hold ERC1155 tokens.
*
* IMPORTANT: When inheriting this contract, you must include a way to use the received tokens, otherwise they will be
* stuck.
*/
abstract contract ERC1155Holder is ERC165, IERC1155Receiver {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
}
function onERC1155Received(
address,
address,
uint256,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address,
address,
uint256[] memory,
uint256[] memory,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155BatchReceived.selector;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {ContextUpgradeable} from "../../utils/ContextUpgradeable.sol";
import {IERC20Errors} from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*/
abstract contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20, IERC20Metadata, IERC20Errors {
/// @custom:storage-location erc7201:openzeppelin.storage.ERC20
struct ERC20Storage {
mapping(address account => uint256) _balances;
mapping(address account => mapping(address spender => uint256)) _allowances;
uint256 _totalSupply;
string _name;
string _symbol;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ERC20")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant ERC20StorageLocation = 0x52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00;
function _getERC20Storage() private pure returns (ERC20Storage storage $) {
assembly {
$.slot := ERC20StorageLocation
}
}
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {
__ERC20_init_unchained(name_, symbol_);
}
function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
ERC20Storage storage $ = _getERC20Storage();
$._name = name_;
$._symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
ERC20Storage storage $ = _getERC20Storage();
return $._name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
ERC20Storage storage $ = _getERC20Storage();
return $._symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
ERC20Storage storage $ = _getERC20Storage();
return $._totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
ERC20Storage storage $ = _getERC20Storage();
return $._balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (uint256) {
ERC20Storage storage $ = _getERC20Storage();
return $._allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Skips emitting an {Approval} event indicating an allowance update. This is not
* required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
ERC20Storage storage $ = _getERC20Storage();
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
$._totalSupply += value;
} else {
uint256 fromBalance = $._balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
$._balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
$._totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
$._balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
*
* ```solidity
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
ERC20Storage storage $ = _getERC20Storage();
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
$._allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reininitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._initialized = version;
$._initializing = true;
_;
$._initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
assembly {
$.slot := INITIALIZABLE_STORAGE
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.20;
import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*/
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address private immutable __self = address(this);
/**
* @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
* and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
* while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
* If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
* be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
* during an upgrade.
*/
string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";
/**
* @dev The call is from an unauthorized context.
*/
error UUPSUnauthorizedCallContext();
/**
* @dev The storage `slot` is unsupported as a UUID.
*/
error UUPSUnsupportedProxiableUUID(bytes32 slot);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC-1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC-1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
_checkProxy();
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
_checkNotDelegated();
_;
}
function __UUPSUpgradeable_init() internal onlyInitializing {
}
function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
}
/**
* @dev Implementation of the ERC-1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate the implementation's compatibility when performing an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual notDelegated returns (bytes32) {
return ERC1967Utils.IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data);
}
/**
* @dev Reverts if the execution is not performed via delegatecall or the execution
* context is not of a proxy with an ERC-1967 compliant implementation pointing to self.
* See {_onlyProxy}.
*/
function _checkProxy() internal view virtual {
if (
address(this) == __self || // Must be called through delegatecall
ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
) {
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Reverts if the execution is performed via delegatecall.
* See {notDelegated}.
*/
function _checkNotDelegated() internal view virtual {
if (address(this) != __self) {
// Must not be called through delegatecall
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
/**
* @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
*
* As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
* is expected to be the implementation slot in ERC-1967.
*
* Emits an {IERC1967-Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
revert UUPSUnsupportedProxiableUUID(slot);
}
ERC1967Utils.upgradeToAndCall(newImplementation, data);
} catch {
// The implementation is not UUPS
revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @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 value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` 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 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.8.0;
interface IRateProvider {
function getRate() external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
interface IPausable {
function pause() external;
function unpause() external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.20;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be
* reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/IERC1155Receiver.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Interface that must be implemented by smart contracts in order to receive
* ERC-1155 token transfers.
*/
interface IERC1155Receiver is IERC165 {
/**
* @dev Handles the receipt of a single ERC1155 token type. This function is
* called at the end of a `safeTransferFrom` after the balance has been updated.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* (i.e. 0xf23a6e61, or its own function selector).
*
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
* @dev Handles the receipt of a multiple ERC1155 token types. This function
* is called at the end of a `safeBatchTransferFrom` after the balances have
* been updated.
*
* NOTE: To accept the transfer(s), this must return
* `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* (i.e. 0xbc197c81, or its own function selector).
*
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*/
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 v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @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 ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.20;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822Proxiable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/ERC1967/ERC1967Utils.sol)
pragma solidity ^0.8.20;
import {IBeacon} from "../beacon/IBeacon.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*/
library ERC1967Utils {
// We re-declare ERC-1967 events here because they can't be used directly from IERC1967.
// This will be fixed in Solidity 0.8.21. At that point we should remove these events.
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Emitted when the beacon is changed.
*/
event BeaconUpgraded(address indexed beacon);
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev The `implementation` of the proxy is invalid.
*/
error ERC1967InvalidImplementation(address implementation);
/**
* @dev The `admin` of the proxy is invalid.
*/
error ERC1967InvalidAdmin(address admin);
/**
* @dev The `beacon` of the proxy is invalid.
*/
error ERC1967InvalidBeacon(address beacon);
/**
* @dev An upgrade function sees `msg.value > 0` that may be lost.
*/
error ERC1967NonPayable();
/**
* @dev Returns the current implementation address.
*/
function getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
if (newImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(newImplementation);
}
StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Performs implementation upgrade with additional setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-Upgraded} event.
*/
function upgradeToAndCall(address newImplementation, bytes memory data) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
if (data.length > 0) {
Address.functionDelegateCall(newImplementation, data);
} else {
_checkNonPayable();
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*
* TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using
* the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
*/
function getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
if (newAdmin == address(0)) {
revert ERC1967InvalidAdmin(address(0));
}
StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {IERC1967-AdminChanged} event.
*/
function changeAdmin(address newAdmin) internal {
emit AdminChanged(getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
if (newBeacon.code.length == 0) {
revert ERC1967InvalidBeacon(newBeacon);
}
StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;
address beaconImplementation = IBeacon(newBeacon).implementation();
if (beaconImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(beaconImplementation);
}
}
/**
* @dev Change the beacon and trigger a setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-BeaconUpgraded} event.
*
* CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
* it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
* efficiency.
*/
function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
} else {
_checkNonPayable();
}
}
/**
* @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
* if an upgrade doesn't perform an initialization call.
*/
function _checkNonPayable() private {
if (msg.value > 0) {
revert ERC1967NonPayable();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.20;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {UpgradeableBeacon} will check that this address is a contract.
*/
function implementation() external view returns (address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}{
"remappings": [
"@solmate/=lib/solmate/src/",
"@forge-std/=lib/forge-std/src/",
"@ds-test/=lib/forge-std/lib/ds-test/src/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"@openzeppelin/=lib/openzeppelin-contracts/",
"@openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@layerzerolabs/lz-evm-protocol-v2/=lib/OAppAuth/lib/LayerZero-V2/packages/layerzero-v2/evm/protocol/",
"@ccip/=lib/ccip/",
"@oapp-auth/=lib/OAppAuth/src/",
"@cryptoalgebra/Algebra/=lib/Algebra/src/core/",
"@devtools-oapp-evm/=lib/OAppAuth/lib/devtools/packages/oapp-evm/contracts/oapp/",
"@layerzerolabs/lz-evm-messagelib-v2/=lib/OAppAuth/node_modules/@layerzerolabs/lz-evm-messagelib-v2/",
"@layerzerolabs/oapp-evm/=lib/OAppAuth/lib/devtools/packages/oapp-evm/",
"@lz-oapp-evm/=lib/OAppAuth/lib/LayerZero-V2/packages/layerzero-v2/evm/oapp/contracts/oapp/",
"@sbu/=lib/OAppAuth/lib/solidity-bytes-utils/",
"LayerZero-V2/=lib/OAppAuth/lib/",
"OAppAuth/=lib/OAppAuth/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"solidity-bytes-utils/=lib/OAppAuth/node_modules/solidity-bytes-utils/",
"solmate/=lib/solmate/src/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "shanghai",
"viaIR": false
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"contract Authority","name":"_authority","type":"address"},{"internalType":"address","name":"_accountant","type":"address"},{"internalType":"address","name":"_solver","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AtomicQueue__BadDiscount","type":"error"},{"inputs":[],"name":"AtomicQueue__BadUser","type":"error"},{"inputs":[],"name":"AtomicQueue__BadWhitelistDivisor","type":"error"},{"inputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"teller","type":"address"}],"name":"AtomicQueue__BoringVaultTellerMismatch","type":"error"},{"inputs":[],"name":"AtomicQueue__DeadlineExpired","type":"error"},{"inputs":[],"name":"AtomicQueue__DuplicateRequest","type":"error"},{"inputs":[{"internalType":"uint256","name":"expected","type":"uint256"},{"internalType":"uint256","name":"actual","type":"uint256"}],"name":"AtomicQueue__InstantWithdrawShortfall","type":"error"},{"inputs":[],"name":"AtomicQueue__InsufficientBalance","type":"error"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"required","type":"uint256"},{"internalType":"uint256","name":"available","type":"uint256"}],"name":"AtomicQueue__InsufficientBalanceInUserWallet","type":"error"},{"inputs":[{"internalType":"uint256","name":"required","type":"uint256"},{"internalType":"uint256","name":"available","type":"uint256"}],"name":"AtomicQueue__InsufficientVaultLiquidity","type":"error"},{"inputs":[],"name":"AtomicQueue__MinimumAssetsNotMet","type":"error"},{"inputs":[],"name":"AtomicQueue__OfferAddressIsZero","type":"error"},{"inputs":[],"name":"AtomicQueue__OfferAmountIsZero","type":"error"},{"inputs":[],"name":"AtomicQueue__RemovedRequest","type":"error"},{"inputs":[{"internalType":"address","name":"offer","type":"address"},{"internalType":"address","name":"vault","type":"address"}],"name":"AtomicQueue__RequestAccountantOfferMismatch","type":"error"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"AtomicQueue__RequestNotMature","type":"error"},{"inputs":[{"internalType":"address","name":"caller","type":"address"}],"name":"AtomicQueue__UnauthorizedSolver","type":"error"},{"inputs":[],"name":"AtomicQueue__UserAddressIsZero","type":"error"},{"inputs":[],"name":"AtomicQueue__WantAddressIsZero","type":"error"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"AtomicQueue__ZeroOfferAmount","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"requestId","type":"bytes32"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"address","name":"offerToken","type":"address"},{"indexed":true,"internalType":"address","name":"wantToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"deadline","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"AtomicRequestCancelled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"requestId","type":"bytes32"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"address","name":"offerToken","type":"address"},{"indexed":true,"internalType":"address","name":"wantToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"offerAmountSpent","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"wantAmountReceived","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"AtomicRequestFulfilled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"requestId","type":"bytes32"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"address","name":"offerToken","type":"address"},{"indexed":true,"internalType":"address","name":"wantToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"deadline","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"AtomicRequestUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"contract Authority","name":"newAuthority","type":"address"}],"name":"AuthorityUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newDiscount","type":"uint256"}],"name":"DiscountUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"offerToken","type":"address"},{"indexed":true,"internalType":"address","name":"wantToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"offerAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"wantAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"InstantWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldMaturityTime","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newMaturityTime","type":"uint256"}],"name":"MaturityTimeUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newSolver","type":"address"}],"name":"SolverUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"}],"name":"WhitelistAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newDivisor","type":"uint256"}],"name":"WhitelistMaturityDivisorUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"}],"name":"WhitelistRemoved","type":"event"},{"inputs":[],"name":"accountant","outputs":[{"internalType":"contract AccountantWithRateProviders","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"addToWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"authority","outputs":[{"internalType":"contract Authority","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint64","name":"deadline","type":"uint64"},{"internalType":"uint64","name":"creationTime","type":"uint64"},{"internalType":"uint96","name":"offerAmount","type":"uint96"},{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"offer","type":"address"},{"internalType":"address","name":"want","type":"address"}],"internalType":"struct AtomicRequest","name":"userRequest","type":"tuple"}],"name":"cancelAtomicRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint64","name":"deadline","type":"uint64"},{"internalType":"uint64","name":"creationTime","type":"uint64"},{"internalType":"uint96","name":"offerAmount","type":"uint96"},{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"offer","type":"address"},{"internalType":"address","name":"want","type":"address"}],"internalType":"struct AtomicRequest[]","name":"userRequests","type":"tuple[]"}],"name":"cancelAtomicRequestByAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint64","name":"deadline","type":"uint64"},{"internalType":"uint64","name":"creationTime","type":"uint64"},{"internalType":"uint96","name":"offerAmount","type":"uint96"},{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"offer","type":"address"},{"internalType":"address","name":"want","type":"address"}],"internalType":"struct AtomicRequest","name":"userRequest","type":"tuple"}],"name":"checkAtomicRequestValid","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[],"name":"discount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"requestId","type":"bytes32"}],"name":"getAtomicRequestById","outputs":[{"components":[{"internalType":"uint64","name":"deadline","type":"uint64"},{"internalType":"uint64","name":"creationTime","type":"uint64"},{"internalType":"uint96","name":"offerAmount","type":"uint96"},{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"offer","type":"address"},{"internalType":"address","name":"want","type":"address"}],"internalType":"struct AtomicRequest","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getExistingWithdrawRequestIds","outputs":[{"internalType":"bytes32[]","name":"","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getExistingWithdrawRequests","outputs":[{"internalType":"bytes32[]","name":"requestIds","type":"bytes32[]"},{"components":[{"internalType":"uint64","name":"deadline","type":"uint64"},{"internalType":"uint64","name":"creationTime","type":"uint64"},{"internalType":"uint96","name":"offerAmount","type":"uint96"},{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"offer","type":"address"},{"internalType":"address","name":"want","type":"address"}],"internalType":"struct AtomicRequest[]","name":"requests","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getExistingWithdrawRequestsByUser","outputs":[{"internalType":"bytes32[]","name":"requestIds","type":"bytes32[]"},{"components":[{"internalType":"uint64","name":"deadline","type":"uint64"},{"internalType":"uint64","name":"creationTime","type":"uint64"},{"internalType":"uint96","name":"offerAmount","type":"uint96"},{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"offer","type":"address"},{"internalType":"address","name":"want","type":"address"}],"internalType":"struct AtomicRequest[]","name":"requests","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"offer","type":"address"},{"internalType":"address","name":"want","type":"address"}],"name":"getTotalWithdrawInProgressAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"offer","type":"address"},{"internalType":"contract ERC20","name":"want","type":"address"},{"internalType":"uint256","name":"offerAmount","type":"uint256"},{"internalType":"uint256","name":"minimumAssetsOut","type":"uint256"},{"internalType":"contract TellerWithMultiAssetSupport","name":"teller","type":"address"}],"name":"instantWithdraw","outputs":[{"internalType":"uint256","name":"assetsOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"maturityTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint64","name":"deadline","type":"uint64"},{"internalType":"uint64","name":"creationTime","type":"uint64"},{"internalType":"uint96","name":"offerAmount","type":"uint96"},{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"offer","type":"address"},{"internalType":"address","name":"want","type":"address"}],"internalType":"struct AtomicRequest","name":"request","type":"tuple"}],"name":"previewReceivedAmount","outputs":[{"internalType":"uint256","name":"wantAmountReceived","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"removeFromWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract Authority","name":"newAuthority","type":"address"}],"name":"setAuthority","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newDiscount","type":"uint256"}],"name":"setDiscount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newMaturityTime","type":"uint256"}],"name":"setMaturityTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newSolver","type":"address"}],"name":"setSolver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"runData","type":"bytes"},{"components":[{"internalType":"uint64","name":"deadline","type":"uint64"},{"internalType":"uint64","name":"creationTime","type":"uint64"},{"internalType":"uint96","name":"offerAmount","type":"uint96"},{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"offer","type":"address"},{"internalType":"address","name":"want","type":"address"}],"internalType":"struct AtomicRequest","name":"request","type":"tuple"}],"name":"solve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"solver","outputs":[{"internalType":"contract IAtomicSolver","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint64","name":"deadline","type":"uint64"},{"internalType":"uint64","name":"creationTime","type":"uint64"},{"internalType":"uint96","name":"offerAmount","type":"uint96"},{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"offer","type":"address"},{"internalType":"address","name":"want","type":"address"}],"internalType":"struct AtomicRequest","name":"userRequest","type":"tuple"}],"name":"updateAtomicRequest","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newDivisor","type":"uint256"}],"name":"updateWhitelistMaturityDivisor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whitelist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"whitelistMaturityDivisor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"withdrawInProgressAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]Contract Creation Code
60a060405260015f5562015180600555600a6009556101f4600a5534801562000026575f80fd5b506040516200344b3803806200344b833981016040819052620000499162000120565b600180546001600160a01b038087166001600160a01b0319928316811790935560028054918716919092161790556040518591859133907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a36040516001600160a01b0382169033907fa3396fd7f6e0a21b50e5089d2da70d5ac0a3bbbd1f617a93f134b76389980198905f90a350506001600160a01b03918216608052600b80546001600160a01b0319169190921617905550620001859050565b6001600160a01b03811681146200011d575f80fd5b50565b5f805f806080858703121562000134575f80fd5b8451620001418162000108565b6020860151909450620001548162000108565b6040860151909350620001678162000108565b60608601519092506200017a8162000108565b939692955090935050565b60805161326e620001dd5f395f818161027c01528181610490015281816105310152818161062c01528181610dca015281816118a4015281816119bc01528181611c4501528181611e400152611efb015261326e5ff3fe608060405234801561000f575f80fd5b50600436106101c6575f3560e01c80638da5cb5b116100fe578063c2f0549f1161009e578063e09bd8e91161006e578063e09bd8e914610403578063e43252d714610416578063e57b50c214610429578063f2fde38b14610449575f80fd5b8063c2f0549f146103b7578063c49b8941146103ca578063cdf30c7a146103dd578063dabd2719146103f0575f80fd5b80639ce4cd2d116100d95780639ce4cd2d14610354578063b11ae5b714610367578063b68ffe0714610391578063bf7e214f146103a4575f80fd5b80638da5cb5b146102fc57806396bb9fbe1461030f5780639b19251a14610322575f80fd5b80634fb3ccc51161016957806371cab2fa1161014457806371cab2fa146102ba5780637a1106bc146102c35780637a9e5e4b146102d65780638ab1d681146102e9575f80fd5b80634fb3ccc514610277578063676418f71461029e5780636b6f4a9d146102b1575f80fd5b806342349b46116101a457806342349b461461021b578063475dfea11461023057806349a7a26d146102435780634e8bfdaa1461026e575f80fd5b8063062f5511146101ca5780631f879433146101f057806335b0012c14610205575b5f80fd5b6101dd6101d8366004612a9a565b61045c565b6040519081526020015b60405180910390f35b6102036101fe366004612b42565b6109de565b005b61020d610a64565b6040516101e7929190612bf5565b610223610b9b565b6040516101e79190612c54565b61020361023e366004612c66565b610bac565b600b54610256906001600160a01b031681565b6040516001600160a01b0390911681526020016101e7565b6101dd60055481565b6102567f000000000000000000000000000000000000000000000000000000000000000081565b6101dd6102ac366004612c93565b610c32565b6101dd600a5481565b6101dd60095481565b6102036102d1366004612cad565b610eb6565b6102036102e4366004612b42565b611162565b6102036102f7366004612b42565b611247565b600154610256906001600160a01b031681565b61020d61031d366004612b42565b6112e7565b610344610330366004612b42565b60086020525f908152604090205460ff1681565b60405190151581526020016101e7565b6101dd610362366004612d1b565b611506565b6101dd610375366004612d1b565b600760209081525f928352604080842090915290825290205481565b61020361039f366004612c66565b611532565b600254610256906001600160a01b031681565b6102036103c5366004612c93565b6115a8565b6102036103d8366004612d52565b61171c565b6101dd6103eb366004612dcc565b611bc6565b6102036103fe366004612c66565b6121d6565b610203610411366004612c93565b61225f565b610203610424366004612b42565b61249f565b61043c610437366004612c66565b612542565b6040516101e79190612e27565b610203610457366004612b42565b6125cc565b5f80546001146104875760405162461bcd60e51b815260040161047e90612e35565b60405180910390fd5b60025f819055507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663fbfa77cf6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156104ea573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061050e9190612e59565b6001600160a01b031682608001516001600160a01b0316146105db5781608001517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663fbfa77cf6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561058b573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105af9190612e59565b604051639ee8ef4160e01b81526001600160a01b0392831660048201529116602482015260440161047e565b60608201516001600160a01b03163314610608576040516301b1115d60e41b815260040160405180910390fd5b60a0820151604051634104b9ed60e11b81526001600160a01b0391821660048201527f00000000000000000000000000000000000000000000000000000000000000009091169063820973da90602401602060405180830381865afa158015610673573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106979190612e74565b506001600160401b034216602083015260408201516001600160601b03165f036106d4576040516324a3228160e21b815260040160405180910390fd5b60808201516001600160a01b03166106ff5760405163199af6fb60e21b815260040160405180910390fd5b60a08201516001600160a01b031661072a576040516302863e3b60e51b815260040160405180910390fd5b608082015160608301516040516370a0823160e01b81526001600160a01b0391821660048201529116906370a0823190602401602060405180830381865afa158015610778573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061079c9190612e74565b82604001516001600160601b031611156107c957604051631fc8970160e01b815260040160405180910390fd5b81516001600160401b03164211156107f4576040516375e1731760e11b815260040160405180910390fd5b5f826040516020016108069190612e27565b60408051601f198184030181529190528051602090910120905061082b600382612648565b61084857604051631e788b6b60e31b815260040160405180910390fd5b5f8181526006602090815260408083208651815488850151898501516001600160401b039384166fffffffffffffffffffffffffffffffff1990931692909217600160401b9390911692909202919091176bffffffffffffffffffffffff60801b1916600160801b6001600160601b0390921691820217825560608801516001830180546001600160a01b03199081166001600160a01b039384161790915560808a01516002850180548316918416918217905560a08b0180516003909601805490931695841695909517909155865260078552838620925116855292528220805491929091610939908490612e9f565b90915550506060830151600b5460408501516080860151610973936001600160a01b039182169390929116906001600160601b031661265a565b8260a001516001600160a01b0316336001600160a01b0316827f16c101ffc8e284e1592775d8fad55cf6d1191fe328fc43804505f14152e1f08986608001518760400151885f0151426040516109cc9493929190612eb2565b60405180910390a460015f5592915050565b6109f3335f356001600160e01b0319166126f2565b610a0f5760405162461bcd60e51b815260040161047e90612eea565b600b80546001600160a01b0319166001600160a01b0383169081179091556040519081527ff13979f62eb3f1694b31513552441f45c5aee53783a43e41fe7596b0c4d5ea1a906020015b60405180910390a150565b606080610a6f610b9b565b8051909250806001600160401b03811115610a8c57610a8c612a33565b604051908082528060200260200182016040528015610ac557816020015b610ab26129ff565b815260200190600190039081610aaa5790505b5091505f5b81811015610b955760065f858381518110610ae757610ae7612f10565b60209081029190910181015182528181019290925260409081015f20815160c08101835281546001600160401b038082168352600160401b82041694820194909452600160801b9093046001600160601b03169183019190915260018101546001600160a01b0390811660608401526002820154811660808401526003909101541660a08201528351849083908110610b8257610b82612f10565b6020908102919091010152600101610aca565b50509091565b6060610ba76003612799565b905090565b610bc1335f356001600160e01b0319166126f2565b610bdd5760405162461bcd60e51b815260040161047e90612eea565b805f03610bfd57604051633db2faf760e01b815260040160405180910390fd5b60098190556040518181527f51684734f68942c7742f94c34ad2c806da1b498f6e8629e9cca1e7769e8576b490602001610a59565b5f610c436060830160408401612f24565b6001600160601b03165f03610c6b576040516324a3228160e21b815260040160405180910390fd5b5f610c7c6080840160608501612b42565b6001600160a01b031603610ca35760405163a605da9360e01b815260040160405180910390fd5b5f610cb460a0840160808501612b42565b6001600160a01b031603610cdb5760405163199af6fb60e21b815260040160405180910390fd5b5f610cec60c0840160a08501612b42565b6001600160a01b031603610d13576040516302863e3b60e51b815260040160405180910390fd5b610d206020830183612f3d565b6001600160401b0316421115610d49576040516375e1731760e11b815260040160405180910390fd5b5f610d5a60a0840160808501612b42565b90505f816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610d99573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610dbd9190612f56565b90505f6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001663820973da610dff60c0880160a08901612b42565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015610e41573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e659190612e74565b90505f610e87600a54620f4240610e7c9190612f76565b8390620f42406127a5565b9050610eac610e9c6060880160408901612f24565b6001600160601b031682856127c0565b9695505050505050565b610ecb335f356001600160e01b0319166126f2565b610ee75760405162461bcd60e51b815260040161047e90612eea565b5f5b8181101561115d5736838383818110610f0457610f04612f10565b905060c0020190505f81604051602001610f1e919061301e565b60408051601f1981840301815291905280516020909101209050610f436003826127d8565b610f6057604051630a589e7d60e31b815260040160405180910390fd5b610f706060830160408401612f24565b6001600160601b031660075f610f8c60a0860160808701612b42565b6001600160a01b0316815260208101919091526040015f90812090610fb760c0860160a08701612b42565b6001600160a01b03166001600160a01b031681526020019081526020015f205f828254610fe49190612f76565b90915550610ff590506003826127ef565b50600b5460405163506724fd60e11b81526001600160a01b039091169063a0ce49fa90611028903090869060040161302c565b5f604051808303815f87803b15801561103f575f80fd5b505af1158015611051573d5f803e3d5ffd5b5050600b546110b092506001600160a01b031690506110766080850160608601612b42565b6110866060860160408701612f24565b6001600160601b031661109f60a0870160808801612b42565b6001600160a01b031692919061265a565b6110c060c0830160a08401612b42565b6001600160a01b03166110d96080840160608501612b42565b6001600160a01b0316827f0752a5782112e7af73ca31e3d4983ec529f678bd61be936032ab7437fae0502a61111460a0870160808801612b42565b6111246060880160408901612f24565b6111316020890189612f3d565b426040516111429493929190612eb2565b60405180910390a450508061115690613049565b9050610ee9565b505050565b6001546001600160a01b03163314806111f4575060025460405163b700961360e01b81526001600160a01b039091169063b7009613906111b590339030906001600160e01b03195f351690600401613061565b602060405180830381865afa1580156111d0573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111f4919061308e565b6111fc575f80fd5b600280546001600160a01b0319166001600160a01b03831690811790915560405133907fa3396fd7f6e0a21b50e5089d2da70d5ac0a3bbbd1f617a93f134b76389980198905f90a350565b61125c335f356001600160e01b0319166126f2565b6112785760405162461bcd60e51b815260040161047e90612eea565b6001600160a01b03811661129f5760405163a605da9360e01b815260040160405180910390fd5b6001600160a01b0381165f81815260086020526040808220805460ff19169055517fde8cf212af7ce38b2840785a2768d97ff2dbf3c21b516961cec0061e134c2a1e9190a250565b6060805f6112f3610b9b565b80519091505f805b8281101561136357866001600160a01b031660065f86848151811061132257611322612f10565b60209081029190910181015182528101919091526040015f20600101546001600160a01b03160361135b578161135781613049565b9250505b6001016112fb565b50806001600160401b0381111561137c5761137c612a33565b6040519080825280602002602001820160405280156113a5578160200160208202803683370190505b509450806001600160401b038111156113c0576113c0612a33565b6040519080825280602002602001820160405280156113f957816020015b6113e66129ff565b8152602001906001900390816113de5790505b5093505f805b838110156114fc575f85828151811061141a5761141a612f10565b6020908102919091018101515f81815260068352604090819020815160c08101835281546001600160401b038082168352600160401b82041695820195909552600160801b9094046001600160601b03169184019190915260018101546001600160a01b0390811660608501819052600283015482166080860152600390920154811660a0850152919350908b1690036114f257818985815181106114c1576114c1612f10565b602002602001018181525050808885815181106114e0576114e0612f10565b60200260200101819052508360010193505b50506001016113ff565b5050505050915091565b6001600160a01b038083165f908152600760209081526040808320938516835292905220545b92915050565b611547335f356001600160e01b0319166126f2565b6115635760405162461bcd60e51b815260040161047e90612eea565b600580549082905560408051828152602081018490527fae0aad9a4c98a3c9a081c2da74a150b6fb3f61a844798309d193692e62f4aebd910160405180910390a15050565b5f816040516020016115ba919061301e565b60408051601f19818403018152919052805160209091012090506115df6003826127d8565b6115fc57604051630a589e7d60e31b815260040160405180910390fd5b5f61160d6080840160608501612b42565b90505f61162060a0850160808601612b42565b90506116326060850160408601612f24565b6001600160601b03165f0361165a576040516324a3228160e21b815260040160405180910390fd5b6001600160a01b0382166116815760405163a605da9360e01b815260040160405180910390fd5b6001600160a01b0381166116a85760405163199af6fb60e21b815260040160405180910390fd5b5f6116b960c0860160a08701612b42565b6001600160a01b0316036116e0576040516302863e3b60e51b815260040160405180910390fd5b6116ed6020850185612f3d565b6001600160401b0316421115611716576040516375e1731760e11b815260040160405180910390fd5b50505050565b5f5460011461173d5760405162461bcd60e51b815260040161047e90612e35565b60025f90815561175360a0830160808401612b42565b90505f61176660c0840160a08501612b42565b90505f6117796080850160608601612b42565b90505f836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156117b8573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117dc9190612f56565b90506117e7856115a8565b6001600160a01b0382165f9081526008602052604090205460ff1661180e5760055461181e565b60095460055461181e91906130ad565b61182e6040870160208801612f3d565b6001600160401b03166118419190612e9f565b42101561186c57604051631c1e73ed60e31b81526001600160a01b038316600482015260240161047e565b600b546001600160a01b03163314611899576040516321db743560e21b815233600482015260240161047e565b5f6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001663820973da6118d960c0890160a08a01612b42565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa15801561191b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061193f9190612e74565b90505f611956600a54620f4240610e7c9190612f76565b90505f61197c61196c60608a0160408b01612f24565b6001600160601b031683866127c0565b9050600b5f9054906101000a90046001600160a01b03166001600160a01b0316633331d30d8b8b338b8b8e60400160208101906119b99190612f24565b887f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663fbfa77cf6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a16573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611a3a9190612e59565b6040518963ffffffff1660e01b8152600401611a5d9897969594939291906130cc565b5f604051808303815f87803b158015611a74575f80fd5b505af1158015611a86573d5f803e3d5ffd5b5050600b54611aa592506001600160a01b03898116925016878461265a565b611ab56060890160408a01612f24565b6001600160a01b038089165f908152600760209081526040808320938b16835292905290812080546001600160601b039390931692909190611af8908490612f76565b90915550506040515f90611b10908a9060200161301e565b604051602081830303815290604052805190602001209050866001600160a01b0316866001600160a01b0316827f53f2fe7e195f144506d2562e6e349ab63baf2b6afba6645f0f77cab9486cfe0b8b8d6040016020810190611b729190612f24565b604080516001600160a01b0390931683526001600160601b039091166020830152810187905242606082015260800160405180910390a4611bb46003826127ef565b505060015f5550505050505050505050565b5f8054600114611be85760405162461bcd60e51b815260040161047e90612e35565b60025f81905550611c04335f356001600160e01b0319166126f2565b611c205760405162461bcd60e51b815260040161047e90612eea565b835f03611c425760405163aeb7e20360e01b815233600482015260240161047e565b5f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663fbfa77cf6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c9f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611cc39190612e59565b9050806001600160a01b0316876001600160a01b031614611d0a57604051639ee8ef4160e01b81526001600160a01b0380891660048301528216602482015260440161047e565b826001600160a01b031663fbfa77cf6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d46573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d6a9190612e59565b6001600160a01b0316876001600160a01b031614611dae5760405163bfb65ed560e01b81526001600160a01b0380891660048301528416602482015260440161047e565b5f876001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611deb573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e0f9190612f56565b611e1a90600a613216565b604051634104b9ed60e11b81526001600160a01b038981166004830152919250611eb1917f0000000000000000000000000000000000000000000000000000000000000000169063820973da90602401602060405180830381865afa158015611e85573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ea99190612e74565b8790836127a5565b92505f611ed3600a54620f4240611ec89190612f76565b8590620f42406127a5565b604051634104b9ed60e11b81526001600160a01b038a811660048301529192505f91611f92917f00000000000000000000000000000000000000000000000000000000000000009091169063820973da90602401602060405180830381865afa158015611f42573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f669190612e74565b6001600160a01b03808d165f908152600760209081526040808320938f168352929052205490856127a5565b6040516370a0823160e01b81526001600160a01b0386811660048301529192505f918b16906370a0823190602401602060405180830381865afa158015611fdb573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fff9190612e74565b90505f61200c8385612e9f565b9050818111156120395760405163109a32a360e01b8152600481018290526024810183905260440161047e565b8884101561205a576040516308b9dbeb60e01b815260040160405180910390fd5b61206f6001600160a01b038d1633308d61265a565b604051633e64ce9960e01b81526001600160a01b038c81166004830152602482018c9052604482018b9052306064830152891690633e64ce99906084016020604051808303815f875af11580156120c8573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120ec9190612e74565b965083871015612119576040516375860fa360e01b8152600481018590526024810188905260440161047e565b5f6121248589612f76565b90508015612140576121406001600160a01b038d1688836127fa565b6121546001600160a01b038d1633876127fa565b8497508b6001600160a01b03168d6001600160a01b0316336001600160a01b03167fbf923f0f1dfc3aa6f87bb57a40713a4460c5189e2937b1fb0daab093639e2c488e89426040516121b9939291909283526020830191909152604082015260600190565b60405180910390a4505060015f5550939998505050505050505050565b6121eb335f356001600160e01b0319166126f2565b6122075760405162461bcd60e51b815260040161047e90612eea565b620f4240811061222a5760405163b24e0f7560e01b815260040160405180910390fd5b600a8190556040518181527f4380d185219209b34ffa7f42fb87214e1e8b63a4957f532acc0cfa84697f051490602001610a59565b336122706080830160608401612b42565b6001600160a01b031614612297576040516301b1115d60e41b815260040160405180910390fd5b5f816040516020016122a9919061301e565b60408051601f19818403018152919052805160209091012090506122ce6003826127d8565b6122eb57604051630a589e7d60e31b815260040160405180910390fd5b6122fb6060830160408401612f24565b6001600160601b031660075f61231760a0860160808701612b42565b6001600160a01b0316815260208101919091526040015f9081209061234260c0860160a08701612b42565b6001600160a01b03166001600160a01b031681526020019081526020015f205f82825461236f9190612f76565b9091555061238090506003826127ef565b50600b5460405163506724fd60e11b81526001600160a01b039091169063a0ce49fa906123b3903090869060040161302c565b5f604051808303815f87803b1580156123ca575f80fd5b505af11580156123dc573d5f803e3d5ffd5b5050600b5461240192506001600160a01b031690506110766080850160608601612b42565b61241160c0830160a08401612b42565b6001600160a01b031661242a6080840160608501612b42565b6001600160a01b0316827f0752a5782112e7af73ca31e3d4983ec529f678bd61be936032ab7437fae0502a61246560a0870160808801612b42565b6124756060880160408901612f24565b6124826020890189612f3d565b426040516124939493929190612eb2565b60405180910390a45050565b6124b4335f356001600160e01b0319166126f2565b6124d05760405162461bcd60e51b815260040161047e90612eea565b6001600160a01b0381166124f75760405163a605da9360e01b815260040160405180910390fd5b6001600160a01b0381165f81815260086020526040808220805460ff19166001179055517f4790a4adb426ca2345bb5108f6e454eae852a7bf687544cd66a7270dff3a41d69190a250565b61254a6129ff565b505f90815260066020908152604091829020825160c08101845281546001600160401b038082168352600160401b82041693820193909352600160801b9092046001600160601b03169282019290925260018201546001600160a01b03908116606083015260028301548116608083015260039092015490911660a082015290565b6125e1335f356001600160e01b0319166126f2565b6125fd5760405162461bcd60e51b815260040161047e90612eea565b600180546001600160a01b0319166001600160a01b03831690811790915560405133907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a350565b5f6126538383612877565b9392505050565b5f6040516323b872dd60e01b81526001600160a01b03851660048201526001600160a01b038416602482015282604482015260205f6064835f8a5af13d15601f3d1160015f5114161716915050806126eb5760405162461bcd60e51b81526020600482015260146024820152731514905394d1915497d19493d357d1905253115160621b604482015260640161047e565b5050505050565b6002545f906001600160a01b03168015801590612779575060405163b700961360e01b81526001600160a01b0382169063b70096139061273a90879030908890600401613061565b602060405180830381865afa158015612755573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612779919061308e565b8061279157506001546001600160a01b038581169116145b949350505050565b60605f612653836128c3565b5f825f1904841183021582026127b9575f80fd5b5091020490565b5f612791846127d084600a613216565b8591906127a5565b5f8181526001830160205260408120541515612653565b5f612653838361291c565b5f60405163a9059cbb60e01b81526001600160a01b038416600482015282602482015260205f6044835f895af13d15601f3d1160015f5114161716915050806117165760405162461bcd60e51b815260206004820152600f60248201526e1514905394d1915497d19052531151608a1b604482015260640161047e565b5f8181526001830160205260408120546128bc57508154600181810184555f84815260208082209093018490558454848252828601909352604090209190915561152c565b505f61152c565b6060815f0180548060200260200160405190810160405280929190818152602001828054801561291057602002820191905f5260205f20905b8154815260200190600101908083116128fc575b50505050509050919050565b5f81815260018301602052604081205480156129f6575f61293e600183612f76565b85549091505f9061295190600190612f76565b90508082146129b0575f865f01828154811061296f5761296f612f10565b905f5260205f200154905080875f01848154811061298f5761298f612f10565b5f918252602080832090910192909255918252600188019052604090208390555b85548690806129c1576129c1613224565b600190038181905f5260205f20015f90559055856001015f8681526020019081526020015f205f90556001935050505061152c565b5f91505061152c565b6040805160c0810182525f80825260208201819052918101829052606081018290526080810182905260a081019190915290565b634e487b7160e01b5f52604160045260245ffd5b80356001600160401b0381168114612a5d575f80fd5b919050565b80356001600160601b0381168114612a5d575f80fd5b6001600160a01b0381168114612a8c575f80fd5b50565b8035612a5d81612a78565b5f60c08284031215612aaa575f80fd5b60405160c081018181106001600160401b0382111715612ad857634e487b7160e01b5f52604160045260245ffd5b604052612ae483612a47565b8152612af260208401612a47565b6020820152612b0360408401612a62565b6040820152612b1460608401612a8f565b6060820152612b2560808401612a8f565b6080820152612b3660a08401612a8f565b60a08201529392505050565b5f60208284031215612b52575f80fd5b813561265381612a78565b5f8151808452602080850194508084015f5b83811015612b8b57815187529582019590820190600101612b6f565b509495945050505050565b80516001600160401b039081168352602080830151909116908301526040808201516001600160601b0316908301526060808201516001600160a01b039081169184019190915260808083015182169084015260a09182015116910152565b604081525f612c076040830185612b5d565b8281036020848101919091528451808352858201928201905f5b81811015612c4757612c34838651612b96565b9383019360c09290920191600101612c21565b5090979650505050505050565b602081525f6126536020830184612b5d565b5f60208284031215612c76575f80fd5b5035919050565b5f60c08284031215612c8d575f80fd5b50919050565b5f60c08284031215612ca3575f80fd5b6126538383612c7d565b5f8060208385031215612cbe575f80fd5b82356001600160401b0380821115612cd4575f80fd5b818501915085601f830112612ce7575f80fd5b813581811115612cf5575f80fd5b86602060c083028501011115612d09575f80fd5b60209290920196919550909350505050565b5f8060408385031215612d2c575f80fd5b8235612d3781612a78565b91506020830135612d4781612a78565b809150509250929050565b5f805f60e08486031215612d64575f80fd5b83356001600160401b0380821115612d7a575f80fd5b818601915086601f830112612d8d575f80fd5b813581811115612d9b575f80fd5b876020828501011115612dac575f80fd5b602092830195509350612dc3918791508601612c7d565b90509250925092565b5f805f805f60a08688031215612de0575f80fd5b8535612deb81612a78565b94506020860135612dfb81612a78565b935060408601359250606086013591506080860135612e1981612a78565b809150509295509295909350565b60c0810161152c8284612b96565b6020808252600a90820152695245454e5452414e435960b01b604082015260600190565b5f60208284031215612e69575f80fd5b815161265381612a78565b5f60208284031215612e84575f80fd5b5051919050565b634e487b7160e01b5f52601160045260245ffd5b8082018082111561152c5761152c612e8b565b6001600160a01b039490941684526001600160601b039290921660208401526001600160401b03166040830152606082015260800190565b6020808252600c908201526b15539055551213d49256915160a21b604082015260600190565b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215612f34575f80fd5b61265382612a62565b5f60208284031215612f4d575f80fd5b61265382612a47565b5f60208284031215612f66575f80fd5b815160ff81168114612653575f80fd5b8181038181111561152c5761152c612e8b565b6001600160401b0380612f9b83612a47565b16835280612fab60208401612a47565b166020840152506001600160601b03612fc660408301612a62565b1660408301526060810135612fda81612a78565b6001600160a01b039081166060840152608082013590612ff982612a78565b908116608084015260a08201359061301082612a78565b80821660a085015250505050565b60c0810161152c8284612f89565b6001600160a01b038316815260e081016126536020830184612f89565b5f6001820161305a5761305a612e8b565b5060010190565b6001600160a01b0393841681529190921660208201526001600160e01b0319909116604082015260600190565b5f6020828403121561309e575f80fd5b81518015158114612653575f80fd5b5f826130c757634e487b7160e01b5f52601260045260245ffd5b500490565b60e081528760e08201525f610100898b828501375f838b018201526001600160a01b03988916602084015296881660408301525093861660608501526001600160601b0392909216608084015260a083015290921660c0830152601f909201601f19160101919050565b600181815b8085111561317057815f190482111561315657613156612e8b565b8085161561316357918102915b93841c939080029061313b565b509250929050565b5f826131865750600161152c565b8161319257505f61152c565b81600181146131a857600281146131b2576131ce565b600191505061152c565b60ff8411156131c3576131c3612e8b565b50506001821b61152c565b5060208310610133831016604e8410600b84101617156131f1575081810a61152c565b6131fb8383613136565b805f190482111561320e5761320e612e8b565b029392505050565b5f61265360ff841683613178565b634e487b7160e01b5f52603160045260245ffdfea2646970667358221220320cac1ac59f41cf3d65b5ee5a8bcb6a048aa13aa80fccf2895022e1e53c755f64736f6c634300081500330000000000000000000000008ab8aeef444aee718a275a8325795fe90cf162c400000000000000000000000058a6481706e4260ef50d362401c7f0357b13ab530000000000000000000000000427645bcea78a84a84efbc26d51f87176581cd90000000000000000000000001db629316b3fb6b026f9ebd5c379a72235a4d5e9
Deployed Bytecode
0x608060405234801561000f575f80fd5b50600436106101c6575f3560e01c80638da5cb5b116100fe578063c2f0549f1161009e578063e09bd8e91161006e578063e09bd8e914610403578063e43252d714610416578063e57b50c214610429578063f2fde38b14610449575f80fd5b8063c2f0549f146103b7578063c49b8941146103ca578063cdf30c7a146103dd578063dabd2719146103f0575f80fd5b80639ce4cd2d116100d95780639ce4cd2d14610354578063b11ae5b714610367578063b68ffe0714610391578063bf7e214f146103a4575f80fd5b80638da5cb5b146102fc57806396bb9fbe1461030f5780639b19251a14610322575f80fd5b80634fb3ccc51161016957806371cab2fa1161014457806371cab2fa146102ba5780637a1106bc146102c35780637a9e5e4b146102d65780638ab1d681146102e9575f80fd5b80634fb3ccc514610277578063676418f71461029e5780636b6f4a9d146102b1575f80fd5b806342349b46116101a457806342349b461461021b578063475dfea11461023057806349a7a26d146102435780634e8bfdaa1461026e575f80fd5b8063062f5511146101ca5780631f879433146101f057806335b0012c14610205575b5f80fd5b6101dd6101d8366004612a9a565b61045c565b6040519081526020015b60405180910390f35b6102036101fe366004612b42565b6109de565b005b61020d610a64565b6040516101e7929190612bf5565b610223610b9b565b6040516101e79190612c54565b61020361023e366004612c66565b610bac565b600b54610256906001600160a01b031681565b6040516001600160a01b0390911681526020016101e7565b6101dd60055481565b6102567f0000000000000000000000000427645bcea78a84a84efbc26d51f87176581cd981565b6101dd6102ac366004612c93565b610c32565b6101dd600a5481565b6101dd60095481565b6102036102d1366004612cad565b610eb6565b6102036102e4366004612b42565b611162565b6102036102f7366004612b42565b611247565b600154610256906001600160a01b031681565b61020d61031d366004612b42565b6112e7565b610344610330366004612b42565b60086020525f908152604090205460ff1681565b60405190151581526020016101e7565b6101dd610362366004612d1b565b611506565b6101dd610375366004612d1b565b600760209081525f928352604080842090915290825290205481565b61020361039f366004612c66565b611532565b600254610256906001600160a01b031681565b6102036103c5366004612c93565b6115a8565b6102036103d8366004612d52565b61171c565b6101dd6103eb366004612dcc565b611bc6565b6102036103fe366004612c66565b6121d6565b610203610411366004612c93565b61225f565b610203610424366004612b42565b61249f565b61043c610437366004612c66565b612542565b6040516101e79190612e27565b610203610457366004612b42565b6125cc565b5f80546001146104875760405162461bcd60e51b815260040161047e90612e35565b60405180910390fd5b60025f819055507f0000000000000000000000000427645bcea78a84a84efbc26d51f87176581cd96001600160a01b031663fbfa77cf6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156104ea573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061050e9190612e59565b6001600160a01b031682608001516001600160a01b0316146105db5781608001517f0000000000000000000000000427645bcea78a84a84efbc26d51f87176581cd96001600160a01b031663fbfa77cf6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561058b573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105af9190612e59565b604051639ee8ef4160e01b81526001600160a01b0392831660048201529116602482015260440161047e565b60608201516001600160a01b03163314610608576040516301b1115d60e41b815260040160405180910390fd5b60a0820151604051634104b9ed60e11b81526001600160a01b0391821660048201527f0000000000000000000000000427645bcea78a84a84efbc26d51f87176581cd99091169063820973da90602401602060405180830381865afa158015610673573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106979190612e74565b506001600160401b034216602083015260408201516001600160601b03165f036106d4576040516324a3228160e21b815260040160405180910390fd5b60808201516001600160a01b03166106ff5760405163199af6fb60e21b815260040160405180910390fd5b60a08201516001600160a01b031661072a576040516302863e3b60e51b815260040160405180910390fd5b608082015160608301516040516370a0823160e01b81526001600160a01b0391821660048201529116906370a0823190602401602060405180830381865afa158015610778573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061079c9190612e74565b82604001516001600160601b031611156107c957604051631fc8970160e01b815260040160405180910390fd5b81516001600160401b03164211156107f4576040516375e1731760e11b815260040160405180910390fd5b5f826040516020016108069190612e27565b60408051601f198184030181529190528051602090910120905061082b600382612648565b61084857604051631e788b6b60e31b815260040160405180910390fd5b5f8181526006602090815260408083208651815488850151898501516001600160401b039384166fffffffffffffffffffffffffffffffff1990931692909217600160401b9390911692909202919091176bffffffffffffffffffffffff60801b1916600160801b6001600160601b0390921691820217825560608801516001830180546001600160a01b03199081166001600160a01b039384161790915560808a01516002850180548316918416918217905560a08b0180516003909601805490931695841695909517909155865260078552838620925116855292528220805491929091610939908490612e9f565b90915550506060830151600b5460408501516080860151610973936001600160a01b039182169390929116906001600160601b031661265a565b8260a001516001600160a01b0316336001600160a01b0316827f16c101ffc8e284e1592775d8fad55cf6d1191fe328fc43804505f14152e1f08986608001518760400151885f0151426040516109cc9493929190612eb2565b60405180910390a460015f5592915050565b6109f3335f356001600160e01b0319166126f2565b610a0f5760405162461bcd60e51b815260040161047e90612eea565b600b80546001600160a01b0319166001600160a01b0383169081179091556040519081527ff13979f62eb3f1694b31513552441f45c5aee53783a43e41fe7596b0c4d5ea1a906020015b60405180910390a150565b606080610a6f610b9b565b8051909250806001600160401b03811115610a8c57610a8c612a33565b604051908082528060200260200182016040528015610ac557816020015b610ab26129ff565b815260200190600190039081610aaa5790505b5091505f5b81811015610b955760065f858381518110610ae757610ae7612f10565b60209081029190910181015182528181019290925260409081015f20815160c08101835281546001600160401b038082168352600160401b82041694820194909452600160801b9093046001600160601b03169183019190915260018101546001600160a01b0390811660608401526002820154811660808401526003909101541660a08201528351849083908110610b8257610b82612f10565b6020908102919091010152600101610aca565b50509091565b6060610ba76003612799565b905090565b610bc1335f356001600160e01b0319166126f2565b610bdd5760405162461bcd60e51b815260040161047e90612eea565b805f03610bfd57604051633db2faf760e01b815260040160405180910390fd5b60098190556040518181527f51684734f68942c7742f94c34ad2c806da1b498f6e8629e9cca1e7769e8576b490602001610a59565b5f610c436060830160408401612f24565b6001600160601b03165f03610c6b576040516324a3228160e21b815260040160405180910390fd5b5f610c7c6080840160608501612b42565b6001600160a01b031603610ca35760405163a605da9360e01b815260040160405180910390fd5b5f610cb460a0840160808501612b42565b6001600160a01b031603610cdb5760405163199af6fb60e21b815260040160405180910390fd5b5f610cec60c0840160a08501612b42565b6001600160a01b031603610d13576040516302863e3b60e51b815260040160405180910390fd5b610d206020830183612f3d565b6001600160401b0316421115610d49576040516375e1731760e11b815260040160405180910390fd5b5f610d5a60a0840160808501612b42565b90505f816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610d99573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610dbd9190612f56565b90505f6001600160a01b037f0000000000000000000000000427645bcea78a84a84efbc26d51f87176581cd91663820973da610dff60c0880160a08901612b42565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015610e41573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e659190612e74565b90505f610e87600a54620f4240610e7c9190612f76565b8390620f42406127a5565b9050610eac610e9c6060880160408901612f24565b6001600160601b031682856127c0565b9695505050505050565b610ecb335f356001600160e01b0319166126f2565b610ee75760405162461bcd60e51b815260040161047e90612eea565b5f5b8181101561115d5736838383818110610f0457610f04612f10565b905060c0020190505f81604051602001610f1e919061301e565b60408051601f1981840301815291905280516020909101209050610f436003826127d8565b610f6057604051630a589e7d60e31b815260040160405180910390fd5b610f706060830160408401612f24565b6001600160601b031660075f610f8c60a0860160808701612b42565b6001600160a01b0316815260208101919091526040015f90812090610fb760c0860160a08701612b42565b6001600160a01b03166001600160a01b031681526020019081526020015f205f828254610fe49190612f76565b90915550610ff590506003826127ef565b50600b5460405163506724fd60e11b81526001600160a01b039091169063a0ce49fa90611028903090869060040161302c565b5f604051808303815f87803b15801561103f575f80fd5b505af1158015611051573d5f803e3d5ffd5b5050600b546110b092506001600160a01b031690506110766080850160608601612b42565b6110866060860160408701612f24565b6001600160601b031661109f60a0870160808801612b42565b6001600160a01b031692919061265a565b6110c060c0830160a08401612b42565b6001600160a01b03166110d96080840160608501612b42565b6001600160a01b0316827f0752a5782112e7af73ca31e3d4983ec529f678bd61be936032ab7437fae0502a61111460a0870160808801612b42565b6111246060880160408901612f24565b6111316020890189612f3d565b426040516111429493929190612eb2565b60405180910390a450508061115690613049565b9050610ee9565b505050565b6001546001600160a01b03163314806111f4575060025460405163b700961360e01b81526001600160a01b039091169063b7009613906111b590339030906001600160e01b03195f351690600401613061565b602060405180830381865afa1580156111d0573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111f4919061308e565b6111fc575f80fd5b600280546001600160a01b0319166001600160a01b03831690811790915560405133907fa3396fd7f6e0a21b50e5089d2da70d5ac0a3bbbd1f617a93f134b76389980198905f90a350565b61125c335f356001600160e01b0319166126f2565b6112785760405162461bcd60e51b815260040161047e90612eea565b6001600160a01b03811661129f5760405163a605da9360e01b815260040160405180910390fd5b6001600160a01b0381165f81815260086020526040808220805460ff19169055517fde8cf212af7ce38b2840785a2768d97ff2dbf3c21b516961cec0061e134c2a1e9190a250565b6060805f6112f3610b9b565b80519091505f805b8281101561136357866001600160a01b031660065f86848151811061132257611322612f10565b60209081029190910181015182528101919091526040015f20600101546001600160a01b03160361135b578161135781613049565b9250505b6001016112fb565b50806001600160401b0381111561137c5761137c612a33565b6040519080825280602002602001820160405280156113a5578160200160208202803683370190505b509450806001600160401b038111156113c0576113c0612a33565b6040519080825280602002602001820160405280156113f957816020015b6113e66129ff565b8152602001906001900390816113de5790505b5093505f805b838110156114fc575f85828151811061141a5761141a612f10565b6020908102919091018101515f81815260068352604090819020815160c08101835281546001600160401b038082168352600160401b82041695820195909552600160801b9094046001600160601b03169184019190915260018101546001600160a01b0390811660608501819052600283015482166080860152600390920154811660a0850152919350908b1690036114f257818985815181106114c1576114c1612f10565b602002602001018181525050808885815181106114e0576114e0612f10565b60200260200101819052508360010193505b50506001016113ff565b5050505050915091565b6001600160a01b038083165f908152600760209081526040808320938516835292905220545b92915050565b611547335f356001600160e01b0319166126f2565b6115635760405162461bcd60e51b815260040161047e90612eea565b600580549082905560408051828152602081018490527fae0aad9a4c98a3c9a081c2da74a150b6fb3f61a844798309d193692e62f4aebd910160405180910390a15050565b5f816040516020016115ba919061301e565b60408051601f19818403018152919052805160209091012090506115df6003826127d8565b6115fc57604051630a589e7d60e31b815260040160405180910390fd5b5f61160d6080840160608501612b42565b90505f61162060a0850160808601612b42565b90506116326060850160408601612f24565b6001600160601b03165f0361165a576040516324a3228160e21b815260040160405180910390fd5b6001600160a01b0382166116815760405163a605da9360e01b815260040160405180910390fd5b6001600160a01b0381166116a85760405163199af6fb60e21b815260040160405180910390fd5b5f6116b960c0860160a08701612b42565b6001600160a01b0316036116e0576040516302863e3b60e51b815260040160405180910390fd5b6116ed6020850185612f3d565b6001600160401b0316421115611716576040516375e1731760e11b815260040160405180910390fd5b50505050565b5f5460011461173d5760405162461bcd60e51b815260040161047e90612e35565b60025f90815561175360a0830160808401612b42565b90505f61176660c0840160a08501612b42565b90505f6117796080850160608601612b42565b90505f836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156117b8573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117dc9190612f56565b90506117e7856115a8565b6001600160a01b0382165f9081526008602052604090205460ff1661180e5760055461181e565b60095460055461181e91906130ad565b61182e6040870160208801612f3d565b6001600160401b03166118419190612e9f565b42101561186c57604051631c1e73ed60e31b81526001600160a01b038316600482015260240161047e565b600b546001600160a01b03163314611899576040516321db743560e21b815233600482015260240161047e565b5f6001600160a01b037f0000000000000000000000000427645bcea78a84a84efbc26d51f87176581cd91663820973da6118d960c0890160a08a01612b42565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa15801561191b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061193f9190612e74565b90505f611956600a54620f4240610e7c9190612f76565b90505f61197c61196c60608a0160408b01612f24565b6001600160601b031683866127c0565b9050600b5f9054906101000a90046001600160a01b03166001600160a01b0316633331d30d8b8b338b8b8e60400160208101906119b99190612f24565b887f0000000000000000000000000427645bcea78a84a84efbc26d51f87176581cd96001600160a01b031663fbfa77cf6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a16573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611a3a9190612e59565b6040518963ffffffff1660e01b8152600401611a5d9897969594939291906130cc565b5f604051808303815f87803b158015611a74575f80fd5b505af1158015611a86573d5f803e3d5ffd5b5050600b54611aa592506001600160a01b03898116925016878461265a565b611ab56060890160408a01612f24565b6001600160a01b038089165f908152600760209081526040808320938b16835292905290812080546001600160601b039390931692909190611af8908490612f76565b90915550506040515f90611b10908a9060200161301e565b604051602081830303815290604052805190602001209050866001600160a01b0316866001600160a01b0316827f53f2fe7e195f144506d2562e6e349ab63baf2b6afba6645f0f77cab9486cfe0b8b8d6040016020810190611b729190612f24565b604080516001600160a01b0390931683526001600160601b039091166020830152810187905242606082015260800160405180910390a4611bb46003826127ef565b505060015f5550505050505050505050565b5f8054600114611be85760405162461bcd60e51b815260040161047e90612e35565b60025f81905550611c04335f356001600160e01b0319166126f2565b611c205760405162461bcd60e51b815260040161047e90612eea565b835f03611c425760405163aeb7e20360e01b815233600482015260240161047e565b5f7f0000000000000000000000000427645bcea78a84a84efbc26d51f87176581cd96001600160a01b031663fbfa77cf6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c9f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611cc39190612e59565b9050806001600160a01b0316876001600160a01b031614611d0a57604051639ee8ef4160e01b81526001600160a01b0380891660048301528216602482015260440161047e565b826001600160a01b031663fbfa77cf6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d46573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d6a9190612e59565b6001600160a01b0316876001600160a01b031614611dae5760405163bfb65ed560e01b81526001600160a01b0380891660048301528416602482015260440161047e565b5f876001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611deb573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e0f9190612f56565b611e1a90600a613216565b604051634104b9ed60e11b81526001600160a01b038981166004830152919250611eb1917f0000000000000000000000000427645bcea78a84a84efbc26d51f87176581cd9169063820973da90602401602060405180830381865afa158015611e85573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ea99190612e74565b8790836127a5565b92505f611ed3600a54620f4240611ec89190612f76565b8590620f42406127a5565b604051634104b9ed60e11b81526001600160a01b038a811660048301529192505f91611f92917f0000000000000000000000000427645bcea78a84a84efbc26d51f87176581cd99091169063820973da90602401602060405180830381865afa158015611f42573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f669190612e74565b6001600160a01b03808d165f908152600760209081526040808320938f168352929052205490856127a5565b6040516370a0823160e01b81526001600160a01b0386811660048301529192505f918b16906370a0823190602401602060405180830381865afa158015611fdb573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fff9190612e74565b90505f61200c8385612e9f565b9050818111156120395760405163109a32a360e01b8152600481018290526024810183905260440161047e565b8884101561205a576040516308b9dbeb60e01b815260040160405180910390fd5b61206f6001600160a01b038d1633308d61265a565b604051633e64ce9960e01b81526001600160a01b038c81166004830152602482018c9052604482018b9052306064830152891690633e64ce99906084016020604051808303815f875af11580156120c8573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120ec9190612e74565b965083871015612119576040516375860fa360e01b8152600481018590526024810188905260440161047e565b5f6121248589612f76565b90508015612140576121406001600160a01b038d1688836127fa565b6121546001600160a01b038d1633876127fa565b8497508b6001600160a01b03168d6001600160a01b0316336001600160a01b03167fbf923f0f1dfc3aa6f87bb57a40713a4460c5189e2937b1fb0daab093639e2c488e89426040516121b9939291909283526020830191909152604082015260600190565b60405180910390a4505060015f5550939998505050505050505050565b6121eb335f356001600160e01b0319166126f2565b6122075760405162461bcd60e51b815260040161047e90612eea565b620f4240811061222a5760405163b24e0f7560e01b815260040160405180910390fd5b600a8190556040518181527f4380d185219209b34ffa7f42fb87214e1e8b63a4957f532acc0cfa84697f051490602001610a59565b336122706080830160608401612b42565b6001600160a01b031614612297576040516301b1115d60e41b815260040160405180910390fd5b5f816040516020016122a9919061301e565b60408051601f19818403018152919052805160209091012090506122ce6003826127d8565b6122eb57604051630a589e7d60e31b815260040160405180910390fd5b6122fb6060830160408401612f24565b6001600160601b031660075f61231760a0860160808701612b42565b6001600160a01b0316815260208101919091526040015f9081209061234260c0860160a08701612b42565b6001600160a01b03166001600160a01b031681526020019081526020015f205f82825461236f9190612f76565b9091555061238090506003826127ef565b50600b5460405163506724fd60e11b81526001600160a01b039091169063a0ce49fa906123b3903090869060040161302c565b5f604051808303815f87803b1580156123ca575f80fd5b505af11580156123dc573d5f803e3d5ffd5b5050600b5461240192506001600160a01b031690506110766080850160608601612b42565b61241160c0830160a08401612b42565b6001600160a01b031661242a6080840160608501612b42565b6001600160a01b0316827f0752a5782112e7af73ca31e3d4983ec529f678bd61be936032ab7437fae0502a61246560a0870160808801612b42565b6124756060880160408901612f24565b6124826020890189612f3d565b426040516124939493929190612eb2565b60405180910390a45050565b6124b4335f356001600160e01b0319166126f2565b6124d05760405162461bcd60e51b815260040161047e90612eea565b6001600160a01b0381166124f75760405163a605da9360e01b815260040160405180910390fd5b6001600160a01b0381165f81815260086020526040808220805460ff19166001179055517f4790a4adb426ca2345bb5108f6e454eae852a7bf687544cd66a7270dff3a41d69190a250565b61254a6129ff565b505f90815260066020908152604091829020825160c08101845281546001600160401b038082168352600160401b82041693820193909352600160801b9092046001600160601b03169282019290925260018201546001600160a01b03908116606083015260028301548116608083015260039092015490911660a082015290565b6125e1335f356001600160e01b0319166126f2565b6125fd5760405162461bcd60e51b815260040161047e90612eea565b600180546001600160a01b0319166001600160a01b03831690811790915560405133907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a350565b5f6126538383612877565b9392505050565b5f6040516323b872dd60e01b81526001600160a01b03851660048201526001600160a01b038416602482015282604482015260205f6064835f8a5af13d15601f3d1160015f5114161716915050806126eb5760405162461bcd60e51b81526020600482015260146024820152731514905394d1915497d19493d357d1905253115160621b604482015260640161047e565b5050505050565b6002545f906001600160a01b03168015801590612779575060405163b700961360e01b81526001600160a01b0382169063b70096139061273a90879030908890600401613061565b602060405180830381865afa158015612755573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612779919061308e565b8061279157506001546001600160a01b038581169116145b949350505050565b60605f612653836128c3565b5f825f1904841183021582026127b9575f80fd5b5091020490565b5f612791846127d084600a613216565b8591906127a5565b5f8181526001830160205260408120541515612653565b5f612653838361291c565b5f60405163a9059cbb60e01b81526001600160a01b038416600482015282602482015260205f6044835f895af13d15601f3d1160015f5114161716915050806117165760405162461bcd60e51b815260206004820152600f60248201526e1514905394d1915497d19052531151608a1b604482015260640161047e565b5f8181526001830160205260408120546128bc57508154600181810184555f84815260208082209093018490558454848252828601909352604090209190915561152c565b505f61152c565b6060815f0180548060200260200160405190810160405280929190818152602001828054801561291057602002820191905f5260205f20905b8154815260200190600101908083116128fc575b50505050509050919050565b5f81815260018301602052604081205480156129f6575f61293e600183612f76565b85549091505f9061295190600190612f76565b90508082146129b0575f865f01828154811061296f5761296f612f10565b905f5260205f200154905080875f01848154811061298f5761298f612f10565b5f918252602080832090910192909255918252600188019052604090208390555b85548690806129c1576129c1613224565b600190038181905f5260205f20015f90559055856001015f8681526020019081526020015f205f90556001935050505061152c565b5f91505061152c565b6040805160c0810182525f80825260208201819052918101829052606081018290526080810182905260a081019190915290565b634e487b7160e01b5f52604160045260245ffd5b80356001600160401b0381168114612a5d575f80fd5b919050565b80356001600160601b0381168114612a5d575f80fd5b6001600160a01b0381168114612a8c575f80fd5b50565b8035612a5d81612a78565b5f60c08284031215612aaa575f80fd5b60405160c081018181106001600160401b0382111715612ad857634e487b7160e01b5f52604160045260245ffd5b604052612ae483612a47565b8152612af260208401612a47565b6020820152612b0360408401612a62565b6040820152612b1460608401612a8f565b6060820152612b2560808401612a8f565b6080820152612b3660a08401612a8f565b60a08201529392505050565b5f60208284031215612b52575f80fd5b813561265381612a78565b5f8151808452602080850194508084015f5b83811015612b8b57815187529582019590820190600101612b6f565b509495945050505050565b80516001600160401b039081168352602080830151909116908301526040808201516001600160601b0316908301526060808201516001600160a01b039081169184019190915260808083015182169084015260a09182015116910152565b604081525f612c076040830185612b5d565b8281036020848101919091528451808352858201928201905f5b81811015612c4757612c34838651612b96565b9383019360c09290920191600101612c21565b5090979650505050505050565b602081525f6126536020830184612b5d565b5f60208284031215612c76575f80fd5b5035919050565b5f60c08284031215612c8d575f80fd5b50919050565b5f60c08284031215612ca3575f80fd5b6126538383612c7d565b5f8060208385031215612cbe575f80fd5b82356001600160401b0380821115612cd4575f80fd5b818501915085601f830112612ce7575f80fd5b813581811115612cf5575f80fd5b86602060c083028501011115612d09575f80fd5b60209290920196919550909350505050565b5f8060408385031215612d2c575f80fd5b8235612d3781612a78565b91506020830135612d4781612a78565b809150509250929050565b5f805f60e08486031215612d64575f80fd5b83356001600160401b0380821115612d7a575f80fd5b818601915086601f830112612d8d575f80fd5b813581811115612d9b575f80fd5b876020828501011115612dac575f80fd5b602092830195509350612dc3918791508601612c7d565b90509250925092565b5f805f805f60a08688031215612de0575f80fd5b8535612deb81612a78565b94506020860135612dfb81612a78565b935060408601359250606086013591506080860135612e1981612a78565b809150509295509295909350565b60c0810161152c8284612b96565b6020808252600a90820152695245454e5452414e435960b01b604082015260600190565b5f60208284031215612e69575f80fd5b815161265381612a78565b5f60208284031215612e84575f80fd5b5051919050565b634e487b7160e01b5f52601160045260245ffd5b8082018082111561152c5761152c612e8b565b6001600160a01b039490941684526001600160601b039290921660208401526001600160401b03166040830152606082015260800190565b6020808252600c908201526b15539055551213d49256915160a21b604082015260600190565b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215612f34575f80fd5b61265382612a62565b5f60208284031215612f4d575f80fd5b61265382612a47565b5f60208284031215612f66575f80fd5b815160ff81168114612653575f80fd5b8181038181111561152c5761152c612e8b565b6001600160401b0380612f9b83612a47565b16835280612fab60208401612a47565b166020840152506001600160601b03612fc660408301612a62565b1660408301526060810135612fda81612a78565b6001600160a01b039081166060840152608082013590612ff982612a78565b908116608084015260a08201359061301082612a78565b80821660a085015250505050565b60c0810161152c8284612f89565b6001600160a01b038316815260e081016126536020830184612f89565b5f6001820161305a5761305a612e8b565b5060010190565b6001600160a01b0393841681529190921660208201526001600160e01b0319909116604082015260600190565b5f6020828403121561309e575f80fd5b81518015158114612653575f80fd5b5f826130c757634e487b7160e01b5f52601260045260245ffd5b500490565b60e081528760e08201525f610100898b828501375f838b018201526001600160a01b03988916602084015296881660408301525093861660608501526001600160601b0392909216608084015260a083015290921660c0830152601f909201601f19160101919050565b600181815b8085111561317057815f190482111561315657613156612e8b565b8085161561316357918102915b93841c939080029061313b565b509250929050565b5f826131865750600161152c565b8161319257505f61152c565b81600181146131a857600281146131b2576131ce565b600191505061152c565b60ff8411156131c3576131c3612e8b565b50506001821b61152c565b5060208310610133831016604e8410600b84101617156131f1575081810a61152c565b6131fb8383613136565b805f190482111561320e5761320e612e8b565b029392505050565b5f61265360ff841683613178565b634e487b7160e01b5f52603160045260245ffdfea2646970667358221220320cac1ac59f41cf3d65b5ee5a8bcb6a048aa13aa80fccf2895022e1e53c755f64736f6c63430008150033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000008ab8aeef444aee718a275a8325795fe90cf162c400000000000000000000000058a6481706e4260ef50d362401c7f0357b13ab530000000000000000000000000427645bcea78a84a84efbc26d51f87176581cd90000000000000000000000001db629316b3fb6b026f9ebd5c379a72235a4d5e9
-----Decoded View---------------
Arg [0] : _owner (address): 0x8Ab8aEEf444AeE718A275a8325795FE90CF162c4
Arg [1] : _authority (address): 0x58A6481706E4260ef50D362401C7F0357b13AB53
Arg [2] : _accountant (address): 0x0427645BceA78A84A84eFBc26d51f87176581cd9
Arg [3] : _solver (address): 0x1DB629316B3fB6B026f9ebD5c379a72235a4d5E9
-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 0000000000000000000000008ab8aeef444aee718a275a8325795fe90cf162c4
Arg [1] : 00000000000000000000000058a6481706e4260ef50d362401c7f0357b13ab53
Arg [2] : 0000000000000000000000000427645bcea78a84a84efbc26d51f87176581cd9
Arg [3] : 0000000000000000000000001db629316b3fb6b026f9ebd5c379a72235a4d5e9
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
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.