Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Anchor version + support new IDL types #317

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/components/account/AnchorAccountCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ErrorCard } from '@components/common/ErrorCard';
import { BorshAccountsCoder } from '@project-serum/anchor';
import { IdlTypeDef } from '@project-serum/anchor/dist/cjs/idl';
import { BorshAccountsCoder } from '@coral-xyz/anchor';
import { IdlTypeDef } from '@coral-xyz/anchor/dist/cjs/idl';
import { Account } from '@providers/accounts';
import { useAnchorProgram } from '@providers/anchor';
import { useCluster } from '@providers/cluster';
Expand Down
14 changes: 7 additions & 7 deletions app/components/instruction/AnchorDetailsCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address } from '@components/common/Address';
import { BorshInstructionCoder, Idl, Instruction, Program } from '@project-serum/anchor';
import { IdlInstruction } from '@project-serum/anchor/dist/cjs/idl';
import { BorshInstructionCoder, Idl, Instruction, Program } from '@coral-xyz/anchor';
import { IdlInstruction } from '@coral-xyz/anchor/dist/cjs/idl';
import { SignatureResult, TransactionInstruction } from '@solana/web3.js';
import {
getAnchorAccountsFromInstruction,
Expand Down Expand Up @@ -39,11 +39,11 @@ function AnchorDetails({ ix, anchorProgram }: { ix: TransactionInstruction; anch
const { ixAccounts, decodedIxData, ixDef } = useMemo(() => {
let ixAccounts:
| {
name: string;
isMut: boolean;
isSigner: boolean;
pda?: object;
}[]
name: string;
isMut: boolean;
isSigner: boolean;
pda?: object;
}[]
| null = null;
let decodedIxData: Instruction | null = null;
let ixDef: IdlInstruction | undefined;
Expand Down
4 changes: 2 additions & 2 deletions app/providers/anchor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AnchorProvider, Idl, Program, Wallet } from '@coral-xyz/anchor';
import { NodeWallet } from '@metaplex/js';
import { Idl, Program, Provider } from '@project-serum/anchor';
import { Connection, Keypair } from '@solana/web3.js';

const cachedAnchorProgramPromises: Record<
Expand All @@ -14,7 +14,7 @@ export function useAnchorProgram(programAddress: string, url: string): Program |
if (cacheEntry === undefined) {
const promise = Program.at(
programAddress,
new Provider(new Connection(url), new NodeWallet(Keypair.generate()), {})
new AnchorProvider(new Connection(url), new NodeWallet(Keypair.generate()) as Wallet, {})
)
.then(program => {
cachedAnchorProgramPromises[key] = {
Expand Down
28 changes: 17 additions & 11 deletions app/utils/anchor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address } from '@components/common/Address';
import { BorshInstructionCoder, Idl, Program } from '@project-serum/anchor';
import { IdlField, IdlInstruction, IdlType, IdlTypeDef } from '@project-serum/anchor/dist/cjs/idl';
import { BorshInstructionCoder, Idl, Program } from '@coral-xyz/anchor';
import { IdlField, IdlInstruction, IdlType, IdlTypeDef } from '@coral-xyz/anchor/dist/cjs/idl';
import { useAnchorProgram } from '@providers/anchor';
import { PublicKey, TransactionInstruction } from '@solana/web3.js';
import { Cluster } from '@utils/cluster';
Expand Down Expand Up @@ -54,11 +54,11 @@ export function getAnchorAccountsFromInstruction(
program: Program
):
| {
name: string;
isMut: boolean;
isSigner: boolean;
pda?: object;
}[]
name: string;
isMut: boolean;
isSigner: boolean;
pda?: object;
}[]
| null {
if (decodedIx) {
// get ix accounts
Expand Down Expand Up @@ -161,7 +161,9 @@ function mapField(key: string, value: any, type: IdlType, idl: Idl, keySuffix?:
type === 'i64' ||
type === 'f64' ||
type === 'u128' ||
type === 'i128'
type === 'i128' ||
type === 'u256' ||
type === 'i256'
) {
return (
<SimpleRow
Expand Down Expand Up @@ -225,6 +227,8 @@ function mapField(key: string, value: any, type: IdlType, idl: Idl, keySuffix?:
</Fragment>
</ExpandableRow>
);
} else if (fieldType?.type.kind === "alias") {
return mapField(fieldType.name, value, fieldType.type.value, idl, keySuffix, nestingLevel);
} else {
const enumVariantName = Object.keys(value)[0];
const variant = fieldType.type.variants.find(
Expand Down Expand Up @@ -417,8 +421,8 @@ function typeDisplayName(
type:
| IdlType
| {
enum: string;
}
enum: string;
}
): string {
switch (type) {
case 'bool':
Expand All @@ -434,6 +438,8 @@ function typeDisplayName(
case 'f64':
case 'u128':
case 'i128':
case 'u256':
case 'i256':
case 'bytes':
case 'string':
return type.toString();
Expand All @@ -445,6 +451,6 @@ function typeDisplayName(
if ('option' in type) return `${typeDisplayName(type.option)} (optional)`;
if ('vec' in type) return `${typeDisplayName(type.vec)}[]`;
if ('array' in type) return `${typeDisplayName(type.array[0])}[${type.array[1]}]`;
return 'unkonwn';
return 'unknown';
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"@blockworks-foundation/mango-client": "^3.6.7",
"@bonfida/spl-name-service": "0.1.30",
"@cloudflare/stream-react": "^1.2.0",
"@coral-xyz/anchor": "^0.29.0",
"@metamask/jazzicon": "^2.0.0",
"@metaplex-foundation/mpl-token-metadata": "^1.1.0",
"@metaplex/js": "^4.12.0",
"@project-serum/anchor": "^0.23.0",
"@project-serum/serum": "^0.13.61",
"@react-hook/debounce": "^4.0.0",
"@react-hook/previous": "^1.0.1",
Expand Down
72 changes: 43 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.