-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1257 from bifrost-finance/add-buy-back
Add buy back
- Loading branch information
Showing
21 changed files
with
1,589 additions
and
17 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
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"] |
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,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); | ||
} |
Oops, something went wrong.