fix: Curve factory addresses are utf-8 encoded
Took 30 minutes
This commit is contained in:
@@ -1783,7 +1783,11 @@ mod tests {
|
|||||||
|
|
||||||
let static_attributes = HashMap::from([(
|
let static_attributes = HashMap::from([(
|
||||||
"factory".to_string(),
|
"factory".to_string(),
|
||||||
Bytes::from("0x98ee851a00abee0d95d08cf4ca2bdce32aeaaf7f"),
|
Bytes::from(
|
||||||
|
"0x98ee851a00abee0d95d08cf4ca2bdce32aeaaf7f"
|
||||||
|
.as_bytes()
|
||||||
|
.to_vec(),
|
||||||
|
),
|
||||||
)]);
|
)]);
|
||||||
|
|
||||||
let component = ProtocolComponent {
|
let component = ProtocolComponent {
|
||||||
@@ -1839,7 +1843,14 @@ mod tests {
|
|||||||
let token_in = Bytes::from("0x0000000000000000000000000000000000000000"); // ETH
|
let token_in = Bytes::from("0x0000000000000000000000000000000000000000"); // ETH
|
||||||
let token_out = Bytes::from("0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84"); // STETH
|
let token_out = Bytes::from("0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84"); // STETH
|
||||||
|
|
||||||
let static_attributes = HashMap::from([("factory".to_string(), Bytes::from(vec![]))]);
|
let static_attributes = HashMap::from([(
|
||||||
|
"factory".to_string(),
|
||||||
|
Bytes::from(
|
||||||
|
"0x0000000000000000000000000000000000000000"
|
||||||
|
.as_bytes()
|
||||||
|
.to_vec(),
|
||||||
|
),
|
||||||
|
)]);
|
||||||
|
|
||||||
let component = ProtocolComponent {
|
let component = ProtocolComponent {
|
||||||
id: String::from("0xDC24316b9AE028F1497c275EB9192a3Ea0f67022"),
|
id: String::from("0xDC24316b9AE028F1497c275EB9192a3Ea0f67022"),
|
||||||
|
|||||||
@@ -380,11 +380,7 @@ pub struct CurveSwapEncoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CurveSwapEncoder {
|
impl CurveSwapEncoder {
|
||||||
fn get_pool_type(
|
fn get_pool_type(&self, pool_id: &str, factory_address: &str) -> Result<U8, EncodingError> {
|
||||||
&self,
|
|
||||||
pool_id: &str,
|
|
||||||
factory_address: Option<&str>,
|
|
||||||
) -> Result<U8, EncodingError> {
|
|
||||||
match pool_id {
|
match pool_id {
|
||||||
// TriPool
|
// TriPool
|
||||||
"0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7" => Ok(U8::from(1)),
|
"0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7" => Ok(U8::from(1)),
|
||||||
@@ -397,25 +393,22 @@ impl CurveSwapEncoder {
|
|||||||
// FRAXUSDCPool
|
// FRAXUSDCPool
|
||||||
"0xDcEF968d416a41Cdac0ED8702fAC8128A64241A2" => Ok(U8::from(1)),
|
"0xDcEF968d416a41Cdac0ED8702fAC8128A64241A2" => Ok(U8::from(1)),
|
||||||
_ => match factory_address {
|
_ => match factory_address {
|
||||||
Some(address) => match address {
|
// CryptoSwapNG factory
|
||||||
// CryptoSwapNG factory
|
"0x6A8cbed756804B16E05E741eDaBd5cB544AE21bf" => Ok(U8::from(1)),
|
||||||
"0x6A8cbed756804B16E05E741eDaBd5cB544AE21bf" => Ok(U8::from(1)),
|
// Metapool factory
|
||||||
// Metapool factory
|
"0xB9fC157394Af804a3578134A6585C0dc9cc990d4" => Ok(U8::from(1)),
|
||||||
"0xB9fC157394Af804a3578134A6585C0dc9cc990d4" => Ok(U8::from(1)),
|
// CryptoPool factory
|
||||||
// CryptoPool factory
|
"0xF18056Bbd320E96A48e3Fbf8bC061322531aac99" => Ok(U8::from(2)),
|
||||||
"0xF18056Bbd320E96A48e3Fbf8bC061322531aac99" => Ok(U8::from(2)),
|
// Tricrypto factory
|
||||||
// Tricrypto factory
|
"0x0c0e5f2fF0ff18a3be9b835635039256dC4B4963" => Ok(U8::from(3)),
|
||||||
"0x0c0e5f2fF0ff18a3be9b835635039256dC4B4963" => Ok(U8::from(3)),
|
// Twocrypto factory
|
||||||
// Twocrypto factory
|
"0x98EE851a00abeE0d95D08cF4CA2BdCE32aeaAF7F" => Ok(U8::from(2)),
|
||||||
"0x98EE851a00abeE0d95D08cF4CA2BdCE32aeaAF7F" => Ok(U8::from(2)),
|
// StableSwap factory
|
||||||
// StableSwap factory
|
"0x4F8846Ae9380B90d2E71D5e3D042dff3E7ebb40d" => Ok(U8::from(1)),
|
||||||
"0x4F8846Ae9380B90d2E71D5e3D042dff3E7ebb40d" => Ok(U8::from(1)),
|
_ => Err(EncodingError::FatalError(format!(
|
||||||
_ => Err(EncodingError::FatalError(format!(
|
"Unsupported curve factory address: {}",
|
||||||
"Unsupported curve factory address: {}",
|
factory_address
|
||||||
address
|
))),
|
||||||
))),
|
|
||||||
},
|
|
||||||
None => Err(EncodingError::FatalError("Unsupported curve pool type".to_string())),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -532,14 +525,17 @@ impl SwapEncoder for CurveSwapEncoder {
|
|||||||
approval_needed = true;
|
approval_needed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let factory_bytes = get_static_attribute(&swap, "factory")?;
|
let factory_bytes = get_static_attribute(&swap, "factory")?.to_vec();
|
||||||
let factory = if factory_bytes.is_empty() {
|
// the conversion to Address is necessary to checksum the address
|
||||||
None
|
let factory_address =
|
||||||
} else {
|
Address::from_str(std::str::from_utf8(&factory_bytes).map_err(|_| {
|
||||||
Some(Address::from_slice(&factory_bytes).to_string())
|
EncodingError::FatalError(
|
||||||
};
|
"Failed to convert curve factory address to string".to_string(),
|
||||||
|
)
|
||||||
|
})?)
|
||||||
|
.map_err(|_| EncodingError::FatalError("Invalid curve factory address".to_string()))?;
|
||||||
|
|
||||||
let pool_type = self.get_pool_type(&swap.component.id, factory.as_deref())?;
|
let pool_type = self.get_pool_type(&swap.component.id, &factory_address.to_string())?;
|
||||||
|
|
||||||
let (i, j) = self.get_coin_indexes(component_address, token_in, token_out)?;
|
let (i, j) = self.get_coin_indexes(component_address, token_in, token_out)?;
|
||||||
|
|
||||||
@@ -1196,7 +1192,14 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_curve_encode_tripool() {
|
fn test_curve_encode_tripool() {
|
||||||
let mut static_attributes: HashMap<String, Bytes> = HashMap::new();
|
let mut static_attributes: HashMap<String, Bytes> = HashMap::new();
|
||||||
static_attributes.insert("factory".into(), Bytes::from(vec![]));
|
static_attributes.insert(
|
||||||
|
"factory".into(),
|
||||||
|
Bytes::from(
|
||||||
|
"0x0000000000000000000000000000000000000000"
|
||||||
|
.as_bytes()
|
||||||
|
.to_vec(),
|
||||||
|
),
|
||||||
|
);
|
||||||
let curve_tri_pool = ProtocolComponent {
|
let curve_tri_pool = ProtocolComponent {
|
||||||
id: String::from("0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7"),
|
id: String::from("0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7"),
|
||||||
protocol_system: String::from("vm:curve"),
|
protocol_system: String::from("vm:curve"),
|
||||||
@@ -1256,7 +1259,11 @@ mod tests {
|
|||||||
let mut static_attributes: HashMap<String, Bytes> = HashMap::new();
|
let mut static_attributes: HashMap<String, Bytes> = HashMap::new();
|
||||||
static_attributes.insert(
|
static_attributes.insert(
|
||||||
"factory".into(),
|
"factory".into(),
|
||||||
Bytes::from("0x6A8cbed756804B16E05E741eDaBd5cB544AE21bf"),
|
Bytes::from(
|
||||||
|
"0x6A8cbed756804B16E05E741eDaBd5cB544AE21bf"
|
||||||
|
.as_bytes()
|
||||||
|
.to_vec(),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
let curve_pool = ProtocolComponent {
|
let curve_pool = ProtocolComponent {
|
||||||
id: String::from("0x02950460E2b9529D0E00284A5fA2d7bDF3fA4d72"),
|
id: String::from("0x02950460E2b9529D0E00284A5fA2d7bDF3fA4d72"),
|
||||||
@@ -1316,7 +1323,14 @@ mod tests {
|
|||||||
// This test is for the stETH pool, which is a special case in Curve
|
// This test is for the stETH pool, which is a special case in Curve
|
||||||
// where the token in is ETH but not as the zero address.
|
// where the token in is ETH but not as the zero address.
|
||||||
let mut static_attributes: HashMap<String, Bytes> = HashMap::new();
|
let mut static_attributes: HashMap<String, Bytes> = HashMap::new();
|
||||||
static_attributes.insert("factory".into(), Bytes::from(vec![]));
|
static_attributes.insert(
|
||||||
|
"factory".into(),
|
||||||
|
Bytes::from(
|
||||||
|
"0x0000000000000000000000000000000000000000"
|
||||||
|
.as_bytes()
|
||||||
|
.to_vec(),
|
||||||
|
),
|
||||||
|
);
|
||||||
let curve_pool = ProtocolComponent {
|
let curve_pool = ProtocolComponent {
|
||||||
id: String::from("0xDC24316b9AE028F1497c275EB9192a3Ea0f67022"),
|
id: String::from("0xDC24316b9AE028F1497c275EB9192a3Ea0f67022"),
|
||||||
protocol_system: String::from("vm:curve"),
|
protocol_system: String::from("vm:curve"),
|
||||||
|
|||||||
Reference in New Issue
Block a user