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

feat: chainlink oracle adapter #1006

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Conversation

Roznovjak
Copy link
Contributor

Fixes #993

@Roznovjak Roznovjak self-assigned this Jan 29, 2025
@Roznovjak Roznovjak requested a review from mrq1911 January 29, 2025 20:20
Copy link

github-actions bot commented Jan 29, 2025

Crate versions that have not been updated:

  • runtime-integration-tests: v1.32.1

Crate versions that have been updated:

  • hydradx-runtime: v285.0.0 -> v286.0.0

Runtime version has been increased.

integration-tests/src/evm.rs Show resolved Hide resolved
@@ -121,6 +121,8 @@ impl Get<Multiplier> for TransactionPaymentMultiplier {
}
}

pub const USDT: AssetId = 10u32;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would not be better to read this from asset registry based on Location? Similarly what we have for DOT so

pub struct DotAssetId;
impl Get<AssetId> for DotAssetId {
	fn get() -> AssetId {
		let invalid_id =
			pallet_asset_registry::Pallet::<crate::Runtime>::next_asset_id().defensive_unwrap_or(AssetId::MAX);

		match pallet_asset_registry::Pallet::<crate::Runtime>::location_to_asset(DOT_ASSET_LOCATION) {
			Some(asset_id) => asset_id,
			None => invalid_id,
		}
	}
}

}
}

impl<QuoteAsset, Runtime> ChainlinkOraclePrecompile<QuoteAsset, Runtime>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i probably dont get what Chainlink is doing, but why is this Chainlink specific? Do we do anything with the official Chainlink oracle network?


/// Encoding is 7 bytes for precompile prefix 0x00000000000001,
/// followed by 1 byte for encoded OraclePeriod enum, 8 bytes for Source, and 4 bytes for AssetId.
pub fn encode_evm_address(asset_id: AssetId, period: OraclePeriod, source: Source) -> Option<EvmAddress> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we could do an invariant test for this to make sure it never panics?

})?;

// use Router to get a route
let price = if source == [0; 8] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make a constant for this magic number [0;8], like EMPTY_SOURCE or so

exit_status: pallet_evm::ExitError::Other("Decimals not available".into()),
})?;

// use Router to get a route
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// use Router to get a route
// In case of empty source, we retrieve onchain route

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add HDX chainlink oracle adapter
2 participants