Skip to content

Commit

Permalink
Create schemas and type predicates
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepinho committed Feb 3, 2024
1 parent 3a92696 commit c4d777d
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export * from './amount';
export * from './chain';
export * from './denom-metadata';
export * from './jsonified';
export * from './type-predicates';
6 changes: 6 additions & 0 deletions packages/types/src/schemas/address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { z } from 'zod';

export const address = z.object({
inner: z.instanceof(Uint8Array),
altBech32m: z.string(),
});
7 changes: 7 additions & 0 deletions packages/types/src/schemas/asset-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { z } from 'zod';

export const assetId = z.object({
inner: z.instanceof(Uint8Array),
altBech32m: z.string(),
altBaseDenom: z.string(),
});
7 changes: 7 additions & 0 deletions packages/types/src/schemas/asset-image--theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { z } from 'zod';

export const assetImage_Theme = z.object({
primaryColorHex: z.string(),
circle: z.boolean(),
darkMode: z.boolean(),
});
8 changes: 8 additions & 0 deletions packages/types/src/schemas/asset-image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { z } from 'zod';
import { assetImage_Theme } from './asset-image--theme';

export const assetImage = z.object({
png: z.string(),
svg: z.string(),
theme: assetImage_Theme.optional(),
});
15 changes: 15 additions & 0 deletions packages/types/src/schemas/denom-metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { z } from 'zod';
import { denomUnit } from './denom-unit';
import { assetId } from './asset-id';
import { assetImage } from './asset-image';

export const denomMetadata = z.object({
description: z.string(),
denomUnits: z.array(denomUnit),
base: z.string(),
display: z.string(),
name: z.string(),
symbol: z.string(),
penumbraAssetId: assetId.optional(),
images: z.array(assetImage),
});
7 changes: 7 additions & 0 deletions packages/types/src/schemas/denom-unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { z } from 'zod';

export const denomUnit = z.object({
denom: z.string(),
exponent: z.number().int(),
aliases: z.array(z.string()),
});
25 changes: 25 additions & 0 deletions packages/types/src/type-predicates/address-view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { address } from '../schemas/address';
import { isType } from '../validation';
import { z } from 'zod';

export const hasAccountIndex = isType(
z.object({
addressView: z.object({
case: z.enum(['visible']),
value: z.object({
index: z.object({
account: z.number(),
}),
}),
}),
}),
);

export const hasAddress = isType(
z.object({
addressView: z.object({
case: z.enum(['visible', 'opaque']),
value: z.object({ address }),
}),
}),
);
2 changes: 2 additions & 0 deletions packages/types/src/type-predicates/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './address-view';
export * from './value-view';
14 changes: 14 additions & 0 deletions packages/types/src/type-predicates/value-view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { denomMetadata } from '../schemas/denom-metadata';
import { isType } from '../validation';
import { z } from 'zod';

export const hasDenomMetadata = isType(
z.object({
valueView: z.object({
case: z.enum(['knownDenom']),
value: z.object({
denom: denomMetadata,
}),
}),
}),
);

0 comments on commit c4d777d

Please sign in to comment.