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(planner): add actions to planner #4248

Merged
merged 4 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/view/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ penumbra-shielded-pool = {workspace = true, default-features = false}
penumbra-stake = {workspace = true, default-features = false}
penumbra-tct = {workspace = true, default-features = true}
penumbra-transaction = {workspace = true, default-features = true}
penumbra-auction = {workspace = true, default-features = true}
prost = {workspace = true}
r2d2 = {workspace = true}
r2d2_sqlite = {workspace = true, features = ["bundled"]}
Expand Down
62 changes: 62 additions & 0 deletions crates/view/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ use rand::{CryptoRng, RngCore};
use tracing::instrument;

use penumbra_asset::{asset, Balance, Value, STAKING_TOKEN_ASSET_ID};
use penumbra_auction::auction::dutch::actions::ActionDutchAuctionWithdrawPlan;
use penumbra_auction::auction::dutch::DutchAuctionDescription;
use penumbra_auction::auction::{
dutch::actions::{ActionDutchAuctionEnd, ActionDutchAuctionSchedule},
AuctionId,
};
use penumbra_community_pool::CommunityPoolDeposit;
use penumbra_dex::{
lp::action::{PositionClose, PositionOpen},
Expand Down Expand Up @@ -465,6 +471,62 @@ impl<R: RngCore + CryptoRng> Planner<R> {
self
}

/// Initiates a Dutch auction using protocol-controlled liquidity.
#[instrument(skip(self))]
pub fn dutch_auction_schedule(
&mut self,
input: Value,
output_id: asset::Id,
max_output: Amount,
min_output: Amount,
start_height: u64,
end_height: u64,
step_count: u64,
nonce: [u8; 32],
) -> &mut Self {
self.action(ActionPlan::ActionDutchAuctionSchedule(
ActionDutchAuctionSchedule {
description: DutchAuctionDescription {
input,
output_id,
max_output,
min_output,
start_height,
end_height,
step_count,
nonce,
},
},
))
}

/// Ends a Dutch auction using protocol-controlled liquidity.
#[instrument(skip(self))]
pub fn dutch_auction_end(&mut self, auction_id: AuctionId) -> &mut Self {
self.action(ActionPlan::ActionDutchAuctionEnd(ActionDutchAuctionEnd {
auction_id,
}))
}

/// Withdraws the reserves of the Dutch auction.
#[instrument(skip(self))]
pub fn dutch_auction_withdraw(
&mut self,
auction_id: AuctionId,
seq: u64,
reserves_input: Value,
reserves_output: Value,
) -> &mut Self {
self.action(ActionPlan::ActionDutchAuctionWithdraw(
ActionDutchAuctionWithdrawPlan {
auction_id,
seq,
reserves_input,
reserves_output,
},
))
}

fn action(&mut self, action: ActionPlan) -> &mut Self {
// Track the contribution of the action to the transaction's balance
self.balance += action.balance();
Expand Down
Loading