Skip to content

external getStakeholderIndex view #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions chain/script/DeployFactory.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,19 @@ library LibDeployment {
return FacetCutInfo({ name: "DiamondLoupeFacet", selectors: selectors });
}
if (facetType == FacetType.Issuer) {
bytes4[] memory selectors = new bytes4[](2);
bytes4[] memory selectors = new bytes4[](3);
selectors[0] = IssuerFacet.initializeIssuer.selector;
selectors[1] = IssuerFacet.adjustIssuerAuthorizedShares.selector;
selectors[2] = IssuerFacet.issuer.selector;
return FacetCutInfo({ name: "IssuerFacet", selectors: selectors });
}
if (facetType == FacetType.Stakeholder) {
bytes4[] memory selectors = new bytes4[](4);
bytes4[] memory selectors = new bytes4[](5);
selectors[0] = StakeholderFacet.createStakeholder.selector;
selectors[1] = StakeholderFacet.getStakeholderPositions.selector;
selectors[2] = StakeholderFacet.linkStakeholderAddress.selector;
selectors[3] = StakeholderFacet.getStakeholderId.selector;
selectors[4] = StakeholderFacet.getStakeholderIndex.selector;
return FacetCutInfo({ name: "StakeholderFacet", selectors: selectors });
}
if (facetType == FacetType.StockClass) {
Expand Down
11 changes: 6 additions & 5 deletions chain/src/facets/IssuerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import { Issuer } from "@libraries/Structs.sol";
import { TxHelper, TxType } from "@libraries/TxHelper.sol";
import { AccessControl } from "@libraries/AccessControl.sol";
import { console } from "forge-std/console.sol";
import { IIssuerFacet } from "@interfaces/IIssuerFacet.sol";

contract IssuerFacet {
error IssuerAlreadyInitialized();

event IssuerAuthorizedSharesAdjusted(uint256 newSharesAuthorized);

contract IssuerFacet is IIssuerFacet {
/// @notice Initialize the issuer with initial shares authorized
/// @dev Can only be called once by an admin during setup
function initializeIssuer(bytes16 id, uint256 initial_shares_authorized) external {
Expand All @@ -30,6 +27,10 @@ contract IssuerFacet {
ds.issuer = Issuer({ id: id, shares_issued: 0, shares_authorized: initial_shares_authorized });
}

function issuer() external view returns (Issuer memory) {
return StorageLib.get().issuer;
}

/// @notice Adjust the total number of authorized shares for the issuer
/// @dev Only DEFAULT_ADMIN_ROLE can adjust authorized shares
function adjustIssuerAuthorizedShares(bytes16 id, uint256 newSharesAuthorized) external {
Expand Down
5 changes: 5 additions & 0 deletions chain/src/facets/StakeholderFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ contract StakeholderFacet {
return stakeholder_id;
}

/// @notice Get stakeholder idx for a stakeholder id
function getStakeholderIndex(bytes16 stakeholder_id) external view returns (uint256) {
return StorageLib.get().stakeholderIndex[stakeholder_id];
}

/// @notice Get all positions for a stakeholder
/// @dev INVESTOR_ROLE can only view their own positions, OPERATOR_ROLE and above can view any
function getStakeholderPositions(bytes16 stakeholder_id) external view returns (StakeholderPositions memory) {
Expand Down
3 changes: 3 additions & 0 deletions chain/src/interfaces/IIssuerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ interface IIssuerFacet {
/// @param initial_shares_authorized Initial number of authorized shares
function initializeIssuer(bytes16 id, uint256 initial_shares_authorized) external;

/// @notice Getter for the Issuer struct
function issuer() external view returns (Issuer memory);

/// @notice Adjust the total number of authorized shares for the issuer
/// @dev Only DEFAULT_ADMIN_ROLE can adjust authorized shares
/// @param id The unique identifier for the tx
Expand Down
3 changes: 3 additions & 0 deletions chain/src/interfaces/IStakeholderFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ interface IStakeholderFacet {
/// @param ensure_exists If true, will revert if the address is not linked to a stakeholder
function getStakeholderId(address wallet_address, bool ensure_exists) external view returns (bytes16);

/// @notice Get stakeholder idx for a stakeholder id
function getStakeholderIndex(bytes16 stakeholder_id) external view returns (uint256);

/// @notice Get all positions for a stakeholder
/// @dev INVESTOR_ROLE can only view their own positions, OPERATOR_ROLE and above can view any
/// @param stakeholder_id The stakeholder to get positions for
Expand Down
30 changes: 30 additions & 0 deletions chain/test/Issuer.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./TestBase.sol";
import {
StockActivePosition,
WarrantActivePosition,
ConvertibleActivePosition,
EquityCompensationActivePosition,
StakeholderPositions,
IssueStockParams,
IssueConvertibleParams,
IssueEquityCompensationParams,
Issuer
} from "@libraries/Structs.sol";
import { IStockFacet } from "@interfaces/IStockFacet.sol";
import { IConvertiblesFacet } from "@interfaces/IConvertiblesFacet.sol";
import { IEquityCompensationFacet } from "@interfaces/IEquityCompensationFacet.sol";
import {ICapTable} from "../src/interfaces/ICapTable.sol";

contract IssuerTest is DiamondTestBase {

function test_issuer() public {
ICapTable ct = ICapTable(address(capTable));
Issuer memory iss = ct.issuer();
assertTrue(iss.id != bytes16(0));
assertGt(iss.shares_authorized, 0);
assertEq(iss.shares_issued, 0);
}
}
3 changes: 3 additions & 0 deletions chain/test/StakeholderPositions.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ contract DiamondStakeholderPositionsTest is DiamondTestBase {
// Ensure it exists
id = sf.getStakeholderId(wallet, true);
assertNotEq(id, bytes16(0));

// Ensure it returns a non-0 idx
assertGt(sf.getStakeholderIndex(id), 0);
}

function testGetStakeholderPositions() public {
Expand Down
Loading