@zoralabs/protocol-sdk 0.10.0 → 0.11.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 (55) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +11 -0
  3. package/dist/apis/multicall3.d.ts +1 -1
  4. package/dist/apis/multicall3.d.ts.map +1 -1
  5. package/dist/create/1155-create-helper.test.d.ts +3 -0
  6. package/dist/create/1155-create-helper.test.d.ts.map +1 -0
  7. package/dist/fixtures/contract-setup.d.ts +16 -0
  8. package/dist/fixtures/contract-setup.d.ts.map +1 -0
  9. package/dist/index.cjs +538 -28
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.js +556 -28
  12. package/dist/index.js.map +1 -1
  13. package/dist/sdk.d.ts +4 -0
  14. package/dist/sdk.d.ts.map +1 -1
  15. package/dist/secondary/conversions.d.ts +7 -0
  16. package/dist/secondary/conversions.d.ts.map +1 -0
  17. package/dist/secondary/secondary-client.d.ts +67 -0
  18. package/dist/secondary/secondary-client.d.ts.map +1 -0
  19. package/dist/secondary/slippage.d.ts +25 -0
  20. package/dist/secondary/slippage.d.ts.map +1 -0
  21. package/dist/secondary/types.d.ts +37 -0
  22. package/dist/secondary/types.d.ts.map +1 -0
  23. package/dist/secondary/uniswap/abis.d.ts +152 -0
  24. package/dist/secondary/uniswap/abis.d.ts.map +1 -0
  25. package/dist/secondary/uniswap/uniswapQuote.d.ts +13 -0
  26. package/dist/secondary/uniswap/uniswapQuote.d.ts.map +1 -0
  27. package/dist/secondary/uniswap/uniswapQuoteExact.d.ts +37 -0
  28. package/dist/secondary/uniswap/uniswapQuoteExact.d.ts.map +1 -0
  29. package/dist/secondary/uniswap/uniswapReserves.d.ts +3 -0
  30. package/dist/secondary/uniswap/uniswapReserves.d.ts.map +1 -0
  31. package/dist/secondary/utils.d.ts +10 -0
  32. package/dist/secondary/utils.d.ts.map +1 -0
  33. package/dist/sparks/sparks-contracts.d.ts.map +1 -1
  34. package/dist/types.d.ts +3 -2
  35. package/dist/types.d.ts.map +1 -1
  36. package/dist/utils.d.ts +2 -1
  37. package/dist/utils.d.ts.map +1 -1
  38. package/package.json +1 -1
  39. package/src/apis/multicall3.ts +1 -1
  40. package/src/fixtures/contract-setup.ts +57 -0
  41. package/src/rewards/rewards-client.test.ts +15 -111
  42. package/src/sdk.ts +11 -0
  43. package/src/secondary/conversions.ts +20 -0
  44. package/src/secondary/secondary-client.test.ts +276 -0
  45. package/src/secondary/secondary-client.ts +374 -0
  46. package/src/secondary/slippage.ts +42 -0
  47. package/src/secondary/types.ts +64 -0
  48. package/src/secondary/uniswap/abis.ts +20 -0
  49. package/src/secondary/uniswap/uniswapQuote.ts +134 -0
  50. package/src/secondary/uniswap/uniswapQuoteExact.ts +114 -0
  51. package/src/secondary/uniswap/uniswapReserves.ts +34 -0
  52. package/src/secondary/utils.ts +40 -0
  53. package/src/sparks/sparks-contracts.ts +1 -3
  54. package/src/types.ts +6 -7
  55. package/src/utils.ts +7 -1
package/dist/index.cjs CHANGED
@@ -397,12 +397,12 @@ var require_semver = __commonJS({
397
397
  this.prerelease = [];
398
398
  break;
399
399
  case "pre": {
400
- const base3 = Number(identifierBase) ? 1 : 0;
400
+ const base4 = Number(identifierBase) ? 1 : 0;
401
401
  if (!identifier && identifierBase === false) {
402
402
  throw new Error("invalid increment argument: identifier is empty");
403
403
  }
404
404
  if (this.prerelease.length === 0) {
405
- this.prerelease = [base3];
405
+ this.prerelease = [base4];
406
406
  } else {
407
407
  let i = this.prerelease.length;
408
408
  while (--i >= 0) {
@@ -415,11 +415,11 @@ var require_semver = __commonJS({
415
415
  if (identifier === this.prerelease.join(".") && identifierBase === false) {
416
416
  throw new Error("invalid increment argument: identifier already exists");
417
417
  }
418
- this.prerelease.push(base3);
418
+ this.prerelease.push(base4);
419
419
  }
420
420
  }
421
421
  if (identifier) {
422
- let prerelease = [identifier, base3];
422
+ let prerelease = [identifier, base4];
423
423
  if (identifierBase === false) {
424
424
  prerelease = [identifier];
425
425
  }
@@ -3071,6 +3071,7 @@ function mintRecipientOrAccount({
3071
3071
  }) {
3072
3072
  return mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
3073
3073
  }
3074
+ var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
3074
3075
 
3075
3076
  // src/premint/premint-client.ts
3076
3077
  var defaultTokenConfigV1MintArguments = () => ({
@@ -5141,7 +5142,6 @@ var sumBalances = (mintAccountBalances) => {
5141
5142
  // src/sparks/sparks-contracts.ts
5142
5143
  var import_protocol_deployments11 = require("@zoralabs/protocol-deployments");
5143
5144
  var import_viem11 = require("viem");
5144
- var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
5145
5145
  var mintWithEthParams = ({
5146
5146
  tokenId,
5147
5147
  quantity,
@@ -5668,6 +5668,509 @@ var SubgraphRewardsGetter = class extends SubgraphGetter {
5668
5668
  }
5669
5669
  };
5670
5670
 
5671
+ // src/secondary/secondary-client.ts
5672
+ var import_viem17 = require("viem");
5673
+ var import_protocol_deployments15 = require("@zoralabs/protocol-deployments");
5674
+
5675
+ // src/secondary/uniswap/uniswapQuote.ts
5676
+ var import_viem16 = require("viem");
5677
+
5678
+ // src/secondary/uniswap/uniswapReserves.ts
5679
+ var import_viem14 = require("viem");
5680
+ var import_chains2 = require("viem/chains");
5681
+
5682
+ // src/secondary/uniswap/abis.ts
5683
+ var import_viem13 = require("viem");
5684
+ var uniswapQuoterABI = (0, import_viem13.parseAbi)([
5685
+ "struct QuoteExactInputSingleParams { address tokenIn; address tokenOut; uint256 amountIn; uint24 fee; uint160 sqrtPriceLimitX96; }",
5686
+ "struct QuoteExactOutputSingleParams { address tokenIn; address tokenOut; uint256 amount; uint24 fee; uint160 sqrtPriceLimitX96; }",
5687
+ "function quoteExactInputSingle(QuoteExactInputSingleParams calldata params) external returns (uint256 amountOut, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate)",
5688
+ "function quoteExactOutputSingle(QuoteExactOutputSingleParams calldata params) external returns (uint256 amountIn, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate)"
5689
+ ]);
5690
+ var uniswapV3PoolAbi = (0, import_viem13.parseAbi)([
5691
+ "function fee() external view returns (uint24)",
5692
+ "function liquidity() external view returns (uint128)",
5693
+ "function slot0() external view returns (uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint8 feeProtocol, bool unlocked)",
5694
+ "function token0() external view returns (address)",
5695
+ "function token1() external view returns (address)"
5696
+ ]);
5697
+ var uniswapV2USDCAbi = (0, import_viem13.parseAbi)([
5698
+ "function getReserves() external view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast)"
5699
+ ]);
5700
+
5701
+ // src/secondary/uniswap/uniswapReserves.ts
5702
+ var uniswapV2USDCMainnetAddress = "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc";
5703
+ function getUniswapV2USDCReserves() {
5704
+ const mainnetClient = (0, import_viem14.createPublicClient)({
5705
+ chain: import_chains2.mainnet,
5706
+ transport: (0, import_viem14.http)()
5707
+ });
5708
+ return mainnetClient.readContract({
5709
+ address: uniswapV2USDCMainnetAddress,
5710
+ abi: uniswapV2USDCAbi,
5711
+ functionName: "getReserves"
5712
+ });
5713
+ }
5714
+ function toEthPriceInUSDC({
5715
+ reserve0,
5716
+ reserve1
5717
+ }) {
5718
+ return Number(reserve0 * BigInt(1e14) / reserve1) / 100;
5719
+ }
5720
+ async function getEthPriceInUSDC() {
5721
+ const reserves = await getUniswapV2USDCReserves();
5722
+ return toEthPriceInUSDC({ reserve0: reserves[0], reserve1: reserves[1] });
5723
+ }
5724
+
5725
+ // src/secondary/conversions.ts
5726
+ var import_viem15 = require("viem");
5727
+ var WEI_PER_SPARK = 1000000000000n;
5728
+ function convertWeiToSparks(wei) {
5729
+ return BigInt(wei) / WEI_PER_SPARK;
5730
+ }
5731
+ function convertWeiToUSD({
5732
+ amount,
5733
+ ethPriceInUSD
5734
+ }) {
5735
+ const amountInEth = (0, import_viem15.formatEther)(amount);
5736
+ return parseFloat(amountInEth) * ethPriceInUSD;
5737
+ }
5738
+
5739
+ // src/secondary/uniswap/uniswapQuote.ts
5740
+ var import_protocol_deployments13 = require("@zoralabs/protocol-deployments");
5741
+
5742
+ // src/secondary/uniswap/uniswapQuoteExact.ts
5743
+ var import_chains3 = require("viem/chains");
5744
+ var UniswapQuoterAddress = {
5745
+ [import_chains3.mainnet.id]: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e",
5746
+ [import_chains3.sepolia.id]: "0xEd1f6473345F45b75F8179591dd5bA1888cf2FB3",
5747
+ [import_chains3.zora.id]: "0x11867e1b3348F3ce4FcC170BC5af3d23E07E64Df",
5748
+ [import_chains3.zoraSepolia.id]: "0xC195976fEF0985886E37036E2DF62bF371E12Df0",
5749
+ [import_chains3.base.id]: "0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a",
5750
+ [import_chains3.baseSepolia.id]: "0xC5290058841028F1614F3A6F0F5816cAd0df5E27",
5751
+ [import_chains3.optimism.id]: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e",
5752
+ [import_chains3.arbitrum.id]: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e",
5753
+ [import_chains3.blast.id]: "0x6Cdcd65e03c1CEc3730AeeCd45bc140D57A25C77"
5754
+ };
5755
+ async function quoteExactOutputSingle({
5756
+ tokenIn,
5757
+ tokenOut,
5758
+ amountOut,
5759
+ fee,
5760
+ chainId,
5761
+ client
5762
+ }) {
5763
+ const quote = await client.simulateContract({
5764
+ abi: uniswapQuoterABI,
5765
+ address: UniswapQuoterAddress[chainId],
5766
+ functionName: "quoteExactOutputSingle",
5767
+ args: [
5768
+ {
5769
+ tokenIn,
5770
+ tokenOut,
5771
+ amount: amountOut,
5772
+ fee,
5773
+ sqrtPriceLimitX96: 0n
5774
+ }
5775
+ ]
5776
+ });
5777
+ return quote.result[0];
5778
+ }
5779
+ async function quoteExactInputSingle({
5780
+ tokenIn,
5781
+ tokenOut,
5782
+ amountIn,
5783
+ fee,
5784
+ chainId,
5785
+ client
5786
+ }) {
5787
+ const quote = await client.simulateContract({
5788
+ abi: uniswapQuoterABI,
5789
+ address: UniswapQuoterAddress[chainId],
5790
+ functionName: "quoteExactInputSingle",
5791
+ args: [
5792
+ {
5793
+ tokenIn,
5794
+ tokenOut,
5795
+ amountIn,
5796
+ fee,
5797
+ sqrtPriceLimitX96: 0n
5798
+ }
5799
+ ]
5800
+ });
5801
+ return quote.result[0];
5802
+ }
5803
+
5804
+ // src/secondary/uniswap/uniswapQuote.ts
5805
+ async function getPoolInfo({
5806
+ poolAddress,
5807
+ client,
5808
+ WETH,
5809
+ erc20z
5810
+ }) {
5811
+ const [fee, wethBalance, erc20zBalance] = await client.multicall({
5812
+ contracts: [
5813
+ {
5814
+ abi: uniswapV3PoolAbi,
5815
+ address: poolAddress,
5816
+ functionName: "fee"
5817
+ },
5818
+ // get WETH and erc20z balance for pool
5819
+ {
5820
+ abi: import_viem16.erc20Abi,
5821
+ address: WETH,
5822
+ functionName: "balanceOf",
5823
+ args: [poolAddress]
5824
+ },
5825
+ {
5826
+ abi: import_viem16.erc20Abi,
5827
+ address: erc20z,
5828
+ functionName: "balanceOf",
5829
+ args: [poolAddress]
5830
+ }
5831
+ ],
5832
+ multicallAddress: multicall3Address,
5833
+ allowFailure: false
5834
+ });
5835
+ return {
5836
+ wethBalance,
5837
+ erc20zBalance,
5838
+ fee
5839
+ };
5840
+ }
5841
+ async function getUniswapQuote(input, client) {
5842
+ const { type, quantity, poolAddress, chainId, erc20z } = input;
5843
+ const WETH = import_protocol_deployments13.wethAddress[chainId];
5844
+ const pool = await getPoolInfo({ poolAddress, WETH, erc20z, client });
5845
+ const { fee, wethBalance, erc20zBalance } = pool;
5846
+ const amountWithDecimals = input.quantity * 10n ** 18n;
5847
+ const amount = type === "buy" ? await quoteExactOutputSingle({
5848
+ tokenIn: WETH,
5849
+ tokenOut: erc20z,
5850
+ amountOut: amountWithDecimals,
5851
+ fee,
5852
+ chainId,
5853
+ client
5854
+ }) : await quoteExactInputSingle({
5855
+ tokenIn: erc20z,
5856
+ tokenOut: WETH,
5857
+ amountIn: amountWithDecimals,
5858
+ fee,
5859
+ chainId,
5860
+ client
5861
+ });
5862
+ const price = amount;
5863
+ const pricePerToken = amount / BigInt(quantity);
5864
+ const getUsdPrice = async () => {
5865
+ const ethPriceInUSD = await getEthPriceInUSDC();
5866
+ return {
5867
+ perToken: convertWeiToUSD({ amount: pricePerToken, ethPriceInUSD }),
5868
+ total: convertWeiToUSD({ amount: price, ethPriceInUSD })
5869
+ };
5870
+ };
5871
+ return {
5872
+ amount,
5873
+ poolBalance: {
5874
+ erc20z: erc20zBalance,
5875
+ weth: wethBalance
5876
+ },
5877
+ price: {
5878
+ wei: {
5879
+ perToken: pricePerToken,
5880
+ total: price
5881
+ },
5882
+ sparks: {
5883
+ perToken: convertWeiToSparks(pricePerToken),
5884
+ total: convertWeiToSparks(price)
5885
+ },
5886
+ usdc: getUsdPrice
5887
+ }
5888
+ };
5889
+ }
5890
+
5891
+ // src/secondary/slippage.ts
5892
+ var SCALE = 1e18;
5893
+ var ONE_SCALED = BigInt(SCALE);
5894
+ function calculateSlippageUp(amount, slippage) {
5895
+ return typeof amount === "bigint" ? amount * (ONE_SCALED + BigInt(slippage * SCALE)) / ONE_SCALED : parseFloat(String(amount)) * (1 + slippage);
5896
+ }
5897
+ function calculateSlippageDown(amount, slippage) {
5898
+ return typeof amount === "bigint" ? amount * (ONE_SCALED - BigInt(slippage * SCALE)) / ONE_SCALED : parseFloat(String(amount)) * (1 - slippage);
5899
+ }
5900
+
5901
+ // src/secondary/utils.ts
5902
+ var import_protocol_deployments14 = require("@zoralabs/protocol-deployments");
5903
+ async function getSecondaryInfo({
5904
+ contract,
5905
+ tokenId,
5906
+ publicClient,
5907
+ chainId
5908
+ }) {
5909
+ const result = await publicClient.readContract({
5910
+ abi: import_protocol_deployments14.zoraTimedSaleStrategyABI,
5911
+ address: import_protocol_deployments14.zoraTimedSaleStrategyAddress[chainId],
5912
+ functionName: "sale",
5913
+ args: [contract, tokenId]
5914
+ });
5915
+ if (!result.erc20zAddress) {
5916
+ return void 0;
5917
+ }
5918
+ return {
5919
+ erc20z: result.erc20zAddress,
5920
+ pool: result.poolAddress,
5921
+ secondaryActivated: result.secondaryActivated,
5922
+ saleEnd: result.saleEnd === 0n ? void 0 : result.saleEnd
5923
+ };
5924
+ }
5925
+
5926
+ // src/secondary/secondary-client.ts
5927
+ var UNISWAP_SLIPPAGE = 5e-3;
5928
+ var ERROR_INSUFFICIENT_WALLET_FUNDS = "Insufficient wallet funds";
5929
+ var ERROR_INSUFFICIENT_POOL_SUPPLY = "Insufficient pool supply";
5930
+ var ERROR_SECONDARY_NOT_CONFIGURED = "Secondary not configured for given contract and token";
5931
+ var ERROR_SECONDARY_NOT_STARTED = "Secondary market has not started";
5932
+ function makeError(errorMessage) {
5933
+ return { error: errorMessage };
5934
+ }
5935
+ async function makeBuy({
5936
+ erc20z,
5937
+ poolBalance,
5938
+ amount,
5939
+ quantity,
5940
+ account,
5941
+ recipient,
5942
+ chainId,
5943
+ slippage,
5944
+ publicClient
5945
+ }) {
5946
+ const costWithSlippage = calculateSlippageUp(amount, slippage);
5947
+ const availableToBuy = poolBalance.erc20z / BigInt(1e18) - 1n;
5948
+ const accountAddress = addressOrAccountAddress(account);
5949
+ const availableToSpend = await publicClient.getBalance({
5950
+ address: accountAddress
5951
+ });
5952
+ if (costWithSlippage > availableToSpend) {
5953
+ return makeError(ERROR_INSUFFICIENT_WALLET_FUNDS);
5954
+ }
5955
+ if (availableToBuy < BigInt(quantity)) {
5956
+ return makeError(ERROR_INSUFFICIENT_POOL_SUPPLY);
5957
+ }
5958
+ return {
5959
+ parameters: makeContractParameters({
5960
+ abi: import_protocol_deployments15.secondarySwapABI,
5961
+ address: import_protocol_deployments15.secondarySwapAddress[chainId],
5962
+ functionName: "buy1155",
5963
+ args: [
5964
+ erc20z,
5965
+ quantity,
5966
+ recipient || accountAddress,
5967
+ accountAddress,
5968
+ costWithSlippage,
5969
+ 0n
5970
+ ],
5971
+ account,
5972
+ value: costWithSlippage
5973
+ })
5974
+ };
5975
+ }
5976
+ async function buyWithSlippage({
5977
+ contract,
5978
+ tokenId,
5979
+ publicClient,
5980
+ quantity,
5981
+ chainId,
5982
+ account,
5983
+ slippage = UNISWAP_SLIPPAGE,
5984
+ recipient
5985
+ }) {
5986
+ const secondaryInfo = await getSecondaryInfo({
5987
+ contract,
5988
+ tokenId,
5989
+ publicClient,
5990
+ chainId
5991
+ });
5992
+ if (!secondaryInfo) {
5993
+ return makeError(ERROR_SECONDARY_NOT_CONFIGURED);
5994
+ }
5995
+ const { erc20z, pool, secondaryActivated } = secondaryInfo;
5996
+ if (!secondaryActivated) {
5997
+ return makeError(ERROR_SECONDARY_NOT_STARTED);
5998
+ }
5999
+ const { poolBalance, amount, price } = await getUniswapQuote(
6000
+ {
6001
+ type: "buy",
6002
+ quantity,
6003
+ poolAddress: pool,
6004
+ erc20z,
6005
+ chainId
6006
+ },
6007
+ publicClient
6008
+ );
6009
+ const call = await makeBuy({
6010
+ erc20z,
6011
+ poolBalance,
6012
+ amount,
6013
+ quantity,
6014
+ account,
6015
+ recipient,
6016
+ chainId,
6017
+ slippage,
6018
+ publicClient
6019
+ });
6020
+ return {
6021
+ ...call,
6022
+ price
6023
+ };
6024
+ }
6025
+ async function makeSell({
6026
+ contract,
6027
+ tokenId,
6028
+ poolBalance,
6029
+ amount,
6030
+ quantity,
6031
+ account,
6032
+ recipient,
6033
+ chainId,
6034
+ slippage,
6035
+ publicClient
6036
+ }) {
6037
+ const accountAddress = addressOrAccountAddress(account);
6038
+ const tokenCount = await publicClient.readContract({
6039
+ abi: import_protocol_deployments15.zoraCreator1155ImplABI,
6040
+ address: contract,
6041
+ functionName: "balanceOf",
6042
+ args: [accountAddress, tokenId]
6043
+ });
6044
+ const availableToSell = tokenCount ?? 0n;
6045
+ const availableToReceive = poolBalance.weth;
6046
+ if (quantity > availableToSell) {
6047
+ return makeError(ERROR_INSUFFICIENT_WALLET_FUNDS);
6048
+ }
6049
+ if (amount > availableToReceive) {
6050
+ return makeError(ERROR_INSUFFICIENT_POOL_SUPPLY);
6051
+ }
6052
+ const receivedWithSlippage = calculateSlippageDown(amount, slippage);
6053
+ const data = (0, import_viem17.encodeAbiParameters)(import_protocol_deployments15.safeTransferSwapAbiParameters, [
6054
+ recipient || accountAddress,
6055
+ receivedWithSlippage,
6056
+ 0n
6057
+ ]);
6058
+ return {
6059
+ parameters: makeContractParameters({
6060
+ abi: import_protocol_deployments15.zoraCreator1155ImplABI,
6061
+ address: contract,
6062
+ functionName: "safeTransferFrom",
6063
+ account,
6064
+ args: [
6065
+ accountAddress,
6066
+ import_protocol_deployments15.secondarySwapAddress[chainId],
6067
+ tokenId,
6068
+ quantity,
6069
+ data
6070
+ ]
6071
+ })
6072
+ };
6073
+ }
6074
+ async function sellWithSlippage({
6075
+ contract,
6076
+ tokenId,
6077
+ publicClient,
6078
+ quantity,
6079
+ chainId,
6080
+ account,
6081
+ slippage = UNISWAP_SLIPPAGE,
6082
+ recipient
6083
+ }) {
6084
+ const secondaryInfo = await getSecondaryInfo({
6085
+ contract,
6086
+ tokenId,
6087
+ publicClient,
6088
+ chainId
6089
+ });
6090
+ if (!secondaryInfo) {
6091
+ return makeError(ERROR_SECONDARY_NOT_CONFIGURED);
6092
+ }
6093
+ const { pool, secondaryActivated, erc20z } = secondaryInfo;
6094
+ if (!secondaryActivated) {
6095
+ return makeError(ERROR_SECONDARY_NOT_STARTED);
6096
+ }
6097
+ const { poolBalance, amount, price } = await getUniswapQuote(
6098
+ { type: "sell", quantity, poolAddress: pool, chainId, erc20z },
6099
+ publicClient
6100
+ );
6101
+ const call = await makeSell({
6102
+ contract,
6103
+ tokenId,
6104
+ poolBalance,
6105
+ amount,
6106
+ quantity,
6107
+ account,
6108
+ recipient,
6109
+ chainId,
6110
+ slippage,
6111
+ publicClient
6112
+ });
6113
+ return {
6114
+ ...call,
6115
+ price
6116
+ };
6117
+ }
6118
+ var SecondaryClient = class {
6119
+ /**
6120
+ * Creates a new SecondaryClient instance.
6121
+ * @param publicClient - The public client for interacting with the blockchain.
6122
+ * @param chainId - The ID of the blockchain network.
6123
+ */
6124
+ constructor({
6125
+ publicClient,
6126
+ chainId
6127
+ }) {
6128
+ this.publicClient = publicClient;
6129
+ this.chainId = chainId;
6130
+ }
6131
+ /**
6132
+ * Get the secondary info for a given contract and token ID.
6133
+ * @param contract - The address of the contract.
6134
+ * @param tokenId - The ID of the token.
6135
+ * @returns A promise that resolves to the secondary info.
6136
+ */
6137
+ async getSecondaryInfo({
6138
+ contract,
6139
+ tokenId
6140
+ }) {
6141
+ return getSecondaryInfo({
6142
+ contract,
6143
+ tokenId,
6144
+ publicClient: this.publicClient,
6145
+ chainId: this.chainId
6146
+ });
6147
+ }
6148
+ /**
6149
+ * Prepares a buy operation with slippage protection for purchasing a quantity of ERC1155 tokens with ETH on the secondary market.
6150
+ * @param input - The input parameters for the buy operation.
6151
+ * @returns A promise that resolves to the result of the buy operation, including price breakdown and transaction parameters.
6152
+ */
6153
+ async buy1155OnSecondary(input) {
6154
+ return buyWithSlippage({
6155
+ ...input,
6156
+ publicClient: this.publicClient,
6157
+ chainId: this.chainId
6158
+ });
6159
+ }
6160
+ /**
6161
+ * Prepares a sell operation with slippage protection for selling a quantity of ERC1155 tokens for ETH on the secondary market.
6162
+ * @param input - The input parameters for the sell operation.
6163
+ * @returns A promise that resolves to the result of the sell operation, including price breakdown and transaction parameters.
6164
+ */
6165
+ async sell1155OnSecondary(input) {
6166
+ return sellWithSlippage({
6167
+ ...input,
6168
+ publicClient: this.publicClient,
6169
+ chainId: this.chainId
6170
+ });
6171
+ }
6172
+ };
6173
+
5671
6174
  // src/sdk.ts
5672
6175
  function createCreatorClient(clientConfig) {
5673
6176
  const premintClient = new PremintClient({
@@ -5703,6 +6206,10 @@ function createCollectorClient(params) {
5703
6206
  premintGetter: premintGetterToUse,
5704
6207
  mintGetter: mintGetterToUse
5705
6208
  });
6209
+ const secondaryClient = new SecondaryClient({
6210
+ publicClient: params.publicClient,
6211
+ chainId: params.chainId
6212
+ });
5706
6213
  return {
5707
6214
  getPremint: (p) => premintGetterToUse.get({
5708
6215
  collectionAddress: p.address,
@@ -5712,7 +6219,10 @@ function createCollectorClient(params) {
5712
6219
  getToken: (p) => mintClient.get(p),
5713
6220
  getTokensOfContract: (p) => mintClient.getOfContract(p),
5714
6221
  mint: (p) => mintClient.mint(p),
5715
- getMintCosts: (p) => mintClient.getMintCosts(p)
6222
+ getMintCosts: (p) => mintClient.getMintCosts(p),
6223
+ buy1155OnSecondary: (p) => secondaryClient.buy1155OnSecondary(p),
6224
+ sell1155OnSecondary: (p) => secondaryClient.sell1155OnSecondary(p),
6225
+ getSecondaryInfo: (p) => secondaryClient.getSecondaryInfo(p)
5716
6226
  };
5717
6227
  }
5718
6228
 
@@ -5748,7 +6258,7 @@ function coerce3(o) {
5748
6258
  }
5749
6259
 
5750
6260
  // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/base-x.js
5751
- function base2(ALPHABET, name) {
6261
+ function base3(ALPHABET, name) {
5752
6262
  if (ALPHABET.length >= 255) {
5753
6263
  throw new TypeError("Alphabet too long");
5754
6264
  }
@@ -5879,7 +6389,7 @@ function base2(ALPHABET, name) {
5879
6389
  decode: decode5
5880
6390
  };
5881
6391
  }
5882
- var src = base2;
6392
+ var src = base3;
5883
6393
  var _brrp__multiformats_scope_baseX = src;
5884
6394
  var base_x_default = _brrp__multiformats_scope_baseX;
5885
6395
 
@@ -6240,13 +6750,13 @@ var Digest = class {
6240
6750
  };
6241
6751
 
6242
6752
  // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/cid.js
6243
- function format(link, base3) {
6753
+ function format(link, base4) {
6244
6754
  const { bytes, version } = link;
6245
6755
  switch (version) {
6246
6756
  case 0:
6247
- return toStringV0(bytes, baseCache(link), base3 ?? base58btc.encoder);
6757
+ return toStringV0(bytes, baseCache(link), base4 ?? base58btc.encoder);
6248
6758
  default:
6249
- return toStringV1(bytes, baseCache(link), base3 ?? base32.encoder);
6759
+ return toStringV1(bytes, baseCache(link), base4 ?? base32.encoder);
6250
6760
  }
6251
6761
  }
6252
6762
  var cache = /* @__PURE__ */ new WeakMap();
@@ -6338,8 +6848,8 @@ var CID = class _CID {
6338
6848
  const unknown = other;
6339
6849
  return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
6340
6850
  }
6341
- toString(base3) {
6342
- return format(this, base3);
6851
+ toString(base4) {
6852
+ return format(this, base4);
6343
6853
  }
6344
6854
  toJSON() {
6345
6855
  return { "/": format(this) };
@@ -6498,8 +7008,8 @@ var CID = class _CID {
6498
7008
  * throw an error if encoding of the CID is not compatible with supplied (or
6499
7009
  * a default decoder).
6500
7010
  */
6501
- static parse(source, base3) {
6502
- const [prefix, bytes] = parseCIDtoBytes(source, base3);
7011
+ static parse(source, base4) {
7012
+ const [prefix, bytes] = parseCIDtoBytes(source, base4);
6503
7013
  const cid = _CID.decode(bytes);
6504
7014
  if (cid.version === 0 && source[0] !== "Q") {
6505
7015
  throw Error("Version 0 CID string must not include multibase prefix");
@@ -6508,50 +7018,50 @@ var CID = class _CID {
6508
7018
  return cid;
6509
7019
  }
6510
7020
  };
6511
- function parseCIDtoBytes(source, base3) {
7021
+ function parseCIDtoBytes(source, base4) {
6512
7022
  switch (source[0]) {
6513
7023
  case "Q": {
6514
- const decoder = base3 ?? base58btc;
7024
+ const decoder = base4 ?? base58btc;
6515
7025
  return [
6516
7026
  base58btc.prefix,
6517
7027
  decoder.decode(`${base58btc.prefix}${source}`)
6518
7028
  ];
6519
7029
  }
6520
7030
  case base58btc.prefix: {
6521
- const decoder = base3 ?? base58btc;
7031
+ const decoder = base4 ?? base58btc;
6522
7032
  return [base58btc.prefix, decoder.decode(source)];
6523
7033
  }
6524
7034
  case base32.prefix: {
6525
- const decoder = base3 ?? base32;
7035
+ const decoder = base4 ?? base32;
6526
7036
  return [base32.prefix, decoder.decode(source)];
6527
7037
  }
6528
7038
  default: {
6529
- if (base3 == null) {
7039
+ if (base4 == null) {
6530
7040
  throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");
6531
7041
  }
6532
- return [source[0], base3.decode(source)];
7042
+ return [source[0], base4.decode(source)];
6533
7043
  }
6534
7044
  }
6535
7045
  }
6536
- function toStringV0(bytes, cache2, base3) {
6537
- const { prefix } = base3;
7046
+ function toStringV0(bytes, cache2, base4) {
7047
+ const { prefix } = base4;
6538
7048
  if (prefix !== base58btc.prefix) {
6539
- throw Error(`Cannot string encode V0 in ${base3.name} encoding`);
7049
+ throw Error(`Cannot string encode V0 in ${base4.name} encoding`);
6540
7050
  }
6541
7051
  const cid = cache2.get(prefix);
6542
7052
  if (cid == null) {
6543
- const cid2 = base3.encode(bytes).slice(1);
7053
+ const cid2 = base4.encode(bytes).slice(1);
6544
7054
  cache2.set(prefix, cid2);
6545
7055
  return cid2;
6546
7056
  } else {
6547
7057
  return cid;
6548
7058
  }
6549
7059
  }
6550
- function toStringV1(bytes, cache2, base3) {
6551
- const { prefix } = base3;
7060
+ function toStringV1(bytes, cache2, base4) {
7061
+ const { prefix } = base4;
6552
7062
  const cid = cache2.get(prefix);
6553
7063
  if (cid == null) {
6554
- const cid2 = base3.encode(bytes);
7064
+ const cid2 = base4.encode(bytes);
6555
7065
  cache2.set(prefix, cid2);
6556
7066
  return cid2;
6557
7067
  } else {