[SDK] make input/output versions of the release metadata schemas (ported) (#13)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@thirdweb-dev/sdk": patch
|
||||
---
|
||||
|
||||
make input/output versions of the release metadata schemas
|
||||
@@ -1,6 +1,10 @@
|
||||
import { BaseContract, ethers } from "ethers";
|
||||
import {
|
||||
Feature,
|
||||
FeatureName,
|
||||
FeatureWithEnabled,
|
||||
SUPPORTED_FEATURES,
|
||||
} from "../constants/contract-features";
|
||||
import { ContractWrapper } from "../core/classes/contract-wrapper";
|
||||
import { IStorage } from "@thirdweb-dev/storage";
|
||||
import {
|
||||
AbiEvent,
|
||||
AbiFunction,
|
||||
@@ -9,21 +13,17 @@ import {
|
||||
ContractInfoSchema,
|
||||
ContractSource,
|
||||
FullPublishMetadata,
|
||||
FullPublishMetadataSchema,
|
||||
FullPublishMetadataSchemaOutput,
|
||||
PreDeployMetadata,
|
||||
PreDeployMetadataFetched,
|
||||
PreDeployMetadataFetchedSchema,
|
||||
PublishedMetadata,
|
||||
} from "../schema/contracts/custom";
|
||||
import { z } from "zod";
|
||||
import {
|
||||
Feature,
|
||||
FeatureName,
|
||||
FeatureWithEnabled,
|
||||
SUPPORTED_FEATURES,
|
||||
} from "../constants/contract-features";
|
||||
import { IStorage } from "@thirdweb-dev/storage";
|
||||
import { decodeFirstSync } from "cbor";
|
||||
import { BaseContract, ethers } from "ethers";
|
||||
import { toB58String } from "multihashes";
|
||||
import { z } from "zod";
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -450,7 +450,7 @@ export async function fetchExtendedReleaseMetadata(
|
||||
storage: IStorage,
|
||||
): Promise<FullPublishMetadata> {
|
||||
const meta = await storage.getRaw(publishMetadataUri);
|
||||
return FullPublishMetadataSchema.parse(JSON.parse(meta));
|
||||
return FullPublishMetadataSchemaOutput.parse(JSON.parse(meta));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
import { NetworkOrSignerOrProvider, TransactionResult } from "../types";
|
||||
import { SDKOptions } from "../../schema/sdk-options";
|
||||
import { IStorage } from "@thirdweb-dev/storage";
|
||||
import { RPCConnectionHandler } from "./rpc-connection-handler";
|
||||
import { constants, utils } from "ethers";
|
||||
import invariant from "tiny-invariant";
|
||||
import {
|
||||
extractConstructorParams,
|
||||
extractFunctions,
|
||||
@@ -13,13 +7,15 @@ import {
|
||||
fetchRawPredeployMetadata,
|
||||
fetchSourceFilesFromMetadata,
|
||||
} from "../../common/feature-detection";
|
||||
import { isIncrementalVersion } from "../../common/version-checker";
|
||||
import { getContractPublisherAddress } from "../../constants";
|
||||
import {
|
||||
AbiFunction,
|
||||
ContractParam,
|
||||
ContractSource,
|
||||
ExtraPublishMetadata,
|
||||
FullPublishMetadata,
|
||||
FullPublishMetadataSchema,
|
||||
FullPublishMetadataSchemaInput,
|
||||
PreDeployMetadataFetched,
|
||||
ProfileMetadata,
|
||||
ProfileMetadataInput,
|
||||
@@ -28,15 +24,19 @@ import {
|
||||
PublishedContractFetched,
|
||||
PublishedContractSchema,
|
||||
} from "../../schema/contracts/custom";
|
||||
import { SDKOptions } from "../../schema/sdk-options";
|
||||
import { NetworkOrSignerOrProvider, TransactionResult } from "../types";
|
||||
import { ContractWrapper } from "./contract-wrapper";
|
||||
import { RPCConnectionHandler } from "./rpc-connection-handler";
|
||||
import {
|
||||
ContractPublisher as OnChainContractPublisher,
|
||||
IContractPublisher,
|
||||
} from "@thirdweb-dev/contracts-js";
|
||||
import { getContractPublisherAddress } from "../../constants";
|
||||
import ContractPublisherAbi from "@thirdweb-dev/contracts-js/abis/ContractPublisher.json";
|
||||
import { isIncrementalVersion } from "../../common/version-checker";
|
||||
import { ContractPublishedEvent } from "@thirdweb-dev/contracts-js/dist/declarations/src/ContractPublisher";
|
||||
import { IStorage } from "@thirdweb-dev/storage";
|
||||
import { constants, utils } from "ethers";
|
||||
import invariant from "tiny-invariant";
|
||||
|
||||
/**
|
||||
* Handles publishing contracts (EXPERIMENTAL)
|
||||
@@ -331,7 +331,7 @@ export class ContractPublisher extends RPCConnectionHandler {
|
||||
const bytecodeHash = utils.solidityKeccak256(["bytes"], [bytecode]);
|
||||
const contractId = predeployMetadata.name;
|
||||
|
||||
const fullMetadata = FullPublishMetadataSchema.parse({
|
||||
const fullMetadata = FullPublishMetadataSchemaInput.parse({
|
||||
...extraMetadata,
|
||||
...predeployMetadata,
|
||||
publisher,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { toSemver } from "../../common/index";
|
||||
import { ChainId, CONTRACT_ADDRESSES } from "../../constants/index";
|
||||
import { AddressSchema, BigNumberishSchema, JsonSchema } from "../shared";
|
||||
import {
|
||||
CommonContractOutputSchema,
|
||||
@@ -114,32 +113,16 @@ export const ChainIdToAddressSchema = z.record(z.string(), z.string());
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
// TODO should have an input and ouput version of this schema
|
||||
export const FactoryDeploymentSchema = z.object({
|
||||
implementationAddresses: ChainIdToAddressSchema,
|
||||
implementationInitializerFunction: z.string().default("initialize"),
|
||||
factoryAddresses: ChainIdToAddressSchema.default({
|
||||
[ChainId.Mainnet]: CONTRACT_ADDRESSES[ChainId.Mainnet].twFactory,
|
||||
[ChainId.Goerli]: CONTRACT_ADDRESSES[ChainId.Goerli].twFactory,
|
||||
[ChainId.Rinkeby]: CONTRACT_ADDRESSES[ChainId.Rinkeby].twFactory,
|
||||
[ChainId.Polygon]: CONTRACT_ADDRESSES[ChainId.Polygon].twFactory,
|
||||
[ChainId.Mumbai]: CONTRACT_ADDRESSES[ChainId.Mumbai].twFactory,
|
||||
[ChainId.Fantom]: CONTRACT_ADDRESSES[ChainId.Fantom].twFactory,
|
||||
[ChainId.FantomTestnet]:
|
||||
CONTRACT_ADDRESSES[ChainId.FantomTestnet].twFactory,
|
||||
[ChainId.Optimism]: CONTRACT_ADDRESSES[ChainId.Optimism].twFactory,
|
||||
[ChainId.OptimismTestnet]:
|
||||
CONTRACT_ADDRESSES[ChainId.OptimismTestnet].twFactory,
|
||||
[ChainId.Arbitrum]: CONTRACT_ADDRESSES[ChainId.Arbitrum].twFactory,
|
||||
[ChainId.ArbitrumTestnet]:
|
||||
CONTRACT_ADDRESSES[ChainId.ArbitrumTestnet].twFactory,
|
||||
}),
|
||||
implementationInitializerFunction: z.string(),
|
||||
factoryAddresses: ChainIdToAddressSchema,
|
||||
});
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const ExtraPublishMetadataSchema = z
|
||||
export const ExtraPublishMetadataSchemaInput = z
|
||||
.object({
|
||||
version: z.string().refine(
|
||||
(v) => {
|
||||
@@ -165,20 +148,41 @@ export const ExtraPublishMetadataSchema = z
|
||||
audit: FileBufferOrStringSchema.nullable().optional(),
|
||||
logo: FileBufferOrStringSchema.nullable().optional(),
|
||||
isDeployableViaFactory: z.boolean().optional(),
|
||||
factoryDeploymentData: FactoryDeploymentSchema.partial().optional(),
|
||||
factoryDeploymentData: FactoryDeploymentSchema.optional(),
|
||||
})
|
||||
.catchall(z.any());
|
||||
export type ExtraPublishMetadata = z.infer<typeof ExtraPublishMetadataSchema>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const FullPublishMetadataSchema = PreDeployMetadata.merge(
|
||||
ExtraPublishMetadataSchema,
|
||||
export const ExtraPublishMetadataSchemaOutput =
|
||||
ExtraPublishMetadataSchemaInput.extend({
|
||||
audit: z.string().nullable().optional(),
|
||||
logo: z.string().nullable().optional(),
|
||||
});
|
||||
export type ExtraPublishMetadata = z.input<
|
||||
typeof ExtraPublishMetadataSchemaInput
|
||||
>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const FullPublishMetadataSchemaInput = PreDeployMetadata.merge(
|
||||
ExtraPublishMetadataSchemaInput,
|
||||
).extend({
|
||||
publisher: AddressSchema.optional(),
|
||||
});
|
||||
export type FullPublishMetadata = z.infer<typeof FullPublishMetadataSchema>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const FullPublishMetadataSchemaOutput = PreDeployMetadata.merge(
|
||||
ExtraPublishMetadataSchemaOutput,
|
||||
).extend({
|
||||
publisher: AddressSchema.optional(),
|
||||
});
|
||||
export type FullPublishMetadata = z.infer<
|
||||
typeof FullPublishMetadataSchemaOutput
|
||||
>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
|
||||
@@ -236,6 +236,7 @@ describe("Publishing", async () => {
|
||||
version: "0.0.1",
|
||||
isDeployableViaFactory: true,
|
||||
factoryDeploymentData: {
|
||||
implementationInitializerFunction: "initialize",
|
||||
implementationAddresses: {
|
||||
[ChainId.Hardhat]: implementations["nft-collection"] || "",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user