Skip to content

Commit 5d0911c

Browse files
1 parent 6edf9ab commit 5d0911c

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

std/src/routers/reserve.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::ops::Deref;
2+
13
use sanctum_router_core::{
24
sanctum_reserve_core::{
35
self, stake_account_record_seeds, Fee, FeeEnum, Pool, ProtocolFee, ProtocolFeeRatios,
@@ -119,3 +121,48 @@ impl<F: Fn(&[&[u8]], &[u8; 32]) -> Option<([u8; 32], u8)>> DepositStake for Rese
119121
self.reserve_deposit_stake_suf_accs(stake_addr)
120122
}
121123
}
124+
125+
/// [`ReserveRouter`] post-prefund.
126+
///
127+
/// Quotes based on state of reserve after
128+
/// a stake-acc exemption prefund operation
129+
#[derive(Debug, Clone, PartialEq)]
130+
pub struct ReserveRouterPpf<F>(pub ReserveRouter<F>);
131+
132+
impl<F> Deref for ReserveRouterPpf<F> {
133+
type Target = ReserveRouter<F>;
134+
135+
#[inline]
136+
fn deref(&self) -> &Self::Target {
137+
&self.0
138+
}
139+
}
140+
141+
impl<F: Fn(&[&[u8]], &[u8; 32]) -> Option<([u8; 32], u8)>> DepositStake for ReserveRouterPpf<F> {
142+
type Quoter<'a>
143+
= ReserveDepositStakeQuoter<'a>
144+
where
145+
F: 'a;
146+
147+
type SufAccs<'a>
148+
= ReserveDepositStakeSufAccs
149+
where
150+
F: 'a;
151+
152+
#[inline]
153+
fn deposit_stake_quoter(&self) -> Self::Quoter<'_> {
154+
let quoter = self.0.deposit_stake_quoter();
155+
quoter.after_prefund().unwrap_or(ReserveDepositStakeQuoter {
156+
// if reserve is unable to service a prefund op
157+
// then it shouldnt be able to service any other
158+
// stake deposits
159+
pool_sol_reserves: 0,
160+
..quoter
161+
})
162+
}
163+
164+
#[inline]
165+
fn deposit_stake_suf_accs(&self, dsa: &DepositStakeAddrs) -> Option<Self::SufAccs<'_>> {
166+
self.0.deposit_stake_suf_accs(dsa)
167+
}
168+
}

0 commit comments

Comments
 (0)