Skip to content

Commit 41ffd91

Browse files
authored
support vana (#548)
1 parent fb4e87a commit 41ffd91

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/evm/onchain/endpoints.rs

+42
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub enum Chain {
5353
LOCAL,
5454
IOTEX,
5555
SCROLL,
56+
VANA,
5657
}
5758

5859
pub trait PriceOracle: Debug {
@@ -87,6 +88,7 @@ impl FromStr for Chain {
8788
"local" => Ok(Self::LOCAL),
8889
"iotex" => Ok(Self::IOTEX),
8990
"scroll" => Ok(Self::SCROLL),
91+
"vana" => Ok(Self::VANA),
9092
_ => Err(()),
9193
}
9294
}
@@ -152,6 +154,7 @@ impl Chain {
152154
59144 => Self::LINEA,
153155
4689 => Self::IOTEX,
154156
534352 => Self::SCROLL,
157+
1480 => Self::VANA,
155158
31337 => Self::LOCAL,
156159
_ => return Err(anyhow!("Unknown chain id: {}", chain_id)),
157160
})
@@ -179,6 +182,7 @@ impl Chain {
179182
Chain::LINEA => 59144,
180183
Chain::IOTEX => 4689,
181184
Chain::SCROLL => 534352,
185+
Chain::VANA => 1480,
182186
Chain::LOCAL => 31337,
183187
}
184188
}
@@ -206,6 +210,7 @@ impl Chain {
206210
Chain::LOCAL => "local",
207211
Chain::IOTEX => "iotex",
208212
Chain::SCROLL => "scroll",
213+
Chain::VANA => "vana",
209214
}
210215
.to_string()
211216
}
@@ -235,6 +240,7 @@ impl Chain {
235240
Chain::LINEA => "https://rpc.ankr.com/linea",
236241
Chain::IOTEX => "https://rpc.ankr.com/iotex",
237242
Chain::SCROLL => "https://rpc.ankr.com/scroll",
243+
Chain::VANA => "https://rpc.vana.org",
238244
Chain::LOCAL => "http://localhost:8545",
239245
}
240246
.to_string()
@@ -263,6 +269,7 @@ impl Chain {
263269
Chain::LOCAL => "http://localhost:8080/abi/",
264270
Chain::IOTEX => "https://babel-api.mainnet.IoTeX.io",
265271
Chain::SCROLL => "https://api.scrollscan.com/api",
272+
Chain::VANA => "https://api.vanascan.io/api/v2",
266273
}
267274
.to_string()
268275
}
@@ -393,6 +400,7 @@ impl ChainConfig for OnChainConfig {
393400
"eth" | "arbitrum" | "scroll" => return pegged_token.get("WETH").unwrap().to_string(),
394401
"bsc" => return pegged_token.get("WBNB").unwrap().to_string(),
395402
"polygon" => return pegged_token.get("WMATIC").unwrap().to_string(),
403+
"vana" => return pegged_token.get("WVANA").unwrap().to_string(),
396404
"local" => return pegged_token.get("ZERO").unwrap().to_string(),
397405
// "mumbai" => panic!("Not supported"),
398406
_ => {
@@ -461,6 +469,14 @@ impl ChainConfig for OnChainConfig {
461469
.iter()
462470
.map(|(k, v)| (k.to_string(), v.to_string()))
463471
.collect(),
472+
"vana" => [
473+
("WETH", "0x2F6F07CDcf3588944Bf4C42aC74ff24bF56e7590"),
474+
("USDC.e", "0xF1815bd50389c46847f0Bda824eC8da914045D14"),
475+
("WVANA", "0x00EDdD9621Fb08436d0331c149D1690909a5906d"),
476+
]
477+
.iter()
478+
.map(|(k, v)| (k.to_string(), v.to_string()))
479+
.collect(),
464480
"local" => [("ZERO", "0x0000000000000000000000000000000000000000")]
465481
.iter()
466482
.map(|(k, v)| (k.to_string(), v.to_string()))
@@ -698,6 +714,10 @@ impl OnChainConfig {
698714
}
699715

700716
pub fn fetch_abi_uncached(&self, address: EVMAddress) -> Option<String> {
717+
if self.chain_name == "vana" {
718+
return self.fetch_vana_abi_uncached(address);
719+
}
720+
701721
#[cfg(feature = "no_etherscan")]
702722
{
703723
return None;
@@ -740,6 +760,28 @@ impl OnChainConfig {
740760
}
741761
}
742762

763+
fn fetch_vana_abi_uncached(&self, address: EVMAddress) -> Option<String> {
764+
let endpoint = format!("{}/smart-contracts/{:?}", self.etherscan_base, address);
765+
766+
// info!(">> {}", endpoint);
767+
match self.get(endpoint.clone()) {
768+
Some(resp) => match serde_json::from_str::<Value>(&resp) {
769+
Ok(json) => {
770+
// info!("<< {}", json);
771+
json.get("abi").map(|abi| abi.to_string())
772+
}
773+
Err(_) => {
774+
error!("Failed to parse JSON response from Vana API");
775+
None
776+
}
777+
},
778+
None => {
779+
error!("Failed to fetch ABI from Vana API: {}", endpoint);
780+
None
781+
}
782+
}
783+
}
784+
743785
pub fn fetch_abi(&mut self, address: EVMAddress) -> Option<String> {
744786
if self.abi_cache.contains_key(&address) {
745787
return self.abi_cache.get(&address).unwrap().clone();

0 commit comments

Comments
 (0)