Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mint client to fix reading from subgraph #392

Merged
merged 4 commits into from
Nov 29, 2023
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/sharp-bobcats-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zoralabs/protocol-sdk": patch
---

Fix reading the FIXED_PRICE_MINTER from the subgraph
2 changes: 1 addition & 1 deletion packages/protocol-sdk/src/create/1155-create-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const DEFAULT_SALE_SETTINGS = {
};

// Hardcode the permission bit for the minter
const PERMISSION_BIT_MINTER = 2n ** 2n;
const PERMISSION_BIT_MINTER = 4n;

type ContractType =
| {
Expand Down
32 changes: 27 additions & 5 deletions packages/protocol-sdk/src/mint/mint-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,40 @@ export class MintAPIClient {
}: {
contractAddress: string;
tokenId: bigint;
}): Promise<undefined | string> {
}): Promise<undefined | { address: Address; pricePerToken: bigint }> {
const { retries, post } = this.httpClient;
return retries(async () => {
const response = await post<any>(this.networkConfig.subgraphUrl, {
query:
"query($id: ID!) {\n zoraCreateToken(id: $id) {\n id\n salesStrategies{\n fixedPrice {\n address\n }\n }\n }\n}",
query: `query ($id: ID!) {
zoraCreateToken(id: $id) {
id
salesStrategies(where: {type: "FIXED_PRICE"}) {
type
fixedPrice {
address
pricePerToken
saleEnd
saleStart
maxTokensPerAddress
}
}
}
}`,
variables: {
id: `${contractAddress.toLowerCase()}-${tokenId.toString()}`,
},
});
return response.zoraCreateToken?.salesStrategies?.find(() => true)
?.fixedPriceMinterAddress;

const fixedPrice: {
address: Address;
pricePerToken: string;
} = response.data?.zoraCreateToken?.salesStrategies?.find(() => true)
?.fixedPrice;

return {
address: fixedPrice.address as Address,
pricePerToken: BigInt(fixedPrice.pricePerToken),
};
});
}

Expand Down
21 changes: 13 additions & 8 deletions packages/protocol-sdk/src/mint/mint-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class MintClient {
if (mintContextType === "zora_create_1155") {
return await get1155MintCosts({
mintable,
price: BigInt(mintable.cost.native_price.raw),
publicClient: this.publicClient,
quantityToMint: BigInt(quantityToMint),
});
Expand Down Expand Up @@ -306,10 +307,12 @@ export type MintCosts = {

export async function get1155MintCosts({
mintable,
price,
publicClient,
quantityToMint,
}: {
mintable: MintableGetTokenResponse;
price: bigint;
publicClient: PublicClient;
quantityToMint: bigint;
}): Promise<MintCosts> {
Expand All @@ -321,8 +324,7 @@ export async function get1155MintCosts({
});

const mintFeeForTokens = mintFee * quantityToMint;
const tokenPurchaseCost =
BigInt(mintable.cost.native_price.raw) * quantityToMint;
const tokenPurchaseCost = price * quantityToMint;

return {
mintFee: mintFeeForTokens,
Expand Down Expand Up @@ -354,19 +356,22 @@ async function makePrepareMint1155TokenParams({

const address = mintable.collection.address as Address;

const tokenFixedPriceMinter = await apiClient.getSalesConfigFixedPrice({
contractAddress: address,
tokenId: BigInt(mintable.token_id!),
});

const mintValue = (
await get1155MintCosts({
mintable,
price:
tokenFixedPriceMinter?.pricePerToken ||
BigInt(mintable.cost.native_price.raw),
publicClient,
quantityToMint: mintQuantity,
})
).totalCost;

const tokenFixedPriceMinter = await apiClient.getSalesConfigFixedPrice({
contractAddress: address,
tokenId: BigInt(mintable.token_id!),
});

const result = {
abi: zoraCreator1155ImplABI,
functionName: "mintWithRewards",
Expand All @@ -375,7 +380,7 @@ async function makePrepareMint1155TokenParams({
address,
/* args: minter, tokenId, quantity, minterArguments, mintReferral */
args: [
(tokenFixedPriceMinter ||
(tokenFixedPriceMinter?.address ||
zoraCreatorFixedPriceSaleStrategyAddress[999]) as Address,
BigInt(mintable.token_id!),
mintQuantity,
Expand Down
Loading