@zoralabs/protocol-sdk 0.11.0 → 0.11.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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @zoralabs/protocol-sdk@0.11.0 build /home/runner/work/zora-protocol-private/zora-protocol-private/packages/protocol-sdk
2
+ > @zoralabs/protocol-sdk@0.11.2 build /home/runner/work/zora-protocol-private/zora-protocol-private/packages/protocol-sdk
3
3
  > pnpm tsup
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -10,9 +10,9 @@ CLI Target: es2021
10
10
  CLI Cleaning output folder
11
11
  CJS Build start
12
12
  ESM Build start
13
- ESM dist/index.js 216.01 KB
14
- ESM dist/index.js.map 448.17 KB
15
- ESM ⚡️ Build success in 355ms
16
- CJS dist/index.cjs 222.28 KB
17
- CJS dist/index.cjs.map 449.68 KB
18
- CJS ⚡️ Build success in 355ms
13
+ CJS dist/index.cjs 224.10 KB
14
+ CJS dist/index.cjs.map 454.19 KB
15
+ CJS ⚡️ Build success in 322ms
16
+ ESM dist/index.js 217.84 KB
17
+ ESM dist/index.js.map 452.19 KB
18
+ ESM ⚡️ Build success in 338ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @zoralabs/protocol-sdk
2
2
 
3
+ ## 0.11.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 66f33bbb: fix: update secondary swap helper contract address
8
+ - 8d7fdc02: For the functions `getToken` and `getTokensOfContract`, the returned `MintableReturn` type has been updated to provide more information about the primary mint status:
9
+
10
+ - Added `primaryMintActive` boolean to indicate if the primary mint is currently active.
11
+ - Added `primaryMintEnd` optional `bigint` to show the end time of the primary mint, if applicable.
12
+ - Added `secondaryMarketActive` boolean to indicate if the secondary market is currently active.
13
+ - Modified `prepareMint` to be conditionally available:
14
+ - When `primaryMintActive` is `true`, `prepareMint` is available as a `PrepareMint` function.
15
+ - When `primaryMintActive` is `false`, `prepareMint` is set to `undefined`.
16
+
17
+ This allows for developers to know if the primary mint is active or not, and if not, if they should buy on secondary.
18
+
19
+ - Updated dependencies [66f33bbb]
20
+ - @zoralabs/protocol-deployments@0.3.4
21
+
22
+ ## 0.11.1
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies [b885539f]
27
+ - @zoralabs/protocol-deployments@0.3.3
28
+
3
29
  ## 0.11.0
4
30
 
5
31
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -2834,100 +2834,123 @@ var getApiNetworkConfigForChain = (chainId) => {
2834
2834
  }
2835
2835
  return networkConfigByChain[chainId];
2836
2836
  };
2837
- function parseSalesConfig(targetStrategy, contractMintFee) {
2838
- if (targetStrategy.type === "FIXED_PRICE")
2839
- return {
2837
+ function parseFixedPriceSalesConfig(fixedPrice, contractMintFee, blockTime) {
2838
+ const saleEnd = BigInt(fixedPrice.saleEnd);
2839
+ return {
2840
+ salesStrategy: {
2840
2841
  saleType: "fixedPrice",
2841
- ...targetStrategy.fixedPrice,
2842
- maxTokensPerAddress: BigInt(
2843
- targetStrategy.fixedPrice.maxTokensPerAddress
2844
- ),
2845
- pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken),
2842
+ ...fixedPrice,
2843
+ maxTokensPerAddress: BigInt(fixedPrice.maxTokensPerAddress),
2844
+ pricePerToken: BigInt(fixedPrice.pricePerToken),
2846
2845
  mintFeePerQuantity: contractMintFee
2847
- };
2848
- if (targetStrategy.type === "ERC_20_MINTER") {
2849
- return {
2846
+ },
2847
+ saleEnd,
2848
+ saleActive: BigInt(fixedPrice.saleStart) <= blockTime && BigInt(saleEnd) > blockTime
2849
+ };
2850
+ }
2851
+ function parseERC20SalesConfig(erc20Minter, blockTime) {
2852
+ const saleEnd = BigInt(erc20Minter.saleEnd);
2853
+ return {
2854
+ salesStrategy: {
2850
2855
  saleType: "erc20",
2851
- ...targetStrategy.erc20Minter,
2852
- maxTokensPerAddress: BigInt(
2853
- targetStrategy.erc20Minter.maxTokensPerAddress
2854
- ),
2855
- pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken),
2856
+ ...erc20Minter,
2857
+ maxTokensPerAddress: BigInt(erc20Minter.maxTokensPerAddress),
2858
+ pricePerToken: BigInt(erc20Minter.pricePerToken),
2856
2859
  mintFeePerQuantity: 0n
2857
- };
2858
- }
2859
- if (targetStrategy.type === "PRESALE") {
2860
- return {
2860
+ },
2861
+ saleEnd,
2862
+ saleActive: BigInt(erc20Minter.saleStart) <= blockTime && saleEnd > blockTime
2863
+ };
2864
+ }
2865
+ function parsePresaleSalesConfig(presale, contractMintFee, blockTime) {
2866
+ const saleEnd = BigInt(presale.presaleEnd);
2867
+ return {
2868
+ salesStrategy: {
2861
2869
  saleType: "allowlist",
2862
- address: targetStrategy.presale.address,
2863
- merkleRoot: targetStrategy.presale.merkleRoot,
2864
- saleStart: targetStrategy.presale.presaleStart,
2865
- saleEnd: targetStrategy.presale.presaleEnd,
2870
+ address: presale.address,
2871
+ merkleRoot: presale.merkleRoot,
2872
+ saleStart: presale.presaleStart,
2873
+ saleEnd: presale.presaleEnd,
2866
2874
  mintFeePerQuantity: contractMintFee
2867
- };
2868
- }
2869
- if (targetStrategy.type === "ZORA_TIMED") {
2870
- return {
2871
- saleType: "timed",
2872
- address: targetStrategy.zoraTimedMinter.address,
2873
- mintFee: BigInt(targetStrategy.zoraTimedMinter.mintFee),
2874
- saleStart: targetStrategy.zoraTimedMinter.saleStart,
2875
- saleEnd: targetStrategy.zoraTimedMinter.saleEnd,
2876
- erc20Z: targetStrategy.zoraTimedMinter.erc20Z.id,
2877
- pool: targetStrategy.zoraTimedMinter.erc20Z.pool,
2878
- secondaryActivated: targetStrategy.zoraTimedMinter.secondaryActivated,
2879
- mintFeePerQuantity: BigInt(targetStrategy.zoraTimedMinter.mintFee),
2880
- marketCountdown: targetStrategy.zoraTimedMinter.marketCountdown ? BigInt(targetStrategy.zoraTimedMinter.marketCountdown) : void 0,
2881
- minimumMarketEth: targetStrategy.zoraTimedMinter.minimumMarketEth ? BigInt(targetStrategy.zoraTimedMinter.minimumMarketEth) : void 0
2882
- };
2883
- }
2884
- throw new Error("Unknown saleType");
2875
+ },
2876
+ saleEnd,
2877
+ saleActive: BigInt(presale.presaleStart) <= blockTime && saleEnd > blockTime
2878
+ };
2885
2879
  }
2886
- function getSaleEnd(a) {
2887
- if (a.type === "FIXED_PRICE")
2888
- return BigInt(a.fixedPrice.saleEnd);
2889
- if (a.type === "ERC_20_MINTER")
2890
- return BigInt(a.erc20Minter.saleEnd);
2891
- if (a.type === "ZORA_TIMED")
2892
- return BigInt(a.zoraTimedMinter.saleEnd);
2893
- return BigInt(a.presale.presaleEnd);
2880
+ function parseZoraTimedSalesConfig(zoraTimedMinter, blockTime) {
2881
+ const saleEnd = BigInt(zoraTimedMinter.saleEnd);
2882
+ const hasSaleEnd = saleEnd > 0n;
2883
+ return {
2884
+ salesStrategy: {
2885
+ saleType: "timed",
2886
+ address: zoraTimedMinter.address,
2887
+ mintFee: BigInt(zoraTimedMinter.mintFee),
2888
+ saleStart: zoraTimedMinter.saleStart,
2889
+ saleEnd: zoraTimedMinter.saleEnd,
2890
+ erc20Z: zoraTimedMinter.erc20Z.id,
2891
+ pool: zoraTimedMinter.erc20Z.pool,
2892
+ secondaryActivated: zoraTimedMinter.secondaryActivated,
2893
+ mintFeePerQuantity: BigInt(zoraTimedMinter.mintFee),
2894
+ marketCountdown: zoraTimedMinter.marketCountdown ? BigInt(zoraTimedMinter.marketCountdown) : void 0,
2895
+ minimumMarketEth: zoraTimedMinter.minimumMarketEth ? BigInt(zoraTimedMinter.minimumMarketEth) : void 0
2896
+ },
2897
+ saleEnd: hasSaleEnd ? saleEnd : void 0,
2898
+ secondaryMarketActive: zoraTimedMinter.secondaryActivated,
2899
+ saleActive: BigInt(zoraTimedMinter.saleStart) <= blockTime && (hasSaleEnd ? saleEnd > blockTime : true)
2900
+ };
2894
2901
  }
2895
- function strategyIsStillValid(strategy, blockTime) {
2896
- if (strategy.type === "FIXED_PRICE") {
2897
- return BigInt(strategy.fixedPrice.saleEnd) > blockTime;
2898
- }
2899
- if (strategy.type === "ERC_20_MINTER") {
2900
- return BigInt(strategy.erc20Minter.saleEnd) > blockTime;
2901
- }
2902
- if (strategy.type === "ZORA_TIMED") {
2903
- return BigInt(strategy.zoraTimedMinter.saleEnd) === 0n || BigInt(strategy.zoraTimedMinter.saleEnd) > blockTime;
2902
+ function parseSalesConfig(targetStrategy, contractMintFee, blockTime) {
2903
+ switch (targetStrategy.type) {
2904
+ case "FIXED_PRICE":
2905
+ return parseFixedPriceSalesConfig(
2906
+ targetStrategy.fixedPrice,
2907
+ contractMintFee,
2908
+ blockTime
2909
+ );
2910
+ case "ERC_20_MINTER":
2911
+ return parseERC20SalesConfig(targetStrategy.erc20Minter, blockTime);
2912
+ case "PRESALE":
2913
+ return parsePresaleSalesConfig(
2914
+ targetStrategy.presale,
2915
+ contractMintFee,
2916
+ blockTime
2917
+ );
2918
+ case "ZORA_TIMED":
2919
+ return parseZoraTimedSalesConfig(
2920
+ targetStrategy.zoraTimedMinter,
2921
+ blockTime
2922
+ );
2923
+ default:
2924
+ throw new Error("Unknown saleType");
2904
2925
  }
2905
- return BigInt(strategy.presale.presaleEnd) > blockTime;
2906
2926
  }
2907
2927
  function getTargetStrategy({
2908
2928
  tokenId,
2909
2929
  preferredSaleType,
2910
2930
  token,
2911
- blockTime
2931
+ blockTime,
2932
+ contractMintFee
2912
2933
  }) {
2913
2934
  const allStrategies = (typeof tokenId !== "undefined" ? token.salesStrategies : token.contract.salesStrategies) || [];
2914
- const stillValidSalesStrategies = allStrategies.filter(
2915
- (strategy) => strategyIsStillValid(strategy, blockTime)
2935
+ const parsedStrategies = allStrategies.map(
2936
+ (strategy) => parseSalesConfig(strategy, contractMintFee, blockTime)
2937
+ );
2938
+ const stillValidSalesStrategies = parsedStrategies.filter(
2939
+ (strategy) => strategy.saleActive
2916
2940
  );
2917
2941
  const saleStrategies = stillValidSalesStrategies.sort(
2918
- (a, b) => getSaleEnd(a) > getSaleEnd(b) ? 1 : -1
2942
+ (a, b) => (a.saleEnd ?? 0n) > (b.saleEnd ?? 0n) ? 1 : -1
2919
2943
  );
2920
2944
  let targetStrategy;
2921
2945
  if (!preferredSaleType) {
2922
2946
  return saleStrategies[0];
2923
2947
  } else {
2924
- const mappedSaleType = preferredSaleType === "erc20" ? "ERC_20_MINTER" : "FIXED_PRICE";
2925
2948
  targetStrategy = saleStrategies.find(
2926
- (strategy) => strategy.type === mappedSaleType
2949
+ ({ salesStrategy }) => salesStrategy.saleType === preferredSaleType
2927
2950
  );
2928
2951
  if (!targetStrategy) {
2929
2952
  const targetStrategy2 = saleStrategies.find(
2930
- (strategy) => strategy.type === "FIXED_PRICE" || strategy.type === "ERC_20_MINTER"
2953
+ ({ salesStrategy }) => salesStrategy.saleType === "timed" || salesStrategy.saleType === "fixedPrice" || salesStrategy.saleType === "erc20"
2931
2954
  );
2932
2955
  if (!targetStrategy2)
2933
2956
  throw new Error("Cannot find valid sale strategy");
@@ -3004,7 +3027,7 @@ var SubgraphMintGetter = class extends SubgraphGetter {
3004
3027
  })) || [];
3005
3028
  }
3006
3029
  };
3007
- function getTargetStrategyAndMintFee({
3030
+ function getTargetStrategyAndMintFeeAndSaleActive({
3008
3031
  token,
3009
3032
  tokenId,
3010
3033
  preferredSaleType,
@@ -3015,12 +3038,10 @@ function getTargetStrategyAndMintFee({
3015
3038
  tokenId,
3016
3039
  preferredSaleType,
3017
3040
  token,
3018
- blockTime
3041
+ blockTime,
3042
+ contractMintFee: defaultMintFee
3019
3043
  });
3020
- if (!targetStrategy)
3021
- return void 0;
3022
- const salesConfig = parseSalesConfig(targetStrategy, defaultMintFee);
3023
- return salesConfig;
3044
+ return targetStrategy;
3024
3045
  }
3025
3046
  function parseTokenQueryResult({
3026
3047
  token,
@@ -3029,7 +3050,7 @@ function parseTokenQueryResult({
3029
3050
  defaultMintFee,
3030
3051
  blockTime
3031
3052
  }) {
3032
- const salesConfig = getTargetStrategyAndMintFee({
3053
+ const salesStrategyAndMintInfo = getTargetStrategyAndMintFeeAndSaleActive({
3033
3054
  token,
3034
3055
  tokenId,
3035
3056
  preferredSaleType,
@@ -3040,8 +3061,13 @@ function parseTokenQueryResult({
3040
3061
  token
3041
3062
  });
3042
3063
  return {
3043
- ...tokenInfo,
3044
- salesConfig
3064
+ salesConfigAndTokenInfo: {
3065
+ ...tokenInfo,
3066
+ salesConfig: salesStrategyAndMintInfo?.salesStrategy
3067
+ },
3068
+ primaryMintActive: salesStrategyAndMintInfo?.saleActive ?? false,
3069
+ primaryMintEnd: salesStrategyAndMintInfo?.saleEnd,
3070
+ secondaryMarketActive: salesStrategyAndMintInfo?.secondaryMarketActive ?? false
3045
3071
  };
3046
3072
  }
3047
3073
  function parseTokenInfo({
@@ -4050,7 +4076,7 @@ async function getMintCosts({
4050
4076
  if (isOnChainMint(params)) {
4051
4077
  const tokenId = is1155Mint(params) ? params.tokenId : void 0;
4052
4078
  const blockTime = (await publicClient.getBlock()).timestamp;
4053
- const salesConfigAndTokenInfo = await mintGetter.getMintable({
4079
+ const { salesConfigAndTokenInfo } = await mintGetter.getMintable({
4054
4080
  tokenId,
4055
4081
  tokenAddress: collection,
4056
4082
  blockTime
@@ -4109,6 +4135,10 @@ async function getPremintsOfContractMintable({
4109
4135
  });
4110
4136
  });
4111
4137
  }
4138
+ function isPrimaryMintActive(premint) {
4139
+ const currentTime = (/* @__PURE__ */ new Date()).getTime() / 1e3;
4140
+ return premint.premintConfig.tokenConfig.mintStart < currentTime;
4141
+ }
4112
4142
  function parsePremint({
4113
4143
  premint,
4114
4144
  mintFee
@@ -4155,27 +4185,58 @@ var makeOnchainPrepareMint = (result) => (params) => {
4155
4185
  };
4156
4186
  };
4157
4187
  function toMintableReturn(result) {
4158
- return { token: result, prepareMint: makeOnchainPrepareMint(result) };
4188
+ const primaryMintActive = result.primaryMintActive;
4189
+ if (!primaryMintActive) {
4190
+ return {
4191
+ token: result.salesConfigAndTokenInfo,
4192
+ primaryMintActive,
4193
+ primaryMintEnd: result.primaryMintEnd,
4194
+ secondaryMarketActive: result.secondaryMarketActive,
4195
+ prepareMint: void 0
4196
+ };
4197
+ }
4198
+ return {
4199
+ token: result.salesConfigAndTokenInfo,
4200
+ primaryMintActive,
4201
+ primaryMintEnd: result.primaryMintEnd,
4202
+ secondaryMarketActive: result.secondaryMarketActive,
4203
+ prepareMint: makeOnchainPrepareMint(result.salesConfigAndTokenInfo)
4204
+ };
4159
4205
  }
4160
- var makePremintPrepareMint = (mintable, mintFee, premint) => (params) => ({
4161
- parameters: buildPremintMintCall({
4162
- mintArguments: params,
4163
- mintFee,
4164
- premint
4165
- }),
4166
- costs: parseMintCosts({
4167
- quantityToMint: BigInt(params.quantityToMint),
4168
- salesConfig: mintable.salesConfig,
4169
- allowListEntry: params.allowListEntry
4170
- })
4171
- });
4206
+ var makePremintPrepareMint = (mintable, mintFee, premint) => {
4207
+ return (params) => {
4208
+ return {
4209
+ parameters: buildPremintMintCall({
4210
+ mintArguments: params,
4211
+ mintFee,
4212
+ premint
4213
+ }),
4214
+ costs: parseMintCosts({
4215
+ quantityToMint: BigInt(params.quantityToMint),
4216
+ salesConfig: mintable.salesConfig,
4217
+ allowListEntry: params.allowListEntry
4218
+ })
4219
+ };
4220
+ };
4221
+ };
4172
4222
  function toPremintMintReturn({
4173
4223
  premint,
4174
4224
  mintFee
4175
4225
  }) {
4176
4226
  const mintable = parsePremint({ premint, mintFee });
4227
+ const primaryMintActive = isPrimaryMintActive(premint.premint);
4228
+ if (!primaryMintActive) {
4229
+ return {
4230
+ token: mintable,
4231
+ primaryMintActive,
4232
+ prepareMint: void 0,
4233
+ secondaryMarketActive: false
4234
+ };
4235
+ }
4177
4236
  return {
4178
4237
  token: mintable,
4238
+ primaryMintActive,
4239
+ secondaryMarketActive: false,
4179
4240
  prepareMint: makePremintPrepareMint(mintable, mintFee, premint)
4180
4241
  };
4181
4242
  }
@@ -4271,12 +4332,15 @@ async function mint({
4271
4332
  mintGetter,
4272
4333
  premintGetter
4273
4334
  }) {
4274
- const { prepareMint } = await getMint({
4335
+ const { prepareMint, primaryMintActive } = await getMint({
4275
4336
  params: parameters,
4276
4337
  mintGetter,
4277
4338
  premintGetter,
4278
4339
  publicClient
4279
4340
  });
4341
+ if (!primaryMintActive) {
4342
+ throw new Error("Primary mint is not active");
4343
+ }
4280
4344
  return prepareMint({
4281
4345
  minterAccount: parameters.minterAccount,
4282
4346
  quantityToMint: parameters.quantityToMint,