flipmeme-sdk 1.0.15 → 1.0.16

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.d.mts CHANGED
@@ -54,6 +54,7 @@ interface BuyResponse {
54
54
  collectionAddress: string;
55
55
  nftAddress: string;
56
56
  tokenId: string;
57
+ tokenName: string;
57
58
  tokenUri: string;
58
59
  price: string;
59
60
  is_sold_out: boolean;
@@ -84,7 +85,7 @@ declare class FlipmemeSDK {
84
85
  updateConfig(chainType: BlockchainType, config: EthereumConfig | SolanaConfig): void;
85
86
  createCollection(params: CollectionParams): Promise<CreateCollectionResponse>;
86
87
  getCollectionPda(): Promise<CollectionInfo>;
87
- buy(params: BuyParams): Promise<void>;
88
+ buy(params: BuyParams): Promise<BuyResponse[]>;
88
89
  flipSell(params: SellParams): Promise<void>;
89
90
  profileSell(data: ProfileSellParams): Promise<void>;
90
91
  buyCredit(params: BuyCreditParams): Promise<string>;
package/dist/index.d.ts CHANGED
@@ -54,6 +54,7 @@ interface BuyResponse {
54
54
  collectionAddress: string;
55
55
  nftAddress: string;
56
56
  tokenId: string;
57
+ tokenName: string;
57
58
  tokenUri: string;
58
59
  price: string;
59
60
  is_sold_out: boolean;
@@ -84,7 +85,7 @@ declare class FlipmemeSDK {
84
85
  updateConfig(chainType: BlockchainType, config: EthereumConfig | SolanaConfig): void;
85
86
  createCollection(params: CollectionParams): Promise<CreateCollectionResponse>;
86
87
  getCollectionPda(): Promise<CollectionInfo>;
87
- buy(params: BuyParams): Promise<void>;
88
+ buy(params: BuyParams): Promise<BuyResponse[]>;
88
89
  flipSell(params: SellParams): Promise<void>;
89
90
  profileSell(data: ProfileSellParams): Promise<void>;
90
91
  buyCredit(params: BuyCreditParams): Promise<string>;
package/dist/index.js CHANGED
@@ -73,7 +73,7 @@ var EthereumConnector = class {
73
73
  };
74
74
 
75
75
  // src/solana/index.ts
76
- var import_anchor = require("@coral-xyz/anchor");
76
+ var import_anchor2 = require("@coral-xyz/anchor");
77
77
 
78
78
  // src/solana/idls/flipmeme.json
79
79
  var flipmeme_default = {
@@ -1561,16 +1561,34 @@ var import_lodash = require("lodash");
1561
1561
  var import_decimal = __toESM(require("decimal.js"));
1562
1562
 
1563
1563
  // src/solana/analyze.ts
1564
- function analyzeBuyTransaction(transactionData) {
1565
- return __async(this, null, function* () {
1566
- var _a, _b, _c;
1567
- console.log("log Messages", (_a = transactionData.meta) == null ? void 0 : _a.logMessages, "log Messages");
1568
- const eventLogs = (_c = (_b = transactionData.meta) == null ? void 0 : _b.logMessages) == null ? void 0 : _c.filter(
1569
- (log) => log.includes("Program data:")
1570
- );
1571
- console.log("eventLogs", eventLogs);
1572
- return [];
1573
- });
1564
+ var import_anchor = require("@coral-xyz/anchor");
1565
+ function analyzeBuyTransaction(program, transactionData) {
1566
+ var _a;
1567
+ let instructions = (_a = transactionData.meta) == null ? void 0 : _a.innerInstructions;
1568
+ let buyResponse = [];
1569
+ if (instructions) {
1570
+ for (const instruction of instructions) {
1571
+ for (const subInstruction of instruction.instructions) {
1572
+ let rawData = import_anchor.utils.bytes.bs58.decode(subInstruction.data);
1573
+ const base64Data = import_anchor.utils.bytes.base64.encode(rawData.subarray(8));
1574
+ let decodedData = program.coder.events.decode(base64Data);
1575
+ if ((decodedData == null ? void 0 : decodedData.name) === "mintEvent") {
1576
+ buyResponse.push({
1577
+ buyer: decodedData.data.buyer.toString(),
1578
+ collectionAddress: decodedData.data.collection.toString(),
1579
+ nftAddress: decodedData.data.nft.toString(),
1580
+ tokenId: decodedData.data.tokenId.toString(),
1581
+ tokenName: decodedData.data.name.toString(),
1582
+ tokenUri: decodedData.data.uri.toString(),
1583
+ price: decodedData.data.price.toString(),
1584
+ is_sold_out: decodedData.data.isSoldOut,
1585
+ totalSolAmount: decodedData.data.totalSol.toString()
1586
+ });
1587
+ }
1588
+ }
1589
+ }
1590
+ }
1591
+ return buyResponse;
1574
1592
  }
1575
1593
 
1576
1594
  // src/solana/index.ts
@@ -1582,7 +1600,7 @@ var SolanaConnector = class {
1582
1600
  }
1583
1601
  setFlipmemeProgram() {
1584
1602
  return __async(this, null, function* () {
1585
- let program = new import_anchor.Program(flipmeme_default, this.config.provider);
1603
+ let program = new import_anchor2.Program(flipmeme_default, this.config.provider);
1586
1604
  this.program = program;
1587
1605
  });
1588
1606
  }
@@ -1691,11 +1709,19 @@ var SolanaConnector = class {
1691
1709
  if (!this.program) {
1692
1710
  throw new Error("Program not initialized");
1693
1711
  }
1694
- const { collectionId, collectionSymbol, creatorAddress, quantity, reserveToken } = params;
1712
+ const {
1713
+ collectionId,
1714
+ collectionSymbol,
1715
+ creatorAddress,
1716
+ quantity,
1717
+ reserveToken
1718
+ } = params;
1695
1719
  if (!reserveToken || ((_a = reserveToken.mintAndBuy) == null ? void 0 : _a.length) === 0 && ((_b = reserveToken.buy) == null ? void 0 : _b.length) === 0) {
1696
1720
  throw new Error("No available token to buy");
1697
1721
  }
1698
- const stateAccount = yield this.program.account.state.fetch(SOLANA_PUBKEYS.STATE_ID);
1722
+ const stateAccount = yield this.program.account.state.fetch(
1723
+ SOLANA_PUBKEYS.STATE_ID
1724
+ );
1699
1725
  const successTxns = [];
1700
1726
  const failedItems = [];
1701
1727
  const instructionsChunks = [];
@@ -1730,11 +1756,16 @@ var SolanaConnector = class {
1730
1756
  console.error("Failed to getMintAndBuyInstructions", { error });
1731
1757
  }
1732
1758
  }
1759
+ let buyResponse = [];
1733
1760
  for (const [instructions, items] of instructionsChunks) {
1734
1761
  try {
1735
1762
  const { signature, latestBlockhash } = yield this.sendTxn(instructions);
1736
1763
  successTxns.push({ items, signature });
1737
- (_g = params.notify) == null ? void 0 : _g.onSuccess(successTxns.map((txn) => txn.items).flat(), quantity, signature);
1764
+ (_g = params.notify) == null ? void 0 : _g.onSuccess(
1765
+ successTxns.map((txn) => txn.items).flat(),
1766
+ quantity,
1767
+ signature
1768
+ );
1738
1769
  const confirmResult = yield this.config.provider.connection.confirmTransaction({
1739
1770
  blockhash: latestBlockhash.blockhash,
1740
1771
  lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
@@ -1746,9 +1777,9 @@ var SolanaConnector = class {
1746
1777
  maxSupportedTransactionVersion: 0
1747
1778
  });
1748
1779
  if (transactionData) {
1749
- analyzeBuyTransaction(transactionData);
1780
+ let itemBuyResponse = yield analyzeBuyTransaction(this.program, transactionData);
1781
+ buyResponse.push(...itemBuyResponse);
1750
1782
  }
1751
- console.log("transactionData", transactionData);
1752
1783
  } catch (e) {
1753
1784
  failedItems.push(...items);
1754
1785
  (_h = params.notify) == null ? void 0 : _h.onFailed(failedItems, quantity);
@@ -1756,6 +1787,7 @@ var SolanaConnector = class {
1756
1787
  throw e;
1757
1788
  }
1758
1789
  }
1790
+ return buyResponse;
1759
1791
  });
1760
1792
  }
1761
1793
  //useFlip.ts
@@ -1784,7 +1816,11 @@ var SolanaConnector = class {
1784
1816
  try {
1785
1817
  const { signature } = yield this.sendTxn(instructions);
1786
1818
  successTxns.push({ items, signature });
1787
- notify == null ? void 0 : notify.onSuccess(successTxns.map((txn) => txn.items).flat(), quantity, signature);
1819
+ notify == null ? void 0 : notify.onSuccess(
1820
+ successTxns.map((txn) => txn.items).flat(),
1821
+ quantity,
1822
+ signature
1823
+ );
1788
1824
  } catch (e) {
1789
1825
  failedItems.push(...items);
1790
1826
  notify == null ? void 0 : notify.onFailed(failedItems, quantity);
@@ -1821,7 +1857,11 @@ var SolanaConnector = class {
1821
1857
  try {
1822
1858
  const { signature } = yield this.sendTxn(instructions);
1823
1859
  successTxns.push({ items: items2, signature });
1824
- (_b = data.notify) == null ? void 0 : _b.onSuccess(successTxns.map((txn) => txn.items).flat(), items2.length, signature);
1860
+ (_b = data.notify) == null ? void 0 : _b.onSuccess(
1861
+ successTxns.map((txn) => txn.items).flat(),
1862
+ items2.length,
1863
+ signature
1864
+ );
1825
1865
  } catch (e) {
1826
1866
  failedItems.push(...items2);
1827
1867
  (_c = data.notify) == null ? void 0 : _c.onFailed(failedItems, items2.length);
@@ -1844,7 +1884,10 @@ var SolanaConnector = class {
1844
1884
  lamports: new import_decimal.default(params.amount).mul(10 ** 9).toNumber()
1845
1885
  })
1846
1886
  );
1847
- return yield this.config.sendTransaction(transaction, this.config.provider.connection);
1887
+ return yield this.config.sendTransaction(
1888
+ transaction,
1889
+ this.config.provider.connection
1890
+ );
1848
1891
  });
1849
1892
  }
1850
1893
  //for testing
@@ -1853,7 +1896,9 @@ var SolanaConnector = class {
1853
1896
  if (!this.program) {
1854
1897
  throw new Error("Program not initialized");
1855
1898
  }
1856
- const state = yield this.program.account.state.fetch(SOLANA_PUBKEYS.STATE_ID);
1899
+ const state = yield this.program.account.state.fetch(
1900
+ SOLANA_PUBKEYS.STATE_ID
1901
+ );
1857
1902
  return state;
1858
1903
  });
1859
1904
  }
@@ -1863,8 +1908,13 @@ var SolanaConnector = class {
1863
1908
  if (!this.program) {
1864
1909
  throw new Error("Program not initialized");
1865
1910
  }
1866
- const collectionAddress = yield collectionPda(collectionId, this.program.programId);
1867
- const collectionInfo = yield this.program.account.collection.fetch(collectionAddress);
1911
+ const collectionAddress = yield collectionPda(
1912
+ collectionId,
1913
+ this.program.programId
1914
+ );
1915
+ const collectionInfo = yield this.program.account.collection.fetch(
1916
+ collectionAddress
1917
+ );
1868
1918
  return { collectionInfo, collectionAddress };
1869
1919
  });
1870
1920
  }
@@ -1886,7 +1936,10 @@ var SolanaConnector = class {
1886
1936
  const tx = new import_web34.VersionedTransaction(messageV0);
1887
1937
  const sim = yield this.config.provider.connection.simulateTransaction(tx);
1888
1938
  console.log("simulation result == ", sim);
1889
- const signature = yield this.config.sendTransaction(tx, this.config.provider.connection);
1939
+ const signature = yield this.config.sendTransaction(
1940
+ tx,
1941
+ this.config.provider.connection
1942
+ );
1890
1943
  return {
1891
1944
  signature,
1892
1945
  latestBlockhash
@@ -1903,7 +1956,9 @@ var SolanaConnector = class {
1903
1956
  const allInstructionSets = [];
1904
1957
  try {
1905
1958
  for (const chunk of tokenChunks) {
1906
- const instructions = yield this.setUpInstructions(25e4 * chunk.length);
1959
+ const instructions = yield this.setUpInstructions(
1960
+ 25e4 * chunk.length
1961
+ );
1907
1962
  for (const token of chunk) {
1908
1963
  const instruction = yield this.program.methods.buy(token.tokenId).accounts({
1909
1964
  state: SOLANA_PUBKEYS.STATE_ID,
@@ -1940,7 +1995,9 @@ var SolanaConnector = class {
1940
1995
  );
1941
1996
  try {
1942
1997
  for (const chunk of tokenChunks) {
1943
- const instructions = yield this.setUpInstructions(25e4 * chunk.length);
1998
+ const instructions = yield this.setUpInstructions(
1999
+ 25e4 * chunk.length
2000
+ );
1944
2001
  for (const token of chunk) {
1945
2002
  const { nftHolderPda: nftHolderPda2, collectionPda: collectionPda2, nftPda: nftPda2 } = yield getNftAccounts(
1946
2003
  token.tokenId
@@ -1980,7 +2037,7 @@ var SolanaConnector = class {
1980
2037
  if (!this.program) {
1981
2038
  throw new Error("Program not initialized");
1982
2039
  }
1983
- const chunkSize = 1;
2040
+ const chunkSize = 20;
1984
2041
  const tokenChunks = getTokenChunks(tokens, chunkSize);
1985
2042
  const allInstructionSets = [];
1986
2043
  const { getNftAccounts } = yield getTradingAccounts(
@@ -1991,7 +2048,9 @@ var SolanaConnector = class {
1991
2048
  );
1992
2049
  try {
1993
2050
  for (const chunk of tokenChunks) {
1994
- const instructions = yield this.setUpInstructions(35e4 * chunk.length);
2051
+ const instructions = yield this.setUpInstructions(
2052
+ 35e4 * chunk.length
2053
+ );
1995
2054
  for (const token of chunk) {
1996
2055
  const { name, tokenURI, tokenId } = token;
1997
2056
  const { nftPda: nftPda2, collectionPda: collectionPda2, nftHolderPda: nftHolderPda2 } = yield getNftAccounts(
@@ -2031,7 +2090,10 @@ var SolanaConnector = class {
2031
2090
  return __async(this, null, function* () {
2032
2091
  const recentFees = yield this.config.provider.connection.getRecentPrioritizationFees();
2033
2092
  const MIN_FEE = 1e4;
2034
- const dynamicFee = Math.max(...recentFees.map((fee) => fee.prioritizationFee), MIN_FEE);
2093
+ const dynamicFee = Math.max(
2094
+ ...recentFees.map((fee) => fee.prioritizationFee),
2095
+ MIN_FEE
2096
+ );
2035
2097
  return dynamicFee;
2036
2098
  });
2037
2099
  }
@@ -2052,12 +2114,15 @@ var SolanaConnector = class {
2052
2114
  }
2053
2115
  getTransactionTest(signature) {
2054
2116
  return __async(this, null, function* () {
2055
- const transaction = yield this.config.provider.connection.getTransaction(signature, {
2056
- commitment: "confirmed",
2057
- maxSupportedTransactionVersion: 0
2058
- });
2059
- if (transaction) {
2060
- analyzeBuyTransaction(transaction);
2117
+ const transaction = yield this.config.provider.connection.getTransaction(
2118
+ signature,
2119
+ {
2120
+ commitment: "confirmed",
2121
+ maxSupportedTransactionVersion: 0
2122
+ }
2123
+ );
2124
+ if (transaction && this.program) {
2125
+ analyzeBuyTransaction(this.program, transaction);
2061
2126
  }
2062
2127
  return transaction;
2063
2128
  });