Проверенный контрактТочноеBUSL-1.1
ReserveCreditLib
Адрес0x7809bb6bfd961e855b8f5e445a475e9f4c3bb466
- Баланс
0 ETH
- Транзакций
1
- Компилятор
solc 0.8.30
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.30+commit.73712a01
- Язык
- solidity
- Оптимизация
- Да, 100 прогонов
- Версия EVM
- cancun
- Лицензия
- BUSL-1.1
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 26 459 304
- Транзакция создания
- 0x07710ce426…b1a77b410e
79 файлов
Исходный код большой: показывается один файл. Выберите файл в списке.
- src/libraries/ReserveCreditLib.solглавный10,73 КБ
- lib/openzeppelin-contracts-upgradeable/contracts/access/AccessControlUpgradeable.sol8,33 КБ
- lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol9,28 КБ
- lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol6,57 КБ
- lib/openzeppelin-contracts-upgradeable/contracts/token/ERC721/ERC721Upgradeable.sol17,8 КБ
- lib/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol1,19 КБ
- lib/openzeppelin-contracts-upgradeable/contracts/utils/PausableUpgradeable.sol3,66 КБ
- lib/openzeppelin-contracts-upgradeable/contracts/utils/ReentrancyGuardUpgradeable.sol4,51 КБ
- lib/openzeppelin-contracts-upgradeable/contracts/utils/introspection/ERC165Upgradeable.sol1,15 КБ
- lib/openzeppelin-contracts/contracts/access/IAccessControl.sol3,34 КБ
- lib/openzeppelin-contracts/contracts/interfaces/IERC1363.sol4,45 КБ
- lib/openzeppelin-contracts/contracts/interfaces/IERC165.sol193 Б
- lib/openzeppelin-contracts/contracts/interfaces/IERC1967.sol637 Б
- lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol182 Б
- lib/openzeppelin-contracts/contracts/interfaces/IERC4626.sol12,18 КБ
- lib/openzeppelin-contracts/contracts/interfaces/draft-IERC1822.sol882 Б
- lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol6,54 КБ
- lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Utils.sol6,24 КБ
- lib/openzeppelin-contracts/contracts/proxy/beacon/IBeacon.sol473 Б
- lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2,78 КБ
- lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol684 Б
- lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol10,08 КБ
- lib/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol4,93 КБ
- lib/openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol997 Б
- lib/openzeppelin-contracts/contracts/token/ERC721/extensions/IERC721Metadata.sol792 Б
- lib/openzeppelin-contracts/contracts/token/ERC721/utils/ERC721Utils.sol1,92 КБ
- lib/openzeppelin-contracts/contracts/utils/Address.sol6 КБ
- lib/openzeppelin-contracts/contracts/utils/Errors.sol896 Б
- lib/openzeppelin-contracts/contracts/utils/Panic.sol1,97 КБ
- lib/openzeppelin-contracts/contracts/utils/StorageSlot.sol4,18 КБ
- lib/openzeppelin-contracts/contracts/utils/Strings.sol19,28 КБ
- lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol871 Б
- lib/openzeppelin-contracts/contracts/utils/math/Math.sol32,15 КБ
- lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol34,94 КБ
- lib/openzeppelin-contracts/contracts/utils/math/SignedMath.sol2,61 КБ
- src/ClaimBridge.sol51,43 КБ
- src/ReserveManager.sol46,83 КБ
- src/interfaces/IAccrualExposure.sol2,49 КБ
- src/interfaces/IAccrualLifecycle.sol6,35 КБ
- src/interfaces/IAccrualMigration.sol2,22 КБ
- src/interfaces/IAttestationOracle.sol11,8 КБ
- src/interfaces/ICascadeBackstop.sol3,47 КБ
- src/interfaces/ICollateralRegistry.sol20,52 КБ
- src/interfaces/IComplianceRegistry.sol2,52 КБ
- src/interfaces/IContinuousAccrual.sol4,39 КБ
- src/interfaces/ICuratorModule.sol21,74 КБ
- src/interfaces/ILMVReleaseHistoryMonitor.sol1,06 КБ
- src/interfaces/IMintRedeemController.sol42,91 КБ
- src/interfaces/IReserveLossAbsorber.sol2,11 КБ
- src/interfaces/IReserveLossGovernance.sol574 Б
- src/interfaces/IReserveManager.sol26,93 КБ
- src/interfaces/IWaterfallEngine.sol16,65 КБ
- src/interfaces/IsUSDfr.sol12,92 КБ
- src/libraries/AccrualBook.sol23,61 КБ
- src/libraries/AccrualCeiling.sol4,34 КБ
- src/libraries/AccrualLoans.sol48,22 КБ
- src/libraries/AccrualMath.sol8,76 КБ
- src/libraries/AccrualSchedule.sol10,13 КБ
- src/libraries/AccrualSegments.sol8,37 КБ
- src/libraries/BorrowerPayoutLib.sol3,5 КБ
- src/libraries/BridgeAccrualLib.sol5,25 КБ
- src/libraries/BridgeMixedInterestLib.sol29,67 КБ
- src/libraries/Config.sol23,1 КБ
- src/libraries/LossEventIds.sol1,35 КБ
- src/libraries/ReleaseHistoryMonitorLib.sol5,08 КБ
- src/libraries/ReserveAccrualCreditLib.sol16,47 КБ
- src/libraries/ReserveAccrualLib.sol22,9 КБ
- src/libraries/ReserveAccrualLifecycleLib.sol14,71 КБ
- src/libraries/ReserveAccrualServiceLib.sol3,15 КБ
- src/libraries/ReserveAccrualStorageLib.sol5,04 КБ
- src/libraries/ReserveAccrualViewsLib.sol3,69 КБ
- src/libraries/ReserveCascadeLib.sol12,35 КБ
- src/libraries/ReserveIncidentLib.sol12,48 КБ
- src/libraries/ReserveMigrationLib.sol18,51 КБ
- src/libraries/ReserveMigrationViewLib.sol1,14 КБ
- src/libraries/ReserveRoundingLib.sol11,72 КБ
- src/libraries/ReserveStorageLib.sol5,53 КБ
- src/libraries/ReserveWiringLib.sol8,77 КБ
- src/libraries/Roles.sol4,2 КБ
src/libraries/ReserveCreditLib.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.30;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IReserveManager} from "../interfaces/IReserveManager.sol";
import {ReserveManager} from "../ReserveManager.sol";
import {ReserveStorageLib} from "./ReserveStorageLib.sol";
import {BorrowerPayoutLib} from "./BorrowerPayoutLib.sol";
import {ReleaseHistoryMonitorLib} from "./ReleaseHistoryMonitorLib.sol";
/// @title ReserveCreditLib — the ReserveManager's credit-path bodies
///
/// @notice EXTRACTED 2026-09-09 FOR EIP-170, mirroring BSC commit `9438be1`. The live mainnet
/// `ReserveManager` shipped with 9 bytes of runtime margin, so it was frozen against any
/// new function; adding `recordPikCapitalization` put it 184 bytes over the 24,576 limit
/// even after the fee and PIK twins were made to share one private body.
///
/// @dev EVERY FUNCTION HERE IS `public` AND THAT IS THE WHOLE POINT. A `public` library function is
/// deployed as its own contract and reached by delegatecall, so its bytecode leaves the
/// caller's runtime; an `internal` one is inlined and saves nothing. The library therefore
/// needs LINKING at deploy time, which is new for this repository.
///
/// @dev THE CALLER KEEPS THE GUARDS. `ReserveManager` retains every `onlyRole`, `nonReentrant` and
/// `whenNotPaused` modifier on the external entry points, because a delegatecall runs in the
/// proxy's context and a library cannot see the caller's modifiers. Do not call anything here
/// from a path that does not carry them.
///
/// @dev DELEGATECALL MEANS `address(this)` IS THE PROXY, which is what keeps `safeTransfer`,
/// `balanceOf(address(this))` and the self-deployment guard meaning exactly what they meant
/// when these bodies lived in the contract.
library ReserveCreditLib {
/// @notice Principal and previously recognized interest discharged by measured canonical USDC.
event AccruedPaymentReceived(
uint256 indexed facilityId,
address indexed asset,
address indexed payer,
uint256 nativeUnits,
uint256 principalReduction,
uint256 interestReduction
);
using SafeERC20 for IERC20;
using ReserveStorageLib for ReserveManager.ReserveStorage;
/// @dev Body of `ReserveManager.recordDeployment`.
function deploy(ReserveManager.ReserveStorage storage $, uint256 facilityId, address to, uint256 usdcAmount)
public
{
if (to == address(0)) revert IReserveManager.ReserveManager_ZeroAddress();
if (to == address(this)) revert IReserveManager.ReserveManager_SelfDeployment();
if (usdcAmount == 0) revert IReserveManager.ReserveManager_ZeroAmount();
BorrowerPayoutLib.requireAllowedInternal(to);
// MA-1/R4-01: a live custody shortfall freezes the facility-funding USDC out-door.
$.requireIdleFullyCustodied();
uint256 value = ReserveStorageLib.normalize(usdcAmount);
uint256 idleValue = ReserveStorageLib.normalize($.idleUSDCUnits);
if (value > idleValue) revert IReserveManager.ReserveManager_InsufficientIdleValue(value, idleValue);
$.idleUSDCUnits -= usdcAmount;
$.deployed[facilityId] += value;
$.totalDeployedPrincipal += value;
ReleaseHistoryMonitorLib.recordOutflow(value);
$.usdcToken.safeTransfer(to, usdcAmount);
emit IReserveManager.PrincipalDeployed(facilityId, value);
}
/// @notice The unchanged legacy release body, moved here to retain EIP-170 headroom.
/// @dev The ReserveManager caller retains its role, pause and reentrancy guards.
function release(ReserveManager.ReserveStorage storage $, address to, uint256 amount) public {
if (to == address(0)) revert IReserveManager.ReserveManager_ZeroAddress();
if (to == address(this)) revert IReserveManager.ReserveManager_SelfDeployment();
if (amount == 0) revert IReserveManager.ReserveManager_ZeroAmount();
$.requireIdleFullyCustodied();
uint256 value = ReserveStorageLib.normalize(amount);
uint256 idleValue = ReserveStorageLib.normalize($.idleUSDCUnits);
if (value > idleValue) revert IReserveManager.ReserveManager_InsufficientIdleValue(value, idleValue);
$.idleUSDCUnits -= amount;
ReleaseHistoryMonitorLib.recordOutflow(value);
$.usdcToken.safeTransfer(to, amount);
emit IReserveManager.USDCReleased(to, amount);
}
/// @dev Shared body of `recordFeeCapitalization` and `recordPikCapitalization`. `requireIdle`
/// is the fee twin's solvency bound; PIK has no cash behind it and passes false.
///
/// The fee twin is sound because the fee's cash NEVER LEFT: `fund` deploys
/// `principal - fee`, so backing rises against RETAINED CASH and bounding it by idle is
/// meaningful. There is no retained cash behind a PIK capitalisation; what stands behind
/// it is the borrower's obligation to repay a larger balance and, beneath that, the
/// curator first-loss layer. Bounding a receivable by idle cash would refuse a legitimate
/// capitalisation on a drawn-down book and admit one on a flush book.
///
/// EVERY OTHER BOUND ON PIK LIVES IN `WaterfallEngine.capitalizePik`.
function capitalize(ReserveManager.ReserveStorage storage $, uint256 facilityId, uint256 amount, bool requireIdle)
public
{
if (amount == 0) revert IReserveManager.ReserveManager_ZeroAmount();
uint256 units = ReserveStorageLib.denormalize(amount);
if (ReserveStorageLib.normalize(units) != amount) {
revert IReserveManager.ReserveManager_ValueNotUSDCExact(amount);
}
if (requireIdle) {
uint256 idleValue = ReserveStorageLib.normalize($.idleUSDCUnits);
if (amount > idleValue) revert IReserveManager.ReserveManager_InsufficientIdleValue(amount, idleValue);
}
// The borrower owes the full face amount while the OID cash stays in the treasury (fee
// path) or while the interest compounds into principal (PIK path). Both are additional
// receivable; only the fee path has retained cash standing behind it.
$.deployed[facilityId] += amount;
$.totalDeployedPrincipal += amount;
if (requireIdle) {
emit IReserveManager.FeeCapitalized(facilityId, amount);
} else {
emit IReserveManager.PikCapitalized(facilityId, amount, $.deployed[facilityId]);
}
}
/// @dev Body of `ReserveManager.recordPayment`.
function pay(
ReserveManager.ReserveStorage storage native,
uint256 facilityId,
address payer,
uint256 usdcAmount,
uint256 principal
) public returns (uint256 receivedValue) {
receivedValue = _pay(native, facilityId, payer, usdcAmount, principal);
emit IReserveManager.PaymentReceived(facilityId, payer, usdcAmount, principal);
}
/// @notice A measured receipt replaces already recognized cash or PIK receivable, without new income.
function payAccrued(
ReserveManager.ReserveStorage storage native,
uint256 facilityId,
address payer,
uint256 usdcAmount,
uint256 principalReduction,
uint256 interestReduction
) public returns (uint256 receivedValue) {
receivedValue = _pay(native, facilityId, payer, usdcAmount, principalReduction + interestReduction);
emit AccruedPaymentReceived(
facilityId, address(native.usdcToken), payer, usdcAmount, principalReduction, interestReduction
);
}
function _pay(
ReserveManager.ReserveStorage storage $,
uint256 facilityId,
address payer,
uint256 usdcAmount,
uint256 principal
) private returns (uint256 receivedValue) {
if (payer == address(0)) revert IReserveManager.ReserveManager_ZeroAddress();
if (usdcAmount == 0) revert IReserveManager.ReserveManager_ZeroAmount();
uint256 beforeBalance = $.usdcToken.balanceOf(address(this));
$.usdcToken.safeTransferFrom(payer, address(this), usdcAmount);
uint256 received = $.usdcToken.balanceOf(address(this)) - beforeBalance;
if (received != usdcAmount) {
revert IReserveManager.ReserveManager_UnexpectedUSDCReceipt(usdcAmount, received);
}
receivedValue = ReserveStorageLib.normalize(received);
if (principal > receivedValue) {
revert IReserveManager.ReserveManager_PrincipalExceedsPayment(principal, receivedValue);
}
uint256 deployedFace = $.deployed[facilityId];
if (principal > deployedFace) {
revert IReserveManager.ReserveManager_InsufficientDeployedPrincipal(facilityId, principal, deployedFace);
}
$.idleUSDCUnits += received;
if (principal != 0) {
uint256 remainingFace = deployedFace - principal;
$.deployed[facilityId] = remainingFace;
$.totalDeployedPrincipal -= principal;
// H-1: cash collection does not prove that a governance-adjudicated impairment
// was recovered. Preserve the mark unless the smaller remaining face can no longer
// support it; only that arithmetically unavoidable excess is released. Treating
// every repayment dollar as recovery made backing depend on repayment/write-down
// ordering and could silently reopen par exits against the still-impaired claim.
$.clampImpairmentToRemainingFace(facilityId, remainingFace);
}
}
/// @dev Body of `ReserveManager.recordPrincipalWritedown`. Extracted with the credit path
/// because it shares the impairment helpers with `pay`.
function writeDown(ReserveManager.ReserveStorage storage $, uint256 facilityId, uint256 amount) public {
if (amount == 0) revert IReserveManager.ReserveManager_ZeroAmount();
uint256 deployedFace = $.deployed[facilityId];
if (amount > deployedFace) {
revert IReserveManager.ReserveManager_InsufficientDeployedPrincipal(facilityId, amount, deployedFace);
}
$.deployed[facilityId] = deployedFace - amount;
$.totalDeployedPrincipal -= amount;
// A write-down is the realization of loss, so the mark already carried against that
// loss must be consumed to avoid counting the same dollar twice.
$.realizeImpairmentOnWriteDown(facilityId, amount);
emit IReserveManager.PrincipalWrittenDown(facilityId, amount);
}
}
Настройки компилятораПоказать
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 100,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"solady/=lib/solady/src/"
]
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.