Skip to Content
Protocol SpecificationSolidity Reference

Solidity Reference

Every function, event, and error in chain/src. Vendored code under chain/lib isn’t covered. For the architecture and roles, see Solidity Cap Table.

CapTable writes

The API column lists the server-signed route that calls each function. The app under /app calls createStockClass, createStakeholder, issueStock, and transferStock from the issuer’s wallet instead. After a stock class or stakeholder confirms, it saves the metadata with /register-onchain.

FunctionAccessInputsEffectAPI
initializeOnce, at creationIssuer id, name, authorized shares, admin, operatorSets roles and the issuer; emits IssuerCreated.Called by createCapTable
mintSharesAuthorizedOperatorInitialSharesSeeds issued and authorized counts for the issuer and every stock class; emits SharesAuthorizedMinted.Direct call (one-shot seed)
mintActivePositionsOperatorStakeholder, security, class, quantity, price, and timestamp arraysSeeds positions matching those counts; emits ActivePositionMinted.Direct call (one-shot seed)
createStakeholderOperatorId, type, relationshipAdds a stakeholder; emits StakeholderCreated.POST /stakeholder/create
createStockClassOperatorId, type, price, authorized sharesAdds a stock class; emits StockClassCreated.POST /stock-class/create
createStockLegendTemplateOperatorLegend idStores a legend id; emits StockLegendTemplateCreated.Direct call
addWalletToStakeholderOperatorStakeholder id, walletLinks the wallet; emits WalletAdded.POST /stakeholder/add-wallet
removeWalletFromStakeholderOperatorStakeholder id, walletUnlinks the wallet; emits WalletRemoved.POST /stakeholder/remove-wallet
issueStockOperatorStockIssuanceParamsAdds a security and raises issued totals.POST /transactions/issuance/stock
transferStockOperatorStockTransferParamsMoves shares, creating new securities for the recipient and any remainder.POST /transactions/transfer/stock
cancelStockOperatorStockParams, quantityCancels shares; any remainder becomes a new security.POST /transactions/cancel/stock
retractStockIssuanceOperatorStockParamsVoids the whole security.POST /transactions/retract/stock
reissueStockOperatorStockParams, resulting security idsCloses the security in favor of securities already issued.POST /transactions/reissue/stock
repurchaseStockOperatorStockParams, quantity, priceBuys back shares; any remainder becomes a new security.POST /transactions/repurchase/stock
acceptStockOperatorStakeholder id, class id, security id, commentsRecords an acceptance.POST /transactions/accept/stock
adjustIssuerAuthorizedSharesAdminNew authorized shares, comments, approval datesSets the issuer’s authorized shares.POST /transactions/adjust/issuer/authorized-shares
adjustStockClassAuthorizedSharesAdminClass id, new authorized shares, comments, approval datesSets a class’s authorized shares.POST /transactions/adjust/stock-class/authorized-shares
addAdmin, removeAdminAdminAddressGrants or revokes ADMIN.Direct call
addOperator, removeOperatorAdminAddressGrants or revokes OPERATOR.Direct call

Operator access means OPERATOR or ADMIN. The two mint* functions seed an imported cap table once, in order, before any other stock transaction.

CapTable reads

FunctionReturns
issuer()Issuer id, legal name, issued shares, authorized shares
stakeholders(i), stockClasses(i), stockLegendTemplates(i)The record at index i
stakeholderIndex(id), stockClassIndex(id)The record’s index plus one, or 0 if it doesn’t exist
walletsPerStakeholder(wallet)The linked stakeholder id, or zero
getStakeholderById(id)Stakeholder id, type, relationship
getStockClassById(id)Class id, type, price, issued, authorized
getStakeholderIdByWallet(wallet)Stakeholder id; reverts with No stakeholder found
getTotalNumberOfStakeholders(), getTotalNumberOfStockClasses()Counts
getActivePosition(stakeholderId, securityId)Class id, quantity, price, timestamp
getAveragePosition(stakeholderId, stockClassId)Sum of quantity × price, total quantity, newest timestamp
getTotalActiveSecuritiesCount()Number of live securities
transactions(i), getTransactionsCount()An encoded transaction, and the count
nonce()The counter mixed into generated ids
ADMIN_ROLE(), OPERATOR_ROLE(), hasRole(role, account)Role constants and checks

Quantities, prices, and issued or authorized share counts are ×1e10. getAveragePosition’s quantity × price sum is ×1e20. Counts, indexes, and timestamps are not scaled. See Scaling.

Events

EventEmitted by
IssuerCreated(id, name)initialize
StakeholderCreated(id)createStakeholder
StockClassCreated(id, classType, pricePerShare, initialSharesAuthorized)createStockClass
StockLegendTemplateCreated(id)createStockLegendTemplate
WalletAdded(stakeholderId, wallet), WalletRemoved(stakeholderId, wallet)Wallet functions
SharesAuthorizedMinted(issuerId, sharesAuthorized, sharesIssued)mintSharesAuthorized
ActivePositionMinted(stakeholderId, securityId, stockClassId, quantity)mintActivePositions
TxCreated(index, txType, txData)Every stock transaction, from the cap table’s address. The poller turns these into history rows.

txType values: 1 issuer authorized-share adjustment, 2 stock class authorized-share adjustment, 3 acceptance, 4 cancellation, 5 issuance, 6 reissuance, 7 repurchase, 8 retraction, 9 transfer. txData is the ABI-encoded payload from Structs Library.

Errors and revert strings

Error or messageCause
Does not have operator role, Does not have admin roleThe caller lacks the role.
NoStakeholder, InvalidStockClassThe stakeholder or stock class doesn’t exist.
StakeholderAlreadyExists, StockClassAlreadyExistsThe id is taken.
InvalidWallet, WalletAlreadyExistsThe zero address, or a wallet already linked to a stakeholder.
NoActivePositionFoundAcceptance or reissue: the security isn’t live for that stakeholder.
NoIssuanceFoundReissue with no resulting security ids.
Issuer: Insufficient shares authorized, StockClass: Insufficient shares authorizedAn issuance would exceed the issuer or class cap.
InsufficientIssuerSharesAuthorized: shares_issued exceeds newSharesAuthorizedAn issuer adjustment below the issued shares.
InsufficientStockClassSharesAuthorized: stock class authorized shares exceeds issuer shares authorizedA class adjustment above the issuer’s cap.
No active security ids foundA transfer from a stakeholder with no securities in the class.
Invalid mint params, Shares already seeded, Seed shares must be minted first, Seeded positions already exist, Active positions do not match issuer shares issued, and similarSeeding inputs are inconsistent or seeding already ran.

StockLib errors are listed in Stock Library. The contract doesn’t enforce every share-cap relationship; see Security.

CapTableFactory

FunctionAccessEffect
constructor(implementation, initialOwner)DeployStores the implementation, sets the owner, and CREATE2-deploys the beacon with BEACON_SALT.
createCapTable(id, name, initialSharesAuthorized, operator)AnyoneDeploys and initializes a BeaconProxy with the caller as ADMIN, stores it, emits CapTableCreated(capTableProxy), and returns its address. Reverts with Invalid issuer params for a zero id or zero shares.
updateCapTableImplementation(newImplementation)OwnerPoints the beacon at a new implementation; emits CapTableImplementationUpdated(old, new).
owner(), transferOwnership(newOwner), renounceOwnership()Anyone reads; owner writesOpenZeppelin Ownable. Renouncing ends upgrades for every cap table on the factory.
capTableImplementation(), capTableBeacon(), BEACON_SALT()AnyoneThe current implementation, the beacon, and its salt.
capTableProxies(i), getCapTableCount()AnyoneEvery cap table the factory created, and the count.

Libraries

LibraryFunctionPurpose
StockLibcreateIssuance, createTransfer, createCancellation, createRetraction, createReissuance, createRepurchase, createAcceptanceStock logic; see Stock Library.
TxHelpercreateTxStores an encoded transaction and emits TxCreated.
TxHelpergenerateDeterministicUniqueIDDerives bytes16 ids from an input id, the block, and the nonce.
TxHelpercreate*Struct, adjust*Build the transaction payloads.
DeleteContextdeleteActivePosition, deleteActiveSecurityIdsByStockClassRemove a closed security, keeping the rest in issuance order.
AdjustmentadjustIssuerAuthorizedShares, adjustStockClassAuthorizedSharesApply and record authorized-share changes.

Related: Solidity Cap Table, Structs Library, and Stock Library.

Last updated on