flipmeme-sdk 1.1.5 → 1.1.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
@@ -100,6 +100,10 @@ interface BuyCreditParams {
100
100
  adminPubKey: PublicKey;
101
101
  amount: number;
102
102
  }
103
+ declare enum PurcahseTye {
104
+ BUY = "buy",
105
+ SELL = "sell"
106
+ }
103
107
 
104
108
  declare class FlipmemeSDK {
105
109
  private blockchainType;
@@ -113,6 +117,7 @@ declare class FlipmemeSDK {
113
117
  flipSell(params: SellParams): Promise<SellResponse[]>;
114
118
  profileSell(data: ProfileSellParams): Promise<SellResponse[]>;
115
119
  buyCredit(params: BuyCreditParams): Promise<string>;
120
+ getTotalPrice(type: PurcahseTye, collectionId: string, amount: number): Promise<string>;
116
121
  /**For testing */
117
122
  getStateInfo(): Promise<{
118
123
  admin: _solana_web3_js.PublicKey;
@@ -135,6 +140,7 @@ declare class FlipmemeSDK {
135
140
  };
136
141
  creator: _solana_web3_js.PublicKey;
137
142
  totalSol: bn_js;
143
+ totalSupply: number;
138
144
  mintCount: number;
139
145
  id: number;
140
146
  sellerFeeBasisPoints: number;
@@ -149,4 +155,4 @@ declare class FlipmemeSDK {
149
155
  getTransactionTest(signature: string): Promise<BuyResponse[]>;
150
156
  }
151
157
 
152
- export { BlockchainType, type BuyCreditParams, type BuyParams, type BuyResponse, type CollectionInfo, type CollectionParams, type CreateCollectionResponse, type EthereumConfig, FlipmemeSDK, type NFTMintData, type NFTTradingData, type ProfileSellParams, type ReserveToken, type SellParams, type SellResponse, type SolanaConfig, isEthereumConfig, isSolanaConfig };
158
+ export { BlockchainType, type BuyCreditParams, type BuyParams, type BuyResponse, type CollectionInfo, type CollectionParams, type CreateCollectionResponse, type EthereumConfig, FlipmemeSDK, type NFTMintData, type NFTTradingData, type ProfileSellParams, PurcahseTye, type ReserveToken, type SellParams, type SellResponse, type SolanaConfig, isEthereumConfig, isSolanaConfig };
package/dist/index.d.ts CHANGED
@@ -100,6 +100,10 @@ interface BuyCreditParams {
100
100
  adminPubKey: PublicKey;
101
101
  amount: number;
102
102
  }
103
+ declare enum PurcahseTye {
104
+ BUY = "buy",
105
+ SELL = "sell"
106
+ }
103
107
 
104
108
  declare class FlipmemeSDK {
105
109
  private blockchainType;
@@ -113,6 +117,7 @@ declare class FlipmemeSDK {
113
117
  flipSell(params: SellParams): Promise<SellResponse[]>;
114
118
  profileSell(data: ProfileSellParams): Promise<SellResponse[]>;
115
119
  buyCredit(params: BuyCreditParams): Promise<string>;
120
+ getTotalPrice(type: PurcahseTye, collectionId: string, amount: number): Promise<string>;
116
121
  /**For testing */
117
122
  getStateInfo(): Promise<{
118
123
  admin: _solana_web3_js.PublicKey;
@@ -135,6 +140,7 @@ declare class FlipmemeSDK {
135
140
  };
136
141
  creator: _solana_web3_js.PublicKey;
137
142
  totalSol: bn_js;
143
+ totalSupply: number;
138
144
  mintCount: number;
139
145
  id: number;
140
146
  sellerFeeBasisPoints: number;
@@ -149,4 +155,4 @@ declare class FlipmemeSDK {
149
155
  getTransactionTest(signature: string): Promise<BuyResponse[]>;
150
156
  }
151
157
 
152
- export { BlockchainType, type BuyCreditParams, type BuyParams, type BuyResponse, type CollectionInfo, type CollectionParams, type CreateCollectionResponse, type EthereumConfig, FlipmemeSDK, type NFTMintData, type NFTTradingData, type ProfileSellParams, type ReserveToken, type SellParams, type SellResponse, type SolanaConfig, isEthereumConfig, isSolanaConfig };
158
+ export { BlockchainType, type BuyCreditParams, type BuyParams, type BuyResponse, type CollectionInfo, type CollectionParams, type CreateCollectionResponse, type EthereumConfig, FlipmemeSDK, type NFTMintData, type NFTTradingData, type ProfileSellParams, PurcahseTye, type ReserveToken, type SellParams, type SellResponse, type SolanaConfig, isEthereumConfig, isSolanaConfig };
package/dist/index.js CHANGED
@@ -52,6 +52,7 @@ var index_exports = {};
52
52
  __export(index_exports, {
53
53
  BlockchainType: () => BlockchainType,
54
54
  FlipmemeSDK: () => FlipmemeSDK,
55
+ PurcahseTye: () => PurcahseTye,
55
56
  isEthereumConfig: () => isEthereumConfig,
56
57
  isSolanaConfig: () => isSolanaConfig
57
58
  });
@@ -75,6 +76,24 @@ var EthereumConnector = class {
75
76
  // src/solana/index.ts
76
77
  var import_anchor2 = require("@coral-xyz/anchor");
77
78
 
79
+ // src/types.ts
80
+ var BlockchainType = /* @__PURE__ */ ((BlockchainType2) => {
81
+ BlockchainType2["SOLANA"] = "solana";
82
+ BlockchainType2["ETHEREUM"] = "ethereum";
83
+ return BlockchainType2;
84
+ })(BlockchainType || {});
85
+ function isEthereumConfig(config) {
86
+ return "chainId" in config;
87
+ }
88
+ function isSolanaConfig(config) {
89
+ return "sendTransaction" in config;
90
+ }
91
+ var PurcahseTye = /* @__PURE__ */ ((PurcahseTye3) => {
92
+ PurcahseTye3["BUY"] = "buy";
93
+ PurcahseTye3["SELL"] = "sell";
94
+ return PurcahseTye3;
95
+ })(PurcahseTye || {});
96
+
78
97
  // src/solana/idls/flipmeme.json
79
98
  var flipmeme_default = {
80
99
  address: "2KHXGcVHjnuEqw7ZrwPBXdPzrG4bWY24QPAvhRmQ1s8c",
@@ -1862,7 +1881,7 @@ var flipmeme_default = {
1862
1881
  // src/constants.ts
1863
1882
  var import_web3 = require("@solana/web3.js");
1864
1883
  var SOLANA = {
1865
- STATE_ID_STR: "CqkvxguJFFM5YE2pn6AqAGJ4snKL5oeUtJ4UjVLKo5Ew",
1884
+ STATE_ID_STR: "ruGm7D1K36pLZpQkwLEhqBP7bkSkK9wiLQfCkUJobve",
1866
1885
  TREASURY_ID_STR: "5VmcDuGTMMxFfcZB1W7AsARSbcswvM2wq7NENqaRV9eu",
1867
1886
  LP_PROVISIONER_ID_STR: "5VmcDuGTMMxFfcZB1W7AsARSbcswvM2wq7NENqaRV9eu",
1868
1887
  TOKEN_METADATA_PROGRAM_ID_STR: "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s",
@@ -1990,10 +2009,11 @@ var getTradingAccounts = (collectionId, userPublicKey, programId, creatorAddress
1990
2009
 
1991
2010
  // src/solana/index.ts
1992
2011
  var import_lodash = require("lodash");
1993
- var import_decimal = __toESM(require("decimal.js"));
2012
+ var import_decimal2 = __toESM(require("decimal.js"));
1994
2013
 
1995
2014
  // src/solana/analyze.ts
1996
2015
  var import_anchor = require("@coral-xyz/anchor");
2016
+ var import_decimal = require("decimal.js");
1997
2017
  function analyzeBuyTransaction(program, transactionData) {
1998
2018
  var _a;
1999
2019
  console.log("transactionData===", transactionData);
@@ -2081,6 +2101,25 @@ function analyzeSellTransaction(program, transactionData) {
2081
2101
  console.log("sellResponse", sellResponse);
2082
2102
  return sellResponse;
2083
2103
  }
2104
+ function getPrice(_mintCount, _nftCount, _steepness, _midPoint, _startPrice, _endPrice) {
2105
+ try {
2106
+ const n = new import_decimal.Decimal(_mintCount).minus(_nftCount);
2107
+ const steepness = new import_decimal.Decimal(_steepness);
2108
+ const midPoint = new import_decimal.Decimal(_midPoint);
2109
+ const startSubEnd = new import_decimal.Decimal(_endPrice).minus(_startPrice);
2110
+ const a = new import_decimal.Decimal(1).plus(
2111
+ steepness.mul(-1).mul(n.minus(midPoint)).exp()
2112
+ );
2113
+ const b = new import_decimal.Decimal(1).plus(
2114
+ steepness.mul(-1).mul(midPoint.mul(-1)).exp()
2115
+ );
2116
+ const startPrice = new import_decimal.Decimal(_startPrice);
2117
+ const price = startPrice.plus(startSubEnd.div(a)).minus(startSubEnd.div(b));
2118
+ return price;
2119
+ } catch (error) {
2120
+ throw new Error(`Price calculation failed: ${error}`);
2121
+ }
2122
+ }
2084
2123
 
2085
2124
  // src/solana/index.ts
2086
2125
  var SolanaConnector = class {
@@ -2421,7 +2460,7 @@ var SolanaConnector = class {
2421
2460
  import_web34.SystemProgram.transfer({
2422
2461
  fromPubkey: params.adminPubKey,
2423
2462
  toPubkey: SOLANA_PUBKEYS.ADMIN_FOR_CREDIT_BUY,
2424
- lamports: new import_decimal.default(params.amount).mul(10 ** 9).toNumber()
2463
+ lamports: new import_decimal2.default(params.amount).mul(10 ** 9).toNumber()
2425
2464
  })
2426
2465
  );
2427
2466
  return yield this.config.sendTransaction(
@@ -2445,6 +2484,77 @@ var SolanaConnector = class {
2445
2484
  return { collectionInfo, collectionAddress };
2446
2485
  });
2447
2486
  }
2487
+ getTotalPrice(type, collectionId, amount) {
2488
+ return __async(this, null, function* () {
2489
+ const collectionInfo = yield this.getCollectionInfo(collectionId);
2490
+ const {
2491
+ collectionInfo: {
2492
+ pool: { startPrice, endPrice, nftCount, steepness, midPoint },
2493
+ mintCount,
2494
+ totalSupply
2495
+ }
2496
+ } = collectionInfo;
2497
+ let startPriceStr = startPrice.toString();
2498
+ let endPriceStr = endPrice.toString();
2499
+ let expectedMintCount = mintCount;
2500
+ let expectedNftCount = nftCount;
2501
+ let totalPrice = new import_decimal2.default(0);
2502
+ if (type === "buy" /* BUY */) {
2503
+ let mintingCount = 0;
2504
+ let buyingCount = 0;
2505
+ if (nftCount < amount) {
2506
+ mintingCount = amount - nftCount;
2507
+ buyingCount = nftCount;
2508
+ if (mintingCount > totalSupply - mintCount) {
2509
+ mintingCount = totalSupply - mintCount;
2510
+ }
2511
+ } else {
2512
+ buyingCount = amount;
2513
+ }
2514
+ for (let i = 0; i < mintingCount; i++) {
2515
+ expectedMintCount++;
2516
+ totalPrice = totalPrice.plus(
2517
+ getPrice(
2518
+ expectedMintCount,
2519
+ expectedNftCount,
2520
+ steepness,
2521
+ midPoint,
2522
+ startPriceStr,
2523
+ endPriceStr
2524
+ )
2525
+ );
2526
+ }
2527
+ for (let i = 0; i < buyingCount; i++) {
2528
+ expectedNftCount = Math.max(expectedNftCount - 1, 0);
2529
+ totalPrice = totalPrice.plus(
2530
+ getPrice(
2531
+ expectedMintCount,
2532
+ expectedNftCount,
2533
+ steepness,
2534
+ midPoint,
2535
+ startPriceStr,
2536
+ endPriceStr
2537
+ )
2538
+ );
2539
+ }
2540
+ } else if (type === "sell" /* SELL */) {
2541
+ for (let i = 0; i < amount; i++) {
2542
+ expectedNftCount++;
2543
+ totalPrice = totalPrice.minus(
2544
+ getPrice(
2545
+ expectedMintCount,
2546
+ expectedNftCount,
2547
+ steepness,
2548
+ midPoint,
2549
+ startPriceStr,
2550
+ endPriceStr
2551
+ )
2552
+ );
2553
+ }
2554
+ }
2555
+ return totalPrice.toString();
2556
+ });
2557
+ }
2448
2558
  //for testing
2449
2559
  getStateInfo() {
2450
2560
  return __async(this, null, function* () {
@@ -2674,19 +2784,6 @@ var SolanaConnector = class {
2674
2784
  }
2675
2785
  };
2676
2786
 
2677
- // src/types.ts
2678
- var BlockchainType = /* @__PURE__ */ ((BlockchainType2) => {
2679
- BlockchainType2["SOLANA"] = "solana";
2680
- BlockchainType2["ETHEREUM"] = "ethereum";
2681
- return BlockchainType2;
2682
- })(BlockchainType || {});
2683
- function isEthereumConfig(config) {
2684
- return "chainId" in config;
2685
- }
2686
- function isSolanaConfig(config) {
2687
- return "sendTransaction" in config;
2688
- }
2689
-
2690
2787
  // src/main_sdk.ts
2691
2788
  var FlipmemeSDK = class {
2692
2789
  constructor(chainType, config) {
@@ -2767,6 +2864,15 @@ var FlipmemeSDK = class {
2767
2864
  }
2768
2865
  });
2769
2866
  }
2867
+ getTotalPrice(type, collectionId, amount) {
2868
+ return __async(this, null, function* () {
2869
+ if (this.blockchainType === "solana" /* SOLANA */ && this.solana) {
2870
+ return yield this.solana.getTotalPrice(type, collectionId, amount);
2871
+ } else {
2872
+ throw new Error("Cannot call this function");
2873
+ }
2874
+ });
2875
+ }
2770
2876
  /**For testing */
2771
2877
  getStateInfo() {
2772
2878
  return __async(this, null, function* () {
@@ -2801,6 +2907,7 @@ var FlipmemeSDK = class {
2801
2907
  0 && (module.exports = {
2802
2908
  BlockchainType,
2803
2909
  FlipmemeSDK,
2910
+ PurcahseTye,
2804
2911
  isEthereumConfig,
2805
2912
  isSolanaConfig
2806
2913
  });