-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDK support for creating / collecting on primary for ZoraTimedSaleStr…
…ategy (#663) * Adds support for creating/minting with the new zora timed sales strategy, only for primary sales * By default when creating a new token, the sales strategy will be the new timed sales strategy. * If token price is set to 0, it will use the new timed sales strategy * If token price is set to non 0, it uses the fixed priced minter For erc20z name and symbol, if they are not provided, it gets the name from the token metadata json which it fetches from ipfs, then uses logic extracted from zora-co to convert that to a symbol It also adds support for stubbing the subgraph queries in tests, which was used for testing out minting after creating using the timed sales strategy It also includes timed sale strategy errors in the zora1155 abi that is published to protocol-deplooyments, to enable those errors to be decoded by viem ToDo: * [x] docs
- Loading branch information
Showing
27 changed files
with
1,008 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@zoralabs/protocol-sdk": minor | ||
--- | ||
|
||
ProtocolSDK - add support for creating 1155s using the new ZoraTimedSaleStrategy. Default to use the new ZoraTimedSaleStrategy. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
docs/snippets/protocol-sdk/create/createNew1155TokenErc20zName.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { createCreatorClient } from "@zoralabs/protocol-sdk"; | ||
import { publicClient, chainId, creatorAccount } from "./config"; | ||
|
||
const creatorClient = createCreatorClient({ chainId, publicClient }); | ||
|
||
const { parameters } = await creatorClient.create1155({ | ||
contract: { | ||
name: "testContract", | ||
uri: "ipfs://DUMMY/contract.json", | ||
}, | ||
token: { | ||
tokenMetadataURI: "ipfs://DUMMY/token.json", | ||
salesConfig: { | ||
// manually specifying the erc20 name and symbol | ||
erc20Name: "My Token Name", // [!code hl] | ||
erc20Symbol: "MTN", // [!code hl] | ||
}, | ||
}, | ||
account: creatorAccount, | ||
}); | ||
|
||
// simulate the transaction | ||
await publicClient.simulateContract(parameters); |
46 changes: 46 additions & 0 deletions
46
docs/snippets/protocol-sdk/create/createNew1155WithPrice.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { | ||
useAccount, | ||
useChainId, | ||
usePublicClient, | ||
useWriteContract, | ||
} from "wagmi"; | ||
import { parseEther } from "viem"; | ||
import { createCreatorClient } from "@zoralabs/protocol-sdk"; | ||
|
||
// use wagmi hooks to get the chainId, publicClient, and account | ||
const chainId = useChainId(); | ||
const publicClient = usePublicClient()!; | ||
const { address } = useAccount(); | ||
|
||
const creatorClient = createCreatorClient({ chainId, publicClient }); | ||
|
||
const { parameters, contractAddress } = await creatorClient.create1155({ | ||
// the contract will be created at a deterministic address | ||
contract: { | ||
// contract name | ||
name: "testContract", | ||
// contract metadata uri | ||
uri: "ipfs://DUMMY/contract.json", | ||
}, | ||
token: { | ||
tokenMetadataURI: "ipfs://DUMMY/token.json", | ||
salesConfig: { | ||
// setting a price per token on the `salesConfig` will | ||
// result in the token being created with a fixed price in addition | ||
// to the mint fee. In this case, creator rewards will not be earned | ||
// on the mint fee, the `ZoraCreatorFixedPriceSaleStrategy` is setup | ||
// as the minter for this token, and correspondingly the onchain | ||
// secondary market feature will NOT be used for tokens minted using | ||
// that minter. | ||
pricePerToken: parseEther("0.1"), // [!code hl] | ||
}, | ||
}, | ||
// account to execute the transaction (the creator) | ||
account: address!, | ||
}); | ||
|
||
const { writeContract } = useWriteContract(); | ||
|
||
writeContract(parameters); | ||
|
||
export { contractAddress }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,6 @@ | |
"tsup": "^7.2.0", | ||
"typescript": "^5.2.2", | ||
"vite": "^4.5.0", | ||
"vitest": "^0.34.6" | ||
"vitest": "^2.0.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { IHttpClient } from "./http-api-base"; | ||
|
||
export interface ISubgraphQuerier { | ||
query: (params: { | ||
subgraphUrl: string; | ||
query: string; | ||
variables?: Record<string, any>; | ||
}) => Promise<object | undefined>; | ||
} | ||
|
||
export class SubgraphQuerier implements ISubgraphQuerier { | ||
httpClient: IHttpClient; | ||
|
||
constructor(httpClient: IHttpClient) { | ||
this.httpClient = httpClient; | ||
} | ||
|
||
async query({ | ||
subgraphUrl, | ||
query, | ||
variables, | ||
}: { | ||
subgraphUrl: string; | ||
query: string; | ||
variables?: Record<string, any>; | ||
}) { | ||
const { retries, post } = this.httpClient; | ||
|
||
const result = await retries(async () => { | ||
return await post<any>(subgraphUrl, { | ||
query, | ||
variables, | ||
}); | ||
}); | ||
|
||
return result?.data; | ||
} | ||
} |
Oops, something went wrong.