Skip to Content
Tables

Tables

Tables keep your protocol’s on-chain data as rows that stay current: loans, withdrawal requests, pools, liquidity positions, swaps or deposits. Explore and export them in the app, and build metrics, alerts and reports on them.

Two kinds of table

KindOne row perExample
State tableThing an event announces: a loan, a pool, a withdrawal request, a liquidity positionLoans, with what each borrower owes, read live
Activity tableEvent, or group of eventsSwaps over $10,000; the top 10 traders by volume over 7 days

State tables

A row starts with the event that announces it and is identified by one of its fields: each LoanOpened is a loan, identified by its loanId. Where no single field names a row, up to three do together, such as a position’s owner and price range.

A new table reads the contracts’ whole history for its rows, then adds each new one as it is announced. A row stays open until its finishing rule holds, such as a LoanClosed with the same id. A finished row keeps its final values and stops being read.

A withdrawal requests table might hold:

RequestRequestedPaidOutstandingStatus
#1042$50,000$20,000$30,000Partially paid
#1043$75,000$0$75,000Pending
#1044$25,000$25,000$0Complete

Activity tables

An activity table keeps events as rows: every swap over $10,000, or every deposit in the last 30 days. Each row can carry figures worked out for its event, such as its value in dollars on the day. Events can be grouped and ranked: the top 10 traders by volume over the last 7 days. An activity table can also be built on another table, or on a metric’s records.

An activity table can keep only the events of a state table’s rows, such as the swaps of the pools in a Pools table, and each event then names its row. It can also read a contract a whole chain shares, such as Uniswap v4’s PoolManager, for your protocol’s part alone, without watching it.

Columns

ColumnWhat it holdsExample
ReadA contract view called for each open row, kept currentWhat a loan’s borrower owes
Count or sumThe row’s events counted, or a field added up, over its whole life or a window such as the last 7 daysRequested, Paid
CalculatedAn expression over the row’s other columnsOutstanding: {Requested} - {Paid}
StatusA label from rules you definePending, Partially paid, Complete

A count or sum can be split by a field, such as a row’s deposits by token, or add up an activity table’s rows: each pool’s fees over the last 7 days from a Swaps table. A calculated column can read a column’s earlier value: {Deposits} - ago({Deposits}, 7d) is the week’s change. See Formulas.

A number is a token amount only when its column names the token. It then shows in whole tokens, or, where the column asks for it, in dollars at the current price.

Row pages

A state table can give each row a page of its own, for things with more to show than one line, such as a pool or a loan. A row’s page shows its columns, how each number moved day by day, what each split column breaks into, and the row’s events from linked activity tables.

Work with a table

Open a table from Tables in the contract.dev app.

  • Search — Find a state table’s rows by name, id or contract address.
  • Filter and sort — Filter on a column’s values and sort by any column.
  • Group — Group a state table’s rows by a column, such as a status or the contract.
  • Window — Narrow an activity table kept over 7, 30 or 90 days to a shorter window, such as its last 24 hours.
  • Hide or remove columns — Hide a column from your view, or remove it from the table.
  • Export — Download a state table’s rows as CSV or JSON, or an activity table’s as CSV.
  • Share a view — The URL keeps the filters, sort, grouping and visible columns.
  • Delete — Delete a table with its rows and every alert on it.

Use a table elsewhere

  • Metrics — Add up a column or count rows. See Metrics from tables.
  • Activity alerts — A message when a row opens or finishes, such as a loan repaid. See Activity alerts.
  • Condition alerts — A rule on a read column of every open row, such as any loan’s health factor below 1.1. Each row alerts and clears on its own. See Condition alerts.
  • Reports — A table’s top rows on a schedule. See Reports.
  • Overview — A table’s top rows on the Overview.

Ask your agent

Tables are created and changed by your coding agent, the Slack/Telegram assistant or the CLI. Describe the table you want. Your agent finds the contracts and events, writes the columns and creates the table. See Agent Integration.

Create a table of our withdrawal requests with Requested, Paid, Outstanding and Status.
Show our top 20 traders by volume this week as a table.
Make a table of our pools with each one's fees over the last 7 days, and pin it to the Overview.

From the CLI

A state table names the event that announces a row, its id, what to read for it and when it finishes:

contract-dev table create "Loans" --on group:markets --each LoanOpened --id loanId \ --column "Owed=accountDebt(id())" --finished "seen(LoanClosed)"

An activity table names the events, with an optional condition:

contract-dev table create "Big swaps" --on group:pools --each Swap \ --where "usd(abs(amount0), token0()) > 10000"

A table built on another names it with --on table::

contract-dev table create "Whales" --on table:"Big swaps" --by wallet --top 10

A state table takes more columns later with table update:

contract-dev table update "Pools" --sum 'Fees 7d=feeusd from table:"Swaps" last 7d'

A table your agent makes only to answer a question stays off the Tables page. See table for every flag, and table show to read a table from the terminal.

Last updated on