@flaunch/sdk 0.8.3-beta.6 → 0.9.0-beta.1

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
@@ -5316,7 +5316,7 @@ const FlaunchPositionManagerV1_1Address = {
5316
5316
  [baseSepolia.id]: "0x24347e0dd16357059abfc1b321df354873552fdc",
5317
5317
  };
5318
5318
  const FlaunchPositionManagerV1_2Address = {
5319
- [base.id]: zeroAddress, // TODO: add mainnet address
5319
+ [base.id]: "0x23321f11a6d44fd1ab790044fdfde5758c902fdc", // "1.3" from github releases
5320
5320
  [baseSepolia.id]: "0x4e7cb1e6800a7b297b38bddcecaf9ca5b6616fdc",
5321
5321
  };
5322
5322
  const AnyPositionManagerAddress = {
@@ -5381,7 +5381,7 @@ const FairLaunchAddress = {
5381
5381
  };
5382
5382
  // also supports AnyPositionManager & PositionManagerV1_2 (sepolia)
5383
5383
  const FairLaunchV1_1Address = {
5384
- [base.id]: "0x4dc442403e8c758425b93c59dc737da522f32640",
5384
+ [base.id]: "0x4dc442403e8c758425b93C59Dc737da522f32640",
5385
5385
  [baseSepolia.id]: "0x7922c1ead7c5825fb52ed6b14f397d064508acbe",
5386
5386
  };
5387
5387
  const FlaunchAddress = {
@@ -5394,7 +5394,7 @@ const FlaunchV1_1Address = {
5394
5394
  [baseSepolia.id]: "0x96be8ff5e244294a34bfa507a39190dc7a839baa",
5395
5395
  };
5396
5396
  const FlaunchV1_2Address = {
5397
- [base.id]: zeroAddress, // TODO: add mainnet address
5397
+ [base.id]: "0x516af52d0c629b5e378da4dc64ecb0744ce10109", // "1.3" from github releases
5398
5398
  [baseSepolia.id]: "0xe2ef58a54ee79dac0D4A130ea58b340124DF9438",
5399
5399
  };
5400
5400
  const AnyFlaunchAddress = {
@@ -5414,12 +5414,13 @@ const AnyBidWallAddress = {
5414
5414
  [base.id]: "0x2154c604df568A5285284D1c4918DC98C39240df",
5415
5415
  [baseSepolia.id]: "0xcfF222eA42E43F46A98755db237E4c9C2CA9B772",
5416
5416
  };
5417
+ // @deprecated: FlaunchZap used instead
5417
5418
  const FastFlaunchZapAddress = {
5418
5419
  [base.id]: "0x68d967d25806fef4aa134db031cdcc55d3e20f92",
5419
5420
  [baseSepolia.id]: "0x821d9f6075e7971cc71c379081de9d532f5f9957",
5420
5421
  };
5421
5422
  const FlaunchZapAddress = {
5422
- [base.id]: "0x2bC8cbfE237AEddc7C296436fefe239A0A22dAbF",
5423
+ [base.id]: "0xf9753e6e4fdd1869be40685690a28bff26b8b114",
5423
5424
  [baseSepolia.id]: "0x808DA25e8ecbCC2C0339B6A436AAEAe2021C235d",
5424
5425
  };
5425
5426
  const TreasuryManagerFactoryAddress = {
@@ -7438,7 +7439,7 @@ const URCommands = {
7438
7439
  /**
7439
7440
  * @dev EXACT_OUT adds the slippage, EXACT_IN removes it
7440
7441
  */
7441
- const getAmountWithSlippage = (amount, slippage, swapType) => {
7442
+ const getAmountWithSlippage = ({ amount, slippage, swapType, }) => {
7442
7443
  if (amount == null) {
7443
7444
  return 0n;
7444
7445
  }
@@ -7449,7 +7450,7 @@ const getAmountWithSlippage = (amount, slippage, swapType) => {
7449
7450
  return (absAmount * slippageMultiplier) / BigInt(1e18);
7450
7451
  };
7451
7452
  const ETH = zeroAddress;
7452
- const ethToMemecoin = (params) => {
7453
+ const buyMemecoin = (params) => {
7453
7454
  const flETH = FLETHAddress[params.chainId];
7454
7455
  const flETHHooks = FLETHHooksAddress[params.chainId];
7455
7456
  const flaunchHooks = params.positionManagerAddress;
@@ -7460,16 +7461,27 @@ const ethToMemecoin = (params) => {
7460
7461
  : V4Actions.SWAP_EXACT_OUT) +
7461
7462
  V4Actions.SETTLE_ALL +
7462
7463
  V4Actions.TAKE_ALL);
7463
- // Initialize variables for path and v4Params
7464
- let path;
7464
+ // Initialize variable for v4Params
7465
7465
  let v4Params;
7466
+ // verify that ETH exists in the intermediate pool key, if it's provided
7467
+ if (params.intermediatePoolKey &&
7468
+ params.intermediatePoolKey.currency0 !== ETH &&
7469
+ params.intermediatePoolKey.currency1 !== ETH) {
7470
+ throw new Error("ETH must be one of the currencies in the intermediatePoolKey");
7471
+ }
7472
+ // if not intermediate pool key, ETH is the input token
7473
+ const inputToken = params.intermediatePoolKey
7474
+ ? params.intermediatePoolKey.currency0 === ETH
7475
+ ? params.intermediatePoolKey.currency1
7476
+ : params.intermediatePoolKey.currency0
7477
+ : ETH;
7466
7478
  // Configure path and parameters based on swapType
7467
7479
  if (params.swapType === "EXACT_IN") {
7468
7480
  if (params.amountIn == null || params.amountOutMin == null) {
7469
7481
  throw new Error("amountIn and amountOutMin are required for EXACT_IN swap");
7470
7482
  }
7471
- // Path for 'EXACT_IN' swap
7472
- path = [
7483
+ // Base Path for 'EXACT_IN' swap
7484
+ const basePath = [
7473
7485
  {
7474
7486
  intermediateCurrency: flETH,
7475
7487
  fee: 0,
@@ -7488,8 +7500,19 @@ const ethToMemecoin = (params) => {
7488
7500
  // Parameters for 'EXACT_IN' swap
7489
7501
  v4Params = encodeAbiParameters(IV4RouterAbiExactInput, [
7490
7502
  {
7491
- currencyIn: ETH,
7492
- path: path,
7503
+ currencyIn: inputToken,
7504
+ path: params.intermediatePoolKey
7505
+ ? [
7506
+ {
7507
+ intermediateCurrency: ETH,
7508
+ fee: params.intermediatePoolKey.fee,
7509
+ tickSpacing: params.intermediatePoolKey.tickSpacing,
7510
+ hooks: params.intermediatePoolKey.hooks,
7511
+ hookData: params.intermediatePoolKey.hookData,
7512
+ },
7513
+ ...basePath,
7514
+ ]
7515
+ : basePath,
7493
7516
  amountIn: params.amountIn,
7494
7517
  amountOutMinimum: params.amountOutMin,
7495
7518
  },
@@ -7499,8 +7522,7 @@ const ethToMemecoin = (params) => {
7499
7522
  if (params.amountOut == null || params.amountInMax == null) {
7500
7523
  throw new Error("amountOut and amountInMax are required for EXACT_OUT swap");
7501
7524
  }
7502
- // Path for 'EXACT_OUT' swap
7503
- path = [
7525
+ const basePath = [
7504
7526
  {
7505
7527
  fee: 0,
7506
7528
  tickSpacing: 60,
@@ -7520,7 +7542,18 @@ const ethToMemecoin = (params) => {
7520
7542
  v4Params = encodeAbiParameters(IV4RouterAbiExactOutput, [
7521
7543
  {
7522
7544
  currencyOut: params.memecoin,
7523
- path: path,
7545
+ path: params.intermediatePoolKey
7546
+ ? [
7547
+ {
7548
+ fee: params.intermediatePoolKey.fee,
7549
+ tickSpacing: params.intermediatePoolKey.tickSpacing,
7550
+ hookData: params.intermediatePoolKey.hookData,
7551
+ hooks: params.intermediatePoolKey.hooks,
7552
+ intermediateCurrency: inputToken,
7553
+ },
7554
+ ...basePath,
7555
+ ]
7556
+ : basePath,
7524
7557
  amountOut: params.amountOut,
7525
7558
  amountInMaximum: params.amountInMax,
7526
7559
  },
@@ -7537,7 +7570,7 @@ const ethToMemecoin = (params) => {
7537
7570
  name: "maxAmount",
7538
7571
  },
7539
7572
  ], [
7540
- ETH,
7573
+ inputToken,
7541
7574
  params.swapType === "EXACT_IN"
7542
7575
  ? params.amountIn ?? maxUint256$1
7543
7576
  : params.amountInMax ?? maxUint256$1,
@@ -7562,29 +7595,70 @@ const ethToMemecoin = (params) => {
7562
7595
  { type: "bytes", name: "actions" },
7563
7596
  { type: "bytes[]", name: "params" },
7564
7597
  ], [v4Actions, [v4Params, settleParams, takeParams]]);
7565
- // Commands for Universal Router
7566
- const urCommands = ("0x" + URCommands.V4_SWAP + URCommands.SWEEP);
7567
- const sweepInput = encodeAbiParameters([
7568
- { type: "address", name: "token" },
7569
- { type: "address", name: "recipient" },
7570
- { type: "uint160", name: "amountIn" },
7571
- ], [ETH, params.sender, 0n]);
7572
- // Encode calldata for Universal Router
7573
- const inputs = [v4RouterData, sweepInput];
7574
- const urExecuteCalldata = encodeFunctionData({
7575
- abi: UniversalRouterAbi,
7576
- functionName: "execute",
7577
- args: [urCommands, inputs],
7578
- });
7579
- return {
7580
- calldata: urExecuteCalldata,
7581
- commands: urCommands,
7582
- inputs,
7583
- };
7598
+ if (params.intermediatePoolKey && params.signature && params.permitSingle) {
7599
+ // Commands for Universal Router
7600
+ const urCommands = ("0x" +
7601
+ URCommands.PERMIT2_PERMIT +
7602
+ URCommands.V4_SWAP);
7603
+ const permit2PermitInput = encodeAbiParameters([
7604
+ {
7605
+ type: "tuple",
7606
+ components: [
7607
+ {
7608
+ type: "tuple",
7609
+ components: [
7610
+ { type: "address", name: "token" },
7611
+ { type: "uint160", name: "amount" },
7612
+ { type: "uint48", name: "expiration" },
7613
+ { type: "uint48", name: "nonce" },
7614
+ ],
7615
+ name: "details",
7616
+ },
7617
+ { type: "address", name: "spender" },
7618
+ { type: "uint256", name: "sigDeadline" },
7619
+ ],
7620
+ name: "PermitSingle",
7621
+ },
7622
+ { type: "bytes", name: "signature" },
7623
+ ], [params.permitSingle, params.signature]);
7624
+ // Encode calldata for Universal Router
7625
+ const inputs = [permit2PermitInput, v4RouterData];
7626
+ const urExecuteCalldata = encodeFunctionData({
7627
+ abi: UniversalRouterAbi,
7628
+ functionName: "execute",
7629
+ args: [urCommands, inputs],
7630
+ });
7631
+ return {
7632
+ calldata: urExecuteCalldata,
7633
+ commands: urCommands,
7634
+ inputs,
7635
+ };
7636
+ }
7637
+ else {
7638
+ // Commands for Universal Router
7639
+ const urCommands = ("0x" + URCommands.V4_SWAP + URCommands.SWEEP);
7640
+ const sweepInput = encodeAbiParameters([
7641
+ { type: "address", name: "token" },
7642
+ { type: "address", name: "recipient" },
7643
+ { type: "uint160", name: "amountIn" },
7644
+ ], [ETH, params.sender, 0n]);
7645
+ // Encode calldata for Universal Router
7646
+ const inputs = [v4RouterData, sweepInput];
7647
+ const urExecuteCalldata = encodeFunctionData({
7648
+ abi: UniversalRouterAbi,
7649
+ functionName: "execute",
7650
+ args: [urCommands, inputs],
7651
+ });
7652
+ return {
7653
+ calldata: urExecuteCalldata,
7654
+ commands: urCommands,
7655
+ inputs,
7656
+ };
7657
+ }
7584
7658
  };
7585
7659
  // @notice Beofre calling the UniversalRouter the user must have:
7586
7660
  // 1. Given the Permit2 contract allowance to spend the memecoin
7587
- const memecoinToEthWithPermit2 = (params) => {
7661
+ const sellMemecoinWithPermit2 = (params) => {
7588
7662
  const flETH = FLETHAddress[params.chainId];
7589
7663
  const flETHHooks = FLETHHooksAddress[params.chainId];
7590
7664
  const flaunchHooks = params.positionManagerAddress;
@@ -7592,32 +7666,56 @@ const memecoinToEthWithPermit2 = (params) => {
7592
7666
  V4Actions.SWAP_EXACT_IN +
7593
7667
  V4Actions.SETTLE_ALL +
7594
7668
  V4Actions.TAKE_ALL);
7595
- const v4ExactInputParams = encodeAbiParameters(IV4RouterAbiExactInput, [
7669
+ // verify that ETH exists in the intermediate pool key, if it's provided
7670
+ if (params.intermediatePoolKey &&
7671
+ params.intermediatePoolKey.currency0 !== ETH &&
7672
+ params.intermediatePoolKey.currency1 !== ETH) {
7673
+ throw new Error("ETH must be one of the currencies in the intermediatePoolKey");
7674
+ }
7675
+ // if not intermediate pool key, ETH is the output token
7676
+ const outputToken = params.intermediatePoolKey
7677
+ ? params.intermediatePoolKey.currency0 === ETH
7678
+ ? params.intermediatePoolKey.currency1
7679
+ : params.intermediatePoolKey.currency0
7680
+ : ETH;
7681
+ const basePath = [
7596
7682
  {
7597
- currencyIn: params.memecoin,
7598
- path: [
7599
- {
7600
- intermediateCurrency: flETH,
7601
- fee: 0,
7602
- tickSpacing: 60,
7603
- hooks: flaunchHooks,
7604
- hookData: encodeAbiParameters([
7605
- {
7606
- type: "address",
7607
- name: "referrer",
7608
- },
7609
- ], [params.referrer ?? zeroAddress]),
7610
- },
7683
+ intermediateCurrency: flETH,
7684
+ fee: 0,
7685
+ tickSpacing: 60,
7686
+ hooks: flaunchHooks,
7687
+ hookData: encodeAbiParameters([
7611
7688
  {
7612
- intermediateCurrency: ETH,
7613
- fee: 0,
7614
- tickSpacing: 60,
7615
- hooks: flETHHooks,
7616
- hookData: "0x",
7689
+ type: "address",
7690
+ name: "referrer",
7617
7691
  },
7618
- ],
7692
+ ], [params.referrer ?? zeroAddress]),
7693
+ },
7694
+ {
7695
+ intermediateCurrency: ETH,
7696
+ fee: 0,
7697
+ tickSpacing: 60,
7698
+ hooks: flETHHooks,
7699
+ hookData: "0x",
7700
+ },
7701
+ ];
7702
+ const v4ExactInputParams = encodeAbiParameters(IV4RouterAbiExactInput, [
7703
+ {
7704
+ currencyIn: params.memecoin,
7705
+ path: params.intermediatePoolKey
7706
+ ? [
7707
+ ...basePath,
7708
+ {
7709
+ intermediateCurrency: outputToken,
7710
+ fee: params.intermediatePoolKey.fee,
7711
+ tickSpacing: params.intermediatePoolKey.tickSpacing,
7712
+ hooks: params.intermediatePoolKey.hooks,
7713
+ hookData: params.intermediatePoolKey.hookData,
7714
+ },
7715
+ ]
7716
+ : basePath,
7619
7717
  amountIn: params.amountIn,
7620
- amountOutMinimum: params.ethOutMin,
7718
+ amountOutMinimum: params.amountOutMin,
7621
7719
  },
7622
7720
  ]);
7623
7721
  const settleParams = encodeAbiParameters([
@@ -7639,7 +7737,7 @@ const memecoinToEthWithPermit2 = (params) => {
7639
7737
  type: "uint256",
7640
7738
  name: "minAmount",
7641
7739
  },
7642
- ], [ETH, params.ethOutMin]);
7740
+ ], [outputToken, params.amountOutMin]);
7643
7741
  const v4RouterData = encodeAbiParameters([
7644
7742
  { type: "bytes", name: "actions" },
7645
7743
  { type: "bytes[]", name: "params" },
@@ -8142,7 +8240,11 @@ class ReadFlaunchPositionManager {
8142
8240
  const readInitialPrice = new ReadInitialPrice(await this.contract.read("initialPrice"), this.drift);
8143
8241
  const flaunchingFee = await readInitialPrice.getFlaunchingFee(params);
8144
8242
  // increase the flaunching fee by the slippage percent
8145
- const flaunchingFeeWithSlippage = getAmountWithSlippage(flaunchingFee, (params.slippagePercent ?? 0 / 100).toFixed(18).toString(), "EXACT_OUT");
8243
+ const flaunchingFeeWithSlippage = getAmountWithSlippage({
8244
+ amount: flaunchingFee,
8245
+ slippage: (params.slippagePercent ?? 0 / 100).toFixed(18).toString(),
8246
+ swapType: "EXACT_OUT",
8247
+ });
8146
8248
  return flaunchingFeeWithSlippage;
8147
8249
  }
8148
8250
  async watchPoolCreated({ onPoolCreated, startBlockNumber, }) {
@@ -12715,7 +12817,11 @@ class ReadFlaunchPositionManagerV1_1 {
12715
12817
  const readInitialPrice = new ReadInitialPrice(await this.contract.read("initialPrice"), this.drift);
12716
12818
  const flaunchingFee = await readInitialPrice.getFlaunchingFee(params);
12717
12819
  // increase the flaunching fee by the slippage percent
12718
- const flaunchingFeeWithSlippage = getAmountWithSlippage(flaunchingFee, (params.slippagePercent ?? 0 / 100).toFixed(18).toString(), "EXACT_OUT");
12820
+ const flaunchingFeeWithSlippage = getAmountWithSlippage({
12821
+ amount: flaunchingFee,
12822
+ slippage: (params.slippagePercent ?? 0 / 100).toFixed(18).toString(),
12823
+ swapType: "EXACT_OUT",
12824
+ });
12719
12825
  return flaunchingFeeWithSlippage;
12720
12826
  }
12721
12827
  async watchPoolCreated({ onPoolCreated, startBlockNumber, }) {
@@ -13004,15 +13110,22 @@ class ReadFlaunchZap {
13004
13110
  const mcapInWei = await this.readPositionManagerV1_1.getFlaunchingMarketCap(params.initialPriceParams);
13005
13111
  const premineCostInWei = (mcapInWei * params.premineAmount) / this.TOTAL_SUPPLY;
13006
13112
  // increase the premine cost by the slippage percent
13007
- const premineCostInWeiWithSlippage = getAmountWithSlippage(premineCostInWei, (params.slippagePercent ?? 0 / 100).toFixed(18).toString(), "EXACT_OUT" // as we know the output premine amount
13008
- );
13113
+ const premineCostInWeiWithSlippage = getAmountWithSlippage({
13114
+ amount: premineCostInWei,
13115
+ slippage: (params.slippagePercent ?? 0 / 100).toFixed(18).toString(),
13116
+ swapType: "EXACT_OUT", // as we know the output premine amount
13117
+ });
13009
13118
  return premineCostInWeiWithSlippage;
13010
13119
  }
13011
13120
  async getFlaunchingFee(params) {
13012
13121
  const readInitialPrice = new ReadInitialPrice(await this.readPositionManagerV1_1.initialPrice(), this.drift);
13013
13122
  const flaunchingFee = await readInitialPrice.getFlaunchingFee(params);
13014
13123
  // increase the flaunching fee by the slippage percent
13015
- const flaunchingFeeWithSlippage = getAmountWithSlippage(flaunchingFee, (params.slippagePercent ?? 0 / 100).toFixed(18).toString(), "EXACT_OUT");
13124
+ const flaunchingFeeWithSlippage = getAmountWithSlippage({
13125
+ amount: flaunchingFee,
13126
+ slippage: (params.slippagePercent ?? 0 / 100).toFixed(18).toString(),
13127
+ swapType: "EXACT_OUT",
13128
+ });
13016
13129
  return flaunchingFeeWithSlippage;
13017
13130
  }
13018
13131
  /**
@@ -14542,6 +14655,35 @@ class ReadMemecoin {
14542
14655
  account: user,
14543
14656
  });
14544
14657
  }
14658
+ /**
14659
+ * Gets the allowance of an ERC20 token to a spender
14660
+ * @param owner - The address of the owner to check
14661
+ * @param spender - The address of the spender to check
14662
+ * @returns Promise<bigint> - The allowance of the coin to the spender
14663
+ */
14664
+ allowance(owner, spender) {
14665
+ return this.contract.read("allowance", {
14666
+ owner,
14667
+ spender,
14668
+ });
14669
+ }
14670
+ }
14671
+ class ReadWriteMemecoin extends ReadMemecoin {
14672
+ constructor(address, drift = createDrift$1()) {
14673
+ super(address, drift);
14674
+ }
14675
+ /**
14676
+ * Approves an amount of the token to be spent by another address
14677
+ * @param spender - The address of the spender to approve
14678
+ * @param amount - The amount of the token to approve
14679
+ * @returns Promise<void> - The transaction receipt
14680
+ */
14681
+ approve(spender, amount) {
14682
+ return this.contract.write("approve", {
14683
+ spender,
14684
+ amount,
14685
+ });
14686
+ }
14545
14687
  }
14546
14688
 
14547
14689
  const QuoterAbi = [
@@ -14911,100 +15053,229 @@ class ReadQuoter {
14911
15053
  });
14912
15054
  }
14913
15055
  /**
14914
- * Gets a quote for selling an exact amount of tokens for ETH
15056
+ * Gets a quote for selling an exact amount of tokens for ETH or outputToken
14915
15057
  * @param coinAddress - The address of the token to sell
14916
15058
  * @param amountIn - The exact amount of tokens to sell
14917
15059
  * @param positionManagerAddress - The address of the position manager to use
15060
+ * @param intermediatePoolKey - Optional intermediate pool key to use containing outputToken and ETH as currencies
14918
15061
  * @returns Promise<bigint> - The expected amount of ETH to receive
14919
15062
  */
14920
- async getSellQuoteExactInput(coinAddress, amountIn, positionManagerAddress) {
14921
- const res = await this.contract.simulateWrite("quoteExactInput", {
14922
- params: {
14923
- exactAmount: amountIn,
14924
- exactCurrency: coinAddress,
14925
- path: [
14926
- {
14927
- fee: 0,
14928
- tickSpacing: 60,
14929
- hooks: positionManagerAddress,
14930
- hookData: "0x",
14931
- intermediateCurrency: FLETHAddress[this.chainId],
14932
- },
14933
- {
14934
- fee: 0,
14935
- tickSpacing: 60,
14936
- hookData: "0x",
14937
- hooks: FLETHHooksAddress[this.chainId],
14938
- intermediateCurrency: zeroAddress,
14939
- },
14940
- ],
14941
- },
14942
- });
14943
- return res.amountOut;
15063
+ async getSellQuoteExactInput({ coinAddress, amountIn, positionManagerAddress, intermediatePoolKey, }) {
15064
+ if (intermediatePoolKey) {
15065
+ // verify that ETH exists in the intermediate pool key
15066
+ if (intermediatePoolKey.currency0 !== zeroAddress &&
15067
+ intermediatePoolKey.currency1 !== zeroAddress) {
15068
+ throw new Error("ETH must be one of the currencies in the intermediatePoolKey");
15069
+ }
15070
+ const outputToken = intermediatePoolKey.currency0 === zeroAddress
15071
+ ? intermediatePoolKey.currency1
15072
+ : intermediatePoolKey.currency0;
15073
+ const res = await this.contract.simulateWrite("quoteExactInput", {
15074
+ params: {
15075
+ exactAmount: amountIn,
15076
+ exactCurrency: coinAddress,
15077
+ path: [
15078
+ {
15079
+ fee: 0,
15080
+ tickSpacing: 60,
15081
+ hooks: positionManagerAddress,
15082
+ hookData: "0x",
15083
+ intermediateCurrency: FLETHAddress[this.chainId],
15084
+ },
15085
+ {
15086
+ fee: 0,
15087
+ tickSpacing: 60,
15088
+ hookData: "0x",
15089
+ hooks: FLETHHooksAddress[this.chainId],
15090
+ intermediateCurrency: zeroAddress,
15091
+ },
15092
+ {
15093
+ fee: intermediatePoolKey.fee,
15094
+ tickSpacing: intermediatePoolKey.tickSpacing,
15095
+ hooks: intermediatePoolKey.hooks,
15096
+ hookData: intermediatePoolKey.hookData,
15097
+ intermediateCurrency: outputToken,
15098
+ },
15099
+ ],
15100
+ },
15101
+ });
15102
+ return res.amountOut;
15103
+ }
15104
+ else {
15105
+ const res = await this.contract.simulateWrite("quoteExactInput", {
15106
+ params: {
15107
+ exactAmount: amountIn,
15108
+ exactCurrency: coinAddress,
15109
+ path: [
15110
+ {
15111
+ fee: 0,
15112
+ tickSpacing: 60,
15113
+ hooks: positionManagerAddress,
15114
+ hookData: "0x",
15115
+ intermediateCurrency: FLETHAddress[this.chainId],
15116
+ },
15117
+ {
15118
+ fee: 0,
15119
+ tickSpacing: 60,
15120
+ hookData: "0x",
15121
+ hooks: FLETHHooksAddress[this.chainId],
15122
+ intermediateCurrency: zeroAddress,
15123
+ },
15124
+ ],
15125
+ },
15126
+ });
15127
+ return res.amountOut;
15128
+ }
14944
15129
  }
14945
15130
  /**
14946
- * Gets a quote for buying tokens with an exact amount of ETH
15131
+ * Gets a quote for buying tokens with an exact amount of ETH or inputToken
14947
15132
  * @param coinAddress - The address of the token to buy
14948
- * @param ethIn - The exact amount of ETH to spend
15133
+ * @param amountIn - The exact amount of ETH or inputToken to spend
14949
15134
  * @param positionManagerAddress - The address of the position manager to use
14950
- * @returns Promise<bigint> - The expected amount of tokens to receive
15135
+ * @param intermediatePoolKey - Optional intermediate pool key to use containing inputToken and ETH as currencies
15136
+ * @returns Promise<bigint> - The expected amount of coins to receive
14951
15137
  */
14952
- async getBuyQuoteExactInput(coinAddress, ethIn, positionManagerAddress) {
14953
- const res = await this.contract.simulateWrite("quoteExactInput", {
14954
- params: {
14955
- exactAmount: ethIn,
14956
- exactCurrency: zeroAddress,
14957
- path: [
14958
- {
14959
- fee: 0,
14960
- tickSpacing: 60,
14961
- hookData: "0x",
14962
- hooks: FLETHHooksAddress[this.chainId],
14963
- intermediateCurrency: FLETHAddress[this.chainId],
14964
- },
14965
- {
14966
- fee: 0,
14967
- tickSpacing: 60,
14968
- hooks: positionManagerAddress,
14969
- hookData: "0x",
14970
- intermediateCurrency: coinAddress,
14971
- },
14972
- ],
14973
- },
14974
- });
14975
- return res.amountOut;
15138
+ async getBuyQuoteExactInput({ coinAddress, amountIn, positionManagerAddress, intermediatePoolKey, }) {
15139
+ if (intermediatePoolKey) {
15140
+ // verify that ETH exists in the intermediate pool key
15141
+ if (intermediatePoolKey.currency0 !== zeroAddress &&
15142
+ intermediatePoolKey.currency1 !== zeroAddress) {
15143
+ throw new Error("ETH must be one of the currencies in the intermediatePoolKey");
15144
+ }
15145
+ const inputToken = intermediatePoolKey.currency0 === zeroAddress
15146
+ ? intermediatePoolKey.currency1
15147
+ : intermediatePoolKey.currency0;
15148
+ const res = await this.contract.simulateWrite("quoteExactInput", {
15149
+ params: {
15150
+ exactAmount: amountIn,
15151
+ exactCurrency: inputToken,
15152
+ path: [
15153
+ {
15154
+ fee: intermediatePoolKey.fee,
15155
+ tickSpacing: intermediatePoolKey.tickSpacing,
15156
+ hooks: intermediatePoolKey.hooks,
15157
+ hookData: intermediatePoolKey.hookData,
15158
+ intermediateCurrency: zeroAddress,
15159
+ },
15160
+ {
15161
+ fee: 0,
15162
+ tickSpacing: 60,
15163
+ hookData: "0x",
15164
+ hooks: FLETHHooksAddress[this.chainId],
15165
+ intermediateCurrency: FLETHAddress[this.chainId],
15166
+ },
15167
+ {
15168
+ fee: 0,
15169
+ tickSpacing: 60,
15170
+ hooks: positionManagerAddress,
15171
+ hookData: "0x",
15172
+ intermediateCurrency: coinAddress,
15173
+ },
15174
+ ],
15175
+ },
15176
+ });
15177
+ return res.amountOut;
15178
+ }
15179
+ else {
15180
+ const res = await this.contract.simulateWrite("quoteExactInput", {
15181
+ params: {
15182
+ exactAmount: amountIn,
15183
+ exactCurrency: zeroAddress,
15184
+ path: [
15185
+ {
15186
+ fee: 0,
15187
+ tickSpacing: 60,
15188
+ hookData: "0x",
15189
+ hooks: FLETHHooksAddress[this.chainId],
15190
+ intermediateCurrency: FLETHAddress[this.chainId],
15191
+ },
15192
+ {
15193
+ fee: 0,
15194
+ tickSpacing: 60,
15195
+ hooks: positionManagerAddress,
15196
+ hookData: "0x",
15197
+ intermediateCurrency: coinAddress,
15198
+ },
15199
+ ],
15200
+ },
15201
+ });
15202
+ return res.amountOut;
15203
+ }
14976
15204
  }
14977
15205
  /**
14978
- * Gets a quote for buying an exact amount of tokens with ETH
15206
+ * Gets a quote for buying an exact amount of tokens with ETH or inputToken
14979
15207
  * @param coinAddress - The address of the token to buy
14980
15208
  * @param coinOut - The exact amount of tokens to receive
14981
15209
  * @param positionManagerAddress - The address of the position manager to use
14982
- * @returns Promise<bigint> - The required amount of ETH to spend
15210
+ * @param intermediatePoolKey - Optional intermediate pool key to use containing inputToken and ETH as currencies
15211
+ * @returns Promise<bigint> - The required amount of ETH or inputToken to spend
14983
15212
  */
14984
- async getBuyQuoteExactOutput(coinAddress, coinOut, positionManagerAddress) {
14985
- const res = await this.contract.simulateWrite("quoteExactOutput", {
14986
- params: {
14987
- path: [
14988
- {
14989
- intermediateCurrency: zeroAddress,
14990
- fee: 0,
14991
- tickSpacing: 60,
14992
- hookData: "0x",
14993
- hooks: FLETHHooksAddress[this.chainId],
14994
- },
14995
- {
14996
- intermediateCurrency: FLETHAddress[this.chainId],
14997
- fee: 0,
14998
- tickSpacing: 60,
14999
- hooks: positionManagerAddress,
15000
- hookData: "0x",
15001
- },
15002
- ],
15003
- exactCurrency: coinAddress,
15004
- exactAmount: coinOut,
15005
- },
15006
- });
15007
- return res.amountIn;
15213
+ async getBuyQuoteExactOutput({ coinAddress, coinOut, positionManagerAddress, intermediatePoolKey, }) {
15214
+ if (intermediatePoolKey) {
15215
+ // verify that ETH exists in the intermediate pool key
15216
+ if (intermediatePoolKey.currency0 !== zeroAddress &&
15217
+ intermediatePoolKey.currency1 !== zeroAddress) {
15218
+ throw new Error("ETH must be one of the currencies in the intermediatePoolKey");
15219
+ }
15220
+ const inputToken = intermediatePoolKey.currency0 === zeroAddress
15221
+ ? intermediatePoolKey.currency1
15222
+ : intermediatePoolKey.currency0;
15223
+ const res = await this.contract.simulateWrite("quoteExactOutput", {
15224
+ params: {
15225
+ path: [
15226
+ {
15227
+ intermediateCurrency: inputToken,
15228
+ fee: intermediatePoolKey.fee,
15229
+ tickSpacing: intermediatePoolKey.tickSpacing,
15230
+ hookData: intermediatePoolKey.hookData,
15231
+ hooks: intermediatePoolKey.hooks,
15232
+ },
15233
+ {
15234
+ intermediateCurrency: zeroAddress,
15235
+ fee: 0,
15236
+ tickSpacing: 60,
15237
+ hookData: "0x",
15238
+ hooks: FLETHHooksAddress[this.chainId],
15239
+ },
15240
+ {
15241
+ intermediateCurrency: FLETHAddress[this.chainId],
15242
+ fee: 0,
15243
+ tickSpacing: 60,
15244
+ hooks: positionManagerAddress,
15245
+ hookData: "0x",
15246
+ },
15247
+ ],
15248
+ exactCurrency: coinAddress,
15249
+ exactAmount: coinOut,
15250
+ },
15251
+ });
15252
+ return res.amountIn;
15253
+ }
15254
+ else {
15255
+ const res = await this.contract.simulateWrite("quoteExactOutput", {
15256
+ params: {
15257
+ path: [
15258
+ {
15259
+ intermediateCurrency: zeroAddress,
15260
+ fee: 0,
15261
+ tickSpacing: 60,
15262
+ hookData: "0x",
15263
+ hooks: FLETHHooksAddress[this.chainId],
15264
+ },
15265
+ {
15266
+ intermediateCurrency: FLETHAddress[this.chainId],
15267
+ fee: 0,
15268
+ tickSpacing: 60,
15269
+ hooks: positionManagerAddress,
15270
+ hookData: "0x",
15271
+ },
15272
+ ],
15273
+ exactCurrency: coinAddress,
15274
+ exactAmount: coinOut,
15275
+ },
15276
+ });
15277
+ return res.amountIn;
15278
+ }
15008
15279
  }
15009
15280
  /**
15010
15281
  * Gets the current ETH/USDC price from the pool
@@ -17180,7 +17451,11 @@ class ReadFlaunchPositionManagerV1_2 {
17180
17451
  const readInitialPrice = new ReadInitialPrice(await this.contract.read("initialPrice"), this.drift);
17181
17452
  const flaunchingFee = await readInitialPrice.getFlaunchingFee(params);
17182
17453
  // increase the flaunching fee by the slippage percent
17183
- const flaunchingFeeWithSlippage = getAmountWithSlippage(flaunchingFee, (params.slippagePercent ?? 0 / 100).toFixed(18).toString(), "EXACT_OUT");
17454
+ const flaunchingFeeWithSlippage = getAmountWithSlippage({
17455
+ amount: flaunchingFee,
17456
+ slippage: (params.slippagePercent ?? 0 / 100).toFixed(18).toString(),
17457
+ swapType: "EXACT_OUT",
17458
+ });
17184
17459
  return flaunchingFeeWithSlippage;
17185
17460
  }
17186
17461
  async watchPoolCreated({ onPoolCreated, startBlockNumber, }) {
@@ -25377,35 +25652,53 @@ class ReadFlaunchSDK {
25377
25652
  /**
25378
25653
  * Gets a quote for selling an exact amount of tokens for ETH
25379
25654
  * @param coinAddress - The address of the token to sell
25655
+ * @param version - Optional specify Flaunch version, if not provided, will determine automatically
25380
25656
  * @param amountIn - The exact amount of tokens to sell
25381
- * @param version - Optional specific version to use
25657
+ * @param intermediatePoolKey - Optional intermediate pool key to use containing outputToken and ETH as currencies
25382
25658
  * @returns Promise<bigint> - The expected amount of ETH to receive
25383
25659
  */
25384
- async getSellQuoteExactInput(coinAddress, amountIn, version) {
25660
+ async getSellQuoteExactInput({ coinAddress, version, amountIn, intermediatePoolKey, }) {
25385
25661
  const coinVersion = version || (await this.getCoinVersion(coinAddress));
25386
- return this.readQuoter.getSellQuoteExactInput(coinAddress, amountIn, this.getPositionManagerAddress(coinVersion));
25662
+ return this.readQuoter.getSellQuoteExactInput({
25663
+ coinAddress,
25664
+ amountIn,
25665
+ positionManagerAddress: this.getPositionManagerAddress(coinVersion),
25666
+ intermediatePoolKey,
25667
+ });
25387
25668
  }
25388
25669
  /**
25389
- * Gets a quote for buying tokens with an exact amount of ETH
25670
+ * Gets a quote for buying tokens with an exact amount of ETH or inputToken
25390
25671
  * @param coinAddress - The address of the token to buy
25391
- * @param ethIn - The exact amount of ETH to spend
25392
- * @param version - Optional specific version to use
25393
- * @returns Promise<bigint> - The expected amount of tokens to receive
25672
+ * @param version - Optional specify Flaunch version, if not provided, will determine automatically
25673
+ * @param amountIn - The exact amount of ETH or inputToken to spend
25674
+ * @param intermediatePoolKey - Optional intermediate pool key to use containing inputToken and ETH as currencies
25675
+ * @returns Promise<bigint> - The expected amount of coins to receive
25394
25676
  */
25395
- async getBuyQuoteExactInput(coinAddress, amountIn, version) {
25677
+ async getBuyQuoteExactInput({ coinAddress, version, amountIn, intermediatePoolKey, }) {
25396
25678
  const coinVersion = version || (await this.getCoinVersion(coinAddress));
25397
- return this.readQuoter.getBuyQuoteExactInput(coinAddress, amountIn, this.getPositionManagerAddress(coinVersion));
25679
+ return this.readQuoter.getBuyQuoteExactInput({
25680
+ coinAddress,
25681
+ amountIn,
25682
+ positionManagerAddress: this.getPositionManagerAddress(coinVersion),
25683
+ intermediatePoolKey,
25684
+ });
25398
25685
  }
25399
25686
  /**
25400
- * Gets a quote for buying an exact amount of tokens with ETH
25687
+ * Gets a quote for buying an exact amount of tokens with ETH or inputToken
25401
25688
  * @param coinAddress - The address of the token to buy
25689
+ * @param version - Optional specify Flaunch version, if not provided, will determine automatically
25402
25690
  * @param coinOut - The exact amount of tokens to receive
25403
- * @param version - Optional specific version to use
25404
- * @returns Promise<bigint> - The required amount of ETH to spend
25691
+ * @param intermediatePoolKey - Optional intermediate pool key to use containing inputToken and ETH as currencies
25692
+ * @returns Promise<bigint> - The required amount of ETH or inputToken to spend
25405
25693
  */
25406
- async getBuyQuoteExactOutput(coinAddress, amountOut, version) {
25694
+ async getBuyQuoteExactOutput({ coinAddress, amountOut, version, intermediatePoolKey, }) {
25407
25695
  const coinVersion = version || (await this.getCoinVersion(coinAddress));
25408
- return this.readQuoter.getBuyQuoteExactOutput(coinAddress, amountOut, this.getPositionManagerAddress(coinVersion));
25696
+ return this.readQuoter.getBuyQuoteExactOutput({
25697
+ coinAddress,
25698
+ coinOut: amountOut,
25699
+ positionManagerAddress: this.getPositionManagerAddress(coinVersion),
25700
+ intermediatePoolKey,
25701
+ });
25409
25702
  }
25410
25703
  /**
25411
25704
  * Determines if flETH is currency0 in the pool
@@ -25556,7 +25849,25 @@ class ReadFlaunchSDK {
25556
25849
  };
25557
25850
  }
25558
25851
  }
25559
- async calculateAddLiquidityAmounts({ coinAddress, liquidityMode, coinOrEthInputAmount, inputToken, minMarketCap, maxMarketCap, currentMarketCap, }) {
25852
+ async calculateAddLiquidityAmounts(params) {
25853
+ const { coinAddress, liquidityMode, inputToken, coinOrEthInputAmount } = params;
25854
+ let minMarketCap;
25855
+ let maxMarketCap;
25856
+ let currentMarketCap;
25857
+ if ("minMarketCap" in params) {
25858
+ minMarketCap = params.minMarketCap;
25859
+ maxMarketCap = params.maxMarketCap;
25860
+ currentMarketCap = params.currentMarketCap;
25861
+ }
25862
+ else {
25863
+ const { totalSupply, decimals } = await this.getCoinInfo(coinAddress);
25864
+ const formattedTotalSupply = parseFloat(formatUnits$1(totalSupply, decimals));
25865
+ minMarketCap = (parseFloat(params.minPriceUSD) * formattedTotalSupply).toString();
25866
+ maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupply).toString();
25867
+ if (params.currentPriceUSD) {
25868
+ currentMarketCap = (params.currentPriceUSD * formattedTotalSupply).toString();
25869
+ }
25870
+ }
25560
25871
  let { tickLower, tickUpper, currentTick } = await this.calculateAddLiquidityTicks({
25561
25872
  coinAddress,
25562
25873
  liquidityMode,
@@ -25564,15 +25875,25 @@ class ReadFlaunchSDK {
25564
25875
  maxMarketCap,
25565
25876
  currentMarketCap,
25566
25877
  });
25878
+ // get the current pool state for the coin
25567
25879
  if (!currentTick) {
25568
- // get the current pool state for AnyPositionManager pool for the coin
25880
+ let version = params.version;
25881
+ // if version is not provided, check on existing managers, else default to ANY
25882
+ if (!version) {
25883
+ try {
25884
+ version = await this.getCoinVersion(coinAddress);
25885
+ }
25886
+ catch {
25887
+ version = FlaunchVersion.ANY;
25888
+ }
25889
+ }
25569
25890
  const poolState = await this.readStateView.poolSlot0({
25570
25891
  poolId: getPoolId(orderPoolKey({
25571
25892
  currency0: coinAddress,
25572
25893
  currency1: FLETHAddress[this.chainId],
25573
25894
  fee: 0,
25574
25895
  tickSpacing: TICK_SPACING,
25575
- hooks: AnyPositionManagerAddress[this.chainId],
25896
+ hooks: this.getPositionManagerAddress(version),
25576
25897
  })),
25577
25898
  });
25578
25899
  currentTick = poolState.tick;
@@ -25820,7 +26141,7 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
25820
26141
  return memecoin.balanceOf(user);
25821
26142
  }
25822
26143
  /**
25823
- * Buys a coin with ETH
26144
+ * Buys a coin with ETH or custom inputToken via intermediatePoolKey
25824
26145
  * @param params - Parameters for buying the coin including amount, slippage, and referrer
25825
26146
  * @param version - Optional specific version to use. If not provided, will determine automatically
25826
26147
  * @returns Transaction response for the buy operation
@@ -25836,8 +26157,16 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
25836
26157
  if (params.swapType === "EXACT_IN") {
25837
26158
  amountIn = params.amountIn;
25838
26159
  if (params.amountOutMin === undefined) {
25839
- // Currently only V1 and V1.1 are supported in the Quoter
25840
- amountOutMin = getAmountWithSlippage(await this.readQuoter.getBuyQuoteExactInput(params.coinAddress, amountIn, this.getPositionManagerAddress(coinVersion)), (params.slippagePercent / 100).toFixed(18).toString(), params.swapType);
26160
+ amountOutMin = getAmountWithSlippage({
26161
+ amount: await this.readQuoter.getBuyQuoteExactInput({
26162
+ coinAddress: params.coinAddress,
26163
+ amountIn,
26164
+ positionManagerAddress: this.getPositionManagerAddress(coinVersion),
26165
+ intermediatePoolKey: params.intermediatePoolKey,
26166
+ }),
26167
+ slippage: (params.slippagePercent / 100).toFixed(18).toString(),
26168
+ swapType: params.swapType,
26169
+ });
25841
26170
  }
25842
26171
  else {
25843
26172
  amountOutMin = params.amountOutMin;
@@ -25846,15 +26175,22 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
25846
26175
  else {
25847
26176
  amountOut = params.amountOut;
25848
26177
  if (params.amountInMax === undefined) {
25849
- // Currently only V1 and V1.1 are supported in the Quoter
25850
- amountInMax = getAmountWithSlippage(await this.readQuoter.getBuyQuoteExactOutput(params.coinAddress, amountOut, this.getPositionManagerAddress(coinVersion)), (params.slippagePercent / 100).toFixed(18).toString(), params.swapType);
26178
+ amountInMax = getAmountWithSlippage({
26179
+ amount: await this.readQuoter.getBuyQuoteExactOutput({
26180
+ coinAddress: params.coinAddress,
26181
+ coinOut: amountOut,
26182
+ positionManagerAddress: this.getPositionManagerAddress(coinVersion),
26183
+ intermediatePoolKey: params.intermediatePoolKey,
26184
+ }),
26185
+ slippage: (params.slippagePercent / 100).toFixed(18).toString(),
26186
+ swapType: params.swapType,
26187
+ });
25851
26188
  }
25852
26189
  else {
25853
26190
  amountInMax = params.amountInMax;
25854
26191
  }
25855
26192
  }
25856
- // When UniversalRouter supports isAny parameter, add it here
25857
- const { commands, inputs } = ethToMemecoin({
26193
+ const { commands, inputs } = buyMemecoin({
25858
26194
  sender: sender,
25859
26195
  memecoin: params.coinAddress,
25860
26196
  chainId: this.chainId,
@@ -25865,6 +26201,9 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
25865
26201
  amountOut: amountOut,
25866
26202
  amountInMax: amountInMax,
25867
26203
  positionManagerAddress: this.getPositionManagerAddress(coinVersion),
26204
+ intermediatePoolKey: params.intermediatePoolKey,
26205
+ permitSingle: params.permitSingle,
26206
+ signature: params.signature,
25868
26207
  });
25869
26208
  return this.drift.adapter.write({
25870
26209
  abi: UniversalRouterAbi,
@@ -25874,7 +26213,11 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
25874
26213
  commands,
25875
26214
  inputs,
25876
26215
  },
25877
- value: params.swapType === "EXACT_IN" ? amountIn : amountInMax,
26216
+ value: params.intermediatePoolKey
26217
+ ? 0n // 0 ETH as inputToken is in another currency
26218
+ : params.swapType === "EXACT_IN"
26219
+ ? amountIn
26220
+ : amountInMax,
25878
26221
  });
25879
26222
  }
25880
26223
  /**
@@ -25885,26 +26228,34 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
25885
26228
  */
25886
26229
  async sellCoin(params, version) {
25887
26230
  const coinVersion = version || (await this.getCoinVersion(params.coinAddress));
25888
- let ethOutMin;
26231
+ let amountOutMin;
25889
26232
  await this.readQuoter.contract.cache.clear();
25890
- if (params.ethOutMin === undefined) {
25891
- // Currently only V1 and V1.1 are supported in the Quoter
25892
- ethOutMin = getAmountWithSlippage(await this.readQuoter.getSellQuoteExactInput(params.coinAddress, params.amountIn, this.getPositionManagerAddress(coinVersion)), (params.slippagePercent / 100).toFixed(18).toString(), "EXACT_IN");
26233
+ if (params.amountOutMin === undefined) {
26234
+ amountOutMin = getAmountWithSlippage({
26235
+ amount: await this.readQuoter.getSellQuoteExactInput({
26236
+ coinAddress: params.coinAddress,
26237
+ amountIn: params.amountIn,
26238
+ positionManagerAddress: this.getPositionManagerAddress(coinVersion),
26239
+ intermediatePoolKey: params.intermediatePoolKey,
26240
+ }),
26241
+ slippage: (params.slippagePercent / 100).toFixed(18).toString(),
26242
+ swapType: "EXACT_IN",
26243
+ });
25893
26244
  }
25894
26245
  else {
25895
- ethOutMin = params.ethOutMin;
26246
+ amountOutMin = params.amountOutMin;
25896
26247
  }
25897
26248
  await this.readPermit2.contract.cache.clear();
25898
- // When UniversalRouter supports isAny parameter, add it here
25899
- const { commands, inputs } = memecoinToEthWithPermit2({
26249
+ const { commands, inputs } = sellMemecoinWithPermit2({
25900
26250
  chainId: this.chainId,
25901
26251
  memecoin: params.coinAddress,
25902
26252
  amountIn: params.amountIn,
25903
- ethOutMin,
26253
+ amountOutMin,
25904
26254
  permitSingle: params.permitSingle,
25905
26255
  signature: params.signature,
25906
26256
  referrer: params.referrer ?? null,
25907
26257
  positionManagerAddress: this.getPositionManagerAddress(coinVersion),
26258
+ intermediatePoolKey: params.intermediatePoolKey,
25908
26259
  });
25909
26260
  return this.drift.write({
25910
26261
  abi: UniversalRouterAbi,
@@ -25945,6 +26296,27 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
25945
26296
  nonce,
25946
26297
  };
25947
26298
  }
26299
+ /**
26300
+ * Gets the allowance of an ERC20 token to Permit2 contract. Flaunch coins automatically have infinite approval for Permit2.
26301
+ * this function is for external tokens.
26302
+ * @param coinAddress - The address of the coin to check
26303
+ * @returns Promise<bigint> - The allowance of the coin to Permit2
26304
+ */
26305
+ async getERC20AllowanceToPermit2(coinAddress) {
26306
+ const coin = new ReadMemecoin(coinAddress, this.drift);
26307
+ return coin.allowance(await this.drift.getSignerAddress(), Permit2Address[this.chainId]);
26308
+ }
26309
+ /**
26310
+ * Sets the allowance of an ERC20 token to Permit2 contract. Flaunch coins automatically have infinite approval for Permit2.
26311
+ * this function is for external tokens.
26312
+ * @param coinAddress - The address of the coin to approve
26313
+ * @param amount - The amount of the token to approve
26314
+ * @returns Promise<Hex> - The transaction hash
26315
+ */
26316
+ async setERC20AllowanceToPermit2(coinAddress, amount) {
26317
+ const coin = new ReadWriteMemecoin(coinAddress, this.drift);
26318
+ return coin.approve(Permit2Address[this.chainId], amount);
26319
+ }
25948
26320
  /**
25949
26321
  * Withdraws the creator's share of the revenue
25950
26322
  * @param params - Parameters for withdrawing the creator's share of the revenue
@@ -26078,12 +26450,21 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
26078
26450
  let tickLower;
26079
26451
  let tickUpper;
26080
26452
  let currentTick;
26453
+ let version = params.version;
26454
+ if (!version) {
26455
+ try {
26456
+ version = await this.getCoinVersion(coinAddress);
26457
+ }
26458
+ catch {
26459
+ version = FlaunchVersion.ANY;
26460
+ }
26461
+ }
26081
26462
  const poolKey = orderPoolKey({
26082
26463
  currency0: coinAddress,
26083
26464
  currency1: flethAddress,
26084
26465
  fee: 0,
26085
26466
  tickSpacing: this.TICK_SPACING,
26086
- hooks: AnyPositionManagerAddress[this.chainId],
26467
+ hooks: this.getPositionManagerAddress(version),
26087
26468
  });
26088
26469
  // Check if we need to calculate values or use direct values
26089
26470
  if ("tickLower" in params) {
@@ -26129,6 +26510,7 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
26129
26510
  minMarketCap,
26130
26511
  maxMarketCap,
26131
26512
  currentMarketCap: initialMarketCapUSD?.toString(),
26513
+ version,
26132
26514
  });
26133
26515
  coinAmount = calculated.coinAmount;
26134
26516
  flethAmount = calculated.ethAmount;
@@ -26442,7 +26824,10 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
26442
26824
  initialMarketCapUSD: params.initialMarketCapUSD,
26443
26825
  verifier: params.verifier,
26444
26826
  });
26445
- const addLiquidityCalls = await this.getAddLiquidityCalls(params);
26827
+ const addLiquidityCalls = await this.getAddLiquidityCalls({
26828
+ ...params,
26829
+ version: FlaunchVersion.ANY, // optimize to avoid fetching if not passed
26830
+ });
26446
26831
  return [
26447
26832
  {
26448
26833
  to: this.readWriteTokenImporter.contract.address,
@@ -26497,5 +26882,5 @@ const FlaunchSDK = {
26497
26882
  ReadWriteFlaunchSDK,
26498
26883
  };
26499
26884
 
26500
- export { AddressFeeSplitManagerAddress, AnyBidWallAddress, AnyFlaunchAddress, AnyPositionManagerAbi, AnyPositionManagerAddress, BidWallAddress, BidWallV1_1Abi, BidWallV1_1Address, BidwallAbi, ClankerWorldVerifierAddress, ClosedPermissionsAddress, DopplerVerifierAddress, FLETHAddress, FLETHHooksAddress, FairLaunchAbi, FairLaunchAddress, FairLaunchV1_1Abi, FairLaunchV1_1Address, FastFlaunchZapAbi, FastFlaunchZapAddress, FeeEscrowAbi, FeeEscrowAddress, FlaunchAbi, FlaunchAddress, FlaunchPositionManagerAbi, FlaunchPositionManagerAddress, FlaunchPositionManagerV1_1Abi, FlaunchPositionManagerV1_1Address, FlaunchPositionManagerV1_2Address, FlaunchSDK, FlaunchV1_1Abi, FlaunchV1_1Address, FlaunchV1_2Address, FlaunchVersion, FlaunchZapAbi, FlaunchZapAddress, InitialPriceAbi, LiquidityMode, MemecoinAbi, MulticallAbi, PERMIT_DETAILS, PERMIT_TYPES, Permissions, Permit2Abi, Permit2Address, PoolManagerAbi, PoolManagerAddress, Q192, Q96, QuoterAbi, QuoterAddress, ReadFlaunchSDK, ReadWriteFlaunchSDK, ReferralEscrowAbi, ReferralEscrowAddress, RevenueManagerAbi, RevenueManagerAddress, StakingManagerAddress, StateViewAbi, StateViewAddress, TICK_SPACING, TickFinder, TokenImporterAddress, TreasuryManagerFactoryAbi, TreasuryManagerFactoryAddress, USDCETHPoolKeys, UniV4PositionManagerAddress, UniversalRouterAbi, UniversalRouterAddress, Verifier, VirtualsVerifierAddress, WhitelistVerifierAddress, WhitelistedPermissionsAddress, ZoraVerifierAddress, bytes32ToUint256, calculateUnderlyingTokenBalances, chainIdToChain, createDrift, createFlaunch, ethToMemecoin, generateTokenUri, getAmountWithSlippage, getAmountsForLiquidity, getLiquidityFromAmounts, getNearestUsableTick, getPermissionsAddress, getPermit2TypedData, getPoolId, getSqrtPriceX96FromTick, getValidTick, maxLiquidityForAmount0Precise, maxLiquidityForAmount1, memecoinToEthWithPermit2, orderPoolKey, parseSwapData, priceRatioToTick, resolveIPFS, uint256ToBytes32, uploadFileToIPFS, uploadImageToIPFS, uploadJsonToIPFS };
26885
+ export { AddressFeeSplitManagerAddress, AnyBidWallAddress, AnyFlaunchAddress, AnyPositionManagerAbi, AnyPositionManagerAddress, BidWallAddress, BidWallV1_1Abi, BidWallV1_1Address, BidwallAbi, ClankerWorldVerifierAddress, ClosedPermissionsAddress, DopplerVerifierAddress, FLETHAddress, FLETHHooksAddress, FairLaunchAbi, FairLaunchAddress, FairLaunchV1_1Abi, FairLaunchV1_1Address, FastFlaunchZapAbi, FastFlaunchZapAddress, FeeEscrowAbi, FeeEscrowAddress, FlaunchAbi, FlaunchAddress, FlaunchPositionManagerAbi, FlaunchPositionManagerAddress, FlaunchPositionManagerV1_1Abi, FlaunchPositionManagerV1_1Address, FlaunchPositionManagerV1_2Address, FlaunchSDK, FlaunchV1_1Abi, FlaunchV1_1Address, FlaunchV1_2Address, FlaunchVersion, FlaunchZapAbi, FlaunchZapAddress, InitialPriceAbi, LiquidityMode, MemecoinAbi, MulticallAbi, PERMIT_DETAILS, PERMIT_TYPES, Permissions, Permit2Abi, Permit2Address, PoolManagerAbi, PoolManagerAddress, Q192, Q96, QuoterAbi, QuoterAddress, ReadFlaunchSDK, ReadWriteFlaunchSDK, ReferralEscrowAbi, ReferralEscrowAddress, RevenueManagerAbi, RevenueManagerAddress, StakingManagerAddress, StateViewAbi, StateViewAddress, TICK_SPACING, TickFinder, TokenImporterAddress, TreasuryManagerFactoryAbi, TreasuryManagerFactoryAddress, USDCETHPoolKeys, UniV4PositionManagerAddress, UniversalRouterAbi, UniversalRouterAddress, Verifier, VirtualsVerifierAddress, WhitelistVerifierAddress, WhitelistedPermissionsAddress, ZoraVerifierAddress, buyMemecoin, bytes32ToUint256, calculateUnderlyingTokenBalances, chainIdToChain, createDrift, createFlaunch, generateTokenUri, getAmountWithSlippage, getAmountsForLiquidity, getLiquidityFromAmounts, getNearestUsableTick, getPermissionsAddress, getPermit2TypedData, getPoolId, getSqrtPriceX96FromTick, getValidTick, maxLiquidityForAmount0Precise, maxLiquidityForAmount1, orderPoolKey, parseSwapData, priceRatioToTick, resolveIPFS, sellMemecoinWithPermit2, uint256ToBytes32, uploadFileToIPFS, uploadImageToIPFS, uploadJsonToIPFS };
26501
26886
  //# sourceMappingURL=index.esm.js.map