Verified contractExactMIT
OfferLibrary
Address0xe523e37e05d27408eff49034baf76f0cb2b0f2dc
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.23
- Same code
Only this contract
Details
- Compiler
- solc 0.8.23+commit.f704f362
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- shanghai
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 24,384,809
- Creation transaction
- 0x738e233a3d…563b40aa18
118 files
The source code is large: one file is shown at a time. Choose a file in the list.
- src/market/libraries/OfferLibrary.solmain9.31 KB
- lib/aave-v3-core/contracts/dependencies/openzeppelin/contracts/IERC20.sol2.58 KB
- lib/aave-v3-core/contracts/interfaces/IAToken.sol5.47 KB
- lib/aave-v3-core/contracts/interfaces/IAaveIncentivesController.sol847 B
- lib/aave-v3-core/contracts/interfaces/IInitializableAToken.sol2.04 KB
- lib/aave-v3-core/contracts/interfaces/IPool.sol32.69 KB
- lib/aave-v3-core/contracts/interfaces/IPoolAddressesProvider.sol8.22 KB
- lib/aave-v3-core/contracts/interfaces/IScaledBalanceToken.sol2.74 KB
- lib/aave-v3-core/contracts/protocol/libraries/math/WadRayMath.sol4.15 KB
- lib/aave-v3-core/contracts/protocol/libraries/types/DataTypes.sol7.37 KB
- lib/chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol592 B
- lib/openzeppelin-contracts-upgradeable/contracts/access/AccessControlUpgradeable.sol8.29 KB
- lib/openzeppelin-contracts-upgradeable/contracts/access/Ownable2StepUpgradeable.sol3.49 KB
- lib/openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol4.03 KB
- lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol9.28 KB
- lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol6.57 KB
- lib/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol1.19 KB
- lib/openzeppelin-contracts-upgradeable/contracts/utils/ReentrancyGuardUpgradeable.sol4.51 KB
- lib/openzeppelin-contracts-upgradeable/contracts/utils/introspection/ERC165Upgradeable.sol1.18 KB
- lib/openzeppelin-contracts/contracts/access/IAccessControl.sol3.34 KB
- lib/openzeppelin-contracts/contracts/access/Ownable.sol3.1 KB
- lib/openzeppelin-contracts/contracts/interfaces/IERC1363.sol4.45 KB
- lib/openzeppelin-contracts/contracts/interfaces/IERC165.sol192 B
- lib/openzeppelin-contracts/contracts/interfaces/IERC1967.sol636 B
- lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol181 B
- lib/openzeppelin-contracts/contracts/interfaces/IERC20Metadata.sol216 B
- lib/openzeppelin-contracts/contracts/interfaces/IERC4626.sol12.18 KB
- lib/openzeppelin-contracts/contracts/interfaces/draft-IERC1822.sol881 B
- lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol6.54 KB
- lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Utils.sol6.24 KB
- lib/openzeppelin-contracts/contracts/proxy/beacon/IBeacon.sol472 B
- lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol10.88 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol684 B
- lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol10.08 KB
- lib/openzeppelin-contracts/contracts/utils/Address.sol6.05 KB
- lib/openzeppelin-contracts/contracts/utils/Arrays.sol18.34 KB
- lib/openzeppelin-contracts/contracts/utils/Comparators.sol443 B
- lib/openzeppelin-contracts/contracts/utils/Context.sol963 B
- lib/openzeppelin-contracts/contracts/utils/Errors.sol896 B
- lib/openzeppelin-contracts/contracts/utils/Panic.sol1.97 KB
- lib/openzeppelin-contracts/contracts/utils/SlotDerivation.sol5.32 KB
- lib/openzeppelin-contracts/contracts/utils/StorageSlot.sol4.18 KB
- lib/openzeppelin-contracts/contracts/utils/Strings.sol19.28 KB
- lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol870 B
- lib/openzeppelin-contracts/contracts/utils/math/Math.sol32.15 KB
- lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol34.94 KB
- lib/openzeppelin-contracts/contracts/utils/math/SignedMath.sol2.61 KB
- lib/openzeppelin-contracts/contracts/utils/structs/EnumerableMap.sol36.39 KB
- lib/openzeppelin-contracts/contracts/utils/structs/EnumerableSet.sol14.72 KB
- lib/solady/src/utils/FixedPointMathLib.sol45.99 KB
- lib/v3-core/contracts/interfaces/IUniswapV3Pool.sol1.09 KB
- lib/v3-core/contracts/interfaces/pool/IUniswapV3PoolActions.sol6.3 KB
- lib/v3-core/contracts/interfaces/pool/IUniswapV3PoolDerivedState.sol2.6 KB
- lib/v3-core/contracts/interfaces/pool/IUniswapV3PoolErrors.sol390 B
- lib/v3-core/contracts/interfaces/pool/IUniswapV3PoolEvents.sol5.96 KB
- lib/v3-core/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol1.81 KB
- lib/v3-core/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol1.19 KB
- lib/v3-core/contracts/interfaces/pool/IUniswapV3PoolState.sol6.67 KB
- lib/v3-core/contracts/libraries/FullMath.sol5.52 KB
- lib/v3-core/contracts/libraries/TickMath.sol9.42 KB
- lib/v3-periphery/contracts/libraries/OracleLibrary.sol9.46 KB
- lib/v3-periphery/contracts/libraries/PoolAddress.sol1.9 KB
- src/collections/interfaces/ICollectionsManager.sol643 B
- src/collections/interfaces/ICollectionsManagerCuratorActions.sol3.62 KB
- src/collections/interfaces/ICollectionsManagerUserActions.sol2.48 KB
- src/collections/interfaces/ICollectionsManagerView.sol8.32 KB
- src/factory/interfaces/ISizeFactory.sol3.19 KB
- src/factory/interfaces/ISizeFactoryOffchainGetters.sol2.13 KB
- src/factory/interfaces/ISizeFactoryV1_7.sol1.95 KB
- src/factory/interfaces/ISizeFactoryV1_8.sol6.02 KB
- src/factory/libraries/Authorization.sol4.52 KB
- src/helpers/ReentrancyGuardUpgradeableWithViewModifier.sol507 B
- src/market/SizeStorage.sol5.03 KB
- src/market/SizeViewData.sol1.37 KB
- src/market/interfaces/IMulticall.sol772 B
- src/market/interfaces/ISize.sol17.34 KB
- src/market/interfaces/ISizeAdmin.sol2.5 KB
- src/market/interfaces/ISizeView.sol4.1 KB
- src/market/interfaces/IWETH.sol269 B
- src/market/interfaces/v1.7/ISizeV1_7.sol4.44 KB
- src/market/interfaces/v1.8/ISizeV1_8.sol1.37 KB
- src/market/interfaces/v1.8/ISizeViewV1_8.sol2.8 KB
- src/market/libraries/AccountingLibrary.sol16.2 KB
- src/market/libraries/Errors.sol5.48 KB
- src/market/libraries/Events.sol5.6 KB
- src/market/libraries/LoanLibrary.sol7.97 KB
- src/market/libraries/Math.sol2.51 KB
- src/market/libraries/RiskLibrary.sol7.4 KB
- src/market/libraries/YieldCurveLibrary.sol6.27 KB
- src/market/libraries/actions/BuyCreditLimit.sol3.12 KB
- src/market/libraries/actions/BuyCreditMarket.sol11.19 KB
- src/market/libraries/actions/Claim.sol2.58 KB
- src/market/libraries/actions/Compensate.sol6.71 KB
- src/market/libraries/actions/Deposit.sol4.11 KB
- src/market/libraries/actions/Initialize.sol11.59 KB
- src/market/libraries/actions/Liquidate.sol6.59 KB
- src/market/libraries/actions/LiquidateWithReplacement.sol7.48 KB
- src/market/libraries/actions/MarketShutdown.sol4.62 KB
- src/market/libraries/actions/PartialRepay.sol4.22 KB
- src/market/libraries/actions/Repay.sol2.56 KB
- src/market/libraries/actions/SelfLiquidate.sol4.11 KB
- src/market/libraries/actions/SellCreditLimit.sol3.15 KB
- src/market/libraries/actions/SellCreditMarket.sol10.78 KB
- src/market/libraries/actions/SetCopyLimitOrderConfigs.sol3.52 KB
- src/market/libraries/actions/SetUserConfiguration.sol4.15 KB
- src/market/libraries/actions/SetVault.sol2.18 KB
- src/market/libraries/actions/UpdateConfig.sol7.63 KB
- src/market/libraries/actions/Withdraw.sol4.02 KB
- src/market/token/NonTransferrableRebasingTokenVault.sol22.64 KB
- src/market/token/NonTransferrableToken.sol1.92 KB
- src/market/token/adapters/IAaveAdapter.sol487 B
- src/market/token/adapters/IAdapter.sol3.13 KB
- src/oracle/IPriceFeed.sol420 B
- src/oracle/adapters/ChainlinkPriceFeed.sol4.17 KB
- src/oracle/adapters/ChainlinkSequencerUptimeFeed.sol1.64 KB
- src/oracle/adapters/UniswapV3PriceFeed.sol4.3 KB
- src/oracle/v1.5.1/PriceFeed.sol3.51 KB
src/market/libraries/OfferLibrary.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {UserCopyLimitOrderConfigs} from "@src/market/SizeStorage.sol";
import {State} from "@src/market/SizeStorage.sol";
import {ISize} from "@src/market/interfaces/ISize.sol";
import {Errors} from "@src/market/libraries/Errors.sol";
import {Math} from "@src/market/libraries/Math.sol";
import {
VariablePoolBorrowRateParams, YieldCurve, YieldCurveLibrary
} from "@src/market/libraries/YieldCurveLibrary.sol";
struct LimitOrder {
// The maximum due date of the limit order
// Since the yield curve is defined in relative terms, users can protect themselves by
// setting a maximum timestamp for a loan to be matched
uint256 maxDueDate;
// The yield curve in relative terms
YieldCurve curveRelativeTime;
}
struct CopyLimitOrderConfig {
// the minimum tenor of the copied offer
uint256 minTenor;
// the maximum tenor of the copied offer
uint256 maxTenor;
// the minimum APR of the copied offer
uint256 minAPR;
// the maximum APR of the copied offer
uint256 maxAPR;
// the offset APR relative to the copied offer
int256 offsetAPR;
}
/// @title OfferLibrary
/// @custom:security-contact [email protected]
/// @author Size (https://size.credit/)
library OfferLibrary {
using YieldCurveLibrary for YieldCurve;
/// @notice Check if the limit order is null
/// @param self The limit order
/// @return True if the limit order is null, false otherwise
function isNull(LimitOrder memory self) internal pure returns (bool) {
return self.maxDueDate == 0 && self.curveRelativeTime.isNull();
}
/// @notice Check if the copy limit order is null
/// @param self The copy limit order
/// @return True if the copy limit order is null, false otherwise
function isNull(CopyLimitOrderConfig memory self) internal pure returns (bool) {
return self.minTenor == 0 && self.maxTenor == 0 && self.minAPR == 0 && self.maxAPR == 0 && self.offsetAPR == 0;
}
/// @notice Validate the limit order
/// @param self The limit order
/// @param minTenor The minimum tenor
/// @param maxTenor The maximum tenor
function validateLimitOrder(LimitOrder memory self, uint256 minTenor, uint256 maxTenor) internal view {
// validate maxDueDate
if (self.maxDueDate == 0) {
revert Errors.NULL_MAX_DUE_DATE();
}
if (self.maxDueDate < block.timestamp + minTenor) {
revert Errors.PAST_MAX_DUE_DATE(self.maxDueDate);
}
// validate curveRelativeTime
YieldCurveLibrary.validateYieldCurve(self.curveRelativeTime, minTenor, maxTenor);
}
/// @notice Validate the copy limit order configs
/// @param copyLoanOfferConfig The copy loan offer config
/// @param copyBorrowOfferConfig The copy borrow offer config
/// @dev assert min <= max and no arbitrageable setup
function validateCopyLimitOrderConfigs(
CopyLimitOrderConfig memory copyLoanOfferConfig,
CopyLimitOrderConfig memory copyBorrowOfferConfig
) internal pure {
if (copyLoanOfferConfig.minTenor > copyLoanOfferConfig.maxTenor) {
revert Errors.INVALID_TENOR_RANGE(copyLoanOfferConfig.minTenor, copyLoanOfferConfig.maxTenor);
}
if (copyLoanOfferConfig.minAPR > copyLoanOfferConfig.maxAPR) {
revert Errors.INVALID_APR_RANGE(copyLoanOfferConfig.minAPR, copyLoanOfferConfig.maxAPR);
}
if (copyBorrowOfferConfig.minTenor > copyBorrowOfferConfig.maxTenor) {
revert Errors.INVALID_TENOR_RANGE(copyBorrowOfferConfig.minTenor, copyBorrowOfferConfig.maxTenor);
}
if (copyBorrowOfferConfig.minAPR > copyBorrowOfferConfig.maxAPR) {
revert Errors.INVALID_APR_RANGE(copyBorrowOfferConfig.minAPR, copyBorrowOfferConfig.maxAPR);
}
if (
copyBorrowOfferConfig.minAPR > copyLoanOfferConfig.maxAPR
&& (copyBorrowOfferConfig.maxTenor >= copyLoanOfferConfig.minTenor)
&& (copyLoanOfferConfig.maxTenor >= copyBorrowOfferConfig.minTenor)
) {
revert Errors.INVALID_OFFER_CONFIGS(
copyBorrowOfferConfig.minTenor,
copyBorrowOfferConfig.maxTenor,
copyBorrowOfferConfig.minAPR,
copyBorrowOfferConfig.maxAPR,
copyLoanOfferConfig.minTenor,
copyLoanOfferConfig.maxTenor,
copyLoanOfferConfig.minAPR,
copyLoanOfferConfig.maxAPR
);
}
}
function getUserDefinedBorrowOfferAPR(State storage state, address user, uint256 tenor)
internal
view
returns (uint256 apr)
{
return getUserDefinedLimitOrderAPR(state, user, state.data.users[user].borrowOffer, tenor);
}
function getUserDefinedLoanOfferAPR(State storage state, address user, uint256 tenor)
internal
view
returns (uint256 apr)
{
return getUserDefinedLimitOrderAPR(state, user, state.data.users[user].loanOffer, tenor);
}
function getUserDefinedLimitOrderAPR(State storage state, address user, LimitOrder memory limitOrder, uint256 tenor)
internal
view
returns (uint256 apr)
{
if (tenor == 0) {
revert Errors.NULL_TENOR();
}
if (isNull(limitOrder)) {
revert Errors.INVALID_OFFER(user);
}
if (block.timestamp + tenor > limitOrder.maxDueDate) {
revert Errors.DUE_DATE_GREATER_THAN_MAX_DUE_DATE(block.timestamp + tenor, limitOrder.maxDueDate);
}
VariablePoolBorrowRateParams memory params = VariablePoolBorrowRateParams({
variablePoolBorrowRate: state.oracle.variablePoolBorrowRate,
variablePoolBorrowRateUpdatedAt: state.oracle.variablePoolBorrowRateUpdatedAt,
variablePoolBorrowRateStaleRateInterval: state.oracle.variablePoolBorrowRateStaleRateInterval
});
return limitOrder.curveRelativeTime.getAPR(params, tenor);
}
/// @notice Get the APR by tenor of a loan offer
/// @param state The state
/// @param user The user
/// @param collectionId The collection id
/// @param rateProvider The rate provider
/// @param tenor The tenor
/// @return apr The APR
function getLoanOfferAPR(
State storage state,
address user,
uint256 collectionId,
address rateProvider,
uint256 tenor
) public view returns (uint256 apr) {
return state.data.sizeFactory.getLoanOfferAPR(user, collectionId, ISize(address(this)), rateProvider, tenor);
}
/// @notice Get the absolute rate per tenor of a loan offer
/// @param state The state
/// @param user The user
/// @param collectionId The collection id
/// @param rateProvider The rate provider
/// @param tenor The tenor
/// @return ratePerTenor The absolute rate
function getLoanOfferRatePerTenor(
State storage state,
address user,
uint256 collectionId,
address rateProvider,
uint256 tenor
) internal view returns (uint256 ratePerTenor) {
uint256 apr = getLoanOfferAPR(state, user, collectionId, rateProvider, tenor);
ratePerTenor = Math.aprToRatePerTenor(apr, tenor);
}
/// @notice Get the APR by tenor of a borrow offer
/// @param state The state
/// @param user The user
/// @param collectionId The collection id
/// @param rateProvider The rate provider
/// @param tenor The tenor
/// @return apr The APR
function getBorrowOfferAPR(
State storage state,
address user,
uint256 collectionId,
address rateProvider,
uint256 tenor
) public view returns (uint256 apr) {
return state.data.sizeFactory.getBorrowOfferAPR(user, collectionId, ISize(address(this)), rateProvider, tenor);
}
/// @notice Get the absolute rate per tenor of a borrow offer
/// @param state The state
/// @param user The user
/// @param collectionId The collection id
/// @param rateProvider The rate provider
/// @param tenor The tenor
/// @return ratePerTenor The absolute rate
function getBorrowOfferRatePerTenor(
State storage state,
address user,
uint256 collectionId,
address rateProvider,
uint256 tenor
) internal view returns (uint256 ratePerTenor) {
uint256 apr = getBorrowOfferAPR(state, user, collectionId, rateProvider, tenor);
ratePerTenor = Math.aprToRatePerTenor(apr, tenor);
}
function isBorrowAPRLowerThanLoanOfferAPRs(State storage state, address user, uint256 borrowAPR, uint256 tenor)
internal
view
returns (bool)
{
return state.data.sizeFactory.isBorrowAPRLowerThanLoanOfferAPRs(user, borrowAPR, ISize(address(this)), tenor);
}
function isLoanAPRGreaterThanBorrowOfferAPRs(State storage state, address user, uint256 loanAPR, uint256 tenor)
internal
view
returns (bool)
{
return state.data.sizeFactory.isLoanAPRGreaterThanBorrowOfferAPRs(user, loanAPR, ISize(address(this)), tenor);
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "shanghai",
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@chainlink/=lib/chainlink/",
"@src/=src/",
"@test/=test/",
"@deprecated/=deprecated/",
"@script/=script/",
"@solady/=lib/solady/",
"@chimera/=lib/chimera/src/",
"@crytic/properties/=lib/properties/",
"@aave/=lib/aave-v3-core/contracts/",
"halmos-cheatcodes/=lib/halmos-cheatcodes/src/",
"@uniswap/v3-core/=lib/v3-core/",
"@uniswap/v3-periphery/=lib/v3-periphery/",
"@pendle/=lib/pendle-core-v2-public/",
"@tenderly-utils/=lib/tenderly-utils/src/",
"@safe-utils/=lib/safe-utils/src/",
"safe-smart-account/=lib/safe-utils/lib/safe-smart-account/contracts/",
"@solidity-http/=lib/solidity-http/src/",
"@ERC-7540-Reference/=lib/ERC-7540-Reference/",
"@solmate/=lib/solmate/",
"solmate/mixins/=lib/solmate/src/tokens/",
"solmate/tokens/=lib/solmate/src/tokens/",
"solmate/utils/=lib/solmate/src/utils/",
"solmate/auth/=lib/solmate/src/auth/",
"halmos-helpers-lib/=lib/halmos-helpers-lib/src/",
"ERC-7540-Reference/=lib/ERC-7540-Reference/src/",
"ERC4626/=lib/properties/lib/ERC4626/contracts/",
"aave-v3-core/=lib/aave-v3-core/",
"chainlink/=lib/chainlink/contracts/",
"chimera/=lib/chimera/src/",
"ds-test/=lib/solmate/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"pendle-core-v2-public/=lib/pendle-core-v2-public/contracts/",
"properties/=lib/properties/contracts/",
"safe-utils/=lib/safe-utils/src/",
"solady/=lib/solady/",
"solidity-http/=lib/solidity-http/src/",
"solidity-stringutils/=lib/solidity-http/lib/solidity-stringutils/",
"tenderly-utils/=lib/tenderly-utils/src/",
"v3-core/=lib/v3-core/contracts/",
"v3-periphery/=lib/v3-periphery/contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.