Skip to content

Commit 2e241a4

Browse files
Merge pull request #422 from propeller-heads/cluster-test/dc/accept-all-slippage-values
feat: Set min amount out to 1 so that execution doesn't fail
2 parents 49bcd10 + b61c6fa commit 2e241a4

File tree

4 files changed

+13
-24
lines changed

4 files changed

+13
-24
lines changed

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tycho-integration-test/src/execution/encoding.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub fn encode_swap(
4444
sell_token: &Token,
4545
buy_token: &Token,
4646
amount_in: BigUint,
47-
expected_amount_out: BigUint,
4847
chain: Chain,
4948
) -> miette::Result<(Solution, Transaction)> {
5049
let solution = create_solution(
@@ -53,7 +52,6 @@ pub fn encode_swap(
5352
sell_token.clone(),
5453
buy_token.clone(),
5554
amount_in.clone(),
56-
expected_amount_out.clone(),
5755
)?;
5856
let encoded_solution = {
5957
let encoder = TychoRouterEncoderBuilder::new()
@@ -81,7 +79,6 @@ fn create_solution(
8179
sell_token: Token,
8280
buy_token: Token,
8381
amount_in: BigUint,
84-
expected_amount_out: BigUint,
8582
) -> miette::Result<Solution> {
8683
let user_address = Bytes::from_str(USER_ADDR).into_diagnostic()?;
8784

@@ -92,26 +89,16 @@ fn create_solution(
9289
.estimated_amount_in(amount_in.clone())
9390
.build();
9491

95-
// Compute a minimum amount out
96-
//
97-
// # ⚠️ Important Responsibility Note
98-
// For maximum security, in production code, this minimum amount out should be computed
99-
// from a third-party source.
100-
let slippage = 0.0025; // 0.25% slippage
101-
let bps = BigUint::from(10_000u32);
102-
let slippage_percent = BigUint::from((slippage * 10000.0) as u32);
103-
let multiplier = &bps - slippage_percent;
104-
let min_amount_out = (expected_amount_out * &multiplier) / &bps;
105-
106-
// Then we create a solution object with the previous swap
10792
Ok(Solution {
10893
sender: user_address.clone(),
10994
receiver: user_address,
11095
given_token: sell_token.address,
11196
given_amount: amount_in,
11297
checked_token: buy_token.address,
11398
exact_out: false, // it's an exact in solution
114-
checked_amount: min_amount_out,
99+
// We want to keep track of how bad the slippage really is and not just error at execution
100+
// time. NEVER DO THIS IN PRODUCTION!
101+
checked_amount: BigUint::from(1u64),
115102
swaps: vec![simple_swap],
116103
..Default::default()
117104
})

tycho-integration-test/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,6 @@ async fn process_state(
677677
token_in,
678678
token_out,
679679
amount_in.clone(),
680-
expected_amount_out.clone(),
681680
chain,
682681
) {
683682
Ok(res) => res,

tycho-integration-test/src/metrics.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ pub async fn create_metrics_exporter(port: u16) -> Result<tokio::task::JoinHandl
180180
.map_err(|e| miette::miette!("Failed to set buckets: {}", e))?
181181
.set_buckets_for_metric(
182182
Matcher::Full("tycho_integration_simulation_execution_slippage_ratio".to_string()),
183-
&[-0.25, -0.2, -0.15, -0.1, -0.05, -0.01, 0.0, 0.01, 0.05, 0.1, 0.15, 0.2, 0.25],
183+
&[
184+
-10.0, -1.0, -0.5, -0.25, -0.2, -0.15, -0.1, -0.05, -0.01, 0.0, 0.01, 0.05, 0.1,
185+
0.15, 0.2, 0.25, 0.5, 1.0, 10.0,
186+
],
184187
)
185188
.map_err(|e| miette::miette!("Failed to set buckets: {}", e))?
186189
.set_buckets_for_metric(

0 commit comments

Comments
 (0)