Skip to content

Commit

Permalink
Extract more helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepinho committed May 14, 2024
1 parent f6cc1aa commit 011452e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 28 deletions.
37 changes: 9 additions & 28 deletions packages/query/src/block-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ import { PRICE_RELEVANCE_THRESHOLDS, assetPatterns } from '@penumbra-zone/types/
import { toDecimalExchangeRate } from '@penumbra-zone/types/amount';
import { ValidatorInfoResponse } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/stake/v1/stake_pb';
import { uint8ArrayToHex } from '@penumbra-zone/types/hex';
import { getAuctionId, getAuctionNftMetadata } from '@penumbra-zone/wasm/auction';
import { AuctionId } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/auction/v1alpha1/auction_pb';
import { auctionIdFromBech32 } from '@penumbra-zone/bech32m/pauctid';
import { ScanBlockResult } from '@penumbra-zone/types/state-commitment-tree';
import { processActionDutchAuctionEnd } from './helpers/process-action-dutch-auction-end';
import { processActionDutchAuctionSchedule } from './helpers/process-action-dutch-auction-schedule';
import { processActionDutchAuctionWithdraw } from './helpers/process-action-dutch-auction-withdraw';

declare global {
// `var` required for global declaration (as let/const are block scoped)
Expand Down Expand Up @@ -419,35 +420,15 @@ export class BlockProcessor implements BlockProcessorInterface {
*/
private async identifyAuctionNfts(action: Action['action']) {
if (action.case === 'actionDutchAuctionSchedule' && action.value.description) {
const auctionId = getAuctionId(action.value.description);

// Always a sequence number of 0 when starting a Dutch auction
const seqNum = 0n;

const metadata = getAuctionNftMetadata(auctionId, seqNum);

await Promise.all([
this.indexedDb.saveAssetsMetadata(metadata),
this.indexedDb.upsertAuction(auctionId, {
auction: action.value.description,
seqNum,
}),
]);
await processActionDutchAuctionSchedule(action.value.description, this.indexedDb);
} else if (action.case === 'actionDutchAuctionEnd' && action.value.auctionId) {
await processActionDutchAuctionEnd(action.value, this.querier.auction, this.indexedDb);
} else if (action.case === 'actionDutchAuctionWithdraw') {
const auctionId = action.value.auctionId;
if (!auctionId) return;

const metadata = getAuctionNftMetadata(auctionId, action.value.seq);

await Promise.all([
this.indexedDb.saveAssetsMetadata(metadata),
this.indexedDb.upsertAuction(auctionId, {
seqNum: action.value.seq,
outstandingReserves: undefined,
}),
]);
} else if (action.case === 'actionDutchAuctionWithdraw' && action.value.auctionId) {
await processActionDutchAuctionWithdraw(
action.value.auctionId,
action.value.seq,
this.indexedDb,
);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { DutchAuctionDescription } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/auction/v1alpha1/auction_pb';
import { IndexedDbInterface } from '@penumbra-zone/types/indexed-db';
import { getAuctionId, getAuctionNftMetadata } from '@penumbra-zone/wasm/auction';

export const processActionDutchAuctionSchedule = async (
description: DutchAuctionDescription,
indexedDb: IndexedDbInterface,
) => {
const auctionId = getAuctionId(description);

// Always a sequence number of 0 when starting a Dutch auction
const seqNum = 0n;

const metadata = getAuctionNftMetadata(auctionId, seqNum);

await Promise.all([
indexedDb.saveAssetsMetadata(metadata),
indexedDb.upsertAuction(auctionId, {
auction: description,
seqNum,
}),
]);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { AuctionId } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/auction/v1alpha1/auction_pb';
import { IndexedDbInterface } from '@penumbra-zone/types/indexed-db';
import { getAuctionNftMetadata } from '@penumbra-zone/wasm/auction';

export const processActionDutchAuctionWithdraw = async (
auctionId: AuctionId,
seqNum: bigint,
indexedDb: IndexedDbInterface,
) => {
const metadata = getAuctionNftMetadata(auctionId, seqNum);

await Promise.all([
indexedDb.saveAssetsMetadata(metadata),
indexedDb.upsertAuction(auctionId, {
seqNum,
outstandingReserves: undefined,
}),
]);
};

0 comments on commit 011452e

Please sign in to comment.