|
|
@ -1,9 +1,10 @@ |
|
|
|
use crate::types::Chain; |
|
|
|
|
|
|
|
use crate::{types::serialize_as_decimal_str, RELAY_URL}; |
|
|
|
|
|
|
|
use ethers::types::{Address, Bytes, U256}; |
|
|
|
use ethers::types::{Address, Bytes, U256}; |
|
|
|
use serde::{Deserialize, Serialize}; |
|
|
|
use serde::{Deserialize, Serialize}; |
|
|
|
use tracing::instrument; |
|
|
|
use tracing::instrument; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use crate::types::Chain; |
|
|
|
|
|
|
|
use crate::{parse_response, types::serialize_as_decimal_str, RELAY_URL}; |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize)] |
|
|
|
#[derive(Debug, Clone, Serialize)] |
|
|
|
#[serde(rename_all = "camelCase")] |
|
|
|
#[serde(rename_all = "camelCase")] |
|
|
|
pub struct SponsoredCallArgs { |
|
|
|
pub struct SponsoredCallArgs { |
|
|
@ -13,16 +14,16 @@ pub struct SponsoredCallArgs { |
|
|
|
|
|
|
|
|
|
|
|
// U256 by default serializes as a 0x-prefixed hexadecimal string.
|
|
|
|
// U256 by default serializes as a 0x-prefixed hexadecimal string.
|
|
|
|
// Gelato's API expects the gasLimit to be a decimal string.
|
|
|
|
// Gelato's API expects the gasLimit to be a decimal string.
|
|
|
|
/// Skip serializing if None - the Gelato API expects the parameter to either be
|
|
|
|
/// Skip serializing if None - the Gelato API expects the parameter to
|
|
|
|
/// present as a string, or not at all.
|
|
|
|
/// either be present as a string, or not at all.
|
|
|
|
#[serde(
|
|
|
|
#[serde(
|
|
|
|
serialize_with = "serialize_as_decimal_str", |
|
|
|
serialize_with = "serialize_as_decimal_str", |
|
|
|
skip_serializing_if = "Option::is_none" |
|
|
|
skip_serializing_if = "Option::is_none" |
|
|
|
)] |
|
|
|
)] |
|
|
|
pub gas_limit: Option<U256>, |
|
|
|
pub gas_limit: Option<U256>, |
|
|
|
/// If None is provided, the Gelato API will use a default of 5.
|
|
|
|
/// If None is provided, the Gelato API will use a default of 5.
|
|
|
|
/// Skip serializing if None - the Gelato API expects the parameter to either be
|
|
|
|
/// Skip serializing if None - the Gelato API expects the parameter to
|
|
|
|
/// present as a number, or not at all.
|
|
|
|
/// either be present as a number, or not at all.
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")] |
|
|
|
#[serde(skip_serializing_if = "Option::is_none")] |
|
|
|
pub retries: Option<u32>, |
|
|
|
pub retries: Option<u32>, |
|
|
|
} |
|
|
|
} |
|
|
@ -41,14 +42,14 @@ pub struct SponsoredCallApiCallResult { |
|
|
|
|
|
|
|
|
|
|
|
impl<'a> SponsoredCallApiCall<'a> { |
|
|
|
impl<'a> SponsoredCallApiCall<'a> { |
|
|
|
#[instrument] |
|
|
|
#[instrument] |
|
|
|
pub async fn run(self) -> Result<SponsoredCallApiCallResult, reqwest::Error> { |
|
|
|
pub async fn run(self) -> eyre::Result<SponsoredCallApiCallResult> { |
|
|
|
let url = format!("{}/relays/v2/sponsored-call", RELAY_URL); |
|
|
|
let url = format!("{}/relays/v2/sponsored-call", RELAY_URL); |
|
|
|
let http_args = HTTPArgs { |
|
|
|
let http_args = HTTPArgs { |
|
|
|
args: self.args, |
|
|
|
args: self.args, |
|
|
|
sponsor_api_key: self.sponsor_api_key, |
|
|
|
sponsor_api_key: self.sponsor_api_key, |
|
|
|
}; |
|
|
|
}; |
|
|
|
let res = self.http.post(url).json(&http_args).send().await?; |
|
|
|
let res = self.http.post(url).json(&http_args).send().await?; |
|
|
|
let result: HTTPResult = res.json().await?; |
|
|
|
let result: HTTPResult = parse_response(res).await?; |
|
|
|
Ok(SponsoredCallApiCallResult::from(result)) |
|
|
|
Ok(SponsoredCallApiCallResult::from(result)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -110,8 +111,8 @@ mod tests { |
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// When the gas limit is specified, ensure it's serialized as a decimal *string*,
|
|
|
|
// When the gas limit is specified, ensure it's serialized as a decimal
|
|
|
|
// and the retries are a number
|
|
|
|
// *string*, and the retries are a number
|
|
|
|
args.gas_limit = Some(U256::from_dec_str("420000").unwrap()); |
|
|
|
args.gas_limit = Some(U256::from_dec_str("420000").unwrap()); |
|
|
|
args.retries = Some(5); |
|
|
|
args.retries = Some(5); |
|
|
|
assert_eq!( |
|
|
|
assert_eq!( |
|
|
|