Stock Library
StockLib (chain/src/lib/Stock.sol) holds the stock logic that CapTable calls. Before calling it, CapTable checks the caller’s role, that the stakeholder and stock class exist, and for issuances, the authorized-share caps. Each StockLib function then checks the security it acts on, updates positions and issued totals, and records a transaction that the poller turns into history rows.
| Function | Called by | Checks | Effect | History rows |
|---|---|---|---|---|
createIssuance | issueStock | Quantity and price above zero | Adds a security; issued totals rise by quantity | StockIssuance |
createTransfer | transferStock | Buyer verified; quantity and price above zero; enough shares | Moves shares; issued totals don’t change | For each security used: StockIssuance for the recipient, StockIssuance for any remainder, StockTransfer |
createCancellation | cancelStock | Security is live; enough shares | Closes the security; issued totals drop by quantity | StockCancellation, plus StockIssuance for any remainder |
createRepurchase | repurchaseStock | Security is live; enough shares | Closes the security; issued totals drop by quantity | StockRepurchase, plus StockIssuance for any remainder |
createRetraction | retractStockIssuance | Security is live | Closes the security; issued totals drop by its quantity | StockRetraction |
createReissuance | reissueStock | Security is live | Closes the security; issued totals drop by its quantity | StockReissuance |
createAcceptance | acceptStock | None; CapTable checks the security | None | StockAcceptance |
A repurchase doesn’t check its price, so a price of zero is accepted.
Leftover shares
A transfer takes the sender’s securities in the class in the order they were created, until it has the requested quantity. When a transfer, cancel, or repurchase uses only part of a security, the contract closes it and issues a new security for the rest at the original price. The transaction’s balance_security_id is that new security, or zero when nothing is left.
Errors
| Error | Cause |
|---|---|
InsufficientShares(available, required) | The quantity is more than the security or the sender holds. |
InvalidQuantityOrPrice(quantity, price) | An issuance or transfer has a zero quantity or price. |
UnverifiedBuyer() | A transfer has is_buyer_verified set to false. |
ActivePositionNotFound(stakeholderId, securityId) | The stakeholder doesn’t hold that security, or it’s closed. |
The quantities in these errors are ×1e10; see Scaling.
Related: Structs Library and Solidity Reference.