flipmeme-sdk 1.0.5 → 1.0.7

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
@@ -1,6 +1,6 @@
1
1
  import { AnchorProvider } from '@coral-xyz/anchor';
2
- import { WalletContextState } from '@solana/wallet-adapter-react';
3
- import { PublicKey } from '@solana/web3.js';
2
+ import { SendTransactionOptions } from '@solana/wallet-adapter-base';
3
+ import { PublicKey, Transaction, VersionedTransaction, Connection, TransactionSignature } from '@solana/web3.js';
4
4
 
5
5
  declare enum BlockchainType {
6
6
  SOLANA = "solana",
@@ -17,7 +17,8 @@ interface EthereumConfig {
17
17
  }
18
18
  interface SolanaConfig {
19
19
  provider: AnchorProvider;
20
- solWallet: WalletContextState;
20
+ wallet: PublicKey;
21
+ sendTransaction: (transaction: Transaction | VersionedTransaction, connection: Connection, options?: SendTransactionOptions) => Promise<TransactionSignature>;
21
22
  }
22
23
  interface CollectionParams {
23
24
  name: string;
@@ -34,7 +35,6 @@ interface NFTTradingData {
34
35
  symbol?: string;
35
36
  }
36
37
  interface ReserveToken {
37
- tokenAddress: string;
38
38
  buy: NFTTradingData[] | null;
39
39
  mintAndBuy: NFTTradingData[] | null;
40
40
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AnchorProvider } from '@coral-xyz/anchor';
2
- import { WalletContextState } from '@solana/wallet-adapter-react';
3
- import { PublicKey } from '@solana/web3.js';
2
+ import { SendTransactionOptions } from '@solana/wallet-adapter-base';
3
+ import { PublicKey, Transaction, VersionedTransaction, Connection, TransactionSignature } from '@solana/web3.js';
4
4
 
5
5
  declare enum BlockchainType {
6
6
  SOLANA = "solana",
@@ -17,7 +17,8 @@ interface EthereumConfig {
17
17
  }
18
18
  interface SolanaConfig {
19
19
  provider: AnchorProvider;
20
- solWallet: WalletContextState;
20
+ wallet: PublicKey;
21
+ sendTransaction: (transaction: Transaction | VersionedTransaction, connection: Connection, options?: SendTransactionOptions) => Promise<TransactionSignature>;
21
22
  }
22
23
  interface CollectionParams {
23
24
  name: string;
@@ -34,7 +35,6 @@ interface NFTTradingData {
34
35
  symbol?: string;
35
36
  }
36
37
  interface ReserveToken {
37
- tokenAddress: string;
38
38
  buy: NFTTradingData[] | null;
39
39
  mintAndBuy: NFTTradingData[] | null;
40
40
  }
package/dist/index.js CHANGED
@@ -1469,7 +1469,7 @@ var SOLANA_PUBKEYS = {
1469
1469
  };
1470
1470
 
1471
1471
  // src/solana/index.ts
1472
- var import_web35 = require("@solana/web3.js");
1472
+ var import_web34 = require("@solana/web3.js");
1473
1473
  var import_bytes = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
1474
1474
  var import_spl_token2 = require("@solana/spl-token");
1475
1475
  var import_bn = require("bn.js");
@@ -1510,21 +1510,8 @@ var masterEditionPda = (mint) => import_web32.PublicKey.findProgramAddressSync(
1510
1510
  )[0];
1511
1511
 
1512
1512
  // src/solana/instructions.ts
1513
- var import_web34 = require("@solana/web3.js");
1514
- var import_spl_token = require("@solana/spl-token");
1515
-
1516
- // src/solana/solana.ts
1517
1513
  var import_web33 = require("@solana/web3.js");
1518
- var QUICKNODE_RPC_ENDPOINT = "https://cosmopolitan-snowy-lake.solana-devnet.quiknode.pro/c5ecc7d6128283ff515091ce2efae962928445f5";
1519
- var getPriorityFee = () => __async(void 0, null, function* () {
1520
- const solana = new import_web33.Connection(QUICKNODE_RPC_ENDPOINT, "processed");
1521
- const recentFees = yield solana.getRecentPrioritizationFees();
1522
- const MIN_FEE = 1e4;
1523
- const dynamicFee = Math.max(...recentFees.map((fee) => fee.prioritizationFee), MIN_FEE);
1524
- return dynamicFee;
1525
- });
1526
-
1527
- // src/solana/instructions.ts
1514
+ var import_spl_token = require("@solana/spl-token");
1528
1515
  var getTokenChunks = (items, chunkSize) => {
1529
1516
  const tokenChunks = [];
1530
1517
  for (let i = 0; i < items.length; i += chunkSize) {
@@ -1532,25 +1519,12 @@ var getTokenChunks = (items, chunkSize) => {
1532
1519
  }
1533
1520
  return tokenChunks;
1534
1521
  };
1535
- var setUpInstructions = (computeUnits) => __async(void 0, null, function* () {
1536
- const microLamports = yield getPriorityFee();
1537
- const instructions = [];
1538
- const modifyComputeUnits = import_web34.ComputeBudgetProgram.setComputeUnitLimit({
1539
- units: computeUnits
1540
- });
1541
- const addPriorityFee = import_web34.ComputeBudgetProgram.setComputeUnitPrice({
1542
- microLamports
1543
- // TODO: get value from Quicknote api
1544
- });
1545
- instructions.push(modifyComputeUnits, addPriorityFee);
1546
- return instructions;
1547
- });
1548
1522
  var getTradingAccounts = (collectionId, userPublicKey, programId, creatorAddress) => __async(void 0, null, function* () {
1549
1523
  const collectionIDBuffer = Buffer.from(collectionId, "base64");
1550
1524
  const collectionIDArray = Array.from(collectionIDBuffer);
1551
1525
  const collectionPda2 = collectionPda(collectionId, programId);
1552
1526
  const nftHolderPda2 = nftHolderPda(userPublicKey, programId);
1553
- const collectionCreator = creatorAddress && new import_web34.PublicKey(creatorAddress);
1527
+ const collectionCreator = creatorAddress && new import_web33.PublicKey(creatorAddress);
1554
1528
  const getNftAccounts = (tokenId) => __async(void 0, null, function* () {
1555
1529
  const nftPda2 = nftPda(collectionPda2, tokenId, programId);
1556
1530
  const nftHolderAta = yield (0, import_spl_token.getAssociatedTokenAddress)(nftPda2, nftHolderPda2, true);
@@ -1604,7 +1578,7 @@ var SolanaConnector = class {
1604
1578
  const state = yield this.program.account.state.fetch(
1605
1579
  SOLANA_PUBKEYS.STATE_ID
1606
1580
  );
1607
- const [collectionPda2] = import_web35.PublicKey.findProgramAddressSync(
1581
+ const [collectionPda2] = import_web34.PublicKey.findProgramAddressSync(
1608
1582
  [
1609
1583
  Buffer.from("collection"),
1610
1584
  SOLANA_PUBKEYS.STATE_ID.toBuffer(),
@@ -1628,7 +1602,7 @@ var SolanaConnector = class {
1628
1602
  SOLANA_PUBKEYS.STATE_ID
1629
1603
  );
1630
1604
  const collectionID = state.collectionCount;
1631
- const [collection] = import_web35.PublicKey.findProgramAddressSync(
1605
+ const [collection] = import_web34.PublicKey.findProgramAddressSync(
1632
1606
  [
1633
1607
  import_bytes.utf8.encode("collection"),
1634
1608
  SOLANA_PUBKEYS.STATE_ID.toBuffer(),
@@ -1636,11 +1610,11 @@ var SolanaConnector = class {
1636
1610
  ],
1637
1611
  this.program.programId
1638
1612
  );
1639
- const [collectionNftPda] = import_web35.PublicKey.findProgramAddressSync(
1613
+ const [collectionNftPda] = import_web34.PublicKey.findProgramAddressSync(
1640
1614
  [import_bytes.utf8.encode("collection_nft"), collection.toBuffer()],
1641
1615
  this.program.programId
1642
1616
  );
1643
- const [collectionMetadataPda] = import_web35.PublicKey.findProgramAddressSync(
1617
+ const [collectionMetadataPda] = import_web34.PublicKey.findProgramAddressSync(
1644
1618
  [
1645
1619
  Buffer.from("metadata"),
1646
1620
  SOLANA_PUBKEYS.TOKEN_METADATA_PROGRAM_ID.toBuffer(),
@@ -1648,7 +1622,7 @@ var SolanaConnector = class {
1648
1622
  ],
1649
1623
  SOLANA_PUBKEYS.TOKEN_METADATA_PROGRAM_ID
1650
1624
  );
1651
- const [masterEditionMetadata] = import_web35.PublicKey.findProgramAddressSync(
1625
+ const [masterEditionMetadata] = import_web34.PublicKey.findProgramAddressSync(
1652
1626
  [
1653
1627
  Buffer.from("metadata"),
1654
1628
  SOLANA_PUBKEYS.TOKEN_METADATA_PROGRAM_ID.toBuffer(),
@@ -1674,28 +1648,28 @@ var SolanaConnector = class {
1674
1648
  //@ts-ignore
1675
1649
  collection,
1676
1650
  collection_nft: collectionNftPda,
1677
- creator: this.config.solWallet.publicKey,
1651
+ creator: this.config.wallet,
1678
1652
  mpl_core: SOLANA.MPL_CORE_STR,
1679
- system_program: import_web35.SystemProgram.programId
1653
+ system_program: import_web34.SystemProgram.programId
1680
1654
  }).instruction();
1681
- const modifyComputeUnits = import_web35.ComputeBudgetProgram.setComputeUnitLimit({
1655
+ const modifyComputeUnits = import_web34.ComputeBudgetProgram.setComputeUnitLimit({
1682
1656
  units: 35e4
1683
1657
  });
1684
- const addPriorityFee = import_web35.ComputeBudgetProgram.setComputeUnitPrice({
1658
+ const addPriorityFee = import_web34.ComputeBudgetProgram.setComputeUnitPrice({
1685
1659
  microLamports: 1e4
1686
1660
  });
1687
1661
  const blockHash = (yield this.config.provider.connection.getLatestBlockhash()).blockhash;
1688
- const messageV0 = new import_web35.TransactionMessage({
1689
- payerKey: this.config.solWallet.publicKey,
1662
+ const messageV0 = new import_web34.TransactionMessage({
1663
+ payerKey: this.config.wallet,
1690
1664
  recentBlockhash: blockHash,
1691
1665
  instructions: [instruction]
1692
1666
  }).compileToV0Message();
1693
- const versionedTransaction = new import_web35.VersionedTransaction(messageV0);
1667
+ const versionedTransaction = new import_web34.VersionedTransaction(messageV0);
1694
1668
  const result = yield this.config.provider.connection.simulateTransaction(
1695
1669
  versionedTransaction
1696
1670
  );
1697
- const tx = new import_web35.Transaction().add(modifyComputeUnits).add(addPriorityFee).add(instruction);
1698
- const txHash = yield this.config.solWallet.sendTransaction(
1671
+ const tx = new import_web34.Transaction().add(modifyComputeUnits).add(addPriorityFee).add(instruction);
1672
+ const txHash = yield this.config.sendTransaction(
1699
1673
  tx,
1700
1674
  this.config.provider.connection
1701
1675
  );
@@ -1710,7 +1684,7 @@ var SolanaConnector = class {
1710
1684
  throw new Error("Program not initialized");
1711
1685
  }
1712
1686
  const { collectionId, collectionSymbol, creatorAddress, quantity, reserveToken } = params;
1713
- if (!reserveToken || ((_a = reserveToken.mintAndBuy) == null ? void 0 : _a.length) === 0 || ((_b = reserveToken.buy) == null ? void 0 : _b.length) === 0) {
1687
+ if (!reserveToken || ((_a = reserveToken.mintAndBuy) == null ? void 0 : _a.length) === 0 && ((_b = reserveToken.buy) == null ? void 0 : _b.length) === 0) {
1714
1688
  throw new Error("No available token to buy");
1715
1689
  }
1716
1690
  const stateAccount = yield this.program.account.state.fetch(SOLANA_PUBKEYS.STATE_ID);
@@ -1720,7 +1694,7 @@ var SolanaConnector = class {
1720
1694
  if ((_c = reserveToken.buy) == null ? void 0 : _c.length) {
1721
1695
  try {
1722
1696
  const buyInstructionsChunks = yield this.getBuyInstructions(
1723
- this.config.solWallet.publicKey,
1697
+ this.config.wallet,
1724
1698
  collectionId,
1725
1699
  reserveToken.buy
1726
1700
  );
@@ -1734,7 +1708,7 @@ var SolanaConnector = class {
1734
1708
  if ((_e = reserveToken.mintAndBuy) == null ? void 0 : _e.length) {
1735
1709
  try {
1736
1710
  const mintAndBuyInstructionsChunks = yield this.getMintAndBuyInstructions(
1737
- this.config.solWallet.publicKey,
1711
+ this.config.wallet,
1738
1712
  collectionId,
1739
1713
  collectionSymbol,
1740
1714
  creatorAddress,
@@ -1773,7 +1747,7 @@ var SolanaConnector = class {
1773
1747
  const sellTokens = (0, import_lodash.sampleSize)(ownedTokens, quantity);
1774
1748
  try {
1775
1749
  instructionsChunks = yield this.getSellInstructions(
1776
- this.config.solWallet.publicKey,
1750
+ this.config.wallet,
1777
1751
  collectionId,
1778
1752
  sellTokens
1779
1753
  );
@@ -1810,7 +1784,7 @@ var SolanaConnector = class {
1810
1784
  try {
1811
1785
  console.log("items", items);
1812
1786
  instructionsChunks = yield this.getSellInstructions(
1813
- this.config.solWallet.publicKey,
1787
+ this.config.wallet,
1814
1788
  collectionId,
1815
1789
  items
1816
1790
  );
@@ -1841,14 +1815,14 @@ var SolanaConnector = class {
1841
1815
  if (!this.program) {
1842
1816
  throw new Error("Program not initialized");
1843
1817
  }
1844
- const transaction = new import_web35.Transaction().add(
1845
- import_web35.SystemProgram.transfer({
1818
+ const transaction = new import_web34.Transaction().add(
1819
+ import_web34.SystemProgram.transfer({
1846
1820
  fromPubkey: params.adminPubKey,
1847
1821
  toPubkey: SOLANA_PUBKEYS.ADMIN_FOR_CREDIT_BUY,
1848
1822
  lamports: new import_decimal.default(params.amount).mul(10 ** 9).toNumber()
1849
1823
  })
1850
1824
  );
1851
- return yield this.config.solWallet.sendTransaction(transaction, this.config.provider.connection);
1825
+ return yield this.config.sendTransaction(transaction, this.config.provider.connection);
1852
1826
  });
1853
1827
  }
1854
1828
  //useSenTxn.ts
@@ -1858,18 +1832,17 @@ var SolanaConnector = class {
1858
1832
  console.error("Trade NFT failed: Insufficient data");
1859
1833
  throw new Error("Trade NFT failed: Insufficient data");
1860
1834
  }
1861
- const transaction = new import_web35.Transaction();
1835
+ const transaction = new import_web34.Transaction();
1862
1836
  instructions.forEach((inx) => transaction.add(inx));
1863
1837
  const { blockhash } = yield this.config.provider.connection.getLatestBlockhash("confirmed");
1864
- const messageV0 = new import_web35.TransactionMessage({
1865
- payerKey: this.config.solWallet.publicKey,
1838
+ const messageV0 = new import_web34.TransactionMessage({
1839
+ payerKey: this.config.wallet,
1866
1840
  recentBlockhash: blockhash,
1867
1841
  instructions
1868
1842
  }).compileToV0Message([]);
1869
- const tx = new import_web35.VersionedTransaction(messageV0);
1843
+ const tx = new import_web34.VersionedTransaction(messageV0);
1870
1844
  const sim = yield this.config.provider.connection.simulateTransaction(tx);
1871
- console.log(sim, "SS");
1872
- return yield this.config.solWallet.sendTransaction(tx, this.config.provider.connection);
1845
+ return yield this.config.sendTransaction(tx, this.config.provider.connection);
1873
1846
  });
1874
1847
  }
1875
1848
  getBuyInstructions(userPublicKey, collectionId, tokens) {
@@ -1882,7 +1855,7 @@ var SolanaConnector = class {
1882
1855
  const allInstructionSets = [];
1883
1856
  try {
1884
1857
  for (const chunk of tokenChunks) {
1885
- const instructions = yield setUpInstructions(25e4 * chunk.length);
1858
+ const instructions = yield this.setUpInstructions(25e4 * chunk.length);
1886
1859
  for (const token of chunk) {
1887
1860
  const instruction = yield this.program.methods.buy(token.tokenId).accounts({
1888
1861
  state: SOLANA_PUBKEYS.STATE_ID,
@@ -1919,7 +1892,7 @@ var SolanaConnector = class {
1919
1892
  );
1920
1893
  try {
1921
1894
  for (const chunk of tokenChunks) {
1922
- const instructions = yield setUpInstructions(25e4 * chunk.length);
1895
+ const instructions = yield this.setUpInstructions(25e4 * chunk.length);
1923
1896
  for (const token of chunk) {
1924
1897
  const { nftHolderPda: nftHolderPda2, collectionPda: collectionPda2, nftPda: nftPda2 } = yield getNftAccounts(
1925
1898
  token.tokenId
@@ -1934,11 +1907,11 @@ var SolanaConnector = class {
1934
1907
  mplCore: SOLANA.MPL_CORE_STR,
1935
1908
  nft: nftPda2,
1936
1909
  nftHolder: nftHolderPda2,
1937
- systemProgram: import_web35.SystemProgram.programId,
1938
- collectionNft: import_web35.PublicKey.findProgramAddressSync(
1910
+ systemProgram: import_web34.SystemProgram.programId,
1911
+ collectionNft: import_web34.PublicKey.findProgramAddressSync(
1939
1912
  [
1940
1913
  Buffer.from("collection_nft"),
1941
- new import_web35.PublicKey(collectionPda2).toBuffer()
1914
+ new import_web34.PublicKey(collectionPda2).toBuffer()
1942
1915
  ],
1943
1916
  this.program.programId
1944
1917
  )[0]
@@ -1970,7 +1943,7 @@ var SolanaConnector = class {
1970
1943
  );
1971
1944
  try {
1972
1945
  for (const chunk of tokenChunks) {
1973
- const instructions = yield setUpInstructions(35e4 * chunk.length);
1946
+ const instructions = yield this.setUpInstructions(35e4 * chunk.length);
1974
1947
  for (const token of chunk) {
1975
1948
  const { name, tokenURI, tokenId } = token;
1976
1949
  const { nftPda: nftPda2, collectionPda: collectionPda2, nftHolderPda: nftHolderPda2 } = yield getNftAccounts(
@@ -1982,14 +1955,14 @@ var SolanaConnector = class {
1982
1955
  buyer: userPublicKey,
1983
1956
  program: this.program.programId,
1984
1957
  mplCore: SOLANA.MPL_CORE_STR,
1985
- systemProgram: import_web35.SystemProgram.programId,
1958
+ systemProgram: import_web34.SystemProgram.programId,
1986
1959
  nft: nftPda2,
1987
1960
  nftHolder: nftHolderPda2,
1988
1961
  collection: collectionPda2,
1989
- collectionNft: import_web35.PublicKey.findProgramAddressSync(
1962
+ collectionNft: import_web34.PublicKey.findProgramAddressSync(
1990
1963
  [
1991
1964
  Buffer.from("collection_nft"),
1992
- new import_web35.PublicKey(collectionPda2).toBuffer()
1965
+ new import_web34.PublicKey(collectionPda2).toBuffer()
1993
1966
  ],
1994
1967
  this.program.programId
1995
1968
  )[0],
@@ -2006,6 +1979,29 @@ var SolanaConnector = class {
2006
1979
  }
2007
1980
  });
2008
1981
  }
1982
+ getPriorityFee() {
1983
+ return __async(this, null, function* () {
1984
+ const recentFees = yield this.config.provider.connection.getRecentPrioritizationFees();
1985
+ const MIN_FEE = 1e4;
1986
+ const dynamicFee = Math.max(...recentFees.map((fee) => fee.prioritizationFee), MIN_FEE);
1987
+ return dynamicFee;
1988
+ });
1989
+ }
1990
+ setUpInstructions(computeUnits) {
1991
+ return __async(this, null, function* () {
1992
+ const microLamports = yield this.getPriorityFee();
1993
+ const instructions = [];
1994
+ const modifyComputeUnits = import_web34.ComputeBudgetProgram.setComputeUnitLimit({
1995
+ units: computeUnits
1996
+ });
1997
+ const addPriorityFee = import_web34.ComputeBudgetProgram.setComputeUnitPrice({
1998
+ microLamports
1999
+ // TODO: get value from Quicknote api
2000
+ });
2001
+ instructions.push(modifyComputeUnits, addPriorityFee);
2002
+ return instructions;
2003
+ });
2004
+ }
2009
2005
  };
2010
2006
 
2011
2007
  // src/types.ts
@@ -2018,7 +2014,7 @@ function isEthereumConfig(config) {
2018
2014
  return "chainId" in config;
2019
2015
  }
2020
2016
  function isSolanaConfig(config) {
2021
- return "solWallet" in config;
2017
+ return "sendTransaction" in config;
2022
2018
  }
2023
2019
 
2024
2020
  // src/main_sdk.ts