Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support vana #548

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/evm/onchain/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub enum Chain {
LOCAL,
IOTEX,
SCROLL,
VANA,
}

pub trait PriceOracle: Debug {
Expand Down Expand Up @@ -87,6 +88,7 @@ impl FromStr for Chain {
"local" => Ok(Self::LOCAL),
"iotex" => Ok(Self::IOTEX),
"scroll" => Ok(Self::SCROLL),
"vana" => Ok(Self::VANA),
_ => Err(()),
}
}
Expand Down Expand Up @@ -152,6 +154,7 @@ impl Chain {
59144 => Self::LINEA,
4689 => Self::IOTEX,
534352 => Self::SCROLL,
1480 => Self::VANA,
31337 => Self::LOCAL,
_ => return Err(anyhow!("Unknown chain id: {}", chain_id)),
})
Expand Down Expand Up @@ -179,6 +182,7 @@ impl Chain {
Chain::LINEA => 59144,
Chain::IOTEX => 4689,
Chain::SCROLL => 534352,
Chain::VANA => 1480,
Chain::LOCAL => 31337,
}
}
Expand Down Expand Up @@ -206,6 +210,7 @@ impl Chain {
Chain::LOCAL => "local",
Chain::IOTEX => "iotex",
Chain::SCROLL => "scroll",
Chain::VANA => "vana",
}
.to_string()
}
Expand Down Expand Up @@ -235,6 +240,7 @@ impl Chain {
Chain::LINEA => "https://rpc.ankr.com/linea",
Chain::IOTEX => "https://rpc.ankr.com/iotex",
Chain::SCROLL => "https://rpc.ankr.com/scroll",
Chain::VANA => "https://rpc.vana.org",
Chain::LOCAL => "http://localhost:8545",
}
.to_string()
Expand Down Expand Up @@ -263,6 +269,7 @@ impl Chain {
Chain::LOCAL => "http://localhost:8080/abi/",
Chain::IOTEX => "https://babel-api.mainnet.IoTeX.io",
Chain::SCROLL => "https://api.scrollscan.com/api",
Chain::VANA => "https://api.vanascan.io/api/v2",
}
.to_string()
}
Expand Down Expand Up @@ -393,6 +400,7 @@ impl ChainConfig for OnChainConfig {
"eth" | "arbitrum" | "scroll" => return pegged_token.get("WETH").unwrap().to_string(),
"bsc" => return pegged_token.get("WBNB").unwrap().to_string(),
"polygon" => return pegged_token.get("WMATIC").unwrap().to_string(),
"vana" => return pegged_token.get("WVANA").unwrap().to_string(),
"local" => return pegged_token.get("ZERO").unwrap().to_string(),
// "mumbai" => panic!("Not supported"),
_ => {
Expand Down Expand Up @@ -461,6 +469,14 @@ impl ChainConfig for OnChainConfig {
.iter()
.map(|(k, v)| (k.to_string(), v.to_string()))
.collect(),
"vana" => [
("WETH", "0x2F6F07CDcf3588944Bf4C42aC74ff24bF56e7590"),
("USDC.e", "0xF1815bd50389c46847f0Bda824eC8da914045D14"),
("WVANA", "0x00EDdD9621Fb08436d0331c149D1690909a5906d"),
]
.iter()
.map(|(k, v)| (k.to_string(), v.to_string()))
.collect(),
"local" => [("ZERO", "0x0000000000000000000000000000000000000000")]
.iter()
.map(|(k, v)| (k.to_string(), v.to_string()))
Expand Down Expand Up @@ -698,6 +714,10 @@ impl OnChainConfig {
}

pub fn fetch_abi_uncached(&self, address: EVMAddress) -> Option<String> {
if self.chain_name == "vana" {
return self.fetch_vana_abi_uncached(address);
}

#[cfg(feature = "no_etherscan")]
{
return None;
Expand Down Expand Up @@ -740,6 +760,28 @@ impl OnChainConfig {
}
}

fn fetch_vana_abi_uncached(&self, address: EVMAddress) -> Option<String> {
let endpoint = format!("{}/smart-contracts/{:?}", self.etherscan_base, address);

// info!(">> {}", endpoint);
match self.get(endpoint.clone()) {
Some(resp) => match serde_json::from_str::<Value>(&resp) {
Ok(json) => {
// info!("<< {}", json);
json.get("abi").map(|abi| abi.to_string())
}
Err(_) => {
error!("Failed to parse JSON response from Vana API");
None
}
},
None => {
error!("Failed to fetch ABI from Vana API: {}", endpoint);
None
}
}
}

pub fn fetch_abi(&mut self, address: EVMAddress) -> Option<String> {
if self.abi_cache.contains_key(&address) {
return self.abi_cache.get(&address).unwrap().clone();
Expand Down
Loading