From 577701438de83e5f46f1ea4d85fc028c4c581d12 Mon Sep 17 00:00:00 2001 From: Loris Leiva Date: Mon, 11 Dec 2023 11:49:04 +0000 Subject: [PATCH] Update Kinobi --- clients/js/package.json | 1 + clients/js/pnpm-lock.yaml | 21 ++++- .../generated/accounts/addressLookupTable.ts | 26 +++--- clients/js/src/generated/shared/index.ts | 88 ++----------------- package.json | 2 +- pnpm-lock.yaml | 28 +++--- 6 files changed, 53 insertions(+), 113 deletions(-) diff --git a/clients/js/package.json b/clients/js/package.json index 4df3e4c..17128dd 100644 --- a/clients/js/package.json +++ b/clients/js/package.json @@ -25,6 +25,7 @@ "author": "Metaplex Maintainers ", "license": "Apache-2.0", "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", diff --git a/clients/js/pnpm-lock.yaml b/clients/js/pnpm-lock.yaml index 6af33eb..1808ca6 100644 --- a/clients/js/pnpm-lock.yaml +++ b/clients/js/pnpm-lock.yaml @@ -1,6 +1,9 @@ lockfileVersion: '6.0' dependencies: + '@solana/accounts': + specifier: 2.0.0-experimental.9741939 + version: 2.0.0-experimental.9741939(fastestsmallesttextencoderdecoder@1.0.22)(ws@8.14.2) '@solana/addresses': specifier: 2.0.0-experimental.9741939 version: 2.0.0-experimental.9741939(fastestsmallesttextencoderdecoder@1.0.22) @@ -1801,6 +1804,20 @@ packages: engines: {node: '>=10'} dev: true + /@solana/accounts@2.0.0-experimental.9741939(fastestsmallesttextencoderdecoder@1.0.22)(ws@8.14.2): + resolution: {integrity: sha512-9i5Ur0/l8GXr4LQQW+ZTmBd2fpWzDcnqbOJ9tuVJsUIgHjD9+JJlOnn95wUpkGgbwDFBCvr1C89t+uXVU6y4lg==} + dependencies: + '@solana/addresses': 2.0.0-experimental.9741939(fastestsmallesttextencoderdecoder@1.0.22) + '@solana/codecs-core': 2.0.0-experimental.9741939 + '@solana/codecs-strings': 2.0.0-experimental.9741939(fastestsmallesttextencoderdecoder@1.0.22) + '@solana/rpc-core': 2.0.0-experimental.9741939 + '@solana/rpc-transport': 2.0.0-experimental.9741939(ws@8.14.2) + '@solana/rpc-types': 2.0.0-experimental.9741939 + transitivePeerDependencies: + - fastestsmallesttextencoderdecoder + - ws + dev: false + /@solana/addresses@2.0.0-experimental.9741939(fastestsmallesttextencoderdecoder@1.0.22): resolution: {integrity: sha512-5yGih/laPMZe97b8vFuknLHBNqW495L79CrsLPVz6F1F0FVq/Af1GbG9IB+CqYofNJJV5Z0x79E3BfaRV0HmUw==} dependencies: @@ -1860,7 +1877,6 @@ packages: /@solana/rpc-core@2.0.0-experimental.9741939: resolution: {integrity: sha512-LsrAkyIJ9jODWEGi0wRy1wCpjCFBUxEmnAQ4lwoRB8kxviQJ5DkUk8tje/7ZS6pPZbO71w48utk+zi8TIQzAQg==} - dev: true /@solana/rpc-transport@2.0.0-experimental.9741939(ws@8.14.2): resolution: {integrity: sha512-w3PeLlo1kMdsW9p1SgV7lZtYd39uSb2X/fkqThsDnq29pUqU5HeRr09bfx/76xsiApvR1usGBrGA2iVHHO79Ow==} @@ -1868,11 +1884,9 @@ packages: ws: ^8.14.0 dependencies: ws: 8.14.2 - dev: true /@solana/rpc-types@2.0.0-experimental.9741939: resolution: {integrity: sha512-iyf0R03lheGear1Lu9ibX6jzSd67hTWptcfSakdKRvZ0q8NRocMM7upEvbddPsAhnF16pc0T9OpiDDSMHnayPQ==} - dev: true /@solana/signers@2.0.0-experimental.9741939(fastestsmallesttextencoderdecoder@1.0.22): resolution: {integrity: sha512-dSSLfKR9dcFJe8GTuPmCd4x/nDsAAFZq9vYLd02FkOSX6b/OwCe2AHe8gunneKrY3Y+qf9wBe0XE+wWb/KTQ/A==} @@ -7806,7 +7820,6 @@ packages: optional: true utf-8-validate: optional: true - dev: true /xdm@2.1.0: resolution: {integrity: sha512-3LxxbxKcRogYY7cQSMy1tUuU1zKNK9YPqMT7/S0r7Cz2QpyF8O9yFySGD7caOZt+LWUOQioOIX+6ZzCoBCpcAA==} diff --git a/clients/js/src/generated/accounts/addressLookupTable.ts b/clients/js/src/generated/accounts/addressLookupTable.ts index a7e77a2..a6c6533 100644 --- a/clients/js/src/generated/accounts/addressLookupTable.ts +++ b/clients/js/src/generated/accounts/addressLookupTable.ts @@ -6,6 +6,14 @@ * @see https://github.com/metaplex-foundation/kinobi */ +import { + Account, + EncodedAccount, + FetchAccountConfig, + FetchAccountsConfig, + assertAccountExists, + decodeAccount, +} from '@solana/accounts'; import { Address, ProgramDerivedAddress, @@ -42,13 +50,7 @@ import { getOptionEncoder, } from '@solana/options'; import { - Account, Context, - EncodedAccount, - FetchEncodedAccountOptions, - FetchEncodedAccountsOptions, - assertAccountExists, - decodeAccount, getProgramAddress, getProgramDerivedAddress, } from '../shared'; @@ -137,7 +139,7 @@ export function decodeAddressLookupTable( export async function fetchAddressLookupTable( context: Pick, address: Address, - options?: FetchEncodedAccountOptions + options?: FetchAccountConfig ): Promise> { const maybeAccount = await context.fetchEncodedAccount(address, options); assertAccountExists(maybeAccount); @@ -149,7 +151,7 @@ export async function safeFetchAddressLookupTable< >( context: Pick, address: Address, - options?: FetchEncodedAccountOptions + options?: FetchAccountConfig ): Promise | null> { const maybeAccount = await context.fetchEncodedAccount(address, options); return maybeAccount.exists ? decodeAddressLookupTable(maybeAccount) : null; @@ -158,7 +160,7 @@ export async function safeFetchAddressLookupTable< export async function fetchAllAddressLookupTable( context: Pick, addresses: Array
, - options?: FetchEncodedAccountsOptions + options?: FetchAccountsConfig ): Promise { const maybeAccounts = await context.fetchEncodedAccounts(addresses, options); return maybeAccounts.map((maybeAccount) => { @@ -170,7 +172,7 @@ export async function fetchAllAddressLookupTable( export async function safeFetchAllAddressLookupTable( context: Pick, addresses: Array
, - options?: FetchEncodedAccountsOptions + options?: FetchAccountsConfig ): Promise { const maybeAccounts = await context.fetchEncodedAccounts(addresses, options); return maybeAccounts @@ -206,7 +208,7 @@ export async function fetchAddressLookupTableFromSeeds( 'fetchEncodedAccount' | 'getProgramAddress' | 'getProgramDerivedAddress' >, seeds: Parameters[1], - options?: FetchEncodedAccountOptions + options?: FetchAccountConfig ): Promise { const [address] = await findAddressLookupTablePda(context, seeds); return fetchAddressLookupTable(context, address, options); @@ -218,7 +220,7 @@ export async function safeFetchAddressLookupTableFromSeeds( 'fetchEncodedAccount' | 'getProgramAddress' | 'getProgramDerivedAddress' >, seeds: Parameters[1], - options?: FetchEncodedAccountOptions + options?: FetchAccountConfig ): Promise { const [address] = await findAddressLookupTablePda(context, seeds); return safeFetchAddressLookupTable(context, address, options); diff --git a/clients/js/src/generated/shared/index.ts b/clients/js/src/generated/shared/index.ts index fce4b69..4dd0b2c 100644 --- a/clients/js/src/generated/shared/index.ts +++ b/clients/js/src/generated/shared/index.ts @@ -6,17 +6,20 @@ * @see https://github.com/metaplex-foundation/kinobi */ +import { + FetchAccountConfig, + FetchAccountsConfig, + MaybeEncodedAccount, +} from '@solana/accounts'; import { Address, isProgramDerivedAddress, getProgramDerivedAddress as web3JsGetProgramDerivedAddress, ProgramDerivedAddress, } from '@solana/addresses'; -import { Decoder } from '@solana/codecs-core'; import { AccountRole, IAccountMeta, - IInstruction, upgradeRoleToSigner, } from '@solana/instructions'; import { @@ -187,21 +190,14 @@ export function isTransactionSigner( ); } -export type CustomGeneratedInstruction< - TInstruction extends IInstruction, - TReturn -> = { - getGeneratedInstruction: (instruction: TInstruction) => TReturn; -}; - export type Context = { fetchEncodedAccount: ( address: Address, - options?: FetchEncodedAccountOptions + options?: FetchAccountConfig ) => Promise>; fetchEncodedAccounts: ( addresses: Address[], - options?: FetchEncodedAccountsOptions + options?: FetchAccountsConfig ) => Promise; getProgramAddress?: (program: { name: string; address: Address }) => Address; getProgramDerivedAddress?: ( @@ -235,76 +231,6 @@ export async function getProgramDerivedAddress( }); } -export const ACCOUNT_HEADER_SIZE = 128; - -export type AccountHeader = { - programAddress: Address; - executable: boolean; - lamports: bigint; - rentEpoch?: bigint; -}; - -export type Account< - TData extends object | Uint8Array, - TAddress extends string = string -> = AccountHeader & { - address: Address; - data: TData; -}; - -export type MaybeAccount< - TData extends object | Uint8Array, - TAddress extends string = string -> = - | ({ exists: true } & Account) - | { exists: false; address: Address }; - -export type EncodedAccount = Account< - Uint8Array, - TAddress ->; -export type MaybeEncodedAccount = - MaybeAccount; - -export function decodeAccount< - TData extends object, - TAddress extends string = string ->( - encodedAccount: EncodedAccount, - decoder: Decoder -): Account { - try { - return { ...encodedAccount, data: decoder.decode(encodedAccount.data) }; - } catch (error: any) { - // TODO: Coded error. - throw new Error(`Failed to decode account [${encodedAccount.address}].`); - } -} - -export function assertAccountExists< - TData extends object | Uint8Array, - TAddress extends string = string ->( - account: MaybeAccount -): asserts account is Account & { exists: true } { - if (!account.exists) { - // TODO: Coded error. - throw new Error(`Expected account [${account.address}] to exist.`); - } -} - -export type Commitment = 'confirmed' | 'finalized' | 'processed'; - -export type FetchEncodedAccountOptions = { - commitment?: Commitment; - abortSignal?: AbortSignal; -}; - -export type FetchEncodedAccountsOptions = { - commitment?: Commitment; - abortSignal?: AbortSignal; -}; - export type Program = { name: string; address: Address; diff --git a/package.json b/package.json index f7a386d..7f156af 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "validator:stop": "amman stop" }, "devDependencies": { - "@metaplex-foundation/kinobi": "file:../@metaplex/kinobi", + "@metaplex-foundation/kinobi": "^0.16.10", "@metaplex-foundation/amman": "^0.12.1", "typescript": "^4.9.4" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0a7daab..0781308 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,8 +5,8 @@ devDependencies: specifier: ^0.12.1 version: 0.12.1(typescript@4.9.5) '@metaplex-foundation/kinobi': - specifier: file:../@metaplex/kinobi - version: file:../@metaplex/kinobi + specifier: ^0.16.10 + version: 0.16.10 typescript: specifier: ^4.9.4 version: 4.9.5 @@ -82,6 +82,17 @@ packages: resolution: {integrity: sha512-S9RulC2fFCFOQraz61bij+5YCHhSO9llJegK8c8Y6731fSi6snUSQJdCUqYS8AIgR0TKbQvdvgSyIIdbDFZbBA==} dev: true + /@metaplex-foundation/kinobi@0.16.10: + resolution: {integrity: sha512-DX80Yk8qqcTeR58dehsUKUXhW2IbrGrVlGui4iKHM4hDHvdliT8Pg8g0RaX0ytj6I+tgAEXCxuxrBsYsQQ8e+w==} + dependencies: + '@noble/hashes': 1.3.0 + chalk: 4.1.2 + nunjucks: 3.2.4 + prettier: 2.8.8 + transitivePeerDependencies: + - chokidar + dev: true + /@noble/ed25519@1.7.3: resolution: {integrity: sha512-iR8GBkDt0Q3GyaVcIu7mSsVIqnFbkbRzGLWlvhwunacoLwt4J3swfKhfaM6rN6WY+TBGoYT1GtT1mIh2/jGbRQ==} dev: true @@ -1211,16 +1222,3 @@ packages: y18n: 5.0.8 yargs-parser: 21.1.1 dev: true - - file:../@metaplex/kinobi: - resolution: {directory: ../@metaplex/kinobi, type: directory} - name: '@metaplex-foundation/kinobi' - version: 0.16.9 - dependencies: - '@noble/hashes': 1.3.0 - chalk: 4.1.2 - nunjucks: 3.2.4 - prettier: 2.8.8 - transitivePeerDependencies: - - chokidar - dev: true