Skip to content

Commit

Permalink
properly format
Browse files Browse the repository at this point in the history
  • Loading branch information
oveddan committed Nov 24, 2023
1 parent 2b38471 commit 70650b8
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 174 deletions.
4 changes: 2 additions & 2 deletions packages/protocol-sdk/src/anvil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function waitForAnvilInit(anvil: any) {
export type AnvilTestForkSettings = {
forkUrl: string;
forkBlockNumber: number;
}
};

export const makeAnvilTest = ({
forkUrl,
Expand All @@ -56,7 +56,7 @@ export const makeAnvilTest = ({
{
cwd: join(__dirname, ".."),
killSignal: "SIGINT",
},
}
);
const anvilHost = `http://0.0.0.0:${port}`;
await waitForAnvilInit(anvil);
Expand Down
6 changes: 3 additions & 3 deletions packages/protocol-sdk/src/apis/http-api-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const get = async <T>(url: string) => {
throw new BadResponseError(
`Invalid response, status ${response.status}`,
response.status,
json,
json
);
}
return (await response.json()) as T;
Expand Down Expand Up @@ -65,7 +65,7 @@ export const post = async <T>(url: string, data: any) => {
throw new BadResponseError(
`Bad response: ${response.status}`,
response.status,
json,
json
);
}
return (await response.json()) as T;
Expand All @@ -75,7 +75,7 @@ export const retries = async <T>(
tryFn: () => T,
maxTries: number = 3,
atTry: number = 1,
linearBackoffMS: number = 200,
linearBackoffMS: number = 200
): Promise<T> => {
try {
return await tryFn();
Expand Down
17 changes: 9 additions & 8 deletions packages/protocol-sdk/src/create/1155-create-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("create-helper", () => {
expect(receipt.to).to.equal("0x777777c338d93e2c7adf08d102d45ca7cc4ed021");
expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(1n);
},
20 * 1000,
20 * 1000
);
anvilTest(
"creates a new contract, than creates a new token on this existing contract",
Expand All @@ -62,11 +62,12 @@ describe("create-helper", () => {
mintToCreatorCount: 1,
});
expect(contractAddress).to.be.equal(
"0xb1A8928dF830C21eD682949Aa8A83C1C215194d3",
"0xb1A8928dF830C21eD682949Aa8A83C1C215194d3"
);
expect(contractExists).to.be.false;
const { request: simulateResponse } =
await publicClient.simulateContract(request);
const { request: simulateResponse } = await publicClient.simulateContract(
request
);
const hash = await walletClient.writeContract(simulateResponse);
const receipt = await publicClient.waitForTransactionReceipt({ hash });
const firstTokenId = getTokenIdFromCreateReceipt(receipt);
Expand All @@ -82,14 +83,14 @@ describe("create-helper", () => {
tokenMetadataURI: demoTokenMetadataURI,
account: creatorAccount,
mintToCreatorCount: 1,
},
}
);
expect(newTokenOnExistingContract.contractAddress).to.be.equal(
"0xb1A8928dF830C21eD682949Aa8A83C1C215194d3",
"0xb1A8928dF830C21eD682949Aa8A83C1C215194d3"
);
expect(newTokenOnExistingContract.contractExists).to.be.true;
const { request: simulateRequest } = await publicClient.simulateContract(
newTokenOnExistingContract.request,
newTokenOnExistingContract.request
);
const newHash = await walletClient.writeContract(simulateRequest);
const newReceipt = await publicClient.waitForTransactionReceipt({
Expand All @@ -99,6 +100,6 @@ describe("create-helper", () => {
expect(tokenId).to.be.equal(2n);
expect(newReceipt).not.toBeNull();
},
20 * 1000,
20 * 1000
);
});
10 changes: 5 additions & 5 deletions packages/protocol-sdk/src/create/1155-create-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export function create1155TokenSetupArgs({
abi: zoraCreator1155ImplABI,
functionName: "adminMint",
args: [account, nextTokenId, mintToCreatorCount, "0x"],
}),
})
);
}

Expand All @@ -160,15 +160,15 @@ export function create1155TokenSetupArgs({
royaltyRecipient: royaltySettings?.royaltyRecipient || account,
},
],
}),
})
);
}

return setupActions;
}

export const getTokenIdFromCreateReceipt = (
receipt: TransactionReceipt,
receipt: TransactionReceipt
): bigint | undefined => {
for (const data of receipt.logs) {
try {
Expand All @@ -188,7 +188,7 @@ async function getContractExists(
publicClient: PublicClient,
contract: ContractType,
// Account that is the creator of the contract
account: Address,
account: Address
) {
let contractAddress;
let contractExists = false;
Expand Down Expand Up @@ -266,7 +266,7 @@ export function create1155CreatorClient({
const { contractExists, contractAddress } = await getContractExists(
publicClient,
contract,
account,
account
);

// Assume the next token id is the first token available for a new contract.
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol-sdk/src/mint/mint-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ function encodeQueryParameters(params: Record<string, string>) {

const getMintable = async (
path: MintableGetTokenPathParameters,
query: MintableGetTokenGetQueryParameters,
query: MintableGetTokenGetQueryParameters
): Promise<MintableGetTokenResponse> =>
retries(() => {
return get<MintableGetTokenResponse>(
`${ZORA_API_BASE}discover/mintables/${path.chain_name}/${
path.collection_address
}${query?.token_id ? `?${encodeQueryParameters(query)}` : ""}`,
}${query?.token_id ? `?${encodeQueryParameters(query)}` : ""}`
);
});

Expand Down
4 changes: 2 additions & 2 deletions packages/protocol-sdk/src/mint/mint-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("mint-helper", () => {
expect(oldBalance).to.be.equal(0n);
expect(newBalance).to.be.equal(1n);
},
12 * 1000,
12 * 1000
);

anvilTest(
Expand Down Expand Up @@ -112,6 +112,6 @@ describe("mint-helper", () => {
expect(oldBalance).to.be.equal(0n);
expect(newBalance).to.be.equal(1n);
},
12 * 1000,
12 * 1000
);
});
8 changes: 4 additions & 4 deletions packages/protocol-sdk/src/mint/mint-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MintClient extends ClientBase {
chain_name: this.network.zoraBackendChainName,
collection_address: tokenContract,
},
{ token_id: tokenId?.toString() },
{ token_id: tokenId?.toString() }
);
}

Expand Down Expand Up @@ -95,11 +95,11 @@ class MintClient extends ClientBase {

if (
!["zora_create", "zora_create_1155"].includes(
mintable.mint_context?.mint_context_type!,
mintable.mint_context?.mint_context_type!
)
) {
throw new MintError(
`Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`,
`Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`
);
}

Expand Down Expand Up @@ -150,7 +150,7 @@ class MintClient extends ClientBase {
contractAddress: mintable.contract_address,
tokenId: mintable.token_id!,
subgraphUrl: this.network.subgraphUrl,
},
}
);

const result: SimulateContractParameters<
Expand Down
16 changes: 8 additions & 8 deletions packages/protocol-sdk/src/premint/premint-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ export type PremintSignatureGetResponse =
export type BackendChainNames = components["schemas"]["ChainName"];

const postSignature = async (
data: PremintSignatureRequestBody,
data: PremintSignatureRequestBody
): Promise<PremintSignatureResponse> =>
retries(() =>
post<PremintSignatureResponse>(`${ZORA_API_BASE}premint/signature`, data),
post<PremintSignatureResponse>(`${ZORA_API_BASE}premint/signature`, data)
);

const getNextUID = async (
path: PremintNextUIDGetPathParameters,
path: PremintNextUIDGetPathParameters
): Promise<PremintNextUIDGetResponse> =>
retries(() =>
get<PremintNextUIDGetResponse>(
`${ZORA_API_BASE}premint/signature/${path.chain_name}/${path.collection_address}/next_uid`,
),
`${ZORA_API_BASE}premint/signature/${path.chain_name}/${path.collection_address}/next_uid`
)
);

const getSignature = async (
path: PremintSignatureGetPathParameters,
path: PremintSignatureGetPathParameters
): Promise<PremintSignatureGetResponse> =>
retries(() =>
get<PremintSignatureGetResponse>(
`${ZORA_API_BASE}premint/signature/${path.chain_name}/${path.collection_address}/${path.uid}`,
),
`${ZORA_API_BASE}premint/signature/${path.chain_name}/${path.collection_address}/${path.uid}`
)
);

export const PremintAPIClient = {
Expand Down
11 changes: 6 additions & 5 deletions packages/protocol-sdk/src/premint/premint-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe("ZoraCreator1155Premint", () => {
"0x588d19641de9ba1dade4d2bb5387c8dc96f4a990fef69787534b60caead759e6334975a6be10a796da948cd7d1d4f5580b3f84d49d9fa4e0b41c97759507975a1c",
});
},
20 * 1000,
20 * 1000
);

anvilTest.skip(
Expand Down Expand Up @@ -112,7 +112,7 @@ describe("ZoraCreator1155Premint", () => {
publicClient,
});
expect(signatureValid.isValid).toBe(true);
},
}
);

anvilTest(
Expand Down Expand Up @@ -163,8 +163,9 @@ describe("ZoraCreator1155Premint", () => {
mintComment: "",
},
});
const { request: simulateRequest } =
await publicClient.simulateContract(request);
const { request: simulateRequest } = await publicClient.simulateContract(
request
);
const hash = await walletClient.writeContract(simulateRequest);
const receipt = await publicClient.waitForTransactionReceipt({ hash });
const { premintedLog, urls } =
Expand Down Expand Up @@ -207,6 +208,6 @@ describe("ZoraCreator1155Premint", () => {
uid: 3,
});
},
20 * 1000,
20 * 1000
);
});
23 changes: 12 additions & 11 deletions packages/protocol-sdk/src/premint/premint-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const DefaultMintArguments = {
* @returns Premint event arguments
*/
export function getPremintedLogFromReceipt(
receipt: TransactionReceipt,
receipt: TransactionReceipt
): PremintedLogType | undefined {
for (const data of receipt.logs) {
try {
Expand All @@ -104,7 +104,7 @@ export function getPremintedLogFromReceipt(
* @returns Viem type-compatible premint object
*/
export const convertPremint = (
premint: PremintSignatureGetResponse["premint"],
premint: PremintSignatureGetResponse["premint"]
) => ({
...premint,
tokenConfig: {
Expand All @@ -120,7 +120,7 @@ export const convertPremint = (
});

export const convertCollection = (
collection: PremintSignatureGetResponse["collection"],
collection: PremintSignatureGetResponse["collection"]
) => ({
...collection,
contractAdmin: collection.contractAdmin as Address,
Expand Down Expand Up @@ -160,11 +160,11 @@ export const encodePremintV2ForAPI = ({
mintDuration: tokenConfig.mintDuration.toString(),
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString(),
},
})
});

export const encodePremintForAPI = ({
premintConfig,
premintConfigVersion
premintConfigVersion,
}: PremintConfigAndVersion) => {
if (premintConfigVersion === PremintConfigVersion.V1) {
return encodePremintV1ForAPI(premintConfig);
Expand All @@ -173,8 +173,7 @@ export const encodePremintForAPI = ({
return encodePremintV2ForAPI(premintConfig);
}
throw new Error(`Invalid premint config version ${premintConfigVersion}`);
}

};

/**
* Preminter API to access ZORA Premint functionality.
Expand Down Expand Up @@ -285,7 +284,7 @@ class PremintClient extends ClientBase {
contractAdmin: signerData.collection.contractAdmin as Address,
},
premintConfig: signerData.premint,
premintConfigVersion: PremintConfigVersion.V1
premintConfigVersion: PremintConfigVersion.V1,
});
}

Expand Down Expand Up @@ -340,7 +339,7 @@ class PremintClient extends ClientBase {
uid: uid,
collection: signerData.collection,
premintConfig: signerData.premint,
premintConfigVersion: PremintConfigVersion.V1
premintConfigVersion: PremintConfigVersion.V1,
});
}

Expand Down Expand Up @@ -391,14 +390,16 @@ class PremintClient extends ClientBase {
originalContractAdmin: collection.contractAdmin as Address,
...premintConfigAndVersion,
publicClient,
signature
signature,
});
if (!isAuthorized) {
throw new Error("Not authorized to create premint");
}
}

if (premintConfigAndVersion.premintConfigVersion === PremintConfigVersion.V2) {
if (
premintConfigAndVersion.premintConfigVersion === PremintConfigVersion.V2
) {
throw new Error("premint config v2 not supported yet");
}

Expand Down
Loading

0 comments on commit 70650b8

Please sign in to comment.