Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9f670dc
create deposits table
dkuthoore Oct 28, 2025
a82c54e
create deposit helper functions
dkuthoore Oct 28, 2025
bcb380c
create on-chain vault validator
dkuthoore Oct 28, 2025
a460d3c
create ERC20 and ETH deposit discovery functions
dkuthoore Oct 28, 2025
1a958cf
create AssignDeposit validator function
dkuthoore Oct 28, 2025
6569490
create AssignDeposit handler in proposer
dkuthoore Oct 28, 2025
297b611
add AssignDeposit logic to publishBundle
dkuthoore Oct 28, 2025
5df347a
create deposits db tests
dkuthoore Oct 28, 2025
ad7e965
formatting fixes
dkuthoore Oct 28, 2025
b5a094d
extract intention-specific logic into util files
dkuthoore Oct 29, 2025
77ed0e1
Merge branch 'main' into dk/assignDeposit
dkuthoore Oct 29, 2025
1cf8c73
lint fixes
dkuthoore Oct 29, 2025
718f8df
function name change
dkuthoore Oct 29, 2025
7ead857
add new deposit assignment events table
dkuthoore Oct 29, 2025
94a7e3a
add partial assignment functions to deposit utility
dkuthoore Oct 29, 2025
733b208
Update AssignDeposit handler to support partial assignment
dkuthoore Oct 29, 2025
fe13013
update proposer to createAssignmentEvent
dkuthoore Oct 29, 2025
3274c18
update deposits db test
dkuthoore Oct 29, 2025
a7f34dc
remove unused deposits functions, update test, update README
dkuthoore Oct 29, 2025
15be675
format fixes
dkuthoore Oct 29, 2025
13bbb25
remove alchemy uniqueID for transferUid
dkuthoore Oct 29, 2025
30b2c46
remove credited_vault column, add chain_id to token index, fixed cono…
dkuthoore Oct 30, 2025
ad56d71
extract validator functions from proposer into validator file
dkuthoore Oct 30, 2025
e1bc128
remove controller from discovery function inputs, remove fromAddress …
dkuthoore Oct 30, 2025
49c4d82
remove seedProposerVaultMapping function
dkuthoore Oct 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ The setup script creates the following tables:
- **nonces:** Tracks the latest nonce for each vault.
- **proposers:** Records block proposers.
- **vaults:** Maps vault IDs to controller addresses and optional rules.
- **deposits:** Records on-chain deposits for assignment to vault balances.
- **deposit_assignment_events:** Records partial or full assignment events against deposits. A deposit becomes fully assigned when the sum of its assignment events equals its original amount; in that case, `deposits.assigned_at` is set automatically.

If deploying to Heroku, run the migration script as follows:

Expand All @@ -151,6 +153,10 @@ chmod +x migrations/1_createTable.sh

Alternatively, execute the SQL commands manually in your PostgreSQL instance.

### Partial Deposit Assignments

The `deposits` table records raw on-chain deposits, and `deposit_assignment_events` records partial or full assignments against those deposits. A deposit’s remaining amount is `deposits.amount - SUM(deposit_assignment_events.amount)`; when it reaches zero, `deposits.assigned_at` is set.

## Filecoin Pin Setup (Optional)

The Oya node supports optional archival storage on Filecoin using the [filecoin-pin SDK](https://github.com/filecoin-shipyard/filecoin-pin). When enabled, bundle data is automatically uploaded to both IPFS and Filecoin for redundancy and long-term permanence.
Expand Down
36 changes: 34 additions & 2 deletions scripts/shared/db-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,27 @@ CREATE TABLE IF NOT EXISTS vaults (
rules TEXT,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

-- Create the deposits table (tracks on-chain deposits to VaultTracker)
CREATE TABLE IF NOT EXISTS deposits (
id SERIAL PRIMARY KEY,
tx_hash TEXT NOT NULL,
transfer_uid TEXT NOT NULL UNIQUE,
chain_id INTEGER NOT NULL,
depositor TEXT NOT NULL,
token TEXT NOT NULL,
amount NUMERIC(78, 0) NOT NULL,
assigned_at TIMESTAMPTZ
);

-- Create the deposit_assignment_events table (supports partial assignments)
CREATE TABLE IF NOT EXISTS deposit_assignment_events (
id SERIAL PRIMARY KEY,
deposit_id INTEGER NOT NULL REFERENCES deposits(id) ON DELETE CASCADE,
amount NUMERIC(78, 0) NOT NULL,
credited_vault TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
`

/**
Expand All @@ -90,12 +111,23 @@ CREATE INDEX IF NOT EXISTS idx_bundles_ipfs_cid ON bundles(ipfs_cid);

-- Create GIN index on vaults controllers array for efficient lookups
CREATE INDEX IF NOT EXISTS idx_vaults_controllers ON vaults USING GIN (controllers);

-- Create indexes for deposits table
CREATE INDEX IF NOT EXISTS idx_deposits_tx_hash ON deposits(tx_hash);
CREATE INDEX IF NOT EXISTS idx_deposits_depositor ON deposits(depositor, chain_id);
CREATE INDEX IF NOT EXISTS idx_deposits_token ON deposits(token, chain_id);

-- Create indexes for deposit_assignment_events table
CREATE INDEX IF NOT EXISTS idx_assignment_deposit ON deposit_assignment_events(deposit_id);
CREATE INDEX IF NOT EXISTS idx_assignment_credited_vault ON deposit_assignment_events(credited_vault);
`

/**
* SQL statements for dropping tables
*/
export const dropTablesSql = `
DROP TABLE IF EXISTS deposit_assignment_events CASCADE;
DROP TABLE IF EXISTS deposits CASCADE;
DROP TABLE IF EXISTS bundles CASCADE;
DROP TABLE IF EXISTS cids CASCADE;
DROP TABLE IF EXISTS balances CASCADE;
Expand Down Expand Up @@ -145,7 +177,7 @@ export async function setupDatabase(options) {

if (!forceDropConfirm) {
console.log(chalk.red('\n⚠️ WARNING: This will DELETE ALL DATA in the following tables:'))
console.log(chalk.red(' - bundles, cids, balances, nonces, proposers, vaults'))
console.log(chalk.red(' - bundles, cids, balances, vaults, proposers, deposits, deposit_assignment_events'))
console.log(chalk.yellow('\nTo confirm, set FORCE_DROP=true or remove --drop-existing flag'))
await pool.end()
process.exit(1)
Expand All @@ -171,7 +203,7 @@ export async function setupDatabase(options) {
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
AND table_name IN ('bundles', 'cids', 'balances', 'nonces', 'proposers', 'vaults')
AND table_name IN ('bundles', 'cids', 'balances', 'nonces', 'proposers', 'vaults', 'deposits', 'deposit_assignment_events')
ORDER BY table_name
`)

Expand Down
2 changes: 2 additions & 0 deletions src/config/dbSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ export const REQUIRED_TABLES = [
'nonces',
'proposers',
'vaults',
'deposits',
'deposit_assignment_events',
] as const
Loading