fix: Bring back swapper_pk for backwards compatibility
Took 16 minutes
This commit is contained in:
@@ -1,10 +1,5 @@
|
||||
use std::{
|
||||
io::{self, Read},
|
||||
str::FromStr,
|
||||
};
|
||||
use std::io::{self, Read};
|
||||
|
||||
use alloy::signers::local::PrivateKeySigner;
|
||||
use alloy_primitives::B256;
|
||||
use alloy_sol_types::SolValue;
|
||||
use clap::{Parser, Subcommand};
|
||||
use tycho_common::{hex_bytes::Bytes, models::Chain};
|
||||
@@ -58,6 +53,8 @@ pub struct Cli {
|
||||
router_address: Option<Bytes>,
|
||||
#[arg(short, long)]
|
||||
user_transfer_type: Option<UserTransferType>,
|
||||
#[arg(short, long)]
|
||||
swapper_pk: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
@@ -94,6 +91,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Some(user_transfer_type) = cli.user_transfer_type {
|
||||
builder = builder.user_transfer_type(user_transfer_type);
|
||||
}
|
||||
#[allow(deprecated)]
|
||||
if let Some(swapper_pk) = cli.swapper_pk {
|
||||
builder = builder.swapper_pk(swapper_pk);
|
||||
}
|
||||
builder.build()?
|
||||
}
|
||||
Commands::TychoExecutor => TychoExecutorEncoderBuilder::new()
|
||||
|
||||
@@ -175,7 +175,7 @@ impl Permit2 {
|
||||
sigDeadline: sig_deadline,
|
||||
};
|
||||
|
||||
Ok(models::PermitSingle::try_from(&permit_single)?)
|
||||
models::PermitSingle::try_from(&permit_single)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, str::FromStr};
|
||||
|
||||
use alloy::signers::local::PrivateKeySigner;
|
||||
use alloy_primitives::B256;
|
||||
use tycho_common::{models::Chain as TychoCommonChain, Bytes};
|
||||
|
||||
use crate::encoding::{
|
||||
@@ -22,7 +23,7 @@ pub struct TychoRouterEncoderBuilder {
|
||||
user_transfer_type: Option<UserTransferType>,
|
||||
executors_file_path: Option<String>,
|
||||
router_address: Option<Bytes>,
|
||||
signer: Option<PrivateKeySigner>,
|
||||
swapper_pk: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for TychoRouterEncoderBuilder {
|
||||
@@ -37,7 +38,7 @@ impl TychoRouterEncoderBuilder {
|
||||
chain: None,
|
||||
executors_file_path: None,
|
||||
router_address: None,
|
||||
signer: None,
|
||||
swapper_pk: None,
|
||||
user_transfer_type: None,
|
||||
}
|
||||
}
|
||||
@@ -65,11 +66,15 @@ impl TychoRouterEncoderBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the `signer` for the encoder. This is used to sign permit2 objects. This is only needed
|
||||
/// if you intend to get the full calldata for the transfer. We do not recommend using this
|
||||
/// option, you should sign and create the function calldata entirely on your own.
|
||||
pub fn signer(mut self, signer: PrivateKeySigner) -> Self {
|
||||
self.signer = Some(signer);
|
||||
/// Sets the `swapper_pk` for the encoder. This is used to sign permit2 objects. This is only
|
||||
/// needed if you intend to get the full calldata for the transfer. We do not recommend
|
||||
/// using this option, you should sign and create the function calldata entirely on your
|
||||
/// own.
|
||||
#[deprecated(
|
||||
note = "This is deprecated and will be removed in the future. You should sign and create the function calldata on your own."
|
||||
)]
|
||||
pub fn swapper_pk(mut self, swapper_pk: String) -> Self {
|
||||
self.swapper_pk = Some(swapper_pk);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -94,12 +99,23 @@ impl TychoRouterEncoderBuilder {
|
||||
let swap_encoder_registry =
|
||||
SwapEncoderRegistry::new(self.executors_file_path.clone(), chain.clone())?;
|
||||
|
||||
let signer = if let Some(pk) = self.swapper_pk {
|
||||
let pk = B256::from_str(&pk).map_err(|_| {
|
||||
EncodingError::FatalError("Invalid swapper private key provided".to_string())
|
||||
})?;
|
||||
Some(PrivateKeySigner::from_bytes(&pk).map_err(|_| {
|
||||
EncodingError::FatalError("Failed to create signer".to_string())
|
||||
})?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(Box::new(TychoRouterEncoder::new(
|
||||
chain,
|
||||
swap_encoder_registry,
|
||||
tycho_router_address,
|
||||
user_transfer_type,
|
||||
self.signer,
|
||||
signer,
|
||||
)?))
|
||||
} else {
|
||||
Err(EncodingError::FatalError(
|
||||
|
||||
@@ -551,15 +551,14 @@ mod tests {
|
||||
|
||||
fn get_permit(router_address: Bytes, solution: &Solution) -> PermitSingle {
|
||||
let permit2 = Permit2::new().unwrap();
|
||||
let permit_single = permit2
|
||||
permit2
|
||||
.get_permit(
|
||||
&router_address,
|
||||
&solution.sender,
|
||||
&solution.given_token,
|
||||
&solution.given_amount,
|
||||
)
|
||||
.unwrap();
|
||||
permit_single
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn get_signer() -> PrivateKeySigner {
|
||||
|
||||
Reference in New Issue
Block a user