@zoralabs/protocol-sdk 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +6 -0
- package/dist/anvil.d.ts.map +1 -1
- package/dist/apis/http-api-base.d.ts +1 -1
- package/dist/apis/http-api-base.d.ts.map +1 -1
- package/dist/apis/subgraph-querier.d.ts +6 -0
- package/dist/apis/subgraph-querier.d.ts.map +1 -1
- package/dist/create/1155-create-helper.d.ts +4 -1
- package/dist/create/1155-create-helper.d.ts.map +1 -1
- package/dist/create/contract-getter.d.ts +30 -0
- package/dist/create/contract-getter.d.ts.map +1 -0
- package/dist/create/contract-setup.d.ts +4 -8
- package/dist/create/contract-setup.d.ts.map +1 -1
- package/dist/create/mint-from-create.d.ts +3 -3
- package/dist/create/mint-from-create.d.ts.map +1 -1
- package/dist/create/subgraph-queries.d.ts +13 -0
- package/dist/create/subgraph-queries.d.ts.map +1 -0
- package/dist/index.cjs +176 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +155 -76
- package/dist/index.js.map +1 -1
- package/dist/mint/subgraph-mint-getter.d.ts +2 -2
- package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
- package/dist/mint/subgraph-queries.d.ts +1 -5
- package/dist/mint/subgraph-queries.d.ts.map +1 -1
- package/dist/retries.d.ts +7 -0
- package/dist/retries.d.ts.map +1 -0
- package/dist/sdk.d.ts +2 -0
- package/dist/sdk.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/apis/http-api-base.ts +12 -20
- package/src/apis/subgraph-querier.ts +7 -0
- package/src/create/1155-create-helper.test.ts +22 -1
- package/src/create/1155-create-helper.ts +18 -9
- package/src/create/contract-getter.ts +90 -0
- package/src/create/contract-setup.ts +17 -46
- package/src/create/mint-from-create.ts +7 -15
- package/src/create/subgraph-queries.ts +35 -0
- package/src/mint/subgraph-mint-getter.ts +5 -2
- package/src/mint/subgraph-queries.ts +1 -7
- package/src/retries.ts +49 -0
- package/src/sdk.ts +8 -0
- package/test-integration/create-multiple-tokens-on-contract.ts +104 -0
package/dist/index.js
CHANGED
|
@@ -2503,6 +2503,44 @@ import {
|
|
|
2503
2503
|
premintTypedDataDefinition as premintTypedDataDefinition2
|
|
2504
2504
|
} from "@zoralabs/protocol-deployments";
|
|
2505
2505
|
|
|
2506
|
+
// src/retries.ts
|
|
2507
|
+
async function wait(delayMs) {
|
|
2508
|
+
return new Promise((resolve) => {
|
|
2509
|
+
setTimeout(resolve, delayMs);
|
|
2510
|
+
});
|
|
2511
|
+
}
|
|
2512
|
+
var retryInternal = async ({
|
|
2513
|
+
tryFn,
|
|
2514
|
+
maxTries = 3,
|
|
2515
|
+
atTry,
|
|
2516
|
+
linearBackoffMS = 200,
|
|
2517
|
+
shouldRetryOnError = () => true
|
|
2518
|
+
}) => {
|
|
2519
|
+
try {
|
|
2520
|
+
return await tryFn();
|
|
2521
|
+
} catch (err) {
|
|
2522
|
+
if (shouldRetryOnError(err)) {
|
|
2523
|
+
if (atTry <= maxTries) {
|
|
2524
|
+
await wait(atTry * linearBackoffMS);
|
|
2525
|
+
return await retryInternal({
|
|
2526
|
+
tryFn,
|
|
2527
|
+
maxTries,
|
|
2528
|
+
atTry: atTry + 1,
|
|
2529
|
+
linearBackoffMS,
|
|
2530
|
+
shouldRetryOnError
|
|
2531
|
+
});
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
throw err;
|
|
2535
|
+
}
|
|
2536
|
+
};
|
|
2537
|
+
var retriesGeneric = async (params) => {
|
|
2538
|
+
return retryInternal({
|
|
2539
|
+
...params,
|
|
2540
|
+
atTry: 1
|
|
2541
|
+
});
|
|
2542
|
+
};
|
|
2543
|
+
|
|
2506
2544
|
// src/apis/http-api-base.ts
|
|
2507
2545
|
var BadResponseError = class extends Error {
|
|
2508
2546
|
constructor(message, status, json) {
|
|
@@ -2512,11 +2550,6 @@ var BadResponseError = class extends Error {
|
|
|
2512
2550
|
this.json = json;
|
|
2513
2551
|
}
|
|
2514
2552
|
};
|
|
2515
|
-
async function wait(delayMs) {
|
|
2516
|
-
return new Promise((resolve) => {
|
|
2517
|
-
setTimeout(resolve, delayMs);
|
|
2518
|
-
});
|
|
2519
|
-
}
|
|
2520
2553
|
var get = async (url) => {
|
|
2521
2554
|
const response = await fetch(url, { method: "GET" });
|
|
2522
2555
|
if (response.status !== 200) {
|
|
@@ -2562,20 +2595,16 @@ var post = async (url, data) => {
|
|
|
2562
2595
|
}
|
|
2563
2596
|
return await response.json();
|
|
2564
2597
|
};
|
|
2565
|
-
var retries = async (tryFn, maxTries = 3,
|
|
2566
|
-
|
|
2567
|
-
return
|
|
2568
|
-
}
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
}
|
|
2576
|
-
}
|
|
2577
|
-
throw err;
|
|
2578
|
-
}
|
|
2598
|
+
var retries = async (tryFn, maxTries = 3, linearBackoffMS = 200) => {
|
|
2599
|
+
const shouldRetry = (err) => {
|
|
2600
|
+
return err instanceof BadResponseError && err.status >= 500;
|
|
2601
|
+
};
|
|
2602
|
+
return retriesGeneric({
|
|
2603
|
+
tryFn,
|
|
2604
|
+
maxTries,
|
|
2605
|
+
linearBackoffMS,
|
|
2606
|
+
shouldRetryOnError: shouldRetry
|
|
2607
|
+
});
|
|
2579
2608
|
};
|
|
2580
2609
|
var httpClient = {
|
|
2581
2610
|
get,
|
|
@@ -4212,7 +4241,7 @@ async function mint({
|
|
|
4212
4241
|
import {
|
|
4213
4242
|
zoraCreator1155FactoryImplABI as zoraCreator1155FactoryImplABI2,
|
|
4214
4243
|
zoraCreator1155FactoryImplAddress as zoraCreator1155FactoryImplAddress2,
|
|
4215
|
-
zoraCreator1155ImplABI as
|
|
4244
|
+
zoraCreator1155ImplABI as zoraCreator1155ImplABI6
|
|
4216
4245
|
} from "@zoralabs/protocol-deployments";
|
|
4217
4246
|
import { decodeEventLog as decodeEventLog2 } from "viem";
|
|
4218
4247
|
|
|
@@ -4230,36 +4259,6 @@ function new1155ContractVersion(chainId) {
|
|
|
4230
4259
|
}
|
|
4231
4260
|
return address.CONTRACT_1155_IMPL_VERSION;
|
|
4232
4261
|
}
|
|
4233
|
-
async function getContractInfoExistingContract({
|
|
4234
|
-
publicClient,
|
|
4235
|
-
contractAddress
|
|
4236
|
-
}) {
|
|
4237
|
-
let contractVersion;
|
|
4238
|
-
try {
|
|
4239
|
-
contractVersion = await publicClient.readContract({
|
|
4240
|
-
abi: zoraCreator1155ImplABI3,
|
|
4241
|
-
address: contractAddress,
|
|
4242
|
-
functionName: "contractVersion"
|
|
4243
|
-
});
|
|
4244
|
-
} catch (e) {
|
|
4245
|
-
throw new Error(`Contract does not exist at ${contractAddress}`);
|
|
4246
|
-
}
|
|
4247
|
-
const nextTokenId = await publicClient.readContract({
|
|
4248
|
-
address: contractAddress,
|
|
4249
|
-
abi: zoraCreator1155ImplABI3,
|
|
4250
|
-
functionName: "nextTokenId"
|
|
4251
|
-
});
|
|
4252
|
-
const contractName = await publicClient.readContract({
|
|
4253
|
-
address: contractAddress,
|
|
4254
|
-
abi: zoraCreator1155ImplABI3,
|
|
4255
|
-
functionName: "name"
|
|
4256
|
-
});
|
|
4257
|
-
return {
|
|
4258
|
-
contractVersion,
|
|
4259
|
-
contractName,
|
|
4260
|
-
nextTokenId
|
|
4261
|
-
};
|
|
4262
|
-
}
|
|
4263
4262
|
async function getDeterministicContractAddress({
|
|
4264
4263
|
publicClient,
|
|
4265
4264
|
account,
|
|
@@ -4281,6 +4280,17 @@ async function getDeterministicContractAddress({
|
|
|
4281
4280
|
});
|
|
4282
4281
|
return contractAddress;
|
|
4283
4282
|
}
|
|
4283
|
+
async function getNewContractMintFee({
|
|
4284
|
+
publicClient,
|
|
4285
|
+
chainId
|
|
4286
|
+
}) {
|
|
4287
|
+
const implAddress = contracts1155.addresses[chainId].CONTRACT_1155_IMPL;
|
|
4288
|
+
return await publicClient.readContract({
|
|
4289
|
+
abi: zoraCreator1155ImplABI3,
|
|
4290
|
+
address: implAddress,
|
|
4291
|
+
functionName: "mintFee"
|
|
4292
|
+
});
|
|
4293
|
+
}
|
|
4284
4294
|
|
|
4285
4295
|
// src/create/token-setup.ts
|
|
4286
4296
|
var semver2 = __toESM(require_semver2(), 1);
|
|
@@ -5816,12 +5826,10 @@ var contractSupportsMintRewards = (contractVersion, contractStandard) => {
|
|
|
5816
5826
|
|
|
5817
5827
|
// src/create/mint-from-create.ts
|
|
5818
5828
|
import { parseEther as parseEther3, zeroAddress as zeroAddress6 } from "viem";
|
|
5819
|
-
import { zoraCreator1155ImplABI as zoraCreator1155ImplABI6 } from "@zoralabs/protocol-deployments";
|
|
5820
5829
|
async function toSalesStrategyFromSubgraph({
|
|
5821
5830
|
minter,
|
|
5822
5831
|
salesConfig,
|
|
5823
|
-
|
|
5824
|
-
contractAddress
|
|
5832
|
+
getContractMintFee
|
|
5825
5833
|
}) {
|
|
5826
5834
|
if (salesConfig.type === "timed") {
|
|
5827
5835
|
return {
|
|
@@ -5850,11 +5858,7 @@ async function toSalesStrategyFromSubgraph({
|
|
|
5850
5858
|
maxTokensPerAddress: salesConfig.maxTokensPerAddress
|
|
5851
5859
|
};
|
|
5852
5860
|
}
|
|
5853
|
-
const contractMintFee = await
|
|
5854
|
-
abi: zoraCreator1155ImplABI6,
|
|
5855
|
-
address: contractAddress,
|
|
5856
|
-
functionName: "mintFee"
|
|
5857
|
-
});
|
|
5861
|
+
const contractMintFee = await getContractMintFee();
|
|
5858
5862
|
if (salesConfig.type === "fixedPrice") {
|
|
5859
5863
|
return {
|
|
5860
5864
|
saleType: "fixedPrice",
|
|
@@ -5880,14 +5884,13 @@ function makeOnchainPrepareMintFromCreate({
|
|
|
5880
5884
|
tokenId,
|
|
5881
5885
|
result,
|
|
5882
5886
|
minter,
|
|
5883
|
-
|
|
5887
|
+
getContractMintFee,
|
|
5884
5888
|
contractVersion
|
|
5885
5889
|
}) {
|
|
5886
5890
|
return async (params) => {
|
|
5887
5891
|
const subgraphSalesConfig = await toSalesStrategyFromSubgraph({
|
|
5888
5892
|
minter,
|
|
5889
|
-
|
|
5890
|
-
publicClient,
|
|
5893
|
+
getContractMintFee,
|
|
5891
5894
|
salesConfig: result
|
|
5892
5895
|
});
|
|
5893
5896
|
return {
|
|
@@ -5916,7 +5919,7 @@ var getTokenIdFromCreateReceipt = (receipt) => {
|
|
|
5916
5919
|
for (const data of receipt.logs) {
|
|
5917
5920
|
try {
|
|
5918
5921
|
const decodedLog = decodeEventLog2({
|
|
5919
|
-
abi:
|
|
5922
|
+
abi: zoraCreator1155ImplABI6,
|
|
5920
5923
|
eventName: "SetupNewToken",
|
|
5921
5924
|
...data
|
|
5922
5925
|
});
|
|
@@ -5982,7 +5985,7 @@ function makeCreateTokenCall({
|
|
|
5982
5985
|
tokenSetupActions
|
|
5983
5986
|
}) {
|
|
5984
5987
|
return makeContractParameters({
|
|
5985
|
-
abi:
|
|
5988
|
+
abi: zoraCreator1155ImplABI6,
|
|
5986
5989
|
functionName: "multicall",
|
|
5987
5990
|
account,
|
|
5988
5991
|
address: contractAddress,
|
|
@@ -5992,10 +5995,12 @@ function makeCreateTokenCall({
|
|
|
5992
5995
|
var Create1155Client = class {
|
|
5993
5996
|
constructor({
|
|
5994
5997
|
chainId,
|
|
5995
|
-
publicClient
|
|
5998
|
+
publicClient,
|
|
5999
|
+
contractGetter
|
|
5996
6000
|
}) {
|
|
5997
6001
|
this.chainId = chainId;
|
|
5998
6002
|
this.publicClient = publicClient;
|
|
6003
|
+
this.contractGetter = contractGetter;
|
|
5999
6004
|
}
|
|
6000
6005
|
async createNew1155(props) {
|
|
6001
6006
|
return createNew1155ContractAndToken({
|
|
@@ -6016,7 +6021,8 @@ var Create1155Client = class {
|
|
|
6016
6021
|
token,
|
|
6017
6022
|
getAdditionalSetupActions,
|
|
6018
6023
|
publicClient: this.publicClient,
|
|
6019
|
-
chainId: this.chainId
|
|
6024
|
+
chainId: this.chainId,
|
|
6025
|
+
contractGetter: this.contractGetter
|
|
6020
6026
|
});
|
|
6021
6027
|
}
|
|
6022
6028
|
};
|
|
@@ -6061,9 +6067,13 @@ async function createNew1155ContractAndToken({
|
|
|
6061
6067
|
contractAddress,
|
|
6062
6068
|
contractVersion,
|
|
6063
6069
|
minter,
|
|
6064
|
-
publicClient,
|
|
6065
6070
|
result: newToken.salesConfig,
|
|
6066
|
-
tokenId: nextTokenId
|
|
6071
|
+
tokenId: nextTokenId,
|
|
6072
|
+
// to get the contract wide mint fee, we get what it would be for a new contract
|
|
6073
|
+
getContractMintFee: async () => getNewContractMintFee({
|
|
6074
|
+
publicClient,
|
|
6075
|
+
chainId
|
|
6076
|
+
})
|
|
6067
6077
|
});
|
|
6068
6078
|
return {
|
|
6069
6079
|
parameters: request,
|
|
@@ -6081,13 +6091,10 @@ async function createNew1155Token({
|
|
|
6081
6091
|
account,
|
|
6082
6092
|
getAdditionalSetupActions,
|
|
6083
6093
|
token,
|
|
6084
|
-
|
|
6085
|
-
|
|
6094
|
+
chainId,
|
|
6095
|
+
contractGetter
|
|
6086
6096
|
}) {
|
|
6087
|
-
const { nextTokenId, contractVersion } = await
|
|
6088
|
-
publicClient,
|
|
6089
|
-
contractAddress
|
|
6090
|
-
});
|
|
6097
|
+
const { nextTokenId, contractVersion, mintFee } = await contractGetter.getContractInfo({ contractAddress, retries: 5 });
|
|
6091
6098
|
const {
|
|
6092
6099
|
minter,
|
|
6093
6100
|
newToken,
|
|
@@ -6109,9 +6116,9 @@ async function createNew1155Token({
|
|
|
6109
6116
|
contractAddress,
|
|
6110
6117
|
contractVersion,
|
|
6111
6118
|
minter,
|
|
6112
|
-
publicClient,
|
|
6113
6119
|
result: newToken.salesConfig,
|
|
6114
|
-
tokenId: nextTokenId
|
|
6120
|
+
tokenId: nextTokenId,
|
|
6121
|
+
getContractMintFee: async () => mintFee
|
|
6115
6122
|
});
|
|
6116
6123
|
return {
|
|
6117
6124
|
parameters: request,
|
|
@@ -6452,6 +6459,77 @@ function decodeCallFailedError(error) {
|
|
|
6452
6459
|
});
|
|
6453
6460
|
}
|
|
6454
6461
|
|
|
6462
|
+
// src/create/subgraph-queries.ts
|
|
6463
|
+
function buildContractInfoQuery({
|
|
6464
|
+
contractAddress
|
|
6465
|
+
}) {
|
|
6466
|
+
return {
|
|
6467
|
+
query: `
|
|
6468
|
+
query ($contractAddress: Bytes!) {
|
|
6469
|
+
zoraCreateContract(id: $contractAddress) {
|
|
6470
|
+
contractVersion
|
|
6471
|
+
name
|
|
6472
|
+
mintFeePerQuantity
|
|
6473
|
+
tokens(first: 1, orderBy: tokenId, orderDirection: desc) {
|
|
6474
|
+
tokenId
|
|
6475
|
+
}
|
|
6476
|
+
}
|
|
6477
|
+
}
|
|
6478
|
+
`,
|
|
6479
|
+
variables: {
|
|
6480
|
+
contractAddress: contractAddress.toLowerCase()
|
|
6481
|
+
},
|
|
6482
|
+
parseResponseData: (responseData) => responseData.zoraCreateContract
|
|
6483
|
+
};
|
|
6484
|
+
}
|
|
6485
|
+
|
|
6486
|
+
// src/create/contract-getter.ts
|
|
6487
|
+
var SubgraphContractGetter = class {
|
|
6488
|
+
constructor(chainId, subgraphQuerier) {
|
|
6489
|
+
this.subgraphQuerier = subgraphQuerier || new SubgraphQuerier(httpClient);
|
|
6490
|
+
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
6491
|
+
}
|
|
6492
|
+
async querySubgraphWithRetries({
|
|
6493
|
+
query,
|
|
6494
|
+
variables,
|
|
6495
|
+
parseResponseData
|
|
6496
|
+
}) {
|
|
6497
|
+
const responseData = await this.subgraphQuerier.query({
|
|
6498
|
+
subgraphUrl: this.networkConfig.subgraphUrl,
|
|
6499
|
+
query,
|
|
6500
|
+
variables
|
|
6501
|
+
});
|
|
6502
|
+
return parseResponseData(responseData);
|
|
6503
|
+
}
|
|
6504
|
+
async getContractInfo({
|
|
6505
|
+
contractAddress,
|
|
6506
|
+
retries: retries2 = 1
|
|
6507
|
+
}) {
|
|
6508
|
+
const tryFn = async () => {
|
|
6509
|
+
const responseData2 = await this.querySubgraphWithRetries(
|
|
6510
|
+
buildContractInfoQuery({ contractAddress })
|
|
6511
|
+
);
|
|
6512
|
+
if (!responseData2) {
|
|
6513
|
+
console.log("could not find contract");
|
|
6514
|
+
throw new Error("Cannot find contract");
|
|
6515
|
+
}
|
|
6516
|
+
return responseData2;
|
|
6517
|
+
};
|
|
6518
|
+
const responseData = await retriesGeneric({
|
|
6519
|
+
tryFn,
|
|
6520
|
+
maxTries: retries2,
|
|
6521
|
+
linearBackoffMS: 1e3
|
|
6522
|
+
});
|
|
6523
|
+
const nextTokenId = responseData.tokens.length === 0 ? 1n : BigInt(responseData.tokens[0].tokenId) + 1n;
|
|
6524
|
+
return {
|
|
6525
|
+
name: responseData.name,
|
|
6526
|
+
contractVersion: responseData.contractVersion,
|
|
6527
|
+
mintFee: BigInt(responseData.mintFeePerQuantity),
|
|
6528
|
+
nextTokenId
|
|
6529
|
+
};
|
|
6530
|
+
}
|
|
6531
|
+
};
|
|
6532
|
+
|
|
6455
6533
|
// src/sdk.ts
|
|
6456
6534
|
function createCreatorClient(clientConfig) {
|
|
6457
6535
|
const premintClient = new PremintClient({
|
|
@@ -6461,7 +6539,8 @@ function createCreatorClient(clientConfig) {
|
|
|
6461
6539
|
});
|
|
6462
6540
|
const create1155CreatorClient = new Create1155Client({
|
|
6463
6541
|
chainId: clientConfig.chainId,
|
|
6464
|
-
publicClient: clientConfig.publicClient
|
|
6542
|
+
publicClient: clientConfig.publicClient,
|
|
6543
|
+
contractGetter: clientConfig.contractGetter || new SubgraphContractGetter(clientConfig.chainId)
|
|
6465
6544
|
});
|
|
6466
6545
|
return {
|
|
6467
6546
|
createPremint: (p) => premintClient.createPremint(p),
|