FUN-1310. Support decimal snek fees#255
Open
Bromel777 wants to merge 16 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
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
AdhocFeeStructurepercent-based storage/calculation with basis-point storage and math. - Added custom config parsing for
relativeFeeBps, with fallback support for legacyrelativeFeePercentvalues (including decimals). - Updated Snek config resources to use
relativeFeeBps: 130and 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 |
0af65bc to
b5d70df
Compare
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 |
5e2338e to
4393a12
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.