Skip to content

Commit

Permalink
tmp: add debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
wischli committed May 17, 2024
1 parent f9af683 commit 7214b97
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 55 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

42 changes: 22 additions & 20 deletions libs/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ documentation.workspace = true
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
log = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
hex = { workspace = true }
Expand All @@ -28,28 +29,29 @@ sp-std = { workspace = true }
[features]
default = ["std"]
std = [
"frame-support/std",
"frame-system/std",
"sp-runtime/std",
"sp-arithmetic/std",
"sp-std/std",
"pallet-timestamp/std",
"pallet-aura/std",
"parity-scale-codec/std",
"scale-info/std",
"sp-consensus-aura/std",
"hex/std",
"frame-support/std",
"frame-system/std",
"sp-runtime/std",
"sp-arithmetic/std",
"sp-std/std",
"pallet-timestamp/std",
"pallet-aura/std",
"parity-scale-codec/std",
"scale-info/std",
"sp-consensus-aura/std",
"hex/std",
"log/std",
]
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-aura/try-runtime",
"pallet-timestamp/try-runtime",
"sp-runtime/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-aura/try-runtime",
"pallet-timestamp/try-runtime",
"sp-runtime/try-runtime",
]
7 changes: 5 additions & 2 deletions libs/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,16 @@ pub mod math {
x: X,
) -> Result<Y, ArithmeticError>
where
X: BaseArithmetic + FixedPointOperand,
Y: BaseArithmetic + FixedPointOperand,
X: BaseArithmetic + FixedPointOperand + sp_std::fmt::Debug,
Y: BaseArithmetic + FixedPointOperand + sp_std::fmt::Debug,
{
// From the equation: (x - x1) / (x2 - x1) == (y - y1) / (y2 - y1) we solve y:
//
// NOTE: With rects that have x or y negative directions, we emulate a
// symmetry in those axis to avoid unsigned underflows in substractions. It
// means, we first "convert" the rect into an increasing rect, and in such rect,
// we find the y coordinate.
log::warn!("y_coord_in_rect: x1 {x1:?}, x2 {x2:?}, y1 {y1:?}, y2 {y2:?}, x: {x:?}");

let left = if x1 <= x2 {
FixedU128::ensure_from_rational(x.ensure_sub(x1)?, x2.ensure_sub(x1)?)?
Expand All @@ -145,6 +146,8 @@ pub mod math {
FixedU128::ensure_from_rational(x1.ensure_sub(x)?, x1.ensure_sub(x2)?)?
};

log::warn!("y_coord_in_rect: left {left:?}");

if y1 <= y2 {
left.ensure_mul_int(y2.ensure_sub(y1)?)?.ensure_add(y1)
} else {
Expand Down
68 changes: 35 additions & 33 deletions pallets/loans/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
log = { workspace = true }

frame-support = { workspace = true }
frame-system = { workspace = true }
Expand Down Expand Up @@ -47,41 +48,42 @@ cfg-mocks = { workspace = true, default-features = true }
[features]
default = ["std"]
std = [
"parity-scale-codec/std",
"scale-info/std",
"frame-support/std",
"frame-system/std",
"sp-arithmetic/std",
"sp-runtime/std",
"sp-std/std",
"cfg-primitives/std",
"cfg-traits/std",
"cfg-types/std",
"cfg-utils/std",
"frame-benchmarking/std",
"strum/std",
"orml-traits/std",
"parity-scale-codec/std",
"scale-info/std",
"frame-support/std",
"frame-system/std",
"sp-arithmetic/std",
"sp-runtime/std",
"sp-std/std",
"cfg-primitives/std",
"cfg-traits/std",
"cfg-types/std",
"cfg-utils/std",
"frame-benchmarking/std",
"strum/std",
"orml-traits/std",
"log/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"cfg-primitives/runtime-benchmarks",
"cfg-traits/runtime-benchmarks",
"cfg-types/runtime-benchmarks",
"cfg-utils/runtime-benchmarks",
"pallet-uniques/runtime-benchmarks",
"cfg-mocks/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"cfg-primitives/runtime-benchmarks",
"cfg-traits/runtime-benchmarks",
"cfg-types/runtime-benchmarks",
"cfg-utils/runtime-benchmarks",
"pallet-uniques/runtime-benchmarks",
"cfg-mocks/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
"cfg-primitives/try-runtime",
"cfg-traits/try-runtime",
"cfg-types/try-runtime",
"cfg-utils/try-runtime",
"cfg-mocks/try-runtime",
"sp-runtime/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
"cfg-primitives/try-runtime",
"cfg-traits/try-runtime",
"cfg-types/try-runtime",
"cfg-utils/try-runtime",
"cfg-mocks/try-runtime",
"sp-runtime/try-runtime",
]
2 changes: 2 additions & 0 deletions pallets/loans/src/entities/pricing/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ impl<T: Config> ExternalActivePricing<T> {
price: T::Balance,
price_last_updated: Seconds,
) -> Result<T::Balance, DispatchError> {
log::warn!("maybe_with_linear_accrual_price: Seconds {maturity:?}, price {price:?}, price_last_updated {price_last_updated:?}");
if self.info.with_linear_pricing {
Ok(cfg_utils::math::y_coord_in_rect(
(price_last_updated, price),
Expand Down Expand Up @@ -187,6 +188,7 @@ impl<T: Config> ExternalActivePricing<T> {
maturity: Seconds,
oracle: Option<PriceOf<T>>,
) -> Result<T::Balance, DispatchError> {
log::warn!("current_price_inner: Seconds {maturity:?}, oracle {oracle:?}");
if let Some((oracle_price, oracle_provided_at)) = oracle {
self.maybe_with_linear_accrual_price(
maturity,
Expand Down

0 comments on commit 7214b97

Please sign in to comment.