Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyth-agent"
version = "2.4.1"
version = "2.4.2"
edition = "2021"

[[bin]]
Expand Down
54 changes: 28 additions & 26 deletions src/agent/solana/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,38 +746,40 @@ impl Exporter {
// used instead of the publishers latest update to avoid overpaying.
let oldest_slot = result
.values()
.filter(|account| account.min_pub != 255) // Only consider live price accounts
.flat_map(|account| {
account
.comp
.iter()
.find(|c| c.publisher == publish_keypair.pubkey())
.map(|c| c.latest.pub_slot)
.map(|c| c.latest.pub_slot.max(account.agg.pub_slot))
})
.min()
.ok_or(anyhow!("No price accounts"))?;

let slot_gap = network_state.current_slot.saturating_sub(oldest_slot);

// Set the dynamic price exponentially based on the slot gap. If the max slot gap is
// 25, on this number (or more) the maximum unit price is paid, and then on slot 24 it
// is half of that and gets halved each lower slot. Given that we have max total
// compute price of 10**12 and 250k compute units in one tx (12 updates) these are the
// estimated prices based on slot gaps:
// 25 (or more): 4_000_000
// 20 : 125_000
// 18 : 31_250
// 15 : 3_906
// 13 : 976
// 10 : 122
let exponential_price = maximum_unit_price
>> self
.config
.maximum_slot_gap_for_dynamic_compute_unit_price
.saturating_sub(slot_gap);

compute_unit_price_micro_lamports = compute_unit_price_micro_lamports
.map(|price| price.max(exponential_price))
.or(Some(exponential_price));
.min();

if let Some(oldest_slot) = oldest_slot {
let slot_gap = network_state.current_slot.saturating_sub(oldest_slot);

// Set the dynamic price exponentially based on the slot gap. If the max slot gap is
// 25, on this number (or more) the maximum unit price is paid, and then on slot 24 it
// is half of that and gets halved each lower slot. Given that we have max total
// compute price of 10**12 and 250k compute units in one tx (12 updates) these are the
// estimated prices based on slot gaps:
// 25 (or more): 4_000_000
// 20 : 125_000
// 18 : 31_250
// 15 : 3_906
// 13 : 976
// 10 : 122
let exponential_price = maximum_unit_price
>> self
.config
.maximum_slot_gap_for_dynamic_compute_unit_price
.saturating_sub(slot_gap);

compute_unit_price_micro_lamports = compute_unit_price_micro_lamports
.map(|price| price.max(exponential_price))
.or(Some(exponential_price));
}
}

if let Some(compute_unit_price_micro_lamports) = compute_unit_price_micro_lamports {
Expand Down