-
Notifications
You must be signed in to change notification settings - Fork 17
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
Remove deprecated position state #763
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,11 @@ | ||
import { ScanBlockResult } from './state-commitment-tree'; | ||
import { CompactBlock } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/compact_block/v1/compact_block_pb'; | ||
import { MerkleRoot } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/crypto/tct/v1/tct_pb'; | ||
import { Metadata } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb'; | ||
import { | ||
Position, | ||
PositionState, | ||
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/dex/v1/dex_pb'; | ||
|
||
export interface ViewServerInterface { | ||
fullViewingKey: string; | ||
scanBlock(compactBlock: CompactBlock): Promise<boolean>; | ||
flushUpdates(): ScanBlockResult; | ||
resetTreeToStored(): Promise<void>; | ||
getSctRoot(): MerkleRoot; | ||
getLpNftMetadata(position: Position, positionState: PositionState): Metadata; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
use std::convert::TryInto; | ||
use std::{collections::BTreeMap, str::FromStr}; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use serde_wasm_bindgen::Error; | ||
use serde_wasm_bindgen::Serializer; | ||
use wasm_bindgen::prelude::wasm_bindgen; | ||
use wasm_bindgen::JsValue; | ||
|
||
use penumbra_asset::asset::{Id, Metadata}; | ||
use penumbra_compact_block::{CompactBlock, StatePayload}; | ||
use penumbra_dex::lp::position::Position; | ||
use penumbra_dex::lp::LpNft; | ||
use penumbra_keys::FullViewingKey; | ||
use penumbra_sct::Nullifier; | ||
use penumbra_shielded_pool::note; | ||
use penumbra_tct as tct; | ||
use penumbra_tct::Witness::*; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_wasm_bindgen::Error; | ||
use serde_wasm_bindgen::Serializer; | ||
use tct::storage::{StoreCommitment, StoreHash, StoredPosition, Updates}; | ||
use tct::{Forgotten, Tree}; | ||
use wasm_bindgen::prelude::wasm_bindgen; | ||
use wasm_bindgen::JsValue; | ||
|
||
use crate::error::WasmResult; | ||
use crate::note_record::SpendableNoteRecord; | ||
|
@@ -304,26 +301,6 @@ impl ViewServer { | |
let root = self.sct.root(); | ||
serde_wasm_bindgen::to_value(&root) | ||
} | ||
|
||
/// get LP NFT asset | ||
/// Arguments: | ||
/// position_value: `lp::position::Position` | ||
/// position_state_value: `lp::position::State` | ||
/// Returns: `DenomMetadata` | ||
#[wasm_bindgen] | ||
pub fn get_lpnft_asset( | ||
&mut self, | ||
position_value: JsValue, | ||
position_state_value: JsValue, | ||
) -> Result<JsValue, Error> { | ||
utils::set_panic_hook(); | ||
|
||
let position: Position = serde_wasm_bindgen::from_value(position_value)?; | ||
let position_state = serde_wasm_bindgen::from_value(position_state_value)?; | ||
let lp_nft = LpNft::new(position.id(), position_state); | ||
let denom = lp_nft.denom(); | ||
serde_wasm_bindgen::to_value(&denom) | ||
} | ||
Comment on lines
-313
to
-326
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not part of the view server actually, moved to dex.rs |
||
} | ||
|
||
pub fn load_tree(stored_tree: StoredTree) -> Tree { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
import { compute_position_id } from '../wasm'; | ||
import { compute_position_id, get_lpnft_asset } from '../wasm'; | ||
import { | ||
Position, | ||
PositionId, | ||
PositionState, | ||
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/dex/v1/dex_pb'; | ||
import { Metadata } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb'; | ||
import { JsonValue } from '@bufbuild/protobuf'; | ||
|
||
export const computePositionId = (position: Position): PositionId => { | ||
const result = compute_position_id(position.toJson()) as unknown; | ||
return PositionId.fromJsonString(JSON.stringify(result)); | ||
}; | ||
|
||
export const getLpNftMetadata = ( | ||
positionId: PositionId, | ||
positionState: PositionState, | ||
): Metadata => { | ||
const result = get_lpnft_asset(positionId.toJson(), positionState.toJson()) as JsonValue; | ||
return Metadata.fromJsonString(JSON.stringify(result)); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have to stringify? Can we not do:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, it works without stringify |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now
getLpNftMetadata()
only requiresPositionId
, notPosition
. This makes its use more versatile