diff --git a/crates/core/component/dex/src/component/circuit_breaker/value.rs b/crates/core/component/dex/src/component/circuit_breaker/value.rs index fd0b8f06f1..eb650207a7 100644 --- a/crates/core/component/dex/src/component/circuit_breaker/value.rs +++ b/crates/core/component/dex/src/component/circuit_breaker/value.rs @@ -55,23 +55,15 @@ mod tests { component::{router::limit_buy, tests::TempStorageExt, PositionManager as _}, state_key, DirectedUnitPair, }; - use crate::{BatchSwapOutputData, PositionOpen, PositionWithdraw}; - use cnidarium::{ - ArcStateDeltaExt as _, StateDelta, StateRead as _, StateWrite as _, TempStorage, - }; + use crate::{BatchSwapOutputData, PositionOpen}; + use cnidarium::{ArcStateDeltaExt as _, StateDelta, TempStorage}; use cnidarium_component::ActionHandler as _; - use penumbra_asset::{asset, Value}; + use penumbra_asset::asset; use penumbra_num::Amount; use penumbra_proto::StateWriteProto as _; use penumbra_sct::component::clock::EpochManager as _; use penumbra_sct::component::source::SourceContext as _; use penumbra_sct::epoch::Epoch; - use rand_core::OsRng; - - use crate::{ - lp::{position::Position, Reserves}, - DirectedTradingPair, - }; use super::*; diff --git a/crates/core/component/dex/src/component/position_manager.rs b/crates/core/component/dex/src/component/position_manager.rs index 1d90ffaefb..9854418fd6 100644 --- a/crates/core/component/dex/src/component/position_manager.rs +++ b/crates/core/component/dex/src/component/position_manager.rs @@ -7,7 +7,7 @@ use async_trait::async_trait; use cnidarium::{EscapedByteSlice, StateRead, StateWrite}; use futures::Stream; use futures::StreamExt; -use penumbra_asset::{asset, Balance, Value}; +use penumbra_asset::asset; use penumbra_num::Amount; use penumbra_proto::DomainType; use penumbra_proto::{StateReadProto, StateWriteProto}; diff --git a/crates/core/component/dex/src/component/router/tests.rs b/crates/core/component/dex/src/component/router/tests.rs index 92081a87de..81ca29dc37 100644 --- a/crates/core/component/dex/src/component/router/tests.rs +++ b/crates/core/component/dex/src/component/router/tests.rs @@ -8,6 +8,7 @@ use penumbra_num::{fixpoint::U128x128, Amount}; use rand_core::OsRng; use std::sync::Arc; +use crate::component::ValueCircuitBreaker; use crate::lp::SellOrder; use crate::DexParameters; use crate::{ @@ -988,6 +989,19 @@ async fn best_position_route_and_fill() -> anyhow::Result<()> { // Create a single 1:1 gn:penumbra position (i.e. buy 1 gn at 1 penumbra). let buy_1 = limit_buy(pair_1.clone(), 1u64.into(), 1u64.into()); state_tx.put_position(buy_1).await.unwrap(); + // TODO: later, this should be folded into an open_position method + state_tx + .vcb_credit(Value { + asset_id: gn.id(), + amount: Amount::from(1u64) * gn.unit_amount(), + }) + .await?; + state_tx + .vcb_credit(Value { + asset_id: penumbra.id(), + amount: Amount::from(1u64) * penumbra.unit_amount(), + }) + .await?; state_tx.apply(); // We should be able to call path_search and route through that position. @@ -1063,6 +1077,27 @@ async fn multi_hop_route_and_fill() -> anyhow::Result<()> { let pair_gn_gm = DirectedUnitPair::new(gn.clone(), gm.clone()); let pair_gm_penumbra = DirectedUnitPair::new(gm.clone(), penumbra.clone()); + // TEMP TODO: disable VCB for this test. Later, remove this code once we restructure + // the position manager. + let infinite_gm = Value { + asset_id: gm.id(), + amount: Amount::from(100000u128) * gm.unit_amount(), + }; + + let infinite_gn = Value { + asset_id: gn.id(), + amount: Amount::from(100000u128) * gn.unit_amount(), + }; + + let infinite_penumbra = Value { + asset_id: penumbra.id(), + amount: Amount::from(100000u128) * penumbra.unit_amount(), + }; + + state_tx.vcb_credit(infinite_gm).await?; + state_tx.vcb_credit(infinite_gn).await?; + state_tx.vcb_credit(infinite_penumbra).await?; + // Create a 2:1 penumbra:gm position (i.e. buy 20 gm at 2 penumbra each). let buy_1 = limit_buy_pq( pair_gm_penumbra.clone(), diff --git a/crates/core/component/dex/src/component/tests.rs b/crates/core/component/dex/src/component/tests.rs index 82451333f4..1aca0cf75b 100644 --- a/crates/core/component/dex/src/component/tests.rs +++ b/crates/core/component/dex/src/component/tests.rs @@ -10,6 +10,7 @@ use rand_core::OsRng; //use crate::TempStorageExt; +use crate::component::ValueCircuitBreaker as _; use crate::lp::action::PositionOpen; use crate::DexParameters; use crate::{ @@ -560,6 +561,21 @@ async fn swap_execution_tests() -> anyhow::Result<()> { let pair_gn_penumbra = DirectedUnitPair::new(gn.clone(), penumbra.clone()); + // TEMP TODO: disable VCB for this test. Later, remove this code once we restructure + // the position manager. + let infinite_gn = Value { + asset_id: gn.id(), + amount: Amount::from(100000u128) * gn.unit_amount(), + }; + + let infinite_penumbra = Value { + asset_id: penumbra.id(), + amount: Amount::from(100000u128) * penumbra.unit_amount(), + }; + + state_tx.vcb_credit(infinite_gn).await?; + state_tx.vcb_credit(infinite_penumbra).await?; + // Create a single 1:1 gn:penumbra position (i.e. buy 1 gn at 1 penumbra). let buy_1 = limit_buy(pair_gn_penumbra.clone(), 1u64.into(), 1u64.into()); state_tx.put_position(buy_1).await.unwrap(); @@ -627,6 +643,30 @@ async fn swap_execution_tests() -> anyhow::Result<()> { .get_unit("test_usd") .unwrap(); + // TEMP TODO: disable VCB for this test. Later, remove this code once we restructure + // the position manager. + let infinite_gn = Value { + asset_id: gn.id(), + amount: Amount::from(100000u128) * gn.unit_amount(), + }; + let infinite_gm = Value { + asset_id: gm.id(), + amount: Amount::from(100000u128) * gm.unit_amount(), + }; + let infinite_penumbra = Value { + asset_id: penumbra.id(), + amount: Amount::from(100000u128) * penumbra.unit_amount(), + }; + let infinite_pusd = Value { + asset_id: pusd.id(), + amount: Amount::from(100000u128) * pusd.unit_amount(), + }; + + state_tx.vcb_credit(infinite_gn).await?; + state_tx.vcb_credit(infinite_gm).await?; + state_tx.vcb_credit(infinite_penumbra).await?; + state_tx.vcb_credit(infinite_pusd).await?; + tracing::info!(gm_id = ?gm.id()); tracing::info!(gn_id = ?gn.id()); tracing::info!(pusd_id = ?pusd.id());