-
Notifications
You must be signed in to change notification settings - Fork 1
Index DBC Configs #492
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
Index DBC Configs #492
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| BEGIN; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS sol_meteora_dbc_configs ( | ||
| account TEXT PRIMARY KEY, | ||
| slot BIGINT NOT NULL, | ||
| quote_mint TEXT NOT NULL, | ||
| fee_claimer TEXT NOT NULL, | ||
| leftover_receiver TEXT NOT NULL, | ||
| collect_fee_mode SMALLINT NOT NULL, | ||
| migration_option SMALLINT NOT NULL, | ||
| activation_type SMALLINT, | ||
| token_decimal SMALLINT, | ||
| version SMALLINT, | ||
| token_type SMALLINT, | ||
| quote_token_flag SMALLINT, | ||
| partner_locked_lp_percentage SMALLINT, | ||
| partner_lp_percentage SMALLINT, | ||
| creator_locked_lp_percentage SMALLINT, | ||
| creator_lp_percentage SMALLINT, | ||
| migration_fee_option SMALLINT, | ||
| fixed_token_supply_flag SMALLINT, | ||
| creator_trading_fee_percentage SMALLINT, | ||
| token_update_authority SMALLINT, | ||
| migration_fee_percentage SMALLINT, | ||
| creator_migration_fee_percentage SMALLINT, | ||
| swap_base_amount BIGINT, | ||
| migration_quote_threshold BIGINT, | ||
| migration_base_threshold BIGINT, | ||
| migration_sqrt_price NUMERIC, | ||
| pre_migration_token_supply BIGINT, | ||
| post_migration_token_supply BIGINT, | ||
| migrated_collect_fee_mode SMALLINT, | ||
| migrated_dynamic_fee SMALLINT, | ||
| migrated_pool_fee_bps SMALLINT, | ||
| sqrt_start_price NUMERIC, | ||
| curve JSONB, | ||
| created_at TIMESTAMP DEFAULT NOW(), | ||
| updated_at TIMESTAMP DEFAULT NOW() | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS sol_meteora_dbc_config_fees ( | ||
| config TEXT PRIMARY KEY REFERENCES sol_meteora_dbc_configs(account) ON DELETE CASCADE, | ||
| slot BIGINT NOT NULL, | ||
| base_fee_cliff_fee_numerator BIGINT, | ||
| base_fee_period_frequency BIGINT, | ||
| base_fee_reduction_factor BIGINT, | ||
| base_fee_number_of_period SMALLINT, | ||
| base_fee_fee_scheduler_mode SMALLINT, | ||
| dynamic_fee_initialized SMALLINT, | ||
| dynamic_fee_max_volatility_accumulator INTEGER, | ||
| dynamic_fee_variable_fee_control INTEGER, | ||
| dynamic_fee_bin_step SMALLINT, | ||
| dynamic_fee_filter_period SMALLINT, | ||
| dynamic_fee_decay_period SMALLINT, | ||
| dynamic_fee_reduction_factor SMALLINT, | ||
| dynamic_fee_bin_step_u128 NUMERIC, | ||
| protocol_fee_percent SMALLINT, | ||
| referral_fee_percent SMALLINT | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS sol_meteora_dbc_config_vestings ( | ||
| config TEXT PRIMARY KEY REFERENCES sol_meteora_dbc_configs(account) ON DELETE CASCADE, | ||
| slot BIGINT NOT NULL, | ||
| amount_per_period BIGINT, | ||
| cliff_duration_from_migration_time BIGINT, | ||
| frequency BIGINT, | ||
| number_of_period BIGINT, | ||
| cliff_unlock_amount BIGINT | ||
| ); | ||
|
|
||
| COMMIT; |
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,304 @@ | ||
| package dbc | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "api.audius.co/solana/spl/programs/meteora_dbc" | ||
| "github.com/jackc/pgx/v5" | ||
| ) | ||
|
|
||
| func upsertDbcConfig( | ||
| ctx context.Context, | ||
| tx pgx.Tx, | ||
| slot uint64, | ||
| account string, | ||
| config *meteora_dbc.PoolConfig, | ||
| ) error { | ||
| _, err := tx.Exec(ctx, ` | ||
| INSERT INTO sol_meteora_dbc_configs ( | ||
| account, | ||
| slot, | ||
| quote_mint, | ||
| fee_claimer, | ||
| leftover_receiver, | ||
| collect_fee_mode, | ||
| migration_option, | ||
| activation_type, | ||
| token_decimal, | ||
| version, | ||
| token_type, | ||
| quote_token_flag, | ||
| partner_locked_lp_percentage, | ||
| partner_lp_percentage, | ||
| creator_locked_lp_percentage, | ||
| creator_lp_percentage, | ||
| migration_fee_option, | ||
| fixed_token_supply_flag, | ||
| creator_trading_fee_percentage, | ||
| token_update_authority, | ||
| migration_fee_percentage, | ||
| creator_migration_fee_percentage, | ||
| swap_base_amount, | ||
| migration_quote_threshold, | ||
| migration_base_threshold, | ||
| migration_sqrt_price, | ||
| pre_migration_token_supply, | ||
| post_migration_token_supply, | ||
| migrated_collect_fee_mode, | ||
| migrated_dynamic_fee, | ||
| migrated_pool_fee_bps, | ||
| sqrt_start_price, | ||
| curve, | ||
| created_at, | ||
| updated_at | ||
| ) VALUES ( | ||
| @account, | ||
| @slot, | ||
| @quote_mint, | ||
| @fee_claimer, | ||
| @leftover_receiver, | ||
| @collect_fee_mode, | ||
| @migration_option, | ||
| @activation_type, | ||
| @token_decimal, | ||
| @version, | ||
| @token_type, | ||
| @quote_token_flag, | ||
| @partner_locked_lp_percentage, | ||
| @partner_lp_percentage, | ||
| @creator_locked_lp_percentage, | ||
| @creator_lp_percentage, | ||
| @migration_fee_option, | ||
| @fixed_token_supply_flag, | ||
| @creator_trading_fee_percentage, | ||
| @token_update_authority, | ||
| @migration_fee_percentage, | ||
| @creator_migration_fee_percentage, | ||
| @swap_base_amount, | ||
| @migration_quote_threshold, | ||
| @migration_base_threshold, | ||
| @migration_sqrt_price, | ||
| @pre_migration_token_supply, | ||
| @post_migration_token_supply, | ||
| @migrated_collect_fee_mode, | ||
| @migrated_dynamic_fee, | ||
| @migrated_pool_fee_bps, | ||
| @sqrt_start_price, | ||
| @curve, | ||
| NOW(), | ||
| NOW() | ||
| ) | ||
| ON CONFLICT (account) DO UPDATE | ||
| SET | ||
| slot = EXCLUDED.slot, | ||
| quote_mint = EXCLUDED.quote_mint, | ||
| fee_claimer = EXCLUDED.fee_claimer, | ||
| leftover_receiver = EXCLUDED.leftover_receiver, | ||
| collect_fee_mode = EXCLUDED.collect_fee_mode, | ||
| migration_option = EXCLUDED.migration_option, | ||
| activation_type = EXCLUDED.activation_type, | ||
| token_decimal = EXCLUDED.token_decimal, | ||
| version = EXCLUDED.version, | ||
| token_type = EXCLUDED.token_type, | ||
| quote_token_flag = EXCLUDED.quote_token_flag, | ||
| partner_locked_lp_percentage = EXCLUDED.partner_locked_lp_percentage, | ||
| partner_lp_percentage = EXCLUDED.partner_lp_percentage, | ||
| creator_locked_lp_percentage = EXCLUDED.creator_locked_lp_percentage, | ||
| creator_lp_percentage = EXCLUDED.creator_lp_percentage, | ||
| migration_fee_option = EXCLUDED.migration_fee_option, | ||
| fixed_token_supply_flag = EXCLUDED.fixed_token_supply_flag, | ||
| creator_trading_fee_percentage = EXCLUDED.creator_trading_fee_percentage, | ||
| token_update_authority = EXCLUDED.token_update_authority, | ||
| migration_fee_percentage = EXCLUDED.migration_fee_percentage, | ||
| creator_migration_fee_percentage = EXCLUDED.creator_migration_fee_percentage, | ||
| swap_base_amount = EXCLUDED.swap_base_amount, | ||
| migration_quote_threshold = EXCLUDED.migration_quote_threshold, | ||
| migration_base_threshold = EXCLUDED.migration_base_threshold, | ||
| migration_sqrt_price = EXCLUDED.migration_sqrt_price, | ||
| pre_migration_token_supply = EXCLUDED.pre_migration_token_supply, | ||
| post_migration_token_supply = EXCLUDED.post_migration_token_supply, | ||
| migrated_collect_fee_mode = EXCLUDED.migrated_collect_fee_mode, | ||
| migrated_dynamic_fee = EXCLUDED.migrated_dynamic_fee, | ||
| migrated_pool_fee_bps = EXCLUDED.migrated_pool_fee_bps, | ||
| sqrt_start_price = EXCLUDED.sqrt_start_price, | ||
| curve = EXCLUDED.curve, | ||
| updated_at = NOW() | ||
| WHERE EXCLUDED.slot > sol_meteora_dbc_configs.slot | ||
| `, pgx.NamedArgs{ | ||
| "account": account, | ||
| "slot": slot, | ||
| "quote_mint": config.QuoteMint.String(), | ||
| "fee_claimer": config.FeeClaimer.String(), | ||
| "leftover_receiver": config.LeftoverReceiver.String(), | ||
| "collect_fee_mode": config.CollectFeeMode, | ||
| "migration_option": config.MigrationOption, | ||
| "activation_type": config.ActivationType, | ||
| "token_decimal": config.TokenDecimal, | ||
| "version": config.Version, | ||
| "token_type": config.TokenType, | ||
| "quote_token_flag": config.QuoteTokenFlag, | ||
| "partner_locked_lp_percentage": config.PartnerLockedLpPercentage, | ||
| "partner_lp_percentage": config.PartnerLpPercentage, | ||
| "creator_locked_lp_percentage": config.CreatorLockedLpPercentage, | ||
| "creator_lp_percentage": config.CreatorLpPercentage, | ||
| "migration_fee_option": config.MigrationFeeOption, | ||
| "fixed_token_supply_flag": config.FixedTokenSupplyFlag, | ||
| "creator_trading_fee_percentage": config.CreatorTradingFeePercentage, | ||
| "token_update_authority": config.TokenUpdateAuthority, | ||
| "migration_fee_percentage": config.MigrationFeePercentage, | ||
| "creator_migration_fee_percentage": config.CreatorMigrationFeePercentage, | ||
| "swap_base_amount": config.SwapBaseAmount, | ||
| "migration_quote_threshold": config.MigrationQuoteThreshold, | ||
| "migration_base_threshold": config.MigrationBaseThreshold, | ||
| "migration_sqrt_price": config.MigrationSqrtPrice.String(), | ||
| "pre_migration_token_supply": config.PreMigrationTokenSupply, | ||
| "post_migration_token_supply": config.PostMigrationTokenSupply, | ||
| "migrated_collect_fee_mode": config.MigratedCollectFeeMode, | ||
| "migrated_dynamic_fee": config.MigratedDynamicFee, | ||
| "migrated_pool_fee_bps": config.MigratedPoolFeeBps, | ||
| "sqrt_start_price": config.SqrtStartPrice.String(), | ||
| "curve": config.Curve, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func upsertDbcConfigFees( | ||
| ctx context.Context, | ||
| tx pgx.Tx, | ||
| slot uint64, | ||
| account string, | ||
| fees *meteora_dbc.PoolFeesConfig, | ||
| ) error { | ||
| _, err := tx.Exec(ctx, ` | ||
| INSERT INTO sol_meteora_dbc_config_fees ( | ||
| config, | ||
| slot, | ||
| base_fee_cliff_fee_numerator, | ||
| base_fee_period_frequency, | ||
| base_fee_reduction_factor, | ||
| base_fee_number_of_period, | ||
| base_fee_fee_scheduler_mode, | ||
| dynamic_fee_initialized, | ||
| dynamic_fee_max_volatility_accumulator, | ||
| dynamic_fee_variable_fee_control, | ||
| dynamic_fee_bin_step, | ||
| dynamic_fee_filter_period, | ||
| dynamic_fee_decay_period, | ||
| dynamic_fee_reduction_factor, | ||
| dynamic_fee_bin_step_u128, | ||
| protocol_fee_percent, | ||
| referral_fee_percent | ||
| ) VALUES ( | ||
| @config, | ||
| @slot, | ||
| @base_fee_cliff_fee_numerator, | ||
| @base_fee_period_frequency, | ||
| @base_fee_reduction_factor, | ||
| @base_fee_number_of_period, | ||
| @base_fee_fee_scheduler_mode, | ||
| @dynamic_fee_initialized, | ||
| @dynamic_fee_max_volatility_accumulator, | ||
| @dynamic_fee_variable_fee_control, | ||
| @dynamic_fee_bin_step, | ||
| @dynamic_fee_filter_period, | ||
| @dynamic_fee_decay_period, | ||
| @dynamic_fee_reduction_factor, | ||
| @dynamic_fee_bin_step_u128, | ||
| @protocol_fee_percent, | ||
| @referral_fee_percent | ||
| ) | ||
| ON CONFLICT (config) DO UPDATE | ||
| SET | ||
| slot = EXCLUDED.slot, | ||
| base_fee_cliff_fee_numerator = EXCLUDED.base_fee_cliff_fee_numerator, | ||
| base_fee_period_frequency = EXCLUDED.base_fee_period_frequency, | ||
| base_fee_reduction_factor = EXCLUDED.base_fee_reduction_factor, | ||
| base_fee_number_of_period = EXCLUDED.base_fee_number_of_period, | ||
| base_fee_fee_scheduler_mode = EXCLUDED.base_fee_fee_scheduler_mode, | ||
| dynamic_fee_initialized = EXCLUDED.dynamic_fee_initialized, | ||
| dynamic_fee_max_volatility_accumulator = EXCLUDED.dynamic_fee_max_volatility_accumulator, | ||
| dynamic_fee_variable_fee_control = EXCLUDED.dynamic_fee_variable_fee_control, | ||
| dynamic_fee_bin_step = EXCLUDED.dynamic_fee_bin_step, | ||
| dynamic_fee_filter_period = EXCLUDED.dynamic_fee_filter_period, | ||
| dynamic_fee_decay_period = EXCLUDED.dynamic_fee_decay_period, | ||
| dynamic_fee_reduction_factor = EXCLUDED.dynamic_fee_reduction_factor, | ||
| dynamic_fee_bin_step_u128 = EXCLUDED.dynamic_fee_bin_step_u128, | ||
| protocol_fee_percent = EXCLUDED.protocol_fee_percent, | ||
| referral_fee_percent = EXCLUDED.referral_fee_percent | ||
| WHERE EXCLUDED.slot > sol_meteora_dbc_config_fees.slot | ||
| `, pgx.NamedArgs{ | ||
| "config": account, | ||
| "slot": slot, | ||
| "base_fee_cliff_fee_numerator": fees.BaseFee.CliffFeeNumerator, | ||
| "base_fee_period_frequency": fees.BaseFee.PeriodFrequency, | ||
| "base_fee_reduction_factor": fees.BaseFee.ReductionFactor, | ||
| "base_fee_number_of_period": fees.BaseFee.NumberOfPeriod, | ||
| "base_fee_fee_scheduler_mode": fees.BaseFee.FeeSchedulerMode, | ||
| "dynamic_fee_initialized": fees.DynamicFee.Initialized, | ||
| "dynamic_fee_max_volatility_accumulator": fees.DynamicFee.MaxVolatilityAccumulator, | ||
| "dynamic_fee_variable_fee_control": fees.DynamicFee.VariableFeeControl, | ||
| "dynamic_fee_bin_step": fees.DynamicFee.BinStep, | ||
| "dynamic_fee_filter_period": fees.DynamicFee.FilterPeriod, | ||
| "dynamic_fee_decay_period": fees.DynamicFee.DecayPeriod, | ||
| "dynamic_fee_reduction_factor": fees.DynamicFee.ReductionFactor, | ||
| "dynamic_fee_bin_step_u128": fees.DynamicFee.BinStepU128.String(), | ||
| "protocol_fee_percent": fees.ProtocolFeePercent, | ||
| "referral_fee_percent": fees.ReferralFeePercent, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func upsertDbcConfigVesting( | ||
| ctx context.Context, | ||
| tx pgx.Tx, | ||
| slot uint64, | ||
| account string, | ||
| vesting *meteora_dbc.LockedVestingConfig, | ||
| ) error { | ||
| _, err := tx.Exec(ctx, ` | ||
| INSERT INTO sol_meteora_dbc_config_vestings ( | ||
| config, | ||
| slot, | ||
| amount_per_period, | ||
| cliff_duration_from_migration_time, | ||
| frequency, | ||
| number_of_period, | ||
| cliff_unlock_amount | ||
| ) VALUES ( | ||
| @config, | ||
| @slot, | ||
| @amount_per_period, | ||
| @cliff_duration_from_migration_time, | ||
| @frequency, | ||
| @number_of_period, | ||
| @cliff_unlock_amount | ||
| ) | ||
| ON CONFLICT (config) DO UPDATE | ||
| SET | ||
| slot = EXCLUDED.slot, | ||
| amount_per_period = EXCLUDED.amount_per_period, | ||
| cliff_duration_from_migration_time = EXCLUDED.cliff_duration_from_migration_time, | ||
| frequency = EXCLUDED.frequency, | ||
| number_of_period = EXCLUDED.number_of_period, | ||
| cliff_unlock_amount = EXCLUDED.cliff_unlock_amount | ||
| WHERE EXCLUDED.slot > sol_meteora_dbc_config_vestings.slot | ||
| `, pgx.NamedArgs{ | ||
| "config": account, | ||
| "slot": slot, | ||
| "amount_per_period": vesting.AmountPerPeriod, | ||
| "cliff_duration_from_migration_time": vesting.CliffDurationFromMigrationTime, | ||
| "frequency": vesting.Frequency, | ||
| "number_of_period": vesting.NumberOfPeriod, | ||
| "cliff_unlock_amount": vesting.CliffUnlockAmount, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
File renamed without changes.
Oops, something went wrong.
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.