Skip to content

Commit

Permalink
Return gas estimate
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinquaXD committed Mar 19, 2024
1 parent 5aafa9e commit e7fa5c9
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 12 deletions.
3 changes: 3 additions & 0 deletions src/api/routes/solve/dto/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ impl Solutions {
success_probability: score.0,
},
},
gas: solution.gas.map(|gas| gas.0.as_u64()),
})
.collect(),
}
Expand All @@ -150,6 +151,8 @@ struct Solution {
trades: Vec<Trade>,
interactions: Vec<Interaction>,
score: Score,
#[serde(skip_serializing_if = "Option::is_none")]
gas: Option<u64>,
}

#[derive(Debug, Serialize)]
Expand Down
2 changes: 2 additions & 0 deletions src/domain/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct Solution {
pub trades: Vec<Trade>,
pub interactions: Vec<Interaction>,
pub score: Score,
pub gas: Option<eth::Gas>,
}

impl Solution {
Expand Down Expand Up @@ -217,6 +218,7 @@ impl Single {
trades: vec![Trade::Fulfillment(Fulfillment::new(order, executed, fee)?)],
interactions,
score,
gas: Some(self.gas),
})
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/tests/balancer/market_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ async fn sell() {
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 88892,
}]
}),
);
Expand Down Expand Up @@ -316,7 +317,8 @@ async fn buy() {
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 88892,
}]
}),
);
Expand Down
9 changes: 6 additions & 3 deletions src/tests/dex/partial_fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ endpoint = 'http://{}/sor'
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 88892,
}]
})
);
Expand Down Expand Up @@ -625,7 +626,8 @@ endpoint = 'http://{}/sor'
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 88892,
}]
})
);
Expand Down Expand Up @@ -893,7 +895,8 @@ async fn market() {
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 88892,
}]
})
);
Expand Down
5 changes: 3 additions & 2 deletions src/tests/oneinch/market_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async fn sell() {
"to": "0x1111111254eeb25477b68fb85ed929f73a960582",
"data": "0x12aa3caf0000000000000000000000001136b25047e142fa3018184793aec68fbb173ce4000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f4980000000000000000000000001136b25047e142fa3018184793aec68fbb173ce40000000000000000000000009008d19f58aabd9ed0d60971565aa8510560ab410000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000001a53f2377c3b1e2f64e0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000020200a0c9e75c48000000000000050028050000000000000000000000000000000000000001d400015a00011e00008f0c20c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20bc5ae46c32d99c434b7383183aca16dd6e9bdc86ae40711b8002dc6c00bc5ae46c32d99c434b7383183aca16dd6e9bdc81111111254eeb25477b68fb85ed929f73a96058200000000000000000000000000000000000000000000002a1e26c62c19f03aabc02aaa39b223fe8d0a0e5c4f27ead9083c756cc20c20c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2c6f348dd3b91a56d117ec0071c1e9b83c0996de46ae40711b8002dc6c0c6f348dd3b91a56d117ec0071c1e9b83c0996de41111111254eeb25477b68fb85ed929f73a9605820000000000000000000000000000000000000000000001508d106e5f82eea57ec02aaa39b223fe8d0a0e5c4f27ead9083c756cc24101c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200042e1a7d4d00000000000000000000000000000000000000000000000000000000000000004040ae76c84c9262cdb9abc0c2c8888e62db8e22a0bfad65d76d00000000000000000000000000000000000000000000002a93ec43381504162400000000000000000000000000000000000000000000000000000000646f5dde0000000000000000000000001111111254eeb25477b68fb85ed929f73a960582cfee7c08",
"value": "0",
"gas": 0,
"gas": 100000,
"gasPrice": "15000000000"
}
}
Expand Down Expand Up @@ -209,7 +209,8 @@ async fn sell() {
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 100000,
}
]
}),
Expand Down
6 changes: 4 additions & 2 deletions src/tests/paraswap/market_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ async fn sell() {
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 242300,
}
]
}),
Expand Down Expand Up @@ -493,7 +494,8 @@ async fn buy() {
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 106935,
}
]
}),
Expand Down
6 changes: 4 additions & 2 deletions src/tests/zeroex/market_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ async fn sell() {
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 127886,
}]
}),
);
Expand Down Expand Up @@ -371,7 +372,8 @@ async fn buy() {
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 111000,
}]
}),
);
Expand Down
3 changes: 2 additions & 1 deletion src/tests/zeroex/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ enable-slippage-protection = true
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 127886,
}]
}),
);
Expand Down

0 comments on commit e7fa5c9

Please sign in to comment.