@zoralabs/protocol-sdk 0.11.6 → 0.11.7-COMMENTS.0

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 (36) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +12 -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 +195 -41
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.js +201 -43
  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/sdk.d.ts.map +1 -1
  16. package/dist/secondary/secondary-client.d.ts +2 -1
  17. package/dist/secondary/secondary-client.d.ts.map +1 -1
  18. package/dist/secondary/types.d.ts +1 -0
  19. package/dist/secondary/types.d.ts.map +1 -1
  20. package/dist/test-utils.d.ts +5 -1
  21. package/dist/test-utils.d.ts.map +1 -1
  22. package/package.json +4 -4
  23. package/src/comments/comments.test.ts +338 -0
  24. package/src/create/1155-create-helper.test.ts +2 -12
  25. package/src/create/1155-create-helper.ts +2 -0
  26. package/src/create/mint-from-create.ts +3 -0
  27. package/src/mint/mint-client.test.ts +67 -30
  28. package/src/mint/mint-client.ts +10 -1
  29. package/src/mint/mint-queries.ts +16 -5
  30. package/src/mint/mint-transactions.ts +80 -16
  31. package/src/sdk.ts +1 -0
  32. package/src/secondary/secondary-client.test.ts +248 -2
  33. package/src/secondary/secondary-client.ts +136 -6
  34. package/src/secondary/types.ts +2 -0
  35. package/src/sparks/sparks-sponsored-sparks-spender.test.ts +2 -1
  36. 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");
@@ -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,
@@ -5747,7 +5809,9 @@ import {
5747
5809
  secondarySwapAddress,
5748
5810
  zoraCreator1155ImplABI as zoraCreator1155ImplABI7,
5749
5811
  safeTransferSwapAbiParameters,
5750
- secondarySwapABI
5812
+ secondarySwapABI,
5813
+ callerAndCommenterABI as callerAndCommenterABI2,
5814
+ callerAndCommenterAddress as callerAndCommenterAddress2
5751
5815
  } from "@zoralabs/protocol-deployments";
5752
5816
 
5753
5817
  // src/secondary/uniswap/uniswapQuote.ts
@@ -6035,10 +6099,13 @@ var ERROR_INSUFFICIENT_WALLET_FUNDS = "Insufficient wallet funds";
6035
6099
  var ERROR_INSUFFICIENT_POOL_SUPPLY = "Insufficient pool supply";
6036
6100
  var ERROR_SECONDARY_NOT_CONFIGURED = "Secondary not configured for given contract and token";
6037
6101
  var ERROR_SECONDARY_NOT_STARTED = "Secondary market has not started";
6102
+ var ERROR_RECIPIENT_MISMATCH = "Recipient must be the same as the caller if there is a comment";
6038
6103
  function makeError(errorMessage) {
6039
6104
  return { error: errorMessage };
6040
6105
  }
6041
6106
  async function makeBuy({
6107
+ contract,
6108
+ tokenId,
6042
6109
  erc20z,
6043
6110
  poolBalance,
6044
6111
  amount,
@@ -6047,20 +6114,106 @@ async function makeBuy({
6047
6114
  recipient,
6048
6115
  chainId,
6049
6116
  slippage,
6050
- publicClient
6117
+ publicClient,
6118
+ comment
6051
6119
  }) {
6052
6120
  const costWithSlippage = calculateSlippageUp(amount, slippage);
6053
- const availableToBuy = poolBalance.erc20z / BigInt(1e18) - 1n;
6054
6121
  const accountAddress = addressOrAccountAddress(account);
6122
+ const validationResult = await validateBuyConditions({
6123
+ poolBalance,
6124
+ quantity,
6125
+ costWithSlippage,
6126
+ accountAddress,
6127
+ publicClient
6128
+ });
6129
+ if (validationResult.error) {
6130
+ return makeError(validationResult.error);
6131
+ }
6132
+ if (comment && comment !== "") {
6133
+ return handleBuyWithComment({
6134
+ accountAddress,
6135
+ recipient,
6136
+ chainId,
6137
+ quantity,
6138
+ contract,
6139
+ tokenId,
6140
+ costWithSlippage,
6141
+ comment,
6142
+ account
6143
+ });
6144
+ }
6145
+ return handleBuyWithoutComment({
6146
+ erc20z,
6147
+ quantity,
6148
+ recipient,
6149
+ accountAddress,
6150
+ costWithSlippage,
6151
+ chainId,
6152
+ account
6153
+ });
6154
+ }
6155
+ async function validateBuyConditions({
6156
+ poolBalance,
6157
+ quantity,
6158
+ costWithSlippage,
6159
+ accountAddress,
6160
+ publicClient
6161
+ }) {
6162
+ const availableToBuy = poolBalance.erc20z / BigInt(1e18) - 1n;
6055
6163
  const availableToSpend = await publicClient.getBalance({
6056
6164
  address: accountAddress
6057
6165
  });
6058
6166
  if (costWithSlippage > availableToSpend) {
6059
- return makeError(ERROR_INSUFFICIENT_WALLET_FUNDS);
6167
+ return { error: ERROR_INSUFFICIENT_WALLET_FUNDS };
6060
6168
  }
6061
6169
  if (availableToBuy < BigInt(quantity)) {
6062
- return makeError(ERROR_INSUFFICIENT_POOL_SUPPLY);
6170
+ return { error: ERROR_INSUFFICIENT_POOL_SUPPLY };
6171
+ }
6172
+ return {};
6173
+ }
6174
+ function handleBuyWithComment({
6175
+ accountAddress,
6176
+ recipient,
6177
+ chainId,
6178
+ quantity,
6179
+ contract,
6180
+ tokenId,
6181
+ costWithSlippage,
6182
+ comment,
6183
+ account
6184
+ }) {
6185
+ if (recipient && recipient !== accountAddress) {
6186
+ return makeError(ERROR_RECIPIENT_MISMATCH);
6063
6187
  }
6188
+ return {
6189
+ parameters: makeContractParameters({
6190
+ abi: callerAndCommenterABI2,
6191
+ address: callerAndCommenterAddress2[chainId],
6192
+ functionName: "buyOnSecondaryAndComment",
6193
+ args: [
6194
+ accountAddress,
6195
+ quantity,
6196
+ contract,
6197
+ tokenId,
6198
+ accountAddress,
6199
+ costWithSlippage,
6200
+ 0n,
6201
+ comment
6202
+ ],
6203
+ account,
6204
+ value: costWithSlippage
6205
+ })
6206
+ };
6207
+ }
6208
+ function handleBuyWithoutComment({
6209
+ erc20z,
6210
+ quantity,
6211
+ recipient,
6212
+ accountAddress,
6213
+ costWithSlippage,
6214
+ chainId,
6215
+ account
6216
+ }) {
6064
6217
  return {
6065
6218
  parameters: makeContractParameters({
6066
6219
  abi: secondarySwapABI,
@@ -6087,7 +6240,8 @@ async function buyWithSlippage({
6087
6240
  chainId,
6088
6241
  account,
6089
6242
  slippage = UNISWAP_SLIPPAGE,
6090
- recipient
6243
+ recipient,
6244
+ comment
6091
6245
  }) {
6092
6246
  const secondaryInfo = await getSecondaryInfo({
6093
6247
  contract,
@@ -6114,6 +6268,8 @@ async function buyWithSlippage({
6114
6268
  );
6115
6269
  const call = await makeBuy({
6116
6270
  erc20z,
6271
+ contract,
6272
+ tokenId,
6117
6273
  poolBalance,
6118
6274
  amount,
6119
6275
  quantity,
@@ -6121,6 +6277,7 @@ async function buyWithSlippage({
6121
6277
  recipient,
6122
6278
  chainId,
6123
6279
  slippage,
6280
+ comment,
6124
6281
  publicClient
6125
6282
  });
6126
6283
  return {
@@ -6310,7 +6467,8 @@ function createCollectorClient(params) {
6310
6467
  const mintClient = new MintClient({
6311
6468
  publicClient: params.publicClient,
6312
6469
  premintGetter: premintGetterToUse,
6313
- mintGetter: mintGetterToUse
6470
+ mintGetter: mintGetterToUse,
6471
+ chainId: params.chainId
6314
6472
  });
6315
6473
  const secondaryClient = new SecondaryClient({
6316
6474
  publicClient: params.publicClient,