Skip to content

Commit

Permalink
Add support for compressed NFTs (#480)
Browse files Browse the repository at this point in the history
* Support for compressed NFTs

* Adding findByAssetId, finishing `createNft`

* Resolving circular dependnecies, exporting ReadApiConnection

* fix: missing and/or incorrect type

* feat: added ReadApiError for rpc response

* refactor: read api types

* feat: added support for getAssetsByGroup

* refactor: moved all ReadAPI types to type file

* feat: transferring

* chore: update spl-compression package to the latest

* feat: added transfer support

* refactor: ReadApi types

* feat: added getAssetsByOwner rpc method

* Update pnpm-lock.yaml

* Fix linting

* Apply some suggestions from code review

Co-authored-by: Loris Leiva <loris.leiva@gmail.com>

* fix: added remaining operations

* fix: removed unused type

* build: removed unused dependancy

* Extract _removeDoubleDefault helper function

* fix: esm import by updating compression package

* Update PNPM and Turbo

* Update packages/js/src/plugins/nftModule/NftClient.ts

Co-authored-by: Loris Leiva <loris.leiva@gmail.com>

* Create rude-countries-tap.md

---------

Co-authored-by: nickfrosty <nick.frostbutter@solana.org>
Co-authored-by: Loris Leiva <loris.leiva@gmail.com>
Co-authored-by: Nick Frostbutter <75431177+nickfrosty@users.noreply.github.com>
  • Loading branch information
4 people authored May 3, 2023
1 parent 61a864a commit 16a3875
Show file tree
Hide file tree
Showing 26 changed files with 3,330 additions and 1,654 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-countries-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@metaplex-foundation/js": minor
---

Add support for compressed NFTs
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"tap-spec": "^5.0.0",
"tape": "^5.5.2",
"tsc-alias": "^1.7.0",
"turbo": "^1.6.0",
"turbo": "^1.9.3",
"typedoc": "^0.23.0",
"typescript": "^4.5.4"
},
Expand All @@ -98,5 +98,5 @@
"not IE 11",
"maintained node versions"
],
"packageManager": "pnpm@7.18.1"
"packageManager": "pnpm@8.2.0"
}
2 changes: 2 additions & 0 deletions packages/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@
"@bundlr-network/client": "^0.8.8",
"@metaplex-foundation/beet": "0.7.1",
"@metaplex-foundation/mpl-auction-house": "^2.3.0",
"@metaplex-foundation/mpl-bubblegum": "^0.6.2",
"@metaplex-foundation/mpl-candy-guard": "^0.3.0",
"@metaplex-foundation/mpl-candy-machine": "^5.0.0",
"@metaplex-foundation/mpl-candy-machine-core": "^0.1.2",
"@metaplex-foundation/mpl-token-metadata": "^2.8.6",
"@noble/ed25519": "^1.7.1",
"@noble/hashes": "^1.1.3",
"@solana/spl-account-compression": "^0.1.8",
"@solana/spl-token": "^0.3.5",
"@solana/web3.js": "^1.63.1",
"bignumber.js": "^9.0.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/js/src/Metaplex.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Connection } from '@solana/web3.js';
import { ReadApiConnection } from './utils/readApiConnection';
import { MetaplexPlugin, Cluster, resolveClusterFromConnection } from '@/types';
import { corePlugins } from '@/plugins/corePlugins';

Expand All @@ -8,7 +9,7 @@ export type MetaplexOptions = {

export class Metaplex {
/** The connection object from Solana's SDK. */
public readonly connection: Connection;
public readonly connection: Connection | ReadApiConnection;

/** The cluster in which the connection endpoint belongs to. */
public readonly cluster: Cluster;
Expand Down
9 changes: 9 additions & 0 deletions packages/js/src/errors/ReadApiError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { MetaplexError } from './MetaplexError';

/** @group Errors */
export class ReadApiError extends MetaplexError {
readonly name: string = 'ReadApiError';
constructor(message: string, cause?: Error) {
super(message, 'rpc', undefined, cause);
}
}
1 change: 1 addition & 0 deletions packages/js/src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './MetaplexError';
export * from './ProgramError';
export * from './RpcError';
export * from './SdkError';
export * from './ReadApiError';
22 changes: 1 addition & 21 deletions packages/js/src/plugins/bundlrStorage/BundlrStorageDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,7 @@ import {
FailedToConnectToBundlrAddressError,
FailedToInitializeBundlrError,
} from '@/errors';

/**
* This method is necessary to import the Bundlr package on both ESM and CJS modules.
* Without this, we get a different structure on each module:
* - CJS: { default: [Getter], WebBundlr: [Getter] }
* - ESM: { default: { default: [Getter], WebBundlr: [Getter] } }
* This method fixes this by ensure there is not double default in the imported package.
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
function _removeDoubleDefault(pkg: any) {
if (
pkg &&
typeof pkg === 'object' &&
'default' in pkg &&
'default' in pkg.default
) {
return pkg.default;
}

return pkg;
}
import { _removeDoubleDefault } from '@/utils';

export type BundlrOptions = {
address?: string;
Expand Down
11 changes: 11 additions & 0 deletions packages/js/src/plugins/nftModule/NftClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ import {
VerifyNftCreatorInput,
verifyNftCreatorOperation,
} from './operations';
import {
FindNftByAssetIdInput,
findNftByAssetIdOperation,
} from './operations/findNftByAssetId';
import { OperationOptions } from '@/types';
import type { Metaplex } from '@/Metaplex';

Expand Down Expand Up @@ -195,6 +199,13 @@ export class NftClient {
.execute(findNftsByUpdateAuthorityOperation(input), options);
}

/** {@inheritDoc findNftByAssetIdOperation} */
findByAssetId(input: FindNftByAssetIdInput, options?: OperationOptions) {
return this.metaplex
.operations()
.execute(findNftByAssetIdOperation(input), options);
}

/** {@inheritDoc loadMetadataOperation} */
load(input: LoadMetadataInput, options?: OperationOptions) {
return this.metaplex
Expand Down
15 changes: 12 additions & 3 deletions packages/js/src/plugins/nftModule/models/Metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import { PublicKey } from '@solana/web3.js';
import { MetadataAccount } from '../accounts';
import { JsonMetadata } from './JsonMetadata';
import { assert, Option, removeEmptyChars } from '@/utils';
import { BigNumber, Creator, Pda, toBigNumber } from '@/types';
import {
BigNumber,
Creator,
Pda,
toBigNumber,
ReadApiCompressionMetadata,
} from '@/types';

/** @group Models */
export type Metadata<Json extends object = JsonMetadata> = {
Expand All @@ -26,7 +32,7 @@ export type Metadata<Json extends object = JsonMetadata> = {
*/
readonly updateAuthorityAddress: PublicKey;

/** The JSON metadata associated with the metadata acount. */
/** The JSON metadata associated with the metadata account. */
readonly json: Option<Json>;

/**
Expand Down Expand Up @@ -110,7 +116,7 @@ export type Metadata<Json extends object = JsonMetadata> = {

/**
* When this field is not `null`, it indicates that
* the asset is a collection. Everytime an asset is
* the asset is a collection. Every time an asset is
* verified/unverified as part of this collection,
* the `size` field inside this object will be updated accordingly.
*/
Expand Down Expand Up @@ -139,6 +145,9 @@ export type Metadata<Json extends object = JsonMetadata> = {

/** Programmable configuration for the asset. */
readonly programmableConfig: Option<ProgrammableConfig>;

/* Compression metadata only provided via the ReadApi */
readonly compression?: ReadApiCompressionMetadata;
};

/** @group Model Helpers */
Expand Down
Loading

0 comments on commit 16a3875

Please sign in to comment.