From faffa4337edad7033a0e706103e3c279a3ab4698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Fri, 21 Jun 2024 15:47:53 +0100 Subject: [PATCH] sdk: add native VPs with filled-in concrete system types --- crates/sdk/src/lib.rs | 2 + crates/sdk/src/validation.rs | 119 +++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 crates/sdk/src/validation.rs diff --git a/crates/sdk/src/lib.rs b/crates/sdk/src/lib.rs index c59fbc2eb90..1ebc5676dc8 100644 --- a/crates/sdk/src/lib.rs +++ b/crates/sdk/src/lib.rs @@ -33,6 +33,8 @@ pub mod masp; pub mod signing; #[allow(clippy::result_large_err)] pub mod tx; +#[cfg(any(test, feature = "testing", feature = "validation"))] +pub mod validation; pub mod error; pub mod events; diff --git a/crates/sdk/src/validation.rs b/crates/sdk/src/validation.rs new file mode 100644 index 00000000000..2ed8ed02104 --- /dev/null +++ b/crates/sdk/src/validation.rs @@ -0,0 +1,119 @@ +//! Validity predictates dependency injection soup. In here, we're assigning +//! concrete types for generic type params of native VPs. + +use namada_vm::wasm::run::VpEvalWasm; +use namada_vm::wasm::VpCache; +use namada_vp::native_vp::{self, CtxPreStorageRead}; + +use crate::state::StateRead; +use crate::{eth_bridge, governance, ibc, parameters, proof_of_stake, token}; + +/// Native VP context +pub type NativeVpCtx<'a, S, CA> = + native_vp::Ctx<'a, S, VpCache, Eval>; + +/// VP WASM evaluator +type Eval = VpEvalWasm<::D, ::H, CA>; + +/// Native PoS VP +pub type PosVp<'a, S, CA> = proof_of_stake::vp::PosVp< + 'a, + S, + VpCache, + Eval, + GovPreStore<'a, S, CA>, +>; + +/// Native IBC VP +pub type IbcVp<'a, S, CA> = ibc::vp::Ibc< + 'a, + S, + VpCache, + Eval, + ParamsPreStore<'a, S, CA>, + GovPreStore<'a, S, CA>, + token::Store< + ibc::vp::context::PseudoExecutionStorage< + 'a, + 'a, + S, + VpCache, + Eval, + >, + >, + PosPreStore<'a, S, CA>, +>; + +/// Native parameters VP +pub type ParametersVp<'a, S, CA> = parameters::vp::ParametersVp< + 'a, + S, + VpCache, + Eval, + GovPreStore<'a, S, CA>, +>; + +/// Native governance VP +pub type GovernanceVp<'a, S, CA> = governance::vp::GovernanceVp< + 'a, + S, + VpCache, + Eval, + PosPreStore<'a, S, CA>, + TokenKeys, +>; + +/// Native PGF VP +pub type PgfVp<'a, S, CA> = + governance::vp::pgf::PgfVp<'a, S, VpCache, Eval>; + +/// Native multitoken VP +pub type MultitokenVp<'a, S, CA> = token::vp::MultitokenVp< + 'a, + S, + VpCache, + Eval, + ParamsPreStore<'a, S, CA>, + GovPreStore<'a, S, CA>, +>; + +/// Native MASP VP +pub type MaspVp<'a, S, CA> = token::vp::MaspVp< + 'a, + S, + VpCache, + Eval, + ParamsPreStore<'a, S, CA>, + GovPreStore<'a, S, CA>, +>; + +/// Native ETH bridge VP +pub type EthBridgeVp<'a, S, CA> = + eth_bridge::vp::EthBridge<'a, S, VpCache, Eval, TokenKeys>; + +/// Native ETH bridge pool VP +pub type EthBridgePoolVp<'a, S, CA> = + eth_bridge::vp::BridgePool<'a, S, VpCache, Eval, TokenKeys>; + +/// Native ETH bridge NUT VP +pub type EthBridgeNutVp<'a, S, CA> = + eth_bridge::vp::NonUsableTokens<'a, S, VpCache, Eval, TokenKeys>; + +/// Governance store implementation over the native prior context +pub type GovPreStore<'a, S, CA> = + governance::Store, Eval>>; + +/// Parameters store implementation over the native prior context +pub type ParamsPreStore<'a, S, CA> = + parameters::Store, Eval>>; + +/// PoS store implementation over the native prior context +pub type PosPreStore<'a, S, CA> = proof_of_stake::Store< + CtxPreStorageRead<'a, 'a, S, VpCache, Eval>, +>; + +/// Token storage keys implementation +pub type TokenKeys = token::Store<()>; + +/// Parameters storage keys implementation +pub type ParamKeys = parameters::Store<()>;