chore: Rename signer_pk to swapper_pk
--- don't change below this line --- ENG-4246 Took 15 minutes
This commit is contained in:
@@ -38,7 +38,7 @@ Permit2.
|
||||
Example:
|
||||
|
||||
```bash
|
||||
echo '<solution_payload>' | tycho-encode tycho-router -p 0x123456789abcdef123456789abcdef123456789abcdef123456789abcdef1234
|
||||
echo '<solution_payload>' | tycho-encode tycho-router --swapper-pk 0x123456789abcdef123456789abcdef123456789abcdef123456789abcdef1234
|
||||
```
|
||||
|
||||
#### Direct execution
|
||||
@@ -55,15 +55,16 @@ echo '<solution_payload>' | tycho-encode direct-execution
|
||||
|
||||
The commands accept the following options:
|
||||
|
||||
- `-c`: Path to the executor addresses configuration file (defaults to `src/encoding/config/executor_addresses.json`)
|
||||
- `-p`: Private key for signing approvals (required when direct_execution is false)
|
||||
- `--config_path`: Path to the executor addresses configuration file (defaults
|
||||
to `src/encoding/config/executor_addresses.json`)
|
||||
- `--swapper-pk`: Private key for signing approvals (required when direct_execution is false)
|
||||
|
||||
#### Example
|
||||
|
||||
Here's a complete example that encodes a swap from WETH to DAI using Uniswap V2 and the Tycho Router strategy:
|
||||
|
||||
```bash
|
||||
echo '{"sender":"0x1234567890123456789012345678901234567890","receiver":"0x1234567890123456789012345678901234567890","given_token":"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2","given_amount":"1000000000000000000","checked_token":"0x6B175474E89094C44Da98b954EedeAC495271d0F","exact_out":false,"slippage":0.01,"expected_amount":"1000000000000000000","checked_amount":"990000000000000000","router_address":"0xaa820C29648D5EA543d712cC928377Bd7206a0E7","swaps":[{"component":{"id":"0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640","protocol_system":"uniswap_v2","protocol_type_name":"UniswapV2Pool","chain":"ethereum","tokens":["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"],"contract_ids":["0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"],"static_attributes":{"factory":"0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f"},"change":"Update","creation_tx":"0x0000000000000000000000000000000000000000000000000000000000000000","created_at":"2024-02-28T12:00:00"},"token_in":"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2","token_out":"0x6B175474E89094C44Da98b954EedeAC495271d0F","split":0.0}],"direct_execution":true}' | tycho-encode tycho-router -p 0x123456789abcdef123456789abcdef123456789abcdef123456789abcdef1234
|
||||
echo '{"sender":"0x1234567890123456789012345678901234567890","receiver":"0x1234567890123456789012345678901234567890","given_token":"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2","given_amount":"1000000000000000000","checked_token":"0x6B175474E89094C44Da98b954EedeAC495271d0F","exact_out":false,"slippage":0.01,"expected_amount":"1000000000000000000","checked_amount":"990000000000000000","router_address":"0xaa820C29648D5EA543d712cC928377Bd7206a0E7","swaps":[{"component":{"id":"0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640","protocol_system":"uniswap_v2","protocol_type_name":"UniswapV2Pool","chain":"ethereum","tokens":["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"],"contract_ids":["0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"],"static_attributes":{"factory":"0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f"},"change":"Update","creation_tx":"0x0000000000000000000000000000000000000000000000000000000000000000","created_at":"2024-02-28T12:00:00"},"token_in":"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2","token_out":"0x6B175474E89094C44Da98b954EedeAC495271d0F","split":0.0}],"direct_execution":true}' | tycho-encode tycho-router --swapper-pk 0x123456789abcdef123456789abcdef123456789abcdef123456789abcdef1234
|
||||
```
|
||||
|
||||
#### JSON Payload Structure: Solution struct
|
||||
|
||||
@@ -15,13 +15,13 @@ fn main() {
|
||||
// Setup variables
|
||||
let router_address = Bytes::from_str("0x1234567890abcdef1234567890abcdef12345678")
|
||||
.expect("Failed to create router address");
|
||||
let signer_pk =
|
||||
let swapper_pk =
|
||||
"0x123456789abcdef123456789abcdef123456789abcdef123456789abcdef1234".to_string();
|
||||
let user_address = Bytes::from_str("0xcd09f75E2BF2A4d11F3AB23f1389FcC1621c0cc2")
|
||||
.expect("Failed to create user address");
|
||||
|
||||
// Initialize the encoder
|
||||
let encoder = EVMEncoderBuilder::tycho_router(TychoCoreChain::Ethereum, signer_pk, None)
|
||||
let encoder = EVMEncoderBuilder::tycho_router(TychoCoreChain::Ethereum, swapper_pk, None)
|
||||
.expect("Failed to create encoder builder")
|
||||
.build()
|
||||
.expect("Failed to build encoder");
|
||||
|
||||
@@ -46,7 +46,7 @@ pub enum Commands {
|
||||
#[arg(short, long)]
|
||||
config_path: Option<String>,
|
||||
#[arg(short, long)]
|
||||
private_key: String,
|
||||
swapper_pk: String,
|
||||
},
|
||||
/// Use the direct execution encoding strategy
|
||||
DirectExecution {
|
||||
|
||||
@@ -29,8 +29,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
// Encode the solution
|
||||
let encoded = match cli.command {
|
||||
Commands::TychoRouter { config_path, private_key } => {
|
||||
encode_swaps(&buffer, config_path, Some(private_key), true)?
|
||||
Commands::TychoRouter { config_path, swapper_pk } => {
|
||||
encode_swaps(&buffer, config_path, Some(swapper_pk), true)?
|
||||
}
|
||||
Commands::DirectExecution { config_path } => {
|
||||
encode_swaps(&buffer, config_path, None, false)?
|
||||
@@ -49,15 +49,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn encode_swaps(
|
||||
input: &str,
|
||||
config_path: Option<String>,
|
||||
private_key: Option<String>,
|
||||
swapper_pk: Option<String>,
|
||||
use_tycho_router: bool,
|
||||
) -> Result<Value, EncodingError> {
|
||||
let solution: Solution = serde_json::from_str(input)?;
|
||||
let chain = Chain::Ethereum;
|
||||
|
||||
let encoder = if use_tycho_router {
|
||||
let private_key = private_key.ok_or(EncodingError::FatalError(
|
||||
"Private key is required for tycho_router".to_string(),
|
||||
let private_key = swapper_pk.ok_or(EncodingError::FatalError(
|
||||
"Swapper private key is required for tycho_router".to_string(),
|
||||
))?;
|
||||
EVMEncoderBuilder::tycho_router(chain, private_key, config_path)?.build()?
|
||||
} else {
|
||||
|
||||
@@ -69,7 +69,7 @@ sol! {
|
||||
}
|
||||
|
||||
impl Permit2 {
|
||||
pub fn new(signer_pk: String, chain: Chain) -> Result<Self, EncodingError> {
|
||||
pub fn new(swapper_pk: String, chain: Chain) -> Result<Self, EncodingError> {
|
||||
let (handle, runtime) = match Handle::try_current() {
|
||||
Ok(h) => (h, None),
|
||||
Err(_) => {
|
||||
@@ -80,8 +80,8 @@ impl Permit2 {
|
||||
}
|
||||
};
|
||||
let client = block_in_place(|| handle.block_on(get_client()))?;
|
||||
let pk = B256::from_str(&signer_pk).map_err(|_| {
|
||||
EncodingError::FatalError("Failed to convert signer private key to B256".to_string())
|
||||
let pk = B256::from_str(&swapper_pk).map_err(|_| {
|
||||
EncodingError::FatalError("Failed to convert swapper private key to B256".to_string())
|
||||
})?;
|
||||
let signer = PrivateKeySigner::from_bytes(&pk).map_err(|_| {
|
||||
EncodingError::FatalError("Failed to create signer from private key".to_string())
|
||||
@@ -224,9 +224,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_get_existing_allowance() {
|
||||
let signer_pk =
|
||||
let swapper_pk =
|
||||
"4c0883a69102937d6231471b5dbb6204fe512961708279feb1be6ae5538da033".to_string();
|
||||
let manager = Permit2::new(signer_pk, eth_chain()).unwrap();
|
||||
let manager = Permit2::new(swapper_pk, eth_chain()).unwrap();
|
||||
|
||||
let token = Bytes::from_str("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48").unwrap();
|
||||
let owner = Bytes::from_str("0x2c6a3cd97c6283b95ac8c5a4459ebb0d5fd404f4").unwrap();
|
||||
|
||||
@@ -21,12 +21,12 @@ impl EVMEncoderBuilder {
|
||||
}
|
||||
pub fn tycho_router(
|
||||
chain: Chain,
|
||||
signer_pk: String,
|
||||
swapper_pk: String,
|
||||
executors_file_path: Option<String>,
|
||||
) -> Result<Self, EncodingError> {
|
||||
let swap_encoder_registry = SwapEncoderRegistry::new(executors_file_path, chain)?;
|
||||
let strategy =
|
||||
Box::new(SplitSwapStrategyEncoder::new(signer_pk, chain, swap_encoder_registry)?);
|
||||
Box::new(SplitSwapStrategyEncoder::new(swapper_pk, chain, swap_encoder_registry)?);
|
||||
Ok(EVMEncoderBuilder { chain, strategy })
|
||||
}
|
||||
pub fn direct_execution(
|
||||
|
||||
@@ -88,14 +88,14 @@ pub struct SplitSwapStrategyEncoder {
|
||||
|
||||
impl SplitSwapStrategyEncoder {
|
||||
pub fn new(
|
||||
signer_pk: String,
|
||||
swapper_pk: String,
|
||||
blockchain: tycho_core::dto::Chain,
|
||||
swap_encoder_registry: SwapEncoderRegistry,
|
||||
) -> Result<Self, EncodingError> {
|
||||
let chain = Chain::from(blockchain);
|
||||
let selector = "swap(uint256,address,address,uint256,bool,bool,uint256,address,((address,uint160,uint48,uint48),address,uint256),bytes,bytes)".to_string();
|
||||
Ok(Self {
|
||||
permit2: Permit2::new(signer_pk, chain.clone())?,
|
||||
permit2: Permit2::new(swapper_pk, chain.clone())?,
|
||||
selector,
|
||||
swap_encoder_registry,
|
||||
native_address: chain.native_token()?,
|
||||
|
||||
Reference in New Issue
Block a user