Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions etc/sdk.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2847,6 +2847,7 @@ export function fetchPreDeployMetadata(publishMetadataUri: string, storage: ISto
// @internal (undocumented)
export function fetchRawPredeployMetadata(publishMetadataUri: string, storage: IStorage): Promise<{
[x: string]: any;
analytics?: any;
name: string;
metadataUri: string;
bytecodeUri: string;
Expand Down Expand Up @@ -2919,6 +2920,7 @@ export const FullPublishMetadataSchema: z.ZodObject<z.extendShape<z.extendShape<
name: z.ZodString;
metadataUri: z.ZodString;
bytecodeUri: z.ZodString;
analytics: z.ZodOptional<z.ZodAny>;
}, {
version: z.ZodEffects<z.ZodString, string, string>;
displayName: z.ZodOptional<z.ZodString>;
Expand All @@ -2933,6 +2935,7 @@ export const FullPublishMetadataSchema: z.ZodObject<z.extendShape<z.extendShape<
[x: string]: any;
publisher?: string | undefined;
description?: string | undefined;
analytics?: any;
displayName?: string | undefined;
readme?: string | undefined;
license?: string | undefined;
Expand All @@ -2946,6 +2949,7 @@ export const FullPublishMetadataSchema: z.ZodObject<z.extendShape<z.extendShape<
[x: string]: any;
publisher?: string | undefined;
description?: string | undefined;
analytics?: any;
displayName?: string | undefined;
readme?: string | undefined;
license?: string | undefined;
Expand Down Expand Up @@ -3338,7 +3342,10 @@ export class MarketplaceDirect {
getAddress(): string;
getListing(listingId: BigNumberish): Promise<DirectListing>;
// @internal
isStillValidListing(listing: DirectListing, quantity?: BigNumberish): Promise<boolean>;
isStillValidListing(listing: DirectListing, quantity?: BigNumberish): Promise<{
valid: boolean;
error?: string;
}>;
makeOffer(listingId: BigNumberish, quantityDesired: BigNumberish, currencyContractAddress: string, pricePerToken: Price, expirationDate?: Date): Promise<TransactionResult>;
// @internal
mapListing(listing: IMarketplace_2.ListingStruct): Promise<DirectListing>;
Expand Down Expand Up @@ -4218,13 +4225,16 @@ export const PreDeployMetadata: z.ZodObject<{
name: z.ZodString;
metadataUri: z.ZodString;
bytecodeUri: z.ZodString;
analytics: z.ZodOptional<z.ZodAny>;
}, "strip", z.ZodAny, {
[x: string]: any;
analytics?: any;
name: string;
metadataUri: string;
bytecodeUri: string;
}, {
[x: string]: any;
analytics?: any;
name: string;
metadataUri: string;
bytecodeUri: string;
Expand All @@ -4242,6 +4252,7 @@ export const PreDeployMetadataFetchedSchema: z.ZodObject<z.extendShape<z.extendS
name: z.ZodString;
metadataUri: z.ZodString;
bytecodeUri: z.ZodString;
analytics: z.ZodOptional<z.ZodAny>;
}, {
name: z.ZodString;
abi: z.ZodArray<z.ZodObject<{
Expand Down Expand Up @@ -4398,6 +4409,7 @@ export const PreDeployMetadataFetchedSchema: z.ZodObject<z.extendShape<z.extendS
bytecode: z.ZodString;
}>, "strip", z.ZodAny, {
[x: string]: any;
analytics?: any;
name: string;
metadataUri: string;
metadata: Record<string, any>;
Expand Down Expand Up @@ -4440,6 +4452,7 @@ export const PreDeployMetadataFetchedSchema: z.ZodObject<z.extendShape<z.extendS
}, {
[x: string]: any;
licenses?: string[] | undefined;
analytics?: any;
name: string;
metadataUri: string;
metadata: Record<string, any>;
Expand Down Expand Up @@ -7080,10 +7093,10 @@ export class WrongListingTypeError extends Error {

// Warnings were encountered during analysis:
//
// dist/src/schema/contracts/custom.d.ts:1270:5 - (ae-incompatible-release-tags) The symbol "inputs" is marked as @public, but its signature references "AbiTypeSchema" which is marked as @internal
// dist/src/schema/contracts/custom.d.ts:1271:5 - (ae-incompatible-release-tags) The symbol "outputs" is marked as @public, but its signature references "AbiTypeSchema" which is marked as @internal
// dist/src/schema/contracts/custom.d.ts:1278:5 - (ae-incompatible-release-tags) The symbol "inputs" is marked as @public, but its signature references "AbiTypeSchema" which is marked as @internal
// dist/src/schema/contracts/custom.d.ts:1279:5 - (ae-incompatible-release-tags) The symbol "outputs" is marked as @public, but its signature references "AbiTypeSchema" which is marked as @internal
// dist/src/schema/contracts/custom.d.ts:1279:5 - (ae-incompatible-release-tags) The symbol "inputs" is marked as @public, but its signature references "AbiTypeSchema" which is marked as @internal
// dist/src/schema/contracts/custom.d.ts:1280:5 - (ae-incompatible-release-tags) The symbol "outputs" is marked as @public, but its signature references "AbiTypeSchema" which is marked as @internal
// dist/src/schema/contracts/custom.d.ts:1287:5 - (ae-incompatible-release-tags) The symbol "inputs" is marked as @public, but its signature references "AbiTypeSchema" which is marked as @internal
// dist/src/schema/contracts/custom.d.ts:1288:5 - (ae-incompatible-release-tags) The symbol "outputs" is marked as @public, but its signature references "AbiTypeSchema" which is marked as @internal

// (No @packageDocumentation comment for this package)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/sdk",
"version": "2.3.35-1",
"version": "2.3.35-3",
"description": "The main thirdweb SDK.",
"repository": {
"type": "git",
Expand Down
18 changes: 10 additions & 8 deletions src/contracts/marketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export class Marketplace implements UpdateableNetwork {
public async getActiveListings(
filter?: MarketplaceFilter,
): Promise<(AuctionListing | DirectListing)[]> {
const rawListings = await this.getAllListingsNoFilter();
const rawListings = await this.getAllListingsNoFilter(true);
const filtered = this.applyFilter(rawListings, filter);
const now = BigNumber.from(Math.floor(Date.now() / 1000));
return filtered.filter((l) => {
Expand Down Expand Up @@ -255,7 +255,7 @@ export class Marketplace implements UpdateableNetwork {
public async getAllListings(
filter?: MarketplaceFilter,
): Promise<(AuctionListing | DirectListing)[]> {
const rawListings = await this.getAllListingsNoFilter();
const rawListings = await this.getAllListingsNoFilter(false);
return this.applyFilter(rawListings, filter);
}

Expand Down Expand Up @@ -444,9 +444,9 @@ export class Marketplace implements UpdateableNetwork {
* PRIVATE FUNCTIONS
*******************************/

private async getAllListingsNoFilter(): Promise<
(AuctionListing | DirectListing)[]
> {
private async getAllListingsNoFilter(
filterInvalidListings: boolean,
): Promise<(AuctionListing | DirectListing)[]> {
const listings = await Promise.all(
Array.from(
Array(
Expand All @@ -465,9 +465,11 @@ export class Marketplace implements UpdateableNetwork {
return listing;
}

const valid = await this.direct.isStillValidListing(listing);
if (!valid) {
return undefined;
if (filterInvalidListings) {
const { valid } = await this.direct.isStillValidListing(listing);
if (!valid) {
return undefined;
}
}

return listing;
Expand Down
15 changes: 12 additions & 3 deletions src/core/classes/contract-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { IContractMetadata } from "contracts";
import { IContractMetadata, IERC20Metadata } from "contracts";
import { z } from "zod";
import { IStorage } from "../interfaces/IStorage";
import { TransactionResult } from "../types";
import { ContractWrapper } from "./contract-wrapper";
import {
detectContractFeature,
fetchContractMetadataFromAddress,
hasFunction,
} from "../../common";
import { DetectableFeature } from "../interfaces/DetectableFeature";
import { FEATURE_METADATA } from "../../constants/thirdweb-features";
Expand Down Expand Up @@ -87,14 +88,22 @@ export class ContractMetadata<

if (!data) {
try {
// try fetching metadata from bytecode
// try fetching metadata from bytecode and / or contract itself
let contractName: string | undefined;
try {
if (hasFunction<IERC20Metadata>("name", this.contractWrapper)) {
contractName = await this.contractWrapper.readContract.name();
}
} catch (err) {
// no-op
}
const publishedMetadata = await fetchContractMetadataFromAddress(
this.contractWrapper.readContract.address,
this.contractWrapper.getProvider(),
this.storage,
);
data = {
name: publishedMetadata.name,
name: contractName || publishedMetadata.name,
description: publishedMetadata.info.title,
};
} catch (e) {
Expand Down
41 changes: 29 additions & 12 deletions src/core/classes/marketplace-direct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,12 @@ export class MarketplaceDirect {
receiver?: string,
): Promise<TransactionResult> {
const listing = await this.validateListing(BigNumber.from(listingId));
const valid = await this.isStillValidListing(listing, quantityDesired);
const { valid, error } = await this.isStillValidListing(
listing,
quantityDesired,
);
if (!valid) {
throw new Error(
"The asset on this listing has been moved from the lister's wallet, this listing is now invalid",
);
throw new Error(`Listing ${listingId} is no longer valid. ${error}`);
}
const buyFor = receiver
? receiver
Expand Down Expand Up @@ -501,7 +502,7 @@ export class MarketplaceDirect {
public async isStillValidListing(
listing: DirectListing,
quantity?: BigNumberish,
): Promise<boolean> {
): Promise<{ valid: boolean; error?: string }> {
const approved = await isTokenApprovedForTransfer(
this.contractWrapper.getProvider(),
this.getAddress(),
Expand All @@ -511,7 +512,10 @@ export class MarketplaceDirect {
);

if (!approved) {
return false;
return {
valid: false,
error: `Token '${listing.tokenId}' from contract '${listing.assetContractAddress}' is not approved for transfer`,
};
}

const provider = this.contractWrapper.getProvider();
Expand All @@ -528,10 +532,15 @@ export class MarketplaceDirect {
ERC721Abi,
provider,
) as IERC721;
return (
const valid =
(await asset.ownerOf(listing.tokenId)).toLowerCase() ===
listing.sellerAddress.toLowerCase()
);
listing.sellerAddress.toLowerCase();
return {
valid,
error: valid
? undefined
: `Seller is not the owner of Token '${listing.tokenId}' from contract '${listing.assetContractAddress} anymore'`,
};
} else if (isERC1155) {
const asset = new Contract(
listing.assetContractAddress,
Expand All @@ -542,10 +551,18 @@ export class MarketplaceDirect {
listing.sellerAddress,
listing.tokenId,
);
return balance.gte(quantity || listing.quantity);
const valid = balance.gte(quantity || listing.quantity);
return {
valid,
error: valid
? undefined
: `Seller does not have enough balance of Token '${listing.tokenId}' from contract '${listing.assetContractAddress} to fulfill the listing`,
};
} else {
console.error("Contract does not implement ERC 1155 or ERC 721.");
return false;
return {
valid: false,
error: "Contract does not implement ERC 1155 or ERC 721.",
};
}
}
}
1 change: 1 addition & 0 deletions src/schema/contracts/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const PreDeployMetadata = z
name: z.string(),
metadataUri: z.string(),
bytecodeUri: z.string(),
analytics: z.any().optional(),
})
.catchall(z.any());

Expand Down
2 changes: 1 addition & 1 deletion test/custom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe("Custom Contracts", async () => {
invariant(c, "Contract undefined");
invariant(c.metadata, "Contract undefined");
const meta = await c.metadata.get();
expect(meta.name).to.eq("Greeter");
expect(meta.name).to.eq("MyToken");
});

it("should detect feature: roles", async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/marketplace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1096,13 +1096,13 @@ describe("Marketplace Contract", async () => {
await sdk.updateSignerOrProvider(adminWallet);
await dummyNftContract.transfer(samWallet.address, "0");

const allListings = await marketplaceContract.getAllListings();
const allListings = await marketplaceContract.getActiveListings();
const found = allListings.find(
(l) => l.id.toString() === directListingId.toString(),
);
assert.isUndefined(
found,
"should not have found the listing becuase it is invalid",
"should not have found the listing because it is invalid",
);
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/publisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe("Publishing", async () => {
// fetch metadata back
const c = await sdk.getContract(deployedAddr);
const meta = await c.metadata.get();
expect(meta.name).to.eq("Greeter");
expect(meta.name).to.eq("MyToken");
});

it("should publish multiple versions", async () => {
Expand Down Expand Up @@ -272,7 +272,7 @@ describe("Publishing", async () => {
expect(all.length).to.eq(1);
invariant(c.royalties, "no royalties detected");
const prevMeta = await c.metadata.get();
expect(prevMeta.name).to.eq("CustomAzukiContract");
expect(prevMeta.name).to.eq("AzukiMint");
expect(prevMeta.description).to.eq(
"Azuki contract that can be fully used in the thirdweb dashboard",
);
Expand Down