Skip to content

Commit

Permalink
Import program types from new @solana/programs in js-experimental cli…
Browse files Browse the repository at this point in the history
…ent (#141)
  • Loading branch information
lorisleiva authored Jan 5, 2024
1 parent 69a9f3e commit 8784db9
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 124 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-rings-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@metaplex-foundation/kinobi': patch
---

Import program types from new @solana/programs in js-experimental client
1 change: 1 addition & 0 deletions src/renderers/js-experimental/ImportMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const DEFAULT_MODULE_MAP: Record<string, string> = {
solanaCodecsStrings: '@solana/codecs-strings',
solanaCodecsDataStructures: '@solana/codecs-data-structures',
solanaInstructions: '@solana/instructions',
solanaPrograms: '@solana/programs',
solanaOptions: '@solana/options',
solanaSigners: '@solana/signers',
solanaTransactions: '@solana/transactions',
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/js-experimental/fragments/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export function getProgramFragment(
programGetErrorFromCodeFunction,
})
.addImports('solanaAddresses', ['Address'])
.addImports('shared', ['Program']);
.addImports('solanaPrograms', ['Program']);

if (programNode.errors.length > 0) {
programFragment
.addImports('shared', ['ProgramWithErrors'])
.addImports('solanaPrograms', ['ProgramWithErrors'])
.addImports('generatedErrors', [
programErrorClass,
programErrorCode,
Expand Down
10 changes: 0 additions & 10 deletions src/renderers/js-experimental/templates/sharedPage.njk
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,6 @@ export function isTransactionSigner<TAddress extends string = string>(value: Add
return !!value && typeof value === 'object' && 'address' in value && web3JsIsTransactionSigner(value);
}

export type Program<TAddress extends string = string> = {
name: string;
address: Address<TAddress>;
getErrorFromCode?: (code: number, cause?: Error) => Error,
}

export type ProgramWithErrors<TErrorCode extends number = number, TError extends Error = Error> = {
getErrorFromCode: (code: TErrorCode, cause?: Error) => TError,
}

export function memcmp(data: Uint8Array, bytes: Uint8Array, offset: number) {
const slice = data.slice(offset, offset + bytes.length);
if (slice.length !== bytes.length) return false;
Expand Down
23 changes: 12 additions & 11 deletions test/packages/js-experimental/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
"author": "",
"license": "ISC",
"dependencies": {
"@solana/accounts": "2.0.0-experimental.9741939",
"@solana/addresses": "2.0.0-experimental.9741939",
"@solana/codecs-core": "2.0.0-experimental.9741939",
"@solana/codecs-data-structures": "2.0.0-experimental.9741939",
"@solana/codecs-numbers": "2.0.0-experimental.9741939",
"@solana/codecs-strings": "2.0.0-experimental.9741939",
"@solana/instructions": "2.0.0-experimental.9741939",
"@solana/keys": "2.0.0-experimental.9741939",
"@solana/options": "2.0.0-experimental.9741939",
"@solana/signers": "2.0.0-experimental.9741939",
"@solana/transactions": "2.0.0-experimental.9741939"
"@solana/accounts": "2.0.0-experimental.5e737f9",
"@solana/addresses": "2.0.0-experimental.5e737f9",
"@solana/codecs-core": "2.0.0-experimental.5e737f9",
"@solana/codecs-data-structures": "2.0.0-experimental.5e737f9",
"@solana/codecs-numbers": "2.0.0-experimental.5e737f9",
"@solana/codecs-strings": "2.0.0-experimental.5e737f9",
"@solana/instructions": "2.0.0-experimental.5e737f9",
"@solana/keys": "2.0.0-experimental.5e737f9",
"@solana/programs": "2.0.0-experimental.5e737f9",
"@solana/options": "2.0.0-experimental.5e737f9",
"@solana/signers": "2.0.0-experimental.5e737f9",
"@solana/transactions": "2.0.0-experimental.5e737f9"
},
"devDependencies": {
"typescript": "^4.9.4"
Expand Down
179 changes: 95 additions & 84 deletions test/packages/js-experimental/pnpm-lock.yaml

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

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
*/

import { Address } from '@solana/addresses';
import { Program, ProgramWithErrors } from '@solana/programs';
import {
MplCandyMachineCoreProgramError,
MplCandyMachineCoreProgramErrorCode,
getMplCandyMachineCoreProgramErrorFromCode,
} from '../errors';
import { Program, ProgramWithErrors, memcmp } from '../shared';
import { memcmp } from '../shared';

export const MPL_CANDY_MACHINE_CORE_PROGRAM_ADDRESS =
'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR' as Address<'CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR'>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

import { Address } from '@solana/addresses';
import { getU64Encoder, getU8Encoder } from '@solana/codecs-numbers';
import { Program, ProgramWithErrors } from '@solana/programs';
import {
MplTokenAuthRulesProgramError,
MplTokenAuthRulesProgramErrorCode,
getMplTokenAuthRulesProgramErrorFromCode,
} from '../errors';
import { Program, ProgramWithErrors, memcmp } from '../shared';
import { memcmp } from '../shared';
import { TaKey } from '../types';

export const MPL_TOKEN_AUTH_RULES_PROGRAM_ADDRESS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

import { Address } from '@solana/addresses';
import { getU8Encoder } from '@solana/codecs-numbers';
import { Program, ProgramWithErrors } from '@solana/programs';
import {
MplTokenMetadataProgramError,
MplTokenMetadataProgramErrorCode,
getMplTokenMetadataProgramErrorFromCode,
} from '../errors';
import { Program, ProgramWithErrors, memcmp } from '../shared';
import { memcmp } from '../shared';
import { TmKey, getTmKeyEncoder } from '../types';

export const MPL_TOKEN_METADATA_PROGRAM_ADDRESS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import { Address } from '@solana/addresses';
import { getU32Encoder } from '@solana/codecs-numbers';
import { Program, memcmp } from '../shared';
import { Program } from '@solana/programs';
import { memcmp } from '../shared';

export const SPL_SYSTEM_PROGRAM_ADDRESS =
'11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
Expand Down
Loading

0 comments on commit 8784db9

Please sign in to comment.