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

Process Dutch auction NFT metadata in the block processor #1015

Merged
merged 6 commits into from
May 2, 2024

Conversation

jessepinho
Copy link
Contributor

@jessepinho jessepinho commented Apr 30, 2024

As part of #942, I've made a massive branch with a ton of changes to the Dutch auction UI. To make the review process more manageable, I'm breaking the changes into smaller atomic PRs.

This PR modifies the block processor to identify Dutch auctions, and save their NFTs' metadata to the database when it encounters them. Future PRs will build on top of this.

@@ -52,10 +56,16 @@ interface QueryClientProps {
stakingTokenMetadata: Metadata;
}

const blankTxSource = new CommitmentSource({
const BLANK_TX_SOURCE = new CommitmentSource({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a rename to make it clear that this is a never-changing constant

source: { case: 'transaction', value: { id: new Uint8Array() } },
});

const POSITION_STATES: PositionState[] = [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort of the same here — extracting this constant from inside of a function, where it was being defined on every function call despite never changing.

@@ -361,45 +371,66 @@ export class BlockProcessor implements BlockProcessorInterface {
return spentNullifiers;
}

private async identifyLpNftPositions(txs: Transaction[]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll probably want to review the rest of this file with "Hide whitespace" turned on. In short, I:

  1. created a new processTransactions method that iterates over each transaction, then each action of each transaction, and calls this.identifyAuctionNfts() and this.identifyLpNftPositions() on each action.
  2. created a new identifyAuctioNfts() method that saves auction NFT metadata when it appears.
  3. modified identifyLpNftPositions() to process individual actions, rather than processing an array of transactions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this a great design choice as it's extensible to other metadata-related processing we'll need to do in the future!

@erwanor erwanor self-requested a review April 30, 2024 21:12
@@ -73,21 +83,32 @@ mod test_helpers {

use super::*;

pub fn get_metadata_for(display_denom: &str) -> Metadata {
pub fn get_metadata_for(display_denom: &str, base_denom_is_display_denom: bool) -> Metadata {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a test helper. Auction NFTs only have one denom unit, so the base denom is the same as the display denom. So I added this arg to this function so that I can generate the right type of metadata for auction NFTs as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smooth brain question: is it ever the case that a base denom is not the display denom?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah — the display denom is the one you see in the UI (e.g., "penumbra") but the base denom is the smallest possible unit (e.g., "upenumbra"). Usually they're different, just like US dollars and cents are different, but auction NFTs apparently only have a single denom unit — which makes sense, since you'll never hold more than 1 NFT for a given auction.

@jessepinho jessepinho force-pushed the jessepinho/block-processor-auctions-web-942 branch from 698e062 to be1d9e5 Compare April 30, 2024 21:16
@jessepinho jessepinho changed the title WIP: Process Dutch auctions in the block processor WIP: Process Dutch auction NFT metadata in the block processor Apr 30, 2024
@TalDerei TalDerei self-requested a review April 30, 2024 22:02
@jessepinho jessepinho marked this pull request as ready for review April 30, 2024 22:38
@jessepinho jessepinho changed the title WIP: Process Dutch auction NFT metadata in the block processor Process Dutch auction NFT metadata in the block processor Apr 30, 2024
@@ -101,7 +101,7 @@ impl ActionList {
for value in self.balance().provided() {
self.change_outputs.insert(
value.asset_id,
OutputPlan::new(&mut OsRng, value, change_address),
OutputPlan::new(&mut OsRng, value, change_address.clone()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I saw something about removing Copy from Address, this would explain why it's moved all the sudden

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, cloning is the right thing to do here. LGTM.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah was getting lot of these copy errors too without cloning

@@ -73,21 +83,32 @@ mod test_helpers {

use super::*;

pub fn get_metadata_for(display_denom: &str) -> Metadata {
pub fn get_metadata_for(display_denom: &str, base_denom_is_display_denom: bool) -> Metadata {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smooth brain question: is it ever the case that a base denom is not the display denom?

const auctionId = getAuctionId(action.value.description);
const metadata = getAuctionNftMetadata(
auctionId,
// Always a sequence number of 0 when starting a Dutch auction
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

} else if (action.case === 'actionDutchAuctionEnd' && action.value.auctionId) {
const metadata = getAuctionNftMetadata(
action.value.auctionId,
// Always a sequence number of 1 when ending a Dutch auction
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
/**
* @todo Handle `actionDutchAuctionWithdraw`, and figure out how to
* determine the sequence number if there have been multiple withdrawals.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one way to do that is to structure the Action['action'] with a sequence number, rather than adding it ex-post in this method, unsure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks, added a link to this comment in the ticket (#1020)

@@ -361,45 +371,66 @@ export class BlockProcessor implements BlockProcessorInterface {
return spentNullifiers;
}

private async identifyLpNftPositions(txs: Transaction[]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this a great design choice as it's extensible to other metadata-related processing we'll need to do in the future!

@@ -261,7 +271,7 @@ export class BlockProcessor implements BlockProcessorInterface {
// - detect LpNft position opens
// - generate all possible position state metadata
// - update idb
await this.identifyLpNftPositions(blockTx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we update the description above processTransactions(blockTx) to accurately describe this function? Can we also move these existing comments to identifyLpNftPositions() and add comments to identifyAuctionNfts().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, good catch — fixed.

penumbra-stake = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.73.0", package = "penumbra-stake", default-features = false }
penumbra-tct = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.73.0", package = "penumbra-tct" }
penumbra-transaction = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.73.0", package = "penumbra-transaction", default-features = false }
# TODO: Use `tag` instead of `rev` once auctions land in a tagged release of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -101,7 +101,7 @@ impl ActionList {
for value in self.balance().provided() {
self.change_outputs.insert(
value.asset_id,
OutputPlan::new(&mut OsRng, value, change_address),
OutputPlan::new(&mut OsRng, value, change_address.clone()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah was getting lot of these copy errors too without cloning

@TalDerei
Copy link
Contributor

TalDerei commented May 2, 2024

save their NFTs' metadata to the database

we're currently only saving the auction metadata to the ASSETS table in indexed-db, where the assetId is used as a key for the table.

can you create a separate issue in the tracking issue for that builds on this? ie. creating a auction state table which stores the auction id and note commitment?

@TalDerei
Copy link
Contributor

TalDerei commented May 2, 2024

The functionality seems to be all here, LGTM!

@jessepinho
Copy link
Contributor Author

@TalDerei

can you create a separate issue in the tracking issue for that builds on this?

Yeah, that's covered by #980. I didn't specifically fill in the details since I know I'll be working on it myself anyway (plus I'll be referencing the pairing doc you created).

@jessepinho jessepinho merged commit a9cb099 into main May 2, 2024
6 checks passed
@jessepinho jessepinho deleted the jessepinho/block-processor-auctions-web-942 branch May 2, 2024 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants