Проверенный контрактТочноеMIT
LienRegistry
Адрес0xcd09c202f27fd7253b49917ca1e0346662b10664
- Баланс
0 ETH
- Транзакций
1
- Компилятор
solc 0.8.24
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.24+commit.e11b9ed9
- Язык
- solidity
- Оптимизация
- Да, 200 прогонов
- Версия EVM
- cancun
- Через IR
- да
- Лицензия
- MIT
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 26 463 915
- Транзакция создания
- 0x8fc5173395…077c3c277a
src/collateral/LienRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
/// @notice Collateral pledge / lien registry (module 08).
/// @dev On-chain lien state is not itself a perfected legal lien.
contract LienRegistry {
enum LienStatus {
None,
Registered,
Locked,
Released,
Discharged
}
struct Lien {
bytes32 collateralRef;
bytes32 obligationRef;
bytes32 agreementHash;
uint256 amount;
uint16 priority;
address beneficiary;
LienStatus status;
}
address public admin;
address public custodian;
address public lender;
uint256 public capacity;
uint256 public available;
mapping(bytes32 => Lien) public liens;
mapping(bytes32 => bool) public collateralLocked;
error ZeroAddress();
error Unauthorized();
error InvalidAmount();
error DoublePledge();
error BadStatus();
error CollateralBusy();
error EmptyRef();
event RolesSet(address admin, address custodian, address lender);
event CapacitySet(uint256 capacity);
event CollateralRegistered(bytes32 indexed collateralRef, uint256 amount);
event Pledged(bytes32 indexed lienId, bytes32 collateralRef, uint256 amount, uint16 priority);
event Locked(bytes32 indexed lienId);
event Released(bytes32 indexed lienId);
event Discharged(bytes32 indexed lienId);
modifier onlyAdmin() {
if (msg.sender != admin) revert Unauthorized();
_;
}
constructor(address admin_, address custodian_, address lender_, uint256 capacity_) {
if (admin_ == address(0) || custodian_ == address(0) || lender_ == address(0)) revert ZeroAddress();
if (custodian_ == lender_) revert Unauthorized();
admin = admin_;
custodian = custodian_;
lender = lender_;
capacity = capacity_;
available = capacity_;
emit RolesSet(admin_, custodian_, lender_);
emit CapacitySet(capacity_);
}
function setRoles(address admin_, address custodian_, address lender_) external onlyAdmin {
if (admin_ == address(0) || custodian_ == address(0) || lender_ == address(0)) revert ZeroAddress();
if (custodian_ == lender_) revert Unauthorized();
admin = admin_;
custodian = custodian_;
lender = lender_;
emit RolesSet(admin_, custodian_, lender_);
}
function registerCollateral(bytes32 collateralRef, uint256 amount) external onlyAdmin {
if (collateralRef == bytes32(0) || amount == 0) revert EmptyRef();
emit CollateralRegistered(collateralRef, amount);
}
function pledge(
bytes32 lienId,
bytes32 collateralRef,
bytes32 obligationRef,
uint256 amount,
address beneficiary,
bytes32 agreementHash,
uint16 priority
) external {
if (msg.sender != admin && msg.sender != custodian) revert Unauthorized();
if (lienId == bytes32(0) || collateralRef == bytes32(0) || obligationRef == bytes32(0) || agreementHash == bytes32(0)) {
revert EmptyRef();
}
if (amount == 0 || amount > available || beneficiary == address(0)) revert InvalidAmount();
if (liens[lienId].status != LienStatus.None) revert DoublePledge();
if (collateralLocked[collateralRef]) revert CollateralBusy();
available -= amount;
collateralLocked[collateralRef] = true;
liens[lienId] = Lien({
collateralRef: collateralRef,
obligationRef: obligationRef,
agreementHash: agreementHash,
amount: amount,
priority: priority,
beneficiary: beneficiary,
status: LienStatus.Registered
});
emit Pledged(lienId, collateralRef, amount, priority);
}
function lock(bytes32 lienId) external {
if (msg.sender != admin && msg.sender != lender) revert Unauthorized();
Lien storage lien = liens[lienId];
if (lien.status != LienStatus.Registered) revert BadStatus();
lien.status = LienStatus.Locked;
emit Locked(lienId);
}
/// @notice Dual-control release: both custodian and lender must be the configured parties.
function release(bytes32 lienId, address custodian_, address lender_) external {
Lien storage lien = liens[lienId];
if (lien.status != LienStatus.Locked && lien.status != LienStatus.Registered) revert BadStatus();
if (custodian_ != custodian || lender_ != lender || custodian_ == lender_) revert Unauthorized();
if (msg.sender != admin && msg.sender != custodian && msg.sender != lender) revert Unauthorized();
lien.status = LienStatus.Released;
available += lien.amount;
collateralLocked[lien.collateralRef] = false;
emit Released(lienId);
}
function discharge(bytes32 lienId) external onlyAdmin {
Lien storage lien = liens[lienId];
if (lien.status != LienStatus.Released) revert BadStatus();
lien.status = LienStatus.Discharged;
emit Discharged(lienId);
}
}
Настройки компилятораПоказать
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"forge-std/=lib/forge-std/src/"
]
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.