Skip to content

Commit

Permalink
add support for new compute budget instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
ngundotra committed Nov 17, 2024
1 parent b00cc9a commit 4b1764d
Show file tree
Hide file tree
Showing 4 changed files with 453 additions and 269 deletions.
48 changes: 48 additions & 0 deletions .pnpmfile.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//@ts-check

// https://pnpm.io/pnpmfile
// https://github.com/pnpm/pnpm/issues/4214
// https://github.com/pnpm/pnpm/issues/5391

const rootPkg = require('./package.json');

console.log (`Checking for package peerDependency overrides`);

const remapPeerDependencies = [
{ package: '@solana-program/compute-budget', packageVersion: '0.6.1', peerDependency: '@solana/web3.js', newVersion: '2.0.0' },
];

function overridesPeerDependencies(pkg) {
if (pkg.peerDependencies) {
remapPeerDependencies.map(dep => {
if (pkg.name === dep.package && pkg.version.startsWith(dep.packageVersion)) {
console.log(` - Checking ${pkg.name}@${pkg.version}`); // , pkg.peerDependencies);

if (dep.peerDependency in pkg.peerDependencies) {
try {
console.log(` - Overriding ${pkg.name}@${pkg.version} peerDependency ${dep.peerDependency}@${pkg.peerDependencies[dep.peerDependency]}`);

// First add a new dependency to the package and then remove the peer dependency.
// This approach has the added advantage that scoped overrides should now work, too.
pkg.dependencies[dep.peerDependency] = dep.newVersion;
delete pkg.peerDependencies[dep.peerDependency];

console.log(` - Overrode ${pkg.name}@${pkg.version} peerDependency ${dep.peerDependency}@${pkg.dependencies[dep.peerDependency]}`);
} catch (err) {
console.error(err);
}
}
}
});
}
}

module.exports = {
hooks: {
readPackage(pkg, _context) {
// skipDeps(pkg);
overridesPeerDependencies(pkg);
return pkg;
},
},
};
76 changes: 65 additions & 11 deletions app/components/instruction/ComputeBudgetDetailsCard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { Address } from '@components/common/Address';
import { SolBalance } from '@components/common/SolBalance';
import { useCluster } from '@providers/cluster';
import { ComputeBudgetInstruction, SignatureResult, TransactionInstruction } from '@solana/web3.js';
import { SignatureResult, TransactionInstruction } from '@solana/web3.js';
import {
ComputeBudgetInstruction,
identifyComputeBudgetInstruction,
parseRequestHeapFrameInstruction,
parseRequestUnitsInstruction,
parseSetComputeUnitLimitInstruction,
parseSetComputeUnitPriceInstruction,
parseSetLoadedAccountsDataSizeLimitInstruction,
} from '@solana-program/compute-budget';
import { microLamportsToLamportsString } from '@utils/index';
import React from 'react';
import { address } from 'web3js-experimental';

import { InstructionCard } from './InstructionCard';
import { SolBalance } from '../common/SolBalance';

export function ComputeBudgetDetailsCard({
ix,
Expand All @@ -24,10 +34,15 @@ export function ComputeBudgetDetailsCard({
}) {
const { url } = useCluster();
try {
const type = ComputeBudgetInstruction.decodeInstructionType(ix);
const type = identifyComputeBudgetInstruction(ix);
switch (type) {
case 'RequestUnits': {
const { units, additionalFee } = ComputeBudgetInstruction.decodeRequestUnits(ix);
case ComputeBudgetInstruction.RequestUnits: {
const {
data: { units, additionalFee },
} = parseRequestUnitsInstruction({
...ix,
programAddress: address(ix.programId.toBase58()),
});
return (
<InstructionCard
ix={ix}
Expand Down Expand Up @@ -60,8 +75,10 @@ export function ComputeBudgetDetailsCard({
</InstructionCard>
);
}
case 'RequestHeapFrame': {
const { bytes } = ComputeBudgetInstruction.decodeRequestHeapFrame(ix);
case ComputeBudgetInstruction.RequestHeapFrame: {
const {
data: { bytes },
} = parseRequestHeapFrameInstruction({ ...ix, programAddress: address(ix.programId.toBase58()) });
return (
<InstructionCard
ix={ix}
Expand All @@ -87,8 +104,10 @@ export function ComputeBudgetDetailsCard({
</InstructionCard>
);
}
case 'SetComputeUnitLimit': {
const { units } = ComputeBudgetInstruction.decodeSetComputeUnitLimit(ix);
case ComputeBudgetInstruction.SetComputeUnitLimit: {
const {
data: { units },
} = parseSetComputeUnitLimitInstruction({ ...ix, programAddress: address(ix.programId.toBase58()) });
return (
<InstructionCard
ix={ix}
Expand All @@ -114,8 +133,13 @@ export function ComputeBudgetDetailsCard({
</InstructionCard>
);
}
case 'SetComputeUnitPrice': {
const { microLamports } = ComputeBudgetInstruction.decodeSetComputeUnitPrice(ix);
case ComputeBudgetInstruction.SetComputeUnitPrice: {
const {
data: { microLamports },
} = parseSetComputeUnitPriceInstruction({
...ix,
programAddress: address(ix.programId.toBase58()),
});
return (
<InstructionCard
ix={ix}
Expand All @@ -141,6 +165,36 @@ export function ComputeBudgetDetailsCard({
</InstructionCard>
);
}
case ComputeBudgetInstruction.SetLoadedAccountsDataSizeLimit: {
const {
data: { accountDataSizeLimit },
} = parseSetLoadedAccountsDataSizeLimitInstruction({
...ix,
programAddress: address(ix.programId.toBase58()),
});
return (
<InstructionCard
ix={ix}
index={index}
result={result}
title="Compute Budget Program: Set Loaded Account Data Size Limit"
innerCards={innerCards}
childIndex={childIndex}
>
<tr>
<td>Program</td>
<td className="text-lg-end">
<Address pubkey={ix.programId} alignRight link />
</td>
</tr>

<tr>
<td>Account Data Size Limit</td>
<td className="text-lg-end font-monospace">{`${accountDataSizeLimit} bytes`}</td>
</tr>
</InstructionCard>
);
}
}
} catch (error) {
console.error(error, {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@project-serum/serum": "^0.13.61",
"@react-hook/debounce": "^4.0.0",
"@react-hook/previous": "^1.0.1",
"@solana-program/compute-budget": "^0.6.1",
"@solana/buffer-layout": "^3.0.0",
"@solana/spl-account-compression": "^0.1.8",
"@solana/spl-token": "^0.1.8",
Expand Down Expand Up @@ -61,7 +62,7 @@
"typescript": "5.0.4",
"use-async-effect": "^2.2.7",
"use-tab-visibility": "^1.0.9",
"web3js-experimental": "npm:@solana/[email protected]-rc.0"
"web3js-experimental": "npm:@solana/[email protected]"
},
"devDependencies": {
"@solana/eslint-config-solana": "^1.0.1",
Expand Down
Loading

0 comments on commit 4b1764d

Please sign in to comment.