Skip to content

Commit e973c6c

Browse files
Remove deprecated callDataInput and queryBatchSwap (#159)
This PR removes deprecated fields from the Balancer SOR endpoint. To give a bit more context, these fields were used to request the api call to also perform an on-chain query to get up-to-date results. This is no longer available, as the complexity of building the on-chain call grew beyond the SOR responsibilities. Balancer FE currently relies on the Balancer SDK to perform that on-chain query with the swap path returned by the SOR endpoint. This flow of performing an SOR request + on-chain call to get up-to-date results is considered the ideal scenario to mitigate any issues with stale/cached data the API might have. I intend to create a separate PR adding this extra on-chain step to the gnosis solver. --------- Co-authored-by: ilya <ilya@cow.fi>
1 parent b58842e commit e973c6c

9 files changed

Lines changed: 5 additions & 185 deletions

File tree

src/infra/config/dex/balancer/file.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ struct Config {
3636
#[serde_as(as = "serialize::ChainId")]
3737
chain_id: eth::ChainId,
3838

39-
/// Whether to run `queryBatchSwap` to update the return amount with most
40-
/// up-to-date on-chain values.
41-
query_batch_swap: Option<bool>,
42-
4339
/// Controls which API versions are enabled.
4440
/// Absence of this config param means all versions are enabled.
4541
enabled_api_versions: Option<Vec<ApiVersion>>,
@@ -95,7 +91,6 @@ pub async fn load(path: &Path) -> super::Config {
9591
settlement: base.contracts.settlement,
9692
block_stream: base.block_stream.clone(),
9793
chain_id: config.chain_id,
98-
query_batch_swap: config.query_batch_swap.unwrap_or(false),
9994
},
10095
base,
10196
}

src/infra/dex/balancer/dto.rs

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ use {
1313

1414
/// Get swap quote from the SOR v2 for the V2 vault.
1515
const QUERY: &str = r#"
16-
query sorGetSwapPaths($callDataInput: GqlSwapCallDataInput!, $chain: GqlChain!, $queryBatchSwap: Boolean!, $swapAmount: AmountHumanReadable!, $swapType: GqlSorSwapType!, $tokenIn: String!, $tokenOut: String!) {
16+
query sorGetSwapPaths($chain: GqlChain!, $swapAmount: AmountHumanReadable!, $swapType: GqlSorSwapType!, $tokenIn: String!, $tokenOut: String!) {
1717
sorGetSwapPaths(
18-
callDataInput: $callDataInput,
1918
chain: $chain,
20-
queryBatchSwap: $queryBatchSwap,
2119
swapAmount: $swapAmount,
2220
swapType: $swapType,
2321
tokenIn: $tokenIn,
@@ -61,11 +59,7 @@ impl Query<'_> {
6159
pub fn from_domain(
6260
order: &dex::Order,
6361
tokens: &auction::Tokens,
64-
slippage: &dex::Slippage,
6562
chain: Chain,
66-
contract_address: eth::ContractAddress,
67-
query_batch_swap: bool,
68-
swap_deadline: Option<u64>,
6963
) -> Result<Self, Error> {
7064
let token_decimals = match order.side {
7165
order::Side::Buy => tokens
@@ -76,14 +70,7 @@ impl Query<'_> {
7670
.ok_or(Error::MissingDecimals(order.sell)),
7771
}?;
7872
let variables = Variables {
79-
call_data_input: CallDataInput {
80-
deadline: swap_deadline,
81-
receiver: contract_address.0,
82-
sender: contract_address.0,
83-
slippage_percentage: slippage.as_factor().clone(),
84-
},
8573
chain,
86-
query_batch_swap,
8774
swap_amount: HumanReadableAmount::from_u256(&order.amount.get(), token_decimals),
8875
swap_type: SwapType::from_domain(order.side),
8976
token_in: order.sell.0,
@@ -139,12 +126,8 @@ impl Serialize for HumanReadableAmount {
139126
#[derive(Serialize)]
140127
#[serde(rename_all = "camelCase")]
141128
struct Variables {
142-
call_data_input: CallDataInput,
143129
/// The Chain to query.
144130
chain: Chain,
145-
/// Whether to run `queryBatchSwap` to update the return amount with most
146-
/// up-to-date on-chain values.
147-
query_batch_swap: bool,
148131
/// The amount to swap in human form.
149132
swap_amount: HumanReadableAmount,
150133
/// SwapType either exact_in or exact_out (also givenIn or givenOut).
@@ -155,23 +138,6 @@ struct Variables {
155138
token_out: H160,
156139
}
157140

158-
/// Inputs for the call data to create the swap transaction. If this input is
159-
/// given, call data is added to the response.
160-
#[derive(Serialize)]
161-
#[serde(rename_all = "camelCase")]
162-
struct CallDataInput {
163-
/// How long the swap should be valid, provide a timestamp. `999999999` for
164-
/// infinite. Default: infinite.
165-
#[serde(skip_serializing_if = "Option::is_none")]
166-
deadline: Option<u64>,
167-
/// Who receives the output amount.
168-
receiver: H160,
169-
/// Who sends the input amount.
170-
sender: H160,
171-
/// The max slippage in percent 0.01 -> 0.01%.
172-
slippage_percentage: BigDecimal,
173-
}
174-
175141
/// Balancer SOR API supported chains.
176142
#[derive(Serialize, Clone, Copy)]
177143
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
@@ -454,34 +420,14 @@ mod tests {
454420
amount: dex::Amount::new(U256::from(1000)),
455421
owner: H160::from_str("0x9008d19f58aabd9ed0d60971565aa8510560ab41").unwrap(),
456422
};
457-
let slippage = dex::Slippage::one_percent();
458423
let chain = Chain::Mainnet;
459-
let contract_address = eth::ContractAddress(
460-
H160::from_str("0x9008d19f58aabd9ed0d60971565aa8510560ab41").unwrap(),
461-
);
462-
let query = Query::from_domain(
463-
&order,
464-
&tokens,
465-
&slippage,
466-
chain,
467-
contract_address,
468-
false,
469-
Some(12345_u64),
470-
)
471-
.unwrap();
424+
let query = Query::from_domain(&order, &tokens, chain).unwrap();
472425

473426
let actual = serde_json::to_value(query).unwrap();
474427
let expected = json!({
475428
"query": QUERY,
476429
"variables": {
477-
"callDataInput": {
478-
"deadline": 12345,
479-
"receiver": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
480-
"sender": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
481-
"slippagePercentage": "0.01"
482-
},
483430
"chain": "MAINNET",
484-
"queryBatchSwap": false,
485431
"swapAmount": "0.000000000000000000001",
486432
"swapType": "EXACT_OUT",
487433
"tokenIn": "0x2170ed0880ac9a755fd29b2688956bd959f933f8",

src/infra/dex/balancer/mod.rs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ use {
1212
contracts::ethcontract::I256,
1313
ethereum_types::U256,
1414
ethrpc::block_stream::CurrentBlockWatcher,
15-
num::ToPrimitive,
16-
std::{
17-
ops::Add,
18-
sync::atomic::{self, AtomicU64},
19-
time::Duration,
20-
},
15+
std::sync::atomic::{self, AtomicU64},
2116
tracing::Instrument,
2217
};
2318

@@ -34,7 +29,6 @@ pub struct Sor {
3429
permit2: v3::Permit2,
3530
settlement: eth::ContractAddress,
3631
chain_id: Chain,
37-
query_batch_swap: bool,
3832
}
3933

4034
pub struct Config {
@@ -60,10 +54,6 @@ pub struct Config {
6054

6155
/// For which chain the solver is configured.
6256
pub chain_id: eth::ChainId,
63-
64-
/// Whether to run `queryBatchSwap` to update the return amount with most
65-
/// up-to-date on-chain values.
66-
pub query_batch_swap: bool,
6757
}
6858

6959
impl Sor {
@@ -82,7 +72,6 @@ impl Sor {
8272
permit2: v3::Permit2::new(config.permit2),
8373
settlement: config.settlement,
8474
chain_id: Chain::from_domain(config.chain_id)?,
85-
query_batch_swap: config.query_batch_swap,
8675
})
8776
}
8877

@@ -96,19 +85,7 @@ impl Sor {
9685
let Some(v2_vault) = &self.v2_vault else {
9786
return Err(Error::DisabledApiVersion(ApiVersion::V2));
9887
};
99-
let query = dto::Query::from_domain(
100-
order,
101-
tokens,
102-
slippage,
103-
self.chain_id,
104-
self.settlement,
105-
self.query_batch_swap,
106-
// 2 minutes from now
107-
chrono::Utc::now()
108-
.add(Duration::from_secs(120))
109-
.timestamp()
110-
.to_u64(),
111-
)?;
88+
let query = dto::Query::from_domain(order, tokens, self.chain_id)?;
11289
let quote = {
11390
// Set up a tracing span to make debugging of API requests easier.
11491
// Historically, debugging API requests to external DEXs was a bit

src/tests/balancer/market_order.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@ async fn sell_v2() {
1717
req: mock::http::RequestBody::Partial(json!({
1818
"query": serde_json::to_value(SWAP_QUERY).unwrap(),
1919
"variables": {
20-
"callDataInput": {
21-
"receiver": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
22-
"sender": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
23-
"slippagePercentage": "0.01"
24-
},
2520
"chain": "MAINNET",
26-
"queryBatchSwap": false,
2721
"swapAmount": "1",
2822
"swapType": "EXACT_IN",
2923
"tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
@@ -198,13 +192,7 @@ async fn sell_v3() {
198192
json!({
199193
"query": serde_json::to_value(SWAP_QUERY).unwrap(),
200194
"variables": {
201-
"callDataInput": {
202-
"receiver": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
203-
"sender": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
204-
"slippagePercentage": "0.01"
205-
},
206195
"chain": "MAINNET",
207-
"queryBatchSwap": false,
208196
"swapAmount": "1",
209197
"swapType": "EXACT_IN",
210198
"tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
@@ -404,13 +392,7 @@ async fn buy_v2() {
404392
req: mock::http::RequestBody::Partial(json!({
405393
"query": serde_json::to_value(SWAP_QUERY).unwrap(),
406394
"variables": {
407-
"callDataInput": {
408-
"receiver": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
409-
"sender": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
410-
"slippagePercentage": "0.01"
411-
},
412395
"chain": "MAINNET",
413-
"queryBatchSwap": false,
414396
"swapAmount": "100",
415397
"swapType": "EXACT_OUT",
416398
"tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",

src/tests/balancer/minimum_surplus.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@ async fn buy_order_insufficient_surplus() {
2020
req: mock::http::RequestBody::Partial(json!({
2121
"query": serde_json::to_value(SWAP_QUERY).unwrap(),
2222
"variables": {
23-
"callDataInput": {
24-
"receiver": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
25-
"sender": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
26-
"slippagePercentage": "0.01"
27-
},
2823
"chain": "MAINNET",
29-
"queryBatchSwap": false,
3024
"swapAmount": "230",
3125
"swapType": "EXACT_OUT",
3226
"tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
@@ -153,13 +147,7 @@ async fn buy_order_with_sufficient_surplus() {
153147
req: mock::http::RequestBody::Partial(json!({
154148
"query": serde_json::to_value(SWAP_QUERY).unwrap(),
155149
"variables": {
156-
"callDataInput": {
157-
"receiver": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
158-
"sender": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
159-
"slippagePercentage": "0.01"
160-
},
161150
"chain": "MAINNET",
162-
"queryBatchSwap": false,
163151
"swapAmount": "230",
164152
"swapType": "EXACT_OUT",
165153
"tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
@@ -282,13 +270,7 @@ async fn sell_order_insufficient_surplus() {
282270
req: mock::http::RequestBody::Partial(json!({
283271
"query": serde_json::to_value(SWAP_QUERY).unwrap(),
284272
"variables": {
285-
"callDataInput": {
286-
"receiver": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
287-
"sender": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
288-
"slippagePercentage": "0.01"
289-
},
290273
"chain": "MAINNET",
291-
"queryBatchSwap": false,
292274
"swapAmount": "1",
293275
"swapType": "EXACT_IN",
294276
"tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
@@ -416,13 +398,7 @@ async fn sell_order_with_sufficient_surplus() {
416398
req: mock::http::RequestBody::Partial(json!({
417399
"query": serde_json::to_value(SWAP_QUERY).unwrap(),
418400
"variables": {
419-
"callDataInput": {
420-
"receiver": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
421-
"sender": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
422-
"slippagePercentage": "0.01"
423-
},
424401
"chain": "MAINNET",
425-
"queryBatchSwap": false,
426402
"swapAmount": "1",
427403
"swapType": "EXACT_IN",
428404
"tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",

src/tests/balancer/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ chain-id = '1'
3333

3434
// Copy from src/infra/dex/balancer/dto.rs
3535
pub const SWAP_QUERY: &str = r#"
36-
query sorGetSwapPaths($callDataInput: GqlSwapCallDataInput!, $chain: GqlChain!, $queryBatchSwap: Boolean!, $swapAmount: AmountHumanReadable!, $swapType: GqlSorSwapType!, $tokenIn: String!, $tokenOut: String!) {
36+
query sorGetSwapPaths($chain: GqlChain!, $swapAmount: AmountHumanReadable!, $swapType: GqlSorSwapType!, $tokenIn: String!, $tokenOut: String!) {
3737
sorGetSwapPaths(
38-
callDataInput: $callDataInput,
3938
chain: $chain,
40-
queryBatchSwap: $queryBatchSwap,
4139
swapAmount: $swapAmount,
4240
swapType: $swapType,
4341
tokenIn: $tokenIn,

src/tests/balancer/out_of_price.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@ async fn sell() {
2020
req: mock::http::RequestBody::Partial(json!({
2121
"query": serde_json::to_value(SWAP_QUERY).unwrap(),
2222
"variables": {
23-
"callDataInput": {
24-
"receiver": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
25-
"sender": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
26-
"slippagePercentage": "0.01"
27-
},
2823
"chain": "MAINNET",
29-
"queryBatchSwap": false,
3024
"swapAmount": "1",
3125
"swapType": "EXACT_IN",
3226
"tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
@@ -129,13 +123,7 @@ async fn buy() {
129123
req: mock::http::RequestBody::Partial(json!({
130124
"query": serde_json::to_value(SWAP_QUERY).unwrap(),
131125
"variables": {
132-
"callDataInput": {
133-
"receiver": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
134-
"sender": "0x9008d19f58aabd9ed0d60971565aa8510560ab41",
135-
"slippagePercentage": "0.01"
136-
},
137126
"chain": "MAINNET",
138-
"queryBatchSwap": false,
139127
"swapAmount": "100",
140128
"swapType": "EXACT_OUT",
141129
"tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",

0 commit comments

Comments
 (0)