Skip to content

Commit

Permalink
fix: use both latest publisher and aggregate slot for dynamic pricing (
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-bahjati authored Dec 1, 2023
1 parent 06d468e commit 533520a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
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

0 comments on commit 533520a

Please sign in to comment.