Skip to the content
TAPEHOUSE

Contracts

Contracts overview

How the Tapehouse contracts fit together, which are Solidity and which are Stylus, where the source lives and how to build, test and verify it.

Tapehouse is a set of contracts on Robinhood Chain. Two are Stylus programs written in Rust, the band and the margin engine. The rest are Solidity contracts that read them. This page maps the set. Each contract has its own reference page, and Addresses lists every deployed address.

Everything here runs on the Robinhood Chain testnet (chain ID 46630) and is unaudited.

How they relate#

Text
                    Stylus                                  Solidity
              +------------------+
              |  Band            |---- BandFeed (one per asset, seals the band before each reopen)
              |  price + session |---- MorphoBandOracle
              +--------+---------+
                       |
              +--------v---------+      +-----------------+
              |  Margin engine   |<-----|  MarginAccounts |---- SupplyVault (USDG lenders)
              |  portfolio rules |      |  positions      |---- StockLendingVault (one per Stock Token)
              +------------------+      +----+-----+------+---- Basket (index shares as collateral)
                                             |     |
                          +------------------+     +------------+
                          |                                     |
                    +-----v-----+   hold / settle / writeOff   +v-------------+
                    | Liquidator|<-----------------------------| GapBackstop  |
                    +-----+-----+                              +^-------------+
                          |  Dutch auction                      | buyRemainder, cover
                    +-----v--------------+                      |
                    | ReopeningAuction   |----------------------+
                    +--------------------+

    ShortPositions: borrows from each StockLendingVault, sells through Uniswap v3
    GapCover:       reads the band and the margin engine, pays USDG after a closure
    SponsorPaymaster: pays gas through the ERC-4337 EntryPoint

The margin accounts hold every position and call the engine to decide what a position may borrow. The liquidator sells what falls short, in a Dutch auction while the market is open. Over a weekend or holiday closure, the reopening auction sells it in one sealed-bid batch at NYSE's open, and the gap backstop buys what the bids leave and covers what a position still owes after that.

What each contract is for#

ContractLanguageWhat it doesPage
BandStylusPrices each Stock Token as a band and reports the sessionBand
Margin engineStylusMargins a portfolio and returns its requirementMargin engine
BandFeedSolidityServes one asset's band behind Chainlink's AggregatorV3Interface and seals it before each reopenBand feeds
MorphoBandOracleSolidityPrices a Stock Token for a Morpho Blue market at the band's low edgeMorpho oracle
SupplyVaultSolidityERC-4626 vault where lenders deposit USDG for the accounts to borrowSupply vault
MarginAccountsSolidityHolds cross and isolated positions, deposits, loans and repaymentsMargin accounts
LiquidatorSoliditySells a position that falls short in a Dutch auctionLiquidator
GapBackstopSolidityJunior ERC-4626 tranche that covers shortfalls and buys what the reopening bids leaveGap backstop
ReopeningAuctionSoliditySealed-bid, uniform-price batch at NYSE's regular open after a closureReopening auction
StockLendingVaultSolidityLends one Stock Token for a fee, one vault per tokenStock lending
ShortPositionsSolidityShorts a Stock Token against USDG marginShort positions
BasketSolidityAn ERC-20 share of a fixed set of Stock Tokens, minted and redeemed in kindBaskets
GapCoverSoliditySells cover against a Stock Token's fall over a closureGap cover
SponsorPaymasterSolidityERC-4337 paymaster that pays gas for a new account's first operationsSponsor paymaster

Two more Solidity contracts have no page of their own. RedStoneRoundFeed is a Chainlink-compatible feed with rounds, for a chain where an asset has no Chainlink feed, and the gap cover reads it through the band. StockTokenWrapper is a one-to-one ERC-20 over a Stock Token with the views the band and the accounts read.

Repository directories#

DirectoryContents
contracts/srcSolidity sources, with interfaces in contracts/src/interfaces
contracts/testFoundry unit, invariant and fork tests
contracts/scriptDeploy and verify scripts the make targets call
stylus/contracts/band and stylus/contracts/marginThe two Stylus programs
stylus/cratesRust code the programs share
deploymentsOne registry file per chain, named by chain ID, for example deployments/46630.json

The Solidity contracts are compiled with solc 0.8.37 and the Osaka EVM target, built on OpenZeppelin, and tested with Foundry 1.8.3. The SDKs read every address from the registry file and compile none in.

Build and test#

Clone the repository and run:

Shell
git clone https://github.com/Tapehouse-Labs/TAPEHOUSE.git tapehouse
cd tapehouse
make build
make test

make build initialises git submodules and installs JavaScript dependencies on first run. It stops with a message if Node, Foundry or cargo-stylus does not match the pinned versions.

TargetWhat it does
make build-contractsforge build in contracts
make test-contractsforge test in contracts, plus the Uniswap testnet deployment's tests
make lint-contractsforge fmt --check, forge lint --deny warnings and Slither
make coverage-contractsSolidity coverage, failing below 95% of lines or branches
make gas-contractsContract sizes and gas snapshots, failing on any change
make build-stylus and make test-stylusThe Stylus programs only
make bindingsRebuilds the contracts and regenerates the SDKs' bindings from their ABIs
make check-activationcargo stylus check of every program against Robinhood Chain, its testnet and Arbitrum One

Fork tests read the chain through the ROBINHOOD_RPC_URL endpoint that contracts/foundry.toml names.

Verify a deployment#

Each Solidity contract has a make verify-* target that rebuilds its constructor arguments from the chain and verifies it on Sourcify, which supports the three chains the repository targets and the compiler it pins:

Shell
make verify-gap-backstop CHAIN=46630
make verify-reopening-auction CHAIN=46630
make verify-stock-lending CHAIN=46630
make verify-short-positions CHAIN=46630
make verify-baskets CHAIN=46630
make verify-sponsor-paymaster CHAIN=46630

The other targets are verify-band-feeds, verify-supply-vault, verify-margin-accounts and verify-liquidator. verify-gap-cover and verify-morpho-oracles accept only CHAIN=4663. A Stylus program verifies by rebuilding it in the reproducible Docker image and comparing it with the code on chain:

Shell
make verify-stylus CHAIN=46630 TX=<deployment tx> CONTRACT=<band|margin>

It passes only when cargo-stylus prints Verification successful. Verification covers the procedure.

Next#