-
Notifications
You must be signed in to change notification settings - Fork 1
Multi pool support #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
ef5ca4c
chore: update blend and stellar dependencies
Ryang-21 6d49339
feat: add blend v2 compatibility
Ryang-21 f95ac6c
feat: add init event to check proper pool loading on startup
Ryang-21 31df054
chore: update docs and example for version
Ryang-21 0d7a527
chore: set default auction type
Ryang-21 f31158f
feat: implement multi pool support
Ryang-21 cbdd9ff
fix: remove poolConfig from pool agnostic app events
Ryang-21 6835611
chore: add name to pool config
Ryang-21 9fd54d1
chore: implement db migration to v2
Ryang-21 0c3135e
fix: revert blend v2 compatibility
Ryang-21 aa53810
chore: update example config and README
Ryang-21 65bf91f
chore: cache errors on load with timer to prevent rpc spam
Ryang-21 8103777
chore: remove pool config check
Ryang-21 1636dcc
fix: properly sort users will pool config
Ryang-21 19519fe
chore: add test coverage and cleanup code format
Ryang-21 01bfdf8
chore: replace backstopAddress arg with backstop address from app config
Ryang-21 1272470
chore: add tests to check short circuit when unable to find pool conf…
Ryang-21 12760d1
fix: place migration scripts at root and handle default pool id updat…
Ryang-21 34a631a
fix: seperate prices by oracle id
Ryang-21 363fdfd
fix: set pool configs to be filler specific and clean up log messages
Ryang-21 23bd046
chore: organize db files to folder
Ryang-21 8acfc3d
chore: bump depdendencies and fix log message
Ryang-21 f5d4d19
fix: check fillers supported pools when assigning filler
Ryang-21 a8091b6
chore: format logging
Ryang-21 99e6c54
chore: update tests replacing PoolConfig for FillerPoolConfig
Ryang-21 f12e6a1
chore: cleanup test and unused imports
Ryang-21 1fec978
chore: update readme and example config
Ryang-21 34abc43
chore: add pool clarification to logs
Ryang-21 c4bf24e
fix: check liability is greater than 0 before repay and fix log
Ryang-21 1d89d4d
chore: implement feedback fixes
Ryang-21 b699583
chore: remove cached errors and handle user refresh by pool
Ryang-21 a6ee43a
chore: fix depdendencies and remove unused import
Ryang-21 ca4e5aa
chore: improve db migration robustness
Ryang-21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| -- Migration steps | ||
|
|
||
| -- Migrate users table | ||
|
|
||
| -- Create new table with pool_id | ||
| CREATE TABLE users_new ( | ||
| pool_id TEXT NOT NULL, | ||
| user_id TEXT NOT NULL, | ||
| health_factor REAL NOT NULL, | ||
| collateral JSON NOT NULL, | ||
| liabilities JSON, | ||
| updated INTEGER NOT NULL, | ||
| PRIMARY KEY (pool_id, user_id) | ||
| ); | ||
|
|
||
| -- Copy data to new table with default pool_id | ||
| INSERT INTO users_new ( | ||
| pool_id, | ||
| user_id, | ||
| health_factor, | ||
| collateral, | ||
| liabilities, | ||
| updated | ||
| ) | ||
| SELECT | ||
| 'default_pool', | ||
| user_id, | ||
| health_factor, | ||
| collateral, | ||
| liabilities, | ||
| updated | ||
| FROM users; | ||
|
|
||
| -- Drop old table | ||
| DROP TABLE users; | ||
|
|
||
| -- Rename new table | ||
| ALTER TABLE users_new RENAME TO users; | ||
|
|
||
| -- Recreate indexes | ||
| CREATE INDEX IF NOT EXISTS idx_health_factor ON users(health_factor); | ||
|
|
||
| -- Migrate auctions table | ||
| -- Check if pool_id column exists | ||
|
|
||
| -- Create new table with pool_id | ||
| CREATE TABLE auctions_new ( | ||
| pool_id TEXT NOT NULL, | ||
| user_id TEXT NOT NULL, | ||
| auction_type INTEGER NOT NULL, | ||
| filler TEXT NOT NULL, | ||
| start_block INTEGER NOT NULL, | ||
| fill_block INTEGER NOT NULL, | ||
| updated INTEGER NOT NULL, | ||
| PRIMARY KEY (pool_id, user_id, auction_type) | ||
| ); | ||
|
|
||
| -- Copy data to new table with default pool_id | ||
| INSERT INTO auctions_new ( | ||
| pool_id, | ||
| user_id, | ||
| auction_type, | ||
| filler, | ||
| start_block, | ||
| fill_block, | ||
| updated | ||
| ) | ||
| SELECT | ||
| 'default_pool', | ||
| user_id, | ||
| auction_type, | ||
| filler, | ||
| start_block, | ||
| fill_block, | ||
| updated | ||
| FROM auctions; | ||
|
|
||
| -- Drop old table | ||
| DROP TABLE auctions; | ||
|
|
||
| -- Rename new table | ||
| ALTER TABLE auctions_new RENAME TO auctions; | ||
|
|
||
| -- Migrate filled_auctions table | ||
| -- Check if pool_id column exists | ||
|
|
||
| -- Create new table with pool_id | ||
| CREATE TABLE filled_auctions_new ( | ||
| tx_hash TEXT PRIMARY KEY, | ||
| pool_id TEXT NOT NULL, | ||
| filler TEXT NOT NULL, | ||
| user_id TEXT NOT NULL, | ||
| auction_type INTEGER NOT NULL, | ||
| bid JSON NOT NULL, | ||
| bid_total REAL NOT NULL, | ||
| lot JSON NOT NULL, | ||
| lot_total REAL NOT NULL, | ||
| est_profit REAL NOT NULL, | ||
| fill_block INTEGER NOT NULL, | ||
| timestamp INTEGER NOT NULL | ||
| ); | ||
|
|
||
| -- Copy data to new table with default pool_id | ||
| INSERT INTO filled_auctions_new ( | ||
| tx_hash, | ||
| pool_id, | ||
| filler, | ||
| user_id, | ||
| auction_type, | ||
| bid, | ||
| bid_total, | ||
| lot, | ||
| lot_total, | ||
| est_profit, | ||
| fill_block, | ||
| timestamp | ||
| ) | ||
| SELECT | ||
| tx_hash, | ||
| 'default_pool', | ||
| filler, | ||
| user_id, | ||
| auction_type, | ||
| bid, | ||
| bid_total, | ||
| lot, | ||
| lot_total, | ||
| est_profit, | ||
| fill_block, | ||
| timestamp | ||
| FROM filled_auctions; | ||
|
|
||
| -- Drop old table | ||
| DROP TABLE filled_auctions; | ||
|
|
||
| -- Rename new table | ||
| ALTER TABLE filled_auctions_new RENAME TO filled_auctions; | ||
|
|
||
| -- Recreate index | ||
| CREATE INDEX IF NOT EXISTS idx_filler ON filled_auctions(filler); | ||
|
|
||
| -- Update version information | ||
| INSERT INTO db_version ( | ||
| version, | ||
| description, | ||
| applied_at | ||
| ) VALUES ( | ||
| 2, | ||
| 'Add pool_id column to users, auctions, and filled_auctions tables', | ||
| unixepoch() | ||
| ); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Set variables | ||
| DB_PATH="./data/auctioneer.sqlite" | ||
| V2_MIGRATION_SCRIPT="./db/migrate_db_v1_to_v2.sql" | ||
|
|
||
| PREV_POOL_ID="" | ||
| DOES_DB_EXIST=1 | ||
| CURRENT_DB_VERSION=2 | ||
|
|
||
| # Function to display usage information | ||
| show_usage() { | ||
| echo "Usage: $0 [options]" | ||
| echo "Options:" | ||
| echo " -h, --help Show this help message" | ||
| echo " -p, --prev-pool-id ID Previous pool ID (required for v2 migration)" | ||
| } | ||
| # Parse command line arguments | ||
| while [[ $# -gt 0 ]]; do | ||
| case $1 in | ||
| -h|--help) | ||
| show_usage | ||
| exit 0 | ||
| ;; | ||
| -p|--prev-pool-id) | ||
| if [ -z "$2" ]; then | ||
| shift | ||
| fi | ||
| PREV_POOL_ID="$2" | ||
| shift 2 | ||
| ;; | ||
| *) | ||
| echo "Error: Unknown option $1" | ||
| show_usage | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| # Check if sqlite3 is installed | ||
| if ! command -v sqlite3 &> /dev/null; then | ||
| echo "Error: sqlite3 is not installed. Please install SQLite3." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if database file exists | ||
| if ! test -f $DB_PATH; then | ||
| # Initialize the database | ||
| DOES_DB_EXIST=0 | ||
| fi | ||
|
|
||
| # Check that all tables exist or create them | ||
| sqlite3 ./data/auctioneer.sqlite < ./db/init_db.sql | ||
|
|
||
| if [ "$DOES_DB_EXIST" -eq 0 ]; then | ||
| sqlite3 "$DB_PATH" " | ||
| INSERT INTO db_version (version, description, applied_at) | ||
| SELECT 2, 'init db', unixepoch(); | ||
| " | ||
| echo "Database initialized." | ||
| fi | ||
|
|
||
| # Check if migration script exists | ||
| if [ ! -f "$V2_MIGRATION_SCRIPT" ]; then | ||
| echo "Error: Migration script $V2_MIGRATION_SCRIPT does not exist." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Function to get current database version | ||
| get_current_version() { | ||
| sqlite3 "$DB_PATH" " | ||
| CREATE TABLE IF NOT EXISTS db_version ( | ||
| version INTEGER PRIMARY KEY NOT NULL, | ||
| description TEXT NOT NULL, | ||
| applied_at INTEGER NOT NULL | ||
| ); | ||
| SELECT COALESCE(MAX(version), 0) FROM db_version; | ||
| " | ||
| } | ||
|
|
||
| # Get current version | ||
| CURRENT_VERSION=$(get_current_version) | ||
|
|
||
| # Check if migration should be applied | ||
| if [ "$CURRENT_VERSION" -lt 2 ]; then | ||
| # Check if previous pool ID is provided for v2 migration | ||
| if [ -z "$PREV_POOL_ID" ]; then | ||
| echo "Error: Previous pool ID is required for v2 migration." | ||
| echo "Please provide it using the -p or --prev-pool-id option." | ||
| exit 1 | ||
| fi | ||
| echo "Applying migration to version 2..." | ||
|
|
||
| # First run the migration script to create the new tables | ||
| sqlite3 "$DB_PATH" < "$V2_MIGRATION_SCRIPT" | ||
| MIGRATION_RESULT=$? | ||
|
|
||
| # Check if migration was successful | ||
| if [ $MIGRATION_RESULT -eq 0 ]; then | ||
| echo "Migration to version 2 completed successfully." | ||
|
|
||
| # Update the pool_id in all tables | ||
| echo "Updating pool_id to '$PREV_POOL_ID' in all tables..." | ||
|
|
||
| sqlite3 "$DB_PATH" " | ||
| UPDATE users SET pool_id = '$PREV_POOL_ID' WHERE pool_id = 'default_pool'; | ||
| UPDATE auctions SET pool_id = '$PREV_POOL_ID' WHERE pool_id = 'default_pool'; | ||
| UPDATE filled_auctions SET pool_id = '$PREV_POOL_ID' WHERE pool_id = 'default_pool'; | ||
| " | ||
|
|
||
| # Check if migration was successful | ||
| if [ $? -eq 0 ]; then | ||
| echo "Successfully updated pool id to $PREV_POOL_ID." | ||
| else | ||
| echo "Error: Failed to update pool id." | ||
| exit 1 | ||
| fi | ||
| fi | ||
| fi |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.