API ReferenceControllers

Controllers

Controllers bridge the Express routes and CapTable.sol. They convert OCF data into the structs the contract expects and send the transaction; the event poller then syncs the resulting events back into MongoDB.

⚠️

Quantities and prices are scaled by 1e10 (10_000_000_000) via toScaledBigNumber(). Divide raw onchain values by 1e10 to match the numbers in API examples.

Conversion

Lifecycle

Common patterns

  • Convert IDs and numbers first: convertUUIDToBytes16(), toScaledBigNumber().
  • Wait for confirmation: const tx = await contract.method(...); await tx.wait();.
  • Logs use ✅ and ⏳ prefixes.
  • seed.js holds legacy bulk helpers (open TODO on dates).

Controller Reference

AreaMain FunctionsWhat It DoesContract Method
IssuerconvertAndAdjustIssuerAuthorizedSharesOnChainScales shares and adjusts issuer authorized amountadjustIssuerAuthorizedShares
StakeholderconvertAndReflectStakeholderOnchain, addWalletToStakeholder, removeWalletFromStakeholder, gettersCreates stakeholder + manages walletscreateStakeholder, addWalletToStakeholder, getStakeholderById, etc.
Stock ClassconvertAndReflectStockClassOnchain, convertAndAdjustStockClassAuthorizedSharesOnchain, gettersCreates class and adjusts authorized sharescreateStockClass, adjustStockClassAuthorizedShares
TransactionsconvertAndCreate*Onchain (one per file)Full equity lifecycle (issue, transfer, cancel, repurchase, reissue, retract, accept)issueStock, transferStock, cancelStock, repurchaseStock, etc.

Notes on Transactions:

  • issuanceController.js is the most complex (uses helper for defaults).
  • Most pair 1:1 with an OCF schema and a Solidity function.
  • Equity compensation and convertible issuances are offchain-only (no controller).

How a POST route uses a controller

  1. Issuer middleware attaches req.contract.
  2. The OCF body is validated.
  3. The matching controller converts and sends the transaction.
  4. The OCF record is saved to MongoDB.
  5. The poller backfills anything emitted by the contract.

For walkthroughs see Create Stakeholder, Create Stock Class, Issue Stock, and Transfer Stock. For the contract-side reference see Solidity Reference and Stock Library.