explorer: Update superstruct (#15835)
This commit is contained in:
parent
5b2da19c93
commit
186b342453
|
@ -17746,8 +17746,9 @@
|
|||
"integrity": "sha512-OFFeUXFgwnGOKvEXaSv0D0KQ5ADP0n6g3SVONx6I/85JzNZ3u50FRwB3lVIk1QO2HNdI75tbVzc4Z66Gdp9voA=="
|
||||
},
|
||||
"superstruct": {
|
||||
"version": "github:solana-labs/superstruct#3425dfd28967286ac9d1c78ce7b3c07c5781caee",
|
||||
"from": "github:solana-labs/superstruct"
|
||||
"version": "0.14.2",
|
||||
"resolved": "https://registry.npmjs.org/superstruct/-/superstruct-0.14.2.tgz",
|
||||
"integrity": "sha512-nPewA6m9mR3d6k7WkZ8N8zpTWfenFH3q9pA2PkuiZxINr9DKB2+40wEQf0ixn8VaGuJ78AB6iWOtStI+/4FKZQ=="
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "5.5.0",
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
"react-router-dom": "^5.2.0",
|
||||
"react-scripts": "^4.0.3",
|
||||
"react-select": "^4.2.1",
|
||||
"superstruct": "github:solana-labs/superstruct",
|
||||
"superstruct": "^0.14.2",
|
||||
"typescript": "^4.2.3"
|
||||
},
|
||||
"scripts": {
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
TokenAccountInfo,
|
||||
MultisigAccountInfo,
|
||||
} from "validators/accounts/token";
|
||||
import { coerce } from "superstruct";
|
||||
import { create } from "superstruct";
|
||||
import { TableCardBody } from "components/common/TableCardBody";
|
||||
import { Address } from "components/common/Address";
|
||||
import { UnknownAccountCard } from "./UnknownAccountCard";
|
||||
|
@ -27,15 +27,15 @@ export function TokenAccountSection({
|
|||
try {
|
||||
switch (tokenAccount.type) {
|
||||
case "mint": {
|
||||
const info = coerce(tokenAccount.info, MintAccountInfo);
|
||||
const info = create(tokenAccount.info, MintAccountInfo);
|
||||
return <MintAccountCard account={account} info={info} />;
|
||||
}
|
||||
case "account": {
|
||||
const info = coerce(tokenAccount.info, TokenAccountInfo);
|
||||
const info = create(tokenAccount.info, TokenAccountInfo);
|
||||
return <TokenAccountCard account={account} info={info} />;
|
||||
}
|
||||
case "multisig": {
|
||||
const info = coerce(tokenAccount.info, MultisigAccountInfo);
|
||||
const info = create(tokenAccount.info, MultisigAccountInfo);
|
||||
return <MultisigAccountCard account={account} info={info} />;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import {
|
|||
useFetchTransactionDetails,
|
||||
useTransactionDetailsCache,
|
||||
} from "providers/transactions/details";
|
||||
import { coerce } from "superstruct";
|
||||
import { create } from "superstruct";
|
||||
import { ParsedInfo } from "validators";
|
||||
import {
|
||||
TokenInstructionType,
|
||||
|
@ -366,9 +366,9 @@ function instructionTypeName(
|
|||
tx: ConfirmedSignatureInfo
|
||||
): string {
|
||||
try {
|
||||
const parsed = coerce(ix.parsed, ParsedInfo);
|
||||
const parsed = create(ix.parsed, ParsedInfo);
|
||||
const { type: rawType } = parsed;
|
||||
const type = coerce(rawType, TokenInstructionType);
|
||||
const type = create(rawType, TokenInstructionType);
|
||||
return IX_TITLES[type];
|
||||
} catch (err) {
|
||||
reportError(err, { signature: tx.signature });
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
BPF_LOADER_PROGRAM_ID,
|
||||
} from "@solana/web3.js";
|
||||
import { InstructionCard } from "../InstructionCard";
|
||||
import { coerce } from "superstruct";
|
||||
import { create } from "superstruct";
|
||||
import { ParsedInfo } from "validators";
|
||||
import { WriteInfo, FinalizeInfo } from "./types";
|
||||
import { reportError } from "utils/sentry";
|
||||
|
@ -25,15 +25,15 @@ type DetailsProps = {
|
|||
|
||||
export function BpfLoaderDetailsCard(props: DetailsProps) {
|
||||
try {
|
||||
const parsed = coerce(props.ix.parsed, ParsedInfo);
|
||||
const parsed = create(props.ix.parsed, ParsedInfo);
|
||||
|
||||
switch (parsed.type) {
|
||||
case "write": {
|
||||
const info = coerce(parsed.info, WriteInfo);
|
||||
const info = create(parsed.info, WriteInfo);
|
||||
return <BpfLoaderWriteDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "finalize": {
|
||||
const info = coerce(parsed.info, FinalizeInfo);
|
||||
const info = create(parsed.info, FinalizeInfo);
|
||||
return <BpfLoaderFinalizeDetailsCard info={info} {...props} />;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
/* eslint-disable @typescript-eslint/no-redeclare */
|
||||
|
||||
import { enums, number, pick, string, StructType } from "superstruct";
|
||||
import { Pubkey } from "validators/pubkey";
|
||||
import { enums, number, type, string, Infer } from "superstruct";
|
||||
import { PublicKeyFromString } from "validators/pubkey";
|
||||
|
||||
export type WriteInfo = StructType<typeof WriteInfo>;
|
||||
export const WriteInfo = pick({
|
||||
account: Pubkey,
|
||||
export type WriteInfo = Infer<typeof WriteInfo>;
|
||||
export const WriteInfo = type({
|
||||
account: PublicKeyFromString,
|
||||
bytes: string(),
|
||||
offset: number(),
|
||||
});
|
||||
|
||||
export type FinalizeInfo = StructType<typeof FinalizeInfo>;
|
||||
export const FinalizeInfo = pick({
|
||||
account: Pubkey,
|
||||
export type FinalizeInfo = Infer<typeof FinalizeInfo>;
|
||||
export const FinalizeInfo = type({
|
||||
account: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type BpfLoaderInstructionType = StructType<
|
||||
typeof BpfLoaderInstructionType
|
||||
>;
|
||||
export type BpfLoaderInstructionType = Infer<typeof BpfLoaderInstructionType>;
|
||||
export const BpfLoaderInstructionType = enums(["write", "finalize"]);
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
PublicKey,
|
||||
} from "@solana/web3.js";
|
||||
import { Address } from "components/common/Address";
|
||||
import { coerce, Struct } from "superstruct";
|
||||
import { create, Struct } from "superstruct";
|
||||
import { camelToTitleCase } from "utils";
|
||||
import { reportError } from "utils/sentry";
|
||||
import { ParsedInfo } from "validators";
|
||||
|
@ -31,7 +31,7 @@ type DetailsProps = {
|
|||
|
||||
export function BpfUpgradeableLoaderDetailsCard(props: DetailsProps) {
|
||||
try {
|
||||
const parsed = coerce(props.ix.parsed, ParsedInfo);
|
||||
const parsed = create(props.ix.parsed, ParsedInfo);
|
||||
switch (parsed.type) {
|
||||
case "write": {
|
||||
return renderDetails<WriteInfo>(props, parsed, WriteInfo);
|
||||
|
@ -72,7 +72,7 @@ function renderDetails<T>(
|
|||
parsed: ParsedInfo,
|
||||
struct: Struct<T>
|
||||
) {
|
||||
const info = coerce(parsed.info, struct);
|
||||
const info = create(parsed.info, struct);
|
||||
|
||||
const attributes: JSX.Element[] = [];
|
||||
for (let [key, value] of Object.entries(info)) {
|
||||
|
|
|
@ -1,56 +1,54 @@
|
|||
/* eslint-disable @typescript-eslint/no-redeclare */
|
||||
|
||||
import { enums, nullable, number, pick, string, StructType } from "superstruct";
|
||||
import { Pubkey } from "validators/pubkey";
|
||||
import { enums, nullable, number, type, string, Infer } from "superstruct";
|
||||
import { PublicKeyFromString } from "validators/pubkey";
|
||||
|
||||
export type WriteInfo = StructType<typeof WriteInfo>;
|
||||
export const WriteInfo = pick({
|
||||
account: Pubkey,
|
||||
authority: Pubkey,
|
||||
export type WriteInfo = Infer<typeof WriteInfo>;
|
||||
export const WriteInfo = type({
|
||||
account: PublicKeyFromString,
|
||||
authority: PublicKeyFromString,
|
||||
bytes: string(),
|
||||
offset: number(),
|
||||
});
|
||||
|
||||
export type InitializeBufferInfo = StructType<typeof InitializeBufferInfo>;
|
||||
export const InitializeBufferInfo = pick({
|
||||
account: Pubkey,
|
||||
authority: Pubkey,
|
||||
export type InitializeBufferInfo = Infer<typeof InitializeBufferInfo>;
|
||||
export const InitializeBufferInfo = type({
|
||||
account: PublicKeyFromString,
|
||||
authority: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type UpgradeInfo = StructType<typeof UpgradeInfo>;
|
||||
export const UpgradeInfo = pick({
|
||||
programDataAccount: Pubkey,
|
||||
programAccount: Pubkey,
|
||||
bufferAccount: Pubkey,
|
||||
spillAccount: Pubkey,
|
||||
authority: Pubkey,
|
||||
rentSysvar: Pubkey,
|
||||
clockSysvar: Pubkey,
|
||||
export type UpgradeInfo = Infer<typeof UpgradeInfo>;
|
||||
export const UpgradeInfo = type({
|
||||
programDataAccount: PublicKeyFromString,
|
||||
programAccount: PublicKeyFromString,
|
||||
bufferAccount: PublicKeyFromString,
|
||||
spillAccount: PublicKeyFromString,
|
||||
authority: PublicKeyFromString,
|
||||
rentSysvar: PublicKeyFromString,
|
||||
clockSysvar: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type SetAuthorityInfo = StructType<typeof SetAuthorityInfo>;
|
||||
export const SetAuthorityInfo = pick({
|
||||
account: Pubkey,
|
||||
authority: Pubkey,
|
||||
newAuthority: nullable(Pubkey),
|
||||
export type SetAuthorityInfo = Infer<typeof SetAuthorityInfo>;
|
||||
export const SetAuthorityInfo = type({
|
||||
account: PublicKeyFromString,
|
||||
authority: PublicKeyFromString,
|
||||
newAuthority: nullable(PublicKeyFromString),
|
||||
});
|
||||
|
||||
export type DeployWithMaxDataLenInfo = StructType<
|
||||
typeof DeployWithMaxDataLenInfo
|
||||
>;
|
||||
export const DeployWithMaxDataLenInfo = pick({
|
||||
programDataAccount: Pubkey,
|
||||
programAccount: Pubkey,
|
||||
payerAccount: Pubkey,
|
||||
bufferAccount: Pubkey,
|
||||
authority: Pubkey,
|
||||
rentSysvar: Pubkey,
|
||||
clockSysvar: Pubkey,
|
||||
systemProgram: Pubkey,
|
||||
export type DeployWithMaxDataLenInfo = Infer<typeof DeployWithMaxDataLenInfo>;
|
||||
export const DeployWithMaxDataLenInfo = type({
|
||||
programDataAccount: PublicKeyFromString,
|
||||
programAccount: PublicKeyFromString,
|
||||
payerAccount: PublicKeyFromString,
|
||||
bufferAccount: PublicKeyFromString,
|
||||
authority: PublicKeyFromString,
|
||||
rentSysvar: PublicKeyFromString,
|
||||
clockSysvar: PublicKeyFromString,
|
||||
systemProgram: PublicKeyFromString,
|
||||
maxDataLen: number(),
|
||||
});
|
||||
|
||||
export type UpgradeableBpfLoaderInstructionType = StructType<
|
||||
export type UpgradeableBpfLoaderInstructionType = Infer<
|
||||
typeof UpgradeableBpfLoaderInstructionType
|
||||
>;
|
||||
export const UpgradeableBpfLoaderInstructionType = enums([
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
import { decodeInstruction, MARKETS } from "@project-serum/serum";
|
||||
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import { coerce, enums, number, optional, pick, StructType } from "superstruct";
|
||||
import { BigNumValue } from "validators/bignum";
|
||||
import { Pubkey } from "validators/pubkey";
|
||||
import { enums, number, optional, type, Infer, create } from "superstruct";
|
||||
import { BigNumFromString } from "validators/bignum";
|
||||
import { PublicKeyFromString } from "validators/pubkey";
|
||||
|
||||
const SERUM_PROGRAM_IDS = [
|
||||
"4ckmDgGdxQoPDLUkDT3vHgSAkzA3QRdNq5ywwY4sUSJn",
|
||||
|
@ -14,10 +14,10 @@ const SERUM_PROGRAM_IDS = [
|
|||
|
||||
export const SERUM_DECODED_MAX = 6;
|
||||
|
||||
export type Side = StructType<typeof Side>;
|
||||
export type Side = Infer<typeof Side>;
|
||||
export const Side = enums(["buy", "sell"]);
|
||||
|
||||
export type OrderType = StructType<typeof OrderType>;
|
||||
export type OrderType = Infer<typeof OrderType>;
|
||||
export const OrderType = enums(["limit", "ioc", "postOnly"]);
|
||||
|
||||
export type InitializeMarket = {
|
||||
|
@ -38,18 +38,18 @@ export type InitializeMarket = {
|
|||
programId: PublicKey;
|
||||
};
|
||||
|
||||
export const InitializeMarketDecode = pick({
|
||||
baseLotSize: BigNumValue,
|
||||
quoteLotSize: BigNumValue,
|
||||
export const InitializeMarketDecode = type({
|
||||
baseLotSize: BigNumFromString,
|
||||
quoteLotSize: BigNumFromString,
|
||||
feeRateBps: number(),
|
||||
quoteDustThreshold: BigNumValue,
|
||||
vaultSignerNonce: BigNumValue,
|
||||
quoteDustThreshold: BigNumFromString,
|
||||
vaultSignerNonce: BigNumFromString,
|
||||
});
|
||||
|
||||
export function decodeInitializeMarket(
|
||||
ix: TransactionInstruction
|
||||
): InitializeMarket {
|
||||
const decoded = coerce(
|
||||
const decoded = create(
|
||||
decodeInstruction(ix.data).initializeMarket,
|
||||
InitializeMarketDecode
|
||||
);
|
||||
|
@ -92,17 +92,17 @@ export type NewOrder = {
|
|||
clientId: BN;
|
||||
};
|
||||
|
||||
export const NewOrderDecode = pick({
|
||||
export const NewOrderDecode = type({
|
||||
side: Side,
|
||||
limitPrice: BigNumValue,
|
||||
maxQuantity: BigNumValue,
|
||||
limitPrice: BigNumFromString,
|
||||
maxQuantity: BigNumFromString,
|
||||
orderType: OrderType,
|
||||
clientId: BigNumValue,
|
||||
feeDiscountPubkey: optional(Pubkey),
|
||||
clientId: BigNumFromString,
|
||||
feeDiscountPubkey: optional(PublicKeyFromString),
|
||||
});
|
||||
|
||||
export function decodeNewOrder(ix: TransactionInstruction): NewOrder {
|
||||
const decoded = coerce(decodeInstruction(ix.data).newOrder, NewOrderDecode);
|
||||
const decoded = create(decodeInstruction(ix.data).newOrder, NewOrderDecode);
|
||||
|
||||
let newOrder: NewOrder = {
|
||||
market: ix.keys[0].pubkey,
|
||||
|
@ -139,12 +139,12 @@ export type MatchOrders = {
|
|||
programId: PublicKey;
|
||||
};
|
||||
|
||||
export const MatchOrdersDecode = pick({
|
||||
export const MatchOrdersDecode = type({
|
||||
limit: number(),
|
||||
});
|
||||
|
||||
export function decodeMatchOrders(ix: TransactionInstruction): MatchOrders {
|
||||
const decoded = coerce(
|
||||
const decoded = create(
|
||||
decodeInstruction(ix.data).matchOrders,
|
||||
MatchOrdersDecode
|
||||
);
|
||||
|
@ -172,12 +172,12 @@ export type ConsumeEvents = {
|
|||
programId: PublicKey;
|
||||
};
|
||||
|
||||
export const ConsumeEventsDecode = pick({
|
||||
export const ConsumeEventsDecode = type({
|
||||
limit: number(),
|
||||
});
|
||||
|
||||
export function decodeConsumeEvents(ix: TransactionInstruction): ConsumeEvents {
|
||||
const decoded = coerce(
|
||||
const decoded = create(
|
||||
decodeInstruction(ix.data).consumeEvents,
|
||||
ConsumeEventsDecode
|
||||
);
|
||||
|
@ -204,14 +204,14 @@ export type CancelOrder = {
|
|||
programId: PublicKey;
|
||||
};
|
||||
|
||||
export const CancelOrderDecode = pick({
|
||||
export const CancelOrderDecode = type({
|
||||
side: Side,
|
||||
orderId: BigNumValue,
|
||||
orderId: BigNumFromString,
|
||||
openOrdersSlot: number(),
|
||||
});
|
||||
|
||||
export function decodeCancelOrder(ix: TransactionInstruction): CancelOrder {
|
||||
const decoded = coerce(
|
||||
const decoded = create(
|
||||
decodeInstruction(ix.data).cancelOrder,
|
||||
CancelOrderDecode
|
||||
);
|
||||
|
@ -239,14 +239,14 @@ export type CancelOrderByClientId = {
|
|||
programId: PublicKey;
|
||||
};
|
||||
|
||||
export const CancelOrderByClientIdDecode = pick({
|
||||
clientId: BigNumValue,
|
||||
export const CancelOrderByClientIdDecode = type({
|
||||
clientId: BigNumFromString,
|
||||
});
|
||||
|
||||
export function decodeCancelOrderByClientId(
|
||||
ix: TransactionInstruction
|
||||
): CancelOrderByClientId {
|
||||
const decoded = coerce(
|
||||
const decoded = create(
|
||||
decodeInstruction(ix.data).cancelOrderByClientId,
|
||||
CancelOrderByClientIdDecode
|
||||
);
|
||||
|
|
|
@ -14,7 +14,7 @@ import { WithdrawDetailsCard } from "./WithdrawDetailsCard";
|
|||
import { DeactivateDetailsCard } from "./DeactivateDetailsCard";
|
||||
import { ParsedInfo } from "validators";
|
||||
import { reportError } from "utils/sentry";
|
||||
import { coerce } from "superstruct";
|
||||
import { create } from "superstruct";
|
||||
import {
|
||||
AuthorizeInfo,
|
||||
DeactivateInfo,
|
||||
|
@ -37,35 +37,35 @@ type DetailsProps = {
|
|||
|
||||
export function StakeDetailsCard(props: DetailsProps) {
|
||||
try {
|
||||
const parsed = coerce(props.ix.parsed, ParsedInfo);
|
||||
const parsed = create(props.ix.parsed, ParsedInfo);
|
||||
|
||||
switch (parsed.type) {
|
||||
case "initialize": {
|
||||
const info = coerce(parsed.info, InitializeInfo);
|
||||
const info = create(parsed.info, InitializeInfo);
|
||||
return <InitializeDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "delegate": {
|
||||
const info = coerce(parsed.info, DelegateInfo);
|
||||
const info = create(parsed.info, DelegateInfo);
|
||||
return <DelegateDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "authorize": {
|
||||
const info = coerce(parsed.info, AuthorizeInfo);
|
||||
const info = create(parsed.info, AuthorizeInfo);
|
||||
return <AuthorizeDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "split": {
|
||||
const info = coerce(parsed.info, SplitInfo);
|
||||
const info = create(parsed.info, SplitInfo);
|
||||
return <SplitDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "withdraw": {
|
||||
const info = coerce(parsed.info, WithdrawInfo);
|
||||
const info = create(parsed.info, WithdrawInfo);
|
||||
return <WithdrawDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "deactivate": {
|
||||
const info = coerce(parsed.info, DeactivateInfo);
|
||||
const info = create(parsed.info, DeactivateInfo);
|
||||
return <DeactivateDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "merge": {
|
||||
const info = coerce(parsed.info, MergeInfo);
|
||||
const info = create(parsed.info, MergeInfo);
|
||||
return <MergeDetailsCard info={info} {...props} />;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -1,69 +1,69 @@
|
|||
/* eslint-disable @typescript-eslint/no-redeclare */
|
||||
|
||||
import { enums, number, pick, string, StructType } from "superstruct";
|
||||
import { Pubkey } from "validators/pubkey";
|
||||
import { enums, number, type, string, Infer } from "superstruct";
|
||||
import { PublicKeyFromString } from "validators/pubkey";
|
||||
|
||||
export type InitializeInfo = StructType<typeof InitializeInfo>;
|
||||
export const InitializeInfo = pick({
|
||||
stakeAccount: Pubkey,
|
||||
authorized: pick({
|
||||
staker: Pubkey,
|
||||
withdrawer: Pubkey,
|
||||
export type InitializeInfo = Infer<typeof InitializeInfo>;
|
||||
export const InitializeInfo = type({
|
||||
stakeAccount: PublicKeyFromString,
|
||||
authorized: type({
|
||||
staker: PublicKeyFromString,
|
||||
withdrawer: PublicKeyFromString,
|
||||
}),
|
||||
lockup: pick({
|
||||
lockup: type({
|
||||
unixTimestamp: number(),
|
||||
epoch: number(),
|
||||
custodian: Pubkey,
|
||||
custodian: PublicKeyFromString,
|
||||
}),
|
||||
});
|
||||
|
||||
export type DelegateInfo = StructType<typeof DelegateInfo>;
|
||||
export const DelegateInfo = pick({
|
||||
stakeAccount: Pubkey,
|
||||
voteAccount: Pubkey,
|
||||
stakeAuthority: Pubkey,
|
||||
export type DelegateInfo = Infer<typeof DelegateInfo>;
|
||||
export const DelegateInfo = type({
|
||||
stakeAccount: PublicKeyFromString,
|
||||
voteAccount: PublicKeyFromString,
|
||||
stakeAuthority: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type AuthorizeInfo = StructType<typeof AuthorizeInfo>;
|
||||
export const AuthorizeInfo = pick({
|
||||
export type AuthorizeInfo = Infer<typeof AuthorizeInfo>;
|
||||
export const AuthorizeInfo = type({
|
||||
authorityType: string(),
|
||||
stakeAccount: Pubkey,
|
||||
authority: Pubkey,
|
||||
newAuthority: Pubkey,
|
||||
stakeAccount: PublicKeyFromString,
|
||||
authority: PublicKeyFromString,
|
||||
newAuthority: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type SplitInfo = StructType<typeof SplitInfo>;
|
||||
export const SplitInfo = pick({
|
||||
stakeAccount: Pubkey,
|
||||
stakeAuthority: Pubkey,
|
||||
newSplitAccount: Pubkey,
|
||||
export type SplitInfo = Infer<typeof SplitInfo>;
|
||||
export const SplitInfo = type({
|
||||
stakeAccount: PublicKeyFromString,
|
||||
stakeAuthority: PublicKeyFromString,
|
||||
newSplitAccount: PublicKeyFromString,
|
||||
lamports: number(),
|
||||
});
|
||||
|
||||
export type WithdrawInfo = StructType<typeof WithdrawInfo>;
|
||||
export const WithdrawInfo = pick({
|
||||
stakeAccount: Pubkey,
|
||||
withdrawAuthority: Pubkey,
|
||||
destination: Pubkey,
|
||||
export type WithdrawInfo = Infer<typeof WithdrawInfo>;
|
||||
export const WithdrawInfo = type({
|
||||
stakeAccount: PublicKeyFromString,
|
||||
withdrawAuthority: PublicKeyFromString,
|
||||
destination: PublicKeyFromString,
|
||||
lamports: number(),
|
||||
});
|
||||
|
||||
export type DeactivateInfo = StructType<typeof DeactivateInfo>;
|
||||
export const DeactivateInfo = pick({
|
||||
stakeAccount: Pubkey,
|
||||
stakeAuthority: Pubkey,
|
||||
export type DeactivateInfo = Infer<typeof DeactivateInfo>;
|
||||
export const DeactivateInfo = type({
|
||||
stakeAccount: PublicKeyFromString,
|
||||
stakeAuthority: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type MergeInfo = StructType<typeof MergeInfo>;
|
||||
export const MergeInfo = pick({
|
||||
source: Pubkey,
|
||||
destination: Pubkey,
|
||||
stakeAuthority: Pubkey,
|
||||
stakeHistorySysvar: Pubkey,
|
||||
clockSysvar: Pubkey,
|
||||
export type MergeInfo = Infer<typeof MergeInfo>;
|
||||
export const MergeInfo = type({
|
||||
source: PublicKeyFromString,
|
||||
destination: PublicKeyFromString,
|
||||
stakeAuthority: PublicKeyFromString,
|
||||
stakeHistorySysvar: PublicKeyFromString,
|
||||
clockSysvar: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type StakeInstructionType = StructType<typeof StakeInstructionType>;
|
||||
export type StakeInstructionType = Infer<typeof StakeInstructionType>;
|
||||
export const StakeInstructionType = enums([
|
||||
"initialize",
|
||||
"delegate",
|
||||
|
|
|
@ -19,7 +19,7 @@ import { NonceWithdrawDetailsCard } from "./NonceWithdrawDetailsCard";
|
|||
import { NonceAuthorizeDetailsCard } from "./NonceAuthorizeDetailsCard";
|
||||
import { TransferWithSeedDetailsCard } from "./TransferWithSeedDetailsCard";
|
||||
import { ParsedInfo } from "validators";
|
||||
import { coerce } from "superstruct";
|
||||
import { create } from "superstruct";
|
||||
import { reportError } from "utils/sentry";
|
||||
import {
|
||||
CreateAccountInfo,
|
||||
|
@ -47,54 +47,54 @@ type DetailsProps = {
|
|||
|
||||
export function SystemDetailsCard(props: DetailsProps) {
|
||||
try {
|
||||
const parsed = coerce(props.ix.parsed, ParsedInfo);
|
||||
const parsed = create(props.ix.parsed, ParsedInfo);
|
||||
switch (parsed.type) {
|
||||
case "createAccount": {
|
||||
const info = coerce(parsed.info, CreateAccountInfo);
|
||||
const info = create(parsed.info, CreateAccountInfo);
|
||||
return <CreateDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "createAccountWithSeed": {
|
||||
const info = coerce(parsed.info, CreateAccountWithSeedInfo);
|
||||
const info = create(parsed.info, CreateAccountWithSeedInfo);
|
||||
return <CreateWithSeedDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "allocate": {
|
||||
const info = coerce(parsed.info, AllocateInfo);
|
||||
const info = create(parsed.info, AllocateInfo);
|
||||
return <AllocateDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "allocateWithSeed": {
|
||||
const info = coerce(parsed.info, AllocateWithSeedInfo);
|
||||
const info = create(parsed.info, AllocateWithSeedInfo);
|
||||
return <AllocateWithSeedDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "assign": {
|
||||
const info = coerce(parsed.info, AssignInfo);
|
||||
const info = create(parsed.info, AssignInfo);
|
||||
return <AssignDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "assignWithSeed": {
|
||||
const info = coerce(parsed.info, AssignWithSeedInfo);
|
||||
const info = create(parsed.info, AssignWithSeedInfo);
|
||||
return <AssignWithSeedDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "transfer": {
|
||||
const info = coerce(parsed.info, TransferInfo);
|
||||
const info = create(parsed.info, TransferInfo);
|
||||
return <TransferDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "advanceNonce": {
|
||||
const info = coerce(parsed.info, AdvanceNonceInfo);
|
||||
const info = create(parsed.info, AdvanceNonceInfo);
|
||||
return <NonceAdvanceDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "withdrawNonce": {
|
||||
const info = coerce(parsed.info, WithdrawNonceInfo);
|
||||
const info = create(parsed.info, WithdrawNonceInfo);
|
||||
return <NonceWithdrawDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "authorizeNonce": {
|
||||
const info = coerce(parsed.info, AuthorizeNonceInfo);
|
||||
const info = create(parsed.info, AuthorizeNonceInfo);
|
||||
return <NonceAuthorizeDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "initializeNonce": {
|
||||
const info = coerce(parsed.info, InitializeNonceInfo);
|
||||
const info = create(parsed.info, InitializeNonceInfo);
|
||||
return <NonceInitializeDetailsCard info={info} {...props} />;
|
||||
}
|
||||
case "transferWithSeed": {
|
||||
const info = coerce(parsed.info, TransferWithSeedInfo);
|
||||
const info = create(parsed.info, TransferWithSeedInfo);
|
||||
return <TransferWithSeedDetailsCard info={info} {...props} />;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -1,104 +1,102 @@
|
|||
/* eslint-disable @typescript-eslint/no-redeclare */
|
||||
|
||||
import { enums, number, pick, string, StructType } from "superstruct";
|
||||
import { Pubkey } from "validators/pubkey";
|
||||
import { enums, number, type, string, Infer } from "superstruct";
|
||||
import { PublicKeyFromString } from "validators/pubkey";
|
||||
|
||||
export type CreateAccountInfo = StructType<typeof CreateAccountInfo>;
|
||||
export const CreateAccountInfo = pick({
|
||||
source: Pubkey,
|
||||
newAccount: Pubkey,
|
||||
export type CreateAccountInfo = Infer<typeof CreateAccountInfo>;
|
||||
export const CreateAccountInfo = type({
|
||||
source: PublicKeyFromString,
|
||||
newAccount: PublicKeyFromString,
|
||||
lamports: number(),
|
||||
space: number(),
|
||||
owner: Pubkey,
|
||||
owner: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type AssignInfo = StructType<typeof AssignInfo>;
|
||||
export const AssignInfo = pick({
|
||||
account: Pubkey,
|
||||
owner: Pubkey,
|
||||
export type AssignInfo = Infer<typeof AssignInfo>;
|
||||
export const AssignInfo = type({
|
||||
account: PublicKeyFromString,
|
||||
owner: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type TransferInfo = StructType<typeof TransferInfo>;
|
||||
export const TransferInfo = pick({
|
||||
source: Pubkey,
|
||||
destination: Pubkey,
|
||||
export type TransferInfo = Infer<typeof TransferInfo>;
|
||||
export const TransferInfo = type({
|
||||
source: PublicKeyFromString,
|
||||
destination: PublicKeyFromString,
|
||||
lamports: number(),
|
||||
});
|
||||
|
||||
export type CreateAccountWithSeedInfo = StructType<
|
||||
typeof CreateAccountWithSeedInfo
|
||||
>;
|
||||
export const CreateAccountWithSeedInfo = pick({
|
||||
source: Pubkey,
|
||||
newAccount: Pubkey,
|
||||
base: Pubkey,
|
||||
export type CreateAccountWithSeedInfo = Infer<typeof CreateAccountWithSeedInfo>;
|
||||
export const CreateAccountWithSeedInfo = type({
|
||||
source: PublicKeyFromString,
|
||||
newAccount: PublicKeyFromString,
|
||||
base: PublicKeyFromString,
|
||||
seed: string(),
|
||||
lamports: number(),
|
||||
space: number(),
|
||||
owner: Pubkey,
|
||||
owner: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type AdvanceNonceInfo = StructType<typeof AdvanceNonceInfo>;
|
||||
export const AdvanceNonceInfo = pick({
|
||||
nonceAccount: Pubkey,
|
||||
nonceAuthority: Pubkey,
|
||||
export type AdvanceNonceInfo = Infer<typeof AdvanceNonceInfo>;
|
||||
export const AdvanceNonceInfo = type({
|
||||
nonceAccount: PublicKeyFromString,
|
||||
nonceAuthority: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type WithdrawNonceInfo = StructType<typeof WithdrawNonceInfo>;
|
||||
export const WithdrawNonceInfo = pick({
|
||||
nonceAccount: Pubkey,
|
||||
destination: Pubkey,
|
||||
nonceAuthority: Pubkey,
|
||||
export type WithdrawNonceInfo = Infer<typeof WithdrawNonceInfo>;
|
||||
export const WithdrawNonceInfo = type({
|
||||
nonceAccount: PublicKeyFromString,
|
||||
destination: PublicKeyFromString,
|
||||
nonceAuthority: PublicKeyFromString,
|
||||
lamports: number(),
|
||||
});
|
||||
|
||||
export type InitializeNonceInfo = StructType<typeof InitializeNonceInfo>;
|
||||
export const InitializeNonceInfo = pick({
|
||||
nonceAccount: Pubkey,
|
||||
nonceAuthority: Pubkey,
|
||||
export type InitializeNonceInfo = Infer<typeof InitializeNonceInfo>;
|
||||
export const InitializeNonceInfo = type({
|
||||
nonceAccount: PublicKeyFromString,
|
||||
nonceAuthority: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type AuthorizeNonceInfo = StructType<typeof AuthorizeNonceInfo>;
|
||||
export const AuthorizeNonceInfo = pick({
|
||||
nonceAccount: Pubkey,
|
||||
nonceAuthority: Pubkey,
|
||||
newAuthorized: Pubkey,
|
||||
export type AuthorizeNonceInfo = Infer<typeof AuthorizeNonceInfo>;
|
||||
export const AuthorizeNonceInfo = type({
|
||||
nonceAccount: PublicKeyFromString,
|
||||
nonceAuthority: PublicKeyFromString,
|
||||
newAuthorized: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type AllocateInfo = StructType<typeof AllocateInfo>;
|
||||
export const AllocateInfo = pick({
|
||||
account: Pubkey,
|
||||
export type AllocateInfo = Infer<typeof AllocateInfo>;
|
||||
export const AllocateInfo = type({
|
||||
account: PublicKeyFromString,
|
||||
space: number(),
|
||||
});
|
||||
|
||||
export type AllocateWithSeedInfo = StructType<typeof AllocateWithSeedInfo>;
|
||||
export const AllocateWithSeedInfo = pick({
|
||||
account: Pubkey,
|
||||
base: Pubkey,
|
||||
export type AllocateWithSeedInfo = Infer<typeof AllocateWithSeedInfo>;
|
||||
export const AllocateWithSeedInfo = type({
|
||||
account: PublicKeyFromString,
|
||||
base: PublicKeyFromString,
|
||||
seed: string(),
|
||||
space: number(),
|
||||
owner: Pubkey,
|
||||
owner: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type AssignWithSeedInfo = StructType<typeof AssignWithSeedInfo>;
|
||||
export const AssignWithSeedInfo = pick({
|
||||
account: Pubkey,
|
||||
base: Pubkey,
|
||||
export type AssignWithSeedInfo = Infer<typeof AssignWithSeedInfo>;
|
||||
export const AssignWithSeedInfo = type({
|
||||
account: PublicKeyFromString,
|
||||
base: PublicKeyFromString,
|
||||
seed: string(),
|
||||
owner: Pubkey,
|
||||
owner: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type TransferWithSeedInfo = StructType<typeof TransferWithSeedInfo>;
|
||||
export const TransferWithSeedInfo = pick({
|
||||
source: Pubkey,
|
||||
sourceBase: Pubkey,
|
||||
destination: Pubkey,
|
||||
export type TransferWithSeedInfo = Infer<typeof TransferWithSeedInfo>;
|
||||
export const TransferWithSeedInfo = type({
|
||||
source: PublicKeyFromString,
|
||||
sourceBase: PublicKeyFromString,
|
||||
destination: PublicKeyFromString,
|
||||
lamports: number(),
|
||||
sourceSeed: string(),
|
||||
sourceOwner: Pubkey,
|
||||
sourceOwner: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type SystemInstructionType = StructType<typeof SystemInstructionType>;
|
||||
export type SystemInstructionType = Infer<typeof SystemInstructionType>;
|
||||
export const SystemInstructionType = enums([
|
||||
"createAccount",
|
||||
"createAccountWithSeed",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React from "react";
|
||||
import { coerce } from "superstruct";
|
||||
import { create } from "superstruct";
|
||||
import {
|
||||
SignatureResult,
|
||||
ParsedTransaction,
|
||||
|
@ -37,12 +37,12 @@ type DetailsProps = {
|
|||
|
||||
export function TokenDetailsCard(props: DetailsProps) {
|
||||
try {
|
||||
const parsed = coerce(props.ix.parsed, ParsedInfo);
|
||||
const parsed = create(props.ix.parsed, ParsedInfo);
|
||||
const { type: rawType, info } = parsed;
|
||||
const type = coerce(rawType, TokenInstructionType);
|
||||
const type = create(rawType, TokenInstructionType);
|
||||
const title = `Token: ${IX_TITLES[type]}`;
|
||||
const coerced = coerce(info, IX_STRUCTS[type] as any);
|
||||
return <TokenInstruction title={title} info={coerced} {...props} />;
|
||||
const created = create(info, IX_STRUCTS[type] as any);
|
||||
return <TokenInstruction title={title} info={created} {...props} />;
|
||||
} catch (err) {
|
||||
reportError(err, {
|
||||
signature: props.tx.signatures[0],
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
import {
|
||||
enums,
|
||||
pick,
|
||||
StructType,
|
||||
type,
|
||||
Infer,
|
||||
number,
|
||||
string,
|
||||
optional,
|
||||
|
@ -11,60 +11,60 @@ import {
|
|||
nullable,
|
||||
union,
|
||||
} from "superstruct";
|
||||
import { Pubkey } from "validators/pubkey";
|
||||
import { PublicKeyFromString } from "validators/pubkey";
|
||||
|
||||
export type TokenAmountUi = StructType<typeof TokenAmountUi>;
|
||||
export const TokenAmountUi = pick({
|
||||
export type TokenAmountUi = Infer<typeof TokenAmountUi>;
|
||||
export const TokenAmountUi = type({
|
||||
amount: string(),
|
||||
decimals: number(),
|
||||
uiAmountString: string(),
|
||||
});
|
||||
|
||||
const InitializeMint = pick({
|
||||
mint: Pubkey,
|
||||
const InitializeMint = type({
|
||||
mint: PublicKeyFromString,
|
||||
decimals: number(),
|
||||
mintAuthority: Pubkey,
|
||||
rentSysvar: Pubkey,
|
||||
freezeAuthority: optional(Pubkey),
|
||||
mintAuthority: PublicKeyFromString,
|
||||
rentSysvar: PublicKeyFromString,
|
||||
freezeAuthority: optional(PublicKeyFromString),
|
||||
});
|
||||
|
||||
const InitializeAccount = pick({
|
||||
account: Pubkey,
|
||||
mint: Pubkey,
|
||||
owner: Pubkey,
|
||||
rentSysvar: Pubkey,
|
||||
const InitializeAccount = type({
|
||||
account: PublicKeyFromString,
|
||||
mint: PublicKeyFromString,
|
||||
owner: PublicKeyFromString,
|
||||
rentSysvar: PublicKeyFromString,
|
||||
});
|
||||
|
||||
const InitializeMultisig = pick({
|
||||
multisig: Pubkey,
|
||||
rentSysvar: Pubkey,
|
||||
signers: array(Pubkey),
|
||||
const InitializeMultisig = type({
|
||||
multisig: PublicKeyFromString,
|
||||
rentSysvar: PublicKeyFromString,
|
||||
signers: array(PublicKeyFromString),
|
||||
m: number(),
|
||||
});
|
||||
|
||||
const Transfer = pick({
|
||||
source: Pubkey,
|
||||
destination: Pubkey,
|
||||
const Transfer = type({
|
||||
source: PublicKeyFromString,
|
||||
destination: PublicKeyFromString,
|
||||
amount: union([string(), number()]),
|
||||
authority: optional(Pubkey),
|
||||
multisigAuthority: optional(Pubkey),
|
||||
signers: optional(array(Pubkey)),
|
||||
authority: optional(PublicKeyFromString),
|
||||
multisigAuthority: optional(PublicKeyFromString),
|
||||
signers: optional(array(PublicKeyFromString)),
|
||||
});
|
||||
|
||||
const Approve = pick({
|
||||
source: Pubkey,
|
||||
delegate: Pubkey,
|
||||
const Approve = type({
|
||||
source: PublicKeyFromString,
|
||||
delegate: PublicKeyFromString,
|
||||
amount: union([string(), number()]),
|
||||
owner: optional(Pubkey),
|
||||
multisigOwner: optional(Pubkey),
|
||||
signers: optional(array(Pubkey)),
|
||||
owner: optional(PublicKeyFromString),
|
||||
multisigOwner: optional(PublicKeyFromString),
|
||||
signers: optional(array(PublicKeyFromString)),
|
||||
});
|
||||
|
||||
const Revoke = pick({
|
||||
source: Pubkey,
|
||||
owner: optional(Pubkey),
|
||||
multisigOwner: optional(Pubkey),
|
||||
signers: optional(array(Pubkey)),
|
||||
const Revoke = type({
|
||||
source: PublicKeyFromString,
|
||||
owner: optional(PublicKeyFromString),
|
||||
multisigOwner: optional(PublicKeyFromString),
|
||||
signers: optional(array(PublicKeyFromString)),
|
||||
});
|
||||
|
||||
const AuthorityType = enums([
|
||||
|
@ -74,97 +74,97 @@ const AuthorityType = enums([
|
|||
"closeAccount",
|
||||
]);
|
||||
|
||||
const SetAuthority = pick({
|
||||
mint: optional(Pubkey),
|
||||
account: optional(Pubkey),
|
||||
const SetAuthority = type({
|
||||
mint: optional(PublicKeyFromString),
|
||||
account: optional(PublicKeyFromString),
|
||||
authorityType: AuthorityType,
|
||||
newAuthority: nullable(Pubkey),
|
||||
authority: optional(Pubkey),
|
||||
multisigAuthority: optional(Pubkey),
|
||||
signers: optional(array(Pubkey)),
|
||||
newAuthority: nullable(PublicKeyFromString),
|
||||
authority: optional(PublicKeyFromString),
|
||||
multisigAuthority: optional(PublicKeyFromString),
|
||||
signers: optional(array(PublicKeyFromString)),
|
||||
});
|
||||
|
||||
const MintTo = pick({
|
||||
mint: Pubkey,
|
||||
account: Pubkey,
|
||||
const MintTo = type({
|
||||
mint: PublicKeyFromString,
|
||||
account: PublicKeyFromString,
|
||||
amount: union([string(), number()]),
|
||||
mintAuthority: optional(Pubkey),
|
||||
multisigMintAuthority: optional(Pubkey),
|
||||
signers: optional(array(Pubkey)),
|
||||
mintAuthority: optional(PublicKeyFromString),
|
||||
multisigMintAuthority: optional(PublicKeyFromString),
|
||||
signers: optional(array(PublicKeyFromString)),
|
||||
});
|
||||
|
||||
const Burn = pick({
|
||||
account: Pubkey,
|
||||
mint: Pubkey,
|
||||
const Burn = type({
|
||||
account: PublicKeyFromString,
|
||||
mint: PublicKeyFromString,
|
||||
amount: union([string(), number()]),
|
||||
authority: optional(Pubkey),
|
||||
multisigAuthority: optional(Pubkey),
|
||||
signers: optional(array(Pubkey)),
|
||||
authority: optional(PublicKeyFromString),
|
||||
multisigAuthority: optional(PublicKeyFromString),
|
||||
signers: optional(array(PublicKeyFromString)),
|
||||
});
|
||||
|
||||
const CloseAccount = pick({
|
||||
account: Pubkey,
|
||||
destination: Pubkey,
|
||||
owner: optional(Pubkey),
|
||||
multisigOwner: optional(Pubkey),
|
||||
signers: optional(array(Pubkey)),
|
||||
const CloseAccount = type({
|
||||
account: PublicKeyFromString,
|
||||
destination: PublicKeyFromString,
|
||||
owner: optional(PublicKeyFromString),
|
||||
multisigOwner: optional(PublicKeyFromString),
|
||||
signers: optional(array(PublicKeyFromString)),
|
||||
});
|
||||
|
||||
const FreezeAccount = pick({
|
||||
account: Pubkey,
|
||||
mint: Pubkey,
|
||||
freezeAuthority: optional(Pubkey),
|
||||
multisigFreezeAuthority: optional(Pubkey),
|
||||
signers: optional(array(Pubkey)),
|
||||
const FreezeAccount = type({
|
||||
account: PublicKeyFromString,
|
||||
mint: PublicKeyFromString,
|
||||
freezeAuthority: optional(PublicKeyFromString),
|
||||
multisigFreezeAuthority: optional(PublicKeyFromString),
|
||||
signers: optional(array(PublicKeyFromString)),
|
||||
});
|
||||
|
||||
const ThawAccount = pick({
|
||||
account: Pubkey,
|
||||
mint: Pubkey,
|
||||
freezeAuthority: optional(Pubkey),
|
||||
multisigFreezeAuthority: optional(Pubkey),
|
||||
signers: optional(array(Pubkey)),
|
||||
const ThawAccount = type({
|
||||
account: PublicKeyFromString,
|
||||
mint: PublicKeyFromString,
|
||||
freezeAuthority: optional(PublicKeyFromString),
|
||||
multisigFreezeAuthority: optional(PublicKeyFromString),
|
||||
signers: optional(array(PublicKeyFromString)),
|
||||
});
|
||||
|
||||
const TransferChecked = pick({
|
||||
source: Pubkey,
|
||||
mint: Pubkey,
|
||||
destination: Pubkey,
|
||||
authority: optional(Pubkey),
|
||||
multisigAuthority: optional(Pubkey),
|
||||
signers: optional(array(Pubkey)),
|
||||
const TransferChecked = type({
|
||||
source: PublicKeyFromString,
|
||||
mint: PublicKeyFromString,
|
||||
destination: PublicKeyFromString,
|
||||
authority: optional(PublicKeyFromString),
|
||||
multisigAuthority: optional(PublicKeyFromString),
|
||||
signers: optional(array(PublicKeyFromString)),
|
||||
tokenAmount: TokenAmountUi,
|
||||
});
|
||||
|
||||
const ApproveChecked = pick({
|
||||
source: Pubkey,
|
||||
mint: Pubkey,
|
||||
delegate: Pubkey,
|
||||
owner: optional(Pubkey),
|
||||
multisigOwner: optional(Pubkey),
|
||||
signers: optional(array(Pubkey)),
|
||||
const ApproveChecked = type({
|
||||
source: PublicKeyFromString,
|
||||
mint: PublicKeyFromString,
|
||||
delegate: PublicKeyFromString,
|
||||
owner: optional(PublicKeyFromString),
|
||||
multisigOwner: optional(PublicKeyFromString),
|
||||
signers: optional(array(PublicKeyFromString)),
|
||||
tokenAmount: TokenAmountUi,
|
||||
});
|
||||
|
||||
const MintToChecked = pick({
|
||||
account: Pubkey,
|
||||
mint: Pubkey,
|
||||
mintAuthority: optional(Pubkey),
|
||||
multisigMintAuthority: optional(Pubkey),
|
||||
signers: optional(array(Pubkey)),
|
||||
const MintToChecked = type({
|
||||
account: PublicKeyFromString,
|
||||
mint: PublicKeyFromString,
|
||||
mintAuthority: optional(PublicKeyFromString),
|
||||
multisigMintAuthority: optional(PublicKeyFromString),
|
||||
signers: optional(array(PublicKeyFromString)),
|
||||
tokenAmount: TokenAmountUi,
|
||||
});
|
||||
|
||||
const BurnChecked = pick({
|
||||
account: Pubkey,
|
||||
mint: Pubkey,
|
||||
authority: optional(Pubkey),
|
||||
multisigAuthority: optional(Pubkey),
|
||||
signers: optional(array(Pubkey)),
|
||||
const BurnChecked = type({
|
||||
account: PublicKeyFromString,
|
||||
mint: PublicKeyFromString,
|
||||
authority: optional(PublicKeyFromString),
|
||||
multisigAuthority: optional(PublicKeyFromString),
|
||||
signers: optional(array(PublicKeyFromString)),
|
||||
tokenAmount: TokenAmountUi,
|
||||
});
|
||||
|
||||
export type TokenInstructionType = StructType<typeof TokenInstructionType>;
|
||||
export type TokenInstructionType = Infer<typeof TokenInstructionType>;
|
||||
export const TokenInstructionType = enums([
|
||||
"initializeMint",
|
||||
"initializeAccount",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import React from "react";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { coerce, Struct } from "superstruct";
|
||||
import { create, Struct } from "superstruct";
|
||||
import { ParsedInfo } from "validators";
|
||||
import {
|
||||
UpdateCommissionInfo,
|
||||
|
@ -23,7 +23,7 @@ export function VoteDetailsCard(props: InstructionDetailsProps) {
|
|||
const { url } = useCluster();
|
||||
|
||||
try {
|
||||
const parsed = coerce(props.ix.parsed, ParsedInfo);
|
||||
const parsed = create(props.ix.parsed, ParsedInfo);
|
||||
|
||||
switch (parsed.type) {
|
||||
case "vote":
|
||||
|
@ -61,7 +61,7 @@ function renderDetails<T>(
|
|||
parsed: ParsedInfo,
|
||||
struct: Struct<T>
|
||||
) {
|
||||
const info = coerce(parsed.info, struct);
|
||||
const info = create(parsed.info, struct);
|
||||
const attributes: JSX.Element[] = [];
|
||||
|
||||
for (let [key, value] of Object.entries(info)) {
|
||||
|
|
|
@ -5,74 +5,74 @@ import {
|
|||
nullable,
|
||||
number,
|
||||
optional,
|
||||
pick,
|
||||
type,
|
||||
string,
|
||||
StructType,
|
||||
Infer,
|
||||
} from "superstruct";
|
||||
import { Pubkey } from "validators/pubkey";
|
||||
import { PublicKeyFromString } from "validators/pubkey";
|
||||
|
||||
export type InitializeInfo = StructType<typeof InitializeInfo>;
|
||||
export const InitializeInfo = pick({
|
||||
voteAccount: Pubkey,
|
||||
rentSysvar: Pubkey,
|
||||
clockSysvar: Pubkey,
|
||||
node: Pubkey,
|
||||
authorizedVoter: Pubkey,
|
||||
authorizedWithdrawer: Pubkey,
|
||||
export type InitializeInfo = Infer<typeof InitializeInfo>;
|
||||
export const InitializeInfo = type({
|
||||
voteAccount: PublicKeyFromString,
|
||||
rentSysvar: PublicKeyFromString,
|
||||
clockSysvar: PublicKeyFromString,
|
||||
node: PublicKeyFromString,
|
||||
authorizedVoter: PublicKeyFromString,
|
||||
authorizedWithdrawer: PublicKeyFromString,
|
||||
commission: number(),
|
||||
});
|
||||
|
||||
export type AuthorizeInfo = StructType<typeof AuthorizeInfo>;
|
||||
export const AuthorizeInfo = pick({
|
||||
voteAccount: Pubkey,
|
||||
clockSysvar: Pubkey,
|
||||
authority: Pubkey,
|
||||
newAuthority: Pubkey,
|
||||
export type AuthorizeInfo = Infer<typeof AuthorizeInfo>;
|
||||
export const AuthorizeInfo = type({
|
||||
voteAccount: PublicKeyFromString,
|
||||
clockSysvar: PublicKeyFromString,
|
||||
authority: PublicKeyFromString,
|
||||
newAuthority: PublicKeyFromString,
|
||||
authorityType: number(),
|
||||
});
|
||||
|
||||
export type VoteInfo = StructType<typeof VoteInfo>;
|
||||
export const VoteInfo = pick({
|
||||
clockSysvar: Pubkey,
|
||||
slotHashesSysvar: Pubkey,
|
||||
voteAccount: Pubkey,
|
||||
voteAuthority: Pubkey,
|
||||
vote: pick({
|
||||
export type VoteInfo = Infer<typeof VoteInfo>;
|
||||
export const VoteInfo = type({
|
||||
clockSysvar: PublicKeyFromString,
|
||||
slotHashesSysvar: PublicKeyFromString,
|
||||
voteAccount: PublicKeyFromString,
|
||||
voteAuthority: PublicKeyFromString,
|
||||
vote: type({
|
||||
hash: string(),
|
||||
slots: array(number()),
|
||||
timestamp: optional(nullable(number())),
|
||||
}),
|
||||
});
|
||||
|
||||
export type WithdrawInfo = StructType<typeof WithdrawInfo>;
|
||||
export const WithdrawInfo = pick({
|
||||
voteAccount: Pubkey,
|
||||
destination: Pubkey,
|
||||
withdrawAuthority: Pubkey,
|
||||
export type WithdrawInfo = Infer<typeof WithdrawInfo>;
|
||||
export const WithdrawInfo = type({
|
||||
voteAccount: PublicKeyFromString,
|
||||
destination: PublicKeyFromString,
|
||||
withdrawAuthority: PublicKeyFromString,
|
||||
lamports: number(),
|
||||
});
|
||||
|
||||
export type UpdateValidatorInfo = StructType<typeof UpdateValidatorInfo>;
|
||||
export const UpdateValidatorInfo = pick({
|
||||
voteAccount: Pubkey,
|
||||
newValidatorIdentity: Pubkey,
|
||||
withdrawAuthority: Pubkey,
|
||||
export type UpdateValidatorInfo = Infer<typeof UpdateValidatorInfo>;
|
||||
export const UpdateValidatorInfo = type({
|
||||
voteAccount: PublicKeyFromString,
|
||||
newValidatorIdentity: PublicKeyFromString,
|
||||
withdrawAuthority: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type UpdateCommissionInfo = StructType<typeof UpdateCommissionInfo>;
|
||||
export const UpdateCommissionInfo = pick({
|
||||
voteAccount: Pubkey,
|
||||
withdrawAuthority: Pubkey,
|
||||
export type UpdateCommissionInfo = Infer<typeof UpdateCommissionInfo>;
|
||||
export const UpdateCommissionInfo = type({
|
||||
voteAccount: PublicKeyFromString,
|
||||
withdrawAuthority: PublicKeyFromString,
|
||||
commission: number(),
|
||||
});
|
||||
|
||||
export type VoteSwitchInfo = StructType<typeof VoteSwitchInfo>;
|
||||
export const VoteSwitchInfo = pick({
|
||||
voteAccount: Pubkey,
|
||||
slotHashesSysvar: Pubkey,
|
||||
clockSysvar: Pubkey,
|
||||
voteAuthority: Pubkey,
|
||||
vote: pick({
|
||||
export type VoteSwitchInfo = Infer<typeof VoteSwitchInfo>;
|
||||
export const VoteSwitchInfo = type({
|
||||
voteAccount: PublicKeyFromString,
|
||||
slotHashesSysvar: PublicKeyFromString,
|
||||
clockSysvar: PublicKeyFromString,
|
||||
voteAuthority: PublicKeyFromString,
|
||||
vote: type({
|
||||
hash: string(),
|
||||
slots: array(number()),
|
||||
timestamp: number(),
|
||||
|
|
|
@ -3,7 +3,7 @@ import { PublicKey, Connection, StakeActivationData } from "@solana/web3.js";
|
|||
import { useCluster, Cluster } from "../cluster";
|
||||
import { HistoryProvider } from "./history";
|
||||
import { TokensProvider } from "./tokens";
|
||||
import { coerce } from "superstruct";
|
||||
import { create } from "superstruct";
|
||||
import { ParsedInfo } from "validators";
|
||||
import { StakeAccount } from "validators/accounts/stake";
|
||||
import {
|
||||
|
@ -151,7 +151,7 @@ async function fetchAccountInfo(
|
|||
let data: ProgramData | undefined;
|
||||
if ("parsed" in result.data) {
|
||||
try {
|
||||
const info = coerce(result.data.parsed, ParsedInfo);
|
||||
const info = create(result.data.parsed, ParsedInfo);
|
||||
switch (result.data.program) {
|
||||
case "bpf-upgradeable-loader": {
|
||||
let programAccount: ProgramAccountInfo;
|
||||
|
@ -161,7 +161,7 @@ async function fetchAccountInfo(
|
|||
break;
|
||||
}
|
||||
|
||||
const parsed = coerce(info, ProgramAccount);
|
||||
const parsed = create(info, ProgramAccount);
|
||||
programAccount = parsed.info;
|
||||
const result = (
|
||||
await connection.getParsedAccountInfo(parsed.info.programData)
|
||||
|
@ -171,8 +171,8 @@ async function fetchAccountInfo(
|
|||
"parsed" in result.data &&
|
||||
result.data.program === "bpf-upgradeable-loader"
|
||||
) {
|
||||
const info = coerce(result.data.parsed, ParsedInfo);
|
||||
programData = coerce(info, ProgramDataAccount).info;
|
||||
const info = create(result.data.parsed, ParsedInfo);
|
||||
programData = create(info, ProgramDataAccount).info;
|
||||
} else {
|
||||
throw new Error(
|
||||
`invalid program data account for program: ${pubkey.toBase58()}`
|
||||
|
@ -188,7 +188,7 @@ async function fetchAccountInfo(
|
|||
break;
|
||||
}
|
||||
case "stake": {
|
||||
const parsed = coerce(info, StakeAccount);
|
||||
const parsed = create(info, StakeAccount);
|
||||
const isDelegated = parsed.type === "delegated";
|
||||
const activation = isDelegated
|
||||
? await connection.getStakeActivation(pubkey)
|
||||
|
@ -204,32 +204,32 @@ async function fetchAccountInfo(
|
|||
case "vote":
|
||||
data = {
|
||||
program: result.data.program,
|
||||
parsed: coerce(info, VoteAccount),
|
||||
parsed: create(info, VoteAccount),
|
||||
};
|
||||
break;
|
||||
case "nonce":
|
||||
data = {
|
||||
program: result.data.program,
|
||||
parsed: coerce(info, NonceAccount),
|
||||
parsed: create(info, NonceAccount),
|
||||
};
|
||||
break;
|
||||
case "sysvar":
|
||||
data = {
|
||||
program: result.data.program,
|
||||
parsed: coerce(info, SysvarAccount),
|
||||
parsed: create(info, SysvarAccount),
|
||||
};
|
||||
break;
|
||||
case "config":
|
||||
data = {
|
||||
program: result.data.program,
|
||||
parsed: coerce(info, ConfigAccount),
|
||||
parsed: create(info, ConfigAccount),
|
||||
};
|
||||
break;
|
||||
|
||||
case "spl-token":
|
||||
data = {
|
||||
program: result.data.program,
|
||||
parsed: coerce(info, TokenAccount),
|
||||
parsed: create(info, TokenAccount),
|
||||
};
|
||||
break;
|
||||
default:
|
||||
|
@ -298,7 +298,7 @@ export function useMintAccountInfo(
|
|||
return;
|
||||
}
|
||||
|
||||
return coerce(data.parsed.info, MintAccountInfo);
|
||||
return create(data.parsed.info, MintAccountInfo);
|
||||
} catch (err) {
|
||||
reportError(err, { address });
|
||||
}
|
||||
|
@ -318,7 +318,7 @@ export function useTokenAccountInfo(
|
|||
return;
|
||||
}
|
||||
|
||||
return coerce(data.parsed.info, TokenAccountInfo);
|
||||
return create(data.parsed.info, TokenAccountInfo);
|
||||
} catch (err) {
|
||||
reportError(err, { address });
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import * as Cache from "providers/cache";
|
|||
import { ActionType, FetchStatus } from "providers/cache";
|
||||
import { TokenAccountInfo } from "validators/accounts/token";
|
||||
import { useCluster, Cluster } from "../cluster";
|
||||
import { coerce } from "superstruct";
|
||||
import { create } from "superstruct";
|
||||
import { reportError } from "utils/sentry";
|
||||
|
||||
export type TokenInfoWithPubkey = {
|
||||
|
@ -68,7 +68,7 @@ async function fetchAccountTokens(
|
|||
data = {
|
||||
tokens: value.map((accountInfo) => {
|
||||
const parsedInfo = accountInfo.account.data.parsed.info;
|
||||
const info = coerce(parsedInfo, TokenAccountInfo);
|
||||
const info = create(parsedInfo, TokenAccountInfo);
|
||||
return { info, pubkey: accountInfo.pubkey };
|
||||
}),
|
||||
};
|
||||
|
|
|
@ -10,7 +10,7 @@ import {
|
|||
} from "@solana/web3.js";
|
||||
import { TokenAccountInfo, TokenAccount } from "validators/accounts/token";
|
||||
import { ParsedInfo } from "validators";
|
||||
import { coerce } from "superstruct";
|
||||
import { create } from "superstruct";
|
||||
import { reportError } from "utils/sentry";
|
||||
|
||||
type LargestAccounts = {
|
||||
|
@ -81,7 +81,7 @@ async function fetchLargestAccounts(
|
|||
)
|
||||
).value;
|
||||
if (accountInfo && "parsed" in accountInfo.data) {
|
||||
const info = coerceParsedAccountInfo(accountInfo.data);
|
||||
const info = createParsedAccountInfo(accountInfo.data);
|
||||
return {
|
||||
...account,
|
||||
owner: info.owner,
|
||||
|
@ -144,13 +144,13 @@ export function useTokenLargestTokens(
|
|||
return context.entries[address];
|
||||
}
|
||||
|
||||
function coerceParsedAccountInfo(
|
||||
function createParsedAccountInfo(
|
||||
parsedData: ParsedAccountData
|
||||
): TokenAccountInfo {
|
||||
try {
|
||||
const data = coerce(parsedData.parsed, ParsedInfo);
|
||||
const parsed = coerce(data, TokenAccount);
|
||||
return coerce(parsed.info, TokenAccountInfo);
|
||||
const data = create(parsedData.parsed, ParsedInfo);
|
||||
const parsed = create(data, TokenAccount);
|
||||
return create(parsed.info, TokenAccountInfo);
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
/* eslint-disable @typescript-eslint/no-redeclare */
|
||||
|
||||
import {
|
||||
StructType,
|
||||
pick,
|
||||
Infer,
|
||||
array,
|
||||
boolean,
|
||||
object,
|
||||
type,
|
||||
number,
|
||||
string,
|
||||
record,
|
||||
|
@ -13,44 +12,40 @@ import {
|
|||
literal,
|
||||
} from "superstruct";
|
||||
|
||||
export type StakeConfigInfo = StructType<typeof StakeConfigInfo>;
|
||||
export const StakeConfigInfo = pick({
|
||||
export type StakeConfigInfo = Infer<typeof StakeConfigInfo>;
|
||||
export const StakeConfigInfo = type({
|
||||
warmupCooldownRate: number(),
|
||||
slashPenalty: number(),
|
||||
});
|
||||
|
||||
export type ConfigKey = StructType<typeof ConfigKey>;
|
||||
export const ConfigKey = pick({
|
||||
export type ConfigKey = Infer<typeof ConfigKey>;
|
||||
export const ConfigKey = type({
|
||||
pubkey: string(),
|
||||
signer: boolean(),
|
||||
});
|
||||
|
||||
export type ValidatorInfoConfigData = StructType<
|
||||
typeof ValidatorInfoConfigData
|
||||
>;
|
||||
export type ValidatorInfoConfigData = Infer<typeof ValidatorInfoConfigData>;
|
||||
export const ValidatorInfoConfigData = record(string(), string());
|
||||
|
||||
export type ValidatorInfoConfigInfo = StructType<
|
||||
typeof ValidatorInfoConfigInfo
|
||||
>;
|
||||
export const ValidatorInfoConfigInfo = pick({
|
||||
export type ValidatorInfoConfigInfo = Infer<typeof ValidatorInfoConfigInfo>;
|
||||
export const ValidatorInfoConfigInfo = type({
|
||||
keys: array(ConfigKey),
|
||||
configData: ValidatorInfoConfigData,
|
||||
});
|
||||
|
||||
export type ValidatorInfoAccount = StructType<typeof ValidatorInfoAccount>;
|
||||
export const ValidatorInfoAccount = object({
|
||||
export type ValidatorInfoAccount = Infer<typeof ValidatorInfoAccount>;
|
||||
export const ValidatorInfoAccount = type({
|
||||
type: literal("validatorInfo"),
|
||||
info: ValidatorInfoConfigInfo,
|
||||
});
|
||||
|
||||
export type StakeConfigInfoAccount = StructType<typeof StakeConfigInfoAccount>;
|
||||
export const StakeConfigInfoAccount = object({
|
||||
export type StakeConfigInfoAccount = Infer<typeof StakeConfigInfoAccount>;
|
||||
export const StakeConfigInfoAccount = type({
|
||||
type: literal("stakeConfig"),
|
||||
info: StakeConfigInfo,
|
||||
});
|
||||
|
||||
export type ConfigAccount = StructType<typeof ConfigAccount>;
|
||||
export type ConfigAccount = Infer<typeof ConfigAccount>;
|
||||
export const ConfigAccount = union([
|
||||
StakeConfigInfoAccount,
|
||||
ValidatorInfoAccount,
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
/* eslint-disable @typescript-eslint/no-redeclare */
|
||||
|
||||
import { StructType, object, string, enums, pick } from "superstruct";
|
||||
import { Pubkey } from "validators/pubkey";
|
||||
import { Infer, string, enums, type } from "superstruct";
|
||||
import { PublicKeyFromString } from "validators/pubkey";
|
||||
|
||||
export type NonceAccountType = StructType<typeof NonceAccountType>;
|
||||
export type NonceAccountType = Infer<typeof NonceAccountType>;
|
||||
export const NonceAccountType = enums(["uninitialized", "initialized"]);
|
||||
|
||||
export type NonceAccountInfo = StructType<typeof NonceAccountInfo>;
|
||||
export const NonceAccountInfo = pick({
|
||||
authority: Pubkey,
|
||||
export type NonceAccountInfo = Infer<typeof NonceAccountInfo>;
|
||||
export const NonceAccountInfo = type({
|
||||
authority: PublicKeyFromString,
|
||||
blockhash: string(),
|
||||
feeCalculator: pick({
|
||||
feeCalculator: type({
|
||||
lamportsPerSignature: string(),
|
||||
}),
|
||||
});
|
||||
|
||||
export type NonceAccount = StructType<typeof NonceAccount>;
|
||||
export const NonceAccount = object({
|
||||
export type NonceAccount = Infer<typeof NonceAccount>;
|
||||
export const NonceAccount = type({
|
||||
type: NonceAccountType,
|
||||
info: NonceAccountInfo,
|
||||
});
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/* eslint-disable @typescript-eslint/no-redeclare */
|
||||
|
||||
import { object, StructType, number, nullable, enums } from "superstruct";
|
||||
import { Pubkey } from "validators/pubkey";
|
||||
import { BigNum } from "validators/bignum";
|
||||
import { Infer, number, nullable, enums, type } from "superstruct";
|
||||
import { PublicKeyFromString } from "validators/pubkey";
|
||||
import { BigNumFromString } from "validators/bignum";
|
||||
|
||||
export type StakeAccountType = StructType<typeof StakeAccountType>;
|
||||
export type StakeAccountType = Infer<typeof StakeAccountType>;
|
||||
export const StakeAccountType = enums([
|
||||
"uninitialized",
|
||||
"initialized",
|
||||
|
@ -12,30 +12,30 @@ export const StakeAccountType = enums([
|
|||
"rewardsPool",
|
||||
]);
|
||||
|
||||
export type StakeMeta = StructType<typeof StakeMeta>;
|
||||
export const StakeMeta = object({
|
||||
rentExemptReserve: BigNum,
|
||||
authorized: object({
|
||||
staker: Pubkey,
|
||||
withdrawer: Pubkey,
|
||||
export type StakeMeta = Infer<typeof StakeMeta>;
|
||||
export const StakeMeta = type({
|
||||
rentExemptReserve: BigNumFromString,
|
||||
authorized: type({
|
||||
staker: PublicKeyFromString,
|
||||
withdrawer: PublicKeyFromString,
|
||||
}),
|
||||
lockup: object({
|
||||
lockup: type({
|
||||
unixTimestamp: number(),
|
||||
epoch: number(),
|
||||
custodian: Pubkey,
|
||||
custodian: PublicKeyFromString,
|
||||
}),
|
||||
});
|
||||
|
||||
export type StakeAccountInfo = StructType<typeof StakeAccountInfo>;
|
||||
export const StakeAccountInfo = object({
|
||||
export type StakeAccountInfo = Infer<typeof StakeAccountInfo>;
|
||||
export const StakeAccountInfo = type({
|
||||
meta: StakeMeta,
|
||||
stake: nullable(
|
||||
object({
|
||||
delegation: object({
|
||||
voter: Pubkey,
|
||||
stake: BigNum,
|
||||
activationEpoch: BigNum,
|
||||
deactivationEpoch: BigNum,
|
||||
type({
|
||||
delegation: type({
|
||||
voter: PublicKeyFromString,
|
||||
stake: BigNumFromString,
|
||||
activationEpoch: BigNumFromString,
|
||||
deactivationEpoch: BigNumFromString,
|
||||
warmupCooldownRate: number(),
|
||||
}),
|
||||
creditsObserved: number(),
|
||||
|
@ -43,8 +43,8 @@ export const StakeAccountInfo = object({
|
|||
),
|
||||
});
|
||||
|
||||
export type StakeAccount = StructType<typeof StakeAccount>;
|
||||
export const StakeAccount = object({
|
||||
export type StakeAccount = Infer<typeof StakeAccount>;
|
||||
export const StakeAccount = type({
|
||||
type: StakeAccountType,
|
||||
info: StakeAccountInfo,
|
||||
});
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
/* eslint-disable @typescript-eslint/no-redeclare */
|
||||
|
||||
import {
|
||||
StructType,
|
||||
Infer,
|
||||
enums,
|
||||
array,
|
||||
number,
|
||||
object,
|
||||
type,
|
||||
boolean,
|
||||
string,
|
||||
pick,
|
||||
literal,
|
||||
union,
|
||||
} from "superstruct";
|
||||
|
||||
export type SysvarAccountType = StructType<typeof SysvarAccountType>;
|
||||
export type SysvarAccountType = Infer<typeof SysvarAccountType>;
|
||||
export const SysvarAccountType = enums([
|
||||
"clock",
|
||||
"epochSchedule",
|
||||
|
@ -26,22 +25,22 @@ export const SysvarAccountType = enums([
|
|||
"stakeHistory",
|
||||
]);
|
||||
|
||||
export type ClockAccountInfo = StructType<typeof ClockAccountInfo>;
|
||||
export const ClockAccountInfo = pick({
|
||||
export type ClockAccountInfo = Infer<typeof ClockAccountInfo>;
|
||||
export const ClockAccountInfo = type({
|
||||
slot: number(),
|
||||
epoch: number(),
|
||||
leaderScheduleEpoch: number(),
|
||||
unixTimestamp: number(),
|
||||
});
|
||||
|
||||
export type SysvarClockAccount = StructType<typeof SysvarClockAccount>;
|
||||
export const SysvarClockAccount = object({
|
||||
export type SysvarClockAccount = Infer<typeof SysvarClockAccount>;
|
||||
export const SysvarClockAccount = type({
|
||||
type: literal("clock"),
|
||||
info: ClockAccountInfo,
|
||||
});
|
||||
|
||||
export type EpochScheduleInfo = StructType<typeof EpochScheduleInfo>;
|
||||
export const EpochScheduleInfo = pick({
|
||||
export type EpochScheduleInfo = Infer<typeof EpochScheduleInfo>;
|
||||
export const EpochScheduleInfo = type({
|
||||
slotsPerEpoch: number(),
|
||||
leaderScheduleSlotOffset: number(),
|
||||
warmup: boolean(),
|
||||
|
@ -49,126 +48,120 @@ export const EpochScheduleInfo = pick({
|
|||
firstNormalSlot: number(),
|
||||
});
|
||||
|
||||
export type SysvarEpochScheduleAccount = StructType<
|
||||
export type SysvarEpochScheduleAccount = Infer<
|
||||
typeof SysvarEpochScheduleAccount
|
||||
>;
|
||||
export const SysvarEpochScheduleAccount = object({
|
||||
export const SysvarEpochScheduleAccount = type({
|
||||
type: literal("epochSchedule"),
|
||||
info: EpochScheduleInfo,
|
||||
});
|
||||
|
||||
export type FeesInfo = StructType<typeof FeesInfo>;
|
||||
export const FeesInfo = pick({
|
||||
feeCalculator: pick({
|
||||
export type FeesInfo = Infer<typeof FeesInfo>;
|
||||
export const FeesInfo = type({
|
||||
feeCalculator: type({
|
||||
lamportsPerSignature: string(),
|
||||
}),
|
||||
});
|
||||
|
||||
export type SysvarFeesAccount = StructType<typeof SysvarFeesAccount>;
|
||||
export const SysvarFeesAccount = object({
|
||||
export type SysvarFeesAccount = Infer<typeof SysvarFeesAccount>;
|
||||
export const SysvarFeesAccount = type({
|
||||
type: literal("fees"),
|
||||
info: FeesInfo,
|
||||
});
|
||||
|
||||
export type RecentBlockhashesEntry = StructType<typeof RecentBlockhashesEntry>;
|
||||
export const RecentBlockhashesEntry = pick({
|
||||
export type RecentBlockhashesEntry = Infer<typeof RecentBlockhashesEntry>;
|
||||
export const RecentBlockhashesEntry = type({
|
||||
blockhash: string(),
|
||||
feeCalculator: pick({
|
||||
feeCalculator: type({
|
||||
lamportsPerSignature: string(),
|
||||
}),
|
||||
});
|
||||
|
||||
export type RecentBlockhashesInfo = StructType<typeof RecentBlockhashesInfo>;
|
||||
export type RecentBlockhashesInfo = Infer<typeof RecentBlockhashesInfo>;
|
||||
export const RecentBlockhashesInfo = array(RecentBlockhashesEntry);
|
||||
|
||||
export type SysvarRecentBlockhashesAccount = StructType<
|
||||
export type SysvarRecentBlockhashesAccount = Infer<
|
||||
typeof SysvarRecentBlockhashesAccount
|
||||
>;
|
||||
export const SysvarRecentBlockhashesAccount = object({
|
||||
export const SysvarRecentBlockhashesAccount = type({
|
||||
type: literal("recentBlockhashes"),
|
||||
info: RecentBlockhashesInfo,
|
||||
});
|
||||
|
||||
export type RentInfo = StructType<typeof RentInfo>;
|
||||
export const RentInfo = pick({
|
||||
export type RentInfo = Infer<typeof RentInfo>;
|
||||
export const RentInfo = type({
|
||||
lamportsPerByteYear: string(),
|
||||
exemptionThreshold: number(),
|
||||
burnPercent: number(),
|
||||
});
|
||||
|
||||
export type SysvarRentAccount = StructType<typeof SysvarRentAccount>;
|
||||
export const SysvarRentAccount = object({
|
||||
export type SysvarRentAccount = Infer<typeof SysvarRentAccount>;
|
||||
export const SysvarRentAccount = type({
|
||||
type: literal("rent"),
|
||||
info: RentInfo,
|
||||
});
|
||||
|
||||
export type RewardsInfo = StructType<typeof RewardsInfo>;
|
||||
export const RewardsInfo = pick({
|
||||
export type RewardsInfo = Infer<typeof RewardsInfo>;
|
||||
export const RewardsInfo = type({
|
||||
validatorPointValue: number(),
|
||||
});
|
||||
|
||||
export type SysvarRewardsAccount = StructType<typeof SysvarRewardsAccount>;
|
||||
export const SysvarRewardsAccount = object({
|
||||
export type SysvarRewardsAccount = Infer<typeof SysvarRewardsAccount>;
|
||||
export const SysvarRewardsAccount = type({
|
||||
type: literal("rewards"),
|
||||
info: RewardsInfo,
|
||||
});
|
||||
|
||||
export type SlotHashEntry = StructType<typeof SlotHashEntry>;
|
||||
export const SlotHashEntry = pick({
|
||||
export type SlotHashEntry = Infer<typeof SlotHashEntry>;
|
||||
export const SlotHashEntry = type({
|
||||
slot: number(),
|
||||
hash: string(),
|
||||
});
|
||||
|
||||
export type SlotHashesInfo = StructType<typeof SlotHashesInfo>;
|
||||
export type SlotHashesInfo = Infer<typeof SlotHashesInfo>;
|
||||
export const SlotHashesInfo = array(SlotHashEntry);
|
||||
|
||||
export type SysvarSlotHashesAccount = StructType<
|
||||
typeof SysvarSlotHashesAccount
|
||||
>;
|
||||
export const SysvarSlotHashesAccount = object({
|
||||
export type SysvarSlotHashesAccount = Infer<typeof SysvarSlotHashesAccount>;
|
||||
export const SysvarSlotHashesAccount = type({
|
||||
type: literal("slotHashes"),
|
||||
info: SlotHashesInfo,
|
||||
});
|
||||
|
||||
export type SlotHistoryInfo = StructType<typeof SlotHistoryInfo>;
|
||||
export const SlotHistoryInfo = pick({
|
||||
export type SlotHistoryInfo = Infer<typeof SlotHistoryInfo>;
|
||||
export const SlotHistoryInfo = type({
|
||||
nextSlot: number(),
|
||||
bits: string(),
|
||||
});
|
||||
|
||||
export type SysvarSlotHistoryAccount = StructType<
|
||||
typeof SysvarSlotHistoryAccount
|
||||
>;
|
||||
export const SysvarSlotHistoryAccount = object({
|
||||
export type SysvarSlotHistoryAccount = Infer<typeof SysvarSlotHistoryAccount>;
|
||||
export const SysvarSlotHistoryAccount = type({
|
||||
type: literal("slotHistory"),
|
||||
info: SlotHistoryInfo,
|
||||
});
|
||||
|
||||
export type StakeHistoryEntryItem = StructType<typeof StakeHistoryEntryItem>;
|
||||
export const StakeHistoryEntryItem = pick({
|
||||
export type StakeHistoryEntryItem = Infer<typeof StakeHistoryEntryItem>;
|
||||
export const StakeHistoryEntryItem = type({
|
||||
effective: number(),
|
||||
activating: number(),
|
||||
deactivating: number(),
|
||||
});
|
||||
|
||||
export type StakeHistoryEntry = StructType<typeof StakeHistoryEntry>;
|
||||
export const StakeHistoryEntry = pick({
|
||||
export type StakeHistoryEntry = Infer<typeof StakeHistoryEntry>;
|
||||
export const StakeHistoryEntry = type({
|
||||
epoch: number(),
|
||||
stakeHistory: StakeHistoryEntryItem,
|
||||
});
|
||||
|
||||
export type StakeHistoryInfo = StructType<typeof StakeHistoryInfo>;
|
||||
export type StakeHistoryInfo = Infer<typeof StakeHistoryInfo>;
|
||||
export const StakeHistoryInfo = array(StakeHistoryEntry);
|
||||
|
||||
export type SysvarStakeHistoryAccount = StructType<
|
||||
typeof SysvarStakeHistoryAccount
|
||||
>;
|
||||
export const SysvarStakeHistoryAccount = object({
|
||||
export type SysvarStakeHistoryAccount = Infer<typeof SysvarStakeHistoryAccount>;
|
||||
export const SysvarStakeHistoryAccount = type({
|
||||
type: literal("stakeHistory"),
|
||||
info: StakeHistoryInfo,
|
||||
});
|
||||
|
||||
export type SysvarAccount = StructType<typeof SysvarAccount>;
|
||||
export type SysvarAccount = Infer<typeof SysvarAccount>;
|
||||
export const SysvarAccount = union([
|
||||
SysvarClockAccount,
|
||||
SysvarEpochScheduleAccount,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* eslint-disable @typescript-eslint/no-redeclare */
|
||||
|
||||
import {
|
||||
StructType,
|
||||
Infer,
|
||||
number,
|
||||
optional,
|
||||
enums,
|
||||
|
@ -9,55 +9,55 @@ import {
|
|||
boolean,
|
||||
string,
|
||||
array,
|
||||
pick,
|
||||
type,
|
||||
nullable,
|
||||
} from "superstruct";
|
||||
import { Pubkey } from "validators/pubkey";
|
||||
import { PublicKeyFromString } from "validators/pubkey";
|
||||
|
||||
export type TokenAccountType = StructType<typeof TokenAccountType>;
|
||||
export type TokenAccountType = Infer<typeof TokenAccountType>;
|
||||
export const TokenAccountType = enums(["mint", "account", "multisig"]);
|
||||
|
||||
export type TokenAccountState = StructType<typeof AccountState>;
|
||||
export type TokenAccountState = Infer<typeof AccountState>;
|
||||
const AccountState = enums(["initialized", "uninitialized", "frozen"]);
|
||||
|
||||
const TokenAmount = pick({
|
||||
const TokenAmount = type({
|
||||
decimals: number(),
|
||||
uiAmountString: string(),
|
||||
amount: string(),
|
||||
});
|
||||
|
||||
export type TokenAccountInfo = StructType<typeof TokenAccountInfo>;
|
||||
export const TokenAccountInfo = pick({
|
||||
mint: Pubkey,
|
||||
owner: Pubkey,
|
||||
export type TokenAccountInfo = Infer<typeof TokenAccountInfo>;
|
||||
export const TokenAccountInfo = type({
|
||||
mint: PublicKeyFromString,
|
||||
owner: PublicKeyFromString,
|
||||
tokenAmount: TokenAmount,
|
||||
delegate: optional(Pubkey),
|
||||
delegate: optional(PublicKeyFromString),
|
||||
state: AccountState,
|
||||
isNative: boolean(),
|
||||
rentExemptReserve: optional(TokenAmount),
|
||||
delegatedAmount: optional(TokenAmount),
|
||||
closeAuthority: optional(Pubkey),
|
||||
closeAuthority: optional(PublicKeyFromString),
|
||||
});
|
||||
|
||||
export type MintAccountInfo = StructType<typeof MintAccountInfo>;
|
||||
export const MintAccountInfo = pick({
|
||||
mintAuthority: nullable(Pubkey),
|
||||
export type MintAccountInfo = Infer<typeof MintAccountInfo>;
|
||||
export const MintAccountInfo = type({
|
||||
mintAuthority: nullable(PublicKeyFromString),
|
||||
supply: string(),
|
||||
decimals: number(),
|
||||
isInitialized: boolean(),
|
||||
freezeAuthority: nullable(Pubkey),
|
||||
freezeAuthority: nullable(PublicKeyFromString),
|
||||
});
|
||||
|
||||
export type MultisigAccountInfo = StructType<typeof MultisigAccountInfo>;
|
||||
export const MultisigAccountInfo = pick({
|
||||
export type MultisigAccountInfo = Infer<typeof MultisigAccountInfo>;
|
||||
export const MultisigAccountInfo = type({
|
||||
numRequiredSigners: number(),
|
||||
numValidSigners: number(),
|
||||
isInitialized: boolean(),
|
||||
signers: array(Pubkey),
|
||||
signers: array(PublicKeyFromString),
|
||||
});
|
||||
|
||||
export type TokenAccount = StructType<typeof TokenAccount>;
|
||||
export const TokenAccount = pick({
|
||||
export type TokenAccount = Infer<typeof TokenAccount>;
|
||||
export const TokenAccount = type({
|
||||
type: TokenAccountType,
|
||||
info: any(),
|
||||
});
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
/* eslint-disable @typescript-eslint/no-redeclare */
|
||||
|
||||
import { StructType, pick, number, nullable, literal } from "superstruct";
|
||||
import { Pubkey } from "validators/pubkey";
|
||||
import { type, number, literal, nullable, Infer } from "superstruct";
|
||||
import { PublicKeyFromString } from "validators/pubkey";
|
||||
|
||||
export type ProgramAccountInfo = StructType<typeof ProgramAccountInfo>;
|
||||
export const ProgramAccountInfo = pick({
|
||||
programData: Pubkey,
|
||||
export type ProgramAccountInfo = Infer<typeof ProgramAccountInfo>;
|
||||
export const ProgramAccountInfo = type({
|
||||
programData: PublicKeyFromString,
|
||||
});
|
||||
|
||||
export type ProgramAccount = StructType<typeof ProgramDataAccount>;
|
||||
export const ProgramAccount = pick({
|
||||
export type ProgramAccount = Infer<typeof ProgramDataAccount>;
|
||||
export const ProgramAccount = type({
|
||||
type: literal("program"),
|
||||
info: ProgramAccountInfo,
|
||||
});
|
||||
|
||||
export type ProgramDataAccountInfo = StructType<typeof ProgramDataAccountInfo>;
|
||||
export const ProgramDataAccountInfo = pick({
|
||||
authority: nullable(Pubkey),
|
||||
export type ProgramDataAccountInfo = Infer<typeof ProgramDataAccountInfo>;
|
||||
export const ProgramDataAccountInfo = type({
|
||||
authority: nullable(PublicKeyFromString),
|
||||
// don't care about data yet
|
||||
slot: number(),
|
||||
});
|
||||
|
||||
export type ProgramDataAccount = StructType<typeof ProgramDataAccount>;
|
||||
export const ProgramDataAccount = pick({
|
||||
export type ProgramDataAccount = Infer<typeof ProgramDataAccount>;
|
||||
export const ProgramDataAccount = type({
|
||||
type: literal("programData"),
|
||||
info: ProgramDataAccountInfo,
|
||||
});
|
||||
|
|
|
@ -1,64 +1,63 @@
|
|||
/* eslint-disable @typescript-eslint/no-redeclare */
|
||||
|
||||
import {
|
||||
StructType,
|
||||
Infer,
|
||||
enums,
|
||||
pick,
|
||||
number,
|
||||
array,
|
||||
object,
|
||||
type,
|
||||
nullable,
|
||||
string,
|
||||
} from "superstruct";
|
||||
import { Pubkey } from "validators/pubkey";
|
||||
import { PublicKeyFromString } from "validators/pubkey";
|
||||
|
||||
export type VoteAccountType = StructType<typeof VoteAccountType>;
|
||||
export type VoteAccountType = Infer<typeof VoteAccountType>;
|
||||
export const VoteAccountType = enums(["vote"]);
|
||||
|
||||
export type AuthorizedVoter = StructType<typeof AuthorizedVoter>;
|
||||
export const AuthorizedVoter = pick({
|
||||
authorizedVoter: Pubkey,
|
||||
export type AuthorizedVoter = Infer<typeof AuthorizedVoter>;
|
||||
export const AuthorizedVoter = type({
|
||||
authorizedVoter: PublicKeyFromString,
|
||||
epoch: number(),
|
||||
});
|
||||
|
||||
export type PriorVoter = StructType<typeof PriorVoter>;
|
||||
export const PriorVoter = pick({
|
||||
authorizedPubkey: Pubkey,
|
||||
export type PriorVoter = Infer<typeof PriorVoter>;
|
||||
export const PriorVoter = type({
|
||||
authorizedPubkey: PublicKeyFromString,
|
||||
epochOfLastAuthorizedSwitch: number(),
|
||||
targetEpoch: number(),
|
||||
});
|
||||
|
||||
export type EpochCredits = StructType<typeof EpochCredits>;
|
||||
export const EpochCredits = pick({
|
||||
export type EpochCredits = Infer<typeof EpochCredits>;
|
||||
export const EpochCredits = type({
|
||||
epoch: number(),
|
||||
credits: string(),
|
||||
previousCredits: string(),
|
||||
});
|
||||
|
||||
export type Vote = StructType<typeof Vote>;
|
||||
export const Vote = object({
|
||||
export type Vote = Infer<typeof Vote>;
|
||||
export const Vote = type({
|
||||
slot: number(),
|
||||
confirmationCount: number(),
|
||||
});
|
||||
|
||||
export type VoteAccountInfo = StructType<typeof VoteAccountInfo>;
|
||||
export const VoteAccountInfo = pick({
|
||||
export type VoteAccountInfo = Infer<typeof VoteAccountInfo>;
|
||||
export const VoteAccountInfo = type({
|
||||
authorizedVoters: array(AuthorizedVoter),
|
||||
authorizedWithdrawer: Pubkey,
|
||||
authorizedWithdrawer: PublicKeyFromString,
|
||||
commission: number(),
|
||||
epochCredits: array(EpochCredits),
|
||||
lastTimestamp: object({
|
||||
lastTimestamp: type({
|
||||
slot: number(),
|
||||
timestamp: number(),
|
||||
}),
|
||||
nodePubkey: Pubkey,
|
||||
nodePubkey: PublicKeyFromString,
|
||||
priorVoters: array(PriorVoter),
|
||||
rootSlot: nullable(number()),
|
||||
votes: array(Vote),
|
||||
});
|
||||
|
||||
export type VoteAccount = StructType<typeof VoteAccount>;
|
||||
export const VoteAccount = pick({
|
||||
export type VoteAccount = Infer<typeof VoteAccount>;
|
||||
export const VoteAccount = type({
|
||||
type: VoteAccountType,
|
||||
info: VoteAccountInfo,
|
||||
});
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { coercion, struct, Struct } from "superstruct";
|
||||
import { coerce, instance, string } from "superstruct";
|
||||
import BN from "bn.js";
|
||||
|
||||
export const BigNumValue = struct("BigNum", (value) => value instanceof BN);
|
||||
export const BigNum: Struct<BN, any> = coercion(BigNumValue, (value) => {
|
||||
export const BigNumFromString = coerce(instance(BN), string(), (value) => {
|
||||
if (typeof value === "string") return new BN(value, 10);
|
||||
throw new Error("invalid big num");
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/* eslint-disable @typescript-eslint/no-redeclare */
|
||||
|
||||
import { object, any, StructType, string } from "superstruct";
|
||||
import { type, any, Infer, string } from "superstruct";
|
||||
|
||||
export type ParsedInfo = StructType<typeof ParsedInfo>;
|
||||
export const ParsedInfo = object({
|
||||
export type ParsedInfo = Infer<typeof ParsedInfo>;
|
||||
export const ParsedInfo = type({
|
||||
type: string(),
|
||||
info: any(),
|
||||
});
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { coercion, struct, Struct } from "superstruct";
|
||||
import { coerce, instance, string } from "superstruct";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
|
||||
const PubkeyValue = struct("Pubkey", (value) => value instanceof PublicKey);
|
||||
export const Pubkey: Struct<PublicKey, any> = coercion(PubkeyValue, (value) => {
|
||||
if (typeof value === "string") return new PublicKey(value);
|
||||
throw new Error("invalid pubkey");
|
||||
});
|
||||
export const PublicKeyFromString = coerce(
|
||||
instance(PublicKey),
|
||||
string(),
|
||||
(value) => new PublicKey(value)
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue