Verified contractPartialMIT
RegistrySmartISIN
Address0x435b7ebb337399e8e03891966118db2b9f4be7d7
- Balance
0 ETH
- Transactions
5
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- No
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,342,466
- Creation transaction
- 0xb88f59df97…0c932afc19
RegistrySmartISIN.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @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 {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling 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 {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_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);
}
}
/// @title RegistrySmartISIN
/// @notice Maps multiple addresses to LEIs, and LEIs to ISIN/WKN pairs.
contract RegistrySmartISIN is Ownable {
constructor() Ownable(msg.sender) {}
// ========= Events =========
event ISINConsumed(string lei, string isin, string wkn);
event ISINRequested(address indexed requester, string lei, string isin, string wkn);
event ISINReactivated(string lei, string isin, string wkn);
// ========= Structs =========
struct SecurityIdentifier {
string isin;
string wkn;
}
// ========= State Variables =========
mapping(address => string) private addressToLEI; // msg.sender → LEI
mapping(string => address[]) private leiToAddresses; // LEI → multiple addresses
mapping(string => SecurityIdentifier[]) private leiToAvailableSecurities;
mapping(string => SecurityIdentifier[]) private leiToConsumedSecurities;
mapping(string => mapping(string => bool)) private leiHasISIN;
mapping(string => mapping(address => bool)) private leiHasAddress; // Schnelle Adressprüfung
// ========= Modifiers =========
modifier onlyIssuer() {
string memory lei = addressToLEI[msg.sender];
require(bytes(lei).length > 0, "Address is no eligible Issuer");
_;
}
// ========= Admin Functions (Owner Only) =========
/// @notice Assign a LEI to a new address (add to multiple addresses)
function assignLEIToAddress(string memory _lei, address _addr) public onlyOwner {
require(_addr != address(0), "Address cannot be zero");
require(bytes(_lei).length > 0, "LEI cannot be empty");
if (!leiHasAddress[_lei][_addr]) {
leiToAddresses[_lei].push(_addr);
leiHasAddress[_lei][_addr] = true;
}
addressToLEI[_addr] = _lei;
}
/// @notice Remove an address from a LEI
function removeAddressFromLEI(string memory _lei, address _addr) public onlyOwner {
require(leiHasAddress[_lei][_addr], "Address not assigned to this LEI");
address[] storage addresses = leiToAddresses[_lei];
for (uint i = 0; i < addresses.length; i++) {
if (addresses[i] == _addr) {
addresses[i] = addresses[addresses.length - 1];
addresses.pop();
break;
}
}
leiHasAddress[_lei][_addr] = false;
delete addressToLEI[_addr];
}
/// @notice Add ISIN/WKN pairs to a LEI
function addISINsForLEI(string memory _lei, SecurityIdentifier[] memory _securities)
public
onlyOwner
{
require(bytes(_lei).length > 0, "LEI cannot be empty");
require(_securities.length > 0, "(ISIN, WKN) list cannot be empty");
SecurityIdentifier[] storage available = leiToAvailableSecurities[_lei];
for (uint i = 0; i < _securities.length; i++) {
SecurityIdentifier memory sec = _securities[i];
require(bytes(sec.isin).length > 0, "ISIN cannot be empty");
require(bytes(sec.wkn).length > 0, "WKN cannot be empty");
require(!leiHasISIN[_lei][sec.isin], "Duplicate ISIN");
available.push(sec);
leiHasISIN[_lei][sec.isin] = true;
}
}
function reactivateISIN(string memory _lei, string memory _isin)
external
onlyOwner
{
require(bytes(_lei).length > 0, "LEI cannot be empty");
require(bytes(_isin).length > 0, "ISIN cannot be empty");
require(!leiHasISIN[_lei][_isin], "ISIN is already available");
SecurityIdentifier[] storage consumed =
leiToConsumedSecurities[_lei];
uint256 consumedIndex;
bool found;
bytes32 isinHash = keccak256(bytes(_isin));
for (uint256 i = 0; i < consumed.length; i++) {
if (keccak256(bytes(consumed[i].isin)) == isinHash) {
consumedIndex = i;
found = true;
break;
}
}
require(found, "Consumed ISIN not found");
SecurityIdentifier memory reactivatedSecurity =
consumed[consumedIndex];
// Remove from consumed list.
consumed[consumedIndex] = consumed[consumed.length - 1];
consumed.pop();
SecurityIdentifier[] storage available =
leiToAvailableSecurities[_lei];
// Insert as the next ISIN returned by requestISINs(1).
available.push(reactivatedSecurity);
uint256 lastIndex = available.length - 1;
if (lastIndex > 0) {
available[lastIndex] = available[0];
available[0] = reactivatedSecurity;
}
leiHasISIN[_lei][_isin] = true;
emit ISINReactivated(
_lei,
reactivatedSecurity.isin,
reactivatedSecurity.wkn
);
}
// ========= Core Functions =========
function requestISINs() external onlyIssuer returns (SecurityIdentifier[] memory) {
return _requestISINs(0);
}
function requestISINs(uint _limit) external onlyIssuer returns (SecurityIdentifier[] memory) {
return _requestISINs(_limit);
}
function _requestISINs(uint _limit) internal returns (SecurityIdentifier[] memory) {
string memory lei = addressToLEI[msg.sender];
SecurityIdentifier[] storage available = leiToAvailableSecurities[lei];
uint returnLength = _limit;
if (_limit == 0 || _limit > available.length) {
returnLength = available.length;
}
SecurityIdentifier[] memory result = new SecurityIdentifier[](returnLength);
for (uint i = 0; i < returnLength; i++) {
SecurityIdentifier memory sec = available[i];
result[i] = sec;
emit ISINRequested(msg.sender, lei, sec.isin, sec.wkn);
}
return result;
}
function requestApprovePublication(string memory _isin, string memory _wkn) external onlyIssuer {
require(bytes(_isin).length > 0, "ISIN cannot be empty");
require(bytes(_wkn).length > 0, "WKN cannot be empty");
string memory lei = addressToLEI[msg.sender];
require(leiHasISIN[lei][_isin], "ISIN not available or not assigned to your LEI");
SecurityIdentifier[] storage available = leiToAvailableSecurities[lei];
SecurityIdentifier memory consumedSec;
bool found = false;
for (uint i = 0; i < available.length; i++) {
if (keccak256(bytes(available[i].isin)) == keccak256(bytes(_isin))) {
consumedSec = available[i];
leiToConsumedSecurities[lei].push(consumedSec);
available[i] = available[available.length - 1];
available.pop();
found = true;
break;
}
}
require(found, "ISIN state inconsistent");
leiHasISIN[lei][_isin] = false;
emit ISINConsumed(lei, consumedSec.isin, consumedSec.wkn);
}
// ========= View Functions =========
function getLEI(address _addr) external view returns (string memory) {
return addressToLEI[_addr];
}
function getAddressesForLEI(string memory _lei) external view returns (address[] memory) {
return leiToAddresses[_lei];
}
function getAvailableISINs(string memory _lei) external view returns (SecurityIdentifier[] memory) {
return leiToAvailableSecurities[_lei];
}
function getConsumedISINs(string memory _lei) external view returns (SecurityIdentifier[] memory) {
return leiToConsumedSecurities[_lei];
}
}Compiler settingsShow
{
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": false
}
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.