Skip to content

Commit

Permalink
Remove the ability to specify which historical epoch amounts are exch…
Browse files Browse the repository at this point in the history
…anged to.
  • Loading branch information
murisi committed Jan 31, 2025
1 parent 4210a13 commit ba4d2c7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 48 deletions.
1 change: 0 additions & 1 deletion crates/apps_lib/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ async fn query_shielded_balance(
context.client(),
context.io(),
&viewing_key,
masp_epoch,
)
.await
.unwrap()
Expand Down
51 changes: 4 additions & 47 deletions crates/shielded_token/src/masp/shielded_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ pub trait ShieldedApi<U: ShieldedUtils + MaybeSend + MaybeSync>:
&'a mut self,
client: &C,
asset_type: AssetType,
target_epoch: MaspEpoch,
conversions: &'a mut Conversions,
) -> Result<(), eyre::Error> {
let btree_map::Entry::Vacant(conv_entry) =
Expand All @@ -515,33 +514,11 @@ pub trait ShieldedApi<U: ShieldedUtils + MaybeSend + MaybeSync>:
return Ok(());
};
// Get the conversion for the given asset type, otherwise fail
let Some((token, denom, position, _ep, mut conv, path)) =
let Some((_token, _denom, _position, _ep, conv, path)) =
Self::query_conversion(client, asset_type).await
else {
return Ok(());
};
// Get the equivalent to the original asset in the target epoch
let pre_asset_type = AssetData {
token,
denom,
position,
epoch: Some(target_epoch),
};
let target_asset_type = pre_asset_type
.encode()
.map_err(|_| eyre!("unable to create asset type",))?;
// Get the conversion for the target asset type. If this query returns
// None for a target_epoch that is less than or equal to the latest,
// then the token stopped participating in the rewards program before
// target_epoch. Therefore a conversion to target_epoch is the same as
// one to the latest epoch.
if let Some((_token, _denom, _position, _ep, nconv, _path)) =
Self::query_conversion(client, target_asset_type).await
{
// Subtract (conversion from target to latest) from (conversion from
// original to latest) to get (conversion from original to target).
conv -= nconv;
}
// If the conversion is 0, then we just have a pure decoding
if !conv.is_zero() {
conv_entry.insert((conv.into(), path, 0));
Expand All @@ -559,20 +536,14 @@ pub trait ShieldedApi<U: ShieldedUtils + MaybeSend + MaybeSync>:
client: &(impl Client + Sync),
io: &impl Io,
mut input: I128Sum,
target_epoch: MaspEpoch,
mut conversions: Conversions,
) -> Result<(I128Sum, Conversions), eyre::Error> {
// Where we will store our exchanged value
let mut output = I128Sum::zero();
// Repeatedly exchange assets until it is no longer possible
while let Some(asset_type) = input.asset_types().next().cloned() {
self.query_allowed_conversion(
client,
asset_type,
target_epoch,
&mut conversions,
)
.await?;
self.query_allowed_conversion(client, asset_type, &mut conversions)
.await?;
// Consolidate the current amount with any dust from output.
// Whatever is not used is moved back to output anyway.
let dust = output.project(asset_type);
Expand Down Expand Up @@ -618,18 +589,11 @@ pub trait ShieldedApi<U: ShieldedUtils + MaybeSend + MaybeSync>:
client: &(impl Client + Sync),
io: &impl Io,
vk: &ViewingKey,
target_epoch: MaspEpoch,
) -> Result<Option<I128Sum>, eyre::Error> {
// First get the unexchanged balance
if let Some(balance) = self.compute_shielded_balance(vk).await? {
let exchanged_amount = self
.compute_exchanged_amount(
client,
io,
balance,
target_epoch,
BTreeMap::new(),
)
.compute_exchanged_amount(client, io, balance, BTreeMap::new())
.await?
.0;
// And then exchange balance into current asset types
Expand Down Expand Up @@ -731,7 +695,6 @@ pub trait ShieldedApi<U: ShieldedUtils + MaybeSend + MaybeSync>:
context.client(),
context.io(),
raw_balance.to_owned(),
current_epoch,
Conversions::new(),
)
.await?
Expand Down Expand Up @@ -760,7 +723,6 @@ pub trait ShieldedApi<U: ShieldedUtils + MaybeSend + MaybeSync>:
self.query_allowed_conversion(
context.client(),
redated_asset_type,
current_epoch,
&mut latest_conversions,
)
.await?;
Expand Down Expand Up @@ -812,7 +774,6 @@ pub trait ShieldedApi<U: ShieldedUtils + MaybeSend + MaybeSync>:
context.client(),
context.io(),
current_exchanged_balance.clone(),
next_epoch,
estimated_next_epoch_conversions,
)
.await?
Expand Down Expand Up @@ -932,7 +893,6 @@ pub trait ShieldedApi<U: ShieldedUtils + MaybeSend + MaybeSync>:
spent_notes: &mut SpentNotesTracker,
sk: PseudoExtendedKey,
target: ValueSum<(MaspDigitPos, Address), i128>,
target_epoch: MaspEpoch,
) -> Result<
(
I128Sum,
Expand Down Expand Up @@ -984,7 +944,6 @@ pub trait ShieldedApi<U: ShieldedUtils + MaybeSend + MaybeSync>:
context.client(),
context.io(),
pre_contr,
target_epoch,
conversions.clone(),
)
.await?;
Expand Down Expand Up @@ -1600,7 +1559,6 @@ pub trait ShieldedApi<U: ShieldedUtils + MaybeSend + MaybeSync>:
notes_tracker,
sk,
required_amt.clone(),
epoch,
)
.await
.map_err(|e| TransferErr::General(e.to_string()))?;
Expand Down Expand Up @@ -2076,7 +2034,6 @@ mod test_shielded_wallet {
context.client(),
context.io(),
balance,
MaspEpoch::new(4),
Conversions::new(),
)
.await
Expand Down

0 comments on commit ba4d2c7

Please sign in to comment.