explorer: Add support for new compute budget ixs (#25446)
This commit is contained in:
parent
773b2f23f4
commit
3b3046ab3d
|
@ -5,7 +5,7 @@ import {
|
||||||
TransactionInstruction,
|
TransactionInstruction,
|
||||||
} from "@solana/web3.js";
|
} from "@solana/web3.js";
|
||||||
import { InstructionCard } from "./InstructionCard";
|
import { InstructionCard } from "./InstructionCard";
|
||||||
import { SolBalance } from "utils";
|
import { microLamportsToLamportsString, SolBalance } from "utils";
|
||||||
import { Address } from "components/common/Address";
|
import { Address } from "components/common/Address";
|
||||||
import { reportError } from "utils/sentry";
|
import { reportError } from "utils/sentry";
|
||||||
import { useCluster } from "providers/cluster";
|
import { useCluster } from "providers/cluster";
|
||||||
|
@ -37,7 +37,7 @@ export function ComputeBudgetDetailsCard({
|
||||||
ix={ix}
|
ix={ix}
|
||||||
index={index}
|
index={index}
|
||||||
result={result}
|
result={result}
|
||||||
title="Compute Budget Program: Request Units"
|
title="Compute Budget Program: Request Units (Deprecated)"
|
||||||
innerCards={innerCards}
|
innerCards={innerCards}
|
||||||
childIndex={childIndex}
|
childIndex={childIndex}
|
||||||
>
|
>
|
||||||
|
@ -50,7 +50,9 @@ export function ComputeBudgetDetailsCard({
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Requested Compute Units</td>
|
<td>Requested Compute Units</td>
|
||||||
<td className="text-lg-end">{units}</td>
|
<td className="text-lg-end font-monospace">{`${new Intl.NumberFormat(
|
||||||
|
"en-US"
|
||||||
|
).format(units)} compute units`}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -82,7 +84,65 @@ export function ComputeBudgetDetailsCard({
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Requested Heap Frame (Bytes)</td>
|
<td>Requested Heap Frame (Bytes)</td>
|
||||||
<td className="text-lg-end">{bytes}</td>
|
<td className="text-lg-end font-monospace">
|
||||||
|
{new Intl.NumberFormat("en-US").format(bytes)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</InstructionCard>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case "SetComputeUnitLimit": {
|
||||||
|
const { units } =
|
||||||
|
ComputeBudgetInstruction.decodeSetComputeUnitLimit(ix);
|
||||||
|
return (
|
||||||
|
<InstructionCard
|
||||||
|
ix={ix}
|
||||||
|
index={index}
|
||||||
|
result={result}
|
||||||
|
title="Compute Budget Program: Set Compute Unit Limit"
|
||||||
|
innerCards={innerCards}
|
||||||
|
childIndex={childIndex}
|
||||||
|
>
|
||||||
|
<tr>
|
||||||
|
<td>Program</td>
|
||||||
|
<td className="text-lg-end">
|
||||||
|
<Address pubkey={ix.programId} alignRight link />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Compute Unit Limit</td>
|
||||||
|
<td className="text-lg-end font-monospace">{`${new Intl.NumberFormat(
|
||||||
|
"en-US"
|
||||||
|
).format(units)} compute units`}</td>
|
||||||
|
</tr>
|
||||||
|
</InstructionCard>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case "SetComputeUnitPrice": {
|
||||||
|
const { microLamports } =
|
||||||
|
ComputeBudgetInstruction.decodeSetComputeUnitPrice(ix);
|
||||||
|
return (
|
||||||
|
<InstructionCard
|
||||||
|
ix={ix}
|
||||||
|
index={index}
|
||||||
|
result={result}
|
||||||
|
title="Compute Budget Program: Set Compute Unit Price"
|
||||||
|
innerCards={innerCards}
|
||||||
|
childIndex={childIndex}
|
||||||
|
>
|
||||||
|
<tr>
|
||||||
|
<td>Program</td>
|
||||||
|
<td className="text-lg-end">
|
||||||
|
<Address pubkey={ix.programId} alignRight link />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Compute Unit Price</td>
|
||||||
|
<td className="text-lg-end font-monospace">{`${microLamportsToLamportsString(
|
||||||
|
microLamports
|
||||||
|
)} lamports per compute unit`}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</InstructionCard>
|
</InstructionCard>
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,7 +6,8 @@ import {
|
||||||
import { PublicKey } from "@solana/web3.js";
|
import { PublicKey } from "@solana/web3.js";
|
||||||
|
|
||||||
// Switch to web3 constant when web3 updates superstruct
|
// Switch to web3 constant when web3 updates superstruct
|
||||||
export const LAMPORTS_PER_SOL = 1000000000;
|
export const LAMPORTS_PER_SOL = 1_000_000_000;
|
||||||
|
export const MICRO_LAMPORTS_PER_LAMPORT = 1_000_000;
|
||||||
|
|
||||||
export const NUM_TICKS_PER_SECOND = 160;
|
export const NUM_TICKS_PER_SECOND = 160;
|
||||||
export const DEFAULT_TICKS_PER_SLOT = 64;
|
export const DEFAULT_TICKS_PER_SLOT = 64;
|
||||||
|
@ -28,6 +29,33 @@ export function normalizeTokenAmount(
|
||||||
return rawTokens / Math.pow(10, decimals);
|
return rawTokens / Math.pow(10, decimals);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function microLamportsToLamports(
|
||||||
|
microLamports: number | bigint
|
||||||
|
): number {
|
||||||
|
if (typeof microLamports === "number") {
|
||||||
|
return microLamports / MICRO_LAMPORTS_PER_LAMPORT;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(microLamports);
|
||||||
|
const microLamportsString = microLamports.toString().padStart(7, "0");
|
||||||
|
const splitIndex = microLamportsString.length - 6;
|
||||||
|
const lamportString =
|
||||||
|
microLamportsString.slice(0, splitIndex) +
|
||||||
|
"." +
|
||||||
|
microLamportsString.slice(splitIndex);
|
||||||
|
return parseFloat(lamportString);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function microLamportsToLamportsString(
|
||||||
|
microLamports: number | bigint,
|
||||||
|
maximumFractionDigits: number = 6
|
||||||
|
): string {
|
||||||
|
const lamports = microLamportsToLamports(microLamports);
|
||||||
|
return new Intl.NumberFormat("en-US", { maximumFractionDigits }).format(
|
||||||
|
lamports
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function lamportsToSol(lamports: number | BN): number {
|
export function lamportsToSol(lamports: number | BN): number {
|
||||||
if (typeof lamports === "number") {
|
if (typeof lamports === "number") {
|
||||||
return Math.abs(lamports) / LAMPORTS_PER_SOL;
|
return Math.abs(lamports) / LAMPORTS_PER_SOL;
|
||||||
|
|
Loading…
Reference in New Issue