@flaunch/sdk 0.9.7 → 0.9.8
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 +52 -0
- package/dist/helpers/index.cjs.map +1 -1
- package/dist/helpers/index.js.map +1 -1
- package/dist/index.cjs.js +113 -43
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +114 -44
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/sdk/FlaunchSDK.d.ts +100 -8
- package/dist/sdk/FlaunchSDK.d.ts.map +1 -1
- package/dist/types.d.ts +63 -0
- package/dist/types.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
|
|
|
@@ -26931,7 +26931,8 @@ class ReadFlaunchSDK {
|
|
|
26931
26931
|
memecoin.totalSupply(),
|
|
26932
26932
|
memecoin.decimals(),
|
|
26933
26933
|
]);
|
|
26934
|
-
|
|
26934
|
+
const formattedTotalSupplyInDecimals = parseFloat(formatUnits$1(totalSupply, decimals));
|
|
26935
|
+
return { totalSupply, decimals, formattedTotalSupplyInDecimals };
|
|
26935
26936
|
}
|
|
26936
26937
|
/**
|
|
26937
26938
|
* Gets market context information needed for tick calculations
|
|
@@ -26953,8 +26954,8 @@ class ReadFlaunchSDK {
|
|
|
26953
26954
|
/**
|
|
26954
26955
|
* Converts market cap in USD to token price in ETH
|
|
26955
26956
|
*/
|
|
26956
|
-
marketCapToTokenPriceEth(marketCapUsd,
|
|
26957
|
-
const tokenPriceUsd = marketCapUsd /
|
|
26957
|
+
marketCapToTokenPriceEth(marketCapUsd, formattedTotalSupplyInDecimals, ethUsdPrice) {
|
|
26958
|
+
const tokenPriceUsd = marketCapUsd / formattedTotalSupplyInDecimals;
|
|
26958
26959
|
return tokenPriceUsd / ethUsdPrice;
|
|
26959
26960
|
}
|
|
26960
26961
|
/**
|
|
@@ -26972,24 +26973,22 @@ class ReadFlaunchSDK {
|
|
|
26972
26973
|
/**
|
|
26973
26974
|
* Calculates current tick from market cap if provided
|
|
26974
26975
|
*/
|
|
26975
|
-
calculateCurrentTickFromMarketCap(currentMarketCap,
|
|
26976
|
+
calculateCurrentTickFromMarketCap(currentMarketCap, formattedTotalSupplyInDecimals, marketContext) {
|
|
26976
26977
|
if (!currentMarketCap) {
|
|
26977
26978
|
return undefined;
|
|
26978
26979
|
}
|
|
26979
26980
|
const currentMarketCapNum = parseFloat(currentMarketCap);
|
|
26980
|
-
const currentTokenPriceEth = this.marketCapToTokenPriceEth(currentMarketCapNum,
|
|
26981
|
+
const currentTokenPriceEth = this.marketCapToTokenPriceEth(currentMarketCapNum, formattedTotalSupplyInDecimals, marketContext.ethUsdPrice);
|
|
26981
26982
|
return this.convertPriceToTick(currentTokenPriceEth, marketContext.isFlethZero, marketContext.decimals0, marketContext.decimals1);
|
|
26982
26983
|
}
|
|
26983
26984
|
async calculateAddLiquidityTicks({ coinAddress, liquidityMode, minMarketCap, maxMarketCap, currentMarketCap, }) {
|
|
26984
26985
|
// Get coin information
|
|
26985
|
-
const { totalSupply: coinTotalSupply, decimals: coinDecimals } = await this.getCoinInfo(coinAddress);
|
|
26986
|
-
// Convert total supply to decimal format
|
|
26987
|
-
const totalSupplyDecimal = parseFloat(formatEther(coinTotalSupply));
|
|
26986
|
+
const { totalSupply: coinTotalSupply, decimals: coinDecimals, formattedTotalSupplyInDecimals, } = await this.getCoinInfo(coinAddress);
|
|
26988
26987
|
if (liquidityMode === LiquidityMode.FULL_RANGE) {
|
|
26989
26988
|
let currentTick;
|
|
26990
26989
|
if (currentMarketCap) {
|
|
26991
26990
|
const marketContext = await this.getMarketContext(coinAddress, coinDecimals);
|
|
26992
|
-
currentTick = this.calculateCurrentTickFromMarketCap(currentMarketCap,
|
|
26991
|
+
currentTick = this.calculateCurrentTickFromMarketCap(currentMarketCap, formattedTotalSupplyInDecimals, marketContext);
|
|
26993
26992
|
}
|
|
26994
26993
|
return {
|
|
26995
26994
|
tickLower: getNearestUsableTick({
|
|
@@ -27016,13 +27015,13 @@ class ReadFlaunchSDK {
|
|
|
27016
27015
|
throw new Error("[ReadFlaunchSDK.addLiquidityCalculateTicks]: Invalid market cap range");
|
|
27017
27016
|
}
|
|
27018
27017
|
// Convert market caps to token prices in ETH
|
|
27019
|
-
const minTokenPriceEth = this.marketCapToTokenPriceEth(minMarketCapNum,
|
|
27020
|
-
const maxTokenPriceEth = this.marketCapToTokenPriceEth(maxMarketCapNum,
|
|
27018
|
+
const minTokenPriceEth = this.marketCapToTokenPriceEth(minMarketCapNum, formattedTotalSupplyInDecimals, marketContext.ethUsdPrice);
|
|
27019
|
+
const maxTokenPriceEth = this.marketCapToTokenPriceEth(maxMarketCapNum, formattedTotalSupplyInDecimals, marketContext.ethUsdPrice);
|
|
27021
27020
|
// Convert to ticks
|
|
27022
27021
|
const minTick = this.convertPriceToTick(minTokenPriceEth, marketContext.isFlethZero, marketContext.decimals0, marketContext.decimals1);
|
|
27023
27022
|
const maxTick = this.convertPriceToTick(maxTokenPriceEth, marketContext.isFlethZero, marketContext.decimals0, marketContext.decimals1);
|
|
27024
27023
|
// Calculate current tick if provided
|
|
27025
|
-
const currentTick = this.calculateCurrentTickFromMarketCap(currentMarketCap,
|
|
27024
|
+
const currentTick = this.calculateCurrentTickFromMarketCap(currentMarketCap, formattedTotalSupplyInDecimals, marketContext);
|
|
27026
27025
|
return {
|
|
27027
27026
|
tickLower: Math.min(minTick, maxTick),
|
|
27028
27027
|
tickUpper: Math.max(minTick, maxTick),
|
|
@@ -27043,12 +27042,11 @@ class ReadFlaunchSDK {
|
|
|
27043
27042
|
currentMarketCap = params.currentMarketCap;
|
|
27044
27043
|
}
|
|
27045
27044
|
else {
|
|
27046
|
-
const {
|
|
27047
|
-
|
|
27048
|
-
|
|
27049
|
-
maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupply).toString();
|
|
27045
|
+
const { formattedTotalSupplyInDecimals } = await this.getCoinInfo(coinAddress);
|
|
27046
|
+
minMarketCap = (parseFloat(params.minPriceUSD) * formattedTotalSupplyInDecimals).toString();
|
|
27047
|
+
maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupplyInDecimals).toString();
|
|
27050
27048
|
if (params.currentPriceUSD) {
|
|
27051
|
-
currentMarketCap = (params.currentPriceUSD *
|
|
27049
|
+
currentMarketCap = (params.currentPriceUSD * formattedTotalSupplyInDecimals).toString();
|
|
27052
27050
|
}
|
|
27053
27051
|
}
|
|
27054
27052
|
let { tickLower, tickUpper, currentTick } = await this.calculateAddLiquidityTicks({
|
|
@@ -27119,12 +27117,11 @@ class ReadFlaunchSDK {
|
|
|
27119
27117
|
currentMarketCap = params.currentMarketCap;
|
|
27120
27118
|
}
|
|
27121
27119
|
else {
|
|
27122
|
-
const {
|
|
27123
|
-
|
|
27124
|
-
|
|
27125
|
-
maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupply).toString();
|
|
27120
|
+
const { formattedTotalSupplyInDecimals } = await this.getCoinInfo(coinAddress);
|
|
27121
|
+
minMarketCap = (parseFloat(params.minPriceUSD) * formattedTotalSupplyInDecimals).toString();
|
|
27122
|
+
maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupplyInDecimals).toString();
|
|
27126
27123
|
if (params.currentPriceUSD) {
|
|
27127
|
-
currentMarketCap = (params.currentPriceUSD *
|
|
27124
|
+
currentMarketCap = (params.currentPriceUSD * formattedTotalSupplyInDecimals).toString();
|
|
27128
27125
|
}
|
|
27129
27126
|
}
|
|
27130
27127
|
let { tickLower, tickUpper, currentTick } = await this.calculateAddLiquidityTicks({
|
|
@@ -27788,12 +27785,12 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
27788
27785
|
initialMarketCapUSD = params.initialMarketCapUSD;
|
|
27789
27786
|
}
|
|
27790
27787
|
else {
|
|
27791
|
-
const {
|
|
27792
|
-
|
|
27793
|
-
|
|
27794
|
-
maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupply).toString();
|
|
27788
|
+
const { formattedTotalSupplyInDecimals } = await this.getCoinInfo(coinAddress);
|
|
27789
|
+
minMarketCap = (parseFloat(params.minPriceUSD) * formattedTotalSupplyInDecimals).toString();
|
|
27790
|
+
maxMarketCap = (parseFloat(params.maxPriceUSD) * formattedTotalSupplyInDecimals).toString();
|
|
27795
27791
|
if (params.initialPriceUSD) {
|
|
27796
|
-
initialMarketCapUSD =
|
|
27792
|
+
initialMarketCapUSD =
|
|
27793
|
+
params.initialPriceUSD * formattedTotalSupplyInDecimals;
|
|
27797
27794
|
}
|
|
27798
27795
|
}
|
|
27799
27796
|
const calculated = await this.calculateAddLiquidityAmounts({
|
|
@@ -27963,18 +27960,27 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
27963
27960
|
calls.push(this.createLiquidityCall(poolKey, tickLower, tickUpper, finalLiquidity, finalAmount0, finalAmount1, userAddress));
|
|
27964
27961
|
return calls;
|
|
27965
27962
|
}
|
|
27966
|
-
|
|
27967
|
-
* Gets the calls needed to import a memecoin to Flaunch and add liquidity to AnyPositionManager as a batch
|
|
27968
|
-
* @param params - Parameters for importing and adding liquidity
|
|
27969
|
-
* @returns Array of calls with descriptions
|
|
27970
|
-
*/
|
|
27963
|
+
// Implementation with union type for internal use
|
|
27971
27964
|
async getImportAndAddLiquidityCalls(params) {
|
|
27972
|
-
|
|
27973
|
-
|
|
27974
|
-
|
|
27975
|
-
|
|
27976
|
-
|
|
27977
|
-
|
|
27965
|
+
let importParams;
|
|
27966
|
+
if ("initialMarketCapUSD" in params) {
|
|
27967
|
+
const paramsWithMarketCap = params;
|
|
27968
|
+
importParams = await this.readWriteTokenImporter.getInitializeParams({
|
|
27969
|
+
coinAddress: paramsWithMarketCap.coinAddress,
|
|
27970
|
+
creatorFeeAllocationPercent: paramsWithMarketCap.creatorFeeAllocationPercent,
|
|
27971
|
+
initialMarketCapUSD: paramsWithMarketCap.initialMarketCapUSD,
|
|
27972
|
+
verifier: paramsWithMarketCap.verifier,
|
|
27973
|
+
});
|
|
27974
|
+
}
|
|
27975
|
+
else {
|
|
27976
|
+
const paramsWithPrice = params;
|
|
27977
|
+
importParams = await this.readWriteTokenImporter.getInitializeParams({
|
|
27978
|
+
coinAddress: paramsWithPrice.coinAddress,
|
|
27979
|
+
creatorFeeAllocationPercent: paramsWithPrice.creatorFeeAllocationPercent,
|
|
27980
|
+
initialPriceUSD: paramsWithPrice.initialPriceUSD,
|
|
27981
|
+
verifier: paramsWithPrice.verifier,
|
|
27982
|
+
});
|
|
27983
|
+
}
|
|
27978
27984
|
const addLiquidityCalls = await this.getAddLiquidityCalls({
|
|
27979
27985
|
...params,
|
|
27980
27986
|
version: FlaunchVersion.ANY, // optimize to avoid fetching if not passed
|
|
@@ -27997,11 +28003,38 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
27997
28003
|
const { coinAddress, coinAmount } = params;
|
|
27998
28004
|
const version = await this.determineCoinVersion(coinAddress, params.version);
|
|
27999
28005
|
const poolKey = this.createPoolKey(coinAddress, version);
|
|
28000
|
-
|
|
28001
|
-
|
|
28002
|
-
|
|
28003
|
-
|
|
28004
|
-
|
|
28006
|
+
let currentTick;
|
|
28007
|
+
// if initial marketcap or price is provided, it means that the pool is not initialized yet
|
|
28008
|
+
// so determining the currentTick
|
|
28009
|
+
if (("initialMarketCapUSD" in params && params.initialMarketCapUSD) ||
|
|
28010
|
+
("initialPriceUSD" in params && params.initialPriceUSD)) {
|
|
28011
|
+
const { decimals: coinDecimals, formattedTotalSupplyInDecimals } = await this.getCoinInfo(coinAddress);
|
|
28012
|
+
// Determine market cap based on provided parameter
|
|
28013
|
+
let initialMarketCapUSD;
|
|
28014
|
+
if ("initialMarketCapUSD" in params && params.initialMarketCapUSD) {
|
|
28015
|
+
initialMarketCapUSD = params.initialMarketCapUSD;
|
|
28016
|
+
}
|
|
28017
|
+
else if ("initialPriceUSD" in params && params.initialPriceUSD) {
|
|
28018
|
+
initialMarketCapUSD =
|
|
28019
|
+
params.initialPriceUSD * formattedTotalSupplyInDecimals;
|
|
28020
|
+
}
|
|
28021
|
+
else {
|
|
28022
|
+
throw new Error("Either initialMarketCapUSD or initialPriceUSD must be provided");
|
|
28023
|
+
}
|
|
28024
|
+
const marketContext = await this.getMarketContext(coinAddress, coinDecimals);
|
|
28025
|
+
const calculatedTick = this.calculateCurrentTickFromMarketCap(initialMarketCapUSD.toString(), formattedTotalSupplyInDecimals, marketContext);
|
|
28026
|
+
if (calculatedTick === undefined) {
|
|
28027
|
+
throw new Error("Failed to calculate current tick from market cap");
|
|
28028
|
+
}
|
|
28029
|
+
currentTick = calculatedTick;
|
|
28030
|
+
}
|
|
28031
|
+
else {
|
|
28032
|
+
// the pool is already initialized, get the current tick from the pool
|
|
28033
|
+
const poolState = await this.readStateView.poolSlot0({
|
|
28034
|
+
poolId: getPoolId(poolKey),
|
|
28035
|
+
});
|
|
28036
|
+
currentTick = poolState.tick;
|
|
28037
|
+
}
|
|
28005
28038
|
// We want to add liquidity from current price to infinity (as coin appreciates vs flETH)
|
|
28006
28039
|
// This means providing single-sided coin liquidity that becomes active as coin price increases
|
|
28007
28040
|
const isFLETHZero = this.flETHIsCurrencyZero(coinAddress);
|
|
@@ -28114,6 +28147,43 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
|
|
|
28114
28147
|
calls.push(this.createLiquidityCall(poolKey, tickLower, tickUpper, finalLiquidity, finalAmount0, finalAmount1, userAddress));
|
|
28115
28148
|
return calls;
|
|
28116
28149
|
}
|
|
28150
|
+
// Implementation with union type for internal use
|
|
28151
|
+
async getImportAndSingleSidedCoinAddLiquidityCalls(params) {
|
|
28152
|
+
let importParams;
|
|
28153
|
+
if ("initialMarketCapUSD" in params) {
|
|
28154
|
+
const paramsWithMarketCap = params;
|
|
28155
|
+
importParams = await this.readWriteTokenImporter.getInitializeParams({
|
|
28156
|
+
coinAddress: paramsWithMarketCap.coinAddress,
|
|
28157
|
+
creatorFeeAllocationPercent: paramsWithMarketCap.creatorFeeAllocationPercent,
|
|
28158
|
+
initialMarketCapUSD: paramsWithMarketCap.initialMarketCapUSD,
|
|
28159
|
+
verifier: paramsWithMarketCap.verifier,
|
|
28160
|
+
});
|
|
28161
|
+
}
|
|
28162
|
+
else {
|
|
28163
|
+
const paramsWithPrice = params;
|
|
28164
|
+
importParams = await this.readWriteTokenImporter.getInitializeParams({
|
|
28165
|
+
coinAddress: paramsWithPrice.coinAddress,
|
|
28166
|
+
creatorFeeAllocationPercent: paramsWithPrice.creatorFeeAllocationPercent,
|
|
28167
|
+
initialPriceUSD: paramsWithPrice.initialPriceUSD,
|
|
28168
|
+
verifier: paramsWithPrice.verifier,
|
|
28169
|
+
});
|
|
28170
|
+
}
|
|
28171
|
+
const addLiquidityCalls = await this.getSingleSidedCoinAddLiquidityCalls({
|
|
28172
|
+
...params,
|
|
28173
|
+
version: FlaunchVersion.ANY, // optimize to avoid fetching if not passed
|
|
28174
|
+
});
|
|
28175
|
+
return [
|
|
28176
|
+
{
|
|
28177
|
+
to: this.readWriteTokenImporter.contract.address,
|
|
28178
|
+
data: this.readWriteTokenImporter.contract.encodeFunctionData("initialize", importParams),
|
|
28179
|
+
description: "Import Memecoin to Flaunch",
|
|
28180
|
+
},
|
|
28181
|
+
...addLiquidityCalls,
|
|
28182
|
+
];
|
|
28183
|
+
}
|
|
28184
|
+
/**
|
|
28185
|
+
* === Private helper functions ===
|
|
28186
|
+
*/
|
|
28117
28187
|
/**
|
|
28118
28188
|
* Calculates and constrains liquidity amounts for a position
|
|
28119
28189
|
* @param currentTick - Current pool tick
|