Skip to content

Commit

Permalink
auction(planner): add actions to planner (#4248)
Browse files Browse the repository at this point in the history
## Describe your changes
Add planner support for auctions

## Issue ticket number and link
References #4241

## Checklist before requesting a review

- [x] If this code contains consensus-breaking changes, I have added the
"consensus-breaking" label. Otherwise, I declare my belief that there
are not consensus-breaking changes, for the following reason:

---------

Signed-off-by: Tal Derei <70081547+TalDerei@users.noreply.github.com>
Co-authored-by: Erwan Or <erwan.ounn.84@gmail.com>
  • Loading branch information
TalDerei and erwanor authored Apr 20, 2024
1 parent 514d30b commit b7da9ec
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
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

0 comments on commit b7da9ec

Please sign in to comment.