Skip to content

FUN-1310. Support decimal snek fees#255

Open
Bromel777 wants to merge 16 commits into
developfrom
bromel777/fun-1310-update-snek-cardano-agent-to-support-decimal-fees
Open

FUN-1310. Support decimal snek fees#255
Bromel777 wants to merge 16 commits into
developfrom
bromel777/fun-1310-update-snek-cardano-agent-to-support-decimal-fees

Conversation

@Bromel777

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Snek’s ad-hoc fee handling to support decimal percentages precisely by moving the internal representation from whole percents to basis points, while keeping legacy config compatibility.

Changes:

  • Replaced AdhocFeeStructure percent-based storage/calculation with basis-point storage and math.
  • Added custom config parsing for relativeFeeBps, with fallback support for legacy relativeFeePercent values (including decimals).
  • Updated Snek config resources to use relativeFeeBps: 130 and added tests/implementation notes.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
snek-cardano-agent/src/config.rs Adds custom AdhocFeeConfig deserialization, conversion helpers, and unit tests for BPS/legacy parsing.
snek-cardano-agent/resources/preprod.config.json Switches the preprod adhoc fee config from percent to basis points.
snek-cardano-agent/resources/mainnet.config.json.template Switches the mainnet template adhoc fee config from percent to basis points.
docs/plans/2026-04-28-snek-decimal-fees.md Adds a plan document describing the decimal-fee rollout and validation steps.
bloom-offchain-cardano/src/orders/adhoc.rs Renames fee storage to basis points, updates fee math, and adds unit tests for the new calculation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

where
D: serde::Deserializer<'de>,
{
let value = serde_json::Value::deserialize(deserializer)?;
Comment on lines +125 to +132
fn bounded_bps<E>(bps: u64) -> Result<BoundedU64<0, 10000>, E>
where
E: Error,
{
if bps <= 10_000 {
Ok(BoundedU64::new_saturating(bps))
} else {
Err(E::custom("relative fee must be between 0 and 10000 bps"))
Comment on lines 39 to +40
pub fn fee(&self, body: u64) -> u64 {
body * self.relative_fee_percent.get() / 100
(body as u128 * self.relative_fee_bps.get() as u128 / 10_000) as u64
@Bromel777 Bromel777 force-pushed the bromel777/fun-1310-update-snek-cardano-agent-to-support-decimal-fees branch from 0af65bc to b5d70df Compare May 7, 2026 07:04
@oskin1 oskin1 requested a review from Copilot May 7, 2026 07:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 30 changed files in this pull request and generated 7 comments.

Comment on lines +121 to +126
let maker_input = input.map(|_| net_input);
let next_inner = self.inner.swap(maker_input);
let make = Trans::new(
self,
next_inner.map_succ(|inner| self.with_inner(inner, operator_fee)),
);
Comment on lines +114 to +120
let operator_fee = self.fee_config.fee(gross_input);
let Some(net_input) = gross_input.checked_sub(operator_fee) else {
return default_swap_with_taker(target_taker, self, input);
};
if net_input == 0 {
return default_swap_with_taker(target_taker, self, input);
}
(
state,
effect.bimap(
|updated| updated.map(|_| next_pool),
Comment on lines +891 to +903
if matches!(graduation_action, GraduationAction::Apply) && !consumed_snek_refs.is_empty() {
let graduated_splash_ids = produced_entities
.keys()
.filter_map(MaybeGraduatedSplashId::maybe_graduated_splash_id)
.collect::<Vec<_>>();
if !graduated_splash_ids.is_empty() {
context_proto.journal_graduated_splash_pools(
tx.hash,
consumed_snek_refs,
produced_snek_refs,
graduated_splash_ids,
);
}
Comment on lines +37 to +46
pub fn enabled(relative_fee_percent: u64) -> Self {
Self {
enabled: true,
relative_fee_percent: BoundedU64::new_saturating(relative_fee_percent),
}
}

pub fn fee(&self, amount: u64) -> u64 {
if self.enabled {
amount * self.relative_fee_percent.get() / 100
Comment on lines +56 to +79
#[derive(Copy, Clone, Debug, Eq, PartialEq, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GraduatedPoolFeeAppConfig {
#[serde(default = "default_graduated_pool_fee_enabled")]
pub enabled: bool,
#[serde(default = "default_graduated_pool_fee_percent")]
pub relative_fee_percent: u64,
}

fn default_graduated_pool_fee_enabled() -> bool {
true
}

fn default_graduated_pool_fee_percent() -> u64 {
1
}

impl Default for GraduatedPoolFeeAppConfig {
fn default() -> Self {
Self {
enabled: true,
relative_fee_percent: 1,
}
}
Comment on lines +639 to +646
// Skip the synthetic batcher output when fee balancing leaves no remainder.
// Also reject dust explicitly instead of constructing an invalid output.
if batcher_output_lovelace > 0 {
if batcher_output_lovelace < 1_000_000 {
return Err(RunOrderError::raw_builder_error(
format!(
"Batcher output {} below minimum lovelace threshold",
batcher_output_lovelace
@Bromel777 Bromel777 force-pushed the bromel777/fun-1310-update-snek-cardano-agent-to-support-decimal-fees branch 2 times, most recently from 5e2338e to 4393a12 Compare May 27, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants