@flaunch/sdk 0.9.7 → 0.9.8-beta.0

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.cjs.js CHANGED
@@ -5786,6 +5786,10 @@ const ZoraVerifierAddress = {
5786
5786
  [base.id]: "0x656047fd43d2c3a121f2ef859d7171d7dd59f8b9",
5787
5787
  [baseSepolia.id]: "0x05a5763e9199b88bb591c6b112d0424b2cd7a99e",
5788
5788
  };
5789
+ const SolanaVerifierAddress = {
5790
+ [base.id]: "0x0000000000000000000000000000000000000000",
5791
+ [baseSepolia.id]: "0x47226918E518f205584bd75Bf81E0b532B0B3Ea7",
5792
+ };
5789
5793
  /** ======== */
5790
5794
  /** Permissions */
5791
5795
  const ClosedPermissionsAddress = {
@@ -11893,6 +11897,7 @@ exports.Verifier = void 0;
11893
11897
  Verifier["VIRTUALS"] = "virtuals";
11894
11898
  Verifier["WHITELIST"] = "whitelist";
11895
11899
  Verifier["ZORA"] = "zora";
11900
+ Verifier["SOLANA"] = "solana";
11896
11901
  })(exports.Verifier || (exports.Verifier = {}));
11897
11902
  exports.LiquidityMode = void 0;
11898
11903
  (function (LiquidityMode) {
@@ -20363,6 +20368,8 @@ class ReadTokenImporter {
20363
20368
  return WhitelistVerifierAddress[this.chainId];
20364
20369
  case exports.Verifier.ZORA:
20365
20370
  return ZoraVerifierAddress[this.chainId];
20371
+ case exports.Verifier.SOLANA:
20372
+ return SolanaVerifierAddress[this.chainId];
20366
20373
  default:
20367
20374
  throw new Error(`Unknown verifier: ${verifier}`);
20368
20375
  }
@@ -26939,7 +26946,8 @@ class ReadFlaunchSDK {
26939
26946
  memecoin.totalSupply(),
26940
26947
  memecoin.decimals(),
26941
26948
  ]);
26942
- return { totalSupply, decimals };
26949
+ const formattedTotalSupplyInDecimals = parseFloat(viem.formatUnits(totalSupply, decimals));
26950
+ return { totalSupply, decimals, formattedTotalSupplyInDecimals };
26943
26951
  }
26944
26952
  /**
26945
26953
  * Gets market context information needed for tick calculations
@@ -26961,8 +26969,8 @@ class ReadFlaunchSDK {
26961
26969
  /**
26962
26970
  * Converts market cap in USD to token price in ETH
26963
26971
  */
26964
- marketCapToTokenPriceEth(marketCapUsd, totalSupplyDecimal, ethUsdPrice) {
26965
- const tokenPriceUsd = marketCapUsd / totalSupplyDecimal;
26972
+ marketCapToTokenPriceEth(marketCapUsd, formattedTotalSupplyInDecimals, ethUsdPrice) {
26973
+ const tokenPriceUsd = marketCapUsd / formattedTotalSupplyInDecimals;
26966
26974
  return tokenPriceUsd / ethUsdPrice;
26967
26975
  }
26968
26976
  /**
@@ -26980,24 +26988,22 @@ class ReadFlaunchSDK {
26980
26988
  /**
26981
26989
  * Calculates current tick from market cap if provided
26982
26990
  */
26983
- calculateCurrentTickFromMarketCap(currentMarketCap, totalSupplyDecimal, marketContext) {
26991
+ calculateCurrentTickFromMarketCap(currentMarketCap, formattedTotalSupplyInDecimals, marketContext) {
26984
26992
  if (!currentMarketCap) {
26985
26993
  return undefined;
26986
26994
  }
26987
26995
  const currentMarketCapNum = parseFloat(currentMarketCap);
26988
- const currentTokenPriceEth = this.marketCapToTokenPriceEth(currentMarketCapNum, totalSupplyDecimal, marketContext.ethUsdPrice);
26996
+ const currentTokenPriceEth = this.marketCapToTokenPriceEth(currentMarketCapNum, formattedTotalSupplyInDecimals, marketContext.ethUsdPrice);
26989
26997
  return this.convertPriceToTick(currentTokenPriceEth, marketContext.isFlethZero, marketContext.decimals0, marketContext.decimals1);
26990
26998
  }
26991
26999
  async calculateAddLiquidityTicks({ coinAddress, liquidityMode, minMarketCap, maxMarketCap, currentMarketCap, }) {
26992
27000
  // Get coin information
26993
- const { totalSupply: coinTotalSupply, decimals: coinDecimals } = await this.getCoinInfo(coinAddress);
26994
- // Convert total supply to decimal format
26995
- const totalSupplyDecimal = parseFloat(viem.formatEther(coinTotalSupply));
27001
+ const { totalSupply: coinTotalSupply, decimals: coinDecimals, formattedTotalSupplyInDecimals, } = await this.getCoinInfo(coinAddress);
26996
27002
  if (liquidityMode === exports.LiquidityMode.FULL_RANGE) {
26997
27003
  let currentTick;
26998
27004
  if (currentMarketCap) {
26999
27005
  const marketContext = await this.getMarketContext(coinAddress, coinDecimals);
27000
- currentTick = this.calculateCurrentTickFromMarketCap(currentMarketCap, totalSupplyDecimal, marketContext);
27006
+ currentTick = this.calculateCurrentTickFromMarketCap(currentMarketCap, formattedTotalSupplyInDecimals, marketContext);
27001
27007
  }
27002
27008
  return {
27003
27009
  tickLower: getNearestUsableTick({
@@ -27024,13 +27030,13 @@ class ReadFlaunchSDK {
27024
27030
  throw new Error("[ReadFlaunchSDK.addLiquidityCalculateTicks]: Invalid market cap range");
27025
27031
  }
27026
27032
  // Convert market caps to token prices in ETH
27027
- const minTokenPriceEth = this.marketCapToTokenPriceEth(minMarketCapNum, totalSupplyDecimal, marketContext.ethUsdPrice);
27028
- const maxTokenPriceEth = this.marketCapToTokenPriceEth(maxMarketCapNum, totalSupplyDecimal, marketContext.ethUsdPrice);
27033
+ const minTokenPriceEth = this.marketCapToTokenPriceEth(minMarketCapNum, formattedTotalSupplyInDecimals, marketContext.ethUsdPrice);
27034
+ const maxTokenPriceEth = this.marketCapToTokenPriceEth(maxMarketCapNum, formattedTotalSupplyInDecimals, marketContext.ethUsdPrice);
27029
27035
  // Convert to ticks
27030
27036
  const minTick = this.convertPriceToTick(minTokenPriceEth, marketContext.isFlethZero, marketContext.decimals0, marketContext.decimals1);
27031
27037
  const maxTick = this.convertPriceToTick(maxTokenPriceEth, marketContext.isFlethZero, marketContext.decimals0, marketContext.decimals1);
27032
27038
  // Calculate current tick if provided
27033
- const currentTick = this.calculateCurrentTickFromMarketCap(currentMarketCap, totalSupplyDecimal, marketContext);
27039
+ const currentTick = this.calculateCurrentTickFromMarketCap(currentMarketCap, formattedTotalSupplyInDecimals, marketContext);
27034
27040
  return {
27035
27041
  tickLower: Math.min(minTick, maxTick),
27036
27042
  tickUpper: Math.max(minTick, maxTick),
@@ -27051,12 +27057,11 @@ class ReadFlaunchSDK {
27051
27057
  currentMarketCap = params.currentMarketCap;
27052
27058
  }
27053
27059
  else {
27054
- const { totalSupply, decimals } = await this.getCoinInfo(coinAddress);
27055
- const formattedTotalSupply = parseFloat(viem.formatUnits(totalSupply, decimals));
27056
- minMarketCap = (parseFloat(params.minPriceUSD) * formattedTotalSupply).toString();
27057
- maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupply).toString();
27060
+ const { formattedTotalSupplyInDecimals } = await this.getCoinInfo(coinAddress);
27061
+ minMarketCap = (parseFloat(params.minPriceUSD) * formattedTotalSupplyInDecimals).toString();
27062
+ maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupplyInDecimals).toString();
27058
27063
  if (params.currentPriceUSD) {
27059
- currentMarketCap = (params.currentPriceUSD * formattedTotalSupply).toString();
27064
+ currentMarketCap = (params.currentPriceUSD * formattedTotalSupplyInDecimals).toString();
27060
27065
  }
27061
27066
  }
27062
27067
  let { tickLower, tickUpper, currentTick } = await this.calculateAddLiquidityTicks({
@@ -27127,12 +27132,11 @@ class ReadFlaunchSDK {
27127
27132
  currentMarketCap = params.currentMarketCap;
27128
27133
  }
27129
27134
  else {
27130
- const { totalSupply, decimals } = await this.getCoinInfo(coinAddress);
27131
- const formattedTotalSupply = parseFloat(viem.formatUnits(totalSupply, decimals));
27132
- minMarketCap = (parseFloat(params.minPriceUSD) * formattedTotalSupply).toString();
27133
- maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupply).toString();
27135
+ const { formattedTotalSupplyInDecimals } = await this.getCoinInfo(coinAddress);
27136
+ minMarketCap = (parseFloat(params.minPriceUSD) * formattedTotalSupplyInDecimals).toString();
27137
+ maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupplyInDecimals).toString();
27134
27138
  if (params.currentPriceUSD) {
27135
- currentMarketCap = (params.currentPriceUSD * formattedTotalSupply).toString();
27139
+ currentMarketCap = (params.currentPriceUSD * formattedTotalSupplyInDecimals).toString();
27136
27140
  }
27137
27141
  }
27138
27142
  let { tickLower, tickUpper, currentTick } = await this.calculateAddLiquidityTicks({
@@ -27796,12 +27800,12 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
27796
27800
  initialMarketCapUSD = params.initialMarketCapUSD;
27797
27801
  }
27798
27802
  else {
27799
- const { totalSupply, decimals } = await this.getCoinInfo(coinAddress);
27800
- const formattedTotalSupply = parseFloat(viem.formatUnits(totalSupply, decimals));
27801
- minMarketCap = (parseFloat(params.minPriceUSD) * formattedTotalSupply).toString();
27802
- maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupply).toString();
27803
+ const { formattedTotalSupplyInDecimals } = await this.getCoinInfo(coinAddress);
27804
+ minMarketCap = (parseFloat(params.minPriceUSD) * formattedTotalSupplyInDecimals).toString();
27805
+ maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupplyInDecimals).toString();
27803
27806
  if (params.initialPriceUSD) {
27804
- initialMarketCapUSD = params.initialPriceUSD * formattedTotalSupply;
27807
+ initialMarketCapUSD =
27808
+ params.initialPriceUSD * formattedTotalSupplyInDecimals;
27805
27809
  }
27806
27810
  }
27807
27811
  const calculated = await this.calculateAddLiquidityAmounts({
@@ -27971,18 +27975,27 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
27971
27975
  calls.push(this.createLiquidityCall(poolKey, tickLower, tickUpper, finalLiquidity, finalAmount0, finalAmount1, userAddress));
27972
27976
  return calls;
27973
27977
  }
27974
- /**
27975
- * Gets the calls needed to import a memecoin to Flaunch and add liquidity to AnyPositionManager as a batch
27976
- * @param params - Parameters for importing and adding liquidity
27977
- * @returns Array of calls with descriptions
27978
- */
27978
+ // Implementation with union type for internal use
27979
27979
  async getImportAndAddLiquidityCalls(params) {
27980
- const importParams = await this.readWriteTokenImporter.getInitializeParams({
27981
- coinAddress: params.coinAddress,
27982
- creatorFeeAllocationPercent: params.creatorFeeAllocationPercent,
27983
- initialMarketCapUSD: params.initialMarketCapUSD,
27984
- verifier: params.verifier,
27985
- });
27980
+ let importParams;
27981
+ if ("initialMarketCapUSD" in params) {
27982
+ const paramsWithMarketCap = params;
27983
+ importParams = await this.readWriteTokenImporter.getInitializeParams({
27984
+ coinAddress: paramsWithMarketCap.coinAddress,
27985
+ creatorFeeAllocationPercent: paramsWithMarketCap.creatorFeeAllocationPercent,
27986
+ initialMarketCapUSD: paramsWithMarketCap.initialMarketCapUSD,
27987
+ verifier: paramsWithMarketCap.verifier,
27988
+ });
27989
+ }
27990
+ else {
27991
+ const paramsWithPrice = params;
27992
+ importParams = await this.readWriteTokenImporter.getInitializeParams({
27993
+ coinAddress: paramsWithPrice.coinAddress,
27994
+ creatorFeeAllocationPercent: paramsWithPrice.creatorFeeAllocationPercent,
27995
+ initialPriceUSD: paramsWithPrice.initialPriceUSD,
27996
+ verifier: paramsWithPrice.verifier,
27997
+ });
27998
+ }
27986
27999
  const addLiquidityCalls = await this.getAddLiquidityCalls({
27987
28000
  ...params,
27988
28001
  version: exports.FlaunchVersion.ANY, // optimize to avoid fetching if not passed
@@ -28005,11 +28018,38 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
28005
28018
  const { coinAddress, coinAmount } = params;
28006
28019
  const version = await this.determineCoinVersion(coinAddress, params.version);
28007
28020
  const poolKey = this.createPoolKey(coinAddress, version);
28008
- // get the current tick from the pool
28009
- const poolState = await this.readStateView.poolSlot0({
28010
- poolId: getPoolId(poolKey),
28011
- });
28012
- const currentTick = poolState.tick;
28021
+ let currentTick;
28022
+ // if initial marketcap or price is provided, it means that the pool is not initialized yet
28023
+ // so determining the currentTick
28024
+ if (("initialMarketCapUSD" in params && params.initialMarketCapUSD) ||
28025
+ ("initialPriceUSD" in params && params.initialPriceUSD)) {
28026
+ const { decimals: coinDecimals, formattedTotalSupplyInDecimals } = await this.getCoinInfo(coinAddress);
28027
+ // Determine market cap based on provided parameter
28028
+ let initialMarketCapUSD;
28029
+ if ("initialMarketCapUSD" in params && params.initialMarketCapUSD) {
28030
+ initialMarketCapUSD = params.initialMarketCapUSD;
28031
+ }
28032
+ else if ("initialPriceUSD" in params && params.initialPriceUSD) {
28033
+ initialMarketCapUSD =
28034
+ params.initialPriceUSD * formattedTotalSupplyInDecimals;
28035
+ }
28036
+ else {
28037
+ throw new Error("Either initialMarketCapUSD or initialPriceUSD must be provided");
28038
+ }
28039
+ const marketContext = await this.getMarketContext(coinAddress, coinDecimals);
28040
+ const calculatedTick = this.calculateCurrentTickFromMarketCap(initialMarketCapUSD.toString(), formattedTotalSupplyInDecimals, marketContext);
28041
+ if (calculatedTick === undefined) {
28042
+ throw new Error("Failed to calculate current tick from market cap");
28043
+ }
28044
+ currentTick = calculatedTick;
28045
+ }
28046
+ else {
28047
+ // the pool is already initialized, get the current tick from the pool
28048
+ const poolState = await this.readStateView.poolSlot0({
28049
+ poolId: getPoolId(poolKey),
28050
+ });
28051
+ currentTick = poolState.tick;
28052
+ }
28013
28053
  // We want to add liquidity from current price to infinity (as coin appreciates vs flETH)
28014
28054
  // This means providing single-sided coin liquidity that becomes active as coin price increases
28015
28055
  const isFLETHZero = this.flETHIsCurrencyZero(coinAddress);
@@ -28122,6 +28162,43 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
28122
28162
  calls.push(this.createLiquidityCall(poolKey, tickLower, tickUpper, finalLiquidity, finalAmount0, finalAmount1, userAddress));
28123
28163
  return calls;
28124
28164
  }
28165
+ // Implementation with union type for internal use
28166
+ async getImportAndSingleSidedCoinAddLiquidityCalls(params) {
28167
+ let importParams;
28168
+ if ("initialMarketCapUSD" in params) {
28169
+ const paramsWithMarketCap = params;
28170
+ importParams = await this.readWriteTokenImporter.getInitializeParams({
28171
+ coinAddress: paramsWithMarketCap.coinAddress,
28172
+ creatorFeeAllocationPercent: paramsWithMarketCap.creatorFeeAllocationPercent,
28173
+ initialMarketCapUSD: paramsWithMarketCap.initialMarketCapUSD,
28174
+ verifier: paramsWithMarketCap.verifier,
28175
+ });
28176
+ }
28177
+ else {
28178
+ const paramsWithPrice = params;
28179
+ importParams = await this.readWriteTokenImporter.getInitializeParams({
28180
+ coinAddress: paramsWithPrice.coinAddress,
28181
+ creatorFeeAllocationPercent: paramsWithPrice.creatorFeeAllocationPercent,
28182
+ initialPriceUSD: paramsWithPrice.initialPriceUSD,
28183
+ verifier: paramsWithPrice.verifier,
28184
+ });
28185
+ }
28186
+ const addLiquidityCalls = await this.getSingleSidedCoinAddLiquidityCalls({
28187
+ ...params,
28188
+ version: exports.FlaunchVersion.ANY, // optimize to avoid fetching if not passed
28189
+ });
28190
+ return [
28191
+ {
28192
+ to: this.readWriteTokenImporter.contract.address,
28193
+ data: this.readWriteTokenImporter.contract.encodeFunctionData("initialize", importParams),
28194
+ description: "Import Memecoin to Flaunch",
28195
+ },
28196
+ ...addLiquidityCalls,
28197
+ ];
28198
+ }
28199
+ /**
28200
+ * === Private helper functions ===
28201
+ */
28125
28202
  /**
28126
28203
  * Calculates and constrains liquidity amounts for a position
28127
28204
  * @param currentTick - Current pool tick
@@ -31992,6 +32069,7 @@ exports.ReferralEscrowAbi = ReferralEscrowAbi;
31992
32069
  exports.ReferralEscrowAddress = ReferralEscrowAddress;
31993
32070
  exports.RevenueManagerAbi = RevenueManagerAbi;
31994
32071
  exports.RevenueManagerAddress = RevenueManagerAddress;
32072
+ exports.SolanaVerifierAddress = SolanaVerifierAddress;
31995
32073
  exports.StakingManagerAddress = StakingManagerAddress;
31996
32074
  exports.StateViewAbi = StateViewAbi;
31997
32075
  exports.StateViewAddress = StateViewAddress;