Skip to content

Commit

Permalink
Merge pull request #1257 from bifrost-finance/add-buy-back
Browse files Browse the repository at this point in the history
Add buy back
  • Loading branch information
SunTiebing authored Jun 5, 2024
2 parents 171f9e9 + fcc6100 commit 08aa1c2
Show file tree
Hide file tree
Showing 21 changed files with 1,589 additions and 17 deletions.
52 changes: 44 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"node/service",
"primitives",
"pallets/asset-registry",
"pallets/buy-back",
"pallets/currencies",
"pallets/flexible-fee",
"pallets/farming",
Expand Down Expand Up @@ -56,6 +57,7 @@ bifrost-polkadot-runtime = { path = "runtime/bifrost-polkadot" }

# Bifrost Wasm
bifrost-asset-registry = { path = "pallets/asset-registry", default-features = false }
bifrost-buy-back = { path = "pallets/buy-back", default-features = false }
bifrost-call-switchgear = { path = "pallets/call-switchgear", default-features = false }
bifrost-cross-in-out = { path = "pallets/cross-in-out", default-features = false }
bifrost-currencies = { path = "pallets/currencies", default-features = false }
Expand Down
69 changes: 69 additions & 0 deletions pallets/buy-back/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[package]
authors = ["Kadokura <[email protected]>"]
edition = "2021"
name = "bifrost-buy-back"
version = "0.8.0"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
bifrost-primitives = { workspace = true }
bifrost-slp = { workspace = true }
bifrost-vtoken-minting = { workspace = true }
cumulus-primitives-core = { workspace = true }
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
hex-literal = { workspace = true }
log = { workspace = true }
orml-traits = { workspace = true }
pallet-balances = { workspace = true }
parity-scale-codec = { workspace = true, features = ["derive"] }
scale-info = { workspace = true, features = ["derive"] }
sp-arithmetic = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
xcm = { workspace = true }
zenlink-protocol = { workspace = true }
bifrost-ve-minting = { workspace = true }

[dev-dependencies]
bifrost-asset-registry = { workspace = true }
bifrost-currencies = { workspace = true }
orml-tokens = { workspace = true }
orml-traits = { workspace = true }
orml-xtokens = { workspace = true }
pallet-xcm = { workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
xcm-builder = { workspace = true }
xcm-executor = { workspace = true }
env_logger = { workspace = true }

[features]
default = ["std"]
std = [
"parity-scale-codec/std",
"scale-info/std",
"sp-runtime/std",
"frame-support/std",
"frame-system/std",
"frame-benchmarking/std",
"bifrost-primitives/std",
"orml-traits/std",
"bifrost-vtoken-minting/std",
"zenlink-protocol/std",
"bifrost-slp/std",
"bifrost-asset-registry/std",
"orml-xtokens/std",
]

runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
75 changes: 75 additions & 0 deletions pallets/buy-back/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// This file is part of Bifrost.

// Copyright (C) Liebi Technologies PTE. LTD.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// Ensure we're `no_std` when compiling for Wasm.

#![cfg(feature = "runtime-benchmarks")]

use crate::{BalanceOf, Call, Config, Pallet, Pallet as BuyBack, *};
use bifrost_primitives::{CurrencyId, TokenSymbol, DOT};
use frame_benchmarking::v1::{account, benchmarks, BenchmarkError};
use frame_support::{
assert_ok,
traits::{EnsureOrigin, Hooks},
};
use frame_system::RawOrigin;
use orml_traits::MultiCurrency;
use sp_runtime::traits::UniqueSaturatedFrom;

benchmarks! {
set_vtoken {
let origin = T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
}: _<T::RuntimeOrigin>(origin,CurrencyId::VToken(TokenSymbol::KSM),1_000_000u32.into(),Permill::from_percent(2),1000u32.into(),1000u32.into(),true)

charge {
let test_account: T::AccountId = account("seed",1,1);

T::MultiCurrency::deposit(DOT, &test_account, BalanceOf::<T>::unique_saturated_from(1_000_000_000_000_000u128))?;
}: _(RawOrigin::Signed(test_account),DOT,BalanceOf::<T>::unique_saturated_from(9_000_000_000_000u128))

remove_vtoken {
let origin = T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
assert_ok!(BuyBack::<T>::set_vtoken(
T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
CurrencyId::VToken(TokenSymbol::KSM),
1_000_000u32.into(),
Permill::from_percent(2),
1000u32.into(),
1000u32.into(),
true
));
}: _<T::RuntimeOrigin>(origin,CurrencyId::Token(TokenSymbol::KSM))


on_idle {
let origin = T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
assert_ok!(BuyBack::<T>::set_vtoken(
T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
CurrencyId::VToken(TokenSymbol::KSM),
1_000_000u32.into(),
Permill::from_percent(2),
1000u32.into(),
1000u32.into(),
true
));
}: {
BuyBack::<T>::on_idle(BlockNumberFor::<T>::from(0u32),Weight::from_parts(0, u64::MAX));
}

impl_benchmark_test_suite!(BuyBack,crate::mock::ExtBuilder::default().build(),crate::mock::Runtime);
}
Loading

0 comments on commit 08aa1c2

Please sign in to comment.