Skip to content

Commit 533520a

Browse files
authored
fix: use both latest publisher and aggregate slot for dynamic pricing (#99)
1 parent 06d468e commit 533520a

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-agent"
3-
version = "2.4.1"
3+
version = "2.4.2"
44
edition = "2021"
55

66
[[bin]]

src/agent/solana/exporter.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -746,38 +746,40 @@ impl Exporter {
746746
// used instead of the publishers latest update to avoid overpaying.
747747
let oldest_slot = result
748748
.values()
749+
.filter(|account| account.min_pub != 255) // Only consider live price accounts
749750
.flat_map(|account| {
750751
account
751752
.comp
752753
.iter()
753754
.find(|c| c.publisher == publish_keypair.pubkey())
754-
.map(|c| c.latest.pub_slot)
755+
.map(|c| c.latest.pub_slot.max(account.agg.pub_slot))
755756
})
756-
.min()
757-
.ok_or(anyhow!("No price accounts"))?;
758-
759-
let slot_gap = network_state.current_slot.saturating_sub(oldest_slot);
760-
761-
// Set the dynamic price exponentially based on the slot gap. If the max slot gap is
762-
// 25, on this number (or more) the maximum unit price is paid, and then on slot 24 it
763-
// is half of that and gets halved each lower slot. Given that we have max total
764-
// compute price of 10**12 and 250k compute units in one tx (12 updates) these are the
765-
// estimated prices based on slot gaps:
766-
// 25 (or more): 4_000_000
767-
// 20 : 125_000
768-
// 18 : 31_250
769-
// 15 : 3_906
770-
// 13 : 976
771-
// 10 : 122
772-
let exponential_price = maximum_unit_price
773-
>> self
774-
.config
775-
.maximum_slot_gap_for_dynamic_compute_unit_price
776-
.saturating_sub(slot_gap);
777-
778-
compute_unit_price_micro_lamports = compute_unit_price_micro_lamports
779-
.map(|price| price.max(exponential_price))
780-
.or(Some(exponential_price));
757+
.min();
758+
759+
if let Some(oldest_slot) = oldest_slot {
760+
let slot_gap = network_state.current_slot.saturating_sub(oldest_slot);
761+
762+
// Set the dynamic price exponentially based on the slot gap. If the max slot gap is
763+
// 25, on this number (or more) the maximum unit price is paid, and then on slot 24 it
764+
// is half of that and gets halved each lower slot. Given that we have max total
765+
// compute price of 10**12 and 250k compute units in one tx (12 updates) these are the
766+
// estimated prices based on slot gaps:
767+
// 25 (or more): 4_000_000
768+
// 20 : 125_000
769+
// 18 : 31_250
770+
// 15 : 3_906
771+
// 13 : 976
772+
// 10 : 122
773+
let exponential_price = maximum_unit_price
774+
>> self
775+
.config
776+
.maximum_slot_gap_for_dynamic_compute_unit_price
777+
.saturating_sub(slot_gap);
778+
779+
compute_unit_price_micro_lamports = compute_unit_price_micro_lamports
780+
.map(|price| price.max(exponential_price))
781+
.or(Some(exponential_price));
782+
}
781783
}
782784

783785
if let Some(compute_unit_price_micro_lamports) = compute_unit_price_micro_lamports {

0 commit comments

Comments
 (0)