Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit 16a3875

Browse files
jnwngnickfrostylorisleiva
authored
Add support for compressed NFTs (#480)
* 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>
1 parent 61a864a commit 16a3875

26 files changed

+3330
-1654
lines changed

.changeset/rude-countries-tap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@metaplex-foundation/js": minor
3+
---
4+
5+
Add support for compressed NFTs

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"tap-spec": "^5.0.0",
8787
"tape": "^5.5.2",
8888
"tsc-alias": "^1.7.0",
89-
"turbo": "^1.6.0",
89+
"turbo": "^1.9.3",
9090
"typedoc": "^0.23.0",
9191
"typescript": "^4.5.4"
9292
},
@@ -98,5 +98,5 @@
9898
"not IE 11",
9999
"maintained node versions"
100100
],
101-
"packageManager": "pnpm@7.18.1"
101+
"packageManager": "pnpm@8.2.0"
102102
}

packages/js/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@
4545
"@bundlr-network/client": "^0.8.8",
4646
"@metaplex-foundation/beet": "0.7.1",
4747
"@metaplex-foundation/mpl-auction-house": "^2.3.0",
48+
"@metaplex-foundation/mpl-bubblegum": "^0.6.2",
4849
"@metaplex-foundation/mpl-candy-guard": "^0.3.0",
4950
"@metaplex-foundation/mpl-candy-machine": "^5.0.0",
5051
"@metaplex-foundation/mpl-candy-machine-core": "^0.1.2",
5152
"@metaplex-foundation/mpl-token-metadata": "^2.8.6",
5253
"@noble/ed25519": "^1.7.1",
5354
"@noble/hashes": "^1.1.3",
55+
"@solana/spl-account-compression": "^0.1.8",
5456
"@solana/spl-token": "^0.3.5",
5557
"@solana/web3.js": "^1.63.1",
5658
"bignumber.js": "^9.0.2",

packages/js/src/Metaplex.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Connection } from '@solana/web3.js';
2+
import { ReadApiConnection } from './utils/readApiConnection';
23
import { MetaplexPlugin, Cluster, resolveClusterFromConnection } from '@/types';
34
import { corePlugins } from '@/plugins/corePlugins';
45

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

910
export class Metaplex {
1011
/** The connection object from Solana's SDK. */
11-
public readonly connection: Connection;
12+
public readonly connection: Connection | ReadApiConnection;
1213

1314
/** The cluster in which the connection endpoint belongs to. */
1415
public readonly cluster: Cluster;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { MetaplexError } from './MetaplexError';
2+
3+
/** @group Errors */
4+
export class ReadApiError extends MetaplexError {
5+
readonly name: string = 'ReadApiError';
6+
constructor(message: string, cause?: Error) {
7+
super(message, 'rpc', undefined, cause);
8+
}
9+
}

packages/js/src/errors/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './MetaplexError';
33
export * from './ProgramError';
44
export * from './RpcError';
55
export * from './SdkError';
6+
export * from './ReadApiError';

packages/js/src/plugins/bundlrStorage/BundlrStorageDriver.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,7 @@ import {
3333
FailedToConnectToBundlrAddressError,
3434
FailedToInitializeBundlrError,
3535
} from '@/errors';
36-
37-
/**
38-
* This method is necessary to import the Bundlr package on both ESM and CJS modules.
39-
* Without this, we get a different structure on each module:
40-
* - CJS: { default: [Getter], WebBundlr: [Getter] }
41-
* - ESM: { default: { default: [Getter], WebBundlr: [Getter] } }
42-
* This method fixes this by ensure there is not double default in the imported package.
43-
*/
44-
// eslint-disable-next-line @typescript-eslint/naming-convention
45-
function _removeDoubleDefault(pkg: any) {
46-
if (
47-
pkg &&
48-
typeof pkg === 'object' &&
49-
'default' in pkg &&
50-
'default' in pkg.default
51-
) {
52-
return pkg.default;
53-
}
54-
55-
return pkg;
56-
}
36+
import { _removeDoubleDefault } from '@/utils';
5737

5838
export type BundlrOptions = {
5939
address?: string;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ import {
7070
VerifyNftCreatorInput,
7171
verifyNftCreatorOperation,
7272
} from './operations';
73+
import {
74+
FindNftByAssetIdInput,
75+
findNftByAssetIdOperation,
76+
} from './operations/findNftByAssetId';
7377
import { OperationOptions } from '@/types';
7478
import type { Metaplex } from '@/Metaplex';
7579

@@ -195,6 +199,13 @@ export class NftClient {
195199
.execute(findNftsByUpdateAuthorityOperation(input), options);
196200
}
197201

202+
/** {@inheritDoc findNftByAssetIdOperation} */
203+
findByAssetId(input: FindNftByAssetIdInput, options?: OperationOptions) {
204+
return this.metaplex
205+
.operations()
206+
.execute(findNftByAssetIdOperation(input), options);
207+
}
208+
198209
/** {@inheritDoc loadMetadataOperation} */
199210
load(input: LoadMetadataInput, options?: OperationOptions) {
200211
return this.metaplex

packages/js/src/plugins/nftModule/models/Metadata.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import { PublicKey } from '@solana/web3.js';
77
import { MetadataAccount } from '../accounts';
88
import { JsonMetadata } from './JsonMetadata';
99
import { assert, Option, removeEmptyChars } from '@/utils';
10-
import { BigNumber, Creator, Pda, toBigNumber } from '@/types';
10+
import {
11+
BigNumber,
12+
Creator,
13+
Pda,
14+
toBigNumber,
15+
ReadApiCompressionMetadata,
16+
} from '@/types';
1117

1218
/** @group Models */
1319
export type Metadata<Json extends object = JsonMetadata> = {
@@ -26,7 +32,7 @@ export type Metadata<Json extends object = JsonMetadata> = {
2632
*/
2733
readonly updateAuthorityAddress: PublicKey;
2834

29-
/** The JSON metadata associated with the metadata acount. */
35+
/** The JSON metadata associated with the metadata account. */
3036
readonly json: Option<Json>;
3137

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

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

140146
/** Programmable configuration for the asset. */
141147
readonly programmableConfig: Option<ProgrammableConfig>;
148+
149+
/* Compression metadata only provided via the ReadApi */
150+
readonly compression?: ReadApiCompressionMetadata;
142151
};
143152

144153
/** @group Model Helpers */

0 commit comments

Comments
 (0)