fix: Support pools that hold ETH but the coin is WETH
--- don't change below this line --- ENG-4307 Took 1 hour 46 minutes
This commit is contained in:
@@ -377,6 +377,7 @@ pub struct CurveSwapEncoder {
|
|||||||
meta_registry_address: String,
|
meta_registry_address: String,
|
||||||
native_token_curve_address: String,
|
native_token_curve_address: String,
|
||||||
native_token_address: Bytes,
|
native_token_address: Bytes,
|
||||||
|
wrapped_native_token_address: Bytes,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CurveSwapEncoder {
|
impl CurveSwapEncoder {
|
||||||
@@ -449,10 +450,34 @@ impl CurveSwapEncoder {
|
|||||||
let j = U8::from(j_256);
|
let j = U8::from(j_256);
|
||||||
Ok((i, j))
|
Ok((i, j))
|
||||||
}
|
}
|
||||||
Err(err) => Err(EncodingError::RecoverableError(format!(
|
Err(err) => {
|
||||||
"Curve meta registry call failed with error: {:?}",
|
// Temporary until we get the coin indexes from the indexer
|
||||||
err
|
// This is because some curve pools hold ETH but the coin is defined as WETH
|
||||||
))),
|
// Our indexer reports this pool as holding ETH but then here we need to use WETH
|
||||||
|
// This is valid only for some pools, that's why we are doing the trial and error
|
||||||
|
// approach
|
||||||
|
let native_token_curve_address =
|
||||||
|
Address::from_str(&self.native_token_curve_address).map_err(|_| {
|
||||||
|
EncodingError::FatalError(
|
||||||
|
"Invalid Curve native token curve address".to_string(),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
if token_in != native_token_curve_address && token_out != native_token_curve_address
|
||||||
|
{
|
||||||
|
Err(EncodingError::RecoverableError(format!(
|
||||||
|
"Curve meta registry call failed with error: {:?}",
|
||||||
|
err
|
||||||
|
)))
|
||||||
|
} else {
|
||||||
|
let wrapped_token = bytes_to_address(&self.wrapped_native_token_address)?;
|
||||||
|
let (i, j) = if token_in == native_token_curve_address {
|
||||||
|
self.get_coin_indexes(pool_id, wrapped_token, token_out)?
|
||||||
|
} else {
|
||||||
|
self.get_coin_indexes(pool_id, token_in, wrapped_token)?
|
||||||
|
};
|
||||||
|
Ok((i, j))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -482,6 +507,7 @@ impl SwapEncoder for CurveSwapEncoder {
|
|||||||
executor_address,
|
executor_address,
|
||||||
meta_registry_address,
|
meta_registry_address,
|
||||||
native_token_address: chain.native_token()?,
|
native_token_address: chain.native_token()?,
|
||||||
|
wrapped_native_token_address: chain.wrapped_token()?,
|
||||||
native_token_curve_address,
|
native_token_curve_address,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1168,6 +1194,22 @@ mod tests {
|
|||||||
2,
|
2,
|
||||||
0
|
0
|
||||||
)]
|
)]
|
||||||
|
// Pool that holds ETH but coin is WETH
|
||||||
|
#[case(
|
||||||
|
"0x7F86Bf177Dd4F3494b841a37e810A34dD56c829B",
|
||||||
|
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
||||||
|
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
||||||
|
2,
|
||||||
|
0
|
||||||
|
)]
|
||||||
|
// Pool that holds ETH but coin is WETH
|
||||||
|
#[case(
|
||||||
|
"0x7F86Bf177Dd4F3494b841a37e810A34dD56c829B",
|
||||||
|
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
||||||
|
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
|
||||||
|
0,
|
||||||
|
2
|
||||||
|
)]
|
||||||
fn test_curve_get_coin_indexes(
|
fn test_curve_get_coin_indexes(
|
||||||
#[case] pool: &str,
|
#[case] pool: &str,
|
||||||
#[case] token_in: &str,
|
#[case] token_in: &str,
|
||||||
|
|||||||
Reference in New Issue
Block a user