Skip to content

Commit

Permalink
feat(query): update block processor to include subaccounts into LPs (#…
Browse files Browse the repository at this point in the history
…279)

* feat(query): update block processor to include subaccounts into LPs

* refactor(query): use `isControlledAddress` as it was before

* chore: update deps

* fix(query): update tests
  • Loading branch information
VanishMax authored Jan 30, 2025
1 parent 89adf40 commit 7bcf54d
Show file tree
Hide file tree
Showing 9 changed files with 367 additions and 285 deletions.
20 changes: 10 additions & 10 deletions apps/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
"@bufbuild/protobuf": "^1.x",
"@connectrpc/connect": "^1.x",
"@connectrpc/connect-web": "^1.x",
"@penumbra-labs/registry": "^12.1.0",
"@penumbra-zone/bech32m": "11.0.0",
"@penumbra-labs/registry": "^12.1.1",
"@penumbra-zone/bech32m": "12.0.0",
"@penumbra-zone/client": "22.0.0",
"@penumbra-zone/crypto-web": "33.0.0",
"@penumbra-zone/getters": "21.0.0",
"@penumbra-zone/crypto-web": "34.0.0",
"@penumbra-zone/getters": "22.0.0",
"@penumbra-zone/keys": "4.2.1",
"@penumbra-zone/perspective": "44.0.0",
"@penumbra-zone/protobuf": "7.0.0",
"@penumbra-zone/perspective": "45.0.0",
"@penumbra-zone/protobuf": "7.1.0",
"@penumbra-zone/query": "workspace:*",
"@penumbra-zone/services": "49.0.0",
"@penumbra-zone/storage": "44.0.0",
"@penumbra-zone/services": "50.0.0",
"@penumbra-zone/storage": "45.0.0",
"@penumbra-zone/transport-chrome": "8.0.1",
"@penumbra-zone/transport-dom": "7.5.0",
"@penumbra-zone/types": "27.1.0",
"@penumbra-zone/wasm": "37.1.0",
"@penumbra-zone/types": "28.0.0",
"@penumbra-zone/wasm": "38.0.0",
"@radix-ui/react-icons": "^1.3.2",
"@repo/context": "workspace:*",
"@repo/ui": "workspace:*",
Expand Down
20 changes: 10 additions & 10 deletions packages/context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@
},
"peerDependencies": {
"@bufbuild/protobuf": "^1.x",
"@penumbra-labs/registry": "^12.1.0",
"@penumbra-zone/bech32m": "11.0.0",
"@penumbra-zone/crypto-web": "33.0.0",
"@penumbra-zone/getters": "21.0.0",
"@penumbra-labs/registry": "^12.1.1",
"@penumbra-zone/bech32m": "12.0.0",
"@penumbra-zone/crypto-web": "34.0.0",
"@penumbra-zone/getters": "22.0.0",
"@penumbra-zone/keys": "4.2.1",
"@penumbra-zone/perspective": "44.0.0",
"@penumbra-zone/protobuf": "7.0.0",
"@penumbra-zone/perspective": "45.0.0",
"@penumbra-zone/protobuf": "7.1.0",
"@penumbra-zone/query": "workspace:*",
"@penumbra-zone/services": "49.0.0",
"@penumbra-zone/storage": "44.0.0",
"@penumbra-zone/services": "50.0.0",
"@penumbra-zone/storage": "45.0.0",
"@penumbra-zone/transport-chrome": "8.0.1",
"@penumbra-zone/transport-dom": "7.5.0",
"@penumbra-zone/types": "27.1.0",
"@penumbra-zone/wasm": "37.1.0",
"@penumbra-zone/types": "28.0.0",
"@penumbra-zone/wasm": "38.0.0",
"exponential-backoff": "^3.1.1"
}
}
6 changes: 3 additions & 3 deletions packages/noble/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
},
"dependencies": {
"@cosmjs/stargate": "^0.32.4",
"@penumbra-zone/bech32m": "11.0.0",
"@penumbra-zone/protobuf": "7.0.0",
"@penumbra-zone/wasm": "37.1.0"
"@penumbra-zone/bech32m": "12.0.0",
"@penumbra-zone/protobuf": "7.1.0",
"@penumbra-zone/wasm": "38.0.0"
}
}
12 changes: 6 additions & 6 deletions packages/query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
"@bufbuild/protobuf": "^1.x",
"@connectrpc/connect": "^1.x",
"@connectrpc/connect-web": "^1.x",
"@penumbra-zone/bech32m": "11.0.0",
"@penumbra-zone/crypto-web": "33.0.0",
"@penumbra-zone/getters": "21.0.0",
"@penumbra-zone/protobuf": "7.0.0",
"@penumbra-zone/types": "27.1.0",
"@penumbra-zone/wasm": "37.1.0",
"@penumbra-zone/bech32m": "12.0.0",
"@penumbra-zone/crypto-web": "34.0.0",
"@penumbra-zone/getters": "22.0.0",
"@penumbra-zone/protobuf": "7.1.0",
"@penumbra-zone/types": "28.0.0",
"@penumbra-zone/wasm": "38.0.0",
"exponential-backoff": "^3.1.1"
},
"engine": {
Expand Down
23 changes: 14 additions & 9 deletions packages/query/src/block-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { processActionDutchAuctionEnd } from './helpers/process-action-dutch-auc
import { processActionDutchAuctionSchedule } from './helpers/process-action-dutch-auction-schedule';
import { processActionDutchAuctionWithdraw } from './helpers/process-action-dutch-auction-withdraw';
import { RootQuerier } from './root-querier';
import { IdentityKey } from '@penumbra-zone/protobuf/penumbra/core/keys/v1/keys_pb';
import { AddressIndex, IdentityKey } from '@penumbra-zone/protobuf/penumbra/core/keys/v1/keys_pb';
import { getDelegationTokenMetadata } from '@penumbra-zone/wasm/stake';
import { toPlainMessage } from '@bufbuild/protobuf';
import { getAssetIdFromGasPrices } from '@penumbra-zone/getters/compact-block';
Expand Down Expand Up @@ -309,7 +309,7 @@ export class BlockProcessor implements BlockProcessorInterface {

// if a new record involves a state commitment, scan all block tx
if (spentNullifiers.size || recordsByCommitment.size) {
// this is a network query
// compact block doesn't store transactions data, this query request it by rpc call
const blockTx = await this.querier.app.txsByHeight(compactBlock.height);

// Filter down to transactions & note records in block relevant to user
Expand Down Expand Up @@ -494,7 +494,7 @@ export class BlockProcessor implements BlockProcessorInterface {

// Nullifier is published in network when a note is spent or swap is claimed.
private async resolveNullifiers(nullifiers: Nullifier[], height: bigint) {
const spentNullifiers = new Set<Nullifier>();
const spentNullifiers = new Map<Nullifier, SpendableNoteRecord | SwapRecord>();
const readOperations = [];
const writeOperations = [];

Expand All @@ -518,8 +518,6 @@ export class BlockProcessor implements BlockProcessorInterface {
continue;
}

spentNullifiers.add(nullifier);

if (record instanceof SpendableNoteRecord) {
record.heightSpent = height;
const writePromise = this.indexedDb.saveSpendableNote({
Expand All @@ -535,6 +533,8 @@ export class BlockProcessor implements BlockProcessorInterface {
});
writeOperations.push(writePromise);
}

spentNullifiers.set(nullifier, record);
}

// Await all writes in parallel
Expand All @@ -548,9 +548,12 @@ export class BlockProcessor implements BlockProcessorInterface {
* such as metadata, liquidity positions, etc.
*/
private async processTransactions(txs: RelevantTx[]) {
for (const { data } of txs) {
for (const { data, subaccount } of txs) {
for (const { action } of data.body?.actions ?? []) {
await Promise.all([this.identifyAuctionNfts(action), this.identifyLpNftPositions(action)]);
await Promise.all([
this.identifyAuctionNfts(action),
this.identifyLpNftPositions(action, subaccount),
]);
}
}
}
Expand Down Expand Up @@ -582,7 +585,7 @@ export class BlockProcessor implements BlockProcessorInterface {
* - generate all possible position state metadata
* - update idb
*/
private async identifyLpNftPositions(action: Action['action']) {
private async identifyLpNftPositions(action: Action['action'], subaccount?: AddressIndex) {
if (action.case === 'positionOpen' && action.value.position) {
for (const state of POSITION_STATES) {
const metadata = getLpNftMetadata(computePositionId(action.value.position), state);
Expand All @@ -597,12 +600,14 @@ export class BlockProcessor implements BlockProcessorInterface {
await this.indexedDb.addPosition(
computePositionId(action.value.position),
action.value.position,
subaccount,
);
}
if (action.case === 'positionClose' && action.value.positionId) {
await this.indexedDb.updatePosition(
action.value.positionId,
new PositionState({ state: PositionState_PositionStateEnum.CLOSED }),
subaccount,
);
}
if (action.case === 'positionWithdraw' && action.value.positionId) {
Expand All @@ -618,7 +623,7 @@ export class BlockProcessor implements BlockProcessorInterface {
penumbraAssetId: getAssetId(metadata),
});

await this.indexedDb.updatePosition(action.value.positionId, positionState);
await this.indexedDb.updatePosition(action.value.positionId, positionState, subaccount);
}
}

Expand Down
Loading

0 comments on commit 7bcf54d

Please sign in to comment.