flipmeme-sdk 1.3.61 → 1.3.63

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
@@ -448,6 +448,7 @@ declare class FlipmemeSDK {
448
448
  lastValidBlockHeight: number;
449
449
  }>;
450
450
  }>;
451
+ getTotalPrice(type: PurcahseType, collectionId: string, amount: number): Promise<string>;
451
452
  /**
452
453
  * create lookup table account with lookuptable addresses and return lookup table account
453
454
  * @param lookupTableAddresses addresses to add lookup table
package/dist/index.d.ts CHANGED
@@ -448,6 +448,7 @@ declare class FlipmemeSDK {
448
448
  lastValidBlockHeight: number;
449
449
  }>;
450
450
  }>;
451
+ getTotalPrice(type: PurcahseType, collectionId: string, amount: number): Promise<string>;
451
452
  /**
452
453
  * create lookup table account with lookuptable addresses and return lookup table account
453
454
  * @param lookupTableAddresses addresses to add lookup table
package/dist/index.js CHANGED
@@ -97,7 +97,7 @@ module.exports = __toCommonJS(index_exports);
97
97
  var import_web35 = require("@solana/web3.js");
98
98
 
99
99
  // src/evm/index.ts
100
- var import_decimal2 = __toESM(require("decimal.js"));
100
+ var import_decimal = __toESM(require("decimal.js"));
101
101
 
102
102
  // src/constants.ts
103
103
  var import_web3 = require("@solana/web3.js");
@@ -31011,55 +31011,6 @@ UUPSUpgradeable__factory.abi = _abi54;
31011
31011
  // src/evm/index.ts
31012
31012
  var import_ethers55 = require("ethers");
31013
31013
 
31014
- // src/utility.ts
31015
- var import_bytes = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
31016
- var crypto = __toESM(require("crypto"));
31017
- var import_decimal = __toESM(require("decimal.js"));
31018
- function splitEncryptedText(encryptedText) {
31019
- return {
31020
- ivString: encryptedText.slice(0, 32),
31021
- encryptedDataString: encryptedText.slice(32)
31022
- };
31023
- }
31024
- function decodeStr(str) {
31025
- const { encryptedDataString, ivString } = splitEncryptedText(str);
31026
- const encoding = "hex";
31027
- try {
31028
- const iv = Buffer.from(ivString, encoding);
31029
- const encryptedText = Buffer.from(encryptedDataString, encoding);
31030
- const decipher = crypto.createDecipheriv(
31031
- "aes-256-cbc",
31032
- import_bytes.bs58.decode("Dr1vQSrALU4KbiP6eDsYQCvneb7tY3QmrUCj2GNFQNUC"),
31033
- iv
31034
- );
31035
- const decrypted = decipher.update(encryptedText);
31036
- return Buffer.concat([decrypted, decipher.final()]).toString();
31037
- } catch (e) {
31038
- console.error(e);
31039
- throw new Error("wrong message");
31040
- }
31041
- }
31042
- function getPrice(_mintCount, _nftCount, _steepness, _midPoint, _startPrice, _endPrice) {
31043
- try {
31044
- const n = new import_decimal.default(_mintCount).minus(_nftCount);
31045
- const steepness = new import_decimal.default(_steepness).div(1e18);
31046
- const midPoint = new import_decimal.default(_midPoint).div(1e18);
31047
- const startSubEnd = new import_decimal.default(_endPrice).minus(_startPrice);
31048
- const a = new import_decimal.default(1).plus(
31049
- Math.exp(Number(steepness.mul(-1).mul(n.minus(midPoint)).toString()))
31050
- ).floor();
31051
- const b = new import_decimal.default(1).plus(
31052
- Math.exp(Number(steepness.mul(midPoint).toString()))
31053
- ).floor();
31054
- const startPrice = new import_decimal.default(_startPrice);
31055
- const price = startPrice.plus(startSubEnd.div(a)).minus(startSubEnd.div(b).floor()).floor();
31056
- console.log("price in getPrice function", price);
31057
- return price;
31058
- } catch (error) {
31059
- throw new Error(`Price calculation failed: ${error}`);
31060
- }
31061
- }
31062
-
31063
31014
  // src/evm/analyze.ts
31064
31015
  function analyzeBuyTransaction(receipt, collectionAddress) {
31065
31016
  const buyResponse = [];
@@ -31182,8 +31133,8 @@ var EthereumConnector = class {
31182
31133
  createCollection(collection) {
31183
31134
  return __async(this, null, function* () {
31184
31135
  var _a;
31185
- const startPrice = collection.startPrice || new import_decimal2.default(10).pow(15).floor().toFixed();
31186
- const endPrice = collection.endPrice || new import_decimal2.default(10).pow(16).floor().toFixed();
31136
+ const startPrice = collection.startPrice || new import_decimal.default(10).pow(15).floor().toFixed();
31137
+ const endPrice = collection.endPrice || new import_decimal.default(10).pow(16).floor().toFixed();
31187
31138
  let tx = yield this.factory.createCollection(
31188
31139
  collection.name,
31189
31140
  collection.symbol,
@@ -31292,15 +31243,54 @@ var EthereumConnector = class {
31292
31243
  return yield collection.getLiquidityPool();
31293
31244
  });
31294
31245
  }
31295
- // public async getTotalPrice(
31246
+ getTotalPrice(type, collectionAddr, amount) {
31247
+ return __async(this, null, function* () {
31248
+ let collection = Collection__factory.connect(
31249
+ collectionAddr,
31250
+ this.config.provider
31251
+ );
31252
+ let [
31253
+ currPrice,
31254
+ startPrice,
31255
+ endPrice,
31256
+ nftCount,
31257
+ steepness,
31258
+ midPoint,
31259
+ isMoved
31260
+ ] = yield collection.getLiquidityPool();
31261
+ let info = yield collection.getCollectionInfo();
31262
+ let mintCount = info[4];
31263
+ let totalSupply = info[3];
31264
+ let totalPrice = import_ethers55.BigNumber.from(0);
31265
+ if (type === "buy" /* BUY */) {
31266
+ let mintingCount = import_ethers55.BigNumber.from(0);
31267
+ let buyingCount = import_ethers55.BigNumber.from(0);
31268
+ if (nftCount < amount) {
31269
+ mintingCount = amount.sub(nftCount);
31270
+ buyingCount = nftCount;
31271
+ if (mintingCount > totalSupply.sub(mintCount)) {
31272
+ mintingCount = totalSupply.sub(mintCount);
31273
+ }
31274
+ } else {
31275
+ buyingCount = amount.lt(totalSupply) ? amount : totalSupply;
31276
+ }
31277
+ totalPrice = yield collection.getTotalPriceOfMintAndBuy(mintingCount, buyingCount);
31278
+ } else if (type === "sell" /* SELL */) {
31279
+ totalPrice = yield collection.getTotalPriceOfSell(amount);
31280
+ }
31281
+ return totalPrice.toString();
31282
+ });
31283
+ }
31284
+ // public async getPriceOfIndex(
31296
31285
  // type: PurcahseType,
31297
31286
  // collectionAddr: string,
31298
- // amount: BigNumber
31287
+ // index: number
31299
31288
  // ): Promise<string> {
31300
- // const collection = new Collection__factory(this.config.signer).attach(
31301
- // collectionAddr
31289
+ // const collection = Collection__factory.connect(
31290
+ // collectionAddr,
31291
+ // this.config.provider
31302
31292
  // );
31303
- // let [
31293
+ // const [
31304
31294
  // currPrice,
31305
31295
  // startPrice,
31306
31296
  // endPrice,
@@ -31309,135 +31299,58 @@ var EthereumConnector = class {
31309
31299
  // midPoint,
31310
31300
  // isMoved,
31311
31301
  // ] = await collection.getLiquidityPool();
31312
- // let info = await collection.getCollectionInfo();
31313
- // let mintCount = info[4];
31314
- // let totalSupply = info[3];
31315
- // let startPriceStr = startPrice.toString();
31316
- // let endPriceStr = endPrice.toString();
31302
+ // const info = await collection.getCollectionInfo();
31303
+ // const mintCount = info[4];
31304
+ // const totalSupply = info[3];
31305
+ // const startPriceStr = startPrice.toString();
31306
+ // const endPriceStr = endPrice.toString();
31307
+ // // Initialize
31317
31308
  // let expectedMintCount = mintCount;
31318
31309
  // let expectedNftCount = nftCount;
31319
- // let totalPrice = new Decimal(0);
31320
31310
  // if (type === PurcahseType.BUY) {
31321
- // let mintingCount = BigNumber.from(0);
31322
- // let buyingCount = BigNumber.from(0);
31323
- // if (nftCount < amount) {
31324
- // mintingCount = amount.sub(nftCount);
31325
- // buyingCount = nftCount;
31326
- // if (mintingCount > totalSupply.sub(mintCount)) {
31327
- // mintingCount = totalSupply.sub(mintCount);
31311
+ // let mintingCount = 0;
31312
+ // let buyingCount = 0;
31313
+ // if (nftCount.toNumber() < index) {
31314
+ // mintingCount = index - nftCount.toNumber();
31315
+ // buyingCount = nftCount.toNumber();
31316
+ // if (mintingCount > totalSupply.sub(mintCount).toNumber()) {
31317
+ // mintingCount = totalSupply.sub(mintCount).toNumber();
31328
31318
  // }
31329
31319
  // } else {
31330
- // buyingCount = amount.lt(totalSupply) ? amount : totalSupply;
31331
- // }
31332
- // for (let i = 0; i < mintingCount.toNumber(); i++) {
31333
- // expectedMintCount = expectedMintCount.add(1).lt(totalSupply)
31334
- // ? expectedMintCount.add(1)
31335
- // : totalSupply;
31336
- // totalPrice = totalPrice.plus(
31337
- // getPrice(
31338
- // expectedMintCount.toString(),
31339
- // expectedNftCount.toString(),
31340
- // steepness.toString(),
31341
- // midPoint.toString(),
31342
- // startPriceStr,
31343
- // endPriceStr
31344
- // )
31345
- // );
31346
- // }
31347
- // for (let i = 0; i < buyingCount.toNumber(); i++) {
31348
- // totalPrice = totalPrice.plus(
31349
- // getPrice(
31350
- // expectedMintCount.toString(),
31351
- // expectedNftCount.toString(),
31352
- // steepness.toString(),
31353
- // midPoint.toString(),
31354
- // startPriceStr,
31355
- // endPriceStr
31356
- // )
31357
- // );
31358
- // expectedNftCount = expectedNftCount.sub(1).gt(0)
31359
- // ? expectedNftCount.sub(1)
31360
- // : BigNumber.from(0);
31320
+ // buyingCount = Math.min(index, totalSupply.toNumber());
31361
31321
  // }
31322
+ // expectedNftCount = expectedNftCount.sub(buyingCount).gt(0)
31323
+ // ? expectedNftCount.sub(buyingCount)
31324
+ // : BigNumber.from(0);
31325
+ // expectedMintCount = expectedMintCount.add(mintingCount).lt(totalSupply)
31326
+ // ? expectedMintCount.add(mintingCount)
31327
+ // : totalSupply;
31328
+ // const currentPrice = getPrice(
31329
+ // expectedMintCount.toString(),
31330
+ // expectedNftCount.toString(),
31331
+ // steepness.toString(),
31332
+ // midPoint.toString(),
31333
+ // startPriceStr,
31334
+ // endPriceStr
31335
+ // );
31336
+ // return currentPrice.toString();
31362
31337
  // } else if (type === PurcahseType.SELL) {
31363
- // for (let i = 0; i < amount.toNumber(); i++) {
31364
- // expectedNftCount = expectedNftCount.add(1).lt(totalSupply)
31365
- // ? expectedNftCount.add(1)
31366
- // : totalSupply;
31367
- // totalPrice = totalPrice.plus(
31368
- // getPrice(
31369
- // expectedMintCount.toString(),
31370
- // expectedNftCount.toString(),
31371
- // steepness.toString(),
31372
- // midPoint.toString(),
31373
- // startPriceStr,
31374
- // endPriceStr
31375
- // )
31376
- // );
31377
- // }
31338
+ // // Contract side calculates the price after adding 1
31339
+ // expectedNftCount = expectedNftCount.add(index).lt(totalSupply)
31340
+ // ? expectedNftCount.add(index)
31341
+ // : totalSupply;
31342
+ // const currentPrice = getPrice(
31343
+ // expectedMintCount.toString(),
31344
+ // expectedNftCount.toString(),
31345
+ // steepness.toString(),
31346
+ // midPoint.toString(),
31347
+ // startPriceStr,
31348
+ // endPriceStr
31349
+ // );
31350
+ // return currentPrice.toString();
31378
31351
  // }
31379
- // return this.addProtocolFee(totalPrice);
31352
+ // return "0";
31380
31353
  // }
31381
- getPriceOfIndex(type, collectionAddr, index) {
31382
- return __async(this, null, function* () {
31383
- const collection = Collection__factory.connect(
31384
- collectionAddr,
31385
- this.config.provider
31386
- );
31387
- const [
31388
- currPrice,
31389
- startPrice,
31390
- endPrice,
31391
- nftCount,
31392
- steepness,
31393
- midPoint,
31394
- isMoved
31395
- ] = yield collection.getLiquidityPool();
31396
- const info = yield collection.getCollectionInfo();
31397
- const mintCount = info[4];
31398
- const totalSupply = info[3];
31399
- const startPriceStr = startPrice.toString();
31400
- const endPriceStr = endPrice.toString();
31401
- let expectedMintCount = mintCount;
31402
- let expectedNftCount = nftCount;
31403
- if (type === "buy" /* BUY */) {
31404
- let mintingCount = 0;
31405
- let buyingCount = 0;
31406
- if (nftCount.toNumber() < index) {
31407
- mintingCount = index - nftCount.toNumber();
31408
- buyingCount = nftCount.toNumber();
31409
- if (mintingCount > totalSupply.sub(mintCount).toNumber()) {
31410
- mintingCount = totalSupply.sub(mintCount).toNumber();
31411
- }
31412
- } else {
31413
- buyingCount = Math.min(index, totalSupply.toNumber());
31414
- }
31415
- expectedNftCount = expectedNftCount.sub(buyingCount).gt(0) ? expectedNftCount.sub(buyingCount) : import_ethers55.BigNumber.from(0);
31416
- expectedMintCount = expectedMintCount.add(mintingCount).lt(totalSupply) ? expectedMintCount.add(mintingCount) : totalSupply;
31417
- const currentPrice = getPrice(
31418
- expectedMintCount.toString(),
31419
- expectedNftCount.toString(),
31420
- steepness.toString(),
31421
- midPoint.toString(),
31422
- startPriceStr,
31423
- endPriceStr
31424
- );
31425
- return currentPrice.toString();
31426
- } else if (type === "sell" /* SELL */) {
31427
- expectedNftCount = expectedNftCount.add(index).lt(totalSupply) ? expectedNftCount.add(index) : totalSupply;
31428
- const currentPrice = getPrice(
31429
- expectedMintCount.toString(),
31430
- expectedNftCount.toString(),
31431
- steepness.toString(),
31432
- midPoint.toString(),
31433
- startPriceStr,
31434
- endPriceStr
31435
- );
31436
- return currentPrice.toString();
31437
- }
31438
- return "0";
31439
- });
31440
- }
31441
31354
  moveLiquidity(collectionAddress) {
31442
31355
  return __async(this, null, function* () {
31443
31356
  const collection = new Collection__factory(this.config.signer).attach(
@@ -35563,6 +35476,55 @@ function analyzeSellTransaction2(program, transactionData) {
35563
35476
  return sellResponse;
35564
35477
  }
35565
35478
 
35479
+ // src/utility.ts
35480
+ var import_bytes = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
35481
+ var crypto = __toESM(require("crypto"));
35482
+ var import_decimal2 = __toESM(require("decimal.js"));
35483
+ function splitEncryptedText(encryptedText) {
35484
+ return {
35485
+ ivString: encryptedText.slice(0, 32),
35486
+ encryptedDataString: encryptedText.slice(32)
35487
+ };
35488
+ }
35489
+ function decodeStr(str) {
35490
+ const { encryptedDataString, ivString } = splitEncryptedText(str);
35491
+ const encoding = "hex";
35492
+ try {
35493
+ const iv = Buffer.from(ivString, encoding);
35494
+ const encryptedText = Buffer.from(encryptedDataString, encoding);
35495
+ const decipher = crypto.createDecipheriv(
35496
+ "aes-256-cbc",
35497
+ import_bytes.bs58.decode("Dr1vQSrALU4KbiP6eDsYQCvneb7tY3QmrUCj2GNFQNUC"),
35498
+ iv
35499
+ );
35500
+ const decrypted = decipher.update(encryptedText);
35501
+ return Buffer.concat([decrypted, decipher.final()]).toString();
35502
+ } catch (e) {
35503
+ console.error(e);
35504
+ throw new Error("wrong message");
35505
+ }
35506
+ }
35507
+ function getPrice(_mintCount, _nftCount, _steepness, _midPoint, _startPrice, _endPrice) {
35508
+ try {
35509
+ const n = new import_decimal2.default(_mintCount).minus(_nftCount);
35510
+ const steepness = new import_decimal2.default(_steepness).div(1e18);
35511
+ const midPoint = new import_decimal2.default(_midPoint).div(1e18);
35512
+ const startSubEnd = new import_decimal2.default(_endPrice).minus(_startPrice);
35513
+ const a = new import_decimal2.default(1).plus(
35514
+ Math.exp(Number(steepness.mul(-1).mul(n.minus(midPoint)).toString()))
35515
+ ).floor();
35516
+ const b = new import_decimal2.default(1).plus(
35517
+ Math.exp(Number(steepness.mul(midPoint).toString()))
35518
+ ).floor();
35519
+ const startPrice = new import_decimal2.default(_startPrice);
35520
+ const price = startPrice.plus(startSubEnd.div(a)).minus(startSubEnd.div(b).floor()).floor();
35521
+ console.log("price in getPrice function", price);
35522
+ return price;
35523
+ } catch (error) {
35524
+ throw new Error(`Price calculation failed: ${error}`);
35525
+ }
35526
+ }
35527
+
35566
35528
  // src/solana/index.ts
35567
35529
  var SolanaConnector = class {
35568
35530
  constructor(config, platform) {
@@ -36525,6 +36487,7 @@ var SolanaConnector = class {
36525
36487
  };
36526
36488
 
36527
36489
  // src/main_sdk.ts
36490
+ var import_ethers56 = require("ethers");
36528
36491
  var FlipmemeSDK = class {
36529
36492
  constructor(chainType, plateform, config) {
36530
36493
  this.ethereum = null;
@@ -36609,6 +36572,21 @@ var FlipmemeSDK = class {
36609
36572
  }
36610
36573
  });
36611
36574
  }
36575
+ getTotalPrice(type, collectionId, amount) {
36576
+ return __async(this, null, function* () {
36577
+ if (this.blockchainType === "solana" /* SOLANA */ && this.solana) {
36578
+ return yield this.solana.getTotalPrice(type, collectionId, amount);
36579
+ } else if (this.blockchainType === "ethereum" /* ETHEREUM */ && this.ethereum) {
36580
+ return this.ethereum.getTotalPrice(
36581
+ type,
36582
+ collectionId,
36583
+ import_ethers56.BigNumber.from(amount)
36584
+ );
36585
+ } else {
36586
+ throw new Error("Cannot call this function");
36587
+ }
36588
+ });
36589
+ }
36612
36590
  /**
36613
36591
  * create lookup table account with lookuptable addresses and return lookup table account
36614
36592
  * @param lookupTableAddresses addresses to add lookup table
@@ -36707,7 +36685,7 @@ var FlipmemeSDK = class {
36707
36685
  const collectionInfo = yield this.solana.getCollectionInfo(collectionId);
36708
36686
  return this.solana.getPriceOfIndex(type, collectionInfo, index).toString();
36709
36687
  } else if (this.blockchainType === "ethereum" /* ETHEREUM */ && this.ethereum) {
36710
- return yield this.ethereum.getPriceOfIndex(type, collectionId, index);
36688
+ throw new Error("Cannot use this function on evm");
36711
36689
  } else {
36712
36690
  throw new Error("Cannot call this function");
36713
36691
  }