-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
221 additions
and
69 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[package] | ||
name = "proxy-bonding" | ||
authors.workspace = true | ||
documentation.workspace = true | ||
edition.workspace = true | ||
homepage.workspace = true | ||
license-file.workspace = true | ||
readme.workspace = true | ||
repository.workspace = true | ||
version.workspace = true | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[dependencies] | ||
frame-system.workspace = true | ||
frame-support.workspace = true | ||
sp-runtime.workspace = true | ||
polimec-common.workspace = true | ||
parity-scale-codec.workspace = true | ||
scale-info.workspace = true | ||
|
||
[features] | ||
default = ["std"] | ||
|
||
std = [ | ||
"frame-system/std", | ||
"frame-support/std", | ||
"sp-runtime/std", | ||
"polimec-common/std", | ||
"parity-scale-codec/std", | ||
"scale-info/std", | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::{AccountIdOf, Balance, Config, HoldReasonOf, Pallet}; | ||
use frame_support::traits::{ | ||
fungible, | ||
tokens::{Fortitude, Precision, Preservation}, | ||
}; | ||
use polimec_common::ProvideAssetPrice; | ||
use sp_runtime::traits::{AccountIdConversion, Get}; | ||
|
||
impl<T: Config> Pallet<T> { | ||
pub fn bond_on_behalf_of( | ||
account: T::AccountId, | ||
bond_amount: Balance, | ||
derivation_path: u32, | ||
hold_reason: HoldReasonOf<T>, | ||
) -> Result<(), &'static str> { | ||
let treasury = T::Treasury::get(); | ||
let bonding_account: AccountIdOf<T> = T::RootId::get().into_sub_account_truncating(derivation_path); | ||
let existential_deposit = <T::BondingToken as fungible::Inspect<T::AccountId>>::minimum_balance(); | ||
// let fee = T::PriceProvider::get_decimals_aware_price()?; | ||
// | ||
// // Ensure the sub-account has an ED by the treasury. This will be refunded after all the tokens are unlocked | ||
// if T::BondingToken::balance(&bonding_account) < existential_deposit { | ||
// T::BondingToken::transfer(treasury.clone(), bonding_account, existential_deposit, Preservation::Preserve)?; | ||
// } | ||
// T::BondingToken::transfer_and_hold(hold_reason, treasury.clone(), bonding_account.clone(), bond_amount, Precision::Exact, Preservation::Preserve, Fortitude::Polite)?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
pub use pallet::*; | ||
|
||
mod functions; | ||
|
||
#[frame_support::pallet] | ||
pub mod pallet { | ||
use frame_support::{ | ||
dispatch::DispatchResultWithPostInfo, | ||
pallet_prelude::*, | ||
traits::{fungible, fungibles}, | ||
DefaultNoBound, | ||
}; | ||
use frame_system::{pallet_prelude::*, weights}; | ||
use polimec_common::ProvideAssetPrice; | ||
use sp_runtime::{ | ||
traits::{CheckedAdd, One}, | ||
TypeId, | ||
}; | ||
use frame_support::pallet_prelude::Weight; | ||
|
||
pub type Balance = u128; | ||
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId; | ||
pub type HoldReasonOf<T> = <<T as Config>::FeeToken as fungibles::InspectHold<AccountIdOf<T>>>::Reason; | ||
// pub type AssetId<T> = <<T as Config>::FeeToken as fungiles::Inspect< | ||
|
||
/// Configure the pallet by specifying the parameters and types on which it depends. | ||
#[pallet::config] | ||
pub trait Config: frame_system::Config { | ||
/// Because this pallet emits events, it depends on the runtime's definition of an event. | ||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; | ||
|
||
/// The pallet giving access to the bonding token | ||
type BondingToken: fungible::Inspect<Self::AccountId, Balance = Balance> | ||
+ fungible::Mutate<Self::AccountId, Balance = Balance> | ||
+ fungible::MutateHold<Self::AccountId, Balance = Balance>; | ||
|
||
/// The pallet giving access to fee-paying assets, like USDT | ||
type FeeToken: fungibles::Inspect<Self::AccountId, Balance = Balance> | ||
+ fungibles::Mutate<Self::AccountId, Balance = Balance> | ||
+ fungibles::InspectHold<Self::AccountId, Balance = Balance>; | ||
|
||
/// Method to get the price of an asset like USDT or PLMC. Likely to come from an oracle | ||
type PriceProvider: ProvideAssetPrice<AssetId = u32>; | ||
|
||
/// The account holding the tokens to be bonded. Normally the treasury | ||
type Treasury: Get<Self::AccountId>; | ||
|
||
/// The id type that can generate sub-accounts | ||
type Id: Encode + Decode + TypeId; | ||
|
||
/// The root id used to derive sub-accounts. These sub-accounts will be used to bond the tokens | ||
type RootId: Get<Self::Id>; | ||
} | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(_); | ||
|
||
#[pallet::event] | ||
#[pallet::generate_deposit(pub(super) fn deposit_event)] | ||
pub enum Event<T: Config> { | ||
Event1 { who: T::AccountId }, | ||
} | ||
|
||
#[pallet::error] | ||
pub enum Error<T> { | ||
Error1, | ||
} | ||
|
||
#[pallet::hooks] | ||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {} | ||
|
||
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
#[pallet::call_index(0)] | ||
#[pallet::weight(Weight::zero())] | ||
pub fn example_extrinsic(origin: OriginFor<T>) -> DispatchResult { | ||
let _caller = ensure_signed(origin)?; | ||
Ok(()) | ||
} | ||
} | ||
} |
Oops, something went wrong.