Skip to content

Commit f51aff2

Browse files
committed
Merge remote-tracking branch 'origin/master' into feat/synth-logs-node-indexing
# Conflicts: # Cargo.lock # Cargo.toml # integration-tests/Cargo.toml # pallets/staking/Cargo.toml # runtime/hydradx/Cargo.toml # runtime/hydradx/src/lib.rs
2 parents a534c65 + b941a66 commit f51aff2

73 files changed

Lines changed: 11620 additions & 58 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 79 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ members = [
4646
'pallets/liquidation',
4747
'precompiles/call-permit',
4848
'precompiles/flash-loan',
49+
'precompiles/lock-manager',
4950
'runtime-mock',
5051
'pallets/broadcast',
5152
'liquidation-worker-support',
5253
'pallets/hsm',
5354
"pallets/signet",
5455
"pallets/dispenser",
55-
"pallets/synthetic-logs"
56+
"pallets/synthetic-logs",
57+
"pallets/gigahdx",
58+
"pallets/gigahdx-rewards",
5659
]
5760

5861
resolver = "2"
@@ -166,6 +169,8 @@ pallet-hsm = { path = "pallets/hsm", default-features = false }
166169
pallet-parameters = { path = "pallets/parameters", default-features = false }
167170
pallet-signet = { path = "pallets/signet", default-features = false }
168171
pallet-dispenser = { path = "pallets/dispenser", default-features = false }
172+
pallet-gigahdx = { path = "pallets/gigahdx", default-features = false }
173+
pallet-gigahdx-rewards = { path = "pallets/gigahdx-rewards", default-features = false }
169174

170175
hydra-dx-build-script-utils = { path = "utils/build-script-utils", default-features = false }
171176
scraper = { path = "scraper", default-features = false }
@@ -175,6 +180,7 @@ integration-tests = { path = "integration-tests", default-features = false }
175180

176181
pallet-evm-precompile-call-permit = { path = "precompiles/call-permit", default-features = false }
177182
pallet-evm-precompile-flash-loan = { path = "precompiles/flash-loan", default-features = false }
183+
pallet-evm-precompile-lock-manager = { path = "precompiles/lock-manager", default-features = false }
178184
precompile-utils = { path = "precompiles/utils", default-features = false }
179185

180186
# Frame

integration-tests/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "runtime-integration-tests"
3-
version = "1.87.1"
3+
version = "1.88.1"
44
description = "Integration tests"
55
authors = ["GalacticCouncil"]
66
edition = "2021"
@@ -47,6 +47,8 @@ pallet-evm-accounts = { workspace = true }
4747
pallet-xyk-liquidity-mining = { workspace = true }
4848
pallet-transaction-pause = { workspace = true }
4949
pallet-liquidation = { workspace = true }
50+
pallet-gigahdx = { workspace = true }
51+
pallet-gigahdx-rewards = { workspace = true }
5052
liquidation-worker-support = { workspace = true }
5153
pallet-broadcast = { workspace = true }
5254
pallet-synthetic-logs = { workspace = true }
@@ -230,6 +232,8 @@ std = [
230232
"precompile-utils/std",
231233
"pallet-transaction-pause/std",
232234
"pallet-liquidation/std",
235+
"pallet-gigahdx/std",
236+
"pallet-gigahdx-rewards/std",
233237
"pallet-broadcast/std",
234238
"pallet-dispatcher/std",
235239
"pallet-hsm/std",
17.6 MB
Binary file not shown.

integration-tests/src/evm.rs

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,7 @@ mod chainlink_precompile {
19541954
use hydradx_traits::{router::AssetPair, AggregatedPriceOracle, OraclePeriod};
19551955
use pallet_ema_oracle::Price;
19561956
use pallet_lbp::AssetId;
1957-
use primitives::constants::chain::{OMNIPOOL_SOURCE, XYK_SOURCE};
1957+
use primitives::constants::chain::{GIGAHDX_SOURCE, OMNIPOOL_SOURCE, XYK_SOURCE};
19581958
use primitives::EvmAddress;
19591959

19601960
fn assert_prices_are_same(ema_price: Price, precompile_price: U256, asset_a_decimals: u8, asset_b_decimals: u8) {
@@ -2692,6 +2692,118 @@ mod chainlink_precompile {
26922692
pretty_assertions::assert_eq!(r, expected_decimals);
26932693
});
26942694
}
2695+
2696+
const STHDX: AssetId = 670;
2697+
const HDX_ID: AssetId = 0;
2698+
2699+
fn register_st_hdx() {
2700+
if hydradx_runtime::AssetRegistry::decimals(STHDX).is_some() {
2701+
return;
2702+
}
2703+
assert_ok!(hydradx_runtime::AssetRegistry::register(
2704+
RuntimeOrigin::root(),
2705+
Some(STHDX),
2706+
Some(b"stHDX".to_vec().try_into().unwrap()),
2707+
pallet_asset_registry::AssetType::Token,
2708+
Some(1u128),
2709+
Some(b"stHDX".to_vec().try_into().unwrap()),
2710+
Some(12u8),
2711+
None,
2712+
None,
2713+
true,
2714+
));
2715+
}
2716+
2717+
fn seed_gigapot_and_supply(gigapot_hdx: Balance, st_hdx_supply: Balance) {
2718+
// `total_gigahdx_supply` reads orml-tokens issuance directly.
2719+
orml_tokens::TotalIssuance::<Runtime>::set(STHDX, st_hdx_supply);
2720+
let gigapot = pallet_gigahdx::Pallet::<Runtime>::gigapot_account_id();
2721+
assert_ok!(Balances::force_set_balance(RuntimeOrigin::root(), gigapot, gigapot_hdx,));
2722+
}
2723+
2724+
fn chainlink_latest_answer(address: EvmAddress) -> U256 {
2725+
let data = EvmDataWriter::new_with_selector(AggregatorInterface::LatestAnswer).build();
2726+
let mut handle = MockHandle {
2727+
input: data,
2728+
context: Context {
2729+
address: evm_address(),
2730+
caller: address,
2731+
apparent_value: U256::from(0),
2732+
},
2733+
code_address: address,
2734+
is_static: true,
2735+
};
2736+
let PrecompileOutput { output, exit_status } =
2737+
ChainlinkOraclePrecompile::<Runtime>::execute(&mut handle).unwrap();
2738+
pretty_assertions::assert_eq!(exit_status, ExitSucceed::Returned);
2739+
U256::from_big_endian(&output)
2740+
}
2741+
2742+
#[test]
2743+
fn chainlink_precompile_should_return_gigahdx_exchange_rate_when_source_is_gigahdx() {
2744+
TestNet::reset();
2745+
2746+
Hydra::execute_with(|| {
2747+
register_st_hdx();
2748+
// 110 HDX in gigapot, 100 stHDX issued ⇒ rate = 1.1.
2749+
seed_gigapot_and_supply(110 * UNITS, 100 * UNITS);
2750+
2751+
pretty_assertions::assert_eq!(
2752+
pallet_gigahdx::Pallet::<Runtime>::exchange_rate().cmp(&hydra_dx_math::ratio::Ratio::new(11, 10)),
2753+
std::cmp::Ordering::Equal
2754+
);
2755+
2756+
let address = encode_oracle_address(STHDX, HDX_ID, OraclePeriod::TenMinutes, GIGAHDX_SOURCE);
2757+
2758+
// Pin the canonical mainnet feed address.
2759+
pretty_assertions::assert_eq!(
2760+
address,
2761+
EvmAddress::from(hex!("0000010267696761686478730000029e00000000"))
2762+
);
2763+
2764+
pretty_assertions::assert_eq!(chainlink_latest_answer(address), U256::from(110_000_000u128));
2765+
});
2766+
}
2767+
2768+
#[test]
2769+
fn chainlink_precompile_should_floor_at_one_when_gigahdx_reserves_drained() {
2770+
TestNet::reset();
2771+
2772+
Hydra::execute_with(|| {
2773+
register_st_hdx();
2774+
// Full drain: native rate would be 0 — pallet floor must clamp to 1.0.
2775+
seed_gigapot_and_supply(0, 100 * UNITS);
2776+
2777+
pretty_assertions::assert_eq!(
2778+
pallet_gigahdx::Pallet::<Runtime>::exchange_rate().cmp(&hydra_dx_math::ratio::Ratio::one()),
2779+
std::cmp::Ordering::Equal
2780+
);
2781+
2782+
let address = encode_oracle_address(STHDX, HDX_ID, OraclePeriod::TenMinutes, GIGAHDX_SOURCE);
2783+
2784+
pretty_assertions::assert_eq!(chainlink_latest_answer(address), U256::from(100_000_000u128));
2785+
});
2786+
}
2787+
2788+
#[test]
2789+
fn chainlink_precompile_should_floor_at_one_when_gigahdx_partially_drained() {
2790+
TestNet::reset();
2791+
2792+
Hydra::execute_with(|| {
2793+
register_st_hdx();
2794+
// Partial drain: native rate would be 0.5 — clamp must hit 1.0, not 50_000_000.
2795+
seed_gigapot_and_supply(50 * UNITS, 100 * UNITS);
2796+
2797+
pretty_assertions::assert_eq!(
2798+
pallet_gigahdx::Pallet::<Runtime>::exchange_rate().cmp(&hydra_dx_math::ratio::Ratio::one()),
2799+
std::cmp::Ordering::Equal
2800+
);
2801+
2802+
let address = encode_oracle_address(STHDX, HDX_ID, OraclePeriod::TenMinutes, GIGAHDX_SOURCE);
2803+
2804+
pretty_assertions::assert_eq!(chainlink_latest_answer(address), U256::from(100_000_000u128));
2805+
});
2806+
}
26952807
}
26962808

26972809
mod contract_deployment {

0 commit comments

Comments
 (0)