Skip to Content

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.

FunctionCalled byChecksEffectHistory rows
createIssuanceissueStockQuantity and price above zeroAdds a security; issued totals rise by quantityStockIssuance
createTransfertransferStockBuyer verified; quantity and price above zero; enough sharesMoves shares; issued totals don’t changeFor each security used: StockIssuance for the recipient, StockIssuance for any remainder, StockTransfer
createCancellationcancelStockSecurity is live; enough sharesCloses the security; issued totals drop by quantityStockCancellation, plus StockIssuance for any remainder
createRepurchaserepurchaseStockSecurity is live; enough sharesCloses the security; issued totals drop by quantityStockRepurchase, plus StockIssuance for any remainder
createRetractionretractStockIssuanceSecurity is liveCloses the security; issued totals drop by its quantityStockRetraction
createReissuancereissueStockSecurity is liveCloses the security; issued totals drop by its quantityStockReissuance
createAcceptanceacceptStockNone; CapTable checks the securityNoneStockAcceptance

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

ErrorCause
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.

Last updated on