Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auction: process triggers/execute DAs #4254

Merged
merged 32 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
688b899
proto: extend `StateReadProto` to work on NV storage
erwanor Apr 22, 2024
a6a4cdb
num: implement `Amount::checked_mul`
erwanor Apr 22, 2024
1554e06
dex(lp): add `Position::new_with_nonce`
erwanor Apr 22, 2024
f7e5cd0
auction: implement `component::TriggerData` util
erwanor Apr 22, 2024
afd68fb
auction(schedule): extra validation of description
erwanor Apr 22, 2024
0f192a9
auction(component): first pass at dutch pricing logic
erwanor Apr 22, 2024
63f3572
auction: move old trigger height tests to `trigger_data`
erwanor Apr 22, 2024
730ac76
auction: impl `execute_dutch_auction`
erwanor Apr 22, 2024
9bac1f4
auction: handle DA triggers
erwanor Apr 22, 2024
f981a24
auction: connect component to `HandleDutchTriggers`
erwanor Apr 22, 2024
1d66fb7
auction: add missed import
erwanor Apr 22, 2024
4e2728f
auction: prototype tough nonce for positions
erwanor Apr 22, 2024
c6aaba9
auction: add comment to tough nonce prototype
erwanor Apr 22, 2024
eed3007
auction: clean up price param interpolation
erwanor Apr 23, 2024
fe2ec1e
auction: pluralize `process_trigger`
erwanor Apr 23, 2024
13f9ee7
auction: extra validation that input/output is `< 2^52`
erwanor Apr 23, 2024
cf7d54d
auction: look ahead for duplicate ids
erwanor Apr 23, 2024
e3f527c
auction: `take` input reserves to LP and zero out original state
erwanor Apr 23, 2024
6a61f5d
auction: pluralize `process_triggerS`
erwanor Apr 23, 2024
9bf7aef
auction(trigger_data): no checked operations in `compute_next..`
erwanor Apr 23, 2024
158374f
auction: process DA inclusive of `step_count`
erwanor Apr 23, 2024
203abe0
auction: restructure PCLP into `allocate_position`
erwanor Apr 23, 2024
80cc28b
auction(trigger_data): use satsub to compute delta from start
erwanor Apr 23, 2024
e79a10d
auction: interpolate with `(0, step_count - 1)`
erwanor Apr 23, 2024
6f3987a
auction: retire auction at `step_count`
erwanor Apr 23, 2024
6377bb2
auction: terminate early if input reserve is exhausted
erwanor Apr 23, 2024
a1ce6d6
auction: remove vestigial position call and todo
erwanor Apr 23, 2024
5ad6223
auction: ensure that `step_count > 1` in AH
erwanor Apr 23, 2024
c8b6af4
auction: add comment to MAX_AUCTION_AMOUNT_RESERVES`
erwanor Apr 23, 2024
bc2baed
auction: switch to `NonZeroU64` for trigger slot
erwanor Apr 23, 2024
a366ec5
auction: fold balance cumsum into reserve assignment
erwanor Apr 23, 2024
d85c02f
auction: add note about autoclose
erwanor Apr 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use penumbra_proto::{core::component::auction::v1alpha1 as pb, DomainType};
use penumbra_txhash::{EffectHash, EffectingData};
use serde::{Deserialize, Serialize};

/// The maximum amount of input/output in a Dutch auction description.
/// 52 bits gives us enough headroom to do infaillible price interpolation.
pub const MAX_AUCTION_AMOUNT_RESERVES: u128 = (1 << 52) - 1;
erwanor marked this conversation as resolved.
Show resolved Hide resolved

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(
try_from = "pb::ActionDutchAuctionSchedule",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::auction::dutch::actions::schedule::MAX_AUCTION_AMOUNT_RESERVES;
use crate::auction::dutch::DutchAuctionDescription;
use crate::component::AuctionStoreRead;
use anyhow::{ensure, Result};
use async_trait::async_trait;
use cnidarium::StateWrite;
use cnidarium_component::ActionHandler;
use penumbra_num::Amount;
use penumbra_sct::component::clock::EpochRead;

use crate::auction::dutch::ActionDutchAuctionSchedule;
Expand All @@ -24,9 +26,21 @@ impl ActionHandler for ActionDutchAuctionSchedule {
nonce: _,
} = self.description;

// Fail fast if the step count is zero
// Fail fast if the input is zero.
ensure!(
input.amount > Amount::zero(),
"input amount MUST be positive (got zero)"
);

// Fail fast if the step count is zero.
ensure!(step_count > 0, "step count MUST be positive (got zero)");

// Check that the input amount is less than 52 bits wide.
ensure!(
input.amount <= MAX_AUCTION_AMOUNT_RESERVES.into(),
"input amount MUST be less than 52 bits wide"
);

// Check that we disallow identical input/output ids.
ensure!(
input.asset_id != output_id,
Expand All @@ -42,6 +56,21 @@ impl ActionHandler for ActionDutchAuctionSchedule {
// Check that the max output is greater than zero.
ensure!(max_output > 0u128.into(), "max output MUST be positive");

// Check that the max output is less than 52 bits wide.
ensure!(
max_output <= MAX_AUCTION_AMOUNT_RESERVES.into(),
"max output amount MUST be less than 52 bits wide"
);

// Check that the min output is greater than zero.
ensure!(min_output > 0u128.into(), "min output MUST be positive");

// Check that the min output is less than 52 bits wide.
ensure!(
min_output <= MAX_AUCTION_AMOUNT_RESERVES.into(),
"min output amount MUST be less than 52 bits wide"
);

// Check that the start and end height are valid.
ensure!(
start_height < end_height,
Expand All @@ -50,16 +79,17 @@ impl ActionHandler for ActionDutchAuctionSchedule {
end_height
);

// Check that the step count is positive.
// Check that the step count is at least 2. This is important
// because DA price interpolation assumes that `step_count-1` is positive.
ensure!(
step_count > 0,
"step count MUST be greater than zero (got: {step_count})"
step_count >= 2,
"step count MUST be at least two (got: {step_count})"
);

// Check that the step count is less than 1000.
// Check that the step count is less than 255.
ensure!(
step_count <= 1000,
"the dutch auction step count MUST be less than 1000 (got: {step_count})",
step_count <= 255,
erwanor marked this conversation as resolved.
Show resolved Hide resolved
"the dutch auction step count MUST be less than 255 (got: {step_count})",
);

// Check that height delta is a multiple of `step_count`.
Expand Down
9 changes: 6 additions & 3 deletions crates/core/component/auction/src/component/auction.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::component::dutch_auction::HandleDutchTriggers;
use anyhow::Result;
use async_trait::async_trait;
use cnidarium::{StateRead, StateWrite};
Expand Down Expand Up @@ -27,11 +28,13 @@ impl Component for Auction {
) {
}

#[instrument(name = "auction", skip(_state, _end_block))]
#[instrument(name = "auction", skip(state, end_block))]
async fn end_block<S: StateWrite + 'static>(
_state: &mut Arc<S>,
_end_block: &abci::request::EndBlock,
state: &mut Arc<S>,
end_block: &abci::request::EndBlock,
) {
let state: &mut S = Arc::get_mut(state).expect("state should be unique");
let _ = state.process_triggers(end_block.height as u64).await;
}

#[instrument(name = "auction", skip(_state))]
Expand Down
Loading
Loading