Skip to content
This repository was archived by the owner on Apr 25, 2026. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions node/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,19 @@ where
SC: SelectChain<Block> + 'static,
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::BlakeTwo256>,
C::Api: pallet_services_rpc::ServicesRuntimeApi<
Block,
PalletServicesConstraints,
AccountId,
AssetId,
>,
C::Api: pallet_rewards_rpc::RewardsRuntimeApi<Block, AccountId, AssetId, Balance>,
C::Api: pallet_credits_rpc::CreditsRuntimeApi<Block, AccountId, Balance, AssetId>,
CIDP: sp_inherents::CreateInherentDataProviders<Block, ()> + Send + Sync + 'static,
{
use pallet_credits_rpc::{CreditsApiServer, CreditsClient};
use pallet_rewards_rpc::{RewardsApiServer, RewardsClient};
use pallet_services_rpc::{ServicesApiServer, ServicesClient};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use sc_consensus_babe_rpc::{Babe, BabeApiServer};
use sc_consensus_grandpa_rpc::{Grandpa, GrandpaApiServer};
Expand Down Expand Up @@ -268,6 +279,9 @@ where

io.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
io.merge(TransactionPayment::new(client.clone()).into_rpc())?;
io.merge(ServicesClient::new(client.clone()).into_rpc())?;
io.merge(RewardsClient::new(client.clone()).into_rpc())?;
io.merge(CreditsClient::new(client.clone()).into_rpc())?;
//io.merge(IsmpRpcHandler::new(client.clone(), backend)?.into_rpc())?;

io.merge(
Expand Down
53 changes: 53 additions & 0 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,59 @@ pub mod credits {
pub const CLAIM_WINDOW_BLOCKS: u64 = DAYS * 7;
}

pub mod multi_asset_delegation {
use crate::types::Balance;
use frame_support::PalletId;

/// Minimum amount required to become an operator
pub const MIN_OPERATOR_BOND_AMOUNT: Balance = 100;

/// Minimum amount required to delegate
pub const MIN_DELEGATE_AMOUNT: Balance = 1;

/// Pallet ID for multi-asset-delegation
pub const PALLET_ID: PalletId = PalletId(*b"PotStake");

/// Maximum number of blueprints a delegator can have
pub const MAX_DELEGATOR_BLUEPRINTS: u32 = 50;

/// Maximum number of blueprints an operator can have
pub const MAX_OPERATOR_BLUEPRINTS: u32 = 50;

/// Maximum number of pending withdraw requests
pub const MAX_WITHDRAW_REQUESTS: u32 = 5;

/// Maximum number of pending unstake requests
pub const MAX_UNSTAKE_REQUESTS: u32 = 5;

/// Maximum number of delegations per delegator
pub const MAX_DELEGATIONS: u32 = 50;

/// Leave operators delay for fast runtime
pub const LEAVE_OPERATORS_DELAY_FAST: u32 = 1;

/// Leave delegators delay for fast runtime
pub const LEAVE_DELEGATORS_DELAY_FAST: u32 = 1;

/// Delegation bond less delay for fast runtime
pub const DELEGATION_BOND_LESS_DELAY_FAST: u32 = 1;

/// Operator bond less delay for fast runtime
pub const OPERATOR_BOND_LESS_DELAY_FAST: u32 = 1;

/// Leave operators delay for normal runtime
pub const LEAVE_OPERATORS_DELAY: u32 = 10;

/// Leave delegators delay for normal runtime
pub const LEAVE_DELEGATORS_DELAY: u32 = 10;

/// Delegation bond less delay for normal runtime
pub const DELEGATION_BOND_LESS_DELAY: u32 = 5;

/// Operator bond less delay for normal runtime
pub const OPERATOR_BOND_LESS_DELAY: u32 = 5;
}

/// We assume that ~10% of the block weight is consumed by `on_initialize` handlers. This is
/// used to limit the maximal weight of a single extrinsic.
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
Expand Down
51 changes: 51 additions & 0 deletions primitives/src/types/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,57 @@ use scale_info::TypeInfo;
use services::AssetIdT;
use sp_std::vec::Vec;

// Rewards Pallet Constants
use crate::{currency::UNIT, types::Balance};
use frame_support::PalletId;
use sp_runtime::Perbill;

/// Pallet ID for rewards
pub const PALLET_ID: PalletId = PalletId(*b"py/tnrew");

/// Minimum deposit cap (same for both mainnet and testnet)
pub const MIN_DEPOSIT_CAP: Balance = 0;

/// Minimum incentive cap (same for both mainnet and testnet)
pub const MIN_INCENTIVE_CAP: Balance = 0;

/// Maximum vault name length
pub const MAX_VAULT_NAME_LENGTH: u32 = 64;

/// Maximum vault logo length
pub const MAX_VAULT_LOGO_LENGTH: u32 = 256;

/// Maximum pending rewards per operator
pub const MAX_PENDING_REWARDS_PER_OPERATOR: u32 = 100;

/// Mainnet-specific constants
pub mod mainnet {
use super::*;

/// Maximum deposit cap for mainnet
pub const MAX_DEPOSIT_CAP: Balance = UNIT * 100_000_000;

/// Maximum incentive cap for mainnet
pub const MAX_INCENTIVE_CAP: Balance = UNIT * 100_000_000;

/// Maximum APY for mainnet (2%)
pub const MAX_APY: Perbill = Perbill::from_percent(2);
}

/// Testnet-specific constants
pub mod testnet {
use super::*;

/// Maximum deposit cap for testnet
pub const MAX_DEPOSIT_CAP: Balance = UNIT * 1_000_000_000_000;

/// Maximum incentive cap for testnet
pub const MAX_INCENTIVE_CAP: Balance = UNIT * 1_000_000_000_000;

/// Maximum APY for testnet (20%)
pub const MAX_APY: Perbill = Perbill::from_percent(20);
}

#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq, Eq)]
pub enum AssetType<AssetId> {
/// This includes all lstTNT assets
Expand Down
80 changes: 54 additions & 26 deletions runtime/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1273,14 +1273,14 @@ impl pallet_tangle_lst::Config for Runtime {
}

parameter_types! {
pub const RewardsPID: PalletId = PalletId(*b"py/tnrew");
pub const MaxDepositCap: u128 = UNIT * 100_000_000;
pub const MaxIncentiveCap: u128 = UNIT * 100_000_000;
pub const MaxApy: Perbill = Perbill::from_percent(2);
pub const MinDepositCap: u128 = 0;
pub const MinIncentiveCap: u128 = 0;
pub const MaxVaultNameLen: u32 = 64;
pub const MaxVaultLogoLen: u32 = 256;
pub const RewardsPID: PalletId = tangle_primitives::types::rewards::PALLET_ID;
pub const MaxDepositCap: Balance = tangle_primitives::types::rewards::mainnet::MAX_DEPOSIT_CAP;
pub const MaxIncentiveCap: Balance = tangle_primitives::types::rewards::mainnet::MAX_INCENTIVE_CAP;
pub const MaxApy: Perbill = tangle_primitives::types::rewards::mainnet::MAX_APY;
pub const MinDepositCap: Balance = tangle_primitives::types::rewards::MIN_DEPOSIT_CAP;
pub const MinIncentiveCap: Balance = tangle_primitives::types::rewards::MIN_INCENTIVE_CAP;
pub const MaxVaultNameLen: u32 = tangle_primitives::types::rewards::MAX_VAULT_NAME_LENGTH;
pub const MaxVaultLogoLen: u32 = tangle_primitives::types::rewards::MAX_VAULT_LOGO_LENGTH;
}

impl pallet_rewards::Config for Runtime {
Expand All @@ -1299,56 +1299,60 @@ impl pallet_rewards::Config for Runtime {
type MaxVaultNameLength = MaxVaultNameLen;
type MaxVaultLogoLength = MaxVaultLogoLen;
type VaultMetadataOrigin = EnsureRootOrHalfCouncil;
type MaxPendingRewardsPerOperator = ConstU32<100>;
type MaxPendingRewardsPerOperator =
ConstU32<{ tangle_primitives::types::rewards::MAX_PENDING_REWARDS_PER_OPERATOR }>;
type WeightInfo = ();
}

parameter_types! {
pub const MinOperatorBondAmount: Balance = 100;
pub const MinOperatorBondAmount: Balance = tangle_primitives::multi_asset_delegation::MIN_OPERATOR_BOND_AMOUNT;
pub const MinDelegateAmount: Balance = tangle_primitives::multi_asset_delegation::MIN_DELEGATE_AMOUNT;
pub PID: PalletId = tangle_primitives::multi_asset_delegation::PALLET_ID;

pub const MinDelegateAmount : Balance = 1;
pub PID: PalletId = PalletId(*b"PotStake");
#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const MaxDelegatorBlueprints : u32 = 50;
#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const MaxOperatorBlueprints : u32 = 50;
pub const MaxDelegatorBlueprints: u32 = tangle_primitives::multi_asset_delegation::MAX_DELEGATOR_BLUEPRINTS;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const MaxWithdrawRequests: u32 = 5;
pub const MaxOperatorBlueprints: u32 = tangle_primitives::multi_asset_delegation::MAX_OPERATOR_BLUEPRINTS;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const MaxUnstakeRequests: u32 = 5;
pub const MaxWithdrawRequests: u32 = tangle_primitives::multi_asset_delegation::MAX_WITHDRAW_REQUESTS;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const MaxDelegations: u32 = 50;
pub const MaxUnstakeRequests: u32 = tangle_primitives::multi_asset_delegation::MAX_UNSTAKE_REQUESTS;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const MaxDelegations: u32 = tangle_primitives::multi_asset_delegation::MAX_DELEGATIONS;
}

#[cfg(feature = "fast-runtime")]
parameter_types! {
#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const LeaveOperatorsDelay: u32 = 1;
pub const LeaveOperatorsDelay: u32 = tangle_primitives::multi_asset_delegation::LEAVE_OPERATORS_DELAY_FAST;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const LeaveDelegatorsDelay: u32 = 1;
pub const LeaveDelegatorsDelay: u32 = tangle_primitives::multi_asset_delegation::LEAVE_DELEGATORS_DELAY_FAST;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const DelegationBondLessDelay: u32 = 1;
pub const DelegationBondLessDelay: u32 = tangle_primitives::multi_asset_delegation::DELEGATION_BOND_LESS_DELAY_FAST;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const OperatorBondLessDelay: u32 = 1;
pub const OperatorBondLessDelay: u32 = tangle_primitives::multi_asset_delegation::OPERATOR_BOND_LESS_DELAY_FAST;
}

#[cfg(not(feature = "fast-runtime"))]
parameter_types! {
#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const LeaveOperatorsDelay: u32 = 10;
pub const LeaveOperatorsDelay: u32 = tangle_primitives::multi_asset_delegation::LEAVE_OPERATORS_DELAY;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const LeaveDelegatorsDelay: u32 = 10;
pub const LeaveDelegatorsDelay: u32 = tangle_primitives::multi_asset_delegation::LEAVE_DELEGATORS_DELAY;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const DelegationBondLessDelay: u32 = 5;
pub const DelegationBondLessDelay: u32 = tangle_primitives::multi_asset_delegation::DELEGATION_BOND_LESS_DELAY;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const OperatorBondLessDelay: u32 = 5;
pub const OperatorBondLessDelay: u32 = tangle_primitives::multi_asset_delegation::OPERATOR_BOND_LESS_DELAY;
}

impl pallet_multi_asset_delegation::Config for Runtime {
Expand Down Expand Up @@ -2235,4 +2239,28 @@ impl_runtime_apis! {
Services::service_requests_with_blueprints_by_operator(operator).map_err(Into::into)
}
}

impl pallet_rewards_rpc_runtime_api::RewardsApi<Block, AccountId, AssetId, Balance> for Runtime {
fn query_user_rewards(
account_id: AccountId,
asset_id: tangle_primitives::services::Asset<AssetId>,
) -> Result<Balance, sp_runtime::DispatchError> {
Rewards::calculate_rewards(&account_id, asset_id)
}
}

impl pallet_credits_rpc_runtime_api::CreditsApi<Block, AccountId, Balance, AssetId> for Runtime {
fn query_user_credits(
account_id: AccountId,
) -> Result<Balance, sp_runtime::DispatchError> {
Credits::get_accrued_amount(&account_id, None)
}

fn query_user_credits_with_asset(
account_id: AccountId,
asset_id: AssetId,
) -> Result<Balance, sp_runtime::DispatchError> {
Credits::get_accrued_amount_for_asset(&account_id, None, asset_id)
}
}
}
56 changes: 30 additions & 26 deletions runtime/testnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,14 +1228,14 @@ impl pallet_tangle_lst::Config for Runtime {
}

parameter_types! {
pub const RewardsPID: PalletId = PalletId(*b"py/tnrew");
pub const MaxDepositCap: u128 = UNIT * 1_000_000_000_000;
pub const MaxIncentiveCap: u128 = UNIT * 1_000_000_000_000;
pub const MaxApy: Perbill = Perbill::from_percent(20);
pub const MinDepositCap: u128 = 0;
pub const MinIncentiveCap: u128 = 0;
pub const MaxVaultNameLen: u32 = 64;
pub const MaxVaultLogoLen: u32 = 256;
pub const RewardsPID: PalletId = tangle_primitives::types::rewards::PALLET_ID;
pub const MaxDepositCap: Balance = tangle_primitives::types::rewards::testnet::MAX_DEPOSIT_CAP;
pub const MaxIncentiveCap: Balance = tangle_primitives::types::rewards::testnet::MAX_INCENTIVE_CAP;
pub const MaxApy: Perbill = tangle_primitives::types::rewards::testnet::MAX_APY;
pub const MinDepositCap: Balance = tangle_primitives::types::rewards::MIN_DEPOSIT_CAP;
pub const MinIncentiveCap: Balance = tangle_primitives::types::rewards::MIN_INCENTIVE_CAP;
pub const MaxVaultNameLen: u32 = tangle_primitives::types::rewards::MAX_VAULT_NAME_LENGTH;
pub const MaxVaultLogoLen: u32 = tangle_primitives::types::rewards::MAX_VAULT_LOGO_LENGTH;
}

impl pallet_rewards::Config for Runtime {
Expand All @@ -1254,7 +1254,8 @@ impl pallet_rewards::Config for Runtime {
type MaxVaultNameLength = MaxVaultNameLen;
type MaxVaultLogoLength = MaxVaultLogoLen;
type VaultMetadataOrigin = EnsureRootOrHalfCouncil;
type MaxPendingRewardsPerOperator = ConstU32<100>;
type MaxPendingRewardsPerOperator =
ConstU32<{ tangle_primitives::types::rewards::MAX_PENDING_REWARDS_PER_OPERATOR }>;
type WeightInfo = ();
}

Expand Down Expand Up @@ -1533,51 +1534,54 @@ impl pallet_assets::Config<LstPoolAssetsInstance> for Runtime {
}

parameter_types! {
pub const MinOperatorBondAmount: Balance = 100;
pub const MinOperatorBondAmount: Balance = tangle_primitives::multi_asset_delegation::MIN_OPERATOR_BOND_AMOUNT;
pub const MinDelegateAmount: Balance = tangle_primitives::multi_asset_delegation::MIN_DELEGATE_AMOUNT;
pub PID: PalletId = tangle_primitives::multi_asset_delegation::PALLET_ID;

pub const MinDelegateAmount : Balance = 1;
pub PID: PalletId = PalletId(*b"PotStake");
#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const MaxDelegatorBlueprints : u32 = 50;
#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const MaxOperatorBlueprints : u32 = 50;
pub const MaxDelegatorBlueprints: u32 = tangle_primitives::multi_asset_delegation::MAX_DELEGATOR_BLUEPRINTS;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const MaxWithdrawRequests: u32 = 5;
pub const MaxOperatorBlueprints: u32 = tangle_primitives::multi_asset_delegation::MAX_OPERATOR_BLUEPRINTS;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const MaxUnstakeRequests: u32 = 5;
pub const MaxWithdrawRequests: u32 = tangle_primitives::multi_asset_delegation::MAX_WITHDRAW_REQUESTS;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const MaxDelegations: u32 = 50;
pub const MaxUnstakeRequests: u32 = tangle_primitives::multi_asset_delegation::MAX_UNSTAKE_REQUESTS;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const MaxDelegations: u32 = tangle_primitives::multi_asset_delegation::MAX_DELEGATIONS;
}

#[cfg(feature = "fast-runtime")]
parameter_types! {
#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const LeaveOperatorsDelay: u32 = 1;
pub const LeaveOperatorsDelay: u32 = tangle_primitives::multi_asset_delegation::LEAVE_OPERATORS_DELAY_FAST;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const LeaveDelegatorsDelay: u32 = 1;
pub const LeaveDelegatorsDelay: u32 = tangle_primitives::multi_asset_delegation::LEAVE_DELEGATORS_DELAY_FAST;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const DelegationBondLessDelay: u32 = 1;
pub const DelegationBondLessDelay: u32 = tangle_primitives::multi_asset_delegation::DELEGATION_BOND_LESS_DELAY_FAST;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const OperatorBondLessDelay: u32 = 1;
pub const OperatorBondLessDelay: u32 = tangle_primitives::multi_asset_delegation::OPERATOR_BOND_LESS_DELAY_FAST;
}

#[cfg(not(feature = "fast-runtime"))]
parameter_types! {
#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const LeaveOperatorsDelay: u32 = 10;
pub const LeaveOperatorsDelay: u32 = tangle_primitives::multi_asset_delegation::LEAVE_OPERATORS_DELAY;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const LeaveDelegatorsDelay: u32 = 10;
pub const LeaveDelegatorsDelay: u32 = tangle_primitives::multi_asset_delegation::LEAVE_DELEGATORS_DELAY;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const DelegationBondLessDelay: u32 = 5;
pub const DelegationBondLessDelay: u32 = tangle_primitives::multi_asset_delegation::DELEGATION_BOND_LESS_DELAY;

#[derive(PartialEq, Eq, Clone, Copy, Debug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub const OperatorBondLessDelay: u32 = 5;
pub const OperatorBondLessDelay: u32 = tangle_primitives::multi_asset_delegation::OPERATOR_BOND_LESS_DELAY;
}

impl pallet_multi_asset_delegation::Config for Runtime {
Expand Down
Loading