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

CCCP-313, BTC price feed #106

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions configs/config.mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ evm_providers:
chainlink_usdc_usd_address: "0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6"
chainlink_usdt_usd_address: "0x3E7d1eAB13ad0104d2750B8863b489D65364e32D"
chainlink_dai_usd_address: "0xAed0c38402a5d19df6E4c03F4E2DceD6e29c1ee9"
chainlink_btc_usd_address: "0xf4030086522a5beea4988f8ca5b36dbc97bee88c"
- name: "bsc"
id: 56
provider: "<YOUR_BSC_RPC_ENDPOINT>"
Expand Down
2 changes: 2 additions & 0 deletions configs/config.testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ evm_providers:
chainlink_usdc_usd_address: "0x90c069C4538adAc136E051052E14c1cD799C41B7"
chainlink_usdt_usd_address: "0xEca2605f0BCF2BA5966372C99837b1F182d3D620"
chainlink_dai_usd_address: "0xE4eE17114774713d2De0eC0f035d4F7665fc025D"
chainlink_btc_usd_address: "0x5741306c21795FdCBb9b265Ea0255F499DFe515C"
- name: "mumbai"
id: 80001
provider: "<YOUR_MUMBAI_RPC_ENDPOINT>"
Expand All @@ -50,6 +51,7 @@ evm_providers:
chainlink_usdc_usd_address: "0x572dDec9087154dC5dfBB1546Bb62713147e0Ab0"
chainlink_usdt_usd_address: "0x92C09849638959196E976289418e5973CC96d645"
chainlink_dai_usd_address: "0x0FCAa9c899EC5A91eBc3D5Dd869De833b06fB046"
chainlink_btc_usd_address: "0x007A22900a3B98143368Bd5906f8E17e9867581b"
- name: "base-sepolia"
id: 84532
provider: "<YOUR_BASE_SEPOLIA_RPC_ENDPOINT>"
Expand Down
7 changes: 5 additions & 2 deletions periodic/src/price_source/chainlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ impl<T: JsonRpcClient + 'static> PriceFetcher for ChainlinkPriceFetcher<T> {
let symbol_str = symbol.as_str();

match symbol_str {
"USDC" | "USDT" | "DAI" => {
"USDC" | "USDT" | "DAI" | "BTC" => {
return if let Some(contract) = match symbol_str {
"USDC" => &client.aggregator_contracts.chainlink_usdc_usd,
"USDT" => &client.aggregator_contracts.chainlink_usdt_usd,
"DAI" => &client.aggregator_contracts.chainlink_dai_usd,
"BTC" => &client.aggregator_contracts.chainlink_btc_usd,
_ => todo!(),
} {
let (_, price, _, _, _) = contract.latest_round_data().await.unwrap();
Expand Down Expand Up @@ -50,7 +51,9 @@ impl<T: JsonRpcClient + 'static> PriceFetcher for ChainlinkPriceFetcher<T> {
async fn get_tickers(&self) -> Result<BTreeMap<String, PriceResponse>, Error> {
let mut ret = BTreeMap::new();

for symbol in vec!["USDC".to_string(), "USDT".to_string(), "DAI".to_string()] {
for symbol in
vec!["USDC".to_string(), "USDT".to_string(), "DAI".to_string(), "BTC".to_string()]
{
match self.get_ticker_with_symbol(symbol.clone()).await {
Ok(ticker) => ret.insert(symbol, ticker),
Err(_) => continue,
Expand Down
15 changes: 9 additions & 6 deletions periodic/src/price_source/coingecko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<T: JsonRpcClient> PriceFetcher for CoingeckoPriceFetcher<T> {
Ok(ret)
},
Err(e) => Err(e),
}
};
}
}

Expand All @@ -91,6 +91,7 @@ impl<T: JsonRpcClient> CoingeckoPriceFetcher<T> {
"bifi".into(),
"tether".into(),
"dai".into(),
"bitcoin".into(),
];

let support_coin_list: Vec<SupportedCoin> = Self::get_all_coin_list()
Expand All @@ -116,7 +117,7 @@ impl<T: JsonRpcClient> CoingeckoPriceFetcher<T> {
.await
.and_then(Response::error_for_status)
{
Ok(response) =>
Ok(response) => {
return match response.json::<Vec<SupportedCoin>>().await {
Ok(coins) => Ok(coins),
Err(e) => {
Expand All @@ -129,7 +130,8 @@ impl<T: JsonRpcClient> CoingeckoPriceFetcher<T> {
);
Err(Error)
},
},
}
},
Err(e) => {
log::warn!(
target: LOG_TARGET,
Expand All @@ -156,7 +158,7 @@ impl<T: JsonRpcClient> CoingeckoPriceFetcher<T> {

loop {
match reqwest::get(url.clone()).await.and_then(Response::error_for_status) {
Ok(response) =>
Ok(response) => {
return match response.json::<BTreeMap<String, BTreeMap<String, f64>>>().await {
Ok(result) => Ok(result),
Err(e) => {
Expand All @@ -168,10 +170,11 @@ impl<T: JsonRpcClient> CoingeckoPriceFetcher<T> {
);
Err(Error)
},
},
}
},
Err(e) => {
if retries_remaining == 0 {
return Err(Error)
return Err(Error);
}

log::warn!(
Expand Down
2 changes: 2 additions & 0 deletions primitives/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ pub struct EVMProvider {
pub chainlink_usdt_usd_address: Option<String>,
/// Chainlink dai/usd aggregator
pub chainlink_dai_usd_address: Option<String>,
/// Chainlink btc/usd aggregator
pub chainlink_btc_usd_address: Option<String>,
}

#[derive(Debug, Clone, Deserialize, PartialEq)]
Expand Down
32 changes: 14 additions & 18 deletions primitives/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ pub struct AggregatorContracts<T> {
pub chainlink_usdt_usd: Option<ChainlinkContract<Provider<T>>>,
/// Chainlink dai/usd aggregator
pub chainlink_dai_usd: Option<ChainlinkContract<Provider<T>>>,
/// Chainlink btc/usd aggregator
pub chainlink_btc_usd: Option<ChainlinkContract<Provider<T>>>,
}

impl<T: JsonRpcClient> AggregatorContracts<T> {
Expand All @@ -89,26 +91,20 @@ impl<T: JsonRpcClient> AggregatorContracts<T> {
chainlink_usdc_usd_address: Option<String>,
chainlink_usdt_usd_address: Option<String>,
chainlink_dai_usd_address: Option<String>,
chainlink_btc_usd_address: Option<String>,
) -> Self {
let create_contract_instance = |address: String| {
ChainlinkContract::new(
H160::from_str(&address).expect(INVALID_CONTRACT_ADDRESS),
provider.clone(),
)
};

Self {
chainlink_usdc_usd: chainlink_usdc_usd_address.map(|address| {
ChainlinkContract::new(
H160::from_str(&address).expect(INVALID_CONTRACT_ADDRESS),
provider.clone(),
)
}),
chainlink_usdt_usd: chainlink_usdt_usd_address.map(|address| {
ChainlinkContract::new(
H160::from_str(&address).expect(INVALID_CONTRACT_ADDRESS),
provider.clone(),
)
}),
chainlink_dai_usd: chainlink_dai_usd_address.map(|address| {
ChainlinkContract::new(
H160::from_str(&address).expect(INVALID_CONTRACT_ADDRESS),
provider.clone(),
)
}),
chainlink_usdc_usd: chainlink_usdc_usd_address.map(create_contract_instance),
chainlink_usdt_usd: chainlink_usdt_usd_address.map(create_contract_instance),
chainlink_dai_usd: chainlink_dai_usd_address.map(create_contract_instance),
chainlink_btc_usd: chainlink_btc_usd_address.map(create_contract_instance),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions relayer/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ fn construct_managers(
evm_provider.chainlink_usdc_usd_address.clone(),
evm_provider.chainlink_usdt_usd_address.clone(),
evm_provider.chainlink_dai_usd_address.clone(),
evm_provider.chainlink_btc_usd_address.clone(),
),
system.debug_mode.unwrap_or(false),
));
Expand Down