Skip to content

Commit

Permalink
eliminate @penumbra-zone/constants (#1078)
Browse files Browse the repository at this point in the history
* eliminate @penumbra-zone/constants

* fmt

* fix build

* format
  • Loading branch information
Valentine1898 authored May 10, 2024
1 parent 1069c1c commit 8b9a6ea
Show file tree
Hide file tree
Showing 36 changed files with 62 additions and 202 deletions.
1 change: 0 additions & 1 deletion apps/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"@penumbra-labs/registry": "^7.0.0",
"@penumbra-zone/bech32m": "workspace:*",
"@penumbra-zone/client": "workspace:*",
"@penumbra-zone/constants": "workspace:*",
"@penumbra-zone/crypto-web": "workspace:*",
"@penumbra-zone/perspective": "workspace:*",
"@penumbra-zone/query": "workspace:*",
Expand Down
1 change: 0 additions & 1 deletion apps/minifront/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@penumbra-labs/registry": "^7.0.0",
"@penumbra-zone/bech32m": "workspace:*",
"@penumbra-zone/client": "workspace:*",
"@penumbra-zone/constants": "workspace:*",
"@penumbra-zone/crypto-web": "workspace:*",
"@penumbra-zone/getters": "workspace:*",
"@penumbra-zone/perspective": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion apps/minifront/src/components/swap/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assetPatterns } from '@penumbra-zone/constants/assets';
import { assetPatterns } from '@penumbra-zone/types/assets';
import { getBalances } from '../../fetchers/balances';
import {
getAmount,
Expand Down
2 changes: 1 addition & 1 deletion apps/minifront/src/state/ibc-out.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { toBaseUnit } from '@penumbra-zone/types/lo-hi';
import { planBuildBroadcast } from './helpers';
import { amountMoreThanBalance } from './send';
import { getAssetId } from '@penumbra-zone/getters/metadata';
import { assetPatterns } from '@penumbra-zone/constants/assets';
import { assetPatterns } from '@penumbra-zone/types/assets';
import { bech32, bech32m } from 'bech32';
import { errorToast } from '@penumbra-zone/ui/lib/toast/presets';
import { Chain } from '@penumbra-labs/registry';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import { sctClient, stakeClient, viewClient } from '../../clients';
import {
getAmount,
getValidatorIdentityKeyFromValueView,
getUnbondingStartHeightFromValueView,
getMetadata,
} from '@penumbra-zone/getters/value-view';
import { getUnbondingStartHeight } from '@penumbra-zone/types/assets';

const getUndelegateClaimPlannerRequest =
(endEpochIndex: bigint) => async (unbondingToken: ValueView) => {
const unbondingStartHeight = getUnbondingStartHeightFromValueView(unbondingToken);
const unbondingStartHeight = getUnbondingStartHeight(getMetadata(unbondingToken));
const identityKey = getValidatorIdentityKeyFromValueView(unbondingToken);
const { epoch: startEpoch } = await sctClient.epochByHeight({ height: unbondingStartHeight });

Expand Down
2 changes: 1 addition & 1 deletion apps/minifront/src/state/staking/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
ValueView,
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { BalancesByAccount, getBalancesByAccount } from '../../fetchers/balances/by-account';
import { assetPatterns } from '@penumbra-zone/constants/assets';
import { AddressIndex } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/keys/v1/keys_pb';
import { planBuildBroadcast } from '../helpers';
import {
Expand Down Expand Up @@ -40,6 +39,7 @@ import { getValueView as getValueViewFromUnbondingTokensByAddressIndexResponse }
import Array from '@penumbra-zone/polyfills/Array.fromAsync';
import { getStakingTokenMetadata } from '../../fetchers/registry';
import { zeroValueView } from '../../utils/zero-value-view';
import { assetPatterns } from '@penumbra-zone/types/assets';

interface UnbondingTokensForAccount {
claimable: {
Expand Down
8 changes: 0 additions & 8 deletions packages/constants/.eslintrc.cjs

This file was deleted.

29 changes: 0 additions & 29 deletions packages/constants/CHANGELOG.md

This file was deleted.

34 changes: 0 additions & 34 deletions packages/constants/package.json

This file was deleted.

8 changes: 0 additions & 8 deletions packages/constants/tsconfig.json

This file was deleted.

14 changes: 0 additions & 14 deletions packages/constants/vite.config.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/getters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
}
},
"dependencies": {
"@penumbra-zone/bech32m": "workspace:*",
"@penumbra-zone/constants": "workspace:*"
"@penumbra-zone/bech32m": "workspace:*"
},
"devDependencies": {
"@buf/penumbra-zone_penumbra.bufbuild_es": "1.9.0-20240501193854-ea3cc743390d.1",
Expand Down
20 changes: 1 addition & 19 deletions packages/getters/src/metadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Metadata } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { describe, expect, it } from 'vitest';
import { getDisplayDenomExponent, getUnbondingStartHeight } from './metadata';
import { getDisplayDenomExponent } from './metadata';

describe('getDisplayDenomExponent()', () => {
it("gets the exponent from the denom unit whose `denom` is equal to the metadata's `display` property", () => {
Expand All @@ -25,21 +25,3 @@ describe('getDisplayDenomExponent()', () => {
expect(getDisplayDenomExponent(penumbraMetadata)).toBe(6);
});
});

describe('getUnbondingStartHeight()', () => {
it("gets the unbonding start height, coerced to a `BigInt`, from an unbonding token's asset ID", () => {
const metadata = new Metadata({ display: 'unbonding_start_at_123_penumbravalid1abc123' });

expect(getUnbondingStartHeight(metadata)).toBe(123n);
});

it("returns `undefined` for a non-unbonding token's metadata", () => {
const metadata = new Metadata({ display: 'penumbra' });

expect(getUnbondingStartHeight.optional()(metadata)).toBeUndefined();
});

it('returns `undefined` for undefined metadata', () => {
expect(getUnbondingStartHeight.optional()(undefined)).toBeUndefined();
});
});
20 changes: 0 additions & 20 deletions packages/getters/src/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Metadata } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { createGetter } from './utils/create-getter';
import { assetPatterns } from '@penumbra-zone/constants/assets';

export const getAssetId = createGetter((metadata?: Metadata) => metadata?.penumbraAssetId);

Expand All @@ -22,25 +21,6 @@ export const getDisplayDenomExponent = createGetter(
metadata?.denomUnits.find(denomUnit => denomUnit.denom === metadata.display)?.exponent,
);

/**
* Get the unbonding start height index from the metadata of an unbonding token
* -- that is, the block height at which unbonding started.
*
* For metadata of a non-unbonding token, will return `undefined`.
*/
export const getUnbondingStartHeight = createGetter((metadata?: Metadata) => {
if (!metadata) return undefined;

const unbondingMatch = assetPatterns.unbondingToken.capture(metadata.display);

if (unbondingMatch) {
const { startAt } = unbondingMatch;
return BigInt(startAt);
}

return undefined;
});

export const getDisplay = createGetter((metadata?: Metadata) => metadata?.display);

export const getSymbol = createGetter((metadata?: Metadata) => metadata?.symbol);
8 changes: 1 addition & 7 deletions packages/getters/src/value-view.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ValueView } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { createGetter } from './utils/create-getter';
import { bech32mAssetId } from '@penumbra-zone/bech32m/passet';
import { getDisplayDenomExponent, getSymbol, getUnbondingStartHeight } from './metadata';
import { getDisplayDenomExponent, getSymbol } from './metadata';
import { Any } from '@bufbuild/protobuf';
import { ValidatorInfo } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/stake/v1/stake_pb';
import { getIdentityKeyFromValidatorInfo } from './validator-info';
Expand Down Expand Up @@ -57,12 +57,6 @@ export const getAmount = createGetter(
(valueView?: ValueView) => valueView?.valueView.value?.amount,
);

/**
* For a `ValueView` containing an unbonding token, gets the unbonding start
* height.
*/
export const getUnbondingStartHeightFromValueView = getMetadata.pipe(getUnbondingStartHeight);

export const getSymbolFromValueView = getMetadata.pipe(getSymbol);

export const getDisplayDenomFromView = createGetter((view?: ValueView) => {
Expand Down
1 change: 0 additions & 1 deletion packages/query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
},
"dependencies": {
"@penumbra-zone/bech32m": "workspace:*",
"@penumbra-zone/constants": "workspace:*",
"@penumbra-zone/crypto-web": "workspace:*",
"@penumbra-zone/getters": "workspace:*",
"@penumbra-zone/types": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/query/src/block-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { bech32mIdentityKey } from '@penumbra-zone/bech32m/penumbravalid';
import { getAssetId } from '@penumbra-zone/getters/metadata';
import { PRICE_RELEVANCE_THRESHOLDS, assetPatterns } from '@penumbra-zone/constants/assets';
import { PRICE_RELEVANCE_THRESHOLDS, assetPatterns } from '@penumbra-zone/types/assets';
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';
Expand Down
1 change: 0 additions & 1 deletion packages/services-context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
},
"dependencies": {
"@penumbra-labs/registry": "^7.0.0",
"@penumbra-zone/constants": "workspace:*",
"@penumbra-zone/query": "workspace:*",
"@penumbra-zone/storage": "workspace:*",
"@penumbra-zone/types": "workspace:*",
Expand Down
1 change: 0 additions & 1 deletion packages/services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
},
"dependencies": {
"@penumbra-zone/bech32m": "workspace:*",
"@penumbra-zone/constants": "workspace:*",
"@penumbra-zone/crypto-web": "workspace:*",
"@penumbra-zone/getters": "workspace:*",
"@penumbra-zone/perspective": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/services/src/view-service/assets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Impl } from '.';
import { servicesCtx } from '../ctx/prax';
import { assetPatterns, RegexMatcher } from '@penumbra-zone/constants/assets';
import { assetPatterns, RegexMatcher } from '@penumbra-zone/types/assets';

export const assets: Impl['assets'] = async function* (req, ctx) {
const services = await ctx.values.get(servicesCtx)();
Expand Down
2 changes: 1 addition & 1 deletion packages/services/src/view-service/auctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { balances } from './balances';
import { getDisplayDenomFromView } from '@penumbra-zone/getters/value-view';
import { ValueView } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { assetPatterns } from '@penumbra-zone/constants/assets';
import { assetPatterns } from '@penumbra-zone/types/assets';
import { Any, PartialMessage } from '@bufbuild/protobuf';
import { servicesCtx } from '../ctx/prax';
import { auctionIdFromBech32 } from '@penumbra-zone/bech32m/pauctid';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IdentityKey } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/keys/v1/keys_pb';
import Array from '@penumbra-zone/polyfills/Array.fromAsync';
import { customizeSymbol } from '@penumbra-zone/wasm/metadata';
import { assetPatterns } from '@penumbra-zone/constants/assets';
import { assetPatterns } from '@penumbra-zone/types/assets';
import { bech32mIdentityKey } from '@penumbra-zone/bech32m/penumbravalid';
import { Any, PartialMessage } from '@bufbuild/protobuf';
import { getValidatorInfo } from '@penumbra-zone/getters/validator-info-response';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb';
import { PartialMessage } from '@bufbuild/protobuf';
import { HandlerContext } from '@connectrpc/connect';
import { assetPatterns } from '@penumbra-zone/constants/assets';
import { assetPatterns } from '@penumbra-zone/types/assets';
import { getDisplayFromBalancesResponse } from '@penumbra-zone/getters/balances-response';
import { status } from '../status';
import { appParameters } from '../app-parameters';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Any } from '@bufbuild/protobuf';
import { ValidatorInfo } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/stake/v1/stake_pb';
import { stakingClientCtx } from '../../ctx/staking-client';
import { getValidatorInfo } from '@penumbra-zone/getters/get-validator-info-response';
import { assetPatterns } from '@penumbra-zone/constants/assets';
import { assetPatterns } from '@penumbra-zone/types/assets';
import {
getBalanceView,
getDisplayFromBalancesResponse,
Expand Down
1 change: 0 additions & 1 deletion packages/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"dependencies": {
"@penumbra-labs/registry": "^7.0.0",
"@penumbra-zone/bech32m": "workspace:*",
"@penumbra-zone/constants": "workspace:*",
"@penumbra-zone/crypto-web": "workspace:*",
"@penumbra-zone/getters": "workspace:*",
"idb": "^8.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/storage/src/indexed-db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
SwapRecord,
TransactionInfo,
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb';
import { assetPatterns, PRICE_RELEVANCE_THRESHOLDS } from '@penumbra-zone/constants/assets';
import { assetPatterns, PRICE_RELEVANCE_THRESHOLDS } from '@penumbra-zone/types/assets';
import { IDBPDatabase, openDB, StoreNames } from 'idb';
import { IbdUpdater, IbdUpdates } from './updater';

Expand Down
1 change: 0 additions & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
},
"dependencies": {
"@penumbra-zone/bech32m": "workspace:*",
"@penumbra-zone/constants": "workspace:*",
"@penumbra-zone/getters": "workspace:*",
"bignumber.js": "^9.1.2",
"idb": "^8.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest';
import { assetPatterns, RegexMatcher } from './assets';
import { assetPatterns, getUnbondingStartHeight, RegexMatcher } from './assets';
import { Metadata } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';

describe('assetPatterns', () => {
describe('auctionNft', () => {
Expand Down Expand Up @@ -156,3 +157,21 @@ describe('RegexMatcher', () => {
expect(matcher.capture('hello world')).toEqual(expected);
});
});

describe('getUnbondingStartHeight()', () => {
it("gets the unbonding start height, coerced to a `BigInt`, from an unbonding token's asset ID", () => {
const metadata = new Metadata({ display: 'unbonding_start_at_123_penumbravalid1abc123' });

expect(getUnbondingStartHeight(metadata)).toBe(123n);
});

it("returns `undefined` for a non-unbonding token's metadata", () => {
const metadata = new Metadata({ display: 'penumbra' });

expect(getUnbondingStartHeight(metadata)).toBeUndefined();
});

it('returns `undefined` for undefined metadata', () => {
expect(getUnbondingStartHeight(undefined)).toBeUndefined();
});
});
Loading

0 comments on commit 8b9a6ea

Please sign in to comment.