@zoralabs/protocol-sdk 0.10.0 → 0.11.1

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 +18 -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 +2 -2
  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.js CHANGED
@@ -391,12 +391,12 @@ var require_semver = __commonJS({
391
391
  this.prerelease = [];
392
392
  break;
393
393
  case "pre": {
394
- const base3 = Number(identifierBase) ? 1 : 0;
394
+ const base4 = Number(identifierBase) ? 1 : 0;
395
395
  if (!identifier && identifierBase === false) {
396
396
  throw new Error("invalid increment argument: identifier is empty");
397
397
  }
398
398
  if (this.prerelease.length === 0) {
399
- this.prerelease = [base3];
399
+ this.prerelease = [base4];
400
400
  } else {
401
401
  let i = this.prerelease.length;
402
402
  while (--i >= 0) {
@@ -409,11 +409,11 @@ var require_semver = __commonJS({
409
409
  if (identifier === this.prerelease.join(".") && identifierBase === false) {
410
410
  throw new Error("invalid increment argument: identifier already exists");
411
411
  }
412
- this.prerelease.push(base3);
412
+ this.prerelease.push(base4);
413
413
  }
414
414
  }
415
415
  if (identifier) {
416
- let prerelease = [identifier, base3];
416
+ let prerelease = [identifier, base4];
417
417
  if (identifierBase === false) {
418
418
  prerelease = [identifier];
419
419
  }
@@ -3023,6 +3023,7 @@ function mintRecipientOrAccount({
3023
3023
  }) {
3024
3024
  return mintRecipient || (typeof minterAccount === "string" ? minterAccount : minterAccount.address);
3025
3025
  }
3026
+ var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
3026
3027
 
3027
3028
  // src/premint/premint-client.ts
3028
3029
  var defaultTokenConfigV1MintArguments = () => ({
@@ -5135,7 +5136,6 @@ import {
5135
5136
  encodeFunctionData as encodeFunctionData3,
5136
5137
  zeroAddress as zeroAddress7
5137
5138
  } from "viem";
5138
- var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
5139
5139
  var mintWithEthParams = ({
5140
5140
  tokenId,
5141
5141
  quantity,
@@ -5668,6 +5668,527 @@ var SubgraphRewardsGetter = class extends SubgraphGetter {
5668
5668
  }
5669
5669
  };
5670
5670
 
5671
+ // src/secondary/secondary-client.ts
5672
+ import { encodeAbiParameters as encodeAbiParameters2 } from "viem";
5673
+ import {
5674
+ secondarySwapAddress,
5675
+ zoraCreator1155ImplABI as zoraCreator1155ImplABI7,
5676
+ safeTransferSwapAbiParameters,
5677
+ secondarySwapABI
5678
+ } from "@zoralabs/protocol-deployments";
5679
+
5680
+ // src/secondary/uniswap/uniswapQuote.ts
5681
+ import { erc20Abi } from "viem";
5682
+
5683
+ // src/secondary/uniswap/uniswapReserves.ts
5684
+ import { createPublicClient, http } from "viem";
5685
+ import { mainnet as mainnet2 } from "viem/chains";
5686
+
5687
+ // src/secondary/uniswap/abis.ts
5688
+ import { parseAbi as parseAbi3 } from "viem";
5689
+ var uniswapQuoterABI = parseAbi3([
5690
+ "struct QuoteExactInputSingleParams { address tokenIn; address tokenOut; uint256 amountIn; uint24 fee; uint160 sqrtPriceLimitX96; }",
5691
+ "struct QuoteExactOutputSingleParams { address tokenIn; address tokenOut; uint256 amount; uint24 fee; uint160 sqrtPriceLimitX96; }",
5692
+ "function quoteExactInputSingle(QuoteExactInputSingleParams calldata params) external returns (uint256 amountOut, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate)",
5693
+ "function quoteExactOutputSingle(QuoteExactOutputSingleParams calldata params) external returns (uint256 amountIn, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate)"
5694
+ ]);
5695
+ var uniswapV3PoolAbi = parseAbi3([
5696
+ "function fee() external view returns (uint24)",
5697
+ "function liquidity() external view returns (uint128)",
5698
+ "function slot0() external view returns (uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint8 feeProtocol, bool unlocked)",
5699
+ "function token0() external view returns (address)",
5700
+ "function token1() external view returns (address)"
5701
+ ]);
5702
+ var uniswapV2USDCAbi = parseAbi3([
5703
+ "function getReserves() external view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast)"
5704
+ ]);
5705
+
5706
+ // src/secondary/uniswap/uniswapReserves.ts
5707
+ var uniswapV2USDCMainnetAddress = "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc";
5708
+ function getUniswapV2USDCReserves() {
5709
+ const mainnetClient = createPublicClient({
5710
+ chain: mainnet2,
5711
+ transport: http()
5712
+ });
5713
+ return mainnetClient.readContract({
5714
+ address: uniswapV2USDCMainnetAddress,
5715
+ abi: uniswapV2USDCAbi,
5716
+ functionName: "getReserves"
5717
+ });
5718
+ }
5719
+ function toEthPriceInUSDC({
5720
+ reserve0,
5721
+ reserve1
5722
+ }) {
5723
+ return Number(reserve0 * BigInt(1e14) / reserve1) / 100;
5724
+ }
5725
+ async function getEthPriceInUSDC() {
5726
+ const reserves = await getUniswapV2USDCReserves();
5727
+ return toEthPriceInUSDC({ reserve0: reserves[0], reserve1: reserves[1] });
5728
+ }
5729
+
5730
+ // src/secondary/conversions.ts
5731
+ import { formatEther } from "viem";
5732
+ var WEI_PER_SPARK = 1000000000000n;
5733
+ function convertWeiToSparks(wei) {
5734
+ return BigInt(wei) / WEI_PER_SPARK;
5735
+ }
5736
+ function convertWeiToUSD({
5737
+ amount,
5738
+ ethPriceInUSD
5739
+ }) {
5740
+ const amountInEth = formatEther(amount);
5741
+ return parseFloat(amountInEth) * ethPriceInUSD;
5742
+ }
5743
+
5744
+ // src/secondary/uniswap/uniswapQuote.ts
5745
+ import { wethAddress as wethAddresses } from "@zoralabs/protocol-deployments";
5746
+
5747
+ // src/secondary/uniswap/uniswapQuoteExact.ts
5748
+ import {
5749
+ mainnet as mainnet3,
5750
+ sepolia as sepolia2,
5751
+ zora as zora2,
5752
+ zoraSepolia as zoraSepolia2,
5753
+ base as base2,
5754
+ baseSepolia as baseSepolia2,
5755
+ optimism as optimism2,
5756
+ arbitrum as arbitrum2,
5757
+ blast
5758
+ } from "viem/chains";
5759
+ var UniswapQuoterAddress = {
5760
+ [mainnet3.id]: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e",
5761
+ [sepolia2.id]: "0xEd1f6473345F45b75F8179591dd5bA1888cf2FB3",
5762
+ [zora2.id]: "0x11867e1b3348F3ce4FcC170BC5af3d23E07E64Df",
5763
+ [zoraSepolia2.id]: "0xC195976fEF0985886E37036E2DF62bF371E12Df0",
5764
+ [base2.id]: "0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a",
5765
+ [baseSepolia2.id]: "0xC5290058841028F1614F3A6F0F5816cAd0df5E27",
5766
+ [optimism2.id]: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e",
5767
+ [arbitrum2.id]: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e",
5768
+ [blast.id]: "0x6Cdcd65e03c1CEc3730AeeCd45bc140D57A25C77"
5769
+ };
5770
+ async function quoteExactOutputSingle({
5771
+ tokenIn,
5772
+ tokenOut,
5773
+ amountOut,
5774
+ fee,
5775
+ chainId,
5776
+ client
5777
+ }) {
5778
+ const quote = await client.simulateContract({
5779
+ abi: uniswapQuoterABI,
5780
+ address: UniswapQuoterAddress[chainId],
5781
+ functionName: "quoteExactOutputSingle",
5782
+ args: [
5783
+ {
5784
+ tokenIn,
5785
+ tokenOut,
5786
+ amount: amountOut,
5787
+ fee,
5788
+ sqrtPriceLimitX96: 0n
5789
+ }
5790
+ ]
5791
+ });
5792
+ return quote.result[0];
5793
+ }
5794
+ async function quoteExactInputSingle({
5795
+ tokenIn,
5796
+ tokenOut,
5797
+ amountIn,
5798
+ fee,
5799
+ chainId,
5800
+ client
5801
+ }) {
5802
+ const quote = await client.simulateContract({
5803
+ abi: uniswapQuoterABI,
5804
+ address: UniswapQuoterAddress[chainId],
5805
+ functionName: "quoteExactInputSingle",
5806
+ args: [
5807
+ {
5808
+ tokenIn,
5809
+ tokenOut,
5810
+ amountIn,
5811
+ fee,
5812
+ sqrtPriceLimitX96: 0n
5813
+ }
5814
+ ]
5815
+ });
5816
+ return quote.result[0];
5817
+ }
5818
+
5819
+ // src/secondary/uniswap/uniswapQuote.ts
5820
+ async function getPoolInfo({
5821
+ poolAddress,
5822
+ client,
5823
+ WETH,
5824
+ erc20z
5825
+ }) {
5826
+ const [fee, wethBalance, erc20zBalance] = await client.multicall({
5827
+ contracts: [
5828
+ {
5829
+ abi: uniswapV3PoolAbi,
5830
+ address: poolAddress,
5831
+ functionName: "fee"
5832
+ },
5833
+ // get WETH and erc20z balance for pool
5834
+ {
5835
+ abi: erc20Abi,
5836
+ address: WETH,
5837
+ functionName: "balanceOf",
5838
+ args: [poolAddress]
5839
+ },
5840
+ {
5841
+ abi: erc20Abi,
5842
+ address: erc20z,
5843
+ functionName: "balanceOf",
5844
+ args: [poolAddress]
5845
+ }
5846
+ ],
5847
+ multicallAddress: multicall3Address,
5848
+ allowFailure: false
5849
+ });
5850
+ return {
5851
+ wethBalance,
5852
+ erc20zBalance,
5853
+ fee
5854
+ };
5855
+ }
5856
+ async function getUniswapQuote(input, client) {
5857
+ const { type, quantity, poolAddress, chainId, erc20z } = input;
5858
+ const WETH = wethAddresses[chainId];
5859
+ const pool = await getPoolInfo({ poolAddress, WETH, erc20z, client });
5860
+ const { fee, wethBalance, erc20zBalance } = pool;
5861
+ const amountWithDecimals = input.quantity * 10n ** 18n;
5862
+ const amount = type === "buy" ? await quoteExactOutputSingle({
5863
+ tokenIn: WETH,
5864
+ tokenOut: erc20z,
5865
+ amountOut: amountWithDecimals,
5866
+ fee,
5867
+ chainId,
5868
+ client
5869
+ }) : await quoteExactInputSingle({
5870
+ tokenIn: erc20z,
5871
+ tokenOut: WETH,
5872
+ amountIn: amountWithDecimals,
5873
+ fee,
5874
+ chainId,
5875
+ client
5876
+ });
5877
+ const price = amount;
5878
+ const pricePerToken = amount / BigInt(quantity);
5879
+ const getUsdPrice = async () => {
5880
+ const ethPriceInUSD = await getEthPriceInUSDC();
5881
+ return {
5882
+ perToken: convertWeiToUSD({ amount: pricePerToken, ethPriceInUSD }),
5883
+ total: convertWeiToUSD({ amount: price, ethPriceInUSD })
5884
+ };
5885
+ };
5886
+ return {
5887
+ amount,
5888
+ poolBalance: {
5889
+ erc20z: erc20zBalance,
5890
+ weth: wethBalance
5891
+ },
5892
+ price: {
5893
+ wei: {
5894
+ perToken: pricePerToken,
5895
+ total: price
5896
+ },
5897
+ sparks: {
5898
+ perToken: convertWeiToSparks(pricePerToken),
5899
+ total: convertWeiToSparks(price)
5900
+ },
5901
+ usdc: getUsdPrice
5902
+ }
5903
+ };
5904
+ }
5905
+
5906
+ // src/secondary/slippage.ts
5907
+ var SCALE = 1e18;
5908
+ var ONE_SCALED = BigInt(SCALE);
5909
+ function calculateSlippageUp(amount, slippage) {
5910
+ return typeof amount === "bigint" ? amount * (ONE_SCALED + BigInt(slippage * SCALE)) / ONE_SCALED : parseFloat(String(amount)) * (1 + slippage);
5911
+ }
5912
+ function calculateSlippageDown(amount, slippage) {
5913
+ return typeof amount === "bigint" ? amount * (ONE_SCALED - BigInt(slippage * SCALE)) / ONE_SCALED : parseFloat(String(amount)) * (1 - slippage);
5914
+ }
5915
+
5916
+ // src/secondary/utils.ts
5917
+ import {
5918
+ zoraTimedSaleStrategyABI as zoraTimedSaleStrategyABI3,
5919
+ zoraTimedSaleStrategyAddress as zoraTimedSaleStrategyAddress2
5920
+ } from "@zoralabs/protocol-deployments";
5921
+ async function getSecondaryInfo({
5922
+ contract,
5923
+ tokenId,
5924
+ publicClient,
5925
+ chainId
5926
+ }) {
5927
+ const result = await publicClient.readContract({
5928
+ abi: zoraTimedSaleStrategyABI3,
5929
+ address: zoraTimedSaleStrategyAddress2[chainId],
5930
+ functionName: "sale",
5931
+ args: [contract, tokenId]
5932
+ });
5933
+ if (!result.erc20zAddress) {
5934
+ return void 0;
5935
+ }
5936
+ return {
5937
+ erc20z: result.erc20zAddress,
5938
+ pool: result.poolAddress,
5939
+ secondaryActivated: result.secondaryActivated,
5940
+ saleEnd: result.saleEnd === 0n ? void 0 : result.saleEnd
5941
+ };
5942
+ }
5943
+
5944
+ // src/secondary/secondary-client.ts
5945
+ var UNISWAP_SLIPPAGE = 5e-3;
5946
+ var ERROR_INSUFFICIENT_WALLET_FUNDS = "Insufficient wallet funds";
5947
+ var ERROR_INSUFFICIENT_POOL_SUPPLY = "Insufficient pool supply";
5948
+ var ERROR_SECONDARY_NOT_CONFIGURED = "Secondary not configured for given contract and token";
5949
+ var ERROR_SECONDARY_NOT_STARTED = "Secondary market has not started";
5950
+ function makeError(errorMessage) {
5951
+ return { error: errorMessage };
5952
+ }
5953
+ async function makeBuy({
5954
+ erc20z,
5955
+ poolBalance,
5956
+ amount,
5957
+ quantity,
5958
+ account,
5959
+ recipient,
5960
+ chainId,
5961
+ slippage,
5962
+ publicClient
5963
+ }) {
5964
+ const costWithSlippage = calculateSlippageUp(amount, slippage);
5965
+ const availableToBuy = poolBalance.erc20z / BigInt(1e18) - 1n;
5966
+ const accountAddress = addressOrAccountAddress(account);
5967
+ const availableToSpend = await publicClient.getBalance({
5968
+ address: accountAddress
5969
+ });
5970
+ if (costWithSlippage > availableToSpend) {
5971
+ return makeError(ERROR_INSUFFICIENT_WALLET_FUNDS);
5972
+ }
5973
+ if (availableToBuy < BigInt(quantity)) {
5974
+ return makeError(ERROR_INSUFFICIENT_POOL_SUPPLY);
5975
+ }
5976
+ return {
5977
+ parameters: makeContractParameters({
5978
+ abi: secondarySwapABI,
5979
+ address: secondarySwapAddress[chainId],
5980
+ functionName: "buy1155",
5981
+ args: [
5982
+ erc20z,
5983
+ quantity,
5984
+ recipient || accountAddress,
5985
+ accountAddress,
5986
+ costWithSlippage,
5987
+ 0n
5988
+ ],
5989
+ account,
5990
+ value: costWithSlippage
5991
+ })
5992
+ };
5993
+ }
5994
+ async function buyWithSlippage({
5995
+ contract,
5996
+ tokenId,
5997
+ publicClient,
5998
+ quantity,
5999
+ chainId,
6000
+ account,
6001
+ slippage = UNISWAP_SLIPPAGE,
6002
+ recipient
6003
+ }) {
6004
+ const secondaryInfo = await getSecondaryInfo({
6005
+ contract,
6006
+ tokenId,
6007
+ publicClient,
6008
+ chainId
6009
+ });
6010
+ if (!secondaryInfo) {
6011
+ return makeError(ERROR_SECONDARY_NOT_CONFIGURED);
6012
+ }
6013
+ const { erc20z, pool, secondaryActivated } = secondaryInfo;
6014
+ if (!secondaryActivated) {
6015
+ return makeError(ERROR_SECONDARY_NOT_STARTED);
6016
+ }
6017
+ const { poolBalance, amount, price } = await getUniswapQuote(
6018
+ {
6019
+ type: "buy",
6020
+ quantity,
6021
+ poolAddress: pool,
6022
+ erc20z,
6023
+ chainId
6024
+ },
6025
+ publicClient
6026
+ );
6027
+ const call = await makeBuy({
6028
+ erc20z,
6029
+ poolBalance,
6030
+ amount,
6031
+ quantity,
6032
+ account,
6033
+ recipient,
6034
+ chainId,
6035
+ slippage,
6036
+ publicClient
6037
+ });
6038
+ return {
6039
+ ...call,
6040
+ price
6041
+ };
6042
+ }
6043
+ async function makeSell({
6044
+ contract,
6045
+ tokenId,
6046
+ poolBalance,
6047
+ amount,
6048
+ quantity,
6049
+ account,
6050
+ recipient,
6051
+ chainId,
6052
+ slippage,
6053
+ publicClient
6054
+ }) {
6055
+ const accountAddress = addressOrAccountAddress(account);
6056
+ const tokenCount = await publicClient.readContract({
6057
+ abi: zoraCreator1155ImplABI7,
6058
+ address: contract,
6059
+ functionName: "balanceOf",
6060
+ args: [accountAddress, tokenId]
6061
+ });
6062
+ const availableToSell = tokenCount ?? 0n;
6063
+ const availableToReceive = poolBalance.weth;
6064
+ if (quantity > availableToSell) {
6065
+ return makeError(ERROR_INSUFFICIENT_WALLET_FUNDS);
6066
+ }
6067
+ if (amount > availableToReceive) {
6068
+ return makeError(ERROR_INSUFFICIENT_POOL_SUPPLY);
6069
+ }
6070
+ const receivedWithSlippage = calculateSlippageDown(amount, slippage);
6071
+ const data = encodeAbiParameters2(safeTransferSwapAbiParameters, [
6072
+ recipient || accountAddress,
6073
+ receivedWithSlippage,
6074
+ 0n
6075
+ ]);
6076
+ return {
6077
+ parameters: makeContractParameters({
6078
+ abi: zoraCreator1155ImplABI7,
6079
+ address: contract,
6080
+ functionName: "safeTransferFrom",
6081
+ account,
6082
+ args: [
6083
+ accountAddress,
6084
+ secondarySwapAddress[chainId],
6085
+ tokenId,
6086
+ quantity,
6087
+ data
6088
+ ]
6089
+ })
6090
+ };
6091
+ }
6092
+ async function sellWithSlippage({
6093
+ contract,
6094
+ tokenId,
6095
+ publicClient,
6096
+ quantity,
6097
+ chainId,
6098
+ account,
6099
+ slippage = UNISWAP_SLIPPAGE,
6100
+ recipient
6101
+ }) {
6102
+ const secondaryInfo = await getSecondaryInfo({
6103
+ contract,
6104
+ tokenId,
6105
+ publicClient,
6106
+ chainId
6107
+ });
6108
+ if (!secondaryInfo) {
6109
+ return makeError(ERROR_SECONDARY_NOT_CONFIGURED);
6110
+ }
6111
+ const { pool, secondaryActivated, erc20z } = secondaryInfo;
6112
+ if (!secondaryActivated) {
6113
+ return makeError(ERROR_SECONDARY_NOT_STARTED);
6114
+ }
6115
+ const { poolBalance, amount, price } = await getUniswapQuote(
6116
+ { type: "sell", quantity, poolAddress: pool, chainId, erc20z },
6117
+ publicClient
6118
+ );
6119
+ const call = await makeSell({
6120
+ contract,
6121
+ tokenId,
6122
+ poolBalance,
6123
+ amount,
6124
+ quantity,
6125
+ account,
6126
+ recipient,
6127
+ chainId,
6128
+ slippage,
6129
+ publicClient
6130
+ });
6131
+ return {
6132
+ ...call,
6133
+ price
6134
+ };
6135
+ }
6136
+ var SecondaryClient = class {
6137
+ /**
6138
+ * Creates a new SecondaryClient instance.
6139
+ * @param publicClient - The public client for interacting with the blockchain.
6140
+ * @param chainId - The ID of the blockchain network.
6141
+ */
6142
+ constructor({
6143
+ publicClient,
6144
+ chainId
6145
+ }) {
6146
+ this.publicClient = publicClient;
6147
+ this.chainId = chainId;
6148
+ }
6149
+ /**
6150
+ * Get the secondary info for a given contract and token ID.
6151
+ * @param contract - The address of the contract.
6152
+ * @param tokenId - The ID of the token.
6153
+ * @returns A promise that resolves to the secondary info.
6154
+ */
6155
+ async getSecondaryInfo({
6156
+ contract,
6157
+ tokenId
6158
+ }) {
6159
+ return getSecondaryInfo({
6160
+ contract,
6161
+ tokenId,
6162
+ publicClient: this.publicClient,
6163
+ chainId: this.chainId
6164
+ });
6165
+ }
6166
+ /**
6167
+ * Prepares a buy operation with slippage protection for purchasing a quantity of ERC1155 tokens with ETH on the secondary market.
6168
+ * @param input - The input parameters for the buy operation.
6169
+ * @returns A promise that resolves to the result of the buy operation, including price breakdown and transaction parameters.
6170
+ */
6171
+ async buy1155OnSecondary(input) {
6172
+ return buyWithSlippage({
6173
+ ...input,
6174
+ publicClient: this.publicClient,
6175
+ chainId: this.chainId
6176
+ });
6177
+ }
6178
+ /**
6179
+ * Prepares a sell operation with slippage protection for selling a quantity of ERC1155 tokens for ETH on the secondary market.
6180
+ * @param input - The input parameters for the sell operation.
6181
+ * @returns A promise that resolves to the result of the sell operation, including price breakdown and transaction parameters.
6182
+ */
6183
+ async sell1155OnSecondary(input) {
6184
+ return sellWithSlippage({
6185
+ ...input,
6186
+ publicClient: this.publicClient,
6187
+ chainId: this.chainId
6188
+ });
6189
+ }
6190
+ };
6191
+
5671
6192
  // src/sdk.ts
5672
6193
  function createCreatorClient(clientConfig) {
5673
6194
  const premintClient = new PremintClient({
@@ -5703,6 +6224,10 @@ function createCollectorClient(params) {
5703
6224
  premintGetter: premintGetterToUse,
5704
6225
  mintGetter: mintGetterToUse
5705
6226
  });
6227
+ const secondaryClient = new SecondaryClient({
6228
+ publicClient: params.publicClient,
6229
+ chainId: params.chainId
6230
+ });
5706
6231
  return {
5707
6232
  getPremint: (p) => premintGetterToUse.get({
5708
6233
  collectionAddress: p.address,
@@ -5712,7 +6237,10 @@ function createCollectorClient(params) {
5712
6237
  getToken: (p) => mintClient.get(p),
5713
6238
  getTokensOfContract: (p) => mintClient.getOfContract(p),
5714
6239
  mint: (p) => mintClient.mint(p),
5715
- getMintCosts: (p) => mintClient.getMintCosts(p)
6240
+ getMintCosts: (p) => mintClient.getMintCosts(p),
6241
+ buy1155OnSecondary: (p) => secondaryClient.buy1155OnSecondary(p),
6242
+ sell1155OnSecondary: (p) => secondaryClient.sell1155OnSecondary(p),
6243
+ getSecondaryInfo: (p) => secondaryClient.getSecondaryInfo(p)
5716
6244
  };
5717
6245
  }
5718
6246
 
@@ -5748,7 +6276,7 @@ function coerce3(o) {
5748
6276
  }
5749
6277
 
5750
6278
  // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/base-x.js
5751
- function base2(ALPHABET, name) {
6279
+ function base3(ALPHABET, name) {
5752
6280
  if (ALPHABET.length >= 255) {
5753
6281
  throw new TypeError("Alphabet too long");
5754
6282
  }
@@ -5879,7 +6407,7 @@ function base2(ALPHABET, name) {
5879
6407
  decode: decode5
5880
6408
  };
5881
6409
  }
5882
- var src = base2;
6410
+ var src = base3;
5883
6411
  var _brrp__multiformats_scope_baseX = src;
5884
6412
  var base_x_default = _brrp__multiformats_scope_baseX;
5885
6413
 
@@ -6240,13 +6768,13 @@ var Digest = class {
6240
6768
  };
6241
6769
 
6242
6770
  // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/cid.js
6243
- function format(link, base3) {
6771
+ function format(link, base4) {
6244
6772
  const { bytes, version } = link;
6245
6773
  switch (version) {
6246
6774
  case 0:
6247
- return toStringV0(bytes, baseCache(link), base3 ?? base58btc.encoder);
6775
+ return toStringV0(bytes, baseCache(link), base4 ?? base58btc.encoder);
6248
6776
  default:
6249
- return toStringV1(bytes, baseCache(link), base3 ?? base32.encoder);
6777
+ return toStringV1(bytes, baseCache(link), base4 ?? base32.encoder);
6250
6778
  }
6251
6779
  }
6252
6780
  var cache = /* @__PURE__ */ new WeakMap();
@@ -6338,8 +6866,8 @@ var CID = class _CID {
6338
6866
  const unknown = other;
6339
6867
  return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
6340
6868
  }
6341
- toString(base3) {
6342
- return format(this, base3);
6869
+ toString(base4) {
6870
+ return format(this, base4);
6343
6871
  }
6344
6872
  toJSON() {
6345
6873
  return { "/": format(this) };
@@ -6498,8 +7026,8 @@ var CID = class _CID {
6498
7026
  * throw an error if encoding of the CID is not compatible with supplied (or
6499
7027
  * a default decoder).
6500
7028
  */
6501
- static parse(source, base3) {
6502
- const [prefix, bytes] = parseCIDtoBytes(source, base3);
7029
+ static parse(source, base4) {
7030
+ const [prefix, bytes] = parseCIDtoBytes(source, base4);
6503
7031
  const cid = _CID.decode(bytes);
6504
7032
  if (cid.version === 0 && source[0] !== "Q") {
6505
7033
  throw Error("Version 0 CID string must not include multibase prefix");
@@ -6508,50 +7036,50 @@ var CID = class _CID {
6508
7036
  return cid;
6509
7037
  }
6510
7038
  };
6511
- function parseCIDtoBytes(source, base3) {
7039
+ function parseCIDtoBytes(source, base4) {
6512
7040
  switch (source[0]) {
6513
7041
  case "Q": {
6514
- const decoder = base3 ?? base58btc;
7042
+ const decoder = base4 ?? base58btc;
6515
7043
  return [
6516
7044
  base58btc.prefix,
6517
7045
  decoder.decode(`${base58btc.prefix}${source}`)
6518
7046
  ];
6519
7047
  }
6520
7048
  case base58btc.prefix: {
6521
- const decoder = base3 ?? base58btc;
7049
+ const decoder = base4 ?? base58btc;
6522
7050
  return [base58btc.prefix, decoder.decode(source)];
6523
7051
  }
6524
7052
  case base32.prefix: {
6525
- const decoder = base3 ?? base32;
7053
+ const decoder = base4 ?? base32;
6526
7054
  return [base32.prefix, decoder.decode(source)];
6527
7055
  }
6528
7056
  default: {
6529
- if (base3 == null) {
7057
+ if (base4 == null) {
6530
7058
  throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");
6531
7059
  }
6532
- return [source[0], base3.decode(source)];
7060
+ return [source[0], base4.decode(source)];
6533
7061
  }
6534
7062
  }
6535
7063
  }
6536
- function toStringV0(bytes, cache2, base3) {
6537
- const { prefix } = base3;
7064
+ function toStringV0(bytes, cache2, base4) {
7065
+ const { prefix } = base4;
6538
7066
  if (prefix !== base58btc.prefix) {
6539
- throw Error(`Cannot string encode V0 in ${base3.name} encoding`);
7067
+ throw Error(`Cannot string encode V0 in ${base4.name} encoding`);
6540
7068
  }
6541
7069
  const cid = cache2.get(prefix);
6542
7070
  if (cid == null) {
6543
- const cid2 = base3.encode(bytes).slice(1);
7071
+ const cid2 = base4.encode(bytes).slice(1);
6544
7072
  cache2.set(prefix, cid2);
6545
7073
  return cid2;
6546
7074
  } else {
6547
7075
  return cid;
6548
7076
  }
6549
7077
  }
6550
- function toStringV1(bytes, cache2, base3) {
6551
- const { prefix } = base3;
7078
+ function toStringV1(bytes, cache2, base4) {
7079
+ const { prefix } = base4;
6552
7080
  const cid = cache2.get(prefix);
6553
7081
  if (cid == null) {
6554
- const cid2 = base3.encode(bytes);
7082
+ const cid2 = base4.encode(bytes);
6555
7083
  cache2.set(prefix, cid2);
6556
7084
  return cid2;
6557
7085
  } else {