Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/shy-toys-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/storage": major
---

Upgrade to initial storage SDK with IPFS support
6 changes: 3 additions & 3 deletions packages/cli/src/common/ci-installer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spinner } from "../core/helpers/logger";
import { IpfsStorage } from "@thirdweb-dev/storage";
import { ThirdwebStorage } from "@thirdweb-dev/storage";
import { existsSync, mkdirSync, writeFileSync } from "fs";
import path, { join } from "path";

Expand All @@ -13,10 +13,10 @@ export async function installGithubAction(options: any) {
: path.resolve(`${projectPath}/${options.path}`);
projectPath = resolvedPath;
}
const storage = new IpfsStorage();
const storage = new ThirdwebStorage();
const log = spinner("Installing thirdweb Github Action...");
try {
const ghActionData = await storage.getRaw(ghActionHash);
const ghActionData = await (await storage.download(ghActionHash)).text();
const dir = join(projectPath, ".github/workflows");
if (!existsSync(dir)) {
mkdirSync(dir, { recursive: true });
Expand Down
19 changes: 12 additions & 7 deletions packages/cli/src/common/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { execute } from "../core/helpers/exec";
import { error, info, logger, spinner } from "../core/helpers/logger";
import { createContractsPrompt } from "../core/helpers/selector";
import { ContractPayload } from "../core/interfaces/ContractPayload";
import { IpfsStorage } from "@thirdweb-dev/storage";
import { ThirdwebStorage } from "@thirdweb-dev/storage";
import chalk from "chalk";
import { readFileSync } from "fs";
import path from "path";
Expand All @@ -15,7 +15,7 @@ export async function processProject(
command: "deploy" | "release",
) {
// TODO: allow overriding the default storage
const storage = new IpfsStorage();
const storage = new ThirdwebStorage();

logger.setSettings({
minLevel: options.debug ? "debug" : "info",
Expand Down Expand Up @@ -129,7 +129,9 @@ export async function processProject(
if (file.includes(soliditySDKPackage)) {
usesSoliditySDK = true;
}
return await storage.uploadSingle(file);
return await storage.upload(file, {
uploadWithoutDirectory: true,
});
}),
);
}
Expand All @@ -140,14 +142,16 @@ export async function processProject(
const metadataURIs = await Promise.all(
selectedContracts.map(async (c) => {
logger.debug(`Uploading ${c.name}...`);
const hash = await storage.uploadSingle(c.metadata);
const hash = await storage.upload(c.metadata, {
uploadWithoutDirectory: true,
});
return `ipfs://${hash}`;
}),
);

// Upload batch all bytecodes
const bytecodes = selectedContracts.map((c) => c.bytecode);
const { uris: bytecodeURIs } = await storage.uploadBatch(bytecodes);
const bytecodeURIs = await storage.uploadBatch(bytecodes);

const combinedContents = selectedContracts.map((c, i) => {
// attach analytics blob to metadata
Expand All @@ -169,13 +173,14 @@ export async function processProject(
let combinedURIs: string[] = [];
if (combinedContents.length === 1) {
// use upload single if only one contract to get a clean IPFS hash
const metadataUri = await storage.uploadSingle(
const metadataUri = await storage.upload(
JSON.stringify(combinedContents[0]),
{ uploadWithoutDirectory: true },
);
combinedURIs.push(metadataUri);
} else {
// otherwise upload batch
const { uris } = await storage.uploadMetadataBatch(combinedContents);
const uris = await storage.uploadBatch(combinedContents);
combinedURIs = uris;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
getProviderForNetwork,
SDKOptionsOutput,
} from "@thirdweb-dev/sdk";
import type { IStorage } from "@thirdweb-dev/storage";
import type { ThirdwebStorage } from "@thirdweb-dev/storage";
import { Signer } from "ethers";
import React, { createContext, useEffect, useMemo } from "react";
import invariant from "tiny-invariant";
Expand Down Expand Up @@ -181,7 +181,7 @@ export interface ThirdwebProviderProps<
/**
* The storage interface to use with the sdk.
*/
storageInterface?: IStorage;
storageInterface?: ThirdwebStorage;

/**
* The react-query client to use. (Defaults to a default client.)
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/hooks/useReadonlySDK.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SDKOptions, ThirdwebSDK } from "@thirdweb-dev/sdk";
import type { IStorage } from "@thirdweb-dev/storage";
import type { ThirdwebStorage } from "@thirdweb-dev/storage";
import { useMemo } from "react";

/**
Expand All @@ -8,7 +8,7 @@ import { useMemo } from "react";
export function useReadonlySDK(
readonlyRpcUrl: string,
sdkOptions: SDKOptions,
storageInterface?: IStorage,
storageInterface?: ThirdwebStorage,
): ThirdwebSDK {
return useMemo(() => {
return new ThirdwebSDK(
Expand Down
14 changes: 7 additions & 7 deletions packages/sdk/src/common/claim-conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from "./currency";
import { createSnapshot } from "./snapshots";
import { IDropClaimCondition } from "@thirdweb-dev/contracts-js/dist/declarations/src/DropERC20";
import { IStorage } from "@thirdweb-dev/storage";
import { ThirdwebStorage } from "@thirdweb-dev/storage";
import {
BigNumber,
BigNumberish,
Expand All @@ -47,7 +47,7 @@ export async function prepareClaim(
merkleMetadataFetcher: () => Promise<Record<string, string>>,
tokenDecimals: number,
contractWrapper: ContractWrapper<any>,
storage: IStorage,
storage: ThirdwebStorage,
checkERC20Allowance: boolean,
): Promise<ClaimVerification> {
const addressToClaim = await contractWrapper.getSignerAddress();
Expand Down Expand Up @@ -131,15 +131,15 @@ type Snapshot =
export async function fetchSnapshot(
merkleRoot: string,
merkleMetadata: Record<string, string> | undefined,
storage: IStorage,
storage: ThirdwebStorage,
): Promise<Snapshot> {
if (!merkleMetadata) {
return undefined;
}
const snapshotUri = merkleMetadata[merkleRoot];
let snapshot: Snapshot = undefined;
if (snapshotUri) {
const raw = await storage.get(snapshotUri);
const raw = await storage.downloadJSON(snapshotUri);
const snapshotData = SnapshotSchema.parse(raw);
if (merkleRoot === snapshotData.merkleRoot) {
snapshot = snapshotData.claims;
Expand Down Expand Up @@ -211,7 +211,7 @@ export async function getClaimerProofs(
merkleRoot: string,
tokenDecimals: number,
merkleMetadata: Record<string, string>,
storage: IStorage,
storage: ThirdwebStorage,
): Promise<{ maxClaimable: BigNumber; proof: string[] }> {
const claims: Snapshot = await fetchSnapshot(
merkleRoot,
Expand Down Expand Up @@ -252,7 +252,7 @@ export async function processClaimConditionInputs(
claimConditionInputs: ClaimConditionInput[],
tokenDecimals: number,
provider: providers.Provider,
storage: IStorage,
storage: ThirdwebStorage,
) {
const snapshotInfos: SnapshotInfo[] = [];
const inputsWithSnapshots = await Promise.all(
Expand Down Expand Up @@ -355,7 +355,7 @@ export async function transformResultToClaimCondition(
tokenDecimals: number,
provider: providers.Provider,
merkleMetadata: Record<string, string> | undefined,
storage: IStorage,
storage: ThirdwebStorage,
): Promise<ClaimCondition> {
const cv = await fetchCurrencyValue(provider, pm.currency, pm.pricePerToken);

Expand Down
30 changes: 16 additions & 14 deletions packages/sdk/src/common/feature-detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
PublishedMetadata,
} from "../schema/contracts/custom";
import { ExtensionNotImplementedError } from "./error";
import { IStorage } from "@thirdweb-dev/storage";
import { ThirdwebStorage } from "@thirdweb-dev/storage";
import { BaseContract, ethers } from "ethers";
import { z } from "zod";

Expand Down Expand Up @@ -57,7 +57,7 @@ function matchesAbiInterface(
*/
export async function extractConstructorParams(
predeployMetadataUri: string,
storage: IStorage,
storage: ThirdwebStorage,
) {
const meta = await fetchPreDeployMetadata(predeployMetadataUri, storage);
return extractConstructorParamsFromAbi(meta.abi);
Expand All @@ -70,7 +70,7 @@ export async function extractConstructorParams(
*/
export async function extractFunctions(
predeployMetadataUri: string,
storage: IStorage,
storage: ThirdwebStorage,
): Promise<AbiFunction[]> {
const metadata = await fetchPreDeployMetadata(predeployMetadataUri, storage);
return extractFunctionsFromAbi(metadata.abi, metadata.metadata);
Expand Down Expand Up @@ -328,7 +328,7 @@ function isHexStrict(hex: string | number) {
export async function fetchContractMetadataFromAddress(
address: string,
provider: ethers.providers.Provider,
storage: IStorage,
storage: ThirdwebStorage,
) {
const compilerMetadataUri = await resolveContractUriFromAddress(
address,
Expand All @@ -347,9 +347,9 @@ export async function fetchContractMetadataFromAddress(
*/
export async function fetchContractMetadata(
compilerMetadataUri: string,
storage: IStorage,
storage: ThirdwebStorage,
): Promise<PublishedMetadata> {
const metadata = await storage.get(compilerMetadataUri);
const metadata = await storage.downloadJSON(compilerMetadataUri);
const abi = AbiSchema.parse(metadata.output.abi);
const compilationTarget = metadata.settings.compilationTarget;
const targets = Object.keys(compilationTarget);
Expand Down Expand Up @@ -381,7 +381,7 @@ export async function fetchContractMetadata(
*/
export async function fetchSourceFilesFromMetadata(
publishedMetadata: PublishedMetadata,
storage: IStorage,
storage: ThirdwebStorage,
): Promise<ContractSource[]> {
return await Promise.all(
Object.entries(publishedMetadata.metadata.sources).map(
Expand All @@ -395,7 +395,7 @@ export async function fetchSourceFilesFromMetadata(
setTimeout(() => rej("timeout"), 5000),
);
const source = await Promise.race([
storage.getRaw(`ipfs://${ipfsHash}`),
(await storage.download(`ipfs://${ipfsHash}`)).text(),
timeout,
]);
return {
Expand All @@ -420,10 +420,10 @@ export async function fetchSourceFilesFromMetadata(
*/
export async function fetchRawPredeployMetadata(
publishMetadataUri: string,
storage: IStorage,
storage: ThirdwebStorage,
) {
return PreDeployMetadata.parse(
JSON.parse(await storage.getRaw(publishMetadataUri)),
JSON.parse(await (await storage.download(publishMetadataUri)).text()),
);
}

Expand All @@ -435,10 +435,12 @@ export async function fetchRawPredeployMetadata(
*/
export async function fetchPreDeployMetadata(
publishMetadataUri: string,
storage: IStorage,
storage: ThirdwebStorage,
): Promise<PreDeployMetadataFetched> {
const rawMeta = await fetchRawPredeployMetadata(publishMetadataUri, storage);
const deployBytecode = await storage.getRaw(rawMeta.bytecodeUri);
const deployBytecode = await (
await storage.download(rawMeta.bytecodeUri)
).text();
const parsedMeta = await fetchContractMetadata(rawMeta.metadataUri, storage);
return PreDeployMetadataFetchedSchema.parse({
...rawMeta,
Expand All @@ -455,9 +457,9 @@ export async function fetchPreDeployMetadata(
*/
export async function fetchExtendedReleaseMetadata(
publishMetadataUri: string,
storage: IStorage,
storage: ThirdwebStorage,
): Promise<FullPublishMetadata> {
const meta = await storage.getRaw(publishMetadataUri);
const meta = await (await storage.download(publishMetadataUri)).text();
return FullPublishMetadataSchemaOutput.parse(JSON.parse(meta));
}

Expand Down
Loading