diff --git a/Cargo.lock b/Cargo.lock index db0c69a73..c829b2038 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7764,6 +7764,7 @@ version = "0.1.0" dependencies = [ "bifrost-farming", "bifrost-farming-rpc-runtime-api", + "clients-info", "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", @@ -7773,8 +7774,10 @@ dependencies = [ "cumulus-primitives-core", "cumulus-primitives-timestamp", "cumulus-primitives-utility", + "currency", "dia-oracle", "dia-oracle-runtime-api", + "fee", "frame-benchmarking", "frame-executive", "frame-support", @@ -7783,9 +7786,16 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal", + "issue", "log", + "module-issue-rpc-runtime-api", "module-oracle-rpc-runtime-api", "module-pallet-staking-rpc-runtime-api", + "module-redeem-rpc-runtime-api", + "module-replace-rpc-runtime-api", + "module-vault-registry-rpc-runtime-api", + "nomination", + "oracle", "orml-asset-registry", "orml-currencies", "orml-currencies-allowance-extension", @@ -7822,8 +7832,13 @@ dependencies = [ "paste", "polkadot-parachain", "polkadot-runtime-common", + "pooled-rewards", + "redeem", + "replace", + "reward-distribution", "runtime-common", "scale-info", + "security", "serde", "smallvec", "sp-api", @@ -7839,7 +7854,10 @@ dependencies = [ "sp-transaction-pool", "sp-version", "spacewalk-primitives", + "staking", + "stellar-relay", "substrate-wasm-builder", + "vault-registry", "vesting-manager", "xcm", "xcm-builder", diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 96c671e86..b3d629874 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -331,6 +331,7 @@ pub fn pendulum_config() -> PendulumChainSpec { vesting_schedules.clone(), multisig_genesis.clone(), pendulum::PARACHAIN_ID.into(), + false, ) }, // Bootnodes @@ -412,6 +413,10 @@ pub fn development_config() -> DevelopmentChainSpec { ) } +fn default_pair(currency_id: CurrencyId) -> VaultCurrencyPair { + VaultCurrencyPair { collateral: currency_id, wrapped: MAINNET_USDC_CURRENCY_ID } +} + fn amplitude_genesis( invulnerables: Vec, signatories: Vec, @@ -420,10 +425,6 @@ fn amplitude_genesis( id: ParaId, start_shutdown: bool, ) -> amplitude_runtime::GenesisConfig { - fn default_pair(currency_id: CurrencyId) -> VaultCurrencyPair { - VaultCurrencyPair { collateral: currency_id, wrapped: MAINNET_USDC_CURRENCY_ID } - } - let mut balances: Vec<_> = signatories .iter() .cloned() @@ -852,6 +853,7 @@ fn pendulum_genesis( vesting_schedules: Vec<(AccountId, BlockNumber, BlockNumber, Balance)>, sudo_account: AccountId, id: ParaId, + start_shutdown: bool, ) -> pendulum_runtime::GenesisConfig { let mut genesis_issuance = pendulum::TOTAL_INITIAL_ISSUANCE; for balance in balances.clone() { @@ -921,6 +923,75 @@ fn pendulum_genesis( ..Default::default() }, vesting: pendulum_runtime::VestingConfig { vesting: vesting_schedules }, + issue: pendulum_runtime::IssueConfig { + issue_period: amplitude_runtime::DAYS, + issue_minimum_transfer_amount: 1000, + limit_volume_amount: None, + limit_volume_currency_id: XCM(0), + current_volume_amount: 0u32.into(), + interval_length: (60u32 * 60 * 24), + last_interval_index: 0u32, + }, + redeem: pendulum_runtime::RedeemConfig { + redeem_period: pendulum_runtime::DAYS, + redeem_minimum_transfer_amount: 1000, + limit_volume_amount: None, + limit_volume_currency_id: XCM(0), + current_volume_amount: 0u32.into(), + interval_length: (60u32 * 60 * 24), + last_interval_index: 0u32, + }, + replace: pendulum_runtime::ReplaceConfig { + replace_period: pendulum_runtime::DAYS, + replace_minimum_transfer_amount: 1000, + }, + security: pendulum_runtime::SecurityConfig { + initial_status: if start_shutdown { + pendulum_runtime::StatusCode::Shutdown + } else { + pendulum_runtime::StatusCode::Error + }, + }, + oracle: pendulum_runtime::OracleConfig { + max_delay: u32::MAX, + oracle_keys: vec![ + Key::ExchangeRate(CurrencyId::XCM(0)), + Key::ExchangeRate(MAINNET_USDC_CURRENCY_ID), + ], + }, + vault_registry: pendulum_runtime::VaultRegistryConfig { + minimum_collateral_vault: vec![(XCM(0), 0)], + punishment_delay: pendulum_runtime::DAYS, + secure_collateral_threshold: vec![( + default_pair(XCM(0)), + FixedU128::checked_from_rational(150, 100).unwrap(), + )], + /* 150% */ + premium_redeem_threshold: vec![( + default_pair(XCM(0)), + FixedU128::checked_from_rational(130, 100).unwrap(), + )], + /* 130% */ + liquidation_collateral_threshold: vec![( + default_pair(XCM(0)), + FixedU128::checked_from_rational(120, 100).unwrap(), + )], + /* 120% */ + system_collateral_ceiling: vec![( + default_pair(XCM(0)), + 60_000 * 10u128.pow(pendulum::TOKEN_DECIMALS), + )], + }, + stellar_relay: pendulum_runtime::StellarRelayConfig::default(), + fee: pendulum_runtime::FeeConfig { + issue_fee: FixedU128::checked_from_rational(15, 10000).unwrap(), // 0.15% + issue_griefing_collateral: FixedU128::checked_from_rational(5, 100000).unwrap(), // 0.005% + redeem_fee: FixedU128::checked_from_rational(5, 1000).unwrap(), // 0.5% + premium_redeem_fee: FixedU128::checked_from_rational(5, 100).unwrap(), // 5% + punishment_fee: FixedU128::checked_from_rational(1, 10).unwrap(), // 10% + replace_griefing_collateral: FixedU128::checked_from_rational(1, 10).unwrap(), // 10% + }, + nomination: pendulum_runtime::NominationConfig { is_nomination_enabled: false }, } } diff --git a/node/src/rpc.rs b/node/src/rpc.rs index 3316ab826..1af41d0fd 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -52,6 +52,11 @@ where module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?; module.merge(Staking::new(client.clone()).into_rpc())?; module.merge(TransactionPayment::new(client.clone()).into_rpc())?; + module.merge(Issue::new(client.clone()).into_rpc())?; + module.merge(Redeem::new(client.clone()).into_rpc())?; + module.merge(Replace::new(client.clone()).into_rpc())?; + module.merge(VaultRegistry::new(client.clone()).into_rpc())?; + module.merge(Oracle::new(client.clone()).into_rpc())?; module.merge(FarmingRpc::new(client.clone()).into_rpc())?; module.merge(ZenlinkProtocol::new(client).into_rpc())?; Ok(module) diff --git a/runtime/pendulum/Cargo.toml b/runtime/pendulum/Cargo.toml index 2523cea68..a94628e13 100644 --- a/runtime/pendulum/Cargo.toml +++ b/runtime/pendulum/Cargo.toml @@ -26,8 +26,28 @@ smallvec = "1.9.0" # Local runtime-common = {path = "../common", default-features = false} -# Spacewalk libraries -spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8"} +# Custom libraries for Spacewalk +clients-info = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +currency = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +security = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +staking = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +oracle = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +stellar-relay = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +fee = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +vault-registry = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +redeem = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +issue = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +nomination = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +replace = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +spacewalk-primitives = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +module-issue-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +module-oracle-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +module-redeem-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +module-replace-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +module-vault-registry-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8" } +module-pallet-staking-rpc-runtime-api = { path = "../../pallets/parachain-staking/rpc/runtime-api", default-features = false } +pooled-rewards = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8"} +reward-distribution = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8"} # Substrate frame-benchmarking = {git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.40"} @@ -37,8 +57,6 @@ frame-system = {git = "https://github.com/paritytech/substrate", default-feature frame-system-benchmarking = {git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.40"} frame-system-rpc-runtime-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40"} frame-try-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.40"} -module-oracle-rpc-runtime-api = { git = "https://github.com/pendulum-chain/spacewalk", default-features = false, rev = "22c52abbecda0c1cdaa4187678fe7bcc2d6868c8"} -module-pallet-staking-rpc-runtime-api = { path = "../../pallets/parachain-staking/rpc/runtime-api", default-features = false } pallet-aura = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40"} pallet-authorship = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40"} pallet-balances = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40"} @@ -178,7 +196,6 @@ std = [ "pallet-vesting/std", "pallet-xcm/std", "parachain-info/std", - "parachain-staking/std", "polkadot-parachain/std", "polkadot-runtime-common/std", "runtime-common/std", @@ -194,7 +211,6 @@ std = [ "sp-std/std", "sp-transaction-pool/std", "sp-version/std", - "vesting-manager/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", @@ -202,7 +218,31 @@ std = [ "zenlink-protocol-runtime-api/std", "bifrost-farming/std", "bifrost-farming-rpc-runtime-api/std", - "orml-currencies-allowance-extension/std" + + #custom libraries from spacewalk + "security/std", + "staking/std", + "oracle/std", + "stellar-relay/std", + "fee/std", + "vault-registry/std", + "redeem/std", + "issue/std", + "currency/std", + "nomination/std", + "replace/std", + "module-issue-rpc-runtime-api/std", + "module-oracle-rpc-runtime-api/std", + "module-redeem-rpc-runtime-api/std", + "module-replace-rpc-runtime-api/std", + "module-pallet-staking-rpc-runtime-api/std", + "module-vault-registry-rpc-runtime-api/std", + "spacewalk-primitives/std", + + # custom libraries from pendulum + "orml-currencies-allowance-extension/std", + "parachain-staking/std", + "vesting-manager/std", ] runtime-benchmarks = [ @@ -213,6 +253,16 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", + + "fee/runtime-benchmarks", + "issue/runtime-benchmarks", + "nomination/runtime-benchmarks", + "oracle/runtime-benchmarks", + "redeem/runtime-benchmarks", + "replace/runtime-benchmarks", + "stellar-relay/runtime-benchmarks", + "vault-registry/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", @@ -221,55 +271,69 @@ runtime-benchmarks = [ "pallet-collective/runtime-benchmarks", "runtime-common/runtime-benchmarks", - "orml-currencies-allowance-extension/runtime-benchmarks" + "orml-currencies-allowance-extension/runtime-benchmarks" ] try-runtime = [ - "frame-executive/try-runtime", - "frame-try-runtime", - "frame-system/try-runtime", - "parachain-info/try-runtime", - "pallet-timestamp/try-runtime", - "pallet-aura/try-runtime", - "pallet-authorship/try-runtime", - "pallet-balances/try-runtime", - "pallet-bounties/try-runtime", - "pallet-child-bounties/try-runtime", - "pallet-collective/try-runtime", - "pallet-contracts/try-runtime", - "pallet-democracy/try-runtime", - "pallet-identity/try-runtime", - "pallet-multisig/try-runtime", - "pallet-proxy/try-runtime", - "pallet-preimage/try-runtime", - "pallet-insecure-randomness-collective-flip/try-runtime", - "pallet-scheduler/try-runtime", - "pallet-session/try-runtime", - "pallet-transaction-payment/try-runtime", - "pallet-treasury/try-runtime", - "pallet-utility/try-runtime", - "pallet-vesting/try-runtime", - "pallet-xcm/try-runtime", + "frame-executive/try-runtime", + "frame-try-runtime", + "frame-system/try-runtime", + "parachain-info/try-runtime", + "pallet-timestamp/try-runtime", + "pallet-aura/try-runtime", + "pallet-authorship/try-runtime", + "pallet-balances/try-runtime", + "pallet-bounties/try-runtime", + "pallet-child-bounties/try-runtime", + "pallet-collective/try-runtime", + "pallet-contracts/try-runtime", + "pallet-democracy/try-runtime", + "pallet-identity/try-runtime", + "pallet-multisig/try-runtime", + "pallet-preimage/try-runtime", + "pallet-proxy/try-runtime", + "pallet-insecure-randomness-collective-flip/try-runtime", + "pallet-scheduler/try-runtime", + "pallet-session/try-runtime", + "pallet-transaction-payment/try-runtime", + "pallet-treasury/try-runtime", + "pallet-utility/try-runtime", + "pallet-vesting/try-runtime", + "pallet-xcm/try-runtime", + + "parachain-staking/try-runtime", - "cumulus-pallet-aura-ext/try-runtime", - "cumulus-pallet-dmp-queue/try-runtime", - "cumulus-pallet-parachain-system/try-runtime", - "cumulus-pallet-xcm/try-runtime", - "cumulus-pallet-xcmp-queue/try-runtime", + "cumulus-pallet-aura-ext/try-runtime", + "cumulus-pallet-dmp-queue/try-runtime", + "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-xcm/try-runtime", + "cumulus-pallet-xcmp-queue/try-runtime", - "orml-asset-registry/try-runtime", - "orml-currencies/try-runtime", - "orml-tokens/try-runtime", - "orml-xtokens/try-runtime", + "orml-asset-registry/try-runtime", + "orml-currencies/try-runtime", + "orml-tokens/try-runtime", + "orml-xtokens/try-runtime", - "dia-oracle/try-runtime", - "orml-currencies-allowance-extension/try-runtime", + "stellar-relay/try-runtime", + "issue/try-runtime", + "currency/try-runtime", + "security/try-runtime", + "staking/try-runtime", + "oracle/try-runtime", + "fee/try-runtime", + "vault-registry/try-runtime", + "redeem/try-runtime", + "nomination/try-runtime", + "replace/try-runtime", + "pooled-rewards/try-runtime", + "clients-info/try-runtime", + "reward-distribution/try-runtime", - "vesting-manager/try-runtime", + "dia-oracle/try-runtime", + "orml-currencies-allowance-extension/try-runtime", + "vesting-manager/try-runtime", + + "bifrost-farming/try-runtime", - "bifrost-farming/try-runtime", - - "zenlink-protocol/try-runtime", - - "parachain-staking/try-runtime", -] + "zenlink-protocol/try-runtime", +] \ No newline at end of file diff --git a/runtime/pendulum/src/lib.rs b/runtime/pendulum/src/lib.rs index eb3e8171d..625063a4e 100644 --- a/runtime/pendulum/src/lib.rs +++ b/runtime/pendulum/src/lib.rs @@ -23,18 +23,28 @@ use scale_info::TypeInfo; use smallvec::smallvec; use sp_api::impl_runtime_apis; -use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; +use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, - traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, ConvertInto}, + traits::{ + AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, Convert, ConvertInto, + }, transaction_validity::{TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, SaturatedConversion, + ApplyExtrinsicResult, DispatchError, FixedPointNumber, MultiAddress, Perbill, Permill, + Perquintill, SaturatedConversion, }; use bifrost_farming as farming; use bifrost_farming_rpc_runtime_api as farming_rpc_runtime_api; pub use spacewalk_primitives::CurrencyId; +use spacewalk_primitives::{ + self as primitives, CurrencyId::XCM, Moment, SignedFixedPoint, SignedInner, UnsignedFixedPoint, + UnsignedInner, +}; + +#[cfg(any(feature = "runtime-benchmarks", feature = "testing-utils"))] +use oracle::testing_utils::MockDataFeeder; use sp_std::{marker::PhantomData, prelude::*}; #[cfg(feature = "std")] @@ -46,8 +56,8 @@ use frame_support::{ dispatch::DispatchClass, parameter_types, traits::{ - ConstBool, ConstU32, Contains, Currency, EitherOfDiverse, EqualPrivilegeOnly, Imbalance, - InstanceFilter, OnUnbalanced, WithdrawReasons, + ConstBool, ConstU32, Contains, Currency as FrameCurrency, EitherOfDiverse, + EqualPrivilegeOnly, Imbalance, InstanceFilter, OnUnbalanced, WithdrawReasons, }, weights::{ constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient, @@ -59,7 +69,6 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureSigned, }; -pub use sp_runtime::{traits::AccountIdConversion, MultiAddress, Perbill, Permill, Perquintill}; use runtime_common::{ asset_registry, opaque, AccountId, Amount, AuraId, Balance, BlockNumber, Hash, Index, PoolId, @@ -69,6 +78,16 @@ use runtime_common::{ use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use dia_oracle::DiaOracle; +pub use issue::{Event as IssueEvent, IssueRequest}; +pub use nomination::Event as NominationEvent; +use oracle::{ + dia, + dia::{DiaOracleAdapter, NativeCurrencyKey, XCMCurrencyConversion}, +}; +pub use redeem::{Event as RedeemEvent, RedeemRequest}; +pub use replace::{Event as ReplaceEvent, ReplaceRequest}; +pub use security::StatusCode; +pub use stellar_relay::traits::{FieldLength, Organization, Validator}; use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin}; @@ -89,6 +108,9 @@ use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; use crate::chain_ext::Psp22Extension; use xcm_executor::XcmExecutor; +/// Spacewalk vault id type +pub type VaultId = primitives::VaultId; + /// The address format for describing accounts. pub type Address = MultiAddress; @@ -134,6 +156,60 @@ pub type Executive = frame_executive::Executive< AllPalletsWithSystem, >; +pub struct PendulumDiaOracleKeyConverter; + +impl NativeCurrencyKey for PendulumDiaOracleKeyConverter { + fn native_symbol() -> Vec { + b"PEN".to_vec() + } + + fn native_chain() -> Vec { + b"Pendulum".to_vec() + } +} + +impl XCMCurrencyConversion for PendulumDiaOracleKeyConverter { + fn convert_to_dia_currency_id(token_symbol: u8) -> Option<(Vec, Vec)> { + match token_symbol { + 0 => Some((b"Polkadot".to_vec(), b"DOT".to_vec())), + _ => None, + } + } + + fn convert_from_dia_currency_id(blockchain: Vec, symbol: Vec) -> Option { + match (blockchain.as_slice(), symbol.as_slice()) { + (b"Polkadot", b"DOT") => Some(0), + _ => None, + } + } +} + +type DataProviderImpl = DiaOracleAdapter< + DiaOracleModule, + UnsignedFixedPoint, + Moment, + dia::DiaOracleKeyConvertor, + ConvertPrice, + ConvertMoment, +>; + +pub struct ConvertPrice; + +impl Convert> for ConvertPrice { + fn convert(price: u128) -> Option { + Some(UnsignedFixedPoint::from_inner(price)) + } +} + +pub struct ConvertMoment; + +impl Convert> for ConvertMoment { + fn convert(moment: u64) -> Option { + // The provided moment is in seconds, but we need milliseconds + Some(moment.saturating_mul(1000)) + } +} + /// Handles converting a weight scalar to a fee value, based on the scale and granularity of the /// node's balance type. /// @@ -251,6 +327,7 @@ impl Contains for BaseFilter { // These modules are all allowed to be called by transactions: RuntimeCall::Bounties(_) | RuntimeCall::ChildBounties(_) | + RuntimeCall::ClientsInfo(_) | RuntimeCall::Treasury(_) | RuntimeCall::Tokens(_) | RuntimeCall::Currencies(_) | @@ -279,6 +356,17 @@ impl Contains for BaseFilter { RuntimeCall::VestingManager(_) | RuntimeCall::TokenAllowance(_) | RuntimeCall::AssetRegistry(_) | + RuntimeCall::Fee(_) | + RuntimeCall::Issue(_) | + RuntimeCall::Nomination(_) | + RuntimeCall::Oracle(_) | + RuntimeCall::Redeem(_) | + RuntimeCall::Replace(_) | + RuntimeCall::Security(_) | + RuntimeCall::StellarRelay(_) | + RuntimeCall::VaultRegistry(_) | + RuntimeCall::PooledVaultRewards(_) | + RuntimeCall::RewardDistribution(_) | RuntimeCall::Farming(_) | RuntimeCall::Proxy(_) => true, // All pallets are allowed, but exhaustive match is defensive @@ -385,7 +473,7 @@ parameter_types! { pub const OperationalFeeMultiplier: u8 = 5; } -type NegativeImbalance = >::NegativeImbalance; +type NegativeImbalance = >::NegativeImbalance; pub struct DealWithFees; impl OnUnbalanced for DealWithFees { @@ -989,6 +1077,183 @@ where } } +pub struct CurrencyConvert; + +impl currency::CurrencyConversion, CurrencyId> for CurrencyConvert { + fn convert( + amount: ¤cy::Amount, + to: CurrencyId, + ) -> Result, DispatchError> { + Oracle::convert(amount, to) + } +} +parameter_types! { + pub const RelayChainCurrencyId: CurrencyId = XCM(0); // 0 is the index of the relay chain in our XCM mapping +} +impl currency::Config for Runtime { + type UnsignedFixedPoint = UnsignedFixedPoint; + type SignedInner = SignedInner; + type SignedFixedPoint = SignedFixedPoint; + type Balance = Balance; + type GetRelayChainCurrencyId = RelayChainCurrencyId; + type AssetConversion = primitives::AssetConversion; + type BalanceConversion = primitives::BalanceConversion; + type CurrencyConversion = CurrencyConvert; + type AmountCompatibility = primitives::StellarCompatibility; +} + +impl security::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = security::SubstrateWeight; +} + +parameter_types! { + pub const MaxRewardCurrencies: u32= 10; +} + +impl staking::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SignedInner = SignedInner; + type SignedFixedPoint = SignedFixedPoint; + type GetNativeCurrencyId = NativeCurrencyId; + type CurrencyId = CurrencyId; + type MaxRewardCurrencies = MaxRewardCurrencies; +} + +#[cfg(feature = "runtime-benchmarks")] +pub struct DataFeederBenchmark(PhantomData<(K, V, A)>); + +#[cfg(feature = "runtime-benchmarks")] +impl orml_traits::DataFeeder for DataFeederBenchmark { + fn feed_value(_who: A, _key: K, _value: V) -> sp_runtime::DispatchResult { + Ok(()) + } +} + +#[cfg(feature = "runtime-benchmarks")] +impl orml_traits::DataProvider for DataFeederBenchmark { + fn get(_key: &K) -> Option { + None + } +} + +impl oracle::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = oracle::SubstrateWeight; + type DataProvider = DataProviderImpl; + #[cfg(feature = "runtime-benchmarks")] + type DataFeeder = MockDataFeeder; +} + +parameter_types! { + pub const OrganizationLimit: u32 = 255; + pub const ValidatorLimit: u32 = 255; + pub const IsPublicNetwork: bool = true; +} + +impl stellar_relay::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type OrganizationId = u128; + type OrganizationLimit = OrganizationLimit; + type ValidatorLimit = ValidatorLimit; + type IsPublicNetwork = IsPublicNetwork; + type WeightInfo = stellar_relay::SubstrateWeight; +} + +parameter_types! { + pub const FeePalletId: PalletId = PalletId(*b"mod/fees"); + pub const VaultRegistryPalletId: PalletId = PalletId(*b"mod/vreg"); + pub const MaxExpectedValue: UnsignedFixedPoint = UnsignedFixedPoint::from_inner(::DIV); + pub FeeAccount: AccountId = FeePalletId::get().into_account_truncating(); +} +impl fee::Config for Runtime { + type FeePalletId = FeePalletId; + type WeightInfo = fee::SubstrateWeight; + type SignedFixedPoint = SignedFixedPoint; + type SignedInner = SignedInner; + type UnsignedFixedPoint = UnsignedFixedPoint; + type UnsignedInner = UnsignedInner; + type VaultRewards = PooledVaultRewards; + type VaultStaking = VaultStaking; + type OnSweep = currency::SweepFunds; + type MaxExpectedValue = MaxExpectedValue; + type RewardDistribution = RewardDistribution; +} + +impl vault_registry::Config for Runtime { + type PalletId = VaultRegistryPalletId; + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type WeightInfo = vault_registry::SubstrateWeight; + type GetGriefingCollateralCurrencyId = NativeCurrencyId; +} + +impl redeem::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = redeem::SubstrateWeight; +} + +pub struct BlockNumberToBalance; + +impl sp_runtime::traits::Convert for BlockNumberToBalance { + fn convert(a: BlockNumber) -> Balance { + a.into() + } +} + +impl issue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type BlockNumberToBalance = BlockNumberToBalance; + type WeightInfo = issue::SubstrateWeight; +} + +impl nomination::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = nomination::SubstrateWeight; +} + +impl replace::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = replace::SubstrateWeight; +} + +impl clients_info::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = clients_info::SubstrateWeight; + type MaxNameLength = ConstU32<255>; + type MaxUriLength = ConstU32<255>; +} +// Choice of parameters: Perquintill::from_parts(36600800000000000u64) represents a value of +// 0.0366008 = 36600800000000000 / 1×10¹⁸ +// The decay interval 216000 equates to a month when considering 1 block every 12 seconds +parameter_types! { + pub const DecayRate: Perquintill = Perquintill::from_parts(36600800000000000); + pub const MaxCurrencies: u32 = 10; +} + +impl reward_distribution::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = reward_distribution::SubstrateWeight; + type Balance = Balance; + type DecayInterval = ConstU32<216_000>; + type DecayRate = DecayRate; + type VaultRewards = PooledVaultRewards; + type MaxCurrencies = MaxCurrencies; + type OracleApi = Oracle; + type Balances = Balances; + type VaultStaking = VaultStaking; + type FeePalletId = FeePalletId; +} + +impl pooled_rewards::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SignedFixedPoint = SignedFixedPoint; + type PoolId = CurrencyId; + type PoolRewardsCurrencyId = CurrencyId; + type StakeId = VaultId; + type MaxRewardCurrencies = MaxRewardCurrencies; +} + impl InstanceFilter for ProxyType { fn filter(&self, c: &RuntimeCall) -> bool { match self { @@ -1100,17 +1365,32 @@ construct_runtime!( RandomnessCollectiveFlip: pallet_insecure_randomness_collective_flip::{Pallet, Storage} = 57, DiaOracleModule: dia_oracle::{Pallet, Storage, Call, Event} = 58, - TokenAllowance: orml_currencies_allowance_extension::{Pallet, Storage, Call, Event} = 80, - + // Zenlink ZenlinkProtocol: zenlink_protocol::{Pallet, Call, Storage, Event} = 59, + // Spacewalk pallets + Currency: currency::{Pallet} = 60, + Fee: fee::{Pallet, Call, Config, Storage} = 61, + Issue: issue::{Pallet, Call, Config, Storage, Event} = 62, + Nomination: nomination::{Pallet, Call, Config, Storage, Event} = 63, + Oracle: oracle::{Pallet, Call, Config, Storage, Event} = 64, + Redeem: redeem::{Pallet, Call, Config, Storage, Event} = 65, + Replace: replace::{Pallet, Call, Config, Storage, Event} = 66, + Security: security::{Pallet, Call, Config, Storage, Event} = 67, + StellarRelay: stellar_relay::{Pallet, Call, Config, Storage, Event} = 68, + VaultRegistry: vault_registry::{Pallet, Call, Config, Storage, Event, ValidateUnsigned} = 69, + PooledVaultRewards: pooled_rewards::{Pallet, Call, Storage, Event} = 70, + VaultStaking: staking::{Pallet, Storage, Event} = 71, + ClientsInfo: clients_info::{Pallet, Call, Storage, Event} = 72, + RewardDistribution: reward_distribution::{Pallet, Call, Storage, Event} = 73, + + TokenAllowance: orml_currencies_allowance_extension::{Pallet, Storage, Call, Event} = 80, + //Farming Farming: farming::{Pallet, Call, Storage, Event} = 90, // Asset Metadata AssetRegistry: orml_asset_registry::{Pallet, Storage, Call, Event, Config} = 91, - - VestingManager: vesting_manager::{Pallet, Call, Event} = 100 } ); @@ -1419,6 +1699,98 @@ impl_runtime_apis! { } } + impl module_issue_rpc_runtime_api::IssueApi< + Block, + AccountId, + H256, + IssueRequest + > for Runtime { + fn get_issue_requests(account_id: AccountId) -> Vec { + Issue::get_issue_requests_for_account(account_id) + } + fn get_vault_issue_requests(vault_id: AccountId) -> Vec { + Issue::get_issue_requests_for_vault(vault_id) + } + } + impl module_vault_registry_rpc_runtime_api::VaultRegistryApi< + Block, + VaultId, + Balance, + UnsignedFixedPoint, + CurrencyId, + AccountId, + > for Runtime { + fn get_vault_collateral(vault_id: VaultId) -> Result, DispatchError> { + let result = VaultRegistry::compute_collateral(&vault_id)?; + Ok(BalanceWrapper{amount:result.amount()}) + } + fn get_vaults_by_account_id(account_id: AccountId) -> Result, DispatchError> { + VaultRegistry::get_vaults_by_account_id(account_id) + } + fn get_vault_total_collateral(vault_id: VaultId) -> Result, DispatchError> { + let result = VaultRegistry::get_backing_collateral(&vault_id)?; + Ok(BalanceWrapper{amount:result.amount()}) + } + fn get_premium_redeem_vaults() -> Result)>, DispatchError> { + let result = VaultRegistry::get_premium_redeem_vaults()?; + Ok(result.iter().map(|v| (v.0.clone(), BalanceWrapper{amount:v.1.amount()})).collect()) + } + fn get_vaults_with_issuable_tokens() -> Result)>, DispatchError> { + let result = VaultRegistry::get_vaults_with_issuable_tokens()?; + Ok(result.into_iter().map(|v| (v.0, BalanceWrapper{amount:v.1.amount()})).collect()) + } + fn get_vaults_with_redeemable_tokens() -> Result)>, DispatchError> { + let result = VaultRegistry::get_vaults_with_redeemable_tokens()?; + Ok(result.into_iter().map(|v| (v.0, BalanceWrapper{amount:v.1.amount()})).collect()) + } + fn get_issuable_tokens_from_vault(vault: VaultId) -> Result, DispatchError> { + let result = VaultRegistry::get_issuable_tokens_from_vault(&vault)?; + Ok(BalanceWrapper{amount:result.amount()}) + } + fn get_collateralization_from_vault(vault: VaultId, only_issued: bool) -> Result { + VaultRegistry::get_collateralization_from_vault(vault, only_issued) + } + fn get_collateralization_from_vault_and_collateral(vault: VaultId, collateral: BalanceWrapper, only_issued: bool) -> Result { + let amount = currency::Amount::new(collateral.amount, vault.collateral_currency()); + VaultRegistry::get_collateralization_from_vault_and_collateral(vault, &amount, only_issued) + } + fn get_required_collateral_for_wrapped(amount_wrapped: BalanceWrapper, wrapped_currency_id: CurrencyId, collateral_currency_id: CurrencyId) -> Result, DispatchError> { + let amount_wrapped = currency::Amount::new(amount_wrapped.amount, wrapped_currency_id); + let result = VaultRegistry::get_required_collateral_for_wrapped(&amount_wrapped, collateral_currency_id)?; + Ok(BalanceWrapper{amount:result.amount()}) + } + fn get_required_collateral_for_vault(vault_id: VaultId) -> Result, DispatchError> { + let result = VaultRegistry::get_required_collateral_for_vault(vault_id)?; + Ok(BalanceWrapper{amount:result.amount()}) + } + } + impl module_redeem_rpc_runtime_api::RedeemApi< + Block, + AccountId, + H256, + RedeemRequest + > for Runtime { + fn get_redeem_requests(account_id: AccountId) -> Vec { + Redeem::get_redeem_requests_for_account(account_id) + } + fn get_vault_redeem_requests(vault_account_id: AccountId) -> Vec { + Redeem::get_redeem_requests_for_vault(vault_account_id) + } + } + impl module_replace_rpc_runtime_api::ReplaceApi< + Block, + AccountId, + H256, + ReplaceRequest + > for Runtime { + fn get_old_vault_replace_requests(vault_id: AccountId) -> Vec { + Replace::get_replace_requests_for_old_vault(vault_id) + } + fn get_new_vault_replace_requests(vault_id: AccountId) -> Vec { + Replace::get_replace_requests_for_new_vault(vault_id) + } + } + impl pallet_contracts::ContractsApi for Runtime { @@ -1484,6 +1856,23 @@ impl_runtime_apis! { } } + impl module_oracle_rpc_runtime_api::OracleApi for Runtime { + fn currency_to_usd(amount:BalanceWrapper, currency_id: CurrencyId) -> Result, DispatchError> { + let result = Oracle::currency_to_usd(amount.amount, currency_id)?; + Ok(BalanceWrapper{amount:result}) + } + + fn usd_to_currency(amount:BalanceWrapper, currency_id: CurrencyId) -> Result, DispatchError> { + let result = Oracle::usd_to_currency(amount.amount, currency_id)?; + Ok(BalanceWrapper{amount:result}) + } + + fn get_exchange_rate(currency_id: CurrencyId) -> Result { + let result = Oracle::get_exchange_rate(currency_id)?; + Ok(result) + } + } + } struct CheckInherents;