flipmeme-sdk 1.0.15 → 1.0.17

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,10 +54,21 @@ 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;
60
61
  totalSolAmount: string;
62
+ timestamp: string;
63
+ }
64
+ interface SellResponse {
65
+ seller: string;
66
+ collectionAddress: string;
67
+ nftAddress: string;
68
+ tokenId: string;
69
+ price: string;
70
+ totalSolAmount: string;
71
+ timestamp: string;
61
72
  }
62
73
  interface SellParams {
63
74
  collectionId: string;
@@ -84,8 +95,8 @@ declare class FlipmemeSDK {
84
95
  updateConfig(chainType: BlockchainType, config: EthereumConfig | SolanaConfig): void;
85
96
  createCollection(params: CollectionParams): Promise<CreateCollectionResponse>;
86
97
  getCollectionPda(): Promise<CollectionInfo>;
87
- buy(params: BuyParams): Promise<void>;
88
- flipSell(params: SellParams): Promise<void>;
98
+ buy(params: BuyParams): Promise<BuyResponse[]>;
99
+ flipSell(params: SellParams): Promise<SellResponse[]>;
89
100
  profileSell(data: ProfileSellParams): Promise<void>;
90
101
  buyCredit(params: BuyCreditParams): Promise<string>;
91
102
  /**For testing */
@@ -126,4 +137,4 @@ declare class FlipmemeSDK {
126
137
  getTransactionTest(signature: string): Promise<_solana_web3_js.VersionedTransactionResponse | null>;
127
138
  }
128
139
 
129
- export { BlockchainType, type BuyCreditParams, type BuyParams, type BuyResponse, type CollectionInfo, type CollectionParams, type CreateCollectionResponse, type EthereumConfig, FlipmemeSDK, type NFTTradingData, type ProfileSellParams, type ReserveToken, type SellParams, type SolanaConfig, isEthereumConfig, isSolanaConfig };
140
+ export { BlockchainType, type BuyCreditParams, type BuyParams, type BuyResponse, type CollectionInfo, type CollectionParams, type CreateCollectionResponse, type EthereumConfig, FlipmemeSDK, type NFTTradingData, type ProfileSellParams, type ReserveToken, type SellParams, type SellResponse, type SolanaConfig, isEthereumConfig, isSolanaConfig };
package/dist/index.d.ts CHANGED
@@ -54,10 +54,21 @@ 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;
60
61
  totalSolAmount: string;
62
+ timestamp: string;
63
+ }
64
+ interface SellResponse {
65
+ seller: string;
66
+ collectionAddress: string;
67
+ nftAddress: string;
68
+ tokenId: string;
69
+ price: string;
70
+ totalSolAmount: string;
71
+ timestamp: string;
61
72
  }
62
73
  interface SellParams {
63
74
  collectionId: string;
@@ -84,8 +95,8 @@ declare class FlipmemeSDK {
84
95
  updateConfig(chainType: BlockchainType, config: EthereumConfig | SolanaConfig): void;
85
96
  createCollection(params: CollectionParams): Promise<CreateCollectionResponse>;
86
97
  getCollectionPda(): Promise<CollectionInfo>;
87
- buy(params: BuyParams): Promise<void>;
88
- flipSell(params: SellParams): Promise<void>;
98
+ buy(params: BuyParams): Promise<BuyResponse[]>;
99
+ flipSell(params: SellParams): Promise<SellResponse[]>;
89
100
  profileSell(data: ProfileSellParams): Promise<void>;
90
101
  buyCredit(params: BuyCreditParams): Promise<string>;
91
102
  /**For testing */
@@ -126,4 +137,4 @@ declare class FlipmemeSDK {
126
137
  getTransactionTest(signature: string): Promise<_solana_web3_js.VersionedTransactionResponse | null>;
127
138
  }
128
139
 
129
- export { BlockchainType, type BuyCreditParams, type BuyParams, type BuyResponse, type CollectionInfo, type CollectionParams, type CreateCollectionResponse, type EthereumConfig, FlipmemeSDK, type NFTTradingData, type ProfileSellParams, type ReserveToken, type SellParams, type SolanaConfig, isEthereumConfig, isSolanaConfig };
140
+ export { BlockchainType, type BuyCreditParams, type BuyParams, type BuyResponse, type CollectionInfo, type CollectionParams, type CreateCollectionResponse, type EthereumConfig, FlipmemeSDK, type NFTTradingData, type ProfileSellParams, type ReserveToken, type SellParams, type SellResponse, type SolanaConfig, isEthereumConfig, isSolanaConfig };
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 = {
@@ -1471,6 +1471,9 @@ var SOLANA_PUBKEYS = {
1471
1471
  EVENT_AUTHORITY_ID: new import_web3.PublicKey(SOLANA.EVENT_AUTHORITY_ID_STR),
1472
1472
  ADMIN_FOR_CREDIT_BUY: new import_web3.PublicKey(SOLANA.ADMIN_FOR_CREDIT_BUY_STR)
1473
1473
  };
1474
+ var SDK_SOLANA_CONFIG = {
1475
+ CHUNK_SIZE: 20
1476
+ };
1474
1477
 
1475
1478
  // src/solana/index.ts
1476
1479
  var import_web34 = require("@solana/web3.js");
@@ -1561,16 +1564,62 @@ var import_lodash = require("lodash");
1561
1564
  var import_decimal = __toESM(require("decimal.js"));
1562
1565
 
1563
1566
  // 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
- });
1567
+ var import_anchor = require("@coral-xyz/anchor");
1568
+ function analyzeBuyTransaction(program, transactionData) {
1569
+ var _a;
1570
+ let instructions = (_a = transactionData.meta) == null ? void 0 : _a.innerInstructions;
1571
+ let buyResponse = [];
1572
+ if (instructions) {
1573
+ for (const instruction of instructions) {
1574
+ for (const subInstruction of instruction.instructions) {
1575
+ let rawData = import_anchor.utils.bytes.bs58.decode(subInstruction.data);
1576
+ const base64Data = import_anchor.utils.bytes.base64.encode(rawData.subarray(8));
1577
+ let decodedData = program.coder.events.decode(base64Data);
1578
+ if ((decodedData == null ? void 0 : decodedData.name) === "mintEvent") {
1579
+ buyResponse.push({
1580
+ buyer: decodedData.data.buyer.toString(),
1581
+ collectionAddress: decodedData.data.collection.toString(),
1582
+ nftAddress: decodedData.data.nft.toString(),
1583
+ tokenId: decodedData.data.tokenId.toString(),
1584
+ tokenName: decodedData.data.name.toString(),
1585
+ tokenUri: decodedData.data.uri.toString(),
1586
+ price: decodedData.data.price.toString(),
1587
+ is_sold_out: decodedData.data.isSoldOut,
1588
+ totalSolAmount: decodedData.data.totalSol.toString(),
1589
+ timestamp: decodedData.data.timestamp.toString()
1590
+ });
1591
+ }
1592
+ }
1593
+ }
1594
+ }
1595
+ return buyResponse;
1596
+ }
1597
+ function analyzeSellTransaction(program, transactionData) {
1598
+ var _a;
1599
+ let instructions = (_a = transactionData.meta) == null ? void 0 : _a.innerInstructions;
1600
+ let sellResponse = [];
1601
+ if (instructions) {
1602
+ for (const instruction of instructions) {
1603
+ for (const subInstruction of instruction.instructions) {
1604
+ let rawData = import_anchor.utils.bytes.bs58.decode(subInstruction.data);
1605
+ const base64Data = import_anchor.utils.bytes.base64.encode(rawData.subarray(8));
1606
+ let decodedData = program.coder.events.decode(base64Data);
1607
+ if ((decodedData == null ? void 0 : decodedData.name) === "sellEvent") {
1608
+ sellResponse.push({
1609
+ seller: decodedData.data.seller.toString(),
1610
+ collectionAddress: decodedData.data.collection.toString(),
1611
+ nftAddress: decodedData.data.nft.toString(),
1612
+ tokenId: decodedData.data.tokenId.toString(),
1613
+ price: decodedData.data.price.toString(),
1614
+ totalSolAmount: decodedData.data.totalSol.toString(),
1615
+ timestamp: decodedData.data.timestamp.toString()
1616
+ });
1617
+ }
1618
+ }
1619
+ }
1620
+ }
1621
+ console.log("sellResponse", sellResponse);
1622
+ return sellResponse;
1574
1623
  }
1575
1624
 
1576
1625
  // src/solana/index.ts
@@ -1582,7 +1631,7 @@ var SolanaConnector = class {
1582
1631
  }
1583
1632
  setFlipmemeProgram() {
1584
1633
  return __async(this, null, function* () {
1585
- let program = new import_anchor.Program(flipmeme_default, this.config.provider);
1634
+ let program = new import_anchor2.Program(flipmeme_default, this.config.provider);
1586
1635
  this.program = program;
1587
1636
  });
1588
1637
  }
@@ -1691,11 +1740,19 @@ var SolanaConnector = class {
1691
1740
  if (!this.program) {
1692
1741
  throw new Error("Program not initialized");
1693
1742
  }
1694
- const { collectionId, collectionSymbol, creatorAddress, quantity, reserveToken } = params;
1743
+ const {
1744
+ collectionId,
1745
+ collectionSymbol,
1746
+ creatorAddress,
1747
+ quantity,
1748
+ reserveToken
1749
+ } = params;
1695
1750
  if (!reserveToken || ((_a = reserveToken.mintAndBuy) == null ? void 0 : _a.length) === 0 && ((_b = reserveToken.buy) == null ? void 0 : _b.length) === 0) {
1696
1751
  throw new Error("No available token to buy");
1697
1752
  }
1698
- const stateAccount = yield this.program.account.state.fetch(SOLANA_PUBKEYS.STATE_ID);
1753
+ const stateAccount = yield this.program.account.state.fetch(
1754
+ SOLANA_PUBKEYS.STATE_ID
1755
+ );
1699
1756
  const successTxns = [];
1700
1757
  const failedItems = [];
1701
1758
  const instructionsChunks = [];
@@ -1730,11 +1787,16 @@ var SolanaConnector = class {
1730
1787
  console.error("Failed to getMintAndBuyInstructions", { error });
1731
1788
  }
1732
1789
  }
1790
+ let buyResponse = [];
1733
1791
  for (const [instructions, items] of instructionsChunks) {
1734
1792
  try {
1735
1793
  const { signature, latestBlockhash } = yield this.sendTxn(instructions);
1736
1794
  successTxns.push({ items, signature });
1737
- (_g = params.notify) == null ? void 0 : _g.onSuccess(successTxns.map((txn) => txn.items).flat(), quantity, signature);
1795
+ (_g = params.notify) == null ? void 0 : _g.onSuccess(
1796
+ successTxns.map((txn) => txn.items).flat(),
1797
+ quantity,
1798
+ signature
1799
+ );
1738
1800
  const confirmResult = yield this.config.provider.connection.confirmTransaction({
1739
1801
  blockhash: latestBlockhash.blockhash,
1740
1802
  lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
@@ -1746,9 +1808,9 @@ var SolanaConnector = class {
1746
1808
  maxSupportedTransactionVersion: 0
1747
1809
  });
1748
1810
  if (transactionData) {
1749
- analyzeBuyTransaction(transactionData);
1811
+ let itemBuyResponse = yield analyzeBuyTransaction(this.program, transactionData);
1812
+ buyResponse.push(...itemBuyResponse);
1750
1813
  }
1751
- console.log("transactionData", transactionData);
1752
1814
  } catch (e) {
1753
1815
  failedItems.push(...items);
1754
1816
  (_h = params.notify) == null ? void 0 : _h.onFailed(failedItems, quantity);
@@ -1756,6 +1818,7 @@ var SolanaConnector = class {
1756
1818
  throw e;
1757
1819
  }
1758
1820
  }
1821
+ return buyResponse;
1759
1822
  });
1760
1823
  }
1761
1824
  //useFlip.ts
@@ -1780,11 +1843,30 @@ var SolanaConnector = class {
1780
1843
  }
1781
1844
  const successTxns = [];
1782
1845
  const failedItems = [];
1846
+ let sellResponse = [];
1783
1847
  for (const [instructions, items] of instructionsChunks) {
1784
1848
  try {
1785
- const { signature } = yield this.sendTxn(instructions);
1849
+ const { signature, latestBlockhash } = yield this.sendTxn(instructions);
1786
1850
  successTxns.push({ items, signature });
1787
- notify == null ? void 0 : notify.onSuccess(successTxns.map((txn) => txn.items).flat(), quantity, signature);
1851
+ notify == null ? void 0 : notify.onSuccess(
1852
+ successTxns.map((txn) => txn.items).flat(),
1853
+ quantity,
1854
+ signature
1855
+ );
1856
+ const confirmResult = yield this.config.provider.connection.confirmTransaction({
1857
+ blockhash: latestBlockhash.blockhash,
1858
+ lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
1859
+ signature
1860
+ });
1861
+ console.log("confirmResult", confirmResult);
1862
+ let transactionData = yield this.config.provider.connection.getTransaction(signature, {
1863
+ commitment: "confirmed",
1864
+ maxSupportedTransactionVersion: 0
1865
+ });
1866
+ if (transactionData) {
1867
+ let itemSellResponse = yield analyzeSellTransaction(this.program, transactionData);
1868
+ sellResponse.push(...itemSellResponse);
1869
+ }
1788
1870
  } catch (e) {
1789
1871
  failedItems.push(...items);
1790
1872
  notify == null ? void 0 : notify.onFailed(failedItems, quantity);
@@ -1792,6 +1874,7 @@ var SolanaConnector = class {
1792
1874
  throw e;
1793
1875
  }
1794
1876
  }
1877
+ return sellResponse;
1795
1878
  });
1796
1879
  }
1797
1880
  //useFlipProfile.ts
@@ -1821,7 +1904,11 @@ var SolanaConnector = class {
1821
1904
  try {
1822
1905
  const { signature } = yield this.sendTxn(instructions);
1823
1906
  successTxns.push({ items: items2, signature });
1824
- (_b = data.notify) == null ? void 0 : _b.onSuccess(successTxns.map((txn) => txn.items).flat(), items2.length, signature);
1907
+ (_b = data.notify) == null ? void 0 : _b.onSuccess(
1908
+ successTxns.map((txn) => txn.items).flat(),
1909
+ items2.length,
1910
+ signature
1911
+ );
1825
1912
  } catch (e) {
1826
1913
  failedItems.push(...items2);
1827
1914
  (_c = data.notify) == null ? void 0 : _c.onFailed(failedItems, items2.length);
@@ -1844,7 +1931,10 @@ var SolanaConnector = class {
1844
1931
  lamports: new import_decimal.default(params.amount).mul(10 ** 9).toNumber()
1845
1932
  })
1846
1933
  );
1847
- return yield this.config.sendTransaction(transaction, this.config.provider.connection);
1934
+ return yield this.config.sendTransaction(
1935
+ transaction,
1936
+ this.config.provider.connection
1937
+ );
1848
1938
  });
1849
1939
  }
1850
1940
  //for testing
@@ -1853,7 +1943,9 @@ var SolanaConnector = class {
1853
1943
  if (!this.program) {
1854
1944
  throw new Error("Program not initialized");
1855
1945
  }
1856
- const state = yield this.program.account.state.fetch(SOLANA_PUBKEYS.STATE_ID);
1946
+ const state = yield this.program.account.state.fetch(
1947
+ SOLANA_PUBKEYS.STATE_ID
1948
+ );
1857
1949
  return state;
1858
1950
  });
1859
1951
  }
@@ -1863,8 +1955,13 @@ var SolanaConnector = class {
1863
1955
  if (!this.program) {
1864
1956
  throw new Error("Program not initialized");
1865
1957
  }
1866
- const collectionAddress = yield collectionPda(collectionId, this.program.programId);
1867
- const collectionInfo = yield this.program.account.collection.fetch(collectionAddress);
1958
+ const collectionAddress = yield collectionPda(
1959
+ collectionId,
1960
+ this.program.programId
1961
+ );
1962
+ const collectionInfo = yield this.program.account.collection.fetch(
1963
+ collectionAddress
1964
+ );
1868
1965
  return { collectionInfo, collectionAddress };
1869
1966
  });
1870
1967
  }
@@ -1886,7 +1983,10 @@ var SolanaConnector = class {
1886
1983
  const tx = new import_web34.VersionedTransaction(messageV0);
1887
1984
  const sim = yield this.config.provider.connection.simulateTransaction(tx);
1888
1985
  console.log("simulation result == ", sim);
1889
- const signature = yield this.config.sendTransaction(tx, this.config.provider.connection);
1986
+ const signature = yield this.config.sendTransaction(
1987
+ tx,
1988
+ this.config.provider.connection
1989
+ );
1890
1990
  return {
1891
1991
  signature,
1892
1992
  latestBlockhash
@@ -1898,12 +1998,14 @@ var SolanaConnector = class {
1898
1998
  if (!this.program) {
1899
1999
  throw new Error("Program not initialized");
1900
2000
  }
1901
- const chunkSize = 1;
2001
+ const chunkSize = SDK_SOLANA_CONFIG.CHUNK_SIZE;
1902
2002
  const tokenChunks = getTokenChunks(tokens, chunkSize);
1903
2003
  const allInstructionSets = [];
1904
2004
  try {
1905
2005
  for (const chunk of tokenChunks) {
1906
- const instructions = yield this.setUpInstructions(25e4 * chunk.length);
2006
+ const instructions = yield this.setUpInstructions(
2007
+ 25e4 * chunk.length
2008
+ );
1907
2009
  for (const token of chunk) {
1908
2010
  const instruction = yield this.program.methods.buy(token.tokenId).accounts({
1909
2011
  state: SOLANA_PUBKEYS.STATE_ID,
@@ -1932,7 +2034,7 @@ var SolanaConnector = class {
1932
2034
  userPublicKey,
1933
2035
  this.program.programId
1934
2036
  );
1935
- const chunkSize = 1;
2037
+ const chunkSize = SDK_SOLANA_CONFIG.CHUNK_SIZE;
1936
2038
  const tokenChunks = getTokenChunks(tokens, chunkSize);
1937
2039
  const allInstructionSets = [];
1938
2040
  const state = yield this.program.account.state.fetch(
@@ -1940,7 +2042,9 @@ var SolanaConnector = class {
1940
2042
  );
1941
2043
  try {
1942
2044
  for (const chunk of tokenChunks) {
1943
- const instructions = yield this.setUpInstructions(25e4 * chunk.length);
2045
+ const instructions = yield this.setUpInstructions(
2046
+ 25e4 * chunk.length
2047
+ );
1944
2048
  for (const token of chunk) {
1945
2049
  const { nftHolderPda: nftHolderPda2, collectionPda: collectionPda2, nftPda: nftPda2 } = yield getNftAccounts(
1946
2050
  token.tokenId
@@ -1980,7 +2084,7 @@ var SolanaConnector = class {
1980
2084
  if (!this.program) {
1981
2085
  throw new Error("Program not initialized");
1982
2086
  }
1983
- const chunkSize = 1;
2087
+ const chunkSize = SDK_SOLANA_CONFIG.CHUNK_SIZE;
1984
2088
  const tokenChunks = getTokenChunks(tokens, chunkSize);
1985
2089
  const allInstructionSets = [];
1986
2090
  const { getNftAccounts } = yield getTradingAccounts(
@@ -1991,7 +2095,9 @@ var SolanaConnector = class {
1991
2095
  );
1992
2096
  try {
1993
2097
  for (const chunk of tokenChunks) {
1994
- const instructions = yield this.setUpInstructions(35e4 * chunk.length);
2098
+ const instructions = yield this.setUpInstructions(
2099
+ 35e4 * chunk.length
2100
+ );
1995
2101
  for (const token of chunk) {
1996
2102
  const { name, tokenURI, tokenId } = token;
1997
2103
  const { nftPda: nftPda2, collectionPda: collectionPda2, nftHolderPda: nftHolderPda2 } = yield getNftAccounts(
@@ -2031,7 +2137,10 @@ var SolanaConnector = class {
2031
2137
  return __async(this, null, function* () {
2032
2138
  const recentFees = yield this.config.provider.connection.getRecentPrioritizationFees();
2033
2139
  const MIN_FEE = 1e4;
2034
- const dynamicFee = Math.max(...recentFees.map((fee) => fee.prioritizationFee), MIN_FEE);
2140
+ const dynamicFee = Math.max(
2141
+ ...recentFees.map((fee) => fee.prioritizationFee),
2142
+ MIN_FEE
2143
+ );
2035
2144
  return dynamicFee;
2036
2145
  });
2037
2146
  }
@@ -2052,12 +2161,15 @@ var SolanaConnector = class {
2052
2161
  }
2053
2162
  getTransactionTest(signature) {
2054
2163
  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);
2164
+ const transaction = yield this.config.provider.connection.getTransaction(
2165
+ signature,
2166
+ {
2167
+ commitment: "confirmed",
2168
+ maxSupportedTransactionVersion: 0
2169
+ }
2170
+ );
2171
+ if (transaction && this.program) {
2172
+ analyzeBuyTransaction(this.program, transaction);
2061
2173
  }
2062
2174
  return transaction;
2063
2175
  });