From ff774504999e28ad5c67fe558b00991e7c03adf0 Mon Sep 17 00:00:00 2001 From: Joaquim Verges Date: Thu, 18 Aug 2022 16:26:43 -0700 Subject: [PATCH 1/5] return undefined for non existing contracts + add audit to extra metadata --- src/core/classes/contract-publisher.ts | 7 +++++-- src/schema/contracts/custom.ts | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/classes/contract-publisher.ts b/src/core/classes/contract-publisher.ts index 7512c7df3..100271ada 100644 --- a/src/core/classes/contract-publisher.ts +++ b/src/core/classes/contract-publisher.ts @@ -280,12 +280,15 @@ export class ContractPublisher extends RPCConnectionHandler { public async getLatest( publisherAddress: string, contractId: string, - ): Promise { + ): Promise { const model = await this.publisher.readContract.getPublishedContract( publisherAddress, contractId, ); - return this.toPublishedContract(model); + if (model && model.publishMetadataUri) { + return this.toPublishedContract(model); + } + return undefined; } public async publish( diff --git a/src/schema/contracts/custom.ts b/src/schema/contracts/custom.ts index 7143af4d6..fa34d7c30 100644 --- a/src/schema/contracts/custom.ts +++ b/src/schema/contracts/custom.ts @@ -166,6 +166,7 @@ export const ExtraPublishMetadataSchema = z license: z.string().optional(), changelog: z.string().optional(), tags: z.array(z.string()).optional(), + audit: FileBufferOrStringSchema.nullable().optional(), logo: FileBufferOrStringSchema.nullable().optional(), isDeployableViaFactory: z.boolean().optional(), factoryDeploymentData: FactoryDeploymentSchema.partial().optional(), From ea1daa33a2319fca3964cd65ddfd5cef88f2d6eb Mon Sep 17 00:00:00 2001 From: Joaquim Verges Date: Thu, 18 Aug 2022 16:33:20 -0700 Subject: [PATCH 2/5] fix docs --- etc/sdk.api.md | 14 ++++++++++---- src/core/classes/contract-deployer.ts | 5 +++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/etc/sdk.api.md b/etc/sdk.api.md index 9a811a4a5..3541cbcd4 100644 --- a/etc/sdk.api.md +++ b/etc/sdk.api.md @@ -2851,6 +2851,7 @@ export const ExtraPublishMetadataSchema: z.ZodObject<{ license: z.ZodOptional; changelog: z.ZodOptional; tags: z.ZodOptional>; + audit: z.ZodOptional>>; logo: z.ZodOptional>>; isDeployableViaFactory: z.ZodOptional; factoryDeploymentData: z.ZodOptional; changelog: z.ZodOptional; tags: z.ZodOptional>; + audit: z.ZodOptional>>; logo: z.ZodOptional>>; isDeployableViaFactory: z.ZodOptional; factoryDeploymentData: z.ZodOptional Date: Fri, 19 Aug 2022 14:18:28 -0700 Subject: [PATCH 3/5] expose ABI synchroneously --- docs/sdk.all_roles.md | 2 +- etc/sdk.api.md | 2 +- src/common/role.ts | 1 + src/common/version-checker.ts | 14 ++++++++++++++ src/contracts/smart-contract.ts | 2 ++ 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/sdk.all_roles.md b/docs/sdk.all_roles.md index 300798858..538a6ca67 100644 --- a/docs/sdk.all_roles.md +++ b/docs/sdk.all_roles.md @@ -8,5 +8,5 @@ Signature: ```typescript -ALL_ROLES: ("transfer" | "unwrap" | "lister" | "admin" | "minter" | "pauser" | "asset")[] +ALL_ROLES: ("transfer" | "unwrap" | "factory" | "lister" | "admin" | "minter" | "pauser" | "asset")[] ``` diff --git a/etc/sdk.api.md b/etc/sdk.api.md index 3541cbcd4..f47849ff7 100644 --- a/etc/sdk.api.md +++ b/etc/sdk.api.md @@ -392,7 +392,7 @@ export class AdminRoleMissingError extends Error { export type AirdropInput = z.input; // @public (undocumented) -export const ALL_ROLES: ("transfer" | "unwrap" | "lister" | "admin" | "minter" | "pauser" | "asset")[]; +export const ALL_ROLES: ("transfer" | "unwrap" | "factory" | "lister" | "admin" | "minter" | "pauser" | "asset")[]; // Warning: (ae-forgotten-export) The symbol "PriceSchema" needs to be exported by the entry point index.d.ts // diff --git a/src/common/role.ts b/src/common/role.ts index 589f24576..724708ccb 100644 --- a/src/common/role.ts +++ b/src/common/role.ts @@ -12,6 +12,7 @@ const roleMap = { lister: "LISTER_ROLE", asset: "ASSET_ROLE", unwrap: "UNWRAP_ROLE", + factory: "FACTORY_ROLE", } as const; /** diff --git a/src/common/version-checker.ts b/src/common/version-checker.ts index ca3c4b5b7..ff9db38c8 100644 --- a/src/common/version-checker.ts +++ b/src/common/version-checker.ts @@ -57,3 +57,17 @@ export function isIncrementalVersion(current: string, next: string) { const eqMinor = nextSemver.minor === currentSemver.minor; return eqMajor && eqMinor && nextSemver.patch > currentSemver.patch; } + +export function isDowngradeVersion(current: string, next: string) { + const currentSemver = toSemver(current); + const nextSemver = toSemver(next); + if (nextSemver.major < currentSemver.major) { + return true; + } + const eqMajor = nextSemver.major === currentSemver.major; + if (eqMajor && nextSemver.minor < currentSemver.minor) { + return true; + } + const eqMinor = nextSemver.minor === currentSemver.minor; + return eqMajor && eqMinor && nextSemver.patch < currentSemver.patch; +} diff --git a/src/contracts/smart-contract.ts b/src/contracts/smart-contract.ts index 0b04d99b9..6c882da28 100644 --- a/src/contracts/smart-contract.ts +++ b/src/contracts/smart-contract.ts @@ -75,6 +75,7 @@ export class SmartContract public interceptor: ContractInterceptor; public estimator: GasCostEstimator; public publishedMetadata: ContractPublishedMetadata; + public abi: ContractInterface; // features public metadata: ContractMetadata; @@ -111,6 +112,7 @@ export class SmartContract this.options = options; this.storage = storage; this.contractWrapper = contractWrapper; + this.abi = abi; this.events = new ContractEvents(this.contractWrapper); this.interceptor = new ContractInterceptor(this.contractWrapper); From 42c6a84671c77655ba60ee92b7d4aa5bfaa019c5 Mon Sep 17 00:00:00 2001 From: Joaquim Verges Date: Fri, 19 Aug 2022 15:49:39 -0700 Subject: [PATCH 4/5] fix delayed reveal detection --- src/constants/erc721-features.ts | 2 +- src/types/eips.ts | 1 + test/custom.test.ts | 13 +++++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/constants/erc721-features.ts b/src/constants/erc721-features.ts index 4c67858a6..14761019f 100644 --- a/src/constants/erc721-features.ts +++ b/src/constants/erc721-features.ts @@ -3,7 +3,7 @@ import Erc721EnumerableAbi from "../../abis/IERC721Enumerable.json"; import Erc721SupplyAbi from "../../abis/IERC721Supply.json"; import IMintableERC721Abi from "../../abis/IMintableERC721.json"; import MulticallAbi from "../../abis/IMulticall.json"; -import DelayedRevealAbi from "../../abis/DelayedReveal.json"; +import DelayedRevealAbi from "../../abis/IDelayedReveal.json"; import ILazyMintAbi from "../../abis/ILazyMint.json"; import IDropSinglePhase from "../../abis/IDropSinglePhase.json"; import SignatureMintERC721Abi from "../../abis/SignatureMintERC721.json"; diff --git a/src/types/eips.ts b/src/types/eips.ts index 76f62ee7b..261d7becd 100644 --- a/src/types/eips.ts +++ b/src/types/eips.ts @@ -13,6 +13,7 @@ import { ISignatureMintERC721, LazyMint, DropSinglePhase1155, + IDelayedReveal, } from "contracts"; export type BaseERC20 = IERC20 & IERC20Metadata; diff --git a/test/custom.test.ts b/test/custom.test.ts index 16725ae38..485b16b72 100644 --- a/test/custom.test.ts +++ b/test/custom.test.ts @@ -27,6 +27,7 @@ describe("Custom Contracts", async () => { let editionDropContractAddress: string; let tokenDropContractAddress: string; let sigDropContractAddress: string; + let nftDropContractAddress: string; let adminWallet: SignerWithAddress, samWallet: SignerWithAddress, bobWallet: SignerWithAddress; @@ -90,6 +91,10 @@ describe("Custom Contracts", async () => { name: "sigdrop", primary_sale_recipient: adminWallet.address, }); + nftDropContractAddress = await sdk.deployer.deployNFTDrop({ + name: "nftdrop", + primary_sale_recipient: adminWallet.address, + }); }); it("should call raw ABI functions and read deployer address", async () => { @@ -330,11 +335,11 @@ describe("Custom Contracts", async () => { }); it("should detect feature: erc721 delay reveal", async () => { - const c = await sdk.getContract(sigDropContractAddress); + const c = await sdk.getContract(nftDropContractAddress); invariant(c, "Contract undefined"); invariant(c.nft, "ERC721 undefined"); invariant(c.nft.drop, "ERC721 drop"); - invariant(c.nft.drop.revealer, "ERC721 query undefined"); + invariant(c.nft.drop.revealer, "ERC721 revealer undefined"); await c.nft.drop.revealer.createDelayedRevealBatch( { @@ -489,8 +494,8 @@ describe("Custom Contracts", async () => { const batch = await c.token.signature.generateBatch(input); - for (const [_, v] of batch.entries()) { - await c.token.signature.mint(v); + for (const b of batch) { + await c.token.signature.mint(b); } const balance = await c.token.balanceOf(samWallet.address); expect(balance.displayValue).to.eq("6.0"); From 66b5b79a1ecfa6d46719d47b80ca70c217ec3b20 Mon Sep 17 00:00:00 2001 From: Joaquim Verges Date: Fri, 19 Aug 2022 15:52:18 -0700 Subject: [PATCH 5/5] fix build --- src/types/eips.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/types/eips.ts b/src/types/eips.ts index 261d7becd..76f62ee7b 100644 --- a/src/types/eips.ts +++ b/src/types/eips.ts @@ -13,7 +13,6 @@ import { ISignatureMintERC721, LazyMint, DropSinglePhase1155, - IDelayedReveal, } from "contracts"; export type BaseERC20 = IERC20 & IERC20Metadata;