@flaunch/sdk 0.9.12 → 0.9.14

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.esm.js CHANGED
@@ -5702,7 +5702,6 @@ const FlaunchAddress = {
5702
5702
  [base.id]: "0xCc7A4A00072ccbeEEbd999edc812C0ce498Fb63B",
5703
5703
  [baseSepolia.id]: "0x7D375C9133721083DF7b7e5Cb0Ed8Fc78862dfe3",
5704
5704
  };
5705
- // also supports AnyPositionManager
5706
5705
  const FlaunchV1_1Address = {
5707
5706
  [base.id]: "0xb4512bf57d50fbcb64a3adf8b17a79b2a204c18c",
5708
5707
  [baseSepolia.id]: "0x96be8ff5e244294a34bfa507a39190dc7a839baa",
@@ -15153,6 +15152,554 @@ class ReadFlaunch {
15153
15152
  }
15154
15153
  }
15155
15154
 
15155
+ const AnyFlaunchAbi = [
15156
+ {
15157
+ inputs: [{ internalType: "string", name: "_baseURI", type: "string" }],
15158
+ stateMutability: "nonpayable",
15159
+ type: "constructor",
15160
+ },
15161
+ { inputs: [], name: "AccountBalanceOverflow", type: "error" },
15162
+ { inputs: [], name: "AlreadyInitialized", type: "error" },
15163
+ { inputs: [], name: "BalanceQueryForZeroAddress", type: "error" },
15164
+ { inputs: [], name: "BaseURICannotBeEmpty", type: "error" },
15165
+ { inputs: [], name: "CallerIsNotPositionManager", type: "error" },
15166
+ {
15167
+ inputs: [
15168
+ { internalType: "uint24", name: "_allocation", type: "uint24" },
15169
+ { internalType: "uint256", name: "_maxAllocation", type: "uint256" },
15170
+ ],
15171
+ name: "CreatorFeeAllocationInvalid",
15172
+ type: "error",
15173
+ },
15174
+ { inputs: [], name: "InvalidInitialization", type: "error" },
15175
+ { inputs: [], name: "NewOwnerIsZeroAddress", type: "error" },
15176
+ { inputs: [], name: "NoHandoverRequest", type: "error" },
15177
+ { inputs: [], name: "NotInitializing", type: "error" },
15178
+ { inputs: [], name: "NotOwnerNorApproved", type: "error" },
15179
+ { inputs: [], name: "TokenAlreadyExists", type: "error" },
15180
+ { inputs: [], name: "TokenDoesNotExist", type: "error" },
15181
+ { inputs: [], name: "TransferFromIncorrectOwner", type: "error" },
15182
+ { inputs: [], name: "TransferToNonERC721ReceiverImplementer", type: "error" },
15183
+ { inputs: [], name: "TransferToZeroAddress", type: "error" },
15184
+ { inputs: [], name: "Unauthorized", type: "error" },
15185
+ {
15186
+ anonymous: false,
15187
+ inputs: [
15188
+ {
15189
+ indexed: true,
15190
+ internalType: "address",
15191
+ name: "owner",
15192
+ type: "address",
15193
+ },
15194
+ {
15195
+ indexed: true,
15196
+ internalType: "address",
15197
+ name: "account",
15198
+ type: "address",
15199
+ },
15200
+ { indexed: true, internalType: "uint256", name: "id", type: "uint256" },
15201
+ ],
15202
+ name: "Approval",
15203
+ type: "event",
15204
+ },
15205
+ {
15206
+ anonymous: false,
15207
+ inputs: [
15208
+ {
15209
+ indexed: true,
15210
+ internalType: "address",
15211
+ name: "owner",
15212
+ type: "address",
15213
+ },
15214
+ {
15215
+ indexed: true,
15216
+ internalType: "address",
15217
+ name: "operator",
15218
+ type: "address",
15219
+ },
15220
+ {
15221
+ indexed: false,
15222
+ internalType: "bool",
15223
+ name: "isApproved",
15224
+ type: "bool",
15225
+ },
15226
+ ],
15227
+ name: "ApprovalForAll",
15228
+ type: "event",
15229
+ },
15230
+ {
15231
+ anonymous: false,
15232
+ inputs: [
15233
+ {
15234
+ indexed: false,
15235
+ internalType: "string",
15236
+ name: "_newBaseURI",
15237
+ type: "string",
15238
+ },
15239
+ ],
15240
+ name: "BaseURIUpdated",
15241
+ type: "event",
15242
+ },
15243
+ {
15244
+ anonymous: false,
15245
+ inputs: [
15246
+ {
15247
+ indexed: false,
15248
+ internalType: "uint64",
15249
+ name: "version",
15250
+ type: "uint64",
15251
+ },
15252
+ ],
15253
+ name: "Initialized",
15254
+ type: "event",
15255
+ },
15256
+ {
15257
+ anonymous: false,
15258
+ inputs: [
15259
+ {
15260
+ indexed: false,
15261
+ internalType: "address",
15262
+ name: "_newImplementation",
15263
+ type: "address",
15264
+ },
15265
+ ],
15266
+ name: "MemecoinTreasuryImplementationUpdated",
15267
+ type: "event",
15268
+ },
15269
+ {
15270
+ anonymous: false,
15271
+ inputs: [
15272
+ {
15273
+ indexed: true,
15274
+ internalType: "address",
15275
+ name: "pendingOwner",
15276
+ type: "address",
15277
+ },
15278
+ ],
15279
+ name: "OwnershipHandoverCanceled",
15280
+ type: "event",
15281
+ },
15282
+ {
15283
+ anonymous: false,
15284
+ inputs: [
15285
+ {
15286
+ indexed: true,
15287
+ internalType: "address",
15288
+ name: "pendingOwner",
15289
+ type: "address",
15290
+ },
15291
+ ],
15292
+ name: "OwnershipHandoverRequested",
15293
+ type: "event",
15294
+ },
15295
+ {
15296
+ anonymous: false,
15297
+ inputs: [
15298
+ {
15299
+ indexed: true,
15300
+ internalType: "address",
15301
+ name: "oldOwner",
15302
+ type: "address",
15303
+ },
15304
+ {
15305
+ indexed: true,
15306
+ internalType: "address",
15307
+ name: "newOwner",
15308
+ type: "address",
15309
+ },
15310
+ ],
15311
+ name: "OwnershipTransferred",
15312
+ type: "event",
15313
+ },
15314
+ {
15315
+ anonymous: false,
15316
+ inputs: [
15317
+ { indexed: true, internalType: "address", name: "from", type: "address" },
15318
+ { indexed: true, internalType: "address", name: "to", type: "address" },
15319
+ { indexed: true, internalType: "uint256", name: "id", type: "uint256" },
15320
+ ],
15321
+ name: "Transfer",
15322
+ type: "event",
15323
+ },
15324
+ {
15325
+ inputs: [],
15326
+ name: "MAX_CREATOR_ALLOCATION",
15327
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
15328
+ stateMutability: "view",
15329
+ type: "function",
15330
+ },
15331
+ {
15332
+ inputs: [
15333
+ { internalType: "address", name: "account", type: "address" },
15334
+ { internalType: "uint256", name: "id", type: "uint256" },
15335
+ ],
15336
+ name: "approve",
15337
+ outputs: [],
15338
+ stateMutability: "payable",
15339
+ type: "function",
15340
+ },
15341
+ {
15342
+ inputs: [{ internalType: "address", name: "owner", type: "address" }],
15343
+ name: "balanceOf",
15344
+ outputs: [{ internalType: "uint256", name: "result", type: "uint256" }],
15345
+ stateMutability: "view",
15346
+ type: "function",
15347
+ },
15348
+ {
15349
+ inputs: [],
15350
+ name: "baseURI",
15351
+ outputs: [{ internalType: "string", name: "", type: "string" }],
15352
+ stateMutability: "view",
15353
+ type: "function",
15354
+ },
15355
+ {
15356
+ inputs: [{ internalType: "uint256", name: "_tokenId", type: "uint256" }],
15357
+ name: "burn",
15358
+ outputs: [],
15359
+ stateMutability: "nonpayable",
15360
+ type: "function",
15361
+ },
15362
+ {
15363
+ inputs: [],
15364
+ name: "cancelOwnershipHandover",
15365
+ outputs: [],
15366
+ stateMutability: "payable",
15367
+ type: "function",
15368
+ },
15369
+ {
15370
+ inputs: [
15371
+ { internalType: "address", name: "pendingOwner", type: "address" },
15372
+ ],
15373
+ name: "completeOwnershipHandover",
15374
+ outputs: [],
15375
+ stateMutability: "payable",
15376
+ type: "function",
15377
+ },
15378
+ {
15379
+ inputs: [{ internalType: "address", name: "_memecoin", type: "address" }],
15380
+ name: "creator",
15381
+ outputs: [{ internalType: "address", name: "creator_", type: "address" }],
15382
+ stateMutability: "view",
15383
+ type: "function",
15384
+ },
15385
+ {
15386
+ inputs: [
15387
+ {
15388
+ components: [
15389
+ { internalType: "address", name: "memecoin", type: "address" },
15390
+ { internalType: "address", name: "creator", type: "address" },
15391
+ {
15392
+ internalType: "uint24",
15393
+ name: "creatorFeeAllocation",
15394
+ type: "uint24",
15395
+ },
15396
+ { internalType: "bytes", name: "initialPriceParams", type: "bytes" },
15397
+ { internalType: "bytes", name: "feeCalculatorParams", type: "bytes" },
15398
+ ],
15399
+ internalType: "struct AnyPositionManager.FlaunchParams",
15400
+ name: "_params",
15401
+ type: "tuple",
15402
+ },
15403
+ ],
15404
+ name: "flaunch",
15405
+ outputs: [
15406
+ {
15407
+ internalType: "address payable",
15408
+ name: "memecoinTreasury_",
15409
+ type: "address",
15410
+ },
15411
+ { internalType: "uint256", name: "tokenId_", type: "uint256" },
15412
+ ],
15413
+ stateMutability: "nonpayable",
15414
+ type: "function",
15415
+ },
15416
+ {
15417
+ inputs: [{ internalType: "uint256", name: "id", type: "uint256" }],
15418
+ name: "getApproved",
15419
+ outputs: [{ internalType: "address", name: "result", type: "address" }],
15420
+ stateMutability: "view",
15421
+ type: "function",
15422
+ },
15423
+ {
15424
+ inputs: [
15425
+ {
15426
+ internalType: "contract AnyPositionManager",
15427
+ name: "_positionManager",
15428
+ type: "address",
15429
+ },
15430
+ {
15431
+ internalType: "address",
15432
+ name: "_memecoinTreasuryImplementation",
15433
+ type: "address",
15434
+ },
15435
+ ],
15436
+ name: "initialize",
15437
+ outputs: [],
15438
+ stateMutability: "nonpayable",
15439
+ type: "function",
15440
+ },
15441
+ {
15442
+ inputs: [
15443
+ { internalType: "address", name: "owner", type: "address" },
15444
+ { internalType: "address", name: "operator", type: "address" },
15445
+ ],
15446
+ name: "isApprovedForAll",
15447
+ outputs: [{ internalType: "bool", name: "result", type: "bool" }],
15448
+ stateMutability: "view",
15449
+ type: "function",
15450
+ },
15451
+ {
15452
+ inputs: [{ internalType: "uint256", name: "_tokenId", type: "uint256" }],
15453
+ name: "memecoin",
15454
+ outputs: [{ internalType: "address", name: "", type: "address" }],
15455
+ stateMutability: "view",
15456
+ type: "function",
15457
+ },
15458
+ {
15459
+ inputs: [{ internalType: "address", name: "_memecoin", type: "address" }],
15460
+ name: "memecoinTreasury",
15461
+ outputs: [{ internalType: "address payable", name: "", type: "address" }],
15462
+ stateMutability: "view",
15463
+ type: "function",
15464
+ },
15465
+ {
15466
+ inputs: [{ internalType: "uint256", name: "_tokenId", type: "uint256" }],
15467
+ name: "memecoinTreasury",
15468
+ outputs: [{ internalType: "address payable", name: "", type: "address" }],
15469
+ stateMutability: "view",
15470
+ type: "function",
15471
+ },
15472
+ {
15473
+ inputs: [],
15474
+ name: "memecoinTreasuryImplementation",
15475
+ outputs: [{ internalType: "address", name: "", type: "address" }],
15476
+ stateMutability: "view",
15477
+ type: "function",
15478
+ },
15479
+ {
15480
+ inputs: [],
15481
+ name: "name",
15482
+ outputs: [{ internalType: "string", name: "", type: "string" }],
15483
+ stateMutability: "view",
15484
+ type: "function",
15485
+ },
15486
+ {
15487
+ inputs: [],
15488
+ name: "nextTokenId",
15489
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
15490
+ stateMutability: "view",
15491
+ type: "function",
15492
+ },
15493
+ {
15494
+ inputs: [],
15495
+ name: "owner",
15496
+ outputs: [{ internalType: "address", name: "result", type: "address" }],
15497
+ stateMutability: "view",
15498
+ type: "function",
15499
+ },
15500
+ {
15501
+ inputs: [{ internalType: "uint256", name: "id", type: "uint256" }],
15502
+ name: "ownerOf",
15503
+ outputs: [{ internalType: "address", name: "result", type: "address" }],
15504
+ stateMutability: "view",
15505
+ type: "function",
15506
+ },
15507
+ {
15508
+ inputs: [
15509
+ { internalType: "address", name: "pendingOwner", type: "address" },
15510
+ ],
15511
+ name: "ownershipHandoverExpiresAt",
15512
+ outputs: [{ internalType: "uint256", name: "result", type: "uint256" }],
15513
+ stateMutability: "view",
15514
+ type: "function",
15515
+ },
15516
+ {
15517
+ inputs: [{ internalType: "uint256", name: "_tokenId", type: "uint256" }],
15518
+ name: "poolId",
15519
+ outputs: [{ internalType: "PoolId", name: "", type: "bytes32" }],
15520
+ stateMutability: "view",
15521
+ type: "function",
15522
+ },
15523
+ {
15524
+ inputs: [],
15525
+ name: "positionManager",
15526
+ outputs: [
15527
+ {
15528
+ internalType: "contract AnyPositionManager",
15529
+ name: "",
15530
+ type: "address",
15531
+ },
15532
+ ],
15533
+ stateMutability: "view",
15534
+ type: "function",
15535
+ },
15536
+ {
15537
+ inputs: [],
15538
+ name: "renounceOwnership",
15539
+ outputs: [],
15540
+ stateMutability: "payable",
15541
+ type: "function",
15542
+ },
15543
+ {
15544
+ inputs: [],
15545
+ name: "requestOwnershipHandover",
15546
+ outputs: [],
15547
+ stateMutability: "payable",
15548
+ type: "function",
15549
+ },
15550
+ {
15551
+ inputs: [
15552
+ { internalType: "address", name: "from", type: "address" },
15553
+ { internalType: "address", name: "to", type: "address" },
15554
+ { internalType: "uint256", name: "id", type: "uint256" },
15555
+ ],
15556
+ name: "safeTransferFrom",
15557
+ outputs: [],
15558
+ stateMutability: "payable",
15559
+ type: "function",
15560
+ },
15561
+ {
15562
+ inputs: [
15563
+ { internalType: "address", name: "from", type: "address" },
15564
+ { internalType: "address", name: "to", type: "address" },
15565
+ { internalType: "uint256", name: "id", type: "uint256" },
15566
+ { internalType: "bytes", name: "data", type: "bytes" },
15567
+ ],
15568
+ name: "safeTransferFrom",
15569
+ outputs: [],
15570
+ stateMutability: "payable",
15571
+ type: "function",
15572
+ },
15573
+ {
15574
+ inputs: [
15575
+ { internalType: "address", name: "operator", type: "address" },
15576
+ { internalType: "bool", name: "isApproved", type: "bool" },
15577
+ ],
15578
+ name: "setApprovalForAll",
15579
+ outputs: [],
15580
+ stateMutability: "nonpayable",
15581
+ type: "function",
15582
+ },
15583
+ {
15584
+ inputs: [{ internalType: "string", name: "_baseURI", type: "string" }],
15585
+ name: "setBaseURI",
15586
+ outputs: [],
15587
+ stateMutability: "nonpayable",
15588
+ type: "function",
15589
+ },
15590
+ {
15591
+ inputs: [
15592
+ {
15593
+ internalType: "address",
15594
+ name: "_memecoinTreasuryImplementation",
15595
+ type: "address",
15596
+ },
15597
+ ],
15598
+ name: "setMemecoinTreasuryImplementation",
15599
+ outputs: [],
15600
+ stateMutability: "nonpayable",
15601
+ type: "function",
15602
+ },
15603
+ {
15604
+ inputs: [{ internalType: "bytes4", name: "interfaceId", type: "bytes4" }],
15605
+ name: "supportsInterface",
15606
+ outputs: [{ internalType: "bool", name: "result", type: "bool" }],
15607
+ stateMutability: "view",
15608
+ type: "function",
15609
+ },
15610
+ {
15611
+ inputs: [],
15612
+ name: "symbol",
15613
+ outputs: [{ internalType: "string", name: "", type: "string" }],
15614
+ stateMutability: "view",
15615
+ type: "function",
15616
+ },
15617
+ {
15618
+ inputs: [{ internalType: "address", name: "_memecoin", type: "address" }],
15619
+ name: "tokenId",
15620
+ outputs: [{ internalType: "uint256", name: "_tokenId", type: "uint256" }],
15621
+ stateMutability: "view",
15622
+ type: "function",
15623
+ },
15624
+ {
15625
+ inputs: [{ internalType: "uint256", name: "_tokenId", type: "uint256" }],
15626
+ name: "tokenURI",
15627
+ outputs: [{ internalType: "string", name: "", type: "string" }],
15628
+ stateMutability: "view",
15629
+ type: "function",
15630
+ },
15631
+ {
15632
+ inputs: [
15633
+ { internalType: "address", name: "from", type: "address" },
15634
+ { internalType: "address", name: "to", type: "address" },
15635
+ { internalType: "uint256", name: "id", type: "uint256" },
15636
+ ],
15637
+ name: "transferFrom",
15638
+ outputs: [],
15639
+ stateMutability: "payable",
15640
+ type: "function",
15641
+ },
15642
+ {
15643
+ inputs: [{ internalType: "address", name: "newOwner", type: "address" }],
15644
+ name: "transferOwnership",
15645
+ outputs: [],
15646
+ stateMutability: "payable",
15647
+ type: "function",
15648
+ },
15649
+ ];
15650
+
15651
+ /**
15652
+ * Client for interacting with the AnyFlaunch contract in read-only mode
15653
+ * Provides methods to query token IDs and metadata URIs
15654
+ */
15655
+ class ReadAnyFlaunch {
15656
+ /**
15657
+ * Creates a new ReadAnyFlaunch instance
15658
+ * @param address - The address of the AnyFlaunch contract
15659
+ * @param drift - Optional drift instance for contract interactions (creates new instance if not provided)
15660
+ * @throws Error if address is not provided
15661
+ */
15662
+ constructor(address, drift = createDrift$1()) {
15663
+ if (!address) {
15664
+ throw new Error("Address is required");
15665
+ }
15666
+ this.contract = drift.contract({
15667
+ abi: AnyFlaunchAbi,
15668
+ address,
15669
+ });
15670
+ }
15671
+ /**
15672
+ * Gets the token ID associated with a memecoin
15673
+ * @param coinAddress - The address of the memecoin
15674
+ * @returns Promise<bigint> - The token ID
15675
+ */
15676
+ tokenId(coinAddress) {
15677
+ return this.contract.read("tokenId", {
15678
+ _memecoin: coinAddress,
15679
+ });
15680
+ }
15681
+ /**
15682
+ * Gets the metadata URI for a token
15683
+ * @param tokenId - The ID of the token
15684
+ * @returns Promise<string> - The token's metadata URI
15685
+ */
15686
+ tokenURI(tokenId) {
15687
+ return this.contract.read("tokenURI", {
15688
+ _tokenId: tokenId,
15689
+ });
15690
+ }
15691
+ /**
15692
+ * Gets the memecoin address for a given token ID
15693
+ * @param tokenId - The ID of the token
15694
+ * @returns Promise<Address> - The address of the memecoin
15695
+ */
15696
+ memecoin(tokenId) {
15697
+ return this.contract.read("memecoin", {
15698
+ _tokenId: tokenId,
15699
+ });
15700
+ }
15701
+ }
15702
+
15156
15703
  const MemecoinAbi = [
15157
15704
  { inputs: [], stateMutability: "nonpayable", type: "constructor" },
15158
15705
  { inputs: [], name: "CallerNotFlaunch", type: "error" },
@@ -26287,6 +26834,7 @@ class ReadFlaunchSDK {
26287
26834
  this.readFlaunch = new ReadFlaunch(FlaunchAddress[this.chainId], drift);
26288
26835
  this.readFlaunchV1_1 = new ReadFlaunchV1_1(FlaunchV1_1Address[this.chainId], drift);
26289
26836
  this.readFlaunchV1_2 = new ReadFlaunchV1_2(FlaunchV1_2Address[this.chainId], drift);
26837
+ this.readAnyFlaunch = new ReadAnyFlaunch(AnyFlaunchAddress[this.chainId], drift);
26290
26838
  this.readQuoter = new ReadQuoter(this.chainId, QuoterAddress[this.chainId], drift);
26291
26839
  this.readPermit2 = new ReadPermit2(Permit2Address[this.chainId], drift);
26292
26840
  }
@@ -26377,23 +26925,30 @@ class ReadFlaunchSDK {
26377
26925
  }
26378
26926
  }
26379
26927
  /**
26380
- * Gets the flaunch contract address for a given version
26381
- * @param version - The version to get the flaunch contract address for
26928
+ * Gets the flaunch contract instance for a given version
26929
+ * @param version - The version to get the flaunch contract instance for
26382
26930
  */
26383
- getFlaunchAddress(version) {
26931
+ getFlaunch(version) {
26384
26932
  switch (version) {
26385
26933
  case FlaunchVersion.V1:
26386
- return this.readFlaunch.contract.address;
26934
+ return this.readFlaunch;
26387
26935
  case FlaunchVersion.V1_1:
26388
- return this.readFlaunchV1_1.contract.address;
26936
+ return this.readFlaunchV1_1;
26389
26937
  case FlaunchVersion.V1_2:
26390
- return this.readFlaunchV1_2.contract.address;
26938
+ return this.readFlaunchV1_2;
26391
26939
  case FlaunchVersion.ANY:
26392
- return this.readFlaunchV1_1.contract.address;
26940
+ return this.readAnyFlaunch;
26393
26941
  default:
26394
- return this.readFlaunchV1_1.contract.address;
26942
+ return this.readFlaunchV1_2;
26395
26943
  }
26396
26944
  }
26945
+ /**
26946
+ * Gets the flaunch contract address for a given version
26947
+ * @param version - The version to get the flaunch contract address for
26948
+ */
26949
+ getFlaunchAddress(version) {
26950
+ return this.getFlaunch(version).contract.address;
26951
+ }
26397
26952
  getPositionManagerAddress(version) {
26398
26953
  return this.getPositionManager(version).contract.address;
26399
26954
  }
@@ -26403,6 +26958,20 @@ class ReadFlaunchSDK {
26403
26958
  getBidWallAddress(version) {
26404
26959
  return this.getBidWall(version).contract.address;
26405
26960
  }
26961
+ /**
26962
+ * Gets the flaunch contract address and token ID for a memecoin
26963
+ * @param coinAddress - The address of the memecoin
26964
+ * @returns Promise<{ flaunchAddress: Address; tokenId: bigint }> - The flaunch contract address and token ID
26965
+ */
26966
+ async getFlaunchTokenIdForMemecoin(coinAddress) {
26967
+ const version = await this.getCoinVersion(coinAddress);
26968
+ const flaunch = this.getFlaunch(version);
26969
+ const tokenId = await flaunch.tokenId(coinAddress);
26970
+ return {
26971
+ flaunchAddress: flaunch.contract.address,
26972
+ tokenId,
26973
+ };
26974
+ }
26406
26975
  /**
26407
26976
  * Retrieves metadata for a given Flaunch coin
26408
26977
  * @param coinAddress - The address of the coin
@@ -28224,7 +28793,8 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
28224
28793
  const amount0 = poolKey.currency0 === coinAddress ? coinAmount : flethAmount;
28225
28794
  const amount1 = poolKey.currency0 === coinAddress ? flethAmount : coinAmount;
28226
28795
  // Calculate and constrain liquidity using shared method
28227
- const { finalLiquidity, finalAmount0, finalAmount1 } = this.calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1);
28796
+ const slippagePercent = params.slippagePercent;
28797
+ const { finalLiquidity, finalAmount0, finalAmount1 } = this.calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1, slippagePercent);
28228
28798
  // 6. Add liquidity
28229
28799
  calls.push(this.createLiquidityCall(poolKey, tickLower, tickUpper, finalLiquidity, finalAmount0, finalAmount1, userAddress));
28230
28800
  return calls;
@@ -28273,11 +28843,22 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
28273
28843
  const version = await this.determineCoinVersion(coinAddress, params.version);
28274
28844
  const poolKey = this.createPoolKey(coinAddress, version);
28275
28845
  let currentTick;
28276
- // if initial marketcap or price is provided, it means that the pool is not initialized yet
28277
- // so determining the currentTick
28278
- if (("initialMarketCapUSD" in params && params.initialMarketCapUSD) ||
28279
- ("initialPriceUSD" in params && params.initialPriceUSD)) {
28280
- const { decimals: coinDecimals, formattedTotalSupplyInDecimals } = await this.getCoinInfo(coinAddress);
28846
+ // First, check if the pool is initialized as we can then get the current tick directly from
28847
+ // the state view.
28848
+ const poolState = await this.readStateView.poolSlot0({
28849
+ poolId: getPoolId(poolKey),
28850
+ });
28851
+ currentTick = poolState.tick;
28852
+ // If the current sqrtPriceX96 of the pool is zero, and the initial marketcap or price is provided,
28853
+ // we can use this to determine the current tick.
28854
+ if (poolState.sqrtPriceX96 === 0n &&
28855
+ (("initialMarketCapUSD" in params && params.initialMarketCapUSD) ||
28856
+ ("initialPriceUSD" in params && params.initialPriceUSD))) {
28857
+ let { decimals: coinDecimals, formattedTotalSupplyInDecimals } = await this.getCoinInfo(coinAddress);
28858
+ // If we have a tokenSupply set, then overwrite the value
28859
+ if ("tokenSupply" in params && params.tokenSupply !== undefined) {
28860
+ formattedTotalSupplyInDecimals = parseFloat(formatUnits$1(params.tokenSupply, coinDecimals));
28861
+ }
28281
28862
  // Determine market cap based on provided parameter
28282
28863
  let initialMarketCapUSD;
28283
28864
  if ("initialMarketCapUSD" in params && params.initialMarketCapUSD) {
@@ -28297,13 +28878,6 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
28297
28878
  }
28298
28879
  currentTick = calculatedTick;
28299
28880
  }
28300
- else {
28301
- // the pool is already initialized, get the current tick from the pool
28302
- const poolState = await this.readStateView.poolSlot0({
28303
- poolId: getPoolId(poolKey),
28304
- });
28305
- currentTick = poolState.tick;
28306
- }
28307
28881
  // We want to add liquidity from current price to infinity (as coin appreciates vs flETH)
28308
28882
  // This means providing single-sided coin liquidity that becomes active as coin price increases
28309
28883
  const isFLETHZero = this.flETHIsCurrencyZero(coinAddress);
@@ -28411,7 +28985,8 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
28411
28985
  const amount0 = poolKey.currency0 === coinAddress ? coinAmount : flethAmount;
28412
28986
  const amount1 = poolKey.currency0 === coinAddress ? flethAmount : coinAmount;
28413
28987
  // Calculate and constrain liquidity using shared method
28414
- const { finalLiquidity, finalAmount0, finalAmount1 } = this.calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1);
28988
+ const slippagePercent = params.slippagePercent;
28989
+ const { finalLiquidity, finalAmount0, finalAmount1 } = this.calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1, slippagePercent);
28415
28990
  // 3. Add liquidity
28416
28991
  calls.push(this.createLiquidityCall(poolKey, tickLower, tickUpper, finalLiquidity, finalAmount0, finalAmount1, userAddress));
28417
28992
  return calls;
@@ -28462,7 +29037,13 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
28462
29037
  }
28463
29038
  }
28464
29039
  const addLiquidityCalls = await this.getSingleSidedCoinAddLiquidityCalls({
29040
+ // Add our liquidity parameters
28465
29041
  ...params,
29042
+ // Add our optional tokenSupply if provided from our initialize params
29043
+ ...("_totalSupply" in importParams && {
29044
+ tokenSupply: importParams._totalSupply,
29045
+ }),
29046
+ // Set our FlaunchVersion
28466
29047
  version: FlaunchVersion.ANY, // optimize to avoid fetching if not passed
28467
29048
  });
28468
29049
  return [
@@ -28486,7 +29067,8 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
28486
29067
  * @param amount1 - Amount of currency1
28487
29068
  * @returns Final liquidity and amounts
28488
29069
  */
28489
- calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1) {
29070
+ calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1, slippagePercent = 0.05 // Default to 0.05%
29071
+ ) {
28490
29072
  // Calculate liquidity first using user's input amounts
28491
29073
  const initialLiquidity = getLiquidityFromAmounts({
28492
29074
  currentTick,
@@ -28540,8 +29122,11 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
28540
29122
  finalAmount1 = constrainedAmounts.amount1;
28541
29123
  }
28542
29124
  // IMPORTANT: Add conservative buffer to account for contract rounding differences
28543
- // Reduce liquidity by 0.05% to ensure contract calculations stay within user bounds
28544
- const liquidityBuffer = finalLiquidity / 2000n; // 0.05%
29125
+ // Reduce liquidity by slippagePercent to ensure contract calculations stay within user bounds
29126
+ // slippagePercent is passed as decimal percentage (e.g., 0.05 for 0.05%), convert to decimal
29127
+ const slippageAsDecimal = slippagePercent / 100;
29128
+ const slippageMultiplier = BigInt(Math.floor(1 / slippageAsDecimal));
29129
+ const liquidityBuffer = finalLiquidity / slippageMultiplier;
28545
29130
  const conservativeLiquidity = finalLiquidity - (liquidityBuffer > 1n ? liquidityBuffer : 1n);
28546
29131
  // Use conservative liquidity but keep user's original amounts as maximums
28547
29132
  // The conservative liquidity ensures the contract won't need more than user provided