@flaunch/sdk 0.9.6 → 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/README.md +66 -0
- package/dist/addresses/index.cjs +5 -0
- package/dist/addresses/index.cjs.map +1 -1
- package/dist/addresses/index.js +5 -1
- package/dist/addresses/index.js.map +1 -1
- package/dist/addresses.d.ts +1 -0
- package/dist/addresses.d.ts.map +1 -1
- package/dist/clients/TokenImporter.d.ts.map +1 -1
- package/dist/helpers/index.cjs +1 -0
- package/dist/helpers/index.cjs.map +1 -1
- package/dist/helpers/index.js +1 -0
- package/dist/helpers/index.js.map +1 -1
- package/dist/index.cjs.js +358 -130
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +359 -132
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +3 -3
- package/dist/index.umd.js.map +1 -1
- package/dist/sdk/FlaunchSDK.d.ts +147 -7
- package/dist/sdk/FlaunchSDK.d.ts.map +1 -1
- package/dist/types.d.ts +70 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/univ4.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createDrift as createDrift$1 } from '@delvtech/drift';
|
|
2
|
-
import { zeroAddress, parseEther, encodeAbiParameters as encodeAbiParameters$1, maxUint256 as maxUint256$1, encodeFunctionData, maxUint160, maxUint48, parseUnits, hexToBigInt as hexToBigInt$1, pad as pad$1, keccak256 as keccak256$1, encodePacked, stringToHex as stringToHex$1, zeroHash, formatUnits as formatUnits$1, parseEventLogs, concat as concat$1, toHex as toHex$1,
|
|
2
|
+
import { zeroAddress, parseEther, encodeAbiParameters as encodeAbiParameters$1, maxUint256 as maxUint256$1, encodeFunctionData, maxUint160, maxUint48, parseUnits, hexToBigInt as hexToBigInt$1, pad as pad$1, keccak256 as keccak256$1, encodePacked, stringToHex as stringToHex$1, zeroHash, formatUnits as formatUnits$1, parseEventLogs, concat as concat$1, toHex as toHex$1, erc721Abi, erc20Abi, parseAbi, createWalletClient, http, decodeFunctionData } from 'viem';
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
import { viemAdapter } from '@delvtech/drift-viem';
|
|
5
5
|
|
|
@@ -5778,6 +5778,10 @@ const ZoraVerifierAddress = {
|
|
|
5778
5778
|
[base.id]: "0x656047fd43d2c3a121f2ef859d7171d7dd59f8b9",
|
|
5779
5779
|
[baseSepolia.id]: "0x05a5763e9199b88bb591c6b112d0424b2cd7a99e",
|
|
5780
5780
|
};
|
|
5781
|
+
const SolanaVerifierAddress = {
|
|
5782
|
+
[base.id]: "0x0000000000000000000000000000000000000000",
|
|
5783
|
+
[baseSepolia.id]: "0x47226918E518f205584bd75Bf81E0b532B0B3Ea7",
|
|
5784
|
+
};
|
|
5781
5785
|
/** ======== */
|
|
5782
5786
|
/** Permissions */
|
|
5783
5787
|
const ClosedPermissionsAddress = {
|
|
@@ -11885,6 +11889,7 @@ var Verifier;
|
|
|
11885
11889
|
Verifier["VIRTUALS"] = "virtuals";
|
|
11886
11890
|
Verifier["WHITELIST"] = "whitelist";
|
|
11887
11891
|
Verifier["ZORA"] = "zora";
|
|
11892
|
+
Verifier["SOLANA"] = "solana";
|
|
11888
11893
|
})(Verifier || (Verifier = {}));
|
|
11889
11894
|
var LiquidityMode;
|
|
11890
11895
|
(function (LiquidityMode) {
|
|
@@ -20355,6 +20360,8 @@ class ReadTokenImporter {
|
|
|
20355
20360
|
return WhitelistVerifierAddress[this.chainId];
|
|
20356
20361
|
case Verifier.ZORA:
|
|
20357
20362
|
return ZoraVerifierAddress[this.chainId];
|
|
20363
|
+
case Verifier.SOLANA:
|
|
20364
|
+
return SolanaVerifierAddress[this.chainId];
|
|
20358
20365
|
default:
|
|
20359
20366
|
throw new Error(`Unknown verifier: ${verifier}`);
|
|
20360
20367
|
}
|
|
@@ -25459,6 +25466,10 @@ function maxLiquidityForAmount0Precise(sqrtRatioAX96, sqrtRatioBX96, amount0) {
|
|
|
25459
25466
|
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
25460
25467
|
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
25461
25468
|
}
|
|
25469
|
+
// Handle edge case where sqrt ratios are equal (division by zero)
|
|
25470
|
+
if (sqrtRatioAX96 === sqrtRatioBX96) {
|
|
25471
|
+
return 0n;
|
|
25472
|
+
}
|
|
25462
25473
|
const Q96 = 2n ** 96n;
|
|
25463
25474
|
const numerator = amount0 * sqrtRatioAX96 * sqrtRatioBX96;
|
|
25464
25475
|
const denominator = Q96 * (sqrtRatioBX96 - sqrtRatioAX96);
|
|
@@ -25475,6 +25486,10 @@ function maxLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1) {
|
|
|
25475
25486
|
if (sqrtRatioAX96 > sqrtRatioBX96) {
|
|
25476
25487
|
[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96];
|
|
25477
25488
|
}
|
|
25489
|
+
// Handle edge case where sqrt ratios are equal (division by zero)
|
|
25490
|
+
if (sqrtRatioAX96 === sqrtRatioBX96) {
|
|
25491
|
+
return 0n;
|
|
25492
|
+
}
|
|
25478
25493
|
const Q96 = 2n ** 96n;
|
|
25479
25494
|
return (amount1 * Q96) / (sqrtRatioBX96 - sqrtRatioAX96);
|
|
25480
25495
|
}
|
|
@@ -26386,7 +26401,7 @@ class ReadFlaunchSDK {
|
|
|
26386
26401
|
* @returns Promise<number> - The current tick of the pool
|
|
26387
26402
|
*/
|
|
26388
26403
|
async currentTick(coinAddress, version) {
|
|
26389
|
-
const coinVersion =
|
|
26404
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26390
26405
|
const poolId = await this.poolId(coinAddress, coinVersion);
|
|
26391
26406
|
const poolState = await this.readStateView.poolSlot0({ poolId });
|
|
26392
26407
|
return poolState.tick;
|
|
@@ -26398,7 +26413,7 @@ class ReadFlaunchSDK {
|
|
|
26398
26413
|
* @returns Promise<string> - The price of the coin in ETH with 18 decimals precision
|
|
26399
26414
|
*/
|
|
26400
26415
|
async coinPriceInETH(coinAddress, version) {
|
|
26401
|
-
const coinVersion =
|
|
26416
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26402
26417
|
const isFLETHZero = this.flETHIsCurrencyZero(coinAddress);
|
|
26403
26418
|
const currentTick = await this.currentTick(coinAddress, coinVersion);
|
|
26404
26419
|
const price = Math.pow(1.0001, currentTick);
|
|
@@ -26418,7 +26433,7 @@ class ReadFlaunchSDK {
|
|
|
26418
26433
|
* @returns Promise<string> - The price of the coin in USD with 18 decimal precision
|
|
26419
26434
|
*/
|
|
26420
26435
|
async coinPriceInUSD({ coinAddress, version, drift, }) {
|
|
26421
|
-
const coinVersion =
|
|
26436
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26422
26437
|
const ethPerCoin = await this.coinPriceInETH(coinAddress, coinVersion);
|
|
26423
26438
|
const ethPrice = await this.getETHUSDCPrice(drift);
|
|
26424
26439
|
return (parseFloat(ethPerCoin) * ethPrice).toFixed(18);
|
|
@@ -26466,7 +26481,7 @@ class ReadFlaunchSDK {
|
|
|
26466
26481
|
* @returns Fair launch information from the appropriate contract version
|
|
26467
26482
|
*/
|
|
26468
26483
|
async fairLaunchInfo(coinAddress, version) {
|
|
26469
|
-
const coinVersion =
|
|
26484
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26470
26485
|
const poolId = await this.poolId(coinAddress, coinVersion);
|
|
26471
26486
|
return this.getFairLaunch(coinVersion).fairLaunchInfo({ poolId });
|
|
26472
26487
|
}
|
|
@@ -26477,12 +26492,12 @@ class ReadFlaunchSDK {
|
|
|
26477
26492
|
* @returns Promise<boolean> - True if fair launch is active, false otherwise
|
|
26478
26493
|
*/
|
|
26479
26494
|
async isFairLaunchActive(coinAddress, version) {
|
|
26480
|
-
const coinVersion =
|
|
26495
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26481
26496
|
const poolId = await this.poolId(coinAddress, coinVersion);
|
|
26482
26497
|
return this.getFairLaunch(coinVersion).isFairLaunchActive({ poolId });
|
|
26483
26498
|
}
|
|
26484
26499
|
async trustedPoolKeySignerStatus(coinAddress, version) {
|
|
26485
|
-
const coinVersion =
|
|
26500
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26486
26501
|
if (coinVersion === FlaunchVersion.ANY) {
|
|
26487
26502
|
throw new Error("AnyPositionManager is not supported for TrustedSigner");
|
|
26488
26503
|
}
|
|
@@ -26531,7 +26546,7 @@ class ReadFlaunchSDK {
|
|
|
26531
26546
|
* @returns Promise<number> - The duration in seconds (30 minutes for V1, variable for V1.1)
|
|
26532
26547
|
*/
|
|
26533
26548
|
async fairLaunchDuration(coinAddress, version) {
|
|
26534
|
-
const coinVersion =
|
|
26549
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26535
26550
|
const poolId = await this.poolId(coinAddress, coinVersion);
|
|
26536
26551
|
return this.getFairLaunch(coinVersion).fairLaunchDuration({ poolId });
|
|
26537
26552
|
}
|
|
@@ -26542,7 +26557,7 @@ class ReadFlaunchSDK {
|
|
|
26542
26557
|
* @returns Promise<number> - The initial tick value
|
|
26543
26558
|
*/
|
|
26544
26559
|
async initialTick(coinAddress, version) {
|
|
26545
|
-
const coinVersion =
|
|
26560
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26546
26561
|
const poolId = await this.poolId(coinAddress, coinVersion);
|
|
26547
26562
|
const fairLaunchInfo = await this.getFairLaunch(coinVersion).fairLaunchInfo({ poolId });
|
|
26548
26563
|
return fairLaunchInfo.initialTick;
|
|
@@ -26554,7 +26569,7 @@ class ReadFlaunchSDK {
|
|
|
26554
26569
|
* @returns Promise<{flETHAmount: bigint, coinAmount: bigint, tickLower: number, tickUpper: number}> - Position details
|
|
26555
26570
|
*/
|
|
26556
26571
|
async fairLaunchETHOnlyPosition(coinAddress, version) {
|
|
26557
|
-
const coinVersion =
|
|
26572
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26558
26573
|
const poolId = await this.poolId(coinAddress, coinVersion);
|
|
26559
26574
|
const initialTick = await this.initialTick(coinAddress, coinVersion);
|
|
26560
26575
|
const currentTick = await this.currentTick(coinAddress, coinVersion);
|
|
@@ -26602,7 +26617,7 @@ class ReadFlaunchSDK {
|
|
|
26602
26617
|
* @returns Promise<{flETHAmount: bigint, coinAmount: bigint, tickLower: number, tickUpper: number}> - Position details
|
|
26603
26618
|
*/
|
|
26604
26619
|
async fairLaunchCoinOnlyPosition(coinAddress, version) {
|
|
26605
|
-
const coinVersion =
|
|
26620
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26606
26621
|
const poolId = await this.poolId(coinAddress, coinVersion);
|
|
26607
26622
|
const initialTick = await this.initialTick(coinAddress, coinVersion);
|
|
26608
26623
|
const currentTick = await this.currentTick(coinAddress, coinVersion);
|
|
@@ -26650,7 +26665,7 @@ class ReadFlaunchSDK {
|
|
|
26650
26665
|
* @returns Promise<{flETHAmount: bigint, coinAmount: bigint, pendingEth: bigint, tickLower: number, tickUpper: number}> - Bid wall position details
|
|
26651
26666
|
*/
|
|
26652
26667
|
async bidWallPosition(coinAddress, version) {
|
|
26653
|
-
const coinVersion =
|
|
26668
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26654
26669
|
const poolId = await this.poolId(coinAddress, coinVersion);
|
|
26655
26670
|
const isFLETHZero = this.flETHIsCurrencyZero(coinAddress);
|
|
26656
26671
|
const { amount0_: amount0, amount1_: amount1, pendingEth_: pendingEth, } = await this.getBidWall(coinVersion).position({ poolId });
|
|
@@ -26766,13 +26781,8 @@ class ReadFlaunchSDK {
|
|
|
26766
26781
|
*/
|
|
26767
26782
|
async poolId(coinAddress, version) {
|
|
26768
26783
|
let hookAddress;
|
|
26769
|
-
|
|
26770
|
-
|
|
26771
|
-
}
|
|
26772
|
-
else {
|
|
26773
|
-
const coinVersion = await this.getCoinVersion(coinAddress);
|
|
26774
|
-
hookAddress = this.getPositionManagerAddress(coinVersion);
|
|
26775
|
-
}
|
|
26784
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26785
|
+
hookAddress = this.getPositionManagerAddress(coinVersion);
|
|
26776
26786
|
return getPoolId(orderPoolKey({
|
|
26777
26787
|
currency0: FLETHAddress[this.chainId],
|
|
26778
26788
|
currency1: coinAddress,
|
|
@@ -26830,7 +26840,7 @@ class ReadFlaunchSDK {
|
|
|
26830
26840
|
* @returns Promise<bigint> - The expected amount of ETH to receive
|
|
26831
26841
|
*/
|
|
26832
26842
|
async getSellQuoteExactInput({ coinAddress, version, amountIn, intermediatePoolKey, }) {
|
|
26833
|
-
const coinVersion =
|
|
26843
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26834
26844
|
return this.readQuoter.getSellQuoteExactInput({
|
|
26835
26845
|
coinAddress,
|
|
26836
26846
|
amountIn,
|
|
@@ -26849,7 +26859,7 @@ class ReadFlaunchSDK {
|
|
|
26849
26859
|
* @returns Promise<bigint> - The expected amount of coins to receive
|
|
26850
26860
|
*/
|
|
26851
26861
|
async getBuyQuoteExactInput({ coinAddress, version, amountIn, intermediatePoolKey, hookData, userWallet, }) {
|
|
26852
|
-
const coinVersion =
|
|
26862
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26853
26863
|
return this.readQuoter.getBuyQuoteExactInput({
|
|
26854
26864
|
coinAddress,
|
|
26855
26865
|
amountIn,
|
|
@@ -26870,7 +26880,7 @@ class ReadFlaunchSDK {
|
|
|
26870
26880
|
* @returns Promise<bigint> - The required amount of ETH or inputToken to spend
|
|
26871
26881
|
*/
|
|
26872
26882
|
async getBuyQuoteExactOutput({ coinAddress, amountOut, version, intermediatePoolKey, hookData, userWallet, }) {
|
|
26873
|
-
const coinVersion =
|
|
26883
|
+
const coinVersion = await this.determineCoinVersion(coinAddress, version);
|
|
26874
26884
|
return this.readQuoter.getBuyQuoteExactOutput({
|
|
26875
26885
|
coinAddress,
|
|
26876
26886
|
coinOut: amountOut,
|
|
@@ -26928,7 +26938,8 @@ class ReadFlaunchSDK {
|
|
|
26928
26938
|
memecoin.totalSupply(),
|
|
26929
26939
|
memecoin.decimals(),
|
|
26930
26940
|
]);
|
|
26931
|
-
|
|
26941
|
+
const formattedTotalSupplyInDecimals = parseFloat(formatUnits$1(totalSupply, decimals));
|
|
26942
|
+
return { totalSupply, decimals, formattedTotalSupplyInDecimals };
|
|
26932
26943
|
}
|
|
26933
26944
|
/**
|
|
26934
26945
|
* Gets market context information needed for tick calculations
|
|
@@ -26950,8 +26961,8 @@ class ReadFlaunchSDK {
|
|
|
26950
26961
|
/**
|
|
26951
26962
|
* Converts market cap in USD to token price in ETH
|
|
26952
26963
|
*/
|
|
26953
|
-
marketCapToTokenPriceEth(marketCapUsd,
|
|
26954
|
-
const tokenPriceUsd = marketCapUsd /
|
|
26964
|
+
marketCapToTokenPriceEth(marketCapUsd, formattedTotalSupplyInDecimals, ethUsdPrice) {
|
|
26965
|
+
const tokenPriceUsd = marketCapUsd / formattedTotalSupplyInDecimals;
|
|
26955
26966
|
return tokenPriceUsd / ethUsdPrice;
|
|
26956
26967
|
}
|
|
26957
26968
|
/**
|
|
@@ -26969,24 +26980,22 @@ class ReadFlaunchSDK {
|
|
|
26969
26980
|
/**
|
|
26970
26981
|
* Calculates current tick from market cap if provided
|
|
26971
26982
|
*/
|
|
26972
|
-
calculateCurrentTickFromMarketCap(currentMarketCap,
|
|
26983
|
+
calculateCurrentTickFromMarketCap(currentMarketCap, formattedTotalSupplyInDecimals, marketContext) {
|
|
26973
26984
|
if (!currentMarketCap) {
|
|
26974
26985
|
return undefined;
|
|
26975
26986
|
}
|
|
26976
26987
|
const currentMarketCapNum = parseFloat(currentMarketCap);
|
|
26977
|
-
const currentTokenPriceEth = this.marketCapToTokenPriceEth(currentMarketCapNum,
|
|
26988
|
+
const currentTokenPriceEth = this.marketCapToTokenPriceEth(currentMarketCapNum, formattedTotalSupplyInDecimals, marketContext.ethUsdPrice);
|
|
26978
26989
|
return this.convertPriceToTick(currentTokenPriceEth, marketContext.isFlethZero, marketContext.decimals0, marketContext.decimals1);
|
|
26979
26990
|
}
|
|
26980
26991
|
async calculateAddLiquidityTicks({ coinAddress, liquidityMode, minMarketCap, maxMarketCap, currentMarketCap, }) {
|
|
26981
26992
|
// Get coin information
|
|
26982
|
-
const { totalSupply: coinTotalSupply, decimals: coinDecimals } = await this.getCoinInfo(coinAddress);
|
|
26983
|
-
// Convert total supply to decimal format
|
|
26984
|
-
const totalSupplyDecimal = parseFloat(formatEther(coinTotalSupply));
|
|
26993
|
+
const { totalSupply: coinTotalSupply, decimals: coinDecimals, formattedTotalSupplyInDecimals, } = await this.getCoinInfo(coinAddress);
|
|
26985
26994
|
if (liquidityMode === LiquidityMode.FULL_RANGE) {
|
|
26986
26995
|
let currentTick;
|
|
26987
26996
|
if (currentMarketCap) {
|
|
26988
26997
|
const marketContext = await this.getMarketContext(coinAddress, coinDecimals);
|
|
26989
|
-
currentTick = this.calculateCurrentTickFromMarketCap(currentMarketCap,
|
|
26998
|
+
currentTick = this.calculateCurrentTickFromMarketCap(currentMarketCap, formattedTotalSupplyInDecimals, marketContext);
|
|
26990
26999
|
}
|
|
26991
27000
|
return {
|
|
26992
27001
|
tickLower: getNearestUsableTick({
|
|
@@ -27013,13 +27022,13 @@ class ReadFlaunchSDK {
|
|
|
27013
27022
|
throw new Error("[ReadFlaunchSDK.addLiquidityCalculateTicks]: Invalid market cap range");
|
|
27014
27023
|
}
|
|
27015
27024
|
// Convert market caps to token prices in ETH
|
|
27016
|
-
const minTokenPriceEth = this.marketCapToTokenPriceEth(minMarketCapNum,
|
|
27017
|
-
const maxTokenPriceEth = this.marketCapToTokenPriceEth(maxMarketCapNum,
|
|
27025
|
+
const minTokenPriceEth = this.marketCapToTokenPriceEth(minMarketCapNum, formattedTotalSupplyInDecimals, marketContext.ethUsdPrice);
|
|
27026
|
+
const maxTokenPriceEth = this.marketCapToTokenPriceEth(maxMarketCapNum, formattedTotalSupplyInDecimals, marketContext.ethUsdPrice);
|
|
27018
27027
|
// Convert to ticks
|
|
27019
27028
|
const minTick = this.convertPriceToTick(minTokenPriceEth, marketContext.isFlethZero, marketContext.decimals0, marketContext.decimals1);
|
|
27020
27029
|
const maxTick = this.convertPriceToTick(maxTokenPriceEth, marketContext.isFlethZero, marketContext.decimals0, marketContext.decimals1);
|
|
27021
27030
|
// Calculate current tick if provided
|
|
27022
|
-
const currentTick = this.calculateCurrentTickFromMarketCap(currentMarketCap,
|
|
27031
|
+
const currentTick = this.calculateCurrentTickFromMarketCap(currentMarketCap, formattedTotalSupplyInDecimals, marketContext);
|
|
27023
27032
|
return {
|
|
27024
27033
|
tickLower: Math.min(minTick, maxTick),
|
|
27025
27034
|
tickUpper: Math.max(minTick, maxTick),
|
|
@@ -27040,12 +27049,11 @@ class ReadFlaunchSDK {
|
|
|
27040
27049
|
currentMarketCap = params.currentMarketCap;
|
|
27041
27050
|
}
|
|
27042
27051
|
else {
|
|
27043
|
-
const {
|
|
27044
|
-
|
|
27045
|
-
|
|
27046
|
-
maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupply).toString();
|
|
27052
|
+
const { formattedTotalSupplyInDecimals } = await this.getCoinInfo(coinAddress);
|
|
27053
|
+
minMarketCap = (parseFloat(params.minPriceUSD) * formattedTotalSupplyInDecimals).toString();
|
|
27054
|
+
maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupplyInDecimals).toString();
|
|
27047
27055
|
if (params.currentPriceUSD) {
|
|
27048
|
-
currentMarketCap = (params.currentPriceUSD *
|
|
27056
|
+
currentMarketCap = (params.currentPriceUSD * formattedTotalSupplyInDecimals).toString();
|
|
27049
27057
|
}
|
|
27050
27058
|
}
|
|
27051
27059
|
let { tickLower, tickUpper, currentTick } = await this.calculateAddLiquidityTicks({
|
|
@@ -27057,24 +27065,9 @@ class ReadFlaunchSDK {
|
|
|
27057
27065
|
});
|
|
27058
27066
|
// If no current tick is provided from the above calculation, get it from the pool state
|
|
27059
27067
|
if (!currentTick) {
|
|
27060
|
-
|
|
27061
|
-
// if version is not provided, check on existing managers, else default to ANY
|
|
27062
|
-
if (!version) {
|
|
27063
|
-
try {
|
|
27064
|
-
version = await this.getCoinVersion(coinAddress);
|
|
27065
|
-
}
|
|
27066
|
-
catch {
|
|
27067
|
-
version = FlaunchVersion.ANY;
|
|
27068
|
-
}
|
|
27069
|
-
}
|
|
27068
|
+
const version = await this.determineCoinVersion(coinAddress, params.version);
|
|
27070
27069
|
const poolState = await this.readStateView.poolSlot0({
|
|
27071
|
-
poolId: getPoolId(
|
|
27072
|
-
currency0: coinAddress,
|
|
27073
|
-
currency1: FLETHAddress[this.chainId],
|
|
27074
|
-
fee: 0,
|
|
27075
|
-
tickSpacing: TICK_SPACING,
|
|
27076
|
-
hooks: this.getPositionManagerAddress(version),
|
|
27077
|
-
})),
|
|
27070
|
+
poolId: getPoolId(this.createPoolKey(coinAddress, version)),
|
|
27078
27071
|
});
|
|
27079
27072
|
currentTick = poolState.tick;
|
|
27080
27073
|
}
|
|
@@ -27131,12 +27124,11 @@ class ReadFlaunchSDK {
|
|
|
27131
27124
|
currentMarketCap = params.currentMarketCap;
|
|
27132
27125
|
}
|
|
27133
27126
|
else {
|
|
27134
|
-
const {
|
|
27135
|
-
|
|
27136
|
-
|
|
27137
|
-
maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupply).toString();
|
|
27127
|
+
const { formattedTotalSupplyInDecimals } = await this.getCoinInfo(coinAddress);
|
|
27128
|
+
minMarketCap = (parseFloat(params.minPriceUSD) * formattedTotalSupplyInDecimals).toString();
|
|
27129
|
+
maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupplyInDecimals).toString();
|
|
27138
27130
|
if (params.currentPriceUSD) {
|
|
27139
|
-
currentMarketCap = (params.currentPriceUSD *
|
|
27131
|
+
currentMarketCap = (params.currentPriceUSD * formattedTotalSupplyInDecimals).toString();
|
|
27140
27132
|
}
|
|
27141
27133
|
}
|
|
27142
27134
|
let { tickLower, tickUpper, currentTick } = await this.calculateAddLiquidityTicks({
|
|
@@ -27148,24 +27140,9 @@ class ReadFlaunchSDK {
|
|
|
27148
27140
|
});
|
|
27149
27141
|
// get the current pool state for the coin
|
|
27150
27142
|
if (!currentTick) {
|
|
27151
|
-
|
|
27152
|
-
// if version is not provided, check on existing managers, else default to ANY
|
|
27153
|
-
if (!version) {
|
|
27154
|
-
try {
|
|
27155
|
-
version = await this.getCoinVersion(coinAddress);
|
|
27156
|
-
}
|
|
27157
|
-
catch {
|
|
27158
|
-
version = FlaunchVersion.ANY;
|
|
27159
|
-
}
|
|
27160
|
-
}
|
|
27143
|
+
const version = await this.determineCoinVersion(coinAddress, params.version);
|
|
27161
27144
|
const poolState = await this.readStateView.poolSlot0({
|
|
27162
|
-
poolId: getPoolId(
|
|
27163
|
-
currency0: coinAddress,
|
|
27164
|
-
currency1: FLETHAddress[this.chainId],
|
|
27165
|
-
fee: 0,
|
|
27166
|
-
tickSpacing: TICK_SPACING,
|
|
27167
|
-
hooks: this.getPositionManagerAddress(version),
|
|
27168
|
-
})),
|
|
27145
|
+
poolId: getPoolId(this.createPoolKey(coinAddress, version)),
|
|
27169
27146
|
});
|
|
27170
27147
|
currentTick = poolState.tick;
|
|
27171
27148
|
}
|
|
@@ -27320,6 +27297,39 @@ class ReadFlaunchSDK {
|
|
|
27320
27297
|
args: { owner, operator },
|
|
27321
27298
|
});
|
|
27322
27299
|
}
|
|
27300
|
+
/**
|
|
27301
|
+
* Determines the version for a coin, using provided version or fetching it
|
|
27302
|
+
* @param coinAddress - The coin address
|
|
27303
|
+
* @param version - Optional version, if not provided will be fetched
|
|
27304
|
+
* @returns The determined version
|
|
27305
|
+
*/
|
|
27306
|
+
async determineCoinVersion(coinAddress, version) {
|
|
27307
|
+
if (!version) {
|
|
27308
|
+
try {
|
|
27309
|
+
version = await this.getCoinVersion(coinAddress);
|
|
27310
|
+
}
|
|
27311
|
+
catch {
|
|
27312
|
+
version = FlaunchVersion.ANY;
|
|
27313
|
+
}
|
|
27314
|
+
}
|
|
27315
|
+
return version;
|
|
27316
|
+
}
|
|
27317
|
+
/**
|
|
27318
|
+
* Creates a pool key for the given coin and version
|
|
27319
|
+
* @param coinAddress - The coin address
|
|
27320
|
+
* @param version - The version to use for position manager
|
|
27321
|
+
* @returns The ordered pool key
|
|
27322
|
+
*/
|
|
27323
|
+
createPoolKey(coinAddress, version) {
|
|
27324
|
+
const flethAddress = FLETHAddress[this.chainId];
|
|
27325
|
+
return orderPoolKey({
|
|
27326
|
+
currency0: coinAddress,
|
|
27327
|
+
currency1: flethAddress,
|
|
27328
|
+
fee: 0,
|
|
27329
|
+
tickSpacing: this.TICK_SPACING,
|
|
27330
|
+
hooks: this.getPositionManagerAddress(version),
|
|
27331
|
+
});
|
|
27332
|
+
}
|
|
27323
27333
|
}
|
|
27324
27334
|
class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
27325
27335
|
constructor(chainId, drift = createDrift$1(), publicClient) {
|
|
@@ -27444,7 +27454,7 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
27444
27454
|
* @returns Transaction response for the buy operation
|
|
27445
27455
|
*/
|
|
27446
27456
|
async buyCoin(params, version) {
|
|
27447
|
-
const coinVersion =
|
|
27457
|
+
const coinVersion = await this.determineCoinVersion(params.coinAddress, version);
|
|
27448
27458
|
const sender = await this.drift.getSignerAddress();
|
|
27449
27459
|
let amountIn;
|
|
27450
27460
|
let amountOutMin;
|
|
@@ -27529,7 +27539,7 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
27529
27539
|
* @returns Transaction response for the sell operation
|
|
27530
27540
|
*/
|
|
27531
27541
|
async sellCoin(params, version) {
|
|
27532
|
-
const coinVersion =
|
|
27542
|
+
const coinVersion = await this.determineCoinVersion(params.coinAddress, version);
|
|
27533
27543
|
let amountOutMin;
|
|
27534
27544
|
await this.readQuoter.contract.cache.clear();
|
|
27535
27545
|
if (params.amountOutMin === undefined) {
|
|
@@ -27752,22 +27762,8 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
27752
27762
|
let tickLower;
|
|
27753
27763
|
let tickUpper;
|
|
27754
27764
|
let currentTick;
|
|
27755
|
-
|
|
27756
|
-
|
|
27757
|
-
try {
|
|
27758
|
-
version = await this.getCoinVersion(coinAddress);
|
|
27759
|
-
}
|
|
27760
|
-
catch {
|
|
27761
|
-
version = FlaunchVersion.ANY;
|
|
27762
|
-
}
|
|
27763
|
-
}
|
|
27764
|
-
const poolKey = orderPoolKey({
|
|
27765
|
-
currency0: coinAddress,
|
|
27766
|
-
currency1: flethAddress,
|
|
27767
|
-
fee: 0,
|
|
27768
|
-
tickSpacing: this.TICK_SPACING,
|
|
27769
|
-
hooks: this.getPositionManagerAddress(version),
|
|
27770
|
-
});
|
|
27765
|
+
const version = await this.determineCoinVersion(coinAddress, params.version);
|
|
27766
|
+
const poolKey = this.createPoolKey(coinAddress, version);
|
|
27771
27767
|
// Check if we need to calculate values or use direct values
|
|
27772
27768
|
if ("tickLower" in params) {
|
|
27773
27769
|
// Use the directly provided values
|
|
@@ -27796,12 +27792,12 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
27796
27792
|
initialMarketCapUSD = params.initialMarketCapUSD;
|
|
27797
27793
|
}
|
|
27798
27794
|
else {
|
|
27799
|
-
const {
|
|
27800
|
-
|
|
27801
|
-
|
|
27802
|
-
maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupply).toString();
|
|
27795
|
+
const { formattedTotalSupplyInDecimals } = await this.getCoinInfo(coinAddress);
|
|
27796
|
+
minMarketCap = (parseFloat(params.minPriceUSD) * formattedTotalSupplyInDecimals).toString();
|
|
27797
|
+
maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupplyInDecimals).toString();
|
|
27803
27798
|
if (params.initialPriceUSD) {
|
|
27804
|
-
initialMarketCapUSD =
|
|
27799
|
+
initialMarketCapUSD =
|
|
27800
|
+
params.initialPriceUSD * formattedTotalSupplyInDecimals;
|
|
27805
27801
|
}
|
|
27806
27802
|
}
|
|
27807
27803
|
const calculated = await this.calculateAddLiquidityAmounts({
|
|
@@ -27965,6 +27961,246 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
27965
27961
|
// Determine amounts for each currency based on pool key ordering
|
|
27966
27962
|
const amount0 = poolKey.currency0 === coinAddress ? coinAmount : flethAmount;
|
|
27967
27963
|
const amount1 = poolKey.currency0 === coinAddress ? flethAmount : coinAmount;
|
|
27964
|
+
// Calculate and constrain liquidity using shared method
|
|
27965
|
+
const { finalLiquidity, finalAmount0, finalAmount1 } = this.calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1);
|
|
27966
|
+
// 6. Add liquidity
|
|
27967
|
+
calls.push(this.createLiquidityCall(poolKey, tickLower, tickUpper, finalLiquidity, finalAmount0, finalAmount1, userAddress));
|
|
27968
|
+
return calls;
|
|
27969
|
+
}
|
|
27970
|
+
// Implementation with union type for internal use
|
|
27971
|
+
async getImportAndAddLiquidityCalls(params) {
|
|
27972
|
+
let importParams;
|
|
27973
|
+
if ("initialMarketCapUSD" in params) {
|
|
27974
|
+
const paramsWithMarketCap = params;
|
|
27975
|
+
importParams = await this.readWriteTokenImporter.getInitializeParams({
|
|
27976
|
+
coinAddress: paramsWithMarketCap.coinAddress,
|
|
27977
|
+
creatorFeeAllocationPercent: paramsWithMarketCap.creatorFeeAllocationPercent,
|
|
27978
|
+
initialMarketCapUSD: paramsWithMarketCap.initialMarketCapUSD,
|
|
27979
|
+
verifier: paramsWithMarketCap.verifier,
|
|
27980
|
+
});
|
|
27981
|
+
}
|
|
27982
|
+
else {
|
|
27983
|
+
const paramsWithPrice = params;
|
|
27984
|
+
importParams = await this.readWriteTokenImporter.getInitializeParams({
|
|
27985
|
+
coinAddress: paramsWithPrice.coinAddress,
|
|
27986
|
+
creatorFeeAllocationPercent: paramsWithPrice.creatorFeeAllocationPercent,
|
|
27987
|
+
initialPriceUSD: paramsWithPrice.initialPriceUSD,
|
|
27988
|
+
verifier: paramsWithPrice.verifier,
|
|
27989
|
+
});
|
|
27990
|
+
}
|
|
27991
|
+
const addLiquidityCalls = await this.getAddLiquidityCalls({
|
|
27992
|
+
...params,
|
|
27993
|
+
version: FlaunchVersion.ANY, // optimize to avoid fetching if not passed
|
|
27994
|
+
});
|
|
27995
|
+
return [
|
|
27996
|
+
{
|
|
27997
|
+
to: this.readWriteTokenImporter.contract.address,
|
|
27998
|
+
data: this.readWriteTokenImporter.contract.encodeFunctionData("initialize", importParams),
|
|
27999
|
+
description: "Import Memecoin to Flaunch",
|
|
28000
|
+
},
|
|
28001
|
+
...addLiquidityCalls,
|
|
28002
|
+
];
|
|
28003
|
+
}
|
|
28004
|
+
/**
|
|
28005
|
+
* Gets the calls needed to add single-sided liquidity in coin from current tick to infinity
|
|
28006
|
+
* @param params - Parameters for adding single-sided liquidity
|
|
28007
|
+
* @returns Array of calls with descriptions
|
|
28008
|
+
*/
|
|
28009
|
+
async getSingleSidedCoinAddLiquidityCalls(params) {
|
|
28010
|
+
const { coinAddress, coinAmount } = params;
|
|
28011
|
+
const version = await this.determineCoinVersion(coinAddress, params.version);
|
|
28012
|
+
const poolKey = this.createPoolKey(coinAddress, version);
|
|
28013
|
+
let currentTick;
|
|
28014
|
+
// if initial marketcap or price is provided, it means that the pool is not initialized yet
|
|
28015
|
+
// so determining the currentTick
|
|
28016
|
+
if (("initialMarketCapUSD" in params && params.initialMarketCapUSD) ||
|
|
28017
|
+
("initialPriceUSD" in params && params.initialPriceUSD)) {
|
|
28018
|
+
const { decimals: coinDecimals, formattedTotalSupplyInDecimals } = await this.getCoinInfo(coinAddress);
|
|
28019
|
+
// Determine market cap based on provided parameter
|
|
28020
|
+
let initialMarketCapUSD;
|
|
28021
|
+
if ("initialMarketCapUSD" in params && params.initialMarketCapUSD) {
|
|
28022
|
+
initialMarketCapUSD = params.initialMarketCapUSD;
|
|
28023
|
+
}
|
|
28024
|
+
else if ("initialPriceUSD" in params && params.initialPriceUSD) {
|
|
28025
|
+
initialMarketCapUSD =
|
|
28026
|
+
params.initialPriceUSD * formattedTotalSupplyInDecimals;
|
|
28027
|
+
}
|
|
28028
|
+
else {
|
|
28029
|
+
throw new Error("Either initialMarketCapUSD or initialPriceUSD must be provided");
|
|
28030
|
+
}
|
|
28031
|
+
const marketContext = await this.getMarketContext(coinAddress, coinDecimals);
|
|
28032
|
+
const calculatedTick = this.calculateCurrentTickFromMarketCap(initialMarketCapUSD.toString(), formattedTotalSupplyInDecimals, marketContext);
|
|
28033
|
+
if (calculatedTick === undefined) {
|
|
28034
|
+
throw new Error("Failed to calculate current tick from market cap");
|
|
28035
|
+
}
|
|
28036
|
+
currentTick = calculatedTick;
|
|
28037
|
+
}
|
|
28038
|
+
else {
|
|
28039
|
+
// the pool is already initialized, get the current tick from the pool
|
|
28040
|
+
const poolState = await this.readStateView.poolSlot0({
|
|
28041
|
+
poolId: getPoolId(poolKey),
|
|
28042
|
+
});
|
|
28043
|
+
currentTick = poolState.tick;
|
|
28044
|
+
}
|
|
28045
|
+
// We want to add liquidity from current price to infinity (as coin appreciates vs flETH)
|
|
28046
|
+
// This means providing single-sided coin liquidity that becomes active as coin price increases
|
|
28047
|
+
const isFLETHZero = this.flETHIsCurrencyZero(coinAddress);
|
|
28048
|
+
let tickLower;
|
|
28049
|
+
let tickUpper;
|
|
28050
|
+
if (isFLETHZero) {
|
|
28051
|
+
// flETH is currency0, coin is currency1
|
|
28052
|
+
// Price = coin/flETH. As coin appreciates, price and tick increase.
|
|
28053
|
+
// For single-sided coin position, we need the range to end at current tick
|
|
28054
|
+
// so as price increases beyond current, position becomes coin-only
|
|
28055
|
+
tickLower = TickFinder.MIN_TICK;
|
|
28056
|
+
tickUpper = getValidTick({
|
|
28057
|
+
tick: currentTick,
|
|
28058
|
+
tickSpacing: this.TICK_SPACING,
|
|
28059
|
+
roundDown: true,
|
|
28060
|
+
});
|
|
28061
|
+
}
|
|
28062
|
+
else {
|
|
28063
|
+
// coin is currency0, flETH is currency1
|
|
28064
|
+
// Price = flETH/coin. As coin appreciates, price decreases and tick decreases.
|
|
28065
|
+
// For single-sided coin position, we need the range to start at current tick
|
|
28066
|
+
// so as price decreases below current, position becomes coin-only
|
|
28067
|
+
tickLower = getValidTick({
|
|
28068
|
+
tick: currentTick,
|
|
28069
|
+
tickSpacing: this.TICK_SPACING,
|
|
28070
|
+
roundDown: false,
|
|
28071
|
+
});
|
|
28072
|
+
tickUpper = TickFinder.MAX_TICK;
|
|
28073
|
+
}
|
|
28074
|
+
// Fetch approvals via multicall
|
|
28075
|
+
const userAddress = await this.drift.getSignerAddress();
|
|
28076
|
+
const permit2Address = Permit2Address[this.chainId];
|
|
28077
|
+
const results = await this.drift.multicall({
|
|
28078
|
+
calls: [
|
|
28079
|
+
// coin -> permit2
|
|
28080
|
+
{
|
|
28081
|
+
address: coinAddress,
|
|
28082
|
+
abi: erc20Abi,
|
|
28083
|
+
fn: "allowance",
|
|
28084
|
+
args: {
|
|
28085
|
+
owner: userAddress,
|
|
28086
|
+
spender: permit2Address,
|
|
28087
|
+
},
|
|
28088
|
+
},
|
|
28089
|
+
// coin --permit2--> uni position manager
|
|
28090
|
+
{
|
|
28091
|
+
address: permit2Address,
|
|
28092
|
+
abi: Permit2Abi,
|
|
28093
|
+
fn: "allowance",
|
|
28094
|
+
args: {
|
|
28095
|
+
0: userAddress,
|
|
28096
|
+
1: coinAddress,
|
|
28097
|
+
2: UniV4PositionManagerAddress[this.chainId],
|
|
28098
|
+
},
|
|
28099
|
+
},
|
|
28100
|
+
// coin symbol
|
|
28101
|
+
{
|
|
28102
|
+
address: coinAddress,
|
|
28103
|
+
abi: erc20Abi,
|
|
28104
|
+
fn: "symbol",
|
|
28105
|
+
},
|
|
28106
|
+
],
|
|
28107
|
+
});
|
|
28108
|
+
const coinToPermit2 = results[0].value;
|
|
28109
|
+
const permit2ToUniPosManagerCoinAllowance = results[1].value;
|
|
28110
|
+
const coinSymbol = results[2].value;
|
|
28111
|
+
const needsCoinApproval = coinToPermit2 < coinAmount;
|
|
28112
|
+
const currentTime = Math.floor(Date.now() / 1000);
|
|
28113
|
+
const needsCoinPermit2Approval = permit2ToUniPosManagerCoinAllowance.amount < coinAmount ||
|
|
28114
|
+
permit2ToUniPosManagerCoinAllowance.expiration <= currentTime;
|
|
28115
|
+
const calls = [];
|
|
28116
|
+
// 1. Coin approval to Permit2
|
|
28117
|
+
if (needsCoinApproval) {
|
|
28118
|
+
calls.push({
|
|
28119
|
+
to: coinAddress,
|
|
28120
|
+
description: `Approve ${coinSymbol} for Permit2`,
|
|
28121
|
+
data: encodeFunctionData({
|
|
28122
|
+
abi: erc20Abi,
|
|
28123
|
+
functionName: "approve",
|
|
28124
|
+
args: [permit2Address, coinAmount],
|
|
28125
|
+
}),
|
|
28126
|
+
});
|
|
28127
|
+
}
|
|
28128
|
+
// 2. Permit2 approval for coin to uni position manager
|
|
28129
|
+
const expiration = Math.floor(Date.now() / 1000) + 3600; // 1 hour from now
|
|
28130
|
+
if (needsCoinPermit2Approval) {
|
|
28131
|
+
calls.push({
|
|
28132
|
+
to: permit2Address,
|
|
28133
|
+
description: `Permit2 approval for ${coinSymbol} to UniV4PositionManager`,
|
|
28134
|
+
data: encodeFunctionData({
|
|
28135
|
+
abi: Permit2Abi,
|
|
28136
|
+
functionName: "approve",
|
|
28137
|
+
args: [
|
|
28138
|
+
coinAddress,
|
|
28139
|
+
UniV4PositionManagerAddress[this.chainId],
|
|
28140
|
+
coinAmount,
|
|
28141
|
+
expiration,
|
|
28142
|
+
],
|
|
28143
|
+
}),
|
|
28144
|
+
});
|
|
28145
|
+
}
|
|
28146
|
+
// === generate add liquidity call ===
|
|
28147
|
+
// Determine amounts for each currency based on pool key ordering
|
|
28148
|
+
const flethAmount = 0n;
|
|
28149
|
+
const amount0 = poolKey.currency0 === coinAddress ? coinAmount : flethAmount;
|
|
28150
|
+
const amount1 = poolKey.currency0 === coinAddress ? flethAmount : coinAmount;
|
|
28151
|
+
// Calculate and constrain liquidity using shared method
|
|
28152
|
+
const { finalLiquidity, finalAmount0, finalAmount1 } = this.calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1);
|
|
28153
|
+
// 3. Add liquidity
|
|
28154
|
+
calls.push(this.createLiquidityCall(poolKey, tickLower, tickUpper, finalLiquidity, finalAmount0, finalAmount1, userAddress));
|
|
28155
|
+
return calls;
|
|
28156
|
+
}
|
|
28157
|
+
// Implementation with union type for internal use
|
|
28158
|
+
async getImportAndSingleSidedCoinAddLiquidityCalls(params) {
|
|
28159
|
+
let importParams;
|
|
28160
|
+
if ("initialMarketCapUSD" in params) {
|
|
28161
|
+
const paramsWithMarketCap = params;
|
|
28162
|
+
importParams = await this.readWriteTokenImporter.getInitializeParams({
|
|
28163
|
+
coinAddress: paramsWithMarketCap.coinAddress,
|
|
28164
|
+
creatorFeeAllocationPercent: paramsWithMarketCap.creatorFeeAllocationPercent,
|
|
28165
|
+
initialMarketCapUSD: paramsWithMarketCap.initialMarketCapUSD,
|
|
28166
|
+
verifier: paramsWithMarketCap.verifier,
|
|
28167
|
+
});
|
|
28168
|
+
}
|
|
28169
|
+
else {
|
|
28170
|
+
const paramsWithPrice = params;
|
|
28171
|
+
importParams = await this.readWriteTokenImporter.getInitializeParams({
|
|
28172
|
+
coinAddress: paramsWithPrice.coinAddress,
|
|
28173
|
+
creatorFeeAllocationPercent: paramsWithPrice.creatorFeeAllocationPercent,
|
|
28174
|
+
initialPriceUSD: paramsWithPrice.initialPriceUSD,
|
|
28175
|
+
verifier: paramsWithPrice.verifier,
|
|
28176
|
+
});
|
|
28177
|
+
}
|
|
28178
|
+
const addLiquidityCalls = await this.getSingleSidedCoinAddLiquidityCalls({
|
|
28179
|
+
...params,
|
|
28180
|
+
version: FlaunchVersion.ANY, // optimize to avoid fetching if not passed
|
|
28181
|
+
});
|
|
28182
|
+
return [
|
|
28183
|
+
{
|
|
28184
|
+
to: this.readWriteTokenImporter.contract.address,
|
|
28185
|
+
data: this.readWriteTokenImporter.contract.encodeFunctionData("initialize", importParams),
|
|
28186
|
+
description: "Import Memecoin to Flaunch",
|
|
28187
|
+
},
|
|
28188
|
+
...addLiquidityCalls,
|
|
28189
|
+
];
|
|
28190
|
+
}
|
|
28191
|
+
/**
|
|
28192
|
+
* === Private helper functions ===
|
|
28193
|
+
*/
|
|
28194
|
+
/**
|
|
28195
|
+
* Calculates and constrains liquidity amounts for a position
|
|
28196
|
+
* @param currentTick - Current pool tick
|
|
28197
|
+
* @param tickLower - Lower tick of the position
|
|
28198
|
+
* @param tickUpper - Upper tick of the position
|
|
28199
|
+
* @param amount0 - Amount of currency0
|
|
28200
|
+
* @param amount1 - Amount of currency1
|
|
28201
|
+
* @returns Final liquidity and amounts
|
|
28202
|
+
*/
|
|
28203
|
+
calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1) {
|
|
27968
28204
|
// Calculate liquidity first using user's input amounts
|
|
27969
28205
|
const initialLiquidity = getLiquidityFromAmounts({
|
|
27970
28206
|
currentTick,
|
|
@@ -28030,7 +28266,25 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
28030
28266
|
}
|
|
28031
28267
|
finalAmount0 = amount0; // Use user's full amount as maximum
|
|
28032
28268
|
finalAmount1 = amount1; // Use user's full amount as maximum
|
|
28033
|
-
|
|
28269
|
+
return {
|
|
28270
|
+
finalLiquidity,
|
|
28271
|
+
finalAmount0,
|
|
28272
|
+
finalAmount1,
|
|
28273
|
+
};
|
|
28274
|
+
}
|
|
28275
|
+
/**
|
|
28276
|
+
* Creates the UniV4 Position Manager liquidity call
|
|
28277
|
+
* @param poolKey - The pool key
|
|
28278
|
+
* @param tickLower - Lower tick of the position
|
|
28279
|
+
* @param tickUpper - Upper tick of the position
|
|
28280
|
+
* @param finalLiquidity - Final liquidity amount
|
|
28281
|
+
* @param finalAmount0 - Final amount of currency0
|
|
28282
|
+
* @param finalAmount1 - Final amount of currency1
|
|
28283
|
+
* @param userAddress - User's address
|
|
28284
|
+
* @returns CallWithDescription for adding liquidity
|
|
28285
|
+
*/
|
|
28286
|
+
createLiquidityCall(poolKey, tickLower, tickUpper, finalLiquidity, finalAmount0, finalAmount1, userAddress) {
|
|
28287
|
+
// Prepare mint position parameters
|
|
28034
28288
|
const V4PMActions = {
|
|
28035
28289
|
MINT_POSITION: "02",
|
|
28036
28290
|
SETTLE_PAIR: "0d",
|
|
@@ -28084,8 +28338,7 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
28084
28338
|
currency1: poolKey.currency1,
|
|
28085
28339
|
},
|
|
28086
28340
|
]);
|
|
28087
|
-
|
|
28088
|
-
calls.push({
|
|
28341
|
+
return {
|
|
28089
28342
|
to: UniV4PositionManagerAddress[this.chainId],
|
|
28090
28343
|
data: encodeFunctionData({
|
|
28091
28344
|
abi: [
|
|
@@ -28111,33 +28364,7 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
28111
28364
|
}),
|
|
28112
28365
|
value: 0n,
|
|
28113
28366
|
description: "Add Liquidity",
|
|
28114
|
-
}
|
|
28115
|
-
return calls;
|
|
28116
|
-
}
|
|
28117
|
-
/**
|
|
28118
|
-
* Gets the calls needed to import a memecoin to Flaunch and add liquidity to AnyPositionManager as a batch
|
|
28119
|
-
* @param params - Parameters for importing and adding liquidity
|
|
28120
|
-
* @returns Array of calls with descriptions
|
|
28121
|
-
*/
|
|
28122
|
-
async getImportAndAddLiquidityCalls(params) {
|
|
28123
|
-
const importParams = await this.readWriteTokenImporter.getInitializeParams({
|
|
28124
|
-
coinAddress: params.coinAddress,
|
|
28125
|
-
creatorFeeAllocationPercent: params.creatorFeeAllocationPercent,
|
|
28126
|
-
initialMarketCapUSD: params.initialMarketCapUSD,
|
|
28127
|
-
verifier: params.verifier,
|
|
28128
|
-
});
|
|
28129
|
-
const addLiquidityCalls = await this.getAddLiquidityCalls({
|
|
28130
|
-
...params,
|
|
28131
|
-
version: FlaunchVersion.ANY, // optimize to avoid fetching if not passed
|
|
28132
|
-
});
|
|
28133
|
-
return [
|
|
28134
|
-
{
|
|
28135
|
-
to: this.readWriteTokenImporter.contract.address,
|
|
28136
|
-
data: this.readWriteTokenImporter.contract.encodeFunctionData("initialize", importParams),
|
|
28137
|
-
description: "Import Memecoin to Flaunch",
|
|
28138
|
-
},
|
|
28139
|
-
...addLiquidityCalls,
|
|
28140
|
-
];
|
|
28367
|
+
};
|
|
28141
28368
|
}
|
|
28142
28369
|
}
|
|
28143
28370
|
|
|
@@ -31779,5 +32006,5 @@ const FlaunchSDK = {
|
|
|
31779
32006
|
ReadWriteFlaunchSDK,
|
|
31780
32007
|
};
|
|
31781
32008
|
|
|
31782
|
-
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, FlaunchBackend, 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, createCallDataWalletClient, createDrift, createFlaunch, createFlaunchCalldata, decodeCallData, encodedCallAbi, generateTokenUri, getAmountWithSlippage, getAmountsForLiquidity, getLiquidityFromAmounts, getNearestUsableTick, getPermissionsAddress, getPermit2TypedData, getPoolId, getSqrtPriceX96FromTick, getValidTick, maxLiquidityForAmount0Precise, maxLiquidityForAmount1, orderPoolKey, parseCall, parseSwapData, priceRatioToTick, resolveIPFS, sellMemecoinWithPermit2, uint256ToBytes32, uploadFileToIPFS, uploadImageToFlaunchAPI, uploadImageToIPFS, uploadJsonToIPFS, uploadMetadataToFlaunchAPI };
|
|
32009
|
+
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, FlaunchBackend, 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, SolanaVerifierAddress, StakingManagerAddress, StateViewAbi, StateViewAddress, TICK_SPACING, TickFinder, TokenImporterAddress, TreasuryManagerFactoryAbi, TreasuryManagerFactoryAddress, USDCETHPoolKeys, UniV4PositionManagerAddress, UniversalRouterAbi, UniversalRouterAddress, Verifier, VirtualsVerifierAddress, WhitelistVerifierAddress, WhitelistedPermissionsAddress, ZoraVerifierAddress, buyMemecoin, bytes32ToUint256, calculateUnderlyingTokenBalances, chainIdToChain, createCallDataWalletClient, createDrift, createFlaunch, createFlaunchCalldata, decodeCallData, encodedCallAbi, generateTokenUri, getAmountWithSlippage, getAmountsForLiquidity, getLiquidityFromAmounts, getNearestUsableTick, getPermissionsAddress, getPermit2TypedData, getPoolId, getSqrtPriceX96FromTick, getValidTick, maxLiquidityForAmount0Precise, maxLiquidityForAmount1, orderPoolKey, parseCall, parseSwapData, priceRatioToTick, resolveIPFS, sellMemecoinWithPermit2, uint256ToBytes32, uploadFileToIPFS, uploadImageToFlaunchAPI, uploadImageToIPFS, uploadJsonToIPFS, uploadMetadataToFlaunchAPI };
|
|
31783
32010
|
//# sourceMappingURL=index.esm.js.map
|