@zoralabs/protocol-sdk 0.11.8 → 0.11.10

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.
Files changed (40) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +17 -0
  3. package/dist/create/mint-from-create.d.ts +2 -1
  4. package/dist/create/mint-from-create.d.ts.map +1 -1
  5. package/dist/index.cjs +202 -48
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.js +208 -50
  8. package/dist/index.js.map +1 -1
  9. package/dist/mint/mint-client.d.ts +3 -1
  10. package/dist/mint/mint-client.d.ts.map +1 -1
  11. package/dist/mint/mint-queries.d.ts +5 -3
  12. package/dist/mint/mint-queries.d.ts.map +1 -1
  13. package/dist/mint/mint-transactions.d.ts +4 -2
  14. package/dist/mint/mint-transactions.d.ts.map +1 -1
  15. package/dist/premint/premint-client.d.ts +27 -27
  16. package/dist/sdk.d.ts.map +1 -1
  17. package/dist/secondary/secondary-client.d.ts +2 -1
  18. package/dist/secondary/secondary-client.d.ts.map +1 -1
  19. package/dist/secondary/types.d.ts +1 -0
  20. package/dist/secondary/types.d.ts.map +1 -1
  21. package/dist/sparks/sparks-contracts.d.ts +1 -1
  22. package/dist/test-utils.d.ts +5 -1
  23. package/dist/test-utils.d.ts.map +1 -1
  24. package/package.json +4 -4
  25. package/src/comments/comments.test.ts +338 -0
  26. package/src/create/1155-create-helper.test.ts +6 -12
  27. package/src/create/1155-create-helper.ts +2 -0
  28. package/src/create/mint-from-create.ts +3 -0
  29. package/src/create/minter-defaults.ts +7 -7
  30. package/src/mint/mint-client.test.ts +67 -30
  31. package/src/mint/mint-client.ts +10 -1
  32. package/src/mint/mint-queries.ts +16 -5
  33. package/src/mint/mint-transactions.ts +80 -16
  34. package/src/sdk.ts +1 -0
  35. package/src/secondary/secondary-client.test.ts +248 -2
  36. package/src/secondary/secondary-client.ts +136 -6
  37. package/src/secondary/types.ts +2 -0
  38. package/src/sparks/sparks-contracts.ts +1 -1
  39. package/src/sparks/sparks-sponsored-sparks-spender.test.ts +1 -0
  40. package/src/test-utils.ts +19 -0
package/dist/index.js CHANGED
@@ -3717,7 +3717,9 @@ import {
3717
3717
  import {
3718
3718
  erc20MinterABI,
3719
3719
  zoraCreator1155ImplABI as zoraCreator1155ImplABI2,
3720
- zoraTimedSaleStrategyABI
3720
+ zoraTimedSaleStrategyABI,
3721
+ callerAndCommenterABI,
3722
+ callerAndCommenterAddress
3721
3723
  } from "@zoralabs/protocol-deployments";
3722
3724
 
3723
3725
  // src/mint/utils.ts
@@ -3735,7 +3737,8 @@ var contractSupportsNewMintFunction = (contractVersion) => {
3735
3737
  // src/mint/mint-transactions.ts
3736
3738
  function makeOnchainMintCall({
3737
3739
  token,
3738
- mintParams
3740
+ mintParams,
3741
+ chainId
3739
3742
  }) {
3740
3743
  if (token.mintType === "721") {
3741
3744
  return makePrepareMint721TokenParams({
@@ -3748,9 +3751,55 @@ function makeOnchainMintCall({
3748
3751
  salesConfigAndTokenInfo: token,
3749
3752
  tokenContract: token.contract.address,
3750
3753
  tokenId: token.tokenId,
3754
+ chainId,
3751
3755
  ...mintParams
3752
3756
  });
3753
3757
  }
3758
+ function makeZoraTimedSaleStrategyMintCall({
3759
+ minterAccount,
3760
+ salesConfigAndTokenInfo,
3761
+ mintQuantity,
3762
+ mintTo,
3763
+ tokenContract,
3764
+ tokenId,
3765
+ mintReferral,
3766
+ mintComment,
3767
+ chainId
3768
+ }) {
3769
+ if (mintComment && mintComment !== "") {
3770
+ return makeContractParameters({
3771
+ abi: callerAndCommenterABI,
3772
+ address: callerAndCommenterAddress[chainId],
3773
+ functionName: "timedSaleMintAndComment",
3774
+ account: minterAccount,
3775
+ value: salesConfigAndTokenInfo.salesConfig.mintFeePerQuantity * mintQuantity,
3776
+ args: [
3777
+ mintTo,
3778
+ mintQuantity,
3779
+ tokenContract,
3780
+ tokenId,
3781
+ mintReferral || zeroAddress3,
3782
+ mintComment
3783
+ ]
3784
+ });
3785
+ }
3786
+ return makeContractParameters({
3787
+ abi: zoraTimedSaleStrategyABI,
3788
+ functionName: "mint",
3789
+ account: minterAccount,
3790
+ address: salesConfigAndTokenInfo.salesConfig.address,
3791
+ value: salesConfigAndTokenInfo.salesConfig.mintFeePerQuantity * mintQuantity,
3792
+ /* args: mintTo, quantity, collection, tokenId, mintReferral, comment */
3793
+ args: [
3794
+ mintTo,
3795
+ mintQuantity,
3796
+ tokenContract,
3797
+ BigInt(tokenId),
3798
+ mintReferral || zeroAddress3,
3799
+ ""
3800
+ ]
3801
+ });
3802
+ }
3754
3803
  function makePrepareMint1155TokenParams({
3755
3804
  tokenContract,
3756
3805
  tokenId,
@@ -3760,7 +3809,8 @@ function makePrepareMint1155TokenParams({
3760
3809
  mintReferral,
3761
3810
  mintRecipient,
3762
3811
  quantityToMint,
3763
- allowListEntry
3812
+ allowListEntry,
3813
+ chainId
3764
3814
  }) {
3765
3815
  const mintQuantity = BigInt(quantityToMint || 1);
3766
3816
  const mintTo = mintRecipientOrAccount({ mintRecipient, minterAccount });
@@ -3779,21 +3829,16 @@ function makePrepareMint1155TokenParams({
3779
3829
  });
3780
3830
  }
3781
3831
  if (saleType === "timed") {
3782
- return makeContractParameters({
3783
- abi: zoraTimedSaleStrategyABI,
3784
- functionName: "mint",
3785
- account: minterAccount,
3786
- address: salesConfigAndTokenInfo.salesConfig.address,
3787
- value: salesConfigAndTokenInfo.salesConfig.mintFeePerQuantity * mintQuantity,
3788
- /* args: mintTo, quantity, collection, tokenId, mintReferral, comment */
3789
- args: [
3790
- mintTo,
3791
- mintQuantity,
3792
- tokenContract,
3793
- BigInt(tokenId),
3794
- mintReferral || zeroAddress3,
3795
- mintComment || ""
3796
- ]
3832
+ return makeZoraTimedSaleStrategyMintCall({
3833
+ minterAccount,
3834
+ salesConfigAndTokenInfo,
3835
+ mintQuantity,
3836
+ mintTo,
3837
+ tokenContract,
3838
+ tokenId,
3839
+ mintReferral,
3840
+ mintComment,
3841
+ chainId
3797
3842
  });
3798
3843
  }
3799
3844
  if (saleType === "erc20") {
@@ -3958,7 +4003,8 @@ async function getMint({
3958
4003
  params,
3959
4004
  mintGetter,
3960
4005
  premintGetter,
3961
- publicClient
4006
+ publicClient,
4007
+ chainId
3962
4008
  }) {
3963
4009
  const { tokenContract } = params;
3964
4010
  if (isOnChainMint(params)) {
@@ -3970,7 +4016,7 @@ async function getMint({
3970
4016
  preferredSaleType: params.preferredSaleType,
3971
4017
  blockTime
3972
4018
  });
3973
- return toMintableReturn(result);
4019
+ return toMintableReturn(result, chainId);
3974
4020
  }
3975
4021
  const premint = await premintGetter.get({
3976
4022
  collectionAddress: tokenContract,
@@ -4008,11 +4054,12 @@ async function getMintsOfContract({
4008
4054
  params,
4009
4055
  mintGetter,
4010
4056
  premintGetter,
4011
- publicClient
4057
+ publicClient,
4058
+ chainId
4012
4059
  }) {
4013
4060
  const onchainMints = (await mintGetter.getContractMintable({
4014
4061
  tokenAddress: params.tokenContract
4015
- })).map(toMintableReturn);
4062
+ })).map((result) => toMintableReturn(result, chainId));
4016
4063
  const offchainMints = await getPremintsOfContractMintable({
4017
4064
  mintGetter,
4018
4065
  premintGetter,
@@ -4129,14 +4176,15 @@ function parsePremint({
4129
4176
  }
4130
4177
  throw new Error("Invalid premint config version");
4131
4178
  }
4132
- var makeOnchainPrepareMint = (result) => (params) => {
4179
+ var makeOnchainPrepareMint = (result, chainId) => (params) => {
4133
4180
  if (!result.salesConfig) {
4134
4181
  throw new Error("No valid sales config found for token");
4135
4182
  }
4136
4183
  return {
4137
4184
  parameters: makeOnchainMintCall({
4138
4185
  token: result,
4139
- mintParams: params
4186
+ mintParams: params,
4187
+ chainId
4140
4188
  }),
4141
4189
  erc20Approval: getRequiredErc20Approvals(params, result.salesConfig),
4142
4190
  costs: parseMintCosts({
@@ -4146,7 +4194,7 @@ var makeOnchainPrepareMint = (result) => (params) => {
4146
4194
  })
4147
4195
  };
4148
4196
  };
4149
- function toMintableReturn(result) {
4197
+ function toMintableReturn(result, chainId) {
4150
4198
  const primaryMintActive = result.primaryMintActive;
4151
4199
  if (!primaryMintActive) {
4152
4200
  return {
@@ -4162,7 +4210,10 @@ function toMintableReturn(result) {
4162
4210
  primaryMintActive,
4163
4211
  primaryMintEnd: result.primaryMintEnd,
4164
4212
  secondaryMarketActive: result.secondaryMarketActive,
4165
- prepareMint: makeOnchainPrepareMint(result.salesConfigAndTokenInfo)
4213
+ prepareMint: makeOnchainPrepareMint(
4214
+ result.salesConfigAndTokenInfo,
4215
+ chainId
4216
+ )
4166
4217
  };
4167
4218
  }
4168
4219
  var makePremintPrepareMint = (mintable, mintFee, premint) => {
@@ -4225,11 +4276,13 @@ var MintClient = class {
4225
4276
  constructor({
4226
4277
  publicClient,
4227
4278
  premintGetter,
4228
- mintGetter
4279
+ mintGetter,
4280
+ chainId
4229
4281
  }) {
4230
4282
  this.publicClient = publicClient;
4231
4283
  this.mintGetter = mintGetter;
4232
4284
  this.premintGetter = premintGetter;
4285
+ this.chainId = chainId;
4233
4286
  }
4234
4287
  /**
4235
4288
  * Returns the parameters needed to prepare a transaction mint a token.
@@ -4243,7 +4296,8 @@ var MintClient = class {
4243
4296
  parameters,
4244
4297
  publicClient: this.publicClient,
4245
4298
  mintGetter: this.mintGetter,
4246
- premintGetter: this.premintGetter
4299
+ premintGetter: this.premintGetter,
4300
+ chainId: this.chainId
4247
4301
  });
4248
4302
  }
4249
4303
  /**
@@ -4257,7 +4311,8 @@ var MintClient = class {
4257
4311
  params: parameters,
4258
4312
  mintGetter: this.mintGetter,
4259
4313
  premintGetter: this.premintGetter,
4260
- publicClient: this.publicClient
4314
+ publicClient: this.publicClient,
4315
+ chainId: this.chainId
4261
4316
  });
4262
4317
  }
4263
4318
  /**
@@ -4271,7 +4326,8 @@ var MintClient = class {
4271
4326
  params,
4272
4327
  mintGetter: this.mintGetter,
4273
4328
  premintGetter: this.premintGetter,
4274
- publicClient: this.publicClient
4329
+ publicClient: this.publicClient,
4330
+ chainId: this.chainId
4275
4331
  });
4276
4332
  }
4277
4333
  /**
@@ -4292,13 +4348,15 @@ async function mint({
4292
4348
  parameters,
4293
4349
  publicClient,
4294
4350
  mintGetter,
4295
- premintGetter
4351
+ premintGetter,
4352
+ chainId
4296
4353
  }) {
4297
4354
  const { prepareMint, primaryMintActive } = await getMint({
4298
4355
  params: parameters,
4299
4356
  mintGetter,
4300
4357
  premintGetter,
4301
- publicClient
4358
+ publicClient,
4359
+ chainId
4302
4360
  });
4303
4361
  if (!primaryMintActive) {
4304
4362
  throw new Error("Primary mint is not active");
@@ -4378,28 +4436,28 @@ import { parseEther as parseEther3 } from "viem";
4378
4436
  var DEFAULT_MINIMUM_MARKET_ETH = parseEther3("0.0123321");
4379
4437
  var DEFAULT_MARKET_COUNTDOWN = BigInt(24 * 60 * 60);
4380
4438
  var SALE_END_FOREVER = 18446744073709551615n;
4381
- var DEFAULT_SALE_START_AND_END = {
4382
- // Sale start time – defaults to beginning of unix time
4383
- saleStart: 0n,
4439
+ var DEFAULT_SALE_START_AND_END = () => ({
4440
+ // Sale start time – defaults to current time in seconds
4441
+ saleStart: BigInt(Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3)),
4384
4442
  // This is the end of uint64, plenty of time
4385
4443
  saleEnd: SALE_END_FOREVER
4386
- };
4444
+ });
4387
4445
  var DEFAULT_MAX_TOKENS_PER_ADDRESS = {
4388
4446
  maxTokensPerAddress: 0n
4389
4447
  };
4390
4448
  var erc20SaleSettingsWithDefaults = (params) => ({
4391
- ...DEFAULT_SALE_START_AND_END,
4449
+ ...DEFAULT_SALE_START_AND_END(),
4392
4450
  ...DEFAULT_MAX_TOKENS_PER_ADDRESS,
4393
4451
  ...params
4394
4452
  });
4395
4453
  var allowListWithDefaults = (allowlist) => {
4396
4454
  return {
4397
- ...DEFAULT_SALE_START_AND_END,
4455
+ ...DEFAULT_SALE_START_AND_END(),
4398
4456
  ...allowlist
4399
4457
  };
4400
4458
  };
4401
4459
  var fixedPriceSettingsWithDefaults = (params) => ({
4402
- ...DEFAULT_SALE_START_AND_END,
4460
+ ...DEFAULT_SALE_START_AND_END(),
4403
4461
  ...DEFAULT_MAX_TOKENS_PER_ADDRESS,
4404
4462
  type: "fixedPrice",
4405
4463
  ...params
@@ -4860,7 +4918,8 @@ function makeOnchainPrepareMintFromCreate({
4860
4918
  result,
4861
4919
  minter,
4862
4920
  getContractMintFee,
4863
- contractVersion
4921
+ contractVersion,
4922
+ chainId
4864
4923
  }) {
4865
4924
  return async (params) => {
4866
4925
  const subgraphSalesConfig = await toSalesStrategyFromSubgraph({
@@ -4876,7 +4935,8 @@ function makeOnchainPrepareMintFromCreate({
4876
4935
  },
4877
4936
  ...params,
4878
4937
  tokenContract: contractAddress,
4879
- tokenId
4938
+ tokenId,
4939
+ chainId
4880
4940
  }),
4881
4941
  costs: parseMintCosts({
4882
4942
  allowListEntry: params.allowListEntry,
@@ -5049,7 +5109,8 @@ async function createNew1155ContractAndToken({
5049
5109
  getContractMintFee: async () => getNewContractMintFee({
5050
5110
  publicClient,
5051
5111
  chainId
5052
- })
5112
+ }),
5113
+ chainId
5053
5114
  });
5054
5115
  return {
5055
5116
  parameters: request,
@@ -5095,7 +5156,8 @@ async function createNew1155Token({
5095
5156
  minter,
5096
5157
  result: newToken.salesConfig,
5097
5158
  tokenId: nextTokenId,
5098
- getContractMintFee: async () => mintFee
5159
+ getContractMintFee: async () => mintFee,
5160
+ chainId
5099
5161
  });
5100
5162
  return {
5101
5163
  parameters: request,
@@ -5760,7 +5822,9 @@ import {
5760
5822
  secondarySwapAddress,
5761
5823
  zoraCreator1155ImplABI as zoraCreator1155ImplABI7,
5762
5824
  safeTransferSwapAbiParameters,
5763
- secondarySwapABI
5825
+ secondarySwapABI,
5826
+ callerAndCommenterABI as callerAndCommenterABI2,
5827
+ callerAndCommenterAddress as callerAndCommenterAddress2
5764
5828
  } from "@zoralabs/protocol-deployments";
5765
5829
 
5766
5830
  // src/secondary/uniswap/uniswapQuote.ts
@@ -6048,10 +6112,13 @@ var ERROR_INSUFFICIENT_WALLET_FUNDS = "Insufficient wallet funds";
6048
6112
  var ERROR_INSUFFICIENT_POOL_SUPPLY = "Insufficient pool supply";
6049
6113
  var ERROR_SECONDARY_NOT_CONFIGURED = "Secondary not configured for given contract and token";
6050
6114
  var ERROR_SECONDARY_NOT_STARTED = "Secondary market has not started";
6115
+ var ERROR_RECIPIENT_MISMATCH = "Recipient must be the same as the caller if there is a comment";
6051
6116
  function makeError(errorMessage) {
6052
6117
  return { error: errorMessage };
6053
6118
  }
6054
6119
  async function makeBuy({
6120
+ contract,
6121
+ tokenId,
6055
6122
  erc20z,
6056
6123
  poolBalance,
6057
6124
  amount,
@@ -6060,20 +6127,106 @@ async function makeBuy({
6060
6127
  recipient,
6061
6128
  chainId,
6062
6129
  slippage,
6063
- publicClient
6130
+ publicClient,
6131
+ comment
6064
6132
  }) {
6065
6133
  const costWithSlippage = calculateSlippageUp(amount, slippage);
6066
- const availableToBuy = poolBalance.erc20z / BigInt(1e18) - 1n;
6067
6134
  const accountAddress = addressOrAccountAddress(account);
6135
+ const validationResult = await validateBuyConditions({
6136
+ poolBalance,
6137
+ quantity,
6138
+ costWithSlippage,
6139
+ accountAddress,
6140
+ publicClient
6141
+ });
6142
+ if (validationResult.error) {
6143
+ return makeError(validationResult.error);
6144
+ }
6145
+ if (comment && comment !== "") {
6146
+ return handleBuyWithComment({
6147
+ accountAddress,
6148
+ recipient,
6149
+ chainId,
6150
+ quantity,
6151
+ contract,
6152
+ tokenId,
6153
+ costWithSlippage,
6154
+ comment,
6155
+ account
6156
+ });
6157
+ }
6158
+ return handleBuyWithoutComment({
6159
+ erc20z,
6160
+ quantity,
6161
+ recipient,
6162
+ accountAddress,
6163
+ costWithSlippage,
6164
+ chainId,
6165
+ account
6166
+ });
6167
+ }
6168
+ async function validateBuyConditions({
6169
+ poolBalance,
6170
+ quantity,
6171
+ costWithSlippage,
6172
+ accountAddress,
6173
+ publicClient
6174
+ }) {
6175
+ const availableToBuy = poolBalance.erc20z / BigInt(1e18) - 1n;
6068
6176
  const availableToSpend = await publicClient.getBalance({
6069
6177
  address: accountAddress
6070
6178
  });
6071
6179
  if (costWithSlippage > availableToSpend) {
6072
- return makeError(ERROR_INSUFFICIENT_WALLET_FUNDS);
6180
+ return { error: ERROR_INSUFFICIENT_WALLET_FUNDS };
6073
6181
  }
6074
6182
  if (availableToBuy < BigInt(quantity)) {
6075
- return makeError(ERROR_INSUFFICIENT_POOL_SUPPLY);
6183
+ return { error: ERROR_INSUFFICIENT_POOL_SUPPLY };
6184
+ }
6185
+ return {};
6186
+ }
6187
+ function handleBuyWithComment({
6188
+ accountAddress,
6189
+ recipient,
6190
+ chainId,
6191
+ quantity,
6192
+ contract,
6193
+ tokenId,
6194
+ costWithSlippage,
6195
+ comment,
6196
+ account
6197
+ }) {
6198
+ if (recipient && recipient !== accountAddress) {
6199
+ return makeError(ERROR_RECIPIENT_MISMATCH);
6076
6200
  }
6201
+ return {
6202
+ parameters: makeContractParameters({
6203
+ abi: callerAndCommenterABI2,
6204
+ address: callerAndCommenterAddress2[chainId],
6205
+ functionName: "buyOnSecondaryAndComment",
6206
+ args: [
6207
+ accountAddress,
6208
+ quantity,
6209
+ contract,
6210
+ tokenId,
6211
+ accountAddress,
6212
+ costWithSlippage,
6213
+ 0n,
6214
+ comment
6215
+ ],
6216
+ account,
6217
+ value: costWithSlippage
6218
+ })
6219
+ };
6220
+ }
6221
+ function handleBuyWithoutComment({
6222
+ erc20z,
6223
+ quantity,
6224
+ recipient,
6225
+ accountAddress,
6226
+ costWithSlippage,
6227
+ chainId,
6228
+ account
6229
+ }) {
6077
6230
  return {
6078
6231
  parameters: makeContractParameters({
6079
6232
  abi: secondarySwapABI,
@@ -6100,7 +6253,8 @@ async function buyWithSlippage({
6100
6253
  chainId,
6101
6254
  account,
6102
6255
  slippage = UNISWAP_SLIPPAGE,
6103
- recipient
6256
+ recipient,
6257
+ comment
6104
6258
  }) {
6105
6259
  const secondaryInfo = await getSecondaryInfo({
6106
6260
  contract,
@@ -6127,6 +6281,8 @@ async function buyWithSlippage({
6127
6281
  );
6128
6282
  const call = await makeBuy({
6129
6283
  erc20z,
6284
+ contract,
6285
+ tokenId,
6130
6286
  poolBalance,
6131
6287
  amount,
6132
6288
  quantity,
@@ -6134,6 +6290,7 @@ async function buyWithSlippage({
6134
6290
  recipient,
6135
6291
  chainId,
6136
6292
  slippage,
6293
+ comment,
6137
6294
  publicClient
6138
6295
  });
6139
6296
  return {
@@ -6323,7 +6480,8 @@ function createCollectorClient(params) {
6323
6480
  const mintClient = new MintClient({
6324
6481
  publicClient: params.publicClient,
6325
6482
  premintGetter: premintGetterToUse,
6326
- mintGetter: mintGetterToUse
6483
+ mintGetter: mintGetterToUse,
6484
+ chainId: params.chainId
6327
6485
  });
6328
6486
  const secondaryClient = new SecondaryClient({
6329
6487
  publicClient: params.publicClient,