Source Code
Overview
ETH Balance
0 ETH
ETH Value
$0.00Multichain Info
N/A
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
TellerV2
Compiler Version
v0.8.11+commit.d7f03943
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
pragma solidity >=0.8.0 <0.9.0; // SPDX-License-Identifier: MIT // Contracts import "./ProtocolFee.sol"; import "./TellerV2Storage.sol"; import "./TellerV2Context.sol"; import "./pausing/HasProtocolPausingManager.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol"; // Interfaces import "./interfaces/IMarketRegistry.sol"; import "./interfaces/IReputationManager.sol"; import "./interfaces/ITellerV2.sol"; import { Collateral } from "./interfaces/escrow/ICollateralEscrowV1.sol"; import "./interfaces/IEscrowVault.sol"; import { ILoanRepaymentCallbacks } from "./interfaces/ILoanRepaymentCallbacks.sol"; import "./interfaces/ILoanRepaymentListener.sol"; // Libraries import "@openzeppelin/contracts/utils/Address.sol"; import {SafeERC20} from "./openzeppelin/SafeERC20.sol"; import "./libraries/NumbersLib.sol"; import "./libraries/ExcessivelySafeCall.sol"; import { V2Calculations, PaymentCycleType } from "./libraries/V2Calculations.sol"; /* Errors */ /** * @notice This error is reverted when the action isn't allowed * @param bidId The id of the bid. * @param action The action string (i.e: 'repayLoan', 'cancelBid', 'etc) * @param message The message string to return to the user explaining why the tx was reverted */ error ActionNotAllowed(uint256 bidId, string action, string message); /** * @notice This error is reverted when repayment amount is less than the required minimum * @param bidId The id of the bid the borrower is attempting to repay. * @param payment The payment made by the borrower * @param minimumOwed The minimum owed value */ error PaymentNotMinimum(uint256 bidId, uint256 payment, uint256 minimumOwed); contract TellerV2 is ITellerV2, ILoanRepaymentCallbacks, OwnableUpgradeable, ProtocolFee, HasProtocolPausingManager, TellerV2Storage, TellerV2Context { using Address for address; using SafeERC20 for IERC20; using NumbersLib for uint256; using EnumerableSet for EnumerableSet.AddressSet; using EnumerableSet for EnumerableSet.UintSet; //the first 20 bytes of keccak256("lender manager") address constant USING_LENDER_MANAGER = 0x84D409EeD89F6558fE3646397146232665788bF8; /** Events */ /** * @notice This event is emitted when a new bid is submitted. * @param bidId The id of the bid submitted. * @param borrower The address of the bid borrower. * @param metadataURI URI for additional bid information as part of loan bid. */ event SubmittedBid( uint256 indexed bidId, address indexed borrower, address receiver, bytes32 indexed metadataURI ); /** * @notice This event is emitted when a bid has been accepted by a lender. * @param bidId The id of the bid accepted. * @param lender The address of the accepted bid lender. */ event AcceptedBid(uint256 indexed bidId, address indexed lender); /** * @notice This event is emitted when a previously submitted bid has been cancelled. * @param bidId The id of the cancelled bid. */ event CancelledBid(uint256 indexed bidId); /** * @notice This event is emitted when market owner has cancelled a pending bid in their market. * @param bidId The id of the bid funded. * * Note: The `CancelledBid` event will also be emitted. */ event MarketOwnerCancelledBid(uint256 indexed bidId); /** * @notice This event is emitted when a payment is made towards an active loan. * @param bidId The id of the bid/loan to which the payment was made. */ event LoanRepayment(uint256 indexed bidId); /** * @notice This event is emitted when a loan has been fully repaid. * @param bidId The id of the bid/loan which was repaid. */ event LoanRepaid(uint256 indexed bidId); /** * @notice This event is emitted when a loan has been closed by a lender to claim collateral. * @param bidId The id of the bid accepted. */ event LoanClosed(uint256 indexed bidId); /** * @notice This event is emitted when a loan has been fully repaid. * @param bidId The id of the bid/loan which was repaid. */ event LoanLiquidated(uint256 indexed bidId, address indexed liquidator); /** * @notice This event is emitted when a fee has been paid related to a bid. * @param bidId The id of the bid. * @param feeType The name of the fee being paid. * @param amount The amount of the fee being paid. */ event FeePaid( uint256 indexed bidId, string indexed feeType, uint256 indexed amount ); /** Modifiers */ /** * @notice This modifier is used to check if the state of a bid is pending, before running an action. * @param _bidId The id of the bid to check the state for. * @param _action The desired action to run on the bid. */ modifier pendingBid(uint256 _bidId, string memory _action) { if (bids[_bidId].state != BidState.PENDING) { revert ActionNotAllowed(_bidId, _action, "Bid not pending"); } _; } /** * @notice This modifier is used to check if the state of a loan has been accepted, before running an action. * @param _bidId The id of the bid to check the state for. * @param _action The desired action to run on the bid. */ modifier acceptedLoan(uint256 _bidId, string memory _action) { if (bids[_bidId].state != BidState.ACCEPTED) { revert ActionNotAllowed(_bidId, _action, "Loan not accepted"); } _; } /** Constant Variables **/ uint8 public constant CURRENT_CODE_VERSION = 10; uint32 public constant LIQUIDATION_DELAY = 86400; //ONE DAY IN SECONDS /** Constructor **/ constructor(address trustedForwarder) TellerV2Context(trustedForwarder) {} /** External Functions **/ /** * @notice Initializes the proxy. * @param _protocolFee The fee collected by the protocol for loan processing. * @param _marketRegistry The address of the market registry contract for the protocol. * @param _reputationManager The address of the reputation manager contract. * @param _lenderCommitmentForwarder The address of the lender commitment forwarder contract. * @param _collateralManager The address of the collateral manager contracts. * @param _lenderManager The address of the lender manager contract for loans on the protocol. * @param _protocolPausingManager The address of the pausing manager contract for the protocol. */ function initialize( uint16 _protocolFee, address _marketRegistry, address _reputationManager, address _lenderCommitmentForwarder, address _collateralManager, address _lenderManager, address _escrowVault, address _protocolPausingManager ) external initializer { __ProtocolFee_init(_protocolFee); //__Pausable_init(); require( _lenderCommitmentForwarder.isContract(), "LCF_ic" ); lenderCommitmentForwarder = _lenderCommitmentForwarder; require( _marketRegistry.isContract(), "MR_ic" ); marketRegistry = IMarketRegistry(_marketRegistry); require( _reputationManager.isContract(), "RM_ic" ); reputationManager = IReputationManager(_reputationManager); require( _collateralManager.isContract(), "CM_ic" ); collateralManager = ICollateralManager(_collateralManager); require( _lenderManager.isContract(), "LM_ic" ); lenderManager = ILenderManager(_lenderManager); require(_escrowVault.isContract(), "EV_ic"); escrowVault = IEscrowVault(_escrowVault); _setProtocolPausingManager(_protocolPausingManager); } /* function setEscrowVault(address _escrowVault) external reinitializer(9) { _setEscrowVault(_escrowVault); } */ function setProtocolPausingManager( address _protocolPausingManager ) external reinitializer(10) { _setProtocolPausingManager(_protocolPausingManager); } /** * @notice Function for a borrower to create a bid for a loan without Collateral. * @param _lendingToken The lending token asset requested to be borrowed. * @param _marketplaceId The unique id of the marketplace for the bid. * @param _principal The principal amount of the loan bid. * @param _duration The recurrent length of time before which a payment is due. * @param _APR The proposed interest rate for the loan bid. * @param _metadataURI The URI for additional borrower loan information as part of loan bid. * @param _receiver The address where the loan amount will be sent to. */ function submitBid( address _lendingToken, uint256 _marketplaceId, uint256 _principal, uint32 _duration, uint16 _APR, string calldata _metadataURI, address _receiver ) public override whenProtocolNotPaused returns (uint256 bidId_) { bidId_ = _submitBid( _lendingToken, _marketplaceId, _principal, _duration, _APR, _metadataURI, _receiver ); } /** * @notice Function for a borrower to create a bid for a loan with Collateral. * @param _lendingToken The lending token asset requested to be borrowed. * @param _marketplaceId The unique id of the marketplace for the bid. * @param _principal The principal amount of the loan bid. * @param _duration The recurrent length of time before which a payment is due. * @param _APR The proposed interest rate for the loan bid. * @param _metadataURI The URI for additional borrower loan information as part of loan bid. * @param _receiver The address where the loan amount will be sent to. * @param _collateralInfo Additional information about the collateral asset. */ function submitBid( address _lendingToken, uint256 _marketplaceId, uint256 _principal, uint32 _duration, uint16 _APR, string calldata _metadataURI, address _receiver, Collateral[] calldata _collateralInfo ) public override whenProtocolNotPaused returns (uint256 bidId_) { bidId_ = _submitBid( _lendingToken, _marketplaceId, _principal, _duration, _APR, _metadataURI, _receiver ); bool validation = collateralManager.commitCollateral( bidId_, _collateralInfo ); require( validation == true, "C bal NV" ); } function _submitBid( address _lendingToken, uint256 _marketplaceId, uint256 _principal, uint32 _duration, uint16 _APR, string calldata _metadataURI, address _receiver ) internal virtual returns (uint256 bidId_) { address sender = _msgSenderForMarket(_marketplaceId); (bool isVerified, ) = marketRegistry.isVerifiedBorrower( _marketplaceId, sender ); require(isVerified, "Borrower NV"); require( marketRegistry.isMarketOpen(_marketplaceId), "Mkt C" ); // Set response bid ID. bidId_ = bidId; // Create and store our bid into the mapping Bid storage bid = bids[bidId]; bid.borrower = sender; bid.receiver = _receiver != address(0) ? _receiver : bid.borrower; bid.marketplaceId = _marketplaceId; bid.loanDetails.lendingToken = IERC20(_lendingToken); bid.loanDetails.principal = _principal; bid.loanDetails.loanDuration = _duration; bid.loanDetails.timestamp = uint32(block.timestamp); // Set payment cycle type based on market setting (custom or monthly) (bid.terms.paymentCycle, bidPaymentCycleType[bidId]) = marketRegistry .getPaymentCycle(_marketplaceId); bid.terms.APR = _APR; bidDefaultDuration[bidId] = marketRegistry.getPaymentDefaultDuration( _marketplaceId ); bidExpirationTime[bidId] = marketRegistry.getBidExpirationTime( _marketplaceId ); bid.paymentType = marketRegistry.getPaymentType(_marketplaceId); bid.terms.paymentCycleAmount = V2Calculations .calculatePaymentCycleAmount( bid.paymentType, bidPaymentCycleType[bidId], _principal, _duration, bid.terms.paymentCycle, _APR ); uris[bidId] = _metadataURI; bid.state = BidState.PENDING; emit SubmittedBid( bidId, bid.borrower, bid.receiver, keccak256(abi.encodePacked(_metadataURI)) ); // Store bid inside borrower bids mapping borrowerBids[bid.borrower].push(bidId); // Increment bid id counter bidId++; } /** * @notice Function for a borrower to cancel their pending bid. * @param _bidId The id of the bid to cancel. */ function cancelBid(uint256 _bidId) external { if ( _msgSenderForMarket(bids[_bidId].marketplaceId) != bids[_bidId].borrower ) { revert ActionNotAllowed({ bidId: _bidId, action: "CB", message: "Not bid owner" //this is a TON of storage space }); } _cancelBid(_bidId); } /** * @notice Function for a market owner to cancel a bid in the market. * @param _bidId The id of the bid to cancel. */ function marketOwnerCancelBid(uint256 _bidId) external { if ( _msgSender() != marketRegistry.getMarketOwner(bids[_bidId].marketplaceId) ) { revert ActionNotAllowed({ bidId: _bidId, action: "MOCB", message: "Not market owner" //this is a TON of storage space }); } _cancelBid(_bidId); emit MarketOwnerCancelledBid(_bidId); } /** * @notice Function for users to cancel a bid. * @param _bidId The id of the bid to be cancelled. */ function _cancelBid(uint256 _bidId) internal virtual pendingBid(_bidId, "cb") { // Set the bid state to CANCELLED bids[_bidId].state = BidState.CANCELLED; // Emit CancelledBid event emit CancelledBid(_bidId); } /** * @notice Function for a lender to accept a proposed loan bid. * @param _bidId The id of the loan bid to accept. */ function lenderAcceptBid(uint256 _bidId) external override pendingBid(_bidId, "lab") whenProtocolNotPaused returns ( uint256 amountToProtocol, uint256 amountToMarketplace, uint256 amountToBorrower ) { // Retrieve bid Bid storage bid = bids[_bidId]; address sender = _msgSenderForMarket(bid.marketplaceId); (bool isVerified, ) = marketRegistry.isVerifiedLender( bid.marketplaceId, sender ); require(isVerified, "NV"); require( !marketRegistry.isMarketClosed(bid.marketplaceId), "Market is closed" ); require(!isLoanExpired(_bidId), "BE"); // Set timestamp bid.loanDetails.acceptedTimestamp = uint32(block.timestamp); bid.loanDetails.lastRepaidTimestamp = uint32(block.timestamp); // Mark borrower's request as accepted bid.state = BidState.ACCEPTED; // Declare the bid acceptor as the lender of the bid bid.lender = sender; // Tell the collateral manager to deploy the escrow and pull funds from the borrower if applicable collateralManager.deployAndDeposit(_bidId); // Transfer funds to borrower from the lender amountToProtocol = bid.loanDetails.principal.percent(protocolFee()); amountToMarketplace = bid.loanDetails.principal.percent( marketRegistry.getMarketplaceFee(bid.marketplaceId) ); amountToBorrower = bid.loanDetails.principal - amountToProtocol - amountToMarketplace; //transfer fee to protocol if (amountToProtocol > 0) { bid.loanDetails.lendingToken.safeTransferFrom( sender, _getProtocolFeeRecipient(), amountToProtocol ); } //transfer fee to marketplace if (amountToMarketplace > 0) { bid.loanDetails.lendingToken.safeTransferFrom( sender, marketRegistry.getMarketFeeRecipient(bid.marketplaceId), amountToMarketplace ); } //local stack scope { uint256 balanceBefore = bid.loanDetails.lendingToken.balanceOf( address(bid.receiver) ); //transfer funds to borrower if (amountToBorrower > 0) { bid.loanDetails.lendingToken.safeTransferFrom( sender, bid.receiver, amountToBorrower ); } uint256 balanceAfter = bid.loanDetails.lendingToken.balanceOf( address(bid.receiver) ); //used to revert for fee-on-transfer tokens as principal uint256 paymentAmountReceived = balanceAfter - balanceBefore; require(amountToBorrower == paymentAmountReceived, "UT"); } // Record volume filled by lenders lenderVolumeFilled[address(bid.loanDetails.lendingToken)][sender] += bid .loanDetails .principal; totalVolumeFilled[address(bid.loanDetails.lendingToken)] += bid .loanDetails .principal; // Add borrower's active bid _borrowerBidsActive[bid.borrower].add(_bidId); // Emit AcceptedBid emit AcceptedBid(_bidId, sender); emit FeePaid(_bidId, "protocol", amountToProtocol); emit FeePaid(_bidId, "marketplace", amountToMarketplace); } function claimLoanNFT(uint256 _bidId) external acceptedLoan(_bidId, "cln") whenProtocolNotPaused { // Retrieve bid Bid storage bid = bids[_bidId]; address sender = _msgSenderForMarket(bid.marketplaceId); require(sender == bid.lender, "NV Lender"); // set lender address to the lender manager so we know to check the owner of the NFT for the true lender bid.lender = address(USING_LENDER_MANAGER); // mint an NFT with the lender manager lenderManager.registerLoan(_bidId, sender); } /** * @notice Function for users to make the minimum amount due for an active loan. * @param _bidId The id of the loan to make the payment towards. */ function repayLoanMinimum(uint256 _bidId) external acceptedLoan(_bidId, "rl") { ( uint256 owedPrincipal, uint256 duePrincipal, uint256 interest ) = V2Calculations.calculateAmountOwed( bids[_bidId], block.timestamp, _getBidPaymentCycleType(_bidId), _getBidPaymentCycleDuration(_bidId) ); _repayLoan( _bidId, Payment({ principal: duePrincipal, interest: interest }), owedPrincipal + interest, true ); } /** * @notice Function for users to repay an active loan in full. * @param _bidId The id of the loan to make the payment towards. */ function repayLoanFull(uint256 _bidId) external acceptedLoan(_bidId, "rl") { _repayLoanFull(_bidId, true); } // function that the borrower (ideally) sends to repay the loan /** * @notice Function for users to make a payment towards an active loan. * @param _bidId The id of the loan to make the payment towards. * @param _amount The amount of the payment. */ function repayLoan(uint256 _bidId, uint256 _amount) external acceptedLoan(_bidId, "rl") { _repayLoanAtleastMinimum(_bidId, _amount, true); } /** * @notice Function for users to repay an active loan in full. * @param _bidId The id of the loan to make the payment towards. */ function repayLoanFullWithoutCollateralWithdraw(uint256 _bidId) external acceptedLoan(_bidId, "rl") { _repayLoanFull(_bidId, false); } function repayLoanWithoutCollateralWithdraw(uint256 _bidId, uint256 _amount) external acceptedLoan(_bidId, "rl") { _repayLoanAtleastMinimum(_bidId, _amount, false); } function _repayLoanFull(uint256 _bidId, bool withdrawCollateral) internal { (uint256 owedPrincipal, , uint256 interest) = V2Calculations .calculateAmountOwed( bids[_bidId], block.timestamp, _getBidPaymentCycleType(_bidId), _getBidPaymentCycleDuration(_bidId) ); _repayLoan( _bidId, Payment({ principal: owedPrincipal, interest: interest }), owedPrincipal + interest, withdrawCollateral ); } function _repayLoanAtleastMinimum( uint256 _bidId, uint256 _amount, bool withdrawCollateral ) internal { ( uint256 owedPrincipal, uint256 duePrincipal, uint256 interest ) = V2Calculations.calculateAmountOwed( bids[_bidId], block.timestamp, _getBidPaymentCycleType(_bidId), _getBidPaymentCycleDuration(_bidId) ); uint256 minimumOwed = duePrincipal + interest; // If amount is less than minimumOwed, we revert if (_amount < minimumOwed) { revert PaymentNotMinimum(_bidId, _amount, minimumOwed); } _repayLoan( _bidId, Payment({ principal: _amount - interest, interest: interest }), owedPrincipal + interest, withdrawCollateral ); } function lenderCloseLoan(uint256 _bidId) external whenProtocolNotPaused whenLiquidationsNotPaused acceptedLoan(_bidId, "lcc") { Bid storage bid = bids[_bidId]; address _collateralRecipient = getLoanLender(_bidId); _lenderCloseLoanWithRecipient(_bidId, _collateralRecipient); } /** * @notice Function for lender to claim collateral for a defaulted loan. The only purpose of a CLOSED loan is to make collateral claimable by lender. * @param _bidId The id of the loan to set to CLOSED status. */ function lenderCloseLoanWithRecipient( uint256 _bidId, address _collateralRecipient ) external whenProtocolNotPaused whenLiquidationsNotPaused { _lenderCloseLoanWithRecipient(_bidId, _collateralRecipient); } function _lenderCloseLoanWithRecipient( uint256 _bidId, address _collateralRecipient ) internal acceptedLoan(_bidId, "lcc") { require(isLoanDefaulted(_bidId), "ND"); Bid storage bid = bids[_bidId]; bid.state = BidState.CLOSED; address sender = _msgSenderForMarket(bid.marketplaceId); require(sender == getLoanLender(_bidId), "NLL"); collateralManager.lenderClaimCollateralWithRecipient(_bidId, _collateralRecipient); emit LoanClosed(_bidId); } /** * @notice Function for users to liquidate a defaulted loan. * @param _bidId The id of the loan to make the payment towards. */ function liquidateLoanFull(uint256 _bidId) external whenProtocolNotPaused whenLiquidationsNotPaused acceptedLoan(_bidId, "ll") { Bid storage bid = bids[_bidId]; // If loan is backed by collateral, withdraw and send to the liquidator address recipient = _msgSenderForMarket(bid.marketplaceId); _liquidateLoanFull(_bidId, recipient); } function liquidateLoanFullWithRecipient(uint256 _bidId, address _recipient) external whenProtocolNotPaused whenLiquidationsNotPaused acceptedLoan(_bidId, "ll") { _liquidateLoanFull(_bidId, _recipient); } /** * @notice Function for users to liquidate a defaulted loan. * @param _bidId The id of the loan to make the payment towards. */ function _liquidateLoanFull(uint256 _bidId, address _recipient) internal acceptedLoan(_bidId, "ll") { require(isLoanLiquidateable(_bidId), "NL"); Bid storage bid = bids[_bidId]; // change state here to prevent re-entrancy bid.state = BidState.LIQUIDATED; (uint256 owedPrincipal, , uint256 interest) = V2Calculations .calculateAmountOwed( bid, block.timestamp, _getBidPaymentCycleType(_bidId), _getBidPaymentCycleDuration(_bidId) ); //this sets the state to 'repaid' _repayLoan( _bidId, Payment({ principal: owedPrincipal, interest: interest }), owedPrincipal + interest, false ); collateralManager.liquidateCollateral(_bidId, _recipient); address liquidator = _msgSenderForMarket(bid.marketplaceId); emit LoanLiquidated(_bidId, liquidator); } /** * @notice Internal function to make a loan payment. * @dev Updates the bid's `status` to `PAID` only if it is not already marked as `LIQUIDATED` * @param _bidId The id of the loan to make the payment towards. * @param _payment The Payment struct with payments amounts towards principal and interest respectively. * @param _owedAmount The total amount owed on the loan. */ function _repayLoan( uint256 _bidId, Payment memory _payment, uint256 _owedAmount, bool _shouldWithdrawCollateral ) internal virtual { Bid storage bid = bids[_bidId]; uint256 paymentAmount = _payment.principal + _payment.interest; RepMark mark = reputationManager.updateAccountReputation( bid.borrower, _bidId ); // Check if we are sending a payment or amount remaining if (paymentAmount >= _owedAmount) { paymentAmount = _owedAmount; if (bid.state != BidState.LIQUIDATED) { bid.state = BidState.PAID; } // Remove borrower's active bid _borrowerBidsActive[bid.borrower].remove(_bidId); // If loan is is being liquidated and backed by collateral, withdraw and send to borrower if (_shouldWithdrawCollateral) { // _getCollateralManagerForBid(_bidId).withdraw(_bidId); collateralManager.withdraw(_bidId); } emit LoanRepaid(_bidId); } else { emit LoanRepayment(_bidId); } // update our mappings bid.loanDetails.totalRepaid.principal += _payment.principal; bid.loanDetails.totalRepaid.interest += _payment.interest; bid.loanDetails.lastRepaidTimestamp = uint32(block.timestamp); //perform this after state change to mitigate re-entrancy _sendOrEscrowFunds(_bidId, _payment); //send or escrow the funds // If the loan is paid in full and has a mark, we should update the current reputation if (mark != RepMark.Good) { reputationManager.updateAccountReputation(bid.borrower, _bidId); } } /* If for some reason the lender cannot receive funds, should put those funds into the escrow so the loan can always be repaid and the borrower can get collateral out */ function _sendOrEscrowFunds(uint256 _bidId, Payment memory _payment) internal virtual { Bid storage bid = bids[_bidId]; address lender = getLoanLender(_bidId); uint256 _paymentAmount = _payment.principal + _payment.interest; //USER STORY: Should function properly with USDT and USDC and WETH for sure //USER STORY : if the lender cannot receive funds for some reason (denylisted) //then we will try to send the funds to the EscrowContract bc we want the borrower to be able to get back their collateral ! // i.e. lender not being able to recieve funds should STILL allow repayment to succeed ! bool transferSuccess = safeTransferFromERC20Custom( address(bid.loanDetails.lendingToken), _msgSenderForMarket(bid.marketplaceId) , //from lender, //to _paymentAmount // amount ); if (!transferSuccess) { //could not send funds due to an issue with lender (denylisted?) so we are going to try and send the funds to the // escrow wallet FOR the lender to be able to retrieve at a later time when they are no longer denylisted by the token address sender = _msgSenderForMarket(bid.marketplaceId); // fee on transfer tokens are not supported in the lenderAcceptBid step //if unable, pay to escrow bid.loanDetails.lendingToken.safeTransferFrom( sender, address(this), _paymentAmount ); bid.loanDetails.lendingToken.forceApprove( address(escrowVault), _paymentAmount ); IEscrowVault(escrowVault).deposit( lender, address(bid.loanDetails.lendingToken), _paymentAmount ); } address loanRepaymentListener = repaymentListenerForBid[_bidId]; if (loanRepaymentListener != address(0)) { //make sure the external call will not fail due to out-of-gas require(gasleft() >= 80000, "NR gas"); //fixes the 63/64 remaining issue bool repayCallbackSucccess = safeRepayLoanCallback( loanRepaymentListener, _bidId, _msgSenderForMarket(bid.marketplaceId), _payment.principal, _payment.interest ); } } function safeRepayLoanCallback( address _loanRepaymentListener, uint256 _bidId, address _sender, uint256 _principal, uint256 _interest ) internal virtual returns (bool) { //The EVM will only forward 63/64 of the remaining gas to the external call to _loanRepaymentListener. ( bool callSuccess, bytes memory callReturnData ) = ExcessivelySafeCall.excessivelySafeCall( address(_loanRepaymentListener), 80000, //max gas 0, //value (eth) to send in call 1000, //max return data size abi.encodeWithSelector( ILoanRepaymentListener .repayLoanCallback .selector, _bidId, _sender, _principal, _interest ) ); return callSuccess ; } /* A try/catch pattern for safeTransferERC20 that helps support standard ERC20 tokens and non-standard ones like USDT @notice If the token address is an EOA, callSuccess will always be true so token address should always be a contract. */ function safeTransferFromERC20Custom( address _token, address _from, address _to, uint256 _amount ) internal virtual returns (bool success) { //https://github.com/nomad-xyz/ExcessivelySafeCall //this works similarly to a try catch -- an inner revert doesnt revert us but will make callSuccess be false. ( bool callSuccess, bytes memory callReturnData ) = ExcessivelySafeCall.excessivelySafeCall( address(_token), 100000, //max gas 0, //value (eth) to send in call 1000, //max return data size abi.encodeWithSelector( IERC20 .transferFrom .selector, _from, _to, _amount ) ); //If the token returns data, make sure it returns true. This helps us with USDT which may revert but never returns a bool. bool dataIsSuccess = true; if (callReturnData.length >= 32) { assembly { // Load the first 32 bytes of the return data (assuming it's a bool) let result := mload(add(callReturnData, 0x20)) // Check if the result equals `true` (1) dataIsSuccess := eq(result, 1) } } // ensures that both callSuccess (the low-level call didn't fail) and dataIsSuccess (the function returned true if it returned something). return callSuccess && dataIsSuccess; } /** * @notice Calculates the total amount owed for a loan bid at a specific timestamp. * @param _bidId The id of the loan bid to calculate the owed amount for. * @param _timestamp The timestamp at which to calculate the loan owed amount at. */ function calculateAmountOwed(uint256 _bidId, uint256 _timestamp) public view returns (Payment memory owed) { Bid storage bid = bids[_bidId]; if ( bid.state != BidState.ACCEPTED || bid.loanDetails.acceptedTimestamp >= _timestamp ) return owed; (uint256 owedPrincipal, , uint256 interest) = V2Calculations .calculateAmountOwed( bid, _timestamp, _getBidPaymentCycleType(_bidId), _getBidPaymentCycleDuration(_bidId) ); owed.principal = owedPrincipal; owed.interest = interest; } /** * @notice Calculates the minimum payment amount due for a loan at a specific timestamp. * @param _bidId The id of the loan bid to get the payment amount for. * @param _timestamp The timestamp at which to get the due payment at. */ function calculateAmountDue(uint256 _bidId, uint256 _timestamp) public view returns (Payment memory due) { Bid storage bid = bids[_bidId]; if ( bids[_bidId].state != BidState.ACCEPTED || bid.loanDetails.acceptedTimestamp >= _timestamp ) return due; (, uint256 duePrincipal, uint256 interest) = V2Calculations .calculateAmountOwed( bid, _timestamp, _getBidPaymentCycleType(_bidId), _getBidPaymentCycleDuration(_bidId) ); due.principal = duePrincipal; due.interest = interest; } /** * @notice Returns the next due date for a loan payment. * @param _bidId The id of the loan bid. */ function calculateNextDueDate(uint256 _bidId) public view returns (uint32 dueDate_) { Bid storage bid = bids[_bidId]; if (bids[_bidId].state != BidState.ACCEPTED) return dueDate_; return V2Calculations.calculateNextDueDate( bid.loanDetails.acceptedTimestamp, bid.terms.paymentCycle, bid.loanDetails.loanDuration, lastRepaidTimestamp(_bidId), bidPaymentCycleType[_bidId] ); } /** * @notice Checks to see if a borrower is delinquent. * @param _bidId The id of the loan bid to check for. */ function isPaymentLate(uint256 _bidId) public view override returns (bool) { if (bids[_bidId].state != BidState.ACCEPTED) return false; return uint32(block.timestamp) > calculateNextDueDate(_bidId); } /** * @notice Checks to see if a borrower is delinquent. * @param _bidId The id of the loan bid to check for. * @return bool True if the loan is defaulted. */ function isLoanDefaulted(uint256 _bidId) public view override returns (bool) { return _isLoanDefaulted(_bidId, 0); } /** * @notice Checks to see if a loan was delinquent for longer than liquidation delay. * @param _bidId The id of the loan bid to check for. * @return bool True if the loan is liquidateable. */ function isLoanLiquidateable(uint256 _bidId) public view override returns (bool) { return _isLoanDefaulted(_bidId, LIQUIDATION_DELAY); } /** * @notice Checks to see if a borrower is delinquent. * @param _bidId The id of the loan bid to check for. * @param _additionalDelay Amount of additional seconds after a loan defaulted to allow a liquidation. * @return bool True if the loan is liquidateable. */ function _isLoanDefaulted(uint256 _bidId, uint32 _additionalDelay) internal view returns (bool) { Bid storage bid = bids[_bidId]; // Make sure loan cannot be liquidated if it is not active if (bid.state != BidState.ACCEPTED) return false; uint32 defaultDuration = bidDefaultDuration[_bidId]; uint32 dueDate = calculateNextDueDate(_bidId); return uint32(block.timestamp) > dueDate + defaultDuration + _additionalDelay; } function getEscrowVault() external view returns(address){ return address(escrowVault); } function getBidState(uint256 _bidId) external view override returns (BidState) { return bids[_bidId].state; } function getBorrowerActiveLoanIds(address _borrower) external view override returns (uint256[] memory) { return _borrowerBidsActive[_borrower].values(); } function getBorrowerLoanIds(address _borrower) external view returns (uint256[] memory) { return borrowerBids[_borrower]; } /** * @notice Checks to see if a pending loan has expired so it is no longer able to be accepted. * @param _bidId The id of the loan bid to check for. */ function isLoanExpired(uint256 _bidId) public view returns (bool) { Bid storage bid = bids[_bidId]; if (bid.state != BidState.PENDING) return false; if (bidExpirationTime[_bidId] == 0) return false; return (uint32(block.timestamp) > bid.loanDetails.timestamp + bidExpirationTime[_bidId]); } /** * @notice Returns the last repaid timestamp for a loan. * @param _bidId The id of the loan bid to get the timestamp for. */ function lastRepaidTimestamp(uint256 _bidId) public view returns (uint32) { return V2Calculations.lastRepaidTimestamp(bids[_bidId]); } /** * @notice Returns the borrower address for a given bid. * @param _bidId The id of the bid/loan to get the borrower for. * @return borrower_ The address of the borrower associated with the bid. */ function getLoanBorrower(uint256 _bidId) public view returns (address borrower_) { borrower_ = bids[_bidId].borrower; } /** * @notice Returns the lender address for a given bid. If the stored lender address is the `LenderManager` NFT address, return the `ownerOf` for the bid ID. * @param _bidId The id of the bid/loan to get the lender for. * @return lender_ The address of the lender associated with the bid. */ function getLoanLender(uint256 _bidId) public view returns (address lender_) { lender_ = bids[_bidId].lender; if (lender_ == address(USING_LENDER_MANAGER)) { return lenderManager.ownerOf(_bidId); } //this is left in for backwards compatibility only if (lender_ == address(lenderManager)) { return lenderManager.ownerOf(_bidId); } } function getLoanLendingToken(uint256 _bidId) external view returns (address token_) { token_ = address(bids[_bidId].loanDetails.lendingToken); } function getLoanMarketId(uint256 _bidId) external view returns (uint256 _marketId) { _marketId = bids[_bidId].marketplaceId; } function getLoanSummary(uint256 _bidId) external view returns ( address borrower, address lender, uint256 marketId, address principalTokenAddress, uint256 principalAmount, uint32 acceptedTimestamp, uint32 lastRepaidTimestamp, BidState bidState ) { Bid storage bid = bids[_bidId]; borrower = bid.borrower; lender = getLoanLender(_bidId); marketId = bid.marketplaceId; principalTokenAddress = address(bid.loanDetails.lendingToken); principalAmount = bid.loanDetails.principal; acceptedTimestamp = bid.loanDetails.acceptedTimestamp; lastRepaidTimestamp = V2Calculations.lastRepaidTimestamp(bids[_bidId]); bidState = bid.state; } // Additions for lender groups function getLoanDefaultTimestamp(uint256 _bidId) public view returns (uint256) { Bid storage bid = bids[_bidId]; uint32 defaultDuration = _getBidDefaultDuration(_bidId); uint32 dueDate = calculateNextDueDate(_bidId); return dueDate + defaultDuration; } function setRepaymentListenerForBid(uint256 _bidId, address _listener) external { uint256 codeSize; assembly { codeSize := extcodesize(_listener) } require(codeSize > 0, "Not a contract"); address sender = _msgSenderForMarket(bids[_bidId].marketplaceId); require( sender == getLoanLender(_bidId), "Not lender" ); repaymentListenerForBid[_bidId] = _listener; } function getRepaymentListenerForBid(uint256 _bidId) external view returns (address) { return repaymentListenerForBid[_bidId]; } // ---------- function _getBidPaymentCycleType(uint256 _bidId) internal view returns (PaymentCycleType) { return bidPaymentCycleType[_bidId]; } function _getBidPaymentCycleDuration(uint256 _bidId) internal view returns (uint32) { Bid storage bid = bids[_bidId]; return bid.terms.paymentCycle; } function _getBidDefaultDuration(uint256 _bidId) internal view returns (uint32) { return bidDefaultDuration[_bidId]; } function _getProtocolFeeRecipient() internal view returns (address) { if (protocolFeeRecipient == address(0x0)){ return owner(); }else { return protocolFeeRecipient; } } function getProtocolFeeRecipient() external view returns (address) { return _getProtocolFeeRecipient(); } function setProtocolFeeRecipient(address _recipient) external onlyOwner { protocolFeeRecipient = _recipient; } // ----- /** OpenZeppelin Override Functions **/ function _msgSender() internal view virtual override(ERC2771ContextUpgradeable, ContextUpgradeable) returns (address sender) { sender = ERC2771ContextUpgradeable._msgSender(); } function _msgData() internal view virtual override(ERC2771ContextUpgradeable, ContextUpgradeable) returns (bytes calldata) { return ERC2771ContextUpgradeable._msgData(); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ function __Ownable_init() internal onlyInitializing { __Ownable_init_unchained(); } function __Ownable_init_unchained() internal onlyInitializing { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.1) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; import "../../utils/AddressUpgradeable.sol"; /** * @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] * ``` * 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 Indicates that the contract has been initialized. * @custom:oz-retyped-from bool */ uint8 private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint8 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 functions marked with `initializer` can be nested in the context of a * constructor. * * Emits an {Initialized} event. */ modifier initializer() { bool isTopLevelCall = !_initializing; require( (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1), "Initializable: contract is already initialized" ); _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 255 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint8 version) { require(!_initializing && _initialized < version, "Initializable: contract is already initialized"); _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() { require(_initializing, "Initializable: contract is not initializing"); _; } /** * @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 { require(!_initializing, "Initializable: contract is initializing"); if (_initialized < type(uint8).max) { _initialized = type(uint8).max; emit Initialized(type(uint8).max); } } /** * @dev Returns the highest version that has been initialized. See {reinitializer}. */ function _getInitializedVersion() internal view returns (uint8) { return _initialized; } /** * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}. */ function _isInitializing() internal view returns (bool) { return _initializing; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165Upgradeable.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721Upgradeable is IERC165Upgradeable { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721 * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must * understand this adds an external call which potentially creates a reentrancy vulnerability. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../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; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @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 IERC165Upgradeable { /** * @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 v4.8.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library MathUpgradeable { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv( uint256 x, uint256 y, uint256 denominator, Rounding rounding ) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10**64) { value /= 10**64; result += 64; } if (value >= 10**32) { value /= 10**32; result += 32; } if (value >= 10**16) { value /= 10**16; result += 16; } if (value >= 10**8) { value /= 10**8; result += 8; } if (value >= 10**4) { value /= 10**4; result += 4; } if (value >= 10**2) { value /= 10**2; result += 2; } if (value >= 10**1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/MathUpgradeable.sol"; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = MathUpgradeable.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, MathUpgradeable.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv( uint256 x, uint256 y, uint256 denominator, Rounding rounding ) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10**64) { value /= 10**64; result += 64; } if (value >= 10**32) { value /= 10**32; result += 32; } if (value >= 10**16) { value /= 10**16; result += 16; } if (value >= 10**8) { value /= 10**8; result += 8; } if (value >= 10**4) { value /= 10**4; result += 4; } if (value >= 10**2) { value /= 10**2; result += 2; } if (value >= 10**1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol) // This file was procedurally generated from scripts/generate/templates/SafeCast.js. pragma solidity ^0.8.0; /** * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow * checks. * * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such an operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. * * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing * all math on `uint256` and `int256` and then downcasting. */ library SafeCast { /** * @dev Returns the downcasted uint248 from uint256, reverting on * overflow (when the input is greater than largest uint248). * * Counterpart to Solidity's `uint248` operator. * * Requirements: * * - input must fit into 248 bits * * _Available since v4.7._ */ function toUint248(uint256 value) internal pure returns (uint248) { require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits"); return uint248(value); } /** * @dev Returns the downcasted uint240 from uint256, reverting on * overflow (when the input is greater than largest uint240). * * Counterpart to Solidity's `uint240` operator. * * Requirements: * * - input must fit into 240 bits * * _Available since v4.7._ */ function toUint240(uint256 value) internal pure returns (uint240) { require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits"); return uint240(value); } /** * @dev Returns the downcasted uint232 from uint256, reverting on * overflow (when the input is greater than largest uint232). * * Counterpart to Solidity's `uint232` operator. * * Requirements: * * - input must fit into 232 bits * * _Available since v4.7._ */ function toUint232(uint256 value) internal pure returns (uint232) { require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits"); return uint232(value); } /** * @dev Returns the downcasted uint224 from uint256, reverting on * overflow (when the input is greater than largest uint224). * * Counterpart to Solidity's `uint224` operator. * * Requirements: * * - input must fit into 224 bits * * _Available since v4.2._ */ function toUint224(uint256 value) internal pure returns (uint224) { require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits"); return uint224(value); } /** * @dev Returns the downcasted uint216 from uint256, reverting on * overflow (when the input is greater than largest uint216). * * Counterpart to Solidity's `uint216` operator. * * Requirements: * * - input must fit into 216 bits * * _Available since v4.7._ */ function toUint216(uint256 value) internal pure returns (uint216) { require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits"); return uint216(value); } /** * @dev Returns the downcasted uint208 from uint256, reverting on * overflow (when the input is greater than largest uint208). * * Counterpart to Solidity's `uint208` operator. * * Requirements: * * - input must fit into 208 bits * * _Available since v4.7._ */ function toUint208(uint256 value) internal pure returns (uint208) { require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits"); return uint208(value); } /** * @dev Returns the downcasted uint200 from uint256, reverting on * overflow (when the input is greater than largest uint200). * * Counterpart to Solidity's `uint200` operator. * * Requirements: * * - input must fit into 200 bits * * _Available since v4.7._ */ function toUint200(uint256 value) internal pure returns (uint200) { require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits"); return uint200(value); } /** * @dev Returns the downcasted uint192 from uint256, reverting on * overflow (when the input is greater than largest uint192). * * Counterpart to Solidity's `uint192` operator. * * Requirements: * * - input must fit into 192 bits * * _Available since v4.7._ */ function toUint192(uint256 value) internal pure returns (uint192) { require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits"); return uint192(value); } /** * @dev Returns the downcasted uint184 from uint256, reverting on * overflow (when the input is greater than largest uint184). * * Counterpart to Solidity's `uint184` operator. * * Requirements: * * - input must fit into 184 bits * * _Available since v4.7._ */ function toUint184(uint256 value) internal pure returns (uint184) { require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits"); return uint184(value); } /** * @dev Returns the downcasted uint176 from uint256, reverting on * overflow (when the input is greater than largest uint176). * * Counterpart to Solidity's `uint176` operator. * * Requirements: * * - input must fit into 176 bits * * _Available since v4.7._ */ function toUint176(uint256 value) internal pure returns (uint176) { require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits"); return uint176(value); } /** * @dev Returns the downcasted uint168 from uint256, reverting on * overflow (when the input is greater than largest uint168). * * Counterpart to Solidity's `uint168` operator. * * Requirements: * * - input must fit into 168 bits * * _Available since v4.7._ */ function toUint168(uint256 value) internal pure returns (uint168) { require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits"); return uint168(value); } /** * @dev Returns the downcasted uint160 from uint256, reverting on * overflow (when the input is greater than largest uint160). * * Counterpart to Solidity's `uint160` operator. * * Requirements: * * - input must fit into 160 bits * * _Available since v4.7._ */ function toUint160(uint256 value) internal pure returns (uint160) { require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits"); return uint160(value); } /** * @dev Returns the downcasted uint152 from uint256, reverting on * overflow (when the input is greater than largest uint152). * * Counterpart to Solidity's `uint152` operator. * * Requirements: * * - input must fit into 152 bits * * _Available since v4.7._ */ function toUint152(uint256 value) internal pure returns (uint152) { require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits"); return uint152(value); } /** * @dev Returns the downcasted uint144 from uint256, reverting on * overflow (when the input is greater than largest uint144). * * Counterpart to Solidity's `uint144` operator. * * Requirements: * * - input must fit into 144 bits * * _Available since v4.7._ */ function toUint144(uint256 value) internal pure returns (uint144) { require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits"); return uint144(value); } /** * @dev Returns the downcasted uint136 from uint256, reverting on * overflow (when the input is greater than largest uint136). * * Counterpart to Solidity's `uint136` operator. * * Requirements: * * - input must fit into 136 bits * * _Available since v4.7._ */ function toUint136(uint256 value) internal pure returns (uint136) { require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits"); return uint136(value); } /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v2.5._ */ function toUint128(uint256 value) internal pure returns (uint128) { require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits"); return uint128(value); } /** * @dev Returns the downcasted uint120 from uint256, reverting on * overflow (when the input is greater than largest uint120). * * Counterpart to Solidity's `uint120` operator. * * Requirements: * * - input must fit into 120 bits * * _Available since v4.7._ */ function toUint120(uint256 value) internal pure returns (uint120) { require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits"); return uint120(value); } /** * @dev Returns the downcasted uint112 from uint256, reverting on * overflow (when the input is greater than largest uint112). * * Counterpart to Solidity's `uint112` operator. * * Requirements: * * - input must fit into 112 bits * * _Available since v4.7._ */ function toUint112(uint256 value) internal pure returns (uint112) { require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits"); return uint112(value); } /** * @dev Returns the downcasted uint104 from uint256, reverting on * overflow (when the input is greater than largest uint104). * * Counterpart to Solidity's `uint104` operator. * * Requirements: * * - input must fit into 104 bits * * _Available since v4.7._ */ function toUint104(uint256 value) internal pure returns (uint104) { require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits"); return uint104(value); } /** * @dev Returns the downcasted uint96 from uint256, reverting on * overflow (when the input is greater than largest uint96). * * Counterpart to Solidity's `uint96` operator. * * Requirements: * * - input must fit into 96 bits * * _Available since v4.2._ */ function toUint96(uint256 value) internal pure returns (uint96) { require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits"); return uint96(value); } /** * @dev Returns the downcasted uint88 from uint256, reverting on * overflow (when the input is greater than largest uint88). * * Counterpart to Solidity's `uint88` operator. * * Requirements: * * - input must fit into 88 bits * * _Available since v4.7._ */ function toUint88(uint256 value) internal pure returns (uint88) { require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits"); return uint88(value); } /** * @dev Returns the downcasted uint80 from uint256, reverting on * overflow (when the input is greater than largest uint80). * * Counterpart to Solidity's `uint80` operator. * * Requirements: * * - input must fit into 80 bits * * _Available since v4.7._ */ function toUint80(uint256 value) internal pure returns (uint80) { require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits"); return uint80(value); } /** * @dev Returns the downcasted uint72 from uint256, reverting on * overflow (when the input is greater than largest uint72). * * Counterpart to Solidity's `uint72` operator. * * Requirements: * * - input must fit into 72 bits * * _Available since v4.7._ */ function toUint72(uint256 value) internal pure returns (uint72) { require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits"); return uint72(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v2.5._ */ function toUint64(uint256 value) internal pure returns (uint64) { require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits"); return uint64(value); } /** * @dev Returns the downcasted uint56 from uint256, reverting on * overflow (when the input is greater than largest uint56). * * Counterpart to Solidity's `uint56` operator. * * Requirements: * * - input must fit into 56 bits * * _Available since v4.7._ */ function toUint56(uint256 value) internal pure returns (uint56) { require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits"); return uint56(value); } /** * @dev Returns the downcasted uint48 from uint256, reverting on * overflow (when the input is greater than largest uint48). * * Counterpart to Solidity's `uint48` operator. * * Requirements: * * - input must fit into 48 bits * * _Available since v4.7._ */ function toUint48(uint256 value) internal pure returns (uint48) { require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits"); return uint48(value); } /** * @dev Returns the downcasted uint40 from uint256, reverting on * overflow (when the input is greater than largest uint40). * * Counterpart to Solidity's `uint40` operator. * * Requirements: * * - input must fit into 40 bits * * _Available since v4.7._ */ function toUint40(uint256 value) internal pure returns (uint40) { require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits"); return uint40(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v2.5._ */ function toUint32(uint256 value) internal pure returns (uint32) { require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits"); return uint32(value); } /** * @dev Returns the downcasted uint24 from uint256, reverting on * overflow (when the input is greater than largest uint24). * * Counterpart to Solidity's `uint24` operator. * * Requirements: * * - input must fit into 24 bits * * _Available since v4.7._ */ function toUint24(uint256 value) internal pure returns (uint24) { require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits"); return uint24(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v2.5._ */ function toUint16(uint256 value) internal pure returns (uint16) { require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits"); return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits * * _Available since v2.5._ */ function toUint8(uint256 value) internal pure returns (uint8) { require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits"); return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. * * _Available since v3.0._ */ function toUint256(int256 value) internal pure returns (uint256) { require(value >= 0, "SafeCast: value must be positive"); return uint256(value); } /** * @dev Returns the downcasted int248 from int256, reverting on * overflow (when the input is less than smallest int248 or * greater than largest int248). * * Counterpart to Solidity's `int248` operator. * * Requirements: * * - input must fit into 248 bits * * _Available since v4.7._ */ function toInt248(int256 value) internal pure returns (int248 downcasted) { downcasted = int248(value); require(downcasted == value, "SafeCast: value doesn't fit in 248 bits"); } /** * @dev Returns the downcasted int240 from int256, reverting on * overflow (when the input is less than smallest int240 or * greater than largest int240). * * Counterpart to Solidity's `int240` operator. * * Requirements: * * - input must fit into 240 bits * * _Available since v4.7._ */ function toInt240(int256 value) internal pure returns (int240 downcasted) { downcasted = int240(value); require(downcasted == value, "SafeCast: value doesn't fit in 240 bits"); } /** * @dev Returns the downcasted int232 from int256, reverting on * overflow (when the input is less than smallest int232 or * greater than largest int232). * * Counterpart to Solidity's `int232` operator. * * Requirements: * * - input must fit into 232 bits * * _Available since v4.7._ */ function toInt232(int256 value) internal pure returns (int232 downcasted) { downcasted = int232(value); require(downcasted == value, "SafeCast: value doesn't fit in 232 bits"); } /** * @dev Returns the downcasted int224 from int256, reverting on * overflow (when the input is less than smallest int224 or * greater than largest int224). * * Counterpart to Solidity's `int224` operator. * * Requirements: * * - input must fit into 224 bits * * _Available since v4.7._ */ function toInt224(int256 value) internal pure returns (int224 downcasted) { downcasted = int224(value); require(downcasted == value, "SafeCast: value doesn't fit in 224 bits"); } /** * @dev Returns the downcasted int216 from int256, reverting on * overflow (when the input is less than smallest int216 or * greater than largest int216). * * Counterpart to Solidity's `int216` operator. * * Requirements: * * - input must fit into 216 bits * * _Available since v4.7._ */ function toInt216(int256 value) internal pure returns (int216 downcasted) { downcasted = int216(value); require(downcasted == value, "SafeCast: value doesn't fit in 216 bits"); } /** * @dev Returns the downcasted int208 from int256, reverting on * overflow (when the input is less than smallest int208 or * greater than largest int208). * * Counterpart to Solidity's `int208` operator. * * Requirements: * * - input must fit into 208 bits * * _Available since v4.7._ */ function toInt208(int256 value) internal pure returns (int208 downcasted) { downcasted = int208(value); require(downcasted == value, "SafeCast: value doesn't fit in 208 bits"); } /** * @dev Returns the downcasted int200 from int256, reverting on * overflow (when the input is less than smallest int200 or * greater than largest int200). * * Counterpart to Solidity's `int200` operator. * * Requirements: * * - input must fit into 200 bits * * _Available since v4.7._ */ function toInt200(int256 value) internal pure returns (int200 downcasted) { downcasted = int200(value); require(downcasted == value, "SafeCast: value doesn't fit in 200 bits"); } /** * @dev Returns the downcasted int192 from int256, reverting on * overflow (when the input is less than smallest int192 or * greater than largest int192). * * Counterpart to Solidity's `int192` operator. * * Requirements: * * - input must fit into 192 bits * * _Available since v4.7._ */ function toInt192(int256 value) internal pure returns (int192 downcasted) { downcasted = int192(value); require(downcasted == value, "SafeCast: value doesn't fit in 192 bits"); } /** * @dev Returns the downcasted int184 from int256, reverting on * overflow (when the input is less than smallest int184 or * greater than largest int184). * * Counterpart to Solidity's `int184` operator. * * Requirements: * * - input must fit into 184 bits * * _Available since v4.7._ */ function toInt184(int256 value) internal pure returns (int184 downcasted) { downcasted = int184(value); require(downcasted == value, "SafeCast: value doesn't fit in 184 bits"); } /** * @dev Returns the downcasted int176 from int256, reverting on * overflow (when the input is less than smallest int176 or * greater than largest int176). * * Counterpart to Solidity's `int176` operator. * * Requirements: * * - input must fit into 176 bits * * _Available since v4.7._ */ function toInt176(int256 value) internal pure returns (int176 downcasted) { downcasted = int176(value); require(downcasted == value, "SafeCast: value doesn't fit in 176 bits"); } /** * @dev Returns the downcasted int168 from int256, reverting on * overflow (when the input is less than smallest int168 or * greater than largest int168). * * Counterpart to Solidity's `int168` operator. * * Requirements: * * - input must fit into 168 bits * * _Available since v4.7._ */ function toInt168(int256 value) internal pure returns (int168 downcasted) { downcasted = int168(value); require(downcasted == value, "SafeCast: value doesn't fit in 168 bits"); } /** * @dev Returns the downcasted int160 from int256, reverting on * overflow (when the input is less than smallest int160 or * greater than largest int160). * * Counterpart to Solidity's `int160` operator. * * Requirements: * * - input must fit into 160 bits * * _Available since v4.7._ */ function toInt160(int256 value) internal pure returns (int160 downcasted) { downcasted = int160(value); require(downcasted == value, "SafeCast: value doesn't fit in 160 bits"); } /** * @dev Returns the downcasted int152 from int256, reverting on * overflow (when the input is less than smallest int152 or * greater than largest int152). * * Counterpart to Solidity's `int152` operator. * * Requirements: * * - input must fit into 152 bits * * _Available since v4.7._ */ function toInt152(int256 value) internal pure returns (int152 downcasted) { downcasted = int152(value); require(downcasted == value, "SafeCast: value doesn't fit in 152 bits"); } /** * @dev Returns the downcasted int144 from int256, reverting on * overflow (when the input is less than smallest int144 or * greater than largest int144). * * Counterpart to Solidity's `int144` operator. * * Requirements: * * - input must fit into 144 bits * * _Available since v4.7._ */ function toInt144(int256 value) internal pure returns (int144 downcasted) { downcasted = int144(value); require(downcasted == value, "SafeCast: value doesn't fit in 144 bits"); } /** * @dev Returns the downcasted int136 from int256, reverting on * overflow (when the input is less than smallest int136 or * greater than largest int136). * * Counterpart to Solidity's `int136` operator. * * Requirements: * * - input must fit into 136 bits * * _Available since v4.7._ */ function toInt136(int256 value) internal pure returns (int136 downcasted) { downcasted = int136(value); require(downcasted == value, "SafeCast: value doesn't fit in 136 bits"); } /** * @dev Returns the downcasted int128 from int256, reverting on * overflow (when the input is less than smallest int128 or * greater than largest int128). * * Counterpart to Solidity's `int128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v3.1._ */ function toInt128(int256 value) internal pure returns (int128 downcasted) { downcasted = int128(value); require(downcasted == value, "SafeCast: value doesn't fit in 128 bits"); } /** * @dev Returns the downcasted int120 from int256, reverting on * overflow (when the input is less than smallest int120 or * greater than largest int120). * * Counterpart to Solidity's `int120` operator. * * Requirements: * * - input must fit into 120 bits * * _Available since v4.7._ */ function toInt120(int256 value) internal pure returns (int120 downcasted) { downcasted = int120(value); require(downcasted == value, "SafeCast: value doesn't fit in 120 bits"); } /** * @dev Returns the downcasted int112 from int256, reverting on * overflow (when the input is less than smallest int112 or * greater than largest int112). * * Counterpart to Solidity's `int112` operator. * * Requirements: * * - input must fit into 112 bits * * _Available since v4.7._ */ function toInt112(int256 value) internal pure returns (int112 downcasted) { downcasted = int112(value); require(downcasted == value, "SafeCast: value doesn't fit in 112 bits"); } /** * @dev Returns the downcasted int104 from int256, reverting on * overflow (when the input is less than smallest int104 or * greater than largest int104). * * Counterpart to Solidity's `int104` operator. * * Requirements: * * - input must fit into 104 bits * * _Available since v4.7._ */ function toInt104(int256 value) internal pure returns (int104 downcasted) { downcasted = int104(value); require(downcasted == value, "SafeCast: value doesn't fit in 104 bits"); } /** * @dev Returns the downcasted int96 from int256, reverting on * overflow (when the input is less than smallest int96 or * greater than largest int96). * * Counterpart to Solidity's `int96` operator. * * Requirements: * * - input must fit into 96 bits * * _Available since v4.7._ */ function toInt96(int256 value) internal pure returns (int96 downcasted) { downcasted = int96(value); require(downcasted == value, "SafeCast: value doesn't fit in 96 bits"); } /** * @dev Returns the downcasted int88 from int256, reverting on * overflow (when the input is less than smallest int88 or * greater than largest int88). * * Counterpart to Solidity's `int88` operator. * * Requirements: * * - input must fit into 88 bits * * _Available since v4.7._ */ function toInt88(int256 value) internal pure returns (int88 downcasted) { downcasted = int88(value); require(downcasted == value, "SafeCast: value doesn't fit in 88 bits"); } /** * @dev Returns the downcasted int80 from int256, reverting on * overflow (when the input is less than smallest int80 or * greater than largest int80). * * Counterpart to Solidity's `int80` operator. * * Requirements: * * - input must fit into 80 bits * * _Available since v4.7._ */ function toInt80(int256 value) internal pure returns (int80 downcasted) { downcasted = int80(value); require(downcasted == value, "SafeCast: value doesn't fit in 80 bits"); } /** * @dev Returns the downcasted int72 from int256, reverting on * overflow (when the input is less than smallest int72 or * greater than largest int72). * * Counterpart to Solidity's `int72` operator. * * Requirements: * * - input must fit into 72 bits * * _Available since v4.7._ */ function toInt72(int256 value) internal pure returns (int72 downcasted) { downcasted = int72(value); require(downcasted == value, "SafeCast: value doesn't fit in 72 bits"); } /** * @dev Returns the downcasted int64 from int256, reverting on * overflow (when the input is less than smallest int64 or * greater than largest int64). * * Counterpart to Solidity's `int64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v3.1._ */ function toInt64(int256 value) internal pure returns (int64 downcasted) { downcasted = int64(value); require(downcasted == value, "SafeCast: value doesn't fit in 64 bits"); } /** * @dev Returns the downcasted int56 from int256, reverting on * overflow (when the input is less than smallest int56 or * greater than largest int56). * * Counterpart to Solidity's `int56` operator. * * Requirements: * * - input must fit into 56 bits * * _Available since v4.7._ */ function toInt56(int256 value) internal pure returns (int56 downcasted) { downcasted = int56(value); require(downcasted == value, "SafeCast: value doesn't fit in 56 bits"); } /** * @dev Returns the downcasted int48 from int256, reverting on * overflow (when the input is less than smallest int48 or * greater than largest int48). * * Counterpart to Solidity's `int48` operator. * * Requirements: * * - input must fit into 48 bits * * _Available since v4.7._ */ function toInt48(int256 value) internal pure returns (int48 downcasted) { downcasted = int48(value); require(downcasted == value, "SafeCast: value doesn't fit in 48 bits"); } /** * @dev Returns the downcasted int40 from int256, reverting on * overflow (when the input is less than smallest int40 or * greater than largest int40). * * Counterpart to Solidity's `int40` operator. * * Requirements: * * - input must fit into 40 bits * * _Available since v4.7._ */ function toInt40(int256 value) internal pure returns (int40 downcasted) { downcasted = int40(value); require(downcasted == value, "SafeCast: value doesn't fit in 40 bits"); } /** * @dev Returns the downcasted int32 from int256, reverting on * overflow (when the input is less than smallest int32 or * greater than largest int32). * * Counterpart to Solidity's `int32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v3.1._ */ function toInt32(int256 value) internal pure returns (int32 downcasted) { downcasted = int32(value); require(downcasted == value, "SafeCast: value doesn't fit in 32 bits"); } /** * @dev Returns the downcasted int24 from int256, reverting on * overflow (when the input is less than smallest int24 or * greater than largest int24). * * Counterpart to Solidity's `int24` operator. * * Requirements: * * - input must fit into 24 bits * * _Available since v4.7._ */ function toInt24(int256 value) internal pure returns (int24 downcasted) { downcasted = int24(value); require(downcasted == value, "SafeCast: value doesn't fit in 24 bits"); } /** * @dev Returns the downcasted int16 from int256, reverting on * overflow (when the input is less than smallest int16 or * greater than largest int16). * * Counterpart to Solidity's `int16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v3.1._ */ function toInt16(int256 value) internal pure returns (int16 downcasted) { downcasted = int16(value); require(downcasted == value, "SafeCast: value doesn't fit in 16 bits"); } /** * @dev Returns the downcasted int8 from int256, reverting on * overflow (when the input is less than smallest int8 or * greater than largest int8). * * Counterpart to Solidity's `int8` operator. * * Requirements: * * - input must fit into 8 bits * * _Available since v3.1._ */ function toInt8(int256 value) internal pure returns (int8 downcasted) { downcasted = int8(value); require(downcasted == value, "SafeCast: value doesn't fit in 8 bits"); } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. * * _Available since v3.0._ */ function toInt256(uint256 value) internal pure returns (int256) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256"); return int256(value); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol) pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the subtraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol) // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js. pragma solidity ^0.8.0; /** * @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. * * ``` * 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 of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @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._indexes[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 read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 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 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastValue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastValue; // Update the index for the moved value set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[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._indexes[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; } }
pragma solidity >=0.8.0 <0.9.0; // SPDX-License-Identifier: MIT import "../Types.sol"; import "../interfaces/IEAS.sol"; import "../interfaces/IASRegistry.sol"; /** * @title TellerAS - Teller Attestation Service - based on EAS - Ethereum Attestation Service */ contract TellerAS is IEAS { error AccessDenied(); error AlreadyRevoked(); error InvalidAttestation(); error InvalidExpirationTime(); error InvalidOffset(); error InvalidRegistry(); error InvalidSchema(); error InvalidVerifier(); error NotFound(); error NotPayable(); string public constant VERSION = "0.8"; // A terminator used when concatenating and hashing multiple fields. string private constant HASH_TERMINATOR = "@"; // The AS global registry. IASRegistry private immutable _asRegistry; // The EIP712 verifier used to verify signed attestations. IEASEIP712Verifier private immutable _eip712Verifier; // A mapping between attestations and their related attestations. mapping(bytes32 => bytes32[]) private _relatedAttestations; // A mapping between an account and its received attestations. mapping(address => mapping(bytes32 => bytes32[])) private _receivedAttestations; // A mapping between an account and its sent attestations. mapping(address => mapping(bytes32 => bytes32[])) private _sentAttestations; // A mapping between a schema and its attestations. mapping(bytes32 => bytes32[]) private _schemaAttestations; // The global mapping between attestations and their UUIDs. mapping(bytes32 => Attestation) private _db; // The global counter for the total number of attestations. uint256 private _attestationsCount; bytes32 private _lastUUID; /** * @dev Creates a new EAS instance. * * @param registry The address of the global AS registry. * @param verifier The address of the EIP712 verifier. */ constructor(IASRegistry registry, IEASEIP712Verifier verifier) { if (address(registry) == address(0x0)) { revert InvalidRegistry(); } if (address(verifier) == address(0x0)) { revert InvalidVerifier(); } _asRegistry = registry; _eip712Verifier = verifier; } /** * @inheritdoc IEAS */ function getASRegistry() external view override returns (IASRegistry) { return _asRegistry; } /** * @inheritdoc IEAS */ function getEIP712Verifier() external view override returns (IEASEIP712Verifier) { return _eip712Verifier; } /** * @inheritdoc IEAS */ function getAttestationsCount() external view override returns (uint256) { return _attestationsCount; } /** * @inheritdoc IEAS */ function attest( address recipient, bytes32 schema, uint256 expirationTime, bytes32 refUUID, bytes calldata data ) public payable virtual override returns (bytes32) { return _attest( recipient, schema, expirationTime, refUUID, data, msg.sender ); } /** * @inheritdoc IEAS */ function attestByDelegation( address recipient, bytes32 schema, uint256 expirationTime, bytes32 refUUID, bytes calldata data, address attester, uint8 v, bytes32 r, bytes32 s ) public payable virtual override returns (bytes32) { _eip712Verifier.attest( recipient, schema, expirationTime, refUUID, data, attester, v, r, s ); return _attest(recipient, schema, expirationTime, refUUID, data, attester); } /** * @inheritdoc IEAS */ function revoke(bytes32 uuid) public virtual override { return _revoke(uuid, msg.sender); } /** * @inheritdoc IEAS */ function revokeByDelegation( bytes32 uuid, address attester, uint8 v, bytes32 r, bytes32 s ) public virtual override { _eip712Verifier.revoke(uuid, attester, v, r, s); _revoke(uuid, attester); } /** * @inheritdoc IEAS */ function getAttestation(bytes32 uuid) external view override returns (Attestation memory) { return _db[uuid]; } /** * @inheritdoc IEAS */ function isAttestationValid(bytes32 uuid) public view override returns (bool) { return _db[uuid].uuid != 0; } /** * @inheritdoc IEAS */ function isAttestationActive(bytes32 uuid) public view virtual override returns (bool) { return isAttestationValid(uuid) && _db[uuid].expirationTime >= block.timestamp && _db[uuid].revocationTime == 0; } /** * @inheritdoc IEAS */ function getReceivedAttestationUUIDs( address recipient, bytes32 schema, uint256 start, uint256 length, bool reverseOrder ) external view override returns (bytes32[] memory) { return _sliceUUIDs( _receivedAttestations[recipient][schema], start, length, reverseOrder ); } /** * @inheritdoc IEAS */ function getReceivedAttestationUUIDsCount(address recipient, bytes32 schema) external view override returns (uint256) { return _receivedAttestations[recipient][schema].length; } /** * @inheritdoc IEAS */ function getSentAttestationUUIDs( address attester, bytes32 schema, uint256 start, uint256 length, bool reverseOrder ) external view override returns (bytes32[] memory) { return _sliceUUIDs( _sentAttestations[attester][schema], start, length, reverseOrder ); } /** * @inheritdoc IEAS */ function getSentAttestationUUIDsCount(address recipient, bytes32 schema) external view override returns (uint256) { return _sentAttestations[recipient][schema].length; } /** * @inheritdoc IEAS */ function getRelatedAttestationUUIDs( bytes32 uuid, uint256 start, uint256 length, bool reverseOrder ) external view override returns (bytes32[] memory) { return _sliceUUIDs( _relatedAttestations[uuid], start, length, reverseOrder ); } /** * @inheritdoc IEAS */ function getRelatedAttestationUUIDsCount(bytes32 uuid) external view override returns (uint256) { return _relatedAttestations[uuid].length; } /** * @inheritdoc IEAS */ function getSchemaAttestationUUIDs( bytes32 schema, uint256 start, uint256 length, bool reverseOrder ) external view override returns (bytes32[] memory) { return _sliceUUIDs( _schemaAttestations[schema], start, length, reverseOrder ); } /** * @inheritdoc IEAS */ function getSchemaAttestationUUIDsCount(bytes32 schema) external view override returns (uint256) { return _schemaAttestations[schema].length; } /** * @dev Attests to a specific AS. * * @param recipient The recipient of the attestation. * @param schema The UUID of the AS. * @param expirationTime The expiration time of the attestation. * @param refUUID An optional related attestation's UUID. * @param data Additional custom data. * @param attester The attesting account. * * @return The UUID of the new attestation. */ function _attest( address recipient, bytes32 schema, uint256 expirationTime, bytes32 refUUID, bytes calldata data, address attester ) private returns (bytes32) { if (expirationTime <= block.timestamp) { revert InvalidExpirationTime(); } IASRegistry.ASRecord memory asRecord = _asRegistry.getAS(schema); if (asRecord.uuid == EMPTY_UUID) { revert InvalidSchema(); } IASResolver resolver = asRecord.resolver; if (address(resolver) != address(0x0)) { if (msg.value != 0 && !resolver.isPayable()) { revert NotPayable(); } if ( !resolver.resolve{ value: msg.value }( recipient, asRecord.schema, data, expirationTime, attester ) ) { revert InvalidAttestation(); } } Attestation memory attestation = Attestation({ uuid: EMPTY_UUID, schema: schema, recipient: recipient, attester: attester, time: block.timestamp, expirationTime: expirationTime, revocationTime: 0, refUUID: refUUID, data: data }); _lastUUID = _getUUID(attestation); attestation.uuid = _lastUUID; _receivedAttestations[recipient][schema].push(_lastUUID); _sentAttestations[attester][schema].push(_lastUUID); _schemaAttestations[schema].push(_lastUUID); _db[_lastUUID] = attestation; _attestationsCount++; if (refUUID != 0) { if (!isAttestationValid(refUUID)) { revert NotFound(); } _relatedAttestations[refUUID].push(_lastUUID); } emit Attested(recipient, attester, _lastUUID, schema); return _lastUUID; } function getLastUUID() external view returns (bytes32) { return _lastUUID; } /** * @dev Revokes an existing attestation to a specific AS. * * @param uuid The UUID of the attestation to revoke. * @param attester The attesting account. */ function _revoke(bytes32 uuid, address attester) private { Attestation storage attestation = _db[uuid]; if (attestation.uuid == EMPTY_UUID) { revert NotFound(); } if (attestation.attester != attester) { revert AccessDenied(); } if (attestation.revocationTime != 0) { revert AlreadyRevoked(); } attestation.revocationTime = block.timestamp; emit Revoked(attestation.recipient, attester, uuid, attestation.schema); } /** * @dev Calculates a UUID for a given attestation. * * @param attestation The input attestation. * * @return Attestation UUID. */ function _getUUID(Attestation memory attestation) private view returns (bytes32) { return keccak256( abi.encodePacked( attestation.schema, attestation.recipient, attestation.attester, attestation.time, attestation.expirationTime, attestation.data, HASH_TERMINATOR, _attestationsCount ) ); } /** * @dev Returns a slice in an array of attestation UUIDs. * * @param uuids The array of attestation UUIDs. * @param start The offset to start from. * @param length The number of total members to retrieve. * @param reverseOrder Whether the offset starts from the end and the data is returned in reverse. * * @return An array of attestation UUIDs. */ function _sliceUUIDs( bytes32[] memory uuids, uint256 start, uint256 length, bool reverseOrder ) private pure returns (bytes32[] memory) { uint256 attestationsLength = uuids.length; if (attestationsLength == 0) { return new bytes32[](0); } if (start >= attestationsLength) { revert InvalidOffset(); } uint256 len = length; if (attestationsLength < start + length) { len = attestationsLength - start; } bytes32[] memory res = new bytes32[](len); for (uint256 i = 0; i < len; ++i) { res[i] = uuids[ reverseOrder ? attestationsLength - (start + i + 1) : start + i ]; } return res; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (metatx/ERC2771Context.sol) pragma solidity ^0.8.9; import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; /** * @dev Context variant with ERC2771 support. * @dev This is modified from the OZ library to remove the gap of storage variables at the end. */ abstract contract ERC2771ContextUpgradeable is Initializable, ContextUpgradeable { /// @custom:oz-upgrades-unsafe-allow state-variable-immutable address private immutable _trustedForwarder; /// @custom:oz-upgrades-unsafe-allow constructor constructor(address trustedForwarder) { _trustedForwarder = trustedForwarder; } function isTrustedForwarder(address forwarder) public view virtual returns (bool) { return forwarder == _trustedForwarder; } function _msgSender() internal view virtual override returns (address sender) { if (isTrustedForwarder(msg.sender)) { // The assembly code is more direct than the Solidity version using `abi.decode`. assembly { sender := shr(96, calldataload(sub(calldatasize(), 20))) } } else { return super._msgSender(); } } function _msgData() internal view virtual override returns (bytes calldata) { if (isTrustedForwarder(msg.sender)) { return msg.data[:msg.data.length - 20]; } else { return super._msgData(); } } }
// SPDX-Licence-Identifier: MIT pragma solidity >=0.8.0 <0.9.0; enum CollateralType { ERC20, ERC721, ERC1155 } struct Collateral { CollateralType _collateralType; uint256 _amount; uint256 _tokenId; address _collateralAddress; } interface ICollateralEscrowV1 { /** * @notice Deposits a collateral asset into the escrow. * @param _collateralType The type of collateral asset to deposit (ERC721, ERC1155). * @param _collateralAddress The address of the collateral token.i feel * @param _amount The amount to deposit. */ function depositAsset( CollateralType _collateralType, address _collateralAddress, uint256 _amount, uint256 _tokenId ) external payable; /** * @notice Withdraws a collateral asset from the escrow. * @param _collateralAddress The address of the collateral contract. * @param _amount The amount to withdraw. * @param _recipient The address to send the assets to. */ function withdraw( address _collateralAddress, uint256 _amount, address _recipient ) external; function withdrawDustTokens( address _tokenAddress, uint256 _amount, address _recipient ) external; function getBid() external view returns (uint256); function initialize(uint256 _bidId) external; }
pragma solidity >=0.8.0 <0.9.0; // SPDX-License-Identifier: MIT import "./IASResolver.sol"; /** * @title The global AS registry interface. */ interface IASRegistry { /** * @title A struct representing a record for a submitted AS (Attestation Schema). */ struct ASRecord { // A unique identifier of the AS. bytes32 uuid; // Optional schema resolver. IASResolver resolver; // Auto-incrementing index for reference, assigned by the registry itself. uint256 index; // Custom specification of the AS (e.g., an ABI). bytes schema; } /** * @dev Triggered when a new AS has been registered * * @param uuid The AS UUID. * @param index The AS index. * @param schema The AS schema. * @param resolver An optional AS schema resolver. * @param attester The address of the account used to register the AS. */ event Registered( bytes32 indexed uuid, uint256 indexed index, bytes schema, IASResolver resolver, address attester ); /** * @dev Submits and reserve a new AS * * @param schema The AS data schema. * @param resolver An optional AS schema resolver. * * @return The UUID of the new AS. */ function register(bytes calldata schema, IASResolver resolver) external returns (bytes32); /** * @dev Returns an existing AS by UUID * * @param uuid The UUID of the AS to retrieve. * * @return The AS data members. */ function getAS(bytes32 uuid) external view returns (ASRecord memory); /** * @dev Returns the global counter for the total number of attestations * * @return The global counter for the total number of attestations. */ function getASCount() external view returns (uint256); }
pragma solidity >=0.8.0 <0.9.0; // SPDX-License-Identifier: MIT /** * @title The interface of an optional AS resolver. */ interface IASResolver { /** * @dev Returns whether the resolver supports ETH transfers */ function isPayable() external pure returns (bool); /** * @dev Resolves an attestation and verifier whether its data conforms to the spec. * * @param recipient The recipient of the attestation. * @param schema The AS data schema. * @param data The actual attestation data. * @param expirationTime The expiration time of the attestation. * @param msgSender The sender of the original attestation message. * * @return Whether the data is valid according to the scheme. */ function resolve( address recipient, bytes calldata schema, bytes calldata data, uint256 expirationTime, address msgSender ) external payable returns (bool); }
// SPDX-Licence-Identifier: MIT pragma solidity >=0.8.0 <0.9.0; import { Collateral } from "./escrow/ICollateralEscrowV1.sol"; interface ICollateralManager { /** * @notice Checks the validity of a borrower's collateral balance. * @param _bidId The id of the associated bid. * @param _collateralInfo Additional information about the collateral asset. * @return validation_ Boolean indicating if the collateral balance was validated. */ function commitCollateral( uint256 _bidId, Collateral[] calldata _collateralInfo ) external returns (bool validation_); /** * @notice Checks the validity of a borrower's collateral balance and commits it to a bid. * @param _bidId The id of the associated bid. * @param _collateralInfo Additional information about the collateral asset. * @return validation_ Boolean indicating if the collateral balance was validated. */ function commitCollateral( uint256 _bidId, Collateral calldata _collateralInfo ) external returns (bool validation_); function checkBalances( address _borrowerAddress, Collateral[] calldata _collateralInfo ) external returns (bool validated_, bool[] memory checks_); /** * @notice Deploys a new collateral escrow. * @param _bidId The associated bidId of the collateral escrow. */ function deployAndDeposit(uint256 _bidId) external; /** * @notice Gets the address of a deployed escrow. * @notice _bidId The bidId to return the escrow for. * @return The address of the escrow. */ function getEscrow(uint256 _bidId) external view returns (address); /** * @notice Gets the collateral info for a given bid id. * @param _bidId The bidId to return the collateral info for. * @return The stored collateral info. */ function getCollateralInfo(uint256 _bidId) external view returns (Collateral[] memory); function getCollateralAmount(uint256 _bidId, address collateralAssetAddress) external view returns (uint256 _amount); /** * @notice Withdraws deposited collateral from the created escrow of a bid. * @param _bidId The id of the bid to withdraw collateral for. */ function withdraw(uint256 _bidId) external; /** * @notice Re-checks the validity of a borrower's collateral balance committed to a bid. * @param _bidId The id of the associated bid. * @return validation_ Boolean indicating if the collateral balance was validated. */ function revalidateCollateral(uint256 _bidId) external returns (bool); /** * @notice Sends the deposited collateral to a lender of a bid. * @notice Can only be called by the protocol. * @param _bidId The id of the liquidated bid. */ function lenderClaimCollateral(uint256 _bidId) external; /** * @notice Sends the deposited collateral to a lender of a bid. * @notice Can only be called by the protocol. * @param _bidId The id of the liquidated bid. * @param _collateralRecipient the address that will receive the collateral */ function lenderClaimCollateralWithRecipient(uint256 _bidId, address _collateralRecipient) external; /** * @notice Sends the deposited collateral to a liquidator of a bid. * @notice Can only be called by the protocol. * @param _bidId The id of the liquidated bid. * @param _liquidatorAddress The address of the liquidator to send the collateral to. */ function liquidateCollateral(uint256 _bidId, address _liquidatorAddress) external; }
pragma solidity >=0.8.0 <0.9.0; // SPDX-License-Identifier: MIT import "./IASRegistry.sol"; import "./IEASEIP712Verifier.sol"; /** * @title EAS - Ethereum Attestation Service interface */ interface IEAS { /** * @dev A struct representing a single attestation. */ struct Attestation { // A unique identifier of the attestation. bytes32 uuid; // A unique identifier of the AS. bytes32 schema; // The recipient of the attestation. address recipient; // The attester/sender of the attestation. address attester; // The time when the attestation was created (Unix timestamp). uint256 time; // The time when the attestation expires (Unix timestamp). uint256 expirationTime; // The time when the attestation was revoked (Unix timestamp). uint256 revocationTime; // The UUID of the related attestation. bytes32 refUUID; // Custom attestation data. bytes data; } /** * @dev Triggered when an attestation has been made. * * @param recipient The recipient of the attestation. * @param attester The attesting account. * @param uuid The UUID the revoked attestation. * @param schema The UUID of the AS. */ event Attested( address indexed recipient, address indexed attester, bytes32 uuid, bytes32 indexed schema ); /** * @dev Triggered when an attestation has been revoked. * * @param recipient The recipient of the attestation. * @param attester The attesting account. * @param schema The UUID of the AS. * @param uuid The UUID the revoked attestation. */ event Revoked( address indexed recipient, address indexed attester, bytes32 uuid, bytes32 indexed schema ); /** * @dev Returns the address of the AS global registry. * * @return The address of the AS global registry. */ function getASRegistry() external view returns (IASRegistry); /** * @dev Returns the address of the EIP712 verifier used to verify signed attestations. * * @return The address of the EIP712 verifier used to verify signed attestations. */ function getEIP712Verifier() external view returns (IEASEIP712Verifier); /** * @dev Returns the global counter for the total number of attestations. * * @return The global counter for the total number of attestations. */ function getAttestationsCount() external view returns (uint256); /** * @dev Attests to a specific AS. * * @param recipient The recipient of the attestation. * @param schema The UUID of the AS. * @param expirationTime The expiration time of the attestation. * @param refUUID An optional related attestation's UUID. * @param data Additional custom data. * * @return The UUID of the new attestation. */ function attest( address recipient, bytes32 schema, uint256 expirationTime, bytes32 refUUID, bytes calldata data ) external payable returns (bytes32); /** * @dev Attests to a specific AS using a provided EIP712 signature. * * @param recipient The recipient of the attestation. * @param schema The UUID of the AS. * @param expirationTime The expiration time of the attestation. * @param refUUID An optional related attestation's UUID. * @param data Additional custom data. * @param attester The attesting account. * @param v The recovery ID. * @param r The x-coordinate of the nonce R. * @param s The signature data. * * @return The UUID of the new attestation. */ function attestByDelegation( address recipient, bytes32 schema, uint256 expirationTime, bytes32 refUUID, bytes calldata data, address attester, uint8 v, bytes32 r, bytes32 s ) external payable returns (bytes32); /** * @dev Revokes an existing attestation to a specific AS. * * @param uuid The UUID of the attestation to revoke. */ function revoke(bytes32 uuid) external; /** * @dev Attests to a specific AS using a provided EIP712 signature. * * @param uuid The UUID of the attestation to revoke. * @param attester The attesting account. * @param v The recovery ID. * @param r The x-coordinate of the nonce R. * @param s The signature data. */ function revokeByDelegation( bytes32 uuid, address attester, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns an existing attestation by UUID. * * @param uuid The UUID of the attestation to retrieve. * * @return The attestation data members. */ function getAttestation(bytes32 uuid) external view returns (Attestation memory); /** * @dev Checks whether an attestation exists. * * @param uuid The UUID of the attestation to retrieve. * * @return Whether an attestation exists. */ function isAttestationValid(bytes32 uuid) external view returns (bool); /** * @dev Checks whether an attestation is active. * * @param uuid The UUID of the attestation to retrieve. * * @return Whether an attestation is active. */ function isAttestationActive(bytes32 uuid) external view returns (bool); /** * @dev Returns all received attestation UUIDs. * * @param recipient The recipient of the attestation. * @param schema The UUID of the AS. * @param start The offset to start from. * @param length The number of total members to retrieve. * @param reverseOrder Whether the offset starts from the end and the data is returned in reverse. * * @return An array of attestation UUIDs. */ function getReceivedAttestationUUIDs( address recipient, bytes32 schema, uint256 start, uint256 length, bool reverseOrder ) external view returns (bytes32[] memory); /** * @dev Returns the number of received attestation UUIDs. * * @param recipient The recipient of the attestation. * @param schema The UUID of the AS. * * @return The number of attestations. */ function getReceivedAttestationUUIDsCount(address recipient, bytes32 schema) external view returns (uint256); /** * @dev Returns all sent attestation UUIDs. * * @param attester The attesting account. * @param schema The UUID of the AS. * @param start The offset to start from. * @param length The number of total members to retrieve. * @param reverseOrder Whether the offset starts from the end and the data is returned in reverse. * * @return An array of attestation UUIDs. */ function getSentAttestationUUIDs( address attester, bytes32 schema, uint256 start, uint256 length, bool reverseOrder ) external view returns (bytes32[] memory); /** * @dev Returns the number of sent attestation UUIDs. * * @param recipient The recipient of the attestation. * @param schema The UUID of the AS. * * @return The number of attestations. */ function getSentAttestationUUIDsCount(address recipient, bytes32 schema) external view returns (uint256); /** * @dev Returns all attestations related to a specific attestation. * * @param uuid The UUID of the attestation to retrieve. * @param start The offset to start from. * @param length The number of total members to retrieve. * @param reverseOrder Whether the offset starts from the end and the data is returned in reverse. * * @return An array of attestation UUIDs. */ function getRelatedAttestationUUIDs( bytes32 uuid, uint256 start, uint256 length, bool reverseOrder ) external view returns (bytes32[] memory); /** * @dev Returns the number of related attestation UUIDs. * * @param uuid The UUID of the attestation to retrieve. * * @return The number of related attestations. */ function getRelatedAttestationUUIDsCount(bytes32 uuid) external view returns (uint256); /** * @dev Returns all per-schema attestation UUIDs. * * @param schema The UUID of the AS. * @param start The offset to start from. * @param length The number of total members to retrieve. * @param reverseOrder Whether the offset starts from the end and the data is returned in reverse. * * @return An array of attestation UUIDs. */ function getSchemaAttestationUUIDs( bytes32 schema, uint256 start, uint256 length, bool reverseOrder ) external view returns (bytes32[] memory); /** * @dev Returns the number of per-schema attestation UUIDs. * * @param schema The UUID of the AS. * * @return The number of attestations. */ function getSchemaAttestationUUIDsCount(bytes32 schema) external view returns (uint256); }
pragma solidity >=0.8.0 <0.9.0; // SPDX-License-Identifier: MIT /** * @title EIP712 typed signatures verifier for EAS delegated attestations interface. */ interface IEASEIP712Verifier { /** * @dev Returns the current nonce per-account. * * @param account The requested accunt. * * @return The current nonce. */ function getNonce(address account) external view returns (uint256); /** * @dev Verifies signed attestation. * * @param recipient The recipient of the attestation. * @param schema The UUID of the AS. * @param expirationTime The expiration time of the attestation. * @param refUUID An optional related attestation's UUID. * @param data Additional custom data. * @param attester The attesting account. * @param v The recovery ID. * @param r The x-coordinate of the nonce R. * @param s The signature data. */ function attest( address recipient, bytes32 schema, uint256 expirationTime, bytes32 refUUID, bytes calldata data, address attester, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Verifies signed revocations. * * @param uuid The UUID of the attestation to revoke. * @param attester The attesting account. * @param v The recovery ID. * @param r The x-coordinate of the nonce R. * @param s The signature data. */ function revoke( bytes32 uuid, address attester, uint8 v, bytes32 r, bytes32 s ) external; }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0 <0.9.0; interface IEscrowVault { /** * @notice Deposit tokens on behalf of another account * @param account The address of the account * @param token The address of the token * @param amount The amount to increase the balance */ function deposit(address account, address token, uint256 amount) external; function withdraw(address token, uint256 amount) external ; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; //records the unpause timestamp s interface IHasProtocolPausingManager { function getProtocolPausingManager() external view returns (address); // function isPauser(address _address) external view returns (bool); }
pragma solidity >=0.8.0 <0.9.0; // SPDX-License-Identifier: MIT import "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol"; abstract contract ILenderManager is IERC721Upgradeable { /** * @notice Registers a new active lender for a loan, minting the nft. * @param _bidId The id for the loan to set. * @param _newLender The address of the new active lender. */ function registerLoan(uint256 _bidId, address _newLender) external virtual; }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0 <0.9.0; //tellerv2 should support this interface ILoanRepaymentCallbacks { function setRepaymentListenerForBid(uint256 _bidId, address _listener) external; function getRepaymentListenerForBid(uint256 _bidId) external view returns (address); }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0 <0.9.0; interface ILoanRepaymentListener { function repayLoanCallback( uint256 bidId, address repayer, uint256 principalAmount, uint256 interestAmount ) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../EAS/TellerAS.sol"; import { PaymentType, PaymentCycleType } from "../libraries/V2Calculations.sol"; interface IMarketRegistry { function initialize(TellerAS tellerAs) external; function isVerifiedLender(uint256 _marketId, address _lender) external view returns (bool, bytes32); function isMarketOpen(uint256 _marketId) external view returns (bool); function isMarketClosed(uint256 _marketId) external view returns (bool); function isVerifiedBorrower(uint256 _marketId, address _borrower) external view returns (bool, bytes32); function getMarketOwner(uint256 _marketId) external view returns (address); function getMarketFeeRecipient(uint256 _marketId) external view returns (address); function getMarketURI(uint256 _marketId) external view returns (string memory); function getPaymentCycle(uint256 _marketId) external view returns (uint32, PaymentCycleType); function getPaymentDefaultDuration(uint256 _marketId) external view returns (uint32); function getBidExpirationTime(uint256 _marketId) external view returns (uint32); function getMarketplaceFee(uint256 _marketId) external view returns (uint16); function getPaymentType(uint256 _marketId) external view returns (PaymentType); function createMarket( address _initialOwner, uint32 _paymentCycleDuration, uint32 _paymentDefaultDuration, uint32 _bidExpirationTime, uint16 _feePercent, bool _requireLenderAttestation, bool _requireBorrowerAttestation, PaymentType _paymentType, PaymentCycleType _paymentCycleType, string calldata _uri ) external returns (uint256 marketId_); function createMarket( address _initialOwner, uint32 _paymentCycleDuration, uint32 _paymentDefaultDuration, uint32 _bidExpirationTime, uint16 _feePercent, bool _requireLenderAttestation, bool _requireBorrowerAttestation, string calldata _uri ) external returns (uint256 marketId_); function closeMarket(uint256 _marketId) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; //records the unpause timestamp s interface IProtocolPausingManager { function isPauser(address _address) external view returns (bool); function protocolPaused() external view returns (bool); function liquidationsPaused() external view returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; enum RepMark { Good, Delinquent, Default } interface IReputationManager { function initialize(address protocolAddress) external; function getDelinquentLoanIds(address _account) external returns (uint256[] memory); function getDefaultedLoanIds(address _account) external returns (uint256[] memory); function getCurrentDelinquentLoanIds(address _account) external returns (uint256[] memory); function getCurrentDefaultLoanIds(address _account) external returns (uint256[] memory); function updateAccountReputation(address _account) external; function updateAccountReputation(address _account, uint256 _bidId) external returns (RepMark); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import { Payment, BidState } from "../TellerV2Storage.sol"; import { Collateral } from "./escrow/ICollateralEscrowV1.sol"; interface ITellerV2 { /** * @notice Function for a borrower to create a bid for a loan. * @param _lendingToken The lending token asset requested to be borrowed. * @param _marketplaceId The unique id of the marketplace for the bid. * @param _principal The principal amount of the loan bid. * @param _duration The recurrent length of time before which a payment is due. * @param _APR The proposed interest rate for the loan bid. * @param _metadataURI The URI for additional borrower loan information as part of loan bid. * @param _receiver The address where the loan amount will be sent to. */ function submitBid( address _lendingToken, uint256 _marketplaceId, uint256 _principal, uint32 _duration, uint16 _APR, string calldata _metadataURI, address _receiver ) external returns (uint256 bidId_); /** * @notice Function for a borrower to create a bid for a loan with Collateral. * @param _lendingToken The lending token asset requested to be borrowed. * @param _marketplaceId The unique id of the marketplace for the bid. * @param _principal The principal amount of the loan bid. * @param _duration The recurrent length of time before which a payment is due. * @param _APR The proposed interest rate for the loan bid. * @param _metadataURI The URI for additional borrower loan information as part of loan bid. * @param _receiver The address where the loan amount will be sent to. * @param _collateralInfo Additional information about the collateral asset. */ function submitBid( address _lendingToken, uint256 _marketplaceId, uint256 _principal, uint32 _duration, uint16 _APR, string calldata _metadataURI, address _receiver, Collateral[] calldata _collateralInfo ) external returns (uint256 bidId_); /** * @notice Function for a lender to accept a proposed loan bid. * @param _bidId The id of the loan bid to accept. */ function lenderAcceptBid(uint256 _bidId) external returns ( uint256 amountToProtocol, uint256 amountToMarketplace, uint256 amountToBorrower ); /** * @notice Function for users to make the minimum amount due for an active loan. * @param _bidId The id of the loan to make the payment towards. */ function repayLoanMinimum(uint256 _bidId) external; /** * @notice Function for users to repay an active loan in full. * @param _bidId The id of the loan to make the payment towards. */ function repayLoanFull(uint256 _bidId) external; /** * @notice Function for users to make a payment towards an active loan. * @param _bidId The id of the loan to make the payment towards. * @param _amount The amount of the payment. */ function repayLoan(uint256 _bidId, uint256 _amount) external; /** * @notice Checks to see if a borrower is delinquent. * @param _bidId The id of the loan bid to check for. */ function isLoanDefaulted(uint256 _bidId) external view returns (bool); /** * @notice Checks to see if a loan was delinquent for longer than liquidation delay. * @param _bidId The id of the loan bid to check for. */ function isLoanLiquidateable(uint256 _bidId) external view returns (bool); /** * @notice Checks to see if a borrower is delinquent. * @param _bidId The id of the loan bid to check for. */ function isPaymentLate(uint256 _bidId) external view returns (bool); function getBidState(uint256 _bidId) external view returns (BidState); function getBorrowerActiveLoanIds(address _borrower) external view returns (uint256[] memory); /** * @notice Returns the borrower address for a given bid. * @param _bidId The id of the bid/loan to get the borrower for. * @return borrower_ The address of the borrower associated with the bid. */ function getLoanBorrower(uint256 _bidId) external view returns (address borrower_); /** * @notice Returns the lender address for a given bid. * @param _bidId The id of the bid/loan to get the lender for. * @return lender_ The address of the lender associated with the bid. */ function getLoanLender(uint256 _bidId) external view returns (address lender_); function getLoanLendingToken(uint256 _bidId) external view returns (address token_); function getLoanMarketId(uint256 _bidId) external view returns (uint256); function getLoanSummary(uint256 _bidId) external view returns ( address borrower, address lender, uint256 marketId, address principalTokenAddress, uint256 principalAmount, uint32 acceptedTimestamp, uint32 lastRepaidTimestamp, BidState bidState ); function calculateAmountOwed(uint256 _bidId, uint256 _timestamp) external view returns (Payment memory owed); function calculateAmountDue(uint256 _bidId, uint256 _timestamp) external view returns (Payment memory due); function lenderCloseLoan(uint256 _bidId) external; function lenderCloseLoanWithRecipient(uint256 _bidId, address _recipient) external; function liquidateLoanFull(uint256 _bidId) external; function liquidateLoanFullWithRecipient(uint256 _bidId, address _recipient) external; function getLoanDefaultTimestamp(uint256 _bidId) external view returns (uint256); function getEscrowVault() external view returns(address); function getProtocolFeeRecipient () external view returns(address); // function isPauser(address _account) external view returns(bool); }
// SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.9.0; // ---------------------------------------------------------------------------- // BokkyPooBah's DateTime Library v1.01 // // A gas-efficient Solidity date and time library // // https://github.com/bokkypoobah/BokkyPooBahsDateTimeLibrary // // Tested date range 1970/01/01 to 2345/12/31 // // Conventions: // Unit | Range | Notes // :-------- |:-------------:|:----- // timestamp | >= 0 | Unix timestamp, number of seconds since 1970/01/01 00:00:00 UTC // year | 1970 ... 2345 | // month | 1 ... 12 | // day | 1 ... 31 | // hour | 0 ... 23 | // minute | 0 ... 59 | // second | 0 ... 59 | // dayOfWeek | 1 ... 7 | 1 = Monday, ..., 7 = Sunday // // // Enjoy. (c) BokkyPooBah / Bok Consulting Pty Ltd 2018-2019. The MIT Licence. // ---------------------------------------------------------------------------- library BokkyPooBahsDateTimeLibrary { uint constant SECONDS_PER_DAY = 24 * 60 * 60; uint constant SECONDS_PER_HOUR = 60 * 60; uint constant SECONDS_PER_MINUTE = 60; int constant OFFSET19700101 = 2440588; uint constant DOW_MON = 1; uint constant DOW_TUE = 2; uint constant DOW_WED = 3; uint constant DOW_THU = 4; uint constant DOW_FRI = 5; uint constant DOW_SAT = 6; uint constant DOW_SUN = 7; // ------------------------------------------------------------------------ // Calculate the number of days from 1970/01/01 to year/month/day using // the date conversion algorithm from // https://aa.usno.navy.mil/faq/JD_formula.html // and subtracting the offset 2440588 so that 1970/01/01 is day 0 // // days = day // - 32075 // + 1461 * (year + 4800 + (month - 14) / 12) / 4 // + 367 * (month - 2 - (month - 14) / 12 * 12) / 12 // - 3 * ((year + 4900 + (month - 14) / 12) / 100) / 4 // - offset // ------------------------------------------------------------------------ function _daysFromDate(uint year, uint month, uint day) internal pure returns (uint _days) { require(year >= 1970); int _year = int(year); int _month = int(month); int _day = int(day); int __days = _day - 32075 + (1461 * (_year + 4800 + (_month - 14) / 12)) / 4 + (367 * (_month - 2 - ((_month - 14) / 12) * 12)) / 12 - (3 * ((_year + 4900 + (_month - 14) / 12) / 100)) / 4 - OFFSET19700101; _days = uint(__days); } // ------------------------------------------------------------------------ // Calculate year/month/day from the number of days since 1970/01/01 using // the date conversion algorithm from // http://aa.usno.navy.mil/faq/docs/JD_Formula.php // and adding the offset 2440588 so that 1970/01/01 is day 0 // // int L = days + 68569 + offset // int N = 4 * L / 146097 // L = L - (146097 * N + 3) / 4 // year = 4000 * (L + 1) / 1461001 // L = L - 1461 * year / 4 + 31 // month = 80 * L / 2447 // dd = L - 2447 * month / 80 // L = month / 11 // month = month + 2 - 12 * L // year = 100 * (N - 49) + year + L // ------------------------------------------------------------------------ function _daysToDate(uint _days) internal pure returns (uint year, uint month, uint day) { int __days = int(_days); int L = __days + 68569 + OFFSET19700101; int N = (4 * L) / 146097; L = L - (146097 * N + 3) / 4; int _year = (4000 * (L + 1)) / 1461001; L = L - (1461 * _year) / 4 + 31; int _month = (80 * L) / 2447; int _day = L - (2447 * _month) / 80; L = _month / 11; _month = _month + 2 - 12 * L; _year = 100 * (N - 49) + _year + L; year = uint(_year); month = uint(_month); day = uint(_day); } function timestampFromDate(uint year, uint month, uint day) internal pure returns (uint timestamp) { timestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY; } function timestampFromDateTime( uint year, uint month, uint day, uint hour, uint minute, uint second ) internal pure returns (uint timestamp) { timestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY + hour * SECONDS_PER_HOUR + minute * SECONDS_PER_MINUTE + second; } function timestampToDate(uint timestamp) internal pure returns (uint year, uint month, uint day) { (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY); } function timestampToDateTime(uint timestamp) internal pure returns ( uint year, uint month, uint day, uint hour, uint minute, uint second ) { (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY); uint secs = timestamp % SECONDS_PER_DAY; hour = secs / SECONDS_PER_HOUR; secs = secs % SECONDS_PER_HOUR; minute = secs / SECONDS_PER_MINUTE; second = secs % SECONDS_PER_MINUTE; } function isValidDate(uint year, uint month, uint day) internal pure returns (bool valid) { if (year >= 1970 && month > 0 && month <= 12) { uint daysInMonth = _getDaysInMonth(year, month); if (day > 0 && day <= daysInMonth) { valid = true; } } } function isValidDateTime( uint year, uint month, uint day, uint hour, uint minute, uint second ) internal pure returns (bool valid) { if (isValidDate(year, month, day)) { if (hour < 24 && minute < 60 && second < 60) { valid = true; } } } function isLeapYear(uint timestamp) internal pure returns (bool leapYear) { (uint year, , ) = _daysToDate(timestamp / SECONDS_PER_DAY); leapYear = _isLeapYear(year); } function _isLeapYear(uint year) internal pure returns (bool leapYear) { leapYear = ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0); } function isWeekDay(uint timestamp) internal pure returns (bool weekDay) { weekDay = getDayOfWeek(timestamp) <= DOW_FRI; } function isWeekEnd(uint timestamp) internal pure returns (bool weekEnd) { weekEnd = getDayOfWeek(timestamp) >= DOW_SAT; } function getDaysInMonth(uint timestamp) internal pure returns (uint daysInMonth) { (uint year, uint month, ) = _daysToDate(timestamp / SECONDS_PER_DAY); daysInMonth = _getDaysInMonth(year, month); } function _getDaysInMonth(uint year, uint month) internal pure returns (uint daysInMonth) { if ( month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 ) { daysInMonth = 31; } else if (month != 2) { daysInMonth = 30; } else { daysInMonth = _isLeapYear(year) ? 29 : 28; } } // 1 = Monday, 7 = Sunday function getDayOfWeek(uint timestamp) internal pure returns (uint dayOfWeek) { uint _days = timestamp / SECONDS_PER_DAY; dayOfWeek = ((_days + 3) % 7) + 1; } function getYear(uint timestamp) internal pure returns (uint year) { (year, , ) = _daysToDate(timestamp / SECONDS_PER_DAY); } function getMonth(uint timestamp) internal pure returns (uint month) { (, month, ) = _daysToDate(timestamp / SECONDS_PER_DAY); } function getDay(uint timestamp) internal pure returns (uint day) { (, , day) = _daysToDate(timestamp / SECONDS_PER_DAY); } function getHour(uint timestamp) internal pure returns (uint hour) { uint secs = timestamp % SECONDS_PER_DAY; hour = secs / SECONDS_PER_HOUR; } function getMinute(uint timestamp) internal pure returns (uint minute) { uint secs = timestamp % SECONDS_PER_HOUR; minute = secs / SECONDS_PER_MINUTE; } function getSecond(uint timestamp) internal pure returns (uint second) { second = timestamp % SECONDS_PER_MINUTE; } function addYears(uint timestamp, uint _years) internal pure returns (uint newTimestamp) { (uint year, uint month, uint day) = _daysToDate( timestamp / SECONDS_PER_DAY ); year += _years; uint daysInMonth = _getDaysInMonth(year, month); if (day > daysInMonth) { day = daysInMonth; } newTimestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY + (timestamp % SECONDS_PER_DAY); require(newTimestamp >= timestamp); } function addMonths(uint timestamp, uint _months) internal pure returns (uint newTimestamp) { (uint year, uint month, uint day) = _daysToDate( timestamp / SECONDS_PER_DAY ); month += _months; year += (month - 1) / 12; month = ((month - 1) % 12) + 1; uint daysInMonth = _getDaysInMonth(year, month); if (day > daysInMonth) { day = daysInMonth; } newTimestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY + (timestamp % SECONDS_PER_DAY); require(newTimestamp >= timestamp); } function addDays(uint timestamp, uint _days) internal pure returns (uint newTimestamp) { newTimestamp = timestamp + _days * SECONDS_PER_DAY; require(newTimestamp >= timestamp); } function addHours(uint timestamp, uint _hours) internal pure returns (uint newTimestamp) { newTimestamp = timestamp + _hours * SECONDS_PER_HOUR; require(newTimestamp >= timestamp); } function addMinutes(uint timestamp, uint _minutes) internal pure returns (uint newTimestamp) { newTimestamp = timestamp + _minutes * SECONDS_PER_MINUTE; require(newTimestamp >= timestamp); } function addSeconds(uint timestamp, uint _seconds) internal pure returns (uint newTimestamp) { newTimestamp = timestamp + _seconds; require(newTimestamp >= timestamp); } function subYears(uint timestamp, uint _years) internal pure returns (uint newTimestamp) { (uint year, uint month, uint day) = _daysToDate( timestamp / SECONDS_PER_DAY ); year -= _years; uint daysInMonth = _getDaysInMonth(year, month); if (day > daysInMonth) { day = daysInMonth; } newTimestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY + (timestamp % SECONDS_PER_DAY); require(newTimestamp <= timestamp); } function subMonths(uint timestamp, uint _months) internal pure returns (uint newTimestamp) { (uint year, uint month, uint day) = _daysToDate( timestamp / SECONDS_PER_DAY ); uint yearMonth = year * 12 + (month - 1) - _months; year = yearMonth / 12; month = (yearMonth % 12) + 1; uint daysInMonth = _getDaysInMonth(year, month); if (day > daysInMonth) { day = daysInMonth; } newTimestamp = _daysFromDate(year, month, day) * SECONDS_PER_DAY + (timestamp % SECONDS_PER_DAY); require(newTimestamp <= timestamp); } function subDays(uint timestamp, uint _days) internal pure returns (uint newTimestamp) { newTimestamp = timestamp - _days * SECONDS_PER_DAY; require(newTimestamp <= timestamp); } function subHours(uint timestamp, uint _hours) internal pure returns (uint newTimestamp) { newTimestamp = timestamp - _hours * SECONDS_PER_HOUR; require(newTimestamp <= timestamp); } function subMinutes(uint timestamp, uint _minutes) internal pure returns (uint newTimestamp) { newTimestamp = timestamp - _minutes * SECONDS_PER_MINUTE; require(newTimestamp <= timestamp); } function subSeconds(uint timestamp, uint _seconds) internal pure returns (uint newTimestamp) { newTimestamp = timestamp - _seconds; require(newTimestamp <= timestamp); } function diffYears(uint fromTimestamp, uint toTimestamp) internal pure returns (uint _years) { require(fromTimestamp <= toTimestamp); (uint fromYear, , ) = _daysToDate(fromTimestamp / SECONDS_PER_DAY); (uint toYear, , ) = _daysToDate(toTimestamp / SECONDS_PER_DAY); _years = toYear - fromYear; } function diffMonths(uint fromTimestamp, uint toTimestamp) internal pure returns (uint _months) { require(fromTimestamp <= toTimestamp); (uint fromYear, uint fromMonth, ) = _daysToDate( fromTimestamp / SECONDS_PER_DAY ); (uint toYear, uint toMonth, ) = _daysToDate( toTimestamp / SECONDS_PER_DAY ); _months = toYear * 12 + toMonth - fromYear * 12 - fromMonth; } function diffDays(uint fromTimestamp, uint toTimestamp) internal pure returns (uint _days) { require(fromTimestamp <= toTimestamp); _days = (toTimestamp - fromTimestamp) / SECONDS_PER_DAY; } function diffHours(uint fromTimestamp, uint toTimestamp) internal pure returns (uint _hours) { require(fromTimestamp <= toTimestamp); _hours = (toTimestamp - fromTimestamp) / SECONDS_PER_HOUR; } function diffMinutes(uint fromTimestamp, uint toTimestamp) internal pure returns (uint _minutes) { require(fromTimestamp <= toTimestamp); _minutes = (toTimestamp - fromTimestamp) / SECONDS_PER_MINUTE; } function diffSeconds(uint fromTimestamp, uint toTimestamp) internal pure returns (uint _seconds) { require(fromTimestamp <= toTimestamp); _seconds = toTimestamp - fromTimestamp; } }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.7.6; library ExcessivelySafeCall { uint256 constant LOW_28_MASK = 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff; /// @notice Use when you _really_ really _really_ don't trust the called /// contract. This prevents the called contract from causing reversion of /// the caller in as many ways as we can. /// @dev The main difference between this and a solidity low-level call is /// that we limit the number of bytes that the callee can cause to be /// copied to caller memory. This prevents stupid things like malicious /// contracts returning 10,000,000 bytes causing a local OOG when copying /// to memory. /// @param _target The address to call /// @param _gas The amount of gas to forward to the remote contract /// @param _value The value in wei to send to the remote contract /// @param _maxCopy The maximum number of bytes of returndata to copy /// to memory. /// @param _calldata The data to send to the remote contract /// @return success and returndata, as `.call()`. Returndata is capped to /// `_maxCopy` bytes. function excessivelySafeCall( address _target, uint256 _gas, uint256 _value, uint16 _maxCopy, bytes memory _calldata ) internal returns (bool, bytes memory) { // set up for assembly call uint256 _toCopy; bool _success; bytes memory _returnData = new bytes(_maxCopy); // dispatch message to recipient // by assembly calling "handle" function // we call via assembly to avoid memcopying a very large returndata // returned by a malicious contract assembly { _success := call( _gas, // gas _target, // recipient _value, // ether value add(_calldata, 0x20), // inloc mload(_calldata), // inlen 0, // outloc 0 // outlen ) // limit our copy to 256 bytes _toCopy := returndatasize() if gt(_toCopy, _maxCopy) { _toCopy := _maxCopy } // Store the length of the copied bytes mstore(_returnData, _toCopy) // copy the bytes from returndata[0:_toCopy] returndatacopy(add(_returnData, 0x20), 0, _toCopy) } return (_success, _returnData); } /// @notice Use when you _really_ really _really_ don't trust the called /// contract. This prevents the called contract from causing reversion of /// the caller in as many ways as we can. /// @dev The main difference between this and a solidity low-level call is /// that we limit the number of bytes that the callee can cause to be /// copied to caller memory. This prevents stupid things like malicious /// contracts returning 10,000,000 bytes causing a local OOG when copying /// to memory. /// @param _target The address to call /// @param _gas The amount of gas to forward to the remote contract /// @param _maxCopy The maximum number of bytes of returndata to copy /// to memory. /// @param _calldata The data to send to the remote contract /// @return success and returndata, as `.call()`. Returndata is capped to /// `_maxCopy` bytes. function excessivelySafeStaticCall( address _target, uint256 _gas, uint16 _maxCopy, bytes memory _calldata ) internal view returns (bool, bytes memory) { // set up for assembly call uint256 _toCopy; bool _success; bytes memory _returnData = new bytes(_maxCopy); // dispatch message to recipient // by assembly calling "handle" function // we call via assembly to avoid memcopying a very large returndata // returned by a malicious contract assembly { _success := staticcall( _gas, // gas _target, // recipient add(_calldata, 0x20), // inloc mload(_calldata), // inlen 0, // outloc 0 // outlen ) // limit our copy to 256 bytes _toCopy := returndatasize() if gt(_toCopy, _maxCopy) { _toCopy := _maxCopy } // Store the length of the copied bytes mstore(_returnData, _toCopy) // copy the bytes from returndata[0:_toCopy] returndatacopy(add(_returnData, 0x20), 0, _toCopy) } return (_success, _returnData); } /** * @notice Swaps function selectors in encoded contract calls * @dev Allows reuse of encoded calldata for functions with identical * argument types but different names. It simply swaps out the first 4 bytes * for the new selector. This function modifies memory in place, and should * only be used with caution. * @param _newSelector The new 4-byte selector * @param _buf The encoded contract args */ function swapSelector(bytes4 _newSelector, bytes memory _buf) internal pure { require(_buf.length >= 4); uint256 _mask = LOW_28_MASK; assembly { // load the first word of let _word := mload(add(_buf, 0x20)) // mask out the top 4 bytes // /x _word := and(_word, _mask) _word := or(_newSelector, _word) mstore(add(_buf, 0x20), _word) } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // Libraries import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; import "./WadRayMath.sol"; /** * @dev Utility library for uint256 numbers * * @author [email protected] */ library NumbersLib { using WadRayMath for uint256; /** * @dev It represents 100% with 2 decimal places. */ uint16 internal constant PCT_100 = 10000; function percentFactor(uint256 decimals) internal pure returns (uint256) { return 100 * (10**decimals); } /** * @notice Returns a percentage value of a number. * @param self The number to get a percentage of. * @param percentage The percentage value to calculate with 2 decimal places (10000 = 100%). */ function percent(uint256 self, uint16 percentage) internal pure returns (uint256) { return percent(self, percentage, 2); } /** * @notice Returns a percentage value of a number. * @param self The number to get a percentage of. * @param percentage The percentage value to calculate with. * @param decimals The number of decimals the percentage value is in. */ function percent(uint256 self, uint256 percentage, uint256 decimals) internal pure returns (uint256) { return (self * percentage) / percentFactor(decimals); } /** * @notice it returns the absolute number of a specified parameter * @param self the number to be returned in it's absolute * @return the absolute number */ function abs(int256 self) internal pure returns (uint256) { return self >= 0 ? uint256(self) : uint256(-1 * self); } /** * @notice Returns a ratio percentage of {num1} to {num2}. * @dev Returned value is type uint16. * @param num1 The number used to get the ratio for. * @param num2 The number used to get the ratio from. * @return Ratio percentage with 2 decimal places (10000 = 100%). */ function ratioOf(uint256 num1, uint256 num2) internal pure returns (uint16) { return SafeCast.toUint16(ratioOf(num1, num2, 2)); } /** * @notice Returns a ratio percentage of {num1} to {num2}. * @param num1 The number used to get the ratio for. * @param num2 The number used to get the ratio from. * @param decimals The number of decimals the percentage value is returned in. * @return Ratio percentage value. */ function ratioOf(uint256 num1, uint256 num2, uint256 decimals) internal pure returns (uint256) { if (num2 == 0) return 0; return (num1 * percentFactor(decimals)) / num2; } /** * @notice Calculates the payment amount for a cycle duration. * The formula is calculated based on the standard Estimated Monthly Installment (https://en.wikipedia.org/wiki/Equated_monthly_installment) * EMI = [P x R x (1+R)^N]/[(1+R)^N-1] * @param principal The starting amount that is owed on the loan. * @param loanDuration The length of the loan. * @param cycleDuration The length of the loan's payment cycle. * @param apr The annual percentage rate of the loan. */ function pmt( uint256 principal, uint32 loanDuration, uint32 cycleDuration, uint16 apr, uint256 daysInYear ) internal pure returns (uint256) { require( loanDuration >= cycleDuration, "PMT: cycle duration < loan duration" ); if (apr == 0) return Math.mulDiv( principal, cycleDuration, loanDuration, Math.Rounding.Up ); // Number of payment cycles for the duration of the loan uint256 n = Math.ceilDiv(loanDuration, cycleDuration); uint256 one = WadRayMath.wad(); uint256 r = WadRayMath.pctToWad(apr).wadMul(cycleDuration).wadDiv( daysInYear ); uint256 exp = (one + r).wadPow(n); uint256 numerator = principal.wadMul(r).wadMul(exp); uint256 denominator = exp - one; return numerator.wadDiv(denominator); } }
pragma solidity >=0.8.0 <0.9.0; // SPDX-License-Identifier: MIT // Libraries import "./NumbersLib.sol"; import "@openzeppelin/contracts/utils/math/Math.sol"; import { Bid } from "../TellerV2Storage.sol"; import { BokkyPooBahsDateTimeLibrary as BPBDTL } from "./DateTimeLib.sol"; enum PaymentType { EMI, Bullet } enum PaymentCycleType { Seconds, Monthly } library V2Calculations { using NumbersLib for uint256; /** * @notice Returns the timestamp of the last payment made for a loan. * @param _bid The loan bid struct to get the timestamp for. */ function lastRepaidTimestamp(Bid storage _bid) internal view returns (uint32) { return _bid.loanDetails.lastRepaidTimestamp == 0 ? _bid.loanDetails.acceptedTimestamp : _bid.loanDetails.lastRepaidTimestamp; } /** * @notice Calculates the amount owed for a loan. * @param _bid The loan bid struct to get the owed amount for. * @param _timestamp The timestamp at which to get the owed amount at. * @param _paymentCycleType The payment cycle type of the loan (Seconds or Monthly). */ function calculateAmountOwed( Bid storage _bid, uint256 _timestamp, PaymentCycleType _paymentCycleType, uint32 _paymentCycleDuration ) public view returns ( uint256 owedPrincipal_, uint256 duePrincipal_, uint256 interest_ ) { // Total principal left to pay return calculateAmountOwed( _bid, lastRepaidTimestamp(_bid), _timestamp, _paymentCycleType, _paymentCycleDuration ); } function calculateAmountOwed( Bid storage _bid, uint256 _lastRepaidTimestamp, uint256 _timestamp, PaymentCycleType _paymentCycleType, uint32 _paymentCycleDuration ) public view returns ( uint256 owedPrincipal_, uint256 duePrincipal_, uint256 interest_ ) { owedPrincipal_ = _bid.loanDetails.principal - _bid.loanDetails.totalRepaid.principal; uint256 owedTime = _timestamp - uint256(_lastRepaidTimestamp); { uint256 daysInYear = _paymentCycleType == PaymentCycleType.Monthly ? 360 days : 365 days; uint256 interestOwedInAYear = owedPrincipal_.percent(_bid.terms.APR, 2); interest_ = (interestOwedInAYear * owedTime) / daysInYear; } bool isLastPaymentCycle; { uint256 lastPaymentCycleDuration = _bid.loanDetails.loanDuration % _paymentCycleDuration; if (lastPaymentCycleDuration == 0) { lastPaymentCycleDuration = _paymentCycleDuration; } uint256 endDate = uint256(_bid.loanDetails.acceptedTimestamp) + uint256(_bid.loanDetails.loanDuration); uint256 lastPaymentCycleStart = endDate - uint256(lastPaymentCycleDuration); isLastPaymentCycle = uint256(_timestamp) > lastPaymentCycleStart || owedPrincipal_ + interest_ <= _bid.terms.paymentCycleAmount; } if (_bid.paymentType == PaymentType.Bullet) { if (isLastPaymentCycle) { duePrincipal_ = owedPrincipal_; } } else { // Default to PaymentType.EMI // Max payable amount in a cycle // NOTE: the last cycle could have less than the calculated payment amount //the amount owed for the cycle should never exceed the current payment cycle amount so we use min here uint256 owedAmountForCycle = Math.min( ((_bid.terms.paymentCycleAmount * owedTime) ) / _paymentCycleDuration , _bid.terms.paymentCycleAmount+interest_ ) ; uint256 owedAmount = isLastPaymentCycle ? owedPrincipal_ + interest_ : owedAmountForCycle ; duePrincipal_ = Math.min(owedAmount - interest_, owedPrincipal_); } } /** * @notice Calculates the amount owed for a loan for the next payment cycle. * @param _type The payment type of the loan. * @param _cycleType The cycle type set for the loan. (Seconds or Monthly) * @param _principal The starting amount that is owed on the loan. * @param _duration The length of the loan. * @param _paymentCycle The length of the loan's payment cycle. * @param _apr The annual percentage rate of the loan. */ function calculatePaymentCycleAmount( PaymentType _type, PaymentCycleType _cycleType, uint256 _principal, uint32 _duration, uint32 _paymentCycle, uint16 _apr ) public view returns (uint256) { uint256 daysInYear = _cycleType == PaymentCycleType.Monthly ? 360 days : 365 days; if (_type == PaymentType.Bullet) { return _principal.percent(_apr).percent( uint256(_paymentCycle).ratioOf(daysInYear, 10), 10 ); } // Default to PaymentType.EMI return NumbersLib.pmt( _principal, _duration, _paymentCycle, _apr, daysInYear ); } function calculateNextDueDate( uint32 _acceptedTimestamp, uint32 _paymentCycle, uint32 _loanDuration, uint32 _lastRepaidTimestamp, PaymentCycleType _bidPaymentCycleType ) public view returns (uint32 dueDate_) { // Calculate due date if payment cycle is set to monthly if (_bidPaymentCycleType == PaymentCycleType.Monthly) { // Calculate the cycle number the last repayment was made uint256 lastPaymentCycle = BPBDTL.diffMonths( _acceptedTimestamp, _lastRepaidTimestamp ); if ( BPBDTL.getDay(_lastRepaidTimestamp) > BPBDTL.getDay(_acceptedTimestamp) ) { lastPaymentCycle += 2; } else { lastPaymentCycle += 1; } dueDate_ = uint32( BPBDTL.addMonths(_acceptedTimestamp, lastPaymentCycle) ); } else if (_bidPaymentCycleType == PaymentCycleType.Seconds) { // Start with the original due date being 1 payment cycle since bid was accepted dueDate_ = _acceptedTimestamp + _paymentCycle; // Calculate the cycle number the last repayment was made uint32 delta = _lastRepaidTimestamp - _acceptedTimestamp; if (delta > 0) { uint32 repaymentCycle = uint32( Math.ceilDiv(delta, _paymentCycle) ); dueDate_ += (repaymentCycle * _paymentCycle); } } uint32 endOfLoan = _acceptedTimestamp + _loanDuration; //if we are in the last payment cycle, the next due date is the end of loan duration if (dueDate_ > endOfLoan) { dueDate_ = endOfLoan; } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/math/SafeCast.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; /** * @title WadRayMath library * @author Multiplier Finance * @dev Provides mul and div function for wads (decimal numbers with 18 digits precision) and rays (decimals with 27 digits) */ library WadRayMath { using SafeMath for uint256; uint256 internal constant WAD = 1e18; uint256 internal constant halfWAD = WAD / 2; uint256 internal constant RAY = 1e27; uint256 internal constant halfRAY = RAY / 2; uint256 internal constant WAD_RAY_RATIO = 1e9; uint256 internal constant PCT_WAD_RATIO = 1e14; uint256 internal constant PCT_RAY_RATIO = 1e23; function ray() internal pure returns (uint256) { return RAY; } function wad() internal pure returns (uint256) { return WAD; } function halfRay() internal pure returns (uint256) { return halfRAY; } function halfWad() internal pure returns (uint256) { return halfWAD; } function wadMul(uint256 a, uint256 b) internal pure returns (uint256) { return halfWAD.add(a.mul(b)).div(WAD); } function wadDiv(uint256 a, uint256 b) internal pure returns (uint256) { uint256 halfB = b / 2; return halfB.add(a.mul(WAD)).div(b); } function rayMul(uint256 a, uint256 b) internal pure returns (uint256) { return halfRAY.add(a.mul(b)).div(RAY); } function rayDiv(uint256 a, uint256 b) internal pure returns (uint256) { uint256 halfB = b / 2; return halfB.add(a.mul(RAY)).div(b); } function rayToWad(uint256 a) internal pure returns (uint256) { uint256 halfRatio = WAD_RAY_RATIO / 2; return halfRatio.add(a).div(WAD_RAY_RATIO); } function rayToPct(uint256 a) internal pure returns (uint16) { uint256 halfRatio = PCT_RAY_RATIO / 2; uint256 val = halfRatio.add(a).div(PCT_RAY_RATIO); return SafeCast.toUint16(val); } function wadToPct(uint256 a) internal pure returns (uint16) { uint256 halfRatio = PCT_WAD_RATIO / 2; uint256 val = halfRatio.add(a).div(PCT_WAD_RATIO); return SafeCast.toUint16(val); } function wadToRay(uint256 a) internal pure returns (uint256) { return a.mul(WAD_RAY_RATIO); } function pctToRay(uint16 a) internal pure returns (uint256) { return uint256(a).mul(RAY).div(1e4); } function pctToWad(uint16 a) internal pure returns (uint256) { return uint256(a).mul(WAD).div(1e4); } /** * @dev calculates base^duration. The code uses the ModExp precompile * @return z base^duration, in ray */ function rayPow(uint256 x, uint256 n) internal pure returns (uint256) { return _pow(x, n, RAY, rayMul); } function wadPow(uint256 x, uint256 n) internal pure returns (uint256) { return _pow(x, n, WAD, wadMul); } function _pow( uint256 x, uint256 n, uint256 p, function(uint256, uint256) internal pure returns (uint256) mul ) internal pure returns (uint256 z) { z = n % 2 != 0 ? x : p; for (n /= 2; n != 0; n /= 2) { x = mul(x, x); if (n % 2 != 0) { z = mul(z, x); } } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.11; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; //import {IERC20} from "../IERC20.sol"; //import {IERC1363} from "../../../interfaces/IERC1363.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC-20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { /** * @dev An operation with an ERC-20 token failed. */ error SafeERC20FailedOperation(address token); /** * @dev Indicates a failed `decreaseAllowance` request. */ error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease); /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value))); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value))); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. * * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client" * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior. */ function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 oldAllowance = token.allowance(address(this), spender); forceApprove(token, spender, oldAllowance + value); } /** * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no * value, non-reverting calls are assumed to be successful. * * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client" * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior. */ function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal { unchecked { uint256 currentAllowance = token.allowance(address(this), spender); if (currentAllowance < requestedDecrease) { revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease); } forceApprove(token, spender, currentAllowance - requestedDecrease); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval * to be set to zero before setting it to a non-zero value, such as USDT. * * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being * set here. */ function forceApprove(IERC20 token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value)); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0))); _callOptionalReturn(token, approvalCall); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements. */ function _callOptionalReturn(IERC20 token, bytes memory data) private { uint256 returnSize; uint256 returnValue; assembly { // ("memory-safe") let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20) // bubble errors if iszero(success) { let ptr := mload(0x40) returndatacopy(ptr, 0, returndatasize()) revert(ptr, returndatasize()) } returnSize := returndatasize() returnValue := mload(0) } if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) { bool success; uint256 returnSize; uint256 returnValue; assembly { // ("memory-safe") success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20) returnSize := returndatasize() returnValue := mload(0) } return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../interfaces/IHasProtocolPausingManager.sol"; import "../interfaces/IProtocolPausingManager.sol"; abstract contract HasProtocolPausingManager is IHasProtocolPausingManager { //Both this bool and the address together take one storage slot bool private __paused;// Deprecated. handled by pausing manager now address private _protocolPausingManager; // 20 bytes, gap will start at new slot modifier whenLiquidationsNotPaused() { require(! IProtocolPausingManager(_protocolPausingManager). liquidationsPaused(), "Liquidations paused" ); _; } modifier whenProtocolNotPaused() { require(! IProtocolPausingManager(_protocolPausingManager). protocolPaused(), "Protocol paused" ); _; } function _setProtocolPausingManager(address protocolPausingManager) internal { _protocolPausingManager = protocolPausingManager ; } function getProtocolPausingManager() public view returns (address){ return _protocolPausingManager; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
pragma solidity >=0.8.0 <0.9.0; // SPDX-License-Identifier: MIT import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; contract ProtocolFee is OwnableUpgradeable { // Protocol fee set for loan processing. uint16 private _protocolFee; /** * @notice This event is emitted when the protocol fee has been updated. * @param newFee The new protocol fee set. * @param oldFee The previously set protocol fee. */ event ProtocolFeeSet(uint16 newFee, uint16 oldFee); /** * @notice Initialized the protocol fee. * @param initFee The initial protocol fee to be set on the protocol. */ function __ProtocolFee_init(uint16 initFee) internal onlyInitializing { __Ownable_init(); __ProtocolFee_init_unchained(initFee); } function __ProtocolFee_init_unchained(uint16 initFee) internal onlyInitializing { setProtocolFee(initFee); } /** * @notice Returns the current protocol fee. */ function protocolFee() public view virtual returns (uint16) { return _protocolFee; } /** * @notice Lets the DAO/owner of the protocol to set a new protocol fee. * @param newFee The new protocol fee to be set. */ function setProtocolFee(uint16 newFee) public virtual onlyOwner { // Skip if the fee is the same if (newFee == _protocolFee) return; uint16 oldFee = _protocolFee; _protocolFee = newFee; emit ProtocolFeeSet(newFee, oldFee); } }
pragma solidity >=0.8.0 <0.9.0; // SPDX-License-Identifier: MIT import "./TellerV2Storage.sol"; import "./ERC2771ContextUpgradeable.sol"; /** * @dev This contract should not use any storage */ abstract contract TellerV2Context is ERC2771ContextUpgradeable, TellerV2Storage { using EnumerableSet for EnumerableSet.AddressSet; event TrustedMarketForwarderSet( uint256 indexed marketId, address forwarder, address sender ); event MarketForwarderApproved( uint256 indexed marketId, address indexed forwarder, address sender ); event MarketForwarderRenounced( uint256 indexed marketId, address indexed forwarder, address sender ); constructor(address trustedForwarder) ERC2771ContextUpgradeable(trustedForwarder) {} /** * @notice Checks if an address is a trusted forwarder contract for a given market. * @param _marketId An ID for a lending market. * @param _trustedMarketForwarder An address to check if is a trusted forwarder in the given market. * @return A boolean indicating the forwarder address is trusted in a market. */ function isTrustedMarketForwarder( uint256 _marketId, address _trustedMarketForwarder ) public view returns (bool) { return _trustedMarketForwarders[_marketId] == _trustedMarketForwarder || lenderCommitmentForwarder == _trustedMarketForwarder; } /** * @notice Checks if an account has approved a forwarder for a market. * @param _marketId An ID for a lending market. * @param _forwarder A forwarder contract address. * @param _account The address to verify set an approval. * @return A boolean indicating if an approval was set. */ function hasApprovedMarketForwarder( uint256 _marketId, address _forwarder, address _account ) public view returns (bool) { return isTrustedMarketForwarder(_marketId, _forwarder) && _approvedForwarderSenders[_forwarder].contains(_account); } /** * @notice Sets a trusted forwarder for a lending market. * @notice The caller must owner the market given. See {MarketRegistry} * @param _marketId An ID for a lending market. * @param _forwarder A forwarder contract address. */ function setTrustedMarketForwarder(uint256 _marketId, address _forwarder) external { require( marketRegistry.getMarketOwner(_marketId) == _msgSender(), "Caller must be the market owner" ); _trustedMarketForwarders[_marketId] = _forwarder; emit TrustedMarketForwarderSet(_marketId, _forwarder, _msgSender()); } /** * @notice Approves a forwarder contract to use their address as a sender for a specific market. * @notice The forwarder given must be trusted by the market given. * @param _marketId An ID for a lending market. * @param _forwarder A forwarder contract address. */ function approveMarketForwarder(uint256 _marketId, address _forwarder) external { require( isTrustedMarketForwarder(_marketId, _forwarder), "Forwarder must be trusted by the market" ); _approvedForwarderSenders[_forwarder].add(_msgSender()); emit MarketForwarderApproved(_marketId, _forwarder, _msgSender()); } /** * @notice Renounces approval of a market forwarder * @param _marketId An ID for a lending market. * @param _forwarder A forwarder contract address. */ function renounceMarketForwarder(uint256 _marketId, address _forwarder) external { if (_approvedForwarderSenders[_forwarder].contains(_msgSender())) { _approvedForwarderSenders[_forwarder].remove(_msgSender()); emit MarketForwarderRenounced(_marketId, _forwarder, _msgSender()); } } /** * @notice Retrieves the function caller address by checking the appended calldata if the _actual_ caller is a trusted forwarder. * @param _marketId An ID for a lending market. * @return sender The address to use as the function caller. */ function _msgSenderForMarket(uint256 _marketId) internal view virtual returns (address) { if ( msg.data.length >= 20 && isTrustedMarketForwarder(_marketId, _msgSender()) ) { address sender; assembly { sender := shr(96, calldataload(sub(calldatasize(), 20))) } // Ensure the appended sender address approved the forwarder require( _approvedForwarderSenders[_msgSender()].contains(sender), "Sender must approve market forwarder" ); return sender; } return _msgSender(); } /** * @notice Retrieves the actual function calldata from a trusted forwarder call. * @param _marketId An ID for a lending market to verify if the caller is a trusted forwarder. * @return calldata The modified bytes array of the function calldata without the appended sender's address. */ function _msgDataForMarket(uint256 _marketId) internal view virtual returns (bytes calldata) { if (isTrustedMarketForwarder(_marketId, _msgSender())) { return msg.data[:msg.data.length - 20]; } else { return _msgData(); } } }
pragma solidity >=0.8.0 <0.9.0; // SPDX-License-Identifier: MIT import { IMarketRegistry } from "./interfaces/IMarketRegistry.sol"; import "./interfaces/IEscrowVault.sol"; import "./interfaces/IReputationManager.sol"; import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "./interfaces/ICollateralManager.sol"; import { PaymentType, PaymentCycleType } from "./libraries/V2Calculations.sol"; import "./interfaces/ILenderManager.sol"; enum BidState { NONEXISTENT, PENDING, CANCELLED, ACCEPTED, PAID, LIQUIDATED, CLOSED } /** * @notice Represents a total amount for a payment. * @param principal Amount that counts towards the principal. * @param interest Amount that counts toward interest. */ struct Payment { uint256 principal; uint256 interest; } /** * @notice Details about a loan request. * @param borrower Account address who is requesting a loan. * @param receiver Account address who will receive the loan amount. * @param lender Account address who accepted and funded the loan request. * @param marketplaceId ID of the marketplace the bid was submitted to. * @param metadataURI ID of off chain metadata to find additional information of the loan request. * @param loanDetails Struct of the specific loan details. * @param terms Struct of the loan request terms. * @param state Represents the current state of the loan. */ struct Bid { address borrower; address receiver; address lender; // if this is the LenderManager address, we use that .owner() as source of truth uint256 marketplaceId; bytes32 _metadataURI; // DEPRECATED LoanDetails loanDetails; Terms terms; BidState state; PaymentType paymentType; } /** * @notice Details about the loan. * @param lendingToken The token address for the loan. * @param principal The amount of tokens initially lent out. * @param totalRepaid Payment struct that represents the total principal and interest amount repaid. * @param timestamp Timestamp, in seconds, of when the bid was submitted by the borrower. * @param acceptedTimestamp Timestamp, in seconds, of when the bid was accepted by the lender. * @param lastRepaidTimestamp Timestamp, in seconds, of when the last payment was made * @param loanDuration The duration of the loan. */ struct LoanDetails { IERC20 lendingToken; uint256 principal; Payment totalRepaid; uint32 timestamp; uint32 acceptedTimestamp; uint32 lastRepaidTimestamp; uint32 loanDuration; } /** * @notice Information on the terms of a loan request * @param paymentCycleAmount Value of tokens expected to be repaid every payment cycle. * @param paymentCycle Duration, in seconds, of how often a payment must be made. * @param APR Annual percentage rating to be applied on repayments. (10000 == 100%) */ struct Terms { uint256 paymentCycleAmount; uint32 paymentCycle; uint16 APR; } abstract contract TellerV2Storage_G0 { /** Storage Variables */ // Current number of bids. uint256 public bidId; // Mapping of bidId to bid information. mapping(uint256 => Bid) public bids; // Mapping of borrowers to borrower requests. mapping(address => uint256[]) public borrowerBids; // Mapping of volume filled by lenders. mapping(address => uint256) public __lenderVolumeFilled; // DEPRECIATED // Volume filled by all lenders. uint256 public __totalVolumeFilled; // DEPRECIATED // List of allowed lending tokens EnumerableSet.AddressSet internal __lendingTokensSet; // DEPRECATED IMarketRegistry public marketRegistry; IReputationManager public reputationManager; // Mapping of borrowers to borrower requests. mapping(address => EnumerableSet.UintSet) internal _borrowerBidsActive; mapping(uint256 => uint32) public bidDefaultDuration; mapping(uint256 => uint32) public bidExpirationTime; // Mapping of volume filled by lenders. // Asset address => Lender address => Volume amount mapping(address => mapping(address => uint256)) public lenderVolumeFilled; // Volume filled by all lenders. // Asset address => Volume amount mapping(address => uint256) public totalVolumeFilled; uint256 public version; // Mapping of metadataURIs by bidIds. // Bid Id => metadataURI string mapping(uint256 => string) public uris; } abstract contract TellerV2Storage_G1 is TellerV2Storage_G0 { // market ID => trusted forwarder mapping(uint256 => address) internal _trustedMarketForwarders; // trusted forwarder => set of pre-approved senders mapping(address => EnumerableSet.AddressSet) internal _approvedForwarderSenders; } abstract contract TellerV2Storage_G2 is TellerV2Storage_G1 { address public lenderCommitmentForwarder; } abstract contract TellerV2Storage_G3 is TellerV2Storage_G2 { ICollateralManager public collateralManager; } abstract contract TellerV2Storage_G4 is TellerV2Storage_G3 { // Address of the lender manager contract ILenderManager public lenderManager; // BidId to payment cycle type (custom or monthly) mapping(uint256 => PaymentCycleType) public bidPaymentCycleType; } abstract contract TellerV2Storage_G5 is TellerV2Storage_G4 { // Address of the lender manager contract IEscrowVault public escrowVault; } abstract contract TellerV2Storage_G6 is TellerV2Storage_G5 { mapping(uint256 => address) public repaymentListenerForBid; } abstract contract TellerV2Storage_G7 is TellerV2Storage_G6 { mapping(address => bool) private __pauserRoleBearer; bool private __liquidationsPaused; } abstract contract TellerV2Storage_G8 is TellerV2Storage_G7 { address protocolFeeRecipient; } abstract contract TellerV2Storage is TellerV2Storage_G8 {}
pragma solidity >=0.8.0 <0.9.0; // SPDX-License-Identifier: MIT // A representation of an empty/uninitialized UUID. bytes32 constant EMPTY_UUID = 0;
{ "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": { "contracts/TellerV2.sol": { "V2Calculations": "0xe11884953b18f8ddc55875cbdab71b624779d3bb" } } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"trustedForwarder","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"bidId","type":"uint256"},{"internalType":"string","name":"action","type":"string"},{"internalType":"string","name":"message","type":"string"}],"name":"ActionNotAllowed","type":"error"},{"inputs":[{"internalType":"uint256","name":"bidId","type":"uint256"},{"internalType":"uint256","name":"payment","type":"uint256"},{"internalType":"uint256","name":"minimumOwed","type":"uint256"}],"name":"PaymentNotMinimum","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"bidId","type":"uint256"},{"indexed":true,"internalType":"address","name":"lender","type":"address"}],"name":"AcceptedBid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"bidId","type":"uint256"}],"name":"CancelledBid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"bidId","type":"uint256"},{"indexed":true,"internalType":"string","name":"feeType","type":"string"},{"indexed":true,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"FeePaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"bidId","type":"uint256"}],"name":"LoanClosed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"bidId","type":"uint256"},{"indexed":true,"internalType":"address","name":"liquidator","type":"address"}],"name":"LoanLiquidated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"bidId","type":"uint256"}],"name":"LoanRepaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"bidId","type":"uint256"}],"name":"LoanRepayment","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"marketId","type":"uint256"},{"indexed":true,"internalType":"address","name":"forwarder","type":"address"},{"indexed":false,"internalType":"address","name":"sender","type":"address"}],"name":"MarketForwarderApproved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"marketId","type":"uint256"},{"indexed":true,"internalType":"address","name":"forwarder","type":"address"},{"indexed":false,"internalType":"address","name":"sender","type":"address"}],"name":"MarketForwarderRenounced","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"bidId","type":"uint256"}],"name":"MarketOwnerCancelledBid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"newFee","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"oldFee","type":"uint16"}],"name":"ProtocolFeeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"bidId","type":"uint256"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"bytes32","name":"metadataURI","type":"bytes32"}],"name":"SubmittedBid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"marketId","type":"uint256"},{"indexed":false,"internalType":"address","name":"forwarder","type":"address"},{"indexed":false,"internalType":"address","name":"sender","type":"address"}],"name":"TrustedMarketForwarderSet","type":"event"},{"inputs":[],"name":"CURRENT_CODE_VERSION","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LIQUIDATION_DELAY","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"__lenderVolumeFilled","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"__totalVolumeFilled","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"},{"internalType":"address","name":"_forwarder","type":"address"}],"name":"approveMarketForwarder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"bidDefaultDuration","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"bidExpirationTime","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bidId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"bidPaymentCycleType","outputs":[{"internalType":"enum PaymentCycleType","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"bids","outputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"lender","type":"address"},{"internalType":"uint256","name":"marketplaceId","type":"uint256"},{"internalType":"bytes32","name":"_metadataURI","type":"bytes32"},{"components":[{"internalType":"contract IERC20","name":"lendingToken","type":"address"},{"internalType":"uint256","name":"principal","type":"uint256"},{"components":[{"internalType":"uint256","name":"principal","type":"uint256"},{"internalType":"uint256","name":"interest","type":"uint256"}],"internalType":"struct Payment","name":"totalRepaid","type":"tuple"},{"internalType":"uint32","name":"timestamp","type":"uint32"},{"internalType":"uint32","name":"acceptedTimestamp","type":"uint32"},{"internalType":"uint32","name":"lastRepaidTimestamp","type":"uint32"},{"internalType":"uint32","name":"loanDuration","type":"uint32"}],"internalType":"struct LoanDetails","name":"loanDetails","type":"tuple"},{"components":[{"internalType":"uint256","name":"paymentCycleAmount","type":"uint256"},{"internalType":"uint32","name":"paymentCycle","type":"uint32"},{"internalType":"uint16","name":"APR","type":"uint16"}],"internalType":"struct Terms","name":"terms","type":"tuple"},{"internalType":"enum BidState","name":"state","type":"uint8"},{"internalType":"enum PaymentType","name":"paymentType","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"borrowerBids","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"},{"internalType":"uint256","name":"_timestamp","type":"uint256"}],"name":"calculateAmountDue","outputs":[{"components":[{"internalType":"uint256","name":"principal","type":"uint256"},{"internalType":"uint256","name":"interest","type":"uint256"}],"internalType":"struct Payment","name":"due","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"},{"internalType":"uint256","name":"_timestamp","type":"uint256"}],"name":"calculateAmountOwed","outputs":[{"components":[{"internalType":"uint256","name":"principal","type":"uint256"},{"internalType":"uint256","name":"interest","type":"uint256"}],"internalType":"struct Payment","name":"owed","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"calculateNextDueDate","outputs":[{"internalType":"uint32","name":"dueDate_","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"cancelBid","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"claimLoanNFT","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"collateralManager","outputs":[{"internalType":"contract ICollateralManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"escrowVault","outputs":[{"internalType":"contract IEscrowVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"getBidState","outputs":[{"internalType":"enum BidState","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_borrower","type":"address"}],"name":"getBorrowerActiveLoanIds","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_borrower","type":"address"}],"name":"getBorrowerLoanIds","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getEscrowVault","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"getLoanBorrower","outputs":[{"internalType":"address","name":"borrower_","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"getLoanDefaultTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"getLoanLender","outputs":[{"internalType":"address","name":"lender_","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"getLoanLendingToken","outputs":[{"internalType":"address","name":"token_","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"getLoanMarketId","outputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"getLoanSummary","outputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"address","name":"lender","type":"address"},{"internalType":"uint256","name":"marketId","type":"uint256"},{"internalType":"address","name":"principalTokenAddress","type":"address"},{"internalType":"uint256","name":"principalAmount","type":"uint256"},{"internalType":"uint32","name":"acceptedTimestamp","type":"uint32"},{"internalType":"uint32","name":"lastRepaidTimestamp","type":"uint32"},{"internalType":"enum BidState","name":"bidState","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getProtocolFeeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getProtocolPausingManager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"getRepaymentListenerForBid","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"},{"internalType":"address","name":"_forwarder","type":"address"},{"internalType":"address","name":"_account","type":"address"}],"name":"hasApprovedMarketForwarder","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"_protocolFee","type":"uint16"},{"internalType":"address","name":"_marketRegistry","type":"address"},{"internalType":"address","name":"_reputationManager","type":"address"},{"internalType":"address","name":"_lenderCommitmentForwarder","type":"address"},{"internalType":"address","name":"_collateralManager","type":"address"},{"internalType":"address","name":"_lenderManager","type":"address"},{"internalType":"address","name":"_escrowVault","type":"address"},{"internalType":"address","name":"_protocolPausingManager","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"isLoanDefaulted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"isLoanExpired","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"isLoanLiquidateable","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"isPaymentLate","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"forwarder","type":"address"}],"name":"isTrustedForwarder","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"},{"internalType":"address","name":"_trustedMarketForwarder","type":"address"}],"name":"isTrustedMarketForwarder","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"lastRepaidTimestamp","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"lenderAcceptBid","outputs":[{"internalType":"uint256","name":"amountToProtocol","type":"uint256"},{"internalType":"uint256","name":"amountToMarketplace","type":"uint256"},{"internalType":"uint256","name":"amountToBorrower","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"lenderCloseLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"},{"internalType":"address","name":"_collateralRecipient","type":"address"}],"name":"lenderCloseLoanWithRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lenderCommitmentForwarder","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lenderManager","outputs":[{"internalType":"contract ILenderManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"lenderVolumeFilled","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"liquidateLoanFull","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"},{"internalType":"address","name":"_recipient","type":"address"}],"name":"liquidateLoanFullWithRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"marketOwnerCancelBid","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"marketRegistry","outputs":[{"internalType":"contract IMarketRegistry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolFee","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"},{"internalType":"address","name":"_forwarder","type":"address"}],"name":"renounceMarketForwarder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"repayLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"repayLoanFull","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"repayLoanFullWithoutCollateralWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"}],"name":"repayLoanMinimum","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"repayLoanWithoutCollateralWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"repaymentListenerForBid","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"reputationManager","outputs":[{"internalType":"contract IReputationManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"newFee","type":"uint16"}],"name":"setProtocolFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"}],"name":"setProtocolFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_protocolPausingManager","type":"address"}],"name":"setProtocolPausingManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_bidId","type":"uint256"},{"internalType":"address","name":"_listener","type":"address"}],"name":"setRepaymentListenerForBid","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"},{"internalType":"address","name":"_forwarder","type":"address"}],"name":"setTrustedMarketForwarder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_lendingToken","type":"address"},{"internalType":"uint256","name":"_marketplaceId","type":"uint256"},{"internalType":"uint256","name":"_principal","type":"uint256"},{"internalType":"uint32","name":"_duration","type":"uint32"},{"internalType":"uint16","name":"_APR","type":"uint16"},{"internalType":"string","name":"_metadataURI","type":"string"},{"internalType":"address","name":"_receiver","type":"address"}],"name":"submitBid","outputs":[{"internalType":"uint256","name":"bidId_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_lendingToken","type":"address"},{"internalType":"uint256","name":"_marketplaceId","type":"uint256"},{"internalType":"uint256","name":"_principal","type":"uint256"},{"internalType":"uint32","name":"_duration","type":"uint32"},{"internalType":"uint16","name":"_APR","type":"uint16"},{"internalType":"string","name":"_metadataURI","type":"string"},{"internalType":"address","name":"_receiver","type":"address"},{"components":[{"internalType":"enum CollateralType","name":"_collateralType","type":"uint8"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"address","name":"_collateralAddress","type":"address"}],"internalType":"struct Collateral[]","name":"_collateralInfo","type":"tuple[]"}],"name":"submitBid","outputs":[{"internalType":"uint256","name":"bidId_","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"totalVolumeFilled","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"uris","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
60a06040523480156200001157600080fd5b5060405162005d6738038062005d67833981016040819052620000349162000046565b6001600160a01b031660805262000078565b6000602082840312156200005957600080fd5b81516001600160a01b03811681146200007157600080fd5b9392505050565b608051615ccc6200009b60003960008181610888015261482a0152615ccc6000f3fe608060405234801561001057600080fd5b50600436106104285760003560e01c806372c8fc0e1161022b578063b0e21e8a11610130578063dfca684e116100b8578063e7094fc711610087578063e7094fc714610bd6578063e8cbab0914610be9578063ecb96fe614610bfc578063f24df81014610c0f578063f2fde38b14610c2257600080fd5b8063dfca684e14610b76578063e0d3d58d14610b89578063e4467f3514610bb0578063e521cb9214610bc357600080fd5b8063c8d3b669116100ff578063c8d3b66914610b01578063c953132514610b14578063d08e4e6d14610b27578063d4eda4cf14610b50578063d87569cc14610b6357600080fd5b8063b0e21e8a14610a9c578063ba6d5b1514610ab2578063ba97120614610ac5578063bf77ffae14610ace57600080fd5b806396cf40b6116101b35780639d72d50c116101825780639d72d50c14610a22578063a10905ea14610a35578063a3b678ae14610a48578063a51e2bad14610a5b578063a8cb5d6814610a6e57600080fd5b806396cf40b6146109c05780639703ef35146109d35780639a11e339146109e65780639b0dbab1146109f957600080fd5b80638a700b53116101fa5780638a700b53146109605780638ac47319146109735780638da5cb5b1461097c5780638fa40d891461098d578063930fbae1146109a057600080fd5b806372c8fc0e1461091f5780637bbd53d7146109275780638288da8a1461093a5780638a2ae60b1461094d57600080fd5b80632519dc79116103315780634a06f6ea116102b95780636aedfe68116102885780636aedfe68146108b85780636b76c085146108cb5780636b868afb146108f1578063706a43c314610904578063715018a61461091757600080fd5b80634a06f6ea1461084b5780635426adf01461085e57806354fd4d501461086f578063572b6c051461087857600080fd5b80633819bcdc116103005780633819bcdc146106b65780633ef0a2f7146106c957806340910c70146106f25780634148f94c146107155780634423c5f11461072f57600080fd5b80632519dc791461063b5780632e9332d41461065b578063352f43001461066e578063367358911461068657600080fd5b80631420a266116103b45780631c960764116103835780631c960764146105e55780631d123633146105ef5780631fff59d914610602578063206c54c71461061557806323be345c1461062857600080fd5b80631420a26614610568578063145730331461057b57806318520f05146105bf57806319b353de146105d257600080fd5b80630da89593116103fb5780630da89593146104c55780631042b85f146104da57806310618223146104fa5780631253c5461461050d578063127caa881461052d57600080fd5b8063054de0ff1461042d57806306f33a9214610456578063089487b514610477578063093f5617146104a2575b600080fd5b61044061043b366004614fba565b610c35565b60405161044d9190614fd7565b60405180910390f35b610469610464366004615086565b610c5f565b60405190815260200161044d565b610469610485366004615128565b60a360209081526000928352604080842090915290825290205481565b6104b56104b0366004615161565b610d1b565b604051901515815260200161044d565b6104d86104d336600461517a565b610d70565b005b6104ed6104e836600461519f565b610ea6565b60405161044d91906151c1565b6104b5610508366004615161565b610fce565b61052061051b366004615161565b611064565b60405161044d9190615225565b61055361053b366004615161565b60a26020526000908152604090205463ffffffff1681565b60405163ffffffff909116815260200161044d565b6104d861057636600461517a565b6110fe565b6105a7610589366004615161565b6000908152609860205260409020600501546001600160a01b031690565b6040516001600160a01b03909116815260200161044d565b6104d86105cd366004615161565b611246565b6104b56105e0366004615238565b611442565b6105536201518081565b6104406105fd366004614fba565b61147f565b6104b5610610366004615161565b6114eb565b6104d8610623366004615161565b6114fa565b60aa546105a7906001600160a01b031681565b610469610649366004614fba565b60a46020526000908152604090205481565b6104d861066936600461517a565b611633565b606554630100000090046001600160a01b03166105a7565b6106a9610694366004615161565b60ac6020526000908152604090205460ff1681565b60405161044d91906152a0565b6104696106c43660046152b3565b611716565b6105a76106d7366004615161565b6000908152609860205260409020546001600160a01b031690565b610469610700366004615161565b60009081526098602052604090206003015490565b61071d600a81565b60405160ff909116815260200161044d565b61083661073d366004615161565b60986020908152600091825260409182902080546001820154600283015460038401546004850154875160e08101895260058701546001600160a01b0390811682526006880154828a01528951808b018b52600789015481526008890154818b0152828b0152600988015463ffffffff808216606080860191909152600160201b80840483166080870152600160401b8404831660a0870152600160601b909304821660c08601528c519081018d52600a8b01548152600b8b01549182169b81019b909b520461ffff1699890199909952600c909601549488169793841696939092169490939192909160ff8082169161010090041689565b60405161044d999897969594939291906152fc565b60ab546105a7906001600160a01b031681565b60ad546001600160a01b03166105a7565b61046960a55481565b6104b5610886366004614fba565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0390811691161490565b6104ed6108c636600461519f565b611747565b6105536108d9366004615161565b60a16020526000908152604090205463ffffffff1681565b609f546105a7906001600160a01b031681565b610553610912366004615161565b61186f565b6104d861196e565b6105a7611982565b6104696109353660046153f5565b611991565b6104d8610948366004615161565b611b02565b60ad546105a7906001600160a01b031681565b6104d861096e36600461519f565b611cc1565b61046960975481565b6033546001600160a01b03166105a7565b6104d861099b36600461517a565b611d38565b6104696109ae366004614fba565b609a6020526000908152604090205481565b6104696109ce366004615161565b611e1b565b6104d86109e1366004615161565b611e5f565b6104d86109f4366004615161565b611efd565b6105a7610a07366004615161565b600090815260ae60205260409020546001600160a01b031690565b6104d8610a30366004615161565b611f72565b6105a7610a43366004615161565b611fe2565b6104d8610a5636600461517a565b6120d3565b610553610a69366004615161565b61215f565b610a81610a7c366004615161565b612176565b6040805193845260208401929092529082015260600161044d565b60655460405161ffff909116815260200161044d565b60a9546105a7906001600160a01b031681565b610469609b5481565b610af4610adc366004615161565b6000908152609860205260409020600c015460ff1690565b60405161044d91906154f5565b6104d8610b0f366004614fba565b612970565b6104d8610b22366004615503565b612a11565b6105a7610b35366004615161565b60ae602052600090815260409020546001600160a01b031681565b6104d8610b5e366004615161565b612cfa565b6104b5610b7136600461517a565b612e45565b6104d8610b8436600461519f565b612e7f565b610b9c610b97366004615161565b612ef0565b60405161044d98979695949392919061559b565b6104d8610bbe3660046155eb565b612f91565b6104d8610bd1366004614fba565b612ffb565b6104d8610be436600461517a565b61302b565b6104b5610bf7366004615161565b6131c2565b609e546105a7906001600160a01b031681565b6104d8610c1d366004615161565b6131cf565b6104d8610c30366004614fba565b613381565b6001600160a01b038116600090815260a060205260409020606090610c59906133f7565b92915050565b6000606560039054906101000a90046001600160a01b03166001600160a01b031663425fad586040518163ffffffff1660e01b8152600401602060405180830381865afa158015610cb4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cd89190615618565b15610cfe5760405162461bcd60e51b8152600401610cf590615633565b60405180910390fd5b610d0e8989898989898989613404565b9998505050505050505050565b600060036000838152609860205260409020600c015460ff166006811115610d4557610d4561527a565b14610d5257506000919050565b610d5b8261186f565b63ffffffff164263ffffffff16119050919050565b606560039054906101000a90046001600160a01b03166001600160a01b031663425fad586040518163ffffffff1660e01b8152600401602060405180830381865afa158015610dc3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610de79190615618565b15610e045760405162461bcd60e51b8152600401610cf590615633565b606560039054906101000a90046001600160a01b03166001600160a01b0316638f6d0f116040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e7b9190615618565b15610e985760405162461bcd60e51b8152600401610cf59061565c565b610ea28282613a90565b5050565b604080518082019091526000808252602082015260008381526098602052604090206003600c82015460ff166006811115610ee357610ee361527a565b141580610f0157506009810154600160201b900463ffffffff168311155b15610f0c5750610c59565b60008073e11884953b18f8ddc55875cbdab71b624779d3bb63e4de10d38487610f448a600090815260ac602052604090205460ff1690565b60008b8152609860205260409020600b015463ffffffff166040518563ffffffff1660e01b8152600401610f7b9493929190615689565b606060405180830381865af4158015610f98573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fbc91906156bb565b91865250602085015250505092915050565b60008181526098602052604081206001600c82015460ff166006811115610ff757610ff761527a565b146110055750600092915050565b600083815260a2602052604090205463ffffffff166110275750600092915050565b600083815260a26020526040902054600982015461104e9163ffffffff90811691166156ff565b63ffffffff164263ffffffff1611915050919050565b60a6602052600090815260409020805461107d90615727565b80601f01602080910402602001604051908101604052809291908181526020018280546110a990615727565b80156110f65780601f106110cb576101008083540402835291602001916110f6565b820191906000526020600020905b8154815290600101906020018083116110d957829003601f168201915b505050505081565b611106613c48565b609e54604051633d36902960e01b8152600481018590526001600160a01b039283169290911690633d36902990602401602060405180830381865afa158015611153573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111779190615762565b6001600160a01b0316146111cd5760405162461bcd60e51b815260206004820152601f60248201527f43616c6c6572206d75737420626520746865206d61726b6574206f776e6572006044820152606401610cf5565b600082815260a76020526040902080546001600160a01b0319166001600160a01b038316179055817fa593acf9edc343669c7fc50d2caa3911326adef438361f0fa911be85c9e296a48261121f613c48565b604080516001600160a01b0393841681529290911660208301520160405180910390a25050565b6040805180820190915260038082526231b63760e91b60208301528291906000838152609860205260409020600c015460ff16600681111561128a5761128a61527a565b146112ac5781816040516347bc33cb60e11b8152600401610cf592919061577f565b606560039054906101000a90046001600160a01b03166001600160a01b031663425fad586040518163ffffffff1660e01b8152600401602060405180830381865afa1580156112ff573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113239190615618565b156113405760405162461bcd60e51b8152600401610cf590615633565b6000838152609860205260408120600381015490919061135f90613c52565b60028301549091506001600160a01b038083169116146113ad5760405162461bcd60e51b8152602060048201526009602482015268272b102632b73232b960b91b6044820152606401610cf5565b6002820180546001600160a01b0319167384d409eed89f6558fe3646397146232665788bf817905560ab5460405163096c998360e41b8152600481018790526001600160a01b038381166024830152909116906396c9983090604401600060405180830381600087803b15801561142357600080fd5b505af1158015611437573d6000803e3d6000fd5b505050505050505050565b600061144e8484612e45565b801561147757506001600160a01b038316600090815260a8602052604090206114779083613d09565b949350505050565b6001600160a01b0381166000908152609960209081526040918290208054835181840281018401909452808452606093928301828280156114df57602002820191906000526020600020905b8154815260200190600101908083116114cb575b50505050509050919050565b6000610c598262015180613d2b565b609e5460008281526098602052604090819020600301549051633d36902960e01b81526001600160a01b0390921691633d3690299161153f9160040190815260200190565b602060405180830381865afa15801561155c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115809190615762565b6001600160a01b0316611591613c48565b6001600160a01b0316146115fc576040516347bc33cb60e11b815260048082018390526060602483015260648201526326a7a1a160e11b608482015260a06044820152601060a48201526f2737ba1036b0b935b2ba1037bbb732b960811b60c482015260e401610cf5565b61160581613db2565b60405181907ff3f271d754f5264e0d143bf9be577d6eba153b0d833bd3a127d7b1a280bb13f190600090a250565b61163d8282612e45565b6116995760405162461bcd60e51b815260206004820152602760248201527f466f72776172646572206d757374206265207472757374656420627920746865604482015266081b585c9ad95d60ca1b6064820152608401610cf5565b6116c26116a4613c48565b6001600160a01b038316600090815260a86020526040902090613e5f565b50806001600160a01b0316827f65d6b5305e8c0e58e88454a1aeecae0f55975222338b25abd0997b4d305056a16116f7613c48565b6040516001600160a01b03909116815260200160405180910390a35050565b6099602052816000526040600020818154811061173257600080fd5b90600052602060002001600091509150505481565b604080518082018252600080825260208083018290528582526098905291909120600c81015460039060ff1660068111156117845761178461527a565b1415806117a257506009810154600160201b900463ffffffff168311155b156117ad5750610c59565b60008073e11884953b18f8ddc55875cbdab71b624779d3bb63e4de10d384876117e58a600090815260ac602052604090205460ff1690565b60008b8152609860205260409020600b015463ffffffff166040518563ffffffff1660e01b815260040161181c9493929190615689565b606060405180830381865af4158015611839573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061185d91906156bb565b90865260208601525050505092915050565b6000818152609860205260408120600c81015460039060ff1660068111156118995761189961527a565b146118a45750919050565b6009810154600b82015473e11884953b18f8ddc55875cbdab71b624779d3bb91630dcf16589163ffffffff600160201b830481169291811691600160601b9004166118ee8861215f565b600089815260ac6020526040908190205490516001600160e01b031960e088901b168152611926959493929160ff16906004016157ca565b602060405180830381865af4158015611943573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119679190615808565b9392505050565b611976613e74565b6119806000613eed565b565b600061198c613f3f565b905090565b6000606560039054906101000a90046001600160a01b03166001600160a01b031663425fad586040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119e6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a0a9190615618565b15611a275760405162461bcd60e51b8152600401610cf590615633565b611a378b8b8b8b8b8b8b8b613404565b60aa54604051631532dc4560e01b81529192506000916001600160a01b0390911690631532dc4590611a7190859088908890600401615832565b6020604051808303816000875af1158015611a90573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ab49190615618565b9050600181151514611af35760405162461bcd60e51b815260206004820152600860248201526721903130b610272b60c11b6044820152606401610cf5565b509a9950505050505050505050565b606560039054906101000a90046001600160a01b03166001600160a01b031663425fad586040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b55573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b799190615618565b15611b965760405162461bcd60e51b8152600401610cf590615633565b606560039054906101000a90046001600160a01b03166001600160a01b0316638f6d0f116040518163ffffffff1660e01b8152600401602060405180830381865afa158015611be9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c0d9190615618565b15611c2a5760405162461bcd60e51b8152600401610cf59061565c565b6040805180820190915260028152611b1b60f21b6020820152819060036000838152609860205260409020600c015460ff166006811115611c6d57611c6d61527a565b14611c8f5781816040516347bc33cb60e11b8152600401610cf592919061577f565b60008381526098602052604081206003810154909190611cae90613c52565b9050611cba8582613f7c565b5050505050565b6040805180820190915260028152611c9b60f21b6020820152829060036000838152609860205260409020600c015460ff166006811115611d0457611d0461527a565b14611d265781816040516347bc33cb60e11b8152600401610cf592919061577f565b611d32848460016141c0565b50505050565b803b80611d785760405162461bcd60e51b815260206004820152600e60248201526d139bdd08184818dbdb9d1c9858dd60921b6044820152606401610cf5565b600083815260986020526040812060030154611d9390613c52565b9050611d9e84611fe2565b6001600160a01b0316816001600160a01b031614611deb5760405162461bcd60e51b815260206004820152600a6024820152692737ba103632b73232b960b11b6044820152606401610cf5565b5050600091825260ae602052604090912080546001600160a01b0319166001600160a01b03909216919091179055565b600081815260986020908152604080832060a190925282205463ffffffff1682611e448561186f565b9050611e5082826156ff565b63ffffffff1695945050505050565b600081815260986020526040902080546003909101546001600160a01b0390911690611e8a90613c52565b6001600160a01b031614611ef1576040516347bc33cb60e11b81526004810182905260606024820152600260648201526121a160f11b608482015260a06044820152600d60a48201526c2737ba103134b21037bbb732b960991b60c482015260e401610cf5565b611efa81613db2565b50565b6040805180820190915260028152611c9b60f21b6020820152819060036000838152609860205260409020600c015460ff166006811115611f4057611f4061527a565b14611f625781816040516347bc33cb60e11b8152600401610cf592919061577f565b611f6d8360016142ee565b505050565b6040805180820190915260028152611c9b60f21b6020820152819060036000838152609860205260409020600c015460ff166006811115611fb557611fb561527a565b14611fd75781816040516347bc33cb60e11b8152600401610cf592919061577f565b611f6d8360006142ee565b6000818152609860205260409020600201546001600160a01b03167384d409eed89f6558fe3646397146232665788bf88114156120875760ab546040516331a9108f60e11b8152600481018490526001600160a01b0390911690636352211e906024015b602060405180830381865afa158015612063573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c599190615762565b60ab546001600160a01b03828116911614156120ce5760ab546040516331a9108f60e11b8152600481018490526001600160a01b0390911690636352211e90602401612046565b919050565b6120fc6120de613c48565b6001600160a01b038316600090815260a86020526040902090613d09565b15610ea25761212a61210c613c48565b6001600160a01b038316600090815260a860205260409020906143c8565b50806001600160a01b0316827f8807f55e9d8f9a1dbe3fb0185a481053b276c0866aa3b92350e4f4fe0e42aebc6116f7613c48565b6000818152609860205260408120610c59906143dd565b600080600083604051806040016040528060038152602001623630b160e91b815250600160068111156121ab576121ab61527a565b6000838152609860205260409020600c015460ff1660068111156121d1576121d161527a565b146121f35781816040516347bc33cb60e11b8152600401610cf59291906158c3565b606560039054906101000a90046001600160a01b03166001600160a01b031663425fad586040518163ffffffff1660e01b8152600401602060405180830381865afa158015612246573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061226a9190615618565b156122875760405162461bcd60e51b8152600401610cf590615633565b600086815260986020526040812060038101549091906122a690613c52565b609e546003840154604051633ef19a9b60e01b815260048101919091526001600160a01b03808416602483015292935060009290911690633ef19a9b906044016040805180830381865afa158015612302573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612326919061590c565b5090508061235b5760405162461bcd60e51b8152602060048201526002602482015261272b60f11b6044820152606401610cf5565b609e546003840154604051631cc672df60e01b81526001600160a01b0390921691631cc672df916123929160040190815260200190565b602060405180830381865afa1580156123af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123d39190615618565b156124135760405162461bcd60e51b815260206004820152601060248201526f13585c9ad95d081a5cc818db1bdcd95960821b6044820152606401610cf5565b61241c89610fce565b1561244e5760405162461bcd60e51b8152602060048201526002602482015261424560f01b6044820152606401610cf5565b6009830180546bffffffffffffffff000000001916600160201b4263ffffffff1690810263ffffffff60401b191691909117600160401b91909102179055600c830180546003919060ff191660018302179055506002830180546001600160a01b0319166001600160a01b038481169190911790915560aa546040516346f0b08b60e11b8152600481018c9052911690638de1611690602401600060405180830381600087803b15801561250157600080fd5b505af1158015612515573d6000803e3d6000fd5b5050505061253461252960655461ffff1690565b600685015490614423565b609e54600385015460405163028ba63960e21b8152929a506125b3926001600160a01b0390921691630a2e98e4916125729160040190815260200190565b602060405180830381865afa15801561258f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125299190615938565b9650868884600501600101546125c99190615955565b6125d39190615955565b955087156125fd576125fd826125e7613f3f565b60058601546001600160a01b031691908b614435565b861561269757609e5460038401546040516332209bcb60e11b81526126979285926001600160a01b03909116916364413796916126409160040190815260200190565b602060405180830381865afa15801561265d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126819190615762565b60058601546001600160a01b031691908a614435565b600583015460018401546040516370a0823160e01b81526001600160a01b03918216600482015260009291909116906370a0823190602401602060405180830381865afa1580156126ec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612710919061596c565b9050861561273b576001840154600585015461273b916001600160a01b03918216918691168a614435565b600584015460018501546040516370a0823160e01b81526001600160a01b03918216600482015260009291909116906370a0823190602401602060405180830381865afa158015612790573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127b4919061596c565b905060006127c28383615955565b90508089146127f85760405162461bcd60e51b8152602060048201526002602482015261155560f21b6044820152606401610cf5565b505050600683015460058401546001600160a01b03908116600090815260a3602090815260408083209387168352929052908120805490919061283c908490615985565b9091555050600683015460058401546001600160a01b0316600090815260a4602052604081208054909190612872908490615985565b909155505082546001600160a01b0316600090815260a06020526040902061289a908a61449c565b506040516001600160a01b038316908a907fde9d3bfa8771df6761c0afac2375c88c70a3aa30478e1bd15363294033b470ed90600090a3604051671c1c9bdd1bd8dbdb60c21b81528890600801604051908190038120908b907f476a21a61ac4a7da250e040733aa10facd2eeee584b2c009d178c3de3d8a12dc90600090a46040516a6d61726b6574706c61636560a81b81528790600b01604051908190038120908b907f476a21a61ac4a7da250e040733aa10facd2eeee584b2c009d178c3de3d8a12dc90600090a450505050509193909250565b600054600a90610100900460ff16158015612992575060005460ff8083169116105b6129ae5760405162461bcd60e51b8152600401610cf59061599d565b6000805461ffff191660ff8316176101001790556129cb826144a8565b6000805461ff001916905560405160ff821681527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15050565b600054610100900460ff1615808015612a315750600054600160ff909116105b80612a4b5750303b158015612a4b575060005460ff166001145b612a675760405162461bcd60e51b8152600401610cf59061599d565b6000805460ff191660011790558015612a8a576000805461ff0019166101001790555b612a93896144d4565b6001600160a01b0386163b612ad35760405162461bcd60e51b81526020600482015260066024820152654c43465f696360d01b6044820152606401610cf5565b60a980546001600160a01b0319166001600160a01b038881169190911790915588163b612b2a5760405162461bcd60e51b81526020600482015260056024820152644d525f696360d81b6044820152606401610cf5565b609e80546001600160a01b0319166001600160a01b038a81169190911790915587163b612b815760405162461bcd60e51b8152602060048201526005602482015264524d5f696360d81b6044820152606401610cf5565b609f80546001600160a01b0319166001600160a01b038981169190911790915585163b612bd85760405162461bcd60e51b8152602060048201526005602482015264434d5f696360d81b6044820152606401610cf5565b60aa80546001600160a01b0319166001600160a01b038781169190911790915584163b612c2f5760405162461bcd60e51b81526020600482015260056024820152644c4d5f696360d81b6044820152606401610cf5565b60ab80546001600160a01b0319166001600160a01b038681169190911790915583163b612c865760405162461bcd60e51b815260206004820152600560248201526445565f696360d81b6044820152606401610cf5565b60ad80546001600160a01b0319166001600160a01b038516179055612caa826144a8565b8015611437576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a1505050505050505050565b6040805180820190915260028152611c9b60f21b6020820152819060036000838152609860205260409020600c015460ff166006811115612d3d57612d3d61527a565b14612d5f5781816040516347bc33cb60e11b8152600401610cf592919061577f565b600083815260986020818152604080842060ac83528185205493909252600b820154905163e4de10d360e01b81528493849373e11884953b18f8ddc55875cbdab71b624779d3bb9363e4de10d393612dca93429260ff9091169163ffffffff90911690600401615689565b606060405180830381865af4158015612de7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e0b91906156bb565b925092509250612e3d866040518060400160405280858152602001848152508386612e369190615985565b600161450c565b505050505050565b600082815260a760205260408120546001600160a01b038381169116148061196757505060a9546001600160a01b03908116911614919050565b6040805180820190915260028152611c9b60f21b6020820152829060036000838152609860205260409020600c015460ff166006811115612ec257612ec261527a565b14612ee45781816040516347bc33cb60e11b8152600401610cf592919061577f565b611d32848460006141c0565b600081815260986020526040812080546001600160a01b03169190819081908190819081908190612f208a611fe2565b600382015460058301546006840154600985015460008f8152609860205260409020949c50929a506001600160a01b0390911698509650600160201b900463ffffffff169450612f6f906143dd565b925080600c0160009054906101000a900460ff16915050919395975091939597565b612f99613e74565b60655461ffff82811691161415612fad5750565b6065805461ffff83811661ffff198316811790935560408051938452911660208301819052917f4810ece076cee6c6042808956f3f65dad1bc72b75181341d7bed810d39deda0f9101612a05565b613003613e74565b60b080546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b606560039054906101000a90046001600160a01b03166001600160a01b031663425fad586040518163ffffffff1660e01b8152600401602060405180830381865afa15801561307e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130a29190615618565b156130bf5760405162461bcd60e51b8152600401610cf590615633565b606560039054906101000a90046001600160a01b03166001600160a01b0316638f6d0f116040518163ffffffff1660e01b8152600401602060405180830381865afa158015613112573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131369190615618565b156131535760405162461bcd60e51b8152600401610cf59061565c565b6040805180820190915260028152611b1b60f21b6020820152829060036000838152609860205260409020600c015460ff1660068111156131965761319661527a565b146131b85781816040516347bc33cb60e11b8152600401610cf592919061577f565b611d328484613f7c565b6000610c59826000613d2b565b606560039054906101000a90046001600160a01b03166001600160a01b031663425fad586040518163ffffffff1660e01b8152600401602060405180830381865afa158015613222573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132469190615618565b156132635760405162461bcd60e51b8152600401610cf590615633565b606560039054906101000a90046001600160a01b03166001600160a01b0316638f6d0f116040518163ffffffff1660e01b8152600401602060405180830381865afa1580156132b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132da9190615618565b156132f75760405162461bcd60e51b8152600401610cf59061565c565b604080518082019091526003808252626c636360e81b60208301528291906000838152609860205260409020600c015460ff16600681111561333b5761333b61527a565b1461335d5781816040516347bc33cb60e11b8152600401610cf592919061577f565b60008381526098602052604081209061337585611fe2565b9050611cba8582613a90565b613389613e74565b6001600160a01b0381166133ee5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610cf5565b611efa81613eed565b60606000611967836147cc565b60008061341089613c52565b609e5460405163066e751360e01b8152600481018c90526001600160a01b0380841660248301529293506000929091169063066e7513906044016040805180830381865afa158015613466573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061348a919061590c565b509050806134c85760405162461bcd60e51b815260206004820152600b60248201526a2137b93937bbb2b910272b60a91b6044820152606401610cf5565b609e54604051639f33da3f60e01b8152600481018c90526001600160a01b0390911690639f33da3f90602401602060405180830381865afa158015613511573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135359190615618565b6135695760405162461bcd60e51b81526020600482015260056024820152644d6b74204360d81b6044820152606401610cf5565b609754600081815260986020526040902080546001600160a01b0319166001600160a01b038581169190911782559194509085166135b15780546001600160a01b03166135b3565b845b6001820180546001600160a01b03199081166001600160a01b0393841617909155600383018d90556005830180549091168e8316179055600682018b90556009820180546fffffffff0000000000000000ffffffff1916600160601b63ffffffff8d81169190910263ffffffff1916919091174291909116179055609e5460405163a5630f1960e01b8152600481018e905291169063a5630f19906024016040805180830381865afa15801561366d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061369191906159f8565b609754600090815260ac602052604081208054600b86019291849160ff1916600183818111156136c3576136c361527a565b021790555081546101009190910a63ffffffff8181021990921694909116029290921790915550600b8101805465ffff000000001916600160201b61ffff8b1602179055609e546040516311bed5bb60e01b8152600481018d90526001600160a01b03909116906311bed5bb90602401602060405180830381865afa158015613750573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137749190615808565b609754600090815260a1602052604090819020805463ffffffff191663ffffffff9390931692909217909155609e54905163082fc54d60e01b8152600481018d90526001600160a01b039091169063082fc54d90602401602060405180830381865afa1580156137e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061380c9190615808565b609754600090815260a2602052604090819020805463ffffffff191663ffffffff9390931692909217909155609e54905163d6e794dd60e01b8152600481018d90526001600160a01b039091169063d6e794dd90602401602060405180830381865afa158015613880573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138a49190615a27565b600c8201805461ff0019166101008360018111156138c4576138c461527a565b021790555073e11884953b18f8ddc55875cbdab71b624779d3bb628945b582600c0160019054906101000a900460ff1660ac6000609754815260200190815260200160002060009054906101000a900460ff168d8d86600a0160010160009054906101000a900463ffffffff168e6040518763ffffffff1660e01b815260040161395396959493929190615a44565b602060405180830381865af4158015613970573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613994919061596c565b600a820155609754600090815260a6602052604090206139b5908888614f0c565b50600c8101805460ff191660011790556040516139d89088908890602001615a90565b60408051808303601f19018152908290528051602091820120835460975460018601546001600160a01b0390811686529294929091169290917ff887b1f393f43fb94c5d50483df4bd410ffbf286128c5f24ff56c580ac7f731c910160405180910390a480546001600160a01b03166000908152609960209081526040822060978054825460018101845592855292842090910191909155805491613a7c83615aa0565b919050555050505098975050505050505050565b604080518082019091526003808252626c636360e81b60208301528391906000838152609860205260409020600c015460ff166006811115613ad457613ad461527a565b14613af65781816040516347bc33cb60e11b8152600401610cf592919061577f565b613aff846131c2565b613b305760405162461bcd60e51b8152602060048201526002602482015261139160f21b6044820152606401610cf5565b6000848152609860205260408120600c8101805460ff191660061790556003810154909190613b5e90613c52565b9050613b6986611fe2565b6001600160a01b0316816001600160a01b031614613baf5760405162461bcd60e51b815260206004820152600360248201526213931360ea1b6044820152606401610cf5565b60aa5460405163068eb88b60e51b8152600481018890526001600160a01b0387811660248301529091169063d1d7116090604401600060405180830381600087803b158015613bfd57600080fd5b505af1158015613c11573d6000803e3d6000fd5b50506040518892507f50d3f9b87161fe68d44f1df9c50ec05198e280f710299688dccdd0dea547266c9150600090a2505050505050565b600061198c614826565b600060143610801590613c6c5750613c6c82610b71613c48565b15613d015760131936013560601c613ca98160a86000613c8a613c48565b6001600160a01b03168152602081019190915260400160002090613d09565b610c595760405162461bcd60e51b8152602060048201526024808201527f53656e646572206d75737420617070726f7665206d61726b657420666f727761604482015263393232b960e11b6064820152608401610cf5565b610c59613c48565b6001600160a01b03811660009081526001830160205260408120541515611967565b60008281526098602052604081206003600c82015460ff166006811115613d5457613d5461527a565b14613d63576000915050610c59565b600084815260a1602052604081205463ffffffff1690613d828661186f565b905084613d8f83836156ff565b613d9991906156ff565b63ffffffff164263ffffffff1611935050505092915050565b60408051808201909152600281526131b160f11b6020820152819060016000838152609860205260409020600c015460ff166006811115613df557613df561527a565b14613e175781816040516347bc33cb60e11b8152600401610cf59291906158c3565b600083815260986020526040808220600c01805460ff191660021790555184917fa0633b09ac3029a6746aa27d4db1407f5f287a10c41a6b2ad2859f4da9b2680b91a2505050565b6000611967836001600160a01b03841661486b565b613e7c613c48565b6001600160a01b0316613e976033546001600160a01b031690565b6001600160a01b0316146119805760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610cf5565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60b05460009061010090046001600160a01b0316613f6757506033546001600160a01b031690565b5060b05461010090046001600160a01b031690565b6040805180820190915260028152611b1b60f21b6020820152829060036000838152609860205260409020600c015460ff166006811115613fbf57613fbf61527a565b14613fe15781816040516347bc33cb60e11b8152600401610cf592919061577f565b613fea846114eb565b61401b5760405162461bcd60e51b8152602060048201526002602482015261139360f21b6044820152606401610cf5565b6000848152609860208181526040808420600c8101805460ff1916600517905560ac83528185205493909252600b820154905163e4de10d360e01b8152919392839273e11884953b18f8ddc55875cbdab71b624779d3bb9263e4de10d392614096928892429260ff169163ffffffff90911690600401615689565b606060405180830381865af41580156140b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140d791906156bb565b92505091506141088760405180604001604052808581526020018481525083856141019190615985565b600061450c565b60aa5460405163f0472c4960e01b8152600481018990526001600160a01b0388811660248301529091169063f0472c4990604401600060405180830381600087803b15801561415657600080fd5b505af115801561416a573d6000803e3d6000fd5b50505050600061417d8460030154613c52565b9050806001600160a01b0316887f73de9acc561f27528ab0a3b5dd63fefb4e59f95575891299a6f862a78779817660405160405180910390a35050505050505050565b600083815260986020818152604080842060ac83528185205493909252600b820154905163e4de10d360e01b81528493849373e11884953b18f8ddc55875cbdab71b624779d3bb9363e4de10d39361422b93429260ff9091169163ffffffff90911690600401615689565b606060405180830381865af4158015614248573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061426c91906156bb565b91945092509050600061427f8284615985565b9050808610156142b25760405162dd9d0f60e61b8152600481018890526024810187905260448101829052606401610cf5565b6142e5876040518060400160405280858a6142cd9190615955565b81526020018590526142df8588615985565b8861450c565b50505050505050565b600082815260986020818152604080842060ac83528185205493909252600b820154905163e4de10d360e01b8152849373e11884953b18f8ddc55875cbdab71b624779d3bb9363e4de10d393614357939192429260ff9091169163ffffffff1690600401615689565b606060405180830381865af4158015614374573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061439891906156bb565b9250509150611d328460405180604001604052808581526020018481525083856143c29190615985565b8661450c565b6000611967836001600160a01b0384166148ba565b6009810154600090600160401b900463ffffffff161561440e576009820154600160401b900463ffffffff16610c59565b5060090154600160201b900463ffffffff1690565b6000611967838361ffff1660026149ad565b6040516001600160a01b038481166024830152838116604483015260648201839052611d329186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050506149cc565b6000611967838361486b565b606580546001600160a01b039092166301000000026301000000600160b81b0319909216919091179055565b600054610100900460ff166144fb5760405162461bcd60e51b8152600401610cf590615abb565b614503614a3d565b611efa81614a6c565b6000848152609860209081526040822090850151855191929161452f9190615985565b609f54835460405163c7312e4760e01b81526001600160a01b039182166004820152602481018a905292935060009291169063c7312e47906044016020604051808303816000875af1158015614589573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145ad9190615b06565b90508482106146a2578491506005600c84015460ff1660068111156145d4576145d461527a565b146145e957600c8301805460ff191660041790555b82546001600160a01b0316600090815260a06020526040902061460c9088614a9c565b5083156146725760aa54604051632e1a7d4d60e01b8152600481018990526001600160a01b0390911690632e1a7d4d90602401600060405180830381600087803b15801561465957600080fd5b505af115801561466d573d6000803e3d6000fd5b505050505b60405187907f9a7851747cd7ffb3fe0a32caf3da48b31f27cebe131267051640f8b72fc4718690600090a26146ce565b60405187907f68ca97895fe2d09eab47e752271728ade667e72dda27e68c20eaa191a9c2187d90600090a25b85516007840180546000906146e4908490615985565b90915550506020860151600884018054600090614702908490615985565b909155505060098301805463ffffffff60401b1916600160401b4263ffffffff16021790556147318787614aa8565b60008160028111156147455761474561527a565b146142e557609f54835460405163c7312e4760e01b81526001600160a01b039182166004820152602481018a905291169063c7312e47906044016020604051808303816000875af115801561479e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906147c29190615b06565b5050505050505050565b6060816000018054806020026020016040519081016040528092919081815260200182805480156114df57602002820191906000526020600020908154815260200190600101908083116114cb5750505050509050919050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316331415614866575060131936013560601c90565b503390565b60008181526001830160205260408120546148b257508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610c59565b506000610c59565b600081815260018301602052604081205480156149a35760006148de600183615955565b85549091506000906148f290600190615955565b905081811461495757600086600001828154811061491257614912615b23565b906000526020600020015490508087600001848154811061493557614935615b23565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061496857614968615b39565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610c59565b6000915050610c59565b60006149b882614c46565b6149c28486615b4f565b6114779190615b6e565b600080602060008451602086016000885af1806149ef576040513d6000823e3d81fd5b50506000513d91508115614a07578060011415614a14565b6001600160a01b0384163b155b15611d3257604051635274afe760e01b81526001600160a01b0385166004820152602401610cf5565b600054610100900460ff16614a645760405162461bcd60e51b8152600401610cf590615abb565b611980614c5e565b600054610100900460ff16614a935760405162461bcd60e51b8152600401610cf590615abb565b611efa81612f91565b600061196783836148ba565b600082815260986020526040812090614ac084611fe2565b9050600083602001518460000151614ad89190615985565b60058401546003850154919250600091614b06916001600160a01b031690614aff90613c52565b8585614c95565b905080614bcc576000614b1c8560030154613c52565b6005860154909150614b39906001600160a01b0316823086614435565b60ad546005860154614b58916001600160a01b03918216911685614d45565b60ad546005860154604051638340f54960e01b81526001600160a01b038781166004830152918216602482015260448101869052911690638340f54990606401600060405180830381600087803b158015614bb257600080fd5b505af1158015614bc6573d6000803e3d6000fd5b50505050505b600086815260ae60205260409020546001600160a01b031680156142e557620138805a1015614c265760405162461bcd60e51b81526020600482015260066024820152654e522067617360d01b6044820152606401610cf5565b60006114378289614c3a8960030154613c52565b8a5160208c0151614dd5565b6000614c5382600a615c74565b610c59906064615b4f565b600054610100900460ff16614c855760405162461bcd60e51b8152600401610cf590615abb565b611980614c90613c48565b613eed565b6040516001600160a01b038085166024830152831660448201526064810182905260009081908190614d12908890620186a09084906103e8906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614e32565b915091506000600190506020825110614d2f575060208101516001145b828015614d395750805b98975050505050505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b179052614d968482614ebd565b611d32576040516001600160a01b03848116602483015260006044830152614dcb91869182169063095ea7b39060640161446a565b611d3284826149cc565b6000806000614e25886201388060006103e863913ff9a960e01b8c8c8c8c604051602401614cdb94939291909384526001600160a01b039290921660208401526040830152606082015260800190565b5098975050505050505050565b6000606060008060008661ffff1667ffffffffffffffff811115614e5857614e58615c80565b6040519080825280601f01601f191660200182016040528015614e82576020820181803683370190505b5090506000808751602089018b8e8ef191503d925086831115614ea3578692505b828152826000602083013e90999098509650505050505050565b6000806000806020600086516020880160008a5af192503d91506000519050828015614f0257508115614ef35780600114614f02565b6000866001600160a01b03163b115b9695505050505050565b828054614f1890615727565b90600052602060002090601f016020900481019282614f3a5760008555614f80565b82601f10614f535782800160ff19823516178555614f80565b82800160010185558215614f80579182015b82811115614f80578235825591602001919060010190614f65565b50614f8c929150614f90565b5090565b5b80821115614f8c5760008155600101614f91565b6001600160a01b0381168114611efa57600080fd5b600060208284031215614fcc57600080fd5b813561196781614fa5565b6020808252825182820181905260009190848201906040850190845b8181101561500f57835183529284019291840191600101614ff3565b50909695505050505050565b63ffffffff81168114611efa57600080fd5b61ffff81168114611efa57600080fd5b60008083601f84011261504f57600080fd5b50813567ffffffffffffffff81111561506757600080fd5b60208301915083602082850101111561507f57600080fd5b9250929050565b60008060008060008060008060e0898b0312156150a257600080fd5b88356150ad81614fa5565b9750602089013596506040890135955060608901356150cb8161501b565b945060808901356150db8161502d565b935060a089013567ffffffffffffffff8111156150f757600080fd5b6151038b828c0161503d565b90945092505060c089013561511781614fa5565b809150509295985092959890939650565b6000806040838503121561513b57600080fd5b823561514681614fa5565b9150602083013561515681614fa5565b809150509250929050565b60006020828403121561517357600080fd5b5035919050565b6000806040838503121561518d57600080fd5b82359150602083013561515681614fa5565b600080604083850312156151b257600080fd5b50508035926020909101359150565b815181526020808301519082015260408101610c59565b6000815180845260005b818110156151fe576020818501810151868301820152016151e2565b81811115615210576000602083870101525b50601f01601f19169290920160200192915050565b60208152600061196760208301846151d8565b60008060006060848603121561524d57600080fd5b83359250602084013561525f81614fa5565b9150604084013561526f81614fa5565b809150509250925092565b634e487b7160e01b600052602160045260246000fd5b60028110611efa57611efa61527a565b602081016152ad83615290565b91905290565b600080604083850312156152c657600080fd5b82356152d181614fa5565b946020939093013593505050565b600781106152ef576152ef61527a565b9052565b6152ef81615290565b60006102408201905060018060a01b03808c168352808b166020840152808a1660408401528860608401528760808401528087511660a084015250602086015160c0830152604086015161535d60e084018280518252602090810151910152565b50606086015163ffffffff9081166101208401526080870151811661014084015260a08701511661016083015260c08601516153a261018084018263ffffffff169052565b5084516101a0830152602085015163ffffffff166101c0830152604085015161ffff166101e08301526153d96102008301856152df565b6153e76102208301846152f3565b9a9950505050505050505050565b6000806000806000806000806000806101008b8d03121561541557600080fd5b8a3561542081614fa5565b995060208b0135985060408b0135975060608b013561543e8161501b565b965060808b013561544e8161502d565b955060a08b013567ffffffffffffffff8082111561546b57600080fd5b6154778e838f0161503d565b909750955060c08d0135915061548c82614fa5565b90935060e08c013590808211156154a257600080fd5b818d0191508d601f8301126154b657600080fd5b8135818111156154c557600080fd5b8e60208260071b85010111156154da57600080fd5b6020830194508093505050509295989b9194979a5092959850565b60208101610c5982846152df565b600080600080600080600080610100898b03121561552057600080fd5b883561552b8161502d565b9750602089013561553b81614fa5565b9650604089013561554b81614fa5565b9550606089013561555b81614fa5565b9450608089013561556b81614fa5565b935060a089013561557b81614fa5565b925060c089013561558b81614fa5565b915060e089013561511781614fa5565b6001600160a01b038981168252888116602083015260408201889052861660608201526080810185905263ffffffff84811660a0830152831660c08201526101008101610d0e60e08301846152df565b6000602082840312156155fd57600080fd5b81356119678161502d565b805180151581146120ce57600080fd5b60006020828403121561562a57600080fd5b61196782615608565b6020808252600f908201526e141c9bdd1bd8dbdb081c185d5cd959608a1b604082015260600190565b602080825260139082015272131a5c5d5a59185d1a5bdb9cc81c185d5cd959606a1b604082015260600190565b84815260208101849052608081016156a084615290565b83604083015263ffffffff8316606083015295945050505050565b6000806000606084860312156156d057600080fd5b8351925060208401519150604084015190509250925092565b634e487b7160e01b600052601160045260246000fd5b600063ffffffff80831681851680830382111561571e5761571e6156e9565b01949350505050565b600181811c9082168061573b57607f821691505b6020821081141561575c57634e487b7160e01b600052602260045260246000fd5b50919050565b60006020828403121561577457600080fd5b815161196781614fa5565b82815260606020820152600061579860608301846151d8565b8281036040938401526011815270131bd85b881b9bdd081858d8d95c1d1959607a1b6020820152919091019392505050565b63ffffffff8681168252858116602083015284811660408301528316606082015260a081016157f883615290565b8260808301529695505050505050565b60006020828403121561581a57600080fd5b81516119678161501b565b60038110611efa57600080fd5b838152604060208083018290528282018490526000919060609081850187855b888110156158b457813561586581615825565b600381106158755761587561527a565b8352818401358484015285820135868401528482013561589481614fa5565b6001600160a01b0316838601526080928301929190910190600101615852565b50909998505050505050505050565b8281526060602082015260006158dc60608301846151d8565b828103604093840152600f81526e426964206e6f742070656e64696e6760881b6020820152919091019392505050565b6000806040838503121561591f57600080fd5b61592883615608565b9150602083015190509250929050565b60006020828403121561594a57600080fd5b81516119678161502d565b600082821015615967576159676156e9565b500390565b60006020828403121561597e57600080fd5b5051919050565b60008219821115615998576159986156e9565b500190565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b60028110611efa57600080fd5b60008060408385031215615a0b57600080fd5b8251615a168161501b565b6020840151909250615156816159eb565b600060208284031215615a3957600080fd5b8151611967816159eb565b60c08101615a5188615290565b878252615a5d87615290565b6020820196909652604081019490945263ffffffff92831660608501529116608083015261ffff1660a090910152919050565b8183823760009101908152919050565b6000600019821415615ab457615ab46156e9565b5060010190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b600060208284031215615b1857600080fd5b815161196781615825565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b6000816000190483118215151615615b6957615b696156e9565b500290565b600082615b8b57634e487b7160e01b600052601260045260246000fd5b500490565b600181815b80851115615bcb578160001904821115615bb157615bb16156e9565b80851615615bbe57918102915b93841c9390800290615b95565b509250929050565b600082615be257506001610c59565b81615bef57506000610c59565b8160018114615c055760028114615c0f57615c2b565b6001915050610c59565b60ff841115615c2057615c206156e9565b50506001821b610c59565b5060208310610133831016604e8410600b8410161715615c4e575081810a610c59565b615c588383615b90565b8060001904821115615c6c57615c6c6156e9565b029392505050565b60006119678383615bd3565b634e487b7160e01b600052604160045260246000fdfea2646970667358221220046839d5d2923a0d2456e0b2d0d31e10d4d3220da4e1527215bf35828b4adaf764736f6c634300080b00330000000000000000000000005d3ecf8877edab28e14bd7d243fa8b0fe416e95e
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106104285760003560e01c806372c8fc0e1161022b578063b0e21e8a11610130578063dfca684e116100b8578063e7094fc711610087578063e7094fc714610bd6578063e8cbab0914610be9578063ecb96fe614610bfc578063f24df81014610c0f578063f2fde38b14610c2257600080fd5b8063dfca684e14610b76578063e0d3d58d14610b89578063e4467f3514610bb0578063e521cb9214610bc357600080fd5b8063c8d3b669116100ff578063c8d3b66914610b01578063c953132514610b14578063d08e4e6d14610b27578063d4eda4cf14610b50578063d87569cc14610b6357600080fd5b8063b0e21e8a14610a9c578063ba6d5b1514610ab2578063ba97120614610ac5578063bf77ffae14610ace57600080fd5b806396cf40b6116101b35780639d72d50c116101825780639d72d50c14610a22578063a10905ea14610a35578063a3b678ae14610a48578063a51e2bad14610a5b578063a8cb5d6814610a6e57600080fd5b806396cf40b6146109c05780639703ef35146109d35780639a11e339146109e65780639b0dbab1146109f957600080fd5b80638a700b53116101fa5780638a700b53146109605780638ac47319146109735780638da5cb5b1461097c5780638fa40d891461098d578063930fbae1146109a057600080fd5b806372c8fc0e1461091f5780637bbd53d7146109275780638288da8a1461093a5780638a2ae60b1461094d57600080fd5b80632519dc79116103315780634a06f6ea116102b95780636aedfe68116102885780636aedfe68146108b85780636b76c085146108cb5780636b868afb146108f1578063706a43c314610904578063715018a61461091757600080fd5b80634a06f6ea1461084b5780635426adf01461085e57806354fd4d501461086f578063572b6c051461087857600080fd5b80633819bcdc116103005780633819bcdc146106b65780633ef0a2f7146106c957806340910c70146106f25780634148f94c146107155780634423c5f11461072f57600080fd5b80632519dc791461063b5780632e9332d41461065b578063352f43001461066e578063367358911461068657600080fd5b80631420a266116103b45780631c960764116103835780631c960764146105e55780631d123633146105ef5780631fff59d914610602578063206c54c71461061557806323be345c1461062857600080fd5b80631420a26614610568578063145730331461057b57806318520f05146105bf57806319b353de146105d257600080fd5b80630da89593116103fb5780630da89593146104c55780631042b85f146104da57806310618223146104fa5780631253c5461461050d578063127caa881461052d57600080fd5b8063054de0ff1461042d57806306f33a9214610456578063089487b514610477578063093f5617146104a2575b600080fd5b61044061043b366004614fba565b610c35565b60405161044d9190614fd7565b60405180910390f35b610469610464366004615086565b610c5f565b60405190815260200161044d565b610469610485366004615128565b60a360209081526000928352604080842090915290825290205481565b6104b56104b0366004615161565b610d1b565b604051901515815260200161044d565b6104d86104d336600461517a565b610d70565b005b6104ed6104e836600461519f565b610ea6565b60405161044d91906151c1565b6104b5610508366004615161565b610fce565b61052061051b366004615161565b611064565b60405161044d9190615225565b61055361053b366004615161565b60a26020526000908152604090205463ffffffff1681565b60405163ffffffff909116815260200161044d565b6104d861057636600461517a565b6110fe565b6105a7610589366004615161565b6000908152609860205260409020600501546001600160a01b031690565b6040516001600160a01b03909116815260200161044d565b6104d86105cd366004615161565b611246565b6104b56105e0366004615238565b611442565b6105536201518081565b6104406105fd366004614fba565b61147f565b6104b5610610366004615161565b6114eb565b6104d8610623366004615161565b6114fa565b60aa546105a7906001600160a01b031681565b610469610649366004614fba565b60a46020526000908152604090205481565b6104d861066936600461517a565b611633565b606554630100000090046001600160a01b03166105a7565b6106a9610694366004615161565b60ac6020526000908152604090205460ff1681565b60405161044d91906152a0565b6104696106c43660046152b3565b611716565b6105a76106d7366004615161565b6000908152609860205260409020546001600160a01b031690565b610469610700366004615161565b60009081526098602052604090206003015490565b61071d600a81565b60405160ff909116815260200161044d565b61083661073d366004615161565b60986020908152600091825260409182902080546001820154600283015460038401546004850154875160e08101895260058701546001600160a01b0390811682526006880154828a01528951808b018b52600789015481526008890154818b0152828b0152600988015463ffffffff808216606080860191909152600160201b80840483166080870152600160401b8404831660a0870152600160601b909304821660c08601528c519081018d52600a8b01548152600b8b01549182169b81019b909b520461ffff1699890199909952600c909601549488169793841696939092169490939192909160ff8082169161010090041689565b60405161044d999897969594939291906152fc565b60ab546105a7906001600160a01b031681565b60ad546001600160a01b03166105a7565b61046960a55481565b6104b5610886366004614fba565b7f0000000000000000000000005d3ecf8877edab28e14bd7d243fa8b0fe416e95e6001600160a01b0390811691161490565b6104ed6108c636600461519f565b611747565b6105536108d9366004615161565b60a16020526000908152604090205463ffffffff1681565b609f546105a7906001600160a01b031681565b610553610912366004615161565b61186f565b6104d861196e565b6105a7611982565b6104696109353660046153f5565b611991565b6104d8610948366004615161565b611b02565b60ad546105a7906001600160a01b031681565b6104d861096e36600461519f565b611cc1565b61046960975481565b6033546001600160a01b03166105a7565b6104d861099b36600461517a565b611d38565b6104696109ae366004614fba565b609a6020526000908152604090205481565b6104696109ce366004615161565b611e1b565b6104d86109e1366004615161565b611e5f565b6104d86109f4366004615161565b611efd565b6105a7610a07366004615161565b600090815260ae60205260409020546001600160a01b031690565b6104d8610a30366004615161565b611f72565b6105a7610a43366004615161565b611fe2565b6104d8610a5636600461517a565b6120d3565b610553610a69366004615161565b61215f565b610a81610a7c366004615161565b612176565b6040805193845260208401929092529082015260600161044d565b60655460405161ffff909116815260200161044d565b60a9546105a7906001600160a01b031681565b610469609b5481565b610af4610adc366004615161565b6000908152609860205260409020600c015460ff1690565b60405161044d91906154f5565b6104d8610b0f366004614fba565b612970565b6104d8610b22366004615503565b612a11565b6105a7610b35366004615161565b60ae602052600090815260409020546001600160a01b031681565b6104d8610b5e366004615161565b612cfa565b6104b5610b7136600461517a565b612e45565b6104d8610b8436600461519f565b612e7f565b610b9c610b97366004615161565b612ef0565b60405161044d98979695949392919061559b565b6104d8610bbe3660046155eb565b612f91565b6104d8610bd1366004614fba565b612ffb565b6104d8610be436600461517a565b61302b565b6104b5610bf7366004615161565b6131c2565b609e546105a7906001600160a01b031681565b6104d8610c1d366004615161565b6131cf565b6104d8610c30366004614fba565b613381565b6001600160a01b038116600090815260a060205260409020606090610c59906133f7565b92915050565b6000606560039054906101000a90046001600160a01b03166001600160a01b031663425fad586040518163ffffffff1660e01b8152600401602060405180830381865afa158015610cb4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cd89190615618565b15610cfe5760405162461bcd60e51b8152600401610cf590615633565b60405180910390fd5b610d0e8989898989898989613404565b9998505050505050505050565b600060036000838152609860205260409020600c015460ff166006811115610d4557610d4561527a565b14610d5257506000919050565b610d5b8261186f565b63ffffffff164263ffffffff16119050919050565b606560039054906101000a90046001600160a01b03166001600160a01b031663425fad586040518163ffffffff1660e01b8152600401602060405180830381865afa158015610dc3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610de79190615618565b15610e045760405162461bcd60e51b8152600401610cf590615633565b606560039054906101000a90046001600160a01b03166001600160a01b0316638f6d0f116040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e7b9190615618565b15610e985760405162461bcd60e51b8152600401610cf59061565c565b610ea28282613a90565b5050565b604080518082019091526000808252602082015260008381526098602052604090206003600c82015460ff166006811115610ee357610ee361527a565b141580610f0157506009810154600160201b900463ffffffff168311155b15610f0c5750610c59565b60008073e11884953b18f8ddc55875cbdab71b624779d3bb63e4de10d38487610f448a600090815260ac602052604090205460ff1690565b60008b8152609860205260409020600b015463ffffffff166040518563ffffffff1660e01b8152600401610f7b9493929190615689565b606060405180830381865af4158015610f98573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fbc91906156bb565b91865250602085015250505092915050565b60008181526098602052604081206001600c82015460ff166006811115610ff757610ff761527a565b146110055750600092915050565b600083815260a2602052604090205463ffffffff166110275750600092915050565b600083815260a26020526040902054600982015461104e9163ffffffff90811691166156ff565b63ffffffff164263ffffffff1611915050919050565b60a6602052600090815260409020805461107d90615727565b80601f01602080910402602001604051908101604052809291908181526020018280546110a990615727565b80156110f65780601f106110cb576101008083540402835291602001916110f6565b820191906000526020600020905b8154815290600101906020018083116110d957829003601f168201915b505050505081565b611106613c48565b609e54604051633d36902960e01b8152600481018590526001600160a01b039283169290911690633d36902990602401602060405180830381865afa158015611153573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111779190615762565b6001600160a01b0316146111cd5760405162461bcd60e51b815260206004820152601f60248201527f43616c6c6572206d75737420626520746865206d61726b6574206f776e6572006044820152606401610cf5565b600082815260a76020526040902080546001600160a01b0319166001600160a01b038316179055817fa593acf9edc343669c7fc50d2caa3911326adef438361f0fa911be85c9e296a48261121f613c48565b604080516001600160a01b0393841681529290911660208301520160405180910390a25050565b6040805180820190915260038082526231b63760e91b60208301528291906000838152609860205260409020600c015460ff16600681111561128a5761128a61527a565b146112ac5781816040516347bc33cb60e11b8152600401610cf592919061577f565b606560039054906101000a90046001600160a01b03166001600160a01b031663425fad586040518163ffffffff1660e01b8152600401602060405180830381865afa1580156112ff573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113239190615618565b156113405760405162461bcd60e51b8152600401610cf590615633565b6000838152609860205260408120600381015490919061135f90613c52565b60028301549091506001600160a01b038083169116146113ad5760405162461bcd60e51b8152602060048201526009602482015268272b102632b73232b960b91b6044820152606401610cf5565b6002820180546001600160a01b0319167384d409eed89f6558fe3646397146232665788bf817905560ab5460405163096c998360e41b8152600481018790526001600160a01b038381166024830152909116906396c9983090604401600060405180830381600087803b15801561142357600080fd5b505af1158015611437573d6000803e3d6000fd5b505050505050505050565b600061144e8484612e45565b801561147757506001600160a01b038316600090815260a8602052604090206114779083613d09565b949350505050565b6001600160a01b0381166000908152609960209081526040918290208054835181840281018401909452808452606093928301828280156114df57602002820191906000526020600020905b8154815260200190600101908083116114cb575b50505050509050919050565b6000610c598262015180613d2b565b609e5460008281526098602052604090819020600301549051633d36902960e01b81526001600160a01b0390921691633d3690299161153f9160040190815260200190565b602060405180830381865afa15801561155c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115809190615762565b6001600160a01b0316611591613c48565b6001600160a01b0316146115fc576040516347bc33cb60e11b815260048082018390526060602483015260648201526326a7a1a160e11b608482015260a06044820152601060a48201526f2737ba1036b0b935b2ba1037bbb732b960811b60c482015260e401610cf5565b61160581613db2565b60405181907ff3f271d754f5264e0d143bf9be577d6eba153b0d833bd3a127d7b1a280bb13f190600090a250565b61163d8282612e45565b6116995760405162461bcd60e51b815260206004820152602760248201527f466f72776172646572206d757374206265207472757374656420627920746865604482015266081b585c9ad95d60ca1b6064820152608401610cf5565b6116c26116a4613c48565b6001600160a01b038316600090815260a86020526040902090613e5f565b50806001600160a01b0316827f65d6b5305e8c0e58e88454a1aeecae0f55975222338b25abd0997b4d305056a16116f7613c48565b6040516001600160a01b03909116815260200160405180910390a35050565b6099602052816000526040600020818154811061173257600080fd5b90600052602060002001600091509150505481565b604080518082018252600080825260208083018290528582526098905291909120600c81015460039060ff1660068111156117845761178461527a565b1415806117a257506009810154600160201b900463ffffffff168311155b156117ad5750610c59565b60008073e11884953b18f8ddc55875cbdab71b624779d3bb63e4de10d384876117e58a600090815260ac602052604090205460ff1690565b60008b8152609860205260409020600b015463ffffffff166040518563ffffffff1660e01b815260040161181c9493929190615689565b606060405180830381865af4158015611839573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061185d91906156bb565b90865260208601525050505092915050565b6000818152609860205260408120600c81015460039060ff1660068111156118995761189961527a565b146118a45750919050565b6009810154600b82015473e11884953b18f8ddc55875cbdab71b624779d3bb91630dcf16589163ffffffff600160201b830481169291811691600160601b9004166118ee8861215f565b600089815260ac6020526040908190205490516001600160e01b031960e088901b168152611926959493929160ff16906004016157ca565b602060405180830381865af4158015611943573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119679190615808565b9392505050565b611976613e74565b6119806000613eed565b565b600061198c613f3f565b905090565b6000606560039054906101000a90046001600160a01b03166001600160a01b031663425fad586040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119e6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a0a9190615618565b15611a275760405162461bcd60e51b8152600401610cf590615633565b611a378b8b8b8b8b8b8b8b613404565b60aa54604051631532dc4560e01b81529192506000916001600160a01b0390911690631532dc4590611a7190859088908890600401615832565b6020604051808303816000875af1158015611a90573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ab49190615618565b9050600181151514611af35760405162461bcd60e51b815260206004820152600860248201526721903130b610272b60c11b6044820152606401610cf5565b509a9950505050505050505050565b606560039054906101000a90046001600160a01b03166001600160a01b031663425fad586040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b55573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b799190615618565b15611b965760405162461bcd60e51b8152600401610cf590615633565b606560039054906101000a90046001600160a01b03166001600160a01b0316638f6d0f116040518163ffffffff1660e01b8152600401602060405180830381865afa158015611be9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c0d9190615618565b15611c2a5760405162461bcd60e51b8152600401610cf59061565c565b6040805180820190915260028152611b1b60f21b6020820152819060036000838152609860205260409020600c015460ff166006811115611c6d57611c6d61527a565b14611c8f5781816040516347bc33cb60e11b8152600401610cf592919061577f565b60008381526098602052604081206003810154909190611cae90613c52565b9050611cba8582613f7c565b5050505050565b6040805180820190915260028152611c9b60f21b6020820152829060036000838152609860205260409020600c015460ff166006811115611d0457611d0461527a565b14611d265781816040516347bc33cb60e11b8152600401610cf592919061577f565b611d32848460016141c0565b50505050565b803b80611d785760405162461bcd60e51b815260206004820152600e60248201526d139bdd08184818dbdb9d1c9858dd60921b6044820152606401610cf5565b600083815260986020526040812060030154611d9390613c52565b9050611d9e84611fe2565b6001600160a01b0316816001600160a01b031614611deb5760405162461bcd60e51b815260206004820152600a6024820152692737ba103632b73232b960b11b6044820152606401610cf5565b5050600091825260ae602052604090912080546001600160a01b0319166001600160a01b03909216919091179055565b600081815260986020908152604080832060a190925282205463ffffffff1682611e448561186f565b9050611e5082826156ff565b63ffffffff1695945050505050565b600081815260986020526040902080546003909101546001600160a01b0390911690611e8a90613c52565b6001600160a01b031614611ef1576040516347bc33cb60e11b81526004810182905260606024820152600260648201526121a160f11b608482015260a06044820152600d60a48201526c2737ba103134b21037bbb732b960991b60c482015260e401610cf5565b611efa81613db2565b50565b6040805180820190915260028152611c9b60f21b6020820152819060036000838152609860205260409020600c015460ff166006811115611f4057611f4061527a565b14611f625781816040516347bc33cb60e11b8152600401610cf592919061577f565b611f6d8360016142ee565b505050565b6040805180820190915260028152611c9b60f21b6020820152819060036000838152609860205260409020600c015460ff166006811115611fb557611fb561527a565b14611fd75781816040516347bc33cb60e11b8152600401610cf592919061577f565b611f6d8360006142ee565b6000818152609860205260409020600201546001600160a01b03167384d409eed89f6558fe3646397146232665788bf88114156120875760ab546040516331a9108f60e11b8152600481018490526001600160a01b0390911690636352211e906024015b602060405180830381865afa158015612063573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c599190615762565b60ab546001600160a01b03828116911614156120ce5760ab546040516331a9108f60e11b8152600481018490526001600160a01b0390911690636352211e90602401612046565b919050565b6120fc6120de613c48565b6001600160a01b038316600090815260a86020526040902090613d09565b15610ea25761212a61210c613c48565b6001600160a01b038316600090815260a860205260409020906143c8565b50806001600160a01b0316827f8807f55e9d8f9a1dbe3fb0185a481053b276c0866aa3b92350e4f4fe0e42aebc6116f7613c48565b6000818152609860205260408120610c59906143dd565b600080600083604051806040016040528060038152602001623630b160e91b815250600160068111156121ab576121ab61527a565b6000838152609860205260409020600c015460ff1660068111156121d1576121d161527a565b146121f35781816040516347bc33cb60e11b8152600401610cf59291906158c3565b606560039054906101000a90046001600160a01b03166001600160a01b031663425fad586040518163ffffffff1660e01b8152600401602060405180830381865afa158015612246573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061226a9190615618565b156122875760405162461bcd60e51b8152600401610cf590615633565b600086815260986020526040812060038101549091906122a690613c52565b609e546003840154604051633ef19a9b60e01b815260048101919091526001600160a01b03808416602483015292935060009290911690633ef19a9b906044016040805180830381865afa158015612302573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612326919061590c565b5090508061235b5760405162461bcd60e51b8152602060048201526002602482015261272b60f11b6044820152606401610cf5565b609e546003840154604051631cc672df60e01b81526001600160a01b0390921691631cc672df916123929160040190815260200190565b602060405180830381865afa1580156123af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123d39190615618565b156124135760405162461bcd60e51b815260206004820152601060248201526f13585c9ad95d081a5cc818db1bdcd95960821b6044820152606401610cf5565b61241c89610fce565b1561244e5760405162461bcd60e51b8152602060048201526002602482015261424560f01b6044820152606401610cf5565b6009830180546bffffffffffffffff000000001916600160201b4263ffffffff1690810263ffffffff60401b191691909117600160401b91909102179055600c830180546003919060ff191660018302179055506002830180546001600160a01b0319166001600160a01b038481169190911790915560aa546040516346f0b08b60e11b8152600481018c9052911690638de1611690602401600060405180830381600087803b15801561250157600080fd5b505af1158015612515573d6000803e3d6000fd5b5050505061253461252960655461ffff1690565b600685015490614423565b609e54600385015460405163028ba63960e21b8152929a506125b3926001600160a01b0390921691630a2e98e4916125729160040190815260200190565b602060405180830381865afa15801561258f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125299190615938565b9650868884600501600101546125c99190615955565b6125d39190615955565b955087156125fd576125fd826125e7613f3f565b60058601546001600160a01b031691908b614435565b861561269757609e5460038401546040516332209bcb60e11b81526126979285926001600160a01b03909116916364413796916126409160040190815260200190565b602060405180830381865afa15801561265d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126819190615762565b60058601546001600160a01b031691908a614435565b600583015460018401546040516370a0823160e01b81526001600160a01b03918216600482015260009291909116906370a0823190602401602060405180830381865afa1580156126ec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612710919061596c565b9050861561273b576001840154600585015461273b916001600160a01b03918216918691168a614435565b600584015460018501546040516370a0823160e01b81526001600160a01b03918216600482015260009291909116906370a0823190602401602060405180830381865afa158015612790573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127b4919061596c565b905060006127c28383615955565b90508089146127f85760405162461bcd60e51b8152602060048201526002602482015261155560f21b6044820152606401610cf5565b505050600683015460058401546001600160a01b03908116600090815260a3602090815260408083209387168352929052908120805490919061283c908490615985565b9091555050600683015460058401546001600160a01b0316600090815260a4602052604081208054909190612872908490615985565b909155505082546001600160a01b0316600090815260a06020526040902061289a908a61449c565b506040516001600160a01b038316908a907fde9d3bfa8771df6761c0afac2375c88c70a3aa30478e1bd15363294033b470ed90600090a3604051671c1c9bdd1bd8dbdb60c21b81528890600801604051908190038120908b907f476a21a61ac4a7da250e040733aa10facd2eeee584b2c009d178c3de3d8a12dc90600090a46040516a6d61726b6574706c61636560a81b81528790600b01604051908190038120908b907f476a21a61ac4a7da250e040733aa10facd2eeee584b2c009d178c3de3d8a12dc90600090a450505050509193909250565b600054600a90610100900460ff16158015612992575060005460ff8083169116105b6129ae5760405162461bcd60e51b8152600401610cf59061599d565b6000805461ffff191660ff8316176101001790556129cb826144a8565b6000805461ff001916905560405160ff821681527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15050565b600054610100900460ff1615808015612a315750600054600160ff909116105b80612a4b5750303b158015612a4b575060005460ff166001145b612a675760405162461bcd60e51b8152600401610cf59061599d565b6000805460ff191660011790558015612a8a576000805461ff0019166101001790555b612a93896144d4565b6001600160a01b0386163b612ad35760405162461bcd60e51b81526020600482015260066024820152654c43465f696360d01b6044820152606401610cf5565b60a980546001600160a01b0319166001600160a01b038881169190911790915588163b612b2a5760405162461bcd60e51b81526020600482015260056024820152644d525f696360d81b6044820152606401610cf5565b609e80546001600160a01b0319166001600160a01b038a81169190911790915587163b612b815760405162461bcd60e51b8152602060048201526005602482015264524d5f696360d81b6044820152606401610cf5565b609f80546001600160a01b0319166001600160a01b038981169190911790915585163b612bd85760405162461bcd60e51b8152602060048201526005602482015264434d5f696360d81b6044820152606401610cf5565b60aa80546001600160a01b0319166001600160a01b038781169190911790915584163b612c2f5760405162461bcd60e51b81526020600482015260056024820152644c4d5f696360d81b6044820152606401610cf5565b60ab80546001600160a01b0319166001600160a01b038681169190911790915583163b612c865760405162461bcd60e51b815260206004820152600560248201526445565f696360d81b6044820152606401610cf5565b60ad80546001600160a01b0319166001600160a01b038516179055612caa826144a8565b8015611437576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a1505050505050505050565b6040805180820190915260028152611c9b60f21b6020820152819060036000838152609860205260409020600c015460ff166006811115612d3d57612d3d61527a565b14612d5f5781816040516347bc33cb60e11b8152600401610cf592919061577f565b600083815260986020818152604080842060ac83528185205493909252600b820154905163e4de10d360e01b81528493849373e11884953b18f8ddc55875cbdab71b624779d3bb9363e4de10d393612dca93429260ff9091169163ffffffff90911690600401615689565b606060405180830381865af4158015612de7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e0b91906156bb565b925092509250612e3d866040518060400160405280858152602001848152508386612e369190615985565b600161450c565b505050505050565b600082815260a760205260408120546001600160a01b038381169116148061196757505060a9546001600160a01b03908116911614919050565b6040805180820190915260028152611c9b60f21b6020820152829060036000838152609860205260409020600c015460ff166006811115612ec257612ec261527a565b14612ee45781816040516347bc33cb60e11b8152600401610cf592919061577f565b611d32848460006141c0565b600081815260986020526040812080546001600160a01b03169190819081908190819081908190612f208a611fe2565b600382015460058301546006840154600985015460008f8152609860205260409020949c50929a506001600160a01b0390911698509650600160201b900463ffffffff169450612f6f906143dd565b925080600c0160009054906101000a900460ff16915050919395975091939597565b612f99613e74565b60655461ffff82811691161415612fad5750565b6065805461ffff83811661ffff198316811790935560408051938452911660208301819052917f4810ece076cee6c6042808956f3f65dad1bc72b75181341d7bed810d39deda0f9101612a05565b613003613e74565b60b080546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b606560039054906101000a90046001600160a01b03166001600160a01b031663425fad586040518163ffffffff1660e01b8152600401602060405180830381865afa15801561307e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130a29190615618565b156130bf5760405162461bcd60e51b8152600401610cf590615633565b606560039054906101000a90046001600160a01b03166001600160a01b0316638f6d0f116040518163ffffffff1660e01b8152600401602060405180830381865afa158015613112573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131369190615618565b156131535760405162461bcd60e51b8152600401610cf59061565c565b6040805180820190915260028152611b1b60f21b6020820152829060036000838152609860205260409020600c015460ff1660068111156131965761319661527a565b146131b85781816040516347bc33cb60e11b8152600401610cf592919061577f565b611d328484613f7c565b6000610c59826000613d2b565b606560039054906101000a90046001600160a01b03166001600160a01b031663425fad586040518163ffffffff1660e01b8152600401602060405180830381865afa158015613222573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132469190615618565b156132635760405162461bcd60e51b8152600401610cf590615633565b606560039054906101000a90046001600160a01b03166001600160a01b0316638f6d0f116040518163ffffffff1660e01b8152600401602060405180830381865afa1580156132b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132da9190615618565b156132f75760405162461bcd60e51b8152600401610cf59061565c565b604080518082019091526003808252626c636360e81b60208301528291906000838152609860205260409020600c015460ff16600681111561333b5761333b61527a565b1461335d5781816040516347bc33cb60e11b8152600401610cf592919061577f565b60008381526098602052604081209061337585611fe2565b9050611cba8582613a90565b613389613e74565b6001600160a01b0381166133ee5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610cf5565b611efa81613eed565b60606000611967836147cc565b60008061341089613c52565b609e5460405163066e751360e01b8152600481018c90526001600160a01b0380841660248301529293506000929091169063066e7513906044016040805180830381865afa158015613466573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061348a919061590c565b509050806134c85760405162461bcd60e51b815260206004820152600b60248201526a2137b93937bbb2b910272b60a91b6044820152606401610cf5565b609e54604051639f33da3f60e01b8152600481018c90526001600160a01b0390911690639f33da3f90602401602060405180830381865afa158015613511573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135359190615618565b6135695760405162461bcd60e51b81526020600482015260056024820152644d6b74204360d81b6044820152606401610cf5565b609754600081815260986020526040902080546001600160a01b0319166001600160a01b038581169190911782559194509085166135b15780546001600160a01b03166135b3565b845b6001820180546001600160a01b03199081166001600160a01b0393841617909155600383018d90556005830180549091168e8316179055600682018b90556009820180546fffffffff0000000000000000ffffffff1916600160601b63ffffffff8d81169190910263ffffffff1916919091174291909116179055609e5460405163a5630f1960e01b8152600481018e905291169063a5630f19906024016040805180830381865afa15801561366d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061369191906159f8565b609754600090815260ac602052604081208054600b86019291849160ff1916600183818111156136c3576136c361527a565b021790555081546101009190910a63ffffffff8181021990921694909116029290921790915550600b8101805465ffff000000001916600160201b61ffff8b1602179055609e546040516311bed5bb60e01b8152600481018d90526001600160a01b03909116906311bed5bb90602401602060405180830381865afa158015613750573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137749190615808565b609754600090815260a1602052604090819020805463ffffffff191663ffffffff9390931692909217909155609e54905163082fc54d60e01b8152600481018d90526001600160a01b039091169063082fc54d90602401602060405180830381865afa1580156137e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061380c9190615808565b609754600090815260a2602052604090819020805463ffffffff191663ffffffff9390931692909217909155609e54905163d6e794dd60e01b8152600481018d90526001600160a01b039091169063d6e794dd90602401602060405180830381865afa158015613880573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138a49190615a27565b600c8201805461ff0019166101008360018111156138c4576138c461527a565b021790555073e11884953b18f8ddc55875cbdab71b624779d3bb628945b582600c0160019054906101000a900460ff1660ac6000609754815260200190815260200160002060009054906101000a900460ff168d8d86600a0160010160009054906101000a900463ffffffff168e6040518763ffffffff1660e01b815260040161395396959493929190615a44565b602060405180830381865af4158015613970573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613994919061596c565b600a820155609754600090815260a6602052604090206139b5908888614f0c565b50600c8101805460ff191660011790556040516139d89088908890602001615a90565b60408051808303601f19018152908290528051602091820120835460975460018601546001600160a01b0390811686529294929091169290917ff887b1f393f43fb94c5d50483df4bd410ffbf286128c5f24ff56c580ac7f731c910160405180910390a480546001600160a01b03166000908152609960209081526040822060978054825460018101845592855292842090910191909155805491613a7c83615aa0565b919050555050505098975050505050505050565b604080518082019091526003808252626c636360e81b60208301528391906000838152609860205260409020600c015460ff166006811115613ad457613ad461527a565b14613af65781816040516347bc33cb60e11b8152600401610cf592919061577f565b613aff846131c2565b613b305760405162461bcd60e51b8152602060048201526002602482015261139160f21b6044820152606401610cf5565b6000848152609860205260408120600c8101805460ff191660061790556003810154909190613b5e90613c52565b9050613b6986611fe2565b6001600160a01b0316816001600160a01b031614613baf5760405162461bcd60e51b815260206004820152600360248201526213931360ea1b6044820152606401610cf5565b60aa5460405163068eb88b60e51b8152600481018890526001600160a01b0387811660248301529091169063d1d7116090604401600060405180830381600087803b158015613bfd57600080fd5b505af1158015613c11573d6000803e3d6000fd5b50506040518892507f50d3f9b87161fe68d44f1df9c50ec05198e280f710299688dccdd0dea547266c9150600090a2505050505050565b600061198c614826565b600060143610801590613c6c5750613c6c82610b71613c48565b15613d015760131936013560601c613ca98160a86000613c8a613c48565b6001600160a01b03168152602081019190915260400160002090613d09565b610c595760405162461bcd60e51b8152602060048201526024808201527f53656e646572206d75737420617070726f7665206d61726b657420666f727761604482015263393232b960e11b6064820152608401610cf5565b610c59613c48565b6001600160a01b03811660009081526001830160205260408120541515611967565b60008281526098602052604081206003600c82015460ff166006811115613d5457613d5461527a565b14613d63576000915050610c59565b600084815260a1602052604081205463ffffffff1690613d828661186f565b905084613d8f83836156ff565b613d9991906156ff565b63ffffffff164263ffffffff1611935050505092915050565b60408051808201909152600281526131b160f11b6020820152819060016000838152609860205260409020600c015460ff166006811115613df557613df561527a565b14613e175781816040516347bc33cb60e11b8152600401610cf59291906158c3565b600083815260986020526040808220600c01805460ff191660021790555184917fa0633b09ac3029a6746aa27d4db1407f5f287a10c41a6b2ad2859f4da9b2680b91a2505050565b6000611967836001600160a01b03841661486b565b613e7c613c48565b6001600160a01b0316613e976033546001600160a01b031690565b6001600160a01b0316146119805760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610cf5565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60b05460009061010090046001600160a01b0316613f6757506033546001600160a01b031690565b5060b05461010090046001600160a01b031690565b6040805180820190915260028152611b1b60f21b6020820152829060036000838152609860205260409020600c015460ff166006811115613fbf57613fbf61527a565b14613fe15781816040516347bc33cb60e11b8152600401610cf592919061577f565b613fea846114eb565b61401b5760405162461bcd60e51b8152602060048201526002602482015261139360f21b6044820152606401610cf5565b6000848152609860208181526040808420600c8101805460ff1916600517905560ac83528185205493909252600b820154905163e4de10d360e01b8152919392839273e11884953b18f8ddc55875cbdab71b624779d3bb9263e4de10d392614096928892429260ff169163ffffffff90911690600401615689565b606060405180830381865af41580156140b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140d791906156bb565b92505091506141088760405180604001604052808581526020018481525083856141019190615985565b600061450c565b60aa5460405163f0472c4960e01b8152600481018990526001600160a01b0388811660248301529091169063f0472c4990604401600060405180830381600087803b15801561415657600080fd5b505af115801561416a573d6000803e3d6000fd5b50505050600061417d8460030154613c52565b9050806001600160a01b0316887f73de9acc561f27528ab0a3b5dd63fefb4e59f95575891299a6f862a78779817660405160405180910390a35050505050505050565b600083815260986020818152604080842060ac83528185205493909252600b820154905163e4de10d360e01b81528493849373e11884953b18f8ddc55875cbdab71b624779d3bb9363e4de10d39361422b93429260ff9091169163ffffffff90911690600401615689565b606060405180830381865af4158015614248573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061426c91906156bb565b91945092509050600061427f8284615985565b9050808610156142b25760405162dd9d0f60e61b8152600481018890526024810187905260448101829052606401610cf5565b6142e5876040518060400160405280858a6142cd9190615955565b81526020018590526142df8588615985565b8861450c565b50505050505050565b600082815260986020818152604080842060ac83528185205493909252600b820154905163e4de10d360e01b8152849373e11884953b18f8ddc55875cbdab71b624779d3bb9363e4de10d393614357939192429260ff9091169163ffffffff1690600401615689565b606060405180830381865af4158015614374573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061439891906156bb565b9250509150611d328460405180604001604052808581526020018481525083856143c29190615985565b8661450c565b6000611967836001600160a01b0384166148ba565b6009810154600090600160401b900463ffffffff161561440e576009820154600160401b900463ffffffff16610c59565b5060090154600160201b900463ffffffff1690565b6000611967838361ffff1660026149ad565b6040516001600160a01b038481166024830152838116604483015260648201839052611d329186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050506149cc565b6000611967838361486b565b606580546001600160a01b039092166301000000026301000000600160b81b0319909216919091179055565b600054610100900460ff166144fb5760405162461bcd60e51b8152600401610cf590615abb565b614503614a3d565b611efa81614a6c565b6000848152609860209081526040822090850151855191929161452f9190615985565b609f54835460405163c7312e4760e01b81526001600160a01b039182166004820152602481018a905292935060009291169063c7312e47906044016020604051808303816000875af1158015614589573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145ad9190615b06565b90508482106146a2578491506005600c84015460ff1660068111156145d4576145d461527a565b146145e957600c8301805460ff191660041790555b82546001600160a01b0316600090815260a06020526040902061460c9088614a9c565b5083156146725760aa54604051632e1a7d4d60e01b8152600481018990526001600160a01b0390911690632e1a7d4d90602401600060405180830381600087803b15801561465957600080fd5b505af115801561466d573d6000803e3d6000fd5b505050505b60405187907f9a7851747cd7ffb3fe0a32caf3da48b31f27cebe131267051640f8b72fc4718690600090a26146ce565b60405187907f68ca97895fe2d09eab47e752271728ade667e72dda27e68c20eaa191a9c2187d90600090a25b85516007840180546000906146e4908490615985565b90915550506020860151600884018054600090614702908490615985565b909155505060098301805463ffffffff60401b1916600160401b4263ffffffff16021790556147318787614aa8565b60008160028111156147455761474561527a565b146142e557609f54835460405163c7312e4760e01b81526001600160a01b039182166004820152602481018a905291169063c7312e47906044016020604051808303816000875af115801561479e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906147c29190615b06565b5050505050505050565b6060816000018054806020026020016040519081016040528092919081815260200182805480156114df57602002820191906000526020600020908154815260200190600101908083116114cb5750505050509050919050565b60007f0000000000000000000000005d3ecf8877edab28e14bd7d243fa8b0fe416e95e6001600160a01b0316331415614866575060131936013560601c90565b503390565b60008181526001830160205260408120546148b257508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610c59565b506000610c59565b600081815260018301602052604081205480156149a35760006148de600183615955565b85549091506000906148f290600190615955565b905081811461495757600086600001828154811061491257614912615b23565b906000526020600020015490508087600001848154811061493557614935615b23565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061496857614968615b39565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610c59565b6000915050610c59565b60006149b882614c46565b6149c28486615b4f565b6114779190615b6e565b600080602060008451602086016000885af1806149ef576040513d6000823e3d81fd5b50506000513d91508115614a07578060011415614a14565b6001600160a01b0384163b155b15611d3257604051635274afe760e01b81526001600160a01b0385166004820152602401610cf5565b600054610100900460ff16614a645760405162461bcd60e51b8152600401610cf590615abb565b611980614c5e565b600054610100900460ff16614a935760405162461bcd60e51b8152600401610cf590615abb565b611efa81612f91565b600061196783836148ba565b600082815260986020526040812090614ac084611fe2565b9050600083602001518460000151614ad89190615985565b60058401546003850154919250600091614b06916001600160a01b031690614aff90613c52565b8585614c95565b905080614bcc576000614b1c8560030154613c52565b6005860154909150614b39906001600160a01b0316823086614435565b60ad546005860154614b58916001600160a01b03918216911685614d45565b60ad546005860154604051638340f54960e01b81526001600160a01b038781166004830152918216602482015260448101869052911690638340f54990606401600060405180830381600087803b158015614bb257600080fd5b505af1158015614bc6573d6000803e3d6000fd5b50505050505b600086815260ae60205260409020546001600160a01b031680156142e557620138805a1015614c265760405162461bcd60e51b81526020600482015260066024820152654e522067617360d01b6044820152606401610cf5565b60006114378289614c3a8960030154613c52565b8a5160208c0151614dd5565b6000614c5382600a615c74565b610c59906064615b4f565b600054610100900460ff16614c855760405162461bcd60e51b8152600401610cf590615abb565b611980614c90613c48565b613eed565b6040516001600160a01b038085166024830152831660448201526064810182905260009081908190614d12908890620186a09084906103e8906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614e32565b915091506000600190506020825110614d2f575060208101516001145b828015614d395750805b98975050505050505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b179052614d968482614ebd565b611d32576040516001600160a01b03848116602483015260006044830152614dcb91869182169063095ea7b39060640161446a565b611d3284826149cc565b6000806000614e25886201388060006103e863913ff9a960e01b8c8c8c8c604051602401614cdb94939291909384526001600160a01b039290921660208401526040830152606082015260800190565b5098975050505050505050565b6000606060008060008661ffff1667ffffffffffffffff811115614e5857614e58615c80565b6040519080825280601f01601f191660200182016040528015614e82576020820181803683370190505b5090506000808751602089018b8e8ef191503d925086831115614ea3578692505b828152826000602083013e90999098509650505050505050565b6000806000806020600086516020880160008a5af192503d91506000519050828015614f0257508115614ef35780600114614f02565b6000866001600160a01b03163b115b9695505050505050565b828054614f1890615727565b90600052602060002090601f016020900481019282614f3a5760008555614f80565b82601f10614f535782800160ff19823516178555614f80565b82800160010185558215614f80579182015b82811115614f80578235825591602001919060010190614f65565b50614f8c929150614f90565b5090565b5b80821115614f8c5760008155600101614f91565b6001600160a01b0381168114611efa57600080fd5b600060208284031215614fcc57600080fd5b813561196781614fa5565b6020808252825182820181905260009190848201906040850190845b8181101561500f57835183529284019291840191600101614ff3565b50909695505050505050565b63ffffffff81168114611efa57600080fd5b61ffff81168114611efa57600080fd5b60008083601f84011261504f57600080fd5b50813567ffffffffffffffff81111561506757600080fd5b60208301915083602082850101111561507f57600080fd5b9250929050565b60008060008060008060008060e0898b0312156150a257600080fd5b88356150ad81614fa5565b9750602089013596506040890135955060608901356150cb8161501b565b945060808901356150db8161502d565b935060a089013567ffffffffffffffff8111156150f757600080fd5b6151038b828c0161503d565b90945092505060c089013561511781614fa5565b809150509295985092959890939650565b6000806040838503121561513b57600080fd5b823561514681614fa5565b9150602083013561515681614fa5565b809150509250929050565b60006020828403121561517357600080fd5b5035919050565b6000806040838503121561518d57600080fd5b82359150602083013561515681614fa5565b600080604083850312156151b257600080fd5b50508035926020909101359150565b815181526020808301519082015260408101610c59565b6000815180845260005b818110156151fe576020818501810151868301820152016151e2565b81811115615210576000602083870101525b50601f01601f19169290920160200192915050565b60208152600061196760208301846151d8565b60008060006060848603121561524d57600080fd5b83359250602084013561525f81614fa5565b9150604084013561526f81614fa5565b809150509250925092565b634e487b7160e01b600052602160045260246000fd5b60028110611efa57611efa61527a565b602081016152ad83615290565b91905290565b600080604083850312156152c657600080fd5b82356152d181614fa5565b946020939093013593505050565b600781106152ef576152ef61527a565b9052565b6152ef81615290565b60006102408201905060018060a01b03808c168352808b166020840152808a1660408401528860608401528760808401528087511660a084015250602086015160c0830152604086015161535d60e084018280518252602090810151910152565b50606086015163ffffffff9081166101208401526080870151811661014084015260a08701511661016083015260c08601516153a261018084018263ffffffff169052565b5084516101a0830152602085015163ffffffff166101c0830152604085015161ffff166101e08301526153d96102008301856152df565b6153e76102208301846152f3565b9a9950505050505050505050565b6000806000806000806000806000806101008b8d03121561541557600080fd5b8a3561542081614fa5565b995060208b0135985060408b0135975060608b013561543e8161501b565b965060808b013561544e8161502d565b955060a08b013567ffffffffffffffff8082111561546b57600080fd5b6154778e838f0161503d565b909750955060c08d0135915061548c82614fa5565b90935060e08c013590808211156154a257600080fd5b818d0191508d601f8301126154b657600080fd5b8135818111156154c557600080fd5b8e60208260071b85010111156154da57600080fd5b6020830194508093505050509295989b9194979a5092959850565b60208101610c5982846152df565b600080600080600080600080610100898b03121561552057600080fd5b883561552b8161502d565b9750602089013561553b81614fa5565b9650604089013561554b81614fa5565b9550606089013561555b81614fa5565b9450608089013561556b81614fa5565b935060a089013561557b81614fa5565b925060c089013561558b81614fa5565b915060e089013561511781614fa5565b6001600160a01b038981168252888116602083015260408201889052861660608201526080810185905263ffffffff84811660a0830152831660c08201526101008101610d0e60e08301846152df565b6000602082840312156155fd57600080fd5b81356119678161502d565b805180151581146120ce57600080fd5b60006020828403121561562a57600080fd5b61196782615608565b6020808252600f908201526e141c9bdd1bd8dbdb081c185d5cd959608a1b604082015260600190565b602080825260139082015272131a5c5d5a59185d1a5bdb9cc81c185d5cd959606a1b604082015260600190565b84815260208101849052608081016156a084615290565b83604083015263ffffffff8316606083015295945050505050565b6000806000606084860312156156d057600080fd5b8351925060208401519150604084015190509250925092565b634e487b7160e01b600052601160045260246000fd5b600063ffffffff80831681851680830382111561571e5761571e6156e9565b01949350505050565b600181811c9082168061573b57607f821691505b6020821081141561575c57634e487b7160e01b600052602260045260246000fd5b50919050565b60006020828403121561577457600080fd5b815161196781614fa5565b82815260606020820152600061579860608301846151d8565b8281036040938401526011815270131bd85b881b9bdd081858d8d95c1d1959607a1b6020820152919091019392505050565b63ffffffff8681168252858116602083015284811660408301528316606082015260a081016157f883615290565b8260808301529695505050505050565b60006020828403121561581a57600080fd5b81516119678161501b565b60038110611efa57600080fd5b838152604060208083018290528282018490526000919060609081850187855b888110156158b457813561586581615825565b600381106158755761587561527a565b8352818401358484015285820135868401528482013561589481614fa5565b6001600160a01b0316838601526080928301929190910190600101615852565b50909998505050505050505050565b8281526060602082015260006158dc60608301846151d8565b828103604093840152600f81526e426964206e6f742070656e64696e6760881b6020820152919091019392505050565b6000806040838503121561591f57600080fd5b61592883615608565b9150602083015190509250929050565b60006020828403121561594a57600080fd5b81516119678161502d565b600082821015615967576159676156e9565b500390565b60006020828403121561597e57600080fd5b5051919050565b60008219821115615998576159986156e9565b500190565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b60028110611efa57600080fd5b60008060408385031215615a0b57600080fd5b8251615a168161501b565b6020840151909250615156816159eb565b600060208284031215615a3957600080fd5b8151611967816159eb565b60c08101615a5188615290565b878252615a5d87615290565b6020820196909652604081019490945263ffffffff92831660608501529116608083015261ffff1660a090910152919050565b8183823760009101908152919050565b6000600019821415615ab457615ab46156e9565b5060010190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b600060208284031215615b1857600080fd5b815161196781615825565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b6000816000190483118215151615615b6957615b696156e9565b500290565b600082615b8b57634e487b7160e01b600052601260045260246000fd5b500490565b600181815b80851115615bcb578160001904821115615bb157615bb16156e9565b80851615615bbe57918102915b93841c9390800290615b95565b509250929050565b600082615be257506001610c59565b81615bef57506000610c59565b8160018114615c055760028114615c0f57615c2b565b6001915050610c59565b60ff841115615c2057615c206156e9565b50506001821b610c59565b5060208310610133831016604e8410600b8410161715615c4e575081810a610c59565b615c588383615b90565b8060001904821115615c6c57615c6c6156e9565b029392505050565b60006119678383615bd3565b634e487b7160e01b600052604160045260246000fdfea2646970667358221220046839d5d2923a0d2456e0b2d0d31e10d4d3220da4e1527215bf35828b4adaf764736f6c634300080b0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000005d3ecf8877edab28e14bd7d243fa8b0fe416e95e
-----Decoded View---------------
Arg [0] : trustedForwarder (address): 0x5d3eCF8877eDAB28e14bD7d243fA8B0fE416E95E
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000005d3ecf8877edab28e14bd7d243fa8b0fe416e95e
Loading...
Loading
Loading...
Loading

Loading...
Loading
Loading...
Loading
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.