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

Support PositionClose within the planner #2269

Merged
merged 2 commits into from
Mar 28, 2023
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
2 changes: 1 addition & 1 deletion proto/proto/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ deps:
- remote: buf.build
owner: cosmos
repository: cosmos-sdk
commit: c45ce7be3e1c4556a8fe3c045379277c
commit: 172f6ce4e9054eb4af8b96e8131da354
- remote: buf.build
owner: cosmos
repository: gogo-proto
Expand Down
3 changes: 3 additions & 0 deletions transaction/src/effect_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ impl TransactionPlan {
for position_open in self.position_openings() {
state.update(position_open.effect_hash().as_bytes());
}
for position_close in self.position_closings() {
state.update(position_close.effect_hash().as_bytes());
}
let num_clues = self.clue_plans.len() as u32;
state.update(&num_clues.to_le_bytes());
for clue_plan in self.clue_plans() {
Expand Down
14 changes: 12 additions & 2 deletions transaction/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use rand::{CryptoRng, Rng};
use serde::{Deserialize, Serialize};

use crate::action::{
DaoDeposit, DaoOutput, DaoSpend, Delegate, IbcAction, PositionOpen, ProposalDepositClaim,
ProposalSubmit, ProposalWithdraw, Undelegate, ValidatorVote,
DaoDeposit, DaoOutput, DaoSpend, Delegate, IbcAction, PositionClose, PositionOpen,
ProposalDepositClaim, ProposalSubmit, ProposalWithdraw, Undelegate, ValidatorVote,
};

mod action;
Expand Down Expand Up @@ -226,6 +226,16 @@ impl TransactionPlan {
})
}

pub fn position_closings(&self) -> impl Iterator<Item = &PositionClose> {
self.actions.iter().filter_map(|action| {
if let ActionPlan::PositionClose(v) = action {
Some(v)
} else {
None
}
})
}

/// Convenience method to get all the destination addresses for each `OutputPlan`s.
pub fn dest_addresses(&self) -> Vec<Address> {
self.output_plans()
Expand Down
6 changes: 6 additions & 0 deletions transaction/src/plan/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ impl TransactionPlan {
for position_open in self.position_openings().cloned() {
actions.push(Action::PositionOpen(position_open))
}
for position_close in self.position_closings().cloned() {
actions.push(Action::PositionClose(position_close))
}

let transaction_body = TransactionBody {
actions,
Expand Down Expand Up @@ -355,6 +358,9 @@ impl TransactionPlan {
for position_open in self.position_openings().cloned() {
actions.push(Action::PositionOpen(position_open))
}
for position_close in self.position_closings().cloned() {
actions.push(Action::PositionClose(position_close))
}

let transaction_body = TransactionBody {
actions,
Expand Down
14 changes: 12 additions & 2 deletions transaction/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use serde::{Deserialize, Serialize};

use crate::{
action::{
DaoDeposit, DaoOutput, DaoSpend, Delegate, DelegatorVote, IbcAction, Output, PositionOpen,
ProposalSubmit, ProposalWithdraw, Spend, Swap, Undelegate, ValidatorVote,
DaoDeposit, DaoOutput, DaoSpend, Delegate, DelegatorVote, IbcAction, Output, PositionClose,
PositionOpen, ProposalSubmit, ProposalWithdraw, Spend, Swap, Undelegate, ValidatorVote,
},
view::{action_view::OutputView, MemoView, TransactionBodyView},
Action, ActionView, Id, IsAction, TransactionPerspective, TransactionView,
Expand Down Expand Up @@ -362,6 +362,16 @@ impl Transaction {
})
}

pub fn position_closings(&self) -> impl Iterator<Item = &PositionClose> {
self.actions().filter_map(|action| {
if let Action::PositionClose(d) = action {
Some(d)
} else {
None
}
})
}

pub fn transaction_body(&self) -> TransactionBody {
self.transaction_body.clone()
}
Expand Down
13 changes: 11 additions & 2 deletions view/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use penumbra_proto::view::v1alpha1::{NotesForVotingRequest, NotesRequest};
use penumbra_tct as tct;
use penumbra_transaction::{
action::{
DaoDeposit, PositionOpen, Proposal, ProposalDepositClaim, ProposalSubmit, ProposalWithdraw,
ValidatorVote, Vote,
DaoDeposit, PositionClose, PositionOpen, Proposal, ProposalDepositClaim, ProposalSubmit,
ProposalWithdraw, ValidatorVote, Vote,
},
plan::{
ActionPlan, DelegatorVotePlan, MemoPlan, OutputPlan, SpendPlan, SwapClaimPlan, SwapPlan,
Expand Down Expand Up @@ -164,6 +164,15 @@ impl<R: RngCore + CryptoRng> Planner<R> {
self
}

/// Close a liquidity position in the order book.
#[instrument(skip(self))]
pub fn position_close(&mut self, position: Position) -> &mut Self {
self.action(ActionPlan::PositionClose(PositionClose {
position_id: position.id(),
}));
self
}

/// Perform a swap claim based on an input swap NFT with a pre-paid fee.
#[instrument(skip(self))]
pub fn swap_claim(&mut self, plan: SwapClaimPlan) -> &mut Self {
Expand Down