@flaunch/sdk 0.4.1 → 0.4.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.
package/dist/index.esm.js CHANGED
@@ -6921,9 +6921,22 @@ const FlaunchPositionManagerAbi = [
6921
6921
  { stateMutability: "payable", type: "receive" },
6922
6922
  ];
6923
6923
 
6924
+ // List of public IPFS gateways to cycle through
6925
+ const IPFS_GATEWAYS = [
6926
+ "https://gateway.pinata.cloud/ipfs/",
6927
+ "https://ipfs.io/ipfs/",
6928
+ "https://dweb.link/ipfs/",
6929
+ ];
6930
+ // Counter to track the current gateway index
6931
+ let currentGatewayIndex = 0;
6924
6932
  const resolveIPFS = (value) => {
6925
6933
  if (value.startsWith("ipfs://")) {
6926
- return `https://gateway.pinata.cloud/ipfs/${value.slice(7)}`;
6934
+ const cid = value.slice(7);
6935
+ // Get the next gateway and increment the counter
6936
+ const gateway = IPFS_GATEWAYS[currentGatewayIndex];
6937
+ // Update the counter, cycling back to 0 when we reach the end
6938
+ currentGatewayIndex = (currentGatewayIndex + 1) % IPFS_GATEWAYS.length;
6939
+ return `${gateway}${cid}`;
6927
6940
  }
6928
6941
  return value;
6929
6942
  };
@@ -17558,6 +17571,7 @@ class ReadFlaunchSDK {
17558
17571
  this.TICK_SPACING = TICK_SPACING;
17559
17572
  this.chainId = chainId;
17560
17573
  this.drift = drift;
17574
+ this.resolveIPFS = resolveIPFS;
17561
17575
  this.readPositionManager = new ReadFlaunchPositionManager(FlaunchPositionManagerAddress[this.chainId], drift);
17562
17576
  this.readPositionManagerV1_1 = new ReadFlaunchPositionManagerV1_1(FlaunchPositionManagerV1_1Address[this.chainId], drift);
17563
17577
  this.readPoolManager = new ReadPoolManager(PoolManagerAddress[this.chainId], drift);
@@ -17599,12 +17613,12 @@ class ReadFlaunchSDK {
17599
17613
  const symbol = await memecoin.symbol();
17600
17614
  const tokenURI = await memecoin.tokenURI();
17601
17615
  // get metadata from tokenURI
17602
- const metadata = (await axios.get(resolveIPFS(tokenURI))).data;
17616
+ const metadata = (await axios.get(this.resolveIPFS(tokenURI))).data;
17603
17617
  return {
17604
17618
  name,
17605
17619
  symbol,
17606
17620
  description: metadata.description ?? "",
17607
- image: metadata.image ? resolveIPFS(metadata.image) : "",
17621
+ image: metadata.image ? this.resolveIPFS(metadata.image) : "",
17608
17622
  external_link: metadata.websiteUrl ?? "",
17609
17623
  collaborators: metadata.collaborators ?? [],
17610
17624
  discordUrl: metadata.discordUrl ?? "",
@@ -17612,12 +17626,25 @@ class ReadFlaunchSDK {
17612
17626
  telegramUrl: metadata.telegramUrl ?? "",
17613
17627
  };
17614
17628
  }
17629
+ /**
17630
+ * Retrieves metadata for a given Flaunch coin using its token ID & Flaunch contract address
17631
+ * @param flaunch - The address of the Flaunch contract
17632
+ * @param tokenId - The token ID of the coin
17633
+ * @returns The coin's metadata including name, symbol, description, and social links
17634
+ */
17615
17635
  async getCoinMetadataFromTokenId(flaunch, tokenId) {
17616
17636
  const _flaunch = new ReadFlaunch(flaunch, this.drift);
17617
17637
  const coinAddress = await _flaunch.memecoin(tokenId);
17618
17638
  return this.getCoinMetadata(coinAddress);
17619
17639
  }
17620
- async getCoinMetadataFromTokenIds(params) {
17640
+ /**
17641
+ * Retrieves metadata for multiple Flaunch coins using their token IDs & Flaunch contract addresses
17642
+ * @param params - An array of objects containing flaunch contract address and token ID
17643
+ * @param batchSize - Optional, the number of ipfs requests to process in each batch
17644
+ * @param batchDelay - Optional, the delay in milliseconds between batches
17645
+ * @returns An array of objects containing coin address, name, symbol, description, and social links
17646
+ */
17647
+ async getCoinMetadataFromTokenIds(params, batchSize = 9, batchDelay = 500) {
17621
17648
  const multicall = new ReadMulticall(this.drift);
17622
17649
  // get coin addresses via multicall
17623
17650
  const coinAddresses_calldata = params.map((p) => this.readFlaunch.contract.encodeFunctionData("memecoin", {
@@ -17670,18 +17697,17 @@ class ReadFlaunchSDK {
17670
17697
  results.push({ name, symbol, tokenURI, coinAddress: coinAddresses[i] });
17671
17698
  }
17672
17699
  // Process IPFS requests in batches to avoid rate limiting
17673
- const batchSize = 3;
17674
17700
  const processedResults = [];
17675
17701
  for (let i = 0; i < results.length; i += batchSize) {
17676
17702
  const batch = results.slice(i, i + batchSize);
17677
17703
  const batchResults = await Promise.all(batch.map(async ({ name, symbol, tokenURI, coinAddress }) => {
17678
- const metadata = (await axios.get(resolveIPFS(tokenURI))).data;
17704
+ const metadata = (await axios.get(this.resolveIPFS(tokenURI))).data;
17679
17705
  return {
17680
17706
  coinAddress,
17681
17707
  name,
17682
17708
  symbol,
17683
17709
  description: metadata.description ?? "",
17684
- image: metadata.image ? resolveIPFS(metadata.image) : "",
17710
+ image: metadata.image ? this.resolveIPFS(metadata.image) : "",
17685
17711
  external_link: metadata.websiteUrl ?? "",
17686
17712
  collaborators: metadata.collaborators ?? [],
17687
17713
  discordUrl: metadata.discordUrl ?? "",
@@ -17692,7 +17718,7 @@ class ReadFlaunchSDK {
17692
17718
  processedResults.push(...batchResults);
17693
17719
  // Add a small delay between batches to avoid rate limiting
17694
17720
  if (i + batchSize < results.length) {
17695
- await new Promise((resolve) => setTimeout(resolve, 200));
17721
+ await new Promise((resolve) => setTimeout(resolve, batchDelay));
17696
17722
  }
17697
17723
  }
17698
17724
  return processedResults;
@@ -18118,6 +18144,14 @@ class ReadFlaunchSDK {
18118
18144
  flETHIsCurrencyZero(coinAddress) {
18119
18145
  return coinAddress > FLETHAddress[this.chainId];
18120
18146
  }
18147
+ /**
18148
+ * Sets a custom IPFS resolver function
18149
+ * @dev this is used to resolve IPFS hash to a gateway URL
18150
+ * @param resolverFn - Custom function to resolve IPFS URIs
18151
+ */
18152
+ setIPFSResolver(resolverFn) {
18153
+ this.resolveIPFS = resolverFn;
18154
+ }
18121
18155
  }
18122
18156
  class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
18123
18157
  constructor(chainId, drift = createDrift()) {