Compare commits

...
Author SHA1 Message Date
github-actions[bot]GitHubgithub-actions[bot] <github-actions[bot]@users.noreply.github.com>
e17e41f4d1 Version Packages (#304)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2022-10-12 15:22:33 -07:00
Joaquim VergesandGitHub 712b11a43e [SDK] Fix not getting real owner of Solana NFTs (#303) 2022-10-12 22:12:53 +00:00
14 changed files with 127 additions and 38 deletions
+2
View File
@@ -1,5 +1,7 @@
# @thirdweb-dev/auth
## 2.0.17
## 2.0.16
## 2.0.15
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/auth",
"version": "2.0.16",
"version": "2.0.17",
"exports": {
"./next": {
"module": "./next/dist/thirdweb-dev-auth-next.esm.js",
+7
View File
@@ -1,5 +1,12 @@
# thirdweb
## 0.8.3
### Patch Changes
- Updated dependencies [[`712b11a`](https://github.com/thirdweb-dev/js/commit/712b11a43e389ae10b7f09648779a69c05b2c913)]:
- @thirdweb-dev/sdk@3.2.5
## 0.8.2
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "thirdweb",
"main": "dist/cli/index.js",
"version": "0.8.2",
"version": "0.8.3",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/cli",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
+2
View File
@@ -1,5 +1,7 @@
# @thirdweb-dev/react
## 3.2.5
## 3.2.4
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/react",
"version": "3.2.4",
"version": "3.2.5",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
+6
View File
@@ -1,5 +1,11 @@
# @thirdweb-dev/sdk
## 3.2.5
### Patch Changes
- [#303](https://github.com/thirdweb-dev/js/pull/303) [`712b11a`](https://github.com/thirdweb-dev/js/commit/712b11a43e389ae10b7f09648779a69c05b2c913) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - [SOL] Fix getting real NFT owners
## 3.2.4
## 3.2.3
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/sdk",
"version": "3.2.4",
"version": "3.2.5",
"description": "The main thirdweb SDK.",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/sdk",
"license": "Apache-2.0",
@@ -8,6 +8,7 @@ import {
METAPLEX_PROGRAM_ID,
} from "../../constants/addresses";
import { TransactionResult } from "../../types/common";
import { getNework, getPublicRpc } from "../../utils/urls";
import {
GmaBuilder,
JsonMetadata,
@@ -23,7 +24,13 @@ import {
toMetadataAccount,
} from "@metaplex-foundation/js";
import { getAccount, getAssociatedTokenAddress } from "@solana/spl-token";
import { ConfirmedSignatureInfo, Connection, PublicKey } from "@solana/web3.js";
import {
clusterApiUrl,
ConfirmedSignatureInfo,
Connection,
ParsedAccountData,
PublicKey,
} from "@solana/web3.js";
/**
* @internal
@@ -80,6 +87,27 @@ export class NFTHelper {
}
}
async ownerOf(nftAddress: string): Promise<string | undefined> {
try {
// TODO switch back to normal connection when alchemy supports getTokenLargestAccounts
const connection = new Connection(
getPublicRpc(this.metaplex),
"confirmed",
);
const largestAccounts = await connection.getTokenLargestAccounts(
new PublicKey(nftAddress),
);
const largestAccountInfo = await connection.getParsedAccountInfo(
largestAccounts.value[0].address,
);
const parsedData = largestAccountInfo?.value?.data as ParsedAccountData;
const owner = parsedData ? parsedData.parsed.info.owner : undefined;
return owner;
} catch (err) {
return undefined;
}
}
async getAll(
collectionAddress: string,
queryParams?: QueryAllParams,
@@ -213,11 +241,13 @@ export class NFTHelper {
if (!mint) {
throw new Error("No mint found for NFT");
}
return this.toNFTMetadataResolved(mint, fullModel);
const owner = await this.ownerOf(mint.address.toBase58());
return this.toNFTMetadataResolved(mint, owner, fullModel);
}
private toNFTMetadataResolved(
mint: Mint,
owner: string | undefined,
fullModel:
| Nft
| Sft
@@ -233,7 +263,7 @@ export class NFTHelper {
symbol: fullModel.symbol,
...fullModel.json,
},
owner: fullModel.updateAuthorityAddress.toBase58(),
owner: owner || PublicKey.default.toBase58(),
supply: mint.supply.basisPoints.toNumber(),
type: "metaplex",
};
@@ -9,6 +9,7 @@ import { enforceCreator } from "../classes/helpers/creators-helper";
import { NFTHelper } from "../classes/helpers/nft-helper";
import { TransactionResult } from "../types/common";
import { CreatorInput } from "../types/programs";
import { getNework } from "../utils/urls";
import {
findEditionMarkerPda,
Metaplex,
@@ -41,15 +42,7 @@ export class NFTCollection {
public publicKey: PublicKey;
public accountType = "nft-collection" as const;
public get network() {
const url = new URL(this.metaplex.connection.rpcEndpoint);
// try this first to avoid hitting `custom` network for alchemy urls
if (url.hostname.includes("devnet")) {
return "devnet";
}
if (url.hostname.includes("mainnet")) {
return "mainnet-beta";
}
return this.metaplex.cluster;
return getNework(this.metaplex);
}
constructor(
@@ -155,6 +148,21 @@ export class NFTCollection {
return this.nft.balanceOf(walletAddress, nftAddress);
}
/**
* Get the current owner of the given NFT
* @param nftAddress - the mint address of the NFT to get the owner of
* @returns the owner of the NFT
* @example
* ```jsx
* const nftAddress = "..."
* const owner = await program.ownerOf(nftAddress);
* console.log(owner);
* ```
*/
async ownerOf(nftAddress: string): Promise<string | undefined> {
return this.nft.ownerOf(nftAddress);
}
/**
* Get the supply of NFT editions minted from a specific NFT
* @param nftAddress - the mint address of the NFT to check the supply of
@@ -163,7 +171,7 @@ export class NFTCollection {
* @example
* ```jsx
* const address = "...";
* const supply = await program.supplyOf(addres);
* const supply = await program.supplyOf(address);
* ```
*/
async supplyOf(nftAddress: string): Promise<bigint> {
+17 -9
View File
@@ -7,6 +7,7 @@ import {
import { ClaimConditions } from "../classes/claim-conditions";
import { NFTHelper } from "../classes/helpers/nft-helper";
import { Amount, TransactionResult } from "../types/common";
import { getNework } from "../utils/urls";
import {
CandyMachineItem,
Metaplex,
@@ -42,15 +43,7 @@ export class NFTDrop {
public accountType = "nft-drop" as const;
public publicKey: PublicKey;
public get network() {
const url = new URL(this.metaplex.connection.rpcEndpoint);
// try this first to avoid hitting `custom` network for alchemy urls
if (url.hostname.includes("devnet")) {
return "devnet";
}
if (url.hostname.includes("mainnet")) {
return "mainnet-beta";
}
return this.metaplex.cluster;
return getNework(this.metaplex);
}
/**
@@ -223,6 +216,21 @@ export class NFTDrop {
return this.nft.balanceOf(walletAddress, nftAddress);
}
/**
* Get the current owner of the given NFT
* @param nftAddress - the mint address of the NFT to get the owner of
* @returns the owner of the NFT
* @example
* ```jsx
* const nftAddress = "..."
* const owner = await program.ownerOf(nftAddress);
* console.log(owner);
* ```
*/
async ownerOf(nftAddress: string): Promise<string | undefined> {
return this.nft.ownerOf(nftAddress);
}
/**
* Get the total unclaimed supply of this drop
* @returns the total supply
+2 -9
View File
@@ -1,6 +1,7 @@
import { CurrencyValue, TokenMetadata } from "../../core/schema/token";
import { Amount, AmountSchema, TransactionResult } from "../types/common";
import { toCurrencyValue } from "../utils/token";
import { getNework } from "../utils/urls";
import {
findMetadataPda,
Metaplex,
@@ -36,15 +37,7 @@ export class Token {
public accountType = "token" as const;
public publicKey: PublicKey;
public get network() {
const url = new URL(this.metaplex.connection.rpcEndpoint);
// try this first to avoid hitting `custom` network for alchemy urls
if (url.hostname.includes("devnet")) {
return "devnet";
}
if (url.hostname.includes("mainnet")) {
return "mainnet-beta";
}
return this.metaplex.cluster;
return getNework(this.metaplex);
}
constructor(
+24
View File
@@ -1,4 +1,5 @@
import { Network } from "../types/index";
import { Metaplex } from "@metaplex-foundation/js";
import { Cluster, clusterApiUrl } from "@solana/web3.js";
/**
@@ -24,3 +25,26 @@ export function getUrlForNetwork(network: Network) {
return network;
}
}
export function getNework(metaplex: Metaplex) {
const url = new URL(metaplex.connection.rpcEndpoint);
// try this first to avoid hitting `custom` network for alchemy urls
if (url.hostname.includes("devnet")) {
return "devnet";
}
if (url.hostname.includes("mainnet")) {
return "mainnet-beta";
}
return metaplex.cluster;
}
export function getPublicRpc(metaplex: Metaplex) {
const url = new URL(metaplex.connection.rpcEndpoint);
if (url.hostname.includes("devnet")) {
return "https://api.devnet.solana.com";
}
if (url.hostname.includes("mainnet")) {
return "https://api.mainnet-beta.solana.com";
}
return url.toString();
}
+12 -3
View File
@@ -1,5 +1,6 @@
import { NFTDrop } from "../../src/solana";
import { sdk } from "./before-setup";
import { Keypair } from "@solana/web3.js";
import { expect } from "chai";
describe("NFTDrop", async () => {
@@ -54,15 +55,21 @@ describe("NFTDrop", async () => {
await drop.claimConditions.set({
maxClaimable: 1,
});
const address = await drop.claim(1);
const receiver = Keypair.generate();
const address = await drop.claimTo(receiver.publicKey.toBase58(), 1);
unclaimed = await drop.totalUnclaimedSupply();
claimed = await drop.totalClaimedSupply();
expect(unclaimed).to.equal(4);
expect(claimed).to.equal(1);
const balance = await drop.balance(address[0]);
const balance = await drop.balanceOf(
receiver.publicKey.toBase58(),
address[0],
);
expect(balance).to.equal(1);
const nftClaimed = await drop.get(address[0]);
expect(nftClaimed.owner).to.equal(receiver.publicKey.toBase58());
});
it("should update claim condition", async () => {
@@ -84,7 +91,9 @@ describe("NFTDrop", async () => {
});
it("should get all nfts", async () => {
await drop.claim(2);
const claimedAddresses = await drop.claim(2);
const nftClaimed = await drop.get(claimedAddresses[0]);
expect(nftClaimed.owner).to.equal(sdk.wallet.getAddress());
const all = await drop.getAll();
const claimed = await drop.getAllClaimed();