Skip to content

Commit 6d028c9

Browse files
committed
Update OCW to SerpTreasury 0.9.0
1 parent e72e24f commit 6d028c9

File tree

3 files changed

+34
-76
lines changed

3 files changed

+34
-76
lines changed

lib-serml/serp/serp-ocw/Cargo.toml

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ lite-json = { version = "0.1", default-features = false }
1313
log = { version = "0.4.14", default-features = false }
1414
fixed = { default-features = false, git = "https://github.com/encointer/substrate-fixed", package = "substrate-fixed" }
1515

16-
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
17-
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
18-
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
16+
# Substrate dependencies
17+
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
18+
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
19+
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
20+
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
21+
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
1922
sp-keystore = { git = 'https://github.com/paritytech/substrate.git', branch = "polkadot-v0.9.8", optional = true }
2023
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
21-
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
22-
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }
2324

2425
# orml dependencies
2526
orml-traits = { path = "../../../lib-openrml/traits", default-features = false }

lib-serml/serp/serp-ocw/src/lib.rs

+28-64
Original file line numberDiff line numberDiff line change
@@ -672,24 +672,24 @@ impl<T: Config> Pallet<T> {
672672
}
673673

674674
/// Calculate the `min_target_amount` for `SerpUp` operation.
675-
fn calculate_min_target_amount(market_price: u64, dinar_price: u64, expand_by: Balance) -> Balance {
676-
type Fix = FixedU128<U128>;
677-
let expand_by_amount = Fix::from_num(1).saturating_mul_int(expand_by as u128);
678-
let relative_price = Fix::from_num(market_price) / Fix::from_num(dinar_price);
679-
let min_target_amount_full = Fix::from_num(expand_by_amount) / Fix::from_num(relative_price);
680-
let min_target_fraction = Fix::from_num(min_target_amount_full) / Fix::from_num(100);
681-
min_target_fraction.saturating_mul_int(94 as u128).to_num::<u128>()
682-
}
675+
// fn calculate_min_target_amount(market_price: u64, dinar_price: u64, expand_by: Balance) -> Balance {
676+
// type Fix = FixedU128<U128>;
677+
// let expand_by_amount = Fix::from_num(1).saturating_mul_int(expand_by as u128);
678+
// let relative_price = Fix::from_num(market_price) / Fix::from_num(dinar_price);
679+
// let min_target_amount_full = Fix::from_num(expand_by_amount) / Fix::from_num(relative_price);
680+
// let min_target_fraction = Fix::from_num(min_target_amount_full) / Fix::from_num(100);
681+
// min_target_fraction.saturating_mul_int(94 as u128).to_num::<u128>()
682+
// }
683683

684684
/// Calculate the `max_supply_amount` for `SerpUp` operation.
685-
fn calculate_max_supply_amount(market_price: u64, dinar_price: u64, contract_by: Balance) -> Balance {
686-
type Fix = FixedU128<U128>;
687-
let contract_by_amount = Fix::from_num(1).saturating_mul_int(contract_by as u128);
688-
let relative_price = Fix::from_num(market_price) / Fix::from_num(dinar_price);
689-
let max_supply_amount_full = Fix::from_num(contract_by_amount) / Fix::from_num(relative_price);
690-
let max_supply_fraction = Fix::from_num(max_supply_amount_full) / Fix::from_num(100);
691-
max_supply_fraction.saturating_mul_int(106 as u128).to_num::<u128>()
692-
}
685+
// fn calculate_max_supply_amount(market_price: u64, dinar_price: u64, contract_by: Balance) -> Balance {
686+
// type Fix = FixedU128<U128>;
687+
// let contract_by_amount = Fix::from_num(1).saturating_mul_int(contract_by as u128);
688+
// let relative_price = Fix::from_num(market_price) / Fix::from_num(dinar_price);
689+
// let max_supply_amount_full = Fix::from_num(contract_by_amount) / Fix::from_num(relative_price);
690+
// let max_supply_fraction = Fix::from_num(max_supply_amount_full) / Fix::from_num(100);
691+
// max_supply_fraction.saturating_mul_int(106 as u128).to_num::<u128>()
692+
// }
693693

694694
/// FETCH SETCURRENCIES COIN PRICES
695695
///
@@ -944,19 +944,13 @@ impl<T: Config> Pallet<T> {
944944
// safe from underflow because `peg_price` is checked to be less than `market_price`
945945
let expand_by = Self::calculate_supply_change(market_price, peg_price, total_supply);
946946

947-
// `min_target_amount` for `SerpUp` operation
948-
let min_target_amount = Self::calculate_min_target_amount(market_price, dinar_price, expand_by);
949-
950-
T::SerpTreasury::on_serpup(T::SetterCurrencyId::get(), expand_by, min_target_amount).unwrap();
947+
T::SerpTreasury::on_serpup(T::SetterCurrencyId::get(), expand_by).unwrap();
951948
}
952949
market_price if market_price < peg_price => {
953950
// safe from underflow because `peg_price` is checked to be greater than `market_price`
954951
let contract_by = Self::calculate_supply_change(peg_price, market_price, total_supply);
955952

956-
// `max_supply_amount` for `SerpDown` operation
957-
let max_supply_amount = Self::calculate_max_supply_amount(market_price, dinar_price, contract_by);
958-
959-
T::SerpTreasury::on_serpdown(T::SetterCurrencyId::get(), contract_by, max_supply_amount).unwrap();
953+
T::SerpTreasury::on_serpdown(T::SetterCurrencyId::get(), contract_by).unwrap();
960954
}
961955
_ => {}
962956
}
@@ -1073,19 +1067,13 @@ impl<T: Config> Pallet<T> {
10731067
// safe from underflow because `peg_price` is checked to be less than `market_price`
10741068
let expand_by = Self::calculate_supply_change(market_price, peg_price, total_supply);
10751069

1076-
// `min_target_amount` for `SerpUp` operation
1077-
let min_target_amount = Self::calculate_min_target_amount(market_price, dinar_price, expand_by);
1078-
1079-
T::SerpTreasury::on_serpup(T::GetSetUSDCurrencyId::get(), expand_by, min_target_amount).unwrap();
1070+
T::SerpTreasury::on_serpup(T::GetSetUSDCurrencyId::get(), expand_by).unwrap();
10801071
}
10811072
market_price if market_price < peg_price => {
10821073
// safe from underflow because `peg_price` is checked to be greater than `market_price`
10831074
let contract_by = Self::calculate_supply_change(peg_price, market_price, total_supply);
10841075

1085-
// `max_supply_amount` for `SerpDown` operation
1086-
let max_supply_amount = Self::calculate_max_supply_amount(market_price, setter_price, contract_by);
1087-
1088-
T::SerpTreasury::on_serpdown(T::GetSetUSDCurrencyId::get(), contract_by, max_supply_amount).unwrap();
1076+
T::SerpTreasury::on_serpdown(T::GetSetUSDCurrencyId::get(), contract_by).unwrap();
10891077
}
10901078
_ => {}
10911079
}
@@ -1202,19 +1190,13 @@ impl<T: Config> Pallet<T> {
12021190
// safe from underflow because `peg_price` is checked to be less than `market_price`
12031191
let expand_by = Self::calculate_supply_change(market_price, peg_price, total_supply);
12041192

1205-
// `min_target_amount` for `SerpUp` operation
1206-
let min_target_amount = Self::calculate_min_target_amount(market_price, dinar_price, expand_by);
1207-
1208-
T::SerpTreasury::on_serpup(T::GetSetEURCurrencyId::get(), expand_by, min_target_amount).unwrap();
1193+
T::SerpTreasury::on_serpup(T::GetSetEURCurrencyId::get(), expand_by).unwrap();
12091194
}
12101195
market_price if market_price < peg_price => {
12111196
// safe from underflow because `peg_price` is checked to be greater than `market_price`
12121197
let contract_by = Self::calculate_supply_change(peg_price, market_price, total_supply);
12131198

1214-
// `max_supply_amount` for `SerpDown` operation
1215-
let max_supply_amount = Self::calculate_max_supply_amount(market_price, setter_price, contract_by);
1216-
1217-
T::SerpTreasury::on_serpdown(T::GetSetEURCurrencyId::get(), contract_by, max_supply_amount).unwrap();
1199+
T::SerpTreasury::on_serpdown(T::GetSetEURCurrencyId::get(), contract_by).unwrap();
12181200
}
12191201
_ => {}
12201202
}
@@ -1331,19 +1313,13 @@ impl<T: Config> Pallet<T> {
13311313
// safe from underflow because `peg_price` is checked to be less than `market_price`
13321314
let expand_by = Self::calculate_supply_change(market_price, peg_price, total_supply);
13331315

1334-
// `min_target_amount` for `SerpUp` operation
1335-
let min_target_amount = Self::calculate_min_target_amount(market_price, dinar_price, expand_by);
1336-
1337-
T::SerpTreasury::on_serpup(T::GetSetGBPCurrencyId::get(), expand_by, min_target_amount).unwrap();
1316+
T::SerpTreasury::on_serpup(T::GetSetGBPCurrencyId::get(), expand_by).unwrap();
13381317
}
13391318
market_price if market_price < peg_price => {
13401319
// safe from underflow because `peg_price` is checked to be greater than `market_price`
13411320
let contract_by = Self::calculate_supply_change(peg_price, market_price, total_supply);
13421321

1343-
// `max_supply_amount` for `SerpDown` operation
1344-
let max_supply_amount = Self::calculate_max_supply_amount(market_price, setter_price, contract_by);
1345-
1346-
T::SerpTreasury::on_serpdown(T::GetSetGBPCurrencyId::get(), contract_by, max_supply_amount).unwrap();
1322+
T::SerpTreasury::on_serpdown(T::GetSetGBPCurrencyId::get(), contract_by).unwrap();
13471323
}
13481324
_ => {}
13491325
}
@@ -1460,19 +1436,13 @@ impl<T: Config> Pallet<T> {
14601436
// safe from underflow because `peg_price` is checked to be less than `market_price`
14611437
let expand_by = Self::calculate_supply_change(market_price, peg_price, total_supply);
14621438

1463-
// `min_target_amount` for `SerpUp` operation
1464-
let min_target_amount = Self::calculate_min_target_amount(market_price, dinar_price, expand_by);
1465-
1466-
T::SerpTreasury::on_serpup(T::GetSetCHFCurrencyId::get(), expand_by, min_target_amount).unwrap();
1439+
T::SerpTreasury::on_serpup(T::GetSetCHFCurrencyId::get(), expand_by).unwrap();
14671440
}
14681441
market_price if market_price < peg_price => {
14691442
// safe from underflow because `peg_price` is checked to be greater than `market_price`
14701443
let contract_by = Self::calculate_supply_change(peg_price, market_price, total_supply);
14711444

1472-
// `max_supply_amount` for `SerpDown` operation
1473-
let max_supply_amount = Self::calculate_max_supply_amount(market_price, setter_price, contract_by);
1474-
1475-
T::SerpTreasury::on_serpdown(T::GetSetCHFCurrencyId::get(), contract_by, max_supply_amount).unwrap();
1445+
T::SerpTreasury::on_serpdown(T::GetSetCHFCurrencyId::get(), contract_by).unwrap();
14761446
}
14771447
_ => {}
14781448
}
@@ -1589,19 +1559,13 @@ impl<T: Config> Pallet<T> {
15891559
// safe from underflow because `peg_price` is checked to be less than `market_price`
15901560
let expand_by = Self::calculate_supply_change(market_price, peg_price, total_supply);
15911561

1592-
// `min_target_amount` for `SerpUp` operation
1593-
let min_target_amount = Self::calculate_min_target_amount(market_price, dinar_price, expand_by);
1594-
1595-
T::SerpTreasury::on_serpup(T::GetSetSARCurrencyId::get(), expand_by, min_target_amount).unwrap();
1562+
T::SerpTreasury::on_serpup(T::GetSetSARCurrencyId::get(), expand_by).unwrap();
15961563
}
15971564
market_price if market_price < peg_price => {
15981565
// safe from underflow because `peg_price` is checked to be greater than `market_price`
15991566
let contract_by = Self::calculate_supply_change(peg_price, market_price, total_supply);
16001567

1601-
// `max_supply_amount` for `SerpDown` operation
1602-
let max_supply_amount = Self::calculate_max_supply_amount(market_price, setter_price, contract_by);
1603-
1604-
T::SerpTreasury::on_serpdown(T::GetSetSARCurrencyId::get(), contract_by, max_supply_amount).unwrap();
1568+
T::SerpTreasury::on_serpdown(T::GetSetSARCurrencyId::get(), contract_by).unwrap();
16051569
}
16061570
_ => {}
16071571
}

lib-serml/serp/serp-ocw/src/tests.rs

-7
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,13 @@ impl DEXManager<AccountId, CurrencyId, Balance> for MockDEX {
158158
fn get_swap_target_amount(
159159
_path: &[CurrencyId],
160160
_supply_amount: Balance,
161-
_price_impact_limit: Option<Ratio>,
162161
) -> Option<Balance> {
163162
unimplemented!()
164163
}
165164

166165
fn get_swap_supply_amount(
167166
_path: &[CurrencyId],
168167
_target_amount: Balance,
169-
_price_impact_limit: Option<Ratio>,
170168
) -> Option<Balance> {
171169
unimplemented!()
172170
}
@@ -176,7 +174,6 @@ impl DEXManager<AccountId, CurrencyId, Balance> for MockDEX {
176174
_path: &[CurrencyId],
177175
_supply_amount: Balance,
178176
_min_target_amount: Balance,
179-
_price_impact_limit: Option<Ratio>,
180177
) -> sp_std::result::Result<Balance, DispatchError> {
181178
unimplemented!()
182179
}
@@ -186,7 +183,6 @@ impl DEXManager<AccountId, CurrencyId, Balance> for MockDEX {
186183
_path: &[CurrencyId],
187184
_target_amount: Balance,
188185
_max_supply_amount: Balance,
189-
_price_impact_limit: Option<Ratio>,
190186
) -> sp_std::result::Result<Balance, DispatchError> {
191187
unimplemented!()
192188
}
@@ -224,7 +220,6 @@ impl SerpTreasury<AccountId> for MockSerpTreasury {
224220
fn get_buyback_serpup(
225221
_amount: Balance,
226222
_currency_id: CurrencyId,
227-
_min_target_amount: Balance
228223
) -> DispatchResult {
229224
unimplemented!()
230225
}
@@ -259,7 +254,6 @@ impl SerpTreasury<AccountId> for MockSerpTreasury {
259254
fn on_serpup(
260255
_currency_id: CurrencyId,
261256
_amount: Balance,
262-
_min_target_amount: Balance
263257
) -> DispatchResult {
264258
unimplemented!()
265259
}
@@ -268,7 +262,6 @@ impl SerpTreasury<AccountId> for MockSerpTreasury {
268262
fn on_serpdown(
269263
_currency_id: CurrencyId,
270264
_amount: Balance,
271-
_max_supply_amount: Balance
272265
) -> DispatchResult {
273266
unimplemented!()
274267
}

0 commit comments

Comments
 (0)